From patchwork Fri Mar 15 06:35:56 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: 10854113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E92F46C2 for ; Fri, 15 Mar 2019 06:38:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C25C22A860 for ; Fri, 15 Mar 2019 06:38:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B252A2A863; Fri, 15 Mar 2019 06:38:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 50F462A860 for ; Fri, 15 Mar 2019 06:38:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h4gRp-0007iF-J3; Fri, 15 Mar 2019 06:36:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h4gRo-0007iA-Ce for xen-devel@lists.xenproject.org; Fri, 15 Mar 2019 06:36:04 +0000 X-Inumbo-ID: 995c0952-46ec-11e9-bc90-bc764e045a96 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 995c0952-46ec-11e9-bc90-bc764e045a96; Fri, 15 Mar 2019 06:36:01 +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 60899AC5C; Fri, 15 Mar 2019 06:36:00 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 15 Mar 2019 07:35:56 +0100 Message-Id: <20190315063557.24814-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190315063557.24814-1-jgross@suse.com> References: <20190315063557.24814-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v2 1/2] xen/debug: make debugtrace configurable via Kconfig 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Instead of having to edit include/xen/lib.h for making debugtrace available make it configurable via Kconfig. Default is off, it is available only in expert mode or in debug builds. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- xen/Kconfig.debug | 7 +++++++ xen/drivers/char/console.c | 2 +- xen/include/xen/lib.h | 3 +-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index 4d5d7f87cb..daacf85141 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -98,6 +98,13 @@ config UBSAN If unsure, say N here. +config DEBUG_TRACE + bool "Debug trace support" + ---help--- + Debug trace enables to record debug trace messages which are printed + either directly to the console or are printed to console in case of + a system crash. + endif # DEBUG || EXPERT endmenu diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 4315588f05..41ec13ce52 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1157,7 +1157,7 @@ int printk_ratelimit(void) * ************************************************************** */ -#ifdef DEBUG_TRACE_DUMP +#ifdef CONFIG_DEBUG_TRACE /* Send output direct to console, or buffer it? */ static volatile int debugtrace_send_to_console; diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 89939f43c8..e0b7bcb6b7 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -86,8 +86,7 @@ int parse_boolean(const char *name, const char *s, const char *e); */ int cmdline_strcmp(const char *frag, const char *name); -/*#define DEBUG_TRACE_DUMP*/ -#ifdef DEBUG_TRACE_DUMP +#ifdef CONFIG_DEBUG_TRACE extern void debugtrace_dump(void); extern void debugtrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); From patchwork Fri Mar 15 06:35:57 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: 10854117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E0A116C2 for ; Fri, 15 Mar 2019 06:38:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBA1C2A860 for ; Fri, 15 Mar 2019 06:38:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFEA92A863; Fri, 15 Mar 2019 06:38:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6532B2A860 for ; Fri, 15 Mar 2019 06:38:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h4gRs-0007in-2G; Fri, 15 Mar 2019 06:36:08 +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 1h4gRq-0007iL-EM for xen-devel@lists.xenproject.org; Fri, 15 Mar 2019 06:36:06 +0000 X-Inumbo-ID: 9954819a-46ec-11e9-a170-637745020753 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9954819a-46ec-11e9-a170-637745020753; Fri, 15 Mar 2019 06:36:01 +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 7C011ACEC; Fri, 15 Mar 2019 06:36:00 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Fri, 15 Mar 2019 07:35:57 +0100 Message-Id: <20190315063557.24814-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190315063557.24814-1-jgross@suse.com> References: <20190315063557.24814-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v2 2/2] xen/debug: make debugtrace more clever regarding repeating entries 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 MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In case debugtrace is writing to memory and the last entry is repeated don't fill up the trace buffer, but modify the count prefix to "x-y " style instead. Signed-off-by: Juergen Gross Acked-by: Wei Liu --- xen/drivers/char/console.c | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 41ec13ce52..f41b689847 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1225,13 +1225,26 @@ void debugtrace_dump(void) watchdog_enable(); } +static void debugtrace_add_to_buf(char *buf) +{ + char *p; + + for ( p = buf; *p != '\0'; p++ ) + { + debugtrace_buf[debugtrace_prd++] = *p; + /* Always leave a nul byte at the end of the buffer. */ + if ( debugtrace_prd == (debugtrace_bytes - 1) ) + debugtrace_prd = 0; + } +} + void debugtrace_printk(const char *fmt, ...) { - static char buf[1024]; - static u32 count; + static char buf[1024], last_buf[1024]; + static unsigned int count, last_count, last_prd; + char cntbuf[24]; va_list args; - char *p; unsigned long flags; if ( debugtrace_bytes == 0 ) @@ -1243,25 +1256,32 @@ void debugtrace_printk(const char *fmt, ...) ASSERT(debugtrace_buf[debugtrace_bytes - 1] == 0); - snprintf(buf, sizeof(buf), "%u ", ++count); - va_start(args, fmt); - (void)vsnprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), fmt, args); + vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); if ( debugtrace_send_to_console ) { + snprintf(cntbuf, sizeof(cntbuf), "%u ", ++count); + serial_puts(sercon_handle, cntbuf); serial_puts(sercon_handle, buf); } else { - for ( p = buf; *p != '\0'; p++ ) + if ( strcmp(buf, last_buf) ) + { + last_prd = debugtrace_prd; + last_count = ++count; + safe_strcpy(last_buf, buf); + snprintf(cntbuf, sizeof(cntbuf), "%u ", count); + } + else { - debugtrace_buf[debugtrace_prd++] = *p; - /* Always leave a nul byte at the end of the buffer. */ - if ( debugtrace_prd == (debugtrace_bytes - 1) ) - debugtrace_prd = 0; + debugtrace_prd = last_prd; + snprintf(cntbuf, sizeof(cntbuf), "%u-%u ", last_count, ++count); } + debugtrace_add_to_buf(cntbuf); + debugtrace_add_to_buf(buf); } spin_unlock_irqrestore(&debugtrace_lock, flags);