Skip to contentSkip to conversation

x86_64: Generic timekeeping for x86_64

RFC PATCH In review john stultz 2 participants 18 messages Aug 9, 2006 Timekeeping, clocksource core, NTP, alarmtimer

lore
Share & tools
lore
#0 lore raw

cover x86_64: Generic timekeeping for x86_64

Hey Andi,
Just wanted to send this by as a first pass on the x86_64
generic timekeeping conversion. If you have the time, a quick review and comments would be greatly appreciated.

As this is the first run after breaking up the larger patch I
was carrying around, there might be a few rough spots. I've made sure the patchset compiles at each stage, but I've not boot tested each step (all together they run fine, though).

If anyone else is interested here, my full timekeeping tree can be found here: http://sr71.net/~jstultz/tod/

New in the current C5 release:
o ia64 and sparc64 conversions by Peter Keilty!

Let me know if you have any thoughts or comments!

thanks again!
-john

#1 lore raw

RFC PATCH 1/6 x86_64: Enable arch-generic vsyscall support.

Provides generic infrastructure for vsyscall-gtod.

 include/linux/clocksource.h |    2 ++
 kernel/timer.c              |    7 +++++++
 2 files changed, 9 insertions(+)

linux-2.6.18-rc4_timeofday-vsyscall-support_C5.patch
============================================

include/linux/clocksource.h +2 -0
index d852024..f554273 100644
@@ -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;
kernel/timer.c +7 -0
index b650f04..08b4a02 100644
@@ -1023,6 +1023,12 @@ static int __init timekeeping_init_devic
 
 device_initcall(timekeeping_init_device);
 
+#ifdef CONFIG_GENERIC_TIME_VSYSCALL
+extern void update_vsyscall(struct timespec* ts, struct clocksource* c);
+#else
+#define update_vsyscall(now, c)
+#endif
+
 /*
  * If the error is already larger, we look ahead even further
  * to compensate for late or lost adjustments.
@@ -1165,6 +1171,7 @@ static void update_wall_time(void)
 		clock->xtime_nsec = 0;
 		clocksource_calculate_interval(clock, tick_nsec);
 	}
+	update_vsyscall(&xtime, clock);
 }
 
 /*
#2 lore raw

Re: [RFC][PATCH 1/6] x86_64: Enable arch-generic vsyscall support.

Quoted 6 lines
kernel/timer.c +0 -0
index b650f04..08b4a02 100644

kernel/timer.c static int __init timekeeping_init_devic · line 1030

Quoted 8 lines
kernel/timer.c +5 -0
@@ -1023,6 +1023,12 @@ static int __init timekeeping_init_devic
 
 device_initcall(timekeeping_init_device);
 
+#ifdef CONFIG_GENERIC_TIME_VSYSCALL
+extern void update_vsyscall(struct timespec* ts, struct clocksource* c);
+#else
+#define update_vsyscall(now, c)
+#endif

Using a weak dummy function would be a bit cleaner.

-Andi

Quoted 1 line
#3 lore raw

Re: [RFC][PATCH 1/6] x86_64: Enable arch-generic vsyscall support.

Quoted 8 lines · Andi Kleen
Quoted 8 lines
kernel/timer.c +0 -0
index b650f04..08b4a02 100644
@@ -1023,6 +1023,12 @@ static int __init timekeeping_init_devic
 
 device_initcall(timekeeping_init_device);
 
Quoted 7 lines

kernel/timer.c static int __init timekeeping_init_devic · line 1030

Quoted 5 lines
kernel/timer.c +5 -0
+#ifdef CONFIG_GENERIC_TIME_VSYSCALL
+extern void update_vsyscall(struct timespec* ts, struct clocksource* c);
+#else
+#define update_vsyscall(now, c)
+#endif

Using a weak dummy function would be a bit cleaner.

Will compilers optimize out the call properly?

Looking at it now, it probably should go in a .h file and the empty define should be a proper "do { } while(0)"

thanks
-john

#4 lore raw

Re: [RFC][PATCH 1/6] x86_64: Enable arch-generic vsyscall support.

Quoted 17 lines · john stultz
Quoted 8 lines · Andi Kleen
Quoted 8 lines
kernel/timer.c +0 -0
index b650f04..08b4a02 100644
@@ -1023,6 +1023,12 @@ static int __init timekeeping_init_devic
 
 device_initcall(timekeeping_init_device);
 
Quoted 7 lines

kernel/timer.c static int __init timekeeping_init_devic · line 1030

Quoted 5 lines
kernel/timer.c +5 -0
+#ifdef CONFIG_GENERIC_TIME_VSYSCALL
+extern void update_vsyscall(struct timespec* ts, struct clocksource* c);
+#else
+#define update_vsyscall(now, c)
+#endif

Using a weak dummy function would be a bit cleaner.

Quoted 1 line

Will compilers optimize out the call properly?

No, but it's just a call ; ret then.

Quoted 3 lines

Looking at it now, it probably should go in a .h file and the empty define should be a proper "do { } while(0)"

Or use weak

-Andi

#5 lore raw

RFC PATCH 2/6 x86_64: hpet_address cleanup

In reply to john stultz

In 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 |   19 ++++++-------------
 arch/x86_64/kernel/apic.c    |    3 ++-
 arch/x86_64/kernel/time.c    |   34 ++++++++++++++++++----------------
 include/asm-x86_64/hpet.h    |    1 +
 4 files changed, 27 insertions(+), 30 deletions(-)

linux-2.6.18-rc4_timeofday-arch-x86-64-part1_C5.patch
============================================

arch/i386/kernel/acpi/boot.c +6 -13
index 0db6387..f2c43da 100644
@@ -575,6 +575,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)
 {
@@ -595,21 +596,13 @@ static int __init acpi_parse_hpet(unsign
 		return -1;
 	}
 #ifdef	CONFIG_X86_64
-	vxtime.hpet_address = hpet_tbl->addr.addrl |
+	hpet_address = hpet_tbl->addr.addrl |
 	    ((long)hpet_tbl->addr.addrh << 32);
-
+#else
+	hpet_address = hpet_tbl->addr.addrl;
+#endif
 	printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
-	       hpet_tbl->id, vxtime.hpet_address);
-#else				/* X86 */
-	{
-		extern unsigned long hpet_address;
-
-		hpet_address = hpet_tbl->addr.addrl;
-		printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
-		       hpet_tbl->id, hpet_address);
-	}
-#endif				/* X86 */
-
+	       hpet_tbl->id, hpet_address);
 	return 0;
 }
 #else
