Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 May 2002 19:16:50 +0100
From:      Tony Finch <dot@dotat.at>
To:        freebsd-standards@freebsd.org
Subject:   clock(3) standardization
Message-ID:  <20020528191650.A8322@chiark.greenend.org.uk>

next in thread | raw e-mail | index | archive | help

I noticed that clock(3) currently violates a requirement of POSIX
2001 (that CLOCKS_PER_SEC is 1000000) and that the various archs
are inconsistent and somtimes different from what is in clocks(7).
However clock() isn't mentioned on the C99 project page.

This patch changes clock_t to a size that is consistent on all platforms
and big enough to allow CLOCKS_PER_SEC to be increased to 1e6 without
loss of range. This implies a binary compatibility breakage for programs
that call clock() or times(), and therefore a __FreeBSD_version bump
which I haven't included in this patch. I also haven't tested it yet :-)
Is there anything else to worry about that I might not be aware of?

This patch is rather repetitive. IWBNI the MI stuff in machine/ansi.h
could be moved into an MI header, e.g. sys/ansi.h which might be included
by machine/ansi.h or vice versa.

Tony.
-- 
f.a.n.finch <dot@dotat.at> http://dotat.at/
SOLE LUNDY FASTNET: SOUTHWESTERLY 6 TO GALE 8 DECREASING 5 OR 6. SQUALLY
SHOWERS. GOOD.


--- lib/libc/gen/clock.3	20 Nov 2001 13:43:58 -0000	1.11
+++ lib/libc/gen/clock.3	28 May 2002 17:13:51 -0000
@@ -56,6 +56,9 @@
 calling process, measured in
 .Dv CLOCKS_PER_SEC Ns s
 of a second.
+.Dv CLOCKS_PER_SEC
+is defined to be one million in
+.In time.h .
 .Sh RETURN VALUES
 The
 .Fn clock
@@ -68,13 +71,6 @@
 The
 .Fn clock
 function conforms to
-.St -isoC .
-However,
-.St -susv2
-requires
-.Dv CLOCKS_PER_SEC
-to be defined as one million.
-.Fx
-does not conform to this requirement;
-changing the value would introduce binary incompatibility
-and one million is still inadequate on modern processors.
+.St -isoC
+and
+.St -p1003.1-2001 .
--- share/man/man7/clocks.7	17 Mar 2002 15:02:20 -0000	1.19
+++ share/man/man7/clocks.7	28 May 2002 17:54:50 -0000
@@ -54,7 +54,7 @@
 .It
 The clock reported by
 .Xr clock 3 .
-This is a virtual clock with a frequency that happens to be 128.
+This is a virtual clock with a frequency that happens to be 1000000.
 Its actual frequency is given by the macro
 .Dv CLOCKS_PER_SEC .
 Note that
@@ -70,11 +70,11 @@
 conformance.
 It is implemented by calling
 .Xr getrusage 2
-and throwing away information and resolution.
+and throwing away information.
 .It
 The clock reported by
 .Xr times 3 .
-This is a virtual clock with a frequency that happens to be 128.
+This is a virtual clock with a frequency that happens to be 1000000.
 Its actual frequency is given by the macro
 .Dv CLK_TCK
 (deprecated; do not use) and by
@@ -97,7 +97,7 @@
 .Xr gettimeofday 2
 and
 .Xr getrusage 2
-and throwing away information and resolution.
+and throwing away information.
 .It
 The profiling clock.
 This is a real clock with frequency 1024.
--- sys/alpha/include/ansi.h	10 May 2002 02:21:05 -0000	1.29
+++ sys/alpha/include/ansi.h	28 May 2002 17:46:08 -0000
@@ -47,7 +47,7 @@
  *	#undef	_BSD_SIZE_T_
  *	#endif
  */
-#define	_BSD_CLOCK_T_	int			/* clock() */
+#define	_BSD_CLOCK_T_	__int64_t		/* clock(), times() */
 #define	_BSD_CLOCKID_T_	int			/* clock_gettime()... */
 #define	_BSD_FFLAGS_T_	__uint_least32_t	/* file flags */
 #define	_BSD_MBSTATE_T_	__mbstate_t		/* mbstate_t */
@@ -106,17 +106,11 @@
  */
 
 /*
- * Frequencies of the clock ticks reported by clock() and times().  They
- * are the same as stathz for bogus historical reasons.  They should be
- * 1e6 because clock() and times() are implemented using getrusage() and
- * there is no good reason why they should be less accurate.  There is
- * the bad reason that (broken) programs might not like clock_t or
- * CLOCKS_PER_SEC being ``double'' (``unsigned long'' is not large enough
- * to hold the required 24 hours worth of ticks if the frequency is
- * 1000000ul, and ``unsigned long long'' would be nonstandard).
+ * Frequencies of the clock ticks reported by clock() and times().
+ * POSIX 2001 requires CLOCKS_PER_SEC to be 1e6.
  */
