From owner-acpi-jp@jp.freebsd.org  Sat Oct 27 03:32:05 2001
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id DAA81919;
	Sat, 27 Oct 2001 03:32:05 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (root@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id DAA81913
	for <acpi-jp@jp.freebsd.org>; Sat, 27 Oct 2001 03:32:02 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (iwasaki.imasy.or.jp [202.227.24.92])
	(authenticated as iwa with CRAM-MD5)
	by tasogare.imasy.or.jp (8.11.6+3.4W/8.11.6/tasogare) with ESMTP/inet id f9QIVvm91656
	for <acpi-jp@jp.freebsd.org>; Sat, 27 Oct 2001 03:31:57 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Date: Sat, 27 Oct 2001 03:31:54 +0900 (JST)
Message-Id: <20011027.033154.59470171.iwasaki@jp.FreeBSD.org>
To: acpi-jp@jp.freebsd.org
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Mailer: Mew version 2.0 on Emacs 20.7 / Mule 4.0 (HANANOEN)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+010328
X-Sequence: acpi-jp 1379
Subject: [acpi-jp 1379] acpi_thermal: small improvement, delayed cooler off and verbose
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

Hi,

I've heard sometimes that console messages from acpi_tz0 is nuisance
and many people want to disable this.  Recently I got a chance to see
the problem on my friend's newer laptop with good thermal system.
Surely there were too many `acpi_tz0: _AC0: temperature 68.0 >= setpoint 64.0'
massages while heavy processes are running such as make buildkernel.

It seems that his laptop's thermal sensor is accurate and cooler
system is powerful, in result, I guess that cooler switching is
repeating ON and OFF many times.

So I made small patches to delay switching cooler off and verbose mode
flag which is controlled by sysctl.

Here is a exapmle of delayed cooler off.  By increasing value of MIB
hw.acpi.thermal.tz0.cooler_off_delay, you are able to make cooler
switching smooth.

CASE 1: hw.acpi.thermal.tz0.cooler_off_delay=0 (default)
Oct 26 23:39:00 fivavl buildkernel: start
Oct 26 23:39:23 fivavl ... : acpi_tz0: _AC0: temperature 65.0 >= setpoint 64.0
Oct 26 23:39:23 fivavl ... : acpi_tz0: switched from NONE to _AC0: 65.0C
Oct 26 23:39:30 fivavl ... : acpi_tz0: switched from _AC0 to NONE: 63.0C
Oct 26 23:43:33 fivavl ... : acpi_tz0: _AC0: temperature 64.0 >= setpoint 64.0
Oct 26 23:43:33 fivavl ... : acpi_tz0: switched from NONE to _AC0: 64.0C
Oct 26 23:43:37 fivavl ... : acpi_tz0: switched from _AC0 to NONE: 60.0C
Oct 26 23:44:48 fivavl ... : acpi_tz0: _AC0: temperature 64.0 >= setpoint 64.0
Oct 26 23:44:51 fivavl ... : acpi_tz0: switched from NONE to _AC0: 64.0C
Oct 26 23:45:08 fivavl ... : acpi_tz0: switched from _AC0 to NONE: 61.0C
[snip]
Oct 26 23:50:03 fivavl ... : acpi_tz0: switched from _AC0 to NONE: 62.0C
Oct 26 23:50:09 fivavl ... : acpi_tz0: _AC0: temperature 70.0 >= setpoint 64.0
Oct 26 23:50:09 fivavl ... : acpi_tz0: switched from NONE to _AC0: 70.0C
Oct 26 23:51:12 fivavl buildkernel: finished
Oct 26 23:51:20 fivavl ... : acpi_tz0: switched from _AC0 to NONE: 63.0C

Total On/Off repeating: 11 times.


CASE 2: hw.acpi.thermal.tz0.cooler_off_delay=20
Oct 26 23:52:30 fivavl buildkernel: start
Oct 26 23:52:41 fivavl ... : acpi_tz0: _AC0: temperature 65.0 >= setpoint 64.0
Oct 26 23:52:41 fivavl ... : acpi_tz0: switched from NONE to _AC0: 65.0C
Oct 27 00:01:24 fivavl buildkernel: finished
Oct 27 00:02:54 fivavl ... : acpi_tz0: switched from _AC0 to NONE: 55.0C

Total On/Off repeating: once.

Setting hw.acpi.thermal.tz0.verbose to 0 (default) shut those messages
up completely.

I'll commit this on Monday of next week.

Thanks


Index: acpi_thermal.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/acpica/acpi_thermal.c,v
retrieving revision 1.16
diff -u -r1.16 acpi_thermal.c
--- acpi_thermal.c	4 Sep 2001 15:40:12 -0000	1.16
+++ acpi_thermal.c	26 Oct 2001 06:02:45 -0000
@@ -76,6 +76,8 @@
     int				tz_active;		/* current active cooling */
 #define TZ_ACTIVE_NONE		-1
     int				tz_requested;		/* user-requested minimum active cooling */
+    int				tz_cooler_off_delay;	/* delayed cooler off */
+    int				tz_verbose;		/* verbose mode */
     int				tz_thflags;		/* current temperature-related flags */
 #define TZ_THFLAG_NONE		0
 #define TZ_THFLAG_PSV		(1<<0)
@@ -168,6 +170,8 @@
     sc->tz_dev = dev;
     sc->tz_handle = acpi_get_handle(dev);
     sc->tz_requested = TZ_ACTIVE_NONE;
+    if (bootverbose)
+	sc->tz_verbose = 1;
 
     /*
      * Parse the current state of the thermal zone and build control
@@ -207,6 +211,12 @@
 		    sc, 0, acpi_tz_active_sysctl, "I", "");
     
     SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
+		   OID_AUTO, "cooler_off_delay", CTLFLAG_RD | CTLFLAG_RW,
+		   &sc->tz_cooler_off_delay, 0, "delayed cooler off counter");
+    SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
+		   OID_AUTO, "verbose", CTLFLAG_RD | CTLFLAG_RW,
+		   &sc->tz_verbose, 0, "verbose mode");
+    SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
 		   OID_AUTO, "thermal_flags", CTLFLAG_RD,
 		   &sc->tz_thflags, 0, "thermal zone flags");
     SYSCTL_ADD_INT(&sc->tz_sysctl_ctx, SYSCTL_CHILDREN(sc->tz_sysctl_tree),
@@ -324,6 +334,20 @@
     return_VALUE(0);
 }
 
+static char	*aclevel_string[] =	{
+	"NONE", "_AC0", "_AC1", "_AC2", "_AC3", "_AC4",
+	"_AC5", "_AC6", "_AC7", "_AC8", "_AC9" };
+
+static __inline const char *
+acpi_tz_aclevel_string(int active)
+{
+	if (active < -1 || active >= TZ_NUMLEVELS) {
+		return (aclevel_string[0]);
+	}
+
+	return (aclevel_string[active+1]);
+}
+
 /*
  * Evaluate the condition of a thermal zone, take appropriate actions.
  */
@@ -333,6 +357,7 @@
     int		temp;
     int		i;
     int		newactive, newflags;
+    static int	cooler_off_delay = 0;
 
     FUNCTION_TRACE(__func__);
 
@@ -359,13 +384,24 @@
 	if ((sc->tz_zone.ac[i] != -1) && (temp >= sc->tz_zone.ac[i])) {
 	    newactive = i;
 	    if (sc->tz_active != newactive) {
-		device_printf(sc->tz_dev,
-			      "_AC%d: temperature %d.%d >= setpoint %d.%d\n", i,
-			      TZ_KELVTOC(temp), TZ_KELVTOC(sc->tz_zone.ac[i]));
+		if (sc->tz_verbose) {
+		    device_printf(sc->tz_dev,
+			"_AC%d: temperature %d.%d >= setpoint %d.%d\n", i,
+			TZ_KELVTOC(temp), TZ_KELVTOC(sc->tz_zone.ac[i]));
+		}
+		cooler_off_delay = sc->tz_cooler_off_delay;
+		break;
 	    }
 	}
     }
 
+    /* We are going to switch all coolers off, but delay it if requested. */
+    if (newactive != sc->tz_active && newactive == TZ_ACTIVE_NONE &&
+	cooler_off_delay > 0) {
+	newactive = sc->tz_active;
+	cooler_off_delay--;
+    }
+
     /* handle user override of active mode */
     if (sc->tz_requested > newactive)
 	newactive = sc->tz_requested;
@@ -393,7 +429,11 @@
 	if (newactive != TZ_ACTIVE_NONE)
 	    acpi_ForeachPackageObject((ACPI_OBJECT *)sc->tz_zone.al[newactive].Pointer,
 				      acpi_tz_switch_cooler_on, sc);
-	device_printf(sc->tz_dev, "switched from _AC%d to _AC%d\n", sc->tz_active, newactive);
+	if (sc->tz_verbose) {
+	    device_printf(sc->tz_dev, "switched from %s to %s: %d.%dC\n",
+		acpi_tz_aclevel_string(sc->tz_active),
+		acpi_tz_aclevel_string(newactive), TZ_KELVTOC(temp));
+	}
 	sc->tz_active = newactive;
     }
 
