diff options
| author | NotRexed <therealnothingfn@gmail.com> | 2026-11-28 15:14:52 -0500 |
|---|---|---|
| committer | NotRexed <therealnothingfn@gmail.com> | 2026-11-28 15:14:52 -0500 |
| commit | 127ffbfa3bd88dfaf77f03daab7c5c32bfacdb60 (patch) | |
| tree | 77aa12cb0644f382f922d652f954a5dc5a3af4a2 /scripts | |
| parent | 95ac2e96aa6976d9095151a71aefeace6335c565 (diff) | |
| parent | 13ed298fa2d6b4eb9969a9196e4b4f38624e513c (diff) | |
Merge remote-tracking branch 'origin/main' into merge/push-m4
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/audit_shader4_regs.py | 5 | ||||
| -rw-r--r-- | scripts/check_no_game_data.py | 20 | ||||
| -rw-r--r-- | scripts/dev.py | 11 | ||||
| -rwxr-xr-x | scripts/linux-boot/boot-digest.sh | 31 | ||||
| -rwxr-xr-x | scripts/linux-boot/boot-inner.sh | 117 | ||||
| -rwxr-xr-x | scripts/linux-boot/boot.sh | 77 | ||||
| -rwxr-xr-x | scripts/linux-boot/configure-worktree.sh | 51 | ||||
| -rwxr-xr-x | scripts/linux-boot/run-boot.sh | 30 | ||||
| -rwxr-xr-x | scripts/run_game_wine.sh | 48 | ||||
| -rwxr-xr-x | scripts/run_wine_session.sh | 18 | ||||
| -rw-r--r-- | scripts/run_wine_tests.py | 13 | ||||
| -rw-r--r-- | scripts/vs_input_survey.py | 5 |
12 files changed, 340 insertions, 86 deletions
diff --git a/scripts/audit_shader4_regs.py b/scripts/audit_shader4_regs.py index fdac5b05d..9f651fbe5 100644 --- a/scripts/audit_shader4_regs.py +++ b/scripts/audit_shader4_regs.py | |||
| @@ -231,10 +231,13 @@ def rbw_registers(insns): | |||
| 231 | is_dual_dst = op.startswith("v_") and ( | 231 | is_dual_dst = op.startswith("v_") and ( |
| 232 | "_co_" in op or op.startswith(("v_mad_u64_u32", "v_mad_i64_i32", "v_div_scale_f32", "v_div_scale_f64")) | 232 | "_co_" in op or op.startswith(("v_mad_u64_u32", "v_mad_i64_i32", "v_div_scale_f32", "v_div_scale_f64")) |
| 233 | ) | 233 | ) |
| 234 | # The assembler's short form v_add_co_ci_u32 vD, src0, src1 (also sub/subrev) has VCC as its carry-out and | ||
| 235 | # carry-in and names neither: args[1] is src0, read, not a carry-out destination. | ||
| 236 | is_short_co_ci = op.endswith("_co_ci_u32") and len(args) == 3 | ||
| 234 | # Carry-out / scale-out forms write the VGPR and scalar mask first, even when they also take a carry-in source. | 237 | # Carry-out / scale-out forms write the VGPR and scalar mask first, even when they also take a carry-in source. |
| 235 | if is_lds_load: | 238 | if is_lds_load: |
| 236 | dsts, srcs = [], args | 239 | dsts, srcs = [], args |
| 237 | elif not is_no_dest and is_dual_dst and len(args) >= 2: | 240 | elif not is_no_dest and is_dual_dst and len(args) >= 2 and not is_short_co_ci: |
| 238 | dsts = args[:2] | 241 | dsts = args[:2] |
| 239 | srcs = args[2:] | 242 | srcs = args[2:] |
| 240 | elif is_no_dest: | 243 | elif is_no_dest: |
diff --git a/scripts/check_no_game_data.py b/scripts/check_no_game_data.py index 595fc7b1c..92097253c 100644 --- a/scripts/check_no_game_data.py +++ b/scripts/check_no_game_data.py | |||
| @@ -3,6 +3,10 @@ | |||
| 3 | python3 -I scripts/check_no_game_data.py # every file `git ls-files` lists | 3 | python3 -I scripts/check_no_game_data.py # every file `git ls-files` lists |
| 4 | python3 -I scripts/check_no_game_data.py PATH... # only these files | 4 | python3 -I scripts/check_no_game_data.py PATH... # only these files |
| 5 | 5 | ||
| 6 | Explicit PATH inputs must be regular files, not directories or symlinks. A missing, unreadable or non-regular | ||
| 7 | explicit input is reported on stderr and causes exit 2 unless another input matches game data (exit 1). | ||
| 8 | Default git enumeration still skips symlinks, submodules and files deleted from the working tree. | ||
| 9 | |||
| 6 | The extension check in .github/workflows/no-game-data.yml misses a renamed file: a DDS saved as .bin, an executable | 10 | The extension check in .github/workflows/no-game-data.yml misses a renamed file: a DDS saved as .bin, an executable |
| 7 | as .txt. This reads the first bytes of each file and matches the magic numbers of the package's formats and the | 11 | as .txt. This reads the first bytes of each file and matches the magic numbers of the package's formats and the |
| 8 | files the build extracts from it: RPF9 archives, TTPF texture pools, RAGE resources, XBCH/FSSM/DXBC shader | 12 | files the build extracts from it: RPF9 archives, TTPF texture pools, RAGE resources, XBCH/FSSM/DXBC shader |
| @@ -25,10 +29,12 @@ exits 1 if there is any. It exits 2 when a file cannot be read or git cannot lis | |||
| 25 | repository, or git not installed). Standard library only, no game files. | 29 | repository, or git not installed). Standard library only, no game files. |
| 26 | """ | 30 | """ |
| 27 | import bz2 | 31 | import bz2 |
| 32 | import errno | ||
| 28 | import gzip | 33 | import gzip |
| 29 | import io | 34 | import io |
| 30 | import lzma | 35 | import lzma |
| 31 | import os | 36 | import os |
| 37 | import stat | ||
| 32 | import subprocess | 38 | import subprocess |
| 33 | import sys | 39 | import sys |
| 34 | import tarfile | 40 | import tarfile |
| @@ -274,15 +280,19 @@ def git_error(e): | |||
| 274 | return e.strerror or str(e) | 280 | return e.strerror or str(e) |
| 275 | 281 | ||
| 276 | 282 | ||
| 277 | def check(paths, unreadable=None): | 283 | def check(paths, unreadable=None, *, explicit=False): |
| 278 | """[(path, format)] for every regular file in `paths` that starts like game data. | 284 | """[(path, format)] for every regular file in `paths` that starts like game data. |
| 279 | 285 | ||
| 280 | A file that exists but cannot be opened or read is appended to `unreadable` (when given) as (path, error).""" | 286 | Files that cannot be opened or read are appended to `unreadable` (when given) as (path, error). |
| 287 | Explicit inputs also report missing paths and non-regular entries instead of silently skipping them.""" | ||
| 281 | found = [] | 288 | found = [] |
| 282 | for path in paths: | 289 | for path in paths: |
| 283 | if os.path.islink(path) or not os.path.isfile(path): | ||
| 284 | continue # submodules, symlinks, files deleted in the working tree | ||
| 285 | try: | 290 | try: |
| 291 | if explicit: | ||
| 292 | if not stat.S_ISREG(os.lstat(path).st_mode): | ||
| 293 | raise OSError(errno.EINVAL, "not a regular file", path) | ||
| 294 | elif os.path.islink(path) or not os.path.isfile(path): | ||
| 295 | continue # submodules, symlinks, files deleted in the working tree | ||
| 286 | name = classify_file(path) | 296 | name = classify_file(path) |
| 287 | except OSError as e: | 297 | except OSError as e: |
| 288 | if unreadable is not None: | 298 | if unreadable is not None: |
| @@ -311,7 +321,7 @@ def main(argv): | |||
| 311 | print(f"check_no_game_data: cannot list the tracked files with git: {git_error(e)}", file=sys.stderr) | 321 | print(f"check_no_game_data: cannot list the tracked files with git: {git_error(e)}", file=sys.stderr) |
| 312 | return 2 # not 1: that is the 'game data found' code | 322 | return 2 # not 1: that is the 'game data found' code |
| 313 | unreadable = [] | 323 | unreadable = [] |
| 314 | found = check(paths, unreadable) | 324 | found = check(paths, unreadable, explicit=bool(argv)) |
| 315 | for path, name in found: | 325 | for path, name in found: |
| 316 | print(f"{display(path)}: {name}") | 326 | print(f"{display(path)}: {name}") |
| 317 | for path, e in unreadable: | 327 | for path, e in unreadable: |
diff --git a/scripts/dev.py b/scripts/dev.py index 4170aac63..00bf1bb21 100644 --- a/scripts/dev.py +++ b/scripts/dev.py | |||
| @@ -90,15 +90,15 @@ def guest_scene(args: list[str]) -> int: | |||
| 90 | parser.add_argument("-h", "--help", action="store_true") | 90 | parser.add_argument("-h", "--help", action="store_true") |
| 91 | parser.add_argument("--out", metavar="PATH") | 91 | parser.add_argument("--out", metavar="PATH") |
| 92 | options, _ = parser.parse_known_args(args) | 92 | options, _ = parser.parse_known_args(args) |
| 93 | if not options.help and not options.out: | 93 | if not options.help and not (options.out and options.out.strip()): |
| 94 | parser.error("--out PATH is required to keep the scene results") | 94 | parser.error("--out PATH is required to keep the scene results") |
| 95 | 95 | ||
| 96 | return run_producer(GUEST_SCENE, args) | 96 | return run_producer(GUEST_SCENE, args) |
| 97 | 97 | ||
| 98 | 98 | ||
| 99 | def main() -> int: | 99 | def main(argv: list[str] | None = None) -> int: |
| 100 | # The producer owns its arguments and help. Forward before argparse handles them. | 100 | # The producer owns its arguments and help. Forward before argparse handles them. |
| 101 | argv = sys.argv[1:] | 101 | argv = sys.argv[1:] if argv is None else list(argv) |
| 102 | if argv[:1] == ["boot-trace"]: | 102 | if argv[:1] == ["boot-trace"]: |
| 103 | return run_producer(BOOT_TRACE, argv[1:]) | 103 | return run_producer(BOOT_TRACE, argv[1:]) |
| 104 | if argv[:1] == ["guest-scene"]: | 104 | if argv[:1] == ["guest-scene"]: |
| @@ -119,7 +119,10 @@ def main() -> int: | |||
| 119 | if args.json: | 119 | if args.json: |
| 120 | print(json.dumps(result, indent=2)) | 120 | print(json.dumps(result, indent=2)) |
| 121 | else: | 121 | else: |
| 122 | sys.stdout.reconfigure(encoding="utf-8") | 122 | try: |
| 123 | sys.stdout.reconfigure(encoding="utf-8") | ||
| 124 | except (AttributeError, ValueError, OSError): | ||
| 125 | pass | ||
| 123 | print("Paths and help commands are relative to the Leonida checkout root.") | 126 | print("Paths and help commands are relative to the Leonida checkout root.") |
| 124 | for tool in result["tools"]: | 127 | for tool in result["tools"]: |
| 125 | status = "present" if tool["present"] else "missing" | 128 | status = "present" if tool["present"] else "missing" |
diff --git a/scripts/linux-boot/boot-digest.sh b/scripts/linux-boot/boot-digest.sh index dd2289e30..9a7c06d68 100755 --- a/scripts/linux-boot/boot-digest.sh +++ b/scripts/linux-boot/boot-digest.sh | |||
| @@ -3,14 +3,23 @@ | |||
| 3 | # Writes /opt/leonida/work/<agent>/boot-<n>.digest.txt and appends a line to /opt/leonida/work/boots.tsv. | 3 | # Writes /opt/leonida/work/<agent>/boot-<n>.digest.txt and appends a line to /opt/leonida/work/boots.tsv. |
| 4 | # Local only: digests quote trace lines, so they never go into commits or PRs. | 4 | # Local only: digests quote trace lines, so they never go into commits or PRs. |
| 5 | set -u | 5 | set -u |
| 6 | AGENT=$1; N=$2; WORK=/opt/leonida/work/$AGENT; LOG=$WORK/boot-$N.log; RES=$WORK/boot-$N.resources.tsv | 6 | AGENT=${1:?agent}; N=${2:?n} |
| 7 | META=$WORK/boot-$N.meta; OUT=$WORK/boot-$N.digest.txt; LEDGER=/opt/leonida/work/boots.tsv | 7 | if [ "$AGENT" = "." ] || [ "$AGENT" = ".." ] || ! [[ "$AGENT" =~ ^[A-Za-z0-9._-]+$ ]]; then |
| 8 | echo "boot-digest: invalid agent: $AGENT" >&2; exit 2 | ||
| 9 | fi | ||
| 10 | if ! [[ "$N" =~ ^[0-9]+$ ]]; then | ||
| 11 | echo "boot-digest: invalid boot number: $N" >&2; exit 2 | ||
| 12 | fi | ||
| 13 | ROOT=${LEONIDA_BOOT_ROOT:-/opt/leonida} | ||
| 14 | WORK=$ROOT/work/$AGENT; LOG=$WORK/boot-$N.log; RES=$WORK/boot-$N.resources.tsv | ||
| 15 | META=$WORK/boot-$N.meta; OUT=$WORK/boot-$N.digest.txt; LEDGER=$ROOT/work/boots.tsv | ||
| 16 | mkdir -p "$WORK" "$(dirname "$LEDGER")" | ||
| 8 | START=$(sed -n 's/^start_epoch=//p' "$META" 2>/dev/null); BOOT=$(sed -n 's/^boot_epoch=//p' "$META" 2>/dev/null) | 17 | START=$(sed -n 's/^start_epoch=//p' "$META" 2>/dev/null); BOOT=$(sed -n 's/^boot_epoch=//p' "$META" 2>/dev/null) |
| 9 | START=${START:-$(date +%s)}; BOOT=${BOOT:-$START}; END=$(date +%s) | 18 | START=${START:-$(date +%s)}; BOOT=${BOOT:-$START}; END=$(date +%s) |
| 10 | RESULT=${SERVICE_RESULT:-?}; ECODE=${EXIT_CODE:-?}; ESTAT=${EXIT_STATUS:-?} | 19 | RESULT=${SERVICE_RESULT:-?}; ECODE=${EXIT_CODE:-?}; ESTAT=${EXIT_STATUS:-?} |
| 11 | D3D=$(grep -o 'd3d12=[^ ]*' "$LOG" 2>/dev/null | tail -1 | cut -d= -f2) | 20 | D3D=$(grep -o 'd3d12=[^ ]*' "$LOG" 2>/dev/null | tail -1 | cut -d= -f2) |
| 12 | STDOUT=${D3D/d3d12-run-/stdout-run-} | 21 | STDOUT=${D3D/d3d12-run-/stdout-run-} |
| 13 | CAP=/opt/leonida/capture/$AGENT-$N | 22 | CAP=$ROOT/capture/$AGENT-$N |
| 14 | 23 | ||
| 15 | verdict=OK | 24 | verdict=OK |
| 16 | # systemd-oomd can kill the unit's processes without the unit ending in "oom-kill" (boot.sh then exits on its own). | 25 | # systemd-oomd can kill the unit's processes without the unit ending in "oom-kill" (boot.sh then exits on its own). |
| @@ -39,15 +48,15 @@ cnt() { local c=0; [ -f "$D3D" ] && c=$(grep -a -c -E "$@" "$D3D"); echo "${c:-0 | |||
| 39 | grep -a 'present-probe: source frame .* via' "$D3D" 2>/dev/null | tail -1 | sed 's/.*via/source via/' | cut -c1-120 | 48 | grep -a 'present-probe: source frame .* via' "$D3D" 2>/dev/null | tail -1 | sed 's/.*via/source via/' | cut -c1-120 |
| 40 | echo | 49 | echo |
| 41 | echo "-- frames (swapchain; then the title's own backbuffer when LEONIDA_CAPTURE_SOURCE=1)" | 50 | echo "-- frames (swapchain; then the title's own backbuffer when LEONIDA_CAPTURE_SOURCE=1)" |
| 42 | [ -f "$CAP/index.txt" ] && { echo "$(wc -l < "$CAP/index.txt") captured; last: $(tail -1 "$CAP/index.txt" | cut -c1-110)"; awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print n+0 " of " NR " frames non-black"}' "$CAP/index.txt"; } || echo "no capture index" | 51 | [ -s "$CAP/index.txt" ] && { echo "$(wc -l < "$CAP/index.txt") captured; last: $(tail -1 "$CAP/index.txt" | cut -c1-110)"; awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print n+0 " of " NR " frames non-black"}' "$CAP/index.txt"; } || echo "no capture index" |
| 43 | grep -a 'present-probe: source frame .* mean' "$D3D" 2>/dev/null | tail -2 | sed 's/.*source frame/source frame/' | cut -c1-140 | 52 | grep -a 'present-probe: source frame .* mean' "$D3D" 2>/dev/null | tail -2 | sed 's/.*source frame/source frame/' | cut -c1-140 |
| 44 | echo | 53 | echo |
| 45 | echo "-- resources (2 s samples)" | 54 | echo "-- resources (2 s samples)" |
| 46 | [ -s "$RES" ] && awk -F'\t' 'NR>1{ if(min==""||$2<min)min=$2; if($3>sw)sw=$3; if($4>um)um=$4; if($5>us)us=$5; if($6+0>gm)gm=$6 } END{printf "min RAM available %s MB, max swap used %s MB, game peak %s MB RAM + %s MB swap, VRAM peak %s MB\n",min,sw,um,us,gm}' "$RES" || echo "no samples" | 55 | [ -s "$RES" ] && awk -F'\t' 'NR>1{ c++; if(min==""||$2<min)min=$2; if($3>sw)sw=$3; if($4>um)um=$4; if($5>us)us=$5; if($6+0>gm)gm=$6 } END{ if(c>0) printf "min RAM available %s MB, max swap used %s MB, game peak %s MB RAM + %s MB swap, VRAM peak %s MB\n",min,sw,um,us,gm; else print "no samples" }' "$RES" || echo "no samples" |
| 47 | journalctl --user -u "leonida-boot-$AGENT-$N" --since "@$START" -q --no-pager 2>/dev/null | grep -E 'Consumed|oom|Failed' | sed 's/^.*\]: //' | sort -u | cut -c1-200 | 56 | journalctl --user -u "leonida-boot-$AGENT-$N" --since "@$START" -q --no-pager 2>/dev/null | grep -E 'Consumed|oom|Failed' | sed 's/^.*\]: //' | sort -u | cut -c1-200 |
| 48 | # Compare with other boots instead of guessing: on the console (Series S) path the title itself grows to ~20 GB of | 57 | # Compare with other boots instead of guessing: on the console (Series S) path the title itself grows to ~20 GB of |
| 49 | # RAM+swap by ~130 s (fsdraw-6: 9.9 GB + 11.2 GB), mostly zero pages that zram compresses well. | 58 | # RAM+swap by ~130 s (fsdraw-6: 9.9 GB + 11.2 GB), mostly zero pages that zram compresses well. |
| 50 | [ -s "$RES" ] && awk -F'\t' 'NR>1{t=$4+$5; if(t>m)m=t} END{printf "game peak RAM+swap %.1f GB (console-path baseline ~20 GB at 130 s; oomd kills when zram swap passes 98%%)\n", m/1024}' "$RES" | 59 | [ -s "$RES" ] && awk -F'\t' 'NR>1{ c++; t=$4+$5; if(t>m)m=t } END{ if(c>0) printf "game peak RAM+swap %.1f GB (console-path baseline ~20 GB at 130 s; oomd kills when zram swap passes 98%%)\n", m/1024 }' "$RES" |
| 51 | echo | 60 | echo |
| 52 | echo "-- system events during the boot (OOM, GPU Xid, segfaults)" | 61 | echo "-- system events during the boot (OOM, GPU Xid, segfaults)" |
| 53 | { journalctl --since "@$BOOT" -q --no-pager 2>/dev/null | grep -i -E 'systemd-oomd.*(Marked|killed)|oom-kill|out of memory|NVRM: Xid|segfault|gta6rt|wineserver.*crash' ; } | cut -c1-200 | tail -15 | 62 | { journalctl --since "@$BOOT" -q --no-pager 2>/dev/null | grep -i -E 'systemd-oomd.*(Marked|killed)|oom-kill|out of memory|NVRM: Xid|segfault|gta6rt|wineserver.*crash' ; } | cut -c1-200 | tail -15 |
| @@ -63,13 +72,13 @@ cnt() { local c=0; [ -f "$D3D" ] && c=$(grep -a -c -E "$@" "$D3D"); echo "${c:-0 | |||
| 63 | [ -f "$D3D" ] && tail -n 8 "$D3D" | cut -c1-200 | 72 | [ -f "$D3D" ] && tail -n 8 "$D3D" | cut -c1-200 |
| 64 | } > "$OUT" 2>&1 | 73 | } > "$OUT" 2>&1 |
| 65 | 74 | ||
| 66 | frames=$( [ -f "$CAP/index.txt" ] && awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print (n+0) "/" NR}' "$CAP/index.txt" || echo "-") | 75 | frames=$( [ -s "$CAP/index.txt" ] && awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print (n+0) "/" NR}' "$CAP/index.txt" || echo "-") |
| 67 | peak=$( [ -s "$RES" ] && awk -F'\t' 'NR>1{if($4>u)u=$4} END{print u+0}' "$RES" || echo "-") | 76 | peak=$( [ -s "$RES" ] && awk -F'\t' 'NR>1{c++; if($4>u)u=$4} END{if(c>0) print u+0; else print "-"}' "$RES" || echo "-") |
| 68 | exec 7>>"$LEDGER"; flock 7 | 77 | exec 7>>"$LEDGER"; if command -v flock >/dev/null 2>&1; then flock 7; fi |
| 69 | # Both the unit's ExecStopPost and the outer wrapper call this; the first one to finish records the boot. | 78 | # Both the unit's ExecStopPost and the outer wrapper call this; the first one to finish records the boot. |
| 70 | grep -q -P "^[^\t]*\t$AGENT\t$N\t" "$LEDGER" 2>/dev/null && exit 0 | 79 | awk -F'\t' -v a="$AGENT" -v n="$N" 'NR>1 && $2==a && $3==n {found=1; exit} END{exit !found}' "$LEDGER" 2>/dev/null && exit 0 |
| 71 | [ -s "$LEDGER" ] || printf 'end\tagent\tn\tresult\tran_s\tpresentx_ok\tpso_failed\tfspx_miss\tnonblack_frames\tpeak_mb\tgta6rt\n' >&7 | 80 | [ -s "$LEDGER" ] || printf 'end\tagent\tn\tresult\tran_s\tpresentx_ok\tpso_failed\tfspx_miss\tnonblack_frames\tpeak_mb\tgta6rt\n' >&7 |
| 72 | printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$(date '+%F %T')" "$AGENT" "$N" "$RESULT" "$((END-BOOT))" \ | 81 | printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$(date '+%F %T')" "$AGENT" "$N" "$RESULT" "$((END-BOOT))" \ |
| 73 | "$(cnt 'XboxPresentation::PresentX ok')" "$(cnt 'CreatePipelineState failed')" "$(cnt 'no translated compute shader for FSPX')" \ | 82 | "$(cnt 'XboxPresentation::PresentX ok')" "$(cnt 'CreatePipelineState failed')" "$(cnt 'no translated compute shader for FSPX')" \ |
| 74 | "$frames" "$peak" "$(sed -n 's/^unit=.*gta6rt=\([^ ]*\).*/\1/p' "$META")" >&7 | 83 | "$frames" "$peak" "$(sed -n 's/^unit=.*gta6rt=\([^ ]*\).*/\1/p' "$META" 2>/dev/null)" >&7 |
| 75 | exit 0 | 84 | exit 0 |
diff --git a/scripts/linux-boot/boot-inner.sh b/scripts/linux-boot/boot-inner.sh index e52d3daef..aa5f1147f 100755 --- a/scripts/linux-boot/boot-inner.sh +++ b/scripts/linux-boot/boot-inner.sh | |||
| @@ -1,44 +1,125 @@ | |||
| 1 | #!/bin/bash | 1 | #!/bin/bash |
| 2 | # Runs inside the leonida-boot-* unit (see run-boot.sh). Waits for memory, takes the locks, samples resources, boots. | 2 | # Runs inside the leonida-boot-* unit (see run-boot.sh). Waits for memory, takes the locks, samples resources, boots. |
| 3 | set -u | 3 | set -u |
| 4 | WORK=/opt/leonida/work/$BOOT_AGENT; N=$BOOT_N; LOG=$WORK/boot-$N.log; RES=$WORK/boot-$N.resources.tsv | 4 | |
| 5 | die() { | ||
| 6 | echo "ERROR: $*" >&2 | ||
| 7 | exit 2 | ||
| 8 | } | ||
| 9 | |||
| 10 | OUT=${LEONIDA_BOOT_ROOT:-${LEONIDA_OUT:-/opt/leonida}} | ||
| 11 | BOOT_AGENT=${BOOT_AGENT:-} | ||
| 12 | BOOT_N=${BOOT_N:-} | ||
| 13 | BOOT_SECS=${BOOT_SECS:-} | ||
| 14 | GTA6RT=${GTA6RT:-} | ||
| 15 | BOOT_SH=${BOOT_SH:-$OUT/boot.sh} | ||
| 16 | NVIDIA_SMI=${NVIDIA_SMI:-nvidia-smi} | ||
| 17 | PROC_MEMINFO=${LEONIDA_MEMINFO_PATH:-/proc/meminfo} | ||
| 18 | CGROUP_SELF=${LEONIDA_SELF_CGROUP_PATH:-/proc/self/cgroup} | ||
| 19 | CGROUP_ROOT=${LEONIDA_CGROUP_ROOT:-/sys/fs/cgroup} | ||
| 20 | WAIT_SLEEP=${LEONIDA_WAIT_SLEEP_SECS:-15} | ||
| 21 | SAMPLE_SLEEP=${LEONIDA_SAMPLE_SLEEP_SECS:-2} | ||
| 22 | WAIT_ITERS=${LEONIDA_WAIT_ITERS:-40} | ||
| 23 | |||
| 24 | [ -n "$BOOT_AGENT" ] || die "BOOT_AGENT must be set" | ||
| 25 | [ -n "$BOOT_N" ] || die "BOOT_N must be set" | ||
| 26 | [ -n "$BOOT_SECS" ] || die "BOOT_SECS must be set" | ||
| 27 | [ -n "$GTA6RT" ] || die "GTA6RT must be set" | ||
| 28 | case "$BOOT_AGENT" in | ||
| 29 | .|..|*/*|*\\*|*..*) die "BOOT_AGENT must be a single path segment: $BOOT_AGENT" ;; | ||
| 30 | esac | ||
| 31 | case "$BOOT_N" in | ||
| 32 | .|..|*/*|*\\*|*..*) die "BOOT_N must be a single path segment: $BOOT_N" ;; | ||
| 33 | esac | ||
| 34 | [[ "$BOOT_SECS" =~ ^[0-9]+$ ]] || die "BOOT_SECS must be a non-negative integer: $BOOT_SECS" | ||
| 35 | [[ "$WAIT_ITERS" =~ ^[0-9]+$ ]] || die "WAIT_ITERS must be a non-negative integer: $WAIT_ITERS" | ||
| 36 | |||
| 37 | NEED=${LEONIDA_BOOT_MIN_FREE_MB:-6500} | ||
| 38 | [[ "$NEED" =~ ^[0-9]+$ ]] || die "LEONIDA_BOOT_MIN_FREE_MB must be a non-negative integer: $NEED" | ||
| 39 | |||
| 40 | WORK=${LEONIDA_BOOT_WORK:-$OUT/work/$BOOT_AGENT}; N=$BOOT_N; LOG=$WORK/boot-$N.log; RES=$WORK/boot-$N.resources.tsv | ||
| 5 | META=$WORK/boot-$N.meta | 41 | META=$WORK/boot-$N.meta |
| 42 | mkdir -p "$OUT" "$WORK" || die "cannot create work directory: $WORK" | ||
| 6 | : > "$LOG" | 43 | : > "$LOG" |
| 7 | echo "start_epoch=$(date +%s)" > "$META" | 44 | echo "start_epoch=$(date +%s)" > "$META" |
| 8 | echo "unit=leonida-boot-$BOOT_AGENT-$N gta6rt=$GTA6RT secs=$BOOT_SECS" >> "$META" | 45 | echo "unit=leonida-boot-$BOOT_AGENT-$N gta6rt=$GTA6RT secs=$BOOT_SECS" >> "$META" |
| 9 | env | grep -E '^(LEONIDA_|WINEDEBUG=)' | sort >> "$META" | 46 | env | grep -E '^(LEONIDA_|WINEDEBUG=)' | sort >> "$META" || true |
| 10 | 47 | ||
| 11 | mem_free_mb() { # RAM available plus a third of free zram swap (zram pages cost RAM, roughly 3:1) | 48 | mem_free_mb() { # RAM available plus a third of free zram swap (zram pages cost RAM, roughly 3:1) |
| 12 | awk '/^MemAvailable:/{a=$2} /^SwapFree:/{s=$2} END{printf "%d", (a + s/3)/1024}' /proc/meminfo | 49 | [ -r "$PROC_MEMINFO" ] || { echo 0; return; } |
| 50 | awk 'BEGIN{a=0; s=0} /^MemAvailable:/{a=$2} /^SwapFree:/{s=$2} END{printf "%d", (a + s/3)/1024}' "$PROC_MEMINFO" | ||
| 13 | } | 51 | } |
| 14 | NEED=${LEONIDA_BOOT_MIN_FREE_MB:-6500} | 52 | swap_pct() { |
| 15 | swap_pct() { awk '/^SwapTotal:/{t=$2} /^SwapFree:/{f=$2} END{printf "%d", t ? (t-f)*100/t : 0}' /proc/meminfo; } | 53 | [ -r "$PROC_MEMINFO" ] || { echo 0; return; } |
| 54 | awk 'BEGIN{t=0; f=0} /^SwapTotal:/{t=$2} /^SwapFree:/{f=$2} END{pct=(t>0 ? (t-f)*100/t : 0); printf "%d", pct}' "$PROC_MEMINFO" | ||
| 55 | } | ||
| 56 | read_uint() { | ||
| 57 | local v="" | ||
| 58 | if [ -r "$1" ]; then | ||
| 59 | v=$(cat "$1" 2>/dev/null || true) | ||
| 60 | v=${v//$'\r'/} | ||
| 61 | fi | ||
| 62 | [[ "$v" =~ ^[0-9]+$ ]] || v=0 | ||
| 63 | printf '%s' "$v" | ||
| 64 | } | ||
| 65 | |||
| 66 | SAMPLER="" | ||
| 67 | cleanup() { | ||
| 68 | if [ -n "${SAMPLER:-}" ]; then | ||
| 69 | kill "$SAMPLER" 2>/dev/null || true | ||
| 70 | wait "$SAMPLER" 2>/dev/null || true | ||
| 71 | SAMPLER="" | ||
| 72 | fi | ||
| 73 | } | ||
| 74 | trap cleanup EXIT INT TERM | ||
| 16 | 75 | ||
| 17 | exec 8>/opt/leonida/.gpu.lock; flock 8 # one boot at a time | 76 | exec 8>"$OUT/.gpu.lock" |
| 77 | if command -v flock >/dev/null 2>&1; then flock 8; fi # one boot at a time | ||
| 18 | echo "[run-boot] $(date +%T) got the GPU lock" >> "$LOG" | 78 | echo "[run-boot] $(date +%T) got the GPU lock" >> "$LOG" |
| 19 | for i in $(seq 1 40); do # up to 10 min for memory headroom | 79 | for ((i = 1; i <= WAIT_ITERS; i++)); do # up to 10 min for memory headroom |
| 20 | f=$(mem_free_mb); sp=$(swap_pct); [ "$f" -ge "$NEED" ] && [ "$sp" -lt 70 ] && break | 80 | f=$(mem_free_mb); sp=$(swap_pct); [ "$f" -ge "$NEED" ] && [ "$sp" -lt 70 ] && break |
| 21 | echo "[run-boot] $(date +%T) waiting for memory: ${f} MB free (need ${NEED}), swap ${sp}% (need < 70%)" >> "$LOG"; sleep 15 | 81 | echo "[run-boot] $(date +%T) waiting for memory: ${f} MB free (need ${NEED}), swap ${sp}% (need < 70%)" >> "$LOG"; sleep "$WAIT_SLEEP" |
| 22 | done | 82 | done |
| 23 | echo "[run-boot] $(date +%T) memory before boot: $(mem_free_mb) MB free, swap $(swap_pct)%" >> "$LOG" | 83 | echo "[run-boot] $(date +%T) memory before boot: $(mem_free_mb) MB free, swap $(swap_pct)%" >> "$LOG" |
| 24 | exec 9>/opt/leonida/.build.lock; flock 9 # no compiles while the game runs | 84 | exec 9>"$OUT/.build.lock" |
| 85 | if command -v flock >/dev/null 2>&1; then flock 9; fi # no compiles while the game runs | ||
| 25 | echo "[run-boot] $(date +%T) got the build lock; booting" >> "$LOG" | 86 | echo "[run-boot] $(date +%T) got the build lock; booting" >> "$LOG" |
| 26 | echo "boot_epoch=$(date +%s)" >> "$META" | 87 | echo "boot_epoch=$(date +%s)" >> "$META" |
| 27 | 88 | ||
| 28 | CG=/sys/fs/cgroup$(cut -d: -f3 /proc/self/cgroup) | 89 | cg_rel="" |
| 29 | ( printf 'time\tmem_avail_mb\tswap_used_mb\tunit_mem_mb\tunit_swap_mb\tgpu_mem_mb\tgpu_util\n' | 90 | if [ -r "$CGROUP_SELF" ]; then |
| 91 | cg_rel=$(awk -F: '$1=="0"{print $3; exit}' "$CGROUP_SELF" 2>/dev/null || true) | ||
| 92 | [ -n "$cg_rel" ] || cg_rel=$(awk -F: 'NF>=3{p=$3} END{print p}' "$CGROUP_SELF" 2>/dev/null || true) | ||
| 93 | cg_rel=${cg_rel//$'\r'/} | ||
| 94 | fi | ||
| 95 | CG=$CGROUP_ROOT$cg_rel | ||
| 96 | ( trap 'kill "${sleep_pid:-}" 2>/dev/null || true; exit 0' TERM INT | ||
| 97 | sleep_pid="" | ||
| 98 | printf 'time\tmem_avail_mb\tswap_used_mb\tunit_mem_mb\tunit_swap_mb\tgpu_mem_mb\tgpu_util\n' | ||
| 30 | while :; do | 99 | while :; do |
| 31 | read -r ma su < <(awk '/^MemAvailable:/{a=$2} /^SwapTotal:/{t=$2} /^SwapFree:/{f=$2} END{print int(a/1024), int((t-f)/1024)}' /proc/meminfo) | 100 | ma=0; su=0 |
| 32 | um=$(( $(cat "$CG/memory.current" 2>/dev/null || echo 0) / 1048576 )); us=$(( $(cat "$CG/memory.swap.current" 2>/dev/null || echo 0) / 1048576 )) | 101 | if [ -r "$PROC_MEMINFO" ]; then |
| 33 | g=$(nvidia-smi --query-gpu=memory.used,utilization.gpu --format=csv,noheader,nounits 2>/dev/null | tr -d ' ' | tr ',' '\t') | 102 | read -r ma su < <(awk 'BEGIN{a=0; t=0; f=0} /^MemAvailable:/{a=$2} /^SwapTotal:/{t=$2} /^SwapFree:/{f=$2} END{u=(t>f ? t-f : 0); print int(a/1024), int(u/1024)}' "$PROC_MEMINFO") |
| 103 | fi | ||
| 104 | um=$(( $(read_uint "$CG/memory.current") / 1048576 )) | ||
| 105 | us=$(( $(read_uint "$CG/memory.swap.current") / 1048576 )) | ||
| 106 | g=$("$NVIDIA_SMI" --query-gpu=memory.used,utilization.gpu --format=csv,noheader,nounits 2>/dev/null | head -n 1 | tr -d ' \r' | tr ',' '\t') | ||
| 34 | printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$(date +%T)" "$ma" "$su" "$um" "$us" "${g:-? ?}" | 107 | printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$(date +%T)" "$ma" "$su" "$um" "$us" "${g:-? ?}" |
| 35 | sleep 2 | 108 | sleep "$SAMPLE_SLEEP" & |
| 109 | sleep_pid=$! | ||
| 110 | wait "$sleep_pid" 2>/dev/null || break | ||
| 111 | sleep_pid="" | ||
| 36 | done ) > "$RES" 2>/dev/null & | 112 | done ) > "$RES" 2>/dev/null & |
| 37 | SAMPLER=$! | 113 | SAMPLER=$! |
| 38 | 114 | ||
| 39 | /opt/leonida/boot.sh run "$BOOT_SECS" >> "$LOG" 2>&1 | 115 | if [ -f "$BOOT_SH" ]; then |
| 40 | rc=$? | 116 | "$BOOT_SH" run "$BOOT_SECS" >> "$LOG" 2>&1 |
| 41 | kill $SAMPLER 2>/dev/null | 117 | rc=$? |
| 118 | else | ||
| 119 | echo "[run-boot] missing boot script: $BOOT_SH" >> "$LOG" | ||
| 120 | rc=127 | ||
| 121 | fi | ||
| 122 | cleanup | ||
| 42 | echo "[run-boot] $(date +%T) boot.sh exit $rc" >> "$LOG" | 123 | echo "[run-boot] $(date +%T) boot.sh exit $rc" >> "$LOG" |
| 43 | # boot.sh stops the title with timeout(1) at the time limit: 124 means it ran the whole time, which is success here. | 124 | # boot.sh stops the title with timeout(1) at the time limit: 124 means it ran the whole time, which is success here. |
| 44 | [ "$rc" = 124 ] && { echo "[run-boot] time limit reached" >> "$LOG"; rc=0; } | 125 | [ "$rc" = 124 ] && { echo "[run-boot] time limit reached" >> "$LOG"; rc=0; } |
diff --git a/scripts/linux-boot/boot.sh b/scripts/linux-boot/boot.sh index 55f84f019..6a2268f27 100755 --- a/scripts/linux-boot/boot.sh +++ b/scripts/linux-boot/boot.sh | |||
| @@ -3,13 +3,65 @@ | |||
| 3 | # usage: boot.sh dry-run|init|run [seconds] (run defaults to 150 s, then the title is stopped) | 3 | # usage: boot.sh dry-run|init|run [seconds] (run defaults to 150 s, then the title is stopped) |
| 4 | # Traces stay local in /opt/leonida/traces: they can quote game data, never post them. | 4 | # Traces stay local in /opt/leonida/traces: they can quote game data, never post them. |
| 5 | set -u | 5 | set -u |
| 6 | MODE=${1:?dry-run|init|run}; SECS=${2:-150} | 6 | usage() { |
| 7 | OUT=/opt/leonida | 7 | echo "usage: boot.sh dry-run|init|run [seconds]" |
| 8 | } | ||
| 9 | |||
| 10 | if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then | ||
| 11 | usage | ||
| 12 | exit 0 | ||
| 13 | fi | ||
| 14 | if [ $# -lt 1 ] || [ $# -gt 2 ]; then | ||
| 15 | usage >&2 | ||
| 16 | exit 2 | ||
| 17 | fi | ||
| 18 | |||
| 19 | MODE=$1 | ||
| 20 | SECS=${2:-150} | ||
| 21 | case "$MODE" in | ||
| 22 | dry-run|init|run) ;; | ||
| 23 | *) | ||
| 24 | echo "boot.sh: invalid mode: $MODE (expected dry-run, init, or run)" >&2 | ||
| 25 | exit 2 | ||
| 26 | ;; | ||
| 27 | esac | ||
| 28 | if ! [[ "$SECS" =~ ^[1-9][0-9]*$ ]]; then | ||
| 29 | echo "boot.sh: invalid seconds: $SECS (expected positive integer)" >&2 | ||
| 30 | exit 2 | ||
| 31 | fi | ||
| 32 | |||
| 33 | OUT=${LEONIDA_OUT:-/opt/leonida} | ||
| 8 | REPO=${LEONIDA_REPO:-$(cd "$(dirname "$(readlink -f "$0")")/../.." && pwd)} # the checkout this script is in | 34 | REPO=${LEONIDA_REPO:-$(cd "$(dirname "$(readlink -f "$0")")/../.." && pwd)} # the checkout this script is in |
| 35 | WINE=${WINE:-wine} # e.g. WINE=".../Proton - Experimental/files/bin/wine" WINEPREFIX=~/.local/share/leonida-proton/pfx | ||
| 36 | PYTHON3=${PYTHON3:-python3} | ||
| 37 | UNSHARE=${UNSHARE:-unshare} | ||
| 38 | TIMEOUT=${TIMEOUT:-timeout} | ||
| 39 | GAME_DIR=${LEONIDA_GAME_DIR:-/opt/gta6/GTA6.Xbox.v1.0.2.1} | ||
| 40 | GAME_WIN=${LEONIDA_GAME_WIN:-'Z:\opt\gta6\GTA6.Xbox.v1.0.2.1'} | ||
| 41 | EXE=${LEONIDA_EXE:-$GAME_DIR/game_scarlett_master.exe} | ||
| 42 | OVERLAY_WIN=${LEONIDA_OVERLAY_WIN:-'Z:\opt\leonida\overlay'} | ||
| 43 | GTA6RT=${GTA6RT:-$OUT/gta6rt.exe}; [ -f "$GTA6RT" ] || GTA6RT=$REPO/runtime/build/boot/gta6rt.exe # GTA6RT=<your build>/gta6rt.exe boots a private build without installing it | ||
| 44 | |||
| 45 | if [ ! -f "$GTA6RT" ]; then | ||
| 46 | echo "boot.sh: missing gta6rt executable: $GTA6RT" >&2 | ||
| 47 | exit 2 | ||
| 48 | fi | ||
| 49 | if ! command -v "$UNSHARE" >/dev/null 2>&1; then | ||
| 50 | echo "boot.sh: missing required command: $UNSHARE" >&2 | ||
| 51 | exit 2 | ||
| 52 | fi | ||
| 53 | if [ "$MODE" = run ] && ! command -v "$TIMEOUT" >/dev/null 2>&1; then | ||
| 54 | echo "boot.sh: missing required command: $TIMEOUT" >&2 | ||
| 55 | exit 2 | ||
| 56 | fi | ||
| 57 | if ! command -v "$WINE" >/dev/null 2>&1; then | ||
| 58 | echo "boot.sh: missing required Wine binary: $WINE" >&2 | ||
| 59 | exit 2 | ||
| 60 | fi | ||
| 61 | |||
| 9 | STAMP=$(date +%H%M%S) | 62 | STAMP=$(date +%H%M%S) |
| 10 | T=$OUT/traces; mkdir -p "$T" "$OUT/overlay" "$OUT/cache/nv" | 63 | T=$OUT/traces; mkdir -p "$T" "$OUT/overlay" "$OUT/cache/nv" |
| 11 | 64 | ||
| 12 | WINE=${WINE:-wine} # e.g. WINE=".../Proton - Experimental/files/bin/wine" WINEPREFIX=~/.local/share/leonida-proton/pfx | ||
| 13 | export WINEPREFIX=${WINEPREFIX:-$HOME/.local/share/leonida-wine} WINEDEBUG=${WINEDEBUG:--all} WINEDLLOVERRIDES="mscoree,mshtml=" | 65 | export WINEPREFIX=${WINEPREFIX:-$HOME/.local/share/leonida-wine} WINEDEBUG=${WINEDEBUG:--all} WINEDLLOVERRIDES="mscoree,mshtml=" |
| 14 | export LEONIDA_D3D12=vulkan | 66 | export LEONIDA_D3D12=vulkan |
| 15 | export LEONIDA_SHADERS=$OUT/work/shaders/spirv | 67 | export LEONIDA_SHADERS=$OUT/work/shaders/spirv |
| @@ -20,23 +72,22 @@ export __GL_SHADER_DISK_CACHE=1 __GL_SHADER_DISK_CACHE_PATH=$OUT/cache/nv __GL_S | |||
| 20 | export __GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1 | 72 | export __GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1 |
| 21 | [ -n "${SKIP_INT3:-}" ] && export LEONIDA_SKIP_INT3=1 | 73 | [ -n "${SKIP_INT3:-}" ] && export LEONIDA_SKIP_INT3=1 |
| 22 | 74 | ||
| 23 | GAME_WIN='Z:\opt\gta6\GTA6.Xbox.v1.0.2.1' | 75 | TRACE_WIN=${LEONIDA_TRACE_WIN:-"Z:\\opt\\leonida\\traces\\boot-$MODE-$STAMP.jsonl"} |
| 24 | EXE=/opt/gta6/GTA6.Xbox.v1.0.2.1/game_scarlett_master.exe | ||
| 25 | TRACE_WIN="Z:\\opt\\leonida\\traces\\boot-$MODE-$STAMP.jsonl" | ||
| 26 | D3D=$T/d3d12-$MODE-$STAMP.log | 76 | D3D=$T/d3d12-$MODE-$STAMP.log |
| 27 | GTA6RT=${GTA6RT:-$OUT/gta6rt.exe}; [ -f "$GTA6RT" ] || GTA6RT=$REPO/runtime/build/boot/gta6rt.exe # GTA6RT=<your build>/gta6rt.exe boots a private build without installing it | ||
| 28 | 77 | ||
| 29 | args=(--"$MODE" "$EXE" --game-dir "$GAME_WIN" --overlay 'Z:\opt\leonida\overlay' --trace "$TRACE_WIN") | 78 | args=(--"$MODE" "$EXE" --game-dir "$GAME_WIN" --overlay "$OVERLAY_WIN" --trace "$TRACE_WIN") |
| 30 | [ "$MODE" = run ] && args+=(--trace-d3d12) | 79 | [ "$MODE" = run ] && args+=(--trace-d3d12) |
| 31 | echo "[boot] $MODE gta6rt=$GTA6RT trace=$T/boot-$MODE-$STAMP.jsonl d3d12=$D3D" | 80 | echo "[boot] $MODE gta6rt=$GTA6RT trace=$T/boot-$MODE-$STAMP.jsonl d3d12=$D3D" |
| 32 | # unshare: new user + network namespace, so the title has no network at all | 81 | # unshare: new user + network namespace, so the title has no network at all |
| 33 | if [ "$MODE" = run ]; then | 82 | if [ "$MODE" = run ]; then |
| 34 | timeout --signal=INT --kill-after=20 "$SECS" unshare -rn "$WINE" "$GTA6RT" "${args[@]}" > "$T/stdout-$MODE-$STAMP.log" 2> "$D3D" | 83 | "$TIMEOUT" --signal=INT --kill-after=20 "$SECS" "$UNSHARE" -rn "$WINE" "$GTA6RT" "${args[@]}" > "$T/stdout-$MODE-$STAMP.log" 2> "$D3D" |
| 35 | else | 84 | else |
| 36 | unshare -rn "$WINE" "$GTA6RT" "${args[@]}" > "$T/stdout-$MODE-$STAMP.log" 2> "$D3D" | 85 | "$UNSHARE" -rn "$WINE" "$GTA6RT" "${args[@]}" > "$T/stdout-$MODE-$STAMP.log" 2> "$D3D" |
| 37 | fi | 86 | fi |
| 38 | rc=$?; echo "[boot] exit=$rc" | 87 | rc=$?; echo "[boot] exit=$rc" |
| 39 | sleep 0 | 88 | sleep 0 |
| 40 | python3 -I "$REPO/tools/boot_trace.py" "$T/boot-$MODE-$STAMP.jsonl" --d3d12 "$D3D" > "$T/summary-$MODE-$STAMP.txt" 2>&1 | 89 | if [ -f "$REPO/tools/boot_trace.py" ]; then |
| 41 | echo "[boot] summary: $T/summary-$MODE-$STAMP.txt" | 90 | "$PYTHON3" -I "$REPO/tools/boot_trace.py" "$T/boot-$MODE-$STAMP.jsonl" --d3d12 "$D3D" > "$T/summary-$MODE-$STAMP.txt" 2>&1 || true |
| 42 | exit $rc | 91 | echo "[boot] summary: $T/summary-$MODE-$STAMP.txt" |
| 92 | fi | ||
| 93 | exit "$rc" | ||
diff --git a/scripts/linux-boot/configure-worktree.sh b/scripts/linux-boot/configure-worktree.sh index c983b3357..ef94973a9 100755 --- a/scripts/linux-boot/configure-worktree.sh +++ b/scripts/linux-boot/configure-worktree.sh | |||
| @@ -2,8 +2,49 @@ | |||
| 2 | # usage: configure-worktree.sh <worktree> | 2 | # usage: configure-worktree.sh <worktree> |
| 3 | # Configures a Windows build of the runtime on Linux with clang-cl and an xwin SDK (XWIN_DIR, default | 3 | # Configures a Windows build of the runtime on Linux with clang-cl and an xwin SDK (XWIN_DIR, default |
| 4 | # ~/.local/share/xwin-sdk). SDL3_SRC=<an SDL3 source tree> makes the configure work offline. | 4 | # ~/.local/share/xwin-sdk). SDL3_SRC=<an SDL3 source tree> makes the configure work offline. |
| 5 | set -eu; W=$(realpath "$1") | 5 | set -eu |
| 6 | cmake -S "$W/runtime" -B "$W/runtime/build/boot" -G Ninja -DCMAKE_BUILD_TYPE=Release \ | 6 | |
| 7 | -DCMAKE_TOOLCHAIN_FILE="$W/runtime/cmake/clang-cl-xwin.cmake" -DXWIN_DIR="${XWIN_DIR:-$HOME/.local/share/xwin-sdk}" \ | 7 | usage() { |
| 8 | -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DLEONIDA_SDL3=ON \ | 8 | echo "usage: configure-worktree.sh <worktree>" |
| 9 | ${SDL3_SRC:+-DFETCHCONTENT_SOURCE_DIR_SDL3="$SDL3_SRC"} | 9 | } |
| 10 | |||
| 11 | die() { | ||
| 12 | echo "ERROR: $*" >&2 | ||
| 13 | exit 2 | ||
| 14 | } | ||
| 15 | |||
| 16 | if [ "$#" -ge 1 ] && { [ "$1" = "-h" ] || [ "$1" = "--help" ]; }; then | ||
| 17 | usage | ||
| 18 | exit 0 | ||
| 19 | fi | ||
| 20 | |||
| 21 | [ "$#" -eq 1 ] || { usage >&2; exit 2; } | ||
| 22 | [ -n "$1" ] || die "worktree path must not be empty" | ||
| 23 | [ -d "$1" ] || die "worktree directory does not exist: $1" | ||
| 24 | |||
| 25 | W=$(realpath "$1") | ||
| 26 | [ -f "$W/runtime/CMakeLists.txt" ] || die "not a runtime worktree (missing runtime/CMakeLists.txt): $W" | ||
| 27 | [ -f "$W/runtime/cmake/clang-cl-xwin.cmake" ] || die "missing toolchain file: $W/runtime/cmake/clang-cl-xwin.cmake" | ||
| 28 | |||
| 29 | CMAKE=${CMAKE:-cmake} | ||
| 30 | command -v "$CMAKE" >/dev/null 2>&1 || die "cmake executable not found: $CMAKE" | ||
| 31 | |||
| 32 | if [ -n "${SDL3_SRC:-}" ] && [ ! -d "$SDL3_SRC" ]; then | ||
| 33 | die "SDL3_SRC directory does not exist: $SDL3_SRC" | ||
| 34 | fi | ||
| 35 | |||
| 36 | cmake_args=( | ||
| 37 | -S "$W/runtime" | ||
| 38 | -B "$W/runtime/build/boot" | ||
| 39 | -G Ninja | ||
| 40 | -DCMAKE_BUILD_TYPE=Release | ||
| 41 | -DCMAKE_TOOLCHAIN_FILE="$W/runtime/cmake/clang-cl-xwin.cmake" | ||
| 42 | -DXWIN_DIR="${XWIN_DIR:-$HOME/.local/share/xwin-sdk}" | ||
| 43 | -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON | ||
| 44 | -DLEONIDA_SDL3=ON | ||
| 45 | ) | ||
| 46 | if [ -n "${SDL3_SRC:-}" ]; then | ||
| 47 | cmake_args+=(-DFETCHCONTENT_SOURCE_DIR_SDL3="$SDL3_SRC") | ||
| 48 | fi | ||
| 49 | |||
| 50 | "$CMAKE" "${cmake_args[@]}" | ||
diff --git a/scripts/linux-boot/run-boot.sh b/scripts/linux-boot/run-boot.sh index 523d17795..b23036ccb 100755 --- a/scripts/linux-boot/run-boot.sh +++ b/scripts/linux-boot/run-boot.sh | |||
| @@ -16,10 +16,26 @@ | |||
| 16 | # Outputs (in /opt/leonida/work/<agent>/): boot-<n>.log boot-<n>.resources.tsv boot-<n>.digest.txt | 16 | # Outputs (in /opt/leonida/work/<agent>/): boot-<n>.log boot-<n>.resources.tsv boot-<n>.digest.txt |
| 17 | set -u | 17 | set -u |
| 18 | AGENT=${1:?agent}; N=${2:?n}; EXE=${3:?gta6rt.exe}; SECS=${4:-150}; shift $(( $# >= 4 ? 4 : $# )) | 18 | AGENT=${1:?agent}; N=${2:?n}; EXE=${3:?gta6rt.exe}; SECS=${4:-150}; shift $(( $# >= 4 ? 4 : $# )) |
| 19 | if [ "$AGENT" = "." ] || [ "$AGENT" = ".." ] || ! [[ "$AGENT" =~ ^[A-Za-z0-9._-]+$ ]]; then | ||
| 20 | echo "run-boot: invalid agent: $AGENT" >&2; exit 2 | ||
| 21 | fi | ||
| 22 | if ! [[ "$N" =~ ^[0-9]+$ ]]; then | ||
| 23 | echo "run-boot: invalid boot number: $N" >&2; exit 2 | ||
| 24 | fi | ||
| 25 | if ! [[ "$SECS" =~ ^[1-9][0-9]*$ ]]; then | ||
| 26 | echo "run-boot: invalid seconds (expected positive integer): $SECS" >&2; exit 2 | ||
| 27 | fi | ||
| 28 | for kv in "$@"; do | ||
| 29 | if ! [[ "$kv" =~ ^[A-Za-z_][A-Za-z0-9_]*= ]]; then | ||
| 30 | echo "run-boot: invalid environment override (expected KEY=VALUE): $kv" >&2; exit 2 | ||
| 31 | fi | ||
| 32 | done | ||
| 19 | [ -f "$EXE" ] || { echo "run-boot: no such gta6rt: $EXE" >&2; exit 2; } | 33 | [ -f "$EXE" ] || { echo "run-boot: no such gta6rt: $EXE" >&2; exit 2; } |
| 20 | # gta6rt loads gta6rt_tls_host.dll from its own folder; without it the title gets no module TLS index and exits at once. | 34 | # gta6rt loads gta6rt_tls_host.dll from its own folder; without it the title gets no module TLS index and exits at once. |
| 21 | [ -f "$(dirname "$EXE")/gta6rt_tls_host.dll" ] || { echo "run-boot: $(dirname "$EXE")/gta6rt_tls_host.dll is missing: copy it next to the exe (build it with the gta6rt target) or boot the exe from its build folder" >&2; exit 2; } | 35 | [ -f "$(dirname "$EXE")/gta6rt_tls_host.dll" ] || { echo "run-boot: $(dirname "$EXE")/gta6rt_tls_host.dll is missing: copy it next to the exe (build it with the gta6rt target) or boot the exe from its build folder" >&2; exit 2; } |
| 22 | WORK=/opt/leonida/work/$AGENT; mkdir -p "$WORK" | 36 | ROOT=${LEONIDA_BOOT_ROOT:-/opt/leonida} |
| 37 | WIN_ROOT=${ROOT#/}; WIN_ROOT="Z:\\${WIN_ROOT//\//\\}" | ||
| 38 | WORK=$ROOT/work/$AGENT; mkdir -p "$WORK" | ||
| 23 | UNIT=leonida-boot-$AGENT-$N | 39 | UNIT=leonida-boot-$AGENT-$N |
| 24 | if systemctl --user is-active --quiet "$UNIT"; then echo "run-boot: $UNIT is already running" >&2; exit 2; fi | 40 | if systemctl --user is-active --quiet "$UNIT"; then echo "run-boot: $UNIT is already running" >&2; exit 2; fi |
| 25 | 41 | ||
| @@ -28,10 +44,10 @@ declare -A ENV=( | |||
| 28 | [WINEPREFIX]="$HOME/.local/share/leonida-proton/pfx" | 44 | [WINEPREFIX]="$HOME/.local/share/leonida-proton/pfx" |
| 29 | [WINEDEBUG]="-all,err+all" | 45 | [WINEDEBUG]="-all,err+all" |
| 30 | [GTA6RT]="$EXE" | 46 | [GTA6RT]="$EXE" |
| 31 | [LEONIDA_CAPTURE]="Z:\\opt\\leonida\\capture\\$AGENT-$N" | 47 | [LEONIDA_CAPTURE]="$WIN_ROOT\\capture\\$AGENT-$N" |
| 32 | [LEONIDA_CAPTURE_EVERY]=4800 [LEONIDA_CAPTURE_LIMIT]=24 [LEONIDA_CAPTURE_SOURCE]=1 | 48 | [LEONIDA_CAPTURE_EVERY]=4800 [LEONIDA_CAPTURE_LIMIT]=24 [LEONIDA_CAPTURE_SOURCE]=1 |
| 33 | [LEONIDA_DEVICE_TYPE]=6 | 49 | [LEONIDA_DEVICE_TYPE]=6 |
| 34 | [LEONIDA_PIPELINE_CACHE_DIR]="Z:\\opt\\leonida\\cache\\pipelines" | 50 | [LEONIDA_PIPELINE_CACHE_DIR]="$WIN_ROOT\\cache\\pipelines" |
| 35 | ) | 51 | ) |
| 36 | for kv in "$@"; do ENV[${kv%%=*}]="${kv#*=}"; done | 52 | for kv in "$@"; do ENV[${kv%%=*}]="${kv#*=}"; done |
| 37 | args=() | 53 | args=() |
| @@ -39,16 +55,16 @@ for k in "${!ENV[@]}"; do args+=(--setenv="$k=${ENV[$k]}"); done | |||
| 39 | 55 | ||
| 40 | echo "run-boot: $UNIT starting (queues for memory headroom, the GPU lock and the build lock)" | 56 | echo "run-boot: $UNIT starting (queues for memory headroom, the GPU lock and the build lock)" |
| 41 | rm -f "$WORK/boot-$N.digest.txt" | 57 | rm -f "$WORK/boot-$N.digest.txt" |
| 42 | systemd-run --user --collect --quiet --unit="$UNIT" -p WorkingDirectory=/opt/leonida \ | 58 | systemd-run --user --collect --quiet --unit="$UNIT" -p WorkingDirectory="$ROOT" \ |
| 43 | --setenv=BOOT_AGENT="$AGENT" --setenv=BOOT_N="$N" --setenv=BOOT_SECS="$SECS" "${args[@]}" \ | 59 | --setenv=BOOT_AGENT="$AGENT" --setenv=BOOT_N="$N" --setenv=BOOT_SECS="$SECS" "${args[@]}" \ |
| 44 | /opt/leonida/boot-inner.sh || { echo "run-boot: could not start $UNIT" >&2; exit 2; } | 60 | "$ROOT/boot-inner.sh" || { echo "run-boot: could not start $UNIT" >&2; exit 2; } |
| 45 | # The digest is written by a separate, tiny watcher unit: it survives systemd-oomd killing the boot's cgroup and the | 61 | # The digest is written by a separate, tiny watcher unit: it survives systemd-oomd killing the boot's cgroup and the |
| 46 | # caller's shell going away. It waits for the boot unit to end, reads its result from the journal and writes the digest. | 62 | # caller's shell going away. It waits for the boot unit to end, reads its result from the journal and writes the digest. |
| 47 | systemd-run --user --collect --quiet --unit="leonida-digest-$AGENT-$N" -p MemoryMax=256M \ | 63 | systemd-run --user --collect --quiet --unit="leonida-digest-$AGENT-$N" -p MemoryMax=256M \ |
| 48 | /bin/bash -c 'while systemctl --user is-active --quiet "$0" || systemctl --user is-activating --quiet "$0"; do sleep 3; done | 64 | /bin/bash -c 'while systemctl --user is-active --quiet "$0" || systemctl --user is-activating --quiet "$0"; do sleep 3; done |
| 49 | START=$(sed -n "s/^start_epoch=//p" "/opt/leonida/work/$1/boot-$2.meta" 2>/dev/null) | 65 | START=$(sed -n "s/^start_epoch=//p" "$3/work/$1/boot-$2.meta" 2>/dev/null) |
| 50 | RES=$(journalctl --user -u "$0" ${START:+--since "@$START"} -q --no-pager 2>/dev/null | grep -o "Failed with result .[a-z-]*." | tail -1 | tr -d "\x27" | sed "s/Failed with result //") | 66 | RES=$(journalctl --user -u "$0" ${START:+--since "@$START"} -q --no-pager 2>/dev/null | grep -o "Failed with result .[a-z-]*." | tail -1 | tr -d "\x27" | sed "s/Failed with result //") |
| 51 | SERVICE_RESULT=${RES:-success} exec /opt/leonida/boot-digest.sh "$1" "$2"' "$UNIT" "$AGENT" "$N" | 67 | SERVICE_RESULT=${RES:-success} exec "$3/boot-digest.sh" "$1" "$2"' "$UNIT" "$AGENT" "$N" "$ROOT" |
| 52 | # Block until the digest exists (so a caller that waits on this script gets the result), then print it. | 68 | # Block until the digest exists (so a caller that waits on this script gets the result), then print it. |
| 53 | while [ ! -s "$WORK/boot-$N.digest.txt" ] || systemctl --user is-active --quiet "leonida-digest-$AGENT-$N"; do sleep 5; done | 69 | while [ ! -s "$WORK/boot-$N.digest.txt" ] || systemctl --user is-active --quiet "leonida-digest-$AGENT-$N"; do sleep 5; done |
| 54 | echo "run-boot: $UNIT finished. Digest:" | 70 | echo "run-boot: $UNIT finished. Digest:" |
diff --git a/scripts/run_game_wine.sh b/scripts/run_game_wine.sh index ce01b0a07..9d8f19a37 100755 --- a/scripts/run_game_wine.sh +++ b/scripts/run_game_wine.sh | |||
| @@ -55,11 +55,13 @@ die() { echo "run_game_wine.sh: $*" >&2; exit 2; } | |||
| 55 | 55 | ||
| 56 | if [ "${1:-}" = --inner ]; then | 56 | if [ "${1:-}" = --inner ]; then |
| 57 | # ---- inside the session: DISPLAY is kwin's Xwayland (headless) or the caller's display (--visible) ---- | 57 | # ---- inside the session: DISPLAY is kwin's Xwayland (headless) or the caller's display (--visible) ---- |
| 58 | [ "$#" -ge 5 ] || die "--inner requires RUN BUILD LIMIT SHOT_EVERY" | ||
| 58 | RUN=$2; BUILD=$3; LIMIT=$4; SHOT_EVERY=$5 | 59 | RUN=$2; BUILD=$3; LIMIT=$4; SHOT_EVERY=$5 |
| 59 | shift 5 | 60 | shift 5 |
| 60 | WINE=${WINE:-wine} | 61 | WINE=${WINE:-wine} |
| 61 | WINESERVER=$(dirname "$(command -v "$WINE")")/wineserver | 62 | wine_bin=$(command -v "$WINE" 2>/dev/null || true) |
| 62 | [ -x "$WINESERVER" ] || WINESERVER=wineserver | 63 | WINESERVER=${wine_bin:+$(dirname "$wine_bin")/wineserver} |
| 64 | [ -n "$WINESERVER" ] && [ -x "$WINESERVER" ] || WINESERVER=wineserver | ||
| 63 | unset WAYLAND_DISPLAY # Wine's X11 driver on Xwayland, never its Wayland driver | 65 | unset WAYLAND_DISPLAY # Wine's X11 driver on Xwayland, never its Wayland driver |
| 64 | { | 66 | { |
| 65 | echo "display: ${DISPLAY:-none}" | 67 | echo "display: ${DISPLAY:-none}" |
| @@ -70,7 +72,7 @@ if [ "${1:-}" = --inner ]; then | |||
| 70 | mkdir -p "$WINEPREFIX" | 72 | mkdir -p "$WINEPREFIX" |
| 71 | "$WINESERVER" -p | 73 | "$WINESERVER" -p |
| 72 | # Warm-up: starts the prefix's services; no Mono/Gecko prompts in a new prefix. | 74 | # Warm-up: starts the prefix's services; no Mono/Gecko prompts in a new prefix. |
| 73 | WINEDLLOVERRIDES="$WINEDLLOVERRIDES;mscoree,mshtml=" "$WINE" wineboot -u </dev/null >/dev/null 2>&1 | 75 | WINEDLLOVERRIDES="${WINEDLLOVERRIDES:+$WINEDLLOVERRIDES;}mscoree,mshtml=" "$WINE" wineboot -u </dev/null >/dev/null 2>&1 |
| 74 | SHOTS= | 76 | SHOTS= |
| 75 | if [ "$SHOT_EVERY" != 0 ]; then | 77 | if [ "$SHOT_EVERY" != 0 ]; then |
| 76 | mkdir -p "$RUN/shots" | 78 | mkdir -p "$RUN/shots" |
| @@ -97,7 +99,10 @@ if [ "${1:-}" = --inner ]; then | |||
| 97 | code=$? | 99 | code=$? |
| 98 | echo "$(( $(date +%s) - t0 ))" > "$RUN/seconds" | 100 | echo "$(( $(date +%s) - t0 ))" > "$RUN/seconds" |
| 99 | echo "$code" > "$RUN/exit_code" | 101 | echo "$code" > "$RUN/exit_code" |
| 100 | [ -n "$SHOTS" ] && kill "$SHOTS" 2>/dev/null | 102 | if [ -n "$SHOTS" ]; then |
| 103 | kill "$SHOTS" 2>/dev/null || true | ||
| 104 | wait "$SHOTS" 2>/dev/null || true | ||
| 105 | fi | ||
| 101 | "$WINESERVER" -k 2>/dev/null | 106 | "$WINESERVER" -k 2>/dev/null |
| 102 | exit 0 | 107 | exit 0 |
| 103 | fi | 108 | fi |
| @@ -132,10 +137,11 @@ done | |||
| 132 | [ -n "$OUT" ] || die "--out is required: the run folder" | 137 | [ -n "$OUT" ] || die "--out is required: the run folder" |
| 133 | [ -n "$SHADERS" ] || die "--shaders (or LEONIDA_SHADERS) is required: the translated shader library, or none" | 138 | [ -n "$SHADERS" ] || die "--shaders (or LEONIDA_SHADERS) is required: the translated shader library, or none" |
| 134 | case $LIMIT in ''|*[!0-9]*|0*) die "--seconds must be a whole number of seconds above 0, not '$LIMIT'" ;; esac | 139 | case $LIMIT in ''|*[!0-9]*|0*) die "--seconds must be a whole number of seconds above 0, not '$LIMIT'" ;; esac |
| 135 | case $SHOT_EVERY in ''|*[!0-9]*) die "--screenshot-every must be a whole number of seconds, not '$SHOT_EVERY'" ;; esac | 140 | case $SHOT_EVERY in ''|*[!0-9]*|0?*) die "--screenshot-every must be a whole number of seconds, not '$SHOT_EVERY'" ;; esac |
| 136 | if [ -n "$DEVICE" ] && ! [[ $DEVICE =~ ^[0-9a-fA-F]{4}:[0-9a-fA-F]{4}$ ]]; then | 141 | if [ -n "$DEVICE" ] && ! [[ $DEVICE =~ ^[0-9a-fA-F]{4}:[0-9a-fA-F]{4}$ ]]; then |
| 137 | die "--device takes VID:DID in hex, as lspci -nn prints it (e.g. 1002:744c), not '$DEVICE'" | 142 | die "--device takes VID:DID in hex, as lspci -nn prints it (e.g. 1002:744c), not '$DEVICE'" |
| 138 | fi | 143 | fi |
| 144 | [ -e "$SRC" ] || die "no build path at $SRC" | ||
| 139 | [ -f "$EXE" ] || die "no game executable at $EXE" | 145 | [ -f "$EXE" ] || die "no game executable at $EXE" |
| 140 | [ -d "$GAME" ] || die "no package folder at $GAME" | 146 | [ -d "$GAME" ] || die "no package folder at $GAME" |
| 141 | if [ "$SHADERS" != none ]; then | 147 | if [ "$SHADERS" != none ]; then |
| @@ -195,6 +201,7 @@ fi | |||
| 195 | # ---- one run at a time: a shared prefix has one wineserver ---- | 201 | # ---- one run at a time: a shared prefix has one wineserver ---- |
| 196 | LOCK=${LOCK:-${XDG_RUNTIME_DIR:+$XDG_RUNTIME_DIR/leonida-run-game-wine.lock}} | 202 | LOCK=${LOCK:-${XDG_RUNTIME_DIR:+$XDG_RUNTIME_DIR/leonida-run-game-wine.lock}} |
| 197 | LOCK=${LOCK:-$RUN/run.lock} | 203 | LOCK=${LOCK:-$RUN/run.lock} |
| 204 | mkdir -p "$(dirname "$LOCK")" || die "cannot create lock parent for $LOCK" | ||
| 198 | exec 9>"$LOCK" || die "cannot open the lock $LOCK" | 205 | exec 9>"$LOCK" || die "cannot open the lock $LOCK" |
| 199 | flock -n 9 || die "another run holds $LOCK" | 206 | flock -n 9 || die "another run holds $LOCK" |
| 200 | mkdir -p "$RUN/overlay" "$RUN/saves" | 207 | mkdir -p "$RUN/overlay" "$RUN/saves" |
| @@ -217,11 +224,17 @@ else | |||
| 217 | unset DISPLAY XAUTHORITY | 224 | unset DISPLAY XAUTHORITY |
| 218 | fi | 225 | fi |
| 219 | export QT_QPA_PLATFORM=offscreen | 226 | export QT_QPA_PLATFORM=offscreen |
| 227 | DRM_SYSFS=${LEONIDA_DRM_SYSFS_DIR:-/sys/class/drm} | ||
| 220 | if [ -n "$DEVICE" ]; then | 228 | if [ -n "$DEVICE" ]; then |
| 221 | export MESA_VK_DEVICE_SELECT="$DEVICE!" | 229 | export MESA_VK_DEVICE_SELECT="$DEVICE!" |
| 222 | # kwin and Xwayland's glamor on the card that renders, so the present path stays on one device. | 230 | # kwin and Xwayland's glamor on the card that renders, so the present path stays on one device. |
| 223 | for n in /sys/class/drm/renderD*; do | 231 | dev_lc=${DEVICE,,} |
| 224 | [ "$(cat "$n/device/vendor" 2>/dev/null):$(cat "$n/device/device" 2>/dev/null)" = "0x${DEVICE%%:*}:0x${DEVICE#*:}" ] \ | 232 | for n in "$DRM_SYSFS"/renderD*; do |
| 233 | [ -e "$n" ] || continue | ||
| 234 | ven=$(cat "$n/device/vendor" 2>/dev/null || true) | ||
| 235 | did=$(cat "$n/device/device" 2>/dev/null || true) | ||
| 236 | ven=${ven//$'\r'/}; did=${did//$'\r'/} | ||
| 237 | [ "${ven,,}:${did,,}" = "0x${dev_lc%%:*}:0x${dev_lc#*:}" ] \ | ||
| 225 | && export KWIN_DRM_DEVICES=/dev/dri/${n##*/} | 238 | && export KWIN_DRM_DEVICES=/dev/dri/${n##*/} |
| 226 | done | 239 | done |
| 227 | else | 240 | else |
| @@ -242,8 +255,9 @@ else | |||
| 242 | fi | 255 | fi |
| 243 | env | grep -E '^(LEONIDA_|MESA_VK|WINEDLL|KWIN_DRM)' | sort > "$RUN/env.txt" | 256 | env | grep -E '^(LEONIDA_|MESA_VK|WINEDLL|KWIN_DRM)' | sort > "$RUN/env.txt" |
| 244 | 257 | ||
| 245 | WINESERVER=$(dirname "$(command -v "$WINE")")/wineserver | 258 | wine_bin=$(command -v "$WINE" 2>/dev/null || true) |
| 246 | [ -x "$WINESERVER" ] || WINESERVER=wineserver | 259 | WINESERVER=${wine_bin:+$(dirname "$wine_bin")/wineserver} |
| 260 | [ -n "$WINESERVER" ] && [ -x "$WINESERVER" ] || WINESERVER=wineserver | ||
| 247 | SESSION_PID= | 261 | SESSION_PID= |
| 248 | teardown() { | 262 | teardown() { |
| 249 | "$WINESERVER" -k 2>/dev/null | 263 | "$WINESERVER" -k 2>/dev/null |
| @@ -257,7 +271,7 @@ trap 'exit 130' INT TERM HUP | |||
| 257 | 271 | ||
| 258 | # The session command with its arguments baked in (kwin takes one program path). | 272 | # The session command with its arguments baked in (kwin takes one program path). |
| 259 | { | 273 | { |
| 260 | echo '#!/bin/sh' | 274 | echo '#!/usr/bin/env bash' |
| 261 | printf 'exec %q --inner %q %q %q %q' "$SELF" "$RUN" "$BUILD" "$LIMIT" "$SHOT_EVERY" | 275 | printf 'exec %q --inner %q %q %q %q' "$SELF" "$RUN" "$BUILD" "$LIMIT" "$SHOT_EVERY" |
| 262 | for a in "$@"; do printf ' %q' "$a"; done | 276 | for a in "$@"; do printf ' %q' "$a"; done |
| 263 | echo | 277 | echo |
| @@ -276,10 +290,17 @@ else | |||
| 276 | fi | 290 | fi |
| 277 | SESSION_PID=$! | 291 | SESSION_PID=$! |
| 278 | # The session ends when the inner run returns; this outer limit adds a margin for the start-up. | 292 | # The session ends when the inner run returns; this outer limit adds a margin for the start-up. |
| 279 | ( sleep $((LIMIT + 180)); kill -TERM "$SESSION_PID" 2>/dev/null ) 9>&- 2>/dev/null & | 293 | ( trap 'kill "${watch_sleep_pid:-}" 2>/dev/null || true; exit 0' TERM INT |
| 294 | watch_sleep_pid="" | ||
| 295 | sleep $((LIMIT + 180)) & | ||
| 296 | watch_sleep_pid=$! | ||
| 297 | wait "$watch_sleep_pid" 2>/dev/null || exit 0 | ||
| 298 | kill -TERM "$SESSION_PID" 2>/dev/null ) 9>&- </dev/null >/dev/null 2>&1 & | ||
| 280 | WATCH=$! | 299 | WATCH=$! |
| 281 | wait "$SESSION_PID" | 300 | wait "$SESSION_PID" |
| 282 | pkill -P "$WATCH" 2>/dev/null; kill "$WATCH" 2>/dev/null | 301 | pkill -P "$WATCH" 2>/dev/null || true |
| 302 | kill "$WATCH" 2>/dev/null || true | ||
| 303 | wait "$WATCH" 2>/dev/null || true | ||
| 283 | teardown; SESSION_PID= | 304 | teardown; SESSION_PID= |
| 284 | T1=$(date +%s) | 305 | T1=$(date +%s) |
| 285 | 306 | ||
| @@ -289,5 +310,6 @@ if [ ! -f "$RUN/exit_code" ]; then | |||
| 289 | exit 3 | 310 | exit 3 |
| 290 | fi | 311 | fi |
| 291 | python3 -I "$ROOT/tools/game_run_summary.py" "$RUN" --limit-seconds "$LIMIT" | tee "$RUN/summary.txt" | 312 | python3 -I "$ROOT/tools/game_run_summary.py" "$RUN" --limit-seconds "$LIMIT" | tee "$RUN/summary.txt" |
| 313 | summary_rc=${PIPESTATUS[0]} | ||
| 292 | echo "output: $RUN (stderr.log, boot.jsonl, summary.txt); total $((T1 - T0)) s. The logs stay on this machine." | 314 | echo "output: $RUN (stderr.log, boot.jsonl, summary.txt); total $((T1 - T0)) s. The logs stay on this machine." |
| 293 | exit 0 | 315 | exit "$summary_rc" |
diff --git a/scripts/run_wine_session.sh b/scripts/run_wine_session.sh index 72ace4407..437e18c3c 100755 --- a/scripts/run_wine_session.sh +++ b/scripts/run_wine_session.sh | |||
| @@ -1,9 +1,23 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | # Run CI tests on the display that initialized their dedicated Wine prefix. | 2 | # Run CI tests on the display that initialized their dedicated Wine prefix. |
| 3 | # | ||
| 4 | # The prefix is initialized and stopped with the Wine the tests use: $WINE (default: wine), as | ||
| 5 | # run_wine_tests.py does, so Proton's or UMU-Proton's files/bin/wine also works on a host without a | ||
| 6 | # system Wine. The wineserver is $WINESERVER, else the one next to $WINE, else wineserver on PATH. | ||
| 3 | set -e | 7 | set -e |
| 4 | : "${WINEPREFIX:?Set WINEPREFIX to a dedicated test prefix}" | 8 | : "${WINEPREFIX:?Set WINEPREFIX to a dedicated test prefix}" |
| 5 | 9 | ||
| 10 | wine=${WINE:-wine} | ||
| 11 | if ! wine_path=$(command -v -- "$wine"); then | ||
| 12 | echo "run_wine_session.sh: Wine not found: $wine (set WINE to the wine executable)" >&2 | ||
| 13 | exit 127 | ||
| 14 | fi | ||
| 15 | if [[ -z ${WINESERVER:-} ]]; then | ||
| 16 | WINESERVER=$(dirname -- "$wine_path")/wineserver | ||
| 17 | [[ -x $WINESERVER ]] || WINESERVER=wineserver | ||
| 18 | fi | ||
| 19 | |||
| 6 | # Stop this prefix's Wine processes before Xvfb tears down the display. | 20 | # Stop this prefix's Wine processes before Xvfb tears down the display. |
| 7 | trap 'wineserver -k || true' EXIT | 21 | trap '"$WINESERVER" -k || true' EXIT |
| 8 | timeout 5m wineboot --init </dev/null | 22 | timeout 5m "$wine_path" wineboot --init </dev/null |
| 9 | "$@" </dev/null | 23 | "$@" </dev/null |
diff --git a/scripts/run_wine_tests.py b/scripts/run_wine_tests.py index bd793a06d..acd933ee3 100644 --- a/scripts/run_wine_tests.py +++ b/scripts/run_wine_tests.py | |||
| @@ -44,6 +44,8 @@ import threading | |||
| 44 | import time | 44 | import time |
| 45 | 45 | ||
| 46 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | 46 | ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 47 | # subprocess uses poll on Linux, whose timeout is a signed int in milliseconds. | ||
| 48 | MAX_TIMEOUT_SECONDS = (2**31 - 1) // 1_000 | ||
| 47 | 49 | ||
| 48 | 50 | ||
| 49 | def _make_parent(path: str) -> None: | 51 | def _make_parent(path: str) -> None: |
| @@ -425,15 +427,13 @@ def stop_running_tests() -> None: | |||
| 425 | 427 | ||
| 426 | 428 | ||
| 427 | def positive_seconds(text: str) -> float: | 429 | def positive_seconds(text: str) -> float: |
| 428 | """--timeout: a finite value greater than 0, so subprocess.run never gets a bad timeout to raise on.""" | 430 | """Parse a positive timeout that fits the subprocess wait on all supported hosts.""" |
| 429 | try: | 431 | try: |
| 430 | value = float(text) | 432 | value = float(text) |
| 431 | except ValueError: | 433 | except ValueError: |
| 432 | raise argparse.ArgumentTypeError(f"invalid float value: {text!r}") from None | 434 | raise argparse.ArgumentTypeError(f"invalid float value: {text!r}") from None |
| 433 | if not math.isfinite(value): | 435 | if not 0 < value <= MAX_TIMEOUT_SECONDS: |
| 434 | raise argparse.ArgumentTypeError("must be a finite number") | 436 | raise argparse.ArgumentTypeError(f"must be positive and no greater than {MAX_TIMEOUT_SECONDS} seconds") |
| 435 | if value <= 0: | ||
| 436 | raise argparse.ArgumentTypeError("must be greater than 0") | ||
| 437 | return value | 437 | return value |
| 438 | 438 | ||
| 439 | 439 | ||
| @@ -547,7 +547,8 @@ def main() -> int: | |||
| 547 | help="Wine command (default: $WINE or wine)") | 547 | help="Wine command (default: $WINE or wine)") |
| 548 | ap.add_argument("--require", action="append", default=[], help="a test name whose entries must all pass (repeatable)") | 548 | ap.add_argument("--require", action="append", default=[], help="a test name whose entries must all pass (repeatable)") |
| 549 | ap.add_argument("--timeout", type=positive_seconds, default=120.0, | 549 | ap.add_argument("--timeout", type=positive_seconds, default=120.0, |
| 550 | help="maximum seconds per test; a shorter CTest TIMEOUT applies (default 120)") | 550 | help=f"maximum seconds per test (default 120, upper limit {MAX_TIMEOUT_SECONDS}). " |
| 551 | "A shorter CTest TIMEOUT applies.") | ||
| 551 | ap.add_argument("--jobs", type=positive_int, default=1, | 552 | ap.add_argument("--jobs", type=positive_int, default=1, |
| 552 | help="tests run at a time; RUN_SERIAL and RESOURCE_LOCK are kept (default 1)") | 553 | help="tests run at a time; RUN_SERIAL and RESOURCE_LOCK are kept (default 1)") |
| 553 | ap.add_argument("--summary", help="append a Markdown table to this file (e.g. $GITHUB_STEP_SUMMARY)") | 554 | ap.add_argument("--summary", help="append a Markdown table to this file (e.g. $GITHUB_STEP_SUMMARY)") |
diff --git a/scripts/vs_input_survey.py b/scripts/vs_input_survey.py index 040801a84..a4807249c 100644 --- a/scripts/vs_input_survey.py +++ b/scripts/vs_input_survey.py | |||
| @@ -90,7 +90,10 @@ def read_before_write(insns): | |||
| 90 | elif op == "v_swap_b32" and len(args) >= 2: | 90 | elif op == "v_swap_b32" and len(args) >= 2: |
| 91 | dsts, srcs = args[:2], args[:2] | 91 | dsts, srcs = args[:2], args[:2] |
| 92 | elif (op.startswith("v_") and ("_co_" in op or op in DUAL_DST_VALU) | 92 | elif (op.startswith("v_") and ("_co_" in op or op in DUAL_DST_VALU) |
| 93 | and len(args) >= 2 and args[1]["k"] in ("sgpr", "special", "slist")): | 93 | and len(args) >= 2 and args[1]["k"] in ("sgpr", "special", "slist") |
| 94 | # the short form v_add_co_ci_u32 vD, src0, src1 (also sub/subrev): carry out and in are an | ||
| 95 | # implicit VCC, and args[1] is src0, a read | ||
| 96 | and not (op.endswith("_co_ci_u32") and len(args) == 3)): | ||
| 94 | dsts, srcs = args[:2], args[2:] # vdst + scalar carry/scale-out dst | 97 | dsts, srcs = args[:2], args[2:] # vdst + scalar carry/scale-out dst |
| 95 | else: | 98 | else: |
| 96 | dst_read = ( | 99 | dst_read = ( |