WindowServer drives the display pipe in the transactional model while
kIOWindowServerActiveAttribute carries kIOWSAA_Transactional ('wsrv'
0x80000013 at its start, then 0x11). When its session restarts it hands the
display back to the CPU ('wsrv' 0x2) and submits the shutdown's frames, each
with cookie 0 at +0x100, waiting on each with selector 9 before it exits. The
kext notified every completion. On a macOS 26 guest, WindowServer aborted in
IOAccelerator's _ioAccelDisplayPipeTransactionNotifyCallback about 5 ms after
the kext sent the notification of the first cookie-less transaction, and the
session's next WindowServer started over it.
The cookie is the transaction's own sign that a notification is wanted. The
pipe now notifies a completion only where its transaction carries a cookie;
every transaction still completes for its waiters and for the display. The
bookkeeping moves into RgfxPipeTransactions.hpp, with a native test that
replays the hand-over's order.
Measured on a cold boot of the x86 guest with the same rule keyed to 'wsrv'
instead of the cookie, which notifies the same transactions on every one
measured: 4469 transactions over three hand-overs (a reboot, a logout and a
loginwindow death). All 4461 submitted in the model carried a cookie and were
notified; each hand-over's 4 shutdown frames carried none and were not. Each
WindowServer then exits with exit(0) and no crash report, every wait returns
(26 ms at most), and the next WindowServer enters the model and composites
with Metal.
108 lines
5.0 KiB
C++
108 lines
5.0 KiB
C++
/*
|
|
* RgfxDisplayPipeUserClient: the display pipe WindowServer presents through, user-client type 4
|
|
* on the accelerator. IOAccelerator.framework's IOAccelDisplayPipeCreate, which IOPresentment
|
|
* calls for each framebuffer naming an accelerator (IOAccelIndex), opens this type and drives
|
|
* the display-pipe interface macOS's IOAccelerator.framework speaks: associate a framebuffer
|
|
* index, read the pipe's capabilities, register for VBL and transaction notifications, and
|
|
* begin, submit and wait for transactions, each of which names the IOSurfaces the display
|
|
* shows (docs/graphics-kext/design.md, "Compositor/present").
|
|
*
|
|
* The selectors, their argument counts and sizes are the interface's:
|
|
* 0 associate(framebuffer index) -> accelerator id scalar 1 / scalar 1
|
|
* 1 mode scaler struct out 24: unsupported
|
|
* 2 capabilities, a serialized dictionary struct out variable
|
|
* 3 notification registration (VBL or transaction) struct in 24, asynchronous
|
|
* 4 begin a transaction -> its id scalar out 1
|
|
* 7 (no arguments) accepted, logged
|
|
* 8 submit a transaction struct in 280
|
|
* 9 wait for a transaction struct in 12
|
|
* Every other selector is refused as unsupported and logged.
|
|
*
|
|
* A submitted transaction's plane 0, where it is an IOSurface, goes to the host on the control
|
|
* ring as PRESENT_SURFACE through the framebuffer (ReimsGraphics owns that ring), and submit
|
|
* returns at once. The transaction completes when the host answers that PRESENT_SURFACE, which
|
|
* it does once the display shows the surface: a waiter returns, and its completion notification
|
|
* goes out where it carries a cookie (RgfxPipeTransactions.hpp). An answer completes every
|
|
* transaction submitted before it, oldest first. At most two are outstanding; a third submit
|
|
* waits up to five seconds for room, then fails unsent. A transaction with no IOSurface on
|
|
* plane 0 keeps the surface shown and completes with the one before it, or at once. VBL
|
|
* notifications follow the device's VBLANK events while one is registered.
|
|
*
|
|
* Our own code; it names only SDK-public IOKit classes.
|
|
*/
|
|
|
|
#ifndef RGFX_DISPLAY_PIPE_USER_CLIENT_HPP_
|
|
#define RGFX_DISPLAY_PIPE_USER_CLIENT_HPP_
|
|
|
|
#include <IOKit/IOLocks.h>
|
|
#include <IOKit/IOUserClient.h>
|
|
|
|
#include "RgfxPipeTransactions.hpp"
|
|
|
|
class RgfxAccelerator;
|
|
class ReimsGraphics;
|
|
|
|
// The user-client type IOAccelDisplayPipeCreate opens.
|
|
static const UInt32 kRgfxDisplayPipeUserClientType = 4;
|
|
|
|
class RgfxDisplayPipeUserClient : public IOUserClient {
|
|
OSDeclareDefaultStructors(RgfxDisplayPipeUserClient);
|
|
|
|
public:
|
|
bool initWithTask(task_t owningTask, void *securityID, UInt32 type,
|
|
OSDictionary *properties) override;
|
|
bool start(IOService *provider) override;
|
|
void stop(IOService *provider) override;
|
|
IOReturn clientClose() override;
|
|
void free() override;
|
|
|
|
IOReturn externalMethod(uint32_t selector, IOExternalMethodArguments *arguments,
|
|
IOExternalMethodDispatch *dispatch, OSObject *target,
|
|
void *reference) override;
|
|
|
|
private:
|
|
// The registrations a client keeps (selector 3's kinds).
|
|
enum { kKindVbl = 0, kKindTransaction = 1, kKinds = 2 };
|
|
// The transactions submitted to the host and not yet answered.
|
|
enum { kMaxOutstanding = 2 };
|
|
typedef RgfxPipeTransactions<kMaxOutstanding> Transactions;
|
|
|
|
static IOReturn sAssociate(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
static IOReturn sModeScaler(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
static IOReturn sCapabilities(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
static IOReturn sRequestNotify(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
static IOReturn sBegin(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
static IOReturn sSeven(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
static IOReturn sSubmit(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
static IOReturn sWait(OSObject *target, void *reference, IOExternalMethodArguments *a);
|
|
|
|
// The framebuffer's hooks (ReimsGraphics::addPipe), on its work loop.
|
|
static void vblankHook(OSObject *client, UInt64 count, UInt64 time);
|
|
static void presentHook(OSObject *client, UInt64 seqno, UInt32 status);
|
|
void presented(UInt64 seqno, UInt32 status);
|
|
void completeLocked(const Transactions::Completion &c, UInt64 time);
|
|
void sendVbl(UInt64 count, UInt64 time);
|
|
|
|
void releaseRegistrations();
|
|
|
|
task_t task;
|
|
RgfxAccelerator *owner;
|
|
ReimsGraphics *framebuffer; // retained once associated
|
|
bool associated;
|
|
|
|
// Under lock: the registrations, the transaction begun and the last completed.
|
|
IOLock *lock;
|
|
bool registered[kKinds];
|
|
OSAsyncReference64 references[kKinds];
|
|
UInt64 cookies[kKinds];
|
|
UInt32 nextTransaction;
|
|
UInt32 begun;
|
|
UInt32 completed;
|
|
UInt64 lastVblTime;
|
|
UInt32 logged;
|
|
UInt32 unnotifiedLogged;
|
|
Transactions transactions;
|
|
};
|
|
|
|
#endif // RGFX_DISPLAY_PIPE_USER_CLIENT_HPP_
|