Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Jan 2008 13:03:56 +0200
From:      m.boyarov@bsd.by (Max N. Boyarov)
To:        acpi@freebsd.org
Subject:   [PATCH]: powerd minimal frequency support
Message-ID:  <86ejcjfizn.fsf@bsd.by>

next in thread | raw e-mail | index | archive | help
--==-=-=
Content-Type: multipart/mixed; boundary="=-=-="

--=-=-=

Hi,

Patch add -m switch to powerd. This is help set minimal frequency level to powerd.

for sample powerd -m 1000 set minimal freq to 1000.

Please say if this patch is useful then I'll send PR.


--=-=-=
Content-Type: text/x-patch
Content-Disposition: inline; filename=powerd.diff
Content-Transfer-Encoding: quoted-printable

Index: powerd.8
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.sbin/powerd/powerd.8,v
retrieving revision 1.10
diff -u -r1.10 powerd.8
=2D-- powerd.8	24 Nov 2005 09:25:08 -0000	1.10
+++ powerd.8	14 Jan 2008 20:56:37 -0000
@@ -83,6 +83,8 @@
 Specifies a different polling interval (in milliseconds) for AC line state
 and system idle levels.
 The default is 500 ms.
+.It Fl m Ar ival
+Specifies a minimal frequency.
 .It Fl P Ar pidfile
 Specifies an alternative file in which the process ID should be stored.
 The default is
Index: powerd.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/usr.sbin/powerd/powerd.c,v
retrieving revision 1.21
diff -u -r1.21 powerd.c
=2D-- powerd.c	13 Jun 2007 19:05:11 -0000	1.21
+++ powerd.c	14 Jan 2008 20:52:28 -0000
@@ -357,7 +357,7 @@
 {
=20
 	fprintf(stderr,
=2D"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-n mode] [-p ival] [-r =
%%] [-P pidfile]\n");
+"usage: powerd [-v] [-a mode] [-b mode] [-i %%] [-n mode] [-p ival] [-r %%=
] [-m minfreq] [-P pidfile]\n");
 	exit(1);
 }
=20
@@ -370,7 +370,7 @@
 	struct pidfh *pfh =3D NULL;
 	const char *pidfile =3D NULL;
 	long idle, total;
=2D	int curfreq, *freqs, i, *mwatts, numfreqs;
+	int curfreq, *freqs, i, *mwatts, numfreqs, minfreq;
 	int ch, mode, mode_ac, mode_battery, mode_none;
 	uint64_t mjoules_used;
 	size_t len;
@@ -383,11 +383,13 @@
 	mjoules_used =3D 0;
 	vflag =3D 0;
=20
+	minfreq =3D 0;
+=09
 	/* User must be root to control frequencies. */
 	if (geteuid() !=3D 0)
 		errx(1, "must be root to run");
=20
=2D	while ((ch =3D getopt(argc, argv, "a:b:i:n:p:P:r:v")) !=3D EOF)
+	while ((ch =3D getopt(argc, argv, "a:b:i:n:p:m:P:r:v")) !=3D EOF)
 		switch (ch) {
 		case 'a':
 			parse_mode(optarg, &mode_ac, ch);
@@ -427,6 +429,9 @@
 		case 'v':
 			vflag =3D 1;
 			break;
+		case 'm':
+			minfreq =3D atoi(optarg);
+			break;=09=09=09
 		default:
 			usage();
 		}
@@ -453,6 +458,17 @@
 	if (read_freqs(&numfreqs, &freqs, &mwatts))
 		err(1, "error reading supported CPU frequencies");
=20
+	if (vflag) {
+		printf("powerd: use %d as minimal freq\n", minfreq);
+	}
+=09
+	if ( minfreq < freqs[numfreqs - 1] ) {
+		minfreq =3D freqs[numfreqs - 1];
+		if (vflag) {
+			printf("minfreq setted to %d\n", minfreq);
+		}
+	}
+=09
 	/* Run in the background unless in verbose mode. */
 	if (!vflag) {
 		pid_t otherpid;
@@ -605,8 +621,8 @@
 			if (set_freq(freqs[i]))
 				warn("error setting CPU frequency %d",
 				    freqs[i]);
=2D		} else if (idle > (total * cpu_idle_mark) / 100 &&
=2D		    curfreq > freqs[numfreqs - 1]) {
+		} else if ( idle > (total * cpu_idle_mark) / 100 &&
+		    curfreq > freqs[numfreqs - 1] && minfreq <=3D freqs[i+1] ) {
 			i++;
 			if (vflag) {
 				printf("idle time > %d%%, decreasing clock"

--=-=-=
Content-Transfer-Encoding: quoted-printable


=2D-=20
Max N. Boyarov

--=-=-=--

--==-=-=
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.4 (FreeBSD)

iD8DBQFHjJMhXJXgXMoFno8RAsmGAJsEmni8bapeW31oSlsxvmrKT+MmEgCfSokK
as+WWE83a8PsyJY/YZD7stE=
=/3is
-----END PGP SIGNATURE-----
--==-=-=--



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