Skip to contentSkip to conversation

new timeofday core subsystem (v. B1)

PATCH In review john stultz 3 participants 11 messages Jun 1, 2005 – Jun 7, 2005

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

PATCH 1/4 new timeofday core subsystem (v. B1)

Andrew, All,
I'm just re-spinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

With the goal to simplify, streamline and consolidate the time-of-day
infrastructure, I propose the following common implementation across all arches. This will allow generic bugs to be fixed once, reduce code duplication, and with many architectures sharing the same time source, this allows drivers to be written once for multiple architectures. Additionally it will better delineate the lines between the soft-timer subsystem and the time-of-day subsystem, opening the door for more flexible and better soft-timer management.

Features of this design:
========================

o Splits time of day management from timer interrupts
o Consolidates a large amount of code
o Generic algorithms which use time-source drivers chosen at runtime
o More consistent and readable code
o Uses nanoseconds as the kernel's base time unit
o Clearly separates the NTP code from the time code

For another description on the rework, see here:
http://lwn.net/Articles/120850/ (Many thanks to the LWN team for that easy to understand writeup!)

This patch implements the architecture independent portion of the new time of day subsystem. Included below is timeofday.c (which includes all the time of day management and accessor functions), ntp.c (which includes the ntp adjustment code, leapsecond processing, and ntp kernel state machine code), timesource.c (for timesource specific management functions), interface definition .h files, the example jiffies timesource (lowest common denominator time source, mainly for use as example code) and minimal hooks into arch independent code.

The patch does nothing without at least minimal architecture specific hooks (i386, x86-64 to follow), and it should be able to be applied to a tree without affecting the existing code.

Finally I'd like to thank the following people who have contributed ideas, criticism, testing and code that has helped shape this work:
George Anzinger, Nish Aravamudan, Max Asbock, Dominik Brodowski, Darren Hart, Christoph Lameter, Matt Mackal, Keith Mannthey, Martin Schwidefsky, Frank Sorenson, Ulrich Windl, Darrick Wong, and any others whom I've accidentally forgotten.

