From patchwork Mon Sep 9 09:25:06 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: 11137529 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 DE1DC912 for ; Mon, 9 Sep 2019 09:26:43 +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 C392A21920 for ; Mon, 9 Sep 2019 09:26:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C392A21920 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 1i7FvI-0005Cj-RQ; Mon, 09 Sep 2019 09:25:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7FvH-0005CI-Gg for xen-devel@lists.xenproject.org; Mon, 09 Sep 2019 09:25:23 +0000 X-Inumbo-ID: ba111514-d2e3-11e9-a337-bc764e2007e4 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ba111514-d2e3-11e9-a337-bc764e2007e4; Mon, 09 Sep 2019 09:25:13 +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 D3B63AFCE; Mon, 9 Sep 2019 09:25:10 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 9 Sep 2019 11:25:06 +0200 Message-Id: <20190909092506.24792-6-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190909092506.24792-1-jgross@suse.com> References: <20190909092506.24792-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v7 5/5] xen: add debugtrace entry when entry count is wrapping 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" The debugtrace entry count is a 32 bit variable, so it can wrap when lots of trace entries are being produced. Making it wider would result in a waste of buffer space as the printed count value would consume more bytes when not wrapping. So instead of letting the count value grow to huge values let it wrap and add a wrap counter printed in this situation. This will keep the needed buffer space at today's value while avoiding to loose a way to sort all entries in case multiple trace buffers are involved. Note that the wrap message will be printed before the first trace entry in case output is switched to console early. This is on purpose in order to enable a future support of debugtrace to console without any allocated buffer. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- xen/common/debugtrace.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/xen/common/debugtrace.c b/xen/common/debugtrace.c index 38f7603c1d..2f9881ac6a 100644 --- a/xen/common/debugtrace.c +++ b/xen/common/debugtrace.c @@ -15,11 +15,14 @@ #include #include +#define DEBUGTRACE_COUNT_WRAP 99999999 + /* Send output direct to console, or buffer it? */ static volatile bool debugtrace_send_to_console; struct debugtrace_data { unsigned long prd; /* Producer index. */ + unsigned long wrap_cnt; char buf[]; }; @@ -72,6 +75,7 @@ static void debugtrace_dump_buffer(struct debugtrace_data *data, /* Print youngest portion of the ring. */ data->buf[data->prd] = '\0'; console_serial_puts(&data->buf[0], data->prd); + printk("wrap: %lu\n", data->wrap_cnt); memset(data->buf, '\0', debugtrace_bytes); data->prd = 0; @@ -153,9 +157,9 @@ void debugtrace_printk(const char *fmt, ...) { static char buf[1024], last_buf[1024]; static unsigned int count, last_count, last_cpu; - static unsigned long last_prd; + static unsigned long last_prd, wrap_cnt; - char cntbuf[24]; + char cntbuf[50]; va_list args; unsigned long flags; unsigned int nr; @@ -173,10 +177,23 @@ void debugtrace_printk(const char *fmt, ...) nr = vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); + if ( count == DEBUGTRACE_COUNT_WRAP ) + { + count = 0; + wrap_cnt++; + } + if ( debugtrace_send_to_console ) { - unsigned int n = scnprintf(cntbuf, sizeof(cntbuf), "%u ", ++count); + unsigned int n; + + if ( count == 0 ) + { + n = scnprintf(cntbuf, sizeof(cntbuf), "wrap: %lu\n", wrap_cnt); + console_serial_puts(cntbuf, n); + } + n = scnprintf(cntbuf, sizeof(cntbuf), "%u ", ++count); console_serial_puts(cntbuf, n); console_serial_puts(buf, nr); } @@ -184,8 +201,16 @@ void debugtrace_printk(const char *fmt, ...) { unsigned int cpu = debugtrace_per_cpu ? smp_processor_id() : 0; - if ( debugtrace_buf_empty || cpu != last_cpu || strcmp(buf, last_buf) ) + if ( debugtrace_buf_empty || cpu != last_cpu || + wrap_cnt != data->wrap_cnt || strcmp(buf, last_buf) ) { + if ( wrap_cnt != data->wrap_cnt ) + { + snprintf(cntbuf, sizeof(cntbuf), "wrap: %lu->%lu\n", + data->wrap_cnt, wrap_cnt); + debugtrace_add_to_buf(cntbuf); + data->wrap_cnt = wrap_cnt; + } debugtrace_buf_empty = false; last_prd = data->prd; last_count = ++count;