arch/x86_64/kernel/apic.c +2 -1
index 2b8cef0..1b9e3d3 100644
@@ -36,6 +36,7 @@
 #include <asm/idle.h>
 #include <asm/proto.h>
 #include <asm/timex.h>
+#include <asm/hpet.h>
 
 int apic_verbosity;
 int apic_runs_main_timer;
@@ -727,7 +728,7 @@ static void setup_APIC_timer(unsigned in
 	local_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 +18 -16
index 7a9b182..da89e60 100644
@@ -67,6 +67,7 @@ static int notsc __initdata = 0;
 
 unsigned 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 */
@@ -326,7 +327,7 @@ static noinline void handle_lost_ticks(i
 		       KERN_WARNING "Your time source seems to be instable or "
 		   		"some driver is hogging interupts\n");
 		print_symbol("rip %s\n", 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) - 
@@ -334,6 +335,7 @@ static noinline void handle_lost_ticks(i
 			else
 				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. */
@@ -364,7 +366,7 @@ void main_timer_handler(struct pt_regs *
 
 	write_seqlock(&xtime_lock);
 
-	if (vxtime.hpet_address)
+	if (hpet_address)
 		offset = hpet_readl(HPET_COUNTER);
 
 	if (hpet_use_timer) {
@@ -734,7 +736,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));
@@ -747,7 +749,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;
@@ -816,10 +818,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.
@@ -873,7 +875,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 {
@@ -899,8 +901,7 @@ void __init time_init(void)
 	char *gtod;
 
 	if (nohpet)
-		vxtime.hpet_address = 0;
-
+		hpet_address = 0;
 	xtime.tv_sec = get_cmos_time();
 	xtime.tv_nsec = 0;
 
@@ -910,7 +911,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 */
@@ -918,7 +919,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();
@@ -979,18 +980,19 @@ __init static char *time_init_gtod(void)
 
 	if (unsynchronized_tsc())
 		notsc = 1;
-	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
 	unsigned long ctime = get_cmos_time();
 	unsigned long sleep_length = (ctime - sleep_start) * HZ;
 
-	if (vxtime.hpet_address)
+	if (hpet_address)
 		hpet_reenable();
 	else
 		i8254_timer_resume();
@@ -1118,7 +1120,7 @@ static unsigned int hpet_t1_cmp; /* cach
 
 int is_hpet_enabled(void)
 {
-	return vxtime.hpet_address != 0;
+	return hpet_address != 0;
 }
 
 /*
include/asm-x86_64/hpet.h +1 -0
index b390984..60d5127 100644
@@ -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);
#6 lore raw

Re: [RFC][PATCH 2/6] x86_64: hpet_address cleanup

Quoted 4 lines · john stultz

In 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.

Does the kernel still boot with that patch only? Your new variable doesn't seem to be exported to vsyscalls

-Andi

#7 lore raw

Re: [RFC][PATCH 2/6] x86_64: hpet_address cleanup

Quoted 7 lines · Andi Kleen
Quoted 4 lines · john stultz

In 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.

Does the kernel still boot with that patch only?

Just tested, and yes it still boots, but my box doesn't have HPET so that isn't much of a test. :(

As I said in the announce mail, I've not boot tested each step, I suspect patches 4/6 and 5/6 will have troubles (vsyscall isn't disabled, but the updating is). I'll try to address that in the next release.

Quoted 1 line

Your new variable doesn't seem to be exported to vsyscalls

The vxtime structure hasn't yet been removed and we set vxtime.hpet_address = hpet_address in necessary spots, so it should be ok.

thanks
-john

#8 lore raw

RFC PATCH 3/6 x86_64: Remove apic_runs_main_timer

In reply to john stultz

Part of the x86-64 cleanup for generic timekeeping. Remove apic_runs_main_timer, on request from Andi, since it doesn't work on many systems.

 arch/x86_64/kernel/apic.c |   30 +-----------------------------
 arch/x86_64/kernel/time.c |    2 --
 include/asm-x86_64/apic.h |    1 -
 3 files changed, 1 insertion(+), 32 deletions(-)

linux-2.6.18-rc4_timeofday-arch-x86-64-part2_C5.patch
============================================

arch/x86_64/kernel/apic.c +1 -29
index 1b9e3d3..6173b2f 100644
@@ -39,7 +39,6 @@
 #include <asm/hpet.h>
 
 int apic_verbosity;
-int apic_runs_main_timer;
 int apic_calibrate_pmtmr __initdata;
 
 int disable_apic_timer __initdata;
@@ -747,16 +746,6 @@ static void setup_APIC_timer(unsigned in
 		} while (c2 - c1 < 300);
 	}
 	__setup_APIC_LVTT(clocks);
-	/* 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 &&
-		smp_processor_id() == boot_cpu_id &&
-		apic_runs_main_timer == 1 &&
-		!cpu_isset(boot_cpu_id, timer_interrupt_broadcast_ipi_mask)) {
-		stop_timer_interrupt();
-		apic_runs_main_timer++;
-	}
 	local_irq_restore(flags);
 }
 
@@ -946,8 +935,6 @@ void smp_local_timer_interrupt(struct pt
 #ifdef CONFIG_SMP
 	update_process_times(user_mode(regs));
 #endif
-	if (apic_runs_main_timer > 1 && smp_processor_id() == boot_cpu_id)
-		main_timer_handler(regs);
 	/*
 	 * We take the 'long' return path, and there every subsystem
 	 * grabs the appropriate locks (kernel lock/ irq lock).
@@ -1162,26 +1149,11 @@ static __init int setup_noapictimer(char
 	return 1;
 } 
 
-static __init int setup_apicmaintimer(char *str)
-{
-	apic_runs_main_timer = 1;
-	nohpet = 1;
-	return 1;
-}
-__setup("apicmaintimer", setup_apicmaintimer);
-
-static __init int setup_noapicmaintimer(char *str)
-{
-	apic_runs_main_timer = -1;
-	return 1;
-}
-__setup("noapicmaintimer", setup_noapicmaintimer);
-
 static __init int setup_apicpmtimer(char *s)
 {
 	apic_calibrate_pmtmr = 1;
 	notsc_setup(NULL);
-	return setup_apicmaintimer(NULL);
+	return 1;
 }
 __setup("apicpmtimer", setup_apicpmtimer);
 
arch/x86_64/kernel/time.c +0 -2
index da89e60..a4aef4e 100644
@@ -469,8 +469,6 @@ void main_timer_handler(struct pt_regs *
 
 static irqreturn_t timer_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-	if (apic_runs_main_timer > 1)
-		return IRQ_HANDLED;
 	main_timer_handler(regs);
 #ifdef CONFIG_X86_LOCAL_APIC
 	if (using_apic_timer)
include/asm-x86_64/apic.h +0 -1
index 9c96a0a..06fcdc2 100644
@@ -16,7 +16,6 @@
 #define APIC_DEBUG   2
 
 extern int apic_verbosity;
-extern int apic_runs_main_timer;
 
 /*
  * Define the default level of output to be very little
#9 lore raw

Re: [RFC][PATCH 3/6] x86_64: Remove apic_runs_main_timer

Quoted 3 lines · john stultz

Part of the x86-64 cleanup for generic timekeeping. Remove apic_runs_main_timer, on request from Andi, since it doesn't work on many systems.

Ok for me.

-Andi

#10 lore raw

RFC PATCH 4/6 x86_64: Enable CONFIG_GENERIC_TIME

In reply to john stultz

Enable CONFIG_GENERIC_TIME on x86_64 and remove arch specific timekeeping code.

 arch/x86_64/Kconfig          |    4 
 arch/x86_64/kernel/pmtimer.c |   58 -------
 arch/x86_64/kernel/time.c    |  354 +------------------------------------------
 include/asm-x86_64/proto.h   |    1 
 4 files changed, 19 insertions(+), 398 deletions(-)

linux-2.6.18-rc4_timeofday-arch-x86-64-part3_C5.patch
============================================

arch/x86_64/Kconfig +4 -0
index 28df7d8..fabb174 100644
@@ -24,6 +24,10 @@ config X86
 	bool
 	default y
 
+config GENERIC_TIME
+	bool
+	default y
+
 config LOCKDEP_SUPPORT
 	bool
 	default y
arch/x86_64/kernel/pmtimer.c +0 -58

76 lines not on this page · raw message

arch/x86_64/kernel/time.c +15 -339

442 lines not on this page · raw message

include/asm-x86_64/proto.h +0 -1
index 038fe1f..716ac55 100644
@@ -47,7 +47,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;
#11 lore raw

RFC PATCH 5/6 x86_64: Clocksources for x86-64

In reply to john stultz

Re-add TSC and HPET support to x86_64 via clocksource infrastructure.

 arch/x86_64/kernel/time.c  |  133 +++++++++++++++++++++++++++++++++++++++++++--
 include/asm-x86_64/timex.h |    3 +
 2 files changed, 133 insertions(+), 3 deletions(-)

linux-2.6.18-rc4_timeofday-arch-x86-64-part4_C5.patch
============================================

arch/x86_64/kernel/time.c +130 -3
index d18230a..546abc7 100644
@@ -39,6 +39,7 @@
 #include <asm/sections.h>
 #include <linux/cpufreq.h>
 #include <linux/hpet.h>
+#include <linux/clocksource.h>
 #ifdef CONFIG_X86_LOCAL_APIC
 #include <asm/apic.h>
 #endif
@@ -60,8 +61,9 @@ static int notsc __initdata = 0;
 #define NS_SCALE	10 /* 2^10, carefully chosen */
 #define US_SCALE	32 /* 2^32, arbitralrily chosen */
 
-unsigned int cpu_khz;					/* TSC clocks / usec, not used here */
+unsigned int cpu_khz;					/* CPU clocks / usec, not used here */
 EXPORT_SYMBOL(cpu_khz);
+unsigned int tsc_khz;					/* TSC clocks / usec, not used here */
 unsigned long hpet_address;
 static unsigned long hpet_period;			/* fsecs / HPET clock */
 unsigned long hpet_tick;				/* HPET clocks / interrupt */
@@ -382,8 +384,9 @@ static int time_cpufreq_notifier(struct 
 		cpufreq_scale(loops_per_jiffy_ref, ref_freq, freq->new);
 
 		cpu_khz = cpufreq_scale(cpu_khz_ref, ref_freq, freq->new);
-		if (!(freq->flags & CPUFREQ_CONST_LOOPS))
-			vxtime.tsc_quot = (USEC_PER_MSEC << US_SCALE) / cpu_khz;
+		if (!(freq->flags & CPUFREQ_CONST_LOOPS)) {
+			tsc_khz = cpu_khz;
+		}
 	}
 	
 	set_cyc2ns_scale(cpu_khz_ref);
@@ -659,6 +662,10 @@ void __init time_init(void)
 		cpu_khz = pit_calibrate_tsc();
 		timename = "PIT";
 	}
+	tsc_khz = cpu_khz;
+
+	if (unsynchronized_tsc())
+		mark_tsc_unstable();
 
 	printk(KERN_INFO "time.c: Detected %d.%03d MHz processor.\n",
 		cpu_khz / 1000, cpu_khz % 1000);
@@ -999,3 +1006,123 @@ int __init notsc_setup(char *s)
 }
 
 __setup("notsc", notsc_setup);
+
+
+/* clock source code: */
+
+static unsigned long current_tsc_khz = 0;
+
+static int tsc_update_callback(void);
+
+static cycle_t read_tsc(void)
+{
+	cycle_t ret;
+	rdtscll(ret);
+	return ret;
+}
+
+static struct clocksource clocksource_tsc = {
+	.name			= "tsc",
+	.rating			= 300,
+	.read			= read_tsc,
+	.mask			= (cycle_t)-1,
+	.mult			= 0, /* to be set */
+	.shift			= 22,
+	.update_callback	= tsc_update_callback,
+	.is_continuous		= 1,
+};
+
+static int tsc_update_callback(void)
+{
+	int change = 0;
+
+	/* check to see if we should switch to the safe clocksource: */
+	if (clocksource_tsc.rating != 50 && check_tsc_unstable()) {
+		clocksource_tsc.rating = 50;
+		clocksource_reselect();
+		change = 1;
+	}
+
+	/* only update if tsc_khz has changed: */
+	if (current_tsc_khz != tsc_khz){
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+		change = 1;
+	}
+	return change;
+}
+
+static int __init init_tsc_clocksource(void)
+{
+	if (!notsc && tsc_khz) {
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+		return clocksource_register(&clocksource_tsc);
+	}
+	return 0;
+}
+
+module_init(init_tsc_clocksource);
+
+
+#define HPET_MASK	0xFFFFFFFF
+#define HPET_SHIFT	22
+
+/* FSEC = 10^-15 NSEC = 10^-9 */
+#define FSEC_PER_NSEC	1000000
+
+static void *hpet_ptr;
+
+static cycle_t read_hpet(void)
+{
+	return (cycle_t)readl(hpet_ptr);
+}
+
+struct clocksource clocksource_hpet = {
+	.name		= "hpet",
+	.rating		= 250,
+	.read		= read_hpet,
+	.mask		= (cycle_t)HPET_MASK,
+	.mult		= 0, /* set below */
+	.shift		= HPET_SHIFT,
+	.is_continuous	= 1,
+};
+
+static int __init init_hpet_clocksource(void)
+{
+	unsigned long hpet_period;
+	void __iomem *hpet_base;
+	u64 tmp;
+
+	if (!hpet_address)
+		return -ENODEV;
+
+	/* calculate the hpet address: */
+	hpet_base =
+		(void __iomem*)ioremap_nocache(hpet_address, HPET_MMAP_SIZE);
+	hpet_ptr = hpet_base + HPET_COUNTER;
+
+	/* calculate the frequency: */
+	hpet_period = readl(hpet_base + HPET_PERIOD);
+
+	/*
+	 * hpet period is in femto seconds per cycle
+	 * so we need to convert this to ns/cyc units
+	 * aproximated by mult/2^shift
+	 *
+	 *  fsec/cyc * 1nsec/1000000fsec = nsec/cyc = mult/2^shift
+	 *  fsec/cyc * 1ns/1000000fsec * 2^shift = mult
+	 *  fsec/cyc * 2^shift * 1nsec/1000000fsec = mult
+	 *  (fsec/cyc << shift)/1000000 = mult
+	 *  (hpet_period << shift)/FSEC_PER_NSEC = mult
+	 */
+	tmp = (u64)hpet_period << HPET_SHIFT;
+	do_div(tmp, FSEC_PER_NSEC);
+	clocksource_hpet.mult = (u32)tmp;
+
+	return clocksource_register(&clocksource_hpet);
+}
+
+module_init(init_hpet_clocksource);
include/asm-x86_64/timex.h +3 -0
index b9e5320..11c6820 100644
@@ -40,6 +40,9 @@ static __always_inline cycles_t get_cycl
 }
 
 extern unsigned int cpu_khz;
