Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2256247imu; Tue, 6 Nov 2018 11:29:17 -0800 (PST) X-Google-Smtp-Source: AJdET5dCzH16S+aQht56HgiB+TEDC9vdpdTk1nMYYV2PnjUenO0wZgpLlbZUQQ+hLvYZZ3NeLYRr X-Received: by 2002:a17:902:8d94:: with SMTP id v20-v6mr28032417plo.109.1541532557024; Tue, 06 Nov 2018 11:29:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541532556; cv=none; d=google.com; s=arc-20160816; b=KHp7qB4kx9mRb7Hl2V4pjgvMrDlZP5tBVdas4eceZZt9PvzHRUlb0zgkGWbos2Yqba ULpuk9RZL/41L7jo1EKF2+itd4/EP4GCavN1p0SWDUakVqhgRwbvBUKmrVpb1p3Y32Ai xWTzV96EbJNL7GSZ5NAvRkpSPCkR9t02AfAiWYlFY6VTHDXtNADqHcMMYs2PVgLxfrCT +iSz6Z1MiXh1Z7Nu50wXP/gVehFdXo9T2I8g5WsmyRR6DOXV8qO6EeDNNF1nreVFKoaE F7PQvd3fpsas+2PyDx+96OsJr/nuzEAnZ7Sc1RL42fZBIQzRl7bLt7S92o6/gR+914Lv uYjw== 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=uVeqPcbtoVjkYjIpjKVc/uxauCPQIHxwWIWvfXDihdQ=; b=MP+CRPdzupbaqZQdPjrQINkeh7aO5ROO2/+wBrriUMrDsrA8TB/qW1JN9+BDdFbJOg SGu4qhAheam1AHNUHjw7Nw0mWIkJq6VqQi+3LL1dXdY24ztWan4/0cNQ83otBLi78NZN ZBtNC51sDjVUP08LnWV5vgmsZdUa/eVk+mgK9YNNQAD2AA1iSUee3echnYarwoyAkGYT jL7pFaax6aLmbxbPgAMkJe+lfCxjQT8g25Qh6p456jeL3S+WPXhAIlJ6jJHdlSy/Yg8m fsqxinriL8FvFDcOjO23oXmF+VU2jY8uHsfJDobSZzJUGELFnhM459aTvL0iF5PvIqB9 tFug== 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 b7-v6si22546147pgm.540.2018.11.06.11.29.01; Tue, 06 Nov 2018 11:29:16 -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 S2388521AbeKGEk5 (ORCPT + 99 others); Tue, 6 Nov 2018 23:40:57 -0500 Received: from terminus.zytor.com ([198.137.202.136]:58939 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388107AbeKGEk4 (ORCPT ); Tue, 6 Nov 2018 23:40:56 -0500 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id wA6JE31T911051 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 6 Nov 2018 11:14:04 -0800 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id wA6JE3rl911048; Tue, 6 Nov 2018 11:14:03 -0800 Date: Tue, 6 Nov 2018 11:14:03 -0800 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Thomas Richter Message-ID: Cc: mingo@kernel.org, hpa@zytor.com, tmricht@linux.ibm.com, tglx@linutronix.de, heiko.carstens@de.ibm.com, sboisvert@gydle.com, schwidefsky@de.ibm.com, acme@redhat.com, kan.liang@linux.intel.com, linux-kernel@vger.kernel.org, brueckner@linux.ibm.com Reply-To: tmricht@linux.ibm.com, tglx@linutronix.de, mingo@kernel.org, hpa@zytor.com, sboisvert@gydle.com, heiko.carstens@de.ibm.com, schwidefsky@de.ibm.com, linux-kernel@vger.kernel.org, brueckner@linux.ibm.com, acme@redhat.com, kan.liang@linux.intel.com In-Reply-To: <20181023151616.78193-1-tmricht@linux.ibm.com> References: <20181023151616.78193-1-tmricht@linux.ibm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] perf stat: Handle different PMU names with common prefix Git-Commit-ID: ea1fa48c055f833eb25f0c33188feecb7002ada5 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: ea1fa48c055f833eb25f0c33188feecb7002ada5 Gitweb: https://git.kernel.org/tip/ea1fa48c055f833eb25f0c33188feecb7002ada5 Author: Thomas Richter AuthorDate: Tue, 23 Oct 2018 17:16:16 +0200 Committer: Arnaldo Carvalho de Melo CommitDate: Mon, 5 Nov 2018 14:37:10 -0300 perf stat: Handle different PMU names with common prefix 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 ...//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 Reviewed-by: Hendrik Brueckner Reviewed-by: Sebastien Boisvert Cc: Heiko Carstens Cc: Kan Liang Cc: Martin Schwidefsky 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 --- 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; }