getcpu on x64
determine CPU and NUMA node on which the calling thread is running
sys_getcpu(unsigned *cpup, unsigned *nodep, void *unused)
| number | 309 (0x135) |
|---|---|
| abi | common |
| entry point | sys_getcpu |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | getcpu(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 309, the syscall number |
rdi | unsigned *cpup |
rsi | unsigned *nodep |
rdx | void *unused |
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 318
- arm64 168
- arm 345
- riscv64 168
- ia32 318
- x32 1073742133
- loongarch64 168
- ppc64 302
- ppc 302
- s390x 311
- mips64 5271
- mipsn32 6275
- mipso32 4312
- alpha 473
- arc 168
- cris 318, removed in 4.17
- csky 168
- frv 318, removed in 4.17
- hexagon 168
- ia64 1304, removed in 6.7
- m32r 318, removed in 4.17
- m68k 314
- metag 168, removed in 4.17
- microblaze 318
- mn10300 319, removed in 4.17
- nds32 168, removed in 5.18
- nios2 168
- openrisc 168
- parisc 296
- score 168, removed in 4.17
- sh 318
- sparc 308
- sparc64 308
- tilegx 168, removed in 4.17
- tilepro 168, removed in 4.17
- xtensa 280
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/getcpu