net/mlx5: convert mark copy resource to indexed
authorSuanming Mou <suanmingm@mellanox.com>
Thu, 16 Apr 2020 08:34:27 +0000 (16:34 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 21 Apr 2020 11:57:09 +0000 (13:57 +0200)
Allocate mark copy resource from indexed pool helps rte flow saves the 4
bytes index instead of 8 bytes pointer. For mark copy resource itself,
it helps save MALLOC_ELEM_OVERHEAD bytes from rte_malloc().

Signed-off-by: Suanming Mou <suanmingm@mellanox.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>
drivers/net/mlx5/mlx5.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_flow.c
drivers/net/mlx5/mlx5_flow.h

index 0e79c79..2e1cf11 100644 (file)
@@ -267,6 +267,17 @@ static struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {
                .free = rte_free,
                .type = "mlx5_meter_ipool",
        },
+       {
+               .size = sizeof(struct mlx5_flow_mreg_copy_resource),
+               .trunk_size = 64,
+               .grow_trunk = 3,
+               .grow_shift = 2,
+               .need_lock = 0,
+               .release_mem_en = 1,
+               .malloc = rte_malloc_socket,
+               .free = rte_free,
+               .type = "mlx5_mcp_ipool",
+       },
        {
                .size = (sizeof(struct mlx5_hrxq) + MLX5_RSS_HASH_KEY_LEN),
                .trunk_size = 64,
index 9d5105e..db376da 100644 (file)
@@ -53,6 +53,7 @@ enum mlx5_ipool_index {
        MLX5_IPOOL_JUMP, /* Pool for jump resource. */
 #endif
        MLX5_IPOOL_MTR, /* Pool for meter resource. */
+       MLX5_IPOOL_MCP, /* Pool for metadata resource. */
        MLX5_IPOOL_HRXQ, /* Pool for hrxq resource. */
        MLX5_IPOOL_MLX5_FLOW, /* Pool for mlx5 flow handle. */
        MLX5_IPOOL_MAX,
index 4205f23..eaf3d8d 100644 (file)
@@ -2962,6 +2962,7 @@ flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
                [3] = { .type = RTE_FLOW_ACTION_TYPE_END, },
        };
        struct mlx5_flow_mreg_copy_resource *mcp_res;
+       uint32_t idx = 0;
        int ret;
 
        /* Fill the register fileds in the flow. */
@@ -3030,11 +3031,12 @@ flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
                };
        }
        /* Build a new entry. */
-       mcp_res = rte_zmalloc(__func__, sizeof(*mcp_res), 0);
+       mcp_res = mlx5_ipool_zmalloc(priv->sh->ipool[MLX5_IPOOL_MCP], &idx);
        if (!mcp_res) {
                rte_errno = ENOMEM;
                return NULL;
        }
