From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thomas Monjalon Subject: Re: [PATCH v3] eal: restrict cores detection Date: Fri, 16 Sep 2016 07:02:01 -0700 (PDT) Message-ID: <2025520.348ocWrbUD@xps13> References: <1453661393-85704-1-git-send-email-jianfeng.tan@intel.com> <1472693507-11369-1-git-send-email-jianfeng.tan@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7Bit Cc: dev@dpdk.org, david.marchand@6wind.com, pmatilai@redhat.com, stephen@networkplumber.org To: Jianfeng Tan Return-path: Received: from mail-wm0-f51.google.com (mail-wm0-f51.google.com [74.125.82.51]) by dpdk.org (Postfix) with ESMTP id B28EA6CC7 for ; Fri, 16 Sep 2016 16:02:02 +0200 (CEST) Received: by mail-wm0-f51.google.com with SMTP id 1so43576383wmz.1 for ; Fri, 16 Sep 2016 07:02:02 -0700 (PDT) In-Reply-To: <1472693507-11369-1-git-send-email-jianfeng.tan@intel.com> 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" 2016-09-01 01:31, Jianfeng Tan: > 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. [...] > --- 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(); > + A comment is needed here to explain which errors we are checking. > + 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; >