From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754156AbdH2OJf (ORCPT ); Tue, 29 Aug 2017 10:09:35 -0400 Received: from mga03.intel.com ([134.134.136.65]:38616 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752410AbdH2OJe (ORCPT ); Tue, 29 Aug 2017 10:09:34 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,445,1498546800"; d="scan'208";a="895179525" From: Alexander Shishkin To: Peter Zijlstra Cc: Ingo Molnar , linux-kernel@vger.kernel.org Subject: Re: [PATCH] perf: Explain perf_sched_mutex In-Reply-To: <20170829140103.6563-1-alexander.shishkin@linux.intel.com> References: <20170829140103.6563-1-alexander.shishkin@linux.intel.com> User-Agent: Notmuch/0.23.7 (http://notmuchmail.org) Emacs/25.1.1 (x86_64-pc-linux-gnu) Date: Tue, 29 Aug 2017 17:04:22 +0300 Message-ID: <87h8wqxyft.fsf@ashishki-desk.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Alexander Shishkin writes: > 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 > > Signed-off-by: Alexander Shishkin > --- > kernel/events/core.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/kernel/events/core.c b/kernel/events/core.c > index efe09b8c38..2c8719b635 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -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; > > -- > 2.14.1