How to delay execution

Hello

I need to delay the code execution
The delay varies from 130 to 1500 usecs. What function should be used?
KeDelayExecutionThread works Ok with delay > 20 msecs, since inaccuracy can
be 5 msecs (or more)
KeStallExecutionProcessor is more accurate, but DDK documentation says:
“… Drivers that call this routine should minimize the number of
microseconds they specify (no more than 50)…”,
So I have not use KeStallExecutionProcessor…

How to solve this?
How to implement the delay in case if range is from 50 usecs to 20 msecs???

Thanx,
Nikolay

Until verifier or whql enforce the 50usec rule, which they may very well do
in the relative near future, I would do the obvious and call stall with the
appropriate time. If you want to be within the letter of the law, call stall
N times to satisfy your delay requirements.

=====================
Mark Roddy

-----Original Message-----
From: Nikolay [mailto:xxxxx@pisem.net]
Sent: Monday, February 09, 2004 9:11 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to delay execution

Hello

I need to delay the code execution
The delay varies from 130 to 1500 usecs. What function should be used?
KeDelayExecutionThread works Ok with delay > 20 msecs, since
inaccuracy can be 5 msecs (or more) KeStallExecutionProcessor
is more accurate, but DDK documentation says:
“… Drivers that call this routine should minimize the
number of microseconds they specify (no more than 50)…”, So
I have not use KeStallExecutionProcessor…

How to solve this?
How to implement the delay in case if range is from 50 usecs
to 20 msecs???

Thanx,
Nikolay


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as:
xxxxx@stratus.com To unsubscribe send a blank email to
xxxxx@lists.osr.com

The problem with KeStallExecutionProcessor is that it’s actually a “empty
loop”, rather than a “make something else happen”. This is how it can be
fairly precise, but it’s not very “nice” to the rest of the system.

The KeDelayExecutionUnit will use the PC 8254 timer to get an interrupt to
wake the processo, and puts the current process to sleep. This is good for
other processes, but has the drawback that you don’t know for sure that the
current process will be woken “in time”, as there’s nothing to say that your
process will be scheduled at any particyular time.

One solution would be to use the QueryPerformanceCounters interface, which
uses the 8254 counters, and it will give you a precision of about 0.9 usec,
IIRC. Something like this:

void delayUsecs(int uSecs)
{
LARGE_INTEGER Count, Count2, CountWanted;
LARGE_INTEGER Passed;
LARGE_INTEGER uSecsLeft;
LARGE_INTEGER Freq;

Count = KeQueryPerformanceCounter( &Freq );

CountWanted.quad = (uSecs * Freq.quad) / 1000000;

if (uSecs > 20)
{
KeDelayExecutionThread(uSecs - 10);
}

Count2 = KeQuesryPerformanceCounter( NULL );

Passed.quad = Count2.quad - Count.quad;

if (Passed.quad > CountWanted.quad)
return; // We overshot. May want to do
something to debug the problem…
uSecsLeft = uSecs - (Passed.Quad * 1000000) / Freq.Quad);

if (uSecsLeft)
KeStallExecutionProcessor(uSecsLeft);
}

This way you get the best of both worlds.

I had problems with KeDelayExecutionThread however. Apparently, if you call
it at the wrong IRQL, it just returns immediately (and I used it to figure
out the frequency of something else, which meant that both my “before” and
“after” times where the same, so I got a divide by zero :frowning: ). I wrote my
own “sleep” routine instead. This uses the KeSetTimer() and
KeWaitForSingleObject(). This isn’t a very precise “sleep”, which is fine if
I’m just trying to figure out how many cycles pass on one of my internal
counters in a specified time, but if you want to delay a certain (exact)
amount, it’s not particularly useful.

Note also that as of current, there’s nothing that prevents an interrupt
from taking several microseconds (or milliseconds for that matter), so any
precise timing that isn’t run at IRQL which dissables Interrupts, will mean
that you could have “overshot” your timing. There’s nothing to prevent this
from happening, except making sure that any drivers in the system is
“well-behaved” (including in "special cases, like error handling and other
obscure scenarios. Num-lock key on the keyboard used to be bad when the BIOS
handled it, but I think Windows doesn’t hold interrupts off for the 4.2
milliseconds it takes for everything to happen in a “set numlock LED”).


Mats

-----Original Message-----
From: Nikolay [mailto:xxxxx@pisem.net]
Sent: Monday, February 09, 2004 2:11 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] How to delay execution

Hello

I need to delay the code execution
The delay varies from 130 to 1500 usecs. What function should be used?
KeDelayExecutionThread works Ok with delay > 20 msecs, since
inaccuracy can
be 5 msecs (or more)
KeStallExecutionProcessor is more accurate, but DDK
documentation says:
“… Drivers that call this routine should minimize the number of
microseconds they specify (no more than 50)…”,
So I have not use KeStallExecutionProcessor…

How to solve this?
How to implement the delay in case if range is from 50 usecs
to 20 msecs???

Thanx,
Nikolay


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@3dlabs.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Obviously should read
KeDelayExecutionThread(uSecs - 20);
on the relevant line below.


Mats

-----Original Message-----
From: xxxxx@3dlabs.com [mailto:xxxxx@3dlabs.com]
Sent: Monday, February 09, 2004 2:50 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

The problem with KeStallExecutionProcessor is that it’s
actually a “empty
loop”, rather than a “make something else happen”. This is
how it can be
fairly precise, but it’s not very “nice” to the rest of the system.

The KeDelayExecutionUnit will use the PC 8254 timer to get an
interrupt to
wake the processo, and puts the current process to sleep.
This is good for
other processes, but has the drawback that you don’t know for
sure that the
current process will be woken “in time”, as there’s nothing
to say that your
process will be scheduled at any particyular time.

One solution would be to use the QueryPerformanceCounters
interface, which
uses the 8254 counters, and it will give you a precision of
about 0.9 usec,
IIRC. Something like this:

void delayUsecs(int uSecs)
{
LARGE_INTEGER Count, Count2, CountWanted;
LARGE_INTEGER Passed;
LARGE_INTEGER uSecsLeft;
LARGE_INTEGER Freq;

Count = KeQueryPerformanceCounter( &Freq );

CountWanted.quad = (uSecs * Freq.quad) / 1000000;

if (uSecs > 20)
{
KeDelayExecutionThread(uSecs - 10);
}

Count2 = KeQuesryPerformanceCounter( NULL );

Passed.quad = Count2.quad - Count.quad;

if (Passed.quad > CountWanted.quad)
return; // We overshot. May want to do
something to debug the problem…
uSecsLeft = uSecs - (Passed.Quad * 1000000) / Freq.Quad);

if (uSecsLeft)
KeStallExecutionProcessor(uSecsLeft);
}

This way you get the best of both worlds.

I had problems with KeDelayExecutionThread however.
Apparently, if you call
it at the wrong IRQL, it just returns immediately (and I used
it to figure
out the frequency of something else, which meant that both my
“before” and
“after” times where the same, so I got a divide by zero :frowning:
). I wrote my
own “sleep” routine instead. This uses the KeSetTimer() and
KeWaitForSingleObject(). This isn’t a very precise “sleep”,
which is fine if
I’m just trying to figure out how many cycles pass on one of
my internal
counters in a specified time, but if you want to delay a
certain (exact)
amount, it’s not particularly useful.

Note also that as of current, there’s nothing that prevents
an interrupt
from taking several microseconds (or milliseconds for that
matter), so any
precise timing that isn’t run at IRQL which dissables
Interrupts, will mean
that you could have “overshot” your timing. There’s nothing
to prevent this
from happening, except making sure that any drivers in the system is
“well-behaved” (including in "special cases, like error
handling and other
obscure scenarios. Num-lock key on the keyboard used to be
bad when the BIOS
handled it, but I think Windows doesn’t hold interrupts off
for the 4.2
milliseconds it takes for everything to happen in a “set
numlock LED”).


Mats

