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 7E5BE2A1A for ; Tue, 26 Apr 2016 14:39:33 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP; 26 Apr 2016 05:39:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,536,1455004800"; d="scan'208";a="953177926" Received: from shwdeisgchi083.ccr.corp.intel.com (HELO [10.239.67.193]) ([10.239.67.193]) by fmsmga001.fm.intel.com with ESMTP; 26 Apr 2016 05:39:31 -0700 To: dev@dpdk.org References: <1453661393-85704-1-git-send-email-jianfeng.tan@intel.com> <1457085957-115339-1-git-send-email-jianfeng.tan@intel.com> Cc: david.marchand@6wind.com, sergio.gonzalez.monroy@intel.com, nhorman@tuxdriver.com, konstantin.ananyev@intel.com From: "Tan, Jianfeng" Message-ID: <571F6182.2040703@intel.com> Date: Tue, 26 Apr 2016 20:39:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: <1457085957-115339-1-git-send-email-jianfeng.tan@intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [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: Tue, 26 Apr 2016 12:39:34 -0000 Hi, Since some guys are asking about the status of this patch, I'd like to ping if anyone still has concerns. Current conclusion is: with option --avail-cores. Thanks, Jianfeng On 3/4/2016 6:05 PM, Jianfeng Tan wrote: > 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 > }; >