diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2017-03-03 13:34:02 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2017-03-09 07:36:15 +0100 |
commit | 8972eb7ff17ad058a6c6018305bb912138ab0ca2 (patch) | |
tree | 6c0d6781f8a0c4fcc148536dd4cecaa4f0347f9e /common/clock.c | |
parent | 6bc48eabbfe78906ac2b7fa8e12cc9b0608c76bd (diff) | |
download | barebox-8972eb7ff17ad058a6c6018305bb912138ab0ca2.tar.gz barebox-8972eb7ff17ad058a6c6018305bb912138ab0ca2.tar.xz |
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 <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/clock.c')
-rw-r--r-- | common/clock.c | 33 |
1 files 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; |