4 * Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 #include <rte_errno.h>
45 #include <rte_cfgfile.h>
46 #include <rte_string_fns.h>
51 * Default config values
54 static struct app_params app_params_default = {
55 .config_file = "./config/ip_pipeline.cfg",
56 .log_level = APP_LOG_LEVEL_HIGH,
63 static const struct app_mempool_params mempool_params_default = {
65 .buffer_size = 2048 + sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM,
66 .pool_size = 32 * 1024,
71 static const struct app_link_params link_params_default = {
89 .mq_mode = ETH_MQ_RX_NONE,
91 .header_split = 0, /* Header split */
92 .hw_ip_checksum = 0, /* IP checksum offload */
93 .hw_vlan_filter = 0, /* VLAN filtering */
94 .hw_vlan_strip = 0, /* VLAN strip */
95 .hw_vlan_extend = 0, /* Extended VLAN */
96 .jumbo_frame = 0, /* Jumbo frame support */
97 .hw_strip_crc = 0, /* CRC strip by HW */
98 .enable_scatter = 0, /* Scattered packets RX handler */
100 .max_rx_pkt_len = 9000, /* Jumbo frame max packet len */
101 .split_hdr_size = 0, /* Header split buffer size */
104 .mq_mode = ETH_MQ_TX_NONE,
112 static const struct app_pktq_hwq_in_params default_hwq_in_params = {
124 .rx_free_thresh = 64,
126 .rx_deferred_start = 0,
130 static const struct app_pktq_hwq_out_params default_hwq_out_params = {
145 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
146 ETH_TXQ_FLAGS_NOOFFLOADS,
147 .tx_deferred_start = 0,
151 static const struct app_pktq_swq_params default_swq_params = {
161 struct app_pktq_tm_params default_tm_params = {
163 .file_name = "./config/tm_profile.cfg",
168 struct app_pktq_source_params default_source_params = {
174 struct app_pktq_sink_params default_sink_params = {
178 struct app_msgq_params default_msgq_params = {
184 struct app_pipeline_params default_pipeline_params = {
197 static const char app_usage[] =
198 "Usage: %s [-f CONFIG_FILE] [-s SCRIPT_FILE] -p PORT_MASK "
202 "\t-f CONFIG_FILE: Default config file is %s\n"
203 "\t-p PORT_MASK: Mask of NIC port IDs in hexadecimal format\n"
204 "\t-s SCRIPT_FILE: No CLI script file is run when not specified\n"
205 "\t-l LOG_LEVEL: 0 = NONE, 1 = HIGH PRIO (default), 2 = LOW PRIO\n"
209 app_print_usage(char *prgname)
211 rte_exit(0, app_usage, prgname, app_params_default.config_file);
214 #define skip_white_spaces(pos) \
216 __typeof__(pos) _p = (pos); \
217 for ( ; isspace(*_p); _p++); \
221 #define PARSER_IMPLICIT_PARAM_ADD_CHECK(result, section_name) \
223 APP_CHECK((result != -EINVAL), \
224 "CFG: [%s] name too long", section_name); \
225 APP_CHECK(result != -ENOMEM, \
226 "CFG: [%s] too much sections", section_name); \
227 APP_CHECK(result >= 0, \
228 "CFG: [%s] Unknown error while adding '%s'", \
229 section_name, section_name); \
232 #define PARSER_PARAM_ADD_CHECK(result, params_array, section_name) \
234 APP_CHECK((result != -EINVAL), \
235 "CFG: [%s] name too long", section_name); \
236 APP_CHECK((result != -ENOMEM), \
237 "CFG: [%s] too much sections", section_name); \
238 APP_CHECK(((result >= 0) && (params_array)[result].parsed == 0),\
239 "CFG: [%s] duplicate section", section_name); \
240 APP_CHECK((result >= 0), \
241 "CFG: [%s] Unknown error while adding '%s'", \
242 section_name, section_name); \
246 parser_read_arg_bool(const char *p)
248 p = skip_white_spaces(p);
249 int result = -EINVAL;
251 if (((p[0] == 'y') && (p[1] == 'e') && (p[2] == 's')) ||
252 ((p[0] == 'Y') && (p[1] == 'E') && (p[2] == 'S'))) {
257 if (((p[0] == 'o') && (p[1] == 'n')) ||
258 ((p[0] == 'O') && (p[1] == 'N'))) {
263 if (((p[0] == 'n') && (p[1] == 'o')) ||
264 ((p[0] == 'N') && (p[1] == 'O'))) {
269 if (((p[0] == 'o') && (p[1] == 'f') && (p[2] == 'f')) ||
270 ((p[0] == 'O') && (p[1] == 'F') && (p[2] == 'F'))) {
275 p = skip_white_spaces(p);
283 #define PARSE_ERROR(exp, section, entry) \
284 APP_CHECK(exp, "Parse error in section \"%s\": entry \"%s\"\n", section, entry)
286 #define PARSE_ERROR_MALLOC(exp) \
287 APP_CHECK(exp, "Parse error: no free memory\n")
289 #define PARSE_ERROR_SECTION(exp, section) \
290 APP_CHECK(exp, "Parse error in section \"%s\"", section)
292 #define PARSE_ERROR_SECTION_NO_ENTRIES(exp, section) \
293 APP_CHECK(exp, "Parse error in section \"%s\": no entries\n", section)
295 #define PARSE_WARNING_IGNORED(exp, section, entry) \
298 fprintf(stderr, "Parse warning in section \"%s\": " \
299 "entry \"%s\" is ignored\n", section, entry); \
302 #define PARSE_ERROR_INVALID(exp, section, entry) \
303 APP_CHECK(exp, "Parse error in section \"%s\": unrecognized entry \"%s\"\n",\
306 #define PARSE_ERROR_DUPLICATE(exp, section, entry) \
307 APP_CHECK(exp, "Parse error in section \"%s\": duplicate entry \"%s\"\n",\
311 parser_read_uint64(uint64_t *value, const char *p)
316 p = skip_white_spaces(p);
320 val = strtoul(p, &next, 10);
342 p = skip_white_spaces(p);
351 parser_read_uint32(uint32_t *value, const char *p)
354 int ret = parser_read_uint64(&val, p);
358 else if (val > UINT32_MAX)
366 parse_pipeline_core(uint32_t *socket,
374 uint32_t s = 0, c = 0, h = 0, val;
375 uint8_t s_parsed = 0, c_parsed = 0, h_parsed = 0;
376 const char *next = skip_white_spaces(entry);
379 /* Expect <CORE> or [sX][cY][h]. At least one parameter is required. */
380 while (*next != '\0') {
381 /* If everything parsed nothing should left */
382 if (s_parsed && c_parsed && h_parsed)
409 /* If it start from digit it must be only core id. */
410 if (!isdigit(*next) || s_parsed || c_parsed || h_parsed)
416 for (num_len = 0; *next != '\0'; next++, num_len++) {
417 if (num_len == RTE_DIM(num))
423 num[num_len] = *next;
426 if (num_len == 0 && type != 'h')
430 val = strtol(num, NULL, 10);
441 if (type == 'C' && *next != '\0')
459 skip_digits(const char *src)
463 for (i = 0; isdigit(src[i]); i++);
469 validate_name(const char *name, const char *prefix, int num)
473 for (i = 0; (name[i] != '\0') && (prefix[i] != '\0'); i++) {
474 if (name[i] != prefix[i])
478 if (prefix[i] != '\0')
489 j = skip_digits(&name[i]);
491 if ((j == 0) || (name[i] != '.'))
497 j = skip_digits(&name[i]);
499 if ((j == 0) || (name[i] != '\0'))
507 parse_eal(struct app_params *app,
508 const char *section_name,
509 struct rte_cfgfile *cfg)
511 struct app_eal_params *p = &app->eal_params;
512 struct rte_cfgfile_entry *entries;
515 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
516 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
518 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
519 PARSE_ERROR_MALLOC(entries != NULL);
521 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
523 for (i = 0; i < n_entries; i++) {
524 struct rte_cfgfile_entry *entry = &entries[i];
527 if (strcmp(entry->name, "c") == 0) {
528 PARSE_WARNING_IGNORED(0, section_name, entry->name);
533 if (strcmp(entry->name, "l") == 0) {
534 PARSE_WARNING_IGNORED(0, section_name, entry->name);
539 if (strcmp(entry->name, "lcores") == 0) {
540 PARSE_ERROR_DUPLICATE((p->coremap == NULL),
543 p->coremap = strdup(entry->value);
548 if (strcmp(entry->name, "master_lcore") == 0) {
551 PARSE_ERROR_DUPLICATE((p->master_lcore_present == 0),
554 p->master_lcore_present = 1;
556 status = parser_read_uint32(&p->master_lcore,
558 PARSE_ERROR((status == 0), section_name, entry->name);
563 if (strcmp(entry->name, "n") == 0) {
566 PARSE_ERROR_DUPLICATE((p->channels_present == 0),
569 p->channels_present = 1;
571 status = parser_read_uint32(&p->channels, entry->value);
572 PARSE_ERROR((status == 0), section_name, entry->name);
577 if (strcmp(entry->name, "m") == 0) {
580 PARSE_ERROR_DUPLICATE((p->memory_present == 0),
583 p->memory_present = 1;
585 status = parser_read_uint32(&p->memory, entry->value);
586 PARSE_ERROR((status == 0), section_name, entry->name);
591 if (strcmp(entry->name, "r") == 0) {
594 PARSE_ERROR_DUPLICATE((p->ranks_present == 0),
597 p->ranks_present = 1;
599 status = parser_read_uint32(&p->ranks, entry->value);
600 PARSE_ERROR((status == 0), section_name, entry->name);
605 if ((strcmp(entry->name, "pci_blacklist") == 0) ||
606 (strcmp(entry->name, "b") == 0)) {
607 PARSE_ERROR_DUPLICATE((p->pci_blacklist == NULL),
610 p->pci_blacklist = strdup(entry->value);
615 if ((strcmp(entry->name, "pci_whitelist") == 0) ||
616 (strcmp(entry->name, "w") == 0)) {
617 PARSE_ERROR_DUPLICATE((p->pci_whitelist == NULL),
620 p->pci_whitelist = strdup(entry->value);
625 if (strcmp(entry->name, "vdev") == 0) {
626 PARSE_ERROR_DUPLICATE((p->vdev == NULL),
629 p->vdev = strdup(entry->value);
634 if (strcmp(entry->name, "vmware_tsc_map") == 0) {
637 PARSE_ERROR_DUPLICATE((p->vmware_tsc_map_present == 0),
640 p->vmware_tsc_map_present = 1;
642 val = parser_read_arg_bool(entry->value);
643 PARSE_ERROR((val >= 0), section_name, entry->name);
644 p->vmware_tsc_map = val;
649 if (strcmp(entry->name, "proc_type") == 0) {
650 PARSE_ERROR_DUPLICATE((p->proc_type == NULL),
653 p->proc_type = strdup(entry->value);
658 if (strcmp(entry->name, "syslog") == 0) {
659 PARSE_ERROR_DUPLICATE((p->syslog == NULL),
662 p->syslog = strdup(entry->value);
667 if (strcmp(entry->name, "log_level") == 0) {
670 PARSE_ERROR_DUPLICATE((p->log_level_present == 0),
673 p->log_level_present = 1;
675 status = parser_read_uint32(&p->log_level,
677 PARSE_ERROR((status == 0), section_name, entry->name);
682 if (strcmp(entry->name, "v") == 0) {
685 PARSE_ERROR_DUPLICATE((p->version_present == 0),
688 p->version_present = 1;
690 val = parser_read_arg_bool(entry->value);
691 PARSE_ERROR((val >= 0), section_name, entry->name);
697 if ((strcmp(entry->name, "help") == 0) ||
698 (strcmp(entry->name, "h") == 0)) {
701 PARSE_ERROR_DUPLICATE((p->help_present == 0),
706 val = parser_read_arg_bool(entry->value);
707 PARSE_ERROR((val >= 0), section_name, entry->name);
713 if (strcmp(entry->name, "no_huge") == 0) {
716 PARSE_ERROR_DUPLICATE((p->no_huge_present == 0),
719 p->no_huge_present = 1;
721 val = parser_read_arg_bool(entry->value);
722 PARSE_ERROR((val >= 0), section_name, entry->name);
728 if (strcmp(entry->name, "no_pci") == 0) {
731 PARSE_ERROR_DUPLICATE((p->no_pci_present == 0),
734 p->no_pci_present = 1;
736 val = parser_read_arg_bool(entry->value);
737 PARSE_ERROR((val >= 0), section_name, entry->name);
743 if (strcmp(entry->name, "no_hpet") == 0) {
746 PARSE_ERROR_DUPLICATE((p->no_hpet_present == 0),
749 p->no_hpet_present = 1;
751 val = parser_read_arg_bool(entry->value);
752 PARSE_ERROR((val >= 0), section_name, entry->name);
758 if (strcmp(entry->name, "no_shconf") == 0) {
761 PARSE_ERROR_DUPLICATE((p->no_shconf_present == 0),
764 p->no_shconf_present = 1;
766 val = parser_read_arg_bool(entry->value);
767 PARSE_ERROR((val >= 0), section_name, entry->name);
773 if (strcmp(entry->name, "d") == 0) {
774 PARSE_ERROR_DUPLICATE((p->add_driver == NULL),
777 p->add_driver = strdup(entry->value);
782 if (strcmp(entry->name, "socket_mem") == 0) {
783 PARSE_ERROR_DUPLICATE((p->socket_mem == NULL),
786 p->socket_mem = strdup(entry->value);
791 if (strcmp(entry->name, "huge_dir") == 0) {
792 PARSE_ERROR_DUPLICATE((p->huge_dir == NULL),
795 p->huge_dir = strdup(entry->value);
800 if (strcmp(entry->name, "file_prefix") == 0) {
801 PARSE_ERROR_DUPLICATE((p->file_prefix == NULL),
804 p->file_prefix = strdup(entry->value);
809 if (strcmp(entry->name, "base_virtaddr") == 0) {
810 PARSE_ERROR_DUPLICATE((p->base_virtaddr == NULL),
813 p->base_virtaddr = strdup(entry->value);
818 if (strcmp(entry->name, "create_uio_dev") == 0) {
821 PARSE_ERROR_DUPLICATE((p->create_uio_dev_present == 0),
824 p->create_uio_dev_present = 1;
826 val = parser_read_arg_bool(entry->value);
827 PARSE_ERROR((val >= 0), section_name, entry->name);
828 p->create_uio_dev = val;
833 if (strcmp(entry->name, "vfio_intr") == 0) {
834 PARSE_ERROR_DUPLICATE((p->vfio_intr == NULL),
837 p->vfio_intr = strdup(entry->value);
842 if (strcmp(entry->name, "xen_dom0") == 0) {
845 PARSE_ERROR_DUPLICATE((p->xen_dom0_present == 0),
848 p->xen_dom0_present = 1;
850 val = parser_read_arg_bool(entry->value);
851 PARSE_ERROR((val >= 0), section_name, entry->name);
857 PARSE_ERROR_INVALID(0, section_name, entry->name);
864 parse_pipeline_pktq_in(struct app_params *app,
865 struct app_pipeline_params *p,
868 const char *next = value;
870 char name[APP_PARAM_NAME_SIZE];
873 while (*next != '\0') {
874 enum app_pktq_in_type type;
877 end = strchr(next, ' ');
879 name_len = strlen(next);
881 name_len = end - next;
883 if (name_len == 0 || name_len == sizeof(name))
886 strncpy(name, next, name_len);
887 name[name_len] = '\0';
892 if (validate_name(name, "RXQ", 2) == 0) {
893 type = APP_PKTQ_IN_HWQ;
894 id = APP_PARAM_ADD(app->hwq_in_params, name);
895 } else if (validate_name(name, "SWQ", 1) == 0) {
896 type = APP_PKTQ_IN_SWQ;
897 id = APP_PARAM_ADD(app->swq_params, name);
898 } else if (validate_name(name, "TM", 1) == 0) {
899 type = APP_PKTQ_IN_TM;
900 id = APP_PARAM_ADD(app->tm_params, name);
901 } else if (validate_name(name, "SOURCE", 1) == 0) {
902 type = APP_PKTQ_IN_SOURCE;
903 id = APP_PARAM_ADD(app->source_params, name);
910 p->pktq_in[p->n_pktq_in].type = type;
911 p->pktq_in[p->n_pktq_in].id = (uint32_t) id;
919 parse_pipeline_pktq_out(struct app_params *app,
920 struct app_pipeline_params *p,
923 const char *next = value;
925 char name[APP_PARAM_NAME_SIZE];
928 while (*next != '\0') {
929 enum app_pktq_out_type type;
932 end = strchr(next, ' ');
934 name_len = strlen(next);
936 name_len = end - next;
938 if (name_len == 0 || name_len == sizeof(name))
941 strncpy(name, next, name_len);
942 name[name_len] = '\0';
947 if (validate_name(name, "TXQ", 2) == 0) {
948 type = APP_PKTQ_OUT_HWQ;
949 id = APP_PARAM_ADD(app->hwq_out_params, name);
950 } else if (validate_name(name, "SWQ", 1) == 0) {
951 type = APP_PKTQ_OUT_SWQ;
952 id = APP_PARAM_ADD(app->swq_params, name);
953 } else if (validate_name(name, "TM", 1) == 0) {
954 type = APP_PKTQ_OUT_TM;
955 id = APP_PARAM_ADD(app->tm_params, name);
956 } else if (validate_name(name, "SINK", 1) == 0) {
957 type = APP_PKTQ_OUT_SINK;
958 id = APP_PARAM_ADD(app->sink_params, name);
965 p->pktq_out[p->n_pktq_out].type = type;
966 p->pktq_out[p->n_pktq_out].id = id;
974 parse_pipeline_msgq_in(struct app_params *app,
975 struct app_pipeline_params *p,
978 const char *next = value;
980 char name[APP_PARAM_NAME_SIZE];
984 while (*next != '\0') {
985 end = strchr(next, ' ');
987 name_len = strlen(next);
989 name_len = end - next;
991 if (name_len == 0 || name_len == sizeof(name))
994 strncpy(name, next, name_len);
995 name[name_len] = '\0';
1000 if (validate_name(name, "MSGQ", 1) != 0)
1003 idx = APP_PARAM_ADD(app->msgq_params, name);
1007 p->msgq_in[p->n_msgq_in] = idx;
1015 parse_pipeline_msgq_out(struct app_params *app,
1016 struct app_pipeline_params *p,
1019 const char *next = value;
1021 char name[APP_PARAM_NAME_SIZE];
1025 while (*next != '\0') {
1026 end = strchr(next, ' ');
1028 name_len = strlen(next);
1030 name_len = end - next;
1032 if (name_len == 0 || name_len == sizeof(name))
1035 strncpy(name, next, name_len);
1036 name[name_len] = '\0';
1041 if (validate_name(name, "MSGQ", 1) != 0)
1044 idx = APP_PARAM_ADD(app->msgq_params, name);
1048 p->msgq_out[p->n_msgq_out] = idx;
1057 parse_pipeline(struct app_params *app,
1058 const char *section_name,
1059 struct rte_cfgfile *cfg)
1061 char name[CFG_NAME_LEN];
1062 struct app_pipeline_params *param;
1063 struct rte_cfgfile_entry *entries;
1065 int n_entries, ret, i;
1067 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1068 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1070 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1071 PARSE_ERROR_MALLOC(entries != NULL);
1073 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1075 param_idx = APP_PARAM_ADD(app->pipeline_params, section_name);
1076 PARSER_PARAM_ADD_CHECK(param_idx, app->pipeline_params, section_name);
1078 param = &app->pipeline_params[param_idx];
1081 for (i = 0; i < n_entries; i++) {
1082 struct rte_cfgfile_entry *ent = &entries[i];
1084 if (strcmp(ent->name, "type") == 0) {
1085 ret = snprintf(param->type,
1086 RTE_DIM(param->type),
1089 if ((ret > 0) && (ret < (int)RTE_DIM(param->type)))
1093 } else if (strcmp(ent->name, "core") == 0)
1094 ret = parse_pipeline_core(¶m->socket_id,
1096 ¶m->hyper_th_id,
1098 else if (strcmp(ent->name, "pktq_in") == 0)
1099 ret = parse_pipeline_pktq_in(app, param, ent->value);
1100 else if (strcmp(ent->name, "pktq_out") == 0)
1101 ret = parse_pipeline_pktq_out(app, param, ent->value);
1102 else if (strcmp(ent->name, "msgq_in") == 0)
1103 ret = parse_pipeline_msgq_in(app, param, ent->value);
1104 else if (strcmp(ent->name, "msgq_out") == 0)
1105 ret = parse_pipeline_msgq_out(app, param, ent->value);
1106 else if (strcmp(ent->name, "timer_period") == 0)
1107 ret = parser_read_uint32(¶m->timer_period,
1110 param->args_name[param->n_args] = strdup(ent->name);
1111 param->args_value[param->n_args] = strdup(ent->value);
1113 APP_CHECK((param->args_name[param->n_args] != NULL) &&
1114 (param->args_value[param->n_args] != NULL),
1115 "CFG: [%s] out of memory",
1123 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1129 snprintf(name, sizeof(name), "MSGQ-REQ-%s", section_name);
1130 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1131 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1132 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1133 param->msgq_in[param->n_msgq_in++] = param_idx;
1135 snprintf(name, sizeof(name), "MSGQ-RSP-%s", section_name);
1136 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1137 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1138 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1139 param->msgq_out[param->n_msgq_out++] = param_idx;
1141 snprintf(name, sizeof(name), "MSGQ-REQ-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1144 (param->hyper_th_id) ? "h" : "");
1145 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1146 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1147 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1149 snprintf(name, sizeof(name), "MSGQ-RSP-CORE-s%" PRIu32 "c%" PRIu32 "%s",
1152 (param->hyper_th_id) ? "h" : "");
1153 param_idx = APP_PARAM_ADD(app->msgq_params, name);
1154 PARSER_IMPLICIT_PARAM_ADD_CHECK(param_idx, name);
1155 app->msgq_params[param_idx].cpu_socket_id = param->socket_id;
1161 parse_mempool(struct app_params *app,
1162 const char *section_name,
1163 struct rte_cfgfile *cfg)
1165 struct app_mempool_params *param;
1166 struct rte_cfgfile_entry *entries;
1168 int n_entries, ret, i;
1170 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1171 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1173 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1174 PARSE_ERROR_MALLOC(entries != NULL);
1176 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1178 param_idx = APP_PARAM_ADD(app->mempool_params, section_name);
1179 PARSER_PARAM_ADD_CHECK(param_idx, app->mempool_params, section_name);
1181 param = &app->mempool_params[param_idx];
1184 for (i = 0; i < n_entries; i++) {
1185 struct rte_cfgfile_entry *ent = &entries[i];
1188 if (strcmp(ent->name, "buffer_size") == 0)
1189 ret = parser_read_uint32(¶m->buffer_size,
1191 else if (strcmp(ent->name, "pool_size") == 0)
1192 ret = parser_read_uint32(¶m->pool_size,
1194 else if (strcmp(ent->name, "cache_size") == 0)
1195 ret = parser_read_uint32(¶m->cache_size,
1197 else if (strcmp(ent->name, "cpu") == 0)
1198 ret = parser_read_uint32(¶m->cpu_socket_id,
1201 APP_CHECK(ret != -ESRCH,
1202 "CFG: [%s] entry '%s': unknown entry\n",
1206 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1216 parse_link(struct app_params *app,
1217 const char *section_name,
1218 struct rte_cfgfile *cfg)
1220 struct app_link_params *param;
1221 struct rte_cfgfile_entry *entries;
1222 int n_entries, ret, i;
1225 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1226 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1228 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1229 PARSE_ERROR_MALLOC(entries != NULL);
1231 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1233 param_idx = APP_PARAM_ADD(app->link_params, section_name);
1234 PARSER_PARAM_ADD_CHECK(param_idx, app->link_params, section_name);
1236 param = &app->link_params[param_idx];
1239 for (i = 0; i < n_entries; i++) {
1240 struct rte_cfgfile_entry *ent = &entries[i];
1243 if (strcmp(ent->name, "arp_q") == 0)
1244 ret = parser_read_uint32(¶m->arp_q,
1246 else if (strcmp(ent->name, "tcp_syn_q") == 0)
1247 ret = parser_read_uint32(¶m->tcp_syn_local_q,
1249 else if (strcmp(ent->name, "ip_local_q") == 0)
1250 ret = parser_read_uint32(¶m->ip_local_q,
1252 else if (strcmp(ent->name, "tcp_local_q") == 0)
1253 ret = parser_read_uint32(¶m->tcp_local_q,
1255 else if (strcmp(ent->name, "udp_local_q") == 0)
1256 ret = parser_read_uint32(¶m->udp_local_q,
1258 else if (strcmp(ent->name, "sctp_local_q") == 0)
1259 ret = parser_read_uint32(¶m->sctp_local_q,
1262 APP_CHECK(ret != -ESRCH,
1263 "CFG: [%s] entry '%s': unknown entry\n",
1267 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1277 parse_rxq(struct app_params *app,
1278 const char *section_name,
1279 struct rte_cfgfile *cfg)
1281 struct app_pktq_hwq_in_params *param;
1282 struct rte_cfgfile_entry *entries;
1283 int n_entries, ret, i;
1286 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1287 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1289 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1290 PARSE_ERROR_MALLOC(entries != NULL);
1292 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1294 param_idx = APP_PARAM_ADD(app->hwq_in_params, section_name);
1295 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_in_params, section_name);
1297 param = &app->hwq_in_params[param_idx];
1300 for (i = 0; i < n_entries; i++) {
1301 struct rte_cfgfile_entry *ent = &entries[i];
1304 if (strcmp(ent->name, "mempool") == 0) {
1305 int status = validate_name(ent->value, "MEMPOOL", 1);
1308 APP_CHECK((status == 0),
1309 "CFG: [%s] entry '%s': invalid mempool\n",
1313 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1314 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1315 param->mempool_id = idx;
1317 } else if (strcmp(ent->name, "size") == 0)
1318 ret = parser_read_uint32(¶m->size,
1320 else if (strcmp(ent->name, "burst") == 0)
1321 ret = parser_read_uint32(¶m->burst,
1324 APP_CHECK(ret != -ESRCH,
1325 "CFG: [%s] entry '%s': unknown entry\n",
1329 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1339 parse_txq(struct app_params *app,
1340 const char *section_name,
1341 struct rte_cfgfile *cfg)
1343 struct app_pktq_hwq_out_params *param;
1344 struct rte_cfgfile_entry *entries;
1345 int n_entries, ret, i;
1348 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1349 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1351 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1352 PARSE_ERROR_MALLOC(entries != NULL);
1354 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1356 param_idx = APP_PARAM_ADD(app->hwq_out_params, section_name);
1357 PARSER_PARAM_ADD_CHECK(param_idx, app->hwq_out_params, section_name);
1359 param = &app->hwq_out_params[param_idx];
1362 for (i = 0; i < n_entries; i++) {
1363 struct rte_cfgfile_entry *ent = &entries[i];
1366 if (strcmp(ent->name, "size") == 0)
1367 ret = parser_read_uint32(¶m->size, ent->value);
1368 else if (strcmp(ent->name, "burst") == 0)
1369 ret = parser_read_uint32(¶m->burst, ent->value);
1370 else if (strcmp(ent->name, "dropless") == 0) {
1371 ret = parser_read_arg_bool(ent->value);
1373 param->dropless = ret;
1378 APP_CHECK(ret != -ESRCH,
1379 "CFG: [%s] entry '%s': unknown entry\n",
1383 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1393 parse_swq(struct app_params *app,
1394 const char *section_name,
1395 struct rte_cfgfile *cfg)
1397 struct app_pktq_swq_params *param;
1398 struct rte_cfgfile_entry *entries;
1399 int n_entries, ret, i;
1402 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1403 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1405 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1406 PARSE_ERROR_MALLOC(entries != NULL);
1408 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1410 param_idx = APP_PARAM_ADD(app->swq_params, section_name);
1411 PARSER_PARAM_ADD_CHECK(param_idx, app->swq_params, section_name);
1413 param = &app->swq_params[param_idx];
1416 for (i = 0; i < n_entries; i++) {
1417 struct rte_cfgfile_entry *ent = &entries[i];
1420 if (strcmp(ent->name, "size") == 0)
1421 ret = parser_read_uint32(¶m->size,
1423 else if (strcmp(ent->name, "burst_read") == 0)
1424 ret = parser_read_uint32(¶m->burst_read,
1426 else if (strcmp(ent->name, "burst_write") == 0)
1427 ret = parser_read_uint32(¶m->burst_write,
1429 else if (strcmp(ent->name, "dropless") == 0) {
1430 ret = parser_read_arg_bool(ent->value);
1432 param->dropless = ret;
1435 } else if (strcmp(ent->name, "n_retries") == 0)
1436 ret = parser_read_uint64(¶m->n_retries,
1438 else if (strcmp(ent->name, "cpu") == 0)
1439 ret = parser_read_uint32(¶m->cpu_socket_id,
1442 APP_CHECK(ret != -ESRCH,
1443 "CFG: [%s] entry '%s': unknown entry\n",
1447 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1457 parse_tm(struct app_params *app,
1458 const char *section_name,
1459 struct rte_cfgfile *cfg)
1461 struct app_pktq_tm_params *param;
1462 struct rte_cfgfile_entry *entries;
1463 int n_entries, ret, i;
1466 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1467 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1469 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1470 PARSE_ERROR_MALLOC(entries != NULL);
1472 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1474 param_idx = APP_PARAM_ADD(app->tm_params, section_name);
1475 PARSER_PARAM_ADD_CHECK(param_idx, app->tm_params, section_name);
1477 param = &app->tm_params[param_idx];
1480 for (i = 0; i < n_entries; i++) {
1481 struct rte_cfgfile_entry *ent = &entries[i];
1484 if (strcmp(ent->name, "cfg") == 0) {
1485 param->file_name = strdup(ent->value);
1486 if (param->file_name == NULL)
1490 } else if (strcmp(ent->name, "burst_read") == 0)
1491 ret = parser_read_uint32(¶m->burst_read,
1493 else if (strcmp(ent->name, "burst_write") == 0)
1494 ret = parser_read_uint32(¶m->burst_write,
1497 APP_CHECK(ret != -ESRCH,
1498 "CFG: [%s] entry '%s': unknown entry\n",
1501 APP_CHECK(ret != -EBADF,
1502 "CFG: [%s] entry '%s': TM cfg parse error '%s'\n",
1507 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1517 parse_source(struct app_params *app,
1518 const char *section_name,
1519 struct rte_cfgfile *cfg)
1521 struct app_pktq_source_params *param;
1522 struct rte_cfgfile_entry *entries;
1523 int n_entries, ret, i;
1526 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1527 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1529 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1530 PARSE_ERROR_MALLOC(entries != NULL);
1532 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1534 param_idx = APP_PARAM_ADD(app->source_params, section_name);
1535 PARSER_PARAM_ADD_CHECK(param_idx, app->source_params, section_name);
1537 param = &app->source_params[param_idx];
1540 for (i = 0; i < n_entries; i++) {
1541 struct rte_cfgfile_entry *ent = &entries[i];
1544 if (strcmp(ent->name, "mempool") == 0) {
1545 int status = validate_name(ent->value, "MEMPOOL", 1);
1548 APP_CHECK((status == 0),
1549 "CFG: [%s] entry '%s': invalid mempool\n",
1553 idx = APP_PARAM_ADD(app->mempool_params, ent->value);
1554 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, section_name);
1555 param->mempool_id = idx;
1557 } else if (strcmp(ent->name, "burst") == 0)
1558 ret = parser_read_uint32(¶m->burst, ent->value);
1560 APP_CHECK(ret != -ESRCH,
1561 "CFG: [%s] entry '%s': unknown entry\n",
1565 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1575 parse_msgq_req_pipeline(struct app_params *app,
1576 const char *section_name,
1577 struct rte_cfgfile *cfg)
1579 struct app_msgq_params *param;
1580 struct rte_cfgfile_entry *entries;
1581 int n_entries, ret, i;
1584 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1585 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1587 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1588 PARSE_ERROR_MALLOC(entries != NULL);
1590 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1592 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1593 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1595 param = &app->msgq_params[param_idx];
1598 for (i = 0; i < n_entries; i++) {
1599 struct rte_cfgfile_entry *ent = &entries[i];
1602 if (strcmp(ent->name, "size") == 0)
1603 ret = parser_read_uint32(¶m->size, ent->value);
1605 APP_CHECK(ret != -ESRCH,
1606 "CFG: [%s] entry '%s': unknown entry\n",
1610 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1620 parse_msgq_rsp_pipeline(struct app_params *app,
1621 const char *section_name,
1622 struct rte_cfgfile *cfg)
1624 struct app_msgq_params *param;
1625 struct rte_cfgfile_entry *entries;
1626 int n_entries, ret, i;
1629 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1630 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1632 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1633 PARSE_ERROR_MALLOC(entries != NULL);
1635 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1637 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1638 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1640 param = &app->msgq_params[param_idx];
1643 for (i = 0; i < n_entries; i++) {
1644 struct rte_cfgfile_entry *ent = &entries[i];
1647 if (strcmp(ent->name, "size") == 0)
1648 ret = parser_read_uint32(¶m->size, ent->value);
1650 APP_CHECK(ret != -ESRCH,
1651 "CFG: [%s] entry '%s': unknown entry\n",
1655 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1665 parse_msgq(struct app_params *app,
1666 const char *section_name,
1667 struct rte_cfgfile *cfg)
1669 struct app_msgq_params *param;
1670 struct rte_cfgfile_entry *entries;
1671 int n_entries, ret, i;
1674 n_entries = rte_cfgfile_section_num_entries(cfg, section_name);
1675 PARSE_ERROR_SECTION_NO_ENTRIES((n_entries > 0), section_name);
1677 entries = malloc(n_entries * sizeof(struct rte_cfgfile_entry));
1678 PARSE_ERROR_MALLOC(entries != NULL);
1680 rte_cfgfile_section_entries(cfg, section_name, entries, n_entries);
1682 param_idx = APP_PARAM_ADD(app->msgq_params, section_name);
1683 PARSER_PARAM_ADD_CHECK(param_idx, app->msgq_params, section_name);
1685 param = &app->msgq_params[param_idx];
1688 for (i = 0; i < n_entries; i++) {
1689 struct rte_cfgfile_entry *ent = &entries[i];
1692 if (strcmp(ent->name, "size") == 0)
1693 ret = parser_read_uint32(¶m->size,
1695 else if (strcmp(ent->name, "cpu") == 0)
1696 ret = parser_read_uint32(¶m->cpu_socket_id,
1699 APP_CHECK(ret != -ESRCH,
1700 "CFG: [%s] entry '%s': unknown entry\n",
1704 "CFG: [%s] entry '%s': Invalid value '%s'\n",
1713 typedef void (*config_section_load)(struct app_params *p,
1714 const char *section_name,
1715 struct rte_cfgfile *cfg);
1717 struct config_section {
1718 const char prefix[CFG_NAME_LEN];
1720 config_section_load load;
1723 static const struct config_section cfg_file_scheme[] = {
1724 {"EAL", 0, parse_eal},
1725 {"PIPELINE", 1, parse_pipeline},
1726 {"MEMPOOL", 1, parse_mempool},
1727 {"LINK", 1, parse_link},
1728 {"RXQ", 2, parse_rxq},
1729 {"TXQ", 2, parse_txq},
1730 {"SWQ", 1, parse_swq},
1731 {"TM", 1, parse_tm},
1732 {"SOURCE", 1, parse_source},
1733 {"MSGQ-REQ-PIPELINE", 1, parse_msgq_req_pipeline},
1734 {"MSGQ-RSP-PIPELINE", 1, parse_msgq_rsp_pipeline},
1735 {"MSGQ", 1, parse_msgq},
1739 create_implicit_mempools(struct app_params *app)
1743 idx = APP_PARAM_ADD(app->mempool_params, "MEMPOOL0");
1744 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, "start-up");
1748 parse_port_mask(struct app_params *app, uint64_t port_mask)
1750 uint32_t pmd_id, link_id;
1753 for (pmd_id = 0; pmd_id < RTE_MAX_ETHPORTS; pmd_id++) {
1754 char name[APP_PARAM_NAME_SIZE];
1757 if ((port_mask & (1LLU << pmd_id)) == 0)
1760 snprintf(name, sizeof(name), "LINK%" PRIu32, link_id);
1761 idx = APP_PARAM_ADD(app->link_params, name);
1762 PARSER_IMPLICIT_PARAM_ADD_CHECK(idx, name);
1764 app->link_params[idx].pmd_id = pmd_id;
1770 app_config_parse(struct app_params *app, const char *file_name)
1772 char config_file_out[APP_FILE_NAME_SIZE];
1773 struct rte_cfgfile *cfg;
1774 char **section_names;
1775 int i, j, sect_count;
1777 /* Implicit mempools */
1778 create_implicit_mempools(app);
1781 parse_port_mask(app, app->port_mask);
1783 /* Load application configuration file */
1784 cfg = rte_cfgfile_load(file_name, 0);
1785 APP_CHECK(cfg != NULL, "Unable to load config file %s", file_name);
1787 sect_count = rte_cfgfile_num_sections(cfg, NULL, 0);
1788 section_names = malloc(sect_count * sizeof(char *));
1789 for (i = 0; i < sect_count; i++)
1790 section_names[i] = malloc(CFG_NAME_LEN);
1792 rte_cfgfile_sections(cfg, section_names, sect_count);
1794 for (i = 0; i < sect_count; i++) {
1795 const struct config_section *sch_s;
1796 int len, cfg_name_len;
1798 cfg_name_len = strlen(section_names[i]);
1800 /* Find section type */
1801 for (j = 0; j < (int)RTE_DIM(cfg_file_scheme); j++) {
1802 sch_s = &cfg_file_scheme[j];
1803 len = strlen(sch_s->prefix);
1805 if (cfg_name_len < len)
1808 /* After section name we expect only '\0' or digit or
1809 * digit dot digit, so protect against false matching,
1810 * for example: "ABC" should match section name
1811 * "ABC0.0", but it should not match section_name
1814 if ((section_names[i][len] != '\0') &&
1815 !isdigit(section_names[i][len]))
1818 if (strncmp(sch_s->prefix, section_names[i], len) == 0)
1822 APP_CHECK(j < (int)RTE_DIM(cfg_file_scheme),
1823 "Unknown section %s",
1826 APP_CHECK(validate_name(section_names[i],
1828 sch_s->numbers) == 0,
1829 "Invalid section name '%s'",
1832 sch_s->load(app, section_names[i], cfg);
1835 for (i = 0; i < sect_count; i++)
1836 free(section_names[i]);
1838 free(section_names);
1840 rte_cfgfile_close(cfg);
1842 APP_PARAM_COUNT(app->mempool_params, app->n_mempools);
1843 APP_PARAM_COUNT(app->link_params, app->n_links);
1844 APP_PARAM_COUNT(app->hwq_in_params, app->n_pktq_hwq_in);
1845 APP_PARAM_COUNT(app->hwq_out_params, app->n_pktq_hwq_out);
1846 APP_PARAM_COUNT(app->swq_params, app->n_pktq_swq);
1847 APP_PARAM_COUNT(app->tm_params, app->n_pktq_tm);
1848 APP_PARAM_COUNT(app->source_params, app->n_pktq_source);
1849 APP_PARAM_COUNT(app->sink_params, app->n_pktq_sink);
1850 APP_PARAM_COUNT(app->msgq_params, app->n_msgq);
1851 APP_PARAM_COUNT(app->pipeline_params, app->n_pipelines);
1853 /* Save configuration to output file */
1854 snprintf(config_file_out,
1858 app_config_save(app, config_file_out);
1860 /* Load TM configuration files */
1861 app_config_parse_tm(app);
1867 save_eal_params(struct app_params *app, FILE *f)
1869 struct app_eal_params *p = &app->eal_params;
1871 fprintf(f, "[EAL]\n");
1874 fprintf(f, "%s = %s\n", "lcores", p->coremap);
1876 if (p->master_lcore_present)
1877 fprintf(f, "%s = %" PRIu32 "\n",
1878 "master_lcore", p->master_lcore);
1880 fprintf(f, "%s = %" PRIu32 "\n", "n", p->channels);
1882 if (p->memory_present)
1883 fprintf(f, "%s = %" PRIu32 "\n", "m", p->memory);
1885 if (p->ranks_present)
1886 fprintf(f, "%s = %" PRIu32 "\n", "r", p->ranks);
1888 if (p->pci_blacklist)
1889 fprintf(f, "%s = %s\n", "pci_blacklist", p->pci_blacklist);
1891 if (p->pci_whitelist)
1892 fprintf(f, "%s = %s\n", "pci_whitelist", p->pci_whitelist);
1895 fprintf(f, "%s = %s\n", "vdev", p->vdev);
1897 if (p->vmware_tsc_map_present)
1898 fprintf(f, "%s = %s\n", "vmware_tsc_map",
1899 (p->vmware_tsc_map) ? "yes" : "no");
1902 fprintf(f, "%s = %s\n", "proc_type", p->proc_type);
1905 fprintf(f, "%s = %s\n", "syslog", p->syslog);
1907 if (p->log_level_present)
1908 fprintf(f, "%s = %" PRIu32 "\n", "log_level", p->log_level);
1910 if (p->version_present)
1911 fprintf(f, "%s = %s\n", "v", (p->version) ? "yes" : "no");
1913 if (p->help_present)
1914 fprintf(f, "%s = %s\n", "help", (p->help) ? "yes" : "no");
1916 if (p->no_huge_present)
1917 fprintf(f, "%s = %s\n", "no_huge", (p->no_huge) ? "yes" : "no");
1919 if (p->no_pci_present)
1920 fprintf(f, "%s = %s\n", "no_pci", (p->no_pci) ? "yes" : "no");
1922 if (p->no_hpet_present)
1923 fprintf(f, "%s = %s\n", "no_hpet", (p->no_hpet) ? "yes" : "no");
1925 if (p->no_shconf_present)
1926 fprintf(f, "%s = %s\n", "no_shconf",
1927 (p->no_shconf) ? "yes" : "no");
1930 fprintf(f, "%s = %s\n", "d", p->add_driver);
1933 fprintf(f, "%s = %s\n", "socket_mem", p->socket_mem);
1936 fprintf(f, "%s = %s\n", "huge_dir", p->huge_dir);
1939 fprintf(f, "%s = %s\n", "file_prefix", p->file_prefix);
1941 if (p->base_virtaddr)
1942 fprintf(f, "%s = %s\n", "base_virtaddr", p->base_virtaddr);
1944 if (p->create_uio_dev_present)
1945 fprintf(f, "%s = %s\n", "create_uio_dev",
1946 (p->create_uio_dev) ? "yes" : "no");
1949 fprintf(f, "%s = %s\n", "vfio_intr", p->vfio_intr);
1951 if (p->xen_dom0_present)
1952 fprintf(f, "%s = %s\n", "xen_dom0",
1953 (p->xen_dom0) ? "yes" : "no");
1959 save_mempool_params(struct app_params *app, FILE *f)
1961 struct app_mempool_params *p;
1964 count = RTE_DIM(app->mempool_params);
1965 for (i = 0; i < count; i++) {
1966 p = &app->mempool_params[i];
1967 if (!APP_PARAM_VALID(p))
1970 fprintf(f, "[%s]\n", p->name);
1971 fprintf(f, "%s = %" PRIu32 "\n", "buffer_size", p->buffer_size);
1972 fprintf(f, "%s = %" PRIu32 "\n", "pool_size", p->pool_size);
1973 fprintf(f, "%s = %" PRIu32 "\n", "cache_size", p->cache_size);
1974 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
1981 save_links_params(struct app_params *app, FILE *f)
1983 struct app_link_params *p;
1986 count = RTE_DIM(app->link_params);
1987 for (i = 0; i < count; i++) {
1988 p = &app->link_params[i];
1989 if (!APP_PARAM_VALID(p))
1992 fprintf(f, "[%s]\n", p->name);
1993 fprintf(f, "; %s = %" PRIu32 "\n", "pmd_id", p->pmd_id);
1994 fprintf(f, "%s = %" PRIu32 "\n", "arp_q", p->arp_q);
1995 fprintf(f, "%s = %" PRIu32 "\n", "tcp_syn_local_q",
1996 p->tcp_syn_local_q);
1997 fprintf(f, "%s = %" PRIu32 "\n", "ip_local_q", p->ip_local_q);
1998 fprintf(f, "%s = %" PRIu32 "\n", "tcp_local_q", p->tcp_local_q);
1999 fprintf(f, "%s = %" PRIu32 "\n", "udp_local_q", p->udp_local_q);
2000 fprintf(f, "%s = %" PRIu32 "\n", "sctp_local_q",
2008 save_rxq_params(struct app_params *app, FILE *f)
2010 struct app_pktq_hwq_in_params *p;
2013 count = RTE_DIM(app->hwq_in_params);
2014 for (i = 0; i < count; i++) {
2015 p = &app->hwq_in_params[i];
2016 if (!APP_PARAM_VALID(p))
2019 fprintf(f, "[%s]\n", p->name);
2020 fprintf(f, "%s = %s\n",
2022 app->mempool_params[p->mempool_id].name);
2023 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2024 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2031 save_txq_params(struct app_params *app, FILE *f)
2033 struct app_pktq_hwq_out_params *p;
2036 count = RTE_DIM(app->hwq_out_params);
2037 for (i = 0; i < count; i++) {
2038 p = &app->hwq_out_params[i];
2039 if (!APP_PARAM_VALID(p))
2042 fprintf(f, "[%s]\n", p->name);
2043 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2044 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2045 fprintf(f, "%s = %s\n",
2047 p->dropless ? "yes" : "no");
2054 save_swq_params(struct app_params *app, FILE *f)
2056 struct app_pktq_swq_params *p;
2059 count = RTE_DIM(app->swq_params);
2060 for (i = 0; i < count; i++) {
2061 p = &app->swq_params[i];
2062 if (!APP_PARAM_VALID(p))
2065 fprintf(f, "[%s]\n", p->name);
2066 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2067 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2068 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2069 fprintf(f, "%s = %s\n", "dropless", p->dropless ? "yes" : "no");
2070 fprintf(f, "%s = %" PRIu64 "\n", "n_retries", p->n_retries);
2071 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2078 save_tm_params(struct app_params *app, FILE *f)
2080 struct app_pktq_tm_params *p;
2083 count = RTE_DIM(app->tm_params);
2084 for (i = 0; i < count; i++) {
2085 p = &app->tm_params[i];
2086 if (!APP_PARAM_VALID(p))
2089 fprintf(f, "[%s]\n", p->name);
2090 fprintf(f, "%s = %s\n", "cfg", p->file_name);
2091 fprintf(f, "%s = %" PRIu32 "\n", "burst_read", p->burst_read);
2092 fprintf(f, "%s = %" PRIu32 "\n", "burst_write", p->burst_write);
2099 save_source_params(struct app_params *app, FILE *f)
2101 struct app_pktq_source_params *p;
2104 count = RTE_DIM(app->source_params);
2105 for (i = 0; i < count; i++) {
2106 p = &app->source_params[i];
2107 if (!APP_PARAM_VALID(p))
2110 fprintf(f, "[%s]\n", p->name);
2111 fprintf(f, "%s = %s\n",
2113 app->mempool_params[p->mempool_id].name);
2114 fprintf(f, "%s = %" PRIu32 "\n", "burst", p->burst);
2120 save_msgq_params(struct app_params *app, FILE *f)
2122 struct app_msgq_params *p;
2125 count = RTE_DIM(app->msgq_params);
2126 for (i = 0; i < count; i++) {
2127 p = &app->msgq_params[i];
2128 if (!APP_PARAM_VALID(p))
2131 fprintf(f, "[%s]\n", p->name);
2132 fprintf(f, "%s = %" PRIu32 "\n", "size", p->size);
2133 fprintf(f, "%s = %" PRIu32 "\n", "cpu", p->cpu_socket_id);
2140 save_pipeline_params(struct app_params *app, FILE *f)
2144 count = RTE_DIM(app->pipeline_params);
2145 for (i = 0; i < count; i++) {
2146 struct app_pipeline_params *p = &app->pipeline_params[i];
2148 if (!APP_PARAM_VALID(p))
2152 fprintf(f, "[%s]\n", p->name);
2155 fprintf(f, "type = %s\n", p->type);
2158 fprintf(f, "core = s%" PRIu32 "c%" PRIu32 "%s\n",
2161 (p->hyper_th_id) ? "h" : "");
2167 fprintf(f, "pktq_in =");
2168 for (j = 0; j < p->n_pktq_in; j++) {
2169 struct app_pktq_in_params *pp = &p->pktq_in[j];
2173 case APP_PKTQ_IN_HWQ:
2174 name = app->hwq_in_params[pp->id].name;
2176 case APP_PKTQ_IN_SWQ:
2177 name = app->swq_params[pp->id].name;
2179 case APP_PKTQ_IN_TM:
2180 name = app->tm_params[pp->id].name;
2182 case APP_PKTQ_IN_SOURCE:
2183 name = app->source_params[pp->id].name;
2186 APP_CHECK(0, "Error\n");
2189 fprintf(f, " %s", name);
2195 if (p->n_pktq_out) {
2198 fprintf(f, "pktq_out =");
2199 for (j = 0; j < p->n_pktq_out; j++) {
2200 struct app_pktq_out_params *pp =
2205 case APP_PKTQ_OUT_HWQ:
2206 name = app->hwq_out_params[pp->id].name;
2208 case APP_PKTQ_OUT_SWQ:
2209 name = app->swq_params[pp->id].name;
2211 case APP_PKTQ_OUT_TM:
2212 name = app->tm_params[pp->id].name;
2214 case APP_PKTQ_OUT_SINK:
2215 name = app->sink_params[pp->id].name;
2218 APP_CHECK(0, "Error\n");
2221 fprintf(f, " %s", name);
2230 fprintf(f, "msgq_in =");
2231 for (j = 0; j < p->n_msgq_in; j++) {
2232 uint32_t id = p->msgq_in[j];
2233 char *name = app->msgq_params[id].name;
2235 fprintf(f, " %s", name);
2244 fprintf(f, "msgq_out =");
2245 for (j = 0; j < p->n_msgq_out; j++) {
2246 uint32_t id = p->msgq_out[j];
2247 char *name = app->msgq_params[id].name;
2249 fprintf(f, " %s", name);
2255 fprintf(f, "timer_period = %" PRIu32 "\n", p->timer_period);
2261 for (j = 0; j < p->n_args; j++)
2262 fprintf(f, "%s = %s\n", p->args_name[j],
2271 app_config_save(struct app_params *app, const char *file_name)
2274 char *name, *dir_name;
2277 name = strdup(file_name);
2278 dir_name = dirname(name);
2279 status = access(dir_name, W_OK);
2280 APP_CHECK((status == 0),
2281 "Need write access to directory \"%s\" to save configuration\n",
2284 file = fopen(file_name, "w");
2285 APP_CHECK((file != NULL),
2286 "Failed to save configuration to file \"%s\"", file_name);
2288 save_eal_params(app, file);
2289 save_pipeline_params(app, file);
2290 save_mempool_params(app, file);
2291 save_links_params(app, file);
2292 save_rxq_params(app, file);
2293 save_txq_params(app, file);
2294 save_swq_params(app, file);
2295 save_tm_params(app, file);
2296 save_source_params(app, file);
2297 save_msgq_params(app, file);
2304 app_config_init(struct app_params *app)
2308 memcpy(app, &app_params_default, sizeof(struct app_params));
2310 for (i = 0; i < RTE_DIM(app->mempool_params); i++)
2311 memcpy(&app->mempool_params[i],
2312 &mempool_params_default,
2313 sizeof(struct app_mempool_params));
2315 for (i = 0; i < RTE_DIM(app->link_params); i++)
2316 memcpy(&app->link_params[i],
2317 &link_params_default,
2318 sizeof(struct app_link_params));
2320 for (i = 0; i < RTE_DIM(app->hwq_in_params); i++)
2321 memcpy(&app->hwq_in_params[i],
2322 &default_hwq_in_params,
2323 sizeof(default_hwq_in_params));
2325 for (i = 0; i < RTE_DIM(app->hwq_out_params); i++)
2326 memcpy(&app->hwq_out_params[i],
2327 &default_hwq_out_params,
2328 sizeof(default_hwq_out_params));
2330 for (i = 0; i < RTE_DIM(app->swq_params); i++)
2331 memcpy(&app->swq_params[i],
2332 &default_swq_params,
2333 sizeof(default_swq_params));
2335 for (i = 0; i < RTE_DIM(app->tm_params); i++)
2336 memcpy(&app->tm_params[i],
2338 sizeof(default_tm_params));
2340 for (i = 0; i < RTE_DIM(app->source_params); i++)
2341 memcpy(&app->source_params[i],
2342 &default_source_params,
2343 sizeof(default_source_params));
2345 for (i = 0; i < RTE_DIM(app->sink_params); i++)
2346 memcpy(&app->sink_params[i],
2347 &default_sink_params,
2348 sizeof(default_sink_params));
2350 for (i = 0; i < RTE_DIM(app->msgq_params); i++)
2351 memcpy(&app->msgq_params[i],
2352 &default_msgq_params,
2353 sizeof(default_msgq_params));
2355 for (i = 0; i < RTE_DIM(app->pipeline_params); i++)
2356 memcpy(&app->pipeline_params[i],
2357 &default_pipeline_params,
2358 sizeof(default_pipeline_params));
2364 app_config_args(struct app_params *app, int argc, char **argv)
2367 int option_index, f_present, s_present, p_present, l_present;
2370 static struct option lgopts[] = {
2374 /* Copy application name */
2375 strncpy(app->app_name, argv[0], APP_APPNAME_SIZE - 1);
2382 while ((opt = getopt_long(argc, argv, "f:s:p:l:", lgopts,
2383 &option_index)) != EOF)
2387 rte_panic("Error: Config file is provided "
2388 "more than once\n");
2391 if (!strlen(optarg))
2392 rte_panic("Error: Config file name is null\n");
2394 app->config_file = strdup(optarg);
2395 if (app->config_file == NULL)
2396 rte_panic("Error: Memory allocation failure\n");
2402 rte_panic("Error: Script file is provided "
2403 "more than once\n");
2406 if (!strlen(optarg))
2407 rte_panic("Error: Script file name is null\n");
2409 app->script_file = strdup(optarg);
2410 if (app->script_file == NULL)
2411 rte_panic("Error: Memory allocation failure\n");
2417 rte_panic("Error: PORT_MASK is provided "
2418 "more than once\n");
2421 if ((sscanf(optarg, "%" SCNx64 "%n", &app->port_mask,
2423 ((size_t) scaned != strlen(optarg)))
2424 rte_panic("Error: PORT_MASK is not "
2425 "a hexadecimal integer\n");
2427 if (app->port_mask == 0)
2428 rte_panic("Error: PORT_MASK is null\n");
2434 rte_panic("Error: LOG_LEVEL is provided "
2435 "more than once\n");
2438 if ((sscanf(optarg, "%" SCNu32 "%n", &app->log_level,
2440 ((size_t) scaned != strlen(optarg)) ||
2441 (app->log_level >= APP_LOG_LEVELS))
2442 rte_panic("Error: LOG_LEVEL invalid value\n");
2447 app_print_usage(argv[0]);
2450 optind = 0; /* reset getopt lib */
2452 /* Check that mandatory args have been provided */
2454 rte_panic("Error: PORT_MASK is not provided\n");