]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use gList for injectglist
authorAustin Clements <austin@google.com>
Fri, 10 Aug 2018 14:33:05 +0000 (10:33 -0400)
committerAustin Clements <austin@google.com>
Mon, 20 Aug 2018 18:19:28 +0000 (18:19 +0000)
Change-Id: Id5af75eaaf41f43bc6baa6d3fe2b852a2f93bb6f
Reviewed-on: https://go-review.googlesource.com/129400
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rick Hudson <rlh@golang.org>
src/runtime/mgc.go
src/runtime/mgcmark.go
src/runtime/proc.go

index 2d67c4d8c44856fb9d37b29eb96774bc8554c2ac..e4c0f5a58762971e11b5f11d7dc9cac7a85eaa70 100644 (file)
@@ -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
index d6ee7ff6fabe4e5a452eb402a1e6a9c25c98a426..69ff895512faa8e8cdf54e7e773ddc66b8a1171f 100644 (file)
@@ -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)
 }
 
index 5cb7f130169d0912a3c1bb76f279c66138c582fd..7875b38e2e2cfe0212c87c6132b2e3eaa94c7aba 100644 (file)
@@ -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