From nobody Wed May 1 09:56:40 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=1564303348; cv=none; d=zoho.com; s=zohoarc; b=miQE5rYQjyp/Zrvb9g0TCeePVCZqcXemzcTIqLVRk/GxJqOE+wtn/N0dSAKw3ZVfXVjpNp2QIgdusOIXztpde6OcaLRnP1ZHTVA/+sOzjcXDZ/s9wYv+HB3u01Nf6HQgc+RviHRv5lF4EStOjVHOHEAIREPeFD4yHZHPXTnNkHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564303348; 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=loIXwz5iW0o5LKn0hxFJjmfqirrAs1y78lSYm/vDx1E=; b=P87rqb7b4U2zrtnxiR5FYhsXMKx0vym0DJ1WHsam27eX+dISnhYQvNQcAJC2tvJbKw9uFhTItZ6LBjSqHLAfcGf9RpEU4q7umw7tZffB+hf8drrMveQxtR+bT7hJeupmJmpTk2qjSDVyqp4SlrFfuYitj3p2dNKPpUzuJFb4JEQ= 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 1564303348153911.4627596284413; Sun, 28 Jul 2019 01:42:28 -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 1hrejt-0008VN-1H; Sun, 28 Jul 2019 08:41:09 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hrejr-0008V9-Jg for xen-devel@lists.xenproject.org; Sun, 28 Jul 2019 08:41:07 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 6fb892c6-b113-11e9-8980-bc764e045a96; Sun, 28 Jul 2019 08:41:05 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2E914AEF1; Sun, 28 Jul 2019 08:41:04 +0000 (UTC) X-Inumbo-ID: 6fb892c6-b113-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Sun, 28 Jul 2019 10:40:58 +0200 Message-Id: <20190728084100.13071-2-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190728084100.13071-1-jgross@suse.com> References: <20190728084100.13071-1-jgross@suse.com> Subject: [Xen-devel] [PATCH 1/3] 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 Signed-off-by: Juergen Gross --- xen/common/Makefile | 1 + xen/common/debugtrace.c | 177 +++++++++++++++++++++++++++++++++++++++++= ++++ xen/drivers/char/console.c | 176 +----------------------------------------= --- xen/include/xen/console.h | 4 + 4 files changed, 184 insertions(+), 174 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..ad10154495 --- /dev/null +++ b/xen/common/debugtrace.c @@ -0,0 +1,177 @@ +/*************************************************************************= ***** + * 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 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. */ + ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); + sercon_puts(&debugtrace_buf[debugtrace_prd]); + + /* Print youngest portion of the ring. */ + debugtrace_buf[debugtrace_prd] =3D '\0'; + sercon_puts(&debugtrace_buf[0]); + + memset(debugtrace_buf, '\0', debugtrace_bytes); + + 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; + /* Always leave a nul byte at the end of the buffer. */ + if ( debugtrace_prd =3D=3D (debugtrace_bytes - 1) ) + 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; + + if ( debugtrace_bytes =3D=3D 0 ) + return; + + debugtrace_used =3D 1; + + spin_lock_irqsave(&debugtrace_lock, flags); + + ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); + + va_start(args, fmt); + 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 + { + if ( strcmp(buf, last_buf) ) + { + 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 d728e737d1..9f87dc74ac 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -92,7 +92,7 @@ static char *__read_mostly conring =3D _conring; static uint32_t __read_mostly conring_size =3D _CONRING_SIZE; static uint32_t conringc, conringp; =20 -static int __read_mostly sercon_handle =3D -1; +int __read_mostly sercon_handle =3D -1; =20 #ifdef CONFIG_X86 /* Tristate: 0 disabled, 1 user enabled, -1 default enabled */ @@ -346,7 +346,7 @@ void console_giveback(int id) serial_steal_fn =3D NULL; } =20 -static void sercon_puts(const char *s) +void sercon_puts(const char *s) { if ( serial_steal_fn !=3D NULL ) (*serial_steal_fn)(s); @@ -1155,178 +1155,6 @@ int printk_ratelimit(void) return __printk_ratelimit(printk_ratelimit_ms, printk_ratelimit_burst); } =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 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. */ - ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); - sercon_puts(&debugtrace_buf[debugtrace_prd]); - - /* Print youngest portion of the ring. */ - debugtrace_buf[debugtrace_prd] =3D '\0'; - sercon_puts(&debugtrace_buf[0]); - - memset(debugtrace_buf, '\0', debugtrace_bytes); - - 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; - /* Always leave a nul byte at the end of the buffer. */ - if ( debugtrace_prd =3D=3D (debugtrace_bytes - 1) ) - 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; - - if ( debugtrace_bytes =3D=3D 0 ) - return; - - debugtrace_used =3D 1; - - spin_lock_irqsave(&debugtrace_lock, flags); - - ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); - - va_start(args, fmt); - 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 - { - if ( strcmp(buf, last_buf) ) - { - 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 *************** diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index b4f9463936..26aede22e4 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -48,4 +48,8 @@ int console_resume(void); =20 extern int8_t opt_console_xen; =20 +/* Issue string via serial line. */ +extern int sercon_handle; +void sercon_puts(const char *s); + #endif /* __CONSOLE_H__ */ --=20 2.16.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Wed May 1 09:56:40 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=1564303350; cv=none; d=zoho.com; s=zohoarc; b=Fnc32nBBiJzggijT83T+fGNpCkXuKCPo804GVTmd+ddCg7tcYqK4atrSn7y1yHTgdlc76hIc8i1BKX1qYS2VQccWIVpjgp6wGErNlFRFKgMCCjVbCm4qjB3Nn3gVSN9o2H3LH7WMkfY/ImDYIBgL37s0mYZtKWDO/nSu/CtE1fs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564303350; 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=anoAvRcYSYmKX3bzSAs7iuTjxA5YBVgxUHKeirj4MAQ=; b=R/QcNRd4xn9I+xKUNxykS0MNCaO09rpCQ5MFeH2JlBEAQ5U6jg/QPYKenNNYLdVm5UGrBA8/oxPiezzRE/px6BQvNyrycHLG6b6YGkFyEgowS9jS8Y0q6VI2oIGCdA4qS5s+bUY2zbgs5xgoM9GgbAu0sv8kAt92hTjhuhLqwz0= 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 1564303350631588.1792045519262; Sun, 28 Jul 2019 01:42:30 -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 1hrejv-0008Vj-Ik; Sun, 28 Jul 2019 08:41:11 +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 1hreju-0008VU-PZ for xen-devel@lists.xenproject.org; Sun, 28 Jul 2019 08:41:10 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 6fb28904-b113-11e9-8550-9fa0da201c0b; Sun, 28 Jul 2019 08:41:05 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2E4F3AEE1; Sun, 28 Jul 2019 08:41:04 +0000 (UTC) X-Inumbo-ID: 6fb28904-b113-11e9-8550-9fa0da201c0b X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Sun, 28 Jul 2019 10:40:59 +0200 Message-Id: <20190728084100.13071-3-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190728084100.13071-1-jgross@suse.com> References: <20190728084100.13071-1-jgross@suse.com> Subject: [Xen-devel] [PATCH 2/3] 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. While at it switch debugtrace_send_to_console and debugtrace_used to bool and delete an empty line. Signed-off-by: Juergen Gross --- xen/common/debugtrace.c | 58 ++++++++++++++++++++++++++++-----------------= ---- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/xen/common/debugtrace.c b/xen/common/debugtrace.c index ad10154495..e5c43d4457 100644 --- a/xen/common/debugtrace.c +++ b/xen/common/debugtrace.c @@ -15,31 +15,37 @@ #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_s { + unsigned long bytes; /* Size of buffer. */ + unsigned long prd; /* Producer index. */ + char buf[]; +}; + +static struct debugtrace_data_s *debtr_data; + +static unsigned int debugtrace_kilobytes =3D 128; +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 ( !debtr_data || !debugtrace_used ) return; =20 printk("debugtrace_dump() starting\n"); =20 /* Print oldest portion of the ring. */ - ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); - sercon_puts(&debugtrace_buf[debugtrace_prd]); + ASSERT(debtr_data->buf[debtr_data->bytes - 1] =3D=3D 0); + sercon_puts(&debtr_data->buf[debtr_data->prd]); =20 /* Print youngest portion of the ring. */ - debugtrace_buf[debugtrace_prd] =3D '\0'; - sercon_puts(&debugtrace_buf[0]); + debtr_data->buf[debtr_data->prd] =3D '\0'; + sercon_puts(&debtr_data->buf[0]); =20 - memset(debugtrace_buf, '\0', debugtrace_bytes); + memset(debtr_data->buf, '\0', debtr_data->bytes); =20 printk("debugtrace_dump() finished\n"); } @@ -64,7 +70,6 @@ static void debugtrace_toggle(void) =20 spin_unlock_irqrestore(&debugtrace_lock, flags); watchdog_enable(); - } =20 void debugtrace_dump(void) @@ -86,10 +91,10 @@ static void debugtrace_add_to_buf(char *buf) =20 for ( p =3D buf; *p !=3D '\0'; p++ ) { - debugtrace_buf[debugtrace_prd++] =3D *p; + debtr_data->buf[debtr_data->prd++] =3D *p; /* Always leave a nul byte at the end of the buffer. */ - if ( debugtrace_prd =3D=3D (debugtrace_bytes - 1) ) - debugtrace_prd =3D 0; + if ( debtr_data->prd =3D=3D (debtr_data->bytes - 1) ) + debtr_data->prd =3D 0; } } =20 @@ -102,14 +107,14 @@ void debugtrace_printk(const char *fmt, ...) va_list args; unsigned long flags; =20 - if ( debugtrace_bytes =3D=3D 0 ) + if ( !debtr_data ) return; =20 - debugtrace_used =3D 1; + debugtrace_used =3D true; =20 spin_lock_irqsave(&debugtrace_lock, flags); =20 - ASSERT(debugtrace_buf[debugtrace_bytes - 1] =3D=3D 0); + ASSERT(debtr_data->buf[debtr_data->bytes - 1] =3D=3D 0); =20 va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); @@ -125,14 +130,14 @@ void debugtrace_printk(const char *fmt, ...) { if ( strcmp(buf, last_buf) ) { - last_prd =3D debugtrace_prd; + last_prd =3D debtr_data->prd; last_count =3D ++count; safe_strcpy(last_buf, buf); snprintf(cntbuf, sizeof(cntbuf), "%u ", count); } else { - debugtrace_prd =3D last_prd; + debtr_data->prd =3D last_prd; snprintf(cntbuf, sizeof(cntbuf), "%u-%u ", last_count, ++count= ); } debugtrace_add_to_buf(cntbuf); @@ -150,7 +155,8 @@ static void debugtrace_key(unsigned char key) static int __init debugtrace_init(void) { int order; - unsigned int kbytes, bytes; + unsigned long kbytes, bytes; + struct debugtrace_data_s *data; =20 /* Round size down to next power of two. */ while ( (kbytes =3D (debugtrace_kilobytes & (debugtrace_kilobytes-1)))= !=3D 0 ) @@ -161,12 +167,14 @@ static int __init debugtrace_init(void) return 0; =20 order =3D get_order_from_bytes(bytes); - debugtrace_buf =3D alloc_xenheap_pages(order, 0); - ASSERT(debugtrace_buf !=3D NULL); + data =3D alloc_xenheap_pages(order, 0); + if ( !data ) + return -ENOMEM; =20 - memset(debugtrace_buf, '\0', bytes); + memset(data, '\0', bytes); =20 - debugtrace_bytes =3D bytes; + data->bytes =3D bytes - sizeof(*data); + debtr_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 May 1 09:56:40 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=1564303350; cv=none; d=zoho.com; s=zohoarc; b=Qy2P4zuh5EWmn3VUskn6D0D+fOkJ590qd+x9K1gqyAVNrcnnREgZbaXrEt1/NYGecDeiV4sXPCiaWquZp3bl7xCZSjXGi+pm7e7rGMHDyXkN/8Yvu52vAf2wERE+kkDJzMnOzadS9WBZ10ivnBnRfAOPdP/T2TsaCzeTGKVD2/0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564303350; 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=J2GuQZNziBq244uoDEEsTT0DGZ6jBm1zivPP9eZvJ5o=; b=VY0ZYkfTjZ1CoIHlctsNNOt+d7UpJVS5OiCQHMHpjV7MUuDi5qOEs7It38DqH9GH2IEMwDMKxfA4X19iOldsiNimsXb3tF92jJowZ+N08sWS8T7gWoh6RKtvey2AfASQQfh9PWu+ALvTUMRTMMYWkSSmc1PP6r+9irMluWd+hv8= 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 1564303350072689.4902391023844; Sun, 28 Jul 2019 01:42:30 -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 1hrejs-0008VH-PI; Sun, 28 Jul 2019 08:41:08 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hrejr-0008V7-FX for xen-devel@lists.xenproject.org; Sun, 28 Jul 2019 08:41:07 +0000 Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 6fb89f12-b113-11e9-8980-bc764e045a96; Sun, 28 Jul 2019 08:41:05 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2EDBFAF2D; Sun, 28 Jul 2019 08:41:04 +0000 (UTC) X-Inumbo-ID: 6fb89f12-b113-11e9-8980-bc764e045a96 X-Virus-Scanned: by amavisd-new at test-mx.suse.de From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Sun, 28 Jul 2019 10:41:00 +0200 Message-Id: <20190728084100.13071-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190728084100.13071-1-jgross@suse.com> References: <20190728084100.13071-1-jgross@suse.com> Subject: [Xen-devel] [PATCH 3/3] 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 --- docs/misc/xen-command-line.pandoc | 7 +- xen/common/debugtrace.c | 145 +++++++++++++++++++++++++++++-----= ---- 2 files changed, 115 insertions(+), 37 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 e5c43d4457..4dd8a9d12c 100644 --- a/xen/common/debugtrace.c +++ b/xen/common/debugtrace.c @@ -6,6 +6,7 @@ =20 =20 #include +#include #include #include #include @@ -24,30 +25,61 @@ struct debugtrace_data_s { }; =20 static struct debugtrace_data_s *debtr_data; +static DEFINE_PER_CPU(struct debugtrace_data_s *, debtr_cpu_data); =20 -static unsigned int debugtrace_kilobytes =3D 128; +static unsigned int debugtrace_bytes =3D 128 << 10; +static bool debugtrace_per_cpu; 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 ( !strncmp(s, "cpu:", 4) ) + { + debugtrace_per_cpu =3D true; + s +=3D 4; + } + debugtrace_bytes =3D parse_size_and_unit(s, NULL); + return 0; +} +custom_param("debugtrace", debugtrace_parse_param); + +static void debugtrace_dump_buffer(struct debugtrace_data_s *data, + const char *which) { - if ( !debtr_data || !debugtrace_used ) + if ( !data ) return; =20 - printk("debugtrace_dump() starting\n"); + printk("debugtrace_dump() %s buffer starting\n", which); =20 /* Print oldest portion of the ring. */ - ASSERT(debtr_data->buf[debtr_data->bytes - 1] =3D=3D 0); - sercon_puts(&debtr_data->buf[debtr_data->prd]); + ASSERT(data->buf[data->bytes - 1] =3D=3D 0); + sercon_puts(&data->buf[data->prd]); =20 /* Print youngest portion of the ring. */ - debtr_data->buf[debtr_data->prd] =3D '\0'; - sercon_puts(&debtr_data->buf[0]); + data->buf[data->prd] =3D '\0'; + sercon_puts(&data->buf[0]); + + memset(data->buf, '\0', data->bytes); + + printk("debugtrace_dump() %s buffer finished\n", which); +} + +static void debugtrace_dump_worker(void) +{ + unsigned int cpu; + char buf[16]; + + if ( !debugtrace_used ) + return; =20 - memset(debtr_data->buf, '\0', debtr_data->bytes); + debugtrace_dump_buffer(debtr_data, "global"); =20 - printk("debugtrace_dump() finished\n"); + for ( cpu =3D 0; cpu < nr_cpu_ids; cpu++ ) + { + snprintf(buf, sizeof(buf), "cpu %u", cpu); + debugtrace_dump_buffer(per_cpu(debtr_cpu_data, cpu), buf); + } } =20 static void debugtrace_toggle(void) @@ -87,34 +119,41 @@ void debugtrace_dump(void) =20 static void debugtrace_add_to_buf(char *buf) { + struct debugtrace_data_s *data; char *p; =20 + data =3D debugtrace_per_cpu ? this_cpu(debtr_cpu_data) : debtr_data; + for ( p =3D buf; *p !=3D '\0'; p++ ) { - debtr_data->buf[debtr_data->prd++] =3D *p; + data->buf[data->prd++] =3D *p; /* Always leave a nul byte at the end of the buffer. */ - if ( debtr_data->prd =3D=3D (debtr_data->bytes - 1) ) - debtr_data->prd =3D 0; + if ( data->prd =3D=3D (data->bytes - 1) ) + 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, last_prd, last_cpu; =20 char cntbuf[24]; va_list args; unsigned long flags; + struct debugtrace_data_s *data; + unsigned int cpu; =20 - if ( !debtr_data ) + data =3D debugtrace_per_cpu ? this_cpu(debtr_cpu_data) : debtr_data; + cpu =3D debugtrace_per_cpu ? smp_processor_id() : 0; + if ( !data ) return; =20 debugtrace_used =3D true; =20 spin_lock_irqsave(&debugtrace_lock, flags); =20 - ASSERT(debtr_data->buf[debtr_data->bytes - 1] =3D=3D 0); + ASSERT(data->buf[data->bytes - 1] =3D=3D 0); =20 va_start(args, fmt); vsnprintf(buf, sizeof(buf), fmt, args); @@ -128,16 +167,17 @@ void debugtrace_printk(const char *fmt, ...) } else { - if ( strcmp(buf, last_buf) ) + if ( strcmp(buf, last_buf) || cpu !=3D last_cpu ) { - last_prd =3D debtr_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 { - debtr_data->prd =3D last_prd; + data->prd =3D last_prd; snprintf(cntbuf, sizeof(cntbuf), "%u-%u ", last_count, ++count= ); } debugtrace_add_to_buf(cntbuf); @@ -152,33 +192,70 @@ static void debugtrace_key(unsigned char key) debugtrace_toggle(); } =20 -static int __init debugtrace_init(void) +static void debugtrace_alloc_buffer(struct debugtrace_data_s **ptr) { int order; - unsigned long kbytes, bytes; struct debugtrace_data_s *data; =20 - /* 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; + if ( debugtrace_bytes < PAGE_SIZE ) + return; =20 - order =3D get_order_from_bytes(bytes); + order =3D get_order_from_bytes(debugtrace_bytes); data =3D alloc_xenheap_pages(order, 0); if ( !data ) - return -ENOMEM; + { + printk("failed to allocate debugtrace buffer\n"); + return; + } + + memset(data, '\0', debugtrace_bytes); + data->bytes =3D debugtrace_bytes - sizeof(*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. */ + switch ( action ) + { + case CPU_UP_PREPARE: + debugtrace_alloc_buffer(&per_cpu(debtr_cpu_data, cpu)); + break; + default: + break; + } + return 0; +} =20 - memset(data, '\0', bytes); +static struct notifier_block debugtrace_nfb =3D { + .notifier_call =3D debugtrace_cpu_callback +}; + +static int __init debugtrace_init(void) +{ + unsigned long bytes; + unsigned int cpu; =20 - data->bytes =3D bytes - sizeof(*data); - debtr_data =3D data; + /* Round size down to next power of two. */ + while ( (bytes =3D (debugtrace_bytes & (debugtrace_bytes - 1))) !=3D 0= ) + debugtrace_bytes =3D bytes; =20 register_keyhandler('T', debugtrace_key, "toggle debugtrace to console/buffer", 0); =20 + if ( debugtrace_per_cpu ) + { + for_each_online_cpu ( cpu ) + debugtrace_alloc_buffer(&per_cpu(debtr_cpu_data, cpu)); + register_cpu_notifier(&debugtrace_nfb); + } + else + debugtrace_alloc_buffer(&debtr_data); + 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