{
  "id": "enwiki-001361988637",
  "slug": "processor-affinity",
  "title": "Processor affinity",
  "qid": "",
  "lead": "In computer science, processor affinity, also called 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 CPUs rather than any CPU. This can be viewed as a modification of the native central queue scheduling algorithm in a symmetric multiprocessing operating system. Each item in the queue has a tag indicating its kin processor. At the time of resource allocation, each task is allocated to its kin processor in preference to others. Scheduling-algorithm implementations vary in adherence to processor affinity. Under certain circumstances, some implementations will allow a task to change to another processor if it results in higher efficiency. For example, when two processor-intensive tasks (A and B) have affinity to one processor while another processor remains unused, many schedulers will shift task B to the second processor in order to maximize processor use. Task B will then acquire affinity with the second processor, while task A will continue to have affinity with the original processor. On most operating systems, the set of processors a process or thread is allowed (or preferred) to run on is expressed as an affinity mask, which is a bit mask corresponding to the system's cores.",
  "body": "In computer science, processor affinity, also called 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 CPUs rather than any CPU. This can be viewed as a modification of the native central queue scheduling algorithm in a symmetric multiprocessing operating system. Each item in the queue has a tag indicating its kin processor. At the time of resource allocation, each task is allocated to its kin processor in preference to others. Scheduling-algorithm implementations vary in adherence to processor affinity. Under certain circumstances, some implementations will allow a task to change to another processor if it results in higher efficiency. For example, when two processor-intensive tasks (A and B) have affinity to one processor while another processor remains unused, many schedulers will shift task B to the second processor in order to maximize processor use. Task B will then acquire affinity with the second processor, while task A will continue to have affinity with the original processor. On most operating systems, the set of processors a process or thread is allowed (or preferred) to run on is expressed as an affinity mask, which is a bit mask corresponding to the system's cores. ==Specific operating systems== On SGI systems, dplace binds a process to a set of CPUs. On NetBSD 5.0, FreeBSD 7.2, DragonFly BSD 4.7 and later versions can use pthread_setaffinity_np and pthread_getaffinity_np . In NetBSD, the psrset utility to set a thread's affinity to a certain CPU set. In FreeBSD, cpuset utility is used to create CPU sets and to assign processes to these sets. On DragonFly BSD 1.9 (2007) and later versions, usched_set system call can be used to control the affinity of a process. In DragonFly BSD 3.1 (2012) and later, usched utility can be used for assigning processes to a certain CPU set. On Solaris it is possible to control bindings of processes and LWPs to processor using the pbind(1) program. To control the affinity programmatically processor_bind(2) can be used. There are more generic interfaces available such as pset_bind(2) or lgrp_affinity_get(3LGRP) using processor set and locality groups concepts. On AIX it is possible to control bindings of processes using the bindprocessor command and the bindprocessor() API. The AIX scheduler is SMT-aware and is able to switch the SMT states of the POWER7/8/9 cores from 1 to 8 threads to maximize throughput. include include // Set OpenMP thread affinity void setThreadAffinity(void) { #pragma omp parallel default(shared) { DWORD_PTR mask = (DWORD_PTR)1",
  "categories": [
    "22914317",
    "23118434",
    "23603337",
    "24043274",
    "24623845",
    "35148843",
    "71603924",
    "89880229"
  ],
  "license": "CC BY-SA 4.0",
  "source_uri": "https://en.wikipedia.org/w/index.php?oldid=1361988637",
  "content_hash": "",
  "created_at": null,
  "updated_at": 1782883952.0,
  "claims": [],
  "contradictions": [],
  "confidence": 0.6,
  "csl": {
    "id": "enwiki-001361988637",
    "type": "webpage",
    "title": "Processor affinity",
    "author": [
      {
        "family": "Anticloud FZ LLE",
        "literal": "Anticloud FZ LLE"
      }
    ],
    "container-title": "encyclopegia.org",
    "publisher": "Anticloud FZ LLE",
    "publisher-place": "Dubai, United Arab Emirates",
    "URL": "https://encyclopegia.org/a/processor-affinity",
    "issued": {
      "date-parts": [
        [
          2026,
          11,
          18
        ]
      ]
    },
    "accessed": {
      "date-parts": [
        [
          2026,
          11,
          18
        ]
      ]
    },
    "license": "CC BY-SA 4.0",
    "DOI": "eo1:enwiki-001361988637",
    "isBasedOn": "https://en.wikipedia.org/w/index.php?oldid=1361988637",
    "note": "Immutable snapshot enwiki-001361988637"
  }
}