From patchwork Thu Aug 29 10:18:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 11120861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 62EF11395 for ; Thu, 29 Aug 2019 10:21:41 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3EA8322CF5 for ; Thu, 29 Aug 2019 10:21:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EA8322CF5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i3HX2-0003ie-HF; Thu, 29 Aug 2019 10:19:56 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i3HX0-0003hr-NE for xen-devel@lists.xenproject.org; Thu, 29 Aug 2019 10:19:54 +0000 X-Inumbo-ID: 7b82d4dc-ca46-11e9-ae64-12813bfff9fa Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 7b82d4dc-ca46-11e9-ae64-12813bfff9fa; Thu, 29 Aug 2019 10:19:29 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B9903AFC2; Thu, 29 Aug 2019 10:19:27 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Thu, 29 Aug 2019 12:18:44 +0200 Message-Id: <20190829101846.21369-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190829101846.21369-1-jgross@suse.com> References: <20190829101846.21369-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v3 3/5] xen: print lock profile info in panic() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Print the lock profile data when the system crashes and add some more information for each lock data (lock address, cpu holding the lock). While at it use the PRI_stime format specifier for printing time data. This is especially beneficial for watchdog triggered crashes in case of deadlocks. In order to have the cpu holding the lock available let the lock profile config option select DEBUG_LOCKS. As printing the lock profile data will make use of locking, too, we need to disable spinlock debugging before calling spinlock_profile_printall() from panic(). While at it remove a superfluous #ifdef CONFIG_LOCK_PROFILE and rename CONFIG_LOCK_PROFILE to CONFIG_DEBUG_LOCK_PROFILE. Also move the .lockprofile.data section to init area in linker scripts as the data is no longer needed after boot. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- V2: - rename CONFIG_LOCK_PROFILE to CONFIG_DEBUG_LOCK_PROFILE (Jan Beulich) - move .lockprofile.data section to init area in linker scripts - use PRI_stime (Andrew Cooper) - don't print "cpu=4095", but "not locked" (Andrew Cooper) --- xen/Kconfig.debug | 3 ++- xen/arch/arm/xen.lds.S | 13 +++++++------ xen/arch/x86/domain.c | 2 +- xen/arch/x86/xen.lds.S | 13 +++++++------ xen/common/keyhandler.c | 2 +- xen/common/spinlock.c | 33 ++++++++++++++++++--------------- xen/common/sysctl.c | 2 +- xen/drivers/char/console.c | 4 +++- xen/include/xen/spinlock.h | 12 +++++++----- 9 files changed, 47 insertions(+), 37 deletions(-) diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index 1faaa3ba6a..22573e74db 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -44,8 +44,9 @@ config COVERAGE If unsure, say N here. -config LOCK_PROFILE +config DEBUG_LOCK_PROFILE bool "Lock Profiling" + select DEBUG_LOCKS ---help--- Lock profiling allows you to see how often locks are taken and blocked. You can use serial console to print (and reset) using 'l' and 'L' diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S index 16ce1dd01e..a497f6a48d 100644 --- a/xen/arch/arm/xen.lds.S +++ b/xen/arch/arm/xen.lds.S @@ -54,12 +54,6 @@ SECTIONS *(.data.rel.ro) *(.data.rel.ro.*) -#ifdef CONFIG_LOCK_PROFILE - . = ALIGN(POINTER_ALIGN); - __lock_profile_start = .; - *(.lockprofile.data) - __lock_profile_end = .; -#endif . = ALIGN(POINTER_ALIGN); __param_start = .; *(.data.param) @@ -173,6 +167,13 @@ SECTIONS . = ALIGN(4); *(.altinstr_replacement) +#ifdef CONFIG_DEBUG_LOCK_PROFILE + . = ALIGN(POINTER_ALIGN); + __lock_profile_start = .; + *(.lockprofile.data) + __lock_profile_end = .; +#endif + *(.init.data) *(.init.data.rel) *(.init.data.rel.*) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index bc082ed827..b1c67c2d28 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -305,7 +305,7 @@ struct domain *alloc_domain_struct(void) #endif -#ifndef CONFIG_LOCK_PROFILE +#ifndef CONFIG_DEBUG_LOCK_PROFILE BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE); #endif d = alloc_xenheap_pages(order, MEMF_bits(bits)); diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S index 87fa02b9b5..111edb5360 100644 --- a/xen/arch/x86/xen.lds.S +++ b/xen/arch/x86/xen.lds.S @@ -128,12 +128,6 @@ SECTIONS *(.ex_table.pre) __stop___pre_ex_table = .; -#ifdef CONFIG_LOCK_PROFILE - . = ALIGN(POINTER_ALIGN); - __lock_profile_start = .; - *(.lockprofile.data) - __lock_profile_end = .; -#endif . = ALIGN(POINTER_ALIGN); __param_start = .; *(.data.param) @@ -251,6 +245,13 @@ SECTIONS *(.altinstructions) __alt_instructions_end = .; +#ifdef CONFIG_DEBUG_LOCK_PROFILE + . = ALIGN(POINTER_ALIGN); + __lock_profile_start = .; + *(.lockprofile.data) + __lock_profile_end = .; +#endif + . = ALIGN(8); __ctors_start = .; *(.ctors) diff --git a/xen/common/keyhandler.c b/xen/common/keyhandler.c index 57b360ee4b..c36baa4dff 100644 --- a/xen/common/keyhandler.c +++ b/xen/common/keyhandler.c @@ -62,7 +62,7 @@ static struct keyhandler { KEYHANDLER('P', perfc_reset, "reset performance counters", 0), #endif -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE KEYHANDLER('l', spinlock_profile_printall, "print lock profile info", 1), KEYHANDLER('L', spinlock_profile_reset, "reset lock profile info", 0), #endif diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c index 79e70a9947..c4f706c627 100644 --- a/xen/common/spinlock.c +++ b/xen/common/spinlock.c @@ -106,7 +106,7 @@ void spin_debug_disable(void) #endif -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE #define LOCK_PROFILE_REL \ if (lock->profile) \ @@ -243,7 +243,7 @@ int _spin_trylock(spinlock_t *lock) old.head_tail, new.head_tail) != old.head_tail ) return 0; got_lock(&lock->debug); -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE if (lock->profile) lock->profile->time_locked = NOW(); #endif @@ -258,7 +258,7 @@ int _spin_trylock(spinlock_t *lock) void _spin_barrier(spinlock_t *lock) { spinlock_tickets_t sample; -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE s_time_t block = NOW(); #endif @@ -269,7 +269,7 @@ void _spin_barrier(spinlock_t *lock) { while ( observe_head(&lock->tickets) == sample.head ) arch_lock_relax(); -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE if ( lock->profile ) { lock->profile->time_block += NOW() - block; @@ -327,7 +327,7 @@ void _spin_unlock_recursive(spinlock_t *lock) } } -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE struct lock_profile_anc { struct lock_profile_qhead *head_q; /* first head of this type */ @@ -362,14 +362,19 @@ static void spinlock_profile_iterate(lock_profile_subfunc *sub, void *par) static void spinlock_profile_print_elem(struct lock_profile *data, int32_t type, int32_t idx, void *par) { - if ( type == LOCKPROF_TYPE_GLOBAL ) - printk("%s %s:\n", lock_profile_ancs[type].name, data->name); + struct spinlock *lock = data->lock; + + printk("%s ", lock_profile_ancs[type].name); + if ( type != LOCKPROF_TYPE_GLOBAL ) + printk("%d ", idx); + printk("%s: addr=%p, lockval=%08x, ", data->name, lock, + lock->tickets.head_tail); + if ( lock->debug.cpu == SPINLOCK_NO_CPU ) + printk("not locked\n"); else - printk("%s %d %s:\n", lock_profile_ancs[type].name, idx, data->name); - printk(" lock:%12"PRId64"(%08X:%08X), block:%12"PRId64"(%08X:%08X)\n", - data->lock_cnt, (u32)(data->time_hold >> 32), (u32)data->time_hold, - data->block_cnt, (u32)(data->time_block >> 32), - (u32)data->time_block); + printk("cpu=%d\n", lock->debug.cpu); + printk(" lock:%" PRId64 "(%" PRI_stime "), block:%" PRId64 "(%" PRI_stime ")\n", + data->lock_cnt, data->time_hold, data->block_cnt, data->time_block); } void spinlock_profile_printall(unsigned char key) @@ -488,7 +493,6 @@ void _lock_profile_deregister_struct( spin_unlock(&lock_profile_lock); } -#ifdef CONFIG_LOCK_PROFILE static int __init lock_prof_init(void) { struct lock_profile **q; @@ -507,6 +511,5 @@ static int __init lock_prof_init(void) return 0; } __initcall(lock_prof_init); -#endif -#endif /* LOCK_PROFILE */ +#endif /* CONFIG_DEBUG_LOCK_PROFILE */ diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c index fcf2d2fd7c..9db94754d3 100644 --- a/xen/common/sysctl.c +++ b/xen/common/sysctl.c @@ -119,7 +119,7 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl) break; #endif -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE case XEN_SYSCTL_lockprof_op: ret = spinlock_profile_control(&op->u.lockprof_op); break; diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 7f29190eaf..e133534be7 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1170,7 +1170,9 @@ void panic(const char *fmt, ...) unsigned long flags; static DEFINE_SPINLOCK(lock); static char buf[128]; - + + spin_debug_disable(); + spinlock_profile_printall('\0'); debugtrace_dump(); /* Protects buf[] and ensure multi-line message prints atomically. */ diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 736490f52b..a7c1967ec7 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -1,6 +1,7 @@ #ifndef __SPINLOCK_H__ #define __SPINLOCK_H__ +#include #include #include #include @@ -26,7 +27,7 @@ union lock_debug { }; #define spin_debug_disable() ((void)0) #endif -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE #include @@ -72,9 +73,9 @@ struct lock_profile { struct spinlock *lock; /* the lock itself */ u64 lock_cnt; /* # of complete locking ops */ u64 block_cnt; /* # of complete wait for lock */ - s64 time_hold; /* cumulated lock time */ - s64 time_block; /* cumulated wait time */ - s64 time_locked; /* system time of last locking */ + s_time_t time_hold; /* cumulated lock time */ + s_time_t time_block; /* cumulated wait time */ + s_time_t time_locked; /* system time of last locking */ }; struct lock_profile_qhead { @@ -130,6 +131,7 @@ struct lock_profile_qhead { }; #define spin_lock_init_prof(s, l) spin_lock_init(&((s)->l)) #define lock_profile_register_struct(type, ptr, idx, print) #define lock_profile_deregister_struct(type, ptr) +#define spinlock_profile_printall(key) #endif @@ -150,7 +152,7 @@ typedef struct spinlock { u16 recurse_cnt:4; #define SPINLOCK_MAX_RECURSE 0xfu union lock_debug debug; -#ifdef CONFIG_LOCK_PROFILE +#ifdef CONFIG_DEBUG_LOCK_PROFILE struct lock_profile *profile; #endif } spinlock_t;