public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Re: How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84?
       [not found] <20200721162210.4A34140605C@ip-64-139-1-69.sjc.megapath.net>
@ 2020-07-21 17:02 ` Florian Weimer
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Weimer @ 2020-07-21 17:02 UTC (permalink / raw)
  To: Hal Murray; +Cc: libc-help

* Hal Murray:

> fw@deneb.enyo.de said:
>> You can run the program under strace, to see if the clock_gettime function
>> performs any system calls.  If the fast path is used, no system call shows
>> up. 
>
> Is there a way for a program to test at runtime if the fast path or syscall 
> will happen?

glibc doesn't know this.  It's possible that we call into the kernel
vDSO (where the syscall-less fast path lives), but the code there
still makes the system call after all because some precondition for
the fast path isn't met.

The kernel doesn't expose any explicit interface for this either, as
far as I know.

You'll have to use something with fork and ptrace, to see if a
clock_gettime call makes a system call or not (but in general, that
may even change over time).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84?
  2020-07-24 14:03   ` Vivek Das Mohapatra
@ 2020-08-12 12:43     ` 孙世龙 sunshilong
  0 siblings, 0 replies; 7+ messages in thread
From: 孙世龙 sunshilong @ 2020-08-12 12:43 UTC (permalink / raw)
  To: Vivek Das Mohapatra
  Cc: Florian Weimer, 孙世龙 sunshilong via Libc-help

Hi, vivek

Thank you for your generous help.
I have carefully studied your tool. But I have found it only supports
several functions(i.e. time, gettimeofday, time and etc), not
including clock_getime.





On Fri, Jul 24, 2020 at 10:03 PM Vivek Das Mohapatra
<vivek@collabora.com> wrote:
>
> >> How can I confirm whether __GI___clock_gettime() implemented as fast
> >> system call or not on x86_64 platform with Linux 4.19.84?
>
> If you're looking for the VDSO fast path I had to knock up
> this tool a few years ago to check whether it was being
> followed (instructions included).
>
> https://gitlab.collabora.com/vivek/syscall-vdso-test
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84?
  2020-07-30  8:37   ` 孙世龙 sunshilong
@ 2020-07-30  8:57     ` Florian Weimer
  0 siblings, 0 replies; 7+ messages in thread
From: Florian Weimer @ 2020-07-30  8:57 UTC (permalink / raw)
  To: 孙世龙 sunshilong via Libc-help
  Cc: 孙世龙 sunshilong

* 孙世龙 sunshilong via Libc-help:

> Hi, Florian Weimer
>
> Thank you for taking the time to respond to my question.
>>You can run the program under strace, to see if the clock_gettime
>>function performs any system calls.
>>If the fast path is used, no system call shows up.
>  I agree with your opinion(i.e. If the fast path is used, no system
> call shows up.)
> But there is a problem,  no system call showing up can't indicate
> a fast system-call is called(maybe, neither system-call nor fast
> system-call is called,e.g. strcmp(3)).

Yes, telling those two cases apart (implementation in glibc vs
implementation in the vDSO) requires inspection of the glibc sources or
binaries.  It can also depend on run-time decisions (see the
sched_getcpu optimization based on rseq which we recently removed
again).

>>Or you can single-step through the function, instruction by
>>instruction, using the “si” command and in “layout asm” mode.  If you
>>never see an syscall instruction, then the fast path is taken.

> By GDB?

Yes, under GDB.

If the implementation is in the vDSO, you will see different addresses
for the program code, so that's one way to detect that situation.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84?
  2020-07-19  9:56 ` Florian Weimer
  2020-07-24 14:03   ` Vivek Das Mohapatra
@ 2020-07-30  8:37   ` 孙世龙 sunshilong
  2020-07-30  8:57     ` Florian Weimer
  1 sibling, 1 reply; 7+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-30  8:37 UTC (permalink / raw)
  To: Florian Weimer; +Cc: 孙世龙 sunshilong via Libc-help, vivek

Hi, Florian Weimer

Thank you for taking the time to respond to my question.
>You can run the program under strace, to see if the clock_gettime
>function performs any system calls.
>If the fast path is used, no system call shows up.
 I agree with your opinion(i.e. If the fast path is used, no system
call shows up.)
But there is a problem,  no system call showing up can't indicate
a fast system-call is called(maybe, neither system-call nor fast
system-call is called,e.g. strcmp(3)).

>Or you can single-step through the function, instruction by
>instruction, using the “si” command and in “layout asm” mode.  If you
>never see an syscall instruction, then the fast path is taken.
By GDB?

Thank you for your attention to this matter.
Best Regards.

On Sun, Jul 19, 2020 at 5:56 PM Florian Weimer <fw@deneb.enyo.de> wrote:
>
> * 孙世龙 sunshilong via Libc-help:
>
> > How can I confirm whether __GI___clock_gettime() implemented as fast
> > system call or not on x86_64 platform with Linux 4.19.84?
>
> The __GI___clock_gettime code is always in libc, so that's not an
> indicator.
>
> You can run the program under strace, to see if the clock_gettime
> function performs any system calls.  If the fast path is used, no
> system call shows up.
>
> Or you can single-step through the function, instruction by
> instruction, using the “si” command and in “layout asm” mode.  If you
> never see an syscall instruction, then the fast path is taken.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84?
  2020-07-19  9:56 ` Florian Weimer
