With the storage array in place it's now trivial to support CLOCK_TAI in
the vdso. Instead of extending the array to accomodate CLOCK_TAI, make use
of the fact that:
- CLOCK ids are set in stone
- CLOCK_THREAD_CPUTIME is never going to be supported in the VDSO so
the array slot 3 is unused
- CLOCK_TAI is id 11 which results in 3 when masked with 0x3
Add the mask to the basetime array lookup and set up the CLOCK_TAI base
time in update_vsyscall().
The performance impact of the mask operation is within the noise.
Signed-off-by: Thomas Gleixner <[email protected]>
---
arch/x86/entry/vdso/vclock_gettime.c | 2 +-
arch/x86/entry/vsyscall/vsyscall_gtod.c | 4 ++++
arch/x86/include/asm/vgtod.h | 6 +++++-
3 files changed, 10 insertions(+), 2 deletions(-)
--- a/arch/x86/entry/vdso/vclock_gettime.c
+++ b/arch/x86/entry/vdso/vclock_gettime.c
@@ -140,7 +140,7 @@ notrace static inline u64 vgetcyc(int mo
notrace static int do_hres(clockid_t clk, struct timespec *ts)
{
- struct vgtod_ts *base = >od->basetime[clk];
+ struct vgtod_ts *base = >od->basetime[clk & VGTOD_HRES_MASK];
u64 cycles, last, ns;
unsigned int seq;
--- a/arch/x86/entry/vsyscall/vsyscall_gtod.c
+++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c
@@ -51,6 +51,10 @@ void update_vsyscall(struct timekeeper *
base->sec = tk->xtime_sec;
base->nsec = tk->tkr_mono.xtime_nsec;
+ base = &vdata->basetime[VGTOD_TAI];
+ base->sec = tk->xtime_sec + (s64)tk->tai_offset;
+ base->nsec = tk->tkr_mono.xtime_nsec;
+
base = &vdata->basetime[CLOCK_MONOTONIC];
base->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
nsec = tk->tkr_mono.xtime_nsec;
--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -19,9 +19,13 @@ struct vgtod_ts {
};
#define VGTOD_BASES (CLOCK_MONOTONIC_COARSE + 1)
-#define VGTOD_HRES (BIT(CLOCK_REALTIME) | BIT(CLOCK_MONOTONIC))
+#define VGTOD_HRES (BIT(CLOCK_REALTIME) | BIT(CLOCK_MONOTONIC) | BIT(CLOCK_TAI))
#define VGTOD_COARSE (BIT(CLOCK_REALTIME_COARSE) | BIT(CLOCK_MONOTONIC_COARSE))
+/* Abuse CLOCK_THREAD_CPUTIME_ID for VGTOD CLOCK TAI */
+#define VGTOD_HRES_MASK 0x3
+#define VGTOD_TAI (CLOCK_TAI & VGTOD_HRES_MASK)
+
/*
* vsyscall_gtod_data will be accessed by 32 and 64 bit code at the same time
* so be carefull by modifying this structure.
> On Sep 14, 2018, at 5:50 AM, Thomas Gleixner <[email protected]> wrote:
>
> With the storage array in place it's now trivial to support CLOCK_TAI in
> the vdso. Instead of extending the array to accomodate CLOCK_TAI, make use
> of the fact that:
>
> - CLOCK ids are set in stone
> - CLOCK_THREAD_CPUTIME is never going to be supported in the VDSO so
> the array slot 3 is unused
> - CLOCK_TAI is id 11 which results in 3 when masked with 0x3
>
> Add the mask to the basetime array lookup and set up the CLOCK_TAI base
> time in update_vsyscall().
That’s... horrible. In an amazing way. Can you add BUILD_BUG_ON somewhere to assert that this actually works?
>
> The performance impact of the mask operation is within the noise.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---
> arch/x86/entry/vdso/vclock_gettime.c | 2 +-
> arch/x86/entry/vsyscall/vsyscall_gtod.c | 4 ++++
> arch/x86/include/asm/vgtod.h | 6 +++++-
> 3 files changed, 10 insertions(+), 2 deletions(-)
>
> --- a/arch/x86/entry/vdso/vclock_gettime.c
> +++ b/arch/x86/entry/vdso/vclock_gettime.c
> @@ -140,7 +140,7 @@ notrace static inline u64 vgetcyc(int mo
>
> notrace static int do_hres(clockid_t clk, struct timespec *ts)
> {
> - struct vgtod_ts *base = >od->basetime[clk];
> + struct vgtod_ts *base = >od->basetime[clk & VGTOD_HRES_MASK];
> u64 cycles, last, ns;
> unsigned int seq;
>
> --- a/arch/x86/entry/vsyscall/vsyscall_gtod.c
> +++ b/arch/x86/entry/vsyscall/vsyscall_gtod.c
> @@ -51,6 +51,10 @@ void update_vsyscall(struct timekeeper *
> base->sec = tk->xtime_sec;
> base->nsec = tk->tkr_mono.xtime_nsec;
>
> + base = &vdata->basetime[VGTOD_TAI];
> + base->sec = tk->xtime_sec + (s64)tk->tai_offset;
> + base->nsec = tk->tkr_mono.xtime_nsec;
> +
> base = &vdata->basetime[CLOCK_MONOTONIC];
> base->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
> nsec = tk->tkr_mono.xtime_nsec;
> --- a/arch/x86/include/asm/vgtod.h
> +++ b/arch/x86/include/asm/vgtod.h
> @@ -19,9 +19,13 @@ struct vgtod_ts {
> };
>
> #define VGTOD_BASES (CLOCK_MONOTONIC_COARSE + 1)
> -#define VGTOD_HRES (BIT(CLOCK_REALTIME) | BIT(CLOCK_MONOTONIC))
> +#define VGTOD_HRES (BIT(CLOCK_REALTIME) | BIT(CLOCK_MONOTONIC) | BIT(CLOCK_TAI))
> #define VGTOD_COARSE (BIT(CLOCK_REALTIME_COARSE) | BIT(CLOCK_MONOTONIC_COARSE))
>
> +/* Abuse CLOCK_THREAD_CPUTIME_ID for VGTOD CLOCK TAI */
> +#define VGTOD_HRES_MASK 0x3
> +#define VGTOD_TAI (CLOCK_TAI & VGTOD_HRES_MASK)
> +
> /*
> * vsyscall_gtod_data will be accessed by 32 and 64 bit code at the same time
> * so be carefull by modifying this structure.
>
>
On Fri, 14 Sep 2018, Andy Lutomirski wrote:
> > On Sep 14, 2018, at 5:50 AM, Thomas Gleixner <[email protected]> wrote:
> >
> > With the storage array in place it's now trivial to support CLOCK_TAI in
> > the vdso. Instead of extending the array to accomodate CLOCK_TAI, make use
> > of the fact that:
> >
> > - CLOCK ids are set in stone
> > - CLOCK_THREAD_CPUTIME is never going to be supported in the VDSO so
> > the array slot 3 is unused
> > - CLOCK_TAI is id 11 which results in 3 when masked with 0x3
> >
> > Add the mask to the basetime array lookup and set up the CLOCK_TAI base
> > time in update_vsyscall().
>
> That’s... horrible. In an amazing way. Can you add BUILD_BUG_ON somewhere
> to assert that this actually works?
Sure, but changing any of the clock ids will cause more wreckage than that.
Thanks,
tglx
> On Sep 14, 2018, at 7:27 AM, Thomas Gleixner <[email protected]> wrote:
>
> On Fri, 14 Sep 2018, Andy Lutomirski wrote:
>>> On Sep 14, 2018, at 5:50 AM, Thomas Gleixner <[email protected]> wrote:
>>>
>>> With the storage array in place it's now trivial to support CLOCK_TAI in
>>> the vdso. Instead of extending the array to accomodate CLOCK_TAI, make use
>>> of the fact that:
>>>
>>> - CLOCK ids are set in stone
>>> - CLOCK_THREAD_CPUTIME is never going to be supported in the VDSO so
>>> the array slot 3 is unused
>>> - CLOCK_TAI is id 11 which results in 3 when masked with 0x3
>>>
>>> Add the mask to the basetime array lookup and set up the CLOCK_TAI base
>>> time in update_vsyscall().
>>
>> That’s... horrible. In an amazing way. Can you add BUILD_BUG_ON somewhere
>> to assert that this actually works?
>
> Sure, but changing any of the clock ids will cause more wreckage than that.
>
I’m more concerned that we add a new one and break the magic masking. Maybe two start sharing the same slot.
> Thanks,
>
> tglx
On Fri, 14 Sep 2018, Andy Lutomirski wrote:
> > On Sep 14, 2018, at 7:27 AM, Thomas Gleixner <[email protected]> wrote:
> > On Fri, 14 Sep 2018, Andy Lutomirski wrote:
> >> That’s... horrible. In an amazing way. Can you add BUILD_BUG_ON somewhere
> >> to assert that this actually works?
> >
> > Sure, but changing any of the clock ids will cause more wreckage than that.
> >
> I’m more concerned that we add a new one and break the magic
> masking. Maybe two start sharing the same slot.
You are right. The obvious extension is CLOCK_BOOTTIME. That's id 7 which
indeed conflicts. I'll remove the magic.
Thanks,
tglx