Show a patch.

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

{
    "id": 42968,
    "url": "http://patches.dpdk.org/api/patches/42968/",
    "web_url": "http://patches.dpdk.org/patch/42968/",
    "project": {
        "id": 1,
        "url": "http://patches.dpdk.org/api/projects/1/",
        "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"
    },
    "msgid": "<5a581b390bb27504e6a3f4878b1f3c01c8e0502b.1531387413.git.nelio.laranjeiro@6wind.com>",
    "date": "2018-07-12T09:31:07",
    "name": "[v4,21/21] net/mlx5: add count flow action",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "573eef17eb4b8d11919c6fd9b2544722b7a8a921",
    "submitter": {
        "id": 243,
        "url": "http://patches.dpdk.org/api/people/243/",
        "name": "Nélio Laranjeiro",
        "email": "nelio.laranjeiro@6wind.com"
    },
    "delegate": {
        "id": 6624,
        "url": "http://patches.dpdk.org/api/users/6624/",
        "username": "shahafs",
        "first_name": "Shahaf",
        "last_name": "Shuler",
        "email": "shahafs@mellanox.com"
    },
    "mbox": "http://patches.dpdk.org/patch/42968/mbox/",
    "series": [
        {
            "id": 544,
            "url": "http://patches.dpdk.org/api/series/544/",
            "web_url": "http://patches.dpdk.org/project/dpdk/list/?series=544",
            "date": "2018-07-12T09:30:46",
            "name": "net/mlx5: flow rework",
            "version": 4,
            "mbox": "http://patches.dpdk.org/series/544/mbox/"
        }
    ],
    "comments": "http://patches.dpdk.org/api/patches/42968/comments/",
    "check": "fail",
    "checks": "http://patches.dpdk.org/api/patches/42968/checks/",
    "tags": {},
    "headers": {
        "X-Mailer": "git-send-email 2.18.0",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "From": "Nelio Laranjeiro <nelio.laranjeiro@6wind.com>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=6wind-com.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=9Rz/2EaFjRDxsUFOaNhENbonqPDcjmPnAYAyvOObRZM=;\n\tb=z8lZBaJ0Kq5GN8BSpvtnq4hN9QVnHQ+hc/p0a338L3kgyPfGkbJDRzBMEkrd2hXnPV\n\tNsy78Dl02i11UeDEVxJ7QupqJZkhJ2c2pQnkf8u8EaOvWoLXXikb2zBK9fJa42Z1/Yqy\n\t0WQipdJp4PVh6Yq5wI71gmioAt7uEb8joEXK186UifUTAfbXYUWOevhnBe1gE73yCNey\n\tLNJ/MeCzgziiYbbytljTjPU8h5zEWCsK7y2LVNS20k73jCSH9jSy1I2rLbB4QEidqGAF\n\txwJwW6GWsEvS+a80dK2ZSR0B4lFmgz0WPYUoHL86+uuOkcmuVraae8wITzvRQoaD6O8d\n\tkWxQ==",
        "X-Mailman-Version": "2.1.15",
        "Delivered-To": "patchwork@dpdk.org",
        "X-Gm-Message-State": "AOUpUlHLgPFBHfGoYDQsKBqQukLnEEQi0o8pGlzZ+PJe529XC50tHIwa\n\t5y2AywyUTHGfrpFLCy92giuOfILCXg==",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n\t<mailto:dev-request@dpdk.org?subject=subscribe>",
        "Cc": "Adrien Mazarguil <adrien.mazarguil@6wind.com>",
        "To": "dev@dpdk.org,\n\tYongseok Koh <yskoh@mellanox.com>",
        "Errors-To": "dev-bounces@dpdk.org",
        "References": "<cover.1531293415.git.nelio.laranjeiro@6wind.com>\n\t<cover.1531387413.git.nelio.laranjeiro@6wind.com>",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=9Rz/2EaFjRDxsUFOaNhENbonqPDcjmPnAYAyvOObRZM=;\n\tb=GJbhiVd8lerS97z3X6/6JvH3xrQO6d4r0JxknsWxV/vyvnexSt1LuS42IQgX0Gq01R\n\trII5ifmqy+4WoxixGPu/RAAi2mKOjGuHGL9JyLYN77zW1gYqwxSW5AXAl0ResmjSGnZg\n\tNX8FyGKZDAKoqW+7yMyXtU3MwTl7dVyoqGcgSYxPW6rcZtsas+RuR1MKCrbY6wxBkflh\n\tEJNl+/DezLKxqsC1+ury4F1pxV8edjwPDzum1g2GxkU4bIKIhWc5H6M+l7R96n0+9pHy\n\tyGUJAw37IrIrt3bxhnvnKNGo5bAJIyYDq1gi5NyX/c8pEy13CTy7YB7fpdvUARfJEUhH\n\tp0+w==",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n\t<mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "Received": [
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id BC3011B8CB;\n\tThu, 12 Jul 2018 11:32:08 +0200 (CEST)",
            "from mail-wr1-f47.google.com (mail-wr1-f47.google.com\n\t[209.85.221.47]) by dpdk.org (Postfix) with ESMTP id 032F71B5D2\n\tfor <dev@dpdk.org>; Thu, 12 Jul 2018 11:31:43 +0200 (CEST)",
            "by mail-wr1-f47.google.com with SMTP id h10-v6so20954567wre.6\n\tfor <dev@dpdk.org>; Thu, 12 Jul 2018 02:31:43 -0700 (PDT)",
            "from laranjeiro-vm.dev.6wind.com\n\t(host.78.145.23.62.rev.coltfrance.com. [62.23.145.78])\n\tby smtp.gmail.com with ESMTPSA id\n\ts2-v6sm18717603wrn.75.2018.07.12.02.31.42\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\n\tThu, 12 Jul 2018 02:31:42 -0700 (PDT)"
        ],
        "Date": "Thu, 12 Jul 2018 11:31:07 +0200",
        "X-Received": "by 2002:adf:c4a7:: with SMTP id\n\tm36-v6mr1125301wrf.103.1531387903467; \n\tThu, 12 Jul 2018 02:31:43 -0700 (PDT)",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "Subject": "[dpdk-dev] [PATCH v4 21/21] net/mlx5: add count flow action",
        "In-Reply-To": "<cover.1531387413.git.nelio.laranjeiro@6wind.com>",
        "Message-Id": "<5a581b390bb27504e6a3f4878b1f3c01c8e0502b.1531387413.git.nelio.laranjeiro@6wind.com>",
        "Precedence": "list",
        "X-BeenThere": "dev@dpdk.org",
        "X-Original-To": "patchwork@dpdk.org",
        "X-Google-Smtp-Source": "AAOMgpfijcAzm66eNHWbyeDjT5YvMjEBl9dlSFfoMYAAKVJXfWB5M9q2RJ0EH9FawWrISEGw/ujZ+w=="
    },
    "content": "This is only supported by Mellanox OFED.\n\nSigned-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>\nAcked-by: Yongseok Koh <yskoh@mellanox.com>\n---\n drivers/net/mlx5/mlx5.h      |   2 +\n drivers/net/mlx5/mlx5_flow.c | 242 +++++++++++++++++++++++++++++++++++\n 2 files changed, 244 insertions(+)",
    "diff": "diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h\nindex 9949cd3fa..131be334c 100644\n--- a/drivers/net/mlx5/mlx5.h\n+++ b/drivers/net/mlx5/mlx5.h\n@@ -188,6 +188,8 @@ struct priv {\n \tstruct mlx5_drop drop_queue; /* Flow drop queues. */\n \tstruct mlx5_flows flows; /* RTE Flow rules. */\n \tstruct mlx5_flows ctrl_flows; /* Control flow rules. */\n+\tLIST_HEAD(counters, mlx5_flow_counter) flow_counters;\n+\t/* Flow counters. */\n \tstruct {\n \t\tuint32_t dev_gen; /* Generation number to flush local caches. */\n \t\trte_rwlock_t rwlock; /* MR Lock. */\ndiff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c\nindex 1d7b72ac1..89bfc670f 100644\n--- a/drivers/net/mlx5/mlx5_flow.c\n+++ b/drivers/net/mlx5/mlx5_flow.c\n@@ -88,6 +88,7 @@ extern const struct eth_dev_ops mlx5_dev_ops_isolate;\n /* Modify a packet. */\n #define MLX5_FLOW_MOD_FLAG (1u << 0)\n #define MLX5_FLOW_MOD_MARK (1u << 1)\n+#define MLX5_FLOW_MOD_COUNT (1u << 2)\n \n /* possible L3 layers protocols filtering. */\n #define MLX5_IP_PROTOCOL_TCP 6\n@@ -249,6 +250,17 @@ struct mlx5_flow_verbs {\n \tuint64_t hash_fields; /**< Verbs hash Rx queue hash fields. */\n };\n \n+/* Counters information. */\n+struct mlx5_flow_counter {\n+\tLIST_ENTRY(mlx5_flow_counter) next; /**< Pointer to the next counter. */\n+\tuint32_t shared:1; /**< Share counter ID with other flow rules. */\n+\tuint32_t ref_cnt:31; /**< Reference counter. */\n+\tuint32_t id; /**< Counter ID. */\n+\tstruct ibv_counter_set *cs; /**< Holds the counters for the rule. */\n+\tuint64_t hits; /**< Number of packets matched by the rule. */\n+\tuint64_t bytes; /**< Number of bytes matched by the rule. */\n+};\n+\n /* Flow structure. */\n struct rte_flow {\n \tTAILQ_ENTRY(rte_flow) next; /**< Pointer to the next flow structure. */\n@@ -264,6 +276,7 @@ struct rte_flow {\n \tLIST_HEAD(verbs, mlx5_flow_verbs) verbs; /**< Verbs flows list. */\n \tstruct mlx5_flow_verbs *cur_verbs;\n \t/**< Current Verbs flow structure being filled. */\n+\tstruct mlx5_flow_counter *counter; /**< Holds Verbs flow counter. */\n \tstruct rte_flow_action_rss rss;/**< RSS context. */\n \tuint8_t key[MLX5_RSS_HASH_KEY_LEN]; /**< RSS hash key. */\n \tuint16_t (*queue)[]; /**< Destination queues to redirect traffic to. */\n@@ -275,6 +288,7 @@ static const struct rte_flow_ops mlx5_flow_ops = {\n \t.destroy = mlx5_flow_destroy,\n \t.flush = mlx5_flow_flush,\n \t.isolate = mlx5_flow_isolate,\n+\t.query = mlx5_flow_query,\n };\n \n /* Convert FDIR request to Generic flow. */\n@@ -454,6 +468,80 @@ mlx5_flow_adjust_priority(struct rte_eth_dev *dev, struct rte_flow *flow)\n \tflow->cur_verbs->attr->priority = priority;\n }\n \n+/**\n+ * Get a flow counter.\n+ *\n+ * @param[in] dev\n+ *   Pointer to Ethernet device.\n+ * @param[in] shared\n+ *   Indicate if this counter is shared with other flows.\n+ * @param[in] id\n+ *   Counter identifier.\n+ *\n+ * @return\n+ *   A pointer to the counter, NULL otherwise and rte_errno is set.\n+ */\n+static struct mlx5_flow_counter *\n+mlx5_flow_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id)\n+{\n+\tstruct priv *priv = dev->data->dev_private;\n+\tstruct mlx5_flow_counter *cnt;\n+\n+\tLIST_FOREACH(cnt, &priv->flow_counters, next) {\n+\t\tif (cnt->shared != shared)\n+\t\t\tcontinue;\n+\t\tif (cnt->id != id)\n+\t\t\tcontinue;\n+\t\tcnt->ref_cnt++;\n+\t\treturn cnt;\n+\t}\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\n+\tstruct mlx5_flow_counter tmpl = {\n+\t\t.shared = shared,\n+\t\t.id = id,\n+\t\t.cs = mlx5_glue->create_counter_set\n+\t\t\t(priv->ctx,\n+\t\t\t &(struct ibv_counter_set_init_attr){\n+\t\t\t\t .counter_set_id = id,\n+\t\t\t }),\n+\t\t.hits = 0,\n+\t\t.bytes = 0,\n+\t};\n+\n+\tif (!tmpl.cs) {\n+\t\trte_errno = errno;\n+\t\treturn NULL;\n+\t}\n+\tcnt = rte_calloc(__func__, 1, sizeof(*cnt), 0);\n+\tif (!cnt) {\n+\t\trte_errno = ENOMEM;\n+\t\treturn NULL;\n+\t}\n+\t*cnt = tmpl;\n+\tLIST_INSERT_HEAD(&priv->flow_counters, cnt, next);\n+\treturn cnt;\n+#endif\n+\trte_errno = ENOTSUP;\n+\treturn NULL;\n+}\n+\n+/**\n+ * Release a flow counter.\n+ *\n+ * @param[in] counter\n+ *   Pointer to the counter handler.\n+ */\n+static void\n+mlx5_flow_counter_release(struct mlx5_flow_counter *counter)\n+{\n+\tif (--counter->ref_cnt == 0) {\n+\t\tclaim_zero(mlx5_glue->destroy_counter_set(counter->cs));\n+\t\tLIST_REMOVE(counter, next);\n+\t\trte_free(counter);\n+\t}\n+}\n+\n /**\n  * Verify the @p attributes will be correctly understood by the NIC and store\n  * them in the @p flow if everything is correct.\n@@ -2127,6 +2215,70 @@ mlx5_flow_action_mark(const struct rte_flow_action *action,\n \treturn size;\n }\n \n+/**\n+ * Convert the @p action into a Verbs specification after ensuring the NIC\n+ * will understand and process it correctly.\n+ * If the necessary size for the conversion is greater than the @p flow_size,\n+ * nothing is written in @p flow, the validation is still performed.\n+ *\n+ * @param action[in]\n+ *   Action configuration.\n+ * @param flow[in, out]\n+ *   Pointer to flow structure.\n+ * @param flow_size[in]\n+ *   Size in bytes of the available space in @p flow, if too small, nothing is\n+ *   written.\n+ * @param error[int, out]\n+ *   Pointer to error structure.\n+ *\n+ * @return\n+ *   On success the number of bytes consumed/necessary, if the returned value\n+ *   is lesser or equal to @p flow_size, the @p action has fully been\n+ *   converted, otherwise another call with this returned memory size should\n+ *   be done.\n+ *   On error, a negative errno value is returned and rte_errno is set.\n+ */\n+static int\n+mlx5_flow_action_count(struct rte_eth_dev *dev,\n+\t\t       const struct rte_flow_action *action,\n+\t\t       struct rte_flow *flow,\n+\t\t       const size_t flow_size __rte_unused,\n+\t\t       struct rte_flow_error *error)\n+{\n+\tconst struct rte_flow_action_count *count = action->conf;\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\tunsigned int size = sizeof(struct ibv_flow_spec_counter_action);\n+\tstruct ibv_flow_spec_counter_action counter = {\n+\t\t.type = IBV_FLOW_SPEC_ACTION_COUNT,\n+\t\t.size = size,\n+\t};\n+#endif\n+\n+\tif (!flow->counter) {\n+\t\tflow->counter = mlx5_flow_counter_new(dev, count->shared,\n+\t\t\t\t\t\t      count->id);\n+\t\tif (!flow->counter)\n+\t\t\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t\t  action,\n+\t\t\t\t\t\t  \"cannot get counter\"\n+\t\t\t\t\t\t  \" context.\");\n+\t}\n+\tif (!((struct priv *)dev->data->dev_private)->config.flow_counter_en)\n+\t\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t  action,\n+\t\t\t\t\t  \"flow counters are not supported.\");\n+\tflow->modifier |= MLX5_FLOW_MOD_COUNT;\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\tcounter.counter_set_handle = flow->counter->cs->handle;\n+\tif (size <= flow_size)\n+\t\tmlx5_flow_spec_verbs_add(flow, &counter, size);\n+\treturn size;\n+#endif\n+\treturn 0;\n+}\n+\n /**\n  * Convert the @p action into @p flow after ensuring the NIC will understand\n  * and process it correctly.\n@@ -2186,6 +2338,10 @@ mlx5_flow_actions(struct rte_eth_dev *dev,\n \t\tcase RTE_FLOW_ACTION_TYPE_RSS:\n \t\t\tret = mlx5_flow_action_rss(dev, actions, flow, error);\n \t\t\tbreak;\n+\t\tcase RTE_FLOW_ACTION_TYPE_COUNT:\n+\t\t\tret = mlx5_flow_action_count(dev, actions, flow, remain,\n+\t\t\t\t\t\t     error);\n+\t\t\tbreak;\n \t\tdefault:\n \t\t\treturn rte_flow_error_set(error, ENOTSUP,\n \t\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n@@ -2567,6 +2723,10 @@ mlx5_flow_remove(struct rte_eth_dev *dev, struct rte_flow *flow)\n \t\t\tverbs->hrxq = NULL;\n \t\t}\n \t}\n+\tif (flow->counter) {\n+\t\tmlx5_flow_counter_release(flow->counter);\n+\t\tflow->counter = NULL;\n+\t}\n }\n \n /**\n@@ -3016,6 +3176,88 @@ mlx5_flow_isolate(struct rte_eth_dev *dev,\n \treturn 0;\n }\n \n+/**\n+ * Query flow counter.\n+ *\n+ * @param flow\n+ *   Pointer to the flow.\n+ *\n+ * @return\n+ *   0 on success, a negative errno value otherwise and rte_errno is set.\n+ */\n+static int\n+mlx5_flow_query_count(struct rte_flow *flow __rte_unused,\n+\t\t      void *data __rte_unused,\n+\t\t      struct rte_flow_error *error)\n+{\n+#ifdef HAVE_IBV_DEVICE_COUNTERS_SET_SUPPORT\n+\tstruct rte_flow_query_count *qc = data;\n+\tuint64_t counters[2] = {0, 0};\n+\tstruct ibv_query_counter_set_attr query_cs_attr = {\n+\t\t.cs = flow->counter->cs,\n+\t\t.query_flags = IBV_COUNTER_SET_FORCE_UPDATE,\n+\t};\n+\tstruct ibv_counter_set_data query_out = {\n+\t\t.out = counters,\n+\t\t.outlen = 2 * sizeof(uint64_t),\n+\t};\n+\tint err = mlx5_glue->query_counter_set(&query_cs_attr, &query_out);\n+\n+\tif (err)\n+\t\treturn rte_flow_error_set(error, err,\n+\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t\t  NULL,\n+\t\t\t\t\t  \"cannot read counter\");\n+\tqc->hits_set = 1;\n+\tqc->bytes_set = 1;\n+\tqc->hits = counters[0] - flow->counter->hits;\n+\tqc->bytes = counters[1] - flow->counter->bytes;\n+\tif (qc->reset) {\n+\t\tflow->counter->hits = counters[0];\n+\t\tflow->counter->bytes = counters[1];\n+\t}\n+\treturn 0;\n+#endif\n+\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,\n+\t\t\t\t  NULL,\n+\t\t\t\t  \"counters are not available\");\n+}\n+\n+/**\n+ * Query a flows.\n+ *\n+ * @see rte_flow_query()\n+ * @see rte_flow_ops\n+ */\n+int\n+mlx5_flow_query(struct rte_eth_dev *dev __rte_unused,\n+\t\tstruct rte_flow *flow,\n+\t\tconst struct rte_flow_action *actions,\n+\t\tvoid *data,\n+\t\tstruct rte_flow_error *error)\n+{\n+\tint ret = 0;\n+\n+\tfor (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {\n+\t\tswitch (actions->type) {\n+\t\tcase RTE_FLOW_ACTION_TYPE_VOID:\n+\t\t\tbreak;\n+\t\tcase RTE_FLOW_ACTION_TYPE_COUNT:\n+\t\t\tret = mlx5_flow_query_count(flow, data, error);\n+\t\t\tbreak;\n+\t\tdefault:\n+\t\t\treturn rte_flow_error_set(error, ENOTSUP,\n+\t\t\t\t\t\t  RTE_FLOW_ERROR_TYPE_ACTION,\n+\t\t\t\t\t\t  actions,\n+\t\t\t\t\t\t  \"action not supported\");\n+\t\t}\n+\t\tif (ret < 0)\n+\t\t\treturn ret;\n+\t}\n+\treturn 0;\n+}\n+\n /**\n  * Convert a flow director filter to a generic flow.\n  *\n",
    "prefixes": [
        "v4",
        "21/21"
    ]
}