Module Name:    src
Committed By:   jruoho
Date:           Wed Jun 22 08:49:54 UTC 2011

Modified Files:
        src/sys/arch/x86/acpi: acpi_cpu_md.c
        src/sys/dev/acpi: acpi_cpu.c acpi_cpu.h acpi_cpu_cstate.c
            acpi_cpu_pstate.c acpi_cpu_tstate.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/arch/x86/acpi/acpi_cpu_md.c
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/acpi/acpi_cpu.c
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/acpi/acpi_cpu.h
cvs rdiff -u -r1.52 -r1.53 src/sys/dev/acpi/acpi_cpu_cstate.c
cvs rdiff -u -r1.50 -r1.51 src/sys/dev/acpi/acpi_cpu_pstate.c
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/acpi/acpi_cpu_tstate.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/arch/x86/acpi/acpi_cpu_md.c
diff -u src/sys/arch/x86/acpi/acpi_cpu_md.c:1.61 src/sys/arch/x86/acpi/acpi_cpu_md.c:1.62
--- src/sys/arch/x86/acpi/acpi_cpu_md.c:1.61	Sun Jun 12 10:11:52 2011
+++ src/sys/arch/x86/acpi/acpi_cpu_md.c	Wed Jun 22 08:49:54 2011
@@ -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 <jruoho...@iki.fi>
@@ -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.

Index: src/sys/dev/acpi/acpi_cpu.c
diff -u src/sys/dev/acpi/acpi_cpu.c:1.43 src/sys/dev/acpi/acpi_cpu.c:1.44
--- src/sys/dev/acpi/acpi_cpu.c:1.43	Tue Jun 21 03:37:21 2011
+++ src/sys/dev/acpi/acpi_cpu.c	Wed Jun 22 08:49:54 2011
@@ -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 <jruoho...@iki.fi>
@@ -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--;

Index: src/sys/dev/acpi/acpi_cpu.h
diff -u src/sys/dev/acpi/acpi_cpu.h:1.41 src/sys/dev/acpi/acpi_cpu.h:1.42
--- src/sys/dev/acpi/acpi_cpu.h:1.41	Sun Jun 12 10:11:52 2011
+++ src/sys/dev/acpi/acpi_cpu.h	Wed Jun 22 08:49:54 2011
@@ -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 <jruoho...@iki.fi>
@@ -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 *);

Index: src/sys/dev/acpi/acpi_cpu_cstate.c
diff -u src/sys/dev/acpi/acpi_cpu_cstate.c:1.52 src/sys/dev/acpi/acpi_cpu_cstate.c:1.53
--- src/sys/dev/acpi/acpi_cpu_cstate.c:1.52	Sat Mar 19 12:57:31 2011
+++ src/sys/dev/acpi/acpi_cpu_cstate.c	Wed Jun 22 08:49:54 2011
@@ -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 <jruoho...@iki.fi>
@@ -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

Index: src/sys/dev/acpi/acpi_cpu_pstate.c
diff -u src/sys/dev/acpi/acpi_cpu_pstate.c:1.50 src/sys/dev/acpi/acpi_cpu_pstate.c:1.51
--- src/sys/dev/acpi/acpi_cpu_pstate.c:1.50	Wed Jun 22 08:05:10 2011
+++ src/sys/dev/acpi/acpi_cpu_pstate.c	Wed Jun 22 08:49:54 2011
@@ -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 <jruoho...@iki.fi>
@@ -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;
-
-	rv = RUN_ONCE(&once_detach, acpicpu_md_pstate_stop);
+		return;
 
-	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);
 
 	sc->sc_flags &= ~ACPICPU_FLAG_P;
-
-	return 0;
 }
 
 void

Index: src/sys/dev/acpi/acpi_cpu_tstate.c
diff -u src/sys/dev/acpi/acpi_cpu_tstate.c:1.29 src/sys/dev/acpi/acpi_cpu_tstate.c:1.30
--- src/sys/dev/acpi/acpi_cpu_tstate.c:1.29	Wed Jun 22 08:05:10 2011
+++ src/sys/dev/acpi/acpi_cpu_tstate.c	Wed Jun 22 08:49:54 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_tstate.c,v 1.29 2011/06/22 08:05:10 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_tstate.c,v 1.30 2011/06/22 08:49:54 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_tstate.c,v 1.29 2011/06/22 08:05:10 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_tstate.c,v 1.30 2011/06/22 08:49:54 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -120,14 +120,14 @@
 	acpicpu_tstate_reset(sc);
 }
 
-int
+void
 acpicpu_tstate_detach(device_t self)
 {
 	struct acpicpu_softc *sc = device_private(self);
 	size_t size;
 
 	if ((sc->sc_flags & ACPICPU_FLAG_T) == 0)
-		return 0;
+		return;
 
 	size = sc->sc_tstate_count * sizeof(*sc->sc_tstate);
 
@@ -135,8 +135,6 @@
 		kmem_free(sc->sc_tstate, size);
 
 	sc->sc_flags &= ~ACPICPU_FLAG_T;
-
-	return 0;
 }
 
 void

Reply via email to