Created attachment 6566 [details] clock_gettime() makes syscalls, but __vdso_clock_gettime doesn't. clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts) seems to always make a syscall, even on kernels that provide a vdso. Although upstream kernels don't have the patches we're running with, I find this behavior surprising. Why doesn't glibc always call __vdso_clock_gettime() and let the kernel decide on the best implementation regardless of the clock id? Relevant patches: http://thread.gmane.org/gmane.linux.kernel/1231015/focus=1231016
clock_gettime always calls __vdso_clock_gettime on x86_64. What are you testing on?
3.2 kernel plus out of tree patches which provide a vdso implementation for this clock. On May 10, 2013 6:02 AM, "siddhesh at redhat dot com" < sourceware-bugzilla@sourceware.org> wrote: > http://sourceware.org/bugzilla/show_bug.cgi?id=14438 > > Siddhesh Poyarekar <siddhesh at redhat dot com> changed: > > What |Removed |Added > > ---------------------------------------------------------------------------- > CC| |siddhesh at redhat dot com > > --- Comment #1 from Siddhesh Poyarekar <siddhesh at redhat dot com> > 2013-05-10 13:02:28 UTC --- > clock_gettime always calls __vdso_clock_gettime on x86_64. What are you > testing on? > > -- > Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email > ------- You are receiving this mail because: ------- > You reported the bug. >
(In reply to comment #2) > 3.2 kernel plus out of tree patches which provide a vdso implementation for > this clock. x86_64 or something else? x86_64 calls __vdso_clock_gettime.
x86_64. IIRC: the implementation calls vdso for some clockids, but not others.
It calls vdso_clock_gettime for all clockids. If vdso function has support for some clockids but not others, for which it does a context switch into the kernel. sysdeps/unix/clock_gettime.c: ... default: #ifdef SYSDEP_GETTIME_CPU SYSDEP_GETTIME_CPU (clock_id, tp); #endif ... sysdeps/unix/sysv/linux/clock_gettime.c ... #define SYSDEP_GETTIME_CPU(clock_id, tp) \ retval = SYSCALL_GETTIME (clock_id, tp); \ break ... sysdeps/unix/sysv/linux/x86_64/clock_gettime.c ... # define SYSCALL_GETTIME(id, tp) \ ({ long int (*f) (clockid_t, struct timespec *) = __vdso_clock_gettime; \ long int v_ret; \ PTR_DEMANGLE (f); \ v_ret = f (id, tp); \ if (INTERNAL_SYSCALL_ERROR_P (v_ret, )) { \ __set_errno (INTERNAL_SYSCALL_ERRNO (v_ret, )); \ v_ret = -1; \ } \ v_ret; }) ...
Verified in glibc-2.14. Thanks for looking into this!