Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp672516ybj; Thu, 7 May 2020 05:05:41 -0700 (PDT) X-Google-Smtp-Source: APiQypITaK42jsyGdxektr7Fo1MnwWVNdhZAfqibSAFqbkkAVGJhe1PHob9sSHEYsXWfXij6f/68 X-Received: by 2002:a17:906:68d7:: with SMTP id y23mr12068863ejr.85.1588853141616; Thu, 07 May 2020 05:05:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588853141; cv=none; d=google.com; s=arc-20160816; b=UX5QB24IMLJndLIcZenJVXUPhhTS7JPeDXp9feheL0H6kNDrYFSOZZ9m8dUvzTZh5F ZUJPANjW311hv/bHjwogbhvrzwFI+wT3xeJkHwnpgkXpXzm6SQng/a6gzBTVQ9CAN38c jCsYpEhjnDWkIgkJ90gMMiAAWR2pv2558zoxKEPgJgPrMvauE4fFxG7jkF8EIhy8IYgX RNGR4svNMZRlr+CBbnRgYrqoSvH5iQQUVrB3JSJNGCsgHu3eJrszqj1bKOoPThMWVgn1 ml3waLA61zNVvQNM+j0xHPAJjDtxP036nHo6C5nfOQGqe5HPwhtf1FM6G0cnITGFRodC bxUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=HsTe93806ObmtbUOymEi51aeZ7uODPgT7ZYWavA05ao=; b=h5pyKtMzYx5KhRI0hQ1xbtIhXEdM6x5wSlFqB9kPi3QXhC1hIQ8TsR1MLmt69Kiya/ Oh9fW29olriZEqfnHs5hjk8xjgTNcWQnUaxN9YlWLoUC2tLz5WfT8kMce08bXXKXn31u b628lZpJJIQVR6nujY9frJGhyCzH3AlrqA8tCZKMXheUDjycqEGU8Xee2uwduP/hw8rL HbYeeNX8M5xfxDeVtO3AfIYlHyfX0TPxXAVvBSWINVo0PPWH0TxGBlKqj7WzaK0+J8yR h35Nio9EOYiHesn0CurfeprRIBfbr//0Gu4PSwhW/pgnN52ufOzgyVjCcxT/KcBJ1sJ2 9b3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si2891585eds.503.2020.05.07.05.05.13; Thu, 07 May 2020 05:05:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727804AbgEGMCl (ORCPT + 99 others); Thu, 7 May 2020 08:02:41 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:60324 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726350AbgEGMCJ (ORCPT ); Thu, 7 May 2020 08:02:09 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id B653B1428696BD3F08A5; Thu, 7 May 2020 20:02:04 +0800 (CST) Received: from localhost.localdomain (10.69.192.58) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 7 May 2020 20:01:58 +0800 From: John Garry To: , , , , , , CC: , , , , , , , , , John Garry Subject: [PATCH RFC v3 06/12] perf pmu: Add pmu_id() Date: Thu, 7 May 2020 19:57:45 +0800 Message-ID: <1588852671-61996-7-git-send-email-john.garry@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1588852671-61996-1-git-send-email-john.garry@huawei.com> References: <1588852671-61996-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 | 18 ++++++++++++++++++ tools/perf/util/pmu.h | 1 + 2 files changed, 19 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ef6a63f3d386..6f77c6af9e04 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 "./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,21 @@ static bool pmu_is_uncore(const char *name) return file_available(path); } +static char *pmu_id(const char *name) +{ + char path[PATH_MAX], *str; + size_t len; + + snprintf(path, PATH_MAX, CPUS_TEMPLATE_ID, name); + + if (sysfs__read_str(path, &str, &len) < 0) + return NULL; + + str[len - 1] = 0; // remove line feed + + return str; +} + /* * PMU CORE devices have different name other than cpu in sysfs on some * platforms. @@ -844,6 +860,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