Skip to content

Commit 72cf1a7

Browse files
authored
Merge pull request #220 from CESNET/prefetch-optimizations
Prefetch optimizations
2 parents 9d4f9aa + 419eba0 commit 72cf1a7

File tree

4 files changed

+19
-1
lines changed

4 files changed

+19
-1
lines changed

input/dpdk-ring.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ InputPlugin::Result DpdkRingReader::get(PacketBlock& packets)
196196
if (pkts_read_ == 0) {
197197
return Result::TIMEOUT;
198198
}
199+
prefetchPackets();
199200
for (auto i = 0; i < pkts_read_; i++) {
200201
parse_packet(&opt,
201202
m_parser_stats,
@@ -256,4 +257,11 @@ void DpdkRingReader::getDynfieldInfo()
256257
}
257258
}
258259

260+
void DpdkRingReader::prefetchPackets() {
261+
for (auto i = 0; i < pkts_read_; i++) {
262+
__builtin_prefetch(mbufs_[i], 0, 2);
263+
__builtin_prefetch((uint8_t*)mbufs_[i] + 64, 0, 2);
264+
}
265+
}
266+
259267
} // namespace ipxp

input/dpdk-ring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class DpdkRingReader : public InputPlugin {
152152

153153
telemetry::Content get_queue_telemetry();
154154
void getDynfieldInfo();
155+
void prefetchPackets();
155156

156157
std::vector<rte_mbuf *> mbufs_;
157158
std::uint16_t pkts_read_;

storage/cache.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ int NHTFlowCache::put_pkt(Packet &pkt)
327327
return 0;
328328
}
329329

330+
prefetch_export_expired();
331+
330332
uint64_t hashval = XXH64(m_key, m_keylen, 0); /* Calculates hash value from key created before. */
331333

332334
FlowRecord *flow; /* Pointer to flow we will be working with. */
@@ -650,4 +652,10 @@ telemetry::Content NHTFlowCache::get_cache_telemetry()
650652
return dict;
651653
}
652654

655+
void NHTFlowCache::prefetch_export_expired() const
656+
{
657+
for (decltype(m_timeout_idx) i = m_timeout_idx; i < m_timeout_idx + m_line_new_idx; i++) {
658+
__builtin_prefetch(m_flow_table[i], 0, 1);
659+
}
660+
}
653661
}

storage/cache.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class CacheOptParser : public OptionsParser
159159
}
160160
};
161161

162-
class FlowRecord
162+
class alignas(64) FlowRecord
163163
{
164164
uint64_t m_hash;
165165

@@ -257,6 +257,7 @@ class NHTFlowCache : TelemetryUtils, public StoragePlugin
257257
void update_flow_end_reason_stats(uint8_t reason);
258258
void update_flow_record_stats(uint64_t packets_count);
259259
telemetry::Content get_cache_telemetry();
260+
void prefetch_export_expired() const;
260261

261262
#ifdef FLOW_CACHE_STATS
262263
void print_report();

0 commit comments

Comments
 (0)