From: Jani Nikula <jani.nikula@linux.intel.com>
To: Uros Bizjak <ubizjak@gmail.com>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
David Airlie <airlied@gmail.com>
Subject: Re: [Intel-gfx] [PATCH] drm/i915/pmu: Use local64_try_cmpxchg in i915_pmu_event_read
Date: Thu, 05 Oct 2023 13:22:15 +0300 [thread overview]
Message-ID: <87ttr5cqso.fsf@intel.com> (raw)
In-Reply-To: <20230703150859.6176-1-ubizjak@gmail.com>
On Mon, 03 Jul 2023, Uros Bizjak <ubizjak@gmail.com> wrote:
> Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> in i915_pmu_event_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: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> ---
> drivers/gpu/drm/i915/i915_pmu.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
> index d35973b41186..108b675088ba 100644
> --- a/drivers/gpu/drm/i915/i915_pmu.c
> +++ b/drivers/gpu/drm/i915/i915_pmu.c
> @@ -696,12 +696,11 @@ static void i915_pmu_event_read(struct perf_event *event)
> event->hw.state = PERF_HES_STOPPED;
> return;
> }
> -again:
> - prev = local64_read(&hwc->prev_count);
> - new = __i915_pmu_event_read(event);
>
> - if (local64_cmpxchg(&hwc->prev_count, prev, new) != prev)
> - goto again;
> + prev = local64_read(&hwc->prev_count);
> + do {
> + new = __i915_pmu_event_read(event);
> + } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, new));
Chased through the documentation again, and pushed to drm-intel-next.
Thanks for the patch.
BR,
Jani.
>
> local64_add(new - prev, &event->count);
> }
--
Jani Nikula, Intel
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Uros Bizjak <ubizjak@gmail.com>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
Uros Bizjak <ubizjak@gmail.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>
Subject: Re: [PATCH] drm/i915/pmu: Use local64_try_cmpxchg in i915_pmu_event_read
Date: Thu, 05 Oct 2023 13:22:15 +0300 [thread overview]
Message-ID: <87ttr5cqso.fsf@intel.com> (raw)
In-Reply-To: <20230703150859.6176-1-ubizjak@gmail.com>
On Mon, 03 Jul 2023, Uros Bizjak <ubizjak@gmail.com> wrote:
> Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> in i915_pmu_event_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: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> ---
> drivers/gpu/drm/i915/i915_pmu.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
> index d35973b41186..108b675088ba 100644
> --- a/drivers/gpu/drm/i915/i915_pmu.c
> +++ b/drivers/gpu/drm/i915/i915_pmu.c
> @@ -696,12 +696,11 @@ static void i915_pmu_event_read(struct perf_event *event)
> event->hw.state = PERF_HES_STOPPED;
> return;
> }
> -again:
> - prev = local64_read(&hwc->prev_count);
> - new = __i915_pmu_event_read(event);
>
> - if (local64_cmpxchg(&hwc->prev_count, prev, new) != prev)
> - goto again;
> + prev = local64_read(&hwc->prev_count);
> + do {
> + new = __i915_pmu_event_read(event);
> + } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, new));
Chased through the documentation again, and pushed to drm-intel-next.
Thanks for the patch.
BR,
Jani.
>
> local64_add(new - prev, &event->count);
> }
--
Jani Nikula, Intel
WARNING: multiple messages have this Message-ID (diff)
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Uros Bizjak <ubizjak@gmail.com>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>
Subject: Re: [PATCH] drm/i915/pmu: Use local64_try_cmpxchg in i915_pmu_event_read
Date: Thu, 05 Oct 2023 13:22:15 +0300 [thread overview]
Message-ID: <87ttr5cqso.fsf@intel.com> (raw)
In-Reply-To: <20230703150859.6176-1-ubizjak@gmail.com>
On Mon, 03 Jul 2023, Uros Bizjak <ubizjak@gmail.com> wrote:
> Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old
> in i915_pmu_event_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: Jani Nikula <jani.nikula@linux.intel.com>
> Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
> Cc: David Airlie <airlied@gmail.com>
> Cc: Daniel Vetter <daniel@ffwll.ch>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> ---
> drivers/gpu/drm/i915/i915_pmu.c | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
> index d35973b41186..108b675088ba 100644
> --- a/drivers/gpu/drm/i915/i915_pmu.c
> +++ b/drivers/gpu/drm/i915/i915_pmu.c
> @@ -696,12 +696,11 @@ static void i915_pmu_event_read(struct perf_event *event)
> event->hw.state = PERF_HES_STOPPED;
> return;
> }
> -again:
> - prev = local64_read(&hwc->prev_count);
> - new = __i915_pmu_event_read(event);
>
> - if (local64_cmpxchg(&hwc->prev_count, prev, new) != prev)
> - goto again;
> + prev = local64_read(&hwc->prev_count);
> + do {
> + new = __i915_pmu_event_read(event);
> + } while (!local64_try_cmpxchg(&hwc->prev_count, &prev, new));
Chased through the documentation again, and pushed to drm-intel-next.
Thanks for the patch.
BR,
Jani.
>
> local64_add(new - prev, &event->count);
> }
--
Jani Nikula, Intel
next prev parent reply other threads:[~2023-10-05 10:22 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-03 15:08 [Intel-gfx] [PATCH] drm/i915/pmu: Use local64_try_cmpxchg in i915_pmu_event_read Uros Bizjak
2023-07-03 15:08 ` Uros Bizjak
2023-07-03 15:08 ` Uros Bizjak
2023-07-04 7:28 ` [Intel-gfx] " Jani Nikula
2023-07-04 7:28 ` Jani Nikula
2023-07-04 7:28 ` Jani Nikula
2023-07-04 8:05 ` [Intel-gfx] " Uros Bizjak
2023-07-04 8:05 ` Uros Bizjak
2023-07-04 8:05 ` Uros Bizjak
2023-07-04 8:37 ` [Intel-gfx] " Jani Nikula
2023-07-04 8:37 ` Jani Nikula
2023-07-04 8:37 ` Jani Nikula
2023-07-04 9:25 ` [Intel-gfx] " Uros Bizjak
2023-07-04 9:25 ` Uros Bizjak
2023-07-04 9:25 ` Uros Bizjak
2023-07-06 18:48 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for " Patchwork
2023-07-06 19:00 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-07-07 0:59 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2023-07-10 14:11 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/i915/pmu: Use local64_try_cmpxchg in i915_pmu_event_read (rev2) Patchwork
2023-07-10 14:24 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
2023-07-10 17:58 ` [Intel-gfx] ✗ Fi.CI.IGT: failure " Patchwork
2023-10-05 10:22 ` Jani Nikula [this message]
2023-10-05 10:22 ` [PATCH] drm/i915/pmu: Use local64_try_cmpxchg in i915_pmu_event_read Jani Nikula
2023-10-05 10:22 ` Jani Nikula
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=87ttr5cqso.fsf@intel.com \
--to=jani.nikula@linux.intel.com \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rodrigo.vivi@intel.com \
--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.