Hello All,

Basically my requirement is to perform some action after every fixed
time interval. I therefore create a "synchronization" type timer and
using KeSetTimerEx () i schedule the timer. But it looks like the
timer is not called at the time interval i need it to invoke the timer
callback routine. I check this using KeQuerySystemTime (). Following
are the steps:

1) KeInitializeTimerEx (&(pDevExt->myTimer), SynchronizationTimer);
KeInitializeDpc (&(pDevExt->myTimerDpc), myTimerRoutine, pKsDev);

2) timerDelay.QuadPart = -180000; // 18 ms
KeSetTimerEx (&(pDevExt->myTimer), timerDelay, 18,
&(pDevExt->myTimerDpc));

But what i observed to my dismay is that my myTimerRoutine () was
called at approximate intervals like:
15.625 ms
15.625 ms
15.625 ms
15.625 ms
31.250 ms
and so on as the pattern keeps repeating....

Any reason why this is happenning? Is it possible to make the timer
routine be called at the exact timer interval?

Also, i used KeSetTimerEx (&(pDevExt->myTimer), timerDelay,
&(pDevExt->myTimerDpc)); but the timer routine got invoked only once!
Is there something iam missing here? Can someone throw some light on
this?

Regards,
Hari.

Using KeSetTimerEx by John

John
Wed Dec 10 08:00:07 CST 2003

The timeBeginPeriod() function could help you out. It is
able to change the interrupt rate of the system timer so
that you can obtain better resolution. You might call it
as timeBeginPeriod(9), for example. There's a discussion
in this newsgroup that you can find by searching
for "timeBeginPeriod".
>-----Original Message-----
>Hello All,
>
>Basically my requirement is to perform some action after
every fixed
>time interval. I therefore create a "synchronization"
type timer and
>using KeSetTimerEx () i schedule the timer. But it looks
like the
>timer is not called at the time interval i need it to
invoke the timer
>callback routine. I check this using KeQuerySystemTime
(). Following
>are the steps:
>
>1) KeInitializeTimerEx (&(pDevExt->myTimer),
SynchronizationTimer);
>KeInitializeDpc (&(pDevExt->myTimerDpc), myTimerRoutine,
pKsDev);
>
>2) timerDelay.QuadPart = -180000; // 18 ms
>KeSetTimerEx (&(pDevExt->myTimer), timerDelay, 18,
>&(pDevExt->myTimerDpc));
>
>But what i observed to my dismay is that my
myTimerRoutine () was
>called at approximate intervals like:
>15.625 ms
>15.625 ms
>15.625 ms
>15.625 ms
>31.250 ms
>and so on as the pattern keeps repeating....
>
>Any reason why this is happenning? Is it possible to
make the timer
>routine be called at the exact timer interval?
>
>Also, i used KeSetTimerEx (&(pDevExt->myTimer),
timerDelay,
>&(pDevExt->myTimerDpc)); but the timer routine got
invoked only once!
>Is there something iam missing here? Can someone throw
some light on
>this?
>
>Regards,
>Hari.
>.
>

Re: Using KeSetTimerEx by harik2k2

harik2k2
Wed Dec 10 23:27:18 CST 2003

> The timeBeginPeriod() function could help you out. It is
> able to change the interrupt rate of the system timer so
> that you can obtain better resolution. You might call it
> as timeBeginPeriod(9), for example. There's a discussion
> in this newsgroup that you can find by searching
> for "timeBeginPeriod".
Thanks for your reply! I will surely check that thread!

But in the meantime i wanted to know whether my approach to creating
and scheduling a timer was correct or not? Any observations on this?

Hari.

Re: Using KeSetTimerEx by John

John
Thu Dec 11 11:16:11 CST 2003


>-----Original Message-----
>> The timeBeginPeriod() function could help you out. It
is
>> able to change the interrupt rate of the system timer
so
>> that you can obtain better resolution. You might call
it
>> as timeBeginPeriod(9), for example. There's a
discussion
>> in this newsgroup that you can find by searching
>> for "timeBeginPeriod".
>Thanks for your reply! I will surely check that thread!
>
>But in the meantime i wanted to know whether my approach
to creating
>and scheduling a timer was correct or not? Any
observations on this?

KeInitializeTimer(&dev_ext_ptr->timer_obj); /* pointer
to timer object */
KeInitializeDpc(
&dev_ext_ptr->dpc_obj, /* pointer to dpc
object */
TimerDpc, /* pointer to timer
dpc routine */
dev_ext_ptr); /* context (device
extension) */
KeInitializeSpinLock(&dev_ext_ptr->lock); /* pointer
to spin lock */


to change rate
(void) KeSetTimerEx(
&dev_ext_ptr->timer_obj, /* pointer to
timer object */
LARGE_INTEGER_ZERO, /* due time, for
one-shot only */
timer_period, /* period in
milliseconds */
&dev_ext_ptr->dpc_obj); /* pointer to
dpc object */


to handle dpc
/*lint -save -esym
(715,Dpc,SystemArgument1,SystemArgument2) not referenced */
#pragma warning(disable:4100) /* unreferenced formal
parameter */
void TimerDpc(
IN PKDPC Dpc,
IN PVOID DeferredContext,
IN PVOID SystemArgument1,
IN PVOID SystemArgument2)
{
DEVICE_EXTENSION *dev_ext_ptr; /* device extension
pointer */


/* Get a clear device extension pointer. */
dev_ext_ptr = (DEVICE_EXTENSION *) DeferredContext;


/* Acquire the spin lock for the board so that we can
have exclusive
access to the xxxxxxxxx data. */
KeAcquireSpinLockAtDpcLevel(&dev_ext_ptr->lock);

(stuff)

/* Release the spin lock. */
KeReleaseSpinLockFromDpcLevel(&dev_ext_ptr->lock);


return;
}




declarations
/* timer_obj -- timer object for automatic reads and
writes */
KTIMER timer_obj;

/* dpc_obj -- deferred procedure call object used by
the timer */
KDPC dpc_obj;

/* lock -- spin lock to synchronize multi-cpu access to
ranges */
KSPIN_LOCK lock;




to shut down

KeAcquireSpinLock(&dev_ext_ptr->lock, &old_irql);
/* Cancel the timer and timer linkages, if necessary.
Because we
have the spin lock we're running at dispatch IRQL
and a pending
timer DPC will not preempt us. Therefore we also
dequeue the DPC. */
(void) KeCancelTimer(&dev_ext_ptr->timer_obj);
(void) KeRemoveQueueDpc(&dev_ext_ptr->dpc_obj);

/* Release the spin lock and return normally. */
KeReleaseSpinLock(&dev_ext_ptr->lock, old_irql);