Andrew, please consider for inclusion for testing into your tree (I'd like to target around end of July for possible inclusion into mainline).

thanks
-john

linux-2.6.12-rc5_timeofday-core_B1.patch
========================================

drivers/Makefile (mode:100644) +1 -0
Index: drivers/Makefile
===================================================================
@@ -64,3 +64,4 @@
 obj-$(CONFIG_BLK_DEV_SGIIOC4)	+= sn/
 obj-y				+= firmware/
 obj-$(CONFIG_CRYPTO)		+= crypto/
+obj-$(CONFIG_NEWTOD)		+= timesource/
drivers/char/hangcheck-timer.c (mode:100644) +5 -0
Index: drivers/char/hangcheck-timer.c
===================================================================
@@ -49,6 +49,7 @@
 #include <linux/delay.h>
 #include <asm/uaccess.h>
 #include <linux/sysrq.h>
+#include <linux/timeofday.h>
 
 
 #define VERSION_STR "0.9.0"
@@ -130,8 +131,12 @@
 #endif
 
 #ifdef HAVE_MONOTONIC
+#ifndef CONFIG_NEWTOD
 extern unsigned long long monotonic_clock(void);
 #else
+#define monotonic_clock() do_monotonic_clock()
+#endif
+#else
 static inline unsigned long long monotonic_clock(void)
 {
 # ifdef __s390__
drivers/timesource/Makefile (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +1 -0
Index: drivers/timesource/Makefile
===================================================================
@@ -0,0 +1 @@
+obj-y += jiffies.o
drivers/timesource/jiffies.c (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +69 -0

69 lines not on this page · raw message

include/asm-generic/timeofday.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +26 -0
Index: include/asm-generic/timeofday.h
===================================================================
@@ -0,0 +1,26 @@
+/*  linux/include/asm-generic/timeofday.h
+ *
+ *  This file contains the asm-generic interface
+ *  to the arch specific calls used by the time of day subsystem
+ */
+#ifndef _ASM_GENERIC_TIMEOFDAY_H
+#define _ASM_GENERIC_TIMEOFDAY_H
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/timex.h>
+#include <asm/div64.h>
+#ifdef CONFIG_NEWTOD
+
+/* Required externs */
+extern nsec_t read_persistent_clock(void);
+extern void sync_persistent_clock(struct timespec ts);
+
+#ifdef CONFIG_NEWTOD_VSYSCALL
+extern void arch_update_vsyscall_gtod(nsec_t wall_time, cycle_t offset_base,
+				struct timesource_t* timesource, int ntp_adj);
+#else
+#define arch_update_vsyscall_gtod(x,y,z,w) {}
+#endif
+
+#endif /* CONFIG_NEWTOD */
+#endif
include/linux/ntp.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +19 -0
Index: include/linux/ntp.h
===================================================================
@@ -0,0 +1,19 @@
+/*  linux/include/linux/ntp.h
+ *
+ *  This file NTP state machine accessor functions.
+ */
+
+#ifndef _LINUX_NTP_H
+#define _LINUX_NTP_H
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/timex.h>
+
+/* NTP state machine interfaces */
+int ntp_advance(nsec_t value);
+int ntp_adjtimex(struct timex*);
+int ntp_leapsecond(struct timespec now);
+void ntp_clear(void);
+int get_ntp_status(void);
+
+#endif
include/linux/time.h (mode:100644) +4 -0
Index: include/linux/time.h
===================================================================
@@ -27,6 +27,10 @@
 
 #ifdef __KERNEL__
 
+/* timeofday base types */
+typedef u64 nsec_t;
+typedef u64 cycle_t;
+
 /* Parameters used to convert the timespec values */
 #ifndef USEC_PER_SEC
 #define USEC_PER_SEC (1000000L)
include/linux/timeofday.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +59 -0

59 lines not on this page · raw message

include/linux/timesource.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +158 -0

158 lines not on this page · raw message

include/linux/timex.h (mode:100644) +2 -0
Index: include/linux/timex.h
===================================================================
@@ -228,6 +228,7 @@
 extern unsigned long tick_nsec;		/* ACTHZ          period (nsec) */
 extern int tickadj;			/* amount of adjustment per tick */
 
+#ifndef CONFIG_NEWTOD
 /*
  * phase-lock loop variables
  */
@@ -314,6 +315,7 @@
 }
 
 #endif /* !CONFIG_TIME_INTERPOLATION */
+#endif /* !CONFIG_NEWTOD */
 
 #endif /* KERNEL */
 
init/main.c (mode:100644) +2 -0
Index: init/main.c
===================================================================
@@ -47,6 +47,7 @@
 #include <linux/rmap.h>
 #include <linux/mempolicy.h>
 #include <linux/key.h>
+#include <linux/timeofday.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -467,6 +468,7 @@
 	pidhash_init();
 	init_timers();
 	softirq_init();
+	timeofday_init();
 	time_init();
 
 	/*
kernel/Makefile (mode:100644) +1 -0
Index: kernel/Makefile
===================================================================
@@ -9,6 +9,7 @@
 	    rcupdate.o intermodule.o extable.o params.o posix-timers.o \
 	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o
 
+obj-$(CONFIG_NEWTOD) += timeofday.o timesource.o ntp.o
 obj-$(CONFIG_FUTEX) += futex.o
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
 obj-$(CONFIG_SMP) += cpu.o spinlock.o
kernel/ntp.c (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +519 -0

519 lines not on this page · raw message

kernel/time.c (mode:100644) +18 -0
Index: kernel/time.c
===================================================================
@@ -38,6 +38,7 @@
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
+#include <linux/timeofday.h>
 
 /* 
  * The timezone where the local system is located.  Used as a default by some
@@ -128,6 +129,7 @@
  * as real UNIX machines always do it. This avoids all headaches about
  * daylight saving times and warping kernel clocks.
  */
+#ifndef CONFIG_NEWTOD
 inline static void warp_clock(void)
 {
 	write_seqlock_irq(&xtime_lock);
@@ -137,6 +139,18 @@
 	write_sequnlock_irq(&xtime_lock);
 	clock_was_set();
 }
+#else /* !CONFIG_NEWTOD */
+/* XXX - this is somewhat cracked out and should
+         be checked  [email protected]
+*/
+inline static void warp_clock(void)
+{
+	struct timespec ts;
+	getnstimeofday(&ts);
+	ts.tv_sec += sys_tz.tz_minuteswest * 60;
+	do_settimeofday(&ts);
+}
+#endif /* !CONFIG_NEWTOD */
 
 /*
  * In case for some reason the CMOS clock has not already been running
@@ -227,6 +241,7 @@
 /* adjtimex mainly allows reading (and writing, if superuser) of
  * kernel time-keeping variables. used by xntpd.
  */
+#ifndef CONFIG_NEWTOD
 int do_adjtimex(struct timex *txc)
 {
         long ltemp, mtemp, save_adjust;
@@ -410,6 +425,7 @@
 	notify_arch_cmos_timer();
 	return(result);
 }
+#endif /* !CONFIG_NEWTOD */
 
 asmlinkage long sys_adjtimex(struct timex __user *txc_p)
 {
@@ -558,6 +574,7 @@
 
 
 #else
+#ifndef CONFIG_NEWTOD
 /*
  * Simulate gettimeofday using do_gettimeofday which only allows a timeval
  * and therefore only yields usec accuracy
@@ -570,6 +587,7 @@
 	tv->tv_sec = x.tv_sec;
 	tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
 }
+#endif /* !CONFIG_NEWTOD */
 #endif
 
 #if (BITS_PER_LONG < 64)
kernel/timeofday.c (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +607 -0

607 lines not on this page · raw message

kernel/timer.c (mode:100644) +4 -0
Index: kernel/timer.c
===================================================================
@@ -577,6 +577,7 @@
 int tickadj = 500/HZ ? : 1;		/* microsecs */
 
 
+#ifndef CONFIG_NEWTOD
 /*
  * phase-lock loop variables
  */
@@ -807,6 +808,9 @@
 		}
 	} while (ticks);
 }
+#else /* !CONFIG_NEWTOD */
+#define update_wall_time(x)
+#endif /* !CONFIG_NEWTOD */
 
 /*
  * Called from the timer interrupt handler to charge one tick to the current 
kernel/timesource.c (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +237 -0

237 lines not on this page · raw message

#1 lore raw

PATCH 2/4 new timeofday i386 arch specific changes (v. B1)

Andrew, All,
I'm just re-spinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

This patch converts the i386 arch to use the new timeofday infrastructure. It applies on top of my timeofday-core_B1 patch. This is a full conversion, so most of this patch is subtractions removing the existing arch specific time keeping code. This patch does not provide any i386 timesources, so using this patch alone on top of the timeofday- core patch will only give you the jiffies timesource. To get full replacements for the code being removed here, the following timeofday- timesources-i386 patch will need to be applied.

Andrew, please consider for inclusion for testing into your tree (I'd like to target around end of July for possible inclusion into mainline).

thanks
-john

linux-2.6.12-rc5_timeofday-arch-i386_B1.patch
=============================================

arch/i386/Kconfig (mode:100644) +4 -0
Index: arch/i386/Kconfig
===================================================================
@@ -14,6 +14,10 @@
 	  486, 586, Pentiums, and various instruction-set-compatible chips by
 	  AMD, Cyrix, and others.
 
+config NEWTOD
+	bool
+	default y
+
 config MMU
 	bool
 	default y
arch/i386/kernel/Makefile (mode:100644) +1 -2
Index: arch/i386/kernel/Makefile
===================================================================
@@ -7,10 +7,9 @@
 obj-y	:= process.o semaphore.o signal.o entry.o traps.o irq.o vm86.o \
 		ptrace.o time.o ioport.o ldt.o setup.o i8259.o sys_i386.o \
 		pci-dma.o i386_ksyms.o i387.o dmi_scan.o bootflag.o \
-		doublefault.o quirks.o
+		doublefault.o quirks.o tsc.o
 
 obj-y				+= cpu/
-obj-y				+= timers/
 obj-$(CONFIG_ACPI_BOOT)		+= acpi/
 obj-$(CONFIG_X86_BIOS_REBOOT)	+= reboot.o
 obj-$(CONFIG_MCA)		+= mca.o
arch/i386/kernel/i8259.c (mode:100644) +42 -0

48 lines not on this page · raw message

arch/i386/kernel/setup.c (mode:100644) +1 -0
Index: arch/i386/kernel/setup.c
===================================================================
@@ -1525,6 +1525,7 @@
 	conswitchp = &dummy_con;
 #endif
 #endif
+	tsc_init();
 }
 
 #include "setup_arch_post.h"
arch/i386/kernel/time.c (mode:100644) +34 -180

307 lines not on this page · raw message

dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/Makefile (mode:100644) +0 -9
Index: arch/i386/kernel/timers/Makefile
===================================================================
@@ -1,9 +0,0 @@
-#
-# Makefile for x86 timers
-#
-
-obj-y := timer.o timer_none.o timer_tsc.o timer_pit.o common.o
-
-obj-$(CONFIG_X86_CYCLONE_TIMER)	+= timer_cyclone.o
-obj-$(CONFIG_HPET_TIMER)	+= timer_hpet.o
-obj-$(CONFIG_X86_PM_TIMER)	+= timer_pm.o
dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/common.c (mode:100644) +0 -162

162 lines not on this page · raw message

dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/timer.c (mode:100644) +0 -66

66 lines not on this page · raw message

dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/timer_cyclone.c (mode:100644) +0 -259

259 lines not on this page · raw message

dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/timer_hpet.c (mode:100644) +0 -194

194 lines not on this page · raw message

dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/timer_none.c (mode:100644) +0 -39
Index: arch/i386/kernel/timers/timer_none.c
===================================================================
@@ -1,39 +0,0 @@
-#include <linux/init.h>
-#include <asm/timer.h>
-
-static void mark_offset_none(void)
-{
-	/* nothing needed */
-}
-
-static unsigned long get_offset_none(void)
-{
-	return 0;
-}
-
-static unsigned long long monotonic_clock_none(void)
-{
-	return 0;
-}
-
-static void delay_none(unsigned long loops)
-{
-	int d0;
-	__asm__ __volatile__(
-		"\tjmp 1f\n"
-		".align 16\n"
-		"1:\tjmp 2f\n"
-		".align 16\n"
-		"2:\tdecl %0\n\tjns 2b"
-		:"=&a" (d0)
-		:"0" (loops));
-}
-
-/* none timer_opts struct */
-struct timer_opts timer_none = {
-	.name = 	"none",
-	.mark_offset =	mark_offset_none, 
-	.get_offset =	get_offset_none,
-	.monotonic_clock =	monotonic_clock_none,
-	.delay = delay_none,
-};
dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/timer_pit.c (mode:100644) +0 -206

206 lines not on this page · raw message

dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/timer_pm.c (mode:100644) +0 -258

258 lines not on this page · raw message

dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) renamed from arch/i386/kernel/timers/timer_tsc.c (mode:100644) +0 -580