-#define	_BSD_CLK_TCK_		100
-#define	_BSD_CLOCKS_PER_SEC_	100
+#define	_BSD_CLK_TCK_		1000000
+#define	_BSD_CLOCKS_PER_SEC_	1000000
 
 /*
  * We define this here since both <stddef.h> and <sys/types.h> needs it.
--- sys/arm/include/ansi.h	10 May 2002 02:20:33 -0000	1.17
+++ sys/arm/include/ansi.h	28 May 2002 17:46:17 -0000
@@ -46,7 +46,7 @@
  *	#undef	_BSD_SIZE_T_
  *	#endif
  */
-#define	_BSD_CLOCK_T_	unsigned long		/* clock()... */
+#define	_BSD_CLOCK_T_	__int64_t		/* clock(), times() */
 #define	_BSD_CLOCKID_T_	int			/* clock_gettime()... */
 #define	_BSD_MBSTATE_T_	__mbstate_t		/* mbstate_t */
 #define	_BSD_PTRDIFF_T_	int			/* ptr1 - ptr2 */
@@ -98,17 +98,11 @@
  */
 
 /*
- * Frequencies of the clock ticks reported by clock() and times().  They
- * are the same as stathz for bogus historical reasons.  They should be
- * 1e6 because clock() and times() are implemented using getrusage() and
- * there is no good reason why they should be less accurate.  There is
- * the bad reason that (broken) programs might not like clock_t or
- * CLOCKS_PER_SEC being ``double'' (``unsigned long'' is not large enough
- * to hold the required 24 hours worth of ticks if the frequency is
- * 1000000ul, and ``unsigned long long'' would be nonstandard).
+ * Frequencies of the clock ticks reported by clock() and times().
+ * POSIX 2001 requires CLOCKS_PER_SEC to be 1e6.
  */
-#define	_BSD_CLK_TCK_		100
-#define	_BSD_CLOCKS_PER_SEC_	100
+#define	_BSD_CLK_TCK_		1000000
+#define	_BSD_CLOCKS_PER_SEC_	1000000
 
 /*
  * We define this here since both <stddef.h> and <sys/types.h> needs it.
--- sys/i386/include/ansi.h	10 May 2002 02:00:00 -0000	1.38
+++ sys/i386/include/ansi.h	28 May 2002 17:46:29 -0000
@@ -46,7 +46,7 @@
  *	#undef	_BSD_SIZE_T_
  *	#endif
  */
-#define	_BSD_CLOCK_T_	unsigned long		/* clock()... */
+#define	_BSD_CLOCK_T_	__int64_t		/* clock(), times() */
 #define	_BSD_CLOCKID_T_	int			/* clock_gettime()... */
 #define	_BSD_FFLAGS_T_	__uint_least32_t	/* file flags */
 #define	_BSD_MBSTATE_T_	__mbstate_t		/* mbstate_t */
@@ -100,17 +100,11 @@
  */
 
 /*
- * Frequencies of the clock ticks reported by clock() and times().  They
- * are the same as stathz for bogus historical reasons.  They should be
- * 1e6 because clock() and times() are implemented using getrusage() and
- * there is no good reason why they should be less accurate.  There is
- * the bad reason that (broken) programs might not like clock_t or
- * CLOCKS_PER_SEC being ``double'' (``unsigned long'' is not large enough
- * to hold the required 24 hours worth of ticks if the frequency is
- * 1000000ul, and ``unsigned long long'' would be nonstandard).
+ * Frequencies of the clock ticks reported by clock() and times().
+ * POSIX 2001 requires CLOCKS_PER_SEC to be 1e6.
  */
-#define	_BSD_CLK_TCK_		128
-#define	_BSD_CLOCKS_PER_SEC_	128
+#define	_BSD_CLK_TCK_		1000000
+#define	_BSD_CLOCKS_PER_SEC_	1000000
 
 /*
  * We define this here since both <stddef.h> and <sys/types.h> needs it.
--- sys/ia64/include/ansi.h	2 May 2002 09:04:29 -0000	1.21
+++ sys/ia64/include/ansi.h	28 May 2002 17:47:28 -0000
@@ -47,7 +47,7 @@
  *	#undef	_BSD_SIZE_T_
  *	#endif
  */
-#define	_BSD_CLOCK_T_	int			/* clock() */
+#define	_BSD_CLOCK_T_	__int64_t		/* clock(), times() */
 #define	_BSD_CLOCKID_T_	int			/* clockid_t */
 #define	_BSD_FFLAGS_T_	__uint_least32_t	/* file flags */
 #define	_BSD_MBSTATE_T_	__mbstate_t		/* mbstate_t */
