Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Revert the previous changes to EST. The used hack h...



details:   https://anonhg.NetBSD.org/src/rev/e5c7216d7df8
branches:  trunk
changeset: 756987:e5c7216d7df8
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Mon Aug 09 15:46:17 2010 +0000

description:
Revert the previous changes to EST. The used hack had an obvious flaw:
the acpicpu(4) driver should attach even if the existing frequency management
code fails to attach, mainly because ACPI is the only proper way to deal
with EST on new Intel system.

Use a more drastic hack to deal with this: when acpicpu(4) attachs, it tears
down any existing sysctl(8) controls and installs identical ones in place.
Upon detachment, the initialization function of the existing EST is called.

diffstat:

 sys/arch/x86/acpi/acpi_cpu_md.c |  95 +++++++++++++++++++++++++++++++++++++---
 sys/arch/x86/include/cpuvar.h   |   7 +-
 sys/arch/x86/x86/cpu.c          |   9 +--
 sys/arch/x86/x86/est.c          |  91 ++++++++++----------------------------
 sys/arch/xen/x86/cpu.c          |   7 ++-
 5 files changed, 123 insertions(+), 86 deletions(-)

diffs (truncated from 385 to 300 lines):

diff -r f410c3f50939 -r e5c7216d7df8 sys/arch/x86/acpi/acpi_cpu_md.c
--- a/sys/arch/x86/acpi/acpi_cpu_md.c   Mon Aug 09 15:39:41 2010 +0000
+++ b/sys/arch/x86/acpi/acpi_cpu_md.c   Mon Aug 09 15:46:17 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_md.c,v 1.8 2010/08/09 13:41:39 jruoho Exp $ */
+/* $NetBSD: acpi_cpu_md.c,v 1.9 2010/08/09 15:46:17 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_md.c,v 1.8 2010/08/09 13:41:39 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_md.c,v 1.9 2010/08/09 15:46:17 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -47,6 +47,7 @@
 
 static char      native_idle_text[16];
 void           (*native_idle)(void) = NULL;
+void           (*native_cpu_freq_init)(int) = NULL;
 
 static int      acpicpu_md_pstate_sysctl_get(SYSCTLFN_PROTO);
 static int      acpicpu_md_pstate_sysctl_set(SYSCTLFN_PROTO);
@@ -205,21 +206,97 @@
 int
 acpicpu_md_pstate_start(void)
 {
+       const struct sysctlnode *fnode, *mnode, *rnode;
+       const char *str;
+       int rv;
 
-       cpu_freq_sysctl_get = acpicpu_md_pstate_sysctl_get;
-       cpu_freq_sysctl_set = acpicpu_md_pstate_sysctl_set;
-       cpu_freq_sysctl_all = acpicpu_md_pstate_sysctl_all;
+       switch (cpu_vendor) {
+
+       case CPUVENDOR_INTEL:
+               str = "est";
+               break;
+
+       default:
+               return ENODEV;
+       }
+
+       /*
+        * A kludge for backwards compatibility.
+        */
+       native_cpu_freq_init = cpu_freq_init;
+
+       if (cpu_freq_sysctllog != NULL) {
+               sysctl_teardown(&cpu_freq_sysctllog);
+               cpu_freq_sysctllog = NULL;
+       }
+
+       rv = sysctl_createv(&cpu_freq_sysctllog, 0, NULL, &rnode,
+           CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
+           NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL);
+
+       if (rv != 0)
+               goto fail;
+
+       rv = sysctl_createv(&cpu_freq_sysctllog, 0, &rnode, &mnode,
+           0, CTLTYPE_NODE, str, NULL,
+           NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+
+       if (rv != 0)
+               goto fail;
+
+       rv = sysctl_createv(&cpu_freq_sysctllog, 0, &mnode, &fnode,
+           0, CTLTYPE_NODE, "frequency", NULL,
+           NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+
+       if (rv != 0)
+               goto fail;
+
+       rv = sysctl_createv(&cpu_freq_sysctllog, 0, &fnode, &rnode,
+           CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
+           acpicpu_md_pstate_sysctl_set, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+
+       if (rv != 0)
+               goto fail;
+
+       rv = sysctl_createv(&cpu_freq_sysctllog, 0, &fnode, &rnode,
+           CTLFLAG_READONLY, CTLTYPE_INT, "current", NULL,
+           acpicpu_md_pstate_sysctl_get, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+
+       if (rv != 0)
+               goto fail;
+
+       rv = sysctl_createv(&cpu_freq_sysctllog, 0, &fnode, &rnode,
+           CTLFLAG_READONLY, CTLTYPE_STRING, "available", NULL,
+           acpicpu_md_pstate_sysctl_all, 0, NULL, 0, CTL_CREATE, CTL_EOL);
+
+       if (rv != 0)
+               goto fail;
 
        return 0;
+
+fail:
+       if (cpu_freq_sysctllog != NULL) {
+               sysctl_teardown(&cpu_freq_sysctllog);
+               cpu_freq_sysctllog = NULL;
+       }
+
+       if (native_cpu_freq_init != NULL)
+               (*native_cpu_freq_init)(cpu_vendor);
+
+       return rv;
 }
 
 int
 acpicpu_md_pstate_stop(void)
 {
 
-       cpu_freq_sysctl_get = NULL;
-       cpu_freq_sysctl_set = NULL;
-       cpu_freq_sysctl_all = NULL;
+       if (cpu_freq_sysctllog != NULL) {
+               sysctl_teardown(&cpu_freq_sysctllog);
+               cpu_freq_sysctllog = NULL;
+       }
+
+       if (native_cpu_freq_init != NULL)
+               (*native_cpu_freq_init)(cpu_vendor);
 
        return 0;
 }
@@ -238,7 +315,7 @@
         * frequencies. In MP environments all CPUs
         * are mandated to support the same number of
         * P-states and each state must have identical
-        * parameters across CPUs.
+        * parameters across processors.
         */
        sc = acpicpu_sc[ci->ci_acpiid];
 
diff -r f410c3f50939 -r e5c7216d7df8 sys/arch/x86/include/cpuvar.h
--- a/sys/arch/x86/include/cpuvar.h     Mon Aug 09 15:39:41 2010 +0000
+++ b/sys/arch/x86/include/cpuvar.h     Mon Aug 09 15:46:17 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpuvar.h,v 1.36 2010/08/09 04:18:48 jruoho Exp $ */
+/*     $NetBSD: cpuvar.h,v 1.37 2010/08/09 15:46:17 jruoho Exp $ */
 
 /*-
  * Copyright (c) 2000, 2007 The NetBSD Foundation, Inc.
@@ -142,9 +142,8 @@
 int    p4_get_bus_clock(struct cpu_info *);
 #endif
 
-extern int (*cpu_freq_sysctl_get)(SYSCTLFN_PROTO);
-extern int (*cpu_freq_sysctl_set)(SYSCTLFN_PROTO);
-extern int (*cpu_freq_sysctl_all)(SYSCTLFN_PROTO);
+extern void (*cpu_freq_init)(int);
+extern struct sysctllog *cpu_freq_sysctllog;
 
 void   cpu_get_tsc_freq(struct cpu_info *);
 void   pat_init(struct cpu_info *);
diff -r f410c3f50939 -r e5c7216d7df8 sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c    Mon Aug 09 15:39:41 2010 +0000
+++ b/sys/arch/x86/x86/cpu.c    Mon Aug 09 15:46:17 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.c,v 1.75 2010/08/09 04:18:48 jruoho Exp $  */
+/*     $NetBSD: cpu.c,v 1.76 2010/08/09 15:46:17 jruoho Exp $  */
 
 /*-
  * Copyright (c) 2000, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.75 2010/08/09 04:18:48 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.76 2010/08/09 15:46:17 jruoho Exp $");
 
 #include "opt_ddb.h"
 #include "opt_mpbios.h"                /* for MPDEBUG */
@@ -185,9 +185,8 @@
 static vaddr_t cmos_data_mapping;
 struct cpu_info *cpu_starting;
 
-int (*cpu_freq_sysctl_get)(SYSCTLFN_PROTO) = NULL;
-int (*cpu_freq_sysctl_set)(SYSCTLFN_PROTO) = NULL;
-int (*cpu_freq_sysctl_all)(SYSCTLFN_PROTO) = NULL;
+void (*cpu_freq_init)(int) = NULL;
+struct sysctllog *cpu_freq_sysctllog = NULL;
 
 void           cpu_hatch(void *);
 static void            cpu_boot_secondary(struct cpu_info *ci);
diff -r f410c3f50939 -r e5c7216d7df8 sys/arch/x86/x86/est.c
--- a/sys/arch/x86/x86/est.c    Mon Aug 09 15:39:41 2010 +0000
+++ b/sys/arch/x86/x86/est.c    Mon Aug 09 15:46:17 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: est.c,v 1.17 2010/08/09 04:18:49 jruoho Exp $  */
+/*     $NetBSD: est.c,v 1.18 2010/08/09 15:46:17 jruoho Exp $  */
 /*
  * Copyright (c) 2003 Michael Eriksson.
  * All rights reserved.
@@ -81,7 +81,7 @@
 /* #define EST_DEBUG */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: est.c,v 1.17 2010/08/09 04:18:49 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: est.c,v 1.18 2010/08/09 15:46:17 jruoho Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -998,72 +998,21 @@
 
 static const struct    fqlist *est_fqlist;     /* not NULL if functional */
 static uint16_t                *fake_table;            /* guessed est_cpu table */
-static char            *freq_names;
 static struct fqlist    fake_fqlist;
 static int             est_node_target, est_node_current;
 static const char      est_desc[] = "Enhanced SpeedStep";
 static int             lvendor, bus_clock;
 
+static int             est_sysctl_helper(SYSCTLFN_PROTO);
 static int             est_init_once(void);
 static void            est_init_main(int);
 
-static int             est_sysctl_helper(SYSCTLFN_PROTO);
-static int             est_sysctl_helper_get(SYSCTLFN_PROTO);
-static int             est_sysctl_helper_set(SYSCTLFN_PROTO);
-static int             est_sysctl_helper_all(SYSCTLFN_PROTO);
-
-static int
-est_sysctl_helper_get(SYSCTLFN_ARGS)
-{
-
-       if (cpu_freq_sysctl_get != NULL)
-               return (*cpu_freq_sysctl_get)(SYSCTLFN_CALL(rnode));
-
-       return est_sysctl_helper(SYSCTLFN_CALL(rnode));
-}
-
-static int
-est_sysctl_helper_set(SYSCTLFN_ARGS)
-{
-
-       if (cpu_freq_sysctl_set != NULL)
-               return (*cpu_freq_sysctl_set)(SYSCTLFN_CALL(rnode));
-
-       return est_sysctl_helper(SYSCTLFN_CALL(rnode));
-}
-
-static int
-est_sysctl_helper_all(SYSCTLFN_ARGS)
-{
-       struct sysctlnode node;
-       int err;
-
-       if (cpu_freq_sysctl_all != NULL)
-               return (*cpu_freq_sysctl_all)(SYSCTLFN_CALL(rnode));
-
-       if (freq_names == NULL)
-               return ENXIO;
-
-       node = *rnode;
-       node.sysctl_data = freq_names;
-
-       err = sysctl_lookup(SYSCTLFN_CALL(&node));
-
-       if (err != 0 || newp == NULL)
-               return err;
-
-       return 0;
-}
-
 static int
 est_sysctl_helper(SYSCTLFN_ARGS)
 {
        struct sysctlnode       node;
        int                     fq, oldfq, error;
 
-       if (freq_names == NULL)
-               return ENXIO;
-
        if (est_fqlist == NULL)
                return EOPNOTSUPP;
 
@@ -1137,6 +1086,7 @@
        uint8_t                 crhi, crlo, crcur;
        int                     i, mv, rc;
        size_t                  len, freq_len;
+       char                    *freq_names;
 
        if (CPUID2FAMILY(curcpu()->ci_signature) == 15)
                bus_clock = p4_get_bus_clock(curcpu());
@@ -1311,45 +1261,54 @@
        /*
         * Setup the sysctl sub-tree machdep.est.*
         */
-       if ((rc = sysctl_createv(NULL, 0, NULL, &node,
+       if (cpu_freq_sysctllog != NULL) {
+               rc = EALREADY;
+               goto err;
+       }
+



Home | Main Index | Thread Index | Old Index