580 lines not on this page · raw message

arch/i386/kernel/tsc.c (mode:100644) renamed from dev/null (tree:15eb8deaa5b22a81f97a9af307d81b0567115674) +190 -0

190 lines not on this page · raw message

arch/i386/lib/delay.c (mode:100644) +13 -3
Index: arch/i386/lib/delay.c
===================================================================
@@ -13,6 +13,7 @@
 #include <linux/config.h>
 #include <linux/sched.h>
 #include <linux/delay.h>
+#include <linux/timeofday.h>
 #include <asm/processor.h>
 #include <asm/delay.h>
 #include <asm/timer.h>
@@ -21,11 +22,20 @@
 #include <asm/smp.h>
 #endif
 
-extern struct timer_opts* timer;
-
+/* XXX - For now just use a simple loop delay
+ *  This has cpufreq issues, but so did the old method.
+ */
 void __delay(unsigned long loops)
 {
-	cur_timer->delay(loops);
+	int d0;
+	__asm__ __volatile__(
+		"\tjmp 1f\n"
+		".align 16\n"
+		"1:\tjmp 2f\n"
+		".align 16\n"
+		"2:\tdecl %0\n\tjns 2b"
+		:"=&a" (d0)
+		:"0" (loops));
 }
 
 inline void __const_udelay(unsigned long xloops)
include/asm-generic/timeofday.h (mode:100644) +1 -1
Index: include/asm-generic/timeofday.h
===================================================================
@@ -20,7 +20,7 @@
 				struct timesource_t* timesource, int ntp_adj);
 #else
 #define arch_update_vsyscall_gtod(x,y,z,w) {}
-#endif
+#endif /* CONFIG_NEWTOD_VSYSCALL */
 
 #endif /* CONFIG_NEWTOD */
 #endif
include/asm-i386/mach-default/mach_timer.h (mode:100644) +5 -1
Index: include/asm-i386/mach-default/mach_timer.h
===================================================================
@@ -14,8 +14,12 @@
  */
 #ifndef _MACH_TIMER_H
 #define _MACH_TIMER_H
+#include <linux/jiffies.h>
+#include <asm/io.h>
 
