From patchwork Wed Sep 4 13:46:07 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: 11130327 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 4E4301395 for ; Wed, 4 Sep 2019 13:47:36 +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 33F4A2339D for ; Wed, 4 Sep 2019 13:47:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33F4A2339D 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 1i5Vbz-0003mT-6u; Wed, 04 Sep 2019 13:46:15 +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 1i5Vbx-0003m9-Mt for xen-devel@lists.xenproject.org; Wed, 04 Sep 2019 13:46:13 +0000 X-Inumbo-ID: 5b664722-cf1a-11e9-abb6-12813bfff9fa Received: from mx1.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5b664722-cf1a-11e9-abb6-12813bfff9fa; Wed, 04 Sep 2019 13:46:12 +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 C802AAF25; Wed, 4 Sep 2019 13:46:11 +0000 (UTC) From: Juergen Gross To: xen-devel@lists.xenproject.org Date: Wed, 4 Sep 2019 15:46:07 +0200 Message-Id: <20190904134608.18425-4-jgross@suse.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20190904134608.18425-1-jgross@suse.com> References: <20190904134608.18425-1-jgross@suse.com> Subject: [Xen-devel] [PATCH v4 3/4] 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" 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 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) --- xen/common/debugtrace.c | 65 ++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/xen/common/debugtrace.c b/xen/common/debugtrace.c index 506aee9418..8fa0e7fb0e 100644 --- a/xen/common/debugtrace.c +++ b/xen/common/debugtrace.c @@ -15,35 +15,41 @@ #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_prd_last; -static unsigned int debugtrace_kilobytes = 128, debugtrace_bytes; -static unsigned int debugtrace_used; +struct debugtrace_data { + unsigned long bytes; /* Size of buffer. */ + unsigned long prd; /* Producer index. */ + unsigned long prd_last; + char buf[]; +}; + +static struct debugtrace_data *dt_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 ( !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); + if ( dt_data->buf[dt_data->prd] != '\0' ) + console_serial_puts(&dt_data->buf[dt_data->prd], + dt_data->bytes - dt_data->prd); /* Print youngest portion of the ring. */ - debugtrace_buf[debugtrace_prd] = '\0'; - console_serial_puts(&debugtrace_buf[0], debugtrace_prd); + dt_data->buf[dt_data->prd] = '\0'; + console_serial_puts(&dt_data->buf[0], dt_data->prd); - memset(debugtrace_buf, '\0', debugtrace_bytes); - debugtrace_prd = 0; - debugtrace_prd_last = 0; + memset(dt_data->buf, '\0', dt_data->bytes); + dt_data->prd = 0; + dt_data->prd_last = 0; printk("debugtrace_dump() finished\n"); } @@ -68,7 +74,6 @@ static void debugtrace_toggle(void) spin_unlock_irqrestore(&debugtrace_lock, flags); watchdog_enable(); - } void debugtrace_dump(void) @@ -90,9 +95,9 @@ static void debugtrace_add_to_buf(char *buf) for ( p = buf; *p != '\0'; p++ ) { - debugtrace_buf[debugtrace_prd++] = *p; - if ( debugtrace_prd == debugtrace_bytes ) - debugtrace_prd = 0; + dt_data->buf[dt_data->prd++] = *p; + if ( dt_data->prd == dt_data->bytes ) + dt_data->prd = 0; } } @@ -106,10 +111,10 @@ void debugtrace_printk(const char *fmt, ...) unsigned long flags; unsigned int nr; - if ( debugtrace_bytes == 0 ) + if ( !dt_data ) return; - debugtrace_used = 1; + debugtrace_used = true; spin_lock_irqsave(&debugtrace_lock, flags); @@ -128,14 +133,14 @@ void debugtrace_printk(const char *fmt, ...) { if ( strcmp(buf, last_buf) ) { - debugtrace_prd_last = debugtrace_prd; + dt_data->prd_last = dt_data->prd; last_count = ++count; safe_strcpy(last_buf, buf); snprintf(cntbuf, sizeof(cntbuf), "%u ", count); } else { - debugtrace_prd = debugtrace_prd_last; + dt_data->prd = dt_data->prd_last; snprintf(cntbuf, sizeof(cntbuf), "%u-%u ", last_count, ++count); } debugtrace_add_to_buf(cntbuf); @@ -153,7 +158,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 *data; /* Round size down to next power of two. */ while ( (kbytes = (debugtrace_kilobytes & (debugtrace_kilobytes-1))) != 0 ) @@ -164,12 +170,15 @@ 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); + bytes = PAGE_SIZE << order; + memset(data, '\0', bytes); - debugtrace_bytes = bytes; + data->bytes = bytes - sizeof(*data); + dt_data = data; register_keyhandler('T', debugtrace_key, "toggle debugtrace to console/buffer", 0);