* [PATCH 1/2] perf/x86/rapl: Stop doing cpu_relax in the cmpxchg loop
@ 2023-08-07 14:51 Uros Bizjak
2023-08-07 14:51 ` [PATCH 2/2] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update Uros Bizjak
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Uros Bizjak @ 2023-08-07 14:51 UTC (permalink / raw)
To: x86, linux-perf-users, linux-kernel
Cc: Uros Bizjak, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Ian Rogers, Adrian Hunter,
Thomas Gleixner, Borislav Petkov, Dave Hansen
According to the commit f5fe24ef17b5 ("lockref: stop doing cpu_relax
in the cmpxchg loop"):
"On the x86-64 architecture even a failing cmpxchg grants exclusive
access to the cacheline, making it preferable to retry the failed op
immediately instead of stalling with the pause instruction."
Based on the above observation, remove cpu_relax from the
cmpxchg loop of rapl_event_update.
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc. "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
arch/x86/events/rapl.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index 52e6e7ed4f78..e8e26733e17b 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -184,10 +184,8 @@ static u64 rapl_event_update(struct perf_event *event)
rdmsrl(event->hw.event_base, new_raw_count);
if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
- new_raw_count) != prev_raw_count) {
- cpu_relax();
+ new_raw_count) != prev_raw_count)
goto again;
- }
/*
* Now we have the new raw value and have updated the prev
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH 2/2] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update
2023-08-07 14:51 [PATCH 1/2] perf/x86/rapl: Stop doing cpu_relax in the cmpxchg loop Uros Bizjak
@ 2023-08-07 14:51 ` Uros Bizjak
2023-10-03 7:45 ` [tip: perf/core] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update() tip-bot2 for Uros Bizjak
2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
2023-10-03 7:45 ` [tip: perf/core] perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop " tip-bot2 for Uros Bizjak
2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
2 siblings, 2 replies; 6+ messages in thread
From: Uros Bizjak @ 2023-08-07 14:51 UTC (permalink / raw)
To: x86, linux-perf-users, linux-kernel
Cc: Uros Bizjak, Peter Zijlstra, Ingo Molnar,
Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
Jiri Olsa, Namhyung Kim, Ian Rogers, Adrian Hunter,
Thomas Gleixner, Borislav Petkov, Dave Hansen
Use local64_try_cmpxchg instead of local64_cmpxchg (*ptr, old, new) == old.
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: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc. "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
arch/x86/events/rapl.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index e8e26733e17b..7c2376dae79d 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -179,13 +179,11 @@ static u64 rapl_event_update(struct perf_event *event)
s64 delta, sdelta;
int shift = RAPL_CNTR_WIDTH;
-again:
prev_raw_count = local64_read(&hwc->prev_count);
- rdmsrl(event->hw.event_base, new_raw_count);
-
- if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
- new_raw_count) != prev_raw_count)
- goto again;
+ do {
+ rdmsrl(event->hw.event_base, 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
--
2.41.0
^ permalink raw reply related [flat|nested] 6+ messages in thread* [tip: perf/core] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update()
2023-08-07 14:51 ` [PATCH 2/2] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update Uros Bizjak
@ 2023-10-03 7:45 ` tip-bot2 for Uros Bizjak
2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
1 sibling, 0 replies; 6+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-10-03 7:45 UTC (permalink / raw)
To: linux-tip-commits; +Cc: Uros Bizjak, Ingo Molnar, x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: df60e18058bb6792c85e4ede43876c1df44f5b9a
Gitweb: https://git.kernel.org/tip/df60e18058bb6792c85e4ede43876c1df44f5b9a
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 07 Aug 2023 16:51:15 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 03 Oct 2023 09:36:18 +02:00
perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update()
Use local64_try_cmpxchg() instead of local64_cmpxchg(*ptr, old, new) == old.
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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230807145134.3176-2-ubizjak@gmail.com
Cc. "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/events/rapl.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index e8f53b2..6d3e738 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -179,13 +179,11 @@ static u64 rapl_event_update(struct perf_event *event)
s64 delta, sdelta;
int shift = RAPL_CNTR_WIDTH;
-again:
prev_raw_count = local64_read(&hwc->prev_count);
- rdmsrl(event->hw.event_base, new_raw_count);
-
- if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
- new_raw_count) != prev_raw_count)
- goto again;
+ do {
+ rdmsrl(event->hw.event_base, 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
^ permalink raw reply related [flat|nested] 6+ messages in thread* [tip: perf/core] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update()
2023-08-07 14:51 ` [PATCH 2/2] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update Uros Bizjak
2023-10-03 7:45 ` [tip: perf/core] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update() tip-bot2 for Uros Bizjak
@ 2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
1 sibling, 0 replies; 6+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-10-03 19:19 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Peter Zijlstra, Linus Torvalds,
H. Peter Anvin, x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: bcc6ec3d954bbcc8bec34a21c05ea536a2e96d6f
Gitweb: https://git.kernel.org/tip/bcc6ec3d954bbcc8bec34a21c05ea536a2e96d6f
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 07 Aug 2023 16:51:15 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 03 Oct 2023 21:13:45 +02:00
perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update()
Use local64_try_cmpxchg() instead of local64_cmpxchg(*ptr, old, new) == old.
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.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/r/20230807145134.3176-2-ubizjak@gmail.com
---
arch/x86/events/rapl.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index e8f53b2..6d3e738 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -179,13 +179,11 @@ static u64 rapl_event_update(struct perf_event *event)
s64 delta, sdelta;
int shift = RAPL_CNTR_WIDTH;
-again:
prev_raw_count = local64_read(&hwc->prev_count);
- rdmsrl(event->hw.event_base, new_raw_count);
-
- if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
- new_raw_count) != prev_raw_count)
- goto again;
+ do {
+ rdmsrl(event->hw.event_base, 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
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [tip: perf/core] perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop in rapl_event_update()
2023-08-07 14:51 [PATCH 1/2] perf/x86/rapl: Stop doing cpu_relax in the cmpxchg loop Uros Bizjak
2023-08-07 14:51 ` [PATCH 2/2] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update Uros Bizjak
@ 2023-10-03 7:45 ` tip-bot2 for Uros Bizjak
2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
2 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-10-03 7:45 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Peter Zijlstra, Linus Torvalds, x86,
linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: df22fb4bcdd6f67c4f568e6321c9b0050819d213
Gitweb: https://git.kernel.org/tip/df22fb4bcdd6f67c4f568e6321c9b0050819d213
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 07 Aug 2023 16:51:14 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 03 Oct 2023 09:36:17 +02:00
perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop in rapl_event_update()
According to the following commit:
f5fe24ef17b5 ("lockref: stop doing cpu_relax in the cmpxchg loop")
"On the x86-64 architecture even a failing cmpxchg grants exclusive
access to the cacheline, making it preferable to retry the failed op
immediately instead of stalling with the pause instruction."
Based on the above observation, remove cpu_relax() from the
local64_cmpxchg() loop of rapl_event_update().
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20230807145134.3176-1-ubizjak@gmail.com
Cc. "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/events/rapl.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index 1579429..e8f53b2 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -184,10 +184,8 @@ again:
rdmsrl(event->hw.event_base, new_raw_count);
if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
- new_raw_count) != prev_raw_count) {
- cpu_relax();
+ new_raw_count) != prev_raw_count)
goto again;
- }
/*
* Now we have the new raw value and have updated the prev
^ permalink raw reply related [flat|nested] 6+ messages in thread* [tip: perf/core] perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop in rapl_event_update()
2023-08-07 14:51 [PATCH 1/2] perf/x86/rapl: Stop doing cpu_relax in the cmpxchg loop Uros Bizjak
2023-08-07 14:51 ` [PATCH 2/2] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update Uros Bizjak
2023-10-03 7:45 ` [tip: perf/core] perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop " tip-bot2 for Uros Bizjak
@ 2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
2 siblings, 0 replies; 6+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2023-10-03 19:19 UTC (permalink / raw)
To: linux-tip-commits
Cc: Uros Bizjak, Ingo Molnar, Peter Zijlstra, Linus Torvalds,
H. Peter Anvin, x86, linux-kernel
The following commit has been merged into the perf/core branch of tip:
Commit-ID: 1ce19bf90bd55bf54f9ed75d594029db63d395b0
Gitweb: https://git.kernel.org/tip/1ce19bf90bd55bf54f9ed75d594029db63d395b0
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Mon, 07 Aug 2023 16:51:14 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 03 Oct 2023 21:13:23 +02:00
perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop in rapl_event_update()
According to the following commit:
f5fe24ef17b5 ("lockref: stop doing cpu_relax in the cmpxchg loop")
"On the x86-64 architecture even a failing cmpxchg grants exclusive
access to the cacheline, making it preferable to retry the failed op
immediately instead of stalling with the pause instruction."
Based on the above observation, remove cpu_relax() from the
local64_cmpxchg() loop of rapl_event_update().
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Link: https://lore.kernel.org/r/20230807145134.3176-1-ubizjak@gmail.com
---
arch/x86/events/rapl.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/arch/x86/events/rapl.c b/arch/x86/events/rapl.c
index 1579429..e8f53b2 100644
--- a/arch/x86/events/rapl.c
+++ b/arch/x86/events/rapl.c
@@ -184,10 +184,8 @@ again:
rdmsrl(event->hw.event_base, new_raw_count);
if (local64_cmpxchg(&hwc->prev_count, prev_raw_count,
- new_raw_count) != prev_raw_count) {
- cpu_relax();
+ new_raw_count) != prev_raw_count)
goto again;
- }
/*
* Now we have the new raw value and have updated the prev
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-10-03 19:19 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-07 14:51 [PATCH 1/2] perf/x86/rapl: Stop doing cpu_relax in the cmpxchg loop Uros Bizjak
2023-08-07 14:51 ` [PATCH 2/2] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update Uros Bizjak
2023-10-03 7:45 ` [tip: perf/core] perf/x86/rapl: Use local64_try_cmpxchg in rapl_event_update() tip-bot2 for Uros Bizjak
2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
2023-10-03 7:45 ` [tip: perf/core] perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop " tip-bot2 for Uros Bizjak
2023-10-03 19:19 ` tip-bot2 for Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox