Skip to content

Commit a105e02

Browse files
KAGA-KOKObwhacks
authored andcommitted
timekeeping: Maintain ktime_t based offsets for hrtimers
This is a backport of 5b9fe75 We need to update the hrtimer clock offsets from the hrtimer interrupt context. To avoid conversions from timespec to ktime_t maintain a ktime_t based representation of those offsets in the timekeeper. This puts the conversion overhead into the code which updates the underlying offsets and provides fast accessible values in the hrtimer interrupt. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: John Stultz <johnstul@us.ibm.com> Reviewed-by: Ingo Molnar <mingo@kernel.org> Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Acked-by: Prarit Bhargava <prarit@redhat.com> Link: http://lkml.kernel.org/r/1341960205-56738-4-git-send-email-johnstul@us.ibm.com Signed-off-by: Thomas Gleixner <tglx@linutronix.de> [John Stultz: Backported to 3.2] Cc: Prarit Bhargava <prarit@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Linux Kernel <linux-kernel@vger.kernel.org> Signed-off-by: John Stultz <johnstul@us.ibm.com> Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
1 parent 8a1ba97 commit a105e02

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

‎kernel/time/timekeeping.c‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,34 @@ static struct timespec xtime __attribute__ ((aligned (16)));
161161
static struct timespec wall_to_monotonic __attribute__ ((aligned (16)));
162162
static struct timespec total_sleep_time;
163163

164+
/* Offset clock monotonic -> clock realtime */
165+
static ktime_t offs_real;
166+
167+
/* Offset clock monotonic -> clock boottime */
168+
static ktime_t offs_boot;
169+
164170
/*
165171
* The raw monotonic time for the CLOCK_MONOTONIC_RAW posix clock.
166172
*/
167173
static struct timespec raw_time;
168174

175+
/* must hold write on xtime_lock */
176+
static void update_rt_offset(void)
177+
{
178+
struct timespec tmp, *wtm = &wall_to_monotonic;
179+
180+
set_normalized_timespec(&tmp, -wtm->tv_sec, -wtm->tv_nsec);
181+
offs_real = timespec_to_ktime(tmp);
182+
}
183+
169184
/* must hold write on xtime_lock */
170185
static void timekeeping_update(bool clearntp)
171186
{
172187
if (clearntp) {
173188
timekeeper.ntp_error = 0;
174189
ntp_clear();
175190
}
191+
update_rt_offset();
176192
update_vsyscall(&xtime, &wall_to_monotonic,
177193
timekeeper.clock, timekeeper.mult);
178194
}
@@ -587,6 +603,7 @@ void __init timekeeping_init(void)
587603
}
588604
set_normalized_timespec(&wall_to_monotonic,
589605
-boot.tv_sec, -boot.tv_nsec);
606+
update_rt_offset();
590607
total_sleep_time.tv_sec = 0;
591608
total_sleep_time.tv_nsec = 0;
592609
write_sequnlock_irqrestore(&xtime_lock, flags);
@@ -595,6 +612,12 @@ void __init timekeeping_init(void)
595612
/* time in seconds when suspend began */
596613
static struct timespec timekeeping_suspend_time;
597614

615+
static void update_sleep_time(struct timespec t)
616+
{
617+
total_sleep_time = t;
618+
offs_boot = timespec_to_ktime(t);
619+
}
620+
598621
/**
599622
* __timekeeping_inject_sleeptime - Internal function to add sleep interval
600623
* @delta: pointer to a timespec delta value
@@ -612,7 +635,7 @@ static void __timekeeping_inject_sleeptime(struct timespec *delta)
612635

613636
xtime = timespec_add(xtime, *delta);
614637
wall_to_monotonic = timespec_sub(wall_to_monotonic, *delta);
615-
total_sleep_time = timespec_add(total_sleep_time, *delta);
638+
update_sleep_time(timespec_add(total_sleep_time, *delta));
616639
}
617640

618641

0 commit comments

Comments
 (0)