@@ -42,6 +42,7 @@
*/
typedef struct {
int cpu_count; /**< system CPU count */
+ const char *mask; /**< core mask */
int if_count; /**< Number of interfaces to be used */
char **if_names; /**< Array of pointers to interface names */
char *if_str; /**< Storage for interface names */
@@ -633,18 +634,27 @@ int main(int argc, char *argv[])
if (args->appl.cpu_count)
num_workers = args->appl.cpu_count;
- /* ping mode need two worker */
- if (args->appl.mode == APPL_MODE_PING)
- num_workers = 2;
+ if (args->appl.mask) {
+ (void)odp_cpumask_from_str(&cpumask, args->appl.mask);
+ num_workers = odp_cpumask_count(&cpumask);
+ } else {
+ num_workers = odp_cpumask_def_worker(&cpumask, num_workers);
+ }
- /* Get default worker cpumask */
- num_workers = odp_cpumask_def_worker(&cpumask, num_workers);
(void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr));
printf("num worker threads: %i\n", num_workers);
printf("first CPU: %i\n", odp_cpumask_first(&cpumask));
printf("cpu mask: %s\n", cpumaskstr);
+ /* ping mode need two workers */
+ if (args->appl.mode == APPL_MODE_PING) {
+ if (num_workers < 2) {
+ EXAMPLE_ERR("Need at least two worker threads\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+
/* Create packet pool */
memset(¶ms, 0, sizeof(params));
params.pkt.seg_len = SHM_PKT_POOL_BUF_SIZE;
@@ -692,12 +702,13 @@ int main(int argc, char *argv[])
memset(thread_tbl, 0, sizeof(thread_tbl));
if (args->appl.mode == APPL_MODE_PING) {
- odp_cpumask_t cpu0_mask;
+ odp_cpumask_t cpu_mask;
odp_queue_t tq;
+ int cpu_first, cpu_next;
- /* Previous code forced both threads to CPU 0 */
- odp_cpumask_zero(&cpu0_mask);
- odp_cpumask_set(&cpu0_mask, 0);
+ odp_cpumask_zero(&cpu_mask);
+ cpu_first = odp_cpumask_first(&cpumask);
+ odp_cpumask_set(&cpu_mask, cpu_first);
tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL);
if (tq == ODP_QUEUE_INVALID)
@@ -713,7 +724,7 @@ int main(int argc, char *argv[])
if (args->thread[1].tmo_ev == ODP_TIMEOUT_INVALID)
abort();
args->thread[1].mode = args->appl.mode;
- odph_linux_pthread_create(&thread_tbl[1], &cpu0_mask,
+ odph_linux_pthread_create(&thread_tbl[1], &cpu_mask,
gen_recv_thread, &args->thread[1]);
tq = odp_queue_create("", ODP_QUEUE_TYPE_POLL, NULL);
@@ -730,7 +741,10 @@ int main(int argc, char *argv[])
if (args->thread[0].tmo_ev == ODP_TIMEOUT_INVALID)
abort();
args->thread[0].mode = args->appl.mode;
- odph_linux_pthread_create(&thread_tbl[0], &cpu0_mask,
+ cpu_next = odp_cpumask_next(&cpumask, cpu_first);
+ odp_cpumask_zero(&cpu_mask);
+ odp_cpumask_set(&cpu_mask, cpu_next);
+ odph_linux_pthread_create(&thread_tbl[0], &cpu_mask,
gen_send_thread, &args->thread[0]);
/* only wait send thread to join */
@@ -812,6 +826,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
static struct option longopts[] = {
{"interface", required_argument, NULL, 'I'},
{"workers", required_argument, NULL, 'w'},
+ {"coremask", required_argument, NULL, 'k'},
{"srcmac", required_argument, NULL, 'a'},
{"dstmac", required_argument, NULL, 'b'},
{"srcip", required_argument, NULL, 'c'},
@@ -831,7 +846,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
appl_args->timeout = -1;
while (1) {
- opt = getopt_long(argc, argv, "+I:a:b:c:d:s:i:m:n:t:w:h",
+ opt = getopt_long(argc, argv, "+I:a:b:c:d:s:i:m:n:t:w:k:h",
longopts, &long_index);
if (opt == -1)
break; /* No more options */
@@ -840,6 +855,15 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args)
case 'w':
appl_args->cpu_count = atoi(optarg);
break;
+ case 'k':
+ len = strlen(optarg);
+ if (len == 0) {
+ usage(argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ appl_args->mask = optarg;
+ break;
/* parse packet-io interface names */
case 'I':
len = strlen(optarg);
@@ -1029,6 +1053,9 @@ static void usage(char *progname)
" -t, --timeout only for ping mode, wait ICMP reply timeout seconds\n"
" -i, --interval wait interval ms between sending each packet\n"
" default is 1000ms. 0 for flood mode\n"
+ " -w, --workers specify number of workers need to be assigned to application\n"
+ " default is to assign all\n"
+ " -k, --coremask to set on cores\n"
"\n"
"Optional OPTIONS\n"
" -h, --help Display help and exit.\n"
Signed-off-by: Balakrishna.Garapati <balakrishna.garapati@linaro.org> --- Fixed cpu_mask for PING mode. The mask is set to what is actually supplied. example/generator/odp_generator.c | 51 ++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 12 deletions(-)