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

[PATCH] Rate limit per DPC using both xenvif and xennet.


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Martin Harvey <Martin.Harvey@xxxxxxxxxx>
  • Date: Fri, 20 May 2022 15:14:50 +0100
  • Authentication-results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Martin Harvey <Martin.Harvey@xxxxxxxxxx>, Martin Harvey <martin.harvey@xxxxxxxxxx>
  • Delivery-date: Fri, 20 May 2022 14:15:05 +0000
  • Ironport-data: A9a23:nYAQGKmV8CbCZKdDtgX8N0Xo5gzGJkRdPkR7XQ2eYbSJt1+Wr1Gzt xIaD2iAa/2KMzfweoh/aNjkpE4O7ZSGm9dkTAtp/no9QiMWpZLJC+rCIxarNUt+DCFioGGLT Sk6QoOdRCzhZiaE/n9BCpC48T8kk/vgqoPUUIYoAAgoLeNfYHpn2EsLd9IR2NYy24DkWVvV4 LsenuWEULOb828sWo4rw/rrRCNH5JwebxtB4zTSzdgS1LPvvyF94KA3fMldHFOhKmVgJcaoR v6r8V2M1jixEyHBqD+Suu2TnkUiGtY+NOUV45Zcc/DKbhNq/kTe3kunXRa1hIg+ZzihxrhMJ NtxWZOYUQkQOo3OlvgkcDphSghDLfMeqLzqPi3q2SCT5xWun3rExvxvCAc9PJEC+/YxCmZLn RAaAGlTNFbZ3bvwme/lDLk37iggBJCD0Ic3v3h60TDfS/YvW47OUo3B5MNC3Sd2jcdLdRrbT 5VDMGs0M06dC/FJElsqKpADl7qLuiDiKwxgtgzWirYR/FGGmWSd15CyaYGIK7RmX/59gUee4 3rYumj0HBweHNie0iaetGKhgPfVmiH2U55UE6e3nsOGm3XKmDZVUkdPEwLm/7/p0SZSRu6zN WQM9BMqjao86HWIbeCkdiCo/ibUvTMDDo84//IB1O2d9kbFy1/HWzNcF2YfNINOWNweHmJzi ALQ9z/9LXk26eDOFyrAnluBhWnqURX5O1PucsPtoeEtx9D46L8+gRvUJjqIOP7k14alcd0cL t3jkcTfu1nwpZRSv0lD1Qqb6w9AX7CQJuLP2i3ZX3i+8iRyb5O/aoqj5DDztKgddtbIHgnf5 SNawaByCdzi6rnUy0SwrBglRun1t55pzhWB6bKQI3XR32v0oCPyFWyhyDp/OF1oIq45lczBO SfuVfdqzMYLZhOCNPYvC6roUphC5fWwRLzNC6GPBvITM8cZSeNy1Hw3DaJm9zu2yxZEfGBWE crzTPtA+l5BUvQ7nGTsFrhBuVLprwhnrV7uqVnA50zP+dKjiLS9E9/p7HPmgjgF0Z65
  • Ironport-hdrordr: A9a23:f+Q62qhkScF2ML+fBRbfLy74DHBQXtYji2hC6mlwRA09TySZ// rBoB19726RtN9xYgBHpTnuAsm9qB/nmaKdgrNhWItKPjOW21dARbsKheCJrgEIcxeOkdK1vp 0AT0ERMrLN5CBB/KTH3DU=
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

Further development of rate limiting code, whereby both xenvif
and xennet co-operate across the VIF interface to decide how
many packets to push up the stack. This allows for the situation
where NDIS could provide information at upstream push time about
how many more packets it is prepared to accept in this DPC.

Signed-off-by: Martin Harvey <martin.harvey@xxxxxxxxxx>
---
 include/vif_interface.h | 103 +++++++++++++++++++++++++++++++++++++---
 src/xennet.inf          |   6 +--
 src/xennet/adapter.c    |  64 ++++++-------------------
 src/xennet/receiver.c   |  12 ++++-
 src/xennet/receiver.h   |   3 +-
 5 files changed, 126 insertions(+), 62 deletions(-)

