mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 21:06:09 +00:00
Expanded Fastpaths for proot and increased performance up to 57% (#494)
* perf: fast path resolves links, /proc and glue as proot does, and answers uname, isatty and passwd
The fast path handed back to proot whatever crossed a symlink, /proc or a directory proot
only shows as glue, which is most of what Steam and Wine ask. It now walks a path the way
proot's canonicalize() does, so those calls stay in-process:
- links are followed in guest terms and their text detranslated as detranslate_path() does,
including readlink into a buffer the kernel cut short and /proc's exe, cwd and fd links;
- a binding proot dropped at start is dropped here too, glue above a binding is ENOENT, and a
last component proot cannot stat is left to the kernel;
- pipe and socket dirfds are ENOTDIR, rmdir("dir/") removes dir, and "." and ".." go to proot;
- a blocking accept() with a connection already waiting no longer goes to proot.
Also answered: uname() and gethostname() (proot's utsname never changes), isatty() (glibc
2.43 asks with TCGETS2, which proot rewrites) and getpwnam/getpwuid when nsswitch.conf
sends passwd to files first and the entry is there (Xwayland asks for every client).
equiv.py, equiv2.py and equiv3.py match line for line with and without the fast path
(222, 507 and 924 lines). Per call on the RedMagic: realpath 240 us -> 1.0 us,
realpath /proc/self/fd/N 408 -> 9.9, getpwuid 41.5 -> 4.6, uname 28 -> 0.006.
* perf: LD_AUDIT module skips library lookups proot would fail
ld.so looks each library up along the game's search path, and Proton puts the game's
directory, Steam's runtime and video directories and its own library directories ahead of
/usr/lib: 72% of ld.so's opens in an Among Us launch failed, each a round trip to proot.
libblaudit.so answers la_objsearch() for a candidate proot would certainly fail with ENOENT
(its directory walked as canonicalize() walks it, the name or a directory on the way missing).
It has no libc and maps the fast path's trampoline itself. Each lookup's first candidate is
still opened, since a skipped one fails with ld.so's errno as it stands, and the default
directories are never skipped, so dlerror() reads the same. droiddeck-proton and the extra
wrapper add it to LD_AUDIT when the fast path is on.
* perf: droiddeck-proton checks a tool's components with one sha256sum
Each program the launcher starts pays a dozen traced library lookups under the game's search
path before it does anything. One sha256sum over every listed file replaces one per file;
the check itself is unchanged.
* perf: build a locale archive for C.UTF-8
Every program loads the locale LANG names before main(). glibc ships C.UTF-8 as a directory
it looks for once per category under two spellings, before reading gconv's module lists:
about 30 opens, each a stop in proot, in every process of the session. droiddeck-session
builds /usr/lib/locale/locale-archive (and gconv's cache) once per glibc package, so that is
one open.
localedef names a finished archive by hard link, which Android refuses; with
DROIDDECK_LINK_RENAME=1 libblsession turns a refused link into a rename that will not replace
an existing name.
* perf: library beat starts its helpers only when what they read changed
Every 15 s the session ran droiddeck-seed-redists (some forty programs under proot) and, when
a library directory had changed, steam-compatibility: a burst of thousands of proot stops each
quarter minute, game loads included. The seeder now runs when a library changed or a prefix
(or Proton's template for them) is unmarked, the compat pass when a manifest, depot, tool or
config.vdf changed, both checked from bash without starting anything, and each every five
minutes regardless. The seeder reads its stamp and the time without a subshell each.
* perf: fakeinput opens pad.log on its first line
Every process the library is loaded in opened the session's pad.log at start, a stop in proot
on shared storage, and most never write to it. The file is now opened when there is a line to
write.
* docs: the fast path as it ships, the audit module and measured launch times
* fix: a game the app launches after an idle spell comes to the front
The Steam client brings a game it launched forward only while it counts someone as present,
which it reads from gamescope's input counter. A game the app launched after four or more
minutes without a touch started, mapped its window, and stayed behind the library page until
the next input (device: Palworld, Stardew Valley, Fallout: New Vegas, Mortal Kombat X; the same
on main). The session now watches a requested launch, and when the game's window is focusable
but the interface keeps focus for two polls, counts one input on gamescope's counter, as a key
would. Nothing changes for a launch the client already brings forward.
This commit is contained in:
1 parent
d250b43eb9
commit
a6d15bcd0b
14 files changed
+2875
-245
No files matched your search
@@ -112,7 +112,8 @@ vcrt() {
|
||||
# dated block it never matched, and every prefix had the whole block appended again on every beat.
|
||||
stamp=$(printf '%s vcrt %s.%s.%s' "$pairs" "$VCRT_MAJOR" "$VCRT_MINOR" "$VCRT_BUILD" | cksum)
|
||||
|
||||
block=$(printf '%s\n' "$pairs" | awk -F'\t' -v now="$(date +%s)" '
|
||||
printf -v now '%(%s)T' -1
|
||||
block=$(printf '%s\n' "$pairs" | awk -F'\t' -v now="$now" '
|
||||
{
|
||||
path = $1
|
||||
sub(/^HKEY_LOCAL_MACHINE\\\\/, "", path)
|
||||
@@ -128,7 +129,7 @@ block=$(printf '%s\n' "$pairs" | awk -F'\t' -v now="$(date +%s)" '
|
||||
}
|
||||
')
|
||||
block="$block
|
||||
$(vcrt "$(date +%s)")"
|
||||
$(vcrt "$now")"
|
||||
|
||||
# Proton builds a new prefix from its template, and the client runs the install scripts in that
|
||||
# prefix moments later, so the template carries the markers too. Its date is kept: Proton reads a
|
||||
@@ -141,12 +142,14 @@ for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/syste
|
||||
/mnt/droiddeck-sd/steamapps/compatdata/*/pfx/system.reg \
|
||||
/root/Games/*/steamapps/compatdata/*/pfx/system.reg; do
|
||||
[ -f "$reg" ] || continue
|
||||
seeded=$(dirname "$reg")/.droiddeck-redists
|
||||
legacy=$(dirname "$reg")/.bannerlator-redists
|
||||
seeded=${reg%/*}/.droiddeck-redists
|
||||
legacy=${reg%/*}/.bannerlator-redists
|
||||
if [ -f "$legacy" ] && [ ! -f "$seeded" ]; then
|
||||
mv -f "$legacy" "$seeded"
|
||||
fi
|
||||
[ "$(cat "$seeded" 2>/dev/null)" = "$stamp" ] && continue
|
||||
have=
|
||||
[ -f "$seeded" ] && read -r have < "$seeded"
|
||||
[ "$have" = "$stamp" ] && continue
|
||||
dated=$(mktemp) || continue
|
||||
touch -r "$reg" "$dated"
|
||||
if printf '%s\n' "$block" >>"$reg"; then
|
||||
|
||||
@@ -29,6 +29,27 @@ if [ -n "${BL_LOG:-}" ] && [ -z "${BL_INSIDE:-}" ]; then
|
||||
echo "== rootfs: $(cat /.version 2>/dev/null || echo unversioned)"
|
||||
fi
|
||||
|
||||
# Every program loads the locale LANG names (C.UTF-8) before main(). glibc ships it as a directory,
|
||||
# which it looks for once per category under two spellings before reading gconv's module lists:
|
||||
# about 30 opens, each a stop in proot, for every process in the session, a script's dirname or cat
|
||||
# included. An archive holding it (and gconv's cache) makes that one open. Built again when the
|
||||
# glibc package changes, or when the archive does (locale-gen rewrites it).
|
||||
prepare_locale() {
|
||||
local dir=/usr/lib/locale stamp=/usr/lib/locale/.droiddeck-archive want have= pkg
|
||||
pkg=(/var/lib/pacman/local/glibc-[0-9]*)
|
||||
want=${pkg[0]##*/}
|
||||
[ -f "$stamp" ] && read -r have < "$stamp"
|
||||
[ "$have" = "$want" ] && [ -f "$dir/locale-archive" ] && [ ! "$dir/locale-archive" -nt "$stamp" ] && return 0
|
||||
[ -d "$dir/C.utf8" ] && command -v localedef >/dev/null 2>&1 || return 0
|
||||
# localedef names a new archive by hard link, which Android refuses; libblsession renames it.
|
||||
DROIDDECK_LINK_RENAME=1 localedef --add-to-archive --replace "$dir/C.utf8" >/dev/null 2>&1 || return 0
|
||||
rm -f /usr/lib/gconv/gconv-modules.cache
|
||||
command -v iconvconfig >/dev/null 2>&1 && iconvconfig >/dev/null 2>&1
|
||||
printf '%s\n' "$want" > "$stamp"
|
||||
echo "== locale archive built for $want"
|
||||
}
|
||||
[ -z "${BL_INSIDE:-}" ] && prepare_locale
|
||||
|
||||
# Until the runtime is stable, Steam's own logs are copied beside the session log at exit so a
|
||||
# failed launch can be handed over as one folder.
|
||||
collect_steam_logs() {
|
||||
@@ -577,23 +598,42 @@ case $mode in
|
||||
esac
|
||||
done
|
||||
) &
|
||||
# The library beat. Both helpers are whole programs under proot (the compat one a python
|
||||
# start and a parse of the client's config), and nearly every beat has nothing new for them.
|
||||
# The seeder marks Proton's prefix template as well as the prefixes, so a new prefix is born
|
||||
# marked and every 15 s is soon enough for the rest. The compat pass runs when a directory it
|
||||
# reads from has changed since its last run - a new manifest, a new depot or tool, the client
|
||||
# rewriting config.vdf - which [ -nt ] answers without starting anything, and once a minute
|
||||
# regardless.
|
||||
# The library beat. Both helpers are whole programs under proot (the seeder some forty of them,
|
||||
# the compat one a python start and a parse of the client's config), and nearly every beat has
|
||||
# nothing new for them: a burst of thousands of proot stops every quarter minute, game loads
|
||||
# included. Each runs only when what it reads has changed, which bash answers without starting
|
||||
# anything ([ -nt ], globs), and every five minutes regardless. The seeder acts on a prefix (or
|
||||
# Proton's template for them) it has not marked, and on new install scripts, which arrive with a
|
||||
# manifest; the compat pass on a new manifest, depot or tool, or the client rewriting config.vdf.
|
||||
(
|
||||
beat=0
|
||||
compat_stamp=$HOME/.bl-compat-beat
|
||||
rm -f "$compat_stamp"
|
||||
compat_due() {
|
||||
seed_stamp=$HOME/.bl-seed-beat
|
||||
rm -f "$compat_stamp" "$seed_stamp"
|
||||
changed_since() {
|
||||
local d
|
||||
[ -e "$compat_stamp" ] && [ "$((beat % 12))" -ne 0 ] || return 0
|
||||
for d in "$steam_root/steamapps" "$steam_root/steamapps/common" "$steam_root/config" \
|
||||
"$steam_root/compatibilitytools.d" /mnt/droiddeck-sd/steamapps /root/Games/*/steamapps; do
|
||||
[ "$d" -nt "$compat_stamp" ] && return 0
|
||||
for d in "${@:2}"; do
|
||||
[ "$d" -nt "$1" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
compat_due() {
|
||||
[ -e "$compat_stamp" ] && [ "$((beat % 60))" -ne 0 ] || return 0
|
||||
changed_since "$compat_stamp" "${libraries[@]}" "$steam_root/steamapps/common" "$steam_root/config" \
|
||||
"$steam_root/compatibilitytools.d"
|
||||
}
|
||||
seed_due() {
|
||||
local reg
|
||||
[ -e "$seed_stamp" ] && [ "$((beat % 60))" -ne 0 ] || return 0
|
||||
changed_since "$seed_stamp" "${libraries[@]}" && return 0
|
||||
for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
|
||||
/mnt/droiddeck-sd/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
|
||||
/root/Games/*/steamapps/common/Proton*/files/share/default_pfx*/system.reg \
|
||||
"$steam_root"/compatibilitytools.d/*/files/share/default_pfx*/system.reg \
|
||||
"$steam_root"/steamapps/compatdata/*/pfx/system.reg \
|
||||
/mnt/droiddeck-sd/steamapps/compatdata/*/pfx/system.reg \
|
||||
/root/Games/*/steamapps/compatdata/*/pfx/system.reg; do
|
||||
[ -f "$reg" ] && [ ! -f "${reg%/*}/.droiddeck-redists" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
@@ -601,7 +641,11 @@ case $mode in
|
||||
nap 5
|
||||
beat=$((beat + 1))
|
||||
[ "$((beat % 3))" -eq 0 ] || continue
|
||||
droiddeck-seed-redists "$steam_root" >/dev/null 2>&1 || true
|
||||
libraries=("$steam_root/steamapps" /mnt/droiddeck/steamapps /mnt/droiddeck-sd/steamapps /root/Games/*/steamapps)
|
||||
if seed_due; then
|
||||
: > "$seed_stamp"
|
||||
droiddeck-seed-redists "$steam_root" >/dev/null 2>&1 || true
|
||||
fi
|
||||
if compat_due; then
|
||||
: > "$compat_stamp"
|
||||
steam-compatibility "$steam_root" >/dev/null 2>&1 || true
|
||||
@@ -839,6 +883,34 @@ BUSCONF
|
||||
# session can never again loop in silence, which reads as a menu opening and closing by itself.
|
||||
steam_updates=0
|
||||
rm -f "$HOME/.bl-stop-requested"
|
||||
# The client brings a game it launched to the front only while it counts someone as present,
|
||||
# which it reads from gamescope's input counter. A game the app launches after a few minutes
|
||||
# with no touch starts behind the library page and stays there until the next input (device,
|
||||
# 2026-10-09). The game's window turning up behind the interface is counted as one input, as
|
||||
# gamescope counts a key.
|
||||
steam_bring_forward() {
|
||||
local end=$((SECONDS + 600)) behind=0 line name value focused other n
|
||||
while [ "$SECONDS" -lt "$end" ]; do
|
||||
nap 2
|
||||
focused= other=
|
||||
while IFS= read -r line; do
|
||||
name=${line%%(*} value=${line#*= }
|
||||
case $name in
|
||||
GAMESCOPE_FOCUSED_APP) focused=$value ;;
|
||||
GAMESCOPE_FOCUSABLE_APPS) for n in ${value//,/ }; do [ "$n" = 769 ] || other=1; done ;;
|
||||
esac
|
||||
done < <(xprop -root GAMESCOPE_FOCUSED_APP GAMESCOPE_FOCUSABLE_APPS 2>/dev/null)
|
||||
[ -n "$focused" ] || continue
|
||||
[ "$focused" = 769 ] || return 0
|
||||
if [ -n "$other" ]; then behind=$((behind + 1)); else behind=0; fi
|
||||
[ "$behind" -ge 2 ] || continue
|
||||
n=$(xprop -root GAMESCOPE_INPUT_COUNTER 2>/dev/null | sed -n 's/.*= *//p')
|
||||
case $n in ''|*[!0-9]*) n=0 ;; esac
|
||||
xprop -root -f GAMESCOPE_INPUT_COUNTER 32c -set GAMESCOPE_INPUT_COUNTER $(((n + 1) % 4294967296)) 2>/dev/null
|
||||
echo "== steam: the game's window came up behind the interface; counted as an input"
|
||||
return 0
|
||||
done
|
||||
}
|
||||
if [ -n "${BL_LAUNCH_DIR:-}" ] && [ -d "$BL_LAUNCH_DIR" ]; then
|
||||
rm -f "$BL_LAUNCH_DIR/steam-stop" "$BL_LAUNCH_DIR/steam-game" "$BL_LAUNCH_DIR/steam-game.tmp"
|
||||
(
|
||||
@@ -862,6 +934,9 @@ BUSCONF
|
||||
}; then
|
||||
echo "== steam: launching requested game $game_id in the running client"
|
||||
"$steam_root/steamrtarm64/steam" "steam://rungameid/$game_id" >/dev/null 2>&1 &
|
||||
[ -n "${forward_pid:-}" ] && kill "$forward_pid" 2>/dev/null
|
||||
steam_bring_forward &
|
||||
forward_pid=$!
|
||||
else
|
||||
echo "== steam: ignored out-of-range game launch request"
|
||||
fi
|
||||
|
||||
@@ -155,11 +155,23 @@ bl_components() {
|
||||
cm_build=$(awk 'NR == 1 { print $2 }' "$base/version" 2>/dev/null)
|
||||
cm_fixed=0
|
||||
cm_checked=0
|
||||
# One sha256sum for every file: each program started here pays a dozen traced library lookups
|
||||
# under the game's search path before it does anything.
|
||||
local cm_rows=() cm_files=() row h p
|
||||
local -A cm_sums=()
|
||||
while IFS=$'\\t' read -r t want comp rel sum src; do
|
||||
[ "$t" = "$cm_tool" ] && [ "$want" = "$cm_build" ] || continue
|
||||
cm_rows+=("$comp"$'\\t'"$rel"$'\\t'"$sum"$'\\t'"$src")
|
||||
[ -f "$base/$rel" ] && cm_files+=("$base/$rel")
|
||||
done < "$cm_list"
|
||||
if [ ${#cm_files[@]} -gt 0 ]; then
|
||||
while read -r h p; do cm_sums["$p"]=$h; done < <(sha256sum -- "${cm_files[@]}" 2>/dev/null)
|
||||
fi
|
||||
for row in "${cm_rows[@]}"; do
|
||||
IFS=$'\\t' read -r comp rel sum src <<< "$row"
|
||||
cm_checked=$((cm_checked + 1))
|
||||
f="$base/$rel"
|
||||
if [ -f "$f" ] && [ "$(sha256sum "$f" | cut -d' ' -f1)" = "$sum" ]; then continue; fi
|
||||
if [ -f "$f" ] && [ "${cm_sums[$f]:-}" = "$sum" ]; then continue; fi
|
||||
if [ ! -f "$src" ]; then
|
||||
echo "droiddeck-proton: components: $comp source missing ($src), left as it is" >&2
|
||||
continue
|
||||
@@ -168,7 +180,7 @@ bl_components() {
|
||||
cp -f "$src" "$f.bl-new" && mv -f "$f.bl-new" "$f" || continue
|
||||
case "$rel" in *.so) chmod 755 "$f" ;; *) chmod 644 "$f" ;; esac
|
||||
cm_fixed=$((cm_fixed + 1))
|
||||
done < "$cm_list"
|
||||
done
|
||||
[ "$cm_checked" -gt 0 ] && echo "droiddeck-proton: components: checked $cm_checked file(s) in $cm_tool for app $cm_app" >&2
|
||||
if [ "$cm_fixed" -gt 0 ]; then
|
||||
echo "droiddeck-proton: components: re-applied $cm_fixed of $cm_checked file(s) in $cm_tool before this launch" >&2
|
||||
@@ -347,6 +359,16 @@ for fake in /usr/local/lib/libfakeinput.so /usr/local/lib/libblsession.so; do
|
||||
esac
|
||||
fi
|
||||
done
|
||||
# ld.so looks every library up along the game's search path (its own directory, Steam's runtime
|
||||
# and video directories, Proton's), and under proot each miss is a round trip to the tracer. With
|
||||
# the fast path, the audit module skips the misses it can prove (tools/proot/fastpath/audit.c).
|
||||
audit=/usr/local/lib/libblaudit.so
|
||||
if [ -n "${PROOT_FP_KEY:-}" ] && [ -f "$audit" ]; then
|
||||
case ":${LD_AUDIT:-}:" in
|
||||
*":$audit:"*) ;;
|
||||
*) LD_AUDIT="$audit${LD_AUDIT:+:$LD_AUDIT}"; export LD_AUDIT ;;
|
||||
esac
|
||||
fi
|
||||
# The depot this tool is named after, newest across the libraries that hold it; the others in the
|
||||
# list stand in only when it is missing.
|
||||
depot=
|
||||
@@ -427,6 +449,14 @@ for fake in /usr/local/lib/libfakeinput.so /usr/local/lib/libblsession.so; do
|
||||
esac
|
||||
fi
|
||||
done
|
||||
# See droiddeck-proton: library lookups that cannot succeed are skipped with the fast path.
|
||||
audit=/usr/local/lib/libblaudit.so
|
||||
if [ -n "${PROOT_FP_KEY:-}" ] && [ -f "$audit" ]; then
|
||||
case ":${LD_AUDIT:-}:" in
|
||||
*":$audit:"*) ;;
|
||||
*) LD_AUDIT="$audit${LD_AUDIT:+:$LD_AUDIT}"; export LD_AUDIT ;;
|
||||
esac
|
||||
fi
|
||||
bl_components "$here"
|
||||
bl_directaudio "$here"
|
||||
bl_game_cpus
|
||||
|
||||
@@ -12,16 +12,27 @@
|
||||
* the lock excludes as before, and the holder removes both names when it is done. Every other
|
||||
* link keeps the real answer: a program that links a file into place and then deletes the
|
||||
* original would be left with a dangling symlink.
|
||||
*
|
||||
* That pattern itself is answered for one caller that asks: with DROIDDECK_LINK_RENAME=1 (the
|
||||
* session sets it for localedef, which names a finished locale archive that way) a refused link
|
||||
* becomes a rename that will not replace an existing name, which is all the link promised there.
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int refused(int error) { return error == EPERM || error == EACCES; }
|
||||
|
||||
static int moves_instead(void) {
|
||||
const char *v = getenv("DROIDDECK_LINK_RENAME");
|
||||
return v != NULL && strcmp(v, "1") == 0;
|
||||
}
|
||||
|
||||
static int lock_name(const char *path) {
|
||||
size_t n = path ? strlen(path) : 0;
|
||||
return n > 2 && strcmp(path + n - 2, "-l") == 0;
|
||||
@@ -31,7 +42,9 @@ static int lock_name(const char *path) {
|
||||
__attribute__((visibility("hidden"))) int bl_link_lock(const char *oldpath, const char *newpath, int result) {
|
||||
/* libc's own symlink: dircache.c's wrapper may be holding its lock around this call. */
|
||||
static int (*real_symlink)(const char *, const char *);
|
||||
if (result == 0 || !refused(errno) || !lock_name(newpath)) return result;
|
||||
if (result == 0 || !refused(errno)) return result;
|
||||
if (moves_instead()) return renameat2(AT_FDCWD, oldpath, AT_FDCWD, newpath, RENAME_NOREPLACE);
|
||||
if (!lock_name(newpath)) return result;
|
||||
if (real_symlink == NULL) real_symlink = dlsym(RTLD_NEXT, "symlink");
|
||||
return real_symlink(oldpath, newpath);
|
||||
}
|
||||
@@ -49,6 +62,8 @@ int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath,
|
||||
static int (*real_linkat)(int, const char *, int, const char *, int);
|
||||
if (real_linkat == NULL) real_linkat = dlsym(RTLD_NEXT, "linkat");
|
||||
int result = real_linkat(olddirfd, oldpath, newdirfd, newpath, flags);
|
||||
if (result != 0 && refused(errno) && flags == 0 && moves_instead())
|
||||
return renameat2(olddirfd, oldpath, newdirfd, newpath, RENAME_NOREPLACE);
|
||||
/* A relative old name would resolve against the new name's directory as a symlink's target. */
|
||||
if (result != 0 && refused(errno) && lock_name(newpath) && oldpath[0] == '/' && flags == 0)
|
||||
return symlinkat(oldpath, newdirfd, newpath);
|
||||
|
||||
Reference in new issue
Block a user