Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/acpi Use evcnt(9) for the counters.



details:   https://anonhg.NetBSD.org/src/rev/97938fe6a642
branches:  trunk
changeset: 757001:97938fe6a642
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Tue Aug 10 02:42:05 2010 +0000

description:
Use evcnt(9) for the counters.

diffstat:

 sys/dev/acpi/acpi_cpu.h        |   8 ++-
 sys/dev/acpi/acpi_cpu_cstate.c |  79 ++++++++++++++++++++++++++++++++++++++---
 sys/dev/acpi/acpi_cpu_pstate.c |  47 +++++++++++++++++++++++-
 3 files changed, 122 insertions(+), 12 deletions(-)

diffs (289 lines):

diff -r eb643ac03a7a -r 97938fe6a642 sys/dev/acpi/acpi_cpu.h
--- a/sys/dev/acpi/acpi_cpu.h   Mon Aug 09 23:08:59 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu.h   Tue Aug 10 02:42:05 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu.h,v 1.11 2010/08/09 13:41:38 jruoho Exp $ */
+/* $NetBSD: acpi_cpu.h,v 1.12 2010/08/10 02:42:05 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -121,7 +121,8 @@
 } __packed;
 
 struct acpicpu_cstate {
-       uint64_t                 cs_stat;
+       struct evcnt             cs_evcnt;
+       char                     cs_name[EVCNT_STRING_MAX];
        uint64_t                 cs_addr;
        uint32_t                 cs_power;      /* mW */
        uint32_t                 cs_latency;    /* us */
@@ -130,7 +131,8 @@
 };
 
 struct acpicpu_pstate {
-       uint64_t                 ps_stat;
+       struct evcnt             ps_evcnt;
+       char                     ps_name[EVCNT_STRING_MAX];
        uint32_t                 ps_freq;       /* MHz */
        uint32_t                 ps_power;      /* mW */
        uint32_t                 ps_latency;    /* us */
diff -r eb643ac03a7a -r 97938fe6a642 sys/dev/acpi/acpi_cpu_cstate.c
--- a/sys/dev/acpi/acpi_cpu_cstate.c    Mon Aug 09 23:08:59 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu_cstate.c    Tue Aug 10 02:42:05 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_cstate.c,v 1.18 2010/08/09 13:41:38 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_cstate.c,v 1.19 2010/08/10 02:42:05 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,11 +27,12 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.18 2010/08/09 13:41:38 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.19 2010/08/10 02:42:05 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/cpu.h>
 #include <sys/device.h>
+#include <sys/evcnt.h>
 #include <sys/kernel.h>
 #include <sys/once.h>
 #include <sys/mutex.h>
@@ -51,10 +52,13 @@
 ACPI_MODULE_NAME        ("acpi_cpu_cstate")
 
 static void             acpicpu_cstate_attach_print(struct acpicpu_softc *);
+static void             acpicpu_cstate_attach_evcnt(struct acpicpu_softc *);
+static void             acpicpu_cstate_detach_evcnt(struct acpicpu_softc *);
 static ACPI_STATUS      acpicpu_cstate_cst(struct acpicpu_softc *);
 static ACPI_STATUS      acpicpu_cstate_cst_add(struct acpicpu_softc *,
                                                ACPI_OBJECT *);
 static void             acpicpu_cstate_cst_bios(void);
+static void             acpicpu_cstate_memset(struct acpicpu_softc *);
 static void             acpicpu_cstate_fadt(struct acpicpu_softc *);
 static void             acpicpu_cstate_quirks(struct acpicpu_softc *);
 static int              acpicpu_cstate_quirks_piix4(struct pci_attach_args *);
@@ -101,6 +105,7 @@
        }
 
        acpicpu_cstate_quirks(sc);
+       acpicpu_cstate_attach_evcnt(sc);
        acpicpu_cstate_attach_print(sc);
 }
 
@@ -143,6 +148,36 @@
        }
 }
 
+static void
+acpicpu_cstate_attach_evcnt(struct acpicpu_softc *sc)
+{
+       struct acpicpu_cstate *cs;
+       const char *str;
+       int i;
+
+       for (i = 0; i < ACPI_C_STATE_COUNT; i++) {
+
+               cs = &sc->sc_cstate[i];
+
+               if (cs->cs_method == 0)
+                       continue;
+
+               str = "HALT";
+
+               if (cs->cs_method == ACPICPU_C_STATE_FFH)
+                       str = "MWAIT";
+
+               if (cs->cs_method == ACPICPU_C_STATE_SYSIO)
+                       str = "I/O";
+
+               (void)snprintf(cs->cs_name, sizeof(cs->cs_name),
+                   "C%d (%s)", i, str);
+
+               evcnt_attach_dynamic(&cs->cs_evcnt, EVCNT_TYPE_MISC,
+                   NULL, device_xname(sc->sc_dev), cs->cs_name);
+       }
+}
+
 int
 acpicpu_cstate_detach(device_t self)
 {
@@ -156,10 +191,26 @@
                return rv;
 
        sc->sc_flags &= ~ACPICPU_FLAG_C;
+       acpicpu_cstate_detach_evcnt(sc);
 
        return 0;
 }
 
+static void
+acpicpu_cstate_detach_evcnt(struct acpicpu_softc *sc)
+{
+       struct acpicpu_cstate *cs;
+       int i;
+
+       for (i = 0; i < ACPI_C_STATE_COUNT; i++) {
+
+               cs = &sc->sc_cstate[i];
+
+               if (cs->cs_method != 0)
+                       evcnt_detach(&cs->cs_evcnt);
+       }
+}
+
 int
 acpicpu_cstate_start(device_t self)
 {
@@ -261,8 +312,7 @@
                goto out;
        }
 
