Skip to contentSkip to conversation

perf: Explain perf_sched_mutex

PATCH In review Alexander Shishkin 2 participants 3 messages Aug 29, 2017 – Sep 29, 2017 perf events

lore
Share & tools
lore

Alexander Shishkin

author reviewer
#0 lore raw

PATCH 1/1 perf: Explain perf_sched_mutex

To clarify why atomic_inc_return(&perf_sched_events) is not sufficient and a mutex is needed to order static branch enabling vs the atomic counter increment, this adds a comment with an short explanation.

---
 kernel/events/core.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/events/core.c +5 -0
index efe09b8c38..2c8719b635 100644
@@ -9569,6 +9569,11 @@ static void account_event(struct perf_event *event)
 		inc = true;
 
 	if (inc) {
+		/*
+		 * We need the mutex here because static_branch_enable()
+		 * must complete *before* the perf_sched_count increment
+		 * becomes visible.
+		 */
 		if (atomic_inc_not_zero(&perf_sched_count))
 			goto enabled;
 
Signature · 1 line
2.14.1
author reviewer
#1 lore raw
Quoted 3 lines · Alexander Shishkin

To clarify why atomic_inc_return(&perf_sched_events) is not sufficient and a mutex is needed to order static branch enabling vs the atomic counter increment, this adds a comment with an short explanation.

"with a short explanation", sigh

Quoted 24 lines
---
 kernel/events/core.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/events/core.c +5 -0
index efe09b8c38..2c8719b635 100644
@@ -9569,6 +9569,11 @@ static void account_event(struct perf_event *event)
 		inc = true;
 
 	if (inc) {
+		/*
+		 * We need the mutex here because static_branch_enable()
+		 * must complete *before* the perf_sched_count increment
+		 * becomes visible.
+		 */
 		if (atomic_inc_not_zero(&perf_sched_count))
 			goto enabled;
 
Signature · 1 line
2.14.1
#2 lore raw

[tip:perf/core] perf/core: Explain perf_sched_mutex

In reply to Alexander Shishkin
perf/core: Explain perf_sched_mutex
Commit-ID:  5bce9db1894c998c5b85a34036d679ea6517668f
Gitweb:     https://git.kernel.org/tip/5bce9db1894c998c5b85a34036d679ea6517668f
Author:     Alexander Shishkin <[email protected]>
AuthorDate: Tue, 29 Aug 2017 17:01:03 +0300
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 29 Sep 2017 13:28:30 +0200

perf/core: Explain perf_sched_mutex

To clarify why atomic_inc_return(&perf_sched_events) is not sufficient and a mutex is needed to order static branch enabling vs the atomic counter increment, this adds a comment with a short explanation.

---
 kernel/events/core.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/events/core.c +5 -0
index 6bc21e2..5ee6271 100644
@@ -9394,6 +9394,11 @@ static void account_event(struct perf_event *event)
 		inc = true;
 
 	if (inc) {
+		/*
+		 * We need the mutex here because static_branch_enable()
+		 * must complete *before* the perf_sched_count increment
+		 * becomes visible.
+		 */
 		if (atomic_inc_not_zero(&perf_sched_count))
 			goto enabled;