Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp3720227imm; Mon, 18 Jun 2018 02:57:57 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKqJyMJdE/YbxmZ/jyUpHWX5BmISINgkx0WSQOlpOIvHFG8TMUFxb14AOz+DF0B3Rcvhnwu X-Received: by 2002:a65:46cb:: with SMTP id n11-v6mr10201523pgr.193.1529315877863; Mon, 18 Jun 2018 02:57:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529315877; cv=none; d=google.com; s=arc-20160816; b=hdpchJ+OKWyBOcrd08CPG9lZNiBdw9LBwFRH9X9dYqq0Rc/+jG9f/D7oCZuNMQxP01 9ptYawEpGOjID12Hwah/M3h8BvOp4SV/Gssxan45s/WV14KQt0FLt0u/NCusi2Zv6f8E gGTV+5pLFEr2oPAH03pXv9o/3qwaAPHuwJS4rhh7t/M9FLkHgOcAbVCPqo/Shgid27+d oXVw+rY7pua6FpPtgPQ5Hvt3b07WqAIzitnjx//Vn2tQoi31hrDc+elb6B7qOvjCmksS KsSKNcomQvvhPaLJzf8Q6j6fv7Qqb2TiEmqTxakwXrL8ECSb3p6A6vb0i5/1Oob2uUTJ OG8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=VW4ACwecm29UErqYK9tRcbq1svp7ll88m0NinhKuuFQ=; b=JaIAprFeiiU+gfl+mu3WTIVFN7eRAzJAvfuFaTOGe0ROX0o91FdkIj6oG/9g7fjT6Y Xh6NbiEDk7Ss+XRjzAwLLh6WoVF4AZEBC/LFlUNPiBVpWWiM+cZlePusReo2N9dXrEbZ ddKjobZq6TUkRi9KA8r1ieth87VpeNUTx+uZ/PW9u2uBY7/OIZNG9KYvOgf1s3sAbfSw ueuM8WKjyKsuV6Pc0XhE3I1+hyFhKtblNJLt7e9H1cDLH4RU1QsTau1Q9orafvkgcGml WUd7ZG81YS5EIhasIX/1b+Sn3ijK0LG+40mUuqitPBB9VCTuZjvK0ZEWgg1oQdjjH2y0 0kkg== 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 y9-v6si11711949pgo.570.2018.06.18.02.57.44; Mon, 18 Jun 2018 02:57:57 -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 S935653AbeFRIUT (ORCPT + 99 others); Mon, 18 Jun 2018 04:20:19 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55042 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935637AbeFRIUR (ORCPT ); Mon, 18 Jun 2018 04:20:17 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5A3C1C84; Mon, 18 Jun 2018 08:20:16 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kan Liang , Arnaldo Carvalho de Melo , Agustin Vega-Frias , Andi Kleen , Ganapatrao Kulkarni , Jin Yao , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Shaokun Zhang , Will Deacon , Sasha Levin Subject: [PATCH 4.16 095/279] perf pmu: Fix core PMU alias list for X86 platform Date: Mon, 18 Jun 2018 10:11:20 +0200 Message-Id: <20180618080612.733313790@linuxfoundation.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180618080608.851973560@linuxfoundation.org> References: <20180618080608.851973560@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Kan Liang [ Upstream commit 292c34c10249c64a70def442f0d977bf9d466ed7 ] When counting uncore event with alias, core event is mistakenly involved, for example: perf stat --no-merge -e "unc_m_cas_count.all" -C0 sleep 1 Performance counter stats for 'CPU(s) 0': 0 unc_m_cas_count.all [uncore_imc_4] 0 unc_m_cas_count.all [uncore_imc_2] 0 unc_m_cas_count.all [uncore_imc_0] 153,640 unc_m_cas_count.all [cpu] 0 unc_m_cas_count.all [uncore_imc_5] 25,026 unc_m_cas_count.all [uncore_imc_3] 0 unc_m_cas_count.all [uncore_imc_1] 1.001447890 seconds time elapsed The reason is that current implementation doesn't check PMU name of a event when adding its alias into the alias list for core PMU. The uncore event aliases are mistakenly added. This bug was introduced in: commit 14b22ae028de ("perf pmu: Add helper function is_pmu_core to detect PMU CORE devices") Checking the PMU name for all PMUs on X86 and other architectures except ARM. There is no behavior change for ARM. Signed-off-by: Kan Liang Tested-by: Arnaldo Carvalho de Melo Cc: Agustin Vega-Frias Cc: Andi Kleen Cc: Ganapatrao Kulkarni Cc: Jin Yao Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Shaokun Zhang Cc: Will Deacon Fixes: 14b22ae028de ("perf pmu: Add helper function is_pmu_core to detect PMU CORE devices") Link: http://lkml.kernel.org/r/1524594014-79243-1-git-send-email-kan.liang@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- tools/perf/util/pmu.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -539,9 +539,10 @@ static bool pmu_is_uncore(const char *na /* * PMU CORE devices have different name other than cpu in sysfs on some - * platforms. looking for possible sysfs files to identify as core device. + * platforms. + * Looking for possible sysfs files to identify the arm core device. */ -static int is_pmu_core(const char *name) +static int is_arm_pmu_core(const char *name) { struct stat st; char path[PATH_MAX]; @@ -550,12 +551,6 @@ static int is_pmu_core(const char *name) if (!sysfs) return 0; - /* Look for cpu sysfs (x86 and others) */ - scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/cpu", sysfs); - if ((stat(path, &st) == 0) && - (strncmp(name, "cpu", strlen("cpu")) == 0)) - return 1; - /* Look for cpu sysfs (specific to arm) */ scnprintf(path, PATH_MAX, "%s/bus/event_source/devices/%s/cpus", sysfs, name); @@ -651,6 +646,7 @@ static void pmu_add_cpu_aliases(struct l struct pmu_events_map *map; struct pmu_event *pe; const char *name = pmu->name; + const char *pname; map = perf_pmu__find_map(pmu); if (!map) @@ -669,11 +665,9 @@ static void pmu_add_cpu_aliases(struct l break; } - if (!is_pmu_core(name)) { - /* check for uncore devices */ - if (pe->pmu == NULL) - continue; - if (strncmp(pe->pmu, name, strlen(pe->pmu))) + if (!is_arm_pmu_core(name)) { + pname = pe->pmu ? pe->pmu : "cpu"; + if (strncmp(pname, name, strlen(pname))) continue; }