Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp1285583pxb; Thu, 24 Mar 2022 16:54:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBl9o0XJvCPrVrhBr0BftDAXvDekmt2HmlmTtS1POXr8duFGrjshEu08XNt3u0JGZuS3KM X-Received: by 2002:a17:90a:a60c:b0:1bd:6058:1dd9 with SMTP id c12-20020a17090aa60c00b001bd60581dd9mr21234362pjq.118.1648166095986; Thu, 24 Mar 2022 16:54:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648166095; cv=none; d=google.com; s=arc-20160816; b=aG7VC1z+m0GnHIzywLlHbDogJA0SzgObYhpC5q7zUeGj5Rh+SYTD8fnjHf2YzQTrJ/ 0d/SupffIY114/dHeokrqKRteHzI/WJvbMo2RBEb5IXGEcCuOMsBri6pbcTYf4+Kyu7+ bom8I+SxuEl/eYO9MupoyOiX/5X6eaAIlBg89cVj+SEuguFnxIljxSEfuYB8gdRLIaug sPMCLpk6r4R3+uCpeAfkspFYBbsBNoyOhK0IQboiXfi12TxViXRb3YMn8CLNl9yG6ST/ cBlCY0PhoqfHQGJb6yT1llypjrPinx2W27gVb8nvquHK2A8GJ356jcKwtBQN7k4FmG30 ALDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=3FBLzTb1AXEqQjLzpkmohwquGAKq0Sq5NcSMQIp/CrM=; b=S98yDQi87vDTjgZAQ+SoaOjB8rQBwNxvZwTYg6LddDB3mwwr7BoFsrNwZ3ikTFkmzi +tbt1M2FXR+CuHQouGA42hLIjW3TlAFD0gazHBT4f2eIndC1maS4gGPjBBILvK0Yxvan jnOpNDSZEfmDjpsXIg+Ry7aLc8X3kbkSLyNqyjf0ikAW7i17r7/hxbtN/HkckxzVZbMW ZNuW39uvkT/QUhg6i83BjwiI/h03e/3BhPjQeweuxmpAmefMZSIubrX/APlKgrTnToaT VMM/UgWgSdpcLd2EjSee510n8KTDgB5O864Kj3P6U9AN5sEDgUkDDnANXmvaz5zlZ9UN NBZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SvPapQeG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o18-20020a056a0015d200b004fa7d7af61fsi1481242pfu.53.2022.03.24.16.54.42; Thu, 24 Mar 2022 16:54:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=SvPapQeG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353441AbiCXUi1 (ORCPT + 99 others); Thu, 24 Mar 2022 16:38:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346156AbiCXUiZ (ORCPT ); Thu, 24 Mar 2022 16:38:25 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49622B0D37; Thu, 24 Mar 2022 13:36:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D8DF760F88; Thu, 24 Mar 2022 20:36:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B981C340EC; Thu, 24 Mar 2022 20:36:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648154212; bh=Kx6tBROKdcOdeiKP7X4AbU2NzC0vd6LCDCQ6b1g3bQk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SvPapQeGsj/0s8K1VaONuL2jEDQcMsPYMoapQ4/y5R3vHXZqkq3cpWbj4lY2BaTX1 eEIjoAH7+ICIjcDFwNx1vpv/yu5O/ju51k7VNa1kZhw5C/TfvFGdox6eC3CtCD7zBV 1lP9nAQU4U6OjjmvQmZX0U5aNXQRsKRhKmUwgw3nLrn+jCpmy+BrcpgLgY6CSBXhud ViNkzdJsjcaEJJVcFVRxNlgVGTXlUAiEkw+PN4SQEJODMIFjHmyxUO3oiyIthH4VuV lTfI4FGlB438hp4zx33DAfcgOsKkIV74Z5TkulgmVtPP8b3DyuO4D08qCMnaN96j3y YchcITBpma4pQ== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 10E8C40407; Thu, 24 Mar 2022 17:36:50 -0300 (-03) Date: Thu, 24 Mar 2022 17:36:50 -0300 From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Jiri Olsa , Thomas Richter , linux-kernel , linux-perf-users , gor@linux.ibm.com, Arnaldo Carvalho de Melo , Sven Schnelle , sumanthk@linux.ibm.com, Heiko Carstens Subject: Re: [PATCH] perf/stat: Fix perf stat for forked applications Message-ID: References: <20220317155346.577384-1-tmricht@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Wed, Mar 23, 2022 at 01:54:23PM -0700, Namhyung Kim escreveu: > On Wed, Mar 23, 2022 at 4:07 AM Jiri Olsa wrote: > > > > On Thu, Mar 17, 2022 at 04:53:46PM +0100, Thomas Richter wrote: > > > I have run into the following issue: > > > > > > # perf stat -a -e new_pmu/INSTRUCTION_7/ -- mytest -c1 7 > > > > > > Performance counter stats for 'system wide': > > > > > > 0 new_pmu/INSTRUCTION_7/ > > > > > > 0.000366428 seconds time elapsed > > > # > > > > > > The new PMU for s390 counts the execution of certain CPU instructions. > > > The root cause is the extremely small run time of the > > > mytest program. It just executes some assembly instructions > > > and then exits. In above invocation the instruction is executed > > > exactly one time (-c1 option). The PMU is expected to report this one > > > time execution by a counter value of one, but fails to do so > > > in some cases, not all. > > > > > > Debugging reveals the invocation of the child process is done > > > *before* the counter events are installed and enabled. Tracing > > > reveals that sometimes the child process starts and exits before > > > the event is installed on all CPUs. The more CPUs the machine has, > > > the more often this miscount happens. > > > > > > Fix this by reversing the start of the work load after the events > > > have been installed on the specified CPUs. Now the comment also > > > matches the code. > > > > > > Output after: > > > # perf stat -a -e new_pmu/INSTRUCTION_7/ -- mytest -c1 7 > > > > > > Performance counter stats for 'system wide': > > > > > > 1 new_pmu/INSTRUCTION_7/ > > > > > > 0.000366428 seconds time elapsed > > > # > > > > > > Now the correct result is reported rock solid all the time regardless > > > how many CPUs are online. > > > > > > Fixes: acf2892270dc ("perf stat: Use perf_evlist__prepare/start_workload()) > > > > > > Signed-off-by: Thomas Richter > > > Acked-by: Sumanth Korikkar > > > Cc: Namhyung Kim > > > --- > > > tools/perf/builtin-stat.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c > > > index 3f98689dd687..60baa3dadc4b 100644 > > > --- a/tools/perf/builtin-stat.c > > > +++ b/tools/perf/builtin-stat.c > > > @@ -955,10 +955,10 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) > > > * Enable counters and exec the command: > > > */ > > > if (forks) { > > > - evlist__start_workload(evsel_list); > > > err = enable_counters(); > > > if (err) > > > return -1; > > > + evlist__start_workload(evsel_list); > > > > right, without -a the event has enable_on_exec so the race does not > > matter, but it's a problem for system wide with fork > > Agreed. Also we may move the enable_counters() and the > clock code out of the if block to be shared with the else block. > > Acked-by: Namhyung Kim Thanks, applied and added your comments as "Reviewer notes", and please consider using the Reviewed-by tag instead of the Acked-by ones. Thanks anyways, as always! - Arnaldo