From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 4746DA0613
	for <public@inbox.dpdk.org>; Thu, 26 Sep 2019 22:55:39 +0200 (CEST)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 8680A31FC;
	Thu, 26 Sep 2019 22:55:03 +0200 (CEST)
Received: from mga09.intel.com (mga09.intel.com [134.134.136.24])
 by dpdk.org (Postfix) with ESMTP id 0F2EC2B8D
 for <dev@dpdk.org>; Thu, 26 Sep 2019 22:54:40 +0200 (CEST)
X-Amp-Result: SKIPPED(no attachment in message)
X-Amp-File-Uploaded: False
Received: from orsmga006.jf.intel.com ([10.7.209.51])
 by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;
 26 Sep 2019 13:54:37 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.64,553,1559545200"; d="scan'208";a="194260452"
Received: from win-dpdk-pallavi.jf.intel.com (HELO localhost.localdomain)
 ([10.166.188.58])
 by orsmga006.jf.intel.com with ESMTP; 26 Sep 2019 13:54:37 -0700
From: Pallavi Kadam <pallavi.kadam@intel.com>
To: dev@dpdk.org,
	thomas@monjalon.net
Cc: Harini.Ramakrishnan@microsoft.com, keith.wiles@intel.com,
 bruce.richardson@intel.com, ranjit.menon@intel.com,
 antara.ganesh.kolar@intel.com, pallavi.kadam@intel.com
Date: Thu, 26 Sep 2019 13:29:22 -0700
Message-Id: <20190926202924.6876-8-pallavi.kadam@intel.com>
X-Mailer: git-send-email 2.18.0.windows.1
In-Reply-To: <20190926202924.6876-1-pallavi.kadam@intel.com>
References: <20190909195404.4760-1-pallavi.kadam@intel.com>
 <20190926202924.6876-1-pallavi.kadam@intel.com>
Subject: [dpdk-dev] [PATCH v2 7/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 <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

Adding a function to detect process type and include
header files to contain suitable function declarations.

Signed-off-by: Pallavi Kadam <pallavi.kadam@intel.com>
Signed-off-by: Antara Ganesh Kolar <antara.ganesh.kolar@intel.com>
Reviewed-by: Ranjit Menon <ranjit.menon@intel.com>
Reviewed-by: Keith Wiles <keith.wiles@intel.com>
---
 lib/librte_eal/windows/eal/eal.c        | 51 ++++++++++++++++++++++++-
 lib/librte_eal/windows/eal/eal_thread.c |  3 ++
 2 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c
index 83907ffa6..ffe5b8552 100644
--- a/lib/librte_eal/windows/eal/eal.c
+++ b/lib/librte_eal/windows/eal/eal.c
@@ -2,21 +2,38 @@
  * Copyright(c) 2019 Intel Corporation
  */
 
+#include <sys/stat.h>
 #include <io.h>
 #include <fcntl.h>
 #include <rte_debug.h>
 #include <rte_eal.h>
+#include <eal_memcfg.h>
 #include <rte_errno.h>
 #include <rte_lcore.h>
 #include <eal_thread.h>
+#include <eal_internal_cfg.h>
+#include <eal_filesystem.h>
 #include <eal_private.h>
 
+/* 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; // INVALID_HANDLE_VALUE;
+
+/* 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;
+
 /* Return a pointer to the configuration structure */
 struct rte_config *
 rte_eal_get_configuration(void)
@@ -24,6 +41,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;
+}
+
 /* Parse the arguments for --log-level only */
 static void
 eal_log_level_parse(__rte_unused int argc, __rte_unused char **argv)
diff --git a/lib/librte_eal/windows/eal/eal_thread.c b/lib/librte_eal/windows/eal/eal_thread.c
index 6e5e6f4ab..54b9c1dd1 100644
--- a/lib/librte_eal/windows/eal/eal_thread.c
+++ b/lib/librte_eal/windows/eal/eal_thread.c
@@ -10,10 +10,13 @@
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.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
-- 
2.18.0.windows.1