Clock resolution on a PC and WinNT

Hi, guys!

I have a question (as always… :wink: ). This time I believe it’s quite
simple:

I’ve developed a driver that listens to the network card. For every frame
that
passes through the NIC, I’d like to record its timestamp.

Currently, I use the KeQuerySystemTime() function in order to get it.

The problem is that the resolution of this clock is not fine enough, and I
get the very
same timestamp for subsequent frames.

I’ve been told by someone that there’s another way to get the time,
using a special register that holds the real-time clock, and is updated
automatically, regardless of CPU state.

Is it true?

Any suggestions?

BTW: I’ve noticed that Linux has a clock with 1 microsecond resolution !

thanks in advance,

  • Barak

Barak Mandelovich xxxxx@mercury.co.il
Mercury Interactive ltd.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

KeQueryPerformanceCounter.

----- Original Message -----
From: “Barak Mandelovich”
To: “NT Developers Interest List”
Sent: Tuesday, June 26, 2001 5:41 AM
Subject: [ntdev] Clock resolution on a PC and WinNT

> Hi, guys!
>
> I have a question (as always… :wink: ). This time I believe it’s quite
> simple:
>
> I’ve developed a driver that listens to the network card. For every frame
> that
> passes through the NIC, I’d like to record its timestamp.
>
> Currently, I use the KeQuerySystemTime() function in order to get it.
>
> The problem is that the resolution of this clock is not fine enough, and I
> get the very
> same timestamp for subsequent frames.
>
> I’ve been told by someone that there’s another way to get the time,
> using a special register that holds the real-time clock, and is updated
> automatically, regardless of CPU state.
>
> Is it true?
>
> Any suggestions?
>
> BTW: I’ve noticed that Linux has a clock with 1 microsecond resolution !
>
>
> thanks in advance,
>
> - Barak
>
>
> ------------------------------------------------------------------------
> Barak Mandelovich xxxxx@mercury.co.il
> Mercury Interactive ltd.
> ------------------------------------------------------------------------
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@pcausa.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Hi!

Well, I checked the KeQueryPerformanceCounter() documentation, and it looks
like the usage of this function is highly discouraged, due to performance
issues.

I’d like to take the timestamp for each incoming frame, so I think using it
will harm the performance of the system severely.

Am I right?

Are there other options?

thanks,

  • Barak

PS: I found a sniffer that records incoming frames in 1 microsecond
resolution (Ethereal)

-----Original Message-----
From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
Sent: Tuesday, June 26, 2001 11:30 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

KeQueryPerformanceCounter.

----- Original Message -----
From: “Barak Mandelovich”
To: “NT Developers Interest List”
Sent: Tuesday, June 26, 2001 5:41 AM
Subject: [ntdev] Clock resolution on a PC and WinNT

> Hi, guys!
>
> I have a question (as always… :wink: ). This time I believe it’s quite
> simple:
>
> I’ve developed a driver that listens to the network card. For every frame
> that
> passes through the NIC, I’d like to record its timestamp.
>
> Currently, I use the KeQuerySystemTime() function in order to get it.
>
> The problem is that the resolution of this clock is not fine enough, and I
> get the very
> same timestamp for subsequent frames.
>
> I’ve been told by someone that there’s another way to get the time,
> using a special register that holds the real-time clock, and is updated
> automatically, regardless of CPU state.
>
> Is it true?
>
> Any suggestions?
>
> BTW: I’ve noticed that Linux has a clock with 1 microsecond resolution !
>
>
> thanks in advance,
>
> - Barak
>
>
> ------------------------------------------------------------------------
> Barak Mandelovich xxxxx@mercury.co.il
> Mercury Interactive ltd.
> ------------------------------------------------------------------------


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

No. Use it if you must have improved resolution.

Regards,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:

----- Original Message -----
From: “Barak Mandelovich”
To: “NT Developers Interest List”
Sent: Tuesday, June 26, 2001 8:54 AM
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

