在支持 syscall
和 sysret
的 x86-64 Intel 系统上,从 vanilla 内核上的 64 位用户代码进行的“最快”系统调用是什么?
特别是,它必须是执行syscall
/sysret
user <-> kernel transition1 的系统调用,但是执行除此之外的最少工作量。它甚至不需要自己执行系统调用:某种类型的早期错误从不分派(dispatch)到内核端的特定调用是可以的,只要它不会因此而走上慢路径。
这样的调用可用于估计原始 syscall
和 sysret
开销,独立于调用完成的任何工作。
1 特别是,这排除了看似系统调用但在 VDSO 中实现(例如,clock_gettime
)或由运行时缓存(例如, getpid
).
最佳答案
一个不存在的,因此很快返回 -ENOSYS。
来自 arch/x86/entry/entry_64.S:
#if __SYSCALL_MASK == ~0
cmpq $__NR_syscall_max, %rax
#else
andl $__SYSCALL_MASK, %eax
cmpl $__NR_syscall_max, %eax
#endif
ja 1f /* return -ENOSYS (already in pt_regs->ax) */
movq %r10, %rcx
/*
* This call instruction is handled specially in stub_ptregs_64.
* It might end up jumping to the slow path. If it jumps, RAX
* and all argument registers are clobbered.
*/
#ifdef CONFIG_RETPOLINE
movq sys_call_table(, %rax, 8), %rax
call __x86_indirect_thunk_rax
#else
call *sys_call_table(, %rax, 8)
#endif
.Lentry_SYSCALL_64_after_fastpath_call:
movq %rax, RAX(%rsp)
1:
关于linux - 最快的 Linux 系统调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48913091/