summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2021-04-15 14:01:49 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-04-15 14:01:49 +0200
commit19df9d7b121f3a4faa6aa2516d00db13fa9c969d (patch)
tree46184a0db08212088bdd39c85d9fd3cf6cc5483c
parent18a358cc0a97ef3e06aa8f7d8fee365e31501e05 (diff)
parentd552af08749fde61564b39f41256858ce32ca0d0 (diff)
downloadbarebox-19df9d7b121f3a4faa6aa2516d00db13fa9c969d.tar.gz
barebox-19df9d7b121f3a4faa6aa2516d00db13fa9c969d.tar.xz
Merge branch 'for-next/clk'
-rw-r--r--common/clock.c13
-rw-r--r--common/console_common.c18
-rw-r--r--include/clock.h2
3 files changed, 15 insertions, 18 deletions
diff --git a/common/clock.c b/common/clock.c
index fa90d1a457..b300e5798a 100644
--- a/common/clock.c
+++ b/common/clock.c
@@ -17,12 +17,6 @@
static uint64_t time_ns;
-/*
- * The first timestamp when the clocksource is registered.
- * Useful for measuring the time spent in barebox.
- */
-uint64_t time_beginning;
-
static uint64_t dummy_read(void)
{
static uint64_t dummy_counter;
@@ -222,8 +216,13 @@ int init_clock(struct clocksource *cs)
return ret;
}
+ /*
+ * If clocksource is freerunning it might have been running for a while
+ * before barebox started, we only care about the time spent in barebox
+ * thus we must discard the clocksource cycles up to this exact moment:
+ */
+ cs->cycle_last = cs->read() & cs->mask;
current_clock = cs;
- time_beginning = get_time_ns();
return 0;
}
diff --git a/common/console_common.c b/common/console_common.c
index 3e07415723..4c1230464c 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -188,8 +188,8 @@ void log_print(unsigned flags, unsigned levels)
unsigned long last = 0;
list_for_each_entry(log, &barebox_logbuf, list) {
- uint64_t diff = log->timestamp - time_beginning;
- unsigned long difful;
+ uint64_t time_ns = log->timestamp;
+ unsigned long time;
if (levels && !(levels & (1 << log->level)))
continue;
@@ -201,21 +201,19 @@ void log_print(unsigned flags, unsigned levels)
if (flags & BAREBOX_LOG_PRINT_RAW)
printf("<%i>", log->level);
- do_div(diff, 1000);
- difful = diff;
-
- if (!log->timestamp)
- difful = 0;
+ /* convert ns to us */
+ do_div(time_ns, 1000);
+ time = time_ns;
if (flags & (BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))
printf("[");
if (flags & BAREBOX_LOG_PRINT_TIME)
- printf("%10luus", difful);
+ printf("%10luus", time);
if (flags & BAREBOX_LOG_DIFF_TIME) {
- printf(" < %10luus", difful - last);
- last = difful;
+ printf(" < %10luus", time - last);
+ last = time;
}
if (flags & (BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))
diff --git a/include/clock.h b/include/clock.h
index d681bf630e..e6197e7eb0 100644
--- a/include/clock.h
+++ b/include/clock.h
@@ -17,7 +17,7 @@ struct clocksource {
int (*init)(struct clocksource*);
};
-static inline uint32_t cyc2ns(struct clocksource *cs, uint64_t cycles)
+static inline uint64_t cyc2ns(struct clocksource *cs, uint64_t cycles)
{
uint64_t ret = cycles;
ret = (ret * cs->mult) >> cs->shift;