From 8972eb7ff17ad058a6c6018305bb912138ab0ca2 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Fri, 3 Mar 2017 13:34:02 +0100 Subject: clocksource: move dummy clock source to init_clock And registered it as soon as possible (at pure initcall). So we not need to check the cs all the time. As get_time_ns() is one of the most called function of barebox at runtime. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- common/clock.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/common/clock.c b/common/clock.c index 1090b605f8..0d581c2c7e 100644 --- a/common/clock.c +++ b/common/clock.c @@ -36,9 +36,32 @@ static uint64_t time_ns; */ uint64_t time_beginning; +static uint64_t dummy_read(void) +{ + static uint64_t dummy_counter; + + dummy_counter += CONFIG_CLOCKSOURCE_DUMMY_RATE; + + return dummy_counter; +} + +static struct clocksource dummy_cs = { + .shift = 0, + .mult = 1, + .read = dummy_read, + .mask = CLOCKSOURCE_MASK(64), + .priority = -1, +}; + +static int dummy_csrc_init(void) +{ + return init_clock(&dummy_cs); +} +pure_initcall(dummy_csrc_init); + static int dummy_csrc_warn(void) { - if (!current_clock) { + if (current_clock == &dummy_cs) { pr_warn("Warning: Using dummy clocksource\n"); } @@ -55,14 +78,6 @@ uint64_t get_time_ns(void) uint64_t cycle_now, cycle_delta; uint64_t ns_offset; - if (!cs) { - static uint64_t dummy_counter; - - dummy_counter += CONFIG_CLOCKSOURCE_DUMMY_RATE; - - return dummy_counter; - } - /* read clocksource: */ cycle_now = cs->read() & cs->mask; -- cgit v1.2.3