🔇 Log each kext failure once a boot, its summaries once a minute

The kext logged a line per event on several paths a guest repeats every
frame, swap or surface: the control ring staying full, a command with no
answer, a surface block whose pages were not named or wired, a release
going on with its pages unnamed, a display transaction not sent, and the
IOMobileFramebuffer calls, which logged one in 1024 after their first 16.
A desktop that meets any of them fills the kernel's log, and the owner's
rule is one line per kind of degradation per boot.

Each such site now logs its first call of each kind alone (rgfxFirstCalls,
keyed by the site and its status, command type or reason where it has
several), the bring-up traces their first calls only, and the periodic
summaries (the control ring's room, the releases, the dormant blocks and
the arm64 swaps) come at most once a minute instead of every 1 to 10 s.
This commit is contained in:
Anees Iqbal committed 2026-11-11 04:55:49 -08:00
1 parent b270aa3611
commit beb91ccd4e
9 files changed
+164 -97

No files matched your search

+29 -11
View File
@@ -68,8 +68,9 @@ constexpr UInt32 kMaxDimension = kRgfxDisplayMaxDimension;
// How long a command waits for ring space, and then for its answer.
constexpr UInt32 kPostTimeoutMs = 5000;
constexpr UInt32 kAnswerTimeoutMs = 5000;
// How often the control ring's room line is logged at most, while posts sleep for room.
constexpr UInt32 kRoomLogMs = 1000;
// How often the control ring's room line is logged at most, while posts sleep for room: a summary,
// at most once a minute (docs/conventions.md).
constexpr UInt32 kRoomLogMs = 60000;
// Answers carry the device's status; a payload the driver cannot read is
// answered with this one.
@@ -289,7 +290,10 @@ IOReturn ReimsGraphics::post(UInt32 type, const void *message, UInt32 size, UInt
if (askForRoom() && tryPost(type, message, size, seqno, waiterSeqno))
return kIOReturnSuccess;
if (!waitForRoom(mark, deadline)) {
IOLog("ReimsGraphics: command %u: the control ring stayed full\n", type);
// Once per command type a boot: every post meets a ring that stays full.
static char site;
if (rgfxFirstCalls(&site, type, 1))
IOLog("ReimsGraphics: command %u: the control ring stayed full\n", type);
return ready ? kIOReturnTimeout : kIOReturnNotReady;
}
}
@@ -385,14 +389,19 @@ IOReturn ReimsGraphics::command(UInt32 type, const void *message, UInt32 size)
IOLockWakeup(stateLock, controlWaiters, false);
IOLockUnlock(stateLock);
// Once per command type, and status, a boot.
if (r == kIOReturnTimeout) {
IOLog("ReimsGraphics: command %u (seqno %llu): no answer\n", type, s);
static char unanswered;
if (rgfxFirstCalls(&unanswered, type, 1))
IOLog("ReimsGraphics: command %u (seqno %llu): no answer\n", type, s);
return kIOReturnTimeout;
}
if (r != kIOReturnSuccess)
return r;
if (status != 0) {
IOLog("ReimsGraphics: command %u (seqno %llu): status %u\n", type, s, status);
static char refused;
if (rgfxFirstCalls(&refused, (static_cast<UInt64>(type) << 32) | status, 1))
IOLog("ReimsGraphics: command %u (seqno %llu): status %u\n", type, s, status);
return kIOReturnError;
}
return kIOReturnSuccess;
@@ -453,7 +462,8 @@ IOReturn ReimsGraphics::postLifecycle(UInt32 type, const void *message, UInt32 s
w->seqno = 0;
IOLockWakeup(stateLock, lifecycleWaiters, false);
IOLockUnlock(stateLock);
if (r == kIOReturnTimeout)
static char unanswered;
if (r == kIOReturnTimeout && rgfxFirstCalls(&unanswered, type, 1))
IOLog("ReimsGraphics: lifecycle %u (seqno %llu): no answer\n", type, s);
if (seqno)
*seqno = s;
@@ -601,8 +611,11 @@ bool ReimsGraphics::drainEvents()
UInt64 end = load64(header + kRingProducer);
bool any = consumed != end;
while (consumed != end) {
static char outOfRange;
if (end - consumed > kRingBytes) {
IOLog("ReimsGraphics: the completion ring's producer is out of range; skipping to it\n");
if (rgfxFirstCalls(&outOfRange, 0, 1))
IOLog("ReimsGraphics: the completion ring's producer is out of range; skipping to "
"it\n");
consumed = end;
break;
}
@@ -622,8 +635,11 @@ bool ReimsGraphics::drainEvents()
continue;
}
if (size < kHeaderBytes || size % kMsgAlign || size > tail || size > end - consumed) {
IOLog("ReimsGraphics: malformed event (type %u, size %u); skipping the ring's contents\n",
type, size);
static char malformed;
if (rgfxFirstCalls(&malformed, type, 1))
IOLog("ReimsGraphics: malformed event (type %u, size %u); skipping the ring's "
"contents\n",
type, size);
consumed = end;
break;
}
@@ -2460,8 +2476,10 @@ IOReturn ReimsGraphics::postReleases(const RgfxBlockRelease *releases, UInt32 co
if (look() || (askForRoom() && look()))
break;
if (!waitForRoom(mark, deadline)) {
IOLog("ReimsGraphics: command %u: the control ring stayed full\n",
RGFX_CMD_BLOCK_RELEASE);
static char site;
if (rgfxFirstCalls(&site, 0, 1))
IOLog("ReimsGraphics: command %u: the control ring stayed full\n",
RGFX_CMD_BLOCK_RELEASE);
return ready ? kIOReturnTimeout : kIOReturnNotReady;
}
}
+3 -3
View File
@@ -608,10 +608,10 @@ private:
void *mobileSwapShowing;
IOInterruptEventSource *mobileSwapAnswer;
IOWorkLoop *mobileSwapLoop;
// What the swaps did over the second now running, logged once it is over (RgfxSwapRate.hpp),
// and a second in mach_absolute_time's ticks.
// What the swaps did over the minute now running, logged once it is over (RgfxSwapRate.hpp),
// and a minute in mach_absolute_time's ticks.
RgfxSwapRate mobileSwapRate;
UInt64 mobileSecond;
UInt64 mobileSwapRateWindow;
void noteMobileSwapRate(UInt64 now);
// The swap-info records notify_swap_done_gated keeps while the class holds them
// (RgfxLegacySwapInfo.hpp), in the class's gate.
+17 -16
View File
@@ -3,13 +3,14 @@
* drives (ReimsGraphics.hpp). The device, its rings, its display and its pipe clients are
* ReimsGraphics.cpp's, as on x86-64; this file is what the class asks of a subclass.
*
* Each override logs its calls (the first ones and then one in kLogEvery). The class queues the
* swaps a process submits, and swap_begin_gated takes them off its queue as Apple's paravirtual
* display does: the device presents a swap's layer-0 surface, and the swap completes once the host
* answers the present. The device's refreshes reach the class as its vblank note. Each completed
* swap's presentation time reaches WindowServer as frame info, which the paravirtual display has
* none of: supported_frame_info answers the tags the device fills, and a record of the swap goes to
* each notify request's client, through its shared data queue (RgfxLegacySwapInfo.hpp). The class's other pure methods answer what a display with no factory
* Each override logs its first calls (kLogFirst a boot), and the swaps a line a minute. The class
* queues the swaps a process submits, and swap_begin_gated takes them off its queue as Apple's
* paravirtual display does: the device presents a swap's layer-0 surface, and the swap completes
* once the host answers the present. The device's refreshes reach the class as its vblank note.
* Each completed swap's presentation time reaches WindowServer as frame info, which the paravirtual
* display has none of: supported_frame_info answers the tags the device fills, and a record of the
* swap goes to each notify request's client, through its shared data queue
* (RgfxLegacySwapInfo.hpp). The class's other pure methods answer what a display with no factory
* configuration and no CRC answers.
*
* None of the class's methods a subclass overrides is forwarded to the class: what the class
@@ -181,14 +182,14 @@ enum MobileCall : unsigned {
};
constexpr UInt32 kLogFirst = 16;
constexpr UInt32 kLogEvery = 1024;
UInt32 callCounts[kMobileCalls];
// Whether this call of `call` is one to log: the first kLogFirst, then one in kLogEvery.
// Whether this call of `call` is one to log: the first kLogFirst a boot, the bring-up's trace. A
// call that comes at every swap or vblank logs nothing after them (docs/conventions.md).
bool logged(MobileCall call)
{
const UInt32 n = __atomic_fetch_add(&callCounts[call], 1, __ATOMIC_RELAXED);
return n < kLogFirst || n % kLogEvery == 0;
return n < kLogFirst;
}
} // namespace
@@ -199,7 +200,7 @@ bool ReimsGraphics::startMobile()
mobileTransaction = 0;
mobileSwapShowing = nullptr;
mobileSwapRate.clear();
mobileSecond = 0;
mobileSwapRateWindow = 0;
mobileShownAt = 0;
mobileShownPeriod = 0;
mobilePresentedAt = 0;
@@ -758,14 +759,14 @@ bool ReimsGraphics::postMobileCursorMove(int32_t x, int32_t y, bool visible)
return true;
}
// The line of the second of swaps just over, once a swap comes after it: none while the display
// is idle.
// The line of the minute of swaps just over, once a swap comes after it: none while the display
// is idle. A summary, at most once a minute (docs/conventions.md).
void ReimsGraphics::noteMobileSwapRate(UInt64 now)
{
if (!mobileSecond)
nanoseconds_to_absolutetime(1000000000ull, &mobileSecond);
if (!mobileSwapRateWindow)
nanoseconds_to_absolutetime(60000000000ull, &mobileSwapRateWindow);
const RgfxSwapRate &r = mobileSwapRate;
if (!r.due(now, mobileSecond))
if (!r.due(now, mobileSwapRateWindow))
return;
uint64_t ns = 0;
absolutetime_to_nanoseconds(now - r.start, &ns);
+28 -14
View File
@@ -58,6 +58,7 @@
#include "RgfxLatency.hpp"
#include "RgfxPagesBlock.hpp"
#include "RgfxIdChunks.hpp"
#include "RgfxTrace.hpp"
#include "RgfxReleaseTable.hpp"
#include <IOKit/IOLib.h>
@@ -93,14 +94,15 @@ constexpr UInt32 kReleaseAnswerMs = 10000;
constexpr UInt64 kPage = 0x1000;
// The guest's memory where hw.memsize gives none, for the dormant blocks' cap of bytes.
constexpr UInt64 kDormantMemoryUnknown = 2ull << 30;
// How often the dormant blocks' line is logged at most, and how long a new block waits for
// dormant blocks' releases to give the region room for it.
constexpr UInt32 kDormantLogMs = 10000;
// How often the dormant blocks' line is logged at most, a summary, once a minute
// (docs/conventions.md), and how long a new block waits for dormant blocks' releases to give the
// region room for it.
constexpr UInt32 kDormantLogMs = 60000;
constexpr UInt32 kDormantRoomMs = 100;
// How many dormant blocks a new block that finds no room in the region lets go.
constexpr UInt32 kDormantRoomBlocks = 16;
// How often the releases' line is logged at most.
constexpr UInt32 kReleaseLogMs = 10000;
// How often the releases' line is logged at most: a summary, once a minute.
constexpr UInt32 kReleaseLogMs = 60000;
// The most BLOCK_RELEASEs in flight at once (RgfxReleaseTable.hpp): 40 bytes each on ring 0,
// under a third of its 32 KiB.
constexpr UInt32 kMaxReleases = 256;
@@ -1414,7 +1416,9 @@ bool letGoBlock(RgfxSurfaceEntry &e, UInt32 context, bool keep, void *wired = nu
*kept = ownedWire;
// Never given back to the guest while the host may map it: kept for good where the block
// cannot hold it.
if (hostPages && !rgfxBlockSetWired(blockTable, e.offset, hostPages))
static char wiredForGood;
if (hostPages && !rgfxBlockSetWired(blockTable, e.offset, hostPages) &&
rgfxFirstCalls(&wiredForGood, 0, 1))
IOLog("RgfxAccelerator: the deferred block 0x%llx's pages stay wired for good: its block "
"is gone\n",
e.offset);
@@ -2312,7 +2316,10 @@ bool RgfxAccelerator::deferSurfaceBlock(RgfxSurfaceEntry &e, UInt32 context, uin
dormantStats.deferred += r == kIOReturnSuccess;
dormantStats.changes++;
IOLockUnlock(contextLock);
if (r != kIOReturnSuccess)
// Once per kind a boot: a surface's every block meets the same cause.
static char unanswered;
if (r != kIOReturnSuccess &&
rgfxFirstCalls(&unanswered, (static_cast<UInt64>(r) << 32) | status, 1))
IOLog("RgfxAccelerator: the deferred block 0x%llx was not answered (0x%x, status "
"%u): it goes\n",
offset, r, status);
@@ -2361,7 +2368,8 @@ bool RgfxAccelerator::deferSurfaceBlock(RgfxSurfaceEntry &e, UInt32 context, uin
e.holds[0].pages = memory;
const bool held = e.holdCount != 0;
IOLockUnlock(contextLock);
if (!held)
static char unheld;
if (!held && rgfxFirstCalls(&unheld, 0, 1))
IOLog("RgfxAccelerator: the block 0x%llx's pages stay wired for good: no hold to "
"keep them\n",
offset);
@@ -2433,8 +2441,10 @@ RgfxPagesNaming RgfxAccelerator::attachSurfacePages(UInt32 context, UInt64 offse
why = "they were not answered, and stay wired until the block's release is answered";
}
if (naming != kRgfxPagesNamed) {
IOLog("RgfxAccelerator: the block 0x%llx's pages (flags 0x%x) were not named: %s\n",
offset, flags, why);
static char unnamed;
if (rgfxFirstCalls(&unnamed, rgfxKeyOf(why), 1))
IOLog("RgfxAccelerator: the block 0x%llx's pages (flags 0x%x) were not named: %s\n",
offset, flags, why);
freeRuns(runs, count);
// The host may yet take pages it did not answer for: those stay wired.
if (!rgfxPagesNamingWired(naming))
@@ -2471,9 +2481,11 @@ bool RgfxAccelerator::postSurfacePages(UInt32 context, UInt64 offset, UInt64 tot
UInt32 *status)
{
if (!writeRuns(region, offset + rgfxSurfaceRunsFrom(size), runs, count)) {
IOLog("RgfxAccelerator: the block 0x%llx's runs could not be written: its surface is "
"copied\n",
offset);
static char unwritten;
if (rgfxFirstCalls(&unwritten, 0, 1))
IOLog("RgfxAccelerator: the block 0x%llx's runs could not be written: its surface is "
"copied\n",
offset);
return false;
}
const UInt32 flags = cached ? RGFX_SURFACE_PAGES_CACHED
@@ -2481,7 +2493,9 @@ bool RgfxAccelerator::postSurfacePages(UInt32 context, UInt64 offset, UInt64 tot
: 0;
IOReturn r = postPages(context, offset, total, offset + rgfxSurfaceRunsFrom(size), length,
count, flags, status, layout);
if (r != kIOReturnSuccess && r != kIOReturnUnsupported)
static char unanswered;
if (r != kIOReturnSuccess && r != kIOReturnUnsupported &&
rgfxFirstCalls(&unanswered, static_cast<UInt32>(r), 1))
IOLog("RgfxAccelerator: the block 0x%llx's pages were not answered (0x%x): its surface "
"is copied\n",
offset, r);
+48 -29
View File
@@ -73,6 +73,7 @@
#include "RgfxIOSurfaceKPI.hpp"
#include "RgfxSurfaceCaches.hpp"
#include "RgfxSurfaceLocks.hpp"
#include "RgfxTrace.hpp"
#include <IOKit/IOBufferMemoryDescriptor.h>
#include <IOKit/IOLib.h>
@@ -101,10 +102,10 @@ constexpr UInt32 kMaxCached = kRgfxCachedMaxSurfaces;
// How many device caches made are logged, with what IOSurface answered, and how many writes
// named of surfaces the kext cannot follow.
constexpr UInt32 kCachesLogged = 4;
constexpr UInt32 kSkipsLogged = 8;
// How many surfaces left uncached for want of room are logged one by one; the dormancy line
// counts them all.
constexpr UInt32 kNoRoomLogged = 4;
constexpr UInt32 kSkipsLogged = 1;
// How many surfaces left uncached for want of room are logged one by one: one a boot, as for
// every degradation (docs/conventions.md); the dormancy line counts them all.
constexpr UInt32 kNoRoomLogged = 1;
// One initialised object (it lands in __DATA,__data, as the contexts' state does), made at the
// first write named and kept for the kernel's life.
@@ -130,7 +131,7 @@ struct LockState {
// sleep on `table` for these too.
RgfxCacheTable caches;
// Under `lock`: surfaces left uncached as the table had no room, the first kNoRoomLogged
// logged.
// logged one by one.
uint64_t noRoom;
// Under `lock`: the releases posted unheld (RGFX_BLOCK_RELEASE_UNHELD) whose surface a
// process took again before their answer (rgfxCacheRetaken), counted at the answer.
@@ -509,8 +510,10 @@ void surfaceControl(void *accelerator, RgfxDeviceCache *cache, uint32_t op, uint
}
}
IOLockUnlock(state.lock);
if (waitedFor) {
// How long the lock waited, whatever it waited for.
// How long the lock waited, whatever it waited for: once a boot per what it waited for
// (docs/conventions.md).
static char wentOn;
if (waitedFor && rgfxFirstCalls(&wentOn, rgfxKeyOf(waitedFor), 1)) {
const uint64_t waitedMs = msSince(start);
char name[64] = {};
proc_selfname(name, sizeof(name));
@@ -533,24 +536,29 @@ bool rgfxSurfaceLocksAttach(RgfxAccelerator *accel, task_t task, uint32_t surfac
if (!startRoot(accel))
return false;
OSObject *surface = rgfxIOSurfaceRootLookupSurface(state.root, surfaceId, task);
// Each refusal below is logged once a boot (docs/conventions.md).
static char refused;
if (!surface) {
IOLog("RgfxAccelerator: IOSurface %u is not the naming process's: its locks wait for no "
"GPU write\n",
surfaceId);
if (rgfxFirstCalls(&refused, 0, 1))
IOLog("RgfxAccelerator: IOSurface %u is not the naming process's: its locks wait for "
"no GPU write\n",
surfaceId);
return false;
}
if (!isSurface(surface) || !surfaceHolds(surface, phys)) {
IOLog("RgfxAccelerator: IOSurface %u is not its shared block's surface: its locks wait "
"for no GPU write\n",
surfaceId);
if (rgfxFirstCalls(&refused, 1, 1))
IOLog("RgfxAccelerator: IOSurface %u is not its shared block's surface: its locks "
"wait for no GPU write\n",
surfaceId);
surface->release();
return false;
}
RgfxDeviceCache *cache = rgfxIOSurfaceDeviceCache(surface, accel, state.acceleratorId, 0);
if (!cache) {
IOLog("RgfxAccelerator: IOSurface %u gave no device cache: its locks wait for no GPU "
"write\n",
surfaceId);
if (rgfxFirstCalls(&refused, 2, 1))
IOLog("RgfxAccelerator: IOSurface %u gave no device cache: its locks wait for no "
"GPU write\n",
surfaceId);
surface->release();
return false;
}
@@ -837,10 +845,12 @@ RgfxDeferAnswer rgfxSurfaceLocksDefer(RgfxAccelerator *accel, OSObject *surface,
if (!memory || !startLocks())
return kRgfxDeferNoCache;
RgfxDeviceCache *cache = rgfxIOSurfaceDeviceCache(surface, accel, state.acceleratorId, 0);
static char notDeferred;
if (!cache) {
IOLog("RgfxAccelerator: IOSurface %u gave no device cache: its block is not deferred, "
"nor cached\n",
surfaceId);
if (rgfxFirstCalls(&notDeferred, 0, 1))
IOLog("RgfxAccelerator: IOSurface %u gave no device cache: its block is not "
"deferred, nor cached\n",
surfaceId);
return kRgfxDeferNoCache;
}
// The surface's memory, retained, not wired: its pages are named only where a lock needs them.
@@ -880,10 +890,11 @@ RgfxDeferAnswer rgfxSurfaceLocksDefer(RgfxAccelerator *accel, OSObject *surface,
}
IOLockUnlock(state.lock);
if (!c) {
IOLog("RgfxAccelerator: IOSurface %u: %s: its block is not deferred, nor cached\n",
surfaceId,
previous ? "its previous block is cached still, its release unanswered"
: "no room for its device cache's state");
if (rgfxFirstCalls(&notDeferred, previous ? 1 : 2, 1))
IOLog("RgfxAccelerator: IOSurface %u: %s: its block is not deferred, nor cached\n",
surfaceId,
previous ? "its previous block is cached still, its release unanswered"
: "no room for its device cache's state");
memory->release();
reinterpret_cast<OSObject *>(cache)->release();
return kRgfxDeferNoCache;
@@ -1024,7 +1035,8 @@ RgfxReleaseAttach rgfxSurfaceCacheReleaseAttach(RgfxAccelerator *accel, UInt64 o
if (!named && !hostPages && c != nullptr && attachBackoff(++tries, deadline))
continue;
did = hostPages ? kRgfxReleaseAttached : kRgfxReleaseUnattached;
if (!named && !hostPages)
static char unnamed;
if (!named && !hostPages && rgfxFirstCalls(&unnamed, 0, 1))
IOLog("RGFX: WARN: the release of IOSurface %u's deferred block 0x%llx goes on "
"after %u ms with its pages not named: what the GPU wrote is not copied "
"into them\n",
@@ -1061,9 +1073,11 @@ IOMemoryDescriptor *rgfxSurfaceCacheHostPages(void *cache, UInt64 offset)
memory->retain();
IOLockUnlock(state.lock);
if (memory && memory->prepare(kIODirectionOutIn) != kIOReturnSuccess) {
IOLog("RgfxAccelerator: the deferred block 0x%llx's pages could not be wired for its "
"block\n",
offset);
static char unwired;
if (rgfxFirstCalls(&unwired, 0, 1))
IOLog("RgfxAccelerator: the deferred block 0x%llx's pages could not be wired for "
"its block\n",
offset);
OSSafeReleaseNULL(memory);
}
return memory;
@@ -1133,8 +1147,11 @@ bool rgfxSurfaceCacheAdd(void *cache, void *surface, UInt64 offset, uint32_t sur
IOMemoryDescriptor *wire =
OSDynamicCast(IOMemoryDescriptor, rgfxIOSurfaceMemory(static_cast<OSObject *>(surface)));
if (!wire || wire->prepare(kIODirectionOutIn) != kIOReturnSuccess) {
IOLog("RgfxAccelerator: IOSurface %u: its memory could not be wired: it is not cached\n",
surfaceId);
static char unwired;
if (rgfxFirstCalls(&unwired, 0, 1))
IOLog("RgfxAccelerator: IOSurface %u: its memory could not be wired: it is not "
"cached\n",
surfaceId);
return false;
}
wire->retain();
@@ -1155,8 +1172,10 @@ bool rgfxSurfaceCacheAdd(void *cache, void *surface, UInt64 offset, uint32_t sur
const char *why = nullptr;
RgfxCachedSurface *c = nullptr;
bool logged = true;
static char previousCached;
if (rgfxCacheFind(state.caches, key)) {
why = "its previous block is cached still, its release unanswered";
logged = rgfxFirstCalls(&previousCached, 0, 1);
} else if (!(c = rgfxCacheAdd(state.caches, key, offset, surfaceId))) {
why = "no room for its device cache's state";
logged = ++state.noRoom <= kNoRoomLogged;
+6 -2
View File
@@ -270,13 +270,17 @@ IOReturn RgfxAcceleratorUserClient::externalMethod(uint32_t selector,
IOExternalMethod *RgfxAcceleratorUserClient::getTargetAndMethodForIndex(IOService **targetP,
UInt32 index)
{
IOLog("RGFX: getTargetAndMethodForIndex index=%u\n", index);
static char site; // once a boot per index
if (rgfxFirstCalls(&site, index, 1))
IOLog("RGFX: getTargetAndMethodForIndex index=%u\n", index);
return super::getTargetAndMethodForIndex(targetP, index);
}
IOExternalTrap *RgfxAcceleratorUserClient::getTargetAndTrapForIndex(IOService **targetP,
UInt32 index)
{
IOLog("RGFX: getTargetAndTrapForIndex index=%u\n", index);
static char site; // once a boot per index
if (rgfxFirstCalls(&site, index, 1))
IOLog("RGFX: getTargetAndTrapForIndex index=%u\n", index);
return super::getTargetAndTrapForIndex(targetP, index);
}
+20 -13
View File
@@ -9,6 +9,7 @@
#include "RgfxAccelerator.hpp"
#include "RgfxPipeColor.hpp"
#include "RgfxPipeNotifications.hpp"
#include "RgfxTrace.hpp"
#include <IOKit/IOLib.h>
#include <IOKit/IOMemoryDescriptor.h>
@@ -56,14 +57,12 @@ const char *const kEntitlement = "com.apple.private.hid.client.event-monitor";
// The accelerator id the association returns: our one accelerator.
constexpr UInt64 kAcceleratorId = 1;
// The calls logged in full (sizes, the registrations' and transactions' fields); after that,
// every 600th transaction.
// The calls logged in full (sizes, the registrations' and transactions' fields), the first a boot:
// a transaction comes at every frame, so none after them is logged (docs/conventions.md).
constexpr UInt32 kLogFirst = 48;
constexpr UInt32 kLogEvery = 600;
// The transactions with no cookie logged, per client.
constexpr UInt32 kLogUnnotified = 8;
// The colour calls logged in full (header fields, first and last entries), per client; after
// that, every kLogEvery-th.
// The colour calls logged in full (header fields, first and last entries), per client.
constexpr UInt32 kLogColor = 32;
inline UInt32 rd32(const UInt8 *p, UInt32 off)
@@ -379,8 +378,10 @@ IOReturn RgfxDisplayPipeUserClient::sRequestNotify(OSObject *target, void *,
}
return kIOReturnSuccess;
}
IOLog("RGFX pipe: notify kind %u: %016llx %016llx %016llx\n", kind, rd64(in, 0), rd64(in, 8),
rd64(in, 16));
static char notifySite;
if (rgfxFirstCalls(&notifySite, kind, 1))
IOLog("RGFX pipe: notify kind %u: %016llx %016llx %016llx\n", kind, rd64(in, 0),
rd64(in, 8), rd64(in, 16));
IOLockLock(self->lock);
if (self->registered) {
IOLockUnlock(self->lock);
@@ -483,7 +484,7 @@ IOReturn RgfxDisplayPipeUserClient::sGamma(OSObject *target, void *, IOExternalM
self->staged[slot] = {entries, args.count, true};
entries = nullptr;
}
const bool log = self->colorLogged < kLogColor || (begun && begun % kLogEvery == 0);
const bool log = self->colorLogged < kLogColor;
if (self->colorLogged < kLogColor)
self->colorLogged++;
IOLockUnlock(self->lock);
@@ -543,7 +544,7 @@ IOReturn RgfxDisplayPipeUserClient::sSubmit(OSObject *target, void *, IOExternal
UInt32 planeType = rd32(t, kTxnPlane0 + kPlaneType);
UInt32 surface = rd32(t, kTxnPlane0 + kPlaneSurface);
UInt64 cookie = rd64(t, kTxnCookie);
bool log = id <= kLogFirst / 4 || id % kLogEvery == 0;
bool log = id <= kLogFirst / 4;
if (log) {
UInt64 dirty = rd64(t, kTxnDirty);
// The time asked for, in microseconds from now (0 where it asks for none).
@@ -577,7 +578,9 @@ IOReturn RgfxDisplayPipeUserClient::submit(const UInt8 *t, UInt32 id, UInt32 pla
if (IOLockSleepDeadline(lock, &completed, deadline, THREAD_UNINT) == THREAD_TIMED_OUT &&
!transactions.hasRoom()) {
IOLockUnlock(lock);
IOLog("RGFX pipe: transaction %u: no room in 5 s, not sent\n", id);
static char site;
if (rgfxFirstCalls(&site, 0, 1))
IOLog("RGFX pipe: transaction %u: no room in 5 s, not sent\n", id);
return kIOReturnTimeout;
}
}
@@ -610,7 +613,9 @@ IOReturn RgfxDisplayPipeUserClient::post(const UInt8 *t, UInt32 id, UInt32 plane
if (displayColor) {
const IOReturn c = postColor(t, id, &colored);
if (c != kIOReturnSuccess) {
IOLog("RGFX pipe: transaction %u: its colour not sent: 0x%x\n", id, c);
static char site;
if (rgfxFirstCalls(&site, static_cast<UInt32>(c), 1))
IOLog("RGFX pipe: transaction %u: its colour not sent: 0x%x\n", id, c);
return c;
}
}
@@ -656,7 +661,9 @@ IOReturn RgfxDisplayPipeUserClient::post(const UInt8 *t, UInt32 id, UInt32 plane
}
if (r != kIOReturnSuccess) {
IOLockUnlock(lock);
IOLog("RGFX pipe: transaction %u: PRESENT_SURFACE not sent: 0x%x\n", id, r);
static char site;
if (rgfxFirstCalls(&site, static_cast<UInt32>(r), 1))
IOLog("RGFX pipe: transaction %u: PRESENT_SURFACE not sent: 0x%x\n", id, r);
return r;
}
// Done at the host's answer: the display shows its surface, or its colour, from then.
@@ -694,7 +701,7 @@ IOReturn RgfxDisplayPipeUserClient::postColor(const UInt8 *t, UInt32 id, bool *s
r = framebuffer->postDisplayColor(id, RGFX_COLOR_MATRIX, kRgfxMatrixRows,
t + kRgfxTxnMatrix);
*sent = true;
if (colorLogged < kLogColor || id % kLogEvery == 0) {
if (colorLogged < kLogColor) {
colorLogged += colorLogged < kLogColor ? 1 : 0;
IOLog("RGFX pipe: transaction %u: colour matrix %08x %08x %08x %08x / %08x %08x %08x "
"%08x / %08x %08x %08x %08x\n",
+4 -1
View File
@@ -7,6 +7,7 @@
#include "RgfxAccelerator.hpp"
#include "RgfxAcceleratorUserClient.hpp"
#include "RgfxTrace.hpp"
#include "RgfxUserClientABI.hpp"
#include <IOKit/IOLib.h>
@@ -216,6 +217,8 @@ void RgfxAccelerator::unnameSharedEvent(UInt64 name)
RgfxSharedEventUnname m = rgfxSharedEventUnnameMessage(name);
IOReturn r = postLifecycle(RGFX_CMD_SHARED_EVENT_UNNAME, &m, sizeof(m), 0, nullptr, 0, nullptr,
nullptr, 0);
if (r != kIOReturnSuccess)
// Once a boot per status (docs/conventions.md).
static char site;
if (r != kIOReturnSuccess && rgfxFirstCalls(&site, static_cast<UInt32>(r), 1))
IOLog("RGFX: shared event name %llu: its unname was not posted (0x%x)\n", name, r);
}
+9 -8
View File
@@ -1,8 +1,9 @@
// RgfxSwapRate: what an arm64 display's swaps did over each second they ran, for one log line a
// second while swaps happen and none while the display is idle: the swaps begun, completed and
// dropped, those with no present, the distinct layer-0 surfaces shown with their counts, and the
// swaps with a layer-1 surface, which is not shown. It tells a log reader the swap rate while an
// app runs and whether the app's own surface reaches a swap. Header-only and free of the
// RgfxSwapRate: what an arm64 display's swaps did over each window they ran (the caller's
// length, a minute), for one log line a window while swaps happen and none while the display is
// idle: the swaps begun, completed and dropped, those with no present, the distinct layer-0
// surfaces shown with their counts, and the swaps with a layer-1 surface, which is not shown. It
// tells a log reader the swap rate while an app runs and whether the app's own surface reaches a
// swap. Header-only and free of the
// kernel's headers, so its native test (tests/swap_rate_test.cpp) builds it as the kext does.
// The caller holds the display's gate around every call.
//
@@ -66,9 +67,9 @@ struct RgfxSwapRate {
touch(now);
dropped++;
}
// Whether the window is a second old or more at `now`, a second being `second` ticks: its
// line is then due, and the caller logs it and clears the window.
bool due(uint64_t now, uint64_t second) const { return start && now - start >= second; }
// Whether the window is `length` ticks old or more at `now`: its line is then due, and the
// caller logs it and clears the window.
bool due(uint64_t now, uint64_t length) const { return start && now - start >= length; }
void clear() { *this = RgfxSwapRate(); }
};