From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4137BA0524; Sat, 1 Feb 2020 01:06:26 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9AB511C136; Sat, 1 Feb 2020 01:05:21 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 7E5941C0DC for ; Sat, 1 Feb 2020 01:05:09 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2020 16:05:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,387,1574150400"; d="scan'208";a="310151707" Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain) ([10.166.188.75]) by orsmga001.jf.intel.com with ESMTP; 31 Jan 2020 16:05:05 -0800 From: Pallavi Kadam To: dev@dpdk.org, thomas@monjalon.net Cc: Harini.Ramakrishnan@microsoft.com, keith.wiles@intel.com, bruce.richardson@intel.com, david.marchand@redhat.com, jerinjacobk@gmail.com, ranjit.menon@intel.com, antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com Date: Fri, 31 Jan 2020 16:04:02 -0800 Message-Id: <20200201000406.11060-6-pallavi.kadam@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 In-Reply-To: <20200201000406.11060-1-pallavi.kadam@intel.com> References: <20200131000307.10608-1-pallavi.kadam@intel.com> <20200201000406.11060-1-pallavi.kadam@intel.com> Subject: [dpdk-dev] [PATCH v7 5/9] eal: add function to detect process type 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Adding a function to detect process type, also included header files to contain suitable function declarations and to support extra warning flags. Signed-off-by: Pallavi Kadam Signed-off-by: Antara Ganesh Kolar Reviewed-by: Ranjit Menon Reviewed-by: Keith Wiles --- lib/librte_eal/windows/eal/eal.c | 61 ++++++++++++++++++++++++- lib/librte_eal/windows/eal/eal_debug.c | 1 + lib/librte_eal/windows/eal/eal_lcore.c | 3 ++ lib/librte_eal/windows/eal/eal_thread.c | 11 +++++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c index ce460481f..931a5860c 100644 --- a/lib/librte_eal/windows/eal/eal.c +++ b/lib/librte_eal/windows/eal/eal.c @@ -2,21 +2,48 @@ * Copyright(c) 2019 Intel Corporation */ +#include #include #include #include #include +#include #include #include #include +#include +#include +#include #include +/* define fd variable here, because file needs to be kept open for the + * duration of the program, as we hold a write lock on it in the primary proc + */ +static int mem_cfg_fd = -1; + +/* early configuration structure, when memory config is not mmapped */ +static struct rte_mem_config early_mem_config; + /* Address of global and public configuration */ -static struct rte_config rte_config; +static struct rte_config rte_config = { + .mem_config = &early_mem_config, +}; /* internal configuration (per-core) */ struct lcore_config lcore_config[RTE_MAX_LCORE]; +/* internal configuration */ +struct internal_config internal_config; + +/* platform-specific runtime dir */ +static char runtime_dir[PATH_MAX]; + +const char * +rte_eal_get_runtime_dir(void) +{ + return runtime_dir; +} + /* Return a pointer to the configuration structure */ struct rte_config * rte_eal_get_configuration(void) @@ -24,6 +51,38 @@ rte_eal_get_configuration(void) return &rte_config; } +/* Detect if we are a primary or a secondary process */ +enum rte_proc_type_t +eal_proc_type_detect(void) +{ + enum rte_proc_type_t ptype = RTE_PROC_PRIMARY; + const char *pathname = eal_runtime_config_path(); + + /* if we can open the file but not get a write-lock we are a secondary + * process. NOTE: if we get a file handle back, we keep that open + * and don't close it to prevent a race condition between multiple opens + */ + errno_t err = _sopen_s(&mem_cfg_fd, pathname, + _O_RDWR, _SH_DENYNO, _S_IREAD | _S_IWRITE); + if (err == 0) { + OVERLAPPED sOverlapped = { 0 }; + sOverlapped.Offset = sizeof(*rte_config.mem_config); + sOverlapped.OffsetHigh = 0; + + HANDLE hWinFileHandle = (HANDLE)_get_osfhandle(mem_cfg_fd); + + if (!LockFileEx(hWinFileHandle, + LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, 0, + sizeof(*rte_config.mem_config), 0, &sOverlapped)) + ptype = RTE_PROC_SECONDARY; + } + + RTE_LOG(INFO, EAL, "Auto-detected process type: %s\n", + ptype == RTE_PROC_PRIMARY ? "PRIMARY" : "SECONDARY"); + + return ptype; +} + static int sync_func(void *arg __rte_unused) { diff --git a/lib/librte_eal/windows/eal/eal_debug.c b/lib/librte_eal/windows/eal/eal_debug.c index edcf257cc..669be6ff9 100644 --- a/lib/librte_eal/windows/eal/eal_debug.c +++ b/lib/librte_eal/windows/eal/eal_debug.c @@ -4,6 +4,7 @@ #include #include +#include /* call abort(), it will generate a coredump if enabled */ void diff --git a/lib/librte_eal/windows/eal/eal_lcore.c b/lib/librte_eal/windows/eal/eal_lcore.c index d39f348a3..b3a6c63af 100644 --- a/lib/librte_eal/windows/eal/eal_lcore.c +++ b/lib/librte_eal/windows/eal/eal_lcore.c @@ -6,6 +6,9 @@ #include +#include "eal_private.h" +#include "eal_thread.h" + /* global data structure that contains the CPU map */ static struct _wcpu_map { unsigned int total_procs; diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c index 0591d4c7f..9e4bbaa08 100644 --- a/lib/librte_eal/windows/eal/eal_thread.c +++ b/lib/librte_eal/windows/eal/eal_thread.c @@ -10,11 +10,14 @@ #include #include #include +#include #include #include "eal_private.h" RTE_DEFINE_PER_LCORE(unsigned int, _lcore_id) = LCORE_ID_ANY; +RTE_DEFINE_PER_LCORE(unsigned int, _socket_id) = (unsigned int)SOCKET_ID_ANY; +RTE_DEFINE_PER_LCORE(rte_cpuset_t, _cpuset); /* * Send a message to a slave lcore identified by slave_id to call a @@ -152,3 +155,11 @@ eal_thread_create(pthread_t *thread) return 0; } + +int +rte_thread_setname(__rte_unused pthread_t id, __rte_unused const char *name) +{ + /* TODO */ + /* This is a stub, not the expected result */ + return 0; +} -- 2.18.0.windows.1