linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: tony@atomide.com (Tony Lindgren)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] omap1: Fix sched_clock implementation when both MPU timer and 32K timer are used (Re: State of LDP3430 platform)
Date: Wed, 19 Jan 2011 10:43:21 -0800	[thread overview]
Message-ID: <20110119184321.GY4957@atomide.com> (raw)
In-Reply-To: <20110118232102.GU4957@atomide.com>

* Tony Lindgren <tony@atomide.com> [110118 15:20]:
> * Tony Lindgren <tony@atomide.com> [110118 14:34]:
> > For omap15xx and 730 we need to use the MPU timer
> > as the 32K timer is not available. For omap16xx
> > we want to use the 32K timer because of PM. Fix this
> > by allowing to build in both timers.
> 
> This still needs one more patch to deal with the
> sched_clock for MPU timer..

And here's that patch to make sched_clock work with both
timers.

Tony

From: Tony Lindgren <tony@atomide.com>
Date: Tue, 18 Jan 2011 17:00:00 -0800
Subject: [PATCH] omap1: Fix sched_clock implementation when both MPU timer and 32K timer are used

Earlier patches select HAVE_SCHED_CLOCK for omaps. To have working sched_clock
also for MPU timer, we need to implement it in a way where the right one gets
selected during the runtime.

Signed-off-by: Tony Lindgren <tony@atomide.com>

--- a/arch/arm/mach-omap1/time.c
+++ b/arch/arm/mach-omap1/time.c
@@ -219,6 +219,24 @@ static struct clocksource clocksource_mpu = {
 
 static DEFINE_CLOCK_DATA(cd);
 
+static inline unsigned long long notrace _omap_mpu_sched_clock(void)
+{
+	u32 cyc = mpu_read(&clocksource_mpu);
+	return cyc_to_sched_clock(&cd, cyc, (u32)~0);
+}
+
+#ifndef CONFIG_OMAP_32K_TIMER
+unsigned long long notrace sched_clock(void)
+{
+	return _omap_mpu_sched_clock();
+}
+#else
+static unsigned long long notrace omap_mpu_sched_clock(void)
+{
+	return _omap_mpu_sched_clock();
+}
+#endif
+
 static void notrace mpu_update_sched_clock(void)
 {
 	u32 cyc = mpu_read(&clocksource_mpu);
@@ -262,6 +280,30 @@ static inline void omap_mpu_timer_init(void)
 }
 #endif	/* CONFIG_OMAP_MPU_TIMER */
 
+#if defined(CONFIG_OMAP_MPU_TIMER) && defined(CONFIG_OMAP_32K_TIMER)
+static unsigned long long (*preferred_sched_clock)(void);
+
+unsigned long long notrace sched_clock(void)
+{
+	if (!preferred_sched_clock)
+		return 0;
+
+	return preferred_sched_clock();
+}
+
+static inline void preferred_sched_clock_init(bool use_32k_sched_clock)
+{
+	if (use_32k_sched_clock)
+		preferred_sched_clock = omap_32k_sched_clock;
+	else
+		preferred_sched_clock = omap_mpu_sched_clock;
+}
+#else
+static inline void preferred_sched_clock_init(bool use_32k_sched_clcok)
+{
+}
+#endif
+
 static inline int omap_32k_timer_usable(void)
 {
 	int res = false;
@@ -283,8 +325,12 @@ static inline int omap_32k_timer_usable(void)
  */
 static void __init omap_timer_init(void)
 {
-	if (!omap_32k_timer_usable())
+	if (omap_32k_timer_usable()) {
+		preferred_sched_clock_init(1);
+	} else {
 		omap_mpu_timer_init();
+		preferred_sched_clock_init(0);
+	}
 }
 
 struct sys_timer omap_timer = {
--- a/arch/arm/plat-omap/counter_32k.c
+++ b/arch/arm/plat-omap/counter_32k.c
@@ -120,12 +120,24 @@ static DEFINE_CLOCK_DATA(cd);
 #define SC_MULT		4000000000u
 #define SC_SHIFT	17
 
-unsigned long long notrace sched_clock(void)
+static inline unsigned long long notrace _omap_32k_sched_clock(void)
 {
 	u32 cyc = clocksource_32k.read(&clocksource_32k);
 	return cyc_to_fixed_sched_clock(&cd, cyc, (u32)~0, SC_MULT, SC_SHIFT);
 }
 
+#ifndef CONFIG_OMAP_MPU_TIMER
+unsigned long long notrace sched_clock(void)
+{
+	return _omap_32k_sched_clock();
+}
+#else
+unsigned long long notrace omap_32k_sched_clock(void)
+{
+	return _omap_32k_sched_clock();
+}
+#endif
+
 static void notrace omap_update_sched_clock(void)
 {
 	u32 cyc = clocksource_32k.read(&clocksource_32k);
--- a/arch/arm/plat-omap/include/plat/common.h
+++ b/arch/arm/plat-omap/include/plat/common.h
@@ -37,6 +37,7 @@ extern void omap_map_common_io(void);
 extern struct sys_timer omap_timer;
 extern bool omap_32k_timer_init(void);
 extern int __init omap_init_clocksource_32k(void);
+extern unsigned long long notrace omap_32k_sched_clock(void);
 
 extern void omap_reserve(void);
 

  reply	other threads:[~2011-01-19 18:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20101206125526.GC31777@n2100.arm.linux.org.uk>
     [not found] ` <20101206181913.GH8345@atomide.com>
     [not found]   ` <alpine.DEB.2.00.1012061125400.13430@utopia.booyaka.com>
     [not found]     ` <20101207083720.GB18336@n2100.arm.linux.org.uk>
     [not found]       ` <alpine.DEB.2.00.1012071745120.13430@utopia.booyaka.com>
     [not found]         ` <alpine.DEB.2.00.1012072012000.13430@utopia.booyaka.com>
     [not found]           ` <20110115000301.GT4957@atomide.com>
     [not found]             ` <alpine.DEB.2.00.1101151237240.32245@utopia.booyaka.com>
     [not found]               ` <20110115233744.GA18159@n2100.arm.linux.org.uk>
2011-01-16  4:32                 ` State of LDP3430 platform Paul Walmsley
2011-01-16 15:08                   ` Thomas Weber
2011-01-18 19:36                     ` Paul Walmsley
2011-01-18 22:26                       ` [PATCH] omap1: Fix sched_clock for the MPU timer (Re: State of LDP3430 platform) Tony Lindgren
2011-01-18 22:35                         ` [PATCH] omap1: Fix booting for 15xx and 730 with omap1_defconfig " Tony Lindgren
2011-01-18 23:21                           ` Tony Lindgren
2011-01-19 18:43                             ` Tony Lindgren [this message]
2011-01-19 18:44                         ` [PATCH] omap1: Fix sched_clock for the MPU timer " Tony Lindgren
2011-01-19 13:43                       ` State of LDP3430 platform Jarkko Nikula
2011-01-18  1:25                   ` Tony Lindgren
2011-01-18 19:24                     ` Paul Walmsley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110119184321.GY4957@atomide.com \
    --to=tony@atomide.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).