Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2101168pxb; Sun, 17 Oct 2021 06:00:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxChx2jOmiDYSDzkp1sNd2EugI0X/rXJqnisZGNpaMcPUx1ZVtaKot4oCZg6P4wZdFDKgQQ X-Received: by 2002:aa7:cd53:: with SMTP id v19mr15931720edw.8.1634475625656; Sun, 17 Oct 2021 06:00:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634475625; cv=none; d=google.com; s=arc-20160816; b=eDM4n6o+NXTWh0SPPZQ8W7YXhIJM7tIbL5zepzivOuY7vI58iqv9B92QcGTktRYmCG R2zYax3NiSZR/4BjCNQJkz8i/IeKXg1bOZ/dNruhJJm92f7fr69uFB4TMhowf/G+aDo0 x6MjaVgmsUHCOGNPngsfWYG+lFXvx4zEjTqVF9clKV3ujRbnesdU8MUssX1ttkpvgLHS OAUNW1vk3DR8OqxniR9TeU9nLZrFsqkLn9JLd83CL46SJZHclXC1ggi5U+OG+ELElUDn YlaaJnP9AYgi/LMnnJiHXPU1BCrf2ZIMVoCf0m7aCp98RnzREJYx0tWF3j0OpcBBGs6N nG3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=gxfMzKW95smVMegJPzan5IoHpS/DHp3BWD4qbUW0ZIs=; b=eBBrlE3UUdaXNSnKBTegaAGAI+NdwcgiHUk8Yk3JH3t+seLdaslv+XqoJoFucSNfZv FVqf/M1XoKLPj03tSVz/9PDZzzK4BXNfRigyvBovfnQfdioPPuzOl8sQk1f76J+hBbl4 edOqqhuEiX/lcRTVDP44noiZVC1uwju99QuvLGj6kxQir/SrZMjESk1Fv7Z566rjJDJB 3g7sDH8yOTWSla42p8JKzPuVLvOBkAhczaizqnerD5D2+3yTaXFvXPXLfyRnkJh3n3nK VTGApdwJ9auMvd39nvwYgT2KoSeDTjAmSRvAYe1Zk9NO6Uo7Vfqia4SVRc7PR3LNWJpF R9ZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=o4UHOoyF; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id sg18si10311696ejc.10.2021.10.17.06.00.01; Sun, 17 Oct 2021 06:00:25 -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; dkim=pass header.i=@google.com header.s=20210112 header.b=o4UHOoyF; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242201AbhJORXw (ORCPT + 99 others); Fri, 15 Oct 2021 13:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242178AbhJORXu (ORCPT ); Fri, 15 Oct 2021 13:23:50 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6999CC061570 for ; Fri, 15 Oct 2021 10:21:43 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id s66-20020a252c45000000b005ba35261459so12014598ybs.7 for ; Fri, 15 Oct 2021 10:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gxfMzKW95smVMegJPzan5IoHpS/DHp3BWD4qbUW0ZIs=; b=o4UHOoyFs78uHXNv1mbf1S3IGByaezfdJ1cMH4PhZfXdXRZNiZjNqsSloO9tMwMcdH 7xGRerH9N8iDlOOv8Fn9YMW0dG26Wm9wgH4aF06Bl+maFH5XvNWscZix+/3axc63chf6 btAKlDsXPR5jxF6s4Hrujg7KbE0DeJKqvixDkyW6NJMNXOsKEZEQn4zqB3XdtUJhqzIb BkD7sxxvn4ynr8BBrc9SSd1I3kyZazHcMz/3qFk4QH3MyAfVz5KGHxUhxo1Fj0cOsX5R iTtRmTStKPXNjVIgh5l/2KDUhbWkUgK7hrdlgq+9fqE4MhENVvmWxwUWQ+tv8Gg1rHnn Kg0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gxfMzKW95smVMegJPzan5IoHpS/DHp3BWD4qbUW0ZIs=; b=1qvFGlvcOWz8mILaAGVgXRHBgJqfY7HHSfqoCXLEGIKbhdZVZlYfe3DM3/esp6DI8R NC8UVoX4pkH41N9fSeja/gSZl928eD45Jm2I41+4A0voPrTrGrh3fdWmaJ0ps7U1+6BU MuyXSIIZUClLAo+wOISkbD5zMPTpuVJy6Ja4QhgiQG45GE/dYxHpbQloqYjdY7Ny/2pQ aV8ecWGTAjN5xx3D6Kh3l2PFSTASl8EuQGTWXSEQH/hzluWzdvqO/aEQpCUP+njzTDmA IWlUzjjAPvdAzScI+EVMW+sm2ztnJuTGDeS2Y1kyHG8diPJFkyA850Df7m2Vk1uTYgl7 yL2A== X-Gm-Message-State: AOAM533FHFQwsD+vApBRUwtAKiLbcMYNS+t0S25aXEercfq/w1snnUsf LDQ9mX/R7nyLHy84qeAIAbwx7dVMcIWQ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:69bc:7451:58ad:6585]) (user=irogers job=sendgmr) by 2002:a25:be0c:: with SMTP id h12mr13939933ybk.22.1634318502612; Fri, 15 Oct 2021 10:21:42 -0700 (PDT) Date: Fri, 15 Oct 2021 10:21:13 -0700 In-Reply-To: <20211015172132.1162559-1-irogers@google.com> Message-Id: <20211015172132.1162559-3-irogers@google.com> Mime-Version: 1.0 References: <20211015172132.1162559-1-irogers@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v2 02/21] perf pmu: Add const to pmu_events_map. From: Ian Rogers To: Andi Kleen , Jiri Olsa , Jin Yao , Namhyung Kim , John Garry , Kajol Jain , "Paul A . Clarke" , Arnaldo Carvalho de Melo , Riccardo Mancini , Kan Liang , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Kees Cook , Sami Tolvanen , Nick Desaulniers , Andrew Morton , Jacob Keller , Zhen Lei , ToastC , Joakim Zhang , Felix Fietkau , Jiapeng Chong , Song Liu , Fabian Hemmer , Alexander Antonov , Nicholas Fraser , Adrian Hunter , Denys Zagorui , Wan Jiabing , Thomas Richter , Sumanth Korikkar , Heiko Carstens , Changbin Du , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Andrew Kilroy Cc: Stephane Eranian , Ian Rogers Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The pmu_events_map is generated at compile time and used for lookup. For testing purposes we need to swap the map being used. Having the pmu_events_map be non-const is misleading as it may be an out argument. Make it const and update uses so they work on const too. Acked-by: Andi Kleen Reviewed-by: John Garry Signed-off-by: Ian Rogers --- tools/perf/arch/arm64/util/pmu.c | 2 +- tools/perf/pmu-events/jevents.c | 2 +- tools/perf/pmu-events/pmu-events.h | 2 +- tools/perf/tests/expand-cgroup.c | 2 +- tools/perf/tests/parse-metric.c | 2 +- tools/perf/tests/pmu-events.c | 18 +++++++++--------- tools/perf/util/metricgroup.c | 20 ++++++++++---------- tools/perf/util/metricgroup.h | 4 ++-- tools/perf/util/pmu.c | 10 +++++----- tools/perf/util/pmu.h | 6 +++--- tools/perf/util/s390-sample-raw.c | 4 ++-- 11 files changed, 36 insertions(+), 36 deletions(-) diff --git a/tools/perf/arch/arm64/util/pmu.c b/tools/perf/arch/arm64/util/pmu.c index 2234fbd0a912..d3a18f9c85f6 100644 --- a/tools/perf/arch/arm64/util/pmu.c +++ b/tools/perf/arch/arm64/util/pmu.c @@ -3,7 +3,7 @@ #include "../../../util/cpumap.h" #include "../../../util/pmu.h" -struct pmu_events_map *pmu_events_map__find(void) +const struct pmu_events_map *pmu_events_map__find(void) { struct perf_pmu *pmu = NULL; diff --git a/tools/perf/pmu-events/jevents.c b/tools/perf/pmu-events/jevents.c index 19497e4f8a86..5624a37d6f93 100644 --- a/tools/perf/pmu-events/jevents.c +++ b/tools/perf/pmu-events/jevents.c @@ -798,7 +798,7 @@ static bool is_sys_dir(char *fname) static void print_mapping_table_prefix(FILE *outfp) { - fprintf(outfp, "struct pmu_events_map pmu_events_map[] = {\n"); + fprintf(outfp, "const struct pmu_events_map pmu_events_map[] = {\n"); } static void print_mapping_table_suffix(FILE *outfp) diff --git a/tools/perf/pmu-events/pmu-events.h b/tools/perf/pmu-events/pmu-events.h index 5c2bf7275c1c..42c6db6bedec 100644 --- a/tools/perf/pmu-events/pmu-events.h +++ b/tools/perf/pmu-events/pmu-events.h @@ -53,7 +53,7 @@ struct pmu_sys_events { * Global table mapping each known CPU for the architecture to its * table of PMU events. */ -extern struct pmu_events_map pmu_events_map[]; +extern const struct pmu_events_map pmu_events_map[]; extern struct pmu_sys_events pmu_sys_event_tables[]; #endif diff --git a/tools/perf/tests/expand-cgroup.c b/tools/perf/tests/expand-cgroup.c index 0e46aeb843ce..aaad51aba12f 100644 --- a/tools/perf/tests/expand-cgroup.c +++ b/tools/perf/tests/expand-cgroup.c @@ -193,7 +193,7 @@ static int expand_metric_events(void) .metric_name = NULL, }, }; - struct pmu_events_map ev_map = { + const struct pmu_events_map ev_map = { .cpuid = "test", .version = "1", .type = "core", diff --git a/tools/perf/tests/parse-metric.c b/tools/perf/tests/parse-metric.c index 4f6f4904e852..dfc797ecc750 100644 --- a/tools/perf/tests/parse-metric.c +++ b/tools/perf/tests/parse-metric.c @@ -79,7 +79,7 @@ static struct pmu_event pme_test[] = { } }; -static struct pmu_events_map map = { +static const struct pmu_events_map map = { .cpuid = "test", .version = "1", .type = "core", diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index d3534960ed25..8a1fdcd072f5 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -242,9 +242,9 @@ static bool is_same(const char *reference, const char *test) return !strcmp(reference, test); } -static struct pmu_events_map *__test_pmu_get_events_map(void) +static const struct pmu_events_map *__test_pmu_get_events_map(void) { - struct pmu_events_map *map; + const struct pmu_events_map *map; for (map = &pmu_events_map[0]; map->cpuid; map++) { if (!strcmp(map->cpuid, "testcpu")) @@ -421,7 +421,7 @@ static int compare_alias_to_test_event(struct perf_pmu_alias *alias, static int test_pmu_event_table(void) { struct pmu_event *sys_event_tables = __test_pmu_get_sys_events_table(); - struct pmu_events_map *map = __test_pmu_get_events_map(); + const struct pmu_events_map *map = __test_pmu_get_events_map(); struct pmu_event *table; int map_events = 0, expected_events; @@ -518,7 +518,7 @@ static int __test_core_pmu_event_aliases(char *pmu_name, int *count) struct perf_pmu *pmu; LIST_HEAD(aliases); int res = 0; - struct pmu_events_map *map = __test_pmu_get_events_map(); + const struct pmu_events_map *map = __test_pmu_get_events_map(); struct perf_pmu_alias *a, *tmp; if (!map) @@ -571,7 +571,7 @@ static int __test_uncore_pmu_event_aliases(struct perf_pmu_test_pmu *test_pmu) struct perf_pmu *pmu = &test_pmu->pmu; const char *pmu_name = pmu->name; struct perf_pmu_alias *a, *tmp, *alias; - struct pmu_events_map *map; + const struct pmu_events_map *map; LIST_HEAD(aliases); int res = 0; @@ -825,7 +825,7 @@ struct metric { static int resolve_metric_simple(struct expr_parse_ctx *pctx, struct list_head *compound_list, - struct pmu_events_map *map, + const struct pmu_events_map *map, const char *metric_name) { struct hashmap_entry *cur, *cur_tmp; @@ -885,8 +885,8 @@ static int resolve_metric_simple(struct expr_parse_ctx *pctx, static int test_parsing(void) { - struct pmu_events_map *cpus_map = pmu_events_map__find(); - struct pmu_events_map *map; + const struct pmu_events_map *cpus_map = pmu_events_map__find(); + const struct pmu_events_map *map; struct pmu_event *pe; int i, j, k; int ret = 0; @@ -1027,7 +1027,7 @@ static int metric_parse_fake(const char *str) */ static int test_parsing_fake(void) { - struct pmu_events_map *map; + const struct pmu_events_map *map; struct pmu_event *pe; unsigned int i, j; int err = 0; diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 8ba5370f5f64..74ea0a3540ce 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -623,7 +623,7 @@ static int metricgroup__print_sys_event_iter(struct pmu_event *pe, void *data) void metricgroup__print(bool metrics, bool metricgroups, char *filter, bool raw, bool details) { - struct pmu_events_map *map = pmu_events_map__find(); + const struct pmu_events_map *map = pmu_events_map__find(); struct pmu_event *pe; int i; struct rblist groups; @@ -910,7 +910,7 @@ static int __add_metric(struct list_head *metric_list, match_metric(__pe->metric_name, __metric))) struct pmu_event *metricgroup__find_metric(const char *metric, - struct pmu_events_map *map) + const struct pmu_events_map *map) { struct pmu_event *pe; int i; @@ -977,7 +977,7 @@ static int add_metric(struct list_head *metric_list, static int __resolve_metric(struct metric *m, bool metric_no_group, struct list_head *metric_list, - struct pmu_events_map *map, + const struct pmu_events_map *map, struct expr_ids *ids) { struct hashmap_entry *cur; @@ -1025,7 +1025,7 @@ static int __resolve_metric(struct metric *m, static int resolve_metric(bool metric_no_group, struct list_head *metric_list, - struct pmu_events_map *map, + const struct pmu_events_map *map, struct expr_ids *ids) { struct metric *m; @@ -1099,7 +1099,7 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe, static int metricgroup__add_metric(const char *metric, bool metric_no_group, struct strbuf *events, struct list_head *metric_list, - struct pmu_events_map *map) + const struct pmu_events_map *map) { struct expr_ids ids = { .cnt = 0, }; struct pmu_event *pe; @@ -1173,7 +1173,7 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group, static int metricgroup__add_metric_list(const char *list, bool metric_no_group, struct strbuf *events, struct list_head *metric_list, - struct pmu_events_map *map) + const struct pmu_events_map *map) { char *llist, *nlist, *p; int ret = -EINVAL; @@ -1230,7 +1230,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, bool metric_no_merge, struct perf_pmu *fake_pmu, struct rblist *metric_events, - struct pmu_events_map *map) + const struct pmu_events_map *map) { struct parse_events_error parse_error; struct strbuf extra_events; @@ -1266,14 +1266,14 @@ int metricgroup__parse_groups(const struct option *opt, struct rblist *metric_events) { struct evlist *perf_evlist = *(struct evlist **)opt->value; - struct pmu_events_map *map = pmu_events_map__find(); + const struct pmu_events_map *map = pmu_events_map__find(); return parse_groups(perf_evlist, str, metric_no_group, metric_no_merge, NULL, metric_events, map); } int metricgroup__parse_groups_test(struct evlist *evlist, - struct pmu_events_map *map, + const struct pmu_events_map *map, const char *str, bool metric_no_group, bool metric_no_merge, @@ -1285,7 +1285,7 @@ int metricgroup__parse_groups_test(struct evlist *evlist, bool metricgroup__has_metric(const char *metric) { - struct pmu_events_map *map = pmu_events_map__find(); + const struct pmu_events_map *map = pmu_events_map__find(); struct pmu_event *pe; int i; diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h index cc4a92492a61..c931596557bf 100644 --- a/tools/perf/util/metricgroup.h +++ b/tools/perf/util/metricgroup.h @@ -44,9 +44,9 @@ int metricgroup__parse_groups(const struct option *opt, bool metric_no_merge, struct rblist *metric_events); struct pmu_event *metricgroup__find_metric(const char *metric, - struct pmu_events_map *map); + const struct pmu_events_map *map); int metricgroup__parse_groups_test(struct evlist *evlist, - struct pmu_events_map *map, + const struct pmu_events_map *map, const char *str, bool metric_no_group, bool metric_no_merge, diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index bdabd62170d2..4bcdc595ce5e 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -710,9 +710,9 @@ static char *perf_pmu__getcpuid(struct perf_pmu *pmu) return cpuid; } -struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) +const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) { - struct pmu_events_map *map; + const struct pmu_events_map *map; char *cpuid = perf_pmu__getcpuid(pmu); int i; @@ -737,7 +737,7 @@ struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu) return map; } -struct pmu_events_map *__weak pmu_events_map__find(void) +const struct pmu_events_map *__weak pmu_events_map__find(void) { return perf_pmu__find_map(NULL); } @@ -824,7 +824,7 @@ bool pmu_uncore_alias_match(const char *pmu_name, const char *name) * as aliases. */ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, - struct pmu_events_map *map) + const struct pmu_events_map *map) { int i; const char *name = pmu->name; @@ -859,7 +859,7 @@ void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, static void pmu_add_cpu_aliases(struct list_head *head, struct perf_pmu *pmu) { - struct pmu_events_map *map; + const struct pmu_events_map *map; map = perf_pmu__find_map(pmu); if (!map) diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 394898b07fd9..dd5cdde6a3d0 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -120,10 +120,10 @@ int perf_pmu__test(void); struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu); void pmu_add_cpu_aliases_map(struct list_head *head, struct perf_pmu *pmu, - struct pmu_events_map *map); + const struct pmu_events_map *map); -struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu); -struct pmu_events_map *pmu_events_map__find(void); +const struct pmu_events_map *perf_pmu__find_map(struct perf_pmu *pmu); +const struct pmu_events_map *pmu_events_map__find(void); bool pmu_uncore_alias_match(const char *pmu_name, const char *name); void perf_pmu_free_alias(struct perf_pmu_alias *alias); diff --git a/tools/perf/util/s390-sample-raw.c b/tools/perf/util/s390-sample-raw.c index 08ec3c3ae0ee..13f33d1ddb78 100644 --- a/tools/perf/util/s390-sample-raw.c +++ b/tools/perf/util/s390-sample-raw.c @@ -135,7 +135,7 @@ static int get_counterset_start(int setnr) * the name of this counter. * If no match is found a NULL pointer is returned. */ -static const char *get_counter_name(int set, int nr, struct pmu_events_map *map) +static const char *get_counter_name(int set, int nr, const struct pmu_events_map *map) { int rc, event_nr, wanted = get_counterset_start(set) + nr; @@ -159,7 +159,7 @@ static void s390_cpumcfdg_dump(struct perf_sample *sample) unsigned char *buf = sample->raw_data; const char *color = PERF_COLOR_BLUE; struct cf_ctrset_entry *cep, ce; - struct pmu_events_map *map; + const struct pmu_events_map *map; u64 *p; map = pmu_events_map__find(); -- 2.33.0.1079.g6e70778dc9-goog