mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 12:56:06 +00:00
fix(proton): Windows CPU 0 is the fastest core (#1697)
Wine numbers the Windows CPUs like the host, so Windows CPU 0 was host
core 0, a small core on most Android chips. Games that pin their main
thread to CPU 0 ran it there: GTA IV 32 fps on the AYANEO Pocket FIT,
61 fps once CPU 0 is the fastest core.
droiddeck-game-env hands Wine the game's cores fastest first, from each
core's cpu_capacity (or its top clock). Equal cores keep their order.
Cores picked globally or in a game profile stay the only cores the game
sees, now fastest first; a pick only counts when it narrows the cores.
Games on Proton's own default_cpu_limit list keep their count on the
fastest cores (quoted and unquoted counts); other values such as "P"
are left to Proton. A typed WINE_CPU_TOPOLOGY / PROTON_CPU_TOPOLOGY
still wins, an empty one turns it off for a game, and
DROIDDECK_FASTEST_CORES=0 turns it off. Steam's own Proton runs in
compatdata/0 are left as before.
Builds on maxjivi05's "Windows games see only the cores they are pinned
to" (9d85af75).
This commit is contained in:
1 parent
4f58230a20
commit
4ef6b53eb0
2 files changed
+125
-4
No files matched your search
@@ -357,21 +357,76 @@ def game_cores(env):
|
||||
print("droiddeck-game-env: could not use game cores %r (%s)" % (text, error), file=sys.stderr)
|
||||
|
||||
|
||||
def cpu_topology(env):
|
||||
def core_speeds(cores, root="/sys/devices/system/cpu"):
|
||||
"""Each core's capacity, else its top clock; None when some core reports neither."""
|
||||
for name in ("cpu_capacity", "cpufreq/cpuinfo_max_freq"):
|
||||
speeds = {}
|
||||
for core in cores:
|
||||
try:
|
||||
with open("%s/cpu%d/%s" % (root, core, name)) as f:
|
||||
speeds[core] = int(f.read().strip())
|
||||
except (OSError, ValueError):
|
||||
break
|
||||
else:
|
||||
return speeds
|
||||
return None
|
||||
|
||||
|
||||
def fastest_first(cores):
|
||||
"""The cores, fastest first; cores of equal or unknown speed keep their numeric order."""
|
||||
cores = sorted(cores)
|
||||
speeds = core_speeds(cores)
|
||||
return sorted(cores, key=lambda core: -speeds[core]) if speeds else cores
|
||||
|
||||
|
||||
def proton_cpu_limit(command, env):
|
||||
"""This game's entry in Proton's own default_cpu_limit list: a core count, another value such as "P" as text, or None."""
|
||||
app_id = env.get("SteamGameId", "")
|
||||
if not command or not app_id.isdigit():
|
||||
return None
|
||||
try:
|
||||
if os.path.getsize(command[0]) > 4 * 1024 * 1024:
|
||||
return None
|
||||
with open(command[0], encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
except OSError:
|
||||
return None
|
||||
table = re.search(r"^default_cpu_limit = \{(.*?)^\}", text, re.M | re.S)
|
||||
match = table and re.search(r'^\s*"%s"\s*:\s*"?(\w+)' % app_id, table.group(1), re.M)
|
||||
if not match:
|
||||
return None
|
||||
value = match.group(1)
|
||||
return int(value) if value.isdigit() else value
|
||||
|
||||
|
||||
def cpu_topology(env, command=()):
|
||||
"""Windows sees the game's cores fastest first, so a thread a game pins to CPU 0 runs on the fastest core."""
|
||||
if "PROTON_CPU_TOPOLOGY" in env:
|
||||
return
|
||||
if "WINE_CPU_TOPOLOGY" in env:
|
||||
if env["WINE_CPU_TOPOLOGY"]:
|
||||
env["PROTON_CPU_TOPOLOGY"] = env["WINE_CPU_TOPOLOGY"]
|
||||
return
|
||||
if not (env.get("DROIDDECK_GAME_CORES", "").strip() or env.get("BL_GAME_CPUS", "").strip()):
|
||||
picked = bool(env.get("DROIDDECK_GAME_CORES", "").strip() or env.get("BL_GAME_CPUS", "").strip())
|
||||
fastest = env.get("DROIDDECK_FASTEST_CORES", "").strip() != "0" and game_id(env) is not None
|
||||
if not (picked or fastest):
|
||||
return
|
||||
try:
|
||||
cores = sorted(os.sched_getaffinity(0))
|
||||
except OSError:
|
||||
return
|
||||
online = online_cores()
|
||||
if not cores or set(cores) >= online or cores[-1] >= len(online):
|
||||
if not cores or cores[-1] >= len(online):
|
||||
return
|
||||
picked = picked and not set(cores) >= online
|
||||
if fastest:
|
||||
limit = None if picked else proton_cpu_limit(command, env)
|
||||
if isinstance(limit, str):
|
||||
return
|
||||
cores = fastest_first(cores)[:limit or None]
|
||||
elif set(cores) >= online:
|
||||
return
|
||||
if cores == sorted(online):
|
||||
return
|
||||
env["WINE_CPU_TOPOLOGY"] = env["PROTON_CPU_TOPOLOGY"] = "%d:%s" % (len(cores), ",".join(map(str, cores)))
|
||||
print("droiddeck-game-env: Windows sees %d cores (%s)" % (len(cores), env["WINE_CPU_TOPOLOGY"]), file=sys.stderr)
|
||||
@@ -653,7 +708,7 @@ def main():
|
||||
env = vram_cap(env)
|
||||
env = force_ssbs(command, env)
|
||||
game_cores(env)
|
||||
cpu_topology(env)
|
||||
cpu_topology(env, command)
|
||||
try:
|
||||
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
|
||||
except Exception as error:
|
||||
|
||||
Reference in new issue
Block a user