Jim Meyering [EMAIL PROTECTED] writes:
Paul Eggert [EMAIL PROTECTED] wrote:
How about if we add a new module (getmonotime, say?) that gets
CLOCK_MONTONIC time, and use that in dd and sleep? On Solaris this
could be done via gethrtime()...
That sounds good.
OK, I did that, and installed the following patch. It also cleans up
gettime a bit too, by using some of the ideas now in gethrxtime. I
realize this is all a bit much if you're trying for a stable coreutils
release sometime real soon, so if that's a problem please let me know
and I'll back out the change.
2005-02-20 Paul Eggert [EMAIL PROTECTED]
* NEWS: Describe user-visible change to dd.
* lib/gethrxtime.h, lib/gethrxtime.c, lib/xtime.h: New files.
* lib/timespec.h (gettime): Return void, since it always
succeeds now. All uses changed.
* lib/gettime.c (gettime) Likewise.
[HAVE_NANOTIME]: Prefer nanotime.
Assume gettimeofday succeeds, as POSIX requires.
Assime time () succeeds, since other code already does.
* lib/xnanosleep.c: Include xtime.h and gethrxtime.h, not xalloc.h.
(timespec_subtract): Remove.
(NANOSLEEP_BUG_WORKAROUND): New constant.
(xnanosleep): Use gethrxtime rather than gettime; this simplifies
things considerably. Use it only on GNU/Linux hosts, since the
workaround shouldn't be needed elsewhere.
* m4/gethrxtime.m4: New file.
* m4/gettime.m4 (gl_GETTIME): Check for nanotime.
* m4/jm-macros.m4 (gl_MACROS): Don't check for gethrtime.
* m4/prereq.m4 (gl_PREREQ): Require gl_GETHRXTIME.
* src/Makefile.am (dd_LDADD, shred_LDADD, nanosec_libs):
Remove $(LIB_CLOCK_GETTIME). These functions now use
gethrxtime instead.
* src/dd.c: Include gethrxtime.h, xtime.h.
(start_time): Now of type xtime_t, not struct timespec.
(print_stats, main): Use gethrxtime rather than gettime.
* src/ls.c (time): Remove obsolete decl.
(get_current_time): gettimeofday always returns 0, so don't
check its result.
* src/shred.c: Include gethrxtime.h.
(isaac_seed): Use gethrxtime rather than a mishmash.
* src/touch.c (time): Remove obsolete decl.
Index: NEWS
===
RCS file: /fetish/cu/NEWS,v
retrieving revision 1.269
diff -p -u -r1.269 NEWS
--- NEWS15 Feb 2005 12:33:35 - 1.269
+++ NEWS21 Feb 2005 08:05:11 -
@@ -20,6 +20,10 @@ GNU coreutils NEWS
** Bug fixes
+ dd now computes statistics using a realtime clock (if available)
+ rather than the time-of-day clock, to avoid glitches if the
+ time-of-day is changed while dd is running.
+
expr now detects integer overflow when evaluating large integers,
rather than silently wrapping around.
--- /dev/null 2003-03-18 21:55:57 +
+++ lib/xtime.h 2005-02-21 07:35:58 +
@@ -0,0 +1,87 @@
+/* xtime -- extended-resolution integer time stamps
+
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+/* Written by Paul Eggert. */
+
+#ifndef XTIME_H_
+#define XTIME_H_ 1
+
+/* xtime_t is a signed type used for time stamps. It is an integer
+ type that is a count of nanoseconds -- except for obsolescent hosts
+ without sufficiently-wide integers, where it is a count of
+ seconds. */
+#if HAVE_LONG_LONG
+typedef long long int xtime_t;
+# define XTIME_PRECISION 10LL
+#else
+# include limits.h
+typedef long int xtime_t;
+# if LONG_MAX 31 31 == 0
+# define XTIME_PRECISION 1L
+# else
+# define XTIME_PRECISION 10L
+# endif
+#endif
+
+/* Return an extended time value that contains S seconds and NS
+ nanoseconds, without any overflow checking. */
+static inline xtime_t
+xtime_make (xtime_t s, int ns)
+{
+ if (XTIME_PRECISION == 1)
+return s;
+ else
+return XTIME_PRECISION * s + ns;
+}
+
+/* Return the number of seconds in T, which must be nonnegative. */
+static inline xtime_t
+xtime_nonnegative_sec (xtime_t t)
+{
+ return t / XTIME_PRECISION;
+}
+
+/* Return the number of seconds in T. */
+static inline xtime_t
+xtime_sec (xtime_t t)
+{
+ return (XTIME_PRECISION == 1
+ ? t
+ : t 0
+ ? (t +