1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2020 Dmitry Kozlyuk
7 #include <rte_memory.h>
8 #include <rte_memzone.h>
11 #include "eal_private.h"
12 #include "eal_filesystem.h"
13 #include "eal_hugepages.h"
14 #include "eal_internal_cfg.h"
15 #include "eal_windows.h"
18 hugepage_claim_privilege(void)
20 static const wchar_t privilege[] = L"SeLockMemoryPrivilege";
27 if (!OpenProcessToken(GetCurrentProcess(),
28 TOKEN_ADJUST_PRIVILEGES, &token)) {
29 RTE_LOG_WIN32_ERR("OpenProcessToken()");
33 if (!LookupPrivilegeValueW(NULL, privilege, &luid)) {
34 RTE_LOG_WIN32_ERR("LookupPrivilegeValue(\"%S\")", privilege);
38 tp.PrivilegeCount = 1;
39 tp.Privileges[0].Luid = luid;
40 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
42 if (!AdjustTokenPrivileges(
43 token, FALSE, &tp, sizeof(tp), NULL, NULL)) {
44 RTE_LOG_WIN32_ERR("AdjustTokenPrivileges()");
48 /* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */
49 if (GetLastError() != ERROR_SUCCESS)
61 hugepage_info_init(void)
63 struct hugepage_info *hpi;
64 unsigned int socket_id;
66 struct internal_config *internal_conf =
67 eal_get_internal_configuration();
69 /* Only one hugepage size available on Windows. */
70 internal_conf->num_hugepage_sizes = 1;
71 hpi = &internal_conf->hugepage_info[0];
73 hpi->hugepage_sz = GetLargePageMinimum();
74 if (hpi->hugepage_sz == 0)
77 /* Assume all memory on each NUMA node available for hugepages,
78 * because Windows neither advertises additional limits,
79 * nor provides an API to query them.
81 for (socket_id = 0; socket_id < rte_socket_count(); socket_id++) {
83 unsigned int numa_node;
85 numa_node = eal_socket_numa_node(socket_id);
86 if (!GetNumaAvailableMemoryNodeEx(numa_node, &bytes)) {
87 RTE_LOG_WIN32_ERR("GetNumaAvailableMemoryNodeEx(%u)",
92 hpi->num_pages[socket_id] = bytes / hpi->hugepage_sz;
94 "Found %u hugepages of %zu bytes on socket %u\n",
95 hpi->num_pages[socket_id], hpi->hugepage_sz, socket_id);
98 /* No hugepage filesystem on Windows. */
99 hpi->lock_descriptor = -1;
100 memset(hpi->hugedir, 0, sizeof(hpi->hugedir));
106 eal_hugepage_info_init(void)
108 if (hugepage_claim_privilege() < 0) {
109 RTE_LOG(ERR, EAL, "Cannot claim hugepage privilege\n"
110 "Verify that large-page support privilege is assigned to the current user\n");
114 if (hugepage_info_init() < 0) {
115 RTE_LOG(ERR, EAL, "Cannot discover available hugepages\n");