Skip to content

Commit

Permalink
Revert "sync: yield to the waiter when unlocking a starving mutex"
Browse files Browse the repository at this point in the history
This reverts CL 200577.

Reason for revert: broke linux-arm64-packet and solaris-amd64-oraclerel builders

Fixes #35424
Updates #33747

Change-Id: I2575fd84d37995d458183caae54704f15d8b8426
Reviewed-on: https://go-review.googlesource.com/c/go/+/205817
Run-TryBot: Bryan C. Mills <[email protected]>
Reviewed-by: Brad Fitzpatrick <[email protected]>
  • Loading branch information
Bryan C. Mills committed Nov 7, 2019
1 parent e8f01d5 commit 73d57bf
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 125 deletions.
8 changes: 0 additions & 8 deletions src/runtime/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,3 @@ func RunGetgThreadSwitchTest() {
panic("g1 != g3")
}
}

var Semacquire = semacquire
var Semrelease1 = semrelease1

func SemNwait(addr *uint32) uint32 {
root := semroot(addr)
return atomic.Load(&root.nwait)
}
15 changes: 0 additions & 15 deletions src/runtime/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2753,22 +2753,7 @@ func preemptPark(gp *g) {
casGToPreemptScan(gp, _Grunning, _Gscan|_Gpreempted)
dropg()
casfrom_Gscanstatus(gp, _Gscan|_Gpreempted, _Gpreempted)
schedule()
}

// goyield is like Gosched, but it:
// - does not emit a GoSched trace event
// - puts the current G on the runq of the current P instead of the globrunq
func goyield() {
checkTimeouts()
mcall(goyield_m)
}

func goyield_m(gp *g) {
pp := gp.m.p.ptr()
casgstatus(gp, _Grunning, _Grunnable)
dropg()
runqput(pp, gp, false)
schedule()
}

Expand Down
21 changes: 1 addition & 20 deletions src/runtime/sema.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func semrelease1(addr *uint32, handoff bool, skipframes int) {
atomic.Xadd(&root.nwait, -1)
}
unlock(&root.lock)
if s != nil { // May be slow or even yield, so unlock first
if s != nil { // May be slow, so unlock first
acquiretime := s.acquiretime
if acquiretime != 0 {
mutexevent(t0-acquiretime, 3+skipframes)
Expand All @@ -192,25 +192,6 @@ func semrelease1(addr *uint32, handoff bool, skipframes int) {
s.ticket = 1
}
readyWithTime(s, 5+skipframes)
if s.ticket == 1 {
// Direct G handoff
// readyWithTime has added the waiter G as runnext in the
// current P; we now call the scheduler so that we start running
// the waiter G immediately.
// Note that waiter inherits our time slice: this is desirable
// to avoid having a highly contended semaphore hog the P
// indefinitely. goyield is like Gosched, but it does not emit a
// GoSched trace event and, more importantly, puts the current G
// on the local runq instead of the global one.
// We only do this in the starving regime (handoff=true), as in
// the non-starving case it is possible for a different waiter
// to acquire the semaphore while we are yielding/scheduling,
// and this would be wasteful. We wait instead to enter starving
// regime, and then we start to do direct handoffs of ticket and
// P.
// See issue 33747 for discussion.
goyield()
}
}
}

Expand Down
80 changes: 0 additions & 80 deletions src/runtime/sema_test.go

This file was deleted.

3 changes: 1 addition & 2 deletions src/sync/mutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ func (m *Mutex) unlockSlow(new int32) {
old = m.state
}
} else {
// Starving mode: handoff mutex ownership to the next waiter, and yield
// our time slice so that the next waiter can start to run immediately.
// Starving mode: handoff mutex ownership to the next waiter.
// Note: mutexLocked is not set, the waiter will set it after wakeup.
// But mutex is still considered locked if mutexStarving is set,
// so new coming goroutines won't acquire it.
Expand Down

0 comments on commit 73d57bf

Please sign in to comment.