From patchwork Sun Jul 28 08:40:59 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: 11062905 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2680E112C for ; Sun, 28 Jul 2019 08:43:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 198E42899D for ; Sun, 28 Jul 2019 08:43:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ACCA289A9; Sun, 28 Jul 2019 08:43:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 97CF32899D for ; Sun, 28 Jul 2019 08:43:07 +0000 (UTC) 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 X-Inumbo-ID: 6fb28904-b113-11e9-8550-9fa0da201c0b 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) 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 2E4F3AEE1; Sun, 28 Jul 2019 08:41:04 +0000 (UTC) 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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 /* Send output direct to console, or buffer it? */ -static volatile int debugtrace_send_to_console; +static volatile bool 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; +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 = 128; +static bool debugtrace_used; static DEFINE_SPINLOCK(debugtrace_lock); integer_param("debugtrace", debugtrace_kilobytes); static void debugtrace_dump_worker(void) { - if ( (debugtrace_bytes == 0) || !debugtrace_used ) + if ( !debtr_data || !debugtrace_used ) return; printk("debugtrace_dump() starting\n"); /* Print oldest portion of the ring. */ - ASSERT(debugtrace_buf[debugtrace_bytes - 1] == 0); - sercon_puts(&debugtrace_buf[debugtrace_prd]); + ASSERT(debtr_data->buf[debtr_data->bytes - 1] == 0); + sercon_puts(&debtr_data->buf[debtr_data->prd]); /* Print youngest portion of the ring. */ - debugtrace_buf[debugtrace_prd] = '\0'; - sercon_puts(&debugtrace_buf[0]); + debtr_data->buf[debtr_data->prd] = '\0'; + sercon_puts(&debtr_data->buf[0]); - memset(debugtrace_buf, '\0', debugtrace_bytes); + memset(debtr_data->buf, '\0', debtr_data->bytes); printk("debugtrace_dump() finished\n"); } @@ -64,7 +70,6 @@ static void debugtrace_toggle(void) spin_unlock_irqrestore(&debugtrace_lock, flags); watchdog_enable(); - } void debugtrace_dump(void) @@ -86,10 +91,10 @@ static void debugtrace_add_to_buf(char *buf) for ( p = buf; *p != '\0'; p++ ) { - debugtrace_buf[debugtrace_prd++] = *p; + debtr_data->buf[debtr_data->prd++] = *p; /* Always leave a nul byte at the end of the buffer. */ - if ( debugtrace_prd == (debugtrace_bytes - 1) ) - debugtrace_prd = 0; + if ( debtr_data->prd == (debtr_data->bytes - 1) ) + debtr_data->prd = 0; } } @@ -102,14 +107,14 @@ void debugtrace_printk(const char *fmt, ...) va_list args; unsigned long flags; - if ( debugtrace_bytes == 0 ) + if ( !debtr_data ) return; - debugtrace_used = 1; + debugtrace_used = true; spin_lock_irqsave(&debugtrace_lock, flags); - ASSERT(debugtrace_buf[debugtrace_bytes - 1] == 0); + ASSERT(debtr_data->buf[debtr_data->bytes - 1] == 0); 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 = debugtrace_prd; + last_prd = debtr_data->prd; last_count = ++count; safe_strcpy(last_buf, buf); snprintf(cntbuf, sizeof(cntbuf), "%u ", count); } else { - debugtrace_prd = last_prd; + debtr_data->prd = 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; /* Round size down to next power of two. */ while ( (kbytes = (debugtrace_kilobytes & (debugtrace_kilobytes-1))) != 0 ) @@ -161,12 +167,14 @@ static int __init debugtrace_init(void) return 0; order = get_order_from_bytes(bytes); - debugtrace_buf = alloc_xenheap_pages(order, 0); - ASSERT(debugtrace_buf != NULL); + data = alloc_xenheap_pages(order, 0); + if ( !data ) + return -ENOMEM; - memset(debugtrace_buf, '\0', bytes); + memset(data, '\0', bytes); - debugtrace_bytes = bytes; + data->bytes = bytes - sizeof(*data); + debtr_data = data; register_keyhandler('T', debugtrace_key, "toggle debugtrace to console/buffer", 0);