Remix.run Logo
higherhalf 2 hours ago

clock_gettime() goes through vDSO, avoiding a context switch. It shows up on the flamegraph as well.

jerrinot 2 hours ago | parent | next [-]

Only for some clocks (CLOCK_MONOTONIC, etc) and some clock sources. For VIRT/SCHED, the vDSO shim still has to invoke the actual syscall. You can't avoid the kernel transition when you need per-thread accounting.

higherhalf 2 hours ago | parent [-]

Thanks, I really should've looked deeper than that.

jerrinot an hour ago | parent [-]

no problem at all, I was confused too when I saw the profile for the first time.

ot 2 hours ago | parent | prev | next [-]

If you look below the vDSO frame, there is still a syscall. I think that the vDSO implementation is missing a fast path for this particular clock id (it could be implemented though).

jerrinot 2 hours ago | parent [-]

Exactly this.

a-dub 2 hours ago | parent | prev [-]

edit: agh, no. CLOCK_THREAD_CPUTIME_ID falls through the vdso to the kernel which makes sense as it would likely need to look at the task struct.

here it gets the task struct: https://elixir.bootlin.com/linux/v6.18.5/source/kernel/time/... and here https://elixir.bootlin.com/linux/v6.18.5/source/kernel/time/... to here where it actually pulls the value out: https://elixir.bootlin.com/linux/v6.18.5/source/kernel/sched...

where here is the vdso clock pick logic https://elixir.bootlin.com/linux/v6.18.5/source/lib/vdso/get... and here is the fallback to the syscall if it's not a vdso clock https://elixir.bootlin.com/linux/v6.18.5/source/lib/vdso/get...