| OLD | NEW |
| 1 #!/bin/bash | 1 #!/bin/bash |
| 2 # Copyright 2014 the V8 project authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 CPUPATH=/sys/devices/system/cpu | 6 CPUPATH=/sys/devices/system/cpu |
| 7 | 7 |
| 8 MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}') | 8 MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}') |
| 9 | 9 |
| 10 set_governor() { | 10 set_governor() { |
| 11 echo "Setting CPU frequency governor to \"$1\"" | 11 echo "Setting CPU frequency governor to \"$1\"" |
| 12 for (( i=0; i<=$MAXID; i++ )); do | 12 for (( i=0; i<=$MAXID; i++ )); do |
| 13 echo "$1" > $CPUPATH/cpu$i/cpufreq/scaling_governor | 13 echo "$1" > $CPUPATH/cpu$i/cpufreq/scaling_governor |
| 14 done | 14 done |
| 15 } | 15 } |
| 16 | 16 |
| 17 enable_cores() { |
| 18 # $1: How many cores to enable. |
| 19 for (( i=1; i<=$MAXID; i++ )); do |
| 20 if [ "$i" -lt "$1" ]; then |
| 21 echo 1 > $CPUPATH/cpu$i/online |
| 22 else |
| 23 echo 0 > $CPUPATH/cpu$i/online |
| 24 fi |
| 25 done |
| 26 } |
| 27 |
| 17 dual_core() { | 28 dual_core() { |
| 18 echo "Switching to dual-core mode" | 29 echo "Switching to dual-core mode" |
| 19 for (( i=2; i<=$MAXID; i++ )); do | 30 enable_cores 2 |
| 20 echo 0 > $CPUPATH/cpu$i/online | |
| 21 done | |
| 22 } | 31 } |
| 23 | 32 |
| 24 single_core() { | 33 single_core() { |
| 25 echo "Switching to single-core mode" | 34 echo "Switching to single-core mode" |
| 26 for (( i=1; i<=$MAXID; i++ )); do | 35 enable_cores 1 |
| 27 echo 0 > $CPUPATH/cpu$i/online | |
| 28 done | |
| 29 } | 36 } |
| 30 | 37 |
| 31 | 38 |
| 32 all_cores() { | 39 all_cores() { |
| 33 echo "Reactivating all CPU cores" | 40 echo "Reactivating all CPU cores" |
| 34 for (( i=1; i<=$MAXID; i++ )); do | 41 enable_cores $((MAXID+1)) |
| 35 echo 1 > $CPUPATH/cpu$i/online | 42 } |
| 36 done | 43 |
| 44 |
| 45 limit_cores() { |
| 46 # $1: How many cores to enable. |
| 47 echo "Limiting to $1 cores" |
| 48 enable_cores $1 |
| 37 } | 49 } |
| 38 | 50 |
| 39 case "$1" in | 51 case "$1" in |
| 40 fast | performance) | 52 fast | performance) |
| 41 set_governor "performance" | 53 set_governor "performance" |
| 42 ;; | 54 ;; |
| 43 slow | powersave) | 55 slow | powersave) |
| 44 set_governor "powersave" | 56 set_governor "powersave" |
| 45 ;; | 57 ;; |
| 46 default | ondemand) | 58 default | ondemand) |
| 47 set_governor "ondemand" | 59 set_governor "ondemand" |
| 48 ;; | 60 ;; |
| 49 dualcore | dual) | 61 dualcore | dual) |
| 50 dual_core | 62 dual_core |
| 51 ;; | 63 ;; |
| 52 singlecore | single) | 64 singlecore | single) |
| 53 single_core | 65 single_core |
| 54 ;; | 66 ;; |
| 55 allcores | all) | 67 allcores | all) |
| 56 all_cores | 68 all_cores |
| 57 ;; | 69 ;; |
| 70 limit_cores) |
| 71 if [ $# -ne 2 ]; then |
| 72 echo "Usage $0 limit_cores <num>" |
| 73 exit 1 |
| 74 fi |
| 75 limit_cores $2 |
| 76 ;; |
| 58 *) | 77 *) |
| 59 echo "Usage: $0 fast|slow|default|singlecore|dualcore|all" | 78 echo "Usage: $0 fast|slow|default|singlecore|dualcore|all|limit_cores" |
| 60 exit 1 | 79 exit 1 |
| 61 ;; | 80 ;; |
| 62 esac | 81 esac |
| OLD | NEW |