Commit d1ef780f authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Cut FOLLY_CACHE_LINE_SIZE

Summary:
[Folly] Cut `FOLLY_CACHE_LINE_SIZE` macro, replacing uses with `folly::hardware_destructive_interference_size`.

As one oddity, `FOLLY_CACHE_LINE_SIZE` had value 64 while `folly::hardware_destructive_interference_size` has value 128, so some types may get larger.

Reviewed By: aary

Differential Revision: D14574695

fbshipit-source-id: 7c5b9e313c5dcdecfec3cc47ec7bd55d08ae762c
parent f11ea4c6
...@@ -118,9 +118,6 @@ static_assert( ...@@ -118,9 +118,6 @@ static_assert(
* contention is unlikely. * contention is unlikely.
*/ */
// TODO: generate it from configure (`getconf LEVEL1_DCACHE_LINESIZE`)
#define FOLLY_CACHE_LINE_SIZE 64
template <class T, size_t N> template <class T, size_t N>
struct alignas(max_align_v) SpinLockArray { struct alignas(max_align_v) SpinLockArray {
T& operator[](size_t i) noexcept { T& operator[](size_t i) noexcept {
...@@ -139,19 +136,20 @@ struct alignas(max_align_v) SpinLockArray { ...@@ -139,19 +136,20 @@ struct alignas(max_align_v) SpinLockArray {
struct PaddedSpinLock { struct PaddedSpinLock {
PaddedSpinLock() : lock() {} PaddedSpinLock() : lock() {}
T lock; T lock;
char padding[FOLLY_CACHE_LINE_SIZE - sizeof(T)]; char padding[hardware_destructive_interference_size - sizeof(T)];
}; };
static_assert( static_assert(
sizeof(PaddedSpinLock) == FOLLY_CACHE_LINE_SIZE, sizeof(PaddedSpinLock) == hardware_destructive_interference_size,
"Invalid size of PaddedSpinLock"); "Invalid size of PaddedSpinLock");
// Check if T can theoretically cross a cache line. // Check if T can theoretically cross a cache line.
static_assert( static_assert(
max_align_v > 0 && FOLLY_CACHE_LINE_SIZE % max_align_v == 0 && max_align_v > 0 &&
hardware_destructive_interference_size % max_align_v == 0 &&
sizeof(T) <= max_align_v, sizeof(T) <= max_align_v,
"T can cross cache line boundaries"); "T can cross cache line boundaries");
char padding_[FOLLY_CACHE_LINE_SIZE]; char padding_[hardware_destructive_interference_size];
std::array<PaddedSpinLock, N> data_; std::array<PaddedSpinLock, N> data_;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment