Skip to content

Commit b185e49

Browse files
Zainullin DamirZainullin Damir
authored andcommitted
++
1 parent 80236e1 commit b185e49

6 files changed

Lines changed: 19 additions & 40 deletions

File tree

include/ipfixprobe/outputPlugin/outputStorage/b2OutputStorage.hpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,6 @@ class B2OutputStorage : public BOutputStorage<ElementType> {
112112
typename BOutputStorage<ElementType>::ReaderData& readerData
113113
= this->m_readersData[readerIndex].get();
114114
if (readerData.bucketAllocation.containersLeft()) {
115-
__builtin_prefetch(
116-
&this->m_storage
117-
[readerData.bucketAllocation.bucketIndex * this->BUCKET_SIZE
118-
+ readerData.bucketAllocation.containerIndex + 1],
119-
PrefetchMode::Read,
120-
Locality::High);
121115
return &this->getNextElement(readerData.bucketAllocation).getData();
122116
}
123117

@@ -126,10 +120,10 @@ class B2OutputStorage : public BOutputStorage<ElementType> {
126120
BackoffScheme backoffScheme(0, std::numeric_limits<std::size_t>::max());
127121
do {
128122
const bool overflowed = readerData.shift(this->m_expectedReadersCount, readerIndex);
129-
__builtin_prefetch(
123+
/*__builtin_prefetch(
130124
&this->m_buckets[readerData.readPosition + this->m_expectedReadersCount],
131125
PrefetchMode::Write,
132-
Locality::High);
126+
Locality::High);*/
133127
if (overflowed) {
134128
if (!this->writersPresent()) {
135129
readerData.generation.fetch_add(1, std::memory_order_release);

include/ipfixprobe/outputPlugin/outputStorage/ffq2OutputStorage.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class FFQ2OutputStorage : public FFQOutputStorage<ElementType> {
3030
BackoffScheme backoffScheme(70, std::numeric_limits<std::size_t>::max());
3131
const uint64_t writeRank = this->m_writeRank->fetch_add(1, std::memory_order_acq_rel);
3232
const uint64_t writeIndex = remap(writeRank) % OutputStorage<ElementType>::STORAGE_CAPACITY;
33-
__builtin_prefetch(&this->m_cells[writeIndex + 1], PrefetchMode::Write, Locality::High);
3433
while (!this->m_cells[writeIndex].state.tryToSetWriter()) {
3534
backoffScheme.backoff();
3635
}
@@ -53,7 +52,6 @@ class FFQ2OutputStorage : public FFQOutputStorage<ElementType> {
5352
}
5453
const uint64_t readRank = this->m_readRank->fetch_add(1, std::memory_order_acq_rel);
5554
const uint64_t readIndex = remap(readRank) % OutputStorage<ElementType>::STORAGE_CAPACITY;
56-
__builtin_prefetch(&this->m_cells[readIndex + 1], PrefetchMode::Write, Locality::High);
5755
while (readRank >= this->m_writeRank->load(std::memory_order_acquire)
5856
&& this->writersPresent()) {
5957
backoffScheme.backoff();

include/ipfixprobe/outputPlugin/outputStorage/lfnbOutputStorage.hpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ class LFNBOutputStorage : public OutputStorage<ElementType> {
3636
= sequentialWritePosition % OutputStorage<ElementType>::STORAGE_CAPACITY;
3737
const uint64_t remappedWritePosition
3838
= remap(writePosition) % OutputStorage<ElementType>::STORAGE_CAPACITY;
39-
const uint64_t nextRemappedWritePosition
40-
= remap(writePosition + 1) % OutputStorage<ElementType>::STORAGE_CAPACITY;
41-
__builtin_prefetch(
42-
&this->m_storage[nextRemappedWritePosition],
43-
PrefetchMode::Write,
44-
Locality::High);
45-
__builtin_prefetch(
46-
&this->m_writersFinished[nextRemappedWritePosition / BUCKET_SIZE],
47-
PrefetchMode::Write,
48-
Locality::High);
49-
__builtin_prefetch(
50-
&this->m_readersFinished[nextRemappedWritePosition / BUCKET_SIZE],
51-
PrefetchMode::Write,
52-
Locality::High);
5339
BackoffScheme backoffScheme(0, std::numeric_limits<std::size_t>::max());
5440
while (m_writersFinished[writePosition / BUCKET_SIZE].load(std::memory_order_acquire)
5541
/ BUCKET_SIZE
@@ -79,21 +65,7 @@ class LFNBOutputStorage : public OutputStorage<ElementType> {
7965
const uint64_t readPosition
8066
= sequentialReadPosition % OutputStorage<ElementType>::STORAGE_CAPACITY;
8167
const uint64_t remappedReadPosition
82-
= remap(sequentialReadPosition) % OutputStorage<ElementType>::STORAGE_CAPACITY;
83-
const uint64_t nextRemappedReadPosition
84-
= remap(readPosition + 1) % OutputStorage<ElementType>::STORAGE_CAPACITY;
85-
__builtin_prefetch(
86-
&this->m_storage[nextRemappedReadPosition],
87-
PrefetchMode::Write,
88-
Locality::High);
89-
__builtin_prefetch(
90-
&this->m_writersFinished[nextRemappedReadPosition / BUCKET_SIZE],
91-
PrefetchMode::Write,
92-
Locality::High);
93-
__builtin_prefetch(
94-
&this->m_readersFinished[nextRemappedReadPosition / BUCKET_SIZE],
95-
PrefetchMode::Write,
96-
Locality::High);
68+
= remap(readPosition) % OutputStorage<ElementType>::STORAGE_CAPACITY;
9769
BackoffScheme backoffScheme(0, std::numeric_limits<std::size_t>::max());
9870
while ((m_readersFinished[readPosition / BUCKET_SIZE].load(std::memory_order_acquire)
9971
/ (BUCKET_SIZE * 1)

include/ipfixprobe/outputPlugin/outputStorage/mq2OutputStorage.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,14 @@ class MQ2OutputStorage : public MQOutputStorage<ElementType> {
5353
BackoffScheme backoff(30, std::numeric_limits<std::size_t>::max());
5454
while (true) {
5555
const uint8_t sequenceIndex = this->m_readersData[readerIndex]->sequenceIndex++;
56+
const uint8_t nextSequenceIndex = sequenceIndex + 1;
5657
const uint8_t queueIndex
5758
= this->m_readersData[readerIndex]->queueJumpSequence
5859
[sequenceIndex % OutputStorage<ElementType>::MAX_WRITERS_COUNT];
60+
const uint8_t nextQueueIndex
61+
= this->m_readersData[readerIndex]->queueJumpSequence
62+
[nextSequenceIndex % OutputStorage<ElementType>::MAX_WRITERS_COUNT];
63+
this->m_queues[nextQueueIndex].prefetch();
5964
auto* element = this->m_queues[queueIndex].tryRead();
6065
if (element != nullptr) {
6166
return element;

include/ipfixprobe/outputPlugin/outputStorage/mqOutputStorage.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ class MQOutputStorage : public OutputStorage<ElementType> {
186186
>= m_buffersSize + currentState.written.load(std::memory_order_acquire);
187187
}
188188

189+
void prefetch() const noexcept
190+
{
191+
const State& currentState = m_stateBuffer.getCurrentValue();
192+
__builtin_prefetch(
193+
&currentState.writeBuffer[currentState.written],
194+
PrefetchMode::Read,
195+
Locality::High);
196+
}
197+
189198
private:
190199
struct State {
191200
std::atomic<uint64_t> written {0};

include/ipfixprobe/outputPlugin/outputStorage/outputStorage.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ enum class PrefetchMode : int { Read = 0, Write = 1 };
1717

1818
enum class Locality : int { None = 0, Low = 1, Medium = 2, High = 3 };
1919

20+
[[gnu::always_inline]]
2021
constexpr std::size_t remap(const std::size_t index) noexcept
2122
{
2223
return index;
2324
// return index * 27644437;
2425
// return ~index;
25-
// return std::byteswap(index);
26+
// return std::byteswap(index) >> 48;
2627
}
2728

2829
template<typename ElementType>

0 commit comments

Comments
 (0)