Skip to contentSkip to conversation

m68k: Drop arch_gettimeoffset and adopt clocksource API

RFC PATCH Superseded Finn Thain 6 participants 53 messages Nov 12, 2018 – Nov 18, 2018

Subsystems (8)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
author
#1 lore raw

RFC PATCH 1/13 arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Finn Thain

Implementations of arch_gettimeoffset are generally not re-entrant and assume that interrupts have been disabled. Unfortunately this pre-condition got broken in v2.6.32.

Fixes 5cfc8ee0bb51 ("ARM: convert arm to arch_gettimeoffset()")
---
 arch/arm/mach-ebsa110/core.c | 5 +++++
 arch/arm/mach-rpc/time.c     | 5 +++++
 2 files changed, 10 insertions(+)
arch/arm/mach-ebsa110/core.c +5 -0
index 688e5fed49a7..479f89a1accf 100644
@@ -160,12 +160,17 @@ static void __init ebsa110_init_early(void)
  */
 static u32 ebsa110_gettimeoffset(void)
 {
+	unsigned long flags;
 	unsigned long offset, count;
 
+	local_irq_save(flags);
+
 	__raw_writeb(0x40, PIT_CTRL);
 	count = __raw_readb(PIT_T1);
 	count |= __raw_readb(PIT_T1) << 8;
 
+	local_irq_restore(flags);
+
 	/*
 	 * If count > COUNT, make the number negative.
 	 */
arch/arm/mach-rpc/time.c +5 -0
index 2689771c1d38..852bb3801638 100644
@@ -29,9 +29,12 @@
 
 static u32 ioc_timer_gettimeoffset(void)
 {
+	unsigned long flags;
 	unsigned int count1, count2, status;
 	long offset;
 
+	local_irq_save(flags);
+
 	ioc_writeb (0, IOC_T0LATCH);
 	barrier ();
 	count1 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
@@ -42,6 +45,8 @@ static u32 ioc_timer_gettimeoffset(void)
 	barrier ();
 	count2 = ioc_readb(IOC_T0CNTL) | (ioc_readb(IOC_T0CNTH) << 8);
 
+	local_irq_restore(flags);
+
 	offset = count2;
 	if (count2 < count1) {
 		/*
Signature · 1 line
2.18.1

Finn Thain

author
#0 lore raw

cover m68k: Drop arch_gettimeoffset and adopt clocksource API

This series removes "select ARCH_USES_GETTIMEOFFSET" from arch/m68k and converts users of arch_gettimeoffset to the clocksource API. Various bugs are fixed along the way.

Those platforms which do not actually implement arch_gettimeoffset (apollo, q40, sun3, sun3x) use the "jiffies" clocksource by default.

More testing and code review would be appreciated.

Finn Thain (13):
arm: Fix mutual exclusion in arch_gettimeoffset
m68k: Fix mutual exclusion in arch_gettimeoffset
m68k: mac: Fix VIA timer counter accesses
m68k: mac: Clean up unused timer definitions
m68k: apollo, q40, sun3, sun3x: Remove arch_gettimeoffset
implementations
m68k: Drop ARCH_USES_GETTIMEOFFSET
m68k: amiga: Convert to clocksource API
m68k: atari: Convert to clocksource API
m68k: bvme6000: Convert to clocksource API
m68k: hp300: Convert to clocksource API
m68k: mac: Convert to clocksource API
m68k: mvme147: Convert to clocksource API
m68k: mvme16x: Convert to clocksource API

 arch/arm/mach-ebsa110/core.c      |   5 ++
 arch/arm/mach-rpc/time.c          |   5 ++
 arch/m68k/Kconfig                 |   1 -
 arch/m68k/amiga/config.c          |  47 +++++++---
 arch/m68k/apollo/config.c         |   7 --
 arch/m68k/atari/config.c          |   2 -
 arch/m68k/atari/time.c            |  45 ++++++++--
 arch/m68k/bvme6000/config.c       |  66 +++++++++-----
 arch/m68k/hp300/config.c          |   1 -
 arch/m68k/hp300/time.c            |  41 +++++++--
 arch/m68k/hp300/time.h            |   1 -
 arch/m68k/include/asm/macints.h   |   3 -
 arch/m68k/include/asm/mvme147hw.h |   1 -
 arch/m68k/mac/config.c            |  10 +--
 arch/m68k/mac/via.c               | 145 ++++++++++++++++++++----------
 arch/m68k/mvme147/config.c        |  51 ++++++++---
 arch/m68k/mvme16x/config.c        |  48 ++++++----
 arch/m68k/q40/config.c            |   9 --
 arch/m68k/sun3/config.c           |   2 -
 arch/m68k/sun3/intersil.c         |   7 --
 arch/m68k/sun3x/config.c          |   1 -
 arch/m68k/sun3x/time.c            |   5 --
 arch/m68k/sun3x/time.h            |   1 -
 23 files changed, 326 insertions(+), 178 deletions(-)
Signature · 1 line
2.18.1
author
#19 lore raw

RFC PATCH 2/13 m68k: Fix mutual exclusion in arch_gettimeoffset

Implementations of arch_gettimeoffset are generally not re-entrant and assume that interrupts have been disabled. Unfortunately this pre-condition got broken in v2.6.32.

Cc Philip Blundell <[email protected]>
Cc Michael Schmitz <[email protected]>
Cc Joshua Thompson <[email protected]>
Fixes 4ad4c76b7afb ("m68k: convert to use arch_gettimeoffset()")
---
 arch/m68k/amiga/config.c    |  6 +++++-
 arch/m68k/atari/time.c      |  6 +++++-
 arch/m68k/bvme6000/config.c | 10 +++++++---
 arch/m68k/hp300/time.c      |  8 +++++++-
 arch/m68k/mac/via.c         |  5 +++++
 arch/m68k/mvme147/config.c  |  6 +++++-
 arch/m68k/mvme16x/config.c  |  1 -
 7 files changed, 34 insertions(+), 8 deletions(-)
arch/m68k/amiga/config.c +5 -1
index 65f63a457130..5ec3687984a9 100644
@@ -492,12 +492,14 @@ static void __init amiga_sched_init(irq_handler_t timer_routine)
 
 #define TICK_SIZE 10000
 
-/* This is always executed with interrupts disabled.  */
 static u32 amiga_gettimeoffset(void)
 {
+	unsigned long flags;
 	unsigned short hi, lo, hi2;
 	u32 ticks, offset = 0;
 
+	local_irq_save(flags);
+
 	/* read CIA B timer A current value */
 	hi  = ciab.tahi;
 	lo  = ciab.talo;
@@ -515,6 +517,8 @@ static u32 amiga_gettimeoffset(void)
 		if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
 			offset = 10000;
 
+	local_irq_restore(flags);
+
 	ticks = jiffy_ticks - ticks;
 	ticks = (10000 * ticks) / jiffy_ticks;
 
arch/m68k/atari/time.c +5 -1
index 9cca64286464..4765e9a58293 100644
@@ -40,11 +40,13 @@ atari_sched_init(irq_handler_t timer_routine)
 
 #define TICK_SIZE 10000
 
-/* This is always executed with interrupts disabled.  */
 u32 atari_gettimeoffset(void)
 {
+  unsigned long flags;
   u32 ticks, offset = 0;
 
+  local_irq_save(flags);
+
   /* read MFP timer C current value */
   ticks = st_mfp.tim_dt_c;
   /* The probability of underflow is less than 2% */
@@ -53,6 +55,8 @@ u32 atari_gettimeoffset(void)
     if (st_mfp.int_pn_b & (1 << 5))
       offset = TICK_SIZE;
 
+  local_irq_restore(flags);
+
   ticks = INT_TICKS - ticks;
   ticks = ticks * 10000L / INT_TICKS;
 
arch/m68k/bvme6000/config.c +7 -3
index 143ee9fa3893..0afdef10a5a4 100644
@@ -206,8 +206,6 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
 }
 
 
-/* This is always executed with interrupts disabled.  */
-
 /*
  * NOTE:  Don't accept any readings within 5us of rollover, as
  * the T1INT bit may be a little slow getting set.  There is also
@@ -217,12 +215,16 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
 
 u32 bvme6000_gettimeoffset(void)
 {
+    unsigned long flags;
     volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
     volatile PitRegsPtr pit = (PitRegsPtr)BVME_PIT_BASE;
-    unsigned char msr = rtc->msr & 0xc0;
+    unsigned char msr;
     unsigned char t1int, t1op;
     u32 v = 800000, ov;
 
+    local_irq_save(flags);
+
+    msr = rtc->msr & 0xc0;
     rtc->msr = 0;	/* Ensure timer registers accessible */
 
     do {
@@ -245,6 +247,8 @@ u32 bvme6000_gettimeoffset(void)
 	v += 10000;			/* Int pending, + 10ms */
     rtc->msr = msr;
 
+    local_irq_restore(flags);
+
     return v * 1000;
 }
 
arch/m68k/hp300/time.c +7 -1
index 289d928a46cb..5cf711fd0858 100644
@@ -49,16 +49,22 @@ static irqreturn_t hp300_tick(int irq, void *dev_id)
 
 u32 hp300_gettimeoffset(void)
 {
-  /* Read current timer 1 value */
+  unsigned long flags;
   unsigned char lsb, msb1, msb2;
   unsigned short ticks;
 
+  local_irq_save(flags);
+
+  /* Read current timer 1 value */
   msb1 = in_8(CLOCKBASE + 5);
   lsb = in_8(CLOCKBASE + 7);
   msb2 = in_8(CLOCKBASE + 5);
   if (msb1 != msb2)
     /* A carry happened while we were reading.  Read it again */
     lsb = in_8(CLOCKBASE + 7);
+
+  local_irq_restore(flags);
+
   ticks = INTVAL - ((msb2 << 8) | lsb);
   return ((USECS_PER_JIFFY * ticks) / INTVAL) * 1000;
 }
arch/m68k/mac/via.c +5 -0
index e4facff0c1f3..e5dff74f59b3 100644
@@ -318,8 +318,11 @@ void via_debug_dump(void)
 
 u32 mac_gettimeoffset(void)
 {
+	unsigned long flags;
 	unsigned long ticks, offset = 0;
 
+	local_irq_save(flags);
+
 	/* read VIA1 timer 2 current value */
 	ticks = via1[vT1CL] | (via1[vT1CH] << 8);
 	/* The probability of underflow is less than 2% */
@@ -327,6 +330,8 @@ u32 mac_gettimeoffset(void)
 		/* Check for pending timer interrupt in VIA1 IFR */
 		if (via1[vIFR] & 0x40) offset = TICK_SIZE;
 
+	local_irq_restore(flags);
+
 	ticks = MAC_CLOCK_TICK - ticks;
 	ticks = ticks * 10000L / MAC_CLOCK_TICK;
 
arch/m68k/mvme147/config.c +5 -1
index adea549d240e..8074940b0aa1 100644
@@ -125,17 +125,21 @@ void mvme147_sched_init (irq_handler_t timer_routine)
 	m147_pcc->t1_int_cntrl = PCC_INT_ENAB|PCC_LEVEL_TIMER1;
 }
 
-/* This is always executed with interrupts disabled.  */
 /* XXX There are race hazards in this code XXX */
 u32 mvme147_gettimeoffset(void)
 {
+	unsigned long flags;
 	volatile unsigned short *cp = (volatile unsigned short *)0xfffe1012;
 	unsigned short n;
 
+	local_irq_save(flags);
+
 	n = *cp;
 	while (n != *cp)
 		n = *cp;
 
+	local_irq_restore(flags);
+
 	n -= PCC_TIMER_PRELOAD;
 	return ((unsigned long)n * 25 / 4) * 1000;
 }
arch/m68k/mvme16x/config.c +0 -1
index 6ee36a5b528d..d4aec717e688 100644
@@ -381,7 +381,6 @@ void mvme16x_sched_init (irq_handler_t timer_routine)
 }
 
 
-/* This is always executed with interrupts disabled.  */
 u32 mvme16x_gettimeoffset(void)
 {
     return (*(volatile u32 *)0xfff42008) * 1000;
Signature · 1 line
2.18.1
author
#23 lore raw

RFC PATCH 6/13 m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Finn Thain

The functions that implement arch_gettimeoffset are re-used by new clocksource drivers in subsequent patches.

Cc Philip Blundell <[email protected]>
Cc Michael Schmitz <[email protected]>
Cc Joshua Thompson <[email protected]>
---
 arch/m68k/Kconfig           | 1 -
 arch/m68k/amiga/config.c    | 3 ---
 arch/m68k/atari/config.c    | 2 --
 arch/m68k/bvme6000/config.c | 2 --
 arch/m68k/hp300/config.c    | 1 -
 arch/m68k/hp300/time.h      | 1 -
 arch/m68k/mac/config.c      | 3 ---
 arch/m68k/mvme147/config.c  | 2 --
 arch/m68k/mvme16x/config.c  | 2 --
 9 files changed, 17 deletions(-)
arch/m68k/Kconfig +0 -1
index 070553791e97..cc62660a5760 100644
@@ -19,7 +19,6 @@ config M68K
 	select GENERIC_STRNCPY_FROM_USER if MMU
 	select GENERIC_STRNLEN_USER if MMU
 	select ARCH_WANT_IPC_PARSE_VERSION
-	select ARCH_USES_GETTIMEOFFSET if MMU && !COLDFIRE
 	select HAVE_FUTEX_CMPXCHG if MMU && FUTEX
 	select HAVE_MOD_ARCH_SPECIFIC
 	select MODULES_USE_ELF_REL
arch/m68k/amiga/config.c +0 -3
index 5ec3687984a9..a575ad419b23 100644
@@ -95,8 +95,6 @@ static char amiga_model_name[13] = "Amiga ";
 static void amiga_sched_init(irq_handler_t handler);
 static void amiga_get_model(char *model);
 static void amiga_get_hardware_list(struct seq_file *m);
-/* amiga specific timer functions */
-static u32 amiga_gettimeoffset(void);
 extern void amiga_mksound(unsigned int count, unsigned int ticks);
 static void amiga_reset(void);
 extern void amiga_init_sound(void);
@@ -386,7 +384,6 @@ void __init config_amiga(void)
 	mach_init_IRQ        = amiga_init_IRQ;
 	mach_get_model       = amiga_get_model;
 	mach_get_hardware_list = amiga_get_hardware_list;
-	arch_gettimeoffset   = amiga_gettimeoffset;
 
 	/*
 	 * default MAX_DMA=0xffffffff on all machines. If we don't do so, the SCSI
arch/m68k/atari/config.c +0 -2
index bd96702a1ad0..89e65be2655f 100644
@@ -78,7 +78,6 @@ static void atari_heartbeat(int on);
 
 /* atari specific timer functions (in time.c) */
 extern void atari_sched_init(irq_handler_t);
-extern u32 atari_gettimeoffset(void);
 extern int atari_mste_hwclk (int, struct rtc_time *);
 extern int atari_tt_hwclk (int, struct rtc_time *);
 
@@ -205,7 +204,6 @@ void __init config_atari(void)
 	mach_init_IRQ        = atari_init_IRQ;
 	mach_get_model	 = atari_get_model;
 	mach_get_hardware_list = atari_get_hardware_list;
-	arch_gettimeoffset   = atari_gettimeoffset;
 	mach_reset           = atari_reset;
 	mach_max_dma_address = 0xffffff;
 #if IS_ENABLED(CONFIG_INPUT_M68K_BEEP)
arch/m68k/bvme6000/config.c +0 -2
index 0afdef10a5a4..3bd56bd04690 100644
@@ -39,7 +39,6 @@
 
 static void bvme6000_get_model(char *model);
 extern void bvme6000_sched_init(irq_handler_t handler);
-extern u32 bvme6000_gettimeoffset(void);
 extern int bvme6000_hwclk (int, struct rtc_time *);
 extern void bvme6000_reset (void);
 void bvme6000_set_vectors (void);
@@ -110,7 +109,6 @@ void __init config_bvme6000(void)
     mach_max_dma_address = 0xffffffff;
     mach_sched_init      = bvme6000_sched_init;
     mach_init_IRQ        = bvme6000_init_IRQ;
-    arch_gettimeoffset   = bvme6000_gettimeoffset;
     mach_hwclk           = bvme6000_hwclk;
     mach_reset		 = bvme6000_reset;
     mach_get_model       = bvme6000_get_model;
arch/m68k/hp300/config.c +0 -1
index a19bcd23f80b..a161d44fd20b 100644
@@ -254,7 +254,6 @@ void __init config_hp300(void)
 	mach_sched_init      = hp300_sched_init;
 	mach_init_IRQ        = hp300_init_IRQ;
 	mach_get_model       = hp300_get_model;
-	arch_gettimeoffset   = hp300_gettimeoffset;
 	mach_hwclk	     = hp300_hwclk;
 	mach_get_ss	     = hp300_get_ss;
 	mach_reset           = hp300_reset;
arch/m68k/hp300/time.h +0 -1
index f5583ec4033d..1d77b55cc72a 100644
@@ -1,2 +1 @@
 extern void hp300_sched_init(irq_handler_t vector);
-extern u32 hp300_gettimeoffset(void);
arch/m68k/mac/config.c +0 -3
index 2367c3792dc7..cecaaa100791 100644
@@ -54,8 +54,6 @@ struct mac_booter_data mac_bi_data;
 /* The phys. video addr. - might be bogus on some machines */
 static unsigned long mac_orig_videoaddr;
 
-/* Mac specific timer functions */
-extern u32 mac_gettimeoffset(void);
 extern int mac_hwclk(int, struct rtc_time *);
 extern void iop_preinit(void);
 extern void iop_init(void);
@@ -150,7 +148,6 @@ void __init config_mac(void)
 	mach_sched_init = via_init_clock;
 	mach_init_IRQ = mac_init_IRQ;
 	mach_get_model = mac_get_model;
-	arch_gettimeoffset = mac_gettimeoffset;
 	mach_hwclk = mac_hwclk;
 	mach_reset = mac_reset;
 	mach_halt = mac_poweroff;
arch/m68k/mvme147/config.c +0 -2
index 8074940b0aa1..ff7141cf27d1 100644
@@ -38,7 +38,6 @@
 
 static void mvme147_get_model(char *model);
 extern void mvme147_sched_init(irq_handler_t handler);
-extern u32 mvme147_gettimeoffset(void);
 extern int mvme147_hwclk (int, struct rtc_time *);
 extern void mvme147_reset (void);
 
@@ -89,7 +88,6 @@ void __init config_mvme147(void)
 	mach_max_dma_address	= 0x01000000;
 	mach_sched_init		= mvme147_sched_init;
 	mach_init_IRQ		= mvme147_init_IRQ;
-	arch_gettimeoffset	= mvme147_gettimeoffset;
 	mach_hwclk		= mvme147_hwclk;
 	mach_reset		= mvme147_reset;
 	mach_get_model		= mvme147_get_model;
arch/m68k/mvme16x/config.c +0 -2
index d4aec717e688..f1ed52331df3 100644
@@ -44,7 +44,6 @@ static MK48T08ptr_t volatile rtc = (MK48T08ptr_t)MVME_RTC_BASE;
 
 static void mvme16x_get_model(char *model);
 extern void mvme16x_sched_init(irq_handler_t handler);
-extern u32 mvme16x_gettimeoffset(void);
 extern int mvme16x_hwclk (int, struct rtc_time *);
 extern void mvme16x_reset (void);
 
@@ -277,7 +276,6 @@ void __init config_mvme16x(void)
     mach_max_dma_address = 0xffffffff;
     mach_sched_init      = mvme16x_sched_init;
     mach_init_IRQ        = mvme16x_init_IRQ;
-    arch_gettimeoffset   = mvme16x_gettimeoffset;
     mach_hwclk           = mvme16x_hwclk;
     mach_reset		 = mvme16x_reset;
     mach_get_model       = mvme16x_get_model;
Signature · 1 line
2.18.1
author
#44 lore raw

RFC PATCH 11/13 m68k: mac: Convert to clocksource API

In reply to Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

Cc Joshua Thompson <[email protected]>
---
 arch/m68k/mac/via.c | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)
arch/m68k/mac/via.c +23 -8
index 7130abec0b77..c4c304470fae 100644
@@ -23,6 +23,7 @@
  *
  */
 
+#include <linux/clocksource.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
@@ -556,13 +557,23 @@ EXPORT_SYMBOL(via2_scsi_drq_pending);
 /* timer and clock source */
 
 #define VIA_CLOCK_FREQ     783360                /* VIA "phase 2" clock in Hz */
-#define VIA_TIMER_INTERVAL (1000000 / HZ)        /* microseconds per jiffy */
 #define VIA_TIMER_CYCLES   (VIA_CLOCK_FREQ / HZ) /* clock cycles per jiffy */
 
 #define VIA_TC             (VIA_TIMER_CYCLES - 2) /* including 0 and -1 */
 #define VIA_TC_LOW         (VIA_TC & 0xFF)
 #define VIA_TC_HIGH        (VIA_TC >> 8)
 
+static u64 mac_read_clk(struct clocksource *cs);
+
+static struct clocksource mac_clk = {
+	.name   = "via1",
+	.rating = 250,
+	.read   = mac_read_clk,
+	.mask   = CLOCKSOURCE_MASK(32),
+	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static u32 clk_total;
 static bool lost_timer_intr;
 
 static irqreturn_t via_timer_handler(int irq, void *data)
@@ -573,16 +584,18 @@ static irqreturn_t via_timer_handler(int irq, void *data)
 	local_irq_save(flags);
 	if (lost_timer_intr) {
 		lost_timer_intr = false;
-		local_irq_restore(flags);
-		func(irq, data);
-	} else
-		local_irq_restore(flags);
+		clk_total += VIA_TIMER_CYCLES;
+	}
+	clk_total += VIA_TIMER_CYCLES;
+	local_irq_restore(flags);
+
 	return func(irq, data);
 }
 
 void __init via_init_clock(irq_handler_t func)
 {
-	if (request_irq(IRQ_MAC_TIMER_1, via_timer_handler, 0, "timer", func)) {
+	if (request_irq(IRQ_MAC_TIMER_1, via_timer_handler, IRQF_TIMER,
+			"timer", func)) {
 		pr_err("Couldn't register %s interrupt\n", "timer");
 		return;
 	}
@@ -592,11 +605,13 @@ void __init via_init_clock(irq_handler_t func)
 	via1[vT1CL] = VIA_TC_LOW;
 	via1[vT1CH] = VIA_TC_HIGH;
 	via1[vACR] |= 0x40;
+
+	clocksource_register_hz(&mac_clk, VIA_CLOCK_FREQ);
 }
 
 #define VIA_T1_INT_FLAG BIT(6)
 
-u32 mac_gettimeoffset(void)
+static u64 mac_read_clk(struct clocksource *cs)
 {
 	unsigned long flags;
 	u8 count_high, count_high_new, count_low;
@@ -631,5 +646,5 @@ u32 mac_gettimeoffset(void)
 	count = ((count_high << 8) | count_low) + 1;
 	count = VIA_TIMER_CYCLES - count + offset;
 
-	return ((count * VIA_TIMER_INTERVAL) / VIA_TIMER_CYCLES) * 1000;
+	return clk_total + count;
 }
Signature · 1 line
2.18.1
author
#45 lore raw

RFC PATCH 12/13 m68k: mvme147: Convert to clocksource API

In reply to Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

---
 arch/m68k/include/asm/mvme147hw.h |  1 -
 arch/m68k/mvme147/config.c        | 43 +++++++++++++++++++++++--------
 2 files changed, 32 insertions(+), 12 deletions(-)
arch/m68k/include/asm/mvme147hw.h +0 -1
index 9c7ff67c5ffd..7c3dd513128e 100644
@@ -66,7 +66,6 @@ struct pcc_regs {
 #define PCC_INT_ENAB		0x08
 
 #define PCC_TIMER_INT_CLR	0x80
-#define PCC_TIMER_PRELOAD	63936l
 
 #define PCC_LEVEL_ABORT		0x07
 #define PCC_LEVEL_SERIAL	0x04
arch/m68k/mvme147/config.c +32 -11

91 lines not on this page · raw message

Signature · 1 line
2.18.1
author
#46 lore raw

RFC PATCH 13/13 m68k: mvme16x: Convert to clocksource API

In reply to Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

---
 arch/m68k/mvme16x/config.c | 45 +++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 13 deletions(-)
arch/m68k/mvme16x/config.c +32 -13
index f1ed52331df3..7bd3a25b2d75 100644
@@ -19,6 +19,7 @@
 #include <linux/mm.h>
 #include <linux/seq_file.h>
 #include <linux/tty.h>
+#include <linux/clocksource.h>
 #include <linux/console.h>
 #include <linux/linkage.h>
 #include <linux/init.h>
@@ -49,12 +50,6 @@ extern void mvme16x_reset (void);
 
 int bcd2int (unsigned char b);
 
-/* Save tick handler routine pointer, will point to xtime_update() in
- * kernel/time/timekeeping.c, called via mvme16x_process_int() */
-
-static irq_handler_t tick_handler;
-
-
 unsigned short mvme16x_config;
 EXPORT_SYMBOL(mvme16x_config);
 
@@ -348,9 +343,31 @@ static irqreturn_t mvme16x_abort_int (int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static u64 mvme16x_read_clk(struct clocksource *cs);
+
+static struct clocksource mvme16x_clk = {
+	.name   = "pcc",
+	.rating = 250,
+	.read   = mvme16x_read_clk,
+	.mask   = CLOCKSOURCE_MASK(32),
+	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static u32 clk_total;
+
+#define PCC_TIMER_CLOCK_FREQ 1000000
+#define PCC_TIMER_CYCLES     (PCC_TIMER_CLOCK_FREQ / HZ)
+
 static irqreturn_t mvme16x_timer_int (int irq, void *dev_id)
 {
+    irq_handler_t tick_handler = dev_id;
+    unsigned long flags;
+
+    local_irq_save(flags);
     *(volatile unsigned char *)0xfff4201b |= 8;
+    clk_total += PCC_TIMER_CYCLES;
+    local_irq_restore(flags);
+
     return tick_handler(irq, dev_id);
 }
 
@@ -359,16 +376,17 @@ void mvme16x_sched_init (irq_handler_t timer_routine)
     uint16_t brdno = be16_to_cpu(mvme_bdid.brdno);
     int irq;
 
-    tick_handler = timer_routine;
     /* Using PCCchip2 or MC2 chip tick timer 1 */
     *(volatile unsigned long *)0xfff42008 = 0;
-    *(volatile unsigned long *)0xfff42004 = 10000;	/* 10ms */
+    *(volatile unsigned long *)0xfff42004 = PCC_TIMER_CYCLES;
     *(volatile unsigned char *)0xfff42017 |= 3;
     *(volatile unsigned char *)0xfff4201b = 0x16;
-    if (request_irq(MVME16x_IRQ_TIMER, mvme16x_timer_int, 0,
-				"timer", mvme16x_timer_int))
+    if (request_irq(MVME16x_IRQ_TIMER, mvme16x_timer_int, IRQF_TIMER,
+				"timer", timer_routine))
 	panic ("Couldn't register timer int");
 
+    clocksource_register_hz(&mvme16x_clk, PCC_TIMER_CLOCK_FREQ);
+
     if (brdno == 0x0162 || brdno == 0x172)
 	irq = MVME162_IRQ_ABORT;
     else
@@ -378,10 +396,11 @@ void mvme16x_sched_init (irq_handler_t timer_routine)
 	panic ("Couldn't register abort int");
 }
 
-
-u32 mvme16x_gettimeoffset(void)
+static u64 mvme16x_read_clk(struct clocksource *cs)
 {
-    return (*(volatile u32 *)0xfff42008) * 1000;
+    u32 count = *(volatile u32 *)0xfff42008;
+
+    return clk_total + count;
 }
 
 int bcd2int (unsigned char b)
Signature · 1 line
2.18.1
author
#22 lore raw

RFC PATCH 5/13 m68k: apollo, q40, sun3, sun3x: Remove arch_gettimeoffset implementations

In reply to Finn Thain

These dummy implementations are no better than
default_arch_gettimeoffset() so remove them.

---
 arch/m68k/apollo/config.c | 7 -------
 arch/m68k/q40/config.c    | 9 ---------
 arch/m68k/sun3/config.c   | 2 --
 arch/m68k/sun3/intersil.c | 7 -------
 arch/m68k/sun3x/config.c  | 1 -
 arch/m68k/sun3x/time.c    | 5 -----
 arch/m68k/sun3x/time.h    | 1 -
 7 files changed, 32 deletions(-)
arch/m68k/apollo/config.c +0 -7
index aef8d42e078d..7d168e6dfb01 100644
@@ -29,7 +29,6 @@ u_long apollo_model;
 
 extern void dn_sched_init(irq_handler_t handler);
 extern void dn_init_IRQ(void);
-extern u32 dn_gettimeoffset(void);
 extern int dn_dummy_hwclk(int, struct rtc_time *);
 extern void dn_dummy_reset(void);
 #ifdef CONFIG_HEARTBEAT
@@ -152,7 +151,6 @@ void __init config_apollo(void)
 
 	mach_sched_init=dn_sched_init; /* */
 	mach_init_IRQ=dn_init_IRQ;
-	arch_gettimeoffset   = dn_gettimeoffset;
 	mach_max_dma_address = 0xffffffff;
 	mach_hwclk           = dn_dummy_hwclk; /* */
 	mach_reset	     = dn_dummy_reset;  /* */
@@ -205,11 +203,6 @@ void dn_sched_init(irq_handler_t timer_routine)
 		pr_err("Couldn't register timer interrupt\n");
 }
 
-u32 dn_gettimeoffset(void)
-{
-	return 0xdeadbeef;
-}
-
 int dn_dummy_hwclk(int op, struct rtc_time *t) {
 
 
arch/m68k/q40/config.c +0 -9
index 96810d91da2b..e63eb5f06999 100644
@@ -40,7 +40,6 @@ extern void q40_init_IRQ(void);
 static void q40_get_model(char *model);
 extern void q40_sched_init(irq_handler_t handler);
 
-static u32 q40_gettimeoffset(void);
 static int q40_hwclk(int, struct rtc_time *);
 static unsigned int q40_get_ss(void);
 static int q40_get_rtc_pll(struct rtc_pll_info *pll);
@@ -169,7 +168,6 @@ void __init config_q40(void)
 	mach_sched_init = q40_sched_init;
 
 	mach_init_IRQ = q40_init_IRQ;
-	arch_gettimeoffset = q40_gettimeoffset;
 	mach_hwclk = q40_hwclk;
 	mach_get_ss = q40_get_ss;
 	mach_get_rtc_pll = q40_get_rtc_pll;
@@ -201,13 +199,6 @@ int __init q40_parse_bootinfo(const struct bi_record *rec)
 	return 1;
 }
 
-
-static u32 q40_gettimeoffset(void)
-{
-	return 5000 * (ql_ticks != 0) * 1000;
-}
-
-
 /*
  * Looks like op is non-zero for setting the clock, and zero for
  * reading the clock.
arch/m68k/sun3/config.c +0 -2
index 79a2bb857906..867e68d92c71 100644
@@ -37,7 +37,6 @@
 
 char sun3_reserved_pmeg[SUN3_PMEGS_NUM];
 
-extern u32 sun3_gettimeoffset(void);
 static void sun3_sched_init(irq_handler_t handler);
 extern void sun3_get_model (char* model);
 extern int sun3_hwclk(int set, struct rtc_time *t);
@@ -138,7 +137,6 @@ void __init config_sun3(void)
         mach_sched_init      =  sun3_sched_init;
         mach_init_IRQ        =  sun3_init_IRQ;
         mach_reset           =  sun3_reboot;
-	arch_gettimeoffset   =  sun3_gettimeoffset;
 	mach_get_model	     =  sun3_get_model;
 	mach_hwclk           =  sun3_hwclk;
 	mach_halt	     =  sun3_halt;
arch/m68k/sun3/intersil.c +0 -7
index d911070af02a..8fc74864de81 100644
@@ -22,13 +22,6 @@
 #define STOP_VAL (INTERSIL_STOP | INTERSIL_INT_ENABLE | INTERSIL_24H_MODE)
 #define START_VAL (INTERSIL_RUN | INTERSIL_INT_ENABLE | INTERSIL_24H_MODE)
 
-/* does this need to be implemented? */
-u32 sun3_gettimeoffset(void)
-{
-  return 1000;
-}
-
-
 /* get/set hwclock */
 
 int sun3_hwclk(int set, struct rtc_time *t)
arch/m68k/sun3x/config.c +0 -1
index 33d3a1c6fba0..03ce7f9facfe 100644
@@ -49,7 +49,6 @@ void __init config_sun3x(void)
 	mach_sched_init      = sun3x_sched_init;
 	mach_init_IRQ        = sun3_init_IRQ;
 
-	arch_gettimeoffset   = sun3x_gettimeoffset;
 	mach_reset           = sun3x_reboot;
 
 	mach_hwclk           = sun3x_hwclk;
arch/m68k/sun3x/time.c +0 -5
index 047e2bcee3d7..5328220ed2d8 100644
@@ -73,11 +73,6 @@ int sun3x_hwclk(int set, struct rtc_time *t)
 
 	return 0;
 }
-/* Not much we can do here */
-u32 sun3x_gettimeoffset(void)
-{
-    return 0L;
-}
 
 #if 0
 static void sun3x_timer_tick(int irq, void *dev_id, struct pt_regs *regs)
arch/m68k/sun3x/time.h +0 -1
index 496f406412ad..86ce78bb3c28 100644
@@ -3,7 +3,6 @@
 #define SUN3X_TIME_H
 
 extern int sun3x_hwclk(int set, struct rtc_time *t);
-u32 sun3x_gettimeoffset(void);
 void sun3x_sched_init(irq_handler_t vector);
 
 struct mostek_dt {
Signature · 1 line
2.18.1
author
#42 lore raw

RFC PATCH 9/13 m68k: bvme6000: Convert to clocksource API

In reply to Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

---
 arch/m68k/bvme6000/config.c | 54 ++++++++++++++++++++++++-------------
 1 file changed, 35 insertions(+), 19 deletions(-)
arch/m68k/bvme6000/config.c +35 -19
index 3bd56bd04690..099cc6edebc8 100644
@@ -18,6 +18,7 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/tty.h>
+#include <linux/clocksource.h>
 #include <linux/console.h>
 #include <linux/linkage.h>
 #include <linux/init.h>
@@ -43,12 +44,6 @@ extern int bvme6000_hwclk (int, struct rtc_time *);
 extern void bvme6000_reset (void);
 void bvme6000_set_vectors (void);
 
-/* Save tick handler routine pointer, will point to xtime_update() in
- * kernel/timer/timekeeping.c, called via bvme6000_process_int() */
-
-static irq_handler_t tick_handler;
-
-
 int __init bvme6000_parse_bootinfo(const struct bi_record *bi)
 {
 	if (be16_to_cpu(bi->tag) == BI_VME_TYPE)
@@ -152,13 +147,34 @@ irqreturn_t bvme6000_abort_int (int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+static u64 bvme6000_read_clk(struct clocksource *cs);
+
+static struct clocksource bvme6000_clk = {
+	.name   = "rtc",
+	.rating = 250,
+	.read   = bvme6000_read_clk,
+	.mask   = CLOCKSOURCE_MASK(32),
+	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static u32 clk_total;
+
+#define RTC_TIMER_CLOCK_FREQ 8000000
+#define RTC_TIMER_CYCLES     (RTC_TIMER_CLOCK_FREQ / HZ)
+#define RTC_TIMER_COUNT      ((RTC_TIMER_CYCLES / 2) - 1)
 
 static irqreturn_t bvme6000_timer_int (int irq, void *dev_id)
 {
+    irq_handler_t tick_handler = dev_id;
     volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
-    unsigned char msr = rtc->msr & 0xc0;
+    unsigned char msr;
+    unsigned long flags;
 
+    local_irq_save(flags);
+    msr = rtc->msr & 0xc0;
     rtc->msr = msr | 0x20;		/* Ack the interrupt */
+    clk_total += RTC_TIMER_CYCLES;
+    local_irq_restore(flags);
 
     return tick_handler(irq, dev_id);
 }
@@ -179,14 +195,13 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
 
     rtc->msr = 0;	/* Ensure timer registers accessible */
 
-    tick_handler = timer_routine;
-    if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, 0,
-				"timer", bvme6000_timer_int))
+    if (request_irq(BVME_IRQ_RTC, bvme6000_timer_int, IRQF_TIMER,
+				"timer", timer_routine))
 	panic ("Couldn't register timer int");
 
     rtc->t1cr_omr = 0x04;	/* Mode 2, ext clk */
-    rtc->t1msb = 39999 >> 8;
-    rtc->t1lsb = 39999 & 0xff;
+    rtc->t1msb = RTC_TIMER_COUNT >> 8;
+    rtc->t1lsb = RTC_TIMER_COUNT & 0xff;
     rtc->irr_icr1 &= 0xef;	/* Route timer 1 to INTR pin */
     rtc->msr = 0x40;		/* Access int.cntrl, etc */
     rtc->pfr_icr0 = 0x80;	/* Just timer 1 ints enabled */
@@ -198,6 +213,8 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
 
     rtc->msr = msr;
 
+    clocksource_register_hz(&bvme6000_clk, RTC_TIMER_CLOCK_FREQ);
+
     if (request_irq(BVME_IRQ_ABORT, bvme6000_abort_int, 0,
 				"abort", bvme6000_abort_int))
 	panic ("Couldn't register abort int");
@@ -211,7 +228,7 @@ void bvme6000_sched_init (irq_handler_t timer_routine)
  * results...
  */
 
-u32 bvme6000_gettimeoffset(void)
+static u64 bvme6000_read_clk(struct clocksource *cs)
 {
     unsigned long flags;
     volatile RtcPtr_t rtc = (RtcPtr_t)BVME_RTC_BASE;
@@ -235,19 +252,18 @@ u32 bvme6000_gettimeoffset(void)
     } while (t1int != (rtc->msr & 0x20) ||
 		t1op != (pit->pcdr & 0x04) ||
 			abs(ov-v) > 80 ||
-				v > 39960);
+				v > RTC_TIMER_COUNT - (RTC_TIMER_COUNT / 100));
 
-    v = 39999 - v;
+    v = RTC_TIMER_COUNT - v;
     if (!t1op)				/* If in second half cycle.. */
-	v += 40000;
-    v /= 8;				/* Convert ticks to microseconds */
+	v += RTC_TIMER_CYCLES / 2;
     if (t1int)
-	v += 10000;			/* Int pending, + 10ms */
+	v += RTC_TIMER_CYCLES;
     rtc->msr = msr;
 
     local_irq_restore(flags);
 
-    return v * 1000;
+    return clk_total + v;
 }
 
 /*
Signature · 1 line
2.18.1
author
#41 lore raw

RFC PATCH 8/13 m68k: atari: Convert to clocksource API

In reply to Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

Cc Michael Schmitz <[email protected]>
---
 arch/m68k/atari/time.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)
arch/m68k/atari/time.c +32 -7
index 4765e9a58293..d066599fcc54 100644
@@ -16,6 +16,7 @@
 #include <linux/init.h>
 #include <linux/rtc.h>
 #include <linux/bcd.h>
+#include <linux/clocksource.h>
 #include <linux/delay.h>
 #include <linux/export.h>
 
@@ -24,6 +25,30 @@
 DEFINE_SPINLOCK(rtc_lock);
 EXPORT_SYMBOL_GPL(rtc_lock);
 
+static u64 atari_read_clk(struct clocksource *cs);
+
+static struct clocksource atari_clk = {
+	.name   = "mfp",
+	.rating = 250,
+	.read   = atari_read_clk,
+	.mask   = CLOCKSOURCE_MASK(32),
+	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static u32 clk_total;
+
+static irqreturn_t mfp_timer_handler(int irq, void *data)
+{
+	irq_handler_t func = data;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	clk_total += INT_TICKS;
+	local_irq_restore(flags);
+
+	return func(irq, data);
+}
+
 void __init
 atari_sched_init(irq_handler_t timer_routine)
 {
@@ -32,15 +57,16 @@ atari_sched_init(irq_handler_t timer_routine)
     /* start timer C, div = 1:100 */
     st_mfp.tim_ct_cd = (st_mfp.tim_ct_cd & 15) | 0x60;
     /* install interrupt service routine for MFP Timer C */
-    if (request_irq(IRQ_MFP_TIMC, timer_routine, 0, "timer", timer_routine))
+    if (request_irq(IRQ_MFP_TIMC, mfp_timer_handler, IRQF_TIMER, "timer",
+                    timer_routine))
 	pr_err("Couldn't register timer interrupt\n");
+
+    clocksource_register_hz(&atari_clk, INT_CLK);
 }
 
 /* ++andreas: gettimeoffset fixed to check for pending interrupt */
 
-#define TICK_SIZE 10000
-
-u32 atari_gettimeoffset(void)
+static u64 atari_read_clk(struct clocksource *cs)
 {
   unsigned long flags;
   u32 ticks, offset = 0;
@@ -53,14 +79,13 @@ u32 atari_gettimeoffset(void)
   if (ticks > INT_TICKS - INT_TICKS / 50)
     /* Check for pending timer interrupt */
     if (st_mfp.int_pn_b & (1 << 5))
-      offset = TICK_SIZE;
+      offset = INT_TICKS;
 
   local_irq_restore(flags);
 
   ticks = INT_TICKS - ticks;
-  ticks = ticks * 10000L / INT_TICKS;
 
-  return (ticks + offset) * 1000;
+  return clk_total + ticks + offset;
 }
 
 
Signature · 1 line
2.18.1
author
#43 lore raw

RFC PATCH 10/13 m68k: hp300: Convert to clocksource API

In reply to Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

Cc Philip Blundell <[email protected]>
---
 arch/m68k/hp300/time.c | 33 ++++++++++++++++++++++++++++-----
 1 file changed, 28 insertions(+), 5 deletions(-)
arch/m68k/hp300/time.c +28 -5
index 5cf711fd0858..ff2fc65bc5e7 100644
@@ -8,6 +8,7 @@
  */
 
 #include <asm/ptrace.h>
+#include <linux/clocksource.h>
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/sched.h>
@@ -19,6 +20,18 @@
 #include <asm/traps.h>
 #include <asm/blinken.h>
 
+static u64 hp300_read_clk(struct clocksource *cs);
+
+static struct clocksource hp300_clk = {
+	.name   = "timer",
+	.rating = 250,
+	.read   = hp300_read_clk,
+	.mask   = CLOCKSOURCE_MASK(32),
+	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static u32 clk_total;
+
 /* Clock hardware definitions */
 
 #define CLOCKBASE	0xf05f8000
@@ -32,22 +45,29 @@
 #define	CLKMSB3		0xD
 
 /* This is for machines which generate the exact clock. */
-#define USECS_PER_JIFFY (1000000/HZ)
 
-#define INTVAL ((10000 / 4) - 1)
+#define HP300_TIMER_CLOCK_FREQ 250000
+#define HP300_TIMER_CYCLES     (HP300_TIMER_CLOCK_FREQ / HZ)
+#define INTVAL                 (HP300_TIMER_CYCLES - 1)
 
 static irqreturn_t hp300_tick(int irq, void *dev_id)
 {
+	unsigned long flags;
 	unsigned long tmp;
 	irq_handler_t vector = dev_id;
+
+	local_irq_save(flags);
 	in_8(CLOCKBASE + CLKSR);
 	asm volatile ("movpw %1@(5),%0" : "=d" (tmp) : "a" (CLOCKBASE));
+	clk_total += INTVAL;
+	local_irq_restore(flags);
+
 	/* Turn off the network and SCSI leds */
 	blinken_leds(0, 0xe0);
 	return vector(irq, NULL);
 }
 
-u32 hp300_gettimeoffset(void)
+static u64 hp300_read_clk(struct clocksource *cs)
 {
   unsigned long flags;
   unsigned char lsb, msb1, msb2;
@@ -66,7 +86,8 @@ u32 hp300_gettimeoffset(void)
   local_irq_restore(flags);
 
   ticks = INTVAL - ((msb2 << 8) | lsb);
-  return ((USECS_PER_JIFFY * ticks) / INTVAL) * 1000;
+
+  return clk_total + ticks;
 }
 
 void __init hp300_sched_init(irq_handler_t vector)
@@ -76,9 +97,11 @@ void __init hp300_sched_init(irq_handler_t vector)
 
   asm volatile(" movpw %0,%1@(5)" : : "d" (INTVAL), "a" (CLOCKBASE));
 
-  if (request_irq(IRQ_AUTO_6, hp300_tick, 0, "timer tick", vector))
+  if (request_irq(IRQ_AUTO_6, hp300_tick, IRQF_TIMER, "timer tick", vector))
     pr_err("Couldn't register timer interrupt\n");
 
   out_8(CLOCKBASE + CLKCR2, 0x1);		/* select CR1 */
   out_8(CLOCKBASE + CLKCR1, 0x40);		/* enable irq */
+
+  clocksource_register_hz(&hp300_clk, HP300_TIMER_CLOCK_FREQ);
 }
Signature · 1 line
2.18.1
author
#38 lore raw

RFC PATCH 7/13 m68k: amiga: Convert to clocksource API

In reply to Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

---
 arch/m68k/amiga/config.c | 38 +++++++++++++++++++++++++++++++-------
 1 file changed, 31 insertions(+), 7 deletions(-)
arch/m68k/amiga/config.c +31 -7
index a575ad419b23..40ebd471cc3c 100644
@@ -17,6 +17,7 @@
 #include <linux/mm.h>
 #include <linux/seq_file.h>
 #include <linux/tty.h>
+#include <linux/clocksource.h>
 #include <linux/console.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
@@ -461,7 +462,30 @@ void __init config_amiga(void)
 		*(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
 }
 
+static u64 amiga_read_clk(struct clocksource *cs);
+
+static struct clocksource amiga_clk = {
+	.name   = "ciab",
+	.rating = 250,
+	.read   = amiga_read_clk,
+	.mask   = CLOCKSOURCE_MASK(32),
+	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
 static unsigned short jiffy_ticks;
+static u32 clk_total;
+
+static irqreturn_t ciab_timer_handler(int irq, void *data)
+{
+	irq_handler_t timer_routine = data;
+	unsigned long flags;
+
+	local_irq_save(flags);
+	clk_total += jiffy_ticks;
+	local_irq_restore(flags);
+
+	return timer_routine(irq, data);
+}
 
 static void __init amiga_sched_init(irq_handler_t timer_routine)
 {
@@ -481,15 +505,16 @@ static void __init amiga_sched_init(irq_handler_t timer_routine)
 	 * Please don't change this to use ciaa, as it interferes with the
 	 * SCSI code. We'll have to take a look at this later
 	 */
-	if (request_irq(IRQ_AMIGA_CIAB_TA, timer_routine, 0, "timer", NULL))
+	if (request_irq(IRQ_AMIGA_CIAB_TA, ciab_timer_handler, IRQF_TIMER,
+			"timer", timer_routine))
 		pr_err("Couldn't register timer interrupt\n");
 	/* start timer */
 	ciab.cra |= 0x11;
-}
 
-#define TICK_SIZE 10000
+	clocksource_register_hz(&amiga_clk, amiga_eclock);
+}
 
-static u32 amiga_gettimeoffset(void)
+static u64 amiga_read_clk(struct clocksource *cs)
 {
 	unsigned long flags;
 	unsigned short hi, lo, hi2;
@@ -512,14 +537,13 @@ static u32 amiga_gettimeoffset(void)
 	if (ticks > jiffy_ticks / 2)
 		/* check for pending interrupt */
 		if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
-			offset = 10000;
+			offset = jiffy_ticks;
 
 	local_irq_restore(flags);
 
 	ticks = jiffy_ticks - ticks;
-	ticks = (10000 * ticks) / jiffy_ticks;
 
-	return (ticks + offset) * 1000;
+	return clk_total + ticks + offset;
 }
 
 static void amiga_reset(void)  __noreturn;
Signature · 1 line
2.18.1
author
#20 lore raw

RFC PATCH 3/13 m68k: mac: Fix VIA timer counter accesses

In reply to Finn Thain

This resolves some bugs that affect VIA timer counter accesses. Firstly, keep track of lost interrupts caused by reading the counter. Secondly, check for inconsistent results when reading the counter. Finally, make allowance for the fact that the counter will be decremented to 0xFFFF before being reloaded.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc Joshua Thompson <[email protected]>
---
 arch/m68k/mac/config.c |   7 +--
 arch/m68k/mac/via.c    | 135 ++++++++++++++++++++++++-----------------
 2 files changed, 82 insertions(+), 60 deletions(-)
arch/m68k/mac/config.c +1 -6
index cd9317d53276..2367c3792dc7 100644
@@ -72,11 +72,6 @@ static void mac_get_model(char *str);
 static void mac_identify(void);
 static void mac_report_hardware(void);
 
-static void __init mac_sched_init(irq_handler_t vector)
-{
-	via_init_clock(vector);
-}
-
 /*
  * Parse a Macintosh-specific record in the bootinfo
  */
@@ -152,7 +147,7 @@ void __init config_mac(void)
 	if (!MACH_IS_MAC)
 		pr_err("ERROR: no Mac, but config_mac() called!!\n");
 
-	mach_sched_init = mac_sched_init;
+	mach_sched_init = via_init_clock;
 	mach_init_IRQ = mac_init_IRQ;
 	mach_get_model = mac_get_model;
 	arch_gettimeoffset = mac_gettimeoffset;
arch/m68k/mac/via.c +81 -54

156 lines not on this page · raw message

Signature · 1 line
2.18.1
author
#21 lore raw

RFC PATCH 4/13 m68k: mac: Clean up unused timer definitions

In reply to Finn Thain
Cc Joshua Thompson <[email protected]>
---
 arch/m68k/include/asm/macints.h | 3 ---
 1 file changed, 3 deletions(-)
arch/m68k/include/asm/macints.h +0 -3
index cddb2d3ea49b..4da172bd048c 100644
@@ -121,7 +121,4 @@
 #define SLOT2IRQ(x)	  (x + 47)
 #define IRQ2SLOT(x)	  (x - 47)
 
-#define INT_CLK   24576	    /* CLK while int_clk =2.456MHz and divide = 100 */
-#define INT_TICKS 246	    /* to make sched_time = 99.902... HZ */
-
 #endif /* asm/macints.h */
Signature · 1 line
2.18.1
#2 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Finn Thain
Quoted 6 lines · Finn Thain

Implementations of arch_gettimeoffset are generally not re-entrant and assume that interrupts have been disabled. Unfortunately this pre-condition got broken in v2.6.32.

Fixes 5cfc8ee0bb51 ("ARM: convert arm to arch_gettimeoffset()")

This looks like a sensible fix for -stable backporting. But with m68k converted over it might be time for these two arm platforms to either be converted to the clocksource API or to be dropped..

#24 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Finn Thain

Hi Finn,

Thanks for your patch!

Quoted 2 lines · Finn Thain

The functions that implement arch_gettimeoffset are re-used by new clocksource drivers in subsequent patches.

Disabling this first affects functionality during bisection, right?

Quoted 12 lines
arch/m68k/amiga/config.c +0 -2
@@ -95,8 +95,6 @@ static char amiga_model_name[13] = "Amiga ";
 static void amiga_sched_init(irq_handler_t handler);
 static void amiga_get_model(char *model);
 static void amiga_get_hardware_list(struct seq_file *m);
-/* amiga specific timer functions */
-static u32 amiga_gettimeoffset(void);
 extern void amiga_mksound(unsigned int count, unsigned int ticks);
 static void amiga_reset(void);
 extern void amiga_init_sound(void);

arch/m68k/amiga/config.c void __init config_amiga(void) · line 389

Quoted 4 lines
arch/m68k/amiga/config.c +0 -1
@@ -386,7 +384,6 @@ void __init config_amiga(void)
        mach_init_IRQ        = amiga_init_IRQ;
        mach_get_model       = amiga_get_model;
        mach_get_hardware_list = amiga_get_hardware_list;
-       arch_gettimeoffset   = amiga_gettimeoffset;

In addition, won't this lead to "function defined statically but not called' warnings?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#39 lore raw

Re: [RFC PATCH 07/13] m68k: amiga: Convert to clocksource API

In reply to Finn Thain

Hi Finn,

Quoted 4 lines · Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

Thanks for your patch!

Quoted 16 lines
arch/m68k/amiga/config.c +3 -0
@@ -17,6 +17,7 @@
 #include <linux/mm.h>
 #include <linux/seq_file.h>
 #include <linux/tty.h>
+#include <linux/clocksource.h>
 #include <linux/console.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
@@ -461,7 +462,30 @@ void __init config_amiga(void)
                *(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
 }
 
+static u64 amiga_read_clk(struct clocksource *cs);
+

arch/m68k/amiga/config.c void __init config_amiga(void) · line 476

Quoted 10 lines
arch/m68k/amiga/config.c +9 -0
+static struct clocksource amiga_clk = {
+       .name   = "ciab",
+       .rating = 250,
+       .read   = amiga_read_clk,
+       .mask   = CLOCKSOURCE_MASK(32),
+       .flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
 static unsigned short jiffy_ticks;
+static u32 clk_total;

Shouldn't clk_total be u64?

Quoted 12 lines
arch/m68k/amiga/config.c +12 -0
+
+static irqreturn_t ciab_timer_handler(int irq, void *data)
+{
+       irq_handler_t timer_routine = data;
+       unsigned long flags;
+
+       local_irq_save(flags);
+       clk_total += jiffy_ticks;
+       local_irq_restore(flags);
+
+       return timer_routine(irq, data);
+}

[...]

Quoted 9 lines
arch/m68k/amiga/config.c +1 -1
-static u32 amiga_gettimeoffset(void)
+static u64 amiga_read_clk(struct clocksource *cs)
 {
        unsigned long flags;
        unsigned short hi, lo, hi2;
@@ -512,14 +537,13 @@ static u32 amiga_gettimeoffset(void)
        if (ticks > jiffy_ticks / 2)
                /* check for pending interrupt */
                if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)

arch/m68k/amiga/config.c static u32 amiga_gettimeoffset(void) · line 546

Quoted 10 lines
arch/m68k/amiga/config.c +2 -3
-                       offset = 10000;
+                       offset = jiffy_ticks;
 
        local_irq_restore(flags);
 
        ticks = jiffy_ticks - ticks;
-       ticks = (10000 * ticks) / jiffy_ticks;
 
-       return (ticks + offset) * 1000;
+       return clk_total + ticks + offset;

... to return a full 64-bit value here?

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
author
#25 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Geert Uytterhoeven
Quoted 10 lines · Geert Uytterhoeven

Hi Finn,

Thanks for your patch!

Quoted 2 lines · Finn Thain

The functions that implement arch_gettimeoffset are re-used by new clocksource drivers in subsequent patches.

Disabling this first affects functionality during bisection, right?

It means that all platforms have to use the 'jiffies' clocksource.

At the end of the series, only apollo, q40, sun3 & sun3x continue to use that clocksource.

Quoted 11 lines
Quoted 11 lines
arch/m68k/amiga/config.c +0 -2
@@ -95,8 +95,6 @@ static char amiga_model_name[13] = "Amiga ";
 static void amiga_sched_init(irq_handler_t handler);
 static void amiga_get_model(char *model);
 static void amiga_get_hardware_list(struct seq_file *m);
-/* amiga specific timer functions */
-static u32 amiga_gettimeoffset(void);
 extern void amiga_mksound(unsigned int count, unsigned int ticks);
 static void amiga_reset(void);
 extern void amiga_init_sound(void);
Quoted 9 lines

arch/m68k/amiga/config.c void __init config_amiga(void) · line 389

Quoted 5 lines
arch/m68k/amiga/config.c +0 -1
@@ -386,7 +384,6 @@ void __init config_amiga(void)
        mach_init_IRQ        = amiga_init_IRQ;
        mach_get_model       = amiga_get_model;
        mach_get_hardware_list = amiga_get_hardware_list;
-       arch_gettimeoffset   = amiga_gettimeoffset;

In addition, won't this lead to "function defined statically but not called' warnings?

I expect so. I haven't compile-tested each step in the series; but I'll do that before I send v2. Thanks for the reminder.

There are no new warnings at the end of the series.

Quoted 5 lines

Gr{oetje,eeting}s,

Geert

author
#40 lore raw

Re: [RFC PATCH 07/13] m68k: amiga: Convert to clocksource API

In reply to Geert Uytterhoeven
Quoted 10 lines · Geert Uytterhoeven

Hi Finn,

Quoted 4 lines · Finn Thain

Add a platform clocksource by adapting the existing arch_gettimeoffset implementation.

Thanks for your patch!

Thanks for your review.

Quoted 14 lines
Quoted 14 lines
arch/m68k/amiga/config.c +1 -0
@@ -17,6 +17,7 @@
 #include <linux/mm.h>
 #include <linux/seq_file.h>
 #include <linux/tty.h>
+#include <linux/clocksource.h>
 #include <linux/console.h>
 #include <linux/rtc.h>
 #include <linux/init.h>
@@ -461,7 +462,30 @@ void __init config_amiga(void)
                *(unsigned char *)ZTWO_VADDR(0xde0002) |= 0x80;
 }
 
Quoted 15 lines

arch/m68k/amiga/config.c void __init config_amiga(void) · line 476

Quoted 12 lines
arch/m68k/amiga/config.c +11 -0
+static u64 amiga_read_clk(struct clocksource *cs);
+
+static struct clocksource amiga_clk = {
+       .name   = "ciab",
+       .rating = 250,
+       .read   = amiga_read_clk,
+       .mask   = CLOCKSOURCE_MASK(32),
+       .flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
 static unsigned short jiffy_ticks;
+static u32 clk_total;

Shouldn't clk_total be u64?

Well, it was intentionally u32, and amiga_clk.mask was intentionally CLOCKSOURCE_MASK(32)...

Quoted 29 lines
Quoted 12 lines
arch/m68k/amiga/config.c +12 -0
+
+static irqreturn_t ciab_timer_handler(int irq, void *data)
+{
+       irq_handler_t timer_routine = data;
+       unsigned long flags;
+
+       local_irq_save(flags);
+       clk_total += jiffy_ticks;
+       local_irq_restore(flags);
+
+       return timer_routine(irq, data);
+}

[...]

Quoted 14 lines
arch/m68k/amiga/config.c +2 -2
-static u32 amiga_gettimeoffset(void)
+static u64 amiga_read_clk(struct clocksource *cs)
 {
        unsigned long flags;
        unsigned short hi, lo, hi2;
@@ -512,14 +537,13 @@ static u32 amiga_gettimeoffset(void)
        if (ticks > jiffy_ticks / 2)
                /* check for pending interrupt */
                if (cia_set_irq(&ciab_base, 0) & CIA_ICR_TA)
-                       offset = 10000;
+                       offset = jiffy_ticks;
 
        local_irq_restore(flags);
 
Quoted 8 lines

arch/m68k/amiga/config.c static u32 amiga_gettimeoffset(void) · line 546

Quoted 5 lines
arch/m68k/amiga/config.c +1 -2
        ticks = jiffy_ticks - ticks;
-       ticks = (10000 * ticks) / jiffy_ticks;
 
-       return (ticks + offset) * 1000;
+       return clk_total + ticks + offset;

... to return a full 64-bit value here?

It's certainly possible. Is it better? It sounds like a question about the cost of wrap-around in the clocksource core vs. the cost of 64-bit additions in the arch code.

Looking at __clocksource_update_freq_scale() there are some consequences to choosing a 32-bit mask --

* For clocksources which have a mask > 32-bit
* we need to limit the max sleep time to have a good
* conversion precision.

I don't know the answer, sorry.

Quoted 5 lines

Gr{oetje,eeting}s,

Geert

#47 lore raw

Re: [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource API

In reply to Finn Thain

Finn,

On Mon, 12 Nov 2018, Finn Thain wrote:

First of all, thanks for tackling this!

arch/m68k/mvme16x/config.c static irqreturn_t mvme16x_abort_int (int irq, void *dev_id) · line 366

Quoted 11 lines
arch/m68k/mvme16x/config.c +9 -0
+static u32 clk_total;
+
+#define PCC_TIMER_CLOCK_FREQ 1000000
+#define PCC_TIMER_CYCLES     (PCC_TIMER_CLOCK_FREQ / HZ)
+
 static irqreturn_t mvme16x_timer_int (int irq, void *dev_id)
 {
+    irq_handler_t tick_handler = dev_id;
+    unsigned long flags;
+
+    local_irq_save(flags);

No need for local_irq_save() here. Interrupt handlers are guaranteed to be called with interrupts disabled.

Quoted 2 lines
     *(volatile unsigned char *)0xfff4201b |= 8;

+ clk_total += PCC_TIMER_CYCLES;

Looking at the read function below, I assume that this magic 0xfff42008 register counts up to PCC_TIMER_CYCLES, which triggers the timer interrupt and then starts from 0 again. And looking at the programming manual actually confirms that assumption (COC is set in the control reg).

arch/m68k/mvme16x/config.c void mvme16x_sched_init (irq_handler_t timer_routine) · line 404

Quoted 8 lines
arch/m68k/mvme16x/config.c +4 -2
-u32 mvme16x_gettimeoffset(void)
+static u64 mvme16x_read_clk(struct clocksource *cs)
 {
-    return (*(volatile u32 *)0xfff42008) * 1000;
+    u32 count = *(volatile u32 *)0xfff42008;
+
+    return clk_total + count;
 }

There is a problem with that approach. Assume the following situation:

				Counter value (HZ = 100)
       local_irq_disable()	
       ...
       ktime_get()		9999
       ....			10000 -> 0 (interrupt is triggered)
       ktime_get()		1

IOW, time goes backwards.

There are two ways to solve that:

1) Take the overflow bits in the timer control register into account,

    which makes time readout even slower because you need to do it like
    this:

    do {
       ovfl = read(TCR1);
       now = read(TCNT1);
    while (ovfl != read(TCR1));
    ....

2) Use Timer2 in freerunning mode which means it will use the full 32bit and then wrap back to 0. That's fine and the clocksource core handles that.

That removes the clk_total thing and just works.

Thanks,

tglx

author
#48 lore raw

Re: [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource API

Quoted 4 lines · Thomas Gleixner

Finn,

First of all, thanks for tackling this!

Happy to help. Thanks for your review.

Quoted 6 lines
Quoted 6 lines
arch/m68k/mvme16x/config.c +5 -0
+static u32 clk_total;
+
+#define PCC_TIMER_CLOCK_FREQ 1000000
+#define PCC_TIMER_CYCLES     (PCC_TIMER_CLOCK_FREQ / HZ)
+
 static irqreturn_t mvme16x_timer_int (int irq, void *dev_id)
Quoted 9 lines

arch/m68k/mvme16x/config.c static irqreturn_t mvme16x_abort_int (int irq, void *dev_id) · line 366

Quoted 5 lines

{

arch/m68k/mvme16x/config.c +4 -0
+    irq_handler_t tick_handler = dev_id;
+    unsigned long flags;
+
+    local_irq_save(flags);

No need for local_irq_save() here. Interrupt handlers are guaranteed to be called with interrupts disabled.

That's not the case on m68k, as I understand it. However, the CPU interrupt level does prevent interrupt handlers from nesting.

Quoted 20 lines
Quoted 2 lines
     *(volatile unsigned char *)0xfff4201b |= 8;

+ clk_total += PCC_TIMER_CYCLES;

Looking at the read function below, I assume that this magic 0xfff42008 register counts up to PCC_TIMER_CYCLES, which triggers the timer interrupt and then starts from 0 again. And looking at the programming manual actually confirms that assumption (COC is set in the control reg).

arch/m68k/mvme16x/config.c void mvme16x_sched_init (irq_handler_t timer_routine) · line 404

Quoted 8 lines
arch/m68k/mvme16x/config.c +4 -2
-u32 mvme16x_gettimeoffset(void)
+static u64 mvme16x_read_clk(struct clocksource *cs)
 {
-    return (*(volatile u32 *)0xfff42008) * 1000;
+    u32 count = *(volatile u32 *)0xfff42008;
+
+    return clk_total + count;
 }

There is a problem with that approach. Assume the following situation:

Quoted 9 lines
				Counter value (HZ = 100)
       local_irq_disable()	
       ...
       ktime_get()		9999
       ....			10000 -> 0 (interrupt is triggered)
       ktime_get()		1

IOW, time goes backwards.

Yes. It's not a new problem. I think hp300 and mvme147 have similar issues.

If the clocksource core is badly affected by this problem then I'll have to address it.

Quoted 12 lines

There are two ways to solve that:

1) Take the overflow bits in the timer control register into account,

    which makes time readout even slower because you need to do it like
    this:

    do {
       ovfl = read(TCR1);
       now = read(TCNT1);
    while (ovfl != read(TCR1));
    ....

How about,

	local_irq_save(flags);
	ovfl = read(TCR1);
	now = read(TCNT1);
	if (ovfl != read(TCR1))
		now = read(TCNT1);

	ticks = clk_total + now;
	offset = (ovfl >> 4) * PCC_TIMER_CYCLES;
	local_irq_restore(flags);

	return offset + ticks;

This has to be synchronized with the interrupt handler because the interrupt handler must clear the overflow counter in TCR1 when it does clk_total += PCC_TIMER_CYCLES;

BTW, there are some synchronization bugs in this patch series that will be addressed in the next submission. They have been fixed in my github repo.

Quoted 7 lines

2) Use Timer2 in freerunning mode which means it will use the full 32bit and then wrap back to 0. That's fine and the clocksource core handles that.

That removes the clk_total thing and just works.

I really like this suggestion!

But I fear it is a change that cannot be checked by inspection. If I wrote it, I'd want to test it, or have someone else test it. (Stephen?)

I wonder if there exists an emulator for MVME 162/166/167/172/177 machines capable of booting Linux...

Quoted 4 lines

Thanks,

tglx

#26 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Finn Thain

Hi Finn,

Am 12.11.2018 um 22:06 schrieb Finn Thain:

Quoted 6 lines · Geert Uytterhoeven
Quoted 5 lines

Hi Finn,

Thanks for your patch!

Quoted 8 lines
Quoted 6 lines · Finn Thain
Quoted 2 lines

The functions that implement arch_gettimeoffset are re-used by new clocksource drivers in subsequent patches.

Disabling this first affects functionality during bisection, right?

It means that all platforms have to use the 'jiffies' clocksource.

So all that happens is timer granularity drops to 10ms, then gets restored by the later patches?

I doubt that would be a large enough regression to matter for bisection, but the way you reuse the arch_gettimeoffset() code for the new read_clock() functions makes reordering of this patch to the end of the series impossible.

Best you can don, under the circumstances.

Cheers,

Michael

author
#27 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

Quoted 14 lines · Michael Schmitz

Hi Finn,

Am 12.11.2018 um 22:06 schrieb Finn Thain:

Quoted 11 lines · Geert Uytterhoeven
Quoted 10 lines

Hi Finn,

Thanks for your patch!

Quoted 2 lines · Finn Thain

The functions that implement arch_gettimeoffset are re-used by new clocksource drivers in subsequent patches.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Disabling this first affects functionality during bisection, right?

It means that all platforms have to use the 'jiffies' clocksource.

So all that happens is timer granularity drops to 10ms, then gets restored by the later patches?

Yes, that was the plan, but I can't confirm that it worked out as I don't have any physical 68k hardware in front of me right now. If you can confirm this on your Atari Falcon, that would be great.

(It appears that a QEMU-emulated Mac does not benefit from having a clocksource that's more accurate than the 'jiffies' clocksource, in spite of "clocksource: Switched to clocksource via1".)

The latest patches can be found at
https://github.com/fthain/linux/commits/mac68k-queue/

Quoted 11 lines

I doubt that would be a large enough regression to matter for bisection, but the way you reuse the arch_gettimeoffset() code for the new read_clock() functions makes reordering of this patch to the end of the series impossible.

Best you can don, under the circumstances.

Cheers,

Michael

author
#3 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Finn Thain

Implementations of arch_gettimeoffset are generally not re-entrant and assume that interrupts have been disabled. Unfortunately this pre-condition got broken in v2.6.32.

Quoted 7 lines
Quoted 2 lines
Fixes 5cfc8ee0bb51 ("ARM: convert arm to arch_gettimeoffset()")

This looks like a sensible fix for -stable backporting. But with m68k converted over it might be time for these two arm platforms to either be converted to the clocksource API or to be dropped..

You could remove the old arch_gettimeoffset API without dropping any platforms.

If no-one converts a given platform to the clocksource API it would mean that the default 'jiffies' clocksource will get used on that platform.

Clock resolution and timer precision would be degraded, but that might not matter.

Anyway, if someone who has this hardware is willing to test a clocksource API conversion, they can let me know and I'll attempt that patch.

#28 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Finn Thain

Hi Finn,

Am 13.11.2018 um 16:14 schrieb Finn Thain:

Quoted 21 lines · Michael Schmitz
Quoted 20 lines

Hi Finn,

Am 12.11.2018 um 22:06 schrieb Finn Thain:

Quoted 15 lines · Geert Uytterhoeven
Quoted 12 lines

Hi Finn,

Thanks for your patch!

Quoted 2 lines · Finn Thain

The functions that implement arch_gettimeoffset are re-used by new clocksource drivers in subsequent patches.

Disabling this first affects functionality during bisection, right?

It means that all platforms have to use the 'jiffies' clocksource.

Quoted 7 lines
Quoted 3 lines

So all that happens is timer granularity drops to 10ms, then gets restored by the later patches?

Yes, that was the plan, but I can't confirm that it worked out as I don't have any physical 68k hardware in front of me right now. If you can confirm this on your Atari Falcon, that would be great.

Will do.

Quoted 3 lines

(It appears that a QEMU-emulated Mac does not benefit from having a clocksource that's more accurate than the 'jiffies' clocksource, in spite of "clocksource: Switched to clocksource via1".)

With the current code, kernel log timestamps have 10 ms resolution on Atari. Time resolution of times reported by initcall_debug is roughly 40 us. I'd expect that changes with falling back to jiffies only. Might be worth a try on QEMU Mac.

Cheers,

Michael

Quoted 3 lines

The latest patches can be found at
https://github.com/fthain/linux/commits/mac68k-queue/

author
#29 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

Quoted 9 lines · Michael Schmitz
Quoted 4 lines

(It appears that a QEMU-emulated Mac does not benefit from having a clocksource that's more accurate than the 'jiffies' clocksource, in spite of "clocksource: Switched to clocksource via1".)

With the current code, kernel log timestamps have 10 ms resolution on Atari. Time resolution of times reported by initcall_debug is roughly 40 us. I'd expect that changes with falling back to jiffies only. Might be worth a try on QEMU Mac.

The initcall debug output shows the same precision as my earlier tests with userland. The VIA timer only gets updated when QEMU wants to update it, which seems to be about every 9765 us. Hence, using the 'jiffies' clocksource would be effectively no regression for a virtual Mac.

#30 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

Hi Finn,

Am 13.11.2018 um 19:15 schrieb Finn Thain:

Quoted 12 lines · Michael Schmitz
Quoted 10 lines
Quoted 5 lines

(It appears that a QEMU-emulated Mac does not benefit from having a clocksource that's more accurate than the 'jiffies' clocksource, in spite of "clocksource: Switched to clocksource via1".)

With the current code, kernel log timestamps have 10 ms resolution on Atari. Time resolution of times reported by initcall_debug is roughly 40 us. I'd expect that changes with falling back to jiffies only. Might be worth a try on QEMU Mac.

Quoted 4 lines

The initcall debug output shows the same precision as my earlier tests with userland. The VIA timer only gets updated when QEMU wants to update it, which seems to be about every 9765 us. Hence, using the 'jiffies' clocksource would be effectively no regression for a virtual Mac.

Running a recent kernel under ARAnyM shows 40 ns resolution so the Atari hardware emulation is a little more complete.

Using that for initial tests, I can confirm that timer resolution is reduced to 10ms after patch 6, and gets restored to 40ns after applying the full series (once clocksource_init runs, that is - the first part of the boot is at 10ms resolution only, a regression compared to with use of arch_gettimeoffset).

Unfortunately, I can't log in at the console with all patches applied. I immediately get the 'login timeout exceeded' message. Weird...

Cheers,

Michael

#4 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Finn Thain
Quoted 18 lines · Finn Thain
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Finn Thain

Implementations of arch_gettimeoffset are generally not re-entrant and assume that interrupts have been disabled. Unfortunately this pre-condition got broken in v2.6.32.

Quoted 7 lines
Quoted 2 lines
Fixes 5cfc8ee0bb51 ("ARM: convert arm to arch_gettimeoffset()")

This looks like a sensible fix for -stable backporting. But with m68k converted over it might be time for these two arm platforms to either be converted to the clocksource API or to be dropped..

You could remove the old arch_gettimeoffset API without dropping any platforms.

Quoted 8 lines

If no-one converts a given platform to the clocksource API it would mean that the default 'jiffies' clocksource will get used on that platform.

Clock resolution and timer precision would be degraded, but that might not matter.

Anyway, if someone who has this hardware is willing to test a clocksource API conversion, they can let me know and I'll attempt that patch.

There's reasons why that's not appropriate - such as not having two separate timers in order to supply a clocksource and separate clock event.

Not all hardware is suited to the clocksource + clockevent idea.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
author
#5 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Finn Thain

You could remove the old arch_gettimeoffset API without dropping any platforms.

If no-one converts a given platform to the clocksource API it would mean that the default 'jiffies' clocksource will get used on that platform.

Clock resolution and timer precision would be degraded, but that might not matter.

Quoted 9 lines
Quoted 2 lines

Anyway, if someone who has this hardware is willing to test a clocksource API conversion, they can let me know and I'll attempt that patch.

There's reasons why that's not appropriate - such as not having two separate timers in order to supply a clocksource and separate clock event.

Not all hardware is suited to the clocksource + clockevent idea.

Sorry, I don't follow.

AFAIK, clocksources and clock event devices are orthogonal concepts. There are platforms with !ARCH_USES_GETTIMEOFFSET && !GENERIC_CLOCKEVENTS (and every other combination).

A clocksource read method just provides a cycle count, and in this sense arch_gettimeoffset() is equivalent to a clocksource.

If these two arm platforms have an existing clock event device which somehow precludes any new clocksources, why doesn't that also render arch_gettimeoffset() impossible?

author
#49 lore raw

Re: [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource API

In reply to Finn Thain
Quoted 18 lines · On Tue, 13 Nov 2018, I wrote:
Quoted 6 lines · Thomas Gleixner
Quoted 6 lines
arch/m68k/mvme16x/config.c +5 -0
+static u32 clk_total;
+
+#define PCC_TIMER_CLOCK_FREQ 1000000
+#define PCC_TIMER_CYCLES     (PCC_TIMER_CLOCK_FREQ / HZ)
+
 static irqreturn_t mvme16x_timer_int (int irq, void *dev_id)
Quoted 9 lines

arch/m68k/mvme16x/config.c static irqreturn_t mvme16x_abort_int (int irq, void *dev_id) · line 366

Quoted 5 lines

{

arch/m68k/mvme16x/config.c +4 -0
+    irq_handler_t tick_handler = dev_id;
+    unsigned long flags;
+
+    local_irq_save(flags);

No need for local_irq_save() here. Interrupt handlers are guaranteed to be called with interrupts disabled.

Quoted 3 lines

That's not the case on m68k, as I understand it. However, the CPU interrupt level does prevent interrupt handlers from nesting.

What I mean by that is, the interrupt level (IPL) prevents interrupt handlers from being re-entered. But a handler can still get interrupted by a higher priority interrupt request. In the past I've had to add defensive locking because of this.

In these patches I've assumed it was possible for some higher priority interrupt handler to perform a clocksource read after the timer handler started executing. Hence the use of local_irq_save/restore.

To be sure, I've just run a quick test and confirmed that the timer handler can indeed get interrupted by the ethernet interrupt handler.

#50 lore raw

Re: [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource APIy

Quoted 29 lines · Finn Thain
Quoted 18 lines · On Tue, 13 Nov 2018, I wrote:
Quoted 6 lines · Thomas Gleixner
Quoted 6 lines
arch/m68k/mvme16x/config.c +5 -0
+static u32 clk_total;
+
+#define PCC_TIMER_CLOCK_FREQ 1000000
+#define PCC_TIMER_CYCLES     (PCC_TIMER_CLOCK_FREQ / HZ)
+
 static irqreturn_t mvme16x_timer_int (int irq, void *dev_id)
Quoted 9 lines

arch/m68k/mvme16x/config.c static irqreturn_t mvme16x_abort_int (int irq, void *dev_id) · line 366

Quoted 5 lines

{

arch/m68k/mvme16x/config.c +4 -0
+    irq_handler_t tick_handler = dev_id;
+    unsigned long flags;
+
+    local_irq_save(flags);

No need for local_irq_save() here. Interrupt handlers are guaranteed to be called with interrupts disabled.

Quoted 3 lines

That's not the case on m68k, as I understand it. However, the CPU interrupt level does prevent interrupt handlers from nesting.

What I mean by that is, the interrupt level (IPL) prevents interrupt handlers from being re-entered. But a handler can still get interrupted by a higher priority interrupt request. In the past I've had to add defensive locking because of this.

Quoted 6 lines

In these patches I've assumed it was possible for some higher priority interrupt handler to perform a clocksource read after the timer handler started executing. Hence the use of local_irq_save/restore.

To be sure, I've just run a quick test and confirmed that the timer handler can indeed get interrupted by the ethernet interrupt handler.

Urgh. Then you have more serious trouble. If the interrupting handler calls any of the time accessor functions then you can actually live lock when the interrupt happens in the middle of the write locked section of the core timekeeping update. So you really want to disable interrupts across the whole timer interrupt function or make sure that the timer interrupt is the highest priority one on the system.

Thanks,

tglx

author
#31 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Michael Schmitz
Quoted 4 lines · Michael Schmitz

Running a recent kernel under ARAnyM shows 40 ns resolution so the Atari hardware emulation is a little more complete.

You mean, 40 us resolution, right?

Quoted 3 lines

Using that for initial tests, I can confirm that timer resolution is reduced to 10ms after patch 6, and gets restored to 40ns after applying the full series

Thanks for testing!

Quoted 4 lines

(once clocksource_init runs, that is - the first part of the boot is at 10ms resolution only, a regression compared to with use of arch_gettimeoffset).

Sounds like a theoretical regression (?)

Is there any need for more precise timers (I mean, better than 40 us) before clocksource_init runs?

Quoted 3 lines

Unfortunately, I can't log in at the console with all patches applied. I immediately get the 'login timeout exceeded' message. Weird...

I didn't see that in my tests... Was this aranym or real hardware or both?

Can you also test tree fbf8405cd982 please?

Quoted 5 lines

Cheers,

Michael

author
#51 lore raw

Re: [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource APIy

In reply to Thomas Gleixner
Quoted 11 lines · Thomas Gleixner
Quoted 10 lines · Finn Thain

What I mean by that is, the interrupt level (IPL) prevents interrupt handlers from being re-entered. But a handler can still get interrupted by a higher priority interrupt request. In the past I've had to add defensive locking because of this.

In these patches I've assumed it was possible for some higher priority interrupt handler to perform a clocksource read after the timer handler started executing. Hence the use of local_irq_save/restore.

Quoted 7 lines
Quoted 2 lines

To be sure, I've just run a quick test and confirmed that the timer handler can indeed get interrupted by the ethernet interrupt handler.

Urgh. Then you have more serious trouble. If the interrupting handler calls any of the time accessor functions then you can actually live lock when the interrupt happens in the middle of the write locked section of the core timekeeping update.

Does this apply to arch_gettimeoffset also? If so, that would mean another bug fix patch for -stable...

Quoted 4 lines

So you really want to disable interrupts across the whole timer interrupt function or make sure that the timer interrupt is the highest priority one on the system.

The timer interrupt priority isn't always what one would hope.

But I can certainly disable interrupts for timer_interrupt() execution (that is, xtime_update() etc.)

Quoted 4 lines

Thanks,

tglx

#6 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Finn Thain
Quoted 23 lines · Finn Thain
Quoted 11 lines · Russell King - ARM Linux
Quoted 10 lines · Finn Thain

You could remove the old arch_gettimeoffset API without dropping any platforms.

If no-one converts a given platform to the clocksource API it would mean that the default 'jiffies' clocksource will get used on that platform.

Clock resolution and timer precision would be degraded, but that might not matter.

Quoted 9 lines
Quoted 2 lines

Anyway, if someone who has this hardware is willing to test a clocksource API conversion, they can let me know and I'll attempt that patch.

There's reasons why that's not appropriate - such as not having two separate timers in order to supply a clocksource and separate clock event.

Not all hardware is suited to the clocksource + clockevent idea.

Quoted 8 lines

Sorry, I don't follow.

AFAIK, clocksources and clock event devices are orthogonal concepts. There are platforms with !ARCH_USES_GETTIMEOFFSET && !GENERIC_CLOCKEVENTS (and every other combination).

A clocksource read method just provides a cycle count, and in this sense arch_gettimeoffset() is equivalent to a clocksource.

A clocksource provides a cycle counter that monotonically changes and does not wrap between clockevent events.

A clock event is responsible for providing events to the system when some work is needing to be done, limited by the wrap interval of the clocksource.

Each time the clock event triggers an interrupt, the clocksource is read to determine how much time has passed, using:

	count = (new_value - old_value) & available_bits
	nanosecs = count * scale >> shift;

If you try to combine the clocksource and clockevent because you only have a single counter, and the counter has the behaviour of:
- counting down towards zero
- when reaching zero, triggers an interrupt, and reloads with N

then this provides your clockevent, but you can't use this as a clock source, because each time you receive an interrupt and try to read the counter value, it will be approximately the same value. This means that the above calculation fails to register the correct number of nanoseconds passing. Hence, this does not work.

Also note where I said above that the clock event device must be able to provide an interrupt _before_ the clocksource wraps - clearly with such a timer, that is utterly impossible.

The simple solution is to not use such a counter as the clocksource, which means you fall back to using the jiffies clocksource, and your timekeeping has jiffy resolution - so 10ms, or possibly 1ms if you want a 1kHz timer interval. For most applications, that's simply way to coarse, as was realised in the very early days of Linux.

If only there was a way to interpolate between timer interrupts... which is exactly what arch_gettimeoffset() does, and is a historical reminant of the pre-clocksource/clockevent days of the kernel - but it is the only way to get better resolution from this sort of setup.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#32 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Finn Thain

Hi Finn,

Quoted 6 lines · Finn Thain
Quoted 3 lines · Michael Schmitz

Running a recent kernel under ARAnyM shows 40 ns resolution so the Atari hardware emulation is a little more complete.

You mean, 40 us resolution, right?

Sorry, typo. Should have been us of course.

Quoted 6 lines
Quoted 4 lines

Using that for initial tests, I can confirm that timer resolution is reduced to 10ms after patch 6, and gets restored to 40ns after applying the full series

Thanks for testing!

Quoted 8 lines
Quoted 4 lines

(once clocksource_init runs, that is - the first part of the boot is at 10ms resolution only, a regression compared to with use of arch_gettimeoffset).

Sounds like a theoretical regression (?)

Is there any need for more precise timers (I mean, better than 40 us) before clocksource_init runs?

I don't think so, given that we can run just fine with 10 ms resolution.

Quoted 5 lines
Quoted 4 lines

Unfortunately, I can't log in at the console with all patches applied. I immediately get the 'login timeout exceeded' message. Weird...

I didn't see that in my tests... Was this aranym or real hardware or both?

ARAnyM only so far.

Quoted 3 lines

Can you also test tree fbf8405cd982 please?

My tests were on c606b5cf902 in case it wasn't clear. I've now seen fbf8405cd982, one moment please ...

That one does appear to work - different versions of ARAnyM, and different userland versions though. I'll test that again with the setup that saw c606b5cf902 fail.

Cheers,

    Michael

#7 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Russell King - ARM Linux
Quoted 47 lines · Russell King - ARM Linux
Quoted 20 lines · Finn Thain
Quoted 10 lines · Russell King - ARM Linux
Quoted 9 lines · Finn Thain

You could remove the old arch_gettimeoffset API without dropping any platforms.

If no-one converts a given platform to the clocksource API it would mean that the default 'jiffies' clocksource will get used on that platform.

Clock resolution and timer precision would be degraded, but that might not matter.

Quoted 8 lines
Quoted 2 lines

Anyway, if someone who has this hardware is willing to test a clocksource API conversion, they can let me know and I'll attempt that patch.

There's reasons why that's not appropriate - such as not having two separate timers in order to supply a clocksource and separate clock event.

Not all hardware is suited to the clocksource + clockevent idea.

Quoted 8 lines

Sorry, I don't follow.

AFAIK, clocksources and clock event devices are orthogonal concepts. There are platforms with !ARCH_USES_GETTIMEOFFSET && !GENERIC_CLOCKEVENTS (and every other combination).

A clocksource read method just provides a cycle count, and in this sense arch_gettimeoffset() is equivalent to a clocksource.

A clocksource provides a cycle counter that monotonically changes and does not wrap between clockevent events.

A clock event is responsible for providing events to the system when some work is needing to be done, limited by the wrap interval of the clocksource.

Each time the clock event triggers an interrupt, the clocksource is read to determine how much time has passed, using:

	count = (new_value - old_value) & available_bits
	nanosecs = count * scale >> shift;

If you try to combine the clocksource and clockevent because you only have a single counter, and the counter has the behaviour of:
- counting down towards zero
- when reaching zero, triggers an interrupt, and reloads with N

Quoted 5 lines

then this provides your clockevent, but you can't use this as a clock source, because each time you receive an interrupt and try to read the counter value, it will be approximately the same value. This means that the above calculation fails to register the correct number of nanoseconds passing. Hence, this does not work.

So we'd still have to use jiffies + interpolation from the current timer rundown counter as clocksource (since that will be monotonous and won't wrap)?

The way Finn did the clocksource for m68k, the clocksource counter does behave as it should (monotonous, doesn't wrap) at least so far as I've tested. Using the same timer for clocksource and clock events will degrade timekeeping based on timer events to jiffies resolution, as you point out. That would already have been the case before, so no gain in resolution. Other timekeeping would have worked at higher resolution before (interpolating through arch_gettimeoffset) just the same as now (interpolating through clocksource reads). Finn's clocksource read code essentially is arch_gettimeoffset under a new name.

Are you saying that's not possible on arm, because the current timer rundown counter can't be read while the timer is running?

If I were to run a second timer at higher rate for clocksource, but keeping the 10 ms timer as clock event (could easily do that by using timer D on Atari Falcon) - how would that improve my timekeeping? Clock events still only happen 10 ms apart ...

Cheers,

??? Michael

Quoted 16 lines

Also note where I said above that the clock event device must be able to provide an interrupt _before_ the clocksource wraps - clearly with such a timer, that is utterly impossible.

The simple solution is to not use such a counter as the clocksource, which means you fall back to using the jiffies clocksource, and your timekeeping has jiffy resolution - so 10ms, or possibly 1ms if you want a 1kHz timer interval. For most applications, that's simply way to coarse, as was realised in the very early days of Linux.

If only there was a way to interpolate between timer interrupts... which is exactly what arch_gettimeoffset() does, and is a historical reminant of the pre-clocksource/clockevent days of the kernel - but it is the only way to get better resolution from this sort of setup.

#33 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Michael Schmitz

Hi Finn,

Am 14.11.2018 um 14:08 schrieb Michael Schmitz:

Quoted 8 lines
Quoted 2 lines

Can you also test tree fbf8405cd982 please?

My tests were on c606b5cf902 in case it wasn't clear. I've now seen fbf8405cd982, one moment please ...

That one does appear to work - different versions of ARAnyM, and different userland versions though. I'll test that again with the setup that saw c606b5cf902 fail.

Still fails on that emulator / userland.

Cheers,

Michael

Quoted 7 lines

Cheers,

Michael

author
#10 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Russell King - ARM Linux
Quoted 35 lines · Russell King - ARM Linux

A clocksource provides a cycle counter that monotonically changes and does not wrap between clockevent events.

A clock event is responsible for providing events to the system when some work is needing to be done, limited by the wrap interval of the clocksource.

Each time the clock event triggers an interrupt, the clocksource is read to determine how much time has passed, using:

	count = (new_value - old_value) & available_bits
	nanosecs = count * scale >> shift;

If you try to combine the clocksource and clockevent because you only have a single counter, and the counter has the behaviour of:
- counting down towards zero
- when reaching zero, triggers an interrupt, and reloads with N

then this provides your clockevent, but you can't use this as a clock source, because each time you receive an interrupt and try to read the counter value, it will be approximately the same value. This means that the above calculation fails to register the correct number of nanoseconds passing. Hence, this does not work.

Also note where I said above that the clock event device must be able to provide an interrupt _before_ the clocksource wraps - clearly with such a timer, that is utterly impossible.

The simple solution is to not use such a counter as the clocksource, which means you fall back to using the jiffies clocksource, and your timekeeping has jiffy resolution - so 10ms, or possibly 1ms if you want a 1kHz timer interval. For most applications, that's simply way to coarse, as was realised in the very early days of Linux.

Quoted 5 lines

If only there was a way to interpolate between timer interrupts... which is exactly what arch_gettimeoffset() does, and is a historical reminant of the pre-clocksource/clockevent days of the kernel - but it is the only way to get better resolution from this sort of setup.

Both of the platforms in question (RPC and EBSA110) have not defined(CONFIG_GENERIC_CLOCKEVENTS) and have not defined any struct clock_event_device, AFAICT.

So, even assuming that you're right about the limitations of single-timer platforms in general, removal of arch_gettimeoffset wouldn't require the removal of any platforms, AFAICT.

#8 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Michael Schmitz
Quoted 9 lines · Michael Schmitz

So we'd still have to use jiffies + interpolation from the current timer rundown counter as clocksource (since that will be monotonous and won't wrap)?

The way Finn did the clocksource for m68k, the clocksource counter does behave as it should (monotonous, doesn't wrap) at least so far as I've tested. Using the same timer for clocksource and clock events will degrade timekeeping based on timer events to jiffies resolution, as you point out. That would already have been the case before, so no gain in resolution.

... and that is where you are wrong.

RPC, for example, has gettimeofday() resolution of 500ns. Removing gettimeoffset() will result in a resolution of 1/HZ since there is no longer any interpolation between interrupts.

Quoted 4 lines

Other timekeeping would have worked at higher resolution before (interpolating through arch_gettimeoffset) just the same as now (interpolating through clocksource reads). Finn's clocksource read code essentially is arch_gettimeoffset under a new name.

Where is this code - all I've seen is code adding IRQ exclusion in the gettimeoffset method. If some other solution is being proposed, then it's no good beating about the bush - show the damn code, and then that can be considered.

However, what has been said in this thread is basically "remove the gettimeoffset method", which is _not_ acceptable, it will cause gettimeofday() on these platforms to lose resolution, which is a user visible REGRESSION, plain and simple.

If what is actually meant is "we have a replacement for gettimeoffset" then, and I'm sure we all know this, there needs to be a patch proposed showing what is being proposed, rather than waffling around the issue.

Quoted 7 lines

Are you saying that's not possible on arm, because the current timer rundown counter can't be read while the timer is running?

If I were to run a second timer at higher rate for clocksource, but keeping the 10 ms timer as clock event (could easily do that by using timer D on Atari Falcon) - how would that improve my timekeeping? Clock events still only happen 10 ms apart ...

Ah, I think you're talking about something else.

You seem to be talking about what happens when time keeping interrupts happen.

I'm talking about the resolution of gettimeofday() and the other interfaces that are used (eg) for packet capture timestamping and the like - the _user_ visible effects of the timekeeping system.

With the existing implementation, all these have better-than-jiffy resolution - in the case of RPC, that's 500ns, rather than 10ms which would be the case without gettimeoffset(). Removing gettimeoffset() as Finn has proposed without preserving that resolution is simply completely unacceptable.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#18 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Finn Thain
Quoted 3 lines · Finn Thain

Implementations of arch_gettimeoffset are generally not re-entrant and assume that interrupts have been disabled. Unfortunately this pre-condition got broken in v2.6.32.

To me, it looks way worse than what you think.

The original code sequence before conversion to arch_gettimeoffset() was:

1. lock (inc. disabling IRQs)
2. read gettimeoffset correction
3. add offset to current xtime
4. unlock

This means there is no chance for a timer interrupt to happen between reading the current offset and adding it to the current kernel time. If the timer does roll over, then the interrupt will remain pending, so the whole "read offset and add to xtime" is one atomic block and we can use the pending interrupt to indicate whether the timer has rolled over and apply the appropriate offset correction.

With the arch_gettimeoffset() code, that changes:

1. read clocksource (which will be jiffies)
2. compute clocksource delta
3. increment nanoseconds
4. add gettimeoffset correction

If we receive a timer interrupt part-way through this, for example, between 2 and 3, then jiffies will increment (via do_timer()) and the interrupt will be cleared. This means that the check in ioc_timer_gettimeoffset() for a pending interrupt, for example, will be false, and we will not know that an interrupt has happened.

So, unless I'm missing something, commit 5cfc8ee0bb51 well and truely broke the accuracy of timekeeping on these platforms, and will result in timekeeping spontaneously jumping backwards. I had been wondering why NTP had become less stable on EBSA110, but never investigated.

However, that still does not justify blowing away this functionality without replacement, as Finn has been proposing.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#11 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Finn Thain
Quoted 43 lines · Finn Thain
Quoted 35 lines · Russell King - ARM Linux

A clocksource provides a cycle counter that monotonically changes and does not wrap between clockevent events.

A clock event is responsible for providing events to the system when some work is needing to be done, limited by the wrap interval of the clocksource.

Each time the clock event triggers an interrupt, the clocksource is read to determine how much time has passed, using:

	count = (new_value - old_value) & available_bits
	nanosecs = count * scale >> shift;

If you try to combine the clocksource and clockevent because you only have a single counter, and the counter has the behaviour of:
- counting down towards zero
- when reaching zero, triggers an interrupt, and reloads with N

then this provides your clockevent, but you can't use this as a clock source, because each time you receive an interrupt and try to read the counter value, it will be approximately the same value. This means that the above calculation fails to register the correct number of nanoseconds passing. Hence, this does not work.

Also note where I said above that the clock event device must be able to provide an interrupt _before_ the clocksource wraps - clearly with such a timer, that is utterly impossible.

The simple solution is to not use such a counter as the clocksource, which means you fall back to using the jiffies clocksource, and your timekeeping has jiffy resolution - so 10ms, or possibly 1ms if you want a 1kHz timer interval. For most applications, that's simply way to coarse, as was realised in the very early days of Linux.

Quoted 5 lines

If only there was a way to interpolate between timer interrupts... which is exactly what arch_gettimeoffset() does, and is a historical reminant of the pre-clocksource/clockevent days of the kernel - but it is the only way to get better resolution from this sort of setup.

Quoted 3 lines

Both of the platforms in question (RPC and EBSA110) have not defined(CONFIG_GENERIC_CLOCKEVENTS) and have not defined any struct clock_event_device, AFAICT.

Correct, because they don't use clockevents. This is pre-clocksource, pre-clockevent code, it uses the old timekeeping infrastructure, which is xtime_update() and providing a gettimeoffset implementation.

Quoted 3 lines

So, even assuming that you're right about the limitations of single-timer platforms in general, removal of arch_gettimeoffset wouldn't require the removal of any platforms, AFAICT.

I haven't proposed removing platforms.

I'm just objecting to the idea of removing arch_gettimeoffset(), thereby causing a regression by changing the resolution of gettimeofday() without any sign of equivalent functionality.

However, I now see (having searched mailing lists) what you are trying to do - you have _not_ copied me or the mailing lists I'm on with your cover message, so I'm *totally* lacking in the context of your patch series, particularly where you are converting m68k to use clocksources without needing the gettimeoffset() stuff.

You have failed to explain that in this thread - probably assuming that I've read your cover message. I haven't until now, because you never sent it to me or the linux-arm-kernel mailing list.

I have found this thread _very_ frustrating, and frankly a waste of my time discussing the finer points because of this lack of context. Please ensure that if you're going to be sending a patch series, that the cover message at least finds its way to the intended audience of your patches, so that everyone has the context they need when looking at (eg) the single patch they may receive.

Alternatively, if someone raises a problem with the patch, and you _know_ you haven't done that, then please consider informing them where they can get more context, eg, by providing a link to your archived cover message. It would help avoid misunderstandings.

Thanks.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#12 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

Hi Russell,

Quoted 28 lines · Russell King - ARM Linux
Quoted 3 lines · Finn Thain

So, even assuming that you're right about the limitations of single-timer platforms in general, removal of arch_gettimeoffset wouldn't require the removal of any platforms, AFAICT.

I haven't proposed removing platforms.

I'm just objecting to the idea of removing arch_gettimeoffset(), thereby causing a regression by changing the resolution of gettimeofday() without any sign of equivalent functionality.

However, I now see (having searched mailing lists) what you are trying to do - you have _not_ copied me or the mailing lists I'm on with your cover message, so I'm *totally* lacking in the context of your patch series, particularly where you are converting m68k to use clocksources without needing the gettimeoffset() stuff.

You have failed to explain that in this thread - probably assuming that I've read your cover message. I haven't until now, because you never sent it to me or the linux-arm-kernel mailing list.

I have found this thread _very_ frustrating, and frankly a waste of my time discussing the finer points because of this lack of context. Please ensure that if you're going to be sending a patch series, that the cover message at least finds its way to the intended audience of your patches, so that everyone has the context they need when looking at (eg) the single patch they may receive.

Quoted 4 lines

Alternatively, if someone raises a problem with the patch, and you _know_ you haven't done that, then please consider informing them where they can get more context, eg, by providing a link to your archived cover message. It would help avoid misunderstandings.

Sorry for the lack of context.
The real trigger was also not explained in the cover message, and was a the threat to remove platforms not using modern timekeeping APIs, cfr.
"Removing support for old hardware from the kernel"
(https://lwn.net/Articles/769468/).

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#13 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

Quoted 37 lines · Geert Uytterhoeven

Hi Russell,

Quoted 28 lines · Russell King - ARM Linux
Quoted 3 lines · Finn Thain

So, even assuming that you're right about the limitations of single-timer platforms in general, removal of arch_gettimeoffset wouldn't require the removal of any platforms, AFAICT.

I haven't proposed removing platforms.

I'm just objecting to the idea of removing arch_gettimeoffset(), thereby causing a regression by changing the resolution of gettimeofday() without any sign of equivalent functionality.

However, I now see (having searched mailing lists) what you are trying to do - you have _not_ copied me or the mailing lists I'm on with your cover message, so I'm *totally* lacking in the context of your patch series, particularly where you are converting m68k to use clocksources without needing the gettimeoffset() stuff.

You have failed to explain that in this thread - probably assuming that I've read your cover message. I haven't until now, because you never sent it to me or the linux-arm-kernel mailing list.

I have found this thread _very_ frustrating, and frankly a waste of my time discussing the finer points because of this lack of context. Please ensure that if you're going to be sending a patch series, that the cover message at least finds its way to the intended audience of your patches, so that everyone has the context they need when looking at (eg) the single patch they may receive.

Quoted 4 lines

Alternatively, if someone raises a problem with the patch, and you _know_ you haven't done that, then please consider informing them where they can get more context, eg, by providing a link to your archived cover message. It would help avoid misunderstandings.

Quoted 5 lines

Sorry for the lack of context.
The real trigger was also not explained in the cover message, and was a the threat to remove platforms not using modern timekeeping APIs, cfr.
"Removing support for old hardware from the kernel"
(https://lwn.net/Articles/769468/).

And naturally, because kernel developers are oh so great at communication, that decision has been communicated to those affected by it. *NOT*.

Clearly there is a need for much better communication. We're better at it when dealing with patches, but not when it comes to physical meetings.

Maybe when some decision like "we're going to kill stuff still using the old gettimeoffset API" then _someone_ needs to identify which platforms are using that and make sure that those maintainers know about that decision, much the same way that if a patch were to touch the gettimeoffset API, we'd make damn sure that such a patch went to those affected by the change.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
#34 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Michael Schmitz

Hi Finn,

Quoted 5 lines · Michael Schmitz

Hi Finn,

Am 14.11.2018 um 14:08 schrieb Michael Schmitz:

Quoted 2 lines
Quoted 2 lines

Can you also test tree fbf8405cd982 please?

Quoted 9 lines
Quoted 6 lines

My tests were on c606b5cf902 in case it wasn't clear. I've now seen fbf8405cd982, one moment please ...

That one does appear to work - different versions of ARAnyM, and different userland versions though. I'll test that again with the setup that saw c606b5cf902 fail.

Still fails on that emulator / userland.

Must be a quirk of ARAnyM 1.0.2 (or powerpc). With 0.9.15 on x86_64, it's fine.

I'm sufficiently convinced to try this on actual hardware now.

Cheers,

    Michael

#9 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Russell King - ARM Linux
Quoted 4 lines · Russell King - ARM Linux
Quoted 4 lines

Are you saying that's not possible on arm, because the current timer rundown counter can't be read while the timer is running?

Quoted 8 lines
Quoted 4 lines

If I were to run a second timer at higher rate for clocksource, but keeping the 10 ms timer as clock event (could easily do that by using timer D on Atari Falcon) - how would that improve my timekeeping? Clock events still only happen 10 ms apart ...

Ah, I think you're talking about something else.

You seem to be talking about what happens when time keeping interrupts happen.

That's what I understood your comment was about.

Quoted 9 lines

I'm talking about the resolution of gettimeofday() and the other interfaces that are used (eg) for packet capture timestamping and the like - the _user_ visible effects of the timekeeping system.

With the existing implementation, all these have better-than-jiffy resolution - in the case of RPC, that's 500ns, rather than 10ms which would be the case without gettimeoffset(). Removing gettimeoffset() as Finn has proposed without preserving that resolution is simply completely unacceptable.

I agree - but Finn had also offered to supply patches to arm that would have added a clocksource_read() function very much like for those m68k platforms that had used gettimeoffset(). I wondered what reason there was for these not to work on arm

I now realize you'd never seen that offer.

The proposal to drop architectures still relying on arch_gettimeoffset() had been raising enough of a response on linux-m68k to make me conclude that same proposal had been kicked on to other arch MLs affected as well. I'm a bit naive that way.

Now your criticism of arch_gettimeoffset() (missing timer rollover because the timer interrupt has been cleared by the interrupt handler) still stands. I just can't find the offset() functions shown in the 5cfc8ee0bb51 patch. Any hints?

Cheers,

??? Michael

author
#14 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Russell King - ARM Linux
Quoted 6 lines · Russell King - ARM Linux

However, I now see (having searched mailing lists) what you are trying to do - you have _not_ copied me or the mailing lists I'm on with your cover message, so I'm *totally* lacking in the context of your patch series, particularly where you are converting m68k to use clocksources without needing the gettimeoffset() stuff.

True. I should have included all interested parties in the recipients of the cover letter. My bad.

Quoted 2 lines

You have failed to explain that in this thread - probably assuming that I've read your cover message.

I offered to write a patch to add a clocksource to replace the arch_gettimeoffset functionality for RPC and EBSA110.

You even replied to that offer.

I did not propose degrading functionality while there is someone able to test modernization patches (assuming there is...).

Would you consider merging untested modernization patches for the arch_gettimeoffset API?

Quoted 5 lines

I haven't until now, because you never sent it to me or the linux-arm-kernel mailing list.

I have found this thread _very_ frustrating, and frankly a waste of my time discussing the finer points because of this lack of context.

Sorry for any frustration I've caused you.

The thread went way off-topic when Christoph took the opportunity to suggest the removal of RPC and EBSA110. That doesn't interest me.

My interest remains API modernization. The actual patches I've sent are intended to modernize the clock API *without* degrading any functionality.

Quoted 5 lines

Please ensure that if you're going to be sending a patch series, that the cover message at least finds its way to the intended audience of your patches, so that everyone has the context they need when looking at (eg) the single patch they may receive.

OK. I'll have to improve my patch submission scripts.

Quoted 8 lines

Alternatively, if someone raises a problem with the patch, and you _know_ you haven't done that, then please consider informing them where they can get more context, eg, by providing a link to your archived cover message. It would help avoid misunderstandings.

Thanks.

author
#35 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Michael Schmitz
Quoted 11 lines · Michael Schmitz

Hi Finn,

Quoted 8 lines · Michael Schmitz

Hi Finn,

Am 14.11.2018 um 14:08 schrieb Michael Schmitz:

Quoted 5 lines
Quoted 2 lines

Can you also test tree fbf8405cd982 please?

My tests were on c606b5cf902 in case it wasn't clear. I've now seen fbf8405cd982, one moment please ...

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

That one does appear to work - different versions of ARAnyM, and different userland versions though. I'll test that again with the setup that saw c606b5cf902 fail.

Still fails on that emulator / userland.

Must be a quirk of ARAnyM 1.0.2 (or powerpc). With 0.9.15 on x86_64, it's fine.

Could be a regression in aranym?

Maybe it's worth trying 0.9.15 on the powerpc host?

Quoted 2 lines

I'm sufficiently convinced to try this on actual hardware now.

Thanks!

Quoted 6 lines

Cheers,

??? Michael

#36 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

In reply to Michael Schmitz

Hi Finn

Am 15.11.2018 um 12:54 schrieb Michael Schmitz:

Quoted 10 lines
Quoted 6 lines
Quoted 3 lines

That one does appear to work - different versions of ARAnyM, and different userland versions though. I'll test that again with the setup that saw c606b5cf902 fail.

Still fails on that emulator / userland.

Must be a quirk of ARAnyM 1.0.2 (or powerpc). With 0.9.15 on x86_64, it's fine.

I'm sufficiently convinced to try this on actual hardware now.

Well, it sort of works - I've seen one login timeout on the console under load (less than 10 seconds after typing in the password), but most attempts went OK. Couldn't log in through SSH without increasing fatal: Timeout before authenticationthe LoginGraceTime parameter though.

I usually get reliable login using ssh key files with the default setting of 120 seconds (takes around 90 to 100 seconds to complete). With your patch, even increasing this to 4800 doesn't result in reliable login.

The error I see in the logs is 'fatal: Timeout before authentication'.

Cheers,

Michael

author
#37 lore raw

Re: [RFC PATCH 06/13] m68k: Drop ARCH_USES_GETTIMEOFFSET

Quoted 6 lines · Michael Schmitz

Well, it sort of works - I've seen one login timeout on the console under load (less than 10 seconds after typing in the password), but most attempts went OK. Couldn't log in through SSH without increasing fatal:
Timeout before authenticationthe LoginGraceTime parameter though.

Quoted 7 lines

I usually get reliable login using ssh key files with the default setting of 120 seconds (takes around 90 to 100 seconds to complete). With your patch, even increasing this to 4800 doesn't result in reliable login.

The error I see in the logs is 'fatal: Timeout before authentication'.

Weird. Let's try 2942e9fd3e57. Please send me your .config so I can send you a kernel binary. (I don't trust gcc 4.6 on m68k...)

Quoted 5 lines

Cheers,

Michael

#15 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

In reply to Finn Thain
Quoted 2 lines · Finn Thain

The thread went way off-topic when Christoph took the opportunity to suggest the removal of RPC and EBSA110. That doesn't interest me.

I suspect that is the right solution - I've been trying to get 4.19 to boot on my RPC and it's proving very difficult for several reasons, not limited to the HDD seeming to be throwing the odd disk error, as well as the kernel being rather large (a 4.19 kernel is 2.7M compressed as opposed to 2.6.29 being 1.2M compressed for the equivalent configuration.)

Given that memory on the RPC is not contiguous, that probably means an uncompressed kernel overflows the size of the first memory bank, so there's probably no hope for modern kernels to boot on the machine.

The EBSA110 is probably in a similar boat - I don't remember whether it had 16MB or 32MB as the maximal amount of memory, but memory was getting tight with some kernels even running a minimalist userspace.

So, it's probably time to say goodbyte to the kernel support for these platforms.

Signature · 3 lines
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
author
#16 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

Quoted 8 lines · Russell King - ARM Linux

The EBSA110 is probably in a similar boat - I don't remember whether it had 16MB or 32MB as the maximal amount of memory, but memory was getting tight with some kernels even running a minimalist userspace.

So, it's probably time to say goodbyte to the kernel support for these platforms.

Your call.

Note that removing code from mainline won't help users obtain older, smaller, -stable kernel releases, free from the bug we were discussing. (The bug appeared in Linux v2.6.32.)

BTW, if you did want to boot Linux on a 16 MB system, you do have some options.

https://lwn.net/Articles/741494/
https://lwn.net/Articles/608945/
https://tiny.wiki.kernel.org/

Contributing to this kind of effort probably has value for IoT deployments. I suspect it also cuts a small amount of bloat from a large number of other Linux systems.

#17 lore raw

Re: [RFC PATCH 01/13] arm: Fix mutual exclusion in arch_gettimeoffset

Hi Finn,

Am 17.11.2018 um 11:49 schrieb Finn Thain:

Quoted 20 lines · Russell King - ARM Linux
Quoted 9 lines

The EBSA110 is probably in a similar boat - I don't remember whether it had 16MB or 32MB as the maximal amount of memory, but memory was getting tight with some kernels even running a minimalist userspace.

So, it's probably time to say goodbyte to the kernel support for these platforms.

Your call.

Note that removing code from mainline won't help users obtain older, smaller, -stable kernel releases, free from the bug we were discussing. (The bug appeared in Linux v2.6.32.)

BTW, if you did want to boot Linux on a 16 MB system, you do have some options.

Quoted 7 lines

https://lwn.net/Articles/741494/
https://lwn.net/Articles/608945/
https://tiny.wiki.kernel.org/

Contributing to this kind of effort probably has value for IoT deployments. I suspect it also cuts a small amount of bloat from a large number of other Linux systems.

I boot 4.19 on a system with 14 MB RAM - 10 MB remain for user space once the kernel loads. After remote login, 4 MB of that remain free for buffers or user code (1.5 MB swapped).
That's with sysvinit - Christian tried to boot a systemd userland on his Falcon once, and ran out of memory before swap could be activated.

I shouldn't say 16 or 32 MB are hopeless. And the 2.6 kernels were a lot more sluggish to my recollection.

Cheers,

Michael

#52 lore raw

Re: [RFC PATCH 13/13] m68k: mvme16x: Convert to clocksource APIy

In reply to Finn Thain

Finn,

Quoted 8 lines · Finn Thain
Quoted 4 lines · Thomas Gleixner

Urgh. Then you have more serious trouble. If the interrupting handler calls any of the time accessor functions then you can actually live lock when the interrupt happens in the middle of the write locked section of the core timekeeping update.

Does this apply to arch_gettimeoffset also? If so, that would mean another bug fix patch for -stable...

arch_gettimeoffset() can be called from any context. The only interrupt which can affect it is the timer interrupt. As m68k are all UP machines this is not a problem because:

ktime_get()

     do {
        seq = read_seqcount_begin(tk.seq);
	nsec = .... + arch_gettimeoffset();
     } while (seqcount_retry(tk.seq);

and the timer interrupt does:

  arch_timeoffset += value;
  ...
    xtime_update()
      ...
        write_seqcount_begin(tk.seq);
        ....
        write_seqcount_end(tk.seq);

So where ever the timer interrupt hits inside of ktime_get() or any other accessor the seqcount will make it retry, so the result is always consistent.

For SMP that would be a different story.

Quoted 9 lines
Quoted 4 lines

So you really want to disable interrupts across the whole timer interrupt function or make sure that the timer interrupt is the highest priority one on the system.

The timer interrupt priority isn't always what one would hope.

But I can certainly disable interrupts for timer_interrupt() execution (that is, xtime_update() etc.)

Oh yes, you should.

Thanks,

tglx