From 083938df14c0602a44d055bd3f4427980cf51c27 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 10 Aug 2018 10:33:05 -0400 Subject: [PATCH] runtime: use gList for injectglist Change-Id: Id5af75eaaf41f43bc6baa6d3fe2b852a2f93bb6f Reviewed-on: https://go-review.googlesource.com/129400 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgc.go | 3 +-- src/runtime/mgcmark.go | 3 ++- src/runtime/proc.go | 31 ++++++++++++++++--------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 2d67c4d8c4..e4c0f5a587 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1630,8 +1630,7 @@ func gcMarkTermination(nextTriggerRatio float64) { // Bump GC cycle count and wake goroutines waiting on sweep. lock(&work.sweepWaiters.lock) memstats.numgc++ - injectglist(work.sweepWaiters.list.head.ptr()) - work.sweepWaiters.list = gList{} + injectglist(&work.sweepWaiters.list) unlock(&work.sweepWaiters.lock) // Finish the current heap profiling cycle and start a new diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index d6ee7ff6fa..69ff895512 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -603,7 +603,8 @@ func gcAssistAlloc1(gp *g, scanWork int64) { // new assists from going to sleep after this point. func gcWakeAllAssists() { lock(&work.assistQueue.lock) - injectglist(work.assistQueue.q.popList().head.ptr()) + list := work.assistQueue.q.popList() + injectglist(&list) unlock(&work.assistQueue.lock) } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 5cb7f13016..7875b38e2e 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1149,7 +1149,7 @@ func startTheWorldWithSema(emitTraceEvent bool) int64 { _g_.m.locks++ // disable preemption because it can be holding p in a local var if netpollinited() { list := netpoll(false) // non-blocking - injectglist(list.head.ptr()) + injectglist(&list) } add := needaddgcproc() lock(&sched.lock) @@ -2314,7 +2314,7 @@ top: if netpollinited() && atomic.Load(&netpollWaiters) > 0 && atomic.Load64(&sched.lastpoll) != 0 { if list := netpoll(false); !list.empty() { // non-blocking gp := list.pop() - injectglist(list.head.ptr()) + injectglist(&list) casgstatus(gp, _Gwaiting, _Grunnable) if trace.enabled { traceGoUnpark(gp, 0) @@ -2475,14 +2475,14 @@ stop: if _p_ != nil { acquirep(_p_) gp := list.pop() - injectglist(list.head.ptr()) + injectglist(&list) casgstatus(gp, _Gwaiting, _Grunnable) if trace.enabled { traceGoUnpark(gp, 0) } return gp, false } - injectglist(list.head.ptr()) + injectglist(&list) } } stopm() @@ -2503,7 +2503,7 @@ func pollWork() bool { } if netpollinited() && atomic.Load(&netpollWaiters) > 0 && sched.lastpoll != 0 { if list := netpoll(false); !list.empty() { - injectglist(list.head.ptr()) + injectglist(&list) return true } } @@ -2528,22 +2528,21 @@ func resetspinning() { } } -// Injects the list of runnable G's into the scheduler. +// Injects the list of runnable G's into the scheduler and clears glist. // Can run concurrently with GC. -func injectglist(glist *g) { - if glist == nil { +func injectglist(glist *gList) { + if glist.empty() { return } if trace.enabled { - for gp := glist; gp != nil; gp = gp.schedlink.ptr() { + for gp := glist.head.ptr(); gp != nil; gp = gp.schedlink.ptr() { traceGoUnpark(gp, 0) } } lock(&sched.lock) var n int - for n = 0; glist != nil; n++ { - gp := glist - glist = gp.schedlink.ptr() + for n = 0; !glist.empty(); n++ { + gp := glist.pop() casgstatus(gp, _Gwaiting, _Grunnable) globrunqput(gp) } @@ -2551,6 +2550,7 @@ func injectglist(glist *g) { for ; n != 0 && sched.npidle != 0; n-- { startm(nil, false) } + *glist = gList{} } // One round of scheduler: find a runnable goroutine and execute it. @@ -4389,7 +4389,7 @@ func sysmon() { // observes that there is no work to do and no other running M's // and reports deadlock. incidlelocked(-1) - injectglist(list.head.ptr()) + injectglist(&list) incidlelocked(1) } } @@ -4404,8 +4404,9 @@ func sysmon() { if t := (gcTrigger{kind: gcTriggerTime, now: now}); t.test() && atomic.Load(&forcegc.idle) != 0 { lock(&forcegc.lock) forcegc.idle = 0 - forcegc.g.schedlink = 0 - injectglist(forcegc.g) + var list gList + list.push(forcegc.g) + injectglist(&list) unlock(&forcegc.lock) } // scavenge heap once in a while -- 2.50.0