pvclock cleanups and pvclock vsyscall support
Subsystems (6)
Hi all,
This series contains several things:
- Unify the separate vdso and vsyscall implementations of vgettimeofday and vgetcpu. There's at least one bugfix which was only applied to one copy (ignore tcache in vgetcpu was only applied to the vdso version); this should avoid such skews in future.
- Bug fixes for the Xen and KVM clocksource.read functions to make sure the returned time doesn't regress compared to clocksource.cycle_last. (Probably stable material.)
- Make sure the pvclock rdtsc is surrounded by appropriate barriers so that it doesn't get speculated to the wrong place with respect to reading the time parameters. (Probably stable material.)
- General cleanups of the pvclock algorithm (there's no need to make a local copy of the time parameters before use).
- Add a new CONFIG_X86_VSYSCALL to control the compilation of vsyscall-related code rather than just using CONFIG_X86_64 - we may want to implement 32-bit vsyscall at some point, and this will make it easier.
- Add the sched notifier for task migration between CPUs, for use by pvclock vread.
- Implement a pvclock vread function, so that pvclock-using clocksources can be used by vsyscall/vdso vgettimeofday and vclock_gettime.
- Use pvclock vread in the Xen clocksource.
The following changes since commit 74fca6a42863ffacaf7ba6f1936a9f228950f657:
Linus Torvalds (1):
Linux 2.6.31
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/jeremy/xen.git xen/vsyscall
Jeremy Fitzhardinge (12):
x86/vsyscall: use common implementation for vgetcpu x86/vgetcpu: ignore tcache in common code. x86/vsyscall: use common implementation for vgettimeofday kvm/pvclock: add monotonicity check
xen/pvclock: add monotonicity check
x86/pvclock: make sure rdtsc doesn't speculate out of region
pvclock: there's no need to copy time_info into shadow
x86: create specific X86_VSYSCALL config variable
sched: add notifier for cross-cpu migrations x86/pvclock: add vsyscall implementation x86/fixmap: add a predicate for usermode fixmaps xen/time: add pvclock_clocksource_vread support
arch/x86/Kconfig | 10 ++- arch/x86/include/asm/fixmap.h | 25 +++++- arch/x86/include/asm/pvclock.h | 6 ++ arch/x86/include/asm/vgtod.h | 64 +++++++++++++- arch/x86/include/asm/vsyscall.h | 30 ++++++ arch/x86/kernel/Makefile | 5 +- arch/x86/kernel/hpet.c | 4 +- arch/x86/kernel/kvmclock.c | 7 ++- arch/x86/kernel/pvclock.c | 186 +++++++++++++++++++++++++++++--------- arch/x86/kernel/tsc.c | 4 +- arch/x86/kernel/vsyscall_64.c | 91 +------------------- arch/x86/vdso/vclock_gettime.c | 46 +--------- arch/x86/vdso/vgetcpu.c | 17 +--- arch/x86/xen/Kconfig | 6 ++ arch/x86/xen/mmu.c | 5 +- arch/x86/xen/smp.c | 2 + arch/x86/xen/time.c | 61 +++++++++++++- arch/x86/xen/xen-ops.h | 8 ++ include/linux/sched.h | 8 ++ include/xen/interface/vcpu.h | 41 +++++++++ kernel/sched.c | 14 +++ 21 files changed, 438 insertions(+), 202 deletions(-)
PATCH 1/12 x86/vsyscall: use common implementation for vgetcpu
There were two implementations of vgetcpu: one for vdso and one for vsyscalls. They are actually functionally different, as the vdso one ignores the tcache parameter (due to change 4307d1e5ada595c8), but the vsyscall implementation honours it. This patch preserves that functional difference, but a subsequent will make both behave the same way.
The actual compiled code is still duplicated as the vdso and vsyscall environments are quite different (variable vs fixed address, for example), and the access to kernel variables is different as well. The implementation is made common as an inline functions, so there's only one copy of the source.
--- arch/x86/include/asm/vsyscall.h | 38 ++++++++++++++++++++++++++++++++++++++ arch/x86/kernel/vsyscall_64.c | 30 +----------------------------- arch/x86/vdso/vgetcpu.c | 18 +++--------------- 3 files changed, 42 insertions(+), 44 deletions(-)
arch/x86/include/asm/vsyscall.h +38 -0
@@ -39,6 +39,44 @@ extern struct timezone sys_tz;extern void map_vsyscall (void ); +#include <linux/getcpu.h> + +static __always_inline +int __vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache, +unsigned long jiffies,int vgetcpu_mode) +{ +unsigned int p; +unsigned long j =0 ; + +/* Fast cache - only recompute value once per jiffies and avoid +relatively costly rdtscp/cpuid otherwise. +This works because the scheduler usually keeps the process +on the same CPU and this syscall doesn't guarantee its +results anyways. +We do this here because otherwise user space would do it on +its own in a likely inferior way (no access to jiffies). +If you don't like it pass NULL. */ +if (tcache && tcache->blob[0 ] == (j = jiffies)) { + p = tcache->blob[1 ]; + }else if (vgetcpu_mode ==VGETCPU_RDTSCP ) { +/* Load per CPU data from RDTSCP */ +native_read_tscp (&p); + }else { +/* Load per CPU data from GDT */ + asm("lsl %1,%0" :"=r" (p) :"r" (__PER_CPU_SEG)); + } +if (tcache) { + tcache->blob[0 ] = j; + tcache->blob[1 ] = p; + } +if (cpu) + *cpu = p &0xfff ; +if (node) + *node = p >>12 ; +return 0 ; +} + +#endif /* __KERNEL__ */ #endif /* _ASM_X86_VSYSCALL_H */
arch/x86/kernel/vsyscall_64.c +1 -29
@@ -190,35 +190,7 @@ time_t __vsyscall(1) vtime(time_t *t) long __vsyscall(2) vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache) { -unsigned int p; -unsigned long j =0 ; - -/* Fast cache - only recompute value once per jiffies and avoid -relatively costly rdtscp/cpuid otherwise. -This works because the scheduler usually keeps the process -on the same CPU and this syscall doesn't guarantee its -results anyways. -We do this here because otherwise user space would do it on -its own in a likely inferior way (no access to jiffies). -If you don't like it pass NULL. */ -if (tcache && tcache->blob[0 ] == (j = __jiffies)) { - p = tcache->blob[1 ]; - }else if (__vgetcpu_mode ==VGETCPU_RDTSCP ) { -/* Load per CPU data from RDTSCP */ -native_read_tscp (&p); - }else { -/* Load per CPU data from GDT */ - asm("lsl %1,%0" :"=r" (p) :"r" (__PER_CPU_SEG)); - } -if (tcache) { - tcache->blob[0 ] = j; - tcache->blob[1 ] = p; - } -if (cpu) - *cpu = p &0xfff ; -if (node) - *node = p >>12 ; -return 0 ; +return __vgetcpu (cpu, node, tcache, __jiffies, __vgetcpu_mode); } static long __vsyscall(3) venosys_1(void)
arch/x86/vdso/vgetcpu.c +3 -15
@@ -14,22 +14,10 @@#include "vextern.h" notrace long -__vdso_getcpu (unsigned *cpu,unsigned *node,struct getcpu_cache *unused) +__vdso_getcpu (unsigned *cpu,unsigned *node,struct getcpu_cache *tcache) { -unsigned int p; - -if (*vdso_vgetcpu_mode ==VGETCPU_RDTSCP ) { -/* Load per CPU data from RDTSCP */ -native_read_tscp (&p); - }else { -/* Load per CPU data from GDT */ - asm("lsl %1,%0" :"=r" (p) :"r" (__PER_CPU_SEG)); - } -if (cpu) - *cpu = p &0xfff ; -if (node) - *node = p >>12 ; -return 0 ; +/* Ignore tcache to preserve old behaviour */ +return __vgetcpu (cpu, node,NULL , *vdso_jiffies, *vdso_vgetcpu_mode); }long getcpu (unsigned *cpu,unsigned *node,struct getcpu_cache *tcache)
Signature · 1 line
1.6.2.5
PATCH 2/12 x86/vgetcpu: ignore tcache in common code.
In reply to Jeremy FitzhardingeThe vdso implementation of vgetcpu has been ignoring the tcache parameter since change 4307d1e5ada595c87f9a4d16db16ba5edb70dcb1, but that overlooked the vsyscall implementation of vgetcpu.
This change ignores tcache in the common code, but passes the pointer in from vdso so that it can be still used if there's a new tcache implementation which addresses the problems mentioned in 4307d1e5ada595c87f.
--- arch/x86/include/asm/vsyscall.h | 19 ++++--------------- arch/x86/vdso/vgetcpu.c | 3 +-- 2 files changed, 5 insertions(+), 17 deletions(-)
arch/x86/include/asm/vsyscall.h +4 -15
@@ -48,27 +48,16 @@ int __vgetcpu(unsigned *cpu, unsigned *node, struct getcpu_cache *tcache,unsigned int p;unsigned long j =0 ; -/* Fast cache - only recompute value once per jiffies and avoid -relatively costly rdtscp/cpuid otherwise. -This works because the scheduler usually keeps the process -on the same CPU and this syscall doesn't guarantee its -results anyways. -We do this here because otherwise user space would do it on -its own in a likely inferior way (no access to jiffies). -If you don't like it pass NULL. */ -if (tcache && tcache->blob[0 ] == (j = jiffies)) { - p = tcache->blob[1 ]; - }else if (vgetcpu_mode ==VGETCPU_RDTSCP ) { +/* tcache is ignored - it is too unreliable */ + +if (vgetcpu_mode ==VGETCPU_RDTSCP ) {/* Load per CPU data from RDTSCP */ native_read_tscp (&p); }else {/* Load per CPU data from GDT */ asm("lsl %1,%0" :"=r" (p) :"r" (__PER_CPU_SEG)); } -if (tcache) { - tcache->blob[0 ] = j; - tcache->blob[1 ] = p; - } +if (cpu) *cpu = p &0xfff ;if (node)
arch/x86/vdso/vgetcpu.c +1 -2
@@ -16,8 +16,7 @@notrace long __vdso_getcpu (unsigned *cpu,unsigned *node,struct getcpu_cache *tcache) { -/* Ignore tcache to preserve old behaviour */ -return __vgetcpu (cpu, node,NULL , *vdso_jiffies, *vdso_vgetcpu_mode); +return __vgetcpu (cpu, node, tcache, *vdso_jiffies, *vdso_vgetcpu_mode); }long getcpu (unsigned *cpu,unsigned *node,struct getcpu_cache *tcache)
Signature · 1 line
1.6.2.5
PATCH 3/12 x86/vsyscall: use common implementation for vgettimeofday
In reply to Jeremy FitzhardingeThere are two implementations of vgettimeofday; one as a vsyscall and one in the vdso. The are functionally identical, but the code is duplicated in two more-or-less equivalent forms.
The vdso implementation is also shared with the vdso vclock_gettime.
To unify the two implementations, the vdso code is hoisted into vgtod.h as inline functions, and the callers modified accordingly. Because vdso and vsyscall have different ways to access struct vsyscall_gtod_data, it is passed into each function.
--- arch/x86/include/asm/vgtod.h | 64 +++++++++++++++++++++++++++++++++++++++- arch/x86/kernel/vsyscall_64.c | 61 +------------------------------------- arch/x86/vdso/vclock_gettime.c | 46 ++--------------------------- 3 files changed, 67 insertions(+), 104 deletions(-)
arch/x86/include/asm/vgtod.h +63 -1
@@ -1,9 +1,11 @@ #ifndef _ASM_X86_VGTOD_H #define _ASM_X86_VGTOD_H -#include <asm/vsyscall.h> #include <linux/clocksource.h> +#include <asm/vsyscall.h> +#include <asm/unistd.h> + struct vsyscall_gtod_data { seqlock_t lock;
@@ -26,4 +28,64 @@ extern struct vsyscall_gtod_data __vsyscall_gtod_data __section_vsyscall_gtod_data;extern struct vsyscall_gtod_data vsyscall_gtod_data; +/* +* Common implementation of vdso/vsyscall time functions. This code +* is used in usermode, exported via either vdso or vsyscall. Because +* of this, it must be inlined rather than linked, hence implemented +* in a .h as inline functions. +*/ +notrace static __always_inline +long vgetns (const struct vsyscall_gtod_data *gtod) +{ +long v; +cycles_t (*vread)(void); + + vread = gtod->clock.vread; + v = (vread () - gtod->clock.cycle_last) & gtod->clock.mask; +return (v * gtod->clock.mult) >> gtod->clock.shift; +} + +notrace static __always_inline +int __do_realtime (const struct vsyscall_gtod_data *gtod, +struct timespec *ts) +{ +unsigned long seq, ns; +do { + seq =read_seqbegin (>od->lock); + ts->tv_sec = gtod->wall_time_sec; + ts->tv_nsec = gtod->wall_time_nsec; + ns =vgetns (gtod); + }while (unlikely (read_seqretry (>od->lock, seq))); +timespec_add_ns (ts, ns); +return 0 ; +} + +notrace static __always_inline +int __do_vgettimeofday (const struct vsyscall_gtod_data *gtod, +struct timeval *tv,struct timezone *tz) +{ +long ret; + +if (likely (gtod->sysctl_enabled && gtod->clock.vread)) { +if (likely (tv !=NULL )) { +BUILD_BUG_ON (offsetof(struct timeval , tv_usec) != + offsetof(struct timespec , tv_nsec) || +sizeof (*tv) !=sizeof (struct timespec )); +__do_realtime (gtod, (struct timespec *)tv); + tv->tv_usec /=1000 ; + } + +if (unlikely (tz !=NULL )) { +/* Avoid memcpy. Some old compilers fail to inline it */ + tz->tz_minuteswest = gtod->sys_tz.tz_minuteswest; + tz->tz_dsttime = gtod->sys_tz.tz_dsttime; + } +return 0 ; + } + + asm("syscall" :"=a" (ret) : +"0" (__NR_gettimeofday),"D" (tv),"S" (tz) :"memory" ); +return ret; +} +#endif /* _ASM_X86_VGTOD_H */
arch/x86/kernel/vsyscall_64.c +1 -60
75 lines not on this page · raw message
arch/x86/vdso/vclock_gettime.c +3 -43
70 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 4/12 kvm/pvclock: add monotonicity check
In reply to Jeremy FitzhardingeOther tsc-based clocksources add a monotonicity test to make sure there's no regression in the returned cycles.
--- arch/x86/kernel/kvmclock.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/kernel/kvmclock.c +6 -1
@@ -77,9 +77,14 @@ static cycle_t kvm_clock_read(void)return ret; } +static struct clocksource kvm_clock; +static cycle_t kvm_clock_get_cycles (struct clocksource *cs) { -return kvm_clock_read (); +cycle_t ret =kvm_clock_read (); + +return ret >= kvm_clock.cycle_last ? + ret : kvm_clock.cycle_last; }/*
Signature · 1 line
1.6.2.5
PATCH 5/12 xen/pvclock: add monotonicity check
In reply to Jeremy FitzhardingeOther tsc-based clocksources add a monotonicity test to make sure there's no regression in the returned cycles.
--- arch/x86/xen/time.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/xen/time.c +6 -1
@@ -213,9 +213,14 @@ cycle_t xen_clocksource_read(void)return ret; } +static struct clocksource xen_clocksource; +static cycle_t xen_clocksource_get_cycles (struct clocksource *cs) { -return xen_clocksource_read (); +cycle_t ret =xen_clocksource_read (); + +return ret >= xen_clocksource.cycle_last ? + ret : xen_clocksource.cycle_last; }static void xen_read_wallclock (struct timespec *ts)
Signature · 1 line
1.6.2.5
RE: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
Quoted 16 lines
Other tsc-based clocksources add a monotonicity test to make sure there's
no regression in the returned cycles.Signed-off-by Jeremy Fitzhardinge <[email protected]>--- arch/x86/xen/time.c | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)arch/x86/xen/time.c +0
-0@@ -213,9 +213,14 @@ cycle_t xen_clocksource_read(void)return ret; }
arch/x86/xen/time.c cycle_t xen_clocksource_read(void) · line 223
Quoted 10 lines
arch/x86/xen/time.c +6
-1+static struct clocksource xen_clocksource; +static cycle_t xen_clocksource_get_cycles (struct clocksource *cs) { -return xen_clocksource_read (); +cycle_t ret =xen_clocksource_read (); + +return ret >= xen_clocksource.cycle_last ? + ret : xen_clocksource.cycle_last;
As long as we are going through the trouble of making this monotonic, shouldn't it be monotonically increasing (rather than just monotonically non-decreasing)? The rdtsc instruction and any suitably high-precision hardware timer will never return the same value on subsequent uses so this might be a reasonable precedent to obey. E.g.
+ return ret > xen_clocksource.cycle_last ?
+ ret : ++xen_clocksource.cycle_last;
Re: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
Review
Quoted 11 lines · Dan Magenheimer
As long as we are going through the trouble of making this monotonic, shouldn't it be monotonically increasing (rather than just monotonically non-decreasing)? The rdtsc instruction and any suitably high-precision hardware timer will never return the same value on subsequent uses so this might be a reasonable precedent to obey. E.g.
(quoted diff) +2
-0+ return ret > xen_clocksource.cycle_last ? + ret : ++xen_clocksource.cycle_last;
No, cycle_last isn't updated on every read, only on timer ticks. This test doesn't seem to be intended to make sure that every clocksource_read is globally monotonic, but just to avoid some boundary conditions in the timer interrupt. I just copied it directly from read_tsc().
J
RE: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
Quoted 9 lines · Dan Magenheimer
Quoted 8 lines
As long as we are going through the trouble of making this monotonic, shouldn't it be monotonically increasing (rather than just monotonically non-decreasing)? The rdtsc instruction and any suitably high-precision hardware timer will never return the same value on subsequent uses so this might be a reasonable precedent to obey. E.g.
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return ret > xen_clocksource.cycle_last ? + ret : ++xen_clocksource.cycle_last;No,
cycle_lastisn't updated on every read, only on timer ticks. This test doesn't seem to be intended to make sure that everyclocksource_readis globally monotonic, but just to avoid some boundary
conditions in the timer interrupt. I just copied it directly fromread_tsc().
I understand but you are now essentially emulating a reliable platform timer with a potentially unreliable (but still high resolution) per-CPU timer AND probably delivering that result to userland.
Read_tsc should only be used if either CONSTANT_TSC or TSC_RELIABLE is true, so read_tsc is guaranteed to be monotonically-strictly-increasing by hardware (and enforced for CONSTANT_TSC by check_tsc_warp at boot).
Re: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
Quoted 11 lines · Dan Magenheimer
I understand but you are now essentially emulating a reliable platform timer with a potentially unreliable (but still high resolution) per-CPU timer AND probably delivering that result to userland.
Read_tscshould only be used if eitherCONSTANT_TSCorTSC_RELIABLEis true, soread_tscis guaranteed to be monotonically-strictly-increasing by hardware (and enforced forCONSTANT_TSCbycheck_tsc_warpat boot).
read_tsc clearly isn't expected to produce absolutely globally monotonic results; if it were then the check wouldn't be necessary.
J
Re: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
In reply to Dan MagenheimerQuoted 11 lines · Dan Magenheimer
Quoted 11 lines · Dan Magenheimer
Quoted 10 lines
As long as we are going through the trouble of making this monotonic, shouldn't it be monotonically increasing (rather than just monotonically non-decreasing)? The rdtsc instruction and any suitably high-precision hardware timer will never return the same value on subsequent uses so this might be a reasonable precedent to obey. E.g.
+ return ret > xen_clocksource.cycle_last ?
+ ret : ++xen_clocksource.cycle_last;
Oof. Modifying .cycle_last will cause timekeeping wreckage. Please don't. Also the above would break on SMP.
Ideally we would have moved cycle_last to the timekeeper structure, since its a timekeeping specific value, not really clocksource related.
However, there is the situation where we have don't have perfectly synced TSCs, but TSCs that are very very close. In this case, the only time we might see skew is if update_wall time were to run on the slightly faster TSC, and then immediately after the gettimeofday() code runs and sees the cycle_last value ahead of the rdtsc.
So the cycle_last check is hackish, but it lets folks use the much faster TSC when we'd have to otherwise throw it out.
If you wanted something like this, a global last_tsc value could be used and cmpxchged to ensure you always have an increasing TSC value. However I suspect the performance hit there would be painful.
Quoted 12 lines
Quoted 6 lines
No,
cycle_lastisn't updated on every read, only on timer ticks. This test doesn't seem to be intended to make sure that everyclocksource_readis globally monotonic, but just to avoid some boundary
conditions in the timer interrupt. I just copied it directly fromread_tsc().I understand but you are now essentially emulating a reliable platform timer with a potentially unreliable (but still high resolution) per-CPU timer AND probably delivering that result to userland.
Quoted 5 lines
Read_tscshould only be used if eitherCONSTANT_TSCorTSC_RELIABLEis true, soread_tscis guaranteed to be monotonically-strictly-increasing by hardware (and enforced forCONSTANT_TSCbycheck_tsc_warpat boot).
Ideally, yes, only perfect TSCs should be used.
But in reality, its a big performance win for folks who can get away with just slightly offset TSCs.
thanks
-john
Re: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
Quoted 18 lines · john stultz
Quoted 12 lines
Quoted 7 lines
No,
cycle_lastisn't updated on every read, only on timer ticks. This test doesn't seem to be intended to make sure that everyclocksource_readis globally monotonic, but just to avoid some boundary
conditions in the timer interrupt. I just copied it directly fromread_tsc().I understand but you are now essentially emulating a reliable platform timer with a potentially unreliable (but still high resolution) per-CPU timer AND probably delivering that result to userland.
Quoted 6 lines
Read_tscshould only be used if eitherCONSTANT_TSCorTSC_RELIABLEis true, soread_tscis guaranteed to be monotonically-strictly-increasing by hardware (and enforced forCONSTANT_TSCbycheck_tsc_warpat boot).
Quoted 5 lines
Ideally, yes, only perfect TSCs should be used.
But in reality, its a big performance win for folks who can get away with just slightly offset TSCs.
What monotonicity guarantees do we make to usermode, for both syscall and vsyscall gettimeofday and clock_gettime?
Though its not clear to me how usermode would even notice very small amounts of cross-thread/cpu non-monotonicity anyway. It would need make sure that it samples the time and stores it to some globally visible place atomically (with locks, compare-and-swap, etc), which is going to be pretty expensive. And if its going to all that effort it may as well do its own monotonicity checking/adjustments if its all that important.
(I can think of plenty of ways of doing it incorrectly, where you'd get apparent non-monotonicity regardless of the quality of the time source.)
J
Re: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
Quoted 19 lines · Jeremy Fitzhardinge
Quoted 18 lines · john stultz
Quoted 18 lines
Quoted 7 lines
No,
cycle_lastisn't updated on every read, only on timer ticks. This test doesn't seem to be intended to make sure that everyclocksource_readis globally monotonic, but just to avoid some boundary
conditions in the timer interrupt. I just copied it directly fromread_tsc().I understand but you are now essentially emulating a reliable platform timer with a potentially unreliable (but still high resolution) per-CPU timer AND probably delivering that result to userland.
Read_tscshould only be used if eitherCONSTANT_TSCorTSC_RELIABLEis true, soread_tscis guaranteed to be monotonically-strictly-increasing by hardware (and enforced forCONSTANT_TSCbycheck_tsc_warpat boot).
Quoted 8 lines
Quoted 5 lines
Ideally, yes, only perfect TSCs should be used.
But in reality, its a big performance win for folks who can get away with just slightly offset TSCs.
What monotonicity guarantees do we make to usermode, for both syscall and vsyscall gettimeofday and
clock_gettime?
The guarantee is time won't go backwards. It may not always increase, between two calls, but applications should not see a previous time after a later time from clock_gettime/gettimeofday.
Quoted 6 lines
Though its not clear to me how usermode would even notice very small amounts of cross-thread/cpu non-monotonicity anyway. It would need make sure that it samples the time and stores it to some globally visible place atomically (with locks, compare-and-swap, etc), which is going to be pretty expensive. And if its going to all that effort it may as well do its own monotonicity checking/adjustments if its all that important.
If the TSCs are offset enough for a thread to move between cpus and see an inconsistency, then the TSC needs to be thrown out. The TSC sync check at boot should provide this.
The cycle_last check in read_tsc() is really only for very very slight offsets, that would otherwise pass the sync check, and a process could not detect when switching between cpus (the skew would have to be smaller then the time it takes to migrate between cpus).
Quoted 2 lines
(I can think of plenty of ways of doing it incorrectly, where you'd get apparent non-monotonicity regardless of the quality of the time source.)
There's been some interesting talk of creating a more offset-robust TSC clocksource using a per-cpu TSC offsets synced periodically against a global counter like the HPET. It seems like it could work, but there are a lot of edge cases and it really has to be right all of the time, so I don't think its quite as trivial as some folks have thought. But it would be interesting to see!
thanks
-john
Re: [Xen-devel] [PATCH 05/12] xen/pvclock: add monotonicity check
Quoted 10 lines · john stultz
Quoted 3 lines
(I can think of plenty of ways of doing it incorrectly, where you'd get apparent non-monotonicity regardless of the quality of the time source.)
There's been some interesting talk of creating a more offset-robust TSC clocksource using a per-cpu TSC offsets synced periodically against a global counter like the HPET. It seems like it could work, but there are a lot of edge cases and it really has to be right all of the time, so I don't think its quite as trivial as some folks have thought. But it would be interesting to see!
Xen and KVM do this already. The host system provides the tsc rate and offset information for each cpu so that the guest kernel can compute a global system time (ns since boot) from the tsc.
I suspect its quite difficult to guarantee that you get completely monotonic results if the tscs are at different rates, but if they're the same rate but merely offset it should give completely OK results.
J
PATCH 6/12 x86/pvclock: make sure rdtsc doesn't speculate out of region
In reply to Jeremy Fitzhardingerdtsc is not necessarily ordered with surrounding instructions so we need to make sure that it doesn't get sampled out of order with respect to reading the time_info.
--- arch/x86/kernel/pvclock.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/pvclock.c +2 -2
@@ -117,10 +117,10 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)do { version =pvclock_get_time_values (&shadow, src); -barrier (); +rdtsc_barrier (); offset =pvclock_get_nsec_offset (&shadow); ret = shadow.system_timestamp + offset; -barrier (); +rdtsc_barrier (); }while (version != src->version);return ret;
Signature · 1 line
1.6.2.5
PATCH 7/12 pvclock: there's no need to copy time_info into shadow
In reply to Jeremy FitzhardingeWe can use the vcpu_time_info as-is, without needing to copy it. We just need to grab a copy of the version number before starting, then we can compute the time using the time_info directly. If things changed under our feet, then we just go back and do the whole thing again.
--- arch/x86/kernel/pvclock.c | 47 +++++--------------------------------------- 1 files changed, 6 insertions(+), 41 deletions(-)
arch/x86/kernel/pvclock.c +6 -41
@@ -20,20 +20,6 @@#include <asm/pvclock.h> /* -* These are perodically updated -* xen: magic shared_info page -* kvm: gpa registered via msr -* and then copied here. -*/ -struct pvclock_shadow_time { -u64 tsc_timestamp;/* TSC at last update of time vals. */ -u64 system_timestamp;/* Time, in nanosecs, since boot. */ -u32 tsc_to_nsec_mul; -int tsc_shift; -u32 version; -}; - -/* * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, * yielding a 64-bit result. */
@@ -71,30 +57,10 @@ static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift)return product; } -static u64 pvclock_get_nsec_offset (struct pvclock_shadow_time *shadow) -{ -u64 delta =native_read_tsc () - shadow->tsc_timestamp; -return scale_delta (delta, shadow->tsc_to_nsec_mul, shadow->tsc_shift); -} - -/* -* Reads a consistent set of time-base values from hypervisor, -* into a shadow data area. -*/ -static unsigned pvclock_get_time_values (struct pvclock_shadow_time *dst, -struct pvclock_vcpu_time_info *src) +static u64 pvclock_get_nsec_offset (const struct pvclock_vcpu_time_info *src) { -do { - dst->version = src->version; -rmb ();/* fetch version before data */ - dst->tsc_timestamp = src->tsc_timestamp; - dst->system_timestamp = src->system_time; - dst->tsc_to_nsec_mul = src->tsc_to_system_mul; - dst->tsc_shift = src->tsc_shift; -rmb ();/* test version after fetching data */ - }while ((src->version &1 ) || (dst->version != src->version)); - -return dst->version; +u64 delta =native_read_tsc () - src->tsc_timestamp; +return scale_delta (delta, src->tsc_to_system_mul, src->tsc_shift); }unsigned long pvclock_tsc_khz (struct pvclock_vcpu_time_info *src)
@@ -111,15 +77,14 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)cycle_t pvclock_clocksource_read (struct pvclock_vcpu_time_info *src) { -struct pvclock_shadow_time shadow;unsigned version;cycle_t ret, offset;do { - version =pvclock_get_time_values (&shadow, src); + version = src->version;rdtsc_barrier (); - offset =pvclock_get_nsec_offset (&shadow); - ret = shadow.system_timestamp + offset; + offset =pvclock_get_nsec_offset (src); + ret = src->system_time + offset;rdtsc_barrier (); }while (version != src->version);
Signature · 1 line
1.6.2.5
PATCH 8/12 x86: create specific X86_VSYSCALL config variable
In reply to Jeremy Fitzhardingevsyscalls are only implemented on 64-bit at present, though there's no fundimental reason why they couldn't be implemented for 32-bit. Create a new CONFIG_X86_VSYSCALL to control compilation of vsyscall-related code and definitions to make it clearer where they are.
--- arch/x86/Kconfig | 6 +++++- arch/x86/include/asm/fixmap.h | 7 +++++-- arch/x86/kernel/Makefile | 3 ++- arch/x86/kernel/hpet.c | 4 ++-- arch/x86/kernel/tsc.c | 4 ++-- 5 files changed, 16 insertions(+), 8 deletions(-)
arch/x86/Kconfig +5 -1
@@ -136,7 +136,7 @@ config GENERIC_CALIBRATE_DELAY config GENERIC_TIME_VSYSCALL bool - default X86_64 + default X86_VSYSCALL config ARCH_HAS_CPU_RELAX def_bool y
@@ -222,6 +222,10 @@ config X86_32_LAZY_GS def_bool y depends on X86_32 && !CC_STACKPROTECTOR +config X86_VSYSCALL + def_bool y + depends on X86_64 + config KTIME_SCALAR def_bool X86_32 source "init/Kconfig"
arch/x86/include/asm/fixmap.h +5 -2
@@ -74,12 +74,15 @@ enum fixed_addresses {#ifdef CONFIG_X86_32 FIX_HOLE, FIX_VDSO, -#else +#endif + +#ifdef CONFIG_X86_VSYSCALL VSYSCALL_LAST_PAGE ,VSYSCALL_FIRST_PAGE =VSYSCALL_LAST_PAGE + ((VSYSCALL_END -VSYSCALL_START ) >>PAGE_SHIFT ) -1 ,VSYSCALL_HPET , -#endif +#endif /* CONFIG_X86_VSYSCALL */ +FIX_DBGP_BASE ,FIX_EARLYCON_MEM_BASE , #ifdef CONFIG_X86_LOCAL_APIC
arch/x86/kernel/Makefile +2 -1
@@ -37,7 +37,8 @@ obj-$(CONFIG_X86_VISWS) += visws_quirks.o obj-$(CONFIG_X86_32) += probe_roms_32.o obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o -obj-$(CONFIG_X86_64) += syscall_64.o vsyscall_64.o +obj-$(CONFIG_X86_64) += syscall_64.o +obj-$(CONFIG_X86_VSYSCALL) += vsyscall_64.o obj-y += bootflag.o e820.o obj-y += pci-dma.o quirks.o i8237.o topology.o kdebugfs.o obj-y += alternative.o i8253.o pci-nommu.o
arch/x86/kernel/hpet.c +2 -2
@@ -744,7 +744,7 @@ static cycle_t read_hpet(struct clocksource *cs)return (cycle_t )hpet_readl (HPET_COUNTER ); } -#ifdef CONFIG_X86_64 +#ifdef CONFIG_X86_VSYSCALL static cycle_t __vsyscall_fn vread_hpet(void) {return readl ((const void __iomem *)fix_to_virt (VSYSCALL_HPET ) +0xf0 );
@@ -759,7 +759,7 @@ static struct clocksource clocksource_hpet = { .shift = HPET_SHIFT, .flags = CLOCK_SOURCE_IS_CONTINUOUS, .resume = hpet_resume_counter, -#ifdef CONFIG_X86_64 +#ifdef CONFIG_X86_VSYSCALL .vread = vread_hpet,#endif };
arch/x86/kernel/tsc.c +2 -2
@@ -725,7 +725,7 @@ static cycle_t read_tsc(struct clocksource *cs) ret : clocksource_tsc.cycle_last; } -#ifdef CONFIG_X86_64 +#ifdef CONFIG_X86_VSYSCALL static cycle_t __vsyscall_fn vread_tsc(void) {cycle_t ret;
@@ -752,7 +752,7 @@ static struct clocksource clocksource_tsc = { .shift = 22, .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_MUST_VERIFY, -#ifdef CONFIG_X86_64 +#ifdef CONFIG_X86_VSYSCALL .vread = vread_tsc,#endif };
Signature · 1 line
1.6.2.5
PATCH 9/12 sched: add notifier for cross-cpu migrations
In reply to Jeremy FitzhardingeAdd a notifier to publish when a task gets migrated from one cpu to another. The first intended use is to export a "migration counter" to usermode so that a task can tell whether its still running on the same cpu (for use in vgetcpu and other vsyscall code).
--- include/linux/sched.h | 8 ++++++++ kernel/sched.c | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
include/linux/sched.h +8 -0
@@ -141,6 +141,14 @@ extern unsigned long nr_iowait(void);extern void calc_global_load (void );extern u64 cpu_nr_migrations (int cpu); +/* Notifier for when a task gets migrated to a new CPU */ +struct task_migration_notifier { +struct task_struct *task; +int from_cpu; +int to_cpu; +}; +extern void register_task_migration_notifier (struct notifier_block *n); +extern unsigned long get_parent_ip (unsigned long addr);struct seq_file ;
kernel/sched.c +14 -0
@@ -1951,6 +1951,12 @@ task_hot(struct task_struct *p, u64 now, struct sched_domain *sd)return delta < (s64 )sysctl_sched_migration_cost; } +static ATOMIC_NOTIFIER_HEAD (task_migration_notifier); + +void register_task_migration_notifier (struct notifier_block *n) +{ +atomic_notifier_chain_register (&task_migration_notifier, n); +}void set_task_cpu (struct task_struct *p,unsigned int new_cpu) {
@@ -1973,6 +1979,8 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu) p->se.block_start -= clock_offset;#endif if (old_cpu != new_cpu) { +struct task_migration_notifier tmn; + p->se.nr_migrations++; new_rq->nr_migrations_in++;#ifdef CONFIG_SCHEDSTATS
@@ -1981,6 +1989,12 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu)#endif perf_swcounter_event (PERF_COUNT_SW_CPU_MIGRATIONS ,1 ,1 ,NULL ,0 ); + + tmn.task = p; + tmn.from_cpu = old_cpu; + tmn.to_cpu = new_cpu; + +atomic_notifier_call_chain (&task_migration_notifier,0 , &tmn); } p->se.vruntime -= old_cfsrq->min_vruntime - new_cfsrq->min_vruntime;
Signature · 1 line
1.6.2.5
PATCH 10/12 x86/pvclock: add vsyscall implementation
In reply to Jeremy FitzhardingeThis patch allows the pvclock mechanism to be used in usermode. To do this, we map an extra page into usermode containing an array of pvclock_vcpu_time_info structures which give the information required to compute a global system clock from the tsc. With this, we can implement pvclock_clocksource_vread().
One complication is that usermode is subject to two levels of scheduling:
kernel scheduling of tasks onto vcpus, and hypervisor scheduling of vcpus onto pcpus. In either case the underlying pcpu changed, and with it, the correct set of parameters to compute tsc->system clock.
To address this we install a task migration notifier to update the "old" vcpu's "migrate_count" number (ie, vcpu has had a task migrated away from it). Usermode can then check the migrate_count while computing the time and retry with a new cpu number if it has changed.
To use this feature, hypervisor-specific code is required to call pvclock_init_vsyscall(), and if successful:
- cause the pvclock_vcpu_time_info structure at pvclock_get_vsyscall_time_info(cpu) to be updated appropriately for each vcpu.
- use pvclock_clocksource_vread as the implementation of clocksource .vread.
--- arch/x86/Kconfig | 4 + arch/x86/include/asm/fixmap.h | 4 +- arch/x86/include/asm/pvclock.h | 6 ++ arch/x86/include/asm/vsyscall.h | 3 + arch/x86/kernel/Makefile | 2 + arch/x86/kernel/pvclock.c | 149 ++++++++++++++++++++++++++++++++++++-- 6 files changed, 159 insertions(+), 9 deletions(-)
arch/x86/Kconfig +4 -0
@@ -522,6 +522,10 @@ config PARAVIRT_CLOCK bool default n +config PARAVIRT_CLOCK_VSYSCALL + bool + depends on PARAVIRT_CLOCK && X86_VSYSCALL + endif config PARAVIRT_DEBUG
arch/x86/include/asm/fixmap.h +3 -1
@@ -82,7 +82,9 @@ enum fixed_addresses { + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1, VSYSCALL_HPET,#endif /* CONFIG_X86_VSYSCALL */ - +#ifdef CONFIG_PARAVIRT_CLOCK_VSYSCALL +FIX_PVCLOCK_TIME_INFO , +#endifFIX_DBGP_BASE ,FIX_EARLYCON_MEM_BASE , #ifdef CONFIG_X86_LOCAL_APIC
arch/x86/include/asm/pvclock.h +6 -0
@@ -3,6 +3,7 @@#include <linux/clocksource.h> #include <asm/pvclock-abi.h> +#include <asm/vsyscall.h> /* some helper functions for xen and kvm pv clock sources */ cycle_t pvclock_clocksource_read (struct pvclock_vcpu_time_info *src);
@@ -11,4 +12,9 @@ void pvclock_read_wallclock(struct pvclock_wall_clock *wall,struct pvclock_vcpu_time_info *vcpu, struct timespec *ts); +int __init pvclock_init_vsyscall (void ); +struct pvclock_vcpu_time_info *pvclock_get_vsyscall_time_info (int cpu); + +cycle_t __vsyscall_fn pvclock_clocksource_vread(void); +#endif /* _ASM_X86_PVCLOCK_H */
arch/x86/include/asm/vsyscall.h +3 -0
@@ -33,6 +33,9 @@ enum vsyscall_num {extern int __vgetcpu_mode;extern volatile unsigned long __jiffies; +struct getcpu_cache ; +extern long vgetcpu (unsigned *cpu,unsigned *node,struct getcpu_cache *tcache); +/* kernel space (writeable) */ extern int vgetcpu_mode;extern struct timezone sys_tz;
arch/x86/kernel/Makefile +2 -0
@@ -24,10 +24,12 @@ CFLAGS_vsyscall_64.o := $(PROFILING) -g0 $(nostackp) CFLAGS_hpet.o := $(nostackp) CFLAGS_tsc.o := $(nostackp) CFLAGS_paravirt.o := $(nostackp) +CFLAGS_pvclock.o := $(nostackp) GCOV_PROFILE_vsyscall_64.o := n GCOV_PROFILE_hpet.o := n GCOV_PROFILE_tsc.o := n GCOV_PROFILE_paravirt.o := n +GCOV_PROFILE_pvclock.o := n obj-y := process_$(BITS).o signal.o entry_$(BITS).o obj-y += traps.o irq.o irq_$(BITS).o dumpstack_$(BITS).o
arch/x86/kernel/pvclock.c +141 -8
177 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 11/12 x86/fixmap: add a predicate for usermode fixmaps
In reply to Jeremy FitzhardingeSome set of fixmaps are intented to be mapped into usermode. Add a predicate to test for those fixmaps.
--- arch/x86/include/asm/fixmap.h | 18 ++++++++++++++++++ 1 files changed, 18 insertions(+), 0 deletions(-)
arch/x86/include/asm/fixmap.h +18 -0
@@ -183,6 +183,24 @@ static inline void __set_fixmap(enum fixed_addresses idx,extern void __this_fixmap_does_not_exist (void ); +static inline bool user_fixmap (enum fixed_addresses fixmap) +{ +switch (fixmap) { +#ifdef CONFIG_X86_32 + case FIX_HOLE ... FIX_VDSO: +#else + case VSYSCALL_LAST_PAGE ... VSYSCALL_HPET: +#ifdef CONFIG_PARAVIRT_CLOCK_VSYSCALL +case FIX_PVCLOCK_TIME_INFO : +#endif +#endif +return true; + +default : +return false; + } +} +/* * 'index to address' translation. If anyone tries to use the idx * directly without translation, we catch the bug with a NULL-deference
Signature · 1 line
1.6.2.5
PATCH 12/12 xen/time: add pvclock_clocksource_vread support
In reply to Jeremy FitzhardingeAdd support to register pvclock_vcpu_time_info structures in the userspace mapped page and set the xen clocksource .vread method if that works. The common pvclock code does everything else.
--- arch/x86/xen/Kconfig | 6 ++++ arch/x86/xen/mmu.c | 5 +++- arch/x86/xen/smp.c | 2 + arch/x86/xen/time.c | 54 ++++++++++++++++++++++++++++++++++++++++++ arch/x86/xen/xen-ops.h | 8 ++++++ include/xen/interface/vcpu.h | 41 +++++++++++++++++++++++++++++++ 6 files changed, 115 insertions(+), 1 deletions(-)
arch/x86/xen/Kconfig +6 -0
@@ -13,6 +13,11 @@ config XEN kernel to boot in a paravirtualized environment under the Xen hypervisor. +config XEN_TIME_VSYSCALL + def_bool y + depends on X86_VSYSCALL && PARAVIRT_CLOCK + select PARAVIRT_CLOCK_VSYSCALL + config XEN_MAX_DOMAIN_MEMORY int "Maximum allowed size of a domain in gigabytes" default 8 if X86_32
@@ -36,3 +41,4 @@ config XEN_DEBUG_FS help Enable statistics output and various tuning options in debugfs. Enabling this option may incur a significant performance overhead. +
arch/x86/xen/mmu.c +4 -1
@@ -1814,6 +1814,9 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)# endif #else case VSYSCALL_LAST_PAGE ... VSYSCALL_FIRST_PAGE: +#ifdef CONFIG_PARAVIRT_CLOCK_VSYSCALL +case FIX_PVCLOCK_TIME_INFO : +#endif #endif #ifdef CONFIG_X86_LOCAL_APIC case FIX_APIC_BASE :/* maps dummy local APIC */
@@ -1834,7 +1837,7 @@ static void xen_set_fixmap(unsigned idx, phys_addr_t phys, pgprot_t prot)#ifdef CONFIG_X86_64 /* Replicate changes to map the vsyscall page into the user pagetable vsyscall mapping. */ -if (idx >=VSYSCALL_LAST_PAGE && idx <=VSYSCALL_FIRST_PAGE ) { +if (user_fixmap (idx)) {unsigned long vaddr =__fix_to_virt (idx);set_pte_vaddr_pud (level3_user_vsyscall, vaddr, pte); }
arch/x86/xen/smp.c +2 -0
@@ -313,6 +313,8 @@ static int __cpuinit xen_cpu_up(unsigned int cpu)if (rc)return rc; +xen_setup_vcpu_vsyscall_time_info (cpu); + rc =HYPERVISOR_vcpu_op (VCPUOP_up, cpu,NULL );BUG_ON (rc);
arch/x86/xen/time.c +54 -0
64 lines not on this page · raw message
arch/x86/xen/xen-ops.h +8 -0
@@ -58,6 +58,14 @@ bool xen_vcpu_stolen(int vcpu);void xen_setup_vcpu_info_placement (void ); +#ifdef CONFIG_PARAVIRT_CLOCK_VSYSCALL +void xen_setup_vcpu_vsyscall_time_info (int cpu); +#else +static inline void xen_setup_vcpu_vsyscall_time_info (int cpu) +{ +} +#endif +#ifdef CONFIG_SMP void xen_smp_init (void );
include/xen/interface/vcpu.h +41 -0
45 lines not on this page · raw message
Signature · 1 line
1.6.2.5
Quoted 24 lines · Jeremy Fitzhardinge
Hi all,
This series contains several things:
- Unify the separate vdso and vsyscall implementations of vgettimeofday and vgetcpu. There's at least one bugfix which was only applied to one copy (ignore tcache in vgetcpu was only applied to the vdso version); this should avoid such skews in future.
- Bug fixes for the Xen and KVM clocksource.read functions to make sure the returned time doesn't regress compared to clocksource.cycle_last. (Probably stable material.)
- Make sure the pvclock rdtsc is surrounded by appropriate barriers so that it doesn't get speculated to the wrong place with respect to reading the time parameters. (Probably stable material.)
- General cleanups of the pvclock algorithm (there's no need to make a local copy of the time parameters before use).
- Add a new
CONFIG_X86_VSYSCALLto control the compilation of vsyscall-related code rather than just usingCONFIG_X86_64- we may want to implement 32-bit vsyscall at some point, and this will make it easier.
Quoted 8 lines
- Add the sched notifier for task migration between CPUs, for use by pvclock vread.
- Implement a pvclock vread function, so that pvclock-using clocksources can be used by vsyscall/vdso vgettimeofday and
vclock_gettime.- Use pvclock vread in the Xen clocksource.
Looks good to me.
Acked-by etc.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 9 lines · Avi Kivity
Quoted 6 lines
- Implement a pvclock vread function, so that pvclock-using
clocksources can be
used by vsyscall/vdso vgettimeofday andvclock_gettime.- Use pvclock vread in the Xen clocksource.
Looks good to me.
Care to cook up a patch to implement the kvm bits to make sure it all works OK for you?
Thanks,
J
Quoted 3 lines · Jeremy Fitzhardinge
Care to cook up a patch to implement the kvm bits to make sure it all works OK for you?
I've started to do that, but it occurs to me that we're missing out on NUMA placement by forcing all clocks to be on the same page. OTOH, if the clocks are heavily used, they'll stay in cache, and if not, who cares.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 10 lines · Avi Kivity
Quoted 3 lines · Jeremy Fitzhardinge
Care to cook up a patch to implement the kvm bits to make sure it all works OK for you?
I've started to do that, but it occurs to me that we're missing out on NUMA placement by forcing all clocks to be on the same page. OTOH, if the clocks are heavily used, they'll stay in cache, and if not, who cares.
Yes, I'd say so. I'd expect the data to be very close to read-only, so the lines should be shared pretty efficiently.
On the other hand, there's nothing to stop us from moving to multiple pages in future (either to support NUMA placement, or just more than 64 cpus).
J
Quoted 8 lines · Jeremy Fitzhardinge
Quoted 6 lines · Avi Kivity
Quoted 4 lines · Jeremy Fitzhardinge
Care to cook up a patch to implement the kvm bits to make sure it all works OK for you?
Quoted 9 lines
Quoted 5 lines
I've started to do that, but it occurs to me that we're missing out on NUMA placement by forcing all clocks to be on the same page. OTOH, if the clocks are heavily used, they'll stay in cache, and if not, who cares.
Yes, I'd say so. I'd expect the data to be very close to read-only, so the lines should be shared pretty efficiently.
There wouldn't be any sharing since each clock is on its own cache line. But the point is valid regardless.
Quoted 4 lines
On the other hand, there's nothing to stop us from moving to multiple pages in future (either to support NUMA placement, or just more than 64 cpus).
I'm already allocating multiple pages, so we'd just need to adjust the fixmap.
Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this signature is too narrow to contain.
Quoted 7 lines · Avi Kivity
Quoted 4 lines
On the other hand, there's nothing to stop us from moving to multiple pages in future (either to support NUMA placement, or just more than 64 cpus).
I'm already allocating multiple pages, so we'd just need to adjust the fixmap.
Are you changing pvclock_init_vsyscall() to allocate more pages? More fixmap slots should be no problem.
J