linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: jamie@jamieiles.com (Jamie Iles)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH] ARM: TWD: fix the clock calculation for TWD
Date: Thu, 20 Jan 2011 18:10:50 +0000	[thread overview]
Message-ID: <20110120181050.GF25954@pulham.picochip.com> (raw)
In-Reply-To: <20110120163836.GF6335@n2100.arm.linux.org.uk>

On Thu, Jan 20, 2011 at 04:38:36PM +0000, Russell King - ARM Linux wrote:
> On Thu, Jan 20, 2011 at 02:44:09PM +0000, Jamie Iles wrote:
> > On Thu, Jan 20, 2011 at 02:08:11PM +0000, Russell King - ARM Linux wrote:
> > > On Thu, Jan 20, 2011 at 02:33:57PM +0800, Chao Xie wrote:
> > > > The original code will do count * (HZ /5). It will make the twd
> > > > timer rate decreased if HZ can not be excatly divided. For
> > > > example HZ=128.
> > > > 
> > > > Signed-off-by: Chao Xie <chao.xie@marvell.com>
> > > > ---
> > > >  arch/arm/kernel/smp_twd.c |    3 ++-
> > > >  1 files changed, 2 insertions(+), 1 deletions(-)
> > > > 
> > > > diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
> > > > index 35882fb..ca6405b 100644
> > > > --- a/arch/arm/kernel/smp_twd.c
> > > > +++ b/arch/arm/kernel/smp_twd.c
> > > > @@ -111,7 +111,8 @@ static void __cpuinit twd_calibrate_rate(void)
> > > >  
> > > >  		count = __raw_readl(twd_base + TWD_TIMER_COUNTER);
> > > >  
> > > > -		twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
> > > > +		twd_timer_rate = ((unsigned long)(0xFFFFFFFFU - count))
> > > > +			* HZ / 5;
> > > >  
> > > >  		printk("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
> > > >  			(twd_timer_rate / 100000) % 100);
> > > 
> > > I don't think this patch has any effect what so ever, so I just tried:
> > > 
> > > #define HZ      128
> > > unsigned long twd_timer_rate;
> > > void calc1(unsigned long count)
> > > {
> > >         twd_timer_rate = (0xffffffffU - count) * (HZ / 5);
> > > }
> > > void calc2(unsigned long count)
> > > {
> > >         twd_timer_rate = ((unsigned long)(0xffffffffU - count)) * (HZ / 5);
> > > }
> > 
> > Hi Russell,
> > 
> > In Chao's patch the parentheses around (HZ / 5) have been removed so its 
> > now dowing the multiplication before the division (if I remember the 
> > precedences correctly!).  I don't think the cast to unsigned long is 
> > needed though.
> 
> Hmm.  That means the maximum twd timer rate we can support is about
> 860MHz.  Is that enough?

I'm not familiar with any ARM SMP systems so I wouldn't like to commit 
to that!  If the answer is no, then I guess could we do something like 
the (untested in a kernel) patch below to get a few more bits and we 
should then be able to support rates of up to ~4294MHz.

Jamie

8<----

diff --git a/arch/arm/kernel/smp_twd.c b/arch/arm/kernel/smp_twd.c
index fd91566..334ad95 100644
--- a/arch/arm/kernel/smp_twd.c
+++ b/arch/arm/kernel/smp_twd.c
@@ -89,6 +89,8 @@ static void __cpuinit twd_calibrate_rate(void)
 	 * the timer ticks
 	 */
 	if (twd_timer_rate == 0) {
+		u64 rate64;
+
 		printk(KERN_INFO "Calibrating local timer... ");
 
 		/* Wait for a tick to start */
@@ -111,7 +113,9 @@ static void __cpuinit twd_calibrate_rate(void)
 
 		count = __raw_readl(twd_base + TWD_TIMER_COUNTER);
 
-		twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
+		rate64 = (0xFFFFFFFFLLU - count) * (u64)HZ;
+		do_div(rate64, 5);
+		twd_timer_rate = rate64;
 
 		printk("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
 			(twd_timer_rate / 1000000) % 100);

  reply	other threads:[~2011-01-20 18:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-20  6:33 [PATCH] ARM: TWD: fix the clock calculation for TWD Chao Xie
2011-01-20 14:08 ` Russell King - ARM Linux
2011-01-20 14:44   ` Jamie Iles
2011-01-20 16:38     ` Russell King - ARM Linux
2011-01-20 18:10       ` Jamie Iles [this message]
2011-01-24  1:35         ` Chao Xie

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=20110120181050.GF25954@pulham.picochip.com \
    --to=jamie@jamieiles.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).