a problem on KeQuerySystemTime()

---------- Original Message ----------------------------------
Hi, All:
I have a problem on KeQuerySystemTime(). Does anybody can give some help?

Here is a problem:
My driver has a kernel timer thread, which is trigged by a timer
object every 10 seconds. When the thread started, it walk through
a customized queue and remove some elements(the queue does not
have any relationship with any IRP). This queue is protected by
a mutex. At the same time, the Thread call KeQuerySystemTime()
to check the elapsed time. The problem is sooner or later, the
elapsed time check will fail because the calculated elapsed time
is lager than 10 seconds (actually it is about 30 seconds).

The code segment is :
/****** Initialize ******/
NTSTATUS DriverEntry(IN PDRIVER_OBJECT driverObject,
IN PUNICODE_STRING registryPath)
{
???
KeInitializeMutex(&deviceExtension->QueueLock, 1);
InitializeListHead(&deviceExtension->ListHead);
KeInitializeTimerEx(&deviceExtension->SystemTimer,
SynchronizationTimer);

status = PsCreateSystemThread(&hSystemTimerThread,
(ACCESS_MASK)0,
NULL,
(HANDLE) 0,
NULL,
DrvrSystemTimerThread,
DeviceObject);

if (!NT_SUCCESS(status))
return status;

// get a pointer to the thread object.
ObReferenceObjectByHandle(hSystemTimerThread,
THREAD_ALL_ACCESS,
NULL,
KernelMode,
&deviceExtension->SystemTimerThread,
NULL);

// release the thread handle.
ZwClose(hSystemTimerThread);

// start system timer, due time is 0, period time 10 seconds
KeSetTimerEx(&deviceExtension->SystemTimer,
0,
10 * 1000,
NULL);
???
return STATUS_SUCCESS;
}

/**** system thread ******/
VOID DrvrSystemTimerThread(PVOID Context)
{

while (TRUE) {
KeWaitForSingleObjects(deviceExtension->SystemTimer,
Executive,
KernelMode,
FALSE,
NULL);
// calculate the elapsed time, soon or later, this will fail
KeQuerySystemTime(&currentSystemTime);
timeDifference.QuadPart = currentSystemTime.QuadPart ?C
deviceExtension->PreviousTimeStamp.QuadPart;
if (timeDifference.QuadPart > TIME_LIMITATION /* 10 seconds */)
break;

deviceExtension->PreviousTime.QuadPart = currentSystemTime.QuadPart;

// acquire queue lock first.
KeWaitForSingleObject(&deviceExtension->QueueLock,
Executive,
KernelMode,
FALSE,
NULL);
???
// remove some element from queue
KeReleaseMutex(&deviceExtension->QueueLock, FALSE);
}
}

The logical is very simple, but after a while, the time check will fail and the system thread will stop. The calculated elapsed time is about 30 seconds. That doesn??t make any sense. To narrow down the problem, I cut off all other part, just leave the system timer thread in there. Even though I just add two elements in the queue and let thread remove it. Eventually, the time check can still fail ( the calculated time is bout 30 seconds).

Does anybody have similar experience? Any information will be appreciated.

Thanks