Skip to content

Commit

Permalink
DPDK: Few types fixes
Browse files Browse the repository at this point in the history
Also ensure more bounds (like burst size) when starting device
  • Loading branch information
Tom Barbette committed Aug 3, 2018
1 parent ed038e8 commit a5f50d4
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 35 deletions.
4 changes: 2 additions & 2 deletions elements/userlevel/fromdpdkdevice.hh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public:
const char *port_count() const { return PORTS_0_1; }
const char *processing() const { return PUSH; }
int configure_phase() const {
return CONFIGURE_PHASE_PRIVILEGED;
return CONFIGURE_PHASE_PRIVILEGED - 5;
}
bool can_live_reconfigure() const { return false; }

Expand Down Expand Up @@ -212,7 +212,7 @@ private:
};

DPDKDevice* _dev;
int _queue_id;
unsigned _queue_id;
bool _promisc;
unsigned int _burst_size;
unsigned long _count;
Expand Down
14 changes: 7 additions & 7 deletions elements/userlevel/todpdkdevice.hh
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,16 @@ public:
}
bool can_live_reconfigure() const { return false; }

int configure(Vector<String> &, ErrorHandler *) CLICK_COLD;
int initialize(ErrorHandler *) CLICK_COLD;
int configure(Vector<String> &, ErrorHandler *) override CLICK_COLD;
int initialize(ErrorHandler *) override CLICK_COLD;

void cleanup(CleanupStage stage) CLICK_COLD;
void cleanup(CleanupStage stage) override CLICK_COLD;

static String statistics_handler(Element *e, void * thunk) CLICK_COLD;
void add_handlers() CLICK_COLD;
void add_handlers() override CLICK_COLD;

void run_timer(Timer *);
void push(int port, Packet *p);
void run_timer(Timer *) override;
void push(int port, Packet *p) override;

private:

Expand Down Expand Up @@ -179,7 +179,7 @@ private:
Vector<InternalQueue> _iqueues;

DPDKDevice* _dev;
int _queue_id;
unsigned _queue_id;
bool _blocking;
Spinlock _lock;
unsigned int _iqueue_size;
Expand Down
19 changes: 11 additions & 8 deletions include/click/dpdkdevice.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ public:

DPDKDevice() CLICK_COLD;
DPDKDevice(portid_t port_id) CLICK_COLD;
int add_rx_queue(
unsigned &queue_id, bool promisc,
unsigned n_desc, ErrorHandler *errh
) CLICK_COLD;

int add_rx_queue(int &queue_id, bool promisc,
unsigned n_desc, ErrorHandler *errh) CLICK_COLD;

int add_tx_queue(int &queue_id, unsigned n_desc,
ErrorHandler *errh) CLICK_COLD;
int add_tx_queue(
unsigned &queue_id, unsigned n_desc,
ErrorHandler *errh
) CLICK_COLD;

EtherAddress get_mac();
void set_init_mac(EtherAddress mac);
Expand Down Expand Up @@ -125,20 +128,20 @@ private:
bool promisc;
unsigned n_rx_descs;
unsigned n_tx_descs;
uint16_t init_mtu;
EtherAddress init_mac;
uint16_t init_mtu;
};

DevInfo info;

static bool _is_initialized;
static HashTable<portid_t, DPDKDevice> _devs;
static struct rte_mempool** _pktmbuf_pools;
static int _nr_pktmbuf_pools;
static unsigned _nr_pktmbuf_pools;
static bool no_more_buffer_msg_printed;

