mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-16 23:57:54 +01:00
Fix a bug under time's "-l" option. The values reported for average
shared memory size, average unshared data size, and average unshared stack size were too high by a factor of 128/100, because the program used a hard-coded hz value of 100. The correct value is the frequency of the statistics clock, currently 128. The program now uses sysctl to get the stathz value from the kernel. Discussed with: bde@freebsd.org (Bruce Evans)
This commit is contained in:
parent
edd84a267a
commit
f0850246bb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=17351
@ -45,8 +45,13 @@ static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93";
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static int getstathz __P((void));
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
@ -102,7 +107,7 @@ main(argc, argv)
|
||||
fprintf(stderr, "%9ld.%02ld sys\n",
|
||||
ru.ru_stime.tv_sec, ru.ru_stime.tv_usec/10000);
|
||||
if (lflag) {
|
||||
int hz = 100; /* XXX */
|
||||
int hz = getstathz();
|
||||
u_long ticks;
|
||||
|
||||
ticks = hz * (ru.ru_utime.tv_sec + ru.ru_stime.tv_sec) +
|
||||
@ -146,3 +151,21 @@ main(argc, argv)
|
||||
}
|
||||
exit (status>>8);
|
||||
}
|
||||
|
||||
/*
|
||||
* Return the frequency of the kernel's statistics clock.
|
||||
*/
|
||||
static int
|
||||
getstathz()
|
||||
{
|
||||
struct clockinfo clockrate;
|
||||
int mib[2];
|
||||
size_t size;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_CLOCKRATE;
|
||||
size = sizeof clockrate;
|
||||
if (sysctl(mib, 2, &clockrate, &size, NULL, 0) == -1)
|
||||
err(1, "sysctl kern.clockrate");
|
||||
return clockrate.stathz;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user