background image

Vol. 3A 8-51

MULTIPLE-PROCESSOR MANAGEMENT

8.10.6.4   Potential Usage of MONITOR/MWAIT in C1 Idle Loops

An operating system may also consider replacing HLT with MONITOR/MWAIT in its C1 idle loop. An example is 
shown in Example 8-26

Example 8-26.  An OS Idle Loop with MONITOR/MWAIT in the C1 Idle Loop

// WorkQueue is a memory location indicating there is a thread 
// ready to run.  A non-zero value for WorkQueue is assumed to
// indicate the presence of work to be scheduled on the processor.
// The following example assumes that the necessary padding has been 
// added surrounding WorkQueue to eliminate false wakeups
// The idle loop is entered with interrupts disabled.

WHILE (1) {

IF (WorkQueue) THEN {

// Schedule work at WorkQueue

ELSE {

// No work to do - wait in appropriate C-state handler depending 
// on Idle time accumulated
IF (IdleTime >= IdleTimeThreshhold) THEN {
// Call appropriate C1, C2, C3 state handler, C1 
// handler shown below
}

}

}

VOID C1Handler() 

{ MONITOR WorkQueue  // Setup of eax with WorkQueue LinearAddress, 

// ECX, EDX = 0

IF (WorkQueue ≠ 0) THEN {

STI
MWAIT

// EAX, ECX = 0

}

}

8.10.6.5   Guidelines for Scheduling Threads on Logical Processors Sharing Execution Resources

Because the logical processors, the order in which threads are dispatched to logical processors for execution can 
affect the overall efficiency of a system. The following guidelines are recommended for scheduling threads for 
execution.

Dispatch threads to one logical processor per processor core before dispatching threads to the other logical 
processor sharing execution resources in the same processor core. 

In an MP system with two or more physical packages, distribute threads out over all the physical processors, 
rather than concentrate them in one or two physical processors.

Use processor affinity to assign a thread to a specific processor core or package, depending on the cache-
sharing topology. The practice increases the chance that the processor’s caches will contain some of the 
thread’s code and data when it is dispatched for execution after being suspended. 

12. Excessive transitions into and out of the HALT state could also incur performance penalties. Operating systems should evaluate the 

performance trade-offs for their operating system.