Browse Source

support kernel-3.x

git-svn-id: http://trac.vinelinux.org/repos/projects/specs@5507 ec354946-7b23-47d6-9f5a-488ba84defc7
daisuke 12 years ago
parent
commit
ec6e49b4ac
3 changed files with 404 additions and 1 deletions
  1. 4 1
      c/cpuspeed/cpuspeed-vl.spec
  2. 83 0
      c/cpuspeed/cpuspeed.conf
  3. 317 0
      c/cpuspeed/cpuspeed.init

+ 4 - 1
c/cpuspeed/cpuspeed-vl.spec

@@ -2,7 +2,7 @@ Summary:	CPU Frequency adjusting daemon.
 Summary(ja):	CPU 周波数調整デーモン
 Name:		cpuspeed
 Version:	1.5
-Release:	2%{?_dist_release}
+Release:	3%{?_dist_release}
 Group:		System Environment/Base
 License:	GPLv2+
 
@@ -94,6 +94,9 @@ fi
 
 
 %changelog
+* Tue Jan 24 2012 Daisuke SUZUKI <daisuke@linux.or.jp> 1.5-3
+- update cpuspeed.init for kernel-3.x
+
 * Thu Apr 07 2011 Daisuke SUZUKI <daisuke@linux.or.jp> 1.5-2
 - rebuild for Vine 6
 - s/BuildPreReq/BuildRequires

+ 83 - 0
c/cpuspeed/cpuspeed.conf

@@ -0,0 +1,83 @@
+# /etc/sysconfig/cpuspeed
+#
+# This configuration file controls the behavior of both the
+# cpuspeed daemon and various cpufreq modules.
+# For the vast majority of users, there shouldn't be any need to
+# alter the contents of this file at all. By and large, frequency
+# scaling should Just Work(tm) with the defaults.
+
+### DRIVER ###
+# Your CPUFreq driver module
+# Note that many drivers are now built-in, rather than built as modules,
+# so its usually best not to specify one. The most commonly-needed driver
+# module these days is 'p4-clockmod', however, in most cases, it is not
+# recommended for use. See: http://lkml.org/lkml/2006/2/25/84
+# default value: empty (try to auto-detect/use built-in)
+DRIVER=
+
+### GOVERNOR ###
+# Which scaling governor to use
+# Details on scaling governors for your cpu(s) can be found in
+# cpu-freq/governors.txt, part of the kernel-doc package
+# NOTES:
+# - The GOVERNOR parameter is only valid on centrino, powernow-k8 (amd64)
+#   and p4-clockmod platforms, other platforms that support frequency
+#   scaling always use the 'userspace' governor.
+# - Using the 'userspace' governor will trigger the cpuspeed daemon to run,
+#   which provides said user-space frequency scaling.
+# default value: empty (defaults to ondemand on centrino, powernow-k8,
+#                       and acpi-cpufreq systems, userspace on others)
+GOVERNOR=
+
+### FREQUENCIES ###
+# NOTE: valid max/min frequencies for your cpu(s) can be found in
+# /sys/devices/system/cpu/cpu*/cpufreq/scaling_available_frequencies
+# on systems that support frequency scaling (though only after the
+# appropriate drivers have been loaded via the cpuspeed initscript).
+# maximum speed to scale up to
+# default value: empty (use cpu reported maximum)
+MAX_SPEED=
+# minimum speed to scale down to
+# default value: empty (use cpu reported minimum)
+MIN_SPEED=
+
+### SCALING THRESHOLDS ###
+# Busy percentage threshold over which to scale up to max frequency
+# default value: empty (use governor default)
+UP_THRESHOLD=60
+# Busy percentage threshold under which to scale frequency down
+# default value: empty (use governor default)
+DOWN_THRESHOLD=40
+
+### NICE PROCESS HANDLING ###
+# Let background (nice) processes speed up the cpu
+# default value: 0 (background process usage can speed up cpu)
+# alternate value: 1 (background processes will be ignored)
+IGNORE_NICE=0
+
+
+#####################################################
+########## HISTORICAL CPUSPEED CONFIG BITS ##########
+#####################################################
+VMAJOR=1
+VMINOR=1
+
+# Sets the polling interval to change speed more frequently
+#OPTS="$OPTS -i 3"
+
+# Restore previous speed on program exit.
+#OPTS="$OPTS -r"
+
+# Add your favorite options here
+#OPTS="$OPTS "
+
+# uncomment and modify this to check the state of the AC adapter
+#if [ -f "/proc/acpi/ac_adapter/*/state" ]; then
+#    OPTS="$OPTS -a /proc/acpi/ac_adapter/*/state -D"
+#fi
+
+# uncomment and modify this to check the system temperature
+#THERMAL_ZONE=`ls /proc/acpi/thermal_zone/*/temperature | head -1`
+#if [ -f $THERMAL_ZONE ]; then
+#    OPTS="$OPTS -t $THERMAL_ZONE 75"
+#fi

