Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Change the default behavior to enforce the maxi...



details:   https://anonhg.NetBSD.org/src/rev/395d78136cdf
branches:  trunk
changeset: 760182:395d78136cdf
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Thu Dec 30 12:05:02 2010 +0000

description:
Change the default behavior to enforce the maximum frequency when the
firmware requests to do so. This cures severe overhating (> 120 C) observed
on many laptops, being also on par with the specification(s). This can be
reverted by using the new "hw.acpi.cpu.dynamic" sysctl variable.

diffstat:

 sys/dev/acpi/acpi_cpu.c        |  67 ++++++++++++++++++++++++++++++++++++++++-
 sys/dev/acpi/acpi_cpu.h        |   3 +-
 sys/dev/acpi/acpi_cpu_pstate.c |  41 +++++++++++++-----------
 sys/dev/acpi/acpi_cpu_tstate.c |   7 +---
 4 files changed, 89 insertions(+), 29 deletions(-)

diffs (266 lines):

diff -r fd8fda97b7fb -r 395d78136cdf sys/dev/acpi/acpi_cpu.c
--- a/sys/dev/acpi/acpi_cpu.c   Thu Dec 30 11:54:50 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu.c   Thu Dec 30 12:05:02 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.c,v 1.23 2010/10/28 04:28:29 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.c,v 1.24 2010/12/30 12:05:02 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.23 2010/10/28 04:28:29 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.24 2010/12/30 12:05:02 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -36,6 +36,7 @@
 #include <sys/module.h>
 #include <sys/mutex.h>
 #include <sys/once.h>
+#include <sys/sysctl.h>
 
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
@@ -53,6 +54,7 @@
 static int               acpicpu_once_detach(void);
 static void              acpicpu_prestart(device_t);
 static void              acpicpu_start(device_t);
+static void              acpicpu_sysctl(device_t);
 
 static int               acpicpu_object(ACPI_HANDLE, struct acpicpu_object *);
 static cpuid_t           acpicpu_id(uint32_t);
@@ -65,6 +67,9 @@
 static bool              acpicpu_resume(device_t, const pmf_qual_t *);
 
 struct acpicpu_softc   **acpicpu_sc = NULL;
+static struct sysctllog         *acpicpu_log = NULL;
+static bool              acpicpu_dynamic = true;
+static bool              acpicpu_passive = true;
 
 static const char * const acpicpu_hid[] = {
        "ACPI0007",
@@ -115,7 +120,6 @@
 
        sc->sc_dev = self;
        sc->sc_cold = true;
-       sc->sc_passive = false;
        sc->sc_node = aa->aa_node;
        sc->sc_cpuid = acpicpu_id(sc->sc_object.ao_procid);
 
@@ -211,6 +215,9 @@
        if (acpicpu_sc != NULL)
                kmem_free(acpicpu_sc, maxcpus * sizeof(*sc));
 
+       if (acpicpu_log != NULL)
+               sysctl_teardown(&acpicpu_log);
+
        return 0;
 }
 
@@ -250,12 +257,63 @@
        if ((sc->sc_flags & ACPICPU_FLAG_T) != 0)
                acpicpu_tstate_start(self);
 
+       acpicpu_sysctl(self);
+
        aprint_debug_dev(sc->sc_dev, "ACPI CPUs started (cap "
            "0x%02x, flags 0x%06x)\n", sc->sc_cap, sc->sc_flags);
 
        sc->sc_cold = false;
 }
 
