Miss clock_gettime
Eugene Syromyatnikov
evgsyr at gmail.com
Sat Apr 7 14:17:07 UTC 2018
On Sat, Apr 7, 2018 at 6:28 AM, <845767657 at qq.com> wrote:
> Hello,
> I want to lean what's the python time.time do?
> Using strace, I cannot find anything about time system call.
> so I write a simple C snippet that just call clock_gettime(2), but
> also strace didn't trace it.
>
> ---------------------
> #include <unistd.h>
> #include <time.h>
>
> int main()
> {
> struct timespec ts;
> clock_gettime(CLOCK_REALTIME, &ts);
> return 0;
> }
> -----------------------
>
>
> $ strace -V
> strace -- version 4.21
> Copyright (c) 1991-2018 The strace developers <https://strace.io>.
> This is free software; see the source for copying conditions. There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> Optional features enabled: stack-unwind stack-demangle m32-mpers mx32-mpers
>
> $ uname -a
> Linux taoqy-PC 4.15.10-1-ARCH #1 SMP PREEMPT Thu Mar 15 12:24:34 UTC 2018 x86_64 GNU/Linux
>
>
> Thanks
>
>From the #strace IRC channel[1]:
< taoqy> Hello, I write a simple C snippet that just call
clock_gettime(2), but strace didn't trace it.
< taoqy> the begining was I want to lean what's the python time.time
do? Using strace, I cannot find anything about time systemcall. so I
write the C code.
< eSyr-ng_> taoqy: are you sure you're calling clock_gettime(2) and
not clock_gettime(3)? clock_gettime is implemented using vDSO in glibc
and does not call the syscall with the sae name.
< taoqy> eSyr-ng_: I notice the vdso in the manual, but how can I tell
the difference?
< taoqy> $ ldd a.out
< taoqy> linux-vdso.so.1 (0x00007ffdd5edc000)
< taoqy> libc.so.6 => /usr/lib/libc.so.6 (0x00007fb25823c000)
< taoqy> /lib64/ld-linux-x86-64.so.2 =>
/usr/lib64/ld-linux-x86-64.so.2 (0x00007fb2587f5000)
< taoqy> is this mean using vdso?
< eSyr-ng_> taoqy: it means that vdso is mapped by kernel, yes. For
the actual usase, it largely depends on libc specifics, but glibc uses
vdso for obtaining time for quite some time.
< taoqy> eSyr-ng_: Thank you for your help. Now i understand that
clock_gettime is not a system call. By the way, can I find all those
system call that are exported by the vDSO.
< eSyr-ng_> taoqy: I'm not really sure whether there's a proper
documentation availabe; you can check out the kernel's source (it's
usually implemented in file vdso.c or in directory vdso, depending on
the architecture); vdso(7) has a pretty nice…
< eSyr-ng_> … overview of what's available on different architectures.
You can also take a look of glibc's usage of vdso symbols, they are
located using _dl_vdso_sym routine. You probabl can also list all the
symbold present there, but it probably…
< eSyr-ng_> … requires some architecture-specific knowledge.
< eSyr-ng_> (for example, as vdso(7) states, on hppa there's no symbol
information, for example)
[1] https://strace.io/logs/strace/2018-04-07#9153;
--
Eugene Syromyatnikov
mailto:evgsyr at gmail.com
xmpp:esyr at jabber.{ru|org}
More information about the Strace-devel
mailing list