> -----Original Message-----
> From: Nikolay [mailto:xxxxx@pisem.net]
> Sent: Monday, February 09, 2004 2:11 PM
> To: Windows System Software Devs Interest List
> Subject: [ntdev] How to delay execution
>
>
> Hello
>
> I need to delay the code execution
> The delay varies from 130 to 1500 usecs. What function
should be used?
> KeDelayExecutionThread works Ok with delay > 20 msecs, since
> inaccuracy can
> be 5 msecs (or more)
> KeStallExecutionProcessor is more accurate, but DDK
> documentation says:
> “… Drivers that call this routine should minimize the number of
> microseconds they specify (no more than 50)…”,
> So I have not use KeStallExecutionProcessor…
>
> How to solve this?
> How to implement the delay in case if range is from 50 usecs
> to 20 msecs???
>
> Thanx,
> Nikolay
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@3dlabs.com
> To unsubscribe send a blank email to
xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@3dlabs.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

> One solution would be to use the QueryPerformanceCounters interface, which

uses the 8254 counters, and it will give you a precision of about 0.9
usec,
IIRC. Something like this:

This depends on the HAL and boot options. Often QPC will use the processor
timestamp counter if one is available and the clocks for all processors are
synchronous.

If I had to deal with this case, (which sounds like broken hardware), I’d
start by changing the time interval to 1ms from the default 16.something,
then determine if the delay is going to be > 2ms or so. If so, I’d use a
delay of some sort. If it was less, I’d stall. I’m not sure that multiple
short stalls will really help over one long stall. The idea is to release
the processor for other time-critical things. If the driver never releases
control between a series of short stalls, I don’t see that doing short
stalls will help any.

Yes, reducing the quantum hurts performance a little. However, it will
probably have far less detrimental effect on the system than stalling for
20ms at a time. And it gets it to the point where you can delay for
anything much over 1ms.

Loren

I wonder if the Kernel guys are ever going to consider allowing ticks down
to 100us or so, rather than 1ms minimum. That 1ms minimum was set in the
days of 33MHz processors. Most systems are a bit faster than that now, and
can probably support timer interrupts at a 10K rate.

