Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2957344imu; Mon, 19 Nov 2018 08:36:42 -0800 (PST) X-Google-Smtp-Source: AJdET5en8bxxU1q4yKCx84fKiblf+cMucZGG5sxzR7I7xhhR/kMYEifSLAiO3mIzNxKq1hy9XJYF X-Received: by 2002:a63:f74f:: with SMTP id f15mr20908964pgk.190.1542645401965; Mon, 19 Nov 2018 08:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542645401; cv=none; d=google.com; s=arc-20160816; b=TbwPdZ4HOu2o2JnaK+eDwdNFln58sMfwhHoP0V/OA1tTv+qbThCTQm7rT+jnYofq2k 5iwjMA9bWTnIpBZgBF+7kjjvOfrJoN4fY6dN4+lM+cFI1AMpAqTYnf9TinSuSWNU5KjA tN4mu+NFjbUdDDeX7aG6DQ2DoG07XoLgBHnmrqO/8gLIEosBMZXMGtifx+KSOozS1sKB EhVmZL430DqYWUxJI+hK6a/waCUNu71H/qIemfhFKdsfSdRexlgrvcYidYhYkV9xVTKG N2YpFrAoQiGd225ojcmmi4+pvs6hfLdwTb+Na1mL26qN2o9ciasMNYO/UaTbjpX3jNeH GDfQ== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WfP9MHziyoSERLxXOMYhRjyzW/jbuAkau6aY9ipQvtk=; b=ZEojneOZPMoRZ/ZsYKDg06T/blTqHTK25aav65yim4vCh6V37uabM5YsmCJvGII1k5 IMBbZXG+uw77mYKnY8xJXXZl0Kkr7oWbUSYS551f1rgOC3LkDxo9GraNBZeG/TCXnnFM icEPS37DxcZy3ja8kipsKn1d/Hlil73lrGEm3PMUXC96TrmMCjw+Fgxmnr//S/nCDRG+ gYKRVqWz/MpSgLnO1QEd7WFPokZGKcNTQerScn+Rt0Oug+lDekpsNVYV3yy6E4/8ebCu dWuYeoM3rOmOjjiqQGEwk+yl+ikExLyS9cnp2i5DRUJelwXBvrnNY0ONbi8EntOGUZIP tpSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BtVMMDjp; 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 c190-v6si9574134pfa.0.2018.11.19.08.36.27; Mon, 19 Nov 2018 08:36:41 -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; dkim=pass header.i=@kernel.org header.s=default header.b=BtVMMDjp; 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 S1731553AbeKTC7L (ORCPT + 99 others); Mon, 19 Nov 2018 21:59:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:58414 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730350AbeKTC7K (ORCPT ); Mon, 19 Nov 2018 21:59:10 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 40A0E20989; Mon, 19 Nov 2018 16:35:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542645301; bh=hyscv4ZFYFuShAmFHTHKFgFX0hnWG9ErhOpzC4wxSE8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BtVMMDjphSe6LOql8j4/bEe7aEDtPOTNqDUnfN7twsu4yyn4FqclJcM+dL/GnZ/WT uiXh42x3FfmAVGK93zyR+eyiD7COFrkpT+VSuv3R+Pv5o46n46SLqsULHakxckUn0l JDmJuh4QXE/zDwidiFBwY9xU5gcfH32cAuX3Fd0A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Richter , Hendrik Brueckner , Sebastien Boisvert , Heiko Carstens , Kan Liang , Martin Schwidefsky , Arnaldo Carvalho de Melo Subject: [PATCH 4.19 113/205] perf stat: Handle different PMU names with common prefix Date: Mon, 19 Nov 2018 17:27:00 +0100 Message-Id: <20181119162634.922075642@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162616.586062722@linuxfoundation.org> References: <20181119162616.586062722@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Thomas Richter commit ea1fa48c055f833eb25f0c33188feecb7002ada5 upstream. 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 Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/pmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -773,7 +773,7 @@ static void pmu_add_cpu_aliases(struct l if (!is_arm_pmu_core(name)) { pname = pe->pmu ? pe->pmu : "cpu"; - if (strncmp(pname, name, strlen(pname))) + if (strcmp(pname, name)) continue; }