summaryrefslogtreecommitdiffstats
path: root/hwclock
diff options
context:
space:
mode:
authorKalev Soikonen2008-07-28 01:26:44 +0200
committerKarel Zak2008-08-13 11:43:59 +0200
commitac1bb1ef9350a79a016d504022c710336244a112 (patch)
tree8a977601b1d422fe8ce3b84eb8b9feaec1d61750 /hwclock
parenthwclock: use time limit for synchronization busy wait (diff)
downloadkernel-qcow2-util-linux-ac1bb1ef9350a79a016d504022c710336244a112.tar.gz
kernel-qcow2-util-linux-ac1bb1ef9350a79a016d504022c710336244a112.tar.xz
kernel-qcow2-util-linux-ac1bb1ef9350a79a016d504022c710336244a112.zip
hwclock: delay loop in set_hardware_clock_exact
- Avoid delaying 1.5 seconds when 0.5 will do. - Guard for forward time resets as well. [kzak@redhat.com: - fix the "Delaying.." debug message - add comments] Signed-off-by: Kalev Soikonen <ksop@hot.ee> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'hwclock')
-rw-r--r--hwclock/hwclock.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c
index c08ae3f5e..48b47ade8 100644
--- a/hwclock/hwclock.c
+++ b/hwclock/hwclock.c
@@ -526,28 +526,32 @@ set_hardware_clock_exact(const time_t sethwtime,
time_t newhwtime;
struct timeval beginsystime, nowsystime;
+ double tdiff;
time_resync:
gettimeofday(&beginsystime, NULL);
- newhwtime = sethwtime + (int) time_diff(beginsystime, refsystime) + 1;
+ tdiff = time_diff(beginsystime, refsystime);
+ newhwtime = sethwtime + (int) (tdiff + 0.5);
if (debug)
printf(_("Time elapsed since reference time has been %.6f seconds.\n"
- "Delaying further to reach the next full second.\n"),
- time_diff(beginsystime, refsystime));
+ "Delaying further to reach the new time.\n"), tdiff);
/*
- * Now delay some more until Hardware Clock time newhwtime arrives. The -500
- * ms is because the Hardware Clock always sets to your set time plus 500 ms
+ * Now delay some more until Hardware Clock time newhwtime arrives. The 0.5 s
+ * is because the Hardware Clock always sets to your set time plus 500 ms
* (because it is designed to update to the next second precisely 500 ms
* after you finish the setting).
*/
do {
- float tdiff;
gettimeofday(&nowsystime, NULL);
tdiff = time_diff(nowsystime, beginsystime);
if (tdiff < 0)
- goto time_resync; /* probably time was reset */
- } while (time_diff(nowsystime, refsystime) - 0.5 < newhwtime - sethwtime);
+ goto time_resync; /* probably backward time reset */
+ if (tdiff > 0.1)
+ goto time_resync; /* probably forward time reset */
+ beginsystime = nowsystime;
+ tdiff = time_diff(nowsystime, refsystime);
+ } while (newhwtime == sethwtime + (int) (tdiff + 0.5));
set_hardware_clock(newhwtime, universal, testing);
}