linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: tomasz.figa@gmail.com (Tomasz Figa)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 5/5] ARM: s3c64xx: Add optional local sched_clock implementation.
Date: Sun, 28 Aug 2011 02:49:58 +0200	[thread overview]
Message-ID: <mailman.114.1314794177.20020.linux-arm-kernel@lists.infradead.org> (raw)

This patch adds local sched_clock implementation using the PWM timer used
for generic clock source and a Kconfig option to enable/disable it.

Signed-off-by: Tomasz Figa <tomasz.figa@gmail.com>
---
 arch/arm/mach-s3c64xx/Kconfig |    8 ++++++++
 arch/arm/mach-s3c64xx/time.c  |   28 +++++++++++++++++++++++++++-
 2 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-s3c64xx/Kconfig b/arch/arm/mach-s3c64xx/Kconfig
index 2db76fd..e11dd9b 100644
--- a/arch/arm/mach-s3c64xx/Kconfig
+++ b/arch/arm/mach-s3c64xx/Kconfig
@@ -33,6 +33,14 @@ config S3C64XX_GENERIC_CLOCKEVENTS
 	  on S3C6400/S3C6410 SoCs using PWM timers 3 and 4 instead
 	  of standard periodic tick using PWM timer 4.
 
+config S3C64XX_SCHED_CLOCK
+	bool "Use PWM clock source for scheduler clock"
+	depends on S3C64XX_GENERIC_CLOCKEVENTS
+	select HAVE_SCHED_CLOCK
+	help
+	  This option enables local scheduler clock implementation
+	  using PWM clock source.
+
 config S3C64XX_ARCH_USES_GETTIMEOFFSET
 	def_bool y if !S3C64XX_GENERIC_CLOCKEVENTS
 	select ARCH_USES_GETTIMEOFFSET
diff --git a/arch/arm/mach-s3c64xx/time.c b/arch/arm/mach-s3c64xx/time.c
index 4fa57f0..4a78844 100644
--- a/arch/arm/mach-s3c64xx/time.c
+++ b/arch/arm/mach-s3c64xx/time.c
@@ -28,6 +28,7 @@
 #include <linux/clockchips.h>
 #include <linux/platform_device.h>
 
+#include <asm/sched_clock.h>
 #include <mach/map.h>
 #include <plat/regs-timer.h>
 #include <asm/mach/time.h>
@@ -241,6 +242,29 @@ static void s3c64xx_clocksource_resume(struct clocksource *cs)
 	s3c64xx_pwm_start(PWM_SOURCE, PERIODIC);
 }
 
+#ifdef CONFIG_S3C64XX_SCHED_CLOCK
+/*
+ * Override the global weak sched_clock symbol with this
+ * local implementation which uses the clocksource to get some
+ * better resolution when scheduling the kernel. We accept that
+ * this wraps around for now, since it is just a relative time
+ * stamp. (Inspired by U300 implementation.)
+ */
+static DEFINE_CLOCK_DATA(cd);
+
+unsigned long long notrace sched_clock(void)
+{
+	return cyc_to_sched_clock(&cd,
+			~__raw_readl(S3C2410_TCNTO(PWM_SOURCE)), TCNT_MAX);
+}
+
+static void notrace s3c64xx_update_sched_clock(void)
+{
+	update_sched_clock(&cd,
+			~__raw_readl(S3C2410_TCNTO(PWM_SOURCE)), (u32)~0);
+}
+#endif /* CONFIG_S3C64XX_SCHED_CLOCK */
+
 static struct clocksource pwm_clocksource = {
 	.name		= "s3c64xx_clksrc",
 	.rating		= 250,
@@ -258,7 +282,9 @@ static void __init s3c64xx_clocksource_init(void)
 
 	s3c64xx_pwm_init(PWM_SOURCE, TCNT_MAX);
 	s3c64xx_pwm_start(PWM_SOURCE, PERIODIC);
-
+#ifdef CONFIG_S3C64XX_SCHED_CLOCK
+	init_sched_clock(&cd, s3c64xx_update_sched_clock, 32, clock_rate);
+#endif /* CONFIG_S3C64XX_SCHED_CLOCK */
 	if (clocksource_register_hz(&pwm_clocksource, clock_rate))
 		panic("%s: can't register clocksource\n", pwm_clocksource.name);
 }
-- 
1.7.6.1

             reply	other threads:[~2011-08-28  0:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-28  0:49 Tomasz Figa [this message]
  -- strict thread matches above, loose matches on Subject: below --
2011-08-31 12:33 [PATCH 0/5] Add high resolution generic time support for S3C64xx Tomasz Figa
2011-08-31 12:36 ` [PATCH 5/5] ARM: s3c64xx: Add optional local sched_clock implementation Tomasz Figa

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=mailman.114.1314794177.20020.linux-arm-kernel@lists.infradead.org \
    --to=tomasz.figa@gmail.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).