[dpdk-dev] [PATCH] eal: add option --avail-cores to detect lcores
Jianfeng Tan
jianfeng.tan at intel.com
Fri Mar 4 11:05:57 CET 2016
This patch adds option, --avail-cores, to use lcores which are available
by calling pthread_getaffinity_np() to narrow down detected cores before
parsing coremask (-c), corelist (-l), and coremap (--lcores).
Test example:
$ taskset 0xc0000 ./examples/helloworld/build/helloworld \
--avail-cores -m 1024
Signed-off-by: Jianfeng Tan <jianfeng.tan at intel.com>
Acked-by: Neil Horman <nhorman at tuxdriver.com>
---
lib/librte_eal/common/eal_common_options.c | 52 ++++++++++++++++++++++++++++++
lib/librte_eal/common/eal_options.h | 2 ++
2 files changed, 54 insertions(+)
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 29942ea..dc4882d 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -95,6 +95,7 @@ eal_long_options[] = {
{OPT_VFIO_INTR, 1, NULL, OPT_VFIO_INTR_NUM },
{OPT_VMWARE_TSC_MAP, 0, NULL, OPT_VMWARE_TSC_MAP_NUM },
{OPT_XEN_DOM0, 0, NULL, OPT_XEN_DOM0_NUM },
+ {OPT_AVAIL_CORES, 0, NULL, OPT_AVAIL_CORES_NUM },
{0, 0, NULL, 0 }
};
@@ -681,6 +682,37 @@ err:
}
static int
+eal_parse_avail_cores(void)
+{
+ int i, count;
+ pthread_t tid;
+ rte_cpuset_t cpuset;
+ struct rte_config *cfg = rte_eal_get_configuration();
+
+ tid = pthread_self();
+ if (pthread_getaffinity_np(tid, sizeof(rte_cpuset_t), &cpuset) != 0)
+ return -1;
+
+ for (i = 0, count = 0; i < RTE_MAX_LCORE; i++) {
+ if (lcore_config[i].detected && !CPU_ISSET(i, &cpuset)) {
+ RTE_LOG(DEBUG, EAL, "Flag lcore %u as undetected\n", i);
+ lcore_config[i].detected = 0;
+ lcore_config[i].core_index = -1;
+ cfg->lcore_role[i] = ROLE_OFF;
+ count++;
+ }
+ }
+ cfg->lcore_count -= count;
+ if (cfg->lcore_count == 0) {
+ RTE_LOG(ERR, EAL, "No lcores available\n");
+ return -1;
+ }
+
+ return 0;
+}
+
+
+static int
eal_parse_syslog(const char *facility, struct internal_config *conf)
{
int i;
@@ -754,6 +786,10 @@ eal_parse_proc_type(const char *arg)
return RTE_PROC_INVALID;
}
+static int param_coremask;
+static int param_corelist;
+static int param_coremap;
+
int
eal_parse_common_option(int opt, const char *optarg,
struct internal_config *conf)
@@ -775,6 +811,7 @@ eal_parse_common_option(int opt, const char *optarg,
break;
/* coremask */
case 'c':
+ param_coremask = 1;
if (eal_parse_coremask(optarg) < 0) {
RTE_LOG(ERR, EAL, "invalid coremask\n");
return -1;
@@ -782,6 +819,7 @@ eal_parse_common_option(int opt, const char *optarg,
break;
/* corelist */
case 'l':
+ param_corelist = 1;
if (eal_parse_corelist(optarg) < 0) {
RTE_LOG(ERR, EAL, "invalid core list\n");
return -1;
@@ -890,12 +928,25 @@ eal_parse_common_option(int opt, const char *optarg,
break;
}
case OPT_LCORES_NUM:
+ param_coremap = 1;
if (eal_parse_lcores(optarg) < 0) {
RTE_LOG(ERR, EAL, "invalid parameter for --"
OPT_LCORES "\n");
return -1;
}
break;
+ case OPT_AVAIL_CORES_NUM:
+ if (param_coremask || param_corelist || param_coremap) {
+ RTE_LOG(ERR, EAL, "should put --" OPT_AVAIL_CORES
+ " before -c, -l and --" OPT_LCORES "\n");
+ return -1;
+ }
+ if (eal_parse_avail_cores() < 0) {
+ RTE_LOG(ERR, EAL, "failed to use --"
+ OPT_AVAIL_CORES "\n");
+ return -1;
+ }
+ break;
/* don't know what to do, leave this to caller */
default:
@@ -990,6 +1041,7 @@ eal_common_usage(void)
" ',' is used for single number separator.\n"
" '( )' can be omitted for single element group,\n"
" '@' can be omitted if cpus and lcores have the same value\n"
+ " --"OPT_AVAIL_CORES" Use pthread_getaffinity_np() to detect cores to be used\n"
" --"OPT_MASTER_LCORE" ID Core ID that is used as master\n"
" -n CHANNELS Number of memory channels\n"
" -m MB Memory to allocate (see also --"OPT_SOCKET_MEM")\n"
diff --git a/lib/librte_eal/common/eal_options.h b/lib/librte_eal/common/eal_options.h
index a881c62..b2ddea3 100644
--- a/lib/librte_eal/common/eal_options.h
+++ b/lib/librte_eal/common/eal_options.h
@@ -83,6 +83,8 @@ enum {
OPT_VMWARE_TSC_MAP_NUM,
#define OPT_XEN_DOM0 "xen-dom0"
OPT_XEN_DOM0_NUM,
+#define OPT_AVAIL_CORES "avail-cores"
+ OPT_AVAIL_CORES_NUM,
OPT_LONG_MAX_NUM
};
--
2.1.4
More information about the dev
mailing list