Affinity Mask
   HOME

TheInfoList



OR:

An affinity mask is a
bit mask In computer science, a mask or bitmask is data that is used for bitwise operations, particularly in a bit field. Using a mask, multiple bits in a byte, nibble, Word (computer architecture), word, etc. can be set either on or off, or inverted fro ...
indicating what processor(s) a thread or
process A process is a series or set of activities that interact to produce a result; it may occur once-only or be recurrent or periodic. Things called a process include: Business and management *Business process, activities that produce a specific se ...
should be run on by the
scheduler A schedule or a timetable, as a basic time-management tool, consists of a list of times at which possible tasks, events, or actions are intended to take place, or of a sequence of events in the chronological order in which such things are i ...
of an
operating system An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs. Time-sharing operating systems schedule tasks for efficient use of the system and may also i ...
. Setting the affinity mask for certain processes running under Windows can be useful as there are several system processes (especially on domain controllers) that are restricted to the first CPU / Core. So, excluding the first CPU might lead to better application performance.


Windows API

Thread affinity in Microsoft Windows can be specified with the ''SetThreadAffinityMask'' function. Forcing of each
OpenMP OpenMP (Open Multi-Processing) is an application programming interface (API) that supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran, on many platforms, instruction-set architectures and operating syst ...
thread to distinctive cores in Windows can be accomplished by means of the following C code: #include #include // Set OpenMP thread affinity void set_thread_affinity ()


See also

*
Processor affinity Processor affinity, or CPU pinning or "cache affinity", enables the binding and unbinding of a process or a thread to a central processing unit (CPU) or a range of CPUs, so that the process or thread will execute only on the designated CPU or CPU ...


References


External links


MSDN article on SetThreadAffinityMask functionCPU Balancer, a free, open-source utility that distributes Windows XP processes uniformly over logical processors using the affinity mask
Job scheduling {{operating-system-stub