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
SpringBoard: boot-arg anim_max=1, its animations ask the window server for 80..120 a second
shimoku743639b98ae6ad
diff --git a/configs/boot-args.lst b/configs/boot-args.lstindex 8e92eee..7af859d 100644--- a/configs/boot-args.lst+++ b/configs/boot-args.lst@@ -63,6 +63,7 @@ bt_again kbuttons kbuttons_steps kca_metallib u+ca_prof uca_vbl ucaenv ucam kl@@ -151,6 +152,14 @@ loader_return_after klmachine_name kmembench kmetal ku+metal_all u+metal_dump u+metal_fps u+metal_gmem u+metal_gmem_draws u+metal_gmem_off u+metal_skip u+metal_trace umetal_watch umic kmic_adc kdiff --git a/configs/symbols.tsv b/configs/symbols.tsvindex 09b76e5..31ed41b 100644--- a/configs/symbols.tsv+++ b/configs/symbols.tsv@@ -58,6 +58,7 @@ BT_AGAIN arg bt_again User space k hakios.bt.c the second look this many secondsBUTTONS arg buttons Touch and buttons k hakios.buttons.cBUTTONS_STEPS arg buttons_steps Touch and buttons k hakios.buttons.cCA_METALLIB arg ca_metallib User space u inject.c+CA_PROF arg ca_prof User space u HakiosMetalCA.mCA_VBL arg ca_vbl User space u inject.c CoreAnimation's frame clock from the display driver's refresh notificationsCAENV arg caenv User space u inject.c,inject_sb.c CoreAnimation's switches here as in the window server (inject.c), set before QuartzCore reads themCAM_AFTER arg cam_after Cameras k hakios.camera.c@@ -137,6 +138,14 @@ HAPTIC_EFFECT arg haptic_effect Haptics and torch k hakios.haptic.cMACHINE_NAME arg machine_name CPU, memory and boot k GenericARMPE.cppMEMBENCH arg membench CPU, memory and boot k hakios.cpufreq.cMETAL arg metal GPU and display ku HakiosMetal.m,MiniIOMobileFramebuffer.cpp only the program metal_test (userland/src/metal_test.m): the safe level, for seeing what Metal does with the device+METAL_ALL arg metal_all User space u HakiosMetalCA.m+METAL_DUMP arg metal_dump User space u HakiosMetalCA.m+METAL_FPS arg metal_fps User space u HakiosMetalCA.m each draw of a sysmem pass timed alone, by program (only sysmem passes are: without metal_gmem=1)+METAL_GMEM arg metal_gmem User space u HakiosMetalCA.m+METAL_GMEM_DRAWS arg metal_gmem_draws User space u HakiosMetalCA.m GMEM for a pass whose like had at least N draws in the frame before (hakios_metal_cb_set_gmem_min_draws), sysmem for the rest; 56 when not given, 0+METAL_GMEM_OFF arg metal_gmem_off User space u HakiosMetalCA.m+METAL_SKIP arg metal_skip User space u HakiosMetalCA.m+METAL_TRACE arg metal_trace User space u HakiosMetalCA.mMETAL_WATCH arg metal_watch User space u inject.cMIC_ADC arg mic_adc Audio and battery k hakios.mic.cMIC_INPUT arg mic_input Audio and battery k hakios.mic.c@@ -236,7 +245,7 @@ TORCH arg torch Haptics and torch kl hakios.torch.c,loader.c a look, reading onlTORCH_MAX_S arg torch_max_s Haptics and torch k hakios.torch.cTORCH_SECS arg torch_secs Haptics and torch k hakios.torch.cTOUCH_FLIP arg touch_flip Touch and buttons k hakios.goodix.c-TOUCH_LAT arg touch_lat GPU and display ku MiniIOMobileFramebuffer.cpp,eagl.c,hakios.goodix.c,hakios.gpu.cpp,hakios.input.c,inject.c,inject_sb.c a line for every wait of a program's for the GPU that took a millisecond or more ("tl: f KIND US at US"), for telling apart what holds a frame up+TOUCH_LAT arg touch_lat GPU and display ku HakiosMetalCA.m,MiniIOMobileFramebuffer.cpp,eagl.c,hakios.goodix.c,hakios.gpu.cpp,hakios.input.c,inject.c,inject_sb.c a line for every wait of a program's for the GPU that took a millisecond or more ("tl: f KIND US at US"), for telling apart what holds a frame upTOUCH_POLL_US arg touch_poll_us Touch and buttons k hakios.goodix.cTOUCH_RATE arg touch_rate Touch and buttons k hakios.goodix.c the chip reports twice as often (Xiaomi's game mode; 240 otherwise)TOUCH_SPI_HZ arg touch_spi_hz Touch and buttons k hakios.goodix.c the bus at N Hz (Android's device tree gives the chip 5 MHz)diff --git a/docs/boot-args.md b/docs/boot-args.mdindex 6092d6f..16bc0fd 100644--- a/docs/boot-args.md+++ b/docs/boot-args.md@@ -2,7 +2,7 @@Made by `tools/boot-args.py --markdown`; CI fails if it is out of date with the source (`tools/boot-args.py --check`).-Every argument that the kernel, the loader or user space of this port reads, and which file reads it. **330 arguments**: 276 read by the kernel, 14 by the loader, 50 by user space (one is read in more than one place).+Every argument that the kernel, the loader or user space of this port reads, and which file reads it. **339 arguments**: 276 read by the kernel, 14 by the loader, 59 by user space (one is read in more than one place).This is a catalogue of what exists and who reads it, not a manual. What an argument means is in the head of the file that reads it. The stable switches have a symbol in the configuration (`tools/hakios-config.py help SYMBOL`, `docs/configs.md`); the rest are the knobs of bring-up (a driver's steps, pauses, traces, test modes) and can change with the driver. Any of them can be given in a configuration with `CONFIG_BOOTARGS="name=value ..."`, which checks that each name is in this list.@@ -84,7 +84,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `surf_wrap` | K | `MiniIOSurface.cpp` | `CONFIG_SURF_WRAP` | || `surftrace` | K | `MiniIOSurface.cpp` | `CONFIG_SURFTRACE` | || `surftrace_of` | K | `MiniIOSurface.cpp` | `CONFIG_SURFTRACE_OF` | |-| `touch_lat` | KU | `MiniIOMobileFramebuffer.cpp`, `eagl.c`, `hakios.goodix.c`, `hakios.gpu.cpp`, `hakios.input.c`, `inject.c`, `inject_sb.c` | `CONFIG_TOUCH_LAT` | |+| `touch_lat` | KU | `HakiosMetalCA.m`, `MiniIOMobileFramebuffer.cpp`, `eagl.c`, `hakios.goodix.c`, `hakios.gpu.cpp`, `hakios.input.c`, `inject.c`, `inject_sb.c` | `CONFIG_TOUCH_LAT` | || `vblur` | U | `eagl.c` | `CONFIG_VBLUR` | |## Security stand-ins (1)@@ -395,7 +395,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `ufs` | L | `loader.c` | `CONFIG_UFS` | || `ufs_probe` | L | `loader.c` | `CONFIG_UFS_PROBE` | |-## User space (18)+## User space (27)| Argument | Layer | Read by | Configuration | Set by ||---|---|---|---|---|@@ -403,6 +403,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `bt` | K | `hakios.bt.c` | `CONFIG_BT` | || `bt_again` | K | `hakios.bt.c` | `CONFIG_BT_AGAIN` | || `ca_metallib` | U | `inject.c` | `CONFIG_CA_METALLIB` | |+| `ca_prof` | U | `HakiosMetalCA.m` | `CONFIG_CA_PROF` | || `ca_vbl` | U | `inject.c` | `CONFIG_CA_VBL` | || `caenv` | U | `inject.c`, `inject_sb.c` | `CONFIG_CAENV` | || `cc_fade` | U | `inject_sb.c` | `CONFIG_CC_FADE` | |@@ -411,6 +412,14 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke| `glno` | U | `inject.c` | `CONFIG_GLNO` | || `glsb3` | U | `inject.c` | `CONFIG_GLSB3` | || `glyes` | U | `inject.c` | `CONFIG_GLYES` | |+| `metal_all` | U | `HakiosMetalCA.m` | `CONFIG_METAL_ALL` | |+| `metal_dump` | U | `HakiosMetalCA.m` | `CONFIG_METAL_DUMP` | |+| `metal_fps` | U | `HakiosMetalCA.m` | `CONFIG_METAL_FPS` | |+| `metal_gmem` | U | `HakiosMetalCA.m` | `CONFIG_METAL_GMEM` | |+| `metal_gmem_draws` | U | `HakiosMetalCA.m` | `CONFIG_METAL_GMEM_DRAWS` | |+| `metal_gmem_off` | U | `HakiosMetalCA.m` | `CONFIG_METAL_GMEM_OFF` | |+| `metal_skip` | U | `HakiosMetalCA.m` | `CONFIG_METAL_SKIP` | |+| `metal_trace` | U | `HakiosMetalCA.m` | `CONFIG_METAL_TRACE` | || `metal_watch` | U | `inject.c` | `CONFIG_METAL_WATCH` | || `root_apfs` | U | `init.c` | `CONFIG_ROOT_APFS` | || `sb_delay` | U | `inject_sb.c` | | xl (XL_SB_DELAY) |diff --git a/userland/src/inject_sb.c b/userland/src/inject_sb.cindex 31e11ca..880ac16 100644--- a/userland/src/inject_sb.c+++ b/userland/src/inject_sb.c@@ -1321,6 +1321,53 @@ boot_arg(const char *arguments, const char *name)return at != NULL && (at == arguments || at[-1] == ' ');}+/*+ * The animations SpringBoard hands the window server (an application opening from its icon and closing to it, the+ * home screen coming back, folders): the window server moves them at the rate each asks for (CAAnimation's+ * preferredFrameRateRange). Through Metal (METAL_PLUGIN=ca) it keeps to that, and what asks for nothing went at 24 a+ * second -- frames exactly 41.7 ms apart with the GPU 0.3 ms busy each; through OpenGL ES it did not. With anim_max=1+ * every animation added to a layer of SpringBoard's asks for 80..120 (a copy of it: one already added is read-only,+ * and setting it raised). touch_lat=1 says the first ones and what they asked.+ */+static void (*original_add_animation)(id self, SEL selector, id animation, id key);+static unsigned anim_said;++static void+add_animation_full_rate(id self, SEL selector, id animation, id key)+{+ SEL range_of = sel_registerName("preferredFrameRateRange"), set_range_of = sel_registerName("setPreferredFrameRateRange:");++ if (animation != NULL && class_respondsToSelector(object_getClass(animation), set_range_of)) {+ frame_rate_range asked = ((frame_rate_range (*)(id, SEL))objc_msgSend)(animation, range_of);++ if (dl_say && anim_said++ < 40) {+ say("hakios: animation %s (%s) asked for %.0f..%.0f, %.0f a second\n", object_getClassName(animation),+ key != NULL ? text_of(key) : "", asked.minimum, asked.maximum, asked.preferred);+ }+ if (asked.maximum == 0 || asked.maximum < 120 || asked.minimum < 80) {+ id copy = SEND(id, animation, "copy");++ ((void (*)(id, SEL, frame_rate_range))objc_msgSend)(copy, set_range_of, (frame_rate_range){ 80, 120, 120 });+ original_add_animation(self, selector, copy, key);+ SEND(void, copy, "release");+ return;+ }+ }+ original_add_animation(self, selector, animation, key);+}++static void+animation_rates(const char *arguments)+{+ Method add = class_getInstanceMethod(objc_getClass("CALayer"), sel_registerName("addAnimation:forKey:"));++ if (!boot_arg(arguments, "anim_max=1") || add == NULL) {+ return;+ }+ original_add_animation = (void (*)(id, SEL, id, id))method_setImplementation(add, (IMP)add_animation_full_rate);+ say("hakios: SpringBoard's animations ask for 80..120 a second (anim_max=1)\n");+}+static voiddisplay_link_rates(void){@@ -1334,6 +1381,7 @@ display_link_rates(void)}dl_say = boot_arg(arguments, "touch_lat=1");dl_max = !boot_arg(arguments, "dl_max=0");+ animation_rates(arguments);if (!dl_say && !dl_max) {return;}