From owner-freebsd-acpi@FreeBSD.ORG Mon Aug 15 07:20:05 2005 Return-Path: X-Original-To: acpi@freebsd.org Delivered-To: freebsd-acpi@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B628416A41F for ; Mon, 15 Aug 2005 07:20:05 +0000 (GMT) (envelope-from ume@mahoroba.org) Received: from ameno.mahoroba.org (gw4.mahoroba.org [218.45.22.175]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1C78A43D45 for ; Mon, 15 Aug 2005 07:20:04 +0000 (GMT) (envelope-from ume@mahoroba.org) Received: from kasuga.mahoroba.org (IDENT:e8rN3dolVy/RgmdGIKilN4jWICHnHja5WJjQ2sgU1JI3VFED/8zUMktyBKNpYCwp@[IPv6:3ffe:501:185b:801a:20b:97ff:fe2e:b521]) (user=ume mech=CRAM-MD5 bits=0) by ameno.mahoroba.org (8.13.3/8.13.3) with ESMTP/inet6 id j7F7Ji8n023935 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 15 Aug 2005 16:19:50 +0900 (JST) (envelope-from ume@mahoroba.org) Date: Mon, 15 Aug 2005 16:19:35 +0900 Message-ID: From: Hajimu UMEMOTO To: "Kevin Oberman" In-Reply-To: References: <20050814023842.C0D845D07@ptavv.es.net> User-Agent: xcite1.38> Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (=?ISO-8859-4?Q?Sanj=F2?=) APEL/10.6 Emacs/22.0.50 (i386-unknown-freebsd6.0) MULE/5.0 (SAKAKI) X-Operating-System: FreeBSD 6.0-BETA2 X-PGP-Key: http://www.imasy.or.jp/~ume/publickey.asc X-PGP-Fingerprint: 1F00 0B9E 2164 70FC 6DC5 BF5F 04E9 F086 BF90 71FE Organization: Internet Mutual Aid Society, YOKOHAMA X-PGP-Key: http://www.imasy.or.jp/~ume/publickey.asc X-PGP-Fingerprint: 1F00 0B9E 2164 70FC 6DC5 BF5F 04E9 F086 BF90 71FE MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Mon_Aug_15_16:19:35_2005-1" X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0 (ameno.mahoroba.org [IPv6:3ffe:501:185b:8010::1]); Mon, 15 Aug 2005 16:19:53 +0900 (JST) X-Virus-Scanned: by amavisd-new X-Virus-Status: Clean X-Spam-Status: No, score=-2.2 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on ameno.mahoroba.org Cc: acpi@freebsd.org Subject: Re: Annoyances with passive thermal code (acpi_thermal) X-BeenThere: freebsd-acpi@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: ACPI and power management development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 15 Aug 2005 07:20:05 -0000 --Multipart_Mon_Aug_15_16:19:35_2005-1 Content-Type: text/plain; charset=US-ASCII Hi, >>>>> On Mon, 15 Aug 2005 04:05:52 +0900 >>>>> Hajimu UMEMOTO 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, --Multipart_Mon_Aug_15_16:19:35_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 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: --Multipart_Mon_Aug_15_16:19:35_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_16:19:35_2005-1--