Skip to content

Commit 82958b1

Browse files
authored
Merge pull request #246 from CESNET/dpdk-rss
dpdk: fix RSS configuration
2 parents 10fea0b + 8d412de commit 82958b1

File tree

4 files changed

+127
-22
lines changed

4 files changed

+127
-22
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ ipfixprobe_input_src+=\
180180
input/dpdk/dpdkMbuf.cpp \
181181
input/dpdk/dpdkDevice.hpp \
182182
input/dpdk/dpdkDevice.cpp \
183+
input/dpdk/dpdkCompat.hpp \
183184
input/dpdk.cpp \
184185
input/dpdk.h \
185186
input/dpdk-ring.cpp \

input/dpdk/dpdkCompat.hpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* \file
3+
* \brief Compatible definitions for DPDK versions.
4+
* \author Pavel Siska <[email protected]>
5+
* \date 2024
6+
*/
7+
/*
8+
* Copyright (C) 2024 CESNET
9+
*
10+
* LICENSE TERMS
11+
*
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions
14+
* are met:
15+
* 1. Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright
18+
* notice, this list of conditions and the following disclaimer in
19+
* the documentation and/or other materials provided with the
20+
* distribution.
21+
* 3. Neither the name of the Company nor the names of its contributors
22+
* may be used to endorse or promote products derived from this
23+
* software without specific prior written permission.
24+
*/
25+
26+
#include <rte_ethdev.h>
27+
#include <rte_version.h>
28+
29+
#if RTE_VERSION < RTE_VERSION_NUM(22, 0, 0, 0)
30+
#define RTE_ETH_MQ_RX_RSS ETH_MQ_RX_RSS
31+
#endif
32+
33+
#if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0)
34+
#define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE DEV_TX_OFFLOAD_MBUF_FAST_FREE
35+
36+
#define RTE_ETH_RX_OFFLOAD_CHECKSUM DEV_RX_OFFLOAD_CHECKSUM
37+
38+
#define RTE_ETH_RX_OFFLOAD_VLAN_STRIP DEV_RX_OFFLOAD_VLAN_STRIP
39+
#define RTE_ETH_RX_OFFLOAD_IPV4_CKSUM DEV_RX_OFFLOAD_IPV4_CKSUM
40+
#define RTE_ETH_RX_OFFLOAD_UDP_CKSUM DEV_RX_OFFLOAD_UDP_CKSUM
41+
#define RTE_ETH_RX_OFFLOAD_TCP_CKSUM DEV_RX_OFFLOAD_TCP_CKSUM
42+
#define RTE_ETH_RX_OFFLOAD_TCP_LRO DEV_RX_OFFLOAD_TCP_LRO
43+
#define RTE_ETH_RX_OFFLOAD_QINQ_STRIP DEV_RX_OFFLOAD_QINQ_STRIP
44+
#define RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM
45+
#define RTE_ETH_RX_OFFLOAD_MACSEC_STRIP DEV_RX_OFFLOAD_MACSEC_STRIP
46+
#define RTE_ETH_RX_OFFLOAD_HEADER_SPLIT DEV_RX_OFFLOAD_HEADER_SPLIT
47+
#define RTE_ETH_RX_OFFLOAD_VLAN_FILTER DEV_RX_OFFLOAD_VLAN_FILTER
48+
#define RTE_ETH_RX_OFFLOAD_VLAN_EXTEND DEV_RX_OFFLOAD_VLAN_EXTEND
49+
#define RTE_ETH_RX_OFFLOAD_SCATTER DEV_RX_OFFLOAD_SCATTER
50+
#define RTE_ETH_RX_OFFLOAD_TIMESTAMP DEV_RX_OFFLOAD_TIMESTAMP
51+
#define RTE_ETH_RX_OFFLOAD_SECURITY DEV_RX_OFFLOAD_SECURITY
52+
#define RTE_ETH_RX_OFFLOAD_KEEP_CRC DEV_RX_OFFLOAD_KEEP_CRC
53+
#define RTE_ETH_RX_OFFLOAD_SCTP_CKSUM DEV_RX_OFFLOAD_SCTP_CKSUM
54+
#define RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM DEV_RX_OFFLOAD_OUTER_UDP_CKSUM
55+
#define RTE_ETH_RX_OFFLOAD_RSS_HASH DEV_RX_OFFLOAD_RSS_HASH
56+
57+
#define RTE_ETH_MQ_TX_NONE ETH_MQ_TX_NONE
58+
59+
#define RTE_ETH_MQ_RX_NONE ETH_MQ_RX_NONE
60+
61+
#define RTE_ETH_RSS_IP ETH_RSS_IP
62+
#define RTE_ETH_RSS_UDP ETH_RSS_UDP
63+
#define RTE_ETH_RSS_TCP ETH_RSS_TCP
64+
#define RTE_ETH_RSS_SCTP ETH_RSS_SCTP
65+
#define RTE_ETH_RSS_TUNNEL ETH_RSS_TUNNEL
66+
67+
#define RTE_ETH_RSS_L3_SRC_ONLY ETH_RSS_L3_SRC_ONLY
68+
#define RTE_ETH_RSS_L3_DST_ONLY ETH_RSS_L3_DST_ONLY
69+
#define RTE_ETH_RSS_L4_SRC_ONLY ETH_RSS_L4_SRC_ONLY
70+
#define RTE_ETH_RSS_L4_DST_ONLY ETH_RSS_L4_DST_ONLY
71+
72+
#define RTE_ETH_RSS_IPV4 ETH_RSS_IPV4
73+
#define RTE_ETH_RSS_FRAG_IPV4 ETH_RSS_FRAG_IPV4
74+
#define RTE_ETH_RSS_NONFRAG_IPV4_TCP ETH_RSS_NONFRAG_IPV4_TCP
75+
#define RTE_ETH_RSS_NONFRAG_IPV4_UDP ETH_RSS_NONFRAG_IPV4_UDP
76+
#define RTE_ETH_RSS_NONFRAG_IPV4_SCTP ETH_RSS_NONFRAG_IPV4_SCTP
77+
#define RTE_ETH_RSS_NONFRAG_IPV4_OTHER ETH_RSS_NONFRAG_IPV4_OTHER
78+
#define RTE_ETH_RSS_IPV6 ETH_RSS_IPV6
79+
#define RTE_ETH_RSS_FRAG_IPV6 ETH_RSS_FRAG_IPV6
80+
#define RTE_ETH_RSS_NONFRAG_IPV6_TCP ETH_RSS_NONFRAG_IPV6_TCP
81+
#define RTE_ETH_RSS_NONFRAG_IPV6_UDP ETH_RSS_NONFRAG_IPV6_UDP
82+
#define RTE_ETH_RSS_NONFRAG_IPV6_SCTP ETH_RSS_NONFRAG_IPV6_SCTP
83+
#define RTE_ETH_RSS_NONFRAG_IPV6_OTHER ETH_RSS_NONFRAG_IPV6_OTHER
84+
#define RTE_ETH_RSS_L2_PAYLOAD ETH_RSS_L2_PAYLOAD
85+
#define RTE_ETH_RSS_IPV6_EX ETH_RSS_IPV6_EX
86+
#define RTE_ETH_RSS_IPV6_TCP_EX ETH_RSS_IPV6_TCP_EX
87+
#define RTE_ETH_RSS_IPV6_UDP_EX ETH_RSS_IPV6_UDP_EX
88+
#define RTE_ETH_RSS_PORT ETH_RSS_PORT
89+
#define RTE_ETH_RSS_VXLAN ETH_RSS_VXLAN
90+
#define RTE_ETH_RSS_NVGRE ETH_RSS_NVGRE
91+
#define RTE_ETH_RSS_GTPU ETH_RSS_GTPU
92+
93+
#define RTE_BIT64(nr) (UINT64_C(1) << (nr))
94+
95+
#endif

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)