Skip to content

Commit

Permalink
Merge pull request #246 from CESNET/dpdk-rss
Browse files Browse the repository at this point in the history
dpdk: fix RSS configuration
  • Loading branch information
SiskaPavel authored Dec 27, 2024
2 parents 10fea0b + 8d412de commit 82958b1
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 22 deletions.
1 change: 1 addition & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ ipfixprobe_input_src+=\
input/dpdk/dpdkMbuf.cpp \
input/dpdk/dpdkDevice.hpp \
input/dpdk/dpdkDevice.cpp \
input/dpdk/dpdkCompat.hpp \
input/dpdk.cpp \
input/dpdk.h \
input/dpdk-ring.cpp \
Expand Down
95 changes: 95 additions & 0 deletions input/dpdk/dpdkCompat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* \file
* \brief Compatible definitions for DPDK versions.
* \author Pavel Siska <[email protected]>
* \date 2024
*/
/*
* Copyright (C) 2024 CESNET
*
* LICENSE TERMS
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name of the Company nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*/

#include <rte_ethdev.h>
#include <rte_version.h>

#if RTE_VERSION < RTE_VERSION_NUM(22, 0, 0, 0)
#define RTE_ETH_MQ_RX_RSS ETH_MQ_RX_RSS
#endif

#if RTE_VERSION < RTE_VERSION_NUM(21, 11, 0, 0)
#define RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE DEV_TX_OFFLOAD_MBUF_FAST_FREE

#define RTE_ETH_RX_OFFLOAD_CHECKSUM DEV_RX_OFFLOAD_CHECKSUM

#define RTE_ETH_RX_OFFLOAD_VLAN_STRIP DEV_RX_OFFLOAD_VLAN_STRIP
#define RTE_ETH_RX_OFFLOAD_IPV4_CKSUM DEV_RX_OFFLOAD_IPV4_CKSUM
#define RTE_ETH_RX_OFFLOAD_UDP_CKSUM DEV_RX_OFFLOAD_UDP_CKSUM
#define RTE_ETH_RX_OFFLOAD_TCP_CKSUM DEV_RX_OFFLOAD_TCP_CKSUM
#define RTE_ETH_RX_OFFLOAD_TCP_LRO DEV_RX_OFFLOAD_TCP_LRO
#define RTE_ETH_RX_OFFLOAD_QINQ_STRIP DEV_RX_OFFLOAD_QINQ_STRIP
#define RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM DEV_RX_OFFLOAD_OUTER_IPV4_CKSUM
#define RTE_ETH_RX_OFFLOAD_MACSEC_STRIP DEV_RX_OFFLOAD_MACSEC_STRIP
#define RTE_ETH_RX_OFFLOAD_HEADER_SPLIT DEV_RX_OFFLOAD_HEADER_SPLIT
#define RTE_ETH_RX_OFFLOAD_VLAN_FILTER DEV_RX_OFFLOAD_VLAN_FILTER
#define RTE_ETH_RX_OFFLOAD_VLAN_EXTEND DEV_RX_OFFLOAD_VLAN_EXTEND
#define RTE_ETH_RX_OFFLOAD_SCATTER DEV_RX_OFFLOAD_SCATTER
#define RTE_ETH_RX_OFFLOAD_TIMESTAMP DEV_RX_OFFLOAD_TIMESTAMP
#define RTE_ETH_RX_OFFLOAD_SECURITY DEV_RX_OFFLOAD_SECURITY
#define RTE_ETH_RX_OFFLOAD_KEEP_CRC DEV_RX_OFFLOAD_KEEP_CRC
#define RTE_ETH_RX_OFFLOAD_SCTP_CKSUM DEV_RX_OFFLOAD_SCTP_CKSUM
#define RTE_ETH_RX_OFFLOAD_OUTER_UDP_CKSUM DEV_RX_OFFLOAD_OUTER_UDP_CKSUM
#define RTE_ETH_RX_OFFLOAD_RSS_HASH DEV_RX_OFFLOAD_RSS_HASH

#define RTE_ETH_MQ_TX_NONE ETH_MQ_TX_NONE

#define RTE_ETH_MQ_RX_NONE ETH_MQ_RX_NONE

#define RTE_ETH_RSS_IP ETH_RSS_IP
#define RTE_ETH_RSS_UDP ETH_RSS_UDP
#define RTE_ETH_RSS_TCP ETH_RSS_TCP
#define RTE_ETH_RSS_SCTP ETH_RSS_SCTP
#define RTE_ETH_RSS_TUNNEL ETH_RSS_TUNNEL

#define RTE_ETH_RSS_L3_SRC_ONLY ETH_RSS_L3_SRC_ONLY
#define RTE_ETH_RSS_L3_DST_ONLY ETH_RSS_L3_DST_ONLY
#define RTE_ETH_RSS_L4_SRC_ONLY ETH_RSS_L4_SRC_ONLY
#define RTE_ETH_RSS_L4_DST_ONLY ETH_RSS_L4_DST_ONLY

