From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1676AC3815B for ; Fri, 17 Apr 2020 10:45:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F14AE221EC for ; Fri, 17 Apr 2020 10:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729977AbgDQKpf (ORCPT ); Fri, 17 Apr 2020 06:45:35 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:36174 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729896AbgDQKpb (ORCPT ); Fri, 17 Apr 2020 06:45:31 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id D4E62AB3D0B362BDEA7C; Fri, 17 Apr 2020 18:45:26 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Fri, 17 Apr 2020 18:45:20 +0800 From: John Garry To: , , , , , , , CC: , , , , , , , , John Garry Subject: [RFC PATCH v2 07/13] perf pmu: Add pmu_id() Date: Fri, 17 Apr 2020 18:41:18 +0800 Message-ID: <1587120084-18990-8-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1587120084-18990-1-git-send-email-john.garry@huawei.com> References: <1587120084-18990-1-git-send-email-john.garry@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a function to read the PMU id sysfs entry. We only do it for uncore PMUs where this would be relevant. Signed-off-by: John Garry --- tools/perf/util/pmu.c | 36 ++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu.h | 1 + 2 files changed, 37 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ef6a63f3d386..6a67c6a28d08 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -594,6 +594,7 @@ static struct perf_cpu_map *__pmu_cpumask(const char *path) * Uncore PMUs have a "cpumask" file under sysfs. CPU PMUs (e.g. on arm/arm64) * may have a "cpus" file. */ +#define CPUS_TEMPLATE_ID "%s/bus/event_source/devices/%s/identifier" #define CPUS_TEMPLATE_UNCORE "%s/bus/event_source/devices/%s/cpumask" #define CPUS_TEMPLATE_CPU "%s/bus/event_source/devices/%s/cpus" @@ -632,6 +633,39 @@ static bool pmu_is_uncore(const char *name) return file_available(path); } +static char *pmu_id(const char *name) +{ + char path[PATH_MAX], *id; + const char *sysfs; + FILE *file; + int n; + + sysfs = sysfs__mountpoint(); + snprintf(path, PATH_MAX, CPUS_TEMPLATE_ID, sysfs, name); + + id = malloc(PATH_MAX); + if (!id) + return NULL; + + file = fopen(path, "r"); + if (!file) { + free(id); + return NULL; + } + + n = fscanf(file, "%s", id); + + fclose(file); + + if (!n) { + free(id); + return NULL; + } + + return id; +} + + /* * PMU CORE devices have different name other than cpu in sysfs on some * platforms. @@ -844,6 +878,8 @@ static struct perf_pmu *pmu_lookup(const char *name) pmu->name = strdup(name); pmu->type = type; pmu->is_uncore = pmu_is_uncore(name); + if (pmu->is_uncore) + pmu->id = pmu_id(name); pmu->max_precise = pmu_max_precise(name); pmu_add_cpu_aliases(&aliases, pmu); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 5fb3f16828df..62ebca9481fe 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -24,6 +24,7 @@ struct perf_event_attr; struct perf_pmu { char *name; + char *id; __u32 type; bool selectable; bool is_uncore; -- 2.16.4