On Tue, Aug 12, 2008 at 02:22:47PM +0200, Karel Zak wrote: > > On Sat, Aug 09, 2008 at 05:05:23PM +0200, Tomasz Chmielewski wrote: > > Karel Zak schrieb: > > > > (...) > > > >>> But would it solve the issue, really? > >> > >> Yes, that's core of the problem. But we also need to remove some return > >> code checks from manipulate_clock(). These checks are unnecessary, > >> because there is hclock_valid boolean... (this is my bug.) > >> > >>> hwclock from busybox is able to show the clock (Tue Nov 30 00:00:00 > >>> 1999 0.000000) and also set it; the above seems to exit only - and > >>> still, we're not able to show or set the clock? > >> > >> I'll send a patch ASAP. > > > > Could you notify the list when the patch is ready, please? > > The patch is below. It's based on gettimeofday() rather than on > SIGALRM (alarm(2)). The gettimeofday has some overhead, but it > shouldn't be a big problem for the synchronization function (... and > it's fallback for systems without RTC_UIE_ON). > > Please, test & review. I'd like to use the patch in 2.14.1. sorry, the patch: >From 50506d3535f4af36a550dcd91136224a608e61f7 Mon Sep 17 00:00:00 2001 From: Karel Zak <kzak@xxxxxxxxxx> Date: Tue, 12 Aug 2008 13:58:51 +0200 Subject: [PATCH] hwclock: use time limit for synchronization busy wait Signed-off-by: Karel Zak <kzak@xxxxxxxxxx> --- hwclock/clock.h | 1 + hwclock/hwclock.c | 2 +- hwclock/rtc.c | 23 ++++++++++++----------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/hwclock/clock.h b/hwclock/clock.h index 6e8a9b4..cbdf999 100644 --- a/hwclock/clock.h +++ b/hwclock/clock.h @@ -33,6 +33,7 @@ extern void outsyserr(char *msg, ...) #else ; #endif +extern double time_diff(struct timeval subtrahend, struct timeval subtractor); /* cmos.c */ extern void set_cmos_epoch(int ARCconsole, int SRM); extern void set_cmos_access(int Jensen, int funky_toy); diff --git a/hwclock/hwclock.c b/hwclock/hwclock.c index 12e7676..44f648c 100644 --- a/hwclock/hwclock.c +++ b/hwclock/hwclock.c @@ -182,7 +182,7 @@ read_date_from_file (struct tm *tm) { write_date_to_file (tm); } -static double +double time_diff(struct timeval subtrahend, struct timeval subtractor) { /*--------------------------------------------------------------------------- The difference in seconds between two times in "timeval" format. diff --git a/hwclock/rtc.c b/hwclock/rtc.c index 3eb1f4e..e59414f 100644 --- a/hwclock/rtc.c +++ b/hwclock/rtc.c @@ -179,8 +179,8 @@ busywait_for_rtc_clock_tick(const int rtc_fd) { struct tm start_time; /* The time when we were called (and started waiting) */ struct tm nowtime; - int i; /* local loop index */ int rc; + struct timeval begin, now; if (debug) printf(_("Waiting in loop for time from %s to change\n"), @@ -191,25 +191,26 @@ busywait_for_rtc_clock_tick(const int rtc_fd) { return 1; /* Wait for change. Should be within a second, but in case something - weird happens, we have a limit on this loop to reduce the impact - of this failure. - */ - for (i = 0; - (rc = do_rtc_read_ioctl(rtc_fd, &nowtime)) == 0 - && start_time.tm_sec == nowtime.tm_sec; - i++) - if (i >= 1000000) { + * weird happens, we have a time limit (1.5s) on this loop to reduce the + * impact of this failure. + */ + gettimeofday(&begin, NULL); + do { + rc = do_rtc_read_ioctl(rtc_fd, &nowtime); + if (rc || 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); if (rc) return 3; return 0; } - - static int synchronize_to_clock_tick_rtc(void) { /*---------------------------------------------------------------------------- -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html