net/mlx5: remove shared context lock
authorXueming Li <xuemingl@nvidia.com>
Wed, 28 Oct 2020 09:33:53 +0000 (17:33 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 3 Nov 2020 22:35:05 +0000 (23:35 +0100)
To support multi-thread flow insertion, this patch removes shared data
lock since all resources should support concurrent protection.

Signed-off-by: Xueming Li <xuemingl@nvidia.com>
Signed-off-by: Suanming Mou <suanmingm@nvidia.com>
Acked-by: Matan Azrad <matan@nvidia.com>
doc/guides/nics/mlx5.rst
doc/guides/rel_notes/release_20_11.rst
drivers/net/mlx5/linux/mlx5_os.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_flow_dv.c

index 964e681..da4940c 100644 (file)
@@ -96,6 +96,7 @@ Features
 - Per packet no-inline hint flag to disable packet data copying into Tx descriptors.
 - Hardware LRO.
 - Hairpin.
+- Multiple-thread flow insertion.
 
 Limitations
 -----------
index 416a42c..a0b5337 100644 (file)
@@ -185,6 +185,7 @@ New Features
 
   Updated Mellanox mlx5 driver with new features and improvements, including:
 
+  * Added support for PMD level multiple-thread flow insertion.
   * Added support for matching on fragmented/non-fragmented IPv4/IPv6 packets.
   * Added support for QinQ packets matching.
   * Added support for the new VLAN fields ``has_vlan`` in the Ethernet item
index 8612cab..d4f2194 100644 (file)
@@ -321,7 +321,6 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
                err = errno;
                goto error;
        }
-       pthread_mutex_init(&sh->dv_mutex, NULL);
        sh->tx_domain = domain;
 #ifdef HAVE_MLX5DV_DR_ESWITCH
        if (priv->config.dv_esw_en) {
@@ -435,7 +434,6 @@ mlx5_os_free_shared_dr(struct mlx5_priv *priv)
                mlx5_glue->destroy_flow_action(sh->pop_vlan_action);
                sh->pop_vlan_action = NULL;
        }
-       pthread_mutex_destroy(&sh->dv_mutex);
 #endif /* HAVE_MLX5DV_DR */
        if (sh->default_miss_action)
                mlx5_glue->destroy_flow_action
@@ -1536,6 +1534,8 @@ err_secondary:
        }
        rte_spinlock_init(&priv->shared_act_sl);
        mlx5_flow_counter_mode_config(eth_dev);
+       if (priv->config.dv_flow_en)
+               eth_dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
        return eth_dev;
 error:
        if (priv) {
index be21a9a..9a458cd 100644 (file)
@@ -639,7 +639,6 @@ struct mlx5_dev_ctx_shared {
        /* Packet pacing related structure. */
        struct mlx5_dev_txpp txpp;
        /* Shared DV/DR flow data section. */
-       pthread_mutex_t dv_mutex; /* DV context mutex. */
        uint32_t dv_meta_mask; /* flow META metadata supported mask. */
        uint32_t dv_mark_mask; /* flow MARK metadata supported mask. */
        uint32_t dv_regc0_mask; /* available bits of metatada reg_c[0]. */
index cf48402..01b6e7c 100644 (file)
@@ -276,45 +276,6 @@ mlx5_flow_tunnel_ip_check(const struct rte_flow_item *item __rte_unused,
        }
 }
 
-/**
- * Acquire the synchronizing object to protect multithreaded access
- * to shared dv context. Lock occurs only if context is actually
- * shared, i.e. we have multiport IB device and representors are
- * created.
- *
- * @param[in] dev
- *   Pointer to the rte_eth_dev structure.
- */
-static void
-flow_dv_shared_lock(struct rte_eth_dev *dev)
-{
-       struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_dev_ctx_shared *sh = priv->sh;
-
-       if (sh->refcnt > 1) {
-               int ret;
-
-               ret = pthread_mutex_lock(&sh->dv_mutex);
-               MLX5_ASSERT(!ret);
-               (void)ret;
-       }
-}
-
-static void
-flow_dv_shared_unlock(struct rte_eth_dev *dev)
-{
-       struct mlx5_priv *priv = dev->data->dev_private;
-       struct mlx5_dev_ctx_shared *sh = priv->sh;
-
-       if (sh->refcnt > 1) {
-               int ret;
-
-               ret = pthread_mutex_unlock(&sh->dv_mutex);
-               MLX5_ASSERT(!ret);
-               (void)ret;
-       }
-}
-
 /* Update VLAN's VID/PCP based on input rte_flow_action.
  *
  * @param[in] action
@@ -5075,7 +5036,7 @@ flow_dv_counter_remove_from_age(struct rte_eth_dev *dev,
  *   Index to the counter handler.
  */
 static void
-flow_dv_counter_release(struct rte_eth_dev *dev, uint32_t counter)
+flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t counter)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
        struct mlx5_flow_counter_pool *pool = NULL;
