* [PATCH 1/2] clocksource: introduce clocksource_freq2mult()
2016-02-27 3:14 [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6 John Stultz
@ 2016-02-27 3:14 ` John Stultz
2016-02-27 8:00 ` [tip:timers/core] clocksource: Introduce clocksource_freq2mult() tip-bot for Alexander Kuleshov
2016-02-27 3:14 ` [PATCH 2/2] jiffies: use CLOCKSOURCE_MASK instead of constant John Stultz
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: John Stultz @ 2016-02-27 3:14 UTC (permalink / raw)
To: lkml
Cc: Alexander Kuleshov, Thomas Gleixner, Prarit Bhargava,
Richard Cochran, Ingo Molnar, John Stultz
From: Alexander Kuleshov <kuleshovmail@gmail.com>
The clocksource_khz2mult() and clocksource_hz2mult() share similar
code wihch calculates a mult from the given frequency. Both implementations
in differ only in value of a frequency. This patch introduces the
clocksource_freq2mult() helper with generic implementation of
mult calculation to prevent code duplication.
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
include/linux/clocksource.h | 45 +++++++++++++++++++--------------------------
1 file changed, 19 insertions(+), 26 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 6013021..a307bf6 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -118,6 +118,23 @@ struct clocksource {
/* simplify initialization of mask field */
#define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
+static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
+{
+ /* freq = cyc/from
+ * mult/2^shift = ns/cyc
+ * mult = ns/cyc * 2^shift
+ * mult = from/freq * 2^shift
+ * mult = from * 2^shift / freq
+ * mult = (from<<shift) / freq
+ */
+ u64 tmp = ((u64)from) << shift_constant;
+
+ tmp += freq/2; /* round for do_div */
+ do_div(tmp, freq);
+
+ return (u32)tmp;
+}
+
/**
* clocksource_khz2mult - calculates mult from khz and shift
* @khz: Clocksource frequency in KHz
@@ -128,19 +145,7 @@ struct clocksource {
*/
static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
{
- /* khz = cyc/(Million ns)
- * mult/2^shift = ns/cyc
- * mult = ns/cyc * 2^shift
- * mult = 1Million/khz * 2^shift
- * mult = 1000000 * 2^shift / khz
- * mult = (1000000<<shift) / khz
- */
- u64 tmp = ((u64)1000000) << shift_constant;
-
- tmp += khz/2; /* round for do_div */
- do_div(tmp, khz);
-
- return (u32)tmp;
+ return clocksource_freq2mult(khz, shift_constant, NSEC_PER_MSEC);
}
/**
@@ -154,19 +159,7 @@ static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
*/
static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant)
{
- /* hz = cyc/(Billion ns)
- * mult/2^shift = ns/cyc
- * mult = ns/cyc * 2^shift
- * mult = 1Billion/hz * 2^shift
- * mult = 1000000000 * 2^shift / hz
- * mult = (1000000000<<shift) / hz
- */
- u64 tmp = ((u64)1000000000) << shift_constant;
-
- tmp += hz/2; /* round for do_div */
- do_div(tmp, hz);
-
- return (u32)tmp;
+ return clocksource_freq2mult(hz, shift_constant, NSEC_PER_SEC);
}
/**
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [tip:timers/core] clocksource: Introduce clocksource_freq2mult()
2016-02-27 3:14 ` [PATCH 1/2] clocksource: introduce clocksource_freq2mult() John Stultz
@ 2016-02-27 8:00 ` tip-bot for Alexander Kuleshov
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Alexander Kuleshov @ 2016-02-27 8:00 UTC (permalink / raw)
To: linux-tip-commits
Cc: richardcochran, kuleshovmail, tglx, john.stultz, prarit, hpa,
linux-kernel, mingo
Commit-ID: 7aca0c07207385cca76025cc85231519935722b9
Gitweb: http://git.kernel.org/tip/7aca0c07207385cca76025cc85231519935722b9
Author: Alexander Kuleshov <kuleshovmail@gmail.com>
AuthorDate: Fri, 26 Feb 2016 19:14:13 -0800
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sat, 27 Feb 2016 08:55:30 +0100
clocksource: Introduce clocksource_freq2mult()
The clocksource_khz2mult() and clocksource_hz2mult() share similar
code wihch calculates a mult from the given frequency. Both implementations
in differ only in value of a frequency. This patch introduces the
clocksource_freq2mult() helper with generic implementation of
mult calculation to prevent code duplication.
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Link: http://lkml.kernel.org/r/1456542854-22104-2-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
include/linux/clocksource.h | 45 +++++++++++++++++++--------------------------
1 file changed, 19 insertions(+), 26 deletions(-)
diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
index 6013021..a307bf6 100644
--- a/include/linux/clocksource.h
+++ b/include/linux/clocksource.h
@@ -118,6 +118,23 @@ struct clocksource {
/* simplify initialization of mask field */
#define CLOCKSOURCE_MASK(bits) (cycle_t)((bits) < 64 ? ((1ULL<<(bits))-1) : -1)
+static inline u32 clocksource_freq2mult(u32 freq, u32 shift_constant, u64 from)
+{
+ /* freq = cyc/from
+ * mult/2^shift = ns/cyc
+ * mult = ns/cyc * 2^shift
+ * mult = from/freq * 2^shift
+ * mult = from * 2^shift / freq
+ * mult = (from<<shift) / freq
+ */
+ u64 tmp = ((u64)from) << shift_constant;
+
+ tmp += freq/2; /* round for do_div */
+ do_div(tmp, freq);
+
+ return (u32)tmp;
+}
+
/**
* clocksource_khz2mult - calculates mult from khz and shift
* @khz: Clocksource frequency in KHz
@@ -128,19 +145,7 @@ struct clocksource {
*/
static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
{
- /* khz = cyc/(Million ns)
- * mult/2^shift = ns/cyc
- * mult = ns/cyc * 2^shift
- * mult = 1Million/khz * 2^shift
- * mult = 1000000 * 2^shift / khz
- * mult = (1000000<<shift) / khz
- */
- u64 tmp = ((u64)1000000) << shift_constant;
-
- tmp += khz/2; /* round for do_div */
- do_div(tmp, khz);
-
- return (u32)tmp;
+ return clocksource_freq2mult(khz, shift_constant, NSEC_PER_MSEC);
}
/**
@@ -154,19 +159,7 @@ static inline u32 clocksource_khz2mult(u32 khz, u32 shift_constant)
*/
static inline u32 clocksource_hz2mult(u32 hz, u32 shift_constant)
{
- /* hz = cyc/(Billion ns)
- * mult/2^shift = ns/cyc
- * mult = ns/cyc * 2^shift
- * mult = 1Billion/hz * 2^shift
- * mult = 1000000000 * 2^shift / hz
- * mult = (1000000000<<shift) / hz
- */
- u64 tmp = ((u64)1000000000) << shift_constant;
-
- tmp += hz/2; /* round for do_div */
- do_div(tmp, hz);
-
- return (u32)tmp;
+ return clocksource_freq2mult(hz, shift_constant, NSEC_PER_SEC);
}
/**
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] jiffies: use CLOCKSOURCE_MASK instead of constant
2016-02-27 3:14 [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6 John Stultz
2016-02-27 3:14 ` [PATCH 1/2] clocksource: introduce clocksource_freq2mult() John Stultz
@ 2016-02-27 3:14 ` John Stultz
2016-02-27 8:00 ` [tip:timers/core] jiffies: Use " tip-bot for Alexander Kuleshov
2016-02-27 7:50 ` [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6 Thomas Gleixner
2016-02-27 7:52 ` Thomas Gleixner
3 siblings, 1 reply; 7+ messages in thread
From: John Stultz @ 2016-02-27 3:14 UTC (permalink / raw)
To: lkml
Cc: Alexander Kuleshov, Thomas Gleixner, Prarit Bhargava,
Richard Cochran, Ingo Molnar, John Stultz
From: Alexander Kuleshov <kuleshovmail@gmail.com>
The CLOCKSOURCE_MASK(32) macro expands to the same value, but
makes code more readable.
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
---
kernel/time/jiffies.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index 347fecf..555e21f 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -68,7 +68,7 @@ static struct clocksource clocksource_jiffies = {
.name = "jiffies",
.rating = 1, /* lowest valid rating*/
.read = jiffies_read,
- .mask = 0xffffffff, /*32bits*/
+ .mask = CLOCKSOURCE_MASK(32),
.mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
.shift = JIFFIES_SHIFT,
.max_cycles = 10,
--
1.9.1
^ permalink raw reply related [flat|nested] 7+ messages in thread* [tip:timers/core] jiffies: Use CLOCKSOURCE_MASK instead of constant
2016-02-27 3:14 ` [PATCH 2/2] jiffies: use CLOCKSOURCE_MASK instead of constant John Stultz
@ 2016-02-27 8:00 ` tip-bot for Alexander Kuleshov
0 siblings, 0 replies; 7+ messages in thread
From: tip-bot for Alexander Kuleshov @ 2016-02-27 8:00 UTC (permalink / raw)
To: linux-tip-commits
Cc: kuleshovmail, john.stultz, mingo, hpa, prarit, tglx,
richardcochran, linux-kernel
Commit-ID: 232d26373d310a941ef2ab46e53ea62fe076ed13
Gitweb: http://git.kernel.org/tip/232d26373d310a941ef2ab46e53ea62fe076ed13
Author: Alexander Kuleshov <kuleshovmail@gmail.com>
AuthorDate: Fri, 26 Feb 2016 19:14:14 -0800
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sat, 27 Feb 2016 08:55:31 +0100
jiffies: Use CLOCKSOURCE_MASK instead of constant
The CLOCKSOURCE_MASK(32) macro expands to the same value, but
makes code more readable.
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Prarit Bhargava <prarit@redhat.com>
Cc: Richard Cochran <richardcochran@gmail.com>
Link: http://lkml.kernel.org/r/1456542854-22104-3-git-send-email-john.stultz@linaro.org
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/time/jiffies.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/jiffies.c b/kernel/time/jiffies.c
index 347fecf..555e21f 100644
--- a/kernel/time/jiffies.c
+++ b/kernel/time/jiffies.c
@@ -68,7 +68,7 @@ static struct clocksource clocksource_jiffies = {
.name = "jiffies",
.rating = 1, /* lowest valid rating*/
.read = jiffies_read,
- .mask = 0xffffffff, /*32bits*/
+ .mask = CLOCKSOURCE_MASK(32),
.mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
.shift = JIFFIES_SHIFT,
.max_cycles = 10,
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6
2016-02-27 3:14 [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6 John Stultz
2016-02-27 3:14 ` [PATCH 1/2] clocksource: introduce clocksource_freq2mult() John Stultz
2016-02-27 3:14 ` [PATCH 2/2] jiffies: use CLOCKSOURCE_MASK instead of constant John Stultz
@ 2016-02-27 7:50 ` Thomas Gleixner
2016-02-27 7:52 ` Thomas Gleixner
3 siblings, 0 replies; 7+ messages in thread
From: Thomas Gleixner @ 2016-02-27 7:50 UTC (permalink / raw)
To: John Stultz
Cc: lkml, Prarit Bhargava, Richard Cochran, Ingo Molnar,
Christopher Hall
John,
On Fri, 26 Feb 2016, John Stultz wrote:
> Hey Thomas, Ingo,
> Here's my somewhat truncated queue for 4.6. I was hoping to
> get the cross-timestamp patchset from Christopher sent along,
> but he's got some last minute changes to address feedback from
> Andy, so I'm holding off.
>
> If the response is good for that last change, I may try to send
> another set with those changes next week, but we're cutting it
> fairly close to -rc6, so I'll check with you before doing so.
If it's just the small fixup to address review comments, we still should take
it.
> So.. two tiny cleanup fixes is all for now.
>
> Boring is good, right?
:)
Thanks,
tglx
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6
2016-02-27 3:14 [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6 John Stultz
` (2 preceding siblings ...)
2016-02-27 7:50 ` [PATCH 0/2][GIT PULL] Timekeeping updates to tip/timers/core for 4.6 Thomas Gleixner
@ 2016-02-27 7:52 ` Thomas Gleixner
3 siblings, 0 replies; 7+ messages in thread
From: Thomas Gleixner @ 2016-02-27 7:52 UTC (permalink / raw)
To: John Stultz
Cc: lkml, Prarit Bhargava, Richard Cochran, Ingo Molnar,
Christopher Hall
On Fri, 26 Feb 2016, John Stultz wrote:
> clocksource: introduce clocksource_freq2mult()
> jiffies: use CLOCKSOURCE_MASK instead of constant
Bah. You again forgot to make the first letter of the sentence upper case.
Hint: There is the concept of scripts, which can automate that :)
Thanks,
tglx
^ permalink raw reply [flat|nested] 7+ messages in thread