Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 4814 - CLOCKS_PER_SEC bug?
Summary: CLOCKS_PER_SEC bug?
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Brandon Low (RETIRED)
URL: http://fireserver.ath.cx/gentoo/msg28...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-07-10 11:54 UTC by Grant Goodyear (RETIRED)
Modified: 2003-02-04 19:42 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
hz.diff; kernel patch to pass the right value on to glibc to get times() and clock() working right (hz.diff,406 bytes, patch)
2002-09-25 18:39 UTC, Toby Dickenson
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Grant Goodyear (RETIRED) gentoo-dev 2002-07-10 11:54:30 UTC
Taken from the -user post in the URL.  In the printf line "doubl" should
be "double" and CLOCK should be CLOCKS, I believe.

Hllo,

recently I reported a problem regarding lame and calculated cpu time. After
reading a  note in the 2.5.25 release notes I wondered if the gentoo kernel
could have a problem with clock_t and CLOCKS_PER_SEC, and indeed it has. If
I write the following simple program:

---
#include <time.h>
int main()
{
   clock_t c;
   double d;
   for (d = 0; d < (double)10000000;d++)
   {
      test(d);
   }
   c = clock();
   printf("%f\n",((doubl)c)/CLOCK_PER_SEC);
}
int test(double d)
{
   return 0;
}

It will report that the program took 2.81 secs of cpu time on my athlon
2000xp+, where in reallity it takes 0.281 seconds.

It appears that clock() on gentoo returns a number ten time as high as my
redhat, but clocks_per_sec has not been adjusted.


Henk,
Comment 1 Michael Cohen (RETIRED) gentoo-dev 2002-07-16 22:16:34 UTC
looking into it =)
Comment 2 Michael Cohen (RETIRED) gentoo-dev 2002-09-02 20:59:42 UTC
HZ problem... I think
Comment 3 Toby Dickenson 2002-09-25 18:39:47 UTC
Created attachment 4191 [details, diff]
hz.diff; kernel patch to pass the right value on to glibc to get times() and clock() working right

Yes, this is a kernel bug relating to changing HZ from the default of 100. The
kernel is not correctly passing the new value on to glibc via ELF.  This patch
works for me.

This patch changes the i386 definition of CLOCKS_PER_SEC to be the same as
almost every other platform, so I consider this low risk.
Comment 4 Toby Dickenson 2002-10-13 07:29:27 UTC
Im suprised to have no followups to this after 2 weeks.... Is anyone tracking 
this? 
Comment 5 Pierre-Henri Jondot 2002-10-14 23:51:31 UTC
Please include this patch on the new kernels...

I did see the error in the lame output too, which doesn't hurt much indeed...
But the error is apparent too using numerous benches (for example pari-gp,
root...) in which my gentoo system is measured as horribly slow...
Comment 6 Brandon Low (RETIRED) gentoo-dev 2002-10-15 17:04:31 UTC
Hmm... well what has been done is to change the default value of the HZ to 100 
in the current series of gentoo kernels, because there may be other issues than 
this brought up by using other values, I'll go ahead and add this patch to the 
current Jiffies patch though for my development sources (lolo-sources-
2.4.20.1_pre1 should be out sometime in the next few days with all sorts of 
goodies.
Comment 7 Brandon Low (RETIRED) gentoo-dev 2002-10-15 17:10:09 UTC
I like unified diffs, and therefore I want things in diff -u from now on.  
Thanks a lot though, if this works as expected we can go ahead and go back to 
defaulting to 1000 for the jiffies.  
Comment 8 Troy Dack 2002-10-16 00:16:08 UTC
This might be of interest:

Robert Love Explains Variable HZ (including patch)
http://kerneltrap.org/node.php?id=464
Comment 9 Brandon Low (RETIRED) gentoo-dev 2002-10-16 00:43:15 UTC
**embarassed... I'm the one who's supposed to watch this stuff as it shoots 
past my eyes on LKML...

Thanks... I'll use RML's patch on the next gentoo kernel.
Comment 10 Brandon Low (RETIRED) gentoo-dev 2002-10-17 14:06:37 UTC
patch in latest lolo-sources, please test and have a party.
Comment 11 Martin Schlemmer (RETIRED) gentoo-dev 2002-12-03 06:16:38 UTC
Can we close this ?
Comment 12 Brandon Low (RETIRED) gentoo-dev 2003-01-09 14:41:19 UTC
ok, so in gentoo-sources < 2.4.20 it is important to keep HZ set to 100, closing
bug.