Re: [RFC] prototype of top(1)'s CPU current frequency display

2006-08-26 Thread Norikatsu Shigemura
On Sun, 20 Aug 2006 17:24:35 +0900
Norikatsu Shigemura <[EMAIL PROTECTED]> wrote:
>   1. assume only 1 CPU.
>   2. assume dev.cpu.0.freq is always exists.
>   3. display position is good?

I modified 1 and 2.  Please check attached diff.
I couldn't fix 3 issue.  So I assumed support max 2CPUs.

I confirmed following environments.

- - PentiumIII-S dual - - - - - - - - - - - - -
dev.cpu.0.%desc: ACPI CPU
dev.cpu.0.%driver: cpu
dev.cpu.0.%location: handle=\_PR_.CPU0
dev.cpu.0.%pnpinfo: _HID=none _UID=0
dev.cpu.0.%parent: acpi0
dev.cpu.1.%desc: ACPI CPU
dev.cpu.1.%driver: cpu
dev.cpu.1.%location: handle=\_PR_.CPU1
dev.cpu.1.%pnpinfo: _HID=none _UID=0
dev.cpu.1.%parent: acpi0
- - PentiumIII-S dual - - - - - - - - - - - - -

- - Pentium-M Dothan - - - - - - - - - - - - - -
dev.cpu.0.%desc: ACPI CPU
dev.cpu.0.%driver: cpu
dev.cpu.0.%location: handle=\_PR_.CPU0
dev.cpu.0.%pnpinfo: _HID=none _UID=0
dev.cpu.0.%parent: acpi0
dev.cpu.0.freq: 1200
dev.cpu.0.freq_levels: 1200/-1 1100/-1 1000/-1 900/-1 800/-1 700/-1 600/-1 
525/-1 450/-1 375/-1 300/-1 225/-1 150/-1 75/-1
- - Pentium-M Dothan - - - - - - - - - - - - - -

- - Xeon 2.8GHz - - - - - - - - - - - - - - - -
dev.cpu.0.%desc: ACPI CPU
dev.cpu.0.%driver: cpu
dev.cpu.0.%location: handle=\_PR_.CPU0
dev.cpu.0.%pnpinfo: _HID=none _UID=0
dev.cpu.0.%parent: acpi0
dev.cpu.0.freq: 2807
dev.cpu.0.freq_levels: 2807/-1 2456/-1 2105/-1 1754/-1 1403/-1 1052/-1 701/-1 
350/-1
- - Xeon 2.8GHz - - - - - - - - - - - - - - - -
Index: machine.c
===
RCS file: /home/ncvs/src/usr.bin/top/machine.c,v
retrieving revision 1.74
diff -u -r1.74 machine.c
--- machine.c   18 May 2005 13:42:51 -  1.74
+++ machine.c   26 Aug 2006 08:41:50 -
@@ -61,6 +61,8 @@
 extern char* printable(char *);
 int swapmode(int *retavail, int *retfree);
 static int smpmode;
+static int ncpu;
+#defineNCPU2   /* support max 2cpu to display 
frequency */
 enum displaymodes displaymode;
 static int namelength = 8;
 static int cmdlengthdelta;
@@ -153,10 +155,10 @@
 
 /* these are for detailing the process states */
 
-int process_states[8];
+int process_states[8+NCPU];
 char *procstatenames[] = {
"", " starting, ", " running, ", " sleeping, ", " stopped, ",
-   " zombie, ", " waiting, ", " lock, ",
+   " zombie, ", " waiting, ", " lock, ", " MHz, ", " MHz, ",
NULL
 };
 
@@ -235,6 +237,13 @@
modelen != sizeof(smpmode))
smpmode = 0;
 
