Skip to content

Commit 2263d4a

Browse files
prattmicgopherbot
authored andcommitted
runtime: doubly-linked sched.midle list
This will be used by CL 714801 to remove Ms from the middle of the list. We could simply convert schedlink to the doubly-linked list, bringing along all other uses of schedlink. However, CL 714801 removes Ms from the middle of the midle list. It would be an easy mistake to make to accidentally remove an M from schedlink, assuming that it is on the midle list when it is actually on a completely different list. Using separate a list node makes this impossible. For #65694. Change-Id: I6a6a636c223d925fdc30c0c648460cbf5c2af4d6 Reviewed-on: https://go-review.googlesource.com/c/go/+/714800 Reviewed-by: Michael Knyszek <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]>
1 parent 046dce0 commit 2263d4a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/runtime/proc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,8 @@ func schedinit() {
849849

850850
lockVerifyMSize()
851851

852+
sched.midle.init(unsafe.Offsetof(m{}.idleNode))
853+
852854
// raceinit must be the first call to race detector.
853855
// In particular, it must be done before mallocinit below calls racemapshadow.
854856
gp := getg()
@@ -6976,8 +6978,7 @@ func schedEnabled(gp *g) bool {
69766978
func mput(mp *m) {
69776979
assertLockHeld(&sched.lock)
69786980

6979-
mp.schedlink = sched.midle
6980-
sched.midle.set(mp)
6981+
sched.midle.push(unsafe.Pointer(mp))
69816982
sched.nmidle++
69826983
checkdead()
69836984
}
@@ -6990,9 +6991,8 @@ func mput(mp *m) {
69906991
func mget() *m {
69916992
assertLockHeld(&sched.lock)
69926993

6993-
mp := sched.midle.ptr()
6994+
mp := (*m)(sched.midle.pop())
69946995
if mp != nil {
6995-
sched.midle = mp.schedlink
69966996
sched.nmidle--
69976997
}
69986998
return mp

src/runtime/runtime2.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ type m struct {
665665
park note
666666
alllink *m // on allm
667667
schedlink muintptr
668+
idleNode listNodeManual
668669
lockedg guintptr
669670
createstack [32]uintptr // stack that created this thread, it's used for StackRecord.Stack0, so it must align with it.
670671
lockedExt uint32 // tracking for external LockOSThread
@@ -875,7 +876,7 @@ type schedt struct {
875876
// When increasing nmidle, nmidlelocked, nmsys, or nmfreed, be
876877
// sure to call checkdead().
877878

878-
midle muintptr // idle m's waiting for work
879+
midle listHeadManual // idle m's waiting for work
879880
nmidle int32 // number of idle m's waiting for work
880881
nmidlelocked int32 // number of locked m's waiting for work
881882
mnext int64 // number of m's that have been created and next M ID

0 commit comments

Comments
 (0)