Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1724428pxb; Thu, 7 Oct 2021 13:48:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBNP7QBBgHUtt7fr1Pygg78k4gE9Z4n+CCdNhIANQeKctManLKdld4xKS5JQqhT3upNS2D X-Received: by 2002:a50:99c6:: with SMTP id n6mr8873273edb.171.1633639735829; Thu, 07 Oct 2021 13:48:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633639735; cv=none; d=google.com; s=arc-20160816; b=sfGfT2uW9xbRiPXOq092CsyvJtxF9oopo4cuV+90hhO0/tRzZd9sYG2cIFv1rbaFXo TNPq+nUx8R1m5pC1FH0+1RR68TeQW3FWXb94Il3odQ3bBx25iBZ3XBiCBX+u6vvfUU0F 1ShsfOguL9oLc1OND5wzJaVlX0eREi+G0330roK+T5dpHv9zCUFzwUmVUKPLIXU5iaTZ /JQBD5A05SGdA2De18hBNst6WN6K9dRU6/Ho+mQbXzXnW/IRnD3YB93MtzwTiAeUlR4s sNx/DKII92Q0VT6QckwpfMJorIAuRyX7GyDCeJ6TfMU7JBNjp8oUOKRznsefqMzyAD9S 2GbQ== 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=WqmvM9N70HVzTEu0CvbsGBGn1/4vSMDbZNuUPp+1PA8=; b=CqgnHmglWUIzndo5c8sHi+iH0AjV7UtMVzMRXlcUU2shW63kHM114umlEuWGCf6QYi bia3TkIMRAHiQVZbcw3JfzSBTLw5mcZ+srX0PT5r6j0EIS8XdYlAtFYCGwgCgPcQDJYW rSgHtzvp3DxRcewQ9ymeNOe7U+AK2kiVwEvonWqdBN2OOD2fcY9Brrwj4csckT2jM1BA P9DtR7T1AqKdmemqkjQmr9zZukoeU3QURwIWBbWkKmJl//ifs/RdwcbjXIl/KGeXTaNW H5QllDNPcZI2ODt78eDRVaE//cxvW93gfiWf67HA/Y21lUhdZGz0T6dItjlF+z2V7NL6 U+qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=E5sv7iQr; 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 e6si513239edj.521.2021.10.07.13.48.31; Thu, 07 Oct 2021 13:48:55 -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=E5sv7iQr; 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 S242892AbhJGQ7g (ORCPT + 99 others); Thu, 7 Oct 2021 12:59:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242956AbhJGQ73 (ORCPT ); Thu, 7 Oct 2021 12:59:29 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01B03C061769 for ; Thu, 7 Oct 2021 09:57:35 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id q5-20020a05620a0d8500b0045edb4779dbso5758719qkl.2 for ; Thu, 07 Oct 2021 09:57:34 -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=WqmvM9N70HVzTEu0CvbsGBGn1/4vSMDbZNuUPp+1PA8=; b=E5sv7iQrp0XNDSXQBDap445WUJmE+yDJm2nrbFWsO/gvYxAqzsPmPl4JWuNmvJPdUP ENYpLkBHez+po9LBrqgbNWbk9wS1SM9jxP95xdAvfTh5nkvY8Iic1/bVknvNb8QqrAc5 ZjUTHFIlG07jB+2GIJp3V6MatiL3B9mbSGBNKqtrTPFhMquM5KQ6rjM/RSViMujK5sDE 7Kf4fJ/rKv0EUhJVDK7pr6JGogyyiWbmMPmwRkhjctvdBgYAjCgj30IAsf3OoS7cp+f1 YEO3F2QquR5DDcbu6zisAdgf90JoQr6ShVwqJ624UVlPTQ1Gq1Z1bTOcvOcu24I3xxUf k1mA== 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=WqmvM9N70HVzTEu0CvbsGBGn1/4vSMDbZNuUPp+1PA8=; b=xqEih8EByVDqXRCDhylF61oyizKb6x7DCGFxH0JRflUwNEHPOL4Jle6rrhZpo5jR1O CtwcFdEjRxRxuk0rSJGaFzGyaYdw52TAJBh4eN0NCgZVpHIr1/IDut1TOUjL24/8G31Q O7OxYVNNxLsAy58wF4bML3nA4EZ2u978mWaMthGWKI71C2F2HYnzJMGQYXf0INVj0xyy qpT4E0hhsUyf4m/q5SsA5+yFT4FN6urSKbhS/8iyZlPSJCB2/eCXGDlkj/pEfl6NxJ3b Xu4YwTqZz60CUxb/4c7OH32KqRBAAgGTYJjOMUusqfTbXb7k+OzbZQ2qppH7QjVmCu9l bGEw== X-Gm-Message-State: AOAM531lNsYkaMN6Lq/580Cn+A6fHD7p4ZeDsI/JHajl8tbYr6xvVFi8 klG1mm4+VMhx6fmSzhWtFJFR33FjIidA X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:fe85:5e36:cb6f:76bc]) (user=irogers job=sendgmr) by 2002:a05:622a:295:: with SMTP id z21mr6540994qtw.125.1633625854072; Thu, 07 Oct 2021 09:57:34 -0700 (PDT) Date: Thu, 7 Oct 2021 09:56:28 -0700 In-Reply-To: <20211007165647.3514803-1-irogers@google.com> Message-Id: <20211007165647.3514803-3-irogers@google.com> Mime-Version: 1.0 References: <20211007165647.3514803-1-irogers@google.com> X-Mailer: git-send-email 2.33.0.882.g93a45727a2-goog Subject: [PATCH 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 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. Signed-off-by: Ian Rogers --- 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 ++-- 10 files changed, 35 insertions(+), 35 deletions(-) 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.882.g93a45727a2-goog