powerpc/irq: Use optimizations for /proc/interrupts
Shrikanth Hegde
reviewerv2 cover powerpc/irq: Use optimizations for /proc/interrupts
v1-> v2:
- Collected the tags (Thanks to Christophe Leroy)
- Rename skip to optional and check optional while printing (Christophe Leroy)
- Decided not to add cpu_has_feature(CPU_FTR_DBELL) while printing. This feature is mostly true for majority of platforms and adding check means more ifdefs in that path. Prinitng "Doorbell interrupts" shouldn't cause any issue when feature if off since all entries would be zero. (sashiko)
This series is based on work by Thomas Gleixner[1]. Further details can be found in cover-letter of v1.
======== Performance Data ==================
Time taken to read /proc/interrupts 1000 times[2]
Base : 103us
v6[1] : 63us
v6+patch 1+2 : 57us
v6+patch 1+2+3 : 54us
Base: tip/master at 'ddfd3966d0d4 ("Merge branch into tip/master: 'x86/tdx'")'
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/all/87jysxw65f.ffs@tglx/
v1: https://lore.kernel.org/all/[email protected]/
Shrikanth Hegde (3):
powerpc/irq: Move __softirq_pending out of irq_stat powerpc/irq: Make irqstats array based powerpc/irq: Suppress unlikely interrupt stats by default
arch/powerpc/include/asm/hardirq.h | 31 ++++--- arch/powerpc/kernel/dbell.c | 2 +- arch/powerpc/kernel/irq.c | 131 +++++++++++++++-------------- arch/powerpc/kernel/time.c | 6 +- arch/powerpc/kernel/traps.c | 11 +-- arch/powerpc/kernel/watchdog.c | 2 +- 6 files changed, 95 insertions(+), 88 deletions(-)
Signature · 1 line
2.47.3
Shrikanth Hegde
reviewerPATCH v2 1/3 powerpc/irq: Move __softirq_pending out of irq_stat
__softirq_pending isn't part of arch specific irq_stats. It is used by softirq core for various decision making such as whether to kick off ksoftirqd.
Move it out of irq_cpustat_t. This makes it simple to make irq_cpustat_t array based approach.
--- arch/powerpc/include/asm/hardirq.h | 3 ++- arch/powerpc/kernel/irq.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/include/asm/hardirq.h +2 -1
@@ -6,7 +6,6 @@#include <linux/irq.h> typedef struct { - unsigned int __softirq_pending; unsigned int timer_irqs_event; unsigned int broadcast_irqs_event; unsigned int timer_irqs_others;
@@ -23,6 +22,8 @@ typedef struct { }____cacheline_aligned irq_cpustat_t;DECLARE_PER_CPU_SHARED_ALIGNED (irq_cpustat_t, irq_stat); +DECLARE_PER_CPU(unsigned int, __softirq_pending); +#define local_softirq_pending_ref __softirq_pending#define __ARCH_IRQ_STAT#define __ARCH_IRQ_EXIT_IRQS_DISABLED
arch/powerpc/kernel/irq.c +1 -0
@@ -73,6 +73,7 @@DEFINE_PER_CPU_SHARED_ALIGNED (irq_cpustat_t, irq_stat);EXPORT_PER_CPU_SYMBOL (irq_stat); +DEFINE_PER_CPU(unsigned int, __softirq_pending);#ifdef CONFIG_PPC32 atomic_t ppc_n_lost_interrupts;
Signature · 1 line
2.47.3
Shrikanth Hegde
reviewerPATCH v2 2/3 powerpc/irq: Make irqstats array based
In reply to Shrikanth HegdeCurrent irq_cpustat_t has separate member for handling each arch specific interrupt type. The same can be achieved with array instead indexed by corresponding irq counter type.
This helps to,
- Make it easy to integrate into genirq improvements by calling genirq provided irq_proc_emit_counts. That speeds up quite a bit by printing all 0's once as much as possible.
- Adding a new vector or software counter only requires to update the table and everything just works
- Remove ifdef usage a bit.
- Instead of going through each member, it simply becomes an array traversal.
Time taken to read /proc/interrupts 1000 times.
Base and v6 details can be found in cover-letter.
Base : 103us
v6 : 63us
v6+this_patch : 57us
A Decent 10% reduction can be seen in a system 240 CPUs. As the system size increases the gain would be more as emitting 0 would reduce more and more.
--- arch/powerpc/include/asm/hardirq.h | 27 +++++--- arch/powerpc/kernel/dbell.c | 2 +- arch/powerpc/kernel/irq.c | 107 ++++++++++------------------- arch/powerpc/kernel/time.c | 6 +- arch/powerpc/kernel/traps.c | 11 ++- arch/powerpc/kernel/watchdog.c | 2 +- 6 files changed, 64 insertions(+), 91 deletions(-)
arch/powerpc/include/asm/hardirq.h +17 -10
@@ -5,26 +5,33 @@#include <linux/threads.h> #include <linux/irq.h> -typedef struct { -unsigned int timer_irqs_event; -unsigned int broadcast_irqs_event; -unsigned int timer_irqs_others; -unsigned int pmu_irqs; -unsigned int mce_exceptions; -unsigned int spurious_irqs; -unsigned int sreset_irqs; +enum irq_stat_counts { +IRQ_COUNT_LOC_TIMER , +IRQ_COUNT_BCT_TIMER , +IRQ_COUNT_OTHER_TIMER , +IRQ_COUNT_SPURIOUS , +IRQ_COUNT_PMI , +IRQ_COUNT_MCE , +IRQ_COUNT_NMI_SRESET ,#ifdef CONFIG_PPC_WATCHDOG -unsigned int soft_nmi_irqs; +IRQ_COUNT_WATCHDOG ,#endif #ifdef CONFIG_PPC_DOORBELL -unsigned int doorbell_irqs; +IRQ_COUNT_DOORBELL ,#endif +IRQ_COUNT_MAX , +}; + +typedef struct { +unsigned int counts[IRQ_COUNT_MAX ]; }____cacheline_aligned irq_cpustat_t ;DECLARE_PER_CPU_SHARED_ALIGNED (irq_cpustat_t, irq_stat); DECLARE_PER_CPU(unsigned int, __softirq_pending);#define local_softirq_pending_ref __softirq_pending +#define inc_irq_stat (index) __this_cpu_inc(irq_stat.counts[IRQ_COUNT_##index]) +#define __ARCH_IRQ_STAT#define __ARCH_IRQ_EXIT_IRQS_DISABLED
arch/powerpc/kernel/dbell.c +1 -1
@@ -31,7 +31,7 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(doorbell_exception)do_hard_irq_enable ();kvmppc_clear_host_ipi (smp_processor_id ()); -__this_cpu_inc (irq_stat.doorbell_irqs); +inc_irq_stat (DOORBELL );smp_ipi_demux_relaxed ();/* already performed the barrier */
arch/powerpc/kernel/irq.c +38 -69
148 lines not on this page · raw message
arch/powerpc/kernel/time.c +3 -3
@@ -574,13 +574,13 @@ DEFINE_INTERRUPT_HANDLER_ASYNC(timer_interrupt) now =get_tb ();if (now >= *next_tb) { evt->event_handler (evt); -__this_cpu_inc (irq_stat.timer_irqs_event); +inc_irq_stat (LOC_TIMER ); }else { now = *next_tb - now;if (now > decrementer_max) now = decrementer_max;set_dec_or_work (now); -__this_cpu_inc (irq_stat.timer_irqs_others); +inc_irq_stat (OTHER_TIMER ); }trace_timer_interrupt_exit (regs);
@@ -593,7 +593,7 @@ EXPORT_SYMBOL(timer_interrupt);void timer_broadcast_interrupt (void ) {tick_receive_broadcast (); -__this_cpu_inc (irq_stat.broadcast_irqs_event); +inc_irq_stat (BCT_TIMER ); }#endif
arch/powerpc/kernel/traps.c +4 -7
@@ -459,8 +459,7 @@ DEFINE_INTERRUPT_HANDLER_NMI(system_reset_exception) }hv_nmi_check_nonrecoverable (regs); - -__this_cpu_inc (irq_stat.sreset_irqs); +inc_irq_stat (NMI_SRESET );/* See if any machine dependent calls */ if (ppc_md.system_reset_exception) {
@@ -817,7 +816,7 @@ static void __machine_check_exception(struct pt_regs *regs) {int recover =0 ; -__this_cpu_inc (irq_stat.mce_exceptions); +inc_irq_stat (MCE );add_taint (TAINT_MACHINE_CHECK ,LOCKDEP_NOW_UNRELIABLE );
@@ -1932,8 +1931,7 @@ DEFINE_INTERRUPT_HANDLER(vsx_unavailable_tm)DECLARE_INTERRUPT_HANDLER_NMI (performance_monitor_exception_nmi);DEFINE_INTERRUPT_HANDLER_NMI (performance_monitor_exception_nmi) { -__this_cpu_inc (irq_stat.pmu_irqs); - +inc_irq_stat (PMI );perf_irq (regs);return 0 ;
@@ -1943,8 +1941,7 @@ DEFINE_INTERRUPT_HANDLER_NMI(performance_monitor_exception_nmi)DECLARE_INTERRUPT_HANDLER_ASYNC (performance_monitor_exception_async);DEFINE_INTERRUPT_HANDLER_ASYNC (performance_monitor_exception_async) { -__this_cpu_inc (irq_stat.pmu_irqs); - +inc_irq_stat (PMI );perf_irq (regs); }
arch/powerpc/kernel/watchdog.c +1 -1
@@ -381,7 +381,7 @@ DEFINE_INTERRUPT_HANDLER_NMI(soft_nmi_interrupt)if (!cpumask_test_cpu (cpu, &wd_cpus_enabled))return 0 ; -__this_cpu_inc (irq_stat.soft_nmi_irqs); +inc_irq_stat (WATCHDOG ); tb =get_tb ();if (tb -per_cpu (wd_timer_tb, cpu) >= wd_panic_timeout_tb) {
Signature · 1 line
2.47.3
Shrikanth Hegde
reviewerPATCH v2 3/3 powerpc/irq: Suppress unlikely interrupt stats by default
In reply to Shrikanth HegdeSome interrupts are always zero and that is expected since they occur very rarely and are mostly error indications. Don't print them by default.
"MCE" - "Machine check exceptions"
"NMI" - "System Reset interrupts"
Print them if they occur once. Maintain a bitmap to know which interrupts are to be printed.
Time taken to read /proc/interrupts 1000 times.
Base and v6 details can be found in cover-letter.
Base : 103us v6 : 63us v6+patch 1+2 : 57us v6+patch 1+2+3 : 54us
Patch 3 shows an additional 5% gain compared to patch 1+2. So it does make sense to print them only if they are ever set.
Note: Since /proc/interrupts depend on kconfig and arch dependent, userspace tools don't make explicit assumptions.
--- arch/powerpc/include/asm/hardirq.h | 1 + arch/powerpc/kernel/irq.c | 37 +++++++++++++++++++++++++++--- arch/powerpc/kernel/traps.c | 4 ++-- 3 files changed, 37 insertions(+), 5 deletions(-)
arch/powerpc/include/asm/hardirq.h +1 -0
@@ -31,6 +31,7 @@ DECLARE_PER_CPU(unsigned int, __softirq_pending);#define local_softirq_pending_ref __softirq_pending#define inc_irq_stat (index) __this_cpu_inc(irq_stat.counts[IRQ_COUNT_##index]) +void inc_irq_stat_and_enable (enum irq_stat_counts which);#define __ARCH_IRQ_STAT#define __ARCH_IRQ_EXIT_IRQS_DISABLED
arch/powerpc/kernel/irq.c +34 -3
@@ -87,9 +87,13 @@ u32 tau_interrupts(unsigned long cpu);struct irq_stat_info {const char *symbol;const char *text; +int optional; }; -#define ISE (idx, sym, txt)[IRQ_COUNT_##idx] = { .symbol = sym, .text = txt} +/* ISE - IRQ STAT ENABLED, ISC - IRQ STAT CONDITIONAL */ +#define ISE (idx, sym, txt)[IRQ_COUNT_##idx] = { .symbol = sym, .text = txt, .optional = 0} +#define ISC (idx, sym, txt)[IRQ_COUNT_##idx] = { .symbol = sym, .text = txt, .optional = 1} +static struct irq_stat_info irq_stat_info[IRQ_COUNT_MAX ]__ro_after_init = {ISE (LOC_TIMER ,"LOC" ," Local timer interrupts for timer event device\n" ),
@@ -97,8 +101,8 @@ static struct irq_stat_info irq_stat_info[IRQ_COUNT_MAX] __ro_after_init = {ISE (OTHER_TIMER ,"LOC" ," Local timer interrupts for others\n" ),ISE (SPURIOUS ,"SPU" ," Spurious interrupts\n" ),ISE (PMI ,"PMI" ," Performance monitoring interrupts\n" ), -ISE (MCE ,"MCE" ," Machine check exceptions\n" ), -ISE (NMI_SRESET ,"NMI" ," System Reset interrupts\n" ), +ISC (MCE ,"MCE" ," Machine check exceptions\n" ), +ISC (NMI_SRESET ,"NMI" ," System Reset interrupts\n" ), #ifdef CONFIG_PPC_WATCHDOG ISE(WATCHDOG, "WDG", " Watchdog soft-NMI interrupts\n"), #endif
@@ -107,11 +111,25 @@ static struct irq_stat_info irq_stat_info[IRQ_COUNT_MAX] __ro_after_init = {#endif }; +/* +* Used for default disabled counters to increment the stats and to enable the +* entry for /proc/interrupts output. +*/ +static DECLARE_BITMAP(irq_stat_count_show, IRQ_COUNT_MAX) __read_mostly; +void inc_irq_stat_and_enable (enum irq_stat_counts which) +{ +__this_cpu_inc (irq_stat.counts[which]); +set_bit (which, irq_stat_count_show); +} +int arch_show_interrupts (struct seq_file *p,int prec) {const struct irq_stat_info *info = irq_stat_info;for (unsigned int i =0 ; i <ARRAY_SIZE (irq_stat_info); i++, info++) { +if (info->optional && !test_bit (i, irq_stat_count_show)) +continue ; +seq_printf (p,"%*s:" , prec, info->symbol);irq_proc_emit_counts (p, &irq_stat.counts[i]);seq_puts (p, info->text);
@@ -138,6 +156,19 @@ int arch_show_interrupts(struct seq_file *p, int prec)return 0 ; } +static int __init irq_init_stats (void ) +{ +struct irq_stat_info *info = irq_stat_info; + +for (unsigned int i =0 ; i <ARRAY_SIZE (irq_stat_info); i++, info++) { +if (info->optional ==0 ) +set_bit (i, irq_stat_count_show); + } + +return 0 ; +} +late_initcall (irq_init_stats); +/* * /proc/stat helpers */
arch/powerpc/kernel/traps.c +2 -2
@@ -459,7 +459,7 @@ DEFINE_INTERRUPT_HANDLER_NMI(system_reset_exception) }hv_nmi_check_nonrecoverable (regs); -inc_irq_stat (NMI_SRESET ); +inc_irq_stat_and_enable (IRQ_COUNT_NMI_SRESET );/* See if any machine dependent calls */ if (ppc_md.system_reset_exception) {
@@ -816,7 +816,7 @@ static void __machine_check_exception(struct pt_regs *regs) {int recover =0 ; -inc_irq_stat (MCE ); +inc_irq_stat_and_enable (IRQ_COUNT_MCE );add_taint (TAINT_MACHINE_CHECK ,LOCKDEP_NOW_UNRELIABLE );
Signature · 1 line
2.47.3