'dpdk_mutex' protects two independent things: list of dpdk devices
and list of memory pools. Let's spit it in two to avoid global blocking
inside 'netdev_dpdk.*_reconfigure()' as possible.

Signed-off-by: Ilya Maximets <i.maxim...@samsung.com>
---
 lib/netdev-dpdk.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index f7a6f82..be48218 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -177,8 +177,6 @@ enum dpdk_dev_type {
 
 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
@@ -274,11 +272,15 @@ static const struct dpdk_qos_ops *const qos_confs[] = {
     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)
+static struct ovs_mutex dpdk_mp_mutex = OVS_MUTEX_INITIALIZER;
+
+static struct ovs_list dpdk_mp_list OVS_GUARDED_BY(dpdk_mp_mutex)
     = OVS_LIST_INITIALIZER(&dpdk_mp_list);
 
 /* This mutex must be used by non pmd threads when allocating or freeing
@@ -290,7 +292,7 @@ struct dpdk_mp {
     int mtu;
     int socket_id;
     int refcount;
-    struct ovs_list list_node OVS_GUARDED_BY(dpdk_mutex);
+    struct ovs_list list_node OVS_GUARDED_BY(dpdk_mp_mutex);
 };
 
 /* There should be one 'struct dpdk_tx_queue' created for
@@ -464,13 +466,14 @@ ovs_rte_pktmbuf_init(struct rte_mempool *mp,
 }
 
 static struct dpdk_mp *
-dpdk_mp_get(int socket_id, int mtu) OVS_REQUIRES(dpdk_mutex)
+dpdk_mp_get(int socket_id, int mtu)
 {
     struct dpdk_mp *dmp = NULL;
     char mp_name[RTE_MEMPOOL_NAMESIZE];
     unsigned mp_size;
     struct rte_pktmbuf_pool_private mbp_priv;
 
+    ovs_mutex_lock(&dpdk_mp_mutex);
     LIST_FOR_EACH (dmp, list_node, &dpdk_mp_list) {
         if (dmp->socket_id == socket_id && dmp->mtu == mtu) {
             dmp->refcount++;
@@ -523,16 +526,18 @@ fail:
     rte_free(dmp);
     dmp = NULL;
 out:
+    ovs_mutex_unlock(&dpdk_mp_mutex);
     return dmp;
 }
 
 static void
-dpdk_mp_put(struct dpdk_mp *dmp) OVS_REQUIRES(dpdk_mutex)
+dpdk_mp_put(struct dpdk_mp *dmp)
 {
     if (!dmp) {
         return;
     }
 
+    ovs_mutex_lock(&dpdk_mp_mutex);
     ovs_assert(dmp->refcount);
 
     if (!--dmp->refcount) {
@@ -540,6 +545,7 @@ dpdk_mp_put(struct dpdk_mp *dmp) OVS_REQUIRES(dpdk_mutex)
         rte_mempool_free(dmp->mp);
         rte_free(dmp);
     }
+    ovs_mutex_unlock(&dpdk_mp_mutex);
 }
 
 /* Tries to allocate new mempool on requested_socket_id with
@@ -548,18 +554,18 @@ dpdk_mp_put(struct dpdk_mp *dmp) OVS_REQUIRES(dpdk_mutex)
  * 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;
+    int err = 0;
 
     mp = dpdk_mp_get(dev->requested_socket_id, 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;
+        err = ENOMEM;
     } else {
         dpdk_mp_put(dev->dpdk_mp);
         dev->dpdk_mp = mp;
@@ -568,7 +574,7 @@ netdev_dpdk_mempool_configure(struct netdev_dpdk *dev)
         dev->max_packet_len = MTU_TO_FRAME_LEN(dev->mtu);
     }
 
-    return 0;
+    return err;
 }
 
 static void
@@ -699,7 +705,8 @@ dpdk_eth_flow_ctrl_setup(struct netdev_dpdk *dev) 
OVS_REQUIRES(dev->mutex)
 }
 
 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;
@@ -2922,7 +2929,6 @@ netdev_dpdk_reconfigure(struct netdev *netdev)
     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
@@ -2949,9 +2955,7 @@ netdev_dpdk_reconfigure(struct netdev *netdev)
     netdev_change_seq_changed(netdev);
 
 out:
-
     ovs_mutex_unlock(&dev->mutex);
-    ovs_mutex_unlock(&dpdk_mutex);
 
     return err;
 }
@@ -2962,7 +2966,6 @@ netdev_dpdk_vhost_reconfigure(struct netdev *netdev)
     struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
     int err = 0;
 
-    ovs_mutex_lock(&dpdk_mutex);
     ovs_mutex_lock(&dev->mutex);
 
     netdev->n_txq = dev->requested_n_txq;
@@ -2999,10 +3002,8 @@ netdev_dpdk_vhost_reconfigure(struct netdev *netdev)
         char *vhost_id = xstrdup(get_vhost_id(dev));
 
         ovs_mutex_unlock(&dev->mutex);
-        ovs_mutex_unlock(&dpdk_mutex);
         err = dpdk_vhost_driver_unregister(dev, vhost_id);
         free(vhost_id);
-        ovs_mutex_lock(&dpdk_mutex);
         ovs_mutex_lock(&dev->mutex);
         if (err) {
             VLOG_ERR("Unable to remove vhost-user socket %s",
@@ -3026,7 +3027,6 @@ netdev_dpdk_vhost_reconfigure(struct netdev *netdev)
     }
 
     ovs_mutex_unlock(&dev->mutex);
-    ovs_mutex_unlock(&dpdk_mutex);
 
     return 0;
 }
-- 
2.7.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to