From patchwork Sun Jul 31 15:03:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Remy Bohmer X-Patchwork-Id: 1023842 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p6VF3rhu014856 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 31 Jul 2011 15:04:14 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QnXYF-0001PJ-6I; Sun, 31 Jul 2011 15:03:35 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QnXYE-0003qk-Mz; Sun, 31 Jul 2011 15:03:34 +0000 Received: from mail-ey0-f170.google.com ([209.85.215.170]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QnXY9-0003qR-9u for linux-arm-kernel@lists.infradead.org; Sun, 31 Jul 2011 15:03:32 +0000 Received: by eyd10 with SMTP id 10so5939442eyd.29 for ; Sun, 31 Jul 2011 08:03:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=rymprhqGzPkIGPe/FbkdSzuYYB4MeqE1//VeBKGrexw=; b=GarMnoLVkvqxR3+n37hq0CAk6kWnI9Um2UELvo3YtQOrOIJZMISrltMDWu14lpk3PU /9K4u7tPdLAOEO9vtGiQ24YDmg75XgwbSgR8bRjYAD4xlMpC6cfDG1pVNn3b4TvLx/uy Ap7VOJzcqO0KVhBeq+49/6t+Llywzxo83WBZg= Received: by 10.213.101.17 with SMTP id a17mr1334212ebo.91.1312124605589; Sun, 31 Jul 2011 08:03:25 -0700 (PDT) Received: from localhost (541F68BB.cm-5-8b.dynamic.ziggo.nl [84.31.104.187]) by mx.google.com with ESMTPS id r5sm715639eef.36.2011.07.31.08.03.22 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 31 Jul 2011 08:03:22 -0700 (PDT) From: Remy Bohmer To: Arnd Bergmann Subject: [PATCH] Add sched_clock to AT91 TCB clocksource driver Date: Sun, 31 Jul 2011 17:03:13 +0200 Message-Id: <1312124593-6088-1-git-send-email-linux@bohmer.net> X-Mailer: git-send-email 1.7.4.1 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110731_110329_722910_8526CC71 X-CRM114-Status: GOOD ( 16.66 ) X-Spam-Score: -0.8 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (l.pinguin[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.215.170 listed in list.dnswl.org] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: Nicolas Pitre , Peter Zijlstra , Nicolas Ferre , linux-kernel@vger.kernel.org, Remy Bohmer , tglx@linutronix.de, Jean-Christophe PLAGNIOL-VILLARD , Andrew Victor , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sun, 31 Jul 2011 15:04:14 +0000 (UTC) On AT91 there is no architecture specific sched_clock() implementation, so the default fallback is used. This fallback uses the jiffie counter as sched_clock(). There is NO standard clocksource available that is accurate enough, except the TC-based clocksource implementation. Therefor this implementation is used as base for the sched_clock(). This clocksource offers sub-millisecond time-stamping. (< 200 ns) Signed-off-by: Remy Bohmer --- arch/arm/Kconfig | 1 + arch/arm/kernel/sched_clock.c | 7 +++++++ drivers/clocksource/tcb_clksrc.c | 23 +++++++++++++++++++++++ 3 files changed, 31 insertions(+), 0 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 9adc278..e0563a7 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -296,6 +296,7 @@ config ARCH_AT91 select HAVE_CLK select CLKDEV_LOOKUP select ARM_PATCH_PHYS_VIRT if MMU + select HAVE_SCHED_CLOCK if ATMEL_TCB_CLKSRC help This enables support for systems based on the Atmel AT91RM9200, AT91SAM9 and AT91CAP9 processors. diff --git a/arch/arm/kernel/sched_clock.c b/arch/arm/kernel/sched_clock.c index 9a46370..f9028e4 100644 --- a/arch/arm/kernel/sched_clock.c +++ b/arch/arm/kernel/sched_clock.c @@ -20,6 +20,13 @@ static void (*sched_clock_update_fn)(void); static void sched_clock_poll(unsigned long wrap_ticks) { + /* + * The sched_clock_update_fn may be initialised AFTER first call to + * time_init() + */ + if (unlikely(!sched_clock_update_fn)) + return; + mod_timer(&sched_clock_timer, round_jiffies(jiffies + wrap_ticks)); sched_clock_update_fn(); } diff --git a/drivers/clocksource/tcb_clksrc.c b/drivers/clocksource/tcb_clksrc.c index 79c47e8..d6069b3 100644 --- a/drivers/clocksource/tcb_clksrc.c +++ b/drivers/clocksource/tcb_clksrc.c @@ -11,6 +11,7 @@ #include #include +#include /* * We're configured to use a specific TC block, one that's not hooked @@ -210,6 +211,23 @@ static void __init setup_clkevents(struct atmel_tc *tc, int clk32k_divisor_idx) #endif +static DEFINE_CLOCK_DATA(cd); + +unsigned long long notrace sched_clock(void) +{ + if (likely(tcaddr)) { + cycle_t cyc = tc_get_cycles(&clksrc); + return cyc_to_sched_clock(&cd, cyc, (u32)~0); + } + return 0; +} + +static void notrace tcb_update_sched_clock(void) +{ + cycle_t cyc = tc_get_cycles(&clksrc); + update_sched_clock(&cd, cyc, (u32)~0); +} + static int __init tcb_clksrc_init(void) { static char bootinfo[] __initdata @@ -297,6 +315,11 @@ static int __init tcb_clksrc_init(void) /* channel 2: periodic and oneshot timer support */ setup_clkevents(tc, clk32k_divisor_idx); + /* Now prepare the sched_clock support */ + init_sched_clock(&cd, tcb_update_sched_clock, 32, divided_rate); + sched_clock_postinit(); + return 0; } arch_initcall(tcb_clksrc_init); +