File: turboboost.sh

package info (click to toggle)
simdjson 4.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,936 kB
  • sloc: cpp: 171,612; ansic: 19,122; sh: 1,126; python: 842; makefile: 47; ruby: 25; javascript: 13
file content (51 lines) | stat: -rwxr-xr-x 1,165 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh
# stolen from https://github.com/DropD/fnc-simplex/blob/master/linux_turboboost.sh

# you might need to run sudo apt-get install msr-tools
# Toggle Turbo Boost for Ivy Bridge CPUs (should work for all newer Core)
# Requires a fairly new Linux kernel (let's say 3.0+)
# Written by Donjan Rodic, released for free use

# check current real frequency with  sudo turbostat -s -i1

sudo modprobe msr

# all_cores FOO
# perform FOO(i) for each core i
all_cores() {
  NPROCS=`cat /proc/cpuinfo | grep "core id" | wc -l`
  NPROCS=$(($NPROCS - 1))
  for i in `seq 0 1 $NPROCS`; do
    $1 $i
  done
}


# report Turbo Boost state on core $1
read_tb() {
  ret=`sudo rdmsr -p"$1" 0x1a0 -f 38:38`
  [ $ret -eq 0 ] && echo "$1": on || echo "$1": off
}

# enable Turbo Boost on core $1
enable_tb() {
  sudo wrmsr -p"$1" 0x1a0 0x850089
}

# disable Turbo Boost on core $1
disable_tb() {
  sudo wrmsr -p"$1" 0x1a0 0x4000850089
}


if [ "$1" = "on" ]; then
  all_cores enable_tb
  all_cores read_tb
elif [ "$1" = "off" ]; then
  all_cores disable_tb
  all_cores read_tb
elif [ "$1" = "list" ]; then
  all_cores read_tb
else
  echo "usage: turboboost.sh on | off | list"
fi