+extern unsigned int tsc_khz;
+
+extern void mark_tsc_unstable(void);
 
 extern int read_current_timer(unsigned long *timer_value);
 #define ARCH_HAS_READ_CURRENT_TIMER	1
#12 lore raw

Re: [RFC][PATCH 5/6] x86_64: Clocksources for x86-64

Quoted 1 line · john stultz

Re-add TSC and HPET support to x86_64 via clocksource infrastructure.

The actual review needed is in the existing clock source drivers I guess.

I definitely don't want the "read three times" pmtimer code that is in the generic clock source on 64bit. You would need at least an ifdef there or better detect the case where it is needed at runtime.

arch/x86_64/kernel/time.c static int notsc __initdata = 0; · line 64

Quoted 2 lines
arch/x86_64/kernel/time.c +1 -1
-unsigned int cpu_khz;					/* TSC clocks / usec, not used here */
+unsigned int cpu_khz;					/* CPU clocks / usec, not used here */

The previous comment was more correct. It is really TSC clocks.

Quoted 2 lines

EXPORT_SYMBOL(cpu_khz);
+unsigned int tsc_khz; /* TSC clocks / usec, not used here */

And that comment can't have the same unit as the earlier one?

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1013

Quoted 3 lines
arch/x86_64/kernel/time.c +3 -0
+/* clock source code: */
+
+static unsigned long current_tsc_khz = 0;

