/*
- * Copyright (c) 2014, 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2014, 2015, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <config.h>
+#include "netdev-dpdk.h"
#include <string.h>
#include <signal.h>
#include <stdlib.h>
-#include <pthread.h>
-#include <config.h>
#include <errno.h>
-#include <sched.h>
-#include <stdlib.h>
#include <unistd.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <getopt.h>
+#include <linux/virtio_net.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+
+#include <rte_bus_pci.h>
+#include <rte_config.h>
+#include <rte_cycles.h>
+#include <rte_errno.h>
+#include <rte_eth_ring.h>
+#include <rte_ethdev.h>
+#include <rte_malloc.h>
+#include <rte_mbuf.h>
+#include <rte_meter.h>
+#include <rte_pci.h>
+#include <rte_vhost.h>
+#include <rte_version.h>
#include "dirs.h"
#include "dp-packet.h"
+#include "dpdk.h"
#include "dpif-netdev.h"
#include "fatal-signal.h"
-#include "netdev-dpdk.h"
#include "netdev-provider.h"
#include "netdev-vport.h"
#include "odp-util.h"
#include "timeval.h"
#include "unixctl.h"
-#include "rte_config.h"
-#include "rte_mbuf.h"
-#include "rte_meter.h"
-#ifdef DPDK_PDUMP
-#include "rte_pdump.h"
-#endif
-#include "rte_virtio_net.h"
+enum {VIRTIO_RXQ, VIRTIO_TXQ, VIRTIO_QNUM};
-VLOG_DEFINE_THIS_MODULE(dpdk);
+VLOG_DEFINE_THIS_MODULE(netdev_dpdk);
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(5, 20);
#define DPDK_PORT_WATCHDOG_INTERVAL 5
* The minimum mbuf size is limited to avoid scatter behaviour and drop in
* performance for standard Ethernet MTU.
*/
-#define ETHER_HDR_MAX_LEN (ETHER_HDR_LEN + ETHER_CRC_LEN + (2 * VLAN_HEADER_LEN))
+#define ETHER_HDR_MAX_LEN (ETHER_HDR_LEN + ETHER_CRC_LEN \
+ + (2 * VLAN_HEADER_LEN))
#define MTU_TO_FRAME_LEN(mtu) ((mtu) + ETHER_HDR_LEN + ETHER_CRC_LEN)
#define MTU_TO_MAX_FRAME_LEN(mtu) ((mtu) + ETHER_HDR_MAX_LEN)
-#define FRAME_LEN_TO_MTU(frame_len) ((frame_len)- ETHER_HDR_LEN - ETHER_CRC_LEN)
-#define MBUF_SIZE(mtu) ( MTU_TO_MAX_FRAME_LEN(mtu) \
- + sizeof(struct dp_packet) \
- + RTE_PKTMBUF_HEADROOM)
+#define FRAME_LEN_TO_MTU(frame_len) ((frame_len) \
+ - ETHER_HDR_LEN - ETHER_CRC_LEN)
+#define MBUF_SIZE(mtu) ROUND_UP((MTU_TO_MAX_FRAME_LEN(mtu) \
+ + sizeof(struct dp_packet) \
+ + RTE_PKTMBUF_HEADROOM), \
+ RTE_CACHE_LINE_SIZE)
#define NETDEV_DPDK_MBUF_ALIGN 1024
#define NETDEV_DPDK_MAX_PKT_LEN 9728
-/* Max and min number of packets in the mempool. OVS tries to allocate a
- * mempool with MAX_NB_MBUF: if this fails (because the system doesn't have
- * enough hugepages) we keep halving the number until the allocation succeeds
- * or we reach MIN_NB_MBUF */
-
-#define MAX_NB_MBUF (4096 * 64)
+/* Min number of packets in the mempool. OVS tries to allocate a mempool with
+ * roughly estimated number of mbufs: if this fails (because the system doesn't
+ * have enough hugepages) we keep halving the number until the allocation
+ * succeeds or we reach MIN_NB_MBUF */
#define MIN_NB_MBUF (4096 * 4)
#define MP_CACHE_SZ RTE_MEMPOOL_CACHE_MAX_SIZE
-/* MAX_NB_MBUF can be divided by 2 many times, until MIN_NB_MBUF */
-BUILD_ASSERT_DECL(MAX_NB_MBUF % ROUND_DOWN_POW2(MAX_NB_MBUF/MIN_NB_MBUF) == 0);
-
-/* The smallest possible NB_MBUF that we're going to try should be a multiple
- * of MP_CACHE_SZ. This is advised by DPDK documentation. */
-BUILD_ASSERT_DECL((MAX_NB_MBUF / ROUND_DOWN_POW2(MAX_NB_MBUF/MIN_NB_MBUF))
- % MP_CACHE_SZ == 0);
-
/*
* DPDK XSTATS Counter names definition
*/
#define XSTAT_TX_1024_TO_1522_PACKETS "tx_size_1024_to_1522_packets"
#define XSTAT_TX_1523_TO_MAX_PACKETS "tx_size_1523_to_max_packets"
+#define XSTAT_RX_MULTICAST_PACKETS "rx_multicast_packets"
#define XSTAT_TX_MULTICAST_PACKETS "tx_multicast_packets"
#define XSTAT_RX_BROADCAST_PACKETS "rx_broadcast_packets"
#define XSTAT_TX_BROADCAST_PACKETS "tx_broadcast_packets"
#define SOCKET0 0
-#define NIC_PORT_RX_Q_SIZE 2048 /* Size of Physical NIC RX Queue, Max (n+32<=4096)*/
-#define NIC_PORT_TX_Q_SIZE 2048 /* Size of Physical NIC TX Queue, Max (n+32<=4096)*/
+/* Default size of Physical NIC RXQ */
+#define NIC_PORT_DEFAULT_RXQ_SIZE 2048
+/* Default size of Physical NIC TXQ */
+#define NIC_PORT_DEFAULT_TXQ_SIZE 2048
+/* Maximum size of Physical NIC Queues */
+#define NIC_PORT_MAX_Q_SIZE 4096
#define OVS_VHOST_MAX_QUEUE_NUM 1024 /* Maximum number of vHost TX queues. */
#define OVS_VHOST_QUEUE_MAP_UNKNOWN (-1) /* Mapping not initialized. */
#define OVS_VHOST_QUEUE_DISABLED (-2) /* Queue was disabled by guest and not
* yet mapped to another queue. */
-static char *vhost_sock_dir = NULL; /* Location of vhost-user sockets */
+#define DPDK_ETH_PORT_ID_INVALID RTE_MAX_ETHPORTS
+
+/* DPDK library uses uint16_t for port_id. */
+typedef uint16_t dpdk_port_t;
#define VHOST_ENQ_RETRY_NUM 8
#define IF_NAME_SZ (PATH_MAX > IFNAMSIZ ? PATH_MAX : IFNAMSIZ)
},
};
+/*
+ * These callbacks allow virtio-net devices to be added to vhost ports when
+ * configuration has been fully completed.
+ */
+static int new_device(int vid);
+static void destroy_device(int vid);
+static int vring_state_changed(int vid, uint16_t queue_id, int enable);
+static const struct vhost_device_ops virtio_net_device_ops =
+{
+ .new_device = new_device,
+ .destroy_device = destroy_device,
+ .vring_state_changed = vring_state_changed,
+ .features_changed = NULL
+};
+
enum { DPDK_RING_SIZE = 256 };
BUILD_ASSERT_DECL(IS_POW2(DPDK_RING_SIZE));
enum { DRAIN_TSC = 200000ULL };
DPDK_DEV_VHOST = 1,
};
-static int rte_eal_init_ret = ENODEV;
-
-static struct ovs_mutex dpdk_mutex = OVS_MUTEX_INITIALIZER;
-
/* Quality of Service */
/* An instance of a QoS configuration. Always associated with a particular
*/
struct qos_conf {
const struct dpdk_qos_ops *ops;
+ rte_spinlock_t lock;
};
/* A particular implementation of dpdk QoS operations.
/* Name of the QoS type */
const char *qos_name;
- /* Called to construct the QoS implementation on 'netdev'. The
- * implementation should make the appropriate calls to configure QoS
- * according to 'details'. The implementation may assume that any current
- * QoS configuration already installed should be destroyed before
- * constructing the new configuration.
+ /* Called to construct a qos_conf object. The implementation should make
+ * the appropriate calls to configure QoS according to 'details'.
*
* The contents of 'details' should be documented as valid for 'ovs_name'
* in the "other_config" column in the "QoS" table in vswitchd/vswitch.xml
* (which is built as ovs-vswitchd.conf.db(8)).
*
- * This function must return 0 if and only if it sets 'netdev->qos_conf'
- * to an initialized 'struct qos_conf'.
+ * This function must return 0 if and only if it sets '*conf' to an
+ * initialized 'struct qos_conf'.
*
* For all QoS implementations it should always be non-null.
*/
- int (*qos_construct)(struct netdev *netdev, const struct smap *details);
+ int (*qos_construct)(const struct smap *details, struct qos_conf **conf);
/* Destroys the data structures allocated by the implementation as part of
- * 'qos_conf.
+ * 'qos_conf'.
*
* For all QoS implementations it should always be non-null.
*/
- void (*qos_destruct)(struct netdev *netdev, struct qos_conf *conf);
+ void (*qos_destruct)(struct qos_conf *conf);
- /* Retrieves details of 'netdev->qos_conf' configuration into 'details'.
+ /* Retrieves details of 'conf' configuration into 'details'.
*
* The contents of 'details' should be documented as valid for 'ovs_name'
* in the "other_config" column in the "QoS" table in vswitchd/vswitch.xml
* (which is built as ovs-vswitchd.conf.db(8)).
*/
- int (*qos_get)(const struct netdev *netdev, struct smap *details);
+ int (*qos_get)(const struct qos_conf *conf, struct smap *details);
- /* Reconfigures 'netdev->qos_conf' according to 'details', performing any
- * required calls to complete the reconfiguration.
+ /* Returns true if 'conf' is already configured according to 'details'.
*
* The contents of 'details' should be documented as valid for 'ovs_name'
* in the "other_config" column in the "QoS" table in vswitchd/vswitch.xml
* (which is built as ovs-vswitchd.conf.db(8)).
*
- * This function may be null if 'qos_conf' is not configurable.
+ * For all QoS implementations it should always be non-null.
*/
- int (*qos_set)(struct netdev *netdev, const struct smap *details);
+ bool (*qos_is_equal)(const struct qos_conf *conf,
+ const struct smap *details);
/* Modify an array of rte_mbufs. The modification is specific to
* each qos implementation.
*
* For all QoS implementations it should always be non-null.
*/
- int (*qos_run)(struct netdev *netdev, struct rte_mbuf **pkts,
- int pkt_cnt);
+ int (*qos_run)(struct qos_conf *qos_conf, struct rte_mbuf **pkts,
+ int pkt_cnt, bool may_steal);
};
/* dpdk_qos_ops for each type of user space QoS implementation */
NULL
};
+static struct ovs_mutex dpdk_mutex = OVS_MUTEX_INITIALIZER;
+
/* Contains all 'struct dpdk_dev's. */
static struct ovs_list dpdk_list OVS_GUARDED_BY(dpdk_mutex)
= OVS_LIST_INITIALIZER(&dpdk_list);
-static struct ovs_list dpdk_mp_list OVS_GUARDED_BY(dpdk_mutex)
- = OVS_LIST_INITIALIZER(&dpdk_mp_list);
-
-/* This mutex must be used by non pmd threads when allocating or freeing
- * mbufs through mempools. */
-static struct ovs_mutex nonpmd_mempool_mutex = OVS_MUTEX_INITIALIZER;
-
-struct dpdk_mp {
- struct rte_mempool *mp;
- int mtu;
- int socket_id;
- int refcount;
- struct ovs_list list_node OVS_GUARDED_BY(dpdk_mutex);
-};
+static struct ovs_mutex dpdk_mp_mutex OVS_ACQ_AFTER(dpdk_mutex)
+ = OVS_MUTEX_INITIALIZER;
/* There should be one 'struct dpdk_tx_queue' created for
* each cpu core. */
struct rte_ring *cring_tx;
struct rte_ring *cring_rx;
unsigned int user_port_id; /* User given port no, parsed from port name */
- int eth_port_id; /* ethernet device port id */
+ dpdk_port_t eth_port_id; /* ethernet device port id */
struct ovs_list list_node OVS_GUARDED_BY(dpdk_mutex);
};
rte_spinlock_t policer_lock;
};
-struct netdev_dpdk {
- struct netdev up;
- int port_id;
- int max_packet_len;
- enum dpdk_dev_type type;
-
- struct dpdk_tx_queue *tx_q;
-
- struct ovs_mutex mutex OVS_ACQ_AFTER(dpdk_mutex);
-
- struct dpdk_mp *dpdk_mp;
- int mtu;
- int socket_id;
- int buf_size;
- struct netdev_stats stats;
- /* Protects stats */
- rte_spinlock_t stats_lock;
-
- struct eth_addr hwaddr;
- enum netdev_flags flags;
-
- struct rte_eth_link link;
- int link_reset_cnt;
-
- /* virtio identifier for vhost devices */
- ovsrcu_index vid;
-
- /* True if vHost device is 'up' and has been reconfigured at least once */
- bool vhost_reconfigured;
-
- /* Identifier used to distinguish vhost devices from each other. */
- char vhost_id[PATH_MAX];
-
- /* In dpdk_list. */
- struct ovs_list list_node OVS_GUARDED_BY(dpdk_mutex);
-
- /* QoS configuration and lock for the device */
- struct qos_conf *qos_conf;
- rte_spinlock_t qos_lock;
-
- /* The following properties cannot be changed when a device is running,
- * so we remember the request and update them next time
- * netdev_dpdk*_reconfigure() is called */
- int requested_mtu;
- int requested_n_txq;
- int requested_n_rxq;
-
- /* Socket ID detected when vHost device is brought up */
- int requested_socket_id;
-
- /* Denotes whether vHost port is client/server mode */
- uint64_t vhost_driver_flags;
+enum dpdk_hw_ol_features {
+ NETDEV_RX_CHECKSUM_OFFLOAD = 1 << 0,
+};
- /* Ingress Policer */
- OVSRCU_TYPE(struct ingress_policer *) ingress_policer;
- uint32_t policer_rate;
- uint32_t policer_burst;
+/*
+ * In order to avoid confusion in variables names, following naming convention
+ * should be used, if possible:
+ *
+ * 'struct netdev' : 'netdev'
+ * 'struct netdev_dpdk' : 'dev'
+ * 'struct netdev_rxq' : 'rxq'
+ * 'struct netdev_rxq_dpdk' : 'rx'
+ *
+ * Example:
+ * struct netdev *netdev = netdev_from_name(name);
+ * struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ *
+ * Also, 'netdev' should be used instead of 'dev->up', where 'netdev' was
+ * already defined.
+ */
- /* DPDK-ETH Flow control */
- struct rte_eth_fc_conf fc_conf;
+struct netdev_dpdk {
+ PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline0,
+ dpdk_port_t port_id;
+
+ /* If true, device was attached by rte_eth_dev_attach(). */
+ bool attached;
+ struct eth_addr hwaddr;
+ int mtu;
+ int socket_id;
+ int buf_size;
+ int max_packet_len;
+ enum dpdk_dev_type type;
+ enum netdev_flags flags;
+ char *devargs; /* Device arguments for dpdk ports */
+ struct dpdk_tx_queue *tx_q;
+ struct rte_eth_link link;
+ int link_reset_cnt;
+ /* 4 pad bytes here. */
+ );
+
+ PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline1,
+ struct ovs_mutex mutex OVS_ACQ_AFTER(dpdk_mutex);
+ struct rte_mempool *mp;
+
+ /* virtio identifier for vhost devices */
+ ovsrcu_index vid;
+
+ /* True if vHost device is 'up' and has been reconfigured at least once */
+ bool vhost_reconfigured;
+ /* 3 pad bytes here. */
+ );
+
+ PADDED_MEMBERS(CACHE_LINE_SIZE,
+ /* Identifier used to distinguish vhost devices from each other. */
+ char vhost_id[PATH_MAX];
+ );
+
+ PADDED_MEMBERS(CACHE_LINE_SIZE,
+ struct netdev up;
+ /* In dpdk_list. */
+ struct ovs_list list_node OVS_GUARDED_BY(dpdk_mutex);
+
+ /* QoS configuration and lock for the device */
+ OVSRCU_TYPE(struct qos_conf *) qos_conf;
+
+ /* Ingress Policer */
+ OVSRCU_TYPE(struct ingress_policer *) ingress_policer;
+ uint32_t policer_rate;
+ uint32_t policer_burst;
+ );
+
+ PADDED_MEMBERS(CACHE_LINE_SIZE,
+ struct netdev_stats stats;
+ /* Protects stats */
+ rte_spinlock_t stats_lock;
+ /* 44 pad bytes here. */
+ );
+
+ PADDED_MEMBERS(CACHE_LINE_SIZE,
+ /* The following properties cannot be changed when a device is running,
+ * so we remember the request and update them next time
+ * netdev_dpdk*_reconfigure() is called */
+ int requested_mtu;
+ int requested_n_txq;
+ int requested_n_rxq;
+ int requested_rxq_size;
+ int requested_txq_size;
+
+ /* Number of rx/tx descriptors for physical devices */
+ int rxq_size;
+ int txq_size;
+
+ /* Socket ID detected when vHost device is brought up */
+ int requested_socket_id;
+
+ /* Denotes whether vHost port is client/server mode */
+ uint64_t vhost_driver_flags;
+
+ /* DPDK-ETH Flow control */
+ struct rte_eth_fc_conf fc_conf;
+
+ /* DPDK-ETH hardware offload features,
+ * from the enum set 'dpdk_hw_ol_features' */
+ uint32_t hw_ol_features;
+ );
};
struct netdev_rxq_dpdk {
struct netdev_rxq up;
- int port_id;
+ dpdk_port_t port_id;
};
-static bool dpdk_thread_is_pmd(void);
-
-static int netdev_dpdk_construct(struct netdev *);
+static void netdev_dpdk_destruct(struct netdev *netdev);
+static void netdev_dpdk_vhost_destruct(struct netdev *netdev);
int netdev_dpdk_get_vid(const struct netdev_dpdk *dev);
static bool
is_dpdk_class(const struct netdev_class *class)
{
- return class->construct == netdev_dpdk_construct;
+ return class->destruct == netdev_dpdk_destruct
+ || class->destruct == netdev_dpdk_vhost_destruct;
}
/* DPDK NIC drivers allocate RX buffers at a particular granularity, typically
* entirety. Furthermore, certain drivers need to ensure that there is also
* sufficient space in the Rx buffer to accommodate two VLAN tags (for QinQ
* frames). If the RX buffer is too small, then the driver enables scatter RX
- * behaviour, which reduces performance. To prevent this, use a buffer size that
- * is closest to 'mtu', but which satisfies the aforementioned criteria.
+ * behaviour, which reduces performance. To prevent this, use a buffer size
+ * that is closest to 'mtu', but which satisfies the aforementioned criteria.
*/
static uint32_t
dpdk_buf_size(int mtu)
NETDEV_DPDK_MBUF_ALIGN);
}
-/* XXX: use dpdk malloc for entire OVS. in fact huge page should be used
- * for all other segments data, bss and text. */
-
+/* Allocates an area of 'sz' bytes from DPDK. The memory is zero'ed.
+ *
+ * Unlike xmalloc(), this function can return NULL on failure. */
static void *
dpdk_rte_mzalloc(size_t sz)
{
- void *ptr;
-
- ptr = rte_zmalloc(OVS_VPORT_DPDK, sz, OVS_CACHE_LINE_SIZE);
- if (ptr == NULL) {
- out_of_memory();
- }
- return ptr;
+ return rte_zmalloc(OVS_VPORT_DPDK, sz, OVS_CACHE_LINE_SIZE);
}
-/* XXX this function should be called only by pmd threads (or by non pmd
- * threads holding the nonpmd_mempool_mutex) */
void
free_dpdk_buf(struct dp_packet *p)
{
}
static void
-ovs_rte_pktmbuf_init(struct rte_mempool *mp,
+ovs_rte_pktmbuf_init(struct rte_mempool *mp OVS_UNUSED,
void *opaque_arg OVS_UNUSED,
- void *_m,
+ void *_p,
unsigned i OVS_UNUSED)
{
- struct rte_mbuf *m = _m;
-
- rte_pktmbuf_init(mp, opaque_arg, _m, i);
+ struct rte_mbuf *pkt = _p;
- dp_packet_init_dpdk((struct dp_packet *) m, m->buf_len);
+ dp_packet_init_dpdk((struct dp_packet *) pkt, pkt->buf_len);
}
-static struct dpdk_mp *
-dpdk_mp_get(int socket_id, int mtu) OVS_REQUIRES(dpdk_mutex)
+/* Returns a valid pointer when either of the following is true:
+ * - a new mempool was just created;
+ * - a matching mempool already exists. */
+static struct rte_mempool *
+dpdk_mp_create(struct netdev_dpdk *dev, int mtu)
{
- struct dpdk_mp *dmp = NULL;
char mp_name[RTE_MEMPOOL_NAMESIZE];
- unsigned mp_size;
- struct rte_pktmbuf_pool_private mbp_priv;
-
- LIST_FOR_EACH (dmp, list_node, &dpdk_mp_list) {
- if (dmp->socket_id == socket_id && dmp->mtu == mtu) {
- dmp->refcount++;
- return dmp;
- }
- }
-
- dmp = dpdk_rte_mzalloc(sizeof *dmp);
- dmp->socket_id = socket_id;
- dmp->mtu = mtu;
- dmp->refcount = 1;
- mbp_priv.mbuf_data_room_size = MBUF_SIZE(mtu) - sizeof(struct dp_packet);
- mbp_priv.mbuf_priv_size = sizeof (struct dp_packet)
- - sizeof (struct rte_mbuf);
- /* XXX: this is a really rough method of provisioning memory.
- * It's impossible to determine what the exact memory requirements are when
- * the number of ports and rxqs that utilize a particular mempool can change
- * dynamically at runtime. For the moment, use this rough heurisitic.
+ const char *netdev_name = netdev_get_name(&dev->up);
+ int socket_id = dev->requested_socket_id;
+ uint32_t n_mbufs;
+ uint32_t hash = hash_string(netdev_name, 0);
+ struct rte_mempool *mp = NULL;
+
+ /*
+ * XXX: rough estimation of number of mbufs required for this port:
+ * <packets required to fill the device rxqs>
+ * + <packets that could be stuck on other ports txqs>
+ * + <packets in the pmd threads>
+ * + <additional memory for corner cases>
*/
- if (mtu >= ETHER_MTU) {
- mp_size = MAX_NB_MBUF;
- } else {
- mp_size = MIN_NB_MBUF;
- }
+ n_mbufs = dev->requested_n_rxq * dev->requested_rxq_size
+ + dev->requested_n_txq * dev->requested_txq_size
+ + MIN(RTE_MAX_LCORE, dev->requested_n_rxq) * NETDEV_MAX_BURST
+ + MIN_NB_MBUF;
+ ovs_mutex_lock(&dpdk_mp_mutex);
do {
- if (snprintf(mp_name, RTE_MEMPOOL_NAMESIZE, "ovs_mp_%d_%d_%u",
- dmp->mtu, dmp->socket_id, mp_size) < 0) {
- goto fail;
+ /* Full DPDK memory pool name must be unique and cannot be
+ * longer than RTE_MEMPOOL_NAMESIZE. */
+ int ret = snprintf(mp_name, RTE_MEMPOOL_NAMESIZE,
+ "ovs%08x%02d%05d%07u",
+ hash, socket_id, mtu, n_mbufs);
+ if (ret < 0 || ret >= RTE_MEMPOOL_NAMESIZE) {
+ VLOG_DBG("snprintf returned %d. "
+ "Failed to generate a mempool name for \"%s\". "
+ "Hash:0x%x, socket_id: %d, mtu:%d, mbufs:%u.",
+ ret, netdev_name, hash, socket_id, mtu, n_mbufs);
+ break;
}
- dmp->mp = rte_mempool_create(mp_name, mp_size, MBUF_SIZE(mtu),
- MP_CACHE_SZ,
- sizeof(struct rte_pktmbuf_pool_private),
- rte_pktmbuf_pool_init, &mbp_priv,
- ovs_rte_pktmbuf_init, NULL,
- socket_id, 0);
- } while (!dmp->mp && rte_errno == ENOMEM && (mp_size /= 2) >= MIN_NB_MBUF);
-
- if (dmp->mp == NULL) {
- goto fail;
- } else {
- VLOG_DBG("Allocated \"%s\" mempool with %u mbufs", mp_name, mp_size );
- }
-
- ovs_list_push_back(&dpdk_mp_list, &dmp->list_node);
- return dmp;
+ VLOG_DBG("Port %s: Requesting a mempool of %u mbufs "
+ "on socket %d for %d Rx and %d Tx queues.",
+ netdev_name, n_mbufs, socket_id,
+ dev->requested_n_rxq, dev->requested_n_txq);
+
+ mp = rte_pktmbuf_pool_create(mp_name, n_mbufs, MP_CACHE_SZ,
+ sizeof (struct dp_packet) - sizeof (struct rte_mbuf),
+ MBUF_SIZE(mtu) - sizeof(struct dp_packet), socket_id);
+
+ if (mp) {
+ VLOG_DBG("Allocated \"%s\" mempool with %u mbufs",
+ mp_name, n_mbufs);
+ /* rte_pktmbuf_pool_create has done some initialization of the
+ * rte_mbuf part of each dp_packet. Some OvS specific fields
+ * of the packet still need to be initialized by
+ * ovs_rte_pktmbuf_init. */
+ rte_mempool_obj_iter(mp, ovs_rte_pktmbuf_init, NULL);
+ } else if (rte_errno == EEXIST) {
+ /* A mempool with the same name already exists. We just
+ * retrieve its pointer to be returned to the caller. */
+ mp = rte_mempool_lookup(mp_name);
+ /* As the mempool create returned EEXIST we can expect the
+ * lookup has returned a valid pointer. If for some reason
+ * that's not the case we keep track of it. */
+ VLOG_DBG("A mempool with name \"%s\" already exists at %p.",
+ mp_name, mp);
+ } else {
+ VLOG_ERR("Failed mempool \"%s\" create request of %u mbufs",
+ mp_name, n_mbufs);
+ }
+ } while (!mp && rte_errno == ENOMEM && (n_mbufs /= 2) >= MIN_NB_MBUF);
-fail:
- rte_free(dmp);
- return NULL;
+ ovs_mutex_unlock(&dpdk_mp_mutex);
+ return mp;
}
+/* Release an existing mempool. */
static void
-dpdk_mp_put(struct dpdk_mp *dmp) OVS_REQUIRES(dpdk_mutex)
+dpdk_mp_free(struct rte_mempool *mp)
{
- if (!dmp) {
+ if (!mp) {
return;
}
- ovs_assert(dmp->refcount);
-
- if (!--dmp->refcount) {
- ovs_list_remove(&dmp->list_node);
- rte_mempool_free(dmp->mp);
- rte_free(dmp);
- }
+ ovs_mutex_lock(&dpdk_mp_mutex);
+ VLOG_DBG("Releasing \"%s\" mempool", mp->name);
+ rte_mempool_free(mp);
+ ovs_mutex_unlock(&dpdk_mp_mutex);
}
-/* Tries to allocate new mempool on requested_socket_id with
- * mbuf size corresponding to requested_mtu.
- * On success new configuration will be applied.
+/* Tries to allocate a new mempool - or re-use an existing one where
+ * appropriate - on requested_socket_id with a size determined by
+ * requested_mtu and requested Rx/Tx queues.
+ * On success - or when re-using an existing mempool - the new configuration
+ * will be applied.
* On error, device will be left unchanged. */
static int
netdev_dpdk_mempool_configure(struct netdev_dpdk *dev)
- OVS_REQUIRES(dpdk_mutex)
OVS_REQUIRES(dev->mutex)
{
uint32_t buf_size = dpdk_buf_size(dev->requested_mtu);
- struct dpdk_mp *mp;
+ struct rte_mempool *mp;
+ int ret = 0;
- mp = dpdk_mp_get(dev->requested_socket_id, FRAME_LEN_TO_MTU(buf_size));
+ mp = dpdk_mp_create(dev, FRAME_LEN_TO_MTU(buf_size));
if (!mp) {
- VLOG_ERR("Insufficient memory to create memory pool for netdev "
- "%s, with MTU %d on socket %d\n",
- dev->up.name, dev->requested_mtu, dev->requested_socket_id);
- return ENOMEM;
+ VLOG_ERR("Failed to create memory pool for netdev "
+ "%s, with MTU %d on socket %d: %s\n",
+ dev->up.name, dev->requested_mtu, dev->requested_socket_id,
+ rte_strerror(rte_errno));
+ ret = rte_errno;
} else {
- dpdk_mp_put(dev->dpdk_mp);
- dev->dpdk_mp = mp;
+ /* If a new MTU was requested and its rounded value equals the one
+ * that is currently used, then the existing mempool is returned. */
+ if (dev->mp != mp) {
+ /* A new mempool was created, release the previous one. */
+ dpdk_mp_free(dev->mp);
+ } else {
+ ret = EEXIST;
+ }
+ dev->mp = mp;
dev->mtu = dev->requested_mtu;
dev->socket_id = dev->requested_socket_id;
dev->max_packet_len = MTU_TO_FRAME_LEN(dev->mtu);
}
- return 0;
+ return ret;
}
static void
dev->link_reset_cnt++;
dev->link = link;
if (dev->link.link_status) {
- VLOG_DBG_RL(&rl, "Port %d Link Up - speed %u Mbps - %s",
- dev->port_id, (unsigned)dev->link.link_speed,
+ VLOG_DBG_RL(&rl, "Port %"PRIu8" Link Up - speed %u Mbps - %s",
+ dev->port_id, (unsigned) dev->link.link_speed,
(dev->link.link_duplex == ETH_LINK_FULL_DUPLEX) ?
("full-duplex") : ("half-duplex"));
} else {
- VLOG_DBG_RL(&rl, "Port %d Link Down", dev->port_id);
+ VLOG_DBG_RL(&rl, "Port %"PRIu8" Link Down", dev->port_id);
}
}
}
int i;
struct rte_eth_conf conf = port_conf;
+ /* For some NICs (e.g. Niantic), scatter_rx mode needs to be explicitly
+ * enabled. */
if (dev->mtu > ETHER_MTU) {
- conf.rxmode.jumbo_frame = 1;
- conf.rxmode.max_rx_pkt_len = dev->max_packet_len;
- } else {
- conf.rxmode.jumbo_frame = 0;
- conf.rxmode.max_rx_pkt_len = 0;
+ conf.rxmode.enable_scatter = 1;
}
+
+ conf.rxmode.hw_ip_checksum = (dev->hw_ol_features &
+ NETDEV_RX_CHECKSUM_OFFLOAD) != 0;
/* A device may report more queues than it makes available (this has
* been observed for Intel xl710, which reserves some of them for
* SRIOV): rte_eth_*_queue_setup will fail if a queue is not
break;
}
+ diag = rte_eth_dev_set_mtu(dev->port_id, dev->mtu);
+ if (diag) {
+ VLOG_ERR("Interface %s MTU (%d) setup error: %s",
+ dev->up.name, dev->mtu, rte_strerror(-diag));
+ break;
+ }
+
for (i = 0; i < n_txq; i++) {
- diag = rte_eth_tx_queue_setup(dev->port_id, i, NIC_PORT_TX_Q_SIZE,
+ diag = rte_eth_tx_queue_setup(dev->port_id, i, dev->txq_size,
dev->socket_id, NULL);
if (diag) {
VLOG_INFO("Interface %s txq(%d) setup error: %s",
}
for (i = 0; i < n_rxq; i++) {
- diag = rte_eth_rx_queue_setup(dev->port_id, i, NIC_PORT_RX_Q_SIZE,
- dev->socket_id, NULL,
- dev->dpdk_mp->mp);
+ diag = rte_eth_rx_queue_setup(dev->port_id, i, dev->rxq_size,
+ dev->socket_id, NULL, dev->mp);
if (diag) {
VLOG_INFO("Interface %s rxq(%d) setup error: %s",
dev->up.name, i, rte_strerror(-diag));
dpdk_eth_flow_ctrl_setup(struct netdev_dpdk *dev) OVS_REQUIRES(dev->mutex)
{
if (rte_eth_dev_flow_ctrl_set(dev->port_id, &dev->fc_conf)) {
- VLOG_WARN("Failed to enable flow control on device %d", dev->port_id);
+ VLOG_WARN("Failed to enable flow control on device %"PRIu8,
+ dev->port_id);
}
}
static int
-dpdk_eth_dev_init(struct netdev_dpdk *dev) OVS_REQUIRES(dpdk_mutex)
+dpdk_eth_dev_init(struct netdev_dpdk *dev)
+ OVS_REQUIRES(dev->mutex)
{
struct rte_pktmbuf_pool_private *mbp_priv;
struct rte_eth_dev_info info;
struct ether_addr eth_addr;
int diag;
int n_rxq, n_txq;
-
- if (!rte_eth_dev_is_valid_port(dev->port_id)) {
- return ENODEV;
- }
+ uint32_t rx_chksm_offload_capa = DEV_RX_OFFLOAD_UDP_CKSUM |
+ DEV_RX_OFFLOAD_TCP_CKSUM |
+ DEV_RX_OFFLOAD_IPV4_CKSUM;
rte_eth_dev_info_get(dev->port_id, &info);
+ if ((info.rx_offload_capa & rx_chksm_offload_capa) !=
+ rx_chksm_offload_capa) {
+ VLOG_WARN("Rx checksum offload is not supported on port %"PRIu8,
+ dev->port_id);
+ dev->hw_ol_features &= ~NETDEV_RX_CHECKSUM_OFFLOAD;
+ } else {
+ dev->hw_ol_features |= NETDEV_RX_CHECKSUM_OFFLOAD;
+ }
+
n_rxq = MIN(info.max_rx_queues, dev->up.n_rxq);
n_txq = MIN(info.max_tx_queues, dev->up.n_txq);
memset(ð_addr, 0x0, sizeof(eth_addr));
rte_eth_macaddr_get(dev->port_id, ð_addr);
- VLOG_INFO_RL(&rl, "Port %d: "ETH_ADDR_FMT"",
+ VLOG_INFO_RL(&rl, "Port %"PRIu8": "ETH_ADDR_FMT,
dev->port_id, ETH_ADDR_BYTES_ARGS(eth_addr.addr_bytes));
memcpy(dev->hwaddr.ea, eth_addr.addr_bytes, ETH_ADDR_LEN);
rte_eth_link_get_nowait(dev->port_id, &dev->link);
- mbp_priv = rte_mempool_get_priv(dev->dpdk_mp->mp);
+ mbp_priv = rte_mempool_get_priv(dev->mp);
dev->buf_size = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
- dev->flags = NETDEV_UP | NETDEV_PROMISC;
-
/* Get the Flow control configuration for DPDK-ETH */
diag = rte_eth_dev_flow_ctrl_get(dev->port_id, &dev->fc_conf);
if (diag) {
- VLOG_DBG("cannot get flow control parameters on port=%d, err=%d",
+ VLOG_DBG("cannot get flow control parameters on port=%"PRIu8", err=%d",
dev->port_id, diag);
}
{
struct netdev_dpdk *dev;
- if (!rte_eal_init_ret) { /* Only after successful initialization */
- dev = dpdk_rte_mzalloc(sizeof *dev);
- if (dev) {
- return &dev->up;
- }
+ dev = dpdk_rte_mzalloc(sizeof *dev);
+ if (dev) {
+ return &dev->up;
}
+
return NULL;
}
-static void
-netdev_dpdk_alloc_txq(struct netdev_dpdk *dev, unsigned int n_txqs)
+static struct dpdk_tx_queue *
+netdev_dpdk_alloc_txq(unsigned int n_txqs)
{
+ struct dpdk_tx_queue *txqs;
unsigned i;
- dev->tx_q = dpdk_rte_mzalloc(n_txqs * sizeof *dev->tx_q);
- for (i = 0; i < n_txqs; i++) {
- /* Initialize map for vhost devices. */
- dev->tx_q[i].map = OVS_VHOST_QUEUE_MAP_UNKNOWN;
- rte_spinlock_init(&dev->tx_q[i].tx_lock);
+ txqs = dpdk_rte_mzalloc(n_txqs * sizeof *txqs);
+ if (txqs) {
+ for (i = 0; i < n_txqs; i++) {
+ /* Initialize map for vhost devices. */
+ txqs[i].map = OVS_VHOST_QUEUE_MAP_UNKNOWN;
+ rte_spinlock_init(&txqs[i].tx_lock);
+ }
}
+
+ return txqs;
}
static int
-netdev_dpdk_init(struct netdev *netdev, unsigned int port_no,
- enum dpdk_dev_type type)
+common_construct(struct netdev *netdev, dpdk_port_t port_no,
+ enum dpdk_dev_type type, int socket_id)
OVS_REQUIRES(dpdk_mutex)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- int sid;
- int err = 0;
ovs_mutex_init(&dev->mutex);
- ovs_mutex_lock(&dev->mutex);
rte_spinlock_init(&dev->stats_lock);
/* If the 'sid' is negative, it means that the kernel fails
* to obtain the pci numa info. In that situation, always
* use 'SOCKET0'. */
- if (type == DPDK_DEV_ETH) {
- sid = rte_eth_dev_socket_id(port_no);
- } else {
- sid = rte_lcore_to_socket_id(rte_get_master_lcore());
- }
-
- dev->socket_id = sid < 0 ? SOCKET0 : sid;
+ dev->socket_id = socket_id < 0 ? SOCKET0 : socket_id;
dev->requested_socket_id = dev->socket_id;
dev->port_id = port_no;
dev->type = type;
dev->flags = 0;
- dev->requested_mtu = dev->mtu = ETHER_MTU;
+ dev->requested_mtu = ETHER_MTU;
dev->max_packet_len = MTU_TO_FRAME_LEN(dev->mtu);
ovsrcu_index_init(&dev->vid, -1);
dev->vhost_reconfigured = false;
+ dev->attached = false;
- err = netdev_dpdk_mempool_configure(dev);
- if (err) {
- goto unlock;
- }
-
- /* Initialise QoS configuration to NULL and qos lock to unlocked */
- dev->qos_conf = NULL;
- rte_spinlock_init(&dev->qos_lock);
+ ovsrcu_init(&dev->qos_conf, NULL);
- /* Initialise rcu pointer for ingress policer to NULL */
ovsrcu_init(&dev->ingress_policer, NULL);
dev->policer_rate = 0;
dev->policer_burst = 0;
- netdev->n_rxq = NR_QUEUE;
- netdev->n_txq = NR_QUEUE;
- dev->requested_n_rxq = netdev->n_rxq;
- dev->requested_n_txq = netdev->n_txq;
+ netdev->n_rxq = 0;
+ netdev->n_txq = 0;
+ dev->requested_n_rxq = NR_QUEUE;
+ dev->requested_n_txq = NR_QUEUE;
+ dev->requested_rxq_size = NIC_PORT_DEFAULT_RXQ_SIZE;
+ dev->requested_txq_size = NIC_PORT_DEFAULT_TXQ_SIZE;
/* Initialize the flow control to NULL */
memset(&dev->fc_conf, 0, sizeof dev->fc_conf);
- if (type == DPDK_DEV_ETH) {
- err = dpdk_eth_dev_init(dev);
- if (err) {
- goto unlock;
- }
- netdev_dpdk_alloc_txq(dev, netdev->n_txq);
- } else {
- netdev_dpdk_alloc_txq(dev, OVS_VHOST_MAX_QUEUE_NUM);
- /* Enable DPDK_DEV_VHOST device and set promiscuous mode flag. */
- dev->flags = NETDEV_UP | NETDEV_PROMISC;
- }
+
+ /* Initilize the hardware offload flags to 0 */
+ dev->hw_ol_features = 0;
+
+ dev->flags = NETDEV_UP | NETDEV_PROMISC;
ovs_list_push_back(&dpdk_list, &dev->list_node);
-unlock:
- ovs_mutex_unlock(&dev->mutex);
- return err;
+ netdev_request_reconfigure(netdev);
+
+ return 0;
}
/* dev_name must be the prefix followed by a positive decimal number.
}
}
+static int
+vhost_common_construct(struct netdev *netdev)
+ OVS_REQUIRES(dpdk_mutex)
+{
+ int socket_id = rte_lcore_to_socket_id(rte_get_master_lcore());
+ struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+
+ dev->tx_q = netdev_dpdk_alloc_txq(OVS_VHOST_MAX_QUEUE_NUM);
+ if (!dev->tx_q) {
+ return ENOMEM;
+ }
+
+ return common_construct(netdev, DPDK_ETH_PORT_ID_INVALID,
+ DPDK_DEV_VHOST, socket_id);
+}
+
static int
netdev_dpdk_vhost_construct(struct netdev *netdev)
{
return EINVAL;
}
- if (rte_eal_init_ret) {
- return rte_eal_init_ret;
- }
-
ovs_mutex_lock(&dpdk_mutex);
/* Take the name of the vhost-user port and append it to the location where
* the socket is to be created, then register the socket.
*/
snprintf(dev->vhost_id, sizeof dev->vhost_id, "%s/%s",
- vhost_sock_dir, name);
+ dpdk_get_vhost_sock_dir(), name);
dev->vhost_driver_flags &= ~RTE_VHOST_USER_CLIENT;
err = rte_vhost_driver_register(dev->vhost_id, dev->vhost_driver_flags);
if (err) {
VLOG_ERR("vhost-user socket device setup failure for socket %s\n",
dev->vhost_id);
+ goto out;
} else {
fatal_signal_add_file_to_unlink(dev->vhost_id);
VLOG_INFO("Socket %s created for vhost-user port %s\n",
dev->vhost_id, name);
}
- err = netdev_dpdk_init(netdev, -1, DPDK_DEV_VHOST);
+ err = rte_vhost_driver_callback_register(dev->vhost_id,
+ &virtio_net_device_ops);
+ if (err) {
+ VLOG_ERR("rte_vhost_driver_callback_register failed for vhost user "
+ "port: %s\n", name);
+ goto out;
+ }
+
+ err = rte_vhost_driver_disable_features(dev->vhost_id,
+ 1ULL << VIRTIO_NET_F_HOST_TSO4
+ | 1ULL << VIRTIO_NET_F_HOST_TSO6
+ | 1ULL << VIRTIO_NET_F_CSUM);
+ if (err) {
+ VLOG_ERR("rte_vhost_driver_disable_features failed for vhost user "
+ "port: %s\n", name);
+ goto out;
+ }
+
+ err = rte_vhost_driver_start(dev->vhost_id);
+ if (err) {
+ VLOG_ERR("rte_vhost_driver_start failed for vhost user "
+ "port: %s\n", name);
+ goto out;
+ }
+
+ err = vhost_common_construct(netdev);
+ if (err) {
+ VLOG_ERR("vhost_common_construct failed for vhost user "
+ "port: %s\n", name);
+ }
+
+out:
ovs_mutex_unlock(&dpdk_mutex);
+ VLOG_WARN_ONCE("dpdkvhostuser ports are considered deprecated; "
+ "please migrate to dpdkvhostuserclient ports.");
return err;
}
{
int err;
- if (rte_eal_init_ret) {
- return rte_eal_init_ret;
- }
-
ovs_mutex_lock(&dpdk_mutex);
- err = netdev_dpdk_init(netdev, -1, DPDK_DEV_VHOST);
+ err = vhost_common_construct(netdev);
+ if (err) {
+ VLOG_ERR("vhost_common_construct failed for vhost user client"
+ "port: %s\n", netdev->name);
+ }
ovs_mutex_unlock(&dpdk_mutex);
return err;
}
static int
netdev_dpdk_construct(struct netdev *netdev)
{
- unsigned int port_no;
int err;
- if (rte_eal_init_ret) {
- return rte_eal_init_ret;
- }
-
- /* Names always start with "dpdk" */
- err = dpdk_dev_parse_name(netdev->name, "dpdk", &port_no);
- if (err) {
- return err;
- }
-
ovs_mutex_lock(&dpdk_mutex);
- err = netdev_dpdk_init(netdev, port_no, DPDK_DEV_ETH);
+ err = common_construct(netdev, DPDK_ETH_PORT_ID_INVALID,
+ DPDK_DEV_ETH, SOCKET0);
ovs_mutex_unlock(&dpdk_mutex);
return err;
}
+static void
+common_destruct(struct netdev_dpdk *dev)
+ OVS_REQUIRES(dpdk_mutex)
+ OVS_EXCLUDED(dev->mutex)
+{
+ rte_free(dev->tx_q);
+ dpdk_mp_free(dev->mp);
+
+ ovs_list_remove(&dev->list_node);
+ free(ovsrcu_get_protected(struct ingress_policer *,
+ &dev->ingress_policer));
+ ovs_mutex_destroy(&dev->mutex);
+}
+
static void
netdev_dpdk_destruct(struct netdev *netdev)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ char devname[RTE_ETH_NAME_MAX_LEN];
ovs_mutex_lock(&dpdk_mutex);
- ovs_mutex_lock(&dev->mutex);
rte_eth_dev_stop(dev->port_id);
- free(ovsrcu_get_protected(struct ingress_policer *,
- &dev->ingress_policer));
- rte_free(dev->tx_q);
- ovs_list_remove(&dev->list_node);
- dpdk_mp_put(dev->dpdk_mp);
+ if (dev->attached) {
+ rte_eth_dev_close(dev->port_id);
+ if (rte_eth_dev_detach(dev->port_id, devname) < 0) {
+ VLOG_ERR("Device '%s' can not be detached", dev->devargs);
+ } else {
+ VLOG_INFO("Device '%s' has been detached", devname);
+ }
+ }
+
+ free(dev->devargs);
+ common_destruct(dev);
- ovs_mutex_unlock(&dev->mutex);
ovs_mutex_unlock(&dpdk_mutex);
}
char *vhost_id;
ovs_mutex_lock(&dpdk_mutex);
- ovs_mutex_lock(&dev->mutex);
/* Guest becomes an orphan if still attached. */
if (netdev_dpdk_get_vid(dev) >= 0
&& !(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT)) {
VLOG_ERR("Removing port '%s' while vhost device still attached.",
netdev->name);
- VLOG_ERR("To restore connectivity after re-adding of port, VM on socket"
- " '%s' must be restarted.", dev->vhost_id);
+ VLOG_ERR("To restore connectivity after re-adding of port, VM on "
+ "socket '%s' must be restarted.", dev->vhost_id);
}
- free(ovsrcu_get_protected(struct ingress_policer *,
- &dev->ingress_policer));
-
- rte_free(dev->tx_q);
- ovs_list_remove(&dev->list_node);
- dpdk_mp_put(dev->dpdk_mp);
-
vhost_id = xstrdup(dev->vhost_id);
- ovs_mutex_unlock(&dev->mutex);
+ common_destruct(dev);
+
ovs_mutex_unlock(&dpdk_mutex);
+ if (!vhost_id[0]) {
+ goto out;
+ }
+
if (dpdk_vhost_driver_unregister(dev, vhost_id)) {
- VLOG_ERR("Unable to remove vhost-user socket %s", vhost_id);
+ VLOG_ERR("%s: Unable to unregister vhost driver for socket '%s'.\n",
+ netdev->name, vhost_id);
} else if (!(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT)) {
/* OVS server mode - remove this socket from list for deletion */
fatal_signal_remove_file_to_unlink(vhost_id);
}
+out:
free(vhost_id);
}
smap_add_format(args, "requested_tx_queues", "%d", dev->requested_n_txq);
smap_add_format(args, "configured_tx_queues", "%d", netdev->n_txq);
smap_add_format(args, "mtu", "%d", dev->mtu);
+
+ if (dev->type == DPDK_DEV_ETH) {
+ smap_add_format(args, "requested_rxq_descriptors", "%d",
+ dev->requested_rxq_size);
+ smap_add_format(args, "configured_rxq_descriptors", "%d",
+ dev->rxq_size);
+ smap_add_format(args, "requested_txq_descriptors", "%d",
+ dev->requested_txq_size);
+ smap_add_format(args, "configured_txq_descriptors", "%d",
+ dev->txq_size);
+ if (dev->hw_ol_features & NETDEV_RX_CHECKSUM_OFFLOAD) {
+ smap_add(args, "rx_csum_offload", "true");
+ } else {
+ smap_add(args, "rx_csum_offload", "false");
+ }
+ }
ovs_mutex_unlock(&dev->mutex);
return 0;
}
+static struct netdev_dpdk *
+netdev_dpdk_lookup_by_port_id(dpdk_port_t port_id)
+ OVS_REQUIRES(dpdk_mutex)
+{
+ struct netdev_dpdk *dev;
+
+ LIST_FOR_EACH (dev, list_node, &dpdk_list) {
+ if (dev->port_id == port_id) {
+ return dev;
+ }
+ }
+
+ return NULL;
+}
+
+static dpdk_port_t
+netdev_dpdk_process_devargs(struct netdev_dpdk *dev,
+ const char *devargs, char **errp)
+{
+ /* Get the name up to the first comma. */
+ char *name = xmemdup0(devargs, strcspn(devargs, ","));
+ dpdk_port_t new_port_id = DPDK_ETH_PORT_ID_INVALID;
+
+ if (rte_eth_dev_get_port_by_name(name, &new_port_id)
+ || !rte_eth_dev_is_valid_port(new_port_id)) {
+ /* Device not found in DPDK, attempt to attach it */
+ if (!rte_eth_dev_attach(devargs, &new_port_id)) {
+ /* Attach successful */
+ dev->attached = true;
+ VLOG_INFO("Device '%s' attached to DPDK", devargs);
+ } else {
+ /* Attach unsuccessful */
+ new_port_id = DPDK_ETH_PORT_ID_INVALID;
+ VLOG_WARN_BUF(errp, "Error attaching device '%s' to DPDK",
+ devargs);
+ }
+ }
+
+ free(name);
+ return new_port_id;
+}
+
static void
dpdk_set_rxq_config(struct netdev_dpdk *dev, const struct smap *args)
+ OVS_REQUIRES(dev->mutex)
{
int new_n_rxq;
- new_n_rxq = MAX(smap_get_int(args, "n_rxq", dev->requested_n_rxq), 1);
+ new_n_rxq = MAX(smap_get_int(args, "n_rxq", NR_QUEUE), 1);
if (new_n_rxq != dev->requested_n_rxq) {
dev->requested_n_rxq = new_n_rxq;
netdev_request_reconfigure(&dev->up);
}
}
-static int
-netdev_dpdk_set_config(struct netdev *netdev, const struct smap *args)
+static void
+dpdk_process_queue_size(struct netdev *netdev, const struct smap *args,
+ const char *flag, int default_size, int *new_size)
{
- struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
-
- ovs_mutex_lock(&dev->mutex);
-
- dpdk_set_rxq_config(dev, args);
-
- /* Flow control support is only available for DPDK Ethernet ports. */
- bool rx_fc_en = false;
- bool tx_fc_en = false;
- enum rte_eth_fc_mode fc_mode_set[2][2] =
- {{RTE_FC_NONE, RTE_FC_TX_PAUSE},
- {RTE_FC_RX_PAUSE, RTE_FC_FULL}
- };
- rx_fc_en = smap_get_bool(args, "rx-flow-ctrl", false);
- tx_fc_en = smap_get_bool(args, "tx-flow-ctrl", false);
- dev->fc_conf.autoneg = smap_get_bool(args, "flow-ctrl-autoneg", false);
- dev->fc_conf.mode = fc_mode_set[tx_fc_en][rx_fc_en];
-
- dpdk_eth_flow_ctrl_setup(dev);
+ int queue_size = smap_get_int(args, flag, default_size);
- ovs_mutex_unlock(&dev->mutex);
+ if (queue_size <= 0 || queue_size > NIC_PORT_MAX_Q_SIZE
+ || !is_pow2(queue_size)) {
+ queue_size = default_size;
+ }
- return 0;
+ if (queue_size != *new_size) {
+ *new_size = queue_size;
+ netdev_request_reconfigure(netdev);
+ }
}
static int
-netdev_dpdk_ring_set_config(struct netdev *netdev, const struct smap *args)
+netdev_dpdk_set_config(struct netdev *netdev, const struct smap *args,
+ char **errp)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ bool rx_fc_en, tx_fc_en, autoneg;
+ enum rte_eth_fc_mode fc_mode;
+ static const enum rte_eth_fc_mode fc_mode_set[2][2] = {
+ {RTE_FC_NONE, RTE_FC_TX_PAUSE},
+ {RTE_FC_RX_PAUSE, RTE_FC_FULL }
+ };
+ const char *new_devargs;
+ int err = 0;
+ ovs_mutex_lock(&dpdk_mutex);
ovs_mutex_lock(&dev->mutex);
+
dpdk_set_rxq_config(dev, args);
- ovs_mutex_unlock(&dev->mutex);
- return 0;
-}
+ dpdk_process_queue_size(netdev, args, "n_rxq_desc",
+ NIC_PORT_DEFAULT_RXQ_SIZE,
+ &dev->requested_rxq_size);
+ dpdk_process_queue_size(netdev, args, "n_txq_desc",
+ NIC_PORT_DEFAULT_TXQ_SIZE,
+ &dev->requested_txq_size);
-static int
-netdev_dpdk_vhost_client_set_config(struct netdev *netdev,
- const struct smap *args)
-{
- struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ new_devargs = smap_get(args, "dpdk-devargs");
+
+ if (dev->devargs && strcmp(new_devargs, dev->devargs)) {
+ /* The user requested a new device. If we return error, the caller
+ * will delete this netdev and try to recreate it. */
+ err = EAGAIN;
+ goto out;
+ }
+
+ /* dpdk-devargs is required for device configuration */
+ if (new_devargs && new_devargs[0]) {
+ /* Don't process dpdk-devargs if value is unchanged and port id
+ * is valid */
+ if (!(dev->devargs && !strcmp(dev->devargs, new_devargs)
+ && rte_eth_dev_is_valid_port(dev->port_id))) {
+ dpdk_port_t new_port_id = netdev_dpdk_process_devargs(dev,
+ new_devargs,
+ errp);
+ if (!rte_eth_dev_is_valid_port(new_port_id)) {
+ err = EINVAL;
+ } else if (new_port_id == dev->port_id) {
+ /* Already configured, do not reconfigure again */
+ err = 0;
+ } else {
+ struct netdev_dpdk *dup_dev;
+
+ dup_dev = netdev_dpdk_lookup_by_port_id(new_port_id);
+ if (dup_dev) {
+ VLOG_WARN_BUF(errp, "'%s' is trying to use device '%s' "
+ "which is already in use by '%s'",
+ netdev_get_name(netdev), new_devargs,
+ netdev_get_name(&dup_dev->up));
+ err = EADDRINUSE;
+ } else {
+ int sid = rte_eth_dev_socket_id(new_port_id);
+
+ dev->requested_socket_id = sid < 0 ? SOCKET0 : sid;
+ dev->devargs = xstrdup(new_devargs);
+ dev->port_id = new_port_id;
+ netdev_request_reconfigure(&dev->up);
+ err = 0;
+ }
+ }
+ }
+ } else {
+ VLOG_WARN_BUF(errp, "'%s' is missing 'options:dpdk-devargs'. "
+ "The old 'dpdk<port_id>' names are not supported",
+ netdev_get_name(netdev));
+ err = EINVAL;
+ }
+
+ if (err) {
+ goto out;
+ }
+
+ rx_fc_en = smap_get_bool(args, "rx-flow-ctrl", false);
+ tx_fc_en = smap_get_bool(args, "tx-flow-ctrl", false);
+ autoneg = smap_get_bool(args, "flow-ctrl-autoneg", false);
+
+ fc_mode = fc_mode_set[tx_fc_en][rx_fc_en];
+ if (dev->fc_conf.mode != fc_mode || autoneg != dev->fc_conf.autoneg) {
+ dev->fc_conf.mode = fc_mode;
+ dev->fc_conf.autoneg = autoneg;
+ dpdk_eth_flow_ctrl_setup(dev);
+ }
+
+out:
+ ovs_mutex_unlock(&dev->mutex);
+ ovs_mutex_unlock(&dpdk_mutex);
+
+ return err;
+}
+
+static int
+netdev_dpdk_ring_set_config(struct netdev *netdev, const struct smap *args,
+ char **errp OVS_UNUSED)
+{
+ struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+
+ ovs_mutex_lock(&dev->mutex);
+ dpdk_set_rxq_config(dev, args);
+ ovs_mutex_unlock(&dev->mutex);
+
+ return 0;
+}
+
+static int
+netdev_dpdk_vhost_client_set_config(struct netdev *netdev,
+ const struct smap *args,
+ char **errp OVS_UNUSED)
+{
+ struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
const char *path;
ovs_mutex_lock(&dev->mutex);
{
struct netdev_rxq_dpdk *rx = dpdk_rte_mzalloc(sizeof *rx);
- return &rx->up;
+ if (rx) {
+ return &rx->up;
+ }
+
+ return NULL;
}
static struct netdev_rxq_dpdk *
rte_free(rx);
}
-static inline void
+/* Tries to transmit 'pkts' to txq 'qid' of device 'dev'. Takes ownership of
+ * 'pkts', even in case of failure.
+ *
+ * Returns the number of packets that weren't transmitted. */
+static inline int
netdev_dpdk_eth_tx_burst(struct netdev_dpdk *dev, int qid,
- struct rte_mbuf **pkts, int cnt)
+ struct rte_mbuf **pkts, int cnt)
{
uint32_t nb_tx = 0;
}
if (OVS_UNLIKELY(nb_tx != cnt)) {
- /* free buffers, which we couldn't transmit, one at a time (each
+ /* Free buffers, which we couldn't transmit, one at a time (each
* packet could come from a different mempool) */
int i;
for (i = nb_tx; i < cnt; i++) {
rte_pktmbuf_free(pkts[i]);
}
- rte_spinlock_lock(&dev->stats_lock);
- dev->stats.tx_dropped += cnt - nb_tx;
- rte_spinlock_unlock(&dev->stats_lock);
}
+
+ return cnt - nb_tx;
}
static inline bool
static int
netdev_dpdk_policer_run(struct rte_meter_srtcm *meter,
- struct rte_mbuf **pkts, int pkt_cnt)
+ struct rte_mbuf **pkts, int pkt_cnt,
+ bool may_steal)
{
int i = 0;
int cnt = 0;
}
cnt++;
} else {
- rte_pktmbuf_free(pkt);
+ if (may_steal) {
+ rte_pktmbuf_free(pkt);
+ }
}
}
static int
ingress_policer_run(struct ingress_policer *policer, struct rte_mbuf **pkts,
- int pkt_cnt)
+ int pkt_cnt, bool may_steal)
{
int cnt = 0;
rte_spinlock_lock(&policer->policer_lock);
- cnt = netdev_dpdk_policer_run(&policer->in_policer, pkts, pkt_cnt);
+ cnt = netdev_dpdk_policer_run(&policer->in_policer, pkts,
+ pkt_cnt, may_steal);
rte_spinlock_unlock(&policer->policer_lock);
return cnt;
struct dp_packet_batch *batch)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(rxq->netdev);
- int qid = rxq->queue_id;
struct ingress_policer *policer = netdev_dpdk_get_ingress_policer(dev);
uint16_t nb_rx = 0;
uint16_t dropped = 0;
+ int qid = rxq->queue_id;
+ int vid = netdev_dpdk_get_vid(dev);
- if (OVS_UNLIKELY(!is_vhost_running(dev)
+ if (OVS_UNLIKELY(vid < 0 || !dev->vhost_reconfigured
|| !(dev->flags & NETDEV_UP))) {
return EAGAIN;
}
- nb_rx = rte_vhost_dequeue_burst(netdev_dpdk_get_vid(dev),
- qid * VIRTIO_QNUM + VIRTIO_TXQ,
- dev->dpdk_mp->mp,
+ nb_rx = rte_vhost_dequeue_burst(vid, qid * VIRTIO_QNUM + VIRTIO_TXQ,
+ dev->mp,
(struct rte_mbuf **) batch->packets,
NETDEV_MAX_BURST);
if (!nb_rx) {
dropped = nb_rx;
nb_rx = ingress_policer_run(policer,
(struct rte_mbuf **) batch->packets,
- nb_rx);
+ nb_rx, true);
dropped -= nb_rx;
}
nb_rx, dropped);
rte_spinlock_unlock(&dev->stats_lock);
- batch->count = (int) nb_rx;
+ batch->count = nb_rx;
+ dp_packet_batch_init_packet_fields(batch);
+
return 0;
}
int nb_rx;
int dropped = 0;
+ if (OVS_UNLIKELY(!(dev->flags & NETDEV_UP))) {
+ return EAGAIN;
+ }
+
nb_rx = rte_eth_rx_burst(rx->port_id, rxq->queue_id,
(struct rte_mbuf **) batch->packets,
NETDEV_MAX_BURST);
if (policer) {
dropped = nb_rx;
nb_rx = ingress_policer_run(policer,
- (struct rte_mbuf **)batch->packets,
- nb_rx);
+ (struct rte_mbuf **) batch->packets,
+ nb_rx, true);
dropped -= nb_rx;
}
}
batch->count = nb_rx;
+ dp_packet_batch_init_packet_fields(batch);
return 0;
}
static inline int
-netdev_dpdk_qos_run__(struct netdev_dpdk *dev, struct rte_mbuf **pkts,
- int cnt)
+netdev_dpdk_qos_run(struct netdev_dpdk *dev, struct rte_mbuf **pkts,
+ int cnt, bool may_steal)
{
- struct netdev *netdev = &dev->up;
+ struct qos_conf *qos_conf = ovsrcu_get(struct qos_conf *, &dev->qos_conf);
- if (dev->qos_conf != NULL) {
- rte_spinlock_lock(&dev->qos_lock);
- if (dev->qos_conf != NULL) {
- cnt = dev->qos_conf->ops->qos_run(netdev, pkts, cnt);
- }
- rte_spinlock_unlock(&dev->qos_lock);
+ if (qos_conf) {
+ rte_spinlock_lock(&qos_conf->lock);
+ cnt = qos_conf->ops->qos_run(qos_conf, pkts, cnt, may_steal);
+ rte_spinlock_unlock(&qos_conf->lock);
}
return cnt;
unsigned int total_pkts = cnt;
unsigned int dropped = 0;
int i, retries = 0;
+ int vid = netdev_dpdk_get_vid(dev);
qid = dev->tx_q[qid % netdev->n_txq].map;
- if (OVS_UNLIKELY(!is_vhost_running(dev) || qid < 0
+ if (OVS_UNLIKELY(vid < 0 || !dev->vhost_reconfigured || qid < 0
|| !(dev->flags & NETDEV_UP))) {
rte_spinlock_lock(&dev->stats_lock);
dev->stats.tx_dropped+= cnt;
cnt = netdev_dpdk_filter_packet_len(dev, cur_pkts, cnt);
/* Check has QoS has been configured for the netdev */
- cnt = netdev_dpdk_qos_run__(dev, cur_pkts, cnt);
+ cnt = netdev_dpdk_qos_run(dev, cur_pkts, cnt, true);
dropped = total_pkts - cnt;
do {
int vhost_qid = qid * VIRTIO_QNUM + VIRTIO_RXQ;
unsigned int tx_pkts;
- tx_pkts = rte_vhost_enqueue_burst(netdev_dpdk_get_vid(dev),
- vhost_qid, cur_pkts, cnt);
+ tx_pkts = rte_vhost_enqueue_burst(vid, vhost_qid, cur_pkts, cnt);
if (OVS_LIKELY(tx_pkts)) {
/* Packets have been sent.*/
cnt -= tx_pkts;
dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch)
OVS_NO_THREAD_SAFETY_ANALYSIS
{
+ const size_t batch_cnt = dp_packet_batch_size(batch);
#if !defined(__CHECKER__) && !defined(_WIN32)
- const size_t PKT_ARRAY_SIZE = batch->count;
+ const size_t PKT_ARRAY_SIZE = batch_cnt;
#else
/* Sparse or MSVC doesn't like variable length array. */
enum { PKT_ARRAY_SIZE = NETDEV_MAX_BURST };
#endif
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- struct rte_mbuf *mbufs[PKT_ARRAY_SIZE];
- int dropped = 0;
- int newcnt = 0;
- int i;
-
- /* If we are on a non pmd thread we have to use the mempool mutex, because
- * every non pmd thread shares the same mempool cache */
+ struct rte_mbuf *pkts[PKT_ARRAY_SIZE];
+ uint32_t cnt = batch_cnt;
+ uint32_t dropped = 0;
- if (!dpdk_thread_is_pmd()) {
- ovs_mutex_lock(&nonpmd_mempool_mutex);
+ if (dev->type != DPDK_DEV_VHOST) {
+ /* Check if QoS has been configured for this netdev. */
+ cnt = netdev_dpdk_qos_run(dev, (struct rte_mbuf **) batch->packets,
+ batch_cnt, false);
+ dropped += batch_cnt - cnt;
}
- dp_packet_batch_apply_cutlen(batch);
+ uint32_t txcnt = 0;
- for (i = 0; i < batch->count; i++) {
- int size = dp_packet_size(batch->packets[i]);
+ for (uint32_t i = 0; i < cnt; i++) {
+ struct dp_packet *packet = batch->packets[i];
+ uint32_t size = dp_packet_size(packet);
if (OVS_UNLIKELY(size > dev->max_packet_len)) {
- VLOG_WARN_RL(&rl, "Too big size %d max_packet_len %d",
- (int)size , dev->max_packet_len);
+ VLOG_WARN_RL(&rl, "Too big size %u max_packet_len %d",
+ size, dev->max_packet_len);
dropped++;
continue;
}
- mbufs[newcnt] = rte_pktmbuf_alloc(dev->dpdk_mp->mp);
-
- if (!mbufs[newcnt]) {
- dropped += batch->count - i;
+ pkts[txcnt] = rte_pktmbuf_alloc(dev->mp);
+ if (OVS_UNLIKELY(!pkts[txcnt])) {
+ dropped += cnt - i;
break;
}
/* We have to do a copy for now */
- memcpy(rte_pktmbuf_mtod(mbufs[newcnt], void *),
- dp_packet_data(batch->packets[i]), size);
-
- rte_pktmbuf_data_len(mbufs[newcnt]) = size;
- rte_pktmbuf_pkt_len(mbufs[newcnt]) = size;
+ memcpy(rte_pktmbuf_mtod(pkts[txcnt], void *),
+ dp_packet_data(packet), size);
+ dp_packet_set_size((struct dp_packet *)pkts[txcnt], size);
- newcnt++;
+ txcnt++;
}
- if (dev->type == DPDK_DEV_VHOST) {
- __netdev_dpdk_vhost_send(netdev, qid, (struct dp_packet **) mbufs,
- newcnt);
- } else {
- unsigned int qos_pkts = newcnt;
-
- /* Check if QoS has been configured for this netdev. */
- newcnt = netdev_dpdk_qos_run__(dev, mbufs, newcnt);
-
- dropped += qos_pkts - newcnt;
- netdev_dpdk_eth_tx_burst(dev, qid, mbufs, newcnt);
+ if (OVS_LIKELY(txcnt)) {
+ if (dev->type == DPDK_DEV_VHOST) {
+ __netdev_dpdk_vhost_send(netdev, qid, (struct dp_packet **) pkts,
+ txcnt);
+ } else {
+ dropped += netdev_dpdk_eth_tx_burst(dev, qid, pkts, txcnt);
+ }
}
if (OVS_UNLIKELY(dropped)) {
dev->stats.tx_dropped += dropped;
rte_spinlock_unlock(&dev->stats_lock);
}
-
- if (!dpdk_thread_is_pmd()) {
- ovs_mutex_unlock(&nonpmd_mempool_mutex);
- }
}
static int
netdev_dpdk_vhost_send(struct netdev *netdev, int qid,
struct dp_packet_batch *batch,
- bool may_steal, bool concurrent_txq OVS_UNUSED)
+ bool concurrent_txq OVS_UNUSED)
{
- if (OVS_UNLIKELY(!may_steal || batch->packets[0]->source != DPBUF_DPDK)) {
+ if (OVS_UNLIKELY(batch->packets[0]->source != DPBUF_DPDK)) {
dpdk_do_tx_copy(netdev, qid, batch);
- dp_packet_delete_batch(batch, may_steal);
+ dp_packet_delete_batch(batch, true);
} else {
- dp_packet_batch_apply_cutlen(batch);
__netdev_dpdk_vhost_send(netdev, qid, batch->packets, batch->count);
}
return 0;
static inline void
netdev_dpdk_send__(struct netdev_dpdk *dev, int qid,
- struct dp_packet_batch *batch, bool may_steal,
+ struct dp_packet_batch *batch,
bool concurrent_txq)
{
+ if (OVS_UNLIKELY(!(dev->flags & NETDEV_UP))) {
+ dp_packet_delete_batch(batch, true);
+ return;
+ }
+
if (OVS_UNLIKELY(concurrent_txq)) {
qid = qid % dev->up.n_txq;
rte_spinlock_lock(&dev->tx_q[qid].tx_lock);
}
- if (OVS_UNLIKELY(!may_steal ||
- batch->packets[0]->source != DPBUF_DPDK)) {
+ if (OVS_UNLIKELY(batch->packets[0]->source != DPBUF_DPDK)) {
struct netdev *netdev = &dev->up;
dpdk_do_tx_copy(netdev, qid, batch);
- dp_packet_delete_batch(batch, may_steal);
+ dp_packet_delete_batch(batch, true);
} else {
- int dropped;
- int cnt = batch->count;
- struct rte_mbuf **cur_pkts = (struct rte_mbuf **) batch->packets;
+ int tx_cnt, dropped;
+ int batch_cnt = dp_packet_batch_size(batch);
+ struct rte_mbuf **pkts = (struct rte_mbuf **) batch->packets;
- dp_packet_batch_apply_cutlen(batch);
+ tx_cnt = netdev_dpdk_filter_packet_len(dev, pkts, batch_cnt);
+ tx_cnt = netdev_dpdk_qos_run(dev, pkts, tx_cnt, true);
+ dropped = batch_cnt - tx_cnt;
- cnt = netdev_dpdk_filter_packet_len(dev, cur_pkts, cnt);
- cnt = netdev_dpdk_qos_run__(dev, cur_pkts, cnt);
- dropped = batch->count - cnt;
-
- netdev_dpdk_eth_tx_burst(dev, qid, cur_pkts, cnt);
+ dropped += netdev_dpdk_eth_tx_burst(dev, qid, pkts, tx_cnt);
if (OVS_UNLIKELY(dropped)) {
rte_spinlock_lock(&dev->stats_lock);
static int
netdev_dpdk_eth_send(struct netdev *netdev, int qid,
- struct dp_packet_batch *batch, bool may_steal,
- bool concurrent_txq)
+ struct dp_packet_batch *batch, bool concurrent_txq)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- netdev_dpdk_send__(dev, qid, batch, may_steal, concurrent_txq);
+ netdev_dpdk_send__(dev, qid, batch, concurrent_txq);
return 0;
}
rte_spinlock_lock(&dev->stats_lock);
/* Supported Stats */
- stats->rx_packets += dev->stats.rx_packets;
- stats->tx_packets += dev->stats.tx_packets;
+ stats->rx_packets = dev->stats.rx_packets;
+ stats->tx_packets = dev->stats.tx_packets;
stats->rx_dropped = dev->stats.rx_dropped;
- stats->tx_dropped += dev->stats.tx_dropped;
+ stats->tx_dropped = dev->stats.tx_dropped;
stats->multicast = dev->stats.multicast;
stats->rx_bytes = dev->stats.rx_bytes;
stats->tx_bytes = dev->stats.tx_bytes;
stats->tx_1024_to_1522_packets = xstats[i].value;
} else if (strcmp(XSTAT_TX_1523_TO_MAX_PACKETS, names[i].name) == 0) {
stats->tx_1523_to_max_packets = xstats[i].value;
+ } else if (strcmp(XSTAT_RX_MULTICAST_PACKETS, names[i].name) == 0) {
+ stats->multicast = xstats[i].value;
} else if (strcmp(XSTAT_TX_MULTICAST_PACKETS, names[i].name) == 0) {
stats->tx_multicast_packets = xstats[i].value;
} else if (strcmp(XSTAT_RX_BROADCAST_PACKETS, names[i].name) == 0) {
int rte_xstats_len, rte_xstats_new_len, rte_xstats_ret;
if (rte_eth_stats_get(dev->port_id, &rte_stats)) {
- VLOG_ERR("Can't get ETH statistics for port: %i.", dev->port_id);
+ VLOG_ERR("Can't get ETH statistics for port: %"PRIu8, dev->port_id);
ovs_mutex_unlock(&dev->mutex);
return EPROTO;
}
/* Get length of statistics */
rte_xstats_len = rte_eth_xstats_get_names(dev->port_id, NULL, 0);
if (rte_xstats_len < 0) {
- VLOG_WARN("Cannot get XSTATS values for port: %i", dev->port_id);
+ VLOG_WARN("Cannot get XSTATS values for port: %"PRIu8, dev->port_id);
goto out;
}
/* Reserve memory for xstats names and values */
rte_xstats_names,
rte_xstats_len);
if (rte_xstats_new_len != rte_xstats_len) {
- VLOG_WARN("Cannot get XSTATS names for port: %i.", dev->port_id);
+ VLOG_WARN("Cannot get XSTATS names for port: %"PRIu8, dev->port_id);
goto out;
}
/* Retreive xstats values */
netdev_dpdk_convert_xstats(stats, rte_xstats, rte_xstats_names,
rte_xstats_len);
} else {
- VLOG_WARN("Cannot get XSTATS values for port: %i.", dev->port_id);
+ VLOG_WARN("Cannot get XSTATS values for port: %"PRIu8, dev->port_id);
}
out:
stats->tx_packets = rte_stats.opackets;
stats->rx_bytes = rte_stats.ibytes;
stats->tx_bytes = rte_stats.obytes;
- /* DPDK counts imissed as errors, but count them here as dropped instead */
- stats->rx_errors = rte_stats.ierrors - rte_stats.imissed;
+ stats->rx_errors = rte_stats.ierrors;
stats->tx_errors = rte_stats.oerrors;
rte_spinlock_lock(&dev->stats_lock);
static int
netdev_dpdk_get_features(const struct netdev *netdev,
enum netdev_features *current,
- enum netdev_features *advertised OVS_UNUSED,
- enum netdev_features *supported OVS_UNUSED,
- enum netdev_features *peer OVS_UNUSED)
+ enum netdev_features *advertised,
+ enum netdev_features *supported,
+ enum netdev_features *peer)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
struct rte_eth_link link;
*current |= NETDEV_F_AUTONEG;
}
+ *advertised = *supported = *peer = 0;
+
return 0;
}
rte_spinlock_init(&policer->policer_lock);
/* rte_meter requires bytes so convert kbits rate and burst to bytes. */
- rate_bytes = rate * 1000/8;
- burst_bytes = burst * 1000/8;
+ rate_bytes = rate * 1000ULL / 8;
+ burst_bytes = burst * 1000ULL / 8;
policer->app_srtcm_params.cir = rate_bytes;
policer->app_srtcm_params.cbs = burst_bytes;
policer->app_srtcm_params.ebs = 0;
err = rte_meter_srtcm_config(&policer->in_policer,
&policer->app_srtcm_params);
- if(err) {
+ if (err) {
VLOG_ERR("Could not create rte meter for ingress policer");
return NULL;
}
netdev_dpdk_get_ifindex(const struct netdev *netdev)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- int ifindex;
ovs_mutex_lock(&dev->mutex);
- ifindex = dev->port_id;
+ /* Calculate hash from the netdev name. Ensure that ifindex is a 24-bit
+ * postive integer to meet RFC 2863 recommendations.
+ */
+ int ifindex = hash_string(netdev->name, 0) % 0xfffffe + 1;
ovs_mutex_unlock(&dev->mutex);
return ifindex;
enum netdev_flags *old_flagsp)
OVS_REQUIRES(dev->mutex)
{
- int err;
-
if ((off | on) & ~(NETDEV_UP | NETDEV_PROMISC)) {
return EINVAL;
}
}
if (dev->type == DPDK_DEV_ETH) {
- if (dev->flags & NETDEV_UP) {
- err = rte_eth_dev_start(dev->port_id);
- if (err)
- return -err;
- }
-
if (dev->flags & NETDEV_PROMISC) {
rte_eth_promiscuous_enable(dev->port_id);
}
- if (!(dev->flags & NETDEV_UP)) {
- rte_eth_dev_stop(dev->port_id);
- }
+ netdev_change_seq_changed(&dev->up);
} else {
/* If DPDK_DEV_VHOST device's NETDEV_UP flag was changed and vhost is
* running then change netdev's change_seq to trigger link state
/* Clear statistics if device is getting up. */
if (NETDEV_UP & on) {
rte_spinlock_lock(&dev->stats_lock);
- memset(&dev->stats, 0, sizeof(dev->stats));
+ memset(&dev->stats, 0, sizeof dev->stats);
rte_spinlock_unlock(&dev->stats_lock);
}
}
ovs_mutex_unlock(&dev->mutex);
smap_add_format(args, "port_no", "%d", dev->port_id);
- smap_add_format(args, "numa_id", "%d", rte_eth_dev_socket_id(dev->port_id));
+ smap_add_format(args, "numa_id", "%d",
+ rte_eth_dev_socket_id(dev->port_id));
smap_add_format(args, "driver_name", "%s", dev_info.driver_name);
smap_add_format(args, "min_rx_bufsize", "%u", dev_info.min_rx_bufsize);
smap_add_format(args, "max_rx_pktlen", "%u", dev->max_packet_len);
smap_add_format(args, "max_rx_queues", "%u", dev_info.max_rx_queues);
smap_add_format(args, "max_tx_queues", "%u", dev_info.max_tx_queues);
smap_add_format(args, "max_mac_addrs", "%u", dev_info.max_mac_addrs);
- smap_add_format(args, "max_hash_mac_addrs", "%u", dev_info.max_hash_mac_addrs);
+ smap_add_format(args, "max_hash_mac_addrs", "%u",
+ dev_info.max_hash_mac_addrs);
smap_add_format(args, "max_vfs", "%u", dev_info.max_vfs);
smap_add_format(args, "max_vmdq_pools", "%u", dev_info.max_vmdq_pools);
+ /* Querying the DPDK library for iftype may be done in future, pending
+ * support; cf. RFC 3635 Section 3.2.4. */
+ enum { IF_TYPE_ETHERNETCSMACD = 6 };
+
+ smap_add_format(args, "if_type", "%"PRIu32, IF_TYPE_ETHERNETCSMACD);
+ smap_add_format(args, "if_descr", "%s %s", rte_version(),
+ dev_info.driver_name);
+
if (dev_info.pci_dev) {
smap_add_format(args, "pci-vendor_id", "0x%u",
dev_info.pci_dev->id.vendor_id);
if (argc > 2) {
struct netdev *netdev = netdev_from_name(argv[1]);
+
if (netdev && is_dpdk_class(netdev->netdev_class)) {
- struct netdev_dpdk *dpdk_dev = netdev_dpdk_cast(netdev);
+ struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- ovs_mutex_lock(&dpdk_dev->mutex);
- netdev_dpdk_set_admin_state__(dpdk_dev, up);
- ovs_mutex_unlock(&dpdk_dev->mutex);
+ ovs_mutex_lock(&dev->mutex);
+ netdev_dpdk_set_admin_state__(dev, up);
+ ovs_mutex_unlock(&dev->mutex);
netdev_close(netdev);
} else {
return;
}
} else {
- struct netdev_dpdk *netdev;
+ struct netdev_dpdk *dev;
ovs_mutex_lock(&dpdk_mutex);
- LIST_FOR_EACH (netdev, list_node, &dpdk_list) {
- ovs_mutex_lock(&netdev->mutex);
- netdev_dpdk_set_admin_state__(netdev, up);
- ovs_mutex_unlock(&netdev->mutex);
+ LIST_FOR_EACH (dev, list_node, &dpdk_list) {
+ ovs_mutex_lock(&dev->mutex);
+ netdev_dpdk_set_admin_state__(dev, up);
+ ovs_mutex_unlock(&dev->mutex);
}
ovs_mutex_unlock(&dpdk_mutex);
}
unixctl_command_reply(conn, "OK");
}
+static void
+netdev_dpdk_detach(struct unixctl_conn *conn, int argc OVS_UNUSED,
+ const char *argv[], void *aux OVS_UNUSED)
+{
+ int ret;
+ char *response;
+ dpdk_port_t port_id;
+ char devname[RTE_ETH_NAME_MAX_LEN];
+ struct netdev_dpdk *dev;
+
+ ovs_mutex_lock(&dpdk_mutex);
+
+ if (rte_eth_dev_get_port_by_name(argv[1], &port_id)) {
+ response = xasprintf("Device '%s' not found in DPDK", argv[1]);
+ goto error;
+ }
+
+ dev = netdev_dpdk_lookup_by_port_id(port_id);
+ if (dev) {
+ response = xasprintf("Device '%s' is being used by interface '%s'. "
+ "Remove it before detaching",
+ argv[1], netdev_get_name(&dev->up));
+ goto error;
+ }
+
+ rte_eth_dev_close(port_id);
+
+ ret = rte_eth_dev_detach(port_id, devname);
+ if (ret < 0) {
+ response = xasprintf("Device '%s' can not be detached", argv[1]);
+ goto error;
+ }
+
+ response = xasprintf("Device '%s' has been detached", argv[1]);
+
+ ovs_mutex_unlock(&dpdk_mutex);
+ unixctl_command_reply(conn, response);
+ free(response);
+ return;
+
+error:
+ ovs_mutex_unlock(&dpdk_mutex);
+ unixctl_command_reply_error(conn, response);
+ free(response);
+}
+
+static void
+netdev_dpdk_get_mempool_info(struct unixctl_conn *conn,
+ int argc, const char *argv[],
+ void *aux OVS_UNUSED)
+{
+ size_t size;
+ FILE *stream;
+ char *response = NULL;
+ struct netdev *netdev = NULL;
+
+ if (argc == 2) {
+ netdev = netdev_from_name(argv[1]);
+ if (!netdev || !is_dpdk_class(netdev->netdev_class)) {
+ unixctl_command_reply_error(conn, "Not a DPDK Interface");
+ goto out;
+ }
+ }
+
+ stream = open_memstream(&response, &size);
+ if (!stream) {
+ response = xasprintf("Unable to open memstream: %s.",
+ ovs_strerror(errno));
+ unixctl_command_reply_error(conn, response);
+ goto out;
+ }
+
+ if (netdev) {
+ struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+
+ ovs_mutex_lock(&dev->mutex);
+ ovs_mutex_lock(&dpdk_mp_mutex);
+
+ rte_mempool_dump(stream, dev->mp);
+
+ ovs_mutex_unlock(&dpdk_mp_mutex);
+ ovs_mutex_unlock(&dev->mutex);
+ } else {
+ ovs_mutex_lock(&dpdk_mp_mutex);
+ rte_mempool_list_dump(stream);
+ ovs_mutex_unlock(&dpdk_mp_mutex);
+ }
+
+ fclose(stream);
+
+ unixctl_command_reply(conn, response);
+out:
+ free(response);
+ netdev_close(netdev);
+}
+
/*
* Set virtqueue flags so that we do not receive interrupts.
*/
set_irq_status(int vid)
{
uint32_t i;
- uint64_t idx;
- for (i = 0; i < rte_vhost_get_queue_num(vid); i++) {
- idx = i * VIRTIO_QNUM;
- rte_vhost_enable_guest_notification(vid, idx + VIRTIO_RXQ, 0);
- rte_vhost_enable_guest_notification(vid, idx + VIRTIO_TXQ, 0);
+ for (i = 0; i < rte_vhost_get_vring_num(vid); i++) {
+ rte_vhost_enable_guest_notification(vid, i, 0);
}
}
int *enabled_queues, n_enabled = 0;
int i, k, total_txqs = dev->up.n_txq;
- enabled_queues = dpdk_rte_mzalloc(total_txqs * sizeof *enabled_queues);
+ enabled_queues = xcalloc(total_txqs, sizeof *enabled_queues);
for (i = 0; i < total_txqs; i++) {
/* Enabled queues always mapped to themselves. */
VLOG_DBG("%2d --> %2d", i, dev->tx_q[i].map);
}
- rte_free(enabled_queues);
+ free(enabled_queues);
}
/*
int newnode = 0;
char ifname[IF_NAME_SZ];
- rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
+ rte_vhost_get_ifname(vid, ifname, sizeof ifname);
ovs_mutex_lock(&dpdk_mutex);
/* Add device to the vhost port with the same name as that passed down. */
LIST_FOR_EACH(dev, list_node, &dpdk_list) {
ovs_mutex_lock(&dev->mutex);
if (strncmp(ifname, dev->vhost_id, IF_NAME_SZ) == 0) {
- uint32_t qp_num = rte_vhost_get_queue_num(vid);
+ uint32_t qp_num = rte_vhost_get_vring_num(vid)/VIRTIO_QNUM;
/* Get NUMA information */
newnode = rte_vhost_get_numa_node(vid);
bool exists = false;
char ifname[IF_NAME_SZ];
- rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
+ rte_vhost_get_ifname(vid, ifname, sizeof ifname);
ovs_mutex_lock(&dpdk_mutex);
LIST_FOR_EACH (dev, list_node, &dpdk_list) {
int qid = queue_id / VIRTIO_QNUM;
char ifname[IF_NAME_SZ];
- rte_vhost_get_ifname(vid, ifname, sizeof(ifname));
+ rte_vhost_get_ifname(vid, ifname, sizeof ifname);
if (queue_id % VIRTIO_QNUM == VIRTIO_TXQ) {
return 0;
return ovsrcu_get(struct ingress_policer *, &dev->ingress_policer);
}
-/*
- * These callbacks allow virtio-net devices to be added to vhost ports when
- * configuration has been fully complete.
- */
-static const struct virtio_net_device_ops virtio_net_device_ops =
+static int
+netdev_dpdk_class_init(void)
{
- .new_device = new_device,
- .destroy_device = destroy_device,
- .vring_state_changed = vring_state_changed
-};
+ static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
-static void *
-start_vhost_loop(void *dummy OVS_UNUSED)
-{
- pthread_detach(pthread_self());
- /* Put the vhost thread into quiescent state. */
- ovsrcu_quiesce_start();
- rte_vhost_driver_session_start();
- return NULL;
-}
+ /* This function can be called for different classes. The initialization
+ * needs to be done only once */
+ if (ovsthread_once_start(&once)) {
+ ovs_thread_create("dpdk_watchdog", dpdk_watchdog, NULL);
+ unixctl_command_register("netdev-dpdk/set-admin-state",
+ "[netdev] up|down", 1, 2,
+ netdev_dpdk_set_admin_state, NULL);
-static int
-dpdk_vhost_class_init(void)
-{
- rte_vhost_driver_callback_register(&virtio_net_device_ops);
- rte_vhost_feature_disable(1ULL << VIRTIO_NET_F_HOST_TSO4
- | 1ULL << VIRTIO_NET_F_HOST_TSO6
- | 1ULL << VIRTIO_NET_F_CSUM);
+ unixctl_command_register("netdev-dpdk/detach",
+ "pci address of device", 1, 1,
+ netdev_dpdk_detach, NULL);
- ovs_thread_create("vhost_thread", start_vhost_loop, NULL);
- return 0;
-}
+ unixctl_command_register("netdev-dpdk/get-mempool-info",
+ "[netdev]", 0, 1,
+ netdev_dpdk_get_mempool_info, NULL);
-static void
-dpdk_common_init(void)
-{
- unixctl_command_register("netdev-dpdk/set-admin-state",
- "[netdev] up|down", 1, 2,
- netdev_dpdk_set_admin_state, NULL);
+ ovsthread_once_done(&once);
+ }
+ return 0;
}
+
/* Client Rings */
static int
dpdk_ring_create(const char dev_name[], unsigned int port_no,
- unsigned int *eth_port_id)
+ dpdk_port_t *eth_port_id)
{
- struct dpdk_ring *ivshmem;
- char ring_name[RTE_RING_NAMESIZE];
- int err;
+ struct dpdk_ring *ring_pair;
+ char *ring_name;
+ int port_id;
- ivshmem = dpdk_rte_mzalloc(sizeof *ivshmem);
- if (ivshmem == NULL) {
+ ring_pair = dpdk_rte_mzalloc(sizeof *ring_pair);
+ if (!ring_pair) {
return ENOMEM;
}
/* XXX: Add support for multiquque ring. */
- err = snprintf(ring_name, sizeof(ring_name), "%s_tx", dev_name);
- if (err < 0) {
- return -err;
- }
+ ring_name = xasprintf("%s_tx", dev_name);
/* Create single producer tx ring, netdev does explicit locking. */
- ivshmem->cring_tx = rte_ring_create(ring_name, DPDK_RING_SIZE, SOCKET0,
+ ring_pair->cring_tx = rte_ring_create(ring_name, DPDK_RING_SIZE, SOCKET0,
RING_F_SP_ENQ);
- if (ivshmem->cring_tx == NULL) {
- rte_free(ivshmem);
+ free(ring_name);
+ if (ring_pair->cring_tx == NULL) {
+ rte_free(ring_pair);
return ENOMEM;
}
- err = snprintf(ring_name, sizeof(ring_name), "%s_rx", dev_name);
- if (err < 0) {
- return -err;
- }
+ ring_name = xasprintf("%s_rx", dev_name);
/* Create single consumer rx ring, netdev does explicit locking. */
- ivshmem->cring_rx = rte_ring_create(ring_name, DPDK_RING_SIZE, SOCKET0,
+ ring_pair->cring_rx = rte_ring_create(ring_name, DPDK_RING_SIZE, SOCKET0,
RING_F_SC_DEQ);
- if (ivshmem->cring_rx == NULL) {
- rte_free(ivshmem);
+ free(ring_name);
+ if (ring_pair->cring_rx == NULL) {
+ rte_free(ring_pair);
return ENOMEM;
}
- err = rte_eth_from_rings(dev_name, &ivshmem->cring_rx, 1,
- &ivshmem->cring_tx, 1, SOCKET0);
+ port_id = rte_eth_from_rings(dev_name, &ring_pair->cring_rx, 1,
+ &ring_pair->cring_tx, 1, SOCKET0);
- if (err < 0) {
- rte_free(ivshmem);
+ if (port_id < 0) {
+ rte_free(ring_pair);
return ENODEV;
}
- ivshmem->user_port_id = port_no;
- ivshmem->eth_port_id = rte_eth_dev_count() - 1;
- ovs_list_push_back(&dpdk_ring_list, &ivshmem->list_node);
+ ring_pair->user_port_id = port_no;
+ ring_pair->eth_port_id = port_id;
+ *eth_port_id = port_id;
+
+ ovs_list_push_back(&dpdk_ring_list, &ring_pair->list_node);
- *eth_port_id = ivshmem->eth_port_id;
return 0;
}
static int
-dpdk_ring_open(const char dev_name[], unsigned int *eth_port_id)
+dpdk_ring_open(const char dev_name[], dpdk_port_t *eth_port_id)
OVS_REQUIRES(dpdk_mutex)
{
- struct dpdk_ring *ivshmem;
+ struct dpdk_ring *ring_pair;
unsigned int port_no;
int err = 0;
return err;
}
- /* look through our list to find the device */
- LIST_FOR_EACH (ivshmem, list_node, &dpdk_ring_list) {
- if (ivshmem->user_port_id == port_no) {
+ /* Look through our list to find the device */
+ LIST_FOR_EACH (ring_pair, list_node, &dpdk_ring_list) {
+ if (ring_pair->user_port_id == port_no) {
VLOG_INFO("Found dpdk ring device %s:", dev_name);
- *eth_port_id = ivshmem->eth_port_id; /* really all that is needed */
+ /* Really all that is needed */
+ *eth_port_id = ring_pair->eth_port_id;
return 0;
}
}
static int
netdev_dpdk_ring_send(struct netdev *netdev, int qid,
- struct dp_packet_batch *batch, bool may_steal,
- bool concurrent_txq)
+ struct dp_packet_batch *batch, bool concurrent_txq)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- unsigned i;
+ struct dp_packet *packet;
- /* When using 'dpdkr' and sending to a DPDK ring, we want to ensure that the
- * rss hash field is clear. This is because the same mbuf may be modified by
- * the consumer of the ring and return into the datapath without recalculating
- * the RSS hash. */
- for (i = 0; i < batch->count; i++) {
- dp_packet_rss_invalidate(batch->packets[i]);
+ /* When using 'dpdkr' and sending to a DPDK ring, we want to ensure that
+ * the rss hash field is clear. This is because the same mbuf may be
+ * modified by the consumer of the ring and return into the datapath
+ * without recalculating the RSS hash. */
+ DP_PACKET_BATCH_FOR_EACH (packet, batch) {
+ dp_packet_mbuf_rss_flag_reset(packet);
}
- netdev_dpdk_send__(dev, qid, batch, may_steal, concurrent_txq);
+ netdev_dpdk_send__(dev, qid, batch, concurrent_txq);
return 0;
}
static int
netdev_dpdk_ring_construct(struct netdev *netdev)
{
- unsigned int port_no = 0;
+ dpdk_port_t port_no = 0;
int err = 0;
- if (rte_eal_init_ret) {
- return rte_eal_init_ret;
- }
-
ovs_mutex_lock(&dpdk_mutex);
err = dpdk_ring_open(netdev->name, &port_no);
goto unlock_dpdk;
}
- err = netdev_dpdk_init(netdev, port_no, DPDK_DEV_ETH);
-
+ err = common_construct(netdev, port_no, DPDK_DEV_ETH,
+ rte_eth_dev_socket_id(port_no));
unlock_dpdk:
ovs_mutex_unlock(&dpdk_mutex);
return err;
qos_conf_init(struct qos_conf *conf, const struct dpdk_qos_ops *ops)
{
conf->ops = ops;
+ rte_spinlock_init(&conf->lock);
}
/*
return NULL;
}
-/*
- * Call qos_destruct to clean up items associated with the netdevs
- * qos_conf. Set netdevs qos_conf to NULL.
- */
-static void
-qos_delete_conf(struct netdev *netdev)
-{
- struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
-
- rte_spinlock_lock(&dev->qos_lock);
- if (dev->qos_conf) {
- if (dev->qos_conf->ops->qos_destruct) {
- dev->qos_conf->ops->qos_destruct(netdev, dev->qos_conf);
- }
- dev->qos_conf = NULL;
- }
- rte_spinlock_unlock(&dev->qos_lock);
-}
-
static int
netdev_dpdk_get_qos_types(const struct netdev *netdev OVS_UNUSED,
struct sset *types)
const char **typep, struct smap *details)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ struct qos_conf *qos_conf;
int error = 0;
ovs_mutex_lock(&dev->mutex);
- if(dev->qos_conf) {
- *typep = dev->qos_conf->ops->qos_name;
- error = (dev->qos_conf->ops->qos_get
- ? dev->qos_conf->ops->qos_get(netdev, details): 0);
+ qos_conf = ovsrcu_get_protected(struct qos_conf *, &dev->qos_conf);
+ if (qos_conf) {
+ *typep = qos_conf->ops->qos_name;
+ error = (qos_conf->ops->qos_get
+ ? qos_conf->ops->qos_get(qos_conf, details): 0);
} else {
/* No QoS configuration set, return an empty string */
*typep = "";
}
static int
-netdev_dpdk_set_qos(struct netdev *netdev,
- const char *type, const struct smap *details)
+netdev_dpdk_set_qos(struct netdev *netdev, const char *type,
+ const struct smap *details)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
const struct dpdk_qos_ops *new_ops = NULL;
+ struct qos_conf *qos_conf, *new_qos_conf = NULL;
int error = 0;
- /* If type is empty or unsupported then the current QoS configuration
- * for the dpdk-netdev can be destroyed */
- new_ops = qos_lookup_name(type);
-
- if (type[0] == '\0' || !new_ops || !new_ops->qos_construct) {
- qos_delete_conf(netdev);
- return EOPNOTSUPP;
- }
-
ovs_mutex_lock(&dev->mutex);
- if (dev->qos_conf) {
- if (new_ops == dev->qos_conf->ops) {
- error = new_ops->qos_set ? new_ops->qos_set(netdev, details) : 0;
- } else {
- /* Delete existing QoS configuration. */
- qos_delete_conf(netdev);
- ovs_assert(dev->qos_conf == NULL);
+ qos_conf = ovsrcu_get_protected(struct qos_conf *, &dev->qos_conf);
- /* Install new QoS configuration. */
- error = new_ops->qos_construct(netdev, details);
+ new_ops = qos_lookup_name(type);
+
+ if (!new_ops || !new_ops->qos_construct) {
+ new_qos_conf = NULL;
+ if (type && type[0]) {
+ error = EOPNOTSUPP;
}
+ } else if (qos_conf && qos_conf->ops == new_ops
+ && qos_conf->ops->qos_is_equal(qos_conf, details)) {
+ new_qos_conf = qos_conf;
} else {
- error = new_ops->qos_construct(netdev, details);
+ error = new_ops->qos_construct(details, &new_qos_conf);
}
- ovs_assert((error == 0) == (dev->qos_conf != NULL));
if (error) {
- VLOG_ERR("Failed to set QoS type %s on port %s, returned error: %s",
- type, netdev->name, rte_strerror(-error));
+ VLOG_ERR("Failed to set QoS type %s on port %s: %s",
+ type, netdev->name, rte_strerror(error));
+ }
+
+ if (new_qos_conf != qos_conf) {
+ ovsrcu_set(&dev->qos_conf, new_qos_conf);
+ if (qos_conf) {
+ ovsrcu_postpone(qos_conf->ops->qos_destruct, qos_conf);
+ }
}
ovs_mutex_unlock(&dev->mutex);
+
return error;
}
struct rte_meter_srtcm egress_meter;
};
-static struct egress_policer *
-egress_policer_get__(const struct netdev *netdev)
+static void
+egress_policer_details_to_param(const struct smap *details,
+ struct rte_meter_srtcm_params *params)
{
- struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- return CONTAINER_OF(dev->qos_conf, struct egress_policer, qos_conf);
+ memset(params, 0, sizeof *params);
+ params->cir = smap_get_ullong(details, "cir", 0);
+ params->cbs = smap_get_ullong(details, "cbs", 0);
+ params->ebs = 0;
}
static int
-egress_policer_qos_construct(struct netdev *netdev,
- const struct smap *details)
+egress_policer_qos_construct(const struct smap *details,
+ struct qos_conf **conf)
{
- struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
struct egress_policer *policer;
int err = 0;
- rte_spinlock_lock(&dev->qos_lock);
policer = xmalloc(sizeof *policer);
qos_conf_init(&policer->qos_conf, &egress_policer_ops);
- dev->qos_conf = &policer->qos_conf;
- policer->app_srtcm_params.cir = smap_get_ullong(details, "cir", 0);
- policer->app_srtcm_params.cbs = smap_get_ullong(details, "cbs", 0);
- policer->app_srtcm_params.ebs = 0;
+ egress_policer_details_to_param(details, &policer->app_srtcm_params);
err = rte_meter_srtcm_config(&policer->egress_meter,
- &policer->app_srtcm_params);
-
- if (err < 0) {
- /* Error occurred during rte_meter creation, destroy the policer
- * and set the qos configuration for the netdev dpdk to NULL
- */
+ &policer->app_srtcm_params);
+ if (!err) {
+ *conf = &policer->qos_conf;
+ } else {
free(policer);
- dev->qos_conf = NULL;
+ *conf = NULL;
err = -err;
}
- rte_spinlock_unlock(&dev->qos_lock);
return err;
}
static void
-egress_policer_qos_destruct(struct netdev *netdev OVS_UNUSED,
- struct qos_conf *conf)
+egress_policer_qos_destruct(struct qos_conf *conf)
{
struct egress_policer *policer = CONTAINER_OF(conf, struct egress_policer,
- qos_conf);
+ qos_conf);
free(policer);
}
static int
-egress_policer_qos_get(const struct netdev *netdev, struct smap *details)
+egress_policer_qos_get(const struct qos_conf *conf, struct smap *details)
{
- struct egress_policer *policer = egress_policer_get__(netdev);
- smap_add_format(details, "cir", "%llu",
- 1ULL * policer->app_srtcm_params.cir);
- smap_add_format(details, "cbs", "%llu",
- 1ULL * policer->app_srtcm_params.cbs);
+ struct egress_policer *policer =
+ CONTAINER_OF(conf, struct egress_policer, qos_conf);
+
+ smap_add_format(details, "cir", "%"PRIu64, policer->app_srtcm_params.cir);
+ smap_add_format(details, "cbs", "%"PRIu64, policer->app_srtcm_params.cbs);
return 0;
}
-static int
-egress_policer_qos_set(struct netdev *netdev, const struct smap *details)
+static bool
+egress_policer_qos_is_equal(const struct qos_conf *conf,
+ const struct smap *details)
{
- struct egress_policer *policer;
- struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- int err = 0;
+ struct egress_policer *policer =
+ CONTAINER_OF(conf, struct egress_policer, qos_conf);
+ struct rte_meter_srtcm_params params;
- policer = egress_policer_get__(netdev);
- rte_spinlock_lock(&dev->qos_lock);
- policer->app_srtcm_params.cir = smap_get_ullong(details, "cir", 0);
- policer->app_srtcm_params.cbs = smap_get_ullong(details, "cbs", 0);
- policer->app_srtcm_params.ebs = 0;
- err = rte_meter_srtcm_config(&policer->egress_meter,
- &policer->app_srtcm_params);
-
- if (err < 0) {
- /* Error occurred during rte_meter creation, destroy the policer
- * and set the qos configuration for the netdev dpdk to NULL
- */
- free(policer);
- dev->qos_conf = NULL;
- err = -err;
- }
- rte_spinlock_unlock(&dev->qos_lock);
+ egress_policer_details_to_param(details, ¶ms);
- return err;
+ return !memcmp(¶ms, &policer->app_srtcm_params, sizeof params);
}
static int
-egress_policer_run(struct netdev *netdev, struct rte_mbuf **pkts, int pkt_cnt)
+egress_policer_run(struct qos_conf *conf, struct rte_mbuf **pkts, int pkt_cnt,
+ bool may_steal)
{
int cnt = 0;
- struct egress_policer *policer = egress_policer_get__(netdev);
+ struct egress_policer *policer =
+ CONTAINER_OF(conf, struct egress_policer, qos_conf);
- cnt = netdev_dpdk_policer_run(&policer->egress_meter, pkts, pkt_cnt);
+ cnt = netdev_dpdk_policer_run(&policer->egress_meter, pkts,
+ pkt_cnt, may_steal);
return cnt;
}
egress_policer_qos_construct,
egress_policer_qos_destruct,
egress_policer_qos_get,
- egress_policer_qos_set,
+ egress_policer_qos_is_equal,
egress_policer_run
};
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
int err = 0;
- ovs_mutex_lock(&dpdk_mutex);
ovs_mutex_lock(&dev->mutex);
if (netdev->n_txq == dev->requested_n_txq
&& netdev->n_rxq == dev->requested_n_rxq
- && dev->mtu == dev->requested_mtu) {
+ && dev->mtu == dev->requested_mtu
+ && dev->rxq_size == dev->requested_rxq_size
+ && dev->txq_size == dev->requested_txq_size
+ && dev->socket_id == dev->requested_socket_id) {
/* Reconfiguration is unnecessary */
goto out;
rte_eth_dev_stop(dev->port_id);
- if (dev->mtu != dev->requested_mtu) {
- netdev_dpdk_mempool_configure(dev);
+ err = netdev_dpdk_mempool_configure(dev);
+ if (err && err != EEXIST) {
+ goto out;
}
netdev->n_txq = dev->requested_n_txq;
netdev->n_rxq = dev->requested_n_rxq;
+ dev->rxq_size = dev->requested_rxq_size;
+ dev->txq_size = dev->requested_txq_size;
+
rte_free(dev->tx_q);
err = dpdk_eth_dev_init(dev);
- netdev_dpdk_alloc_txq(dev, netdev->n_txq);
+ dev->tx_q = netdev_dpdk_alloc_txq(netdev->n_txq);
+ if (!dev->tx_q) {
+ err = ENOMEM;
+ }
netdev_change_seq_changed(netdev);
out:
-
ovs_mutex_unlock(&dev->mutex);
- ovs_mutex_unlock(&dpdk_mutex);
-
return err;
}
-static void
+static int
dpdk_vhost_reconfigure_helper(struct netdev_dpdk *dev)
- OVS_REQUIRES(dpdk_mutex)
OVS_REQUIRES(dev->mutex)
{
dev->up.n_txq = dev->requested_n_txq;
dev->up.n_rxq = dev->requested_n_rxq;
+ int err;
/* Enable TX queue 0 by default if it wasn't disabled. */
if (dev->tx_q[0].map == OVS_VHOST_QUEUE_MAP_UNKNOWN) {
netdev_dpdk_remap_txqs(dev);
- if (dev->requested_socket_id != dev->socket_id
- || dev->requested_mtu != dev->mtu) {
- if (!netdev_dpdk_mempool_configure(dev)) {
+ err = netdev_dpdk_mempool_configure(dev);
+ if (!err) {
+ /* A new mempool was created. */
+ netdev_change_seq_changed(&dev->up);
+ } else if (err != EEXIST){
+ return err;
+ }
+ if (netdev_dpdk_get_vid(dev) >= 0) {
+ if (dev->vhost_reconfigured == false) {
+ dev->vhost_reconfigured = true;
+ /* Carrier status may need updating. */
netdev_change_seq_changed(&dev->up);
}
}
- if (netdev_dpdk_get_vid(dev) >= 0) {
- dev->vhost_reconfigured = true;
- }
+ return 0;
}
static int
netdev_dpdk_vhost_reconfigure(struct netdev *netdev)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ int err;
- ovs_mutex_lock(&dpdk_mutex);
ovs_mutex_lock(&dev->mutex);
-
- dpdk_vhost_reconfigure_helper(dev);
-
+ err = dpdk_vhost_reconfigure_helper(dev);
ovs_mutex_unlock(&dev->mutex);
- ovs_mutex_unlock(&dpdk_mutex);
- return 0;
+ return err;
}
static int
netdev_dpdk_vhost_client_reconfigure(struct netdev *netdev)
{
struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
- int err = 0;
+ int err;
+ uint64_t vhost_flags = 0;
- ovs_mutex_lock(&dpdk_mutex);
ovs_mutex_lock(&dev->mutex);
- dpdk_vhost_reconfigure_helper(dev);
-
/* Configure vHost client mode if requested and if the following criteria
* are met:
* 1. Device hasn't been registered yet.
*/
if (!(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT)
&& strlen(dev->vhost_id)) {
- /* Register client-mode device */
- err = rte_vhost_driver_register(dev->vhost_id,
- RTE_VHOST_USER_CLIENT);
+ /* Register client-mode device. */
+ vhost_flags |= RTE_VHOST_USER_CLIENT;
+
+ /* Enable IOMMU support, if explicitly requested. */
+ if (dpdk_vhost_iommu_enabled()) {
+ vhost_flags |= RTE_VHOST_USER_IOMMU_SUPPORT;
+ }
+ err = rte_vhost_driver_register(dev->vhost_id, vhost_flags);
if (err) {
VLOG_ERR("vhost-user device setup failure for device %s\n",
dev->vhost_id);
+ goto unlock;
} else {
/* Configuration successful */
- dev->vhost_driver_flags |= RTE_VHOST_USER_CLIENT;
+ dev->vhost_driver_flags |= vhost_flags;
VLOG_INFO("vHost User device '%s' created in 'client' mode, "
"using client socket '%s'",
dev->up.name, dev->vhost_id);
}
+
+ err = rte_vhost_driver_callback_register(dev->vhost_id,
+ &virtio_net_device_ops);
+ if (err) {
+ VLOG_ERR("rte_vhost_driver_callback_register failed for "
+ "vhost user client port: %s\n", dev->up.name);
+ goto unlock;
+ }
+
+ err = rte_vhost_driver_disable_features(dev->vhost_id,
+ 1ULL << VIRTIO_NET_F_HOST_TSO4
+ | 1ULL << VIRTIO_NET_F_HOST_TSO6
+ | 1ULL << VIRTIO_NET_F_CSUM);
+ if (err) {
+ VLOG_ERR("rte_vhost_driver_disable_features failed for vhost user "
+ "client port: %s\n", dev->up.name);
+ goto unlock;
+ }
+
+ err = rte_vhost_driver_start(dev->vhost_id);
+ if (err) {
+ VLOG_ERR("rte_vhost_driver_start failed for vhost user "
+ "client port: %s\n", dev->up.name);
+ goto unlock;
+ }
}
+ err = dpdk_vhost_reconfigure_helper(dev);
+
+unlock:
ovs_mutex_unlock(&dev->mutex);
- ovs_mutex_unlock(&dpdk_mutex);
- return 0;
+ return err;
}
-#define NETDEV_DPDK_CLASS(NAME, CONSTRUCT, DESTRUCT, \
+#define NETDEV_DPDK_CLASS(NAME, INIT, CONSTRUCT, DESTRUCT, \
SET_CONFIG, SET_TX_MULTIQ, SEND, \
GET_CARRIER, GET_STATS, \
GET_FEATURES, GET_STATUS, \
{ \
NAME, \
true, /* is_pmd */ \
- NULL, /* init */ \
+ INIT, /* init */ \
NULL, /* netdev_dpdk_run */ \
NULL, /* netdev_dpdk_wait */ \
\
GET_STATS, \
GET_FEATURES, \
NULL, /* set_advertisements */ \
+ NULL, /* get_pt_mode */ \
\
netdev_dpdk_set_policing, \
netdev_dpdk_get_qos_types, \
RXQ_RECV, \
NULL, /* rx_wait */ \
NULL, /* rxq_drain */ \
-}
-
-static int
-process_vhost_flags(char *flag, char *default_val, int size,
- const struct smap *ovs_other_config,
- char **new_val)
-{
- const char *val;
- int changed = 0;
-
- val = smap_get(ovs_other_config, flag);
-
- /* Process the vhost-sock-dir flag if it is provided, otherwise resort to
- * default value.
- */
- if (val && (strlen(val) <= size)) {
- changed = 1;
- *new_val = xstrdup(val);
- VLOG_INFO("User-provided %s in use: %s", flag, *new_val);
- } else {
- VLOG_INFO("No %s provided - defaulting to %s", flag, default_val);
- *new_val = default_val;
- }
-
- return changed;
-}
-
-static char **
-grow_argv(char ***argv, size_t cur_siz, size_t grow_by)
-{
- return xrealloc(*argv, sizeof(char *) * (cur_siz + grow_by));
-}
-
-static void
-dpdk_option_extend(char ***argv, int argc, const char *option,
- const char *value)
-{
- char **newargv = grow_argv(argv, argc, 2);
- *argv = newargv;
- newargv[argc] = xstrdup(option);
- newargv[argc+1] = xstrdup(value);
-}
-
-static char **
-move_argv(char ***argv, size_t cur_size, char **src_argv, size_t src_argc)
-{
- char **newargv = grow_argv(argv, cur_size, src_argc);
- while (src_argc--) {
- newargv[cur_size+src_argc] = src_argv[src_argc];
- src_argv[src_argc] = NULL;
- }
- return newargv;
-}
-
-static int
-extra_dpdk_args(const char *ovs_extra_config, char ***argv, int argc)
-{
- int ret = argc;
- char *release_tok = xstrdup(ovs_extra_config);
- char *tok, *endptr = NULL;
-
- for (tok = strtok_r(release_tok, " ", &endptr); tok != NULL;
- tok = strtok_r(NULL, " ", &endptr)) {
- char **newarg = grow_argv(argv, ret, 1);
- *argv = newarg;
- newarg[ret++] = xstrdup(tok);
- }
- free(release_tok);
- return ret;
-}
-
-static bool
-argv_contains(char **argv_haystack, const size_t argc_haystack,
- const char *needle)
-{
- for (size_t i = 0; i < argc_haystack; ++i) {
- if (!strcmp(argv_haystack[i], needle))
- return true;
- }
- return false;
-}
-
-static int
-construct_dpdk_options(const struct smap *ovs_other_config,
- char ***argv, const int initial_size,
- char **extra_args, const size_t extra_argc)
-{
- struct dpdk_options_map {
- const char *ovs_configuration;
- const char *dpdk_option;
- bool default_enabled;
- const char *default_value;
- } opts[] = {
- {"dpdk-lcore-mask", "-c", false, NULL},
- {"dpdk-hugepage-dir", "--huge-dir", false, NULL},
- };
-
- int i, ret = initial_size;
-
- /*First, construct from the flat-options (non-mutex)*/
- for (i = 0; i < ARRAY_SIZE(opts); ++i) {
- const char *lookup = smap_get(ovs_other_config,
- opts[i].ovs_configuration);
- if (!lookup && opts[i].default_enabled) {
- lookup = opts[i].default_value;
- }
-
- if (lookup) {
- if (!argv_contains(extra_args, extra_argc, opts[i].dpdk_option)) {
- dpdk_option_extend(argv, ret, opts[i].dpdk_option, lookup);
- ret += 2;
- } else {
- VLOG_WARN("Ignoring database defined option '%s' due to "
- "dpdk_extras config", opts[i].dpdk_option);
- }
- }
- }
-
- return ret;
-}
-
-#define MAX_DPDK_EXCL_OPTS 10
-
-static int
-construct_dpdk_mutex_options(const struct smap *ovs_other_config,
- char ***argv, const int initial_size,
- char **extra_args, const size_t extra_argc)
-{
- struct dpdk_exclusive_options_map {
- const char *category;
- const char *ovs_dpdk_options[MAX_DPDK_EXCL_OPTS];
- const char *eal_dpdk_options[MAX_DPDK_EXCL_OPTS];
- const char *default_value;
- int default_option;
- } excl_opts[] = {
- {"memory type",
- {"dpdk-alloc-mem", "dpdk-socket-mem", NULL,},
- {"-m", "--socket-mem", NULL,},
- "1024,0", 1
- },
- };
-
- int i, ret = initial_size;
- for (i = 0; i < ARRAY_SIZE(excl_opts); ++i) {
- int found_opts = 0, scan, found_pos = -1;
- const char *found_value;
- struct dpdk_exclusive_options_map *popt = &excl_opts[i];
-
- for (scan = 0; scan < MAX_DPDK_EXCL_OPTS
- && popt->ovs_dpdk_options[scan]; ++scan) {
- const char *lookup = smap_get(ovs_other_config,
- popt->ovs_dpdk_options[scan]);
- if (lookup && strlen(lookup)) {
- found_opts++;
- found_pos = scan;
- found_value = lookup;
- }
- }
-
- if (!found_opts) {
- if (popt->default_option) {
- found_pos = popt->default_option;
- found_value = popt->default_value;
- } else {
- continue;
- }
- }
-
- if (found_opts > 1) {
- VLOG_ERR("Multiple defined options for %s. Please check your"
- " database settings and reconfigure if necessary.",
- popt->category);
- }
-
- if (!argv_contains(extra_args, extra_argc,
- popt->eal_dpdk_options[found_pos])) {
- dpdk_option_extend(argv, ret, popt->eal_dpdk_options[found_pos],
- found_value);
- ret += 2;
- } else {
- VLOG_WARN("Ignoring database defined option '%s' due to "
- "dpdk_extras config", popt->eal_dpdk_options[found_pos]);
- }
- }
-
- return ret;
-}
-
-static int
-get_dpdk_args(const struct smap *ovs_other_config, char ***argv,
- int argc)
-{
- const char *extra_configuration;
- char **extra_args = NULL;
- int i;
- size_t extra_argc = 0;
-
- extra_configuration = smap_get(ovs_other_config, "dpdk-extra");
- if (extra_configuration) {
- extra_argc = extra_dpdk_args(extra_configuration, &extra_args, 0);
- }
-
- i = construct_dpdk_options(ovs_other_config, argv, argc, extra_args,
- extra_argc);
- i = construct_dpdk_mutex_options(ovs_other_config, argv, i, extra_args,
- extra_argc);
-
- if (extra_configuration) {
- *argv = move_argv(argv, i, extra_args, extra_argc);
- }
-
- return i + extra_argc;
-}
-
-static char **dpdk_argv;
-static int dpdk_argc;
-
-static void
-deferred_argv_release(void)
-{
- int result;
- for (result = 0; result < dpdk_argc; ++result) {
- free(dpdk_argv[result]);
- }
-
- free(dpdk_argv);
-}
-
-static void
-dpdk_init__(const struct smap *ovs_other_config)
-{
- char **argv = NULL;
- int result;
- int argc, argc_tmp;
- bool auto_determine = true;
- int err = 0;
- cpu_set_t cpuset;
- char *sock_dir_subcomponent;
-
- if (!smap_get_bool(ovs_other_config, "dpdk-init", false)) {
- VLOG_INFO("DPDK Disabled - to change this requires a restart.\n");
- return;
- }
-
- VLOG_INFO("DPDK Enabled, initializing");
- if (process_vhost_flags("vhost-sock-dir", xstrdup(ovs_rundir()),
- NAME_MAX, ovs_other_config,
- &sock_dir_subcomponent)) {
- struct stat s;
- if (!strstr(sock_dir_subcomponent, "..")) {
- vhost_sock_dir = xasprintf("%s/%s", ovs_rundir(),
- sock_dir_subcomponent);
-
- err = stat(vhost_sock_dir, &s);
- if (err) {
- VLOG_ERR("vhost-user sock directory '%s' does not exist.",
- vhost_sock_dir);
- }
- } else {
- vhost_sock_dir = xstrdup(ovs_rundir());
- VLOG_ERR("vhost-user sock directory request '%s/%s' has invalid"
- "characters '..' - using %s instead.",
- ovs_rundir(), sock_dir_subcomponent, ovs_rundir());
- }
- free(sock_dir_subcomponent);
- } else {
- vhost_sock_dir = sock_dir_subcomponent;
- }
-
- argv = grow_argv(&argv, 0, 1);
- argc = 1;
- argv[0] = xstrdup(ovs_get_program_name());
- argc_tmp = get_dpdk_args(ovs_other_config, &argv, argc);
-
- while (argc_tmp != argc) {
- if (!strcmp("-c", argv[argc]) || !strcmp("-l", argv[argc])) {
- auto_determine = false;
- break;
- }
- argc++;
- }
- argc = argc_tmp;
-
- /**
- * NOTE: This is an unsophisticated mechanism for determining the DPDK
- * lcore for the DPDK Master.
- */
- if (auto_determine) {
- int i;
- /* Get the main thread affinity */
- CPU_ZERO(&cpuset);
- err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t),
- &cpuset);
- if (!err) {
- for (i = 0; i < CPU_SETSIZE; i++) {
- if (CPU_ISSET(i, &cpuset)) {
- argv = grow_argv(&argv, argc, 2);
- argv[argc++] = xstrdup("-c");
- argv[argc++] = xasprintf("0x%08llX", (1ULL<<i));
- i = CPU_SETSIZE;
- }
- }
- } else {
- VLOG_ERR("Thread getaffinity error %d. Using core 0x1", err);
- /* User did not set dpdk-lcore-mask and unable to get current
- * thread affintity - default to core 0x1 */
- argv = grow_argv(&argv, argc, 2);
- argv[argc++] = xstrdup("-c");
- argv[argc++] = xasprintf("0x%X", 1);
- }
- }
-
- argv = grow_argv(&argv, argc, 1);
- argv[argc] = NULL;
-
- optind = 1;
-
- if (VLOG_IS_INFO_ENABLED()) {
- struct ds eal_args;
- int opt;
- ds_init(&eal_args);
- ds_put_cstr(&eal_args, "EAL ARGS:");
- for (opt = 0; opt < argc; ++opt) {
- ds_put_cstr(&eal_args, " ");
- ds_put_cstr(&eal_args, argv[opt]);
- }
- VLOG_INFO("%s", ds_cstr_ro(&eal_args));
- ds_destroy(&eal_args);
- }
-
- /* Make sure things are initialized ... */
- result = rte_eal_init(argc, argv);
- if (result < 0) {
- ovs_abort(result, "Cannot init EAL");
- }
-
- /* Set the main thread affinity back to pre rte_eal_init() value */
- if (auto_determine && !err) {
- err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
- &cpuset);
- if (err) {
- VLOG_ERR("Thread setaffinity error %d", err);
- }
- }
-
- dpdk_argv = argv;
- dpdk_argc = argc;
-
- atexit(deferred_argv_release);
-
- rte_memzone_dump(stdout);
- rte_eal_init_ret = 0;
-
- /* We are called from the main thread here */
- RTE_PER_LCORE(_lcore_id) = NON_PMD_CORE_ID;
-
- ovs_thread_create("dpdk_watchdog", dpdk_watchdog, NULL);
-
- dpdk_vhost_class_init();
-
-#ifdef DPDK_PDUMP
- VLOG_INFO("DPDK pdump packet capture enabled");
- err = rte_pdump_init(ovs_rundir());
- if (err) {
- VLOG_INFO("Error initialising DPDK pdump");
- rte_pdump_uninit();
- } else {
- char *server_socket_path;
-
- server_socket_path = xasprintf("%s/%s", ovs_rundir(),
- "pdump_server_socket");
- fatal_signal_add_file_to_unlink(server_socket_path);
- free(server_socket_path);
- }
-#endif
-
- /* Finally, register the dpdk classes */
- netdev_dpdk_register();
-}
-
-void
-dpdk_init(const struct smap *ovs_other_config)
-{
- static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
-
- if (ovs_other_config && ovsthread_once_start(&once)) {
- dpdk_init__(ovs_other_config);
- ovsthread_once_done(&once);
- }
+ NO_OFFLOAD_API \
}
static const struct netdev_class dpdk_class =
NETDEV_DPDK_CLASS(
"dpdk",
+ netdev_dpdk_class_init,
netdev_dpdk_construct,
netdev_dpdk_destruct,
netdev_dpdk_set_config,
static const struct netdev_class dpdk_ring_class =
NETDEV_DPDK_CLASS(
"dpdkr",
+ netdev_dpdk_class_init,
netdev_dpdk_ring_construct,
netdev_dpdk_destruct,
netdev_dpdk_ring_set_config,
static const struct netdev_class dpdk_vhost_class =
NETDEV_DPDK_CLASS(
"dpdkvhostuser",
+ NULL,
netdev_dpdk_vhost_construct,
netdev_dpdk_vhost_destruct,
NULL,
static const struct netdev_class dpdk_vhost_client_class =
NETDEV_DPDK_CLASS(
"dpdkvhostuserclient",
+ NULL,
netdev_dpdk_vhost_client_construct,
netdev_dpdk_vhost_destruct,
netdev_dpdk_vhost_client_set_config,
void
netdev_dpdk_register(void)
{
- dpdk_common_init();
netdev_register_provider(&dpdk_class);
netdev_register_provider(&dpdk_ring_class);
netdev_register_provider(&dpdk_vhost_class);
netdev_register_provider(&dpdk_vhost_client_class);
}
-
-void
-dpdk_set_lcore_id(unsigned cpu)
-{
- /* NON_PMD_CORE_ID is reserved for use by non pmd threads. */
- ovs_assert(cpu != NON_PMD_CORE_ID);
- RTE_PER_LCORE(_lcore_id) = cpu;
-}
-
-static bool
-dpdk_thread_is_pmd(void)
-{
- return rte_lcore_id() != NON_PMD_CORE_ID;
-}