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
22 changes: 17 additions & 5 deletions drivers/gpu/drm/asahi/g17/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const COMPUTE_CREDITS: u32 = crate::hw::t8140::queues::COMPUTE_DEPTH as u32;
/// behind a long frontier (about 120 of them under Astro Bot) made every submit
/// quadratic, about 1 ms of CPU. Past this many, the scheduler waits on one
/// merged fence instead: the same wait, while status checks keep each fence.
const MERGED_DEPENDENCIES: usize = 8;
pub(crate) const MERGED_DEPENDENCIES: usize = 8;

#[derive(Clone, Copy, PartialEq, Eq)]
pub(crate) enum Engine {
Expand Down Expand Up @@ -132,6 +132,9 @@ pub(crate) struct Packet {
/// Number of render passes in the submit ioctl that created this packet.
pub(crate) batch_renders: u16,
inputs: KVec<Fence>,
/// The submission's own input fences ([`super::sync_input::Inputs`]), unless compute sources
/// take them over in firmware.
shared_inputs: Option<super::sync_input::CommandInputs>,
/// The other engine's producers this packet waits for in firmware, checked for failure
/// through that engine's failure log instead of one fence each.
producers: Option<Producers>,
Expand Down Expand Up @@ -167,6 +170,7 @@ impl Packet {
completion: Arc<Completion>,
batch_renders: u16,
inputs: KVec<Fence>,
shared_inputs: Option<super::sync_input::CommandInputs>,
producers: Option<Producers>,
) -> Result<Arc<Self>> {
let footprint = match &command {
Expand All @@ -187,6 +191,7 @@ impl Packet {
footprint,
batch_renders,
inputs,
shared_inputs,
producers,
publication: AtomicU8::new(0),
cancelled: AtomicBool::new(false),
Expand Down Expand Up @@ -236,7 +241,7 @@ impl Packet {
/// Replay holds the device mutex. Its original inputs were satisfied before
/// first publication; never sleep on a fence that needs event service here.
pub(crate) fn check_replay_dependencies(&self) -> Result {
for fence in &self.inputs {
for fence in self.inputs() {
super::dependency::replay_status(fence_status(fence))?;
}
self.check_firmware_producers()?;
Expand All @@ -249,7 +254,7 @@ impl Packet {
pub(crate) fn check_dependencies(&self) -> Result {
let polls = if self.command.long_job() { 5 } else { 1 };
let deadline = super::now_ns().saturating_add(u64::from(TIMEOUT_MS) * polls * 1_000_000);
for fence in &self.inputs {
for fence in self.inputs() {
loop {
if self.cancel_requested() || self.completion.status().get() != 0 {
return Err(ECANCELED);
Expand Down Expand Up @@ -292,13 +297,20 @@ impl Packet {

/// Dependency-bearing packets remain on the scheduler publication path.
pub(crate) fn has_dependencies(&self) -> bool {
!self.inputs.is_empty() || self.producers.is_some()
self.inputs().next().is_some() || self.producers.is_some()
}

/// The fences checked on the host before publication: the command's own, then its
/// submission's inputs.
fn inputs(&self) -> impl Iterator<Item = &Fence> {
let shared = self.shared_inputs.as_ref().map_or(&[][..], |inputs| inputs.fences());
Iterator::chain(self.inputs.iter(), shared)
}

/// 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()
self.inputs().next().is_some()
}

pub(crate) fn begin_publication(&self) -> bool {
Expand Down
42 changes: 20 additions & 22 deletions drivers/gpu/drm/asahi/g17/queue/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use super::{
dependency::{FailureLog, FailureRecord},
fence::{ChunkWork, Outputs},
job::{self, Backend, Engine, Fences, Order, Packet, Scheduler},
sync_input::Inputs,
validation::Proof,
};
use crate::{
Expand Down Expand Up @@ -255,6 +256,7 @@ impl<B: Backend> Queue<B> {
aggregate: &super::fence::Aggregate,
work: Option<Arc<ChunkWork>>,
inputs: &[file::SyncItem],
shared_inputs: Option<&Arc<Inputs>>,
destinations: Destinations,
batch_renders: u16,
) -> Result {
Expand Down Expand Up @@ -396,17 +398,25 @@ impl<B: Backend> Queue<B> {
});
}
let failure_count = failures.iter().flatten().count();
// Each command waits on every input its compute sources do not take over in firmware.
let command_inputs = super::sync_input::command_inputs(
shared_inputs,
inputs.iter().filter_map(|sync| sync.fence.as_ref()),
|fence| sources.as_ref().is_some_and(|sources| sources.contains_input(fence)),
)?;
let input_dependencies =
command_inputs.as_ref().map_or(&[][..], |inputs| inputs.dependencies());
let mut dependencies = KVec::with_capacity(
// The firmware-ordered producers add one scheduled fence between them.
inputs.len()
input_dependencies.len()
+ ordering_host_waits.len()
+ usize::from(!ordering_firmware_waits.is_empty())
+ failure_count,
GFP_KERNEL,
)?;
// Host-waited producers are checked on the host instead of in firmware.
let mut checked_inputs = KVec::with_capacity(
inputs.len() + ordering_host_waits.len() + failure_count,
ordering_host_waits.len() + failure_count,
GFP_KERNEL,
)?;
for fence in failures.into_iter().flatten() {
Expand Down Expand Up @@ -440,26 +450,10 @@ impl<B: Backend> Queue<B> {
prefix,
});
producer_waits.finish(|fence| Ok(dependencies.push(fence.clone(), GFP_KERNEL)?))?;
// Each command owns every input fence; independent engines may publish in
// either order and must each consume an input's error status before running.
for sync in inputs {
if let Some(fence) = &sync.fence {
if sources
.as_ref()
.is_some_and(|sources| sources.contains_input(fence))
{
continue;
}
// An input that already signalled without error orders nothing and has no status
// left to consume (like a completed frontier producer above). Keeping it would
// send the render through the scheduler thread instead of inline publication:
// most compositor and client renders carry such already-signalled buffer fences.
if job::fence_status(fence) > 0 {
continue;
}
dependencies.push(fence.clone(), GFP_KERNEL)?;
checked_inputs.push(fence.clone(), GFP_KERNEL)?;
}
// Independent engines may publish in either order and must each consume an input's error
// status before running, so every command keeps the inputs.
for fence in input_dependencies {
dependencies.push(fence.clone(), GFP_KERNEL)?;
}
if let Some(sources) = &sources {
for ready in sources.publication_waits() {
Expand All @@ -479,6 +473,7 @@ impl<B: Backend> Queue<B> {
completion,
batch_renders,
checked_inputs,
command_inputs,
producers,
)?;
let scheduler = match engine {
Expand Down Expand Up @@ -746,6 +741,8 @@ impl<B: Backend> crate::queue::Queue for Queue<B> {
0,
Some(&output_fence),
);
let shared_inputs =
Inputs::new(outputs.inputs().iter().filter_map(|sync| sync.fence.as_ref()))?;
let mut work_states = work_states.into_iter();
for (command, order, destinations) in pending.drain_all() {
let guard = guards.next().ok_or(EIO)?;
Expand All @@ -757,6 +754,7 @@ impl<B: Backend> crate::queue::Queue for Queue<B> {
&aggregate,
work_states.next(),
outputs.inputs(),
shared_inputs.as_ref(),
destinations,
batch_renders,
)?;
Expand Down
Loading
Loading