From: "Jan Beulich" Subject: Re: [PATCH, v3] reduce 'd' debug key's global impact Date: Thu, 06 May 2010 14:05:41 +0100 Message-ID: <4BE2DAC50200007800001912@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartCAE06EB5.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartCAE06EB5.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On large systems, dumping state may cause time management to get stalled for so long a period that it wouldn't recover. Therefore alter the state dumping logic to alternatively block each CPU as it prints rather than one CPU for a very long time (using the alternative key handling toggle introduced with an earlier patch). Further, instead of using on_selected_cpus(), which is unsafe when the dumping happens from a hardware interrupt, introduce and use a dedicated IPI sending function (which each architecture can implement to its liking) Finally, don't print useless data (e.g. the hypervisor context of the interrupt that is used for triggering the printing, but isn't part of the context that's actually interesting). Signed-off-by: Jan Beulich --- 2010-05-04.orig/xen/arch/ia64/linux-xen/smp.c 2010-05-06 = 14:52:45.000000000 +0200 +++ 2010-05-04/xen/arch/ia64/linux-xen/smp.c 2010-05-06 11:20:40.0000000= 00 +0200 @@ -94,6 +94,7 @@ static volatile struct call_data_struct=20 =20 #define IPI_CALL_FUNC 0 #define IPI_CPU_STOP 1 +#define IPI_STATE_DUMP 2 =20 /* This needs to be cacheline aligned because it is written to by *other* = CPUs. */ static DEFINE_PER_CPU(u64, ipi_operation) ____cacheline_aligned; @@ -202,6 +203,10 @@ handle_IPI (int irq, void *dev_id, struc stop_this_cpu(); break; =20 + case IPI_STATE_DUMP: + dump_execstate(regs); + break; + default: printk(KERN_CRIT "Unknown IPI on CPU %d: = %lu\n", this_cpu, which); break; @@ -479,6 +484,12 @@ smp_send_stop (void) send_IPI_allbutself(IPI_CPU_STOP); } =20 +void +smp_send_state_dump (unsigned int cpu) +{ + send_IPI_single(cpu, IPI_STATE_DUMP); +} + int __init setup_profiling_timer (unsigned int multiplier) { --- 2010-05-04.orig/xen/arch/x86/smp.c 2010-05-06 14:52:45.000000000 = +0200 +++ 2010-05-04/xen/arch/x86/smp.c 2010-05-06 11:21:07.000000000 = +0200 @@ -375,11 +375,24 @@ void smp_send_nmi_allbutself(void) send_IPI_mask(&cpu_online_map, APIC_DM_NMI); } =20 +void smp_send_state_dump(unsigned int cpu) +{ + state_dump_pending(cpu) =3D 1; + smp_send_event_check_cpu(cpu); +} + fastcall void smp_event_check_interrupt(struct cpu_user_regs *regs) { struct cpu_user_regs *old_regs =3D set_irq_regs(regs); ack_APIC_irq(); perfc_incr(ipis); + if ( unlikely(state_dump_pending(smp_processor_id())) ) + { + irq_enter(); + state_dump_pending(smp_processor_id()) =3D 0; + dump_execstate(regs); + irq_exit(); + } set_irq_regs(old_regs); } =20 --- 2010-05-04.orig/xen/common/keyhandler.c 2010-05-04 13:21:53.0000000= 00 +0200 +++ 2010-05-04/xen/common/keyhandler.c 2010-05-06 11:40:55.000000000 = +0200 @@ -71,19 +71,52 @@ static struct keyhandler show_handlers_k .desc =3D "show this message" }; =20 -static void __dump_execstate(void *unused) +#ifdef CONFIG_SMP +static cpumask_t dump_execstate_mask; +#endif + +void dump_execstate(struct cpu_user_regs *regs) { - dump_execution_state(); - printk("*** Dumping CPU%d guest state: ***\n", smp_processor_id()); + unsigned int cpu =3D smp_processor_id(); + + if ( !guest_mode(regs) ) + { + printk("\n*** Dumping CPU%u host state: ***\n", cpu); + show_execution_state(regs); + } if ( is_idle_vcpu(current) ) - printk("No guest context (CPU is idle).\n"); + printk("No guest context (CPU%u is idle).\n", cpu); else + { + printk("*** Dumping CPU%u guest state (d%d:v%d): ***\n", + smp_processor_id(), current->domain->domain_id, + current->vcpu_id); show_execution_state(guest_cpu_user_regs()); + } + +#ifdef CONFIG_SMP + cpu_clear(cpu, dump_execstate_mask); + if ( !alt_key_handling ) + return; + + cpu =3D cycle_cpu(cpu, dump_execstate_mask); + if ( cpu < NR_CPUS ) + smp_send_state_dump(cpu); + else + { + printk("\n"); + + console_end_sync(); + watchdog_enable(); + } +#endif } =20 static void dump_registers(unsigned char key, struct cpu_user_regs *regs) { +#ifdef CONFIG_SMP unsigned int cpu; +#endif =20 /* We want to get everything out that we possibly can. */ watchdog_disable(); @@ -91,17 +124,28 @@ static void dump_registers(unsigned char =20 printk("'%c' pressed -> dumping registers\n", key); =20 +#ifdef CONFIG_SMP + if ( alt_key_handling ) + dump_execstate_mask =3D cpu_online_map; +#endif + /* Get local execution state out immediately, in case we get stuck. = */ - printk("\n*** Dumping CPU%d host state: ***\n", smp_processor_id()); - __dump_execstate(NULL); + dump_execstate(regs); + +#ifdef CONFIG_SMP + if ( alt_key_handling ) + return; =20 for_each_online_cpu ( cpu ) { if ( cpu =3D=3D smp_processor_id() ) continue; - printk("\n*** Dumping CPU%d host state: ***\n", cpu); - on_selected_cpus(cpumask_of(cpu), __dump_execstate, NULL, 1); + cpu_set(cpu, dump_execstate_mask); + smp_send_state_dump(cpu); + while ( cpu_isset(cpu, dump_execstate_mask) ) + cpu_relax(); } +#endif =20 printk("\n"); =20 --- 2010-05-04.orig/xen/include/asm-ia64/linux-xen/asm/ptrace.h 2010-05-06 = 14:52:45.000000000 +0200 +++ 2010-05-04/xen/include/asm-ia64/linux-xen/asm/ptrace.h 2010-05-04 = 13:22:27.000000000 +0200 @@ -280,7 +280,7 @@ struct switch_stack { # define ia64_task_regs(t) (((struct pt_regs *) ((char *) (t) = + IA64_STK_OFFSET)) - 1) # define ia64_psr(regs) ((struct ia64_psr *) = &(regs)->cr_ipsr) #ifdef XEN -# define guest_mode(regs) (ia64_psr(regs)->cpl !=3D 0) +# define guest_mode(regs) (ia64_psr(regs)->cpl && !ia64_psr(r= egs)->vm) # define guest_kernel_mode(regs) (ia64_psr(regs)->cpl =3D=3D = CONFIG_CPL0_EMUL) # define vmx_guest_kernel_mode(regs) (ia64_psr(regs)->cpl =3D=3D 0) # define regs_increment_iip(regs) \ --- 2010-05-04.orig/xen/include/asm-x86/hardirq.h 2010-05-06 = 14:52:57.000000000 +0200 +++ 2010-05-04/xen/include/asm-x86/hardirq.h 2010-05-06 14:54:55.0000000= 00 +0200 @@ -9,6 +9,7 @@ typedef struct { unsigned int __local_irq_count; unsigned int __nmi_count; bool_t __mwait_wakeup; + bool_t __state_dump_pending; } __cacheline_aligned irq_cpustat_t; =20 #include /* Standard mappings for irq_cpustat_t = above */ --- 2010-05-04.orig/xen/include/xen/irq_cpustat.h 2010-05-06 = 14:52:57.000000000 +0200 +++ 2010-05-04/xen/include/xen/irq_cpustat.h 2010-05-06 14:54:49.0000000= 00 +0200 @@ -27,5 +27,6 @@ extern irq_cpustat_t irq_stat[]; #define local_irq_count(cpu) __IRQ_STAT((cpu), __local_irq_count) #define nmi_count(cpu) __IRQ_STAT((cpu), __nmi_count) #define mwait_wakeup(cpu) __IRQ_STAT((cpu), __mwait_wakeup) +#define state_dump_pending(cpu) __IRQ_STAT((cpu), __state_dump_pend= ing) =20 #endif /* __irq_cpustat_h */ --- 2010-05-04.orig/xen/include/xen/lib.h 2010-05-06 14:52:45.0000000= 00 +0200 +++ 2010-05-04/xen/include/xen/lib.h 2010-05-06 11:17:03.000000000 = +0200 @@ -111,4 +111,7 @@ extern int tainted; extern char *print_tainted(char *str); extern void add_taint(unsigned); =20 +struct cpu_user_regs; +void dump_execstate(struct cpu_user_regs *); + #endif /* __LIB_H__ */ --- 2010-05-04.orig/xen/include/xen/smp.h 2010-05-04 13:22:06.0000000= 00 +0200 +++ 2010-05-04/xen/include/xen/smp.h 2010-05-06 10:44:43.000000000 = +0200 @@ -13,6 +13,8 @@ extern void smp_send_event_check_mask(co #define smp_send_event_check_cpu(cpu) \ smp_send_event_check_mask(cpumask_of(cpu)) =20 +extern void smp_send_state_dump(unsigned int cpu); + /* * Prepare machine for booting other CPUs. */ --=__PartCAE06EB5.0__= Content-Type: text/plain; name="dump-exec-state.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="dump-exec-state.patch" On large systems, dumping state may cause time management to get=0Astalled = for so long a period that it wouldn't recover. Therefore alter=0Athe state = dumping logic to alternatively block each CPU as it prints=0Arather than = one CPU for a very long time (using the alternative key=0Ahandling toggle = introduced with an earlier patch).=0A=0AFurther, instead of using = on_selected_cpus(), which is unsafe when=0Athe dumping happens from a = hardware interrupt, introduce and use a=0Adedicated IPI sending function = (which each architecture can implement=0Ato its liking)=0A=0AFinally, = don't print useless data (e.g. the hypervisor context of the=0Ainterrupt = that is used for triggering the printing, but isn't part of=0Athe context = that's actually interesting).=0A=0ASigned-off-by: Jan Beulich =0A=0A--- 2010-05-04.orig/xen/arch/ia64/linux-xen/smp.c 2010-05-06 = 14:52:45.000000000 +0200=0A+++ 2010-05-04/xen/arch/ia64/linux-xen/smp.c = 2010-05-06 11:20:40.000000000 +0200=0A@@ -94,6 +94,7 @@ static volatile = struct call_data_struct =0A =0A #define IPI_CALL_FUNC 0=0A = #define IPI_CPU_STOP 1=0A+#define IPI_STATE_DUMP = 2=0A =0A /* This needs to be cacheline aligned because it is written to by = *other* CPUs. */=0A static DEFINE_PER_CPU(u64, ipi_operation) ____cachelin= e_aligned;=0A@@ -202,6 +203,10 @@ handle_IPI (int irq, void *dev_id, = struc=0A stop_this_cpu();=0A = break;=0A =0A+ case IPI_STATE_DUMP:=0A+ = dump_execstate(regs);=0A+ = break;=0A+=0A default:=0A = printk(KERN_CRIT "Unknown IPI on CPU %d: %lu\n", this_cpu, which);=0A = break;=0A@@ -479,6 +484,12 @@ smp_send_stop (void)=0A = send_IPI_allbutself(IPI_CPU_STOP);=0A }=0A =0A+void=0A+smp_send_state_dump = (unsigned int cpu)=0A+{=0A+ send_IPI_single(cpu, IPI_STATE_DUMP);=0A+}= =0A+=0A int __init=0A setup_profiling_timer (unsigned int multiplier)=0A = {=0A--- 2010-05-04.orig/xen/arch/x86/smp.c 2010-05-06 14:52:45.0000000= 00 +0200=0A+++ 2010-05-04/xen/arch/x86/smp.c 2010-05-06 11:21:07.0000000= 00 +0200=0A@@ -375,11 +375,24 @@ void smp_send_nmi_allbutself(void)=0A = send_IPI_mask(&cpu_online_map, APIC_DM_NMI);=0A }=0A =0A+void smp_send_stat= e_dump(unsigned int cpu)=0A+{=0A+ state_dump_pending(cpu) =3D 1;=0A+ = smp_send_event_check_cpu(cpu);=0A+}=0A+=0A fastcall void smp_event_check_in= terrupt(struct cpu_user_regs *regs)=0A {=0A struct cpu_user_regs = *old_regs =3D set_irq_regs(regs);=0A ack_APIC_irq();=0A perfc_incr(= ipis);=0A+ if ( unlikely(state_dump_pending(smp_processor_id())) )=0A+ = {=0A+ irq_enter();=0A+ state_dump_pending(smp_processor_id(= )) =3D 0;=0A+ dump_execstate(regs);=0A+ irq_exit();=0A+ = }=0A set_irq_regs(old_regs);=0A }=0A =0A--- 2010-05-04.orig/xen/common/= keyhandler.c 2010-05-04 13:21:53.000000000 +0200=0A+++ 2010-05-04/xen/co= mmon/keyhandler.c 2010-05-06 11:40:55.000000000 +0200=0A@@ -71,19 = +71,52 @@ static struct keyhandler show_handlers_k=0A .desc =3D "show = this message"=0A };=0A =0A-static void __dump_execstate(void *unused)=0A+#i= fdef CONFIG_SMP=0A+static cpumask_t dump_execstate_mask;=0A+#endif=0A+=0A+v= oid dump_execstate(struct cpu_user_regs *regs)=0A {=0A- dump_execution_s= tate();=0A- printk("*** Dumping CPU%d guest state: ***\n", smp_processor= _id());=0A+ unsigned int cpu =3D smp_processor_id();=0A+=0A+ if ( = !guest_mode(regs) )=0A+ {=0A+ printk("\n*** Dumping CPU%u host = state: ***\n", cpu);=0A+ show_execution_state(regs);=0A+ }=0A = if ( is_idle_vcpu(current) )=0A- printk("No guest context (CPU is = idle).\n");=0A+ printk("No guest context (CPU%u is idle).\n", = cpu);=0A else=0A+ {=0A+ printk("*** Dumping CPU%u guest = state (d%d:v%d): ***\n",=0A+ smp_processor_id(), current->dom= ain->domain_id,=0A+ current->vcpu_id);=0A show_execut= ion_state(guest_cpu_user_regs());=0A+ }=0A+=0A+#ifdef CONFIG_SMP=0A+ = cpu_clear(cpu, dump_execstate_mask);=0A+ if ( !alt_key_handling )=0A+ = return;=0A+=0A+ cpu =3D cycle_cpu(cpu, dump_execstate_mask);=0A+ = if ( cpu < NR_CPUS )=0A+ smp_send_state_dump(cpu);=0A+ else=0A+ = {=0A+ printk("\n");=0A+=0A+ console_end_sync();=0A+ = watchdog_enable();=0A+ }=0A+#endif=0A }=0A =0A static void dump_registe= rs(unsigned char key, struct cpu_user_regs *regs)=0A {=0A+#ifdef CONFIG_SMP= =0A unsigned int cpu;=0A+#endif=0A =0A /* We want to get everything= out that we possibly can. */=0A watchdog_disable();=0A@@ -91,17 = +124,28 @@ static void dump_registers(unsigned char=0A =0A printk("'%c'= pressed -> dumping registers\n", key);=0A =0A+#ifdef CONFIG_SMP=0A+ if = ( alt_key_handling )=0A+ dump_execstate_mask =3D cpu_online_map;=0A+= #endif=0A+=0A /* Get local execution state out immediately, in case we = get stuck. */=0A- printk("\n*** Dumping CPU%d host state: ***\n", = smp_processor_id());=0A- __dump_execstate(NULL);=0A+ dump_execstate(r= egs);=0A+=0A+#ifdef CONFIG_SMP=0A+ if ( alt_key_handling )=0A+ = return;=0A =0A for_each_online_cpu ( cpu )=0A {=0A if ( = cpu =3D=3D smp_processor_id() )=0A continue;=0A- = printk("\n*** Dumping CPU%d host state: ***\n", cpu);=0A- on_selecte= d_cpus(cpumask_of(cpu), __dump_execstate, NULL, 1);=0A+ cpu_set(cpu,= dump_execstate_mask);=0A+ smp_send_state_dump(cpu);=0A+ = while ( cpu_isset(cpu, dump_execstate_mask) )=0A+ cpu_relax();= =0A }=0A+#endif=0A =0A printk("\n");=0A =0A--- 2010-05-04.orig/xen/= include/asm-ia64/linux-xen/asm/ptrace.h 2010-05-06 14:52:45.000000000 = +0200=0A+++ 2010-05-04/xen/include/asm-ia64/linux-xen/asm/ptrace.h = 2010-05-04 13:22:27.000000000 +0200=0A@@ -280,7 +280,7 @@ struct switch_sta= ck {=0A # define ia64_task_regs(t) (((struct pt_regs *) = ((char *) (t) + IA64_STK_OFFSET)) - 1)=0A # define ia64_psr(regs) = ((struct ia64_psr *) &(regs)->cr_ipsr)=0A #ifdef XEN=0A-# define = guest_mode(regs) (ia64_psr(regs)->cpl !=3D 0)=0A+# define = guest_mode(regs) (ia64_psr(regs)->cpl && !ia64_psr(regs)->vm= )=0A # define guest_kernel_mode(regs) (ia64_psr(regs)->cpl =3D=3D = CONFIG_CPL0_EMUL)=0A # define vmx_guest_kernel_mode(regs) (ia64_psr(r= egs)->cpl =3D=3D 0)=0A # define regs_increment_iip(regs) = \=0A--- 2010-05-04.orig/xen/include/asm-x86/hardirq.h = 2010-05-06 14:52:57.000000000 +0200=0A+++ 2010-05-04/xen/include/asm-x86/ha= rdirq.h 2010-05-06 14:54:55.000000000 +0200=0A@@ -9,6 +9,7 @@ typedef = struct {=0A unsigned int __local_irq_count;=0A unsigned int = __nmi_count;=0A bool_t __mwait_wakeup;=0A+ bool_t __state_dump= _pending;=0A } __cacheline_aligned irq_cpustat_t;=0A =0A #include = /* Standard mappings for irq_cpustat_t above = */=0A--- 2010-05-04.orig/xen/include/xen/irq_cpustat.h 2010-05-06 = 14:52:57.000000000 +0200=0A+++ 2010-05-04/xen/include/xen/irq_cpustat.h = 2010-05-06 14:54:49.000000000 +0200=0A@@ -27,5 +27,6 @@ extern irq_cpustat_= t irq_stat[];=0A #define local_irq_count(cpu) __IRQ_STAT((cpu), = __local_irq_count)=0A #define nmi_count(cpu) __IRQ_STAT((cpu), = __nmi_count)=0A #define mwait_wakeup(cpu) __IRQ_STAT((cpu), = __mwait_wakeup)=0A+#define state_dump_pending(cpu) __IRQ_STAT((cpu), = __state_dump_pending)=0A =0A #endif /* __irq_cpustat_h */=0A--- = 2010-05-04.orig/xen/include/xen/lib.h 2010-05-06 14:52:45.000000000 = +0200=0A+++ 2010-05-04/xen/include/xen/lib.h 2010-05-06 11:17:03.0000000= 00 +0200=0A@@ -111,4 +111,7 @@ extern int tainted;=0A extern char = *print_tainted(char *str);=0A extern void add_taint(unsigned);=0A = =0A+struct cpu_user_regs;=0A+void dump_execstate(struct cpu_user_regs = *);=0A+=0A #endif /* __LIB_H__ */=0A--- 2010-05-04.orig/xen/include/xen/smp= .h 2010-05-04 13:22:06.000000000 +0200=0A+++ 2010-05-04/xen/include/xe= n/smp.h 2010-05-06 10:44:43.000000000 +0200=0A@@ -13,6 +13,8 @@ extern = void smp_send_event_check_mask(co=0A #define smp_send_event_check_cpu(cpu) = \=0A smp_send_event_check_mask(cpumask_of(cpu))=0A =0A+extern void = smp_send_state_dump(unsigned int cpu);=0A+=0A /*=0A * Prepare machine for = booting other CPUs.=0A */=0A --=__PartCAE06EB5.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartCAE06EB5.0__=--