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()");
44 /* AdjustTokenPrivileges() may succeed with ERROR_NOT_ALL_ASSIGNED. */
45 if (GetLastError() != ERROR_SUCCESS)
57 hugepage_info_init(void)
59 struct hugepage_info *hpi;
60 unsigned int socket_id;
62 struct internal_config *internal_conf =
63 eal_get_internal_configuration();
65 /* Only one hugepage size available on Windows. */
66 internal_conf->num_hugepage_sizes = 1;
67 hpi = &internal_conf->hugepage_info[0];
69 hpi->hugepage_sz = GetLargePageMinimum();
70 if (hpi->hugepage_sz == 0)
73 /* Assume all memory on each NUMA node available for hugepages,
74 * because Windows neither advertises additional limits,
75 * nor provides an API to query them.
77 for (socket_id = 0; socket_id < rte_socket_count(); socket_id++) {
79 unsigned int numa_node;
81 numa_node = eal_socket_numa_node(socket_id);
82 if (!GetNumaAvailableMemoryNodeEx(numa_node, &bytes)) {
83 RTE_LOG_WIN32_ERR("GetNumaAvailableMemoryNodeEx(%u)",
88 hpi->num_pages[socket_id] = bytes / hpi->hugepage_sz;
90 "Found %u hugepages of %zu bytes on socket %u\n",
91 hpi->num_pages[socket_id], hpi->hugepage_sz, socket_id);
94 /* No hugepage filesystem on Windows. */
95 hpi->lock_descriptor = -1;
96 memset(hpi->hugedir, 0, sizeof(hpi->hugedir));
102 eal_hugepage_info_init(void)
104 if (hugepage_claim_privilege() < 0) {
105 RTE_LOG(ERR, EAL, "Cannot claim hugepage privilege\n"
106 "Verify that large-page support privilege is assigned to the current user\n");
110 if (hugepage_info_init() < 0) {
111 RTE_LOG(ERR, EAL, "Cannot discover available hugepages\n");