2023-03-21 18:00:07

by Christophe JAILLET

[permalink] [raw]
Subject: [PATCH] drm/amd/display: Slightly optimize dm_dmub_outbox1_low_irq()

A kzalloc()+memcpy() can be optimized in a single kmemdup().
This saves a few cycles because some memory doesn't need to be zeroed.

Signed-off-by: Christophe JAILLET <[email protected]>
---
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 5bac5781a06b..57a5fbdab890 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -820,15 +820,14 @@ static void dm_dmub_outbox1_low_irq(void *interrupt_params)
DRM_ERROR("Failed to allocate dmub_hpd_wrk");
return;
}
- dmub_hpd_wrk->dmub_notify = kzalloc(sizeof(struct dmub_notification), GFP_ATOMIC);
+ dmub_hpd_wrk->dmub_notify = kmemdup(&notify, sizeof(struct dmub_notification),
+ GFP_ATOMIC);
if (!dmub_hpd_wrk->dmub_notify) {
kfree(dmub_hpd_wrk);
DRM_ERROR("Failed to allocate dmub_hpd_wrk->dmub_notify");
return;
}
INIT_WORK(&dmub_hpd_wrk->handle_hpd_work, dm_handle_hpd_work);
- if (dmub_hpd_wrk->dmub_notify)
- memcpy(dmub_hpd_wrk->dmub_notify, &notify, sizeof(struct dmub_notification));
dmub_hpd_wrk->adev = adev;
if (notify.type == DMUB_NOTIFICATION_HPD) {
plink = adev->dm.dc->links[notify.link_index];
--
2.32.0



2023-03-22 15:39:13

by Hamza Mahfooz

[permalink] [raw]
Subject: Re: [PATCH] drm/amd/display: Slightly optimize dm_dmub_outbox1_low_irq()

On 3/21/23 13:58, Christophe JAILLET wrote:
> A kzalloc()+memcpy() can be optimized in a single kmemdup().
> This saves a few cycles because some memory doesn't need to be zeroed.
>
> Signed-off-by: Christophe JAILLET <[email protected]>

Applied, thanks!

> ---
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index 5bac5781a06b..57a5fbdab890 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -820,15 +820,14 @@ static void dm_dmub_outbox1_low_irq(void *interrupt_params)
> DRM_ERROR("Failed to allocate dmub_hpd_wrk");
> return;
> }
> - dmub_hpd_wrk->dmub_notify = kzalloc(sizeof(struct dmub_notification), GFP_ATOMIC);
> + dmub_hpd_wrk->dmub_notify = kmemdup(&notify, sizeof(struct dmub_notification),
> + GFP_ATOMIC);
> if (!dmub_hpd_wrk->dmub_notify) {
> kfree(dmub_hpd_wrk);
> DRM_ERROR("Failed to allocate dmub_hpd_wrk->dmub_notify");
> return;
> }
> INIT_WORK(&dmub_hpd_wrk->handle_hpd_work, dm_handle_hpd_work);
> - if (dmub_hpd_wrk->dmub_notify)
> - memcpy(dmub_hpd_wrk->dmub_notify, &notify, sizeof(struct dmub_notification));
> dmub_hpd_wrk->adev = adev;
> if (notify.type == DMUB_NOTIFICATION_HPD) {
> plink = adev->dm.dc->links[notify.link_index];

--
Hamza