alistair23-linux/kernel
Thomas Gleixner 6a669ee8a7 timekeeping: Prevent time going backwards on resume
Timekeeping resume adjusts xtime by adding the slept time in seconds and
resets the reference value of the clock source (clock->cycle_last).
clock->cycle last is used to calculate the delta between the last xtime
update and the readout of the clock source in __get_nsec_offset(). xtime
plus the offset is the current time. The resume code ignores the delta
which had already elapsed between the last xtime update and the actual
time of suspend. If the suspend time is short, then we can see time
going backwards on resume.

Suspend:
offs_s = clock->read() - clock->cycle_last;
now = xtime + offs_s;
timekeeping_suspend_time = read_rtc();

Resume:
sleep_time = read_rtc() - timekeeping_suspend_time;
xtime.tv_sec += sleep_time;
clock->cycle_last = clock->read();
offs_r = clock->read() - clock->cycle_last;
now = xtime + offs_r;

if sleep_time_seconds == 0 and offs_r < offs_s, then time goes
backwards.

Fix this by storing the offset from the last xtime update and add it to
xtime during resume, when we reset clock->cycle_last:

sleep_time = read_rtc() - timekeeping_suspend_time;
xtime.tv_sec += sleep_time;
xtime += offs_s;	/* Fixup xtime offset at suspend time */
clock->cycle_last = clock->read();
offs_r = clock->read() - clock->cycle_last;
now = xtime + offs_r;