Another one? Don't we have already too many of these variables?

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1020

Quoted 7 lines
arch/x86_64/kernel/time.c +7 -0
+
+static int tsc_update_callback(void);
+
+static cycle_t read_tsc(void)
+{
+	cycle_t ret;
+	rdtscll(ret);

It would need to be _sync

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1052

Quoted 8 lines
arch/x86_64/kernel/time.c +8 -0
+
+	/* only update if tsc_khz has changed: */
+	if (current_tsc_khz != tsc_khz){
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+		change = 1;
+	}

Are you sure this handles p-state invariant TSC correctly?

And I hope there is a printk somewhere when this happens?

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1058

Quoted 6 lines
arch/x86_64/kernel/time.c +6 -0
+	return change;
+}
+
+static int __init init_tsc_clocksource(void)
+{
+	if (!notsc && tsc_khz) {

How can tsc_khz be 0 ?

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1067

Quoted 9 lines
arch/x86_64/kernel/time.c +9 -0
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+		return clocksource_register(&clocksource_tsc);
+	}
+	return 0;
+}
+
+module_init(init_tsc_clocksource);

So what clocksource does it use before?

BTW I guess i would be ok with putting tsc and hpet into their own files. And is there a reason HPET can't be generic in drivers/clocksource now?

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1080

