From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 842CE2B9E for ; Fri, 4 Mar 2016 18:06:34 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 04 Mar 2016 09:06:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.22,536,1449561600"; d="scan'208";a="901426604" Received: from dpdk06.sh.intel.com ([10.239.128.225]) by orsmga001.jf.intel.com with ESMTP; 04 Mar 2016 09:06:31 -0800 From: Jianfeng Tan To: dev@dpdk.org Date: Fri, 4 Mar 2016 18:05:57 +0800 Message-Id: <1457085957-115339-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453661393-85704-1-git-send-email-jianfeng.tan@intel.com> References: <1453661393-85704-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH] eal: add option --avail-cores to detect lcores X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Mar 2016 17:06:35 -0000 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 Acked-by: Neil Horman --- 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