[PATCH 2/4] drm/amdgpu: replace use of system_wq with system_percpu_wq

Marco Crivellari posted 4 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH 2/4] drm/amdgpu: replace use of system_wq with system_percpu_wq
Posted by Marco Crivellari 3 months, 1 week ago
Currently if a user enqueue a work item using schedule_delayed_work() the
used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use
WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to
schedule_work() that is using system_wq and queue_work(), that makes use
again of WORK_CPU_UNBOUND.

This lack of consistency cannot be addressed without refactoring the API.

system_wq should be the per-cpu workqueue, yet in this name nothing makes
that clear, so replace system_wq with system_percpu_wq.

The old wq (system_wq) will be kept for a few release cycles.

Suggested-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 8c4d79f6c14f..2f8160702f9a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -4798,7 +4798,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
 		}
 		/* must succeed. */
 		amdgpu_ras_resume(adev);
-		queue_delayed_work(system_wq, &adev->delayed_init_work,
+		queue_delayed_work(system_percpu_wq, &adev->delayed_init_work,
 				   msecs_to_jiffies(AMDGPU_RESUME_MS));
 	}
 
@@ -5328,7 +5328,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)
 	if (r)
 		goto exit;
 
-	queue_delayed_work(system_wq, &adev->delayed_init_work,
+	queue_delayed_work(system_percpu_wq, &adev->delayed_init_work,
 			   msecs_to_jiffies(AMDGPU_RESUME_MS));
 exit:
 	if (amdgpu_sriov_vf(adev)) {
-- 
2.51.0
Re: [PATCH 2/4] drm/amdgpu: replace use of system_wq with system_percpu_wq
Posted by Christian König 3 months, 1 week ago
On 10/30/25 17:10, Marco Crivellari wrote:
> Currently if a user enqueue a work item using schedule_delayed_work() the
> used wq is "system_wq" (per-cpu wq) while queue_delayed_work() use
> WORK_CPU_UNBOUND (used when a cpu is not specified). The same applies to
> schedule_work() that is using system_wq and queue_work(), that makes use
> again of WORK_CPU_UNBOUND.
> 
> This lack of consistency cannot be addressed without refactoring the API.
> 
> system_wq should be the per-cpu workqueue, yet in this name nothing makes
> that clear, so replace system_wq with system_percpu_wq.
> 
> The old wq (system_wq) will be kept for a few release cycles.

Oh, good point!

> 
> Suggested-by: Tejun Heo <tj@kernel.org>
> Signed-off-by: Marco Crivellari <marco.crivellari@suse.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 8c4d79f6c14f..2f8160702f9a 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -4798,7 +4798,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,
>  		}
>  		/* must succeed. */
>  		amdgpu_ras_resume(adev);
> -		queue_delayed_work(system_wq, &adev->delayed_init_work,
> +		queue_delayed_work(system_percpu_wq, &adev->delayed_init_work,
>  				   msecs_to_jiffies(AMDGPU_RESUME_MS));
>  	}
>  
> @@ -5328,7 +5328,7 @@ int amdgpu_device_resume(struct drm_device *dev, bool notify_clients)
>  	if (r)
>  		goto exit;
>  
> -	queue_delayed_work(system_wq, &adev->delayed_init_work,
> +	queue_delayed_work(system_percpu_wq, &adev->delayed_init_work,
>  			   msecs_to_jiffies(AMDGPU_RESUME_MS));

In this particular use case we actually don't want the percpu wq.

This can execute on any CPU except for the current one.

Regards,
Christian.

>  exit:
>  	if (amdgpu_sriov_vf(adev)) {
Re: [PATCH 2/4] drm/amdgpu: replace use of system_wq with system_percpu_wq
Posted by Marco Crivellari 3 months, 1 week ago
On Thu, Oct 30, 2025 at 6:10 PM Christian König
<christian.koenig@amd.com> wrote:
>[...]
> In this particular use case we actually don't want the percpu wq.
>
> This can execute on any CPU except for the current one.
>
> Regards,
> Christian.
>
> >  exit:
> >       if (amdgpu_sriov_vf(adev)) {
>

Hi Christian,

like for the unbound workqueue also the system_percpu_wq is just a
rename for system_wq.
Technically I changed the workqueue because we added in the code two wq:
- system_percpu_wq
- system_dfl_wq

You can see the commits mentioned in the cover letter, shared also below:

- commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
- commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")

So basically the behavior is the same.

But if it would be beneficial to have an unbound wq, I can send the v2
with the change!
We did so also for other subsystems.

Thanks!



--

Marco Crivellari

L3 Support Engineer, Technology & Product
Re: [PATCH 2/4] drm/amdgpu: replace use of system_wq with system_percpu_wq
Posted by Christian König 3 months, 1 week ago

On 10/31/25 10:01, Marco Crivellari wrote:
> On Thu, Oct 30, 2025 at 6:10 PM Christian König
> <christian.koenig@amd.com> wrote:
>> [...]
>> In this particular use case we actually don't want the percpu wq.
>>
>> This can execute on any CPU except for the current one.
>>
>> Regards,
>> Christian.
>>
>>>  exit:
>>>       if (amdgpu_sriov_vf(adev)) {
>>
> 
> Hi Christian,
> 
> like for the unbound workqueue also the system_percpu_wq is just a
> rename for system_wq.
> Technically I changed the workqueue because we added in the code two wq:
> - system_percpu_wq
> - system_dfl_wq
> 
> You can see the commits mentioned in the cover letter, shared also below:
> 
> - commit 128ea9f6ccfb ("workqueue: Add system_percpu_wq and system_dfl_wq")
> - commit 930c2ea566af ("workqueue: Add new WQ_PERCPU flag")
> 
> So basically the behavior is the same.
> 
> But if it would be beneficial to have an unbound wq, I can send the v2
> with the change!

Please do so. The purpose of offloading that into a work item is to execute it on a different CPU.

I wasn't aware that the system_wq was CPU bound at all.

Thanks to taking care of that,
Christian.

> We did so also for other subsystems.
> 
> Thanks!
> 
> 
> 
> --
> 
> Marco Crivellari
> 
> L3 Support Engineer, Technology & Product