From patchwork Sun Apr 28 02:17:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240218 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3DA9B2C00B1 for ; Sun, 28 Apr 2013 12:20:05 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 253FA4A219; Sun, 28 Apr 2013 04:19:36 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LhHO4bGOIuyj; Sun, 28 Apr 2013 04:19:35 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2F6A74A1B5; Sun, 28 Apr 2013 04:18:56 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BC6F24A1A1 for ; Sun, 28 Apr 2013 04:18:31 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nX1oHbQcAvEn for ; Sun, 28 Apr 2013 04:18:30 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-vc0-f201.google.com (mail-vc0-f201.google.com [209.85.220.201]) by theia.denx.de (Postfix) with ESMTPS id 56C284A18F for ; Sun, 28 Apr 2013 04:18:23 +0200 (CEST) Received: by mail-vc0-f201.google.com with SMTP id gf12so271756vcb.2 for ; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=Ta55XlvUt92vVHKvy1Nzy4mUECygSfcwMeBBzbUTxxo=; b=IbJv7GYue+ssrrNVZW/lfPjwYe4aL2hRBcxLEhXwMMPFtl9ElduQSAtPZp1MzZxVFP YBh6fFirqc/FVFiGyaXgMBTRUIraMKh+EFtLI241OfvSsE8sQuNoxsH4W2CLLAVCC3Lv 5QmAYTIEPuuPBQtr4MzBi1bnbp4bKtuAuqagc35+FUrCoFHnVXqJiv4cCvOu8OlbAgbB xy+1Zs/rhxyvQOC0RUV64ZQ2PXI4mb2YNCbMOFReVKMQse7uAiiGVpkPXfQLc5yw84Pk +aUdDTEMFUA2FTyBAbw5eto7kblaBaQe6S8QAuxh/qsRu1lL3LHEfKLAeVJ+bhU4wFcN tRIQ== X-Received: by 10.236.203.47 with SMTP id e35mr17358029yho.5.1367115501519; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id g7si993960yhf.0.2013.04.27.19.18.21 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sat, 27 Apr 2013 19:18:21 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 5FF6431C18B; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 0D82016089C; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 27 Apr 2013 19:17:39 -0700 Message-Id: <1367115472-29531-3-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367115472-29531-1-git-send-email-sjg@chromium.org> References: <1367115472-29531-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQkYMvVERe0wVacRX5MYE4BwwdxvPHXwwcK0hxZdqIcIH2Wlw0Hhr1srPrAjxUbYLUT5HQWyE3Zu9noX+S4RtIW+Ka0xPAeH+tskP88V9bvldfpM2EgigURSLCLmx+XHS58g/Ep4vCLPqmXg6/X/df6GWRqi4z0ukLp1y2Wl+FpPeM8yZacZ5w81zANRHfzf/vkBMrmi Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [RFC PATCH 02/15] Add function to print a number with grouped digits X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Move bootstage's numbering printing code into a generic place so that it can be used by tracing also. Signed-off-by: Simon Glass --- common/bootstage.c | 22 ++++------------------ include/vsprintf.h | 11 +++++++++++ lib/vsprintf.c | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/common/bootstage.c b/common/bootstage.c index d0ea632..02c3633 100644 --- a/common/bootstage.c +++ b/common/bootstage.c @@ -47,6 +47,7 @@ static int next_id = BOOTSTAGE_ID_USER; enum { BOOTSTAGE_VERSION = 0, BOOTSTAGE_MAGIC = 0xb00757a3, + BOOTSTAGE_DIGITS = 9, }; struct bootstage_hdr { @@ -121,21 +122,6 @@ uint32_t bootstage_accum(enum bootstage_id id) return duration; } -static void print_time(unsigned long us_time) -{ - char str[15], *s; - int grab = 3; - - /* We don't seem to have %'d in U-Boot */ - sprintf(str, "%12lu", us_time); - for (s = str + 3; *s; s += grab) { - if (s != str + 3) - putc(s[-1] != ' ' ? ',' : ' '); - printf("%.*s", grab, s); - grab = 3; - } -} - /** * Get a record name as a printable string * @@ -164,10 +150,10 @@ static uint32_t print_time_record(enum bootstage_id id, if (prev == -1U) { printf("%11s", ""); - print_time(rec->time_us); + print_grouped_ull(rec->time_us, BOOTSTAGE_DIGITS); } else { - print_time(rec->time_us); - print_time(rec->time_us - prev); + print_grouped_ull(rec->time_us, BOOTSTAGE_DIGITS); + print_grouped_ull(rec->time_us - prev, BOOTSTAGE_DIGITS); } printf(" %s\n", get_record_name(buf, sizeof(buf), rec)); diff --git a/include/vsprintf.h b/include/vsprintf.h index 651077c..6568854 100644 --- a/include/vsprintf.h +++ b/include/vsprintf.h @@ -178,4 +178,15 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args); #define vscnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args) #endif /* CONFIG_SYS_VSNPRINTF */ +/** + * print_grouped_ull() - print a value with digits grouped by ',' + * + * This prints a value with grouped digits, like 12,345,678 to make it easier + * to read. + * + * @val: Value to print + * @digits: Number of digiits to print + */ +void print_grouped_ull(unsigned long long int_val, int digits); + #endif diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 533a96b..82e5c13 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -870,3 +870,19 @@ char *simple_itoa(ulong i) } while (i > 0); return p + 1; } + +/* We don't seem to have %'d in U-Boot */ +void print_grouped_ull(unsigned long long int_val, int digits) +{ + char str[21], *s; + int grab = 3; + + digits = (digits + 2) / 3; + sprintf(str, "%*llu", digits * 3, int_val); + for (s = str; *s; s += grab) { + if (s != str) + putc(s[-1] != ' ' ? ',' : ' '); + printf("%.*s", grab, s); + grab = 3; + } +}