From e82a9583d38ea0eda8ab81ed13bf6c4d5fc1083f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 27 Nov 2026 19:00:11 +1100 Subject: [PATCH 1/2] drm/asahi: g17: let every GPU coprocessor follow the RTKit OSLOG echo The G17 driver turned the RTKit OSLOG counter echo off on every GPU coprocessor, because the T8140 and T8142 GPU firmware had only run with its counters unanswered. That is not a property of the hardware or the firmware: the echo is the OSLOG protocol of every RTKit firmware that sends counters. A firmware that uses it holds the next counter until the last is echoed and takes no AP power notice while one is outstanding; a firmware that does not use it sends no counters, so the echo never goes out. Drop the set_oslog_echo(false) call, so the GPU coprocessors follow the RTKit default like every other RTKit client. On T8140 and T8142, where RTKit starts with the echo on, the GPU counters are now echoed instead of dropped. On T6040, T6041 and T6050 nothing changes on the wire: an admitted counter was already acknowledged with the same message (the exact counter on endpoint 8) by the non-echo path. Signed-off-by: Ryan Murray --- drivers/gpu/drm/asahi/g17/mod.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/mod.rs b/drivers/gpu/drm/asahi/g17/mod.rs index f30bdc97d0b47..a3971503aab55 100644 --- a/drivers/gpu/drm/asahi/g17/mod.rs +++ b/drivers/gpu/drm/asahi/g17/mod.rs @@ -630,11 +630,7 @@ impl Coprocessor { ) -> Result> { for attempt in 0..RECEIVER_ATTEMPTS { match rtkit::RtKit::::new(dev.as_ref().as_ref(), None, index, state.clone()) { - Ok(receiver) => { - // Its OSLOG counters stay unanswered until a soak shows echoing them is safe. - receiver.set_oslog_echo(false); - return Ok(receiver); - } + Ok(receiver) => return Ok(receiver), Err(error) if error == EINVAL || error == ETIMEDOUT => { if attempt + 1 < RECEIVER_ATTEMPTS { fsleep(Delta::from_millis(RECEIVER_RETRY_MS)); From f6fac68b799abda133cf450032d168b3b02cdfa5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Fri, 27 Nov 2026 19:05:04 +1100 Subject: [PATCH 2/2] soc: apple: rtkit: Echo OSLOG counters on every RTKit, not by machine The OSLOG counter echo was chosen by machine: rtk->oslog_echo was set only when the machine is apple,t8140 or apple,t8142. With the echo off, a counter was dropped on those two machines (and on a node with apple,sync-syslog-ack) by apple_rtkit_oslog_unanswered(), but acknowledged after a buffer/channel check on every other one by apple_rtkit_oslog_echoed(). The echo is RTKit protocol behaviour, not a SoC property. The IOP sends nothing at OSLOG setup that tells the two apart: its endpoint carries a buffer request (size and IOVA), channel-zero counters and the opaque types 3-5, and the management HELLO advertises protocol 11-12 on every generation. A firmware that uses the counter protocol sends counters and holds the next one until the last is echoed; one that does not sends none, so the echo never goes out. The acknowledgment that every non-T814x RTKit has sent since commit 1369d18b4ec7 ("soc: apple: acknowledge OSLog progress in negotiated and inherited sessions") is the same message (the exact counter on endpoint 8), so M1- to M5-era firmware already gets it. So echo every channel-zero counter by default, on every RTKit. The off state keeps one meaning everywhere: the counter is dropped. It is off on a node with apple,sync-syslog-ack (the T8122 dcpext, which has only run with its counters unanswered; a DCP driver that restarts its DCP across a sleep turns it back on as before) and where a client turns it off. Both machine-keyed helpers go, with the admitted-buffer and channel checks of the old acknowledgment path, APPLE_RTKIT_OSLOG_LOG_RESERVED and oslog_inherited, which only that path read. The saved-scope poll's log-word test (apple_rtkit_log_word()) now follows the echo flag alone, as the receive path does. The echo path, which T8140 and T8142 have run since their sleep work, echoes the exact counter as macOS does. The one behaviour change on other SoCs is in edge cases: a counter that failed those checks is now echoed instead of dropped with a warning, a polled idle (T6050 AOP) echoes an owed counter as on T8140, and when two counters are queued before the receive work runs only the newer one is echoed, which acknowledges the older one too since the counter is cumulative. T8140 and T8142 keep the same messages on the wire: the echo starts on there as before (no node of theirs has apple,sync-syslog-ack). The host OSLOG control test and the DCP selftest now check the echo policy instead of the machine list. The echo and its polled-idle handling are Diljit Singh's (T8140) and Nick's (T8142); the counter acknowledgment is Eryk Wieliczko's and Chris Kearney's. Fixes: d9b438c4ca41 ("arm64: apple: support coordinated suspend-to-RAM on T8140") Fixes: 1369d18b4ec7 ("soc: apple: acknowledge OSLog progress in negotiated and inherited sessions") Signed-off-by: Ryan Murray --- drivers/soc/apple/rtkit-internal.h | 6 +- drivers/soc/apple/rtkit.c | 67 ++++----------- include/linux/soc/apple/rtkit.h | 5 +- tools/asahi/rtkit-oslog-tests.py | 85 +++++++++---------- tools/asahi/run-host-tests.py | 2 +- .../selftests/drivers/gpu/apple-dcp/boot.py | 57 ++++++------- 6 files changed, 92 insertions(+), 130 deletions(-) diff --git a/drivers/soc/apple/rtkit-internal.h b/drivers/soc/apple/rtkit-internal.h index d953d8c0d6c42..288e96603717e 100644 --- a/drivers/soc/apple/rtkit-internal.h +++ b/drivers/soc/apple/rtkit-internal.h @@ -69,7 +69,10 @@ struct apple_rtkit { * hand out kdebug buffers, and poll the mailbox while waiting. */ bool sync_syslog_ack; - /* Echo each OSLOG channel-0 counter, as macOS does. */ + /* + * Echo each OSLOG channel-0 counter, as macOS does. On unless the node has + * apple,sync-syslog-ack or the client turned it off; off drops the counters. + */ bool oslog_echo; /* A counter queued for the receive work and not yet echoed. */ u64 oslog_owed; @@ -139,7 +142,6 @@ struct apple_rtkit { bool crashlog_inherited; /* The crash log buffer is the firmware's own, mapped here when it crashed. */ bool crashlog_placed; - bool oslog_inherited; /* A crash reported before the crashlog buffer was mapped: the log is * read once the co-processor has written it. */ diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 4b873f1fdd464..18150bb3052ed 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -100,7 +100,6 @@ enum { #define APPLE_RTKIT_OSLOG_TYPE GENMASK_ULL(63, 56) #define APPLE_RTKIT_OSLOG_BUFFER_REQUEST 1 #define APPLE_RTKIT_OSLOG_LOG 2 -#define APPLE_RTKIT_OSLOG_LOG_RESERVED GENMASK_ULL(55, 32) #define APPLE_RTKIT_OSLOG_SIZE GENMASK_ULL(55, 36) #define APPLE_RTKIT_OSLOG_IOVA GENMASK_ULL(35, 0) @@ -1374,25 +1373,6 @@ static void apple_rtkit_syslog_rx(struct apple_rtkit *rtk, u64 msg) } } -/* Where a counter has only ever run unanswered: nothing is echoed. */ -static bool apple_rtkit_oslog_unanswered(struct apple_rtkit *rtk) -{ - return !rtk->oslog_echo && - (rtk->sync_syslog_ack || of_machine_is_compatible("apple,t8140") || - of_machine_is_compatible("apple,t8142")); -} - -/* An OSLOG counter that is answered with its echo, on any lane. */ -static bool apple_rtkit_oslog_echoed(struct apple_rtkit *rtk, u64 msg) -{ - if (rtk->oslog_echo) - return true; - if (apple_rtkit_oslog_unanswered(rtk)) - return false; - return (rtk->oslog_buffer.size || rtk->oslog_inherited) && - !(msg & APPLE_RTKIT_OSLOG_LOG_RESERVED); -} - static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) { u8 type = FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg); @@ -1402,6 +1382,8 @@ static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) * A firmware counts its log writes and holds the next counter until the last is * echoed, and with one outstanding takes no AP power notice: a DCP after a warm * restart, the MTP and the SMC after about eight sleeps. macOS echoes every one. + * The counter is cumulative, so echoing the newest one acknowledges every write + * before it. */ if (type == APPLE_RTKIT_OSLOG_LOG && rtk->oslog_echo) { /* A polled idle that came first echoed it already. */ @@ -1416,13 +1398,9 @@ static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) return; } - if (type == APPLE_RTKIT_OSLOG_LOG && !apple_rtkit_oslog_echoed(rtk, msg)) { - /* Preserve the tested Neo/M5 and synchronous-log no-ACK policy. */ - if (apple_rtkit_oslog_unanswered(rtk)) - dev_dbg(rtk->dev, "RTKit: oslog notification: %016llx\n", msg); - else - dev_warn_ratelimited(rtk->dev, "RTKit: invalid oslog notification: %llx\n", - msg); + /* Where the echo is off (apple_rtkit_set_oslog_echo()), the counter is dropped. */ + if (type == APPLE_RTKIT_OSLOG_LOG) { + dev_dbg(rtk->dev, "RTKit: oslog notification: %016llx\n", msg); return; } @@ -1431,20 +1409,6 @@ static void apple_rtkit_oslog_rx(struct apple_rtkit *rtk, u64 msg) apple_rtkit_common_rx_get_buffer(rtk, &rtk->oslog_buffer, APPLE_RTKIT_EP_OSLOG, msg); break; - case APPLE_RTKIT_OSLOG_LOG: - /* Channel zero reports a cumulative 32-bit write counter. Even - * though we discard these logs, acknowledge that exact counter: - * AppleDCP waits for its log transport to drain before AP sleep. - * This is not a buffer offset and may wrap. Other channels do not - * have a buffer admitted by this endpoint implementation. An inherited - * channel zero needs no buffer mapping to acknowledge its counter - * (apple_rtkit_oslog_echoed()). - */ - err = apple_rtkit_send_message(rtk, APPLE_RTKIT_EP_OSLOG, - msg, NULL, false); - if (err) - dev_err(rtk->dev, "RTKit: oslog acknowledgment failed: %d\n", err); - break; case 3 ... 5: /* * Undocumented notifications sent during normal operation. They @@ -1867,8 +1831,7 @@ static bool apple_rtkit_log_word(struct apple_rtkit *rtk, u8 ep, u64 msg) if (ep == APPLE_RTKIT_EP_SYSLOG) return apple_rtkit_notification_msg(ep, msg); return ep == APPLE_RTKIT_EP_OSLOG && - FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg) == APPLE_RTKIT_OSLOG_LOG && - apple_rtkit_oslog_echoed(rtk, msg); + FIELD_GET(APPLE_RTKIT_OSLOG_TYPE, msg) == APPLE_RTKIT_OSLOG_LOG && rtk->oslog_echo; } int apple_rtkit_m5_saved_poll(struct apple_rtkit *rtk) @@ -2230,7 +2193,6 @@ static void apple_rtkit_mark_running(struct apple_rtkit *rtk) rtk->ap_power_state = APPLE_RTKIT_PWR_STATE_ON; rtk->syslog_inherited = true; rtk->crashlog_inherited = true; - rtk->oslog_inherited = true; } static int apple_rtkit_claim_rx(struct apple_rtkit *rtk) @@ -2420,13 +2382,17 @@ static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, rtk->sync_syslog_ack = of_property_read_bool(dev->of_node, "apple,sync-syslog-ack"); /* - * As macOS does; a driver whose firmware shouldn't get them turns it off. T8142 too: - * its MTP left a counter unechoed after the first sleep's resume, then took no AP - * idle notice for the next one (J815, -ETIME at prepare) and asserted on the one - * after ("Invalid AP power"). + * Echo every OSLOG channel-0 counter, as macOS does. This is the OSLOG protocol of + * every RTKit firmware that sends counters: it holds the next one until the last is + * echoed and takes no AP power notice while one is outstanding (T8140, and the J815 + * MTP, whose second sleep failed at prepare with -ETIME without it). The IOP sends + * no version or capability for this; a firmware that does not use the protocol + * sends no counters, so the echo never goes out. apple,sync-syslog-ack turns it + * off: the dcpext that carries it (T8122) has only run with its counters + * unanswered; a DCP driver that restarts its DCP across a sleep turns the echo + * back on. */ - rtk->oslog_echo = of_machine_is_compatible("apple,t8140") || - of_machine_is_compatible("apple,t8142"); + rtk->oslog_echo = !rtk->sync_syslog_ack; rtk->m5_saved.tracked = track_saved; atomic_set(&rtk->m5_saved.jobs, 0); atomic_set(&rtk->v27_jobs, 0); @@ -2710,7 +2676,6 @@ static void apple_rtkit_reset_session(struct apple_rtkit *rtk) rtk->syslog_msg_size = 0; rtk->syslog_inherited = false; rtk->crashlog_inherited = false; - rtk->oslog_inherited = false; bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS); set_bit(APPLE_RTKIT_EP_MGMT, rtk->endpoints); diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index b0edf3d2b9ec1..24b4997faf4c0 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -437,8 +437,9 @@ int apple_rtkit_power_cycled_return(struct apple_rtkit *rtk, void __iomem *cpu_c int apple_rtkit_sleep_return_start(struct apple_rtkit *rtk, void __iomem *cpu_control); /* - * Echo each OSLOG channel-0 counter the firmware sends, as macOS does. On by default on - * T8140, where a firmware with one outstanding takes no AP power notice. + * Echo each OSLOG channel-0 counter the firmware sends, as macOS does, or drop them. On by + * default (off on a node with apple,sync-syslog-ack): a firmware with one outstanding + * takes no AP power notice. */ void apple_rtkit_set_oslog_echo(struct apple_rtkit *rtk, bool echo); diff --git a/tools/asahi/rtkit-oslog-tests.py b/tools/asahi/rtkit-oslog-tests.py index 944e07c67b887..c6ff6dd87e626 100644 --- a/tools/asahi/rtkit-oslog-tests.py +++ b/tools/asahi/rtkit-oslog-tests.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only OR MIT -"""Check OSLog counter acknowledgements and inherited-session reset.""" +"""Check the OSLog counter echo policy and the session reset.""" import argparse import hashlib import json @@ -52,7 +52,7 @@ def function(source, name): struct apple_rtkit_shmem oslog_buffer, syslog_buffer, ioreport_buffer, crashlog_buffer; struct apple_rtkit_shmem kdebug_buffer0, kdebug_buffer1, coreanalytics_buffer, pmp_aux_buffer; int sync_ack_fifo; - bool sync_syslog_ack, oslog_inherited, syslog_inherited, crashlog_inherited, crashed, shutting_down; + bool sync_syslog_ack, syslog_inherited, crashlog_inherited, crashed, shutting_down; bool oslog_echo; u64 oslog_owed; /* Read only by the J714s firmware 27 sleep; a failed echo sets it. */ @@ -68,9 +68,6 @@ def function(source, name): static unsigned sent, warnings, errors, requests, detachments, flushes, freed, checks; static int send_error, setup_error, start_error; static u64 sent_message; -static bool neo, m5; -static bool of_machine_is_compatible(const char *s) -{ return (!strcmp(s, "apple,t8140") && neo) || (!strcmp(s, "apple,t8142") && m5); } #define kfifo_reset(f) (*(f)=0) #define dev_dbg(...) ((void)0) #define dev_warn(...) (++warnings) @@ -98,12 +95,13 @@ def function(source, name): MAIN = r''' static void reset(void) { sent=warnings=errors=requests=0; send_error=setup_error=0; } -static void event(struct apple_rtkit *r, u64 msg, bool ack) +/* A counter as the receive work sees it: owed is what the IRQ path recorded. */ +static void event(struct apple_rtkit *r, u64 msg, u64 owed, bool echo) { - reset(); apple_rtkit_oslog_rx(r,msg); - assert(sent==(unsigned)ack && requests==0 && errors==0); - if (ack) { assert(sent_message==msg && warnings==0); } - else { assert(warnings==1); } + reset(); r->oslog_owed=owed; apple_rtkit_oslog_rx(r,msg); + assert(sent==(unsigned)echo && requests==0 && errors==0 && warnings==0); + if (echo) assert(sent_message==msg && r->oslog_owed==0); + else assert(r->oslog_owed==owed); ++checks; } int main(void) @@ -111,50 +109,55 @@ def function(source, name): struct mailbox m={0}; struct apple_rtkit r={.mbox=&m}; const u64 type=(u64)APPLE_RTKIT_OSLOG_LOG<<56; const uint32_t counters[]={0,1,4095,4096,UINT32_MAX,0,0x80000000}; - for (unsigned owner=0; owner<3; owner++) { - r.oslog_buffer.size=owner==1?4096:0; r.oslog_inherited=false; - if (owner==2) { apple_rtkit_mark_running(&r); assert(r.oslog_inherited); } - for (unsigned i=0;i=3 && kind<=5)) continue; - event(&r,(u64)kind<<56,false); + for (unsigned echo=0; echo<2; echo++) { + for (unsigned owner=0; owner<3; owner++) { + memset(&r,0,sizeof(r)); r.mbox=&m; r.oslog_echo=echo; + r.oslog_buffer.size=owner==1?4096:0; + if (owner==2) apple_rtkit_mark_running(&r); + // Echoed exactly when the echo is on, with or without a buffer, on any channel. + for (unsigned i=0;i=3 && kind<=5)) continue; + reset(); apple_rtkit_oslog_rx(&r,(u64)kind<<56); + assert(warnings==1 && sent==0); ++checks; + } } } for (unsigned fail=0;fail<2;fail++) { - memset(&r,0,sizeof(r));r.mbox=&m; reset();setup_error=fail?-5:0; + memset(&r,0,sizeof(r));r.mbox=&m;r.oslog_echo=true; reset();setup_error=fail?-5:0; const u64 req=((u64)APPLE_RTKIT_OSLOG_BUFFER_REQUEST<<56)|(4096ULL<<36); apple_rtkit_oslog_rx(&r,req); assert(requests==1 && sent==0); - event(&r,type|UINT32_MAX,!fail);++checks; + event(&r,type|UINT32_MAX,type|UINT32_MAX,true); } - r.oslog_buffer.size=4096; for (unsigned failure=0;failure<2;failure++) { - reset();send_error=failure?-5:0;apple_rtkit_oslog_rx(&r,type|UINT32_MAX); - assert(sent==1 && sent_message==(type|UINT32_MAX));assert(errors==failure && warnings==0);++checks; + memset(&r,0,sizeof(r));r.mbox=&m;r.oslog_echo=true; + reset();send_error=failure?-5:0;r.oslog_owed=type|UINT32_MAX;apple_rtkit_oslog_rx(&r,type|UINT32_MAX); + assert(sent==1 && sent_message==(type|UINT32_MAX));assert(errors==failure && warnings==0); + assert(r.v27_rx_failed==failure);++checks; } for (unsigned fail=0;fail<2;fail++) { - memset(&r,0,sizeof(r));r.mbox=&m;apple_rtkit_mark_running(&r); - assert(r.oslog_inherited && (r.endpoints[0]&(1UL<size=4096; r.crashed=true;r.syslog_msg_size=128; detachments=flushes=freed=0;start_error=fail?-5:0; assert(apple_rtkit_reinit(&r)==start_error); - assert(!r.oslog_inherited && !r.syslog_inherited && !r.crashlog_inherited); + assert(!r.syslog_inherited && !r.crashlog_inherited); assert(!r.crashed && !r.syslog_msg_size && freed==ARRAY_SIZE(buffers)); // Every buffer of the old firmware session goes, the OSLog one included. for (unsigned i=0;isize); assert(r.endpoints[0]==(1UL<oslog_buffer.size && !rtk->oslog_inherited)', 'false') - bodies = bodies.replace('(rtk->oslog_buffer.size || rtk->oslog_inherited)', 'true') - elif args.mutate == 'channel': - bodies = bodies.replace('(msg & APPLE_RTKIT_OSLOG_LOG_RESERVED)', 'false') + if args.mutate == 'owed': + bodies = bodies.replace('cmpxchg(&rtk->oslog_owed, msg, 0) != msg', 'false') + elif args.mutate == 'policy': + bodies = bodies.replace('type == APPLE_RTKIT_OSLOG_LOG && rtk->oslog_echo', 'type == APPLE_RTKIT_OSLOG_LOG') elif args.mutate == 'counter': bodies = bodies.replace('msg, NULL, false);', '(msg & ~0xffffffffULL) | ((u32)msg % 4096), NULL, false);') elif args.mutate == 'reset': - bodies = bodies.replace('rtk->oslog_inherited = false;', 'rtk->oslog_inherited = true;') + bodies = bodies.replace('rtk->syslog_inherited = false;', 'rtk->syslog_inherited = true;') elif args.mutate == 'buffer': bodies = bodies.replace('apple_rtkit_free_buffer(rtk, &rtk->oslog_buffer);', '') # A mutation that no longer matches the driver would test nothing. diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index a20d283737988..e008066e6b4c9 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -440,7 +440,7 @@ def mutations(flag, names, base, expect=KILL): 'rtkit-crashlog-map-tests.py': [(out(), PASS), (out() + ['--old-ref', 'cacf35543b4d534fccef3033bd2ddbb415a325b2'], PASS)], 'rtkit-oslog-tests.py': [(out(), PASS)] - + mutations('--mutate', ('admission', 'channel', 'counter', 'reset', 'buffer'), out()), + + mutations('--mutate', ('owed', 'policy', 'counter', 'reset', 'buffer'), out()), 'rtkit-adopted-session-tests.py': [(out(), PASS)] + mutations('--mutation', ('no-management', 'any-system', 'any-version', 'ignore-ops-version', 'any-buffer-endpoint'), out()), diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index 14f46e0279025..9ac30d625269f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -7,11 +7,6 @@ def oslog(root): source = (root / 'drivers/soc/apple/rtkit.c').read_text() constants = '\n'.join(line for line in source.splitlines() if line.startswith('#define APPLE_RTKIT_OSLOG_')) - # The echo's predicate, where the receiver is built on one. - helpers = ''.join(block(source, marker) + '\n' - for marker in ('static bool apple_rtkit_oslog_unanswered(', - 'static bool apple_rtkit_oslog_echoed(') - if marker in source) return r''' #include #include @@ -25,7 +20,7 @@ def oslog(root): #define APPLE_RTKIT_EP_OSLOG 8 struct buffer { unsigned sentinel; unsigned size; }; /* v27_rx_failed: read only by the J714s firmware 27 sleep; a failed echo sets it. */ -struct apple_rtkit { void *dev; struct buffer oslog_buffer; bool oslog_inherited, sync_syslog_ack, oslog_echo; u64 oslog_owed; bool v27_rx_failed; }; +struct apple_rtkit { void *dev; struct buffer oslog_buffer; bool sync_syslog_ack, oslog_echo; u64 oslog_owed; bool v27_rx_failed; }; #define cmpxchg(p,o,n) __sync_val_compare_and_swap((p),(o),(n)) #define WRITE_ONCE(x,v) ((x)=(v)) /* As the shared Apple configuration builds it. */ @@ -33,8 +28,6 @@ def oslog(root): #define IS_ENABLED(option) (option) static unsigned warnings, notifications, requests, acks, errors; static u64 observed; -static bool neo, m5; -#define of_machine_is_compatible(s) ((!strcmp(s,"apple,t8140") && neo) || (!strcmp(s,"apple,t8142") && m5)) #define dev_warn(dev,fmt,msg) do { (void)(dev); (void)(fmt); warnings++; observed=(msg); } while (0) #define dev_warn_ratelimited(dev,fmt,msg) dev_warn(dev,fmt,msg) #define dev_dbg(dev,fmt,msg) do { (void)(dev); (void)(fmt); notifications++; observed=(msg); } while (0) @@ -43,12 +36,12 @@ def oslog(root): { (void)rtk; assert(ep==8 && !completion && !atomic); acks++; observed=msg; return 0; } static void apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk, struct buffer *b, u8 ep, u64 msg) { assert(b==&rtk->oslog_buffer && ep==8); requests++; observed=msg; } -''' + constants + '\n' + helpers + block(source, 'static void apple_rtkit_oslog_rx(') + r''' +''' + constants + '\n' + block(source, 'static void apple_rtkit_oslog_rx(') + r''' static void reset(void) { warnings=notifications=requests=acks=errors=0; observed=0; } int main(void) { + /* Echo off: a client turned it off, or the node has apple,sync-syslog-ack. */ struct apple_rtkit rtk={.oslog_buffer={.sentinel=0x12345678}}; - neo=true; for (u8 type=2; type<=5; type++) { for (unsigned edge=0; edge<2; edge++) { u64 msg=((u64)type<<56) | (edge ? ((1ULL<<56)-1) : 0); @@ -70,28 +63,30 @@ def oslog(root): assert(requests==1 && !warnings && !notifications && observed==(1ULL<<56)); puts("PASS buffer requests retain existing dispatch"); #ifdef APPLE_RTKIT_OSLOG_LOG - /* Other machines acknowledge only admitted channel-zero counters. */ - neo=m5=false; - reset(); apple_rtkit_oslog_rx(&rtk,2ULL<<56); - assert(warnings==1 && !acks && !notifications); - for (unsigned inherited=0; inherited<2; inherited++) { - rtk.oslog_buffer.size=inherited ? 0 : 4096; - rtk.oslog_inherited=inherited; - reset(); apple_rtkit_oslog_rx(&rtk,(2ULL<<56)|UINT32_MAX); - assert(acks==1 && !warnings && observed==((2ULL<<56)|UINT32_MAX)); - reset(); apple_rtkit_oslog_rx(&rtk,(2ULL<<56)|(1ULL<<32)); - assert(warnings==1 && !acks); - } - /* Each tested platform policy overrides channel and buffer admission. */ - rtk.oslog_inherited=false; - for (unsigned policy=0; policy<3; policy++) { - neo=policy==0; m5=policy==1; rtk.sync_syslog_ack=policy==2; - reset(); apple_rtkit_oslog_rx(&rtk,(2ULL<<56)|(1ULL<<32)); - assert(notifications==1 && !warnings && !acks); + /* Echo on (every RTKit by default): the exact counter goes back, whatever its + * channel bits and whether or not a buffer was negotiated. */ + rtk.oslog_echo=true; + const u64 counters[]={2ULL<<56, (2ULL<<56)|UINT32_MAX, (2ULL<<56)|(1ULL<<32), (2ULL<<56)|((1ULL<<56)-1)}; + for (unsigned buffer=0; buffer<2; buffer++) { + rtk.oslog_buffer.size=buffer ? 4096 : 0; + for (unsigned i=0; i