int initialize_device(ErrorHandler *errh) CLICK_COLD;
int add_queue(Dir dir, int &queue_id, bool promisc,
int add_queue(Dir dir, unsigned &queue_id, bool promisc,
unsigned n_desc, ErrorHandler *errh) CLICK_COLD;

static bool alloc_pktmbufs() CLICK_COLD;
Expand Down
75 changes: 57 additions & 18 deletions lib/dpdkdevice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <click/config.h>
#include <click/dpdkdevice.hh>
#include <rte_errno.h>

CLICK_DECLS

Expand Down Expand Up @@ -119,20 +120,58 @@ int DPDKDevice::initialize_device(ErrorHandler *errh)
//We must open at least one queue per direction
if (info.rx_queues.size() == 0) {
info.rx_queues.resize(1);
info.n_rx_descs = 64;
info.n_rx_descs = DEF_DEV_RXDESC;
}
if (info.tx_queues.size() == 0) {
info.tx_queues.resize(1);
info.n_tx_descs = 64;
info.n_tx_descs = DEF_DEV_TXDESC;
}

if (rte_eth_dev_configure(port_id, info.rx_queues.size(), info.tx_queues.size(),
&dev_conf) < 0)
if (info.rx_queues.size() > dev_info.max_rx_queues) {
return errh->error("Port %d can only use %d RX queues (asked for %d), use MAXQUEUES to set the maximum "
"number of queues or N_QUEUES to strictly define it.", port_id, dev_info.max_rx_queues, info.rx_queues.size());
}
if (info.tx_queues.size() > dev_info.max_tx_queues) {
return errh->error("Port %d can only use %d TX queues (FastClick asked for %d, probably to serve that same amount of threads).\n"
"Add the argument \"MAXQUEUES %d\" to the corresponding ToDPDKDevice to set the maximum "
"number of queues to %d or \"N_QUEUES %d\" to strictly define it. "
"If the TX device has more threads than queues due to this parameter change, it will automatically rely on locking to share the queues as evenly as possible between the threads.", port_id, dev_info.max_tx_queues, info.tx_queues.size(), dev_info.max_tx_queues, dev_info.max_tx_queues, dev_info.max_tx_queues);
}

if (info.n_rx_descs < dev_info.rx_desc_lim.nb_min || info.n_rx_descs > dev_info.rx_desc_lim.nb_max) {
return errh->error("The number of receive descriptors is %d but needs to be between %d and %d",info.n_rx_descs, dev_info.rx_desc_lim.nb_min, dev_info.rx_desc_lim.nb_max);
}

if (info.n_tx_descs < dev_info.tx_desc_lim.nb_min || info.n_tx_descs > dev_info.tx_desc_lim.nb_max) {
return errh->error("The number of transmit descriptors is %d but needs to be between %d and %d",info.n_tx_descs, dev_info.tx_desc_lim.nb_min, dev_info.tx_desc_lim.nb_max);
}

int ret;
if ((ret = rte_eth_dev_configure(
port_id, info.rx_queues.size(),
info.tx_queues.size(), &dev_conf)) < 0)
return errh->error(
"Cannot initialize DPDK port %u with %u RX and %u TX queues",
port_id, info.rx_queues.size(), info.tx_queues.size());
"Cannot initialize DPDK port %u with %u RX and %u TX queues\nError %d : %s",
port_id, info.rx_queues.size(), info.tx_queues.size(),
ret, strerror(ret));

rte_eth_dev_info_get(port_id, &dev_info);

#if RTE_VERSION >= RTE_VERSION_NUM(16,07,0,0)
if (dev_info.nb_rx_queues != info.rx_queues.size()) {
return errh->error("Device only initialized %d RX queues instead of %d. "
"Please check configuration.", dev_info.nb_rx_queues,
info.rx_queues.size());
}
if (dev_info.nb_tx_queues != info.tx_queues.size()) {
return errh->error("Device only initialized %d TX queues instead of %d. "
"Please check configuration.", dev_info.nb_tx_queues,
info.tx_queues.size());
}
#endif

struct rte_eth_rxconf rx_conf;
#if RTE_VERSION >= (RTE_VERSION_NUM(2,0,0,0))
#if RTE_VERSION >= RTE_VERSION_NUM(2,0,0,0)
memcpy(&rx_conf, &dev_info.default_rxconf, sizeof rx_conf);
#else
bzero(&rx_conf,sizeof rx_conf);
Expand All @@ -153,16 +192,16 @@ int DPDKDevice::initialize_device(ErrorHandler *errh)
tx_conf.txq_flags |= ETH_TXQ_FLAGS_NOMULTSEGS | ETH_TXQ_FLAGS_NOOFFLOADS;

