From aae3d318d4523d26a77f15cc2e7b6e01e9c0c336 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Fri, 7 Oct 2011 10:08:42 +1100 Subject: [PATCH 1/3] Elf note AT_CLKTCK is only found on Linux Suppresses a message about elf notes not found on non-Linux systems. kFreeBSD systems, for one, don't have this so the message appears every time you run a procps program otherwise. Based upon Debian patch sysinfo_elfnote by Petr Salinger Bug-Debian: http://bugs.debian.org/378157 --- proc/sysinfo.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/proc/sysinfo.c b/proc/sysinfo.c index 5e224f12..1c7c2798 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -253,11 +253,13 @@ static void init_libproc(void){ cpuinfo(); +#ifdef __linux__ if(linux_version_code > LINUX_VERSION(2, 4, 0)){ Hertz = find_elf_note(AT_CLKTCK); if(Hertz!=NOTE_NOT_FOUND) return; fputs("2.4+ kernel w/o ELF notes? -- report this\n", stderr); } +#endif /* __linux __ */ old_Hertz_hack(); } From a5750100a026a85cbc51d32f91c40205746c737b Mon Sep 17 00:00:00 2001 From: Craig Small Date: Fri, 7 Oct 2011 10:22:24 +1100 Subject: [PATCH 2/3] Fix Hertz calculation for FreeBSD FreeBSD has no good way of finding the Hertz value. ELF notes don't work, you can't find it in a function and even asm/params.h does not have it. Lucky for us, it is always 100. Based upon Debian patch patch sysinfo_kfreebsd_hertz by Petr Salinger Bug-Debian: http://bugs.debian.org/460331 Caution, 460331 has lots of overlapping bugs all around the Hertz problem across many arches. --- proc/sysinfo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/proc/sysinfo.c b/proc/sysinfo.c index 1c7c2798..85b28b7c 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -260,6 +260,14 @@ static void init_libproc(void){ fputs("2.4+ kernel w/o ELF notes? -- report this\n", stderr); } #endif /* __linux __ */ +#if defined(__FreeBSD_kernel__) || defined(__FreeBSD__) + /* On FreeBSD the Hertz hack is unrelaible, there is no ELF note and + * Hertz isn't defined in asm/params.h + * See Debian Bug #460331 + */ + Hertz = 100; + return; +#endif /* __FreeBSD__ */ old_Hertz_hack(); } From 13ce6ebdf0acd9fc3b26c48497ef2c0e8b99d074 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Fri, 7 Oct 2011 14:35:16 +1100 Subject: [PATCH 3/3] Use 7 cpu numbers not 4 for Hertz Hack For the small number of devices that we cannot get Hertz out of ELF notes but the cpu numbers make sense (ie not kFreeBSD) there is a hack by using the CPU numbers. The problem is there was 4 numbers, now there are 7. This fixes the hack by adding all 7 to get a more correct number. This is from Debian patch sysinfo_7_numbers Bug-Debian: http://bugs.debian.org/460331 --- proc/sysinfo.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/proc/sysinfo.c b/proc/sysinfo.c index 85b28b7c..6396db58 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -153,7 +153,7 @@ unsigned long getbtime(void) { unsigned long long Hertz; static void old_Hertz_hack(void){ - unsigned long long user_j, nice_j, sys_j, other_j; /* jiffies (clock ticks) */ + unsigned long long user_j, nice_j, sys_j, other_j, wait_j, hirq_j, sirq_j, stol_j; /* jiffies (clock ticks) */ double up_1, up_2, seconds; unsigned long long jiffies; unsigned h; @@ -167,18 +167,19 @@ static void old_Hertz_hack(void){ } #endif + wait_j = hirq_j = sirq_j = stol_j = 0; savelocale = setlocale(LC_NUMERIC, NULL); setlocale(LC_NUMERIC, "C"); do{ FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_1); /* uptime(&up_1, NULL); */ FILE_TO_BUF(STAT_FILE,stat_fd); - sscanf(buf, "cpu %Lu %Lu %Lu %Lu", &user_j, &nice_j, &sys_j, &other_j); + sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", &user_j, &nice_j, &sys_j, &other_j, &wait_j, &hirq_j, &sirq_j, &stol_j); FILE_TO_BUF(UPTIME_FILE,uptime_fd); sscanf(buf, "%lf", &up_2); /* uptime(&up_2, NULL); */ } while((long long)( (up_2-up_1)*1000.0/up_1 )); /* want under 0.1% error */ setlocale(LC_NUMERIC, savelocale); - jiffies = user_j + nice_j + sys_j + other_j; + jiffies = user_j + nice_j + sys_j + other_j + wait_j + hirq_j + sirq_j + stol_j ; seconds = (up_1 + up_2) / 2; h = (unsigned)( (double)jiffies/seconds/smp_num_cpus ); /* actual values used by 2.4 kernels: 32 64 100 128 1000 1024 1200 */