Compare commits

...
Author SHA1 Message Date
maxjivi05 62b8b2e5dd fix(steam): launch games when CPU affinity is refused 2026-11-30 14:17:42 -05:00
5 changed files with 33 additions and 15 deletions

No files matched your search

@@ -251,7 +251,7 @@ dd_game_cpus() {
fi
[ -n "${DD_GAME_CPUS:-}" ] || return 0
command -v taskset >/dev/null 2>&1 || return 0
DD_TASKSET="taskset -c $DD_GAME_CPUS"
DD_TASKSET=(bash -c 'taskset -cp "$1" "$$" >/dev/null 2>&1 || printf "droiddeck-proton: CPU affinity refused; using inherited cores\n" >&2; shift; exec "$@"' -- "$DD_GAME_CPUS")
echo "droiddeck-proton: game cores $DD_GAME_CPUS" >&2
}
"""
@@ -470,7 +470,7 @@ if [ -n "$depot" ]; then
DD_STORE_PROTON="$depot/proton"; export DD_STORE_PROTON
dd_store_launch "$@"
DD_STORE_ARGS=("$@")
dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env "$depot/proton" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
fi
echo "droiddeck-proton: no ARM64 Proton depot yet - the client downloads one as this tool's dependency; retry the launch once it has" >&2
exit 1
@@ -525,7 +525,7 @@ dd_libpath
DD_STORE_PROTON="$here/%s"; export DD_STORE_PROTON
dd_store_launch "$@"
DD_STORE_ARGS=("$@")
dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env "$DD_STORE_PROTON" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env "$DD_STORE_PROTON" "$verb" "$@" "${DD_EXTRA_ARGS[@]}"
"""
@@ -581,9 +581,9 @@ esac
""" + DD_DESKTOP_GPU_SETUP + DD_GAME_CPUS_SETUP + """
dd_game_cpus
if [ -x /usr/local/bin/droiddeck-steamvr-flat ] && /usr/local/bin/droiddeck-steamvr-flat "$verb"; then
exec /usr/local/bin/droiddeck-steamvr-game ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
exec /usr/local/bin/droiddeck-steamvr-game "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-fex steam "$verb" "$@"
fi
exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-fex steam "$verb" "$@"
exec "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-fex steam "$verb" "$@"
"""
+12 -6
View File
@@ -1571,15 +1571,21 @@ class AppInfoTest(unittest.TestCase):
tool, bin_dir = Path(tmp) / "droiddeck-fex", Path(tmp) / "bin"
self.COMPAT["build_fex_tool"](str(tool))
bin_dir.mkdir()
(bin_dir / "taskset").write_text('#!/bin/sh\necho "taskset $*"\n')
affinity = Path(tmp) / "affinity"
(bin_dir / "taskset").write_text(f'#!/bin/sh\nprintf "%s\\n" "$*" > "{affinity}"\n')
(bin_dir / "taskset").chmod(0o755)
fex = bin_dir / "fex"
fex.write_text('#!/bin/sh\nprintf "%s\\n" "$@"\n')
fex.chmod(0o755)
launcher = tool / "droiddeck-fex-tool"
launcher.write_text(launcher.read_text().replace("/usr/local/bin/droiddeck-fex", str(fex)))
env = dict(os.environ, PATH="%s:%s" % (bin_dir, os.environ.get("PATH", "")), DD_GAME_CPUS="2-7")
run = subprocess.run([str(tool / "droiddeck-fex-tool"), "waitforexitandrun", "/games/a/game"],
env=env, capture_output=True, text=True, timeout=10)
self.assertEqual(run.stdout,
"taskset -c 2-7 /usr/local/bin/droiddeck-fex steam waitforexitandrun /games/a/game\n")
run = subprocess.run([str(launcher), "waitforexitandrun", "/games/a/game"],
env=env, capture_output=True, text=True, timeout=10, check=True)
self.assertRegex(affinity.read_text(), r"^-cp 2-7 [0-9]+\n$")
self.assertEqual(run.stdout.splitlines(), ["steam", "waitforexitandrun", "/games/a/game"])
self.assertIn("game cores 2-7", run.stderr)
self.assertIn('exec /usr/local/bin/droiddeck-steamvr-game ${DD_TASKSET:-} '
self.assertIn('exec /usr/local/bin/droiddeck-steamvr-game "${DD_TASKSET[@]}" '
'/usr/local/bin/droiddeck-fex steam "$verb" "$@"', self.COMPAT["FEX_LAUNCHER_SH"])
+13 -1
View File
@@ -27,12 +27,24 @@ class LiveGameCpusTest(unittest.TestCase):
if live is not None:
self.live.write_bytes(live.encode())
setup = COMPAT["DD_GAME_CPUS_SETUP"].replace("/root/.config/droiddeck/game-cores", str(self.live))
script = setup + '\ndd_game_cpus\necho "taskset=${DD_TASKSET:-}"\necho "cpus=${DD_GAME_CPUS-unset}"\n'
script = setup + '\ndd_game_cpus\nif (( ${#DD_TASKSET[@]} )); then echo "taskset=taskset -c ${DD_TASKSET[4]}"; else echo "taskset="; fi\necho "cpus=${DD_GAME_CPUS-unset}"\n'
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH=self.path, **extra)
result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True)
return result.stdout.splitlines()
def test_refused_affinity_still_runs_the_requested_program(self):
taskset = Path(self.path.split(os.pathsep)[0]) / "taskset"
for status in (0, 1):
taskset.write_text(f"#!/bin/sh\nexit {status}\n")
setup = COMPAT["DD_GAME_CPUS_SETUP"].replace("/root/.config/droiddeck/game-cores", str(self.live))
script = setup + '''\ndd_game_cpus\n"${DD_TASKSET[@]}" bash -c 'printf "%s\\n" "$@"' -- "first argument" second\n'''
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(PATH=self.path, DD_GAME_CPUS="2,3")
result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True)
self.assertEqual(result.stdout.splitlines(), ["first argument", "second"])
self.assertEqual("CPU affinity refused" in result.stderr, status != 0)
def test_a_change_made_during_the_session_wins_over_the_session_value(self):
self.assertEqual(self.run_setup("6,7\n", DD_GAME_CPUS="3,4,5,6,7"),
["taskset=taskset -c 6,7", "cpus=6,7"])
+1 -1
View File
@@ -2615,7 +2615,7 @@ class GameEnvironmentTest(unittest.TestCase):
self.assertIn('dd_directaudio "$here" "$@"', COMPAT["EXTRA_WRAPPER_SH"] % "proton")
for script in (COMPAT["LAUNCHER_SH"], COMPAT["EXTRA_WRAPPER_SH"] % "proton"):
subprocess.run(["bash", "-n"], input=script, text=True, check=True)
self.assertIn('dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', script)
self.assertIn('dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', script)
def test_both_proton_wrappers_answer_steams_driver_query_without_wine(self):
scripts = (COMPAT["launcher_sh"](), COMPAT["extra_wrapper_sh"]("proton"))
+2 -2
View File
@@ -379,8 +379,8 @@ class CloudHooks(unittest.TestCase):
def test_both_launchers_wait_for_proton_only_for_a_store_game(self):
for sh in (compat.LAUNCHER_SH, compat.EXTRA_WRAPPER_SH):
self.assertIn('dd_run ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec ${DD_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('dd_run "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec "${DD_TASKSET[@]}" /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('[ $rc -eq 10 ] && DD_STORE_EXIT=1', compat.DD_STORE_SETUP)
self.assertIn('droiddeck-store-launch --exited --code "$rc" "${DD_STORE_ARGS[@]}"', compat.DD_STORE_SETUP)
self.assertIn('exec "$@"', compat.DD_STORE_SETUP)