From patchwork Mon Sep 9 09:25:03 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: 11137539 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 EB26C912 for ; Mon, 9 Sep 2019 09:27:22 +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 C556F21920 for ; Mon, 9 Sep 2019 09:27:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C556F21920 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 1i7FvG-0005Bm-HQ; Mon, 09 Sep 2019 09:25:22 +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 1i7FvF-0005BR-4H for xen-devel@lists.xenproject.org; Mon, 09 Sep 2019 09:25:21 +0000 X-Inumbo-ID: b8513ac4-d2e3-11e9-ac09-12813bfff9fa Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b8513ac4-d2e3-11e9-ac09-12813bfff9fa; Mon, 09 Sep 2019 09:25:10 +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 DC04DAF65; Mon, 9 Sep 2019 09:25:09 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 9 Sep 2019 11:25:03 +0200 Message-Id: <20190909092506.24792-3-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 2/5] xen: move debugtrace coding to common/debugtrace.c 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" Instead of living in drivers/char/console.c move the debugtrace related coding to a new file common/debugtrace.c No functional change, code movement only. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- xen/common/Makefile | 1 + xen/common/debugtrace.c | 180 +++++++++++++++++++++++++++++++++++++++++++++ xen/drivers/char/console.c | 178 +------------------------------------------- 3 files changed, 182 insertions(+), 177 deletions(-) create mode 100644 xen/common/debugtrace.c diff --git a/xen/common/Makefile b/xen/common/Makefile index eddda5daa6..62b34e69e9 100644 --- a/xen/common/Makefile +++ b/xen/common/Makefile @@ -4,6 +4,7 @@ obj-y += bsearch.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o obj-y += cpupool.o +obj-$(CONFIG_DEBUG_TRACE) += debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) += device_tree.o obj-y += domctl.o obj-y += domain.o diff --git a/xen/common/debugtrace.c b/xen/common/debugtrace.c new file mode 100644 index 0000000000..93cdddb61c --- /dev/null +++ b/xen/common/debugtrace.c @@ -0,0 +1,180 @@ +/****************************************************************************** + * debugtrace.c + * + * Debugtrace for Xen + */ + + +#include +#include +#include +#include +#include +#include +#include +#include + +/* Send output direct to console, or buffer it? */ +static volatile int debugtrace_send_to_console; + +static char *debugtrace_buf; /* Debug-trace buffer */ +static unsigned int debugtrace_prd; /* Producer index */ +static unsigned int debugtrace_kilobytes = 128, debugtrace_bytes; +static unsigned int debugtrace_used; +static bool debugtrace_buf_empty = true; +static DEFINE_SPINLOCK(debugtrace_lock); +integer_param("debugtrace", debugtrace_kilobytes); + +static void debugtrace_dump_worker(void) +{ + if ( (debugtrace_bytes == 0) || !debugtrace_used ) + return; + + printk("debugtrace_dump() starting\n"); + + /* Print oldest portion of the ring. */ + if ( debugtrace_buf[debugtrace_prd] != '\0' ) + console_serial_puts(&debugtrace_buf[debugtrace_prd], + debugtrace_bytes - debugtrace_prd); + + /* Print youngest portion of the ring. */ + debugtrace_buf[debugtrace_prd] = '\0'; + console_serial_puts(&debugtrace_buf[0], debugtrace_prd); + + memset(debugtrace_buf, '\0', debugtrace_bytes); + debugtrace_prd = 0; + debugtrace_buf_empty = true; + + printk("debugtrace_dump() finished\n"); +} + +static void debugtrace_toggle(void) +{ + unsigned long flags; + + watchdog_disable(); + spin_lock_irqsave(&debugtrace_lock, flags); + + /* + * Dump the buffer *before* toggling, in case the act of dumping the + * buffer itself causes more printk() invocations. + */ + printk("debugtrace_printk now writing to %s.\n", + !debugtrace_send_to_console ? "console": "buffer"); + if ( !debugtrace_send_to_console ) + debugtrace_dump_worker(); + + debugtrace_send_to_console = !debugtrace_send_to_console; + + spin_unlock_irqrestore(&debugtrace_lock, flags); + watchdog_enable(); + +} + +void debugtrace_dump(void) +{ + unsigned long flags; + + watchdog_disable(); + spin_lock_irqsave(&debugtrace_lock, flags); + + debugtrace_dump_worker(); + + spin_unlock_irqrestore(&debugtrace_lock, flags); + watchdog_enable(); +} + +static void debugtrace_add_to_buf(char *buf) +{ + char *p; + + for ( p = buf; *p != '\0'; p++ ) + { + debugtrace_buf[debugtrace_prd++] = *p; + if ( debugtrace_prd == debugtrace_bytes ) + debugtrace_prd = 0; + } +} + +void debugtrace_printk(const char *fmt, ...) +{ + static char buf[1024], last_buf[1024]; + static unsigned int count, last_count, last_prd; + + char cntbuf[24]; + va_list args; + unsigned long flags; + unsigned int nr; + + if ( debugtrace_bytes == 0 ) + return; + + debugtrace_used = 1; + + spin_lock_irqsave(&debugtrace_lock, flags); + + va_start(args, fmt); + nr = vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + if ( debugtrace_send_to_console ) + { + unsigned int n = scnprintf(cntbuf, sizeof(cntbuf), "%u ", ++count); + + console_serial_puts(cntbuf, n); + console_serial_puts(buf, nr); + } + else + { + if ( debugtrace_buf_empty || strcmp(buf, last_buf) ) + { + debugtrace_buf_empty = false; + last_prd = debugtrace_prd; + last_count = ++count; + safe_strcpy(last_buf, buf); + snprintf(cntbuf, sizeof(cntbuf), "%u ", count); + } + else + { + 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); +} + +static void debugtrace_key(unsigned char key) +{ + debugtrace_toggle(); +} + +static int __init debugtrace_init(void) +{ + int order; + unsigned int kbytes, bytes; + + /* Round size down to next power of two. */ + while ( (kbytes = (debugtrace_kilobytes & (debugtrace_kilobytes-1))) != 0 ) + debugtrace_kilobytes = kbytes; + + bytes = debugtrace_kilobytes << 10; + if ( bytes == 0 ) + return 0; + + order = get_order_from_bytes(bytes); + debugtrace_buf = alloc_xenheap_pages(order, 0); + ASSERT(debugtrace_buf != NULL); + + memset(debugtrace_buf, '\0', bytes); + + debugtrace_bytes = bytes; + + register_keyhandler('T', debugtrace_key, + "toggle debugtrace to console/buffer", 0); + + return 0; +} +__initcall(debugtrace_init); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 3783618c17..7f29190eaf 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1160,183 +1160,7 @@ int printk_ratelimit(void) /* * ************************************************************** - * *************** Serial console ring buffer ******************* - * ************************************************************** - */ - -#ifdef CONFIG_DEBUG_TRACE - -/* Send output direct to console, or buffer it? */ -static volatile int debugtrace_send_to_console; - -static char *debugtrace_buf; /* Debug-trace buffer */ -static unsigned int debugtrace_prd; /* Producer index */ -static unsigned int debugtrace_kilobytes = 128, debugtrace_bytes; -static unsigned int debugtrace_used; -static bool debugtrace_buf_empty = true; -static DEFINE_SPINLOCK(debugtrace_lock); -integer_param("debugtrace", debugtrace_kilobytes); - -static void debugtrace_dump_worker(void) -{ - if ( (debugtrace_bytes == 0) || !debugtrace_used ) - return; - - printk("debugtrace_dump() starting\n"); - - /* Print oldest portion of the ring. */ - if ( debugtrace_buf[debugtrace_prd] != '\0' ) - console_serial_puts(&debugtrace_buf[debugtrace_prd], - debugtrace_bytes - debugtrace_prd); - - /* Print youngest portion of the ring. */ - debugtrace_buf[debugtrace_prd] = '\0'; - console_serial_puts(&debugtrace_buf[0], debugtrace_prd); - - memset(debugtrace_buf, '\0', debugtrace_bytes); - debugtrace_prd = 0; - debugtrace_buf_empty = true; - - printk("debugtrace_dump() finished\n"); -} - -static void debugtrace_toggle(void) -{ - unsigned long flags; - - watchdog_disable(); - spin_lock_irqsave(&debugtrace_lock, flags); - - /* - * Dump the buffer *before* toggling, in case the act of dumping the - * buffer itself causes more printk() invocations. - */ - printk("debugtrace_printk now writing to %s.\n", - !debugtrace_send_to_console ? "console": "buffer"); - if ( !debugtrace_send_to_console ) - debugtrace_dump_worker(); - - debugtrace_send_to_console = !debugtrace_send_to_console; - - spin_unlock_irqrestore(&debugtrace_lock, flags); - watchdog_enable(); - -} - -void debugtrace_dump(void) -{ - unsigned long flags; - - watchdog_disable(); - spin_lock_irqsave(&debugtrace_lock, flags); - - debugtrace_dump_worker(); - - spin_unlock_irqrestore(&debugtrace_lock, flags); - watchdog_enable(); -} - -static void debugtrace_add_to_buf(char *buf) -{ - char *p; - - for ( p = buf; *p != '\0'; p++ ) - { - debugtrace_buf[debugtrace_prd++] = *p; - if ( debugtrace_prd == debugtrace_bytes ) - debugtrace_prd = 0; - } -} - -void debugtrace_printk(const char *fmt, ...) -{ - static char buf[1024], last_buf[1024]; - static unsigned int count, last_count, last_prd; - - char cntbuf[24]; - va_list args; - unsigned long flags; - unsigned int nr; - - if ( debugtrace_bytes == 0 ) - return; - - debugtrace_used = 1; - - spin_lock_irqsave(&debugtrace_lock, flags); - - va_start(args, fmt); - nr = vscnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - if ( debugtrace_send_to_console ) - { - unsigned int n = scnprintf(cntbuf, sizeof(cntbuf), "%u ", ++count); - - console_serial_puts(cntbuf, n); - console_serial_puts(buf, nr); - } - else - { - if ( debugtrace_buf_empty || strcmp(buf, last_buf) ) - { - debugtrace_buf_empty = false; - last_prd = debugtrace_prd; - last_count = ++count; - safe_strcpy(last_buf, buf); - snprintf(cntbuf, sizeof(cntbuf), "%u ", count); - } - else - { - 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); -} - -static void debugtrace_key(unsigned char key) -{ - debugtrace_toggle(); -} - -static int __init debugtrace_init(void) -{ - int order; - unsigned int kbytes, bytes; - - /* Round size down to next power of two. */ - while ( (kbytes = (debugtrace_kilobytes & (debugtrace_kilobytes-1))) != 0 ) - debugtrace_kilobytes = kbytes; - - bytes = debugtrace_kilobytes << 10; - if ( bytes == 0 ) - return 0; - - order = get_order_from_bytes(bytes); - debugtrace_buf = alloc_xenheap_pages(order, 0); - ASSERT(debugtrace_buf != NULL); - - memset(debugtrace_buf, '\0', bytes); - - debugtrace_bytes = bytes; - - register_keyhandler('T', debugtrace_key, - "toggle debugtrace to console/buffer", 0); - - return 0; -} -__initcall(debugtrace_init); - -#endif /* !CONFIG_DEBUG_TRACE */ - - -/* - * ************************************************************** - * *************** Debugging/tracing/error-report *************** + * ********************** Error-report ************************** * ************************************************************** */