Skip to contentSkip to conversation

ARC IPI related fix

PATCH In review Vineet Gupta 1 participant 7 messages Feb 23, 2016 – Feb 26, 2016

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

cover ARC IPI related fix

Hi,

This cam eout of debugging a csd deadlock on ARC.
The fix itself is 1/5, rest of patches are additional improvements, optimizations while we are at it.

Thx,
-Vineet

Vineet Gupta (5):
ARCv2: SMP: Emulate IPI to self using software triggered interrupt
ARC: [intc-compact] Remove IPI setup from ARCompact port
ARCv2: SMP: Push IPI_IRQ into IPI provider
ARCv2: Elide sending new cross core intr if receiver didn't ack prev
ARC: SMP: No need for CONFIG_ARC_IPI_DBG

 arch/arc/Kconfig                      |  8 ------
 arch/arc/include/asm/irq.h            |  2 --
 arch/arc/include/asm/irqflags-arcv2.h | 11 ++++++++
 arch/arc/kernel/intc-compact.c        |  3 --
 arch/arc/kernel/mcip.c                | 52 ++++++++++++++++++-----------------
 arch/arc/kernel/smp.c                 |  3 --
 6 files changed, 38 insertions(+), 41 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH 1/5 ARCv2: SMP: Emulate IPI to self using software triggered interrupt

ARConnect/MCIP Inter-Core-Interrupt module can't send interrupt to local core. So use core intc capability to trigger software interrupt to self, using an unsued IRQ #21.

This showed up as csd deadlock with LTP trace_sched on a dual core system. This test acts as scheduler fuzzer, triggering all sorts of schedulting activity. Trouble starts with IPI to self, which doesn't get delivered (effectively lost due to H/w capability), but the msg intended to be sent remain enqueued in per-cpu @ipi_data.

All subsequent IPIs to this core from other cores get elided due to the IPI coalescing optimization in ipi_send_msg_one() where a pending msg implies an IPI already sent and assumes other core is yet to ack it. After the elided IPI, other core simply goes into csd_lock_wait() but never comes out as this core never sees the interrupt.

Fixes STAR 9001008624

Cc Peter Zijlstra <peterz at infradead.org>
Cc <stable at vger.kernel.org> [4.2]
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/include/asm/irqflags-arcv2.h | 11 +++++++++++
 arch/arc/kernel/mcip.c                | 15 +++++++++++++++
 2 files changed, 26 insertions(+)
arch/arc/include/asm/irqflags-arcv2.h +11 -0
index 1fc18ee06cf2..37c2f751eebf 100644
@@ -22,6 +22,7 @@
 #define AUX_IRQ_CTRL		0x00E
 #define AUX_IRQ_ACT		0x043	/* Active Intr across all levels */
 #define AUX_IRQ_LVL_PEND	0x200	/* Pending Intr across all levels */
+#define AUX_IRQ_HINT		0x201	/* For generating Soft Interrupts */
 #define AUX_IRQ_PRIORITY	0x206
 #define ICAUSE			0x40a
 #define AUX_IRQ_SELECT		0x40b
@@ -115,6 +116,16 @@ static inline int arch_irqs_disabled(void)
 	return arch_irqs_disabled_flags(arch_local_save_flags());
 }
 
+static inline void arc_softirq_trigger(int irq)
+{
+	write_aux_reg(AUX_IRQ_HINT, irq);
+}
+
+static inline void arc_softirq_clear(int irq)
+{
+	write_aux_reg(AUX_IRQ_HINT, 0);
+}
+
 #else
 
 .macro IRQ_DISABLE  scratch
arch/arc/kernel/mcip.c +15 -0
index 002c5fcf8947..9e1bd03b87a6 100644
@@ -11,9 +11,12 @@
 #include <linux/smp.h>
 #include <linux/irq.h>
 #include <linux/spinlock.h>
+#include <asm/irqflags-arcv2.h>
 #include <asm/mcip.h>
 #include <asm/setup.h>
 
+#define SOFTIRQ_IRQ	21
+
 static char smp_cpuinfo_buf[128];
 static int idu_detected;
 
