Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
634ee93
drm/asahi: g16: skip no-op publishes, batch event ring drains, and sm…
DjDeveloperr Nov 22, 2026
27a96a7
drm/asahi: g16: offload displaced render pass scrubbing to an unbound…
DjDeveloperr Nov 22, 2026
1d446f2
drm/asahi: g16: expand render pass slots to 32 in demand-grown tiers …
DjDeveloperr Nov 22, 2026
513c15b
drm/asahi: g16: parse SUBMIT streams in one pass, batch CDM gate lock…
DjDeveloperr Nov 22, 2026
1563d4b
drm/asahi: g16: use stamp-only cross-engine barriers for same-VM non-…
DjDeveloperr Nov 22, 2026
0764260
drm/asahi: use VM reservation lock for VmReadGuard and merge G16 rend…
DjDeveloperr Nov 22, 2026
19c5d8a
drm/asahi: g16: elide redundant independent FS and TA-FS render barriers
DjDeveloperr Nov 22, 2026
ba66533
drm/asahi: reuse per-queue SUBMIT cmdbuf staging and bulk-read syncs
DjDeveloperr Nov 22, 2026
94a03f5
drm/asahi: g16: raise render pass slots to 48 and tighten slot-wait r…
DjDeveloperr Nov 22, 2026
87c8f91
drm/asahi: g16: release full batched render count in commit_render()
DjDeveloperr Nov 22, 2026
c29c465
drm/asahi: g16: use usage::Lane, harden suspect aborts, calibrate wat…
DjDeveloperr Nov 23, 2026
6bc1ca4
selftests: asahi-g15: add lifetime parameter to mocked VmReadGuard
DjDeveloperr Nov 23, 2026
d1f88bb
drm/asahi: g16: deduplicate fdinfo per DRM file and accept equal time…
DjDeveloperr Nov 23, 2026
15bda88
Merge djdev/g16-perf-wave2-5 into djdev/g16-perf-wave6
DjDeveloperr Nov 24, 2026
fd49ba2
selftests: drm/asahi-m4: publish render claims mutably in test-resources
DjDeveloperr Nov 24, 2026
1c6a24d
Merge djdev/g16-perf-wave6 into djdev/g16-perf-wave7
DjDeveloperr Nov 24, 2026
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
11 changes: 7 additions & 4 deletions Documentation/gpu/asahi-usage-stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ start and end operations. The shared G17 backend runs several commands of one
queue at once, so their stages overlap. It charges each engine of a queue the
union of that queue's stage intervals (exact, because a queue's stages retire in
the order they started), so a queue never counts more than the wall time on one
engine. Queues of one file still add up. The other backends sum their intervals
without merging overlapping commands on the same engine. Missing, zero-start or
reversed intervals are ignored. Failed or cancelled commands do not contribute
incomplete intervals;
engine. Queues of one file still add up on G17. Native G16 executes pipelined
commands and dual-pipe compute across sibling queues of one DRM file, so it
unions overlapping stage intervals per file (``Client::add_union``) to keep each
engine bounded by wall time. The other backends sum their intervals without
merging overlapping commands on the same engine. Missing, zero-start or reversed
intervals are ignored. Failed or cancelled commands do not contribute incomplete
intervals;
successful stages that retired before a later failure remain counted. An
unexecuted G17 replay contributes only when it eventually retires successfully.
There is no submit-to-completion wall-time fallback in the current backends.
Expand Down
141 changes: 103 additions & 38 deletions drivers/gpu/drm/asahi/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,34 +294,45 @@ impl SyncItem {
let count = in_count.checked_add(out_count).ok_or(EOVERFLOW)?;

const STRIDE: usize = core::mem::size_of::<uapi::drm_asahi_sync>();
const CHUNK: usize = 8;
let size = STRIDE.checked_mul(count as usize).ok_or(EOVERFLOW)?;
let mut vec = KVec::with_capacity(count as usize, GFP_KERNEL)?;
let mut anchor = None;

// Read each record once so validation and use see the same retained bytes.
// Read each record once in small stack chunks so validation and use see the
// same retained bytes without a per-entry copy_from_user.
let mut reader = UserSlice::new(UserPtr::from_addr(ptr as usize), size).reader();
let mut buf = MaybeUninit::<[uapi::drm_asahi_sync; CHUNK]>::uninit();

for i in 0..count {
let mut sync: MaybeUninit<uapi::drm_asahi_sync> = MaybeUninit::uninit();
let mut base = 0u32;
while base < count {
let chunk = ((count - base) as usize).min(CHUNK);
let raw = buf.as_mut_ptr().cast::<uapi::drm_asahi_sync>();

// SAFETY: The size of `sync` is STRIDE
// SAFETY: `buf` holds `CHUNK` contiguous `drm_asahi_sync` entries and
// `chunk <= CHUNK`, so `chunk * STRIDE` bytes are writable.
reader.read_raw(unsafe {
core::slice::from_raw_parts_mut(sync.as_mut_ptr().cast::<MaybeUninit<u8>>(), STRIDE)
core::slice::from_raw_parts_mut(raw.cast::<MaybeUninit<u8>>(), chunk * STRIDE)
})?;

// SAFETY: All bit patterns in the struct are valid
let sync = unsafe { sync.assume_init() };
for offset in 0..chunk {
let i = base + offset as u32;
// SAFETY: `read_raw` initialized `chunk` contiguous entries starting at `raw`,
// `offset < chunk`, and all bit patterns in the struct are valid.
let sync = unsafe { raw.add(offset).read() };

if sync.sync_type == crate::g17::sync_output::SYNC_CUMULATIVE {
if !allow_cumulative || i < in_count || anchor.is_some() {
return Err(EINVAL);
if sync.sync_type == crate::g17::sync_output::SYNC_CUMULATIVE {
if !allow_cumulative || i < in_count || anchor.is_some() {
return Err(EINVAL);
}
anchor = Some(i as usize);
}
anchor = Some(i as usize);
vec.push(
Self::parse_one(file, sync, i >= in_count, allow_cumulative)?,
GFP_KERNEL,
)?;
}
vec.push(
Self::parse_one(file, sync, i >= in_count, allow_cumulative)?,
GFP_KERNEL,
)?;
base += chunk as u32;
}
if let Some(anchor) = anchor {
let bundle = crate::g17::sync_output::SignalBundle::new(
Expand Down Expand Up @@ -350,9 +361,42 @@ pub(crate) enum Object {
/// queues is given back once the queue itself is gone.
pub(crate) struct TableQueue {
queue: KBox<dyn queue::Queue>,
/// Reusable staging buffer for `SUBMIT` command buffers, avoiding per-submit heap
/// allocations and keeping large command buffers off the kernel stack.
cmdbuf: KVec<u8>,
_share: Option<queue_share::Share>,
}

impl TableQueue {
/// Maximum command-buffer capacity retained on a queue between submissions.
const REUSE_CMDBUF_CAP: usize = 4096;

/// Takes the cached command-buffer staging allocation so userspace copies run outside the
/// queue mutex (preventing `queue.lock()` -> `mmap_lock` lock-order inversion).
fn take_cmdbuf(&mut self) -> KVec<u8> {
core::mem::take(&mut self.cmdbuf)
}

/// Returns a cleared command-buffer allocation to the per-queue cache when within the
/// reuse capacity cap; oversized buffers are dropped.
fn return_cmdbuf(&mut self, mut buf: KVec<u8>) {
buf.clear();
if buf.capacity() > 0
&& buf.capacity() <= Self::REUSE_CMDBUF_CAP
&& buf.capacity() >= self.cmdbuf.capacity()
{
self.cmdbuf = buf;
}
}
}

fn copy_cmdbuf_from_user(buf: &mut KVec<u8>, addr: u64, size: usize) -> Result {
buf.clear();
UserSlice::new(UserPtr::from_addr(addr as usize), size)
.reader()
.read_all(buf, GFP_KERNEL)
}

impl Deref for TableQueue {
type Target = dyn queue::Queue;

Expand Down Expand Up @@ -1751,6 +1795,7 @@ impl File {
resv.fill(Arc::pin_init(
new_mutex!(TableQueue {
queue,
cmdbuf: KVec::new(),
_share: share,
}),
GFP_KERNEL,
Expand Down Expand Up @@ -1822,28 +1867,37 @@ impl File {
data.queue_id,
id
);
let mut vec = KVec::new();
let copy_commands = |bytes: &mut KVec<u8>| {
UserSlice::new(
UserPtr::from_addr(data.cmdbuf as usize),
data.cmdbuf_size as usize,
)
.reader()
.read_all(bytes, GFP_KERNEL)
};
let cmdbuf_size = data.cmdbuf_size as usize;
let guarded = gpu.as_any().is::<crate::g17::Gpu>() || gpu.tracked_submission();
// Once G17 output syncobjs are resolved, its queue must install a fence
// on every failure. Take the fallible userspace snapshot before that point.
if guarded {
copy_commands(&mut vec)?;
}
let syncs = SyncItem::parse_array(
// on every failure. Take the fallible userspace snapshot before that point,
// staging into a buffer taken from the queue's reusable cache so user
// copies never execute under `queue.lock()`.
let mut cmdbuf = if guarded {
let mut buf = queue.lock().take_cmdbuf();
if let Err(e) = copy_cmdbuf_from_user(&mut buf, data.cmdbuf, cmdbuf_size) {
queue.lock().return_cmdbuf(buf);
return Err(e);
}
Some(buf)
} else {
None
};
let syncs = match SyncItem::parse_array(
file,
data.syncs,
data.in_sync_count,
data.out_sync_count,
gpu.as_any().is::<crate::g17::Gpu>(),
)?;
) {
Ok(syncs) => syncs,
Err(e) => {
if let Some(buf) = cmdbuf {
queue.lock().return_cmdbuf(buf);
}
return Err(e);
}
};

mod_dev_dbg!(
device,
Expand All @@ -1853,22 +1907,33 @@ impl File {
id
);

// Copy the command buffer into the kernel. Because we need to iterate
// the command buffer twice, we do this in one big copy_from_user to
// avoid TOCTOU issues.
if !guarded {
copy_commands(&mut vec)?;
}
// Copy the command buffer into the kernel outside `queue.lock()`. Because we
// need to iterate the command buffer twice, we do this in one big copy_from_user
// to avoid TOCTOU issues.
let cmdbuf = match cmdbuf.take() {
Some(buf) => buf,
None => {
let mut buf = queue.lock().take_cmdbuf();
if let Err(e) = copy_cmdbuf_from_user(&mut buf, data.cmdbuf, cmdbuf_size) {
queue.lock().return_cmdbuf(buf);
return Err(e);
}
buf
}
};

let objects = file.inner().objects();
let ret = queue.lock().submit(
let mut guard = queue.lock();
let ret = guard.queue.submit(
reg_data,
id,
syncs,
data.in_sync_count as usize,
&vec,
cmdbuf.as_slice(),
objects,
);
guard.return_cmdbuf(cmdbuf);
drop(guard);

if ret.is_ok() {
if let Some((util_min, duration_ms)) = gpu.syncobj_wait_hint() {
Expand Down
12 changes: 6 additions & 6 deletions drivers/gpu/drm/asahi/g15/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ pub(crate) struct Context<'a> {
pub(crate) usc_base: u64,
}

struct CheckedContext<'a> {
vm: &'a mut mmu::VmReadGuard,
struct CheckedContext<'a, 'b> {
vm: &'a mut mmu::VmReadGuard<'b>,
usc_base: u64,
}

Expand Down Expand Up @@ -383,7 +383,7 @@ impl Timestamps<'_> {
/// GPU access: a driver range ENOENT, outside the user range EINVAL, an unmapped page ENOENT, a
/// page without the access EACCES.
pub(crate) fn cover(
vm: &mut mmu::VmReadGuard,
vm: &mut mmu::VmReadGuard<'_>,
start: u64,
end: u64,
read: bool,
Expand Down Expand Up @@ -419,7 +419,7 @@ pub(crate) fn cover(

/// Attachment spans, 128-byte granular, actually mapped with `write` or read access.
fn check_attachments(
vm: &mut mmu::VmReadGuard,
vm: &mut mmu::VmReadGuard<'_>,
list: &[uapi::drm_asahi_attachment],
write: bool,
) -> Result {
Expand Down Expand Up @@ -482,7 +482,7 @@ fn geometry_bytes(cmd: &uapi::drm_asahi_cmd_render) -> (u64, u64) {
}

/// Per-command render admission.
fn check_render(context: &mut CheckedContext<'_>, cmd: &uapi::drm_asahi_cmd_render) -> Result {
fn check_render(context: &mut CheckedContext<'_, '_>, cmd: &uapi::drm_asahi_cmd_render) -> Result {
let vm = &mut *context.vm;
let allowed = PROCESS_EMPTY_TILES
| NO_VERTEX_CLUSTERING
Expand Down Expand Up @@ -567,7 +567,7 @@ fn check_render(context: &mut CheckedContext<'_>, cmd: &uapi::drm_asahi_cmd_rend

/// Per-command compute admission.
fn check_compute(
context: &mut CheckedContext<'_>,
context: &mut CheckedContext<'_, '_>,
cmd: &uapi::drm_asahi_cmd_compute,
attachments: &[uapi::drm_asahi_attachment],
) -> Result {
Expand Down
12 changes: 6 additions & 6 deletions drivers/gpu/drm/asahi/g15/gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct Window {
impl Window {
/// The `count` words at `va`, reading whole spans of up to 256 bytes (not past the page
/// unless the record crosses it). Unreadable memory: EFAULT.
fn words(&mut self, vm: &mut mmu::VmReadGuard, va: u64, count: usize) -> Result<[u32; 10]> {
fn words(&mut self, vm: &mut mmu::VmReadGuard<'_>, va: u64, count: usize) -> Result<[u32; 10]> {
let n = count * 4;
let cached = self.len != 0
&& va >= self.va
Expand Down Expand Up @@ -112,7 +112,7 @@ struct Checked {

/// One page check of `[start, end)` under the walk's page budget: ENOSPC once the budget is
/// spent.
fn check(vm: &mut mmu::VmReadGuard, start: u64, end: u64, count: &mut u32) -> Result {
fn check(vm: &mut mmu::VmReadGuard<'_>, start: u64, end: u64, count: &mut u32) -> Result {
if *count >= CDM_MAX_PAGE_CHECKS {
return Err(ENOSPC);
}
Expand All @@ -122,7 +122,7 @@ fn check(vm: &mut mmu::VmReadGuard, start: u64, end: u64, count: &mut u32) -> Re

/// A launch's program: inside the queue's 4 GiB USC window, 64-aligned, first block readable.
/// The last proven program page is not checked again.
fn program(vm: &mut mmu::VmReadGuard, usc: u64, address: u64, checked: &mut Checked) -> Result {
fn program(vm: &mut mmu::VmReadGuard<'_>, usc: u64, address: u64, checked: &mut Checked) -> Result {
if address < usc || address - usc >= USC_WINDOW || address & 63 != 0 {
return Err(EINVAL);
}
Expand All @@ -138,7 +138,7 @@ fn program(vm: &mut mmu::VmReadGuard, usc: u64, address: u64, checked: &mut Chec

/// An indirect launch's 12 argument bytes: readable. The last proven argument page is not
/// checked again; arguments that cross a page are checked each time.
fn arguments(vm: &mut mmu::VmReadGuard, address: u64, checked: &mut Checked) -> Result {
fn arguments(vm: &mut mmu::VmReadGuard<'_>, address: u64, checked: &mut Checked) -> Result {
let end = address.checked_add(12).ok_or(EINVAL)?;
let page = address & !(mmu::UAT_PGMSK as u64);
let within = (end - 1) & !(mmu::UAT_PGMSK as u64) == page;
Expand All @@ -154,7 +154,7 @@ fn arguments(vm: &mut mmu::VmReadGuard, address: u64, checked: &mut Checked) ->

/// VDM admission: a normal root stream opens with the G15 barrier, with or
/// without the USC cache invalidate.
pub(crate) fn vdm(vm: &mut mmu::VmReadGuard, va: u64) -> Result {
pub(crate) fn vdm(vm: &mut mmu::VmReadGuard<'_>, va: u64) -> Result {
if !params::stream_gate() {
return Ok(());
}
Expand All @@ -170,7 +170,7 @@ pub(crate) fn vdm(vm: &mut mmu::VmReadGuard, va: u64) -> Result {
/// CDM admission: walks the stream from its base through no-return links until TERMINATE,
/// admitting only the known G15S records: direct launch (40), indirect launch (36/24), barriers
/// (4), link (8).
pub(crate) fn cdm(vm: &mut mmu::VmReadGuard, usc: u64, base: u64) -> Result {
pub(crate) fn cdm(vm: &mut mmu::VmReadGuard<'_>, usc: u64, base: u64) -> Result {
if !params::stream_gate() {
return Ok(());
}
Expand Down
Loading