> Hi!
>
> Well, I checked the KeQueryPerformanceCounter() documentation, and it
looks
> like the usage of this function is highly discouraged, due to performance
> issues.
>
> I’d like to take the timestamp for each incoming frame, so I think using
it
> will harm the performance of the system severely.
>
> Am I right?
>
> Are there other options?
>
>
> thanks,
>
> - Barak
>
>
> PS: I found a sniffer that records incoming frames in 1 microsecond
> resolution (Ethereal)
>
>
>
> -----Original Message-----
> From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
> Sent: Tuesday, June 26, 2001 11:30 AM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Clock resolution on a PC and WinNT
>
>
> KeQueryPerformanceCounter.
>
> ----- Original Message -----
> From: “Barak Mandelovich”
> To: “NT Developers Interest List”
> Sent: Tuesday, June 26, 2001 5:41 AM
> Subject: [ntdev] Clock resolution on a PC and WinNT
>
>
> > Hi, guys!
> >
> > I have a question (as always… :wink: ). This time I believe it’s quite
> > simple:
> >
> > I’ve developed a driver that listens to the network card. For every
frame
> > that
> > passes through the NIC, I’d like to record its timestamp.
> >
> > Currently, I use the KeQuerySystemTime() function in order to get it.
> >
> > The problem is that the resolution of this clock is not fine enough, and
I
> > get the very
> > same timestamp for subsequent frames.
> >
> > I’ve been told by someone that there’s another way to get the time,
> > using a special register that holds the real-time clock, and is updated
> > automatically, regardless of CPU state.
> >
> > Is it true?
> >
> > Any suggestions?
> >
> > BTW: I’ve noticed that Linux has a clock with 1 microsecond resolution !
> >
> >
> > thanks in advance,
> >
> > - Barak
> >
> >
> > ------------------------------------------------------------------------
> > Barak Mandelovich xxxxx@mercury.co.il
> > Mercury Interactive ltd.
> > ------------------------------------------------------------------------
>
> —
> You are currently subscribed to ntdev as: xxxxx@pcausa.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

The DDK comments on KeQueryPerformanceCounter() seem to be made to
scare people to not use it like this (or similar):

t = KeQueryPerformanceCounter();
timeForLunch = t+5000L;
while( timeForLunch > KeQueryPerformanceCounter())
; // do nothing.

Doing this while at DISPATCH_LEVEL or in a ISR will surely degrade
system performance. But assuming PASSIVE_LEVEL I do not see why it
would degrade system performance.

| Norbert Kawulski | mailto:xxxxx@stollmann.de |
| Stollmann T.P.GmbH, Development | http://www.stollmann.de |
–If it’s ISDN or Bluetooth, make sure it’s driven by Stollmann–

“Violence is the last refuge of the incompetent. - Isaac Asimov”

---------- cut ------------


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

The comments in the DDK are based on the original
HAL implementation. Modern MPS HAL’s use the
Pentium RDTSC instruction, and exhibit almost no
overhead what so ever.

Don Burn
Windows 2000 Device Driver and Filesystem consulting


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

On a single Intel processor the resolution of the
KeQueryPerformanceCounter is limited to 1 microsecond.

The Pentium Cycle Counter runs at the rate of the CPU system clock.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnmag00/html/VTrace.asp

Pentium Cycle Counter

Whenever the logger driver receives a description of an event, it
writes a time stamp to the log just before it writes the event
description to the log. To get accurate time stamps for our trace
events, we use the Pentium cycle counter. This counter gives the
number of cycles that have passed since the computer started up.
We access it with the RDTSC instruction, which can be coded in C
by invoking assembler, as shown in these lines of code:

__asm {
push eax ; Save registers we will overwrite (eax, ebx, edx).
push ebx
push edx
_emit 0x0F ; The RDTSC instruction consists of these two bytes.
_emit 0x31
mov ebx, bufPtr ; Put the address where the timestamp goes in ebx.
mov [ebx],eax ; Save low 4 bytes of timestamp there.
mov [ebx+4],edx ; Save high 4 bytes of timestamp next.
pop edx ; Restore overwritten registers.
pop ebx
pop eax
}

