summaryrefslogtreecommitdiffstats
path: root/hwclock
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:26:05 +0100
committerKarel Zak2006-12-07 00:26:05 +0100
commit95f1bdeee42cd7b9ac49d64b27bcec49557a991e (patch)
tree5813d335771188c724c3d1bc9f9f9feb23c1d9ca /hwclock
parentImported from util-linux-2.11w tarball. (diff)
downloadkernel-qcow2-util-linux-95f1bdeee42cd7b9ac49d64b27bcec49557a991e.tar.gz
kernel-qcow2-util-linux-95f1bdeee42cd7b9ac49d64b27bcec49557a991e.tar.xz
kernel-qcow2-util-linux-95f1bdeee42cd7b9ac49d64b27bcec49557a991e.zip
Imported from util-linux-2.11x tarball.
Diffstat (limited to 'hwclock')
-rw-r--r--hwclock/hwclock.c45
-rw-r--r--hwclock/rtc.c2
2 files changed, 26 insertions, 21 deletions
diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c
index 22a7a43cb..eeabc3726 100644
--- a/hwclock/hwclock.c
+++ b/hwclock/hwclock.c
@@ -483,21 +483,20 @@ set_hardware_clock(const time_t newtime,
static void
-set_hardware_clock_exact(const time_t settime,
- const struct timeval ref_time,
+set_hardware_clock_exact(const time_t sethwtime,
+ const struct timeval refsystime,
const bool universal,
const bool testing) {
/*----------------------------------------------------------------------------
- Set the Hardware Clock to the time "settime", in local time zone or UTC,
+ Set the Hardware Clock to the time "sethwtime", in local time zone or UTC,
according to "universal".
- But correct "settime" and wait for a fraction of a second so that
- "settime" is the value of the Hardware Clock as of system time
- "ref_time", which is in the past. For example, if "settime" is
- 14:03:05 and "ref_time" is 12:10:04.5 and the current system
- time is 12:10:06.0: Wait .5 seconds (to make exactly 2 seconds since
- "ref_time") and then set the Hardware Clock to 14:03:07, thus
- getting a precise and retroactive setting of the clock.
+ Wait for a fraction of a second so that "sethwtime" is the value of
+ the Hardware Clock as of system time "refsystime", which is in the past.
+ For example, if "sethwtime" is 14:03:05 and "refsystime" is 12:10:04.5
+ and the current system time is 12:10:06.0: Wait .5 seconds (to make
+ exactly 2 seconds since "refsystime") and then set the Hardware Clock
+ to 14:03:07, thus getting a precise and retroactive setting of the clock.
(Don't be confused by the fact that the system clock and the Hardware
Clock differ by two hours in the above example. That's just to remind
@@ -505,23 +504,29 @@ set_hardware_clock_exact(const time_t settime,
This function ought to be able to accept set times as fractional times.
Idea for future enhancement.
-
-----------------------------------------------------------------------------*/
- time_t newtime; /* Time to which we will set Hardware Clock */
- struct timeval now_time; /* locally used time */
- gettimeofday(&now_time, NULL);
- newtime = settime + (int) time_diff(now_time, ref_time) + 1;
+ time_t newhwtime;
+ struct timeval beginsystime, nowsystime;
+
+ time_resync:
+ gettimeofday(&beginsystime, NULL);
+ newhwtime = sethwtime + (int) time_diff(beginsystime, refsystime) + 1;
if (debug)
printf(_("Time elapsed since reference time has been %.6f seconds.\n"
"Delaying further to reach the next full second.\n"),
- time_diff(now_time, ref_time));
+ time_diff(beginsystime, refsystime));
- /* Now delay some more until Hardware Clock time newtime arrives */
- do gettimeofday(&now_time, NULL);
- while (time_diff(now_time, ref_time) < newtime - settime);
+ /* Now delay some more until Hardware Clock time newhwtime arrives */
+ 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) < newhwtime - sethwtime);
- set_hardware_clock(newtime, universal, testing);
+ set_hardware_clock(newhwtime, universal, testing);
}
diff --git a/hwclock/rtc.c b/hwclock/rtc.c
index f6fb0186e..98d1ef9c4 100644
--- a/hwclock/rtc.c
+++ b/hwclock/rtc.c
@@ -210,7 +210,7 @@ int ret;
} else {
int rc; /* Return code from ioctl */
/* Turn on update interrupts (one per second) */
-#if defined(__alpha__) || defined(__sparc__)
+#if defined(__alpha__) || defined(__sparc__) || defined(__x86_64__)
/* Not all alpha kernels reject RTC_UIE_ON, but probably they should. */
rc = -1;
errno = EINVAL;