gvisor/pkg/sync
Jamie Liu 9bd0164237 Improve sync.SeqCount performance.
- Make sync.SeqCountEpoch not a struct. This allows sync.SeqCount.BeginRead()
  to be inlined.

- Mark sync.SeqAtomicLoad<T> nosplit to mitigate the Go compiler's refusal to
  inline it. (Best I could get was "cost 92 exceeds budget 80".)

- Use runtime-guided spinning in SeqCount.BeginRead().

Benchmarks:
name                               old time/op  new time/op   delta
pkg:pkg/sync/sync goos:linux goarch:amd64
SeqCountWriteUncontended-12        8.24ns ± 0%  11.40ns ± 0%  +38.35%  (p=0.000 n=10+10)
SeqCountReadUncontended-12         0.33ns ± 0%   0.14ns ± 3%  -57.77%  (p=0.000 n=7+8)
pkg:pkg/sync/seqatomictest/seqatomic goos:linux goarch:amd64
SeqAtomicLoadIntUncontended-12     0.64ns ± 1%   0.41ns ± 1%  -36.40%  (p=0.000 n=10+8)
SeqAtomicTryLoadIntUncontended-12  0.18ns ± 4%   0.18ns ± 1%     ~     (p=0.206 n=10+8)
AtomicValueLoadIntUncontended-12   0.27ns ± 3%   0.27ns ± 0%   -1.77%  (p=0.000 n=10+8)

(atomic.Value.Load is, of course, inlined. We would expect an uncontended
inline SeqAtomicLoad<int> to perform identically to SeqAtomicTryLoad<int>.) The
"regression" in BenchmarkSeqCountWriteUncontended, despite this CL changing
nothing in that path, is attributed to microarchitectural subtlety; the
benchmark loop is unchanged except for its address:

Before this CL:
  :0                    0x4e62d1                48ffc2                  INCQ DX
  :0                    0x4e62d4                48399110010000          CMPQ DX, 0x110(CX)
  :0                    0x4e62db                7e26                    JLE 0x4e6303
  :0                    0x4e62dd                90                      NOPL
  :0                    0x4e62de                bb01000000              MOVL $0x1, BX
  :0                    0x4e62e3                f00fc118                LOCK XADDL BX, 0(AX)
  :0                    0x4e62e7                ffc3                    INCL BX
  :0                    0x4e62e9                0fbae300                BTL $0x0, BX
  :0                    0x4e62ed                733a                    JAE 0x4e6329
  :0                    0x4e62ef                90                      NOPL
  :0                    0x4e62f0                bb01000000              MOVL $0x1, BX
  :0                    0x4e62f5                f00fc118                LOCK XADDL BX, 0(AX)
  :0                    0x4e62f9                ffc3                    INCL BX
  :0                    0x4e62fb                0fbae300                BTL $0x0, BX
  :0                    0x4e62ff                73d0                    JAE 0x4e62d1

After this CL:
  :0                    0x4e6361                48ffc2                  INCQ DX
  :0                    0x4e6364                48399110010000          CMPQ DX, 0x110(CX)
  :0                    0x4e636b                7e26                    JLE 0x4e6393
  :0                    0x4e636d                90                      NOPL
  :0                    0x4e636e                bb01000000              MOVL $0x1, BX
  :0                    0x4e6373                f00fc118                LOCK XADDL BX, 0(AX)
  :0                    0x4e6377                ffc3                    INCL BX
  :0                    0x4e6379                0fbae300                BTL $0x0, BX
  :0                    0x4e637d                733a                    JAE 0x4e63b9
  :0                    0x4e637f                90                      NOPL
  :0                    0x4e6380                bb01000000              MOVL $0x1, BX
  :0                    0x4e6385                f00fc118                LOCK XADDL BX, 0(AX)
  :0                    0x4e6389                ffc3                    INCL BX
  :0                    0x4e638b                0fbae300                BTL $0x0, BX
  :0                    0x4e638f                73d0                    JAE 0x4e6361

PiperOrigin-RevId: 329754148
2020-09-02 11:37:31 -07:00
..
atomicptrtest Standardize on tools directory. 2020-01-27 12:21:00 -08:00
seqatomictest Standardize on tools directory. 2020-01-27 12:21:00 -08:00
BUILD Improve sync.SeqCount performance. 2020-09-02 11:37:31 -07:00
LICENSE New sync package. 2020-01-09 22:02:24 -08:00
README.md New sync package. 2020-01-09 22:02:24 -08:00
aliases.go Fix data-race in endpoint.Readiness 2020-03-25 10:55:22 -07:00
atomicptr_unsafe.go New sync package. 2020-01-09 22:02:24 -08:00
memmove_unsafe.go Bump build constraints to 1.17 2020-08-24 12:58:39 -07:00
mutex_test.go Rename files in //pkg/sync to better reflect what they contain. 2020-04-02 11:57:06 -07:00
mutex_unsafe.go Bump build constraints to 1.17 2020-08-24 12:58:39 -07:00
nocopy.go Do not copy sleep.Waker 2020-07-12 17:22:08 -07:00
norace_unsafe.go New sync package. 2020-01-09 22:02:24 -08:00
race_unsafe.go New sync package. 2020-01-09 22:02:24 -08:00
rwmutex_test.go Rename files in //pkg/sync to better reflect what they contain. 2020-04-02 11:57:06 -07:00
rwmutex_unsafe.go Bump build constraints to 1.17 2020-08-24 12:58:39 -07:00
seqatomic_unsafe.go Improve sync.SeqCount performance. 2020-09-02 11:37:31 -07:00
seqcount.go Improve sync.SeqCount performance. 2020-09-02 11:37:31 -07:00
seqcount_test.go New sync package. 2020-01-09 22:02:24 -08:00
spin_unsafe.go Improve sync.SeqCount performance. 2020-09-02 11:37:31 -07:00
sync.go Rename files in //pkg/sync to better reflect what they contain. 2020-04-02 11:57:06 -07:00

README.md

Syncutil

This package provides additional synchronization primitives not provided by the Go stdlib 'sync' package. It is partially derived from the upstream 'sync' package from go1.10.