mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-02 19:15:41 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1c9a958e5 |
No files matched your search
@@ -565,7 +565,22 @@ def online_cores():
|
||||
cores = parse_cores(f.read().strip())
|
||||
except OSError:
|
||||
cores = None
|
||||
return cores or os.sched_getaffinity(0) | set(range(os.cpu_count() or 0))
|
||||
return cores or allowed_cores() | set(range(os.cpu_count() or 0))
|
||||
|
||||
|
||||
def allowed_cores(status="/proc/self/status"):
|
||||
try:
|
||||
with open(status) as f:
|
||||
for line in f:
|
||||
key, _, value = line.partition(":")
|
||||
if key == "Cpus_allowed_list":
|
||||
cores = parse_cores(value.strip())
|
||||
if cores:
|
||||
return cores
|
||||
break
|
||||
except OSError:
|
||||
pass
|
||||
return os.sched_getaffinity(0)
|
||||
|
||||
|
||||
def game_cores(env):
|
||||
@@ -634,11 +649,11 @@ def cpu_topology(env, command=()):
|
||||
fastest = env.get("DROIDDECK_FASTEST_CORES", "").strip() != "0" and game_id(env) is not None
|
||||
if not (picked or fastest):
|
||||
return
|
||||
online = online_cores()
|
||||
try:
|
||||
cores = sorted(os.sched_getaffinity(0))
|
||||
cores = sorted(allowed_cores() & online)
|
||||
except OSError:
|
||||
return
|
||||
online = online_cores()
|
||||
if not cores or cores[-1] >= len(online):
|
||||
return
|
||||
picked = picked and not set(cores) >= online
|
||||
|
||||
@@ -1872,6 +1872,7 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
for env, affinity, expected, proton in cases:
|
||||
env["DROIDDECK_FASTEST_CORES"] = "0"
|
||||
with mock.patch.dict(MODULE["cpu_topology"].__globals__, online), \
|
||||
mock.patch.object(MODULE["allowed_cores"], "__defaults__", ("/missing/status",)), \
|
||||
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
|
||||
MODULE["cpu_topology"](env)
|
||||
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
|
||||
@@ -1986,6 +1987,7 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/3608888694")
|
||||
with mock.patch.dict(MODULE["cpu_topology"].__globals__, {"online_cores": lambda: every}), \
|
||||
mock.patch.dict(MODULE["fastest_first"].__globals__, {"core_speeds": lambda cores, speeds=speeds: speeds}), \
|
||||
mock.patch.object(MODULE["allowed_cores"], "__defaults__", ("/missing/status",)), \
|
||||
mock.patch.object(os_mod, "sched_getaffinity", return_value=affinity, create=True):
|
||||
MODULE["cpu_topology"](env, command)
|
||||
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, env)
|
||||
@@ -1995,6 +1997,46 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "1038250"}), "P")
|
||||
self.assertEqual(MODULE["proton_cpu_limit"](command, {"SteamGameId": "618970"}), 4)
|
||||
|
||||
def test_windows_sees_the_same_cores_while_android_pauses_some(self):
|
||||
os_mod = MODULE["os"]
|
||||
kalama = {0: 411, 1: 411, 2: 411, 3: 869, 4: 869, 5: 869, 6: 869, 7: 1024}
|
||||
every = set(range(8))
|
||||
cases = [
|
||||
({}, "0-7", {3, 4, 5, 6}, "8:7,3,4,5,6,0,1,2"),
|
||||
({}, "0-7", {0, 1, 2, 3, 4, 5, 7}, "8:7,3,4,5,6,0,1,2"),
|
||||
({}, "0-7", every, "8:7,3,4,5,6,0,1,2"),
|
||||
({"DD_GAME_CPUS": "6,7"}, "6-7", {6}, "2:7,6"),
|
||||
({"DROIDDECK_GAME_CORES": "3-7"}, "3-7", {3, 4, 5}, "5:7,3,4,5,6"),
|
||||
({}, "0-9", {3, 4}, "8:7,3,4,5,6,0,1,2"),
|
||||
({"DROIDDECK_FASTEST_CORES": "0"}, "0-7", {3, 4, 5, 6}, None),
|
||||
({"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/0"}, "0-7", {3, 4, 5, 6}, None),
|
||||
]
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
status = Path(tmp) / "status"
|
||||
for env, allowed, active, expected in cases:
|
||||
env.setdefault("STEAM_COMPAT_DATA_PATH", "/steam/compatdata/1687950")
|
||||
status.write_text("Name:\tpython3\nCpus_allowed:\tff\nCpus_allowed_list:\t%s\n" % allowed)
|
||||
with mock.patch.dict(MODULE["cpu_topology"].__globals__, {"online_cores": lambda: every}), \
|
||||
mock.patch.dict(MODULE["fastest_first"].__globals__, {"core_speeds": lambda cores: kalama}), \
|
||||
mock.patch.object(MODULE["allowed_cores"], "__defaults__", (str(status),)), \
|
||||
mock.patch.object(os_mod, "sched_getaffinity", return_value=active, create=True):
|
||||
MODULE["cpu_topology"](env, ["/missing/proton", "waitforexitandrun", "/game/P5R.exe"])
|
||||
self.assertEqual(env.get("WINE_CPU_TOPOLOGY"), expected, (env, allowed, active))
|
||||
self.assertEqual(env.get("PROTON_CPU_TOPOLOGY"), expected, (env, allowed, active))
|
||||
|
||||
def test_allowed_cores_read_the_tasks_mask_before_the_active_one(self):
|
||||
os_mod = MODULE["os"]
|
||||
allowed = MODULE["allowed_cores"]
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
status = Path(tmp) / "status"
|
||||
with mock.patch.object(os_mod, "sched_getaffinity", return_value={3, 4}, create=True):
|
||||
status.write_text("Cpus_allowed_list:\t0-2,4,6-7\n")
|
||||
self.assertEqual(allowed(str(status)), {0, 1, 2, 4, 6, 7})
|
||||
for text in ("Name:\tpython3\n", "Cpus_allowed_list:\t\n", "Cpus_allowed_list:\tjunk\n"):
|
||||
status.write_text(text)
|
||||
self.assertEqual(allowed(str(status)), {3, 4}, text)
|
||||
self.assertEqual(allowed(str(Path(tmp) / "missing")), {3, 4})
|
||||
|
||||
def test_core_speeds_read_capacity_then_top_clock(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
for core, capacity, clock in ((0, "379", "2265600"), (1, None, "3302400")):
|
||||
|
||||
Reference in new issue
Block a user