x86/vdso: Add support for CLOCK_MONOTONIC_RAW in the vDSO
Subsystems (3)
cover x86/vdso: Add support for CLOCK_MONOTONIC_RAW in the vDSO
This series adds support for the CLOCK_MONOTONIC_RAW clock in the x86 vDSO, thus decreasing its readout cost. This is particularly useful for Wine which needs to implement Win32 API clock functions whose value does not get adjusted with adjtimex().
Huw Davies (3):
x86/vdso: Remove unused 'mask' member
x86/vdso: Allow clock specific mult and shift values x86/vdso: Add support for CLOCK_MONOTONIC_RAW in the vDSO
arch/x86/entry/vdso/vclock_gettime.c | 4 ++-- arch/x86/entry/vsyscall/vsyscall_gtod.c | 15 ++++++++++++--- arch/x86/include/asm/vgtod.h | 10 +++++----- 3 files changed, 19 insertions(+), 10 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 x86/vdso: Remove unused 'mask' member
The 'mask' member of struct vsyscall_gtod_data is unused, so remove it. Its use was removed in commit a51e996d48ac (x86/vdso: Enforce 64bit clocksource).
--- arch/x86/entry/vsyscall/vsyscall_gtod.c | 1 - arch/x86/include/asm/vgtod.h | 1 - 2 files changed, 2 deletions(-)
arch/x86/entry/vsyscall/vsyscall_gtod.c +0 -1
@@ -43,7 +43,6 @@ void update_vsyscall(struct timekeeper *tk)/* copy vsyscall data */ vdata->vclock_mode = vclock_mode; vdata->cycle_last = tk->tkr_mono.cycle_last; - vdata->mask = tk->tkr_mono.mask; vdata->mult = tk->tkr_mono.mult; vdata->shift = tk->tkr_mono.shift;
arch/x86/include/asm/vgtod.h +0 -1
@@ -40,7 +40,6 @@ struct vsyscall_gtod_data {int vclock_mode;u64 cycle_last; -u64 mask;u32 mult;u32 shift;
Signature · 1 line
2.17.1
Re: [PATCH 1/3] x86/vdso: Remove unused 'mask' member
Quoted 3 lines · Huw Davies
The 'mask' member of struct
vsyscall_gtod_datais unused, so remove it. Its use was removed in commita51e996d48ac(x86/vdso: Enforce 64bit clocksource).
That's true, but we are moving the VDSO to generic code, so the mask will stay.
Thanks,
tglx
PATCH 2/3 x86/vdso: Allow clock specific mult and shift values
In reply to Huw DaviesThis will allow clocks with different mult and shift values, e.g. CLOCK_MONOTONIC_RAW, to be supported in the vDSO.
The coarse clocks do not require these data so the values are not copied for these clocks.
One could add potential new values of mult and shift alongside the existing values in struct vsyscall_gtod_data, but it seems more natural to group them with the actual clock data in the basetime array at the expense of a few more cycles in update_vsyscall().
--- arch/x86/entry/vdso/vclock_gettime.c | 4 ++-- arch/x86/entry/vsyscall/vsyscall_gtod.c | 8 ++++++-- arch/x86/include/asm/vgtod.h | 6 +++--- 3 files changed, 11 insertions(+), 7 deletions(-)
arch/x86/entry/vdso/vclock_gettime.c +2 -2
@@ -153,8 +153,8 @@ notrace static int do_hres(clockid_t clk, struct timespec *ts)if (unlikely ((s64 )cycles <0 ))return vdso_fallback_gettime (clk, ts);if (cycles > last) - ns += (cycles - last) * gtod->mult; - ns >>= gtod->shift; + ns += (cycles - last) * base->mult; + ns >>= base->shift; sec = base->sec; }while (unlikely (gtod_read_retry (gtod, seq)));
arch/x86/entry/vsyscall/vsyscall_gtod.c +6 -2
@@ -43,16 +43,18 @@ void update_vsyscall(struct timekeeper *tk)/* copy vsyscall data */ vdata->vclock_mode = vclock_mode; vdata->cycle_last = tk->tkr_mono.cycle_last; - vdata->mult = tk->tkr_mono.mult; - vdata->shift = tk->tkr_mono.shift; base = &vdata->basetime[CLOCK_REALTIME ]; base->sec = tk->xtime_sec; base->nsec = tk->tkr_mono.xtime_nsec; + base->mult = tk->tkr_mono.mult; + base->shift = tk->tkr_mono.shift; base = &vdata->basetime[CLOCK_TAI ]; base->sec = tk->xtime_sec + (s64 )tk->tai_offset; base->nsec = tk->tkr_mono.xtime_nsec; + base->mult = tk->tkr_mono.mult; + base->shift = tk->tkr_mono.shift; base = &vdata->basetime[CLOCK_MONOTONIC ]; base->sec = tk->xtime_sec + tk->wall_to_monotonic.tv_sec;
@@ -63,6 +65,8 @@ void update_vsyscall(struct timekeeper *tk) base->sec++; } base->nsec = nsec; + base->mult = tk->tkr_mono.mult; + base->shift = tk->tkr_mono.shift; base = &vdata->basetime[CLOCK_REALTIME_COARSE ]; base->sec = tk->xtime_sec;
arch/x86/include/asm/vgtod.h +3 -3
@@ -20,11 +20,13 @@ typedef unsigned long gtod_long_t;* clocks, this encodes the actual time. * * To confuse the reader, for high-resolution clocks, nsec is left-shifted -* by vsyscall_gtod_data.shift. +* by shift. */ struct vgtod_ts {u64 sec;u64 nsec; +u32 mult; +u32 shift; };#define VGTOD_BASES (CLOCK_TAI + 1)
@@ -40,8 +42,6 @@ struct vsyscall_gtod_data {int vclock_mode;u64 cycle_last; -u32 mult; -u32 shift;struct vgtod_ts basetime[VGTOD_BASES ];
Signature · 1 line
2.17.1
Re: [PATCH 2/3] x86/vdso: Allow clock specific mult and shift values
On Thu, 11 Apr 2019, Huw Davies wrote:
CC+: Vincenzo Frascino who is working on the generic VDSO.
Quoted 10 lines
This will allow clocks with different mult and shift values, e.g.
CLOCK_MONOTONIC_RAW, to be supported in the vDSO.The coarse clocks do not require these data so the values are not copied for these clocks.
One could add potential new values of mult and shift alongside the existing values in struct
vsyscall_gtod_data, but it seems more natural to group them with the actual clock data in the basetime array at the expense of a few more cycles inupdate_vsyscall().
The few cycles are one thing. Did you verify that this does not change the cache layout for CLOCK_MONOTONIC and CLOCK_REALTIME? Let's look:
Quoted 9 lines
struct
vgtod_ts{arch/x86/include/asm/vgtod.h +2
-0u64 sec;u64 nsec; +u32 mult; +u32 shift; };#define VGTOD_BASES (CLOCK_TAI + 1)
arch/x86/include/asm/vgtod.h struct vsyscall_gtod_data { · line 46
Quoted 7 lines
arch/x86/include/asm/vgtod.h +0
-2@@ -40,8 +42,6 @@ struct vsyscall_gtod_data {int vclock_mode;u64 cycle_last; -u32 mult; -u32 shift;struct vgtod_ts basetime[VGTOD_BASES ];
The current state is:
struct vsyscall_gtod_data {
unsigned int seq; /* 0 4 */ int vclock_mode; /* 4 4 */ u64 cycle_last; /* 8 8 */ u64 mask; /* 16 8 */ u32 mult; /* 24 4 */ u32 shift; /* 28 4 */ struct vgtod_ts basetime[12]; /* 32 192 */
basetime[CLOCK_REALTIME] 32 .. 47
basetime[CLOCK_MONOTONIC] 48 .. 63So with your change it looks like this:
struct vsyscall_gtod_data {
unsigned int seq; /* 0 4 */ int vclock_mode; /* 4 4 */ u64 cycle_last; /* 8 8 */ struct vgtod_ts basetime[12]; /* 16 288 */
which makes
basetime[CLOCK_REALTIME] 16 .. 39
basetime[CLOCK_MONOTONIC] 40 .. 63So it stays in the same cache line, but as we move the VDSO to generic code, the mask field needs to stay and this will make basetime[CLOCK_MONOTONIC] overlap into the next cache line.
See https://lkml.kernel.org/r/[email protected]
for an alternate solution to this problem, which avoids this and just gives CLOCK_MONOTONIC_RAW a separate storage space alltogether.
Thanks,
tglx
Re: [PATCH 2/3] x86/vdso: Allow clock specific mult and shift values
Quoted 3 lines · Thomas Gleixner
So it stays in the same cache line, but as we move the VDSO to generic code, the mask field needs to stay and this will make basetime[CLOCK_MONOTONIC] overlap into the next cache line.
Thanks for the great review; this is a good point.
Quoted 3 lines
See https://lkml.kernel.org/r/[email protected]
for an alternate solution to this problem, which avoids this and just givesCLOCK_MONOTONIC_RAWa separate storage space alltogether.
I can certainly do this for the x86 vdso. Would that be useful or should I wait for Vincenzo's work on the generic vdso first?
Many thanks,
Huw.
Re: [PATCH 2/3] x86/vdso: Allow clock specific mult and shift values
Quoted 5 lines · Huw Davies
Quoted 3 lines · Thomas Gleixner
So it stays in the same cache line, but as we move the VDSO to generic code, the mask field needs to stay and this will make basetime[CLOCK_MONOTONIC] overlap into the next cache line.
Quoted 8 lines
Thanks for the great review; this is a good point.
Quoted 3 lines
See https://lkml.kernel.org/r/[email protected]
for an alternate solution to this problem, which avoids this and just givesCLOCK_MONOTONIC_RAWa separate storage space alltogether.I can certainly do this for the x86 vdso. Would that be useful or should I wait for Vincenzo's work on the generic vdso first?
Depends. If Vincenzo comes along with his new version soon, then you might get this for free :)
Vincenzo, what's the state of your work?
Thanks,
tglx
Re: [PATCH 2/3] x86/vdso: Allow clock specific mult and shift values
Hi Thomas,
Quoted 13 lines · Thomas Gleixner
Quoted 11 lines · Huw Davies
Quoted 3 lines · Thomas Gleixner
So it stays in the same cache line, but as we move the VDSO to generic code, the mask field needs to stay and this will make basetime[CLOCK_MONOTONIC] overlap into the next cache line.
Thanks for the great review; this is a good point.
Quoted 3 lines
See https://lkml.kernel.org/r/[email protected]
for an alternate solution to this problem, which avoids this and just givesCLOCK_MONOTONIC_RAWa separate storage space alltogether.
Quoted 8 lines
Quoted 2 lines
I can certainly do this for the x86 vdso. Would that be useful or should I wait for Vincenzo's work on the generic vdso first?
Depends. If Vincenzo comes along with his new version soon, then you might get this for free :)
Vincenzo, what's the state of your work?
I am mostly done with the development, the only thing missing is the integration of the generic update_vsyscall. After this is complete, I will need to do some testing and extract the performance numbers.
Considering that I will be on Easter holiday from this Wednesday till the end of April, I think v6 will be ready around second week of May.
Quoted 4 lines
Thanks,
tglx
Signature · 2 lines
Regards, Vincenzo
Re: [PATCH 2/3] x86/vdso: Allow clock specific mult and shift values
Quoted 16 lines · Vincenzo Frascino
Quoted 6 lines · Thomas Gleixner
Quoted 5 lines · Huw Davies
Quoted 3 lines · Thomas Gleixner
See https://lkml.kernel.org/r/[email protected]
for an alternate solution to this problem, which avoids this and just givesCLOCK_MONOTONIC_RAWa separate storage space alltogether.Quoted 8 lines
Quoted 2 lines
I can certainly do this for the x86 vdso. Would that be useful or should I wait for Vincenzo's work on the generic vdso first?
Depends. If Vincenzo comes along with his new version soon, then you might get this for free :)
Vincenzo, what's the state of your work?
Quoted 6 lines
I am mostly done with the development, the only thing missing is the integration of the generic
update_vsyscall. After this is complete, I will need to do some testing and extract the performance numbers.Considering that I will be on Easter holiday from this Wednesday till the end of April, I think v6 will be ready around second week of May.
Hi Vincenzo,
Great! In which case there's not much point in me changing the x86 vdso---it'll just end up making more work for you.
Let me know if there's anything I can help with.
Huw.
Re: [PATCH 2/3] x86/vdso: Allow clock specific mult and shift values
Hi Huw,
Quoted 24 lines · Huw Davies
Quoted 16 lines · Vincenzo Frascino
Quoted 6 lines · Thomas Gleixner
Quoted 5 lines · Huw Davies
Quoted 3 lines · Thomas Gleixner
See https://lkml.kernel.org/r/[email protected]
for an alternate solution to this problem, which avoids this and just givesCLOCK_MONOTONIC_RAWa separate storage space alltogether.Quoted 8 lines
Quoted 2 lines
I can certainly do this for the x86 vdso. Would that be useful or should I wait for Vincenzo's work on the generic vdso first?
Depends. If Vincenzo comes along with his new version soon, then you might get this for free :)
Vincenzo, what's the state of your work?
Quoted 6 lines
I am mostly done with the development, the only thing missing is the integration of the generic
update_vsyscall. After this is complete, I will need to do some testing and extract the performance numbers.Considering that I will be on Easter holiday from this Wednesday till the end of April, I think v6 will be ready around second week of May.
Quoted 7 lines
Hi Vincenzo,
Great! In which case there's not much point in me changing the x86 vdso---it'll just end up making more work for you.
Let me know if there's anything I can help with.
I wanted to let you know that I just posted my updated patchset for unifying vdso. I should have tested it enough (I hope :) ), but if your help offer is still valid, and you want to give it a go, you are more than welcome.
Please let me know if you find any issue.
Quoted 2 lines
Huw.
Signature · 2 lines
Regards, Vincenzo
PATCH 3/3 x86/vdso: Add support for CLOCK_MONOTONIC_RAW in the vDSO
In reply to Huw DaviesThis is particularly useful for Wine which needs to implement Win32 API clock functions whose values do not get adjusted by adjtimex().
--- arch/x86/entry/vsyscall/vsyscall_gtod.c | 6 ++++++ arch/x86/include/asm/vgtod.h | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-)
arch/x86/entry/vsyscall/vsyscall_gtod.c +6 -0
@@ -68,6 +68,12 @@ void update_vsyscall(struct timekeeper *tk) base->mult = tk->tkr_mono.mult; base->shift = tk->tkr_mono.shift; + base = &vdata->basetime[CLOCK_MONOTONIC_RAW ]; + base->sec = tk->raw_sec; + base->nsec = tk->tkr_raw.xtime_nsec; + base->mult = tk->tkr_raw.mult; + base->shift = tk->tkr_raw.shift; + base = &vdata->basetime[CLOCK_REALTIME_COARSE ]; base->sec = tk->xtime_sec; base->nsec = tk->tkr_mono.xtime_nsec >> tk->tkr_mono.shift;
arch/x86/include/asm/vgtod.h +2 -1
@@ -30,7 +30,8 @@ struct vgtod_ts { };#define VGTOD_BASES (CLOCK_TAI + 1) -#define VGTOD_HRES (BIT(CLOCK_REALTIME) | BIT(CLOCK_MONOTONIC) | BIT(CLOCK_TAI)) +#define VGTOD_HRES (BIT(CLOCK_REALTIME) | BIT(CLOCK_MONOTONIC) | \ + BIT(CLOCK_MONOTONIC_RAW) | BIT(CLOCK_TAI))#define VGTOD_COARSE (BIT(CLOCK_REALTIME_COARSE) | BIT(CLOCK_MONOTONIC_COARSE))/*
Signature · 1 line
2.17.1