All of lore.kernel.org
 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 <wei.liu2@citrix.com>,
	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: [PATCH 2/2] xen/debug: make debugtrace more clever regarding repeating entries
Date: Thu, 14 Mar 2019 10:37:33 +0100	[thread overview]
Message-ID: <20190314093733.18175-3-jgross@suse.com> (raw)
In-Reply-To: <20190314093733.18175-1-jgross@suse.com>

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 <jgross@suse.com>
---
 xen/drivers/char/console.c | 44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c
index 41ec13ce52..38dcfc732e 100644
--- a/xen/drivers/char/console.c
+++ b/xen/drivers/char/console.c
@@ -1225,13 +1225,28 @@ 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];
+    static char last_buf[1024];
+    static u32 count, last_count;
+    static unsigned int last_prd;
 
+    char          cntbuf[24];
     va_list       args;
-    char         *p;
     unsigned long flags;
 
     if ( debugtrace_bytes == 0 )
@@ -1243,25 +1258,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);
+    (void)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);
-- 
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-03-14  9:37 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14  9:37 [PATCH 0/2] xen: some debug trace enhancements Juergen Gross
2019-03-14  9:37 ` [PATCH 1/2] xen/debug: make debugtrace configurable via Kconfig Juergen Gross
2019-03-14 13:26   ` Jan Beulich
2019-03-14  9:37 ` Juergen Gross [this message]
2019-03-14 13:33   ` [PATCH 2/2] xen/debug: make debugtrace more clever regarding repeating entries Jan Beulich
     [not found]   ` <5C8A5842020000780021EA3E@suse.com>
2019-03-14 13:38     ` Juergen Gross
2019-03-14 13:40       ` Andrew Cooper
2019-03-14 14:14         ` Jan Beulich
     [not found]         ` <5C8A61CB020000780021EB19@suse.com>
2019-03-14 14:28           ` Juergen Gross
2019-03-14 14:31             ` Jan Beulich
  -- strict thread matches above, loose matches on Subject: below --
2019-03-14 14:36 Juergen Gross
     [not found] <20190314093733.18175*1*jgross@suse.com>

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=20190314093733.18175-3-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=wei.liu2@citrix.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.