The trouble is that KeDelayExecutionThread(uSecs - 20) will cause lost of
precision ;(
You’re right, there is no that prevents an interrupt from taking
milliseconds and behavior of KeDelayExecutionThread is strongly depends on
behavior of the rest kernel population.
It seems the only way is to use KeStallExecutionProcessor.

Thanks,
Nikolay

PS Btw, on XP SP1 atapi.sys calls KeStallExecutionProcessor(400) (…in
critical section :slight_smile:

wrote in message news:xxxxx@ntdev…
> Obviously should read
> KeDelayExecutionThread(uSecs - 20);
> on the relevant line below.
>
> –
> Mats
>
> > -----Original Message-----
> > From: xxxxx@3dlabs.com [mailto:xxxxx@3dlabs.com]
> > Sent: Monday, February 09, 2004 2:50 PM
> > To: Windows System Software Devs Interest List
> > Subject: RE: [ntdev] How to delay execution
> >
> >
> > The problem with KeStallExecutionProcessor is that it’s
> > actually a “empty
> > loop”, rather than a “make something else happen”. This is
> > how it can be
> > fairly precise, but it’s not very “nice” to the rest of the system.
> >
> > The KeDelayExecutionUnit will use the PC 8254 timer to get an
> > interrupt to
> > wake the processo, and puts the current process to sleep.
> > This is good for
> > other processes, but has the drawback that you don’t know for
> > sure that the
> > current process will be woken “in time”, as there’s nothing
> > to say that your
> > process will be scheduled at any particyular time.
> >
> > One solution would be to use the QueryPerformanceCounters
> > interface, which
> > uses the 8254 counters, and it will give you a precision of
> > about 0.9 usec,
> > IIRC. Something like this:
> >
> > void delayUsecs(int uSecs)
> > {
> > LARGE_INTEGER Count, Count2, CountWanted;
> > LARGE_INTEGER Passed;
> > LARGE_INTEGER uSecsLeft;
> > LARGE_INTEGER Freq;
> >
> > Count = KeQueryPerformanceCounter( &Freq );
> >
> > CountWanted.quad = (uSecs * Freq.quad) / 1000000;
> >
> > if (uSecs > 20)
> > {
> > KeDelayExecutionThread(uSecs - 10);
> > }
> >
> > Count2 = KeQuesryPerformanceCounter( NULL );
> >
> > Passed.quad = Count2.quad - Count.quad;
> >
> > if (Passed.quad > CountWanted.quad)
> > return; // We overshot. May want to do
> > something to debug the problem…
> > uSecsLeft = uSecs - (Passed.Quad * 1000000) / Freq.Quad);
> >
> > if (uSecsLeft)
> > KeStallExecutionProcessor(uSecsLeft);
> > }
> >
> > This way you get the best of both worlds.
> >
> > I had problems with KeDelayExecutionThread however.
> > Apparently, if you call
> > it at the wrong IRQL, it just returns immediately (and I used
> > it to figure
> > out the frequency of something else, which meant that both my
> > “before” and
> > “after” times where the same, so I got a divide by zero :frowning:
> > ). I wrote my
> > own “sleep” routine instead. This uses the KeSetTimer() and
> > KeWaitForSingleObject(). This isn’t a very precise “sleep”,
> > which is fine if
> > I’m just trying to figure out how many cycles pass on one of
> > my internal
> > counters in a specified time, but if you want to delay a
> > certain (exact)
> > amount, it’s not particularly useful.
> >
> > Note also that as of current, there’s nothing that prevents
> > an interrupt
> > from taking several microseconds (or milliseconds for that
> > matter), so any
> > precise timing that isn’t run at IRQL which dissables
> > Interrupts, will mean
> > that you could have “overshot” your timing. There’s nothing
> > to prevent this
> > from happening, except making sure that any drivers in the system is
> > “well-behaved” (including in "special cases, like error
> > handling and other
> > obscure scenarios. Num-lock key on the keyboard used to be
> > bad when the BIOS
> > handled it, but I think Windows doesn’t hold interrupts off
> > for the 4.2
> > milliseconds it takes for everything to happen in a “set
> > numlock LED”).
> >
> > –
> > Mats
> >
> > > -----Original Message-----
> > > From: Nikolay [mailto:xxxxx@pisem.net]
> > > Sent: Monday, February 09, 2004 2:11 PM
> > > To: Windows System Software Devs Interest List
> > > Subject: [ntdev] How to delay execution
> > >
> > >
> > > Hello
> > >
> > > I need to delay the code execution
> > > The delay varies from 130 to 1500 usecs. What function
> > should be used?
> > > KeDelayExecutionThread works Ok with delay > 20 msecs, since
> > > inaccuracy can
> > > be 5 msecs (or more)
> > > KeStallExecutionProcessor is more accurate, but DDK
> > > documentation says:
> > > “… Drivers that call this routine should minimize the number of
> > > microseconds they specify (no more than 50)…”,
> > > So I have not use KeStallExecutionProcessor…
> > >
> > > How to solve this?
> > > How to implement the delay in case if range is from 50 usecs
> > > to 20 msecs???
> > >
> > > Thanx,
> > > Nikolay
> > >
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@3dlabs.com
> > > To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> > >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@3dlabs.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

Hi all

I have seen here many times discussion for accurate timing.
Since I had this same problem, I think that I must share my experience.
I have a driver that must measures accurately the time elapsed between
interrupts that the hardware generates.
QueryPerformanceCounters is not what I was expected perhaps because windows
modify the counter depending on the system hardware.

I am doing something else more simple .
I am using the speaker counter. It is accurate and easy to use.
A good practise is to reprogram the counter every now and then since someone
else may try to change it. From my experience noone ever tried to modify it.
My driver runs on more that 2000 systems including WIN98 version.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
Sent: Monday, February 09, 2004 5:17 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to delay execution

One solution would be to use the QueryPerformanceCounters interface,
which uses the 8254 counters, and it will give you a precision of
about 0.9
usec,
IIRC. Something like this:

This depends on the HAL and boot options. Often QPC will use the processor
timestamp counter if one is available and the clocks for all processors are
synchronous.

If I had to deal with this case, (which sounds like broken hardware), I’d
start by changing the time interval to 1ms from the default 16.something,
then determine if the delay is going to be > 2ms or so. If so, I’d use a
delay of some sort. If it was less, I’d stall. I’m not sure that multiple
short stalls will really help over one long stall. The idea is to release
the processor for other time-critical things. If the driver never releases
control between a series of short stalls, I don’t see that doing short
stalls will help any.

Yes, reducing the quantum hurts performance a little. However, it will
probably have far less detrimental effect on the system than stalling for
20ms at a time. And it gets it to the point where you can delay for
anything much over 1ms.

Loren

I wonder if the Kernel guys are ever going to consider allowing ticks down
to 100us or so, rather than 1ms minimum. That 1ms minimum was set in the
days of 33MHz processors. Most systems are a bit faster than that now, and
can probably support timer interrupts at a 10K rate.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@softhome.net To unsubscribe
send a blank email to xxxxx@lists.osr.com

The whole point of checking KeQueryPerformanceCounter is so that you get a
precise amount later on when you get to the KeStallExecution, and thus you
get a precise amount of wait there, whilst still keeping the overall
processor usage low.

Of course, it may be that it’s better to use 40 usec or some such for the
Delay part, and do the last 40 usecs in the Stall function, but the
principle is: Wait for a while in “inprecise” way, then calculate how much
left to be done, and do a Stall for the final part.

But there’s no good way of dealing with short & precise timeouts/waits in
the driver. This is basicly because Windows isn’t supposed to be a Real time
OS.

Of course, you could say that the hardware is broken if you need it… :wink:


Mats

-----Original Message-----
From: Nikolay [mailto:xxxxx@pisem.net]
Sent: Monday, February 09, 2004 4:36 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

The trouble is that KeDelayExecutionThread(uSecs - 20) will
cause lost of
precision ;(
You’re right, there is no that prevents an interrupt from taking
milliseconds and behavior of KeDelayExecutionThread is
strongly depends on
behavior of the rest kernel population.
It seems the only way is to use KeStallExecutionProcessor.

Thanks,
Nikolay

PS Btw, on XP SP1 atapi.sys calls
KeStallExecutionProcessor(400) (…in
critical section :slight_smile:

wrote in message news:xxxxx@ntdev…
> > Obviously should read
> > KeDelayExecutionThread(uSecs - 20);
> > on the relevant line below.
> >
> > –
> > Mats
> >
> > > -----Original Message-----
> > > From: xxxxx@3dlabs.com [mailto:xxxxx@3dlabs.com]
> > > Sent: Monday, February 09, 2004 2:50 PM
> > > To: Windows System Software Devs Interest List
> > > Subject: RE: [ntdev] How to delay execution
> > >
> > >
> > > The problem with KeStallExecutionProcessor is that it’s
> > > actually a “empty
> > > loop”, rather than a “make something else happen”. This is
> > > how it can be
> > > fairly precise, but it’s not very “nice” to the rest of
> the system.
> > >
> > > The KeDelayExecutionUnit will use the PC 8254 timer to get an
> > > interrupt to
> > > wake the processo, and puts the current process to sleep.
> > > This is good for
> > > other processes, but has the drawback that you don’t know for
> > > sure that the
> > > current process will be woken “in time”, as there’s nothing
> > > to say that your
> > > process will be scheduled at any particyular time.
> > >
> > > One solution would be to use the QueryPerformanceCounters
> > > interface, which
> > > uses the 8254 counters, and it will give you a precision of
> > > about 0.9 usec,
> > > IIRC. Something like this:
> > >
> > > void delayUsecs(int uSecs)
> > > {
> > > LARGE_INTEGER Count, Count2, CountWanted;
> > > LARGE_INTEGER Passed;
> > > LARGE_INTEGER uSecsLeft;
> > > LARGE_INTEGER Freq;
> > >
> > > Count = KeQueryPerformanceCounter( &Freq );
> > >
> > > CountWanted.quad = (uSecs * Freq.quad) / 1000000;
> > >
> > > if (uSecs > 20)
> > > {
> > > KeDelayExecutionThread(uSecs - 10);
> > > }
> > >
> > > Count2 = KeQuesryPerformanceCounter( NULL );
> > >
> > > Passed.quad = Count2.quad - Count.quad;
> > >
> > > if (Passed.quad > CountWanted.quad)
> > > return; // We overshot. May want to do
> > > something to debug the problem…
> > > uSecsLeft = uSecs - (Passed.Quad * 1000000) / Freq.Quad);
> > >
> > > if (uSecsLeft)
> > > KeStallExecutionProcessor(uSecsLeft);
> > > }
> > >
> > > This way you get the best of both worlds.
> > >
> > > I had problems with KeDelayExecutionThread however.
> > > Apparently, if you call
> > > it at the wrong IRQL, it just returns immediately (and I used
> > > it to figure
> > > out the frequency of something else, which meant that both my
> > > “before” and
> > > “after” times where the same, so I got a divide by zero :frowning:
> > > ). I wrote my
> > > own “sleep” routine instead. This uses the KeSetTimer() and
> > > KeWaitForSingleObject(). This isn’t a very precise “sleep”,
> > > which is fine if
> > > I’m just trying to figure out how many cycles pass on one of
> > > my internal
> > > counters in a specified time, but if you want to delay a
> > > certain (exact)
> > > amount, it’s not particularly useful.
> > >
> > > Note also that as of current, there’s nothing that prevents
> > > an interrupt
> > > from taking several microseconds (or milliseconds for that
> > > matter), so any
> > > precise timing that isn’t run at IRQL which dissables
> > > Interrupts, will mean
> > > that you could have “overshot” your timing. There’s nothing
> > > to prevent this
> > > from happening, except making sure that any drivers in
> the system is
> > > “well-behaved” (including in "special cases, like error
> > > handling and other
> > > obscure scenarios. Num-lock key on the keyboard used to be
> > > bad when the BIOS
> > > handled it, but I think Windows doesn’t hold interrupts off
> > > for the 4.2
> > > milliseconds it takes for everything to happen in a “set
> > > numlock LED”).
> > >
> > > –
> > > Mats
> > >
> > > > -----Original Message-----
> > > > From: Nikolay [mailto:xxxxx@pisem.net]
> > > > Sent: Monday, February 09, 2004 2:11 PM
> > > > To: Windows System Software Devs Interest List
> > > > Subject: [ntdev] How to delay execution
> > > >
> > > >
> > > > Hello
> > > >
> > > > I need to delay the code execution
> > > > The delay varies from 130 to 1500 usecs. What function
> > > should be used?
> > > > KeDelayExecutionThread works Ok with delay > 20 msecs, since
> > > > inaccuracy can
> > > > be 5 msecs (or more)
> > > > KeStallExecutionProcessor is more accurate, but DDK
> > > > documentation says:
> > > > “… Drivers that call this routine should minimize the
> number of
> > > > microseconds they specify (no more than 50)…”,
> > > > So I have not use KeStallExecutionProcessor…
> > > >
> > > > How to solve this?
> > > > How to implement the delay in case if range is from 50 usecs
> > > > to 20 msecs???
> > > >
> > > > Thanx,
> > > > Nikolay
> > > >
> > > >
> > > >
> > > > —
> > > > Questions? First check the Kernel Driver FAQ at
> > > > http://www.osronline.com/article.cfm?id=256
> > > >
> > > > You are currently subscribed to ntdev as:
> xxxxx@3dlabs.com
> > > > To unsubscribe send a blank email to
> > > xxxxx@lists.osr.com
> > > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@3dlabs.com
> > To unsubscribe send a blank email to
> xxxxx@lists.osr.com
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@3dlabs.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

But this is exactly what QueryPerformanceCounters do. Why not use it?
Because it’s differnet between system. Yes, but you do get the frequency of
the counter if you ask nicely (as in, if you supply a pointer to a space for
the counter to be stored in), and you can then convert it to whatever units
you like, like 0.1 ms or 0.1 us units (like what MS uses internally).

Using hardware that isn’t “yours” is not nice to other software. What if
Nikolay decides to use this, and his driver gets loaded in a system with
your driver? Who gets the right value? Answer is neither of you, if you both
reset the counter each time you get a value.

This is fine for a hobby project, but a production driver should NEVER touch
some hardware that isn’t owned by that driver, because that’s exactly how
you get conflicts.

[Of course, if you only use this for a debug version of the driver, that’s a
different case].


Mats

-----Original Message-----
From: (SV2AGW)George Rossopoulos [mailto:xxxxx@softhome.net]
Sent: Monday, February 09, 2004 4:43 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

Hi all

I have seen here many times discussion for accurate timing.
Since I had this same problem, I think that I must share my
experience.
I have a driver that must measures accurately the time elapsed between
interrupts that the hardware generates.
QueryPerformanceCounters is not what I was expected perhaps
because windows
modify the counter depending on the system hardware.

I am doing something else more simple .
I am using the speaker counter. It is accurate and easy to use.
A good practise is to reprogram the counter every now and
then since someone
else may try to change it. From my experience noone ever
tried to modify it.
My driver runs on more that 2000 systems including WIN98 version.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
Sent: Monday, February 09, 2004 5:17 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] How to delay execution

> One solution would be to use the QueryPerformanceCounters
interface,
> which uses the 8254 counters, and it will give you a precision of
> about 0.9
usec,
> IIRC. Something like this:

This depends on the HAL and boot options. Often QPC will use
the processor
timestamp counter if one is available and the clocks for all
processors are
synchronous.

If I had to deal with this case, (which sounds like broken
hardware), I’d
start by changing the time interval to 1ms from the default
16.something,
then determine if the delay is going to be > 2ms or so. If
so, I’d use a
delay of some sort. If it was less, I’d stall. I’m not sure
that multiple
short stalls will really help over one long stall. The idea
is to release
the processor for other time-critical things. If the driver
never releases
control between a series of short stalls, I don’t see that doing short
stalls will help any.

Yes, reducing the quantum hurts performance a little. However, it will
probably have far less detrimental effect on the system than
stalling for
20ms at a time. And it gets it to the point where you can delay for
anything much over 1ms.

Loren

I wonder if the Kernel guys are ever going to consider
allowing ticks down
to 100us or so, rather than 1ms minimum. That 1ms minimum
was set in the
days of 33MHz processors. Most systems are a bit faster than
that now, and
can probably support timer interrupts at a 10K rate.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@softhome.net
To unsubscribe
send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@3dlabs.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Sorry, I must use HAL, I can not want work with HW directly.
But your way is attractive! Could you show the piece of code?

“(SV2AGW)George Rossopoulos” wrote in message
news:xxxxx@ntdev…
> Hi all
>
> I have seen here many times discussion for accurate timing.
> Since I had this same problem, I think that I must share my experience.
> I have a driver that must measures accurately the time elapsed between
> interrupts that the hardware generates.
> QueryPerformanceCounters is not what I was expected perhaps because
windows
> modify the counter depending on the system hardware.
>
> I am doing something else more simple .
> I am using the speaker counter. It is accurate and easy to use.
> A good practise is to reprogram the counter every now and then since
someone
> else may try to change it. From my experience noone ever tried to modify
it.
> My driver runs on more that 2000 systems including WIN98 version.

>
> regards
>
>
> (SV2AGW)George Rossopoulos
> xxxxx@elcom.gr
> www.elcom.gr/sv2agw
> +306932465216
> George Rossopoulos
> Nikanoros 59
> 54250,Thessaloniki
> Greece
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
> Sent: Monday, February 09, 2004 5:17 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] How to delay execution
>
> > One solution would be to use the QueryPerformanceCounters interface,
> > which uses the 8254 counters, and it will give you a precision of
> > about 0.9
> usec,
> > IIRC. Something like this:
>
> This depends on the HAL and boot options. Often QPC will use the
processor
> timestamp counter if one is available and the clocks for all processors
are
> synchronous.
>
> If I had to deal with this case, (which sounds like broken hardware), I’d
> start by changing the time interval to 1ms from the default 16.something,
> then determine if the delay is going to be > 2ms or so. If so, I’d use a
> delay of some sort. If it was less, I’d stall. I’m not sure that
multiple
> short stalls will really help over one long stall. The idea is to release
> the processor for other time-critical things. If the driver never
releases
> control between a series of short stalls, I don’t see that doing short
> stalls will help any.
>
> Yes, reducing the quantum hurts performance a little. However, it will
> probably have far less detrimental effect on the system than stalling for
> 20ms at a time. And it gets it to the point where you can delay for
> anything much over 1ms.
>
> Loren
>
> I wonder if the Kernel guys are ever going to consider allowing ticks down
> to 100us or so, rather than 1ms minimum. That 1ms minimum was set in the
> days of 33MHz processors. Most systems are a bit faster than that now,
and
> can probably support timer interrupts at a 10K rate.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@softhome.net To
unsubscribe
> send a blank email to xxxxx@lists.osr.com
>
>

