sched_setaffinity on x64
set and get a thread's CPU affinity mask
sys_sched_setaffinity(pid_t pid, unsigned int len, unsigned long *user_mask_ptr)
| number | 203 (0xcb) |
|---|---|
| abi | common |
| entry point | sys_sched_setaffinity |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | sched_setaffinity(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 203, the syscall number |
rdi | pid_t pid |
rsi | unsigned int len |
rdx | unsigned long *user_mask_ptr |
rax | the return value |
Then run syscall to enter the kernel.
The syscall instruction clobbers rcx (the return address lands in rcx) and r11 (the flags land in r11).
Since Linux 5.14 the kernel reads the syscall number from eax and ignores the upper 32 bits of rax. Older kernels fail with ENOSYS when those bits are not zero, and mov eax, N clears them, so it works on both.
Same syscall on other architectures
- x86 241
- arm64 122
- arm 241
- riscv64 122
- ia32 241
- x32 1073742027
- loongarch64 122
- ppc64 222
- ppc 222
- s390x 239
- mips64 5195
- mipsn32 6195
- mipso32 4239
- alpha 395
- arc 122
- blackfin 241, removed in 4.17
- cris 241, removed in 4.17
- csky 122
- frv 241, removed in 4.17
- hexagon 122
- ia64 1231, removed in 6.7
- m32r 241, removed in 4.17
- m68k 311
- metag 122, removed in 4.17
- microblaze 241
- mn10300 241, removed in 4.17
- nds32 122, removed in 5.18
- nios2 122
- openrisc 122
- parisc 211
- score 122, removed in 4.17
- sh 241
- sparc 261
- sparc64 261
- tilegx 122, removed in 4.17
- tilepro 122, removed in 4.17
- xtensa 156
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/sched_setaffinity