Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7291702imu; Tue, 22 Jan 2019 03:40:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN51P2/Fi7twwkEPv5f5Nxx3bOvM/yFngxzW5/0DAw/KQ/bJ/B3Ktxy1qdgbnGOsdOwXdTns X-Received: by 2002:a62:33c1:: with SMTP id z184mr33027438pfz.104.1548157241016; Tue, 22 Jan 2019 03:40:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548157240; cv=none; d=google.com; s=arc-20160816; b=C6v5OoJ0nIjBs+S/s8+6oUayblFZmQh9cbaNVOh7GPdufCbzqXnWHKmZ1u377U8lz5 zI5Sk8vyMS837xxEYCiUey2xK8IIArlyqxBr/ZWybzgxCwUTo7txj6ssnRnVrLNZ7avp 57XNkzEYeEWarv2+tr/wBlVKbFkNlLjUc66C+7Uc6l/JtamvJdFWnC4F+jsrFIcq692U +ZKGJV3XgESgYubN+xzD5pOOXjh1KoYTsypcxuOaGVQRIr8yRzwiDzFFn9KTYXcROz8u 683UT0KzpvstzOXeUMPA4tJute+d7JUgVFQMscGU3utaH4Bv5oDfDkrtZtIEuYRMLAj0 //dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=etU+ilxL5DWaL/FVU1n3iPdDn9hbJxGzSZV/B5f+1H4=; b=k2kKZhTgSg633+uKK9+gYf4UQ53MrDLcDYc/13E5sEwF65Gx0xAoB/fM89FNatU6a9 jM8IHIjEw37Uc///cYpqaushnVg85xiX+WLL55cafejj8+mVtDCNWMzZ7ttP4ZTArWR/ wH5Lrl+IYkgWy+ilv/ovcjdLbsFmug4rwvxjlT767BJ69xlTSp7pqzJqhTCWtdOnc/oS PVf1P0E1iPAb0QFWS41IsJ/I6EiPC4dUmnb7X57B5ISLvBRpORftN0a9Cb0jrS80XMY3 R/x2Q0DthviVjwa33pJnvurrH5zjERv+KGmYJ5WooGV/nxJz+xNPjJ93V/M4SD2Z9i67 IOEg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a6si7301937pgc.137.2019.01.22.03.40.25; Tue, 22 Jan 2019 03:40:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728317AbfAVLh6 (ORCPT + 99 others); Tue, 22 Jan 2019 06:37:58 -0500 Received: from terminus.zytor.com ([198.137.202.136]:45881 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727777AbfAVLh6 (ORCPT ); Tue, 22 Jan 2019 06:37:58 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x0MBbkeO2929990 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 22 Jan 2019 03:37:47 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x0MBbkhQ2929984; Tue, 22 Jan 2019 03:37:46 -0800 Date: Tue, 22 Jan 2019 03:37:46 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Tony Jones Message-ID: Cc: jolsa@kernel.org, ak@linux.intel.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, ravi.bangoria@linux.ibm.com, hpa@zytor.com, yao.jin@linux.intel.com, tonyj@suse.de, acme@redhat.com, mingo@kernel.org Reply-To: ravi.bangoria@linux.ibm.com, hpa@zytor.com, yao.jin@linux.intel.com, jolsa@kernel.org, ak@linux.intel.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, tonyj@suse.de, acme@redhat.com In-Reply-To: <20190120191414.12925-1-tonyj@suse.de> References: <20190120191414.12925-1-tonyj@suse.de> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf script: Fix crash when processing recorded stat data Git-Commit-ID: 8bf8c6da53c2265aea365a1de6038f118f522113 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 X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, T_DATE_IN_FUTURE_96_Q autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 8bf8c6da53c2265aea365a1de6038f118f522113 Gitweb: https://git.kernel.org/tip/8bf8c6da53c2265aea365a1de6038f118f522113 Author: Tony Jones AuthorDate: Sun, 20 Jan 2019 11:14:14 -0800 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 21 Jan 2019 11:29:07 -0300 perf script: Fix crash when processing recorded stat data While updating perf to work with Python3 and Python2 I noticed that the stat-cpi script was dumping core. $ perf stat -e cycles,instructions record -o /tmp/perf.data /bin/false Performance counter stats for '/bin/false': 802,148 cycles 604,622 instructions 802,148 cycles 604,622 instructions 0.001445842 seconds time elapsed $ perf script -i /tmp/perf.data -s scripts/python/stat-cpi.py Segmentation fault (core dumped) ... ... rblist=rblist@entry=0xb2a200 , new_entry=new_entry@entry=0x7ffcb755c310) at util/rblist.c:33 ctx=, type=, create=, cpu=, evsel=) at util/stat-shadow.c:118 ctx=, type=, st=) at util/stat-shadow.c:196 count=count@entry=727442, cpu=cpu@entry=0, st=0xb2a200 ) at util/stat-shadow.c:239 config=config@entry=0xafeb40 , counter=counter@entry=0x133c6e0) at util/stat.c:372 ... ... The issue is that since 1fcd03946b52 perf_stat__update_shadow_stats now calls update_runtime_stat passing rt_stat rather than calling update_stats but perf_stat__init_shadow_stats has never been called to initialize rt_stat in the script path processing recorded stat data. Since I can't see any reason why perf_stat__init_shadow_stats() is presently initialized like it is in builtin-script.c::perf_sample__fprint_metric() [4bd1bef8bba2f] I'm proposing it instead be initialized once in __cmd_script Committer testing: After applying the patch: # perf script -i /tmp/perf.data -s tools/perf/scripts/python/stat-cpi.py 0.001970: cpu -1, thread -1 -> cpi 1.709079 (1075684/629394) # No segfault. Signed-off-by: Tony Jones Reviewed-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Tested-by: Ravi Bangoria Cc: Andi Kleen Cc: Jin Yao Fixes: 1fcd03946b52 ("perf stat: Update per-thread shadow stats") Link: http://lkml.kernel.org/r/20190120191414.12925-1-tonyj@suse.de Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 357906ed1898..ac221f137ed2 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1681,13 +1681,8 @@ static void perf_sample__fprint_metric(struct perf_script *script, .force_header = false, }; struct perf_evsel *ev2; - static bool init; u64 val; - if (!init) { - perf_stat__init_shadow_stats(); - init = true; - } if (!evsel->stats) perf_evlist__alloc_stats(script->session->evlist, false); if (evsel_script(evsel->leader)->gnum++ == 0) @@ -2359,6 +2354,8 @@ static int __cmd_script(struct perf_script *script) signal(SIGINT, sig_handler); + perf_stat__init_shadow_stats(); + /* override event processing functions */ if (script->show_task_events) { script->tool.comm = process_comm_event;