Skip to content

Commit 93825f2

Browse files
fweisbecIngo Molnar
authored andcommitted
jiffies: Reuse TICK_NSEC instead of NSEC_PER_JIFFY
NSEC_PER_JIFFY is an ad-hoc redefinition of TICK_NSEC. Let's rather use a unique and well maintained version. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Tony Luck <tony.luck@intel.com> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Stanislaw Gruszka <sgruszka@redhat.com> Cc: Wanpeng Li <wanpeng.li@hotmail.com> Link: http://lkml.kernel.org/r/1485832191-26889-1-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent ed5c8c8 commit 93825f2

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

kernel/time/jiffies.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,17 @@
2727

2828
#include "timekeeping.h"
2929

30-
/* The Jiffies based clocksource is the lowest common
31-
* denominator clock source which should function on
32-
* all systems. It has the same coarse resolution as
33-
* the timer interrupt frequency HZ and it suffers
34-
* inaccuracies caused by missed or lost timer
35-
* interrupts and the inability for the timer
36-
* interrupt hardware to accuratly tick at the
37-
* requested HZ value. It is also not recommended
38-
* for "tick-less" systems.
39-
*/
40-
#define NSEC_PER_JIFFY ((NSEC_PER_SEC+HZ/2)/HZ)
4130

42-
/* Since jiffies uses a simple NSEC_PER_JIFFY multiplier
31+
/* Since jiffies uses a simple TICK_NSEC multiplier
4332
* conversion, the .shift value could be zero. However
4433
* this would make NTP adjustments impossible as they are
4534
* in units of 1/2^.shift. Thus we use JIFFIES_SHIFT to
4635
* shift both the nominator and denominator the same
4736
* amount, and give ntp adjustments in units of 1/2^8
4837
*
4938
* The value 8 is somewhat carefully chosen, as anything
50-
* larger can result in overflows. NSEC_PER_JIFFY grows as
51-
* HZ shrinks, so values greater than 8 overflow 32bits when
39+
* larger can result in overflows. TICK_NSEC grows as HZ
40+
* shrinks, so values greater than 8 overflow 32bits when
5241
* HZ=100.
5342
*/
5443
#if HZ < 34
@@ -64,12 +53,23 @@ static u64 jiffies_read(struct clocksource *cs)
6453
return (u64) jiffies;
6554
}
6655

56+
/*
57+
* The Jiffies based clocksource is the lowest common
58+
* denominator clock source which should function on
59+
* all systems. It has the same coarse resolution as
60+
* the timer interrupt frequency HZ and it suffers
61+
* inaccuracies caused by missed or lost timer
62+
* interrupts and the inability for the timer
63+
* interrupt hardware to accuratly tick at the
64+
* requested HZ value. It is also not recommended
65+
* for "tick-less" systems.
66+
*/
6767
static struct clocksource clocksource_jiffies = {
6868
.name = "jiffies",
6969
.rating = 1, /* lowest valid rating*/
7070
.read = jiffies_read,
7171
.mask = CLOCKSOURCE_MASK(32),
72-
.mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
72+
.mult = TICK_NSEC << JIFFIES_SHIFT, /* details above */
7373
.shift = JIFFIES_SHIFT,
7474
.max_cycles = 10,
7575
};
@@ -125,7 +125,7 @@ int register_refined_jiffies(long cycles_per_second)
125125
shift_hz += cycles_per_tick/2;
126126
do_div(shift_hz, cycles_per_tick);
127127
/* Calculate nsec_per_tick using shift_hz */
128-
nsec_per_tick = (u64)NSEC_PER_SEC << 8;
128+
nsec_per_tick = (u64)TICK_NSEC << 8;
129129
nsec_per_tick += (u32)shift_hz/2;
130130
do_div(nsec_per_tick, (u32)shift_hz);
131131

0 commit comments

Comments
 (0)