s390/traps: Add exception statistics
Heiko Carstens
maintainerPATCH v2 1/1 s390/traps: Add exception statistics
From: Sven Schnelle <[email protected]>
Add a new debugfs file which displays the number of exceptions (program checks) per CPU. This is helpful for debugging purposes.
The statistics are typically available at/sys/kernel/debug/s390/exceptions.
[ [email protected]: Forward ported code, changed file location ]
---
Notes:
v2:
- Fix / remove broken iterator handling as reported by Sashiko:
https://sashiko.dev/#/patchset/[email protected]?part=1arch/s390/kernel/traps.c | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
arch/s390/kernel/traps.c +40 -1
@@ -9,7 +9,9 @@* Copyright (C) 1991, 1992 Linus Torvalds */ +#include <linux/capability.h> #include <linux/cpufeature.h> +#include <linux/debugfs.h> #include <linux/kprobes.h> #include <linux/kdebug.h> #include <linux/randomize_kstack.h>
@@ -33,6 +35,12 @@#include <asm/fault.h> #include "entry.h" +struct pgm_stat { +unsigned int count[128 ]; +}; + +static DEFINE_PER_CPU_SHARED_ALIGNED(struct pgm_stat, pgm_stat); +static inline void __user *get_trap_ip (struct pt_regs *regs) {unsigned long address;
@@ -332,6 +340,7 @@ void noinstr __do_pgm_check(struct pt_regs *regs)struct lowcore *lc =get_lowcore ();bool percpu_needs_fixup;irqentry_state_t state; +struct pgm_stat *stat;unsigned int trapnr;union teid teid;
@@ -339,6 +348,10 @@ void noinstr __do_pgm_check(struct pt_regs *regs) regs->int_code = lc->pgm_int_code; regs->int_parm_long = teid.val; regs->monitor_code = lc->monitor_code; + + trapnr = regs->int_code &PGM_INT_CODE_MASK ; + stat =this_cpu_ptr (&pgm_stat); + stat->count[trapnr]++;/* * In case of a guest fault, short-circuit the fault handler and return. * This way the sie64a() function will return 0; fault address and
@@ -383,7 +396,6 @@ void noinstr __do_pgm_check(struct pt_regs *regs)if (!irqs_disabled_flags (regs->psw.mask))trace_hardirqs_on ();__arch_local_irq_ssm (regs->psw.mask & ~PSW_MASK_PER ); - trapnr = regs->int_code &PGM_INT_CODE_MASK ;if (trapnr) pgm_check_table[trapnr](regs); out:
@@ -393,6 +405,33 @@ void noinstr __do_pgm_check(struct pt_regs *regs)percpu_exit (regs, percpu_needs_fixup); } +static int pgm_check_stat_show (struct seq_file *p,void *v) +{ +int i, cpu; + +cpus_read_lock (); +seq_puts (p," " ); +for_each_online_cpu (cpu) +seq_printf (p,"CPU%-8d" , cpu); +seq_putc (p,'\n' ); +for (i =0 ; i <128 ; i++) { +seq_printf (p,"%02x: " , i); +for_each_online_cpu (cpu) +seq_printf (p,"%10u " ,per_cpu (pgm_stat, cpu).count[i]); +seq_putc (p,'\n' ); + } +cpus_read_unlock (); +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (pgm_check_stat); + +static int __init debugfs_pgm_check_init (void ) +{ +debugfs_create_file ("exceptions" ,0400 , arch_debugfs_dir,NULL , &pgm_check_stat_fops); +return 0 ; +} +late_initcall (debugfs_pgm_check_init); +/* * The program check table contains exactly 128 (0x00-0x7f) entries. Each * line defines the function to be called corresponding to the program check
Signature · 1 line
2.53.0
Am 17.06.26 um 14:33 schrieb Heiko Carstens:
Quoted 5 lines
From: Sven Schnelle <[email protected]>
Add a new debugfs file which displays the number of exceptions (program checks) per CPU. This is helpful for debugging purposes.
Quoted 8 lines
The statistics are typically available at
/sys/kernel/debug/s390/exceptions.[ [email protected]: Forward ported code, changed file location ]
Suggested-by Christian Borntraeger <[email protected]>Signed-off-by Sven Schnelle <[email protected]>Signed-off-by Heiko Carstens <[email protected]>
Looks good to me
Quoted 98 lines
---
Notes:
v2: - Fix / remove broken iterator handling as reported by Sashiko: https://sashiko.dev/#/patchset/[email protected]?part=1arch/s390/kernel/traps.c | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)arch/s390/kernel/traps.c +40
-1@@ -9,7 +9,9 @@* Copyright (C) 1991, 1992 Linus Torvalds */ +#include <linux/capability.h> #include <linux/cpufeature.h> +#include <linux/debugfs.h> #include <linux/kprobes.h> #include <linux/kdebug.h> #include <linux/randomize_kstack.h> @@ -33,6 +35,12 @@#include <asm/fault.h> #include "entry.h" +struct pgm_stat { +unsigned int count[128 ]; +}; + +static DEFINE_PER_CPU_SHARED_ALIGNED(struct pgm_stat, pgm_stat); +static inline void __user *get_trap_ip (struct pt_regs *regs) {unsigned long address;@@ -332,6 +340,7 @@ void noinstr __do_pgm_check(struct pt_regs *regs)struct lowcore *lc =get_lowcore ();bool percpu_needs_fixup;irqentry_state_t state; +struct pgm_stat *stat;unsigned int trapnr;union teid teid;@@ -339,6 +348,10 @@ void noinstr __do_pgm_check(struct pt_regs *regs) regs->int_code = lc->pgm_int_code; regs->int_parm_long = teid.val; regs->monitor_code = lc->monitor_code; + + trapnr = regs->int_code &PGM_INT_CODE_MASK ; + stat =this_cpu_ptr (&pgm_stat); + stat->count[trapnr]++;/* * In case of a guest fault, short-circuit the fault handler and return. * This way the sie64a() function will return 0; fault address and @@ -383,7 +396,6 @@ void noinstr __do_pgm_check(struct pt_regs *regs)if (!irqs_disabled_flags (regs->psw.mask))trace_hardirqs_on ();__arch_local_irq_ssm (regs->psw.mask & ~PSW_MASK_PER ); - trapnr = regs->int_code &PGM_INT_CODE_MASK ;if (trapnr) pgm_check_table[trapnr](regs); out:@@ -393,6 +405,33 @@ void noinstr __do_pgm_check(struct pt_regs *regs)percpu_exit (regs, percpu_needs_fixup); } +static int pgm_check_stat_show (struct seq_file *p,void *v) +{ +int i, cpu; + +cpus_read_lock (); +seq_puts (p," " ); +for_each_online_cpu (cpu) +seq_printf (p,"CPU%-8d" , cpu); +seq_putc (p,'\n' ); +for (i =0 ; i <128 ; i++) { +seq_printf (p,"%02x: " , i); +for_each_online_cpu (cpu) +seq_printf (p,"%10u " ,per_cpu (pgm_stat, cpu).count[i]); +seq_putc (p,'\n' ); + } +cpus_read_unlock (); +return 0 ; +} +DEFINE_SHOW_ATTRIBUTE (pgm_check_stat); + +static int __init debugfs_pgm_check_init (void ) +{ +debugfs_create_file ("exceptions" ,0400 , arch_debugfs_dir,NULL , &pgm_check_stat_fops); +return 0 ; +} +late_initcall (debugfs_pgm_check_init); +/* * The program check table contains exactly 128 (0x00-0x7f) entries. Each * line defines the function to be called corresponding to the program check
Alexander Gordeev
maintainerQuoted 1 line · Christian Borntraeger
Am 17.06.26 um 14:33 schrieb Heiko Carstens:
...
Quoted 5 lines
Quoted 3 lines
Suggested-by Christian Borntraeger <[email protected]>Signed-off-by Sven Schnelle <[email protected]>Signed-off-by Heiko Carstens <[email protected]>Looks good to me
Does it also translate to Acked-by or Reviewed-by?
Quoted 1 line
Thanks!
Am 19.06.26 um 15:57 schrieb Alexander Gordeev:
Quoted 10 lines · Christian Borntraeger
Quoted 1 line
Am 17.06.26 um 14:33 schrieb Heiko Carstens:
...
Quoted 5 lines
Quoted 3 lines
Suggested-by Christian Borntraeger <[email protected]>Signed-off-by Sven Schnelle <[email protected]>Signed-off-by Heiko Carstens <[email protected]>Looks good to me
Does it also translate to Acked-by or Reviewed-by?
if it still matters,
Quoted 4 lines
Quoted 2 lines
Thanks!
Quoted 14 lines · Heiko Carstens
From: Sven Schnelle <[email protected]>
Add a new debugfs file which displays the number of exceptions (program checks) per CPU. This is helpful for debugging purposes.
The statistics are typically available at
/sys/kernel/debug/s390/exceptions.[ [email protected]: Forward ported code, changed file location ]
Suggested-by Christian Borntraeger <[email protected]>Signed-off-by Sven Schnelle <[email protected]>Signed-off-by Heiko Carstens <[email protected]>---
...
Quoted 2 lines
arch/s390/kernel/traps.c | 41 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-)
Applied, thanks!