From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: Clark Williams <williams@redhat.com>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
Thomas Richter <tmricht@linux.ibm.com>,
Heiko Carstens <heiko.carstens@de.ibm.com>,
Kan Liang <kan.liang@linux.intel.com>,
Martin Schwidefsky <schwidefsky@de.ibm.com>,
stable@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 08/18] perf stat: Handle different PMU names with common prefix
Date: Tue, 6 Nov 2018 09:06:02 -0300 [thread overview]
Message-ID: <20181106120612.8262-9-acme@kernel.org> (raw)
In-Reply-To: <20181106120612.8262-1-acme@kernel.org>
From: Thomas Richter <tmricht@linux.ibm.com>
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
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'.
This is caused by the following call sequence:
pmu_lookup() scans and installs a PMU.
+--> pmu_aliases() parses all aliases in directory
.../<pmu-name>/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.
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;
}
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);
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.
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.
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
0.001815365 seconds time elapsed
0.000123000 seconds user
0.001756000 seconds sys
[root@s35lp76 perf]#
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
Reviewed-by: Hendrik Brueckner <brueckner@linux.ibm.com>
Reviewed-by: Sebastien Boisvert <sboisvert@gydle.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: stable@vger.kernel.org
Fixes: 292c34c10249 ("perf pmu: Fix core PMU alias list for X86 platform")
Link: http://lkml.kernel.org/r/20181023151616.78193-1-tmricht@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
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;
}
--
2.14.4
next prev parent reply other threads:[~2018-11-06 12:06 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 12:05 [GIT PULL 00/18] perf/urgent improvements and fixes Arnaldo Carvalho de Melo
2018-11-06 12:05 ` [PATCH 01/18] tools headers barrier: Fix arm64 tools build failure wrt smp_load_{acquire,release} Arnaldo Carvalho de Melo
2018-11-06 12:05 ` [PATCH 02/18] perf examples bpf: Start augmenting raw_syscalls:sys_{start,exit} Arnaldo Carvalho de Melo
2018-11-06 12:05 ` [PATCH 03/18] perf trace: When augmenting raw_syscalls plug raw_syscalls:sys_exit too Arnaldo Carvalho de Melo
2018-11-06 12:05 ` [PATCH 04/18] perf trace: Fix setting of augmented payload when using eBPF + raw_syscalls Arnaldo Carvalho de Melo
2018-11-06 12:05 ` [PATCH 05/18] perf augmented_syscalls: Start collecting pathnames in the BPF program Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 06/18] perf evlist: Move perf_evsel__reset_weak_group into evlist Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 07/18] perf record: Support weak groups Arnaldo Carvalho de Melo
2018-11-06 12:06 ` Arnaldo Carvalho de Melo [this message]
2018-11-06 12:06 ` [PATCH 09/18] perf top: Display the LBR stats in callchain entry Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 10/18] perf scripts python: exported-sql-viewer.py: Fall back to /usr/local/lib/libxed.so Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 11/18] perf scripts python: exported-sql-viewer.py: Add Selected branches report Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 12/18] perf scripts python: exported-sql-viewer.py: Add help window Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 13/18] perf scripts python: exported-sql-viewer.py: Fix table find when table re-ordered Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 14/18] perf intel-pt: Add more event information to debug log Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 15/18] perf intel-pt: Add MTC and CYC timestamps " Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 16/18] perf beauty: Use SRCARCH, ARCH=x86_64 must map to "x86" to find the headers Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 17/18] perf tools: Fix undefined symbol scnprintf in libperf-jvmti.so Arnaldo Carvalho de Melo
2018-11-06 12:06 ` [PATCH 18/18] perf tools: Do not zero sample_id_all for group members Arnaldo Carvalho de Melo
2018-11-06 19:06 ` [GIT PULL 00/18] perf/urgent improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181106120612.8262-9-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=heiko.carstens@de.ibm.com \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=schwidefsky@de.ibm.com \
--cc=stable@vger.kernel.org \
--cc=tmricht@linux.ibm.com \
--cc=williams@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).