This question is about possibility of tweaking windows kernel towards real-time like oses, and ways of doing it. It is quite specific narrow topic that requires deep level of knowledge - you either know, either not.

I am on WS2016 x64 platform, and I can set timer resolution only to 500us (0.5ms), calling NtSetTimerResolution() function within ntdll.dll library. I guess that value is tied to sheduler timeslice.

However, I want to increase it to 100us. Measuring could involve calling NtDelayExecution() wrapped in QueryPerformanceCounter() calls many times within loop and then analysing statistics like jitter, std deviation, so on.

How is this supposed to do? Is there any registry/file tweak, where i can set arbiraty windows sheduler timeslice?

PS. Some people may ask "Why do you need it?", or state "Dont do it, its wrong!". I forsee that kind of thoughts and would answer ahead.

  • This is just software Experiment. It is just for testing possibility and physical results of doing it.
  • I am aware that it can lead to potential problems, like extra cpu time wasted just on context switches, system unstability, unresponsibility, data loss and whatever problems it could cause. I accept any negative consequences of doing it in advance and taking all responsibility. Even if smoke and sparkles would come out of my machine :)
  • As per googling or searching in here - ofc i alredy did it, and failed to find useful information, because this topic is quite narrow, relating to OS shedulers functioning. And almost pointless to do on any windows-machine. I know i can not turn it to real time. This site search "sheduler timeslice" gives no result.

The scheduler timeslice interval is not directly influenced by the timer resolution. For most processes on the client SKUs it is 20 msec; for a process that owns the foreground window, it is 60 msec. These values are normally both 120 msec on Server SKUs.

These values are the same regardless of what you do with NtSetTimerResolution. Whatever the timer resolution, an appropriate number of timer clock interrupts are counted before a 20 msec interval is detected and the scheduler decrements the "quantum" counter of the current thread, etc.

Thus, if you do manage to improve the timer resolution to 100 usec, it won't affect thread scheduling. It will however create additional overhead, what with 5x the previous number of calls to the routine that checks to see if any timers have expired.

There is no registry or other tweak to change this.

There is a registry hack that can be used to defeat the "timeslice stretch" that occurs on client SKUs, or to make a Server system behave like a client or vice versa as far as timeslice length is concerned. And sometimes (due to a little twiddling of Thread->Quantum that's done when a thread comes out of a wait) the timeslice may be a little shorter than it "should" have been. But there's no way to set the timeslice to less than 20 msec, or to anything but a multiple of 20 msec, and not many different multiples are available.

Note that the scheduler timeslice interval has no effect on preemption. When a thread's wait is resolved, if the thread's priority is higher than that of the currently-running thread on the new thread's ideal processor, the latter thread is preempted immediately. It doesn't get to run to the end of its timeslice before being prempted. Timeslices are only important when there are multiple threads competing at the same priority.

Source: Most of this is in Windows Internals by Solomon, Russinovich, et al.

| improve this answer | |
  • Even via hex-editing some binaries, if it accidently was compiled as a constant somewhere inside windows kernel? Then in becomes a question of finding 4 or 8 bytes and tweaking it. This cannot be impossible, because in is not hardware issue, but a software one. And it is definetely some kind of OS tweak, despite it may be not directly exposed through registry. Where should i start the search? – xakepp35 May 27 '18 at 10:54
  • as far as i can see in reactos source code (best guess we have from source opened) NtQueryTimerResolution() just returns some integers which are changed in KeSetTimeIncrement() function – xakepp35 May 27 '18 at 11:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.