From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751532AbdJEJv5 (ORCPT ); Thu, 5 Oct 2017 05:51:57 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36656 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751298AbdJEJvz (ORCPT ); Thu, 5 Oct 2017 05:51:55 -0400 Subject: Re: [PATCH] powerpc/perf: Fix for core/nest imc call trace on cpuhotplug To: Santosh Sivaraj Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, maddy@linux.vnet.ibm.com, hemant@linux.vnet.ibm.com References: <1507099852-28004-1-git-send-email-anju@linux.vnet.ibm.com> <20171005095015.wr6spduebk4zqktk@santosiv.in.ibm.com> From: Anju T Sudhakar Date: Thu, 5 Oct 2017 15:21:47 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20171005095015.wr6spduebk4zqktk@santosiv.in.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-TM-AS-GCONF: 00 x-cbid: 17100509-0004-0000-0000-00001304BB95 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007847; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000234; SDB=6.00926778; UDB=6.00466249; IPR=6.00706989; BA=6.00005621; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017405; XFM=3.00000015; UTC=2017-10-05 09:51:52 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17100509-0005-0000-0000-0000845AC46C Message-Id: X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-10-05_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710050140 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Santosh, On Thursday 05 October 2017 03:20 PM, Santosh Sivaraj wrote: > * Anju T Sudhakar wrote (on 2017-10-04 06:50:52 +0000): > >> Nest/core pmu units are enabled only when it is used. A reference count is >> maintained for the events which uses the nest/core pmu units. Currently in >> *_imc_counters_release function a WARN() is used for notification of any >> underflow of ref count. >> >> The case where event ref count hit a negative value is, when perf session is >> started, followed by offlining of all cpus in a given core. >> i.e. in cpuhotplug offline path ppc_core_imc_cpu_offline() function set the >> ref->count to zero, if the current cpu which is about to offline is the last >> cpu in a given core and make an OPAL call to disable the engine in that core. >> And on perf session termination, perf->destroy (core_imc_counters_release) will >> first decrement the ref->count for this core and based on the ref->count value >> an opal call is made to disable the core-imc engine. >> Now, since cpuhotplug path already clears the ref->count for core and disabled >> the engine, perf->destroy() decrementing again at event termination make it >> negative which in turn fires the WARN_ON. The same happens for nest units. >> >> Add a check to see if the reference count is alreday zero, before decrementing >> the count, so that the ref count will not hit a negative value. >> >> Signed-off-by: Anju T Sudhakar > Reviewed-by: Santosh Sivaraj Thanks for reviewing. -Anju >> --- >> arch/powerpc/perf/imc-pmu.c | 28 ++++++++++++++++++++++++++++ >> 1 file changed, 28 insertions(+) >> >> diff --git a/arch/powerpc/perf/imc-pmu.c b/arch/powerpc/perf/imc-pmu.c >> index 9ccac86f3463..e3a1f65933b5 100644 >> --- a/arch/powerpc/perf/imc-pmu.c >> +++ b/arch/powerpc/perf/imc-pmu.c >> @@ -399,6 +399,20 @@ static void nest_imc_counters_release(struct perf_event *event) >> >> /* Take the mutex lock for this node and then decrement the reference count */ >> mutex_lock(&ref->lock); >> + if (ref->refc == 0) { >> + /* >> + * The scenario where this is true is, when perf session is >> + * started, followed by offlining of all cpus in a given node. >> + * >> + * In the cpuhotplug offline path, ppc_nest_imc_cpu_offline() >> + * function set the ref->count to zero, if the cpu which is >> + * about to offline is the last cpu in a given node and make >> + * an OPAL call to disable the engine in that node. >> + * >> + */ >> + mutex_unlock(&ref->lock); >> + return; >> + } >> ref->refc--; >> if (ref->refc == 0) { >> rc = opal_imc_counters_stop(OPAL_IMC_COUNTERS_NEST, >> @@ -646,6 +660,20 @@ static void core_imc_counters_release(struct perf_event *event) >> return; >> >> mutex_lock(&ref->lock); >> + if (ref->refc == 0) { >> + /* >> + * The scenario where this is true is, when perf session is >> + * started, followed by offlining of all cpus in a given core. >> + * >> + * In the cpuhotplug offline path, ppc_core_imc_cpu_offline() >> + * function set the ref->count to zero, if the cpu which is >> + * about to offline is the last cpu in a given core and make >> + * an OPAL call to disable the engine in that core. >> + * >> + */ >> + mutex_unlock(&ref->lock); >> + return; >> + } >> ref->refc--; >> if (ref->refc == 0) { >> rc = opal_imc_counters_stop(OPAL_IMC_COUNTERS_CORE,