@@ -101,17 +101,11 @@
  */
 
 /*
- * Frequencies of the clock ticks reported by clock() and times().  They
- * are the same as stathz for bogus historical reasons.  They should be
- * 1e6 because clock() and times() are implemented using getrusage() and
- * there is no good reason why they should be less accurate.  There is
- * the bad reason that (broken) programs might not like clock_t or
- * CLOCKS_PER_SEC being ``double'' (``unsigned long'' is not large enough
- * to hold the required 24 hours worth of ticks if the frequency is
- * 1000000ul, and ``unsigned long long'' would be nonstandard).
+ * Frequencies of the clock ticks reported by clock() and times().
+ * POSIX 2001 requires CLOCKS_PER_SEC to be 1e6.
  */
-#define	_BSD_CLK_TCK_		100
-#define	_BSD_CLOCKS_PER_SEC_	100
+#define	_BSD_CLK_TCK_		1000000
+#define	_BSD_CLOCKS_PER_SEC_	1000000
 
 /*
  * We define this here since both <stddef.h> and <sys/types.h> needs it.
--- sys/powerpc/include/ansi.h	10 May 2002 02:12:04 -0000	1.21
+++ sys/powerpc/include/ansi.h	28 May 2002 17:48:36 -0000
@@ -46,7 +46,7 @@
  *	#undef	_BSD_SIZE_T_
  *	#endif
  */
-#define	_BSD_CLOCK_T_	int			/* clock() */
+#define	_BSD_CLOCK_T_	__int64_t		/* clock(), times() */
 #define	_BSD_FFLAGS_T_	__uint_least32_t	/* file flags */
 #define	_BSD_CLOCKID_T_	int			/* clockid_t */
 #define	_BSD_MBSTATE_T_	__mbstate_t		/* mbstate_t */
@@ -107,17 +107,11 @@
  */
 
 /*
- * Frequencies of the clock ticks reported by clock() and times().  They
- * are the same as stathz for bogus historical reasons.  They should be
- * 1e6 because clock() and times() are implemented using getrusage() and
- * there is no good reason why they should be less accurate.  There is
- * the bad reason that (broken) programs might not like clock_t or
- * CLOCKS_PER_SEC being ``double'' (``unsigned long'' is not large enough
- * to hold the required 24 hours worth of ticks if the frequency is
- * 1000000ul, and ``unsigned long long'' would be nonstandard).
+ * Frequencies of the clock ticks reported by clock() and times().
+ * POSIX 2001 requires CLOCKS_PER_SEC to be 1e6.
  */
-#define	_BSD_CLK_TCK_		100
-#define	_BSD_CLOCKS_PER_SEC_	100
+#define	_BSD_CLK_TCK_		1000000
+#define	_BSD_CLOCKS_PER_SEC_	1000000
 
 /*
  * We define this here since both <stddef.h> and <sys/types.h> needs it.
--- sys/sparc64/include/ansi.h	10 May 2002 02:02:54 -0000	1.15
+++ sys/sparc64/include/ansi.h	28 May 2002 17:49:36 -0000
@@ -47,7 +47,7 @@
  *	#undef	_BSD_SIZE_T_
  *	#endif
  */
-#define	_BSD_CLOCK_T_	int			/* clock() */
+#define	_BSD_CLOCK_T_	__int64_t		/* clock(), times() */
 #define	_BSD_CLOCKID_T_	int			/* clock_gettime()... */
 #define	_BSD_FFLAGS_T_	__uint_least32_t	/* file flags */
 #define	_BSD_MBSTATE_T_	__mbstate_t		/* mbstate_t */
@@ -101,17 +101,11 @@
  */
 
 /*
- * Frequencies of the clock ticks reported by clock() and times().  They
- * are the same as stathz for bogus historical reasons.  They should be
- * 1e6 because clock() and times() are implemented using getrusage() and
- * there is no good reason why they should be less accurate.  There is
- * the bad reason that (broken) programs might not like clock_t or
- * CLOCKS_PER_SEC being ``double'' (``unsigned long'' is not large enough
- * to hold the required 24 hours worth of ticks if the frequency is
- * 1000000ul, and ``unsigned long long'' would be nonstandard).
+ * Frequencies of the clock ticks reported by clock() and times().
+ * POSIX 2001 requires CLOCKS_PER_SEC to be 1e6.
  */
-#define	_BSD_CLK_TCK_		100
-#define	_BSD_CLOCKS_PER_SEC_	100
+#define	_BSD_CLK_TCK_		1000000
+#define	_BSD_CLOCKS_PER_SEC_	1000000
 
 /*
  * We define this here since both <stddef.h> and <sys/types.h> needs it.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-standards" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020528191650.A8322>