Processor Scheduling on Windows NT

In order to understand how processors are used in Windows NT you need to understand how they are scheduled. This is typical of what we will find throughout this book: we need to know how the system works and how it is measured to properly interpret the data. Otherwise, we're just guessing. Let's avoid that, it's what our boss does!

Windows NT schedules processors using symmetric multiprocessing with soft affinity and preemptive multitasking. What a mouthful! Read on to find out what it means.

Let's look first at a single-processor computer, which is scheduled by preemptive multitasking. This means that the highest priority thread that is ready to run will execute processor instructions. If another thread is waiting, what happens depends on its priority. If it is a lower priority than the executing thread, it will mostly wait, only occasionally getting processor time to prevent total starvation. If it has the same priority as the executing thread, the two will share the processor. The system will periodically switch from one thread to the other in order to let them both have processor access.

Priorities are assigned at two levels. The process is assigned a priority class based on how the user starts and interacts with it. Then, within the process's priority class, its threads are assigned priorities that can change depending on requests by the thread itself, or because of interactions with peripherals or with the user. When the thread uses the processor, its priority is lowered; when it accesses peripherals, it is raised, and when it accesses such peripherals as the keyboard it is boosted even more. But to gain this boost, peripheral access must be through direct communication with Windows NT Executive. Windows applications are treated somewhat differently, as described shortly.

If a computer has multiple processors, a ready thread can run on any of them. The system attempts to run a thread on the same processor it last ran on, all other things being equal. (This is soft affinity.) This helps reuse data left in the processor's memory caches from the previous execution of the thread. A thread could be restricted to run on only certain processors, but this is uncommon.

Most applications started by users during system operation run in the Normal Priority class. When a user is interacting with an application using the keyboard and mouse, that application is in the foreground. The foreground application processes get an elevated base priority of nine instead of the level eight assigned to other Normal Priority class processes. (A higher number has higher priority.) When an application relinquishes the foreground, it becomes a background process and is given a base priority of seven.

What all this means is that when the foreground application uses the processor heavily, it can lock out all lower priority processes from execution. Because responding quickly to the user is usually the goal of the system, this is the chosen default for Windows NT operation. If you want to alter this behavior, choose the Tasking button in the System option in Control Panel. The setting of Best Foreground Application Response Time is the default. If you change this to Foreground Application More Responsive Than Background, foreground processes will be given a priority of eight. Setting this to Foreground And Background Applications Equally Responsive assures that both foreground and background processes get priority level seven.

The following table lists all possible thread priorities.

Table 3.1 Thread Priorities in Windows NT

Base

Priority class

Thread priority

31

Real-time

THREAD_PRIORITY_TIME_CRITICAL

26

Real-time

THREAD_PRIORITY_HIGHEST

25

Real-time

THREAD_PRIORITY_ABOVE_NORMAL

24

Real-time

THREAD_PRIORITY_NORMAL

23

Real-time

THREAD_PRIORITY_BELOW_NORMAL

22

Real-time

THREAD_PRIORITY_LOWEST

16

Real-time

THREAD_PRIORITY_IDLE

15

Idle, Normal, or High

THREAD_PRIORITY_TIME_CRITICAL

15

High

THREAD_PRIORITY_HIGHEST

14

High

THREAD_PRIORITY_ABOVE_NORMAL

13

High

THREAD_PRIORITY_NORMAL

12

High

THREAD_PRIORITY_BELOW_NORMAL

11

High

THREAD_PRIORITY_LOWEST

11

Foreground normal

THREAD_PRIORITY_HIGHEST

10

Foreground normal

THREAD_PRIORITY_ABOVE_NORMAL

9

Foreground normal

THREAD_PRIORITY_NORMAL

9

Background normal

THREAD_PRIORITY_HIGHEST

8

Foreground normal

THREAD_PRIORITY_BELOW_NORMAL

8

Background normal

THREAD_PRIORITY_ABOVE_NORMAL

7

Foreground normal

THREAD_PRIORITY_LOWEST

7

Background normal

THREAD_PRIORITY_NORMAL

6

Background normal

THREAD_PRIORITY_BELOW_NORMAL

6

Idle

THREAD_PRIORITY_HIGHEST

5

Background normal

THREAD_PRIORITY_LOWEST

5

Idle

THREAD_PRIORITY_ABOVE_NORMAL

4

Idle

THREAD_PRIORITY_NORMAL

3

Idle

THREAD_PRIORITY_BELOW_NORMAL

2

Idle

THREAD_PRIORITY_LOWEST

1

Idle, Normal, or High

THREAD_PRIORITY_IDLE

|