Skip to content

Commit

Permalink
net: introduce the interface to pass HW RSS key to the upper layers
Browse files Browse the repository at this point in the history
Signed-off-by: Vlad Zolotarov <[email protected]>
  • Loading branch information
Vlad Zolotarov committed Sep 1, 2015
1 parent 7ff1411 commit b61d647
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
3 changes: 2 additions & 1 deletion net/dpdk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,8 @@ int dpdk_device::init_port_start()
if (smp::count > 1) {
port_conf.rxmode.mq_mode = ETH_MQ_RX_RSS;
port_conf.rx_adv_conf.rss_conf.rss_hf = ETH_RSS_PROTO_MASK;
port_conf.rx_adv_conf.rss_conf.rss_key = const_cast<uint8_t*>(rsskey.data());
// FIXME:
port_conf.rx_adv_conf.rss_conf.rss_key = const_cast<uint8_t*>(default_rsskey.data());
} else {
port_conf.rxmode.mq_mode = ETH_MQ_RX_NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion net/ip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ ipv4::handle_received_packet(packet p, ethernet_address from) {
hash_data.push_back(hton(h.src_ip.ip));
hash_data.push_back(hton(h.dst_ip.ip));
l4->forward(hash_data, ip_data, l4_offset);
cpu_id = _netif->hash2cpu(toeplitz_hash(rsskey, hash_data));
cpu_id = _netif->hash2cpu(toeplitz_hash(_netif->rss_key(), hash_data));
}

// No need to forward if the dst cpu is the current cpu
Expand Down
4 changes: 2 additions & 2 deletions net/ip.hh
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ struct l4connid {
&& foreign_port == x.foreign_port;
}

uint32_t hash() {
uint32_t hash(const rss_key_type& rss_key) {
forward_hash hash_data;
hash_data.push_back(hton(foreign_ip.ip));
hash_data.push_back(hton(local_ip.ip));
hash_data.push_back(hton(foreign_port));
hash_data.push_back(hton(local_port));
return toeplitz_hash(rsskey, hash_data);
return toeplitz_hash(rss_key, hash_data);
}
};

Expand Down
8 changes: 6 additions & 2 deletions net/net.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ unsigned interface::hash2cpu(uint32_t hash) {
return _dev->hash2cpu(hash);
}

const rss_key_type& interface::rss_key() const {
return _dev->rss_key();
}

void interface::forward(unsigned cpuid, packet p) {
static __thread unsigned queue_depth;

Expand All @@ -331,14 +335,14 @@ future<> interface::dispatch_packet(packet p) {
auto i = _proto_map.find(ntoh(eh->eth_proto));
if (i != _proto_map.end()) {
l3_rx_stream& l3 = i->second;
auto fw = _dev->forward_dst(engine().cpu_id(), [&p, &l3] () {
auto fw = _dev->forward_dst(engine().cpu_id(), [&p, &l3, this] () {
auto hwrss = p.rss_hash();
if (hwrss) {
return hwrss.value();
} else {
forward_hash data;
if (l3.forward(data, p, sizeof(eth_hdr))) {
return toeplitz_hash(rsskey, data);
return toeplitz_hash(rss_key(), data);
}
return 0u;
}
Expand Down
3 changes: 3 additions & 0 deletions net/net.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "core/queue.hh"
#include "core/stream.hh"
#include "core/scollectd.hh"
#include "net/toeplitz.hh"
#include "ethernet.hh"
#include "packet.hh"
#include "const.hh"
Expand Down Expand Up @@ -130,6 +131,7 @@ public:
void register_packet_provider(l3_protocol::packet_provider_type func) {
_pkt_providers.push_back(std::move(func));
}
const rss_key_type& rss_key() const;
friend class l3_protocol;
};

Expand Down Expand Up @@ -265,6 +267,7 @@ public:
subscription<packet> receive(std::function<future<> (packet)> next_packet);
virtual ethernet_address hw_address() = 0;
virtual net::hw_features hw_features() = 0;
virtual const rss_key_type& rss_key() const { return default_rsskey; }
virtual uint16_t hw_queues_count() { return 1; }
virtual future<> link_ready() { return make_ready_future<>(); }
virtual std::unique_ptr<qp> init_local_queue(boost::program_options::variables_map opts, uint16_t qid) = 0;
Expand Down
2 changes: 1 addition & 1 deletion net/tcp.hh
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ future<typename tcp<InetTraits>::connection> tcp<InetTraits>::connect(socket_add
do {
src_port = _port_dist(_e);
id = connid{src_ip, dst_ip, src_port, dst_port};
} while (_inet._inet.netif()->hash2cpu(id.hash()) != engine().cpu_id()
} while (_inet._inet.netif()->hash2cpu(id.hash(_inet._inet.netif()->rss_key())) != engine().cpu_id()
|| _tcbs.find(id) != _tcbs.end());

auto tcbp = make_lw_shared<tcb>(*this, id);
Expand Down
9 changes: 4 additions & 5 deletions net/toeplitz.hh
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,18 @@
#ifndef TOEPLITZ_HH_
#define TOEPLITZ_HH_

#include <array>
#include <vector>

constexpr size_t rss_keysize = 40;
using rss_key_type = std::array<uint8_t, rss_keysize>;
using rss_key_type = std::vector<uint8_t>;

// Mellanox Linux's driver key in network byte order
static const rss_key_type rsskey = { {
static const rss_key_type default_rsskey = {
0xd1,0x81,0xc6,0x2c,0xf7,0xf4,0xdb,0x5b,
0x19,0x83,0xa2,0xfc,0x94,0x3e,0x1a,0xdb,
0xd9,0x38,0x9e,0x6b,0xd1,0x03,0x9c,0x2c,
0xa7,0x44,0x99,0xad,0x59,0x3d,0x56,0xd9,
0xf3,0x25,0x3c,0x06,0x2a,0xdc,0x1f,0xfc
} };
};

template<typename T>
static inline uint32_t
Expand Down

0 comments on commit b61d647

Please sign in to comment.