From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760561AbcCEIOp (ORCPT ); Sat, 5 Mar 2016 03:14:45 -0500 Received: from torg.zytor.com ([198.137.202.12]:58552 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754415AbcCEIOf (ORCPT ); Sat, 5 Mar 2016 03:14:35 -0500 Date: Sat, 5 Mar 2016 00:14:17 -0800 From: tip-bot for Jiri Olsa Message-ID: Cc: acme@redhat.com, hpa@zytor.com, jolsa@kernel.org, a.p.zijlstra@chello.nl, tglx@linutronix.de, dsahern@gmail.com, namhyung@kernel.org, jolsa@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org, mingo@redhat.com Reply-To: acme@redhat.com, hpa@zytor.com, jolsa@kernel.org, a.p.zijlstra@chello.nl, tglx@linutronix.de, dsahern@gmail.com, namhyung@kernel.org, jolsa@redhat.com, linux-kernel@vger.kernel.org, mingo@redhat.com, mingo@kernel.org In-Reply-To: <20160303095348.GA24511@krava.redhat.com> References: <20160303095348.GA24511@krava.redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf tools: Fix locale handling in pmu parsing Git-Commit-ID: f9a5978ac4ede901fa73d7c28ae1c5d89bc2a46a 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: f9a5978ac4ede901fa73d7c28ae1c5d89bc2a46a Gitweb: http://git.kernel.org/tip/f9a5978ac4ede901fa73d7c28ae1c5d89bc2a46a Author: Jiri Olsa AuthorDate: Thu, 3 Mar 2016 10:53:48 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 3 Mar 2016 11:04:54 -0300 perf tools: Fix locale handling in pmu parsing Ingo reported regression on display format of big numbers, which is missing separators (in default perf stat output). triton:~/tip> perf stat -a sleep 1 ... 127008602 cycles # 0.011 GHz 279538533 stalled-cycles-frontend # 220.09% frontend cycles idle 119213269 instructions # 0.94 insn per cycle This is caused by recent change: perf stat: Check existence of frontend/backed stalled cycles that added call to pmu_have_event, that subsequently calls perf_pmu__parse_scale, which has a bug in locale handling. The lc string returned from setlocale, that we use to store old locale value, may be allocated in static storage. Getting a dynamic copy to make it survive another setlocale call. $ perf stat ls ... 2,360,602 cycles # 3.080 GHz 2,703,090 instructions # 1.15 insn per cycle 546,031 branches # 712.511 M/sec Committer note: Since the patch introducing the regression didn't made to perf/core, move it to just before where the regression was introduced, so that we don't break bisection for this feature. Reported-by: Ingo Molnar Signed-off-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/20160303095348.GA24511@krava.redhat.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/pmu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ce61f79..d8cd038 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -124,6 +124,17 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char * lc = setlocale(LC_NUMERIC, NULL); /* + * The lc string may be allocated in static storage, + * so get a dynamic copy to make it survive setlocale + * call below. + */ + lc = strdup(lc); + if (!lc) { + ret = -ENOMEM; + goto error; + } + + /* * force to C locale to ensure kernel * scale string is converted correctly. * kernel uses default C locale. @@ -135,6 +146,8 @@ static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char * /* restore locale */ setlocale(LC_NUMERIC, lc); + free((char *) lc); + ret = 0; error: close(fd);