From b66af12b69e74d7fd023a0997efaeda814fa03a8 Mon Sep 17 00:00:00 2001 From: jruoho Date: Thu, 24 Mar 2011 05:10:05 +0000 Subject: [PATCH] Remove the "simple CPU lock" that was unnecessary. Thanks to rmind@ for clarifications. --- sys/arch/x86/acpi/acpi_cpu_md.c | 60 +++++++++++---------------------- sys/dev/acpi/acpi_cpu.c | 6 ++-- sys/dev/acpi/acpi_cpu.h | 5 ++- 3 files changed, 23 insertions(+), 48 deletions(-) diff --git a/sys/arch/x86/acpi/acpi_cpu_md.c b/sys/arch/x86/acpi/acpi_cpu_md.c index 6f0d020c6b7d..4ed38ff679a2 100644 --- a/sys/arch/x86/acpi/acpi_cpu_md.c +++ b/sys/arch/x86/acpi/acpi_cpu_md.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_cpu_md.c,v 1.55 2011/03/05 09:47:19 jruoho Exp $ */ +/* $NetBSD: acpi_cpu_md.c,v 1.56 2011/03/24 05:10:05 jruoho Exp $ */ /*- * Copyright (c) 2010, 2011 Jukka Ruohonen @@ -27,7 +27,7 @@ * SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.55 2011/03/05 09:47:19 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.56 2011/03/24 05:10:05 jruoho Exp $"); #include #include @@ -105,10 +105,8 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.55 2011/03/05 09:47:19 jruoho Exp static char native_idle_text[16]; void (*native_idle)(void) = NULL; -static u_long acpicpu_md_lock(struct acpicpu_softc *); -static void acpicpu_md_unlock(struct acpicpu_softc *, u_long); static int acpicpu_md_quirk_piix4(struct pci_attach_args *); -static void acpicpu_md_pstate_percent_reset(struct cpu_info *); +static void acpicpu_md_pstate_hwf_reset(void *, void *); static int acpicpu_md_pstate_fidvid_get(struct acpicpu_softc *, uint32_t *); static int acpicpu_md_pstate_fidvid_set(struct acpicpu_pstate *); @@ -142,24 +140,6 @@ acpicpu_md_attach(device_t parent, device_t self, void *aux) return cfaa->ci; } -static u_long -acpicpu_md_lock(struct acpicpu_softc *sc) -{ - const u_long flags = x86_read_psl(); - - x86_disable_intr(); - __cpu_simple_lock(&sc->sc_lock); - - return flags; -} - -static void -acpicpu_md_unlock(struct acpicpu_softc *sc, u_long flags) -{ - __cpu_simple_unlock(&sc->sc_lock); - x86_write_psl(flags); -} - uint32_t acpicpu_md_cap(void) { @@ -510,10 +490,10 @@ acpicpu_md_pstate_stop(void) int acpicpu_md_pstate_init(struct acpicpu_softc *sc) { + struct cpu_info *ci = sc->sc_ci; struct acpicpu_pstate *ps, msr; - struct cpu_info *ci = curcpu(); uint32_t family, i = 0; - uint64_t val; + uint64_t val, xc; (void)memset(&msr, 0, sizeof(struct acpicpu_pstate)); @@ -595,7 +575,6 @@ acpicpu_md_pstate_init(struct acpicpu_softc *sc) break; default: - /* * If we have an unknown AMD CPU, rely on XPSS. */ @@ -639,11 +618,11 @@ acpicpu_md_pstate_init(struct acpicpu_softc *sc) /* * Reset the APERF and MPERF counters. - * - * XXX: Should be with xc_unicast(9). */ - if ((sc->sc_flags & ACPICPU_FLAG_P_HWF) != 0) - acpicpu_md_pstate_percent_reset(sc->sc_ci); + if ((sc->sc_flags & ACPICPU_FLAG_P_HWF) != 0) { + xc = xc_unicast(0, acpicpu_md_pstate_hwf_reset, sc, NULL, ci); + xc_wait(xc); + } return 0; } @@ -671,12 +650,11 @@ acpicpu_md_pstate_init(struct acpicpu_softc *sc) * 2.4.5, Revision 3.48, April 2010. */ uint8_t -acpicpu_md_pstate_percent(struct cpu_info *ci) +acpicpu_md_pstate_hwf(struct cpu_info *ci) { struct acpicpu_softc *sc; uint64_t aperf, mperf; uint8_t rv = 0; - u_long flags; sc = acpicpu_sc[ci->ci_acpiid]; @@ -686,45 +664,45 @@ acpicpu_md_pstate_percent(struct cpu_info *ci) if (__predict_false((sc->sc_flags & ACPICPU_FLAG_P_HWF) == 0)) return 0; - flags = acpicpu_md_lock(sc); - aperf = sc->sc_pstate_aperf; mperf = sc->sc_pstate_mperf; + x86_disable_intr(); + sc->sc_pstate_aperf = rdmsr(MSR_APERF); sc->sc_pstate_mperf = rdmsr(MSR_MPERF); + x86_enable_intr(); + aperf = sc->sc_pstate_aperf - aperf; mperf = sc->sc_pstate_mperf - mperf; if (__predict_true(mperf != 0)) rv = (aperf * 100) / mperf; - acpicpu_md_unlock(sc, flags); - return rv; } static void -acpicpu_md_pstate_percent_reset(struct cpu_info *ci) +acpicpu_md_pstate_hwf_reset(void *arg1, void *arg2) { + struct cpu_info *ci = curcpu(); struct acpicpu_softc *sc; - u_long flags; sc = acpicpu_sc[ci->ci_acpiid]; if (__predict_false(sc == NULL)) return; - flags = acpicpu_md_lock(sc); + x86_disable_intr(); wrmsr(MSR_APERF, 0); wrmsr(MSR_MPERF, 0); + x86_enable_intr(); + sc->sc_pstate_aperf = 0; sc->sc_pstate_mperf = 0; - - acpicpu_md_unlock(sc, flags); } int diff --git a/sys/dev/acpi/acpi_cpu.c b/sys/dev/acpi/acpi_cpu.c index 98bc5b2b9949..24ad41e95a6f 100644 --- a/sys/dev/acpi/acpi_cpu.c +++ b/sys/dev/acpi/acpi_cpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_cpu.c,v 1.38 2011/03/19 12:57:30 jruoho Exp $ */ +/* $NetBSD: acpi_cpu.c,v 1.39 2011/03/24 05:10:06 jruoho Exp $ */ /*- * Copyright (c) 2010, 2011 Jukka Ruohonen @@ -27,7 +27,7 @@ * SUCH DAMAGE. */ #include -__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.38 2011/03/19 12:57:30 jruoho Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_cpu.c,v 1.39 2011/03/24 05:10:06 jruoho Exp $"); #include #include @@ -187,8 +187,6 @@ acpicpu_attach(device_t parent, device_t self, void *aux) KASSERT(sc->sc_node->ad_device == NULL); sc->sc_node->ad_device = self; - - __cpu_simple_lock_init(&sc->sc_lock); mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE); acpicpu_cstate_attach(self); diff --git a/sys/dev/acpi/acpi_cpu.h b/sys/dev/acpi/acpi_cpu.h index 0f0492a94125..54f154b7a287 100644 --- a/sys/dev/acpi/acpi_cpu.h +++ b/sys/dev/acpi/acpi_cpu.h @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_cpu.h,v 1.39 2011/03/19 12:57:31 jruoho Exp $ */ +/* $NetBSD: acpi_cpu.h,v 1.40 2011/03/24 05:10:06 jruoho Exp $ */ /*- * Copyright (c) 2010, 2011 Jukka Ruohonen @@ -224,7 +224,6 @@ struct acpicpu_softc { uint32_t sc_tstate_max; uint32_t sc_tstate_min; - __cpu_simple_lock_t sc_lock; kmutex_t sc_mtx; uint32_t sc_cap; uint32_t sc_ncpus; @@ -270,7 +269,7 @@ void acpicpu_md_cstate_enter(int, int); int acpicpu_md_pstate_start(struct acpicpu_softc *); int acpicpu_md_pstate_stop(void); int acpicpu_md_pstate_init(struct acpicpu_softc *); -uint8_t acpicpu_md_pstate_percent(struct cpu_info *); +uint8_t acpicpu_md_pstate_hwf(struct cpu_info *); int acpicpu_md_pstate_get(struct acpicpu_softc *, uint32_t *); int acpicpu_md_pstate_set(struct acpicpu_pstate *); int acpicpu_md_tstate_get(struct acpicpu_softc *, uint32_t *);