From 4c1ac396780d2dd3c320e828c6a86fbdb81afef0 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Thu, 11 Dec 2008 14:27:18 +0000 Subject: [PATCH] Changes so the HZ constant isn't needed any more. --- commands/ibm/autopart.c | 9 ++++++++- commands/ps/ps.c | 9 ++++++++- commands/simple/tcpstat.c | 15 ++++++++++----- commands/simple/top.c | 9 +++++++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/commands/ibm/autopart.c b/commands/ibm/autopart.c index dca991a5d..9d974c2f7 100755 --- a/commands/ibm/autopart.c +++ b/commands/ibm/autopart.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include #include #include @@ -1582,6 +1584,7 @@ void m_read(int ev, int *biosdrive) { int i, mode, n, v; struct part_entry *pe; + u32_t system_hz; if (ev != 'r' || device >= 0) return; @@ -1594,7 +1597,11 @@ void m_read(int ev, int *biosdrive) return; } - v = 2*HZ; + if(getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz) < 0) { + fprintf(stderr, "autopart: system hz not found\n"); + exit(1); + } + v = 2*system_hz; ioctl(device, DIOCTIMEOUT, &v); memset(bootblock, 0, sizeof(bootblock)); diff --git a/commands/ps/ps.c b/commands/ps/ps.c index fa82bdd33..7c81d9dd8 100644 --- a/commands/ps/ps.c +++ b/commands/ps/ps.c @@ -54,6 +54,8 @@ */ #include +#include +#include #include #include #include @@ -295,6 +297,11 @@ char *argv[]; char cpu[sizeof(clock_t) * 3 + 1 + 2]; struct kinfo kinfo; int s; + u32_t system_hz; + + if(getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz) < 0) { + exit(1); + } (void) signal(SIGSEGV, disaster); /* catch a common crash */ @@ -385,7 +392,7 @@ char *argv[]; sprintf(pid, "%d", buf.ps_pid); } - ustime = (buf.ps_utime + buf.ps_stime) / HZ; + ustime = (buf.ps_utime + buf.ps_stime) / system_hz; if (ustime < 60 * 60) { sprintf(cpu, "%2lu:%02lu", ustime / 60, ustime % 60); } else diff --git a/commands/simple/tcpstat.c b/commands/simple/tcpstat.c index 248ba706b..6fa78da65 100644 --- a/commands/simple/tcpstat.c +++ b/commands/simple/tcpstat.c @@ -23,6 +23,8 @@ Created: June 1995 by Philip Homburg #include #include #include +#include +#include #include #include @@ -31,6 +33,7 @@ Created: June 1995 by Philip Homburg #include #include +u32_t system_hz; char *prog_name; tcp_conn_t tcp_conn_table[TCP_CONN_NR]; char values[2 * sizeof(tcp_conn_table) + 1]; @@ -50,6 +53,8 @@ int main(int argc, char*argv[]) int fl; int a_flag, n_flag, v_flag; + getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz); + (prog_name=strrchr(argv[0], '/')) ? prog_name++ : (prog_name=argv[0]); a_flag= 0; @@ -219,7 +224,7 @@ void print_conn(int i, clock_t now) if (tcp_conn->tc_senddis >= now) { printf("(time wait %ld s)", - (tcp_conn->tc_senddis-now)/HZ); + (tcp_conn->tc_senddis-now)/system_hz); } no_verbose= 1; break; @@ -263,9 +268,9 @@ void print_conn(int i, clock_t now) tcp_conn->tc_max_mtu-IP_TCP_MIN_HDR_SIZE, tcp_conn->tc_mtu, (tcp_conn->tc_flags & TCF_PMTU) ? "" : " (no PMTU)", - rtt/(HZ+0.0), - artt/(HZ+0.0)/TCP_RTT_SCALE, TCP_DRTT_MULT, - drtt/(HZ+0.0)/TCP_RTT_SCALE); + rtt/(system_hz+0.0), + artt/(system_hz+0.0)/TCP_RTT_SCALE, TCP_DRTT_MULT, + drtt/(system_hz+0.0)/TCP_RTT_SCALE); flags= tcp_conn->tc_flags; printf("\tflags:"); if (!flags) @@ -319,7 +324,7 @@ void print_conn(int i, clock_t now) printf("\n"); printf("\ttimer: ref %d, time %f, active %d\n", tcp_conn->tc_transmit_timer.tim_ref, - (0.0+tcp_conn->tc_transmit_timer.tim_time-now)/HZ, + (0.0+tcp_conn->tc_transmit_timer.tim_time-now)/system_hz, tcp_conn->tc_transmit_timer.tim_active); } diff --git a/commands/simple/top.c b/commands/simple/top.c index 4679f4f7f..0cb4a088a 100644 --- a/commands/simple/top.c +++ b/commands/simple/top.c @@ -26,6 +26,8 @@ #include #include +#include +#include #include #include #include @@ -35,6 +37,8 @@ #include "../../kernel/const.h" #include "../../kernel/proc.h" +u32_t system_hz; + #define TC_BUFFER 1024 /* Size of termcap(3) buffer */ #define TC_STRINGS 200 /* Enough room for cm,cl,so,se */ @@ -197,7 +201,7 @@ void print_procs(int maxlines, ((pr->p_memmap[T].mem_len + pr->p_memmap[D].mem_len) << CLICK_SHIFT)/1024); printf("%6s", pr->p_rts_flags ? "" : "RUN"); - printf(" %3d:%02d ", (ticks/HZ/60), (ticks/HZ)%60); + printf(" %3d:%02d ", (ticks/system_hz/60), (ticks/system_hz)%60); printf("%6.2f%% %s\n", 100.0*tick_procs[p].ticks/dt, name); @@ -306,6 +310,8 @@ int main(int argc, char *argv[]) { int r, c, s = 0, orig; + getsysinfo_up(PM_PROC_NR, SIU_SYSTEMHZ, sizeof(system_hz), &system_hz); + init(&r); while((c=getopt(argc, argv, "s:")) != EOF) { @@ -357,4 +363,3 @@ int main(int argc, char *argv[]) return 0; } -int sys_hz() { return 50; } -- 2.44.0