get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 86845,
    "url": "https://patches.dpdk.org/api/patches/86845/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/1611027580-332220-3-git-send-email-dongzhou@nvidia.com/",
    "project": {
        "id": 1,
        "url": "https://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": "<1611027580-332220-3-git-send-email-dongzhou@nvidia.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/1611027580-332220-3-git-send-email-dongzhou@nvidia.com",
    "date": "2021-01-19T03:39:40",
    "name": "[v2,2/2] app/flow-perf: support meter action",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "8a347e2a0a478df11dedd98bd0c578e04c49f404",
    "submitter": {
        "id": 2011,
        "url": "https://patches.dpdk.org/api/people/2011/?format=api",
        "name": "Dong Zhou",
        "email": "dongzhou@nvidia.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/1611027580-332220-3-git-send-email-dongzhou@nvidia.com/mbox/",
    "series": [
        {
            "id": 14826,
            "url": "https://patches.dpdk.org/api/series/14826/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=14826",
            "date": "2021-01-19T03:39:38",
            "name": "app/flow-perf: support meter action",
            "version": 2,
            "mbox": "https://patches.dpdk.org/series/14826/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/86845/comments/",
    "check": "warning",
    "checks": "https://patches.dpdk.org/api/patches/86845/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 mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 7240AA0A03;\n\tTue, 19 Jan 2021 04:39:51 +0100 (CET)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 93466140DF9;\n\tTue, 19 Jan 2021 04:39:49 +0100 (CET)",
            "from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129])\n by mails.dpdk.org (Postfix) with ESMTP id EF490140DF9\n for <dev@dpdk.org>; Tue, 19 Jan 2021 04:39:47 +0100 (CET)",
            "from Internal Mail-Server by MTLPINE1 (envelope-from\n dongzhou@nvidia.com) with SMTP; 19 Jan 2021 05:39:45 +0200",
            "from nvidia.com (gen-l-vrt-320.mtl.labs.mlnx [10.237.113.1])\n by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 10J3dgxc001138;\n Tue, 19 Jan 2021 05:39:45 +0200"
        ],
        "From": "Dong Zhou <dongzhou@nvidia.com>",
        "To": "wisamm@nvidia.com, akozyrev@nvidia.com, suanmingm@nvidia.com,\n thomas@monjalon.net",
        "Cc": "dev@dpdk.org, rasland@nvidia.com",
        "Date": "Tue, 19 Jan 2021 05:39:40 +0200",
        "Message-Id": "<1611027580-332220-3-git-send-email-dongzhou@nvidia.com>",
        "X-Mailer": "git-send-email 1.8.3.1",
        "In-Reply-To": "<1611027580-332220-1-git-send-email-dongzhou@nvidia.com>",
        "References": "<1610542256-285053-1-git-send-email-dongzhou@nvidia.com>\n <1611027580-332220-1-git-send-email-dongzhou@nvidia.com>",
        "Subject": "[dpdk-dev] [PATCH v2 2/2] app/flow-perf: support meter action",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "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": "Currently, test-flow-perf app cannot generate flows with meter\naction. This patch introduces new parameter \"--meter\" to generate\nflows with meter action.\n\nSigned-off-by: Dong Zhou <dongzhou@nvidia.com>\nReviewed-by: Wisam Jaddo <wisamm@nvidia.com>\nReviewed-by: Alexander Kozyrev <akozyrev@nvidia.com>\n---\n app/test-flow-perf/actions_gen.c |  19 ++++\n app/test-flow-perf/config.h      |   2 +\n app/test-flow-perf/main.c        | 210 ++++++++++++++++++++++++++++++++++++++-\n doc/guides/tools/flow-perf.rst   |   4 +\n 4 files changed, 233 insertions(+), 2 deletions(-)",
    "diff": "diff --git a/app/test-flow-perf/actions_gen.c b/app/test-flow-perf/actions_gen.c\nindex c3545ba..1f5c64f 100644\n--- a/app/test-flow-perf/actions_gen.c\n+++ b/app/test-flow-perf/actions_gen.c\n@@ -891,6 +891,19 @@ struct action_rss_data {\n \tactions[actions_counter].type = RTE_FLOW_ACTION_TYPE_VXLAN_DECAP;\n }\n \n+static void\n+add_meter(struct rte_flow_action *actions,\n+\tuint8_t actions_counter,\n+\t__rte_unused struct additional_para para)\n+{\n+\tstatic struct rte_flow_action_meter\n+\t\tmeters[RTE_MAX_LCORE] __rte_cache_aligned;\n+\n+\tmeters[para.core_idx].mtr_id = para.counter;\n+\tactions[actions_counter].type = RTE_FLOW_ACTION_TYPE_METER;\n+\tactions[actions_counter].conf = &meters[para.core_idx];\n+}\n+\n void\n fill_actions(struct rte_flow_action *actions, uint64_t *flow_actions,\n \tuint32_t counter, uint16_t next_table, uint16_t hairpinq,\n@@ -1103,6 +1116,12 @@ struct action_rss_data {\n \t\t\t),\n \t\t\t.funct = add_vxlan_decap,\n \t\t},\n+\t\t{\n+\t\t\t.mask = FLOW_ACTION_MASK(\n+\t\t\t\tRTE_FLOW_ACTION_TYPE_METER\n+\t\t\t),\n+\t\t\t.funct = add_meter,\n+\t\t},\n \t};\n \n \tfor (j = 0; j < MAX_ACTIONS_NUM; j++) {\ndiff --git a/app/test-flow-perf/config.h b/app/test-flow-perf/config.h\nindex 94e83c9..3d4696d 100644\n--- a/app/test-flow-perf/config.h\n+++ b/app/test-flow-perf/config.h\n@@ -16,6 +16,8 @@\n #define NR_RXD  256\n #define NR_TXD  256\n #define MAX_PORTS 64\n+#define METER_CIR 1250000\n+#define DEFAULT_METER_PROF_ID 100\n \n /* This is used for encap/decap & header modify actions.\n  * When it's 1: it means all actions have fixed values.\ndiff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c\nindex d10fa3f..99d0463 100644\n--- a/app/test-flow-perf/main.c\n+++ b/app/test-flow-perf/main.c\n@@ -34,6 +34,7 @@\n #include <rte_mbuf.h>\n #include <rte_ethdev.h>\n #include <rte_flow.h>\n+#include <rte_mtr.h>\n \n #include \"config.h\"\n #include \"flow_gen.h\"\n@@ -72,6 +73,8 @@\n #define LCORE_MODE_PKT    1\n #define LCORE_MODE_STATS  2\n #define MAX_STREAMS      64\n+#define METER_CREATE\t  1\n+#define METER_DELETE\t  2\n \n struct stream {\n \tint tx_port;\n@@ -200,6 +203,7 @@ struct multi_cores_pool {\n \tprintf(\"  --set-ipv6-dscp: add set ipv6 dscp action to flow actions\\n\"\n \t\t\"ipv6 dscp value to be set is random each flow\\n\");\n \tprintf(\"  --flag: add flag action to flow actions\\n\");\n+\tprintf(\"  --meter: add meter action to flow actions\\n\");\n \tprintf(\"  --raw-encap=<data>: add raw encap action to flow actions\\n\"\n \t\t\"Data is the data needed to be encaped\\n\"\n \t\t\"Example: raw-encap=ether,ipv4,udp,vxlan\\n\");\n@@ -529,6 +533,14 @@ struct multi_cores_pool {\n \t\t\t.map_idx = &actions_idx\n \t\t},\n \t\t{\n+\t\t\t.str = \"meter\",\n+\t\t\t.mask = FLOW_ACTION_MASK(\n+\t\t\t\tRTE_FLOW_ACTION_TYPE_METER\n+\t\t\t),\n+\t\t\t.map = &flow_actions[0],\n+\t\t\t.map_idx = &actions_idx\n+\t\t},\n+\t\t{\n \t\t\t.str = \"vxlan-encap\",\n \t\t\t.mask = FLOW_ACTION_MASK(\n \t\t\t\tRTE_FLOW_ACTION_TYPE_VXLAN_ENCAP\n@@ -607,6 +619,7 @@ struct multi_cores_pool {\n \t\t{ \"set-ipv4-dscp\",              0, 0, 0 },\n \t\t{ \"set-ipv6-dscp\",              0, 0, 0 },\n \t\t{ \"flag\",                       0, 0, 0 },\n+\t\t{ \"meter\",\t\t        0, 0, 0 },\n \t\t{ \"raw-encap\",                  1, 0, 0 },\n \t\t{ \"raw-decap\",                  1, 0, 0 },\n \t\t{ \"vxlan-encap\",                0, 0, 0 },\n@@ -879,6 +892,185 @@ struct multi_cores_pool {\n \t}\n }\n \n+\n+static inline int\n+has_meter(void)\n+{\n+\tint i;\n+\n+\tfor (i = 0; i < MAX_ACTIONS_NUM; i++) {\n+\t\tif (flow_actions[i] == 0)\n+\t\t\tbreak;\n+\t\tif (flow_actions[i]\n+\t\t\t\t& FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_METER))\n+\t\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+static void\n+create_meter_rule(int port_id, uint32_t counter)\n+{\n+\tint ret;\n+\tstruct rte_mtr_params params;\n+\tuint32_t default_prof_id = 100;\n+\tstruct rte_mtr_error error;\n+\n+\tmemset(&params, 0, sizeof(struct rte_mtr_params));\n+\tparams.meter_enable = 1;\n+\tparams.stats_mask = 0xffff;\n+\tparams.use_prev_mtr_color = 0;\n+\tparams.dscp_table = NULL;\n+\n+\t/*create meter*/\n+\tparams.meter_profile_id = default_prof_id;\n+\tparams.action[RTE_COLOR_GREEN] =\n+\t\tMTR_POLICER_ACTION_COLOR_GREEN;\n+\tparams.action[RTE_COLOR_YELLOW] =\n+\t\tMTR_POLICER_ACTION_COLOR_YELLOW;\n+\tparams.action[RTE_COLOR_RED] =\n+\t\tMTR_POLICER_ACTION_DROP;\n+\n+\tret = rte_mtr_create(port_id, counter, &params, 1, &error);\n+\tif (ret != 0) {\n+\t\tprintf(\"Port %u create meter idx(%d) error(%d) message: %s\\n\",\n+\t\t\tport_id, counter, error.type,\n+\t\t\terror.message ? error.message : \"(no stated reason)\");\n+\t\trte_exit(EXIT_FAILURE, \"error in creating meter\");\n+\t}\n+}\n+\n+static void\n+destroy_meter_rule(int port_id, uint32_t counter)\n+{\n+\tstruct rte_mtr_error error;\n+\n+\tif (rte_mtr_destroy(port_id, counter, &error)) {\n+\t\tprintf(\"Port %u destroy meter(%d) error(%d) message: %s\\n\",\n+\t\t\tport_id, counter, error.type,\n+\t\t\terror.message ? error.message : \"(no stated reason)\");\n+\t\trte_exit(EXIT_FAILURE, \"Error in deleting meter rule\");\n+\t}\n+}\n+\n+static void\n+meters_handler(int port_id, uint8_t core_id, uint8_t ops)\n+{\n+\tuint64_t start_batch;\n+\tdouble cpu_time_used, insertion_rate;\n+\tint rules_count_per_core, rules_batch_idx;\n+\tuint32_t counter, start_counter = 0, end_counter;\n+\tdouble cpu_time_per_batch[MAX_BATCHES_COUNT] = { 0 };\n+\n+\trules_count_per_core = rules_count / mc_pool.cores_count;\n+\n+\tif (core_id)\n+\t\tstart_counter = core_id * rules_count_per_core;\n+\tend_counter = (core_id + 1) * rules_count_per_core;\n+\n+\tcpu_time_used = 0;\n+\tstart_batch = rte_rdtsc();\n+\tfor (counter = start_counter; counter < end_counter; counter++) {\n+\t\tif (ops == METER_CREATE)\n+\t\t\tcreate_meter_rule(port_id, counter);\n+\t\telse\n+\t\t\tdestroy_meter_rule(port_id, counter);\n+\t\t/*\n+\t\t * Save the insertion rate for rules batch.\n+\t\t * Check if the insertion reached the rules\n+\t\t * patch counter, then save the insertion rate\n+\t\t * for this batch.\n+\t\t */\n+\t\tif (!((counter + 1) % rules_batch)) {\n+\t\t\trules_batch_idx = ((counter + 1) / rules_batch) - 1;\n+\t\t\tcpu_time_per_batch[rules_batch_idx] =\n+\t\t\t\t((double)(rte_rdtsc() - start_batch))\n+\t\t\t\t/ rte_get_tsc_hz();\n+\t\t\tcpu_time_used += cpu_time_per_batch[rules_batch_idx];\n+\t\t\tstart_batch = rte_rdtsc();\n+\t\t}\n+\t}\n+\n+\t/* Print insertion rates for all batches */\n+\tif (dump_iterations)\n+\t\tprint_rules_batches(cpu_time_per_batch);\n+\n+\tinsertion_rate =\n+\t\t((double) (rules_count_per_core / cpu_time_used) / 1000);\n+\n+\t/* Insertion rate for all rules in one core */\n+\tprintf(\":: Port %d :: Core %d Meter %s :: start @[%d] - end @[%d],\"\n+\t\t\" use:%.02fs, rate:%.02fk Rule/Sec\\n\",\n+\t\tport_id, core_id, ops == METER_CREATE ? \"create\" : \"delete\",\n+\t\tstart_counter, end_counter - 1,\n+\t\tcpu_time_used, insertion_rate);\n+\n+\tif (ops == METER_CREATE)\n+\t\tmc_pool.create_meter.insertion[port_id][core_id]\n+\t\t\t= cpu_time_used;\n+\telse\n+\t\tmc_pool.create_meter.deletion[port_id][core_id]\n+\t\t\t= cpu_time_used;\n+}\n+\n+static void\n+destroy_meter_profile(void)\n+{\n+\tstruct rte_mtr_error error;\n+\tuint16_t nr_ports;\n+\tint port_id;\n+\n+\tnr_ports = rte_eth_dev_count_avail();\n+\tfor (port_id = 0; port_id < nr_ports; port_id++) {\n+\t\t/* If port outside portmask */\n+\t\tif (!((ports_mask >> port_id) & 0x1))\n+\t\t\tcontinue;\n+\n+\t\tif (rte_mtr_meter_profile_delete\n+\t\t\t(port_id, DEFAULT_METER_PROF_ID, &error)) {\n+\t\t\tprintf(\"Port %u del profile error(%d) message: %s\\n\",\n+\t\t\t\tport_id, error.type,\n+\t\t\t\terror.message ? error.message : \"(no stated reason)\");\n+\t\t\trte_exit(EXIT_FAILURE, \"Error: Destroy meter profile Failed!\\n\");\n+\t\t}\n+\t}\n+}\n+\n+static void\n+create_meter_profile(void)\n+{\n+\tuint16_t nr_ports;\n+\tint ret, port_id;\n+\tstruct rte_mtr_meter_profile mp;\n+\tstruct rte_mtr_error error;\n+\n+\t/*\n+\t *currently , only create one meter file for one port\n+\t *1 meter profile -> N meter rules -> N rte flows\n+\t */\n+\tmemset(&mp, 0, sizeof(struct rte_mtr_meter_profile));\n+\tnr_ports = rte_eth_dev_count_avail();\n+\tfor (port_id = 0; port_id < nr_ports; port_id++) {\n+\t\t/* If port outside portmask */\n+\t\tif (!((ports_mask >> port_id) & 0x1))\n+\t\t\tcontinue;\n+\n+\t\tmp.alg = RTE_MTR_SRTCM_RFC2697;\n+\t\tmp.srtcm_rfc2697.cir = METER_CIR;\n+\t\tmp.srtcm_rfc2697.cbs = METER_CIR / 8;\n+\t\tmp.srtcm_rfc2697.ebs = 0;\n+\n+\t\tret = rte_mtr_meter_profile_add\n+\t\t\t(port_id, DEFAULT_METER_PROF_ID, &mp, &error);\n+\t\tif (ret != 0) {\n+\t\t\tprintf(\"Port %u create Profile error(%d) message: %s\\n\",\n+\t\t\t\tport_id, error.type,\n+\t\t\t\terror.message ? error.message : \"(no stated reason)\");\n+\t\t\trte_exit(EXIT_FAILURE, \"Error: Creation meter profile Failed!\\n\");\n+\t\t}\n+\t}\n+}\n+\n static inline void\n destroy_flows(int port_id, uint8_t core_id, struct rte_flow **flows_list)\n {\n@@ -893,6 +1085,9 @@ struct multi_cores_pool {\n \tint rules_count_per_core;\n \n \trules_count_per_core = rules_count / mc_pool.cores_count;\n+\t/* If group > 0 , should add 1 flow which created in group 0 */\n+\tif (flow_group > 0 && core_id == 0)\n+\t\trules_count_per_core++;\n \n \tstart_batch = rte_rdtsc();\n \tfor (i = 0; i < (uint32_t) rules_count_per_core; i++) {\n@@ -1064,14 +1259,19 @@ struct multi_cores_pool {\n \n \t\t/* Insertion part. */\n \t\tmc_pool.last_alloc[core_id] = (int64_t)dump_socket_mem(stdout);\n+\t\tif (has_meter())\n+\t\t\tmeters_handler(port_id, core_id, METER_CREATE);\n \t\tflows_list = insert_flows(port_id, core_id);\n \t\tif (flows_list == NULL)\n \t\t\trte_exit(EXIT_FAILURE, \"Error: Insertion Failed!\\n\");\n \t\tmc_pool.current_alloc[core_id] = (int64_t)dump_socket_mem(stdout);\n \n \t\t/* Deletion part. */\n-\t\tif (delete_flag)\n+\t\tif (delete_flag) {\n \t\t\tdestroy_flows(port_id, core_id, flows_list);\n+\t\t\tif (has_meter())\n+\t\t\t\tmeters_handler(port_id, core_id, METER_DELETE);\n+\t\t}\n \t}\n }\n \n@@ -1230,7 +1430,9 @@ struct multi_cores_pool {\n \trte_eal_mp_wait_lcore();\n \n \tRTE_ETH_FOREACH_DEV(port) {\n-\n+\t\tif (has_meter())\n+\t\t\tdump_used_cpu_time(\"Meters:\",\n+\t\t\t\tport, &mc_pool.create_meter);\n \t\tdump_used_cpu_time(\"Flows:\",\n \t\t\tport, &mc_pool.create_flow);\n \t\tdump_used_mem(port);\n@@ -1679,12 +1881,16 @@ struct multi_cores_pool {\n \n \tprintf(\":: Flows Count per port: %d\\n\\n\", rules_count);\n \n+\tif (has_meter())\n+\t\tcreate_meter_profile();\n \trte_eal_mp_remote_launch(run_rte_flow_handler_cores, NULL, CALL_MAIN);\n \n \tif (enable_fwd) {\n \t\tinit_lcore_info();\n \t\trte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MAIN);\n \t}\n+\tif (has_meter() && delete_flag)\n+\t\tdestroy_meter_profile();\n \n \tRTE_ETH_FOREACH_DEV(port) {\n \t\trte_flow_flush(port, &error);\ndiff --git a/doc/guides/tools/flow-perf.rst b/doc/guides/tools/flow-perf.rst\nindex 40d157e..017e200 100644\n--- a/doc/guides/tools/flow-perf.rst\n+++ b/doc/guides/tools/flow-perf.rst\n@@ -345,3 +345,7 @@ Actions:\n \n *\t``--vxlan-decap``\n \tAdd vxlan decap action to all flows actions.\n+\n+*       ``--meter``\n+        Add meter action to all flows actions.\n+        Currently, 1 meter profile -> N meter rules -> N rte flows.\n",
    "prefixes": [
        "v2",
        "2/2"
    ]
}