Skip to content

Commit

Permalink
tuning: Avoid crash in PerformancePowerProfile
Browse files Browse the repository at this point in the history
The current code do not check if the scaling_governor is present before
using it, leading to a crash.

To improve this part of the code, this commit is:
- considering the current_governor instead of the available ones to
  decide if the tuning should be done
- adding a check before actually reading the scaling governor file and
  ignore the function if no file found

This commit fixes issue #25.

Signed-off-by: Erwan Velu <[email protected]>
  • Loading branch information
ErwanAliasr1 committed Aug 19, 2024
1 parent 1669f9f commit 5101fa4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions hwbench/tuning/power_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ def __init__(self, out_dir):
self.out_dir = out_dir
self.skip_tuning = False

available_governors = (
pathlib.Path("/sys/devices/system/cpu/cpuidle/available_governors")
current_governor = (
pathlib.Path("/sys/devices/system/cpu/cpuidle/current_governor")
.read_text("ascii")
.strip()
.split()
)
self.skip_tuning |= (
len(available_governors) == 1 and available_governors[0] == "menu"
)
self.skip_tuning |= current_governor == "menu"

def run(self) -> None:
log = tunninglog()
Expand All @@ -29,8 +27,15 @@ def run(self) -> None:
for rootpath, dirnames, filenames in os.walk("/sys/devices/system/cpu"):
for dirname in dirnames:
if pattern.match(dirname):
cpudir = pathlib.Path(rootpath) / dirname
file = cpudir / "cpufreq/scaling_governor"
file = pathlib.Path(rootpath).joinpath(
dirname, "cpufreq", "scaling_governor"
)
# Ignore this tuning if no scaling_governor available
if not file.exists():
log.info(
f"skip PerformancePowerProfile for {dirname} as no scaling governor detected"
)
continue
previous = file.read_text(encoding="utf-8").rstrip()
# please read https://www.kernel.org/doc/html/latest/admin-guide/pm/cpufreq.html
# for more explanation
Expand Down

0 comments on commit 5101fa4

Please sign in to comment.