Skip to contentSkip to conversation

clocksource: dw_apb: allow build for architectures other than arm

RFC PATCH In review Baruch Siach 3 participants 7 messages May 26, 2013 – Jun 20, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 2/2 clocksource: dw_apb: allow build for architectures other than arm

ARM is the only architecture providing sched_clock.h and setup_sched_clock(). Implement sched_clock() for use by other architectures.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jamie Iles <[email protected]>
Cc Dinh Nguyen <[email protected]>
---
 arch/arm/Kconfig                      |    1 +
 drivers/clocksource/Kconfig           |    3 +++
 drivers/clocksource/dw_apb_timer_of.c |   18 ++++++++++++++++++
 3 files changed, 22 insertions(+)
arch/arm/Kconfig +1 -0
index 1cacda4..7489604 100644
@@ -47,6 +47,7 @@ config ARM
 	select HAVE_OPROFILE if (HAVE_PERF_EVENTS)
 	select HAVE_PERF_EVENTS
 	select HAVE_REGS_AND_STACK_ACCESS_API
+	select HAVE_SETUP_SCHED_CLOCK
 	select HAVE_SYSCALL_TRACEPOINTS
 	select HAVE_UID16
 	select KTIME_SCALAR
drivers/clocksource/Kconfig +3 -0
index e507ab7..0fd6d13 100644
@@ -1,3 +1,6 @@
+config HAVE_SETUP_SCHED_CLOCK
+	bool
+
 config CLKSRC_OF
 	bool
 
drivers/clocksource/dw_apb_timer_of.c +18 -0
index 5a61ebc..9fdb4d3 100644
@@ -21,7 +21,11 @@
 #include <linux/of_address.h>
 #include <linux/of_irq.h>
 
+#ifdef CONFIG_HAVE_SETUP_SCHED_CLOCK
 #include <asm/sched_clock.h>
+#else
+#include <linux/sched.h>
+#endif
 
 static void timer_get_base_and_rate(struct device_node *np,
 				    void __iomem **base, u32 *rate)
@@ -73,6 +77,9 @@ static void add_clocksource(struct device_node *source_timer)
 }
 
 static void __iomem *sched_io_base;
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+static u64 sched_clock_mult __read_mostly;
+#endif
 
 static u32 read_sched_clock(void)
 {
@@ -97,7 +104,11 @@ static void init_sched_clock(void)
 	timer_get_base_and_rate(sched_timer, &sched_io_base, &rate);
 	of_node_put(sched_timer);
 
+#ifdef CONFIG_HAVE_SETUP_SCHED_CLOCK
 	setup_sched_clock(read_sched_clock, 32, rate);
+#else
+	sched_clock_mult = NSEC_PER_SEC / rate;
+#endif
 }
 
 static const struct of_device_id osctimer_ids[] __initconst = {
@@ -124,3 +135,10 @@ void __init dw_apb_timer_init(void)
 
 	init_sched_clock();
 }
+
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+unsigned long long notrace sched_clock()
+{
+	return read_sched_clock() * sched_clock_mult;
+}
+#endif
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 66 lines · Baruch Siach

ARM is the only architecture providing sched_clock.h and setup_sched_clock(). Implement sched_clock() for use by other architectures.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jamie Iles <[email protected]>
Cc Dinh Nguyen <[email protected]>
---
  arch/arm/Kconfig                      |    1 +
  drivers/clocksource/Kconfig           |    3 +++
  drivers/clocksource/dw_apb_timer_of.c |   18 ++++++++++++++++++
  3 files changed, 22 insertions(+)
arch/arm/Kconfig +1 -0
index 1cacda4..7489604 100644
@@ -47,6 +47,7 @@ config ARM
  	select HAVE_OPROFILE if (HAVE_PERF_EVENTS)
  	select HAVE_PERF_EVENTS
  	select HAVE_REGS_AND_STACK_ACCESS_API
+	select HAVE_SETUP_SCHED_CLOCK
  	select HAVE_SYSCALL_TRACEPOINTS
  	select HAVE_UID16
  	select KTIME_SCALAR
drivers/clocksource/Kconfig +3 -0
index e507ab7..0fd6d13 100644
@@ -1,3 +1,6 @@
+config HAVE_SETUP_SCHED_CLOCK
+	bool
+
  config CLKSRC_OF
  	bool
 
drivers/clocksource/dw_apb_timer_of.c +7 -0
index 5a61ebc..9fdb4d3 100644
@@ -21,7 +21,11 @@
  #include <linux/of_address.h>
  #include <linux/of_irq.h>
 
+#ifdef CONFIG_HAVE_SETUP_SCHED_CLOCK
  #include <asm/sched_clock.h>
