Skip to content

Commit 352dd2d

Browse files
ianlancetaylorprattmic
authored andcommitted
runtime: only poll network from one P at a time in findRunnable
For #65064 Change-Id: Ifecd7e332d2cf251750752743befeda4ed396f33 Reviewed-on: https://go-review.googlesource.com/c/go/+/564197 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Artur M. Wolff <[email protected]> Reviewed-by: Carlos Amedee <[email protected]> Reviewed-by: Mauri de Souza Meneguzzo <[email protected]> Reviewed-by: Michael Pratt <[email protected]>
1 parent 336626b commit 352dd2d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/runtime/proc.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3387,8 +3387,12 @@ top:
33873387
// blocked thread (e.g. it has already returned from netpoll, but does
33883388
// not set lastpoll yet), this thread will do blocking netpoll below
33893389
// anyway.
3390-
if netpollinited() && netpollAnyWaiters() && sched.lastpoll.Load() != 0 {
3391-
if list, delta := netpoll(0); !list.empty() { // non-blocking
3390+
// We only poll from one thread at a time to avoid kernel contention
3391+
// on machines with many cores.
3392+
if netpollinited() && netpollAnyWaiters() && sched.lastpoll.Load() != 0 && sched.pollingNet.Swap(1) == 0 {
3393+
list, delta := netpoll(0)
3394+
sched.pollingNet.Store(0)
3395+
if !list.empty() { // non-blocking
33923396
gp := list.pop()
33933397
injectglist(&list)
33943398
netpollAdjustWaiters(delta)

src/runtime/runtime2.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,10 @@ type p struct {
757757
}
758758

759759
type schedt struct {
760-
goidgen atomic.Uint64
761-
lastpoll atomic.Int64 // time of last network poll, 0 if currently polling
762-
pollUntil atomic.Int64 // time to which current poll is sleeping
760+
goidgen atomic.Uint64
761+
lastpoll atomic.Int64 // time of last network poll, 0 if currently polling
762+
pollUntil atomic.Int64 // time to which current poll is sleeping
763+
pollingNet atomic.Int32 // 1 if some P doing non-blocking network poll
763764

764765
lock mutex
765766

0 commit comments

Comments
 (0)