]> git.droids-corp.org - dpdk.git/commitdiff
eal/windows: detect process type
authorPallavi Kadam <pallavi.kadam@intel.com>
Fri, 7 Feb 2020 03:14:33 +0000 (19:14 -0800)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 12 Feb 2020 21:50:29 +0000 (22:50 +0100)
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 <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>
Reviewed-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Tested-by: Narcisa Ana Maria Vasile <narcisa.vasile@microsoft.com>
Acked-by: Narcisa Ana Maria Vasile <narcisa.vasile@microsoft.com>
lib/librte_eal/windows/eal/eal.c
lib/librte_eal/windows/eal/eal_debug.c
lib/librte_eal/windows/eal/eal_lcore.c
lib/librte_eal/windows/eal/eal_thread.c

index ce460481f8a4272b7c8ee1600135899141864708..6a1208c353f00f52d80359b6102970820de9d089 100644 (file)
@@ -2,21 +2,48 @@
  * 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_options.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;
+
+/* 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)
 {
index edcf257cc3f1fb9cda0a223e7fecaac1be01f0c0..669be6ff97c2bd15618622e9e70350f836b88c31 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <stdarg.h>
 #include <rte_log.h>
+#include <rte_debug.h>
 
  /* call abort(), it will generate a coredump if enabled */
 void
index d39f348a3a45107b8a42b6d3b0b8a827f8f31fc7..b3a6c63afad8995129eccbfe5c8db048ec70d360 100644 (file)
@@ -6,6 +6,9 @@
 
 #include <rte_common.h>
 
+#include "eal_private.h"
+#include "eal_thread.h"
+
 /* global data structure that contains the CPU map */
 static struct _wcpu_map {
        unsigned int total_procs;
index 0591d4c7fb063d29f801756c60ced43012d0ba87..9e4bbaa08283d2c7c401accf432a63397dbb06b1 100644 (file)
 #include <rte_lcore.h>
 #include <rte_per_lcore.h>
 #include <rte_common.h>
+#include <rte_memory.h>
 #include <eal_thread.h>
 
 #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;
+}