Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 15 Aug 2005 04:05:52 +0900
From:      Hajimu UMEMOTO <ume@freebsd.org>
To:        "Kevin Oberman" <oberman@es.net>
Cc:        acpi@freebsd.org
Subject:   Re: Annoyances with passive thermal code (acpi_thermal)
Message-ID:  <ygezmrk2van.wl%ume@mahoroba.org>
In-Reply-To: <20050814023842.C0D845D07@ptavv.es.net>
References:  <20050814023842.C0D845D07@ptavv.es.net>

next in thread | previous in thread | raw e-mail | index | archive | help
--Multipart_Mon_Aug_15_04:05:51_2005-1
Content-Type: text/plain; charset=US-ASCII

Hi,

>>>>> On Sat, 13 Aug 2005 19:38:42 -0700
>>>>> "Kevin Oberman" <oberman@es.net> said:

oberman> I've noted an unpleasant mis-behavior in acpi_thermal.

oberman> 1. Killed powerd
oberman> 2. Set dev.cpu.0.freq to 1200 (I was on batteries and wanted to stretch
oberman>    them) 
oberman> 3. Started a BIG build...openoffice

oberman> The temp went up over _PSV and the CPU was slowed to 1050. The CPU
oberman> cooled for a while and the freq was reset to 1800 which started draining
oberman> my battery way too fast.

It's curious that even when CPU speed is slowed, the temperature go up
over _PSV.

oberman> Ideally, acpi_thermal should store the frequency when it cuts speed and
oberman> restore that speed when the CPU cools, not the maximum speed.

CPUFREQ_SET() does it, actually.  However, since CPU speed is restored
by degrees, we couldn't use the facility effectively.  Please try the
attached patch.

Sincerely,


--Multipart_Mon_Aug_15_04:05:51_2005-1
Content-Type: text/x-patch; charset=US-ASCII
Content-Disposition: attachment; filename="acpi_thermal.c-saved_level.diff"
Content-Transfer-Encoding: 7bit

Index: sys/dev/acpica/acpi_thermal.c
diff -u -p sys/dev/acpica/acpi_thermal.c.orig sys/dev/acpica/acpi_thermal.c
--- sys/dev/acpica/acpi_thermal.c.orig	Fri Aug  5 03:02:39 2005
+++ sys/dev/acpica/acpi_thermal.c	Mon Aug 15 03:29:30 2005
@@ -116,6 +116,7 @@ struct acpi_tz_softc {
     int				tz_cooling_enabled;
     int				tz_cooling_active;
     int				tz_cooling_updated;
+    int				tz_cooling_saved_level;
 };
 
 #define CPUFREQ_MAX_LEVELS	64 /* XXX cpufreq should export this */
@@ -202,6 +203,7 @@ acpi_tz_attach(device_t dev)
     sc->tz_cooling_proc_running = FALSE;
     sc->tz_cooling_active = FALSE;
     sc->tz_cooling_updated = FALSE;
+    sc->tz_cooling_saved_level = 0;
 
     /*
      * Always attempt to enable passive cooling for tz0.  Users can enable
@@ -853,11 +855,13 @@ acpi_tz_cpufreq_restore(struct acpi_tz_s
     if ((dev = devclass_get_device(devclass_find("cpufreq"), 0)) == NULL)
 	return (ENXIO);
     ACPI_VPRINT(sc->tz_dev, acpi_device_get_parent_softc(sc->tz_dev),
-	"temperature %d.%dC: resuming previous clock speed\n",
-	TZ_KELVTOC(sc->tz_temperature));
+	"temperature %d.%dC: resuming previous clock speed (%d)\n",
+	TZ_KELVTOC(sc->tz_temperature), sc->tz_cooling_saved_level);
     error = CPUFREQ_SET(dev, NULL, CPUFREQ_PRIO_KERN);
-    if (error == 0)
+    if (error == 0) {
+	sc->tz_cooling_saved_level = 0;
 	sc->tz_cooling_updated = FALSE;
+    }
     return (error);
 }
 
@@ -914,18 +918,20 @@ acpi_tz_cpufreq_update(struct acpi_tz_so
 	if (i == num_levels)
 	    i--;
     } else {
+	/* If we didn't decrease frequency yet, don't increase it. */
+	if (!sc->tz_cooling_updated) {
+	    sc->tz_cooling_active = FALSE;
+	    goto out;
+	}
+
 	/* Find the closest available frequency, rounding up. */
-	for (i = num_levels - 1; i >= 0; i--)
+	for (i = num_levels - 1; i >= sc->tz_cooling_saved_level; i--)
 	    if (levels[i].total_set.freq >= desired_freq)
 		break;
-
-	/* If we didn't find a relevant setting, use the highest. */
-	if (i == -1)
-	    i++;
     }
 
     /* If we're going to the highest frequency, restore the old setting. */
-    if (i == 0) {
+    if (i <= sc->tz_cooling_saved_level) {
 	error = acpi_tz_cpufreq_restore(sc);
 	if (error == 0)
 	    sc->tz_cooling_active = FALSE;
@@ -941,8 +947,14 @@ acpi_tz_cpufreq_update(struct acpi_tz_so
 	    (freq > levels[i].total_set.freq) ? "de" : "in",
 	    freq, levels[i].total_set.freq);
 	error = CPUFREQ_SET(dev, &levels[i], CPUFREQ_PRIO_KERN);
-	if (error == 0)
+	if (error == 0 && !sc->tz_cooling_updated) {
+	    /* Use saved cpu level as maximum value. */
+	    for (i = num_levels - 1; i >= 0; i--)
+		if (levels[i].total_set.freq >= freq)
+		    break;
+	    sc->tz_cooling_saved_level = (i < 0) ? 0 : i;
 	    sc->tz_cooling_updated = TRUE;
+	}
     }
 
 out:

--Multipart_Mon_Aug_15_04:05:51_2005-1
Content-Type: text/plain; charset=US-ASCII

--
Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
ume@mahoroba.org  ume@{,jp.}FreeBSD.org
http://www.imasy.org/~ume/

--Multipart_Mon_Aug_15_04:05:51_2005-1--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ygezmrk2van.wl%ume>