aboutsummaryrefslogtreecommitdiff
path: root/perfmgr
blob: 143a23cd2ac95611466186ceec286b4097835c6a (plain)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
import sys
import subprocess

def system(cmd):
    print(f"$ {cmd}")
    subprocess.run(cmd, shell=True)

def usage():
    print(f"usage: {sys.argv[0]} [on|off / turbo[on|off] / info]")

def main(argv) -> int:
    argc = len(argv)

    if argc < 2:
        usage()
        return 1

    opt1 = argv[1]

    if argc == 2:
        if opt1 == "on":
            system("sudo -E cpupower frequency-set -g powersave")
            return 0
        elif opt1 == "off":
            system("sudo -E cpupower frequency-set -g performance")
            return 0
        elif opt1 == "info":
            system("cpupower frequency-info")
            return 0
        elif opt1 == "-h" or opt1 == "--help":
            usage()
            return 0
        else:
            print(f"unknown option \'{opt1}\'")
            return 1

    elif argc >= 3:
        opt2 = argv[2]

        if opt1 == "turbo":
            if opt2 == "on":
                system("echo 0 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo")
                return 0
            elif opt2 == "off":
                system("echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo")
                return 0
            else:
                print(f"unknown option \'{opt2}\' for 'turbo'")
                return 1
        else:
            if opt1 == "on":
                system("sudo -E cpupower frequency-set -g powersave")
                return 0
            elif opt1 == "off":
                system("sudo -E cpupower frequency-set -g performance")
                return 0
            elif opt1 == "info":
                system("cpupower frequency-info")
                return 0
            elif opt1 == "-h" or opt1 == "--help":
                usage()
                return 0
            else:
                print(f"unknown option \'{opt1}\'")
                return 1

    return 0

main(sys.argv)