HTH,
Niraj

-----Original Message-----
From: Don Burn [mailto:xxxxx@acm.org]
Sent: Tuesday, June 26, 2001 6:59 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

The comments in the DDK are based on the original
HAL implementation. Modern MPS HAL’s use the
Pentium RDTSC instruction, and exhibit almost no
overhead what so ever.

Don Burn
Windows 2000 Device Driver and Filesystem consulting


You are currently subscribed to ntdev as: xxxxx@netapp.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

While certainly less intrusive than polling at DISPATCH_LEVEL or in an ISR,
running such a loop at PASSIVE_LEVEL does indeed prevent any threads with
lesser priority from running, and takes time away from other threads of the
same priority that may have useful work to do. The CPU usage would also be
pegged at 100%.

Additionally, using such a loop at PASSIVE_LEVEL is unlikely to consistantly
result in much better resolution than using KeDelayExecutionThread(). The
scheduler’s still going to run those other same-or-higher priority threads
in the system, which very well might be running at t+5000l. The result
would be that the while() condition check may not execute again until after
the other thread(s) run.

-Tim

Timothy A. Johns — xxxxx@driverdev.com
Driver Development Corporation — 800.841.0092
Bring Up Your Hardware — Fast. www.driverdev.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Norbert Kawulski
Sent: Tuesday, June 26, 2001 6:41 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

The DDK comments on KeQueryPerformanceCounter() seem to be made to
scare people to not use it like this (or similar):

t = KeQueryPerformanceCounter();
timeForLunch = t+5000L;
while( timeForLunch > KeQueryPerformanceCounter())
; // do nothing.

Doing this while at DISPATCH_LEVEL or in a ISR will surely degrade
system performance. But assuming PASSIVE_LEVEL I do not see why it
would degrade system performance.

| Norbert Kawulski | mailto:xxxxx@stollmann.de |
| Stollmann T.P.GmbH, Development | http://www.stollmann.de |
–If it’s ISDN or Bluetooth, make sure it’s driven by Stollmann–

“Violence is the last refuge of the incompetent. - Isaac Asimov”

---------- cut ------------


You are currently subscribed to ntdev as: xxxxx@driverdev.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Barak,

(despite my previous comments regarding using this function for
polling/timing) For a high-resolution time stamp, that function is perfectly
reasonable and common.

-Tim

Timothy A. Johns — xxxxx@driverdev.com
Driver Development Corporation — 800.841.0092
Bring Up Your Hardware — Fast. www.driverdev.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Barak Mandelovich
Sent: Tuesday, June 26, 2001 5:55 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

Hi!

Well, I checked the KeQueryPerformanceCounter() documentation,
and it looks
like the usage of this function is highly discouraged, due to performance
issues.

I’d like to take the timestamp for each incoming frame, so I
think using it
will harm the performance of the system severely.

Am I right?

Are there other options?

thanks,

  • Barak

PS: I found a sniffer that records incoming frames in 1 microsecond
resolution (Ethereal)

-----Original Message-----
From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
Sent: Tuesday, June 26, 2001 11:30 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

KeQueryPerformanceCounter.

