X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_eal%2Fwindows%2Feal%2Feal.c;h=6a1208c353f00f52d80359b6102970820de9d089;hb=8938998a298ab6dbecbe9f5a0f4ebdfdba90862e;hp=ce460481f8a4272b7c8ee1600135899141864708;hpb=5e373e456e6acdc8acfce046a09afc9c6597e550;p=dpdk.git diff --git a/lib/librte_eal/windows/eal/eal.c b/lib/librte_eal/windows/eal/eal.c index ce460481f8..6a1208c353 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) {