This is how you can handle it

********** Timer addresses*****************

Counteraddress.LowPart =0x42;//timers
Counteraddress.HighPart = 0;

Counteriniaddress.LowPart =0x61;//timer address to setup it
Counteriniaddress.HighPart = 0;

**************** How to Initialize it *****************
void initialize_counter(IN PDEVICE_EXTENSION Dev)
{
unsigned char t;
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort+1),0xb6);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);

t=READ_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort));
t|=1;
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort),t);
}

***********************This is how you read it, Timernow is a 16 bit
int**************

WRITE_PORT_UCHAR((PUCHAR)(CounterTranslatedPort+1),0x80);
t0=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=(TimerNow << 8) + t0;

Hope this helps.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolay
Sent: Monday, February 09, 2004 7:05 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

Sorry, I must use HAL, I can not want work with HW directly.
But your way is attractive! Could you show the piece of code?

“(SV2AGW)George Rossopoulos” wrote in message
news:xxxxx@ntdev…
> Hi all
>
> I have seen here many times discussion for accurate timing.
> Since I had this same problem, I think that I must share my experience.
> I have a driver that must measures accurately the time elapsed between
> interrupts that the hardware generates.
> QueryPerformanceCounters is not what I was expected perhaps because
windows
> modify the counter depending on the system hardware.
>
> I am doing something else more simple .
> I am using the speaker counter. It is accurate and easy to use.
> A good practise is to reprogram the counter every now and then since
someone
> else may try to change it. From my experience noone ever tried to
> modify
it.
> My driver runs on more that 2000 systems including WIN98 version.

>
> regards
>
>
> (SV2AGW)George Rossopoulos
> xxxxx@elcom.gr
> www.elcom.gr/sv2agw
> +306932465216
> George Rossopoulos
> Nikanoros 59
> 54250,Thessaloniki
> Greece
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
> Sent: Monday, February 09, 2004 5:17 PM
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] How to delay execution
>
> > One solution would be to use the QueryPerformanceCounters interface,
> > which uses the 8254 counters, and it will give you a precision of
> > about 0.9
> usec,
> > IIRC. Something like this:
>
> This depends on the HAL and boot options. Often QPC will use the
processor
> timestamp counter if one is available and the clocks for all
> processors
are
> synchronous.
>
> If I had to deal with this case, (which sounds like broken hardware),
> I’d start by changing the time interval to 1ms from the default
> 16.something, then determine if the delay is going to be > 2ms or so.
> If so, I’d use a delay of some sort. If it was less, I’d stall. I’m
> not sure that
multiple
> short stalls will really help over one long stall. The idea is to
> release the processor for other time-critical things. If the driver
> never
releases
> control between a series of short stalls, I don’t see that doing short
> stalls will help any.
>
> Yes, reducing the quantum hurts performance a little. However, it will
> probably have far less detrimental effect on the system than stalling
> for 20ms at a time. And it gets it to the point where you can delay
> for anything much over 1ms.
>
> Loren
>
> I wonder if the Kernel guys are ever going to consider allowing ticks
> down to 100us or so, rather than 1ms minimum. That 1ms minimum was
> set in the days of 33MHz processors. Most systems are a bit faster
> than that now,
and
> can probably support timer interrupts at a 10K rate.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@softhome.net To
unsubscribe
> send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@softhome.net To unsubscribe
send a blank email to xxxxx@lists.osr.com

I’m sorry but while this might work on 99% of all deployed windows
platforms, it is just wrong. (Slowly putting on alberto-flame armor.)

=====================
Mark Roddy

-----Original Message-----
From: (SV2AGW)George Rossopoulos [mailto:xxxxx@softhome.net]
Sent: Monday, February 09, 2004 2:42 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

This is how you can handle it

********** Timer addresses*****************

Counteraddress.LowPart =0x42;//timers
Counteraddress.HighPart = 0;

Counteriniaddress.LowPart =0x61;//timer address to setup it
Counteriniaddress.HighPart = 0;

