From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 5AA775599 for ; Thu, 23 Mar 2017 16:10:10 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1490281810; x=1521817810; h=from:to:cc:subject:date:message-id; bh=qByo5vAMZM1ZxyFNXF2YZ7RJS9wQBR6qhz48Hegi/XI=; b=hQDhaIBln6xTVMKzrRKh8vPn5AliGevNQofNrdP7NyQUgAUQzltYcian 8dvci3g9SqQ2w1T4HT0YtblF6RgXDA==; Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Mar 2017 08:10:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,210,1486454400"; d="scan'208";a="1111459883" Received: from sivswdev01.ir.intel.com ([10.237.217.45]) by orsmga001.jf.intel.com with ESMTP; 23 Mar 2017 08:10:06 -0700 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Date: Thu, 23 Mar 2017 15:09:58 +0000 Message-Id: <20170323150958.17089-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.8.4 Subject: [dpdk-dev] [PATCH] eal/bsd: query the cpu count only once 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: Thu, 23 Mar 2017 15:10:10 -0000 Rather than querying the number of CPUs on the system multiple times, and printing out the number each time, just query the value from sysctl once and store it for future reuse. Signed-off-by: Bruce Richardson --- lib/librte_eal/bsdapp/eal/eal_lcore.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c index b8bfafde0..bc584dd53 100644 --- a/lib/librte_eal/bsdapp/eal/eal_lcore.c +++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c @@ -53,12 +53,14 @@ eal_cpu_core_id(__rte_unused unsigned lcore_id) static int eal_get_ncpus(void) { + static int ncpu = -1; int mib[2] = {CTL_HW, HW_NCPU}; - int ncpu; size_t len = sizeof(ncpu); - sysctl(mib, 2, &ncpu, &len, NULL, 0); - RTE_LOG(INFO, EAL, "Sysctl reports %d cpus\n", ncpu); + if (ncpu < 0) { + sysctl(mib, 2, &ncpu, &len, NULL, 0); + RTE_LOG(INFO, EAL, "Sysctl reports %d cpus\n", ncpu); + } return ncpu; } -- 2.11.0