From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 09449A0588; Thu, 16 Apr 2020 04:43:28 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 59C041DA10; Thu, 16 Apr 2020 04:42:33 +0200 (CEST) Received: from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130]) by dpdk.org (Postfix) with ESMTP id 5ABF71D9DA for ; Thu, 16 Apr 2020 04:42:27 +0200 (CEST) From: Suanming Mou To: viacheslavo@mellanox.com, matan@mellanox.com Cc: rasland@mellanox.com, dev@dpdk.org Date: Thu, 16 Apr 2020 10:42:05 +0800 Message-Id: <1587004928-328077-8-git-send-email-suanmingm@mellanox.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1587004928-328077-1-git-send-email-suanmingm@mellanox.com> References: <1586740309-449310-1-git-send-email-suanmingm@mellanox.com> <1587004928-328077-1-git-send-email-suanmingm@mellanox.com> Subject: [dpdk-dev] [PATCH v2 07/10] net/mlx5: convert port id action to indexed X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This commit converts port id action to indexed. Using the uint32_t index instead of pointer saves 4 bytes memory for the flow handle. For millions flows, it will save several MBytes of memory. Signed-off-by: Suanming Mou Acked-by: Viacheslav Ovsiienko --- drivers/net/mlx5/mlx5.c | 11 +++++++++++ drivers/net/mlx5/mlx5.h | 4 ++-- drivers/net/mlx5/mlx5_flow.h | 6 ++++-- drivers/net/mlx5/mlx5_flow_dv.c | 43 +++++++++++++++++++++++++++++------------ 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index e18e801..e02361c 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -232,6 +232,17 @@ struct mlx5_dev_spawn_data { .free = rte_free, .type = "mlx5_tag_ipool", }, + { + .size = sizeof(struct mlx5_flow_dv_port_id_action_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_port_id_ipool", + }, }; diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h index 59ba9e2..9227d67 100644 --- a/drivers/net/mlx5/mlx5.h +++ b/drivers/net/mlx5/mlx5.h @@ -48,6 +48,7 @@ enum mlx5_ipool_index { MLX5_IPOOL_DECAP_ENCAP = 0, /* Pool for encap/decap resource. */ MLX5_IPOOL_PUSH_VLAN, /* Pool for push vlan resource. */ MLX5_IPOOL_TAG, /* Pool for tag resource. */ + MLX5_IPOOL_PORT_ID, /* Pool for port id resource. */ MLX5_IPOOL_MAX, }; @@ -434,8 +435,7 @@ struct mlx5_ibv_shared { uint32_t encaps_decaps; /* Encap/decap action indexed memory list. */ LIST_HEAD(modify_cmd, mlx5_flow_dv_modify_hdr_resource) modify_cmds; struct mlx5_hlist *tag_table; - LIST_HEAD(port_id_action_list, mlx5_flow_dv_port_id_action_resource) - port_id_action_list; /* List of port ID actions. */ + uint32_t port_id_action_list; /* List of port ID actions. */ uint32_t push_vlan_action_list; /* List of push VLAN actions. */ struct mlx5_flow_counter_mng cmng; /* Counters management structure. */ struct mlx5_indexed_pool *ipool[MLX5_IPOOL_MAX]; diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h index 8f9f5e6..da86272 100644 --- a/drivers/net/mlx5/mlx5_flow.h +++ b/drivers/net/mlx5/mlx5_flow.h @@ -420,7 +420,7 @@ struct mlx5_flow_dv_jump_tbl_resource { /* Port ID resource structure. */ struct mlx5_flow_dv_port_id_action_resource { - LIST_ENTRY(mlx5_flow_dv_port_id_action_resource) next; + ILIST_ENTRY(uint32_t)next; /* Pointer to next element. */ rte_atomic32_t refcnt; /**< Reference counter. */ void *action; @@ -489,7 +489,7 @@ struct mlx5_flow_handle_dv { /**< Pointer to modify header resource in cache. */ struct mlx5_flow_dv_jump_tbl_resource *jump; /**< Pointer to the jump action resource. */ - struct mlx5_flow_dv_port_id_action_resource *port_id_action; + uint32_t port_id_action; /**< Pointer to port ID action resource. */ struct mlx5_vf_vlan vf_vlan; /**< Structure for VF VLAN workaround. */ @@ -549,6 +549,8 @@ struct mlx5_flow_dv_workspace { struct mlx5_flow_dv_push_vlan_action_resource *push_vlan_res; /**< Pointer to push VLAN action resource in cache. */ struct mlx5_flow_dv_tag_resource *tag_resource; + struct mlx5_flow_dv_port_id_action_resource *port_id_action; + /**< Pointer to port ID action resource. */ /**< pointer to the tag action. */ struct mlx5_flow_dv_match_params value; /**< Holds the value that the packet is compared to. */ diff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c index 5aa624d..43cace4 100644 --- a/drivers/net/mlx5/mlx5_flow_dv.c +++ b/drivers/net/mlx5/mlx5_flow_dv.c @@ -2601,21 +2601,25 @@ struct field_modify_info modify_tcp[] = { struct mlx5_priv *priv = dev->data->dev_private; struct mlx5_ibv_shared *sh = priv->sh; struct mlx5_flow_dv_port_id_action_resource *cache_resource; + uint32_t idx = 0; /* Lookup a matching resource from cache. */ - LIST_FOREACH(cache_resource, &sh->port_id_action_list, next) { + ILIST_FOREACH(sh->ipool[MLX5_IPOOL_PORT_ID], sh->port_id_action_list, + idx, cache_resource, next) { if (resource->port_id == cache_resource->port_id) { DRV_LOG(DEBUG, "port id action resource resource %p: " "refcnt %d++", (void *)cache_resource, rte_atomic32_read(&cache_resource->refcnt)); rte_atomic32_inc(&cache_resource->refcnt); - dev_flow->handle->dvh.port_id_action = cache_resource; + dev_flow->handle->dvh.port_id_action = idx; + dev_flow->dv.port_id_action = cache_resource; return 0; } } /* Register new port id action resource. */ - cache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0); + cache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_PORT_ID], + &dev_flow->handle->dvh.port_id_action); if (!cache_resource) return rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, @@ -2637,8 +2641,10 @@ struct field_modify_info modify_tcp[] = { } rte_atomic32_init(&cache_resource->refcnt); rte_atomic32_inc(&cache_resource->refcnt); - LIST_INSERT_HEAD(&sh->port_id_action_list, cache_resource, next); - dev_flow->handle->dvh.port_id_action = cache_resource; + ILIST_INSERT(sh->ipool[MLX5_IPOOL_PORT_ID], &sh->port_id_action_list, + dev_flow->handle->dvh.port_id_action, cache_resource, + next); + dev_flow->dv.port_id_action = cache_resource; DRV_LOG(DEBUG, "new port id action resource %p: refcnt %d++", (void *)cache_resource, rte_atomic32_read(&cache_resource->refcnt)); @@ -7425,12 +7431,14 @@ struct field_modify_info modify_tcp[] = { if (flow_dv_translate_action_port_id(dev, action, &port_id, error)) return -rte_errno; + memset(&port_id_resource, 0, sizeof(port_id_resource)); port_id_resource.port_id = port_id; if (flow_dv_port_id_action_resource_register (dev, &port_id_resource, dev_flow, error)) return -rte_errno; + MLX5_ASSERT(!handle->dvh.port_id_action); dev_flow->dv.actions[actions_n++] = - handle->dvh.port_id_action->action; + dev_flow->dv.port_id_action->action; action_flags |= MLX5_FLOW_ACTION_PORT_ID; break; case RTE_FLOW_ACTION_TYPE_FLAG: @@ -8318,6 +8326,8 @@ struct field_modify_info modify_tcp[] = { /** * Release port ID action resource. * + * @param dev + * Pointer to Ethernet device. * @param handle * Pointer to mlx5_flow_handle. * @@ -8325,11 +8335,17 @@ struct field_modify_info modify_tcp[] = { * 1 while a reference on it exists, 0 when freed. */ static int -flow_dv_port_id_action_resource_release(struct mlx5_flow_handle *handle) +flow_dv_port_id_action_resource_release(struct rte_eth_dev *dev, + struct mlx5_flow_handle *handle) { - struct mlx5_flow_dv_port_id_action_resource *cache_resource = - handle->dvh.port_id_action; + struct mlx5_priv *priv = dev->data->dev_private; + struct mlx5_flow_dv_port_id_action_resource *cache_resource; + uint32_t idx = handle->dvh.port_id_action; + cache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_PORT_ID], + idx); + if (!cache_resource) + return 0; MLX5_ASSERT(cache_resource->action); DRV_LOG(DEBUG, "port ID action resource %p: refcnt %d--", (void *)cache_resource, @@ -8337,8 +8353,10 @@ struct field_modify_info modify_tcp[] = { if (rte_atomic32_dec_and_test(&cache_resource->refcnt)) { claim_zero(mlx5_glue->destroy_flow_action (cache_resource->action)); - LIST_REMOVE(cache_resource, next); - rte_free(cache_resource); + ILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_PORT_ID], + &priv->sh->port_id_action_list, idx, + cache_resource, next); + mlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_PORT_ID], idx); DRV_LOG(DEBUG, "port id action resource %p: removed", (void *)cache_resource); return 0; @@ -8457,7 +8475,8 @@ struct field_modify_info modify_tcp[] = { if (dev_handle->dvh.jump) flow_dv_jump_tbl_resource_release(dev, dev_handle); if (dev_handle->dvh.port_id_action) - flow_dv_port_id_action_resource_release(dev_handle); + flow_dv_port_id_action_resource_release(dev, + dev_handle); if (dev_handle->dvh.push_vlan_res) flow_dv_push_vlan_action_resource_release(dev, dev_handle); -- 1.8.3.1