From b02fd5a7e6dc10d11a26f7d48244a006d1cbcbc9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E9=BB=84=E6=B6=9B?= Date: Fri, 11 Mar 2011 13:20:01 +0800 Subject: [PATCH] rk29: implement sched_clock() --- arch/arm/Kconfig | 2 +- arch/arm/mach-rk29/timer.c | 34 ++++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 5a41a4dec78e..df6eafbf69b8 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -721,10 +721,10 @@ config ARCH_RK2818 config ARCH_RK29 bool "Rockchip Soc Rk29" - select HAVE_CLK select CPU_V7 select HAVE_CLK select COMMON_CLKDEV + select HAVE_SCHED_CLOCK select ARCH_HAS_CPUFREQ select GENERIC_TIME select GENERIC_CLOCKEVENTS diff --git a/arch/arm/mach-rk29/timer.c b/arch/arm/mach-rk29/timer.c index 501d820668ab..b00430d78533 100644 --- a/arch/arm/mach-rk29/timer.c +++ b/arch/arm/mach-rk29/timer.c @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -166,12 +167,20 @@ static cycle_t rk29_timer_read(struct clocksource *cs) return ~RK_TIMER_READVALUE(TIMER_CLKSRC); } +/* + * Constants generated by clocksource_hz2mult(24000000, 26). + * This gives a resolution of about 41ns and a wrap period of about 178s. + */ +#define MULT 2796202667u +#define SHIFT 26 +#define MASK (u32)~0 + static struct clocksource rk29_timer_clocksource = { .name = TIMER_CLKSRC_NAME, .rating = 200, .read = rk29_timer_read, .mask = CLOCKSOURCE_MASK(32), - .shift = 26, + .shift = SHIFT, .flags = CLOCK_SOURCE_IS_CONTINUOUS, }; @@ -189,15 +198,36 @@ static void __init rk29_timer_init_clocksource(void) RK_TIMER_SETCOUNT(TIMER_CLKSRC, 0xFFFFFFFF); RK_TIMER_ENABLE_FREE_RUNNING(TIMER_CLKSRC); - cs->mult = clocksource_hz2mult(24000000, cs->shift); + cs->mult = MULT; if (clocksource_register(cs)) printk(err, cs->name); } +static DEFINE_CLOCK_DATA(cd); + +unsigned long long notrace sched_clock(void) +{ + u32 cyc = ~RK_TIMER_READVALUE(TIMER_CLKSRC); + return cyc_to_fixed_sched_clock(&cd, cyc, MASK, MULT, SHIFT); +} + +static void notrace rk29_update_sched_clock(void) +{ + u32 cyc = ~RK_TIMER_READVALUE(TIMER_CLKSRC); + update_sched_clock(&cd, cyc, MASK); +} + +static void __init rk29_sched_clock_init(void) +{ + init_fixed_sched_clock(&cd, rk29_update_sched_clock, + 32, 24000000, MULT, SHIFT); +} + static void __init rk29_timer_init(void) { rk29_timer_init_clocksource(); rk29_timer_init_clockevent(); + rk29_sched_clock_init(); } struct sys_timer rk29_timer = { -- 2.34.1