Thanks to Marcelo for tracking this down on the OLPC and providing the
necessary details to analyze the root cause.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <johnstul@us.ibm.com>
Cc: Tosatti <marcelo@kvack.org>
2007-09-16 15:36:43 +02:00
..
irq request_irq: fix DEBUG_SHIRQ handling 2007-08-31 01:42:23 -07:00
power PM: Fix dependencies of CONFIG_SUSPEND and CONFIG_HIBERNATION 2007-08-31 01:42:22 -07:00
time timekeeping: Prevent time going backwards on resume 2007-09-16 15:36:43 +02:00
.gitignore
acct.c Cleanup non-arch xtime uses, use get_seconds() or current_kernel_time(). 2007-07-25 10:09:20 -07:00
audit.c
audit.h
auditfilter.c [PATCH] allow audit filtering on bit & operations 2007-07-22 09:57:02 -04:00
auditsc.c kernel/auditsc.c: fix an off-by-one 2007-08-22 19:52:44 -07:00
capability.c
compat.c
configs.c
cpu.c PM: Fix dependencies of CONFIG_SUSPEND and CONFIG_HIBERNATION 2007-08-31 01:42:22 -07:00
cpuset.c usermodehelper: Tidy up waiting 2007-07-18 08:47:40 -07:00
delayacct.c
die_notifier.c
dma.c
exec_domain.c
exit.c Assign task_struct.exit_code before taskstats_exit() 2007-08-31 01:42:22 -07:00
extable.c
fork.c mm: Remove slab destructors from kmem_cache_create(). 2007-07-20 10:11:58 +09:00
futex.c futex_unlock_pi() hurts my brain and may cause application deadlock 2007-08-22 19:52:44 -07:00
futex_compat.c futex_compat: fix list traversal bugs 2007-09-11 17:21:20 -07:00
hrtimer.c Cache xtime every call to update_wall_time 2007-07-25 10:17:44 -07:00
itimer.c
kallsyms.c
Kconfig.hz
Kconfig.preempt [PATCH] sched: arch preempt notifier mechanism 2007-07-26 13:40:43 +02:00
kexec.c
kfifo.c
kmod.c Restore call_usermodehelper_pipe() behaviour 2007-09-11 17:21:20 -07:00
kprobes.c fix compilation with gcc 4.2 2007-08-11 15:47:42 -07:00
ksysfs.c FRV: Fix linkage problems 2007-07-20 12:01:34 -07:00
kthread.c kthread: silence bogus section mismatch warning 2007-07-31 15:39:42 -07:00
latency.c
lockdep.c lockdep debugging: give stacktrace for init_error 2007-07-19 10:04:49 -07:00
lockdep_internals.h
lockdep_proc.c Fix leak on /proc/lockdep_stats 2007-07-31 15:39:40 -07:00
Makefile
module.c Fix Off-by-one in /sys/module/*/refcnt 2007-08-22 14:35:35 -07:00
mutex-debug.c
mutex-debug.h
mutex.c lockstat: measure lock bouncing 2007-07-19 10:04:49 -07:00
mutex.h
nsproxy.c mm: Remove slab destructors from kmem_cache_create(). 2007-07-20 10:11:58 +09:00
panic.c
params.c modules: better error messages when modules fail to load due to a sysfs problem. 2007-07-30 14:25:23 -07:00
pid.c
posix-cpu-timers.c
posix-timers.c posix-timers: fix creation race 2007-08-22 19:52:46 -07:00
printk.c fix - ensure we don't use bootconsoles after init has been released 2007-08-21 20:23:53 -07:00
profile.c fix compilation with gcc 4.2 2007-08-11 15:47:42 -07:00
ptrace.c Fix spurious syscall tracing after PTRACE_DETACH + PTRACE_ATTACH 2007-09-10 18:57:47 -07:00
rcupdate.c
rcutorture.c
relay.c Fix a use after free bug in kernel->userspace relay file support 2007-07-31 15:39:42 -07:00
resource.c
rtmutex-debug.c
rtmutex-debug.h
rtmutex-tester.c
rtmutex.c
rtmutex.h
rtmutex_common.h
rwsem.c lockstat: hook into spinlock_t, rwlock_t, rwsem and mutex 2007-07-19 10:04:49 -07:00
sched.c sched: fix xtensa build warning 2007-09-05 14:32:49 +02:00
sched_debug.c sched: debug: fix sum_exec_runtime clearing 2007-09-05 14:32:49 +02:00
sched_fair.c sched: fix ideal_runtime calculations for reniced tasks 2007-09-05 14:32:49 +02:00
sched_idletask.c sched: remove the 'u64 now' parameter from ->put_prev_task() 2007-08-09 11:16:49 +02:00
sched_rt.c sched: optimize task_tick_rt() a bit 2007-08-24 20:39:10 +02:00
sched_stats.h [PATCH] sched: add schedstat_set() API 2007-08-02 17:41:40 +02:00
seccomp.c
signal.c sigqueue_free: fix the race with collect_signal() 2007-08-31 01:42:23 -07:00
softirq.c
softlockup.c
spinlock.c lockstat: hook into spinlock_t, rwlock_t, rwsem and mutex 2007-07-19 10:04:49 -07:00
srcu.c
stacktrace.c
stop_machine.c
sys.c setpgid(child) fails if the child was forked by sub-thread 2007-08-31 01:42:22 -07:00
sys_ni.c
sysctl.c sched: cleanup, sched_granularity -> sched_min_granularity 2007-08-25 18:41:53 +02:00
taskstats.c
time.c Cleanup non-arch xtime uses, use get_seconds() or current_kernel_time(). 2007-07-25 10:09:20 -07:00
timer.c Pull ia64-clocksource into release branch 2007-07-20 11:26:47 -07:00
tsacct.c Cleanup non-arch xtime uses, use get_seconds() or current_kernel_time(). 2007-07-25 10:09:20 -07:00
uid16.c
user.c mm: Remove slab destructors from kmem_cache_create(). 2007-07-20 10:11:58 +09:00
user_namespace.c userns: don't leak root user 2007-08-31 01:42:23 -07:00
utsname.c
utsname_sysctl.c
wait.c
workqueue.c fix bogus hotplug cpu warning 2007-08-27 10:27:48 -07:00