From patchwork Mon Jul 27 00:56:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 6599 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 084D9C4E6; Mon, 27 Jul 2015 02:57:56 +0200 (CEST) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by dpdk.org (Postfix) with ESMTP id 68CD4C4E4 for ; Mon, 27 Jul 2015 02:57:55 +0200 (CEST) Received: by wibxm9 with SMTP id xm9so95417034wib.1 for ; Sun, 26 Jul 2015 17:57:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/S04XxCS6QyaJI8jQNq/KbGXLaW6qVFy+pbOfQCMKWI=; b=BqzEipZjhoBpu8ITydir3YGJqUmbi0U2he5PXJqkC3logSof2qhOil41oaM24K+7eF zH8YGxSlAPqua+NuTEGZA5+Xs4C2IJGAIJjdEVEZ2GyRQat7Dx+3/LiElUeNSChV10Xx EbrRDqWPJ4fGoE4GWD205U89pcXGNysRwkVGqs1M9Lrcx9AebfJytdS1buV9b1Bq/Ck2 TETYsWEtkHQpMdhNd5C3+BPVl4QK0xIPrHYAaQ32SH8tDybGXOg1tTsELKp1KQ8ZObfY bCLVZHvmXSxDUYLhEMjX81s80qYDqXC1uuKVEyYxvrsw1+njZKDvb7Vik1xK/aKFkix2 j/gA== X-Gm-Message-State: ALoCoQklqqWrnFPeFSo0KJQY2rHAT7DXDZ0/I6nFGd5xdzj1VrDiK8BIeYwvUhZZkNlclsFFBqoI X-Received: by 10.194.77.179 with SMTP id t19mr52911817wjw.30.1437958675310; Sun, 26 Jul 2015 17:57:55 -0700 (PDT) Received: from localhost.localdomain (136-92-190-109.dsl.ovh.fr. [109.190.92.136]) by smtp.gmail.com with ESMTPSA id dz4sm10733801wib.17.2015.07.26.17.57.53 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 26 Jul 2015 17:57:54 -0700 (PDT) From: Thomas Monjalon To: david.marchand@6wind.com Date: Mon, 27 Jul 2015 02:56:32 +0200 Message-Id: <1437958594-29468-2-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.4.2 In-Reply-To: <1437958594-29468-1-git-send-email-thomas.monjalon@6wind.com> References: <1437852868-6031-1-git-send-email-rkerur@gmail.com> <1437958594-29468-1-git-send-email-thomas.monjalon@6wind.com> Cc: dev@dpdk.org Subject: [dpdk-dev] [PATCH v10 1/3] eal: deduplicate lcore initialization 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" From: Ravi Kerur Implement cpu_detected() for BSD. Move common function in eal_lcore.c to eal_common_lcore.c file. Signed-off-by: Ravi Kerur --- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/bsdapp/eal/eal_lcore.c | 72 +++++----------------- .../eal/eal_lcore.c => common/eal_common_lcore.c} | 52 ++++++---------- lib/librte_eal/common/eal_private.h | 14 +++++ lib/librte_eal/linuxapp/eal/Makefile | 2 + lib/librte_eal/linuxapp/eal/eal_lcore.c | 66 ++------------------ 6 files changed, 55 insertions(+), 152 deletions(-) copy lib/librte_eal/{bsdapp/eal/eal_lcore.c => common/eal_common_lcore.c} (75%) diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile index 01e5972..24733ae 100644 --- a/lib/librte_eal/bsdapp/eal/Makefile +++ b/lib/librte_eal/bsdapp/eal/Makefile @@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_interrupts.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_alarm.c # from common dir +SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_lcore.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/bsdapp/eal/eal_lcore.c index 162fb4f..b47eb1b 100644 --- a/lib/librte_eal/bsdapp/eal/eal_lcore.c +++ b/lib/librte_eal/bsdapp/eal/eal_lcore.c @@ -44,11 +44,14 @@ #include "eal_thread.h" /* No topology information available on FreeBSD including NUMA info */ -#define cpu_core_id(X) 0 -#define cpu_socket_id(X) 0 +unsigned +eal_cpu_core_id(__rte_unused unsigned lcore_id) +{ + return 0; +} static int -get_ncpus(void) +eal_get_ncpus(void) { int mib[2] = {CTL_HW, HW_NCPU}; int ncpu; @@ -59,63 +62,18 @@ get_ncpus(void) return ncpu; } -/* - * fill the cpu_info structure with as much info as we can get. - * code is similar to linux version, but sadly available info is less. - */ -int -rte_eal_cpu_init(void) +unsigned +eal_cpu_socket_id(__rte_unused unsigned cpu_id) { - /* pointer to global configuration */ - struct rte_config *config = rte_eal_get_configuration(); - unsigned lcore_id; - unsigned count = 0; - - const unsigned ncpus = get_ncpus(); - /* - * Parse the maximum set of logical cores, detect the subset of running - * ones and enable them by default. - */ - for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { - /* init cpuset for per lcore config */ - CPU_ZERO(&lcore_config[lcore_id].cpuset); - - lcore_config[lcore_id].detected = (lcore_id < ncpus); - if (lcore_config[lcore_id].detected == 0) { - config->lcore_role[lcore_id] = ROLE_OFF; - continue; - } - - /* By default, lcore 1:1 map to cpu id */ - CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset); - - /* By default, each detected core is enabled */ - config->lcore_role[lcore_id] = ROLE_RTE; - lcore_config[lcore_id].core_id = cpu_core_id(lcore_id); - lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id); - if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES) -#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID - lcore_config[lcore_id].socket_id = 0; -#else - rte_panic("Socket ID (%u) is greater than " - "RTE_MAX_NUMA_NODES (%d)\n", - lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES); -#endif - RTE_LOG(DEBUG, EAL, "Detected lcore %u\n", - lcore_id); - count++; - } - /* Set the count of enabled logical cores of the EAL configuration */ - config->lcore_count = count; - RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n", - RTE_MAX_LCORE); - RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count); - return 0; } -unsigned -eal_cpu_socket_id(__rte_unused unsigned cpu_id) +/* Check if a cpu is present by the presence of the + * cpu information for it. + */ +int +eal_cpu_detected(unsigned lcore_id) { - return cpu_socket_id(cpu_id); + const unsigned ncpus = eal_get_ncpus(); + return (lcore_id < ncpus); } diff --git a/lib/librte_eal/bsdapp/eal/eal_lcore.c b/lib/librte_eal/common/eal_common_lcore.c similarity index 75% copy from lib/librte_eal/bsdapp/eal/eal_lcore.c copy to lib/librte_eal/common/eal_common_lcore.c index 162fb4f..845140b 100644 --- a/lib/librte_eal/bsdapp/eal/eal_lcore.c +++ b/lib/librte_eal/common/eal_common_lcore.c @@ -32,7 +32,9 @@ */ #include -#include +#include +#include +#include #include #include @@ -43,25 +45,10 @@ #include "eal_private.h" #include "eal_thread.h" -/* No topology information available on FreeBSD including NUMA info */ -#define cpu_core_id(X) 0 -#define cpu_socket_id(X) 0 - -static int -get_ncpus(void) -{ - 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); - return ncpu; -} - /* - * fill the cpu_info structure with as much info as we can get. - * code is similar to linux version, but sadly available info is less. + * Parse /sys/devices/system/cpu to get the number of physical and logical + * processors on the machine. The function will fill the cpu_info + * structure. */ int rte_eal_cpu_init(void) @@ -71,7 +58,6 @@ rte_eal_cpu_init(void) unsigned lcore_id; unsigned count = 0; - const unsigned ncpus = get_ncpus(); /* * Parse the maximum set of logical cores, detect the subset of running * ones and enable them by default. @@ -80,7 +66,8 @@ rte_eal_cpu_init(void) /* init cpuset for per lcore config */ CPU_ZERO(&lcore_config[lcore_id].cpuset); - lcore_config[lcore_id].detected = (lcore_id < ncpus); + /* 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) { config->lcore_role[lcore_id] = ROLE_OFF; continue; @@ -91,31 +78,30 @@ rte_eal_cpu_init(void) /* By default, each detected core is enabled */ config->lcore_role[lcore_id] = ROLE_RTE; - lcore_config[lcore_id].core_id = cpu_core_id(lcore_id); - lcore_config[lcore_id].socket_id = cpu_socket_id(lcore_id); + lcore_config[lcore_id].core_id = eal_cpu_core_id(lcore_id); + lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id); if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES) #ifdef RTE_EAL_ALLOW_INV_SOCKET_ID lcore_config[lcore_id].socket_id = 0; #else rte_panic("Socket ID (%u) is greater than " "RTE_MAX_NUMA_NODES (%d)\n", - lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES); + lcore_config[lcore_id].socket_id, + RTE_MAX_NUMA_NODES); #endif - RTE_LOG(DEBUG, EAL, "Detected lcore %u\n", - lcore_id); + + RTE_LOG(DEBUG, EAL, "Detected lcore %u as " + "core %u on socket %u\n", + lcore_id, lcore_config[lcore_id].core_id, + lcore_config[lcore_id].socket_id); count++; } /* Set the count of enabled logical cores of the EAL configuration */ config->lcore_count = count; - RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n", + RTE_LOG(DEBUG, EAL, + "Support maximum %u logical core(s) by configuration.\n", RTE_MAX_LCORE); RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count); return 0; } - -unsigned -eal_cpu_socket_id(__rte_unused unsigned cpu_id) -{ - return cpu_socket_id(cpu_id); -} diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index 73363f6..8505b05 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -300,4 +300,18 @@ int rte_eal_dev_init(void); */ int rte_eal_check_module(const char *module_name); +/** + * Get cpu core_id. + * + * This function is private to the EAL. + */ +unsigned eal_cpu_core_id(unsigned lcore_id); + +/** + * Check if cpu is present. + * + * This function is private to the EAL. + */ +int eal_cpu_detected(unsigned lcore_id); + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 0726ce1..f4f8cdf 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -70,6 +70,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_ivshmem.c endif # from common dir +SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_lcore.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c @@ -102,6 +103,7 @@ CFLAGS_eal_pci_vfio.o := -D_GNU_SOURCE CFLAGS_eal_common_whitelist.o := -D_GNU_SOURCE CFLAGS_eal_common_options.o := -D_GNU_SOURCE CFLAGS_eal_common_thread.o := -D_GNU_SOURCE +CFLAGS_eal_common_lcore.o := -D_GNU_SOURCE # workaround for a gcc bug with noreturn attribute # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603 diff --git a/lib/librte_eal/linuxapp/eal/eal_lcore.c b/lib/librte_eal/linuxapp/eal/eal_lcore.c index 560039b..de5b426 100644 --- a/lib/librte_eal/linuxapp/eal/eal_lcore.c +++ b/lib/librte_eal/linuxapp/eal/eal_lcore.c @@ -52,8 +52,8 @@ #define NUMA_NODE_PATH "/sys/devices/system/node" /* Check if a cpu is present by the presence of the cpu information for it */ -static int -cpu_detected(unsigned lcore_id) +int +eal_cpu_detected(unsigned lcore_id) { char path[PATH_MAX]; int len = snprintf(path, sizeof(path), SYS_CPU_DIR @@ -90,8 +90,8 @@ eal_cpu_socket_id(unsigned lcore_id) } /* Get the cpu core id value from the /sys/.../cpuX core_id value */ -static unsigned -cpu_core_id(unsigned lcore_id) +unsigned +eal_cpu_core_id(unsigned lcore_id) { char path[PATH_MAX]; unsigned long id; @@ -108,61 +108,3 @@ err: "for lcore %u - assuming core 0\n", SYS_CPU_DIR, lcore_id); return 0; } - -/* - * Parse /sys/devices/system/cpu to get the number of physical and logical - * processors on the machine. The function will fill the cpu_info - * structure. - */ -int -rte_eal_cpu_init(void) -{ - /* pointer to global configuration */ - struct rte_config *config = rte_eal_get_configuration(); - unsigned lcore_id; - unsigned count = 0; - - /* - * Parse the maximum set of logical cores, detect the subset of running - * ones and enable them by default. - */ - for (lcore_id = 0; lcore_id < RTE_MAX_LCORE; lcore_id++) { - /* init cpuset for per lcore config */ - CPU_ZERO(&lcore_config[lcore_id].cpuset); - - /* in 1:1 mapping, record related cpu detected state */ - lcore_config[lcore_id].detected = cpu_detected(lcore_id); - if (lcore_config[lcore_id].detected == 0) { - config->lcore_role[lcore_id] = ROLE_OFF; - continue; - } - - /* By default, lcore 1:1 map to cpu id */ - CPU_SET(lcore_id, &lcore_config[lcore_id].cpuset); - - /* By default, each detected core is enabled */ - config->lcore_role[lcore_id] = ROLE_RTE; - lcore_config[lcore_id].core_id = cpu_core_id(lcore_id); - lcore_config[lcore_id].socket_id = eal_cpu_socket_id(lcore_id); - if (lcore_config[lcore_id].socket_id >= RTE_MAX_NUMA_NODES) -#ifdef RTE_EAL_ALLOW_INV_SOCKET_ID - lcore_config[lcore_id].socket_id = 0; -#else - rte_panic("Socket ID (%u) is greater than " - "RTE_MAX_NUMA_NODES (%d)\n", - lcore_config[lcore_id].socket_id, RTE_MAX_NUMA_NODES); -#endif - RTE_LOG(DEBUG, EAL, "Detected lcore %u as core %u on socket %u\n", - lcore_id, - lcore_config[lcore_id].core_id, - lcore_config[lcore_id].socket_id); - count ++; - } - /* Set the count of enabled logical cores of the EAL configuration */ - config->lcore_count = count; - RTE_LOG(DEBUG, EAL, "Support maximum %u logical core(s) by configuration.\n", - RTE_MAX_LCORE); - RTE_LOG(DEBUG, EAL, "Detected %u lcore(s)\n", config->lcore_count); - - return 0; -}