Source-Changes-HG archive

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

[src/trunk]: src/sys Get rid of RUN_ONCE(9). Should fix PR # kern/44043.



details:   https://anonhg.NetBSD.org/src/rev/fcd69a80fd87
branches:  trunk
changeset: 766433:fcd69a80fd87
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Wed Jun 22 08:49:54 2011 +0000

description:
Get rid of RUN_ONCE(9). Should fix PR # kern/44043.

diffstat:

 sys/arch/x86/acpi/acpi_cpu_md.c |  58 ++++++++++++++++++++++++----------------
 sys/dev/acpi/acpi_cpu.c         |  26 +++--------------
 sys/dev/acpi/acpi_cpu.h         |   8 ++--
 sys/dev/acpi/acpi_cpu_cstate.c  |  17 ++++-------
 sys/dev/acpi/acpi_cpu_pstate.c  |  18 +++---------
 sys/dev/acpi/acpi_cpu_tstate.c  |  10 ++----
 6 files changed, 58 insertions(+), 79 deletions(-)

diffs (truncated from 351 to 300 lines):

diff -r a790811e8528 -r fcd69a80fd87 sys/arch/x86/acpi/acpi_cpu_md.c
--- a/sys/arch/x86/acpi/acpi_cpu_md.c   Wed Jun 22 08:05:10 2011 +0000
+++ b/sys/arch/x86/acpi/acpi_cpu_md.c   Wed Jun 22 08:49:54 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_md.c,v 1.61 2011/06/12 10:11:52 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_md.c,v 1.62 2011/06/22 08:49:54 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.61 2011/06/12 10:11:52 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.62 2011/06/22 08:49:54 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -373,9 +373,16 @@
 int
 acpicpu_md_cstate_stop(void)
 {
+       static char text[16];
+       void (*func)(void);
        uint64_t xc;
        bool ipi;
 
+       x86_cpu_idle_get(&func, text, sizeof(text));
+
+       if (func == native_idle)
+               return EALREADY;
+
        ipi = (native_idle != x86_cpu_idle_halt) ? false : true;
        x86_cpu_idle_set(native_idle, native_idle_text, ipi);
 
@@ -424,7 +431,25 @@
 int
 acpicpu_md_pstate_start(struct acpicpu_softc *sc)
 {
-       uint64_t xc;
+       uint64_t xc, val;
+
+       /*
+        * Make sure EST is enabled.
+        */
+       if ((sc->sc_flags & ACPICPU_FLAG_P_FFH) != 0) {
+
+               val = rdmsr(MSR_MISC_ENABLE);
+
+               if ((val & MSR_MISC_ENABLE_EST) == 0) {
+
+                       val |= MSR_MISC_ENABLE_EST;
+                       wrmsr(MSR_MISC_ENABLE, val);
+                       val = rdmsr(MSR_MISC_ENABLE);
+
+                       if ((val & MSR_MISC_ENABLE_EST) == 0)
+                               return ENOTTY;
+               }
+       }
 
        /*
         * Reset the APERF and MPERF counters.
@@ -440,8 +465,12 @@
 int
 acpicpu_md_pstate_stop(void)
 {
-       if (acpicpu_log != NULL)
-               sysctl_teardown(&acpicpu_log);
+
+       if (acpicpu_log == NULL)
+               return EALREADY;
+
+       sysctl_teardown(&acpicpu_log);
+       acpicpu_log = NULL;
 
        return 0;
 }
@@ -452,7 +481,6 @@
        struct cpu_info *ci = sc->sc_ci;
        struct acpicpu_pstate *ps, msr;
        uint32_t family, i = 0;
-       uint64_t val;
 
        (void)memset(&msr, 0, sizeof(struct acpicpu_pstate));
 
@@ -462,24 +490,6 @@
        case CPUVENDOR_INTEL:
 
                /*
-                * Make sure EST is enabled.
-                */
-               if ((sc->sc_flags & ACPICPU_FLAG_P_FFH) != 0) {
-
-                       val = rdmsr(MSR_MISC_ENABLE);
-
-                       if ((val & MSR_MISC_ENABLE_EST) == 0) {
-
-                               val |= MSR_MISC_ENABLE_EST;
-                               wrmsr(MSR_MISC_ENABLE, val);
-                               val = rdmsr(MSR_MISC_ENABLE);
-
-                               if ((val & MSR_MISC_ENABLE_EST) == 0)
-                                       return ENOTTY;
-                       }
-               }
-
-               /*
                 * If the so-called Turbo Boost is present,
                 * the P0-state is always the "turbo state".
                 * It is shown as the P1 frequency + 1 MHz.
diff -r a790811e8528 -r fcd69a80fd87 sys/dev/acpi/acpi_cpu.c
--- a/sys/dev/acpi/acpi_cpu.c   Wed Jun 22 08:05:10 2011 +0000
+++ b/sys/dev/acpi/acpi_cpu.c   Wed Jun 22 08:49:54 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.c,v 1.43 2011/06/21 03:37:21 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.c,v 1.44 2011/06/22 08:49:54 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 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.43 2011/06/21 03:37:21 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.44 2011/06/22 08:49:54 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
@@ -202,33 +202,17 @@
 acpicpu_detach(device_t self, int flags)
 {
        struct acpicpu_softc *sc = device_private(self);
-       int rv = 0;
 
        sc->sc_cold = true;
 
        acpicpu_evcnt_detach(self);
        acpi_deregister_notify(sc->sc_node);
 
-       if ((sc->sc_flags & ACPICPU_FLAG_C) != 0)
-               rv = acpicpu_cstate_detach(self);
-
-       if (rv != 0)
-               return rv;
-
-       if ((sc->sc_flags & ACPICPU_FLAG_P) != 0)
-               rv = acpicpu_pstate_detach(self);
-
-       if (rv != 0)
-               return rv;
-
-       if ((sc->sc_flags & ACPICPU_FLAG_T) != 0)
-               rv = acpicpu_tstate_detach(self);
-
-       if (rv != 0)
-               return rv;
+       acpicpu_cstate_detach(self);
+       acpicpu_pstate_detach(self);
+       acpicpu_tstate_detach(self);
 
        mutex_destroy(&sc->sc_mtx);
-
        sc->sc_node->ad_device = NULL;
 
        acpicpu_count--;
diff -r a790811e8528 -r fcd69a80fd87 sys/dev/acpi/acpi_cpu.h
--- a/sys/dev/acpi/acpi_cpu.h   Wed Jun 22 08:05:10 2011 +0000
+++ b/sys/dev/acpi/acpi_cpu.h   Wed Jun 22 08:49:54 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.h,v 1.41 2011/06/12 10:11:52 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.h,v 1.42 2011/06/22 08:49:54 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -232,7 +232,7 @@
 };
 
 void            acpicpu_cstate_attach(device_t);
-int             acpicpu_cstate_detach(device_t);
+void            acpicpu_cstate_detach(device_t);
 void            acpicpu_cstate_start(device_t);
 void            acpicpu_cstate_suspend(void *);
 void            acpicpu_cstate_resume(void *);
@@ -240,7 +240,7 @@
 void            acpicpu_cstate_idle(void);
 
 void            acpicpu_pstate_attach(device_t);
-int             acpicpu_pstate_detach(device_t);
+void            acpicpu_pstate_detach(device_t);
 void            acpicpu_pstate_start(device_t);
 void            acpicpu_pstate_suspend(void *);
 void            acpicpu_pstate_resume(void *);
@@ -249,7 +249,7 @@
 void            acpicpu_pstate_set(struct cpu_info *, uint32_t);
 
 void            acpicpu_tstate_attach(device_t);
-int             acpicpu_tstate_detach(device_t);
+void            acpicpu_tstate_detach(device_t);
 void            acpicpu_tstate_start(device_t);
 void            acpicpu_tstate_suspend(void *);
 void            acpicpu_tstate_resume(void *);
diff -r a790811e8528 -r fcd69a80fd87 sys/dev/acpi/acpi_cpu_cstate.c
--- a/sys/dev/acpi/acpi_cpu_cstate.c    Wed Jun 22 08:05:10 2011 +0000
+++ b/sys/dev/acpi/acpi_cpu_cstate.c    Wed Jun 22 08:49:54 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_cstate.c,v 1.52 2011/03/19 12:57:31 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_cstate.c,v 1.53 2011/06/22 08:49:54 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,13 +27,12 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.52 2011/03/19 12:57:31 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.53 2011/06/22 08:49:54 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
 #include <sys/device.h>
 #include <sys/kernel.h>
-#include <sys/once.h>
 #include <sys/mutex.h>
 #include <sys/timetc.h>
 
@@ -109,21 +108,17 @@
        acpicpu_cstate_quirks(sc);
 }
 
-int
+void
 acpicpu_cstate_detach(device_t self)
 {
        struct acpicpu_softc *sc = device_private(self);
-       static ONCE_DECL(once_detach);
-       int rv;
 
-       rv = RUN_ONCE(&once_detach, acpicpu_md_cstate_stop);
+       if ((sc->sc_flags & ACPICPU_FLAG_C) == 0)
+               return;
 
-       if (rv != 0)
-               return rv;
+       (void)acpicpu_md_cstate_stop();
 
        sc->sc_flags &= ~ACPICPU_FLAG_C;
-
-       return 0;
 }
 
 void
diff -r a790811e8528 -r fcd69a80fd87 sys/dev/acpi/acpi_cpu_pstate.c
--- a/sys/dev/acpi/acpi_cpu_pstate.c    Wed Jun 22 08:05:10 2011 +0000
+++ b/sys/dev/acpi/acpi_cpu_pstate.c    Wed Jun 22 08:49:54 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_pstate.c,v 1.50 2011/06/22 08:05:10 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_pstate.c,v 1.51 2011/06/22 08:49:54 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,11 +27,10 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.50 2011/06/22 08:05:10 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.51 2011/06/22 08:49:54 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
-#include <sys/once.h>
 #include <sys/xcall.h>
 
 #include <dev/acpi/acpireg.h>
@@ -153,21 +152,16 @@
        }
 }
 
-int
+void
 acpicpu_pstate_detach(device_t self)
 {
        struct acpicpu_softc *sc = device_private(self);
-       static ONCE_DECL(once_detach);
        size_t size;
-       int rv;
 
        if ((sc->sc_flags & ACPICPU_FLAG_P) == 0)
-               return 0;
+               return;
 
-       rv = RUN_ONCE(&once_detach, acpicpu_md_pstate_stop);
-
-       if (rv != 0)
-               return rv;
+       (void)acpicpu_md_pstate_stop();
 
        size = sc->sc_pstate_count * sizeof(*sc->sc_pstate);
 
@@ -175,8 +169,6 @@
                kmem_free(sc->sc_pstate, size);



Home | Main Index | Thread Index | Old Index