+static void
+acpicpu_sysctl(device_t self)
+{
+       const struct sysctlnode *node;
+       int err;
+
+       err = sysctl_createv(&acpicpu_log, 0, NULL, &node,
+           CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL,
+           NULL, 0, NULL, 0, CTL_HW, CTL_EOL);
+
+       if (err != 0)
+               goto fail;
+
+       err = sysctl_createv(&acpicpu_log, 0, &node, &node,
+           CTLFLAG_PERMANENT, CTLTYPE_NODE, "acpi", NULL,
+           NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+
+       if (err != 0)
+               goto fail;
+
+       err = sysctl_createv(&acpicpu_log, 0, &node, &node,
+           0, CTLTYPE_NODE, "cpu", SYSCTL_DESCR("ACPI CPU"),
+           NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+
+       if (err != 0)
+               goto fail;
+
+       err = sysctl_createv(&acpicpu_log, 0, &node, NULL,
+           CTLFLAG_READWRITE, CTLTYPE_BOOL, "dynamic",
+           SYSCTL_DESCR("Dynamic states"), NULL, 0,
+           &acpicpu_dynamic, 0, CTL_CREATE, CTL_EOL);
+
+       if (err != 0)
+               goto fail;
+
+       err = sysctl_createv(&acpicpu_log, 0, &node, NULL,
+           CTLFLAG_READWRITE, CTLTYPE_BOOL, "passive",
+           SYSCTL_DESCR("Passive cooling"), NULL, 0,
+           &acpicpu_passive, 0, CTL_CREATE, CTL_EOL);
+
+       if (err != 0)
+               goto fail;
+
+       return;
+
+fail:
+       aprint_error_dev(self, "failed to initialize sysctl (err %d)\n", err);
+}
+
 static int
 acpicpu_object(ACPI_HANDLE hdl, struct acpicpu_object *ao)
 {
@@ -492,6 +550,9 @@
        if (sc->sc_cold != false)
                return;
 
+       if (acpicpu_dynamic != true)
+               return;
+
        switch (evt) {
 
        case ACPICPU_C_NOTIFY:
diff -r fd8fda97b7fb -r 395d78136cdf sys/dev/acpi/acpi_cpu.h
--- a/sys/dev/acpi/acpi_cpu.h   Thu Dec 30 11:54:50 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu.h   Thu Dec 30 12:05:02 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.h,v 1.26 2010/11/30 04:31:00 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.h,v 1.27 2010/12/30 12:05:02 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -205,7 +205,6 @@
        uint32_t                 sc_flags;
        cpuid_t                  sc_cpuid;
        bool                     sc_cold;
-       bool                     sc_passive;
 };
 
 void           acpicpu_cstate_attach(device_t);
diff -r fd8fda97b7fb -r 395d78136cdf sys/dev/acpi/acpi_cpu_pstate.c
--- a/sys/dev/acpi/acpi_cpu_pstate.c    Thu Dec 30 11:54:50 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu_pstate.c    Thu Dec 30 12:05:02 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_pstate.c,v 1.35 2010/12/20 08:13:04 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_pstate.c,v 1.36 2010/12/30 12:05:02 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.35 2010/12/20 08:13:04 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.36 2010/12/30 12:05:02 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/evcnt.h>
@@ -346,26 +346,24 @@
        sc = device_private(self);
 
        mutex_enter(&sc->sc_mtx);
+
        old = sc->sc_pstate_max;
        acpicpu_pstate_change(sc);
        new = sc->sc_pstate_max;
+
+       if (old == new) {
+               mutex_exit(&sc->sc_mtx);
+               return;
+       }
+
        mutex_exit(&sc->sc_mtx);
 
-       if (old != new) {
+       ACPI_DEBUG_PRINT((ACPI_DB_INFO, "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));
 
-               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.
-                */
-               (void)acpicpu_pstate_set(sc, sc->sc_pstate[new].ps_freq);
-
-#endif
-       }
+       (void)acpicpu_pstate_set(sc, sc->sc_pstate[new].ps_freq);
 }
 
 ACPI_STATUS
@@ -800,9 +798,17 @@
        static ACPI_STATUS rv = AE_OK;
        ACPI_OBJECT_LIST arg;
        ACPI_OBJECT obj[2];
+       static int val = 0;
 
        acpicpu_pstate_reset(sc);
 
+       /*
+        * Cache the checks as the optional
+        * _PDL and _OST are rarely present.
+        */
+       if (val == 0)
+               val = acpicpu_pstate_min(sc);
+
        arg.Count = 2;
        arg.Pointer = obj;
 
@@ -812,9 +818,6 @@
        obj[0].Integer.Value = ACPICPU_P_NOTIFY;
        obj[1].Integer.Value = acpicpu_pstate_max(sc);
 
-       if (sc->sc_passive != false)
-               (void)acpicpu_pstate_min(sc);
-
        if (ACPI_FAILURE(rv))
                return;
 
diff -r fd8fda97b7fb -r 395d78136cdf sys/dev/acpi/acpi_cpu_tstate.c
--- a/sys/dev/acpi/acpi_cpu_tstate.c    Thu Dec 30 11:54:50 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu_tstate.c    Thu Dec 30 12:05:02 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_tstate.c,v 1.17 2010/12/20 08:13:04 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_tstate.c,v 1.18 2010/12/30 12:05:02 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_tstate.c,v 1.17 2010/12/20 08:13:04 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_tstate.c,v 1.18 2010/12/30 12:05:02 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/evcnt.h>
@@ -605,9 +605,6 @@
                        sc->sc_tstate_max = val;
        }
 
-       if (sc->sc_passive != true)
-               return AE_OK;
-
        rv = acpi_eval_integer(sc->sc_node->ad_handle, "_TDL", &val);
 
        if (ACPI_SUCCESS(rv) && val < sc->sc_tstate_count) {



Home | Main Index | Thread Index | Old Index