linux-mips
[Top] [All Lists]

Re: [PATCH] MIPS: Add a high precision sched_clock() via cnt32_to_63().

To: Ralf Baechle <ralf@linux-mips.org>
Subject: Re: [PATCH] MIPS: Add a high precision sched_clock() via cnt32_to_63().
From: Wu Zhangjin <wuzhangjin@gmail.com>
Date: Fri, 20 Nov 2009 21:20:37 +0800
Cc: Thomas Gleixner <tglx@linutronix.de>, rostedt@goodmis.org, Frederic Weisbecker <fweisbec@gmail.com>, Nicholas Mc Guire <der.herr@hofr.at>, David Daney <ddaney@caviumnetworks.com>, linux-mips@linux-mips.org, Michal Simek <monstr@monstr.eu>, Ingo Molnar <mingo@elte.hu>, linux-kernel@vger.kernel.org
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:reply-to:to:cc :in-reply-to:references:content-type:organization:date:message-id :mime-version:x-mailer:content-transfer-encoding; bh=4acnx5EOnmHgnKykGyKuP7cJsJTPTO9rCm13SYoWs4U=; b=Gsrl7ArIthpbWMWrrrAUMdDEbZ5LE5PhkHya+yHAcUc60U2Q+fyMql49h+S+PztxNJ IjoLpmG8B35xLNR8u+eTrrA3SfKH5l9NEIfPKroicX9Xm3TEdW6+hQiAJVqKxLWtmFd5 xtoLvaoQNiP8dlq56ykgtg2ZdtcVHJ4Yri40I=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:reply-to:to:cc:in-reply-to:references:content-type :organization:date:message-id:mime-version:x-mailer :content-transfer-encoding; b=FEXt1WCeQJvUQi7J2sA4uEyzOHvxtexeFvqvi+DgHdA+d30hB2kH3CVF654wuR0qqW fHCwQ8gx68yUVe+mVUi1Vrqzn57IzQ2Hom0yLr1XU78luim/u2v0cAzzoyPfME3kabKG vu8QgfuHl5vBGbCMtPhq5sXdnoUgl/Ui7fuLE=
In-reply-to: <1258703602-29065-1-git-send-email-wuzhangjin@gmail.com>
Organization: DSLab, Lanzhou University, China
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <1258703602-29065-1-git-send-email-wuzhangjin@gmail.com>
Reply-to: wuzhangjin@gmail.com
Sender: linux-mips-bounce@linux-mips.org
[...]
> ---
>  arch/mips/kernel/csrc-r4k.c |   37 +++++++++++++++++++++++++++++++++++++
>  1 files changed, 37 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/mips/kernel/csrc-r4k.c b/arch/mips/kernel/csrc-r4k.c
> index e95a3cd..865035d 100644
> --- a/arch/mips/kernel/csrc-r4k.c
> +++ b/arch/mips/kernel/csrc-r4k.c
> @@ -6,10 +6,45 @@
>   * Copyright (C) 2007 by Ralf Baechle
>   */
>  #include <linux/clocksource.h>
> +#include <linux/cnt32_to_63.h>
> +#include <linux/timer.h>

Sorry, <linux/timer.h> is not needed here, I have used it in the old
version with setup_timer()/mod_timer().

>  #include <linux/init.h>
>  
>  #include <asm/time.h>
>  
> +/*
> + * MIPS' sched_clock implementation.
> + *
> + * NOTE: because cnt32_to_63() needs to be called at least once per half 
> period
> + * to work properly, and some of the MIPS' frequency is very low, perhaps a
> + * kernel timer is needed to be set up to ensure this requirement is always
> + * met. please refer to  arch/arm/plat-orion/time.c and
> + * include/linux/cnt32_to_63.h
> + */
> +static unsigned long tclk2ns_scale, tclk2ns_scale_factor;
> +
> +unsigned long long notrace sched_clock(void)
> +{
> +     unsigned long long v = cnt32_to_63(read_c0_count());
> +     return (v * tclk2ns_scale) >> tclk2ns_scale_factor;
> +}
> +
> +static void __init setup_sched_clock(struct clocksource *cs, unsigned long 
> tclk)

the tclk is not used, I have also used it in the old version with
setup_timer()/mod_timer(). so, we can remove it for this version.

> +{
> +     unsigned long long v;
> +
> +     v = cs->mult;
> +     /*
> +      * We want an even value to automatically clear the top bit
> +      * returned by cnt32_to_63() without an additional run time
> +      * instruction. So if the LSB is 1 then round it up.
> +      */
> +     if (v & 1)
> +             v++;
> +     tclk2ns_scale = v;
> +     tclk2ns_scale_factor = cs->shift;
> +}
> +
>  static cycle_t c0_hpt_read(struct clocksource *cs)
>  {
>       return read_c0_count();
> @@ -32,6 +67,8 @@ int __init init_r4k_clocksource(void)
>  
>       clocksource_set_clock(&clocksource_mips, mips_hpt_frequency);
>  
> +     setup_sched_clock(&clocksource_mips, mips_hpt_frequency);
> +

And here should be setup_sched_clock(&clocksource_mips);

Regards,
        Wu Zhangjin


<Prev in Thread] Current Thread [Next in Thread>