[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[win-pv-devel] [PATCH] Make XENNET processor group aware



Processor groups have been around for a long time in Windows and
contnuing to ignore them becomes ever more painful when trying to
pass the HCK multiple processor group device test. This patch, therefore,
modifies all the code that uses the non-group-aware kernel calls to use
the newer group aware calls.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xennet/driver.c          |  2 ++
 src/xennet/receiver.c        | 53 ++++++++++++++++++++++++++++++++------------
 vs2012/xennet/xennet.vcxproj |  4 ++--
 vs2013/xennet/xennet.vcxproj |  4 ++--
 4 files changed, 45 insertions(+), 18 deletions(-)

diff --git a/src/xennet/driver.c b/src/xennet/driver.c
index c6a4896..e77ae6e 100644
--- a/src/xennet/driver.c
+++ b/src/xennet/driver.c
@@ -32,6 +32,7 @@
 #define INITGUID 1
 
 #include <ndis.h>
+#include <procgrp.h>
 #include "adapter.h"
 #include <version.h>
 #include "dbg_print.h"
@@ -411,6 +412,7 @@ DriverEntry (
     ULONG FailDeviceControl;
 
     ExInitializeDriverRuntime(DrvRtPoolNxOptIn);
+    WdmlibProcgrpInitialize();
 
     Trace("====>\n");
 
diff --git a/src/xennet/receiver.c b/src/xennet/receiver.c
index dcd88af..95285cd 100644
--- a/src/xennet/receiver.c
+++ b/src/xennet/receiver.c
@@ -29,6 +29,8 @@
  * SUCH DAMAGE.
  */
 
+#include <ndis.h>
+#include <procgrp.h>
 #include "receiver.h"
 #include "adapter.h"
 #include <util.h>
@@ -39,7 +41,8 @@ struct _XENNET_RECEIVER {
     PXENNET_ADAPTER             Adapter;
     NDIS_HANDLE                 NetBufferListPool;
     PNET_BUFFER_LIST            PutList;
-    PNET_BUFFER_LIST            GetList[MAXIMUM_PROCESSORS];
+    PNET_BUFFER_LIST            *GetList;
+    ULONG                       GetListCount;
     LONG                        InNDIS;
     LONG                        InNDISMax;
     XENVIF_VIF_OFFLOAD_OPTIONS  OffloadOptions;
@@ -56,22 +59,23 @@ __ReceiverAllocateNetBufferList(
     IN  ULONG               Length
     )
 {
-    ULONG                   Cpu;
+    ULONG                   Index;
     PNET_BUFFER_LIST        NetBufferList;
 
-    Cpu = KeGetCurrentProcessorNumber();
+    Index = KeGetCurrentProcessorNumberEx(NULL);
+    ASSERT3U(Index, <, Receiver->GetListCount);
 
-    NetBufferList = Receiver->GetList[Cpu];
+    NetBufferList = Receiver->GetList[Index];
 
-    if (NetBufferList == NULL)
-        Receiver->GetList[Cpu] = 
InterlockedExchangePointer(&Receiver->PutList, NULL);
-
-    NetBufferList = Receiver->GetList[Cpu];
+    if (NetBufferList == NULL) {
+        Receiver->GetList[Index] = 
InterlockedExchangePointer(&Receiver->PutList, NULL);
+        NetBufferList = Receiver->GetList[Index];
+    }
 
     if (NetBufferList != NULL) {
         PNET_BUFFER NetBuffer;
 
-        Receiver->GetList[Cpu] = NET_BUFFER_LIST_NEXT_NBL(NetBufferList);
+        Receiver->GetList[Index] = NET_BUFFER_LIST_NEXT_NBL(NetBufferList);
         NET_BUFFER_LIST_NEXT_NBL(NetBufferList) = NULL;
 
         NetBuffer = NET_BUFFER_LIST_FIRST_NB(NetBufferList);
@@ -285,6 +289,16 @@ ReceiverInitialize(
     RtlZeroMemory(*Receiver, sizeof(XENNET_RECEIVER));
     (*Receiver)->Adapter = Adapter;
 
+    (*Receiver)->GetListCount = 
KeQueryActiveProcessorCountEx(ALL_PROCESSOR_GROUPS);
+    (*Receiver)->GetList = ExAllocatePoolWithTag(NonPagedPool,
+                                                 sizeof(PNET_BUFFER_LIST) *
+                                                 (*Receiver)->GetListCount,
+                                                 RECEIVER_POOL_TAG);
+
+    status = NDIS_STATUS_RESOURCES;
+    if ((*Receiver)->GetList == NULL)
+        goto fail2;
+
     RtlZeroMemory(&Params, sizeof(NET_BUFFER_LIST_POOL_PARAMETERS));
     Params.Header.Type = NDIS_OBJECT_TYPE_DEFAULT;
     Params.Header.Revision = NET_BUFFER_LIST_POOL_PARAMETERS_REVISION_1;
@@ -299,11 +313,18 @@ ReceiverInitialize(
 
     status = NDIS_STATUS_RESOURCES;
     if ((*Receiver)->NetBufferListPool == NULL)
-        goto fail2;
+        goto fail3;
 
     return NDIS_STATUS_SUCCESS;
 
+fail3:
+    ExFreePoolWithTag((*Receiver)->GetList, RECEIVER_POOL_TAG);
+    (*Receiver)->GetListCount = 0;
+
 fail2:
+    ExFreePoolWithTag(*Receiver, RECEIVER_POOL_TAG);
+    *Receiver = NULL;
+
 fail1:
     return status;
 }
@@ -313,13 +334,14 @@ ReceiverTeardown(
     IN  PXENNET_RECEIVER    Receiver
     )
 {
-    ULONG               Cpu;
-    PNET_BUFFER_LIST    NetBufferList;
+    ULONG                   Index;
+    PNET_BUFFER_LIST        NetBufferList;
 
     ASSERT(Receiver != NULL);
 
-    for (Cpu = 0; Cpu < MAXIMUM_PROCESSORS; Cpu++) {
-        NetBufferList = Receiver->GetList[Cpu];
+    for (Index = 0; Index < Receiver->GetListCount; Index++) {
+        NetBufferList = Receiver->GetList[Index];
+
         while (NetBufferList != NULL) {
             PNET_BUFFER_LIST    Next;
 
@@ -347,6 +369,9 @@ ReceiverTeardown(
     NdisFreeNetBufferListPool(Receiver->NetBufferListPool);
     Receiver->NetBufferListPool = NULL;
 
+    ExFreePoolWithTag(Receiver->GetList, RECEIVER_POOL_TAG);
+    Receiver->GetListCount = 0;
+
     Receiver->Adapter = NULL;
 
     ExFreePoolWithTag(Receiver, RECEIVER_POOL_TAG);
diff --git a/vs2012/xennet/xennet.vcxproj b/vs2012/xennet/xennet.vcxproj
index 03ddf91..0e2fc22 100644
--- a/vs2012/xennet/xennet.vcxproj
+++ b/vs2012/xennet/xennet.vcxproj
@@ -42,7 +42,7 @@
             <Inputs>..\..\src\xennet.inf;..\..\include\version.hx</Inputs>
         </CustomBuildStep>
                <ClCompile>
-                       
<PreprocessorDefinitions>__MODULE__="XENNET";NDIS_MINIPORT_DRIVER;NDIS60_MINIPORT=1;POOL_NX_OPTIN=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+                       
<PreprocessorDefinitions>__MODULE__="XENNET";NDIS_MINIPORT_DRIVER;NDIS60_MINIPORT=1;POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
                        <WarningLevel>EnableAllWarnings</WarningLevel>
                        
<DisableSpecificWarnings>4711;4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings>
                        
<MultiProcessorCompilation>true</MultiProcessorCompilation>
@@ -50,7 +50,7 @@
                </ClCompile>
                <Link>
                        
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
-                       
<AdditionalDependencies>$(DDK_LIB_PATH)\ndis.lib;%(AdditionalDependencies)</AdditionalDependencies>
+                       
<AdditionalDependencies>$(DDK_LIB_PATH)\ndis.lib;$(DDK_LIB_PATH)\procgrp.lib;%(AdditionalDependencies)</AdditionalDependencies>
                        <EnableCOMDATFolding>false</EnableCOMDATFolding>
                </Link>
                <Inf>
diff --git a/vs2013/xennet/xennet.vcxproj b/vs2013/xennet/xennet.vcxproj
index 6cb09d2..2eaf191 100644
--- a/vs2013/xennet/xennet.vcxproj
+++ b/vs2013/xennet/xennet.vcxproj
@@ -74,7 +74,7 @@
       <Inputs>..\..\src\xennet.inf;..\..\include\version.hx</Inputs>
     </CustomBuildStep>
     <ClCompile>
-      
<PreprocessorDefinitions>__MODULE__="XENNET";NDIS_MINIPORT_DRIVER;NDIS60_MINIPORT=1;POOL_NX_OPTIN=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      
<PreprocessorDefinitions>__MODULE__="XENNET";NDIS_MINIPORT_DRIVER;NDIS60_MINIPORT=1;POOL_NX_OPTIN=1;NT_PROCESSOR_GROUPS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <WarningLevel>EnableAllWarnings</WarningLevel>
       
<DisableSpecificWarnings>4711;4548;4820;4668;4255;6001;6054;28196;%(DisableSpecificWarnings)</DisableSpecificWarnings>
       <MultiProcessorCompilation>true</MultiProcessorCompilation>
@@ -82,7 +82,7 @@
     </ClCompile>
     <Link>
       <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
-      
<AdditionalDependencies>$(DDK_LIB_PATH)\ndis.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      
<AdditionalDependencies>$(DDK_LIB_PATH)\ndis.lib;$(DDK_LIB_PATH)\procgrp.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <EnableCOMDATFolding>false</EnableCOMDATFolding>
     </Link>
     <Inf>
-- 
2.1.1


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.