-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpowerswap.py
44 lines (37 loc) · 1.17 KB
/
powerswap.py
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
#! /usr/bin/python3
import os
import sys
class WrongModeError(Exception):
pass
class HelpError(Exception):
pass
def set_core(mode,start_core, core_count,passed="no"):
if passed == "yes":
pass
else:
for i in range(start_core,core_count):
with open("/sys/devices/system/cpu/cpu{0}/cpufreq/scaling_governor".format(i), "w") as f:
f.write(str(mode))
print("set core mode to {0} for cpu cores {1} to {2}".format(mode,start_core, core_count))
try:
core_mode = sys.argv[1]
if core_mode not in ["performance", "ondemand", "powersave","conservative","help"]:
print('please enter: "performance","ondemand","powersave"')
raise WrongModeError
if core_mode == "help":
print("How to use: ./powerswap.py mode_name max_core start_core")
#raise HelpError
skip = "yes"
else:
skip = "no"
try:
start_core = sys.argv[3]
except IndexError:
start_core = 0
try:
core_count = sys.argv[2]
except IndexError:
core_count = 8
set_core(core_mode, int(start_core),int(core_count),skip)
except IndexError:
print("please set core mode")