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);