Skip to contentSkip to conversation

ARM: S5PV310: Implement kernel timers using MCT

PATCH Superseded Kukjin Kim 2 participants 5 messages Jan 4, 2011 – Jan 10, 2011

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Kukjin Kim

author
#0 lore raw

PATCH v2 1/1 ARM: S5PV310: Implement kernel timers using MCT

From: Changhwan Youn <[email protected]>

The Multi-Core Timer(MCT) of S5PV310 is designed for implementing clock source timer and clock event timers. This patch implements 1 clock source timer with 64 bit free running counter of MCT and 2 clock event timers with two of 31-bit tick counters.

---
Changes since v1:
- Addressed comments from Russell King (implemented global timer, used local timer and so on)

- Fixed small things

 arch/arm/Kconfig                              |    2 +-
 arch/arm/mach-s5pv310/Kconfig                 |    5 +
 arch/arm/mach-s5pv310/Makefile                |   10 +-
 arch/arm/mach-s5pv310/include/mach/regs-mct.h |   58 +++
 arch/arm/mach-s5pv310/mct.c                   |  492 +++++++++++++++++++++++++
 5 files changed, 564 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/mach-s5pv310/include/mach/regs-mct.h
 create mode 100644 arch/arm/mach-s5pv310/mct.c
arch/arm/Kconfig +1 -1
index d56d21c..d9ee300 100644
@@ -1291,7 +1291,7 @@ config LOCAL_TIMERS
 	bool "Use local timer interrupts"
 	depends on SMP
 	default y
-	select HAVE_ARM_TWD
+	select HAVE_ARM_TWD if !S5PV310_MCT
 	help
 	  Enable support for local timers on SMP platforms, rather then the
 	  legacy IPI broadcast method.  Local timers allows the system
arch/arm/mach-s5pv310/Kconfig +5 -0
index 1150b36..5fecf1b 100644
@@ -14,6 +14,11 @@ config CPU_S5PV310
 	help
 	  Enable S5PV310 CPU support
 
+config S5PV310_MCT
+	bool "Kernel timer support by MCT"
+	help
+	  Use MCT (Multi Core Timer) as kernel timers
+
 config S5PV310_SETUP_I2C1
 	bool
 	help
arch/arm/mach-s5pv310/Makefile +8 -2
index 84afc64..5ca7645 100644
@@ -13,10 +13,16 @@ obj-				:=
 # Core support for S5PV310 system
 
 obj-$(CONFIG_CPU_S5PV310)	+= cpu.o init.o clock.o irq-combiner.o
-obj-$(CONFIG_CPU_S5PV310)	+= setup-i2c0.o time.o gpiolib.o irq-eint.o
+obj-$(CONFIG_CPU_S5PV310)	+= setup-i2c0.o gpiolib.o irq-eint.o
 
-obj-$(CONFIG_SMP)		+= platsmp.o headsmp.o
+ifeq ($(CONFIG_S5PV310_MCT),y)
+obj-y				+= mct.o
+else
+obj-y				+= time.o
 obj-$(CONFIG_LOCAL_TIMERS)	+= localtimer.o
+endif
+
+obj-$(CONFIG_SMP)		+= platsmp.o headsmp.o
 obj-$(CONFIG_HOTPLUG_CPU)	+= hotplug.o
 
 # machine support
arch/arm/mach-s5pv310/include/mach/regs-mct.h new file +58 -0

58 lines not on this page · raw message

arch/arm/mach-s5pv310/mct.c new file +492 -0

492 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#1 lore raw

PATCH v2 1/1 ARM: S5PV310: Implement kernel timers using MCT

Quoted 6 lines · Kukjin Kim

From: Changhwan Youn <[email protected]>

The Multi-Core Timer(MCT) of S5PV310 is designed for implementing clock source timer and clock event timers. This patch implements 1 clock source timer with 64 bit free running counter of MCT and 2 clock event timers with two of 31-bit tick counters.

I want to wait until after this merge window before commenting too much on this; some of this patch will be impacted by changes in this merge window.

arch/arm/mach-s5pv310/mct.c line 142

Quoted 9 lines
arch/arm/mach-s5pv310/mct.c new file +9 -0
+static void s5pv310_frc_suspend(struct clocksource *cs)
+{
+	time_suspended = s5pv310_frc_read(cs);
+};
+
+static void s5pv310_frc_resume(struct clocksource *cs)
+{
+	s5pv310_mct_frc_start((u32)(time_suspended >> 32), (u32)time_suspended);
+};

Is this something which other clocksource drivers need to do, or does the core automatically deal with the clocksource being irregular across a suspend/resume event?