Quoted 13 lines
arch/x86_64/kernel/time.c +13 -0
+
+
+#define HPET_MASK	0xFFFFFFFF
+#define HPET_SHIFT	22
+
+/* FSEC = 10^-15 NSEC = 10^-9 */
+#define FSEC_PER_NSEC	1000000
+
+static void *hpet_ptr;
+
+static cycle_t read_hpet(void)
+{
+	return (cycle_t)readl(hpet_ptr);

No 64bit HPET support?

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1091

Quoted 11 lines
arch/x86_64/kernel/time.c +11 -0
+}
+
+struct clocksource clocksource_hpet = {
+	.name		= "hpet",
+	.rating		= 250,
+	.read		= read_hpet,
+	.mask		= (cycle_t)HPET_MASK,
+	.mult		= 0, /* set below */
+	.shift		= HPET_SHIFT,
+	.is_continuous	= 1,
+};

How is priority of the different time sources established in this?

e.g. is the old fallback selection logic still fully functional?

-Andi

#13 lore raw

Re: [RFC][PATCH 5/6] x86_64: Clocksources for x86-64

Quoted 5 lines · Andi Kleen
Quoted 1 line · john stultz

Re-add TSC and HPET support to x86_64 via clocksource infrastructure.

The actual review needed is in the existing clock source drivers I guess.