-#define CALIBRATE_LATCH	(5 * LATCH)
+#define CALIBRATE_ITERATION 50
+#define CALIBRATE_LATCH	(CALIBRATE_ITERATION * LATCH)
+#define CALIBRATE_TIME	(CALIBRATE_ITERATION * 1000020/HZ)
 
 static inline void mach_prepare_counter(void)
 {
include/asm-i386/timeofday.h (mode:100644) renamed from dev/null (tree:15eb8deaa5b22a81f97a9af307d81b0567115674) +4 -0
Index: include/asm-i386/timeofday.h
===================================================================
@@ -0,0 +1,4 @@
+#ifndef _ASM_I386_TIMEOFDAY_H
+#define _ASM_I386_TIMEOFDAY_H
+#include <asm-generic/timeofday.h>
+#endif
include/asm-i386/timer.h (mode:100644) +0 -53

64 lines not on this page · raw message

include/asm-i386/timex.h (mode:100644) +3 -0
Index: include/asm-i386/timex.h
===================================================================
@@ -16,6 +16,8 @@
 #endif
 
 
+/* XXX - All of this should likely move elsewhere [email protected]*/
+
 /*
  * Standard way to access the cycle counter on i586+ CPUs.
  * Currently only used on SMP.
@@ -48,5 +50,6 @@
 }
 
 extern unsigned long cpu_khz;
+extern void tsc_init(void);
 
 #endif
#2 lore raw

PATCH 3/4 new timeofday x86-64 arch specific changes (v. B1)

Andi, All,
I'm just re-spinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

This patch converts the x86-64 arch to use the new timeofday infrastructure. It applies on top of my timeofday-core_B1 patch. This is a full conversion, so most of this patch is subtractions removing the existing arch specific time keeping code. This patch does not provide any x86-64 timesources, so using this patch alone on top of the timeofday-core patch will only give you the jiffies timesource. To get full replacements for the code being removed here, the following timeofday-timesources-i386 patch (x86-64 shares the same timesources as i386) will need to be applied.

Andi: I'd like to submit this to Andrew for inclusion into his tree for testing, however I'd like to get an ACK from you first. Please let me know if you have any feedback or suggestions.

thanks
-john

linux-2.6.12-rc5_timeofday-arch-x86-64_B1.patch
===============================================

arch/i386/kernel/acpi/boot.c (mode:100644) +3 -9
Index: arch/i386/kernel/acpi/boot.c
===================================================================
@@ -547,7 +547,7 @@
 
 
 #ifdef CONFIG_HPET_TIMER
-
+#include <asm/hpet.h>
 static int __init acpi_parse_hpet(unsigned long phys, unsigned long size)
 {
 	struct acpi_table_hpet *hpet_tbl;
@@ -570,18 +570,12 @@
 #ifdef	CONFIG_X86_64
         vxtime.hpet_address = hpet_tbl->addr.addrl |
                 ((long) hpet_tbl->addr.addrh << 32);
-
-        printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
-               hpet_tbl->id, vxtime.hpet_address);
+	hpet_address = vxtime.hpet_address;
 #else	/* X86 */
-	{
-		extern unsigned long hpet_address;
-
 		hpet_address = hpet_tbl->addr.addrl;
+#endif	/* X86 */
 		printk(KERN_INFO PREFIX "HPET id: %#x base: %#lx\n",
 			hpet_tbl->id, hpet_address);
-	}
-#endif	/* X86 */
 
 	return 0;
 }
arch/x86_64/Kconfig (mode:100644) +8 -0
Index: arch/x86_64/Kconfig
===================================================================
@@ -24,6 +24,14 @@
 	bool
 	default y
 
+config NEWTOD
+       bool
+       default y
+
+config NEWTOD_VSYSCALL
+       bool
+       default y
+
 config MMU
 	bool
 	default y
arch/x86_64/kernel/Makefile (mode:100644) +0 -1
Index: arch/x86_64/kernel/Makefile
===================================================================
@@ -28,7 +28,6 @@
 obj-$(CONFIG_DUMMY_IOMMU)	+= pci-nommu.o pci-dma.o
 obj-$(CONFIG_SWIOTLB)		+= swiotlb.o
 obj-$(CONFIG_KPROBES)		+= kprobes.o
-obj-$(CONFIG_X86_PM_TIMER)	+= pmtimer.o
 
 obj-$(CONFIG_MODULES)		+= module.o
 
dev/null (tree:85c83ea7c8c2d1f7e94ba65fa8d2a77d1022c973) renamed from arch/x86_64/kernel/pmtimer.c (mode:100644) +0 -101

101 lines not on this page · raw message

arch/x86_64/kernel/time.c (mode:100644) +26 -311

425 lines not on this page · raw message

arch/x86_64/kernel/vmlinux.lds.S (mode:100644) +7 -0
Index: arch/x86_64/kernel/vmlinux.lds.S
===================================================================
@@ -71,6 +71,13 @@
   . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
   .jiffies : AT CACHE_ALIGN(AFTER(.xtime)) { *(.jiffies) }
   jiffies = LOADADDR(.jiffies);
+
+  .vsyscall_gtod_data : AT AFTER(.jiffies) { *(.vsyscall_gtod_data) }
+  vsyscall_gtod_data = LOADADDR(.vsyscall_gtod_data);
+  .vsyscall_gtod_lock : AT AFTER(.vsyscall_gtod_data) { *(.vsyscall_gtod_lock) }
+  vsyscall_gtod_lock = LOADADDR(.vsyscall_gtod_lock);
+
+
   .vsyscall_1 ADDR(.vsyscall_0) + 1024: AT (LOADADDR(.vsyscall_0) + 1024) { *(.vsyscall_1) }
   . = LOADADDR(.vsyscall_0) + 4096;
 
arch/x86_64/kernel/vsyscall.c (mode:100644) +104 -30

183 lines not on this page · raw message

include/asm-generic/div64.h (mode:100644) +9 -0
Index: include/asm-generic/div64.h
===================================================================
@@ -55,4 +55,13 @@
 
 #endif /* BITS_PER_LONG */
 
+#ifndef div_long_long_rem
+#define div_long_long_rem(dividend,divisor,remainder) \
+({							\
+	u64 result = dividend;				\
+	*remainder = do_div(result,divisor);		\
+	result;						\
+})
+#endif
+
 #endif /* _ASM_GENERIC_DIV64_H */
