[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
__get_clockfreq() in glibc-2.2.3pre3
From: |
Van Okamura |
Subject: |
__get_clockfreq() in glibc-2.2.3pre3 |
Date: |
Tue, 17 Apr 2001 21:28:36 -0700 (PDT) |
In glibc-2.2.3pre3 on Linux, when clock_gettime() is called using
the cpu clock from clock_getcpuclockid(), the result can sometimes
be off by a factor of 1000. The problem is that __get_clockfreq()
doesn't handle the case when the MHz from /proc/cpuinfo is reported
with less than 9 digits. On my 2.4.0 and 2.4.3 systems,
the /proc/cpuinfo "cpu MHz" line looks like this:
cpu MHz : 863.880
The resulting tst-clock.out looks like this:
clock 0: resolution = 0.010000000 secs
clock 0: time = 987117137.019621000 secs
clock 0: time = 987117137.527212000 secs
clock 0: time = 987117138.037217000 secs
clock 0: time = 987117138.547226000 secs
clock 0: time = 987117139.057207000 secs
clock 0: time = 987117139.567212000 secs
clock 0: time = 987117140.077207000 secs
clock 0: time = 987117140.587210000 secs
clock 0: time = 987117141.097223000 secs
clock 0: time = 987117141.607210000 secs
clock 2: resolution = 0.000004297 secs
clock 2: time = 610203451.212760287 secs
clock 2: time = 610203960.674266680 secs
clock 2: time = 610204470.660161169 secs
clock 2: time = 610204980.659297303 secs
clock 2: time = 610205490.665653808 secs
clock 2: time = 610206000.655136993 secs
clock 2: time = 610206510.656018050 secs
clock 2: time = 610207020.659890405 secs
clock 2: time = 610207530.645028473 secs
clock 2: time = 610208040.647529816 secs
For clock 2, time is incrementing by about 500 per .5 second
because the frequency is 1000 times less than what it should be.
The included patch handles this case.
Van
diff -Naur glibc-2.2.3/ChangeLog glibc-2.2.3pre3-mod/ChangeLog
--- glibc-2.2.3/ChangeLog Thu Apr 12 22:58:39 2001
+++ glibc-2.2.3pre3-mod/ChangeLog Tue Apr 17 20:36:38 2001
@@ -1,3 +1,8 @@
+2001-04-17 Van Okamura <address@hidden>
+
+ * sysdeps/unix/sysv/linux/i386/get_clockfreq.c: Handle case
+ where MHz is reported with less than 9 digits.
+
2001-04-12 Ulrich Drepper <address@hidden>
* sysdeps/ia64/Dist: Add elf/entry.h.
diff -Naur glibc-2.2.3/sysdeps/unix/sysv/linux/i386/get_clockfreq.c
glibc-2.2.3pre3-mod/sysdeps/unix/sysv/linux/i386/get_clockfreq.c
--- glibc-2.2.3/sysdeps/unix/sysv/linux/i386/get_clockfreq.c Sat Jan 6
20:35:41 2001
+++ glibc-2.2.3pre3-mod/sysdeps/unix/sysv/linux/i386/get_clockfreq.c Tue Apr
17 20:34:18 2001
@@ -45,6 +45,7 @@
to a size of 4096 bytes. */
char buf[4096];
ssize_t n;
+ int base;
n = read (fd, buf, sizeof buf);
if (__builtin_expect (n, 1) > 0)
@@ -59,7 +60,7 @@
while (mhz < endp && (*mhz < '0' || *mhz > '9') && *mhz != '\n')
++mhz;
- while (mhz < endp && *mhz != '\n')
+ while (mhz < endp && *mhz != '\n' && *mhz != '.')
{
if (*mhz >= '0' && *mhz <= '9')
{
@@ -69,6 +70,22 @@
++mhz;
}
+ if (mhz < endp && *mhz == '.')
+ {
+ result *= 1000000;
+ base = 100000;
+ ++mhz;
+
+ while (mhz < endp && *mhz != '\n')
+ {
+ if (*mhz >= '0' && *mhz <= '9')
+ {
+ result += (*mhz - '0') * base;
+ base /= 10;
+ }
+ ++mhz;
+ }
+ }
}
}
- __get_clockfreq() in glibc-2.2.3pre3,
Van Okamura <=