9
0
Fork 0

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>
This commit is contained in:
Jean-Christophe PLAGNIOL-VILLARD 2017-03-03 13:34:02 +01:00 committed by Sascha Hauer
parent 6bc48eabbf
commit 8972eb7ff1
1 changed files with 24 additions and 9 deletions

View File

@ -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;