Dear All,
How to delay microsecond(us) in KM?
In UM,I used QueryPerformanceFrequency and QueryPerformanceCounter.
In KM, I tried KeQueryPerformanceCounter,but I found this API returned value is like “1953222”,this value is like QueryPerformanceFrequency function returned.
And the value KeQueryPerformanceCounter is not changed,is always “1953222”.
Any help is appreciated.Thanks.
Best Regards
Zhou cj
Perhaps you are looking for KeStallExecutionProcessor.
Note that this does not suspend the thread, is spins at 100% cpu use in that thread. I see the page at http://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx has lots of interesting details about timing.
If you are seeing a performance clock frequency in the 2 Mhz range (like 1953222) that may be in indication your processor does not support an invariant TSC speed, so the system has to use some other timing source.
KeQueryPerformanceCounter has a return value of the count and a pointer parameter of the frequency. Are you calling it correctly?
Jan
On Sep 30, 2014, at 2:21 AM, > > wrote:
Dear All,
How to delay microsecond(us) in KM?
In UM,I used QueryPerformanceFrequency and QueryPerformanceCounter.
In KM, I tried KeQueryPerformanceCounter,but I found this API returned value is like “1953222”,this value is like QueryPerformanceFrequency function returned.
And the value KeQueryPerformanceCounter is not changed,is always “1953222”.
Any help is appreciated.Thanks.
Best Regards
Zhou cj
—
NTDEV is sponsored by OSR
Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
OSR is HIRING!! See http://www.osr.com/careers
For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
xxxxx@yahoo.com.cn wrote:
How to delay microsecond(us) in KM?
In UM,I used QueryPerformanceFrequency and QueryPerformanceCounter.
It is idiotic to try to delay on a microsecond level in user mode. You
can have a process switch at any time, and now your 5 microsecond switch
delays for 10 milliseconds.
In KM, I tried KeQueryPerformanceCounter,but I found this API returned value is like “1953222”,this value is like QueryPerformanceFrequency function returned.
And the value KeQueryPerformanceCounter is not changed,is always “1953222”.
Have you read the documentation at all, or did you just assume it was
identical to the user-mode API? KeQueryPerformanceCounter returns TWO
values. The LARGE_INTEGER you pass as a parameter is, in fact, filled
in with the current frequency. The counter value is returned as the
return value of the function. If all you want is the counter, do this:
LARGE_INTEGER liTime = KeQueryPerformanceCounter(nullptr);
However, as Jan pointed out, the right way to delay for small integer
microseconds is to use KeStallExecutionProcessor, which waits in a tight
loop. If you have to wait any more than that, use
KeDelayExecutionThread, which releases the CPU.
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.
On 9/30/2014 12:22 PM, Tim Roberts wrote:
xxxxx@yahoo.com.cn wrote:
> How to delay microsecond(us) in KM?
> In UM,I used QueryPerformanceFrequency and QueryPerformanceCounter.
It is idiotic to try to delay on a microsecond level in user mode. You
can have a process switch at any time, and now your 5 microsecond switch
delays for 10 milliseconds.
I have actually had cases, in user mode, writing
test/diagnostic/bring-up code for new hardware, where I needed to delay
a *minimum* of X microseconds between operations (due to hardware
vagaries, or as I liked to call them, “bugs”).
However, as you point out, it was always understood that the delay was
non-deterministic, and could in fact be longer (by many orders of
magnitude).
But not, I hope, a totally idiotic thing to do 
– mkj
//
// Michael K. Jones
// Stone Hill Consulting, LLC
// http://www.stonehill.com
//_______________________________________________
Use KeDelayExecutionThread to suspend the current thread. If the delay is a negative number, then it is expressed in 100 nanoseconds units or 0.1 microseconds units. So if you set thecdelay to -10 000, the thread will sleep 1 millisecond.
LARGE_INTEGER Delay;
Delay.QuadPart = -10000i64; // One millisecond
KeDelayExecutionThread(&Delay);
Look at tha API documentation.