@@ -22,6 +25,7 @@ static DEFINE_RAW_SPINLOCK(mcip_lock);
 static void mcip_setup_per_cpu(int cpu)
 {
 	smp_ipi_irq_setup(cpu, IPI_IRQ);
+	smp_ipi_irq_setup(cpu, SOFTIRQ_IRQ);
 }
 
 static void mcip_ipi_send(int cpu)
@@ -29,6 +33,12 @@ static void mcip_ipi_send(int cpu)
 	unsigned long flags;
 	int ipi_was_pending;
 
+	/* ARConnect can only send IPI to others */
+	if (unlikely(cpu == raw_smp_processor_id())) {
+		arc_softirq_trigger(SOFTIRQ_IRQ);
+		return;
+	}
+
 	/*
 	 * NOTE: We must spin here if the other cpu hasn't yet
 	 * serviced a previous message. This can burn lots
@@ -63,6 +73,11 @@ static void mcip_ipi_clear(int irq)
 	unsigned long flags;
 	unsigned int __maybe_unused copy;
 
+	if (unlikely(irq == SOFTIRQ_IRQ)) {
+		arc_softirq_clear(irq);
+		return;
+	}
+
 	raw_spin_lock_irqsave(&mcip_lock, flags);
 
 	/* Who sent the IPI */
Signature · 1 line
2.5.0
#2 lore raw

PATCH 2/5 ARC: [intc-compact] Remove IPI setup from ARCompact port

In reply to Vineet Gupta

There is no real ARC700 based SMP SoC so remove IPI definition. EZChip's SMP ARC700 is going to use a different intc and IPI provider anyways.

Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/include/asm/irq.h     | 1 -
 arch/arc/kernel/intc-compact.c | 3 ---
 2 files changed, 4 deletions(-)
arch/arc/include/asm/irq.h +0 -1
index 4fd7d62a6e30..bc5103637326 100644
@@ -16,7 +16,6 @@
 #ifdef CONFIG_ISA_ARCOMPACT
 #define TIMER0_IRQ      3
 #define TIMER1_IRQ      4
-#define IPI_IRQ		(NR_CPU_IRQS-1) /* dummy to enable SMP build for up hardware */
 #else
 #define TIMER0_IRQ      16
 #define TIMER1_IRQ      17