----- Original Message -----
From: “Barak Mandelovich”
> To: “NT Developers Interest List”
> Sent: Tuesday, June 26, 2001 5:41 AM
> Subject: [ntdev] Clock resolution on a PC and WinNT
>
>
> > Hi, guys!
> >
> > I have a question (as always… :wink: ). This time I believe it’s quite
> > simple:
> >
> > I’ve developed a driver that listens to the network card. For
> every frame
> > that
> > passes through the NIC, I’d like to record its timestamp.
> >
> > Currently, I use the KeQuerySystemTime() function in order to get it.
> >
> > The problem is that the resolution of this clock is not fine
> enough, and I
> > get the very
> > same timestamp for subsequent frames.
> >
> > I’ve been told by someone that there’s another way to get the time,
> > using a special register that holds the real-time clock, and is updated
> > automatically, regardless of CPU state.
> >
> > Is it true?
> >
> > Any suggestions?
> >
> > BTW: I’ve noticed that Linux has a clock with 1 microsecond resolution !
> >
> >
> > thanks in advance,
> >
> > - Barak
> >
> >
> > ------------------------------------------------------------------------
> > Barak Mandelovich xxxxx@mercury.co.il
> > Mercury Interactive ltd.
> > ------------------------------------------------------------------------
>
> —
> You are currently subscribed to ntdev as: xxxxx@driverdev.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Tim,
you are 100% right. My point was to show that
KeQueryPerformanceCounter would do no more harm as that dumb
while-loop does anyhow. The thing is that I associate measuring time
with KeQueryPerformanceCounter. Next thing I thought was: 'Oh, people
might poll this within a while-loop. Ah, that is it, what MS does not
want to be done with this function."

| Norbert Kawulski | mailto:xxxxx@stollmann.de |
| Stollmann T.P.GmbH, Development | http://www.stollmann.de |
–If it’s ISDN or Bluetooth, make sure it’s driven by Stollmann–

“All that glitters has a high refractive index.”

While certainly less intrusive than polling at DISPATCH_LEVEL or in an ISR,
running such a loop at PASSIVE_LEVEL does indeed prevent any threads with
lesser priority from running, and takes time away from other threads of the
same priority that may have useful work to do. The CPU usage would also be
pegged at 100%.

Additionally, using such a loop at PASSIVE_LEVEL is unlikely to consistantly
result in much better resolution than using KeDelayExecutionThread(). The
scheduler’s still going to run those other same-or-higher priority threads
in the system, which very well might be running at t+5000l. The result
would be that the while() condition check may not execute again until after
the other thread(s) run.

-Tim

Timothy A. Johns — xxxxx@driverdev.com
Driver Development Corporation — 800.841.0092
Bring Up Your Hardware — Fast. www.driverdev.com
------- cut------------------


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Does this KeQueryPerformanceCounter function have its Win32 API clone?

Regards,

----- Original Message -----
From: Norbert Kawulski
To: NT Developers Interest List
Sent: Tuesday, June 26, 2001 11:48 PM
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

> Tim,
> you are 100% right. My point was to show that
> KeQueryPerformanceCounter would do no more harm as that dumb
> while-loop does anyhow. The thing is that I associate measuring time
> with KeQueryPerformanceCounter. Next thing I thought was: ‘Oh, people
> might poll this within a while-loop. Ah, that is it, what MS does not
> want to be done with this function."
> -----------------------------------------------------------------
> | Norbert Kawulski | mailto:xxxxx@stollmann.de |
> | Stollmann T.P.GmbH, Development | http://www.stollmann.de |
> --If it’s ISDN or Bluetooth, make sure it’s driven by Stollmann–
>
> “All that glitters has a high refractive index.”
>
>
> > While certainly less intrusive than polling at DISPATCH_LEVEL or in an ISR,
> > running such a loop at PASSIVE_LEVEL does indeed prevent any threads with
> > lesser priority from running, and takes time away from other threads of the
> > same priority that may have useful work to do. The CPU usage would also be
> > pegged at 100%.
>
> > Additionally, using such a loop at PASSIVE_LEVEL is unlikely to consistantly
> > result in much better resolution than using KeDelayExecutionThread(). The
> > scheduler’s still going to run those other same-or-higher priority threads
> > in the system, which very well might be running at t+5000l. The result
> > would be that the while() condition check may not execute again until after
> > the other thread(s) run.
>
> > -Tim
>
> > Timothy A. Johns — xxxxx@driverdev.com
> > Driver Development Corporation — 800.841.0092
> > Bring Up Your Hardware — Fast. www.driverdev.com
> ------- cut------------------
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@sdtm.online.sh.cn
> To unsubscribe send a blank email to xxxxx@lists.osr.com
b???.???????&?v?’?ׯj?.n?Qyȩf??]?:.?˛???m??֛???zf???%y?ޞ?^?˛??^r*Lzfެ?…???l??ܢ

