From cd1b9757fd5d730bf85aabb37a4bce729ede9e58 Mon Sep 17 00:00:00 2001 From: bluseliu50 <265648257+bluseliu50@users.noreply.github.com> Date: Mon, 26 Oct 2026 00:59:46 +0800 Subject: [PATCH] perf(turnip): wait for a fence up to 100 ms a call The Darwin KMD waited in 1 ms slices: i553 made 258682 fence waits in 166 s and 97 % timed out. The kernel already idles until the next GPU interrupt inside a wait, so a call now waits up to 100 ms or the caller's deadline. --- patches/mesa/turnip-darwin-kmd.patch | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/patches/mesa/turnip-darwin-kmd.patch b/patches/mesa/turnip-darwin-kmd.patch index aeaab9d..1ef82a0 100644 --- a/patches/mesa/turnip-darwin-kmd.patch +++ b/patches/mesa/turnip-darwin-kmd.patch @@ -271,7 +271,7 @@ new file mode 100644 index 0000000..b03c6ee --- /dev/null +++ b/src/freedreno/vulkan/tu_knl_darwin.cc -@@ -0,0 +1,1110 @@ +@@ -0,0 +1,1112 @@ +/* + * Native Darwin kernel backend for Turnip: talks to the NativeAdreno IOKit user client (NativeAdrenoABI.h, version 1). + * Modelled on tu_knl_kgsl.cc (no libdrm) and tu_knl_drm_msm.cc (the client chooses GPU addresses). @@ -450,9 +450,11 @@ index 0000000..b03c6ee +{ + for (;;) { + uint64_t now = os_time_get_nano(); -+ uint64_t slice = 1000000; /* 1 ms */ -+ if (abs_timeout_ns != UINT64_MAX && abs_timeout_ns <= now) -+ slice = 0; ++ /* The rest of the wait, at most 100 ms a call: the kernel sleeps between fence interrupts until the fence or the ++ * timeout. One 1 ms slice a call made a frame's wait several IOKit calls (i553: 258682 waits in 166 s, 97 % timed out). */ ++ uint64_t slice = 100000000; /* 100 ms */ ++ if (abs_timeout_ns != UINT64_MAX) ++ slice = abs_timeout_ns > now ? MIN2(abs_timeout_ns - now, slice) : 0; + NativeAdrenoAbiWaitFence req = {.fence = fence, .timeout_ns = slice}; + kern_return_t kr = dw_call(NativeAdrenoMethodWaitFence, &req, sizeof(req), NULL, 0); + if (kr == KERN_SUCCESS)