+ 317 - 0
c/cpuspeed/cpuspeed.init

@@ -0,0 +1,317 @@
+#!/bin/sh
+# Startup script for cpuspeed
+#
+# chkconfig: 12345 06 99
+# description: Run dynamic CPU speed daemon and/or load appropriate
+#              cpu frequency scaling kernel modules and/or governors
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+[ -r /proc/cmdline ] && cmdline=$(cat /proc/cmdline)
+if (strstr "$cmdline" nocpufreq) ; then exit 0 ; fi
+
+prog="cpuspeed"
+
+[ -f /usr/sbin/$prog ] || exit 5
+
+# Get config.
+if [ -f /etc/$prog.conf ]; then
+  . /etc/$prog.conf
+fi
+
+cpufreqd=/sys/devices/system/cpu/cpufreq
+cpu0freqd=/sys/devices/system/cpu/cpu0/cpufreq
+cpus='/sys/devices/system/cpu/cpu[0-9]*'
+testpat="${cpus}/cpufreq/scaling_driver"
+lockfile="/var/lock/subsys/$prog"
+xendir="/proc/xen"
+logger="/usr/bin/logger -p info -t $prog"
+IGNORE_NICE=${IGNORE_NICE:-0}
+module_loaded=false
+
+some_file_exist() {
+  while [ "$1" ] ; do
+    [ -f "$1" ] && return 0
+    shift
+  done
+  return 1
+}
+
+governor_is_module() {
+  # Check to see if the requested cpufreq governor
+  # is provided as a kernel module or not
+  module_info=`/sbin/modinfo cpufreq-${governor}`
+  return $?
+}
+
+is_p4_clockmod() {
+  if [ `/sbin/lsmod | grep -c -w "p4.clockmod"` -ge 1 -a -d "/sys/devices/system/cpu/cpu0/thermal_throttle" ]; then
+    return 0
+  fi
+  return 1
+}
+
+governor_module_loaded() {
+# Check to see if we have a module loaded for
+# the current cpufreq governor
+  if [ -e ${cpu0freqd}/scaling_governor ]; then
+    governor=`cat ${cpu0freqd}/scaling_governor`
+  else
+    governor="none"
+  fi
+  if [ "${governor}" != "none" -a `/sbin/lsmod | grep -c -w "cpufreq.${governor}"` -ge 1 ]; then
+    return 0
+  fi
+  return 1
+}
+
+adjust_cpufreq() {
+  # First arg is a param under $cpufreqd
+  # Second arg is the value you want to set that param to
+  echo $2 > $cpufreqd/$1
+}
+
+adjust_governor() {
+  # First arg is a param under $cpu/cpufreq/
+  # Second arg is the value you want to set that param to
+  for cpu in ${cpus}; do
+      echo $2 > $cpu/cpufreq/$1
+  done
+}
+
+start_cpuspeed() {
+  echo -n $"Starting $prog: "
+  # cpuspeed daemon thresholds are specified as idle percentages,
+  # cpufreq modules as busy percentages, so we need to do some
+  # math here for use of unified config...
+  # DOWN_THRESHOLD doesn't mean exactly the same thing for
+  # cpuspeed as it does for the cpufreq governors, but close
+  # enough, and if not specified, we use same defaults as governors.
+  if [ -n "$UP_THRESHOLD" ]; then
+    let UP_THRESHOLD=100-$UP_THRESHOLD
+  else
+    UP_THRESHOLD=20
+  fi
+  if [ -n "$DOWN_THRESHOLD" ]; then
+    let DOWN_THRESHOLD=100-$DOWN_THRESHOLD
+  else
+    DOWN_THRESHOLD=80
+  fi
+  OPTS="$OPTS -p $UP_THRESHOLD $DOWN_THRESHOLD"
+  if [ -n "$MIN_SPEED" ]; then
+    OPTS="$OPTS -m $MIN_SPEED"
+  fi
+  if [ -n "$MAX_SPEED" ]; then
+    OPTS="$OPTS -M $MAX_SPEED"
+  fi
+  if [ "$IGNORE_NICE" -eq 1 ]; then
+    OPTS="$OPTS -n"
+  fi
+  daemon $prog -d $OPTS
+  RETVAL=$?
+  return $RETVAL
+}
+
+stop_cpuspeed() {
+  if [ -n "`pidof $prog`" ]; then
+    echo -n $"Stopping $prog: "
+    killproc $prog -USR1
+    killproc $prog -INT
+  fi
+  if [ -n "`pidof $prog`" ]; then
+    killproc $prog
+  fi
+  RETVAL=$?
+  return $RETVAL
+}
+
+start() {
+  if [ ! -f $lockfile ] && [ ! -d "$xendir" ]; then
+    cpu_vendor=$(awk '/vendor_id/{print $3}' /proc/cpuinfo | tail -n 1)
+    cpu_family=$(awk '/cpu family/{print $4}' /proc/cpuinfo | tail -n 1)
+    if ! some_file_exist $testpat ; then
+      # Attempt to load scaling_driver if not loaded
+      # but it is configured
+      if [ -n "$DRIVER" ]; then
+        /sbin/modprobe "$DRIVER"
+      elif [ "$cpu_vendor" == AuthenticAMD ] && [ "$cpu_family" -ge 7 ]; then
+        # Try loading powernow-k8 if this is an AMD processor,
+        # family 7 or greater (Athlon XP/MP was family 6)
+        pk8m=$(/sbin/modinfo powernow-k8 > /dev/null 2>&1)
+        if [ "$?" -eq 0 ]; then
+          /sbin/modprobe powernow-k8 2> /dev/null
+          [ -d ${cpu0freqd} ] || /sbin/modprobe -r powernow-k8 2> /dev/null
+        fi
+      elif [ -d /proc/acpi ]; then
+        # use ACPI as a fallback 
+        /sbin/modprobe acpi-cpufreq 2> /dev/null
+        # if even ACPI didn't work, remove it
+        # and then next test will bail out.
+        [ -d ${cpu0freqd} ] || /sbin/modprobe -r acpi-cpufreq 2> /dev/null
+      fi
+      if [ ! -d ${cpu0freqd} -a "$cpu_vendor" == GenuineIntel ]; then
+        # last-ditch effort for Intel proc boxes, try our neutered p4-clockmod
+        # to get at least passive cooling support (no clock changes)
+        /sbin/modprobe p4-clockmod 2> /dev/null
+        if [ -d ${cpu0freqd} ]; then
+          echo -n "Enabling p4-clockmod driver (passive cooling only): "
+          success; echo
+          return 0
+        else
+          /sbin/modprobe -r p4-clockmod 2> /dev/null
+        fi
+      fi
+    fi
+
+    # If we get this far with no driver, we must have no scaling.
+    # We're doomed.
+    [ ! -f ${cpu0freqd}/scaling_driver ] && return 6
+
+    # Okay, we have a driver, carry on...
+    drv=`cat ${cpu0freqd}/scaling_driver`
+
+    # Figure out default governor to use
+    case "$drv" in
+      centrino|powernow-k8|acpi-cpufreq|e_powersaver)
+        default_governor=ondemand
+        ;;
+      *)
+        default_governor=userspace
+        ;;
+    esac
+    governor=${GOVERNOR:-${default_governor}}
+
+    # Load governor module, if need be, and validate
+    governor_is_module && /sbin/modprobe cpufreq-${governor}
+    if [ `grep -c -w ${governor} ${cpu0freqd}/scaling_available_governors` -ge 1 ]; then
+      $logger "Enabling ${governor} cpu frequency scaling governor"
+    else
+      $logger "Invalid governor \"${governor}\" specified, falling back to ${default_governor}"
+      governor_is_module && /sbin/modprobe -r cpufreq-${governor}
+      governor=${default_governor}
+      governor_is_module && /sbin/modprobe cpufreq-${governor}
+    fi
+
+    # Set governor
+    adjust_governor scaling_governor ${governor}
+
+    # Run cpuspeed daemon for userspace gov, kernel ones otherwise
+    if [ "${governor}" == "userspace" ]; then
+      start_cpuspeed
+      RETVAL=$?
+    else
+      if [ -n "$MIN_SPEED" ]; then
+        adjust_cpufreq scaling_min_freq $MIN_SPEED
+      fi
+      if [ -n "$MAX_SPEED" ]; then
+        adjust_cpufreq scaling_max_freq $MAX_SPEED
+      fi
+      if [ -n "$UP_THRESHOLD" -a ${governor} == "ondemand" ]; then
+        adjust_cpufreq ondemand/up_threshold $UP_THRESHOLD
+      fi
+      if [ -n "$DOWN_THRESHOLD" -a ${governor} == "conservative" ]; then
+        adjust_cpufreq conservative/down_threshold $DOWN_THRESHOLD
+      fi
+      if [ "$IGNORE_NICE" -eq 1 -a ${governor} == "ondemand" -o ${governor} == "conservative" ]; then
+        adjust_cpufreq ${governor}/ignore_nice_load $IGNORE_NICE
+      fi
+      echo -n "Enabling ${governor} cpu frequency scaling: "
+      success
+      RETVAL=0
+    fi
+    echo
+    # Technically, not quite right in non-cpuspeed daemon
+    # cases, but close enough to indicate that we're
+    # doing some sort of cpu frequency scaling.
+    [ $RETVAL = 0 ] && touch $lockfile
+  else
+    if [ -d "$xendir" ]; then
+      $logger "CPU Frequency scaling is currently not supported on xen kernels"
+    fi
+    return 0
+  fi
+  return $RETVAL
+}
+
+stop() {
+  is_p4_clockmod && p4status="true"
+  if [ "$p4status" == "true" ]; then
+    echo "p4-clockmod passive cooling support cannot be stopped"
+    return 0
+  fi
+  [ ! -f ${cpu0freqd}/scaling_driver ] && return 0
+  drv=`cat ${cpu0freqd}/scaling_driver`
+  governor_module_loaded && module_loaded=true
+
+  if [ "${governor}" != "userspace" ]; then
+    echo -n "Disabling ${governor} cpu frequency scaling: "
+    $logger "Disabling ${governor} cpu frequency scaling governor"
+    for cpu in ${cpus}; do
+      echo userspace > $cpu/cpufreq/scaling_governor
+      cat $cpu/cpufreq/cpuinfo_max_freq > $cpu/cpufreq/scaling_setspeed
+    done
+    if [ $module_loaded == true ]; then
+      /sbin/modprobe -r cpufreq-${governor}
+    fi
+    success
+    RETVAL=0
+  else
+    stop_cpuspeed
+    RETVAL=$?
+  fi
+  echo
+  [ -n "$DRIVER" ] && /sbin/modprobe -r $DRIVER
+  [ $RETVAL = 0 ] && RETVAL=$?
+  [ $RETVAL = 0 ] && rm -f $lockfile
+  return $RETVAL
+}
+
+case "$1" in
+  start)
+    start
+    ;;
+
+  stop)
+    stop
+    ;;
+
+  status)
+    is_p4_clockmod && p4status="true"
+    if [ "$p4status" == "true" ]; then
+      echo "p4-clockmod passive cooling is enabled"
+      exit 0
+    fi
+    governor_module_loaded && module_loaded=true
+    if [ -d "$xendir" ]; then
+      echo "Frequency scaling not supported under xen kernels"
+      RETVAL=0
+    elif [ $module_loaded == true -o ${governor} == "performance" ]; then
+      echo "Frequency scaling enabled using ${governor} governor"
+      RETVAL=0
+    else
+      status $prog
+      RETVAL="$?"
+    fi
+    ;;
+
+  restart)
+    stop
+    start
+    ;;
+
+  condrestart)
+    governor_module_loaded && module_loaded=true
+    if [ $module_loaded == true -o -n "`pidof $prog`" -o ${governor} == "performance" ]; then
+      stop
+      start
+    fi
+    ;;
+
+  *)
+    echo $"Usage: $0 {start|stop|restart|condrestart|status}"
+    exit 3
+    ;;
+esac
+
+exit $RETVAL