I don’t recall if there is a Win32 clone.

In my drivers I define an IOCTL to fetch a structure containing two values:
1.) the current value returned from KeQueryPerformanceCounter and 2.) the
frequency value. These values can be used to synchronize time and to scale
time.

There may be a better way…

Regards,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:

----- Original Message -----
From: “Chen Miaobo”
To: “NT Developers Interest List”
Sent: Tuesday, June 26, 2001 9:47 PM
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

> Does this KeQueryPerformanceCounter function have its Win32 API clone?
>
> Regards,
>
>
> ----- Original Message -----
> From: Norbert Kawulski
> To: NT Developers Interest List
> Sent: Tuesday, June 26, 2001 11:48 PM
> Subject: [ntdev] Re: Clock resolution on a PC and WinNT
>
>
> > Tim,
> > you are 100% right. My point was to show that
> > KeQueryPerformanceCounter would do no more harm as that dumb
> > while-loop does anyhow. The thing is that I associate measuring time
> > with KeQueryPerformanceCounter. Next thing I thought was: 'Oh, people
> > might poll this within a while-loop. Ah, that is it, what MS does not
> > want to be done with this function."
> > -----------------------------------------------------------------
> > | Norbert Kawulski | mailto:xxxxx@stollmann.de |
> > | Stollmann T.P.GmbH, Development | http://www.stollmann.de |
> > --If it’s ISDN or Bluetooth, make sure it’s driven by Stollmann–
> >
> > “All that glitters has a high refractive index.”
> >
> >
> > > While certainly less intrusive than polling at DISPATCH_LEVEL or in an
ISR,
> > > running such a loop at PASSIVE_LEVEL does indeed prevent any threads
with
> > > lesser priority from running, and takes time away from other threads
of the
> > > same priority that may have useful work to do. The CPU usage would
also be
> > > pegged at 100%.
> >
> > > Additionally, using such a loop at PASSIVE_LEVEL is unlikely to
consistantly
> > > result in much better resolution than using KeDelayExecutionThread().
The
> > > scheduler’s still going to run those other same-or-higher priority
threads
> > > in the system, which very well might be running at t+5000l. The
result
> > > would be that the while() condition check may not execute again until
after
> > > the other thread(s) run.
> >
> > > -Tim
> >
> > > Timothy A. Johns — xxxxx@driverdev.com
> > > Driver Development Corporation — 800.841.0092
> > > Bring Up Your Hardware — Fast. www.driverdev.com
> > ------- cut------------------
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@sdtm.online.sh.cn
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
b?(


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
</http:></http:>

Hi,

Actually two functions that work together: QueryPerformanceCounter() and
QueryPerformanceFrequency(). You can check them out in MSDN.

George

George Blat
NT with real time performance
8016 188th SW, Edmonds, WA 98026

phone: 425-775-7475
fax: 781-998-5940
mailto:xxxxx@ntrealtime.com

At 09:47 AM 6/27/01 +0800, you wrote:

Does this KeQueryPerformanceCounter function have its Win32 API clone?

Regards,


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

BOOL QueryPerformanceCounter (
LARGE_INTEGER *lpliPerformanceCount );

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Thomas F. Divine
Sent: Tuesday, June 26, 2001 10:25 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

I don’t recall if there is a Win32 clone.

In my drivers I define an IOCTL to fetch a structure
containing two values:
1.) the current value returned from KeQueryPerformanceCounter
and 2.) the frequency value. These values can be used to
synchronize time and to scale time.

There may be a better way…

