From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 6696A58CE for ; Fri, 2 Dec 2016 18:48:21 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP; 02 Dec 2016 09:48:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.33,287,1477983600"; d="scan'208";a="1067171345" Received: from dpdk06.sh.intel.com ([10.239.129.195]) by orsmga001.jf.intel.com with ESMTP; 02 Dec 2016 09:48:18 -0800 From: Jianfeng Tan To: dev@dpdk.org Cc: david.marchand@6wind.com, pmatilai@redhat.com, bruce.richardson@intel.com, Jianfeng Tan Date: Fri, 2 Dec 2016 17:48:56 +0000 Message-Id: <1480700936-8450-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1472693507-11369-1-git-send-email-jianfeng.tan@intel.com> References: <1472693507-11369-1-git-send-email-jianfeng.tan@intel.com> Subject: [dpdk-dev] [PATCH v4] eal: restrict cores auto detection X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Dec 2016 17:48:21 -0000 This patch uses pthread_getaffinity_np() to narrow down used cores when none of below options is specified: * coremask (-c) * corelist (-l) * and coremap (--lcores) The purpose of this patch is to leave out these core related options when DPDK applications are deployed under container env, so that users do not need decide the core related parameters when developing applications. Instead, when applications are deployed in containers, use cpu-set to constrain which cores can be used inside this container instance. And DPDK application inside containers just rely on this auto detect mechanism to start polling threads. Note: previously, some users are using isolated CPUs, which could be excluded by default. Please add commands like taskset to use those cores. Test example: $ taskset 0xc0000 ./examples/helloworld/build/helloworld -m 1024 Signed-off-by: Jianfeng Tan Acked-by: Neil Horman --- v4: - Address Bruce's comment: only enable this auto detection mechanism when none of core options is specified. - More detailed use case on how it helps in containers. v3: - Choose a more descriptive variable name, and remove comments as suggested by Stephen Hemminger. v2: - Make it as default instead of adding the new options. --- lib/librte_eal/common/eal_common_options.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c index 6ca8af1..d192de1 100644 --- a/lib/librte_eal/common/eal_common_options.c +++ b/lib/librte_eal/common/eal_common_options.c @@ -126,6 +126,7 @@ static const char dpdk_solib_path[] __attribute__((used)) = static int master_lcore_parsed; static int mem_parsed; +static int core_specified; void eal_reset_internal_config(struct internal_config *internal_cfg) @@ -797,6 +798,7 @@ eal_parse_common_option(int opt, const char *optarg, RTE_LOG(ERR, EAL, "invalid coremask\n"); return -1; } + core_specified = 1; break; /* corelist */ case 'l': @@ -804,6 +806,7 @@ eal_parse_common_option(int opt, const char *optarg, RTE_LOG(ERR, EAL, "invalid core list\n"); return -1; } + core_specified = 1; break; /* size of memory */ case 'm': @@ -912,6 +915,7 @@ eal_parse_common_option(int opt, const char *optarg, OPT_LCORES "\n"); return -1; } + core_specified = 1; break; /* don't know what to do, leave this to caller */ @@ -923,12 +927,38 @@ eal_parse_common_option(int opt, const char *optarg, return 0; } +static void +eal_auto_detect_cores(struct rte_config *cfg) +{ + unsigned int lcore_id; + unsigned int removed = 0; + rte_cpuset_t affinity_set; + pthread_t tid = pthread_self(); + + if (pthread_getaffinity_np(tid, sizeof(rte_cpuset_t), + &affinity_set) < 0) + CPU_ZERO(&affinity_set); + + for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { + if (cfg->lcore_role[lcore_id] == ROLE_RTE && + !CPU_ISSET(lcore_id, &affinity_set)) { + cfg->lcore_role[lcore_id] = ROLE_OFF; + removed++; + } + } + + cfg->lcore_count -= removed; +} + int eal_adjust_config(struct internal_config *internal_cfg) { int i; struct rte_config *cfg = rte_eal_get_configuration(); + if (!core_specified) + eal_auto_detect_cores(cfg); + if (internal_config.process_type == RTE_PROC_AUTO) internal_config.process_type = eal_proc_type_detect(); -- 2.7.4