Skip to contentSkip to conversation

Modernize ARC clocksource/clockevent/intc drivers

PATCH Superseded Vineet Gupta 3 participants 17 messages Apr 13, 2016 – Apr 18, 2016 Synopsys ARC architecture

lore
Share & tools
lore
#0 lore raw

v4 cover Modernize ARC clocksource/clockevent/intc drivers

Hi,

This is a partial repost of a series [1] which improves the ARC clock* drivers. I've also included the patches to switch the core intc from legacy to linear domains (as suggested by Marc Z a while back).

These are stepping stones for eventual landing into driver/*

Please review !

Thx,
-Vineet

[1] http://lists.infradead.org/pipermail/linux-snps-arc/2016-March/000653.html

Vineet Gupta (5):
ARC: clockevent: DT based probe
ARC: clocksource: DT based probe
ARC: irq: export some IRQs again
ARC: [intc-*] Do a domain lookup in primary handler for hwirq -> linux
virq
ARC: [intc-*] switch to linear domain

 arch/arc/Kconfig               |   1 +
 arch/arc/include/asm/irq.h     |   9 +--
 arch/arc/kernel/intc-arcv2.c   |  17 +++--
 arch/arc/kernel/intc-compact.c |  14 ++--
 arch/arc/kernel/irq.c          |   9 +--
 arch/arc/kernel/mcip.c         |   7 +-
 arch/arc/kernel/setup.c        |   3 -
 arch/arc/kernel/time.c         | 169 +++++++++++++++++++++++++----------------
 8 files changed, 131 insertions(+), 98 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH v4 1/5 ARC: clockevent: DT based probe

- timer frequency is derived from DT (no longer rely on top level DT "clock-frequency" probed early and exported by asm/clk.h)

- TIMER0_IRQ need not be exported across arch code, confined to intc as it is property of same

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/include/asm/irq.h     |  9 --------
 arch/arc/kernel/intc-compact.c |  2 ++
 arch/arc/kernel/time.c         | 49 +++++++++++++++++++++++++++++-------------
 3 files changed, 36 insertions(+), 24 deletions(-)
arch/arc/include/asm/irq.h +0 -9
index 5c0b5abda67a..a6ac89dc228f 100644
@@ -12,15 +12,6 @@
 #define NR_CPU_IRQS	32  /* number of interrupt lines of ARC770 CPU */
 #define NR_IRQS		128 /* allow some CPU external IRQ handling */
 
-/* Platform Independent IRQs */
-#ifdef CONFIG_ISA_ARCOMPACT
-#define TIMER0_IRQ      3
-#define TIMER1_IRQ      4
-#else
-#define TIMER0_IRQ      16
-#define TIMER1_IRQ      17
-#endif
-
 #include <linux/interrupt.h>
 #include <asm-generic/irq.h>
 
arch/arc/kernel/intc-compact.c +2 -0
index 4195eedeb6d1..d31bc647146d 100644
@@ -14,6 +14,8 @@
 #include <linux/irqchip.h>
 #include <asm/irq.h>
 
+#define TIMER0_IRQ	3	/* Fixed by ISA */
+
 /*
  * Early Hardware specific Interrupt setup
  * -Platform independent, needed for each CPU (not foldable into init_IRQ)
arch/arc/kernel/time.c +34 -15

115 lines not on this page · raw message

Signature · 1 line
2.5.0
#7 lore raw

PATCH v4 2/5 ARC: clocksource: DT based probe

In reply to Vineet Gupta

- Remove explicit clocksource setup and let it be done by OF framework by defining CLOCKSOURCE_OF_DECLARE() for various timers

- This allows multiple clocksources to be potentially registered
simultaneouly: previously we could only do one - as all of them had same arc_counter_setup() routine for registration

- Setup routines also ensure that the underlying timer actually exists.

- Remove some of the panic() calls if underlying timer is NOT detected as fallback clocksource might still be available
1. If GRFC doesn't exist, jiffies clocksource gets registered anyways
2. if RTC doesn't exist, TIMER1 can take over (as it is always present)

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/mcip.c  |   4 +-
 arch/arc/kernel/setup.c |   3 --
 arch/arc/kernel/time.c  | 124 +++++++++++++++++++++++++++---------------------
 3 files changed, 72 insertions(+), 59 deletions(-)
arch/arc/kernel/mcip.c +1 -3
index c41c364b926c..262d9c3771e6 100644
@@ -116,15 +116,13 @@ static void mcip_probe_n_setup(void)
 		IS_AVAIL1(mp.dbg, "DEBUG "),
 		IS_AVAIL1(mp.gfrc, "GFRC"));
 
+	cpuinfo_arc700[0].extn.gfrc = mp.gfrc;
 	idu_detected = mp.idu;
 
 	if (mp.dbg) {
 		__mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, 0xf);
 		__mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xf, 0xf);
 	}
-
-	if (IS_ENABLED(CONFIG_ARC_HAS_GFRC) && !mp.gfrc)
-		panic("kernel trying to use non-existent GFRC\n");
 }
 
 struct plat_smp_ops plat_smp_ops = {
arch/arc/kernel/setup.c +0 -3
index 507ec523112a..91f79fa447bc 100644
@@ -313,9 +313,6 @@ static void arc_chk_core_config(void)
 	if (!cpu->extn.timer1)
 		panic("Timer1 is not present!\n");
 
-	if (IS_ENABLED(CONFIG_ARC_HAS_RTC) && !cpu->extn.rtc)
-		panic("RTC is not present\n");
-
 #ifdef CONFIG_ARC_HAS_DCCM
 	/*
 	 * DCCM can be arbit placed in hardware.
arch/arc/kernel/time.c +71 -53

186 lines not on this page · raw message

Signature · 1 line
2.5.0
#12 lore raw

PATCH v4 3/5 ARC: irq: export some IRQs again

In reply to Vineet Gupta

This will be needed for switching ti lineaser irq domain as irq_create_mapping() called by intr code, needs the IRQ numbers as well in addition to existing usage in mcip.c

Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/include/asm/irq.h | 6 ++++++
 arch/arc/kernel/mcip.c     | 3 ---
 2 files changed, 6 insertions(+), 3 deletions(-)
arch/arc/include/asm/irq.h +6 -0
index a6ac89dc228f..c0fa0d2de400 100644
@@ -12,6 +12,12 @@
 #define NR_CPU_IRQS	32  /* number of interrupt lines of ARC770 CPU */
 #define NR_IRQS		128 /* allow some CPU external IRQ handling */
 
