Re: times(2) no sys_call ??

Olaf Klein (oklein@smallo.ruhr.de)
Sat, 11 May 1996 18:44:41 +0200 (MET DST)


Hello,

> Harald> for DEC Unix times() again is implemeted using
> Harald> getrusage/gettimeofday (thanks to Linux strace ;-) but here
> Harald> CLK_TCK is 60 :-(
> This seems the "standard" value. It's the same value that glibc uses.
> I don't think there is anything in POSIX requires CLK_TCK to equal HZ.
> And since OSF/1 uses 60 as well, it's probably better to stick with
> that value.
> IMHO: avoid times() if you can...
I have the old ssba benchmark suite and need it to run on linux-alpha,
there I have also a problem with times:

#include <sys/signal.h>
#include <sys/time.h>
#include <sys/resource.h>
#define DELAY 30
long t1,ticks,hz;
struct tms ts;
struct rlimit rlp;
int sigxcpu();

main()
{
signal(SIGXCPU, sigxcpu);
getrlimit(RLIMIT_CPU, &rlp);
rlp.rlim_cur = DELAY;
setrlimit(RLIMIT_CPU, &rlp);
times(&ts);
t1 = ts.tms_utime;
for (;;) ;
}
sigxcpu()
{
times(&ts);
ticks = ts.tms_utime - t1;
hz = (ticks/DELAY + 5)/10 * 10;
printf("%ld \/\* ticks = %ld (setrlimit method) \*\/\n",
hz, ticks);
exit(0);
}

And the result is always 0. On a i386-Linux system, I get the correct answer
100 (same as linux/include/asm-i386/param.h - why is it 1024 in
linux/include/asm-alpha/param.h?).

The second method in the suite uses sleep(), but gives me different results
every time:

/* same as above but main */
main()
{
t1 = times(&ts);
t1 = times(&ts);
t1 = times(&ts);
t1 = times(&ts);
sleep( DELAY );
ticks = (times(&ts)-t1+DELAY/2)/DELAY;
hz = (ticks+5)/10 * 10;
printf("%ld\/\* ticks = %ld (times method) \*\/\n", hz, ticks);
}

I looked into the linux source and found times() to return only
current->utime, where is it set, and why are the results on alpha so
different to i386 machines?

Thanks for your help.

Bye, Olaf