Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results
The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.
Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/
is there way to make delay function that faster then KeDelayExecutionThread?
thats what im using right now
waitTime.QuadPart = -10000000; // 1 second
KeDelayExecutionThread(KernelMode, FALSE, &waitTime);
KeStallExecutionProcessor slow in my end
im thinking loop with rdtsc but i dont know how to convert it to x64 reading it through masm x64 its causing bsod
__declspec(naked) __forceinline void __fastcall Delay(unsigned int TicksC)
{
__asm
{
rdtsc
mov esi, eax
_loop:
rdtsc
sub eax, esi
cmp eax, ecx
jbe _loop
ret
}
}
Upcoming OSR Seminars | ||
---|---|---|
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead! | ||
Kernel Debugging | 13-17 May 2024 | Live, Online |
Developing Minifilters | 1-5 Apr 2024 | Live, Online |
Internals & Software Drivers | 11-15 Mar 2024 | Live, Online |
Writing WDF Drivers | 26 Feb - 1 Mar 2024 | Live, Online |
Comments
Can you elaborate on what your intentions are? What do you mean by "faster"?
im reading the rdtsc as main system clock so i need very good sleep function that have extreme nanoseconds KeDelayExecutionThread is the fastest on kernel ?
It's still unclear what you're trying to do.
rdtsc isn't a system clock. It's an instruction that returns the processor time stamp as a number of clock cycles since the last reset.
Are you trying to sleep for exactly one second so you can see how many tick counts there are for the processor in one second?
What's an extreme nanosecond?
When you ask "is KeDelayExecutionThread() the fastest on kernel" are you wanting to know if it's return from delay is deterministic? It's hard to offer a recommendation without knowing more about what you're trying to do. I'm assuming you've found the documentation for KeDelayExecutionThread which clearly states accuracy of expiration times are limited by the granularity of the system clock.
so rdtsc can be used as source of time
i found out KeDelayExecutionThread return to 100ns its still not fast enough then rdtsc loop i will try to found a way thanks for help !
Best of luck. You may find the following information about high resolution time stamps helpful in your quest.
https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps#direct-tsc-usage
thank you very much ZwYieldExecution fixed it
For the sake of clarity, ZwYieldExecution is not a function that delays thread execution in the same way as KeDelayExecutionThread or KeStallExecutionProcessor. KeDelayExecutionThread is like UM Sleep and interacts with the scheduler to make this thread non-runnable for at least the time requested. KeStallExecutionProcessor runs a busy loop for approximately the time requested using a hardware specific algorithm.
ZwYieldExecution interacts with the scheduler and might initiate a context switch if there is another thread ready to run. This is like the UM Sleep(0).
Possibly the OP is avoiding a crash by using ZwYieldExecution to avoid a watchdog timer, but it is hard to know based on the lack of detail