linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
@ 2018-08-17 12:09 Matt Rickard
  0 siblings, 0 replies; 8+ messages in thread
From: Matt Rickard @ 2018-08-17 12:09 UTC (permalink / raw)
  To: Matt Rickard; +Cc: LKML

Process clock_gettime(CLOCK_TAI) in vDSO. This makes the call about as fast as
CLOCK_REALTIME instead of taking about four times as long.

Signed-off-by: Matt Rickard <matt@softrans.com.au>
---
 0 files changed


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

* Re: [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
  2018-08-28 15:36   ` Matthew Rickard
@ 2018-08-31 18:45     ` Thomas Gleixner
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Gleixner @ 2018-08-31 18:45 UTC (permalink / raw)
  To: Matthew Rickard; +Cc: Andy Lutomirski, Stephen Boyd, John Stultz, X86 ML, LKML

On Wed, 29 Aug 2018, Matthew Rickard wrote:

> Here are the before and after times with CONFIG_RETPOLINE=y always on.
> I don't see any regression, just the hoped-for improvement on glibc and
> vDSO calls of CLOCK_TAI.
> 
> Before:
>        sec Timestamp                   nanos clockname    tzname type
> ---------- --------------------------- ----- --------- --------- -------
> 1535445844 2018/08/28 08:44:04.338599419  96 CLOCK_REALTIME  UTC 0 glibc
> 1535445844 2018/08/28 08:44:04.348494684  87 CLOCK_REALTIME  UTC 1 vdso
> 1535445844 2018/08/28 08:44:04.357328913 321 CLOCK_REALTIME  UTC 2 sys
> 1535445834 2018/08/28 08:43:27.507099055 233 CLOCK_TAI right/UTC 0 glibc
> 1535445834 2018/08/28 08:43:27.530666383 239 CLOCK_TAI right/UTC 1 vdso
> 1535445834 2018/08/28 08:43:27.554827262 389 CLOCK_TAI right/UTC 2 sys
>         80 1970/01/01 00:01:20.593942210  88 CLOCK_MONOTONIC UTC 0 glibc
>         80 1970/01/01 00:01:20.602866312  84 CLOCK_MONOTONIC UTC 1 vdso
>         80 1970/01/01 00:01:20.611322392 272 CLOCK_MONOTONIC UTC 2 sys
>         80 1970/01/01 00:01:20.638630685 298 CLOCK_BOOTTIME  UTC 0 glibc
>         80 1970/01/01 00:01:20.668487920 293 CLOCK_BOOTTIME  UTC 1 vdso
>         80 1970/01/01 00:01:20.697818847 279 CLOCK_BOOTTIME  UTC 2 sys
> 
> After yours and my patches:
>        sec Timestamp                   nanos clockname    tzname type
> ---------- --------------------------- ----- --------- --------- -------
> 1535466985 2018/08/28 14:36:25.483377529  93 CLOCK_REALTIME  UTC 0 glibc
> 1535466985 2018/08/28 14:36:25.493020681  89 CLOCK_REALTIME  UTC 1 vdso
> 1535466985 2018/08/28 14:36:25.502139080 282 CLOCK_REALTIME  UTC 2 sys
> 1535466975 2018/08/28 14:35:48.530621935  87 CLOCK_TAI right/UTC 0 glibc
> 1535466975 2018/08/28 14:35:48.539393751  81 CLOCK_TAI right/UTC 1 vdso
> 1535466975 2018/08/28 14:35:48.547693183 276 CLOCK_TAI right/UTC 2 sys
>        224 1970/01/01 00:03:44.575542852  87 CLOCK_MONOTONIC UTC 0 glibc
>        224 1970/01/01 00:03:44.584329822  81 CLOCK_MONOTONIC UTC 1 vdso
>        224 1970/01/01 00:03:44.592473982 269 CLOCK_MONOTONIC UTC 2 sys
>        224 1970/01/01 00:03:44.619450784 296 CLOCK_BOOTTIME  UTC 0 glibc
>        224 1970/01/01 00:03:44.649224430 312 CLOCK_BOOTTIME  UTC 1 vdso
>        224 1970/01/01 00:03:44.680600544 297 CLOCK_BOOTTIME  UTC 2 sys

Can you please send a V3 with that information (condensed) in the
changelog?

Thanks,

	tglx

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

* Re: [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
  2018-08-24 17:47 ` Andy Lutomirski
  2018-08-24 18:25   ` John Stultz
@ 2018-08-28 15:36   ` Matthew Rickard
  2018-08-31 18:45     ` Thomas Gleixner
  1 sibling, 1 reply; 8+ messages in thread
From: Matthew Rickard @ 2018-08-28 15:36 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: Stephen Boyd, John Stultz, X86 ML, LKML

Here are the before and after times with CONFIG_RETPOLINE=y always on.
I don't see any regression, just the hoped-for improvement on glibc and
vDSO calls of CLOCK_TAI.

Before:
        sec Timestamp                   nanos clockname    tzname type
---------- --------------------------- ----- --------- --------- -------
1535445844 2018/08/28 08:44:04.338599419  96 CLOCK_REALTIME  UTC 0 glibc
1535445844 2018/08/28 08:44:04.348494684  87 CLOCK_REALTIME  UTC 1 vdso
1535445844 2018/08/28 08:44:04.357328913 321 CLOCK_REALTIME  UTC 2 sys
1535445834 2018/08/28 08:43:27.507099055 233 CLOCK_TAI right/UTC 0 glibc
1535445834 2018/08/28 08:43:27.530666383 239 CLOCK_TAI right/UTC 1 vdso
1535445834 2018/08/28 08:43:27.554827262 389 CLOCK_TAI right/UTC 2 sys
         80 1970/01/01 00:01:20.593942210  88 CLOCK_MONOTONIC UTC 0 glibc
         80 1970/01/01 00:01:20.602866312  84 CLOCK_MONOTONIC UTC 1 vdso
         80 1970/01/01 00:01:20.611322392 272 CLOCK_MONOTONIC UTC 2 sys
         80 1970/01/01 00:01:20.638630685 298 CLOCK_BOOTTIME  UTC 0 glibc
         80 1970/01/01 00:01:20.668487920 293 CLOCK_BOOTTIME  UTC 1 vdso
         80 1970/01/01 00:01:20.697818847 279 CLOCK_BOOTTIME  UTC 2 sys

After yours and my patches:
        sec Timestamp                   nanos clockname    tzname type
---------- --------------------------- ----- --------- --------- -------
1535466985 2018/08/28 14:36:25.483377529  93 CLOCK_REALTIME  UTC 0 glibc
1535466985 2018/08/28 14:36:25.493020681  89 CLOCK_REALTIME  UTC 1 vdso
1535466985 2018/08/28 14:36:25.502139080 282 CLOCK_REALTIME  UTC 2 sys
1535466975 2018/08/28 14:35:48.530621935  87 CLOCK_TAI right/UTC 0 glibc
1535466975 2018/08/28 14:35:48.539393751  81 CLOCK_TAI right/UTC 1 vdso
1535466975 2018/08/28 14:35:48.547693183 276 CLOCK_TAI right/UTC 2 sys
        224 1970/01/01 00:03:44.575542852  87 CLOCK_MONOTONIC UTC 0 glibc
        224 1970/01/01 00:03:44.584329822  81 CLOCK_MONOTONIC UTC 1 vdso
        224 1970/01/01 00:03:44.592473982 269 CLOCK_MONOTONIC UTC 2 sys
        224 1970/01/01 00:03:44.619450784 296 CLOCK_BOOTTIME  UTC 0 glibc
        224 1970/01/01 00:03:44.649224430 312 CLOCK_BOOTTIME  UTC 1 vdso
        224 1970/01/01 00:03:44.680600544 297 CLOCK_BOOTTIME  UTC 2 sys

-Matt-

On 25/08/2018 3:47 AM, Andy Lutomirski wrote:
> Minor nit: if it's not literally a resend, don't call it "RESEND" in
> $SUBJECT.  Call it v2, please.
> 
> Also, I added LKML and relevant maintainers to cc.  John and Stephen:
> this is a purely x86 patch, but it digs into the core timekeeping
> structures a bit.
> 
> On Fri, Aug 17, 2018 at 5:12 AM, Matt Rickard <matt@softrans.com.au> wrote:
>> Process clock_gettime(CLOCK_TAI) in vDSO. This makes the call about as fast as
>> CLOCK_REALTIME instead of taking about four times as long.
> 
> I'm conceptually okay with this, but the bug encountered last time
> around makes me suspect that GCC is generating genuinely horrible
> code.  Can you benchmark CLOCK_MONOTONIC before and after to make sure
> there isn't a big regression?  Please do this benchmark with
> CONFIG_RETPOLINE=y.
> 
> If there is a regression, then the code will need some reasonable
> restructuring to fix it.  Or perhaps -fno-jump-tables.
> 
> --Andy
> 
>> Signed-off-by: Matt Rickard <matt@softrans.com.au>
>> ---
>>   arch/x86/entry/vdso/vclock_gettime.c    | 25 +++++++++++++++++++++++++
>>   arch/x86/entry/vsyscall/vsyscall_gtod.c |  2 ++
>>   arch/x86/include/asm/vgtod.h            |  1 +
>>   3 files changed, 28 insertions(+)
>>
>> diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
>> index f19856d95c60..91ed1bb2a3bb 100644
>> --- a/arch/x86/entry/vdso/vclock_gettime.c
>> +++ b/arch/x86/entry/vdso/vclock_gettime.c
>> @@ -246,6 +246,27 @@ notrace static int __always_inline do_monotonic(struct timespec *ts)
>>          return mode;
>>   }
>>
>> +notrace static int __always_inline do_tai(struct timespec *ts)
>> +{
>> +       unsigned long seq;
>> +       u64 ns;
>> +       int mode;
>> +
>> +       do {
>> +               seq = gtod_read_begin(gtod);
>> +               mode = gtod->vclock_mode;
>> +               ts->tv_sec = gtod->tai_time_sec;
>> +               ns = gtod->wall_time_snsec;
>> +               ns += vgetsns(&mode);
>> +               ns >>= gtod->shift;
>> +       } while (unlikely(gtod_read_retry(gtod, seq)));
>> +
>> +       ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);
>> +       ts->tv_nsec = ns;
>> +
>> +       return mode;
>> +}
>> +
>>   notrace static void do_realtime_coarse(struct timespec *ts)
>>   {
>>          unsigned long seq;
>> @@ -277,6 +298,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
>>                  if (do_monotonic(ts) == VCLOCK_NONE)
>>                          goto fallback;
>>                  break;
>> +       case CLOCK_TAI:
>> +               if (do_tai(ts) == VCLOCK_NONE)
>> +                       goto fallback;
>> +               break;
>>          case CLOCK_REALTIME_COARSE:
>>                  do_realtime_coarse(ts);
>>                  break;
>> diff --git a/arch/x86/entry/vsyscall/vsyscall_gtod.c b/arch/x86/entry/vsyscall/vsyscall_gtod.c
>> index e1216dd95c04..d61392fe17f6 100644
>> --- a/arch/x86/entry/vsyscall/vsyscall_gtod.c
>> +++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c
>> @@ -53,6 +53,8 @@ void update_vsyscall(struct timekeeper *tk)
>>          vdata->monotonic_time_snsec     = tk->tkr_mono.xtime_nsec
>>                                          + ((u64)tk->wall_to_monotonic.tv_nsec
>>                                                  << tk->tkr_mono.shift);
>> +       vdata->tai_time_sec             = tk->xtime_sec
>> +                                       + tk->tai_offset;
>>          while (vdata->monotonic_time_snsec >=
>>                                          (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
>>                  vdata->monotonic_time_snsec -=
>> diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
>> index fb856c9f0449..adc9f7b20b9c 100644
>> --- a/arch/x86/include/asm/vgtod.h
>> +++ b/arch/x86/include/asm/vgtod.h
>> @@ -32,6 +32,7 @@ struct vsyscall_gtod_data {
>>          gtod_long_t     wall_time_coarse_nsec;
>>          gtod_long_t     monotonic_time_coarse_sec;
>>          gtod_long_t     monotonic_time_coarse_nsec;
>> +       gtod_long_t     tai_time_sec;
>>
>>          int             tz_minuteswest;
>>          int             tz_dsttime;

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

* Re: [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
  2018-08-24 17:47 ` Andy Lutomirski
@ 2018-08-24 18:25   ` John Stultz
  2018-08-28 15:36   ` Matthew Rickard
  1 sibling, 0 replies; 8+ messages in thread
From: John Stultz @ 2018-08-24 18:25 UTC (permalink / raw)
  To: Andy Lutomirski; +Cc: Matt Rickard, Stephen Boyd, X86 ML, LKML

On Fri, Aug 24, 2018 at 10:47 AM, Andy Lutomirski <luto@kernel.org> wrote:
> Minor nit: if it's not literally a resend, don't call it "RESEND" in
> $SUBJECT.  Call it v2, please.
>
> Also, I added LKML and relevant maintainers to cc.  John and Stephen:
> this is a purely x86 patch, but it digs into the core timekeeping
> structures a bit.

From a quick review, looks reasonable, so no objections from me.

thanks
-john

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

* Re: [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
       [not found] <20180817121251.4EB5318E01A1@virtux64.softrans.com.au>
@ 2018-08-24 17:47 ` Andy Lutomirski
  2018-08-24 18:25   ` John Stultz
  2018-08-28 15:36   ` Matthew Rickard
  0 siblings, 2 replies; 8+ messages in thread
From: Andy Lutomirski @ 2018-08-24 17:47 UTC (permalink / raw)
  To: Matt Rickard; +Cc: Stephen Boyd, John Stultz, X86 ML, LKML

Minor nit: if it's not literally a resend, don't call it "RESEND" in
$SUBJECT.  Call it v2, please.

Also, I added LKML and relevant maintainers to cc.  John and Stephen:
this is a purely x86 patch, but it digs into the core timekeeping
structures a bit.

On Fri, Aug 17, 2018 at 5:12 AM, Matt Rickard <matt@softrans.com.au> wrote:
> Process clock_gettime(CLOCK_TAI) in vDSO. This makes the call about as fast as
> CLOCK_REALTIME instead of taking about four times as long.

I'm conceptually okay with this, but the bug encountered last time
around makes me suspect that GCC is generating genuinely horrible
code.  Can you benchmark CLOCK_MONOTONIC before and after to make sure
there isn't a big regression?  Please do this benchmark with
CONFIG_RETPOLINE=y.

If there is a regression, then the code will need some reasonable
restructuring to fix it.  Or perhaps -fno-jump-tables.

--Andy

> Signed-off-by: Matt Rickard <matt@softrans.com.au>
> ---
>  arch/x86/entry/vdso/vclock_gettime.c    | 25 +++++++++++++++++++++++++
>  arch/x86/entry/vsyscall/vsyscall_gtod.c |  2 ++
>  arch/x86/include/asm/vgtod.h            |  1 +
>  3 files changed, 28 insertions(+)
>
> diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
> index f19856d95c60..91ed1bb2a3bb 100644
> --- a/arch/x86/entry/vdso/vclock_gettime.c
> +++ b/arch/x86/entry/vdso/vclock_gettime.c
> @@ -246,6 +246,27 @@ notrace static int __always_inline do_monotonic(struct timespec *ts)
>         return mode;
>  }
>
> +notrace static int __always_inline do_tai(struct timespec *ts)
> +{
> +       unsigned long seq;
> +       u64 ns;
> +       int mode;
> +
> +       do {
> +               seq = gtod_read_begin(gtod);
> +               mode = gtod->vclock_mode;
> +               ts->tv_sec = gtod->tai_time_sec;
> +               ns = gtod->wall_time_snsec;
> +               ns += vgetsns(&mode);
> +               ns >>= gtod->shift;
> +       } while (unlikely(gtod_read_retry(gtod, seq)));
> +
> +       ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);
> +       ts->tv_nsec = ns;
> +
> +       return mode;
> +}
> +
>  notrace static void do_realtime_coarse(struct timespec *ts)
>  {
>         unsigned long seq;
> @@ -277,6 +298,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
>                 if (do_monotonic(ts) == VCLOCK_NONE)
>                         goto fallback;
>                 break;
> +       case CLOCK_TAI:
> +               if (do_tai(ts) == VCLOCK_NONE)
> +                       goto fallback;
> +               break;
>         case CLOCK_REALTIME_COARSE:
>                 do_realtime_coarse(ts);
>                 break;
> diff --git a/arch/x86/entry/vsyscall/vsyscall_gtod.c b/arch/x86/entry/vsyscall/vsyscall_gtod.c
> index e1216dd95c04..d61392fe17f6 100644
> --- a/arch/x86/entry/vsyscall/vsyscall_gtod.c
> +++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c
> @@ -53,6 +53,8 @@ void update_vsyscall(struct timekeeper *tk)
>         vdata->monotonic_time_snsec     = tk->tkr_mono.xtime_nsec
>                                         + ((u64)tk->wall_to_monotonic.tv_nsec
>                                                 << tk->tkr_mono.shift);
> +       vdata->tai_time_sec             = tk->xtime_sec
> +                                       + tk->tai_offset;
>         while (vdata->monotonic_time_snsec >=
>                                         (((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
>                 vdata->monotonic_time_snsec -=
> diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
> index fb856c9f0449..adc9f7b20b9c 100644
> --- a/arch/x86/include/asm/vgtod.h
> +++ b/arch/x86/include/asm/vgtod.h
> @@ -32,6 +32,7 @@ struct vsyscall_gtod_data {
>         gtod_long_t     wall_time_coarse_nsec;
>         gtod_long_t     monotonic_time_coarse_sec;
>         gtod_long_t     monotonic_time_coarse_nsec;
> +       gtod_long_t     tai_time_sec;
>
>         int             tz_minuteswest;
>         int             tz_dsttime;

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

* Re: [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
  2018-08-17 12:09 Matt Rickard
  2018-08-17 13:08 ` kbuild test robot
@ 2018-08-17 13:24 ` kbuild test robot
  1 sibling, 0 replies; 8+ messages in thread
From: kbuild test robot @ 2018-08-17 13:24 UTC (permalink / raw)
  To: Matt Rickard; +Cc: kbuild-all, Matt Rickard, LKML

[-- Attachment #1: Type: text/plain, Size: 4803 bytes --]

Hi Matt,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/x86/vdso]
[also build test ERROR on v4.18 next-20180817]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Matt-Rickard/x86-vdso-Handle-clock_gettime-CLOCK_TAI-in-vDSO/20180817-202932
config: x86_64-randconfig-x017-201832 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

All errors (new ones prefixed by >>):

   arch/x86/entry/vdso/vclock_gettime.o: In function `__vdso_clock_gettime':
>> arch/x86/entry/vdso/vclock_gettime.c:292: undefined reference to `__x86_indirect_thunk_rax'
   ld: arch/x86/entry/vdso/vclock_gettime.o: relocation R_X86_64_PC32 against undefined symbol `__x86_indirect_thunk_rax' can not be used when making a shared object; recompile with -fPIC
   ld: final link failed: Bad value

vim +292 arch/x86/entry/vdso/vclock_gettime.c

da15cfdae arch/x86/vdso/vclock_gettime.c       John Stultz     2009-08-19  289  
23adec554 arch/x86/vdso/vclock_gettime.c       Steven Rostedt  2008-05-12  290  notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  291  {
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21 @292  	switch (clock) {
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  293  	case CLOCK_REALTIME:
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  294  		if (do_realtime(ts) == VCLOCK_NONE)
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  295  			goto fallback;
da15cfdae arch/x86/vdso/vclock_gettime.c       John Stultz     2009-08-19  296  		break;
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  297  	case CLOCK_MONOTONIC:
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  298  		if (do_monotonic(ts) == VCLOCK_NONE)
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  299  			goto fallback;
da15cfdae arch/x86/vdso/vclock_gettime.c       John Stultz     2009-08-19  300  		break;
c764c5daa arch/x86/entry/vdso/vclock_gettime.c Matt Rickard    2018-08-17  301  	case CLOCK_TAI:
c764c5daa arch/x86/entry/vdso/vclock_gettime.c Matt Rickard    2018-08-17  302  		if (do_tai(ts) == VCLOCK_NONE)
c764c5daa arch/x86/entry/vdso/vclock_gettime.c Matt Rickard    2018-08-17  303  			goto fallback;
c764c5daa arch/x86/entry/vdso/vclock_gettime.c Matt Rickard    2018-08-17  304  		break;
da15cfdae arch/x86/vdso/vclock_gettime.c       John Stultz     2009-08-19  305  	case CLOCK_REALTIME_COARSE:
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  306  		do_realtime_coarse(ts);
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  307  		break;
da15cfdae arch/x86/vdso/vclock_gettime.c       John Stultz     2009-08-19  308  	case CLOCK_MONOTONIC_COARSE:
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  309  		do_monotonic_coarse(ts);
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  310  		break;
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  311  	default:
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  312  		goto fallback;
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  313  	}
0d7b8547f arch/x86/vdso/vclock_gettime.c       Andy Lutomirski 2011-06-05  314  
a939e817a arch/x86/vdso/vclock_gettime.c       John Stultz     2012-03-01  315  	return 0;
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  316  fallback:
ce39c6402 arch/x86/vdso/vclock_gettime.c       Stefani Seibold 2014-03-17  317  	return vdso_fallback_gettime(clock, ts);
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  318  }
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  319  int clock_gettime(clockid_t, struct timespec *)
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  320  	__attribute__((weak, alias("__vdso_clock_gettime")));
2aae950b2 arch/x86_64/vdso/vclock_gettime.c    Andi Kleen      2007-07-21  321  

:::::: The code at line 292 was first introduced by commit
:::::: 2aae950b21e4bc789d1fc6668faf67e8748300b7 x86_64: Add vDSO for x86-64 with gettimeofday/clock_gettime/getcpu

:::::: TO: Andi Kleen <ak@suse.de>
:::::: CC: Linus Torvalds <torvalds@woody.linux-foundation.org>

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 28865 bytes --]

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

* Re: [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
  2018-08-17 12:09 Matt Rickard
@ 2018-08-17 13:08 ` kbuild test robot
  2018-08-17 13:24 ` kbuild test robot
  1 sibling, 0 replies; 8+ messages in thread
From: kbuild test robot @ 2018-08-17 13:08 UTC (permalink / raw)
  To: Matt Rickard; +Cc: kbuild-all, Matt Rickard, LKML

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]

Hi Matt,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on tip/x86/vdso]
[also build test ERROR on v4.18 next-20180817]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Matt-Rickard/x86-vdso-Handle-clock_gettime-CLOCK_TAI-in-vDSO/20180817-202932
config: i386-randconfig-x002-201832 (attached as .config)
compiler: gcc-7 (Debian 7.3.0-16) 7.3.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

>> arch/x86/entry/vdso/vdso32.so.dbg: undefined symbols found

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 31747 bytes --]

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

* [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO
@ 2018-08-17 12:09 Matt Rickard
  2018-08-17 13:08 ` kbuild test robot
  2018-08-17 13:24 ` kbuild test robot
  0 siblings, 2 replies; 8+ messages in thread
From: Matt Rickard @ 2018-08-17 12:09 UTC (permalink / raw)
  To: Matt Rickard; +Cc: LKML

Process clock_gettime(CLOCK_TAI) in vDSO. This makes the call about as fast as
CLOCK_REALTIME instead of taking about four times as long.

Signed-off-by: Matt Rickard <matt@softrans.com.au>
---
 arch/x86/entry/vdso/vclock_gettime.c    | 25 +++++++++++++++++++++++++
 arch/x86/entry/vsyscall/vsyscall_gtod.c |  2 ++
 arch/x86/include/asm/vgtod.h            |  1 +
 3 files changed, 28 insertions(+)

diff --git a/arch/x86/entry/vdso/vclock_gettime.c b/arch/x86/entry/vdso/vclock_gettime.c
index f19856d95c60..91ed1bb2a3bb 100644
--- a/arch/x86/entry/vdso/vclock_gettime.c
+++ b/arch/x86/entry/vdso/vclock_gettime.c
@@ -246,6 +246,27 @@ notrace static int __always_inline do_monotonic(struct timespec *ts)
 	return mode;
 }
 
+notrace static int __always_inline do_tai(struct timespec *ts)
+{
+	unsigned long seq;
+	u64 ns;
+	int mode;
+
+	do {
+		seq = gtod_read_begin(gtod);
+		mode = gtod->vclock_mode;
+		ts->tv_sec = gtod->tai_time_sec;
+		ns = gtod->wall_time_snsec;
+		ns += vgetsns(&mode);
+		ns >>= gtod->shift;
+	} while (unlikely(gtod_read_retry(gtod, seq)));
+
+	ts->tv_sec += __iter_div_u64_rem(ns, NSEC_PER_SEC, &ns);
+	ts->tv_nsec = ns;
+
+	return mode;
+}
+
 notrace static void do_realtime_coarse(struct timespec *ts)
 {
 	unsigned long seq;
@@ -277,6 +298,10 @@ notrace int __vdso_clock_gettime(clockid_t clock, struct timespec *ts)
 		if (do_monotonic(ts) == VCLOCK_NONE)
 			goto fallback;
 		break;
+	case CLOCK_TAI:
+		if (do_tai(ts) == VCLOCK_NONE)
+			goto fallback;
+		break;
 	case CLOCK_REALTIME_COARSE:
 		do_realtime_coarse(ts);
 		break;
diff --git a/arch/x86/entry/vsyscall/vsyscall_gtod.c b/arch/x86/entry/vsyscall/vsyscall_gtod.c
index e1216dd95c04..d61392fe17f6 100644
--- a/arch/x86/entry/vsyscall/vsyscall_gtod.c
+++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c
@@ -53,6 +53,8 @@ void update_vsyscall(struct timekeeper *tk)
 	vdata->monotonic_time_snsec	= tk->tkr_mono.xtime_nsec
 					+ ((u64)tk->wall_to_monotonic.tv_nsec
 						<< tk->tkr_mono.shift);
+	vdata->tai_time_sec	        = tk->xtime_sec
+					+ tk->tai_offset;
 	while (vdata->monotonic_time_snsec >=
 					(((u64)NSEC_PER_SEC) << tk->tkr_mono.shift)) {
 		vdata->monotonic_time_snsec -=
diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
index fb856c9f0449..adc9f7b20b9c 100644
--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -32,6 +32,7 @@ struct vsyscall_gtod_data {
 	gtod_long_t	wall_time_coarse_nsec;
 	gtod_long_t	monotonic_time_coarse_sec;
 	gtod_long_t	monotonic_time_coarse_nsec;
+	gtod_long_t	tai_time_sec;
 
 	int		tz_minuteswest;
 	int		tz_dsttime;

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

end of thread, other threads:[~2018-08-31 18:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-17 12:09 [RESEND PATCH] x86/vdso: Handle clock_gettime(CLOCK_TAI) in vDSO Matt Rickard
2018-08-17 12:09 Matt Rickard
2018-08-17 13:08 ` kbuild test robot
2018-08-17 13:24 ` kbuild test robot
     [not found] <20180817121251.4EB5318E01A1@virtux64.softrans.com.au>
2018-08-24 17:47 ` Andy Lutomirski
2018-08-24 18:25   ` John Stultz
2018-08-28 15:36   ` Matthew Rickard
2018-08-31 18:45     ` Thomas Gleixner

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 NNTP newsgroup(s).