mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Petr Tesarik <ptesarik@suse.cz>
To: Andi Kleen <andi@firstfloor.org>,
	John Stultz <johnstul@us.ibm.com>,
	george@mvista.com
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Carefully chosen CYC2NS_SCALE_FACTOR ??
Date: Wed, 15 Jul 2009 16:03:23 +0200	[thread overview]
Message-ID: <1247666603.11358.62.camel@nathan.suse.cz> (raw)

Hi,

I'm having trouble understanding the rationale behind the choice for
CYC2NS_SCALE_FACTOR in arch/x86/include/asm/timer.h:

#define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */

Why on Earth is this 10?

AFAICS this constant is the position of the decimal point in the
fixed-point cycle-to-nanoseconds computations. It is computed as
follows:

                *scale = (NSEC_PER_MSEC << CYC2NS_SCALE_FACTOR)/cpu_khz;

Now, NSEC_PER_MSEC is 10^6, the size of cyc2ns is 32 bits and cpu_khz,
being an integer, cannot be less than 1. So, if I want maximum accuracy,
I should choose the maximium CYC2NS_SCALE_FACTOR such that:

10^6 * 2^CYC2NS_SCALE_FACTOR < 2^32

Which transforms to:

CYC2NS_SCALE_FACTOR = floor(log2(2^32/NSEC_PER_MSEC)) = 12

Did I miss an obvious reason for not using the scale factor of 12?

TIA,
Petr Tesarik
SUSE Linux



             reply	other threads:[~2009-07-15 14:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-15 14:03 Petr Tesarik [this message]
2009-07-15 22:54 ` john stultz

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=1247666603.11358.62.camel@nathan.suse.cz \
    --to=ptesarik@suse.cz \
    --cc=andi@firstfloor.org \
    --cc=george@mvista.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®