RE: Re[2]: Clock resolution on a PC and WinNT

Yes,

that’s one more problem. Also, I don’t know if power-saving features in
general could also get in the way.

However, if I could get a good, reliable way for using the rdtsc for getting
high-resolution clock times when running my monitoring and control software
within a controlled environment - I would be reasonably happy. Notebooks,
and other fluff like that, I could live without having support for.

// Johan

-----Original Message-----
From: Norbert Kawulski [mailto:xxxxx@stollmann.de]
Sent: den 27 juni 2001 12:04
To: NT Developers Interest List
Subject: [ntdev] Re[2]: Clock resolution on a PC and WinNT

Johan,
I think on mobile systems like notebooks there are influences from
‘speed-step’ technologies that will give you very unreliable results
in using RDTSC. On these systems the clock rate seems to vary over
time.

| 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–

“I’m not as innocent as I look”

> 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: xxxxx@stollmann.de
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


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

At 04:43 AM 6/27/01 +0200, you wrote:

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.

The original K6 and Cyrix did not have it, but when they added MMX they
also implemented RDTSC, among other instructions.

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


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 RDTSC is normally not a privledged instruction. However the TSD
flag of CR4 can make it priveledged. However in Windows 95 thru
2000SP1 it is available for ring3 usage. I can only assume this hasn’t
changed.

I’ve had no problem with RDTSC on any of the AMD’s where I’ve been profiling with this
instruction.

Regards,
Anders

Tuesday, June 26, 2001, 6:43:18 PM, you wrote:

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

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

MV> Best regards,

MV> Michal Vodicka
MV> Veridicom
MV> (RKK - Skytale)
MV> [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,
>>

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


Best regards,
Anders mailto:xxxxx@flaffer.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:>

> 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,

KeQueryPerformanceCounter?

Max


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

There is a Win32 API equivalent.
Here is how I use it.

//+++++++++++++++++++

LARGE_INTEGER tStart, tStop;
LARGE_INTEGER Freq = m_PerfFreq;
int Oht = m_OverheadTicks;

SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
QueryPerformanceCounter(&tStart);
#ifdef __NO_VTBL
//call the actual function being timed. Don;t use VTBL to
dereference.
#else
//call the actual function being timed. Use VTBL to dereference.
#endif
QueryPerformanceCounter(&tStop);
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
//+++++++++++++++++++

However on a 32 bit machine you would have to write code to lose the 64
bit


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

Have you tried NdisGetCurrentSystemTime ??
It has a 100-nanosecond granularity.

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

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

I hate to break the news to everyone, but just because the Operating
System has the possibility to keep time in 100nsec increments, that
does NOT mean the closk resolution is that fine. I believe that PCs
have clocks that interrupt every 1 millisecond (at least as WinNT
sets them).

The clock tick count is the minimum true resolution that can be
used. I suspect that some systems have clock rates that are settable
to something less that 1msec, and that an industrious system programmer
could change the resolution. The issue of clock resolution has to do
with whether or not you want to service that number of interrupts required.

I am sure you could buy a clock board that can interrupt faster than
every 1msec and write a driver to service those requests if you have
such a need.

just my opinion, Rick Cadruvi…

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@nai.com
Sent: Wednesday, June 27, 2001 8:56 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Clock resolution on a PC and WinNT

Have you tried NdisGetCurrentSystemTime ??
It has a 100-nanosecond granularity.

>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

You are currently subscribed to ntdev as: xxxxx@rdperf.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

> Could you expand on that a bit?
> Johan

The KeStallExecutionProcessor() routine takes a parameter in terms of
microseconds, and implements it by looping for the number of times
specified by a value it retrieves. This value, of course, differs from
machine to machine, depending on their speed. The value seems to be stored
inside the Processor Control Region. Based on this value, then, we may be
able to get an accurate count of the number of cycles per microsecond on a
given machine.

However, now that I think about it, the usefulness of this value is
limited; basically, it just gives us the speed of the machine. And it
would not be able to help us with your goal of synchronizing the clock.

  • 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