int numa_node = DPDKDevice::get_port_numa_node(port_id);
for (int i = 0; i < info.rx_queues.size(); ++i) {
for (unsigned i = 0; i < info.rx_queues.size(); ++i) {
if (rte_eth_rx_queue_setup(
port_id, i, info.n_rx_descs, numa_node, &rx_conf,
_pktmbuf_pools[numa_node]) != 0)
return errh->error(
"Cannot initialize RX queue %u of port %u on node %u",
i, port_id, numa_node);
"Cannot initialize RX queue %u of port %u on node %u : %s",
i, port_id, numa_node, rte_strerror(rte_errno));
}

for (int i = 0; i < info.tx_queues.size(); ++i)
for (unsigned i = 0; i < info.tx_queues.size(); ++i)
if (rte_eth_tx_queue_setup(port_id, i, info.n_tx_descs, numa_node,
&tx_conf) != 0)
return errh->error(
Expand Down Expand Up @@ -217,7 +256,7 @@ EtherAddress DPDKDevice::get_mac() {
* If v[id] is already true, this function return false. True if it is a
* new slot or if the existing slot was false.
*/
bool set_slot(Vector<bool> &v, int &id) {
bool set_slot(Vector<bool> &v, unsigned &id) {
if (id <= 0) {
int i;
for (i = 0; i < v.size(); i ++) {
Expand All @@ -237,7 +276,7 @@ bool set_slot(Vector<bool> &v, int &id) {
}

int DPDKDevice::add_queue(DPDKDevice::Dir dir,
int &queue_id, bool promisc, unsigned n_desc,
unsigned &queue_id, bool promisc, unsigned n_desc,
ErrorHandler *errh)
{
if (_is_initialized) {
Expand All @@ -258,7 +297,7 @@ int DPDKDevice::add_queue(DPDKDevice::Dir dir,
"for device %u", port_id);
info.n_rx_descs = n_desc;
}
if (!set_slot(info.rx_queues,queue_id))
if (!set_slot(info.rx_queues, queue_id))
return errh->error(
"Some elements are assigned to the same RX queue "
"for device %u", port_id);
Expand All @@ -279,13 +318,13 @@ int DPDKDevice::add_queue(DPDKDevice::Dir dir,
return 0;
}

int DPDKDevice::add_rx_queue(int &queue_id, bool promisc,
int DPDKDevice::add_rx_queue(unsigned &queue_id, bool promisc,
unsigned n_desc, ErrorHandler *errh)
{
return add_queue(DPDKDevice::RX, queue_id, promisc, n_desc, errh);
}

int DPDKDevice::add_tx_queue(int &queue_id, unsigned n_desc,
int DPDKDevice::add_tx_queue(unsigned &queue_id, unsigned n_desc,
ErrorHandler *errh)
{
return add_queue(DPDKDevice::TX, queue_id, false, n_desc, errh);
Expand All @@ -300,7 +339,7 @@ int DPDKDevice::initialize(ErrorHandler *errh)
return errh->error( "Supply the --dpdk argument to use DPDK.");

click_chatter("Initializing DPDK");
#if RTE_VERSION < (RTE_VERSION_NUM(2,1,0,0))
#if RTE_VERSION < RTE_VERSION_NUM(2,0,0,0)
if (rte_eal_pci_probe())
return errh->error("Cannot probe the PCI bus");
#endif
Expand Down Expand Up @@ -427,7 +466,7 @@ unsigned DPDKDevice::DEF_BURST_SIZE = 32;
bool DPDKDevice::_is_initialized = false;
HashTable<portid_t, DPDKDevice> DPDKDevice::_devs;
struct rte_mempool** DPDKDevice::_pktmbuf_pools;
int DPDKDevice::_nr_pktmbuf_pools;
unsigned DPDKDevice::_nr_pktmbuf_pools;
bool DPDKDevice::no_more_buffer_msg_printed = false;

CLICK_ENDDECLS

0 comments on commit a5f50d4

Please sign in to comment.