**************** How to Initialize it ***************** void
initialize_counter(IN PDEVICE_EXTENSION Dev) { unsigned char
t; WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort+1),0xb6);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);

t=READ_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort));
t|=1;
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort),t);
}

***********************This is how you read it, Timernow is a 16 bit
int**************

WRITE_PORT_UCHAR((PUCHAR)(CounterTranslatedPort+1),0x80);
t0=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=(TimerNow << 8) + t0;

Hope this helps.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolay
Sent: Monday, February 09, 2004 7:05 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

Sorry, I must use HAL, I can not want work with HW directly.
But your way is attractive! Could you show the piece of code?

“(SV2AGW)George Rossopoulos” wrote in
> message news:xxxxx@ntdev…
> > Hi all
> >
> > I have seen here many times discussion for accurate timing.
> > Since I had this same problem, I think that I must share my
> experience.
> > I have a driver that must measures accurately the time
> elapsed between
> > interrupts that the hardware generates.
> > QueryPerformanceCounters is not what I was expected perhaps because
> windows
> > modify the counter depending on the system hardware.
> >
> > I am doing something else more simple .
> > I am using the speaker counter. It is accurate and easy to use.
> > A good practise is to reprogram the counter every now and then since
> someone
> > else may try to change it. From my experience noone ever tried to
> > modify
> it.
> > My driver runs on more that 2000 systems including WIN98 version.
>
> >
> > regards
> >
> >
> > (SV2AGW)George Rossopoulos
> > xxxxx@elcom.gr
> > www.elcom.gr/sv2agw
> > +306932465216
> > George Rossopoulos
> > Nikanoros 59
> > 54250,Thessaloniki
> > Greece
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
> > Sent: Monday, February 09, 2004 5:17 PM
> > To: Windows System Software Devs Interest List
> > Subject: Re: [ntdev] How to delay execution
> >
> > > One solution would be to use the QueryPerformanceCounters
> interface,
> > > which uses the 8254 counters, and it will give you a precision of
> > > about 0.9
> > usec,
> > > IIRC. Something like this:
> >
> > This depends on the HAL and boot options. Often QPC will use the
> processor
> > timestamp counter if one is available and the clocks for all
> > processors
> are
> > synchronous.
> >
> > If I had to deal with this case, (which sounds like broken
> hardware),
> > I’d start by changing the time interval to 1ms from the default
> > 16.something, then determine if the delay is going to be >
> 2ms or so.
> > If so, I’d use a delay of some sort. If it was less, I’d
> stall. I’m
> > not sure that
> multiple
> > short stalls will really help over one long stall. The idea is to
> > release the processor for other time-critical things. If
> the driver
> > never
> releases
> > control between a series of short stalls, I don’t see that
> doing short
> > stalls will help any.
> >
> > Yes, reducing the quantum hurts performance a little.
> However, it will
> > probably have far less detrimental effect on the system
> than stalling
> > for 20ms at a time. And it gets it to the point where you
> can delay
> > for anything much over 1ms.
> >
> > Loren
> >
> > I wonder if the Kernel guys are ever going to consider
> allowing ticks
> > down to 100us or so, rather than 1ms minimum. That 1ms minimum was
> > set in the days of 33MHz processors. Most systems are a bit faster
> > than that now,
> and
> > can probably support timer interrupts at a 10K rate.
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> unsubscribe
> > send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@softhome.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>

Nah, I would write it in machine code. :slight_smile:

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Roddy, Mark
Sent: Monday, February 09, 2004 2:47 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I’m sorry but while this might work on 99% of all deployed windows
platforms, it is just wrong. (Slowly putting on alberto-flame armor.)

=====================
Mark Roddy

-----Original Message-----
From: (SV2AGW)George Rossopoulos [mailto:xxxxx@softhome.net]
Sent: Monday, February 09, 2004 2:42 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

This is how you can handle it

********** Timer addresses*****************

Counteraddress.LowPart =0x42;//timers
Counteraddress.HighPart = 0;

Counteriniaddress.LowPart =0x61;//timer address to setup it
Counteriniaddress.HighPart = 0;

**************** How to Initialize it ***************** void
initialize_counter(IN PDEVICE_EXTENSION Dev) { unsigned char
t; WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort+1),0xb6);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);

t=READ_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort));
t|=1;
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort),t);
}

***********************This is how you read it, Timernow is a 16 bit
int**************

WRITE_PORT_UCHAR((PUCHAR)(CounterTranslatedPort+1),0x80);
t0=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=(TimerNow << 8) + t0;

Hope this helps.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolay
Sent: Monday, February 09, 2004 7:05 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

Sorry, I must use HAL, I can not want work with HW directly.
But your way is attractive! Could you show the piece of code?

“(SV2AGW)George Rossopoulos” wrote in
> message news:xxxxx@ntdev…
> > Hi all
> >
> > I have seen here many times discussion for accurate timing.
> > Since I had this same problem, I think that I must share my
> experience.
> > I have a driver that must measures accurately the time
> elapsed between
> > interrupts that the hardware generates.
> > QueryPerformanceCounters is not what I was expected perhaps because
> windows
> > modify the counter depending on the system hardware.
> >
> > I am doing something else more simple .
> > I am using the speaker counter. It is accurate and easy to use.
> > A good practise is to reprogram the counter every now and then since
> someone
> > else may try to change it. From my experience noone ever tried to
> > modify
> it.
> > My driver runs on more that 2000 systems including WIN98 version.
>
> >
> > regards
> >
> >
> > (SV2AGW)George Rossopoulos
> > xxxxx@elcom.gr
> > www.elcom.gr/sv2agw
> > +306932465216
> > George Rossopoulos
> > Nikanoros 59
> > 54250,Thessaloniki
> > Greece
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
> > Sent: Monday, February 09, 2004 5:17 PM
> > To: Windows System Software Devs Interest List
> > Subject: Re: [ntdev] How to delay execution
> >
> > > One solution would be to use the QueryPerformanceCounters
> interface,
> > > which uses the 8254 counters, and it will give you a precision of
> > > about 0.9
> > usec,
> > > IIRC. Something like this:
> >
> > This depends on the HAL and boot options. Often QPC will use the
> processor
> > timestamp counter if one is available and the clocks for all
> > processors
> are
> > synchronous.
> >
> > If I had to deal with this case, (which sounds like broken
> hardware),
> > I’d start by changing the time interval to 1ms from the default
> > 16.something, then determine if the delay is going to be >
> 2ms or so.
> > If so, I’d use a delay of some sort. If it was less, I’d
> stall. I’m
> > not sure that
> multiple
> > short stalls will really help over one long stall. The idea is to
> > release the processor for other time-critical things. If
> the driver
> > never
> releases
> > control between a series of short stalls, I don’t see that
> doing short
> > stalls will help any.
> >
> > Yes, reducing the quantum hurts performance a little.
> However, it will
> > probably have far less detrimental effect on the system
> than stalling
> > for 20ms at a time. And it gets it to the point where you
> can delay
> > for anything much over 1ms.
> >
> > Loren
> >
> > I wonder if the Kernel guys are ever going to consider
> allowing ticks
> > down to 100us or so, rather than 1ms minimum. That 1ms minimum was
> > set in the days of 33MHz processors. Most systems are a bit faster
> > than that now,
> and
> > can probably support timer interrupts at a 10K rate.
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> unsubscribe
> > send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@softhome.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.

“(SV2AGW)George Rossopoulos” wrote in message
news:xxxxx@ntdev…
>
> I have a driver that must measures accurately the time
> elapsed between interrupts that the hardware generates.
> QueryPerformanceCounters is not what I was expected
> perhaps because windows modify the counter depending
> on the system hardware.

What were you expecting? Why was it not suitable?

I was wondering how long it would be before we got the “Alberto” hack :slight_smile:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Monday, February 09, 2004 11:50 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

Nah, I would write it in machine code. :slight_smile:

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Roddy, Mark
Sent: Monday, February 09, 2004 2:47 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I’m sorry but while this might work on 99% of all deployed windows
platforms, it is just wrong. (Slowly putting on alberto-flame armor.)

=====================
Mark Roddy

-----Original Message-----
From: (SV2AGW)George Rossopoulos [mailto:xxxxx@softhome.net]
Sent: Monday, February 09, 2004 2:42 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

