From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752586AbdI2UKk (ORCPT ); Fri, 29 Sep 2017 16:10:40 -0400 Received: from terminus.zytor.com ([65.50.211.136]:35313 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752554AbdI2UKj (ORCPT ); Fri, 29 Sep 2017 16:10:39 -0400 Date: Fri, 29 Sep 2017 13:07:06 -0700 From: tip-bot for Alexander Shishkin Message-ID: Cc: hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de, peterz@infradead.org, alexander.shishkin@linux.intel.com, torvalds@linux-foundation.org, mingo@kernel.org Reply-To: alexander.shishkin@linux.intel.com, peterz@infradead.org, torvalds@linux-foundation.org, mingo@kernel.org, hpa@zytor.com, linux-kernel@vger.kernel.org, tglx@linutronix.de In-Reply-To: <20170829140103.6563-1-alexander.shishkin@linux.intel.com> References: <20170829140103.6563-1-alexander.shishkin@linux.intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf/core: Explain perf_sched_mutex Git-Commit-ID: 5bce9db1894c998c5b85a34036d679ea6517668f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 5bce9db1894c998c5b85a34036d679ea6517668f Gitweb: https://git.kernel.org/tip/5bce9db1894c998c5b85a34036d679ea6517668f Author: Alexander Shishkin AuthorDate: Tue, 29 Aug 2017 17:01:03 +0300 Committer: Ingo Molnar 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. Signed-off-by: Alexander Shishkin Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Link: http://lkml.kernel.org/r/20170829140103.6563-1-alexander.shishkin@linux.intel.com Signed-off-by: Ingo Molnar --- kernel/events/core.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 6bc21e2..5ee6271 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -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;