+/* Platform Independent IRQs */
+#ifdef CONFIG_ISA_ARCV2
+#define IPI_IRQ		19
+#define SOFTIRQ_IRQ	21
+#endif
+
 #include <linux/interrupt.h>
 #include <asm-generic/irq.h>
 
arch/arc/kernel/mcip.c +0 -3
index 262d9c3771e6..72f9179b1a24 100644
@@ -15,9 +15,6 @@
 #include <asm/mcip.h>
 #include <asm/setup.h>
 
-#define IPI_IRQ		19
-#define SOFTIRQ_IRQ	21
-
 static char smp_cpuinfo_buf[128];
 static int idu_detected;
 
Signature · 1 line
2.5.0
#13 lore raw

PATCH v4 4/5 ARC: [intc-*] Do a domain lookup in primary handler for hwirq -> linux virq

In reply to Vineet Gupta

The primary interrupt handler arch_do_IRQ() was passing hwirq as linux virq to core code. This was fragile and worked so far as we only had legacy/linear domains.

This came out of a rant by Marc Zyngier.
http://lists.infradead.org/pipermail/linux-snps-arc/2015-December/000298.html

Cc Marc Zyngier <marc.zyngier at arm.com>
Cc Thomas Gleixner <tglx at linutronix.de>
Cc Noam Camus <noamc at ezchip.com>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/Kconfig               |  1 +
 arch/arc/kernel/intc-arcv2.c   |  9 ++++++---
 arch/arc/kernel/intc-compact.c | 10 ++++++----
 arch/arc/kernel/irq.c          |  9 ++-------
 4 files changed, 15 insertions(+), 14 deletions(-)
arch/arc/Kconfig +1 -0
index 80b222651a90..bf0a4fd45d25 100644
@@ -31,6 +31,7 @@ config ARC
 	select HAVE_MOD_ARCH_SPECIFIC if ARC_DW2_UNWIND
 	select HAVE_OPROFILE
 	select HAVE_PERF_EVENTS
+	select HANDLE_DOMAIN_IRQ
 	select IRQ_DOMAIN
 	select MODULES_USE_ELF_RELA
 	select NO_BOOTMEM
arch/arc/kernel/intc-arcv2.c +6 -3
index 942526322ae7..592cc977151e 100644
@@ -137,21 +137,24 @@ static const struct irq_domain_ops arcv2_irq_ops = {
 	.map = arcv2_irq_map,
 };
 
-static struct irq_domain *root_domain;
 
 static int __init
 init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 {
+	struct irq_domain *root_domain;
+
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
 	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
 					    &arcv2_irq_ops, NULL);
-
 	if (!root_domain)
 		panic("root irq domain not avail\n");
 
-	/* with this we don't need to export root_domain */
+	/*
+	 * Needed for primary domain lookup to succeed
+	 * This is a primary irqchip, and can never have a parent
+	 */
 	irq_set_default_host(root_domain);
 
 	return 0;
arch/arc/kernel/intc-compact.c +6 -4
index d31bc647146d..48a8b24de23e 100644
@@ -97,21 +97,23 @@ static const struct irq_domain_ops arc_intc_domain_ops = {
 	.map = arc_intc_domain_map,
 };
 
-static struct irq_domain *root_domain;
-
 static int __init
 init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 {
+	struct irq_domain *root_domain;
+
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
 	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
 					    &arc_intc_domain_ops, NULL);
-
 	if (!root_domain)
 		panic("root irq domain not avail\n");
 
-	/* with this we don't need to export root_domain */
+	/*
+	 * Needed for primary domain lookup to succeed
+	 * This is a primary irqchip, and can never have a parent
+	 */
 	irq_set_default_host(root_domain);
 
 	return 0;
arch/arc/kernel/irq.c +2 -7
index fb6dede9d05f..538b36afe89e 100644
@@ -41,12 +41,7 @@ void __init init_IRQ(void)
  * "C" Entry point for any ARC ISR, called from low level vector handler
  * @irq is the vector number read from ICAUSE reg of on-chip intc
  */
-void arch_do_IRQ(unsigned int irq, struct pt_regs *regs)
+void arch_do_IRQ(unsigned int hwirq, struct pt_regs *regs)
 {
-	struct pt_regs *old_regs = set_irq_regs(regs);
-
-	irq_enter();
-	generic_handle_irq(irq);
-	irq_exit();
-	set_irq_regs(old_regs);
+	handle_domain_irq(NULL, hwirq, regs);
 }
