DragonFly BSD
DragonFly users List (threaded) for 2006-06
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: A mobile user's wishlist


From: Johannes Hofmann <Johannes.Hofmann@xxxxxx>
Date: 16 Jun 2006 18:23:45 GMT

YONETANI Tomokazu <qhwt+dfly@xxxxxxxxxx> wrote:
> On Wed, Jun 07, 2006 at 11:10:59AM +0900, YONETANI Tomokazu wrote:
>> > FreeBSD has tools for that: sysutils/est and sysutils/estrcl
>> 
>> FreeBSD has a daemon named powerd and it's based on estctrl.
>> I'll try porting it to DragonFly.
> 
> Obviously I spoke too soon for this part; powerd is too hard to port
> without cpufreq framework.  I'm going to commit est driver alone for now
> and work on a DragonFly patch for estd(if Johannes Hofmann hasn't started
> it yet).

Ok, here is an initial patch against estd-r4.1 that makes things 
work on DragonFly. The question is how to integrate the modifications.
We could add #ifdef's or add the patch to the pkgsrc stuff...
Also I would suggest to adjust our est-sysctl names to match the
NetBSD ones's.
And what about that useconds_t? I just changed it to int. Any better
ideas?

  Johannes



diff -r 94c0f08cbd8c Makefile
--- a/Makefile	Fri Jun 16 19:33:44 2006 +0200
+++ b/Makefile	Fri Jun 16 20:16:38 2006 +0200
@@ -6,7 +6,7 @@ clean:
 	rm -f *~
 
 estd:	estd.c
-	gcc -O2 -lutil -o estd estd.c
+	gcc -O2 -lutil -lkinfo -o estd estd.c
 	
 all: estd
 
diff -r 94c0f08cbd8c estd.c
--- a/estd.c	Fri Jun 16 19:33:44 2006 +0200
+++ b/estd.c	Fri Jun 16 20:16:38 2006 +0200
@@ -26,13 +26,13 @@
 
 
 #include <stdlib.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <time.h>
 #include <sys/param.h>
 #include <sys/sysctl.h>
-#include <sys/sched.h>
+#include <kinfo.h>
 #include <errno.h>
-#include <util.h>
 #include <signal.h>
 
 #define ESTD_VERSION "Release 4.1"
@@ -59,7 +59,7 @@ int             daemonize = 0;
 int             daemonize = 0;
 int             verbose = 0;
 int             strategy = SMOOTH;
-useconds_t      poll = DEF_POLL;
+int             poll = DEF_POLL;
 int             high = DEF_HIGH;
 int             low = DEF_LOW;
 int             minmhz = -1;
@@ -67,26 +67,23 @@ int             listfreq = 0;
 int             listfreq = 0;
 int		tech = TECH_UNKNOWN;
 
-static int      cpumib[2] = {CTL_KERN, KERN_CP_TIME};
 
 static char	*techdesc[3] = {"Unknown",
 				"Enhanced SpeedStep",
 				"PowerNow"
 				};
 static char	*freqctl[3] = {	"",	
-				"machdep.est.frequency.available",
+				"hw.est_freqs",
 				"machdep.powernow.frequency.available"
 				};
 static char	*setctl[3] = {	"",
-				"machdep.est.frequency.target",
+				"hw.est_curfreq",
 				"machdep.powernow.frequency.target"
 				};
 
-static u_int64_t cp_time[CPUSTATES];
-static u_int64_t cp_old[CPUSTATES];
-static u_int64_t cp_diff[CPUSTATES];
-static size_t   cp_time_size = sizeof(cp_time[0]) * CPUSTATES;
-
+static struct kinfo_cputime cp_time;
+static struct kinfo_cputime cp_old;
+static struct kinfo_cputime cp_diff;
 
 void
 usage()
@@ -113,16 +110,25 @@ get_cpuusage()
 {
 	int             i;
 	u_int64_t       total_time = 0;
-	memcpy(&cp_old[0], &cp_time[0], cp_time_size);
-	if (sysctl(cpumib, 2, &cp_time, &cp_time_size, NULL, 0) < 0) {
+
+	cp_old = cp_time;
+	if (kinfo_get_sched_cputime(&cp_time)) {
 		fprintf(stderr, "estd: Cannot get CPU status\n");
 		exit(1);
 	}
-	for (i = 0; i < CPUSTATES; i++) {
-		cp_diff[i] = cp_time[i] - cp_old[i];
-		total_time += cp_diff[i];
-	}
-	return (100 - (cp_diff[CP_IDLE] * 100) / total_time);
+
+	cp_diff.cp_user = cp_time.cp_user - cp_old.cp_user;
+	total_time += cp_diff.cp_user;
+	cp_diff.cp_nice = cp_time.cp_nice - cp_old.cp_nice;
+	total_time += cp_diff.cp_nice;
+	cp_diff.cp_sys = cp_time.cp_sys - cp_old.cp_sys;
+	total_time += cp_diff.cp_sys;
+	cp_diff.cp_intr = cp_time.cp_intr - cp_old.cp_intr;
+	total_time += cp_diff.cp_intr;
+	cp_diff.cp_idle = cp_time.cp_idle - cp_old.cp_idle;
+	total_time += cp_diff.cp_idle;
+
+	return (100 - (cp_diff.cp_idle * 100) / total_time);
 }
 
 /* sets the cpu frequency */
@@ -313,11 +319,6 @@ main(int argc, char *argv[])
 	signal(SIGTERM, &sighandler);
 	curfreq = minidx;
 	set_freq(freqtab[curfreq]);
-	for (i = 0; i < CPUSTATES; i++) {
-		cp_time[i] = 0;
-		cp_old[i] = 0;
-		cp_diff[i] = 0;
-	}
 
 	/* the big processing loop, we will only exit via signal */
 	while (1) {




[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]