Query the time and print out both:
- Right before you goto sleep
- Right after you wakeup
It is likely that one of the following is happening:
- Your thread is either taking longer than you expect to execute
- Your driver is corrupting system memory and the locations associated with maintaining time
Duane.
-----Original Message-----
From: Dongli Wu [mailto:xxxxx@highstream.net]
Sent: Wednesday, December 25, 2002 9:40 PM
To: NT Developers Interest List
Subject: [ntdev] RE: a problem on KeQuerySystemTime()
Hi, Duane:
Thank you very much for your response.
The deviceExtension->PreviousTime was initialized to 0 in
DriverEntry. In the kernel thread there is only one path that don’t
update the
deviceExtension->PreviousTime: when timeDifference.QuadPart is large
than
TIME_LIMITATION and thread will stop.
To analysis the problem, I put KdPrint() after
KeQuerySystemTime(¤tSystemTime)
and print out every current time tick that returned from
KeQuerySystemTime().
The print out results make me confused: Originally, when
KeWaitForSingleObject is
trigged, the current time tick is correct. But after a while (less than
30 minutes)
the current time tick returned from KeQuerySystemTime suddenly change to
a
new unreasonable value so that timeDifference.QuadPart is larger than
TIME_LIMITATION and kernel thread stoped.
Based on the above scenarios, could you help me figure out what problem
in my driver?
Thanks
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of McCrory, Duane
Sent: Monday, December 23, 2002 3:32 PM
To: NT Developers Interest List
Subject: [ntdev] RE: a problem on KeQuerySystemTime()
I think your problem is not in the timer, but in your service routine.
You might want to check how long it took you do service your queue.
Other comments:
- Did you initialize deviceExtension->PreviousTime in DriverEntry?
- It looks like you have paths in DrvrSystemTimerThread where you do
not update deviceExtension->PreviousTime. - I suggest always updating deviceExtension->PreviousTime immediately
before doing the KeWaitForSingleObjects in your while loop.
Duane.
-----Original Message-----
From: Dongli Wu [mailto:xxxxx@highstream.net]
Sent: Friday, December 20, 2002 7:38 PM
To: NT Developers Interest List
Subject: [ntdev] 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(¤tSystemTime);
timeDifference.QuadPart = currentSystemTime.QuadPart -
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);
?
// in this section, kernel thread walk through the queue and remove
// the 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
You are currently subscribed to ntdev as: xxxxx@infiniconsys.com To
unsubscribe send a blank email to %%email.unsub%%
You are currently subscribed to ntdev as: xxxxx@highstream.net To
unsubscribe send a blank email to %%email.unsub%%
You are currently subscribed to ntdev as: xxxxx@infiniconsys.com
To unsubscribe send a blank email to %%email.unsub%%