Skip to content

Commit

Permalink
cpu disable process for each little and big cores
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Jul 8, 2024
1 parent 47d78e8 commit 2f59614
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
29 changes: 27 additions & 2 deletions src/service/backends/cpu.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,38 @@
import os
from common import *
def list_cpu():
i = 0
ret = []
for i in range(0, get_num_of_cpu()):
ret.append("cpu"+str(i))
return ret

def get_num_of_cpu():
i = 0
while os.path.exists("/sys/devices/system/cpu/cpu"+str(i)):
i += 1
ret.append("cpu"+str(i))
return i

def list_little_cpu():
max_all = 0
ret = []
for i in range(0, get_num_of_cpu()):
with open("/sys/devices/system/cpu/cpu{}//cpufreq/scaling_max_freq".format(i), "r") as f:
freq = int(f.read())
if freq > max_all:
max_all = freq
for i in range(0, get_num_of_cpu()):
with open("/sys/devices/system/cpu/cpu{}//cpufreq/scaling_max_freq".format(i), "r") as f:
freq = int(f.read())
if freq < max_all:
ret.append("cpu"+str(i))
return ret

def list_big_cpu():
all_cpu = list_cpu()
for cpu in list_little_cpu():
all_cpu.remove(cpu)
return all_cpu

def change_cpu_status(core, status):
log("New core status: {} = {}".format(core, status))
if not os.path.exists("/sys/devices/system/cpu/cpu"+str(core)+"/online"):
Expand Down
18 changes: 10 additions & 8 deletions src/service/backends/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ def _powersave():

if get("core",True,"power"):
# disable cpu core
cpus = list_cpu()
dnum = len(cpus) * float(get("core-ratio",0.5,"powersave"))
if len(cpus) <= 4:
dnum = 0
elif len(cpus) - dnum < 4:
dnum = 4
for cpu in range(len(cpus) - int(dnum), len(cpus)):
change_cpu_status(cpu,False)
def cpu_disable_event(cpus, min):
dnum = len(cpus) * float(get("core-ratio",0.5,"powersave"))
if len(cpus) <= min:
dnum = 0
elif len(cpus) - dnum < min:
dnum = min
for cpu in range(len(cpus) - int(dnum), len(cpus)):
change_cpu_status(cpu,False)
cpu_disable_event(list_big_cpu(), 4)
cpu_disable_event(list_little_cpu(), 0)

if not is_acpi_supported():
return
Expand Down

0 comments on commit 2f59614

Please sign in to comment.