From patchwork Thu Dec 23 07:44:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12697982 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id E861AC433F5 for ; Thu, 23 Dec 2021 07:49:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=CsbPRUQlkUhTyiBl33BctY+VBpOnhsY+wjWoEPs1VCo=; b=w3V2uMmzhJcg1VVu6YppT4rk0V 7U76hV7Q53xryMIXd0O8bIBwMGMvmC+CfXhMVDbj8Jq2KfOL3w25j/g0EWWF24eHGn8FJH47lhBU3 pRCYEhno500MOBnc1ORgE7OaUNFGKLj+2v4Vqrgw2oR2swLJS3yMzaaec20fornZTNlIRvPVT0q0Z TsbCU7RI+nkJ6jKz5K3AKEiai9J4OtHNzq5prZ61iNRdnauBHPLDQ+EvWddZ0lF0N4OrH5YTV2CKW T2VXCYrSrcZusDNOMLu6v7bONO9GI7L7mB1tUndLvHe8LnbUhwV4laGYjbwi/vZBAsrbGGhMmcfNk P3eS+dZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n0Ipd-00C0G0-EL; Thu, 23 Dec 2021 07:48:12 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n0Inu-00BzQP-2F for linux-arm-kernel@lists.infradead.org; Thu, 23 Dec 2021 07:46:24 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id y125-20020a25dc83000000b005c2326bf744so8486812ybe.21 for ; Wed, 22 Dec 2021 23:46:21 -0800 (PST) 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=jtnhIQvDDKagT6wtjqGmg+dssS1Yps+94alfifa67bE=; b=HI2QpkfyFILczZpA4tqxqS7lPqo2sm8ZCR/luL7dfWAsLO4/MvoaVKn4VhL0I4cqHJ mvlLB0byooGjlOef4UfPcQuR7MOoqFI32W705cdiMfM8qv3NMblbjCnnsqsFBbyU06Fb d5yXZZWtxboFZuVKdXZc14aMubr49tFNPAw63BsTD2NCoso+om7iMffZAGykvM6DYNGm JAQRQBo7srMzDjfhsWkbi0umzFoHD8DrmYfOH3Dx30HDaHSyglXkEfBocfkNBCDoZVlk 4o/L3e7nEuizDr4w4LJQwdiICsFctA/Q5bboD3writt4qBfnIhG3+M01RewZ3xnhvBA1 vhFw== 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=jtnhIQvDDKagT6wtjqGmg+dssS1Yps+94alfifa67bE=; b=AtcUPCcv7gzz6qqlh1a7KaWfxX9LP8xHGqc+Mjf1o8VsDGHbwsCBtkk6pw1f/WLxJx VtxHvqZxYKSmQ01SYaiiPRloBpC0U/OYH1t9Iavef1LemezMNFNzo39JeAx8ggfPDncg gQLR6gWfFGT7opU2w69YGfnnJe4HQ2ZZcy/wi5s7h86Hm8cYDVi8fcGYfklug9nJrYxR LCpRxwnq1DYyNwjeOLSu69oMZc4ixDjK9PV5VhTkspMl8dMjqPA47PMww77KP05NNRqW oLVFgEbLqc5rWnv3WzWrfqtwkqwowotPHOOfjl9rr8p8KLAPLu4SLYeSznx9mNRgr89d 2NMA== X-Gm-Message-State: AOAM530w8N+6szXA65uSf8fnLKy/mIS+AJx+D92hV9am0UoR9ikNuFvK eZWWLmkVCwT1S7cC5BafGbiAmzwWW2ah X-Google-Smtp-Source: ABdhPJzKsPPHSyx0u6muu+CQhXSCxonAMxh9VR8DG18ZP+26Ro4Iy09Sfpe3qaB9g17rhzJBSNEQGZfvcWA8 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:8607:: with SMTP id y7mr1775558ybk.283.1640245580500; Wed, 22 Dec 2021 23:46:20 -0800 (PST) Date: Wed, 22 Dec 2021 23:44:58 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-6-irogers@google.com> Mime-Version: 1.0 References: <20211223074541.3318938-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.307.g9b7440fafd-goog Subject: [PATCH v2 05/48] perf stat: Switch to cpu version of cpu_map__get From: Ian Rogers To: Andi Kleen , Jiri Olsa , 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 , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Vineet Singh , James Clark , Mathieu Poirier , Suzuki K Poulose , Mike Leach , Leo Yan , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211222_234622_170389_3E6B1723 X-CRM114-Status: GOOD ( 16.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Avoid bugs where the wrong index is passed with the cpu_map. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 93 +++++++++++++++++++--------------- tools/perf/util/stat-display.c | 11 ++-- tools/perf/util/stat.h | 3 +- 3 files changed, 57 insertions(+), 50 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index f6ca2b054c5b..9791ae9b1a53 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1323,69 +1323,63 @@ static struct option stat_options[] = { }; static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_socket(map, cpu, NULL); + return cpu_map__get_socket_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_die(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_die(map, cpu, NULL); + return cpu_map__get_die_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_core(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_core(map, cpu, NULL); + return cpu_map__get_core_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_node(map, cpu, NULL); + return cpu_map__get_node_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, - aggr_get_id_t get_id, struct perf_cpu_map *map, int idx) + aggr_get_id_t get_id, int cpu) { - int cpu; struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - if (idx >= map->nr) - return id; - - cpu = map->map[idx]; - if (cpu_map__aggr_cpu_id_is_empty(config->cpus_aggr_map->map[cpu])) - config->cpus_aggr_map->map[cpu] = get_id(config, map, idx); + config->cpus_aggr_map->map[cpu] = get_id(config, cpu); id = config->cpus_aggr_map->map[cpu]; return id; } static struct aggr_cpu_id perf_stat__get_socket_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_socket, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_socket, cpu); } static struct aggr_cpu_id perf_stat__get_die_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_die, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_die, cpu); } static struct aggr_cpu_id perf_stat__get_core_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_core, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_core, cpu); } static struct aggr_cpu_id perf_stat__get_node_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_node, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_node, cpu); } static bool term_percore_set(void) @@ -1483,8 +1477,9 @@ static void perf_stat__exit_aggr_mode(void) stat_config.cpus_aggr_map = NULL; } -static inline int perf_env__get_cpu(struct perf_env *env, struct perf_cpu_map *map, int idx) +static inline int perf_env__get_cpu(void *data, struct perf_cpu_map *map, int idx) { + struct perf_env *env = data; int cpu; if (idx > map->nr) @@ -1498,10 +1493,9 @@ static inline int perf_env__get_cpu(struct perf_env *env, struct perf_cpu_map *m return cpu; } -static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; - int cpu = perf_env__get_cpu(env, map, idx); struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); if (cpu != -1) @@ -1510,11 +1504,15 @@ static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, int idx return id; } -static struct aggr_cpu_id perf_env__get_die(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_socket_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + +static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - int cpu = perf_env__get_cpu(env, map, idx); if (cpu != -1) { /* @@ -1529,11 +1527,15 @@ static struct aggr_cpu_id perf_env__get_die(struct perf_cpu_map *map, int idx, v return id; } -static struct aggr_cpu_id perf_env__get_core(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_die(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_die_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + +static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - int cpu = perf_env__get_cpu(env, map, idx); if (cpu != -1) { /* @@ -1549,15 +1551,24 @@ static struct aggr_cpu_id perf_env__get_core(struct perf_cpu_map *map, int idx, return id; } -static struct aggr_cpu_id perf_env__get_node(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_core(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_core_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + +static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) { - int cpu = perf_env__get_cpu(data, map, idx); struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); id.node = perf_env__numa_node(data, cpu); return id; } +static struct aggr_cpu_id perf_env__get_node(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_node_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + static int perf_env__build_socket_map(struct perf_env *env, struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp) { @@ -1583,26 +1594,26 @@ static int perf_env__build_node_map(struct perf_env *env, struct perf_cpu_map *c } static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_socket(map, idx, &perf_stat.session->header.env); + return perf_env__get_socket_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_die_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_die(map, idx, &perf_stat.session->header.env); + return perf_env__get_die_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_core_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_core(map, idx, &perf_stat.session->header.env); + return perf_env__get_core_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_node(map, idx, &perf_stat.session->header.env); + return perf_env__get_node_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static int perf_stat_init_aggr_mode_file(struct perf_stat *st) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index efab39a759ff..6c40b91d5e32 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -341,8 +341,7 @@ static int first_shadow_cpu(struct perf_stat_config *config, cpus = evsel__cpus(evsel); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - if (cpu_map__compare_aggr_cpu_id(config->aggr_get_id(config, cpus, idx), - id)) + if (cpu_map__compare_aggr_cpu_id(config->aggr_get_id(config, cpu), id)) return cpu; } return 0; @@ -525,8 +524,7 @@ static void aggr_update_shadow(struct perf_stat_config *config, cpus = evsel__cpus(counter); val = 0; perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - (void)cpu; - s2 = config->aggr_get_id(config, cpus, idx); + s2 = config->aggr_get_id(config, cpu); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; val += perf_counts(counter->counts, idx, 0)->val; @@ -642,8 +640,7 @@ static void aggr_cb(struct perf_stat_config *config, perf_cpu_map__for_each_cpu(cpu, idx, cpus) { struct perf_counts_values *counts; - (void)cpu; - s2 = config->aggr_get_id(config, cpus, idx); + s2 = config->aggr_get_id(config, cpu); if (!cpu_map__compare_aggr_cpu_id(s2, ad->id)) continue; if (first) @@ -1217,7 +1214,7 @@ static void print_percore_thread(struct perf_stat_config *config, cpus = evsel__cpus(counter); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - s2 = config->aggr_get_id(config, cpus, idx); + s2 = config->aggr_get_id(config, cpu); for (s = 0; s < config->aggr_map->nr; s++) { id = config->aggr_map->map[s]; if (cpu_map__compare_aggr_cpu_id(s2, id)) diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 32c8527de347..32cf24186229 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -108,8 +108,7 @@ struct runtime_stat { struct rblist value_list; }; -typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, - struct perf_cpu_map *m, int cpu); +typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, int cpu); struct perf_stat_config { enum aggr_mode aggr_mode;