+#else
+#include <linux/sched.h>
+#endif
 
  static void timer_get_base_and_rate(struct device_node *np,
  				    void __iomem **base, u32 *rate)
@@ -73,6 +77,9 @@ static void add_clocksource(struct device_node *source_timer)
  }
 
  static void __iomem *sched_io_base;
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+static u64 sched_clock_mult __read_mostly;
+#endif
 
  static u32 read_sched_clock(void)
  {

drivers/clocksource/dw_apb_timer_of.c static void init_sched_clock(void) · line 112

Quoted 9 lines
drivers/clocksource/dw_apb_timer_of.c +4 -0
@@ -97,7 +104,11 @@ static void init_sched_clock(void)
  	timer_get_base_and_rate(sched_timer, &sched_io_base, &rate);
  	of_node_put(sched_timer);
 
+#ifdef CONFIG_HAVE_SETUP_SCHED_CLOCK
  	setup_sched_clock(read_sched_clock, 32, rate);
+#else
+	sched_clock_mult = NSEC_PER_SEC / rate;
+#endif
  }

Can you rework this to not use #ifdefs within the function? They make it annoying to read the code.

Instead maybe have a local setup_sched_clock() function that sets the mult value for the !CONFIG_HAVE_SETUP_SCHED_CLOCK case?

drivers/clocksource/dw_apb_timer_of.c void __init dw_apb_timer_init(void) · line 144

Quoted 13 lines
drivers/clocksource/dw_apb_timer_of.c +7 -0
  static const struct of_device_id osctimer_ids[] __initconst = {
@@ -124,3 +135,10 @@ void __init dw_apb_timer_init(void)
 
  	init_sched_clock();
  }
+
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+unsigned long long notrace sched_clock()
+{
+	return read_sched_clock() * sched_clock_mult;
+}
+#endif

Also, can you try to condense the number of #ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK checks to one, and consolidate the needed functions all in that one conditional?

thanks
-john

#2 lore raw

Hi John,

Quoted 12 lines · John Stultz
Quoted 11 lines · Baruch Siach

ARM is the only architecture providing sched_clock.h and setup_sched_clock(). Implement sched_clock() for use by other architectures.

Cc Ingo Molnar <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc John Stultz <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Jamie Iles <[email protected]>
Cc Dinh Nguyen <[email protected]>

---

[snip]

Quoted 25 lines
Quoted 10 lines
drivers/clocksource/dw_apb_timer_of.c +3 -0
@@ -73,6 +77,9 @@ static void add_clocksource(struct device_node 
 *source_timer)
 }
 static void __iomem *sched_io_base;
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+static u64 sched_clock_mult __read_mostly;
+#endif
 static u32 read_sched_clock(void)
 {

drivers/clocksource/dw_apb_timer_of.c static void init_sched_clock(void) · line 111

Quoted 8 lines
drivers/clocksource/dw_apb_timer_of.c +4 -0
@@ -97,7 +104,11 @@ static void init_sched_clock(void)
 	timer_get_base_and_rate(sched_timer, &sched_io_base, &rate);
 	of_node_put(sched_timer);
+#ifdef CONFIG_HAVE_SETUP_SCHED_CLOCK
 	setup_sched_clock(read_sched_clock, 32, rate);
+#else
+	sched_clock_mult = NSEC_PER_SEC / rate;
+#endif
 }

Can you rework this to not use #ifdefs within the function? They make it annoying to read the code.

Instead maybe have a local setup_sched_clock() function that sets the mult value for the !CONFIG_HAVE_SETUP_SCHED_CLOCK case?

Quoted 15 lines

drivers/clocksource/dw_apb_timer_of.c void __init dw_apb_timer_init(void) · line 143

Quoted 11 lines
drivers/clocksource/dw_apb_timer_of.c +7 -0
 static const struct of_device_id osctimer_ids[] __initconst = {
@@ -124,3 +135,10 @@ void __init dw_apb_timer_init(void)
 	init_sched_clock();
 }
+
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+unsigned long long notrace sched_clock()
+{
+	return read_sched_clock() * sched_clock_mult;
+}
+#endif

Also, can you try to condense the number of #ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK checks to one, and consolidate the needed functions all in that one conditional?

Thanks for your comments. I'll rework the patch and resubmit.

I've just noticed that I have a bigger problem. read_sched_clock() returns u32, not u64. This means that in a rate of, say, 100MHz it will wrap around after a little more than 40 seconds. Would it make sense to put ARM's 32 bin sched_clock extension code (arch/arm/kernel/sched_clock.c) is a common place (maybe drivers/clocksource), and use that? There seems to be nothing ARM specific in this code, after all.

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#3 lore raw
Quoted 18 lines · Baruch Siach

