diff options
author | Zoltan Kiss <zoltan.kiss@linaro.org> | 2015-11-24 18:13:40 +0000 |
---|---|---|
committer | Zoltan Kiss <zoltan.kiss@linaro.org> | 2015-11-24 18:30:19 +0000 |
commit | d0fe316d5404b84212978931faa7d53c64a4efcc (patch) | |
tree | 35d37f33b2adb9f4ee379d11188bc2a65dda61af | |
parent | e2e0a537c2953d8e67b45ac5fb4f66157e28378b (diff) |
linux-dpdk: init: fix cpumask string allocation
The calloc() has several issues in calculating the string size:
- doesn't account for the "0x" prefix
- nor the space after the core mask
- sizeof(core_mask) should be doubled, as each byte can be represented as two
hex characters
But also the width of coremask cause a limitation. This patch uses the
odp_cpumask_*() functions to create a proper mask.
Reported-by: Stuart Haslam <stuart.haslam@linaro.org>
Signed-off-by: Zoltan Kiss <zoltan.kiss@linaro.org>
-rw-r--r-- | platform/linux-dpdk/odp_init.c | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/platform/linux-dpdk/odp_init.c b/platform/linux-dpdk/odp_init.c index e8eab7ae7..3d7ccd202 100644 --- a/platform/linux-dpdk/odp_init.c +++ b/platform/linux-dpdk/odp_init.c @@ -11,6 +11,7 @@ #include <odp_packet_dpdk.h> #include <odp_debug_internal.h> #include <odp/system_info.h> +#include <odp/cpumask.h> #include <unistd.h> #define PMD_EXT(drv) extern void devinitfn_##drv(void); @@ -168,7 +169,10 @@ int odp_init_dpdk(const char *cmdline) char **dpdk_argv; int dpdk_argc; char *full_cmdline; - int core_mask, i, save_optind; + int i, save_optind; + odp_cpumask_t mask; + char mask_str[ODP_CPUMASK_STR_SIZE]; + int32_t masklen; if (cmdline == NULL) { cmdline = getenv("ODP_PLATFORM_PARAMS"); @@ -178,14 +182,22 @@ int odp_init_dpdk(const char *cmdline) } } - for (i = 0, core_mask = 0; i < odp_cpu_count(); i++) - core_mask += (0x1 << i); + odp_cpumask_zero(&mask); + for (i = 0; i < odp_cpu_count(); i++) + odp_cpumask_set(&mask, i); + masklen = odp_cpumask_to_str(&mask, mask_str, ODP_CPUMASK_STR_SIZE); - full_cmdline = calloc(1, strlen(cmdline) + strlen("odpdpdk -c ") + - sizeof(core_mask) + 1); + if (masklen < 0) { + ODP_ERR("CPU mask error: d\n", masklen); + return -1; + } + + /* masklen includes the terminating null as well */ + full_cmdline = calloc(1, strlen("odpdpdk -c ") + masklen + + strlen(" ") + strlen(cmdline)); /* first argument is facility log, simply bind it to odpdpdk for now.*/ - sprintf(full_cmdline, "odpdpdk -c 0x%x %s", core_mask, cmdline); + sprintf(full_cmdline, "odpdpdk -c %s %s", mask_str, cmdline); parse_dpdk_args(full_cmdline, &dpdk_argc, &dpdk_argv); for (i = 0; i < dpdk_argc; ++i) |