Signature · 1 line
2.5.0
#14 lore raw

PATCH v4 5/5 ARC: [intc-*] switch to linear domain

In reply to Vineet Gupta

Now that we have Timers probed from DT, don't need legacy domain

This however requires mapping to be called explicitly for the IRQ which still can't (and probably never) be probed from DT such as IPI and SOFTIRQ

Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/intc-arcv2.c   | 8 ++++++--
 arch/arc/kernel/intc-compact.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
arch/arc/kernel/intc-arcv2.c +6 -2
index 592cc977151e..6c24faf48b16 100644
@@ -146,8 +146,7 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
-	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
-					    &arcv2_irq_ops, NULL);
+	root_domain = irq_domain_add_linear(intc, NR_CPU_IRQS, &arcv2_irq_ops, NULL);
 	if (!root_domain)
 		panic("root irq domain not avail\n");
 
@@ -157,6 +156,11 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	 */
 	irq_set_default_host(root_domain);
 
+#ifdef CONFIG_SMP
+	irq_create_mapping(root_domain, IPI_IRQ);
+#endif
+	irq_create_mapping(root_domain, SOFTIRQ_IRQ);
+
 	return 0;
 }
 
arch/arc/kernel/intc-compact.c +1 -1
index 48a8b24de23e..c5cceca36118 100644
@@ -105,7 +105,7 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
-	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
+	root_domain = irq_domain_add_linear(intc, NR_CPU_IRQS,
 					    &arc_intc_domain_ops, NULL);
 	if (!root_domain)
 		panic("root irq domain not avail\n");
Signature · 1 line
2.5.0
#2 lore raw

Re: [PATCH v4 1/5] ARC: clockevent: DT based probe

In reply to Vineet Gupta
Quoted 9 lines · Vineet Gupta

- timer frequency is derived from DT (no longer rely on top level DT "clock-frequency" probed early and exported by asm/clk.h)

- TIMER0_IRQ need not be exported across arch code, confined to intc as it is property of same

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>

---

[ ... ]

arch/arc/kernel/time.c line 68

Quoted 9 lines
arch/arc/kernel/time.c +9 -0
+static void noinline arc_get_timer_clk(struct device_node *node)
+{
+	struct clk *clk;
+	int ret;
+
+	clk = of_clk_get(node, 0);
+	if (IS_ERR(clk))
+		panic("Can't get timer clock");
+

Don't panic here. Change the function to return an error and let the caller to handle it.

Quoted 7 lines
arch/arc/kernel/time.c +7 -0
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		pr_err("Couldn't enable parent clock\n");
+
+	arc_timer_freq = clk_get_rate(clk);
+}
+

[ ... ]

