drm/amdgpu: add GL2 HT threshold debugfs placeholder for gfx12.1
Subsystems (3)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/2 drm/amdgpu: add persisting GL2 cache size support for gfx12.1
Expose a new "persisting GL2 cache size" property for GC 12.1.0 through two interfaces:
- AMDGPU_INFO ioctl: report the per-GL2-instance maximum (in bytes) through the new AMDGPU_INFO_GL2_PERSISTING_CACHE_SIZE_MAX query.
- DRM_IOCTL_AMDGPU_VM: let user mode (e.g. ROCr) request a persisting cache size for its VM via the new AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE op (the size in bytes is carried in the flags/size union of drm_amdgpu_vm_in), and read the current request back via AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE_GET (returned in the size field of drm_amdgpu_vm_out). Exposing both on the render node lets a request be saved and restored through the same interface it was configured on (e.g. CRIU checkpoint/restore). The default is 0.
The persisting GL2 cache is accounted per GL2 instance, the granularity at which GL2 and its residency control are physically partitioned. The generic gfx layer stays ASIC-agnostic and learns the number of GL2 instances and the instance(s) backing a GPU partition through SOC callbacks. On gfx12.1 a GL2 instance maps 1:1 to an AID (gc12.1.0 has up to 2 AIDs, each with its own L2 shared by its XCDs), so those callbacks are implemented in terms of the device's AID mask.
The sizing comes from the IP discovery GC info table (gc_info v1.5):gc_cache_ways_size_in_bytes is the persisting budget for the whole device (the total across all GL2 instances, e.g. 12MB on a 2-instance gc12.1.0) and gc_max_num_residency_ways is the way cap. The per-instance maximum reported to user mode is derived on demand as the total budget divided by the number of GL2 instances (amdgpu_gfx_gl2_persisting_max_per_instance()); a table that does not advertise a budget self-gates the feature to 0.
A requested size is translated into the 4-bit GL2C_RESIDENCY_CTRL.RESIDENCY_WAYS field and programmed by a new gfx12.1 callback. The mapping is linear: 0 bytes disables it, the per-instance maximum maps to gc_max_num_residency_ways ways, and intermediate sizes scale proportionally, clamped to the way cap.
The feature is only offered in the SPX and DPX compute partition modes, where a partition maps to whole GL2 instances that it owns exclusively (on gfx12.1: SPX owns all AIDs; DPX owns one AID each). In TPX/QPX/CPX several partitions share a single GL2 instance's L2, so the per-instance request model does not apply: the AMDGPU_INFO query reports 0 and AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE returns -EOPNOTSUPP (amdgpu_gfx_gl2_residency_mode_supported()).
Each request is scoped to the GL2 instances of the process's GPU partition (derived from the file private's xcp_id) and added to a per-instance running total kept by a device-wide manager; the VM remembers its own contribution so it can be removed again when the request changes or the VM is torn down. The hardware is programmed from the per-instance aggregate of all requests, clamped to the per-instance maximum:
- a single process controls its instances' setting directly;
- processes that share a GL2 instance (multiple processes in the same partition) have their sizes summed for that instance;
- when the last requester on a GL2 instance goes away the aggregate is 0, resetting RESIDENCY_WAYS to 0 for that idle instance.
The GL2C_RESIDENCY_CTRL register is not yet in the public register headers, so its offset is defined locally in the gfx12.1 code.
Bump the KMS driver minor version so user space can detect the new UAPI.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 7 + drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 272 ++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 55 ++++ drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 48 +++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 7 + drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 114 ++++++++ include/uapi/drm/amdgpu_drm.h | 23 +- 9 files changed, 525 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +7 -0
@@ -286,6 +286,13 @@ static int hw_id_map[MAX_HWIP] = { [UMSCH_HWIP] = UMSCH_HWID, [ISP_HWIP] = ISP_HWID, [ATU_HWIP] = ATU_HWID, +/* +* AID-GC block (per-AID GC, hosts the AID-resident GL2). Needed so +* reg_offset[AIGC_HWIP][aid] is populated from IP discovery and the +* per-AID GL2 registers (e.g. GL2C_RESIDENCY_CTRL) can be reached via +* RREG32_SOC15(AIGC, aid, ...). Only enumerated on gfx12.1+ (MI400). +*/ + [AIGC_HWIP] = AIGC_HWID, }; static int amdgpu_discovery_get_tmr_info(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +3 -1
@@ -128,9 +128,11 @@* - 3.63.0 - GFX12 display DCC supports 256B max compressed block size * - 3.64.0 - Userq IP support query * - 3.65.0 - Add userq syncobj timeline signaling support +* - 3.66.0 - Add persisting GL2 cache size query, AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE and +* AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE_GET */ #define KMS_DRIVER_MAJOR 3 -#define KMS_DRIVER_MINOR 65 +#define KMS_DRIVER_MINOR 66#define KMS_DRIVER_PATCHLEVEL 0/*
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +272 -0
278 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +55 -0
79 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +3 -0
@@ -1389,6 +1389,9 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)kfree (caps);return r; } +case AMDGPU_INFO_GL2_PERSISTING_CACHE_SIZE_MAX : + ui32 =amdgpu_gfx_gl2_persisting_max_per_instance (adev); +return copy_to_user (out, &ui32,min (size,4u )) ? -EFAULT :0 ;case AMDGPU_INFO_MAX_IBS : {uint32_t max_ibs[AMDGPU_HW_IP_NUM ];
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +44 -4
73 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +7 -0
@@ -378,6 +378,13 @@ struct amdgpu_vm {/* cached fault info */ struct amdgpu_vm_fault_info fault_info; + +/* This VM's persisting GL2 cache request (gfx12.1), tracked so the gfx +* arbiter can adjust its per-instance running total on update/teardown +* and read it back (AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE_GET). +*/ +u32 gl2_persisting_size;/* bytes */ +u32 gl2_persisting_instance_mask;/* GL2 instances it applies to */ };struct amdgpu_vm_manager {
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +114 -0
150 lines not on this page · raw message
include/uapi/drm/amdgpu_drm.h +20 -3
@@ -645,16 +645,31 @@ union drm_amdgpu_sem {/* vm ioctl */ #define AMDGPU_VM_OP_RESERVE_VMID 1#define AMDGPU_VM_OP_UNRESERVE_VMID 2 +#define AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE 3 +#define AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE_GET 4struct drm_amdgpu_vm_in {/** AMDGPU_VM_OP_* */ __u32 op; -__u32 flags; +union { +__u32 flags; +/** Requested persisting GL2 cache size in bytes. +* Only used by AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE. +*/ +__u32 size; + }; };struct drm_amdgpu_vm_out { -/** For future use, no flags defined so far */ -__u64 flags; +union { +/** For future use, no flags defined so far */ +__u64 flags; +/** Current persisting GL2 cache size in bytes requested by +* this VM. Returned by +* AMDGPU_VM_OP_GL2_PERSISTING_L2_CACHE_GET. +*/ +__u64 size; + }; };union drm_amdgpu_vm {
@@ -1330,6 +1345,8 @@ struct drm_amdgpu_cs_chunk_cp_gfx_shadow {#define AMDGPU_INFO_GPUVM_FAULT 0x23/* query FW object size and alignment */ #define AMDGPU_INFO_UQ_FW_AREAS 0x24 +/* Max persisting GL2 cache size in bytes (gfx12.1+, 0 on chips without it) */ +#define AMDGPU_INFO_GL2_PERSISTING_CACHE_SIZE_MAX 0x25/* Hybrid Stack Specific Defs*/ /* gpu capability */
Signature · 1 line
2.34.1
PATCH 2/2 drm/amdgpu: add GL2 HT threshold debugfs placeholder for gfx12.1
Expose the GL2 high-temporal residency threshold (GL2C_RESIDENCY_CTRL.REG_THRESHOLD) through a new per-device debugfs file, /sys/kernel/debug/dri/*/amdgpu_gl2_ht_threshold.
A read returns the current threshold as a decimal number; a write parses a decimal value and range-checks it against the field width. The get/set logic is implemented as gfx_funcs callbacks in gfx_v12_1, so the file is only created on ASICs that support the feature (GC IP >= 12.1.0).
--- drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 92 +++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h | 12 +++ drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c | 51 ++++++++++++ 4 files changed, 156 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -0
@@ -2216,6 +2216,7 @@ int amdgpu_debugfs_init(struct amdgpu_device *adev)amdgpu_debugfs_jpeg_sched_mask_init (adev);amdgpu_debugfs_gfx_sched_mask_init (adev);amdgpu_debugfs_compute_sched_mask_init (adev); +amdgpu_debugfs_gl2_ht_threshold_init (adev);amdgpu_debugfs_sdma_sched_mask_init (adev);amdgpu_ras_debugfs_create_all (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +92 -0
98 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +12 -0
@@ -398,6 +398,12 @@ struct amdgpu_gfx_funcs {* persisting GL2 cache is accounted and programmed. SOC-specific. */ u32 (*get_num_gl2_instances)(struct amdgpu_device *adev); +/* Get/set the GL2 high-temporal residency threshold +* (GL2C_RESIDENCY_CTRL.REG_THRESHOLD). Only implemented on ASICs that +* support the feature; used to expose it through debugfs. +*/ +int (*get_gl2_ht_threshold)(struct amdgpu_device *adev,u32 *val); +int (*set_gl2_ht_threshold)(struct amdgpu_device *adev,u32 val); };struct sq_work {
@@ -607,6 +613,11 @@ struct amdgpu_gfx {/* Persisting GL2 cache request accounting (gfx12.1+) */ struct amdgpu_gl2_persisting_mgr gl2_persisting; + +/* Placeholder software shadow of GL2C_RESIDENCY_CTRL.REG_THRESHOLD +* until the real register access is wired up (gfx12.1+). +*/ +u32 gl2_ht_threshold; };struct amdgpu_gfx_deferred_entry {
@@ -755,6 +766,7 @@ void amdgpu_gfx_csb_preamble_end(u32 *buffer, u32 count);void amdgpu_debugfs_gfx_sched_mask_init (struct amdgpu_device *adev);void amdgpu_debugfs_compute_sched_mask_init (struct amdgpu_device *adev); +void amdgpu_debugfs_gl2_ht_threshold_init (struct amdgpu_device *adev);int amdgpu_gfx_ring_preempt_ib (struct amdgpu_ring *ring);
drivers/gpu/drm/amd/amdgpu/gfx_v12_1.c +51 -0
69 lines not on this page · raw message
Signature · 1 line
2.34.1