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

[win-pv-devel] [PATCH xenbus] Remove some code duplication in store.c...


  • To: <win-pv-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Paul Durrant <pdurrant@xxxxxxxxxx>
  • Date: Thu, 14 Nov 2019 17:46:54 +0000
  • Cc: Paul Durrant <pdurrant@xxxxxxxxxx>
  • Delivery-date: Thu, 14 Nov 2019 17:47:10 +0000
  • Ironport-sdr: FBkXwnk8CJCvKWcfQQQzr4yX3QFk/f5ahGytqd0gfOKOpqY4q2/Z1eDUusUrVUBL9/vjtW4nBH 17zJ4G7SLh9w==
  • List-id: Developer list for the Windows PV Drivers subproject <win-pv-devel.lists.xenproject.org>

...by using a new inline __StorePoll() function and returning event count
directly from StorePollLocked().

Signed-off-by: Paul Durrant <pdurrant@xxxxxxxxxx>
---
 src/xenbus/store.c | 54 ++++++++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 23 deletions(-)

diff --git a/src/xenbus/store.c b/src/xenbus/store.c
index 556d040..f07e469 100644
--- a/src/xenbus/store.c
+++ b/src/xenbus/store.c
@@ -824,11 +824,12 @@ StoreProcessResponse(
     KeMemoryBarrier();
 }
 
-static VOID
+static ULONG
 StorePollLocked(
     IN  PXENBUS_STORE_CONTEXT   Context
     )
 {
+    ULONG                       Count;
     ULONG                       Read;
     ULONG                       Written;
     NTSTATUS                    status;
@@ -837,6 +838,12 @@ StorePollLocked(
 
     Context->Polls++;
 
+    Count = XENBUS_EVTCHN(GetCount,
+                          &Context->EvtchnInterface,
+                          Context->Channel);
+
+    KeMemoryBarrier();
+
     do {
         Read = Written = 0;
 
@@ -856,6 +863,19 @@ StorePollLocked(
                                  Context->Channel);
 
     } while (Written != 0 || Read != 0);
+
+    return Count;
+}
+
+static FORCEINLINE VOID
+__StorePoll(
+    IN  PXENBUS_STORE_CONTEXT   Context
+    )
+{
+    KeAcquireSpinLockAtDpcLevel(&Context->Lock);
+    if (Context->References != 0)
+        (VOID) StorePollLocked(Context);
+    KeReleaseSpinLockFromDpcLevel(&Context->Lock);
 }
 
 static
@@ -879,11 +899,7 @@ StoreDpc(
     UNREFERENCED_PARAMETER(Argument2);
 
     ASSERT(Context != NULL);
-
-    KeAcquireSpinLockAtDpcLevel(&Context->Lock);
-    if (Context->References != 0)
-        StorePollLocked(Context);
-    KeReleaseSpinLockFromDpcLevel(&Context->Lock);
+    __StorePoll(Context);
 }
 
 #define TIME_US(_us)        ((_us) * 10)
@@ -902,6 +918,7 @@ StoreSubmitRequest(
     PXENBUS_STORE_RESPONSE      Response;
     KIRQL                       Irql;
     ULONG                       Count;
+    XENBUS_STORE_REQUEST_STATE  State;
     LARGE_INTEGER               Timeout;
 
     ASSERT3U(Request->State, ==, XENBUS_STORE_REQUEST_PREPARED);
@@ -916,16 +933,14 @@ StoreSubmitRequest(
 
     Request->State = XENBUS_STORE_REQUEST_SUBMITTED;
 
-    Count = XENBUS_EVTCHN(GetCount,
-                          &Context->EvtchnInterface,
-                          Context->Channel);
+    Count = StorePollLocked(Context);
 
-    StorePollLocked(Context);
     KeMemoryBarrier();
+    State = Request->State;
 
     Timeout.QuadPart = TIME_RELATIVE(TIME_S(XENBUS_STORE_POLL_PERIOD));
 
-    while (Request->State != XENBUS_STORE_REQUEST_COMPLETED) {
+    while (State != XENBUS_STORE_REQUEST_COMPLETED) {
         NTSTATUS    status;
 
         status = XENBUS_EVTCHN(Wait,
@@ -936,12 +951,10 @@ StoreSubmitRequest(
         if (status == STATUS_TIMEOUT)
             Warning("TIMED OUT\n");
 
-        Count = XENBUS_EVTCHN(GetCount,
-                              &Context->EvtchnInterface,
-                              Context->Channel);
+        Count = StorePollLocked(Context);
 
-        StorePollLocked(Context);
         KeMemoryBarrier();
+        State = Request->State;
     }
 
     KeReleaseSpinLockFromDpcLevel(&Context->Lock);
@@ -1823,12 +1836,7 @@ StorePoll(
     IN  PINTERFACE          Interface
     )
 {
-    PXENBUS_STORE_CONTEXT   Context = Interface->Context;
-
-    KeAcquireSpinLockAtDpcLevel(&Context->Lock);
-    if (Context->References != 0)
-        StorePollLocked(Context);
-    KeReleaseSpinLockFromDpcLevel(&Context->Lock);
+    __StorePoll(Interface->Context);
 }
 
 #define TIME_US(_us)        ((_us) * 10)
@@ -1898,7 +1906,7 @@ StoreWatchdog(
                 (VOID) XENBUS_EVTCHN(Send,
                                      &Context->EvtchnInterface,
                                      Context->Channel);
-                StorePollLocked(Context);
+                (VOID) StorePollLocked(Context);
             }
 
             KeMemoryBarrier();
@@ -2604,7 +2612,7 @@ StoreRelease(
     XENBUS_SUSPEND(Release, &Context->SuspendInterface);
 
     StoreDisable(Context);
-    StorePollLocked(Context);
+    (VOID) StorePollLocked(Context);
     RtlZeroMemory(&Context->Response, sizeof (XENBUS_STORE_RESPONSE));
 
     XENBUS_EVTCHN(Release, &Context->EvtchnInterface);
-- 
2.17.1


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

 


Rackspace

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