diff options
author | Jamie Liu <jamieliu@google.com> | 2021-11-05 00:49:55 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-11-05 00:52:35 -0700 |
commit | 822a647018adbd994114cb0dc8932f2853b805aa (patch) | |
tree | 46421204e5d7bb3c31e665910839711528d3e3ab /pkg/sentry/fsimpl/kernfs | |
parent | d80af5f8b58d2bfe23d57e133a8d35eaed59fa13 (diff) |
Fix unfair comparison to unbuffered channels in sleep_test.go.
Consider the following benchmark, which is equivalent to
BenchmarkSleeperWaitOnSingleSelect with names changed to more closely reflect
the behavior of BenchmarkGoWaitOnSingleSelect:
var (
empty Sleeper
emptyCond Waker
full Sleeper
fullCond Waker
)
empty.AddWaker(&emptyCond)
full.AddWaker(&fullCond)
go func() {
for i := 0; i < b.N; i++ {
empty.Fetch(true)
fullCond.Assert()
}
}()
for i := 0; i < b.N; i++ {
emptyCond.Assert()
full.Fetch(true)
}
The unfairness arises because runtime.chansend and runtime.chanrecv don't
actually work this way. If runtime.chansend blocks, it has already enqueued the
element to be sent on runtime.hchan.sendq, which runtime.chanrecv dequeues
before calling goready(); in sleep-like terms, by the time empty.Fetch()
returns, fullCond.Assert() has already happened and been fetched by the other
goroutine. The same property applies to runtime.chanrecv/runtime.hchan.recvq.
This property has no correspondence to the actual usage of the sleep package,
so change the channel benchmarks to explicitly exchange control using buffered
channels instead. Also remove some stale comments and align the syncevent
benchmarks with the sleep ones.
BenchmarkSleeperWaitOnSingleSelect
BenchmarkSleeperWaitOnSingleSelect-12 2118603 472.5 ns/op
BenchmarkGoWaitOnSingleSelect
BenchmarkGoWaitOnSingleSelect-12 2224262 517.7 ns/op
BenchmarkSleeperWaitOnMultiSelect
BenchmarkSleeperWaitOnMultiSelect-12 2630569 459.8 ns/op
BenchmarkGoWaitOnMultiSelect
BenchmarkGoWaitOnMultiSelect-12 807918 1312 ns/op
BenchmarkWaiterPingPong
BenchmarkWaiterPingPong-12 2955579 385.8 ns/op
BenchmarkSleeperPingPong
BenchmarkSleeperPingPong-12 2454367 474.3 ns/op
BenchmarkChannelPingPong
BenchmarkChannelPingPong-12 2302662 513.5 ns/op
BenchmarkWaiterPingPongMulti
BenchmarkWaiterPingPongMulti-12 3023676 388.8 ns/op
BenchmarkSleeperPingPongMulti
BenchmarkSleeperPingPongMulti-12 2574064 471.5 ns/op
BenchmarkChannelPingPongMulti
BenchmarkChannelPingPongMulti-12 1000000 1088 ns/op
PiperOrigin-RevId: 407760956
Diffstat (limited to 'pkg/sentry/fsimpl/kernfs')
0 files changed, 0 insertions, 0 deletions