From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DFC95ECAAD8 for ; Wed, 21 Sep 2022 14:08:23 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B5D5284C9B; Wed, 21 Sep 2022 16:07:09 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1663769229; bh=HIh0I+lZRue8fRozQHyYCpAbQUfUwmju18xdvZWwswI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=HbBsNOCwGSO+x+pkgN8qctgWinlIUbHuWTiz70dnXlMseZ23ERACAJWbaPiRxZTYj wNT8m2v/PmvcbdyPOqWm2BdbUw/1yBr3i8F8yhlB+QWo5BGIn4GmbQvKUr69Mqn/2p i9FloFQ4ounEUjwzdXEMzUjysCWkbTXHQgobIKpzWpNTKla/C9LodgGBpjK9QziedQ atagmJlH7frOUPYjfQn2SjPEmw6JDNB1D4lPruFBS2+dwgMwVnNG3F7lB1B+rg6hY9 ZL5UqwLxHaTQPy5jNDqNTfInNTe452JgUgHB7Hm8Up8HjEj7sQ2naznDA6RKUJi7uE mq2Ym1o0uU07w== Received: by phobos.denx.de (Postfix, from userid 109) id 8044784CA2; Wed, 21 Sep 2022 16:06:43 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [80.241.59.204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 82C1984CA7 for ; Wed, 21 Sep 2022 16:06:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp102.mailbox.org (smtp102.mailbox.org [IPv6:2001:67c:2050:b231:465::102]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4MXgFL4L56z9sW9; Wed, 21 Sep 2022 16:06:30 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: sjg@chromium.org, trini@konsulko.com Subject: [PATCH 09/10] bootstage: Migrate from timer_get_boot_us() to timer_get_us() Date: Wed, 21 Sep 2022 16:06:24 +0200 Message-Id: <20220921140625.999002-10-sr@denx.de> In-Reply-To: <20220921140625.999002-1-sr@denx.de> References: <20220921140625.999002-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4MXgFL4L56z9sW9 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean This patch migrates the bootstage code from using the boot specific timer_get_boot_us() timer function to the common timer_get_us() function. This can only be done, also supporting the early boot phase, when CONFIG_TIMER_EARLY is enabled. This way, the common timer functions provide this functionality. Because of this, CONFIG_TIMER_EARLY is now selected via CONFIG_BOOTSTAGE. Additionally all 'uint32_t' timer occurances are changed to 'ulong', as this is the return value of timer_get_us(). Otherwise this might lead to 32bit vs 64bit conversion issues on 64bit platforms. Also the start time of the bootstage recording is now saved. Otherwise bigger timing offsets are seen on platforms where the timer does not start with 0. Signed-off-by: Stefan Roese --- boot/Kconfig | 1 + common/bootstage.c | 26 ++++++++++++++------------ include/bootstage.h | 17 +++++------------ 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/boot/Kconfig b/boot/Kconfig index 6b3b8f072cb9..2ac7752a2eef 100644 --- a/boot/Kconfig +++ b/boot/Kconfig @@ -642,6 +642,7 @@ menu "Boot timing" config BOOTSTAGE bool "Boot timing and reporting" + select TIMER_EARLY help Enable recording of boot time while booting. To use it, insert calls to bootstage_mark() with a suitable BOOTSTAGE_ID from diff --git a/common/bootstage.c b/common/bootstage.c index 326c40f1561f..6a655b20196b 100644 --- a/common/bootstage.c +++ b/common/bootstage.c @@ -30,7 +30,7 @@ enum { struct bootstage_record { ulong time_us; - uint32_t start_us; + ulong start_us; const char *name; int flags; /* see enum bootstage_flags */ enum bootstage_id id; @@ -39,6 +39,7 @@ struct bootstage_record { struct bootstage_data { uint rec_count; uint next_id; + ulong start_time_us; struct bootstage_record record[RECORD_COUNT]; }; @@ -132,7 +133,7 @@ ulong bootstage_add_record(enum bootstage_id id, const char *name, if (!rec) { if (data->rec_count < RECORD_COUNT) { rec = &data->record[data->rec_count++]; - rec->time_us = mark; + rec->time_us = mark - data->start_time_us; rec->name = name; rec->flags = flags; rec->id = id; @@ -150,7 +151,7 @@ ulong bootstage_add_record(enum bootstage_id id, const char *name, ulong bootstage_error_name(enum bootstage_id id, const char *name) { return bootstage_add_record(id, name, BOOTSTAGEF_ERROR, - timer_get_boot_us()); + timer_get_us()); } ulong bootstage_mark_name(enum bootstage_id id, const char *name) @@ -160,7 +161,7 @@ ulong bootstage_mark_name(enum bootstage_id id, const char *name) if (id == BOOTSTAGE_ID_ALLOC) flags = BOOTSTAGEF_ALLOC; - return bootstage_add_record(id, name, flags, timer_get_boot_us()); + return bootstage_add_record(id, name, flags, timer_get_us()); } ulong bootstage_mark_code(const char *file, const char *func, int linenum) @@ -190,11 +191,11 @@ ulong bootstage_mark_code(const char *file, const char *func, int linenum) return bootstage_mark_name(BOOTSTAGE_ID_ALLOC, str); } -uint32_t bootstage_start(enum bootstage_id id, const char *name) +ulong bootstage_start(enum bootstage_id id, const char *name) { struct bootstage_data *data = gd->bootstage; struct bootstage_record *rec = ensure_id(data, id); - ulong start_us = timer_get_boot_us(); + ulong start_us = timer_get_us(); if (rec) { rec->start_us = start_us; @@ -204,15 +205,15 @@ uint32_t bootstage_start(enum bootstage_id id, const char *name) return start_us; } -uint32_t bootstage_accum(enum bootstage_id id) +ulong bootstage_accum(enum bootstage_id id) { struct bootstage_data *data = gd->bootstage; struct bootstage_record *rec = ensure_id(data, id); - uint32_t duration; + ulong duration; if (!rec) return 0; - duration = (uint32_t)timer_get_boot_us() - rec->start_us; + duration = timer_get_us() - rec->start_us; rec->time_us += duration; return duration; @@ -239,11 +240,11 @@ static const char *get_record_name(char *buf, int len, return buf; } -static uint32_t print_time_record(struct bootstage_record *rec, uint32_t prev) +static ulong print_time_record(struct bootstage_record *rec, ulong prev) { char buf[20]; - if (prev == -1U) { + if (prev == -1) { printf("%11s", ""); print_grouped_ull(rec->time_us, BOOTSTAGE_DIGITS); } else { @@ -331,7 +332,7 @@ void bootstage_report(void) { struct bootstage_data *data = gd->bootstage; struct bootstage_record *rec = data->record; - uint32_t prev; + ulong prev; int i; printf("Timer summary in microseconds (%d records):\n", @@ -530,6 +531,7 @@ int bootstage_init(bool first) if (first) { data->next_id = BOOTSTAGE_ID_USER; bootstage_add_record(BOOTSTAGE_ID_AWAKE, "reset", 0, 0); + data->start_time_us = timer_get_us(); } return 0; diff --git a/include/bootstage.h b/include/bootstage.h index 7088d0b875e4..e4516f5ca632 100644 --- a/include/bootstage.h +++ b/include/bootstage.h @@ -3,7 +3,7 @@ * This file implements recording of each stage of the boot process. It is * intended to implement timing of each stage, reporting this information * to the user and passing it to the OS for logging / further analysis. - * Note that it requires timer_get_boot_us() to be defined by the board + * Note that it requires CONFIG_TIMER_EARLY to be defined by the board * * Copyright (c) 2011 The Chromium OS Authors. */ @@ -215,13 +215,6 @@ enum bootstage_id { BOOTSTAGE_ID_ALLOC, }; -/* - * Return the time since boot in microseconds, This is needed for bootstage - * and should be defined in CPU- or board-specific code. If undefined then - * you will get a link error. - */ -ulong timer_get_boot_us(void); - #if defined(USE_HOSTCC) || !CONFIG_IS_ENABLED(SHOW_BOOT_PROGRESS) #define show_boot_progress(val) do {} while (0) #else @@ -313,7 +306,7 @@ ulong bootstage_mark_code(const char *file, const char *func, * @param name Textual name to display for this id in the report (maybe NULL) * Return: start timestamp in microseconds */ -uint32_t bootstage_start(enum bootstage_id id, const char *name); +ulong bootstage_start(enum bootstage_id id, const char *name); /** * Mark the end of a bootstage activity @@ -327,7 +320,7 @@ uint32_t bootstage_start(enum bootstage_id id, const char *name); * less the start time recorded in the last bootstage_start() call * with this id. */ -uint32_t bootstage_accum(enum bootstage_id id); +ulong bootstage_accum(enum bootstage_id id); /* Print a report about boot time */ void bootstage_report(void); @@ -418,12 +411,12 @@ static inline ulong bootstage_mark_code(const char *file, const char *func, return 0; } -static inline uint32_t bootstage_start(enum bootstage_id id, const char *name) +static inline ulong bootstage_start(enum bootstage_id id, const char *name) { return 0; } -static inline uint32_t bootstage_accum(enum bootstage_id id) +static inline ulong bootstage_accum(enum bootstage_id id) { return 0; } -- 2.37.3