arch/arc/kernel/time.c static struct notifier_block arc_timer_cpu_nb = { · line 300

Quoted 12 lines
arch/arc/kernel/time.c +6 -0
+static void __init arc_clockevent_setup(struct device_node *node)
 {
 	struct clock_event_device *evt = this_cpu_ptr(&arc_clockevent_device);
 	int ret;
 
 	register_cpu_notifier(&arc_timer_cpu_nb);
 
+	arc_timer_irq = irq_of_parse_and_map(node, 0);
+	if (arc_timer_irq <= 0)
+		panic("Can't parse IRQ");
+
+	arc_get_timer_clk(node);

Connected to the comment above, check the return code.

Quoted 36 lines
arch/arc/kernel/time.c +5 -5
+
+	evt->irq = arc_timer_irq;
 	evt->cpumask = cpumask_of(smp_processor_id());
-	clockevents_config_and_register(evt, arc_get_core_freq(),
+	clockevents_config_and_register(evt, arc_timer_freq,
 					0, ARC_TIMER_MAX);
 
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
@@ -291,6 +312,7 @@ static void __init arc_clockevent_setup(void)
 
 	enable_percpu_irq(arc_timer_irq, 0);
 }
+CLOCKSOURCE_OF_DECLARE(arc_clkevt, "snps,arc-timer", arc_clockevent_setup);
 
 /*
  * Called from start_kernel() - boot CPU only
@@ -299,7 +321,6 @@ static void __init arc_clockevent_setup(void)
  * -Also sets up any global state needed for timer subsystem:
  *    - for "counting" timer, registers a clocksource, usable across CPUs
  *      (provided that underlying counter h/w is synchronized across cores)
- *    - for "event" timer, sets up TIMER0 IRQ (as that is platform agnostic)
  */
 void __init time_init(void)
 {
@@ -315,7 +336,5 @@ void __init time_init(void)
 		 * CLK upto 4.29 GHz can be safely represented in 32 bits
 		 * because Max 32 bit number is 4,294,967,295
 		 */
-		clocksource_register_hz(&arc_counter, arc_get_core_freq());
-
-	arc_clockevent_setup();
+		clocksource_register_hz(&arc_counter, arc_timer_freq);
 }
Signature · 1 line
2.5.0
#8 lore raw

Re: [PATCH v4 2/5] ARC: clocksource: DT based probe

In reply to Vineet Gupta
Quoted 148 lines · Vineet Gupta

- Remove explicit clocksource setup and let it be done by OF framework by defining CLOCKSOURCE_OF_DECLARE() for various timers

- This allows multiple clocksources to be potentially registered
simultaneouly: previously we could only do one - as all of them had same arc_counter_setup() routine for registration

- Setup routines also ensure that the underlying timer actually exists.

- Remove some of the panic() calls if underlying timer is NOT detected as fallback clocksource might still be available
1. If GRFC doesn't exist, jiffies clocksource gets registered anyways
2. if RTC doesn't exist, TIMER1 can take over (as it is always present)

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/mcip.c  |   4 +-
 arch/arc/kernel/setup.c |   3 --
 arch/arc/kernel/time.c  | 124 +++++++++++++++++++++++++++---------------------
 3 files changed, 72 insertions(+), 59 deletions(-)
arch/arc/kernel/mcip.c +1 -3
index c41c364b926c..262d9c3771e6 100644
@@ -116,15 +116,13 @@ static void mcip_probe_n_setup(void)
 		IS_AVAIL1(mp.dbg, "DEBUG "),
 		IS_AVAIL1(mp.gfrc, "GFRC"));
 
+	cpuinfo_arc700[0].extn.gfrc = mp.gfrc;
 	idu_detected = mp.idu;
 
 	if (mp.dbg) {
 		__mcip_cmd_data(CMD_DEBUG_SET_SELECT, 0, 0xf);
 		__mcip_cmd_data(CMD_DEBUG_SET_MASK, 0xf, 0xf);
 	}
-
-	if (IS_ENABLED(CONFIG_ARC_HAS_GFRC) && !mp.gfrc)
-		panic("kernel trying to use non-existent GFRC\n");
 }
 
 struct plat_smp_ops plat_smp_ops = {
arch/arc/kernel/setup.c +0 -3
index 507ec523112a..91f79fa447bc 100644
@@ -313,9 +313,6 @@ static void arc_chk_core_config(void)
 	if (!cpu->extn.timer1)
 		panic("Timer1 is not present!\n");
 
-	if (IS_ENABLED(CONFIG_ARC_HAS_RTC) && !cpu->extn.rtc)
-		panic("RTC is not present\n");
-
 #ifdef CONFIG_ARC_HAS_DCCM
 	/*
 	 * DCCM can be arbit placed in hardware.
arch/arc/kernel/time.c +21 -27
index 693545df9827..72f023440739 100644
@@ -77,12 +77,7 @@ static void noinline arc_get_timer_clk(struct device_node *node)
 
 #ifdef CONFIG_ARC_HAS_GFRC
 
-static int arc_counter_setup(void)
-{
-	return 1;
-}
-
-static cycle_t arc_counter_read(struct clocksource *cs)
+static cycle_t arc_read_gfrc(struct clocksource *cs)
 {
 	unsigned long flags;
 	union {
@@ -107,15 +102,28 @@ static cycle_t arc_counter_read(struct clocksource *cs)
 	return stamp.full;
 }
 
-static struct clocksource arc_counter = {
+static struct clocksource arc_counter_gfrc = {
 	.name   = "ARConnect GFRC",
 	.rating = 400,
-	.read   = arc_counter_read,
+	.read   = arc_read_gfrc,
 	.mask   = CLOCKSOURCE_MASK(64),
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-#else
+static void __init arc_cs_setup_gfrc(struct device_node *node)
+{
+	int exists = cpuinfo_arc700[0].extn.gfrc;
+
+	if (WARN(!exists, "Global-64-bit-Ctr clocksource not detected"))
+		return;
+
+	arc_get_timer_clk(node);
+
+	clocksource_register_hz(&arc_counter_gfrc, arc_timer_freq);
+}
+CLOCKSOURCE_OF_DECLARE(arc_gfrc, "snps,archs-timer-gfrc", arc_cs_setup_gfrc);
+
+#endif
 
 #ifdef CONFIG_ARC_HAS_RTC
 
@@ -123,15 +131,7 @@ static struct clocksource arc_counter = {
 #define AUX_RTC_LOW	0x104
 #define AUX_RTC_HIGH	0x105
 
-int arc_counter_setup(void)
-{
-	write_aux_reg(AUX_RTC_CTRL, 1);
-
-	/* Not usable in SMP */
-	return !IS_ENABLED(CONFIG_SMP);
-}
-
-static cycle_t arc_counter_read(struct clocksource *cs)
+static cycle_t arc_read_rtc(struct clocksource *cs)
 {
 	unsigned long status;
 	union {
@@ -155,44 +155,66 @@ static cycle_t arc_counter_read(struct clocksource *cs)
 	return stamp.full;
 }
 
-static struct clocksource arc_counter = {
+static struct clocksource arc_counter_rtc = {
 	.name   = "ARCv2 RTC",
 	.rating = 350,
-	.read   = arc_counter_read,
+	.read   = arc_read_rtc,
 	.mask   = CLOCKSOURCE_MASK(64),
 	.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-#else /* !CONFIG_ARC_HAS_RTC */
-
-/*
- * set 32bit TIMER1 to keep counting monotonically and wraparound
- */
-int arc_counter_setup(void)
+static void __init arc_cs_setup_rtc(struct device_node *node)
 {
-	write_aux_reg(ARC_REG_TIMER1_LIMIT, ARC_TIMER_MAX);

arch/arc/kernel/time.c static cycle_t arc_counter_read(struct clocksource *cs) · line 175

Quoted 10 lines
arch/arc/kernel/time.c +8 -2
-	write_aux_reg(ARC_REG_TIMER1_CNT, 0);
-	write_aux_reg(ARC_REG_TIMER1_CTRL, TIMER_CTRL_NH);
+	int exists = cpuinfo_arc700[smp_processor_id()].extn.rtc;
+
+	if (WARN(!exists, "Local-64-bit-Ctr clocksource not detected"))
+		return;
+
+	/* Local to CPU hence not usable in SMP */
+	if (WARN(IS_ENABLED(CONFIG_SMP), "Local-64-bit-Ctr not usable in SMP"))
+		return;

Sorry if this outlines my lack of understanding of the ARC architecture, but what makes per-cpu timer unsuitable for SMP? I'd have thought that it was actually what you wanted...

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#9 lore raw

Re: [PATCH v4 2/5] ARC: clocksource: DT based probe

Quoted 17 lines · Marc Zyngier
Quoted 14 lines

-int arc_counter_setup(void)

arch/arc/kernel/time.c static cycle_t arc_counter_read(struct clocksource *cs) · line 175

Quoted 13 lines
arch/arc/kernel/time.c +9 -3
+static void __init arc_cs_setup_rtc(struct device_node *node)
 {
-	write_aux_reg(ARC_REG_TIMER1_LIMIT, ARC_TIMER_MAX);
-	write_aux_reg(ARC_REG_TIMER1_CNT, 0);
-	write_aux_reg(ARC_REG_TIMER1_CTRL, TIMER_CTRL_NH);
+	int exists = cpuinfo_arc700[smp_processor_id()].extn.rtc;
+
+	if (WARN(!exists, "Local-64-bit-Ctr clocksource not detected"))
+		return;
+
+	/* Local to CPU hence not usable in SMP */
+	if (WARN(IS_ENABLED(CONFIG_SMP), "Local-64-bit-Ctr not usable in SMP"))
+		return;

Sorry if this outlines my lack of understanding of the ARC architecture, but what makes per-cpu timer unsuitable for SMP? I'd have thought that it was actually what you wanted...

This is clocksource, not clockevent. cs needs to synchronized across all cores so that concurrent gtod call from threads on different cores gives you similar values. This obviously is not true for the local RTC hardware timer.

#10 lore raw

Re: [PATCH v4 2/5] ARC: clocksource: DT based probe

Quoted 19 lines · Vineet Gupta
Quoted 17 lines · Marc Zyngier
Quoted 14 lines

-int arc_counter_setup(void)

arch/arc/kernel/time.c static cycle_t arc_counter_read(struct clocksource *cs) · line 175

Quoted 13 lines
arch/arc/kernel/time.c +9 -3
+static void __init arc_cs_setup_rtc(struct device_node *node)
 {
-	write_aux_reg(ARC_REG_TIMER1_LIMIT, ARC_TIMER_MAX);
-	write_aux_reg(ARC_REG_TIMER1_CNT, 0);
-	write_aux_reg(ARC_REG_TIMER1_CTRL, TIMER_CTRL_NH);
+	int exists = cpuinfo_arc700[smp_processor_id()].extn.rtc;
+
+	if (WARN(!exists, "Local-64-bit-Ctr clocksource not detected"))
+		return;
+
+	/* Local to CPU hence not usable in SMP */
+	if (WARN(IS_ENABLED(CONFIG_SMP), "Local-64-bit-Ctr not usable in SMP"))
+		return;

Sorry if this outlines my lack of understanding of the ARC architecture, but what makes per-cpu timer unsuitable for SMP? I'd have thought that it was actually what you wanted...

Quoted 3 lines

This is clocksource, not clockevent. cs needs to synchronized across all cores so that concurrent gtod call from threads on different cores gives you similar values. This obviously is not true for the local RTC hardware timer.

Unsynchronized counters on SMP HW, who would have thought! ;-) I guess each and every architecture has to repeat the same mistakes.

Thanks for shedding some light on it.

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...
#3 lore raw

Re: [PATCH v4 1/5] ARC: clockevent: DT based probe

In reply to Daniel Lezcano
Quoted 26 lines · Daniel Lezcano
Quoted 9 lines · Vineet Gupta

- timer frequency is derived from DT (no longer rely on top level DT "clock-frequency" probed early and exported by asm/clk.h)

- TIMER0_IRQ need not be exported across arch code, confined to intc as it is property of same

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>

---

[ ... ]

arch/arc/kernel/time.c line 68

Quoted 9 lines
arch/arc/kernel/time.c +9 -0
+static void noinline arc_get_timer_clk(struct device_node *node)
+{
+	struct clk *clk;
+	int ret;
+
+	clk = of_clk_get(node, 0);
+	if (IS_ERR(clk))
+		panic("Can't get timer clock");
+

Don't panic here. Change the function to return an error and let the caller to handle it.

Quoted 3 lines

arch/arc/kernel/time.c line 71

Quoted 3 lines
arch/arc/kernel/time.c +3 -0
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		pr_err("Couldn't enable parent clock\n");

I suppose we need to return here too ?

Quoted 14 lines
Quoted 4 lines
arch/arc/kernel/time.c +4 -0
+
+	arc_timer_freq = clk_get_rate(clk);
+}
+

[ ... ]

Quoted 7 lines
arch/arc/kernel/time.c +1 -0
+static void __init arc_clockevent_setup(struct device_node *node)
 {
 	struct clock_event_device *evt = this_cpu_ptr(&arc_clockevent_device);
 	int ret;
 
 	register_cpu_notifier(&arc_timer_cpu_nb);
Quoted 7 lines

arch/arc/kernel/time.c static struct notifier_block arc_timer_cpu_nb = { · line 300

Quoted 5 lines
arch/arc/kernel/time.c +5 -0
+	arc_timer_irq = irq_of_parse_and_map(node, 0);
+	if (arc_timer_irq <= 0)
+		panic("Can't parse IRQ");
+
+	arc_get_timer_clk(node);

Connected to the comment above, check the return code.

Right and if there's error, bail from here too ? This will leave a system w/o a working clockevent and our lpj setup loop will spin forever. Better to add a WARN so that user knows to fix his DT.

Quoted 38 lines
Quoted 37 lines
arch/arc/kernel/time.c +5 -5
+
+	evt->irq = arc_timer_irq;
 	evt->cpumask = cpumask_of(smp_processor_id());
-	clockevents_config_and_register(evt, arc_get_core_freq(),
+	clockevents_config_and_register(evt, arc_timer_freq,
 					0, ARC_TIMER_MAX);
 
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
@@ -291,6 +312,7 @@ static void __init arc_clockevent_setup(void)
 
 	enable_percpu_irq(arc_timer_irq, 0);
 }
+CLOCKSOURCE_OF_DECLARE(arc_clkevt, "snps,arc-timer", arc_clockevent_setup);
 
 /*
  * Called from start_kernel() - boot CPU only
@@ -299,7 +321,6 @@ static void __init arc_clockevent_setup(void)
  * -Also sets up any global state needed for timer subsystem:
  *    - for "counting" timer, registers a clocksource, usable across CPUs
  *      (provided that underlying counter h/w is synchronized across cores)
- *    - for "event" timer, sets up TIMER0 IRQ (as that is platform agnostic)
  */
 void __init time_init(void)
 {
@@ -315,7 +336,5 @@ void __init time_init(void)
 		 * CLK upto 4.29 GHz can be safely represented in 32 bits
 		 * because Max 32 bit number is 4,294,967,295
 		 */
-		clocksource_register_hz(&arc_counter, arc_get_core_freq());
-
-	arc_clockevent_setup();
+		clocksource_register_hz(&arc_counter, arc_timer_freq);
 }
Signature · 1 line
2.5.0
#11 lore raw

Re: [PATCH v4 2/5] ARC: clocksource: DT based probe

In reply to Marc Zyngier
Quoted 5 lines · Marc Zyngier
Quoted 3 lines

This is clocksource, not clockevent. cs needs to synchronized across all cores so

Quoted 2 lines

that concurrent gtod call from threads on different cores gives you similar values. This obviously is not true for the local RTC hardware timer.

Unsynchronized counters on SMP HW, who would have thought! ;-) I guess each and every architecture has to repeat the same mistakes.

Not really - hardware wise the SMP support is pretty recent and before that we only had UP cores. So transition from 32 TIMER1 to 64 bit RTC was only a natural progression in improvements and in theory SoC guys throw in this local timer into the config. We just prevent SMP linux from using it.

#4 lore raw

Re: [PATCH v4 1/5] ARC: clockevent: DT based probe

In reply to Vineet Gupta
Quoted 55 lines · Vineet Gupta
Quoted 26 lines · Daniel Lezcano
Quoted 9 lines · Vineet Gupta

- timer frequency is derived from DT (no longer rely on top level DT "clock-frequency" probed early and exported by asm/clk.h)

- TIMER0_IRQ need not be exported across arch code, confined to intc as it is property of same

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>

---

[ ... ]

arch/arc/kernel/time.c line 68

Quoted 9 lines
arch/arc/kernel/time.c +9 -0
+static void noinline arc_get_timer_clk(struct device_node *node)
+{
+	struct clk *clk;
+	int ret;
+
+	clk = of_clk_get(node, 0);
+	if (IS_ERR(clk))
+		panic("Can't get timer clock");
+

Don't panic here. Change the function to return an error and let the caller to handle it.

Quoted 3 lines

arch/arc/kernel/time.c line 71

Quoted 3 lines
arch/arc/kernel/time.c +3 -0
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		pr_err("Couldn't enable parent clock\n");

I suppose we need to return here too ?

Quoted 14 lines
Quoted 4 lines
arch/arc/kernel/time.c +4 -0
+
+	arc_timer_freq = clk_get_rate(clk);
+}
+

[ ... ]

Quoted 7 lines
arch/arc/kernel/time.c +1 -0
+static void __init arc_clockevent_setup(struct device_node *node)
 {
 	struct clock_event_device *evt = this_cpu_ptr(&arc_clockevent_device);
 	int ret;
 
 	register_cpu_notifier(&arc_timer_cpu_nb);
Quoted 7 lines

arch/arc/kernel/time.c static struct notifier_block arc_timer_cpu_nb = { · line 300

Quoted 5 lines
arch/arc/kernel/time.c +5 -0
+	arc_timer_irq = irq_of_parse_and_map(node, 0);
+	if (arc_timer_irq <= 0)
+		panic("Can't parse IRQ");
+
+	arc_get_timer_clk(node);

Connected to the comment above, check the return code.

Quoted 3 lines

Right and if there's error, bail from here too ? This will leave a system w/o a working clockevent and our lpj setup loop will spin forever. Better to add a WARN so that user knows to fix his DT.

You can handle the error as you wish here. I just don't want panics spread in the code.

In the patch 2/5, you mention:

"Remove some of the panic() calls if underlying timer is NOT detected as
fallback clocksource might still be available"

but you add calls to arc_get_timer_clk() which can panic.

The main problem is the macro CLOCKSOURCE_OF_DECLARE() which expect an init function returning void. I would like to change the code to have it returning an int, so the panic could be raised in the generic clksrc code when all clocksource inits fail.

In the meantime, it is a good practice to concentrate all panics in a single place, that is in the init function to facilitate the conversion above which will happen in the future ...

-- Daniel

Quoted 38 lines
Quoted 37 lines
Quoted 36 lines
arch/arc/kernel/time.c +5 -5
+
+	evt->irq = arc_timer_irq;
 	evt->cpumask = cpumask_of(smp_processor_id());
-	clockevents_config_and_register(evt, arc_get_core_freq(),
+	clockevents_config_and_register(evt, arc_timer_freq,
 					0, ARC_TIMER_MAX);
 
 	/* Needs apriori irq_set_percpu_devid() done in intc map function */
@@ -291,6 +312,7 @@ static void __init arc_clockevent_setup(void)
 
 	enable_percpu_irq(arc_timer_irq, 0);
 }
+CLOCKSOURCE_OF_DECLARE(arc_clkevt, "snps,arc-timer", arc_clockevent_setup);
 
 /*
  * Called from start_kernel() - boot CPU only
@@ -299,7 +321,6 @@ static void __init arc_clockevent_setup(void)
  * -Also sets up any global state needed for timer subsystem:
  *    - for "counting" timer, registers a clocksource, usable across CPUs
  *      (provided that underlying counter h/w is synchronized across cores)
- *    - for "event" timer, sets up TIMER0 IRQ (as that is platform agnostic)
  */
 void __init time_init(void)
 {
@@ -315,7 +336,5 @@ void __init time_init(void)
 		 * CLK upto 4.29 GHz can be safely represented in 32 bits
 		 * because Max 32 bit number is 4,294,967,295
 		 */
-		clocksource_register_hz(&arc_counter, arc_get_core_freq());
-
-	arc_clockevent_setup();
+		clocksource_register_hz(&arc_counter, arc_timer_freq);
 }
Signature · 1 line
2.5.0
#5 lore raw

PATCH v5 1/1 ARC: clockevent: DT based probe

- timer frequency is derived from DT (no longer rely on top level DT "clock-frequency" probed early and exported by asm/clk.h)

- TIMER0_IRQ need not be exported across arch code, confined to intc as it is property of same

- Any failures in clockevent setup are considered pedantic and system panic()'s as there is no generic fallback (unlike clocksource where a jiffies based soft clocksource always exists)

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>

---
Changes since v4 [*]
- clockevent setup failure panic()s bubbled up to top level function [Daniel]
- arc_get_timer_clk() returns error status vs. void [Daniel]
- For consistency, straggler pr_err() in setup function also converted to panic

[*] http://lists.infradead.org/pipermail/linux-snps-arc/2016-April/000903.html

---
 arch/arc/include/asm/irq.h     |  9 -------
 arch/arc/kernel/intc-compact.c |  2 ++
 arch/arc/kernel/time.c         | 58 ++++++++++++++++++++++++++++++------------
 3 files changed, 44 insertions(+), 25 deletions(-)
arch/arc/include/asm/irq.h +0 -9
index 5c0b5abda67a..a6ac89dc228f 100644
@@ -12,15 +12,6 @@
 #define NR_CPU_IRQS	32  /* number of interrupt lines of ARC770 CPU */
 #define NR_IRQS		128 /* allow some CPU external IRQ handling */
 
-/* Platform Independent IRQs */
-#ifdef CONFIG_ISA_ARCOMPACT
-#define TIMER0_IRQ      3
-#define TIMER1_IRQ      4
-#else
-#define TIMER0_IRQ      16
-#define TIMER1_IRQ      17
-#endif
-
 #include <linux/interrupt.h>
 #include <asm-generic/irq.h>
 
arch/arc/kernel/intc-compact.c +2 -0
index 4195eedeb6d1..d31bc647146d 100644
@@ -14,6 +14,8 @@
 #include <linux/irqchip.h>
 #include <asm/irq.h>
 
+#define TIMER0_IRQ	3	/* Fixed by ISA */
+
 /*
  * Early Hardware specific Interrupt setup
  * -Platform independent, needed for each CPU (not foldable into init_IRQ)
arch/arc/kernel/time.c +42 -16

127 lines not on this page · raw message

Signature · 1 line
2.5.0
#15 lore raw

Re: [PATCH v4 5/5] ARC: [intc-*] switch to linear domain

In reply to Vineet Gupta

Hi Marc,

Quoted 44 lines · Vineet Gupta

Now that we have Timers probed from DT, don't need legacy domain

This however requires mapping to be called explicitly for the IRQ which still can't (and probably never) be probed from DT such as IPI and SOFTIRQ

Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/intc-arcv2.c   | 8 ++++++--
 arch/arc/kernel/intc-compact.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
arch/arc/kernel/intc-arcv2.c +6 -2
index 592cc977151e..6c24faf48b16 100644
@@ -146,8 +146,7 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
-	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
-					    &arcv2_irq_ops, NULL);
+	root_domain = irq_domain_add_linear(intc, NR_CPU_IRQS, &arcv2_irq_ops, NULL);
 	if (!root_domain)
 		panic("root irq domain not avail\n");
 
@@ -157,6 +156,11 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	 */
 	irq_set_default_host(root_domain);
 
+#ifdef CONFIG_SMP
+	irq_create_mapping(root_domain, IPI_IRQ);
+#endif
+	irq_create_mapping(root_domain, SOFTIRQ_IRQ);
+
 	return 0;
 }
 
arch/arc/kernel/intc-compact.c +0 -0
index 48a8b24de23e..c5cceca36118 100644

arch/arc/kernel/intc-compact.c init_onchip_IRQ(struct device_node *intc, struct device_node *parent) · line 111

Quoted 8 lines
arch/arc/kernel/intc-compact.c +1 -1
@@ -105,7 +105,7 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
-	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
+	root_domain = irq_domain_add_linear(intc, NR_CPU_IRQS,
 					    &arc_intc_domain_ops, NULL);
 	if (!root_domain)
 		panic("root irq domain not avail\n");

Does this patch look ok to you ? Do you want to see any other improvements here.

-Vineet

#6 lore raw

Re: [PATCH v5] ARC: clockevent: DT based probe

In reply to Vineet Gupta
Quoted 19 lines · Vineet Gupta

- timer frequency is derived from DT (no longer rely on top level DT "clock-frequency" probed early and exported by asm/clk.h)

- TIMER0_IRQ need not be exported across arch code, confined to intc as it is property of same

- Any failures in clockevent setup are considered pedantic and system panic()'s as there is no generic fallback (unlike clocksource where a jiffies based soft clocksource always exists)

Cc Daniel Lezcano <daniel.lezcano at linaro.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>

---
Changes since v4 [*]
- clockevent setup failure panic()s bubbled up to top level function [Daniel]
- arc_get_timer_clk() returns error status vs. void [Daniel]
- For consistency, straggler pr_err() in setup function also converted to panic

[*] http://lists.infradead.org/pipermail/linux-snps-arc/2016-April/000903.html

[ ... ]

arch/arc/kernel/time.c line 69

Quoted 10 lines
arch/arc/kernel/time.c +10 -0
+static int noinline arc_get_timer_clk(struct device_node *node)
+{
+	struct clk *clk;
+	int ret = -1;
+
+	clk = of_clk_get(node, 0);
+	if (IS_ERR(clk)) {
+		pr_err("timer missing clk");
+		return ret;
+	}

return PTR_ERR(clk);

arch/arc/kernel/time.c line 79

Quoted 9 lines
arch/arc/kernel/time.c +9 -0
+	ret = clk_prepare_enable(clk);
+	if (ret) {
+		pr_err("Couldn't enable parent clk\n");
+		return ret;
+	}
+
+	arc_timer_freq = clk_get_rate(clk);
+	return ret;
+}

With the change above: Acked-by: Daniel Lezcano <daniel.lezcano at linaro.org>

Acked-by
#16 lore raw

Re: [PATCH v4 5/5] ARC: [intc-*] switch to linear domain

In reply to Vineet Gupta
Quoted 49 lines · Vineet Gupta

Hi Marc,

Quoted 46 lines · Vineet Gupta

Now that we have Timers probed from DT, don't need legacy domain

This however requires mapping to be called explicitly for the IRQ which still can't (and probably never) be probed from DT such as IPI and SOFTIRQ

Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/intc-arcv2.c   | 8 ++++++--
 arch/arc/kernel/intc-compact.c | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
arch/arc/kernel/intc-arcv2.c +6 -2
index 592cc977151e..6c24faf48b16 100644
@@ -146,8 +146,7 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
-	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
-					    &arcv2_irq_ops, NULL);
+	root_domain = irq_domain_add_linear(intc, NR_CPU_IRQS, &arcv2_irq_ops, NULL);
 	if (!root_domain)
 		panic("root irq domain not avail\n");
 
@@ -157,6 +156,11 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	 */
 	irq_set_default_host(root_domain);
 
+#ifdef CONFIG_SMP
+	irq_create_mapping(root_domain, IPI_IRQ);
+#endif
+	irq_create_mapping(root_domain, SOFTIRQ_IRQ);
+
 	return 0;
 }
 
arch/arc/kernel/intc-compact.c +0 -0
index 48a8b24de23e..c5cceca36118 100644
@@ -105,7 +105,7 @@ init_onchip_IRQ(struct device_node *intc, struct device_node *parent)
 	if (parent)
 		panic("DeviceTree incore intc not a root irq controller\n");
 
Quoted 8 lines

arch/arc/kernel/intc-compact.c init_onchip_IRQ(struct device_node *intc, struct device_node *parent) · line 111

Quoted 6 lines
arch/arc/kernel/intc-compact.c +1 -1
-	root_domain = irq_domain_add_legacy(intc, NR_CPU_IRQS, 0, 0,
+	root_domain = irq_domain_add_linear(intc, NR_CPU_IRQS,
 					    &arc_intc_domain_ops, NULL);
 	if (!root_domain)
 		panic("root irq domain not avail\n");

Does this patch look ok to you ? Do you want to see any other improvements here.

Decoupling HW irqs from Linux irqs is a major progress, so for that:

Acked-by Marc Zyngier <marc.zyngier at arm.com>

Thanks,

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...