linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: js@sig21.net (Johannes Stezenbach)
To: linux-arm-kernel@lists.infradead.org
Subject: Q: sched_clock() vs. clocksource, how to implement correctly
Date: Mon, 26 Apr 2010 15:18:43 +0200	[thread overview]
Message-ID: <20100426131843.GA28332@sig21.net> (raw)
In-Reply-To: <20100424205011.GA21632@sig21.net>

On Sat, Apr 24, 2010 at 10:50:11PM +0200, Johannes Stezenbach wrote:
> /*
>  * Orion's sched_clock implementation. It has a resolution of
>  * at least 7.5ns (133MHz TCLK) and a maximum value of 834 days.
>  *
>  * Because the hardware timer period is quite short (21 secs if
>  * 200MHz TCLK) and because cnt32_to_63() needs to be called at
>  * least once per half period to work properly, a kernel timer is
>  * set up to ensure this requirement is always met.
>  */
> #define TCLK2NS_SCALE_FACTOR 8

I found the following discussion of the sched_clock()
implementation trade-offs very informative:
http://lkml.org/lkml/2010/4/15/299

It mentions clocksource_calc_mult_shift() which was added in 2.6.33,
however I had some difficulties understanding the meaning of the minsec
parameter, especially since all existing callers use a value of 4.
But when using minsec = 365*24*60*60 (1 year) it results in the shift value of 8.

So finally the pieces connect together :-)

> BTW, even though this uses TCLK2NS_SCALE_FACTOR of 8, the same file
> uses a shift vaue of 20 for the orion_clksrc...

It seems clocksource_cyc2ns() is used in kernel/time/timekeeping.c
and kernel/time/clocksource.c only on relatively
small delta values, so there's no need to worry
about overflow and a large clocksource.shift and .mult is OK.

(Apparently the minsec value of 4 mentioned above is suitable
for timekeeping?  Where does the 4 come from?)


Thanks,
Johannes

  parent reply	other threads:[~2010-04-26 13:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-23 15:09 Q: sched_clock() vs. clocksource, how to implement correctly Johannes Stezenbach
2010-04-23 16:29 ` Martin Schwidefsky
2010-04-24 20:50   ` Johannes Stezenbach
2010-04-25 14:36     ` Peter Zijlstra
2010-04-26 13:18     ` Johannes Stezenbach [this message]
2010-04-26 23:48   ` Daniel Walker

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=20100426131843.GA28332@sig21.net \
    --to=js@sig21.net \
    --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).