From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id ED14E3237 for ; Fri, 5 Jun 2015 11:44:23 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 05 Jun 2015 02:44:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,558,1427785200"; d="scan'208";a="503168392" Received: from irsmsx153.ger.corp.intel.com ([163.33.192.75]) by FMSMGA003.fm.intel.com with ESMTP; 05 Jun 2015 02:44:22 -0700 Received: from irsmsx108.ger.corp.intel.com ([169.254.11.59]) by IRSMSX153.ger.corp.intel.com ([169.254.9.95]) with mapi id 14.03.0224.002; Fri, 5 Jun 2015 10:44:20 +0100 From: "Dumitrescu, Cristian" To: "Jastrzebski, MichalX K" , "dev@dpdk.org" Thread-Topic: [dpdk-dev] [PATCH] qos_sched: example modification to use librte_cfgfile Thread-Index: AQHQn3ITKZpAi/R9LEyiUnGt1yvO9J2dqVhg Date: Fri, 5 Jun 2015 09:44:19 +0000 Message-ID: <3EB4FA525960D640B5BDFFD6A3D8912632371B64@IRSMSX108.ger.corp.intel.com> References: <1433496497-2872-1-git-send-email-michalx.k.jastrzebski@intel.com> In-Reply-To: <1433496497-2872-1-git-send-email-michalx.k.jastrzebski@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [163.33.239.181] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Cc: "??cristian.dumitrescu@intel.com" Subject: Re: [dpdk-dev] [PATCH] qos_sched: example modification to use librte_cfgfile X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Jun 2015 09:44:24 -0000 > -----Original Message----- > From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Michal Jastrzebski > Sent: Friday, June 5, 2015 10:28 AM > To: dev@dpdk.org > Cc: ??cristian.dumitrescu@intel.com > Subject: [dpdk-dev] [PATCH] qos_sched: example modification to use > librte_cfgfile >=20 > This is a modification of qos_sched example to use > librte_cfgfile for parsing configuration file. >=20 > Signed-off-by: Michal Jastrzebski > --- > examples/qos_sched/cfg_file.c | 157 ++++++++++-------------------------= ------ > examples/qos_sched/cfg_file.h | 35 ++------- > examples/qos_sched/init.c | 14 ++-- > 3 files changed, 47 insertions(+), 159 deletions(-) >=20 > diff --git a/examples/qos_sched/cfg_file.c b/examples/qos_sched/cfg_file.= c > index 05a8caf..71ddabb 100644 > --- a/examples/qos_sched/cfg_file.c > +++ b/examples/qos_sched/cfg_file.c > @@ -233,92 +233,7 @@ int cfg_close(struct cfg_file *cfg) > } >=20 > int > -cfg_num_sections(struct cfg_file *cfg, const char *sectionname, size_t > length) > -{ > - int i; > - int num_sections =3D 0; > - for (i =3D 0; i < cfg->num_sections; i++) { > - if (strncmp(cfg->sections[i]->name, sectionname, length) =3D=3D > 0) > - num_sections++; > - } > - return num_sections; > -} > - > -int > -cfg_sections(struct cfg_file *cfg, char *sections[], int max_sections) > -{ > - int i; > - for (i =3D 0; i < cfg->num_sections && i < max_sections; i++) { > - snprintf(sections[i], CFG_NAME_LEN, "%s", cfg->sections[i]- > >name); > - } > - return i; > -} > - > -static const struct cfg_section * > -_get_section(struct cfg_file *cfg, const char *sectionname) > -{ > - int i; > - for (i =3D 0; i < cfg->num_sections; i++) { > - if (strncmp(cfg->sections[i]->name, sectionname, > - sizeof(cfg->sections[0]->name)) =3D=3D 0) > - return cfg->sections[i]; > - } > - return NULL; > -} > - > -int > -cfg_has_section(struct cfg_file *cfg, const char *sectionname) > -{ > - return (_get_section(cfg, sectionname) !=3D NULL); > -} > - > -int > -cfg_section_num_entries(struct cfg_file *cfg, const char *sectionname) > -{ > - const struct cfg_section *s =3D _get_section(cfg, sectionname); > - if (s =3D=3D NULL) > - return -1; > - return s->num_entries; > -} > - > - > -int > -cfg_section_entries(struct cfg_file *cfg, const char *sectionname, > - struct cfg_entry *entries, int max_entries) > -{ > - int i; > - const struct cfg_section *sect =3D _get_section(cfg, sectionname); > - if (sect =3D=3D NULL) > - return -1; > - for (i =3D 0; i < max_entries && i < sect->num_entries; i++) > - entries[i] =3D *sect->entries[i]; > - return i; > -} > - > -const char * > -cfg_get_entry(struct cfg_file *cfg, const char *sectionname, > - const char *entryname) > -{ > - int i; > - const struct cfg_section *sect =3D _get_section(cfg, sectionname); > - if (sect =3D=3D NULL) > - return NULL; > - for (i =3D 0; i < sect->num_entries; i++) > - if (strncmp(sect->entries[i]->name, entryname, > CFG_NAME_LEN) =3D=3D 0) > - return sect->entries[i]->value; > - return NULL; > -} > - > -int > -cfg_has_entry(struct cfg_file *cfg, const char *sectionname, > - const char *entryname) > -{ > - return (cfg_get_entry(cfg, sectionname, entryname) !=3D NULL); > -} > - > - > -int > -cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params > *port_params) > +cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params > *port_params) > { > const char *entry; > int j; > @@ -326,19 +241,19 @@ cfg_load_port(struct cfg_file *cfg, struct > rte_sched_port_params *port_params) > if (!cfg || !port_params) > return -1; >=20 > - entry =3D cfg_get_entry(cfg, "port", "frame overhead"); > + entry =3D rte_cfgfile_get_entry(cfg, "port", "frame overhead"); > if (entry) > port_params->frame_overhead =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, "port", "number of subports per port"); > + entry =3D rte_cfgfile_get_entry(cfg, "port", "number of subports per > port"); > if (entry) > port_params->n_subports_per_port =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, "port", "number of pipes per subport"); > + entry =3D rte_cfgfile_get_entry(cfg, "port", "number of pipes per > subport"); > if (entry) > port_params->n_pipes_per_subport =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, "port", "queue sizes"); > + entry =3D rte_cfgfile_get_entry(cfg, "port", "queue sizes"); > if (entry) { > char *next; >=20 > @@ -356,7 +271,7 @@ cfg_load_port(struct cfg_file *cfg, struct > rte_sched_port_params *port_params) >=20 > /* Parse WRED min thresholds */ > snprintf(str, sizeof(str), "tc %d wred min", j); > - entry =3D cfg_get_entry(cfg, "red", str); > + entry =3D rte_cfgfile_get_entry(cfg, "red", str); > if (entry) { > char *next; > int k; > @@ -372,7 +287,7 @@ cfg_load_port(struct cfg_file *cfg, struct > rte_sched_port_params *port_params) >=20 > /* Parse WRED max thresholds */ > snprintf(str, sizeof(str), "tc %d wred max", j); > - entry =3D cfg_get_entry(cfg, "red", str); > + entry =3D rte_cfgfile_get_entry(cfg, "red", str); > if (entry) { > char *next; > int k; > @@ -388,7 +303,7 @@ cfg_load_port(struct cfg_file *cfg, struct > rte_sched_port_params *port_params) >=20 > /* Parse WRED inverse mark probabilities */ > snprintf(str, sizeof(str), "tc %d wred inv prob", j); > - entry =3D cfg_get_entry(cfg, "red", str); > + entry =3D rte_cfgfile_get_entry(cfg, "red", str); > if (entry) { > char *next; > int k; > @@ -405,7 +320,7 @@ cfg_load_port(struct cfg_file *cfg, struct > rte_sched_port_params *port_params) >=20 > /* Parse WRED EWMA filter weights */ > snprintf(str, sizeof(str), "tc %d wred weight", j); > - entry =3D cfg_get_entry(cfg, "red", str); > + entry =3D rte_cfgfile_get_entry(cfg, "red", str); > if (entry) { > char *next; > int k; > @@ -425,7 +340,7 @@ cfg_load_port(struct cfg_file *cfg, struct > rte_sched_port_params *port_params) > } >=20 > int > -cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params > *pipe_params) > +cfg_load_pipe(struct rte_cfgfile *cfg, struct rte_sched_pipe_params > *pipe_params) > { > int i, j; > char *next; > @@ -435,48 +350,48 @@ cfg_load_pipe(struct cfg_file *cfg, struct > rte_sched_pipe_params *pipe_params) > if (!cfg || !pipe_params) > return -1; >=20 > - profiles =3D cfg_num_sections(cfg, "pipe profile", sizeof("pipe profile= ") > - 1); > + profiles =3D rte_cfgfile_num_sections(cfg, "pipe profile", sizeof("pipe > profile") - 1); > port_params.n_pipe_profiles =3D profiles; >=20 > for (j =3D 0; j < profiles; j++) { > char pipe_name[32]; > snprintf(pipe_name, sizeof(pipe_name), "pipe profile %d", > j); >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tb rate"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tb rate"); > if (entry) > pipe_params[j].tb_rate =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tb size"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tb size"); > if (entry) > pipe_params[j].tb_size =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tc period"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc period"); > if (entry) > pipe_params[j].tc_period =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 0 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 0 rate"); > if (entry) > pipe_params[j].tc_rate[0] =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 1 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 1 rate"); > if (entry) > pipe_params[j].tc_rate[1] =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 2 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 2 rate"); > if (entry) > pipe_params[j].tc_rate[2] =3D (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 3 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 rate"); > if (entry) > pipe_params[j].tc_rate[3] =3D (uint32_t)atoi(entry); >=20 > #ifdef RTE_SCHED_SUBPORT_TC_OV > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 3 oversubscription > weight"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 > oversubscription weight"); > if (entry) > pipe_params[j].tc_ov_weight =3D (uint8_t)atoi(entry); > #endif >=20 > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 0 wrr weights"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 0 wrr > weights"); > if (entry) { > for(i =3D 0; i < > RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) { >=20 > pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PI > PE*0 + i] =3D > @@ -486,7 +401,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct > rte_sched_pipe_params *pipe_params) > entry =3D next; > } > } > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 1 wrr weights"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 1 wrr > weights"); > if (entry) { > for(i =3D 0; i < > RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) { >=20 > pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PI > PE*1 + i] =3D > @@ -496,7 +411,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct > rte_sched_pipe_params *pipe_params) > entry =3D next; > } > } > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 2 wrr weights"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 2 wrr > weights"); > if (entry) { > for(i =3D 0; i < > RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) { >=20 > pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PI > PE*2 + i] =3D > @@ -506,7 +421,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct > rte_sched_pipe_params *pipe_params) > entry =3D next; > } > } > - entry =3D cfg_get_entry(cfg, pipe_name, "tc 3 wrr weights"); > + entry =3D rte_cfgfile_get_entry(cfg, pipe_name, "tc 3 wrr > weights"); > if (entry) { > for(i =3D 0; i < > RTE_SCHED_QUEUES_PER_TRAFFIC_CLASS; i++) { >=20 > pipe_params[j].wrr_weights[RTE_SCHED_TRAFFIC_CLASSES_PER_PI > PE*3 + i] =3D > @@ -521,7 +436,7 @@ cfg_load_pipe(struct cfg_file *cfg, struct > rte_sched_pipe_params *pipe_params) > } >=20 > int > -cfg_load_subport(struct cfg_file *cfg, struct rte_sched_subport_params > *subport_params) > +cfg_load_subport(struct rte_cfgfile *cfg, struct rte_sched_subport_param= s > *subport_params) > { > const char *entry; > int i, j, k; > @@ -535,39 +450,39 @@ cfg_load_subport(struct cfg_file *cfg, struct > rte_sched_subport_params *subport_ > char sec_name[CFG_NAME_LEN]; > snprintf(sec_name, sizeof(sec_name), "subport %d", i); >=20 > - if (cfg_has_section(cfg, sec_name)) { > - entry =3D cfg_get_entry(cfg, sec_name, "tb rate"); > + if (rte_cfgfile_has_section(cfg, sec_name)) { > + entry =3D rte_cfgfile_get_entry(cfg, sec_name, "tb > rate"); > if (entry) > subport_params[i].tb_rate =3D > (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, sec_name, "tb size"); > + entry =3D rte_cfgfile_get_entry(cfg, sec_name, "tb > size"); > if (entry) > subport_params[i].tb_size =3D > (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, sec_name, "tc period"); > + entry =3D rte_cfgfile_get_entry(cfg, sec_name, "tc > period"); > if (entry) > subport_params[i].tc_period =3D > (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, sec_name, "tc 0 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, sec_name, "tc 0 > rate"); > if (entry) > subport_params[i].tc_rate[0] =3D > (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, sec_name, "tc 1 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, sec_name, "tc 1 > rate"); > if (entry) > subport_params[i].tc_rate[1] =3D > (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, sec_name, "tc 2 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, sec_name, "tc 2 > rate"); > if (entry) > subport_params[i].tc_rate[2] =3D > (uint32_t)atoi(entry); >=20 > - entry =3D cfg_get_entry(cfg, sec_name, "tc 3 rate"); > + entry =3D rte_cfgfile_get_entry(cfg, sec_name, "tc 3 > rate"); > if (entry) > subport_params[i].tc_rate[3] =3D > (uint32_t)atoi(entry); >=20 > - int n_entries =3D cfg_section_num_entries(cfg, > sec_name); > - struct cfg_entry entries[n_entries]; > + int n_entries =3D rte_cfgfile_section_num_entries(cfg, > sec_name); > + struct rte_cfgfile_entry entries[n_entries]; >=20 > - cfg_section_entries(cfg, sec_name, entries, > n_entries); > + rte_cfgfile_section_entries(cfg, sec_name, entries, > n_entries); >=20 > for (j =3D 0; j < n_entries; j++) { > if (strncmp("pipe", entries[j].name, > sizeof("pipe") - 1) =3D=3D 0) { > @@ -594,7 +509,7 @@ cfg_load_subport(struct cfg_file *cfg, struct > rte_sched_subport_params *subport_ >=20 > snprintf(profile_name, > sizeof(profile_name), > "pipe profile > %d", profile); > - if (cfg_has_section(cfg, > profile_name)) > + if > (rte_cfgfile_has_section(cfg, profile_name)) >=20 > app_pipe_to_profile[i][k] =3D profile; > else >=20 > rte_exit(EXIT_FAILURE, "Wrong pipe profile %s\n", > diff --git a/examples/qos_sched/cfg_file.h b/examples/qos_sched/cfg_file.= h > index 3a8fc66..960cea4 100644 > --- a/examples/qos_sched/cfg_file.h > +++ b/examples/qos_sched/cfg_file.h > @@ -35,6 +35,7 @@ > #define __CFG_FILE_H__ >=20 > #include > +#include >=20 > #define CFG_NAME_LEN 32 > #define CFG_VALUE_LEN 64 > @@ -57,45 +58,17 @@ struct cfg_file { > }; >=20 >=20 > -int cfg_load_port(struct cfg_file *cfg, struct rte_sched_port_params *po= rt); > +int cfg_load_port(struct rte_cfgfile *cfg, struct rte_sched_port_params > *port); >=20 > -int cfg_load_pipe(struct cfg_file *cfg, struct rte_sched_pipe_params *pi= pe); > - > -int cfg_load_subport(struct cfg_file *cfg, struct rte_sched_subport_para= ms > *subport); > +int cfg_load_pipe(struct rte_cfgfile *cfg, struct rte_sched_pipe_params > *pipe); >=20 > +int cfg_load_subport(struct rte_cfgfile *cfg, struct > rte_sched_subport_params *subport); >=20 > /* reads a config file from disk and returns a handle to the config > * 'flags' is reserved for future use and must be 0 > */ > struct cfg_file *cfg_load(const char *filename, int flags); >=20 > -/* returns the number of sections in the config */ > -int cfg_num_sections(struct cfg_file *cfg, const char *sec_name, size_t > length); > - > -/* fills the array "sections" with the names of all the sections in the = file > - * (up to a max of max_sections). > - * NOTE: buffers in the sections array must be at least CFG_NAME_LEN big > - */ > -int cfg_sections(struct cfg_file *cfg, char *sections[], int max_section= s); > - > -/* true if the named section exists, false otherwise */ > -int cfg_has_section(struct cfg_file *cfg, const char *sectionname); > - > -/* returns the number of entries in a section */ > -int cfg_section_num_entries(struct cfg_file *cfg, const char *sectionnam= e); > - > -/* returns the entries in a section as key-value pairs in the "entries" = array */ > -int cfg_section_entries(struct cfg_file *cfg, const char *sectionname, > - struct cfg_entry *entries, int max_entries); > - > -/* returns a pointer to the value of the named entry in the named sectio= n > */ > -const char *cfg_get_entry(struct cfg_file *cfg, const char *sectionname, > - const char *entryname); > - > -/* true if the given entry exists in the given section, false otherwise = */ > -int cfg_has_entry(struct cfg_file *cfg, const char *sectionname, > - const char *entryname); > - > /* cleans up memory allocated by cfg_load() */ > int cfg_close(struct cfg_file *cfg); >=20 > diff --git a/examples/qos_sched/init.c b/examples/qos_sched/init.c > index 88cf811..70e12bb 100644 > --- a/examples/qos_sched/init.c > +++ b/examples/qos_sched/init.c > @@ -42,6 +42,7 @@ > #include > #include > #include > +#include >=20 > #include "main.h" > #include "cfg_file.h" > @@ -284,16 +285,15 @@ app_load_cfg_profile(const char *profile) > { > if (profile =3D=3D NULL) > return 0; > - > - struct cfg_file *cfg_file =3D cfg_load(profile, 0); > - if (cfg_file =3D=3D NULL) > + struct rte_cfgfile *file =3D rte_cfgfile_load(profile, 0); > + if (file =3D=3D NULL) > rte_exit(EXIT_FAILURE, "Cannot load configuration profile > %s\n", profile); >=20 > - cfg_load_port(cfg_file, &port_params); > - cfg_load_subport(cfg_file, subport_params); > - cfg_load_pipe(cfg_file, pipe_profiles); > + cfg_load_port(file, &port_params); > + cfg_load_subport(file, subport_params); > + cfg_load_pipe(file, pipe_profiles); >=20 > - cfg_close(cfg_file); > + rte_cfgfile_close(file); >=20 > return 0; > } > -- > 1.7.9.5 Acked-by: Cristian Dumitrescu