Skip to contentSkip to conversation

Convert acked !GENERIC_TIME architectures to use the generic timekeeping core.

PATCH RESEND In review john stultz 6 participants 18 messages Apr 15, 2009 – May 7, 2009

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

cover Convert acked !GENERIC_TIME architectures to use the generic timekeeping core.

Andrew, All,

Its been two and a half years since the GENERIC_TIME infrastructure
landed. It allowed architectures that have free running counters to only have to provide a clocksource driver and leave the rest of the timekeeping management to generic code.

So far out of the 23 architectures we've fully converted 15 of them over to GENERIC_TIME. The remaining 8 (alpha, arm, blackfin, cris, m32r, m68k, sh, sparc) have in some cases been able to convert, but not fully. The issue that keeps most architectures from converting is that they do not have free running counters. They instead use the counter on their tick timer to determine their inter-tick time. This counter usually wraps every interrupt, so its not really efficient to use as a clocksource.

This has created some difficulty as the generic timekeeping core has had to deal with both GENERIC_TIME arches as well as !GENERIC_TIME arches, and since it didn't manage 100% of the calculation in the !GENERIC_TIME case, we've been limited in some of the changes we could make.

So since these last remaining architectures are unlikely to be able to fully convert to GENERIC_TIME as it stands, the generic core should try to adopt to their needs so we can bring them into the fold and reduce code duplication.

The solution is to provide a arch callout from the generic timekeeping
core: arch_gettimeoffset(). On architectures that do not provide a clocksource, the jiffies clocksource is used, and arch_gettimeoffset is added in to create finer grained inter-tick time.

The patchset I'm submitting for -mm does the following:
1) Introduces the arch_gettimeoffset infrastructure to the timekeeping core.
2) Converts Acked arch (sh) to use the arch_gettimeoffset()hook.

The sparc arch was earlier acked, but I found some complications when cross-compile testing it, so I'll be reworking it and requesting a new ack later.

I still have patches for the 6 other arches that need to be converted, but have not received acks for them yet. Instead of stalling the patchset for all of those arches, I'm submitting these, so overloaded arch maintainers can convert their arches or take my patches on their schedule without blocking arches that are ready to go.

Once all 8 arches are converted, I'll send a final cleanup patch that removes all conditionals and references to GENERIC_TIME.

I'll be sending the unacked patches I'm not submitting to -mm shortly.

Credits to Roman for initially suggesting the idea quite awhile back.

thanks
-john

#1 lore raw

PATCH RESEND 1/2 Create arch_gettimeoffset infrastructure for use in the generic timekeeping core.

Andrew, all,

Some arches don't supply their own clocksource. This is mainly the case in architectures that get their inter-tick times by reading the counter on their interval timer. Since these timers wrap every tick, they're not really useful as clocksources. Wrapping them to act like one is possible but not very efficient. So we provide a callout these arches can implement for use with the jiffies clocksource to provide finer then tick granular time.

Please consider for inclusion into -mm in preparation for 2.6.31.

include/linux/time.h +15 -0
index 242f624..01145d5 100644
@@ -113,6 +113,21 @@ struct timespec current_kernel_time(void);
 #define CURRENT_TIME		(current_kernel_time())
 #define CURRENT_TIME_SEC	((struct timespec) { get_seconds(), 0 })
 
+/* Some architectures do not supply their own clocksource.
+ * This is mainly the case in architectures that get their
+ * inter-tick times by reading the counter on their interval
+ * timer. Since these timers wrap every tick, they're not really
+ * useful as clocksources. Wrapping them to act like one is possible
+ * but not very efficient. So we provide a callout these arches
+ * can implement for use with the jiffies clocksource to provide
+ * finer then tick granular time.
+ */
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
+extern u32 arch_gettimeoffset(void);
+#else
+#define arch_gettimeoffset() (0)
+#endif
+
 extern void do_gettimeofday(struct timeval *tv);
 extern int do_settimeofday(struct timespec *tv);
 extern int do_sys_settimeofday(struct timespec *tv, struct timezone *tz);
kernel/time/timekeeping.c +7 -0
index 900f1b6..45d777f 100644
@@ -77,6 +77,10 @@ static void clocksource_forward_now(void)
 	clock->cycle_last = cycle_now;
 
 	nsec = cyc2ns(clock, cycle_delta);
+
+	/* If arch requires, add in gettimeoffset() */
+	nsec += arch_gettimeoffset();
+
 	timespec_add_ns(&xtime, nsec);
 
 	nsec = ((s64)cycle_delta * clock->mult_orig) >> clock->shift;
@@ -111,6 +115,9 @@ void getnstimeofday(struct timespec *ts)
 		/* convert to nanoseconds: */
 		nsecs = cyc2ns(clock, cycle_delta);
 
+		/* If arch requires, add in gettimeoffset() */
+		nsecs += arch_gettimeoffset();
+
 	} while (read_seqretry(&xtime_lock, seq));
 
 	timespec_add_ns(ts, nsecs);
#2 lore raw

PATCH RESEND 2/2 Convert sh to use arch_getoffset() infrastructure.

This patch converts sh to use GENERIC_TIME via the arch_getoffset() infrastructure

I have tried cross-compiling this for sh3 and sh4. Also little has changed since my last submission where it was acked. So I've taken my best swing at converting this, but I'm not 100% confident I got it right. Any assistance from arch maintainers or testers would be great.

arch/sh/Kconfig +5 -1
index e7390dd..6ee1240 100644
@@ -74,7 +74,7 @@ config GENERIC_IOMAP
 	bool
 
 config GENERIC_TIME
-	def_bool n
+	def_bool y
 
 config GENERIC_CLOCKEVENTS
 	def_bool n
@@ -451,6 +451,10 @@ config SH_TMU
 	help
 	  This enables the use of the TMU as the system timer.
 
+config ARCH_USES_GETTIMEOFFSET
+	def_bool y
+	depends on !SH_TMU
+
 config SH_CMT
 	bool "CMT timer support"
 	depends on SYS_SUPPORTS_CMT && CPU_SH2
arch/sh/include/asm/timer.h +2 -2
index 4c3b66e..f688df2 100644
@@ -9,7 +9,7 @@ struct sys_timer_ops {
 	int (*init)(void);
 	int (*start)(void);
 	int (*stop)(void);
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	unsigned long (*get_offset)(void);
 #endif
 };
