SpeedStep on NetBSD/xen

       470 words, 3 minutes

When you boot NetBSD/xen, you don’t get SpeedStep anymore. At least, on NetBSD 5.1, as of 2011-07-14. Some job have been done in 2009 but wasn’t kept in the sources. Check Add Intel SpeedStep and AMD PowerNow! support in Xen dom0 for more informations.

Those are the patches than enabled SpeedStep on my Dell XPS M1330 running NetBSD 5.1/xen:

--- src/sys/arch/x86/include/cpuvar.h.orig      2010-04-22 22:02:48.000000000 +0200
+++ src/sys/arch/x86/include/cpuvar.h   2011-07-14 21:34:25.000000000 +0200
@@ -88,8 +88,8 @@

 #include "opt_multiprocessor.h"
-#ifndef XEN
 #include "opt_enhanced_speedstep.h"
 #include "opt_intel_coretemp.h"
 #include "opt_intel_odcm.h"
+#ifndef XEN
 #include "opt_via_c7temp.h"
 #endif
--- src/sys/arch/x86/x86/x86_machdep.c.orig     2009-02-03 00:47:35.000000000 +0100
+++ src/sys/arch/x86/x86/x86_machdep.c  2011-07-14 23:39:22.000000000 +0200
@@ -129,7 +129,5 @@
 x86_init(void)
 {
-#ifndef XEN
        msr_cpu_broadcast_initmtx();
-#endif
 }
--- src/sys/arch/xen/conf/files.xen.orig        2009-10-04 01:54:04.000000000 +0200
+++ src/sys/arch/xen/conf/files.xen     2011-07-14 21:51:00.000000000 +0200
@@ -29,4 +29,18 @@
 defparam               PCI_CONF_MODE

+# Intel Enhanced Speedstep
+defflag opt_enhanced_speedstep.h XXXENHANCED_SPEEDSTEP
+defflag opt_est.h               XXXEST_FREQ_USERWRITE
+file   arch/x86/x86/est.c              enhanced_speedstep
+file   arch/x86/x86/intel_busclock.c   enhanced_speedstep
+#Pentium 4+ Thermal Monitor ODCM (aka On Demand Clock Modulation)
+defflag opt_intel_odcm.h        XXXINTEL_ONDEMAND_CLOCKMOD
+file   arch/x86/x86/iclockmod.c        intel_ondemand_clockmod
+
+# Intel On Die Temperature sensor
+defflag opt_intel_coretemp.h            XXXINTEL_CORETEMP
+file   arch/x86/x86/coretemp.c         intel_coretemp
+
+
 file   arch/xen/x86/autoconf.c
 ifdef i386
@@ -288,4 +302,6 @@
 file   arch/xen/x86/cpu.c              cpu | vcpu

+file   arch/x86/x86/msr_ipifuncs.c
+
 #
 # Compatibility modules
--- src/sys/arch/xen/conf/files.compat.orig     2009-10-05 13:57:41.000000000 +0200
+++ src/sys/arch/xen/conf/files.compat  2011-07-14 21:38:17.000000000 +0200
@@ -54,8 +54,8 @@

 #Pentium 4+ Thermal Monitor ODCM (aka On Demand Clock Modulation)
-defflag opt_intel_odcm.h       XXXINTEL_ONDEMAND_CLOCKMOD
+#defflag opt_intel_odcm.h      XXXINTEL_ONDEMAND_CLOCKMOD

 # Intel On Die Temperature sensor
-defflag opt_intel_coretemp.h           XXXINTEL_CORETEMP
+#defflag opt_intel_coretemp.h          XXXINTEL_CORETEMP

 # AMD Powernow/Cool`n'Quiet Technology
@@ -63,6 +63,6 @@

 # Intel Enhanced Speedstep
-defflag        opt_enhanced_speedstep.h XXXENHANCED_SPEEDSTEP
-defflag opt_est.h              XXXEST_FREQ_USERWRITE
+#defflag       opt_enhanced_speedstep.h XXXENHANCED_SPEEDSTEP
+#defflag opt_est.h             XXXEST_FREQ_USERWRITE

 defflag opt_powernow_k7.h XXXPOWERNOW_K7

Here is the kernel configuration file I use:

# cat src/sys/arch/amd64/conf/LUUNA_XEN3
# $NetBSD: LUUNA

include         "arch/amd64/conf/XEN3_DOM0"

ident           "LUUNA-$Revision: 1.231.4.7 $"

# Intel Enhanced Speedstep for EM64T CPUs
options         ENHANCED_SPEEDSTEP

# Intel(R) On Demand Clock Modulation (aka ODCM)
options       INTEL_ONDEMAND_CLOCKMOD

# Intel Core's on-die Thermal sensor
options         INTEL_CORETEMP

# Intel ICH SMBus controller
ichsmb* at pci? dev ? function ?
iic*    at ichsmb?

# Thermal monitor and fan controller
dbcool* at iic? addr 0x2C               # Unknown other motherboard(s)
dbcool* at iic? addr 0x2D               # Tyan S2881
dbcool* at iic? addr 0x2E               # Tyan S2882-D

# Serial Presence Detect capable memory modules
spdmem* at iic? addr 0x50
spdmem* at iic? addr 0x51
spdmem* at iic? addr 0x52
spdmem* at iic? addr 0x53

Now, I have SpeedStep enabled in NetBSD/xen:

# sysctl machdep
machdep.tsc_freq = 0
machdep.idle-mechanism = xen
machdep.sleep_state = 0
machdep.est.frequency.target = 1200
machdep.est.frequency.current = 1200
machdep.est.frequency.available = 2000 1800 1600 1400 1200
machdep.clockmod.target = 7
machdep.clockmod.current = 7
machdep.clockmod.available = 7 6 5 4 3 2
machdep.xen_timepush_ticks = 5303
# envstat | tail -4
[acpitz0]
        temperature:     46.500                                degC
[coretemp0]
  vcpu0 temperature:     46.000                                degC

You can also use estd to automagically adjust CPU speed:

# grep estd /etc/rc.conf
estd=YES
estd_flags="-s -l 20 -h 50 -m 1200 -M 2000"

Groovy Baby!