Regards,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:
>
>
> ----- Original Message -----
> From: “Chen Miaobo”
> To: “NT Developers Interest List”
> Sent: Tuesday, June 26, 2001 9:47 PM
> Subject: [ntdev] Re: Clock resolution on a PC and WinNT
>
>
> > Does this KeQueryPerformanceCounter function have its Win32
> API clone?
> >
> > Regards,
> >
> >
> > ----- Original Message -----
> > From: Norbert Kawulski
> > To: NT Developers Interest List
> > Sent: Tuesday, June 26, 2001 11:48 PM
> > Subject: [ntdev] Re: Clock resolution on a PC and WinNT
> >
> >
> > > Tim,
> > > you are 100% right. My point was to show that
> > > KeQueryPerformanceCounter would do no more harm as that dumb
> > > while-loop does anyhow. The thing is that I associate
> measuring time
> > > with KeQueryPerformanceCounter. Next thing I thought was: 'Oh,
> > > people might poll this within a while-loop. Ah, that is
> it, what MS
> > > does not want to be done with this function."
> > > -----------------------------------------------------------------
> > > | Norbert Kawulski |
> mailto:xxxxx@stollmann.de |
> > > | Stollmann T.P.GmbH, Development |
> http://www.stollmann.de |
> > > --If it’s ISDN or Bluetooth, make sure it’s driven by Stollmann–
> > >
> > > “All that glitters has a high refractive index.”
> > >
> > >
> > > > While certainly less intrusive than polling at
> DISPATCH_LEVEL or
> > > > in an
> ISR,
> > > > running such a loop at PASSIVE_LEVEL does indeed prevent any
> > > > threads
> with
> > > > lesser priority from running, and takes time away from other
> > > > threads
> of the
> > > > same priority that may have useful work to do. The CPU usage
> > > > would
> also be
> > > > pegged at 100%.
> > >
> > > > Additionally, using such a loop at PASSIVE_LEVEL is unlikely to
> consistantly
> > > > result in much better resolution than using
> > > > KeDelayExecutionThread().
> The
> > > > scheduler’s still going to run those other
> same-or-higher priority
> threads
> > > > in the system, which very well might be running at t+5000l. The
> result
> > > > would be that the while() condition check may not execute again
> > > > until
> after
> > > > the other thread(s) run.
> > >
> > > > -Tim
> > >
> > > > Timothy A. Johns — xxxxx@driverdev.com
> > > > Driver Development Corporation — 800.841.0092
> > > > Bring Up Your Hardware — Fast. www.driverdev.com
> > > ------- cut------------------
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as:
> > > xxxxx@sdtm.online.sh.cn To unsubscribe send a blank email to
> > > leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> b>
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
</http:></http:>

I also don’t recall but RDTSC instruction can be used directly. All Pentium
processors should have it and it isn’t privileged instruction (IMHO). I’m
not sure about AMD processors; CPUID instruction can be used to check
processor type.

There is a problem with frequency value which can be read from registry
(somewhere in the HARDWARE hive) or ignored when only unique timestamp is
necessary.

Best regards,

Michal Vodicka
Veridicom
(RKK - Skytale)
[WWW: http://www.veridicom.com , http://www.skytale.com]


From: Thomas F. Divine[SMTP:xxxxx@pcausa.com]
Reply To: NT Developers Interest List
Sent: Wednesday, June 27, 2001 4:24 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

I don’t recall if there is a Win32 clone.

In my drivers I define an IOCTL to fetch a structure containing two
values:
1.) the current value returned from KeQueryPerformanceCounter and 2.) the
frequency value. These values can be used to synchronize time and to scale
time.

There may be a better way…

Regards,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:
>
>
> ----- Original Message -----
> From: “Chen Miaobo”
> To: “NT Developers Interest List”
> Sent: Tuesday, June 26, 2001 9:47 PM
> Subject: [ntdev] Re: Clock resolution on a PC and WinNT
>
>
> > Does this KeQueryPerformanceCounter function have its Win32 API clone?
> >
> > Regards,
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