Quoted 29 lines
arch/arm/mach-s5pv310/mct.c new file +29 -0
+irqreturn_t s5pv310_mct_tick0_isr(int irq, void *dev_id)
+{
+	struct clock_event_device *evt = dev_id;
+
+	/*
+	 * This is for supporting oneshot mode.
+	 * Mct would generate interrupt periodically
+	 * without explicit stopping.
+	 */
+	if (evt->mode != CLOCK_EVT_MODE_PERIODIC)
+		s5pv310_mct_tick_stop(MCT_TICK0);
+
+	/* Clear the MCT tick0 interrupt */
+	s5pv310_mct_write(0x1, S5PV310_MCT_L0_INT_CSTAT);
+
+	evt->event_handler(evt);
+
+	return IRQ_HANDLED;
+}
+
+irqreturn_t s5pv310_mct_tick1_isr(int irq, void *dev_id)
+{
+	struct clock_event_device *evt = dev_id;
+
+	/*
+	 * This is for supporting oneshot mode.
+	 * Mct would generate interrupt periodically
+	 * without explicit stopping.
+	 */

arch/arm/mach-s5pv310/mct.c line 404

Quoted 10 lines
arch/arm/mach-s5pv310/mct.c new file +10 -0
+	if (evt->mode != CLOCK_EVT_MODE_PERIODIC)
+		s5pv310_mct_tick_stop(MCT_TICK1);
+
+	/* Clear the MCT tick1 interrupt */
+	s5pv310_mct_write(0x1, S5PV310_MCT_L1_INT_CSTAT);
+
+	evt->event_handler(evt);
+
+	return IRQ_HANDLED;
+}

Umm, why not wrap up the clock_event_device into your own structure, which then carries the base address of the MCT to be used - rather than duplicating the code just because the base address is different. Eg,

struct mct_clock_event_device {
	struct clock_event_device evt;
	void __iomem *base;
};
author
#2 lore raw

PATCH v2 1/1 ARM: S5PV310: Implement kernel timers using MCT

Quoted 4 lines · Russell King - ARM Linux
Quoted 2 lines · Kukjin Kim

From: Changhwan Youn <[email protected]>

Quoted 9 lines
Quoted 4 lines

The Multi-Core Timer(MCT) of S5PV310 is designed for implementing clock source timer and clock event timers. This patch implements 1 clock source timer with 64 bit free running counter of MCT and 2 clock event timers with two of 31-bit tick counters.

I want to wait until after this merge window before commenting too much on this; some of this patch will be impacted by changes in this merge window.

Hmmm...Ok, I understood.

Quoted 9 lines

arch/arm/mach-s5pv310/mct.c

Quoted 8 lines
arch/arm/mach-s5pv310/mct.c new file +8 -0
+static void s5pv310_frc_suspend(struct clocksource *cs)
+{
+	time_suspended = s5pv310_frc_read(cs);
+};
+
+static void s5pv310_frc_resume(struct clocksource *cs)
+{
+	s5pv310_mct_frc_start((u32)(time_suspended >> 32),

(u32)time_suspended);

Quoted 6 lines
Quoted 1 line

+};

Is this something which other clocksource drivers need to do, or does the core automatically deal with the clocksource being irregular across a suspend/resume event?

Normally this is not necessary because core deals with the irregularity of clocksource, but for sched_clock() implementation, clocksource had better be regular across a suspend/resume event. One example is "Show timing information on printks" kernel configuration. Without this code, timing information resets after suspend/resume event.

Following is not submitted but will be submitted :-)

unsigned long long sched_clock(void)

{
	struct clocksource *cs = &mct_frc;

	return clocksource_cyc2ns(cs->read(NULL), sched_mult, sched_shift);
}
Quoted 44 lines
Quoted 29 lines
arch/arm/mach-s5pv310/mct.c new file +29 -0
+irqreturn_t s5pv310_mct_tick0_isr(int irq, void *dev_id)
+{
+	struct clock_event_device *evt = dev_id;
+
+	/*
+	 * This is for supporting oneshot mode.
+	 * Mct would generate interrupt periodically
+	 * without explicit stopping.
+	 */
+	if (evt->mode != CLOCK_EVT_MODE_PERIODIC)
+		s5pv310_mct_tick_stop(MCT_TICK0);
+
+	/* Clear the MCT tick0 interrupt */
+	s5pv310_mct_write(0x1, S5PV310_MCT_L0_INT_CSTAT);
+
+	evt->event_handler(evt);
+
+	return IRQ_HANDLED;
+}
+
+irqreturn_t s5pv310_mct_tick1_isr(int irq, void *dev_id)
+{
+	struct clock_event_device *evt = dev_id;
+
+	/*
+	 * This is for supporting oneshot mode.
+	 * Mct would generate interrupt periodically
+	 * without explicit stopping.
+	 */

arch/arm/mach-s5pv310/mct.c line 404

Quoted 10 lines
arch/arm/mach-s5pv310/mct.c new file +10 -0
+	if (evt->mode != CLOCK_EVT_MODE_PERIODIC)
+		s5pv310_mct_tick_stop(MCT_TICK1);
+
+	/* Clear the MCT tick1 interrupt */
+	s5pv310_mct_write(0x1, S5PV310_MCT_L1_INT_CSTAT);
+
+	evt->event_handler(evt);
+
+	return IRQ_HANDLED;
+}

Umm, why not wrap up the clock_event_device into your own structure, which then carries the base address of the MCT to be used - rather than duplicating the code just because the base address is different. Eg,