@@ -26,7 +26,7 @@ struct sys_timer {
 extern struct sys_timer tmu_timer, cmt_timer, mtu2_timer;
 extern struct sys_timer *sys_timer;
 
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 static inline unsigned long get_timer_offset(void)
 {
 	return sys_timer->ops->get_offset();
arch/sh/kernel/time_32.c +5 -58

77 lines not on this page · raw message

arch/sh/kernel/time_64.c +2 -51

61 lines not on this page · raw message

arch/sh/kernel/timers/timer-cmt.c +1 -1
index 9aa3486..c5e5ad7 100644
@@ -177,7 +177,7 @@ static struct sys_timer_ops cmt_timer_ops = {
 	.init		= cmt_timer_init,
 	.start		= cmt_timer_start,
 	.stop		= cmt_timer_stop,
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	.get_offset	= cmt_timer_get_offset,
 #endif
 };
arch/sh/kernel/timers/timer-mtu2.c +1 -1
index 9b0ef01..8a1dcc2 100644
@@ -191,7 +191,7 @@ struct sys_timer_ops mtu2_timer_ops = {
 	.init		= mtu2_timer_init,
 	.start		= mtu2_timer_start,
 	.stop		= mtu2_timer_stop,
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	.get_offset	= mtu2_timer_get_offset,
 #endif
 };
#3 lore raw

RFC PATCH 1/8 Convert alpha to use arch_getoffset() infrastructure.

This patch converts alpha to use GENERIC_TIME via the arch_getoffset() infrastructure

I do not have cross compilers for these architectures, and in some cases the architectures can be compiles both with and without clocksources. So I've taken my best swing at converting this, but I'm not confident I got it right. Any assistance from arch maintainers or testers would be great.

NOT FOR INCLUSION

arch/alpha/Kconfig +8 -0
index 9fb8aae..4434481 100644
@@ -45,6 +45,14 @@ config GENERIC_CALIBRATE_DELAY
 	bool
 	default y
 
+config GENERIC_TIME
+	bool
+	default y
+
+config ARCH_USES_GETTIMEOFFSET
+	bool
+	default y
+
 config ZONE_DMA
 	bool
 	default y
arch/alpha/kernel/time.c +4 -68

94 lines not on this page · raw message

#4 lore raw

RFC PATCH 2/8 Convert arm to use arch_getoffset() infrastructure.

This patch converts arm to use GENERIC_TIME via the arch_getoffset() infrastructure

I do not have cross compilers for these architectures, and in some cases the architectures can be compiles both with and without clocksources. So I've taken my best swing at converting this, but I'm not confident I got it right. Any assistance from arch maintainers or testers would be great.

NOT FOR INCLUSION

arch/arm/Kconfig +22 -18
index e02b893..61c88e1 100644
@@ -38,7 +38,7 @@ config GENERIC_GPIO
 
 config GENERIC_TIME
 	bool
-	default n
+	default y
 
 config GENERIC_CLOCKEVENTS
 	bool
@@ -203,6 +203,7 @@ config ARCH_AAEC2000
 	select CPU_ARM920T
 	select ARM_AMBA
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for systems based on the Agilent AAEC-2000
 
@@ -212,6 +213,7 @@ config ARCH_INTEGRATOR
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ICST525
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for ARM's Integrator platform.
 
@@ -221,7 +223,6 @@ config ARCH_REALVIEW
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ICST307
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  This enables support for ARM Ltd RealView boards.
@@ -233,7 +234,6 @@ config ARCH_VERSATILE
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ICST307
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  This enables support for ARM Ltd Versatile board.
@@ -243,6 +243,7 @@ config ARCH_AT91
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for systems based on the Atmel AT91RM9200,
 	  AT91SAM9 and AT91CAP9 processors.
@@ -258,6 +259,7 @@ config ARCH_EBSA110
 	select CPU_SA110
 	select ISA
 	select NO_IOPORT
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This is an evaluation board for the StrongARM processor available
 	  from Digital. It has limited hardware on-board, including an
@@ -273,6 +275,7 @@ config ARCH_EP93XX
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for the Cirrus EP93xx series of CPUs.
 
@@ -288,6 +291,7 @@ config ARCH_FOOTBRIDGE
 	bool "FootBridge"
 	select CPU_SA110
 	select FOOTBRIDGE
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for systems based on the DC21285 companion chip
 	  ("FootBridge"), such as the Simtec CATS and the Rebel NetWinder.
@@ -297,7 +301,6 @@ config ARCH_NETX
 	select CPU_ARM926T
 	select ARM_VIC
 	select GENERIC_CLOCKEVENTS
-	select GENERIC_TIME
 	help
 	  This enables support for systems based on the Hilscher NetX Soc
 
@@ -305,6 +308,7 @@ config ARCH_H720X
 	bool "Hynix HMS720x-based"
 	select CPU_ARM720T
 	select ISA_DMA_API
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for systems based on the Hynix HMS720x
 
@@ -312,7 +316,6 @@ config ARCH_IMX
 	bool "IMX"
 	select CPU_ARM920T
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  Support for Motorola's i.MX family of processors (MX1, MXL).
@@ -325,6 +328,7 @@ config ARCH_IOP13XX
 	select PCI
 	select ARCH_SUPPORTS_MSI
 	select VMSPLIT_1G
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IOP13XX (XScale) family of processors.
 
@@ -336,6 +340,7 @@ config ARCH_IOP32X
 	select PCI
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's 80219 and IOP32X (XScale) family of
 	  processors.
@@ -348,6 +353,7 @@ config ARCH_IOP33X
 	select PCI
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IOP33X (XScale) family of processors.
 
@@ -356,6 +362,7 @@ config ARCH_IXP23XX
 	depends on MMU
 	select CPU_XSC3
  	select PCI
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IXP23xx (XScale) family of processors.
 
@@ -364,6 +371,7 @@ config ARCH_IXP2000
 	depends on MMU
 	select CPU_XSCALE
 	select PCI
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IXP2400/2800 (XScale) family of processors.
 
@@ -372,7 +380,6 @@ config ARCH_IXP4XX
 	depends on MMU
 	select CPU_XSCALE
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select DMABOUNCE if PCI
 	help
@@ -382,6 +389,7 @@ config ARCH_L7200
 	bool "LinkUp-L7200"
 	select CPU_ARM720T
 	select FIQ
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Say Y here if you intend to run this kernel on a LinkUp Systems
 	  L7200 Software Development Board which uses an ARM720T processor.
@@ -397,7 +405,6 @@ config ARCH_KIRKWOOD
 	select CPU_FEROCEON
 	select PCI
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -409,6 +416,7 @@ config ARCH_KS8695
 	select CPU_ARM922T
 	select GENERIC_GPIO
         select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Micrel/Kendin KS8695 "Centaur" (ARM922T) based
 	  System-on-Chip devices.
@@ -417,7 +425,6 @@ config ARCH_NS9XXX
 	bool "NetSilicon NS9xxx"
 	select CPU_ARM926T
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select HAVE_CLK
 	help
@@ -429,7 +436,6 @@ config ARCH_NS9XXX
 config ARCH_LOKI
 	bool "Marvell Loki (88RC8480)"
 	select CPU_FEROCEON
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -440,7 +446,6 @@ config ARCH_MV78XX0
 	select CPU_FEROCEON
 	select PCI
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -449,7 +454,6 @@ config ARCH_MV78XX0
 
 config ARCH_MXC
 	bool "Freescale MXC/iMX-based"
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select ARCH_MTD_XIP
 	select GENERIC_GPIO
@@ -463,7 +467,6 @@ config ARCH_ORION5X
 	select CPU_FEROCEON
 	select PCI
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -475,6 +478,7 @@ config ARCH_PNX4008
 	bool "Philips Nexperia PNX4008 Mobile"
 	select CPU_ARM926T
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for Philips PNX4008 mobile platform.
 
@@ -488,7 +492,6 @@ config ARCH_PXA
 	select ARCH_REQUIRE_GPIOLIB
 	select HAVE_CLK
 	select COMMON_CLKDEV
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
 	select PLAT_PXA
@@ -502,7 +505,6 @@ config ARCH_MMP
 	select ARCH_REQUIRE_GPIOLIB
 	select HAVE_CLK
 	select COMMON_CLKDEV
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
 	select PLAT_PXA
@@ -519,6 +521,7 @@ config ARCH_RPC
 	select ISA_DMA_API
 	select NO_IOPORT
 	select ARCH_SPARSEMEM_ENABLE
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  On the Acorn Risc-PC, Linux can support the internal IDE disk and
 	  CD-ROM interface, serial and parallel port, and the floppy drive.
@@ -530,7 +533,6 @@ config ARCH_SA1100
 	select ARCH_SPARSEMEM_ENABLE
 	select ARCH_MTD_XIP
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select HAVE_CLK
 	select TICK_ONESHOT
@@ -542,6 +544,7 @@ config ARCH_S3C2410
 	bool "Samsung S3C2410, S3C2412, S3C2413, S3C2440, S3C2442, S3C2443"
 	select GENERIC_GPIO
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Samsung S3C2410X CPU based systems, such as the Simtec Electronics
 	  BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or
@@ -551,6 +554,7 @@ config ARCH_S3C64XX
 	bool "Samsung S3C64XX"
 	select GENERIC_GPIO
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Samsung S3C64XX series based systems
 
@@ -561,6 +565,7 @@ config ARCH_SHARK
 	select ISA_DMA
 	select ZONE_DMA
 	select PCI
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for the StrongARM based Digital DNARD machine, also known
 	  as "Shark" (<http://www.shark-linux.de/shark.html>).
@@ -570,6 +575,7 @@ config ARCH_LH7A40X
 	select CPU_ARM922T
 	select ARCH_DISCONTIGMEM_ENABLE if !LH7A40X_CONTIGMEM
 	select ARCH_SPARSEMEM_ENABLE if !LH7A40X_CONTIGMEM
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Say Y here for systems based on one of the Sharp LH7A40X
 	  System on a Chip processors.  These CPUs include an ARM922T
@@ -579,7 +585,6 @@ config ARCH_LH7A40X
 config ARCH_DAVINCI
 	bool "TI DaVinci"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
@@ -593,7 +598,6 @@ config ARCH_OMAP
 	select GENERIC_GPIO
 	select HAVE_CLK
 	select ARCH_REQUIRE_GPIOLIB
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  Support for TI's OMAP platform (OMAP1 and OMAP2).
@@ -601,7 +605,6 @@ config ARCH_OMAP
 config ARCH_MSM
 	bool "Qualcomm MSM"
 	select CPU_V6
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  Support for Qualcomm MSM7K based systems.  This runs on the ARM11
@@ -612,6 +615,7 @@ config ARCH_MSM
 config ARCH_W90X900
 	bool "Nuvoton W90X900 CPU"
 	select CPU_ARM926T
+	select ARCH_USES_GETTIMEOFFSET
 	help
 		Support for Nuvoton (Winbond logic dept.) ARM9 processor,You
 		can login www.mcuos.com or www.nuvoton.com to know more.
arch/arm/include/asm/mach/time.h +1 -1
index b2cc1fc..20c1d84 100644
@@ -38,7 +38,7 @@ struct sys_timer {
 	void			(*init)(void);
 	void			(*suspend)(void);
 	void			(*resume)(void);
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	unsigned long		(*offset)(void);
 #endif
 };
arch/arm/kernel/time.c +6 -57

83 lines not on this page · raw message

arch/arm/mach-at91/Kconfig +1 -7
index 323b47f..e82979c 100644
@@ -8,47 +8,41 @@ choice
 config ARCH_AT91RM9200
 	bool "AT91RM9200"
 	select CPU_ARM920T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9260
 	bool "AT91SAM9260 or AT91SAM9XE"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9261
 	bool "AT91SAM9261"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9263
 	bool "AT91SAM9263"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9RL
 	bool "AT91SAM9RL"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9G20
 	bool "AT91SAM9G20"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91CAP9
 	bool "AT91CAP9"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91X40
 	bool "AT91x40"
+	select ARCH_USES_GETTIMEOFFSET
 
 endchoice
 
#5 lore raw

RFC PATCH 3/8 Convert blackfin to use arch_getoffset() infrastructure.

This patch converts blackfin to use GENERIC_TIME via the arch_getoffset() infrastructure

I do not have cross compilers for these architectures, and in some cases the architectures can be compiles both with and without clocksources. So I've taken my best swing at converting this, but I'm not confident I got it right. Any assistance from arch maintainers or testers would be great.

arch/blackfin/Kconfig +5 -3
index 3640cdc..2b41547 100644
@@ -606,9 +606,7 @@ comment "Kernel Timer/Scheduler"
 source kernel/Kconfig.hz
 
 config GENERIC_TIME
-	bool "Generic time"
-	depends on !SMP
-	default y
+	def_bool y
 
 config GENERIC_CLOCKEVENTS
 	bool "Generic clock events"
@@ -628,6 +626,10 @@ config CYCLES_CLOCKSOURCE
 	  still be able to read it (such as for performance monitoring), but
 	  writing the registers will most likely crash the kernel.
 
+config ARCH_USES_GETTIMEOFFSET
+	depends on !CYCLES_CLOCKSOURCE
+	def_bool y
+
 source kernel/time/Kconfig
 
 comment "Misc"
arch/blackfin/kernel/time.c +20 -55

95 lines not on this page · raw message

#6 lore raw

RFC PATCH 4/8 Convert cris to use arch_getoffset() infrastructure.

This patch converts cris to use GENERIC_TIME via the arch_getoffset() infrastructure

I do not have cross compilers for these architectures, and in some cases the architectures can be compiles both with and without clocksources. So I've taken my best swing at converting this, but I'm not confident I got it right. Any assistance from arch maintainers or testers would be great.

NOT FOR INCLUSION

arch/cris/Kconfig +6 -0
index 7adac38..059eac6 100644
@@ -20,6 +20,12 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
+config GENERIC_TIME
+	def_bool y
+
+config ARCH_USES_GETTIMEOFFSET
+	def_bool y
+
 config GENERIC_IOMAP
        bool
        default y
arch/cris/kernel/time.c +2 -66

77 lines not on this page · raw message

#7 lore raw

RFC PATCH 5/8 Convert m32r to use arch_getoffset() infrastructure.

This patch converts m32r to use GENERIC_TIME via the arch_getoffset() infrastructure

I do not have cross compilers for these architectures, and in some cases the architectures can be compiles both with and without clocksources. So I've taken my best swing at converting this, but I'm not confident I got it right. Any assistance from arch maintainers or testers would be great.

NOT FOR INCLUSION

arch/m32r/Kconfig +6 -0
index cabba33..c41234f 100644
@@ -41,6 +41,12 @@ config HZ
 	int
 	default 100
 
+config GENERIC_TIME
+	def_bool y
+
+config ARCH_USES_GETTIMEOFFSET
+	def_bool y
+
 source "init/Kconfig"
 
 source "kernel/Kconfig.freezer"
arch/m32r/kernel/time.c +3 -71

95 lines not on this page · raw message

#8 lore raw

RFC PATCH 6/8 Convert m68k to use arch_getoffset() infrastructure.

This patch converts m68k to use GENERIC_TIME via the arch_getoffset() infrastructure

I do not have cross compilers for these architectures, and in some cases the architectures can be compiles both with and without clocksources. So I've taken my best swing at converting this, but I'm not confident I got it right. Any assistance from arch maintainers or testers would be great.

NOT FOR INCLUSION

arch/m68k/Kconfig +6 -0
index fb87c08..29dd848 100644
@@ -58,6 +58,12 @@ config HZ
 	int
 	default 100
 
+config GENERIC_TIME
+	def_bool y
+
+config ARCH_USES_GETTIMEOFFSET
+	def_bool y
+
 mainmenu "Linux/68k Kernel Configuration"
 
 source "init/Kconfig"
arch/m68k/kernel/time.c +2 -68

79 lines not on this page · raw message

#9 lore raw

Re: [RFC][PATCH 7/8] Convert sparc to use arch_getoffset() infrastructure.

Hey Dave,
You acked this patch earlier, but I've just tried building with a
cross-compiler environment I had access to and had problems getting it to build.

It seems the pci_do_get/settimeofday() and the bus_do_get/settimeofday() redirection code is causing some trouble. I'm really not sure how the BTFIXUPSET_CALL code works, so I don't want to just kill it off.

Any advice here on how to do this right?

thanks
-john

This patch converts sparc to use GENERIC_TIME via the arch_getoffset() infrastructure

NOT FOR INCLUSION

arch/sparc/Kconfig +4 -1
index cc12cd4..1358aab 100644
@@ -55,8 +55,11 @@ config BITS
 	default 64 if SPARC64
 
 config GENERIC_TIME
+	def_bool y
+
+config ARCH_USES_GETTIMEOFFSET
 	bool
-	default y if SPARC64
+	default y if SPARC32
 
 config GENERIC_CMOS_UPDATE
 	bool
arch/sparc/kernel/time_32.c +2 -79

93 lines not on this page · raw message

#10 lore raw

RFC PATCH 8/8 Remove CONFIG_GENERIC_TIME

This removes all references to CONFIG_GENERIC_TIME in the timekeeping core as well as the arch Kconfig files.

Arch defconfig files were left alone.

Documentation/kernel-parameters.txt +1 -2
index 6172e43..d6769ff 100644
@@ -64,7 +64,6 @@ parameter is applicable:
 	MTD	MTD (Memory Technology Device) support is enabled.
 	NET	Appropriate network support is enabled.
 	NUMA	NUMA support is enabled.
-	GENERIC_TIME The generic timeofday code is enabled.
 	NFS	Appropriate NFS support is enabled.
 	OSS	OSS sound support is enabled.
 	PV_OPS	A paravirtualized kernel is enabled.
@@ -426,7 +425,7 @@ and is between 256 and 4096 characters. It is defined in the file
 			clocksource is not available, it defaults to PIT.
 			Format: { pit | tsc | cyclone | pmtmr }
 
-	clocksource=	[GENERIC_TIME] Override the default clocksource
+	clocksource=	Override the default clocksource
 			Format: <string>
 			Override the default clocksource and use the clocksource
 			with the name specified.
arch/alpha/Kconfig +0 -4
index 4434481..e2251b5 100644
@@ -45,10 +45,6 @@ config GENERIC_CALIBRATE_DELAY
 	bool
 	default y
 
-config GENERIC_TIME
-	bool
-	default y
-
 config ARCH_USES_GETTIMEOFFSET
 	bool
 	default y
arch/arm/Kconfig +0 -4
index 61c88e1..37f3bda 100644
@@ -36,10 +36,6 @@ config GENERIC_GPIO
 	bool
 	default n
 
-config GENERIC_TIME
-	bool
-	default y
-
 config GENERIC_CLOCKEVENTS
 	bool
 	default n
arch/avr32/Kconfig +0 -3
index 35e3bd9..0b1e70d 100644
@@ -45,9 +45,6 @@ config GENERIC_IRQ_PROBE
 config RWSEM_GENERIC_SPINLOCK
 	def_bool y
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_CLOCKEVENTS
 	def_bool y
 
arch/blackfin/Kconfig +0 -4
index 2b41547..7be2b94 100644
@@ -605,12 +605,8 @@ comment "Kernel Timer/Scheduler"
 
 source kernel/Kconfig.hz
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_CLOCKEVENTS
 	bool "Generic clock events"
-	depends on GENERIC_TIME
 	default y
 
 config CYCLES_CLOCKSOURCE
arch/cris/Kconfig +0 -3
index 059eac6..a668ce1 100644
@@ -20,9 +20,6 @@ config RWSEM_GENERIC_SPINLOCK
 config RWSEM_XCHGADD_ALGORITHM
 	bool
 
-config GENERIC_TIME
-	def_bool y
-
 config ARCH_USES_GETTIMEOFFSET
 	def_bool y
 
arch/frv/Kconfig +0 -4
index 9d1552a..42c3497 100644
@@ -38,10 +38,6 @@ config GENERIC_HARDIRQS_NO__DO_IRQ
 	bool
 	default y
 
-config GENERIC_TIME
-	bool
-	default y
-
 config TIME_LOW_RES
 	bool
 	default y
arch/h8300/Kconfig +0 -4
index 9420648..3bf6e51 100644
@@ -58,10 +58,6 @@ config GENERIC_CALIBRATE_DELAY
 	bool
 	default y
 
-config GENERIC_TIME
-	bool
-	default y
-
 config GENERIC_BUG
         bool
         depends on BUG
arch/ia64/Kconfig +0 -4
index 294a3b1..5e1df8c 100644
@@ -80,10 +80,6 @@ config GENERIC_CALIBRATE_DELAY
 	bool
 	default y
 
-config GENERIC_TIME
-	bool
-	default y
-
 config GENERIC_TIME_VSYSCALL
 	bool
 	default y
arch/m32r/Kconfig +0 -3
index c41234f..32ad821 100644
@@ -41,9 +41,6 @@ config HZ
 	int
 	default 100
 
-config GENERIC_TIME
-	def_bool y
-
 config ARCH_USES_GETTIMEOFFSET
 	def_bool y
 
arch/m68k/Kconfig +0 -3
index 29dd848..7b0f880 100644
@@ -58,9 +58,6 @@ config HZ
 	int
 	default 100
 
-config GENERIC_TIME
-	def_bool y
-
 config ARCH_USES_GETTIMEOFFSET
 	def_bool y
 
arch/m68knommu/Kconfig +0 -4
index 4beb59d..2806400 100644
@@ -58,10 +58,6 @@ config GENERIC_CALIBRATE_DELAY
 	bool
 	default y
 
-config GENERIC_TIME
-	bool
-	default y
-
 config GENERIC_CMOS_UPDATE
 	bool
 	default y
arch/microblaze/Kconfig +0 -3
index 8cc312b..73d9963 100644
@@ -37,9 +37,6 @@ config GENERIC_IRQ_PROBE
 config GENERIC_CALIBRATE_DELAY
 	def_bool y
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_TIME_VSYSCALL
 	def_bool n
 
arch/mips/Kconfig +0 -4
index 998e5db..8e1be85 100644
@@ -680,10 +680,6 @@ config GENERIC_CLOCKEVENTS
 	bool
 	default y
 
-config GENERIC_TIME
-	bool
-	default y
-
 config GENERIC_CMOS_UPDATE
 	bool
 	default y
arch/mn10300/Kconfig +0 -3
index 3559267..bab6c1f 100644
@@ -42,9 +42,6 @@ config GENERIC_FIND_NEXT_BIT
 config GENERIC_HWEIGHT
 	def_bool y
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_BUG
 	def_bool y
 
arch/parisc/Kconfig +0 -4
index 9038f39..c42c0b4 100644
@@ -64,10 +64,6 @@ config GENERIC_CALIBRATE_DELAY
 	bool
 	default y
 
-config GENERIC_TIME
-	bool
-	default y
-
 config TIME_LOW_RES
 	bool
 	depends on SMP
arch/powerpc/Kconfig +0 -3
index 5b50e1a..c3f6489 100644
@@ -29,9 +29,6 @@ config MMU
 config GENERIC_CMOS_UPDATE
 	def_bool y
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_TIME_VSYSCALL
 	def_bool y
 
arch/s390/Kconfig +0 -3
index 2eca5fe..dae9e1b 100644
@@ -40,9 +40,6 @@ config ARCH_HAS_ILOG2_U64
 config GENERIC_HWEIGHT
 	def_bool y
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_TIME_VSYSCALL
 	def_bool y
 
arch/sh/Kconfig +0 -4
index 8a13c1a..23ffcae 100644
@@ -73,9 +73,6 @@ config GENERIC_CALIBRATE_DELAY
 config GENERIC_IOMAP
 	bool
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_CLOCKEVENTS
 	def_bool n
 
@@ -446,7 +443,6 @@ config SH_TMU
 	bool "TMU timer support"
 	depends on CPU_SH3 || CPU_SH4
 	default y
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  This enables the use of the TMU as the system timer.
arch/sparc/Kconfig +0 -3
index 1358aab..527efea 100644
@@ -54,9 +54,6 @@ config BITS
 	default 32 if SPARC32
 	default 64 if SPARC64
 
-config GENERIC_TIME
-	def_bool y
-
 config ARCH_USES_GETTIMEOFFSET
 	bool
 	default y if SPARC32
arch/um/Kconfig.common +0 -4
index 0d207e7..7c8e277 100644
@@ -55,10 +55,6 @@ config GENERIC_BUG
 	default y
 	depends on BUG
 
-config GENERIC_TIME
-	bool
-	default y
-
 config GENERIC_CLOCKEVENTS
 	bool
 	default y
arch/x86/Kconfig +2 -5
index bc25b9f..c73cb50 100644
@@ -52,9 +52,6 @@ config ARCH_DEFCONFIG
 	default "arch/x86/configs/i386_defconfig" if X86_32
 	default "arch/x86/configs/x86_64_defconfig" if X86_64
 
-config GENERIC_TIME
-	def_bool y
-
 config GENERIC_CMOS_UPDATE
 	def_bool y
 
@@ -1942,7 +1939,7 @@ config SCx200
 
 config SCx200HR_TIMER
 	tristate "NatSemi SCx200 27MHz High-Resolution Timer Support"
-	depends on SCx200 && GENERIC_TIME
+	depends on SCx200
 	default y
 	---help---
 	  This driver provides a clocksource built upon the on-chip
@@ -1954,7 +1951,7 @@ config SCx200HR_TIMER
 config GEODE_MFGPT_TIMER
 	def_bool y
 	prompt "Geode Multi-Function General Purpose Timer (MFGPT) events"
-	depends on MGEODE_LX && GENERIC_TIME && GENERIC_CLOCKEVENTS
+	depends on MGEODE_LX && GENERIC_CLOCKEVENTS
 	---help---
 	  This driver provides a clock event source based on the MFGPT
 	  timer(s) in the CS5535 and CS5536 companion chip for the geode.
arch/xtensa/Kconfig +0 -3
index fa6dc4d..7bbc6c1 100644
@@ -48,9 +48,6 @@ config HZ
 	int
 	default 100
 
-config GENERIC_TIME
-	def_bool y
-
 source "init/Kconfig"
 source "kernel/Kconfig.freezer"
 
drivers/Makefile +3 -1
index 2618a61..953bc52 100644
@@ -97,7 +97,9 @@ obj-$(CONFIG_SGI_SN)		+= sn/
 obj-y				+= firmware/
 obj-$(CONFIG_CRYPTO)		+= crypto/
 obj-$(CONFIG_SUPERH)		+= sh/
-obj-$(CONFIG_GENERIC_TIME)	+= clocksource/
+ifndef CONFIG_ARCH_USES_GETTIMEOFFSET
+obj-y				+= clocksource/
+endif
 obj-$(CONFIG_DMA_ENGINE)	+= dma/
 obj-$(CONFIG_DCA)		+= dca/
 obj-$(CONFIG_HID)		+= hid/
drivers/acpi/processor_idle.c +3 -3
index 6fe1214..84bee72 100644
@@ -215,7 +215,7 @@ int acpi_processor_resume(struct acpi_device * device)
 	return 0;
 }
 
-#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
+#if defined (CONFIG_X86)
 static int tsc_halts_in_c(int state)
 {
 	switch (boot_cpu_data.x86_vendor) {
@@ -871,7 +871,7 @@ static int acpi_idle_enter_simple(struct cpuidle_device *dev,
 	kt2 = ktime_get_real();
 	idle_time =  ktime_to_us(ktime_sub(kt2, kt1));
 
-#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
+#if defined (CONFIG_X86)
 	/* TSC could halt in idle, so notify users */
 	if (tsc_halts_in_c(cx->type))
 		mark_tsc_unstable("TSC halts in idle");;
@@ -989,7 +989,7 @@ static int acpi_idle_enter_bm(struct cpuidle_device *dev,
 		spin_unlock(&c3_lock);
 	}
 
-#if defined (CONFIG_GENERIC_TIME) && defined (CONFIG_X86)
+#if defined (CONFIG_X86)
 	/* TSC could halt in idle, so notify users */
 	if (tsc_halts_in_c(ACPI_STATE_C3))
 		mark_tsc_unstable("TSC halts in idle");
drivers/misc/Kconfig +1 -1
index 6d1ac18..1a2be66 100644
@@ -32,7 +32,7 @@ config ATMEL_TCLIB
 
 config ATMEL_TCB_CLKSRC
 	bool "TC Block Clocksource"
-	depends on ATMEL_TCLIB && GENERIC_TIME
+	depends on ATMEL_TCLIB
 	default y
 	help
 	  Select this to get a high precision clocksource based on a
kernel/time.c +0 -16
index 2951194..f001888 100644
@@ -302,22 +302,6 @@ struct timespec timespec_trunc(struct timespec t, unsigned gran)
 }
 EXPORT_SYMBOL(timespec_trunc);
 
-#ifndef CONFIG_GENERIC_TIME
-/*
- * Simulate gettimeofday using do_gettimeofday which only allows a timeval
- * and therefore only yields usec accuracy
- */
-void getnstimeofday(struct timespec *tv)
-{
-	struct timeval x;
-
-	do_gettimeofday(&x);
-	tv->tv_sec = x.tv_sec;
-	tv->tv_nsec = x.tv_usec * NSEC_PER_USEC;
-}
-EXPORT_SYMBOL_GPL(getnstimeofday);
-#endif
-
 /* Converts Gregorian date to seconds since 1970-01-01 00:00:00.
  * Assumes input in normal date format, i.e. 1980-12-31 23:59:59
  * => year=1980, mon=12, day=31, hour=23, min=59, sec=59.
kernel/time/Kconfig +2 -2
index 95ed429..f06a8a3 100644
@@ -6,7 +6,7 @@ config TICK_ONESHOT
 
 config NO_HZ
 	bool "Tickless System (Dynamic Ticks)"
-	depends on GENERIC_TIME && GENERIC_CLOCKEVENTS
+	depends on !ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
 	help
 	  This option enables a tickless system: timer interrupts will
@@ -15,7 +15,7 @@ config NO_HZ
 
 config HIGH_RES_TIMERS
 	bool "High Resolution Timer Support"
-	depends on GENERIC_TIME && GENERIC_CLOCKEVENTS
+	depends on !ARCH_USES_GETTIMEOFFSET && GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
 	help
 	  This option enables high resolution timer support. If your
kernel/time/timekeeping.c +4 -5
index 45d777f..7b0575c 100644
@@ -59,7 +59,6 @@ void update_xtime_cache(u64 nsec)
 struct clocksource *clock;
 
 
-#ifdef CONFIG_GENERIC_TIME
 /**
  * clocksource_forward_now - update clock to the current time
  *
@@ -182,6 +181,7 @@ int do_settimeofday(struct timespec *tv)
 
 EXPORT_SYMBOL(do_settimeofday);
 
+#ifndef CONFIG_ARCH_USES_GETTIMEOFFSET
 /**
  * change_clocksource - Swaps clocksources if a new one is available
  *
@@ -217,7 +217,6 @@ static void change_clocksource(void)
 	 */
 }
 #else
-static inline void clocksource_forward_now(void) { }
 static inline void change_clocksource(void) { }
 #endif
 
@@ -492,10 +491,10 @@ void update_wall_time(void)
 	if (unlikely(timekeeping_suspended))
 		return;
 
-#ifdef CONFIG_GENERIC_TIME
-	offset = (clocksource_read(clock) - clock->cycle_last) & clock->mask;
-#else
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	offset = clock->cycle_interval;
+#else
+	offset = (clocksource_read(clock) - clock->cycle_last) & clock->mask;
 #endif
 	clock->xtime_nsec = (s64)xtime.tv_nsec << clock->shift;
 
kernel/trace/Kconfig +2 -2
index 417d198..b156fee 100644
@@ -108,7 +108,7 @@ config IRQSOFF_TRACER
 	bool "Interrupts-off Latency Tracer"
 	default n
 	depends on TRACE_IRQFLAGS_SUPPORT
-	depends on GENERIC_TIME
+	depends on !ARCH_USES_GETTIMEOFFSET
 	select TRACE_IRQFLAGS
 	select TRACING
 	select TRACER_MAX_TRACE
@@ -129,7 +129,7 @@ config IRQSOFF_TRACER
 config PREEMPT_TRACER
 	bool "Preemption-off Latency Tracer"
 	default n
-	depends on GENERIC_TIME
+	depends on !ARCH_USES_GETTIMEOFFSET
 	depends on PREEMPT
 	select TRACING
 	select TRACER_MAX_TRACE
maintainer
#11 lore raw

Re: [RFC][PATCH 7/8] Convert sparc to use arch_getoffset() infrastructure.

In reply to john stultz

From: john stultz <[email protected]>
Date: Tue, 14 Apr 2009 18:51:26 -0700

Quoted 9 lines

You acked this patch earlier, but I've just tried building with a
cross-compiler environment I had access to and had problems getting it to build.

It seems the pci_do_get/settimeofday() and the bus_do_get/settimeofday() redirection code is causing some trouble. I'm really not sure how the BTFIXUPSET_CALL code works, so I don't want to just kill it off.

Any advice here on how to do this right?

BTFIXUP is basically a kernel boot time patching service, but it only works if we can declare function prototypes in the sparc specific header files.

Since do_gettimeofday() doesn't fall into that requirement, the code in pci_time_init() is patching the first two instructions of do_gettimeofday() such that is makes a call to pci_do_gettimeofday().

#12 lore raw

Re: [RFC][PATCH 2/8] Convert arm to use arch_getoffset() infrastructure.

In reply to john stultz

You really need to also post this (and the generic part) to the linux-arm-kernel mailing list; there's far too much here for one person (me) to deal with.

Quoted 487 lines · john stultz

This patch converts arm to use GENERIC_TIME via the arch_getoffset() infrastructure

I do not have cross compilers for these architectures, and in some cases the architectures can be compiles both with and without clocksources. So I've taken my best swing at converting this, but I'm not confident I got it right. Any assistance from arch maintainers or testers would be great.

NOT FOR INCLUSION

arch/arm/Kconfig +22 -18
index e02b893..61c88e1 100644
@@ -38,7 +38,7 @@ config GENERIC_GPIO
 
 config GENERIC_TIME
 	bool
-	default n
+	default y
 
 config GENERIC_CLOCKEVENTS
 	bool
@@ -203,6 +203,7 @@ config ARCH_AAEC2000
 	select CPU_ARM920T
 	select ARM_AMBA
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for systems based on the Agilent AAEC-2000
 
@@ -212,6 +213,7 @@ config ARCH_INTEGRATOR
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ICST525
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for ARM's Integrator platform.
 
@@ -221,7 +223,6 @@ config ARCH_REALVIEW
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ICST307
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  This enables support for ARM Ltd RealView boards.
@@ -233,7 +234,6 @@ config ARCH_VERSATILE
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ICST307
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  This enables support for ARM Ltd Versatile board.
@@ -243,6 +243,7 @@ config ARCH_AT91
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for systems based on the Atmel AT91RM9200,
 	  AT91SAM9 and AT91CAP9 processors.
@@ -258,6 +259,7 @@ config ARCH_EBSA110
 	select CPU_SA110
 	select ISA
 	select NO_IOPORT
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This is an evaluation board for the StrongARM processor available
 	  from Digital. It has limited hardware on-board, including an
@@ -273,6 +275,7 @@ config ARCH_EP93XX
 	select HAVE_CLK
 	select COMMON_CLKDEV
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for the Cirrus EP93xx series of CPUs.
 
@@ -288,6 +291,7 @@ config ARCH_FOOTBRIDGE
 	bool "FootBridge"
 	select CPU_SA110
 	select FOOTBRIDGE
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for systems based on the DC21285 companion chip
 	  ("FootBridge"), such as the Simtec CATS and the Rebel NetWinder.
@@ -297,7 +301,6 @@ config ARCH_NETX
 	select CPU_ARM926T
 	select ARM_VIC
 	select GENERIC_CLOCKEVENTS
-	select GENERIC_TIME
 	help
 	  This enables support for systems based on the Hilscher NetX Soc
 
@@ -305,6 +308,7 @@ config ARCH_H720X
 	bool "Hynix HMS720x-based"
 	select CPU_ARM720T
 	select ISA_DMA_API
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for systems based on the Hynix HMS720x
 
@@ -312,7 +316,6 @@ config ARCH_IMX
 	bool "IMX"
 	select CPU_ARM920T
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  Support for Motorola's i.MX family of processors (MX1, MXL).
@@ -325,6 +328,7 @@ config ARCH_IOP13XX
 	select PCI
 	select ARCH_SUPPORTS_MSI
 	select VMSPLIT_1G
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IOP13XX (XScale) family of processors.
 
@@ -336,6 +340,7 @@ config ARCH_IOP32X
 	select PCI
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's 80219 and IOP32X (XScale) family of
 	  processors.
@@ -348,6 +353,7 @@ config ARCH_IOP33X
 	select PCI
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IOP33X (XScale) family of processors.
 
@@ -356,6 +362,7 @@ config ARCH_IXP23XX
 	depends on MMU
 	select CPU_XSC3
  	select PCI
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IXP23xx (XScale) family of processors.
 
@@ -364,6 +371,7 @@ config ARCH_IXP2000
 	depends on MMU
 	select CPU_XSCALE
 	select PCI
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Intel's IXP2400/2800 (XScale) family of processors.
 
@@ -372,7 +380,6 @@ config ARCH_IXP4XX
 	depends on MMU
 	select CPU_XSCALE
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select DMABOUNCE if PCI
 	help
@@ -382,6 +389,7 @@ config ARCH_L7200
 	bool "LinkUp-L7200"
 	select CPU_ARM720T
 	select FIQ
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Say Y here if you intend to run this kernel on a LinkUp Systems
 	  L7200 Software Development Board which uses an ARM720T processor.
@@ -397,7 +405,6 @@ config ARCH_KIRKWOOD
 	select CPU_FEROCEON
 	select PCI
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -409,6 +416,7 @@ config ARCH_KS8695
 	select CPU_ARM922T
 	select GENERIC_GPIO
         select ARCH_REQUIRE_GPIOLIB
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for Micrel/Kendin KS8695 "Centaur" (ARM922T) based
 	  System-on-Chip devices.
@@ -417,7 +425,6 @@ config ARCH_NS9XXX
 	bool "NetSilicon NS9xxx"
 	select CPU_ARM926T
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select HAVE_CLK
 	help
@@ -429,7 +436,6 @@ config ARCH_NS9XXX
 config ARCH_LOKI
 	bool "Marvell Loki (88RC8480)"
 	select CPU_FEROCEON
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -440,7 +446,6 @@ config ARCH_MV78XX0
 	select CPU_FEROCEON
 	select PCI
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -449,7 +454,6 @@ config ARCH_MV78XX0
 
 config ARCH_MXC
 	bool "Freescale MXC/iMX-based"
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select ARCH_MTD_XIP
 	select GENERIC_GPIO
@@ -463,7 +467,6 @@ config ARCH_ORION5X
 	select CPU_FEROCEON
 	select PCI
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select PLAT_ORION
 	help
@@ -475,6 +478,7 @@ config ARCH_PNX4008
 	bool "Philips Nexperia PNX4008 Mobile"
 	select CPU_ARM926T
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  This enables support for Philips PNX4008 mobile platform.
 
@@ -488,7 +492,6 @@ config ARCH_PXA
 	select ARCH_REQUIRE_GPIOLIB
 	select HAVE_CLK
 	select COMMON_CLKDEV
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
 	select PLAT_PXA
@@ -502,7 +505,6 @@ config ARCH_MMP
 	select ARCH_REQUIRE_GPIOLIB
 	select HAVE_CLK
 	select COMMON_CLKDEV
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select TICK_ONESHOT
 	select PLAT_PXA
@@ -519,6 +521,7 @@ config ARCH_RPC
 	select ISA_DMA_API
 	select NO_IOPORT
 	select ARCH_SPARSEMEM_ENABLE
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  On the Acorn Risc-PC, Linux can support the internal IDE disk and
 	  CD-ROM interface, serial and parallel port, and the floppy drive.
@@ -530,7 +533,6 @@ config ARCH_SA1100
 	select ARCH_SPARSEMEM_ENABLE
 	select ARCH_MTD_XIP
 	select GENERIC_GPIO
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select HAVE_CLK
 	select TICK_ONESHOT
@@ -542,6 +544,7 @@ config ARCH_S3C2410
 	bool "Samsung S3C2410, S3C2412, S3C2413, S3C2440, S3C2442, S3C2443"
 	select GENERIC_GPIO
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Samsung S3C2410X CPU based systems, such as the Simtec Electronics
 	  BAST (<http://www.simtec.co.uk/products/EB110ITX/>), the IPAQ 1940 or
@@ -551,6 +554,7 @@ config ARCH_S3C64XX
 	bool "Samsung S3C64XX"
 	select GENERIC_GPIO
 	select HAVE_CLK
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Samsung S3C64XX series based systems
 
@@ -561,6 +565,7 @@ config ARCH_SHARK
 	select ISA_DMA
 	select ZONE_DMA
 	select PCI
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Support for the StrongARM based Digital DNARD machine, also known
 	  as "Shark" (<http://www.shark-linux.de/shark.html>).
@@ -570,6 +575,7 @@ config ARCH_LH7A40X
 	select CPU_ARM922T
 	select ARCH_DISCONTIGMEM_ENABLE if !LH7A40X_CONTIGMEM
 	select ARCH_SPARSEMEM_ENABLE if !LH7A40X_CONTIGMEM
+	select ARCH_USES_GETTIMEOFFSET
 	help
 	  Say Y here for systems based on one of the Sharp LH7A40X
 	  System on a Chip processors.  These CPUs include an ARM922T
@@ -579,7 +585,6 @@ config ARCH_LH7A40X
 config ARCH_DAVINCI
 	bool "TI DaVinci"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_GPIO
 	select ARCH_REQUIRE_GPIOLIB
@@ -593,7 +598,6 @@ config ARCH_OMAP
 	select GENERIC_GPIO
 	select HAVE_CLK
 	select ARCH_REQUIRE_GPIOLIB
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  Support for TI's OMAP platform (OMAP1 and OMAP2).
@@ -601,7 +605,6 @@ config ARCH_OMAP
 config ARCH_MSM
 	bool "Qualcomm MSM"
 	select CPU_V6
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 	help
 	  Support for Qualcomm MSM7K based systems.  This runs on the ARM11
@@ -612,6 +615,7 @@ config ARCH_MSM
 config ARCH_W90X900
 	bool "Nuvoton W90X900 CPU"
 	select CPU_ARM926T
+	select ARCH_USES_GETTIMEOFFSET
 	help
 		Support for Nuvoton (Winbond logic dept.) ARM9 processor,You
 		can login www.mcuos.com or www.nuvoton.com to know more.
arch/arm/include/asm/mach/time.h +1 -1
index b2cc1fc..20c1d84 100644
@@ -38,7 +38,7 @@ struct sys_timer {
 	void			(*init)(void);
 	void			(*suspend)(void);
 	void			(*resume)(void);
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	unsigned long		(*offset)(void);
 #endif
 };
arch/arm/kernel/time.c +6 -57
index 4cdc4a0..d9d8d6d 100644
@@ -81,7 +81,7 @@ EXPORT_SYMBOL(profile_pc);
  */
 int (*set_rtc)(void);
 
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 static unsigned long dummy_gettimeoffset(void)
 {
 	return 0;
@@ -236,63 +236,12 @@ static inline void do_leds(void)
 #define	do_leds()
 #endif
 
-#ifndef CONFIG_GENERIC_TIME
-void do_gettimeofday(struct timeval *tv)
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
+u32 arch_gettimeoffset(void)
 {
-	unsigned long flags;
-	unsigned long seq;
-	unsigned long usec, sec;
-
-	do {
-		seq = read_seqbegin_irqsave(&xtime_lock, flags);
-		usec = system_timer->offset();
-		sec = xtime.tv_sec;
-		usec += xtime.tv_nsec / 1000;
-	} while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
-
-	/* usec may have gone up a lot: be safe */
-	while (usec >= 1000000) {
-		usec -= 1000000;
-		sec++;
-	}
-
-	tv->tv_sec = sec;
-	tv->tv_usec = usec;
-}
-
-EXPORT_SYMBOL(do_gettimeofday);
-
-int do_settimeofday(struct timespec *tv)
-{
-	time_t wtm_sec, sec = tv->tv_sec;
-	long wtm_nsec, nsec = tv->tv_nsec;
-
-	if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
-		return -EINVAL;
-
-	write_seqlock_irq(&xtime_lock);
-	/*
-	 * This is revolting. We need to set "xtime" correctly. However, the
-	 * value in this location is the value at the most recent update of
-	 * wall time.  Discover what correction gettimeofday() would have
-	 * done, and then undo it!
-	 */
-	nsec -= system_timer->offset() * NSEC_PER_USEC;
-
-	wtm_sec  = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
-	wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
-
-	set_normalized_timespec(&xtime, sec, nsec);
-	set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
-
-	ntp_clear();
-	write_sequnlock_irq(&xtime_lock);
-	clock_was_set();
-	return 0;
+	return system_timer->offset() * 1000;
 }
-
-EXPORT_SYMBOL(do_settimeofday);
-#endif /* !CONFIG_GENERIC_TIME */
+#endif /* CONFIG_ARCH_USES_GETTIMEOFFSET */
 
 /**
  * save_time_delta - Save the offset between system time and RTC time
@@ -391,7 +340,7 @@ device_initcall(timer_init_sysfs);
 
 void __init time_init(void)
 {
-#ifndef CONFIG_GENERIC_TIME
+#ifdef CONFIG_ARCH_USES_GETTIMEOFFSET
 	if (system_timer->offset == NULL)
 		system_timer->offset = dummy_gettimeoffset;
 #endif
arch/arm/mach-at91/Kconfig +1 -7
index 323b47f..e82979c 100644
@@ -8,47 +8,41 @@ choice
 config ARCH_AT91RM9200
 	bool "AT91RM9200"
 	select CPU_ARM920T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9260
 	bool "AT91SAM9260 or AT91SAM9XE"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9261
 	bool "AT91SAM9261"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9263
 	bool "AT91SAM9263"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9RL
 	bool "AT91SAM9RL"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91SAM9G20
 	bool "AT91SAM9G20"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91CAP9
 	bool "AT91CAP9"
 	select CPU_ARM926T
-	select GENERIC_TIME
 	select GENERIC_CLOCKEVENTS
 
 config ARCH_AT91X40
 	bool "AT91x40"
+	select ARCH_USES_GETTIMEOFFSET
 
 endchoice
 
Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#13 lore raw

Re: [RESEND][PATCH 2/2] Convert sh to use arch_getoffset() infrastructure.

In reply to john stultz
Quoted 7 lines · On Tue, 14 Apr 2009 18:36:33 -0700 john stultz <[email protected]> wrote:

This patch converts sh to use GENERIC_TIME via the arch_getoffset() infrastructure

I have tried cross-compiling this for sh3 and sh4. Also little has changed since my last submission where it was acked. So I've taken my best swing at converting this, but I'm not 100% confident I got it right. Any assistance from arch maintainers or testers would be great.

arch/sh/kernel/timers/timer-cmt.c has just vanished from linux-next and I didn't find it popping up anywhere else, so I simply dropped that hunk from the patch.

I'll send these patches at Thomas before they bitrot any further.

What's the status of clocksource-sanity-check-sysfs-clocksource-changes.patch, btw? I have it marked as "still an RFC", but it's been sitting here since January?

#14 lore raw

Re: [RESEND][PATCH 2/2] Convert sh to use arch_getoffset() infrastructure.

Quoted 6 lines · Andrew Morton
Quoted 3 lines · On Tue, 14 Apr 2009 18:36:33 -0700 john stultz <[email protected]> wrote:

This patch converts sh to use GENERIC_TIME via the arch_getoffset() infrastructure

Quoted 9 lines
Quoted 4 lines

I have tried cross-compiling this for sh3 and sh4. Also little has changed since my last submission where it was acked. So I've taken my best swing at converting this, but I'm not 100% confident I got it right. Any assistance from arch maintainers or testers would be great.

arch/sh/kernel/timers/timer-cmt.c has just vanished from linux-next and I didn't find it popping up anywhere else, so I simply dropped that hunk from the patch.

We have been doing a bit of timer chainsawing lately trying to get the last stragglers moved over to clockevents/clocksource code to enable us to kill the old bits and use GENERIC_TIME always. So, it's more bitrot by design ;-)

#15 lore raw

PATCH 1/1 Sanity check sysfs clocksource changes

In reply to Andrew Morton
Quoted 3 lines · Andrew Morton

What's the status of clocksource-sanity-check-sysfs-clocksource-changes.patch, btw? I have it marked as "still an RFC", but it's been sitting here since January?

Thanks for reminding me! I lost track of that one. Still waiting on feedback from Thomas.

Thomas? What do you think? Original patch below, applies with fuzz and builds.

-john

Hey all,
Thomas, Andrew and Ingo pointed out that we don't have any safety
checks in the clocksource sysfs entries to make sure sysadmins don't try to change the clocksource to a non high-res timer capable clocksource (such as jiffies) when high-res timers (HRT) is enabled. Doing so will likely hang a system.

This patch tries to correct this by filtering non HRT clocksources from available_clocksources and not accepting non HRT clocksources with HRT is is enabled.

This has been lightly tested, and seems to work, but there may be some drawbacks.

One issue I realized was that when TSCs disqualified, they are marked as not CLOCK_SOURCE_VALID_FOR_HRES. This means on boxes with unsycned TSCs, the only available clocksource may be the slower acpi_pm and the user will not be able to override it with the TSC as is currently possible. (even if that seems ill-advised).

So Thomas, what do you think? Should we just use CLOCK_SOURCE_IS_CONTINUOUS flag or is CLOCK_SOURCE_VALID_FOR_HRES really what we want?

include/linux/hrtimer.h +1 -1
index bd37078..05f67f0 100644
@@ -305,7 +305,7 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 
 extern ktime_t ktime_get(void);
 extern ktime_t ktime_get_real(void);
-
+extern int hrtimer_hres_active(void);
 
 DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
 
kernel/hrtimer.c +2 -2
index 2dc30c5..fa4abdc 100644
@@ -476,7 +476,7 @@ static inline int hrtimer_is_hres_enabled(void)
 /*
  * Is the high resolution mode active ?
  */
-static inline int hrtimer_hres_active(void)
+int hrtimer_hres_active(void)
 {
 	return __get_cpu_var(hrtimer_bases).hres_active;
 }
@@ -689,7 +689,7 @@ static int hrtimer_switch_to_hres(void)
 
 #else
 
-static inline int hrtimer_hres_active(void) { return 0; }
+int hrtimer_hres_active(void) { return 0; }
 static inline int hrtimer_is_hres_enabled(void) { return 0; }
 static inline int hrtimer_switch_to_hres(void) { return 0; }
 static inline void hrtimer_force_reprogram(struct hrtimer_cpu_base *base) { }
kernel/time/clocksource.c +16 -1
index ca89e15..1bb1161 100644
@@ -30,6 +30,7 @@
 #include <linux/module.h>
 #include <linux/sched.h> /* for spin_unlock_irq() using preempt_count() m68k */
 #include <linux/tick.h>
+#include <linux/hrtimer.h>
 
 /* XXX - Would like a better way for initializing curr_clocksource */
 extern struct clocksource clocksource_jiffies;
@@ -436,6 +437,17 @@ static ssize_t sysfs_override_clocksource(struct sys_device *dev,
 		}
 	}
 
+	/* Check to make sure we don't switch to a non-HRT usable
+	 * clocksource if HRT is enabled and running
+	 */
+	if (hrtimer_hres_active() &&
+	    !(ovr->flags & CLOCK_SOURCE_VALID_FOR_HRES)) {
+		printk(KERN_WARNING "%s clocksource is not HRT compatible. "
+			"Cannot switch while in HRT mode\n", ovr->name);
+		ovr = NULL;
+		override_name[0] = 0;
+	}
+
 	/* Reselect, when the override name has changed */
 	if (ovr != clocksource_override) {
 		clocksource_override = ovr;
@@ -464,7 +476,10 @@ sysfs_show_available_clocksources(struct sys_device *dev,
 
 	spin_lock_irq(&clocksource_lock);
 	list_for_each_entry(src, &clocksource_list, list) {
-		count += snprintf(buf + count,
+		/* Don't show non-HRES clocksource if HRES is enabled */
+		if (!hrtimer_hres_active() ||
+				(src->flags & CLOCK_SOURCE_VALID_FOR_HRES))
+			count += snprintf(buf + count,
 				  max((ssize_t)PAGE_SIZE - count, (ssize_t)0),
 				  "%s ", src->name);
 	}
#16 lore raw

Re: [PATCH] Sanity check sysfs clocksource changes

Quoted 34 lines · john stultz
Quoted 3 lines · Andrew Morton

What's the status of clocksource-sanity-check-sysfs-clocksource-changes.patch, btw? I have it marked as "still an RFC", but it's been sitting here since January?

Thanks for reminding me! I lost track of that one. Still waiting on feedback from Thomas.

Thomas? What do you think? Original patch below, applies with fuzz and builds.

-john

Hey all,
Thomas, Andrew and Ingo pointed out that we don't have any safety
checks in the clocksource sysfs entries to make sure sysadmins don't try to change the clocksource to a non high-res timer capable clocksource (such as jiffies) when high-res timers (HRT) is enabled. Doing so will likely hang a system.

This patch tries to correct this by filtering non HRT clocksources from available_clocksources and not accepting non HRT clocksources with HRT is is enabled.

This has been lightly tested, and seems to work, but there may be some drawbacks.

One issue I realized was that when TSCs disqualified, they are marked as not CLOCK_SOURCE_VALID_FOR_HRES. This means on boxes with unsycned TSCs, the only available clocksource may be the slower acpi_pm and the user will not be able to override it with the TSC as is currently possible. (even if that seems ill-advised).

Quoted 3 lines

So Thomas, what do you think? Should we just use CLOCK_SOURCE_IS_CONTINUOUS flag or is CLOCK_SOURCE_VALID_FOR_HRES really what we want?

Hmm. If we switched to highres and discarded TSC already then we should not go back to it.

Quoted 30 lines
include/linux/hrtimer.h +1 -1
index bd37078..05f67f0 100644
@@ -305,7 +305,7 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 
 extern ktime_t ktime_get(void);
 extern ktime_t ktime_get_real(void);
-
+extern int hrtimer_hres_active(void);
 
 DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
 
kernel/hrtimer.c +1 -1
index 2dc30c5..fa4abdc 100644
@@ -476,7 +476,7 @@ static inline int hrtimer_is_hres_enabled(void)
 /*
  * Is the high resolution mode active ?
  */
-static inline int hrtimer_hres_active(void)
+int hrtimer_hres_active(void)
 {
 	return __get_cpu_var(hrtimer_bases).hres_active;
 }

kernel/hrtimer.c static int hrtimer_switch_to_hres(void) · line 692

Quoted 5 lines
kernel/hrtimer.c +1 -1
@@ -689,7 +689,7 @@ static int hrtimer_switch_to_hres(void)
 
 #else
 
-static inline int hrtimer_hres_active(void) { return 0; }
+int hrtimer_hres_active(void) { return 0; }

We want to keep that static inline and move it to hrtimer.h to allow gcc to optimize stuff out.

Thanks,

tglx

#17 lore raw

Re: [PATCH] Sanity check sysfs clocksource changes

Quoted 7 lines · Thomas Gleixner

Review

Quoted 3 lines · john stultz
(quoted diff) +1 -1
-static inline int hrtimer_hres_active(void) { return 0; }
+int hrtimer_hres_active(void) { return 0; }

We want to keep that static inline and move it to hrtimer.h to allow gcc to optimize stuff out.

Ok. I'm assuming you just wanted the return 0 case moved to hrtimer.h, as moving the other would require moving the hrtimer_base defines out as well.

Let me know if this works for you.

thanks
-john

Hey all,
Thomas, Andrew and Ingo pointed out that we don't have any
safety checks in the clocksource sysfs entries to make sure sysadmins don't try to change the clocksource to a non high-res timer capable clocksource (such as jiffies) when high-res timers (HRT) is enabled. Doing so will likely hang a system.

This patch tries to correct this by filtering non HRT clocksources from available_clocksources and not accepting non HRT clocksources with HRT is is enabled.

This has been lightly tested, and seems to work, but there may be some drawbacks.

One issue I realized was that when TSCs disqualified, they are marked as not CLOCK_SOURCE_VALID_FOR_HRES. This means on boxes with unsycned TSCs, the only available clocksource may be the slower acpi_pm and the user will not be able to override it with the TSC as is currently possible. (even if that seems ill-advised).

include/linux/hrtimer.h +6 -0
index 0d2f7c8..88c7578 100644
@@ -260,6 +260,7 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 	return timer->base->cpu_base->hres_active;
 }
 
+extern int hrtimer_hres_active(void);
 extern void hrtimer_peek_ahead_timers(void);
 
 /*
@@ -301,6 +302,11 @@ static inline int hrtimer_is_hres_active(struct hrtimer *timer)
 {
 	return 0;
 }
+
+static inline int hrtimer_hres_active(void)
+{
+	return 0;
+}
 #endif
 
 extern ktime_t ktime_get(void);
kernel/hrtimer.c +1 -2
index cb8a15c..2f83247 100644
@@ -476,7 +476,7 @@ static inline int hrtimer_is_hres_enabled(void)
 /*
  * Is the high resolution mode active ?
  */
-static inline int hrtimer_hres_active(void)
+int hrtimer_hres_active(void)
 {
 	return __get_cpu_var(hrtimer_bases).hres_active;
 }
@@ -704,7 +704,6 @@ static int hrtimer_switch_to_hres(void)
 
 #else
 
-static inline int hrtimer_hres_active(void) { return 0; }
 static inline int hrtimer_is_hres_enabled(void) { return 0; }
 static inline int hrtimer_switch_to_hres(void) { return 0; }
 static inline void hrtimer_force_reprogram(struct hrtimer_cpu_base *base) { }
kernel/time/clocksource.c +16 -1
index ecfd7b5..27dff34 100644
@@ -30,6 +30,7 @@
 #include <linux/module.h>
 #include <linux/sched.h> /* for spin_unlock_irq() using preempt_count() m68k */
 #include <linux/tick.h>
+#include <linux/hrtimer.h>
 
 void timecounter_init(struct timecounter *tc,
 		      const struct cyclecounter *cc,
@@ -512,6 +513,17 @@ static ssize_t sysfs_override_clocksource(struct sys_device *dev,
 		}
 	}
 
+	/* Check to make sure we don't switch to a non-HRT usable
+	 * clocksource if HRT is enabled and running
+	 */
+	if (hrtimer_hres_active() &&
+	    !(ovr->flags & CLOCK_SOURCE_VALID_FOR_HRES)) {
+		printk(KERN_WARNING "%s clocksource is not HRT compatible. "
+			"Cannot switch while in HRT mode\n", ovr->name);
+		ovr = NULL;
+		override_name[0] = 0;
+	}
+
 	/* Reselect, when the override name has changed */
 	if (ovr != clocksource_override) {
 		clocksource_override = ovr;
@@ -540,7 +552,10 @@ sysfs_show_available_clocksources(struct sys_device *dev,
 
 	spin_lock_irq(&clocksource_lock);
 	list_for_each_entry(src, &clocksource_list, list) {
-		count += snprintf(buf + count,
+		/* Don't show non-HRES clocksource if HRES is enabled */
+		if (!hrtimer_hres_active() ||
+				(src->flags & CLOCK_SOURCE_VALID_FOR_HRES))
+			count += snprintf(buf + count,
 				  max((ssize_t)PAGE_SIZE - count, (ssize_t)0),
 				  "%s ", src->name);
 	}