diff --git a/include/vif_interface.h b/include/vif_interface.h
index 20de314..7056783 100644
--- a/include/vif_interface.h
+++ b/include/vif_interface.h
@@ -408,7 +408,7 @@ typedef VOID
     IN  PINTERFACE  Interface
     );
 
-/*! \typedef XENVIF_VIF_CALLBACK
+/*! \typedef XENVIF_VIF_CALLBACK_V6
     \brief Provider to subscriber callback function
 
     \param Argument An optional context argument passed to the callback
@@ -436,13 +436,72 @@ typedef VOID
     No additional arguments
 */
 typedef VOID
-(*XENVIF_VIF_CALLBACK)(
+(*XENVIF_VIF_CALLBACK_V6)(
     IN  PVOID                       Argument OPTIONAL,
     IN  XENVIF_VIF_CALLBACK_TYPE    Type,
     ...
     );
 
-/*! \typedef XENVIF_VIF_ENABLE
+/*! \typedef XENVIF_VIF_ENABLE_V6
+    \brief Enable the VIF interface
+
+    All packets queued for transmit will be rejected and no packets will
+    be queued for receive until this method completes. 
+
+    \param Interface The interface header
+    \param Callback The subscriber's callback function
+    \param Argument An optional context argument passed to the callback
+*/
+typedef NTSTATUS
+(*XENVIF_VIF_ENABLE_V6)(
+    IN  PINTERFACE          Interface,
+    IN  XENVIF_VIF_CALLBACK_V6 Callback,
+    IN  PVOID               Argument OPTIONAL
+    );
+
+
+typedef union _XENVIF_VIF_CALLBACK_PARAMS {
+    struct _XENVIF_VIF_CALLBACK_RETURN_PACKET_PARAMS {
+        PVOID Cookie;
+        PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO Completion;
+    } ReturnPacketParams;
+    struct _XENVIF_VIF_CALLBACK_QUEUE_PACKET_PARAMS {
+        ULONG Index;
+        PMDL Mdl;
+        ULONG Offset;
+        ULONG Length;
+        XENVIF_PACKET_CHECKSUM_FLAGS Flags;
+        USHORT MaximumSegmentSize;
+        USHORT TagControlInformation;
+        PXENVIF_PACKET_INFO Info;
+        PXENVIF_PACKET_HASH Hash;
+        BOOLEAN More;
+        PVOID Cookie;
+        PBOOLEAN NdisFinished;
+    } QueuePacketParams;
+    /*
+    struct _XENVIF_VIF_CALLBACK_STATE_CHANGE_PARAMS {
+        No parameters here
+    } StateChangeParams;
+    */
+} XENVIF_VIF_CALLBACK_PARAMS, *PXENVIF_VIF_CALLBACK_PARAMS;
+
+/*! \typedef XENVIF_VIF_CALLBACK
+    \brief Provider to subscriber callback function
+
+    \param Argument An optional context argument passed to the callback
+    \param Type The callback type
+    \param Params Additional paramaters required by \a Type
+*/
+
+typedef VOID
+(*XENVIF_VIF_CALLBACK)(
+    IN  PVOID                       Argument OPTIONAL,
+    IN  XENVIF_VIF_CALLBACK_TYPE    Type,
+    IN  PXENVIF_VIF_CALLBACK_PARAMS Params
+    );
+
+/*! \typedef XENVIF_VIF_ENABLE_V6
     \brief Enable the VIF interface
 
     All packets queued for transmit will be rejected and no packets will
@@ -834,7 +893,7 @@ struct _XENVIF_VIF_INTERFACE_V6 {
     INTERFACE                                       Interface;
     XENVIF_VIF_ACQUIRE                              Acquire;
     XENVIF_VIF_RELEASE                              Release;
-    XENVIF_VIF_ENABLE                               Enable;
+    XENVIF_VIF_ENABLE_V6                            Enable;
     XENVIF_VIF_DISABLE                              Disable;
     XENVIF_VIF_QUERY_STATISTIC                      QueryStatistic;
     XENVIF_VIF_QUERY_RING_COUNT                     QueryRingCount;
@@ -868,7 +927,7 @@ struct _XENVIF_VIF_INTERFACE_V7 {
     INTERFACE                                       Interface;
     XENVIF_VIF_ACQUIRE                              Acquire;
     XENVIF_VIF_RELEASE                              Release;
-    XENVIF_VIF_ENABLE                               Enable;
+    XENVIF_VIF_ENABLE_V6                            Enable;
     XENVIF_VIF_DISABLE                              Disable;
     XENVIF_VIF_QUERY_STATISTIC                      QueryStatistic;
     XENVIF_VIF_QUERY_RING_COUNT                     QueryRingCount;
@@ -899,6 +958,36 @@ struct _XENVIF_VIF_INTERFACE_V7 {
     \ingroup interfaces
 */
 struct _XENVIF_VIF_INTERFACE_V8 {
+    INTERFACE                                       Interface;
+    XENVIF_VIF_ACQUIRE                              Acquire;
+    XENVIF_VIF_RELEASE                              Release;
+    XENVIF_VIF_ENABLE_V6                            Enable;
+    XENVIF_VIF_DISABLE                              Disable;
+    XENVIF_VIF_QUERY_STATISTIC                      QueryStatistic;
+    XENVIF_VIF_QUERY_RING_COUNT                     QueryRingCount;
+    XENVIF_VIF_UPDATE_HASH_MAPPING                  UpdateHashMapping;
+    XENVIF_VIF_RECEIVER_RETURN_PACKET               ReceiverReturnPacket;
+    XENVIF_VIF_RECEIVER_SET_OFFLOAD_OPTIONS         ReceiverSetOffloadOptions;
+    XENVIF_VIF_RECEIVER_SET_BACKFILL_SIZE           ReceiverSetBackfillSize;
+    XENVIF_VIF_RECEIVER_QUERY_RING_SIZE             ReceiverQueryRingSize;
+    XENVIF_VIF_RECEIVER_SET_HASH_ALGORITHM          ReceiverSetHashAlgorithm;
+    XENVIF_VIF_RECEIVER_QUERY_HASH_CAPABILITIES     
ReceiverQueryHashCapabilities;
+    XENVIF_VIF_RECEIVER_UPDATE_HASH_PARAMETERS      
ReceiverUpdateHashParameters;
+    XENVIF_VIF_TRANSMITTER_QUEUE_PACKET             TransmitterQueuePacket;
+    XENVIF_VIF_TRANSMITTER_QUERY_OFFLOAD_OPTIONS    
TransmitterQueryOffloadOptions;
+    XENVIF_VIF_TRANSMITTER_QUERY_LARGE_PACKET_SIZE  
TransmitterQueryLargePacketSize;
+    XENVIF_VIF_TRANSMITTER_QUERY_RING_SIZE          TransmitterQueryRingSize;
+    XENVIF_VIF_MAC_QUERY_STATE                      MacQueryState;
+    XENVIF_VIF_MAC_QUERY_MAXIMUM_FRAME_SIZE         MacQueryMaximumFrameSize;
+    XENVIF_VIF_MAC_QUERY_PERMANENT_ADDRESS          MacQueryPermanentAddress;
+    XENVIF_VIF_MAC_QUERY_CURRENT_ADDRESS            MacQueryCurrentAddress;
+    XENVIF_VIF_MAC_QUERY_MULTICAST_ADDRESSES        MacQueryMulticastAddresses;
+    XENVIF_VIF_MAC_SET_MULTICAST_ADDRESSES          MacSetMulticastAddresses;
+    XENVIF_VIF_MAC_SET_FILTER_LEVEL                 MacSetFilterLevel;
+    XENVIF_VIF_MAC_QUERY_FILTER_LEVEL               MacQueryFilterLevel;
+};
+
+struct _XENVIF_VIF_INTERFACE_V9 {
     INTERFACE                                       Interface;
     XENVIF_VIF_ACQUIRE                              Acquire;
     XENVIF_VIF_RELEASE                              Release;
@@ -928,7 +1017,7 @@ struct _XENVIF_VIF_INTERFACE_V8 {
     XENVIF_VIF_MAC_QUERY_FILTER_LEVEL               MacQueryFilterLevel;
 };
 
-typedef struct _XENVIF_VIF_INTERFACE_V8 XENVIF_VIF_INTERFACE, 
*PXENVIF_VIF_INTERFACE;
+typedef struct _XENVIF_VIF_INTERFACE_V9 XENVIF_VIF_INTERFACE, 
*PXENVIF_VIF_INTERFACE;
 
 /*! \def XENVIF_VIF
     \brief Macro at assist in method invocation
@@ -939,6 +1028,6 @@ typedef struct _XENVIF_VIF_INTERFACE_V8 
XENVIF_VIF_INTERFACE, *PXENVIF_VIF_INTER
 #endif  // _WINDLL
 
 #define XENVIF_VIF_INTERFACE_VERSION_MIN    6
-#define XENVIF_VIF_INTERFACE_VERSION_MAX    8
+#define XENVIF_VIF_INTERFACE_VERSION_MAX    9
 
 #endif  // _XENVIF_INTERFACE_H
diff --git a/src/xennet.inf b/src/xennet.inf
index c44f4af..58ea5d7 100644
--- a/src/xennet.inf
+++ b/src/xennet.inf
@@ -61,9 +61,9 @@ 
xennet_coinst_@MAJOR_VERSION@_@MINOR_VERSION@_@MICRO_VERSION@_@BUILD_NUMBER@.dll
 ; DisplayName          Section         DeviceID
 ; -----------          -------         --------
 
-%XenNetName%           =XenNet_Inst,   
XENVIF\VEN_@VENDOR_PREFIX@@VENDOR_DEVICE_ID@&DEV_NET&REV_09000001
-%XenNetName%           =XenNet_Inst,   
XENVIF\VEN_@VENDOR_PREFIX@0001&DEV_NET&REV_09000001
-%XenNetName%           =XenNet_Inst,   
XENVIF\VEN_@VENDOR_PREFIX@0002&DEV_NET&REV_09000001
+%XenNetName%           =XenNet_Inst,   
XENVIF\VEN_@VENDOR_PREFIX@@VENDOR_DEVICE_ID@&DEV_NET&REV_09000002
+%XenNetName%           =XenNet_Inst,   
XENVIF\VEN_@VENDOR_PREFIX@0001&DEV_NET&REV_09000002
+%XenNetName%           =XenNet_Inst,   
XENVIF\VEN_@VENDOR_PREFIX@0002&DEV_NET&REV_09000002
 
 [XenNet_Inst] 
 Characteristics=0x84
diff --git a/src/xennet/adapter.c b/src/xennet/adapter.c
index 743cf35..9e8bebe 100644
--- a/src/xennet/adapter.c
+++ b/src/xennet/adapter.c
@@ -201,64 +201,32 @@ static VOID
 AdapterVifCallback(
     IN  PVOID                       Context,
     IN  XENVIF_VIF_CALLBACK_TYPE    Type,
-    ...
+    IN  PXENVIF_VIF_CALLBACK_PARAMS Params
     )
 {
     PXENNET_ADAPTER     Adapter = Context;
-    va_list             Arguments;
-
-    va_start(Arguments, Type);
 
     switch (Type) {
     case XENVIF_TRANSMITTER_RETURN_PACKET: {
-        PVOID                                       Cookie;
-        PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO  Completion;
-
-        Cookie = va_arg(Arguments, PVOID);
-        Completion = va_arg(Arguments, 
PXENVIF_TRANSMITTER_PACKET_COMPLETION_INFO);
-
         TransmitterReturnPacket(Adapter->Transmitter,
-                                Cookie,
-                                Completion);
+                                Params->ReturnPacketParams.Cookie,
+                                Params->ReturnPacketParams.Completion);
         break;
     }
     case XENVIF_RECEIVER_QUEUE_PACKET: {
-        ULONG                           Index;
-        PMDL                            Mdl;
-        ULONG                           Offset;
-        ULONG                           Length;
-        XENVIF_PACKET_CHECKSUM_FLAGS    Flags;
-        USHORT                          MaximumSegmentSize;
-        USHORT                          TagControlInformation;
-        PXENVIF_PACKET_INFO             Info;
-        PXENVIF_PACKET_HASH             Hash;
-        BOOLEAN                         More;
-        PVOID                           Cookie;
-
-        Index = va_arg(Arguments, ULONG);
-        Mdl = va_arg(Arguments, PMDL);
-        Offset = va_arg(Arguments, ULONG);
-        Length = va_arg(Arguments, ULONG);
-        Flags = va_arg(Arguments, XENVIF_PACKET_CHECKSUM_FLAGS);
-        MaximumSegmentSize = va_arg(Arguments, USHORT);
-        TagControlInformation = va_arg(Arguments, USHORT);
-        Info = va_arg(Arguments, PXENVIF_PACKET_INFO);
-        Hash = va_arg(Arguments, PXENVIF_PACKET_HASH);
-        More = va_arg(Arguments, BOOLEAN);
-        Cookie = va_arg(Arguments, PVOID);
-
         ReceiverQueuePacket(Adapter->Receiver,
-                            Index,
-                            Mdl,
-                            Offset,
-                            Length,
-                            Flags,
-                            MaximumSegmentSize,
-                            TagControlInformation,
-                            Info,
-                            Hash,
-                            More,
-                            Cookie);
+                            Params->QueuePacketParams.Index,
+                            Params->QueuePacketParams.Mdl,
+                            Params->QueuePacketParams.Offset,
+                            Params->QueuePacketParams.Length,
+                            Params->QueuePacketParams.Flags,
+                            Params->QueuePacketParams.MaximumSegmentSize,
+                            Params->QueuePacketParams.TagControlInformation,
+                            Params->QueuePacketParams.Info,
+                            Params->QueuePacketParams.Hash,
+                            Params->QueuePacketParams.More,
+                            Params->QueuePacketParams.Cookie,
+                            Params->QueuePacketParams.NdisFinished);
         break;
     }
     case XENVIF_MAC_STATE_CHANGE: {
@@ -266,8 +234,6 @@ AdapterVifCallback(
         break;
     }
     }
-
-    va_end(Arguments);
 }
 
 static VOID
diff --git a/src/xennet/receiver.c b/src/xennet/receiver.c
index 65527c5..d7a1e41 100644
--- a/src/xennet/receiver.c
+++ b/src/xennet/receiver.c
@@ -45,6 +45,7 @@ typedef struct _XENNET_RECEIVER_QUEUE {
     PNET_BUFFER_LIST    Head;
     PNET_BUFFER_LIST    Tail;
     ULONG               Count;
+    ULONG               SinceLastPush;
 } XENNET_RECEIVER_QUEUE, *PXENNET_RECEIVER_QUEUE;
 
 struct _XENNET_RECEIVER {
@@ -544,7 +545,8 @@ ReceiverQueuePacket(
     IN  PXENVIF_PACKET_INFO             Info,
     IN  PXENVIF_PACKET_HASH             Hash,
     IN  BOOLEAN                         More,
-    IN  PVOID                           Cookie
+    IN  PVOID                           Cookie,
+    OUT PBOOLEAN                        NdisFinished
     )
 {
     PXENVIF_VIF_INTERFACE               VifInterface;
@@ -582,11 +584,17 @@ ReceiverQueuePacket(
         Queue->Tail = NetBufferList;
     }
     Queue->Count++;
+    Queue->SinceLastPush++;
+
+    *NdisFinished = More && (Queue->SinceLastPush > IN_NDIS_MAX);
+
+    if (!More || (*NdisFinished))
+        Queue->SinceLastPush = 0;
 
     KeReleaseSpinLockFromDpcLevel(&Queue->Lock);
 
 done:
-    if (!More)
+    if (!More || (*NdisFinished))
         __ReceiverPushPackets(Receiver, Index);
 }
 
diff --git a/src/xennet/receiver.h b/src/xennet/receiver.h
index 5fc9e66..6089fd4 100644
--- a/src/xennet/receiver.h
+++ b/src/xennet/receiver.h
@@ -68,7 +68,8 @@ ReceiverQueuePacket(
     IN  PXENVIF_PACKET_INFO             Info,
     IN  PXENVIF_PACKET_HASH             Hash,
     IN  BOOLEAN                         More,
-    IN  PVOID                           Cookie
+    IN  PVOID                           Cookie,
+    OUT PBOOLEAN                        NdisFinished
     );
 
 extern PXENVIF_VIF_OFFLOAD_OPTIONS
-- 
2.25.0.windows.1




 


Rackspace

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