Skip to content

Commit

Permalink
Merge pull request #7 from KyleGospo/main
Browse files Browse the repository at this point in the history
Add support for masking/unmasking TuneD
  • Loading branch information
antheas authored Sep 30, 2024
2 parents c7ab315 + ba85820 commit 117633b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/adjustor/drivers/amd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,13 @@ def settings(self):

if self.ppd_conflict and os.environ.get("HHD_PPD_MASK", None):
logger.warning(
"PPD conflict detected but HHD_PPD_MASK is set. Masking PPD."
"PPD conflict detected but HHD_PPD_MASK is set. Masking PPD/TuneD."
)
# Mask and disable
os.system("systemctl mask power-profiles-daemon.service")
os.system("systemctl disable --now power-profiles-daemon.service")
os.system("systemctl mask tuned.service")
os.system("systemctl disable --now tuned.service")
# Keep going without check to avoid obscure errors
self.ppd_conflict = False

Expand Down
69 changes: 69 additions & 0 deletions 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,26 @@ 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):
logger.info("Unmasking TuneD in the case it was masked.")
os.system('systemctl unmask tuned')
subprocess.run(
[tuned],
check=True,
stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
self.tuned_supported = True
except Exception as e:
logger.warning(f"tuned-adm returned with error:\n{e}")


if not self.ppd_supported:
del sets["children"]["profile"]

Expand Down Expand Up @@ -122,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 117633b

Please sign in to comment.