Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH i-g-t v1 0/4] lib/amdgpu: refactor cmd_context ownership and packet operands
@ 2026-08-21 12:41 Junhua Shen
  2026-08-21 12:41 ` [PATCH i-g-t v1 1/4] lib/amdgpu: document amdgpu_ring_context field contract Junhua Shen
                   ` (7 more replies)
  0 siblings, 8 replies; 11+ messages in thread
From: Junhua Shen @ 2026-08-21 12:41 UTC (permalink / raw)
  To: igt-dev
  Cc: Vitaly Prosyak, Jesse Zhang, Sunil Khatri, Honglei Huang,
	Huang Rui, Yiru Ma, Junhua Shen

This series refactors the amdgpu command-submission helper library
(lib/amdgpu/amd_command_submission.*) around a single principle:
cmd_context should own only the PM4/IB command stream, while the buffers
those commands read and write, together with their GPU virtual addresses,
are supplied and kept resident by the caller.

Currently cmd_context both builds the PM4 stream and allocates and clears
an internal data BO, and several IB and packet sizes are derived from the
data transfer size (write_length) rather than from the command-stream
capacity (pm4_size). This couples unrelated concerns, hides residency
management from callers, and leaves the IB size ambiguous. The series
separates these concerns incrementally while keeping every existing
caller compiling and functional.

Scope: cmd_context is a convenience wrapper for SDMA data operations
(linear write/copy/const-fill/atomic). Only three tests currently use it
(amd_mem, amd_dmabuf_unload, amd_kfd_dmabuf_unload); the rest of the
amdgpu tests deliberately drive libdrm_amdgpu directly to validate the
kernel submission UAPI (cs_submit, bo_list, syncobj, gang, compute
dispatch), and are intentionally left untouched. The ring_context field
usage in those low-level callers is already consistent with the contract
documented here, so no changes are required on their side.

Overview of the changes
-----------------------
1. document amdgpu_ring_context field contract
   Add IN/OUT/INTERNAL annotations to struct amdgpu_ring_context so the
   ownership and direction of each field is unambiguous before the
   behavioural changes are introduced. Documentation only, no functional
   change.

2. drop external BO from cmd_context
   cmd_context no longer allocates, tracks, or clears a caller-visible
   data BO. Callers now register the residency of those buffers
   explicitly via the new cmd_context_add_resource(). cmd_context_create()
   loses the write_length parameter (the IB is sized from pm4_size alone)
   and all call sites are updated (amd_dmabuf_unload.c,
   amd_kfd_dmabuf_unload.c, amd_mem.c).

3. source packet operands from params and size the IB from pm4_size
   The legacy IB byte size is now derived from pm4_size (the command
   stream capacity), not write_length (the data transfer size).
   WRITE_LINEAR, WRITE_ATOMIC and COPY_LINEAR take their source and
   destination GPU virtual addresses from cmd_packet_params_t, so callers
   pass those addresses directly rather than relying on context-internal
   BOs.

4. add CONST_FILL packet type and pass caller fill value through
   Add a CMD_PACKET_CONST_FILL packet type with a per-packet size guard,
   and propagate the caller-supplied fill value
   (write_data/write_data_valid) through write_linear and const_fill in
   the IP block builders.

Testing
-------
Ran on local hardware: AMD GFX1036 (GFX10_3). The three cmd_context
callers (amd_mem, amd_dmabuf_unload, amd_kfd_dmabuf_unload) and the
low-level tests that exercise the changed shared code (amd_basic SDMA and
compute submission, amd_userptr_invalidation) all pass. There is no
regression from this series.

Known limitations / follow-up work
----------------------------------
The following items are intentionally excluded from this series to limit
its scope; they are candidates for follow-up patches:

- pm4_size is currently a hard-coded 256 dwords in cmd_context_create().
  It should become a caller-provided parameter (or be derived from the
  expected packet mix) so large PM4 streams are not silently truncated.

- The residency set (amdgpu_ring_context.resources[]) is a fixed-size
  array (4 entries). cmd_context_add_resource() returns -ENOSPC when it
  overflows; a growable set would remove that limit for callers that
  require more operands per submit.

- Some low-level callers open-code the same linear write/copy/fill
  sequences that cmd_context now wraps. Where a test only needs the data
  operation itself (and is not specifically exercising the submission
  UAPI), it could be migrated onto the high-level cmd_context API to
  remove boilerplate. Tests that deliberately drive libdrm_amdgpu to
  validate cs_submit/bo_list/syncobj/gang/compute paths should stay as
  they are.

Junhua Shen (4):
  lib/amdgpu: document amdgpu_ring_context field contract
  lib/amdgpu: drop external BO from cmd_context
  lib/amdgpu: source packet operands from params and size the IB from
    pm4_size
  lib/amdgpu: add CONST_FILL packet type and pass caller fill value
    through

 lib/amdgpu/amd_command_submission.c  | 385 ++++++++++++++-------------
 lib/amdgpu/amd_command_submission.h  | 102 ++++++-
 lib/amdgpu/amd_ip_blocks.c           |  20 +-
 lib/amdgpu/amd_ip_blocks.h           |  59 +++-
 tests/amdgpu/amd_dmabuf_unload.c     |  15 +-
 tests/amdgpu/amd_kfd_dmabuf_unload.c |  15 +-
 tests/amdgpu/amd_mem.c               |  22 +-
 7 files changed, 378 insertions(+), 240 deletions(-)

-- 
2.34.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-09-09  8:00 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-21 12:41 [PATCH i-g-t v1 0/4] lib/amdgpu: refactor cmd_context ownership and packet operands Junhua Shen
2026-08-21 12:41 ` [PATCH i-g-t v1 1/4] lib/amdgpu: document amdgpu_ring_context field contract Junhua Shen
2026-08-21 12:41 ` [PATCH i-g-t v1 2/4] lib/amdgpu: drop external BO from cmd_context Junhua Shen
2026-08-25 10:18   ` Zhang, Jesse(Jie)
2026-09-09  7:59     ` Junhua Shen
2026-08-21 12:41 ` [PATCH i-g-t v1 3/4] lib/amdgpu: source packet operands from params and size the IB from pm4_size Junhua Shen
2026-08-21 12:41 ` [PATCH i-g-t v1 4/4] lib/amdgpu: add CONST_FILL packet type and pass caller fill value through Junhua Shen
2026-08-25  0:05 ` ✓ Xe.CI.BAT: success for lib/amdgpu: refactor cmd_context ownership and packet operands Patchwork
2026-08-25  0:17 ` ✓ i915.CI.BAT: " Patchwork
2026-08-25  3:57 ` ✓ Xe.CI.FULL: " Patchwork
2026-08-25  4:31 ` ✗ i915.CI.Full: failure " Patchwork

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox