[ofw] [PATCH] WinVerbs: Make QP modification asynchronous

Fab Tillier ftillier at windows.microsoft.com
Wed Feb 11 11:42:36 PST 2009


This patch defers the QP modification to a work item if it can be allocated.  This is intended to serve as an example of how deferring work to a work item does not complicate locking, destruction handling, or device removal.

Note that the patch has only been compile tested.  Note also that the choice of local variable names were selected to minimize the diffs, and so break with the normal syntax of all-lower-case local parameters.

Signed-off-by: Fab Tillier <ftillier at microsoft.com>

Index: wv_driver.c
===================================================================
--- wv_driver.c (revision 1924)
+++ wv_driver.c (working copy)
@@ -47,7 +47,6 @@
 #include "wv_ep.h"

 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WV_RDMA_DEVICE, WvRdmaDeviceGetContext)
-WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WV_PROVIDER, WvProviderGetContext)

 WDFDEVICE                              ControlDevice;
 static LIST_ENTRY              DevList;
Index: wv_provider.h
===================================================================
--- wv_provider.h       (revision 1924)
+++ wv_provider.h       (working copy)
@@ -66,6 +66,8 @@ typedef struct _WV_PROVIDER

 }      WV_PROVIDER;

+WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(WV_PROVIDER, WvProviderGetContext)
+
 void WvProviderGet(WV_PROVIDER *pProvider);
 void WvProviderPut(WV_PROVIDER *pProvider);
 void WvProviderInit(WDFDEVICE Device, WV_PROVIDER *pProvider);
Index: wv_qp.c
===================================================================
--- wv_qp.c     (revision 1924)
+++ wv_qp.c     (working copy)
@@ -28,6 +28,7 @@
  */

 #include "wv_qp.h"
+#include "wv_provider.h"
 #include "wv_ioctl.h"

 typedef struct _WV_MULTICAST
@@ -584,8 +585,11 @@ complete:
        WdfRequestCompleteWithInformation(Request, status, len);
 }

-void WvQpModify(WV_PROVIDER *pProvider, WDFREQUEST Request)
+static void WvDoQpModify( __in DEVICE_OBJECT* pDevObj, __in void* Context, __in PIO_WORKITEM pWorkItem )
 {
+       WDFREQUEST                              Request = (WDFREQUEST)Context;
+       WDFFILEOBJECT                   file;
+       WV_PROVIDER                             *pProvider;
        WV_IO_QP_ATTRIBUTES             *pattr;
        UINT8                                   *out;
        size_t                                  outlen, len = 0;
@@ -594,6 +598,8 @@ void WvQpModify(WV_PROVIDER *pProvider,
        NTSTATUS                                status;
        ib_api_status_t                 ib_status;

+       UNREFERENCED_PARAMETER( pDevObj );
+
        status = WdfRequestRetrieveInputBuffer(Request, sizeof(WV_IO_QP_ATTRIBUTES),
                                                                                   &pattr, NULL);
        if (!NT_SUCCESS(status)) {
@@ -604,6 +610,9 @@ void WvQpModify(WV_PROVIDER *pProvider,
                goto complete;
        }

+       file = WdfRequestGetFileObject(Request);
+       pProvider = WvProviderGetContext(file);
+
        WvVerbsConvertAttr(&attr, pattr);
        qp = WvQpAcquire(pProvider, pattr->Id.Id);
        if (qp == NULL) {
@@ -620,6 +629,27 @@ void WvQpModify(WV_PROVIDER *pProvider,

 complete:
        WdfRequestCompleteWithInformation(Request, status, len);
+       if (pWorkItem) {
+               IoFreeWorkItem(pWorkItem);
+       }
+}
+
+void WvQpModify(WV_PROVIDER *pProvider, WDFREQUEST Request)
+{
+       WDFFILEOBJECT file;
+       WDFDEVICE device;
+       PIO_WORKITEM workitem;
+
+       file = WdfRequestGetFileObject(Request);
+       device = WdfFileObjectGetDevice(file);
+
+       workitem = IoAllocateWorkItem( WdfDeviceWdmGetDeviceObject(device) );
+       if (workitem == NULL) {
+               /* No work item, just execute the modify synchronously. */
+               WvDoQpModify(NULL, Request, NULL);
+       } else {
+               IoQueueWorkItemEx(workitem, WvDoQpModify, DelayedWorkQueue, Request);
+       }
 }

 void WvQpAttach(WV_PROVIDER *pProvider, WDFREQUEST Request)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: wv_qp_modify.patch
Type: application/octet-stream
Size: 2979 bytes
Desc: wv_qp_modify.patch
URL: <http://lists.openfabrics.org/pipermail/ofw/attachments/20090211/d8cfb778/attachment.obj>


More information about the ofw mailing list