Date: Mon, 15 Aug 2005 16:19:35 +0900 From: Hajimu UMEMOTO <ume@mahoroba.org> To: "Kevin Oberman" <oberman@es.net> Cc: acpi@freebsd.org Subject: Re: Annoyances with passive thermal code (acpi_thermal) Message-ID: <ygeoe7zacqg.wl%ume@mahoroba.org> In-Reply-To: <ygezmrk2van.wl%ume@mahoroba.org> References: <20050814023842.C0D845D07@ptavv.es.net> <ygezmrk2van.wl%ume@mahoroba.org>
index | next in thread | previous in thread | raw e-mail
[-- Attachment #1 --]
Hi,
>>>>> On Mon, 15 Aug 2005 04:05:52 +0900
>>>>> Hajimu UMEMOTO <ume@freebsd.org> said:
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.
ume> CPUFREQ_SET() does it, actually. However, since CPU speed is restored
ume> by degrees, we couldn't use the facility effectively. Please try the
ume> attached patch.
It seems CPUFREQ_SET(NULL) doesn't restore previous setting correctly.
So, I changed to make sure to restore previous setting for workaround.
Please try this patch instead.
Sincerely,
[-- Attachment #2 --]
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 15:05:17 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,28 @@ 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) {
+ struct cf_level *levels;
+ int num_levels;
+
+ /* XXX: It seems cpu level is not saved/restored correctly. */
+ levels = malloc(CPUFREQ_MAX_LEVELS * sizeof(*levels), M_TEMP,
+ M_NOWAIT);
+ if (levels == NULL)
+ return (ENOMEM);
+ num_levels = CPUFREQ_MAX_LEVELS;
+ error = CPUFREQ_LEVELS(dev, levels, &num_levels);
+ if (error == 0)
+ CPUFREQ_SET(dev, &levels[sc->tz_cooling_saved_level],
+ CPUFREQ_PRIO_USER);
+ free(levels, M_TEMP);
+
+ sc->tz_cooling_saved_level = 0;
sc->tz_cooling_updated = FALSE;
+ }
return (error);
}
@@ -914,18 +933,24 @@ 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 (i < sc->tz_cooling_saved_level)
+ i = sc->tz_cooling_saved_level;
}
/* 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 +966,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:
[-- Attachment #3 --]
--
Hajimu UMEMOTO @ Internet Mutual Aid Society Yokohama, Japan
ume@mahoroba.org ume@{,jp.}FreeBSD.org
http://www.imasy.org/~ume/
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ygeoe7zacqg.wl%ume>
