diff options
| author | 童宗振 <[email protected]> | 2024-08-30 02:58:14 +0000 |
|---|---|---|
| committer | 童宗振 <[email protected]> | 2024-08-30 02:58:14 +0000 |
| commit | 3bc326ea168dfe0ecb6a616bc7f9d2fd25d28974 (patch) | |
| tree | 78044970d22622c41de9c5acee60d208ac8e60a8 | |
| parent | baa980bc0f0446ca199fc81e494dfcc13afbfa99 (diff) | |
Modify the l2fw-nf parameters
| -rw-r--r-- | examples/l2fwd-nf.c | 146 |
1 files changed, 143 insertions, 3 deletions
diff --git a/examples/l2fwd-nf.c b/examples/l2fwd-nf.c index 0c8e8ba..fb97959 100644 --- a/examples/l2fwd-nf.c +++ b/examples/l2fwd-nf.c @@ -29,7 +29,7 @@ unsigned int opt_dump_packet_metadata = 1; unsigned int opt_inject_by_deep_copy = 0; int str_uint_range_parse(const char * str, unsigned int * out, const size_t size); -int core_list_parse(const char * str); +static int mr_parse_corelist(const char * corelist, int * cores); void dump_packet_metadata(marsio_buff_t * buff) { @@ -190,10 +190,21 @@ int main(int argc, char * argv[]) break; } case 'l': { - if (core_list_parse(optarg) < 0) + int lcore_indexes[RTE_MAX_LCORE]; + if (mr_parse_corelist(optarg, lcore_indexes) < 0) { + fprintf(stderr, "%s\n", "invalid core list syntax"); help(); } + CPU_ZERO(&cpu_set_io); + for (unsigned int i = 0; i < RTE_MAX_LCORE; i++) + { + if (lcore_indexes[i] == -1) + { + continue; + } + CPU_SET(i, &cpu_set_io); + } break; } case 'b': { @@ -248,6 +259,134 @@ int main(int argc, char * argv[]) return 0; } +// copy from lib/eal/common/eal_common_options.c +static int check_core_list(int * lcores, unsigned int count) +{ + char lcorestr[RTE_MAX_LCORE * 10]; + bool overflow = false; + int len = 0, ret; + unsigned int i; + + for (i = 0; i < count; i++) + { + if (lcores[i] < RTE_MAX_LCORE) + continue; + + fprintf(stdout, "lcore %d >= RTE_MAX_LCORE (%d)", lcores[i], RTE_MAX_LCORE); + overflow = true; + } + if (!overflow) + return 0; + + /* + * We've encountered a core that's greater than RTE_MAX_LCORE, + * suggest using --lcores option to map lcores onto physical cores + * greater than RTE_MAX_LCORE. + */ + for (i = 0; i < count; i++) + { + ret = snprintf(&lcorestr[len], sizeof(lcorestr) - len, "%d@%d,", i, lcores[i]); + if (ret > 0) + len = len + ret; + } + if (len > 0) + lcorestr[len - 1] = 0; + fprintf(stdout, + "To use high physical core ids, " + "please use --lcores to map them to lcore ids below RTE_MAX_LCORE, " + "e.g. --lcores %s", + lcorestr); + return -1; +} + +static int mr_parse_corelist(const char * corelist, int * cores) +{ + unsigned int count = 0, i; + int lcores[RTE_MAX_LCORE]; + char * end = NULL; + int min, max; + int idx; + + for (idx = 0; idx < RTE_MAX_LCORE; idx++) + cores[idx] = -1; + + /* Remove all blank characters ahead */ + while (isblank(*corelist)) + corelist++; + + /* Get list of cores */ + min = -1; + do + { + while (isblank(*corelist)) + corelist++; + if (*corelist == '\0') + return -1; + errno = 0; + idx = strtol(corelist, &end, 10); + if (errno || end == NULL) + return -1; + if (idx < 0) + return -1; + while (isblank(*end)) + end++; + if (*end == '-') + { + min = idx; + } + else if ((*end == ',') || (*end == '\0')) + { + max = idx; + if (min == -1) + min = idx; + for (idx = min; idx <= max; idx++) + { + bool dup = false; + + /* Check if this idx is already present */ + for (i = 0; i < count; i++) + { + if (lcores[i] == idx) + dup = true; + } + if (dup) + continue; + if (count >= RTE_MAX_LCORE) + { + fprintf(stdout, "Too many lcores provided. Cannot exceed RTE_MAX_LCORE (%d)", RTE_MAX_LCORE); + return -1; + } + lcores[count++] = idx; + } + min = -1; + } + else + return -1; + corelist = end + 1; + } while (*end != '\0'); + + if (count == 0) + return -1; + + if (check_core_list(lcores, count)) + return -1; + + /* + * Now that we've got a list of cores no longer than RTE_MAX_LCORE, + * and no lcore in that list is greater than RTE_MAX_LCORE, populate + * the cores array. + */ + do + { + count--; + cores[lcores[count]] = count; + } while (count != 0); + + return 0; +} + +#if 0 +// Remove the following code later int core_list_parse(const char * str) { unsigned int io_cores[128] = {}; @@ -291,4 +430,5 @@ int str_uint_range_parse(const char * str, unsigned int * out, const size_t size end: free(line); return ret; -}
\ No newline at end of file +} +#endif
\ No newline at end of file |
