Skip to contentSkip to conversation

x86_64: Generic timekeeping for x86_64

PATCH In review john stultz 2 participants 8 messages Sep 7, 2006 – Sep 9, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86_64: Generic timekeeping for x86_64

Hey Andi,
Just wanted to send this second pass on the x86_64 generic
timekeeping conversion. It includes a number of changes you suggested, however its possible I missed a few things. I've made sure the patchset compiles at each stage, and atleast w/ the box I was using it booted each step as well.

Still on the TODO:
o See about merging i386/x86-64 hpet.c (maybe driver/char/hpet.c as well?)
o 64bit hpet (should be trivial)
o Further cleanups

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

New in the current C6 release:
o x86-64 cleanups
o arch-trivial patch that converts arches w/o inter-tick resolution
o ia64 fixups by Peter Keilty

Let me know if you have any thoughts or comments!

thanks again!
-john

#1 lore raw

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

Provides generic infrastructure for vsyscall-gtod.

 include/linux/clocksource.h |    8 ++++++++
 include/linux/time.h        |    1 +
 kernel/timer.c              |    1 +
 3 files changed, 10 insertions(+)

linux-2.6.18-rc6_timeofday-vsyscall-support_C6.patch
============================================

include/linux/clocksource.h +8 -0
index d852024..cd4d514 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;
@@ -182,4 +184,10 @@ int clocksource_register(struct clocksou
 void 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 */
include/linux/time.h +1 -0
index a5b7399..14e12f0 100644
@@ -174,6 +174,7 @@ static inline void timespec_add_ns(struc
 	}
 	a->tv_nsec = ns;
 }
+
 #endif /* __KERNEL__ */
 
 #define NFDBITS			__NFDBITS
kernel/timer.c +1 -0
index 1d7dd62..a444016 100644
@@ -1165,6 +1165,7 @@ static void update_wall_time(void)
 		clock->xtime_nsec = 0;
 		clocksource_calculate_interval(clock, tick_nsec);
 	}