Quoted 4 lines
struct mct_clock_event_device {
	struct clock_event_device evt;
	void __iomem *base;
};

Thanks.

Best regards,
Kgene.
--
Kukjin Kim <[email protected]>, Senior Engineer, SW Solution Development Team, Samsung Electronics Co., Ltd.

#3 lore raw

PATCH v2 1/1 ARM: S5PV310: Implement kernel timers using MCT

Quoted 10 lines · Kukjin Kim
Quoted 9 lines · Russell King - ARM Linux
Quoted 6 lines · Kukjin Kim

From: Changhwan Youn <[email protected]>

The Multi-Core Timer(MCT) of S5PV310 is designed for implementing clock source timer and clock event timers. This patch implements 1 clock source timer with 64 bit free running counter of MCT and 2 clock event timers with two of 31-bit tick counters.

Quoted 5 lines
Quoted 4 lines

I want to wait until after this merge window before commenting too much on this; some of this patch will be impacted by changes in this merge window.

Hmmm...Ok, I understood.

That stuff is now in mainline - not only the new sched_clock() support but also the SMP changes (which impact on your MCT code.) Please rebase on latest mainline and re-send.

Quoted 21 lines
Quoted 9 lines

arch/arm/mach-s5pv310/mct.c

Quoted 8 lines
arch/arm/mach-s5pv310/mct.c new file +8 -0
+static void s5pv310_frc_suspend(struct clocksource *cs)
+{
+	time_suspended = s5pv310_frc_read(cs);
+};
+
+static void s5pv310_frc_resume(struct clocksource *cs)
+{
+	s5pv310_mct_frc_start((u32)(time_suspended >> 32),

(u32)time_suspended);

Quoted 6 lines
Quoted 1 line

+};

Is this something which other clocksource drivers need to do, or does the core automatically deal with the clocksource being irregular across a suspend/resume event?

Normally this is not necessary because core deals with the irregularity of clocksource, but for sched_clock() implementation, clocksource had better be regular across a suspend/resume event. One example is "Show timing information on printks" kernel configuration. Without this code, timing information resets after suspend/resume event.

Quoted 8 lines

Following is not submitted but will be submitted :-)

unsigned long long sched_clock(void)

{
	struct clocksource *cs = &mct_frc;

	return clocksource_cyc2ns(cs->read(NULL), sched_mult, sched_shift);
}

Please use the new sched_clock stuff which guarantees to return a 64-bit cycle count (which is what sched_clock() is required to do.)

author
#4 lore raw

PATCH v2 1/1 ARM: S5PV310: Implement kernel timers using MCT

Quoted 5 lines · Russell King - ARM Linux
Quoted 3 lines · Kukjin Kim
Quoted 2 lines · Russell King - ARM Linux

On Tue, Jan 04, 2011 at 11:18:47AM +0900, Kukjin Kim wrote:

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

From: Changhwan Youn <[email protected]>

The Multi-Core Timer(MCT) of S5PV310 is designed for implementing clock source timer and clock event timers. This patch implements 1 clock source timer with 64 bit free running counter of MCT and 2 clock event timers with two of 31-bit tick counters.

I want to wait until after this merge window before commenting too

much

Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

on this; some of this patch will be impacted by changes in this merge window.

Hmmm...Ok, I understood.

That stuff is now in mainline - not only the new sched_clock() support but also the SMP changes (which impact on your MCT code.) Please rebase on latest mainline and re-send.

I found it in mainline...thanks...ok, will do it.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

arch/arm/mach-s5pv310/mct.c

Quoted 8 lines
arch/arm/mach-s5pv310/mct.c new file +8 -0
+static void s5pv310_frc_suspend(struct clocksource *cs)
+{
+	time_suspended = s5pv310_frc_read(cs);
+};
+
+static void s5pv310_frc_resume(struct clocksource *cs)
+{
+	s5pv310_mct_frc_start((u32)(time_suspended >> 32),

(u32)time_suspended);

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line

+};

Is this something which other clocksource drivers need to do, or does

the

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

core automatically deal with the clocksource being irregular across a suspend/resume event?

Normally this is not necessary because core deals with the irregularity

of

Quoted 1 line
Quoted 1 line

clocksource, but for sched_clock() implementation, clocksource had

better

Quoted 11 lines

be

Quoted 10 lines

regular across a suspend/resume event. One example is "Show timing information on printks" kernel configuration. Without this code, timing information resets after suspend/resume event.

Following is not submitted but will be submitted :-)

unsigned long long sched_clock(void)

{
	struct clocksource *cs = &mct_frc;
Quoted 5 lines
Quoted 2 lines
	return clocksource_cyc2ns(cs->read(NULL), sched_mult, sched_shift);
}

Please use the new sched_clock stuff which guarantees to return a 64-bit cycle count (which is what sched_clock() is required to do.)

Ok.

Russell one more,
Is it possible that I send 'pull request' to you for 38 merge window on this Wednesday?

Thanks.

Best regards,
Kgene.
--
Kukjin Kim <[email protected]>, Senior Engineer, SW Solution Development Team, Samsung Electronics Co., Ltd.