Grab bag of size savings, or amdgpu goes on the pen
cover Grab bag of size savings, or amdgpu goes on the pen
Removing almost half a megabyte of redundant instructions is not bad for a mornings work:
add/remove: 18/39 grow/shrink: 78/1161 up/down: 21752/-473345 (-451593)
...
Total: Before=9421643, After=8970050, chg -4.79%
Smoke tested on the Steam Deck but not very thoroughly.
Important to note is that I still do not see a problem in either VCE or UVD6 which Alex was detecting. But as I had some more shrinkage ideas I thought to float them and see what sticks.
Also, one of the concepts from the series, the one starting in "drm/amdgpu/sdma5.2: Use local variables more" could be replicated to more files if there is interest for me to do so.
Otherwise I suppose I am most curious about the feedback on the SOC15 RLC and instance map patches, since they are the ones which remove the most of redundant code. For example it is possible I missed some important gotcha which would make them not as simple as they currently are.
Tvrtko Ursulin (25):
drm/amdgpu/vcn4.0.3: Use an existing local variable drm/amdgpu/jpeg3.0 Simplify idle check
drm/amdgpu: Choose SOC15 RLC register read write functions at init
time
drm/amdgpu: Only calculate register offset once in SOC15 RLC drm/amdgpu: Extend logical to device instance lookup to all devices drm/amdgpu/gfx10.0: More compact reading of wave data drm/amdgpu/sdma5.2: Use local variables more drm/amdgpu/vcn2.0: Use local variables more drm/amdgpu/vcn3.0.0: Use local variables more drm/amdgpu/jpeg: Use more local variables
drm/amdgpu: More compact VCE IB emission
drm/amdgpu: More compact VCN IB emission
drm/amdgpu: More compact UVD 6 IB emission
drm/amdgpu: More compact UVD 7 IB emission
drm/amdgpu: More compact SI SDMA emission
drm/amdgpu: More compact CIK SDMA IB emission drm/amdgpu: More compact GFX 9.4.2 IB emission drm/amdgpu: More compact SDMA 2.4 IB emission drm/amdgpu: More compact SDMA 3.0 IB emission drm/amdgpu: More compact SDMA 4.0 IB emission drm/amdgpu: More compact SDMA 4.4.2 IB emission drm/amdgpu: More compact SDMA 5.0 IB emission drm/amdgpu: More compact SDMA 5.2 IB emission drm/amdgpu: More compact SDMA 6.0 IB emission drm/amdgpu: More compact SDMA 7.0 IB emission
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 +- .../drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c | 1 + .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 + drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 49 +-- drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h | 15 + drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 11 +- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c | 39 +++ drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h | 10 + drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 96 +++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 134 ++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 1 + drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 2 +- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 105 ++++--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 40 ++- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 + drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c | 51 +-- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 10 +- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 7 +- drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 1 + drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c | 1 + drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 108 ++++--- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 108 ++++--- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 109 ++++--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 109 ++++--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 106 ++++--- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 295 ++++++++++-------- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 110 ++++--- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 119 ++++--- drivers/gpu/drm/amd/amdgpu/si_dma.c | 84 +++-- drivers/gpu/drm/amd/amdgpu/soc15_common.h | 61 ++-- drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 72 +++-- drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c | 72 +++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 72 +++-- drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 9 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 3 +- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 1 + drivers/gpu/drm/amd/amdkfd/kfd_device.c | 1 + .../drm/amd/pm/swsmu/smu13/smu_v13_0_12_ppt.c | 1 + .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 1 + drivers/gpu/drm/amd/ras/ras_mgr/ras_sys.h | 7 +- 56 files changed, 1203 insertions(+), 849 deletions(-)
Signature · 1 line
2.48.0
RFC 1/25 drm/amdgpu/vcn4.0.3: Use an existing local variable
There is already a cached vcn instance in vcn_v4_0_3_ring_reset() so lets use it.
--- drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1 -1
@@ -1619,7 +1619,7 @@ static int vcn_v4_0_3_ring_reset(struct amdgpu_ring *ring,if (RREG32_SOC15 (VCN ,GET_INST (VCN ,0 ), regVCN_RRMT_CNTL) &0x100 ) adev->vcn.caps |=AMDGPU_VCN_CAPS (RRMT_ENABLED );vcn_v4_0_3_hw_init_inst (vinst); -vcn_v4_0_3_start_dpg_mode (vinst, adev->vcn.inst[ring->me].indirect_sram); +vcn_v4_0_3_start_dpg_mode (vinst, vinst->indirect_sram);return amdgpu_ring_reset_helper_end (ring, timedout_fence); }
Signature · 1 line
2.48.0
RFC 2/25 drm/amdgpu/jpeg3.0 Simplify idle check
In reply to Tvrtko UrsulinSimplify the idle check by looking at the done bit directly instead of clearing the assumed idle status if not done.
--- drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/jpeg_v3_0.c +2 -5
@@ -476,13 +476,10 @@ static void jpeg_v3_0_dec_ring_set_wptr(struct amdgpu_ring *ring)static bool jpeg_v3_0_is_idle (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -int ret =1 ; - ret &= (((RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS) & +return (RREG32_SOC15 (JPEG ,0 , mmUVD_JRBC_STATUS) &UVD_JRBC_STATUS__RB_JOB_DONE_MASK ) == -UVD_JRBC_STATUS__RB_JOB_DONE_MASK )); - -return ret; +UVD_JRBC_STATUS__RB_JOB_DONE_MASK ; }static int jpeg_v3_0_wait_for_idle (struct amdgpu_ip_block *ip_block)
Signature · 1 line
2.48.0
RFC 3/25 drm/amdgpu: Choose SOC15 RLC register read write functions at init time
In reply to Tvrtko UrsulinCurrently on every RLC register read the driver checks for three different conditions to decide which of the two register read/write functions to call.
As these register operations are macros, which is required for register name expansion to work, the result is a significant explosion of generated (redundant) code which the compiler cannot optimise away.
We however know that all of the three conditional are static and can therefore move the decision to driver init time. All that we need to do is define a new vfunc table for the SOC12 RLC read/write functions and just use them directly.
Bloat-o-meter agrees the driver size savings are significant:
add/remove: 9/31 grow/shrink: 74/1012 up/down: 39784/-381724 (-341940)
...
Total: Before=9421643, After=9079703, chg -3.63%
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c | 39 ++++++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h | 10 ++++++ drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 2 ++ drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 2 ++ drivers/gpu/drm/amd/amdgpu/soc15_common.h | 8 ++--- 9 files changed, 62 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
@@ -4558,6 +4558,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->gfx.workload_profile_mutex);mutex_init (&adev->vcn.workload_profile_mutex); +amdgpu_early_init_rlc_reg_funcs (adev);amdgpu_device_init_apu_flags (adev); r =amdgpu_device_check_arguments (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.c +39 -0
@@ -548,3 +548,42 @@ int amdgpu_gfx_rlc_init_microcode(struct amdgpu_device *adev,return 0 ; } + +static const struct amdgpu_rlc_reg_funcs amdgpu_sriov_rlc_reg_funcs = { + .rreg32 = amdgpu_sriov_rreg, + .wreg32 = amdgpu_sriov_wreg, +}; + +static u32 +amdgpu_rlc_rreg (struct amdgpu_device *adev,u32 reg,u32 acc_flags,u32 hwip, +u32 xcc_id) +{ +return amdgpu_device_rreg (adev, reg,0 ); +} + +static void +amdgpu_rlc_wreg (struct amdgpu_device *adev,u32 reg,u32 value,u32 acc_flags, +u32 hwip,u32 xcc_id) +{ +amdgpu_device_wreg (adev, reg, value,0 ); +} + +static const struct amdgpu_rlc_reg_funcs amdgpu_rlc_reg_funcs = { + .rreg32 = amdgpu_rlc_rreg, + .wreg32 = amdgpu_rlc_wreg, +}; + +void amdgpu_early_init_rlc_reg_funcs (struct amdgpu_device *adev) +{ + adev->gfx.rlc.reg_funcs = &amdgpu_rlc_reg_funcs; +} + +void amdgpu_init_rlc_reg_funcs (struct amdgpu_device *adev) +{ +if (amdgpu_sriov_vf (adev) && + adev->gfx.rlc.funcs && + adev->gfx.rlc.rlcg_reg_access_supported) + adev->gfx.rlc.reg_funcs = &amdgpu_sriov_rlc_reg_funcs; +else + adev->gfx.rlc.reg_funcs = &amdgpu_rlc_reg_funcs; +}
drivers/gpu/drm/amd/amdgpu/amdgpu_rlc.h +10 -0
@@ -261,6 +261,11 @@ struct amdgpu_rlc_funcs {bool (*is_rlcg_access_range)(struct amdgpu_device *adev,uint32_t reg); }; +struct amdgpu_rlc_reg_funcs { +u32 (*rreg32)(struct amdgpu_device *adev,u32 reg,u32 acc_flags,u32 hwip,u32 xcc_id); +void (*wreg32)(struct amdgpu_device *adev,u32 reg,u32 val,u32 acc_flags,u32 hwip,u32 xcc_id); +}; +struct amdgpu_rlcg_reg_access_ctrl {uint32_t scratch_reg0;uint32_t scratch_reg1;
@@ -293,6 +298,7 @@ struct amdgpu_rlc {/* safe mode for updating CG/PG state */ bool in_safe_mode[AMDGPU_MAX_RLC_INSTANCES ];const struct amdgpu_rlc_funcs *funcs; +const struct amdgpu_rlc_reg_funcs *reg_funcs;/* for firmware data */ u32 save_and_restore_offset;
@@ -360,4 +366,8 @@ void amdgpu_gfx_rlc_fini(struct amdgpu_device *adev);int amdgpu_gfx_rlc_init_microcode (struct amdgpu_device *adev,uint16_t version_major,uint16_t version_minor); + +void amdgpu_early_init_rlc_reg_funcs (struct amdgpu_device *adev); +void amdgpu_init_rlc_reg_funcs (struct amdgpu_device *adev); +#endif
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +2 -0
@@ -7827,6 +7827,8 @@ static int gfx_v10_0_early_init(struct amdgpu_ip_block *ip_block)/* init rlcg reg access ctrl */ gfx_v10_0_init_rlcg_reg_access_ctrl (adev); +amdgpu_init_rlc_reg_funcs (adev); +return gfx_v10_0_init_microcode (adev); }
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2 -0
@@ -5258,6 +5258,8 @@ static int gfx_v11_0_early_init(struct amdgpu_ip_block *ip_block)gfx_v11_0_init_rlcg_reg_access_ctrl (adev); +amdgpu_init_rlc_reg_funcs (adev); +return gfx_v11_0_init_microcode (adev); }
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2 -0
@@ -3873,6 +3873,8 @@ static int gfx_v12_0_early_init(struct amdgpu_ip_block *ip_block)gfx_v12_0_init_rlcg_reg_access_ctrl (adev); +amdgpu_init_rlc_reg_funcs (adev); +return gfx_v12_0_init_microcode (adev); }
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -0
@@ -4812,6 +4812,8 @@ static int gfx_v9_0_early_init(struct amdgpu_ip_block *ip_block)/* init rlcg reg access ctrl */ gfx_v9_0_init_rlcg_reg_access_ctrl (adev); +amdgpu_init_rlc_reg_funcs (adev); +return gfx_v9_0_init_microcode (adev); }
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +2 -0
@@ -2520,6 +2520,8 @@ static int gfx_v9_4_3_early_init(struct amdgpu_ip_block *ip_block)/* init rlcg reg access ctrl */ gfx_v9_4_3_init_rlcg_reg_access_ctrl (adev); +amdgpu_init_rlc_reg_funcs (adev); +return gfx_v9_4_3_init_microcode (adev); }
drivers/gpu/drm/amd/amdgpu/soc15_common.h +2 -6
@@ -38,14 +38,10 @@ (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + (reg)+(offset))#define __WREG32_SOC15_RLC__ (reg, value, flag, hwip, inst) \ - ((amdgpu_sriov_vf(adev) && adev->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported) ? \ - amdgpu_sriov_wreg(adev, reg, value, flag, hwip, inst) : \ - WREG32(reg, value)) + adev->gfx.rlc.reg_funcs->wreg32(adev, reg, value, flag, hwip, inst)#define __RREG32_SOC15_RLC__ (reg, flag, hwip, inst) \ - ((amdgpu_sriov_vf(adev) && adev->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported) ? \ - amdgpu_sriov_rreg(adev, reg, flag, hwip, inst) : \ - RREG32(reg)) + adev->gfx.rlc.reg_funcs->rreg32(adev, reg, flag, hwip, inst)#define WREG32_FIELD15 (ip, idx, reg, field, val) \ __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \
Signature · 1 line
2.48.0
RFC 4/25 drm/amdgpu: Only calculate register offset once in SOC15 RLC
In reply to Tvrtko UrsulinWe can save some text by only calculating the register offset once in a few of the SOC15 RLC register read/write macros.
add/remove: 0/0 grow/shrink: 2/65 up/down: 32/-1078 (-1046)
Total: Before=9079703, After=9078657, chg -0.01%
--- drivers/gpu/drm/amd/amdgpu/soc15_common.h | 47 +++++++++++++---------- 1 file changed, 27 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/soc15_common.h +27 -20
@@ -43,21 +43,25 @@#define __RREG32_SOC15_RLC__ (reg, flag, hwip, inst) \ adev->gfx.rlc.reg_funcs->rreg32(adev, reg, flag, hwip, inst) -#define WREG32_FIELD15 (ip, idx, reg, field, val) \ - __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ - (__RREG32_SOC15_RLC__( \ - adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ - 0, ip##_HWIP, idx) & \ - ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field), \ - 0, ip##_HWIP, idx) +#define WREG32_FIELD15 (ip, idx, reg_name, field, val) \ +do { \ + u32 reg__ = adev->reg_offset[ip##_HWIP][idx][mm##reg_name##_BASE_IDX] + mm##reg_name; \ + u32 val__ = __RREG32_SOC15_RLC__(reg__, 0, ip##_HWIP, idx); \ +\ + val__ &= ~REG_FIELD_MASK(reg_name, field); \ + val__ |= (val) << REG_FIELD_SHIFT(reg_name, field); \ + __WREG32_SOC15_RLC__(reg__, val__, 0, ip##_HWIP, idx); \ +} while (0) -#define WREG32_FIELD15_PREREG (ip, idx, reg_name, field, val) \ - __WREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][reg##reg_name##_BASE_IDX] + reg##reg_name, \ - (__RREG32_SOC15_RLC__( \ - adev->reg_offset[ip##_HWIP][idx][reg##reg_name##_BASE_IDX] + reg##reg_name, \ - 0, ip##_HWIP, idx) & \ - ~REG_FIELD_MASK(reg_name, field)) | (val) << REG_FIELD_SHIFT(reg_name, field), \ - 0, ip##_HWIP, idx) +#define WREG32_FIELD15_PREREG (ip, idx, reg_name, field, val) \ +do { \ + u32 reg__ = adev->reg_offset[ip##_HWIP][idx][reg##reg_name##_BASE_IDX] + reg##reg_name; \ + u32 val__ = __RREG32_SOC15_RLC__(reg__, 0, ip##_HWIP, idx); \ +\ + val__ &= ~REG_FIELD_MASK(reg_name, field); \ + val__ |= (val) << REG_FIELD_SHIFT(reg_name, field); \ + __WREG32_SOC15_RLC__(reg__, val__, 0, ip##_HWIP, idx); \ +} while (0)#define RREG32_SOC15 (ip, inst, reg) \ __RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \
@@ -177,12 +181,15 @@WREG32_RLC_EX (prefix, target_reg, value, inst); \ } while (0) -#define WREG32_FIELD15_RLC (ip, idx, reg, field, val) \ - __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg), \ - (__RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \ - AMDGPU_REGS_RLC, ip##_HWIP, idx) & \ - ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field), \ - AMDGPU_REGS_RLC, ip##_HWIP, idx) +#define WREG32_FIELD15_RLC (ip, idx, reg_name, field, val) \ +do { \ + u32 reg__ = adev->reg_offset[ip##_HWIP][idx][mm##reg_name##_BASE_IDX] + mm##reg_name; \ + u32 val__ = __RREG32_SOC15_RLC__(reg__, AMDGPU_REGS_RLC, ip##_HWIP, idx); \ +\ + val__ &= ~REG_FIELD_MASK(reg_name, field); \ + val__ |= (val) << REG_FIELD_SHIFT(reg_name, field); \ + __WREG32_SOC15_RLC__(reg__, val__, AMDGPU_REGS_RLC, ip##_HWIP, idx); \ +} while (0)#define WREG32_SOC15_OFFSET_RLC (ip, inst, reg, offset, value) \ __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, value, AMDGPU_REGS_RLC, ip##_HWIP, inst)
Signature · 1 line
2.48.0
RFC 5/25 drm/amdgpu: Extend logical to device instance lookup to all devices
In reply to Tvrtko UrsulinA subset of supported devices can have a mismatch between the logical and device engine instance numbers which the driver currently solves by a combination of lookup table generated at driver init time, and a conditionally set vfunc checked and used at runtime to do the lookup.
As the requirement to do these lookups is relatively widespread in the code base, plus the fact the mapping table is already allocated for all possible hw ips and instances, we can significantly streamline them by initializing the said lookup table unconditionally to the predominant "identity map" (logical instance numbers equal to device instances), and allow affected parts to re-configure the table based on their configuration.
The effect is that for each lookup site we replace the conditional followed by a indirect function call with a simple two-dimensional table lookup.
Bloat-o-meter agrees the savings are significant:
add/remove: 13/11 grow/shrink: 12/178 up/down: 49091/-148553 (-99462)
...
Total: Before=9078695, After=8979233, chg -1.10%
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 8 +-- .../drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c | 1 + .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 + drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c | 49 +++++++------------ drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h | 15 ++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 1 + drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c | 1 + drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c | 2 +- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c | 8 +-- drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c | 1 + drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c | 1 + drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c | 1 + drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c | 1 + drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 1 + drivers/gpu/drm/amd/amdgpu/soc15_common.h | 6 +-- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c | 1 + drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c | 1 + drivers/gpu/drm/amd/amdkfd/kfd_device.c | 1 + .../drm/amd/pm/swsmu/smu13/smu_v13_0_12_ppt.c | 1 + .../drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c | 1 + drivers/gpu/drm/amd/ras/ras_mgr/ras_sys.h | 7 ++- 35 files changed, 72 insertions(+), 52 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -7
@@ -813,13 +813,7 @@ enum amd_hw_ip_block_type {struct amdgpu_ip_map_info {/* Map of logical to actual dev instances/mask */ -uint32_t dev_inst[MAX_HWIP ][HWIP_MAX_INSTANCE ]; -int8_t (*logical_to_dev_inst)(struct amdgpu_device *adev, -enum amd_hw_ip_block_type block, -int8_t inst); -uint32_t (*logical_to_dev_mask)(struct amdgpu_device *adev, -enum amd_hw_ip_block_type block, -uint32_t mask); +unsigned int dev_inst[MAX_HWIP ][HWIP_MAX_INSTANCE ]; };enum amdgpu_uid_type {
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gc_9_4_3.c +1 -0
@@ -20,6 +20,7 @@* OTHER DEALINGS IN THE SOFTWARE. */ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_amdkfd.h" #include "amdgpu_amdkfd_gfx_v9.h" #include "amdgpu_amdkfd_aldebaran.h"
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +1 -0
@@ -20,6 +20,7 @@* OTHER DEALINGS IN THE SOFTWARE. */ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_amdkfd.h" #include "gc/gc_9_0_offset.h" #include "gc/gc_9_0_sh_mask.h"
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -0
@@ -67,6 +67,7 @@#include "amdgpu_vf_error.h" #include "amdgpu_amdkfd.h" +#include "amdgpu_ip.h" #include "amdgpu_pm.h" #include "amdgpu_xgmi.h"
@@ -4558,6 +4559,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,mutex_init (&adev->gfx.workload_profile_mutex);mutex_init (&adev->vcn.workload_profile_mutex); +amdgpu_ip_map_init (adev);amdgpu_early_init_rlc_reg_funcs (adev);amdgpu_device_init_apu_flags (adev);
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c +17 -32
69 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h +15 -0
@@ -24,6 +24,21 @@#ifndef __AMDGPU_IP_H__#define __AMDGPU_IP_H__ +#include "amdgpu.h" +void amdgpu_ip_map_init (struct amdgpu_device *adev); +void amdgpu_ip_map_aqua_vanjaram_override (struct amdgpu_device *adev); + +u32 amdgpu_ip_map_logical_to_dev_mask (struct amdgpu_ip_map_info *ip_map, +enum amd_hw_ip_block_type block, +u32 mask); + +static inline unsigned int +amdgpu_ip_map_logical_to_dev_inst (struct amdgpu_ip_map_info *ip_map, +enum amd_hw_ip_block_type block, +unsigned int inst) +{ +return ip_map->dev_inst[block][inst]; +}#endif /* __AMDGPU_IP_H__ */
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -0
@@ -25,6 +25,7 @@*/ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_jpeg.h" #include "amdgpu_pm.h" #include "soc15d.h"
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +1 -0
@@ -27,6 +27,7 @@#include <drm/drm_drv.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_psp.h" #include "amdgpu_ucode.h" #include "amdgpu_xgmi.h"
drivers/gpu/drm/amd/amdgpu/amdgpu_xcp.c +1 -0
@@ -23,6 +23,7 @@#include "amdgpu.h" #include "amdgpu_xcp.h" #include "amdgpu_drv.h" +#include "amdgpu_ip.h" #include <drm/drm_drv.h> #include "../amdxcp/amdgpu_xcp_drv.h"
drivers/gpu/drm/amd/amdgpu/aqua_vanjaram.c +1 -1
@@ -566,7 +566,7 @@ int aqua_vanjaram_init_soc_config(struct amdgpu_device *adev)if (ret)return ret; -amdgpu_ip_map_init (adev); +amdgpu_ip_map_aqua_vanjaram_override (adev);return 0 ; }
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +4 -4
@@ -23,6 +23,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_gfx.h" #include "soc15.h" #include "soc15d.h"
@@ -1705,10 +1706,9 @@ static bool gfx_v9_4_3_check_rlcg_range(struct amdgpu_device *adev,const struct soc15_reg_rlcg *entry; entry = &entries[i]; - inst = adev->ip_map.logical_to_dev_inst ? - adev->ip_map.logical_to_dev_inst ( - adev, entry->hwip, entry->instance) : - entry->instance; + inst =amdgpu_ip_map_logical_to_dev_inst (&adev->ip_map, + entry->hwip, + entry->instance); reg = adev->reg_offset[entry->hwip][inst][entry->segment] + entry->reg;if (offset == reg)
drivers/gpu/drm/amd/amdgpu/gfxhub_v1_2.c +1 -0
@@ -21,6 +21,7 @@* */ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_xcp.h" #include "gfxhub_v1_2.h" #include "gfxhub_v1_1.h"
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +1 -0
@@ -26,6 +26,7 @@#include <drm/drm_cache.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_atomfirmware.h" #include "gmc_v10_0.h" #include "umc_v8_7.h"
drivers/gpu/drm/amd/amdgpu/gmc_v11_0.c +1 -0
@@ -26,6 +26,7 @@#include <drm/drm_cache.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_atomfirmware.h" #include "gmc_v11_0.h" #include "umc_v8_10.h"
drivers/gpu/drm/amd/amdgpu/gmc_v12_0.c +1 -0
@@ -27,6 +27,7 @@#include "amdgpu.h" #include "amdgpu_atomfirmware.h" +#include "amdgpu_ip.h" #include "gmc_v12_0.h" #include "athub/athub_4_1_0_sh_mask.h" #include "athub/athub_4_1_0_offset.h"
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1 -0
@@ -62,6 +62,7 @@#include "ivsrcid/vmc/irqsrcs_vmc_1_0.h" +#include "amdgpu_ip.h" #include "amdgpu_ras.h" #include "amdgpu_xgmi.h"
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_3.c +1 -0
@@ -22,6 +22,7 @@*/ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_jpeg.h" #include "soc15.h" #include "soc15d.h"
drivers/gpu/drm/amd/amdgpu/jpeg_v4_0_5.c +1 -0
@@ -22,6 +22,7 @@*/ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_jpeg.h" #include "amdgpu_pm.h" #include "soc15.h"
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_0.c +1 -0
@@ -22,6 +22,7 @@*/ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_jpeg.h" #include "amdgpu_pm.h" #include "soc15.h"
drivers/gpu/drm/amd/amdgpu/jpeg_v5_0_1.c +1 -0
@@ -22,6 +22,7 @@*/ #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_jpeg.h" #include "amdgpu_pm.h" #include "soc15.h"
drivers/gpu/drm/amd/amdgpu/nbio_v7_9.c +1 -0
@@ -22,6 +22,7 @@*/ #include "amdgpu.h" #include "nbio_v7_9.h" +#include "amdgpu_ip.h" #include "amdgpu_ras.h" #include "nbio/nbio_7_9_0_offset.h"
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +1 -0
@@ -27,6 +27,7 @@#include <linux/pci.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_xcp.h" #include "amdgpu_ucode.h" #include "amdgpu_trace.h"
drivers/gpu/drm/amd/amdgpu/soc15_common.h +2 -4
@@ -26,11 +26,9 @@/* GET_INST returns the physical instance corresponding to a logical instance */ #define GET_INST (ip, inst) \ - (adev->ip_map.logical_to_dev_inst ? \ - adev->ip_map.logical_to_dev_inst(adev, ip##_HWIP, inst) : inst) + amdgpu_ip_map_logical_to_dev_inst(&adev->ip_map, ip##_HWIP, inst)#define GET_MASK (ip, mask) \ - (adev->ip_map.logical_to_dev_mask ? \ - adev->ip_map.logical_to_dev_mask(adev, ip##_HWIP, mask) : mask) + amdgpu_ip_map_logical_to_dev_mask(&adev->ip_map, ip##_HWIP, mask)/* Register Access Macros */ #define SOC15_REG_OFFSET (ip, inst, reg) (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +1 -0
@@ -25,6 +25,7 @@#include <drm/drm_drv.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "soc15.h" #include "soc15d.h"
drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c +1 -0
@@ -25,6 +25,7 @@#include <drm/drm_drv.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "amdgpu_pm.h" #include "soc15.h"
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +1 -0
@@ -23,6 +23,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "amdgpu_pm.h" #include "amdgpu_cs.h"
drivers/gpu/drm/amd/amdgpu/vcn_v4_0.c +1 -0
@@ -23,6 +23,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "amdgpu_pm.h" #include "amdgpu_cs.h"
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_3.c +1 -0
@@ -25,6 +25,7 @@#include <drm/drm_drv.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "amdgpu_pm.h" #include "soc15.h"
drivers/gpu/drm/amd/amdgpu/vcn_v4_0_5.c +1 -0
@@ -23,6 +23,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "amdgpu_pm.h" #include "amdgpu_cs.h"
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_0.c +1 -0
@@ -23,6 +23,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "amdgpu_pm.h" #include "soc15.h"
drivers/gpu/drm/amd/amdgpu/vcn_v5_0_1.c +1 -0
@@ -23,6 +23,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_vcn.h" #include "amdgpu_pm.h" #include "soc15.h"
drivers/gpu/drm/amd/amdkfd/kfd_device.c +1 -0
@@ -34,6 +34,7 @@#include "kfd_svm.h" #include "kfd_migrate.h" #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_xcp.h" #define MQD_SIZE_ALIGNED 768
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_12_ppt.c +1 -0
@@ -25,6 +25,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_smu.h" #include "smu_v13_0_12_pmfw.h" #include "smu_v13_0_6_ppt.h"
drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_6_ppt.c +1 -0
@@ -25,6 +25,7 @@#include <linux/firmware.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #include "amdgpu_smu.h" #include "atomfirmware.h" #include "amdgpu_atomfirmware.h"
drivers/gpu/drm/amd/ras/ras_mgr/ras_sys.h +3 -4
@@ -29,6 +29,7 @@#include <linux/dev_printk.h> #include <linux/mempool.h> #include "amdgpu.h" +#include "amdgpu_ip.h" #define RAS_DEV_ERR (device, fmt, ...) \ do { \
@@ -82,15 +83,13 @@#define RAS_GET_INST (dev, ip, inst) \ ({ \ struct amdgpu_device *adev = (struct amdgpu_device *)dev; \ - adev->ip_map.logical_to_dev_inst ? \ - adev->ip_map.logical_to_dev_inst(adev, ip##_HWIP, inst) : inst; \ + amdgpu_ip_map_logical_to_dev_inst(&adev->ip_map, ip##_HWIP, inst); \ })#define RAS_GET_MASK (dev, ip, mask) \ ({ \ struct amdgpu_device *adev = (struct amdgpu_device *)dev; \ - (adev->ip_map.logical_to_dev_mask ? \ - adev->ip_map.logical_to_dev_mask(adev, ip##_HWIP, mask) : mask); \ + amdgpu_ip_map_logical_to_dev_mask(&adev->ip_map, ip##_HWIP, mask); \ })static inline void *ras_radix_tree_delete_iter (struct radix_tree_root *root,void *iter)
Signature · 1 line
2.48.0
RFC 6/25 drm/amdgpu/gfx10.0: More compact reading of wave data
In reply to Tvrtko UrsulinTrivial compaction of some repetitive code:
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-216 (-216)
Function old new delta gfx_v10_0_read_wave_data 580 364 -216
Total: Before=8979233, After=8979017, chg -0.00%
--- drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 38 ++++++++++++++------------ 1 file changed, 21 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +21 -17
@@ -4497,6 +4497,8 @@ static void wave_read_regs(struct amdgpu_device *adev, uint32_t wave,static void gfx_v10_0_read_wave_data (struct amdgpu_device *adev,uint32_t xcc_id,uint32_t simd,uint32_t wave,uint32_t *dst,int *no_fields) { +u32 *_dst = dst; +/* in gfx10 the SIMD_ID is specified as part of the INSTANCE * field when performing a select_se_sh so it should be * zero here
@@ -4504,23 +4506,25 @@ static void gfx_v10_0_read_wave_data(struct amdgpu_device *adev, uint32_t xcc_idWARN_ON (simd !=0 );/* type 2 wave data */ - dst[(*no_fields)++] =2 ; - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_STATUS); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_PC_LO); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_PC_HI); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_EXEC_LO); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_EXEC_HI); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_HW_ID1); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_HW_ID2); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_INST_DW0); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_GPR_ALLOC); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_LDS_ALLOC); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_TRAPSTS); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_IB_STS); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_IB_STS2); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_IB_DBG1); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_M0); - dst[(*no_fields)++] =wave_read_ind (adev, wave, ixSQ_WAVE_MODE); + *dst++ =2 ; + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_STATUS); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_PC_LO); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_PC_HI); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_EXEC_LO); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_EXEC_HI); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_HW_ID1); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_HW_ID2); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_INST_DW0); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_GPR_ALLOC); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_LDS_ALLOC); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_TRAPSTS); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_IB_STS); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_IB_STS2); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_IB_DBG1); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_M0); + *dst++ =wave_read_ind (adev, wave, ixSQ_WAVE_MODE); + + *no_fields += _dst - dst; } static void gfx_v10_0_read_wave_sgprs(struct amdgpu_device *adev, uint32_t xcc_id, uint32_t simd,
Signature · 1 line
2.48.0
RFC 7/25 drm/amdgpu/sdma5.2: Use local variables more
In reply to Tvrtko UrsulinLets apply a few simple strategies to make the code a bit more readable and compact. For example we cache some verbose register offset calculations, static values from repeatedly dereferenced pointers, where some of the latter are sometimes already being used but not consistently so.
It is not a huge saving but if the principle would be applied to all of the hwip families and version would be more interesting:
add/remove: 0/0 grow/shrink: 2/8 up/down: 42/-1454 (-1412)
Function old new delta sdma_v5_2_ring_get_wptr 280 321 +41 sdma_v5_2_ring_emit_vm_flush 381 382 +1 sdma_v5_2_mqd_init 196 195 -1 sdma_v5_2_ring_emit_ib 446 439 -7 sdma_v5_2_ring_set_wptr 518 428 -90 sdma_v5_2_restore_queue 243 149 -94 sdma_v5_2_enable 303 199 -104 sdma_v5_2_gfx_stop 695 505 -190 sdma_v5_2_stop_queue 988 676 -312 sdma_v5_2_set_clockgating_state 1299 643 -656
Total: Before=8979017, After=8977605, chg -0.02%
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 185 +++++++++++++------------ 1 file changed, 100 insertions(+), 85 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +100 -85
@@ -185,6 +185,7 @@ static uint64_t sdma_v5_2_ring_get_rptr(struct amdgpu_ring *ring)static uint64_t sdma_v5_2_ring_get_wptr (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; +unsigned int inst_id = ring->me;u64 wptr;if (ring->use_doorbell) {
@@ -192,10 +193,10 @@ static uint64_t sdma_v5_2_ring_get_wptr(struct amdgpu_ring *ring) wptr =READ_ONCE (*((u64 *)ring->wptr_cpu_addr));DRM_DEBUG ("wptr/doorbell before shift == 0x%016llx\n" , wptr); }else { - wptr =RREG32 (sdma_v5_2_get_reg_offset (adev, ring->me, mmSDMA0_GFX_RB_WPTR_HI)); + wptr =RREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_GFX_RB_WPTR_HI)); wptr = wptr <<32 ; - wptr |=RREG32 (sdma_v5_2_get_reg_offset (adev, ring->me, mmSDMA0_GFX_RB_WPTR)); -DRM_DEBUG ("wptr before shift [%i] wptr == 0x%016llx\n" , ring->me, wptr); + wptr |=RREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_GFX_RB_WPTR)); +DRM_DEBUG ("wptr before shift [%i] wptr == 0x%016llx\n" , inst_id, wptr); }return wptr >>2 ;
@@ -211,6 +212,8 @@ static uint64_t sdma_v5_2_ring_get_wptr(struct amdgpu_ring *ring)static void sdma_v5_2_ring_set_wptr (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; +unsigned int inst_id = ring->me; +u64 wptr = ring->wptr;DRM_DEBUG ("Setting write pointer\n" );if (ring->use_doorbell) {
@@ -219,36 +222,35 @@ static void sdma_v5_2_ring_set_wptr(struct amdgpu_ring *ring)"lower_32_bits(ring->wptr << 2) == 0x%08x " "upper_32_bits(ring->wptr << 2) == 0x%08x\n" , ring->wptr_offs, -lower_32_bits (ring->wptr <<2 ), - upper_32_bits(ring->wptr << 2)); +lower_32_bits (wptr <<2 ), + upper_32_bits(wptr << 2));/* XXX check if swapping is necessary on BE */ -atomic64_set ((atomic64_t *)ring->wptr_cpu_addr, - ring->wptr <<2 ); +atomic64_set ((atomic64_t *)ring->wptr_cpu_addr, wptr <<2 );DRM_DEBUG ("calling WDOORBELL64(0x%08x, 0x%016llx)\n" , - ring->doorbell_index, ring->wptr <<2 ); -WDOORBELL64 (ring->doorbell_index, ring->wptr <<2 ); + ring->doorbell_index, wptr <<2 ); +WDOORBELL64 (ring->doorbell_index, wptr <<2 );if (amdgpu_ip_version (adev,SDMA0_HWIP ,0 ) ==IP_VERSION (5 ,2 ,1 )) {/* SDMA seems to miss doorbells sometimes when powergating kicks in. * Updating the wptr directly will wake it. This is only safe because * we disallow gfxoff in begin_use() and then allow it again in end_use(). */ -WREG32 (sdma_v5_2_get_reg_offset (adev, ring->me, mmSDMA0_GFX_RB_WPTR), -lower_32_bits (ring->wptr <<2 )); -WREG32 (sdma_v5_2_get_reg_offset (adev, ring->me, mmSDMA0_GFX_RB_WPTR_HI), -upper_32_bits (ring->wptr <<2 )); +WREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_GFX_RB_WPTR), +lower_32_bits (wptr <<2 )); +WREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_GFX_RB_WPTR_HI), +upper_32_bits (wptr <<2 )); } }else {DRM_DEBUG ("Not using doorbell -- " "mmSDMA%i_GFX_RB_WPTR == 0x%08x " "mmSDMA%i_GFX_RB_WPTR_HI == 0x%08x\n" , - ring->me, -lower_32_bits (ring->wptr <<2 ), - ring->me, -upper_32_bits (ring->wptr <<2 )); -WREG32 (sdma_v5_2_get_reg_offset (adev, ring->me, mmSDMA0_GFX_RB_WPTR), -lower_32_bits (ring->wptr <<2 )); -WREG32 (sdma_v5_2_get_reg_offset (adev, ring->me, mmSDMA0_GFX_RB_WPTR_HI), -upper_32_bits (ring->wptr <<2 )); + inst_id, +lower_32_bits (wptr <<2 ), + inst_id, +upper_32_bits (wptr <<2 )); +WREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_GFX_RB_WPTR), +lower_32_bits (wptr <<2 )); +WREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_GFX_RB_WPTR_HI), +upper_32_bits (wptr <<2 )); } }
@@ -281,7 +283,8 @@ static void sdma_v5_2_ring_emit_ib(struct amdgpu_ring *ring, uint32_t flags) {unsigned vmid =AMDGPU_JOB_GET_VMID (job); -uint64_t csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid); +u64 csa_mc_addr =amdgpu_sdma_get_csa_mc_addr (ring, vmid); +u64 gpu_addr = ib->gpu_addr;/* An IB packet must end on a 8 DW boundary--the next dword * must be on a 8-dword boundary. Our IB packet below is 6
@@ -296,8 +299,8 @@ static void sdma_v5_2_ring_emit_ib(struct amdgpu_ring *ring,amdgpu_ring_write (ring,SDMA_PKT_HEADER_OP (SDMA_OP_INDIRECT ) |SDMA_PKT_INDIRECT_HEADER_VMID (vmid &0xf ));/* base must be 32 byte aligned */ -amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr) &0xffffffe0 ); -amdgpu_ring_write (ring,upper_32_bits (ib->gpu_addr)); +amdgpu_ring_write (ring,lower_32_bits (gpu_addr) &0xffffffe0 ); +amdgpu_ring_write (ring,upper_32_bits (gpu_addr));amdgpu_ring_write (ring, ib->length_dw);amdgpu_ring_write (ring,lower_32_bits (csa_mc_addr));amdgpu_ring_write (ring,upper_32_bits (csa_mc_addr));
@@ -338,13 +341,14 @@ static void sdma_v5_2_ring_emit_mem_sync(struct amdgpu_ring *ring)static void sdma_v5_2_ring_emit_hdp_flush (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -u32 ref_and_mask =0 ;const struct nbio_hdp_flush_reg *nbio_hf_reg = adev->nbio.hdp_flush_reg; +unsigned int inst_id = ring->me; +u32 ref_and_mask =0 ; -if (ring->me >1 ) { +if (inst_id >1 ) {amdgpu_asic_flush_hdp (adev, ring); }else { - ref_and_mask = nbio_hf_reg->ref_and_mask_sdma0 << ring->me; + ref_and_mask = nbio_hf_reg->ref_and_mask_sdma0 << inst_id; amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) | SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(1) |
@@ -412,16 +416,20 @@ static void sdma_v5_2_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 se*/ static void sdma_v5_2_gfx_stop (struct amdgpu_device *adev,uint32_t inst_mask) { -u32 rb_cntl, ib_cntl;int i;for_each_inst (i, inst_mask) { - rb_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL)); - rb_cntl =REG_SET_FIELD (rb_cntl,SDMA0_GFX_RB_CNTL ,RB_ENABLE ,0 ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL), rb_cntl); - ib_cntl =RREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL)); - ib_cntl =REG_SET_FIELD (ib_cntl,SDMA0_GFX_IB_CNTL ,IB_ENABLE ,0 ); -WREG32_SOC15_IP (GC ,sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL), ib_cntl); +u32 reg, cntl; + + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_RB_CNTL); + cntl =RREG32_SOC15_IP (GC , reg); + cntl =REG_SET_FIELD (cntl,SDMA0_GFX_RB_CNTL ,RB_ENABLE ,0 ); +WREG32_SOC15_IP (GC , reg, cntl); + + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_GFX_IB_CNTL); + cntl =RREG32_SOC15_IP (GC , reg); + cntl =REG_SET_FIELD (cntl,SDMA0_GFX_IB_CNTL ,IB_ENABLE ,0 ); +WREG32_SOC15_IP (GC , reg, cntl); } }
@@ -504,21 +512,22 @@ static void sdma_v5_2_ctx_switch_enable(struct amdgpu_device *adev, bool enable)*/ static void sdma_v5_2_enable (struct amdgpu_device *adev,bool enable) { -u32 f32_cntl; -int i; -uint32_t inst_mask; - - inst_mask =GENMASK (adev->sdma.num_instances -1 ,0 );if (!enable) { -sdma_v5_2_gfx_stop (adev, inst_mask); +sdma_v5_2_gfx_stop (adev, +GENMASK (adev->sdma.num_instances -1 ,0 ));sdma_v5_2_rlc_stop (adev); }if (!amdgpu_sriov_vf (adev)) { +int i; +for (i =0 ; i < adev->sdma.num_instances; i++) { - f32_cntl =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); +u32 f32_reg, f32_cntl; + + f32_reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL); + f32_cntl =RREG32 (f32_reg); f32_cntl =REG_SET_FIELD (f32_cntl,SDMA0_F32_CNTL ,HALT , enable ?0 :1 ); -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), f32_cntl); +WREG32 (f32_reg, f32_cntl); } } }
@@ -861,7 +870,7 @@ static int sdma_v5_2_mqd_init(struct amdgpu_device *adev, void *mqd, struct amdgpu_mqd_prop *prop) {struct v10_sdma_mqd *m = mqd; -uint64_t wb_gpu_addr; +u64 gpu_addr; m->sdmax_rlcx_rb_cntl = order_base_2(prop->queue_size / 4) << SDMA0_RLC0_RB_CNTL__RB_SIZE__SHIFT |
@@ -869,19 +878,20 @@ static int sdma_v5_2_mqd_init(struct amdgpu_device *adev, void *mqd,6 <<SDMA0_RLC0_RB_CNTL__RPTR_WRITEBACK_TIMER__SHIFT |1 <<SDMA0_RLC0_RB_CNTL__RB_PRIV__SHIFT ; - m->sdmax_rlcx_rb_base =lower_32_bits (prop->hqd_base_gpu_addr >>8 ); - m->sdmax_rlcx_rb_base_hi =upper_32_bits (prop->hqd_base_gpu_addr >>8 ); + gpu_addr = prop->hqd_base_gpu_addr; + m->sdmax_rlcx_rb_base =lower_32_bits (gpu_addr >>8 ); + m->sdmax_rlcx_rb_base_hi =upper_32_bits (gpu_addr >>8 ); m->sdmax_rlcx_rb_wptr_poll_cntl =RREG32 (sdma_v5_2_get_reg_offset (adev,0 , mmSDMA0_GFX_RB_WPTR_POLL_CNTL)); - wb_gpu_addr = prop->wptr_gpu_addr; - m->sdmax_rlcx_rb_wptr_poll_addr_lo =lower_32_bits (wb_gpu_addr); - m->sdmax_rlcx_rb_wptr_poll_addr_hi =upper_32_bits (wb_gpu_addr); + gpu_addr = prop->wptr_gpu_addr; + m->sdmax_rlcx_rb_wptr_poll_addr_lo =lower_32_bits (gpu_addr); + m->sdmax_rlcx_rb_wptr_poll_addr_hi =upper_32_bits (gpu_addr); - wb_gpu_addr = prop->rptr_gpu_addr; - m->sdmax_rlcx_rb_rptr_addr_lo =lower_32_bits (wb_gpu_addr); - m->sdmax_rlcx_rb_rptr_addr_hi =upper_32_bits (wb_gpu_addr); + gpu_addr = prop->rptr_gpu_addr; + m->sdmax_rlcx_rb_rptr_addr_lo =lower_32_bits (gpu_addr); + m->sdmax_rlcx_rb_rptr_addr_hi =upper_32_bits (gpu_addr); m->sdmax_rlcx_ib_cntl =RREG32 (sdma_v5_2_get_reg_offset (adev,0 , mmSDMA0_GFX_IB_CNTL));
@@ -1193,13 +1203,14 @@ static void sdma_v5_2_ring_emit_vm_flush(struct amdgpu_ring *ring, {struct amdgpu_vmhub *hub = &ring->adev->vmhub[ring->vm_hub];uint32_t req = hub->vmhub_funcs->get_invalidate_req (vmid,0 ); +uint32_t ctx_addr_distance = hub->ctx_addr_distance;/* Update the PD address for this VMID. */ amdgpu_ring_emit_wreg (ring, hub->ctx0_ptb_addr_lo32 + - (hub->ctx_addr_distance * vmid), + ctx_addr_distance * vmid,lower_32_bits (pd_addr));amdgpu_ring_emit_wreg (ring, hub->ctx0_ptb_addr_hi32 + - (hub->ctx_addr_distance * vmid), + ctx_addr_distance * vmid,upper_32_bits (pd_addr));/* Trigger invalidation. */
@@ -1479,9 +1490,9 @@ static int sdma_v5_2_reset_queue(struct amdgpu_ring *ring,static int sdma_v5_2_stop_queue (struct amdgpu_ring *ring) { -u32 f32_cntl, freeze, cntl, stat1_reg;struct amdgpu_device *adev = ring->adev;int i, j, r =0 ; +u32 reg, cntl;if (amdgpu_sriov_vf (adev))return -EINVAL ;
@@ -1493,35 +1504,39 @@ static int sdma_v5_2_stop_queue(struct amdgpu_ring *ring)sdma_v5_2_gfx_stop (adev,1 << i);/*engine stop SDMA1_F32_CNTL.HALT to 1 and SDMAx_FREEZE freeze bit to 1 */ - freeze =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); - freeze =REG_SET_FIELD (freeze,SDMA0_FREEZE ,FREEZE ,1 ); -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE), freeze); + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE); + cntl =RREG32 (reg); + cntl =REG_SET_FIELD (cntl,SDMA0_FREEZE ,FREEZE ,1 ); +WREG32 (reg, cntl);for (j =0 ; j < adev->usec_timeout; j++) { - freeze =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_FREEZE)); + cntl =RREG32 (reg); -if (REG_GET_FIELD (freeze,SDMA0_FREEZE ,FROZEN ) &1 ) +if (REG_GET_FIELD (cntl,SDMA0_FREEZE ,FROZEN ) &1 )break ;udelay (1 ); }if (j == adev->usec_timeout) { - stat1_reg =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_STATUS1_REG)); -if ((stat1_reg &0x3FF ) !=0x3FF ) { + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_STATUS1_REG); + cntl =RREG32 (reg); +if ((cntl &0x3FF ) !=0x3FF ) {DRM_ERROR ("cannot soft reset as sdma not idle\n" ); r = -ETIMEDOUT ; goto err0; } } - f32_cntl =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL)); - f32_cntl =REG_SET_FIELD (f32_cntl,SDMA0_F32_CNTL ,HALT ,1 ); -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL), f32_cntl); + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_F32_CNTL); + cntl =RREG32 (reg); + cntl =REG_SET_FIELD (cntl,SDMA0_F32_CNTL ,HALT ,1 ); +WREG32 (reg, cntl); - cntl =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL)); + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL); + cntl =RREG32 (reg); cntl =REG_SET_FIELD (cntl,SDMA0_CNTL ,UTC_L1_ENABLE ,0 ); -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CNTL), cntl); +WREG32 (reg, cntl); err0:amdgpu_gfx_rlc_exit_safe_mode (adev,0 );
@@ -1532,14 +1547,15 @@ static int sdma_v5_2_restore_queue(struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev;u32 inst_id = ring->me; -u32 freeze; +u32 reg, freeze;int r;amdgpu_gfx_rlc_enter_safe_mode (adev,0 );/* unfreeze and unhalt */ - freeze =RREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_FREEZE)); + reg =sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_FREEZE); + freeze =RREG32 (reg); freeze =REG_SET_FIELD (freeze,SDMA0_FREEZE ,FREEZE ,0 ); -WREG32 (sdma_v5_2_get_reg_offset (adev, inst_id, mmSDMA0_FREEZE), freeze); +WREG32 (reg, freeze); r =sdma_v5_2_gfx_resume_instance (adev, inst_id, true);
@@ -1737,67 +1753,66 @@ static bool sdma_v5_2_firmware_mgcg_support(struct amdgpu_device *adev,static void sdma_v5_2_update_medium_grain_clock_gating (struct amdgpu_device *adev,bool enable) { -uint32_t data, def; +u32 reg, data, def;int i;for (i =0 ; i < adev->sdma.num_instances; i++) { + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CLK_CTRL);if (!sdma_v5_2_firmware_mgcg_support (adev, i)) adev->cg_flags &= ~AMD_CG_SUPPORT_SDMA_MGCG ; + def = data =RREG32 (reg); +if (enable && (adev->cg_flags &AMD_CG_SUPPORT_SDMA_MGCG )) {/* Enable sdma clock gating */ - def = data =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CLK_CTRL)); data &= ~(SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDER_REG_MASK ); -if (def != data) -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CLK_CTRL), data); }else {/* Disable sdma clock gating */ - def = data =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CLK_CTRL)); data |= (SDMA0_CLK_CTRL__SOFT_OVERRIDE4_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE3_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE2_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE1_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDE0_MASK |SDMA0_CLK_CTRL__SOFT_OVERRIDER_REG_MASK ); -if (def != data) -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_CLK_CTRL), data); } + +if (def != data) +WREG32 (reg, data); } }static void sdma_v5_2_update_medium_grain_light_sleep (struct amdgpu_device *adev,bool enable) { -uint32_t data, def; +u32 reg, data, def;int i;for (i =0 ; i < adev->sdma.num_instances; i++) { + reg =sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_POWER_CNTL); +if (adev->sdma.instance[i].fw_version <70 &&amdgpu_ip_version (adev,SDMA0_HWIP ,0 ) ==IP_VERSION (5 ,2 ,1 )) adev->cg_flags &= ~AMD_CG_SUPPORT_SDMA_LS ; + def = data =RREG32 (reg); +if (enable && (adev->cg_flags &AMD_CG_SUPPORT_SDMA_LS )) {/* Enable sdma mem light sleep */ - def = data =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_POWER_CNTL)); data |=SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK ; -if (def != data) -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_POWER_CNTL), data); - }else {/* Disable sdma mem light sleep */ - def = data =RREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_POWER_CNTL)); data &= ~SDMA0_POWER_CNTL__MEM_POWER_OVERRIDE_MASK ; -if (def != data) -WREG32 (sdma_v5_2_get_reg_offset (adev, i, mmSDMA0_POWER_CNTL), data); - } + +if (def != data) +WREG32 (reg, data); } }
Signature · 1 line
2.48.0
RFC 8/25 drm/amdgpu/vcn2.0: Use local variables more
In reply to Tvrtko UrsulinCompact some very long and repetitive lines of code by caching the respective object in local variables. This is a concept which is already used at places, but not consistently so.
add/remove: 0/0 grow/shrink: 0/7 up/down: 0/-246 (-246)
Function old new delta vcn_v2_0_dec_ring_insert_nop 200 198 -2 vcn_v2_0_dec_ring_insert_start 272 257 -15 vcn_v2_0_dec_ring_emit_wreg 402 373 -29 vcn_v2_0_dec_ring_test_ring 457 422 -35 vcn_v2_0_dec_ring_emit_ib 571 530 -41 vcn_v2_0_dec_ring_emit_reg_wait 536 492 -44 vcn_v2_0_dec_ring_emit_fence 938 858 -80
Total: Before=8977605, After=8977359, chg -0.00%
--- drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c | 71 +++++++++++++++------------ 1 file changed, 40 insertions(+), 31 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v2_0.c +40 -31
@@ -1479,11 +1479,12 @@ static void vcn_v2_0_dec_ring_set_wptr(struct amdgpu_ring *ring)*/ void vcn_v2_0_dec_ring_insert_start (struct amdgpu_ring *ring) { -struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = + &ring->adev->vcn.inst[ring->me].internal; -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data0,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data0,0 ));amdgpu_ring_write (ring,0 ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.cmd,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->cmd,0 ));amdgpu_ring_write (ring,VCN_DEC_KMD_CMD | (VCN_DEC_CMD_PACKET_START <<1 )); }
@@ -1512,13 +1513,14 @@ void vcn_v2_0_dec_ring_insert_end(struct amdgpu_ring *ring)*/ void vcn_v2_0_dec_ring_insert_nop (struct amdgpu_ring *ring,uint32_t count) { -struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = + &ring->adev->vcn.inst[ring->me].internal;int i;WARN_ON (ring->wptr %2 || count %2 );for (i =0 ; i < count /2 ; i++) { -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.nop,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->nop,0 ));amdgpu_ring_write (ring,0 ); } }
@@ -1536,28 +1538,30 @@ void vcn_v2_0_dec_ring_insert_nop(struct amdgpu_ring *ring, uint32_t count)void vcn_v2_0_dec_ring_emit_fence (struct amdgpu_ring *ring,u64 addr,u64 seq,unsigned flags) { -struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = + &ring->adev->vcn.inst[ring->me].internal;WARN_ON (flags &AMDGPU_FENCE_FLAG_64BIT ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.context_id,0 )); + +amdgpu_ring_write (ring,PACKET0 (internal->context_id,0 ));amdgpu_ring_write (ring, seq); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data0,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data0,0 ));amdgpu_ring_write (ring, addr &0xffffffff ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data1,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data1,0 ));amdgpu_ring_write (ring,upper_32_bits (addr) &0xff ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.cmd,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->cmd,0 ));amdgpu_ring_write (ring,VCN_DEC_KMD_CMD | (VCN_DEC_CMD_FENCE <<1 )); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data0,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data0,0 ));amdgpu_ring_write (ring,0 ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data1,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data1,0 ));amdgpu_ring_write (ring,0 ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.cmd,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->cmd,0 ));amdgpu_ring_write (ring,VCN_DEC_KMD_CMD | (VCN_DEC_CMD_TRAP <<1 )); }
@@ -1577,35 +1581,37 @@ void vcn_v2_0_dec_ring_emit_ib(struct amdgpu_ring *ring, struct amdgpu_ib *ib, uint32_t flags) { -struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = + &ring->adev->vcn.inst[ring->me].internal;unsigned vmid =AMDGPU_JOB_GET_VMID (job); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.ib_vmid,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->ib_vmid,0 ));amdgpu_ring_write (ring, vmid); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.ib_bar_low,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->ib_bar_low,0 ));amdgpu_ring_write (ring,lower_32_bits (ib->gpu_addr)); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.ib_bar_high,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->ib_bar_high,0 ));amdgpu_ring_write (ring,upper_32_bits (ib->gpu_addr)); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.ib_size,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->ib_size,0 ));amdgpu_ring_write (ring, ib->length_dw); }void vcn_v2_0_dec_ring_emit_reg_wait (struct amdgpu_ring *ring,uint32_t reg,uint32_t val,uint32_t mask) { -struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = + &ring->adev->vcn.inst[ring->me].internal; -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data0,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data0,0 ));amdgpu_ring_write (ring, reg <<2 ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data1,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data1,0 ));amdgpu_ring_write (ring, val); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.gp_scratch8,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->gp_scratch8,0 ));amdgpu_ring_write (ring, mask); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.cmd,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->cmd,0 ));amdgpu_ring_write (ring,VCN_DEC_KMD_CMD | (VCN_DEC_CMD_REG_READ_COND_WAIT <<1 )); }
@@ -1628,15 +1634,16 @@ void vcn_v2_0_dec_ring_emit_vm_flush(struct amdgpu_ring *ring,void vcn_v2_0_dec_ring_emit_wreg (struct amdgpu_ring *ring,uint32_t reg,uint32_t val) { -struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = + &ring->adev->vcn.inst[ring->me].internal; -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data0,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data0,0 ));amdgpu_ring_write (ring, reg <<2 ); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.data1,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->data1,0 ));amdgpu_ring_write (ring, val); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.cmd,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->cmd,0 ));amdgpu_ring_write (ring,VCN_DEC_KMD_CMD | (VCN_DEC_CMD_WRITE_REG <<1 )); }
@@ -1826,6 +1833,8 @@ static int vcn_v2_0_process_interrupt(struct amdgpu_device *adev,int vcn_v2_0_dec_ring_test_ring (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = &adev->vcn.inst[ring->me].internal; +struct amdgpu_vcn_reg *external = &adev->vcn.inst[ring->me].external;uint32_t tmp =0 ;unsigned i;int r;
@@ -1833,17 +1842,17 @@ int vcn_v2_0_dec_ring_test_ring(struct amdgpu_ring *ring)if (amdgpu_sriov_vf (adev))return 0 ; -WREG32 (adev->vcn.inst[ring->me].external.scratch9,0xCAFEDEAD ); +WREG32 (external->scratch9,0xCAFEDEAD ); r =amdgpu_ring_alloc (ring,4 );if (r)return r; -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.cmd,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->cmd,0 ));amdgpu_ring_write (ring,VCN_DEC_KMD_CMD | (VCN_DEC_CMD_PACKET_START <<1 )); -amdgpu_ring_write (ring,PACKET0 (adev->vcn.inst[ring->me].internal.scratch9,0 )); +amdgpu_ring_write (ring,PACKET0 (internal->scratch9,0 ));amdgpu_ring_write (ring,0xDEADBEEF );amdgpu_ring_commit (ring);for (i =0 ; i < adev->usec_timeout; i++) { - tmp =RREG32 (adev->vcn.inst[ring->me].external.scratch9); + tmp =RREG32 (external->scratch9);if (tmp ==0xDEADBEEF )break ;udelay (1 );
Signature · 1 line
2.48.0
RFC 9/25 drm/amdgpu/vcn3.0.0: Use local variables more
In reply to Tvrtko UrsulinCompact some very long and repetitive lines of code by caching the respective object in local variables. This is a concept which is already used at places, but not consistently so.
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-27 (-27)
Function old new delta vcn_v3_0_ring_patch_cs_in_place 987 960 -27
Total: Before=8977359, After=8977332, chg -0.00%
--- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +5 -3
@@ -1991,6 +1991,8 @@ static int vcn_v3_0_ring_patch_cs_in_place(struct amdgpu_cs_parser *p, struct amdgpu_ib *ib) {struct amdgpu_ring *ring =amdgpu_job_ring (job); +struct amdgpu_vcn_reg *internal = + &ring->adev->vcn.inst[ring->me].internal;uint32_t msg_lo =0 , msg_hi =0 ;unsigned i;int r;
@@ -2003,11 +2005,11 @@ static int vcn_v3_0_ring_patch_cs_in_place(struct amdgpu_cs_parser *p,uint32_t reg =amdgpu_ib_get_value (ib, i);uint32_t val =amdgpu_ib_get_value (ib, i +1 ); -if (reg ==PACKET0 (p->adev->vcn.inst[ring->me].internal.data0,0 )) { +if (reg ==PACKET0 (internal->data0,0 )) { msg_lo = val; - }else if (reg ==PACKET0 (p->adev->vcn.inst[ring->me].internal.data1,0 )) { + }else if (reg ==PACKET0 (internal->data1,0 )) { msg_hi = val; - }else if (reg ==PACKET0 (p->adev->vcn.inst[ring->me].internal.cmd,0 ) && + }else if (reg ==PACKET0 (internal->cmd,0 ) && val ==0 ) { r =vcn_v3_0_dec_msg (p, job, ((u64 )msg_hi) <<32 | msg_lo);
Signature · 1 line
2.48.0
RFC 10/25 drm/amdgpu/jpeg: Use more local variables
In reply to Tvrtko UrsulinCompact some very long and repetitive lines of code by caching the respective object in local variables. This is a concept which is already used at places, but not consistently so.
add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-45 (-45)
Function old new delta amdgpu_jpeg_dec_ring_test_ring 382 337 -45
Total: Before=8977332, After=8977287, chg -0.00%
--- drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +6 -4
@@ -153,6 +153,8 @@ void amdgpu_jpeg_ring_end_use(struct amdgpu_ring *ring)int amdgpu_jpeg_dec_ring_test_ring (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; +struct amdgpu_jpeg_reg *external = &adev->jpeg.inst[ring->me].external; +unsigned int pipe = ring->pipe;uint32_t tmp =0 ;unsigned i;int r;
@@ -165,16 +167,16 @@ int amdgpu_jpeg_dec_ring_test_ring(struct amdgpu_ring *ring)if (r)return r; -WREG32 (adev->jpeg.inst[ring->me].external.jpeg_pitch[ring->pipe],0xCAFEDEAD ); +WREG32 (external->jpeg_pitch[pipe],0xCAFEDEAD );/* Add a read register to make sure the write register is executed. */ -RREG32 (adev->jpeg.inst[ring->me].external.jpeg_pitch[ring->pipe]); +RREG32 (external->jpeg_pitch[pipe]); -amdgpu_ring_write (ring,PACKET0 (adev->jpeg.internal.jpeg_pitch[ring->pipe],0 )); +amdgpu_ring_write (ring,PACKET0 (adev->jpeg.internal.jpeg_pitch[pipe],0 ));amdgpu_ring_write (ring,0xABADCAFE );amdgpu_ring_commit (ring);for (i =0 ; i < adev->usec_timeout; i++) { - tmp =RREG32 (adev->jpeg.inst[ring->me].external.jpeg_pitch[ring->pipe]); + tmp =RREG32 (external->jpeg_pitch[pipe]);if (tmp ==0xABADCAFE )break ;udelay (1 );
Signature · 1 line
2.48.0
RFC 11/25 drm/amdgpu: More compact VCE IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c | 96 +++++++++++++------------ 1 file changed, 50 insertions(+), 46 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vce.c +50 -46
@@ -444,7 +444,8 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle,struct amdgpu_ib ib_msg;struct dma_fence *f =NULL ;uint64_t addr; -int i, r; +u32 *ptr; +int r; r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, AMDGPU_FENCE_OWNER_UNDEFINED,
@@ -462,45 +463,46 @@ static int amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle, goto err; ib = &job->ibs[0 ]; + ptr = ib->ptr;/* let addr point to page boundary */ addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg.gpu_addr);/* stitch together an VCE create msg */ - ib->length_dw =0 ; - ib->ptr[ib->length_dw++] =0x0000000c ;/* len */ - ib->ptr[ib->length_dw++] =0x00000001 ;/* session cmd */ - ib->ptr[ib->length_dw++] = handle; + *ptr++ =0x0000000c ;/* len */ + *ptr++ =0x00000001 ;/* session cmd */ + *ptr++ = handle;if ((ring->adev->vce.fw_version >>24 ) >=52 ) - ib->ptr[ib->length_dw++] =0x00000040 ;/* len */ + *ptr++ =0x00000040 ;/* len */ else - ib->ptr[ib->length_dw++] =0x00000030 ;/* len */ - ib->ptr[ib->length_dw++] =0x01000001 ;/* create cmd */ - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000042 ; - ib->ptr[ib->length_dw++] =0x0000000a ; - ib->ptr[ib->length_dw++] =0x00000001 ; - ib->ptr[ib->length_dw++] =0x00000080 ; - ib->ptr[ib->length_dw++] =0x00000060 ; - ib->ptr[ib->length_dw++] =0x00000100 ; - ib->ptr[ib->length_dw++] =0x00000100 ; - ib->ptr[ib->length_dw++] =0x0000000c ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000030 ;/* len */ + *ptr++ =0x01000001 ;/* create cmd */ + *ptr++ =0x00000000 ; + *ptr++ =0x00000042 ; + *ptr++ =0x0000000a ; + *ptr++ =0x00000001 ; + *ptr++ =0x00000080 ; + *ptr++ =0x00000060 ; + *ptr++ =0x00000100 ; + *ptr++ =0x00000100 ; + *ptr++ =0x0000000c ; + *ptr++ =0x00000000 ;if ((ring->adev->vce.fw_version >>24 ) >=52 ) { - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; } - ib->ptr[ib->length_dw++] =0x00000014 ;/* len */ - ib->ptr[ib->length_dw++] =0x05000005 ;/* feedback buffer */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = addr; - ib->ptr[ib->length_dw++] =0x00000001 ; + *ptr++ =0x00000014 ;/* len */ + *ptr++ =0x05000005 ;/* feedback buffer */ + *ptr++ =upper_32_bits (addr); + *ptr++ = addr; + *ptr++ =0x00000001 ; -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw); r =amdgpu_job_submit_direct (job, ring, &f);amdgpu_ib_free (&ib_msg, f);
@@ -534,7 +536,8 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,struct amdgpu_job *job;struct amdgpu_ib *ib;struct dma_fence *f =NULL ; -int i, r; +u32 *ptr; +int r; r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity, AMDGPU_FENCE_OWNER_UNDEFINED,
@@ -546,27 +549,28 @@ static int amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle,return r; ib = &job->ibs[0 ]; + ptr = ib->ptr;/* stitch together an VCE destroy msg */ - ib->length_dw =0 ; - ib->ptr[ib->length_dw++] =0x0000000c ;/* len */ - ib->ptr[ib->length_dw++] =0x00000001 ;/* session cmd */ - ib->ptr[ib->length_dw++] = handle; + *ptr++ =0x0000000c ;/* len */ + *ptr++ =0x00000001 ;/* session cmd */ + *ptr++ = handle; - ib->ptr[ib->length_dw++] =0x00000020 ;/* len */ - ib->ptr[ib->length_dw++] =0x00000002 ;/* task info */ - ib->ptr[ib->length_dw++] =0xffffffff ;/* next task info, set to 0xffffffff if no */ - ib->ptr[ib->length_dw++] =0x00000001 ;/* destroy session */ - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0xffffffff ;/* feedback is not needed, set to 0xffffffff and firmware will not output feedback */ - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000020 ;/* len */ + *ptr++ =0x00000002 ;/* task info */ + *ptr++ =0xffffffff ;/* next task info, set to 0xffffffff if no */ + *ptr++ =0x00000001 ;/* destroy session */ + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; + *ptr++ =0xffffffff ;/* feedback is not needed, set to 0xffffffff and firmware will not output feedback */ + *ptr++ =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000008 ;/* len */ - ib->ptr[ib->length_dw++] =0x02000001 ;/* destroy cmd */ + *ptr++ =0x00000008 ;/* len */ + *ptr++ =0x02000001 ;/* destroy cmd */ -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw);if (direct) r =amdgpu_job_submit_direct (job, ring, &f);
Signature · 1 line
2.48.0
RFC 12/25 drm/amdgpu: More compact VCN IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 134 +++++++++++++----------- 1 file changed, 75 insertions(+), 59 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +75 -59
@@ -619,9 +619,12 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring, {u64 addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr);struct amdgpu_device *adev = ring->adev; +struct amdgpu_vcn_reg *internal = &adev->vcn.inst[ring->me].internal; +uint32_t nop =PACKET0 (internal->nop,0 );struct dma_fence *f =NULL ;struct amdgpu_job *job;struct amdgpu_ib *ib; +uint32_t *ptr;int i, r; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL,
@@ -631,15 +634,16 @@ static int amdgpu_vcn_dec_send_msg(struct amdgpu_ring *ring, goto err; ib = &job->ibs[0 ]; - ib->ptr[0 ] =PACKET0 (adev->vcn.inst[ring->me].internal.data0,0 ); - ib->ptr[1 ] = addr; - ib->ptr[2 ] =PACKET0 (adev->vcn.inst[ring->me].internal.data1,0 ); - ib->ptr[3 ] = addr >>32 ; - ib->ptr[4 ] =PACKET0 (adev->vcn.inst[ring->me].internal.cmd,0 ); - ib->ptr[5 ] =0 ; + ptr = ib->ptr; + *ptr++ =PACKET0 (internal->data0,0 ); + *ptr++ = addr; + *ptr++ =PACKET0 (internal->data1,0 ); + *ptr++ = addr >>32 ; + *ptr++ =PACKET0 (internal->cmd,0 ); + *ptr++ =0 ;for (i =6 ; i <16 ; i +=2 ) { - ib->ptr[i] =PACKET0 (adev->vcn.inst[ring->me].internal.nop,0 ); - ib->ptr[i+1 ] =0 ; + *ptr++ = nop; + *ptr++ =0 ; } ib->length_dw =16 ;
@@ -759,17 +763,20 @@ int amdgpu_vcn_dec_ring_test_ib(struct amdgpu_ring *ring, long timeout)static uint32_t *amdgpu_vcn_unified_ring_ib_header (struct amdgpu_ib *ib,uint32_t ib_pack_in_dw,bool enc) { +u32 *ptr = &ib->ptr[ib->length_dw];uint32_t *ib_checksum; - ib->ptr[ib->length_dw++] =0x00000010 ;/* single queue checksum */ - ib->ptr[ib->length_dw++] =0x30000002 ; - ib_checksum = &ib->ptr[ib->length_dw++]; - ib->ptr[ib->length_dw++] = ib_pack_in_dw; + *ptr++ =0x00000010 ;/* single queue checksum */ + *ptr++ =0x30000002 ; + ib_checksum = ptr++; + *ptr++ = ib_pack_in_dw; - ib->ptr[ib->length_dw++] =0x00000010 ;/* engine info */ - ib->ptr[ib->length_dw++] =0x30000001 ; - ib->ptr[ib->length_dw++] = enc ?0x2 :0x3 ; - ib->ptr[ib->length_dw++] = ib_pack_in_dw *sizeof (uint32_t ); + *ptr++ =0x00000010 ;/* engine info */ + *ptr++ =0x30000001 ; + *ptr++ = enc ?0x2 :0x3 ; + *ptr++ = ib_pack_in_dw *sizeof (uint32_t ); + + ib->length_dw = ptr - ib->ptr;return ib_checksum; }
@@ -799,7 +806,8 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring,uint64_t addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr);uint32_t *ib_checksum;uint32_t ib_pack_in_dw; -int i, r; +u32 *ptr; +int r;if (adev->vcn.inst[ring->me].using_unified_queue) ib_size_dw +=8 ;
@@ -820,18 +828,20 @@ static int amdgpu_vcn_dec_sw_send_msg(struct amdgpu_ring *ring, ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib, ib_pack_in_dw, false); } - ib->ptr[ib->length_dw++] =sizeof (struct amdgpu_vcn_decode_buffer ) +8 ; - ib->ptr[ib->length_dw++] =cpu_to_le32 (AMDGPU_VCN_IB_FLAG_DECODE_BUFFER ); - decode_buffer = (struct amdgpu_vcn_decode_buffer *)&(ib->ptr[ib->length_dw]); - ib->length_dw +=sizeof (struct amdgpu_vcn_decode_buffer ) /4 ; + ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =sizeof (struct amdgpu_vcn_decode_buffer ) +8 ; + *ptr++ =cpu_to_le32 (AMDGPU_VCN_IB_FLAG_DECODE_BUFFER ); + decode_buffer = (struct amdgpu_vcn_decode_buffer *)ptr; + ib->length_dw = ptr - ib->ptr + +sizeof (struct amdgpu_vcn_decode_buffer ) /4 ;memset (decode_buffer,0 ,sizeof (struct amdgpu_vcn_decode_buffer )); decode_buffer->valid_buf_flag |=cpu_to_le32 (AMDGPU_VCN_CMD_FLAG_MSG_BUFFER ); decode_buffer->msg_buffer_address_hi =cpu_to_le32 (addr >>32 ); decode_buffer->msg_buffer_address_lo =cpu_to_le32 (addr); -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; +memset32 (ptr,0 , ib_size_dw - ib->length_dw);if (adev->vcn.inst[ring->me].using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum, ib_pack_in_dw);
@@ -929,7 +939,8 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handstruct dma_fence *f =NULL ;uint32_t *ib_checksum =NULL ;uint64_t addr; -int i, r; +u32 *ptr; +int r;if (adev->vcn.inst[ring->me].using_unified_queue) ib_size_dw +=8 ;
@@ -941,31 +952,33 @@ static int amdgpu_vcn_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handreturn r; ib = &job->ibs[0 ]; - addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr); - ib->length_dw =0 ; + addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr);if (adev->vcn.inst[ring->me].using_unified_queue) ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib,0x11 , true); - ib->ptr[ib->length_dw++] =0x00000018 ; - ib->ptr[ib->length_dw++] =0x00000001 ;/* session info */ - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = addr; - ib->ptr[ib->length_dw++] =0x00000000 ; + ptr = &ib->ptr[ib->length_dw]; - ib->ptr[ib->length_dw++] =0x00000014 ; - ib->ptr[ib->length_dw++] =0x00000002 ;/* task info */ - ib->ptr[ib->length_dw++] =0x0000001c ; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000018 ; + *ptr++ =0x00000001 ;/* session info */ + *ptr++ = handle; + *ptr++ =upper_32_bits (addr); + *ptr++ = addr; + *ptr++ =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000008 ; - ib->ptr[ib->length_dw++] =0x08000001 ;/* op initialize */ + *ptr++ =0x00000014 ; + *ptr++ =0x00000002 ;/* task info */ + *ptr++ =0x0000001c ; + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + *ptr++ =0x00000008 ; + *ptr++ =0x08000001 ;/* op initialize */ + + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw);if (adev->vcn.inst[ring->me].using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum,0x11 );
@@ -996,7 +1009,8 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t hanstruct dma_fence *f =NULL ;uint32_t *ib_checksum =NULL ;uint64_t addr; -int i, r; +u32 *ptr; +int r;if (adev->vcn.inst[ring->me].using_unified_queue) ib_size_dw +=8 ;
@@ -1008,31 +1022,33 @@ static int amdgpu_vcn_enc_get_destroy_msg(struct amdgpu_ring *ring, uint32_t hanreturn r; ib = &job->ibs[0 ]; - addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr); - ib->length_dw =0 ; + addr =AMDGPU_GPU_PAGE_ALIGN (ib_msg->gpu_addr);if (adev->vcn.inst[ring->me].using_unified_queue) ib_checksum =amdgpu_vcn_unified_ring_ib_header (ib,0x11 , true); - ib->ptr[ib->length_dw++] =0x00000018 ; - ib->ptr[ib->length_dw++] =0x00000001 ; - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = addr; - ib->ptr[ib->length_dw++] =0x00000000 ; + ptr = &ib->ptr[ib->length_dw]; - ib->ptr[ib->length_dw++] =0x00000014 ; - ib->ptr[ib->length_dw++] =0x00000002 ; - ib->ptr[ib->length_dw++] =0x0000001c ; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000018 ; + *ptr++ =0x00000001 ; + *ptr++ = handle; + *ptr++ =upper_32_bits (addr); + *ptr++ = addr; + *ptr++ =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000008 ; - ib->ptr[ib->length_dw++] =0x08000002 ;/* op close session */ + *ptr++ =0x00000014 ; + *ptr++ =0x00000002 ; + *ptr++ =0x0000001c ; + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + *ptr++ =0x00000008 ; + *ptr++ =0x08000002 ;/* op close session */ + + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw);if (adev->vcn.inst[ring->me].using_unified_queue)amdgpu_vcn_unified_ring_ib_checksum (&ib_checksum,0x11 );
Signature · 1 line
2.48.0
RFC 13/25 drm/amdgpu: More compact UVD 6 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.uvd 6
--- drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c | 72 ++++++++++++++------------- 1 file changed, 38 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/amdgpu/uvd_v6_0.c +38 -34
@@ -214,7 +214,8 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handlestruct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint64_t addr; -int i, r; +u32 *ptr; +int r; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, &job,
@@ -223,27 +224,28 @@ static int uvd_v6_0_enc_get_create_msg(struct amdgpu_ring *ring, uint32_t handlereturn r; ib = &job->ibs[0 ]; + ptr = ib->ptr; addr =amdgpu_bo_gpu_offset (bo); - ib->length_dw =0 ; - ib->ptr[ib->length_dw++] =0x00000018 ; - ib->ptr[ib->length_dw++] =0x00000001 ;/* session info */ - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] =0x00010000 ; - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ =0x00000018 ; + *ptr++ =0x00000001 ;/* session info */ + *ptr++ = handle; + *ptr++ =0x00010000 ; + *ptr++ =upper_32_bits (addr); + *ptr++ = addr; - ib->ptr[ib->length_dw++] =0x00000014 ; - ib->ptr[ib->length_dw++] =0x00000002 ;/* task info */ - ib->ptr[ib->length_dw++] =0x0000001c ; - ib->ptr[ib->length_dw++] =0x00000001 ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000014 ; + *ptr++ =0x00000002 ;/* task info */ + *ptr++ =0x0000001c ; + *ptr++ =0x00000001 ; + *ptr++ =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000008 ; - ib->ptr[ib->length_dw++] =0x08000001 ;/* op initialize */ + *ptr++ =0x00000008 ; + *ptr++ =0x08000001 ;/* op initialize */ -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw); r =amdgpu_job_submit_direct (job, ring, &f);if (r)
@@ -279,7 +281,8 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,struct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint64_t addr; -int i, r; +u32 *ptr; +int r; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, &job,
@@ -288,27 +291,28 @@ static int uvd_v6_0_enc_get_destroy_msg(struct amdgpu_ring *ring,return r; ib = &job->ibs[0 ]; + ptr = ib->ptr; addr =amdgpu_bo_gpu_offset (bo); - ib->length_dw =0 ; - ib->ptr[ib->length_dw++] =0x00000018 ; - ib->ptr[ib->length_dw++] =0x00000001 ;/* session info */ - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] =0x00010000 ; - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ =0x00000018 ; + *ptr++ =0x00000001 ;/* session info */ + *ptr++ = handle; + *ptr++ =0x00010000 ; + *ptr++ =upper_32_bits (addr); + *ptr++ = addr; - ib->ptr[ib->length_dw++] =0x00000014 ; - ib->ptr[ib->length_dw++] =0x00000002 ;/* task info */ - ib->ptr[ib->length_dw++] =0x0000001c ; - ib->ptr[ib->length_dw++] =0x00000001 ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000014 ; + *ptr++ =0x00000002 ;/* task info */ + *ptr++ =0x0000001c ; + *ptr++ =0x00000001 ; + *ptr++ =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000008 ; - ib->ptr[ib->length_dw++] =0x08000002 ;/* op close session */ + *ptr++ =0x00000008 ; + *ptr++ =0x08000002 ;/* op close session */ -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw); r =amdgpu_job_submit_direct (job, ring, &f);if (r)
Signature · 1 line
2.48.0
RFC 14/25 drm/amdgpu: More compact UVD 7 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c | 72 ++++++++++++++------------- 1 file changed, 38 insertions(+), 34 deletions(-)
drivers/gpu/drm/amd/amdgpu/uvd_v7_0.c +38 -34
@@ -222,7 +222,8 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, u32 handle,struct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint64_t addr; -int i, r; +u32 *ptr; +int r; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, &job,
@@ -231,27 +232,28 @@ static int uvd_v7_0_enc_get_create_msg(struct amdgpu_ring *ring, u32 handle,return r; ib = &job->ibs[0 ]; + ptr = ib->ptr; addr =amdgpu_bo_gpu_offset (bo); - ib->length_dw =0 ; - ib->ptr[ib->length_dw++] =0x00000018 ; - ib->ptr[ib->length_dw++] =0x00000001 ;/* session info */ - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ =0x00000018 ; + *ptr++ =0x00000001 ;/* session info */ + *ptr++ = handle; + *ptr++ =0x00000000 ; + *ptr++ =upper_32_bits (addr); + *ptr++ = addr; - ib->ptr[ib->length_dw++] =0x00000014 ; - ib->ptr[ib->length_dw++] =0x00000002 ;/* task info */ - ib->ptr[ib->length_dw++] =0x0000001c ; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000014 ; + *ptr++ =0x00000002 ;/* task info */ + *ptr++ =0x0000001c ; + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000008 ; - ib->ptr[ib->length_dw++] =0x08000001 ;/* op initialize */ + *ptr++ =0x00000008 ; + *ptr++ =0x08000001 ;/* op initialize */ -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw); r =amdgpu_job_submit_direct (job, ring, &f);if (r)
@@ -286,7 +288,8 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, u32 handle,struct amdgpu_ib *ib;struct dma_fence *f =NULL ;uint64_t addr; -int i, r; +u32 *ptr; +int r; r = amdgpu_job_alloc_with_ib(ring->adev, NULL, NULL, ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT, &job,
@@ -295,27 +298,28 @@ static int uvd_v7_0_enc_get_destroy_msg(struct amdgpu_ring *ring, u32 handle,return r; ib = &job->ibs[0 ]; + ptr = ib->ptr; addr =amdgpu_bo_gpu_offset (bo); - ib->length_dw =0 ; - ib->ptr[ib->length_dw++] =0x00000018 ; - ib->ptr[ib->length_dw++] =0x00000001 ; - ib->ptr[ib->length_dw++] = handle; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = addr; + *ptr++ =0x00000018 ; + *ptr++ =0x00000001 ; + *ptr++ = handle; + *ptr++ =0x00000000 ; + *ptr++ =upper_32_bits (addr); + *ptr++ = addr; - ib->ptr[ib->length_dw++] =0x00000014 ; - ib->ptr[ib->length_dw++] =0x00000002 ; - ib->ptr[ib->length_dw++] =0x0000001c ; - ib->ptr[ib->length_dw++] =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000000 ; + *ptr++ =0x00000014 ; + *ptr++ =0x00000002 ; + *ptr++ =0x0000001c ; + *ptr++ =0x00000000 ; + *ptr++ =0x00000000 ; - ib->ptr[ib->length_dw++] =0x00000008 ; - ib->ptr[ib->length_dw++] =0x08000002 ;/* op close session */ + *ptr++ =0x00000008 ; + *ptr++ =0x08000002 ;/* op close session */ -for (i = ib->length_dw; i < ib_size_dw; ++i) - ib->ptr[i] =0x0 ; + ib->length_dw = ptr - ib->ptr; + +memset32 (ptr,0 , ib_size_dw - ib->length_dw); r =amdgpu_job_submit_direct (job, ring, &f);if (r)
Signature · 1 line
2.48.0
RFC 15/25 drm/amdgpu: More compact SI SDMA emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/si_dma.c | 84 +++++++++++++++++------------ 1 file changed, 51 insertions(+), 33 deletions(-)
drivers/gpu/drm/amd/amdgpu/si_dma.c +51 -33
@@ -323,14 +323,16 @@ static void si_dma_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =DMA_PACKET (DMA_PACKET_COPY , -1 ,0 ,0 , bytes); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (pe) &0xff ; - ib->ptr[ib->length_dw++] =upper_32_bits (src) &0xff ; + *ptr++ =DMA_PACKET (DMA_PACKET_COPY ,1 ,0 ,0 , bytes); + *ptr++ =lower_32_bits (pe); + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (pe) &0xff ; + *ptr++ =upper_32_bits (src) &0xff ; + + ib->length_dw = ptr - ib->ptr; }/**
@@ -348,16 +350,19 @@ static void si_dma_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =DMA_PACKET (DMA_PACKET_WRITE ,0 ,0 ,0 , ndw); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =DMA_PACKET (DMA_PACKET_WRITE ,0 ,0 ,0 , ndw); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe);for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -377,6 +382,7 @@ static void si_dma_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw];uint64_t value;unsigned ndw;
@@ -391,19 +397,21 @@ static void si_dma_vm_set_pte_pde(struct amdgpu_ib *ib, value =0 ;/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] =DMA_PTE_PDE_PACKET (ndw); - ib->ptr[ib->length_dw++] = pe;/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe) &0xff ; - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] = value;/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (value); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; + *ptr++ =DMA_PTE_PDE_PACKET (ndw); + *ptr++ = pe;/* dst addr */ + *ptr++ =upper_32_bits (pe) &0xff ; + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ = value;/* value */ + *ptr++ =upper_32_bits (value); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; pe += ndw *4 ; addr += (ndw /2 ) * incr; count -= ndw /2 ; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -415,8 +423,12 @@ static void si_dma_vm_set_pte_pde(struct amdgpu_ib *ib,*/ static void si_dma_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) { -while (ib->length_dw &0x7 ) - ib->ptr[ib->length_dw++] =DMA_PACKET (DMA_PACKET_NOP ,0 ,0 ,0 ,0 ); +int pad =8 - (ib->length_dw &0x7 ); + +if (pad && pad <8 ) { +memset32 (ib->ptr,DMA_PACKET (DMA_PACKET_NOP ,0 ,0 ,0 ,0 ), pad); + ib->length_dw += pad; + } }/**
@@ -783,12 +795,15 @@ static void si_dma_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =DMA_PACKET (DMA_PACKET_COPY , -1 ,0 ,0 , byte_count); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset) &0xff ; - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset) &0xff ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =DMA_PACKET (DMA_PACKET_COPY ,1 ,0 ,0 , byte_count); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (dst_offset) &0xff ; + *ptr++ =upper_32_bits (src_offset) &0xff ; + + ib->length_dw = ptr - ib->ptr; }/**
@@ -806,11 +821,14 @@ static void si_dma_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =DMA_PACKET (DMA_PACKET_CONSTANT_FILL , -0 ,0 ,0 , byte_count /4 ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset) <<16 ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =DMA_PACKET (DMA_PACKET_CONSTANT_FILL ,0 ,0 ,0 , byte_count /4 ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ =upper_32_bits (dst_offset) <<16 ; + + ib->length_dw = ptr - ib->ptr; }
Signature · 1 line
2.48.0
RFC 16/25 drm/amdgpu: More compact CIK SDMA IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/cik_sdma.c | 105 +++++++++++++++----------- 1 file changed, 63 insertions(+), 42 deletions(-)
drivers/gpu/drm/amd/amdgpu/cik_sdma.c +63 -42
@@ -718,16 +718,18 @@ static void cik_sdma_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PACKET (SDMA_OPCODE_COPY , -SDMA_WRITE_SUB_OPCODE_LINEAR ,0 ); - ib->ptr[ib->length_dw++] = bytes; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PACKET (SDMA_OPCODE_COPY ,SDMA_WRITE_SUB_OPCODE_LINEAR ,0 ); + *ptr++ = bytes; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -745,18 +747,21 @@ static void cik_sdma_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PACKET (SDMA_OPCODE_WRITE , -SDMA_WRITE_SUB_OPCODE_LINEAR ,0 ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw; + *ptr++ =SDMA_PACKET (SDMA_OPCODE_WRITE , +SDMA_WRITE_SUB_OPCODE_LINEAR ,0 ); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -775,17 +780,21 @@ static void cik_sdma_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PACKET(SDMA_OPCODE_GENERATE_PTE_PDE, 0, 0); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count;/* number of entries */ + *ptr++ =SDMA_PACKET (SDMA_OPCODE_GENERATE_PTE_PDE ,0 ,0 ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -798,18 +807,22 @@ static void cik_sdma_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,static void cik_sdma_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PACKET (SDMA_OPCODE_NOP ,0 ,0 ) | -SDMA_NOP_COUNT (pad_count -1 ); + *ptr++ =SDMA_PACKET (SDMA_OPCODE_NOP ,0 ,0 ) | +SDMA_NOP_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PACKET (SDMA_OPCODE_NOP ,0 ,0 ); + *ptr++ =SDMA_PACKET (SDMA_OPCODE_NOP ,0 ,0 ); + + ib->length_dw += pad_count; }/**
@@ -1290,13 +1303,17 @@ static void cik_sdma_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PACKET (SDMA_OPCODE_COPY ,SDMA_COPY_SUB_OPCODE_LINEAR ,0 ); - ib->ptr[ib->length_dw++] = byte_count; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PACKET (SDMA_OPCODE_COPY ,SDMA_COPY_SUB_OPCODE_LINEAR ,0 ); + *ptr++ = byte_count; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1314,11 +1331,15 @@ static void cik_sdma_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PACKET (SDMA_OPCODE_CONSTANT_FILL ,0 ,0 ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PACKET (SDMA_OPCODE_CONSTANT_FILL ,0 ,0 ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs cik_sdma_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 17/25 drm/amdgpu: More compact GFX 9.4.2 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c | 51 +++++++++++++------------ 1 file changed, 26 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_2.c +26 -25
@@ -354,6 +354,7 @@ static int gfx_v9_4_2_run_shader(struct amdgpu_device *adev,int r, i;uint32_t total_size, shader_offset;u64 gpu_addr; +u32 *ptr; total_size = (regs_size *3 +4 +5 +5 ) *4 ; total_size =ALIGN (total_size,256 );
@@ -370,43 +371,43 @@ static int gfx_v9_4_2_run_shader(struct amdgpu_device *adev, }/* load the compute shaders */ -for (i =0 ; i < shader_size/sizeof (u32); i++) - ib->ptr[i + (shader_offset /4 )] = shader_ptr[i]; +memcpy (&ib->ptr[shader_offset /sizeof (u32)], shader_ptr, shader_size); -/* init the ib length to 0 */ - ib->length_dw =0 ; + ptr = ib->ptr;/* write the register state for the compute dispatch */ for (i =0 ; i < regs_size; i++) { - ib->ptr[ib->length_dw++] =PACKET3 (PACKET3_SET_SH_REG ,1 ); - ib->ptr[ib->length_dw++] =SOC15_REG_ENTRY_OFFSET (init_regs[i]) - -PACKET3_SET_SH_REG_START ; - ib->ptr[ib->length_dw++] = init_regs[i].reg_value; + *ptr++ =PACKET3 (PACKET3_SET_SH_REG ,1 ); + *ptr++ =SOC15_REG_ENTRY_OFFSET (init_regs[i]) - +PACKET3_SET_SH_REG_START ; + *ptr++ = init_regs[i].reg_value; }/* write the shader start address: mmCOMPUTE_PGM_LO, mmCOMPUTE_PGM_HI */ gpu_addr = (ib->gpu_addr + (u64 )shader_offset) >>8 ; - ib->ptr[ib->length_dw++] =PACKET3 (PACKET3_SET_SH_REG ,2 ); - ib->ptr[ib->length_dw++] =SOC15_REG_OFFSET (GC ,0 , regCOMPUTE_PGM_LO) - -PACKET3_SET_SH_REG_START ; - ib->ptr[ib->length_dw++] =lower_32_bits (gpu_addr); - ib->ptr[ib->length_dw++] =upper_32_bits (gpu_addr); + *ptr++ =PACKET3 (PACKET3_SET_SH_REG ,2 ); + *ptr++ =SOC15_REG_OFFSET (GC ,0 , regCOMPUTE_PGM_LO) + -PACKET3_SET_SH_REG_START ; + *ptr++ =lower_32_bits (gpu_addr); + *ptr++ =upper_32_bits (gpu_addr);/* write the wb buffer address */ - ib->ptr[ib->length_dw++] =PACKET3 (PACKET3_SET_SH_REG ,3 ); - ib->ptr[ib->length_dw++] =SOC15_REG_OFFSET (GC ,0 , regCOMPUTE_USER_DATA_0) - -PACKET3_SET_SH_REG_START ; - ib->ptr[ib->length_dw++] =lower_32_bits (wb_gpu_addr); - ib->ptr[ib->length_dw++] =upper_32_bits (wb_gpu_addr); - ib->ptr[ib->length_dw++] = pattern; + *ptr++ =PACKET3 (PACKET3_SET_SH_REG ,3 ); + *ptr++ =SOC15_REG_OFFSET (GC ,0 , regCOMPUTE_USER_DATA_0) - +PACKET3_SET_SH_REG_START ; + *ptr++ =lower_32_bits (wb_gpu_addr); + *ptr++ =upper_32_bits (wb_gpu_addr); + *ptr++ = pattern;/* write dispatch packet */ - ib->ptr[ib->length_dw++] =PACKET3 (PACKET3_DISPATCH_DIRECT ,3 ); - ib->ptr[ib->length_dw++] = compute_dim_x;/* x */ - ib->ptr[ib->length_dw++] =1 ;/* y */ - ib->ptr[ib->length_dw++] =1 ;/* z */ - ib->ptr[ib->length_dw++] = -REG_SET_FIELD (0 ,COMPUTE_DISPATCH_INITIATOR ,COMPUTE_SHADER_EN ,1 ); + *ptr++ =PACKET3 (PACKET3_DISPATCH_DIRECT ,3 ); + *ptr++ = compute_dim_x;/* x */ + *ptr++ =1 ;/* y */ + *ptr++ =1 ;/* z */ + *ptr++ =REG_SET_FIELD (0 ,COMPUTE_DISPATCH_INITIATOR ,COMPUTE_SHADER_EN , +1 ); + + ib->length_dw = ptr - ib->ptr;/* shedule the ib on the ring */ r =amdgpu_ib_schedule (ring,1 , ib,NULL , fence_ptr);
Signature · 1 line
2.48.0
RFC 18/25 drm/amdgpu: More compact SDMA 2.4 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c | 108 +++++++++++++++---------- 1 file changed, 65 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v2_4.c +65 -43
@@ -654,16 +654,19 @@ static void sdma_v2_4_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = bytes; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = bytes; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -681,18 +684,21 @@ static void sdma_v2_4_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] = pe; - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw; + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); + *ptr++ = pe; + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -711,17 +717,21 @@ static void sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count;/* number of entries */ + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_GEN_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -734,18 +744,22 @@ static void sdma_v2_4_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,static void sdma_v2_4_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | -SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | +SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw += pad_count; }/**
@@ -1184,14 +1198,18 @@ static void sdma_v2_4_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = byte_count; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = byte_count; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1209,11 +1227,15 @@ static void sdma_v2_4_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v2_4_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 19/25 drm/amdgpu: More compact SDMA 3.0 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c | 108 +++++++++++++++---------- 1 file changed, 65 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c +65 -43
@@ -927,16 +927,19 @@ static void sdma_v3_0_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = bytes; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = bytes; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -954,18 +957,21 @@ static void sdma_v3_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw; + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -984,17 +990,21 @@ static void sdma_v3_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_GEN_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count;/* number of entries */ + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_GEN_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1007,18 +1017,22 @@ static void sdma_v3_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t pe,static void sdma_v3_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | -SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | +SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw = pad_count; }/**
@@ -1626,14 +1640,18 @@ static void sdma_v3_0_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = byte_count; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = byte_count; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1651,11 +1669,15 @@ static void sdma_v3_0_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v3_0_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 20/25 drm/amdgpu: More compact SDMA 4.0 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c | 109 +++++++++++++++---------- 1 file changed, 65 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_0.c +65 -44
@@ -1587,17 +1587,19 @@ static void sdma_v4_0_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = bytes -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = bytes -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + ib->length_dw = ptr - ib->ptr; }/**
@@ -1615,18 +1617,21 @@ static void sdma_v4_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw -1 ; + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw -1 ;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1646,17 +1651,21 @@ static void sdma_v4_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count -1 ;/* number of entries */ + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count -1 ;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1668,18 +1677,22 @@ static void sdma_v4_0_vm_set_pte_pde(struct amdgpu_ib *ib,static void sdma_v4_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | -SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | +SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw += pad_count; }
@@ -2563,15 +2576,19 @@ static void sdma_v4_0_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | -SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); - ib->ptr[ib->length_dw++] = byte_count -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | +SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); + *ptr++ = byte_count -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -2589,11 +2606,15 @@ static void sdma_v4_0_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count -1 ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count -1 ; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v4_0_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 21/25 drm/amdgpu: More compact SDMA 4.4.2 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c | 108 ++++++++++++++--------- 1 file changed, 65 insertions(+), 43 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v4_4_2.c +65 -43
@@ -1184,16 +1184,19 @@ static void sdma_v4_4_2_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = bytes -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = bytes -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + + ib->length_dw = ptr - ib->ptr; }
@@ -1212,18 +1215,21 @@ static void sdma_v4_4_2_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) |SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw -1 ; + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw -1 ;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1243,17 +1249,21 @@ static void sdma_v4_4_2_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count -1 ;/* number of entries */ + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count -1 ;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1265,18 +1275,22 @@ static void sdma_v4_4_2_vm_set_pte_pde(struct amdgpu_ib *ib,static void sdma_v4_4_2_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | -SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | +SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw += pad_count; }
@@ -2265,15 +2279,19 @@ static void sdma_v4_4_2_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | -SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); - ib->ptr[ib->length_dw++] = byte_count -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | +SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); + *ptr++ = byte_count -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -2291,11 +2309,15 @@ static void sdma_v4_4_2_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count -1 ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count -1 ; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v4_4_2_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 22/25 drm/amdgpu: More compact SDMA 5.0 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c | 106 +++++++++++++++---------- 1 file changed, 64 insertions(+), 42 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_0.c +64 -42
@@ -1155,16 +1155,19 @@ static void sdma_v5_0_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = bytes -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = bytes -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + + ib->length_dw = ptr - ib->ptr; }
@@ -1183,18 +1186,21 @@ static void sdma_v5_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw -1 ; + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw -1 ;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1214,17 +1220,21 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count -1 ;/* number of entries */ + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count -1 ;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1237,18 +1247,22 @@ static void sdma_v5_0_vm_set_pte_pde(struct amdgpu_ib *ib,static void sdma_v5_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &0x7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | -SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | +SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw += pad_count; }
@@ -2021,15 +2035,19 @@ static void sdma_v5_0_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) |SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) |SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); - ib->ptr[ib->length_dw++] = byte_count -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); + *ptr++ = byte_count -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -2047,11 +2065,15 @@ static void sdma_v5_0_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count -1 ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count -1 ; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v5_0_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 23/25 drm/amdgpu: More compact SDMA 5.2 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c | 110 +++++++++++++++---------- 1 file changed, 66 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v5_2.c +66 -44
@@ -1065,15 +1065,18 @@ static void sdma_v5_2_vm_copy_pte(struct amdgpu_ib *ib, unsigned count) {unsigned bytes = count *8 ; +u32 *ptr = &ib->ptr[ib->length_dw]; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = bytes -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = bytes -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + + ib->length_dw = ptr - ib->ptr; }
@@ -1093,17 +1096,20 @@ static void sdma_v5_2_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint32_t incr) {unsigned ndw = count *2 ; +u32 *ptr = &ib->ptr[ib->length_dw]; - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw -1 ; + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_WRITE ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw -1 ;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1123,17 +1129,21 @@ static void sdma_v5_2_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_HEADER_OP(SDMA_OP_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count -1 ;/* number of entries */ + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count -1 ;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1147,18 +1157,22 @@ static void sdma_v5_2_vm_set_pte_pde(struct amdgpu_ib *ib,static void sdma_v5_2_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &0x7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | -SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ) | +SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw += pad_count; }
@@ -2046,15 +2060,19 @@ static void sdma_v5_2_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | -SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); - ib->ptr[ib->length_dw++] = byte_count -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | +SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); + *ptr++ = byte_count -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -2072,11 +2090,15 @@ static void sdma_v5_2_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count -1 ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_HEADER_OP (SDMA_OP_CONST_FILL ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count -1 ; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v5_2_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 24/25 drm/amdgpu: More compact SDMA 6.0 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c | 110 +++++++++++++++---------- 1 file changed, 66 insertions(+), 44 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v6_0.c +66 -44
@@ -1060,16 +1060,19 @@ static void sdma_v6_0_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); - ib->ptr[ib->length_dw++] = bytes -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ); + *ptr++ = bytes -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + + ib->length_dw = ptr - ib->ptr; }
@@ -1088,18 +1091,21 @@ static void sdma_v6_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_WRITE ) | -SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw -1 ; + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_WRITE ) | +SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw -1 ;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1119,17 +1125,21 @@ static void sdma_v6_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count -1 ;/* number of entries */ + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count -1 ;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/*
@@ -1142,18 +1152,22 @@ static void sdma_v6_0_vm_set_pte_pde(struct amdgpu_ib *ib,static void sdma_v6_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &0x7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ) | -SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 ); + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ) | +SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw += pad_count; }/**
@@ -1839,15 +1853,19 @@ static void sdma_v6_0_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t byte_count, uint32_t copy_flags) { - ib->ptr[ib->length_dw++] =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | -SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); - ib->ptr[ib->length_dw++] = byte_count -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | +SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ); + *ptr++ = byte_count -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1865,11 +1883,15 @@ static void sdma_v6_0_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_CONSTANT_FILL_HEADER_OP (SDMA_OP_CONST_FILL ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count -1 ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_CONSTANT_FILL_HEADER_OP (SDMA_OP_CONST_FILL ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count -1 ; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v6_0_buffer_funcs = {
Signature · 1 line
2.48.0
RFC 25/25 drm/amdgpu: More compact SDMA 7.0 IB emission
In reply to Tvrtko UrsulinAvoid constant register reloads while emitting IBs by using a local write pointer and only updating the size at the end of each helper.
--- drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c | 119 +++++++++++++++---------- 1 file changed, 70 insertions(+), 49 deletions(-)
drivers/gpu/drm/amd/amdgpu/sdma_v7_0.c +70 -49
@@ -1077,19 +1077,22 @@ static void sdma_v7_0_vm_copy_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t src, unsigned count) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned bytes = count *8 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | -SDMA_PKT_COPY_LINEAR_HEADER_CPV (1 ); + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | +SDMA_PKT_COPY_LINEAR_HEADER_CPV (1 ); - ib->ptr[ib->length_dw++] = bytes -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src); - ib->ptr[ib->length_dw++] =upper_32_bits (src); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =0 ; + *ptr++ = bytes -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src); + *ptr++ =upper_32_bits (src); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ =0 ; + + ib->length_dw = ptr - ib->ptr; }
@@ -1108,18 +1111,21 @@ static void sdma_v7_0_vm_write_pte(struct amdgpu_ib *ib, uint64_t pe, uint64_t value, unsigned count, uint32_t incr) { + u32 *ptr = &ib->ptr[ib->length_dw];unsigned ndw = count *2 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_WRITE ) | -SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); - ib->ptr[ib->length_dw++] =lower_32_bits (pe); - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] = ndw -1 ; + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_WRITE ) | +SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_WRITE_LINEAR ); + *ptr++ =lower_32_bits (pe); + *ptr++ =upper_32_bits (pe); + *ptr++ = ndw -1 ;for (; ndw >0 ; ndw -=2 ) { - ib->ptr[ib->length_dw++] =lower_32_bits (value); - ib->ptr[ib->length_dw++] =upper_32_bits (value); + *ptr++ =lower_32_bits (value); + *ptr++ =upper_32_bits (value); value += incr; } + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1139,17 +1145,21 @@ static void sdma_v7_0_vm_set_pte_pde(struct amdgpu_ib *ib, uint64_t addr, unsigned count, uint32_t incr, uint64_t flags) { + u32 *ptr = &ib->ptr[ib->length_dw]; +/* for physically contiguous pages (vram) */ - ib->ptr[ib->length_dw++] = SDMA_PKT_COPY_LINEAR_HEADER_OP(SDMA_OP_PTEPDE); - ib->ptr[ib->length_dw++] =lower_32_bits (pe);/* dst addr */ - ib->ptr[ib->length_dw++] =upper_32_bits (pe); - ib->ptr[ib->length_dw++] =lower_32_bits (flags);/* mask */ - ib->ptr[ib->length_dw++] =upper_32_bits (flags); - ib->ptr[ib->length_dw++] =lower_32_bits (addr);/* value */ - ib->ptr[ib->length_dw++] =upper_32_bits (addr); - ib->ptr[ib->length_dw++] = incr;/* increment size */ - ib->ptr[ib->length_dw++] =0 ; - ib->ptr[ib->length_dw++] = count -1 ;/* number of entries */ + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_PTEPDE ); + *ptr++ =lower_32_bits (pe);/* dst addr */ + *ptr++ =upper_32_bits (pe); + *ptr++ =lower_32_bits (flags);/* mask */ + *ptr++ =upper_32_bits (flags); + *ptr++ =lower_32_bits (addr);/* value */ + *ptr++ =upper_32_bits (addr); + *ptr++ = incr;/* increment size */ + *ptr++ =0 ; + *ptr++ = count -1 ;/* number of entries */ + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1163,18 +1173,22 @@ static void sdma_v7_0_vm_set_pte_pde(struct amdgpu_ib *ib,static void sdma_v7_0_ring_pad_ib (struct amdgpu_ring *ring,struct amdgpu_ib *ib) {struct amdgpu_sdma_instance *sdma =amdgpu_sdma_get_instance_from_ring (ring); +u32 *ptr = &ib->ptr[ib->length_dw];u32 pad_count;int i; pad_count = (-ib->length_dw) &0x7 ; +if (!pad_count) +return ; +for (i =0 ; i < pad_count; i++)if (sdma && sdma->burst_nop && (i ==0 )) - ib->ptr[ib->length_dw++] = -SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ) | + *ptr++=SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ) |SDMA_PKT_NOP_HEADER_COUNT (pad_count -1 );else - ib->ptr[ib->length_dw++] = -SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ); + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_NOP ); + + ib->length_dw += pad_count; }/**
@@ -1765,31 +1779,34 @@ static void sdma_v7_0_emit_copy_buffer(struct amdgpu_ib *ib, uint32_t copy_flags) {uint32_t num_type, data_format, max_com, write_cm; +u32 *ptr = &ib->ptr[ib->length_dw]; max_com =AMDGPU_COPY_FLAGS_GET (copy_flags,MAX_COMPRESSED ); data_format =AMDGPU_COPY_FLAGS_GET (copy_flags,DATA_FORMAT ); num_type =AMDGPU_COPY_FLAGS_GET (copy_flags,NUMBER_TYPE ); write_cm =AMDGPU_COPY_FLAGS_GET (copy_flags,WRITE_COMPRESS_DISABLE ) ?2 :1 ; - ib->ptr[ib->length_dw++] =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | -SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | -SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ) | -SDMA_PKT_COPY_LINEAR_HEADER_CPV (1 ); + *ptr++ =SDMA_PKT_COPY_LINEAR_HEADER_OP (SDMA_OP_COPY ) | +SDMA_PKT_COPY_LINEAR_HEADER_SUB_OP (SDMA_SUBOP_COPY_LINEAR ) | +SDMA_PKT_COPY_LINEAR_HEADER_TMZ ((copy_flags &AMDGPU_COPY_FLAGS_TMZ ) ?1 :0 ) | +SDMA_PKT_COPY_LINEAR_HEADER_CPV (1 ); - ib->ptr[ib->length_dw++] = byte_count -1 ; - ib->ptr[ib->length_dw++] =0 ;/* src/dst endian swap */ - ib->ptr[ib->length_dw++] =lower_32_bits (src_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (src_offset); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); + *ptr++ = byte_count -1 ; + *ptr++ =0 ;/* src/dst endian swap */ + *ptr++ =lower_32_bits (src_offset); + *ptr++ =upper_32_bits (src_offset); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset);if ((copy_flags & (AMDGPU_COPY_FLAGS_READ_DECOMPRESSED |AMDGPU_COPY_FLAGS_WRITE_COMPRESSED ))) - ib->ptr[ib->length_dw++] =SDMA_DCC_DATA_FORMAT (data_format) |SDMA_DCC_NUM_TYPE (num_type) | + *ptr++ =SDMA_DCC_DATA_FORMAT (data_format) |SDMA_DCC_NUM_TYPE (num_type) | ((copy_flags &AMDGPU_COPY_FLAGS_READ_DECOMPRESSED ) ?SDMA_DCC_READ_CM (2 ) :0 ) | ((copy_flags &AMDGPU_COPY_FLAGS_WRITE_COMPRESSED ) ?SDMA_DCC_WRITE_CM (write_cm) :0 ) |SDMA_DCC_MAX_COM (max_com) |SDMA_DCC_MAX_UCOM (1 );else - ib->ptr[ib->length_dw++] =0 ; + *ptr++ =0 ; + + ib->length_dw = ptr - ib->ptr; }/**
@@ -1807,12 +1824,16 @@ static void sdma_v7_0_emit_fill_buffer(struct amdgpu_ib *ib, uint64_t dst_offset, uint32_t byte_count) { - ib->ptr[ib->length_dw++] =SDMA_PKT_CONSTANT_FILL_HEADER_OP (SDMA_OP_CONST_FILL ) | -SDMA_PKT_CONSTANT_FILL_HEADER_COMPRESS (1 ); - ib->ptr[ib->length_dw++] =lower_32_bits (dst_offset); - ib->ptr[ib->length_dw++] =upper_32_bits (dst_offset); - ib->ptr[ib->length_dw++] = src_data; - ib->ptr[ib->length_dw++] = byte_count -1 ; +u32 *ptr = &ib->ptr[ib->length_dw]; + + *ptr++ =SDMA_PKT_CONSTANT_FILL_HEADER_OP (SDMA_OP_CONST_FILL ) | +SDMA_PKT_CONSTANT_FILL_HEADER_COMPRESS (1 ); + *ptr++ =lower_32_bits (dst_offset); + *ptr++ =upper_32_bits (dst_offset); + *ptr++ = src_data; + *ptr++ = byte_count -1 ; + + ib->length_dw = ptr - ib->ptr; }static const struct amdgpu_buffer_funcs sdma_v7_0_buffer_funcs = {
Signature · 1 line
2.48.0