All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Deucher <alexdeucher@gmail.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, "Pan, Xinhui" <Xinhui.Pan@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH] drm/amdgpu: Use local64_try_cmpxchg in amdgpu_perf_read
Date: Wed, 9 Aug 2023 18:09:36 -0400	[thread overview]
Message-ID: <CADnq5_MCquO_Sh0RUVYATbLwS1+h2UrLHoUkCXYeF7=R4kZmDg@mail.gmail.com> (raw)
In-Reply-To: <20230703150135.5784-1-ubizjak@gmail.com>

Applied.  Thanks!

Alex

On Mon, Jul 3, 2023 at 7:16 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> in amdgpu_perf_read.  x86 CMPXCHG instruction returns success in ZF flag,
> so this change saves a compare after cmpxchg (and related move instruction
> in front of cmpxchg).
>
> Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg
> fails. There is no need to re-read the value in the loop.
>
> No functional change intended.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
> index 71ee361d0972..6e91ea1de5aa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
> @@ -276,9 +276,8 @@ static void amdgpu_perf_read(struct perf_event *event)
>             (!pe->adev->df.funcs->pmc_get_count))
>                 return;
>
> +       prev = local64_read(&hwc->prev_count);
>         do {
> -               prev = local64_read(&hwc->prev_count);
> -
>                 switch (hwc->config_base) {
>                 case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
>                 case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
> @@ -289,7 +288,7 @@ static void amdgpu_perf_read(struct perf_event *event)
>                         count = 0;
>                         break;
>                 }
> -       } while (local64_cmpxchg(&hwc->prev_count, prev, count) != prev);
> +       } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, count));
>
>         local64_add(count - prev, &event->count);
>  }
> --
> 2.41.0
>

WARNING: multiple messages have this Message-ID (diff)
From: Alex Deucher <alexdeucher@gmail.com>
To: Uros Bizjak <ubizjak@gmail.com>
Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>,
	linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org,
	amd-gfx@lists.freedesktop.org,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: Re: [PATCH] drm/amdgpu: Use local64_try_cmpxchg in amdgpu_perf_read
Date: Wed, 9 Aug 2023 18:09:36 -0400	[thread overview]
Message-ID: <CADnq5_MCquO_Sh0RUVYATbLwS1+h2UrLHoUkCXYeF7=R4kZmDg@mail.gmail.com> (raw)
In-Reply-To: <20230703150135.5784-1-ubizjak@gmail.com>

Applied.  Thanks!

Alex

On Mon, Jul 3, 2023 at 7:16 PM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> in amdgpu_perf_read.  x86 CMPXCHG instruction returns success in ZF flag,
> so this change saves a compare after cmpxchg (and related move instruction
> in front of cmpxchg).
>
> Also, try_cmpxchg implicitly assigns old *ptr value to "old" when cmpxchg
> fails. There is no need to re-read the value in the loop.
>
> No functional change intended.
>
> Cc: Alex Deucher <alexander.deucher@amd.com>
> Cc: "Christian König" <christian.koenig@amd.com>
> Cc: "Pan, Xinhui" <Xinhui.Pan@amd.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
> index 71ee361d0972..6e91ea1de5aa 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pmu.c
> @@ -276,9 +276,8 @@ static void amdgpu_perf_read(struct perf_event *event)
>             (!pe->adev->df.funcs->pmc_get_count))
>                 return;
>
> +       prev = local64_read(&hwc->prev_count);
>         do {
> -               prev = local64_read(&hwc->prev_count);
> -
>                 switch (hwc->config_base) {
>                 case AMDGPU_PMU_EVENT_CONFIG_TYPE_DF:
>                 case AMDGPU_PMU_EVENT_CONFIG_TYPE_XGMI:
> @@ -289,7 +288,7 @@ static void amdgpu_perf_read(struct perf_event *event)
>                         count = 0;
>                         break;
>                 }
> -       } while (local64_cmpxchg(&hwc->prev_count, prev, count) != prev);
> +       } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, count));
>
>         local64_add(count - prev, &event->count);
>  }
> --
> 2.41.0
>

  reply	other threads:[~2023-08-09 22:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-03 15:00 [PATCH] drm/amdgpu: Use local64_try_cmpxchg in amdgpu_perf_read Uros Bizjak
2023-07-03 15:00 ` Uros Bizjak
2023-07-03 15:00 ` Uros Bizjak
2023-08-09 22:09 ` Alex Deucher [this message]
2023-08-09 22:09   ` Alex Deucher

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='CADnq5_MCquO_Sh0RUVYATbLwS1+h2UrLHoUkCXYeF7=R4kZmDg@mail.gmail.com' \
    --to=alexdeucher@gmail.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ubizjak@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.