[ovs-dev] [PATCH 5/8] netdev-dpdk: Autofill lcore coremask if absent
Aaron Conole
aconole at redhat.com
Fri Apr 1 03:22:46 UTC 2016
The user has control over the DPDK internal lcore coremask, but this
parameter can be autofilled with a bit more intelligence. If the user
does not fill this parameter in, we use the lowest set bit in the
current task CPU affinity. Otherwise, we will reassign the current
thread to the specified lcore mask, in addition to the dpdk lcore
threads.
Signed-off-by: Aaron Conole <aconole at redhat.com>
Tested-by: Sean K Mooney <sean.k.mooney at intel.com>
Tested-by: RobertX Wojciechowicz <robertx.wojciechowicz at intel.com>
Tested-by: Kevin Traynor <kevin.traynor at intel.com>
Acked-by: Panu Matilainen <pmatilai at redhat.com>
Acked-by: Kevin Traynor <kevin.traynor at intel.com>
Acked-by: Flavio Leitner <fbl at sysclose.org>
---
v2:
* Fix a conditional branch coding standard issue
* When lcore coremask is set, do not reset the affinities as
suggested by Kevin Traynor
v3:
* Fixed grow_argv calls
* Fixed an error in argc assignment after 'break;' introduced
in v2
* Switched to using xstrdup
v4->v7:
* No change
v8:
* Assign the lcore only when resetting the affinity.
v9,v10:
* No change
v11:
* Minor refactors due to previous changes
* Cleanups suggested by Daniele
lib/netdev-dpdk.c | 40 +++++++++++++++++++++++++++++++++-------
1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index 7705c7a..c84a2b8 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2792,7 +2792,6 @@ construct_dpdk_options(const struct ovsrec_open_vswitch *ovs_cfg,
{"dpdk-mem-channels", "-n", false, NULL},
{"dpdk-hugepage-dir", "--huge-dir", false, NULL},
};
-
int i, ret = initial_size;
/*First, construct from the flat-options (non-mutex)*/
@@ -2873,9 +2872,10 @@ construct_dpdk_mutex_options(const struct ovsrec_open_vswitch *ovs_cfg,
}
static int
-get_dpdk_args(const struct ovsrec_open_vswitch *ovs_cfg, char ***argv)
+get_dpdk_args(const struct ovsrec_open_vswitch *ovs_cfg, char ***argv,
+ int argc)
{
- int i = construct_dpdk_options(ovs_cfg, argv, 1);
+ int i = construct_dpdk_options(ovs_cfg, argv, argc);
i = construct_dpdk_mutex_options(ovs_cfg, argv, i);
return i;
}
@@ -2899,7 +2899,8 @@ dpdk_init__(const struct ovsrec_open_vswitch *ovs_cfg)
{
char **argv = NULL;
int result;
- int argc;
+ int argc, argc_tmp;
+ bool auto_determine = true;
int err;
cpu_set_t cpuset;
#ifndef VHOST_CUSE
@@ -2939,9 +2940,34 @@ dpdk_init__(const struct ovsrec_open_vswitch *ovs_cfg)
VLOG_ERR("Thread getaffinity error %d.", err);
}
- argv = grow_argv(&argv, 0, 1);
+ argv = grow_argv(&argv, argc, 1);
argv[0] = xstrdup(ovs_get_program_name());
- argc = get_dpdk_args(ovs_cfg, &argv);
+ argc_tmp = get_dpdk_args(ovs_cfg, &argv, argc);
+
+ while (argc_tmp != argc) {
+ if (!strcmp("-c", argv[argc]) || !strcmp("-l", argv[argc])) {
+ auto_determine = false;
+ break;
+ }
+ argc++;
+ }
+ argc = argc_tmp;
+
+ /**
+ * NOTE: This is an unsophisticated mechanism for determining the DPDK
+ * lcore for the DPDK Master.
+ */
+ 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;
+ }
+ }
+ }
argv = grow_argv(&argv, argc, 1);
argv[argc] = 0;
@@ -2955,7 +2981,7 @@ dpdk_init__(const struct ovsrec_open_vswitch *ovs_cfg)
}
/* Set the main thread affinity back to pre rte_eal_init() value */
- if (!err) {
+ if (auto_determine) {
err = pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t),
&cpuset);
if (err) {
--
2.5.5
More information about the dev
mailing list