From 86781963cc2bf0d3dbd1eccebd8a2f080846f3ee Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sun, 29 Sep 2024 04:24:00 +0200 Subject: runtime: align vgetrandom states to cache line MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents false sharing, which makes a large difference on machines with several NUMA nodes, such as this dual socket server: cpu: Intel(R) Xeon(R) Gold 6338 CPU @ 2.00GHz │ sec/op │ sec/op vs base │ ParallelGetRandom-128 0.7944n ± 5% 0.4503n ± 0% -43.31% (p=0.000 n=10) │ B/s │ B/s vs base │ ParallelGetRandom-128 4.690Gi ± 5% 8.272Gi ± 0% +76.38% (p=0.000 n=10) Change-Id: Id4421e9a4c190b38aff0be4c59e9067b0a38ccd7 Reviewed-on: https://go-review.googlesource.com/c/go/+/616535 LUCI-TryBot-Result: Go LUCI Auto-Submit: Jason Donenfeld Reviewed-by: David Chase Reviewed-by: Michael Pratt --- src/internal/syscall/unix/getrandom_linux_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/internal/syscall/unix/getrandom_linux_test.go (limited to 'src/internal') diff --git a/src/internal/syscall/unix/getrandom_linux_test.go b/src/internal/syscall/unix/getrandom_linux_test.go new file mode 100644 index 0000000000..e1778c19e8 --- /dev/null +++ b/src/internal/syscall/unix/getrandom_linux_test.go @@ -0,0 +1,22 @@ +// Copyright 2024 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package unix_test + +import ( + "internal/syscall/unix" + "testing" +) + +func BenchmarkParallelGetRandom(b *testing.B) { + b.SetBytes(4) + b.RunParallel(func(pb *testing.PB) { + var buf [4]byte + for pb.Next() { + if _, err := unix.GetRandom(buf[:], 0); err != nil { + b.Fatal(err) + } + } + }) +} -- cgit v1.3