@@ -8624,7 +8585,7 @@ flow_dv_sample_sub_actions_release(struct rte_eth_dev *dev,
                act_res->rix_tag = 0;
        }
        if (act_res->cnt) {
-               flow_dv_counter_release(dev, act_res->cnt);
+               flow_dv_counter_free(dev, act_res->cnt);
                act_res->cnt = 0;
        }
 }
@@ -9298,12 +9259,12 @@ flow_dv_create_action_sample(struct rte_eth_dev *dev,
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-__flow_dv_translate(struct rte_eth_dev *dev,
-                   struct mlx5_flow *dev_flow,
-                   const struct rte_flow_attr *attr,
-                   const struct rte_flow_item items[],
-                   const struct rte_flow_action actions[],
-                   struct rte_flow_error *error)
+flow_dv_translate(struct rte_eth_dev *dev,
+                 struct mlx5_flow *dev_flow,
+                 const struct rte_flow_attr *attr,
+                 const struct rte_flow_item items[],
+                 const struct rte_flow_action actions[],
+                 struct rte_flow_error *error)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
        struct mlx5_dev_config *dev_conf = &priv->config;
@@ -10380,8 +10341,8 @@ __flow_dv_rss_get_hrxq(struct rte_eth_dev *dev, struct rte_flow *flow,
  *   0 on success, a negative errno value otherwise and rte_errno is set.
  */
 static int
-__flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
-               struct rte_flow_error *error)
+flow_dv_apply(struct rte_eth_dev *dev, struct rte_flow *flow,
+             struct rte_flow_error *error)
 {
        struct mlx5_flow_dv_workspace *dv;
        struct mlx5_flow_handle *dh;
@@ -10837,7 +10798,7 @@ flow_dv_dest_array_resource_release(struct rte_eth_dev *dev,
  *   Pointer to flow structure.
  */
 static void
-__flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
+flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
 {
        struct mlx5_flow_handle *dh;
        uint32_t handle_idx;
@@ -10873,7 +10834,7 @@ __flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
  *   Pointer to flow structure.
  */
 static void
-__flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
+flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
 {
        struct rte_flow_shared_action *shared;
        struct mlx5_flow_handle *dev_handle;
@@ -10881,12 +10842,12 @@ __flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
 
        if (!flow)
                return;
-       __flow_dv_remove(dev, flow);
+       flow_dv_remove(dev, flow);
        shared = mlx5_flow_get_shared_rss(flow);
        if (shared)
                __atomic_sub_fetch(&shared->refcnt, 1, __ATOMIC_RELAXED);
        if (flow->counter) {
-               flow_dv_counter_release(dev, flow->counter);
+               flow_dv_counter_free(dev, flow->counter);
                flow->counter = 0;
        }
        if (flow->meter) {
@@ -11169,10 +11130,10 @@ __flow_dv_action_rss_release(struct rte_eth_dev *dev,
  *   rte_errno is set.
  */
 static struct rte_flow_shared_action *
-__flow_dv_action_create(struct rte_eth_dev *dev,
-                       const struct rte_flow_shared_action_conf *conf,
-                       const struct rte_flow_action *action,
-                       struct rte_flow_error *error)
+flow_dv_action_create(struct rte_eth_dev *dev,
+                     const struct rte_flow_shared_action_conf *conf,
+                     const struct rte_flow_action *action,
+                     struct rte_flow_error *error)
 {
        struct rte_flow_shared_action *shared_action = NULL;
        struct mlx5_priv *priv = dev->data->dev_private;
@@ -11216,9 +11177,9 @@ __flow_dv_action_create(struct rte_eth_dev *dev,
  *   0 on success, otherwise negative errno value.
  */
 static int
-__flow_dv_action_destroy(struct rte_eth_dev *dev,
-                        struct rte_flow_shared_action *action,
-                        struct rte_flow_error *error)
+flow_dv_action_destroy(struct rte_eth_dev *dev,
+                      struct rte_flow_shared_action *action,
+                      struct rte_flow_error *error)
 {
        struct mlx5_priv *priv = dev->data->dev_private;
        int ret;
@@ -11338,7 +11299,7 @@ __flow_dv_action_rss_update(struct rte_eth_dev *dev,
  *   0 on success, otherwise negative errno value.
  */
 static int
-__flow_dv_action_update(struct rte_eth_dev *dev,
+flow_dv_action_update(struct rte_eth_dev *dev,
                        struct rte_flow_shared_action *action,
                        const void *action_conf,
                        struct rte_flow_error *error)
@@ -12101,86 +12062,13 @@ flow_get_aged_flows(struct rte_eth_dev *dev,
        return nb_flows;
 }
 
-/*
- * Mutex-protected thunk to lock-free  __flow_dv_translate().
- */
-static int
-flow_dv_translate(struct rte_eth_dev *dev,
-                 struct mlx5_flow *dev_flow,
-                 const struct rte_flow_attr *attr,
-                 const struct rte_flow_item items[],
-                 const struct rte_flow_action actions[],
-                 struct rte_flow_error *error)
-{
-       int ret;
-
-       flow_dv_shared_lock(dev);
-       ret = __flow_dv_translate(dev, dev_flow, attr, items, actions, error);
-       flow_dv_shared_unlock(dev);
-       return ret;
-}
-
-/*
- * Mutex-protected thunk to lock-free  __flow_dv_apply().
- */
-static int
-flow_dv_apply(struct rte_eth_dev *dev,
-             struct rte_flow *flow,
-             struct rte_flow_error *error)
-{
-       int ret;
-
-       flow_dv_shared_lock(dev);
-       ret = __flow_dv_apply(dev, flow, error);
-       flow_dv_shared_unlock(dev);
-       return ret;
-}
-
-/*
- * Mutex-protected thunk to lock-free __flow_dv_remove().
- */
-static void
-flow_dv_remove(struct rte_eth_dev *dev, struct rte_flow *flow)
-{
-       flow_dv_shared_lock(dev);
-       __flow_dv_remove(dev, flow);
-       flow_dv_shared_unlock(dev);
-}
-
-/*
- * Mutex-protected thunk to lock-free __flow_dv_destroy().
- */
-static void
-flow_dv_destroy(struct rte_eth_dev *dev, struct rte_flow *flow)
-{
-       flow_dv_shared_lock(dev);
-       __flow_dv_destroy(dev, flow);
-       flow_dv_shared_unlock(dev);
-}
-
 /*
  * Mutex-protected thunk to lock-free flow_dv_counter_alloc().
  */
 static uint32_t
 flow_dv_counter_allocate(struct rte_eth_dev *dev)
 {
-       uint32_t cnt;
-
-       flow_dv_shared_lock(dev);
-       cnt = flow_dv_counter_alloc(dev, 0);
-       flow_dv_shared_unlock(dev);
-       return cnt;
-}
-
-/*
- * Mutex-protected thunk to lock-free flow_dv_counter_release().
- */
-static void
-flow_dv_counter_free(struct rte_eth_dev *dev, uint32_t cnt)
-{
-       flow_dv_shared_lock(dev);
-       flow_dv_counter_release(dev, cnt);
-       flow_dv_shared_unlock(dev);
+       return flow_dv_counter_alloc(dev, 0);
 }
 
 /**
@@ -12218,57 +12106,6 @@ flow_dv_action_validate(struct rte_eth_dev *dev,
        }
 }
 
-/*
- * Mutex-protected thunk to lock-free  __flow_dv_action_create().
- */
-static struct rte_flow_shared_action *
-flow_dv_action_create(struct rte_eth_dev *dev,
-                     const struct rte_flow_shared_action_conf *conf,
-                     const struct rte_flow_action *action,
-                     struct rte_flow_error *error)
-{
-       struct rte_flow_shared_action *shared_action = NULL;
-
-       flow_dv_shared_lock(dev);
-       shared_action = __flow_dv_action_create(dev, conf, action, error);
-       flow_dv_shared_unlock(dev);
-       return shared_action;
-}
-
-/*
- * Mutex-protected thunk to lock-free  __flow_dv_action_destroy().
- */
-static int
-flow_dv_action_destroy(struct rte_eth_dev *dev,
-                      struct rte_flow_shared_action *action,
-                      struct rte_flow_error *error)
-{
-       int ret;
-
-       flow_dv_shared_lock(dev);
-       ret = __flow_dv_action_destroy(dev, action, error);
-       flow_dv_shared_unlock(dev);
-       return ret;
-}
-
-/*
- * Mutex-protected thunk to lock-free  __flow_dv_action_update().
- */
-static int
-flow_dv_action_update(struct rte_eth_dev *dev,
-                     struct rte_flow_shared_action *action,
-                     const void *action_conf,
-                     struct rte_flow_error *error)
-{
-       int ret;
-
-       flow_dv_shared_lock(dev);
-       ret = __flow_dv_action_update(dev, action, action_conf,
-                                     error);
-       flow_dv_shared_unlock(dev);
-       return ret;
-}
-
 static int
 flow_dv_sync_domain(struct rte_eth_dev *dev, uint32_t domains, uint32_t flags)
 {