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

[win-pv-devel] [PATCH 1/3] Add the boilerplate for a new Poller sub-system



The intention is that the separate Receiver and Transmitter event and DPC
handling be combined into a single sub-system. This patch lays the ground-
work for that to be done.

Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx>
---
 src/xenvif/frontend.c        |  85 ++++++++++++-----
 src/xenvif/frontend.h        |   7 ++
 src/xenvif/poller.c          | 217 +++++++++++++++++++++++++++++++++++++++++++
 src/xenvif/poller.h          |  80 ++++++++++++++++
 vs2015/xenvif/xenvif.vcxproj |   1 +
 5 files changed, 367 insertions(+), 23 deletions(-)
 create mode 100644 src/xenvif/poller.c
 create mode 100644 src/xenvif/poller.h

diff --git a/src/xenvif/frontend.c b/src/xenvif/frontend.c
index a04d886..f715c19 100644
--- a/src/xenvif/frontend.c
+++ b/src/xenvif/frontend.c
@@ -47,6 +47,7 @@
 #include "tcpip.h"
 #include "receiver.h"
 #include "transmitter.h"
+#include "poller.h"
 #include "link.h"
 #include "dbg_print.h"
 #include "assert.h"
@@ -86,6 +87,7 @@ struct _XENVIF_FRONTEND {
     PXENVIF_MAC                 Mac;
     PXENVIF_RECEIVER            Receiver;
     PXENVIF_TRANSMITTER         Transmitter;
+    PXENVIF_POLLER              Poller;
     PXENVIF_CONTROLLER          Controller;
 
     XENBUS_DEBUG_INTERFACE      DebugInterface;
@@ -338,6 +340,7 @@ FrontendGet ## _Function(                               \
 DEFINE_FRONTEND_GET_FUNCTION(Mac, PXENVIF_MAC)
 DEFINE_FRONTEND_GET_FUNCTION(Receiver, PXENVIF_RECEIVER)
 DEFINE_FRONTEND_GET_FUNCTION(Transmitter, PXENVIF_TRANSMITTER)
+DEFINE_FRONTEND_GET_FUNCTION(Poller, PXENVIF_POLLER)
 DEFINE_FRONTEND_GET_FUNCTION(Controller, PXENVIF_CONTROLLER)
 
 static BOOLEAN
@@ -2207,18 +2210,22 @@ FrontendConnect(
     FrontendSetNumQueues(Frontend);
     FrontendSetSplit(Frontend);
 
-    status = ReceiverConnect(__FrontendGetReceiver(Frontend));
+    status = PollerConnect(__FrontendGetPoller(Frontend));
     if (!NT_SUCCESS(status))
         goto fail4;
 
-    status = TransmitterConnect(__FrontendGetTransmitter(Frontend));
+    status = ReceiverConnect(__FrontendGetReceiver(Frontend));
     if (!NT_SUCCESS(status))
         goto fail5;
 
-    status = ControllerConnect(__FrontendGetController(Frontend));
+    status = TransmitterConnect(__FrontendGetTransmitter(Frontend));
     if (!NT_SUCCESS(status))
         goto fail6;
 
+    status = ControllerConnect(__FrontendGetController(Frontend));
+    if (!NT_SUCCESS(status))
+        goto fail7;
+
     Attempt = 0;
     do {
         PXENBUS_STORE_TRANSACTION   Transaction;
@@ -2229,6 +2236,11 @@ FrontendConnect(
         if (!NT_SUCCESS(status))
             break;
 
+        status = PollerStoreWrite(__FrontendGetPoller(Frontend),
+                                  Transaction);
+        if (!NT_SUCCESS(status))
+            goto abort;
+
         status = ReceiverStoreWrite(__FrontendGetReceiver(Frontend),
                                     Transaction);
         if (!NT_SUCCESS(status))
@@ -2272,7 +2284,7 @@ abort:
     } while (status == STATUS_RETRY);
 
     if (!NT_SUCCESS(status))
-        goto fail7;
+        goto fail8;
 
     State = XenbusStateUnknown;
     while (State != XenbusStateConnected) {
@@ -2311,7 +2323,7 @@ abort:
 
     status = STATUS_UNSUCCESSFUL;
     if (State != XenbusStateConnected)
-        goto fail8;
+        goto fail9;
 
     ControllerEnable(__FrontendGetController(Frontend));
 
@@ -2320,23 +2332,28 @@ abort:
     Trace("<====\n");
     return STATUS_SUCCESS;
 
+fail9:
+    Error("fail9\n");
+
 fail8:
     Error("fail8\n");
 
+    ControllerDisconnect(__FrontendGetController(Frontend));
+
 fail7:
     Error("fail7\n");
 
-    ControllerDisconnect(__FrontendGetController(Frontend));
+    TransmitterDisconnect(__FrontendGetTransmitter(Frontend));
 
 fail6:
     Error("fail6\n");
 
-    TransmitterDisconnect(__FrontendGetTransmitter(Frontend));
+    ReceiverDisconnect(__FrontendGetReceiver(Frontend));
 
 fail5:
     Error("fail5\n");
 
-    ReceiverDisconnect(__FrontendGetReceiver(Frontend));
+    PollerDisconnect(__FrontendGetPoller(Frontend));
 
 fail4:
     Error("fail4\n");
@@ -2378,6 +2395,7 @@ FrontendDisconnect(
     ControllerDisconnect(__FrontendGetController(Frontend));
     TransmitterDisconnect(__FrontendGetTransmitter(Frontend));
     ReceiverDisconnect(__FrontendGetReceiver(Frontend));
+    PollerDisconnect(__FrontendGetPoller(Frontend));
     MacDisconnect(__FrontendGetMac(Frontend));
 
     Frontend->Split = FALSE;
@@ -2406,32 +2424,41 @@ FrontendEnable(
     if (!NT_SUCCESS(status))
         goto fail1;
 
-    status = ReceiverEnable(__FrontendGetReceiver(Frontend));
+    status = PollerEnable(__FrontendGetPoller(Frontend));
     if (!NT_SUCCESS(status))
         goto fail2;
 
-    status = TransmitterEnable(__FrontendGetTransmitter(Frontend));
+    status = ReceiverEnable(__FrontendGetReceiver(Frontend));
     if (!NT_SUCCESS(status))
         goto fail3;
 
-    status = __FrontendUpdateHash(Frontend, &Frontend->Hash);
+    status = TransmitterEnable(__FrontendGetTransmitter(Frontend));
     if (!NT_SUCCESS(status))
         goto fail4;
 
+    status = __FrontendUpdateHash(Frontend, &Frontend->Hash);
+    if (!NT_SUCCESS(status))
+        goto fail5;
+
     (VOID) FrontendNotifyMulticastAddresses(Frontend, TRUE);
 
     Trace("<====\n");
     return STATUS_SUCCESS;
 
+fail5:
+    Error("fail5\n");
+
+    TransmitterDisable(__FrontendGetTransmitter(Frontend));
+
 fail4:
     Error("fail4\n");
 
-    TransmitterDisable(__FrontendGetTransmitter(Frontend));
+    ReceiverDisable(__FrontendGetReceiver(Frontend));
 
 fail3:
     Error("fail3\n");
 
-    ReceiverDisable(__FrontendGetReceiver(Frontend));
+    PollerDisable(__FrontendGetPoller(Frontend));
 
 fail2:
     Error("fail2\n");
@@ -2455,6 +2482,7 @@ FrontendDisable(
 
     TransmitterDisable(__FrontendGetTransmitter(Frontend));
     ReceiverDisable(__FrontendGetReceiver(Frontend));
+    PollerDisable(__FrontendGetPoller(Frontend));
     MacDisable(__FrontendGetMac(Frontend));
 
     Trace("<====\n");
@@ -2866,19 +2894,23 @@ FrontendInitialize(
     if (!NT_SUCCESS(status))
         goto fail8;
 
-    status = ControllerInitialize(*Frontend, &(*Frontend)->Controller);
+    status = PollerInitialize(*Frontend, &(*Frontend)->Poller);
     if (!NT_SUCCESS(status))
         goto fail9;
 
+    status = ControllerInitialize(*Frontend, &(*Frontend)->Controller);
+    if (!NT_SUCCESS(status))
+        goto fail10;
+
     KeInitializeEvent(&(*Frontend)->EjectEvent, NotificationEvent, FALSE);
 
     status = ThreadCreate(FrontendEject, *Frontend, &(*Frontend)->EjectThread);
     if (!NT_SUCCESS(status))
-        goto fail10;
+        goto fail11;
 
     status = ThreadCreate(FrontendMib, *Frontend, &(*Frontend)->MibThread);
     if (!NT_SUCCESS(status))
-        goto fail11;
+        goto fail12;
 
     (*Frontend)->StatisticsCount = 
KeQueryMaximumProcessorCountEx(ALL_PROCESSOR_GROUPS);
     (*Frontend)->Statistics = __FrontendAllocate(sizeof 
(XENVIF_FRONTEND_STATISTICS) *
@@ -2886,34 +2918,38 @@ FrontendInitialize(
 
     status = STATUS_NO_MEMORY;
     if ((*Frontend)->Statistics == NULL)
-        goto fail12;
+        goto fail13;
 
     Trace("<====\n");
 
     return STATUS_SUCCESS;
 
-fail12:
-    Error("fail12\n");
+fail13:
+    Error("fail13\n");
 
     ThreadAlert((*Frontend)->MibThread);
     ThreadJoin((*Frontend)->MibThread);
     (*Frontend)->MibThread = NULL;
 
-fail11:
-    Error("fail11\n");
+fail12:
+    Error("fail12\n");
 
     ThreadAlert((*Frontend)->EjectThread);
     ThreadJoin((*Frontend)->EjectThread);
     (*Frontend)->EjectThread = NULL;
 
-fail10:
-    Error("fail10\n");
+fail11:
+    Error("fail11\n");
 
     RtlZeroMemory(&(*Frontend)->EjectEvent, sizeof (KEVENT));
 
     ControllerTeardown(__FrontendGetController(*Frontend));
     (*Frontend)->Controller = NULL;
 
+fail10:
+    PollerTeardown(__FrontendGetPoller(*Frontend));
+    (*Frontend)->Poller = NULL;
+
 fail9:
     TransmitterTeardown(__FrontendGetTransmitter(*Frontend));
     (*Frontend)->Transmitter = NULL;
@@ -3021,6 +3057,9 @@ FrontendTeardown(
     ControllerTeardown(__FrontendGetController(Frontend));
     Frontend->Controller = NULL;
 
+    PollerTeardown(__FrontendGetPoller(Frontend));
+    Frontend->Poller = NULL;
+
     TransmitterTeardown(__FrontendGetTransmitter(Frontend));
     Frontend->Transmitter = NULL;
 
diff --git a/src/xenvif/frontend.h b/src/xenvif/frontend.h
index 8e5552e..92008d0 100644
--- a/src/xenvif/frontend.h
+++ b/src/xenvif/frontend.h
@@ -166,6 +166,13 @@ FrontendGetTransmitter(
     IN  PXENVIF_FRONTEND    Frontend
     );
 
+#include "poller.h"
+
+extern PXENVIF_POLLER
+FrontendGetPoller(
+    IN  PXENVIF_FRONTEND    Frontend
+    );
+
 #include "controller.h"
 
 extern PXENVIF_CONTROLLER
diff --git a/src/xenvif/poller.c b/src/xenvif/poller.c
new file mode 100644
index 0000000..4ac358e
--- /dev/null
+++ b/src/xenvif/poller.c
@@ -0,0 +1,217 @@
+/* Copyright (c) Citrix Systems Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * *   Redistributions of source code must retain the above
+ *     copyright notice, this list of conditions and the
+ *     following disclaimer.
+ * *   Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the
+ *     following disclaimer in the documetation and/or other
+ *     materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ntddk.h>
+#include <procgrp.h>
+#include <ntstrsafe.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <xen.h>
+
+#include <debug_interface.h>
+#include <store_interface.h>
+#include <evtchn_interface.h>
+
+#include "pdo.h"
+#include "frontend.h"
+#include "poller.h"
+#include "vif.h"
+#include "thread.h"
+#include "registry.h"
+#include "dbg_print.h"
+#include "assert.h"
+#include "util.h"
+
+#define MAXNAMELEN  128
+
+struct _XENVIF_POLLER {
+    PXENVIF_FRONTEND        Frontend;
+    XENBUS_DEBUG_INTERFACE  DebugInterface;
+    PXENBUS_DEBUG_CALLBACK  DebugCallback;
+};
+
+#define XENVIF_POLLER_TAG  'LLOP'
+
+static FORCEINLINE PVOID
+__PollerAllocate(
+    IN  ULONG   Length
+    )
+{
+    return __AllocatePoolWithTag(NonPagedPool, Length, XENVIF_POLLER_TAG);
+}
+
+static FORCEINLINE VOID
+__PollerFree(
+    IN  PVOID   Buffer
+    )
+{
+    __FreePoolWithTag(Buffer, XENVIF_POLLER_TAG);
+}
+
+static VOID
+PollerDebugCallback(
+    IN  PVOID   Argument,
+    IN  BOOLEAN Crashing
+    )
+{
+    UNREFERENCED_PARAMETER(Argument);
+    UNREFERENCED_PARAMETER(Crashing);
+}
+
+NTSTATUS
+PollerInitialize(
+    IN  PXENVIF_FRONTEND    Frontend,
+    OUT PXENVIF_POLLER      *Poller
+    )
+{
+    NTSTATUS                status;
+
+    *Poller = __PollerAllocate(sizeof (XENVIF_POLLER));
+
+    status = STATUS_NO_MEMORY;
+    if (*Poller == NULL)
+        goto fail1;
+
+    FdoGetDebugInterface(PdoGetFdo(FrontendGetPdo(Frontend)),
+                         &(*Poller)->DebugInterface);
+
+    (*Poller)->Frontend = Frontend;
+
+    return STATUS_SUCCESS;
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
+}
+
+NTSTATUS
+PollerConnect(
+    IN  PXENVIF_POLLER  Poller
+    )
+{
+    NTSTATUS            status;
+
+    Trace("====>\n");
+
+    status = XENBUS_DEBUG(Acquire, &Poller->DebugInterface);
+    if (!NT_SUCCESS(status))
+        goto fail1;
+
+    status = XENBUS_DEBUG(Register,
+                          &Poller->DebugInterface,
+                          __MODULE__ "|POLLER",
+                          PollerDebugCallback,
+                          Poller,
+                          &Poller->DebugCallback);
+    if (!NT_SUCCESS(status))
+        goto fail2;
+
+    Trace("<====\n");
+    return STATUS_SUCCESS;
+
+fail2:
+    Error("fail2\n");
+
+    XENBUS_DEBUG(Release, &Poller->DebugInterface);
+
+fail1:
+    Error("fail1 (%08x)\n", status);
+
+    return status;
+}
+
+NTSTATUS
+PollerStoreWrite(
+    IN  PXENVIF_POLLER              Poller,
+    IN  PXENBUS_STORE_TRANSACTION   Transaction
+    )
+{
+    UNREFERENCED_PARAMETER(Poller);
+    UNREFERENCED_PARAMETER(Transaction);
+
+    Trace("<===>\n");
+
+    return STATUS_SUCCESS;
+}
+
+NTSTATUS
+PollerEnable(
+    IN  PXENVIF_POLLER      Poller
+    )
+{
+    UNREFERENCED_PARAMETER(Poller);
+
+    Trace("<===>\n");
+
+    return STATUS_SUCCESS;
+}
+
+VOID
+PollerDisable(
+    IN  PXENVIF_POLLER      Poller
+    )
+{
+    UNREFERENCED_PARAMETER(Poller);
+
+    Trace("<===>\n");
+}
+
+VOID
+PollerDisconnect(
+    IN  PXENVIF_POLLER  Poller
+    )
+{
+    Trace("====>\n");
+
+    XENBUS_DEBUG(Deregister,
+                 &Poller->DebugInterface,
+                 Poller->DebugCallback);
+    Poller->DebugCallback = NULL;
+
+    XENBUS_DEBUG(Release, &Poller->DebugInterface);
+
+    Trace("<====\n");
+}
+
+VOID
+PollerTeardown(
+    IN  PXENVIF_POLLER  Poller
+    )
+{
+    ASSERT3U(KeGetCurrentIrql(), ==, PASSIVE_LEVEL);
+
+    RtlZeroMemory(&Poller->DebugInterface,
+                  sizeof (XENBUS_DEBUG_INTERFACE));
+
+    ASSERT(IsZeroMemory(Poller, sizeof (XENVIF_POLLER)));
+    __PollerFree(Poller);
+}
diff --git a/src/xenvif/poller.h b/src/xenvif/poller.h
new file mode 100644
index 0000000..5ba0eaa
--- /dev/null
+++ b/src/xenvif/poller.h
@@ -0,0 +1,80 @@
+/* Copyright (c) Citrix Systems Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms,
+ * with or without modification, are permitted provided
+ * that the following conditions are met:
+ *
+ * *   Redistributions of source code must retain the above
+ *     copyright notice, this list of conditions and the
+ *     following disclaimer.
+ * *   Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the
+ *     following disclaimer in the documentation and/or other
+ *     materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _XENVIF_POLLER_H
+#define _XENVIF_POLLER_H
+
+#include <ntddk.h>
+
+#include <vif_interface.h>
+
+#include "frontend.h"
+
+typedef struct _XENVIF_POLLER XENVIF_POLLER, *PXENVIF_POLLER;
+
+extern NTSTATUS
+PollerInitialize(
+    IN  PXENVIF_FRONTEND    Frontend,
+    OUT PXENVIF_POLLER  *Poller
+    );
+
+extern NTSTATUS
+PollerConnect(
+    IN  PXENVIF_POLLER  Poller
+    );
+
+extern NTSTATUS
+PollerStoreWrite(
+    IN  PXENVIF_POLLER          Poller,
+    IN  PXENBUS_STORE_TRANSACTION   Transaction
+    );
+
+extern NTSTATUS
+PollerEnable(
+    IN  PXENVIF_POLLER  Poller
+    );
+
+extern VOID
+PollerDisable(
+    IN  PXENVIF_POLLER  Poller
+    );
+
+extern VOID
+PollerDisconnect(
+    IN  PXENVIF_POLLER  Poller
+    );
+
+extern VOID
+PollerTeardown(
+    IN  PXENVIF_POLLER  Poller
+    );
+
+#endif  // _XENVIF_POLLER_H
diff --git a/vs2015/xenvif/xenvif.vcxproj b/vs2015/xenvif/xenvif.vcxproj
index 076d873..cc39f8d 100644
--- a/vs2015/xenvif/xenvif.vcxproj
+++ b/vs2015/xenvif/xenvif.vcxproj
@@ -73,6 +73,7 @@
     <ClCompile Include="../../src/xenvif/mac.c" />
     <ClCompile Include="../../src/xenvif/parse.c" />
     <ClCompile Include="../../src/xenvif/pdo.c" />
+    <ClCompile Include="../../src/xenvif/poller.c" />
     <ClCompile Include="../../src/xenvif/receiver.c" />
     <ClCompile Include="../../src/xenvif/registry.c" />
     <ClCompile Include="../../src/xenvif/settings.c" />
-- 
2.5.3


_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://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®.