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 @@ -3396,8 +3396,12 @@ top:
3396
3396
// blocked thread (e.g. it has already returned from netpoll, but does
3397
3397
// not set lastpoll yet), this thread will do blocking netpoll below
3398
3398
// 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
3401
3405
gp := list .pop ()
3402
3406
injectglist (& list )
3403
3407
netpollAdjustWaiters (delta )
Original file line number Diff line number Diff line change @@ -760,9 +760,10 @@ type p struct {
760
760
}
761
761
762
762
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
766
767
767
768
lock mutex
768
769
You can’t perform that action at this time.
0 commit comments