From 301f9dd095b486d9c0d5fe0e73b539a9e89ced38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger?= Date: Sun, 13 May 2018 22:15:07 +0200 Subject: [PATCH] Implemented Bus_PlugInRequestCleanUpEvtTimerFunc --- sys/Context.h | 2 +- sys/Driver.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- sys/busenum.c | 2 +- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/sys/Context.h b/sys/Context.h index efd88d5..94da20c 100644 --- a/sys/Context.h +++ b/sys/Context.h @@ -181,7 +181,7 @@ typedef struct _FDO_PLUGIN_REQUEST_DATA // // High resolution timestamp taken when this request got moved to pending state // - LONGLONG Timestamp; + LARGE_INTEGER Timestamp; // // Performance counter system frequency taken upon fetching timestamp diff --git a/sys/Driver.c b/sys/Driver.c index 562621f..a992bc9 100644 --- a/sys/Driver.c +++ b/sys/Driver.c @@ -587,8 +587,59 @@ Bus_PlugInRequestCleanUpEvtTimerFunc( WDFTIMER Timer ) { - UNREFERENCED_PARAMETER(Timer); + ULONG i; + PFDO_DEVICE_DATA pFdoData; + WDFREQUEST curRequest; + ULONG items; + WDFDEVICE device; + PFDO_PLUGIN_REQUEST_DATA pPluginData; + LONGLONG freq; + LARGE_INTEGER pcNow; + LONGLONG ellapsed; + TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DRIVER, "%!FUNC! Entry"); + + device = WdfTimerGetParentObject(Timer); + pFdoData = FdoGetData(device); + + WdfSpinLockAcquire(pFdoData->PendingPluginRequestsLock); + + items = WdfCollectionGetCount(pFdoData->PendingPluginRequests); + + TraceEvents(TRACE_LEVEL_INFORMATION, + TRACE_DRIVER, + "Items count: %d", + items); + + for (i = 0; i < items; i++) + { + curRequest = WdfCollectionGetItem(pFdoData->PendingPluginRequests, i); + pPluginData = PluginRequestGetData(curRequest); + + freq = pPluginData->Frequency.QuadPart / 1000; + pcNow = KeQueryPerformanceCounter(NULL); + ellapsed = (pcNow.QuadPart - pPluginData->Timestamp.QuadPart) / freq; + + TraceEvents(TRACE_LEVEL_VERBOSE, + TRACE_DRIVER, + "PDO (serial = %d) age: %llu", + pPluginData->Serial, ellapsed); + + //if (Serial == curSerial) + //{ + // WdfRequestComplete(curRequest, Status); + // + // WdfCollectionRemove(pFdoData->PendingPluginRequests, curRequest); + // + // TraceEvents(TRACE_LEVEL_INFORMATION, + // TRACE_DRIVER, + // "Removed item with serial: %d", + // curSerial); + // + // break; + //} + } + WdfSpinLockRelease(pFdoData->PendingPluginRequestsLock); } diff --git a/sys/busenum.c b/sys/busenum.c index 2f69ace..183332d 100644 --- a/sys/busenum.c +++ b/sys/busenum.c @@ -227,7 +227,7 @@ NTSTATUS Bus_PlugInDevice( // // Timestamp the request to track its age // - pReqData->Timestamp = KeQueryPerformanceCounter(&pReqData->Frequency).QuadPart; + pReqData->Timestamp = KeQueryPerformanceCounter(&pReqData->Frequency); // // Keep track of pending request in collection