From: Boyuan Zhang <Boyuan.Zhang@amd.com>
To: Alex Deucher <alexander.deucher@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu/vcn: fix idle work handler for VCN 2.5
Date: Tue, 4 Mar 2025 15:52:23 -0500 [thread overview]
Message-ID: <0358291a-7744-4e91-9442-3dd9f999d4d0@amd.com> (raw)
In-Reply-To: <20250304162242.4029795-1-alexander.deucher@amd.com>
On 2025-03-04 11:22, Alex Deucher wrote:
> VCN 2.5 uses the PG callback to enable VCN DPM which is
> a global state. As such, we need to make sure all instances
> are in the same state.
>
> v2: switch to a ref count (Lijo)
>
> Fixes: 4ce4fe27205c ("drm/amdgpu/vcn: use per instance callbacks for idle work handler")
> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h | 4 +++
> drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c | 41 +++++++++++++++++++------
> 2 files changed, 36 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
> index 26c9c2d90f455..3bc4fe4aeb481 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.h
> @@ -358,6 +358,10 @@ struct amdgpu_vcn {
>
> bool per_inst_fw;
> unsigned fw_version;
> + /* VCN 2.5 global PG handling */
> + struct mutex global_pg_lock;
> + unsigned int global_pg_count;
> + enum amd_powergating_state global_pg_state;
> };
>
> struct amdgpu_fw_shared_rb_ptrs_struct {
> diff --git a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
> index dff1a88590363..972f0842ea47b 100644
> --- a/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
> +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v2_5.c
> @@ -172,6 +172,8 @@ static int vcn_v2_5_sw_init(struct amdgpu_ip_block *ip_block)
> uint32_t *ptr;
> struct amdgpu_device *adev = ip_block->adev;
>
> + mutex_init(&adev->vcn.global_pg_lock);
> +
> for (j = 0; j < adev->vcn.num_vcn_inst; j++) {
> volatile struct amdgpu_fw_shared *fw_shared;
>
> @@ -1853,21 +1855,42 @@ static int vcn_v2_5_set_pg_state(struct amdgpu_vcn_inst *vinst,
> enum amd_powergating_state state)
> {
> struct amdgpu_device *adev = vinst->adev;
> - int ret;
> + struct amdgpu_vcn_inst *v;
> + int ret = 0, i;
>
> if (amdgpu_sriov_vf(adev))
> return 0;
>
> - if (state == vinst->cur_state)
> - return 0;
> + mutex_lock(&adev->vcn.global_pg_lock);
> + if (state == AMD_PG_STATE_GATE) {
> + if (adev->vcn.global_pg_count == 0)
> + goto unlock;
> + adev->vcn.global_pg_count--;
> + if (adev->vcn.global_pg_count == 0 &&
> + adev->vcn.global_pg_state == AMD_PG_STATE_UNGATE) {
> + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
> + v = &adev->vcn.inst[i];
> +
> + ret = vcn_v2_5_stop(v);
> + }
> + adev->vcn.global_pg_state = AMD_PG_STATE_GATE;
> + }
> + } else {
> + if (adev->vcn.global_pg_count == 0 &&
> + adev->vcn.global_pg_state == AMD_PG_STATE_GATE) {
> + for (i = 0; i < adev->vcn.num_vcn_inst; ++i) {
> + v = &adev->vcn.inst[i];
>
> - if (state == AMD_PG_STATE_GATE)
> - ret = vcn_v2_5_stop(vinst);
> - else
> - ret = vcn_v2_5_start(vinst);
> + ret = vcn_v2_5_start(v);
> + }
> + adev->vcn.global_pg_state = AMD_PG_STATE_UNGATE;
> + }
> + adev->vcn.global_pg_count++;
> + }
>
> - if (!ret)
> - vinst->cur_state = state;
> +unlock:
> + vinst->cur_state = state;
I guess we don't need to bother this per instant (vinst->cur_state) at
all in this case? Other than this, this patch is
Reviewed-by: Boyuan Zhang <Boyuan.Zhang@amd.com>
> + mutex_unlock(&adev->vcn.global_pg_lock);
>
> return ret;
> }
next prev parent reply other threads:[~2025-03-04 20:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 16:22 [PATCH] drm/amdgpu/vcn: fix idle work handler for VCN 2.5 Alex Deucher
2025-03-04 20:52 ` Boyuan Zhang [this message]
2025-03-04 21:05 ` Alex Deucher
2025-03-04 23:12 ` Alex Deucher
-- strict thread matches above, loose matches on Subject: below --
2025-03-05 19:17 Alex Deucher
2025-03-06 15:05 ` Alex Deucher
2025-03-07 15:22 ` Alex Deucher
2025-03-07 21:14 ` Zhang, Boyuan
2025-03-04 23:01 Alex Deucher
2025-03-05 14:20 ` Boyuan Zhang
2025-03-04 14:20 Alex Deucher
2025-03-04 14:37 ` Lazar, Lijo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0358291a-7744-4e91-9442-3dd9f999d4d0@amd.com \
--to=boyuan.zhang@amd.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox