Home | History | Annotate | Download | only in tools
      1 #!/bin/bash
      2 # Copyright 2014 the V8 project authors. All rights reserved.
      3 # Use of this source code is governed by a BSD-style license that can be
      4 # found in the LICENSE file.
      5 
      6 CPUPATH=/sys/devices/system/cpu
      7 
      8 MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}')
      9 
     10 set_governor() {
     11   echo "Setting CPU frequency governor to \"$1\""
     12   for (( i=0; i<=$MAXID; i++ )); do
     13     echo "$1" > $CPUPATH/cpu$i/cpufreq/scaling_governor
     14   done
     15 }
     16 
     17 dual_core() {
     18   echo "Switching to dual-core mode"
     19   for (( i=2; i<=$MAXID; i++ )); do
     20     echo 0 > $CPUPATH/cpu$i/online
     21   done
     22 }
     23 
     24 single_core() {
     25   echo "Switching to single-core mode"
     26   for (( i=1; i<=$MAXID; i++ )); do
     27     echo 0 > $CPUPATH/cpu$i/online
     28   done
     29 }
     30 
     31 
     32 all_cores() {
     33   echo "Reactivating all CPU cores"
     34   for (( i=2; i<=$MAXID; i++ )); do
     35     echo 1 > $CPUPATH/cpu$i/online
     36   done
     37 }
     38 
     39 case "$1" in
     40   fast | performance)
     41     set_governor "performance"
     42     ;;
     43   slow | powersave)
     44     set_governor "powersave"
     45     ;;
     46   default | ondemand)
     47     set_governor "ondemand"
     48     ;;
     49   dualcore | dual)
     50     dual_core
     51     ;;
     52   singlecore | single)
     53     single_core
     54     ;;
     55   allcores | all)
     56     all_cores
     57     ;;
     58   *)
     59     echo "Usage: $0 fast|slow|default|singlecore|dualcore|all"
     60     exit 1
     61     ;;
     62 esac 
     63