This is how you can handle it

********** Timer addresses*****************

Counteraddress.LowPart =0x42;//timers
Counteraddress.HighPart = 0;

Counteriniaddress.LowPart =0x61;//timer address to setup it
Counteriniaddress.HighPart = 0;

**************** How to Initialize it ***************** void
initialize_counter(IN PDEVICE_EXTENSION Dev) { unsigned char
t; WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort+1),0xb6);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);

t=READ_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort));
t|=1;
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort),t);
}

***********************This is how you read it, Timernow is a 16 bit
int**************

WRITE_PORT_UCHAR((PUCHAR)(CounterTranslatedPort+1),0x80);
t0=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=(TimerNow << 8) + t0;

Hope this helps.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolay
Sent: Monday, February 09, 2004 7:05 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

Sorry, I must use HAL, I can not want work with HW directly.
But your way is attractive! Could you show the piece of code?

“(SV2AGW)George Rossopoulos” wrote in
> message news:xxxxx@ntdev…
> > Hi all
> >
> > I have seen here many times discussion for accurate timing.
> > Since I had this same problem, I think that I must share my
> experience.
> > I have a driver that must measures accurately the time
> elapsed between
> > interrupts that the hardware generates.
> > QueryPerformanceCounters is not what I was expected perhaps because
> windows
> > modify the counter depending on the system hardware.
> >
> > I am doing something else more simple .
> > I am using the speaker counter. It is accurate and easy to use.
> > A good practise is to reprogram the counter every now and then since
> someone
> > else may try to change it. From my experience noone ever tried to
> > modify
> it.
> > My driver runs on more that 2000 systems including WIN98 version.
>
> >
> > regards
> >
> >
> > (SV2AGW)George Rossopoulos
> > xxxxx@elcom.gr
> > www.elcom.gr/sv2agw
> > +306932465216
> > George Rossopoulos
> > Nikanoros 59
> > 54250,Thessaloniki
> > Greece
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
> > Sent: Monday, February 09, 2004 5:17 PM
> > To: Windows System Software Devs Interest List
> > Subject: Re: [ntdev] How to delay execution
> >
> > > One solution would be to use the QueryPerformanceCounters
> interface,
> > > which uses the 8254 counters, and it will give you a precision of
> > > about 0.9
> > usec,
> > > IIRC. Something like this:
> >
> > This depends on the HAL and boot options. Often QPC will use the
> processor
> > timestamp counter if one is available and the clocks for all
> > processors
> are
> > synchronous.
> >
> > If I had to deal with this case, (which sounds like broken
> hardware),
> > I’d start by changing the time interval to 1ms from the default
> > 16.something, then determine if the delay is going to be >
> 2ms or so.
> > If so, I’d use a delay of some sort. If it was less, I’d
> stall. I’m
> > not sure that
> multiple
> > short stalls will really help over one long stall. The idea is to
> > release the processor for other time-critical things. If
> the driver
> > never
> releases
> > control between a series of short stalls, I don’t see that
> doing short
> > stalls will help any.
> >
> > Yes, reducing the quantum hurts performance a little.
> However, it will
> > probably have far less detrimental effect on the system
> than stalling
> > for 20ms at a time. And it gets it to the point where you
> can delay
> > for anything much over 1ms.
> >
> > Loren
> >
> > I wonder if the Kernel guys are ever going to consider
> allowing ticks
> > down to 100us or so, rather than 1ms minimum. That 1ms minimum was
> > set in the days of 33MHz processors. Most systems are a bit faster
> > than that now,
> and
> > can probably support timer interrupts at a 10K rate.
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> unsubscribe
> > send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@softhome.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Well, hey, I was prodded !

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Jamey Kirby
Sent: Monday, February 09, 2004 3:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I was wondering how long it would be before we got the “Alberto” hack :slight_smile:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Moreira, Alberto
Sent: Monday, February 09, 2004 11:50 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

Nah, I would write it in machine code. :slight_smile:

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Roddy, Mark
Sent: Monday, February 09, 2004 2:47 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I’m sorry but while this might work on 99% of all deployed windows
platforms, it is just wrong. (Slowly putting on alberto-flame armor.)

=====================
Mark Roddy

-----Original Message-----
From: (SV2AGW)George Rossopoulos [mailto:xxxxx@softhome.net]
Sent: Monday, February 09, 2004 2:42 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

This is how you can handle it

********** Timer addresses*****************

Counteraddress.LowPart =0x42;//timers
Counteraddress.HighPart = 0;

Counteriniaddress.LowPart =0x61;//timer address to setup it
Counteriniaddress.HighPart = 0;

**************** How to Initialize it ***************** void
initialize_counter(IN PDEVICE_EXTENSION Dev) { unsigned char
t; WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort+1),0xb6);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);

t=READ_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort));
t|=1;
WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort),t);
}

***********************This is how you read it, Timernow is a 16 bit
int**************

WRITE_PORT_UCHAR((PUCHAR)(CounterTranslatedPort+1),0x80);
t0=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
TimerNow=(TimerNow << 8) + t0;

Hope this helps.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Nikolay
Sent: Monday, February 09, 2004 7:05 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

Sorry, I must use HAL, I can not want work with HW directly.
But your way is attractive! Could you show the piece of code?

“(SV2AGW)George Rossopoulos” wrote in
> message news:xxxxx@ntdev…
> > Hi all
> >
> > I have seen here many times discussion for accurate timing.
> > Since I had this same problem, I think that I must share my
> experience.
> > I have a driver that must measures accurately the time
> elapsed between
> > interrupts that the hardware generates.
> > QueryPerformanceCounters is not what I was expected perhaps because
> windows
> > modify the counter depending on the system hardware.
> >
> > I am doing something else more simple .
> > I am using the speaker counter. It is accurate and easy to use.
> > A good practise is to reprogram the counter every now and then since
> someone
> > else may try to change it. From my experience noone ever tried to
> > modify
> it.
> > My driver runs on more that 2000 systems including WIN98 version.
>
> >
> > regards
> >
> >
> > (SV2AGW)George Rossopoulos
> > xxxxx@elcom.gr
> > www.elcom.gr/sv2agw
> > +306932465216
> > George Rossopoulos
> > Nikanoros 59
> > 54250,Thessaloniki
> > Greece
> >
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com] On Behalf Of Loren Wilton
> > Sent: Monday, February 09, 2004 5:17 PM
> > To: Windows System Software Devs Interest List
> > Subject: Re: [ntdev] How to delay execution
> >
> > > One solution would be to use the QueryPerformanceCounters
> interface,
> > > which uses the 8254 counters, and it will give you a precision of
> > > about 0.9
> > usec,
> > > IIRC. Something like this:
> >
> > This depends on the HAL and boot options. Often QPC will use the
> processor
> > timestamp counter if one is available and the clocks for all
> > processors
> are
> > synchronous.
> >
> > If I had to deal with this case, (which sounds like broken
> hardware),
> > I’d start by changing the time interval to 1ms from the default
> > 16.something, then determine if the delay is going to be >
> 2ms or so.
> > If so, I’d use a delay of some sort. If it was less, I’d
> stall. I’m
> > not sure that
> multiple
> > short stalls will really help over one long stall. The idea is to
> > release the processor for other time-critical things. If
> the driver
> > never
> releases
> > control between a series of short stalls, I don’t see that
> doing short
> > stalls will help any.
> >
> > Yes, reducing the quantum hurts performance a little.
> However, it will
> > probably have far less detrimental effect on the system
> than stalling
> > for 20ms at a time. And it gets it to the point where you
> can delay
> > for anything much over 1ms.
> >
> > Loren
> >
> > I wonder if the Kernel guys are ever going to consider
> allowing ticks
> > down to 100us or so, rather than 1ms minimum. That 1ms minimum was
> > set in the days of 33MHz processors. Most systems are a bit faster
> > than that now,
> and
> > can probably support timer interrupts at a 10K rate.
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> unsubscribe
> > send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@softhome.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.

I agree. I started it. It was an entirely justified preemptive strike. Trust
me, you are much safer now.

=====================
Mark Roddy

-----Original Message-----
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Monday, February 09, 2004 3:04 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

