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


Groups > linux.kernel > #1327043 > unrolled thread

[PATCH v1] clocksource: atmel-pit: register as a sched_clock

Started byRomain Izard <romain.izard.pro@gmail.com>
First post2016-02-04 18:30 +0100
Last post2016-02-08 15:10 +0100
Articles 3 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH v1] clocksource: atmel-pit: register as a sched_clock Romain Izard <romain.izard.pro@gmail.com> - 2016-02-04 18:30 +0100
    Re: [PATCH v1] clocksource: atmel-pit: register as a sched_clock Daniel Lezcano <daniel.lezcano@linaro.org> - 2016-02-08 14:40 +0100
      Re: [PATCH v1] clocksource: atmel-pit: register as a sched_clock Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-02-08 15:10 +0100

#1327043 — [PATCH v1] clocksource: atmel-pit: register as a sched_clock

FromRomain Izard <romain.izard.pro@gmail.com>
Date2016-02-04 18:30 +0100
Subject[PATCH v1] clocksource: atmel-pit: register as a sched_clock
Message-ID<qYvTd-53o-27@gated-at.bofh.it>
Register the counter of the Periodic Interval Timer as a possible source
for sched_clock. This provides a better precision than the jiffies-based
default.

Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
---

To reduce overhead and cache consumption, sched_clock_register does not
take a void* argument, as it is the case when using interrupt handlers.
As a result, the signature of the function used to read the counter is
u64 (*) (void). It is thus necessary to use a static variable inside the
driver to keep a reference to the clocksource. It is a common pattern in
other existing clocksource drivers.

All existing Atmel SoCs that rely on the PIT only have a single instance
of the controller, and future SoCs should remain this way as additional
timers are provided in 'Timer Counter' controllers. Additional code
handling the case of multiple PIT instances would thus be dead code.

 drivers/clocksource/timer-atmel-pit.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/clocksource/timer-atmel-pit.c b/drivers/clocksource/timer-atmel-pit.c
index d911c5dca8f1..744e1afc4b69 100644
--- a/drivers/clocksource/timer-atmel-pit.c
+++ b/drivers/clocksource/timer-atmel-pit.c
@@ -21,6 +21,7 @@
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 #include <linux/slab.h>
+#include <linux/sched_clock.h>
 
 #define AT91_PIT_MR		0x00			/* Mode Register */
 #define AT91_PIT_PITIEN			BIT(25)			/* Timer Interrupt Enable */
@@ -174,6 +175,13 @@ static irqreturn_t at91sam926x_pit_interrupt(int irq, void *dev_id)
 	return IRQ_NONE;
 }
 
+static struct clocksource *pit_sched_clock;
+
+static u64 pit_sched_clock_read(void)
+{
+	return read_pit_clk(pit_sched_clock);
+}
+
 /*
  * Set up both clocksource and clockevent support.
  */
@@ -206,6 +214,9 @@ static void __init at91sam926x_pit_common_init(struct pit_data *data)
 	data->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
 	clocksource_register_hz(&data->clksrc, pit_rate);
 
+	pit_sched_clock = &data->clksrc;
+	sched_clock_register(pit_sched_clock_read, bits, pit_rate);
+
 	/* Set up irq handler */
 	ret = request_irq(data->irq, at91sam926x_pit_interrupt,
 			  IRQF_SHARED | IRQF_TIMER | IRQF_IRQPOLL,
-- 
2.5.0

[toc] | [next] | [standalone]


#1329050

FromDaniel Lezcano <daniel.lezcano@linaro.org>
Date2016-02-08 14:40 +0100
Message-ID<qZUcP-5U1-37@gated-at.bofh.it>
In reply to#1327043
On 02/04/2016 06:21 PM, Romain Izard wrote:
> Register the counter of the Periodic Interval Timer as a possible source
> for sched_clock. This provides a better precision than the jiffies-based
> default.
>
> Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>

Nicolas, Boris,

Are you ok with this patch ?

[ ... ]

-- 
  <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

[toc] | [prev] | [next] | [standalone]


#1329085

FromBoris Brezillon <boris.brezillon@free-electrons.com>
Date2016-02-08 15:10 +0100
Message-ID<qZUFR-6nz-29@gated-at.bofh.it>
In reply to#1329050
+ Alexandre

Hi Daniel,

On Mon, 8 Feb 2016 14:33:04 +0100
Daniel Lezcano <daniel.lezcano@linaro.org> wrote:

> On 02/04/2016 06:21 PM, Romain Izard wrote:
> > Register the counter of the Periodic Interval Timer as a possible source
> > for sched_clock. This provides a better precision than the jiffies-based
> > default.
> >
> > Signed-off-by: Romain Izard <romain.izard.pro@gmail.com>
> 
> Nicolas, Boris,
> 
> Are you ok with this patch ?

Not sure yet :). On most platforms we are also declaring a clocksource
based on the TCB IP, and this one provides a better precision than the
PIT clocksource.
What happens if the PIT is de-activated while it's still supposed to
provide the sched_clock(). Is there a way to flag the clocksource as
still needed so that the core does not shut it down by when the TCB
clocksource comes in.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web