From a0045b428f1e6c20fd8a31dec22d7f16ffef86f3 Mon Sep 17 00:00:00 2001 From: Sorin Vinturis Date: Fri, 25 Mar 2016 14:49:26 +0000 Subject: [PATCH] datapath-windows: Percpu allocation support function Signed-off-by: Sorin Vinturis Co-authored-by: Alin Gabriel Serdean Acked-by: Nithin Raju Signed-off-by: Ben Pfaff --- datapath-windows/ovsext/Util.c | 16 ++++++++++++++++ datapath-windows/ovsext/Util.h | 1 + 2 files changed, 17 insertions(+) diff --git a/datapath-windows/ovsext/Util.c b/datapath-windows/ovsext/Util.c index 65dd1327a..14c4493b0 100644 --- a/datapath-windows/ovsext/Util.c +++ b/datapath-windows/ovsext/Util.c @@ -116,3 +116,19 @@ OvsCompareString(PVOID string1, PVOID string2) RtlInitString(&str2, string2); return RtlEqualString(&str1, &str2, FALSE); } + +VOID * +OvsAllocateMemoryPerCpu(size_t size, ULONG tag) +{ + VOID *ptr = NULL; + ULONG count = KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS); + + ASSERT(KeQueryActiveGroupCount() == 1); + + ptr = OvsAllocateMemoryWithTag(count * size, tag); + if (ptr) { + RtlZeroMemory(ptr, count * size); + } + + return ptr; +} diff --git a/datapath-windows/ovsext/Util.h b/datapath-windows/ovsext/Util.h index a81c723b0..b2ec798e0 100644 --- a/datapath-windows/ovsext/Util.h +++ b/datapath-windows/ovsext/Util.h @@ -40,6 +40,7 @@ VOID *OvsAllocateMemory(size_t size); VOID *OvsAllocateMemoryWithTag(size_t size, ULONG tag); VOID *OvsAllocateAlignedMemory(size_t size, UINT16 align); +VOID *OvsAllocateMemoryPerCpu(size_t size, ULONG tag); VOID OvsFreeMemory(VOID *ptr); VOID OvsFreeMemoryWithTag(VOID *ptr, ULONG tag); VOID OvsFreeAlignedMemory(VOID *ptr);