Comment by ori_b

17 days ago

> spectre & meltdown.

I just measured. On my Ryzen 7 9700X, with Linux 6.12, it's about 50ns to call syscall(__NR_gettimeofday). Even post-spectre, entering the kernel isn't so expensive.

Are you sure that system call actually enters the kernel mode? It might be one of the special ones where kernel serves it from user space, forgot their name.

If it isn't a vDSO call, I think 50ns figure shouldn't be possible.

  • No need to guess, it's 10 lines of code. And you can use bpftrace to watch the test program enter the kernel.

    Using the libc wrapper will use the vdso. Using syscall() will enter the kernel.

    I haven't measured, but calling the vdso should be closer to 5ns.

    Someone else did more detailed measurements here:

    https://arkanis.de/weblog/2017-01-05-measurements-of-system-...

    • 50ns on a 3GHz CPU core is ~150 cycles. Pushing and popping back the registers to L1 cache is 5-10 cycles each. With having to handle 16 general purpose registers on x86-64 this is already close to or even more than 150 cycles, no?

      14 replies →