Skip to content

Commit 7b9f1d1

Browse files
dengrafdlezcano
authored andcommitted
clocksource/drivers/tcb_clksrc: Use 32 bit tcb as sched_clock
On newer boards the TC can be read as single 32 bit value without locking. Thus the clock can be used as reference for sched_clock which is much more accurate than the jiffies implementation. Tested on a Atmel SAMA5D2 board. Signed-off-by: David Engraf <david.engraf@sysgo.com> Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
1 parent 4750535 commit 7b9f1d1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

drivers/clocksource/tcb_clksrc.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/io.h>
1111
#include <linux/platform_device.h>
1212
#include <linux/atmel_tc.h>
13+
#include <linux/sched_clock.h>
1314

1415

1516
/*
@@ -56,11 +57,16 @@ static u64 tc_get_cycles(struct clocksource *cs)
5657
return (upper << 16) | lower;
5758
}
5859

59-
static u64 tc_get_cycles32(struct clocksource *cs)
60+
static u32 tc_get_cv32(void)
6061
{
6162
return __raw_readl(tcaddr + ATMEL_TC_REG(0, CV));
6263
}
6364

65+
static u64 tc_get_cycles32(struct clocksource *cs)
66+
{
67+
return tc_get_cv32();
68+
}
69+
6470
static struct clocksource clksrc = {
6571
.name = "tcb_clksrc",
6672
.rating = 200,
@@ -69,6 +75,11 @@ static struct clocksource clksrc = {
6975
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
7076
};
7177

78+
static u64 notrace tc_read_sched_clock(void)
79+
{
80+
return tc_get_cv32();
81+
}
82+
7283
#ifdef CONFIG_GENERIC_CLOCKEVENTS
7384

7485
struct tc_clkevt_device {
@@ -339,6 +350,9 @@ static int __init tcb_clksrc_init(void)
339350
clksrc.read = tc_get_cycles32;
340351
/* setup ony channel 0 */
341352
tcb_setup_single_chan(tc, best_divisor_idx);
353+
354+
/* register sched_clock on chips with single 32 bit counter */
355+
sched_clock_register(tc_read_sched_clock, 32, divided_rate);
342356
} else {
343357
/* tclib will give us three clocks no matter what the
344358
* underlying platform supports.

0 commit comments

Comments
 (0)