Hi John,

Quoted 15 lines · John Stultz

drivers/clocksource/dw_apb_timer_of.c void __init dw_apb_timer_init(void) · line 143

Quoted 11 lines · Baruch Siach
  static const struct of_device_id osctimer_ids[] __initconst = {
drivers/clocksource/dw_apb_timer_of.c +7 -0
@@ -124,3 +135,10 @@ void __init dw_apb_timer_init(void)
  	init_sched_clock();
  }
+
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+unsigned long long notrace sched_clock()
+{
+	return read_sched_clock() * sched_clock_mult;
+}
+#endif

Also, can you try to condense the number of #ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK checks to one, and consolidate the needed functions all in that one conditional?

Quoted 8 lines

Thanks for your comments. I'll rework the patch and resubmit.

I've just noticed that I have a bigger problem. read_sched_clock() returns u32, not u64. This means that in a rate of, say, 100MHz it will wrap around after a little more than 40 seconds. Would it make sense to put ARM's 32 bin sched_clock extension code (arch/arm/kernel/sched_clock.c) is a common place (maybe drivers/clocksource), and use that? There seems to be nothing ARM specific in this code, after all.

Yea, working out an actual generic sched_clock implementation is something I'd like to see done.

Though I'd really rather we not toss yet another chunk of infrastructure in the drivers/clocksource directory. Instead we should probably have a kernel/time/sched_clock.c.

Then its just the issue of tying that and the clocksource code together so you just register existing capable clocksources with a SCHED_CLOCK flag or via a different registration hook.

I don't think it will be an easy job, but if you want to give it a shot, I'd be quite interested in reviewing the patches!

thanks
-john

#4 lore raw

Hi John,

Quoted 33 lines · John Stultz
Quoted 16 lines · Baruch Siach
Quoted 15 lines · John Stultz

drivers/clocksource/dw_apb_timer_of.c void __init dw_apb_timer_init(void) · line 143

Quoted 11 lines · Baruch Siach

static const struct of_device_id osctimer_ids[] __initconst = {

drivers/clocksource/dw_apb_timer_of.c +7 -0
@@ -124,3 +135,10 @@ void __init dw_apb_timer_init(void)
 	init_sched_clock();
 }
+
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+unsigned long long notrace sched_clock()
+{
+	return read_sched_clock() * sched_clock_mult;
+}
+#endif

Also, can you try to condense the number of #ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK checks to one, and consolidate the needed functions all in that one conditional?

Quoted 8 lines

Thanks for your comments. I'll rework the patch and resubmit.

I've just noticed that I have a bigger problem. read_sched_clock() returns u32, not u64. This means that in a rate of, say, 100MHz it will wrap around after a little more than 40 seconds. Would it make sense to put ARM's 32 bin sched_clock extension code (arch/arm/kernel/sched_clock.c) is a common place (maybe drivers/clocksource), and use that? There seems to be nothing ARM specific in this code, after all.

Yea, working out an actual generic sched_clock implementation is something I'd like to see done.

Though I'd really rather we not toss yet another chunk of infrastructure in the drivers/clocksource directory. Instead we should probably have a kernel/time/sched_clock.c.

Quoted 6 lines

Then its just the issue of tying that and the clocksource code together so you just register existing capable clocksources with a SCHED_CLOCK flag or via a different registration hook.

I don't think it will be an easy job, but if you want to give it a shot, I'd be quite interested in reviewing the patches!

Although I'd very much like to contribute in this area, I'm afraid I don't have time for this now. My problem is much narrower in scope, though, and I think it can be solved without a generic sched_clock implementation at first step. All I want is to use a 32 bit counter for sched_clock. The code enabling this is currently only available for ARM (arch/arm/kernel/sched_clock.c). Should this part of the code move to kernel/time/sched_clock.c?

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#5 lore raw
In reply to Baruch Siach

Hi!

Quoted 41 lines
Quoted 25 lines
Quoted 10 lines
drivers/clocksource/dw_apb_timer_of.c +3 -0
@@ -73,6 +77,9 @@ static void add_clocksource(struct device_node 
 *source_timer)
 }
 static void __iomem *sched_io_base;
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+static u64 sched_clock_mult __read_mostly;
+#endif
 static u32 read_sched_clock(void)
 {

drivers/clocksource/dw_apb_timer_of.c static void init_sched_clock(void) · line 111

Quoted 8 lines
drivers/clocksource/dw_apb_timer_of.c +4 -0
@@ -97,7 +104,11 @@ static void init_sched_clock(void)
 	timer_get_base_and_rate(sched_timer, &sched_io_base, &rate);
 	of_node_put(sched_timer);
+#ifdef CONFIG_HAVE_SETUP_SCHED_CLOCK
 	setup_sched_clock(read_sched_clock, 32, rate);
+#else
+	sched_clock_mult = NSEC_PER_SEC / rate;
+#endif
 }

