perf_event_open on x64
set up performance monitoring
sys_perf_event_open(struct perf_event_attr *attr_uptr, pid_t pid, int cpu, int group_fd, unsigned long flags)
| number | 298 (0x12a) |
|---|---|
| abi | common |
| kconfig | CONFIG_PERF_EVENTS |
| entry point | sys_perf_event_open |
| since | Linux 3.3 or earlier (3.3 is the first release scanned for x64) |
| man page | perf_event_open(2) |
| source | elixir.bootlin.com |
Registers
| register | value |
|---|---|
rax | 298, the syscall number |
rdi | struct perf_event_attr *attr_uptr |
rsi | pid_t pid |
rdx | int cpu |
r10 | int group_fd |
r8 | unsigned long flags |
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 336
- arm64 241
- arm 364
- riscv64 241
- ia32 336
- x32 1073742122
- loongarch64 241
- ppc64 319
- ppc 319
- s390x 331
- mips64 5292
- mipsn32 6296
- mipso32 4333
- alpha 493
- arc 241
- blackfin 369, removed in 4.17
- cris 339, removed in 4.17
- csky 241
- frv 336, removed in 4.17
- hexagon 241
- ia64 1352, removed in 6.7
- m68k 332
- metag 241, removed in 4.17
- microblaze 366
- mn10300 337, removed in 4.17
- nds32 241, removed in 5.18
- nios2 241
- openrisc 241
- parisc 318
- score 241, removed in 4.17
- sh 336
- sparc 327
- sparc64 327
- tilegx 241, removed in 4.17
- tilepro 241, removed in 4.17
- xtensa 327
Get this as JSON: https://api.syscall.sh/v2/syscalls/x64/perf_event_open