From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C8C2BA0548; Thu, 11 Nov 2021 15:24:10 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0790741160; Thu, 11 Nov 2021 15:24:04 +0100 (CET) Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2040.outbound.protection.outlook.com [40.107.244.40]) by mails.dpdk.org (Postfix) with ESMTP id 9AAD64115E for ; Thu, 11 Nov 2021 15:24:02 +0100 (CET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MAF7xbUdft8yOvEphPOPv2Ar4Yb+KqpJo5Pemy+6qnQi1CJOMpf+btktvGz6PRSa5BPG4hRBViaJT1vVnEReOrX23hRtB6Z/3+TmFWCXWHR7rul0QD1cqpaLHx//SSZRa0jTmeCf1GeCjXS3FiFPlFRnR63s1LgFZPt6lsv23WyoWjAplNR62MV2KH9ox4zwb+0DFN2etJVECWv/5H58tix5Wc+wiD4MDlOlNxFdVdwSmrvrk95Ze6Lfc0KtSVu37jZTHmGGRv6yg/EOBQTMTLvtXfJoQEO+JSZ9XQpxFtA3KguN8QH9BB/TqmSR3yhFwRyWSeP1FEFEYbYTHSA5Dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6khPr0QIFNPZ8gBG8HhYx5q+6APCB44Hs/rat82WCKo=; b=alGq4yLnEovoRS7Y7QFhbBH1TarKVgJheOSzLlaVqkJJVBCkZygSEugRuVfeAyAu7UkCoNHRLM1yUlBTL577EitIAbEsu6Ycw2SW9ZDuXaRdLK4A/eN+ToJVk0MMyqulHEAvOeNkKou7sabbI4IvpKbazHJzuAE9E86v1+AK1YECmyygWCH8wPWo7jU8tmSVXQ9kkULUkvMEQ2qdAD2AkWwvXLm6dtycbFBN30qwATElDICeod1NxMTnoRLP41XB+3JNYR2HPXELdnOFWc+OldpGLxlh60gx4mS+dUqhsYJ5HRiZ01AIC16I0/zHvh6BENAse8JbqozazZbMxbCwOg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) smtp.rcpttodomain=dpdk.org smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6khPr0QIFNPZ8gBG8HhYx5q+6APCB44Hs/rat82WCKo=; b=lO8gSi8vhQXqWGeILTXDkke0NIWyyOuT4Y3xLS1WLmwsvrZ8HWocG3DPJ8A2XBYL3S8I6ycB+aee5KYKSUHolaXTB3IHeBxC9WnE9Wvj73DzL1v7PN0nPdxPYvY2bN7wJnN/V1G7vCUh53haNYt7MY52/NmkYl5DrNfBPpJRdT6kQo75HT0p/W6+rHMt/jq0fbYGfCeBYFtToJYjvTd81sEUTE382QqSt+k/qV6vZYHE7lDXABmHfgrWRKQaZyQBrhRF984ykoQA3kvwmKJTd2fdfWzlGk+LE6v6GGi6Jg5UrSaGqcDv3S0t7kTzJGz86vTBDdISHl0omRZSf9+iAA== Received: from DM5PR07CA0158.namprd07.prod.outlook.com (2603:10b6:3:ee::24) by SN6PR12MB2846.namprd12.prod.outlook.com (2603:10b6:805:70::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.16; Thu, 11 Nov 2021 14:24:00 +0000 Received: from DM6NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:3:ee:cafe::37) by DM5PR07CA0158.outlook.office365.com (2603:10b6:3:ee::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4690.19 via Frontend Transport; Thu, 11 Nov 2021 14:24:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by DM6NAM11FT034.mail.protection.outlook.com (10.13.173.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4690.15 via Frontend Transport; Thu, 11 Nov 2021 14:24:00 +0000 Received: from nvidia.com (172.20.187.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Thu, 11 Nov 2021 14:23:57 +0000 From: Rongwei Liu To: , , , , Wisam Jaddo CC: , , Haifei Luo , Jiawei Wang Subject: [PATCH v9 2/5] app/flow-perf: support meter policy API Date: Thu, 11 Nov 2021 16:23:37 +0200 Message-ID: <20211111142340.2209292-3-rongweil@nvidia.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211111142340.2209292-1-rongweil@nvidia.com> References: <6177033.fEpqbVaury@thomas> <20211111142340.2209292-1-rongweil@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.20.187.6] X-ClientProxiedBy: HQMAIL111.nvidia.com (172.20.187.18) To HQMAIL107.nvidia.com (172.20.187.13) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 81d80bd0-5e19-498c-f520-08d9a51ee793 X-MS-TrafficTypeDiagnostic: SN6PR12MB2846: X-LD-Processed: 43083d15-7273-40c1-b7db-39efd9ccc17a,ExtAddr X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:186; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U9UNn+CFUAKlFfHGMB1ivIRWcLNOpNYTVq1jiJQORKd2ngfVgOZAvkICEO9gsmLYWoxqrN3xoh6dWQYHHHn7e4JGtvGMTF9uTdSuNPldAH/AMbRslD0DIJps7mRFACB78EBbIFF+A0RP7dCh3+5nNHn8sY5KUBth4DIkKwOWUFbzntrjmI4jE4NXg0X/nRbbSqFBlXDUNmmIRbROSu/8vKi/Pgl5dhGZFMIkSZ/o3La+t0tUHYu6pUn6eXxLGWLet0HJRxquYRhFOJlo8i8cHDGF5X2l+QFFpwGXUFixJ4sBtef0rFU1JpS/9nB5evVAUOzL18XUoJ6orD7aYzZrVnJ5Mzd5W69jn661TRDAtVYJwDvDjQyyt+IJzLffRPzqvA3LrP2B417GQHiPJcNZOUAo1ilW7Lr99kjzJESoo5vnD5irgwE4wfMs0JUZkOMtv9B1m2JeTWOM3qZEqcgzT22fDgmcCYOKX8JU0uZk09djqIHMc7tHGNGXFlJ+xaHIpF/8UbLYJkNzST45d6YeAicfOf7zmjj+F8EHwDY4/eARaJytloCjf/20UVpZgQi6orD39QigfKrnFBcvTfUn0c0AAG/hCDCcKuwtKKpHP/8oaw/USX1yVeNERStSecf2lldwUMwYHp5zULRQhoK9EScYCxBYUgUAUqKs0tadBcqfmTOSoG9u/NJtCoOglsEE1YL+wX4iFL8qnxRkhH9ZeQ== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(36840700001)(46966006)(26005)(36756003)(426003)(186003)(107886003)(16526019)(8936002)(5660300002)(1076003)(82310400003)(7636003)(6636002)(83380400001)(47076005)(356005)(7696005)(4326008)(54906003)(110136005)(36860700001)(70206006)(316002)(508600001)(55016002)(336012)(8676002)(36906005)(86362001)(2616005)(6286002)(70586007)(2906002)(6666004); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2021 14:24:00.0892 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 81d80bd0-5e19-498c-f520-08d9a51ee793 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR12MB2846 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add option "policy-mtr" to indicate if meter creation will include policy or not. Meter creation will keep unchanged without it. With "policy-mtr", the policy is introduced. API create_meter_policy is to create a policy. API create_meter_rule will use it to create a meter. The value of it is used to specify meter policy actions. Signed-off-by: Haifei Luo Signed-off-by: Jiawei Wang Signed-off-by: Rongwei Liu --- app/test-flow-perf/main.c | 142 ++++++++++++++++++++++++++++++--- doc/guides/tools/flow-perf.rst | 4 + 2 files changed, 134 insertions(+), 12 deletions(-) diff --git a/app/test-flow-perf/main.c b/app/test-flow-perf/main.c index 42d13ec495..89596eb3f6 100644 --- a/app/test-flow-perf/main.c +++ b/app/test-flow-perf/main.c @@ -37,6 +37,7 @@ #include #include "config.h" +#include "actions_gen.h" #include "flow_gen.h" #define MAX_BATCHES_COUNT 100 @@ -49,10 +50,13 @@ static uint8_t flow_group; static uint64_t encap_data; static uint64_t decap_data; +static uint64_t all_actions[RTE_COLORS][MAX_ACTIONS_NUM]; +static char *actions_str[RTE_COLORS]; static uint64_t flow_items[MAX_ITEMS_NUM]; static uint64_t flow_actions[MAX_ACTIONS_NUM]; static uint64_t flow_attrs[MAX_ATTRS_NUM]; +static uint32_t policy_id[MAX_PORTS]; static uint8_t items_idx, actions_idx, attrs_idx; static uint64_t ports_mask; @@ -63,6 +67,7 @@ static bool delete_flag; static bool dump_socket_mem_flag; static bool enable_fwd; static bool unique_data; +static bool policy_mtr; static uint8_t rx_queues_count; static uint8_t tx_queues_count; @@ -560,6 +565,8 @@ usage(char *progname) "ipv6 dscp value to be set is random each flow\n"); printf(" --flag: add flag action to flow actions\n"); printf(" --meter: add meter action to flow actions\n"); + printf(" --policy-mtr=\"g1,g2:y1:r1\": to create meter with specified " + "colored actions\n"); printf(" --raw-encap=: add raw encap action to flow actions\n" "Data is the data needed to be encaped\n" "Example: raw-encap=ether,ipv4,udp,vxlan\n"); @@ -572,6 +579,45 @@ usage(char *progname) printf(" --vxlan-decap: add vxlan_decap action to flow actions\n"); } +static void +read_meter_policy(char *prog, char *arg) +{ + char *token; + size_t i, j, k; + + j = 0; + k = 0; + policy_mtr = true; + token = strsep(&arg, ":\0"); + while (token != NULL && j < RTE_COLORS) { + actions_str[j++] = token; + token = strsep(&arg, ":\0"); + } + j = 0; + token = strtok(actions_str[0], ",\0"); + while (token == NULL && j < RTE_COLORS - 1) + token = strtok(actions_str[++j], ",\0"); + while (j < RTE_COLORS && token != NULL) { + for (i = 0; i < RTE_DIM(flow_options); i++) { + if (!strcmp(token, flow_options[i].str)) { + all_actions[j][k++] = flow_options[i].mask; + break; + } + } + /* Reached last action with no match */ + if (i >= RTE_DIM(flow_options)) { + fprintf(stderr, "Invalid colored actions: %s\n", token); + usage(prog); + rte_exit(EXIT_SUCCESS, "Invalid colored actions\n"); + } + token = strtok(NULL, ",\0"); + while (!token && j < RTE_COLORS - 1) { + token = strtok(actions_str[++j], ",\0"); + k = 0; + } + } +} + static void args_parse(int argc, char **argv) { @@ -660,6 +706,7 @@ args_parse(int argc, char **argv) { "raw-decap", 1, 0, 0 }, { "vxlan-encap", 0, 0, 0 }, { "vxlan-decap", 0, 0, 0 }, + { "policy-mtr", 1, 0, 0 }, }; RTE_ETH_FOREACH_DEV(i) @@ -877,6 +924,8 @@ args_parse(int argc, char **argv) RTE_MAX_LCORE); } } + if (strcmp(lgopts[opt_idx].name, "policy-mtr") == 0) + read_meter_policy(argv[0], optarg); break; default: usage(argv[0]); @@ -981,7 +1030,6 @@ print_rules_batches(double *cpu_time_per_batch) } } - static inline int has_meter(void) { @@ -997,12 +1045,66 @@ has_meter(void) return 0; } +static void +create_meter_policy(void) +{ + struct rte_mtr_error error; + int ret, port_id; + struct rte_mtr_meter_policy_params policy; + uint16_t nr_ports; + struct rte_flow_action actions[RTE_COLORS][MAX_ACTIONS_NUM]; + int i; + + memset(actions, 0, sizeof(actions)); + memset(&policy, 0, sizeof(policy)); + nr_ports = rte_eth_dev_count_avail(); + for (port_id = 0; port_id < nr_ports; port_id++) { + for (i = 0; i < RTE_COLORS; i++) + fill_actions(actions[i], all_actions[i], 0, 0, 0, + 0, 0, 0, unique_data, rx_queues_count, + dst_ports[port_id]); + policy.actions[RTE_COLOR_GREEN] = actions[RTE_COLOR_GREEN]; + policy.actions[RTE_COLOR_YELLOW] = actions[RTE_COLOR_YELLOW]; + policy.actions[RTE_COLOR_RED] = actions[RTE_COLOR_RED]; + policy_id[port_id] = port_id + 10; + ret = rte_mtr_meter_policy_add(port_id, policy_id[port_id], + &policy, &error); + if (ret) { + fprintf(stderr, "port %d: failed to create meter policy\n", + port_id); + policy_id[port_id] = UINT32_MAX; + } + memset(actions, 0, sizeof(actions)); + } +} + +static void +destroy_meter_policy(void) +{ + struct rte_mtr_error error; + uint16_t nr_ports; + int port_id; + + nr_ports = rte_eth_dev_count_avail(); + for (port_id = 0; port_id < nr_ports; port_id++) { + /* If port outside portmask */ + if (!((ports_mask >> port_id) & 0x1)) + continue; + + if (rte_mtr_meter_policy_delete + (port_id, policy_id[port_id], &error)) { + fprintf(stderr, "port %u: failed to delete meter policy\n", + port_id); + rte_exit(EXIT_FAILURE, "Error: Failed to delete meter policy.\n"); + } + } +} + static void create_meter_rule(int port_id, uint32_t counter) { int ret; struct rte_mtr_params params; - uint32_t default_prof_id = 100; struct rte_mtr_error error; memset(¶ms, 0, sizeof(struct rte_mtr_params)); @@ -1012,8 +1114,15 @@ create_meter_rule(int port_id, uint32_t counter) params.dscp_table = NULL; /*create meter*/ - params.meter_profile_id = default_prof_id; - ret = rte_mtr_create(port_id, counter, ¶ms, 1, &error); + params.meter_profile_id = DEFAULT_METER_PROF_ID; + + if (!policy_mtr) { + ret = rte_mtr_create(port_id, counter, ¶ms, 1, &error); + } else { + params.meter_policy_id = policy_id[port_id]; + ret = rte_mtr_create(port_id, counter, ¶ms, 0, &error); + } + if (ret != 0) { printf("Port %u create meter idx(%d) error(%d) message: %s\n", port_id, counter, error.type, @@ -1027,11 +1136,16 @@ destroy_meter_rule(int port_id, uint32_t counter) { struct rte_mtr_error error; + if (policy_mtr && policy_id[port_id] != UINT32_MAX) { + if (rte_mtr_meter_policy_delete(port_id, policy_id[port_id], + &error)) + fprintf(stderr, "Error: Failed to delete meter policy\n"); + policy_id[port_id] = UINT32_MAX; + } if (rte_mtr_destroy(port_id, counter, &error)) { - printf("Port %u destroy meter(%d) error(%d) message: %s\n", - port_id, counter, error.type, - error.message ? error.message : "(no stated reason)"); - rte_exit(EXIT_FAILURE, "Error in deleting meter rule\n"); + fprintf(stderr, "Port %d: Failed to delete meter.\n", + port_id); + rte_exit(EXIT_FAILURE, "Error in deleting meter rule"); } } @@ -1136,12 +1250,10 @@ create_meter_profile(void) /* If port outside portmask */ if (!((ports_mask >> port_id) & 0x1)) continue; - mp.alg = RTE_MTR_SRTCM_RFC2697; mp.srtcm_rfc2697.cir = METER_CIR; mp.srtcm_rfc2697.cbs = METER_CIR / 8; mp.srtcm_rfc2697.ebs = 0; - ret = rte_mtr_meter_profile_add (port_id, DEFAULT_METER_PROF_ID, &mp, &error); if (ret != 0) { @@ -2012,16 +2124,22 @@ main(int argc, char **argv) rte_srand(rand_seed); - if (has_meter()) + if (has_meter()) { create_meter_profile(); + if (policy_mtr) + create_meter_policy(); + } rte_eal_mp_remote_launch(run_rte_flow_handler_cores, NULL, CALL_MAIN); if (enable_fwd) { init_lcore_info(); rte_eal_mp_remote_launch(start_forwarding, NULL, CALL_MAIN); } - if (has_meter() && delete_flag) + if (has_meter() && delete_flag) { destroy_meter_profile(); + if (policy_mtr) + destroy_meter_policy(); + } RTE_ETH_FOREACH_DEV(port) { rte_flow_flush(port, &error); diff --git a/doc/guides/tools/flow-perf.rst b/doc/guides/tools/flow-perf.rst index 7d986f0158..e4083f053e 100644 --- a/doc/guides/tools/flow-perf.rst +++ b/doc/guides/tools/flow-perf.rst @@ -384,6 +384,10 @@ Actions: * ``--vxlan-decap`` Add vxlan decap action to all flows actions. +* ``--policy-mtr=`` + Add policy-mtr to create meter with policy and specify policy actions. + Example: policy-mtr=rss,mark::drop + * ``--meter`` Add meter action to all flows actions. Currently, 1 meter profile -> N meter rules -> N rte flows. -- 2.27.0