Well, the acpi_pm is the only x86-64/i386 generic clocksource, so yes, please look that one over if you have a chance.

Quoted 3 lines

I definitely don't want the "read three times" pmtimer code that is in the generic clock source on 64bit. You would need at least an ifdef there or better detect the case where it is needed at runtime.

We do have blacklist detection enabled, and by default it does only a single read.

Quoted 5 lines

arch/x86_64/kernel/time.c static int notsc __initdata = 0; · line 64

Quoted 3 lines
arch/x86_64/kernel/time.c +1 -1
-unsigned int cpu_khz;					/* TSC clocks / usec, not used here */
+unsigned int cpu_khz;					/* CPU clocks / usec, not used here */

The previous comment was more correct. It is really TSC clocks.

Well, I'm trying to clean up the cpu_khz to be a cpufreq rating so the scheduler can make better decisions, while still having a constant tsc_khz on systems that do not change freq. This change can be thrown out, or atleast delayed if its an issue.

Quoted 11 lines
Quoted 3 lines

EXPORT_SYMBOL(cpu_khz);
+unsigned int tsc_khz; /* TSC clocks / usec, not used here */

And that comment can't have the same unit as the earlier one?

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1013

Quoted 3 lines
arch/x86_64/kernel/time.c +3 -0
+/* clock source code: */
+
+static unsigned long current_tsc_khz = 0;

Another one? Don't we have already too many of these variables?

Heh. :) That one is specific to the TSC clocksource, which can only change state during an update_callback(). But yes, its unclear and could use a name-change and/or just be static to tsc_update_callback()

Quoted 9 lines

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1020

Quoted 7 lines
arch/x86_64/kernel/time.c +7 -0
+
+static int tsc_update_callback(void);
+
+static cycle_t read_tsc(void)
+{
+	cycle_t ret;
+	rdtscll(ret);

It would need to be _sync

Good point.

Quoted 10 lines

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1052

Quoted 8 lines
arch/x86_64/kernel/time.c +8 -0
+
+	/* only update if tsc_khz has changed: */
+	if (current_tsc_khz != tsc_khz){
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+		change = 1;
+	}

Are you sure this handles p-state invariant TSC correctly?

It should, as the tsc_khz won't be changed on those systems.

Quoted 1 line

And I hope there is a printk somewhere when this happens?

Maybe a BUGON would be the right thing if the TSC is p-state invariant?

Quoted 8 lines

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1058

Quoted 6 lines
arch/x86_64/kernel/time.c +6 -0
+	return change;
+}
+
+static int __init init_tsc_clocksource(void)
+{
+	if (!notsc && tsc_khz) {

How can tsc_khz be 0 ?

In the case that cpu_khz is zero. Hmmm, that be an i386-ism that slipped in. I'll look into it.

Quoted 11 lines

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1067

Quoted 9 lines
arch/x86_64/kernel/time.c +9 -0
+		current_tsc_khz = tsc_khz;
+		clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz,
+							clocksource_tsc.shift);
+		return clocksource_register(&clocksource_tsc);
+	}
+	return 0;
+}
+
+module_init(init_tsc_clocksource);

So what clocksource does it use before?

In early boot, the jiffies clocksource is used until the clocksource drivers are registered.

Quoted 1 line

BTW I guess i would be ok with putting tsc and hpet into their own files.

Great, I actually prefer that, but I didn't want to change too much right off.

Quoted 1 line

And is there a reason HPET can't be generic in drivers/clocksource now?

Nope. Thomas and Ingo suggested the clocksource drivers should be arch specific, but hpet has been generic before.

We'll still likely need an arch/x86_64/hpet.c for the differences in the HPET interrupt bits between i386/x86_64, but those could be combined at some point (also ia64 will be interested in the same bits).

Quoted 5 lines
Quoted 5 lines
arch/x86_64/kernel/time.c +5 -0
+#define HPET_MASK	0xFFFFFFFF
+#define HPET_SHIFT	22
+
+/* FSEC = 10^-15 NSEC = 10^-9 */
+#define FSEC_PER_NSEC	1000000
Quoted 8 lines

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1080