-       (void)memset(sc->sc_cstate, 0,
-           sizeof(*sc->sc_cstate) * ACPI_C_STATE_COUNT);
+       acpicpu_cstate_memset(sc);
 
        CTASSERT(ACPI_STATE_C0 == 0 && ACPI_STATE_C1 == 1);
        CTASSERT(ACPI_STATE_C2 == 2 && ACPI_STATE_C3 == 3);
@@ -471,11 +521,28 @@
 }
 
 static void
+acpicpu_cstate_memset(struct acpicpu_softc *sc)
+{
+       int i = 0;
+
+       while (i < ACPI_C_STATE_COUNT) {
+
+               sc->sc_cstate[i].cs_addr = 0;
+               sc->sc_cstate[i].cs_power = 0;
+               sc->sc_cstate[i].cs_flags = 0;
+               sc->sc_cstate[i].cs_method = 0;
+               sc->sc_cstate[i].cs_latency = 0;
+
+               i++;
+       }
+}
+
+static void
 acpicpu_cstate_fadt(struct acpicpu_softc *sc)
 {
        struct acpicpu_cstate *cs = sc->sc_cstate;
 
-       (void)memset(cs, 0, sizeof(*cs) * ACPI_C_STATE_COUNT);
+       acpicpu_cstate_memset(sc);
 
        /*
         * All x86 processors should support C1 (a.k.a. HALT).
@@ -720,7 +787,7 @@
                break;
        }
 
-       cs->cs_stat++;
+       cs->cs_evcnt.ev_count++;
 
        end = acpitimer_read_safe(NULL);
        sc->sc_cstate_sleep = hztoms(acpitimer_delta(end, start)) * 1000;
diff -r eb643ac03a7a -r 97938fe6a642 sys/dev/acpi/acpi_cpu_pstate.c
--- a/sys/dev/acpi/acpi_cpu_pstate.c    Mon Aug 09 23:08:59 2010 +0000
+++ b/sys/dev/acpi/acpi_cpu_pstate.c    Tue Aug 10 02:42:05 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_pstate.c,v 1.6 2010/08/09 15:56:45 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_pstate.c,v 1.7 2010/08/10 02:42:05 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen <jruohonen%iki.fi@localhost>
@@ -27,9 +27,10 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.6 2010/08/09 15:56:45 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_pstate.c,v 1.7 2010/08/10 02:42:05 jruoho Exp $");
 
 #include <sys/param.h>
+#include <sys/evcnt.h>
 #include <sys/kmem.h>
 #include <sys/once.h>
 
@@ -41,6 +42,8 @@
 ACPI_MODULE_NAME        ("acpi_cpu_pstate")
 
 static void             acpicpu_pstate_attach_print(struct acpicpu_softc *);
+static void             acpicpu_pstate_attach_evcnt(struct acpicpu_softc *);
+static void             acpicpu_pstate_detach_evcnt(struct acpicpu_softc *);
 static ACPI_STATUS      acpicpu_pstate_pss(struct acpicpu_softc *sc);
 static ACPI_STATUS      acpicpu_pstate_pss_add(struct acpicpu_pstate *,
                                                ACPI_OBJECT *);
@@ -84,6 +87,7 @@
        sc->sc_pstate_current = sc->sc_pstate[0].ps_freq;
 
        acpicpu_pstate_bios();
+       acpicpu_pstate_attach_evcnt(sc);
        acpicpu_pstate_attach_print(sc);
 
        return;
@@ -116,6 +120,27 @@
        }
 }
 
+static void
+acpicpu_pstate_attach_evcnt(struct acpicpu_softc *sc)
+{
+       struct acpicpu_pstate *ps;
+       uint32_t i;
+
+       for (i = 0; i < sc->sc_pstate_count; i++) {
+
+               ps = &sc->sc_pstate[i];
+
+               if (ps->ps_freq == 0)
+                       continue;
+
+               (void)snprintf(ps->ps_name, sizeof(ps->ps_name),
+                   "P%u (%u MHz)", i, ps->ps_freq);
+
+               evcnt_attach_dynamic(&ps->ps_evcnt, EVCNT_TYPE_MISC,
+                   NULL, device_xname(sc->sc_dev), ps->ps_name);
+       }
+}
+
 int
 acpicpu_pstate_detach(device_t self)
 {
@@ -138,10 +163,26 @@
                kmem_free(sc->sc_pstate, size);
 
        sc->sc_flags &= ~ACPICPU_FLAG_P;
+       acpicpu_pstate_detach_evcnt(sc);
 
        return 0;
 }
 
+static void
+acpicpu_pstate_detach_evcnt(struct acpicpu_softc *sc)
+{
+       struct acpicpu_pstate *ps;
+       uint32_t i;
+
+       for (i = 0; i < sc->sc_pstate_count; i++) {
+
+               ps = &sc->sc_pstate[i];
+
+               if (ps->ps_freq != 0)
+                       evcnt_detach(&ps->ps_evcnt);
+       }
+}
+
 int
 acpicpu_pstate_start(device_t self)
 {
@@ -647,7 +688,7 @@
                goto fail;
        }
 
-       ps->ps_stat++;
+       ps->ps_evcnt.ev_count++;
        sc->sc_pstate_current = freq;
 
        return 0;



Home | Main Index | Thread Index | Old Index