]> Cypherpunks repositories - gostls13.git/commitdiff
internal/cpu: add a CacheLinePadSize constant
authorMartin Möhrmann <moehrmann@google.com>
Fri, 24 Aug 2018 15:07:20 +0000 (17:07 +0200)
committerMartin Möhrmann <moehrmann@google.com>
Fri, 24 Aug 2018 17:45:28 +0000 (17:45 +0000)
The new constant CacheLinePadSize can be used to compute best effort
alignment of structs to cache lines.

e.g. the runtime can use this in the locktab definition:
var locktab [57]struct {
        l   spinlock
        pad [cpu.CacheLinePadSize - unsafe.Sizeof(spinlock{})]byte
}

Change-Id: I86f6fbfc5ee7436f742776a7d4a99a1d54ffccc8
Reviewed-on: https://go-review.googlesource.com/131237
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/internal/cpu/cpu.go
src/internal/cpu/cpu_arm.go
src/internal/cpu/cpu_arm64.go
src/internal/cpu/cpu_mips.go
src/internal/cpu/cpu_mips64.go
src/internal/cpu/cpu_mips64le.go
src/internal/cpu/cpu_mipsle.go
src/internal/cpu/cpu_ppc64x.go
src/internal/cpu/cpu_s390x.go
src/internal/cpu/cpu_wasm.go
src/internal/cpu/cpu_x86.go

index 2b5db91fe2b2257cd5672b7248e17916c61cd22d..5363f11b90839c3ba8209a9a857e1dac67519a8c 100644 (file)
@@ -12,7 +12,12 @@ package cpu
 var DebugOptions bool
 
 // CacheLinePad is used to pad structs to avoid false sharing.
-type CacheLinePad struct{ _ [CacheLineSize]byte }
+type CacheLinePad struct{ _ [CacheLinePadSize]byte }
+
+// CacheLineSize is the CPU's assumed cache line size.
+// There is currently no runtime detection of the real cache line size
+// so we use the constant per GOARCH CacheLinePadSize as an approximation.
+var CacheLineSize = CacheLinePadSize
 
 var X86 x86
 
index b9baa44fea6f0aec61867e27ba3b346d8484f932..6a5b30580c94ec0efdd14caa5793c3e115062ac1 100644 (file)
@@ -4,7 +4,7 @@
 
 package cpu
 
-const CacheLineSize = 32
+const CacheLinePadSize = 32
 
 // arm doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
 // These are linknamed in runtime/os_(linux|freebsd)_arm.go and are
index 77b617e49f18bd1f1e7d192b892a3ad9edefc6d0..ad930af005f11263505e7f2cf1186f3bbff291f7 100644 (file)
@@ -4,7 +4,7 @@
 
 package cpu
 
-const CacheLineSize = 64
+const CacheLinePadSize = 64
 
 // arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
 // These are initialized by archauxv in runtime/os_linux_arm64.go.
index 078a6c3b80a28d6049ad5dd50932d46413618918..0f821e44e7798637c89de872f23ea81f27006834 100644 (file)
@@ -4,4 +4,4 @@
 
 package cpu
 
-const CacheLineSize = 32
+const CacheLinePadSize = 32
index 078a6c3b80a28d6049ad5dd50932d46413618918..0f821e44e7798637c89de872f23ea81f27006834 100644 (file)
@@ -4,4 +4,4 @@
 
 package cpu
 
-const CacheLineSize = 32
+const CacheLinePadSize = 32
index 078a6c3b80a28d6049ad5dd50932d46413618918..0f821e44e7798637c89de872f23ea81f27006834 100644 (file)
@@ -4,4 +4,4 @@
 
 package cpu
 
-const CacheLineSize = 32
+const CacheLinePadSize = 32
index 078a6c3b80a28d6049ad5dd50932d46413618918..0f821e44e7798637c89de872f23ea81f27006834 100644 (file)
@@ -4,4 +4,4 @@
 
 package cpu
 
-const CacheLineSize = 32
+const CacheLinePadSize = 32
index d3f02efa7ff615cd2db190fa29dfd3796c9f93dd..0195e663c60d73c0d8e0b73ad5d47e302ed45c13 100644 (file)
@@ -6,7 +6,7 @@
 
 package cpu
 
-const CacheLineSize = 128
+const CacheLinePadSize = 128
 
 // ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2.
 // These are initialized by archauxv in runtime/os_linux_ppc64x.go.
index 0a12922045e4d021e6f478a888d408d30e2cfff7..23484b2950878de59cd16badec7383e616876a29 100644 (file)
@@ -4,7 +4,7 @@
 
 package cpu
 
-const CacheLineSize = 256
+const CacheLinePadSize = 256
 
 // bitIsSet reports whether the bit at index is set. The bit index
 // is in big endian order, so bit index 0 is the leftmost bit.
index 1107a7ad6f7adefce445b69bc541684773a2e8b3..b45973877051094511bba027cb6a92ff79fedac0 100644 (file)
@@ -4,4 +4,4 @@
 
 package cpu
 
-const CacheLineSize = 64
+const CacheLinePadSize = 64
index 7d9d3aaf76028c28d658a61aae2af04bd6ae6a39..0b00779a906411d49047f613994d04d2760f3248 100644 (file)
@@ -6,7 +6,7 @@
 
 package cpu
 
-const CacheLineSize = 64
+const CacheLinePadSize = 64
 
 // cpuid is implemented in cpu_x86.s.
 func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32)