From 6c79a541616a40c7d854ecdf2c3202c9b6b24b4d Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 26 Nov 2026 04:18:48 -0500 Subject: [PATCH 1/2] drm/asahi: g17: allow inline cross-engine publication behind already-published producers Previously Queue::enqueue() added every cross-engine firmware producer's drm_sched scheduled fence to the consumer's dependencies, and both try_compute_early() and try_render_early() gated on has_dependencies() (which includes firmware completion fences). As a result, every cross-engine command fell off the inline publication path onto drm_sched even when its producer had already been published inline in the same ioctl or had already signalled scheduled, leaving cross-engine workloads at 0% inline publication and adding a scheduler wakeup plus firmware cold-start stall on C->R and R->C transitions. Track whether Scheduler::enqueue() published a command inline, omit scheduled dependencies for producers that are already published (inline or scheduled fence signalled), gate early inline publication on host dependencies only (has_host_dependencies()), and check check_firmware_producers() before inline publication so failed producers propagate unpublished errors cleanly. Add a compiled host test with mutation traps covering producer scheduled-wait filtering, host vs firmware early-publication gating, and failed-producer error propagation. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g17/job.rs | 19 +- drivers/gpu/drm/asahi/g17/queue/mod.rs | 35 +- drivers/gpu/drm/asahi/g17/runtime.rs | 12 +- .../drm/asahi/g17/runtime/render/submit.rs | 12 +- tools/asahi/g17-inline-cross-engine-tests.py | 319 ++++++++++++++++++ tools/asahi/run-host-tests.py | 4 + 6 files changed, 392 insertions(+), 9 deletions(-) create mode 100755 tools/asahi/g17-inline-cross-engine-tests.py diff --git a/drivers/gpu/drm/asahi/g17/job.rs b/drivers/gpu/drm/asahi/g17/job.rs index 2d6e2dd3b2bf3..762879759da86 100644 --- a/drivers/gpu/drm/asahi/g17/job.rs +++ b/drivers/gpu/drm/asahi/g17/job.rs @@ -246,6 +246,12 @@ impl Packet { !self.inputs.is_empty() || !self.firmware.is_empty() } + /// Host-waited inputs keep a packet on the scheduler publication path; + /// already-published cross-engine firmware producers do not. + pub(crate) fn has_host_dependencies(&self) -> bool { + !self.inputs.is_empty() + } + pub(crate) fn begin_publication(&self) -> bool { self.publication .compare_exchange(0, 1, Ordering::AcqRel, Ordering::Acquire) @@ -550,6 +556,10 @@ pub(crate) struct Fences { pub(crate) completed: Fence, pub(crate) publication: Option>, pub(crate) owner: Arc, + /// True when `Scheduler::enqueue()` already published this command inline + /// before returning, so later cross-engine consumers can publish inline too + /// without waiting for `scheduled` to signal through `drm_sched`. + pub(crate) inline_published: bool, } impl super::dependency::Retention for Fences { @@ -680,7 +690,14 @@ impl Scheduler { self.backend.count_backlog(&packet); } job.push(); - Ok(Fences { ready, scheduled, completed, publication: host_publication, owner: packet.completion.clone() }) + Ok(Fences { + ready, + scheduled, + completed, + publication: host_publication, + owner: packet.completion.clone(), + inline_published: inline, + }) } } diff --git a/drivers/gpu/drm/asahi/g17/queue/mod.rs b/drivers/gpu/drm/asahi/g17/queue/mod.rs index f480b7cda3dec..d6d5d4cdccb5d 100644 --- a/drivers/gpu/drm/asahi/g17/queue/mod.rs +++ b/drivers/gpu/drm/asahi/g17/queue/mod.rs @@ -289,7 +289,13 @@ impl Queue { // since the prune above without a publication is not among them, so prune again: any // failure now visible makes it a full scan, and the failure record below has it. self.prune_frontier(index); - let (completion, publication, ordering_host_waits, ordering_firmware_waits) = { + let ( + completion, + publication, + ordering_host_waits, + ordering_firmware_waits, + ordering_firmware_published, + ) = { let ordering = EnqueueOrdering::build( &self.publishers[index], &self.frontiers[other], @@ -320,6 +326,7 @@ impl Queue { publication, ordering.host_waits, ordering.firmware_waits, + ordering.firmware_published, ) }; let mut failures: [Option; 2] = [None, None]; @@ -352,12 +359,17 @@ impl Queue { checked_inputs.push(fence, GFP_KERNEL)?; } // Firmware orders execution after each producer; the scheduler needs only the latest - // scheduled fence of them (dependency::ProducerWaits). + // scheduled fence of producers that have not already been published into firmware. let mut producer_waits = super::dependency::ProducerWaits::new(); - for (scheduled, completed) in &ordering_firmware_waits { - producer_waits.producer(scheduled, |fence| { - Ok(dependencies.push(fence.clone(), GFP_KERNEL)?) - })?; + for ((scheduled, completed), published) in ordering_firmware_waits + .iter() + .zip(ordering_firmware_published.iter()) + { + if !*published && job::fence_status(scheduled) <= 0 { + producer_waits.producer(scheduled, |fence| { + Ok(dependencies.push(fence.clone(), GFP_KERNEL)?) + })?; + } firmware.push(completed.clone(), GFP_KERNEL)?; } producer_waits.finish(|fence| Ok(dependencies.push(fence.clone(), GFP_KERNEL)?))?; @@ -700,6 +712,9 @@ trait FrontierEntry: outstanding::Status { } fn completed(&self) -> &Fence; fn scheduled(&self) -> &Fence; + fn inline_published(&self) -> bool { + false + } } impl FrontierEntry for Fences { @@ -718,12 +733,17 @@ impl FrontierEntry for Fences { fn scheduled(&self) -> &Fence { &self.scheduled } + + fn inline_published(&self) -> bool { + self.inline_published + } } struct EnqueueOrdering<'a> { predecessors: KVec<&'a Arc>, host_waits: KVec, firmware_waits: KVec<(Fence, Fence)>, + firmware_published: KVec, } impl<'a> EnqueueOrdering<'a> { @@ -754,6 +774,7 @@ impl<'a> EnqueueOrdering<'a> { let mut predecessors = KVec::new(); let mut host = KVec::new(); let mut firmware = KVec::new(); + let mut firmware_published = KVec::new(); if same_chain { for (_, entry) in same_covered.clone() { let status = entry.status(); @@ -809,6 +830,7 @@ impl<'a> EnqueueOrdering<'a> { (entry.scheduled().clone(), entry.completed().clone()), GFP_KERNEL, )?; + firmware_published.push(entry.inline_published(), GFP_KERNEL)?; } } @@ -816,6 +838,7 @@ impl<'a> EnqueueOrdering<'a> { predecessors, host_waits: host, firmware_waits: firmware, + firmware_published, }) } } diff --git a/drivers/gpu/drm/asahi/g17/runtime.rs b/drivers/gpu/drm/asahi/g17/runtime.rs index e64a10eb7d945..5f4588c68d7f5 100644 --- a/drivers/gpu/drm/asahi/g17/runtime.rs +++ b/drivers/gpu/drm/asahi/g17/runtime.rs @@ -3687,13 +3687,23 @@ impl Backend { /// its queue is already bound and nothing has to wait, as renders do. Any /// wait leaves the command, unpublished, to its scheduler. pub(super) fn try_compute_early(&self, packet: &Arc) -> bool { - if self.compute_backlog.load(Ordering::Acquire) != 0 || packet.has_dependencies() { + if self.compute_backlog.load(Ordering::Acquire) != 0 || packet.has_host_dependencies() { return false; } // A command the ray-traversal rule could hold now is left to its scheduler. if !self.traversal_inline(packet) { return false; } + if let Err(error) = packet.check_firmware_producers() { + if !packet.begin_publication() { + packet.completion.fail_unpublished(ECANCELED); + packet.set_early_result(Err(ECANCELED)); + return true; + } + packet.completion.fail_unpublished(error); + packet.set_early_result(Err(error)); + return true; + } if !packet.begin_publication() { packet.completion.fail_unpublished(ECANCELED); packet.set_early_result(Err(ECANCELED)); diff --git a/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs b/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs index d06e91c804f98..a72d5234acb8e 100644 --- a/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs +++ b/drivers/gpu/drm/asahi/g17/runtime/render/submit.rs @@ -578,13 +578,23 @@ impl Backend { } pub(in crate::g17) fn try_render_early(&self, packet: &Arc) -> bool { - if self.backlog.load(Ordering::Acquire) != 0 || packet.has_dependencies() { + if self.backlog.load(Ordering::Acquire) != 0 || packet.has_host_dependencies() { return false; } // As for compute: a render that traces rays is admitted by its scheduler. if !self.traversal_inline(packet) { return false; } + if let Err(error) = packet.check_firmware_producers() { + if !packet.begin_publication() { + packet.completion.fail_unpublished(ECANCELED); + packet.set_early_result(Err(ECANCELED)); + return true; + } + packet.completion.fail_unpublished(error); + packet.set_early_result(Err(error)); + return true; + } let admission = match self.admission.try_acquire_render(self.owner, self.render_pairs(packet).into(), Request::of(packet)) { Ok(Some(lease)) => lease, _ => return false, diff --git a/tools/asahi/g17-inline-cross-engine-tests.py b/tools/asahi/g17-inline-cross-engine-tests.py new file mode 100755 index 0000000000000..19011c4d337ac --- /dev/null +++ b/tools/asahi/g17-inline-cross-engine-tests.py @@ -0,0 +1,319 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Host test for G17 inline cross-engine publication behind already-published producers. + +Compiles production `has_host_dependencies()` (`job.rs`), the firmware-producer +dependency filtering in `queue/mod.rs`, and the early-publication guards in +`try_compute_early()` (`runtime.rs`) and `try_render_early()` +(`runtime/render/submit.rs`) to prove: +1. Already-inline-published or already-scheduled cross-engine producers do not + add `scheduled` waits to `dependencies`, so consumers stay eligible for + inline publication while retaining firmware completion ordering. +2. Unpublished cross-engine producers still add their `scheduled` fence to + `dependencies` so the consumer waits for producer publication in `drm_sched`. +3. `try_compute_early()` and `try_render_early()` gate on host dependencies + only (`has_host_dependencies()`), allowing firmware-ordered cross-engine + packets to publish inline while still keeping host-waited packets on + `drm_sched`. +4. Failed firmware producers are caught by `check_firmware_producers()` in both + `try_compute_early()` and `try_render_early()`, failing the consumer + unpublished with the producer's error before any hardware publication. +""" +import argparse +import os +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +G17 = ROOT / 'drivers/gpu/drm/asahi/g17' + +MUTATIONS = [ + 'always-wait-scheduled', + 'skip-unpublished-scheduled', + 'block-firmware-early', + 'skip-compute-producer-check', + 'skip-render-producer-check', +] + + +def item(source, signature): + assert source.count(signature) == 1, signature + start = source.index(signature) + begin = source.index('{', start) + depth, end = 1, begin + 1 + while depth: + depth += (source[end] == '{') - (source[end] == '}') + end += 1 + return source[start:end] + + +def build_harness(mutation=None): + job_src = (G17 / 'job.rs').read_text() + queue_src = (G17 / 'queue/mod.rs').read_text() + runtime_src = (G17 / 'runtime.rs').read_text() + submit_src = (G17 / 'runtime/render/submit.rs').read_text() + + has_host_fn = item(job_src, 'pub(crate) fn has_host_dependencies(') + has_deps_fn = item(job_src, 'pub(crate) fn has_dependencies(') + comp_early_fn = item(runtime_src, 'pub(super) fn try_compute_early(') + rend_early_fn = item(submit_src, 'pub(in crate::g17) fn try_render_early(') + + # Extract the exact producer-wait loop from Queue::enqueue(). + loop_sig = 'for ((scheduled, completed), published) in ordering_firmware_waits' + assert queue_src.count(loop_sig) == 1, loop_sig + loop_start = queue_src.index(loop_sig) + loop_end = queue_src.index('producer_waits.finish(', loop_start) + loop_block = queue_src[loop_start:loop_end] + + if mutation == 'always-wait-scheduled': + old = 'if !*published && job::fence_status(scheduled) <= 0 {' + assert old in loop_block + loop_block = loop_block.replace(old, 'if true {', 1) + elif mutation == 'skip-unpublished-scheduled': + old = 'if !*published && job::fence_status(scheduled) <= 0 {' + assert old in loop_block + loop_block = loop_block.replace(old, 'if false {', 1) + elif mutation == 'block-firmware-early': + old = 'packet.has_host_dependencies()' + assert old in comp_early_fn and old in rend_early_fn + comp_early_fn = comp_early_fn.replace(old, 'packet.has_dependencies()', 1) + rend_early_fn = rend_early_fn.replace(old, 'packet.has_dependencies()', 1) + elif mutation == 'skip-compute-producer-check': + old = 'if let Err(error) = packet.check_firmware_producers() {' + assert old in comp_early_fn + comp_early_fn = comp_early_fn.replace(old, 'if let Err::<(), i32>(error) = Ok(()) {', 1) + elif mutation == 'skip-render-producer-check': + old = 'if let Err(error) = packet.check_firmware_producers() {' + assert old in rend_early_fn + rend_early_fn = rend_early_fn.replace(old, 'if let Err::<(), i32>(error) = Ok(()) {', 1) + + # Verify structural pieces that feed into inline_published. + fences_has_inline = ( + 'pub(crate) inline_published: bool,' in job_src + and 'inline_published: inline,' in job_src + and 'firmware_published.push(entry.inline_published(), GFP_KERNEL)?;' in queue_src + ) + + # Extract the guard prefix of try_compute_early and try_render_early up to begin_publication. + comp_guard_start = comp_early_fn.index('{') + 1 + comp_guard_end = comp_early_fn.index('let mut deferred =', comp_guard_start) + comp_guard = comp_early_fn[comp_guard_start:comp_guard_end] + + rend_guard_start = rend_early_fn.index('{') + 1 + rend_guard_end = rend_early_fn.index('let admission =', rend_guard_start) + rend_guard = rend_early_fn[rend_guard_start:rend_guard_end] + + # Normalize loop_block for std Vec instead of KVec(..., GFP_KERNEL)?. + loop_std = ( + loop_block + .replace('Ok(dependencies.push(fence.clone(), GFP_KERNEL)?)', '{ dependencies.push(fence.clone()); Ok::<(), i32>(()) }') + .replace('firmware.push(completed.clone(), GFP_KERNEL)?;', 'firmware.push(completed.clone());') + ) + + return f''' +use std::cell::Cell; +use std::sync::atomic::{{AtomicUsize, Ordering}}; + +const ECANCELED: i32 = -125; +const EIO: i32 = -5; +type Result = std::result::Result; + +#[derive(Clone, Copy)] +struct Fence {{ + id: u32, + status: i32, +}} + +mod job {{ + use super::Fence; + pub fn fence_status(f: &Fence) -> i32 {{ + f.status + }} +}} + +struct ProducerWaits {{ + last: Option, +}} + +impl ProducerWaits {{ + fn new() -> Self {{ Self {{ last: None }} }} + fn producer(&mut self, fence: &Fence, mut emit: impl FnMut(&Fence) -> Result) -> Result {{ + if let Some(prev) = self.last.replace(*fence) {{ + emit(&prev)?; + }} + Ok(()) + }} + fn finish(self, mut emit: impl FnMut(&Fence) -> Result) -> Result {{ + if let Some(last) = self.last {{ + emit(&last)?; + }} + Ok(()) + }} +}} + +struct Completion {{ + failed_unpublished: Cell>, +}} + +impl Completion {{ + fn fail_unpublished(&self, err: i32) {{ + self.failed_unpublished.set(Some(err)); + }} +}} + +struct Packet {{ + inputs: Vec, + firmware: Vec, + producer_err: Option, + began: Cell, + early_result: Cell>, + completion: Completion, +}} + +impl Packet {{ + {has_deps_fn.replace('pub(crate) ', '')} + {has_host_fn.replace('pub(crate) ', '')} + fn check_firmware_producers(&self) -> Result {{ + match self.producer_err {{ + Some(err) => Err(err), + None => Ok(()), + }} + }} + fn begin_publication(&self) -> bool {{ + let ok = !self.began.get(); + self.began.set(true); + ok + }} + fn set_early_result(&self, res: Result) {{ + self.early_result.set(Some(res)); + }} +}} + +struct Backend {{ + backlog: AtomicUsize, + compute_backlog: AtomicUsize, + traversal_ok: bool, +}} + +impl Backend {{ + fn traversal_inline(&self, _packet: &Packet) -> bool {{ + self.traversal_ok + }} + fn run_compute_early_guard(&self, packet: &Packet) -> bool {{ + {comp_guard} + true + }} + fn run_render_early_guard(&self, packet: &Packet) -> bool {{ + {rend_guard} + true + }} +}} + +fn filter_producers( + ordering_firmware_waits: &[(Fence, Fence)], + ordering_firmware_published: &[bool], +) -> (Vec, Vec) {{ + let mut dependencies: Vec = Vec::new(); + let mut firmware: Vec = Vec::new(); + let mut producer_waits = ProducerWaits::new(); + let _: Result = (|| {{ + {loop_std} + producer_waits.finish(|fence| {{ dependencies.push(fence.clone()); Ok(()) }})?; + Ok(()) + }})(); + (dependencies, firmware) +}} + +fn pkt(inputs: Vec, firmware: Vec, producer_err: Option) -> Packet {{ + Packet {{ + inputs, + firmware, + producer_err, + began: Cell::new(false), + early_result: Cell::new(None), + completion: Completion {{ failed_unpublished: Cell::new(None) }}, + }} +}} + +fn main() {{ + assert!({str(fences_has_inline).lower()}, "Fences::inline_published must flow into EnqueueOrdering"); + + let sched_pending = Fence {{ id: 10, status: 0 }}; + let sched_done = Fence {{ id: 11, status: 1 }}; + let comp_pending = Fence {{ id: 20, status: 0 }}; + + // 1. Producer published inline: no scheduled dependency, firmware completion kept. + let (deps, fw) = filter_producers(&[(sched_pending, comp_pending)], &[true]); + assert!(deps.is_empty(), "inline-published producer must not add scheduled dependency"); + assert_eq!(fw.len(), 1); + assert_eq!(fw[0].id, 20); + + // 2. Producer already scheduled via drm_sched: no scheduled dependency, firmware kept. + let (deps, fw) = filter_producers(&[(sched_done, comp_pending)], &[false]); + assert!(deps.is_empty(), "already-scheduled producer must not add scheduled dependency"); + assert_eq!(fw.len(), 1); + + // 3. Producer neither inline-published nor scheduled: MUST wait on scheduled fence. + let (deps, fw) = filter_producers(&[(sched_pending, comp_pending)], &[false]); + assert_eq!(deps.len(), 1, "unpublished producer must add scheduled dependency"); + assert_eq!(deps[0].id, 10); + assert_eq!(fw.len(), 1); + + // 4. Early guards allow firmware-only cross-engine dependencies, block host waits. + let b = Backend {{ + backlog: AtomicUsize::new(0), + compute_backlog: AtomicUsize::new(0), + traversal_ok: true, + }}; + let p_fw_c = pkt(vec![], vec![comp_pending], None); + assert!(b.run_compute_early_guard(&p_fw_c), "compute must publish inline with firmware-only deps"); + assert!(p_fw_c.completion.failed_unpublished.get().is_none()); + + let p_fw_r = pkt(vec![], vec![comp_pending], None); + assert!(b.run_render_early_guard(&p_fw_r), "render must publish inline with firmware-only deps"); + assert!(p_fw_r.completion.failed_unpublished.get().is_none()); + + let p_host = pkt(vec![sched_pending], vec![comp_pending], None); + assert!(!b.run_compute_early_guard(&p_host), "compute with host dep must stay on drm_sched"); + assert!(!b.run_render_early_guard(&p_host), "render with host dep must stay on drm_sched"); + + // 5. Failed firmware producer fails consumer unpublished in both compute and render. + let p_err_c = pkt(vec![], vec![comp_pending], Some(EIO)); + assert!(b.run_compute_early_guard(&p_err_c)); + assert_eq!(p_err_c.completion.failed_unpublished.get(), Some(EIO), "compute must catch failed producer"); + assert_eq!(p_err_c.early_result.get(), Some(Err(EIO))); + + let p_err_r = pkt(vec![], vec![comp_pending], Some(EIO)); + assert!(b.run_render_early_guard(&p_err_r)); + assert_eq!(p_err_r.completion.failed_unpublished.get(), Some(EIO), "render must catch failed producer"); + assert_eq!(p_err_r.early_result.get(), Some(Err(EIO))); + + println!("PASS g17 inline cross-engine publication"); +}} +''' + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument('--mutation', choices=MUTATIONS) + args = ap.parse_args() + + src = build_harness(args.mutation) + with tempfile.TemporaryDirectory(prefix='g17-inline-xeng-') as tmp: + rs = os.path.join(tmp, 'harness.rs') + bin_path = os.path.join(tmp, 'harness') + Path(rs).write_text(src) + c = subprocess.run(['rustc', '-O', rs, '-o', bin_path], capture_output=True, text=True) + if c.returncode != 0: + sys.stderr.write(c.stderr) + return 2 + r = subprocess.run([bin_path], capture_output=True, text=True) + sys.stdout.write(r.stdout) + sys.stderr.write(r.stderr) + return r.returncode + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index a20d283737988..8da9ad3029c4e 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -352,6 +352,10 @@ def mutations(flag, names, base, expect=KILL): 'max-channels', 'multi-channel-max'), []), 'g17-m5-effort-tests.py': [([], PASS)] + mutations('--mutation', ('m5-ignores-bound',), []), + 'g17-inline-cross-engine-tests.py': [([], PASS)] + + mutations('--mutation', ('always-wait-scheduled', 'skip-unpublished-scheduled', + 'block-firmware-early', 'skip-compute-producer-check', + 'skip-render-producer-check'), []), 'g17-firmware-selection-tests.py': [([], PASS)], 'g17-freelist-lease-direct-tests.py': [([], PASS)] + mutations('--mutation', ('reject-preparing-complete', 'snapshot-rollback', From 513edcf43d8f67ec51e30a6dcaa5cfe7f746b5a2 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Fri, 27 Nov 2026 09:39:35 -0500 Subject: [PATCH 2/2] drm/asahi: g17: require packet.is_published() for Fences::inline_published try_early() returns true both when a command was published inline to firmware and when it handled a terminal unpublished error before hardware publication. Gate Fences::inline_published on inline && packet.is_published() so an early unpublished producer failure never causes a cross-engine consumer to omit its scheduled-fence wait. Extend g17-inline-cross-engine-tests.py with an early-failed producer followed by a cross-engine consumer and the copy-try-early-bool mutation. Signed-off-by: DjDeveloperr --- drivers/gpu/drm/asahi/g17/job.rs | 2 +- tools/asahi/g17-inline-cross-engine-tests.py | 38 +++++++++++++++++++- tools/asahi/run-host-tests.py | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/asahi/g17/job.rs b/drivers/gpu/drm/asahi/g17/job.rs index 762879759da86..f9f5c981466d3 100644 --- a/drivers/gpu/drm/asahi/g17/job.rs +++ b/drivers/gpu/drm/asahi/g17/job.rs @@ -696,7 +696,7 @@ impl Scheduler { completed, publication: host_publication, owner: packet.completion.clone(), - inline_published: inline, + inline_published: inline && packet.is_published(), }) } } diff --git a/tools/asahi/g17-inline-cross-engine-tests.py b/tools/asahi/g17-inline-cross-engine-tests.py index 19011c4d337ac..351427a99d199 100755 --- a/tools/asahi/g17-inline-cross-engine-tests.py +++ b/tools/asahi/g17-inline-cross-engine-tests.py @@ -35,6 +35,7 @@ 'block-firmware-early', 'skip-compute-producer-check', 'skip-render-producer-check', + 'copy-try-early-bool', ] @@ -67,6 +68,13 @@ def build_harness(mutation=None): loop_end = queue_src.index('producer_waits.finish(', loop_start) loop_block = queue_src[loop_start:loop_end] + # Extract the exact inline_published expression from Scheduler::enqueue(). + inline_pub_sig = ' inline_published: ' + assert job_src.count(inline_pub_sig) == 1, inline_pub_sig + ip_start = job_src.index(inline_pub_sig) + len(inline_pub_sig) + ip_end = job_src.index(',', ip_start) + inline_pub_expr = job_src[ip_start:ip_end].strip() + if mutation == 'always-wait-scheduled': old = 'if !*published && job::fence_status(scheduled) <= 0 {' assert old in loop_block @@ -88,11 +96,13 @@ def build_harness(mutation=None): old = 'if let Err(error) = packet.check_firmware_producers() {' assert old in rend_early_fn rend_early_fn = rend_early_fn.replace(old, 'if let Err::<(), i32>(error) = Ok(()) {', 1) + elif mutation == 'copy-try-early-bool': + assert inline_pub_expr == 'inline && packet.is_published()', inline_pub_expr + inline_pub_expr = 'inline' # Verify structural pieces that feed into inline_published. fences_has_inline = ( 'pub(crate) inline_published: bool,' in job_src - and 'inline_published: inline,' in job_src and 'firmware_published.push(entry.inline_published(), GFP_KERNEL)?;' in queue_src ) @@ -168,6 +178,7 @@ def build_harness(mutation=None): firmware: Vec, producer_err: Option, began: Cell, + published: Cell, early_result: Cell>, completion: Completion, }} @@ -186,11 +197,18 @@ def build_harness(mutation=None): self.began.set(true); ok }} + fn is_published(&self) -> bool {{ + self.published.get() + }} fn set_early_result(&self, res: Result) {{ self.early_result.set(Some(res)); }} }} +fn compute_inline_published(inline: bool, packet: &Packet) -> bool {{ + {inline_pub_expr} +}} + struct Backend {{ backlog: AtomicUsize, compute_backlog: AtomicUsize, @@ -232,6 +250,7 @@ def build_harness(mutation=None): firmware, producer_err, began: Cell::new(false), + published: Cell::new(false), early_result: Cell::new(None), completion: Completion {{ failed_unpublished: Cell::new(None) }}, }} @@ -290,6 +309,23 @@ def build_harness(mutation=None): assert_eq!(p_err_r.completion.failed_unpublished.get(), Some(EIO), "render must catch failed producer"); assert_eq!(p_err_r.early_result.get(), Some(Err(EIO))); + // 6. Early failed producer (try_early returned true without hardware publication) + // followed by a cross-engine consumer: inline_published MUST be false so the + // consumer keeps its scheduled-fence wait and never omits it. + assert!(!p_err_c.is_published(), "early failed producer was never published to firmware"); + let prod_inline_pub = compute_inline_published(true, &p_err_c); + assert!(!prod_inline_pub, "inline_published must be false when try_early failed unpublished"); + let (deps, fw) = filter_producers(&[(sched_pending, comp_pending)], &[prod_inline_pub]); + assert_eq!(deps.len(), 1, "consumer after early-failed producer must keep scheduled wait"); + assert_eq!(deps[0].id, 10); + assert_eq!(fw.len(), 1); + + // Confirm a genuinely firmware-published inline producer sets inline_published = true. + let p_ok = pkt(vec![], vec![], None); + p_ok.published.set(true); + assert!(compute_inline_published(true, &p_ok)); + assert!(!compute_inline_published(false, &p_ok)); + println!("PASS g17 inline cross-engine publication"); }} ''' diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 8da9ad3029c4e..124f53cc95a69 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -355,7 +355,7 @@ def mutations(flag, names, base, expect=KILL): 'g17-inline-cross-engine-tests.py': [([], PASS)] + mutations('--mutation', ('always-wait-scheduled', 'skip-unpublished-scheduled', 'block-firmware-early', 'skip-compute-producer-check', - 'skip-render-producer-check'), []), + 'skip-render-producer-check', 'copy-try-early-bool'), []), 'g17-firmware-selection-tests.py': [([], PASS)], 'g17-freelist-lease-direct-tests.py': [([], PASS)] + mutations('--mutation', ('reject-preparing-complete', 'snapshot-rollback',