@ 2020-07-24 14:03   ` Vivek Das Mohapatra
  2020-08-12 12:43     ` 孙世龙 sunshilong
  2020-07-30  8:37   ` 孙世龙 sunshilong
  1 sibling, 1 reply; 7+ messages in thread
From: Vivek Das Mohapatra @ 2020-07-24 14:03 UTC (permalink / raw)
  To: Florian Weimer
  Cc: 孙世龙 sunshilong via Libc-help,
	孙世龙 sunshilong

>> How can I confirm whether __GI___clock_gettime() implemented as fast
>> system call or not on x86_64 platform with Linux 4.19.84?

If you're looking for the VDSO fast path I had to knock up
this tool a few years ago to check whether it was being
followed (instructions included).

https://gitlab.collabora.com/vivek/syscall-vdso-test


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84?
  2020-07-19  8:10 孙世龙 sunshilong
@ 2020-07-19  9:56 ` Florian Weimer
  2020-07-24 14:03   ` Vivek Das Mohapatra
  2020-07-30  8:37   ` 孙世龙 sunshilong
  0 siblings, 2 replies; 7+ messages in thread
From: Florian Weimer @ 2020-07-19  9:56 UTC (permalink / raw)
  To: 孙世龙 sunshilong via Libc-help
  Cc: 孙世龙 sunshilong

* 孙世龙 sunshilong via Libc-help:

> How can I confirm whether __GI___clock_gettime() implemented as fast
> system call or not on x86_64 platform with Linux 4.19.84?

The __GI___clock_gettime code is always in libc, so that's not an
indicator.

You can run the program under strace, to see if the clock_gettime
function performs any system calls.  If the fast path is used, no
system call shows up.

Or you can single-step through the function, instruction by
instruction, using the “si” command and in “layout asm” mode.  If you
never see an syscall instruction, then the fast path is taken.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84?
@ 2020-07-19  8:10 孙世龙 sunshilong
  2020-07-19  9:56 ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: 孙世龙 sunshilong @ 2020-07-19  8:10 UTC (permalink / raw)
  To: libc-help

Hi, list

How can I confirm whether __GI___clock_gettime() implemented as fast
system call or not on x86_64 platform with Linux 4.19.84?
Here is some related backtrace log(hope there is some hint on this question):

(gdb) bt
#0  0x00007ffc41da89fa in ?? ()
#1  0x00007fa90785aaf0 in ?? ()
#2  0x00007fa905a16876 in __GI___clock_gettime (clock_id=0,
tp=0x7fa90785aac0) at ../sysdeps/unix/clock_gettime.c:115

Thank you for your attention to this matter.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-08-12 12:43 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200721162210.4A34140605C@ip-64-139-1-69.sjc.megapath.net>
2020-07-21 17:02 ` How to confirm whether __GI___clock_gettime() implemented as fast system call or not on x86_64 platform with Linux 4.19.84? Florian Weimer
2020-07-19  8:10 孙世龙 sunshilong
2020-07-19  9:56 ` Florian Weimer
2020-07-24 14:03   ` Vivek Das Mohapatra
2020-08-12 12:43     ` 孙世龙 sunshilong
2020-07-30  8:37   ` 孙世龙 sunshilong
2020-07-30  8:57     ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).