From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E78A5A0093; Mon, 15 Jun 2020 02:45:59 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C16811BEC3; Mon, 15 Jun 2020 02:44:37 +0200 (CEST) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by dpdk.org (Postfix) with ESMTP id 7E19D4C8B for ; Mon, 15 Jun 2020 02:44:14 +0200 (CEST) Received: by mail-lj1-f193.google.com with SMTP id x18so17054193lji.1 for ; Sun, 14 Jun 2020 17:44:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Ps01p+yBXSeqVZgez7F1ApFAxqR9jG6QNIuOrkJu5uY=; b=JjRINsogpQi+rFXDfTC81aqigTAo7QhVhjECj7VrFwckKW4El+h3QM9ga9pRgzrJVv VYw4/3R0zVMHmzDgGRP+Pb0ZVWrC7DThboJU+IX3TxWcXBSPXpl9DhCVee2DxeBpnqyV HQXuJslaw1wJlPnfXQ+txNJ1hMfU5IiY/WlAzUqiGbDcv7M/MNP/ZfNQPQdmxGPrKPU6 TlCRjFmJBpC7+keGz0zOvSLiQy+dHoHF2F0DhxuSjod5tVKgZ5EMYfBmbCeyfgDeLS1F c5pU8/inbzxJqjketkir0n8TNjgTS0FK+nZjPP6lq1tGYS+MyXNTae9a6Umg+uojnYky q8aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Ps01p+yBXSeqVZgez7F1ApFAxqR9jG6QNIuOrkJu5uY=; b=G/PFcLnnbFrrI3HfjXA11mHxtosDNtM0MKAxgl/P5M/yTyLIsaf33WnfvOEvzqvB1/ hwuXv9nRSEu0r5/aEJiSxJ9X0lQ76iFAzHCjbL97mQ6GJmrzx65GSEl825XdlJrGFbdW 1D83vadVYkKVWVDFpc7CwRwZI1eX1+0sTzhssuz/O7bG752JwcRCa8tGqU3pWaE5DNIl 4VIducUZJpsWjBVXIaTTdZ3vro16Lvn1WF92v0nkEm1gYzxSWaB4SWLnarNXOOwoTJg8 zhaOGtq5pCtZCkCugwUo1J9GpnZq21+cb7nMmrxH5HvpqAA2LllC1diQSjWOQ9Kz2w4r RYfw== X-Gm-Message-State: AOAM531X72num/U+c3b9fF59bayr+ssi8LyT8uU1Rd0X025hUHibjdWg XfxTKsq4CpEryHcOh8DS4rt0bz2uq+nUhA== X-Google-Smtp-Source: ABdhPJzCiZZhYZ3PTywkjWtMm+92fmaFBo4CuGJ4GQXoXkKbTBnrYu86g9y8ah+y6TzcOKbW4Y9hsA== X-Received: by 2002:a2e:b4b6:: with SMTP id q22mr9945282ljm.53.1592181853854; Sun, 14 Jun 2020 17:44:13 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id f19sm4176342lfk.24.2020.06.14.17.44.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 14 Jun 2020 17:44:13 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Malloy , Narcisa Ana Maria Vasile , Fady Bader , Tal Shnaiderman , Dmitry Kozlyuk , Thomas Monjalon , Harini Ramakrishnan , Omar Cardona , Pallavi Kadam , Ranjit Menon , John McNamara , Marko Kovacevic Date: Mon, 15 Jun 2020 03:43:53 +0300 Message-Id: <20200615004354.14380-12-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200615004354.14380-1-dmitry.kozliuk@gmail.com> References: <20200610142730.31376-1-dmitry.kozliuk@gmail.com> <20200615004354.14380-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v9 11/12] eal/windows: initialize hugepage info X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add hugepages discovery ("large pages" in Windows terminology) and update documentation for required privilege setup. Only 2MB hugepages are supported and their number is estimated roughly due to the lack or unstable status of suitable OS APIs. Assign myself as maintainer for the implementation file. Signed-off-by: Dmitry Kozlyuk --- MAINTAINERS | 4 + config/meson.build | 2 + doc/guides/windows_gsg/run_apps.rst | 23 ++++++ lib/librte_eal/windows/eal.c | 14 ++++ lib/librte_eal/windows/eal_hugepages.c | 108 +++++++++++++++++++++++++ lib/librte_eal/windows/meson.build | 1 + 6 files changed, 152 insertions(+) create mode 100644 lib/librte_eal/windows/eal_hugepages.c diff --git a/MAINTAINERS b/MAINTAINERS index 241dbc3d7..9d5dacc23 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -334,6 +334,10 @@ F: lib/librte_eal/windows/ F: lib/librte_eal/rte_eal_exports.def F: doc/guides/windows_gsg/ +Windows memory allocation +M: Dmitry Kozlyuk +F: lib/librte_eal/windows/eal_hugepages.c + Core Libraries -------------- diff --git a/config/meson.build b/config/meson.build index 43ab11310..c1e80de4b 100644 --- a/config/meson.build +++ b/config/meson.build @@ -268,6 +268,8 @@ if is_windows if cc.get_id() == 'gcc' add_project_arguments('-D__USE_MINGW_ANSI_STDIO', language: 'c') endif + + add_project_link_arguments('-ladvapi32', language: 'c') endif if get_option('b_lto') diff --git a/doc/guides/windows_gsg/run_apps.rst b/doc/guides/windows_gsg/run_apps.rst index ff4c4654f..21ac7f6c1 100644 --- a/doc/guides/windows_gsg/run_apps.rst +++ b/doc/guides/windows_gsg/run_apps.rst @@ -4,6 +4,29 @@ Running DPDK Applications ========================= +Grant *Lock pages in memory* Privilege +-------------------------------------- + +Use of hugepages ("large pages" in Windows terminolocy) requires +``SeLockMemoryPrivilege`` for the user running an application. + +1. Open *Local Security Policy* snap in, either: + + * Control Panel / Computer Management / Local Security Policy; + * or Win+R, type ``secpol``, press Enter. + +2. Open *Local Policies / User Rights Assignment / Lock pages in memory.* + +3. Add desired users or groups to the list of grantees. + +4. Privilege is applied upon next logon. In particular, if privilege has been + granted to current user, a logoff is required before it is available. + +See `Large-Page Support`_ in MSDN for details. + +.. _Large-page Support: https://docs.microsoft.com/en-us/windows/win32/memory/large-page-support + + Run the ``helloworld`` Example ------------------------------ diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c index dfc10b494..759bf4be5 100644 --- a/lib/librte_eal/windows/eal.c +++ b/lib/librte_eal/windows/eal.c @@ -19,8 +19,11 @@ #include #include +#include "eal_hugepages.h" #include "eal_windows.h" +#define MEMSIZE_IF_NO_HUGE_PAGE (64ULL * 1024ULL * 1024ULL) + /* Allow the application to print its usage message too if set */ static rte_usage_hook_t rte_application_usage_hook; @@ -279,6 +282,17 @@ rte_eal_init(int argc, char **argv) if (fctret < 0) exit(1); + if (!internal_config.no_hugetlbfs && (eal_hugepage_info_init() < 0)) { + rte_eal_init_alert("Cannot get hugepage information"); + rte_errno = EACCES; + return -1; + } + + if (internal_config.memory == 0 && !internal_config.force_sockets) { + if (internal_config.no_hugetlbfs) + internal_config.memory = MEMSIZE_IF_NO_HUGE_PAGE; + } + eal_thread_init_master(rte_config.master_lcore); RTE_LCORE_FOREACH_SLAVE(i) { diff --git a/lib/librte_eal/windows/eal_hugepages.c b/lib/librte_eal/windows/eal_hugepages.c new file mode 100644 index 000000000..61d0dcd3c --- /dev/null +++ b/lib/librte_eal/windows/eal_hugepages.c @@ -0,0 +1,108 @@ +#include +#include +#include +#include +#include + +#include "eal_filesystem.h" +#include "eal_hugepages.h" +#include "eal_internal_cfg.h" +#include "eal_windows.h" + +static int +hugepage_claim_privilege(void) +{ + static const wchar_t privilege[] = L"SeLockMemoryPrivilege"; + + HANDLE token; + LUID luid; + TOKEN_PRIVILEGES tp; + int ret = -1; + + if (!OpenProcessToken(GetCurrentProcess(), + TOKEN_ADJUST_PRIVILEGES, &token)) { + RTE_LOG_WIN32_ERR("OpenProcessToken()"); + return -1; + } + + if (!LookupPrivilegeValueW(NULL, privilege, &luid)) { + RTE_LOG_WIN32_ERR("LookupPrivilegeValue(\"%S\")", privilege); + goto exit; + } + + tp.PrivilegeCount = 1; + tp.Privileges[0].Luid = luid; + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + + if (!AdjustTokenPrivileges( + token, FALSE, &tp, sizeof(tp), NULL, NULL)) { + RTE_LOG_WIN32_ERR("AdjustTokenPrivileges()"); + goto exit; + } + + ret = 0; + +exit: + CloseHandle(token); + + return ret; +} + +static int +hugepage_info_init(void) +{ + struct hugepage_info *hpi; + unsigned int socket_id; + int ret = 0; + + /* Only one hugepage size available on Windows. */ + internal_config.num_hugepage_sizes = 1; + hpi = &internal_config.hugepage_info[0]; + + hpi->hugepage_sz = GetLargePageMinimum(); + if (hpi->hugepage_sz == 0) + return -ENOTSUP; + + /* Assume all memory on each NUMA node available for hugepages, + * because Windows neither advertises additional limits, + * nor provides an API to query them. + */ + for (socket_id = 0; socket_id < rte_socket_count(); socket_id++) { + ULONGLONG bytes; + unsigned int numa_node; + + numa_node = eal_socket_numa_node(socket_id); + if (!GetNumaAvailableMemoryNodeEx(numa_node, &bytes)) { + RTE_LOG_WIN32_ERR("GetNumaAvailableMemoryNodeEx(%u)", + numa_node); + continue; + } + + hpi->num_pages[socket_id] = bytes / hpi->hugepage_sz; + RTE_LOG(DEBUG, EAL, + "Found %u hugepages of %zu bytes on socket %u\n", + hpi->num_pages[socket_id], hpi->hugepage_sz, socket_id); + } + + /* No hugepage filesystem on Windows. */ + hpi->lock_descriptor = -1; + memset(hpi->hugedir, 0, sizeof(hpi->hugedir)); + + return ret; +} + +int +eal_hugepage_info_init(void) +{ + if (hugepage_claim_privilege() < 0) { + RTE_LOG(ERR, EAL, "Cannot claim hugepage privilege\n"); + return -1; + } + + if (hugepage_info_init() < 0) { + RTE_LOG(ERR, EAL, "Cannot get hugepage information\n"); + return -1; + } + + return 0; +} diff --git a/lib/librte_eal/windows/meson.build b/lib/librte_eal/windows/meson.build index adfc8b9b7..52978e9d7 100644 --- a/lib/librte_eal/windows/meson.build +++ b/lib/librte_eal/windows/meson.build @@ -6,6 +6,7 @@ subdir('include') sources += files( 'eal.c', 'eal_debug.c', + 'eal_hugepages.c', 'eal_lcore.c', 'eal_log.c', 'eal_thread.c', -- 2.25.4