NetBSD-Bugs archive

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

Re: kern/39960: Enhanced Speedstep module patch



The following reply was made to PR kern/39960; it has been noted by GNATS.

From: Juan RP <xtraeme%gmail.com@localhost>
To: gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: kern/39960: Enhanced Speedstep module patch
Date: Wed, 19 Nov 2008 23:09:47 +0100

 Here's the patch:
 
 Index: distrib/sets/lists/base/md.amd64
 ===================================================================
 RCS file: /cvsroot/src/distrib/sets/lists/base/md.amd64,v
 retrieving revision 1.31
 diff -b -u -p -r1.31 md.amd64
 --- distrib/sets/lists/base/md.amd64   19 Nov 2008 18:35:57 -0000      1.31
 +++ distrib/sets/lists/base/md.amd64   19 Nov 2008 21:30:18 -0000
 @@ -9,6 +9,8 @@
  ./@MODULEDIR@/compat_netbsd32/compat_netbsd32.kmod    base-kernel-modules
  ./@MODULEDIR@/drm                             base-kernel-modules
  ./@MODULEDIR@/drm/drm.kmod                    base-kernel-modules
 +./@MODULEDIR@/est                             base-kernel-modules
 +./@MODULEDIR@/est/est.kmod                    base-kernel-modules
  ./@MODULEDIR@/exec_elf64                      base-kernel-modules
  ./@MODULEDIR@/exec_elf64/exec_elf64.kmod      base-kernel-modules
  ./@MODULEDIR@/i915drm                         base-kernel-modules
 Index: distrib/sets/lists/base/md.i386
 ===================================================================
 RCS file: /cvsroot/src/distrib/sets/lists/base/md.i386,v
 retrieving revision 1.132
 diff -b -u -p -r1.132 md.i386
 --- distrib/sets/lists/base/md.i386    19 Nov 2008 18:35:57 -0000      1.132
 +++ distrib/sets/lists/base/md.i386    19 Nov 2008 21:30:18 -0000
 @@ -11,6 +11,8 @@
  ./@MODULEDIR@/compat_svr4/compat_svr4.kmod    base-kernel-modules
  ./@MODULEDIR@/drm                             base-kernel-modules
  ./@MODULEDIR@/drm/drm.kmod                    base-kernel-modules
 +./@MODULEDIR@/est                             base-kernel-modules
 +./@MODULEDIR@/est/est.kmod                    base-kernel-modules
  ./@MODULEDIR@/exec_aout                               base-kernel-modules
  ./@MODULEDIR@/exec_aout/exec_aout.kmod                base-kernel-modules
  ./@MODULEDIR@/i915drm                         base-kernel-modules
 Index: sys/modules/Makefile
 ===================================================================
 RCS file: /cvsroot/src/sys/modules/Makefile,v
 retrieving revision 1.15
 diff -b -u -p -r1.15 Makefile
 --- sys/modules/Makefile       19 Nov 2008 18:36:07 -0000      1.15
 +++ sys/modules/Makefile       19 Nov 2008 21:30:18 -0000
 @@ -54,6 +54,7 @@ SUBDIR+=     compat_linux
  SUBDIR+=      compat_linux32
  SUBDIR+=      compat_netbsd32
  SUBDIR+=      drm
 +SUBDIR+=      est
  SUBDIR+=      exec_elf64
  SUBDIR+=      i915drm
  .endif
 @@ -65,6 +66,7 @@ SUBDIR+=     compat_ibcs2
  SUBDIR+=      compat_linux
  SUBDIR+=      compat_svr4
  SUBDIR+=      drm
 +SUBDIR+=      est
  SUBDIR+=      exec_aout
  SUBDIR+=      i915drm
  SUBDIR+=      radeondrm
 Index: sys/arch/amd64/conf/GENERIC
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/amd64/conf/GENERIC,v
 retrieving revision 1.233
 diff -b -u -p -r1.233 GENERIC
 --- sys/arch/amd64/conf/GENERIC        12 Nov 2008 14:36:31 -0000      1.233
 +++ sys/arch/amd64/conf/GENERIC        19 Nov 2008 21:30:21 -0000
 @@ -71,10 +71,6 @@ options     USERCONF        # userconf(4) support
  #options      PIPE_SOCKETPAIR # smaller, but slower pipe(2)
  options       SYSCTL_INCLUDE_DESCR    # Include sysctl descriptions in kernel
  
 -# Intel Enhanced Speedstep for EM64T CPUs
 -options       ENHANCED_SPEEDSTEP
 -#options      EST_FREQ_USERWRITE      # any user can set frequency
 -
  # AMD PowerNow! and Cool`n'Quiet technology
  options       POWERNOW_K8
  
 Index: sys/arch/i386/conf/ALL
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/i386/conf/ALL,v
 retrieving revision 1.184
 diff -b -u -p -r1.184 ALL
 --- sys/arch/i386/conf/ALL     12 Nov 2008 12:36:01 -0000      1.184
 +++ sys/arch/i386/conf/ALL     19 Nov 2008 21:30:29 -0000
 @@ -25,10 +25,6 @@ maxusers    32              # estimated number of users
  options       VM86            # virtual 8086 emulation
  options       USER_LDT        # user-settable LDT; used by WINE
  
 -# Enhanced SpeedStep Technology in the Pentium M
 -options       ENHANCED_SPEEDSTEP
 -options       EST_FREQ_USERWRITE      # any user can set frequency
 -
  # AMD PowerNow! K7
  options       POWERNOW_K7
  
 Index: sys/arch/i386/conf/GENERIC
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/i386/conf/GENERIC,v
 retrieving revision 1.917
 diff -b -u -p -r1.917 GENERIC
 --- sys/arch/i386/conf/GENERIC 12 Nov 2008 14:36:31 -0000      1.917
 +++ sys/arch/i386/conf/GENERIC 19 Nov 2008 21:30:31 -0000
 @@ -33,10 +33,6 @@ makeoptions         CPUFLAGS="-march=i486 -mtun
  options       VM86            # virtual 8086 emulation
  options       USER_LDT        # user-settable LDT; used by WINE
  
 -# Enhanced SpeedStep Technology in the Pentium M
 -options       ENHANCED_SPEEDSTEP
 -#options      EST_FREQ_USERWRITE      # any user can set frequency
 -
  # AMD PowerNow! K7
  options       POWERNOW_K7
  
 Index: sys/arch/x86/conf/files.x86
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/x86/conf/files.x86,v
 retrieving revision 1.44
 diff -b -u -p -r1.44 files.x86
 --- sys/arch/x86/conf/files.x86        3 Aug 2008 19:32:03 -0000       1.44
 +++ sys/arch/x86/conf/files.x86        19 Nov 2008 21:30:40 -0000
 @@ -10,10 +10,6 @@ defflag                 MTRR
  defflag opt_pcifixup.h        PCI_ADDR_FIXUP PCI_BUS_FIXUP
                        PCI_INTR_FIXUP PCI_INTR_FIXUP_FORCE
  
 -# Intel Enhanced Speedstep
 -defflag                       ENHANCED_SPEEDSTEP
 -defflag       opt_est.h               EST_FREQ_USERWRITE
 -
  # Intel On Die Temperature sensor
  defflag       opt_intel_coretemp.h    INTEL_CORETEMP: sysmon_envsys
  
 @@ -85,10 +81,6 @@ file        arch/x86/x86/powernow_common.c  powe
  # Intel On Demand Clock Modulation
  file  arch/x86/x86/iclockmod.c        intel_ondemand_clockmod
  
 -# Intel Enhanced Speedstep
 -file  arch/x86/x86/est.c              enhanced_speedstep
 -file  arch/x86/x86/intel_busclock.c   enhanced_speedstep
 -
  # Intel On-Die Temperature sensor
  file  arch/x86/x86/coretemp.c         intel_coretemp
  
 Index: sys/arch/x86/include/cpuvar.h
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/x86/include/cpuvar.h,v
 retrieving revision 1.27
 diff -b -u -p -r1.27 cpuvar.h
 --- sys/arch/x86/include/cpuvar.h      13 May 2008 22:39:17 -0000      1.27
 +++ sys/arch/x86/include/cpuvar.h      19 Nov 2008 21:30:40 -0000
 @@ -86,12 +86,13 @@ struct cpu_attach_args {
  
  #ifdef _KERNEL
  
 +#ifdef _KERNEL_OPT
  #include "opt_multiprocessor.h"
  #ifndef XEN
 -#include "opt_enhanced_speedstep.h"
  #include "opt_intel_coretemp.h"
  #include "opt_intel_odcm.h"
  #endif
 +#endif
  
  #ifdef MULTIPROCESSOR
  extern uint32_t cpus_running;
 @@ -124,12 +125,10 @@ void coretemp_register(struct cpu_info *
  void clockmod_init(void);
  #endif
  
 -#ifdef ENHANCED_SPEEDSTEP
 -void  est_init(int);
 +/* Intel Enhanced Speedstep (intel_busclock.c) */
  int   via_get_bus_clock(struct cpu_info *);
  int   p3_get_bus_clock(struct cpu_info *);
  int   p4_get_bus_clock(struct cpu_info *);
 -#endif
  
  void  cpu_get_tsc_freq(struct cpu_info *);
  
 Index: sys/arch/x86/x86/est.c
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/x86/x86/est.c,v
 retrieving revision 1.9
 diff -b -u -p -r1.9 est.c
 --- sys/arch/x86/x86/est.c     28 Apr 2008 20:23:40 -0000      1.9
 +++ sys/arch/x86/x86/est.c     19 Nov 2008 21:30:41 -0000
 @@ -87,7 +87,7 @@ __KERNEL_RCSID(0, "$NetBSD: est.c,v 1.9 
  #include <sys/systm.h>
  #include <sys/malloc.h>
  #include <sys/sysctl.h>
 -#include <sys/once.h>
 +#include <sys/module.h>
  
  #include <x86/cpuvar.h>
  #include <x86/cputypes.h>
 @@ -96,11 +96,11 @@ __KERNEL_RCSID(0, "$NetBSD: est.c,v 1.9 
  #include <machine/cpu.h>
  #include <machine/specialreg.h>
  
 -#include "opt_est.h"
 -#ifdef EST_FREQ_USERWRITE
 -#define       EST_TARGET_CTLFLAG      (CTLFLAG_READWRITE | CTLFLAG_ANYWRITE)
 +#ifdef _MODULE
 +static struct sysctllog *sysctllog;
 +#define SYSCTLLOG     &sysctllog
  #else
 -#define       EST_TARGET_CTLFLAG      CTLFLAG_READWRITE
 +#define SYSCTLLOG     NULL
  #endif
  
  /* Convert MHz and mV into IDs for passing to the MSR. */
 @@ -997,13 +997,13 @@ static const struct fqlist est_cpus[] = 
  static const struct   fqlist *est_fqlist;     /* not NULL if functional */
  static uint16_t               *fake_table;            /* guessed est_cpu 
table */
  static struct fqlist    fake_fqlist;
 -static int            est_node_target, est_node_current;
 +static int            est_node_target, est_node_current, bus_clock;
  static const char     est_desc[] = "Enhanced SpeedStep";
 -static int            lvendor, bus_clock;
 +static char           *freq_names;
 +static bool           attached;
  
  static int            est_sysctl_helper(SYSCTLFN_PROTO);
 -static int            est_init_once(void);
 -static void           est_init_main(int);
 +static void           est_init(int);
  
  static int
  est_sysctl_helper(SYSCTLFN_ARGS)
 @@ -1048,28 +1048,8 @@ est_sysctl_helper(SYSCTLFN_ARGS)
        return 0;
  }
  
 -static int
 -est_init_once(void)
 -{
 -      est_init_main(lvendor);
 -      return 0;
 -}
 -
 -void
 -est_init(int vendor)
 -{
 -      int error;
 -      static ONCE_DECL(est_initialized);
 -
 -      lvendor = vendor;
 -
 -      error = RUN_ONCE(&est_initialized, est_init_once);
 -      if (__predict_false(error != 0))
 -              return;
 -}
 -
  static void
 -est_init_main(int vendor)
 +est_init(int vendor)
  {
  #ifdef __i386__
        const struct fqlist     *fql;
 @@ -1080,7 +1060,6 @@ est_init_main(int vendor)
        uint8_t                 crhi, crlo, crcur;
        int                     i, mv, rc;
        size_t                  len, freq_len;
 -      char                    *freq_names;
        const char *cpuname;
         
        cpuname = device_xname(curcpu()->ci_dev);
 @@ -1254,41 +1233,64 @@ est_init_main(int vendor)
        /*
         * Setup the sysctl sub-tree machdep.est.*
         */
 -      if ((rc = sysctl_createv(NULL, 0, NULL, &node,
 +      if ((rc = sysctl_createv(SYSCTLLOG, 0, NULL, &node,
            CTLFLAG_PERMANENT, CTLTYPE_NODE, "machdep", NULL,
            NULL, 0, NULL, 0, CTL_MACHDEP, CTL_EOL)) != 0)
                goto err;
  
 -      if ((rc = sysctl_createv(NULL, 0, &node, &estnode,
 +      if ((rc = sysctl_createv(SYSCTLLOG, 0, &node, &estnode,
            0, CTLTYPE_NODE, "est", NULL,
            NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
                goto err;
  
 -      if ((rc = sysctl_createv(NULL, 0, &estnode, &freqnode,
 +      if ((rc = sysctl_createv(SYSCTLLOG, 0, &estnode, &freqnode,
            0, CTLTYPE_NODE, "frequency", NULL,
            NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
                goto err;
  
 -      if ((rc = sysctl_createv(NULL, 0, &freqnode, &node,
 -          EST_TARGET_CTLFLAG, CTLTYPE_INT, "target", NULL,
 +      if ((rc = sysctl_createv(SYSCTLLOG, 0, &freqnode, &node,
 +          CTLFLAG_READWRITE, CTLTYPE_INT, "target", NULL,
            est_sysctl_helper, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
                goto err;
        est_node_target = node->sysctl_num;
  
 -      if ((rc = sysctl_createv(NULL, 0, &freqnode, &node,
 +      if ((rc = sysctl_createv(SYSCTLLOG, 0, &freqnode, &node,
            0, CTLTYPE_INT, "current", NULL,
            est_sysctl_helper, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
                goto err;
        est_node_current = node->sysctl_num;
  
 -      if ((rc = sysctl_createv(NULL, 0, &freqnode, &node,
 +      if ((rc = sysctl_createv(SYSCTLLOG, 0, &freqnode, &node,
            0, CTLTYPE_STRING, "available", NULL,
            NULL, 0, freq_names, freq_len, CTL_CREATE, CTL_EOL)) != 0)
                goto err;
  
 +      attached = true;
        return;
  
   err:
        free(freq_names, M_SYSCTLDATA);
        aprint_error("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
  }
 +
 +MODULE(MODULE_CLASS_MISC, est, NULL);
 +
 +static int
 +est_modcmd(modcmd_t cmd, void *arg)
 +{
 +      switch (cmd) {
 +      case MODULE_CMD_INIT:
 +              est_init(cpu_vendor);
 +              return 0;
 +      case MODULE_CMD_FINI:
 +              if (!attached)
 +                      return 0;
 +              sysctl_teardown(SYSCTLLOG);
 +              free(freq_names, M_SYSCTLDATA);
 +              if (fake_table)
 +                      free(fake_table, M_DEVBUF);
 +              return 0;
 +      default:
 +              return ENOTTY;
 +      }
 +}
 Index: sys/arch/x86/x86/identcpu.c
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/x86/x86/identcpu.c,v
 retrieving revision 1.10
 diff -b -u -p -r1.10 identcpu.c
 --- sys/arch/x86/x86/identcpu.c        18 Oct 2008 09:08:34 -0000      1.10
 +++ sys/arch/x86/x86/identcpu.c        19 Nov 2008 21:30:42 -0000
 @@ -58,7 +58,6 @@
  #include <sys/cdefs.h>
  __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.10 2008/10/18 09:08:34 cegger Exp 
$");
  
 -#include "opt_enhanced_speedstep.h"
  #include "opt_intel_odcm.h"
  #include "opt_intel_coretemp.h"
  #include "opt_powernow_k8.h"
 @@ -71,6 +70,7 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v
  #include <sys/systm.h>
  #include <sys/malloc.h>
  #include <sys/bitops.h>
 +#include <sys/module.h>
  
  #include <uvm/uvm_extern.h>
  
 @@ -712,6 +712,7 @@ cpu_probe(struct cpu_info *ci)
  void
  cpu_identify(struct cpu_info *ci)
  {
 +      int error = 0;
  
        snprintf(cpu_model, sizeof(cpu_model), "%s %d86-class",
            cpu_vendor_names[cpu_vendor], cpu_class + 3);
 @@ -774,12 +775,16 @@ cpu_identify(struct cpu_info *ci)
                i386_use_fxsave = 0;
  #endif        /* i386 */
  
 -#ifdef ENHANCED_SPEEDSTEP
 +      /* Load the Enhanced Speedstep module if EST feature enabled */
        if (cpu_feature2 & CPUID2_EST) {
 -              if (rdmsr(MSR_MISC_ENABLE) & (1 << 16))
 -                      est_init(cpu_vendor);
 +              if (rdmsr(MSR_MISC_ENABLE) & (1 << 16)) {
 +                      error = module_autoload("est", MODULE_CLASS_MISC);
 +                      if (error) {
 +                              aprint_error("est module autoload failed"
 +                                  " (%d)\n", error);
 +                      }
 +              }
        }
 -#endif /* ENHANCED_SPEEDSTEP */
  
  #ifdef INTEL_CORETEMP
        if (cpu_vendor == CPUVENDOR_INTEL && cpuid_level >= 0x06)
 Index: sys/arch/xen/conf/files.compat
 ===================================================================
 RCS file: /cvsroot/src/sys/arch/xen/conf/files.compat,v
 retrieving revision 1.18
 diff -b -u -p -r1.18 files.compat
 --- sys/arch/xen/conf/files.compat     23 Jan 2008 19:46:45 -0000      1.18
 +++ sys/arch/xen/conf/files.compat     19 Nov 2008 21:30:42 -0000
 @@ -61,10 +61,6 @@ defflag opt_intel_coretemp.h                XXXINTEL_C
  # AMD Powernow/Cool`n'Quiet Technology
  defflag opt_powernow_k8.h     XXPOWERNOW_K8
  
 -# Intel Enhanced Speedstep
 -defflag       opt_enhanced_speedstep.h XXXENHANCED_SPEEDSTEP
 -defflag opt_est.h             XXXEST_FREQ_USERWRITE
 -
  defflag opt_powernow_k7.h XXXPOWERNOW_K7
  
  # Multiboot support
 ---- END OF PATCH ----
 
 Additionally, here's sys/modules/est/Makefile:
 
 $ cat /usr/src/sys/modules/est/Makefile                                        
                      
 #       $NetBSD$
 
 .include "../Makefile.inc"
 
 .PATH:  ${S}/arch/x86/x86
 
 KMOD=   est
 SRCS=   est.c intel_busclock.c
 
 .include <bsd.kmodule.mk>
 $
 


Home | Main Index | Thread Index | Old Index