All of lore.kernel.org
 help / color / mirror / Atom feed
From: Uros Bizjak <ubizjak@gmail.com>
To: linux-alpha@vger.kernel.org, loongarch@lists.linux.dev,
	linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org,
	x86@kernel.org, linux-arch@vger.kernel.org,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Uros Bizjak <ubizjak@gmail.com>
Subject: [PATCH v2 5/5] events: Illustrate the transition to local{,64}_try_cmpxchg
Date: Wed,  5 Apr 2023 16:17:10 +0200	[thread overview]
Message-ID: <20230405141710.3551-6-ubizjak@gmail.com> (raw)
In-Reply-To: <20230405141710.3551-1-ubizjak@gmail.com>

This patch illustrates the transition to local{,64}_try_cmpxchg.
It is not intended to be merged as-is.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
 arch/x86/events/core.c      | 9 ++++-----
 kernel/events/ring_buffer.c | 5 +++--
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index d096b04bf80e..d9310e9363f1 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -129,13 +129,12 @@ u64 x86_perf_event_update(struct perf_event *event)
 	 * exchange a new raw count - then add that new-prev delta
 	 * count to the generic event atomically:
 	 */
-again:
 	prev_raw_count = local64_read(&hwc->prev_count);
-	rdpmcl(hwc->event_base_rdpmc, new_raw_count);
 
-	if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
-					new_raw_count) != prev_raw_count)
-		goto again;
+	do {
+		rdpmcl(hwc->event_base_rdpmc, new_raw_count);
+	} while (!local64_try_cmpxchg(&hwc->prev_count, &prev_raw_count,
+				      new_raw_count));
 
 	/*
 	 * Now we have the new raw value and have updated the prev
diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 273a0fe7910a..111ab85ee97d 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -191,9 +191,10 @@ __perf_output_begin(struct perf_output_handle *handle,
 
 	perf_output_get_handle(handle);
 
+	offset = local_read(&rb->head);
 	do {
 		tail = READ_ONCE(rb->user_page->data_tail);
-		offset = head = local_read(&rb->head);
+		head = offset;
 		if (!rb->overwrite) {
 			if (unlikely(!ring_buffer_has_space(head, tail,
 							    perf_data_size(rb),
@@ -217,7 +218,7 @@ __perf_output_begin(struct perf_output_handle *handle,
 			head += size;
 		else
 			head -= size;
-	} while (local_cmpxchg(&rb->head, offset, head) != offset);
+	} while (!local_try_cmpxchg(&rb->head, &offset, head));
 
 	if (backward) {
 		offset = head;
-- 
2.39.2


  parent reply	other threads:[~2023-04-05 14:17 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-05 14:17 [PATCH v2 0/5] locking: Introduce local{,64}_try_cmpxchg Uros Bizjak
2023-04-05 14:17 ` Uros Bizjak
2023-04-05 14:17 ` Uros Bizjak
2023-04-05 14:17 ` [PATCH v2 1/5] locking/atomic: Add generic try_cmpxchg{,64}_local support Uros Bizjak
2023-04-05 14:17   ` Uros Bizjak
2023-04-11 11:10   ` Mark Rutland
2023-04-11 11:10     ` Mark Rutland
2023-04-13 11:38   ` [tip: locking/core] " tip-bot2 for Uros Bizjak
2023-04-29  7:03   ` [tip: locking/core] locking/atomic: Add generic try_cmpxchg{,64}_local() support tip-bot2 for Uros Bizjak
2023-04-29  7:18   ` tip-bot2 for Uros Bizjak
2023-04-05 14:17 ` [PATCH v2 2/5] locking/generic: Wire up local{,64}_try_cmpxchg Uros Bizjak
2023-04-11 11:13   ` Mark Rutland
2023-04-11 11:13     ` Mark Rutland
2023-04-13 11:38   ` [tip: locking/core] " tip-bot2 for Uros Bizjak
2023-04-29  7:03   ` [tip: locking/core] locking/generic: Wire up local{,64}_try_cmpxchg() tip-bot2 for Uros Bizjak
2023-04-29  7:18   ` tip-bot2 for Uros Bizjak
2023-04-05 14:17 ` [PATCH v2 3/5] locking/arch: Wire up local_try_cmpxchg Uros Bizjak
2023-04-05 14:17   ` Uros Bizjak
2023-04-12 11:32   ` Peter Zijlstra
2023-04-12 11:32     ` Peter Zijlstra
2023-04-12 13:37     ` Uros Bizjak
2023-04-12 13:37       ` Uros Bizjak
2023-04-12 13:37       ` Uros Bizjak
2023-04-12 13:40       ` Peter Zijlstra
2023-04-12 13:40         ` Peter Zijlstra
2023-04-12 13:40         ` Peter Zijlstra
2023-04-13 11:38   ` [tip: locking/core] " tip-bot2 for Uros Bizjak
2023-04-29  7:03   ` [tip: locking/core] locking/arch: Wire up local_try_cmpxchg() tip-bot2 for Uros Bizjak
2023-04-29  7:18   ` tip-bot2 for Uros Bizjak
2023-05-17  7:41   ` [PATCH v2 3/5] locking/arch: Wire up local_try_cmpxchg Charlemagne Lasse
2023-05-17  7:41     ` Charlemagne Lasse
2023-05-17  7:41     ` Charlemagne Lasse
2023-04-05 14:17 ` [PATCH v2 4/5] locking/x86: Define arch_try_cmpxchg_local Uros Bizjak
2023-04-05 14:17   ` Uros Bizjak
2023-04-13 11:38   ` [tip: locking/core] " tip-bot2 for Uros Bizjak
2023-04-29  7:03   ` [tip: locking/core] locking/x86: Define arch_try_cmpxchg_local() tip-bot2 for Uros Bizjak
2023-04-29  7:18   ` tip-bot2 for Uros Bizjak
2023-04-05 14:17 ` Uros Bizjak [this message]
2023-04-05 16:37 ` [PATCH v2 0/5] locking: Introduce local{,64}_try_cmpxchg Dave Hansen
2023-04-05 16:37   ` Dave Hansen
2023-04-05 16:37   ` Dave Hansen
2023-04-05 18:53   ` Uros Bizjak
2023-04-05 18:53     ` Uros Bizjak
2023-04-05 18:53     ` Uros Bizjak
2023-04-06  8:25   ` David Laight
2023-04-06  8:25     ` David Laight
2023-04-06  8:25     ` David Laight
2023-04-06  8:38     ` Uros Bizjak
2023-04-06  8:38       ` Uros Bizjak
2023-04-06  8:38       ` Uros Bizjak
2023-04-06  9:01       ` David Laight
2023-04-06  9:01         ` David Laight
2023-04-06  9:01         ` David Laight
2023-04-11 11:35   ` Mark Rutland
2023-04-11 11:35     ` Mark Rutland
2023-04-11 11:35     ` Mark Rutland
2023-04-11 13:43     ` Dave Hansen
2023-04-11 13:43       ` Dave Hansen
2023-04-11 13:43       ` Dave Hansen
2023-04-11 21:34       ` David Laight
2023-04-11 21:34         ` David Laight
2023-04-11 21:34         ` David Laight

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=20230405141710.3551-6-ubizjak@gmail.com \
    --to=ubizjak@gmail.com \
    --cc=linux-alpha@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=loongarch@lists.linux.dev \
    --cc=x86@kernel.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 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.