arch/arc/kernel/intc-compact.c +0 -3
index 06bcedf19b62..224d1c3aa9c4 100644
@@ -81,9 +81,6 @@ static int arc_intc_domain_map(struct irq_domain *d, unsigned int irq,
 {
 	switch (irq) {
 	case TIMER0_IRQ:
-#ifdef CONFIG_SMP
-	case IPI_IRQ:
-#endif
 		irq_set_chip_and_handler(irq, &onchip_intc, handle_percpu_irq);
 		break;
 	default:
Signature · 1 line
2.5.0
#3 lore raw

PATCH 3/5 ARCv2: SMP: Push IPI_IRQ into IPI provider

In reply to Vineet Gupta
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/include/asm/irq.h | 1 -
 arch/arc/kernel/mcip.c     | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
arch/arc/include/asm/irq.h +0 -1
index bc5103637326..49014f0ef36d 100644
@@ -19,7 +19,6 @@
 #else
 #define TIMER0_IRQ      16
 #define TIMER1_IRQ      17
-#define IPI_IRQ         19
 #endif
 
 #include <linux/interrupt.h>
arch/arc/kernel/mcip.c +1 -0
index 9e1bd03b87a6..e30d5d428330 100644
@@ -15,6 +15,7 @@
 #include <asm/mcip.h>
 #include <asm/setup.h>
 
+#define IPI_IRQ		19
 #define SOFTIRQ_IRQ	21
 
 static char smp_cpuinfo_buf[128];
Signature · 1 line
2.5.0
#4 lore raw

PATCH 4/5 ARCv2: Elide sending new cross core intr if receiver didn't ack prev

In reply to Vineet Gupta

ARConnect/MCIP IPI sending has a retry-wait loop in case caller had not seen a previous such interrupt. Turns out that it is not needed at all. Linux cross core calling allows coalescing multiple IPIs to same receiver - it is fine as long as there is one.

This logic is built into upper layer already, at a higher level of abstraction. ipi_send_msg_one() sets the actual msg payload, but it only calls MCIP IPI sending if msg holder was empty (using atomic-set-new-and-get-old construct). Thus it is unlikely that the retry-wait looping was ever getting exercised at all.

Cc Chuck Jordan <cjordan at synopsys.com>
Cc Peter Zijlstra <peterz at infradead.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/mcip.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
arch/arc/kernel/mcip.c +10 -17
index e30d5d428330..7afc3c703ed1 100644
@@ -40,26 +40,19 @@ static void mcip_ipi_send(int cpu)
 		return;
 	}
 
+	raw_spin_lock_irqsave(&mcip_lock, flags);
+
 	/*
-	 * NOTE: We must spin here if the other cpu hasn't yet
-	 * serviced a previous message. This can burn lots
-	 * of time, but we MUST follows this protocol or
-	 * ipi messages can be lost!!!
-	 * Also, we must release the lock in this loop because
-	 * the other side may get to this same loop and not
-	 * be able to ack -- thus causing deadlock.
+	 * If receiver already has a pending interrupt, elide sending this one.
+	 * Linux cross core calling works well with concurrent IPIs
+	 * coalesced into one
+	 * see arch/arc/kernel/smp.c: ipi_send_msg_one()
 	 */
+	__mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
+	ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
+	if (!ipi_was_pending)
+		__mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
 
-	do {
-		raw_spin_lock_irqsave(&mcip_lock, flags);
-		__mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
-		ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
-		if (ipi_was_pending == 0)
-			break; /* break out but keep lock */
-		raw_spin_unlock_irqrestore(&mcip_lock, flags);
-	} while (1);
-
-	__mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
 	raw_spin_unlock_irqrestore(&mcip_lock, flags);
 
 #ifdef CONFIG_ARC_IPI_DBG
Signature · 1 line
2.5.0
#5 lore raw

Re: [PATCH 4/5] ARCv2: Elide sending new cross core intr if receiver didn't ack prev

Quoted 10 lines · Vineet Gupta

ARConnect/MCIP IPI sending has a retry-wait loop in case caller had not seen a previous such interrupt. Turns out that it is not needed at all. Linux cross core calling allows coalescing multiple IPIs to same receiver - it is fine as long as there is one.

This logic is built into upper layer already, at a higher level of abstraction. ipi_send_msg_one() sets the actual msg payload, but it only calls MCIP IPI sending if msg holder was empty (using atomic-set-new-and-get-old construct). Thus it is unlikely that the retry-wait looping was ever getting exercised at all.

Turns out that this patch was needed for more serious reasons.
For experiment sake I reverted the IPI eliding optimization and immediately ran into a deadlock, with LTP:trace_sched !

@@ -241,7 +241,7 @@ static void ipi_send_msg_one(int cpu, enum ipi_msg_type msg)
* IPI handler, because !@old means it has not yet dequeued the msg(s)
* so @new msg can be a free-loader
*/
- if (plat_smp_ops.ipi_send && !old)
+ if (plat_smp_ops.ipi_send)

-Vineet

Quoted 50 lines
Cc Chuck Jordan <cjordan at synopsys.com>
Cc Peter Zijlstra <peterz at infradead.org>
Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/kernel/mcip.c | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)
arch/arc/kernel/mcip.c +10 -17
index e30d5d428330..7afc3c703ed1 100644
@@ -40,26 +40,19 @@ static void mcip_ipi_send(int cpu)
 		return;
 	}
 
+	raw_spin_lock_irqsave(&mcip_lock, flags);
+
 	/*
-	 * NOTE: We must spin here if the other cpu hasn't yet
-	 * serviced a previous message. This can burn lots
-	 * of time, but we MUST follows this protocol or
-	 * ipi messages can be lost!!!
-	 * Also, we must release the lock in this loop because
-	 * the other side may get to this same loop and not
-	 * be able to ack -- thus causing deadlock.
+	 * If receiver already has a pending interrupt, elide sending this one.
+	 * Linux cross core calling works well with concurrent IPIs
+	 * coalesced into one
+	 * see arch/arc/kernel/smp.c: ipi_send_msg_one()
 	 */
