Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1577184

[PATCH 04/10] clocksource/drivers/tcb_clksrc: Use 32 bit tcb as sched_clock

From Daniel Lezcano <daniel.lezcano@linaro.org>
Newsgroups linux.kernel
Subject [PATCH 04/10] clocksource/drivers/tcb_clksrc: Use 32 bit tcb as sched_clock
Date 2017-02-09 00:20 +0100
Message-ID <t8JGN-6E5-11@gated-at.bofh.it> (permalink)
References <t8JGN-6E5-9@gated-at.bofh.it> <t8JGN-6E5-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: David Engraf <david.engraf@sysgo.com>

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>
---
 drivers/clocksource/tcb_clksrc.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c
index d4ca996..745844e 100644
--- a/drivers/clocksource/tcb_clksrc.c
+++ b/drivers/clocksource/tcb_clksrc.c
@@ -10,6 +10,7 @@
 #include <linux/io.h>
 #include <linux/platform_device.h>
 #include <linux/atmel_tc.h>
+#include <linux/sched_clock.h>
 
 
 /*
@@ -56,11 +57,16 @@ static u64 tc_get_cycles(struct clocksource *cs)
 	return (upper << 16) | lower;
 }
 
-static u64 tc_get_cycles32(struct clocksource *cs)
+static u32 tc_get_cv32(void)
 {
 	return __raw_readl(tcaddr + ATMEL_TC_REG(0, CV));
 }
 
+static u64 tc_get_cycles32(struct clocksource *cs)
+{
+	return tc_get_cv32();
+}
+
 static struct clocksource clksrc = {
 	.name           = "tcb_clksrc",
 	.rating         = 200,
@@ -69,6 +75,11 @@ static struct clocksource clksrc = {
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
+static u64 notrace tc_read_sched_clock(void)
+{
+	return tc_get_cv32();
+}
+
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 struct tc_clkevt_device {
@@ -339,6 +350,9 @@ static int __init tcb_clksrc_init(void)
 		clksrc.read = tc_get_cycles32;
 		/* setup ony channel 0 */
 		tcb_setup_single_chan(tc, best_divisor_idx);
+
+		/* register sched_clock on chips with single 32 bit counter */
+		sched_clock_register(tc_read_sched_clock, 32, divided_rate);
 	} else {
 		/* tclib will give us three clocks no matter what the
 		 * underlying platform supports.
-- 
2.7.4

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[GIT PULL] clockevents for 4.11 Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 00:20 +0100
  [PATCH 04/10] clocksource/drivers/tcb_clksrc: Use 32 bit tcb as sched_clock Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 00:20 +0100
  [PATCH 03/10] clocksource/drivers/gemini: Add driver for the Cortina Gemini Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 00:20 +0100
  [PATCH 05/10] clocksource/drivers/ostm: Document renesas-ostm timer DT bindings Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 00:20 +0100
  [PATCH 08/10] clocksource/drivers/arm_arch_timer: Remove fsl-a008585 parameter Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 00:30 +0100
  [PATCH 10/10] clocksource/drivers/arm_arch_timer: Work around Hisilicon erratum 161010101 Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 00:30 +0100
  [PATCH 01/10] clockevents: Add a clkevt-of mechanism like clksrc-of Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 00:30 +0100
    [PATCH 06/10] clocksource/drivers/ostm: Add renesas-ostm timer driver Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 01:20 +0100
    [PATCH 02/10] clocksource: add DT bindings for Cortina Gemini Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 01:30 +0100
    [PATCH 09/10] clocksource/drivers/arm_arch_timer: Introduce generic errata handling infrastructure Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 02:00 +0100
    [PATCH 07/10] clocksource/drivers/arm_arch_timer: Add dt binding for hisilicon-161010101 erratum Daniel Lezcano <daniel.lezcano@linaro.org> - 2017-02-09 02:00 +0100

csiph-web