Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Sep 2006 01:39:22 +0900
From:      Norikatsu Shigemura <nork@FreeBSD.org>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/102793: top(1): display feature of current CPU frequency
Message-ID:  <200609021640.k82GeINE061081@freefall.freebsd.org>
Resent-Message-ID: <200609021640.k82GeINE061081@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         102793
>Category:       bin
>Synopsis:       top(1): display feature of current CPU frequency
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Sep 02 16:40:18 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Norikatsu Shigemura
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
Personal
>Environment:
System: FreeBSD melfina.ninth-nine.com 6.1-STABLE FreeBSD 6.1-STABLE #4: Sat Sep 2 16:14:54 JST 2006 nork@melfina.ninth-nine.com:/usr/obj/usr/src/sys/MELFINA i386
>Description:
	The recent CPUs can change the operating frequency.  The feature
	makes CPUs for servers workable.  So I want to see relation of
	process status (CPU usage) and CPU current frequency using powerd(8)
	on the fly.

>How-To-Repeat:
	We can get CPU frequency by only sysctl on CUI.
	$ sysctl dev.cpu.0.freq
	If you can use GNOME, we can get CPU frequency by
	cpufreq-selector on GUI.
>Fix:
	I confirmed following environment:
	1. Intel Tualatin Core (PentiumIII-S): no display
	   It has no dev.cpu.?.freq.
	2. Intel Dothan Core (Pentium-M): works
	   It has one dev.cpu.?.freq.
	3. Intel Nocona Core (Xeon): works
	   It has one dev.cpu.?.freq.

	I don't run patched top(1), I know that following environment
	will works:

	4. Intel Yonah Core(Core Duo): will works
	   It has one dev.cpu.?.freq.

	I make two patches for 7-current and 6-stable.
	Please apply following patches.

	These patches are following state:
	No objection: hackers

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 -0000	1.77
+++ machine.c	26 Aug 2006 08:41:29 -0000
@@ -58,6 +58,8 @@
 extern struct process_select ps;
 extern char* printable(char *);
 static int smpmode;
+static int ncpu;
+#define	NCPU	2		/* 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 @@
 		}
 	}
 
+	/* 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.74.2.1
diff -u -r1.74.2.1 machine.c
--- machine.c	1 Sep 2006 18:12:10 -0000	1.74.2.1
+++ machine.c	2 Sep 2006 16:28:59 -0000
@@ -61,6 +61,8 @@
 extern char* printable(char *);
 int swapmode(int *retavail, int *retfree);
 static int smpmode;
+static int ncpu;
+#define	NCPU	2		/* 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);
@@ -630,6 +639,17 @@
 		}
 	}
 
+	/* 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);
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609021640.k82GeINE061081>