Quoted 6 lines
arch/x86_64/kernel/time.c +6 -0
+
+static void *hpet_ptr;
+
+static cycle_t read_hpet(void)
+{
+	return (cycle_t)readl(hpet_ptr);

No 64bit HPET support?

For no reason I can recall. Its probably a leftover from the i386/x86_64 shared hpet driver.

Quoted 5 lines
Quoted 5 lines
arch/x86_64/kernel/time.c +5 -0
+}
+
+struct clocksource clocksource_hpet = {
+	.name		= "hpet",
+	.rating		= 250,
Quoted 8 lines

arch/x86_64/kernel/time.c int __init notsc_setup(char *s) · line 1091

Quoted 6 lines
arch/x86_64/kernel/time.c +6 -0
+	.read		= read_hpet,
+	.mask		= (cycle_t)HPET_MASK,
+	.mult		= 0, /* set below */
+	.shift		= HPET_SHIFT,
+	.is_continuous	= 1,
+};

How is priority of the different time sources established in this?

Via the rating value above.

Quoted 1 line

e.g. is the old fallback selection logic still fully functional?

Yep, the only complication is when the TSC is marked unstable (using the same logic as before) and we fall back to the next best clocksource (HPET, then ACPI PM).

Once again, I really appreciate your time reviewing this!

I'll fix up the issues you pointed for the next release.

thanks
-john

#14 lore raw

RFC PATCH 6/6 x86_64: GENERIC_TIME based vsyscall code

In reply to john stultz

Re-enable vsyscall gettimeofday using the generic clocksource infrastructure.

 arch/x86_64/Kconfig              |    4 +
 arch/x86_64/kernel/time.c        |   23 +++++--
 arch/x86_64/kernel/vmlinux.lds.S |   24 +-------
 arch/x86_64/kernel/vsyscall.c    |  116 ++++++++++++++++++++++++++-------------
 include/asm-x86_64/proto.h       |    2 
 include/asm-x86_64/timex.h       |    2 
 include/asm-x86_64/vsyscall.h    |   38 +-----------
 7 files changed, 105 insertions(+), 104 deletions(-)

linux-2.6.18-rc4_timeofday-arch-x86-64-part5_C5.patch
============================================

arch/x86_64/Kconfig +4 -0
index fabb174..6167ce2 100644
@@ -28,6 +28,10 @@ config GENERIC_TIME
 	bool
 	default y
 
+config GENERIC_TIME_VSYSCALL
+	bool
+	default y
+
 config LOCKDEP_SUPPORT
 	bool
 	default y
arch/x86_64/kernel/time.c +15 -8
index 546abc7..3501871 100644
@@ -68,16 +68,9 @@ 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 */
-unsigned long vxtime_hz = PIT_TICK_RATE;
 int report_lost_ticks;				/* command line option */
-unsigned long long monotonic_base;
 
-struct vxtime_data __vxtime __section_vxtime;	/* for vsyscalls */
-
-volatile unsigned long __jiffies __section_jiffies = INITIAL_JIFFIES;
-unsigned long __wall_jiffies __section_wall_jiffies = INITIAL_JIFFIES;
-struct timespec __xtime __section_xtime;
-struct timezone __sys_tz __section_sys_tz;
+volatile unsigned long jiffies  = INITIAL_JIFFIES;
 
 unsigned long profile_pc(struct pt_regs *regs)
 {
@@ -1021,6 +1014,13 @@ static cycle_t read_tsc(void)
 	return ret;
 }
 
+static cycle_t __vsyscall_fn vread_tsc(void)
+{
+	cycle_t ret;
+	rdtscll(ret);
+	return ret;
+}
+
 static struct clocksource clocksource_tsc = {
 	.name			= "tsc",
 	.rating			= 300,
@@ -1030,6 +1030,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)
@@ -1080,6 +1081,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,
@@ -1088,6 +1094,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/vmlinux.lds.S +4 -20
index 7c4de31..9e7c048 100644
@@ -93,27 +93,11 @@ SECTIONS
   __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);
-
-  .wall_jiffies : AT(VLOAD(.wall_jiffies)) { *(.wall_jiffies) }
-  wall_jiffies = VVIRT(.wall_jiffies);
-
-  .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);
-
+  .vsyscall_fn : AT(VLOAD(.vsyscall_fn)) { *(.vsyscall_fn) }
   . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
-  .jiffies : AT(VLOAD(.jiffies)) { *(.jiffies) }
-  jiffies = VVIRT(.jiffies);
+  .vsyscall_gtod_data : AT(VLOAD(.vsyscall_gtod_data)) { *(.vsyscall_gtod_data) }
+  vsyscall_gtod_data = VVIRT(.vsyscall_gtod_data);
+
 
   .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT(VLOAD(.vsyscall_1)) { *(.vsyscall_1) }
   .vsyscall_2 ADDR(.vsyscall_0) + 2048: AT(VLOAD(.vsyscall_2)) { *(.vsyscall_2) }
