All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Daney <ddaney@caviumnetworks.com>
To: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Subject: Re: [PATCH] MIPS: Octeon: Use non-overflowing arithmetic in sched_clock
Date: Mon, 11 Jan 2010 09:28:23 -0800	[thread overview]
Message-ID: <4B4B5FB7.3050701@caviumnetworks.com> (raw)
In-Reply-To: <20100111102023.GE13886@linux-mips.org>

Ralf Baechle wrote:
> On Fri, Jan 08, 2010 at 02:47:36PM -0800, David Daney wrote:
> 
>> With typical mult and shift values, the calculation for Octeon's
>> sched_clock overflows when using 64-bit arithmetic.  Use 128-bit
>> calculations instead.
> 
> Applied though my first thought whenever I see extended precission math
> is gross - maybe we're going to find a better solution.  Hopefully!
> 
>   Ralf

I did have some apprehension myself.  However consider:

* For an 800MHz core clock, clocksource_set_clock() generates a shift 
value of 31.  This leads to overflow of 64-bit arithmetic approximately 
every 8 seconds.  This specific case could be reduced to a 2 bit shift, 
resulting in time to overflow of more than 100 years.  But one can 
imagine clock rates that would require large shifts.

* We need to return a 64-bit clock value, this will overflow in about 
500 years, Unless we are very careful with our arithmetic, we risk 
overflow in unacceptable short time periods.

* This is octeon specific and the 128-bit operation is cheap.  Probably 
cheaper than accounting for overflows in 64-bit arithmetic.

David Daney

      reply	other threads:[~2010-01-11 17:30 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-08 22:47 [PATCH] MIPS: Octeon: Use non-overflowing arithmetic in sched_clock David Daney
2010-01-11 10:20 ` Ralf Baechle
2010-01-11 17:28   ` David Daney [this message]

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=4B4B5FB7.3050701@caviumnetworks.com \
    --to=ddaney@caviumnetworks.com \
    --cc=linux-mips@linux-mips.org \
    --cc=ralf@linux-mips.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.