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

[win-pv-devel] [PATCH 6/9] Create a thread per VBD to handle backend change watches



Using a single thread for all backend watch events pust unneccesary
strain on xenstore when multiple vbds are in use, as each change
causes XenVbd to check several values in all backend areas.

Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>
---
 src/xenvbd/fdo.c      | 55 +--------------------------------------------------
 src/xenvbd/frontend.c | 54 +++++++++++++++++++++++++++++++++++---------------
 src/xenvbd/frontend.h |  7 -------
 src/xenvbd/pdo.c      | 31 ++++++++++-------------------
 src/xenvbd/pdo.h      |  7 -------
 5 files changed, 49 insertions(+), 105 deletions(-)

diff --git a/src/xenvbd/fdo.c b/src/xenvbd/fdo.c
index dab7ae1..29ec966 100644
--- a/src/xenvbd/fdo.c
+++ b/src/xenvbd/fdo.c
@@ -93,7 +93,6 @@ struct _XENVBD_FDO {
     PXENVBD_THREAD              ScanThread;
     KEVENT                      ScanEvent;
     PXENBUS_STORE_WATCH         ScanWatch;
-    PXENVBD_THREAD              FrontendThread;
 
     // Statistics
     LONG                        CurrentSrbs;
@@ -648,7 +647,6 @@ __FdoEnumerate(
         if (PdoCreate(Fdo,
                       Device,
                       TargetId,
-                      ThreadGetEvent(Fdo->FrontendThread),
                       DeviceType)) {
             *NeedInvalidate = TRUE;
         }
@@ -712,43 +710,6 @@ FdoScan(
     return STATUS_SUCCESS;
 }
 
-__checkReturn
-static DECLSPEC_NOINLINE NTSTATUS
-FdoFrontend(
-    __in PXENVBD_THREAD              Thread,
-    __in PVOID                       Context
-    )
-{
-    PXENVBD_FDO     Fdo = Context;
-
-    for (;;) {
-        ULONG       TargetId;
-        KIRQL       Irql;
-        
-        if (!ThreadWait(Thread))
-            break;
-
-        KeAcquireSpinLock(&Fdo->Lock, &Irql);
-
-        if (Fdo->DevicePower != PowerDeviceD0) {
-            KeReleaseSpinLock(&Fdo->Lock, Irql);
-            continue;
-        }
-
-        for (TargetId = 0; TargetId < XENVBD_MAX_TARGETS; ++TargetId) {
-            PXENVBD_PDO Pdo = __FdoGetPdo(Fdo, TargetId);
-            if (Pdo) {
-                PdoBackendPathChanged(Pdo);
-                PdoDereference(Pdo);
-            }
-        }
-
-        KeReleaseSpinLock(&Fdo->Lock, Irql);
-    }
-
-    return STATUS_SUCCESS;
-}
-
 //=============================================================================
 // Initialize, Start, Stop
 
@@ -1556,13 +1517,9 @@ __FdoInitialize(
     if (!NT_SUCCESS(Status))
         goto fail3;
 
-    Status = ThreadCreate(FdoFrontend, Fdo, &Fdo->FrontendThread);
-    if (!NT_SUCCESS(Status))
-        goto fail4;
-
     Status = ThreadCreate(FdoDevicePower, Fdo, &Fdo->DevicePowerThread);
     if (!NT_SUCCESS(Status))
-        goto fail5;
+        goto fail4;
 
     // query enumerator
     // fix this up to query from device location(?)
@@ -1574,11 +1531,6 @@ __FdoInitialize(
     Trace("<===== (%d)\n", KeGetCurrentIrql());
     return STATUS_SUCCESS;
 
-fail5:
-    Error("fail5\n");
-    ThreadAlert(Fdo->FrontendThread);
-    ThreadJoin(Fdo->FrontendThread);
-    Fdo->FrontendThread = NULL;
 fail4:
     Error("fail4\n");
     ThreadAlert(Fdo->ScanThread);
@@ -1621,11 +1573,6 @@ __FdoTerminate(
     ThreadJoin(Fdo->DevicePowerThread);
     Fdo->DevicePowerThread = NULL;
 
-    // stop frontend thread
-    ThreadAlert(Fdo->FrontendThread);
-    ThreadJoin(Fdo->FrontendThread);
-    Fdo->FrontendThread = NULL;
-
     // stop enum thread
     ThreadAlert(Fdo->ScanThread);
     ThreadJoin(Fdo->ScanThread);
diff --git a/src/xenvbd/frontend.c b/src/xenvbd/frontend.c
index 4a8fbe3..1436001 100644
--- a/src/xenvbd/frontend.c
+++ b/src/xenvbd/frontend.c
@@ -41,6 +41,7 @@
 #include "notifier.h"
 #include "blockring.h"
 #include "granter.h"
+#include "thread.h"
 #include <store_interface.h>
 #include <suspend_interface.h>
 
@@ -76,7 +77,7 @@ struct _XENVBD_FRONTEND {
 
     // Backend State Watch
     BOOLEAN                     Active;
-    PKEVENT                     BackendEvent;
+    PXENVBD_THREAD              BackendThread;
     PXENBUS_STORE_WATCH         BackendWatch;
 };
 
@@ -925,7 +926,7 @@ FrontendPrepare(
                           Frontend->Store,
                           NULL,
                           Frontend->BackendPath,
-                          Frontend->BackendEvent,
+                          ThreadGetEvent(Frontend->BackendThread),
                           &Frontend->BackendWatch);
     if (!NT_SUCCESS(Status))
         goto fail2;
@@ -1502,21 +1503,32 @@ FrontendSetState(
     return Status;
 }
 
-__drv_requiresIRQL(DISPATCH_LEVEL)
-VOID
-FrontendBackendPathChanged(
-    __in  PXENVBD_FRONTEND        Frontend
+__checkReturn
+static DECLSPEC_NOINLINE NTSTATUS
+FrontendBackend(
+    __in PXENVBD_THREAD              Thread,
+    __in PVOID                       Context
     )
 {
-    KIRQL       Irql;
-    KeAcquireSpinLock(&Frontend->StateLock, &Irql);
-    // Only attempt this if Active, Active is set/cleared on D3->D0/D0->D3
-    if (Frontend->Active) {
-        // Note: Nothing may have changed with this target, this could be 
caused by another target changing
-        __ReadDiskInfo(Frontend);
-        __CheckBackendForEject(Frontend);
+    PXENVBD_FRONTEND                Frontend = Context;
+
+    for (;;) {
+        KIRQL       Irql;
+ 
+        if (ThreadWait(Thread))
+            break;
+
+        KeAcquireSpinLock(&Frontend->StateLock, &Irql);
+        // Only attempt this if Active, Active is set/cleared on D3->D0/D0->D3
+        if (Frontend->Active) {
+            __ReadDiskInfo(Frontend);
+            __CheckBackendForEject(Frontend);
+        }
+        KeReleaseSpinLock(&Frontend->StateLock, Irql);
     }
-    KeReleaseSpinLock(&Frontend->StateLock, Irql);
+
+    return STATUS_SUCCESS;
+
 }
 
 __checkReturn
@@ -1525,7 +1537,6 @@ FrontendCreate(
     __in  PXENVBD_PDO             Pdo,
     __in  PCHAR                   DeviceId, 
     __in  ULONG                   TargetId, 
-    __in  PKEVENT                 Event,
     __out PXENVBD_FRONTEND*       _Frontend
     )
 {
@@ -1547,7 +1558,6 @@ FrontendCreate(
     Frontend->State = XENVBD_INITIALIZED;
     Frontend->DiskInfo.SectorSize = 512; // default sector size
     Frontend->BackendId = DOMID_INVALID;
-    Frontend->BackendEvent = Event;
     
     Status = STATUS_INSUFFICIENT_RESOURCES;
     Frontend->FrontendPath = DriverFormat("device/%s/%s", 
FdoEnum(PdoGetFdo(Pdo)), DeviceId);
@@ -1570,6 +1580,10 @@ FrontendCreate(
     if (!NT_SUCCESS(Status))
         goto fail6;
 
+    Status = ThreadCreate(FrontendBackend, Frontend, &Frontend->BackendThread);
+    if (!NT_SUCCESS(Status))
+        goto fail7;
+
     // kernel objects
     KeInitializeSpinLock(&Frontend->StateLock);
     
@@ -1577,6 +1591,10 @@ FrontendCreate(
     *_Frontend = Frontend;
     return STATUS_SUCCESS;
 
+fail7:
+    Error("fail7\n");
+    GranterDestroy(Frontend->Granter);
+    Frontend->Granter = NULL;
 fail6:
     Error("fail6\n");
     BlockRingDestroy(Frontend->BlockRing);
@@ -1614,6 +1632,10 @@ FrontendDestroy(
     PdoFreeInquiryData(Frontend->Inquiry);
     Frontend->Inquiry = NULL;
 
+    ThreadAlert(Frontend->BackendThread);
+    ThreadJoin(Frontend->BackendThread);
+    Frontend->BackendThread = NULL;
+
     GranterDestroy(Frontend->Granter);
     Frontend->Granter = NULL;
 
diff --git a/src/xenvbd/frontend.h b/src/xenvbd/frontend.h
index 7d934f9..7e40bce 100644
--- a/src/xenvbd/frontend.h
+++ b/src/xenvbd/frontend.h
@@ -171,19 +171,12 @@ FrontendSetState(
     __in  XENVBD_STATE            State
     );
 
-__drv_requiresIRQL(DISPATCH_LEVEL)
-extern VOID
-FrontendBackendPathChanged(
-    __in  PXENVBD_FRONTEND        Frontend
-    );
-
 __checkReturn
 extern NTSTATUS
 FrontendCreate(
     __in  PXENVBD_PDO             Pdo,
     __in  PCHAR                   DeviceId, 
     __in  ULONG                   TargetId, 
-    __in  PKEVENT                 Event,
     __out PXENVBD_FRONTEND*       _Frontend
     );
 
diff --git a/src/xenvbd/pdo.c b/src/xenvbd/pdo.c
index c7d8b2b..918b824 100644
--- a/src/xenvbd/pdo.c
+++ b/src/xenvbd/pdo.c
@@ -2458,15 +2458,6 @@ PdoIssueDeviceEject(
     }
 }
 
-__drv_requiresIRQL(DISPATCH_LEVEL)
-VOID
-PdoBackendPathChanged(
-    __in PXENVBD_PDO             Pdo
-    )
-{
-    FrontendBackendPathChanged(Pdo->Frontend);
-}
-
 __checkReturn
 NTSTATUS
 PdoD3ToD0(
@@ -2538,7 +2529,6 @@ PdoCreate(
     __in PXENVBD_FDO             Fdo,
     __in __nullterminated PCHAR  DeviceId,
     __in ULONG                   TargetId,
-    __in PKEVENT                 FrontendEvent,
     __in XENVBD_DEVICE_TYPE      DeviceType
     )
 {
@@ -2569,15 +2559,14 @@ PdoCreate(
     QueueInit(&Pdo->PreparedReqs);
     QueueInit(&Pdo->SubmittedReqs);
     QueueInit(&Pdo->ShutdownSrbs);
-
-    Status = FrontendCreate(Pdo, DeviceId, TargetId, FrontendEvent, 
&Pdo->Frontend);
-    if (!NT_SUCCESS(Status))
-        goto fail2;
-
     __LookasideInit(&Pdo->RequestList, sizeof(XENVBD_REQUEST), 
REQUEST_POOL_TAG);
     __LookasideInit(&Pdo->SegmentList, sizeof(XENVBD_SEGMENT), 
SEGMENT_POOL_TAG);
     __LookasideInit(&Pdo->IndirectList, sizeof(XENVBD_INDIRECT), 
INDIRECT_POOL_TAG);
 
+    Status = FrontendCreate(Pdo, DeviceId, TargetId, &Pdo->Frontend);
+    if (!NT_SUCCESS(Status))
+        goto fail2;
+
     Status = PdoD3ToD0(Pdo);
     if (!NT_SUCCESS(Status))
         goto fail3;
@@ -2595,14 +2584,14 @@ fail4:
 
 fail3:
     Error("Fail3\n");
-    __LookasideTerm(&Pdo->IndirectList);
-    __LookasideTerm(&Pdo->SegmentList);
-    __LookasideTerm(&Pdo->RequestList);
     FrontendDestroy(Pdo->Frontend);
     Pdo->Frontend = NULL;
 
 fail2:
     Error("Fail2\n");
+    __LookasideTerm(&Pdo->IndirectList);
+    __LookasideTerm(&Pdo->SegmentList);
+    __LookasideTerm(&Pdo->RequestList);
     __PdoFree(Pdo);
 
 fail1:
@@ -2665,13 +2654,13 @@ PdoDestroy(
     ASSERT3S(Pdo->ReferenceCount, ==, 0);
     ASSERT3U(PdoGetDevicePnpState(Pdo), ==, Deleted);
 
+    FrontendDestroy(Pdo->Frontend);
+    Pdo->Frontend = NULL;
+
     __LookasideTerm(&Pdo->IndirectList);
     __LookasideTerm(&Pdo->SegmentList);
     __LookasideTerm(&Pdo->RequestList);
 
-    FrontendDestroy(Pdo->Frontend);
-    Pdo->Frontend = NULL;
-
     ASSERT3U(Pdo->Signature, ==, PDO_SIGNATURE);
     RtlZeroMemory(Pdo, sizeof(XENVBD_PDO));
     __PdoFree(Pdo);
diff --git a/src/xenvbd/pdo.h b/src/xenvbd/pdo.h
index 3bff743..946c34f 100644
--- a/src/xenvbd/pdo.h
+++ b/src/xenvbd/pdo.h
@@ -55,7 +55,6 @@ PdoCreate(
     __in PXENVBD_FDO             Fdo,
     __in __nullterminated PCHAR  DeviceId,
     __in ULONG                   TargetId,
-    __in PKEVENT                 FrontendEvent,
     __in XENVBD_DEVICE_TYPE      DeviceType
     );
 
@@ -75,12 +74,6 @@ PdoD0ToD3(
     __in PXENVBD_PDO             Pdo
     );
 
-__drv_requiresIRQL(DISPATCH_LEVEL)
-extern VOID
-PdoBackendPathChanged(
-    __in PXENVBD_PDO             Pdo
-    );
-
 // PnP States
 extern VOID
 PdoSetMissing(
-- 
1.9.4.msysgit.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®.