Specifying a Processor Affinity Bitmask

You specify processor affinity in the API functions through the use of processor affinity masks. A processor affinity mask is a 32-bit value in which each bit represents a processor and the bit number (0-based) is equal to the processor number (also 0-based). A bit set to 1 means that the corresponding processor is allowed to run the process or thread, 0 means that the processor is not available.

When there is more than one bit set in the affinity mask, the process or thread is allowed to run on more than one processor. In this latter case, the RTSS scheduler will select the ideal processor or, if an ideal processor has not been defined, the processor that corresponds to the least-significant bit in the affinity mask. (There is no consideration for dynamic load balancing. See RTX Uses a Static Affinity Model for more information.)

For example, in an 8-processor system, the lower 8 bits identify Processor 0 through Processor 7.

In a 32-processor system, bits 0 through 31 identify Processor 0 through Processor 31.

To set an affinity mask for Processors 3 and 7, you would set the bits as follows:

You create the bitmask by enabling the bits that correspond to your processors. For example, the following code snippet shows how to enable bits for Processors 7 and 3:

DWORD mask = (1<< 7) + (1<< 3);

The value of (1<< 7) is 10000000 while the value of (1<< 3) is 00001000, making the sum of these two values 10001000.

To specify a mask containing the current processor RTSS is running, call the function RtGetCurrentProcessorNumber and shift as follows:

DWORD mask = 1<< RtGetCurrentProcessorNumber();


See Also

IntervalZero.com | Support | Give Feedback