Skip to content

Commit 1aa5dfb

Browse files
John StultzIngo Molnar
authored andcommitted
clocksource: keep track of original clocksource frequency
The clocksource frequency is represented by clocksource->mult/2^(clocksource->shift). Currently, when NTP makes adjustments to the clock frequency, they are made directly to the mult value. This has the drawback that once changed, we cannot know what the orignal mult value was, or how much adjustment has been applied. This property causes problems in calculating proper ntp intervals when switching back and forth between clocksources. This patch separates the current mult value into a mult and mult_orig pair. The mult_orig value stays constant, while the ntp clocksource adjustments are done only to the mult value. This allows for correct ntp interval calculation and additionally lays the groundwork for a new notion of time, what I'm calling the monotonic-raw time, which is introduced in a following patch. Signed-off-by: John Stultz <johnstul@us.ibm.com> Signed-off-by: Roman Zippel <zippel@linux-m68k.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent ee974e0 commit 1aa5dfb

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎include/linux/clocksource.h‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ struct clocksource;
4545
* @read: returns a cycle value
4646
* @mask: bitmask for two's complement
4747
* subtraction of non 64 bit counters
48-
* @mult: cycle to nanosecond multiplier
48+
* @mult: cycle to nanosecond multiplier (adjusted by NTP)
49+
* @mult_orig: cycle to nanosecond multiplier (unadjusted by NTP)
4950
* @shift: cycle to nanosecond divisor (power of two)
5051
* @flags: flags describing special properties
5152
* @vread: vsyscall based read
@@ -63,6 +64,7 @@ struct clocksource {
6364
cycle_t (*read)(void);
6465
cycle_t mask;
6566
u32 mult;
67+
u32 mult_orig;
6668
u32 shift;
6769
unsigned long flags;
6870
cycle_t (*vread)(void);
@@ -201,16 +203,17 @@ static inline void clocksource_calculate_interval(struct clocksource *c,
201203
{
202204
u64 tmp;
203205

204-
/* XXX - All of this could use a whole lot of optimization */
206+
/* Do the ns -> cycle conversion first, using original mult */
205207
tmp = length_nsec;
206208
tmp <<= c->shift;
207-
tmp += c->mult/2;
208-
do_div(tmp, c->mult);
209+
tmp += c->mult_orig/2;
210+
do_div(tmp, c->mult_orig);
209211

210212
c->cycle_interval = (cycle_t)tmp;
211213
if (c->cycle_interval == 0)
212214
c->cycle_interval = 1;
213215

216+
/* Go back from cycles -> shifted ns, this time use ntp adjused mult */
214217
c->xtime_interval = (u64)c->cycle_interval * c->mult;
215218
}
216219

‎kernel/time/clocksource.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ int clocksource_register(struct clocksource *c)
325325
unsigned long flags;
326326
int ret;
327327

328+
/* save mult_orig on registration */
329+
c->mult_orig = c->mult;
330+
328331
spin_lock_irqsave(&clocksource_lock, flags);
329332
ret = clocksource_enqueue(c);
330333
if (!ret)

‎kernel/time/jiffies.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct clocksource clocksource_jiffies = {
6161
.read = jiffies_read,
6262
.mask = 0xffffffff, /*32bits*/
6363
.mult = NSEC_PER_JIFFY << JIFFIES_SHIFT, /* details above */
64+
.mult_orig = NSEC_PER_JIFFY << JIFFIES_SHIFT,
6465
.shift = JIFFIES_SHIFT,
6566
};
6667

0 commit comments

Comments
 (0)