Skip to content

Commit

Permalink
netdev-dpdk: Improve pthread_getaffinity_np() fail handling.
Browse files Browse the repository at this point in the history
Prevent pthread_setaffinity_np() being called with a potentially
invalid cpu_set_t and add a default (core 0x1).

Also, only call pthread_getaffinity_np() if no dpdk-lcore-mask specified.

Signed-off-by: Kevin Traynor <[email protected]>
Acked-by: Aaron Conole <[email protected]>
Acked-by: Daniele Di Proietto <[email protected]>
  • Loading branch information
kevintraynor authored and ddiproietto committed May 21, 2016
1 parent 30149e2 commit d8e2f4c
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions lib/netdev-dpdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ dpdk_init__(const struct smap *ovs_other_config)
int result;
int argc, argc_tmp;
bool auto_determine = true;
int err;
int err = 0;
cpu_set_t cpuset;
#ifndef VHOST_CUSE
char *sock_dir_subcomponent;
Expand Down Expand Up @@ -3126,14 +3126,6 @@ dpdk_init__(const struct smap *ovs_other_config)
#endif
}

/* Get the main thread affinity */
CPU_ZERO(&cpuset);
err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t),
&cpuset);
if (err) {
VLOG_ERR("Thread getaffinity error %d.", err);
}

argv = grow_argv(&argv, 0, 1);
argc = 1;
argv[0] = xstrdup(ovs_get_program_name());
Expand All @@ -3154,13 +3146,26 @@ dpdk_init__(const struct smap *ovs_other_config)
*/
if (auto_determine) {
int i;
for (i = 0; i < CPU_SETSIZE; i++) {
if (CPU_ISSET(i, &cpuset)) {
argv = grow_argv(&argv, argc, 2);
argv[argc++] = xstrdup("-c");
argv[argc++] = xasprintf("0x%08llX", (1ULL<<i));
i = CPU_SETSIZE;
/* Get the main thread affinity */
CPU_ZERO(&cpuset);
err = pthread_getaffinity_np(pthread_self(), sizeof(cpu_set_t),
&cpuset);
if (!err) {
for (i = 0; i < CPU_SETSIZE; i++) {
if (CPU_ISSET(i, &cpuset)) {
argv = grow_argv(&argv, argc, 2);
argv[argc++] = xstrdup("-c");
argv[argc++] = xasprintf("0x%08llX", (1ULL<<i));
i = CPU_SETSIZE;
}
}
} else {
VLOG_ERR("Thread getaffinity error %d. Using core 0x1", err);
/* User did not set dpdk-lcore-mask and unable to get current
* thread affintity - default to core 0x1 */
argv = grow_argv(&argv, argc, 2);
argv[argc++] = xstrdup("-c");
argv[argc++] = xasprintf("0x%X", 1);
}
}

Expand Down Expand Up @@ -3189,7 +3194,7 @@ dpdk_init__(const struct smap *ovs_other_config)
}

/* Set the main thread affinity back to pre rte_eal_init() value */
if (auto_determine) {
if (auto_determine && !err) {
err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
&cpuset);
if (err) {
Expand Down

0 comments on commit d8e2f4c

Please sign in to comment.