summaryrefslogtreecommitdiff
path: root/hwclock
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2009-08-20 15:46:10 +0200
committerKarel Zak <kzak@redhat.com>2009-08-20 15:46:10 +0200
commit102f5d89d942ee54c5b9a5adfb04df8a5b09177f (patch)
treef906ec0deb9f2507f1707cdea9985e105ccbec00 /hwclock
parent3f99aaf1c95fa39e54d27324da777ebd3721c7de (diff)
downloadutil-linux-old-102f5d89d942ee54c5b9a5adfb04df8a5b09177f.tar.gz
hwclocks: use time limit for KDGHWCLK busy wait
Currently the busy wait in synchronize_to_clock_tick_kd() is restricted by number of loops. It's better to use time limit (1.5s). We already use this method for RTC. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'hwclock')
-rw-r--r--hwclock/kd.c38
1 files changed, 19 insertions, 19 deletions
diff --git a/hwclock/kd.c b/hwclock/kd.c
index 3b5708a9..b0e55d1c 100644
--- a/hwclock/kd.c
+++ b/hwclock/kd.c
@@ -44,10 +44,10 @@ synchronize_to_clock_tick_kd(void) {
Wait for the top of a clock tick by calling KDGHWCLK in a busy loop until
we see it.
-----------------------------------------------------------------------------*/
- int i;
/* The time when we were called (and started waiting) */
struct hwclk_time start_time, nowtime;
+ struct timeval begin, now;
if (debug)
printf(_("Waiting in loop for time from KDGHWCLK to change\n"));
@@ -57,31 +57,31 @@ synchronize_to_clock_tick_kd(void) {
return 3;
}
- i = 0;
+ /* Wait for change. Should be within a second, but in case something
+ * weird happens, we have a time limit (1.5s) on this loop to reduce the
+ * impact of this failure.
+ */
+ gettimeofday(&begin, NULL);
do {
- /* Added by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
- /* "The culprit is the fast loop with KDGHWCLK ioctls. It seems
- the kernel gets confused by those on Amigas with A2000 RTCs
- and simply hangs after some time. Inserting a nanosleep helps." */
- /* Christian T. Steigies: 1 instead of 1000000 is still sufficient
- to keep the machine from freezing. */
-
-#ifdef HAVE_NANOSLEEP
- struct timespec xsleep = { 0, 1 };
- nanosleep( &xsleep, NULL );
-#else
+ /* Added by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
+ * "The culprit is the fast loop with KDGHWCLK ioctls. It seems
+ * the kernel gets confused by those on Amigas with A2000 RTCs
+ * and simply hangs after some time. Inserting a sleep helps."
+ */
usleep(1);
-#endif
- if (i++ >= 1000000) {
- fprintf(stderr, _("Timed out waiting for time change.\n"));
- return 2;
- }
if (ioctl(con_fd, KDGHWCLK, &nowtime) == -1) {
outsyserr(_("KDGHWCLK ioctl to read time failed in loop"));
return 3;
}
- } while (start_time.sec == nowtime.sec);
+ if (start_time.tm_sec != nowtime.tm_sec)
+ break;
+ gettimeofday(&now, NULL);
+ if (time_diff(now, begin) > 1.5) {
+ fprintf(stderr, _("Timed out waiting for time change.\n"));
+ return 2;
+ }
+ } while(1);
return 0;
}