Hello all.
As majority of current hardware use some form of dynamic CPU frequency
scaling and it is frequently controlled by ampd, wouldn't it be good to
have the current hw.cpuspeed displayed somewhere in the header lines of
systat(1) and top(1)? Just to know the scale for other performace figures
on the display.
Is it safe to plan for 9.999 GHz maximum CPU frequency?
In contrary to top(1), the header lines of systat(1) seem too crowded for
now, so no patch suggestion yet.
Couldn't "PAUSE" and references to remaining lines of the display
"(1-48 of 58)" be moved to the second line?
Regards,
David
Index: src/usr.bin/top/display.c
===================================================================
RCS file: /cvs/src/usr.bin/top/display.c,v
retrieving revision 1.40
diff -u -p -u -r1.40 display.c
--- src/usr.bin/top/display.c 23 Apr 2010 09:26:13 -0000 1.40
+++ src/usr.bin/top/display.c 23 Mar 2011 19:35:47 -0000
@@ -205,7 +205,7 @@ display_init(struct statics * statics)
}
void
-i_loadave(pid_t mpid, double *avenrun)
+i_loadave(pid_t mpid, double *avenrun, int cpuspeed)
{
if (screen_length > 1 || !smart_terminal) {
int i;
@@ -220,6 +220,8 @@ i_loadave(pid_t mpid, double *avenrun)
for (i = 0; i < 3; i++)
printwp("%c %5.2f", i == 0 ? ':' : ',', avenrun[i]);
+
+ printwp(" / %4d MHz", cpuspeed);
}
}
@@ -238,16 +240,25 @@ void
i_timeofday(time_t * tod)
{
static char buf[30];
+ int bufspace;
if (buf[0] == '\0')
gethostname(buf, sizeof(buf));
if (screen_length > 1 || !smart_terminal) {
if (smart_terminal) {
- move(0, screen_width - 8 - strlen(buf) - 1);
+ /* Load averages and space fill up 35 chars,
+ * cpu speed and space fill up 11 chars,
+ * space and clock fill up 9 chars.
+ */
+ bufspace = screen_width - 35 - 11 - 9 - strlen(buf);
+ if (bufspace < 0)
+ bufspace = 0;
+ move(0, screen_width - 8 - bufspace - 1);
} else {
if (fputs(" ", stdout) == EOF)
exit(1);
+ bufspace = 24;
}
#ifdef DEBUG
{
@@ -256,7 +267,7 @@ i_timeofday(time_t * tod)
addstrp(foo);
}
#endif
- printwp("%s %-8.8s", buf, &(ctime(tod)[11]));
+ printwp("%*s %-8.8s", bufspace, buf, &(ctime(tod)[11]));
putn();
}
}
Index: src/usr.bin/top/display.h
===================================================================
RCS file: /cvs/src/usr.bin/top/display.h,v
retrieving revision 1.11
diff -u -p -u -r1.11 display.h
--- src/usr.bin/top/display.h 22 Nov 2007 11:01:04 -0000 1.11
+++ src/usr.bin/top/display.h 23 Mar 2011 19:35:47 -0000
@@ -35,7 +35,7 @@
/* prototypes */
int display_resize(void);
-void i_loadave(int, double *);
+void i_loadave(int, double *, int);
void u_loadave(int, double *);
void i_timeofday(time_t *);
void i_procstates(int, int *);
Index: src/usr.bin/top/machine.c
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.c,v
retrieving revision 1.67
diff -u -p -u -r1.67 machine.c
--- src/usr.bin/top/machine.c 26 Apr 2010 00:30:58 -0000 1.67
+++ src/usr.bin/top/machine.c 23 Mar 2011 19:35:48 -0000
@@ -204,6 +204,8 @@ format_header(char *uname_field)
void
get_system_info(struct system_info *si)
{
+ static int cpuspeed_mib[] = {CTL_HW, HW_CPUSPEED};
+ int cpuspeed;
static int sysload_mib[] = {CTL_VM, VM_LOADAVG};
static int vmtotal_mib[] = {CTL_VM, VM_METER};
struct loadavg sysload;
@@ -239,6 +241,12 @@ get_system_info(struct system_info *si)
(void) percentages(CPUSTATES, cpu_states, cp_time[0],
cp_old[0], cp_diff[0]);
}
+
+ size = sizeof(sysload);
+ if (sysctl(cpuspeed_mib, 2, &cpuspeed, &size, NULL, 0) < 0)
+ si->cpuspeed = 0;
+ else
+ si->cpuspeed = cpuspeed;
size = sizeof(sysload);
if (sysctl(sysload_mib, 2, &sysload, &size, NULL, 0) < 0)
Index: src/usr.bin/top/machine.h
===================================================================
RCS file: /cvs/src/usr.bin/top/machine.h,v
retrieving revision 1.15
diff -u -p -u -r1.15 machine.h
--- src/usr.bin/top/machine.h 29 May 2007 00:56:56 -0000 1.15
+++ src/usr.bin/top/machine.h 23 Mar 2011 19:35:48 -0000
@@ -50,6 +50,7 @@ struct statics {
struct system_info {
pid_t last_pid;
+ int cpuspeed;
double load_avg[NUM_AVERAGES];
int p_total;
int p_active; /* number of procs considered
Index: src/usr.bin/top/top.1
===================================================================
RCS file: /cvs/src/usr.bin/top/top.1,v
retrieving revision 1.57
diff -u -p -u -r1.57 top.1
--- src/usr.bin/top/top.1 10 Aug 2010 20:34:16 -0000 1.57
+++ src/usr.bin/top/top.1 23 Mar 2011 19:35:48 -0000
@@ -370,6 +370,7 @@ about the state of the system, including
.\" the last process ID assigned to a process,
.\" (on most systems),
the three load average numbers,
+the current CPU frequency,
the hostname,
the current time,
the number of existing processes,
Index: src/usr.bin/top/top.c
===================================================================
RCS file: /cvs/src/usr.bin/top/top.c,v
retrieving revision 1.75
diff -u -p -u -r1.75 top.c
--- src/usr.bin/top/top.c 24 Apr 2010 22:02:14 -0000 1.75
+++ src/usr.bin/top/top.c 23 Mar 2011 19:35:48 -0000
@@ -434,10 +434,10 @@ restart:
processes = get_process_info(&system_info, &ps,
proc_compares[order_index]);
- /* display the load averages */
- i_loadave(system_info.last_pid, system_info.load_avg);
+ /* display the load averages and current cpu speed */
+ i_loadave(system_info.last_pid, system_info.load_avg,
system_info.cpuspeed);
- /* display the current time */
+ /* display the hostname and current time */
/* this method of getting the time SHOULD be fairly portable */
time(&curr_time);
i_timeofday(&curr_time);