Skip to content

Commit

Permalink
timekeeping: Make fast accessors return 0 before timekeeping is initi…
Browse files Browse the repository at this point in the history
…alized

printk timestamps will be extended to include mono and boot time by using
the fast timekeeping accessors ktime_get_mono|boot_fast_ns().  The
functions can return garbage before timekeeping is initialized resulting in
garbage timestamps.

Initialize the fast timekeepers with dummy clocks which guarantee a 0
readout up to timekeeping_init().

Suggested-by: Peter Zijlstra <[email protected]>
Signed-off-by: Prarit Bhargava <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Stephen Boyd <[email protected]>
Cc: John Stultz <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
  • Loading branch information
prarit authored and KAGA-KOKO committed Sep 25, 2017
1 parent e19b205 commit 5df3210
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions kernel/time/timekeeping.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,27 @@ struct tk_fast {
struct tk_read_base base[2];
};

static struct tk_fast tk_fast_mono ____cacheline_aligned;
static struct tk_fast tk_fast_raw ____cacheline_aligned;
/* Suspend-time cycles value for halted fast timekeeper. */
static u64 cycles_at_suspend;

static u64 dummy_clock_read(struct clocksource *cs)
{
return cycles_at_suspend;
}

static struct clocksource dummy_clock = {
.read = dummy_clock_read,
};

static struct tk_fast tk_fast_mono ____cacheline_aligned = {
.base[0] = { .clock = &dummy_clock, },
.base[1] = { .clock = &dummy_clock, },
};

static struct tk_fast tk_fast_raw ____cacheline_aligned = {
.base[0] = { .clock = &dummy_clock, },
.base[1] = { .clock = &dummy_clock, },
};

/* flag for if timekeeping is suspended */
int __read_mostly timekeeping_suspended;
Expand Down Expand Up @@ -477,18 +496,6 @@ u64 notrace ktime_get_boot_fast_ns(void)
}
EXPORT_SYMBOL_GPL(ktime_get_boot_fast_ns);

/* Suspend-time cycles value for halted fast timekeeper. */
static u64 cycles_at_suspend;

static u64 dummy_clock_read(struct clocksource *cs)
{
return cycles_at_suspend;
}

static struct clocksource dummy_clock = {
.read = dummy_clock_read,
};

/**
* halt_fast_timekeeper - Prevent fast timekeeper from accessing clocksource.
* @tk: Timekeeper to snapshot.
Expand Down

0 comments on commit 5df3210

Please sign in to comment.