blob: 5634cac9395953778b09a76dd5d344138e12ea5f [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001#!/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
6CPUPATH=/sys/devices/system/cpu
7
8MAXID=$(cat $CPUPATH/present | awk -F- '{print $NF}')
9
10set_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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000017enable_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
Ben Murdochb8a8cc12014-11-26 15:28:44 +000028dual_core() {
29 echo "Switching to dual-core mode"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000030 enable_cores 2
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031}
32
33single_core() {
34 echo "Switching to single-core mode"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000035 enable_cores 1
Ben Murdochb8a8cc12014-11-26 15:28:44 +000036}
37
38
39all_cores() {
40 echo "Reactivating all CPU cores"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000041 enable_cores $((MAXID+1))
42}
43
44
45limit_cores() {
46 # $1: How many cores to enable.
47 echo "Limiting to $1 cores"
48 enable_cores $1
Ben Murdochb8a8cc12014-11-26 15:28:44 +000049}
50
51case "$1" in
52 fast | performance)
53 set_governor "performance"
54 ;;
55 slow | powersave)
56 set_governor "powersave"
57 ;;
58 default | ondemand)
59 set_governor "ondemand"
60 ;;
61 dualcore | dual)
62 dual_core
63 ;;
64 singlecore | single)
65 single_core
66 ;;
67 allcores | all)
68 all_cores
69 ;;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000070 limit_cores)
71 if [ $# -ne 2 ]; then
72 echo "Usage $0 limit_cores <num>"
73 exit 1
74 fi
75 limit_cores $2
76 ;;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000077 *)
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000078 echo "Usage: $0 fast|slow|default|singlecore|dualcore|all|limit_cores"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000079 exit 1
80 ;;
81esac