Subject: sysconf _SC_CLK_TCK bug?
To: None <tech-userlevel@netbsd.org>
From: Perry E. Metzger <perry@wasabisystems.com>
List: tech-userlevel
Date: 06/16/2002 18:26:58
It appears that sysconf(_SC_CLK_TCK) has a bug -- or at least that the
implementation is, er, "deficient".
As one can readily see from the standards document,
http://www.opengroup.org/onlinepubs/007904975/functions/sysconf.html
the call should be returning the number of clock ticks per second on
the host, but it is instead returning a constant CLK_TCK which is
defined in time.h as "100", which is certainly not The Right Thing,
especially when HZ is not 100.
I propose the following patch, which I have tested, to bring us into
conformance. I would also like to know if the CLK_TCK #define in
time.h should be removed since it does something horribly spurious.
----------------------------------------------------------------------
Index: sysconf.c
===================================================================
RCS file: /cvsroot/basesrc/lib/libc/gen/sysconf.c,v
retrieving revision 1.14
diff -u -r1.14 sysconf.c
--- sysconf.c 2002/01/31 00:32:47 1.14
+++ sysconf.c 2002/06/16 22:19:24
@@ -78,6 +78,7 @@
struct rlimit rl;
size_t len;
int mib[2], value;
+ struct clockinfo tmpclock;
len = sizeof(value);
@@ -90,7 +91,15 @@
case _SC_CHILD_MAX:
return (getrlimit(RLIMIT_NPROC, &rl) ? -1 : (long)rl.rlim_cur);
case _SC_CLK_TCK:
- return (CLK_TCK);
+ /*
+ * Has to be handled specially because it returns a
+ * struct clockinfo instead of an integer.
+ */
+ mib[0] = CTL_KERN;
+ mib[1] = KERN_CLOCKRATE;
+ len = sizeof(struct clockinfo);
+ return(sysctl(mib, 2, &tmpclock, &len, NULL, 0) == -1 ?
+ -1 : tmpclock.hz);
case _SC_JOB_CONTROL:
mib[0] = CTL_KERN;
mib[1] = KERN_JOB_CONTROL;
----------------------------------------------------------------------
--
Perry E. Metzger perry@wasabisystems.com
--
NetBSD: The right OS for your embedded design. http://www.wasabisystems.com/