arch/x86_64/kernel/vsyscall.c +78 -38

175 lines not on this page · raw message

include/asm-x86_64/proto.h +0 -2
index 716ac55..33d1a19 100644
@@ -47,9 +47,7 @@ extern u32 pmtmr_ioport;
 #else
 #define pmtmr_ioport 0
 #endif
-extern int sysctl_vsyscall;
 extern int nohpet;
-extern unsigned long vxtime_hz;
 
 extern int numa_setup(char *opt);
 
include/asm-x86_64/timex.h +0 -2
index 11c6820..043a774 100644
@@ -47,6 +47,4 @@ extern void mark_tsc_unstable(void);
 extern int read_current_timer(unsigned long *timer_value);
 #define ARCH_HAS_READ_CURRENT_TIMER	1
 
-extern struct vxtime_data vxtime;
-
 #endif
include/asm-x86_64/vsyscall.h +4 -34
index a85e16f..0b5a499 100644
@@ -15,49 +15,19 @@ enum vsyscall_num {
 
 #ifdef __KERNEL__
 
-#define __section_vxtime __attribute__ ((unused, __section__ (".vxtime"), aligned(16)))
-#define __section_wall_jiffies __attribute__ ((unused, __section__ (".wall_jiffies"), 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
-
-struct vxtime_data {
-	long hpet_address;	/* HPET base address */
-	int last;
-	unsigned long last_tsc;
-	long quot;
-	long tsc_quot;
-	int mode;
-};
+/* 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 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 struct timespec __xtime;
-extern volatile unsigned long __jiffies;
-extern unsigned long __wall_jiffies;
-extern struct timezone __sys_tz;
-extern seqlock_t __xtime_lock;
-
 /* kernel space (writeable) */
-extern struct vxtime_data vxtime;
 extern unsigned long wall_jiffies;
 extern struct timezone sys_tz;
-extern int sysctl_vsyscall;
 extern seqlock_t xtime_lock;
 
-extern int sysctl_vsyscall;
-
-#define ARCH_HAVE_XTIME_LOCK 1
-
 #endif /* __KERNEL__ */
 
 #endif /* _ASM_X86_64_VSYSCALL_H_ */
#15 lore raw

Re: [RFC][PATCH 6/6] x86_64: GENERIC_TIME based vsyscall code

arch/x86_64/kernel/time.c static cycle_t read_tsc(void) · line 1020

Quoted 2 lines · john stultz
arch/x86_64/kernel/time.c +2 -0
+	cycle_t ret;
+	rdtscll(ret);

_sync

arch/x86_64/kernel/time.c static cycle_t read_hpet(void) · line 1087

Quoted 4 lines
arch/x86_64/kernel/time.c +4 -0
+static cycle_t __vsyscall_fn vread_hpet(void)
+{
+	return (cycle_t)readl((void *)fix_to_virt(VSYSCALL_HPET) + 0xf0);
+}

64bit HPET?

Quoted 1 line

+extern struct vsyscall_gtod_data_t vsyscall_gtod_data;

No extern in .c please

arch/x86_64/kernel/vsyscall.c line 79

Quoted 5 lines
arch/x86_64/kernel/vsyscall.c +5 -0
+static __always_inline int syscall_gtod(struct timeval *tv, struct timezone *tz)
+{
+	int ret;
+
+	asm volatile("syscall"

You eliminated the patching away of the syscall opcode? Please retain that.

arch/x86_64/kernel/vsyscall.c line 109

Quoted 12 lines
arch/x86_64/kernel/vsyscall.c +10 -2
-	tv->tv_sec = sec + usec / 1000000;
-	tv->tv_usec = usec % 1000000;
+		now = __vsyscall_gtod_data.clock.vread();
+
+		base = __vsyscall_gtod_data.clock.cycle_last;
+		mask = __vsyscall_gtod_data.clock.mask;
+		mult = __vsyscall_gtod_data.clock.mult;
+		shift = __vsyscall_gtod_data.clock.shift;
+
+		*tv = __vsyscall_gtod_data.wall_time_tv;
+
+	} while (read_seqretry(&__vsyscall_gtod_data.lock, seq));

Do you have benchmarks on performance compared to the old code?

-Andi

#16 lore raw
In reply to john stultz
Quoted 4 lines · john stultz

Hey Andi,
Just wanted to send this by as a first pass on the x86_64
generic timekeeping conversion. If you have the time, a quick review and comments would be greatly appreciated.

Ok, but it's more 2.6.20 material

-Andi

#17 lore raw
Quoted 7 lines · Andi Kleen
Quoted 4 lines · john stultz

Hey Andi,
Just wanted to send this by as a first pass on the x86_64
generic timekeeping conversion. If you have the time, a quick review and comments would be greatly appreciated.

Ok, but it's more 2.6.20 material

Very much agreed! Just trying to get the ball rolling.

thanks
-john