milli/micro/nano seconds to cpu ticks conversion

Hi to all.

—>I am porting one driver from linux to windows.we are using KMDF.Like “msecs_to_jiffies” in linux, in windows how can i convert milli seconds to cpu clock ticks.
—>I googled and i found “KeQueryPerformanceCounter” instruction.
—>What is Performence counter?
—>How can i use this instruction to meet my requirement?

Please give me a solution.

xxxxx@industeqsite.com wrote:

—>I am porting one driver from linux to windows.we are using KMDF.Like “msecs_to_jiffies” in linux, in windows how can i convert milli seconds to cpu clock ticks.
—>I googled and i found “KeQueryPerformanceCounter” instruction.
—>What is Performence counter?
—>How can i use this instruction to meet my requirement?

That’s not a requirement, that’s an implementation detail.  Why do you
need the time in “jiffies”?  What is the actual requirement?  In almost
every case, you want to go the other direction – you have a
CPU-specific time period, and you want the value in microseconds or
milliseconds.  Hardware devices NEVER work in “jiffies”.

You should also understand that the Linux “jiffy” is not “CPU ticks”. 
It is the time between timer interrupts, typically a value between 1ms
and 10ms.  Windows has a similar range, from 1ms to 16ms.

The exact source of KeQueryPerformanceCounter depends on the hardware
and the operating system version.  In olden days, it was based on the
motherboard countdown timer, which was also used to generate the timer
interrupt.  Later, it came from the High-Precision Event Timer (HPET). 
These days, it is commonly derived from the CPU cycle counters. 
KeQueryPerformanceCounter also returns to you the frequency of the
counter, so you can derive meaningful time from the value.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

> in windows how can i convert milli seconds to cpu clock ticks.

Converting is easy. The time unit in Windows is always 100 nano seconds so 1 ms is 10000 in these units. This can be used to specify delays, like in KeSetTimer, KeWaitForSingleObject, KeDelayExecutionThread etc. Remember only to use *negative* values for relative time!

Usually you don’t need to express time in ticks. But if you want to, you can get the tick value with ExQueryTimerResolution.

I googled and i found “KeQueryPerformanceCounter” instruction.

KeQueryPerformanceCounter - as its documentation says - is used to “acquire high resolution … time stamps for time interval measurements”. If this is what you need, use it.

Good luck.
– pa

xxxxx@fastmail.fm wrote:

> in windows how can i convert milli seconds to cpu clock ticks.
Converting is easy. The time unit in Windows is always 100 nano seconds so 1 ms is 10000 in these units.

EXCEPT, of course, for KeQueryPerformanceCounter, which is the direction
our poster is going.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.