From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id AAA8D1B729 for ; Mon, 16 Oct 2017 20:18:06 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Oct 2017 11:18:05 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,387,1503385200"; d="scan'208";a="1231425791" Received: from irsmsx152.ger.corp.intel.com ([163.33.192.66]) by fmsmga002.fm.intel.com with ESMTP; 16 Oct 2017 11:18:04 -0700 Received: from irsmsx103.ger.corp.intel.com ([169.254.3.49]) by IRSMSX152.ger.corp.intel.com ([169.254.6.87]) with mapi id 14.03.0319.002; Mon, 16 Oct 2017 19:18:03 +0100 From: "Singh, Jasvinder" To: "Wu, Jingjing" , "dev@dpdk.org" CC: "Dumitrescu, Cristian" , "Pei, Yulong" Thread-Topic: [PATCH v9 3/3] app/test-pmd: add CLI for TM nodes and hierarchy commit Thread-Index: AQHTRmgRubBWVoyGJ0ObOdB31nRnlqLmxayg Date: Mon, 16 Oct 2017 18:18:02 +0000 Message-ID: <54CBAA185211B4429112C315DA58FF6D3326F551@IRSMSX103.ger.corp.intel.com> References: <20171013170000.26118-1-jasvinder.singh@intel.com> <20171014102025.101462-1-jasvinder.singh@intel.com> <20171014102025.101462-3-jasvinder.singh@intel.com> <9BB6961774997848B5B42BEC655768F810E96EBB@SHSMSX103.ccr.corp.intel.com> In-Reply-To: <9BB6961774997848B5B42BEC655768F810E96EBB@SHSMSX103.ccr.corp.intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiYzQxNjQ4ZDUtZmQ0MS00Yjg1LWI1YjItNWM4MmMyMTU4ZTg5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE2LjUuOS4zIiwiVHJ1c3RlZExhYmVsSGFzaCI6Ik9HbHdMcUxMQ0ZFWU1pXC9nTEh3a0wyQjY2em5RdXFYZ0VVbk9STFpQYlJNPSJ9 x-ctpclassification: CTP_IC dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [163.33.239.180] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v9 3/3] app/test-pmd: add CLI for TM nodes and hierarchy commit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Oct 2017 18:18:07 -0000 > > diff --git a/app/test-pmd/cmdline_tm.c b/app/test-pmd/cmdline_tm.c > > index 38048ae..002209c 100644 > > --- a/app/test-pmd/cmdline_tm.c > > +++ b/app/test-pmd/cmdline_tm.c > > @@ -42,6 +42,17 @@ > > #include "testpmd.h" > > #include "cmdline_tm.h" > > > > +#define PARSE_DELIMITER " \f\n\r\t\v" > > +#define MAX_NUM_SHARED_SHAPERS 256 > > + > > +#define skip_white_spaces(pos) \ > > +({ \ > > + __typeof__(pos) _p =3D (pos); \ > > + for ( ; isspace(*_p); _p++) \ > > + ; \ > > + _p; \ > > +}) > > + > > /** Display TM Error Message */ > > static void > > print_err_msg(struct rte_tm_error *error) @@ -118,6 +129,100 @@ > > print_err_msg(struct rte_tm_error *error) > > error->type); > > } > > > > +static int > > +read_uint64(uint64_t *value, const char *p) { > > + char *next; > > + uint64_t val; > > + > > + p =3D skip_white_spaces(p); > > + if (!isdigit(*p)) > > + return -EINVAL; > > + > > + val =3D strtoul(p, &next, 10); > > + if (p =3D=3D next) > > + return -EINVAL; > > + > > + p =3D next; > > + switch (*p) { > > + case 'T': > > + val *=3D 1024ULL; > > + /* fall through */ > > + case 'G': > > + val *=3D 1024ULL; > > + /* fall through */ > > + case 'M': > > + val *=3D 1024ULL; > > + /* fall through */ > > + case 'k': > > + case 'K': > > + val *=3D 1024ULL; > > + p++; > > + break; > > + } > > + > > + p =3D skip_white_spaces(p); > > + if (*p !=3D '\0') > > + return -EINVAL; > > + > > + *value =3D val; > > + return 0; > > +} > > + > > +static int > > +read_uint32(uint32_t *value, const char *p) { > > + uint64_t val =3D 0; > > + int ret =3D read_uint64(&val, p); > > + > > + if (ret < 0) > > + return ret; > > + > > + if (val > UINT32_MAX) > > + return -ERANGE; > > + > > + *value =3D val; > > + return 0; > > +} > > + > > +static int > > +parse_multi_ss_id_str(char *s_str, uint32_t *n_ssp, uint32_t > > +shaper_id[]) { > > + uint32_t n_shared_shapers =3D 0, i =3D 0; > > + char *token; > > + > > + /* First token: num of shared shapers */ > > + token =3D strtok_r(s_str, PARSE_DELIMITER, &s_str); > > + if (token =3D=3D NULL) > > + return -1; > > + > > + if (read_uint32(&n_shared_shapers, token)) > > + return -1; > > + > > + /* Check: num of shared shaper */ > > + if (n_shared_shapers >=3D MAX_NUM_SHARED_SHAPERS) { > > + printf(" Number of shared shapers exceed the max > (error)\n"); > > + return -1; > > + } > > + > > + /* Parse shared shaper ids */ > > + while (1) { > > + token =3D strtok_r(s_str, PARSE_DELIMITER, &s_str); > > + if ((token !=3D NULL && n_shared_shapers =3D=3D 0) || > > + (token =3D=3D NULL && i < n_shared_shapers)) > > + return -1; > > + > > + if (token =3D=3D NULL) > > + break; > > + > > + if (read_uint32(&shaper_id[i], token)) > > + return -1; > > + i++; > > + } > > + *n_ssp =3D n_shared_shapers; > > + > > + return 0; > > +} >=20 > Thanks for the change, can those be done by rte_strsplit? On CLI, user can inadvertently press tab, etc., instead of space character = while specifying the cli arguments. The above approach is robust to such i= ncidents by allowing range of characters to be used as delim. On the other = hand, rte_strsplit() allows only one character to be used as delim and rest= ricts the user to specify only that character on CLI. > > /* *** Port TM Capability *** */ > > struct cmd_show_port_tm_cap_result { > > cmdline_fixed_string_t show; > > @@ -1410,3 +1515,549 @@ cmdline_parse_inst_t > > cmd_set_port_tm_node_shaper_profile =3D { > > NULL, > > }, > > }; > > + > > +/* *** Add Port TM nonleaf node *** */ struct > > +cmd_add_port_tm_nonleaf_node_result { > > + cmdline_fixed_string_t add; > > + cmdline_fixed_string_t port; > > + cmdline_fixed_string_t tm; > > + cmdline_fixed_string_t nonleaf; > > + cmdline_fixed_string_t node; > > + uint16_t port_id; > > + uint32_t node_id; > > + int32_t parent_node_id; > > + uint32_t priority; > > + uint32_t weight; > > + uint32_t level_id; > > + uint32_t shaper_profile_id; > > + uint32_t n_sp_priorities; > > + uint64_t stats_mask; > > + cmdline_multi_string_t multi_shared_shaper_id; }; > > + > > +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_nonleaf_node_result, add, "add"); > > +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_nonleaf_node_result, port, "port"); > > +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_nonleaf_node_result, tm, "tm"); > > +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf > =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_nonleaf_node_result, nonleaf, > > "nonleaf"); > > +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_nonleaf_node_result, node, > "node"); > > +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id =3D > > + TOKEN_NUM_INITIALIZER( > > + struct cmd_add_port_tm_nonleaf_node_result, > > + port_id, UINT16); > > +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id > =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + node_id, UINT32); > > +cmdline_parse_token_num_t > > cmd_add_port_tm_nonleaf_node_parent_node_id =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + parent_node_id, INT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + priority, UINT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + weight, UINT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id > =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + level_id, UINT32); > > +cmdline_parse_token_num_t > > cmd_add_port_tm_nonleaf_node_shaper_profile_id =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + shaper_profile_id, UINT32); > > +cmdline_parse_token_num_t > > cmd_add_port_tm_nonleaf_node_n_sp_priorities =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + n_sp_priorities, UINT32); > > +cmdline_parse_token_num_t > cmd_add_port_tm_nonleaf_node_stats_mask =3D > > + TOKEN_NUM_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + stats_mask, UINT64); > > +cmdline_parse_token_string_t > > + cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id =3D > > + TOKEN_STRING_INITIALIZER(struct > > cmd_add_port_tm_nonleaf_node_result, > > + multi_shared_shaper_id, TOKEN_STRING_MULTI); > > + > > +static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result, > > + __attribute__((unused)) struct cmdline *cl, > > + __attribute__((unused)) void *data) > > +{ > > + struct cmd_add_port_tm_nonleaf_node_result *res =3D parsed_result; > > + struct rte_tm_error error; > > + struct rte_tm_node_params np; > > + uint32_t *shared_shaper_id; > > + uint32_t parent_node_id, n_shared_shapers =3D 0; > > + char *s_str =3D res->multi_shared_shaper_id; > > + portid_t port_id =3D res->port_id; > > + int ret; > > + > > + if (port_id_is_invalid(port_id, ENABLED_WARN)) > > + return; > > + > > + /* Port status */ > > + if (port_is_started(port_id)) { > > + printf(" Port %u not stopped (error)\n", port_id); > > + return; > > + } > > + > > + memset(&np, 0, sizeof(struct rte_tm_node_params)); > > + > > + /* Node parameters */ > > + if (res->parent_node_id < 0) > > + parent_node_id =3D UINT32_MAX; > > + else > > + parent_node_id =3D res->parent_node_id; > > + > > + shared_shaper_id =3D (uint32_t > *)malloc(MAX_NUM_SHARED_SHAPERS > > * > > + sizeof(uint32_t)); > > + /* Parse multi shared shaper id string */ > > + ret =3D parse_multi_ss_id_str(s_str, &n_shared_shapers, > > shared_shaper_id); > > + if (ret) { > > + printf(" Shared shapers params string parse error\n"); > > + return; >=20 > You forgot to free shared_shaper_id. >=20 > > + } > > + > > + np.shaper_profile_id =3D res->shaper_profile_id; > > + np.n_shared_shapers =3D n_shared_shapers; > > + if (np.n_shared_shapers) > > + np.shared_shaper_id =3D &shared_shaper_id[0]; > > + else > > + np.shared_shaper_id =3D NULL; > > + > > + np.nonleaf.n_sp_priorities =3D res->n_sp_priorities; > > + np.stats_mask =3D res->stats_mask; > > + np.nonleaf.wfq_weight_mode =3D NULL; > > + > > + ret =3D rte_tm_node_add(port_id, res->node_id, parent_node_id, > > + res->priority, res->weight, res->level_id, > > + &np, &error); > > + if (ret !=3D 0) { > > + print_err_msg(&error); > > + return; > > + } >=20 > You forgot to free shared_shaper_id. >=20 > > +} > > + > > +cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node =3D { > > + .f =3D cmd_add_port_tm_nonleaf_node_parsed, > > + .data =3D NULL, > > + .help_str =3D "Add port tm nonleaf node", > > + .tokens =3D { > > + (void *)&cmd_add_port_tm_nonleaf_node_add, > > + (void *)&cmd_add_port_tm_nonleaf_node_port, > > + (void *)&cmd_add_port_tm_nonleaf_node_tm, > > + (void *)&cmd_add_port_tm_nonleaf_node_nonleaf, > > + (void *)&cmd_add_port_tm_nonleaf_node_node, > > + (void *)&cmd_add_port_tm_nonleaf_node_port_id, > > + (void *)&cmd_add_port_tm_nonleaf_node_node_id, > > + (void *)&cmd_add_port_tm_nonleaf_node_parent_node_id, > > + (void *)&cmd_add_port_tm_nonleaf_node_priority, > > + (void *)&cmd_add_port_tm_nonleaf_node_weight, > > + (void *)&cmd_add_port_tm_nonleaf_node_level_id, > > + (void > *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id, > > + (void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities, > > + (void *)&cmd_add_port_tm_nonleaf_node_stats_mask, > > + (void > > *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id, > > + NULL, > > + }, > > +}; > > + > > +/* *** Add Port TM leaf node *** */ > > +struct cmd_add_port_tm_leaf_node_result { > > + cmdline_fixed_string_t add; > > + cmdline_fixed_string_t port; > > + cmdline_fixed_string_t tm; > > + cmdline_fixed_string_t leaf; > > + cmdline_fixed_string_t node; > > + uint16_t port_id; > > + uint32_t node_id; > > + int32_t parent_node_id; > > + uint32_t priority; > > + uint32_t weight; > > + uint32_t level_id; > > + uint32_t shaper_profile_id; > > + uint32_t cman_mode; > > + uint32_t wred_profile_id; > > + uint64_t stats_mask; > > + cmdline_multi_string_t multi_shared_shaper_id; }; > > + > > +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_leaf_node_result, add, "add"); > > +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_leaf_node_result, port, "port"); > > +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_leaf_node_result, tm, "tm"); > > +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_leaf_node_result, leaf, "leaf"); > > +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node =3D > > + TOKEN_STRING_INITIALIZER( > > + struct cmd_add_port_tm_leaf_node_result, node, "node"); > > +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + port_id, UINT16); > > +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + node_id, UINT32); > > +cmdline_parse_token_num_t > cmd_add_port_tm_leaf_node_parent_node_id =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + parent_node_id, INT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + priority, UINT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + weight, UINT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + level_id, UINT32); > > +cmdline_parse_token_num_t > cmd_add_port_tm_leaf_node_shaper_profile_id > > =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + shaper_profile_id, UINT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode > =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + cman_mode, UINT32); > > +cmdline_parse_token_num_t > cmd_add_port_tm_leaf_node_wred_profile_id > > =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + wred_profile_id, UINT32); > > +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask =3D > > + TOKEN_NUM_INITIALIZER(struct > cmd_add_port_tm_leaf_node_result, > > + stats_mask, UINT64); > > +cmdline_parse_token_string_t > > + cmd_add_port_tm_leaf_node_multi_shared_shaper_id =3D > > + TOKEN_STRING_INITIALIZER(struct > > cmd_add_port_tm_leaf_node_result, > > + multi_shared_shaper_id, TOKEN_STRING_MULTI); > > + > > +static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result, > > + __attribute__((unused)) struct cmdline *cl, > > + __attribute__((unused)) void *data) > > +{ > > + struct cmd_add_port_tm_leaf_node_result *res =3D parsed_result; > > + struct rte_tm_error error; > > + struct rte_tm_node_params np; > > + uint32_t *shared_shaper_id; > > + uint32_t parent_node_id, n_shared_shapers =3D 0; > > + portid_t port_id =3D res->port_id; > > + char *s_str =3D res->multi_shared_shaper_id; > > + int ret; > > + > > + if (port_id_is_invalid(port_id, ENABLED_WARN)) > > + return; > > + > > + /* Port status */ > > + if (port_is_started(port_id)) { > > + printf(" Port %u not stopped (error)\n", port_id); > > + return; > > + } > > + > > + memset(&np, 0, sizeof(struct rte_tm_node_params)); > > + > > + /* Node parameters */ > > + if (res->parent_node_id < 0) > > + parent_node_id =3D UINT32_MAX; > > + else > > + parent_node_id =3D res->parent_node_id; > > + > > + shared_shaper_id =3D (uint32_t > *)malloc(MAX_NUM_SHARED_SHAPERS > > * > > + sizeof(uint32_t)); > > + /* Parse multi shared shaper id string */ > > + ret =3D parse_multi_ss_id_str(s_str, &n_shared_shapers, > > shared_shaper_id); > > + if (ret) { > > + printf(" Shared shapers params string parse error\n"); > The same, free the memory you malloced. Oops, will fix this in next version. Thanks.