linux-rt-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/1] Clocksource: Add sched_clock to Atmel TCB clocksource
@ 2015-06-02 21:46 Carsten Emde
  2015-06-02 22:08 ` [PATCH V2 RESEND " Carsten Emde
  0 siblings, 1 reply; 3+ messages in thread
From: Carsten Emde @ 2015-06-02 21:46 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Sebastian Andrzej Siewior, RT-users, Carsten Emde

[-- Attachment #1: drivers-clocksource-tcb-register-sched-clock.patch --]
[-- Type: text/plain, Size: 2189 bytes --]

The default sched_clock provides a maximum resolution of 1 ms which
normally is not sufficient to investigate scheduling related
irregularities - more so, if a low-latency or even a real-time kernel is
used. Therefore, register the Atmel TCB clocksource that provides a
resolution of 63 ns as sched_clock.

Signed-off-by: Carsten Emde <C.Emde@osadl.org>

---
 drivers/clocksource/tcb_clksrc.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

Index: linux/drivers/clocksource/tcb_clksrc.c
===================================================================
--- linux.orig/drivers/clocksource/tcb_clksrc.c
+++ linux/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>
 
 
 /*
@@ -41,6 +42,14 @@
 
 static void __iomem *tcaddr;
 
+static struct clocksource clksrc = {
+	.name           = "tcb_clksrc",
+	.rating         = 200,
+	.read           = tc_get_cycles,
+	.mask           = CLOCKSOURCE_MASK(32),
+	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
 static cycle_t tc_get_cycles(struct clocksource *cs)
 {
 	unsigned long	flags;
@@ -61,13 +70,10 @@ static cycle_t tc_get_cycles32(struct cl
 	return __raw_readl(tcaddr + ATMEL_TC_REG(0, CV));
 }
 
-static struct clocksource clksrc = {
-	.name           = "tcb_clksrc",
-	.rating         = 200,
-	.read           = tc_get_cycles,
-	.mask           = CLOCKSOURCE_MASK(32),
-	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
-};
+static u64 sched_clock_get_cycles(void)
+{
+	return (u64) do_sched_clock_get_cycles(NULL);
+}
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
@@ -273,6 +279,7 @@ static int __init tcb_clksrc_init(void)
 	int clk32k_divisor_idx = -1;
 	int i;
 	int ret;
+	unsigned long flags;
 
 	tc = atmel_tc_alloc(CONFIG_ATMEL_TCB_CLKSRC_BLOCK);
 	if (!tc) {
@@ -339,6 +346,10 @@ static int __init tcb_clksrc_init(void)
 	if (ret)
 		goto err_disable_t1;
 
+	local_irq_save(flags);
+	sched_clock_register(sched_clock_get_cycles, 32, divided_rate);
+	local_irq_restore(flags);
+
 	/* channel 2:  periodic and oneshot timer support */
 	ret = setup_clkevents(tc, clk32k_divisor_idx);
 	if (ret)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2 RESEND  1/1] Clocksource: Add sched_clock to Atmel TCB clocksource
  2015-06-02 21:46 [PATCH V2 1/1] Clocksource: Add sched_clock to Atmel TCB clocksource Carsten Emde
@ 2015-06-02 22:08 ` Carsten Emde
  2015-06-11 15:15   ` Sebastian Andrzej Siewior
  0 siblings, 1 reply; 3+ messages in thread
From: Carsten Emde @ 2015-06-02 22:08 UTC (permalink / raw)
  To: Thomas Gleixner; +Cc: Sebastian Andrzej Siewior, RT-users

[Sorry, picked wrong patch]

The default sched_clock provides a maximum resolution of 1 ms which
normally is not sufficient to investigate scheduling related
irregularities - more so, if a low-latency or even a real-time kernel is
used. Therefore, register the Atmel TCB clocksource that provides a
resolution of 63 ns as sched_clock.

Signed-off-by: Carsten Emde <C.Emde@osadl.org>

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

Index: linux/drivers/clocksource/tcb_clksrc.c
===================================================================
--- linux.orig/drivers/clocksource/tcb_clksrc.c
+++ linux/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>


  /*
@@ -69,6 +70,11 @@ static struct clocksource clksrc = {
  	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
  };

+static u64 sched_clock_get_cycles(void)
+{
+	return (u64) clksrc.read(NULL);
+}
+
  #ifdef CONFIG_GENERIC_CLOCKEVENTS

  struct tc_clkevt_device {
@@ -273,6 +279,7 @@ static int __init tcb_clksrc_init(void)
  	int clk32k_divisor_idx = -1;
  	int i;
  	int ret;
+	unsigned long flags;

  	tc = atmel_tc_alloc(CONFIG_ATMEL_TCB_CLKSRC_BLOCK);
  	if (!tc) {
@@ -339,6 +346,10 @@ static int __init tcb_clksrc_init(void)
  	if (ret)
  		goto err_disable_t1;

+	local_irq_save(flags);
+	sched_clock_register(sched_clock_get_cycles, 32, divided_rate);
+	local_irq_restore(flags);
+
  	/* channel 2:  periodic and oneshot timer support */
  	ret = setup_clkevents(tc, clk32k_divisor_idx);
  	if (ret)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V2 RESEND  1/1] Clocksource: Add sched_clock to Atmel TCB clocksource
  2015-06-02 22:08 ` [PATCH V2 RESEND " Carsten Emde
@ 2015-06-11 15:15   ` Sebastian Andrzej Siewior
  0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2015-06-11 15:15 UTC (permalink / raw)
  To: Carsten Emde; +Cc: Thomas Gleixner, RT-users

* Carsten Emde | 2015-06-03 00:08:05 [+0200]:

>@@ -339,6 +346,10 @@ static int __init tcb_clksrc_init(void)
> 	if (ret)
> 		goto err_disable_t1;
>
>+	local_irq_save(flags);
>+	sched_clock_register(sched_clock_get_cycles, 32, divided_rate);
>+	local_irq_restore(flags);

The other sched_clock_register() users don't do this and are invoked via
CLOCKSOURCE_OF_DECLARE / clocksource_of_init() and this is probably
early enough so the irqs stay off.
Since this is not -RT specific at all, do you mind routing it via ARM/
clocksource folks? They also may have an idea what is stopping them from
using clocksource_of_init() so you wouldn't have to disable interrupts
here.

> 	/* channel 2:  periodic and oneshot timer support */
> 	ret = setup_clkevents(tc, clk32k_divisor_idx);
> 	if (ret)

Sebastian

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-06-11 15:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-02 21:46 [PATCH V2 1/1] Clocksource: Add sched_clock to Atmel TCB clocksource Carsten Emde
2015-06-02 22:08 ` [PATCH V2 RESEND " Carsten Emde
2015-06-11 15:15   ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).