Skip to content

Commit 1e436ba

Browse files
committed
runtime: only poll network from one P at a time in findRunnable
This change reintroduces CL 564197. It was reverted due to a failing benchmark. That failure has been resolved. For #65064 Change-Id: Ic88841d2bc24c2717ad324873f0f52699f21dc66 Reviewed-on: https://go-review.googlesource.com/c/go/+/669235 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
1 parent 3474c52 commit 1e436ba

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/runtime/proc.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -3396,8 +3396,12 @@ top:
33963396
// blocked thread (e.g. it has already returned from netpoll, but does
33973397
// not set lastpoll yet), this thread will do blocking netpoll below
33983398
// anyway.
3399-
if netpollinited() && netpollAnyWaiters() && sched.lastpoll.Load() != 0 {
3400-
if list, delta := netpoll(0); !list.empty() { // non-blocking
3399+
// We only poll from one thread at a time to avoid kernel contention
3400+
// on machines with many cores.
3401+
if netpollinited() && netpollAnyWaiters() && sched.lastpoll.Load() != 0 && sched.pollingNet.Swap(1) == 0 {
3402+
list, delta := netpoll(0)
3403+
sched.pollingNet.Store(0)
3404+
if !list.empty() { // non-blocking
34013405
gp := list.pop()
34023406
injectglist(&list)
34033407
netpollAdjustWaiters(delta)

src/runtime/runtime2.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,10 @@ type p struct {
760760
}
761761

762762
type schedt struct {
763-
goidgen atomic.Uint64
764-
lastpoll atomic.Int64 // time of last network poll, 0 if currently polling
765-
pollUntil atomic.Int64 // time to which current poll is sleeping
763+
goidgen atomic.Uint64
764+
lastpoll atomic.Int64 // time of last network poll, 0 if currently polling
765+
pollUntil atomic.Int64 // time to which current poll is sleeping
766+
pollingNet atomic.Int32 // 1 if some P doing non-blocking network poll
766767

767768
lock mutex
768769

0 commit comments

Comments
 (0)