+	update_vsyscall(&xtime, clock);
 }
 
 /*
#2 lore raw

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-rc6_timeofday-arch-x86-64-part1_C6.patch
============================================

arch/i386/kernel/acpi/boot.c +6 -13
index ee003bc..ba6c82d 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);
#3 lore raw

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-rc6_timeofday-arch-x86-64-part2_C6.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
#4 lore raw

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 +-----------------------------------------
 drivers/acpi/processor_idle.c |    1 
 include/asm-x86_64/proto.h    |    1 
 include/asm-x86_64/timex.h    |    2 
 6 files changed, 22 insertions(+), 398 deletions(-)

linux-2.6.18-rc6_timeofday-arch-x86-64-part3_C6.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

drivers/acpi/processor_idle.c +1 -0
index 7106606..415bfa7 100644
@@ -41,6 +41,7 @@
 
 #include <asm/io.h>
 #include <asm/uaccess.h>
+#include <asm/timex.h>
 
 #include <acpi/acpi_bus.h>
 #include <acpi/processor.h>
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;
include/asm-x86_64/timex.h +2 -0
index b9e5320..40167eb 100644
@@ -41,6 +41,8 @@ static __always_inline cycles_t get_cycl
 
 extern unsigned int cpu_khz;
 
+extern void mark_tsc_unstable(void);
+
 extern int read_current_timer(unsigned long *timer_value);
 #define ARCH_HAS_READ_CURRENT_TIMER	1
 
#5 lore raw

PATCH 5/6 x86_64: Clocksources for x86-64

In reply to john stultz

Break up HPET and TSC code into their own .c files. Also add clocksource structures for both.

 arch/x86_64/kernel/Makefile |    2 
 arch/x86_64/kernel/hpet.c   |  469 +++++++++++++++++++++++++++++++++++++
 arch/x86_64/kernel/time.c   |  557 --------------------------------------------
 arch/x86_64/kernel/tsc.c    |  222 +++++++++++++++++
 include/asm-x86_64/hpet.h   |    6 
 include/asm-x86_64/timex.h  |    2 
 6 files changed, 705 insertions(+), 553 deletions(-)

linux-2.6.18-rc6_timeofday-arch-x86-64-part4_C6.patch
============================================

arch/x86_64/kernel/Makefile +1 -1
index b5aaeaf..5834f49 100644
@@ -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
arch/x86_64/kernel/hpet.c new file +469 -0

469 lines not on this page · raw message

arch/x86_64/kernel/time.c +6 -551

618 lines not on this page · raw message

arch/x86_64/kernel/tsc.c new file +222 -0

222 lines not on this page · raw message

include/asm-x86_64/hpet.h +6 -0
index 60d5127..c10d4e4 100644
@@ -60,6 +60,12 @@ extern int apic_is_clustered_box(void);
 extern int hpet_use_timer;
 extern unsigned long hpet_address;
 
+extern int hpet_reenable(void);
+extern int hpet_arch_init(void);
+extern int hpet_stop(void);
+extern unsigned int hpet_calibrate_tsc(void);
+
+
 #ifdef CONFIG_HPET_EMULATE_RTC
 extern int hpet_mask_rtc_irq_bit(unsigned long bit_mask);
 extern int hpet_set_rtc_irq_bit(unsigned long bit_mask);
include/asm-x86_64/timex.h +1 -1
index 40167eb..c5165cd 100644
@@ -42,7 +42,7 @@ static __always_inline cycles_t get_cycl
 extern unsigned int cpu_khz;
 
 extern void mark_tsc_unstable(void);
-
+extern void set_cyc2ns_scale(unsigned long khz);
 extern int read_current_timer(unsigned long *timer_value);
 #define ARCH_HAS_READ_CURRENT_TIMER	1
 
#6 lore raw

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/hpet.c        |    6 ++
 arch/x86_64/kernel/time.c        |    9 ---
 arch/x86_64/kernel/tsc.c         |    7 ++
 arch/x86_64/kernel/vmlinux.lds.S |   24 +-------
 arch/x86_64/kernel/vsyscall.c    |  111 ++++++++++++++++++++++-----------------
 include/asm-x86_64/proto.h       |    2 
 include/asm-x86_64/timex.h       |    2 
 include/asm-x86_64/vsyscall.h    |   39 +------------
 9 files changed, 92 insertions(+), 112 deletions(-)

linux-2.6.18-rc6_timeofday-arch-x86-64-part5_C6.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/hpet.c +6 -0
index 8ac58a8..97be615 100644
@@ -421,6 +421,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,
@@ -429,6 +434,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 +1 -8
index aafcd2f..afa2f7f 100644
@@ -55,16 +55,9 @@ DEFINE_SPINLOCK(i8253_lock);
 #define NSEC_PER_TICK (NSEC_PER_SEC / HZ)
 
 
-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)
 {
arch/x86_64/kernel/tsc.c +7 -0
index f662183..5c55a51 100644
@@ -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 +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 +65 -46

165 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 c5165cd..372bdc6 100644
@@ -46,6 +46,4 @@ extern void set_cyc2ns_scale(unsigned lo
 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 +5 -34
index a85e16f..b8f7ab4 100644
@@ -15,48 +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
+extern struct vsyscall_gtod_data_t vsyscall_gtod_data;
 
 #endif /* __KERNEL__ */
 
#7 lore raw
In reply to john stultz
Quoted 6 lines · john stultz

Hey Andi,
Just wanted to send this second pass on the x86_64 generic
timekeeping conversion. It includes a number of changes you suggested, however its possible I missed a few things. I've made sure the patchset compiles at each stage, and atleast w/ the box I was using it booted each step as well.

Looks all reasonable from a quick look.
I assume it will clash with the recent patch to remove wall_jiffies use, but that should be easy to fix.

How does the performance of the user space gettimeofday look compared to the old code in TSC mode?

BTW I got some experimental code to put clock_gettime into user space too, but that can be later merged I guess.

-Andi