From patchwork Fri Apr 17 10:41:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 11494729 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEE3D6CA for ; Fri, 17 Apr 2020 10:45:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AC15B221EC for ; Fri, 17 Apr 2020 10:45:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Kg72kvM/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AC15B221EC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8FYMHhRiovXrSYfl3/TtMHmd6b/k0OVJ4XeJ7lSONog=; b=Kg72kvM/m87biQ /Suvf5EOXP6Mfx8kbhL2uIJdn0t9Xw6fWOq29NCD/VNhOdOpdwJ93imSCoVX+vutNtEEq4YQ72Wsq vPei/BY2XKHP9aEB3MmtXwif4AIPulP8PhJFPZpa0rQV25ffZZEt3L595gqGKY28gVjoHgxYFG6eG CJW04KghYddmKXSteEjyRMLwGGjLOX2HNvnbTg4dsIiGH6JTAy2R2ffZ1lr/20GLCZfCq4sfUvLhk 2ingovxCwsl0Kx5DZQH7WLkkrkzwCc3cPYeOqmCdGRXOYZhgpMLcUnjNFoMZg2prSl+C5sUN8ii5i 0Z1B1mlmPtC0tCj6Zqww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPOV5-0000oR-5n; Fri, 17 Apr 2020 10:45:35 +0000 Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jPOUy-0000fx-JS for linux-arm-kernel@lists.infradead.org; Fri, 17 Apr 2020 10:45:30 +0000 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 99262AD9048FCD38B932; 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: , , , , , , , Subject: [RFC PATCH v2 08/13] perf pmu: Add pmu_add_sys_aliases() Date: Fri, 17 Apr 2020 18:41:19 +0800 Message-ID: <1587120084-18990-9-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 X-Originating-IP: [10.69.192.58] X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200417_034529_223344_257787AC X-CRM114-Status: GOOD ( 10.42 ) X-Spam-Score: -2.3 (--) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-2.3 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [45.249.212.32 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: irogers@google.com, ak@linux.intel.com, linux-kernel@vger.kernel.org, John Garry , qiangqing.zhang@nxp.com, linuxarm@huawei.com, zhangshaokun@hisilicon.com, robin.murphy@arm.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add pmu_add_sys_aliases() to add system PMU events aliases. For adding system PMU events, we iterate through all the events per SoC event table in pmu_sys_event_tables[]. Matches must satisfy both: - PMU identifier matches event "compat" value - like uncore event matching, the event "Unit" member must match; this match under return value of pmu_uncore_alias_match() (maybe rename that function?) Signed-off-by: John Garry --- tools/perf/util/pmu.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu.h | 5 ++++ 2 files changed, 84 insertions(+) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 6a67c6a28d08..2f38465e8a73 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -827,6 +827,84 @@ static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) pmu_add_cpu_aliases_map(head, pmu, map); } +void pmu_for_each_sys_event(struct perf_pmu *pmu, pmu_sys_event_iter_fn fn, + void *data) +{ + struct pmu_event *pe; + int i = 0; + + if (!pmu->id) + return; + + while (1) { + struct pmu_sys_events *event_table; + int j = 0; + + event_table = &pmu_sys_event_tables[i++]; + + if (!event_table->table) + break; + + while (1) { + int ret; + + pe = &event_table->table[j++]; + + if (!pe->name && !pe->metric_group && !pe->metric_name) + break; + + ret = fn(pmu, pe, data); + if (ret) + break; + } + } +} + +struct pmu_sys_event_iter_data { + struct list_head *head; +}; + +static int pmu_add_sys_aliases_iter_fn(struct perf_pmu *pmu, + struct pmu_event *pe, void *data) +{ + struct pmu_sys_event_iter_data *idata = data; + + if (!pe->name) { + if (pe->metric_group || pe->metric_name) + return 0; + return -EINVAL; + } + + if (!pe->compat || !pe->pmu) + return 0; + + if (!strcmp(pmu->id, pe->compat) && + pmu_uncore_alias_match(pe->pmu, pmu->name)) { + __perf_pmu__new_alias(idata->head, NULL, + (char *)pe->name, + (char *)pe->desc, + (char *)pe->event, + (char *)pe->long_desc, + (char *)pe->topic, + (char *)pe->unit, + (char *)pe->perpkg, + (char *)pe->metric_expr, + (char *)pe->metric_name, + (char *)pe->deprecated); + } + + return 0; +} + +static void pmu_add_sys_aliases(struct list_head *head, struct perf_pmu *pmu) +{ + struct pmu_sys_event_iter_data idata = { + .head = head, + }; + + pmu_for_each_sys_event(pmu, pmu_add_sys_aliases_iter_fn, &idata); +} + struct perf_event_attr * __weak perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused) { @@ -882,6 +960,7 @@ static struct perf_pmu *pmu_lookup(const char *name) pmu->id = pmu_id(name); pmu->max_precise = pmu_max_precise(name); pmu_add_cpu_aliases(&aliases, pmu); + pmu_add_sys_aliases(&aliases, pmu); INIT_LIST_HEAD(&pmu->format); INIT_LIST_HEAD(&pmu->aliases); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 62ebca9481fe..e4bc9d192236 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -106,6 +106,11 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); +typedef int (*pmu_sys_event_iter_fn)(struct perf_pmu *, struct pmu_event *pe, + void *data); + +void pmu_for_each_sys_event(struct perf_pmu *pmu, pmu_sys_event_iter_fn fn, + void *data); int perf_pmu__convert_scale(const char *scale, char **end, double *sval); #endif /* __PMU_H */