Skip to content

Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.

C

tools: metal-run.sh at eight cores, 120 Hz, six scaling threads, without -v; frames.py counts the Metal road

yehorkaae4281188ed30
diff --git a/tools/frames.py b/tools/frames.py
index 5dd40c3..4de051d 100755
--- a/tools/frames.py
+++ b/tools/frames.py
@@ -19,12 +19,17 @@ to the next one or 2.5 s later -- is a segment; for each:
copy the display driver's copy into the panel's memory
The thresholds are as the coordinator asked for them; 18.0 rather than 16.7 because a frame of a steady
-60 comes 16.6 to 16.8 ms after the one before.
+60 comes 16.6 to 16.8 ms after the one before. Beside them, the share over 8.3 ms (from 9.0: a 120 Hz frame
+missed), what a run at fb_hz=120 is measured by.
+
+A window server drawing through Metal says no "tl: g" (that is eagl.c's, the OpenGL ES road): its frames are
+counted all the same, by the swap that handed each over, and draw and idle are then unknown (0).
"""
import os
import sys
OVER_ONE, OVER_TWO, SEGMENT_US = 18000, 34500, 2500000
+OVER_120 = 9000
# the first cpu-id of a small core: the loader lists the boot core, then the big ones, then the small (xnuloader/loader.c);
# on the phone with cpus=7 the Cortex-A55s are 4, 5 and 6 (FRAMES_SMALL_FROM= for another layout)
SMALL_FROM = int(os.environ.get('FRAMES_SMALL_FROM', '4'))
@@ -77,9 +82,13 @@ def main():
continue
swap = swaps[sid]
drawn = [f for f in frames if f[1] <= swap]
- if not drawn:
+ if drawn:
+ began, ended, draws, cpu = drawn[-1]
+ elif not frames:
+ began = ended = swap # the Metal road: no "tl: g", the swap is where its frame ended
+ cpu = -1
+ else:
continue
- began, ended, draws, cpu = drawn[-1]
ready, shown, done = shows[sid]
timeline.append(dict(began=began, ended=ended, swap=swap, ready=ready, shown=shown, done=done, cpu=cpu))
timeline.sort(key=lambda f: f['done'])
@@ -101,6 +110,7 @@ def main():
span = sum(g[0] for g in moving)
over1 = [g for g in moving if g[0] > OVER_ONE]
over2 = [g for g in moving if g[0] > OVER_TWO]
+ over120 = [g for g in moving if g[0] > OVER_120]
all_counts[0] += len(moving)
all_counts[1] += len(over1)
all_counts[2] += len(over2)
@@ -112,6 +122,7 @@ def main():
k[4] += len(over2)
fps = len(moving) * 1e6 / span if span else 0
line = (f'{i + 1:2}. {start / 1e6:9.3f} s {what}: {len(moving)} frames at {fps:4.1f} a second; '
+ f'over 8.3 ms {100 * len(over120) / max(1, len(moving)):3.0f}%, '
f'over 16.7 ms {100 * len(over1) / max(1, len(moving)):3.0f}%, over 33 ms {100 * len(over2) / max(1, len(moving)):3.0f}%')
if over1:
# where the slow frames' time went (means over them)
diff --git a/tools/metal-run.sh b/tools/metal-run.sh
index d662a91..d9c1b40 100755
--- a/tools/metal-run.sh
+++ b/tools/metal-run.sh
@@ -8,6 +8,7 @@
# PERSIST=0 tools/metal-run.sh without var_store: /private/var starts empty and nothing is written to darwin
# UPLOAD=0 tools/metal-run.sh keep the system image already in the phone's RAM (default: upload this copy's)
# SHOTS=N a screenshot every N seconds during the run into logs/<stamp>-shots/ (default 0)
+# VERBOSE=1 tools/metal-run.sh with -v: the kernel's text console drawn over the picture (off by default: the log has it all)
#
# What it needs, built in WSL (docs/windows.md) and copied here: userland/root.apfs and userland/system.apfs from
# METAL_PLUGIN=ca RC_JOBS=rc.jobs.bench EXTRA_SHARE=<dir of QuartzCore-default.metallib> PREBUILT=1 REST=1 SYSTEM=1 userland/build.sh
@@ -21,6 +22,13 @@
# ca_metallib=... QuartzCore's library for the window server (tools/ca-metallib.py)
# gpu_recover=1 a GPU hang is reset and counted, not the end of the run
# anim_max=1 SpringBoard's animations ask for 80..120 frames a second
+# bootcpu=7 cpus=8 cpufreq=1 the kernel on a big core with all eight and their clocks (docs/u-boot.md): xl's own
+# default is one small core, on which the first boot is still compiling CoreAnimation's
+# shaders when the bench ends (2 November: first frame at 159 s on one core, 86 s on eight)
+# fb_hz=120 fb_measure=1 the framebuffer's beat at the panel's 120 Hz, not its default 60, and the panel's own
+# rate measured once (MiniIOMobileFramebuffer.cpp)
+# fb_threads=6 six processors scale a frame onto the panel, not three: Settings' scroll 75 -> 84 frames
+# a second (2 November, tools/frames.py)
# ufs=2 ufs_write=1 var_store=1 (PERSIST=1, the default) /private/var kept in the partition darwin between boots: the
# compiled shader stages in /var/db/hakios-metal-cache survive, so only the first boot
# ever compiles them (tools/metal-cache-seed.sh then puts them in the image)
@@ -47,8 +55,9 @@ PERSIST=${PERSIST:-1}
UPLOAD=${UPLOAD:-1}
SHOTS=${SHOTS:-0}
CA_METALLIB=${CA_METALLIB:-/redwood/share/ca-share/QuartzCore-default.metallib}
-ARGS="-v gpu=1 metal=1 metal_fps=1 touch_lat=1 touchscreen=1 ca_metallib=$CA_METALLIB gpu_recover=1 anim_max=1"
+ARGS="gpu=1 metal=1 metal_fps=1 touch_lat=1 touchscreen=1 ca_metallib=$CA_METALLIB gpu_recover=1 anim_max=1 bootcpu=7 cpus=8 cpufreq=1 fb_hz=120 fb_measure=1 fb_threads=6"
[ "$PERSIST" = 1 ] && ARGS="$ARGS ufs=2 ufs_write=1 var_store=1"
+[ "${VERBOSE:-0}" = 1 ] && ARGS="-v $ARGS"
ARGS="$ARGS ${MORE:-}"
stamp=$(date +%H%M%S)
mkdir -p logs
@@ -81,11 +90,16 @@ log=logs/$(readlink logs/last.log 2>/dev/null || ls -t logs/*-run.log 2>/dev/nul
"$PY" -I tools/frames.py "$log" $(ls "$log".live.* 2>/dev/null) 2>&1 | head -60
echo
echo "== HakiosMetal"
- grep -a 'HakiosMetal: fps:' "$log" | tail -40
- grep -a -E 'HakiosMetal: (inplace_copy|CoreAnimation.s .*compiled as)' "$log" | sort | uniq -c | head
+ grep -a -E 'HakiosMetal(\[[^]]*\])?: fps:' "$log" | tail -40
+ grep -a -E 'HakiosMetal(\[[^]]*\])?: (inplace_copy|CoreAnimation.s .*compiled as)' "$log" | sort | uniq -c | head
echo
echo "== refused (count, kind)"
- grep -a 'HakiosMetal: refused:' "$log" | sed -E 's/.*refused: //; s/[0-9]+ vertices.*: /...: /' | sort | uniq -c | sort -rn | head -15
+ grep -a -E 'HakiosMetal(\[[^]]*\])?: refused:' "$log" | sed -E 's/.*refused: //; s/[0-9]+ vertices.*: /...: /' | sort | uniq -c | sort -rn | head -15
+ echo
+ echo "== frames on the panel (MiniIOMobileFramebuffer, every 5 s: what the window server drew through Metal)"
+ grep -a -E 'MiniIOMobileFramebuffer: the panel:' "$log" | sed 's/^\[[^]]*\]: //'
+ grep -a -oE 'MiniIOMobileFramebuffer: [0-9]+ frames in [0-9]+ ms \([0-9]+ a second\), [0-9]+ us each in the driver, after [0-9]+ us waiting for the GPU' "$log" |
+ sed -E 's/MiniIOMobileFramebuffer: //' | tail -40
echo
echo "== shader cache and var_store"
grep -a -E 'var_store|hakios-metal-cache' "$log" | tail -12