Index: tools/cpu.sh |
diff --git a/tools/cpu.sh b/tools/cpu.sh |
index 0597d09ea99647eae832b755e9b59995a3f1d4d0..5634cac9395953778b09a76dd5d344138e12ea5f 100755 |
--- a/tools/cpu.sh |
+++ b/tools/cpu.sh |
@@ -14,26 +14,38 @@ set_governor() { |
done |
} |
+enable_cores() { |
+ # $1: How many cores to enable. |
+ for (( i=1; i<=$MAXID; i++ )); do |
+ if [ "$i" -lt "$1" ]; then |
+ echo 1 > $CPUPATH/cpu$i/online |
+ else |
+ echo 0 > $CPUPATH/cpu$i/online |
+ fi |
+ done |
+} |
+ |
dual_core() { |
echo "Switching to dual-core mode" |
- for (( i=2; i<=$MAXID; i++ )); do |
- echo 0 > $CPUPATH/cpu$i/online |
- done |
+ enable_cores 2 |
} |
single_core() { |
echo "Switching to single-core mode" |
- for (( i=1; i<=$MAXID; i++ )); do |
- echo 0 > $CPUPATH/cpu$i/online |
- done |
+ enable_cores 1 |
} |
all_cores() { |
echo "Reactivating all CPU cores" |
- for (( i=1; i<=$MAXID; i++ )); do |
- echo 1 > $CPUPATH/cpu$i/online |
- done |
+ enable_cores $((MAXID+1)) |
+} |
+ |
+ |
+limit_cores() { |
+ # $1: How many cores to enable. |
+ echo "Limiting to $1 cores" |
+ enable_cores $1 |
} |
case "$1" in |
@@ -55,8 +67,15 @@ case "$1" in |
allcores | all) |
all_cores |
;; |
+ limit_cores) |
+ if [ $# -ne 2 ]; then |
+ echo "Usage $0 limit_cores <num>" |
+ exit 1 |
+ fi |
+ limit_cores $2 |
+ ;; |
*) |
- echo "Usage: $0 fast|slow|default|singlecore|dualcore|all" |
+ echo "Usage: $0 fast|slow|default|singlecore|dualcore|all|limit_cores" |
exit 1 |
;; |
esac |