+   for (ncpu = -1; ncpu < NCPU; ncpu++) {
+   char buf[32];
+   snprintf(buf, sizeof buf-1, "dev.cpu.%d.freq", ncpu+1);
+   if (sysctlbyname(buf, NULL, NULL, NULL, 0) < 0)
+   break;
+   }
+
while ((pw = getpwent()) != NULL) {
if (strlen(pw->pw_name) > namelength)
namelength = strlen(pw->pw_name);
@@ -629,6 +638,16 @@
}
}
 
+   /* CPU current frequency */
+   if (ncpu != -1) {
+   int j;
+   for(j = 0; j <= ncpu; j++) {
+   char buf[32];
+   snprintf(buf, sizeof buf-1, "dev.cpu.%d.freq", j);
+   GETSYSCTL(buf, process_states[j+8]);
+   }
+   }
+
/* if requested, sort the "interesting" processes */
if (compare != NULL)
qsort(pref, active_procs, sizeof(*pref), compare);
Index: machine.c
===
RCS file: /home/ncvs/src/usr.bin/top/machine.c,v
retrieving revision 1.77
diff -u -r1.77 machine.c
--- machine.c   11 Jun 2006 19:18:39 -  1.77
+++ machine.c   26 Aug 2006 08:41:29 -
@@ -58,6 +58,8 @@
 extern struct process_select ps;
 extern char* printable(char *);
 static int smpmode;
+static int ncpu;
+#defineNCPU2   /* support max 2cpu to display 
frequency */
 enum displaymodes displaymode;
 static int namelength = 8;
 static int cmdlengthdelta;
@@ -147,10 +149,10 @@
 
 /* these are for detailing the process states */
 
-int process_states[8];
+int process_states[8+NCPU];
 char *procstatenames[] = {
"", " starting, ", " running, ", " sleeping, ", " stopped, ",
-   " zombie, ", " waiting, ", " lock, ",
+   " zombie, ", " waiting, ", " lock, ", " MHz, ", " MHz, ",
NULL
 };
 
@@ -234,6 +236,13 @@
modelen != sizeof(smpmode))
smpmode = 0;
 
+   for (ncpu = -1; ncpu < NCPU; ncpu++) {
+   char buf[32];
+   snprintf(buf, sizeof buf-1, "dev.cpu.%d.freq", ncpu+1);
+   if (sysctlbyname(buf, NULL, NULL, NULL, 0) < 0)
+   break;
+   }
+
while ((pw = getpwent()) != NULL) {
if (strlen(pw->pw_name) > namelength)
namelength = strlen(pw->pw_name);
@@ -632,6 +641,16 @@
}
}
 
+

[RFC] prototype of top(1)'s CPU current frequency display

2006-08-20 Thread Norikatsu Shigemura
I want to see CPU current frequency on top(1), because I want
to see relation of process status (CPU usage) and cpu current
frequency using powerd(8) on the fly.  In recently, many CPUs
for servers like Xeon support frequency changing like Speed
Step Technology.  I run powerd(8) on these servers.  So I
should know performance issue, whichever program performance
or server performance.  I wrote a little usability patch.
But I don't think that my code is not good:-(.  So please
improve my code.

Wellknown problem.
1. assume only 1 CPU.
2. assume dev.cpu.0.freq is always exists.
3. display position is good?

--- usr.bin/top/machine.c.orig  Wed May 18 22:42:51 2005
+++ usr.bin/top/machine.c   Sun Aug 20 16:41:59 2006
@@ -153,10 +153,10 @@
 
 /* these are for detailing the process states */
 
-int process_states[8];
+int process_states[9];
 char *procstatenames[] = {
"", " starting, ", " running, ", " sleeping, ", " stopped, ",
-   " zombie, ", " waiting, ", " lock, ",
+   " zombie, ", " waiting, ", " lock, ", " MHz, ",
NULL
 };
 
@@ -628,6 +628,9 @@
prev_pp->ki_pctcpu += pp->ki_pctcpu;
}
}
+
+   /* CPU current frequency */
+   GETSYSCTL("dev.cpu.0.freq", process_states[8]);
 
/* if requested, sort the "interesting" processes */
if (compare != NULL)
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"