[ovs-dev] [PATCH] datapath-windows: Add Core.h

Samuel Ghinet sghinet at cloudbasesolutions.com
Wed Aug 6 15:52:36 UTC 2014

Hello Eitan,

Just found this (it is an answer on a thread, not true doc, but may be helpful):
"I would actually suggest avoiding the NdisAllocateMemory* APIs for general pool allocations, and going straight to the ExAllocate APIs.  There's nothing interesting going on in the NDIS APIs, and the kernel ones are better-documented and slightly better-designed.  (For DMA memory, you will still have to go through NDIS, though.)"

This guy, Jeffrey Tippet, is apparently working at microsoft, and also gives answers on osronline.
I'm just saying, perhaps he's right :)

From: Eitan Eliahu [eliahue at vmware.com]
Sent: Wednesday, August 06, 2014 6:22 PM
To: Samuel Ghinet; dev at openvswitch.org
Subject: RE: [PATCH] datapath-windows: Add Core.h

Hi Sam,
Since the switch extension driver is an NDIS filter driver it would be preferable to use NDIS memory allocation functions rather direct executive system calls.
On another thing: since this driver is basically two combined drivers (Extension and WFP) it would be nice if we could pass the tag used by the memory allocation function as a parameter.
Beside the extension and the WFP, we would like to be able to distinguish between memory blocks allocated during initialization and memory allocated during the fast path.

-----Original Message-----
From: dev [mailto:dev-bounces at openvswitch.org] On Behalf Of Samuel Ghinet
Sent: Wednesday, August 06, 2014 7:55 AM
To: dev at openvswitch.org
Subject: [ovs-dev] [PATCH] datapath-windows: Add Core.h

Add Core.h

Functionalities & macros that are expected to be needed / used anywhere.

Such as: macros for memory allocations.
These would replace the memory allocations functions defined in Utils.c:
* There is no need to allocate memory with priority if priority = normal (default)
* There is no need to use the Ndis mem allocation function, which requires an NDIS_HANDLE, when we can use the Executive mem allocation function (ExAllocatePoolWithTag) which does not.
* There is no need to do a check like "OVS_VERIFY_IRQL_LE(DISPATCH_LEVEL)": the maximum IRQL that we can have in the driver is dispatch level.
* OVS_ALLOC, OVS_FREE and KZAlloc are shorter-named, improving the code clarity.

Signed-off-by: Samuel Ghinet <sghinet at cloudbasesolutions.com>
 datapath-windows/ovsext/Core/Core.h            | 55 ++++++++++++++++++++++++++
 datapath-windows/ovsext/ovsext.vcxproj         |  1 +
 datapath-windows/ovsext/ovsext.vcxproj.filters |  5 ++-
 datapath-windows/ovsext/precomp.h              |  1 +
 4 files changed, 61 insertions(+), 1 deletion(-)  create mode 100644 datapath-windows/ovsext/Core/Core.h

diff --git a/datapath-windows/ovsext/Core/Core.h b/datapath-windows/ovsext/Core/Core.h
new file mode 100644
index 0000000..3c56a13
--- /dev/null
+++ b/datapath-windows/ovsext/Core/Core.h
@@ -0,0 +1,55 @@
+Copyright 2014 Cloudbase Solutions Srl
+Licensed under the Apache License, Version 2.0 (the "License"); you may
+not use this file except in compliance with the License.
+You may obtain a copy of the License at
+http ://www.apache.org/licenses/LICENSE-2.0
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+See the License for the specific language governing permissions and
+limitations under the License.
+#pragma once
+#include "precomp.h"
+//used in ASSERT-s
+#define __NEVER_TRIED_THIS__      0
+#define __NOT_IMPLEMENTED__       0
+#define __UNEXPECTED__            0
+#define OVS_ALLOC(size) ExAllocatePoolWithTag(NonPagedPool, size,
+OVS_MEMORY_TAG) #define OVS_FREE(p) KFreeSafe(p)
+#define OVS_ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) #define
+#define OVS_SIZE_ALIGNED_N(dataSize, N)        (((dataSize) / (N)) * (N) + ((dataSize) % (N) ? (N) : 0))
+#define OVS_SIZE_ALIGNED_4(dataSize)           OVS_SIZE_ALIGNED_N(dataSize, 4)
+#define OVS_SIZE_ALIGNED_16(dataSize)          OVS_SIZE_ALIGNED_N(dataSize, 16)
+static __inline VOID* KZAlloc(SIZE_T size) {
+    VOID* p = OVS_ALLOC(size);
+    if (!p)
+    {
+        return NULL;
+    }
+    RtlZeroMemory(p, size);
+    return p;
+static __inline VOID KFreeSafe(VOID* p) {
+    if (p)
+    {
+        ExFreePoolWithTag(p, OVS_MEMORY_TAG);
+    }
diff --git a/datapath-windows/ovsext/ovsext.vcxproj b/datapath-windows/ovsext/ovsext.vcxproj
index 2c62cab..ee69327 100644
--- a/datapath-windows/ovsext/ovsext.vcxproj
+++ b/datapath-windows/ovsext/ovsext.vcxproj
@@ -70,6 +70,7 @@
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" />
   <ItemGroup Label="WrappedTaskItems">
+    <ClInclude Include="Core\Core.h" />
     <ClInclude Include="Core\Debug.h" />
     <ClInclude Include="Core\Error.h" />
     <ClInclude Include="Core\FixedSizedArray.h" /> diff --git a/datapath-windows/ovsext/ovsext.vcxproj.filters b/datapath-windows/ovsext/ovsext.vcxproj.filters
index 96cfac6..78d041b 100644
--- a/datapath-windows/ovsext/ovsext.vcxproj.filters
+++ b/datapath-windows/ovsext/ovsext.vcxproj.filters
@@ -89,6 +89,9 @@
     <ClInclude Include="Core\FixedSizedArray.h">
+    <ClInclude Include="Core\Core.h">
+      <Filter>Core</Filter>
+    </ClInclude>
     <ResourceCompile Include="ovsext.rc" /> @@ -185,4 +188,4 @@
\ No newline at end of file
diff --git a/datapath-windows/ovsext/precomp.h b/datapath-windows/ovsext/precomp.h
index 3fd5da2..b28e9ec 100644
--- a/datapath-windows/ovsext/precomp.h
+++ b/datapath-windows/ovsext/precomp.h
@@ -21,6 +21,7 @@
 #include <ntstrsafe.h>
 #include <Strsafe.h>

+#include "Core/Core.h"
 #include "Core/Debug.h"
 #include "Core/Types.h"
 #include "Core/Util.h"

dev mailing list
dev at openvswitch.org

More information about the dev mailing list