include/asm-x86_64/hpet.h (mode:100644) +2 -1
Index: include/asm-x86_64/hpet.h
===================================================================
@@ -1,6 +1,6 @@
 #ifndef _ASM_X8664_HPET_H
 #define _ASM_X8664_HPET_H 1
-
+#include <asm/fixmap.h>
 /*
  * Documentation on HPET can be found at:
  *      http://www.intel.com/ial/home/sp/pcmmspec.htm
@@ -44,6 +44,7 @@
 #define HPET_TN_SETVAL		0x040
 #define HPET_TN_32BIT		0x100
 
+extern unsigned long hpet_address;	/* hpet memory map physical address */
 extern int is_hpet_enabled(void);
 extern int hpet_rtc_timer_init(void);
 extern int oem_force_hpet_timer(void);
include/asm-x86_64/timeofday.h (mode:100644) renamed from dev/null (tree:15eb8deaa5b22a81f97a9af307d81b0567115674) +4 -0
Index: include/asm-x86_64/timeofday.h
===================================================================
@@ -0,0 +1,4 @@
+#ifndef _ASM_X86_64_TIMEOFDAY_H
+#define _ASM_X86_64_TIMEOFDAY_H
+#include <asm-generic/timeofday.h>
+#endif
include/asm-x86_64/vsyscall.h (mode:100644) +2 -0
Index: include/asm-x86_64/vsyscall.h
===================================================================
@@ -22,6 +22,8 @@
 #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 __section_vsyscall_gtod_data __attribute__ ((unused, __section__ (".vsyscall_gtod_data"),aligned(16)))
+#define __section_vsyscall_gtod_lock __attribute__ ((unused, __section__ (".vsyscall_gtod_lock"),aligned(16)))
 
 #define VXTIME_TSC	1
 #define VXTIME_HPET	2
#3 lore raw

PATCH 4/4 new timeofday i386 and x86-64 timesources (v. B1)

Andrew, All,
I'm just respinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

This patch implements the time sources shared between i386 and x86-64 (acpi_pm, cyclone, hpet, pit, tsc and tsc-interp). The patch should apply on top of the timeofday-arch-i386_B1.patch as well as the arch- x86-64_B1.patch.

The patch should be fairly straight forward, only adding the new timesources.

Andrew, please consider for inclusion for testing into your tree (I'd like to target around end of July for possible inclusion into mainline).

thanks
-john

linux-2.6.12-rc5_timeofday-timesources-i386_B1.patch
====================================================

drivers/acpi/processor_idle.c (mode:100644) +5 -0
Index: drivers/acpi/processor_idle.c
===================================================================
@@ -162,6 +162,7 @@
 	return;
 }
 
+extern void tsc_c3_compensate(unsigned long usecs);
 
 static void acpi_processor_idle (void)
 {
@@ -309,6 +310,10 @@
 		t2 = inl(acpi_fadt.xpm_tmr_blk.address);
 		/* Enable bus master arbitration */
 		acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, ACPI_MTX_DO_NOT_LOCK);
+
+		/* compensate for TSC pause */
+		tsc_c3_compensate((((t2-t1)&0xFFFFFF)*286)>>10);
+
 		/* Re-enable interrupts */
 		local_irq_enable();
 		/* Compute time (ticks) that we were actually asleep */
drivers/timesource/Makefile (mode:100644) +7 -0
Index: drivers/timesource/Makefile
===================================================================
@@ -1 +1,8 @@
 obj-y += jiffies.o
+
+obj-$(CONFIG_X86) += tsc.o
+obj-$(CONFIG_X86) += i386_pit.o
+obj-$(CONFIG_X86) += tsc-interp.o
+obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o
+obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o
+obj-$(CONFIG_HPET_TIMER) += hpet.o
drivers/timesource/acpi_pm.c (mode:100644) renamed from dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) +140 -0

140 lines not on this page · raw message

drivers/timesource/cyclone.c (mode:100644) renamed from dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) +135 -0

135 lines not on this page · raw message

drivers/timesource/hpet.c (mode:100644) renamed from dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) +59 -0

59 lines not on this page · raw message

drivers/timesource/i386_pit.c (mode:100644) renamed from dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) +64 -0

64 lines not on this page · raw message

drivers/timesource/tsc-interp.c (mode:100644) renamed from dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) +112 -0

112 lines not on this page · raw message

drivers/timesource/tsc.c (mode:100644) renamed from dev/null (tree:6f1948595e5fa374fc552a4a01fe5524530ea1dd) +95 -0

95 lines not on this page · raw message

#4 lore raw

Re: [PATCH 3/4] new timeofday x86-64 arch specific changes (v. B1)

In reply to john stultz
Quoted 2 lines · john stultz

This patch converts the x86-64 arch to use the new timeofday infrastructure. It applies on top of my timeofday-core_B1 patch.

This one fails to apply - time.c HUNK #1 gets rejected. (Attached)

Parag

***************
*** 26,35 ****
#include <linux/sysdev.h>
#include <linux/bcd.h>
#include <linux/kallsyms.h>
- #include <linux/acpi.h>
- #ifdef CONFIG_ACPI
- #include <acpi/achware.h> /* for PM timer frequency */
- #endif
#include <asm/8253pit.h>
#include <asm/pgtable.h>
#include <asm/vsyscall.h>
--- 26,31 ----
#include <linux/sysdev.h>
#include <linux/bcd.h>
#include <linux/kallsyms.h>
#include <asm/8253pit.h>
#include <asm/pgtable.h>
#include <asm/vsyscall.h>

#5 lore raw

Re: [PATCH 3/4] new timeofday x86-64 arch specific changes (v. B1)

Quoted 5 lines · Parag Warudkar
Quoted 2 lines · john stultz

This patch converts the x86-64 arch to use the new timeofday infrastructure. It applies on top of my timeofday-core_B1 patch.

This one fails to apply - time.c HUNK #1 gets rejected. (Attached)

