Skip to content

Commit 8d412de

Browse files
committed
dpdk: fix RSS configuration
Previously, RSS was set to RTE_ETH_RSS_IP, which is not supported by all NICs. This update allows configuring RSS to a subset of RTE_ETH_RSS_IP, ensuring better compatibility.
1 parent 24ce625 commit 8d412de

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

input/dpdk/dpdkDevice.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,7 @@ rte_eth_conf DpdkDevice::createPortConfig()
148148
#endif
149149

150150
if (m_supportedRSS) {
151-
#if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
152151
portConfig.rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
153-
#else
154-
portConfig.rxmode.mq_mode = ETH_MQ_RX_RSS;
155-
#endif
156152
} else {
157153
portConfig.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
158154
}
@@ -219,25 +215,36 @@ void DpdkDevice::configureRSS()
219215
return;
220216
}
221217

222-
constexpr size_t RSS_KEY_LEN = 40;
223-
// biflow hash key
224-
static uint8_t rssKey[RSS_KEY_LEN]
225-
= {0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
226-
0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
227-
0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A};
218+
rte_eth_dev_info rteDevInfo;
219+
if (rte_eth_dev_info_get(m_portID, &rteDevInfo)) {
220+
throw PluginError("DpdkDevice::configureRSS() has failed. Unable to get rte dev info");
221+
}
228222

229-
struct rte_eth_rss_conf rssConfig
230-
= {.rss_key = rssKey,
231-
.rss_key_len = RSS_KEY_LEN,
232-
#if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
233-
.rss_hf = RTE_ETH_RSS_IP,
234-
#else
235-
.rss_hf = ETH_RSS_IP,
236-
#endif
237-
};
223+
const uint8_t rssHashKeySize = rteDevInfo.hash_key_size;
224+
225+
m_hashKey.resize(rssHashKeySize);
226+
std::generate(
227+
m_hashKey.begin(),
228+
m_hashKey.end(),
229+
[idx = static_cast<std::size_t>(0)]() mutable {
230+
static const std::array<uint8_t, 2> hashKey = {0x6D, 0x5A};
231+
return hashKey[idx++ % sizeof(hashKey)];
232+
});
233+
234+
const uint64_t rssOffloads = rteDevInfo.flow_type_rss_offloads & RTE_ETH_RSS_IP;
235+
if (rssOffloads != RTE_ETH_RSS_IP) {
236+
std::cerr << "RTE_ETH_RSS_IP is not supported by the card. Used subset: " << rssOffloads << std::endl;
237+
}
238+
239+
struct rte_eth_rss_conf rssConfig = {};
240+
rssConfig.rss_key = m_hashKey.data();
241+
rssConfig.rss_key_len = rssHashKeySize;
242+
rssConfig.rss_hf = rssOffloads;
238243

239-
if (rte_eth_dev_rss_hash_update(m_portID, &rssConfig)) {
240-
std::cerr << "Setting RSS hash for port " << m_portID << "." << std::endl;
244+
int ret = rte_eth_dev_rss_hash_update(m_portID, &rssConfig);
245+
if (ret < 0) {
246+
std::cerr << "Setting RSS {" << rssOffloads << "} for port " << m_portID << " failed. Errno:" << ret << std::endl;
247+
throw PluginError("DpdkDevice::configureRSS() has failed.");
241248
}
242249
}
243250

input/dpdk/dpdkDevice.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#pragma once
2727

2828
#include "dpdkMbuf.hpp"
29+
#include "dpdkCompat.hpp"
2930

3031
#include <rte_ethdev.h>
3132
#include <rte_mempool.h>
@@ -84,7 +85,8 @@ class DpdkDevice {
8485
void registerRxTimestamp();
8586

8687
std::vector<rte_mempool*> m_memPools;
87-
uint16_t m_portID;
88+
std::vector<uint8_t> m_hashKey;
89+
uint16_t m_portID;
8890
uint16_t m_rxQueueCount;
8991
uint16_t m_txQueueCount;
9092
uint16_t m_mBufsCount;

0 commit comments

Comments
 (0)