3 #include <rte_memory.h>
4 #include <rte_memzone.h>
7 #include "eal_private.h"
8 #include "eal_filesystem.h"
9 #include "eal_hugepages.h"
10 #include "eal_internal_cfg.h"
11 #include "eal_windows.h"
14 hugepage_claim_privilege(void)
16 static const wchar_t privilege[] = L"SeLockMemoryPrivilege";
23 if (!OpenProcessToken(GetCurrentProcess(),
24 TOKEN_ADJUST_PRIVILEGES, &token)) {
25 RTE_LOG_WIN32_ERR("OpenProcessToken()");
29 if (!LookupPrivilegeValueW(NULL, privilege, &luid)) {
30 RTE_LOG_WIN32_ERR("LookupPrivilegeValue(\"%S\")", privilege);
34 tp.PrivilegeCount = 1;
35 tp.Privileges[0].Luid = luid;
36 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
38 if (!AdjustTokenPrivileges(
39 token, FALSE, &tp, sizeof(tp), NULL, NULL)) {
40 RTE_LOG_WIN32_ERR("AdjustTokenPrivileges()");
53 hugepage_info_init(void)
55 struct hugepage_info *hpi;
56 unsigned int socket_id;
58 struct internal_config *internal_conf =
59 eal_get_internal_configuration();
61 /* Only one hugepage size available on Windows. */
62 internal_conf->num_hugepage_sizes = 1;
63 hpi = &internal_conf->hugepage_info[0];
65 hpi->hugepage_sz = GetLargePageMinimum();
66 if (hpi->hugepage_sz == 0)
69 /* Assume all memory on each NUMA node available for hugepages,
70 * because Windows neither advertises additional limits,
71 * nor provides an API to query them.
73 for (socket_id = 0; socket_id < rte_socket_count(); socket_id++) {
75 unsigned int numa_node;
77 numa_node = eal_socket_numa_node(socket_id);
78 if (!GetNumaAvailableMemoryNodeEx(numa_node, &bytes)) {
79 RTE_LOG_WIN32_ERR("GetNumaAvailableMemoryNodeEx(%u)",
84 hpi->num_pages[socket_id] = bytes / hpi->hugepage_sz;
86 "Found %u hugepages of %zu bytes on socket %u\n",
87 hpi->num_pages[socket_id], hpi->hugepage_sz, socket_id);
90 /* No hugepage filesystem on Windows. */
91 hpi->lock_descriptor = -1;
92 memset(hpi->hugedir, 0, sizeof(hpi->hugedir));
98 eal_hugepage_info_init(void)
100 if (hugepage_claim_privilege() < 0) {
101 RTE_LOG(ERR, EAL, "Cannot claim hugepage privilege\n");
105 if (hugepage_info_init() < 0) {
106 RTE_LOG(ERR, EAL, "Cannot get hugepage information\n");