+	__mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
+	ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
+	if (!ipi_was_pending)
+		__mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
 
-	do {
-		raw_spin_lock_irqsave(&mcip_lock, flags);
-		__mcip_cmd(CMD_INTRPT_READ_STATUS, cpu);
-		ipi_was_pending = read_aux_reg(ARC_REG_MCIP_READBACK);
-		if (ipi_was_pending == 0)
-			break; /* break out but keep lock */
-		raw_spin_unlock_irqrestore(&mcip_lock, flags);
-	} while (1);
-
-	__mcip_cmd(CMD_INTRPT_GENERATE_IRQ, cpu);
 	raw_spin_unlock_irqrestore(&mcip_lock, flags);
 
 #ifdef CONFIG_ARC_IPI_DBG
#6 lore raw

PATCH 5/5 ARC: SMP: No need for CONFIG_ARC_IPI_DBG

In reply to Vineet Gupta

This was more relevant during SMP bringup.

The warning for bogus msg better be visible always.

Signed-off-by Vineet Gupta <vgupta at synopsys.com>
---
 arch/arc/Kconfig       | 8 --------
 arch/arc/kernel/mcip.c | 9 +--------
 arch/arc/kernel/smp.c  | 3 ---
 3 files changed, 1 insertion(+), 19 deletions(-)
arch/arc/Kconfig +0 -8
index 4abc81907071..8a188bc1786a 100644
@@ -532,14 +532,6 @@ config ARC_DBG_TLB_MISS_COUNT
 	  Counts number of I and D TLB Misses and exports them via Debugfs
 	  The counters can be cleared via Debugfs as well
 
-if SMP
-
-config ARC_IPI_DBG
-	bool "Debug Inter Core interrupts"
-	default n
-
-endif
-
 endif
 
 config ARC_UBOOT_SUPPORT
arch/arc/kernel/mcip.c +1 -8
index 7afc3c703ed1..7b4af70ffd18 100644
@@ -65,7 +65,6 @@ static void mcip_ipi_clear(int irq)
 {
 	unsigned int cpu, c;
 	unsigned long flags;
-	unsigned int __maybe_unused copy;
 
 	if (unlikely(irq == SOFTIRQ_IRQ)) {
 		arc_softirq_clear(irq);
@@ -77,7 +76,7 @@ static void mcip_ipi_clear(int irq)
 	/* Who sent the IPI */
 	__mcip_cmd(CMD_INTRPT_CHECK_SOURCE, 0);
 
-	copy = cpu = read_aux_reg(ARC_REG_MCIP_READBACK);	/* 1,2,4,8... */
+	cpu = read_aux_reg(ARC_REG_MCIP_READBACK);	/* 1,2,4,8... */
 
 	/*
 	 * In rare case, multiple concurrent IPIs sent to same target can
@@ -91,12 +90,6 @@ static void mcip_ipi_clear(int irq)
 	} while (cpu);
 
 	raw_spin_unlock_irqrestore(&mcip_lock, flags);
-
-#ifdef CONFIG_ARC_IPI_DBG
-	if (c != __ffs(copy))
-		pr_info("IPIs from %x coalesced to %x\n",
-			copy, raw_smp_processor_id());
-#endif
 }
 
 static void mcip_probe_n_setup(void)
arch/arc/kernel/smp.c +0 -3
index ef6e9e15b82a..424e937da5c8 100644
@@ -336,11 +336,8 @@ irqreturn_t do_IPI(int irq, void *dev_id)
 		int rc;
 
 		rc = __do_IPI(msg);
-#ifdef CONFIG_ARC_IPI_DBG
-		/* IPI received but no valid @msg */
 		if (rc)
 			pr_info("IPI with bogus msg %ld in %ld\n", msg, copy);
-#endif
 		pending &= ~(1U << msg);
 	} while (pending);
 
Signature · 1 line
2.5.0