From patchwork Thu Sep 1 01:31:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jianfeng Tan X-Patchwork-Id: 15576 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 439C42BCD; Thu, 1 Sep 2016 03:31:46 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id E5D6E11D4 for ; Thu, 1 Sep 2016 03:31:43 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 31 Aug 2016 18:31:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.30,264,1470726000"; d="scan'208";a="755748373" Received: from dpdk06.sh.intel.com ([10.239.129.195]) by FMSMGA003.fm.intel.com with ESMTP; 31 Aug 2016 18:31:41 -0700 From: Jianfeng Tan To: dev@dpdk.org Cc: david.marchand@6wind.com, pmatilai@redhat.com, thomas.monjalon@6wind.com, stephen@networkplumber.org, Jianfeng Tan Date: Thu, 1 Sep 2016 01:31:47 +0000 Message-Id: <1472693507-11369-1-git-send-email-jianfeng.tan@intel.com> X-Mailer: git-send-email 2.7.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 v3] eal: restrict cores detection 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch uses pthread_getaffinity_np() to narrow down detected cores before parsing 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 only specify core restriction as starting the instance. 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 --- 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_lcore.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/common/eal_common_lcore.c b/lib/librte_eal/common/eal_common_lcore.c index 2cd4132..71c575c 100644 --- a/lib/librte_eal/common/eal_common_lcore.c +++ b/lib/librte_eal/common/eal_common_lcore.c @@ -57,6 +57,12 @@ rte_eal_cpu_init(void) struct rte_config *config = rte_eal_get_configuration(); unsigned lcore_id; unsigned count = 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); /* * Parse the maximum set of logical cores, detect the subset of running @@ -70,7 +76,8 @@ rte_eal_cpu_init(void) /* in 1:1 mapping, record related cpu detected state */ lcore_config[lcore_id].detected = eal_cpu_detected(lcore_id); - if (lcore_config[lcore_id].detected == 0) { + if (lcore_config[lcore_id].detected == 0 || + !CPU_ISSET(lcore_id, &affinity_set)) { config->lcore_role[lcore_id] = ROLE_OFF; lcore_config[lcore_id].core_index = -1; continue;