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

fb_filter=2 (the default): nearest neighbour while frames come, the frame drawn again bilinear once it stands still (40 ms); fb_pri: the panel's threads at 92. Scaling onto the panel: 1.9 ms as a rule and 4.4 for one in ten, against 3.6 and 11; Settings scrolled at 108 frames a second (rc.jobs.scroll)

shimoku74cd8fdbb562b9
diff --git a/configs/boot-args.lst b/configs/boot-args.lst
index e2e05d3..6a3a0fb 100644
--- a/configs/boot-args.lst
+++ b/configs/boot-args.lst
@@ -93,6 +93,7 @@ fb_diff k
fb_filter k
fb_hz k
fb_measure k
+fb_pri k
fb_queue k
fb_threads k
fbheight k
diff --git a/configs/symbols.tsv b/configs/symbols.tsv
index dba06d1..548174c 100644
--- a/configs/symbols.tsv
+++ b/configs/symbols.tsv
@@ -84,6 +84,7 @@ FB_DIFF arg fb_diff GPU and display k MiniIOMobileFramebuffer.cpp which pixels o
FB_FILTER arg fb_filter GPU and display k MiniIOMobileFramebuffer.cpp the picture is scaled to the panel nearest neighbour, as it once was
FB_HZ arg fb_hz GPU and display k MiniIOMobileFramebuffer.cpp
FB_MEASURE arg fb_measure GPU and display k MiniIOMobileFramebuffer.cpp how often the panel is really refreshed
+FB_PRI arg fb_pri GPU and display k MiniIOMobileFramebuffer.cpp
FB_QUEUE arg fb_queue GPU and display k MiniIOMobileFramebuffer.cpp
FB_THREADS arg fb_threads GPU and display k MiniIOMobileFramebuffer.cpp
FBHEIGHT arg fbheight GPU and display k MiniIOMobileFramebuffer.cpp
diff --git a/docs/boot-args.md b/docs/boot-args.md
index ed7bfb4..cb91133 100644
--- a/docs/boot-args.md
+++ b/docs/boot-args.md
@@ -2,13 +2,13 @@
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. **324 arguments**: 274 read by the kernel, 14 by the loader, 46 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. **325 arguments**: 275 read by the kernel, 14 by the loader, 46 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.
Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl kern.bootargs`).
-## GPU and display (70)
+## GPU and display (71)
| Argument | Layer | Read by | Configuration | Set by |
|---|---|---|---|---|
@@ -31,6 +31,7 @@ Layers: **K** the kernel, **L** the loader, **U** user space (through `sysctl ke
| `fb_filter` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FB_FILTER` | |
| `fb_hz` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FB_HZ` | |
| `fb_measure` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FB_MEASURE` | |
+| `fb_pri` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FB_PRI` | |
| `fb_queue` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FB_QUEUE` | |
| `fb_threads` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FB_THREADS` | |
| `fbheight` | K | `MiniIOMobileFramebuffer.cpp` | `CONFIG_FBHEIGHT` | |
diff --git a/userland/rc.jobs.scroll b/userland/rc.jobs.scroll
new file mode 100644
index 0000000..c04c414
--- /dev/null
+++ b/userland/rc.jobs.scroll
@@ -0,0 +1,8 @@
+# Commands run by the launchd job com.hakios.demo (see com.hakios.demo.plist).
+# Frame rate while a finger moves (RC_JOBS=rc.jobs.scroll, touch_lat=1, a run of about 110 s, short enough for the log to
+# keep it all): unlock; the home screen's pages swiped both ways six times; Settings opened and its list dragged up and
+# down by a finger that stays on the glass (zigzag) and flung; closed. What CoreAnimation believes of the screen last.
+/redwood/bin/rwtouch wait 30 swipe 0.5 0.985 0.5 0.3 200 wait 8
+/redwood/bin/rwtouch swipe 0.85 0.5 0.15 0.5 300 wait 1 swipe 0.15 0.5 0.85 0.5 300 wait 1 swipe 0.85 0.5 0.15 0.5 300 wait 1 swipe 0.15 0.5 0.85 0.5 300 wait 1 swipe 0.85 0.5 0.15 0.5 300 wait 1 swipe 0.15 0.5 0.85 0.5 300 wait 2
+/redwood/bin/rwtouch tap 0.615 0.71 wait 5 zigzag 0.5 0.75 0.35 500 6 wait 2 swipe 0.5 0.8 0.5 0.3 150 wait 2 swipe 0.5 0.3 0.5 0.8 150 wait 2 button home wait 3
+/redwood/bin/fps_info
diff --git a/xnu/files/iokit/Kernel/MiniIOMobileFramebuffer.cpp b/xnu/files/iokit/Kernel/MiniIOMobileFramebuffer.cpp
index fb288f2..47af973 100644
--- a/xnu/files/iokit/Kernel/MiniIOMobileFramebuffer.cpp
+++ b/xnu/files/iokit/Kernel/MiniIOMobileFramebuffer.cpp
@@ -150,7 +150,15 @@ static TUNABLE(uint32_t, gDiff, "fb_diff", 0);
* little crooked, here and there and never in the same places twice. By default every pixel of the
* panel is worked out from the four of the picture around where it falls (bilinear).
*/
-static TUNABLE(uint32_t, gFilter, "fb_filter", 1);
+static TUNABLE(uint32_t, gFilter, "fb_filter", 2);
+/*
+ * fb_filter=2 (the default): nearest neighbour while frames come, bilinear once they stop. Bilinear costs: a frame
+ * took 3.6 ms to scale onto the panel as a rule and 11 ms for one in ten, at any priority (fb_pri), against 1.7 and
+ * 4.3 by nearest neighbour (touch_lat=1, 30 October) -- and at 120 Hz a refresh is 8.3 ms. What nearest neighbour
+ * gets wrong (a column in 25 and a row in 67 left out) does not show while the picture moves; so a frame drawn so is
+ * drawn again, filtered, when no other has come for SETTLE_MS: what stands still on the screen is the bilinear one.
+ */
+#define SETTLE_MS 40
static TUNABLE(uint32_t, gRefreshHz, "fb_hz", kFBRefreshHz);
/*
* Boot-arg fb_ca_hz=N: the refresh rate told to CoreAnimation (IOMFBDisplayRefresh) when it is not to be fb_hz's. On
@@ -166,6 +174,25 @@ static TUNABLE(uint32_t, gOnTheBeat, "fb_beat", 1);
* to 10 (the phone, 15 October; fb_threads=1 is how it was).
*/
static TUNABLE(uint32_t, gThreads, "fb_threads", 3);
+/*
+ * Boot-arg fb_pri=N: the scheduling priority of the threads that put frames on the panel (the presenter and its
+ * helpers); 0 is the kernel's default for its threads. By default 92 (BASEPRI_PREEMPT): at the kernel's they lost the
+ * processors to the window server's own real-time threads under load, and a frame took 3.6 ms to put on the panel
+ * as a rule but 10.9 for one in ten (touch_lat=1, 30 October), more than the whole of a refresh at 120 Hz.
+ */
+static TUNABLE(uint32_t, gThreadPriority, "fb_pri", 92);
+extern "C" kern_return_t kernel_thread_start_priority(thread_continue_t continuation, void * parameter, integer_t priority,
+ thread_t * new_thread);
+
+/* a thread of the panel's, at fb_pri */
+static kern_return_t
+panel_thread_start(thread_continue_t continuation, void * parameter, thread_t * thread)
+{
+ if (gThreadPriority >= 1 && gThreadPriority <= 95) {
+ return kernel_thread_start_priority(continuation, parameter, (integer_t) gThreadPriority, thread);
+ }
+ return kernel_thread_start(continuation, parameter, thread);
+}
#define SWAP_QUEUE 2 /* frames that may wait for the panel at most (fb_queue) */
static TUNABLE(uint32_t, gQueue, "fb_queue", 2);
static inline unsigned
@@ -304,6 +331,7 @@ public:
uint64_t fBeat; /* the beat the last frame was shown on */
uint64_t fReady; /* when the last frame was ready to be shown */
uint32_t fStatOnBeat; /* frames that waited for a refresh, and for how long together */
+ uint32_t fStatSettled; /* frames drawn again, filtered, once they stood still (fb_filter=2) */
uint64_t fStatBeatWait;
uint32_t fStatSurfaces[8]; /* the first different surfaces the bottom layer was given */
uint32_t fStatHeld, fStatLost; /* swaps that waited for the one before; that gave up waiting */
@@ -339,6 +367,8 @@ public:
MiniIOSurface * defaultSurface(void);
void present(const uint8_t * swap);
void show(const uint8_t * swap, MiniIOSurface ** surfaces);
+ void settle(const uint8_t * swap, MiniIOSurface ** surfaces);
+ bool fSettling; /* drawing the last frame again, filtered (fb_filter=2) */
void presenter(void);
static void presenterMain(void * self, wait_result_t result);
void reportFrameTimes(void);
@@ -480,7 +510,7 @@ IOMobileFramebuffer::start(IOService * provider)
}
fLock = IOLockAlloc();
fSwapLock = IOLockAlloc();
- if (kernel_thread_start(&IOMobileFramebuffer::presenterMain, this, &thread) != KERN_SUCCESS) {
+ if (panel_thread_start(&IOMobileFramebuffer::presenterMain, this, &thread) != KERN_SUCCESS) {
IOLog("MiniIOMobileFramebuffer: no thread to put frames on the panel with\n");
return false;
}
@@ -489,7 +519,7 @@ IOMobileFramebuffer::start(IOService * provider)
fThreads = gThreads >= 1 && gThreads <= 8 ? gThreads : 1;
fHelperLock = IOLockAlloc();
for (unsigned i = 0; i + 1 < fThreads; i++) {
- if (kernel_thread_start(&IOMobileFramebuffer::helperMain, this, &thread) != KERN_SUCCESS) {
+ if (panel_thread_start(&IOMobileFramebuffer::helperMain, this, &thread) != KERN_SUCCESS) {
fThreads = i + 1;
break;
}
@@ -833,7 +863,7 @@ IOMobileFramebuffer::drawLayer(MiniIOSurface * s, const int32_t * src, const int
int32_t sx = src[0], sy = src[1], sw = src[2], sh = src[3];
int32_t dx = dst[0], dy = dst[1], dw = dst[2], dh = dst[3];
int32_t px0, py0, px1, py1, cx0, cx1;
- bool filter = gFilter != 0;
+ bool filter = gFilter == 1 || (gFilter == 2 && fSettling);
RowJob job;
if (sw <= 0 || sh <= 0) {
@@ -1046,26 +1076,79 @@ void
IOMobileFramebuffer::presenter(void)
{
static uint8_t swap[SWAP_SIZE]; /* (one thread) */
- MiniIOSurface * surfaces[SWAP_LAYERS];
+ MiniIOSurface * surfaces[SWAP_LAYERS] = { NULL };
+ bool unsettled = false; /* the frame on the panel was drawn unfiltered, and its surfaces are held */
for (;;) {
IOLockLock(fSwapLock);
while (fSwapsWaiting == 0) {
- IOLockSleep(fSwapLock, fSwap, THREAD_UNINT);
+ uint64_t deadline;
+
+ if (!unsettled) {
+ IOLockSleep(fSwapLock, fSwap, THREAD_UNINT);
+ continue;
+ }
+ clock_interval_to_deadline(SETTLE_MS, NSEC_PER_MSEC, &deadline);
+ if (IOLockSleepDeadline(fSwapLock, fSwap, deadline, THREAD_UNINT) == THREAD_TIMED_OUT && fSwapsWaiting == 0) {
+ IOLockUnlock(fSwapLock);
+ settle(swap, surfaces);
+ unsettled = false;
+ IOLockLock(fSwapLock);
+ }
}
- memcpy(swap, fSwap[fSwapFirst], SWAP_SIZE);
- memcpy(surfaces, fSwapSurfaces[fSwapFirst], sizeof(surfaces));
IOLockUnlock(fSwapLock);
- show(swap, surfaces);
+ /* the frame before is done with now, settled or not */
for (unsigned layer = 0; layer < SWAP_LAYERS; layer++) {
if (surfaces[layer] != NULL) {
MiniIOSurfaceDrop(surfaces[layer]);
+ surfaces[layer] = NULL;
+ }
+ }
+ IOLockLock(fSwapLock);
+ memcpy(swap, fSwap[fSwapFirst], SWAP_SIZE);
+ memcpy(surfaces, fSwapSurfaces[fSwapFirst], sizeof(surfaces));
+ IOLockUnlock(fSwapLock);
+ show(swap, surfaces);
+ unsettled = gFilter == 2;
+ if (!unsettled) {
+ for (unsigned layer = 0; layer < SWAP_LAYERS; layer++) {
+ if (surfaces[layer] != NULL) {
+ MiniIOSurfaceDrop(surfaces[layer]);
+ surfaces[layer] = NULL;
+ }
}
}
MiniIOSurfaceClearKept(); /* (the next frame is some milliseconds away) */
}
}
+/*
+ * The frame on the panel once more, filtered (fb_filter=2): the same layers from the same surfaces where show() put
+ * them, nothing else (no turn to wait for, no swap to hand on, nothing counted). Its surfaces were held since.
+ */
+void
+IOMobileFramebuffer::settle(const uint8_t * swap, MiniIOSurface ** surfaces)
+{
+ int32_t src[4], dst[4];
+
+ if (!fGraphics) {
+ return;
+ }
+ fSettling = true;
+ for (unsigned layer = 0; layer < SWAP_LAYERS; layer++) {
+ MiniIOSurface * s = surfaces[layer];
+
+ if (s == NULL || s->info.bytesPerElement != 4 || s->info.planeCount != 0) {
+ continue;
+ }
+ memcpy(src, swap + SWAP_SOURCE(layer), sizeof(src));
+ memcpy(dst, swap + SWAP_DEST(layer), sizeof(dst));
+ drawLayer(s, src, dst);
+ }
+ fSettling = false;
+ fStatSettled++;
+}
+
/* A swap's surfaces onto the panel, once the GPU is done with them. */
void
IOMobileFramebuffer::show(const uint8_t * swap, MiniIOSurface ** surfaces)
@@ -1213,10 +1296,10 @@ IOMobileFramebuffer::show(const uint8_t * swap, MiniIOSurface ** surfaces)
absolutetime_to_nanoseconds(fStatBeatWait, &beat);
IOLog("MiniIOMobileFramebuffer: %u frames in %llu ms (%llu a second), %llu us each in the driver, after %llu us "
"waiting for the GPU and, %u of them, %llu us for the next refresh; %u swaps waited for the frame before, "
- "%u gave up; %u swaps came a refresh late themselves\n", fStatFrames, nanos / NSEC_PER_MSEC,
+ "%u gave up; %u swaps came a refresh late themselves; %u frames drawn again filtered\n", fStatFrames, nanos / NSEC_PER_MSEC,
fStatFrames * NSEC_PER_SEC / nanos, drawing / fStatFrames / NSEC_PER_USEC,
waiting / fStatFrames / NSEC_PER_USEC, fStatOnBeat, fStatOnBeat ? beat / fStatOnBeat / NSEC_PER_USEC : 0,
- fStatHeld, fStatLost, fStatSwapsLate);
+ fStatHeld, fStatLost, fStatSwapsLate, fStatSettled);
fStatSwapsLate = 0;
for (different = 0; different < 8 && fStatSurfaces[different] != 0; different++) {
}
@@ -1232,7 +1315,7 @@ IOMobileFramebuffer::show(const uint8_t * swap, MiniIOSurface ** surfaces)
fStatSurfaces[4], made, making, again, freed, freeing);
}
bzero(fStatSurfaces, sizeof(fStatSurfaces));
- fStatHeld = fStatLost = fStatOnBeat = 0;
+ fStatHeld = fStatLost = fStatOnBeat = fStatSettled = 0;
fStatWaiting = fStatBeatWait = 0;
reportFrameTimes();
if (fDiff) {