最快的Linux系统调用 [英] Fastest Linux system call

查看:114
本文介绍了最快的Linux系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在支持syscallsysret的x86-64 Intel系统上,香草内核上来自64位用户代码的最快"系统调用是什么?

On an x86-64 Intel system that supports syscall and sysret what's the "fastest" system call from 64-bit user code on a vanilla kernel?

特别是,它必须是一个行使syscall/sysret用户<->内核转换 1 的系统调用,但执行的工作量最少.它甚至不需要执行syscall本身:只要不因某些原因而走慢路,就可以从不分派给内核方面的特定调用的某种类型的早期错误是可以的.

In particular, it must be a system call that exercises the syscall/sysret user <-> kernel transition1, but does the least amount of work beyond that. It doesn't even need to do the syscall itself: some type of early error which never dispatches to the specific call on the kernel side is fine, as long as it doesn't go down some slow path because of that.

这样的调用可以用来估计原始的syscallsysret开销,而与该调用所做的任何工作无关.

Such a call could be used to estimate the raw syscall and sysret overhead independent of any work done by the call.

1 特别是,这排除了看似是系统调用但在VDSO中实现的内容(例如,clock_gettime)或在运行时被缓存的内容(例如,getpid).

1 In particular, this excludes things that appear to be system calls but are implemented in the VDSO (e.g., clock_gettime) or are cached by the runtime (e.g., getpid).

推荐答案

一个不存在的,因此会迅速返回-ENOSYS.

One that doesn't exist, and therefore returns -ENOSYS quickly.

从arch/x86/entry/entry_64.S:

From 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系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