Skip to contentSkip to conversation

RISC-V: Show IPI stats

PATCH Superseded Anup Patel 3 participants 6 messages Sep 7, 2018 – Oct 1, 2018 RISC-V

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Anup Patel

author
#0 lore raw

PATCH 1/1 RISC-V: Show IPI stats

This patch provides arch_show_interrupts() implementation to show IPI stats via /proc/interrupts.

Now the contents of /proc/interrupts" will look like below:
CPU0 CPU1 CPU2 CPU3

  8:         17          7          6         14  SiFive PLIC   8  virtio0
 10:         10         10          9         11  SiFive PLIC  10  ttyS0
IPI0:       170        673        251         79  Rescheduling interrupts
IPI1:         1         12         27          1  Function call interrupts
IPI2:         0          0          0          0  CPU wake-up interrupts
---
 arch/riscv/include/asm/smp.h |  5 +++++
 arch/riscv/kernel/irq.c      |  9 +++++++++
 arch/riscv/kernel/smp.c      | 30 ++++++++++++++++++++++++++++--
 3 files changed, 42 insertions(+), 2 deletions(-)
arch/riscv/include/asm/smp.h +5 -0
index 8145b8657d20..a87e292becba 100644
@@ -48,6 +48,11 @@ enum ipi_message_type {
 void send_ipi_message(const struct cpumask *to_whom,
 		      enum ipi_message_type operation);
 
+struct seq_file;
+
+/* print IPI stats */
+void show_ipi_stats(struct seq_file *p, int prec);
+
 /* SMP initialization hook for setup_arch */
 void __init setup_smp(void);
 
arch/riscv/kernel/irq.c +9 -0
index 7e14b0d9a71d..9177552cd76c 100644
@@ -8,6 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/irqchip.h>
 #include <linux/irqdomain.h>
+#include <linux/seq_file.h>
 
 /*
  * Possible interrupt causes:
@@ -24,6 +25,14 @@
  */
 #define INTERRUPT_CAUSE_FLAG	(1UL << (__riscv_xlen - 1))
 
+int arch_show_interrupts(struct seq_file *p, int prec)
+{
+#ifdef CONFIG_SMP
+	show_ipi_stats(p, prec);
+#endif
+	return 0;
+}
+
 asmlinkage void __irq_entry do_IRQ(struct pt_regs *regs, unsigned long cause)
 {
 	struct pt_regs *old_regs = set_irq_regs(regs);
arch/riscv/kernel/smp.c +28 -2
index 629456bb6122..4e67a690edbc 100644
@@ -22,6 +22,7 @@
 #include <linux/interrupt.h>
 #include <linux/smp.h>
 #include <linux/sched.h>
+#include <linux/seq_file.h>
 
 #include <asm/sbi.h>
 #include <asm/tlbflush.h>
@@ -29,6 +30,7 @@
 
 /* A collection of single bit ipi messages.  */
 static struct {
+	unsigned long stats[IPI_MAX] ____cacheline_aligned;
 	unsigned long bits ____cacheline_aligned;
 } ipi_data[NR_CPUS] __cacheline_aligned;
 
@@ -61,6 +63,7 @@ int setup_profiling_timer(unsigned int multiplier)
 void riscv_software_interrupt(void)
 {
 	unsigned long *pending_ipis = &ipi_data[smp_processor_id()].bits;
+	unsigned long *stats = ipi_data[smp_processor_id()].stats;
 
 	/* Clear pending IPI */
 	csr_clear(sip, SIE_SSIE);
@@ -75,11 +78,15 @@ void riscv_software_interrupt(void)
 		if (ops == 0)
 			return;
 
-		if (ops & (1 << IPI_RESCHEDULE))
+		if (ops & (1 << IPI_RESCHEDULE)) {
+			stats[IPI_RESCHEDULE]++;
 			scheduler_ipi();
+		}
 
-		if (ops & (1 << IPI_CALL_FUNC))
+		if (ops & (1 << IPI_CALL_FUNC)) {
+			stats[IPI_CALL_FUNC]++;
 			generic_smp_call_function_interrupt();
+		}
 
 		BUG_ON((ops >> IPI_MAX) != 0);
 
@@ -105,6 +112,25 @@ send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
 	sbi_send_ipi(cpumask_bits(&hartid_mask));
 }
 
+static const char *ipi_names[IPI_MAX] = {
+	[IPI_RESCHEDULE] = "Rescheduling interrupts",
+	[IPI_CALL_FUNC] = "Function call interrupts",
+	[IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
+};
+
+void show_ipi_stats(struct seq_file *p, int prec)
+{
+	unsigned int cpu, i;
+
+	for (i = 0; i < IPI_MAX; i++) {
+		seq_printf(p, "%*s%u:%s", prec - 1, "IPI", i,
+			   prec >= 4 ? " " : "");
+		for_each_online_cpu(cpu)
+			seq_printf(p, "%10lu ", ipi_data[cpu].stats[i]);
+		seq_printf(p, " %s\n", ipi_names[i]);
+	}
+}
+
 void arch_send_call_function_ipi_mask(struct cpumask *mask)
 {
 	send_ipi_message(mask, IPI_CALL_FUNC);
Signature · 1 line
2.17.1
#1 lore raw
Quoted 5 lines · Anup Patel

This patch provides arch_show_interrupts() implementation to show IPI stats via /proc/interrupts.

Now the contents of /proc/interrupts" will look like below:
CPU0 CPU1 CPU2 CPU3

Quoted 7 lines
  8:         17          7          6         14  SiFive PLIC   8  virtio0
 10:         10         10          9         11  SiFive PLIC  10  ttyS0
IPI0:       170        673        251         79  Rescheduling interrupts
IPI1:         1         12         27          1  Function call interrupts
IPI2:         0          0          0          0  CPU wake-up interrupts

Thanks, this looks pretty sensible to me. Maybe we want to also show timer interrupts if we do this?

Quoted 11 lines
arch/riscv/kernel/irq.c +1 -0
@@ -8,6 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/irqchip.h>
 #include <linux/irqdomain.h>
+#include <linux/seq_file.h>
 
 /*
  * Possible interrupt causes:

arch/riscv/kernel/irq.c line 34

Quoted 10 lines
arch/riscv/kernel/irq.c +7 -0
@@ -24,6 +25,14 @@
  */
 #define INTERRUPT_CAUSE_FLAG	(1UL << (__riscv_xlen - 1))
 
+int arch_show_interrupts(struct seq_file *p, int prec)
+{
+#ifdef CONFIG_SMP
+	show_ipi_stats(p, prec);
+#endif
+	return 0;
+}

If we don't also add timer stats I'd just move arch_show_interrupts to smp.c and make it conditional. If we don't this split might make more sense.

arch/riscv/kernel/irq.c

Quoted 5 lines
arch/riscv/kernel/irq.c +5 -0
+static const char *ipi_names[IPI_MAX] = {
+	[IPI_RESCHEDULE] = "Rescheduling interrupts",
+	[IPI_CALL_FUNC] = "Function call interrupts",
+	[IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
+};

No need for the explicit array size. Also please use a few tabs to align this nicely:

static const char *ipi_names[] = {
[IPI_RESCHEDULE] = "Rescheduling interrupts",
[IPI_CALL_FUNC] = "Function call interrupts",
[IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
};

author
#2 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Anup Patel

This patch provides arch_show_interrupts() implementation to show IPI stats via /proc/interrupts.

Now the contents of /proc/interrupts" will look like below:
CPU0 CPU1 CPU2 CPU3

  8:         17          7          6         14  SiFive PLIC   8  virtio0
 10:         10         10          9         11  SiFive PLIC  10  ttyS0
IPI0:       170        673        251         79  Rescheduling interrupts
IPI1:         1         12         27          1  Function call interrupts
IPI2:         0          0          0          0  CPU wake-up interrupts
Quoted 4 lines
Quoted 1 line

Thanks, this looks pretty sensible to me. Maybe we want to also show timer interrupts if we do this?

Let's not include timer stats here until RISCV INTC driver is concluded. We can do it as separate patch if required.

Quoted 15 lines
Quoted 15 lines
arch/riscv/kernel/irq.c +1 -0
@@ -8,6 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/irqchip.h>
 #include <linux/irqdomain.h>
+#include <linux/seq_file.h>
 
 /*
  * Possible interrupt causes:
@@ -24,6 +25,14 @@
  */
 #define INTERRUPT_CAUSE_FLAG (1UL << (__riscv_xlen - 1))
 
Quoted 11 lines

arch/riscv/kernel/irq.c line 34

Quoted 7 lines
arch/riscv/kernel/irq.c +7 -0
+int arch_show_interrupts(struct seq_file *p, int prec)
+{
+#ifdef CONFIG_SMP
+     show_ipi_stats(p, prec);
+#endif
+     return 0;
+}

If we don't also add timer stats I'd just move arch_show_interrupts to smp.c and make it conditional. If we don't this split might make more sense.

I understand you want to avoid #ifdef here. We can do same thing by having empty inline function show_ipi_stats() in asm/smp.h for !CONFIG_SMP case. This way we can keep arch_show_interrupts() in kernel/irq.c which is intuitively correct location for arch_show_interrupts().

Quoted 10 lines

arch/riscv/kernel/irq.c

Quoted 6 lines
arch/riscv/kernel/irq.c +5 -0
+static const char *ipi_names[IPI_MAX] = {
+     [IPI_RESCHEDULE] = "Rescheduling interrupts",
+     [IPI_CALL_FUNC] = "Function call interrupts",
+     [IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
+};

No need for the explicit array size. Also please use a few tabs to align this nicely:

Quoted 5 lines

static const char *ipi_names[] = {

        [IPI_RESCHEDULE]        = "Rescheduling interrupts",
        [IPI_CALL_FUNC]         = "Function call interrupts",
        [IPI_CALL_WAKEUP]       = "CPU wake-up interrupts",

};

Sure, will do.

Regards,
Anup

#3 lore raw
In reply to Christoph Hellwig
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Anup Patel

This patch provides arch_show_interrupts() implementation to show IPI stats via /proc/interrupts.

Now the contents of /proc/interrupts" will look like below:
CPU0 CPU1 CPU2 CPU3

  8:         17          7          6         14  SiFive PLIC   8  virtio0
 10:         10         10          9         11  SiFive PLIC  10  ttyS0
IPI0:       170        673        251         79  Rescheduling interrupts
IPI1:         1         12         27          1  Function call interrupts
IPI2:         0          0          0          0  CPU wake-up interrupts
Quoted 4 lines
Quoted 1 line

Thanks, this looks pretty sensible to me. Maybe we want to also show timer interrupts if we do this?

IIRC we used to have some issue where the timer interrupt ID in /proc/interrupts aliased with a possible PLIC interrupt ID, but that was back when we had a big mess of chained interrupt drivers that didn't really talk to each other. I think at some point I might have just removed the timer interrupt from /proc/interrupts as a hack, but now that our interrupt controller mess is sorted out it'd be better to have it.

I'm fine taking this without the timer interrupts, as something is better than nothing.

Quoted 14 lines
Quoted 14 lines
arch/riscv/kernel/irq.c +1 -0
@@ -8,6 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/irqchip.h>
 #include <linux/irqdomain.h>
+#include <linux/seq_file.h>
 
 /*
  * Possible interrupt causes:
@@ -24,6 +25,14 @@
  */
 #define INTERRUPT_CAUSE_FLAG	(1UL << (__riscv_xlen - 1))
 
Quoted 11 lines

arch/riscv/kernel/irq.c line 34

Quoted 7 lines
arch/riscv/kernel/irq.c +7 -0
+int arch_show_interrupts(struct seq_file *p, int prec)
+{
+#ifdef CONFIG_SMP
+	show_ipi_stats(p, prec);
+#endif
+	return 0;
+}

If we don't also add timer stats I'd just move arch_show_interrupts to smp.c and make it conditional. If we don't this split might make more sense.

Makes sense, but I think timer interrupts are more interesting to see than IPIs so we'll eventually pipe them through. Might just be my workloads, though :)

Quoted 9 lines

arch/riscv/kernel/irq.c

Quoted 5 lines
arch/riscv/kernel/irq.c +5 -0
+static const char *ipi_names[IPI_MAX] = {
+	[IPI_RESCHEDULE] = "Rescheduling interrupts",
+	[IPI_CALL_FUNC] = "Function call interrupts",
+	[IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
+};

No need for the explicit array size. Also please use a few tabs to align this nicely:

Quoted 5 lines

static const char *ipi_names[] = {
[IPI_RESCHEDULE] = "Rescheduling interrupts",
[IPI_CALL_FUNC] = "Function call interrupts",
[IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
};

I don't see a v2 of this, was there one? If not then I'll just clean up ipi_names and drop this on for-next.

Thanks for the patch!

author
#4 lore raw
Quoted 19 lines · Palmer Dabbelt
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Anup Patel

This patch provides arch_show_interrupts() implementation to show IPI stats via /proc/interrupts.

Now the contents of /proc/interrupts" will look like below:
CPU0 CPU1 CPU2 CPU3

  8:         17          7          6         14  SiFive PLIC   8  virtio0
 10:         10         10          9         11  SiFive PLIC  10  ttyS0
IPI0:       170        673        251         79  Rescheduling interrupts
IPI1:         1         12         27          1  Function call interrupts
IPI2:         0          0          0          0  CPU wake-up interrupts
Quoted 4 lines
Quoted 1 line

Thanks, this looks pretty sensible to me. Maybe we want to also show timer interrupts if we do this?

Quoted 6 lines

IIRC we used to have some issue where the timer interrupt ID in /proc/interrupts aliased with a possible PLIC interrupt ID, but that was back when we had a big mess of chained interrupt drivers that didn't really talk to each other. I think at some point I might have just removed the timer interrupt from /proc/interrupts as a hack, but now that our interrupt controller mess is sorted out it'd be better to have it.

If we have irqdomain and irqchip for HLIC then showing timer interrupts becomes cleaner. My RISCV INTC patch achieves this.

Quoted 3 lines

I'm fine taking this without the timer interrupts, as something is better than nothing.

Sure.

Quoted 45 lines
Quoted 15 lines
Quoted 15 lines
arch/riscv/kernel/irq.c +1 -0
@@ -8,6 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/irqchip.h>
 #include <linux/irqdomain.h>
+#include <linux/seq_file.h>
 
 /*
  * Possible interrupt causes:
@@ -24,6 +25,14 @@
  */
 #define INTERRUPT_CAUSE_FLAG        (1UL << (__riscv_xlen - 1))
 
Quoted 11 lines

arch/riscv/kernel/irq.c line 34

Quoted 7 lines
arch/riscv/kernel/irq.c +7 -0
+int arch_show_interrupts(struct seq_file *p, int prec)
+{
+#ifdef CONFIG_SMP
+    show_ipi_stats(p, prec);
+#endif
+    return 0;
+}

If we don't also add timer stats I'd just move arch_show_interrupts to smp.c and make it conditional. If we don't this split might make more sense.

Makes sense, but I think timer interrupts are more interesting to see than IPIs so we'll eventually pipe them through. Might just be my workloads, though :)

Quoted 9 lines

arch/riscv/kernel/irq.c

Quoted 5 lines
arch/riscv/kernel/irq.c +5 -0
+static const char *ipi_names[IPI_MAX] = {
+    [IPI_RESCHEDULE] = "Rescheduling interrupts",
+    [IPI_CALL_FUNC] = "Function call interrupts",
+    [IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
+};

No need for the explicit array size. Also please use a few tabs to align this nicely:

Quoted 5 lines

static const char *ipi_names[] = {

      [IPI_RESCHEDULE]        = "Rescheduling interrupts",
      [IPI_CALL_FUNC]         = "Function call interrupts",
      [IPI_CALL_WAKEUP]       = "CPU wake-up interrupts",

};

Quoted 4 lines

I don't see a v2 of this, was there one? If not then I'll just clean up ipi_names and drop this on for-next.

Thanks for the patch!

I will send v3 patch because IPI_CALL_WAKEUP is not going to be available.

I will base v3 patch upon v5 of Atish's patchset. Atish will take v3 of this patch and make it part of his v6 patchset so that it will be easy for you to apply.

Regards,
Anup

#5 lore raw
Quoted 84 lines · anup at brainfault.org
Quoted 19 lines · Palmer Dabbelt
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Anup Patel

This patch provides arch_show_interrupts() implementation to show IPI stats via /proc/interrupts.

Now the contents of /proc/interrupts" will look like below:
CPU0 CPU1 CPU2 CPU3

  8:         17          7          6         14  SiFive PLIC   8  virtio0
 10:         10         10          9         11  SiFive PLIC  10  ttyS0
IPI0:       170        673        251         79  Rescheduling interrupts
IPI1:         1         12         27          1  Function call interrupts
IPI2:         0          0          0          0  CPU wake-up interrupts
Quoted 4 lines
Quoted 1 line

Thanks, this looks pretty sensible to me. Maybe we want to also show timer interrupts if we do this?

Quoted 6 lines

IIRC we used to have some issue where the timer interrupt ID in /proc/interrupts aliased with a possible PLIC interrupt ID, but that was back when we had a big mess of chained interrupt drivers that didn't really talk to each other. I think at some point I might have just removed the timer interrupt from /proc/interrupts as a hack, but now that our interrupt controller mess is sorted out it'd be better to have it.

If we have irqdomain and irqchip for HLIC then showing timer interrupts becomes cleaner. My RISCV INTC patch achieves this.

Quoted 3 lines

I'm fine taking this without the timer interrupts, as something is better than nothing.

Sure.

Quoted 48 lines
Quoted 15 lines
Quoted 15 lines
arch/riscv/kernel/irq.c +1 -0
@@ -8,6 +8,7 @@
 #include <linux/interrupt.h>
 #include <linux/irqchip.h>
 #include <linux/irqdomain.h>
+#include <linux/seq_file.h>
 
 /*
  * Possible interrupt causes:
@@ -24,6 +25,14 @@
  */
 #define INTERRUPT_CAUSE_FLAG        (1UL << (__riscv_xlen - 1))
 
Quoted 11 lines

arch/riscv/kernel/irq.c line 34

Quoted 7 lines
arch/riscv/kernel/irq.c +7 -0
+int arch_show_interrupts(struct seq_file *p, int prec)
+{
+#ifdef CONFIG_SMP
+    show_ipi_stats(p, prec);
+#endif
+    return 0;
+}

If we don't also add timer stats I'd just move arch_show_interrupts to smp.c and make it conditional. If we don't this split might make more sense.

Makes sense, but I think timer interrupts are more interesting to see than IPIs so we'll eventually pipe them through. Might just be my workloads, though :)

Quoted 9 lines

arch/riscv/kernel/irq.c

Quoted 5 lines
arch/riscv/kernel/irq.c +5 -0
+static const char *ipi_names[IPI_MAX] = {
+    [IPI_RESCHEDULE] = "Rescheduling interrupts",
+    [IPI_CALL_FUNC] = "Function call interrupts",
+    [IPI_CALL_WAKEUP] = "CPU wake-up interrupts",
+};

No need for the explicit array size. Also please use a few tabs to align this nicely:

Quoted 5 lines

static const char *ipi_names[] = {

      [IPI_RESCHEDULE]        = "Rescheduling interrupts",
      [IPI_CALL_FUNC]         = "Function call interrupts",
      [IPI_CALL_WAKEUP]       = "CPU wake-up interrupts",

};

I don't see a v2 of this, was there one? If not then I'll just clean up ipi_names and drop this on for-next.

Quoted 7 lines
Quoted 1 line

Thanks for the patch!

I will send v3 patch because IPI_CALL_WAKEUP is not going to be available.

I will base v3 patch upon v5 of Atish's patchset. Atish will take v3 of this patch and make it part of his v6 patchset so that it will be easy for you to apply.

Thanks!