xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Juergen Gross <jgross@suse.com>
To: xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>,
	Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>,
	George Dunlap <George.Dunlap@eu.citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Ian Jackson <ian.jackson@eu.citrix.com>, Tim Deegan <tim@xen.org>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <jbeulich@suse.com>
Subject: [Xen-devel] [PATCH v6 5/5] xen: add debugtrace entry when entry count is wrapping
Date: Mon,  9 Sep 2019 09:35:57 +0200	[thread overview]
Message-ID: <20190909073557.16168-6-jgross@suse.com> (raw)
In-Reply-To: <20190909073557.16168-1-jgross@suse.com>

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.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 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 669b2102ab..f779ad36ed 100644
--- a/xen/common/debugtrace.c
+++ b/xen/common/debugtrace.c
@@ -15,11 +15,14 @@
 #include <xen/spinlock.h>
 #include <xen/watchdog.h>
 
+#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 || strcmp(buf, last_buf) )
+        if ( debugtrace_buf_empty || 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;
-- 
2.16.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2019-09-09  7:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09  7:35 [Xen-devel] [PATCH v6 0/5] xen: debugtrace cleanup and per-cpu buffer support Juergen Gross
2019-09-09  7:35 ` [Xen-devel] [PATCH v6 1/5] xen: fix debugtrace clearing Juergen Gross
2019-09-09  7:53   ` Jan Beulich
2019-09-09  8:11     ` Jan Beulich
2019-09-09  8:19     ` Juergen Gross
2019-09-09  7:35 ` [Xen-devel] [PATCH v6 2/5] xen: move debugtrace coding to common/debugtrace.c Juergen Gross
2019-09-09  7:35 ` [Xen-devel] [PATCH v6 3/5] xen: refactor debugtrace data Juergen Gross
2019-09-09  7:35 ` [Xen-devel] [PATCH v6 4/5] xen: add per-cpu buffer option to debugtrace Juergen Gross
2019-09-09  7:59   ` Jan Beulich
2019-09-09  8:04     ` Jan Beulich
2019-09-09  8:15       ` Juergen Gross
2019-09-09  7:35 ` Juergen Gross [this message]
2019-09-09  8:19   ` [Xen-devel] [PATCH v6 5/5] xen: add debugtrace entry when entry count is wrapping Jan Beulich
2019-09-09  8:22     ` Juergen Gross

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190909073557.16168-6-jgross@suse.com \
    --to=jgross@suse.com \
    --cc=George.Dunlap@eu.citrix.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=ian.jackson@eu.citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=konrad.wilk@oracle.com \
    --cc=sstabellini@kernel.org \
    --cc=tim@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).