From: Daniel Walker <dwalker@mvista.com>
To: akpm@linux-foundation.org
Cc: johnstul@us.ibm.com, ralf@linux-mips.org, linux-kernel@vger.kernel.org
Subject: [PATCH] clocksource: shift helper
Date: Thu, 01 May 2008 10:31:23 -0700 [thread overview]
Message-ID: <20080501173123.444094226@mvista.com> (raw)
This is a little helper I pulled from the mips tree. I've seen a couple
of bogus shift values, and this helper calculates the shift. This
should move the shift selection away from the user, and systematically
pick the value base on the hz.
I also modified the acpi_pm timer to use this new interface. The original
shift was 22 , and after this patch it's increased to 23. Which should make
the clocksource slightly more accurate, but shouldn't have much of a visible
effect.
Signed-off-by: Daniel Walker <dwalker@mvista.com>
---
drivers/clocksource/acpi_pm.c | 5 ++++-
include/linux/acpi_pmtmr.h | 5 +++--
include/linux/clocksource.h | 21 +++++++++++++++++++++
3 files changed, 28 insertions(+), 3 deletions(-)
Index: linux-2.6.25/drivers/clocksource/acpi_pm.c
===================================================================
--- linux-2.6.25.orig/drivers/clocksource/acpi_pm.c
+++ linux-2.6.25/drivers/clocksource/acpi_pm.c
@@ -72,7 +72,7 @@ static struct clocksource clocksource_ac
.read = acpi_pm_read,
.mask = (cycle_t)ACPI_PM_MASK,
.mult = 0, /*to be calculated*/
- .shift = 22,
+ .shift = 0,
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
};
@@ -183,6 +183,9 @@ static int __init init_acpi_pm_clocksour
if (!pmtmr_ioport)
return -ENODEV;
+ clocksource_acpi_pm.shift =
+ clocksource_hz2shift(ACPI_PM_BITS, PMTMR_TICKS_PER_SEC);
+
clocksource_acpi_pm.mult = clocksource_hz2mult(PMTMR_TICKS_PER_SEC,
clocksource_acpi_pm.shift);
Index: linux-2.6.25/include/linux/acpi_pmtmr.h
===================================================================
--- linux-2.6.25.orig/include/linux/acpi_pmtmr.h
+++ linux-2.6.25/include/linux/acpi_pmtmr.h
@@ -7,10 +7,11 @@
#define PMTMR_TICKS_PER_SEC 3579545
/* limit it to 24 bits */
-#define ACPI_PM_MASK CLOCKSOURCE_MASK(24)
+#define ACPI_PM_BITS 24
+#define ACPI_PM_MASK CLOCKSOURCE_MASK(ACPI_PM_BITS)
/* Overrun value */
-#define ACPI_PM_OVRRUN (1<<24)
+#define ACPI_PM_OVRRUN (1 << ACPI_PM_BITS)
#ifdef CONFIG_X86_PM_TIMER
Index: linux-2.6.25/include/linux/clocksource.h
===================================================================
--- linux-2.6.25.orig/include/linux/clocksource.h
+++ linux-2.6.25/include/linux/clocksource.h
@@ -157,6 +157,27 @@ static inline u32 clocksource_hz2mult(u3
}
/**
+ * clocksource_hz2shift - calculates shift from hz and # of bits
+ * @bits: Number of bits this clocksource uses
+ * @hz: Clocksource frequency in Hz
+ *
+ * Helper functions that calculates the best shift value
+ * based on the hz and # of bits of any given clock.
+ */
+static inline u32 clocksource_hz2shift(u32 bits, u32 hz)
+{
+ u64 temp;
+
+ for (; bits > 0; bits--) {
+ temp = (u64) NSEC_PER_SEC << bits;
+ do_div(temp, hz);
+ if ((temp >> 32) == 0)
+ break;
+ }
+ return bits;
+}
+
+/**
* clocksource_read: - Access the clocksource's current cycle value
* @cs: pointer to clocksource being read
*
--
--
next reply other threads:[~2008-05-01 17:35 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-01 17:31 Daniel Walker [this message]
2008-05-01 19:32 ` [PATCH] clocksource: shift helper Andrew Morton
2008-05-01 19:48 ` Daniel Walker
2008-05-01 21:05 ` Ralf Baechle
2008-05-06 0:52 ` Thomas Gleixner
2008-05-06 16:39 ` Daniel Walker
2008-05-06 20:25 ` Thomas Gleixner
2008-05-06 20:33 ` Daniel Walker
2008-05-06 20:53 ` Thomas Gleixner
2008-05-06 21:01 ` Daniel Walker
2008-05-06 21:18 ` Andrew Morton
2008-05-06 21:21 ` Thomas Gleixner
2008-05-06 21:19 ` Thomas Gleixner
2008-05-06 21:30 ` Daniel Walker
2008-05-07 16:23 ` Atsushi Nemoto
2008-05-07 3:57 ` Roman Zippel
2008-05-08 16: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=20080501173123.444094226@mvista.com \
--to=dwalker@mvista.com \
--cc=akpm@linux-foundation.org \
--cc=johnstul@us.ibm.com \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox