From patchwork Thu Dec 23 07:44:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12697981 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 7F325C433EF for ; Thu, 23 Dec 2021 07:48:50 +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=MLjl+eqgLhw1xuD8G2HyObaHoR89/WGl3iOg6LbLejE=; b=t8gf5a/LNkiUIiMLJhj4kJdUS3 lFnDjgPV4iMyNu23ZzXknF0cKei4rirNTbfdr41uC9nZawD5M/vVSTLZ1mRRdvru3wIXSPvIrq6IT L/UzwHviHY5MDkdaCa/APisHTeyBC4UadKOLn2ZFN8f8i/i03YnhOMDiFRX35q5UQm5UR4q/SdCwp H/HfgMjN12FK6VsDgpV4UQoTaLe5xPGfawqf2wGjyiN3xRVtedkOVwHtU0BsIdOz11GMhml1nzhRD RNqhCZ5Q6XJmTiTJGh79OWE8zA6sq2MO59lMS9Dhh60zb+hRJcGiJ+65Wpzc6Qzg5Mk6pvUvuGy5N A/C88q7A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n0Ioc-00BznD-K0; Thu, 23 Dec 2021 07:47:07 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n0Inr-00BzPH-Gi for linux-arm-kernel@lists.infradead.org; Thu, 23 Dec 2021 07:46:21 +0000 Received: by mail-yb1-xb49.google.com with SMTP id g36-20020a25ae64000000b005c1f46f7ee6so8747839ybe.8 for ; Wed, 22 Dec 2021 23:46:18 -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=KB4ymq594wnrj0TjDKrBcXeqxzyza4tPwUh3PAEieIg=; b=gLzLTCVyuRpNP+y5hYI1ckNpuuCB3iXC+5EVTdqp03PKNGOk5Vnz7pHdunasKhnRoq uKFiPcFa44fvKihYAmTK6OJz3dF6FVfC5d0ISNVA7kPaOYteQGZGXRG/aHNerRPStzKu dHbga4i/MhbpddE0DbPARDspWrRFIbIQFW1nkBUu0jFrKMCLhqe4jUKDh9QOFMLvBD6b 4myCpp3acrjGfWFJGWd12AwOSZqka3rohXQONPPaciUNjScfg7R/WO0AFFbbpU/xZX6T RNAICCQ5s0hRkhPSYapD9jZnmUQnF7QHEQGAy390qEG3HZvR6PIrBBQHX5RxjjbZuez2 at4w== 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=KB4ymq594wnrj0TjDKrBcXeqxzyza4tPwUh3PAEieIg=; b=XvSOExJtMuDK4n6C6YL9H9Jh73o4XHu5/7EPbauOZkInWvu0BBApkR4HJIjs1yGPew lXieoqF4TyBUFbCpqknxl0Y/zSIR8PF1z8QgwQwLybXPZUfpbBAk2FfykBZqFg6/bD5s 1oC9jlVpFcPzCDuusxm2m63ScZS9EkBk7SqLdzziweLBEy/Vn1cQYez/KkvoDCCKe1Zn mt2Z4sl85PaSMARJxd4IB/EvsvnCewAk7bypZhzCc2msup/6RN6INfxxK0bVJzlWYJ9O NWiHqjfjNvK3anskY6OB20iK0zxMZtAUmsvAb6zRMMed890IjjYxMTmw9I4Oo1XJUxCE 2fQw== X-Gm-Message-State: AOAM533kTdCVJV0lsxEix+Xl3DKss31CCLFFzvpBXZuu39urGjXnD7QF eb22w51rPgCmP9FOUbBDqk59ajDigRbG X-Google-Smtp-Source: ABdhPJzIjJYNYiimurAGeGtkdiiWCY0XDEroIInYLWDQe+2ftdVyqn5oGH7ooFmQvoGPK643H7T/CMXAVV1f X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a05:6902:110d:: with SMTP id o13mr1698978ybu.715.1640245577953; Wed, 22 Dec 2021 23:46:17 -0800 (PST) Date: Wed, 22 Dec 2021 23:44:57 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-5-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 04/48] perf stat: Switch aggregation to use for_each loop 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_234619_604036_BAFEF559 X-CRM114-Status: GOOD ( 17.13 ) 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 Tidy up the use of cpu and index to hopefully make the code less error prone. Avoid unused warnings with (void) which will be removed in a later patch. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 48 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index b0fa81ffce61..efab39a759ff 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -330,8 +330,8 @@ static void print_metric_header(struct perf_stat_config *config, static int first_shadow_cpu(struct perf_stat_config *config, struct evsel *evsel, struct aggr_cpu_id id) { - struct evlist *evlist = evsel->evlist; - int i; + struct perf_cpu_map *cpus; + int cpu, idx; if (config->aggr_mode == AGGR_NONE) return id.core; @@ -339,14 +339,11 @@ static int first_shadow_cpu(struct perf_stat_config *config, if (!config->aggr_get_id) return 0; - for (i = 0; i < evsel__nr_cpus(evsel); i++) { - int cpu2 = evsel__cpus(evsel)->map[i]; - - if (cpu_map__compare_aggr_cpu_id( - config->aggr_get_id(config, evlist->core.cpus, cpu2), - id)) { - return cpu2; - } + 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)) + return cpu; } return 0; } @@ -516,20 +513,23 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int static void aggr_update_shadow(struct perf_stat_config *config, struct evlist *evlist) { - int cpu, s; + int cpu, idx, s; struct aggr_cpu_id s2, id; u64 val; struct evsel *counter; + struct perf_cpu_map *cpus; for (s = 0; s < config->aggr_map->nr; s++) { id = config->aggr_map->map[s]; evlist__for_each_entry(evlist, counter) { + cpus = evsel__cpus(counter); val = 0; - for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { - s2 = config->aggr_get_id(config, evsel__cpus(counter), cpu); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + (void)cpu; + s2 = config->aggr_get_id(config, cpus, idx); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; - val += perf_counts(counter->counts, cpu, 0)->val; + val += perf_counts(counter->counts, idx, 0)->val; } perf_stat__update_shadow_stats(counter, val, first_shadow_cpu(config, counter, id), @@ -634,18 +634,21 @@ static void aggr_cb(struct perf_stat_config *config, struct evsel *counter, void *data, bool first) { struct aggr_data *ad = data; - int cpu; + int idx, cpu; + struct perf_cpu_map *cpus; struct aggr_cpu_id s2; - for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { + cpus = evsel__cpus(counter); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { struct perf_counts_values *counts; - s2 = config->aggr_get_id(config, evsel__cpus(counter), cpu); + (void)cpu; + s2 = config->aggr_get_id(config, cpus, idx); if (!cpu_map__compare_aggr_cpu_id(s2, ad->id)) continue; if (first) ad->nr++; - counts = perf_counts(counter->counts, cpu, 0); + counts = perf_counts(counter->counts, idx, 0); /* * When any result is bad, make them all to give * consistent output in interval mode. @@ -1208,10 +1211,13 @@ static void print_percore_thread(struct perf_stat_config *config, { int s; struct aggr_cpu_id s2, id; + struct perf_cpu_map *cpus; bool first = true; + int idx, cpu; - for (int i = 0; i < evsel__nr_cpus(counter); i++) { - s2 = config->aggr_get_id(config, evsel__cpus(counter), i); + cpus = evsel__cpus(counter); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + s2 = config->aggr_get_id(config, cpus, idx); for (s = 0; s < config->aggr_map->nr; s++) { id = config->aggr_map->map[s]; if (cpu_map__compare_aggr_cpu_id(s2, id)) @@ -1220,7 +1226,7 @@ static void print_percore_thread(struct perf_stat_config *config, print_counter_aggrdata(config, counter, s, prefix, false, - &first, i); + &first, cpu); } }