diff options
author | Ian Lance Taylor <iant@golang.org> | 2017-11-27 15:40:28 -0800 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2018-02-14 17:37:26 +0000 |
commit | 07751f4b582d17289dc19511e2f45d48021f827d (patch) | |
tree | c3f83002fed064981bd82ab18fbca03ab7279177 /src/runtime/os_linux.go | |
parent | ebd4950e3b52dda243baf8330b5cac49125a4a9a (diff) | |
download | go-07751f4b582d17289dc19511e2f45d48021f827d.tar.gz go-07751f4b582d17289dc19511e2f45d48021f827d.zip |
runtime: use private futexes on Linux
By default futexes are permitted in shared memory regions, which
requires the kernel to translate the memory address. Since our futexes
are never in shared memory, set FUTEX_PRIVATE_FLAG, which makes futex
operations slightly more efficient.
Change-Id: I2a82365ed27d5cd8d53c5382ebaca1a720a80952
Reviewed-on: https://go-review.googlesource.com/80144
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Diffstat (limited to 'src/runtime/os_linux.go')
-rw-r--r-- | src/runtime/os_linux.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/runtime/os_linux.go b/src/runtime/os_linux.go index 2e442192cc..7231cf1226 100644 --- a/src/runtime/os_linux.go +++ b/src/runtime/os_linux.go @@ -24,8 +24,9 @@ func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, // Futexsleep is allowed to wake up spuriously. const ( - _FUTEX_WAIT = 0 - _FUTEX_WAKE = 1 + _FUTEX_PRIVATE_FLAG = 128 + _FUTEX_WAIT_PRIVATE = 0 | _FUTEX_PRIVATE_FLAG + _FUTEX_WAKE_PRIVATE = 1 | _FUTEX_PRIVATE_FLAG ) // Atomically, @@ -42,7 +43,7 @@ func futexsleep(addr *uint32, val uint32, ns int64) { // here, and so can we: as it says a few lines up, // spurious wakeups are allowed. if ns < 0 { - futex(unsafe.Pointer(addr), _FUTEX_WAIT, val, nil, nil, 0) + futex(unsafe.Pointer(addr), _FUTEX_WAIT_PRIVATE, val, nil, nil, 0) return } @@ -59,13 +60,13 @@ func futexsleep(addr *uint32, val uint32, ns int64) { ts.tv_nsec = 0 ts.set_sec(int64(timediv(ns, 1000000000, (*int32)(unsafe.Pointer(&ts.tv_nsec))))) } - futex(unsafe.Pointer(addr), _FUTEX_WAIT, val, unsafe.Pointer(&ts), nil, 0) + futex(unsafe.Pointer(addr), _FUTEX_WAIT_PRIVATE, val, unsafe.Pointer(&ts), nil, 0) } // If any procs are sleeping on addr, wake up at most cnt. //go:nosplit func futexwakeup(addr *uint32, cnt uint32) { - ret := futex(unsafe.Pointer(addr), _FUTEX_WAKE, cnt, nil, nil, 0) + ret := futex(unsafe.Pointer(addr), _FUTEX_WAKE_PRIVATE, cnt, nil, nil, 0) if ret >= 0 { return } |