Yea, sorry. My naming scheme isn't quite granular enough. The patch is against Linus' git tree as of yesterday, not -rc5 vanilla.

If you grab Linus' current tree it should apply.

Sorry about the confusion.
-john

#6 lore raw
In reply to john stultz

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Patch 1 appears to be truncated, so here's an updated patch, completed from version B0.

Frank
- --
Frank Sorenson - KD7TZK
Systems Manager, Computer Science Department
Brigham Young University
[email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCnlvzaI0dwg4A47wRArIVAJ9EI73wnQ7JZlseD8vXKow+SBw5SgCg1V/F qJ8bvFbBtugiq3MnXMdAIpA=
=50Os
-----END PGP SIGNATURE-----

Andrew, All,
I'm just re-spinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

With the goal to simplify, streamline and consolidate the time-of-day
infrastructure, I propose the following common implementation across all arches. This will allow generic bugs to be fixed once, reduce code duplication, and with many architectures sharing the same time source, this allows drivers to be written once for multiple architectures. Additionally it will better delineate the lines between the soft-timer subsystem and the time-of-day subsystem, opening the door for more flexible and better soft-timer management.

Features of this design:
========================

o Splits time of day management from timer interrupts
o Consolidates a large amount of code
o Generic algorithms which use time-source drivers chosen at runtime
o More consistent and readable code
o Uses nanoseconds as the kernel's base time unit
o Clearly separates the NTP code from the time code

For another description on the rework, see here:
http://lwn.net/Articles/120850/ (Many thanks to the LWN team for that easy to understand writeup!)

This patch implements the architecture independent portion of the new time of day subsystem. Included below is timeofday.c (which includes all the time of day management and accessor functions), ntp.c (which includes the ntp adjustment code, leapsecond processing, and ntp kernel state machine code), timesource.c (for timesource specific management functions), interface definition .h files, the example jiffies timesource (lowest common denominator time source, mainly for use as example code) and minimal hooks into arch independent code.

The patch does nothing without at least minimal architecture specific hooks (i386, x86-64 to follow), and it should be able to be applied to a tree without affecting the existing code.

Finally I'd like to thank the following people who have contributed ideas, criticism, testing and code that has helped shape this work:
George Anzinger, Nish Aravamudan, Max Asbock, Dominik Brodowski, Darren Hart, Christoph Lameter, Matt Mackal, Keith Mannthey, Martin Schwidefsky, Frank Sorenson, Ulrich Windl, Darrick Wong, and any others whom I've accidentally forgotten.

Andrew, please consider for inclusion for testing into your tree (I'd like to target around end of July for possible inclusion into mainline).

thanks
-john

linux-2.6.12-rc5_timeofday-core_B1.patch
========================================

drivers/Makefile (mode:100644) +1 -0
Index: drivers/Makefile
===================================================================
@@ -64,3 +64,4 @@
 obj-$(CONFIG_BLK_DEV_SGIIOC4)	+= sn/
 obj-y				+= firmware/
 obj-$(CONFIG_CRYPTO)		+= crypto/
+obj-$(CONFIG_NEWTOD)		+= timesource/
drivers/char/hangcheck-timer.c (mode:100644) +5 -0
Index: drivers/char/hangcheck-timer.c
===================================================================
@@ -49,6 +49,7 @@
 #include <linux/delay.h>
 #include <asm/uaccess.h>
 #include <linux/sysrq.h>
+#include <linux/timeofday.h>
 
 
 #define VERSION_STR "0.9.0"
@@ -130,8 +131,12 @@
 #endif
 
 #ifdef HAVE_MONOTONIC
+#ifndef CONFIG_NEWTOD
 extern unsigned long long monotonic_clock(void);
 #else
+#define monotonic_clock() do_monotonic_clock()
+#endif
+#else
 static inline unsigned long long monotonic_clock(void)
 {
 # ifdef __s390__
drivers/timesource/Makefile (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +1 -0
Index: drivers/timesource/Makefile
===================================================================
@@ -0,0 +1 @@
+obj-y += jiffies.o
drivers/timesource/jiffies.c (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +69 -0

69 lines not on this page · raw message

include/asm-generic/timeofday.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +26 -0
Index: include/asm-generic/timeofday.h
===================================================================
@@ -0,0 +1,26 @@
+/*  linux/include/asm-generic/timeofday.h
+ *
+ *  This file contains the asm-generic interface
+ *  to the arch specific calls used by the time of day subsystem
+ */
+#ifndef _ASM_GENERIC_TIMEOFDAY_H
+#define _ASM_GENERIC_TIMEOFDAY_H
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/timex.h>
+#include <asm/div64.h>
+#ifdef CONFIG_NEWTOD
+
+/* Required externs */
+extern nsec_t read_persistent_clock(void);
+extern void sync_persistent_clock(struct timespec ts);
+
+#ifdef CONFIG_NEWTOD_VSYSCALL
+extern void arch_update_vsyscall_gtod(nsec_t wall_time, cycle_t offset_base,
+				struct timesource_t* timesource, int ntp_adj);
+#else
+#define arch_update_vsyscall_gtod(x,y,z,w) {}
+#endif
+
+#endif /* CONFIG_NEWTOD */
+#endif
include/linux/ntp.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +19 -0
Index: include/linux/ntp.h
===================================================================
@@ -0,0 +1,19 @@
+/*  linux/include/linux/ntp.h
+ *
+ *  This file NTP state machine accessor functions.
+ */
+
+#ifndef _LINUX_NTP_H
+#define _LINUX_NTP_H
+#include <linux/types.h>
+#include <linux/time.h>
+#include <linux/timex.h>
+
+/* NTP state machine interfaces */
+int ntp_advance(nsec_t value);
+int ntp_adjtimex(struct timex*);
+int ntp_leapsecond(struct timespec now);
+void ntp_clear(void);
+int get_ntp_status(void);
+
+#endif
include/linux/time.h (mode:100644) +4 -0
Index: include/linux/time.h
===================================================================
@@ -27,6 +27,10 @@
 
 #ifdef __KERNEL__
 
+/* timeofday base types */
+typedef u64 nsec_t;
+typedef u64 cycle_t;
+
 /* Parameters used to convert the timespec values */
 #ifndef USEC_PER_SEC
 #define USEC_PER_SEC (1000000L)
include/linux/timeofday.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +59 -0

59 lines not on this page · raw message

include/linux/timesource.h (mode:100644) renamed from dev/null (tree:d414ab9a0f0995899c2e76c232714410f787b209) +158 -0

158 lines not on this page · raw message

include/linux/timex.h (mode:100644) +2 -0
Index: include/linux/timex.h
===================================================================
@@ -228,6 +228,7 @@
 extern unsigned long tick_nsec;		/* ACTHZ          period (nsec) */
 extern int tickadj;			/* amount of adjustment per tick */
 
+#ifndef CONFIG_NEWTOD
 /*
  * phase-lock loop variables
  */
@@ -314,6 +315,7 @@
 }
 
 #endif /* !CONFIG_TIME_INTERPOLATION */
+#endif /* !CONFIG_NEWTOD */
 
 #endif /* KERNEL */
 
init/main.c (mode:100644) +2 -0
Index: init/main.c
===================================================================
@@ -47,6 +47,7 @@
 #include <linux/rmap.h>
 #include <linux/mempolicy.h>
 #include <linux/key.h>
+#include <linux/timeofday.h>
 
 #include <asm/io.h>
 #include <asm/bugs.h>
@@ -467,6 +468,7 @@
 	pidhash_init();
 	init_timers();
 	softirq_init();
+	timeofday_init();
 	time_init();
 
 	/*
kernel/Makefile (mode:100644) +1 -0
Index: kernel/Makefile
===================================================================
@@ -9,6 +9,7 @@
 	    rcupdate.o intermodule.o extable.o params.o posix-timers.o \
 	    kthread.o wait.o kfifo.o sys_ni.o posix-cpu-timers.o
 
+obj-$(CONFIG_NEWTOD) += timeofday.o timesource.o ntp.o
 obj-$(CONFIG_FUTEX) += futex.o
 obj-$(CONFIG_GENERIC_ISA_DMA) += dma.o
 obj-$(CONFIG_SMP) += cpu.o spinlock.o
kernel/ntp.c (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +519 -0

519 lines not on this page · raw message

kernel/time.c (mode:100644) +18 -0
Index: kernel/time.c
===================================================================
@@ -38,6 +38,7 @@
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
+#include <linux/timeofday.h>
 
 /* 
  * The timezone where the local system is located.  Used as a default by some
@@ -128,6 +129,7 @@
  * as real UNIX machines always do it. This avoids all headaches about
  * daylight saving times and warping kernel clocks.
  */
+#ifndef CONFIG_NEWTOD
 inline static void warp_clock(void)
 {
 	write_seqlock_irq(&xtime_lock);
@@ -137,6 +139,18 @@
 	write_sequnlock_irq(&xtime_lock);
 	clock_was_set();
 }
+#else /* !CONFIG_NEWTOD */
+/* XXX - this is somewhat cracked out and should
+         be checked  [email protected]
+*/
+inline static void warp_clock(void)
+{
+	struct timespec ts;
+	getnstimeofday(&ts);
+	ts.tv_sec += sys_tz.tz_minuteswest * 60;
+	do_settimeofday(&ts);
+}
+#endif /* !CONFIG_NEWTOD */
 
 /*
  * In case for some reason the CMOS clock has not already been running
@@ -227,6 +241,7 @@
 /* adjtimex mainly allows reading (and writing, if superuser) of
  * kernel time-keeping variables. used by xntpd.
  */
+#ifndef CONFIG_NEWTOD
 int do_adjtimex(struct timex *txc)
 {
         long ltemp, mtemp, save_adjust;
@@ -410,6 +425,7 @@
 	notify_arch_cmos_timer();
 	return(result);
 }
+#endif /* !CONFIG_NEWTOD */
 
 asmlinkage long sys_adjtimex(struct timex __user *txc_p)
 {
@@ -558,6 +574,7 @@
 
 
 #else
+#ifndef CONFIG_NEWTOD
 /*
  * Simulate gettimeofday using do_gettimeofday which only allows a timeval
  * and therefore only yields usec accuracy
@@ -570,6 +587,7 @@
 	tv->tv_sec = x.tv_sec;
 	tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
 }
+#endif /* !CONFIG_NEWTOD */
 #endif
 
 #if (BITS_PER_LONG < 64)
kernel/timeofday.c (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +607 -0

607 lines not on this page · raw message

kernel/timer.c (mode:100644) +4 -0
Index: kernel/timer.c
===================================================================
@@ -577,6 +577,7 @@
 int tickadj = 500/HZ ? : 1;		/* microsecs */
 
 
+#ifndef CONFIG_NEWTOD
 /*
  * phase-lock loop variables
  */
@@ -807,6 +808,9 @@
 		}
 	} while (ticks);
 }
+#else /* !CONFIG_NEWTOD */
+#define update_wall_time(x)
+#endif /* !CONFIG_NEWTOD */
 
 /*
  * Called from the timer interrupt handler to charge one tick to the current 
kernel/timesource.c (mode:100644) renamed from dev/null (tree:9b7fa103dfb222f809bf277668d9ac0636c060ee) +237 -0

237 lines not on this page · raw message

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#7 lore raw
Quoted 2 lines · Frank Sorenson

Patch 1 appears to be truncated, so here's an updated patch, completed from version B0.

Hmm. The archives seem to have the full B1 patch. Are you sure it didn't just get lost on your end?

thanks
-john

#8 lore raw
In reply to john stultz

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 3 lines · john stultz

Andrew, All,
I'm just re-spinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

<snip>

John,

I have found an issue with these TOD subsystem patches, and I think it's only an issue on systems that use CPUFREQ. Whenever the frequency changes, at least some portions of the kernel get confused about their notion of time. Here are some example entries from my syslog:

Jun  3 00:33:40 moebius kernel: [  145.023201] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:33:47 moebius kernel: [  114.838909] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:33:47 moebius kernel: [  114.838977] freq-table: request for target 1000000 kHz (relation: 0) for cpu 0
Jun  3 00:33:47 moebius kernel: [   92.161872] codec_semaphore: semaphore is not ready [0x1][0x700300]
Jun  3 00:33:52 moebius kernel: [   97.433279] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:33:58 moebius kernel: [   66.352233] cpufreq-core: target for CPU 0: 1400000 kHz, relation 0
Jun  3 00:34:08 moebius kernel: [   85.547260] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:34:16 moebius kernel: [  211.791738] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:27 moebius kernel: [  112.941898] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:34:31 moebius kernel: [  231.793121] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:41 moebius kernel: [  147.122593] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:34:42 moebius kernel: [  123.906802] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:34:46 moebius kernel: [  251.342116] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:51 moebius kernel: [  192.985214] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0

The printk times are taken from sched_clock(), which now varies depending on the cpu frequency. Without these patches, the printk times appear to consistently increase at the right rate. I'm not sure what other portions of the kernel are affected by this (watchdogs firing, or other issues?).

Thanks,

Frank
- --
Frank Sorenson - KD7TZK
Systems Manager, Computer Science Department
Brigham Young University
[email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCoAboaI0dwg4A47wRAmWsAJsHJ3sYtUqXKqjnualA3JTOih9RwACeIulR CCKYtqdZ/096knyiwZf6X44=
=SjAZ
-----END PGP SIGNATURE-----

#9 lore raw
Quoted 32 lines · Frank Sorenson

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 3 lines · john stultz

Andrew, All,
I'm just re-spinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

<snip>

John,

I have found an issue with these TOD subsystem patches, and I think it's only an issue on systems that use CPUFREQ. Whenever the frequency changes, at least some portions of the kernel get confused about their notion of time. Here are some example entries from my syslog:

Jun  3 00:33:40 moebius kernel: [  145.023201] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:33:47 moebius kernel: [  114.838909] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:33:47 moebius kernel: [  114.838977] freq-table: request for target 1000000 kHz (relation: 0) for cpu 0
Jun  3 00:33:47 moebius kernel: [   92.161872] codec_semaphore: semaphore is not ready [0x1][0x700300]
Jun  3 00:33:52 moebius kernel: [   97.433279] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:33:58 moebius kernel: [   66.352233] cpufreq-core: target for CPU 0: 1400000 kHz, relation 0
Jun  3 00:34:08 moebius kernel: [   85.547260] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:34:16 moebius kernel: [  211.791738] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:27 moebius kernel: [  112.941898] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:34:31 moebius kernel: [  231.793121] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:41 moebius kernel: [  147.122593] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:34:42 moebius kernel: [  123.906802] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:34:46 moebius kernel: [  251.342116] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:51 moebius kernel: [  192.985214] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Quoted 5 lines

The printk times are taken from sched_clock(), which now varies depending on the cpu frequency. Without these patches, the printk times appear to consistently increase at the right rate. I'm not sure what other portions of the kernel are affected by this (watchdogs firing, or other issues?).

Yep, looks like something isn't right between sched_clock and the cpufreq changes. I'll let you know when I've sorted it out.

Thanks for the great testing!
-john

#10 lore raw
In reply to Frank Sorenson
Quoted 30 lines · Frank Sorenson

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 3 lines · john stultz

Andrew, All,
I'm just re-spinning this to resolve a conflict w/ the CPUFREQ changes
Linus accepted last night.

<snip>

I have found an issue with these TOD subsystem patches, and I think it's only an issue on systems that use CPUFREQ. Whenever the frequency changes, at least some portions of the kernel get confused about their notion of time. Here are some example entries from my syslog:

Jun  3 00:33:40 moebius kernel: [  145.023201] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:33:47 moebius kernel: [  114.838909] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:33:47 moebius kernel: [  114.838977] freq-table: request for target 1000000 kHz (relation: 0) for cpu 0
Jun  3 00:33:47 moebius kernel: [   92.161872] codec_semaphore: semaphore is not ready [0x1][0x700300]
Jun  3 00:33:52 moebius kernel: [   97.433279] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:33:58 moebius kernel: [   66.352233] cpufreq-core: target for CPU 0: 1400000 kHz, relation 0
Jun  3 00:34:08 moebius kernel: [   85.547260] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:34:16 moebius kernel: [  211.791738] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:27 moebius kernel: [  112.941898] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:34:31 moebius kernel: [  231.793121] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:41 moebius kernel: [  147.122593] cpufreq-core: target for CPU 0: 1200000 kHz, relation 0
Jun  3 00:34:42 moebius kernel: [  123.906802] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Jun  3 00:34:46 moebius kernel: [  251.342116] cpufreq-core: target for CPU 0: 800000 kHz, relation 0
Jun  3 00:34:51 moebius kernel: [  192.985214] cpufreq-core: target for CPU 0: 1000000 kHz, relation 0
Quoted 5 lines

The printk times are taken from sched_clock(), which now varies depending on the cpu frequency. Without these patches, the printk times appear to consistently increase at the right rate. I'm not sure what other portions of the kernel are affected by this (watchdogs firing, or other issues?).

Hrm. So, I've been looking into this and I'm a bit stumped, as I'm not really changing the behavior of sched_clock().

sched_clock() is a pretty bad interface as it just takes the current TSC value (relative to zero) and scales it using the current cpukhz value (well, indirectly using cycles_2_ns). Since it doesn't ever accumulate the past time, frequency changes affect the full interval (since the TSC was reset) which can cause large errors. The rational for this was that sched_clock() was supposed to be as fast as possible just to give a quick guide to the scheduler and occasional incorrect values are acceptable.

I'm looking further into it, but could you send me privately the dmesg output for both with and without the TOD patch?

thanks
-john