Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


July 1997

Inside the Windows NT Scheduler, Part 1


RSS
Subscribe to Windows IT Pro | See More Internals and Architecture Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Boosting and Decay
The picture I've presented so far is of a fairly static system: Threads execute at a priority level until a program changes their priorities or they exit. What actually happens is more dynamic: In a variety of situations, NT boosts (or increases) the priority of dynamic range threads. The most common boost occurs when an event happens that a blocked thread was waiting for. For example, a thread waiting for input from the keyboard increases six priority levels (a 6-point boost) when a keystroke wakes it up. Other increases include a 6-point boost for mouse events and a 1-point boost when a thread wakes up from a wait on a general event.

Boosting applies to only dynamic range threads. The system never changes the priority of a realtime thread--only a program can change a realtime priority. In addition, a boost never causes a thread's priority to move into the realtime range; priority level 15 is the upper limit for boosts. Event-related boosts are temporary because the boost decays over time. Each time a thread runs through an entire quantum, its boost decreases by 1 point. This decay continues until the thread reaches its programmed priority level (the priority it had before its first boost).

NT's boosting logic lets the system boost a thread repeatedly before its priority has decayed to its base priority. Thus, a priority 8 thread that receives keyboard input gets boosted to priority 14. If the thread completes a quantum, its priority decays to 13. If the thread waits for and receives another keyboard event, its priority gets boosted to the 15 limit.

Another type of boost NT Workstation applies is a foreground application boost, which you can control from the Performance tab of the System applet in Control Panel (shown in Screen 1). This type of boost affects quantum length, rather than priority. For the default Maximum setting, NT extends the quantums of foreground application threads to 60ms. If you position the slider in the middle, NT sets the quantums to 40ms. If you position the slider on None, the quantums are 20ms--the same as the quantums of background application threads.

Starvation Prevention
Left alone, the FindReadyThread and ReadyThread might prevent low-priority threads from getting a chance to execute. For example, a priority 4 thread running on a system with continuously running priority 8 threads would be starved for CPU time. However, NT provides a mechanism that gives low-priority threads a shot at the CPU. The NT Balance Set Manager is a system thread that wakes up every second or so to perform memory tuning. As a secondary responsibility, Balance Set Manager executes the ScanReadyQueues algorithm, which implements NT's anti-CPU starvation policy.

ScanReadyQueues scans the Dispatcher Ready List, working down the list from priority 31. It looks for threads that haven't executed in more than 3 seconds. When it finds one, ScanReadyQueues gives the thread a special anti-starvation boost, doubles its quantum, and calls ReadyThread with the thread as a parameter. The anti-starvation boost differs from other boosts: Instead of applying a relative priority increment, the anti-starvation boost slams the thread's priority to the top of the dynamic range. (On pre-Service Pack 2--SP2--systems, the anti-starvation boost was to priority 14; post-SP2 systems boost to priority 15). When a thread that receives an anti-starvation boost finishes its extended quantum (or the thread blocks), its priority returns to the pre-starvation boost level and its quantum returns to its usual length.

Next Month
Scheduling in a uniprocessor environment is relatively straightforward, but factors within a multiprocessor environment complicate how FindReadyThread and ReadyThread work. For example, NT lets applications define threads to execute on only certain CPUs, and NT tries to keep threads running on the same CPU for performance benefits. Next month, I'll describe the multiprocessor implementations of FindReadyThread and ReadyThread. These algorithms are complex--so complex that you might argue that a better way must exist for scheduling in a multiprocessor environment. Stay tuned.

End of Article

   Previous  1  [2]  Next  


Reader Comments
its very usefull thanks. the info you have provide help my research

marilou flroresca March 18, 2000


very good and helpful.

Maybe also in this article to be added following sentences from other articles by Dr. Mark Russinovich:

"When a thread's quantum is over, or if the thread cedes its turn early, the scheduler schedules other threads of the same priority (if any exist) in a round-robin manner. "

"A defining aspect of the NT and VMS schedulers is that they never lower a process' priority below the priority level the application programmed."

Or maybe i did not read exactly enough?
Best Regards

oliver frager May 06, 2000


The article was really good and attended to the important issues in process creation and scheduling in a concise manner. As I encountered this page while searching for such material in google, I dont hv link to other articles. If possible pls. give the links to any other related articles.

Sujit Vettiyatil March 29, 2004


Does the linux kernel implement better scheduling algorithms than NT?

Anonymous User April 19, 2005 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Related Articles Inside the Windows NT Scheduler, Part 2

Related Events Windows Internals with Sysinternals Webinar

Deep Dive into Windows Server 2008 R2 presented by John Savill

Check out our list of Free Email Newsletters!

Windows OSs eBooks Understanding and Leveraging Code Signing Technologies

A Guide to Windows Certification and Public Keys

SQL Server Administration for Oracle DBAs

Related Windows OSs Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement