1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2020 Dmitry Kozlyuk
7 #include <rte_memory.h>
8 #include <rte_memzone.h>
10 #include "eal_private.h"
11 #include "eal_filesystem.h"
12 #include "eal_hugepages.h"
13 #include "eal_internal_cfg.h"
14 #include "eal_windows.h"
17 hugepage_claim_privilege(void)
19 static const wchar_t privilege[] = L"SeLockMemoryPrivilege";
26 if (!OpenProcessToken(GetCurrentProcess(),
27 TOKEN_ADJUST_PRIVILEGES, &token)) {
28 RTE_LOG_WIN32_ERR("OpenProcessToken()");
32 if (!LookupPrivilegeValueW(NULL, privilege, &luid)) {
33 RTE_LOG_WIN32_ERR("LookupPrivilegeValue(\"%S\")", privilege);
37 tp.PrivilegeCount = 1;
38 tp.Privileges[0].Luid = luid;
39 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
41 if (!AdjustTokenPrivileges(
42 token, FALSE, &tp, sizeof(tp), NULL, NULL)) {
43 RTE_LOG_WIN32_ERR("AdjustTokenPrivileges()");
47 /* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */
48 if (GetLastError() != ERROR_SUCCESS)
60 hugepage_info_init(void)
62 struct hugepage_info *hpi;
63 unsigned int socket_id;
65 struct internal_config *internal_conf =
66 eal_get_internal_configuration();
68 /* Only one hugepage size available on Windows. */
69 internal_conf->num_hugepage_sizes = 1;
70 hpi = &internal_conf->hugepage_info[0];
72 hpi->hugepage_sz = GetLargePageMinimum();
73 if (hpi->hugepage_sz == 0)
76 /* Assume all memory on each NUMA node available for hugepages,
77 * because Windows neither advertises additional limits,
78 * nor provides an API to query them.
80 for (socket_id = 0; socket_id < rte_socket_count(); socket_id++) {
82 unsigned int numa_node;
84 numa_node = eal_socket_numa_node(socket_id);
85 if (!GetNumaAvailableMemoryNodeEx(numa_node, &bytes)) {
86 RTE_LOG_WIN32_ERR("GetNumaAvailableMemoryNodeEx(%u)",
91 hpi->num_pages[socket_id] = bytes / hpi->hugepage_sz;
93 "Found %u hugepages of %zu bytes on socket %u\n",
94 hpi->num_pages[socket_id], hpi->hugepage_sz, socket_id);
97 /* No hugepage filesystem on Windows. */
98 hpi->lock_descriptor = -1;
99 memset(hpi->hugedir, 0, sizeof(hpi->hugedir));
105 eal_hugepage_info_init(void)
107 if (hugepage_claim_privilege() < 0) {
108 RTE_LOG(ERR, EAL, "Cannot claim hugepage privilege\n"
109 "Verify that large-page support privilege is assigned to the current user\n");
113 if (hugepage_info_init() < 0) {
114 RTE_LOG(ERR, EAL, "Cannot discover available hugepages\n");