As I saw the word ‘synchronize’ I thought I’d jump in with a warning, in
case anyone is about to use the performance counter on MPS systems or rdtsc
instruction directly to get the clock time with a better resolution than
the scheduler’s 10-15 millis.

The basic idea is that you synchronize the system time to a specific
counter value and then use the counter to get time stamps with better
resolution (note: we’re talking clock timestamps here, like
‘12:23:34.12345’). Some things you’ll have to be aware of:

* You’ll have to synchronize the counter value to the system time exactly
when it (the system time) changes to avoid a constant offset of +/- tick
period (this is obvious).

This is a simplified method on how to perform the synchronization:

* Get counter frequency using KeQueryPerformanceFrequency.
* Busy spin (at an elevated IRQL/thread priority) calling KeQuerySystemTime
until it changes.
* Get counter value using KeQueryPerformanceCounter.
* Store these values as your base for you calculations.

Once this is done, each time you need the clock time - use the elapsed
counter ticks since synchronization in combination with the frequency to
get the amount of millis/micros/whatever since the synchronization. Add
this to the base time at that point and you’ll have ‘continuously’ updated
clock time.

BUT: Note that the performance frequency reported is not entirely accurate.
On my system (dual PIII@550MHz) the error is ~8 ppm. This results in a
situation where the calculated time ‘drifts’ away from the real system
time, resulting in milliseconds offsets after some time. What ‘some time’
means is of course hardware dependent, in my case t’was something like
1ms/minute on a dual PII@400MHz.

I guess that there are ways of getting round this, a few suggestions:

* Periodically resynchronize (not too often, as busy spinning takes down
the overall performance of the system).
* Determine the frequency more accurately (could be done by a supporting
driver, or background thread, or service in UM that continously
measures/calibrates the CPU frequency).

I’ve tried both, but there are still some problems with the approaches. Not
mentioning the fact that someone might actually change the system time
after after/between synchronizations …

Disclaimer: My results are totally based on user-mode experiences, but
should hold in KM as well.

If anyone here has been doing the same stuff (and succeeded), please drop
me an direct e-mail in case you don’t want to post something to this list.

Regards,

Johan

