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 AE242A05A1; Wed, 22 Apr 2020 02:55:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3C2D11D40E; Wed, 22 Apr 2020 02:55:07 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id B3F9F1D181 for ; Wed, 22 Apr 2020 02:55:05 +0200 (CEST) IronPort-SDR: MocUg9ztHKuku4mc9Er3GCR99HCVCZiA5Q8HXkmOfwfUqRjk0wKBUoF1GWzIVSaDpl5AoWuCLv oMhn6vipc9Zg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2020 17:55:04 -0700 IronPort-SDR: jhW+wA88OzDSzGQ020HDuCDMU3EPeaON9Vpoc4rnW8QogCOaNNK6Wx4A8f4tQikRMhgX+w1aI1 S/9nLkrIj7TQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,412,1580803200"; d="scan'208";a="279835608" Received: from rmenon-mobl.amr.corp.intel.com (HELO [10.251.1.78]) ([10.251.1.78]) by fmsmga004.fm.intel.com with ESMTP; 21 Apr 2020 17:55:04 -0700 To: Dmitry Kozlyuk , "dev@dpdk.org" Cc: "Dmitry Malloy (MESHCHANINOV)" , Narcisa Ana Maria Vasile , Fady Bader , Tal Shnaiderman , Thomas Monjalon , "Burakov, Anatoly" , Harini Ramakrishnan , Omar Cardona , "Kadam, Pallavi" References: <20200410164342.1194634-1-dmitry.kozliuk@gmail.com> <20200414194426.1640704-1-dmitry.kozliuk@gmail.com> <20200414194426.1640704-7-dmitry.kozliuk@gmail.com> From: Ranjit Menon Message-ID: <397c08ab-5fc0-952e-196e-b963245679ae@intel.com> Date: Tue, 21 Apr 2020 17:55:03 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: <20200414194426.1640704-7-dmitry.kozliuk@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [dpdk-dev] [PATCH v3 06/10] eal: introduce memory management wrappers 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" On 4/14/2020 12:44 PM, Dmitry Kozlyuk wrote: > System meory management is implemented differently for POSIX and > Windows. Introduce wrapper functions for operations used across DPDK: > > * rte_mem_map() > Create memory mapping for a regular file or a page file (swap). > This supports mapping to a reserved memory region even on Windows. > > * rte_mem_unmap() > Remove mapping created with rte_mem_map(). > > * rte_get_page_size() > Obtain default system page size. > > * rte_mem_lock() > Make arbitrary-sized memory region non-swappable. > > Wrappers follow POSIX semantics limited to DPDK tasks, but their > signatures deliberately differ from POSIX ones to be more safe and > expressive. > > Signed-off-by: Dmitry Kozlyuk > diff --git a/lib/librte_eal/windows/eal_memory.c b/lib/librte_eal/windows/eal_memory.c > new file mode 100644 > index 000000000..5697187ce > --- /dev/null > +++ b/lib/librte_eal/windows/eal_memory.c > @@ -0,0 +1,437 @@ > +#include > + > +#include > +#include > + > +#include "eal_private.h" > +#include "eal_windows.h" > + > +/* MinGW-w64 headers lack VirtualAlloc2() in some distributions. > + * Provide a copy of definitions and code to load it dynamically. > + * Note: definitions are copied verbatim from Microsoft documentation > + * and don't follow DPDK code style. > + */ > +#ifndef MEM_PRESERVE_PLACEHOLDER > + > +/* https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-mem_extended_parameter_type */ > +typedef enum MEM_EXTENDED_PARAMETER_TYPE { > + MemExtendedParameterInvalidType, > + MemExtendedParameterAddressRequirements, > + MemExtendedParameterNumaNode, > + MemExtendedParameterPartitionHandle, > + MemExtendedParameterMax, > + MemExtendedParameterUserPhysicalHandle, > + MemExtendedParameterAttributeFlags > +} *PMEM_EXTENDED_PARAMETER_TYPE; > + > +#define MEM_EXTENDED_PARAMETER_TYPE_BITS 4 > + > +/* https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-mem_extended_parameter */ > +typedef struct MEM_EXTENDED_PARAMETER { > + struct { > + DWORD64 Type : MEM_EXTENDED_PARAMETER_TYPE_BITS; > + DWORD64 Reserved : 64 - MEM_EXTENDED_PARAMETER_TYPE_BITS; > + } DUMMYSTRUCTNAME; > + union { > + DWORD64 ULong64; > + PVOID Pointer; > + SIZE_T Size; > + HANDLE Handle; > + DWORD ULong; > + } DUMMYUNIONNAME; > +} MEM_EXTENDED_PARAMETER, *PMEM_EXTENDED_PARAMETER; > + > +/* https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualalloc2 */ > +typedef PVOID (*VirtualAlloc2_type)( > + HANDLE Process, > + PVOID BaseAddress, > + SIZE_T Size, > + ULONG AllocationType, > + ULONG PageProtection, > + MEM_EXTENDED_PARAMETER *ExtendedParameters, > + ULONG ParameterCount > +); > + > +/* VirtualAlloc2() flags. */ > +#define MEM_COALESCE_PLACEHOLDERS 0x00000001 > +#define MEM_PRESERVE_PLACEHOLDER 0x00000002 > +#define MEM_REPLACE_PLACEHOLDER 0x00004000 > +#define MEM_RESERVE_PLACEHOLDER 0x00040000 > + > +/* Named exactly as the function, so that user code does not depend > + * on it being found at compile time or dynamically. > + */ > +static VirtualAlloc2_type VirtualAlloc2; > + > +int > +eal_mem_win32api_init(void) > +{ > + static const char library_name[] = "kernelbase.dll"; > + static const char function[] = "VirtualAlloc2"; > + > + OSVERSIONINFO info; > + HMODULE library = NULL; > + int ret = 0; > + > + /* Already done. */ > + if (VirtualAlloc2 != NULL) > + return 0; > + > + /* IsWindows10OrGreater() may also be unavailable. */ > + memset(&info, 0, sizeof(info)); > + info.dwOSVersionInfoSize = sizeof(info); > + GetVersionEx(&info); > + > + /* Checking for Windows 10+ will also detect Windows Server 2016+. > + * Do not abort, because Windows may report false version depending > + * on executable manifest, compatibility mode, etc. > + */ > + if (info.dwMajorVersion < 10) > + RTE_LOG(DEBUG, EAL, "Windows 10+ or Windows Server 2016+ " > + "is required for advanced memory features\n"); > + > + library = LoadLibraryA(library_name); > + if (library == NULL) { > + RTE_LOG_WIN32_ERR("LoadLibraryA(\"%s\")", library_name); > + return -1; > + } > + > + VirtualAlloc2 = (VirtualAlloc2_type)( > + (void *)GetProcAddress(library, function)); > + if (VirtualAlloc2 == NULL) { > + RTE_LOG_WIN32_ERR("GetProcAddress(\"%s\", \"%s\")\n", > + library_name, function); > + ret = -1; > + } > + > + FreeLibrary(library); > + > + return ret; > +} > + > +#else > + > +/* Stub in case VirtualAlloc2() is provided by the compiler. */ > +int > +eal_mem_win32api_init(void) > +{ > + return 0; > +} > + > +#endif /* no VirtualAlloc2() */ Can you fix this comment to match the #ifndef definition above? BTW...Why use MEM_PRESERVE_PLACEHOLDER (which is also defined within the block?) ranjit m.