[ovs-dev] [dpdk patch 6/8] netdev-dpdk: Add function for configuring rx queues for all dpdk interfaces.

Alex Wang alexw at nicira.com
Tue Aug 12 04:56:41 UTC 2014


Later patch will use this function to configure rx queues.

Signed-off-by: Alex Wang <alexw at nicira.com>
---
 lib/netdev-dpdk.c |   42 +++++++++++++++++++++++++++++++++++++++++-
 lib/netdev-dpdk.h |    7 +++++++
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 012ee68..3013df5 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -130,6 +130,8 @@ enum { DRAIN_TSC = 200000ULL };
 
 static int rte_eal_init_ret = ENODEV;
 
+static size_t dpdk_rx_queues OVS_GUARDED_BY(dpdk_mutex);
+
 static struct ovs_mutex dpdk_mutex = OVS_MUTEX_INITIALIZER;
 
 /* Contains all 'struct dpdk_dev's. */
@@ -491,7 +493,8 @@ netdev_dpdk_init(struct netdev *netdev_, unsigned int port_no) OVS_REQUIRES(dpdk
 
     ovs_mutex_lock(&netdev->mutex);
 
-    netdev->n_rx_q = dpdk_get_n_devs(netdev->socket_id);
+    netdev->n_rx_q = dpdk_rx_queues ? dpdk_rx_queues
+                         : dpdk_get_n_devs(netdev->socket_id);
 
     /* There can only be ovs_numa_get_n_cores() pmd threads, so creates a tx_q
      * for each of them. */
@@ -1514,6 +1517,43 @@ netdev_dpdk_flush_non_local(struct netdev *netdev_, int qid)
     dpdk_queue_flush(dev, qid);
 }
 
+/* Sets the number of rx queues for each dpdk interface.  If the
+ * configuration fails on one interface, do not try restoring its
+ * old configuration and just returns the error.
+ * Caller should make decision on the error case.  One option is to
+ * call the function again with smaller n_queues or 0 (default). */
+int
+netdev_dpdk_set_rx_queues(int n_queues)
+{
+    struct netdev_dpdk *dev;
+    int err = 0;
+
+    ovs_mutex_lock(&dpdk_mutex);
+
+    if (dpdk_rx_queues == n_queues) {
+        goto out;
+    }
+
+    LIST_FOR_EACH (dev, list_node, &dpdk_list) {
+        ovs_mutex_lock(&dev->mutex);
+        rte_eth_dev_stop(dev->port_id);
+        dev->n_rx_q = n_queues ? n_queues
+                               : dpdk_get_n_devs(dev->socket_id);
+        err = dpdk_eth_dev_init(dev);
+        if (err) {
+            ovs_mutex_unlock(&dev->mutex);
+            goto out;
+        }
+        dev->up.n_rxq = n_queues;
+        ovs_mutex_unlock(&dev->mutex);
+    }
+    dpdk_rx_queues = n_queues;
+out:
+    ovs_mutex_unlock(&dpdk_mutex);
+
+    return err;
+}
+
 int
 pmd_thread_setaffinity_cpu(int cpu)
 {
diff --git a/lib/netdev-dpdk.h b/lib/netdev-dpdk.h
index 5e8f296..38f916c 100644
--- a/lib/netdev-dpdk.h
+++ b/lib/netdev-dpdk.h
@@ -26,6 +26,7 @@ void netdev_dpdk_register(void);
 int netdev_dpdk_get_socket_id(const struct netdev *);
 int netdev_dpdk_get_n_devs_on_socket(int socket_id);
 void netdev_dpdk_flush_non_local(struct netdev *, int qid);
+int netdev_dpdk_set_rx_queues(int n_queues);
 void free_dpdk_buf(struct dpif_packet *);
 int pmd_thread_setaffinity_cpu(int cpu);
 void thread_set_nonpmd(void);
@@ -56,6 +57,12 @@ netdev_dpdk_get_n_devs_on_socket(int socket_id OVS_UNUSED)
     return -1;
 }
 
+static inline int
+netdev_dpdk_set_rx_queues(int n_queues OVS_UNUSED)
+{
+    return -1;
+}
+
 static inline void
 netdev_dpdk_flush_non_local(struct netdev *netdev OVS_UNUSED,
                             int qid OVS_UNUSED)
-- 
1.7.9.5




More information about the dev mailing list