Module Name: src Committed By: jruoho Date: Thu Aug 12 06:17:15 UTC 2010
Modified Files: src/sys/dev/acpi: acpi_cpu_pstate.c Log Message: Three small things: (1) fix off by one, (2) protect the cached P-state (required for interaction with T-states), and (3) use aprint_debug(9) instead of the ACPI_DEBUG_PRINT(x) macro for the dynamic frequency changes (for the time being, people need easier way to observe the dynamic changes). To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/sys/dev/acpi/acpi_cpu_pstate.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/acpi/acpi_cpu_pstate.c diff -u src/sys/dev/acpi/acpi_cpu_pstate.c:1.13 src/sys/dev/acpi/acpi_cpu_pstate.c:1.14 --- src/sys/dev/acpi/acpi_cpu_pstate.c:1.13 Wed Aug 11 18:15:52 2010 +++ src/sys/dev/acpi/acpi_cpu_pstate.c Thu Aug 12 06:17:14 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_cpu_pstate.c,v 1.13 2010/08/11 18:15:52 jruoho Exp $ */ +/* $NetBSD: acpi_cpu_pstate.c,v 1.14 2010/08/12 06:17:14 jruoho Exp $ */ /*- * Copyright (c) 2010 Jukka Ruohonen <jruoho...@iki.fi> @@ -27,7 +27,7 @@ * SUCH DAMAGE. */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.13 2010/08/11 18:15:52 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.14 2010/08/12 06:17:14 jruoho Exp $"); #include <sys/param.h> #include <sys/evcnt.h> @@ -242,20 +242,21 @@ mutex_exit(&sc->sc_mtx); -#if 0 if (old != new) { + aprint_debug_dev(sc->sc_dev, "maximum frequency " + "changed from P%u (%u MHz) to P%u (%u MHz)\n", + old, sc->sc_pstate[old].ps_freq, new, + sc->sc_pstate[sc->sc_pstate_max].ps_freq); +#if 0 /* * If the maximum changed, proactively * raise or lower the target frequency. */ acpicpu_pstate_set(sc, sc->sc_pstate[new].ps_freq); - ACPI_DEBUG_PRINT((ACPI_DB_INFO, "frequency changed from " - "%u MHz to %u MHz\n", sc->sc_pstate[old].ps_freq, - sc->sc_pstate[sc->sc_pstate_max].ps_freq)); - } #endif + } } ACPI_STATUS @@ -494,13 +495,13 @@ if (ACPI_FAILURE(rv)) return 1; - if (val > (uint64_t)sc->sc_pstate_count) + if (val > sc->sc_pstate_count - 1) return 1; if (sc->sc_pstate[val].ps_freq == 0) return 1; - sc->sc_pstate_max = val; /* XXX: sysctl(8) knob? */ + sc->sc_pstate_max = val; return 0; } @@ -555,11 +556,16 @@ goto fail; } + mutex_enter(&sc->sc_mtx); + if (sc->sc_pstate_current != ACPICPU_P_STATE_UNKNOWN) { *freq = sc->sc_pstate_current; + mutex_exit(&sc->sc_mtx); return 0; } + mutex_exit(&sc->sc_mtx); + switch (method) { case ACPI_ADR_SPACE_FIXED_HARDWARE: @@ -611,7 +617,9 @@ goto fail; } + mutex_enter(&sc->sc_mtx); sc->sc_pstate_current = *freq; + mutex_exit(&sc->sc_mtx); return 0; @@ -619,7 +627,9 @@ aprint_error_dev(sc->sc_dev, "failed " "to get frequency (err %d)\n", rv); + mutex_enter(&sc->sc_mtx); *freq = sc->sc_pstate_current = ACPICPU_P_STATE_UNKNOWN; + mutex_exit(&sc->sc_mtx); return rv; } @@ -712,7 +722,10 @@ } ps->ps_evcnt.ev_count++; + + mutex_enter(&sc->sc_mtx); sc->sc_pstate_current = freq; + mutex_exit(&sc->sc_mtx); return 0; @@ -720,7 +733,9 @@ aprint_error_dev(sc->sc_dev, "failed to set " "frequency to %u (err %d)\n", freq, rv); + mutex_enter(&sc->sc_mtx); sc->sc_pstate_current = ACPICPU_P_STATE_UNKNOWN; + mutex_exit(&sc->sc_mtx); return rv; }