Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp254768imd; Fri, 26 Oct 2018 08:05:50 -0700 (PDT) X-Google-Smtp-Source: AJdET5cLY/eGcK3qI94CiDs7nkL2ifGYCdaSm9KIKrxvGc2EdIhc7uvo+wgiAvetm47rdIeJXCZz X-Received: by 2002:a63:5558:: with SMTP id f24-v6mr3899103pgm.37.1540566350212; Fri, 26 Oct 2018 08:05:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540566350; cv=none; d=google.com; s=arc-20160816; b=UIrESlM8LEv5jYBHFJXzdJ2Q4fSY+dKYg0SCQ7HbMLR9sixsireBX9f26O3hJQh2mX TMtqTHvDJRrNIQTgAtavNxGYnET4tu7k1tbUKJtZhA2n2Y2CT96eicWKBLXLwLeeXJlf AVraySg9Uqk55huWmjxfn3jnRh8Nm8/h4J8NcpVqw+LoffoCO8SqAseOsq2KTu23BxuW ZF6ObM1NdAtaMObRqtiS5lLuTjtlS1prf2IL9CaJhib1AH7AJitOLM3SUYY/WwHDI/bc wJoex4iwDPo4cjBIdf83DJxfks64ComO5vlqotB+AQ6BKe2EtoIGuQmaptcnGm6q/jeH 0QSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject; bh=S8EFlvGQl+Y+793Sk3YGdyM22SRx1yyY+GHsAoe3cYo=; b=c4R2feRR8lTV7RezBFnwk/ddAxyeWT6cIq6nfWL8w5krkKh9kzGmfBU1XWoDpUX3qw CxcwIpO3kHhaaG7ffJNJU3T3eoiplaGpdVF9ieWtIiVejtKnzT5O5gbP8CTe8Lw9m1Xt x6dixhDsMsGM9CqwDlb1Fdrc+jpQT03OyFNrJnvDtAgjP7TEHm2XkGpDyqrdvaE5rN+Y SJtkLaVs1UsnLGYb+jG0k2eVYfqj2xrEA60+VOKyzSvn4sqOyKvy+rifptPBPpn0o1cv FBNLVRL1XlGCxgYtWXdzVfqH04Ecrc6DMkDeuknDAgRho2wwevojCC1kbMlN7b1ws3V8 argw== 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 q2-v6si8788042pgd.217.2018.10.26.08.05.32; Fri, 26 Oct 2018 08:05:50 -0700 (PDT) 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 S1727020AbeJZXmM (ORCPT + 99 others); Fri, 26 Oct 2018 19:42:12 -0400 Received: from mail.gydle.com ([64.18.173.180]:57776 "EHLO mail.gydle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbeJZXmL (ORCPT ); Fri, 26 Oct 2018 19:42:11 -0400 X-Received: from [192.168.1.136] (unknown [69.70.179.254]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: sboisvert@gydle.com) by mail.gydle.com (Postfix) with ESMTPSA id CA56841ACA; Fri, 26 Oct 2018 11:04:45 -0400 (EDT) Subject: Re: [PATCH] perf/stat: Handle different PMU names with common prefix To: Thomas Richter , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, acme@kernel.org Cc: brueckner@linux.vnet.ibm.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, kan.liang@linux.intel.com, stable@vger.kernel.org References: <20181023151616.78193-1-tmricht@linux.ibm.com> From: =?UTF-8?Q?S=c3=a9bastien_Boisvert?= Openpgp: preference=signencrypt Autocrypt: addr=sboisvert@gydle.com; keydata= xsFNBFi0QgMBEADLVQ63iQaeZj99I4+5AZe9ilJQ/fE7J49iS+NV3ChKgTfxMlxhagmq4a8E czme5AGkYeb9JAufWzcaGe4DGHJ0l26QdU/YQcpxGVGTobql+LUQ4VgEe9MxB6sMuO7QV5fZ aO27nCqk488ZS7e5g7Y10lMrY+4ZqzjOBIWVOXPpsDrqFY4zKuryLMtRDdINDCl+uahpIi4F P/c00/uGR04s+UmdZRgB1RroyZJjeSHgyR90THl8sDssR8zddaDEae2aO1/1dMI9KGamStYe 5wo9zS4ewPAgfNxRdhsdBvCNIrU2qnKFIE9Juc59NjGPmeRUjB/iHHS6zY4BSNruWrUG5KHs ykHpZhP/Gg5y2RL3Pmu9vIBo5C8sUb2/sRNeWXSD7Rh/0zHtYu5T3cx3/gz71WNRhiOncZuY pgZltzFRxCYc9kDuthITXbI8GoR3XGq8uo2hTDBW8b+VYqLZ7n4fggkvo8f1bgt0ACVKR0nq JViiVO9mYDr7UUWUfS8CABAJCjsbqjxRHMEDw+UNbCS54KJ5vxxkt4LNd0nkwaVwMfrOF3mA foEjSmeM2NLx5SOJuMPOSRyOKjfsOgYEbFsA9hZJ34r/zAPEIdwHf57dY+nSiV/avcE6WN5P ks0CfGMOTBNsxyqYXPov7kkwvCb09KYU9/J6F1nM9Wm83knzewARAQABzShTZWJhc3RpZW4g Qm9pc3ZlcnQgPHNib2lzdmVydEBneWRsZS5jb20+wsF9BBMBCAAnBQJYtEIDAhsjBQkJZgGA BQsJCAcCBhUICQoLAgQWAgMBAh4BAheAAAoJEGsrrSebZ4/xsY4QAJHIgXH9+KBNt0rgccCt DN4ueDoRIEmYS7NK/gUKQ8yHUreRHNpJqRSxNKzUPmvVAnnLdaopf/abhS+Ado5QGAZhiNzp +szWcwT4Za8P1mat+/HJznz06TwgiBJNSuMwItZmlgkBpgt2GVtmTP8LOJ1LVSD0615FO84m xUWqNfKijf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gbcdU+OYVjHqVWvI ae7HXSITVgByZAK6Di7/byqqjl1hwkiZeIcajZqK8hws6h6bLLZBn7EcZAEj8VLSdfUjJqCt VOZyQGdo8sNYjJPeV69vNbBUbX7BcxhxRZEYXw1rCz/xaCbNyRqRsxT03haPLg+WVQARAQAB wsFlBBgBCAAPBQJYtEIDAhsMBQkJZgGAAAoJEGsrrSebZ4/x13oP/2gWO3D6zo2Ok13khz4u +blJz8rzV1PQ5TVJmrsU05pVDlKgoZdtfEUtHlfAkzvNUpoKhNRWVN5/3QLwF4z0jfXyFYuS 8CVMRA75h59jSABdCWvZrQLHKJV03t++IFBi3y2DUilHXrCHUxg0iJeUhbMorgxc43d6DJw2 o53r+hBTfexVvcCodOREHR253eaw55lnL1J4sn0KVfprd0tLUTtR6QtF6oMXTcRedrE5bbQB oH/mmorTeQcEO6uDqc9SgqzEaLpNUxsXOBEMp0HYsQBoTdGzsh6aZGrVHX47A3ZLFv9WbRB+ iluFb5KY2n673MOZgSuCFurTuNm+Ik4qfHz3KCVkEghN/swYZW/ONxqZC+2kIPO30WJOnvSL OptwSrxigmRMwJMCYI59NwaF9lyk/F8iL798mNXuhb9mWoiw2Qfjm5xAI+8u3ECDlF6RImKJ QW26frU/JgIUOPrTP+XkxBzCK+vKVekqjhASMH0vLMUBjY02EvqjYfR1egevXc63hMJDR513 uqyECDvmUMJulfMUR2BeaX/+6/alsvQLlvDF8sZ1wrP4PFdqTELwMPHvKsZgX4KhMnNUhPSD XxdTif6ZoOAt/ZdtmdSV6InuwAz/1C9VnBRGP459T4N2OYSql4P4rcGBokrQCFC4kP/ZdqDf vnOzfc5OOiR/D+lE Message-ID: <7b3b23b7-1c73-66bf-611b-8dd9fb274694@gydle.com> Date: Fri, 26 Oct 2018 11:04:45 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181023151616.78193-1-tmricht@linux.ibm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-10-23 11:16 a.m., Thomas Richter wrote: > On s390 the CPU Measurement Facility for counters now supports > 2 PMUs named cpum_cf (CPU Measurement Facility for counters) and > cpum_cf_diag (CPU Measurement Facility for diagnostic counters) > for one and the same CPU. > > Running command > > [root@s35lp76 perf]# ./perf stat -e tx_c_tend \ > -- ~/mytests/cf-tx-events 1 > Is tx_c_tend related to these ? tx-abort OR cpu/tx-abort/ [Kernel PMU event] tx-capacity OR cpu/tx-capacity/ [Kernel PMU event] tx-commit OR cpu/tx-commit/ [Kernel PMU event] tx-conflict OR cpu/tx-conflict/ [Kernel PMU event] tx-start OR cpu/tx-start/ [Kernel PMU event] > Measuring transactions > TX_C_TABORT_NO_SPECIAL: 0 expected:0 > TX_C_TABORT_SPECIAL: 0 expected:0 > TX_C_TEND: 1 expected:1 > TX_NC_TABORT: 11 expected:11 > TX_NC_TEND: 1 expected:1 > > Performance counter stats for '/root/mytests/cf-tx-events 1': > > 2 tx_c_tend > > 0.002120091 seconds time elapsed > > 0.000121000 seconds user > 0.002127000 seconds sys > > [root@s35lp76 perf]# > > displays output which is unexpected (and wrong): > > 2 tx_c_tend > > The test program definitely triggers only one transaction, as shown > in line 'TX_C_TEND: 1 expected:1'. OK, something is done twice in perf stat, but should be done once. > > This is caused by the following call sequence: > > pmu_lookup() scans and installs a PMU. > +--> pmu_aliases() parses all aliases in directory > ...//events/* which are file names. > +--> pmu_aliases_parse() Read each file in directory and create > an new alias entry. This is done with > +--> perf_pmu__new_alias() and > +--> __perf_pmu__new_alias() which also check for > identical alias names. > > After pmu_aliases() returns, a complete list of event names > for this pmu has been created. Now function > > pmu_add_cpu_aliases() is called to add the events listed in the json > | files to the alias list of the cpu. > +--> perf_pmu__find_map() Returns a pointer to the json events. > > Now function pmu_add_cpu_aliases() scans through all events listed > in the JSON files for this CPU. Are these JSON files temporary in nature ? > Each json event pmu name is compared with the current PMU being > built up and if they mismatch, the json event is added to the > current PMUs alias list. > To avoid duplicate entries the following comparison is done: > > if (!is_arm_pmu_core(name)) { > pname = pe->pmu ? pe->pmu : "cpu"; > if (strncmp(pname, name, strlen(pname))) > continue; > } Is this the test to know whether a PMU event must be added or not ? > > The culprit is the strncmp() function. > > Using current s390 PMU naming, the first PMU is 'cpum_cf' > and a long list of events is added, among them 'tx_c_tend' > > When the second PMU named 'cpum_cf_diag' is added, only one event > named 'CF_DIAG' is added by the pmu_aliases() function. > > Now function pmu_add_cpu_aliases() is invoked for PMU 'cpum_cf_diag'. > Since the CPUID string is the same for both PMUs, json file events > for PMU named 'cpum_cf' are added to the PMU 'cpm_cf_diag' > > This happens because the strncmp() actually compares: >> strncmp("cpum_cf", "cpum_cf_diag", 6); I fail to see how these argument values can be generated by this code: pname = pe->pmu ? pe->pmu : "cpu"; if (strncmp(pname, name, strlen(pname))) The 3rd argument is the length of the first argument, pname. With "cpum_cf", it should be 7, not 6. > > The first parameter is the pmu name taken from the event in > the json file. The second parameter is the pmu name of the PMU > currently being built. > They are different, but the length of the compare only tests the > common prefix and this returns 0(true) when it should return false. > The 6 comes from strlen(pname). In that case, it is neither the length of "cpum_cf" (7) or "cpum_cf_diag" (12). > Now all events for PMU cpum_cf are added to the alias list for pmu > cpum_cf_diag. > > Later on in function parse_events_add_pmu() the event 'tx_c_end' is > searched in all available PMUs and found twice, adding it two > times to the evsel_list global variable which is the root > of all events. This results in a counter value of 2 instead > of 1. The counter value of 2 is 1 + 1 since both PMU events 'tx_c_end' that were added got a +1. > > Output with this patch: > > [root@s35lp76 perf]# ./perf stat -e tx_c_tend \ > -- ~/mytests/cf-tx-events 1 > Measuring transactions > TX_C_TABORT_NO_SPECIAL: 0 expected:0 > TX_C_TABORT_SPECIAL: 0 expected:0 > TX_C_TEND: 1 expected:1 > TX_NC_TABORT: 11 expected:11 > TX_NC_TEND: 1 expected:1 > > Performance counter stats for '/root/mytests/cf-tx-events 1': > > 1 tx_c_tend > OK, now that's 1, like in your expected test value: TX_C_TEND: 1 expected:1 > 0.001815365 seconds time elapsed > > 0.000123000 seconds user > 0.001756000 seconds sys > > [root@s35lp76 perf]# > > Fixes: 292c34c10249 ("perf pmu: Fix core PMU alias list for X86 platform") > Signed-off-by: Thomas Richter > Reviewed-by: Hendrik Brueckner > Cc: Kan Liang > Cc: # 4.18+ > --- > tools/perf/util/pmu.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index 7799788f662f..7e49baad304d 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -773,7 +773,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) > > if (!is_arm_pmu_core(name)) { > pname = pe->pmu ? pe->pmu : "cpu"; > - if (strncmp(pname, name, strlen(pname))) > + if (strcmp(pname, name)) > continue; > } > >