File tree 2 files changed +10
-5
lines changed
2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -3387,8 +3387,12 @@ top:
3387
3387
// blocked thread (e.g. it has already returned from netpoll, but does
3388
3388
// not set lastpoll yet), this thread will do blocking netpoll below
3389
3389
// 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
3392
3396
gp := list .pop ()
3393
3397
injectglist (& list )
3394
3398
netpollAdjustWaiters (delta )
Original file line number Diff line number Diff line change @@ -757,9 +757,10 @@ type p struct {
757
757
}
758
758
759
759
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
763
764
764
765
lock mutex
765
766
You can’t perform that action at this time.
0 commit comments