On 06/26/01, ““Thomas F. Divine” ” wrote:
> I don’t recall if there is a Win32 clone.
>
> In my drivers I define an IOCTL to fetch a structure containing two value=
> s:
> 1.) the current value returned from KeQueryPerformanceCounter and 2.) the
> frequency value. These values can be used to synchronize time and to scal=
> e
> time.
>
> There may be a better way…
>
> Regards,
>
> Thomas F. Divine
>
> PCAUSA - Toolkits & Resources For Network Software Developers
> NDIS Protocol - NDIS Intermediate - TDI Client
> http: - http:
>
>
> ----- Original Message -----
> From: “Chen Miaobo”
> To: “NT Developers Interest List”
> Sent: Tuesday, June 26, 2001 9:47 PM
> Subject: [ntdev] Re: Clock resolution on a PC and WinNT
>
>
> > Does this KeQueryPerformanceCounter function have its Win32 API clone?
> >
> > Regards,
> >
> >
> > ----- Original Message -----
> > From: Norbert Kawulski
> > To: NT Developers Interest List
> > Sent: Tuesday, June 26, 2001 11:48 PM
> > Subject: [ntdev] Re: Clock resolution on a PC and WinNT
> >
> >
> > > Tim,
> > > you are 100% right. My point was to show that
> > > KeQueryPerformanceCounter would do no more harm as that dumb
> > > while-loop does anyhow. The thing is that I associate measuring time
> > > with KeQueryPerformanceCounter. Next thing I thought was: ‘Oh, people
> > > might poll this within a while-loop. Ah, that is it, what MS does not
> > > want to be done with this function."
> > > -----------------------------------------------------------------
> > > | Norbert Kawulski | mailto:xxxxx@stollmann.de |
> > > | Stollmann T.P.GmbH, Development | http://www.stollmann.de |
> > > --If it’s ISDN or Bluetooth, make sure it’s driven by Stollmann–
> > >
> > > “All that glitters has a high refractive index.”
> > >
> > >
> > > > While certainly less intrusive than polling at DISPATCH_LEVEL or in=
> an
> ISR,
> > > > running such a loop at PASSIVE_LEVEL does indeed prevent any thread=
> s
> with
> > > > lesser priority from running, and takes time away from other thread=
> s
> of the
> > > > same priority that may have useful work to do. The CPU usage would
> also be
> > > > pegged at 100%.
> > >
> > > > Additionally, using such a loop at PASSIVE_LEVEL is unlikely to
> consistantly
> > > > result in much better resolution than using KeDelayExecutionThread(=
> ).
> The
> > > > scheduler’s still going to run those other same-or-higher priority
> threads
> > > > in the system, which very well might be running at t+5000l. The
> result
> > > > would be that the while() condition check may not execute again unt=
> il
> after
> > > > the other thread(s) run.
> > >
> > > > -Tim
> > >
> > > > Timothy A. Johns — xxxxx@driverdev.com
> > > > Driver Development Corporation — 800.841.0092
> > > > Bring Up Your Hardware — Fast. www.driverdev.com
> > > ------- cut------------------
> > >
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as: xxxxx@sdtm.online.sh.c=
> n
> > > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> b> =BA=C6o=A2d=E8=BA{.n=C7+?=B7=ACzwZnV=A7’=E9sS[h.=E6=AFz{]z=FDy=E0=B9b=B2=DB=
> (=B2
> =B7(
>
>
> —
> You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
</http:></http:>

Hi,

I am using SoftICE 4.05(versus 4.0)on Windows NT 4.0 Checked Build,SP5.When I
CTRL-D into SoftICE, in SoftICE startup “manual” mode it is working fine but
for kayboard driver debugging i changed the SoftICE startup to “Boot” mode
than restart the syatem then I get a blank screen. I can CTRL-D out of SoftICE
and return to the OS.what should i do to get the display in “boot” mode ?
from where and how can i set the start value of softice.

With warm regards
Ajay Kumar

“Moreira, Alberto” wrote:
Hi, Ajay,

What version of SoftICE are you using ? I believe this has been fixed in
DriverStudio 2.0. You need to make sure, after changing the start values of
Softice, that the start value of SIWVID is set to 0.

Please let me know if this helps, if not, I’ll try to get a Sis6215 card and
do some more investigation.

Alberto.

-----Original Message-----
From: xxxxx@usa.net [mailto:xxxxx@usa.net]
Sent: Monday, June 25, 2001 8:59 PM
To: NT Developers Interest List
Subject: [ntdev] Query about SoftICE Debugger

Hello All,

I want to use SoftICE for debugging kernel mode keyboard devive driver.

i am facing a problem:->

On which display setting it would be visible.i am using Sis dispaly card
and Sis6215 driver.
Actually it is visible in SoftICE startup “manual” mode but as i changed it
to SoftICE startup “Boot” mode for debugging it became invisible.

can any one give some info abt above query…

Thanks and Regards
Ajay Kumar


You are currently subscribed to ntdev as: xxxxx@compuware.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@usa.net
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

>* You’ll have to synchronize the counter value… to the system time exactly

Is it possible to use the StallFactor from the Processor Control Region to
get a more accurate value? (This is what the KM KeStallExecutionProcessor
routine uses to achieve microsecond precision).

  • Avi

You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Could you expand on that a bit?

// Johan

-----Original Message-----
From: Avi Shmidman [mailto:xxxxx@excalibur.co.il]
Sent: den 27 juni 2001 11:24
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

>* You’ll have to synchronize the counter value… to the
system time exactly

Is it possible to use the StallFactor from the Processor
Control Region to
get a more accurate value? (This is what the KM
KeStallExecutionProcessor
routine uses to achieve microsecond precision).

  • Avi

You are currently subscribed to ntdev as: xxxxx@esrange.ssc.se
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com