Received: by 10.192.165.148 with SMTP id m20csp880075imm; Wed, 25 Apr 2018 09:03:12 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/S9vHZsiwV6fe0z65OgfPLSiqAsagZA0wjr8MCJ9/j/ByrvufBha3OwTA7cK1NaqQ27cxa X-Received: by 2002:a17:902:6b02:: with SMTP id o2-v6mr29726388plk.6.1524672192351; Wed, 25 Apr 2018 09:03:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524672192; cv=none; d=google.com; s=arc-20160816; b=gENCRWFfFeJ8+hpNl9NWPU7ywr+P5L+mYW9pQRFh6ox7yYjfSIZz+r++CcWXhqc7xs DRiKNXT5szqbE0AtT0iWZfiqSz+DYOh8vvva1TyraDF7Ld/F08k04G7HKPcP53nRWL+I 09gyVLXXPEtkY9NqXVW3CwxICQfCiqh3z/VHSSmpxhMclM3YuGvkt2RMgWPKI9fDOMON 1KybKAssd801mpy8Iq5/GjviEUH9uOQ07otajLA77a1PktuGAtc7YZ388JRjbvFiGFbY blQsDDo6txxMFnVCVIMaWI5vW5ZXrmoXj4aEsBJtc1YxxrEgmu+sR53mAYXoP6goMiTm pHYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dmarc-filter:arc-authentication-results; bh=35/wx6TK0YKvbywlLb8dyc5/LEOSzWYq7mkdxpgBK1o=; b=nDOrl4yPMQrI3Sh75Sd5jLi7WTIaQ2OKulS/Ipl7KeGQS39hybF4mWeB3VoKgrlQ6S gLioKPmJ40DiequZJoKLHJRgHjMEm4mXlFvob4HC1WC5Eua1xavOkbc2/quToamgDORb e0IduDnXVeLV9OkEz1KVKMUOO0WyY7c5w1r9YZVwHc4VQA3lAXIaqMfgDaEXiNPTwiQu TQzcZxKihFYjKxKu0xGa3CVR1yh1GKp7Buio6dfrfZxuhjEmWk99On0kaja0FW1ynBRl pxK766feI0tGIkzbVvRlmcsBBKa9jG7aZHzhLPJAVYwiDhrl7A4enziQy7KHS5jeqb92 UWng== 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 b1si5035964pgr.464.2018.04.25.09.02.30; Wed, 25 Apr 2018 09:03:12 -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 S932102AbeDYQA6 (ORCPT + 99 others); Wed, 25 Apr 2018 12:00:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:47142 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755770AbeDYQAp (ORCPT ); Wed, 25 Apr 2018 12:00:45 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (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 EEBAA217D9; Wed, 25 Apr 2018 16:00:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEBAA217D9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=acme@kernel.org From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Kan Liang , Agustin Vega-Frias , Andi Kleen , Ganapatrao Kulkarni , Jin Yao , Jiri Olsa , Namhyung Kim , Peter Zijlstra , Shaokun Zhang , Will Deacon , Arnaldo Carvalho de Melo Subject: [PATCH 09/12] perf pmu: Fix core PMU alias list for X86 platform Date: Wed, 25 Apr 2018 13:00:05 -0300 Message-Id: <20180425160008.3407-10-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180425160008.3407-1-acme@kernel.org> References: <20180425160008.3407-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kan Liang 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 --- tools/perf/util/pmu.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index af4bedf4cf98..d2fb597c9a8c 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -539,9 +539,10 @@ static bool pmu_is_uncore(const char *name) /* * 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); @@ -668,6 +663,7 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) 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) @@ -686,11 +682,9 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) 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; } -- 2.14.3