Can you rework this to not use #ifdefs within the function? They make it annoying to read the code.

Instead maybe have a local setup_sched_clock() function that sets the mult value for the !CONFIG_HAVE_SETUP_SCHED_CLOCK case?

Quoted 15 lines

drivers/clocksource/dw_apb_timer_of.c void __init dw_apb_timer_init(void) · line 143

Quoted 11 lines
drivers/clocksource/dw_apb_timer_of.c +7 -0
 static const struct of_device_id osctimer_ids[] __initconst = {
@@ -124,3 +135,10 @@ void __init dw_apb_timer_init(void)
 	init_sched_clock();
 }
+
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+unsigned long long notrace sched_clock()
+{
+	return read_sched_clock() * sched_clock_mult;
+}
+#endif

Also, can you try to condense the number of #ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK checks to one, and consolidate the needed functions all in that one conditional?

Quoted 8 lines

Thanks for your comments. I'll rework the patch and resubmit.

I've just noticed that I have a bigger problem. read_sched_clock() returns u32, not u64. This means that in a rate of, say, 100MHz it will wrap around after a little more than 40 seconds. Would it make sense to put ARM's 32 bin sched_clock extension code (arch/arm/kernel/sched_clock.c) is a common place (maybe drivers/clocksource), and use that? There seems to be nothing ARM specific in this code, after all.

Also note that there are two conflicting changes to this area pending. It seems one in soc-next arm tree will prevail.

Please take a look...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw

Hi Pavel,

Quoted 50 lines · Pavel Machek
Quoted 41 lines
Quoted 25 lines
Quoted 10 lines
drivers/clocksource/dw_apb_timer_of.c +3 -0
@@ -73,6 +77,9 @@ static void add_clocksource(struct device_node 
 *source_timer)
 }
 static void __iomem *sched_io_base;
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+static u64 sched_clock_mult __read_mostly;
+#endif
 static u32 read_sched_clock(void)
 {

drivers/clocksource/dw_apb_timer_of.c static void init_sched_clock(void) · line 111

Quoted 8 lines
drivers/clocksource/dw_apb_timer_of.c +4 -0
@@ -97,7 +104,11 @@ static void init_sched_clock(void)
 	timer_get_base_and_rate(sched_timer, &sched_io_base, &rate);
 	of_node_put(sched_timer);
+#ifdef CONFIG_HAVE_SETUP_SCHED_CLOCK
 	setup_sched_clock(read_sched_clock, 32, rate);
+#else
+	sched_clock_mult = NSEC_PER_SEC / rate;
+#endif
 }

Can you rework this to not use #ifdefs within the function? They make it annoying to read the code.

Instead maybe have a local setup_sched_clock() function that sets the mult value for the !CONFIG_HAVE_SETUP_SCHED_CLOCK case?

Quoted 15 lines

drivers/clocksource/dw_apb_timer_of.c void __init dw_apb_timer_init(void) · line 143

Quoted 11 lines
drivers/clocksource/dw_apb_timer_of.c +7 -0
 static const struct of_device_id osctimer_ids[] __initconst = {
@@ -124,3 +135,10 @@ void __init dw_apb_timer_init(void)
 	init_sched_clock();
 }
+
+#ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK
+unsigned long long notrace sched_clock()
+{
+	return read_sched_clock() * sched_clock_mult;
+}
+#endif

Also, can you try to condense the number of #ifndef CONFIG_HAVE_SETUP_SCHED_CLOCK checks to one, and consolidate the needed functions all in that one conditional?

Quoted 8 lines

Thanks for your comments. I'll rework the patch and resubmit.

I've just noticed that I have a bigger problem. read_sched_clock() returns u32, not u64. This means that in a rate of, say, 100MHz it will wrap around after a little more than 40 seconds. Would it make sense to put ARM's 32 bin sched_clock extension code (arch/arm/kernel/sched_clock.c) is a common place (maybe drivers/clocksource), and use that? There seems to be nothing ARM specific in this code, after all.

Quoted 4 lines

Also note that there are two conflicting changes to this area pending. It seems one in soc-next arm tree will prevail.

Please take a look...

Now that generic sched_clock implementation is available to all architectures (38ff87f77 "sched_clock: Make ARM's sched_clock generic for all architectures" in the timers/core branch of the tip tree) this patch is not needed anymore.

Thanks for the head up.

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -