Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 38 additions & 11 deletions drivers/gpu/drm/asahi/g16/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ fn plan_render_barriers(
}
}

/// Whether the FS ring's own order already holds FS(N) behind FS(N-1), so that the FS->FS
/// `fs_dep` barrier of [`plan_render_barriers`] would only re-check a stamp the ring implies.
///
/// Every render's FS work goes on the one firmware FS queue, whose works the firmware runs in
/// ring order: on Metal's FS ring, which carries only each pass's own TA barrier ahead of its
/// FS work, consecutive passes serialize in ring order without self-event FS->FS barriers. A
/// predecessor of another VM (`cross_vm_prev`) and any InitBM producer or consumer
/// (`producer_initbm || init_buffer`) keep the barrier.
fn fs_ring_orders_prev(cross_vm_prev: bool, producer_initbm: bool, init_buffer: bool) -> bool {
!cross_vm_prev && !producer_initbm && !init_buffer
}

/// Engine of the previous member.
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub(crate) enum Prev {
Expand Down Expand Up @@ -447,6 +459,9 @@ struct Prefix {
last_fs: u32,
/// Compute commands staged onto the VM's shared compute UMA descriptor in this prefix.
uma_delta: u64,
/// Staged FS->FS barrier counts committed only after TA producer publication.
fs_dep: u64,
fs_order: u64,
}

/// Error provenance must remain independent of errno: EIO can be an ordinary failed VM
Expand Down Expand Up @@ -529,6 +544,9 @@ pub(crate) struct Stats {
pub(crate) job_cmds: u64,
pub(crate) job_max: u64,
pub(crate) early: u64,
/// FS->FS barriers posted, and those the FS ring's order made unnecessary.
pub(crate) fs_dep: u64,
pub(crate) fs_order: u64,
/// Type-0 FS->compute / compute->TA waits.
pub(crate) fs2c0: u64,
pub(crate) c2ta0: u64,
Expand Down Expand Up @@ -3360,6 +3378,9 @@ impl Firmware {
prefix.ta_head,
&mut self.engine.stats.publications[1],
)?;
self.engine.stats.fs_dep = self.engine.stats.fs_dep.saturating_add(prefix.fs_dep);
self.engine.stats.fs_order =
self.engine.stats.fs_order.saturating_add(prefix.fs_order);
self.graph.render.qstate[1].w32(qstate::WRITE, prefix.fs_head)?;
} else {
publish_producer(
Expand Down Expand Up @@ -4042,18 +4063,24 @@ impl Firmware {
r.ring[0].w64(8 * pf.ta_head as usize, p.ta_fs_barrier.va)?;
pf.ta_head = (pf.ta_head + 1) % cap;
}
let fs_ordered = fs_ring_orders_prev(cross_vm_prev, producer_initbm, init_buffer);
if let Some(wait_fs) = plan.fs_render_wait {
let dep = encode::barrier(
r.fw_stamp[1].va,
wait_fs,
0x71,
target,
work::barrier::RENDER_WAIT_UUID,
render_bar,
);
p.fs_dep.write(0, &dep)?;
r.ring[1].w64(8 * pf.fs_head as usize, p.fs_dep.va)?;
pf.fs_head = (pf.fs_head + 1) % cap;
if fs_ordered {
pf.fs_order += 1;
} else {
let dep = encode::barrier(
r.fw_stamp[1].va,
wait_fs,
0x71,
target,
work::barrier::RENDER_WAIT_UUID,
render_bar,
);
p.fs_dep.write(0, &dep)?;
r.ring[1].w64(8 * pf.fs_head as usize, p.fs_dep.va)?;
pf.fs_head = (pf.fs_head + 1) % cap;
pf.fs_dep += 1;
}
}
if plan.early {
self.engine.stats.early += 1;
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/asahi/g16/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2298,6 +2298,7 @@ impl Firmware {
self.slots.tilemap_clear_bytes_total()
)?;
writeln!(f, "type0: fs2c {} c2ta {}", s.fs2c0, s.c2ta0)?;
writeln!(f, "fs_ring: dep {} order {}", s.fs_dep, s.fs_order)?;
write!(f, "horizon:")?;
for n in s.hz.iter() {
write!(f, " {}", n)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""Execute production M4 publication/error isolation with a CPU-only transport recorder."""
from common import kernel_root, output_dir, rustc, sha
import json
import re
import subprocess

production = kernel_root() / 'drivers/gpu/drm/asahi/g16/engine.rs'
Expand Down Expand Up @@ -58,6 +59,18 @@ def item(declaration):
assert 'f.msaa |= cmd.is_multisampled();' in prefix_render_fn
assert 'p.ta_fs_barrier.write(0, &ta_fs)?;' in prefix_render_fn
assert 'p.fs_dep.write(0, &dep)?;' in prefix_render_fn
# The FS->FS barrier is posted only when the plan asks for it and the FS ring's order does not
# cover it (cross-VM or InitBM). The decision comes after every InitBM producer is known, and
# the counters are staged on Prefix and committed only after TA producer publication.
assert (
prefix_render_fn.index('let render_bar = cross_engine_barrier_type(producer_initbm, init_buffer);')
< prefix_render_fn.index('let fs_ordered = fs_ring_orders_prev(cross_vm_prev, producer_initbm, init_buffer);')
< prefix_render_fn.index('if let Some(wait_fs) = plan.fs_render_wait {')
< prefix_render_fn.index('p.fs_dep.write(0, &dep)?;')
), 'fs_ring_orders_prev must follow producer_initbm/init_buffer and gate p.fs_dep'
assert 'pf.fs_order += 1;' in prefix_render_fn and 'pf.fs_dep += 1;' in prefix_render_fn
assert 'self.engine.stats.fs_dep' not in prefix_render_fn
assert 'self.engine.stats.fs_order' not in prefix_render_fn
assert 'p.compute_barrier.write(off, &cbar)?;' in prefix_render_fn
assert 'p.fs_compute_barrier.write(off, &fcbar)?;' in prefix_render_fn
c2ta_slice = prefix_render_fn[
Expand All @@ -81,6 +94,9 @@ def item(declaration):
assert 'DRM_ASAHI_FEATURE_RENDER_STAGE_PREFIXES_V2' in params_src
publish_prefix_body_fn = item('fn publish_prefix_body(')
assert 'self.graph.render.threshold.w32(0, prefix.draw as u32)?;' in publish_prefix_body_fn
_ta_pub = publish_prefix_body_fn.index('&self.graph.render.qstate[0],')
assert publish_prefix_body_fn.index('self.engine.stats.fs_dep =') > _ta_pub
assert publish_prefix_body_fn.index('self.engine.stats.fs_order =') > _ta_pub
_visible = publish_prefix_body_fn.index('*visible = true;')
assert publish_prefix_body_fn.count('job.vm.note_msaa_render();') == 1
assert publish_prefix_body_fn.index('job.vm.note_msaa_render();') > _visible
Expand Down Expand Up @@ -3164,6 +3180,17 @@ def item(declaration):
}
}

__FS_RING_ORDERS_PREV__

#[test]
fn fs_ring_orders_prev_keeps_cross_vm_and_initbm_barriers() {
assert!(fs_ring_orders_prev(false, false, false));
assert!(!fs_ring_orders_prev(true, false, false));
assert!(!fs_ring_orders_prev(false, true, false));
assert!(!fs_ring_orders_prev(false, false, true));
assert!(!fs_ring_orders_prev(true, true, true));
}

'''
harness = harness.replace('__LOGIC__', str(production.parent / 'recovery/logic.rs'))

Expand Down Expand Up @@ -3273,6 +3300,7 @@ def item(declaration):
'__CROSS_ENGINE_BARRIER_TYPE__': 'const fn cross_engine_barrier_type(',
'__RENDER_BARRIER_PLAN__': 'struct RenderBarrierPlan {',
'__PLAN_RENDER_BARRIERS__': 'fn plan_render_barriers(',
'__FS_RING_ORDERS_PREV__': 'fn fs_ring_orders_prev(',
}.items():
harness = harness.replace(token, item(declaration).replace("super::command::", "crate::command::").replace("super::recovery::", "crate::recovery::").replace("super::hw::", "crate::hw::").replace("super::resources::", "crate::resources::").replace("super::queue::QueueState", "crate::Queue").replace("super::vm::VmState", "crate::Vm").replace("super::fence::", "crate::fence::"))
unit = output / 'publication.rs'
Expand All @@ -3287,7 +3315,9 @@ def item(declaration):
if result.returncode:
raise SystemExit(result.returncode)
(output/'publication.json').write_text(json.dumps({
'passed': True, 'tests': 70, 'cpu_only': True, 'hardware_execution': False,
'passed': True,
'tests': int(re.search(r'^test result: ok\. (\d+) passed;', log, re.MULTILINE)[1]),
'cpu_only': True, 'hardware_execution': False,
'scope': 'Verbatim production publication wrapper, selection, error isolation and descriptor-error containment branch; wire encoder, descriptor failure injection and transport replaced by CPU recorders.',
'source_sha256': sha(production),
}, indent=2)+'\n')
Loading