Well, hey, I was prodded !

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Jamey Kirby
Sent: Monday, February 09, 2004 3:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I was wondering how long it would be before we got the
“Alberto” hack :slight_smile:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
Moreira, Alberto
Sent: Monday, February 09, 2004 11:50 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

Nah, I would write it in machine code. :slight_smile:

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Roddy, Mark
Sent: Monday, February 09, 2004 2:47 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I’m sorry but while this might work on 99% of all deployed
windows platforms, it is just wrong. (Slowly putting on
alberto-flame armor.)

=====================
Mark Roddy

> -----Original Message-----
> From: (SV2AGW)George Rossopoulos [mailto:xxxxx@softhome.net]
> Sent: Monday, February 09, 2004 2:42 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] How to delay execution
>
> This is how you can handle it
>
> ********** Timer addresses*****************
>
> Counteraddress.LowPart =0x42;//timers
> Counteraddress.HighPart = 0;
>
> Counteriniaddress.LowPart =0x61;//timer address to setup it
> Counteriniaddress.HighPart = 0;
>
> **************** How to Initialize it ***************** void
> initialize_counter(IN PDEVICE_EXTENSION Dev) { unsigned char t;
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort+1),0xb6);
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
>
>
> t=READ_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort));
> t|=1;
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort),t);
> }
>
> ***********************This is how you read it, Timernow is a 16 bit
> int**************
>
> WRITE_PORT_UCHAR((PUCHAR)(CounterTranslatedPort+1),0x80);
> t0=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
> TimerNow=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
> TimerNow=(TimerNow << 8) + t0;
>
> Hope this helps.
>
> regards
>
>
> (SV2AGW)George Rossopoulos
> xxxxx@elcom.gr
> www.elcom.gr/sv2agw
> +306932465216
> George Rossopoulos
> Nikanoros 59
> 54250,Thessaloniki
> Greece
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Nikolay
> Sent: Monday, February 09, 2004 7:05 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] How to delay execution
>
> Sorry, I must use HAL, I can not want work with HW directly.
> But your way is attractive! Could you show the piece of code?
>
> “(SV2AGW)George Rossopoulos” wrote in message
> > news:xxxxx@ntdev…
> > > Hi all
> > >
> > > I have seen here many times discussion for accurate timing.
> > > Since I had this same problem, I think that I must share my
> > experience.
> > > I have a driver that must measures accurately the time
> > elapsed between
> > > interrupts that the hardware generates.
> > > QueryPerformanceCounters is not what I was expected
> perhaps because
> > windows
> > > modify the counter depending on the system hardware.
> > >
> > > I am doing something else more simple .
> > > I am using the speaker counter. It is accurate and easy to use.
> > > A good practise is to reprogram the counter every now and
> then since
> > someone
> > > else may try to change it. From my experience noone ever tried to
> > > modify
> > it.
> > > My driver runs on more that 2000 systems including WIN98 version.
> >
> > >
> > > regards
> > >
> > >
> > > (SV2AGW)George Rossopoulos
> > > xxxxx@elcom.gr
> > > www.elcom.gr/sv2agw
> > > +306932465216
> > > George Rossopoulos
> > > Nikanoros 59
> > > 54250,Thessaloniki
> > > Greece
> > >
> > > -----Original Message-----
> > > From: xxxxx@lists.osr.com
> > > [mailto:xxxxx@lists.osr.com] On Behalf Of
> Loren Wilton
> > > Sent: Monday, February 09, 2004 5:17 PM
> > > To: Windows System Software Devs Interest List
> > > Subject: Re: [ntdev] How to delay execution
> > >
> > > > One solution would be to use the QueryPerformanceCounters
> > interface,
> > > > which uses the 8254 counters, and it will give you a
> precision of
> > > > about 0.9
> > > usec,
> > > > IIRC. Something like this:
> > >
> > > This depends on the HAL and boot options. Often QPC will use the
> > processor
> > > timestamp counter if one is available and the clocks for all
> > > processors
> > are
> > > synchronous.
> > >
> > > If I had to deal with this case, (which sounds like broken
> > hardware),
> > > I’d start by changing the time interval to 1ms from the default
> > > 16.something, then determine if the delay is going to be >
> > 2ms or so.
> > > If so, I’d use a delay of some sort. If it was less, I’d
> > stall. I’m
> > > not sure that
> > multiple
> > > short stalls will really help over one long stall. The
> idea is to
> > > release the processor for other time-critical things. If
> > the driver
> > > never
> > releases
> > > control between a series of short stalls, I don’t see that
> > doing short
> > > stalls will help any.
> > >
> > > Yes, reducing the quantum hurts performance a little.
> > However, it will
> > > probably have far less detrimental effect on the system
> > than stalling
> > > for 20ms at a time. And it gets it to the point where you
> > can delay
> > > for anything much over 1ms.
> > >
> > > Loren
> > >
> > > I wonder if the Kernel guys are ever going to consider
> > allowing ticks
> > > down to 100us or so, rather than 1ms minimum. That 1ms
> minimum was
> > > set in the days of 33MHz processors. Most systems are a
> bit faster
> > > than that now,
> > and
> > > can probably support timer interrupts at a 10K rate.
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> > unsubscribe
> > > send a blank email to xxxxx@lists.osr.com
> > >
> > >
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> > unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@stratus.com To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@compuware.com To unsubscribe send a blank
> email to xxxxx@lists.osr.com
>
>
>
> The contents of this e-mail are intended for the named
> addressee only. It contains information that may be
> confidential. Unless you are the named addressee or an
> authorized designee, you may not copy or use it, or disclose
> it to anyone else. If you received it in error please notify
> us immediately and then destroy it.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@storagecraft.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@compuware.com To unsubscribe send a blank
> email to xxxxx@lists.osr.com
>
>
>
> The contents of this e-mail are intended for the named
> addressee only. It contains information that may be
> confidential. Unless you are the named addressee or an
> authorized designee, you may not copy or use it, or disclose
> it to anyone else. If you received it in error please notify
> us immediately and then destroy it.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>

We would have been disappointed if Alberto had not given his “insight” :slight_smile:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roddy, Mark
Sent: Monday, February 09, 2004 12:25 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I agree. I started it. It was an entirely justified preemptive strike. Trust
me, you are much safer now.

=====================
Mark Roddy

-----Original Message-----
From: Moreira, Alberto [mailto:xxxxx@compuware.com]
Sent: Monday, February 09, 2004 3:04 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

Well, hey, I was prodded !

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Jamey Kirby
Sent: Monday, February 09, 2004 3:02 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I was wondering how long it would be before we got the
“Alberto” hack :slight_smile:

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
Moreira, Alberto
Sent: Monday, February 09, 2004 11:50 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

Nah, I would write it in machine code. :slight_smile:

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Roddy, Mark
Sent: Monday, February 09, 2004 2:47 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

I’m sorry but while this might work on 99% of all deployed
windows platforms, it is just wrong. (Slowly putting on
alberto-flame armor.)

=====================
Mark Roddy

