From nobody Wed Apr 24 02:38:53 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568021187; cv=none; d=zoho.com; s=zohoarc; b=Lj9bSQwlBOq5PHoNNzW3mNyHTrkuKwnaUYV1VbH1Y4fyGapePduEsycMBHvLPiifMCyqEqiNPpAYW6oT/SsKRVuRm/QbEjFejCttbmbMQUTDBd1pioweiX286HWgyAU/S/AoThCSm5bO2fOgIXhE+wdj26YnTQFLSQYDH0rLLjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568021187; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9M4mXfDKLFUy++JcCovagFlstRAfobynv0mZpMOnpj8=; b=dthvqFrbjm8XHOSbN48xlUJkuzr/VIeYGN1EVyNwuDgSeGmNRGLSAriIFWeLWJvy75ACb8ZoQG/JHmcGpb2KkiL18U43GY2/7JZ9dIVm7xIj2h0GZykoZ513LHu9+GvgF1kJhGas0qyWiPEHM8k4dOAmDssvgLbp+GPBpJB08TY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 156802118769938.59466232406737; Mon, 9 Sep 2019 02:26:27 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7Fv8-0005A1-FF; Mon, 09 Sep 2019 09:25:14 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7Fv7-00059w-LG for xen-devel@lists.xenproject.org; Mon, 09 Sep 2019 09:25:13 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b850bd2e-d2e3-11e9-978d-bc764e2007e4; Mon, 09 Sep 2019 09:25:11 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 94671AC11; Mon, 9 Sep 2019 09:25:09 +0000 (UTC) X-Inumbo-ID: b850bd2e-d2e3-11e9-978d-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 9 Sep 2019 11:25:02 +0200 Message-Id: <20190909092506.24792-2-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 1/5] xen: fix debugtrace clearing 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" After dumping the debugtrace buffer it is cleared. This results in some entries not being printed in case the buffer is dumped again before having wrapped. While at it remove the trailing zero byte in the buffer as it is no longer needed. Commit b5e6e1ee8da59f introduced passing the number of chars to be printed in the related interfaces, so the trailing 0 byte is no longer required. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V5: - invalidate last_buf instead of last_prd after printing the buffer (Jan Beulich) V6: - instead of moving last_buf to file scope use a boolean for buffer invalidation (Jan Beulich) V7: - init debugtrace_buf_empty as true (Jan Beulich) --- xen/drivers/char/console.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index f49c6f29a8..3783618c17 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -1173,6 +1173,7 @@ static char *debugtrace_buf; /* Debug-trace bu= ffer */ static unsigned int debugtrace_prd; /* Producer index */ static unsigned int debugtrace_kilobytes =3D 128, debugtrace_bytes; static unsigned int debugtrace_used; +static bool debugtrace_buf_empty =3D true; static DEFINE_SPINLOCK(debugtrace_lock); integer_param("debugtrace", debugtrace_kilobytes); =20 @@ -1184,16 +1185,17 @@ static void debugtrace_dump_worker(void) printk("debugtrace_dump() starting\n"); =20 /* Print oldest portion of the ring. */ - ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); if ( debugtrace_buf[debugtrace_prd] !=3D '\0' ) console_serial_puts(&debugtrace_buf[debugtrace_prd], - debugtrace_bytes - debugtrace_prd - 1); + debugtrace_bytes - debugtrace_prd); =20 /* Print youngest portion of the ring. */ debugtrace_buf[debugtrace_prd] =3D '\0'; console_serial_puts(&debugtrace_buf[0], debugtrace_prd); =20 memset(debugtrace_buf, '\0', debugtrace_bytes); + debugtrace_prd =3D 0; + debugtrace_buf_empty =3D true; =20 printk("debugtrace_dump() finished\n"); } @@ -1241,8 +1243,7 @@ static void debugtrace_add_to_buf(char *buf) for ( p =3D buf; *p !=3D '\0'; p++ ) { debugtrace_buf[debugtrace_prd++] =3D *p; - /* Always leave a nul byte at the end of the buffer. */ - if ( debugtrace_prd =3D=3D (debugtrace_bytes - 1) ) + if ( debugtrace_prd =3D=3D debugtrace_bytes ) debugtrace_prd =3D 0; } } @@ -1264,8 +1265,6 @@ void debugtrace_printk(const char *fmt, ...) =20 spin_lock_irqsave(&debugtrace_lock, flags); =20 - ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); - va_start(args, fmt); nr =3D vscnprintf(buf, sizeof(buf), fmt, args); va_end(args); @@ -1279,8 +1278,9 @@ void debugtrace_printk(const char *fmt, ...) } else { - if ( strcmp(buf, last_buf) ) + if ( debugtrace_buf_empty || strcmp(buf, last_buf) ) { + debugtrace_buf_empty =3D false; last_prd =3D debugtrace_prd; last_count =3D ++count; safe_strcpy(last_buf, buf); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 02:38:53 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568021185; cv=none; d=zoho.com; s=zohoarc; b=bO8YA0x8zMCL6tUgpn2ePsxqQ3qoz985Oc4GSi5KY3I9GFhrHQpFYl/O3Fven4CtRBbnz6lkOErHHs6wot8VzfjbioKbmO4W40Yi9VQAWoUbb034dn6vU+Mhukhl1sBET+XNLmTeauvLYvyMtdwvfFY+Y0I91gaMjwcaCHW7u5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568021185; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=kUJR53qTzowdwj8lgV4wISlRDkJ3PWlbdT6RSZZAud0=; b=bc/nNFwcQVyl9xCEMGR6lRiUdtQ6VdgrX2LWDTGR/AGb1oHlBH0InTuzEIhAmJxyRA4Y1LKUnqEA6iPZ7zjCZquvpHFULDpX6WkJLc2o4mTTYy/UIo4tSwzxGP9eVDtSdf7/0e0NvlXtZev7zmnt/dXwo7fVtnfCy/8W/5VamDU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568021185753655.3143567488304; Mon, 9 Sep 2019 02:26:25 -0700 (PDT) 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 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) 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) X-Inumbo-ID: b8513ac4-d2e3-11e9-ac09-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 +=3D bsearch.o obj-$(CONFIG_CORE_PARKING) +=3D core_parking.o obj-y +=3D cpu.o obj-y +=3D cpupool.o +obj-$(CONFIG_DEBUG_TRACE) +=3D debugtrace.o obj-$(CONFIG_HAS_DEVICE_TREE) +=3D device_tree.o obj-y +=3D domctl.o obj-y +=3D 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 =3D 128, debugtrace_bytes; +static unsigned int debugtrace_used; +static bool debugtrace_buf_empty =3D true; +static DEFINE_SPINLOCK(debugtrace_lock); +integer_param("debugtrace", debugtrace_kilobytes); + +static void debugtrace_dump_worker(void) +{ + if ( (debugtrace_bytes =3D=3D 0) || !debugtrace_used ) + return; + + printk("debugtrace_dump() starting\n"); + + /* Print oldest portion of the ring. */ + if ( debugtrace_buf[debugtrace_prd] !=3D '\0' ) + console_serial_puts(&debugtrace_buf[debugtrace_prd], + debugtrace_bytes - debugtrace_prd); + + /* Print youngest portion of the ring. */ + debugtrace_buf[debugtrace_prd] =3D '\0'; + console_serial_puts(&debugtrace_buf[0], debugtrace_prd); + + memset(debugtrace_buf, '\0', debugtrace_bytes); + debugtrace_prd =3D 0; + debugtrace_buf_empty =3D 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 =3D !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 =3D buf; *p !=3D '\0'; p++ ) + { + debugtrace_buf[debugtrace_prd++] =3D *p; + if ( debugtrace_prd =3D=3D debugtrace_bytes ) + debugtrace_prd =3D 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 =3D=3D 0 ) + return; + + debugtrace_used =3D 1; + + spin_lock_irqsave(&debugtrace_lock, flags); + + va_start(args, fmt); + nr =3D vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + + if ( debugtrace_send_to_console ) + { + unsigned int n =3D scnprintf(cntbuf, sizeof(cntbuf), "%u ", ++coun= t); + + console_serial_puts(cntbuf, n); + console_serial_puts(buf, nr); + } + else + { + if ( debugtrace_buf_empty || strcmp(buf, last_buf) ) + { + debugtrace_buf_empty =3D false; + last_prd =3D debugtrace_prd; + last_count =3D ++count; + safe_strcpy(last_buf, buf); + snprintf(cntbuf, sizeof(cntbuf), "%u ", count); + } + else + { + debugtrace_prd =3D 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 =3D (debugtrace_kilobytes & (debugtrace_kilobytes-1)))= !=3D 0 ) + debugtrace_kilobytes =3D kbytes; + + bytes =3D debugtrace_kilobytes << 10; + if ( bytes =3D=3D 0 ) + return 0; + + order =3D get_order_from_bytes(bytes); + debugtrace_buf =3D alloc_xenheap_pages(order, 0); + ASSERT(debugtrace_buf !=3D NULL); + + memset(debugtrace_buf, '\0', bytes); + + debugtrace_bytes =3D 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) =20 /* * ************************************************************** - * *************** 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 =3D 128, debugtrace_bytes; -static unsigned int debugtrace_used; -static bool debugtrace_buf_empty =3D true; -static DEFINE_SPINLOCK(debugtrace_lock); -integer_param("debugtrace", debugtrace_kilobytes); - -static void debugtrace_dump_worker(void) -{ - if ( (debugtrace_bytes =3D=3D 0) || !debugtrace_used ) - return; - - printk("debugtrace_dump() starting\n"); - - /* Print oldest portion of the ring. */ - if ( debugtrace_buf[debugtrace_prd] !=3D '\0' ) - console_serial_puts(&debugtrace_buf[debugtrace_prd], - debugtrace_bytes - debugtrace_prd); - - /* Print youngest portion of the ring. */ - debugtrace_buf[debugtrace_prd] =3D '\0'; - console_serial_puts(&debugtrace_buf[0], debugtrace_prd); - - memset(debugtrace_buf, '\0', debugtrace_bytes); - debugtrace_prd =3D 0; - debugtrace_buf_empty =3D 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 =3D !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 =3D buf; *p !=3D '\0'; p++ ) - { - debugtrace_buf[debugtrace_prd++] =3D *p; - if ( debugtrace_prd =3D=3D debugtrace_bytes ) - debugtrace_prd =3D 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 =3D=3D 0 ) - return; - - debugtrace_used =3D 1; - - spin_lock_irqsave(&debugtrace_lock, flags); - - va_start(args, fmt); - nr =3D vscnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - if ( debugtrace_send_to_console ) - { - unsigned int n =3D scnprintf(cntbuf, sizeof(cntbuf), "%u ", ++coun= t); - - console_serial_puts(cntbuf, n); - console_serial_puts(buf, nr); - } - else - { - if ( debugtrace_buf_empty || strcmp(buf, last_buf) ) - { - debugtrace_buf_empty =3D false; - last_prd =3D debugtrace_prd; - last_count =3D ++count; - safe_strcpy(last_buf, buf); - snprintf(cntbuf, sizeof(cntbuf), "%u ", count); - } - else - { - debugtrace_prd =3D 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 =3D (debugtrace_kilobytes & (debugtrace_kilobytes-1)))= !=3D 0 ) - debugtrace_kilobytes =3D kbytes; - - bytes =3D debugtrace_kilobytes << 10; - if ( bytes =3D=3D 0 ) - return 0; - - order =3D get_order_from_bytes(bytes); - debugtrace_buf =3D alloc_xenheap_pages(order, 0); - ASSERT(debugtrace_buf !=3D NULL); - - memset(debugtrace_buf, '\0', bytes); - - debugtrace_bytes =3D 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 ************************** * ************************************************************** */ =20 --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 02:38:53 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568021186; cv=none; d=zoho.com; s=zohoarc; b=OYUaC6ey9hCNHv+Px2bwfE8iSkMfJtOXkwQAdba8Uakt3autE0Z/r+M98zGhETkHmrl6ep6174spApZwYVuGtyLUVV5th4B4j7SAhScCccrdRhYpo/2jEEbIeLm2qtMrPvVfDe4joUJaDZm38uzyH16CJ37gih8eBm9s8fkJLRk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568021186; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=uuSJKi9C1qfNIjb7qw6gO73Zkpr7XWGYkAu0+jmgrqI=; b=l2Pj/f1yPi50+juPPLouGvNGO9oY0hiJinZfVGoCUWKDruTOqA4JsTDtOxKRPk6CKIEz2IM6A4sLQP3rEwEFmcBNI2bkf4WRafTLNQPuryawSlYgb+XHOcM7ubWq1HphowIuW62kwNKlRhqydYhWzBZPxmugvUZ6bKZg/F4hTgs= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568021186551337.4072480790571; Mon, 9 Sep 2019 02:26:26 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7FvL-0005Ef-As; Mon, 09 Sep 2019 09:25:27 +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 1i7FvK-0005Dw-2Q for xen-devel@lists.xenproject.org; Mon, 09 Sep 2019 09:25:26 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b8721456-d2e3-11e9-ac09-12813bfff9fa; Mon, 09 Sep 2019 09:25:11 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3A349AFA4; Mon, 9 Sep 2019 09:25:10 +0000 (UTC) X-Inumbo-ID: b8721456-d2e3-11e9-ac09-12813bfff9fa X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 9 Sep 2019 11:25:04 +0200 Message-Id: <20190909092506.24792-4-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 3/5] xen: refactor debugtrace data 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" As a preparation for per-cpu buffers do a little refactoring of the debugtrace data: put the needed buffer admin data into the buffer as it will be needed for each buffer. In order not to limit buffer size switch the related fields from unsigned int to unsigned long, as on huge machines with RAM in the TB range it might be interesting to support buffers >4GB. While at it switch debugtrace_send_to_console and debugtrace_used to bool and delete an empty line. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V4: - renamed struct debugtrace_data_s (Jan Beulich) - renamed debtr_data (Jan Beulich) - remove unneeded condition (Jan Beulich) - recalc debugtrace_bytes (Jan Beulich) V6: - undo putting bytes into struct debugtrace_data (Jan Beulich) --- xen/common/debugtrace.c | 70 ++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/xen/common/debugtrace.c b/xen/common/debugtrace.c index 93cdddb61c..a66aa39103 100644 --- a/xen/common/debugtrace.c +++ b/xen/common/debugtrace.c @@ -15,34 +15,40 @@ #include =20 /* Send output direct to console, or buffer it? */ -static volatile int debugtrace_send_to_console; +static volatile bool debugtrace_send_to_console; =20 -static char *debugtrace_buf; /* Debug-trace buffer */ -static unsigned int debugtrace_prd; /* Producer index */ -static unsigned int debugtrace_kilobytes =3D 128, debugtrace_bytes; -static unsigned int debugtrace_used; +struct debugtrace_data { + unsigned long prd; /* Producer index. */ + char buf[]; +}; + +static struct debugtrace_data *dt_data; + +static unsigned int debugtrace_kilobytes =3D 128; +static unsigned long debugtrace_bytes; static bool debugtrace_buf_empty =3D true; +static bool debugtrace_used; static DEFINE_SPINLOCK(debugtrace_lock); integer_param("debugtrace", debugtrace_kilobytes); =20 static void debugtrace_dump_worker(void) { - if ( (debugtrace_bytes =3D=3D 0) || !debugtrace_used ) + if ( !debugtrace_used ) return; =20 printk("debugtrace_dump() starting\n"); =20 /* Print oldest portion of the ring. */ - if ( debugtrace_buf[debugtrace_prd] !=3D '\0' ) - console_serial_puts(&debugtrace_buf[debugtrace_prd], - debugtrace_bytes - debugtrace_prd); + if ( dt_data->buf[dt_data->prd] !=3D '\0' ) + console_serial_puts(&dt_data->buf[dt_data->prd], + debugtrace_bytes - dt_data->prd); =20 /* Print youngest portion of the ring. */ - debugtrace_buf[debugtrace_prd] =3D '\0'; - console_serial_puts(&debugtrace_buf[0], debugtrace_prd); + dt_data->buf[dt_data->prd] =3D '\0'; + console_serial_puts(&dt_data->buf[0], dt_data->prd); =20 - memset(debugtrace_buf, '\0', debugtrace_bytes); - debugtrace_prd =3D 0; + memset(dt_data->buf, '\0', debugtrace_bytes); + dt_data->prd =3D 0; debugtrace_buf_empty =3D true; =20 printk("debugtrace_dump() finished\n"); @@ -68,7 +74,6 @@ static void debugtrace_toggle(void) =20 spin_unlock_irqrestore(&debugtrace_lock, flags); watchdog_enable(); - } =20 void debugtrace_dump(void) @@ -90,26 +95,27 @@ static void debugtrace_add_to_buf(char *buf) =20 for ( p =3D buf; *p !=3D '\0'; p++ ) { - debugtrace_buf[debugtrace_prd++] =3D *p; - if ( debugtrace_prd =3D=3D debugtrace_bytes ) - debugtrace_prd =3D 0; + dt_data->buf[dt_data->prd++] =3D *p; + if ( dt_data->prd =3D=3D debugtrace_bytes ) + dt_data->prd =3D 0; } } =20 void debugtrace_printk(const char *fmt, ...) { static char buf[1024], last_buf[1024]; - static unsigned int count, last_count, last_prd; + static unsigned int count, last_count; + static unsigned long last_prd; =20 char cntbuf[24]; va_list args; unsigned long flags; unsigned int nr; =20 - if ( debugtrace_bytes =3D=3D 0 ) + if ( !dt_data ) return; =20 - debugtrace_used =3D 1; + debugtrace_used =3D true; =20 spin_lock_irqsave(&debugtrace_lock, flags); =20 @@ -129,14 +135,14 @@ void debugtrace_printk(const char *fmt, ...) if ( debugtrace_buf_empty || strcmp(buf, last_buf) ) { debugtrace_buf_empty =3D false; - last_prd =3D debugtrace_prd; + last_prd =3D dt_data->prd; last_count =3D ++count; safe_strcpy(last_buf, buf); snprintf(cntbuf, sizeof(cntbuf), "%u ", count); } else { - debugtrace_prd =3D last_prd; + dt_data->prd =3D last_prd; snprintf(cntbuf, sizeof(cntbuf), "%u-%u ", last_count, ++count= ); } debugtrace_add_to_buf(cntbuf); @@ -154,23 +160,27 @@ static void debugtrace_key(unsigned char key) static int __init debugtrace_init(void) { int order; - unsigned int kbytes, bytes; + unsigned long kbytes; + struct debugtrace_data *data; =20 /* Round size down to next power of two. */ while ( (kbytes =3D (debugtrace_kilobytes & (debugtrace_kilobytes-1)))= !=3D 0 ) debugtrace_kilobytes =3D kbytes; =20 - bytes =3D debugtrace_kilobytes << 10; - if ( bytes =3D=3D 0 ) + debugtrace_bytes =3D debugtrace_kilobytes << 10; + if ( debugtrace_bytes =3D=3D 0 ) return 0; =20 - order =3D get_order_from_bytes(bytes); - debugtrace_buf =3D alloc_xenheap_pages(order, 0); - ASSERT(debugtrace_buf !=3D NULL); + order =3D get_order_from_bytes(debugtrace_bytes); + data =3D alloc_xenheap_pages(order, 0); + if ( !data ) + return -ENOMEM; =20 - memset(debugtrace_buf, '\0', bytes); + debugtrace_bytes =3D PAGE_SIZE << order; + memset(data, '\0', debugtrace_bytes); + debugtrace_bytes -=3D sizeof(*data); =20 - debugtrace_bytes =3D bytes; + dt_data =3D data; =20 register_keyhandler('T', debugtrace_key, "toggle debugtrace to console/buffer", 0); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 02:38:53 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568021183; cv=none; d=zoho.com; s=zohoarc; b=bv//Xop3E9OZQh4S1O3B3m3tMiLzBrFzZq4AT8lBE+MIo4MMLJMSqnfSyqTMMTYwTyuaAHkeDkca3rupDUjq3s28iJwLmVwVj+OQO9hUW+QuvxPqUVFQutRU7iMi+n5zG0wZwt17ikcjrZiw8fAO9hvNSVKCBXjzAyZLvVhCWRI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568021183; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=S2V9wtPaIn0V/K7FCE3vaY6rMEaPt4uG8ueLCsC0z4E=; b=Q6nPWk145jN/GUKfBpp6leQozu1OTmFDt91AktaMxSyDJJ/BrxfXS6sjUEj+v6089lUdKEBNC8LCa3jOJTlFOZj57lLVWOje6U2qQyoa0cxNR01qjp2UkNiXcSmP021TGjt84AoosNYo+AhtNbp6e92YQNqEHB/364eH0lyCfB0= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568021183687775.3283956363472; Mon, 9 Sep 2019 02:26:23 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7FvE-0005B5-6S; Mon, 09 Sep 2019 09:25:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i7FvC-0005Aa-FU for xen-devel@lists.xenproject.org; Mon, 09 Sep 2019 09:25:18 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id b8a3fc3c-d2e3-11e9-a337-bc764e2007e4; Mon, 09 Sep 2019 09:25:11 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 80B38AFBF; Mon, 9 Sep 2019 09:25:10 +0000 (UTC) X-Inumbo-ID: b8a3fc3c-d2e3-11e9-a337-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Mon, 9 Sep 2019 11:25:05 +0200 Message-Id: <20190909092506.24792-5-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 4/5] xen: add per-cpu buffer option to debugtrace 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" debugtrace is normally writing trace entries into a single trace buffer. There are cases where this is not optimal, e.g. when hunting a bug which requires writing lots of trace entries and one cpu is stuck. This will result in other cpus filling the trace buffer and finally overwriting the interesting trace entries of the hanging cpu. In order to be able to debug such situations add the capability to use per-cpu trace buffers. This can be selected by specifying the debugtrace boot parameter with the modifier "cpu:", like: debugtrace=3Dcpu:16 At the same time switch the parsing function to accept size modifiers (e.g. 4M or 1G). Printing out the trace entries is done for each buffer in order to minimize the effort needed during printing. As each entry is prefixed with its sequence number sorting the entries can easily be done when analyzing them. Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich --- V2: - only allocate buffer if not already done so V4: - unsigned int -> unsigned long (Jan Beulich) - replace check for bytes < PAGE_SIZE by !bytes (Jan Beulich) - print info which buffer allocation failed (Jan Beulich) - replace switch by if in cpu notifier handler (Jan Beulich) V5: - don't silently ignore trailing characters when parsing buffer size (Jan Beulich) - limit scope of some variables (Jan Beulich) - adjust error message format (Jan Beulich) V6: - move calculation of final debugtrace_bytes value to parameter parsing --- docs/misc/xen-command-line.pandoc | 7 +- xen/common/debugtrace.c | 160 +++++++++++++++++++++++++++++-----= ---- 2 files changed, 128 insertions(+), 39 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index 7c72e31032..832797e2e2 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -644,12 +644,13 @@ over the PCI busses sequentially) or by PCI device (m= ust be on segment 0). Limits the number lines printed in Xen stack traces. =20 ### debugtrace -> `=3D ` +> `=3D [cpu:]` =20 > Default: `128` =20 -Specify the size of the console debug trace buffer in KiB. The debug -trace feature is only enabled in debugging builds of Xen. +Specify the size of the console debug trace buffer. By specifying `cpu:` +additionally a trace buffer of the specified size is allocated per cpu. +The debug trace feature is only enabled in debugging builds of Xen. =20 ### dma_bits > `=3D ` diff --git a/xen/common/debugtrace.c b/xen/common/debugtrace.c index a66aa39103..38f7603c1d 100644 --- a/xen/common/debugtrace.c +++ b/xen/common/debugtrace.c @@ -6,6 +6,7 @@ =20 =20 #include +#include #include #include #include @@ -23,35 +24,79 @@ struct debugtrace_data { }; =20 static struct debugtrace_data *dt_data; +static DEFINE_PER_CPU(struct debugtrace_data *, dt_cpu_data); =20 -static unsigned int debugtrace_kilobytes =3D 128; -static unsigned long debugtrace_bytes; +static unsigned long debugtrace_bytes =3D 128 << 10; +static bool debugtrace_per_cpu; static bool debugtrace_buf_empty =3D true; static bool debugtrace_used; static DEFINE_SPINLOCK(debugtrace_lock); -integer_param("debugtrace", debugtrace_kilobytes); =20 -static void debugtrace_dump_worker(void) +static int __init debugtrace_parse_param(const char *s) { - if ( !debugtrace_used ) + unsigned long bytes; + + if ( !strncmp(s, "cpu:", 4) ) + { + debugtrace_per_cpu =3D true; + s +=3D 4; + } + bytes =3D parse_size_and_unit(s, &s); + + if ( *s ) + return -EINVAL; + + debugtrace_bytes =3D MAX(bytes, PAGE_SIZE); + + /* Round size down to next power of two. */ + while ( (bytes =3D (debugtrace_bytes & (debugtrace_bytes - 1))) !=3D 0= ) + debugtrace_bytes =3D bytes; + + return 0; +} +custom_param("debugtrace", debugtrace_parse_param); + +static void debugtrace_dump_buffer(struct debugtrace_data *data, + const char *which) +{ + if ( !data ) return; =20 - printk("debugtrace_dump() starting\n"); + printk("debugtrace_dump() %s buffer starting\n", which); =20 /* Print oldest portion of the ring. */ - if ( dt_data->buf[dt_data->prd] !=3D '\0' ) - console_serial_puts(&dt_data->buf[dt_data->prd], - debugtrace_bytes - dt_data->prd); + if ( data->buf[data->prd] !=3D '\0' ) + console_serial_puts(&data->buf[data->prd], + debugtrace_bytes - data->prd); =20 /* Print youngest portion of the ring. */ - dt_data->buf[dt_data->prd] =3D '\0'; - console_serial_puts(&dt_data->buf[0], dt_data->prd); + data->buf[data->prd] =3D '\0'; + console_serial_puts(&data->buf[0], data->prd); =20 - memset(dt_data->buf, '\0', debugtrace_bytes); - dt_data->prd =3D 0; - debugtrace_buf_empty =3D true; + memset(data->buf, '\0', debugtrace_bytes); + data->prd =3D 0; =20 - printk("debugtrace_dump() finished\n"); + printk("debugtrace_dump() %s buffer finished\n", which); +} + +static void debugtrace_dump_worker(void) +{ + unsigned int cpu; + + if ( !debugtrace_used ) + return; + + debugtrace_dump_buffer(dt_data, "global"); + + for ( cpu =3D 0; cpu < nr_cpu_ids; cpu++ ) + { + char buf[16]; + + snprintf(buf, sizeof(buf), "cpu %u", cpu); + debugtrace_dump_buffer(per_cpu(dt_cpu_data, cpu), buf); + } + + debugtrace_buf_empty =3D true; } =20 static void debugtrace_toggle(void) @@ -91,28 +136,33 @@ void debugtrace_dump(void) =20 static void debugtrace_add_to_buf(char *buf) { + struct debugtrace_data *data; char *p; =20 + data =3D debugtrace_per_cpu ? this_cpu(dt_cpu_data) : dt_data; + for ( p =3D buf; *p !=3D '\0'; p++ ) { - dt_data->buf[dt_data->prd++] =3D *p; - if ( dt_data->prd =3D=3D debugtrace_bytes ) - dt_data->prd =3D 0; + data->buf[data->prd++] =3D *p; + if ( data->prd =3D=3D debugtrace_bytes ) + data->prd =3D 0; } } =20 void debugtrace_printk(const char *fmt, ...) { static char buf[1024], last_buf[1024]; - static unsigned int count, last_count; + static unsigned int count, last_count, last_cpu; static unsigned long last_prd; =20 char cntbuf[24]; va_list args; unsigned long flags; unsigned int nr; + struct debugtrace_data *data; =20 - if ( !dt_data ) + data =3D debugtrace_per_cpu ? this_cpu(dt_cpu_data) : dt_data; + if ( !data ) return; =20 debugtrace_used =3D true; @@ -132,17 +182,20 @@ void debugtrace_printk(const char *fmt, ...) } else { - if ( debugtrace_buf_empty || strcmp(buf, last_buf) ) + unsigned int cpu =3D debugtrace_per_cpu ? smp_processor_id() : 0; + + if ( debugtrace_buf_empty || cpu !=3D last_cpu || strcmp(buf, last= _buf) ) { debugtrace_buf_empty =3D false; - last_prd =3D dt_data->prd; + last_prd =3D data->prd; last_count =3D ++count; + last_cpu =3D cpu; safe_strcpy(last_buf, buf); snprintf(cntbuf, sizeof(cntbuf), "%u ", count); } else { - dt_data->prd =3D last_prd; + data->prd =3D last_prd; snprintf(cntbuf, sizeof(cntbuf), "%u-%u ", last_count, ++count= ); } debugtrace_add_to_buf(cntbuf); @@ -157,34 +210,69 @@ static void debugtrace_key(unsigned char key) debugtrace_toggle(); } =20 -static int __init debugtrace_init(void) +static void debugtrace_alloc_buffer(struct debugtrace_data **ptr, + unsigned int cpu) { int order; - unsigned long kbytes; struct debugtrace_data *data; =20 - /* Round size down to next power of two. */ - while ( (kbytes =3D (debugtrace_kilobytes & (debugtrace_kilobytes-1)))= !=3D 0 ) - debugtrace_kilobytes =3D kbytes; - - debugtrace_bytes =3D debugtrace_kilobytes << 10; - if ( debugtrace_bytes =3D=3D 0 ) - return 0; + if ( *ptr ) + return; =20 order =3D get_order_from_bytes(debugtrace_bytes); data =3D alloc_xenheap_pages(order, 0); if ( !data ) - return -ENOMEM; + { + if ( debugtrace_per_cpu ) + printk("CPU%u: failed to allocate debugtrace buffer\n", cpu); + else + printk("failed to allocate debugtrace buffer\n"); + return; + } =20 - debugtrace_bytes =3D PAGE_SIZE << order; - memset(data, '\0', debugtrace_bytes); - debugtrace_bytes -=3D sizeof(*data); + memset(data, '\0', debugtrace_bytes + sizeof(*data)); =20 dt_data =3D data; + *ptr =3D data; +} + +static int debugtrace_cpu_callback(struct notifier_block *nfb, + unsigned long action, void *hcpu) +{ + unsigned int cpu =3D (unsigned long)hcpu; + + /* Buffers are only ever allocated, never freed. */ + if ( action =3D=3D CPU_UP_PREPARE ) + debugtrace_alloc_buffer(&per_cpu(dt_cpu_data, cpu), cpu); + + return 0; +} + +static struct notifier_block debugtrace_nfb =3D { + .notifier_call =3D debugtrace_cpu_callback +}; + +static int __init debugtrace_init(void) +{ + unsigned int cpu; + + if ( !debugtrace_bytes ) + return 0; =20 register_keyhandler('T', debugtrace_key, "toggle debugtrace to console/buffer", 0); =20 + debugtrace_bytes -=3D sizeof(struct debugtrace_data); + + if ( debugtrace_per_cpu ) + { + for_each_online_cpu ( cpu ) + debugtrace_alloc_buffer(&per_cpu(dt_cpu_data, cpu), cpu); + register_cpu_notifier(&debugtrace_nfb); + } + else + debugtrace_alloc_buffer(&dt_data, 0); + return 0; } __initcall(debugtrace_init); --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed Apr 24 02:38:53 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1568021182; cv=none; d=zoho.com; s=zohoarc; b=VQ32Eex6kHyh53yf1KhvFlSOZ+WZr7PeQfy4AZzBU9LF7lJCV/HA8UgLRCTgsbdrqGiyhYzVrlkOu3WhrweAgQPVfpQ7RKlDFA1AqN9NrPj2QllX/DIm/zC0x3NjZp3Zp+xwyS+b3PkECysfmsH41pZ0IPQtBwTfQ1diXY2Vr4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568021182; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=nRYoLo3I2gVVCPLlYbm/PSvFsWQnIz2JS7ByibGCgJQ=; b=L55HAyC+6Ioe4F+hcdjkTatqVKALuNYkKEHt5SDlyg/sH9c21/PfpzEAFhicL1EONW3nyA4O14tR+N3U1ijtv/IZemyvXKqwdU0yjaozrdQOgUIfZY1p8bI7Hwxg/KAp8q+mkPEnRz1c7Kfu0pttG+Kp338en55A6phxPOLkl2Q= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1568021182853502.4573527336513; Mon, 9 Sep 2019 02:26:22 -0700 (PDT) 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 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) 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) X-Inumbo-ID: ba111514-d2e3-11e9-a337-bc764e2007e4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 =20 +#define DEBUGTRACE_COUNT_WRAP 99999999 + /* Send output direct to console, or buffer it? */ static volatile bool debugtrace_send_to_console; =20 struct debugtrace_data { unsigned long prd; /* Producer index. */ + unsigned long wrap_cnt; char buf[]; }; =20 @@ -72,6 +75,7 @@ static void debugtrace_dump_buffer(struct debugtrace_data= *data, /* Print youngest portion of the ring. */ data->buf[data->prd] =3D '\0'; console_serial_puts(&data->buf[0], data->prd); + printk("wrap: %lu\n", data->wrap_cnt); =20 memset(data->buf, '\0', debugtrace_bytes); data->prd =3D 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; =20 - 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 =3D vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); =20 + if ( count =3D=3D DEBUGTRACE_COUNT_WRAP ) + { + count =3D 0; + wrap_cnt++; + } + if ( debugtrace_send_to_console ) { - unsigned int n =3D scnprintf(cntbuf, sizeof(cntbuf), "%u ", ++coun= t); + unsigned int n; + + if ( count =3D=3D 0 ) + { + n =3D scnprintf(cntbuf, sizeof(cntbuf), "wrap: %lu\n", wrap_cn= t); + console_serial_puts(cntbuf, n); + } =20 + n =3D 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 =3D debugtrace_per_cpu ? smp_processor_id() : 0; =20 - if ( debugtrace_buf_empty || cpu !=3D last_cpu || strcmp(buf, last= _buf) ) + if ( debugtrace_buf_empty || cpu !=3D last_cpu || + wrap_cnt !=3D data->wrap_cnt || strcmp(buf, last_buf) ) { + if ( wrap_cnt !=3D data->wrap_cnt ) + { + snprintf(cntbuf, sizeof(cntbuf), "wrap: %lu->%lu\n", + data->wrap_cnt, wrap_cnt); + debugtrace_add_to_buf(cntbuf); + data->wrap_cnt =3D wrap_cnt; + } debugtrace_buf_empty =3D false; last_prd =3D data->prd; last_count =3D ++count; --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel