GENERIC_TIME patchset for x86_64
cover GENERIC_TIME patchset for x86_64
Hey Andi,
First let me apologize, I've been busy with other things and
its been far too long since I last posted this. Anyway, I found some time to resync my trees and wanted to send this along.
You had asked earlier about performance impact:
Vanilla TSC:
149 nsecs per gtod call
367 nsecs per CLOCK_MONOTONIC call
288 nsecs per CLOCK_REALTIME call
Vanilla ACPI PM:
1272 nsecs per gtod call
1335 nsecs per CLOCK_MONOTONIC call
1273 nsecs per CLOCK_REALTIME call
GENERIC_TIME TSC:
149 nsecs per gtod call
304 nsecs per CLOCK_MONOTONIC call
275 nsecs per CLOCK_REALTIME callGENERIC_TIME ACPI PM:
1273 nsecs per gtod call
1275 nsecs per CLOCK_MONOTONIC call
1273 nsecs per CLOCK_REALTIME call
So almost no performance change.
Ingo has a few cleanups I need to merge, but otherwise I think this is getting close to ready for inclusion into -mm for testing. Please let me know if you have any major objections and if not I'll re-diff it against -mm and send it to Andrew.
New in the current C7 release:
o Synched up w/ 2.6.19-rc6-git11
o Reworked the patch order to be a bit more logical
o Dropped the apic_runs_main_timer removal on Andi's request
Let me know if you have any thoughts or comments!
thanks again!
-john
PATCH 1/5 vsyscall-gtod support for GENERIC_TIME
Provides generic infrastructure for vsyscall-gtod.
include/linux/clocksource.h | 8 ++++++++ kernel/timer.c | 1 + 2 files changed, 9 insertions(+)
linux-2.6.19-rc6git11_timeofday-vsyscall-support_C7.patch
============================================
include/linux/clocksource.h +8 -0
@@ -46,6 +46,7 @@ typedef u64 cycle_t;* @shift: cycle to nanosecond divisor (power of two) * @update_callback: called when safe to alter clocksource values * @is_continuous: defines if clocksource is free-running. +* @vread: vsyscall based read * @cycle_interval: Used internally by timekeeping core, please ignore. * @xtime_interval: Used internally by timekeeping core, please ignore. */
@@ -59,6 +60,7 @@ struct clocksource {u32 shift;int (*update_callback)(void );int is_continuous; +cycle_t (*vread)(void);/* timekeeping specific data, ignore */ cycle_t cycle_last, cycle_interval;
@@ -182,4 +184,10 @@ int clocksource_register(struct clocksouvoid clocksource_reselect (void );struct clocksource *clocksource_get_next (void ); +#ifdef CONFIG_GENERIC_TIME_VSYSCALL +extern void update_vsyscall (struct timespec *ts,struct clocksource *c); +#else +#define update_vsyscall (now, c) do { } while(0) +#endif +#endif /* _LINUX_CLOCKSOURCE_H */
kernel/timer.c +1 -0
@@ -956,6 +956,7 @@ #endif clock->xtime_nsec =0 ;clocksource_calculate_interval (clock, tick_nsec); } +update_vsyscall (&xtime, clock); }/*
PATCH 2/5 hpet_address cleanup
In reply to john stultzIn preparation for supporting generic timekeeping, this patch cleans up x86-64's use of vxtime.hpet_address, changing it to just hpet_address as is also used in i386. This is necessary since the vxtime structure will be going away.
arch/i386/kernel/acpi/boot.c | 23 ++++++----------------- arch/x86_64/kernel/apic.c | 3 ++- arch/x86_64/kernel/time.c | 36 +++++++++++++++++++----------------- include/asm-x86_64/hpet.h | 1 + 4 files changed, 28 insertions(+), 35 deletions(-)
linux-2.6.19-rc6git11_timeofday-arch-x86-64-hpet-address-cleanup_C7.patch
============================================
arch/i386/kernel/acpi/boot.c +6 -17
@@ -638,6 +638,7 @@ static int __init acpi_parse_sbf(unsigne }#ifdef CONFIG_HPET_TIMER +#include <asm/hpet.h> static int __init acpi_parse_hpet (unsigned long phys,unsigned long size) {
@@ -671,32 +672,20 @@ #define HPET_RESOURCE_NAME_SIZE 9 hpet_res->end = (1 *1024 ) -1 ; } + hpet_address = hpet_tbl->addr.addrl;#ifdef CONFIG_X86_64 - vxtime.hpet_address = hpet_tbl->addr.addrl | - ((long )hpet_tbl->addr.addrh <<32 ); - + hpet_address |= ((long )hpet_tbl->addr.addrh <<32 ); +#endif printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n", - hpet_tbl->id, vxtime.hpet_address); - - res_start = vxtime.hpet_address; -#else /* X86 */ - { -extern unsigned long hpet_address; + hpet_tbl->id, hpet_address); - hpet_address = hpet_tbl->addr.addrl; - printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n", - hpet_tbl->id, hpet_address); - - res_start = hpet_address; - } -#endif /* X86 */ + res_start = hpet_address;if (hpet_res) { hpet_res->start = res_start; hpet_res->end += res_start;insert_resource (&iomem_resource, hpet_res); } - return 0; }#else
arch/x86_64/kernel/apic.c +2 -1
@@ -36,6 +36,7 @@ #include <asm/nmi.h>#include <asm/idle.h> #include <asm/proto.h> #include <asm/timex.h> +#include <asm/hpet.h> #include <asm/apic.h> int apic_mapped;
@@ -673,7 +674,7 @@ static void setup_APIC_timer(unsigned inlocal_irq_save (flags);/* wait for irq slice */ -if (vxtime.hpet_address && hpet_use_timer) { +if (hpet_address && hpet_use_timer) {int trigger =hpet_readl (HPET_T0_CMP );while (hpet_readl (HPET_COUNTER ) >= trigger)/* do nothing */ ;
arch/x86_64/kernel/time.c +19 -17
@@ -67,6 +67,7 @@ #define US_SCALE 32 /* 2^32, arbitralrilunsigned int cpu_khz;/* TSC clocks / usec, not used here */ EXPORT_SYMBOL (cpu_khz); +unsigned long hpet_address;static unsigned long hpet_period;/* fsecs / HPET clock */ unsigned long hpet_tick;/* HPET clocks / interrupt */ int hpet_use_timer;/* Use counter of hpet for time keeping, otherwise PIT */
@@ -316,7 +317,7 @@ static noinline void handle_lost_ticks(iKERN_WARNING "Your time source seems to be instable or " "some driver is hogging interupts\n");print_symbol ("rip %s\n" ,get_irq_regs ()->rip); -if (vxtime.mode ==VXTIME_TSC && vxtime.hpet_address) { +if (vxtime.mode ==VXTIME_TSC && hpet_address) {printk (KERN_WARNING "Falling back to HPET\n" );if (hpet_use_timer) vxtime.last = hpet_readl(HPET_T0_CMP) -
@@ -324,6 +325,7 @@ static noinline void handle_lost_ticks(ielse vxtime.last =hpet_readl (HPET_COUNTER ); vxtime.mode =VXTIME_HPET ; + vxtime.hpet_address = hpet_address; do_gettimeoffset = do_gettimeoffset_hpet; }/* else should fall back to PIT, but code missing. */
@@ -354,7 +356,7 @@ void main_timer_handler(void)write_seqlock (&xtime_lock); -if (vxtime.hpet_address) +if (hpet_address) offset =hpet_readl (HPET_COUNTER );if (hpet_use_timer) {
@@ -717,7 +719,7 @@ static __init int late_hpet_init(void)struct hpet_data hd;unsigned int ntimer; -if (!vxtime.hpet_address) +if (!hpet_address)return 0 ;memset (&hd,0 ,sizeof (hd));
@@ -730,7 +732,7 @@ static __init int late_hpet_init(void)* Register with driver. * Timer0 and Timer1 is used by platform. */ - hd.hd_phys_address = vxtime.hpet_address; + hd.hd_phys_address = hpet_address; hd.hd_address = (void __iomem *)fix_to_virt (FIX_HPET_BASE ); hd.hd_nirqs = ntimer; hd.hd_flags =HPET_DATA_PLATFORM ;
@@ -799,10 +801,10 @@ static int hpet_init(void) {unsigned int id; -if (!vxtime.hpet_address) +if (!hpet_address)return -1 ; -set_fixmap_nocache (FIX_HPET_BASE , vxtime.hpet_address); -__set_fixmap (VSYSCALL_HPET , vxtime.hpet_address,PAGE_KERNEL_VSYSCALL_NOCACHE ); +set_fixmap_nocache (FIX_HPET_BASE , hpet_address); +__set_fixmap (VSYSCALL_HPET , hpet_address,PAGE_KERNEL_VSYSCALL_NOCACHE );/* * Read the period, compute tick and quotient.
@@ -856,7 +858,7 @@ void __init pit_stop_interrupt(void)void __init stop_timer_interrupt (void ) {char *name; -if (vxtime.hpet_address) { +if (hpet_address) { name ="HPET" ;hpet_timer_stop_set_go (0 ); }else {
@@ -879,8 +881,7 @@ static struct irqaction irq0 = {void __init time_init (void ) {if (nohpet) - vxtime.hpet_address =0 ; - + hpet_address =0 ; xtime.tv_sec =get_cmos_time (); xtime.tv_nsec =0 ;
@@ -890,7 +891,7 @@ void __init time_init(void)if (!hpet_init ()) vxtime_hz = (FSEC_PER_SEC + hpet_period /2 ) / hpet_period;else - vxtime.hpet_address =0 ; + hpet_address =0 ;if (hpet_use_timer) {/* set tick_nsec to use the proper rate for HPET */
@@ -898,7 +899,7 @@ void __init time_init(void) cpu_khz =hpet_calibrate_tsc (); timename ="HPET" ; #ifdef CONFIG_X86_PM_TIMER - }else if (pmtmr_ioport && !vxtime.hpet_address) { + }else if (pmtmr_ioport && !hpet_address) { vxtime_hz =PM_TIMER_FREQUENCY ; timename ="PM" ;pit_init ();
@@ -957,23 +958,24 @@ void time_init_gtod(void)if (unsynchronized_tsc ()) notsc =1 ; -if (cpu_has (&boot_cpu_data,X86_FEATURE_RDTSCP )) +if (cpu_has (&boot_cpu_data,X86_FEATURE_RDTSCP )) vgetcpu_mode =VGETCPU_RDTSCP ;else vgetcpu_mode =VGETCPU_LSL ; -if (vxtime.hpet_address && notsc) { +if (hpet_address && notsc) { timetype = hpet_use_timer ?"HPET" :"PIT/HPET" ;if (hpet_use_timer) vxtime.last =hpet_readl (HPET_T0_CMP ) - hpet_tick;else vxtime.last =hpet_readl (HPET_COUNTER ); vxtime.mode =VXTIME_HPET ; + vxtime.hpet_address = hpet_address; do_gettimeoffset = do_gettimeoffset_hpet;#ifdef CONFIG_X86_PM_TIMER /* Using PM for gettimeofday is quite slow, but we have no other choice because the TSC is too unreliable on some systems. */ - }else if (pmtmr_ioport && !vxtime.hpet_address && notsc) { + }else if (pmtmr_ioport && !hpet_address && notsc) { timetype ="PM" ; do_gettimeoffset = do_gettimeoffset_pm; vxtime.mode =VXTIME_PMTMR ;
@@ -1033,7 +1035,7 @@ static int timer_resume(struct sys_devic sleep_length =0 ; ctime = sleep_start; } -if (vxtime.hpet_address) +if (hpet_address)hpet_reenable ();else i8254_timer_resume ();
@@ -1117,7 +1119,7 @@ static unsigned int hpet_t1_cmp; /* cachint is_hpet_enabled (void ) { -return vxtime.hpet_address !=0 ; +return hpet_address !=0 ; }/*
include/asm-x86_64/hpet.h +1 -0
@@ -58,6 +58,7 @@ extern int hpet_rtc_timer_init(void);extern int apic_is_clustered_box (void );extern int hpet_use_timer; +extern unsigned long hpet_address;#ifdef CONFIG_HPET_EMULATE_RTC extern int hpet_mask_rtc_irq_bit (unsigned long bit_mask);
PATCH 3/5 Split x86_64/kernel/time.c up
In reply to john stultzIn preperation for the x86_64 generic time conversion, this patch splits out TSC and HPET related code from arch/x86_64/kernel/time.c into respective hpet.c and tsc.c files.
arch/x86_64/kernel/Makefile | 2 arch/x86_64/kernel/hpet.c | 435 ++++++++++++++++++++++++++++++ arch/x86_64/kernel/time.c | 628 -------------------------------------------- arch/x86_64/kernel/tsc.c | 201 ++++++++++++++ include/asm-x86_64/hpet.h | 6 include/asm-x86_64/timex.h | 11 6 files changed, 658 insertions(+), 625 deletions(-)
linux-2.6.19-rc6git11_timeofday-arch-x86-64-split-hpet-tsc-time_C7.patch
============================================
arch/x86_64/kernel/Makefile +1 -1
@@ -8,7 +8,7 @@ obj-y := process.o signal.o entry.o trap ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_x86_64.o \ x8664_ksyms.o i387.o syscall.o vsyscall.o \ setup64.o bootflag.o e820.o reboot.o quirks.o i8237.o \ - pci-dma.o pci-nommu.o alternative.o + pci-dma.o pci-nommu.o alternative.o hpet.o tsc.o obj-$(CONFIG_STACKTRACE) += stacktrace.o obj-$(CONFIG_X86_MCE) += mce.o therm_throt.o
arch/x86_64/kernel/hpet.c new file +435 -0
435 lines not on this page · raw message
arch/x86_64/kernel/time.c +4 -624
687 lines not on this page · raw message
arch/x86_64/kernel/tsc.c new file +201 -0
201 lines not on this page · raw message
include/asm-x86_64/hpet.h +6 -0
@@ -56,9 +56,15 @@ #define HPET_TICK_RATE (HZ * 100000UL)extern int is_hpet_enabled (void );extern int hpet_rtc_timer_init (void );extern int apic_is_clustered_box (void ); +extern int hpet_arch_init (void ); +extern int hpet_timer_stop_set_go (unsigned long tick); +extern int hpet_reenable (void ); +extern unsigned int hpet_calibrate_tsc (void );extern int hpet_use_timer;extern unsigned long hpet_address; +extern unsigned long hpet_period; +extern unsigned long hpet_tick;#ifdef CONFIG_HPET_EMULATE_RTC extern int hpet_mask_rtc_irq_bit (unsigned long bit_mask);
include/asm-x86_64/timex.h +11 -0
@@ -44,6 +44,17 @@ extern unsigned int cpu_khz;extern int read_current_timer (unsigned long *timer_value);#define ARCH_HAS_READ_CURRENT_TIMER 1 +#define USEC_PER_TICK (USEC_PER_SEC / HZ) +#define NSEC_PER_TICK (NSEC_PER_SEC / HZ) +#define FSEC_PER_TICK (FSEC_PER_SEC / HZ) + +#define NS_SCALE 10/* 2^10, carefully chosen */ +#define US_SCALE 32/* 2^32, arbitralrily chosen */ +extern struct vxtime_data vxtime; +extern unsigned int do_gettimeoffset_hpet (void ); +extern unsigned int do_gettimeoffset_tsc (void ); +extern void set_cyc2ns_scale (unsigned long khz); +extern int notsc;#endif
PATCH 4/5 Convert x86_64 to use GENERIC_TIME
In reply to john stultzThis patch converts x86_64 to use the GENERIC_TIME infrastructure and adds clocksource structures for both TSC and HPET (ACPI PM is shared w/ i386).
arch/x86_64/Kconfig | 4 arch/x86_64/kernel/apic.c | 2 arch/x86_64/kernel/hpet.c | 65 ++++++++- arch/x86_64/kernel/pmtimer.c | 58 -------- arch/x86_64/kernel/smpboot.c | 1 arch/x86_64/kernel/time.c | 301 ------------------------------------------- arch/x86_64/kernel/tsc.c | 105 +++++++++------ include/asm-x86_64/proto.h | 1 include/asm-x86_64/timex.h | 5 9 files changed, 133 insertions(+), 409 deletions(-)
linux-2.6.19-rc6git11_timeofday-arch-x86-64-generic-time-conversion_C7.patch
============================================
arch/x86_64/Kconfig +4 -0
@@ -24,6 +24,10 @@ config X86 bool default y +config GENERIC_TIME + bool + default y + config ZONE_DMA32 bool default y
arch/x86_64/kernel/apic.c +1 -1
@@ -696,7 +696,7 @@ static void setup_APIC_timer(unsigned in/* Turn off PIT interrupt if we use APIC timer as main timer. Only works with the PM timer right now TBD fix it for HPET too. */ -if (vxtime.mode ==VXTIME_PMTMR && +if ((pmtmr_ioport !=0 ) &&smp_processor_id () == boot_cpu_id && apic_runs_main_timer ==1 && !cpu_isset (boot_cpu_id, timer_interrupt_broadcast_ipi_mask)) {
arch/x86_64/kernel/hpet.c +59 -6
74 lines not on this page · raw message
arch/x86_64/kernel/pmtimer.c +0 -58
76 lines not on this page · raw message
arch/x86_64/kernel/smpboot.c +0 -1
@@ -1180,7 +1180,6 @@ void __init smp_cpus_done(unsigned int msmp_cleanup_boot ();setup_ioapic_dest ();check_nmi_watchdog (); -time_init_gtod (); }#ifdef CONFIG_HOTPLUG_CPU
arch/x86_64/kernel/time.c +5 -296
383 lines not on this page · raw message
arch/x86_64/kernel/tsc.c +63 -42
142 lines not on this page · raw message
include/asm-x86_64/proto.h +0 -1
@@ -45,7 +45,6 @@ extern u32 pmtmr_ioport;#else #define pmtmr_ioport 0#endif -extern unsigned long long monotonic_base;extern int sysctl_vsyscall;extern int nohpet;extern unsigned long vxtime_hz;
include/asm-x86_64/timex.h +1 -4
@@ -52,9 +52,6 @@ #define NS_SCALE 10 /* 2^10, care#define US_SCALE 32/* 2^32, arbitralrily chosen */ extern struct vxtime_data vxtime; - -extern unsigned int do_gettimeoffset_hpet (void ); -extern unsigned int do_gettimeoffset_tsc (void ); +extern void mark_tsc_unstable (void );extern void set_cyc2ns_scale (unsigned long khz); -extern int notsc;#endif
rdtscp vgettimeofday
Hello,
As far as I can see, many changes happened but nobody has yet added the rdtscp support to x86-64. rdtscp finally solves the problem and it obsoletes hpet for timekeeping and it allows a fully userland gettimeofday running at maximum speed in userland.
Before rdtscp we could never index the rdtsc offset in a proper index without being in kernel with preemption disabled, so it could never work reliably.
What's the status of the DSO API? Does it break backwards compatibility or is the production glibc already capable of handling that new kernel API?
I need rdtscp working on vsyscalls ASAP, but I should first understand if I need to base my code on top of the vDSO patch or if to fork it off in a dead branch to preserve backwards compatibility with current glibc userland.
Thanks.
Re: rdtscp vgettimeofday
Quoted 4 lines · Andrea Arcangeli
As far as I can see, many changes happened but nobody has yet added the rdtscp support to x86-64. rdtscp finally solves the problem and it obsoletes hpet for timekeeping and it allows a fully userland gettimeofday running at maximum speed in userland.
rdtscp doesn't solve anything extra which can't already be solved with existing vgetcpu (based on lsl) and rdtsc. which have the advantage of working on all x86, not just the (currently) rare revF opteron.
lsl-based vgetcpu is relatively slow (because it is a protected instruction with lots of microcode) -- but there are other options which continue to work on all x86 (see <http://lkml.org/lkml/2006/11/13/401>).
Quoted 3 lines
Before rdtscp we could never index the rdtsc offset in a proper index without being in kernel with preemption disabled, so it could never work reliably.
even with rdtscp you have to deal with the definite possibility of being scheduled away in the middle of the computation. arguably you need to deal with the possibility of being scheduled away *and* back again to the same cpu (so testing cpu# at top and bottom of a loop isn't sufficient).
suleiman proposed a per-cpu scheduling event number to deal with that... not sure what folks think of that idea.
-dean
Re: rdtscp vgettimeofday
Quoted 2 lines · dean gaudet
rdtscp doesn't solve anything extra [..]
[..] lsl-based vgetcpu is relatively slow
Well, if you accept to run slow there's nothing to solve in the first place indeed.
If nothing else rdtscp should avoid the mess of restarting a vsyscalls, which is quite a difficult problem as it heavily depends on the compiler/dwarf.
Quoted 3 lines
even with rdtscp you have to deal with the definite possibility of being scheduled away in the middle of the computation. arguably you need to
Isn't rdtscp atomic? all you need is to read atomically the current contents of the tsc and the index to use in a per-cpu table exported in readonly. This table will contain a per-cpu seqlock as well. Then a math logic has to be built with per-cpu threads, so that those per-cpu tables are updated by cpufreq and at regular intervals.
If this is all wrong and it's not feasible to implement a safe and monothonic vgettimeofday that doesn't access the southbridge and that doesn't require restarting the vsyscall manually by patching rip/rsp, I've an hard time to see how rdtscp is useful at all. I hope somebody thought about those issues before adding a new instruction to a popular CPU ;).
Re: rdtscp vgettimeofday
Quoted 10 lines · Andrea Arcangeli
Quoted 2 lines · dean gaudet
rdtscp doesn't solve anything extra [..]
[..] lsl-based vgetcpu is relatively slowWell, if you accept to run slow there's nothing to solve in the first place indeed.
If nothing else rdtscp should avoid the mess of restarting a vsyscalls, which is quite a difficult problem as it heavily depends on the compiler/dwarf.
rdtscp gets you 2 of the 5 values you need to compute the time. anything can happen between when you do the rdtscp and do the other 3 reads: the computation is (((tsc-A)*B)>>N)+C where N is a constant, and A, B, C are per-cpu data.
A/B/C change a few times a second (to avoid 32-bit rollover in (tsc-A)), every time there's a halt, and every P-state transition.
if you lose your tick in the middle of those reads any number of things can happen to screw the computation... including being scheduled on another core and mixing values from two cores.
Quoted 10 lines
Quoted 3 lines
even with rdtscp you have to deal with the definite possibility of being scheduled away in the middle of the computation. arguably you need to
Isn't rdtscp atomic? all you need is to read atomically the current contents of the tsc and the index to use in a per-cpu table exported in readonly. This table will contain a per-cpu seqlock as well. Then a math logic has to be built with per-cpu threads, so that those per-cpu tables are updated by cpufreq and at regular intervals.
Quoted 6 lines
If this is all wrong and it's not feasible to implement a safe and monothonic vgettimeofday that doesn't access the southbridge and that doesn't require restarting the vsyscall manually by patching rip/rsp, I've an hard time to see how rdtscp is useful at all. I hope somebody thought about those issues before adding a new instruction to a popular CPU ;).
oh i think there are several solutions which will work... and i also think rdtscp wasn't a necessary addition to the ISA :)
-dean
Re: rdtscp vgettimeofday
Quoted 6 lines · dean gaudet
rdtscp gets you 2 of the 5 values you need to compute the time. anything can happen between when you do the rdtscp and do the other 3 reads: the computation is (((tsc-A)*B)>>N)+C where N is a constant, and A, B, C are per-cpu data.
A/B/C change a few times a second (to avoid 32-bit rollover in (tsc-A)), every time there's a halt, and every P-state transition.
This is wrong. There's the D variable too, the seq lock.
The thing I've in mind is something like:
rdstcp (get tsc and cpu atomic) this is fundamental without tsc and cpu read atomically nothing of the below is possible
read D from cpu we got from rdtscp (seqlock) smb_rmb()
check that D isn't during the race condition (last LSB clear or similar) or restart
rdstcp again (tsc and cpu atomic)
check that cpu is still the same or restart
index the per-cpu array and get the safe A B C smp_rmb()
read per-cpu D again and check that it didn't change or restart
Then you have tsc, A, B and C all atomic. N is a constant. rdtsc again is fundamental in getting this info all atomic w/o accessing the southbridge and without expensive asm instruction.
Quoted 3 lines
if you lose your tick in the middle of those reads any number of things can happen to screw the computation... including being scheduled on another core and mixing values from two cores.
Being scheduled in another core is normal. continuing gettimeofday from another core after you have the tsc value is just fine.
If something the problem is to generate A B C in per-cpu data with a per-cpu seqlock around it. That's the job for the per-cpu kernel thread.
The only real trouble I see is the offset from the last irq. It's possible to make this to work we need to rotate the timer irq across all cpus at regular intervals (before the tsc2usec measurement error showup).
Quoted 2 lines
oh i think there are several solutions which will work... and i also think rdtscp wasn't a necessary addition to the ISA :)
Please don't suggest me the userland rsp manual unwinding, that's orders of magnitude more fragile and it sounds much more complex too ;).
PATCH 5/5 Re-enable vsyscall support for x86_64
In reply to john stultzCleanup and re-enable vsyscall gettimeofday using the generic clocksource infrastructure.
arch/x86_64/Kconfig | 4 + arch/x86_64/kernel/hpet.c | 6 + arch/x86_64/kernel/time.c | 6 - arch/x86_64/kernel/tsc.c | 7 ++ arch/x86_64/kernel/vmlinux.lds.S | 28 +++------ arch/x86_64/kernel/vsyscall.c | 121 +++++++++++++++++++++++---------------- include/asm-x86_64/proto.h | 3 include/asm-x86_64/timex.h | 1 include/asm-x86_64/vsyscall.h | 32 +--------- 9 files changed, 105 insertions(+), 103 deletions(-)
linux-2.6.19-rc6git11_timeofday-arch-x86-64-vsyscall-reenablement_C7.patch
============================================
arch/x86_64/Kconfig +4 -0
@@ -28,6 +28,10 @@ config GENERIC_TIME bool default y +config GENERIC_TIME_VSYSCALL + bool + default y + config ZONE_DMA32 bool default y
arch/x86_64/kernel/hpet.c +6 -0
@@ -440,6 +440,11 @@ static cycle_t read_hpet(void)return (cycle_t )readl (hpet_ptr); } +static cycle_t __vsyscall_fn vread_hpet(void) +{ +return (cycle_t )readl ((void *)fix_to_virt (VSYSCALL_HPET ) +0xf0 ); +} +struct clocksource clocksource_hpet = { .name ="hpet" , .rating =250 ,
@@ -448,6 +453,7 @@ struct clocksource clocksource_hpet = { .mult = 0, /* set below */ .shift = HPET_SHIFT, .is_continuous = 1, + .vread = vread_hpet, };static int __init init_hpet_clocksource (void )
arch/x86_64/kernel/time.c +0 -6
@@ -53,13 +53,7 @@ DEFINE_SPINLOCK(rtc_lock);EXPORT_SYMBOL (rtc_lock);DEFINE_SPINLOCK (i8253_lock); -unsigned long vxtime_hz =PIT_TICK_RATE ; - -struct vxtime_data __vxtime __section_vxtime; /* for vsyscalls */ -volatile unsigned long __jiffies __section_jiffies =INITIAL_JIFFIES ; -struct timespec __xtime __section_xtime; -struct timezone __sys_tz __section_sys_tz;unsigned long profile_pc (struct pt_regs *regs) {
arch/x86_64/kernel/tsc.c +7 -0
@@ -185,6 +185,12 @@ static cycle_t read_tsc(void)return ret; } +static cycle_t __vsyscall_fn vread_tsc(void) +{ +cycle_t ret = (cycle_t )get_cycles_sync (); +return ret; +} +static struct clocksource clocksource_tsc = { .name ="tsc" , .rating =300 ,
@@ -194,6 +200,7 @@ static struct clocksource clocksource_ts .shift = 22, .update_callback = tsc_update_callback, .is_continuous = 1, + .vread = vread_tsc, };static int tsc_update_callback (void )
arch/x86_64/kernel/vmlinux.lds.S +11 -17
@@ -94,31 +94,25 @@ #define VVIRT(x) (ADDR(x) - VVIRT_OFFSET __vsyscall_0 = VSYSCALL_VIRT_ADDR; . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); - .xtime_lock : AT(VLOAD(.xtime_lock)) { *(.xtime_lock) } - xtime_lock = VVIRT(.xtime_lock); - - .vxtime : AT(VLOAD(.vxtime)) { *(.vxtime) } - vxtime = VVIRT(.vxtime); + .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { *(.vsyscall_fn) } + . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); + .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) + { *(.vsyscall_gtod_data) } + vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data); .vgetcpu_mode : AT(VLOAD(.vgetcpu_mode)) { *(.vgetcpu_mode) } vgetcpu_mode = VVIRT(.vgetcpu_mode); - .sys_tz : AT(VLOAD(.sys_tz)) { *(.sys_tz) } - sys_tz = VVIRT(.sys_tz); - - .sysctl_vsyscall : AT(VLOAD(.sysctl_vsyscall)) { *(.sysctl_vsyscall) } - sysctl_vsyscall = VVIRT(.sysctl_vsyscall); - - .xtime : AT(VLOAD(.xtime)) { *(.xtime) } - xtime = VVIRT(.xtime); - . = ALIGN(CONFIG_X86_L1_CACHE_BYTES); .jiffies : AT(VLOAD(.jiffies)) { *(.jiffies) } jiffies = VVIRT(.jiffies); - .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) { *(.vsyscall_1) } - .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) { *(.vsyscall_2) } - .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) { *(.vsyscall_3) } + .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) + { *(.vsyscall_1) } + .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) + { *(.vsyscall_2) } + .vsyscall_3 ADDR(.vsyscall_0) + 3072: AT(VLOAD(.vsyscall_3)) + { *(.vsyscall_3) } . = VSYSCALL_VIRT_ADDR + 4096;
arch/x86_64/kernel/vsyscall.c +72 -49
182 lines not on this page · raw message
include/asm-x86_64/proto.h +0 -3
@@ -45,10 +45,7 @@ extern u32 pmtmr_ioport;#else #define pmtmr_ioport 0#endif -extern int sysctl_vsyscall;extern int nohpet; -extern unsigned long vxtime_hz; -extern void time_init_gtod (void );extern void early_printk (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));
include/asm-x86_64/timex.h +0 -1
@@ -51,7 +51,6 @@ #define FSEC_PER_TICK (FSEC_PER_SEC / HZ#define NS_SCALE 10/* 2^10, carefully chosen */ #define US_SCALE 32/* 2^32, arbitralrily chosen */ -extern struct vxtime_data vxtime;extern void mark_tsc_unstable (void );extern void set_cyc2ns_scale (unsigned long khz);#endif
include/asm-x86_64/vsyscall.h +5 -27
@@ -15,51 +15,29 @@ #define VSYSCALL_ADDR(vsyscall_nr) (VSYS#ifdef __KERNEL__#include <linux/seqlock.h> -#define __section_vxtime __attribute__ ((unused, __section__ (".vxtime"), aligned(16)))#define __section_vgetcpu_mode __attribute__ ((unused, __section__ (".vgetcpu_mode"), aligned(16)))#define __section_jiffies __attribute__ ((unused, __section__ (".jiffies"), aligned(16))) -#define __section_sys_tz __attribute__ ((unused, __section__ (".sys_tz"), aligned(16))) -#define __section_sysctl_vsyscall __attribute__ ((unused, __section__ (".sysctl_vsyscall"), aligned(16))) -#define __section_xtime __attribute__ ((unused, __section__ (".xtime"), aligned(16))) -#define __section_xtime_lock __attribute__ ((unused, __section__ (".xtime_lock"), aligned(16))) -#define VXTIME_TSC 1 -#define VXTIME_HPET 2 -#define VXTIME_PMTMR 3 +/* Definitions for CONFIG_GENERIC_TIME definitions */ +#define __section_vsyscall_gtod_data __attribute__ \ + ((unused, __section__ (".vsyscall_gtod_data"),aligned(16))) +#define __vsyscall_fn __attribute__ ((unused,__section__(".vsyscall_fn")))#define VGETCPU_RDTSCP 1#define VGETCPU_LSL 2 -struct vxtime_data { -long hpet_address;/* HPET base address */ -int last; -unsigned long last_tsc; -long quot; -long tsc_quot; -int mode; -};#define hpet_readl (a) readl((const void __iomem *)fix_to_virt(FIX_HPET_BASE) + a)#define hpet_writel (d,a) writel(d, (void __iomem *)fix_to_virt(FIX_HPET_BASE) + a) -/* vsyscall space (readonly) */ -extern struct vxtime_data __vxtime;extern int __vgetcpu_mode; -extern struct timespec __xtime;extern volatile unsigned long __jiffies; -extern struct timezone __sys_tz; -extern seqlock_t __xtime_lock;/* kernel space (writeable) */ -extern struct vxtime_data vxtime;extern int vgetcpu_mode;extern struct timezone sys_tz; -extern int sysctl_vsyscall;extern seqlock_t xtime_lock; - -extern int sysctl_vsyscall; - -#define ARCH_HAVE_XTIME_LOCK 1 +extern struct vsyscall_gtod_data_t vsyscall_gtod_data;#endif /* __KERNEL__ */