> -----Original Message-----
> From: (SV2AGW)George Rossopoulos [mailto:xxxxx@softhome.net]
> Sent: Monday, February 09, 2004 2:42 PM
> To: Windows System Software Devs Interest List
> Subject: RE: [ntdev] How to delay execution
>
> This is how you can handle it
>
> ********** Timer addresses*****************
>
> Counteraddress.LowPart =0x42;//timers
> Counteraddress.HighPart = 0;
>
> Counteriniaddress.LowPart =0x61;//timer address to setup it
> Counteriniaddress.HighPart = 0;
>
> **************** How to Initialize it ***************** void
> initialize_counter(IN PDEVICE_EXTENSION Dev) { unsigned char t;
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort+1),0xb6);
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterTranslatedPort),0x0);
>
>
> t=READ_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort));
> t|=1;
> WRITE_PORT_UCHAR((PUCHAR)(Dev->CounterIniTranslatedPort),t);
> }
>
> ***********************This is how you read it, Timernow is a 16 bit
> int**************
>
> WRITE_PORT_UCHAR((PUCHAR)(CounterTranslatedPort+1),0x80);
> t0=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
> TimerNow=READ_PORT_UCHAR((PUCHAR)(CounterTranslatedPort));
> TimerNow=(TimerNow << 8) + t0;
>
> Hope this helps.
>
> regards
>
>
> (SV2AGW)George Rossopoulos
> xxxxx@elcom.gr
> www.elcom.gr/sv2agw
> +306932465216
> George Rossopoulos
> Nikanoros 59
> 54250,Thessaloniki
> Greece
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Nikolay
> Sent: Monday, February 09, 2004 7:05 PM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] How to delay execution
>
> Sorry, I must use HAL, I can not want work with HW directly.
> But your way is attractive! Could you show the piece of code?
>
> “(SV2AGW)George Rossopoulos” wrote in message
> > news:xxxxx@ntdev…
> > > Hi all
> > >
> > > I have seen here many times discussion for accurate timing.
> > > Since I had this same problem, I think that I must share my
> > experience.
> > > I have a driver that must measures accurately the time
> > elapsed between
> > > interrupts that the hardware generates.
> > > QueryPerformanceCounters is not what I was expected
> perhaps because
> > windows
> > > modify the counter depending on the system hardware.
> > >
> > > I am doing something else more simple .
> > > I am using the speaker counter. It is accurate and easy to use.
> > > A good practise is to reprogram the counter every now and
> then since
> > someone
> > > else may try to change it. From my experience noone ever tried to
> > > modify
> > it.
> > > My driver runs on more that 2000 systems including WIN98 version.
> >
> > >
> > > regards
> > >
> > >
> > > (SV2AGW)George Rossopoulos
> > > xxxxx@elcom.gr
> > > www.elcom.gr/sv2agw
> > > +306932465216
> > > George Rossopoulos
> > > Nikanoros 59
> > > 54250,Thessaloniki
> > > Greece
> > >
> > > -----Original Message-----
> > > From: xxxxx@lists.osr.com
> > > [mailto:xxxxx@lists.osr.com] On Behalf Of
> Loren Wilton
> > > Sent: Monday, February 09, 2004 5:17 PM
> > > To: Windows System Software Devs Interest List
> > > Subject: Re: [ntdev] How to delay execution
> > >
> > > > One solution would be to use the QueryPerformanceCounters
> > interface,
> > > > which uses the 8254 counters, and it will give you a
> precision of
> > > > about 0.9
> > > usec,
> > > > IIRC. Something like this:
> > >
> > > This depends on the HAL and boot options. Often QPC will use the
> > processor
> > > timestamp counter if one is available and the clocks for all
> > > processors
> > are
> > > synchronous.
> > >
> > > If I had to deal with this case, (which sounds like broken
> > hardware),
> > > I’d start by changing the time interval to 1ms from the default
> > > 16.something, then determine if the delay is going to be >
> > 2ms or so.
> > > If so, I’d use a delay of some sort. If it was less, I’d
> > stall. I’m
> > > not sure that
> > multiple
> > > short stalls will really help over one long stall. The
> idea is to
> > > release the processor for other time-critical things. If
> > the driver
> > > never
> > releases
> > > control between a series of short stalls, I don’t see that
> > doing short
> > > stalls will help any.
> > >
> > > Yes, reducing the quantum hurts performance a little.
> > However, it will
> > > probably have far less detrimental effect on the system
> > than stalling
> > > for 20ms at a time. And it gets it to the point where you
> > can delay
> > > for anything much over 1ms.
> > >
> > > Loren
> > >
> > > I wonder if the Kernel guys are ever going to consider
> > allowing ticks
> > > down to 100us or so, rather than 1ms minimum. That 1ms
> minimum was
> > > set in the days of 33MHz processors. Most systems are a
> bit faster
> > > than that now,
> > and
> > > can probably support timer interrupts at a 10K rate.
> > >
> > >
> > > —
> > > Questions? First check the Kernel Driver FAQ at
> > > http://www.osronline.com/article.cfm?id=256
> > >
> > > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> > unsubscribe
> > > send a blank email to xxxxx@lists.osr.com
> > >
> > >
> >
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as: xxxxx@softhome.net To
> > unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
> > —
> > Questions? First check the Kernel Driver FAQ at
> > http://www.osronline.com/article.cfm?id=256
> >
> > You are currently subscribed to ntdev as:
> > xxxxx@stratus.com To unsubscribe send a blank email to
> > xxxxx@lists.osr.com
> >
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@compuware.com To unsubscribe send a blank
> email to xxxxx@lists.osr.com
>
>
>
> The contents of this e-mail are intended for the named
> addressee only. It contains information that may be
> confidential. Unless you are the named addressee or an
> authorized designee, you may not copy or use it, or disclose
> it to anyone else. If you received it in error please notify
> us immediately and then destroy it.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@storagecraft.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@compuware.com To unsubscribe send a blank
> email to xxxxx@lists.osr.com
>
>
>
> The contents of this e-mail are intended for the named
> addressee only. It contains information that may be
> confidential. Unless you are the named addressee or an
> authorized designee, you may not copy or use it, or disclose
> it to anyone else. If you received it in error please notify
> us immediately and then destroy it.
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@stratus.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@storagecraft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

>

> I have a driver that must measures accurately the time elapsed between
>interrupts that the hardware generates.
> QueryPerformanceCounters is not what I was expected perhaps because
> windows modify the counter depending on the system hardware.

What were you expecting? Why was it not suitable?

The returning value was not updated regulary. I mean that if you call it
twice you get most of the time the same result.
Although in general shows the time elapsed you cannot get accurate short
ranges.
The code is working well for more than 7 years now.
I must say here that the driver is for a special device and is used in
systems where the user knows how to handle this.

Of course you cannot put it in a device sold off the self, but it is rather
rare to need such performance from such devices.
On the other hand you can put it in dedicated systems safely.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J. J. Farrell
Sent: Monday, February 09, 2004 9:55 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

“(SV2AGW)George Rossopoulos” wrote in message
news:xxxxx@ntdev…
>
> I have a driver that must measures accurately the time elapsed between
> interrupts that the hardware generates.
> QueryPerformanceCounters is not what I was expected perhaps because
> windows modify the counter depending on the system hardware.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@softhome.net To unsubscribe
send a blank email to xxxxx@lists.osr.com

Have you tried to issue an RDTSC instruction directly ? It’s available in
every machine since the P6, and it ticks every clock cycle. But of course,
if Windows writes to MSR 10h, you’re out of luck. However, the P4 has 16
sets of counters you can reach through the RDPMC instruction, hopefully you
might find one that’s not touched by the OS ? I suggest you take a good look
at Section 14 of Volume 3 of the P4 Architecture Manual (go to
http://developer.intel.com and you can download it), there’s a lot of good
stuff on performance measurement in there.

Another alternative, of course, is to use a scope or a logic analyzer. Hope
this helps,

Alberto.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of (SV2AGW)George
Rossopoulos
Sent: Monday, February 09, 2004 5:32 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] How to delay execution

> I have a driver that must measures accurately the time elapsed between
>interrupts that the hardware generates.
> QueryPerformanceCounters is not what I was expected perhaps because
> windows modify the counter depending on the system hardware.

What were you expecting? Why was it not suitable?

The returning value was not updated regulary. I mean that if you call it
twice you get most of the time the same result.
Although in general shows the time elapsed you cannot get accurate short
ranges.
The code is working well for more than 7 years now.
I must say here that the driver is for a special device and is used in
systems where the user knows how to handle this.

Of course you cannot put it in a device sold off the self, but it is rather
rare to need such performance from such devices.
On the other hand you can put it in dedicated systems safely.

regards

(SV2AGW)George Rossopoulos
xxxxx@elcom.gr
www.elcom.gr/sv2agw
+306932465216
George Rossopoulos
Nikanoros 59
54250,Thessaloniki
Greece

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of J. J. Farrell
Sent: Monday, February 09, 2004 9:55 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] How to delay execution

“(SV2AGW)George Rossopoulos” wrote in message
news:xxxxx@ntdev…
>
> I have a driver that must measures accurately the time elapsed between
> interrupts that the hardware generates.
> QueryPerformanceCounters is not what I was expected perhaps because
> windows modify the counter depending on the system hardware.


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@softhome.net To unsubscribe
send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

The contents of this e-mail are intended for the named addressee only. It
contains information that may be confidential. Unless you are the named
addressee or an authorized designee, you may not copy or use it, or disclose
it to anyone else. If you received it in error please notify us immediately
and then destroy it.