+       mcp_res->idx = idx;
        /*
         * The copy Flows are not included in any list. There
         * ones are referenced from other Flows and can not
@@ -3056,7 +3058,7 @@ flow_mreg_add_copy_action(struct rte_eth_dev *dev, uint32_t mark_id,
 error:
        if (mcp_res->flow)
                flow_list_destroy(dev, NULL, mcp_res->flow);
-       rte_free(mcp_res);
+       mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
        return NULL;
 }
 
@@ -3072,9 +3074,13 @@ static void
 flow_mreg_del_copy_action(struct rte_eth_dev *dev,
                          struct rte_flow *flow)
 {
-       struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
+       struct mlx5_flow_mreg_copy_resource *mcp_res;
        struct mlx5_priv *priv = dev->data->dev_private;
 
+       if (!flow->rix_mreg_copy)
+               return;
+       mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
+                                flow->rix_mreg_copy);
        if (!mcp_res || !priv->mreg_cp_tbl)
                return;
        if (flow->copy_applied) {
@@ -3093,8 +3099,8 @@ flow_mreg_del_copy_action(struct rte_eth_dev *dev,
        MLX5_ASSERT(mcp_res->flow);
        flow_list_destroy(dev, NULL, mcp_res->flow);
        mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
-       rte_free(mcp_res);
-       flow->mreg_copy = NULL;
+       mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
+       flow->rix_mreg_copy = 0;
 }
 
 /**
@@ -3112,10 +3118,15 @@ static int
 flow_mreg_start_copy_action(struct rte_eth_dev *dev,
                            struct rte_flow *flow)
 {
-       struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
+       struct mlx5_flow_mreg_copy_resource *mcp_res;
+       struct mlx5_priv *priv = dev->data->dev_private;
        int ret;
 
-       if (!mcp_res || flow->copy_applied)
+       if (!flow->rix_mreg_copy || flow->copy_applied)
+               return 0;
+       mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
+                                flow->rix_mreg_copy);
+       if (!mcp_res)
                return 0;
        if (!mcp_res->appcnt) {
                ret = flow_drv_apply(dev, mcp_res->flow, NULL);
@@ -3139,9 +3150,14 @@ static void
 flow_mreg_stop_copy_action(struct rte_eth_dev *dev,
                           struct rte_flow *flow)
 {
-       struct mlx5_flow_mreg_copy_resource *mcp_res = flow->mreg_copy;
+       struct mlx5_flow_mreg_copy_resource *mcp_res;
+       struct mlx5_priv *priv = dev->data->dev_private;
 
-       if (!mcp_res || !flow->copy_applied)
+       if (!flow->rix_mreg_copy || !flow->copy_applied)
+               return;
+       mcp_res = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_MCP],
+                                flow->rix_mreg_copy);
+       if (!mcp_res)
                return;
        MLX5_ASSERT(mcp_res->appcnt);
        --mcp_res->appcnt;
@@ -3172,7 +3188,7 @@ flow_mreg_del_default_copy_action(struct rte_eth_dev *dev)
        MLX5_ASSERT(mcp_res->flow);
        flow_list_destroy(dev, NULL, mcp_res->flow);
        mlx5_hlist_remove(priv->mreg_cp_tbl, &mcp_res->hlist_ent);
-       rte_free(mcp_res);
+       mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_MCP], mcp_res->idx);
 }
 
 /**
@@ -3264,7 +3280,7 @@ flow_mreg_update_copy_table(struct rte_eth_dev *dev,
                                (dev, MLX5_FLOW_MARK_DEFAULT, error);
                        if (!mcp_res)
                                return -rte_errno;
-                       flow->mreg_copy = mcp_res;
+                       flow->rix_mreg_copy = mcp_res->idx;
                        if (dev->data->dev_started) {
                                mcp_res->appcnt++;
                                flow->copy_applied = 1;
@@ -3277,7 +3293,7 @@ flow_mreg_update_copy_table(struct rte_eth_dev *dev,
                                flow_mreg_add_copy_action(dev, mark->id, error);
                        if (!mcp_res)
                                return -rte_errno;
-                       flow->mreg_copy = mcp_res;
+                       flow->rix_mreg_copy = mcp_res->idx;
                        if (dev->data->dev_started) {
                                mcp_res->appcnt++;
                                flow->copy_applied = 1;
index b508299..c9b357d 100644 (file)
@@ -460,6 +460,7 @@ struct mlx5_flow_mreg_copy_resource {
        /* List entry for device flows. */
        uint32_t refcnt; /* Reference counter. */
        uint32_t appcnt; /* Apply/Remove counter. */
+       uint32_t idx;
        struct rte_flow *flow; /* Built flow for copy. */
 };
 
@@ -756,8 +757,8 @@ struct rte_flow {
        enum mlx5_flow_drv_type drv_type; /**< Driver type. */
        struct mlx5_flow_rss rss; /**< RSS context. */
        uint32_t counter; /**< Holds flow counter. */
-       struct mlx5_flow_mreg_copy_resource *mreg_copy;
-       /**< pointer to metadata register copy table resource. */
+       uint32_t rix_mreg_copy;
+       /**< Index to metadata register copy table resource. */
        uint16_t meter; /**< Holds flow meter id. */
        uint32_t dev_handles;
        /**< Device flow handles that are part of the flow. */