Skip to content

Commit 2a4b115

Browse files
committed
Improved alignment
1 parent 4fab38d commit 2a4b115

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

converter.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ def __init__(self):
2525
impls[name].values[x].append(y)
2626

2727
for k, v in impls.items():
28-
for x, y in v.values.items():
28+
for x, y in sorted(v.values.items()):
2929
print(k + " " + str(x) + " " + str(statistics.mean(y)) + " " + str(statistics.stdev(y)))
3030
print()

relaxed_concurrent_fifo/atomic_bitset.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ template <size_t N, typename ARR_TYPE = uint8_t>
2222
class atomic_bitset {
2323
private:
2424
struct wrapper {
25-
alignas(128) std::atomic<ARR_TYPE> atomic;
25+
alignas(std::hardware_destructive_interference_size) std::atomic<ARR_TYPE> atomic;
2626
std::atomic<ARR_TYPE>* operator->() { return &atomic; }
2727
const std::atomic<ARR_TYPE>* operator->() const { return &atomic; }
2828
operator std::atomic<ARR_TYPE>&() { return atomic; }

relaxed_concurrent_fifo/relaxed_fifo.h

+15-18
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,17 @@
77
#include <random>
88
#include <new>
99
#include <optional>
10+
#include <ostream>
1011

1112
#include "atomic_bitset.h"
1213

13-
#include <iostream>
14-
1514
#define LOG_WINDOW_MOVE 0
1615

17-
constexpr size_t CACHE_SIZE =
18-
#if __cpp_lib_hardware_interference_size >= 201603
19-
std::hardware_constructive_interference_size;
20-
#else
21-
64;
22-
#endif // __cpp_lib_hardware_interference_size
16+
#if LOG_WINDOW_MOVE
17+
#include <iostream>
18+
#endif
2319

24-
template <typename T, size_t BLOCKS_PER_WINDOW_RAW = 8, size_t CELLS_PER_BLOCK = CACHE_SIZE / sizeof(T) - 1, typename BITSET_TYPE = uint8_t>
20+
template <typename T, size_t BLOCKS_PER_WINDOW_RAW = 1, size_t CELLS_PER_BLOCK = 7, typename BITSET_TYPE = uint8_t>
2521
class relaxed_fifo {
2622
private:
2723
static constexpr size_t make_po2(size_t size) {
@@ -45,7 +41,7 @@ class relaxed_fifo {
4541
static_assert(sizeof(T) == 8);
4642
static_assert(sizeof(std::atomic<T>) == 8);
4743

48-
struct alignas(8) header_t {
44+
struct header_t {
4945
// 16 bits epoch, 16 bits read started index, 16 bits read finished index, 16 bits write index
5046
std::atomic_uint64_t epoch_and_indices;
5147
};
@@ -65,8 +61,8 @@ class relaxed_fifo {
6561
static_assert(sizeof(block_t) == CELLS_PER_BLOCK * sizeof(T) + sizeof(header_t));
6662

6763
struct window_t {
68-
alignas(128) atomic_bitset<BLOCKS_PER_WINDOW, BITSET_TYPE> filled_set;
69-
alignas(128) block_t blocks[BLOCKS_PER_WINDOW];
64+
alignas(std::hardware_destructive_interference_size) atomic_bitset<BLOCKS_PER_WINDOW, BITSET_TYPE> filled_set;
65+
alignas(std::hardware_destructive_interference_size) block_t blocks[BLOCKS_PER_WINDOW];
7066
};
7167

7268
std::unique_ptr<window_t[]> buffer;
@@ -75,8 +71,8 @@ class relaxed_fifo {
7571
return buffer[index & window_count_mod_mask];
7672
}
7773

78-
alignas(128) std::atomic_uint64_t read_window;
79-
alignas(128) std::atomic_uint64_t write_window;
74+
alignas(std::hardware_destructive_interference_size) std::atomic_uint64_t read_window;
75+
alignas(std::hardware_destructive_interference_size) std::atomic_uint64_t write_window;
8076

8177
public:
8278
// TODO: Remove unused parameter!!
@@ -98,16 +94,17 @@ class relaxed_fifo {
9894
}
9995
}
10096

101-
void debug_print() {
102-
std::cout << "Printing relaxed_fifo:\n"
97+
std::ostream& operator<<(std::ostream& os) const {
98+
os << "Printing relaxed_fifo:\n"
10399
<< "Read: " << read_window << "; Write: " << write_window << '\n';
104100
for (size_t i = 0; i < window_count; i++) {
105101
for (size_t j = 0; j < BLOCKS_PER_WINDOW; j++) {
106102
uint64_t val = buffer[i].blocks[j].header.epoch_and_indices;
107-
std::cout << (val >> 48) << " " << ((val >> 32) & 0xffff) << " " << ((val >> 16) & 0xffff) << " " << (val & 0xffff) << " | ";
103+
os << (val >> 48) << " " << ((val >> 32) & 0xffff) << " " << ((val >> 16) & 0xffff) << " " << (val & 0xffff) << " | ";
108104
}
109-
std::cout << "\n======================\n";
105+
os << "\n======================\n";
110106
}
107+
return os;
111108
}
112109

113110
class handle {

0 commit comments

Comments
 (0)