From owner-freebsd-bugs@FreeBSD.ORG Sat Sep 2 16:40:19 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E1B2616A4E1 for ; Sat, 2 Sep 2006 16:40:19 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id BAB6543D4C for ; Sat, 2 Sep 2006 16:40:18 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k82GeIMt061082 for ; Sat, 2 Sep 2006 16:40:18 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k82GeINE061081; Sat, 2 Sep 2006 16:40:18 GMT (envelope-from gnats) Resent-Date: Sat, 2 Sep 2006 16:40:18 GMT Resent-Message-Id: <200609021640.k82GeINE061081@freefall.freebsd.org> Message-Id: <200609021640.k82GeINE061081@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Norikatsu Shigemura Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BA7DC16A4E1 for ; Sat, 2 Sep 2006 16:39:35 +0000 (UTC) (envelope-from nork@FreeBSD.org) Received: from sakura.ninth-nine.com (sakura.ninth-nine.com [219.127.74.120]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2B7E343D55 for ; Sat, 2 Sep 2006 16:39:31 +0000 (GMT) (envelope-from nork@FreeBSD.org) Received: from nadesico.ninth-nine.com (nadesico.ninth-nine.com [219.127.74.122]) by sakura.ninth-nine.com (8.13.6/8.13.6/NinthNine) with ESMTP id k82GdMH5019431 for ; Sun, 3 Sep 2006 01:39:24 +0900 (JST) (envelope-from Message-Id: <20060903013922.04fbe6c5.nork@FreeBSD.org> Date: Sun, 3 Sep 2006 01:39:22 +0900 From: Norikatsu Shigemura To: FreeBSD-gnats-submit@FreeBSD.org Cc: Subject: bin/102793: top(1): display feature of current CPU frequency X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Sep 2006 16:40:20 -0000 >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: