get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 71719,
    "url": "http://patches.dpdk.org/api/patches/71719/?format=api",
    "web_url": "http://patches.dpdk.org/project/dpdk/patch/1592465084-140601-4-git-send-email-suanmingm@mellanox.com/",
    "project": {
        "id": 1,
        "url": "http://patches.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": "<1592465084-140601-4-git-send-email-suanmingm@mellanox.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1592465084-140601-4-git-send-email-suanmingm@mellanox.com",
    "date": "2020-06-18T07:24:44",
    "name": "[3/3] net/mlx5: optimize single counter pool search",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "142d7609dcec7223dd25f9991a1df13ea1d5bed4",
    "submitter": {
        "id": 1358,
        "url": "http://patches.dpdk.org/api/people/1358/?format=api",
        "name": "Suanming Mou",
        "email": "suanmingm@mellanox.com"
    },
    "delegate": {
        "id": 3268,
        "url": "http://patches.dpdk.org/api/users/3268/?format=api",
        "username": "rasland",
        "first_name": "Raslan",
        "last_name": "Darawsheh",
        "email": "rasland@nvidia.com"
    },
    "mbox": "http://patches.dpdk.org/project/dpdk/patch/1592465084-140601-4-git-send-email-suanmingm@mellanox.com/mbox/",
    "series": [
        {
            "id": 10496,
            "url": "http://patches.dpdk.org/api/series/10496/?format=api",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=10496",
            "date": "2020-06-18T07:24:41",
            "name": "net/mlx5: optimize single counter allocate",
            "version": 1,
            "mbox": "http://patches.dpdk.org/series/10496/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/71719/comments/",
    "check": "success",
    "checks": "http://patches.dpdk.org/api/patches/71719/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 CC2E3A04A5;\n\tThu, 18 Jun 2020 09:25:18 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id CD1721BEA7;\n\tThu, 18 Jun 2020 09:24:57 +0200 (CEST)",
            "from git-send-mailer.rdmz.labs.mlnx (unknown [37.142.13.130])\n by dpdk.org (Postfix) with ESMTP id F0E291BE85\n for <dev@dpdk.org>; Thu, 18 Jun 2020 09:24:54 +0200 (CEST)"
        ],
        "From": "Suanming Mou <suanmingm@mellanox.com>",
        "To": "viacheslavo@mellanox.com,\n\tmatan@mellanox.com",
        "Cc": "rasland@mellanox.com,\n\tdev@dpdk.org",
        "Date": "Thu, 18 Jun 2020 15:24:44 +0800",
        "Message-Id": "<1592465084-140601-4-git-send-email-suanmingm@mellanox.com>",
        "X-Mailer": "git-send-email 1.8.3.1",
        "In-Reply-To": "<1592465084-140601-1-git-send-email-suanmingm@mellanox.com>",
        "References": "<1592465084-140601-1-git-send-email-suanmingm@mellanox.com>",
        "Subject": "[dpdk-dev] [PATCH 3/3] net/mlx5: optimize single counter pool search",
        "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": "For single counter, when allocate a new counter, it needs to find the pool\nit belongs in order to do the query together.\n\nOnce there are millions of counters allocated, the pool array in the\ncounter container will become very large. In this case, the pool search\nfrom the pool array will become extremely slow.\n\nSave the minimum and maximum counter ID to have a quick check of current\ncounter ID range. And start searching the pool from the last pool in the\ncontainer will mostly get the needed pool since counter ID increases\nsequentially.\n\nSigned-off-by: Suanming Mou <suanmingm@mellanox.com>\nAcked-by: Matan Azrad <matan@mellanox.com>\n---\n drivers/net/mlx5/mlx5.c         |  3 +++\n drivers/net/mlx5/mlx5.h         |  9 +++++++\n drivers/net/mlx5/mlx5_flow_dv.c | 60 +++++++++++++++++++++++++++++++----------\n 3 files changed, 58 insertions(+), 14 deletions(-)",
    "diff": "diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c\nindex 4c0c26e..670a59e 100644\n--- a/drivers/net/mlx5/mlx5.c\n+++ b/drivers/net/mlx5/mlx5.c\n@@ -457,6 +457,9 @@ struct mlx5_flow_id_pool *\n \tmemset(&sh->cmng, 0, sizeof(sh->cmng));\n \tTAILQ_INIT(&sh->cmng.flow_counters);\n \tfor (i = 0; i < MLX5_CCONT_TYPE_MAX; ++i) {\n+\t\tsh->cmng.ccont[i].min_id = MLX5_CNT_BATCH_OFFSET;\n+\t\tsh->cmng.ccont[i].max_id = -1;\n+\t\tsh->cmng.ccont[i].last_pool_idx = POOL_IDX_INVALID;\n \t\tTAILQ_INIT(&sh->cmng.ccont[i].pool_list);\n \t\trte_spinlock_init(&sh->cmng.ccont[i].resize_sl);\n \t}\ndiff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h\nindex 1ee9da7..3ddae17 100644\n--- a/drivers/net/mlx5/mlx5.h\n+++ b/drivers/net/mlx5/mlx5.h\n@@ -312,6 +312,12 @@ struct mlx5_drop {\n \tMLX5_CNT_TO_CNT_EXT(pool, MLX5_POOL_GET_CNT((pool), (offset)))\n #define MLX5_CNT_TO_AGE(cnt) \\\n \t((struct mlx5_age_param *)((cnt) + 1))\n+/*\n+ * The maximum single counter is 0x800000 as MLX5_CNT_BATCH_OFFSET\n+ * defines. The pool size is 512, pool index should never reach\n+ * INT16_MAX.\n+ */\n+#define POOL_IDX_INVALID UINT16_MAX\n \n struct mlx5_flow_counter_pool;\n \n@@ -420,6 +426,9 @@ struct mlx5_counter_stats_raw {\n struct mlx5_pools_container {\n \trte_atomic16_t n_valid; /* Number of valid pools. */\n \tuint16_t n; /* Number of pools. */\n+\tuint16_t last_pool_idx; /* Last used pool index */\n+\tint min_id; /* The minimum counter ID in the pools. */\n+\tint max_id; /* The maximum counter ID in the pools. */\n \trte_spinlock_t resize_sl; /* The resize lock. */\n \tstruct mlx5_counter_pools pool_list; /* Counter pool list. */\n \tstruct mlx5_flow_counter_pool **pools; /* Counter pool array. */\ndiff --git a/drivers/net/mlx5/mlx5_flow_dv.c b/drivers/net/mlx5/mlx5_flow_dv.c\nindex 6e4e10c..9fa8568 100644\n--- a/drivers/net/mlx5/mlx5_flow_dv.c\n+++ b/drivers/net/mlx5/mlx5_flow_dv.c\n@@ -4051,6 +4051,28 @@ struct field_modify_info modify_tcp[] = {\n }\n \n /**\n+ * Check the devx counter belongs to the pool.\n+ *\n+ * @param[in] pool\n+ *   Pointer to the counter pool.\n+ * @param[in] id\n+ *   The counter devx ID.\n+ *\n+ * @return\n+ *   True if counter belongs to the pool, false otherwise.\n+ */\n+static bool\n+flow_dv_is_counter_in_pool(struct mlx5_flow_counter_pool *pool, int id)\n+{\n+\tint base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *\n+\t\t   MLX5_COUNTERS_PER_POOL;\n+\n+\tif (id >= base && id < base + MLX5_COUNTERS_PER_POOL)\n+\t\treturn true;\n+\treturn false;\n+}\n+\n+/**\n  * Get a pool by devx counter ID.\n  *\n  * @param[in] cont\n@@ -4065,24 +4087,25 @@ struct field_modify_info modify_tcp[] = {\n flow_dv_find_pool_by_id(struct mlx5_pools_container *cont, int id)\n {\n \tuint32_t i;\n-\tuint32_t n_valid = rte_atomic16_read(&cont->n_valid);\n \n-\tfor (i = 0; i < n_valid; i++) {\n+\t/* Check last used pool. */\n+\tif (cont->last_pool_idx != POOL_IDX_INVALID &&\n+\t    flow_dv_is_counter_in_pool(cont->pools[cont->last_pool_idx], id))\n+\t\treturn cont->pools[cont->last_pool_idx];\n+\t/* ID out of range means no suitable pool in the container. */\n+\tif (id > cont->max_id || id < cont->min_id)\n+\t\treturn NULL;\n+\t/*\n+\t * Find the pool from the end of the container, since mostly counter\n+\t * ID is sequence increasing, and the last pool should be the needed\n+\t * one.\n+\t */\n+\ti = rte_atomic16_read(&cont->n_valid);\n+\twhile (i--) {\n \t\tstruct mlx5_flow_counter_pool *pool = cont->pools[i];\n-\t\tint base = (pool->min_dcs->id / MLX5_COUNTERS_PER_POOL) *\n-\t\t\t   MLX5_COUNTERS_PER_POOL;\n \n-\t\tif (id >= base && id < base + MLX5_COUNTERS_PER_POOL) {\n-\t\t\t/*\n-\t\t\t * Move the pool to the head, as counter allocate\n-\t\t\t * always gets the first pool in the container.\n-\t\t\t */\n-\t\t\tif (pool != TAILQ_FIRST(&cont->pool_list)) {\n-\t\t\t\tTAILQ_REMOVE(&cont->pool_list, pool, next);\n-\t\t\t\tTAILQ_INSERT_HEAD(&cont->pool_list, pool, next);\n-\t\t\t}\n+\t\tif (flow_dv_is_counter_in_pool(pool, id))\n \t\t\treturn pool;\n-\t\t}\n \t}\n \treturn NULL;\n }\n@@ -4337,6 +4360,15 @@ struct field_modify_info modify_tcp[] = {\n \tTAILQ_INSERT_HEAD(&cont->pool_list, pool, next);\n \tpool->index = n_valid;\n \tcont->pools[n_valid] = pool;\n+\tif (!batch) {\n+\t\tint base = RTE_ALIGN_FLOOR(dcs->id, MLX5_COUNTERS_PER_POOL);\n+\n+\t\tif (base < cont->min_id)\n+\t\t\tcont->min_id = base;\n+\t\tif (base > cont->max_id)\n+\t\t\tcont->max_id = base + MLX5_COUNTERS_PER_POOL - 1;\n+\t\tcont->last_pool_idx = pool->index;\n+\t}\n \t/* Pool initialization must be updated before host thread access. */\n \trte_cio_wmb();\n \trte_atomic16_add(&cont->n_valid, 1);\n",
    "prefixes": [
        "3/3"
    ]
}