Analyzing Processor Activity

Examining thread context switching and thread state gives you information about when threads in a bottleneck are being scheduled to run by the operating system and when threads are being held in the queue prior to running. Although the operating system is designed to optimize the scheduling of threads, you have some control over this behavior because you can adjust for situations in which scheduling behavior on your system is unsatisfactory. This section describes how you can determine a threads scheduling priority and how you can adjust thread priority to reduce bottlenecks and allow blocked threads to run.



To ensure optimum performance on production systems, Microsoft recommends that you adjust priorities of processes first in a test environment. In addition, you should make these adjustments only if you have an in-depth understanding of priority settings and their effect on other processes and the operating system.

Priority Class and Priority

Under the preemptive multitasking strategy built into Windows 2000, threads and processes are assigned a priority for scheduling purposes. A threads priority determines the order in which it is scheduled to run on the processor.

A threads priority is based on the priority class of its parent process. The four process priority classes are:

Idle.    Screen savers and other processes that periodically update the display typically use the Idle class.

Normal.    The default priority class for a process is Normal.

High.    Processes that run in the High priority class receive the majority of processor time.

Real Time.    Many kernel-mode system processes, such as those that manage mouse and keyboard input and other device operations, run in the Real Time priority class.

Each processs priority class sets a range of priority values (between 1 and 31, where 1 is lowest and 31 is highest), and the threads of that process have a priority value that is within that range. (Priority 0 is reserved for system use.) If the priority class is Real Time (priorities 16 through 31), the threads priority cannot change while the thread is running. If you have at least one priority 31 thread running, other threads cannot run.

On the other hand, threads running in all other priority classes are variable, meaning that the threads priority can change while the thread is running. For threads in the Normal or High priority classes (priorities 1 through 15), the threads priority can be raised or lowered by up to a value of 2 but cannot fall below its original, program-defined base priority. When the base priority is adjusted to optimize scheduling, the resulting value is called the threads dynamic priority.

Table 29.4 associates each process priority class with relative thread priorities, ranked from highest priority to lowest. Notice that the highest priority class is Real Time and the lowest is Idle.

Table 29.4 Process Priority Classes with Relative Thread Priorities



Thread Priorities

Real Time




Time critical










Above normal










Below normal















Thread Scheduling

The scheduling routines of the operating system checks for the highest-priority thread that is in a ready state and runs it without interruption during a quantum . A quantum, also known as a time slice, is the maximum amount of time a thread can run before the system checks for another ready thread of the same priority to run. If a higher-priority thread becomes ready during the quantum, the lower-priority thread is interrupted and the higher-priority thread is run. Otherwise, threads with the same priority are scheduled to run in a round-robin fashion, and the operating system switches among those threads in order, allowing them to run until the quantum expires.

Windows 2000 always runs the highest-priority ready thread. However, there are optimization strategies built into the operating system to address situations in which the default scheduling methods would cause problems. The following sections describe these strategies.

Foreground Process Scheduling

The scheduler runs a foreground process at a higher priority, which means it tends to get more time slices than background processes. In addition, the scheduler ensures that those time slices are longer than the ones allocated to background processes. As a result, the foreground process is much more responsive than other processes because it runs more often, and it runs longer before being preempted. By default, Windows 2000 Professional defines short, variable time slices for applications and gives a foreground application a priority boost. On the other hand, Windows 2000 Server has longer, fixed time slices with no priority boost for foreground applications, allowing background services to run more efficiently. To see foreground process scheduling in action, monitor the processor time for a process and move its window to the bottom of the stack. Note that the time value allocated to that process falls immediately. Then move the process to the top of the stack and note that the processor time value rises immediately. See Figure 29.19 for an illustration.

Automatic Priority Boost

The operating system automatically boosts a threads priority until it is high enough for a low-priority thread to complete its operation and release the resource. After raising a threads dynamic priority, the scheduler reduces that priority by one level each time the thread completes a time slice (quantum), until the thread drops back to its base priority.