Skip to contentSkip to conversation

How to use a different sched_clock() for ftrace on omap?

PATCH Tim Bird 4 participants 5 messages May 6, 2009 – May 7, 2009

Subsystems (3)
lore
Share & tools
lore

Tim Bird

author
#0 lore raw

Hi all,

I've worked up a replacement sched_clock for ftrace on my omap platform. The current sched_clock, based on the 32K timer, has low resolution and doesn't provide very useful results.

Unfortunately, I'm not sure the best way to use my special one, in place of a common one in arch/arm/plat-omap/common.c

Here's a patch:

---
 arch/arm/mach-omap1/time.c  |    9 +++++++++
 arch/arm/plat-omap/common.c |    2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)
arch/arm/mach-omap1/time.c +9 -0
@@ -212,6 +212,15 @@ static struct clocksource clocksource_mp
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
+unsigned long long notrace sched_clock(void)
+{
+	unsigned long long ret;
+
+	ret = (unsigned long long) ~omap_mpu_timer_read(1);
+	ret = (ret * clocksource_mpu.mult_orig) >>clocksource_mpu.shift;
+	return ret;
+}
+
 static void __init omap_init_clocksource(unsigned long rate)
 {
 	static char err[] __initdata = KERN_ERR
arch/arm/plat-omap/common.c +1 -1
@@ -203,7 +203,7 @@ static struct clocksource clocksource_32
  * Returns current time from boot in nsecs. It's OK for this to wrap
  * around for now, as it's just a relative time stamp.
  */
-unsigned long long notrace sched_clock(void)
+__attribute__((weak)) unsigned long long notrace sched_clock_old(void)
 {
 	unsigned long long ret;
 

Obviously, renaming the common sched_clock() to sched_clock_old() is a hack.

I thought the __attribute__ ((weak)) would be enough to have the sched_clock() in common.c get out of the way, and allow my board-specific sched_clock() to be used. But that didn't work. What is the recommended way to specify a board-specific function at compile time?

Thanks,
-- Tim

=============================
Tim Bird
Architecture Group Chair, CE Linux Forum Senior Staff Engineer, Sony Corporation of America
=============================

#1 lore raw
Quoted 6 lines · Tim Bird

Hi all,

I've worked up a replacement sched_clock for ftrace on my omap platform. The current sched_clock, based on the 32K timer, has low resolution and doesn't provide very useful results.

Quoted 6 lines

Unfortunately, I'm not sure the best way to use my special one, in place of a common one in arch/arm/plat-omap/common.c

I thought the __attribute__ ((weak)) would be enough to have the sched_clock() in common.c get out of the way, and allow my board-specific sched_clock() to be used. But that didn't work.

Not sure that will work correctly since sched_clock in kernel/sched.c is already defined as weak. If you have two weak versions of a function I think the one which gets used is based on link order (if your board's sched_clock is not being used).

Quoted 2 lines

What is the recommended
way to specify a board-specific function at compile time?

You could look at arch/x86/kernel/tsc_32.c, I think it does what you want by using the function called native_sched_clock for the default sched_clock implementation and using the alias attribute if no board specific implementation is given, ie:

#ifdef CONFIG_SOME_BOARD
unsigned long long sched_clock(void)

{
	some_board_sched_clock();
}
#else
unsigned long long sched_clock(void)
	__attribute__((alias("native_sched_clock")));

#endif

You could make it more generic by have some_board_sched_clock be a #define (__board_sched_clock or something), so if a board defines it (will need to be in a platform wide header) then you use that, otherwise you use native_sched_clock.

~Ryan

Signature · 8 lines
Bluewater Systems Ltd - ARM Technology Solution Centre

       Ryan Mallon                              Unit 5, Amuri Park
       Phone: +64 3 3779127                     404 Barbadoes St
       Fax:   +64 3 3779135                     PO Box 13 889
       Email: [email protected]             Christchurch, 8013
       Web:   http://www.bluewatersys.com       New Zealand
       Freecall Australia  1800 148 751         USA 1800 261 2934
#2 lore raw
In reply to Tim Bird
Quoted 5 lines · Tim Bird

Hi all,

I've worked up a replacement sched_clock for ftrace on my omap platform. The current sched_clock, based on the 32K timer, has low resolution and doesn't provide very useful results.

hm, why dont you replace the real sched_clock() with it? High resolution sched_clock() gives (much!) better scheduling, better fairness, etc.

Ingo

#3 lore raw
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Tim Bird

Hi all,

Quoted 7 lines
Quoted 3 lines

I've worked up a replacement sched_clock for ftrace on my omap platform. The current sched_clock, based on the 32K timer, has low resolution and doesn't provide very useful results.

hm, why dont you replace the real sched_clock() with it? High resolution sched_clock() gives (much!) better scheduling, better fairness, etc.

Probably because it is board specific, that he can not replace it. But I think something like Ryan's idea would be good. Instead of aliasing, just make another weak symbol.

unsigned long long __attribute__((weak)) board_sched_clock(void) {
[ original sched_clock code ]
}

unsigned long long sched_clock(void)

{
	return board_sched_clock();
}

Then Tim could define a "board_sched_clock" that would be used when that board is active.

-- Steve

#4 lore raw
Quoted 25 lines · Steven Rostedt
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Tim Bird

Hi all,

Quoted 7 lines
Quoted 3 lines

I've worked up a replacement sched_clock for ftrace on my omap platform. The current sched_clock, based on the 32K timer, has low resolution and doesn't provide very useful results.

hm, why dont you replace the real sched_clock() with it? High resolution sched_clock() gives (much!) better scheduling, better fairness, etc.

Probably because it is board specific, that he can not replace it. But I think something like Ryan's idea would be good. Instead of aliasing, just make another weak symbol.

unsigned long long __attribute__((weak)) board_sched_clock(void) {
[ original sched_clock code ]
}

Quoted 7 lines

unsigned long long sched_clock(void)

{
	return board_sched_clock();
}

Then Tim could define a "board_sched_clock" that would be used when that board is active.

that sounds good. Weak aliases are now generally supported in Linux, we excluded that one broken GCC version that messed them up.

Ingo