Skip to content

Commit

Permalink
Add tuned-adm handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleGospo committed Sep 30, 2024
1 parent a322e1b commit ba85820
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/adjustor/drivers/general/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
self.old_sched = None
self.sched_proc = None
self.ppd_supported = None
self.tuned_supported = None
self.is_steamdeck = is_steamdeck
self.ovr_enabled = False
self.should_exit = Event()
Expand Down Expand Up @@ -54,6 +55,9 @@ def settings(self):
except Exception as e:
logger.warning(f"powerprofilectl returned with error:\n{e}")

# TuneD
if self.tuned_supported is None:
self.tuned_supported = False
if tuned := shutil.which('tuned-adm'):
try:
if os.environ.get("HHD_PPD_MASK", None):
Expand All @@ -66,7 +70,7 @@ def settings(self):
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
self.ppd_supported = True
self.tuned_supported = True
except Exception as e:
logger.warning(f"tuned-adm returned with error:\n{e}")

Expand Down Expand Up @@ -139,6 +143,54 @@ def update(self, conf: Config):
logger.warning(f"powerprofilectl returned with error:\n{e}")
self.ppd_supported = False

# Handle TuneD
if self.tuned_supported:
curr = time.time()
ppd_tuned_mapping = {
"power-saver": "powersave",
"balanced": "balanced",
"performance": "throughput-performance"
}
new_profile = ppd_tuned_mapping.get(conf.get("tdp.general.profile", self.target))
if new_profile != self.target and new_profile and self.target:
logger.info(f"Setting TuneD profile to '{new_profile}'")
self.target = new_profile
try:
subprocess.run(
[shutil.which('tuned-adm'), "profile", new_profile],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
except Exception as e:
self.tuned_supported = False
logger.warning(f"tuned-adm returned with error:\n{e}")
self.tuned_supported = False
elif not self.last_check or curr - self.last_check > 2:
# Update profile every 2 seconds
self.last_check = curr
try:
res = subprocess.run(
[shutil.which('tuned-adm'), "active"],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)

tuned_ppd_mapping = {
"powersave": "power-saver",
"balanced": "balanced",
"throughput-performance": "performance"
}
self.target = tuned_ppd_mapping.get(res.stdout.decode().split(":")[1].strip()) # type: ignore

if self.target != conf["tdp.general.profile"].to(str):
conf["tdp.general.profile"] = self.target
except Exception as e:
self.tuned_supported = False
logger.warning(f"powerprofilectl returned with error:\n{e}")
self.tuned_supported = False

# Handle sched
if self.avail_scheds:
# Check health and print error
Expand Down

0 comments on commit ba85820

Please sign in to comment.