feat: pick a game's CPU cores in its game profile (#1566)

* feat: pick a game's CPU cores in its game profile

* fix: match per-game cores against the online CPU list
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-25 16:38:11 -04:00
1 parent ee3f32d31e
commit 8d858b4334
4 files changed
+63

No files matched your search

@@ -299,6 +299,46 @@ def vram_cap(env):
return result
def parse_cores(text):
"""CPU numbers from a list such as "0-3,6"; None when the text is not one."""
cores = set()
for part in text.replace(" ", "").split(","):
match = re.fullmatch(r"(\d{1,3})(?:-(\d{1,3}))?", part)
if not match:
return None
first, last = int(match.group(1)), int(match.group(2) or match.group(1))
if last < first:
return None
cores.update(range(first, last + 1))
return cores or None
def online_cores():
try:
with open("/sys/devices/system/cpu/online") as f:
cores = parse_cores(f.read().strip())
except OSError:
cores = None
return cores or os.sched_getaffinity(0) | set(range(os.cpu_count() or 0))
def game_cores(env):
"""Pins the game to the cores its profile names, in place of the session's game cores."""
text = env.get("DROIDDECK_GAME_CORES", "").strip()
if not text:
return
cores = parse_cores(text)
chosen = cores & online_cores() if cores else None
if not chosen:
print("droiddeck-game-env: ignoring game cores %r" % text, file=sys.stderr)
return
try:
os.sched_setaffinity(0, chosen)
print("droiddeck-game-env: game cores %s" % ",".join(map(str, sorted(chosen))), file=sys.stderr)
except OSError as error:
print("droiddeck-game-env: could not use game cores %r (%s)" % (text, error), file=sys.stderr)
def apply_config(env, config, app_id, fixes=None):
if config.get("version") != 1:
raise ValueError("unsupported environment configuration")
@@ -574,6 +614,7 @@ def main():
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
env = vram_cap(env)
env = force_ssbs(command, env)
game_cores(env)
try:
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
except Exception as error: