2023-08-07 16:30:03

by Uros Bizjak

[permalink] [raw]
Subject: [PATCH 1/2] perf/x86/rapl: Stop doing cpu_relax in the cmpxchg loop

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 <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc. "H. Peter Anvin" <[email protected]>
Signed-off-by: Uros Bizjak <[email protected]>
---
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



Subject: [tip: perf/core] perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop in rapl_event_update()

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 <[email protected]>
AuthorDate: Mon, 07 Aug 2023 16:51:14 +02:00
Committer: Ingo Molnar <[email protected]>
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 <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Linus Torvalds <[email protected]>
Link: https://lore.kernel.org/r/[email protected]

Cc. "H. Peter Anvin" <[email protected]>
---
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

Subject: [tip: perf/core] perf/x86/rapl: Stop doing cpu_relax() in the local64_cmpxchg() loop in rapl_event_update()

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 <[email protected]>
AuthorDate: Mon, 07 Aug 2023 16:51:14 +02:00
Committer: Ingo Molnar <[email protected]>
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 <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
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