get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/68230/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 68230,
    "url": "http://patchwork.dpdk.org/api/patches/68230/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/1586740309-449310-5-git-send-email-suanmingm@mellanox.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<1586740309-449310-5-git-send-email-suanmingm@mellanox.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1586740309-449310-5-git-send-email-suanmingm@mellanox.com",
    "date": "2020-04-13T01:11:43",
    "name": "[04/10] net/mlx5: convert encap/decap resource to indexed",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "7d6e99d91d4538adf128e9a82387601dda4b5a76",
    "submitter": {
        "id": 1358,
        "url": "http://patchwork.dpdk.org/api/people/1358/?format=api",
        "name": "Suanming Mou",
        "email": "suanmingm@mellanox.com"
    },
    "delegate": {
        "id": 3268,
        "url": "http://patchwork.dpdk.org/api/users/3268/?format=api",
        "username": "rasland",
        "first_name": "Raslan",
        "last_name": "Darawsheh",
        "email": "rasland@nvidia.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/1586740309-449310-5-git-send-email-suanmingm@mellanox.com/mbox/",
    "series": [
        {
            "id": 9321,
            "url": "http://patchwork.dpdk.org/api/series/9321/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=9321",
            "date": "2020-04-13T01:11:39",
            "name": "net/mlx5: optimize flow resource allocation",
            "version": 1,
            "mbox": "http://patchwork.dpdk.org/series/9321/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/68230/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/68230/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 2FDC2A0577;\n\tMon, 13 Apr 2020 03:12:37 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id AB7D71BE9D;\n\tMon, 13 Apr 2020 03:12:05 +0200 (CEST)",
            "from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130])\n by dpdk.org (Postfix) with ESMTP id 713A52BFA\n for <dev@dpdk.org>; Mon, 13 Apr 2020 03:12:03 +0200 (CEST)"
        ],
        "From": "Suanming Mou <suanmingm@mellanox.com>",
        "To": "Matan Azrad <matan@mellanox.com>, Shahaf Shuler <shahafs@mellanox.com>,\n Viacheslav Ovsiienko <viacheslavo@mellanox.com>",
        "Cc": "rasland@mellanox.com,\n\tdev@dpdk.org",
        "Date": "Mon, 13 Apr 2020 09:11:43 +0800",
        "Message-Id": "<1586740309-449310-5-git-send-email-suanmingm@mellanox.com>",
        "X-Mailer": "git-send-email 1.8.3.1",
        "In-Reply-To": "<1586740309-449310-1-git-send-email-suanmingm@mellanox.com>",
        "References": "<1586740309-449310-1-git-send-email-suanmingm@mellanox.com>",
        "Subject": "[dpdk-dev] [PATCH 04/10] net/mlx5: convert encap/decap resource to\n\tindexed",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.15",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>"
    },
    "content": "This commit converts the flow encap/decap resource to indexed.\n\nUsing the uint32_t index instead of pointer saves 4 bytes memory for the\nflow handle. For millions flows, it will save several MBytes of memory.\n\nSigned-off-by: Suanming Mou <suanmingm@mellanox.com>\nAcked-by: Viacheslav Ovsiienko <viacheslavo@mellanox.com>\n---\n drivers/net/mlx5/mlx5.c         | 47 ++++++++++++++++++++++++++++++++++++++++\n drivers/net/mlx5/mlx5.h         |  9 +++++++-\n drivers/net/mlx5/mlx5_flow.h    |  8 ++++---\n drivers/net/mlx5/mlx5_flow_dv.c | 48 +++++++++++++++++++++++++++--------------\n 4 files changed, 92 insertions(+), 20 deletions(-)",
    "diff": "diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c\nindex 6a11b14..f4c2c14 100644\n--- a/drivers/net/mlx5/mlx5.c\n+++ b/drivers/net/mlx5/mlx5.c\n@@ -194,6 +194,21 @@ struct mlx5_dev_spawn_data {\n static LIST_HEAD(, mlx5_ibv_shared) mlx5_ibv_list = LIST_HEAD_INITIALIZER();\n static pthread_mutex_t mlx5_ibv_list_mutex = PTHREAD_MUTEX_INITIALIZER;\n \n+static struct mlx5_indexed_pool_config mlx5_ipool_cfg[] = {\n+\t{\n+\t\t.size = sizeof(struct mlx5_flow_dv_encap_decap_resource),\n+\t\t.trunk_size = 64,\n+\t\t.grow_trunk = 3,\n+\t\t.grow_shift = 2,\n+\t\t.need_lock = 0,\n+\t\t.release_mem_en = 1,\n+\t\t.malloc = rte_malloc_socket,\n+\t\t.free = rte_free,\n+\t\t.type = \"mlx5_encap_decap_ipool\",\n+\t},\n+};\n+\n+\n #define MLX5_FLOW_MIN_ID_POOL_SIZE 512\n #define MLX5_ID_GENERATION_ARRAY_FACTOR 16\n \n@@ -411,6 +426,36 @@ struct mlx5_flow_id_pool *\n }\n \n /**\n+ * Initialize the flow resources' indexed mempool.\n+ *\n+ * @param[in] sh\n+ *   Pointer to mlx5_ibv_shared object.\n+ */\n+static void\n+mlx5_flow_ipool_create(struct mlx5_ibv_shared *sh)\n+{\n+\tuint8_t i;\n+\n+\tfor (i = 0; i < MLX5_IPOOL_MAX; ++i)\n+\t\tsh->ipool[i] = mlx5_ipool_create(&mlx5_ipool_cfg[i]);\n+}\n+\n+/**\n+ * Release the flow resources' indexed mempool.\n+ *\n+ * @param[in] sh\n+ *   Pointer to mlx5_ibv_shared object.\n+ */\n+static void\n+mlx5_flow_ipool_destroy(struct mlx5_ibv_shared *sh)\n+{\n+\tuint8_t i;\n+\n+\tfor (i = 0; i < MLX5_IPOOL_MAX; ++i)\n+\t\tmlx5_ipool_destroy(sh->ipool[i]);\n+}\n+\n+/**\n  * Extract pdn of PD object using DV API.\n  *\n  * @param[in] pd\n@@ -625,6 +670,7 @@ struct mlx5_flow_id_pool *\n \t\tgoto error;\n \t}\n \tmlx5_flow_counters_mng_init(sh);\n+\tmlx5_flow_ipool_create(sh);\n \t/* Add device to memory callback list. */\n \trte_rwlock_write_lock(&mlx5_shared_data->mem_event_rwlock);\n \tLIST_INSERT_HEAD(&mlx5_shared_data->mem_event_cb_list,\n@@ -697,6 +743,7 @@ struct mlx5_flow_id_pool *\n \t *  Only primary process handles async device events.\n \t **/\n \tmlx5_flow_counters_mng_close(sh);\n+\tmlx5_flow_ipool_destroy(sh);\n \tMLX5_ASSERT(!sh->intr_cnt);\n \tif (sh->intr_cnt)\n \t\tmlx5_intr_callback_unregister\ndiff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h\nindex 34ab475..a1a7294 100644\n--- a/drivers/net/mlx5/mlx5.h\n+++ b/drivers/net/mlx5/mlx5.h\n@@ -51,6 +51,11 @@ enum mlx5_mp_req_type {\n \tMLX5_MP_REQ_QUEUE_STATE_MODIFY,\n };\n \n+enum mlx5_ipool_index {\n+\tMLX5_IPOOL_DECAP_ENCAP = 0, /* Pool for encap/decap resource. */\n+\tMLX5_IPOOL_MAX,\n+};\n+\n struct mlx5_mp_arg_queue_state_modify {\n \tuint8_t is_wq; /* Set if WQ. */\n \tuint16_t queue_id; /* DPDK queue ID. */\n@@ -446,7 +451,7 @@ struct mlx5_ibv_shared {\n \t/* Direct Rules tables for FDB, NIC TX+RX */\n \tvoid *esw_drop_action; /* Pointer to DR E-Switch drop action. */\n \tvoid *pop_vlan_action; /* Pointer to DR pop VLAN action. */\n-\tLIST_HEAD(encap_decap, mlx5_flow_dv_encap_decap_resource) encaps_decaps;\n+\tuint32_t encaps_decaps; /* Encap/decap action indexed memory list. */\n \tLIST_HEAD(modify_cmd, mlx5_flow_dv_modify_hdr_resource) modify_cmds;\n \tstruct mlx5_hlist *tag_table;\n \tLIST_HEAD(port_id_action_list, mlx5_flow_dv_port_id_action_resource)\n@@ -454,6 +459,8 @@ struct mlx5_ibv_shared {\n \tLIST_HEAD(push_vlan_action_list, mlx5_flow_dv_push_vlan_action_resource)\n \t\tpush_vlan_action_list; /* List of push VLAN actions. */\n \tstruct mlx5_flow_counter_mng cmng; /* Counters management structure. */\n+\tstruct mlx5_indexed_pool *ipool[MLX5_IPOOL_MAX];\n+\t/* Memory Pool for mlx5 flow resources. */\n \t/* Shared interrupt handler section. */\n \tpthread_mutex_t intr_mutex; /* Interrupt config mutex. */\n \tuint32_t intr_cnt; /* Interrupt handler reference counter. */\ndiff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h\nindex 0f0e59d..77d6b2d 100644\n--- a/drivers/net/mlx5/mlx5_flow.h\n+++ b/drivers/net/mlx5/mlx5_flow.h\n@@ -364,7 +364,7 @@ struct mlx5_flow_dv_matcher {\n \n /* Encap/decap resource structure. */\n struct mlx5_flow_dv_encap_decap_resource {\n-\tLIST_ENTRY(mlx5_flow_dv_encap_decap_resource) next;\n+\tILIST_ENTRY(uint32_t)next;\n \t/* Pointer to next element. */\n \trte_atomic32_t refcnt; /**< Reference counter. */\n \tvoid *verbs_action;\n@@ -482,8 +482,8 @@ struct mlx5_flow_rss {\n struct mlx5_flow_handle_dv {\n \t/* Flow DV api: */\n \tstruct mlx5_flow_dv_matcher *matcher; /**< Cache to matcher. */\n-\tstruct mlx5_flow_dv_encap_decap_resource *encap_decap;\n-\t/**< Pointer to encap/decap resource in cache. */\n+\tuint32_t encap_decap;\n+\t/**< Index to encap/decap resource in cache. */\n \tstruct mlx5_flow_dv_modify_hdr_resource *modify_hdr;\n \t/**< Pointer to modify header resource in cache. */\n \tstruct mlx5_flow_dv_jump_tbl_resource *jump;\n@@ -543,6 +543,8 @@ struct mlx5_flow_dv_workspace {\n \tuint8_t transfer; /**< 1 if the flow is E-Switch flow. */\n \tint actions_n; /**< number of actions. */\n \tvoid *actions[MLX5_DV_MAX_NUMBER_OF_ACTIONS]; /**< Action list. */\n+\tstruct mlx5_flow_dv_encap_decap_resource *encap_decap;\n+\t/**< Pointer to encap/decap resource in cache. */\n \tstruct mlx5_flow_dv_match_params value;\n \t/**< Holds the value that the packet is compared to. */\n };\ndiff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c\nindex f5d98d2..8275098 100644\n--- a/drivers/net/mlx5/mlx5_flow_dv.c\n+++ b/drivers/net/mlx5/mlx5_flow_dv.c\n@@ -2437,6 +2437,7 @@ struct field_modify_info modify_tcp[] = {\n \tstruct mlx5_ibv_shared *sh = priv->sh;\n \tstruct mlx5_flow_dv_encap_decap_resource *cache_resource;\n \tstruct mlx5dv_dr_domain *domain;\n+\tuint32_t idx = 0;\n \n \tresource->flags = dev_flow->dv.group ? 0 : 1;\n \tif (resource->ft_type == MLX5DV_FLOW_TABLE_TYPE_FDB)\n@@ -2446,7 +2447,8 @@ struct field_modify_info modify_tcp[] = {\n \telse\n \t\tdomain = sh->tx_domain;\n \t/* Lookup a matching resource from cache. */\n-\tLIST_FOREACH(cache_resource, &sh->encaps_decaps, next) {\n+\tILIST_FOREACH(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], sh->encaps_decaps, idx,\n+\t\t      cache_resource, next) {\n \t\tif (resource->reformat_type == cache_resource->reformat_type &&\n \t\t    resource->ft_type == cache_resource->ft_type &&\n \t\t    resource->flags == cache_resource->flags &&\n@@ -2458,12 +2460,14 @@ struct field_modify_info modify_tcp[] = {\n \t\t\t\t(void *)cache_resource,\n \t\t\t\trte_atomic32_read(&cache_resource->refcnt));\n \t\t\trte_atomic32_inc(&cache_resource->refcnt);\n-\t\t\tdev_flow->handle->dvh.encap_decap = cache_resource;\n+\t\t\tdev_flow->handle->dvh.encap_decap = idx;\n+\t\t\tdev_flow->dv.encap_decap = cache_resource;\n \t\t\treturn 0;\n \t\t}\n \t}\n \t/* Register new encap/decap resource. */\n-\tcache_resource = rte_calloc(__func__, 1, sizeof(*cache_resource), 0);\n+\tcache_resource = mlx5_ipool_zmalloc(sh->ipool[MLX5_IPOOL_DECAP_ENCAP],\n+\t\t\t\t       &dev_flow->handle->dvh.encap_decap);\n \tif (!cache_resource)\n \t\treturn rte_flow_error_set(error, ENOMEM,\n \t\t\t\t\t  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,\n@@ -2483,8 +2487,9 @@ struct field_modify_info modify_tcp[] = {\n \t}\n \trte_atomic32_init(&cache_resource->refcnt);\n \trte_atomic32_inc(&cache_resource->refcnt);\n-\tLIST_INSERT_HEAD(&sh->encaps_decaps, cache_resource, next);\n-\tdev_flow->handle->dvh.encap_decap = cache_resource;\n+\tILIST_INSERT(sh->ipool[MLX5_IPOOL_DECAP_ENCAP], &sh->encaps_decaps,\n+\t\t     dev_flow->handle->dvh.encap_decap, cache_resource, next);\n+\tdev_flow->dv.encap_decap = cache_resource;\n \tDRV_LOG(DEBUG, \"new encap/decap resource %p: refcnt %d++\",\n \t\t(void *)cache_resource,\n \t\trte_atomic32_read(&cache_resource->refcnt));\n@@ -3080,6 +3085,7 @@ struct field_modify_info modify_tcp[] = {\n \tconst struct rte_flow_action_raw_encap *encap_data;\n \tstruct mlx5_flow_dv_encap_decap_resource res;\n \n+\tmemset(&res, 0, sizeof(res));\n \tencap_data = (const struct rte_flow_action_raw_encap *)action->conf;\n \tres.size = encap_data->size;\n \tmemcpy(res.buf, encap_data->data, res.size);\n@@ -7572,7 +7578,7 @@ struct field_modify_info modify_tcp[] = {\n \t\t\t\t\t\t\t   error))\n \t\t\t\treturn -rte_errno;\n \t\t\tdev_flow->dv.actions[actions_n++] =\n-\t\t\t\t\thandle->dvh.encap_decap->verbs_action;\n+\t\t\t\t\tdev_flow->dv.encap_decap->verbs_action;\n \t\t\taction_flags |= MLX5_FLOW_ACTION_ENCAP;\n \t\t\tbreak;\n \t\tcase RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:\n@@ -7582,7 +7588,7 @@ struct field_modify_info modify_tcp[] = {\n \t\t\t\t\t\t\t   error))\n \t\t\t\treturn -rte_errno;\n \t\t\tdev_flow->dv.actions[actions_n++] =\n-\t\t\t\t\thandle->dvh.encap_decap->verbs_action;\n+\t\t\t\t\tdev_flow->dv.encap_decap->verbs_action;\n \t\t\taction_flags |= MLX5_FLOW_ACTION_DECAP;\n \t\t\tbreak;\n \t\tcase RTE_FLOW_ACTION_TYPE_RAW_ENCAP:\n@@ -7592,7 +7598,7 @@ struct field_modify_info modify_tcp[] = {\n \t\t\t\t\t(dev, actions, dev_flow, attr, error))\n \t\t\t\t\treturn -rte_errno;\n \t\t\t\tdev_flow->dv.actions[actions_n++] =\n-\t\t\t\t\thandle->dvh.encap_decap->verbs_action;\n+\t\t\t\t\tdev_flow->dv.encap_decap->verbs_action;\n \t\t\t} else {\n \t\t\t\t/* Handle encap without preceding decap. */\n \t\t\t\tif (flow_dv_create_action_l2_encap\n@@ -7600,7 +7606,7 @@ struct field_modify_info modify_tcp[] = {\n \t\t\t\t     error))\n \t\t\t\t\treturn -rte_errno;\n \t\t\t\tdev_flow->dv.actions[actions_n++] =\n-\t\t\t\t\thandle->dvh.encap_decap->verbs_action;\n+\t\t\t\t\tdev_flow->dv.encap_decap->verbs_action;\n \t\t\t}\n \t\t\taction_flags |= MLX5_FLOW_ACTION_ENCAP;\n \t\t\tbreak;\n@@ -7612,7 +7618,7 @@ struct field_modify_info modify_tcp[] = {\n \t\t\t\t    (dev, dev_flow, attr->transfer, error))\n \t\t\t\t\treturn -rte_errno;\n \t\t\t\tdev_flow->dv.actions[actions_n++] =\n-\t\t\t\t\thandle->dvh.encap_decap->verbs_action;\n+\t\t\t\t\tdev_flow->dv.encap_decap->verbs_action;\n \t\t\t}\n \t\t\t/* If decap is followed by encap, handle it at encap. */\n \t\t\taction_flags |= MLX5_FLOW_ACTION_DECAP;\n@@ -8166,6 +8172,8 @@ struct field_modify_info modify_tcp[] = {\n /**\n  * Release an encap/decap resource.\n  *\n+ * @param dev\n+ *   Pointer to Ethernet device.\n  * @param handle\n  *   Pointer to mlx5_flow_handle.\n  *\n@@ -8173,11 +8181,17 @@ struct field_modify_info modify_tcp[] = {\n  *   1 while a reference on it exists, 0 when freed.\n  */\n static int\n-flow_dv_encap_decap_resource_release(struct mlx5_flow_handle *handle)\n+flow_dv_encap_decap_resource_release(struct rte_eth_dev *dev,\n+\t\t\t\t     struct mlx5_flow_handle *handle)\n {\n-\tstruct mlx5_flow_dv_encap_decap_resource *cache_resource =\n-\t\t\t\t\t\thandle->dvh.encap_decap;\n+\tstruct mlx5_priv *priv = dev->data->dev_private;\n+\tuint32_t idx = handle->dvh.encap_decap;\n+\tstruct mlx5_flow_dv_encap_decap_resource *cache_resource;\n \n+\tcache_resource = mlx5_ipool_get(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],\n+\t\t\t idx);\n+\tif (!cache_resource)\n+\t\treturn 0;\n \tMLX5_ASSERT(cache_resource->verbs_action);\n \tDRV_LOG(DEBUG, \"encap/decap resource %p: refcnt %d--\",\n \t\t(void *)cache_resource,\n@@ -8185,8 +8199,10 @@ struct field_modify_info modify_tcp[] = {\n \tif (rte_atomic32_dec_and_test(&cache_resource->refcnt)) {\n \t\tclaim_zero(mlx5_glue->destroy_flow_action\n \t\t\t\t(cache_resource->verbs_action));\n-\t\tLIST_REMOVE(cache_resource, next);\n-\t\trte_free(cache_resource);\n+\t\tILIST_REMOVE(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP],\n+\t\t\t     &priv->sh->encaps_decaps, idx,\n+\t\t\t     cache_resource, next);\n+\t\tmlx5_ipool_free(priv->sh->ipool[MLX5_IPOOL_DECAP_ENCAP], idx);\n \t\tDRV_LOG(DEBUG, \"encap/decap resource %p: removed\",\n \t\t\t(void *)cache_resource);\n \t\treturn 0;\n@@ -8388,7 +8404,7 @@ struct field_modify_info modify_tcp[] = {\n \t\tif (dev_handle->dvh.matcher)\n \t\t\tflow_dv_matcher_release(dev, dev_handle);\n \t\tif (dev_handle->dvh.encap_decap)\n-\t\t\tflow_dv_encap_decap_resource_release(dev_handle);\n+\t\t\tflow_dv_encap_decap_resource_release(dev, dev_handle);\n \t\tif (dev_handle->dvh.modify_hdr)\n \t\t\tflow_dv_modify_hdr_resource_release(dev_handle);\n \t\tif (dev_handle->dvh.jump)\n",
    "prefixes": [
        "04/10"
    ]
}