Interrupt affinity
The affinity of an interrupt is the set of processors that can service the interrupt. Each device has an affinity policy. The operating system uses the affinity policy to compute the affinity for that device's interrupts. The affinity policy can be specified in the device's INF file or registry settings. Administrators can use the registry to set an affinity policy for an interrupt.
Administrators can set the following entries under the \Interrupt Management\Affinity Policy registry key:
DevicePolicy is a REG_DWORD value that specifies an affinity policy. For possible values and their meanings, see IRQ_DEVICE_POLICY. Microsoft recommends using the default policy if applicable.
AssignmentSetOverride can be a REG_BINARY, REG_DWORD, or REG_QWORD value that specifies a KAFFINITY mask. For REG_BINARY, size must be less than or equal to the KAFFINITY size for the platform, and input byte order is little endian. If DevicePolicy is 0x04 (IrqPolicySpecifiedProcessors), then this mask specifies a set of processors to assign the device's interrupts to.
A driver's INF file can provide default settings for the registry values. Here's an example of how to set the DevicePolicy value to IrqPolicyOneCloseProcessor in the INF file. For more information, see INF AddReg Directive.
[install-section-name.HW]
AddReg=add-registry-section
[add-registry-section]
HKR, "Interrupt Management\Affinity Policy", DevicePolicy, 0x00010001, 2
The system makes the registry settings available to the device's driver when it sends the IRP_MN_FILTER_RESOURCE_REQUIREMENTS IRP to the driver. The operating system provides an IO_RESOURCE_DESCRIPTOR structure for each interrupt with the Type member set to CmResourceTypeInterrupt. For a message-signaled interrupt, the CM_RESOURCE_INTERRUPT_MESSAGE bit of the Flags member is set; otherwise, it's clear. The u.Interrupt member describes the settings for the interrupt.
The following table gives the correspondence between registry settings and members of u.Interrupt.
Registry Value | Member of u.Interrupt |
---|---|
DevicePolicy | AffinityPolicy |
AssignmentSetOverride | TargetedProcessors |
About KAFFINITY
The KAFFINITY type is an affinity mask that represents a set of logical processors in a group.
typedef ULONG_PTR KAFFINITY;
The KAFFINITY type is 32 bits on a 32-bit version of Windows and is 64 bits on a 64-bit version of Windows.
If a group contains n logical processors, the processors are numbered from 0 to n-1. Processor number i in the group is represented by bit i in the affinity mask, where i is in the range 0 to n-1. Affinity mask bits that don't correspond to logical processors are always zero.
For example, if a KAFFINITY value identifies the active processors in a group, the mask bit for a processor is one if the processor is active, and is zero if the processor isn't active.
The number of bits in the affinity mask determines the maximum number of logical processors in a group. For a 64-bit version of Windows, the maximum number of processors per group is 64. For a 32-bit version of Windows, the maximum number of processors per group is 32. Call the KeQueryMaximumProcessorCountEx routine to obtain the maximum number of processors per group. This number depends on the hardware configuration of the multiprocessor system, but can never exceed the fixed 64-processor and 32-processor limits that are set by the 64-bit and 32-bit versions of Windows, respectively.
The GROUP_AFFINITY structure contains an affinity mask and a group number. The group number identifies the group to which the affinity mask applies.
Kernel routines that use the KAFFINITY type include IoConnectInterrupt, KeQueryActiveProcessorCount, and KeQueryActiveProcessors.