mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 22:36:00 +00:00
Performance: idle front end, proot stops, launch-time passes and log collection (#529)
* Front end: draw the capsule wall without clipping it every frame The tilted wall clipped each capsule to a rounded rect and recomposed its columns on every drift step, and a rotated rounded clip is rasterised in software on the render threads: the idle main page held about 1.7 cores. The art is now loaded at the capsule's size with its corners already rounded, each column draws its capsules itself in one layer moved by the drift, and the drift advances at most every 15 ms. The idle page takes about a third of a core. * libfakeinput: let calls on descriptors it does not serve skip its lock Every read, write, ioctl, close and poll of every process in a Proton session went through the controller lock and the three map lookups, Wine's wineserver pipes and the game's files alike. A bitmap of the descriptors the maps hold, set before one is handed out and cleared when it is closed, lets everything else go straight to the kernel. * Pad motion: ask the display for its rotation four times a second The rotation was looked up for every sensor reading, every 2 ms, and cost more than the rest of the reading; it is now refreshed every 250 ms, and the readings no longer allocate pairs. * Session: keep the library passes out of a game's launch The redist seeder stamped each prefix with the checksum of the whole set of names, which differs between the session's pass and the game launch's (the game's own names are added), so every launch re-appended the markers to every prefix in the library while the game loaded. Each prefix's marker now lists the names it was given and only the missing ones are added. The beat's seed and compatibility passes, and the Lossless Scaling ownership probe (which loads steamclient.so), also wait while a wineserver runs: a launch rewrites the manifest and made them due at exactly that moment. The game's own launch seeds its prefix regardless. * Agent: keep the focus watcher's X connection open while nothing changes The connect timeout stayed on the socket, so with no property change the read timed out, and the watcher dropped the connection, reconnected and took a fresh snapshot every few seconds. * Game environment: start Cyberpunk 2077 without REDlauncher The prelauncher opens REDlauncher, a Qt WebEngine window that hands over to the game half a minute later and then stays up beside it, well over a core busy for as long as the game runs; its own --launcher-skip started the game twice. The game's executable is started directly instead. * netif: answer Wine's network driver from a reading of the link Mortal Kombat X has Wine's network driver enumerate every interface, address and route table hundreds of times a second. Each enumeration read /etc/droiddeck-net several times, asked the kernel for its interface dump again (a netlink socket bound under proot, refused each time) and looked the real functions up with dlsym. The link file is now read at most once a second, a refused dump is not asked for again within that second, and the real functions are looked up once. * Fast path: create memfds without a stop in proot proot looks at a memfd's name only to refuse the few that are then executed or locked; every other memfd_create is now issued from the trampoline. The session's /proc/net and status copies made one per read, a stop each. Without memfd in the kernel the call still goes to proot's ashmem. * Logs: run each redaction rule only on a line that could match it A session's end copies some 70 MB of the Steam client's logs and puts every line through all twenty-odd rules, most of a minute of a core on the phone after every session. Each rule now runs only on a line holding what it cannot match without: its keyword, the five separators of a MAC, the four dashes of a GUID, a long enough hex or token run, the learned account or address text. Lines with non-ASCII text still meet every case-insensitive rule. Over 895,000 lines of real client logs, with the device's accounts and addresses learned, the output is identical and the pass takes a twentieth of the time.
This commit is contained in:
1 parent
f21f20a578
commit
15b2d19f68
11 files changed
+416
-125
No files matched your search
@@ -287,6 +287,9 @@ class FocusWatcher(threading.Thread):
|
||||
x = X(os.environ["DISPLAY"])
|
||||
wanted = {x.atom(name) for name in FOCUS_PROPS}
|
||||
x.select(x.root, 0x400000) # PropertyChangeMask
|
||||
# Waits for events as long as there are none: the connect timeout left in place
|
||||
# here dropped and remade the connection, and took a snapshot, every few seconds.
|
||||
x.s.settimeout(None)
|
||||
self.changed.set()
|
||||
while True:
|
||||
event = x.next_event()
|
||||
|
||||
@@ -106,6 +106,19 @@ def godot_sentry(game):
|
||||
return {"WINEDLLOVERRIDES": ";".join(n + "=d" for n in sentry)}, [], "Godot: Sentry crash handler off"
|
||||
|
||||
|
||||
def skip_red_launcher(command):
|
||||
"""Cyberpunk 2077's prelauncher opens REDlauncher, a Qt WebEngine window that hands over to the
|
||||
game half a minute later and then stays up beside it, well over a core busy for as long as the
|
||||
game runs. The game is started itself instead; the prelauncher's own --launcher-skip started it
|
||||
twice."""
|
||||
if len(command) > 2 and os.path.basename(command[2]).lower() == "redprelauncher.exe":
|
||||
game = os.path.join(os.path.dirname(command[2]), "bin", "x64", "Cyberpunk2077.exe")
|
||||
if os.path.isfile(game):
|
||||
print("droiddeck-game-env: REDlauncher skipped", file=sys.stderr)
|
||||
return command[:2] + [game] + command[3:]
|
||||
return command
|
||||
|
||||
|
||||
def engine_fixes(exe, args):
|
||||
"""Environment and extra arguments a game needs because of what it is built with."""
|
||||
game = Game(exe, args)
|
||||
@@ -269,6 +282,7 @@ def main():
|
||||
waiting = len(command) > 1 and command[1] == "waitforexitandrun"
|
||||
fixes = {}
|
||||
if waiting:
|
||||
command = skip_red_launcher(command)
|
||||
fixes, extra, notes = engine_fixes(command[2], command[3:]) if len(command) > 2 else ({}, [], [])
|
||||
for note in notes:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
|
||||
@@ -108,12 +108,18 @@ vcrt() {
|
||||
done
|
||||
}
|
||||
|
||||
# The stamp is the set of names, taken before the block below dates its keys: stamped from the
|
||||
# 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)
|
||||
# Each prefix's marker lists the names it was given, so it is handed only what it lacks. One stamp
|
||||
# for the whole set flipped between the session's set and the evaluator's (which adds the game's
|
||||
# own names) on every launch, and every prefix was appended to again, inside the launch.
|
||||
want=()
|
||||
declare -A wanted=()
|
||||
while IFS= read -r line; do
|
||||
[[ $line == *$'\t'* ]] && [ -z "${wanted[$line]:-}" ] && wanted[$line]=1 && want+=("$line")
|
||||
done <<<"$pairs"
|
||||
want+=("vcrt"$'\t'"$VCRT_MAJOR.$VCRT_MINOR.$VCRT_BUILD")
|
||||
|
||||
printf -v now '%(%s)T' -1
|
||||
block=$(printf '%s\n' "$pairs" | awk -F'\t' -v now="$now" '
|
||||
block_for() { printf '%s\n' "$@" | awk -F'\t' -v now="$now" '
|
||||
{
|
||||
path = $1
|
||||
sub(/^HKEY_LOCAL_MACHINE\\\\/, "", path)
|
||||
@@ -127,9 +133,10 @@ block=$(printf '%s\n' "$pairs" | awk -F'\t' -v now="$now" '
|
||||
next
|
||||
printf "\n[%s] %d\n\"%s\"=dword:00000001\n", "Software\\\\Wow6432Node\\\\" substr(path, 11), now, $2
|
||||
}
|
||||
')
|
||||
block="$block
|
||||
$(vcrt "$now")"
|
||||
'
|
||||
local line
|
||||
for line; do [[ $line == vcrt$'\t'* ]] && vcrt "$now"; done
|
||||
}
|
||||
|
||||
# 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
|
||||
@@ -147,13 +154,17 @@ for reg in "$steam_root"/steamapps/common/Proton*/files/share/default_pfx*/syste
|
||||
if [ -f "$legacy" ] && [ ! -f "$seeded" ]; then
|
||||
mv -f "$legacy" "$seeded"
|
||||
fi
|
||||
have=
|
||||
[ -f "$seeded" ] && read -r have < "$seeded"
|
||||
[ "$have" = "$stamp" ] && continue
|
||||
declare -A had=()
|
||||
if [ -f "$seeded" ]; then
|
||||
while IFS= read -r line; do [[ $line == *$'\t'* ]] && had[$line]=1; done <"$seeded"
|
||||
fi
|
||||
missing=()
|
||||
for line in "${want[@]}"; do [ -n "${had[$line]:-}" ] || missing+=("$line"); done
|
||||
[ ${#missing[@]} -eq 0 ] && continue
|
||||
dated=$(mktemp) || continue
|
||||
touch -r "$reg" "$dated"
|
||||
if printf '%s\n' "$block" >>"$reg"; then
|
||||
printf '%s\n' "$stamp" >"$seeded"
|
||||
if printf '%s\n' "$(block_for "${missing[@]}")" >>"$reg"; then
|
||||
printf '%s\n' "${!had[@]}" "${missing[@]}" >"$seeded"
|
||||
echo "== seeded redist markers into $reg"
|
||||
fi
|
||||
touch -r "$dated" "$reg"
|
||||
|
||||
@@ -642,11 +642,18 @@ case $mode in
|
||||
beat=$((beat + 1))
|
||||
[ "$((beat % 3))" -eq 0 ] || continue
|
||||
libraries=("$steam_root/steamapps" /mnt/droiddeck/steamapps /mnt/droiddeck-sd/steamapps /root/Games/*/steamapps)
|
||||
if seed_due; then
|
||||
seed=; compat=
|
||||
seed_due && seed=1
|
||||
compat_due && compat=1
|
||||
[ -n "$seed$compat" ] || continue
|
||||
# Not beside a running game: the client rewrites its manifest at each launch, which made both
|
||||
# due while it loaded. Its own launch seeds its prefix (droiddeck-game-env) regardless.
|
||||
pgrep -x wineserver >/dev/null 2>&1 && continue
|
||||
if [ -n "$seed" ]; then
|
||||
: > "$seed_stamp"
|
||||
droiddeck-seed-redists "$steam_root" >/dev/null 2>&1 || true
|
||||
fi
|
||||
if compat_due; then
|
||||
if [ -n "$compat" ]; then
|
||||
: > "$compat_stamp"
|
||||
steam-compatibility "$steam_root" >/dev/null 2>&1 || true
|
||||
fi
|
||||
@@ -869,6 +876,8 @@ BUSCONF
|
||||
for ((_i = 0; _i < 60; _i++)); do
|
||||
nap 30
|
||||
[ -e "$owned" ] && exit 0
|
||||
# Loading steamclient.so under proot takes seconds of CPU: not while a game loads or runs.
|
||||
pgrep -x wineserver >/dev/null 2>&1 && continue
|
||||
answer=$(droiddeck-steam-games probe "$steam_root" 993090 2>/dev/null) || continue
|
||||
case $answer in
|
||||
*'"993090": true'*) mkdir -p "${owned%/*}" && : > "$owned" && echo "== Lossless Scaling: owned" ;;
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <net/if_arp.h>
|
||||
#include <netpacket/packet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -28,6 +29,7 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/socket.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define LINK_FILE "/etc/droiddeck-net"
|
||||
@@ -35,6 +37,7 @@
|
||||
#define LO_INDEX 1
|
||||
#define LO_MTU 65536
|
||||
#define MAX_ADDRS 16
|
||||
#define FRESH_NS 1000000000LL
|
||||
|
||||
struct link_addr {
|
||||
int family;
|
||||
@@ -61,10 +64,11 @@ static int parse_addr(const char *text, struct link_addr *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Read on every call: the app rewrites the file when the device changes network. */
|
||||
static int load_link(struct link *link) {
|
||||
typedef FILE *(*fopen_fn)(const char *, const char *);
|
||||
fopen_fn real_fopen = (fopen_fn) dlsym(RTLD_NEXT, "fopen");
|
||||
typedef FILE *(*fopen_fn)(const char *, const char *);
|
||||
|
||||
static int read_link(struct link *link) {
|
||||
static fopen_fn real_fopen;
|
||||
if (real_fopen == NULL) real_fopen = (fopen_fn) dlsym(RTLD_NEXT, "fopen");
|
||||
FILE *f = real_fopen ? real_fopen(LINK_FILE, "re") : NULL;
|
||||
if (f == NULL) return 0;
|
||||
|
||||
@@ -93,6 +97,50 @@ static int load_link(struct link *link) {
|
||||
return link->name[0] != '\0' && link->index > LO_INDEX && link->addr_count > 0;
|
||||
}
|
||||
|
||||
static long long now_ns(void) {
|
||||
struct timespec ts;
|
||||
clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
|
||||
return ts.tv_sec * 1000000000LL + ts.tv_nsec;
|
||||
}
|
||||
|
||||
static int fresh(long long *at) {
|
||||
long long then = __atomic_load_n(at, __ATOMIC_RELAXED);
|
||||
return then != 0 && now_ns() - then < FRESH_NS;
|
||||
}
|
||||
|
||||
/* Wine's network driver reads the link several times for each table it builds, and some games
|
||||
* have it build them all hundreds of times a second. The app rewrites the file when the device
|
||||
* changes network, so a reading stands for a second. */
|
||||
static pthread_mutex_t link_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static struct link link_read;
|
||||
static int link_ok;
|
||||
static long long link_at;
|
||||
|
||||
static int load_link(struct link *link) {
|
||||
pthread_mutex_lock(&link_lock);
|
||||
if (!fresh(&link_at)) {
|
||||
link_ok = read_link(&link_read);
|
||||
__atomic_store_n(&link_at, now_ns(), __ATOMIC_RELAXED);
|
||||
}
|
||||
int ok = link_ok;
|
||||
if (ok) *link = link_read;
|
||||
pthread_mutex_unlock(&link_lock);
|
||||
return ok;
|
||||
}
|
||||
|
||||
/* See drm.c: a fork must not leave the lock held by a thread the child does not have. */
|
||||
static void link_lock_before_fork(void) { pthread_mutex_lock(&link_lock); }
|
||||
static void link_unlock_after_fork(void) { pthread_mutex_unlock(&link_lock); }
|
||||
static void link_reset_after_fork(void) { pthread_mutex_init(&link_lock, NULL); }
|
||||
|
||||
__attribute__((constructor)) static void install_link_fork_handlers(void) {
|
||||
pthread_atfork(link_lock_before_fork, link_unlock_after_fork, link_reset_after_fork);
|
||||
}
|
||||
|
||||
/* When the kernel's own list was of no use, it is not asked again for a second: each asking binds
|
||||
* a netlink socket, a stop in the tracer, only to be refused again. */
|
||||
static long long ifaddrs_unusable_at, nameindex_unusable_at;
|
||||
|
||||
static void prefix_mask(int family, unsigned prefix, unsigned char *out) {
|
||||
int len = family == AF_INET ? 4 : 16;
|
||||
for (int i = 0; i < len; i++, prefix -= prefix < 8 ? prefix : 8) {
|
||||
@@ -168,25 +216,35 @@ static int real_list_usable(const struct ifaddrs *list) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef void (*freeifaddrs_fn)(struct ifaddrs *);
|
||||
static freeifaddrs_fn real_freeifaddrs;
|
||||
|
||||
int getifaddrs(struct ifaddrs **out) {
|
||||
typedef int (*getifaddrs_fn)(struct ifaddrs **);
|
||||
typedef void (*freeifaddrs_fn)(struct ifaddrs *);
|
||||
getifaddrs_fn real = (getifaddrs_fn) dlsym(RTLD_NEXT, "getifaddrs");
|
||||
static getifaddrs_fn real;
|
||||
if (real == NULL) real = (getifaddrs_fn) dlsym(RTLD_NEXT, "getifaddrs");
|
||||
if (real_freeifaddrs == NULL) real_freeifaddrs = (freeifaddrs_fn) dlsym(RTLD_NEXT, "freeifaddrs");
|
||||
struct ifaddrs *list = NULL;
|
||||
int rc = real(&list);
|
||||
int saved = errno;
|
||||
if (rc == 0 && real_list_usable(list)) {
|
||||
*out = list;
|
||||
return 0;
|
||||
int asked = !fresh(&ifaddrs_unusable_at);
|
||||
int rc = -1, saved = errno;
|
||||
if (asked) {
|
||||
rc = real(&list);
|
||||
saved = errno;
|
||||
if (rc == 0 && real_list_usable(list)) {
|
||||
*out = list;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
struct link link;
|
||||
if (!load_link(&link)) {
|
||||
if (!asked) return real(out);
|
||||
if (rc == 0) *out = list;
|
||||
errno = saved;
|
||||
return rc;
|
||||
}
|
||||
if (rc == 0 && list) ((freeifaddrs_fn) dlsym(RTLD_NEXT, "freeifaddrs"))(list);
|
||||
if (asked) __atomic_store_n(&ifaddrs_unusable_at, now_ns(), __ATOMIC_RELAXED);
|
||||
if (rc == 0 && list) real_freeifaddrs(list);
|
||||
|
||||
/* A leading slot keeps fill_entry()'s back link in bounds; the list starts after it. */
|
||||
struct entry *block = calloc((size_t) link.addr_count + 5, sizeof(*block));
|
||||
@@ -210,13 +268,13 @@ int getifaddrs(struct ifaddrs **out) {
|
||||
}
|
||||
|
||||
void freeifaddrs(struct ifaddrs *list) {
|
||||
typedef void (*freeifaddrs_fn)(struct ifaddrs *);
|
||||
if (list == NULL) return;
|
||||
if (list->ifa_data == list) {
|
||||
free((struct entry *) list - 1);
|
||||
return;
|
||||
}
|
||||
((freeifaddrs_fn) dlsym(RTLD_NEXT, "freeifaddrs"))(list);
|
||||
if (real_freeifaddrs == NULL) real_freeifaddrs = (freeifaddrs_fn) dlsym(RTLD_NEXT, "freeifaddrs");
|
||||
real_freeifaddrs(list);
|
||||
}
|
||||
|
||||
/* Names live in the same allocation as the array, right behind it; glibc strdup()s each one. */
|
||||
@@ -227,16 +285,29 @@ struct name_block {
|
||||
|
||||
struct if_nameindex *if_nameindex(void) {
|
||||
typedef struct if_nameindex *(*if_nameindex_fn)(void);
|
||||
struct if_nameindex *list = ((if_nameindex_fn) dlsym(RTLD_NEXT, "if_nameindex"))();
|
||||
static if_nameindex_fn real;
|
||||
if (real == NULL) real = (if_nameindex_fn) dlsym(RTLD_NEXT, "if_nameindex");
|
||||
struct if_nameindex *list = NULL;
|
||||
int asked = !fresh(&nameindex_unusable_at);
|
||||
int saved = errno;
|
||||
if (list && list[0].if_index != 0) return list;
|
||||
if (asked) {
|
||||
list = real();
|
||||
saved = errno;
|
||||
if (list && list[0].if_index != 0) return list;
|
||||
}
|
||||
|
||||
struct link link;
|
||||
struct name_block *block;
|
||||
if (!load_link(&link) || (block = calloc(1, sizeof(*block))) == NULL) {
|
||||
if (!load_link(&link)) {
|
||||
if (!asked) return real();
|
||||
errno = saved;
|
||||
return list;
|
||||
}
|
||||
if (asked) __atomic_store_n(&nameindex_unusable_at, now_ns(), __ATOMIC_RELAXED);
|
||||
if ((block = calloc(1, sizeof(*block))) == NULL) {
|
||||
if (asked) errno = saved;
|
||||
return list;
|
||||
}
|
||||
if (list) if_freenameindex(list);
|
||||
snprintf(block->names[0], IFNAMSIZ, "%s", LO_NAME);
|
||||
snprintf(block->names[1], IFNAMSIZ, "%s", link.name);
|
||||
@@ -489,8 +560,7 @@ static FILE *synthesize(const char *table) {
|
||||
/* tracer.c */
|
||||
int bl_status_without_tracer(const char *path, int flags) __attribute__((visibility("hidden")));
|
||||
|
||||
static FILE *open_stream(const char *symbol, const char *path, const char *mode) {
|
||||
typedef FILE *(*fopen_fn)(const char *, const char *);
|
||||
static FILE *open_stream(fopen_fn real, const char *path, const char *mode) {
|
||||
int status = mode && mode[0] == 'r' && !strchr(mode, '+')
|
||||
? bl_status_without_tracer(path, O_RDONLY | O_CLOEXEC) : -1;
|
||||
if (status >= 0) {
|
||||
@@ -498,7 +568,7 @@ static FILE *open_stream(const char *symbol, const char *path, const char *mode)
|
||||
if (copy == NULL) close(status);
|
||||
return copy;
|
||||
}
|
||||
FILE *f = ((fopen_fn) dlsym(RTLD_NEXT, symbol))(path, mode);
|
||||
FILE *f = real(path, mode);
|
||||
if (f || path == NULL || mode == NULL || mode[0] != 'r') return f;
|
||||
int saved = errno;
|
||||
const char *table = denied_table(path);
|
||||
@@ -508,9 +578,13 @@ static FILE *open_stream(const char *symbol, const char *path, const char *mode)
|
||||
}
|
||||
|
||||
FILE *fopen(const char *path, const char *mode) {
|
||||
return open_stream("fopen", path, mode);
|
||||
static fopen_fn real;
|
||||
if (real == NULL) real = (fopen_fn) dlsym(RTLD_NEXT, "fopen");
|
||||
return open_stream(real, path, mode);
|
||||
}
|
||||
|
||||
FILE *fopen64(const char *path, const char *mode) {
|
||||
return open_stream("fopen64", path, mode);
|
||||
static fopen_fn real;
|
||||
if (real == NULL) real = (fopen_fn) dlsym(RTLD_NEXT, "fopen64");
|
||||
return open_stream(real, path, mode);
|
||||
}
|
||||
Reference in new issue
Block a user