]> Cypherpunks repositories - gostls13.git/commit
runtime: add goroutines returned by poller to local run queue
authorIan Lance Taylor <iant@golang.org>
Fri, 24 Jan 2020 04:38:20 +0000 (20:38 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 16 Mar 2020 22:31:39 +0000 (22:31 +0000)
commit2fbca94db7e14fc1d18162cd203d7afc19b520e8
tree53a9092ec3cf5aba8b2c16ec914dc9c4d66f3ed4
parentff1eb428654b7815a8fc825f1cc29d6cf72cc2f7
runtime: add goroutines returned by poller to local run queue

In Go 1.13, when the network poller found a list of ready goroutines,
they were added to the global run queue. The timer goroutine would
typically sleep in a futex with a timeout, and when the timeout
expired the timer goroutine would either be handed off to an idle P
or added to the global run queue. The effect was that on a busy system
with no idle P's goroutines waiting for timeouts and goroutines waiting
for the network would start at the same priority.

That changed on tip with the new timer code. Now timer functions are
invoked directly from a P, and it happens that the functions used
by time.Sleep and time.After and time.Ticker add the newly ready
goroutines to the local run queue. When a P looks for work it will
prefer goroutines on the local run queue; in fact it will only
occasionally look at the global run queue, and even when it does it
will just pull one goroutine off. So on a busy system with both active
timers and active network connections the system can noticeably prefer
to run goroutines waiting for timers rather than goroutines waiting
for the network.

This CL undoes that change by, when possible, adding goroutines
waiting for the network to the local run queue of the P that checked.
This doesn't affect network poller checks done by sysmon, but it
does affect network poller checks done as each P enters the scheduler.

This CL also makes injecting a list into either the local or global run
queue more efficient, using bulk operations rather than individual ones.

Change-Id: I85a66ad74e4fc3b458256fb7ab395d06f0d2ffac
Reviewed-on: https://go-review.googlesource.com/c/go/+/216198
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/proc.go