#define RTE_ETH_RSS_IPV4 ETH_RSS_IPV4
#define RTE_ETH_RSS_FRAG_IPV4 ETH_RSS_FRAG_IPV4
#define RTE_ETH_RSS_NONFRAG_IPV4_TCP ETH_RSS_NONFRAG_IPV4_TCP
#define RTE_ETH_RSS_NONFRAG_IPV4_UDP ETH_RSS_NONFRAG_IPV4_UDP
#define RTE_ETH_RSS_NONFRAG_IPV4_SCTP ETH_RSS_NONFRAG_IPV4_SCTP
#define RTE_ETH_RSS_NONFRAG_IPV4_OTHER ETH_RSS_NONFRAG_IPV4_OTHER
#define RTE_ETH_RSS_IPV6 ETH_RSS_IPV6
#define RTE_ETH_RSS_FRAG_IPV6 ETH_RSS_FRAG_IPV6
#define RTE_ETH_RSS_NONFRAG_IPV6_TCP ETH_RSS_NONFRAG_IPV6_TCP
#define RTE_ETH_RSS_NONFRAG_IPV6_UDP ETH_RSS_NONFRAG_IPV6_UDP
#define RTE_ETH_RSS_NONFRAG_IPV6_SCTP ETH_RSS_NONFRAG_IPV6_SCTP
#define RTE_ETH_RSS_NONFRAG_IPV6_OTHER ETH_RSS_NONFRAG_IPV6_OTHER
#define RTE_ETH_RSS_L2_PAYLOAD ETH_RSS_L2_PAYLOAD
#define RTE_ETH_RSS_IPV6_EX ETH_RSS_IPV6_EX
#define RTE_ETH_RSS_IPV6_TCP_EX ETH_RSS_IPV6_TCP_EX
#define RTE_ETH_RSS_IPV6_UDP_EX ETH_RSS_IPV6_UDP_EX
#define RTE_ETH_RSS_PORT ETH_RSS_PORT
#define RTE_ETH_RSS_VXLAN ETH_RSS_VXLAN
#define RTE_ETH_RSS_NVGRE ETH_RSS_NVGRE
#define RTE_ETH_RSS_GTPU ETH_RSS_GTPU

#define RTE_BIT64(nr) (UINT64_C(1) << (nr))

#endif
49 changes: 28 additions & 21 deletions input/dpdk/dpdkDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ rte_eth_conf DpdkDevice::createPortConfig()
#endif

if (m_supportedRSS) {
#if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
portConfig.rxmode.mq_mode = RTE_ETH_MQ_RX_RSS;
#else
portConfig.rxmode.mq_mode = ETH_MQ_RX_RSS;
#endif
} else {
portConfig.rxmode.mq_mode = RTE_ETH_MQ_RX_NONE;
}
Expand Down Expand Up @@ -219,25 +215,36 @@ void DpdkDevice::configureRSS()
return;
}

constexpr size_t RSS_KEY_LEN = 40;
// biflow hash key
static uint8_t rssKey[RSS_KEY_LEN]
= {0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A,
0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A, 0x6D, 0x5A};
rte_eth_dev_info rteDevInfo;
if (rte_eth_dev_info_get(m_portID, &rteDevInfo)) {
throw PluginError("DpdkDevice::configureRSS() has failed. Unable to get rte dev info");
}

struct rte_eth_rss_conf rssConfig
= {.rss_key = rssKey,
.rss_key_len = RSS_KEY_LEN,
#if RTE_VERSION >= RTE_VERSION_NUM(21, 11, 0, 0)
.rss_hf = RTE_ETH_RSS_IP,
#else
.rss_hf = ETH_RSS_IP,
#endif
};
const uint8_t rssHashKeySize = rteDevInfo.hash_key_size;

m_hashKey.resize(rssHashKeySize);
std::generate(
m_hashKey.begin(),
m_hashKey.end(),
[idx = static_cast<std::size_t>(0)]() mutable {
static const std::array<uint8_t, 2> hashKey = {0x6D, 0x5A};
return hashKey[idx++ % sizeof(hashKey)];
});

const uint64_t rssOffloads = rteDevInfo.flow_type_rss_offloads & RTE_ETH_RSS_IP;
if (rssOffloads != RTE_ETH_RSS_IP) {
std::cerr << "RTE_ETH_RSS_IP is not supported by the card. Used subset: " << rssOffloads << std::endl;
}

struct rte_eth_rss_conf rssConfig = {};
rssConfig.rss_key = m_hashKey.data();
rssConfig.rss_key_len = rssHashKeySize;
rssConfig.rss_hf = rssOffloads;

if (rte_eth_dev_rss_hash_update(m_portID, &rssConfig)) {
std::cerr << "Setting RSS hash for port " << m_portID << "." << std::endl;
int ret = rte_eth_dev_rss_hash_update(m_portID, &rssConfig);
if (ret < 0) {
std::cerr << "Setting RSS {" << rssOffloads << "} for port " << m_portID << " failed. Errno:" << ret << std::endl;
throw PluginError("DpdkDevice::configureRSS() has failed.");
}
}

Expand Down
4 changes: 3 additions & 1 deletion input/dpdk/dpdkDevice.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#pragma once

#include "dpdkMbuf.hpp"
#include "dpdkCompat.hpp"

#include <rte_ethdev.h>
#include <rte_mempool.h>
Expand Down Expand Up @@ -84,7 +85,8 @@ class DpdkDevice {
void registerRxTimestamp();

std::vector<rte_mempool*> m_memPools;
uint16_t m_portID;
std::vector<uint8_t> m_hashKey;
uint16_t m_portID;
uint16_t m_rxQueueCount;
uint16_t m_txQueueCount;
uint16_t m_mBufsCount;
Expand Down

0 comments on commit 82958b1

Please sign in to comment.