From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBCBFC433FE for ; Thu, 23 Dec 2021 07:46:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346909AbhLWHqN (ORCPT ); Thu, 23 Dec 2021 02:46:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346897AbhLWHqL (ORCPT ); Thu, 23 Dec 2021 02:46:11 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 646A5C061401 for ; Wed, 22 Dec 2021 23:46:11 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id j18-20020a258152000000b006000d292a42so8794408ybm.0 for ; Wed, 22 Dec 2021 23:46:11 -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=88O+wwMIUMjGSp8vBh5a99/6nPbt91KU3ZoFuApgaYM=; b=kkIK6Jg8+WpZYmng3joQ3qp7DcIRoNBjVuzHPir6XhEiQ2dPDMf24HdOEIFj3H32O9 iAV59G2dqE3olG8dUf/LvN+WWu5yfgmfxfZ8dbpDvAH7gRDurmrARUNNtzzHoYMTKDHK bvm6ebVeuPWxP3qt1IWSHXjt2CEDs3rvibkZprdo+h54jN0UFejfqm5XnZ+hkM1CkKv2 Aoktcu01x4wkJ/4Owe/c+dJR8ZrXFc6418v3JO03Rj7gytXcvJSbvaCIZoOPzWUI/gpf kRnd7H+McfkEgdyWEtX5i7mcPvrtbLMMXFDUopiv4D9nLN6qYz+mknTdUvJhu1Mh6yxE dorQ== 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=88O+wwMIUMjGSp8vBh5a99/6nPbt91KU3ZoFuApgaYM=; b=mCdHlBV8QSaKMIR7Ifqp+0IXL7C9X1WuCwPbj/I9+/60shZ3WcjYPXQT8mcFOc0lE+ OQCmDRZ9zwH0rUxao2XVWFgptAQlFIk7JfTk6787DGX6sFBvZoofH7i861wW+he9YErw 4aWo5E4CtJwn/WJQEa7KDgIkHMFYw1jDxTZOylBWyV0UG387h9DRZqKtI108Dt2ldkgy +fVhRTjeYJeJVSNw1i6AniAmnwsxJhNRbQlaMLNT3emDpVoy8Mvv4uRxGazicIw8ql74 2yat87PTbK3pfCJ4xAwp67/7FpocKFxLxSeh7SWSQJqPgKmGYVTbCqExvh+p4k5QV4u/ x2XA== X-Gm-Message-State: AOAM530ziEPW8Ql2UB60WCFbyOnpseyoUuqDf6k/2epJhVIx9jNMtOl5 LKlfQ7MqAsCK/wNcaGNwttFVNYs9lHkS X-Google-Smtp-Source: ABdhPJzjEgbayUhuRxq6Yf8H4X/kehgDmv/v3Teayg7xc+3ZCMqY4PFVtePthRhrD2JiHRScvPQB4dR3Qvxm X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:d984:: with SMTP id q126mr1810815ybg.392.1640245570595; Wed, 22 Dec 2021 23:46:10 -0800 (PST) Date: Wed, 22 Dec 2021 23:44:54 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-2-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 01/48] libperf: Add comments to perf_cpu_map. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A particular observed problem is confusing the index with the CPU value, documentation should hopefully reduce this type of problem. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/lib/perf/include/internal/cpumap.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/incl= ude/internal/cpumap.h index 840d4032587b..4054169c12c5 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -4,9 +4,18 @@ =20 #include =20 +/** + * A sized, reference counted, sorted array of integers representing CPU + * numbers. This is commonly used to capture which CPUs a PMU is associated + * with. The indices into the cpumap are frequently used as they avoid hav= ing + * gaps if CPU numbers were used. For events associated with a pid, rather= than + * a CPU, a single dummy map with an entry of -1 is used. + */ struct perf_cpu_map { refcount_t refcnt; + /** Length of the map array. */ int nr; + /** The CPU values. */ int map[]; }; =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D78EC433EF for ; Thu, 23 Dec 2021 07:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346948AbhLWHqS (ORCPT ); Thu, 23 Dec 2021 02:46:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346921AbhLWHqO (ORCPT ); Thu, 23 Dec 2021 02:46:14 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0663FC061757 for ; Wed, 22 Dec 2021 23:46:14 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id b15-20020a25ae8f000000b005c20f367790so8721748ybj.2 for ; Wed, 22 Dec 2021 23:46:13 -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=mePtsrhLWgWXoq3H5FC5G2u7jgVyGfpWaebHRXPv2DI=; b=FTYkNk9HVNHs1xEfbvYqkPX6xssmZpi3cZ0WHqSWKB21s3HVQfmvlF8heOT/6l4HD2 1LehHyj97rZLyFKPm96XoRMMAmWwMNgcSLFdBuMqrvl1Cj2jf2hmxGpxlWvZu7glKfVK x5JWt7g/SMGtjCc0NykMn/8x0N/0clU0xYjq58Fk26msBz2LuNf09o36ONzA9zymoWeL Ms9UJpMR5WG++zl76QppjyHOrWf9yTG0OHSktumzzGEyZlbyM5ZJx7WPj3Mxjk1xEvUF W+BGkgtnmyNdS6S+b6XsfbUFluJHlIzIc6okQXXts8VCRrx6NluvqTDuXbb5te087+sv Hwhg== 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=mePtsrhLWgWXoq3H5FC5G2u7jgVyGfpWaebHRXPv2DI=; b=F6ncACRygoSIHkK5VtBQKCX2EG+RrFQIQtwWTt33dNjwLPyhcCjsFSoKylP+6eNHkJ 1Yk3o7ZN2aUPlrgA/MAX4xIY3+vo5fy9dt9KUkeiDLB5HybbixjPNtEVLyfKmVH6Fhsr ac8ZZaoUmrKtRIx6Rl4L69txW4FE+YTgOS+0oegRQCQI5lv0A4wCZRb6Wy6G4s30T50j TzXuDzf3hx8QzPJCcakdOQ2cNAswE7JujqkYRTH2S7mnhAM4kxteCX0rxOHVBCQdxAcT UMd2tKW7KnUPm8pDBjsx25S0KIO09bMDnYobstR++n10EQWiLwgRcmWGY5iOxcCki63U qlsA== X-Gm-Message-State: AOAM531hgkNHlibwFJNY7bW3lYiJIs7UW51nwR0cx2kz+npOiupy4DD6 QTrIgxFrm/yLYsPTTehPE44qmtHoBIs9 X-Google-Smtp-Source: ABdhPJyfXm/WEmuaV+oEkW/4vjSdbjwpUre/bVaKHM2F5bhP4/pnZUgv6GW4xgNxO27nqPXoGMHyY37FQnAD X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:e7c3:: with SMTP id e186mr1656956ybh.97.1640245573221; Wed, 22 Dec 2021 23:46:13 -0800 (PST) Date: Wed, 22 Dec 2021 23:44:55 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-3-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 02/48] perf stat: Add aggr creators that are passed a cpu. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The cpu_map and index can get confused. Add variants of the cpu_map__get routines that are passed a cpu. Make the existing cpu_map__get routines use the new functions with a view to remove them when no longer used. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.c | 79 +++++++++++++++++++++++----------------- tools/perf/util/cpumap.h | 6 ++- 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 87d3eca9b872..49fba2c53822 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -128,21 +128,23 @@ int cpu_map__get_socket_id(int cpu) return ret ?: value; } =20 -struct aggr_cpu_id cpu_map__get_socket(struct perf_cpu_map *map, int idx, - void *data __maybe_unused) +struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data __m= aybe_unused) { - int cpu; struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); =20 - if (idx > map->nr) - return id; - - cpu =3D map->map[idx]; - id.socket =3D cpu_map__get_socket_id(cpu); return id; } =20 +struct aggr_cpu_id cpu_map__get_socket(struct perf_cpu_map *map, int idx, + void *data) +{ + if (idx < 0 || idx > map->nr) + return cpu_map__empty_aggr_cpu_id(); + + return cpu_map__get_socket_aggr_by_cpu(map->map[idx], data); +} + static int cmp_aggr_cpu_id(const void *a_pointer, const void *b_pointer) { struct aggr_cpu_id *a =3D (struct aggr_cpu_id *)a_pointer; @@ -200,15 +202,10 @@ int cpu_map__get_die_id(int cpu) return ret ?: value; } =20 -struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, voi= d *data) +struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data) { - int cpu, die; - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); - - if (idx > map->nr) - return id; - - cpu =3D map->map[idx]; + struct aggr_cpu_id id; + int die; =20 die =3D cpu_map__get_die_id(cpu); /* There is no die_id on legacy system. */ @@ -220,7 +217,7 @@ struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map= *map, int idx, void *dat * with the socket ID and then add die to * make a unique ID. */ - id =3D cpu_map__get_socket(map, idx, data); + id =3D cpu_map__get_socket_aggr_by_cpu(cpu, data); if (cpu_map__aggr_cpu_id_is_empty(id)) return id; =20 @@ -228,6 +225,15 @@ struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_ma= p *map, int idx, void *dat return id; } =20 +struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, + void *data) +{ + if (idx < 0 || idx > map->nr) + return cpu_map__empty_aggr_cpu_id(); + + return cpu_map__get_die_aggr_by_cpu(map->map[idx], data); +} + int cpu_map__get_core_id(int cpu) { int value, ret =3D cpu__get_topology_int(cpu, "core_id", &value); @@ -239,20 +245,13 @@ int cpu_map__get_node_id(int cpu) return cpu__get_node(cpu); } =20 -struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, vo= id *data) +struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data) { - int cpu; - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); - - if (idx > map->nr) - return id; - - cpu =3D map->map[idx]; - - cpu =3D cpu_map__get_core_id(cpu); + struct aggr_cpu_id id; + int core =3D cpu_map__get_core_id(cpu); =20 /* cpu_map__get_die returns a struct with socket and die set*/ - id =3D cpu_map__get_die(map, idx, data); + id =3D cpu_map__get_die_aggr_by_cpu(cpu, data); if (cpu_map__aggr_cpu_id_is_empty(id)) return id; =20 @@ -260,19 +259,33 @@ struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_= map *map, int idx, void *da * core_id is relative to socket and die, we need a global id. * So we combine the result from cpu_map__get_die with the core id */ - id.core =3D cpu; + id.core =3D core; return id; + } =20 -struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, vo= id *data __maybe_unused) +struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, vo= id *data) +{ + if (idx < 0 || idx > map->nr) + return cpu_map__empty_aggr_cpu_id(); + + return cpu_map__get_core_aggr_by_cpu(map->map[idx], data); +} + +struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data __may= be_unused) { struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); =20 + id.node =3D cpu_map__get_node_id(cpu); + return id; +} + +struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, vo= id *data) +{ if (idx < 0 || idx >=3D map->nr) - return id; + return cpu_map__empty_aggr_cpu_id(); =20 - id.node =3D cpu_map__get_node_id(map->map[idx]); - return id; + return cpu_map__get_node_aggr_by_cpu(map->map[idx], data); } =20 int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp) diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index a27eeaf086e8..c62d67704425 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -31,13 +31,17 @@ size_t cpu_map__snprint(struct perf_cpu_map *map, char = *buf, size_t size); size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t s= ize); size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); int cpu_map__get_socket_id(int cpu); +struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_socket(struct perf_cpu_map *map, int idx, = void *data); int cpu_map__get_die_id(int cpu); +struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, voi= d *data); int cpu_map__get_core_id(int cpu); +struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, vo= id *data); int cpu_map__get_node_id(int cpu); -struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, v= oid *data); +struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); +struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, vo= id *data); int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp); int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map = **diep); int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **corep); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7459C433F5 for ; Thu, 23 Dec 2021 07:46:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346964AbhLWHqU (ORCPT ); Thu, 23 Dec 2021 02:46:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346946AbhLWHqR (ORCPT ); Thu, 23 Dec 2021 02:46:17 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82888C06175C for ; Wed, 22 Dec 2021 23:46:16 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id i187-20020a2522c4000000b006093b616e65so8614607ybi.17 for ; Wed, 22 Dec 2021 23:46:16 -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=jOgZ+dsJ80gHSAYy1PEpxKlsT1rqOZcGXpM1p4DxDhE=; b=ALf5lK2Ov9iU0BCplEQ5qzLZD7goP9VK6FnyebpGcOLPQu3jXAT/OSi3DRcgeN1fco jwkPOMuiD1cTWg2Ad0l2cmneh3EFHLIOv69P162DKV7OWumzO8IsF2aAr6to7l7qZnPe 6XnF1x6GRmW2GIcUd75SIUH/pyZ0pm+Y+TFkldWmTVIJ60iz+T1Ywc4wb7nHTSYmaAad 1zFjWy9/eBiWNX2hjiHlYE/vCmM2q3qcYrdnBD9R/En8VltJoH7wN2kjCIdAFIOxKrYp +bZyXBaC8R8aY3bPJWxaIuQfcRZPwz14V5P9VKxfa4jrg0CzPjtuf0cqebNdgcYHTq5H 73wg== 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=jOgZ+dsJ80gHSAYy1PEpxKlsT1rqOZcGXpM1p4DxDhE=; b=VzM5hFRSq2eWMkgvfAK/HN3ua7Ge9FbgR9C96fOFEBea3zDTffFe/SPnXe/5sDpTBi COu01R5PFdP5UF/esVOVqtvbLdibbbOeu7/cPv0fRxYuLYNDAHwnlW52AFJgNWND130y 7fgLyWl1UMd56A9f02unOHUjV1g77ujZtytv2zXQfK/JW19XOS1fLcN0T83FR5YzW9fk PUYXPgHeH2bP0HcQVFfoucVOwxXYDQUdeDjIry9IL2N//DjTK4+Ab4MMUWOCzxvBQZ3+ vPTJe34zkJv0lzW7dF4oWFs3LS//mtq2bFV+FJWBZn3VXw17MtJxuMr053TVKUBVEmir h2Hw== X-Gm-Message-State: AOAM530U4NLUIdAeCeoZVbaOhCnTL0be9zApxyJmznOb9dEdkn13wJS3 cvtoOwUqEFOFjFPopnDK2jrm0pbagqbA X-Google-Smtp-Source: ABdhPJxfqk1AW2t7CvhGLgWlWdGHvdajhUDHd3O9XpcDl32AG8vbZ3Z1T8RUrnMO7UiDO8j9a3C8qoAvj20/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:bfd2:: with SMTP id q18mr1882341ybm.542.1640245575752; Wed, 22 Dec 2021 23:46:15 -0800 (PST) Date: Wed, 22 Dec 2021 23:44:56 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-4-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 03/48] perf stat: Correct aggregation CPU map 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch the perf_cpu_map in aggr_update_shadow from the evlist to the counter's cpu map, so the index is appropriate. This addresses a problem where uncore counts, with a cpumap like: $ cat /sys/devices/uncore_imc_0/cpumask 0,18 Don't aggregate counts in CPUs based on the index of those values in the cpumap (0 and 1) but on the actual CPU (0 and 18). Thereby correcting metric calculations in per-socket mode for counters without a full cpumask. On a SkylakeX with a tweaked DRAM_BW_Use metric, to remove unnecessary scaling, this gives: Before: $ /perf stat --per-socket -M DRAM_BW_Use -I 1000 1.001102293 S0 1 27.01 MiB uncore_imc/cas_count_w= rite/ # 103.00 DRAM_BW_Use 1.001102293 S0 1 30.22 MiB uncore_imc/cas_count_r= ead/ 1.001102293 S0 1 1,001,102,293 ns duration_time 1.001102293 S1 1 20.10 MiB uncore_imc/cas_count_w= rite/ # 0.00 DRAM_BW_Use 1.001102293 S1 1 32.74 MiB uncore_imc/cas_count_r= ead/ 1.001102293 S1 0 ns duration_time 2.003517973 S0 1 83.04 MiB uncore_imc/cas_count_w= rite/ # 920.00 DRAM_BW_Use 2.003517973 S0 1 145.95 MiB uncore_imc/cas_count_r= ead/ 2.003517973 S0 1 1,002,415,680 ns duration_time 2.003517973 S1 1 302.45 MiB uncore_imc/cas_count_w= rite/ # 0.00 DRAM_BW_Use 2.003517973 S1 1 290.99 MiB uncore_imc/cas_count_r= ead/ 2.003517973 S1 0 ns duration_time After: $ perf stat --per-socket -M DRAM_BW_Use -I 1000 1.001080840 S0 1 24.96 MiB uncore_imc/cas_count_w= rite/ # 54.00 DRAM_BW_Use 1.001080840 S0 1 33.64 MiB uncore_imc/cas_count_r= ead/ 1.001080840 S0 1 1,001,080,840 ns duration_time 1.001080840 S1 1 42.43 MiB uncore_imc/cas_count_w= rite/ # 84.00 DRAM_BW_Use 1.001080840 S1 1 47.05 MiB uncore_imc/cas_count_r= ead/ 1.001080840 S1 0 ns duration_time Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 588601000f3f..b0fa81ffce61 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -526,7 +526,7 @@ static void aggr_update_shadow(struct perf_stat_config = *config, evlist__for_each_entry(evlist, counter) { val =3D 0; for (cpu =3D 0; cpu < evsel__nr_cpus(counter); cpu++) { - s2 =3D config->aggr_get_id(config, evlist->core.cpus, cpu); + s2 =3D config->aggr_get_id(config, evsel__cpus(counter), cpu); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; val +=3D perf_counts(counter->counts, cpu, 0)->val; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DA9BC433FE for ; Thu, 23 Dec 2021 07:46:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346978AbhLWHqW (ORCPT ); Thu, 23 Dec 2021 02:46:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346922AbhLWHqS (ORCPT ); Thu, 23 Dec 2021 02:46:18 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AC825C061401 for ; Wed, 22 Dec 2021 23:46:18 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id e131-20020a25d389000000b005fb5e6eb757so8556204ybf.22 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=BRM8AdX588SVEYhTe2itWKWQVxjVgZ8aBfeVNKQNmADCzuzxLFquJAlvExXSVjmQzC tGX99KvdS/myET2KxYruucmvWENsVleeS0G6qEWehPmOnx6hA3yEokoiayRBuiddhiGk eosMdQtvQ5p2m15ilF7KNvtFFMSUU8VMeGOnDDEkvuGeX41Pu/cN8Elngt9qGwzl2A5p bw1du3er2BHd2SPTAati6Cc2T4+ltua3yZXUXUiEQDxSXuRfZnTI9ADZpm0zBliegArw Z5y9gs+pyiQTfCCO87IytZQ+LrEsByWdDK+BrMAnwLd35OKaxKp9/vcWlq/PgO1vW4AZ GNrg== X-Gm-Message-State: AOAM531AJSCj5EDj2RcPgxDRzY5YgcnAJ/q/Sr0hEFo15i53KQin2kz6 v+dTJUSvM0uDEvt9WF+SmVOb1g/CRNQs 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 =3D evsel->evlist; - int i; + struct perf_cpu_map *cpus; + int cpu, idx; =20 if (config->aggr_mode =3D=3D 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; =20 - for (i =3D 0; i < evsel__nr_cpus(evsel); i++) { - int cpu2 =3D 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 =3D 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; =20 for (s =3D 0; s < config->aggr_map->nr; s++) { id =3D config->aggr_map->map[s]; evlist__for_each_entry(evlist, counter) { + cpus =3D evsel__cpus(counter); val =3D 0; - for (cpu =3D 0; cpu < evsel__nr_cpus(counter); cpu++) { - s2 =3D config->aggr_get_id(config, evsel__cpus(counter), cpu); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + (void)cpu; + s2 =3D config->aggr_get_id(config, cpus, idx); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; - val +=3D perf_counts(counter->counts, cpu, 0)->val; + val +=3D 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 =3D data; - int cpu; + int idx, cpu; + struct perf_cpu_map *cpus; struct aggr_cpu_id s2; =20 - for (cpu =3D 0; cpu < evsel__nr_cpus(counter); cpu++) { + cpus =3D evsel__cpus(counter); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { struct perf_counts_values *counts; =20 - s2 =3D config->aggr_get_id(config, evsel__cpus(counter), cpu); + (void)cpu; + s2 =3D config->aggr_get_id(config, cpus, idx); if (!cpu_map__compare_aggr_cpu_id(s2, ad->id)) continue; if (first) ad->nr++; - counts =3D perf_counts(counter->counts, cpu, 0); + counts =3D 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_c= onfig *config, { int s; struct aggr_cpu_id s2, id; + struct perf_cpu_map *cpus; bool first =3D true; + int idx, cpu; =20 - for (int i =3D 0; i < evsel__nr_cpus(counter); i++) { - s2 =3D config->aggr_get_id(config, evsel__cpus(counter), i); + cpus =3D evsel__cpus(counter); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + s2 =3D config->aggr_get_id(config, cpus, idx); for (s =3D 0; s < config->aggr_map->nr; s++) { id =3D 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_con= fig *config, =20 print_counter_aggrdata(config, counter, s, prefix, false, - &first, i); + &first, cpu); } } =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB0CCC433FE for ; Thu, 23 Dec 2021 07:46:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346954AbhLWHqY (ORCPT ); Thu, 23 Dec 2021 02:46:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346968AbhLWHqV (ORCPT ); Thu, 23 Dec 2021 02:46:21 -0500 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 42804C06175A for ; Wed, 22 Dec 2021 23:46:21 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id q123-20020a252a81000000b00609e97bb74bso8693256ybq.5 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=Lua5W47oQBx9EQj5x/5Kp4skCajsbTHRMjcMlXyPSM2CcQaFg0FyDI2N3FmkZZhf05 fuTu/oDIdpRK23N7OQuC8PLH9JMHS+rGahQLob8pFUJxvshWc2NJImZ5C5Cv71wblTqs 6FkH+A7kJTTnlyjmmMpoBKXvH6yoX2B3YpHVSrpFXV1084ciy3OwCB6b122AOKMIkJ9n mZO9ixZi3wABJEu49up6CZIe1qr0HJcwlfq65tDTSpe1vTmhe3YIJqYiELqSL7ZdTZxN Skk1YgNTs3SrMiIUV1utojN4vXJc0OJ3t/GJvP4nsH1fpdPUTYmnfWDtREgO8a3QysMN PZhg== X-Gm-Message-State: AOAM530e+/Q0F/dAkHK5sCTnyyPtpzxFHZz7e2mxTa+yGcbSvFHRNDxt NSPJPDPH1P+BlqSNIW6z/FAPFzaVyHLG 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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[] =3D { }; =20 static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *c= onfig __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=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_die(struct perf_stat_config *conf= ig __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=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_core(struct perf_stat_config *con= fig __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=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *con= fig __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=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *con= fig, - 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 =3D cpu_map__empty_aggr_cpu_id(); =20 - if (idx >=3D map->nr) - return id; - - cpu =3D map->map[idx]; - if (cpu_map__aggr_cpu_id_is_empty(config->cpus_aggr_map->map[cpu])) - config->cpus_aggr_map->map[cpu] =3D get_id(config, map, idx); + config->cpus_aggr_map->map[cpu] =3D get_id(config, cpu); =20 id =3D config->cpus_aggr_map->map[cpu]; return id; } =20 static struct aggr_cpu_id perf_stat__get_socket_cached(struct perf_stat_co= nfig *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); } =20 static struct aggr_cpu_id perf_stat__get_die_cached(struct perf_stat_confi= g *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); } =20 static struct aggr_cpu_id perf_stat__get_core_cached(struct perf_stat_conf= ig *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); } =20 static struct aggr_cpu_id perf_stat__get_node_cached(struct perf_stat_conf= ig *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); } =20 static bool term_percore_set(void) @@ -1483,8 +1477,9 @@ static void perf_stat__exit_aggr_mode(void) stat_config.cpus_aggr_map =3D NULL; } =20 -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 =3D data; int cpu; =20 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; } =20 -static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, i= nt idx, void *data) +static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(int cpu, void *= data) { struct perf_env *env =3D data; - int cpu =3D perf_env__get_cpu(env, map, idx); struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); =20 if (cpu !=3D -1) @@ -1510,11 +1504,15 @@ static struct aggr_cpu_id perf_env__get_socket(stru= ct perf_cpu_map *map, int idx return id; } =20 -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, i= nt 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 *dat= a) { struct perf_env *env =3D data; struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); - int cpu =3D perf_env__get_cpu(env, map, idx); =20 if (cpu !=3D -1) { /* @@ -1529,11 +1527,15 @@ static struct aggr_cpu_id perf_env__get_die(struct = perf_cpu_map *map, int idx, v return id; } =20 -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), d= ata); +} + +static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *da= ta) { struct perf_env *env =3D data; struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); - int cpu =3D perf_env__get_cpu(env, map, idx); =20 if (cpu !=3D -1) { /* @@ -1549,15 +1551,24 @@ static struct aggr_cpu_id perf_env__get_core(struct= perf_cpu_map *map, int idx, return id; } =20 -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 *da= ta) { - int cpu =3D perf_env__get_cpu(data, map, idx); struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); =20 id.node =3D perf_env__numa_node(data, cpu); return id; } =20 +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_cp= u_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 } =20 static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_conf= ig *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.e= nv); } 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); } =20 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= ); } =20 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= ); } =20 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 *co= nfig, =20 cpus =3D 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 =3D evsel__cpus(counter); val =3D 0; perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - (void)cpu; - s2 =3D config->aggr_get_id(config, cpus, idx); + s2 =3D config->aggr_get_id(config, cpu); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; val +=3D 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; =20 - (void)cpu; - s2 =3D config->aggr_get_id(config, cpus, idx); + s2 =3D 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_con= fig *config, =20 cpus =3D evsel__cpus(counter); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - s2 =3D config->aggr_get_id(config, cpus, idx); + s2 =3D config->aggr_get_id(config, cpu); for (s =3D 0; s < config->aggr_map->nr; s++) { id =3D 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; }; =20 -typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *confi= g, - struct perf_cpu_map *m, int cpu); +typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *confi= g, int cpu); =20 struct perf_stat_config { enum aggr_mode aggr_mode; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C488FC433F5 for ; Thu, 23 Dec 2021 07:46:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346981AbhLWHq1 (ORCPT ); Thu, 23 Dec 2021 02:46:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346985AbhLWHqX (ORCPT ); Thu, 23 Dec 2021 02:46:23 -0500 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 734BBC061401 for ; Wed, 22 Dec 2021 23:46:23 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id g36-20020a25ae64000000b005c1f46f7ee6so8748148ybe.8 for ; Wed, 22 Dec 2021 23:46:23 -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=n0dEWZPTqb+S0pWa6wTVizZO8NEoLxYxvxJfIHMbS/U=; b=btq3RWNbpndjsgIOvBErrP3PHawbbLObRJa0DY/38ExCcxeDufdJRAe2TC7MAjkcaA YuObOtjjZk6loQwR8eaa+Ivk4Ue431uYQ8gpO6hnkKLNZZerfLbOuvwSlPia6/yw6C3/ qaMzmRvJ7awM5GGcuqMmsmO7F0HCS+idM6UT8Zb5C6oaZlUlD4LiC27nxhOqYZfm/LCq cfRGuWQ1yDR/xJyWuPevvdDRcxYFTfMJjGpQXqvqsvfTttlvKAkJ0b/efz9FcotFGsag GGBtV/g3DIqmqVl5jGOCCljzrSJPC5iBKE5bgNUAmR1oQy1or7fT4uemK3Ql71A6ADvl f1pQ== 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=n0dEWZPTqb+S0pWa6wTVizZO8NEoLxYxvxJfIHMbS/U=; b=bNZ8z9tx87pfqvPaHBtgS+nGKBdT8CNouToQRUlK35lOMo2TAcCJ0+Rw/gZ0hIe7/2 Up0AsQGuxeyloC8VtPAY2JYNFO7H4bOzJeSLmI+pXYtfsDyJKaaJXe27m9/4pPw/ZLdZ i0rYUa9eInFAOgXRiYWM2kkPEc16QONrLttqT6do1ytmPcVgtKvaNtyYMUMbh/dOn5Qz AeIR9AuIStHWveGsKnK8giEoBvc4Am5+hcpqQzp6m62rb2CHspeVT+5BXNJrcDPeTJyG Rmd9BKB9O6/12C+k2CFHNJbWvBu+slAh+Q7Phmatsb7jwArlTIvdBnnpwXql0TdyjPnH ZWCA== X-Gm-Message-State: AOAM532YI/bBsxfRX8FzXbLT2bKpV6ot/8UfwHdTyPTo4K37LECfLsav wlINPO6HZ9EXAMQYO9cRg38ANeBe+rrV X-Google-Smtp-Source: ABdhPJyfhg1rzaXCzlRw/tc0OBXQHu/3eLWhfN5LPpH7NAdg4kZGqvgjSa59t1ZUz+Aj0iATlFRmLZnOqipl X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:418f:: with SMTP id o137mr1813615yba.154.1640245582689; Wed, 22 Dec 2021 23:46:22 -0800 (PST) Date: Wed, 22 Dec 2021 23:44:59 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-7-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 06/48] perf cpumap: Switch cpu_map__build_map to cpu function 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Avoid error prone cpu_map + idx variant. Remove now unused functions. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 28 ++++------------------------ tools/perf/util/cpumap.c | 12 ++++++------ tools/perf/util/cpumap.h | 2 +- 3 files changed, 11 insertions(+), 31 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 9791ae9b1a53..6b985abaa2d2 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1504,11 +1504,6 @@ static struct aggr_cpu_id perf_env__get_socket_aggr_= by_cpu(int cpu, void *data) return id; } =20 -static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, i= nt 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 *dat= a) { struct perf_env *env =3D data; @@ -1527,11 +1522,6 @@ static struct aggr_cpu_id perf_env__get_die_aggr_by_= cpu(int cpu, void *data) return id; } =20 -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), d= ata); -} - static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *da= ta) { struct perf_env *env =3D data; @@ -1551,11 +1541,6 @@ static struct aggr_cpu_id perf_env__get_core_aggr_by= _cpu(int cpu, void *data) return id; } =20 -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 *da= ta) { struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); @@ -1564,33 +1549,28 @@ static struct aggr_cpu_id perf_env__get_node_aggr_b= y_cpu(int cpu, void *data) return id; } =20 -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_cp= u_map *cpus, struct cpu_aggr_map **sockp) { - return cpu_map__build_map(cpus, sockp, perf_env__get_socket, env); + return cpu_map__build_map(cpus, sockp, perf_env__get_socket_aggr_by_cpu, = env); } =20 static int perf_env__build_die_map(struct perf_env *env, struct perf_cpu_m= ap *cpus, struct cpu_aggr_map **diep) { - return cpu_map__build_map(cpus, diep, perf_env__get_die, env); + return cpu_map__build_map(cpus, diep, perf_env__get_die_aggr_by_cpu, env); } =20 static int perf_env__build_core_map(struct perf_env *env, struct perf_cpu_= map *cpus, struct cpu_aggr_map **corep) { - return cpu_map__build_map(cpus, corep, perf_env__get_core, env); + return cpu_map__build_map(cpus, corep, perf_env__get_core_aggr_by_cpu, en= v); } =20 static int perf_env__build_node_map(struct perf_env *env, struct perf_cpu_= map *cpus, struct cpu_aggr_map **nodep) { - return cpu_map__build_map(cpus, nodep, perf_env__get_node, env); + return cpu_map__build_map(cpus, nodep, perf_env__get_node_aggr_by_cpu, en= v); } =20 static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_conf= ig *config __maybe_unused, diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 49fba2c53822..feaf34b25efc 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -163,7 +163,7 @@ static int cmp_aggr_cpu_id(const void *a_pointer, const= void *b_pointer) } =20 int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **re= s, - struct aggr_cpu_id (*f)(struct perf_cpu_map *map, int cpu, void *= data), + struct aggr_cpu_id (*f)(int cpu, void *data), void *data) { int nr =3D cpus->nr; @@ -178,7 +178,7 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struc= t cpu_aggr_map **res, c->nr =3D 0; =20 for (cpu =3D 0; cpu < nr; cpu++) { - s1 =3D f(cpus, cpu, data); + s1 =3D f(cpu, data); for (s2 =3D 0; s2 < c->nr; s2++) { if (cpu_map__compare_aggr_cpu_id(s1, c->map[s2])) break; @@ -290,22 +290,22 @@ struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_= map *map, int idx, void *da =20 int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp) { - return cpu_map__build_map(cpus, sockp, cpu_map__get_socket, NULL); + return cpu_map__build_map(cpus, sockp, cpu_map__get_socket_aggr_by_cpu, N= ULL); } =20 int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map = **diep) { - return cpu_map__build_map(cpus, diep, cpu_map__get_die, NULL); + return cpu_map__build_map(cpus, diep, cpu_map__get_die_aggr_by_cpu, NULL); } =20 int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **corep) { - return cpu_map__build_map(cpus, corep, cpu_map__get_core, NULL); + return cpu_map__build_map(cpus, corep, cpu_map__get_core_aggr_by_cpu, NUL= L); } =20 int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **numap) { - return cpu_map__build_map(cpus, numap, cpu_map__get_node, NULL); + return cpu_map__build_map(cpus, numap, cpu_map__get_node_aggr_by_cpu, NUL= L); } =20 /* setup simple routines to easily access node numbers given a cpu number = */ diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index c62d67704425..9648816c4255 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -63,7 +63,7 @@ int cpu__max_present_cpu(void); int cpu__get_node(int cpu); =20 int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **re= s, - struct aggr_cpu_id (*f)(struct perf_cpu_map *map, int cpu, void *= data), + struct aggr_cpu_id (*f)(int cpu, void *data), void *data); =20 int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A19BC433EF for ; Thu, 23 Dec 2021 07:46:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346941AbhLWHqa (ORCPT ); Thu, 23 Dec 2021 02:46:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346970AbhLWHq0 (ORCPT ); Thu, 23 Dec 2021 02:46:26 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F995C061759 for ; Wed, 22 Dec 2021 23:46:26 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id d27-20020a25addb000000b005c2355d9052so8654552ybe.3 for ; Wed, 22 Dec 2021 23:46:26 -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=uVyVqD21U2Soqznhfqq2tSEZ5WG+Ru8TxcMiQZbzBD4=; b=K+hioLFYWxIsTHvDePn3dCFjJ7SmLeflYQmFDXxOQ3TYga15SjzP+3mwkg8gYlY+xw MKDtUFd+0Z3jOMvAo1kXdHZ77m0At1myTt4iEKbGKzNMIfbgu3IPlVJqu1SXiTwdkT2E GdbyWj8MoAC3fVWErY10CAj7BNdmuRyKB670QLUEjX0f9XuUP0gVSli649x5P702cRar 9U82rQQblLXbYrc2/6fkGNfan8w1dV9/rm+39ZIDDSbhi0ulKXh6YX7GXSuxm1KEM5pS DydwdjpBSYybD5OYM54ZY6Ovga01RZXDhwC2/nG61Mb5Ve0+joZW7HsO7jQf5VBWBU/h nx9Q== 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=uVyVqD21U2Soqznhfqq2tSEZ5WG+Ru8TxcMiQZbzBD4=; b=UaBGQ3XFV66BYRajSeovYlcYd6QhVGNE0RqILdOIcb2OuAuqWvhXnsDdlT2hABPqui Q/LKcAMrx6AVYDsRBL+iBy6v3ABM//dfKEl9qdYye9cYF7nsR2mxaMc5NTETA//cL47k tCOt7NbdMaNgHbw1mZ3QwQNcjXs/a/vya9DEjhZ8/0eatcPeaVSeg8AZ0xHeAfpIniiE LDhKXntI4JVLD57uJNuv6X9BbHVEIPGUaoolXaI4mHnaKfldwiqaiW55IOXMqZd/eO71 aPhaxirqrefVsAdCYIkVofqscPHKt1DJyCA7qylQeUACbZX0mxlsgKS2O67S2iUmm8Yi P5yA== X-Gm-Message-State: AOAM530Wuxa3nnzLIYde2VWwKA6my4kxWFZ0pGIejG3JFc7nil8KYAm6 RCcC7bn9vk0XPEJyALgKSXYwaHkKftfI X-Google-Smtp-Source: ABdhPJyJGIW6yzS9rYiVxPItQMeHKyfomy5FZW4D3XI4uf7L/TyXgn8bsy9VPlHhgO/t5iA/Gj+WLYygoMts X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:33d6:: with SMTP id z205mr1633609ybz.36.1640245585299; Wed, 22 Dec 2021 23:46:25 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:00 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-8-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 07/48] perf cpumap: Remove map+index get_socket 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Migrate final users to appropriate cpu variant. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/tests/topology.c | 2 +- tools/perf/util/cpumap.c | 9 --------- tools/perf/util/cpumap.h | 1 - tools/perf/util/stat.c | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 869986139146..69a64074b897 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -150,7 +150,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that socket ID contains only socket for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_socket(map, i, NULL); + id =3D cpu_map__get_socket_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Socket map - Socket ID doesn't match", session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); =20 diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index feaf34b25efc..342a5eaee9d3 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -136,15 +136,6 @@ struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int= cpu, void *data __maybe_u return id; } =20 -struct aggr_cpu_id cpu_map__get_socket(struct perf_cpu_map *map, int idx, - void *data) -{ - if (idx < 0 || idx > map->nr) - return cpu_map__empty_aggr_cpu_id(); - - return cpu_map__get_socket_aggr_by_cpu(map->map[idx], data); -} - static int cmp_aggr_cpu_id(const void *a_pointer, const void *b_pointer) { struct aggr_cpu_id *a =3D (struct aggr_cpu_id *)a_pointer; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 9648816c4255..a53af24301d2 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -32,7 +32,6 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, ch= ar *buf, size_t size); size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); int cpu_map__get_socket_id(int cpu); struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data); -struct aggr_cpu_id cpu_map__get_socket(struct perf_cpu_map *map, int idx, = void *data); int cpu_map__get_die_id(int cpu); struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, voi= d *data); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 09ea334586f2..9eca1111fa52 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -328,7 +328,7 @@ static int check_per_pkg(struct evsel *counter, if (!(vals->run && vals->ena)) return 0; =20 - s =3D cpu_map__get_socket(cpus, cpu, NULL).socket; + s =3D cpu_map__get_socket_id(cpu); if (s < 0) return -1; =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FE8BC433F5 for ; Thu, 23 Dec 2021 07:46:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347006AbhLWHqd (ORCPT ); Thu, 23 Dec 2021 02:46:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40566 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346996AbhLWHq3 (ORCPT ); Thu, 23 Dec 2021 02:46:29 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6186C061756 for ; Wed, 22 Dec 2021 23:46:28 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id w5-20020a25ac05000000b005c55592df4dso8702368ybi.12 for ; Wed, 22 Dec 2021 23:46:28 -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=XMhxFWBeVRuEETnE+BwPikcCWy5mLHkNqyV9tFQoVss=; b=I57ah+5DPDWKDOY7/eycjwMW6xNYhZ1jfVuGS5ncB/vx1ZlIhbOrR6FKrSwZbpthZA M/uTasVvE1VQ4VE9MNUUvSHO4jkNkXbmVru1Sh4UWOOvtkZtkufI4/tvyaLb2lK/mUeg 2mAhf0L3+g41Szw2v4rir6kWaq43e2nyBMf+/58Ryq2dCkbXXXSoXY68gOw1MGkjyTFR rBPMAerBqWq3oycoeTioSQBDHmhV1mgkwE6DFKKkOZen+xYLPgGGS3y4jdfSgADc8Dgx kFSwUO4tcWu2NCVc2iZ10Vpxa/d3/p0MzP+QvgLhLuj/qA3uqpwfacpViSJnNQ3dnpKq eYDw== 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=XMhxFWBeVRuEETnE+BwPikcCWy5mLHkNqyV9tFQoVss=; b=L7d/o1FulOdsF1yIZ+lrFoziAi1XNteCEgFRTJ3D8+f1yDA0HLotrFFIlfzIbBTPLf whl9VzqfTyg/ygBHVetCsrwETizRy62SozNhjr40JWK4Wl37hs7evOI/Nfg2fGoFOR5E GZHZG/MErFiCv7k9W3kcnPjx/8jw9HkgUm/joWLQGQi7cM05LeznyVQ+fIFvWTt7bp0P 9D2MxgC6zt98hIJgURkdhTDRUD2qj+lBjZ1yb6N1xDAIaaWITJTl+Mha9IhjoW14L6IE cW6yYNn+cUe1xkXCoe4rY9OP/yXCqQD5TMb897HOjFAxA678VgXd7oAUJxO9k2LXyuZP gpoQ== X-Gm-Message-State: AOAM5311XmWPL4NQP5qeBHrr8PxaySt/TE0/xyo7JQXuEY/1uvQIyHeT f8gjuVrBUdWC9rhBbhlfQyTPY9zqtQnS X-Google-Smtp-Source: ABdhPJyGDKLEdbH97OTrkXsESmtagS+ejAQGDy2zvluksa3GsQzoOmQS9wGFqpCbULRTZC+qoTrzr/mJEm84 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:1fc1:: with SMTP id f184mr1663842ybf.687.1640245587870; Wed, 22 Dec 2021 23:46:27 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:01 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-9-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 08/48] perf cpumap: Remove map+index get_die 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Migrate final users to appropriate cpu variant. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/tests/topology.c | 2 +- tools/perf/util/cpumap.c | 9 --------- tools/perf/util/cpumap.h | 1 - tools/perf/util/stat.c | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 69a64074b897..ce085b6f379b 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -136,7 +136,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that die ID contains socket and die for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_die(map, i, NULL); + id =3D cpu_map__get_die_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Die map - Socket ID doesn't match", session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); =20 diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 342a5eaee9d3..ff91c32da688 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -216,15 +216,6 @@ struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cp= u, void *data) return id; } =20 -struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, - void *data) -{ - if (idx < 0 || idx > map->nr) - return cpu_map__empty_aggr_cpu_id(); - - return cpu_map__get_die_aggr_by_cpu(map->map[idx], data); -} - int cpu_map__get_core_id(int cpu) { int value, ret =3D cpu__get_topology_int(cpu, "core_id", &value); diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index a53af24301d2..365ed69699e1 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -34,7 +34,6 @@ int cpu_map__get_socket_id(int cpu); struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data); int cpu_map__get_die_id(int cpu); struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); -struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, voi= d *data); int cpu_map__get_core_id(int cpu); struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, vo= id *data); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 9eca1111fa52..5ed99bcfe91e 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -336,7 +336,7 @@ static int check_per_pkg(struct evsel *counter, * On multi-die system, die_id > 0. On no-die system, die_id =3D 0. * We use hashmap(socket, die) to check the used socket+die pair. */ - d =3D cpu_map__get_die(cpus, cpu, NULL).die; + d =3D cpu_map__get_die_id(cpu); if (d < 0) return -1; =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF0E7C4332F for ; Thu, 23 Dec 2021 07:46:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347010AbhLWHqg (ORCPT ); Thu, 23 Dec 2021 02:46:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346993AbhLWHqb (ORCPT ); Thu, 23 Dec 2021 02:46:31 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AB85C061401 for ; Wed, 22 Dec 2021 23:46:31 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id q198-20020a25d9cf000000b005f7a6a84f9fso8566026ybg.6 for ; Wed, 22 Dec 2021 23:46:31 -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=MCK3PXHKxnJ+ljXLSZiTWLvHtcXTKUfApdV6xTysANE=; b=KBqN6r7LevbIJ7DspJ9ZQuQ1H8mJQaV3PHwKSOvqliRrH0SmzqfHG43ZeW1Kd+mKpu 8wcjrP78XSYonUw1hZvvoIexqKj5cAjqs3aaFZYqsFj6YtS7sUzKdMxWb5EOiA5IR9UY AJ1Lw56EryjZ0NDW58jhV2uGdg3izc2DVHPMEYeUBMG8Ku66IwtNaC9/l7EeMLSYyhFl 6rvnc8+k6SXJmoWrCsmV7QnzkXXVeaO/hescaBe+W4Pq/nZAn7Z/CZrc138Kf7KZpBYS YI4ExYTI78g7QbmaMcGZ8vmbKe9gim6Mr2b01f8usfTgCMnPiUMgKAhNk2nxrPBAkg1a jLIQ== 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=MCK3PXHKxnJ+ljXLSZiTWLvHtcXTKUfApdV6xTysANE=; b=djDXmPHkM1+qLz3rTChEkul8kVgszUYvcahd34HGc51YVItGZc8OstEZKSETkW5iXD e4UTboVXChzZBB8eKBtBGFGI7lKd/JyAIkzRYf+S8fGwqW9SXrCY6zJY0XXVrR70Hrxq wsElTgo5Lmmc6cfgci8kn8e8Pd5kkT7rAk5dm6TsToSI/5wPFOylb3qlo5gG9HkG+/dn UOhuth2mqAMbvld5ZhENZqzlAmqzFSORqAycBUE0uEXDxNeglicIKVAiKQzk8yDWPPPs MUBtUZWwo3/AikQ6fqpec9PevdE+XMqz32eiTuSnYWiNGYeXSoPD+RqNUshZSqSaXtnc S6NQ== X-Gm-Message-State: AOAM531BmNvs/5HruM7dLsnlbgung4rIGilVnTk3EWAFlZYZclyc8vw1 fRRb3NSvTViMlZ0HPvEz7viz1hDJ+uip X-Google-Smtp-Source: ABdhPJy8YqT1jzES8T/J1ThGT2eMjmeaj38Tu5Uwrk0WsTJnid8jvKkoKLBXCSeX8B6vtH3kyibTDWhBeHuL X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a5b:c8d:: with SMTP id i13mr1771035ybq.354.1640245590498; Wed, 22 Dec 2021 23:46:30 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:02 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-10-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 09/48] perf cpumap: Remove map+index get_core 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Migrate final users to appropriate cpu variant. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/tests/topology.c | 2 +- tools/perf/util/cpumap.c | 8 -------- tools/perf/util/cpumap.h | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index ce085b6f379b..9a671670415a 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -121,7 +121,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that core ID contains socket, die and core for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_core(map, i, NULL); + id =3D cpu_map__get_core_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Core map - Core ID doesn't match", session->header.env.cpu[map->map[i]].core_id =3D=3D id.core); =20 diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index ff91c32da688..e8149bcf8bfa 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -246,14 +246,6 @@ struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int c= pu, void *data) =20 } =20 -struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, vo= id *data) -{ - if (idx < 0 || idx > map->nr) - return cpu_map__empty_aggr_cpu_id(); - - return cpu_map__get_core_aggr_by_cpu(map->map[idx], data); -} - struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data __may= be_unused) { struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 365ed69699e1..7e1829468bd6 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -36,7 +36,6 @@ int cpu_map__get_die_id(int cpu); struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); int cpu_map__get_core_id(int cpu); struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); -struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, vo= id *data); int cpu_map__get_node_id(int cpu); struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, vo= id *data); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FAC2C433F5 for ; Thu, 23 Dec 2021 07:46:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347019AbhLWHqi (ORCPT ); Thu, 23 Dec 2021 02:46:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347016AbhLWHqf (ORCPT ); Thu, 23 Dec 2021 02:46:35 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76D7AC06175C for ; Wed, 22 Dec 2021 23:46:33 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id r18-20020a25ac52000000b005c9047c420bso8728492ybd.4 for ; Wed, 22 Dec 2021 23:46:33 -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=IOVWCeh5kE6zfEvaqpsG89YizqzabGkupqLnB+tiwXE=; b=eA5RJ3bMTokwOYkT2TLv9AwfMr248LwqYt4ywr+nUo2pLVtxMWsfRyBU0pkMiCzDKr J10iB0ivit7LIduS2Ajr9DyaF/NjArZuy4PWzgoaQQI71TTS+3lfDZbCT5OYSm1D5ly5 EyBDLyZz/63LgICPG2eWk1ohMQxeoy+almSxrYE1ocHkrDj/EhoHOc2PvPac/CwZlFm5 PkTxXAfkoJ7s2ekjXHK1YovvR9eUq6DnVw//Lh6Kr9qfkO1rre14tDU1zlRhfGcLfXqI 1+mCPuSz5YDhVHRYiB710X6FqbY4hpEWOFW4wgj3Me87wEhg+S6XMuD70bPJZ3BNxnab +kyw== 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=IOVWCeh5kE6zfEvaqpsG89YizqzabGkupqLnB+tiwXE=; b=KlczRoda6Ew3oAHe3t4USEBpZtneHB3RI5XlV22fY1m7EPtyL0hkXRu4bScmZPnuLC yY6AdWvecL3hr/3L4OPCh2cW7LBi7XQ8Z998vlCcEZBr8aSu1FXWcdvY24kjCmXVO1lH PE1iul+8M0b8QCWfuNpen621rcH8FoXkXxaY4LLzmQ2NfGzLFvDZQ8Gbn1tuHJOojaT9 XN4dRZ0yWVkZTVVuxplj3/NiRZ8ITEtWHWTPkpOihO38n3xaLJHUhv2eifVEAV+fjPnm 2/0rNkraRSXa+rGrvEgwBCvUYd8edDb9JT+ZCXj04wqUPiDC5NkNmQ84Gbed3lhDXj/t zw1A== X-Gm-Message-State: AOAM531si49gCguT69acAgkMdTacBI/tkx/vPY+1XYlL48RtzM3q6NNw Xp4biVx1/G5y9jGgwt6wiJ2a1IoKvpDI X-Google-Smtp-Source: ABdhPJzwr9tvOH9TYl4s/7K80EibN8uAtfYvMJRBqj6dDiXHyHmsyVYFLriMbY4RrsBHU1igLraiucp9wf52 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:b3cc:: with SMTP id x12mr1797675ybf.243.1640245592717; Wed, 22 Dec 2021 23:46:32 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:03 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-11-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 10/48] perf cpumap: Remove map+index get_node 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Migrate final users to appropriate cpu variant. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/tests/topology.c | 2 +- tools/perf/util/cpumap.c | 8 -------- tools/perf/util/cpumap.h | 1 - 3 files changed, 1 insertion(+), 10 deletions(-) diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 9a671670415a..5992b323c4f5 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -162,7 +162,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that node ID contains only node for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_node(map, i, NULL); + id =3D cpu_map__get_node_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Node map - Node ID doesn't match", cpu__get_node(map->map[i]) =3D=3D id.node); TEST_ASSERT_VAL("Node map - Socket is set", id.socket =3D=3D -1); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index e8149bcf8bfa..f67b2e7aac13 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -254,14 +254,6 @@ struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int c= pu, void *data __maybe_unu return id; } =20 -struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, vo= id *data) -{ - if (idx < 0 || idx >=3D map->nr) - return cpu_map__empty_aggr_cpu_id(); - - return cpu_map__get_node_aggr_by_cpu(map->map[idx], data); -} - int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp) { return cpu_map__build_map(cpus, sockp, cpu_map__get_socket_aggr_by_cpu, N= ULL); diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 7e1829468bd6..f0121dd4fdcb 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -38,7 +38,6 @@ int cpu_map__get_core_id(int cpu); struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); int cpu_map__get_node_id(int cpu); struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); -struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, vo= id *data); int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp); int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map = **diep); int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **corep); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E070C433EF for ; Thu, 23 Dec 2021 07:46:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347032AbhLWHqk (ORCPT ); Thu, 23 Dec 2021 02:46:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346999AbhLWHqg (ORCPT ); Thu, 23 Dec 2021 02:46:36 -0500 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 C31F4C061756 for ; Wed, 22 Dec 2021 23:46:35 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id r18-20020a25ac52000000b005c9047c420bso8728658ybd.4 for ; Wed, 22 Dec 2021 23:46:35 -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=i7256vb/Zx8IIeVMwww3dL/k4OEqcir0FFGgHyZofME=; b=ULf7pncHNSXp74XAiBkRZsQ2We3PFB8Q6TLzGDSIonox8ZanH6Qkow4Mrc4PWRHQfP q/Sfhe3s5uOsFTdgq1wgbUSW0223h23SUnF8X++qM+vLzFZSBgWEYuACJss2wepreTnK Jf3gJiLFO2iaB53o4KLMpAQ0fWqkPZCaD8drbNrmQv2mcqSv+8yyrPecChcT2dckeMM/ k2w8pIiFpuL/8kSi1srTjFgPb/5EHoCETU/5ICYUhaN3EaDXOhXmvSZmadajv1/Qi5bV VSHoEm0TVW81+Qe9AIwsjsGB8B2Uq2SCU86B9CseVBXgUkMYa5KxDMu1vn6jG91+xUOU hFXg== 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=i7256vb/Zx8IIeVMwww3dL/k4OEqcir0FFGgHyZofME=; b=K94Z8gYdZjn0Ze1LH1O0g8pGTh2WDJ2mHcjMdERwRH0e7YF6abTXwdUHFyLf+pvHU4 nVHR8FrAg+17ECFuPu3BhlFrYL/YazZnj4F54638sxdAit5/EFMojNlJU6DP+7eA+YvB Y82mjWLSiX+A8DxqIoMq6+ONcaSN/IxJExUucczBl0Rhvq448Eq9Rs/6iIhq47aw4G3I Oj/Fcth2ZBWPU/k6gytesRmHNqNuIsls2rvr+IOdLLB63wHuc5S6rqFauCF0HuE4y/2l tYsYtIyJuEpD4AVevWns5zjCacyx6/FpzmDqpg+GR/AhZ/a0bNn8u9uUZwjwg0g+9Jax iyFw== X-Gm-Message-State: AOAM530w2AzNkpdoBk9CR70OY94fQ+FeVFPhA+bPkR0hzxzU+Hk3wzIy QGKgFAzrty8bhQa/Fbrkk8vfkpeVgQVp X-Google-Smtp-Source: ABdhPJyR5JZf5bjSrz0ulaEcX4bGs7VsSsfLIz8hrDRGWaiBoyyjWL+6gtkZ7bJTmSJ7QJfv+tI/QK92QsEU X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:328b:: with SMTP id y133mr1567948yby.233.1640245595027; Wed, 22 Dec 2021 23:46:35 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:04 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-12-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 11/48] perf cpumap: Add comments to aggr_cpu_id 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This code is already tested in topology.c. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index f0121dd4fdcb..edd93e1db36a 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -7,11 +7,20 @@ #include #include =20 +/** Identify where counts are aggregated, -1 implies not to aggregate. */ struct aggr_cpu_id { + /** A value in the range 0 to number of threads. */ int thread; + /** The numa node X as read from /sys/devices/system/node/nodeX. */ int node; + /** + * The socket number as read from + * /sys/devices/system/cpu/cpuX/topology/physical_package_id. + */ int socket; + /** The die id as read from /sys/devices/system/cpu/cpuX/topology/die_id.= */ int die; + /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_i= d. */ int core; }; =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D09BC433EF for ; Thu, 23 Dec 2021 07:46:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347070AbhLWHqn (ORCPT ); Thu, 23 Dec 2021 02:46:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347016AbhLWHqi (ORCPT ); Thu, 23 Dec 2021 02:46:38 -0500 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 3DD07C061757 for ; Wed, 22 Dec 2021 23:46:38 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id p133-20020a255b8b000000b006086e19f89fso8555579ybb.19 for ; Wed, 22 Dec 2021 23:46:38 -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=eEInaxEsEve0QLZ8igLVk6cMHD2TdWaDtxRpGZXeF78=; b=N0vrtFwLQU1q7abSqGMyKyZMpqH7TqawrR8F7sIDWlmeD8nJn1YMTHJnwzJzlGNmvt J7WxUSGU94JZE5zGQuPjqwRW1QkzYmMweoDdwYwwGCf0pmyb+cpjlMtiS+YlKlkPw1iR rq2SRy1jE+wFvR8RfYGvtYgC/UDaNpaeceparnLTY8Q648j1CTfvwCA0dFPnZrmtN8F9 LHH3JcdArfNeGgnKwRr259ANm1LntQ4ThbBOyJxjc30YV9B/DPBPfHHyDPQhEULzvcne F3Od8Oj9uCQlNj7Gt4gC51eGmleTyedGxODKnOiBAUIFEaWS6Xfp4OcikxSR+E991UE2 EZwQ== 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=eEInaxEsEve0QLZ8igLVk6cMHD2TdWaDtxRpGZXeF78=; b=2xg+Qy/JekfX77sJooOSg0STFZuEHSjnhzRJ6Fh7gWIZr4XardZrHoec+HokcwgUH7 Ez0ey81FReqkXHw7X2GkVA15NMMUY+40Fg+Au0mhsv6pKE886WhzVqIA71M0WlVjh+AB htLvrH2+8g0b3aiuwz1IjPGb8ya50eLrK2lRbQlWLwdkqzZ+Lw3V0w8QHFTtaEsouoTv JCY82t7sHc+paVsvxXyvDgUyQ9DMfTeJtMXigOWNuS+yGQpcTdk1/2jUtuiiQQaTtuz8 IF7lwfRw/YtYDGwJWUhiw2J5yG8qZkBEf9JjFSRBdYCLpbVq/l8spzSYW+K2TMN6/TvU CKyQ== X-Gm-Message-State: AOAM53026vw+VfWYx9+2D34WreDUyicUhyH04DYPfU/6ZN3tDaZ3ymrd U0/Q67X4dwpoyd0HC3FQGA4ji1HiD909 X-Google-Smtp-Source: ABdhPJyMV9p5dilbpJj9lZFv4lwVDJfkQWdmjSih72KOOnbXd0DtxzUGLUbt+Dwd++RBqmm/x3rguqLNwJzC X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:bbc7:: with SMTP id c7mr1571216ybk.725.1640245597478; Wed, 22 Dec 2021 23:46:37 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:05 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-13-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 12/48] perf cpumap: Remove unused cpu_map__socket 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Unused function so remove. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.h | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index edd93e1db36a..22e53fd54657 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -53,13 +53,6 @@ int cpu_map__build_core_map(struct perf_cpu_map *cpus, s= truct cpu_aggr_map **cor int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **nodep); const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ =20 -static inline int cpu_map__socket(struct perf_cpu_map *sock, int s) -{ - if (!sock || s > sock->nr || s < 0) - return 0; - return sock->map[s]; -} - int cpu__setup_cpunode_map(void); =20 int cpu__max_node(void); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F90AC433EF for ; Thu, 23 Dec 2021 07:46:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347094AbhLWHqt (ORCPT ); Thu, 23 Dec 2021 02:46:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347041AbhLWHqk (ORCPT ); Thu, 23 Dec 2021 02:46:40 -0500 Received: from mail-pg1-x54a.google.com (mail-pg1-x54a.google.com [IPv6:2607:f8b0:4864:20::54a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E3F9C06175A for ; Wed, 22 Dec 2021 23:46:40 -0800 (PST) Received: by mail-pg1-x54a.google.com with SMTP id s8-20020a63af48000000b002e6c10ac245so2852518pgo.21 for ; Wed, 22 Dec 2021 23:46:40 -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=5u9uOvrM0MZW4hQbQrlJVSUOMIL0GMHYnyDBSXZC4ik=; b=qIVAAtr6ofyUe6ovBipZf/c3cfC9KP2iym9VMkWZ4IVlc+tsXbWVqXAa1VrJxlRlNG cGUqPpCr0XoycqNLxyVHg9yY6QxvehmlfyYLGTNPVAzLWmWtPlP3zZci+2xKNxyJdMlh UgZHnrsETcaQz1wXVRdwJPnfA8yH9siGL2PQq44JxrjhrSkhXqdCdyfvHZhMqzqdhBDA qp4Csm/vekB5JSLS3+zLgvea0ib92e9kNtnrPkN5507gWo3oAbjbvgAYuZ0oQPehKGy/ kMIiRpvJJpgJ9EkHWxHzyJ+//Nf93g2E5qVTUnoYY6rZAkXwgti4aeCHEdH4et9cTmJo xw0A== 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=5u9uOvrM0MZW4hQbQrlJVSUOMIL0GMHYnyDBSXZC4ik=; b=0w29ChAUECh6qM3x962GYW08BusCqTSHuo+93xMAaKKxRnWpL6QHCNcmC9XXwl+pZC TD4P5umhelTnxFQAaMnRLDb8o4lWIwomWR42AuxznquYI9l20swg/cPA+7sgh3tDmYEW Gpa1o4tT3fEVgBpP8YVEYnM/BDZ2BaFNqd/63rcAieyWxy0BvlyxP3ats69kmBh77HkT ZltCh5SCX/2lmYRaDoQOFOFh9rwXDzRN2HEbiF+vvdZMMlMcKmD2QC5CFc/4aWmUUJMH sGWUrPM3kjD2QkoZxfOU2bmG+ZPXGMb8W9XvNRMy+f249OkwKGOkIU15ddnZFmr0ozLT s51w== X-Gm-Message-State: AOAM533GfbBW0eNwckSuB5rssGtqos0vLG/E9wVdXKdc5djK/M4aMea7 QB2JNXbnRK3IpWU0fFsnAw748F6MLY13 X-Google-Smtp-Source: ABdhPJwlhHfxKAtk99Bk5IZEENVaNeKaQwYA2sTDg9XONvjMttn4NmO8MtIsYPprP67p/o9LkTxB5nLnKDmB X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a62:8cca:0:b0:4ba:d6d4:7bac with SMTP id m193-20020a628cca000000b004bad6d47bacmr1310531pfd.43.1640245600048; Wed, 22 Dec 2021 23:46:40 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:06 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-14-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 13/48] perf cpumap: Simplify equal function name. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rename cpu_map__compare_aggr_cpu_id to aggr_cpu_id__equal, the cpu_map part of the name is misleading. Equal better describes the function than compare. Switch to const pointer rather than value as struct given the number of variables in aggr_cpu_id. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.c | 14 +++++++------- tools/perf/util/cpumap.h | 2 +- tools/perf/util/stat-display.c | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index f67b2e7aac13..8fa00a6221c8 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -171,7 +171,7 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struc= t cpu_aggr_map **res, for (cpu =3D 0; cpu < nr; cpu++) { s1 =3D f(cpu, data); for (s2 =3D 0; s2 < c->nr; s2++) { - if (cpu_map__compare_aggr_cpu_id(s1, c->map[s2])) + if (aggr_cpu_id__equal(&s1, &c->map[s2])) break; } if (s2 =3D=3D c->nr) { @@ -593,13 +593,13 @@ const struct perf_cpu_map *cpu_map__online(void) /* t= hread unsafe */ return online; } =20 -bool cpu_map__compare_aggr_cpu_id(struct aggr_cpu_id a, struct aggr_cpu_id= b) +bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu= _id *b) { - return a.thread =3D=3D b.thread && - a.node =3D=3D b.node && - a.socket =3D=3D b.socket && - a.die =3D=3D b.die && - a.core =3D=3D b.core; + return a->thread =3D=3D b->thread && + a->node =3D=3D b->node && + a->socket =3D=3D b->socket && + a->die =3D=3D b->die && + a->core =3D=3D b->core; } =20 bool cpu_map__aggr_cpu_id_is_empty(struct aggr_cpu_id a) diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 22e53fd54657..652b76c69376 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -67,7 +67,7 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct = cpu_aggr_map **res, int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); =20 -bool cpu_map__compare_aggr_cpu_id(struct aggr_cpu_id a, struct aggr_cpu_id= b); +bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu= _id *b); bool cpu_map__aggr_cpu_id_is_empty(struct aggr_cpu_id a); struct aggr_cpu_id cpu_map__empty_aggr_cpu_id(void); =20 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 6c40b91d5e32..0241436bb1fb 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -328,20 +328,22 @@ static void print_metric_header(struct perf_stat_conf= ig *config, } =20 static int first_shadow_cpu(struct perf_stat_config *config, - struct evsel *evsel, struct aggr_cpu_id id) + struct evsel *evsel, const struct aggr_cpu_id *id) { struct perf_cpu_map *cpus; int cpu, idx; =20 if (config->aggr_mode =3D=3D AGGR_NONE) - return id.core; + return id->core; =20 if (!config->aggr_get_id) return 0; =20 cpus =3D evsel__cpus(evsel); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - if (cpu_map__compare_aggr_cpu_id(config->aggr_get_id(config, cpu), id)) + struct aggr_cpu_id cpu_id =3D config->aggr_get_id(config, cpu); + + if (aggr_cpu_id__equal(&cpu_id, id)) return cpu; } return 0; @@ -501,7 +503,7 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int } =20 perf_stat__print_shadow_stats(config, counter, uval, - first_shadow_cpu(config, counter, id), + first_shadow_cpu(config, counter, &id), &out, &config->metric_events, st); if (!config->csv_output && !config->metric_only) { print_noise(config, counter, noise); @@ -525,12 +527,12 @@ static void aggr_update_shadow(struct perf_stat_confi= g *config, val =3D 0; perf_cpu_map__for_each_cpu(cpu, idx, cpus) { s2 =3D config->aggr_get_id(config, cpu); - if (!cpu_map__compare_aggr_cpu_id(s2, id)) + if (!aggr_cpu_id__equal(&s2, &id)) continue; val +=3D perf_counts(counter->counts, idx, 0)->val; } perf_stat__update_shadow_stats(counter, val, - first_shadow_cpu(config, counter, id), + first_shadow_cpu(config, counter, &id), &rt_stat); } } @@ -641,7 +643,7 @@ static void aggr_cb(struct perf_stat_config *config, struct perf_counts_values *counts; =20 s2 =3D config->aggr_get_id(config, cpu); - if (!cpu_map__compare_aggr_cpu_id(s2, ad->id)) + if (!aggr_cpu_id__equal(&s2, &ad->id)) continue; if (first) ad->nr++; @@ -1217,7 +1219,7 @@ static void print_percore_thread(struct perf_stat_con= fig *config, s2 =3D config->aggr_get_id(config, cpu); for (s =3D 0; s < config->aggr_map->nr; s++) { id =3D config->aggr_map->map[s]; - if (cpu_map__compare_aggr_cpu_id(s2, id)) + if (aggr_cpu_id__equal(&s2, &id)) break; } =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47BB4C433EF for ; Thu, 23 Dec 2021 07:46:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347064AbhLWHqz (ORCPT ); Thu, 23 Dec 2021 02:46:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346993AbhLWHqn (ORCPT ); Thu, 23 Dec 2021 02:46:43 -0500 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 77518C061759 for ; Wed, 22 Dec 2021 23:46:43 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id j204-20020a2523d5000000b005c21574c704so8595906ybj.13 for ; Wed, 22 Dec 2021 23:46:43 -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=qXF1qKYfawu8i5Ximj84AI0eI7NctMy7cT7+8XiJz60=; b=O6qiFfYmy1+ymjTXdpRRA6zg4ZVZsdKmdtseMA6CZ9NneGUe2dCKhCunnK8EP0783h Gt0r+lf8GYdNFkSsEqRM8H6ovXUNr866izO1VVinDFcaNdF7VUX1EzFR3CYAotw/AlmV F477jQEC6kw0T9K9hDLbi0O5RYnTEYNwmhZpQyG/74lgDaZanKXHBMNJbjq0e0ao3ZiX CQjtpzxnkXGraZxX2REqNk25GKw+dGwK2fkDvv9mN+isxh/Hen+3lajt6Zjpq4KMu9CM CVRwoGgu4WnEehbjqTYMF+90GEWq5Vr2jY67VJ+crnyKAw/SjLyN/6rt1LUtof0xfHTu JLyA== 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=qXF1qKYfawu8i5Ximj84AI0eI7NctMy7cT7+8XiJz60=; b=4OZPukrbapWiwzvhXkl8gOFMjW+udOSM4Wyt6nEAk0frdwHz+XOqqiBNNEE/tB5bPz 51d9I05gcCmOO9v2DSB4wFGYBP+zUhZXqm83HO5OBCuXmX2Bjfy1HKysWJ168ita5I71 XFmCiZek6GqSzDLTJ9bxaEazzCPaBGzcvqKgWebGaLPSEsuizuvBoKoqNDHeZ4pFouPL tQfhYPV2BySH8a5rX3pk2xWQ2+EPB+Qv3DfToihY4EOjLdaTFllyrlbEGP5Hbqd7gPq8 MZc7qcgf33v7siq9bXOyjEOkE98dvlZYkiktYDmpSwrUSB/IA8y+JLxtnVtpGpah54St qlHg== X-Gm-Message-State: AOAM533GQTuyQ3YouTfgOWrPj4vRQlfzrRsuxveZfsFfvFK27nPnaD9W 72UuaMfhUE12BGRNUhexFGkzE9hB9h0A X-Google-Smtp-Source: ABdhPJyecSzgPZuokdBzsg9gz5ovTDfSLiJG02MJmJRAgEygy9n57xi+N30jyRQmPzMO574XpeMAYQlpnvvC X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:2c92:: with SMTP id s140mr1685192ybs.308.1640245602659; Wed, 22 Dec 2021 23:46:42 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:07 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-15-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 14/48] perf cpumap: Rename empty functions. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove cpu_map from name as a cpu_map isn't used. Pass a const pointer rather than by value to avoid unnecessary copying. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 12 ++++++------ tools/perf/util/cpumap.c | 24 ++++++++++++------------ tools/perf/util/cpumap.h | 4 ++-- tools/perf/util/stat-display.c | 10 +++++----- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 6b985abaa2d2..d229fb71b577 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1349,9 +1349,9 @@ static struct aggr_cpu_id perf_stat__get_node(struct = perf_stat_config *config __ static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *con= fig, aggr_get_id_t get_id, int cpu) { - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 - if (cpu_map__aggr_cpu_id_is_empty(config->cpus_aggr_map->map[cpu])) + if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu])) config->cpus_aggr_map->map[cpu] =3D get_id(config, cpu); =20 id =3D config->cpus_aggr_map->map[cpu]; @@ -1496,7 +1496,7 @@ static inline int perf_env__get_cpu(void *data, struc= t perf_cpu_map *map, int id static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(int cpu, void *= data) { struct perf_env *env =3D data; - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 if (cpu !=3D -1) id.socket =3D env->cpu[cpu].socket_id; @@ -1507,7 +1507,7 @@ static struct aggr_cpu_id perf_env__get_socket_aggr_b= y_cpu(int cpu, void *data) static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *dat= a) { struct perf_env *env =3D data; - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 if (cpu !=3D -1) { /* @@ -1525,7 +1525,7 @@ static struct aggr_cpu_id perf_env__get_die_aggr_by_c= pu(int cpu, void *data) static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *da= ta) { struct perf_env *env =3D data; - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 if (cpu !=3D -1) { /* @@ -1543,7 +1543,7 @@ static struct aggr_cpu_id perf_env__get_core_aggr_by_= cpu(int cpu, void *data) =20 static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *da= ta) { - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 id.node =3D perf_env__numa_node(data, cpu); return id; diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 8fa00a6221c8..b3e1304aca0c 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -104,7 +104,7 @@ struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr) =20 cpus->nr =3D nr; for (i =3D 0; i < nr; i++) - cpus->map[i] =3D cpu_map__empty_aggr_cpu_id(); + cpus->map[i] =3D aggr_cpu_id__empty(); =20 refcount_set(&cpus->refcnt, 1); } @@ -130,7 +130,7 @@ int cpu_map__get_socket_id(int cpu) =20 struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data __m= aybe_unused) { - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 id.socket =3D cpu_map__get_socket_id(cpu); return id; @@ -209,7 +209,7 @@ struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu= , void *data) * make a unique ID. */ id =3D cpu_map__get_socket_aggr_by_cpu(cpu, data); - if (cpu_map__aggr_cpu_id_is_empty(id)) + if (aggr_cpu_id__is_empty(&id)) return id; =20 id.die =3D die; @@ -234,7 +234,7 @@ struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cp= u, void *data) =20 /* cpu_map__get_die returns a struct with socket and die set*/ id =3D cpu_map__get_die_aggr_by_cpu(cpu, data); - if (cpu_map__aggr_cpu_id_is_empty(id)) + if (aggr_cpu_id__is_empty(&id)) return id; =20 /* @@ -248,7 +248,7 @@ struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cp= u, void *data) =20 struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data __may= be_unused) { - struct aggr_cpu_id id =3D cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 id.node =3D cpu_map__get_node_id(cpu); return id; @@ -602,16 +602,16 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, = const struct aggr_cpu_id *b a->core =3D=3D b->core; } =20 -bool cpu_map__aggr_cpu_id_is_empty(struct aggr_cpu_id a) +bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) { - return a.thread =3D=3D -1 && - a.node =3D=3D -1 && - a.socket =3D=3D -1 && - a.die =3D=3D -1 && - a.core =3D=3D -1; + return a->thread =3D=3D -1 && + a->node =3D=3D -1 && + a->socket =3D=3D -1 && + a->die =3D=3D -1 && + a->core =3D=3D -1; } =20 -struct aggr_cpu_id cpu_map__empty_aggr_cpu_id(void) +struct aggr_cpu_id aggr_cpu_id__empty(void) { struct aggr_cpu_id ret =3D { .thread =3D -1, diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 652b76c69376..9589b0001a28 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -68,7 +68,7 @@ int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); =20 bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu= _id *b); -bool cpu_map__aggr_cpu_id_is_empty(struct aggr_cpu_id a); -struct aggr_cpu_id cpu_map__empty_aggr_cpu_id(void); +bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a); +struct aggr_cpu_id aggr_cpu_id__empty(void); =20 #endif /* __PERF_CPUMAP_H */ diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 0241436bb1fb..870b1db71fbc 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -698,7 +698,7 @@ static void print_counter_aggrdata(struct perf_stat_con= fig *config, =20 uval =3D val * counter->scale; if (cpu !=3D -1) { - id =3D cpu_map__empty_aggr_cpu_id(); + id =3D aggr_cpu_id__empty(); id.core =3D cpu; } printout(config, id, nr, counter, uval, @@ -780,7 +780,7 @@ static struct perf_aggr_thread_value *sort_aggr_thread( continue; =20 buf[i].counter =3D counter; - buf[i].id =3D cpu_map__empty_aggr_cpu_id(); + buf[i].id =3D aggr_cpu_id__empty(); buf[i].id.thread =3D thread; buf[i].uval =3D uval; buf[i].val =3D val; @@ -868,7 +868,7 @@ static void print_counter_aggr(struct perf_stat_config = *config, fprintf(output, "%s", prefix); =20 uval =3D cd.avg * counter->scale; - printout(config, cpu_map__empty_aggr_cpu_id(), 0, counter, uval, prefix, = cd.avg_running, + printout(config, aggr_cpu_id__empty(), 0, counter, uval, prefix, cd.avg_r= unning, cd.avg_enabled, cd.avg, &rt_stat); if (!metric_only) fprintf(output, "\n"); @@ -911,7 +911,7 @@ static void print_counter(struct perf_stat_config *conf= ig, fprintf(output, "%s", prefix); =20 uval =3D val * counter->scale; - id =3D cpu_map__empty_aggr_cpu_id(); + id =3D aggr_cpu_id__empty(); id.core =3D cpu; printout(config, id, 0, counter, uval, prefix, run, ena, 1.0, &rt_stat); @@ -938,7 +938,7 @@ static void print_no_aggr_metric(struct perf_stat_confi= g *config, if (prefix) fputs(prefix, config->output); evlist__for_each_entry(evlist, counter) { - id =3D cpu_map__empty_aggr_cpu_id(); + id =3D aggr_cpu_id__empty(); id.core =3D cpu; if (first) { aggr_printout(config, counter, id, 0); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E328CC433F5 for ; Thu, 23 Dec 2021 07:47:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347083AbhLWHq6 (ORCPT ); Thu, 23 Dec 2021 02:46:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347081AbhLWHqq (ORCPT ); Thu, 23 Dec 2021 02:46:46 -0500 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 0727BC061763 for ; Wed, 22 Dec 2021 23:46:46 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id d205-20020a251dd6000000b0060977416ad4so8515074ybd.16 for ; Wed, 22 Dec 2021 23:46:45 -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=oK4z5E5fiyzkgFCJbjPVTXl+1a3iQ4V/763qtnP+njI=; b=FJ470XTGu1n28V1ATGzFkx+a6y6IY7sA8YqbHakatI88rGF0HcROWHQ7c+agHMxVGQ ipZRdI2SLwQ6Q4zx0go2BxMm9pWQrnTq1w1xsgCZPWvIL0oT8/09FwThJFmBKh9kwQw1 eaLr3iKbvTNJtLGZN44476RGQaz+qCAvrAFRn5kvTi9hrWPVGJD6OnjmaGaar2/g2vit C2kYNb42EjdduHlZMy1cRWyL0DeNfakffPV2owzKsQWI34nNvfESCEwnKvRxQOgb1I32 Q67p2LBNN46xiesFBCBufpIcfId3DLncPFbxrhDFoJv0lniPufGKQYSTo+gY4a30MDwM p/ZQ== 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=oK4z5E5fiyzkgFCJbjPVTXl+1a3iQ4V/763qtnP+njI=; b=HH9uXjXy/eRNdENIGAwKV6hl9KERoE2Xvb3O4vg0fhF/y2DbN0/l6I3EpjpkVXl+JZ ENkTTvKVm3JrWK9xE3lNBOHiFoLJkOJS+zklUZw9beUSrc4jZEdSumqLjzaszZS/slXV 1UZdnEW3hK4IOdcT/B6VznXuFKb6PyEsFx46eBz5ZaA8xZz4d30tDWNsV/PKYs0XXoBj BbfDxzplMjz7jS3GI/LVedYuJ7fbFa54fGxO5EIiFGiabStTOc7gZhdyTE89yzMSkPzp tr8IrNkBkhcajuQ7ltsCrFLHvafriQRcL2p3xajN5N+FQFFZbEzNu84SKviyBsxOhdF4 FGkw== X-Gm-Message-State: AOAM530JcZ1KBDSech9In4b9IG0XOq2Z7XIqGH6Fd24w/mC869puAcfO xpFryTrjfyHVfF1KivqJrE3Wdpk9z0lm X-Google-Smtp-Source: ABdhPJymUOB7LGtIX2a9eR7ad1c348HlWb3l8JGGmoCGMzqjqRvlco6jPwBosbOtjOlDzUZa4aiCJXzdmfAn X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:abe3:: with SMTP id v90mr1636040ybi.315.1640245605233; Wed, 22 Dec 2021 23:46:45 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:08 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-16-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 15/48] perf cpumap: Document cpu__get_node and remove redundant function 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cpu_map__get_node_id isn't used externally and merely delegates to cpu__get_node. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.c | 11 +++++------ tools/perf/util/cpumap.h | 5 ++++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index b3e1304aca0c..1626b0991408 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -16,6 +16,10 @@ static int max_cpu_num; static int max_present_cpu_num; static int max_node_num; +/** + * The numa node X as read from /sys/devices/system/node/nodeX indexed by = the + * CPU number. + */ static int *cpunode_map; =20 static struct perf_cpu_map *cpu_map__from_entries(struct cpu_map_entries *= cpus) @@ -222,11 +226,6 @@ int cpu_map__get_core_id(int cpu) return ret ?: value; } =20 -int cpu_map__get_node_id(int cpu) -{ - return cpu__get_node(cpu); -} - struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data) { struct aggr_cpu_id id; @@ -250,7 +249,7 @@ struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cp= u, void *data __maybe_unu { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 - id.node =3D cpu_map__get_node_id(cpu); + id.node =3D cpu__get_node(cpu); return id; } =20 diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 9589b0001a28..f849f01c5860 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -45,7 +45,6 @@ int cpu_map__get_die_id(int cpu); struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); int cpu_map__get_core_id(int cpu); struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); -int cpu_map__get_node_id(int cpu); struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp); int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map = **diep); @@ -58,6 +57,10 @@ int cpu__setup_cpunode_map(void); int cpu__max_node(void); int cpu__max_cpu(void); int cpu__max_present_cpu(void); +/** + * cpu__get_node - Returns the numa node X as read from + * /sys/devices/system/node/nodeX for the given CPU. + */ int cpu__get_node(int cpu); =20 int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **re= s, --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53116C433F5 for ; Thu, 23 Dec 2021 07:47:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347147AbhLWHrL (ORCPT ); Thu, 23 Dec 2021 02:47:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347041AbhLWHqu (ORCPT ); Thu, 23 Dec 2021 02:46:50 -0500 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 419D1C061799 for ; Wed, 22 Dec 2021 23:46:48 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id l145-20020a25cc97000000b005c5d04a1d52so8598506ybf.23 for ; Wed, 22 Dec 2021 23:46:48 -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=R21tXxp1l1AKkDbM35zGCh/17/tAm03C0wqwQ2IqSuo=; b=VHhXnyDVum/RJBo4Ca9fkxRCfGhgzoktW/whBrzenk3Xdmcp6dtMnTxCt/CCcLoqOH VbCvTqhRAunNEERDAasbkM2xC/65rP8JYGlceGf4cshyQf2wlZdmU2/eFak7a1JjkX2s 7xjVBsCAI8jIWoKIR1l66CUtzlskcAD686SGp+X68lBX/91XoCgaS8YamaTQadQOMoMo m8f1sR3Wkx4Yg7GRkGVhoY24aVgOWxra0DDCProKG6p4p6suFRW3fJSLuPFC0CO/Ge6W doN81u5GyBnqKO35Gr3fBETdhR/U+/ofG/WxqD3OIlJKJ82v1HqfvfauehBhfrmewZBs JXww== 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=R21tXxp1l1AKkDbM35zGCh/17/tAm03C0wqwQ2IqSuo=; b=fJv0Qy3qcwwOqLTABGwv4A9l+WG2biePyPdIupwhfa76B8zkq7YNzJMu/A/P8XyfGN cQO60eT4Esd4aMG6M1GhgC9rW148Yq0Q/sa2QG1fyVuAAFRW/zprdZ3v16onBIqq3ZsS qRyZ6brCOW2mtxDLL7CYtvBGGECiKdJ71eAtzqrnh5iavjkzxet99cdfMKSrdNDsDhq5 rBHLDiFMuGz0Kw+8XGdgZiatTw08mYP+w1gBq/PnKXgV08+ydjebb7JcYFIZrohbkwxf hUNEdgj1hpoY40GMR92/lR6yupdLtp7Xb6S8F2f44Zj2ggwD5q5yoZBFq1rU2+wKf9QT gjYw== X-Gm-Message-State: AOAM5307DoCNEQ05yeOAtPJ5Nqfm1qGuUUN/kzsk2Ske2aezqmRkY8dz zrFY//DsUgGGUkdKNfqrK9mgHbw/nS4T X-Google-Smtp-Source: ABdhPJzaNCjESqzmvbKHasdNOlQwdpDftojOkPDGRCHos1IqTsfSMmjBuTWnBKaL6YyeNTd+uxI0u6/Hni1T X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a05:6902:552:: with SMTP id z18mr1690671ybs.318.1640245607469; Wed, 22 Dec 2021 23:46:47 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:09 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-17-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 16/48] perf cpumap: Remove map from function names that don't use a map. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move to the cpu name and document for consistency. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.c | 12 ++++++------ tools/perf/util/cpumap.h | 19 ++++++++++++++++--- tools/perf/util/env.c | 6 +++--- tools/perf/util/stat.c | 4 ++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 1626b0991408..e0d7f1da5858 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -126,7 +126,7 @@ static int cpu__get_topology_int(int cpu, const char *n= ame, int *value) return sysfs__read_int(path, value); } =20 -int cpu_map__get_socket_id(int cpu) +int cpu__get_socket_id(int cpu) { int value, ret =3D cpu__get_topology_int(cpu, "physical_package_id", &val= ue); return ret ?: value; @@ -136,7 +136,7 @@ struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int = cpu, void *data __maybe_u { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 - id.socket =3D cpu_map__get_socket_id(cpu); + id.socket =3D cpu__get_socket_id(cpu); return id; } =20 @@ -190,7 +190,7 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struc= t cpu_aggr_map **res, return 0; } =20 -int cpu_map__get_die_id(int cpu) +int cpu__get_die_id(int cpu) { int value, ret =3D cpu__get_topology_int(cpu, "die_id", &value); =20 @@ -202,7 +202,7 @@ struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu= , void *data) struct aggr_cpu_id id; int die; =20 - die =3D cpu_map__get_die_id(cpu); + die =3D cpu__get_die_id(cpu); /* There is no die_id on legacy system. */ if (die =3D=3D -1) die =3D 0; @@ -220,7 +220,7 @@ struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu= , void *data) return id; } =20 -int cpu_map__get_core_id(int cpu) +int cpu__get_core_id(int cpu) { int value, ret =3D cpu__get_topology_int(cpu, "core_id", &value); return ret ?: value; @@ -229,7 +229,7 @@ int cpu_map__get_core_id(int cpu) struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data) { struct aggr_cpu_id id; - int core =3D cpu_map__get_core_id(cpu); + int core =3D cpu__get_core_id(cpu); =20 /* cpu_map__get_die returns a struct with socket and die set*/ id =3D cpu_map__get_die_aggr_by_cpu(cpu, data); diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index f849f01c5860..a053bf31a3f0 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -39,11 +39,8 @@ struct perf_cpu_map *cpu_map__new_data(struct perf_recor= d_cpu_map_data *data); size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t s= ize); size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); -int cpu_map__get_socket_id(int cpu); struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data); -int cpu_map__get_die_id(int cpu); struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); -int cpu_map__get_core_id(int cpu); struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp); @@ -62,6 +59,22 @@ int cpu__max_present_cpu(void); * /sys/devices/system/node/nodeX for the given CPU. */ int cpu__get_node(int cpu); +/** + * cpu__get_socket_id - Returns the socket number as read from + * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given= CPU. + */ +int cpu__get_socket_id(int cpu); +/** + * cpu__get_die_id - Returns the die id as read from + * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU. + */ +int cpu__get_die_id(int cpu); +/** + * cpu__get_core_id - Returns the core id as read from + * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU. + */ +int cpu__get_core_id(int cpu); + =20 int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **re= s, struct aggr_cpu_id (*f)(int cpu, void *data), diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index b9904896eb97..fd12c0dcaefb 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -302,9 +302,9 @@ int perf_env__read_cpu_topology_map(struct perf_env *en= v) return -ENOMEM; =20 for (cpu =3D 0; cpu < nr_cpus; ++cpu) { - env->cpu[cpu].core_id =3D cpu_map__get_core_id(cpu); - env->cpu[cpu].socket_id =3D cpu_map__get_socket_id(cpu); - env->cpu[cpu].die_id =3D cpu_map__get_die_id(cpu); + env->cpu[cpu].core_id =3D cpu__get_core_id(cpu); + env->cpu[cpu].socket_id =3D cpu__get_socket_id(cpu); + env->cpu[cpu].die_id =3D cpu__get_die_id(cpu); } =20 env->nr_cpus_avail =3D nr_cpus; diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 5ed99bcfe91e..5c24aca0968c 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -328,7 +328,7 @@ static int check_per_pkg(struct evsel *counter, if (!(vals->run && vals->ena)) return 0; =20 - s =3D cpu_map__get_socket_id(cpu); + s =3D cpu__get_socket_id(cpu); if (s < 0) return -1; =20 @@ -336,7 +336,7 @@ static int check_per_pkg(struct evsel *counter, * On multi-die system, die_id > 0. On no-die system, die_id =3D 0. * We use hashmap(socket, die) to check the used socket+die pair. */ - d =3D cpu_map__get_die_id(cpu); + d =3D cpu__get_die_id(cpu); if (d < 0) return -1; =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FEBDC433F5 for ; Thu, 23 Dec 2021 07:47:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347178AbhLWHrU (ORCPT ); Thu, 23 Dec 2021 02:47:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347107AbhLWHqv (ORCPT ); Thu, 23 Dec 2021 02:46:51 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CC808C0617A2 for ; Wed, 22 Dec 2021 23:46:50 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id q198-20020a25d9cf000000b005f7a6a84f9fso8567101ybg.6 for ; Wed, 22 Dec 2021 23:46:50 -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=i2Vhfge4p8jg+eqgbjlb142jYxPFoaLEzdDupKyV2vE=; b=rcC+5g2bROePhd5WVPwNxxsovw3kJu6BWGXhGpqmLmq04IHG6wzWGxO1TaQzgD++MJ 5pjLqme+ieWLsGnTSqhowFCo3t9sgiIDTXpMnFJrbvxFZC/HgAjkvyuWsgpnoXZQ7XVA JfYbc46JH6JDAQHmMIkUB3bVZkaWaU/pca4fa5WjR4F4XaI3AsYUNaG6MN8oNC1giQE8 hMCSeNA08HwH5WMfbXahg/QDoyrOtgMLmsVn3+y6JG6yiHdm9j0E9SF7XuHbZypFV415 sPgsFHi/HajokPYkqGM4y6KuSxPoyfn7d4/7i78W3Motn3se0/KBnQNdQlqYi/HvFIbj YzIA== 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=i2Vhfge4p8jg+eqgbjlb142jYxPFoaLEzdDupKyV2vE=; b=G1GRU5P7pIky4YzrUjxcw5/4n0O9NA2ZD4TrY1xHLz2Fa0Bv1w/oII7PoJzKoeuh1V 5BmjU9Ap01bTQv7rcPh3LGgh7x9GvN4IWbH14E7aADeMLsy29N3OsUXcFz5wwQwdzFa6 RuuBCbVo6MuiqH+VkeRfoh4ZdSNlLjlyaxFC/pAe4Ux03a/KtgWBq6LB4nBa1IU80XSi FM7qpOLNszykMWzeKHUM9g3Ue17NV6q08Ph8Y1SiRze5RK2+FOxLEAF/ygIRD8kaiSZW xJl9tK5Se3LyJMeSubGAGByYa+86YWl0G1X46v/jqK1mVE3HE5FxNhC1Sq1EfbzhQScO sr8g== X-Gm-Message-State: AOAM531EI6W/Rc9zgVpjtCGkLmTTeRIaGEI34ECd7p8xhCn6b0ZLdV0H yeIQJBytyD5O53M/CJqnIzd08Z7UF6Je X-Google-Smtp-Source: ABdhPJyrF9k0EpiWni/WH5dHhqK2o2zDJaOgnPcbMN9oKEW+PwbTM3Ch2ywMcsi7eF7Dn28JvOsak5WOOswt X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:50d2:: with SMTP id e201mr1831648ybb.99.1640245610007; Wed, 22 Dec 2021 23:46:50 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:10 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-18-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 17/48] perf cpumap: Remove cpu_map__cpu, use libperf function. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch the remaining few users of cpu_map__cpu to perf_cpu_map__cpu and remove the function. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/builtin-ftrace.c | 2 +- tools/perf/util/cpumap.c | 9 ++------- tools/perf/util/cpumap.h | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 87cb11a7a3ee..5a65dc7a1580 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -303,7 +303,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpu= map) int ret; int last_cpu; =20 - last_cpu =3D cpu_map__cpu(cpumap, cpumap->nr - 1); + last_cpu =3D perf_cpu_map__cpu(cpumap, cpumap->nr - 1); mask_size =3D last_cpu / 4 + 2; /* one more byte for EOS */ mask_size +=3D last_cpu / 32; /* ',' is needed for every 32th cpus */ =20 diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index e0d7f1da5858..32f9fc2dd389 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -485,11 +485,6 @@ bool cpu_map__has(struct perf_cpu_map *cpus, int cpu) return perf_cpu_map__idx(cpus, cpu) !=3D -1; } =20 -int cpu_map__cpu(struct perf_cpu_map *cpus, int idx) -{ - return cpus->map[idx]; -} - size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) { int i, cpu, start =3D -1; @@ -547,7 +542,7 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, = char *buf, size_t size) int i, cpu; char *ptr =3D buf; unsigned char *bitmap; - int last_cpu =3D cpu_map__cpu(map, map->nr - 1); + int last_cpu =3D perf_cpu_map__cpu(map, map->nr - 1); =20 if (buf =3D=3D NULL) return 0; @@ -559,7 +554,7 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, = char *buf, size_t size) } =20 for (i =3D 0; i < map->nr; i++) { - cpu =3D cpu_map__cpu(map, i); + cpu =3D perf_cpu_map__cpu(map, i); bitmap[cpu / 8] |=3D 1 << (cpu % 8); } =20 diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index a053bf31a3f0..87545bcd461d 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -80,7 +80,6 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct = cpu_aggr_map **res, struct aggr_cpu_id (*f)(int cpu, void *data), void *data); =20 -int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); =20 bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu= _id *b); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C297CC433EF for ; Thu, 23 Dec 2021 07:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347246AbhLWHrt (ORCPT ); Thu, 23 Dec 2021 02:47:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347038AbhLWHrD (ORCPT ); Thu, 23 Dec 2021 02:47:03 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BA74C061756 for ; Wed, 22 Dec 2021 23:46:53 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id t184-20020a2546c1000000b006008b13c80bso8745971yba.1 for ; Wed, 22 Dec 2021 23:46:53 -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=fTUR5VG8a/+8UOVZeCoh/rbzUAVJU6bq+SOLs+aNQRw=; b=ReTb6NzMIRGxqZErghagCAEupNuZMhHsxwL/jqcOJpVHr5sgzOX9q6Tc+xc1rG8bpD NIBlTJiUzXgVqAeWne8Zd6TrQZkt3xJ60zOuOo4hCWE3Fi4vHOR4sJ0ZVv5UNV6JH2Fa Ve0AAwq7qaItHE71yJznSobk0lxTdmU3gqNdQaXIUOC2dlwaOTN/5aRm5M3wmuknKZyy wixSYVm4BfqTkFsA+2tbaqvjYuK8sMaD/TWsrTjIvoJPf273jzuIU5Pfho5geYBAppNp 0H8GODpsgJaFL4ebSTvCm9D3EPONZGdPItQksxC23OC48sPhrrxON7TdylLhMt1mG+Is a/YA== 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=fTUR5VG8a/+8UOVZeCoh/rbzUAVJU6bq+SOLs+aNQRw=; b=zeMu8We1q5QmwvGAA2R4qXDf0weT187r6tmOqsS6PqBtqteTcSIu+AHsalCbAbghpY tH7pEHnxXG0LBtUQt/layGHXNuBLFdcl4GXc8Xr/KhtjtKheFgAwKksht0ZXZn0V8F8M wfWv35e8PwF2fLH+cSSziC+wOcmzyEIPl0fXzhQkyddB5rqvLFK4R941TS50YjcGmAEg ZKX1a8jxSLfVZjDuTbCwYF/6AsvPAoC+OKcrwC+gCoK2YuE6SdvKt3Xo2KNbB4IZXPLt 53NQ8WJVtExwJQH4jI6LyneRvYfF9r8iCx9Vwl2tdwxcA3Nbku/EBEdv70hXbn9d5Y9n /yNQ== X-Gm-Message-State: AOAM530WixGdTGsOP1XpBkLWZLRXAzT8LBwU5IP+qL7EtYQ+YI80yAa3 UzzMdXyz/IwC0+RdVL5Ky1bObQc/6+v6 X-Google-Smtp-Source: ABdhPJwcdBH2/CcubIhmiZzDyEWmCcpO7mosFjotsrXWYeEg4n6tdPuWTq41wFk+BqgyWp7mP1ONEoHZhTPm X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:2745:: with SMTP id n66mr1726032ybn.120.1640245612852; Wed, 22 Dec 2021 23:46:52 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:11 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-19-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 18/48] perf cpumap: Refactor cpu_map__build_map 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Turn it into a cpu_aggr_map__new. Pass helper functions. Refactor builtin-stat calls to manually pass function pointers. Try to reduce some copy-paste code. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 187 ++++++++++++++++++++------------------ tools/perf/util/cpumap.c | 59 +++++------- tools/perf/util/cpumap.h | 16 ++-- 3 files changed, 130 insertions(+), 132 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d229fb71b577..2b04a948cf37 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1322,6 +1322,17 @@ static struct option stat_options[] =3D { OPT_END() }; =20 +static const char *const aggr_mode__string[] =3D { + [AGGR_CORE] =3D "core", + [AGGR_DIE] =3D "die", + [AGGR_GLOBAL] =3D "global", + [AGGR_NODE] =3D "node", + [AGGR_NONE] =3D "none", + [AGGR_SOCKET] =3D "socket", + [AGGR_THREAD] =3D "thread", + [AGGR_UNSET] =3D "unset", +}; + static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *c= onfig __maybe_unused, int cpu) { @@ -1394,54 +1405,67 @@ static bool term_percore_set(void) return false; } =20 -static int perf_stat_init_aggr_mode(void) +static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_mode aggr_mode) { - int nr; + switch (aggr_mode) { + case AGGR_SOCKET: + return cpu_map__get_socket_aggr_by_cpu; + case AGGR_DIE: + return cpu_map__get_die_aggr_by_cpu; + case AGGR_CORE: + return cpu_map__get_core_aggr_by_cpu; + case AGGR_NODE: + return cpu_map__get_node_aggr_by_cpu; + case AGGR_NONE: + if (term_percore_set()) + return cpu_map__get_core_aggr_by_cpu; + + return NULL; + case AGGR_GLOBAL: + case AGGR_THREAD: + case AGGR_UNSET: + default: + return NULL; + } +} =20 - switch (stat_config.aggr_mode) { +static aggr_get_id_t aggr_mode__get_id(enum aggr_mode aggr_mode) +{ + switch (aggr_mode) { case AGGR_SOCKET: - if (cpu_map__build_socket_map(evsel_list->core.cpus, &stat_config.aggr_m= ap)) { - perror("cannot build socket map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_socket_cached; - break; + return perf_stat__get_socket_cached; case AGGR_DIE: - if (cpu_map__build_die_map(evsel_list->core.cpus, &stat_config.aggr_map)= ) { - perror("cannot build die map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_die_cached; - break; + return perf_stat__get_die_cached; case AGGR_CORE: - if (cpu_map__build_core_map(evsel_list->core.cpus, &stat_config.aggr_map= )) { - perror("cannot build core map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_core_cached; - break; + return perf_stat__get_core_cached; case AGGR_NODE: - if (cpu_map__build_node_map(evsel_list->core.cpus, &stat_config.aggr_map= )) { - perror("cannot build core map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_node_cached; - break; + return perf_stat__get_node_cached; case AGGR_NONE: if (term_percore_set()) { - if (cpu_map__build_core_map(evsel_list->core.cpus, - &stat_config.aggr_map)) { - perror("cannot build core map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_core_cached; + return perf_stat__get_core_cached; } - break; + return NULL; case AGGR_GLOBAL: case AGGR_THREAD: case AGGR_UNSET: default: - break; + return NULL; + } +} + +static int perf_stat_init_aggr_mode(void) +{ + int nr; + aggr_cpu_id_get_t get_id =3D aggr_mode__get_aggr(stat_config.aggr_mode); + + if (get_id) { + stat_config.aggr_map =3D cpu_aggr_map__new(evsel_list->core.cpus, + get_id, /*data=3D*/NULL); + if (!stat_config.aggr_map) { + pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); + return -1; + } + stat_config.aggr_get_id =3D aggr_mode__get_id(stat_config.aggr_mode); } =20 /* @@ -1549,30 +1573,6 @@ static struct aggr_cpu_id perf_env__get_node_aggr_by= _cpu(int cpu, void *data) return id; } =20 -static int perf_env__build_socket_map(struct perf_env *env, struct perf_cp= u_map *cpus, - struct cpu_aggr_map **sockp) -{ - return cpu_map__build_map(cpus, sockp, perf_env__get_socket_aggr_by_cpu, = env); -} - -static int perf_env__build_die_map(struct perf_env *env, struct perf_cpu_m= ap *cpus, - struct cpu_aggr_map **diep) -{ - return cpu_map__build_map(cpus, diep, perf_env__get_die_aggr_by_cpu, env); -} - -static int perf_env__build_core_map(struct perf_env *env, struct perf_cpu_= map *cpus, - struct cpu_aggr_map **corep) -{ - return cpu_map__build_map(cpus, corep, perf_env__get_core_aggr_by_cpu, en= v); -} - -static int perf_env__build_node_map(struct perf_env *env, struct perf_cpu_= map *cpus, - struct cpu_aggr_map **nodep) -{ - return cpu_map__build_map(cpus, nodep, perf_env__get_node_aggr_by_cpu, en= v); -} - static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_conf= ig *config __maybe_unused, int cpu) { @@ -1596,47 +1596,60 @@ static struct aggr_cpu_id perf_stat__get_node_file(= struct perf_stat_config *conf return perf_env__get_node_aggr_by_cpu(cpu, &perf_stat.session->header.env= ); } =20 -static int perf_stat_init_aggr_mode_file(struct perf_stat *st) +static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) { - struct perf_env *env =3D &st->session->header.env; + switch (aggr_mode) { + case AGGR_SOCKET: + return perf_env__get_socket_aggr_by_cpu; + case AGGR_DIE: + return perf_env__get_die_aggr_by_cpu; + case AGGR_CORE: + return perf_env__get_core_aggr_by_cpu; + case AGGR_NODE: + return perf_env__get_node_aggr_by_cpu; + case AGGR_NONE: + case AGGR_GLOBAL: + case AGGR_THREAD: + case AGGR_UNSET: + default: + return NULL; + } +} =20 - switch (stat_config.aggr_mode) { +static aggr_get_id_t aggr_mode__get_id_file(enum aggr_mode aggr_mode) +{ + switch (aggr_mode) { case AGGR_SOCKET: - if (perf_env__build_socket_map(env, evsel_list->core.cpus, &stat_config.= aggr_map)) { - perror("cannot build socket map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_socket_file; - break; + return perf_stat__get_socket_file; case AGGR_DIE: - if (perf_env__build_die_map(env, evsel_list->core.cpus, &stat_config.agg= r_map)) { - perror("cannot build die map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_die_file; - break; + return perf_stat__get_die_file; case AGGR_CORE: - if (perf_env__build_core_map(env, evsel_list->core.cpus, &stat_config.ag= gr_map)) { - perror("cannot build core map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_core_file; - break; + return perf_stat__get_core_file; case AGGR_NODE: - if (perf_env__build_node_map(env, evsel_list->core.cpus, &stat_config.ag= gr_map)) { - perror("cannot build core map"); - return -1; - } - stat_config.aggr_get_id =3D perf_stat__get_node_file; - break; + return perf_stat__get_node_file; case AGGR_NONE: case AGGR_GLOBAL: case AGGR_THREAD: case AGGR_UNSET: default: - break; + return NULL; } +} + +static int perf_stat_init_aggr_mode_file(struct perf_stat *st) +{ + struct perf_env *env =3D &st->session->header.env; + aggr_cpu_id_get_t get_id =3D aggr_mode__get_aggr_file(stat_config.aggr_mo= de); =20 + if (!get_id) + return 0; + + stat_config.aggr_map =3D cpu_aggr_map__new(evsel_list->core.cpus, get_id,= env); + if (!stat_config.aggr_map) { + pr_err("cannot build %s map", aggr_mode__string[stat_config.aggr_mode]); + return -1; + } + stat_config.aggr_get_id =3D aggr_mode__get_id_file(stat_config.aggr_mode); return 0; } =20 diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 32f9fc2dd389..ba4468f691c8 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -140,7 +140,7 @@ struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int = cpu, void *data __maybe_u return id; } =20 -static int cmp_aggr_cpu_id(const void *a_pointer, const void *b_pointer) +static int aggr_cpu_id__cmp(const void *a_pointer, const void *b_pointer) { struct aggr_cpu_id *a =3D (struct aggr_cpu_id *)a_pointer; struct aggr_cpu_id *b =3D (struct aggr_cpu_id *)b_pointer; @@ -157,37 +157,40 @@ static int cmp_aggr_cpu_id(const void *a_pointer, con= st void *b_pointer) return a->thread - b->thread; } =20 -int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **re= s, - struct aggr_cpu_id (*f)(int cpu, void *data), - void *data) +struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, + aggr_cpu_id_get_t f, + void *data) { - int nr =3D cpus->nr; - struct cpu_aggr_map *c =3D cpu_aggr_map__empty_new(nr); - int cpu, s2; - struct aggr_cpu_id s1; + int cpu, idx; + struct cpu_aggr_map *c =3D cpu_aggr_map__empty_new(cpus->nr); =20 if (!c) - return -1; + return NULL; =20 /* Reset size as it may only be partially filled */ c->nr =3D 0; =20 - for (cpu =3D 0; cpu < nr; cpu++) { - s1 =3D f(cpu, data); - for (s2 =3D 0; s2 < c->nr; s2++) { - if (aggr_cpu_id__equal(&s1, &c->map[s2])) + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + bool duplicate =3D false; + struct aggr_cpu_id cpu_id =3D f(cpu, data); + + for (int j =3D 0; j < c->nr; j++) { + if (aggr_cpu_id__equal(&cpu_id, &c->map[j])) { + duplicate =3D true; break; + } } - if (s2 =3D=3D c->nr) { - c->map[c->nr] =3D s1; + if (!duplicate) { + c->map[c->nr] =3D cpu_id; c->nr++; } } + /* ensure we process id in increasing order */ - qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), cmp_aggr_cpu_id); + qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); + + return c; =20 - *res =3D c; - return 0; } =20 int cpu__get_die_id(int cpu) @@ -253,26 +256,6 @@ struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int c= pu, void *data __maybe_unu return id; } =20 -int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp) -{ - return cpu_map__build_map(cpus, sockp, cpu_map__get_socket_aggr_by_cpu, N= ULL); -} - -int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map = **diep) -{ - return cpu_map__build_map(cpus, diep, cpu_map__get_die_aggr_by_cpu, NULL); -} - -int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **corep) -{ - return cpu_map__build_map(cpus, corep, cpu_map__get_core_aggr_by_cpu, NUL= L); -} - -int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **numap) -{ - return cpu_map__build_map(cpus, numap, cpu_map__get_node_aggr_by_cpu, NUL= L); -} - /* setup simple routines to easily access node numbers given a cpu number = */ static int get_max_num(char *path, int *max) { diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 87545bcd461d..02e8c80fea0a 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -43,10 +43,6 @@ struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int c= pu, void *data); struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); -int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_m= ap **sockp); -int cpu_map__build_die_map(struct perf_cpu_map *cpus, struct cpu_aggr_map = **diep); -int cpu_map__build_core_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **corep); -int cpu_map__build_node_map(struct perf_cpu_map *cpus, struct cpu_aggr_map= **nodep); const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ =20 int cpu__setup_cpunode_map(void); @@ -75,10 +71,16 @@ int cpu__get_die_id(int cpu); */ int cpu__get_core_id(int cpu); =20 +typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(int cpu, void *data); =20 -int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **re= s, - struct aggr_cpu_id (*f)(int cpu, void *data), - void *data); +/** + * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each = cpu in + * cpus. The aggr_cpu_id is created with 'f' that may have a data value pa= ssed + * to it. The cpu_aggr_map is sorted with duplicate values removed. + */ +struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, + aggr_cpu_id_get_t f, + void *data); =20 bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 329E7C433EF for ; Thu, 23 Dec 2021 07:47:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347261AbhLWHr4 (ORCPT ); Thu, 23 Dec 2021 02:47:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347075AbhLWHrD (ORCPT ); Thu, 23 Dec 2021 02:47:03 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D181C06175B for ; Wed, 22 Dec 2021 23:46:56 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id q198-20020a25d9cf000000b005f7a6a84f9fso8567449ybg.6 for ; Wed, 22 Dec 2021 23:46:56 -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=MpQ9JbQr3HlpwnDJApfNQMTPoiVpc8Vmb9u/K5T47HA=; b=qwAHiOgIXlSa8wzdii8vzLZkZ7YeP4F8PPIJduxf8StSUXQOcCelsewNrRw/KLc9So n3An1dNZxVbbb5TRWl1YL1ZA6etm7YBs7UZ3w/Taul6jGKfL0qys9W6VQiE4wzC38+iv n1eBoZurEM7l1a1PS61AhWBv498kY/PujSTOSNuuJTPzjM8Wuxpfv2i5G5+wCu70IoP5 5/kA2sgQBN0DUybhldTcHY51zvc/NMTE838RztRO1oP/+PbeQhWHgYKD9NAaMGLyhicw QIyhNrnWPrINMHY2A0CaLRWAhnRTB5S3YCunhq98V+aZFVijWyfVP7FSyQ7g8OZRYSKA eFQQ== 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=MpQ9JbQr3HlpwnDJApfNQMTPoiVpc8Vmb9u/K5T47HA=; b=V2O5ZMFgOKXknFuQq+k7P5+7QsSIizGASe3eHALdVYU7mIFXuqNkArEOgWe7QxfuzY a2mM1s/mU3f600lcugNcXhYBALppVqptX1AVMY6L0zVATIi2X//sSLhuhonYf7LcRztL aCZJjBpyStAnyiG3rCl89DybjC3zmckfAU/JykxthdcmxHp+cT7kPAIAs7VqbkqtezFn 9uSThjfyf42VHCG9qbRLfElpM3JZ52cgEgj6ZoqBD+uuG3ssWc195i6v/lrV/2oXoeZ0 A0X7/9EKJA5w2EJiqd4zNQTUL0DmWGZ9FEtV8UEZqMo83uqjhzoD4egeFoIlzAZW446G jDVw== X-Gm-Message-State: AOAM5313eWcytcdhW6R4rLdTO8Rey9TV34DjKwVO6DMwpiz4aXKWmerl ucGAa0sWxcWTXgGShQRuaBx2/bRL/IAw X-Google-Smtp-Source: ABdhPJx6e0CPGdyQKuaH3pga3LQ6mgyRV1se1FBJer87qYIGCvW0v+4KhJ/ZQjzvXJIQeHqrFdg8Q9vzsB51 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:26cb:: with SMTP id m194mr1631918ybm.558.1640245615441; Wed, 22 Dec 2021 23:46:55 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:12 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-20-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 19/48] perf cpumap: Rename cpu_map__get_X_aggr_by_cpu functions 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The functions don't use a cpu_map so reduce them to being like constructors of aggr_cpu_id. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 18 +++++++++--------- tools/perf/tests/topology.c | 8 ++++---- tools/perf/util/cpumap.c | 14 +++++++------- tools/perf/util/cpumap.h | 29 +++++++++++++++++++++++++---- 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 2b04a948cf37..98f80c217279 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1336,25 +1336,25 @@ static const char *const aggr_mode__string[] =3D { static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *c= onfig __maybe_unused, int cpu) { - return cpu_map__get_socket_aggr_by_cpu(cpu, /*data=3D*/NULL); + return aggr_cpu_id__socket(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_die(struct perf_stat_config *conf= ig __maybe_unused, int cpu) { - return cpu_map__get_die_aggr_by_cpu(cpu, /*data=3D*/NULL); + return aggr_cpu_id__die(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_core(struct perf_stat_config *con= fig __maybe_unused, int cpu) { - return cpu_map__get_core_aggr_by_cpu(cpu, /*data=3D*/NULL); + return aggr_cpu_id__core(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *con= fig __maybe_unused, int cpu) { - return cpu_map__get_node_aggr_by_cpu(cpu, /*data=3D*/NULL); + return aggr_cpu_id__node(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *con= fig, @@ -1409,16 +1409,16 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum a= ggr_mode aggr_mode) { switch (aggr_mode) { case AGGR_SOCKET: - return cpu_map__get_socket_aggr_by_cpu; + return aggr_cpu_id__socket; case AGGR_DIE: - return cpu_map__get_die_aggr_by_cpu; + return aggr_cpu_id__die; case AGGR_CORE: - return cpu_map__get_core_aggr_by_cpu; + return aggr_cpu_id__core; case AGGR_NODE: - return cpu_map__get_node_aggr_by_cpu; + return aggr_cpu_id__node; case AGGR_NONE: if (term_percore_set()) - return cpu_map__get_core_aggr_by_cpu; + return aggr_cpu_id__core; =20 return NULL; case AGGR_GLOBAL: diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 5992b323c4f5..0cb7b015b4b9 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -121,7 +121,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that core ID contains socket, die and core for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_core_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id =3D aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Core map - Core ID doesn't match", session->header.env.cpu[map->map[i]].core_id =3D=3D id.core); =20 @@ -136,7 +136,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that die ID contains socket and die for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_die_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id =3D aggr_cpu_id__die(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Die map - Socket ID doesn't match", session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); =20 @@ -150,7 +150,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that socket ID contains only socket for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_socket_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id =3D aggr_cpu_id__socket(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Socket map - Socket ID doesn't match", session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); =20 @@ -162,7 +162,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 // Test that node ID contains only node for (i =3D 0; i < map->nr; i++) { - id =3D cpu_map__get_node_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id =3D aggr_cpu_id__node(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Node map - Node ID doesn't match", cpu__get_node(map->map[i]) =3D=3D id.node); TEST_ASSERT_VAL("Node map - Socket is set", id.socket =3D=3D -1); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index ba4468f691c8..0e325559c33c 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -132,7 +132,7 @@ int cpu__get_socket_id(int cpu) return ret ?: value; } =20 -struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data __m= aybe_unused) +struct aggr_cpu_id aggr_cpu_id__socket(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 @@ -200,7 +200,7 @@ int cpu__get_die_id(int cpu) return ret ?: value; } =20 -struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data) +struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data) { struct aggr_cpu_id id; int die; @@ -215,7 +215,7 @@ struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu= , void *data) * with the socket ID and then add die to * make a unique ID. */ - id =3D cpu_map__get_socket_aggr_by_cpu(cpu, data); + id =3D aggr_cpu_id__socket(cpu, data); if (aggr_cpu_id__is_empty(&id)) return id; =20 @@ -229,13 +229,13 @@ int cpu__get_core_id(int cpu) return ret ?: value; } =20 -struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data) +struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data) { struct aggr_cpu_id id; int core =3D cpu__get_core_id(cpu); =20 - /* cpu_map__get_die returns a struct with socket and die set*/ - id =3D cpu_map__get_die_aggr_by_cpu(cpu, data); + /* aggr_cpu_id__die returns a struct with socket and die set*/ + id =3D aggr_cpu_id__die(cpu, data); if (aggr_cpu_id__is_empty(&id)) return id; =20 @@ -248,7 +248,7 @@ struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cp= u, void *data) =20 } =20 -struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data __may= be_unused) +struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 02e8c80fea0a..15043e764fa6 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -39,10 +39,6 @@ struct perf_cpu_map *cpu_map__new_data(struct perf_recor= d_cpu_map_data *data); size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t s= ize); size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp); -struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data); -struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data); -struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data); -struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data); const struct perf_cpu_map *cpu_map__online(void); /* thread unsafe */ =20 int cpu__setup_cpunode_map(void); @@ -88,4 +84,29 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, con= st struct aggr_cpu_id *b bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a); struct aggr_cpu_id aggr_cpu_id__empty(void); =20 + +/** + * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated w= ith + * the socket for cpu. The function signature is compatible with + * aggr_cpu_id_get_t. + */ +struct aggr_cpu_id aggr_cpu_id__socket(int cpu, void *data); +/** + * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket popula= ted + * with the die and socket for cpu. The function signature is compatible w= ith + * aggr_cpu_id_get_t. + */ +struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data); +/** + * aggr_cpu_id__core - Create an aggr_cpu_id with the core, die and socket + * populated with the core, die and socket for cpu. The function signature= is + * compatible with aggr_cpu_id_get_t. + */ +struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data); +/** + * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated = for + * cpu. The function signature is compatible with aggr_cpu_id_get_t. + */ +struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data); + #endif /* __PERF_CPUMAP_H */ --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CA16C433FE for ; Thu, 23 Dec 2021 07:47:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347133AbhLWHr5 (ORCPT ); Thu, 23 Dec 2021 02:47:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347089AbhLWHrD (ORCPT ); Thu, 23 Dec 2021 02:47:03 -0500 Received: from mail-pf1-x44a.google.com (mail-pf1-x44a.google.com [IPv6:2607:f8b0:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9E4CC061761 for ; Wed, 22 Dec 2021 23:46:58 -0800 (PST) Received: by mail-pf1-x44a.google.com with SMTP id i3-20020a628703000000b004ba462357d6so2934443pfe.23 for ; Wed, 22 Dec 2021 23:46:58 -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=wzNfHRH15UqedWU0GeHamcoaHHXLikx8Lp67BsvKm/8=; b=DswF2V/+HCId512V6RYlFazEkdCZKdunTz5HyGerKtovNwGST7qqcC2D/TL9xmJs7S N97OmhgO37H6HsbsLP0PP5RLzWwWEHY9cIOwRjb5Rvx8QfLOuWAdLuee5KheCboF0lET YnGwiMu8ravg0kcelU9B9II23oztB6OdYp2fDOBhagT7M9fNWrMZjApCa5vsmRnnrtEi lwQDC6RbZNHJvgzbjg/vGG9CTK2iQ0oGOKkG7gbHjABmU62/IzNnfDKBwKTZsmJ1651/ jNhiLzyQzPOken7ZJ+v04lBQEdCXtzVhutiwEm/4x/UtY8xI20fIxXa/asD+fdcQvtxJ ok+Q== 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=wzNfHRH15UqedWU0GeHamcoaHHXLikx8Lp67BsvKm/8=; b=beIi0Y18Il3NdJC+KO1MtX9nsR5pbOFJ2TdH/VxDnfZ6k325ArTIRUJJA9V1G5UJwZ oBhpcgNcD3JsHeSRMce7MXqFiW8RVO6dO99PAQmm5WWq+9tfhXxTND2lSkKWJ6fMpMjz yaClCpz/8H2e19Su5oOmJqMhpFXZ93L5o87Lxd53offXHw0BDLbIqA0+eucibIhD9i3Q iqKD1Z7nQJJb+VCZBHjuoagNNoA74lX0mssAKrfSHcn3LUNwbWOj7q2nSVl8WeOgCGQF qAUw8GhMSUP17p249n5o/0ARvdMg4WBbFW1KdMIADOX2H8cGYfcaff9ast37miKv5Q0L TH6w== X-Gm-Message-State: AOAM532LffiWb16dixl45dNJCmiIPRQ5zWUUMzDrEBTIFuZiYlrZaPeh ZOiqOQs2LB9A39n7rjlvOYtmNwgAo5K3 X-Google-Smtp-Source: ABdhPJxaI28ohdtPvEYm0D2zTZ62SQ2bUo280IlPmfflMrBSZ1Crt7N5E3JMsGsRQ1x2gx0b1SebIoEJBQr6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a17:90a:ba03:: with SMTP id s3mr1668443pjr.219.1640245618142; Wed, 22 Dec 2021 23:46:58 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:13 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-21-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 20/48] perf cpumap: Move 'has' function to libperf 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make the cpu map argument const for consistency with the rest of the API. Modify cpu_map__idx accordingly. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 7 ++++++- tools/lib/perf/include/internal/cpumap.h | 2 +- tools/lib/perf/include/perf/cpumap.h | 1 + tools/perf/arch/arm/util/cs-etm.c | 16 ++++++++-------- tools/perf/builtin-sched.c | 6 +++--- tools/perf/tests/topology.c | 2 +- tools/perf/util/cpumap.c | 5 ----- tools/perf/util/cpumap.h | 2 -- tools/perf/util/cputopo.c | 2 +- 9 files changed, 21 insertions(+), 22 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index adaad3dddf6e..3c36a06771af 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -268,7 +268,7 @@ bool perf_cpu_map__empty(const struct perf_cpu_map *map) return map ? map->map[0] =3D=3D -1 : true; } =20 -int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu) +int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu) { int low =3D 0, high =3D cpus->nr; =20 @@ -288,6 +288,11 @@ int perf_cpu_map__idx(struct perf_cpu_map *cpus, int c= pu) return -1; } =20 +bool perf_cpu_map__has(const struct perf_cpu_map *cpus, int cpu) +{ + return perf_cpu_map__idx(cpus, cpu) !=3D -1; +} + int perf_cpu_map__max(struct perf_cpu_map *map) { // cpu_map__trim_new() qsort()s it, cpu_map__default_new() sorts it as we= ll. diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/incl= ude/internal/cpumap.h index 4054169c12c5..71a31ed738c9 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -23,6 +23,6 @@ struct perf_cpu_map { #define MAX_NR_CPUS 2048 #endif =20 -int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu); +int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu); =20 #endif /* __LIBPERF_INTERNAL_CPUMAP_H */ diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 7c27766ea0bf..3f1c0afa3ccd 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -20,6 +20,7 @@ LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_m= ap *cpus, int idx); LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); LIBPERF_API int perf_cpu_map__max(struct perf_cpu_map *map); +LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, int cpu= ); =20 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) =3D 0, (cpu) =3D perf_cpu_map__cpu(cpus, idx); \ diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index 293a23bf8be3..76c66780617c 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -204,8 +204,8 @@ static int cs_etm_set_option(struct auxtrace_record *it= r, =20 /* Set option of each CPU we have */ for (i =3D 0; i < cpu__max_cpu(); i++) { - if (!cpu_map__has(event_cpus, i) || - !cpu_map__has(online_cpus, i)) + if (!perf_cpu_map__has(event_cpus, i) || + !perf_cpu_map__has(online_cpus, i)) continue; =20 if (option & BIT(ETM_OPT_CTXTID)) { @@ -542,8 +542,8 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __may= be_unused, /* cpu map is not empty, we have specific CPUs to work with */ if (!perf_cpu_map__empty(event_cpus)) { for (i =3D 0; i < cpu__max_cpu(); i++) { - if (!cpu_map__has(event_cpus, i) || - !cpu_map__has(online_cpus, i)) + if (!perf_cpu_map__has(event_cpus, i) || + !perf_cpu_map__has(online_cpus, i)) continue; =20 if (cs_etm_is_ete(itr, i)) @@ -556,7 +556,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __may= be_unused, } else { /* get configuration for all CPUs in the system */ for (i =3D 0; i < cpu__max_cpu(); i++) { - if (!cpu_map__has(online_cpus, i)) + if (!perf_cpu_map__has(online_cpus, i)) continue; =20 if (cs_etm_is_ete(itr, i)) @@ -741,8 +741,8 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, } else { /* Make sure all specified CPUs are online */ for (i =3D 0; i < perf_cpu_map__nr(event_cpus); i++) { - if (cpu_map__has(event_cpus, i) && - !cpu_map__has(online_cpus, i)) + if (perf_cpu_map__has(event_cpus, i) && + !perf_cpu_map__has(online_cpus, i)) return -EINVAL; } =20 @@ -763,7 +763,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, offset =3D CS_ETM_SNAPSHOT + 1; =20 for (i =3D 0; i < cpu__max_cpu() && offset < priv_size; i++) - if (cpu_map__has(cpu_map, i)) + if (perf_cpu_map__has(cpu_map, i)) cs_etm_get_metadata(i, &offset, itr, info); =20 perf_cpu_map__put(online_cpus); diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 4527f632ebe4..9da1da4749c9 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -1617,10 +1617,10 @@ static int map_switch_event(struct perf_sched *sche= d, struct evsel *evsel, if (curr_thread && thread__has_color(curr_thread)) pid_color =3D COLOR_PIDS; =20 - if (sched->map.cpus && !cpu_map__has(sched->map.cpus, cpu)) + if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, cpu)) continue; =20 - if (sched->map.color_cpus && cpu_map__has(sched->map.color_cpus, cpu)) + if (sched->map.color_cpus && perf_cpu_map__has(sched->map.color_cpus, cp= u)) cpu_color =3D COLOR_CPUS; =20 if (cpu !=3D this_cpu) @@ -1639,7 +1639,7 @@ static int map_switch_event(struct perf_sched *sched,= struct evsel *evsel, color_fprintf(stdout, color, " "); } =20 - if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu)) + if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, this_cpu)) goto out; =20 timestamp__scnprintf_usec(timestamp, stimestamp, sizeof(stimestamp)); diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 0cb7b015b4b9..cb29ea7ec409 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -112,7 +112,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu= ); =20 for (i =3D 0; i < session->header.env.nr_cpus_avail; i++) { - if (!cpu_map__has(map, i)) + if (!perf_cpu_map__has(map, i)) continue; pr_debug("CPU %d, core %d, socket %d\n", i, session->header.env.cpu[i].core_id, diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 0e325559c33c..8a72ee996722 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -463,11 +463,6 @@ int cpu__setup_cpunode_map(void) return 0; } =20 -bool cpu_map__has(struct perf_cpu_map *cpus, int cpu) -{ - return perf_cpu_map__idx(cpus, cpu) !=3D -1; -} - size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) { int i, cpu, start =3D -1; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 15043e764fa6..832fc53f3c11 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -78,8 +78,6 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_= cpu_map *cpus, aggr_cpu_id_get_t f, void *data); =20 -bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); - bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu= _id *b); bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a); struct aggr_cpu_id aggr_cpu_id__empty(void); diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 51b429c86f98..8affb37d90e7 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -218,7 +218,7 @@ struct cpu_topology *cpu_topology__new(void) tp->core_cpus_list =3D addr; =20 for (i =3D 0; i < nr; i++) { - if (!cpu_map__has(map, i)) + if (!perf_cpu_map__has(map, i)) continue; =20 ret =3D build_cpu_topology(tp, i); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACF92C433EF for ; Thu, 23 Dec 2021 07:48:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347140AbhLWHr7 (ORCPT ); Thu, 23 Dec 2021 02:47:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347109AbhLWHrD (ORCPT ); Thu, 23 Dec 2021 02:47:03 -0500 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 9B672C061792 for ; Wed, 22 Dec 2021 23:47:01 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id j204-20020a2523d5000000b005c21574c704so8596840ybj.13 for ; Wed, 22 Dec 2021 23:47:01 -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=jkb8WQdF9O+yiT4urJzPw184L/fpHPkSKVmnEzvHNI4=; b=cjmUrPorOPwMSR8Clp9D3BUztfdQynd9f+mTH9gfaUFdKwgXLjEpecPhtWm10pTf95 kUko6md3ZhP8VUeVp+cOBc0Jy7VYksiU+XwG9bEZJZwyYpL5+WlBI25m6x8I0AoE7YBy /5hIfsd9OEg5Sd6a2fM8L2GTWOy0Qy3BrRE2imlAsxGVpL2bAMTuwSXqDv6IBpjLDw28 Cih2qQTG3eSXRCzQsGWh/12JzeNtpxdPyM8wv8uXQza4zo9nnDbamcbPPwJEiqNLD2q9 b6L5BCdYsBLbBj+19qoSMjTDstctOdLIIZKT6surEGtmeqFG6rPdV/KQvv303T+YxZTW YSAA== 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=jkb8WQdF9O+yiT4urJzPw184L/fpHPkSKVmnEzvHNI4=; b=eEifWoVlvK0r4WtdBGUMQJCACqcyr6szRqlJt4Z/Enh2lU0c0kK/i8IeGIMT59Sv0W 27qDIJKnfpni0KbXvH/xlQqB6vvCVvjjv0tEzcF17H5MgLhK5kgSu60JkRov17A9azER oyHbe93dSeayVGOnUtVJ1dnBT9Tj8PoL4xN+XtjZDZIeiDEq7Vx2JbafHEiqzx/hi7V3 wFrZkhwS40k8YKVIaT9PGsw4eBD/j6loMU1egWnQPMNpR+r/hIkQcM4DwwiBB2GLSkCZ k3Xt82VrDspmWIQjDQfVcjHgqaVIamDTF9SVRaDhLjtddvU3YTdqE64OWpXzVn2FBp5w TPgQ== X-Gm-Message-State: AOAM533kWdUWsE+z3edgNXd9dmhGw5N9LNqUOmAE7UqMs96CcgF1v5+y U/aSWsr5CmzQiEEUQwMFl1ivuL4c7xVq X-Google-Smtp-Source: ABdhPJzRHzlckq6o8uuyeTGVvKZ4mtq8Xw/HKmt9jKvhxGET/afj05hc3jdaQ7vdvPJiKVhC3up45BXHd1bO X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:d492:: with SMTP id m140mr1874549ybf.105.1640245620849; Wed, 22 Dec 2021 23:47:00 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:14 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-22-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 21/48] perf cpumap: Add some comments to cpu_aggr_map 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move cpu_aggr_map__empty_new to be with other cpu_aggr_map function. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 832fc53f3c11..8acef8ff8753 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -24,16 +24,18 @@ struct aggr_cpu_id { int core; }; =20 +/** A collection of aggr_cpu_id values, the "built" version is sorted and = uniqued. */ struct cpu_aggr_map { refcount_t refcnt; + /** Number of valid entries. */ int nr; + /** The entries. */ struct aggr_cpu_id map[]; }; =20 struct perf_record_cpu_map_data; =20 struct perf_cpu_map *perf_cpu_map__empty_new(int nr); -struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr); =20 struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *da= ta); size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size); @@ -67,6 +69,12 @@ int cpu__get_die_id(int cpu); */ int cpu__get_core_id(int cpu); =20 +/** + * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every e= ntry + * being empty. + */ +struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr); + typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(int cpu, void *data); =20 /** --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31082C4332F for ; Thu, 23 Dec 2021 07:48:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347278AbhLWHsA (ORCPT ); Thu, 23 Dec 2021 02:48:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347051AbhLWHrE (ORCPT ); Thu, 23 Dec 2021 02:47:04 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3762EC06175C for ; Wed, 22 Dec 2021 23:47:04 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id l28-20020a25b31c000000b005c27dd4987bso8672867ybj.18 for ; Wed, 22 Dec 2021 23:47:04 -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=g+jHwVdZi4B6GdlseRL5ELravrR1guQUj3kmE+JxJm8=; b=B4vGh4VAwLBWoylESSncozctWph8CS0QeXEDByAGcppY0P9nGS+w0sesanM55ugnTb /WeQLHISwQs5H67cPQnSua2Nv8OVey40AvwtwE7MS8fnMzVzOLotHejQLZGxfngrjVmg eiFVHMK1vm4UIfShpqDMENuOb/UP8N/tb4OfV5u6posui4nDhzqGmws+NoJTfHMEwwKl Ii9nULWt4Nr/FZPmXsSUcOoD1XDYyygsPgXfI03AExcHvQYq2JnZUliOn+dhu7LMyiSx x5l71m2SkIjskS2sLqKmkBGSjqM6TahyIFmkR78SzfYbz8+ezWQO8YfHJL6xkP5lTKVY 1oWA== 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=g+jHwVdZi4B6GdlseRL5ELravrR1guQUj3kmE+JxJm8=; b=mc6qWtLU/Rr2nS13+P6mLM1ulqF5PiCRVgA2dUEhNnvOK/G85GxK2OIHNWoGtloGWl H6nj3MVt91sbHixqu3hIeQbUkJmNuBlAqGeghU9fBWqKSeiF1m8RAkHpXg8LGT9CUbVo JoW34Zrpzr1d1J6jq8eu6QXfVhMcPNVDu0r7xCO2GVmv8YHXVPY7CbRD3V98NrCxci0G fbYslGOuwb8t/bhSfUYk+BDPfZllhgkzEdQpMSI9WRyOiXlcuOTlx0NgD4lUjJ8G0hfC 0wstEqax3hgWlAXHLnUjQbZVOOUB8mg/QDn3QtVF9mpAtlqurBCykf77N1HA0bVdpn+h 13WA== X-Gm-Message-State: AOAM530l4IwVcWGXOMmf5xFtl32IMmZZOM1PsWqqQRgWU2FtacvAHT9p 2xSMVA0xHtz0qOtgW1Avzo/B4cBY1AW9 X-Google-Smtp-Source: ABdhPJzg3LpTwWlyt8N1+tZ1tGQQMdgr2r8ENnhl+i42HOW9nej5lVbnMNKfVUy+kRwpLQ/89koZK4xBlfoK X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:7dc4:: with SMTP id y187mr1800387ybc.165.1640245623434; Wed, 22 Dec 2021 23:47:03 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:15 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-23-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 22/48] perf cpumap: Trim the cpu_aggr_map 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cpu_aggr_map__new removes duplicates, when this happens shrink the array. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/cpumap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 8a72ee996722..985c87f1f1ca 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -185,7 +185,12 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct pe= rf_cpu_map *cpus, c->nr++; } } - + /* Trim. */ + if (c->nr !=3D cpus->nr) { + c =3D realloc(c, sizeof(struct cpu_aggr_map) + sizeof(struct aggr_cpu_id= ) * c->nr); + if (!c) + return NULL; + } /* ensure we process id in increasing order */ qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30CF5C4332F for ; Thu, 23 Dec 2021 07:48:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347292AbhLWHsE (ORCPT ); Thu, 23 Dec 2021 02:48:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347130AbhLWHrJ (ORCPT ); Thu, 23 Dec 2021 02:47:09 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94CB2C06179E for ; Wed, 22 Dec 2021 23:47:06 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id y125-20020a25dc83000000b005c2326bf744so8489264ybe.21 for ; Wed, 22 Dec 2021 23:47:06 -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=J5Uxwz+NmtGEEgwvjL1sqJyX0/ppatr3BMcnhgtMNdI=; b=P+SChYI6l4zrhclWgOqBwpBXlMLUJiQXf8pyYNraVwtkdhs7KWxi4SHRuEs8Dijfgf kB1zINsX/1g3a6FuZyqmfEelCd7gyfYYCTtIpCFy2FxhV/ZOBHyDptAOnFsp6C3HVdhZ WkVyOVFxTKqSjMdxYGMUpMXp9RUfPetQ9mrev4LzHC+t+v611w5UC2P5sKBbddh+XkzM pg59NoJ+Ls4g/9bHvkjqV+KQiVTf3LaRBoNk7NzWdeke3jAlFx+a+gTeOmLXbtjIkBQC mTMKim6DKViJkpsGVDSFhFS1zlCWZl3Kwh+HIU/qNb+pACBdW1rcVEGSg+8ihB9wPwgx RKCw== 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=J5Uxwz+NmtGEEgwvjL1sqJyX0/ppatr3BMcnhgtMNdI=; b=Xx3edXxXaVcmHUsn8PobCQSoWTxqcolgD8s/CEiazSUBOP0FX+o6PWKtuQoqyqz2kg HOOAll1/HQHORneVlVH18hXV9kXn4a0zvr1hu2uPMkfYc9cS4YpPeIOwSHenZWTxH0sH QBqbhrp6pBplarUOPtXv98ffTSmly6jCLAqFWJO4TVtS9rrnv+jmlCcPGWyGb9l+4Tel Pq6ZwMAHahFdknRKjuJdbJgMXoGawI5RF+JN07CbWU0Ldc/Y62HJYA5tZgQCHOg6SXYX jPF1QevMS4Yy2NSq91GdQtQ8xb0jT6b/Dmzd51/CX2LgfGiuQ4ooZwVwAztPW8orkcAw 308A== X-Gm-Message-State: AOAM531+BvDfpkaGENaEcKavXhCVW4+ZQIt8D+bKqw6c8td7cGflJwQx 8hoEBDKMdADQ952oUpXbLC5NuFGlC+Ko X-Google-Smtp-Source: ABdhPJzuyhZb4oXRwSxm+ExXDmsSz287nUms3ZLP6USDOSqq/SCugWDf3aY2ieELM5n9Z8Xd11OZuvQJU437 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:ac23:: with SMTP id w35mr1680442ybi.341.1640245625867; Wed, 22 Dec 2021 23:47:05 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:16 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-24-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 23/48] perf stat: Fix memory leak in check_per_pkg 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If the key is already present then free the key used for lookup. Found with: $ perf stat -M IO_Read_BW /bin/true =3D=3D1749112=3D=3DERROR: LeakSanitizer: detected memory leaks Direct leak of 32 byte(s) in 4 object(s) allocated from: #0 0x7f6f6fa7d7cf in __interceptor_malloc ../../../../src/libsanitizer/= asan/asan_malloc_linux.cpp:145 #1 0x55acecd9d7a6 in check_per_pkg util/stat.c:343 #2 0x55acecd9d9c5 in process_counter_values util/stat.c:365 #3 0x55acecd9e0ab in process_counter_maps util/stat.c:421 #4 0x55acecd9e292 in perf_stat_process_counter util/stat.c:443 #5 0x55aceca8553e in read_counters ./tools/perf/builtin-stat.c:470 #6 0x55aceca88fe3 in __run_perf_stat ./tools/perf/builtin-stat.c:1023 #7 0x55aceca89146 in run_perf_stat ./tools/perf/builtin-stat.c:1048 #8 0x55aceca90858 in cmd_stat ./tools/perf/builtin-stat.c:2555 #9 0x55acecc05fa5 in run_builtin ./tools/perf/perf.c:313 #10 0x55acecc064fe in handle_internal_command ./tools/perf/perf.c:365 #11 0x55acecc068bb in run_argv ./tools/perf/perf.c:409 #12 0x55acecc070aa in main ./tools/perf/perf.c:539 Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/stat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 5c24aca0968c..c69b221f5e3e 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -345,9 +345,10 @@ static int check_per_pkg(struct evsel *counter, return -ENOMEM; =20 *key =3D (uint64_t)d << 32 | s; - if (hashmap__find(mask, (void *)key, NULL)) + if (hashmap__find(mask, (void *)key, NULL)) { *skip =3D true; - else + free(key); + } else ret =3D hashmap__add(mask, (void *)key, (void *)1); =20 return ret; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80BE7C433F5 for ; Thu, 23 Dec 2021 07:48:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347306AbhLWHsG (ORCPT ); Thu, 23 Dec 2021 02:48:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347143AbhLWHrL (ORCPT ); Thu, 23 Dec 2021 02:47:11 -0500 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 37B09C0617A2 for ; Wed, 22 Dec 2021 23:47:09 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id h5-20020a255f45000000b005ffd939127bso8564808ybm.10 for ; Wed, 22 Dec 2021 23:47:09 -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=4fl4+/RnYjZ/c1n8ssVcVocIenEbnGshJWO17sTd1Uo=; b=oJfnWHmlynNBn19s9/HxQ1IK3WCOMXNxc7scb8vAYOYBizAcv9o6gqt8VqdYzDtnr9 QljlK4aAp9ZJ6wHnEFE+wHnQEJgax6fbyNSRiXoXMnp3fdxKYbuOFB3tsUbPLAHwdv09 UH6ahZ/BtFOvBp/9oAKJ7iNLsGXSpwH3K+nNRMfTfyiIAKSa2AbIPoyUU2G0JA30bfhO qRF0vfNwvNwh4XGqRc2shAkpVko8NMIOzTgm4GTLUms/OfNG8Wj5A5lAs4V7aFY2kFj1 9NaVeAdM/eY304F8LTLkma1ZlpExQNsO1n+Wso+/AirzMTq0Q08KXvl22VIMPvmgu8Z1 umTQ== 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=4fl4+/RnYjZ/c1n8ssVcVocIenEbnGshJWO17sTd1Uo=; b=5nIljoOZVeTEGlD9iLBcAFW3Vm0QNB78RSgQW4KKQKFQBhUTxhshxoPzIsjLEn9Mda HZy6pI9FS+pLvCB31i10IQiiXZK1ftCrxRkBbyBvx86lQ/nSHxU5Cl3hxuMCjjL3CGq2 FqOi3+k0J3P6yJkqeHijQ7CSh5BB0SLJCur/4k8T42xbPNzawXEFlGN0DCsGWWCCeDb+ jLdxsELnIxi0CcY70Y1rcfdk48kJJ1TEB2ZNNXAi2/eeegsorh6vg6bCJNwv4hFmfesY kWy/IkqyaEV+KQn46dRGTnB5Q1PhDytC6VIy5Xb9d4o/nPqNliNCeWtSLgRREsxucL7d /jyQ== X-Gm-Message-State: AOAM530Dyp0fZGFQkUP4l8Gyf+Vp+a6+gyNVkSu6V0gigvRgfSTJWaum HV3utjtUofhO8jfkEe/cnkv/8b88Xz0e X-Google-Smtp-Source: ABdhPJxeDyR4cL1775cPklXCUGbNUUrez4v3eL6JgYpB5hpzHlaMeypTbkzUhbIYH0sAg4bmvOd4T9kLv+ZI X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a05:6902:706:: with SMTP id k6mr1788789ybt.643.1640245628437; Wed, 22 Dec 2021 23:47:08 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:17 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-25-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 24/48] perf cpumap: Add CPU to aggr_cpu_id 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With no aggregration, such as 'perf stat -A', the aggr_cpu_id lacks a way to describe per CPU aggregation and the core is set to the CPU in places like print_counter_aggrdata in stat-display.c. Setting the core to the CPU is undesirable as the CPU will exceed valid core values and lead to confusion. Add a CPU variable to address this. Signed-off-by: Ian Rogers --- tools/perf/tests/topology.c | 19 +++++++++++++++++++ tools/perf/util/cpumap.c | 23 ++++++++++++++++++++--- tools/perf/util/cpumap.h | 8 ++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index cb29ea7ec409..33e4cb81265c 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -119,6 +119,22 @@ static int check_cpu_topology(char *path, struct perf_= cpu_map *map) session->header.env.cpu[i].socket_id); } =20 + // Test that CPU ID contains socket, die, core and CPU + for (i =3D 0; i < map->nr; i++) { + id =3D aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL); + TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", map->map[i] =3D=3D id.= cpu); + + TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", + session->header.env.cpu[map->map[i]].core_id =3D=3D id.core); + TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match", + session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); + + TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", + session->header.env.cpu[map->map[i]].die_id =3D=3D id.die); + TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node =3D=3D -1); + TEST_ASSERT_VAL("Cpu map - Thread is set", id.thread =3D=3D -1); + } + // Test that core ID contains socket, die and core for (i =3D 0; i < map->nr; i++) { id =3D aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); @@ -145,6 +161,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) =20 TEST_ASSERT_VAL("Die map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Die map - Core is set", id.core =3D=3D -1); + TEST_ASSERT_VAL("Die map - CPU is set", id.cpu =3D=3D -1); TEST_ASSERT_VAL("Die map - Thread is set", id.thread =3D=3D -1); } =20 @@ -157,6 +174,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) TEST_ASSERT_VAL("Socket map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Socket map - Die ID is set", id.die =3D=3D -1); TEST_ASSERT_VAL("Socket map - Core is set", id.core =3D=3D -1); + TEST_ASSERT_VAL("Socket map - CPU is set", id.cpu =3D=3D -1); TEST_ASSERT_VAL("Socket map - Thread is set", id.thread =3D=3D -1); } =20 @@ -168,6 +186,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) TEST_ASSERT_VAL("Node map - Socket is set", id.socket =3D=3D -1); TEST_ASSERT_VAL("Node map - Die ID is set", id.die =3D=3D -1); TEST_ASSERT_VAL("Node map - Core is set", id.core =3D=3D -1); + TEST_ASSERT_VAL("Node map - CPU is set", id.cpu =3D=3D -1); TEST_ASSERT_VAL("Node map - Thread is set", id.thread =3D=3D -1); } perf_session__delete(session); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 985c87f1f1ca..a535fd360d46 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -253,6 +253,20 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *da= ta) =20 } =20 +struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data) +{ + struct aggr_cpu_id id; + + /* aggr_cpu_id__die returns a struct with socket and die set*/ + id =3D aggr_cpu_id__core(cpu, data); + if (aggr_cpu_id__is_empty(&id)) + return id; + + id.cpu =3D cpu; + return id; + +} + struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); @@ -576,7 +590,8 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, co= nst struct aggr_cpu_id *b a->node =3D=3D b->node && a->socket =3D=3D b->socket && a->die =3D=3D b->die && - a->core =3D=3D b->core; + a->core =3D=3D b->core && + a->cpu =3D=3D b->cpu; } =20 bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) @@ -585,7 +600,8 @@ bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) a->node =3D=3D -1 && a->socket =3D=3D -1 && a->die =3D=3D -1 && - a->core =3D=3D -1; + a->core =3D=3D -1 && + a->cpu =3D=3D -1; } =20 struct aggr_cpu_id aggr_cpu_id__empty(void) @@ -595,7 +611,8 @@ struct aggr_cpu_id aggr_cpu_id__empty(void) .node =3D -1, .socket =3D -1, .die =3D -1, - .core =3D -1 + .core =3D -1, + .cpu =3D -1 }; return ret; } diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 8acef8ff8753..651c6417d3c3 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -22,6 +22,8 @@ struct aggr_cpu_id { int die; /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_i= d. */ int core; + /** CPU aggregation, note there is one CPU for each SMT thread. */ + int cpu; }; =20 /** A collection of aggr_cpu_id values, the "built" version is sorted and = uniqued. */ @@ -109,6 +111,12 @@ struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *dat= a); * compatible with aggr_cpu_id_get_t. */ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data); +/** + * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and s= ocket + * populated with the cpu, core, die and socket for cpu. The function sign= ature + * is compatible with aggr_cpu_id_get_t. + */ +struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data); /** * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated = for * cpu. The function signature is compatible with aggr_cpu_id_get_t. --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DBA6CC433F5 for ; Thu, 23 Dec 2021 07:48:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347182AbhLWHsJ (ORCPT ); Thu, 23 Dec 2021 02:48:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347076AbhLWHrW (ORCPT ); Thu, 23 Dec 2021 02:47:22 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35243C061395 for ; Wed, 22 Dec 2021 23:47:12 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id p3-20020a170903248300b00143c00a5411so1038241plw.12 for ; Wed, 22 Dec 2021 23:47:12 -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=KJHGDGEK7ssktfoLh0ZMvZi7f3goEvX8mnP7RB/juA8=; b=kwuscwT4Z11JCrxnzVtReakR7Qi6T/KJ++xKFKpUchUSmuvR3At8fY9vhOXU1TMJ5+ A9Q9RRouOfStzn53XpqbaMbdIZLV1jE50LJYOQUQKvi18c1tiOQnICd6r++mkX3lIIi+ RbpgrMnM4Amd//9TrWPlE/Mx5HYSGOKGtrqtUaqxNq45a9V3/ta9t5UWCevrY4BJ1xF2 xlb6diMCZl/VeBHTKDnFRvaj7BI/VvOpx/CDtC3jAKphxJByDfAcO6iGB87jnDxK8xkf ceivX2wTFC+g3Cn1DIqiuiwOXKK1ti4Y6wYfxSGi9nJR1XJk3J9tFJ4ef3GebzAi8DH8 TiLA== 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=KJHGDGEK7ssktfoLh0ZMvZi7f3goEvX8mnP7RB/juA8=; b=MYB1QI+2WJQjn33mr8SMLS+IHGIqZAH66llX4aVrIoMu+2/QxT0/gdQY0JjMLJ5EvY f4MighuPLFglDltQnKzrYbWwLJyRx7e9Z1De/eeGj77+oB9xzvSquuAEGU4qQI6Duvrk 9sAgsTKo4gGGjMybz5YaPDcEjO0+qhGyASaDQS9Q/vW631Y9ZdApdIxVEjygP6J+tu2H 3l61cBh7AQovztYMCPxbDTzC1LgOyMSSzkaBe3LCi6h9oKzDjg7kZlqtkxq+zOcq5ojr ldbnLZOkd4j82oI5nzL3AtQ/FPdAWpcq8oDRcdZyZe2BHLo30lxVou8onIiFrUNQY5h7 c+8Q== X-Gm-Message-State: AOAM530NMl1Bon+VolZw3bN70PifaqYl8CojoX65VpEr3A7LYyl4Uxb/ jKyI+b4MzUw/NvxqaQtoFKMVALLm3VL7 X-Google-Smtp-Source: ABdhPJyr4euc+sNZ4F0aifxo1nK40USp0OShKIjYuQaa0EnymHFQoqO8VSGW7LZeuS8F/RVn/weqXy1ga+oy X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a17:90b:50e:: with SMTP id r14mr1458321pjz.175.1640245631645; Wed, 22 Dec 2021 23:47:11 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:18 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-26-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 25/48] perf stat-display: Avoid use of core for CPU. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Correct use of cpumap index in print_no_aggr_metric. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 870b1db71fbc..821511ba22cc 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -120,11 +120,10 @@ static void aggr_printout(struct perf_stat_config *co= nfig, id.die, config->csv_output ? 0 : -3, id.core, config->csv_sep); - } else if (id.core > -1) { + } else if (id.cpu > -1) { fprintf(config->output, "CPU%*d%s", config->csv_output ? 0 : -7, - evsel__cpus(evsel)->map[id.core], - config->csv_sep); + id.cpu, config->csv_sep); } break; case AGGR_THREAD: @@ -334,7 +333,7 @@ static int first_shadow_cpu(struct perf_stat_config *co= nfig, int cpu, idx; =20 if (config->aggr_mode =3D=3D AGGR_NONE) - return id->core; + return id->cpu; =20 if (!config->aggr_get_id) return 0; @@ -697,10 +696,9 @@ static void print_counter_aggrdata(struct perf_stat_co= nfig *config, fprintf(output, "%s", prefix); =20 uval =3D val * counter->scale; - if (cpu !=3D -1) { - id =3D aggr_cpu_id__empty(); - id.core =3D cpu; - } + if (cpu !=3D -1) + id =3D aggr_cpu_id__cpu(cpu, /*data=3D*/NULL); + printout(config, id, nr, counter, uval, prefix, run, ena, 1.0, &rt_stat); if (!metric_only) @@ -911,8 +909,7 @@ static void print_counter(struct perf_stat_config *conf= ig, fprintf(output, "%s", prefix); =20 uval =3D val * counter->scale; - id =3D aggr_cpu_id__empty(); - id.core =3D cpu; + id =3D aggr_cpu_id__cpu(cpu, /*data=3D*/NULL); printout(config, id, 0, counter, uval, prefix, run, ena, 1.0, &rt_stat); =20 @@ -924,29 +921,32 @@ static void print_no_aggr_metric(struct perf_stat_con= fig *config, struct evlist *evlist, char *prefix) { - int cpu; - int nrcpus =3D 0; - struct evsel *counter; - u64 ena, run, val; - double uval; - struct aggr_cpu_id id; + int cpu, nrcpus; =20 nrcpus =3D evlist->core.cpus->nr; for (cpu =3D 0; cpu < nrcpus; cpu++) { + struct evsel *counter; bool first =3D true; =20 if (prefix) fputs(prefix, config->output); evlist__for_each_entry(evlist, counter) { - id =3D aggr_cpu_id__empty(); - id.core =3D cpu; + u64 ena, run, val; + double uval; + struct aggr_cpu_id id; + int idx =3D perf_cpu_map__idx(evsel__cpus(counter), cpu); + + if (idx < 0) + continue; + + id =3D aggr_cpu_id__cpu(cpu, /*data=3D*/NULL); if (first) { aggr_printout(config, counter, id, 0); first =3D false; } - val =3D perf_counts(counter->counts, cpu, 0)->val; - ena =3D perf_counts(counter->counts, cpu, 0)->ena; - run =3D perf_counts(counter->counts, cpu, 0)->run; + val =3D perf_counts(counter->counts, idx, 0)->val; + ena =3D perf_counts(counter->counts, idx, 0)->ena; + run =3D perf_counts(counter->counts, idx, 0)->run; =20 uval =3D val * counter->scale; printout(config, id, 0, counter, uval, prefix, --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13D39C433EF for ; Thu, 23 Dec 2021 07:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347314AbhLWHsM (ORCPT ); Thu, 23 Dec 2021 02:48:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239143AbhLWHrW (ORCPT ); Thu, 23 Dec 2021 02:47:22 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3B6FC061396 for ; Wed, 22 Dec 2021 23:47:14 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id d27-20020a25addb000000b005c2355d9052so8657113ybe.3 for ; Wed, 22 Dec 2021 23:47:14 -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=KSXy9ATDOwcZ/rEbQw1i8r+s/0Z51P4OcVCvaux1vkY=; b=UlhpLZUuzZ8abEN/Gzuqndw3CpVJYzc/d08nP0X9kw5NGl+l8gKl9QAzM01hFWnuy8 miKFHwR3Vxghj2irYRCdIcIIGUhOJr5Uu/FBnm+5TmpN6/MTZ9o9S+6DmI/qOp0wL1Xr 0h7toeV0FPhc2eB9rwdh/t1SFHbKiPoIkFWod56tze/5f7+cESjGfAs/sgXBNLwaIZgO 73wBokpaXYm2QwsmnsG7X3G7Dw1U1xRzMX+bFqaV7ulENC8FPIkgRX15g9nBIdHyg9Ta D6y3kIC8VKeN2iAHqEdlplMFEvl0htBaFoWJu+5kGiQ1mgSxokTwxXqgL55kLOfghj1Y 9xmA== 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=KSXy9ATDOwcZ/rEbQw1i8r+s/0Z51P4OcVCvaux1vkY=; b=uXMABugO0dYulWjqAJMv8Unadec9/0yY4IY1DrRmgDRq51+FruO3bGtPe0wklsTOIN SgWhCl6b/iijSEDzgVVposwErR6fW117rTqiTaGc9PNrqGJCL/fYsUOb/Pb+vr9LoGU7 9exupgURNA8Dn4tYGXLjKZ6VzHIeGPxyq2kC+q6tC78EMwIMwY1ouvSYzBa71mTIoVXw u8Nxsu+dcggO8HC89JYBKJqbu/W7WeBSABCzTXVcMqQpREukntqzXPSuFb1EF+taXarv JKNrcn52FM9OkrcwbtUkgx2ys+Gb4AR0rpnMcmHanpboax2b7v9s26z61546HZc4iTIg Ks2Q== X-Gm-Message-State: AOAM530dK8D5NQr0GvQctoMwabHDZGON/fFEoOyPdSF639IrT7E8Ch7P dwgeCGRVdEiW3WxQCN3TvDDv852DwKo/ X-Google-Smtp-Source: ABdhPJxbsXOPk2WMCPKJLYjXolQiSaV0gMEvhHEdya7o+nFosvtmAS1pSHQIQT4QWQz4gdM5R6bgcMs/Wmi+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:ae12:: with SMTP id a18mr1754765ybj.286.1640245634152; Wed, 22 Dec 2021 23:47:14 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:19 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-27-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 26/48] perf evsel: Derive CPUs and threads in alloc_counts 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Passing the number of CPUs and threads allows for an evsel's counts to be mismatched to its cpu map. To avoid this always derive the counts size from the cpu map. Change openaat-syscall-all-cpus to set the cpus to allow for this to work. Signed-off-by: Ian Rogers --- tools/perf/tests/openat-syscall-all-cpus.c | 10 +--------- tools/perf/util/counts.c | 8 ++++++-- tools/perf/util/counts.h | 2 +- tools/perf/util/evsel.c | 2 +- tools/perf/util/stat.c | 13 ++++++------- 5 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/= openat-syscall-all-cpus.c index cd3dd463783f..544db0839b3b 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -85,15 +85,7 @@ static int test__openat_syscall_event_on_all_cpus(struct= test_suite *test __mayb CPU_CLR(cpus->map[cpu], &cpu_set); } =20 - /* - * Here we need to explicitly preallocate the counts, as if - * we use the auto allocation it will allocate just for 1 cpu, - * as we start by cpu 0. - */ - if (evsel__alloc_counts(evsel, cpus->nr, 1) < 0) { - pr_debug("evsel__alloc_counts(ncpus=3D%d)\n", cpus->nr); - goto out_close_fd; - } + evsel->core.cpus =3D perf_cpu_map__get(cpus); =20 err =3D 0; =20 diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c index 582f3aeaf5e4..2b81707b9dba 100644 --- a/tools/perf/util/counts.c +++ b/tools/perf/util/counts.c @@ -4,6 +4,7 @@ #include #include "evsel.h" #include "counts.h" +#include #include =20 struct perf_counts *perf_counts__new(int ncpus, int nthreads) @@ -55,9 +56,12 @@ void evsel__reset_counts(struct evsel *evsel) perf_counts__reset(evsel->counts); } =20 -int evsel__alloc_counts(struct evsel *evsel, int ncpus, int nthreads) +int evsel__alloc_counts(struct evsel *evsel) { - evsel->counts =3D perf_counts__new(ncpus, nthreads); + struct perf_cpu_map *cpus =3D evsel__cpus(evsel); + int nthreads =3D perf_thread_map__nr(evsel->core.threads); + + evsel->counts =3D perf_counts__new(cpus ? cpus->nr : 1, nthreads); return evsel->counts !=3D NULL ? 0 : -ENOMEM; } =20 diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h index 7ff36bf6d644..3e275e9c60d1 100644 --- a/tools/perf/util/counts.h +++ b/tools/perf/util/counts.h @@ -40,7 +40,7 @@ void perf_counts__delete(struct perf_counts *counts); void perf_counts__reset(struct perf_counts *counts); =20 void evsel__reset_counts(struct evsel *evsel); -int evsel__alloc_counts(struct evsel *evsel, int ncpus, int nthreads); +int evsel__alloc_counts(struct evsel *evsel); void evsel__free_counts(struct evsel *evsel); =20 #endif /* __PERF_COUNTS_H */ diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 656c30b988ce..6c9af21776e6 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1578,7 +1578,7 @@ int __evsel__read_on_cpu(struct evsel *evsel, int cpu= , int thread, bool scale) if (FD(evsel, cpu, thread) < 0) return -EINVAL; =20 - if (evsel->counts =3D=3D NULL && evsel__alloc_counts(evsel, cpu + 1, thre= ad + 1) < 0) + if (evsel->counts =3D=3D NULL && evsel__alloc_counts(evsel) < 0) return -ENOMEM; =20 if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <=3D 0) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index c69b221f5e3e..995cb5003133 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -152,11 +152,13 @@ static void evsel__free_stat_priv(struct evsel *evsel) zfree(&evsel->stats); } =20 -static int evsel__alloc_prev_raw_counts(struct evsel *evsel, int ncpus, in= t nthreads) +static int evsel__alloc_prev_raw_counts(struct evsel *evsel) { + int cpu_map_nr =3D evsel__nr_cpus(evsel); + int nthreads =3D perf_thread_map__nr(evsel->core.threads); struct perf_counts *counts; =20 - counts =3D perf_counts__new(ncpus, nthreads); + counts =3D perf_counts__new(cpu_map_nr, nthreads); if (counts) evsel->prev_raw_counts =3D counts; =20 @@ -177,12 +179,9 @@ static void evsel__reset_prev_raw_counts(struct evsel = *evsel) =20 static int evsel__alloc_stats(struct evsel *evsel, bool alloc_raw) { - int ncpus =3D evsel__nr_cpus(evsel); - int nthreads =3D perf_thread_map__nr(evsel->core.threads); - if (evsel__alloc_stat_priv(evsel) < 0 || - evsel__alloc_counts(evsel, ncpus, nthreads) < 0 || - (alloc_raw && evsel__alloc_prev_raw_counts(evsel, ncpus, nthreads) < = 0)) + evsel__alloc_counts(evsel) < 0 || + (alloc_raw && evsel__alloc_prev_raw_counts(evsel) < 0)) return -ENOMEM; =20 return 0; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CD52C433FE for ; Thu, 23 Dec 2021 07:48:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347234AbhLWHsT (ORCPT ); Thu, 23 Dec 2021 02:48:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347200AbhLWHrc (ORCPT ); Thu, 23 Dec 2021 02:47:32 -0500 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 81122C061398 for ; Wed, 22 Dec 2021 23:47:17 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id j204-20020a2523d5000000b005c21574c704so8597633ybj.13 for ; Wed, 22 Dec 2021 23:47:17 -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=lqlPzE1KKe0cwE8XNVrYZKVUkIkDEyGxGITJCS9kpPU=; b=UGnOPNdw1zLN3u4BEX4Xd13VGazFg3c0hIY7oRwkK5Vhcuu6AMmoojAKHTcyO05W0x pu6pcriZqrmOx0b5pIOyqUJ8BIKmpIx0fnHDgzhcoXdpz9cfKBXs4bE40v/PxBYoRBO2 rJNIXJgFgCuRVQzJeA2i3CkCPVbm7Uj2q38vOrR0SzOoveYaALJih0Do2j6Aisc+Q8UR igae4CD5g1g/hCSuBIv8sh5xoqrGb698u+UfWUGW/aQeUBxwRA7e1cp0VXf3r7jUxUd4 pKs7/kt9P4IPn+EHPabPskg9ZzbAPlN+GNXHW2J6NPT2LK0k0z0jrQw6n5U3a6mOTVsH 4iBw== 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=lqlPzE1KKe0cwE8XNVrYZKVUkIkDEyGxGITJCS9kpPU=; b=DgOzNUEGFQZ5TSUAXrIuq8bYxeKTJSxsOn7S/FXLVuPNDuZJ9mYaaOKHWt744qw6Ag sRZEEVYBSZ64q1pZDCfkCIO3yf8a5Q3ZHv/GXB1tyBmr3A0rAN2dD37E8iUNd6Y7PDcw J1ns6IzMZ51YhaiedZtBT8r/3qhXG/lFK1P0Qi2ggUcr1y/AMljB/N4abCd5vLHOtXt1 U2Bc4TPHmef2IwVdb/1fbF0p7u2TIav2w/PclJUOS/chua2EmZSmg+zzek5dQ6ESFnzR Dyzk19g2Noxafonpdp3s7IiWwV5/DLOq7qicEeGLgVmaf469Y6QO/4ltr7y9PwTA7ukg 1cxQ== X-Gm-Message-State: AOAM530V3P0n1K87E2qF6RiWlzV8K8tYRnwK+mfriS6CkaaPCkI2YEqH V846Zmo07Z04EWD7YpRd96zj1VgsRQFO X-Google-Smtp-Source: ABdhPJx+fgqHSsG5r8/Yi9OAICcpGbBIc+pcuuZx0TprjdDfIEfccqUBBJsa7Mco8JYCdmiM1zn7TUbBZM8t X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a05:6902:100d:: with SMTP id w13mr1842576ybt.149.1640245636670; Wed, 22 Dec 2021 23:47:16 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:20 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-28-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 27/48] libperf: Switch cpu to more accurate cpu_map_idx 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Modify variable names and adopt perf_cpu_map__for_each_cpu in perf_evsel__open. Renaming is done by looking for consistency in API usage. Signed-off-by: Ian Rogers --- tools/lib/perf/evsel.c | 88 +++++++++++++++-------------- tools/lib/perf/include/perf/evsel.h | 10 ++-- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 68f83d2c27c1..8028b5a4da69 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -43,18 +43,22 @@ void perf_evsel__delete(struct perf_evsel *evsel) free(evsel); } =20 -#define FD(e, x, y) ((int *) xyarray__entry(e->fd, x, y)) -#define MMAP(e, x, y) (e->mmap ? ((struct perf_mmap *) xyarray__entry(e->m= map, x, y)) : NULL) +#define FD(_evsel, _cpu_map_idx, _thread) \ + ((int *)xyarray__entry(_evsel->fd, _cpu_map_idx, _thread)) +#define MMAP(_evsel, _cpu_map_idx, _thread) \ + (_evsel->mmap ? ((struct perf_mmap *) xyarray__entry(_evsel->mmap, _cpu_m= ap_idx, _thread)) \ + : NULL) =20 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) { evsel->fd =3D xyarray__new(ncpus, nthreads, sizeof(int)); =20 if (evsel->fd) { - int cpu, thread; - for (cpu =3D 0; cpu < ncpus; cpu++) { + int idx, thread; + + for (idx =3D 0; idx < ncpus; idx++) { for (thread =3D 0; thread < nthreads; thread++) { - int *fd =3D FD(evsel, cpu, thread); + int *fd =3D FD(evsel, idx, thread); =20 if (fd) *fd =3D -1; @@ -80,7 +84,7 @@ sys_perf_event_open(struct perf_event_attr *attr, return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); } =20 -static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread, int= *group_fd) +static int get_group_fd(struct perf_evsel *evsel, int cpu_map_idx, int thr= ead, int *group_fd) { struct perf_evsel *leader =3D evsel->leader; int *fd; @@ -97,7 +101,7 @@ static int get_group_fd(struct perf_evsel *evsel, int cp= u, int thread, int *grou if (!leader->fd) return -ENOTCONN; =20 - fd =3D FD(leader, cpu, thread); + fd =3D FD(leader, cpu_map_idx, thread); if (fd =3D=3D NULL || *fd =3D=3D -1) return -EBADF; =20 @@ -109,7 +113,7 @@ static int get_group_fd(struct perf_evsel *evsel, int c= pu, int thread, int *grou int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads) { - int cpu, thread, err =3D 0; + int cpu, idx, thread, err =3D 0; =20 if (cpus =3D=3D NULL) { static struct perf_cpu_map *empty_cpu_map; @@ -139,21 +143,21 @@ int perf_evsel__open(struct perf_evsel *evsel, struct= perf_cpu_map *cpus, perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0) return -ENOMEM; =20 - for (cpu =3D 0; cpu < cpus->nr; cpu++) { + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { for (thread =3D 0; thread < threads->nr; thread++) { int fd, group_fd, *evsel_fd; =20 - evsel_fd =3D FD(evsel, cpu, thread); + evsel_fd =3D FD(evsel, idx, thread); if (evsel_fd =3D=3D NULL) return -EINVAL; =20 - err =3D get_group_fd(evsel, cpu, thread, &group_fd); + err =3D get_group_fd(evsel, idx, thread, &group_fd); if (err < 0) return err; =20 fd =3D sys_perf_event_open(&evsel->attr, threads->map[thread].pid, - cpus->map[cpu], group_fd, 0); + cpu, group_fd, 0); =20 if (fd < 0) return -errno; @@ -165,12 +169,12 @@ int perf_evsel__open(struct perf_evsel *evsel, struct= perf_cpu_map *cpus, return err; } =20 -static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, int cpu) +static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, int cpu_map= _idx) { int thread; =20 for (thread =3D 0; thread < xyarray__max_y(evsel->fd); ++thread) { - int *fd =3D FD(evsel, cpu, thread); + int *fd =3D FD(evsel, cpu_map_idx, thread); =20 if (fd && *fd >=3D 0) { close(*fd); @@ -181,10 +185,8 @@ static void perf_evsel__close_fd_cpu(struct perf_evsel= *evsel, int cpu) =20 void perf_evsel__close_fd(struct perf_evsel *evsel) { - int cpu; - - for (cpu =3D 0; cpu < xyarray__max_x(evsel->fd); cpu++) - perf_evsel__close_fd_cpu(evsel, cpu); + for (int idx =3D 0; idx < xyarray__max_x(evsel->fd); idx++) + perf_evsel__close_fd_cpu(evsel, idx); } =20 void perf_evsel__free_fd(struct perf_evsel *evsel) @@ -202,29 +204,29 @@ void perf_evsel__close(struct perf_evsel *evsel) perf_evsel__free_fd(evsel); } =20 -void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu) +void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu_map_idx) { if (evsel->fd =3D=3D NULL) return; =20 - perf_evsel__close_fd_cpu(evsel, cpu); + perf_evsel__close_fd_cpu(evsel, cpu_map_idx); } =20 void perf_evsel__munmap(struct perf_evsel *evsel) { - int cpu, thread; + int idx, thread; =20 if (evsel->fd =3D=3D NULL || evsel->mmap =3D=3D NULL) return; =20 - for (cpu =3D 0; cpu < xyarray__max_x(evsel->fd); cpu++) { + for (idx =3D 0; idx < xyarray__max_x(evsel->fd); idx++) { for (thread =3D 0; thread < xyarray__max_y(evsel->fd); thread++) { - int *fd =3D FD(evsel, cpu, thread); + int *fd =3D FD(evsel, idx, thread); =20 if (fd =3D=3D NULL || *fd < 0) continue; =20 - perf_mmap__munmap(MMAP(evsel, cpu, thread)); + perf_mmap__munmap(MMAP(evsel, idx, thread)); } } =20 @@ -234,7 +236,7 @@ void perf_evsel__munmap(struct perf_evsel *evsel) =20 int perf_evsel__mmap(struct perf_evsel *evsel, int pages) { - int ret, cpu, thread; + int ret, idx, thread; struct perf_mmap_param mp =3D { .prot =3D PROT_READ | PROT_WRITE, .mask =3D (pages * page_size) - 1, @@ -246,18 +248,18 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int pa= ges) if (perf_evsel__alloc_mmap(evsel, xyarray__max_x(evsel->fd), xyarray__max= _y(evsel->fd)) < 0) return -ENOMEM; =20 - for (cpu =3D 0; cpu < xyarray__max_x(evsel->fd); cpu++) { + for (idx =3D 0; idx < xyarray__max_x(evsel->fd); idx++) { for (thread =3D 0; thread < xyarray__max_y(evsel->fd); thread++) { - int *fd =3D FD(evsel, cpu, thread); + int *fd =3D FD(evsel, idx, thread); struct perf_mmap *map; =20 if (fd =3D=3D NULL || *fd < 0) continue; =20 - map =3D MMAP(evsel, cpu, thread); + map =3D MMAP(evsel, idx, thread); perf_mmap__init(map, NULL, false, NULL); =20 - ret =3D perf_mmap__mmap(map, &mp, *fd, cpu); + ret =3D perf_mmap__mmap(map, &mp, *fd, idx); if (ret) { perf_evsel__munmap(evsel); return ret; @@ -268,14 +270,14 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int pa= ges) return 0; } =20 -void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu, int thread) +void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu_map_idx, int= thread) { - int *fd =3D FD(evsel, cpu, thread); + int *fd =3D FD(evsel, cpu_map_idx, thread); =20 - if (fd =3D=3D NULL || *fd < 0 || MMAP(evsel, cpu, thread) =3D=3D NULL) + if (fd =3D=3D NULL || *fd < 0 || MMAP(evsel, cpu_map_idx, thread) =3D=3D = NULL) return NULL; =20 - return MMAP(evsel, cpu, thread)->base; + return MMAP(evsel, cpu_map_idx, thread)->base; } =20 int perf_evsel__read_size(struct perf_evsel *evsel) @@ -303,19 +305,19 @@ int perf_evsel__read_size(struct perf_evsel *evsel) return size; } =20 -int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, +int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread, struct perf_counts_values *count) { size_t size =3D perf_evsel__read_size(evsel); - int *fd =3D FD(evsel, cpu, thread); + int *fd =3D FD(evsel, cpu_map_idx, thread); =20 memset(count, 0, sizeof(*count)); =20 if (fd =3D=3D NULL || *fd < 0) return -EINVAL; =20 - if (MMAP(evsel, cpu, thread) && - !perf_mmap__read_self(MMAP(evsel, cpu, thread), count)) + if (MMAP(evsel, cpu_map_idx, thread) && + !perf_mmap__read_self(MMAP(evsel, cpu_map_idx, thread), count)) return 0; =20 if (readn(*fd, count->values, size) <=3D 0) @@ -326,13 +328,13 @@ int perf_evsel__read(struct perf_evsel *evsel, int cp= u, int thread, =20 static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ioc, void *arg, - int cpu) + int cpu_map_idx) { int thread; =20 for (thread =3D 0; thread < xyarray__max_y(evsel->fd); thread++) { int err; - int *fd =3D FD(evsel, cpu, thread); + int *fd =3D FD(evsel, cpu_map_idx, thread); =20 if (fd =3D=3D NULL || *fd < 0) return -1; @@ -346,9 +348,9 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evs= el, return 0; } =20 -int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu) +int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, cpu); + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, NULL, cpu_map_= idx); } =20 int perf_evsel__enable(struct perf_evsel *evsel) @@ -361,9 +363,9 @@ int perf_evsel__enable(struct perf_evsel *evsel) return err; } =20 -int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu) +int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx) { - return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, cpu); + return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, NULL, cpu_map= _idx); } =20 int perf_evsel__disable(struct perf_evsel *evsel) diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/p= erf/evsel.h index f401c7484bec..2a9516b42d15 100644 --- a/tools/lib/perf/include/perf/evsel.h +++ b/tools/lib/perf/include/perf/evsel.h @@ -28,16 +28,16 @@ LIBPERF_API void perf_evsel__delete(struct perf_evsel *= evsel); LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu= _map *cpus, struct perf_thread_map *threads); LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel); -LIBPERF_API void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu); +LIBPERF_API void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu_m= ap_idx); LIBPERF_API int perf_evsel__mmap(struct perf_evsel *evsel, int pages); LIBPERF_API void perf_evsel__munmap(struct perf_evsel *evsel); -LIBPERF_API void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu,= int thread); -LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int th= read, +LIBPERF_API void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu_= map_idx, int thread); +LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx= , int thread, struct perf_counts_values *count); LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel); -LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu); +LIBPERF_API int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_m= ap_idx); LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel); -LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu); +LIBPERF_API int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_= map_idx); LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel= ); LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel = *evsel); LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *ev= sel); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E0C0C433F5 for ; Thu, 23 Dec 2021 07:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347218AbhLWHsR (ORCPT ); Thu, 23 Dec 2021 02:48:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347205AbhLWHrf (ORCPT ); Thu, 23 Dec 2021 02:47:35 -0500 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 199C0C06139A for ; Wed, 22 Dec 2021 23:47:20 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id y125-20020a25dc83000000b005c2326bf744so8489908ybe.21 for ; Wed, 22 Dec 2021 23:47:20 -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=ErABhHzBAdfT0a5ELxa3T/433q7mkoWRWaaPkr2zYLE=; b=h8ZCv5xpAMC9yF2kAMaxLxcymXWeg49EXaiL3OtamiPvT60DCEbRj+QLqM5moN4W8N cDtzztDAzcCThB3KlEz4R+jmMAHQWwC0HWP9jzLrXQeSgbrISK7vUtwmIT3hgpk8SnZf Ea9k4Vw/8Cu2Cdt9poAJAnCZzvqBtOEBBihTwocK1pOVbQEMqkL30NhY5x1b3qIvRjz4 fZ/pakEDofR/HPl2V3MJr+X78TgyvuQt7Pnw0BdOGwBWbb1AwiQ5TqTdNRY8Ibpa4R9J QnytXVyIbzFHR52fV6mELViTABsYuN04e+hTtQnQ/bbrmoakuXNkJUX/vXlWQxbzo5zJ 3Cyg== 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=ErABhHzBAdfT0a5ELxa3T/433q7mkoWRWaaPkr2zYLE=; b=GC9oya3X9U6eHDu645xD4JD+b2hmmzUocZHt8zC5aqzO05rEm/MShg+730z/fRS8ll JWBWWMTnNTTTCiE4r77ftYorHdNY4+HRG2MWcw1ws3CNGiRW3GEE2wuUZq56i7MoXEnq pF5OblgiZcwL7ZqtyPJ737Crm2AisiQEuBsubATDPJHIU8BY/pcMG5w1sl7QKweCe65u PKhjLbrfL5CxvT4tgxDYyzQXnZjP750aI/qkb1e4xaobs8KbxBcnfLDEYQk8es2wC3XV aDbq+Ba/ivpcj0hw0QPqLl0Oz1sOQAslXaw/ECFclTR8scp+1u2utInXxefRLNxUMSrc mjvQ== X-Gm-Message-State: AOAM533PG4LOUa4pjeGfLk/bhz+A+eS8Hw23Q2C5b3sJ513SgrwbJlqm LKFJCGNLfulLUW4KTP/tHPcaj3tV6cpX X-Google-Smtp-Source: ABdhPJwqZDzpHASDcXqKxGGvIcAj99RfagujZOxumPIiBCWlWRZFjRDOAtRAIxTsQbSB/e87K/O6PSKPvp4b X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:238a:: with SMTP id j132mr1715031ybj.530.1640245639355; Wed, 22 Dec 2021 23:47:19 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:21 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-29-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 28/48] libperf: Use cpu not index for evsel mmap 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Fix issue where evsel's CPU map index was being used as the mmap cpu. Signed-off-by: Ian Rogers --- tools/lib/perf/evsel.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index 8028b5a4da69..f1e1665ef4bd 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -252,6 +252,7 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int page= s) for (thread =3D 0; thread < xyarray__max_y(evsel->fd); thread++) { int *fd =3D FD(evsel, idx, thread); struct perf_mmap *map; + int cpu =3D perf_cpu_map__cpu(evsel->cpus, idx); =20 if (fd =3D=3D NULL || *fd < 0) continue; @@ -259,7 +260,7 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int page= s) map =3D MMAP(evsel, idx, thread); perf_mmap__init(map, NULL, false, NULL); =20 - ret =3D perf_mmap__mmap(map, &mp, *fd, idx); + ret =3D perf_mmap__mmap(map, &mp, *fd, cpu); if (ret) { perf_evsel__munmap(evsel); return ret; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE780C433F5 for ; Thu, 23 Dec 2021 07:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347230AbhLWHs0 (ORCPT ); Thu, 23 Dec 2021 02:48:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242786AbhLWHri (ORCPT ); Thu, 23 Dec 2021 02:47:38 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A775C06139E for ; Wed, 22 Dec 2021 23:47:22 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id w5-20020a25ac05000000b005c55592df4dso8705200ybi.12 for ; Wed, 22 Dec 2021 23:47:22 -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=9MlO9Oc0ygtrZ/h2HPcbPSvrjEKGPTLy8AFmEb58PdQ=; b=QRvmyQ7dNLCCzxTek5kADkOOAY1TOzPPY4YUro9+3bnIA71ybO6VL5mpwQ6+/AL4L+ +zMCRVNebJJT5zqf6Yhn8uShyaZQ/cxf/tPjzhJW+Wdzf2pPo4NoDt5YepVxJVilRkrR ZHs5n+0bWa1l44WmXtzMjOlnGG5QGZnZIoD78fi5t1pgjG5BJWi2UU/no+TZAkOrLJ6B FuNamVbKccv1PslUXtsBRmAN/MlvwCWvfCQV6aqkZk5l47leYhjWcHwpqnFpq/o6MIOk OJn51HpK8ss0QhHvm4As8UTzqJJmykWjG7nWNwHZ8kCqRihirym89DRfneUF43B15U5M gY8Q== 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=9MlO9Oc0ygtrZ/h2HPcbPSvrjEKGPTLy8AFmEb58PdQ=; b=yhqTSQh7LaIFv01vt9c3ENiYgo3vXD3tFCHzWU8Ew3Y4mFApWD6LQ2Cw/HvmvZR8Ct jZfdcEwUG2cC9ubWjYbz3AoRYpAaP1ZktePMRCukYUqAcdE1q5SZO4W0xjlNKceosgUb 4MHIhMUOGray/l+TuELduJumhznILpJhmO/RiDFR3K3+LWv8i5C/1M/cUmvlRBZui/+f c+AiJjXqqz/Boq58pohMz2miuCoAuJNPOoenSXieQRKFSUchiZ8d9H9m7dIMDzhX8uag eKwLSz1pFu9Mer3AlS7ntXB+AZLvNlwGPyKAMdySwy5F7R3hDIWbeNO1y0gc2NaZKFJj coEQ== X-Gm-Message-State: AOAM531TGSVZ+XiC25MUks07dku9JTT/2ZenhQuC7b6V57wLyZd7aNJE Qo4F8awFBkLtC46nUDRwcxn3gCxXcbOX X-Google-Smtp-Source: ABdhPJw+xZ/j9KPjaoan9KyhnSh4c7HwSNgk0Z8l1o/khlbiifft972N8n40w8o6xk7NCchdOZ7J2Vjb8AI2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:aaaa:: with SMTP id t39mr1542314ybi.201.1640245641771; Wed, 22 Dec 2021 23:47:21 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:22 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-30-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 29/48] perf counts: Switch name cpu to cpu_map_idx 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Try to reduce confusion in particular when the cpu map doesn't contain an entry for every CPU. Signed-off-by: Ian Rogers --- tools/perf/util/counts.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h index 3e275e9c60d1..5de275194f2b 100644 --- a/tools/perf/util/counts.h +++ b/tools/perf/util/counts.h @@ -18,21 +18,21 @@ struct perf_counts { =20 =20 static inline struct perf_counts_values* -perf_counts(struct perf_counts *counts, int cpu, int thread) +perf_counts(struct perf_counts *counts, int cpu_map_idx, int thread) { - return xyarray__entry(counts->values, cpu, thread); + return xyarray__entry(counts->values, cpu_map_idx, thread); } =20 static inline bool -perf_counts__is_loaded(struct perf_counts *counts, int cpu, int thread) +perf_counts__is_loaded(struct perf_counts *counts, int cpu_map_idx, int th= read) { - return *((bool *) xyarray__entry(counts->loaded, cpu, thread)); + return *((bool *) xyarray__entry(counts->loaded, cpu_map_idx, thread)); } =20 static inline void -perf_counts__set_loaded(struct perf_counts *counts, int cpu, int thread, b= ool loaded) +perf_counts__set_loaded(struct perf_counts *counts, int cpu_map_idx, int t= hread, bool loaded) { - *((bool *) xyarray__entry(counts->loaded, cpu, thread)) =3D loaded; + *((bool *) xyarray__entry(counts->loaded, cpu_map_idx, thread)) =3D loade= d; } =20 struct perf_counts *perf_counts__new(int ncpus, int nthreads); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A7C5C433EF for ; Thu, 23 Dec 2021 07:48:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242737AbhLWHso (ORCPT ); Thu, 23 Dec 2021 02:48:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347215AbhLWHrl (ORCPT ); Thu, 23 Dec 2021 02:47:41 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29930C061353 for ; Wed, 22 Dec 2021 23:47:25 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id w9-20020a25c709000000b00608a9489fc1so8586964ybe.20 for ; Wed, 22 Dec 2021 23:47:25 -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=hkPo8liTuI9h6KOorTG0Q0VnFokCocOgWRmiktw00dU=; b=Xcj0ee+hgy+nDCYG/rsM91+FuuqQSJiMSCzMOM5SkpY53T4DzkFC3flZLbcPQJ0xOW ucf2StOzgxlmQWFBtpk07akH+Ih91uqwgd1SMQCB2yVnBLHsYRa+avn6wgPFt0kjsNpr YwbBXIrJUuKVqeYyf/FM/YHOI0xj9btID3ki+m/EGWmg+sNQYCI07g79MZCdpOAU/BVP 7xrCMsCuo94Fz14MPRqjNXM3IgUKSoibZqYXoQlX7f4LfI/d9uARzppArHlhFKv0NNPP godVNKuyjvowcHh5mfHlqzEk2VHtLkw1SGFdfboDj6XRovc2Lq4bIDiSIU5UWJUDkBe0 Qlng== 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=hkPo8liTuI9h6KOorTG0Q0VnFokCocOgWRmiktw00dU=; b=cOMqtsak1y2TzqiLZcVaK0KXALB5SXyT/qEghQSZPQhs1pBzXGfg6TAU/DFLm7Z3oO MlRwtRj5ANZXmawKcjdsas4evXXr6z7VYteGtePrHyc4J74v/Ro+H5Qray8Yb7uTZntV Pxy9fOA+pQPP+KGWHYH3d9ycv9jnRUZgBhGxVn2QQdNFKvFVpwliAlj1CgB/dE+E+buu MrYjTqXmgXRS+oRb02+P5Qbf+zkYOXqmMO7QTJ52cof/ul4KkWAcE4HOSLeTt1YJyGnF PKNY1h08MuevLmVXXjPDTkA7dNfElphNvZMZjSX2NS0b0327kVXtrVB0yWxj/SUOQS3k uZew== X-Gm-Message-State: AOAM531En0gkEql+ogm17cg3vcBaSHh6jpsQaPhL8L/nCRaxvXd1mWBF GP/v5HPt53ijaa7aU5XLRqTB8/dL7kgt X-Google-Smtp-Source: ABdhPJxp6t3w/qnJ+v3zw2zyM1duZWB+B4DWIZtTNpflJlX6sZOLZwc2wLe7o4mryuVEonh3x19x1ZBXjNXr X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:50cf:: with SMTP id e198mr1803293ybb.508.1640245644353; Wed, 22 Dec 2021 23:47:24 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:23 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-31-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 30/48] perf stat: Rename aggr_data cpu to imply it's an index 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Trying to make cpu maps less error prone. Signed-off-by: Ian Rogers --- tools/perf/util/python.c | 2 +- tools/perf/util/stat-display.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 563a9ba8954f..4b510a1f27d4 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1057,7 +1057,7 @@ static struct mmap *get_md(struct evlist *evlist, int= cpu) for (i =3D 0; i < evlist->core.nr_mmaps; i++) { struct mmap *md =3D &evlist->mmap[i]; =20 - if (md->core.cpu =3D=3D cpu) + if (md->core.cpu_map_idx =3D=3D cpu) return md; } =20 diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 821511ba22cc..4f93591aaa76 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -626,7 +626,7 @@ struct aggr_data { u64 ena, run, val; struct aggr_cpu_id id; int nr; - int cpu; + int cpu_map_idx; }; =20 static void aggr_cb(struct perf_stat_config *config, @@ -878,9 +878,9 @@ static void counter_cb(struct perf_stat_config *config = __maybe_unused, { struct aggr_data *ad =3D data; =20 - ad->val +=3D perf_counts(counter->counts, ad->cpu, 0)->val; - ad->ena +=3D perf_counts(counter->counts, ad->cpu, 0)->ena; - ad->run +=3D perf_counts(counter->counts, ad->cpu, 0)->run; + ad->val +=3D perf_counts(counter->counts, ad->cpu_map_idx, 0)->val; + ad->ena +=3D perf_counts(counter->counts, ad->cpu_map_idx, 0)->ena; + ad->run +=3D perf_counts(counter->counts, ad->cpu_map_idx, 0)->run; } =20 /* @@ -897,7 +897,7 @@ static void print_counter(struct perf_stat_config *conf= ig, struct aggr_cpu_id id; =20 for (cpu =3D 0; cpu < evsel__nr_cpus(counter); cpu++) { - struct aggr_data ad =3D { .cpu =3D cpu }; + struct aggr_data ad =3D { .cpu_map_idx =3D cpu }; =20 if (!collect_data(config, counter, counter_cb, &ad)) return; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4263C433F5 for ; Thu, 23 Dec 2021 07:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242916AbhLWHsn (ORCPT ); Thu, 23 Dec 2021 02:48:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242729AbhLWHrr (ORCPT ); Thu, 23 Dec 2021 02:47:47 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6550C061376 for ; Wed, 22 Dec 2021 23:47:27 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id q123-20020a252a81000000b00609e97bb74bso8696908ybq.5 for ; Wed, 22 Dec 2021 23:47:27 -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=5tVJzNTPrT5Mz019UGpMqh4/y+iJ54XVPfgHv8yLcW0=; b=TQyU/YpVCjIz2BUqO2jBW/aSe8SJJ8OhQe20TBnnnPqLK1vyy6hwJqBFl3KfwmlYdF kD8Yp3uDQNG55m7ttdUsfgTh8YBvFgmISS0eQOzVZuCs3MCyQ6FwIRN2GEJMsnZO2+y/ B/6sX6cO+5HDmbyv5nFF1nn+IJEXKPnTy5G3fNKJP3peVoN+dU3OdYCVo3LEKCM/adaI mKYh9jZwDzP1lcdT/R6LTuzVqw4QwPsQ23imyiDTX7JWhGl1ckosjrz5t61r7O31brcT TLM1yiQYq2u+SX3cObKOaTaHRcVmysUTAIWeZUSOT86CUn8i4H+kDPOgudioV70LLyPu HyKA== 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=5tVJzNTPrT5Mz019UGpMqh4/y+iJ54XVPfgHv8yLcW0=; b=Jm4vpTGy8YeBVlHRzvCfWLRbdxLe8KuerAmCZErYM6EOlO6iojfCAmSwW6awFjo8rd rftaX8ONReky5EZrpb2foI5PtpxRlVDrtjqG966k9r8i20xV1ri4Anyu+Jf6rNoyhjyF GtgTl6m8FNNvjptoHw+LCH0s8RJ0lLrzofUIVRqdMt9UeGSnOTgF42vtaYtQ7tRtnCxX xSOR3qYeCoQKd8I3Vo8OEt4tiMAw2Ile8ve6h6VSjt6QPYNPLi6Y/Rh4TrA2vSwMZ93k ZvCCRWueMSwvp8A/K9ccqpA4tRKZpFacAyL26TdXFBJrg4ujtFBHGWmDT/0f0xdsFfjM 2/sQ== X-Gm-Message-State: AOAM532xSEg7yVtxgkNgnTbtHpge3jXeHiGvH+VynxpafhmoX+J9lBbe fYdbbg6nusahm7dshyea6Tn1+zR4x26P X-Google-Smtp-Source: ABdhPJyftWeLHeEAE1+KjGOdTuxDKZVxQ6Lm+rFn/DSubwAQ+QTEgxV94xTRIHGTQT/w4ZG4G93EWVCQd/mW X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:504d:: with SMTP id e74mr1602226ybb.685.1640245647040; Wed, 22 Dec 2021 23:47:27 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:24 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-32-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 31/48] perf stat: Use perf_cpu_map__for_each_cpu 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Correct in print_counter where an index was being used as a cpu. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 4f93591aaa76..9be74e907352 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "color.h" #include "counts.h" #include "evlist.h" @@ -732,7 +733,7 @@ static void print_aggr(struct perf_stat_config *config, evlist__for_each_entry(evlist, counter) { print_counter_aggrdata(config, counter, s, prefix, metric_only, - &first, -1); + &first, /*cpu=3D*/-1); } if (metric_only) fputc('\n', output); @@ -893,11 +894,11 @@ static void print_counter(struct perf_stat_config *co= nfig, FILE *output =3D config->output; u64 ena, run, val; double uval; - int cpu; + int idx, cpu; struct aggr_cpu_id id; =20 - for (cpu =3D 0; cpu < evsel__nr_cpus(counter); cpu++) { - struct aggr_data ad =3D { .cpu_map_idx =3D cpu }; + perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { + struct aggr_data ad =3D { .cpu_map_idx =3D idx }; =20 if (!collect_data(config, counter, counter_cb, &ad)) return; @@ -921,10 +922,9 @@ static void print_no_aggr_metric(struct perf_stat_conf= ig *config, struct evlist *evlist, char *prefix) { - int cpu, nrcpus; + int all_idx, cpu; =20 - nrcpus =3D evlist->core.cpus->nr; - for (cpu =3D 0; cpu < nrcpus; cpu++) { + perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.cpus) { struct evsel *counter; bool first =3D true; =20 @@ -1249,7 +1249,7 @@ static void print_percore(struct perf_stat_config *co= nfig, =20 print_counter_aggrdata(config, counter, s, prefix, metric_only, - &first, -1); + &first, /*cpu=3D*/-1); } =20 if (metric_only) --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B236FC433FE for ; Thu, 23 Dec 2021 07:48:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347051AbhLWHsi (ORCPT ); Thu, 23 Dec 2021 02:48:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347232AbhLWHrr (ORCPT ); Thu, 23 Dec 2021 02:47:47 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E9AAC061378 for ; Wed, 22 Dec 2021 23:47:30 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id r18-20020a25ac52000000b005c9047c420bso8731406ybd.4 for ; Wed, 22 Dec 2021 23:47:30 -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=gS702mZNdqaqGqsGN8/od6/9eJfsTdX5XaCwO/CHnxg=; b=ZAG5FsujH76QsBUz/tYbzeEG+GrdHE0RRbhUkLTKIjXs8evI8wAwEzY1h9EMDJqLnH hlWlHw8ziKRJadI9FWV7TXuil8dvJNhJdyncQg+B0ziD3qhSeeGq9zd8RStul7QZcUHP nLgq9PAndLX+i87S/32ECHBitev9Eh0Ep/uGVfLee+lL+BdKoKPAUlgUEFWZvOiIwJld 9RGSqm7s322Kdx9GRuLW6iLuqNsN5wQqpiwwM2KspOhUZUSB0WHBTF0FV7MJMUm5PikU 7a8JPVmxmEa9NuVRw/kcDPUHBeKeJE5lbmgn1WFsX9OJ5W6RcdOIsS2rG/xSt8AG48z3 3XLQ== 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=gS702mZNdqaqGqsGN8/od6/9eJfsTdX5XaCwO/CHnxg=; b=Goycs7gWo+7xOLt8O1iAKQ39u8sGM/cX1ObzqJpCHqJDvzdE32V9LJ1ZULpDzFQHEg 0eR22D4MZD170IWcxHzGytiB3okK7Mzz970jol5Bl3hhOpVyjjdFwVCrftZtqMj8iim9 LlHmbHLbKJRBU70hi1+EAfdhgtEDcH04+cNE0Oe3ftM8Kpqhs5FMgUFP/TbHrpCLf6A2 554UvXrTjlmhzh3mSoEhqY/P/Ts2v8f4Y/3cNEuoMc+9YbwfTpBlAsnNCm6nJTLOIChR P1rzR2H3OZ1Wr84SwtOHfzGrn84VEAKCWOjGECPvw+8nAs+Bhb3yqcnL8oyCFBzX2j+D lkxA== X-Gm-Message-State: AOAM532UWXxfDsWLmw/UdNmlP/s0oNUVv7a/zmU037JmO0HjGrv+pFgC jkMgGtw75tDXgjAY8i+G6F+tpeCeLZzi X-Google-Smtp-Source: ABdhPJzky4057KHzG/tA4tur8qNXghY66f9kz+2zvw0XyPAyGCbP0JD3U0gIN/QaSj9xsR799MWG2pDgUs+J X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:258c:: with SMTP id l134mr1685364ybl.40.1640245649513; Wed, 22 Dec 2021 23:47:29 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:25 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-33-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 32/48] perf script: Use for each cpu to aid readability 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use perf_cpu_map__for_each_cpu to help with readability. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 9434367af166..af06fe1271cc 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2113,8 +2113,7 @@ static struct scripting_ops *scripting_ops; static void __process_stat(struct evsel *counter, u64 tstamp) { int nthreads =3D perf_thread_map__nr(counter->core.threads); - int ncpus =3D evsel__nr_cpus(counter); - int cpu, thread; + int idx, cpu, thread; static int header_printed; =20 if (counter->core.system_wide) @@ -2127,13 +2126,13 @@ static void __process_stat(struct evsel *counter, u= 64 tstamp) } =20 for (thread =3D 0; thread < nthreads; thread++) { - for (cpu =3D 0; cpu < ncpus; cpu++) { + perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { struct perf_counts_values *counts; =20 counts =3D perf_counts(counter->counts, cpu, thread); =20 printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 "= %s\n", - counter->core.cpus->map[cpu], + cpu, perf_thread_map__pid(counter->core.threads, thread), counts->val, counts->ena, --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05F42C433EF for ; Thu, 23 Dec 2021 07:48:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347478AbhLWHsh (ORCPT ); Thu, 23 Dec 2021 02:48:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347233AbhLWHrr (ORCPT ); Thu, 23 Dec 2021 02:47:47 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9F6FC061763 for ; Wed, 22 Dec 2021 23:47:32 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id d205-20020a251dd6000000b0060977416ad4so8517563ybd.16 for ; Wed, 22 Dec 2021 23:47:32 -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=7KMW6WRtr7zGKUVYDJaGbIMwO/xb3TdjfWdejoRFxZk=; b=PD4AhddK0yCJrWHFUVFzF6fy/Hy7kE5hAz32UsxLOp2AWaiATpdPZNCESgd7gmZh+0 JD9szVEZUwVwVIovJ8uhUR86l/3obJU0BPy0vtKl5hh/RzQIxNRTRLuKGDvT5HhD/yOY 7CkPaB8T0BMkbm834BJKnDbYDjVJ6M72NJOIPfDmDT0/XJ8FQ0wSOKcrz1Wd3rBBrUbR Bqk8D0IIq5X+1wZ3FpVNLhVw7Qq54DrrbCECNH/qXk7Dl2u/AZHZkMRE6RED9In2ibgw C5Z3sPDQck0XHpCGjAL4/8F0gNSwBg3zIh80bnxvN8HFHtOSeMh62yc6uD8f8ZPBSSSd rtww== 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=7KMW6WRtr7zGKUVYDJaGbIMwO/xb3TdjfWdejoRFxZk=; b=AO4TvqQKjGv9OVsDQyWtwLpOwQLRr6zX6BymS/6bnKn03HhR18H+QglTW6pVEKPa2f qUqvqXaYmtMtMQE37iCFQlr2As62UJAWB8HNMuvQ7LCBrVxTID8u7krpI5xG9r0b6DdV UhfHT3RGBUllelCFwfNPr0+PCPxmF5jvSUol2eOsTFdZMuqeKPLuWSzBhYu0szTUu81d MROTTxUxzIUQswBUyxdppvyrzVLco8M8bZfn6ZCFsgAdB2GZ5zmp+4HNStmj+nWkpw3e EsnfTPLBXNrkRY+Bm0RzxMjHSv15qQwQrzVqRWaT+v/f0dbTnc6F6K72FZeTr4lrrDgG tskw== X-Gm-Message-State: AOAM5323dwVaC0nOjZlLF0oDLFJaNrQHk9jyMGwoF7IYgr0Eg7SHFn83 9rKrJto4fW8D/HdtUiyIxA8n58ltrFTE X-Google-Smtp-Source: ABdhPJy1JMKjOvk17SbJ4unY+bdUb6VxzdlzcVN9x0G1cd9E8XUWweez9IQ3dMvk09C8NWl/FjP22s3abygL X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:da06:: with SMTP id n6mr1734069ybf.763.1640245652081; Wed, 22 Dec 2021 23:47:32 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:26 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-34-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 33/48] libperf: Allow NULL in perf_cpu_map__idx 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Return -1, not found, if NULL is passed. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 3c36a06771af..eacea3ab965a 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -270,8 +270,13 @@ bool perf_cpu_map__empty(const struct perf_cpu_map *ma= p) =20 int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu) { - int low =3D 0, high =3D cpus->nr; + int low, high; =20 + if (!cpus) + return -1; + + low =3D 0; + high =3D cpus->nr; while (low < high) { int idx =3D (low + high) / 2, cpu_at_idx =3D cpus->map[idx]; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6175AC433FE for ; Thu, 23 Dec 2021 07:48:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347440AbhLWHs2 (ORCPT ); Thu, 23 Dec 2021 02:48:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40980 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347236AbhLWHrs (ORCPT ); Thu, 23 Dec 2021 02:47:48 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37992C06137A for ; Wed, 22 Dec 2021 23:47:35 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id p133-20020a255b8b000000b006086e19f89fso8558534ybb.19 for ; Wed, 22 Dec 2021 23:47:35 -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=MBx2+H5jSsSvrhGDLOtrKSU1i8mxpvcEw3Pj8vdRNVU=; b=cT8fGHyZJ3/0eURIwZZUWC64E+BnWvjaHu0Yas4pXyELxq0Z4HEMi86NKL+Oz5q6yL oK4pTU5Mp014jRzd+YVjOSS7KLqc11t7icQ0CZMp3X+ebDDFxG9h0UXQ5F7w92kFmgTh jRIYlVm5zf6o10vmE7BHFnI5tWVRoB9jzD3tQo+9Haw9wn3bqTmXSh7U3dgnEj//wIKy s9f0k2jyYR8citrzqnDLoshZk5MBJSJlM2jjFN+WxYbytfm8Vbc/4gU+0ym54q1coH3u 34saj1y7ZRKomKCv1VevE92x7cZQ/4jquY3cG2wGHUCgMADl/5G8uZzAxhbtSu7twI+o s0GA== 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=MBx2+H5jSsSvrhGDLOtrKSU1i8mxpvcEw3Pj8vdRNVU=; b=MTIjthFCCelQrro9Fm5i7NtAlebK4f3jhyd4UMAJKb+ghXEJA9ELeYWCMyicSMP3Zo lsAWurj2oV//lblbjt52Z937YTHJOuGmq/MvI1LonPj0qmJabpQ5uavBAuNpcJ0AgiWt Y4Un9lFW2BKO06rpIeb1PRF1kAjRePyP3fV49SYSZSnOQtInAUbIXS3jFvzcQLK6onpY y5Lt5AYeH3HDbvCsum6L3A/N3w7454SLTWPLEEP8YPR2zTmecUHsrnXSex44ll5iqtSY XLHFigfO3XMLeUmrY5Nohypswk1XgbhxSciHwd4BHz/lVEhbt3wudDmBzUmq894kpDAO iI+g== X-Gm-Message-State: AOAM5313o3yBNaKtFt9QKRRZiPAWJUlp0LnFpxmT6RzM5vx5ZOcuL5Gf 4DIoIQJnZGd2fee3NXYow0PL/VN3bxS/ X-Google-Smtp-Source: ABdhPJysc6sUwVF4Y+BUv0WS7OPqBzsw5IOO4Wi6HVSfjFzlryCEzh42YZjEuOESD/Dj5+w46ci/o9uOvZgF X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:4086:: with SMTP id n128mr1715987yba.280.1640245654461; Wed, 22 Dec 2021 23:47:34 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:27 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-35-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 34/48] perf evlist: Refactor evlist__for_each_cpu. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously evlist__for_each_cpu needed to iterate over the evlist in an inner loop and call "skip" routines. Refactor this so that the iteratr is smarter and the next function can update both the current CPU and evsel. By using a cpu map index, fix apparent off-by-1 in __run_perf_stat's call to perf_evsel__close_cpu. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 179 ++++++++++++++++++-------------------- tools/perf/util/evlist.c | 146 +++++++++++++++++-------------- tools/perf/util/evlist.h | 50 +++++++++-- tools/perf/util/evsel.h | 1 - 4 files changed, 210 insertions(+), 166 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 98f80c217279..f31bc34bd4cc 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -405,36 +405,33 @@ static int read_counter_cpu(struct evsel *counter, st= ruct timespec *rs, int cpu) =20 static int read_affinity_counters(struct timespec *rs) { - struct evsel *counter; - struct affinity affinity; - int i, ncpus, cpu; + struct evlist_cpu_iterator evlist_cpu_itr; + struct affinity saved_affinity, *affinity; =20 if (all_counters_use_bpf) return 0; =20 - if (affinity__setup(&affinity) < 0) + if (!target__has_cpu(&target) || target__has_per_thread(&target)) + affinity =3D NULL; + else if (affinity__setup(&saved_affinity) < 0) return -1; + else + affinity =3D &saved_affinity; =20 - ncpus =3D perf_cpu_map__nr(evsel_list->core.all_cpus); - if (!target__has_cpu(&target) || target__has_per_thread(&target)) - ncpus =3D 1; - evlist__for_each_cpu(evsel_list, i, cpu) { - if (i >=3D ncpus) - break; - affinity__set(&affinity, cpu); + evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) { + struct evsel *counter =3D evlist_cpu_itr.evsel; =20 - evlist__for_each_entry(evsel_list, counter) { - if (evsel__cpu_iter_skip(counter, cpu)) - continue; - if (evsel__is_bpf(counter)) - continue; - if (!counter->err) { - counter->err =3D read_counter_cpu(counter, rs, - counter->cpu_iter - 1); - } + if (evsel__is_bpf(counter)) + continue; + + if (!counter->err) { + counter->err =3D read_counter_cpu(counter, rs, + evlist_cpu_itr.cpu_map_idx); } } - affinity__cleanup(&affinity); + if (affinity) + affinity__cleanup(&saved_affinity); + return 0; } =20 @@ -788,8 +785,9 @@ static int __run_perf_stat(int argc, const char **argv,= int run_idx) int status =3D 0; const bool forks =3D (argc > 0); bool is_pipe =3D STAT_RECORD ? perf_stat.data.is_pipe : false; + struct evlist_cpu_iterator evlist_cpu_itr; struct affinity affinity; - int i, cpu, err; + int err; bool second_pass =3D false; =20 if (forks) { @@ -813,102 +811,97 @@ static int __run_perf_stat(int argc, const char **ar= gv, int run_idx) all_counters_use_bpf =3D false; } =20 - evlist__for_each_cpu (evsel_list, i, cpu) { + evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) { + counter =3D evlist_cpu_itr.evsel; + /* * bperf calls evsel__open_per_cpu() in bperf__load(), so * no need to call it again here. */ if (target.use_bpf) break; - affinity__set(&affinity, cpu); =20 - evlist__for_each_entry(evsel_list, counter) { - if (evsel__cpu_iter_skip(counter, cpu)) + if (counter->reset_group || counter->errored) + continue; + if (evsel__is_bpf(counter)) + continue; +try_again: + if (create_perf_stat_counter(counter, &stat_config, &target, + evlist_cpu_itr.cpu_map_idx) < 0) { + + /* + * Weak group failed. We cannot just undo this here + * because earlier CPUs might be in group mode, and the kernel + * doesn't support mixing group and non group reads. Defer + * it to later. + * Don't close here because we're in the wrong affinity. + */ + if ((errno =3D=3D EINVAL || errno =3D=3D EBADF) && + evsel__leader(counter) !=3D counter && + counter->weak_group) { + evlist__reset_weak_group(evsel_list, counter, false); + assert(counter->reset_group); + second_pass =3D true; continue; - if (counter->reset_group || counter->errored) + } + + switch (stat_handle_error(counter)) { + case COUNTER_FATAL: + return -1; + case COUNTER_RETRY: + goto try_again; + case COUNTER_SKIP: continue; - if (evsel__is_bpf(counter)) + default: + break; + } + + } + counter->supported =3D true; + } + + if (second_pass) { + /* + * Now redo all the weak group after closing them, + * and also close errored counters. + */ + + /* First close errored or weak retry */ + evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) { + counter =3D evlist_cpu_itr.evsel; + + if (!counter->reset_group && !counter->errored) continue; -try_again: + + perf_evsel__close_cpu(&counter->core, evlist_cpu_itr.cpu_map_idx); + } + /* Now reopen weak */ + evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) { + counter =3D evlist_cpu_itr.evsel; + + if (!counter->reset_group && !counter->errored) + continue; + if (!counter->reset_group) + continue; +try_again_reset: + pr_debug2("reopening weak %s\n", evsel__name(counter)); if (create_perf_stat_counter(counter, &stat_config, &target, - counter->cpu_iter - 1) < 0) { - - /* - * Weak group failed. We cannot just undo this here - * because earlier CPUs might be in group mode, and the kernel - * doesn't support mixing group and non group reads. Defer - * it to later. - * Don't close here because we're in the wrong affinity. - */ - if ((errno =3D=3D EINVAL || errno =3D=3D EBADF) && - evsel__leader(counter) !=3D counter && - counter->weak_group) { - evlist__reset_weak_group(evsel_list, counter, false); - assert(counter->reset_group); - second_pass =3D true; - continue; - } + evlist_cpu_itr.cpu_map_idx) < 0) { =20 switch (stat_handle_error(counter)) { case COUNTER_FATAL: return -1; case COUNTER_RETRY: - goto try_again; + goto try_again_reset; case COUNTER_SKIP: continue; default: break; } - } counter->supported =3D true; } } - - if (second_pass) { - /* - * Now redo all the weak group after closing them, - * and also close errored counters. - */ - - evlist__for_each_cpu(evsel_list, i, cpu) { - affinity__set(&affinity, cpu); - /* First close errored or weak retry */ - evlist__for_each_entry(evsel_list, counter) { - if (!counter->reset_group && !counter->errored) - continue; - if (evsel__cpu_iter_skip_no_inc(counter, cpu)) - continue; - perf_evsel__close_cpu(&counter->core, counter->cpu_iter); - } - /* Now reopen weak */ - evlist__for_each_entry(evsel_list, counter) { - if (!counter->reset_group && !counter->errored) - continue; - if (evsel__cpu_iter_skip(counter, cpu)) - continue; - if (!counter->reset_group) - continue; -try_again_reset: - pr_debug2("reopening weak %s\n", evsel__name(counter)); - if (create_perf_stat_counter(counter, &stat_config, &target, - counter->cpu_iter - 1) < 0) { - - switch (stat_handle_error(counter)) { - case COUNTER_FATAL: - return -1; - case COUNTER_RETRY: - goto try_again_reset; - case COUNTER_SKIP: - continue; - default: - break; - } - } - counter->supported =3D true; - } - } - } affinity__cleanup(&affinity); =20 evlist__for_each_entry(evsel_list, counter) { diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 5f92319ce258..39d294f6c321 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -342,36 +342,65 @@ static int evlist__nr_threads(struct evlist *evlist, = struct evsel *evsel) return perf_thread_map__nr(evlist->core.threads); } =20 -void evlist__cpu_iter_start(struct evlist *evlist) -{ - struct evsel *pos; - - /* - * Reset the per evsel cpu_iter. This is needed because - * each evsel's cpumap may have a different index space, - * and some operations need the index to modify - * the FD xyarray (e.g. open, close) - */ - evlist__for_each_entry(evlist, pos) - pos->cpu_iter =3D 0; -} +struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct= affinity *affinity) +{ + struct evlist_cpu_iterator itr =3D { + .container =3D evlist, + .evsel =3D evlist__first(evlist), + .cpu_map_idx =3D 0, + .evlist_cpu_map_idx =3D 0, + .evlist_cpu_map_nr =3D perf_cpu_map__nr(evlist->core.all_cpus), + .cpu =3D -1, + .affinity =3D affinity, + }; =20 -bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu) -{ - if (ev->cpu_iter >=3D ev->core.cpus->nr) - return true; - if (cpu >=3D 0 && ev->core.cpus->map[ev->cpu_iter] !=3D cpu) - return true; - return false; + if (itr.affinity) { + itr.cpu =3D perf_cpu_map__cpu(evlist->core.all_cpus, 0); + affinity__set(itr.affinity, itr.cpu); + itr.cpu_map_idx =3D perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu); + /* + * If this CPU isn't in the evsel's cpu map then advance through + * the list. + */ + if (itr.cpu_map_idx =3D=3D -1) + evlist_cpu_iterator__next(&itr); + } + return itr; +} + +void evlist_cpu_iterator__next(struct evlist_cpu_iterator *evlist_cpu_itr) +{ + while (evlist_cpu_itr->evsel !=3D evlist__last(evlist_cpu_itr->container)= ) { + evlist_cpu_itr->evsel =3D evsel__next(evlist_cpu_itr->evsel); + evlist_cpu_itr->cpu_map_idx =3D + perf_cpu_map__idx(evlist_cpu_itr->evsel->core.cpus, + evlist_cpu_itr->cpu); + if (evlist_cpu_itr->cpu_map_idx !=3D -1) + return; + } + evlist_cpu_itr->evlist_cpu_map_idx++; + if (evlist_cpu_itr->evlist_cpu_map_idx < evlist_cpu_itr->evlist_cpu_map_n= r) { + evlist_cpu_itr->evsel =3D evlist__first(evlist_cpu_itr->container); + evlist_cpu_itr->cpu =3D + perf_cpu_map__cpu(evlist_cpu_itr->container->core.all_cpus, + evlist_cpu_itr->evlist_cpu_map_idx); + if (evlist_cpu_itr->affinity) + affinity__set(evlist_cpu_itr->affinity, evlist_cpu_itr->cpu); + evlist_cpu_itr->cpu_map_idx =3D + perf_cpu_map__idx(evlist_cpu_itr->evsel->core.cpus, + evlist_cpu_itr->cpu); + /* + * If this CPU isn't in the evsel's cpu map then advance through + * the list. + */ + if (evlist_cpu_itr->cpu_map_idx =3D=3D -1) + evlist_cpu_iterator__next(evlist_cpu_itr); + } } =20 -bool evsel__cpu_iter_skip(struct evsel *ev, int cpu) +bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu= _itr) { - if (!evsel__cpu_iter_skip_no_inc(ev, cpu)) { - ev->cpu_iter++; - return false; - } - return true; + return evlist_cpu_itr->evlist_cpu_map_idx >=3D evlist_cpu_itr->evlist_cpu= _map_nr; } =20 static int evsel__strcmp(struct evsel *pos, char *evsel_name) @@ -400,31 +429,26 @@ static int evlist__is_enabled(struct evlist *evlist) static void __evlist__disable(struct evlist *evlist, char *evsel_name) { struct evsel *pos; + struct evlist_cpu_iterator evlist_cpu_itr; struct affinity affinity; - int cpu, i, imm =3D 0; bool has_imm =3D false; =20 if (affinity__setup(&affinity) < 0) return; =20 /* Disable 'immediate' events last */ - for (imm =3D 0; imm <=3D 1; imm++) { - evlist__for_each_cpu(evlist, i, cpu) { - affinity__set(&affinity, cpu); - - evlist__for_each_entry(evlist, pos) { - if (evsel__strcmp(pos, evsel_name)) - continue; - if (evsel__cpu_iter_skip(pos, cpu)) - continue; - if (pos->disabled || !evsel__is_group_leader(pos) || !pos->core.fd) - continue; - if (pos->immediate) - has_imm =3D true; - if (pos->immediate !=3D imm) - continue; - evsel__disable_cpu(pos, pos->cpu_iter - 1); - } + for (int imm =3D 0; imm <=3D 1; imm++) { + evlist__for_each_cpu(evlist_cpu_itr, evlist, &affinity) { + pos =3D evlist_cpu_itr.evsel; + if (evsel__strcmp(pos, evsel_name)) + continue; + if (pos->disabled || !evsel__is_group_leader(pos) || !pos->core.fd) + continue; + if (pos->immediate) + has_imm =3D true; + if (pos->immediate !=3D imm) + continue; + evsel__disable_cpu(pos, evlist_cpu_itr.cpu_map_idx); } if (!has_imm) break; @@ -462,24 +486,19 @@ void evlist__disable_evsel(struct evlist *evlist, cha= r *evsel_name) static void __evlist__enable(struct evlist *evlist, char *evsel_name) { struct evsel *pos; + struct evlist_cpu_iterator evlist_cpu_itr; struct affinity affinity; - int cpu, i; =20 if (affinity__setup(&affinity) < 0) return; =20 - evlist__for_each_cpu(evlist, i, cpu) { - affinity__set(&affinity, cpu); - - evlist__for_each_entry(evlist, pos) { - if (evsel__strcmp(pos, evsel_name)) - continue; - if (evsel__cpu_iter_skip(pos, cpu)) - continue; - if (!evsel__is_group_leader(pos) || !pos->core.fd) - continue; - evsel__enable_cpu(pos, pos->cpu_iter - 1); - } + evlist__for_each_cpu(evlist_cpu_itr, evlist, &affinity) { + pos =3D evlist_cpu_itr.evsel; + if (evsel__strcmp(pos, evsel_name)) + continue; + if (!evsel__is_group_leader(pos) || !pos->core.fd) + continue; + evsel__enable_cpu(pos, evlist_cpu_itr.cpu_map_idx); } affinity__cleanup(&affinity); evlist__for_each_entry(evlist, pos) { @@ -1264,8 +1283,8 @@ void evlist__set_selected(struct evlist *evlist, stru= ct evsel *evsel) void evlist__close(struct evlist *evlist) { struct evsel *evsel; + struct evlist_cpu_iterator evlist_cpu_itr; struct affinity affinity; - int cpu, i; =20 /* * With perf record core.cpus is usually NULL. @@ -1279,15 +1298,12 @@ void evlist__close(struct evlist *evlist) =20 if (affinity__setup(&affinity) < 0) return; - evlist__for_each_cpu(evlist, i, cpu) { - affinity__set(&affinity, cpu); =20 - evlist__for_each_entry_reverse(evlist, evsel) { - if (evsel__cpu_iter_skip(evsel, cpu)) - continue; - perf_evsel__close_cpu(&evsel->core, evsel->cpu_iter - 1); - } + evlist__for_each_cpu(evlist_cpu_itr, evlist, &affinity) { + perf_evsel__close_cpu(&evlist_cpu_itr.evsel->core, + evlist_cpu_itr.cpu_map_idx); } + affinity__cleanup(&affinity); evlist__for_each_entry_reverse(evlist, evsel) { perf_evsel__free_fd(&evsel->core); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 27594900a052..57828ebfcb61 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -327,17 +327,53 @@ void evlist__to_front(struct evlist *evlist, struct e= vsel *move_evsel); #define evlist__for_each_entry_safe(evlist, tmp, evsel) \ __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel) =20 -#define evlist__for_each_cpu(evlist, index, cpu) \ - evlist__cpu_iter_start(evlist); \ - perf_cpu_map__for_each_cpu (cpu, index, (evlist)->core.all_cpus) +/** Iterator state for evlist__for_each_cpu */ +struct evlist_cpu_iterator { + /** The list being iterated through. */ + struct evlist *container; + /** The current evsel of the iterator. */ + struct evsel *evsel; + /** The CPU map index corresponding to the evsel->core.cpus for the curre= nt CPU. */ + int cpu_map_idx; + /** + * The CPU map index corresponding to evlist->core.all_cpus for the + * current CPU. Distinct from cpu_map_idx as the evsel's cpu map may + * contain fewer entries. + */ + int evlist_cpu_map_idx; + /** The number of CPU map entries in evlist->core.all_cpus. */ + int evlist_cpu_map_nr; + /** The current CPU of the iterator. */ + int cpu; + /** If present, used to set the affinity when switching between CPUs. */ + struct affinity *affinity; +}; + +/** + * evlist__for_each_cpu - without affinity, iterate over the evlist. With + * affinity, iterate over all CPUs and then the evl= ist + * for each evsel on that CPU. When switching betwe= en + * CPUs the affinity is set to the CPU to avoid IPIs + * during syscalls. + * @evlist_cpu_itr: the iterator instance. + * @evlist: evlist instance to iterate. + * @affinity: NULL or used to set the affinity to the current CPU. + */ +#define evlist__for_each_cpu(evlist_cpu_itr, evlist, affinity) \ + for ((evlist_cpu_itr) =3D evlist__cpu_begin(evlist, affinity); \ + !evlist_cpu_iterator__end(&evlist_cpu_itr); \ + evlist_cpu_iterator__next(&evlist_cpu_itr)) + +/** Returns an iterator set to the first CPU/evsel of evlist. */ +struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct= affinity *affinity); +/** Move to next element in iterator, updating CPU, evsel and the affinity= . */ +void evlist_cpu_iterator__next(struct evlist_cpu_iterator *evlist_cpu_itr); +/** Returns true when iterator is at the end of the CPUs and evlist. */ +bool evlist_cpu_iterator__end(const struct evlist_cpu_iterator *evlist_cpu= _itr); =20 struct evsel *evlist__get_tracking_event(struct evlist *evlist); void evlist__set_tracking_event(struct evlist *evlist, struct evsel *track= ing_evsel); =20 -void evlist__cpu_iter_start(struct evlist *evlist); -bool evsel__cpu_iter_skip(struct evsel *ev, int cpu); -bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu); - struct evsel *evlist__find_evsel_by_str(struct evlist *evlist, const char = *str); =20 struct evsel *evlist__event2evsel(struct evlist *evlist, union perf_event = *event); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 99aa3363def7..7cb7c9c77ab0 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -121,7 +121,6 @@ struct evsel { bool errored; struct hashmap *per_pkg_mask; int err; - int cpu_iter; struct { evsel__sb_cb_t *cb; void *data; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B88FC433EF for ; Thu, 23 Dec 2021 07:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347471AbhLWHse (ORCPT ); Thu, 23 Dec 2021 02:48:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347247AbhLWHrv (ORCPT ); Thu, 23 Dec 2021 02:47:51 -0500 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 B7AB4C061785 for ; Wed, 22 Dec 2021 23:47:37 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id d27-20020a25addb000000b005c2355d9052so8658427ybe.3 for ; Wed, 22 Dec 2021 23:47:37 -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=JSu0B8tdHCivMmDl9rVtfSdI8JuN1SLb4661ulsOdOs=; b=MuISUn2+IVYi8HnSczfjLUDfV1pxeGKnT55sncC7WyvReipoUdXYVPMvxpwiPDMqU2 AYJfmx4vLR9RcAyDuu6owRy9tJrDvwVoKz5c4xUKG9YjpN5NJpauNgUb7OqvoFyIwIi/ NasVWkbfWPGJRjpuGOHNm10Oxtbnfb9Id+Ha4YpxO5wLSBe4wCUPI8zSOyvrGQFp+nyz jxIAyTkK5gXOUZeb15/+pDNVx/56JMEvk6A0w3MNT1H9QfcV0y//6f8mh7+jLD6CTbU9 0K6uYkGy6TfG1SrF8sc3vm45nSfZl4mk4HKWbKKlUWWsQNpQ7GFYMEjZTg1EljASGglN RO2w== 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=JSu0B8tdHCivMmDl9rVtfSdI8JuN1SLb4661ulsOdOs=; b=Uf01+Ews95fLRphwRo2bW04I3uVgz2bBdOV+zQfjL+faqPfT7hH89Lx+q56PUY15v9 Tsx8LkNwSxC2/wj6SOp/UC4dSb2OKED09zccXd+dHe1uGA51Qm5uPHtOvNTjDPngjk1D hAflIMplNMhtxx5ZyWd8zVZbu0cMniUXYI4uDhxoYqb0QR0aMSjhBu1ER2n3+eWn+iQQ YxkgOT26inLW5cM+GI2RimDF+E+C62vJaLf3VzlQkrw7Vi33x13MPQlZOhQAxV/4wN5b L/GXwrZ3c770TBFOnXNaBdy/wjIQEyWteE1m8BIrp1TNnxrbIBBbrY3A4MiphhCNoDHY dAjw== X-Gm-Message-State: AOAM532dst/5N2daB89ZRqXg0tTfUPu3NAh3E1iFBSePR5PkOdf1Lc5x ytq3fqe/BrEmZoKHSQAzE/2mZzpg6l4V X-Google-Smtp-Source: ABdhPJxYbNY0pwl8Fufs0Pid0QbIDU5v4Zuv3xywBYVxR6l5Lyw95aqt3+MnHVp2HyKaLvHGj3YPR0TT1Jox X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a5b:14a:: with SMTP id c10mr1640778ybp.586.1640245656983; Wed, 22 Dec 2021 23:47:36 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:28 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-36-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 35/48] perf evsel: Pass cpu not cpu map index to synthesize 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" evsel__write_stat_event was incorrectly passing a cpu map index rather than a CPU to perf_event__synthesize_stat. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index f31bc34bd4cc..ec252579b587 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -327,10 +327,11 @@ static int write_stat_round_event(u64 tm, u64 type) =20 #define SID(e, x, y) xyarray__entry(e->core.sample_id, x, y) =20 -static int evsel__write_stat_event(struct evsel *counter, u32 cpu, u32 thr= ead, +static int evsel__write_stat_event(struct evsel *counter, int cpu_map_idx,= u32 thread, struct perf_counts_values *count) { - struct perf_sample_id *sid =3D SID(counter, cpu, thread); + struct perf_sample_id *sid =3D SID(counter, cpu_map_idx, thread); + int cpu =3D perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx); =20 return perf_event__synthesize_stat(NULL, cpu, thread, sid->id, count, process_synthesized_event, NULL); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 842C4C433FE for ; Thu, 23 Dec 2021 07:48:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347294AbhLWHsq (ORCPT ); Thu, 23 Dec 2021 02:48:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347121AbhLWHrw (ORCPT ); Thu, 23 Dec 2021 02:47:52 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63381C061757 for ; Wed, 22 Dec 2021 23:47:40 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id l28-20020a25b31c000000b005c27dd4987bso8674757ybj.18 for ; Wed, 22 Dec 2021 23:47:40 -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=k6RAlIhwSy4euwiiIyrIldZt9nlK1nan7mAyKCFApFY=; b=ownxiw/vt2pjo97xGiLh2jcneMKFLYvx94XaBGlQ9zY7NqjFWQWTCDCEg1THWtCc/W dJhdPDyIFLbXvqZM+ilqQebhX3F0g3cFfenyfeaDQrhDyiq0i1jfF+3pKFIDlRPZw4tq vWXVZgVuoOOUILCkelA8guBbmFertL/X5dsm+QmTGT5y7WoWOGP0+6xjlnGTfcguI8rn B5d9Oi+59MBPvpZa24vNKq9RhAYxOJosnlgAeazGLoz5G2D4y8h1M1JbPb+P8hnwUXSV RwroxgnaO3VWhcYgtjd7rwVNVjsRbpHNNTKjX+CMqwBSnuSHM1fCnpiJUcbHXDBg9WHr b8lw== 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=k6RAlIhwSy4euwiiIyrIldZt9nlK1nan7mAyKCFApFY=; b=Nj8CdJDZ8FhJ02yF9fISrv8Jjq2qdoonrUdErls4CF7MM1PzMzXuQWPpLEjLKExzKb XR/PYQLPJ7Mfm8PrXl0RzJpMQTIUBEfeIq5mGeZUjr+Y0VYV22ZmXnQ62sMwR/7164Yt 5ftcASpK/VFvJTsbeFWcWFTKDoMxe+TDqyF8ATdmdsrd7OsTgXdzjUtXhmX4J2rtvo+o iqwJ/f5UsM26Uh1ZLUV3Y5j/aj0asIrz2pjTQcsN+B/aZTgBdZpJwvN2KwvvrAvLzq8R LdFn33jTwR4vAobLDU+/XAQ/caJ0szm1ylH2B10DhQ86EWe9Zmr06G6Fl4rQp5sNrlHw /RLg== X-Gm-Message-State: AOAM530PDVUrNg2m52sJ16rzvznTGYGefPWAj3jyLl5n+Nz6WM2qjjyW CxUcmvrVxjAPIy650K+BrX87uxbejXMm X-Google-Smtp-Source: ABdhPJxGfT1ZdlQrMY0/6tpguRYtWDuKzA9SMuP697ld+ynfqgOCvWi9XDayYfxaps23g8rcEctfjkec1+NU X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:e755:: with SMTP id e82mr1616261ybh.389.1640245659626; Wed, 22 Dec 2021 23:47:39 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:29 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-37-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 36/48] perf stat: Correct variable name for read counter 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Switch from cpu to cpu_map_idx to reduce confusion. Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 24 ++++++++++++------------ tools/perf/util/evsel.c | 30 +++++++++++++++--------------- tools/perf/util/evsel.h | 16 ++++++++-------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index ec252579b587..68543bc7459f 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -337,25 +337,25 @@ static int evsel__write_stat_event(struct evsel *coun= ter, int cpu_map_idx, u32 t process_synthesized_event, NULL); } =20 -static int read_single_counter(struct evsel *counter, int cpu, +static int read_single_counter(struct evsel *counter, int cpu_map_idx, int thread, struct timespec *rs) { if (counter->tool_event =3D=3D PERF_TOOL_DURATION_TIME) { u64 val =3D rs->tv_nsec + rs->tv_sec*1000000000ULL; struct perf_counts_values *count =3D - perf_counts(counter->counts, cpu, thread); + perf_counts(counter->counts, cpu_map_idx, thread); count->ena =3D count->run =3D val; count->val =3D val; return 0; } - return evsel__read_counter(counter, cpu, thread); + return evsel__read_counter(counter, cpu_map_idx, thread); } =20 /* * Read out the results of a single counter: * do not aggregate counts across CPUs in system-wide mode */ -static int read_counter_cpu(struct evsel *counter, struct timespec *rs, in= t cpu) +static int read_counter_cpu(struct evsel *counter, struct timespec *rs, in= t cpu_map_idx) { int nthreads =3D perf_thread_map__nr(evsel_list->core.threads); int thread; @@ -369,24 +369,24 @@ static int read_counter_cpu(struct evsel *counter, st= ruct timespec *rs, int cpu) for (thread =3D 0; thread < nthreads; thread++) { struct perf_counts_values *count; =20 - count =3D perf_counts(counter->counts, cpu, thread); + count =3D perf_counts(counter->counts, cpu_map_idx, thread); =20 /* * The leader's group read loads data into its group members * (via evsel__read_counter()) and sets their count->loaded. */ - if (!perf_counts__is_loaded(counter->counts, cpu, thread) && - read_single_counter(counter, cpu, thread, rs)) { + if (!perf_counts__is_loaded(counter->counts, cpu_map_idx, thread) && + read_single_counter(counter, cpu_map_idx, thread, rs)) { counter->counts->scaled =3D -1; - perf_counts(counter->counts, cpu, thread)->ena =3D 0; - perf_counts(counter->counts, cpu, thread)->run =3D 0; + perf_counts(counter->counts, cpu_map_idx, thread)->ena =3D 0; + perf_counts(counter->counts, cpu_map_idx, thread)->run =3D 0; return -1; } =20 - perf_counts__set_loaded(counter->counts, cpu, thread, false); + perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, false); =20 if (STAT_RECORD) { - if (evsel__write_stat_event(counter, cpu, thread, count)) { + if (evsel__write_stat_event(counter, cpu_map_idx, thread, count)) { pr_err("failed to write stat event\n"); return -1; } @@ -396,7 +396,7 @@ static int read_counter_cpu(struct evsel *counter, stru= ct timespec *rs, int cpu) fprintf(stat_config.output, "%s: %d: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", evsel__name(counter), - cpu, + perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx), count->val, count->ena, count->run); } } diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 6c9af21776e6..b4a2c5034cfe 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1476,11 +1476,11 @@ void evsel__compute_deltas(struct evsel *evsel, int= cpu, int thread, count->run =3D count->run - tmp.run; } =20 -static int evsel__read_one(struct evsel *evsel, int cpu, int thread) +static int evsel__read_one(struct evsel *evsel, int cpu_map_idx, int threa= d) { - struct perf_counts_values *count =3D perf_counts(evsel->counts, cpu, thre= ad); + struct perf_counts_values *count =3D perf_counts(evsel->counts, cpu_map_i= dx, thread); =20 - return perf_evsel__read(&evsel->core, cpu, thread, count); + return perf_evsel__read(&evsel->core, cpu_map_idx, thread, count); } =20 static void evsel__set_count(struct evsel *counter, int cpu, int thread, u= 64 val, u64 ena, u64 run) @@ -1530,7 +1530,7 @@ static int evsel__process_group_data(struct evsel *le= ader, int cpu, int thread, return 0; } =20 -static int evsel__read_group(struct evsel *leader, int cpu, int thread) +static int evsel__read_group(struct evsel *leader, int cpu_map_idx, int th= read) { struct perf_stat_evsel *ps =3D leader->stats; u64 read_format =3D leader->core.attr.read_format; @@ -1551,42 +1551,42 @@ static int evsel__read_group(struct evsel *leader, = int cpu, int thread) ps->group_data =3D data; } =20 - if (FD(leader, cpu, thread) < 0) + if (FD(leader, cpu_map_idx, thread) < 0) return -EINVAL; =20 - if (readn(FD(leader, cpu, thread), data, size) <=3D 0) + if (readn(FD(leader, cpu_map_idx, thread), data, size) <=3D 0) return -errno; =20 - return evsel__process_group_data(leader, cpu, thread, data); + return evsel__process_group_data(leader, cpu_map_idx, thread, data); } =20 -int evsel__read_counter(struct evsel *evsel, int cpu, int thread) +int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread) { u64 read_format =3D evsel->core.attr.read_format; =20 if (read_format & PERF_FORMAT_GROUP) - return evsel__read_group(evsel, cpu, thread); + return evsel__read_group(evsel, cpu_map_idx, thread); =20 - return evsel__read_one(evsel, cpu, thread); + return evsel__read_one(evsel, cpu_map_idx, thread); } =20 -int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool sc= ale) +int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread,= bool scale) { struct perf_counts_values count; size_t nv =3D scale ? 3 : 1; =20 - if (FD(evsel, cpu, thread) < 0) + if (FD(evsel, cpu_map_idx, thread) < 0) return -EINVAL; =20 if (evsel->counts =3D=3D NULL && evsel__alloc_counts(evsel) < 0) return -ENOMEM; =20 - if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <=3D 0) + if (readn(FD(evsel, cpu_map_idx, thread), &count, nv * sizeof(u64)) <=3D = 0) return -errno; =20 - evsel__compute_deltas(evsel, cpu, thread, &count); + evsel__compute_deltas(evsel, cpu_map_idx, thread, &count); perf_counts_values__scale(&count, scale, NULL); - *perf_counts(evsel->counts, cpu, thread) =3D count; + *perf_counts(evsel->counts, cpu_map_idx, thread) =3D count; return 0; } =20 diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 7cb7c9c77ab0..c3db41282400 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -333,32 +333,32 @@ static inline bool evsel__match2(struct evsel *e1, st= ruct evsel *e2) (e1->core.attr.config =3D=3D e2->core.attr.config); } =20 -int evsel__read_counter(struct evsel *evsel, int cpu, int thread); +int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread); =20 -int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool sc= ale); +int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread,= bool scale); =20 /** * evsel__read_on_cpu - Read out the results on a CPU and thread * * @evsel - event selector to read value - * @cpu - CPU of interest + * @cpu_map_idx - CPU of interest * @thread - thread of interest */ -static inline int evsel__read_on_cpu(struct evsel *evsel, int cpu, int thr= ead) +static inline int evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx,= int thread) { - return __evsel__read_on_cpu(evsel, cpu, thread, false); + return __evsel__read_on_cpu(evsel, cpu_map_idx, thread, false); } =20 /** * evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, s= caled * * @evsel - event selector to read value - * @cpu - CPU of interest + * @cpu_map_idx - CPU of interest * @thread - thread of interest */ -static inline int evsel__read_on_cpu_scaled(struct evsel *evsel, int cpu, = int thread) +static inline int evsel__read_on_cpu_scaled(struct evsel *evsel, int cpu_m= ap_idx, int thread) { - return __evsel__read_on_cpu(evsel, cpu, thread, true); + return __evsel__read_on_cpu(evsel, cpu_map_idx, thread, true); } =20 int evsel__parse_sample(struct evsel *evsel, union perf_event *event, --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42D55C4332F for ; Thu, 23 Dec 2021 07:48:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347301AbhLWHss (ORCPT ); Thu, 23 Dec 2021 02:48:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347023AbhLWHrw (ORCPT ); Thu, 23 Dec 2021 02:47:52 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E31C5C06175A for ; Wed, 22 Dec 2021 23:47:42 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id t24-20020a252d18000000b005c225ae9e16so8619548ybt.15 for ; Wed, 22 Dec 2021 23:47:42 -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=Psj3VZxbAwFP1vAQTBNCyzZPof5d8rm7KZTKeBB5bD8=; b=XnaIT5sMNMofcBzh0eJYLWvadrz18KX/BFz9jUe2q1NXS2VPiNFBVEld/VzCGjO5AJ FesCgPT1eXtNtqbcNCKMNf9LycfaTJBJOlrce26GDAyFz6z4MXPt4bvKw/+SPq+6t1QL LZeUpr+1TVP1sNbr9rQ2lSQ8f3/oxHPpvg2nZQdb+I+3iT/KirMJfA5gx7uFjbvpZmK9 0HfScruNAfRInokHPquRdRA7NlAKidAy4qpV7sD+jjGQP+aJEMbVJdPl3+UugILUOItq gdi9DnUHlx2K25ForCOERAX8Wo862UxrmXTHY42z5pCCMvsP4Amu8/YnLwOsebhY8Uqw f70Q== 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=Psj3VZxbAwFP1vAQTBNCyzZPof5d8rm7KZTKeBB5bD8=; b=HLFhaGM9uj9HEM5ACqvj52WDZdH6yHf6Z4yTF50LmQ3O5GkXogRh0S+ryO3M7OVw70 ave6bzABiUkSUbY/mP/DTgBMoMRv/aflIJezqNZjf4x5rtTR4TnVlYLcF4sZTUS3akMr tGy6u+R19gRSlOmu2/xeV7UwkhKj3zK7JP135tQq4mhBX+0NjETr5dgK53GIxWux/J7z GaGvdXQT5/4yOqj9XQeQTsF+5epdNosOMF6rqYrKmbwMKIc5xXpx2324wSm4RwjaO3i8 /A8INgAKIWFQTtBN2ZcaLYmQppX0h5Y686xEfHHjTVN3KwgDd5OxIBI1SsbtHDKY1m78 XK/Q== X-Gm-Message-State: AOAM530SqKbCiy4Vy3MKlYRmSAFTPYLYWehRkrgnbK/sVznq4RmIIf8Y EweP4lf5BUM9jl75cR+p29P1S5xW705Y X-Google-Smtp-Source: ABdhPJzKXlgj+iaoDTmwl/snbfmWy/Imp/moMR6bS6PHjM3kYqJPPGlIKA4xq/Wbw+nE4uQY8vBCaZBQhOJt X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:b5c7:: with SMTP id d7mr1660547ybg.741.1640245662171; Wed, 22 Dec 2021 23:47:42 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:30 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-38-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 37/48] perf evsel: Rename CPU around get_group_fd 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" CPU is really a cpu map index, change names to make code more intention revealing. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index b4a2c5034cfe..4b3ba4408af2 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1591,27 +1591,27 @@ int __evsel__read_on_cpu(struct evsel *evsel, int c= pu_map_idx, int thread, bool } =20 static int evsel__match_other_cpu(struct evsel *evsel, struct evsel *other, - int cpu) + int cpu_map_idx) { - int cpuid; + int cpu; =20 - cpuid =3D perf_cpu_map__cpu(evsel->core.cpus, cpu); - return perf_cpu_map__idx(other->core.cpus, cpuid); + cpu =3D perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); + return perf_cpu_map__idx(other->core.cpus, cpu); } =20 -static int evsel__hybrid_group_cpu(struct evsel *evsel, int cpu) +static int evsel__hybrid_group_cpu_map_idx(struct evsel *evsel, int cpu_ma= p_idx) { struct evsel *leader =3D evsel__leader(evsel); =20 if ((evsel__is_hybrid(evsel) && !evsel__is_hybrid(leader)) || (!evsel__is_hybrid(evsel) && evsel__is_hybrid(leader))) { - return evsel__match_other_cpu(evsel, leader, cpu); + return evsel__match_other_cpu(evsel, leader, cpu_map_idx); } =20 - return cpu; + return cpu_map_idx; } =20 -static int get_group_fd(struct evsel *evsel, int cpu, int thread) +static int get_group_fd(struct evsel *evsel, int cpu_map_idx, int thread) { struct evsel *leader =3D evsel__leader(evsel); int fd; @@ -1625,11 +1625,11 @@ static int get_group_fd(struct evsel *evsel, int cp= u, int thread) */ BUG_ON(!leader->core.fd); =20 - cpu =3D evsel__hybrid_group_cpu(evsel, cpu); - if (cpu =3D=3D -1) + cpu_map_idx =3D evsel__hybrid_group_cpu_map_idx(evsel, cpu_map_idx); + if (cpu_map_idx =3D=3D -1) return -1; =20 - fd =3D FD(leader, cpu, thread); + fd =3D FD(leader, cpu_map_idx, thread); BUG_ON(fd =3D=3D -1); =20 return fd; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 439DCC433EF for ; Thu, 23 Dec 2021 07:48:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347501AbhLWHsv (ORCPT ); Thu, 23 Dec 2021 02:48:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347089AbhLWHr6 (ORCPT ); Thu, 23 Dec 2021 02:47:58 -0500 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 7425BC0619D8 for ; Wed, 22 Dec 2021 23:47:45 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id p133-20020a255b8b000000b006086e19f89fso8559049ybb.19 for ; Wed, 22 Dec 2021 23:47:45 -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=wM2F9YGkn6QITwu+SCK05wcndw1aQWuNO5bNevKaVrE=; b=I3VaHfG8SUE4Gt75X2npP4PVqrzNQI8mhPK/WMyNaMczZyFE4lEeZ1v5XP+qfE++LX UNrc3/Mao4f1U4CzploAaO/UNGOnxyLLE25GfvGxFm+SXdA6+HdNfDce+6AG4KhR4D50 komQGpOo+IEhp+A7dk7STB67/rqJeWdHbjITILfjkQqWbHhf04fjo17PdPuwH1868JX0 yPnH9v14Qqd6LXNbWGQrpn+gCOOfEJMy3Kk/IGfMM5KmZrRKL3nCL/JCQ1XgydSk/u2g ebZ5srkMSUF23E/szNLp3gdOeXkOEhmfFH8Jn41O8yGmp/hFy0snw57T1Kw1313pFInK uORw== 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=wM2F9YGkn6QITwu+SCK05wcndw1aQWuNO5bNevKaVrE=; b=ti0H+6YcWrAVOnw1AfxW4g8mWXNt+M26OPKeVwsVc5wTp8YQSmxhEPrM0tlt9iUWU8 A4aqOl/0Zcn9/Wq3JF4lhMKFEKoXsdlN7sXa9hlekAbI/EPP4ekWGULvn4iCZ8i6keX8 rRrVwVXGbkdifXJRcwIG4/7B2yZZA6050rUfR/AA6kfh3tLMkepmOf4/UoBZQrMyQeCz CNVDRI64Q/hnaJdlwFMxf1gMwcjUFHSw1iwlWFtmDdr1xCLqIIDQHumWzsmX3aSuEzfQ t9NG6YSDZrLjoejK03MhXnDscXtCSUZ/SbAZ0cVHaz68nc1YdDG4ueIqOXtysaU6ROif 9LDQ== X-Gm-Message-State: AOAM531Urwtd+Su3UXPHS0/MSdhlAUOPHr8BglbrJMKH1rPAX0TkEJ15 jKos0eM5nTh0w6R19CrvfLGetqKiV+M6 X-Google-Smtp-Source: ABdhPJy5p01OjIn0FII81SwAXYoRLRKDnND7XSXM7c5skduqLeZtLt2qI1Kg2O0zZxHK/3gbVHDbQLfJvgjP X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:4d8:: with SMTP id 207mr1592266ybe.320.1640245664700; Wed, 22 Dec 2021 23:47:44 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:31 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-39-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 38/48] perf evsel: Reduce scope of evsel__ignore_missing_thread 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move to being static. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 8 ++++---- tools/perf/util/evsel.h | 4 ---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 4b3ba4408af2..8911ebde54d6 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1666,10 +1666,10 @@ static int update_fds(struct evsel *evsel, return 0; } =20 -bool evsel__ignore_missing_thread(struct evsel *evsel, - int nr_cpus, int cpu, - struct perf_thread_map *threads, - int thread, int err) +static bool evsel__ignore_missing_thread(struct evsel *evsel, + int nr_cpus, int cpu, + struct perf_thread_map *threads, + int thread, int err) { pid_t ignore_pid =3D perf_thread_map__pid(threads, thread); =20 diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index c3db41282400..84e597f6c395 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -301,10 +301,6 @@ bool evsel__detect_missing_features(struct evsel *evse= l); enum rlimit_action { NO_CHANGE, SET_TO_MAX, INCREASED_MAX }; bool evsel__increase_rlimit(enum rlimit_action *set_rlimit); =20 -bool evsel__ignore_missing_thread(struct evsel *evsel, - int nr_cpus, int cpu, - struct perf_thread_map *threads, - int thread, int err); bool evsel__precise_ip_fallback(struct evsel *evsel); =20 struct perf_sample; --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E166BC4332F for ; Thu, 23 Dec 2021 07:49:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242730AbhLWHtC (ORCPT ); Thu, 23 Dec 2021 02:49:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347192AbhLWHsP (ORCPT ); Thu, 23 Dec 2021 02:48:15 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE15EC061D5E for ; Wed, 22 Dec 2021 23:47:47 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id s7-20020a5b0447000000b005fb83901511so8688649ybp.11 for ; Wed, 22 Dec 2021 23:47:47 -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=19OmOB1yH4osBFibchDEMz7aKJ6fe3Ae1hC2EyxP8dM=; b=mkwjw/sCQO3HKsC703KdVi6IAxa6LkiZqwe+5666TihFjD+cru6cS/bdpJ4Azgygfl Or7p+YVlU6tNmZ8nm2xDgcy5tIUBKVwDL4uIH2PxTnopgx76ag+EpXRLie03TChqWz3i Wa3Xkl5Y7Vcp0RwHaXSrwILn3rmSJiDirY9HbLlOssWBFu1Rh2/Tr/vCJpvCEferP1Hc rgC/FCzAM2m4/jmhPjMX2KSkhD6Tm4q+byhPUHrmdhcAmRMEcmtbarHGywSOmdV6h6qs m5Z7cE7g3UQ/b826nkuaxfOD0zCBZOlXMMaCV3pIV4fjWbxULu+WdY7r4O1O5w8V2JiJ L1ag== 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=19OmOB1yH4osBFibchDEMz7aKJ6fe3Ae1hC2EyxP8dM=; b=WIZhBPBPwEdBwHH1GK/jJ6UxyuuAJxjaIUFi/W4cE/EnuZOSRXPUttNgMAXAjGVmZz 96GFi8/cj/a+XCvka5mACXGe3b0UFopR1OMOfGQLEDS4BCEPb2qJiEJWwzImGlQoXYAZ jU7NhmJgkEA8G0AUS+e2dDvV6qAs1Xwj+fxut6zjV7ENvc6gTBfljvqsblBAcaWDkCBW VM7I0IcZK/BoT37PXrQI3GlDhaNBuD4b7qbGVGF9PyNO1bEe0MxDkdYeEJMZ+BcZZeni iG65ZRAYzMwizpQGQlICWeP1d+2KH7nvgVUkbTZZxkpZel6oDOzNPSh5DeBoKhzTBjWT gcfQ== X-Gm-Message-State: AOAM530MaM8f5NO7bWxH+peTGQGoxzf4bNcHp5gUnW4+2Qp1yzEHRmuX LsaPSIf0a6j8NjC+fiI5Ug44HaompmWo X-Google-Smtp-Source: ABdhPJyHrIyA8ZFgbNxmtAXCLJ4ixpaOoZpQrLbJBPhFgiriJLIPXXrQ8ZL5LZ1tKKbD925yVRAodlz47pYK X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:c403:: with SMTP id u3mr1871621ybf.82.1640245667064; Wed, 22 Dec 2021 23:47:47 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:32 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-40-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 39/48] perf evsel: Rename variable cpu to index 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make naming less error prone. Signed-off-by: Ian Rogers --- tools/perf/util/evsel.c | 83 +++++++++++++++++++++-------------------- tools/perf/util/evsel.h | 6 +-- tools/perf/util/stat.c | 4 +- tools/perf/util/stat.h | 2 +- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 8911ebde54d6..2b18b29a534f 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1372,9 +1372,9 @@ int evsel__append_addr_filter(struct evsel *evsel, co= nst char *filter) } =20 /* Caller has to clear disabled after going through all CPUs. */ -int evsel__enable_cpu(struct evsel *evsel, int cpu) +int evsel__enable_cpu(struct evsel *evsel, int cpu_map_idx) { - return perf_evsel__enable_cpu(&evsel->core, cpu); + return perf_evsel__enable_cpu(&evsel->core, cpu_map_idx); } =20 int evsel__enable(struct evsel *evsel) @@ -1387,9 +1387,9 @@ int evsel__enable(struct evsel *evsel) } =20 /* Caller has to set disabled after going through all CPUs. */ -int evsel__disable_cpu(struct evsel *evsel, int cpu) +int evsel__disable_cpu(struct evsel *evsel, int cpu_map_idx) { - return perf_evsel__disable_cpu(&evsel->core, cpu); + return perf_evsel__disable_cpu(&evsel->core, cpu_map_idx); } =20 int evsel__disable(struct evsel *evsel) @@ -1455,7 +1455,7 @@ void evsel__delete(struct evsel *evsel) free(evsel); } =20 -void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread, +void evsel__compute_deltas(struct evsel *evsel, int cpu_map_idx, int threa= d, struct perf_counts_values *count) { struct perf_counts_values tmp; @@ -1463,12 +1463,12 @@ void evsel__compute_deltas(struct evsel *evsel, int= cpu, int thread, if (!evsel->prev_raw_counts) return; =20 - if (cpu =3D=3D -1) { + if (cpu_map_idx =3D=3D -1) { tmp =3D evsel->prev_raw_counts->aggr; evsel->prev_raw_counts->aggr =3D *count; } else { - tmp =3D *perf_counts(evsel->prev_raw_counts, cpu, thread); - *perf_counts(evsel->prev_raw_counts, cpu, thread) =3D *count; + tmp =3D *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); + *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread) =3D *count; } =20 count->val =3D count->val - tmp.val; @@ -1483,20 +1483,21 @@ static int evsel__read_one(struct evsel *evsel, int= cpu_map_idx, int thread) return perf_evsel__read(&evsel->core, cpu_map_idx, thread, count); } =20 -static void evsel__set_count(struct evsel *counter, int cpu, int thread, u= 64 val, u64 ena, u64 run) +static void evsel__set_count(struct evsel *counter, int cpu_map_idx, int t= hread, + u64 val, u64 ena, u64 run) { struct perf_counts_values *count; =20 - count =3D perf_counts(counter->counts, cpu, thread); + count =3D perf_counts(counter->counts, cpu_map_idx, thread); =20 count->val =3D val; count->ena =3D ena; count->run =3D run; =20 - perf_counts__set_loaded(counter->counts, cpu, thread, true); + perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, true); } =20 -static int evsel__process_group_data(struct evsel *leader, int cpu, int th= read, u64 *data) +static int evsel__process_group_data(struct evsel *leader, int cpu_map_idx= , int thread, u64 *data) { u64 read_format =3D leader->core.attr.read_format; struct sample_read_value *v; @@ -1515,7 +1516,7 @@ static int evsel__process_group_data(struct evsel *le= ader, int cpu, int thread, =20 v =3D (struct sample_read_value *) data; =20 - evsel__set_count(leader, cpu, thread, v[0].value, ena, run); + evsel__set_count(leader, cpu_map_idx, thread, v[0].value, ena, run); =20 for (i =3D 1; i < nr; i++) { struct evsel *counter; @@ -1524,7 +1525,7 @@ static int evsel__process_group_data(struct evsel *le= ader, int cpu, int thread, if (!counter) return -EINVAL; =20 - evsel__set_count(counter, cpu, thread, v[i].value, ena, run); + evsel__set_count(counter, cpu_map_idx, thread, v[i].value, ena, run); } =20 return 0; @@ -1643,16 +1644,16 @@ static void evsel__remove_fd(struct evsel *pos, int= nr_cpus, int nr_threads, int } =20 static int update_fds(struct evsel *evsel, - int nr_cpus, int cpu_idx, + int nr_cpus, int cpu_map_idx, int nr_threads, int thread_idx) { struct evsel *pos; =20 - if (cpu_idx >=3D nr_cpus || thread_idx >=3D nr_threads) + if (cpu_map_idx >=3D nr_cpus || thread_idx >=3D nr_threads) return -EINVAL; =20 evlist__for_each_entry(evsel->evlist, pos) { - nr_cpus =3D pos !=3D evsel ? nr_cpus : cpu_idx; + nr_cpus =3D pos !=3D evsel ? nr_cpus : cpu_map_idx; =20 evsel__remove_fd(pos, nr_cpus, nr_threads, thread_idx); =20 @@ -1667,7 +1668,7 @@ static int update_fds(struct evsel *evsel, } =20 static bool evsel__ignore_missing_thread(struct evsel *evsel, - int nr_cpus, int cpu, + int nr_cpus, int cpu_map_idx, struct perf_thread_map *threads, int thread, int err) { @@ -1692,7 +1693,7 @@ static bool evsel__ignore_missing_thread(struct evsel= *evsel, * We should remove fd for missing_thread first * because thread_map__remove() will decrease threads->nr. */ - if (update_fds(evsel, nr_cpus, cpu, threads->nr, thread)) + if (update_fds(evsel, nr_cpus, cpu_map_idx, threads->nr, thread)) return false; =20 if (thread_map__remove(threads, thread)) @@ -1974,9 +1975,9 @@ bool evsel__increase_rlimit(enum rlimit_action *set_r= limit) =20 static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads, - int start_cpu, int end_cpu) + int start_cpu_map_idx, int end_cpu_map_idx) { - int cpu, thread, nthreads; + int idx, thread, nthreads; int pid =3D -1, err, old_errno; enum rlimit_action set_rlimit =3D NO_CHANGE; =20 @@ -2003,7 +2004,7 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, =20 display_attr(&evsel->core.attr); =20 - for (cpu =3D start_cpu; cpu < end_cpu; cpu++) { + for (idx =3D start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { =20 for (thread =3D 0; thread < nthreads; thread++) { int fd, group_fd; @@ -2014,17 +2015,17 @@ static int evsel__open_cpu(struct evsel *evsel, str= uct perf_cpu_map *cpus, if (!evsel->cgrp && !evsel->core.system_wide) pid =3D perf_thread_map__pid(threads, thread); =20 - group_fd =3D get_group_fd(evsel, cpu, thread); + group_fd =3D get_group_fd(evsel, idx, thread); =20 test_attr__ready(); =20 pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags = %#lx", - pid, cpus->map[cpu], group_fd, evsel->open_flags); + pid, cpus->map[idx], group_fd, evsel->open_flags); =20 - fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpus->map[cpu], + fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpus->map[idx], group_fd, evsel->open_flags); =20 - FD(evsel, cpu, thread) =3D fd; + FD(evsel, idx, thread) =3D fd; =20 if (fd < 0) { err =3D -errno; @@ -2034,10 +2035,10 @@ static int evsel__open_cpu(struct evsel *evsel, str= uct perf_cpu_map *cpus, goto try_fallback; } =20 - bpf_counter__install_pe(evsel, cpu, fd); + bpf_counter__install_pe(evsel, idx, fd); =20 if (unlikely(test_attr__enabled)) { - test_attr__open(&evsel->core.attr, pid, cpus->map[cpu], + test_attr__open(&evsel->core.attr, pid, cpus->map[idx], fd, group_fd, evsel->open_flags); } =20 @@ -2078,7 +2079,7 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, if (evsel__precise_ip_fallback(evsel)) goto retry_open; =20 - if (evsel__ignore_missing_thread(evsel, cpus->nr, cpu, threads, thread, e= rr)) { + if (evsel__ignore_missing_thread(evsel, cpus->nr, idx, threads, thread, e= rr)) { /* We just removed 1 thread, so lower the upper nthreads limit. */ nthreads--; =20 @@ -2093,7 +2094,7 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, if (err =3D=3D -EMFILE && evsel__increase_rlimit(&set_rlimit)) goto retry_open; =20 - if (err !=3D -EINVAL || cpu > 0 || thread > 0) + if (err !=3D -EINVAL || idx > 0 || thread > 0) goto out_close; =20 if (evsel__detect_missing_features(evsel)) @@ -2105,12 +2106,12 @@ static int evsel__open_cpu(struct evsel *evsel, str= uct perf_cpu_map *cpus, old_errno =3D errno; do { while (--thread >=3D 0) { - if (FD(evsel, cpu, thread) >=3D 0) - close(FD(evsel, cpu, thread)); - FD(evsel, cpu, thread) =3D -1; + if (FD(evsel, idx, thread) >=3D 0) + close(FD(evsel, idx, thread)); + FD(evsel, idx, thread) =3D -1; } thread =3D nthreads; - } while (--cpu >=3D 0); + } while (--idx >=3D 0); errno =3D old_errno; return err; } @@ -2127,13 +2128,13 @@ void evsel__close(struct evsel *evsel) perf_evsel__free_id(&evsel->core); } =20 -int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, in= t cpu) +int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, in= t cpu_map_idx) { - if (cpu =3D=3D -1) + if (cpu_map_idx =3D=3D -1) return evsel__open_cpu(evsel, cpus, NULL, 0, cpus ? cpus->nr : 1); =20 - return evsel__open_cpu(evsel, cpus, NULL, cpu, cpu + 1); + return evsel__open_cpu(evsel, cpus, NULL, cpu_map_idx, cpu_map_idx + 1); } =20 int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *th= reads) @@ -2954,15 +2955,15 @@ struct perf_env *evsel__env(struct evsel *evsel) =20 static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist) { - int cpu, thread; + int cpu_map_idx, thread; =20 - for (cpu =3D 0; cpu < xyarray__max_x(evsel->core.fd); cpu++) { + for (cpu_map_idx =3D 0; cpu_map_idx < xyarray__max_x(evsel->core.fd); cpu= _map_idx++) { for (thread =3D 0; thread < xyarray__max_y(evsel->core.fd); thread++) { - int fd =3D FD(evsel, cpu, thread); + int fd =3D FD(evsel, cpu_map_idx, thread); =20 if (perf_evlist__id_add_fd(&evlist->core, &evsel->core, - cpu, thread, fd) < 0) + cpu_map_idx, thread, fd) < 0) return -1; } } diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 84e597f6c395..5720ceebffac 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -284,12 +284,12 @@ void arch_evsel__fixup_new_cycles(struct perf_event_a= ttr *attr); int evsel__set_filter(struct evsel *evsel, const char *filter); int evsel__append_tp_filter(struct evsel *evsel, const char *filter); int evsel__append_addr_filter(struct evsel *evsel, const char *filter); -int evsel__enable_cpu(struct evsel *evsel, int cpu); +int evsel__enable_cpu(struct evsel *evsel, int cpu_map_idx); int evsel__enable(struct evsel *evsel); int evsel__disable(struct evsel *evsel); -int evsel__disable_cpu(struct evsel *evsel, int cpu); +int evsel__disable_cpu(struct evsel *evsel, int cpu_map_idx); =20 -int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, in= t cpu); +int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, in= t cpu_map_idx); int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *th= reads); int evsel__open(struct evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads); diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 995cb5003133..f7f9757eba23 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -531,7 +531,7 @@ size_t perf_event__fprintf_stat_config(union perf_event= *event, FILE *fp) int create_perf_stat_counter(struct evsel *evsel, struct perf_stat_config *config, struct target *target, - int cpu) + int cpu_map_idx) { struct perf_event_attr *attr =3D &evsel->core.attr; struct evsel *leader =3D evsel__leader(evsel); @@ -585,7 +585,7 @@ int create_perf_stat_counter(struct evsel *evsel, } =20 if (target__has_cpu(target) && !target__has_per_thread(target)) - return evsel__open_per_cpu(evsel, evsel__cpus(evsel), cpu); + return evsel__open_per_cpu(evsel, evsel__cpus(evsel), cpu_map_idx); =20 return evsel__open_per_thread(evsel, evsel->core.threads); } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 32cf24186229..5e25d53e891b 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -248,7 +248,7 @@ size_t perf_event__fprintf_stat_config(union perf_event= *event, FILE *fp); int create_perf_stat_counter(struct evsel *evsel, struct perf_stat_config *config, struct target *target, - int cpu); + int cpu_map_idx); void evlist__print_counters(struct evlist *evlist, struct perf_stat_config= *config, struct target *_target, struct timespec *ts, int argc, const char *= *argv); =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31343C433FE for ; Thu, 23 Dec 2021 07:49:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233176AbhLWHtJ (ORCPT ); Thu, 23 Dec 2021 02:49:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347194AbhLWHsP (ORCPT ); Thu, 23 Dec 2021 02:48:15 -0500 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 866EBC061792 for ; Wed, 22 Dec 2021 23:47:50 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id j204-20020a2523d5000000b005c21574c704so8599408ybj.13 for ; Wed, 22 Dec 2021 23:47:50 -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=J+XZcWIvTsMTXk/jF0b/YxErH+RdVpP417KXG5BKDgQ=; b=qINuLaApMXPezDR3O3jtt/WAs+gUahEe62wROOyyU64FhMjIQDuk6iFrPd9nND5dhZ BHyaPjAI6A84A1YLGA/bZ8OzeV7TALDFXuODvwMf+XrzUK0PZnwNY2OBkrnHqIT4b5ZB xzqy1FWR9uBUiimKdM1M5tXnYThntnMHuLPqAcn6kQ1dqwRJqMsznMMcpkqu+C+F0OTT aTVJ8HNQUN2Sj9wGpuYM3fayqBO7cpJGvAahG3jDfc2FS5xjx6kpilevRyUmp+EdWtSX uQQD3TT0oTYF7xNxxdTY5DdwmtCj334dnul3ra3QpR+8bKDHTLVmmhNmYFiUPtK9cPWg 1GuA== 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=J+XZcWIvTsMTXk/jF0b/YxErH+RdVpP417KXG5BKDgQ=; b=rOKmO0uKBGSJtk9n3YB4tG4fDneX3cIf4S37KDq4Gsy5HRA5DbGGZMvNlHXYgN5XbO 4o8KI9V4Xw6zLC3Qw5qC+/mXDixm+RYOxKLZj9i2hN5rK3FJGoPGjQDzw4gWXpYkEHj4 D/8TYc2eLuUwKbbfJTehWLXJm11F5I+Jd/b62eTjDAObDnCWtMYGMH40JLGMNqhOrkN6 DmUg8SkYo1VZ9w0Nb/PLSvSXJDCY6DRDMchgy1lF5GS2CvxqKLsCEAiPFbm7JfvWUzmS E8i/YhdME0eT2H9e8Hppd4ODGZHQs7c6Z9G/TIe4NYABgLLAygQE3a9LB4uupmfeKrsM A6lA== X-Gm-Message-State: AOAM533dAOgPoLArxV4i5pRdmo/cpABUaruOewV5zizAC3WTQMW8oK5Z A2h1pdr6YRhIb166AFs4sB8KzghLkDju X-Google-Smtp-Source: ABdhPJzLRWoaIPKwhtvd7PAQUCqVSNKCsmBsw5xkU76uWfw/NKh8WqXoB837sdBX/gDC08lELhKKt7I/8ciz X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:d013:: with SMTP id h19mr1759800ybg.428.1640245669757; Wed, 22 Dec 2021 23:47:49 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:33 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-41-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 40/48] perf test: Use perf_cpu_map__for_each_cpu 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clean up variable naming to make cpu and index clearer. Signed-off-by: Ian Rogers --- tools/perf/tests/openat-syscall-all-cpus.c | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/= openat-syscall-all-cpus.c index 544db0839b3b..ca0a50e92839 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -22,7 +22,7 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test = __maybe_unused, int subtest __maybe_unused) { - int err =3D -1, fd, cpu; + int err =3D -1, fd, idx, cpu; struct perf_cpu_map *cpus; struct evsel *evsel; unsigned int nr_openat_calls =3D 111, i; @@ -58,23 +58,23 @@ static int test__openat_syscall_event_on_all_cpus(struc= t test_suite *test __mayb goto out_evsel_delete; } =20 - for (cpu =3D 0; cpu < cpus->nr; ++cpu) { - unsigned int ncalls =3D nr_openat_calls + cpu; + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + unsigned int ncalls =3D nr_openat_calls + idx; /* * XXX eventually lift this restriction in a way that * keeps perf building on older glibc installations * without CPU_ALLOC. 1024 cpus in 2010 still seems * a reasonable upper limit tho :-) */ - if (cpus->map[cpu] >=3D CPU_SETSIZE) { - pr_debug("Ignoring CPU %d\n", cpus->map[cpu]); + if (cpu >=3D CPU_SETSIZE) { + pr_debug("Ignoring CPU %d\n", cpu); continue; } =20 - CPU_SET(cpus->map[cpu], &cpu_set); + CPU_SET(cpu, &cpu_set); if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { pr_debug("sched_setaffinity() failed on CPU %d: %s ", - cpus->map[cpu], + cpu, str_error_r(errno, sbuf, sizeof(sbuf))); goto out_close_fd; } @@ -82,29 +82,29 @@ static int test__openat_syscall_event_on_all_cpus(struc= t test_suite *test __mayb fd =3D openat(0, "/etc/passwd", O_RDONLY); close(fd); } - CPU_CLR(cpus->map[cpu], &cpu_set); + CPU_CLR(cpu, &cpu_set); } =20 evsel->core.cpus =3D perf_cpu_map__get(cpus); =20 err =3D 0; =20 - for (cpu =3D 0; cpu < cpus->nr; ++cpu) { + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { unsigned int expected; =20 - if (cpus->map[cpu] >=3D CPU_SETSIZE) + if (cpu >=3D CPU_SETSIZE) continue; =20 - if (evsel__read_on_cpu(evsel, cpu, 0) < 0) { + if (evsel__read_on_cpu(evsel, idx, 0) < 0) { pr_debug("evsel__read_on_cpu\n"); err =3D -1; break; } =20 - expected =3D nr_openat_calls + cpu; - if (perf_counts(evsel->counts, cpu, 0)->val !=3D expected) { + expected =3D nr_openat_calls + idx; + if (perf_counts(evsel->counts, idx, 0)->val !=3D expected) { pr_debug("evsel__read_on_cpu: expected to intercept %d calls on cpu %d,= got %" PRIu64 "\n", - expected, cpus->map[cpu], perf_counts(evsel->counts, cpu, 0)->val); + expected, cpu, perf_counts(evsel->counts, idx, 0)->val); err =3D -1; } } --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 941DBC433F5 for ; Thu, 23 Dec 2021 07:49:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347522AbhLWHtL (ORCPT ); Thu, 23 Dec 2021 02:49:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347197AbhLWHsP (ORCPT ); Thu, 23 Dec 2021 02:48:15 -0500 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 315E8C061799 for ; Wed, 22 Dec 2021 23:47:53 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id q198-20020a25d9cf000000b005f7a6a84f9fso8570356ybg.6 for ; Wed, 22 Dec 2021 23:47:53 -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=84jiul3eS69fZOps8gyBR2xeuwa8naIlTNqvP/j/8xA=; b=eWvVaORPbPCnckO/NmOe+ry/whk3ae7kUZNUzcG+mrlyrUmZJAMUJzjb+aMMLos9VA 3aF8p1UpAPuuUehAL4NI9mLMLA2AT7CimKeCxG1bJ4r8NrvH/Ag9dpRdUNMYOUpNz+NZ MDT7urMFaz5qbPYzLQUHQp1Nu3Dru8+RHWWE2nLNsuUxnBeAYtXxe5LgRY4izM2LoEQg +P+jY5XIjXuKW6r6/skwTDr3uoDZkiUCDd5RuCCqaGrh4QLQCEqGxXR3v0+3f6qvKYIH GMJmHEiZuL3CtVbNK2buWxV2fNimLbiDIbZ8hJcT+XyNiIhX/Y9qlYd2VOYotU5TM/t1 Vjog== 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=84jiul3eS69fZOps8gyBR2xeuwa8naIlTNqvP/j/8xA=; b=H7v9R/7Bhvk4u8IcI8BxnMh60gNuW+Ca2CSu9E5kpZg47yWgU44BdLL3YxcTC0Kfn+ y5UqWYM/8/2kgHmust39o9hUKR+o2KsFeAwtqxBrZr1tMhdbVkfwM4mjLnCJOJFjl7S6 +alDb7+RS3QdBJHuENtMRxwgMiG7ORcu5GucN1OIbAqIQv1KEEY6IVVhDNWDoQoeYn8i A/ykDKAWHfqbpbLRur6RMo6/95oYr0sXhGmn+ZvQ3rGNVc9I67hFRzDHE11BWiJ/fDeQ MfoAto1OozNG7Ofu4Mm6h9GN822UAPhz/wwFeUcoPCTya7BGTBir/ObYfIsXBS7M7Jaq p8+Q== X-Gm-Message-State: AOAM531QJQgiH5XwB3DNuPHw//Avb+C22HZff4RIom7yVf9RKLfYp1je nG2Z8eKeRIKOSiIwN6QgQOPSjBhB2xJX X-Google-Smtp-Source: ABdhPJxhU524UVDy65p+6AJP7nFi0/17OcNMoh/MQicxFL+nsP8RdWqJqC3cARe3QImikhkZrwzBUDdJOmI/ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:13c6:: with SMTP id 189mr1675596ybt.113.1640245672380; Wed, 22 Dec 2021 23:47:52 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:34 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-42-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 41/48] perf stat: Correct check_per_pkg cpu 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Code was incorrectly using the cpu map index as the CPU. Signed-off-by: Ian Rogers --- tools/perf/util/stat.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index f7f9757eba23..86ab427e87fc 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -292,11 +292,12 @@ static bool pkg_id_equal(const void *__key1, const vo= id *__key2, return *key1 =3D=3D *key2; } =20 -static int check_per_pkg(struct evsel *counter, - struct perf_counts_values *vals, int cpu, bool *skip) +static int check_per_pkg(struct evsel *counter, struct perf_counts_values = *vals, + int cpu_map_idx, bool *skip) { struct hashmap *mask =3D counter->per_pkg_mask; struct perf_cpu_map *cpus =3D evsel__cpus(counter); + int cpu =3D perf_cpu_map__cpu(cpus, cpu_map_idx); int s, d, ret =3D 0; uint64_t *key; =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19A1CC433F5 for ; Thu, 23 Dec 2021 07:49:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347377AbhLWHtO (ORCPT ); Thu, 23 Dec 2021 02:49:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347340AbhLWHsP (ORCPT ); Thu, 23 Dec 2021 02:48:15 -0500 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 011FCC061D72 for ; Wed, 22 Dec 2021 23:47:56 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id s7-20020a5b0447000000b005fb83901511so8688989ybp.11 for ; Wed, 22 Dec 2021 23:47:55 -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=4D9lO78KkmiWxKRxDQOoO9pyFsoIhwFkAX4z1IUujxA=; b=d98vqh2xX6Lm6ak4cUfB7OBetFG8urhfWYruRiJxl7I+Gtd5pj3XN4m0OfWJm30Kg+ 2Is64k3fiPjCFu6kjhq+x3MxnvzTPIQGK49YE5TmWbz9KssYSLHoLq4uHk+TLh8/FxoZ dwMf16A0JPD5Zu8IwDZ3bQ6B4tCxIc5TO9GU+H/r6YhDqooXmKCCiEmkTAaEWDIw6C/k jx+99k0Djm0HwGvFvQh7Fk1quJS7M2/WFEL1NFIksJ6mcnYosiMMegTAJKuhjWwv8Bl+ lF3NVXMo7Tbh9HiZ8f6pTFeSJZABWVxekt4NaeD6D/qGEsFfnRybQPMtFsL8SPgqnk8a B8jw== 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=4D9lO78KkmiWxKRxDQOoO9pyFsoIhwFkAX4z1IUujxA=; b=qt/wtAJS8mOtKXrWUwsrrZDHCVCvaoFTfwqfrCwNWmDyJVwwjqGJE/2oFEd/xTUWjN D0a8JinarooIH36ptuXbpvp+StuJq1KJksv/5N80ugGFmeNk30OQbebDq368bqK6Ti2u do9B7P65PhtNVLBchqpLAuii70WV7pnYZ1HqelkvO+PMgQ1Lz0cWY62FOMP7gFZPsUl7 2Nzfy8kR/bhi6rtTWcHdcULfZVwebmHMjXKUMk2u3AI8UWzvvvvGnEHPzrO8l206EwZr wmZ1AdKEBLJuYtBCeYlCxE20+uWMxnWrW8oGiyG8WbVIb+ZQMhRvlLIf4jUAORHgFfVK 7FOQ== X-Gm-Message-State: AOAM530hF2+4Qddu4tTDyMVJpyUDIK7mHNIXf+3El26B0Mx9qvYD24Bg P80+Cw9iVxDl3afHJFp6fPOEdMmJlaCQ X-Google-Smtp-Source: ABdhPJxejW/lNz8V2JrZSd0vRNyAUtdYkovpRmVUn1uJCLlt07eH/8kukwrgCd2cg+1AFpqRs7MbQsud4MqM X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:2b49:: with SMTP id r70mr1685020ybr.210.1640245675203; Wed, 22 Dec 2021 23:47:55 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:35 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-43-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 42/48] perf stat: Swap variable name cpu to index 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The use of CPU is error prone, switch to cpu_map_idx. Signed-off-by: Ian Rogers --- tools/perf/util/stat-shadow.c | 308 +++++++++++++++++----------------- tools/perf/util/stat.c | 16 +- tools/perf/util/stat.h | 4 +- 3 files changed, 164 insertions(+), 164 deletions(-) diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c index 5c7308efa768..10af7804e482 100644 --- a/tools/perf/util/stat-shadow.c +++ b/tools/perf/util/stat-shadow.c @@ -32,7 +32,7 @@ struct saved_value { struct evsel *evsel; enum stat_type type; int ctx; - int cpu; + int cpu_map_idx; struct cgroup *cgrp; struct runtime_stat *stat; struct stats stats; @@ -47,8 +47,8 @@ static int saved_value_cmp(struct rb_node *rb_node, const= void *entry) rb_node); const struct saved_value *b =3D entry; =20 - if (a->cpu !=3D b->cpu) - return a->cpu - b->cpu; + if (a->cpu_map_idx !=3D b->cpu_map_idx) + return a->cpu_map_idx - b->cpu_map_idx; =20 /* * Previously the rbtree was used to link generic metrics. @@ -105,7 +105,7 @@ static void saved_value_delete(struct rblist *rblist __= maybe_unused, } =20 static struct saved_value *saved_value_lookup(struct evsel *evsel, - int cpu, + int cpu_map_idx, bool create, enum stat_type type, int ctx, @@ -115,7 +115,7 @@ static struct saved_value *saved_value_lookup(struct ev= sel *evsel, struct rblist *rblist; struct rb_node *nd; struct saved_value dm =3D { - .cpu =3D cpu, + .cpu_map_idx =3D cpu_map_idx, .evsel =3D evsel, .type =3D type, .ctx =3D ctx, @@ -213,10 +213,10 @@ struct runtime_stat_data { =20 static void update_runtime_stat(struct runtime_stat *st, enum stat_type type, - int cpu, u64 count, + int cpu_map_idx, u64 count, struct runtime_stat_data *rsd) { - struct saved_value *v =3D saved_value_lookup(NULL, cpu, true, type, + struct saved_value *v =3D saved_value_lookup(NULL, cpu_map_idx, true, typ= e, rsd->ctx, st, rsd->cgrp); =20 if (v) @@ -229,7 +229,7 @@ static void update_runtime_stat(struct runtime_stat *st, * instruction rates, etc: */ void perf_stat__update_shadow_stats(struct evsel *counter, u64 count, - int cpu, struct runtime_stat *st) + int cpu_map_idx, struct runtime_stat *st) { u64 count_ns =3D count; struct saved_value *v; @@ -241,88 +241,88 @@ void perf_stat__update_shadow_stats(struct evsel *cou= nter, u64 count, count *=3D counter->scale; =20 if (evsel__is_clock(counter)) - update_runtime_stat(st, STAT_NSECS, cpu, count_ns, &rsd); + update_runtime_stat(st, STAT_NSECS, cpu_map_idx, count_ns, &rsd); else if (evsel__match(counter, HARDWARE, HW_CPU_CYCLES)) - update_runtime_stat(st, STAT_CYCLES, cpu, count, &rsd); + update_runtime_stat(st, STAT_CYCLES, cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, CYCLES_IN_TX)) - update_runtime_stat(st, STAT_CYCLES_IN_TX, cpu, count, &rsd); + update_runtime_stat(st, STAT_CYCLES_IN_TX, cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TRANSACTION_START)) - update_runtime_stat(st, STAT_TRANSACTION, cpu, count, &rsd); + update_runtime_stat(st, STAT_TRANSACTION, cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, ELISION_START)) - update_runtime_stat(st, STAT_ELISION, cpu, count, &rsd); + update_runtime_stat(st, STAT_ELISION, cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_TOTAL_SLOTS)) update_runtime_stat(st, STAT_TOPDOWN_TOTAL_SLOTS, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_SLOTS_ISSUED)) update_runtime_stat(st, STAT_TOPDOWN_SLOTS_ISSUED, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_SLOTS_RETIRED)) update_runtime_stat(st, STAT_TOPDOWN_SLOTS_RETIRED, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_FETCH_BUBBLES)) update_runtime_stat(st, STAT_TOPDOWN_FETCH_BUBBLES, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_RECOVERY_BUBBLES)) update_runtime_stat(st, STAT_TOPDOWN_RECOVERY_BUBBLES, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_RETIRING)) update_runtime_stat(st, STAT_TOPDOWN_RETIRING, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_BAD_SPEC)) update_runtime_stat(st, STAT_TOPDOWN_BAD_SPEC, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_FE_BOUND)) update_runtime_stat(st, STAT_TOPDOWN_FE_BOUND, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_BE_BOUND)) update_runtime_stat(st, STAT_TOPDOWN_BE_BOUND, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_HEAVY_OPS)) update_runtime_stat(st, STAT_TOPDOWN_HEAVY_OPS, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_BR_MISPREDICT)) update_runtime_stat(st, STAT_TOPDOWN_BR_MISPREDICT, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_FETCH_LAT)) update_runtime_stat(st, STAT_TOPDOWN_FETCH_LAT, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, TOPDOWN_MEM_BOUND)) update_runtime_stat(st, STAT_TOPDOWN_MEM_BOUND, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) update_runtime_stat(st, STAT_STALLED_CYCLES_FRONT, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (evsel__match(counter, HARDWARE, HW_STALLED_CYCLES_BACKEND)) update_runtime_stat(st, STAT_STALLED_CYCLES_BACK, - cpu, count, &rsd); + cpu_map_idx, count, &rsd); else if (evsel__match(counter, HARDWARE, HW_BRANCH_INSTRUCTIONS)) - update_runtime_stat(st, STAT_BRANCHES, cpu, count, &rsd); + update_runtime_stat(st, STAT_BRANCHES, cpu_map_idx, count, &rsd); else if (evsel__match(counter, HARDWARE, HW_CACHE_REFERENCES)) - update_runtime_stat(st, STAT_CACHEREFS, cpu, count, &rsd); + update_runtime_stat(st, STAT_CACHEREFS, cpu_map_idx, count, &rsd); else if (evsel__match(counter, HW_CACHE, HW_CACHE_L1D)) - update_runtime_stat(st, STAT_L1_DCACHE, cpu, count, &rsd); + update_runtime_stat(st, STAT_L1_DCACHE, cpu_map_idx, count, &rsd); else if (evsel__match(counter, HW_CACHE, HW_CACHE_L1I)) - update_runtime_stat(st, STAT_L1_ICACHE, cpu, count, &rsd); + update_runtime_stat(st, STAT_L1_ICACHE, cpu_map_idx, count, &rsd); else if (evsel__match(counter, HW_CACHE, HW_CACHE_LL)) - update_runtime_stat(st, STAT_LL_CACHE, cpu, count, &rsd); + update_runtime_stat(st, STAT_LL_CACHE, cpu_map_idx, count, &rsd); else if (evsel__match(counter, HW_CACHE, HW_CACHE_DTLB)) - update_runtime_stat(st, STAT_DTLB_CACHE, cpu, count, &rsd); + update_runtime_stat(st, STAT_DTLB_CACHE, cpu_map_idx, count, &rsd); else if (evsel__match(counter, HW_CACHE, HW_CACHE_ITLB)) - update_runtime_stat(st, STAT_ITLB_CACHE, cpu, count, &rsd); + update_runtime_stat(st, STAT_ITLB_CACHE, cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, SMI_NUM)) - update_runtime_stat(st, STAT_SMI_NUM, cpu, count, &rsd); + update_runtime_stat(st, STAT_SMI_NUM, cpu_map_idx, count, &rsd); else if (perf_stat_evsel__is(counter, APERF)) - update_runtime_stat(st, STAT_APERF, cpu, count, &rsd); + update_runtime_stat(st, STAT_APERF, cpu_map_idx, count, &rsd); =20 if (counter->collect_stat) { - v =3D saved_value_lookup(counter, cpu, true, STAT_NONE, 0, st, + v =3D saved_value_lookup(counter, cpu_map_idx, true, STAT_NONE, 0, st, rsd.cgrp); update_stats(&v->stats, count); if (counter->metric_leader) v->metric_total +=3D count; } else if (counter->metric_leader) { v =3D saved_value_lookup(counter->metric_leader, - cpu, true, STAT_NONE, 0, st, rsd.cgrp); + cpu_map_idx, true, STAT_NONE, 0, st, rsd.cgrp); v->metric_total +=3D count; v->metric_other++; } @@ -464,12 +464,12 @@ void perf_stat__collect_metric_expr(struct evlist *ev= sel_list) } =20 static double runtime_stat_avg(struct runtime_stat *st, - enum stat_type type, int cpu, + enum stat_type type, int cpu_map_idx, struct runtime_stat_data *rsd) { struct saved_value *v; =20 - v =3D saved_value_lookup(NULL, cpu, false, type, rsd->ctx, st, rsd->cgrp); + v =3D saved_value_lookup(NULL, cpu_map_idx, false, type, rsd->ctx, st, rs= d->cgrp); if (!v) return 0.0; =20 @@ -477,12 +477,12 @@ static double runtime_stat_avg(struct runtime_stat *s= t, } =20 static double runtime_stat_n(struct runtime_stat *st, - enum stat_type type, int cpu, + enum stat_type type, int cpu_map_idx, struct runtime_stat_data *rsd) { struct saved_value *v; =20 - v =3D saved_value_lookup(NULL, cpu, false, type, rsd->ctx, st, rsd->cgrp); + v =3D saved_value_lookup(NULL, cpu_map_idx, false, type, rsd->ctx, st, rs= d->cgrp); if (!v) return 0.0; =20 @@ -490,7 +490,7 @@ static double runtime_stat_n(struct runtime_stat *st, } =20 static void print_stalled_cycles_frontend(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -498,7 +498,7 @@ static void print_stalled_cycles_frontend(struct perf_s= tat_config *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_CYCLES, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -513,7 +513,7 @@ static void print_stalled_cycles_frontend(struct perf_s= tat_config *config, } =20 static void print_stalled_cycles_backend(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -521,7 +521,7 @@ static void print_stalled_cycles_backend(struct perf_st= at_config *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_CYCLES, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -532,7 +532,7 @@ static void print_stalled_cycles_backend(struct perf_st= at_config *config, } =20 static void print_branch_misses(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -540,7 +540,7 @@ static void print_branch_misses(struct perf_stat_config= *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_BRANCHES, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_BRANCHES, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -551,7 +551,7 @@ static void print_branch_misses(struct perf_stat_config= *config, } =20 static void print_l1_dcache_misses(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -559,7 +559,7 @@ static void print_l1_dcache_misses(struct perf_stat_con= fig *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_L1_DCACHE, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_L1_DCACHE, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -570,7 +570,7 @@ static void print_l1_dcache_misses(struct perf_stat_con= fig *config, } =20 static void print_l1_icache_misses(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -578,7 +578,7 @@ static void print_l1_icache_misses(struct perf_stat_con= fig *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_L1_ICACHE, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_L1_ICACHE, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -588,7 +588,7 @@ static void print_l1_icache_misses(struct perf_stat_con= fig *config, } =20 static void print_dtlb_cache_misses(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -596,7 +596,7 @@ static void print_dtlb_cache_misses(struct perf_stat_co= nfig *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_DTLB_CACHE, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_DTLB_CACHE, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -606,7 +606,7 @@ static void print_dtlb_cache_misses(struct perf_stat_co= nfig *config, } =20 static void print_itlb_cache_misses(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -614,7 +614,7 @@ static void print_itlb_cache_misses(struct perf_stat_co= nfig *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_ITLB_CACHE, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_ITLB_CACHE, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -624,7 +624,7 @@ static void print_itlb_cache_misses(struct perf_stat_co= nfig *config, } =20 static void print_ll_cache_misses(struct perf_stat_config *config, - int cpu, double avg, + int cpu_map_idx, double avg, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -632,7 +632,7 @@ static void print_ll_cache_misses(struct perf_stat_conf= ig *config, double total, ratio =3D 0.0; const char *color; =20 - total =3D runtime_stat_avg(st, STAT_LL_CACHE, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_LL_CACHE, cpu_map_idx, rsd); =20 if (total) ratio =3D avg / total * 100.0; @@ -690,61 +690,61 @@ static double sanitize_val(double x) return x; } =20 -static double td_total_slots(int cpu, struct runtime_stat *st, +static double td_total_slots(int cpu_map_idx, struct runtime_stat *st, struct runtime_stat_data *rsd) { - return runtime_stat_avg(st, STAT_TOPDOWN_TOTAL_SLOTS, cpu, rsd); + return runtime_stat_avg(st, STAT_TOPDOWN_TOTAL_SLOTS, cpu_map_idx, rsd); } =20 -static double td_bad_spec(int cpu, struct runtime_stat *st, +static double td_bad_spec(int cpu_map_idx, struct runtime_stat *st, struct runtime_stat_data *rsd) { double bad_spec =3D 0; double total_slots; double total; =20 - total =3D runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_ISSUED, cpu, rsd) - - runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_RETIRED, cpu, rsd) + - runtime_stat_avg(st, STAT_TOPDOWN_RECOVERY_BUBBLES, cpu, rsd); + total =3D runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_ISSUED, cpu_map_idx, rs= d) - + runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_RETIRED, cpu_map_idx, rsd) + + runtime_stat_avg(st, STAT_TOPDOWN_RECOVERY_BUBBLES, cpu_map_idx, rsd); =20 - total_slots =3D td_total_slots(cpu, st, rsd); + total_slots =3D td_total_slots(cpu_map_idx, st, rsd); if (total_slots) bad_spec =3D total / total_slots; return sanitize_val(bad_spec); } =20 -static double td_retiring(int cpu, struct runtime_stat *st, +static double td_retiring(int cpu_map_idx, struct runtime_stat *st, struct runtime_stat_data *rsd) { double retiring =3D 0; - double total_slots =3D td_total_slots(cpu, st, rsd); + double total_slots =3D td_total_slots(cpu_map_idx, st, rsd); double ret_slots =3D runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_RETIRED, - cpu, rsd); + cpu_map_idx, rsd); =20 if (total_slots) retiring =3D ret_slots / total_slots; return retiring; } =20 -static double td_fe_bound(int cpu, struct runtime_stat *st, +static double td_fe_bound(int cpu_map_idx, struct runtime_stat *st, struct runtime_stat_data *rsd) { double fe_bound =3D 0; - double total_slots =3D td_total_slots(cpu, st, rsd); + double total_slots =3D td_total_slots(cpu_map_idx, st, rsd); double fetch_bub =3D runtime_stat_avg(st, STAT_TOPDOWN_FETCH_BUBBLES, - cpu, rsd); + cpu_map_idx, rsd); =20 if (total_slots) fe_bound =3D fetch_bub / total_slots; return fe_bound; } =20 -static double td_be_bound(int cpu, struct runtime_stat *st, +static double td_be_bound(int cpu_map_idx, struct runtime_stat *st, struct runtime_stat_data *rsd) { - double sum =3D (td_fe_bound(cpu, st, rsd) + - td_bad_spec(cpu, st, rsd) + - td_retiring(cpu, st, rsd)); + double sum =3D (td_fe_bound(cpu_map_idx, st, rsd) + + td_bad_spec(cpu_map_idx, st, rsd) + + td_retiring(cpu_map_idx, st, rsd)); if (sum =3D=3D 0) return 0; return sanitize_val(1.0 - sum); @@ -755,15 +755,15 @@ static double td_be_bound(int cpu, struct runtime_sta= t *st, * the ratios we need to recreate the sum. */ =20 -static double td_metric_ratio(int cpu, enum stat_type type, +static double td_metric_ratio(int cpu_map_idx, enum stat_type type, struct runtime_stat *stat, struct runtime_stat_data *rsd) { - double sum =3D runtime_stat_avg(stat, STAT_TOPDOWN_RETIRING, cpu, rsd) + - runtime_stat_avg(stat, STAT_TOPDOWN_FE_BOUND, cpu, rsd) + - runtime_stat_avg(stat, STAT_TOPDOWN_BE_BOUND, cpu, rsd) + - runtime_stat_avg(stat, STAT_TOPDOWN_BAD_SPEC, cpu, rsd); - double d =3D runtime_stat_avg(stat, type, cpu, rsd); + double sum =3D runtime_stat_avg(stat, STAT_TOPDOWN_RETIRING, cpu_map_idx,= rsd) + + runtime_stat_avg(stat, STAT_TOPDOWN_FE_BOUND, cpu_map_idx, rsd) + + runtime_stat_avg(stat, STAT_TOPDOWN_BE_BOUND, cpu_map_idx, rsd) + + runtime_stat_avg(stat, STAT_TOPDOWN_BAD_SPEC, cpu_map_idx, rsd); + double d =3D runtime_stat_avg(stat, type, cpu_map_idx, rsd); =20 if (sum) return d / sum; @@ -775,23 +775,23 @@ static double td_metric_ratio(int cpu, enum stat_type= type, * We allow two missing. */ =20 -static bool full_td(int cpu, struct runtime_stat *stat, +static bool full_td(int cpu_map_idx, struct runtime_stat *stat, struct runtime_stat_data *rsd) { int c =3D 0; =20 - if (runtime_stat_avg(stat, STAT_TOPDOWN_RETIRING, cpu, rsd) > 0) + if (runtime_stat_avg(stat, STAT_TOPDOWN_RETIRING, cpu_map_idx, rsd) > 0) c++; - if (runtime_stat_avg(stat, STAT_TOPDOWN_BE_BOUND, cpu, rsd) > 0) + if (runtime_stat_avg(stat, STAT_TOPDOWN_BE_BOUND, cpu_map_idx, rsd) > 0) c++; - if (runtime_stat_avg(stat, STAT_TOPDOWN_FE_BOUND, cpu, rsd) > 0) + if (runtime_stat_avg(stat, STAT_TOPDOWN_FE_BOUND, cpu_map_idx, rsd) > 0) c++; - if (runtime_stat_avg(stat, STAT_TOPDOWN_BAD_SPEC, cpu, rsd) > 0) + if (runtime_stat_avg(stat, STAT_TOPDOWN_BAD_SPEC, cpu_map_idx, rsd) > 0) c++; return c >=3D 2; } =20 -static void print_smi_cost(struct perf_stat_config *config, int cpu, +static void print_smi_cost(struct perf_stat_config *config, int cpu_map_id= x, struct perf_stat_output_ctx *out, struct runtime_stat *st, struct runtime_stat_data *rsd) @@ -799,9 +799,9 @@ static void print_smi_cost(struct perf_stat_config *con= fig, int cpu, double smi_num, aperf, cycles, cost =3D 0.0; const char *color =3D NULL; =20 - smi_num =3D runtime_stat_avg(st, STAT_SMI_NUM, cpu, rsd); - aperf =3D runtime_stat_avg(st, STAT_APERF, cpu, rsd); - cycles =3D runtime_stat_avg(st, STAT_CYCLES, cpu, rsd); + smi_num =3D runtime_stat_avg(st, STAT_SMI_NUM, cpu_map_idx, rsd); + aperf =3D runtime_stat_avg(st, STAT_APERF, cpu_map_idx, rsd); + cycles =3D runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, rsd); =20 if ((cycles =3D=3D 0) || (aperf =3D=3D 0)) return; @@ -818,7 +818,7 @@ static void print_smi_cost(struct perf_stat_config *con= fig, int cpu, static int prepare_metric(struct evsel **metric_events, struct metric_ref *metric_refs, struct expr_parse_ctx *pctx, - int cpu, + int cpu_map_idx, struct runtime_stat *st) { double scale; @@ -836,7 +836,7 @@ static int prepare_metric(struct evsel **metric_events, scale =3D 1e-9; source_count =3D 1; } else { - v =3D saved_value_lookup(metric_events[i], cpu, false, + v =3D saved_value_lookup(metric_events[i], cpu_map_idx, false, STAT_NONE, 0, st, metric_events[i]->cgrp); if (!v) @@ -874,7 +874,7 @@ static void generic_metric(struct perf_stat_config *con= fig, const char *metric_name, const char *metric_unit, int runtime, - int cpu, + int cpu_map_idx, struct perf_stat_output_ctx *out, struct runtime_stat *st) { @@ -889,7 +889,7 @@ static void generic_metric(struct perf_stat_config *con= fig, return; =20 pctx->runtime =3D runtime; - i =3D prepare_metric(metric_events, metric_refs, pctx, cpu, st); + i =3D prepare_metric(metric_events, metric_refs, pctx, cpu_map_idx, st); if (i < 0) { expr__ctx_free(pctx); return; @@ -934,7 +934,7 @@ static void generic_metric(struct perf_stat_config *con= fig, expr__ctx_free(pctx); } =20 -double test_generic_metric(struct metric_expr *mexp, int cpu, struct runti= me_stat *st) +double test_generic_metric(struct metric_expr *mexp, int cpu_map_idx, stru= ct runtime_stat *st) { struct expr_parse_ctx *pctx; double ratio =3D 0.0; @@ -943,7 +943,7 @@ double test_generic_metric(struct metric_expr *mexp, in= t cpu, struct runtime_sta if (!pctx) return NAN; =20 - if (prepare_metric(mexp->metric_events, mexp->metric_refs, pctx, cpu, st)= < 0) + if (prepare_metric(mexp->metric_events, mexp->metric_refs, pctx, cpu_map_= idx, st) < 0) goto out; =20 if (expr__parse(&ratio, pctx, mexp->metric_expr)) @@ -956,7 +956,7 @@ double test_generic_metric(struct metric_expr *mexp, in= t cpu, struct runtime_sta =20 void perf_stat__print_shadow_stats(struct perf_stat_config *config, struct evsel *evsel, - double avg, int cpu, + double avg, int cpu_map_idx, struct perf_stat_output_ctx *out, struct rblist *metric_events, struct runtime_stat *st) @@ -975,7 +975,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_con= fig *config, if (config->iostat_run) { iostat_print_metric(config, evsel, out); } else if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) { - total =3D runtime_stat_avg(st, STAT_CYCLES, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, &rsd); =20 if (total) { ratio =3D avg / total; @@ -985,11 +985,11 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, print_metric(config, ctxp, NULL, NULL, "insn per cycle", 0); } =20 - total =3D runtime_stat_avg(st, STAT_STALLED_CYCLES_FRONT, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_STALLED_CYCLES_FRONT, cpu_map_idx, &= rsd); =20 total =3D max(total, runtime_stat_avg(st, STAT_STALLED_CYCLES_BACK, - cpu, &rsd)); + cpu_map_idx, &rsd)); =20 if (total && avg) { out->new_line(config, ctxp); @@ -999,8 +999,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_con= fig *config, ratio); } } else if (evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES)) { - if (runtime_stat_n(st, STAT_BRANCHES, cpu, &rsd) !=3D 0) - print_branch_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_BRANCHES, cpu_map_idx, &rsd) !=3D 0) + print_branch_misses(config, cpu_map_idx, avg, out, st, &rsd); else print_metric(config, ctxp, NULL, NULL, "of all branches", 0); } else if ( @@ -1009,8 +1009,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { =20 - if (runtime_stat_n(st, STAT_L1_DCACHE, cpu, &rsd) !=3D 0) - print_l1_dcache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_L1_DCACHE, cpu_map_idx, &rsd) !=3D 0) + print_l1_dcache_misses(config, cpu_map_idx, avg, out, st, &rsd); else print_metric(config, ctxp, NULL, NULL, "of all L1-dcache accesses", 0); } else if ( @@ -1019,8 +1019,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { =20 - if (runtime_stat_n(st, STAT_L1_ICACHE, cpu, &rsd) !=3D 0) - print_l1_icache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_L1_ICACHE, cpu_map_idx, &rsd) !=3D 0) + print_l1_icache_misses(config, cpu_map_idx, avg, out, st, &rsd); else print_metric(config, ctxp, NULL, NULL, "of all L1-icache accesses", 0); } else if ( @@ -1029,8 +1029,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { =20 - if (runtime_stat_n(st, STAT_DTLB_CACHE, cpu, &rsd) !=3D 0) - print_dtlb_cache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_DTLB_CACHE, cpu_map_idx, &rsd) !=3D 0) + print_dtlb_cache_misses(config, cpu_map_idx, avg, out, st, &rsd); else print_metric(config, ctxp, NULL, NULL, "of all dTLB cache accesses", 0); } else if ( @@ -1039,8 +1039,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { =20 - if (runtime_stat_n(st, STAT_ITLB_CACHE, cpu, &rsd) !=3D 0) - print_itlb_cache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_ITLB_CACHE, cpu_map_idx, &rsd) !=3D 0) + print_itlb_cache_misses(config, cpu_map_idx, avg, out, st, &rsd); else print_metric(config, ctxp, NULL, NULL, "of all iTLB cache accesses", 0); } else if ( @@ -1049,27 +1049,27 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { =20 - if (runtime_stat_n(st, STAT_LL_CACHE, cpu, &rsd) !=3D 0) - print_ll_cache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_LL_CACHE, cpu_map_idx, &rsd) !=3D 0) + print_ll_cache_misses(config, cpu_map_idx, avg, out, st, &rsd); else print_metric(config, ctxp, NULL, NULL, "of all LL-cache accesses", 0); } else if (evsel__match(evsel, HARDWARE, HW_CACHE_MISSES)) { - total =3D runtime_stat_avg(st, STAT_CACHEREFS, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_CACHEREFS, cpu_map_idx, &rsd); =20 if (total) ratio =3D avg * 100 / total; =20 - if (runtime_stat_n(st, STAT_CACHEREFS, cpu, &rsd) !=3D 0) + if (runtime_stat_n(st, STAT_CACHEREFS, cpu_map_idx, &rsd) !=3D 0) print_metric(config, ctxp, NULL, "%8.3f %%", "of all cache refs", ratio); else print_metric(config, ctxp, NULL, NULL, "of all cache refs", 0); } else if (evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_FRONTEND)) { - print_stalled_cycles_frontend(config, cpu, avg, out, st, &rsd); + print_stalled_cycles_frontend(config, cpu_map_idx, avg, out, st, &rsd); } else if (evsel__match(evsel, HARDWARE, HW_STALLED_CYCLES_BACKEND)) { - print_stalled_cycles_backend(config, cpu, avg, out, st, &rsd); + print_stalled_cycles_backend(config, cpu_map_idx, avg, out, st, &rsd); } else if (evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) { - total =3D runtime_stat_avg(st, STAT_NSECS, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_NSECS, cpu_map_idx, &rsd); =20 if (total) { ratio =3D avg / total; @@ -1078,7 +1078,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, print_metric(config, ctxp, NULL, NULL, "Ghz", 0); } } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX)) { - total =3D runtime_stat_avg(st, STAT_CYCLES, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, &rsd); =20 if (total) print_metric(config, ctxp, NULL, @@ -1088,8 +1088,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, print_metric(config, ctxp, NULL, NULL, "transactional cycles", 0); } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX_CP)) { - total =3D runtime_stat_avg(st, STAT_CYCLES, cpu, &rsd); - total2 =3D runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, &rsd); + total2 =3D runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd); =20 if (total2 < avg) total2 =3D avg; @@ -1099,19 +1099,19 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, else print_metric(config, ctxp, NULL, NULL, "aborted cycles", 0); } else if (perf_stat_evsel__is(evsel, TRANSACTION_START)) { - total =3D runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd); =20 if (avg) ratio =3D total / avg; =20 - if (runtime_stat_n(st, STAT_CYCLES_IN_TX, cpu, &rsd) !=3D 0) + if (runtime_stat_n(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd) !=3D 0) print_metric(config, ctxp, NULL, "%8.0f", "cycles / transaction", ratio); else print_metric(config, ctxp, NULL, NULL, "cycles / transaction", 0); } else if (perf_stat_evsel__is(evsel, ELISION_START)) { - total =3D runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd); =20 if (avg) ratio =3D total / avg; @@ -1124,28 +1124,28 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, else print_metric(config, ctxp, NULL, NULL, "CPUs utilized", 0); } else if (perf_stat_evsel__is(evsel, TOPDOWN_FETCH_BUBBLES)) { - double fe_bound =3D td_fe_bound(cpu, st, &rsd); + double fe_bound =3D td_fe_bound(cpu_map_idx, st, &rsd); =20 if (fe_bound > 0.2) color =3D PERF_COLOR_RED; print_metric(config, ctxp, color, "%8.1f%%", "frontend bound", fe_bound * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_SLOTS_RETIRED)) { - double retiring =3D td_retiring(cpu, st, &rsd); + double retiring =3D td_retiring(cpu_map_idx, st, &rsd); =20 if (retiring > 0.7) color =3D PERF_COLOR_GREEN; print_metric(config, ctxp, color, "%8.1f%%", "retiring", retiring * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_RECOVERY_BUBBLES)) { - double bad_spec =3D td_bad_spec(cpu, st, &rsd); + double bad_spec =3D td_bad_spec(cpu_map_idx, st, &rsd); =20 if (bad_spec > 0.1) color =3D PERF_COLOR_RED; print_metric(config, ctxp, color, "%8.1f%%", "bad speculation", bad_spec * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_SLOTS_ISSUED)) { - double be_bound =3D td_be_bound(cpu, st, &rsd); + double be_bound =3D td_be_bound(cpu_map_idx, st, &rsd); const char *name =3D "backend bound"; static int have_recovery_bubbles =3D -1; =20 @@ -1158,14 +1158,14 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, =20 if (be_bound > 0.2) color =3D PERF_COLOR_RED; - if (td_total_slots(cpu, st, &rsd) > 0) + if (td_total_slots(cpu_map_idx, st, &rsd) > 0) print_metric(config, ctxp, color, "%8.1f%%", name, be_bound * 100.); else print_metric(config, ctxp, NULL, NULL, name, 0); } else if (perf_stat_evsel__is(evsel, TOPDOWN_RETIRING) && - full_td(cpu, st, &rsd)) { - double retiring =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double retiring =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_RETIRING, st, &rsd); if (retiring > 0.7) @@ -1173,8 +1173,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, print_metric(config, ctxp, color, "%8.1f%%", "retiring", retiring * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_FE_BOUND) && - full_td(cpu, st, &rsd)) { - double fe_bound =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double fe_bound =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_FE_BOUND, st, &rsd); if (fe_bound > 0.2) @@ -1182,8 +1182,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, print_metric(config, ctxp, color, "%8.1f%%", "frontend bound", fe_bound * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_BE_BOUND) && - full_td(cpu, st, &rsd)) { - double be_bound =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double be_bound =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BE_BOUND, st, &rsd); if (be_bound > 0.2) @@ -1191,8 +1191,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, print_metric(config, ctxp, color, "%8.1f%%", "backend bound", be_bound * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_BAD_SPEC) && - full_td(cpu, st, &rsd)) { - double bad_spec =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double bad_spec =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BAD_SPEC, st, &rsd); if (bad_spec > 0.1) @@ -1200,11 +1200,11 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, print_metric(config, ctxp, color, "%8.1f%%", "bad speculation", bad_spec * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_HEAVY_OPS) && - full_td(cpu, st, &rsd) && (config->topdown_level > 1)) { - double retiring =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double retiring =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_RETIRING, st, &rsd); - double heavy_ops =3D td_metric_ratio(cpu, + double heavy_ops =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_HEAVY_OPS, st, &rsd); double light_ops =3D retiring - heavy_ops; @@ -1220,11 +1220,11 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, print_metric(config, ctxp, color, "%8.1f%%", "light operations", light_ops * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_BR_MISPREDICT) && - full_td(cpu, st, &rsd) && (config->topdown_level > 1)) { - double bad_spec =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double bad_spec =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BAD_SPEC, st, &rsd); - double br_mis =3D td_metric_ratio(cpu, + double br_mis =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BR_MISPREDICT, st, &rsd); double m_clears =3D bad_spec - br_mis; @@ -1240,11 +1240,11 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, print_metric(config, ctxp, color, "%8.1f%%", "machine clears", m_clears * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_FETCH_LAT) && - full_td(cpu, st, &rsd) && (config->topdown_level > 1)) { - double fe_bound =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double fe_bound =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_FE_BOUND, st, &rsd); - double fetch_lat =3D td_metric_ratio(cpu, + double fetch_lat =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_FETCH_LAT, st, &rsd); double fetch_bw =3D fe_bound - fetch_lat; @@ -1260,11 +1260,11 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, print_metric(config, ctxp, color, "%8.1f%%", "fetch bandwidth", fetch_bw * 100.); } else if (perf_stat_evsel__is(evsel, TOPDOWN_MEM_BOUND) && - full_td(cpu, st, &rsd) && (config->topdown_level > 1)) { - double be_bound =3D td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double be_bound =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BE_BOUND, st, &rsd); - double mem_bound =3D td_metric_ratio(cpu, + double mem_bound =3D td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_MEM_BOUND, st, &rsd); double core_bound =3D be_bound - mem_bound; @@ -1281,12 +1281,12 @@ void perf_stat__print_shadow_stats(struct perf_stat= _config *config, core_bound * 100.); } else if (evsel->metric_expr) { generic_metric(config, evsel->metric_expr, evsel->metric_events, NULL, - evsel->name, evsel->metric_name, NULL, 1, cpu, out, st); - } else if (runtime_stat_n(st, STAT_NSECS, cpu, &rsd) !=3D 0) { + evsel->name, evsel->metric_name, NULL, 1, cpu_map_idx, out, st); + } else if (runtime_stat_n(st, STAT_NSECS, cpu_map_idx, &rsd) !=3D 0) { char unit =3D ' '; char unit_buf[10] =3D "/sec"; =20 - total =3D runtime_stat_avg(st, STAT_NSECS, cpu, &rsd); + total =3D runtime_stat_avg(st, STAT_NSECS, cpu_map_idx, &rsd); if (total) ratio =3D convert_unit_double(1000000000.0 * avg / total, &unit); =20 @@ -1294,7 +1294,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, snprintf(unit_buf, sizeof(unit_buf), "%c/sec", unit); print_metric(config, ctxp, NULL, "%8.3f", unit_buf, ratio); } else if (perf_stat_evsel__is(evsel, SMI_NUM)) { - print_smi_cost(config, cpu, out, st, &rsd); + print_smi_cost(config, cpu_map_idx, out, st, &rsd); } else { num =3D 0; } @@ -1307,7 +1307,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_c= onfig *config, out->new_line(config, ctxp); generic_metric(config, mexp->metric_expr, mexp->metric_events, mexp->metric_refs, evsel->name, mexp->metric_name, - mexp->metric_unit, mexp->runtime, cpu, out, st); + mexp->metric_unit, mexp->runtime, cpu_map_idx, out, st); } } if (num =3D=3D 0) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 86ab427e87fc..7dbd7c4f3c33 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -356,14 +356,14 @@ static int check_per_pkg(struct evsel *counter, struc= t perf_counts_values *vals, =20 static int process_counter_values(struct perf_stat_config *config, struct evsel *evse= l, - int cpu, int thread, + int cpu_map_idx, int thread, struct perf_counts_values *count) { struct perf_counts_values *aggr =3D &evsel->counts->aggr; static struct perf_counts_values zero; bool skip =3D false; =20 - if (check_per_pkg(evsel, count, cpu, &skip)) { + if (check_per_pkg(evsel, count, cpu_map_idx, &skip)) { pr_err("failed to read per-pkg counter\n"); return -1; } @@ -379,11 +379,11 @@ process_counter_values(struct perf_stat_config *confi= g, struct evsel *evsel, case AGGR_NODE: case AGGR_NONE: if (!evsel->snapshot) - evsel__compute_deltas(evsel, cpu, thread, count); + evsel__compute_deltas(evsel, cpu_map_idx, thread, count); perf_counts_values__scale(count, config->scale, NULL); if ((config->aggr_mode =3D=3D AGGR_NONE) && (!evsel->percore)) { perf_stat__update_shadow_stats(evsel, count->val, - cpu, &rt_stat); + cpu_map_idx, &rt_stat); } =20 if (config->aggr_mode =3D=3D AGGR_THREAD) { @@ -412,15 +412,15 @@ static int process_counter_maps(struct perf_stat_conf= ig *config, { int nthreads =3D perf_thread_map__nr(counter->core.threads); int ncpus =3D evsel__nr_cpus(counter); - int cpu, thread; + int idx, thread; =20 if (counter->core.system_wide) nthreads =3D 1; =20 for (thread =3D 0; thread < nthreads; thread++) { - for (cpu =3D 0; cpu < ncpus; cpu++) { - if (process_counter_values(config, counter, cpu, thread, - perf_counts(counter->counts, cpu, thread))) + for (idx =3D 0; idx < ncpus; idx++) { + if (process_counter_values(config, counter, idx, thread, + perf_counts(counter->counts, idx, thread))) return -1; } } diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 5e25d53e891b..691c12fd8976 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -208,7 +208,7 @@ void perf_stat__init_shadow_stats(void); void perf_stat__reset_shadow_stats(void); void perf_stat__reset_shadow_per_stat(struct runtime_stat *st); void perf_stat__update_shadow_stats(struct evsel *counter, u64 count, - int cpu, struct runtime_stat *st); + int cpu_map_idx, struct runtime_stat *st); struct perf_stat_output_ctx { void *ctx; print_metric_t print_metric; @@ -253,5 +253,5 @@ void evlist__print_counters(struct evlist *evlist, stru= ct perf_stat_config *conf struct target *_target, struct timespec *ts, int argc, const char *= *argv); =20 struct metric_expr; -double test_generic_metric(struct metric_expr *mexp, int cpu, struct runti= me_stat *st); +double test_generic_metric(struct metric_expr *mexp, int cpu_map_idx, stru= ct runtime_stat *st); #endif --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 973C1C433FE for ; Thu, 23 Dec 2021 07:49:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346980AbhLWHtR (ORCPT ); Thu, 23 Dec 2021 02:49:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347208AbhLWHsP (ORCPT ); Thu, 23 Dec 2021 02:48:15 -0500 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 74435C06179E for ; Wed, 22 Dec 2021 23:47:58 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id w9-20020a25c709000000b00608a9489fc1so8588643ybe.20 for ; Wed, 22 Dec 2021 23:47:58 -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=57/+4CL2ERGKB8wcFmTlsb9+ddyZs/YCDFj+XQK+r0Y=; b=Kmw2HMz8OnTT8+e6Av5zTsnabJHV8YuPlY4nBiiHSrQaqFlf8OO8BaE6JhznIb+SkY VbqZrgtC4iehGZ7B79QmLrZdOtspJq5LF9uzHuUOCAFNmOfeWXOL1obfpVpL699oH31r RMl4gBPGQa5La8+7Mb7usxHC/DEYrY3rgqrQ/8f1Js0gwjznxcIY/fwlRyNgnH2fPbKQ TXgOSJrulJ12P/58l9iRWaPGNYN7knQGXt4VJS/5PeyX3P28yZJyE6IdNO6uOr1Aka5L fXWzycF1yUW/PHYWg4mkth7nRHn4Qx4qFCwINtwn1FAmf6VVPFS+bEt+pEQTGGEvrMrm 04eA== 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=57/+4CL2ERGKB8wcFmTlsb9+ddyZs/YCDFj+XQK+r0Y=; b=GwjoYseuW7Qe4sWbaiKV/3cQXxIEkjE7NCG20ZxHi87ACoYctB2u9VWKLmznXsx5gH gln5ww2bbh6jfnVfqptzg6XjJEyawCsWTdoe0bLmwLEJhHL70XyeY3AmkUxtC7hN1OEu CSO15NLyxiALa/Y9wZfT1lJL+WgGP+0furjWxt9kCnFmQS4VWalAP4OkNPR+PLFL0E90 yVncuN5Vz8KS5oz/HIsPBtqpTfG7dPqIYxX9WkEMWB8tCJDjotme61YAI3JcuCJQCTx9 UyEWe7nzWdoKVDx3W4DBXePpikRw9iZaC3w6c/uYWRdIIe3R/Umz6G5J+RfrLhu2wb3n M+bQ== X-Gm-Message-State: AOAM5333Dy4XXAbhB8JqeDzOemhue3TLFMPtosYJ1jWcpE6KigxEDacc tw0dTJ6BZTJ77Uky0g/4/6giTi2Xxv71 X-Google-Smtp-Source: ABdhPJz7s6JPrDDNZF3on+3gorJfYhIFzNZiyO0pXViekCWuxfoR7TVmFQdx4NTB8GlHaIJ5D01ruOND6QQL X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:516:: with SMTP id 22mr1724778ybf.294.1640245677712; Wed, 22 Dec 2021 23:47:57 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:36 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-44-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 43/48] libperf: Sync evsel documentation 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" cpu was renamed cpu_map_idx, for clarity. Signed-off-by: Ian Rogers --- tools/lib/perf/Documentation/libperf.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Docu= mentation/libperf.txt index 63ae5e0195ce..88a9335421ab 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -135,16 +135,16 @@ SYNOPSIS int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads); void perf_evsel__close(struct perf_evsel *evsel); - void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu); + void perf_evsel__close_cpu(struct perf_evsel *evsel, int cpu_map_idx); int perf_evsel__mmap(struct perf_evsel *evsel, int pages); void perf_evsel__munmap(struct perf_evsel *evsel); - void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu, int threa= d); - int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, + void *perf_evsel__mmap_base(struct perf_evsel *evsel, int cpu_map_idx, i= nt thread); + int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thre= ad, struct perf_counts_values *count); int perf_evsel__enable(struct perf_evsel *evsel); - int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu); + int perf_evsel__enable_cpu(struct perf_evsel *evsel, int cpu_map_idx); int perf_evsel__disable(struct perf_evsel *evsel); - int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu); + int perf_evsel__disable_cpu(struct perf_evsel *evsel, int cpu_map_idx); struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel); struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel); struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel); --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C6C1C4332F for ; Thu, 23 Dec 2021 07:49:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347433AbhLWHtT (ORCPT ); Thu, 23 Dec 2021 02:49:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347201AbhLWHsQ (ORCPT ); Thu, 23 Dec 2021 02:48:16 -0500 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 057F8C0698C3 for ; Wed, 22 Dec 2021 23:48:01 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id d27-20020a25addb000000b005c2355d9052so8659582ybe.3 for ; Wed, 22 Dec 2021 23:48:00 -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=ZhtwMx5XmOUxargn0OJvoWgG4zJ20RlnI8nSzXmFBiA=; b=cF/W+j1wUQlcKvSQ/5mNaIKiUE9tza12393fzA6WaZLhsDYM1r7PIYKxYMlEcDRnSs 03+Wgtma4aC7HAWdsPHD9UZA1990+E9LTOO2L6HKoi8iPBYr72A3zQTZSnogBntc5r/1 HI77yATkA+EOu4Zru5R2FbaeTqKbDCf+GNrPuIh5H74KbOVOlS/MYCbQurlMekaL89qM YE3ftGgjvTdWKy/GbuXk5VyaTMq6QUq3SiBkSSFQWS7povraNIfsioyV8NxLMZ/ujR/1 l9ktc/vehndZvQPzDmnWRjKo43H0k4NQ0qAYbRxr6i1Sm7S/VvOx7RkMT/Z3HXCVkXwi DiYA== 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=ZhtwMx5XmOUxargn0OJvoWgG4zJ20RlnI8nSzXmFBiA=; b=ZDRO+IB7mWdFHIPsUKqrCR+81kA6QRyeRWrR/QFnWF/FoD9KyKLiSMkL3LGtUfke+a VlEEJndQw5I9XsGYJ1yfgnPzvPYNzakbC/bwX7pQS8C8NDxhSoo6f84AapNld5Cf7BlC +hcTGh3BIhmVuf4XJ9G2Bw/rlyVGVSir9kfSXWFCy8PgoGKYcfMqrxjoSf0JvK0I0luV Qps4mtmiUi15cnzUa595xhl//vypIgxcFWxD5/TK1Hem7lgxPWIju5u7rZpACQuqPkqM VF6HblFulrG1Z+RY4KxpXNUfZU/DESWHLzPDbYD1kuChXLIq4+gPHIm/cJ9vdM5bQakK RCog== X-Gm-Message-State: AOAM531QnfwLELcyESAIUjO7/jhxXV6k+xJZkaluMw5HUbogojaS4uYg dYfBqvMum0I4pVXqCnu11j9XS5OoPFII X-Google-Smtp-Source: ABdhPJzUOFTBp8xme2THzFqg1XjnHXFKMcITvfTbSeai3tZhHOQotzeL83lYSQ4TOw+DRzlH02104Y+uqKDN X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:37cb:: with SMTP id e194mr1730367yba.449.1640245680254; Wed, 22 Dec 2021 23:48:00 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:37 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-45-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 44/48] perf bpf: Rename cpu to cpu_map_idx 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Synchronize the caller in evsel with the called function. Shorten 3 lines of code in bperf_read by using perf_cpu_map__for_each_cpu. This code is frequently using variables named cpu as cpu map indices, which doesn't matter as all CPUs are in the CPU map. It is strange in some cases the cpumap is used at all. Signed-off-by: Ian Rogers --- tools/perf/util/bpf_counter.c | 16 +++++++--------- tools/perf/util/bpf_counter.h | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/tools/perf/util/bpf_counter.c b/tools/perf/util/bpf_counter.c index c17d4a43ce06..ae5bd87ff020 100644 --- a/tools/perf/util/bpf_counter.c +++ b/tools/perf/util/bpf_counter.c @@ -265,7 +265,7 @@ static int bpf_program_profiler__read(struct evsel *evs= el) return 0; } =20 -static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu, +static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu_m= ap_idx, int fd) { struct bpf_prog_profiler_bpf *skel; @@ -277,7 +277,7 @@ static int bpf_program_profiler__install_pe(struct evse= l *evsel, int cpu, assert(skel !=3D NULL); =20 ret =3D bpf_map_update_elem(bpf_map__fd(skel->maps.events), - &cpu, &fd, BPF_ANY); + &cpu_map_idx, &fd, BPF_ANY); if (ret) return ret; } @@ -566,12 +566,12 @@ static int bperf__load(struct evsel *evsel, struct ta= rget *target) return err; } =20 -static int bperf__install_pe(struct evsel *evsel, int cpu, int fd) +static int bperf__install_pe(struct evsel *evsel, int cpu_map_idx, int fd) { struct bperf_leader_bpf *skel =3D evsel->leader_skel; =20 return bpf_map_update_elem(bpf_map__fd(skel->maps.events), - &cpu, &fd, BPF_ANY); + &cpu_map_idx, &fd, BPF_ANY); } =20 /* @@ -623,9 +623,7 @@ static int bperf__read(struct evsel *evsel) case BPERF_FILTER_GLOBAL: assert(i =3D=3D 0); =20 - num_cpu =3D all_cpu_map->nr; - for (j =3D 0; j < num_cpu; j++) { - cpu =3D all_cpu_map->map[j]; + perf_cpu_map__for_each_cpu(cpu, j, all_cpu_map) { perf_counts(evsel->counts, cpu, 0)->val =3D values[cpu].counter; perf_counts(evsel->counts, cpu, 0)->ena =3D values[cpu].enabled; perf_counts(evsel->counts, cpu, 0)->run =3D values[cpu].running; @@ -757,11 +755,11 @@ static inline bool bpf_counter_skip(struct evsel *evs= el) evsel->follower_skel =3D=3D NULL; } =20 -int bpf_counter__install_pe(struct evsel *evsel, int cpu, int fd) +int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd) { if (bpf_counter_skip(evsel)) return 0; - return evsel->bpf_counter_ops->install_pe(evsel, cpu, fd); + return evsel->bpf_counter_ops->install_pe(evsel, cpu_map_idx, fd); } =20 int bpf_counter__load(struct evsel *evsel, struct target *target) diff --git a/tools/perf/util/bpf_counter.h b/tools/perf/util/bpf_counter.h index 65ebaa6694fb..4dbf26408b69 100644 --- a/tools/perf/util/bpf_counter.h +++ b/tools/perf/util/bpf_counter.h @@ -16,7 +16,7 @@ typedef int (*bpf_counter_evsel_op)(struct evsel *evsel); typedef int (*bpf_counter_evsel_target_op)(struct evsel *evsel, struct target *target); typedef int (*bpf_counter_evsel_install_pe_op)(struct evsel *evsel, - int cpu, + int cpu_map_idx, int fd); =20 struct bpf_counter_ops { @@ -40,7 +40,7 @@ int bpf_counter__enable(struct evsel *evsel); int bpf_counter__disable(struct evsel *evsel); int bpf_counter__read(struct evsel *evsel); void bpf_counter__destroy(struct evsel *evsel); -int bpf_counter__install_pe(struct evsel *evsel, int cpu, int fd); +int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd); =20 #else /* HAVE_BPF_SKEL */ =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32928C433EF for ; Thu, 23 Dec 2021 07:49:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347563AbhLWHtW (ORCPT ); Thu, 23 Dec 2021 02:49:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347361AbhLWHsQ (ORCPT ); Thu, 23 Dec 2021 02:48:16 -0500 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 5CEE7C0698CB for ; Wed, 22 Dec 2021 23:48:03 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id j18-20020a258152000000b006000d292a42so8800455ybm.0 for ; Wed, 22 Dec 2021 23:48:03 -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=0+jllfj9qKTtJn62Mv0xaycKEmjVjVqlWS+UU/ykrAI=; b=VS1sJ5HaFNgLWNjQYGVO1AtJP7sYCg/muV4bWo4w9PU1mXOnMoE2wy2OOHSPptpn2e 8LBFCDKZ4EjtqSPtym/k8DfExCgIcaZ64yNjXn0dfjp1nOoiQzswq3FYIS8MOteOJGtE yCaOybVqwP/dg7QKAKb3xVJjcmqSEbX+9Z8BQo1GizOG3xz0MQcHMis3c6tTiCb2f7Mo 4Kl5OgK9mi4fV0xNjFYNcncF/iQVH2cpuZkxSN7Y1P9B9h8HjRvr9mZJh4G2bhe+boat m5W3RIosFUHAC9q0KNgBYT3dMEzl6qtVOwXxTHw1OiUyFsBO1JEfQJtUP/oSiOmpojl7 TIfQ== 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=0+jllfj9qKTtJn62Mv0xaycKEmjVjVqlWS+UU/ykrAI=; b=dxX9Gqbm18TghQl1RGB8AGvWPQps667pwOCetv3DvkMCmix7L8aQsPzQ6q8upH8cXG 0eXAwSue7mzbPg7eNKAMl094sVPeTW3//0qobgah4jVkoFIlGWWT0If6E6W1duSUoz8L 5UPur+5GlTza5lGBbyCelFRZYU30SAM1b7PHCTmqysQyN99mzriKhZSNOkyK/7tIj29x hPM4oces0UZ1TDls7m0QE7g01P3lMvmU75ghJfgIZ1WXHIjjNEDaX3ryf023VbNM++DN zA8d4a1SdrX3GxD2iyL+3SPINlM/gsx5n4XEUsNsHhwvyMFLdqNo0RL3HVAvgTGmqZ3B 1vpA== X-Gm-Message-State: AOAM533RC4Yf1GzY3s5q1awYl5Cu5f3o86Hp8Ojg+X2QfPc60RcZv1Jw v7Rj9DEOg7I46xygI8KOEQA4YT5q7RVz X-Google-Smtp-Source: ABdhPJw1XvXrCrCmgw8Tk2gnaSSb4wGPW7JXEGtNiZ5hS4rNdk0qW6Y2vLin1IHozUlivVvyHQGwrvdHCPkX X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:2c4d:: with SMTP id s74mr1589032ybs.171.1640245682584; Wed, 22 Dec 2021 23:48:02 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:38 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-46-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 45/48] perf c2c: Use more intention revealing iterator 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use perf_cpu_map__for_each_cpu in setup_nodes. Signed-off-by: Ian Rogers --- tools/perf/builtin-c2c.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index b5c67ef73862..ad1fbeafc93d 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -2015,7 +2015,7 @@ static int setup_nodes(struct perf_session *session) { struct numa_node *n; unsigned long **nodes; - int node, cpu; + int node, cpu, idx; int *cpu2node; =20 if (c2c.node_info > 2) @@ -2057,13 +2057,13 @@ static int setup_nodes(struct perf_session *session) if (perf_cpu_map__empty(map)) continue; =20 - for (cpu =3D 0; cpu < map->nr; cpu++) { - set_bit(map->map[cpu], set); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + set_bit(cpu, set); =20 - if (WARN_ONCE(cpu2node[map->map[cpu]] !=3D -1, "node/cpu topology bug")) + if (WARN_ONCE(cpu2node[cpu] !=3D -1, "node/cpu topology bug")) return -EINVAL; =20 - cpu2node[map->map[cpu]] =3D node; + cpu2node[cpu] =3D node; } } =20 --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84954C433F5 for ; Thu, 23 Dec 2021 07:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347272AbhLWHt3 (ORCPT ); Thu, 23 Dec 2021 02:49:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40968 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347223AbhLWHsR (ORCPT ); Thu, 23 Dec 2021 02:48:17 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7070C0698D1 for ; Wed, 22 Dec 2021 23:48:05 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id d205-20020a251dd6000000b0060977416ad4so8519191ybd.16 for ; Wed, 22 Dec 2021 23:48:05 -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=8dsbS5qNAaZwjjgso/tH43ZBCOZXMegiAB2IxZGAtxY=; b=PQhAtMAARGULqWwBTpXr3yXhs2ODyw/ITTTon4PBCLboBEqbgmDaHbmw4c6nePmtTs uAGCVnve4qdC3HB0ycP8Ffwg3laRq/3wRwQLITuj/NM6ljjzWyV2PuZsqKjsoKC7P0vV CxBdrtKujfQ5fKSG12PNfMvK51kmg7PJKeTxB2Hem9rrLzH2ujPUhnK3mh6yxmxEsRBt nJSUpYWHia6Jmf9ZYIq1Q4OHllCwz39+BFSwFa6deXzEI6bD2zJdbCJbhwaJNV7xH/7D 1AQmqj0XFlL3Nzie5Ah66Swk9U5RR578skOC784re3hCuU1+PSmz32lI/J8gkXrBWiRr HBSg== 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=8dsbS5qNAaZwjjgso/tH43ZBCOZXMegiAB2IxZGAtxY=; b=5oVY5rcxvur8nWjNjQ5vxZqxAxS1C/MtcC2L934yxZ/754ucicucGdFuqZSdFQQb5a DHdnhPDkBs60OaPw94X9M/AsQZ+Ukexn6Sf/QnHsxlf1awRM+DOdh50Jt1n8wz5q8xu5 zUrcz8DKPiTlTBixCccq/rmzz0kSzSRyazu/QrJThVYigCCAvM60gAqb0TLvfXFjJpat 88nOIAKwDHAeUanC6mnpRhN6GGMC4FSfaoEQH1WlxUHHwpnDjvJlbRSwjSQwmIaZeiwj DrRMghdC3i7bpXirlM1hYx0Ge6Pwdzygbt371Y51lZIbfF8nOpntatKxY2OeRf0bNXV5 fuUA== X-Gm-Message-State: AOAM533wCqD8VOFz8grTZfWaDukCzWZ6t7dbt3b8cOZAN4yBC2NY7qZo gQ80mEE5bGM0JizXxeouHRHuauR6o5EY X-Google-Smtp-Source: ABdhPJzWqsoRQMCzJi9y2FpN5S2sgEEMwklh3mJKbN+pS1OAmbSTCoL/av3GIvKVh+8AzLIV6l2ui3xlohJr X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:d743:: with SMTP id o64mr1575188ybg.81.1640245685068; Wed, 22 Dec 2021 23:48:05 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:39 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-47-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 46/48] perf script: Fix flipped index and cpu 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_counts are accessed by the densely packed index. Signed-off-by: Ian Rogers --- tools/perf/builtin-script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index af06fe1271cc..de4af7af34c8 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2129,7 +2129,7 @@ static void __process_stat(struct evsel *counter, u64= tstamp) perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { struct perf_counts_values *counts; =20 - counts =3D perf_counts(counter->counts, cpu, thread); + counts =3D perf_counts(counter->counts, idx, thread); =20 printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 "= %s\n", cpu, --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6522CC433FE for ; Thu, 23 Dec 2021 07:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347290AbhLWHtf (ORCPT ); Thu, 23 Dec 2021 02:49:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40662 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347380AbhLWHsS (ORCPT ); Thu, 23 Dec 2021 02:48:18 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C25BC0698D7 for ; Wed, 22 Dec 2021 23:48:08 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id l28-20020a25b31c000000b005c27dd4987bso8676133ybj.18 for ; Wed, 22 Dec 2021 23:48:08 -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=cDaibtPTEVy/marM7k5BRfohlw9xTdSxUKumkjr4yhw=; b=LR0s9gyR8FdFtVpedgrPoQl0RipPyJFh0k9uDNnNWGWyGp41FS4MhvQkerVXScw40O 5Q3UgSXloAekM3enRkXD4/fIt1iveTUNFR0xdq3R6OFB9RC0H4mm7C5I+csb4PN4VXAD OM1S1z3/mX//nMtqRh1DDVuWQQLz4PaV3PkuyzaPSutZdqFk+nkgpusXJ1Vpw0h/w/Ph l/BwiN3gdX47cU0o3t3KRNEAahlbYreHh1/4QpHUMgyeVSF0BmDVPK37E76zHjbXRqAn 6vXc2tDWW8hi2lqSUOqLp8z8MMmAgzWAS9djaYyCpkhDylETPN22SZ2S/Iu4bT57KrOx ZDSg== 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=cDaibtPTEVy/marM7k5BRfohlw9xTdSxUKumkjr4yhw=; b=pTPOiALAdM1AFguzj/91oihtX21muGvC0fIR5AXJpVKynsMyW+ee4Xz/CHLkfm49UV WpqZydI9aSQZ/QZO1TTGOJV6x9XKc5mrkDXMep6gvHLK5qe4q5+XvEUG/pbvhSzeuVdz qODomDFRUpO6c8Fu7iVaaIwTeUE46OhGueFiZWTDu+dN5/jgaTjSeXLyi0QFlHgZJiUb q5zz1LYT0LfHAQn4PPwC4EoCFv1DdickyMh8WvkY8+IBFkI2ugoJHVsD6jXYrKtC2ssX zyMytiY0d7TLMgKurVT4xtGe28XDO1azJfTik9IlPP5Tjanj9nr7Z2loH7KI1KjsGHso ygSg== X-Gm-Message-State: AOAM532fpnpWY2pNs3zSKnirGeKm+f1ceSYzbOXPblVQS1guqFjvYbQA NyIPRwEYnp8cfK8pQJCjowvWq1aNdICT X-Google-Smtp-Source: ABdhPJzDnNWgSN3KpORsveY6l3QnqXRD+G9oM9zhBV0+i5/UTFDThki+ZfSFVKKlRC0auWHdTdRytkGYHEup X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:3814:: with SMTP id f20mr1711353yba.117.1640245687520; Wed, 22 Dec 2021 23:48:07 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:40 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-48-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 47/48] perf stat: Correct first_shadow_cpu to return index 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" perf_stat__update_shadow_stats and perf_stat__print_shadow_stats use a cpu map index rather than a CPU, but first_shadow_cpu is returning the wrong value for this. Change first_shadow_cpu to first_shadow_cpu_map_idx to make things agree. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 9be74e907352..81a288a7ae46 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -327,24 +327,23 @@ static void print_metric_header(struct perf_stat_conf= ig *config, fprintf(os->fh, "%*s ", config->metric_only_len, unit); } =20 -static int first_shadow_cpu(struct perf_stat_config *config, - struct evsel *evsel, const struct aggr_cpu_id *id) +static int first_shadow_cpu_map_idx(struct perf_stat_config *config, + struct evsel *evsel, const struct aggr_cpu_id *id) { - struct perf_cpu_map *cpus; + struct perf_cpu_map *cpus =3D evsel__cpus(evsel); int cpu, idx; =20 if (config->aggr_mode =3D=3D AGGR_NONE) - return id->cpu; + return perf_cpu_map__idx(cpus, id->cpu); =20 if (!config->aggr_get_id) return 0; =20 - cpus =3D evsel__cpus(evsel); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { struct aggr_cpu_id cpu_id =3D config->aggr_get_id(config, cpu); =20 if (aggr_cpu_id__equal(&cpu_id, id)) - return cpu; + return idx; } return 0; } @@ -503,7 +502,7 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int } =20 perf_stat__print_shadow_stats(config, counter, uval, - first_shadow_cpu(config, counter, &id), + first_shadow_cpu_map_idx(config, counter, &id), &out, &config->metric_events, st); if (!config->csv_output && !config->metric_only) { print_noise(config, counter, noise); @@ -532,7 +531,7 @@ static void aggr_update_shadow(struct perf_stat_config = *config, val +=3D perf_counts(counter->counts, idx, 0)->val; } perf_stat__update_shadow_stats(counter, val, - first_shadow_cpu(config, counter, &id), + first_shadow_cpu_map_idx(config, counter, &id), &rt_stat); } } --=20 2.34.1.307.g9b7440fafd-goog From nobody Wed Jul 1 09:55:05 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84492C433EF for ; Thu, 23 Dec 2021 07:50:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347613AbhLWHti (ORCPT ); Thu, 23 Dec 2021 02:49:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347388AbhLWHsS (ORCPT ); Thu, 23 Dec 2021 02:48:18 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40EFDC0698DC for ; Wed, 22 Dec 2021 23:48:11 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id g36-20020a25ae64000000b005c1f46f7ee6so8753697ybe.8 for ; Wed, 22 Dec 2021 23:48:11 -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=CsmehZxdtr4mzWpchiEDLLM8u5lq+Hr6Xrox8uy1DZA=; b=gQzchocgZhknICizpxcCM9+V7d+0Wwht0jkBIqwp6A00j09ZfqLZf3jclAVHfB7lia C39m/5r32G34f4QqXSqH1P+Linl4lotZBjjzECU3jA00FSI1N1usom5ocO8pLJaWqhkl IFI3hI2ITztI9vSODFgNCmhBMVetzrwTxajWwlbAWnVHkt+avvRh+f8rB65p/3pjVxNA xOQqKui9vovpEi4jooUthU/NAAcyZi2sLrQ82vJzhpZ0+kDniCt0mLJBWGP3J/RjKnAI 4+jXMLglClNe6QZ373Tr85jlDyHcGBoajanoWG1sWlaXX/w4YW/kcJ1YizmGnAiuEq9q YHnw== 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=CsmehZxdtr4mzWpchiEDLLM8u5lq+Hr6Xrox8uy1DZA=; b=1ryIQQFzO9HgpznV9WQ/dGwgo8Fq8Fz78tOaNYZB7We+bzdKDbXAlYOj8l+qWVsIBm i60zyU87va1v4rxlSDDIHsKu1pXBuMtqjfFT570kioVPozDt43HYH4PYcrk97koo1J+g 0zlr9/5fk8y8M9sF0aLqZey9WbUy6szKuCDDAfjDqbDt/l8yMcktESrnD3yRAoBjenv/ tWLY3h/9vXWgzIX1iKCWEp8msVsb6Ew5UvYqkdNKptPW6v125Mzl5fUHJXBnMnF2L5Vh SgHl2mKBuJ4f7LdddW2O3wyhkqIh5mWN57DGsKRnXuBk8CMc/XTr1TCukwfWm7wqSTmC zSfQ== X-Gm-Message-State: AOAM531QOlvCYifttSmQdVBCQzZfMS4PDALd9qT2T8XkVfYOzOA9CtTW H3AigZ8gVsmT5yY7M7sL1MKhAcmera0m X-Google-Smtp-Source: ABdhPJy8nhRaQGVSljzbtw49ECFjJWJKxjM/tFjWuCPjkgSwCqcXbBpYr/rxv5475BgSUmf3exyHcmkIs4l1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:4fef:90ff:589d:24ca]) (user=irogers job=sendgmr) by 2002:a25:820e:: with SMTP id q14mr1618749ybk.396.1640245690473; Wed, 22 Dec 2021 23:48:10 -0800 (PST) Date: Wed, 22 Dec 2021 23:45:41 -0800 In-Reply-To: <20211223074541.3318938-1-irogers@google.com> Message-Id: <20211223074541.3318938-49-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 48/48] perf cpumap: Give CPUs their own type. 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A common problem is confusing CPU map indices with the CPU, by wrapping the CPU with a struct then this is avoided. This approach is similar to atomic_t. Suggested-by: John Garry Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 121 ++++++++++-------- tools/lib/perf/evlist.c | 4 +- tools/lib/perf/evsel.c | 9 +- tools/lib/perf/include/internal/cpumap.h | 9 +- tools/lib/perf/include/internal/evlist.h | 3 +- tools/lib/perf/include/internal/evsel.h | 4 +- tools/lib/perf/include/internal/mmap.h | 5 +- tools/lib/perf/include/perf/cpumap.h | 9 +- tools/lib/perf/mmap.c | 2 +- tools/perf/bench/epoll-ctl.c | 2 +- tools/perf/bench/epoll-wait.c | 2 +- tools/perf/bench/futex-hash.c | 2 +- tools/perf/bench/futex-lock-pi.c | 2 +- tools/perf/bench/futex-requeue.c | 2 +- tools/perf/bench/futex-wake-parallel.c | 2 +- tools/perf/bench/futex-wake.c | 2 +- tools/perf/builtin-c2c.c | 13 +- tools/perf/builtin-ftrace.c | 2 +- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-record.c | 2 +- tools/perf/builtin-sched.c | 65 +++++----- tools/perf/builtin-script.c | 5 +- tools/perf/builtin-stat.c | 80 ++++++------ tools/perf/tests/attr.c | 6 +- tools/perf/tests/bitmap.c | 2 +- tools/perf/tests/cpumap.c | 6 +- tools/perf/tests/event_update.c | 6 +- tools/perf/tests/mem2node.c | 2 +- tools/perf/tests/mmap-basic.c | 4 +- tools/perf/tests/openat-syscall-all-cpus.c | 17 +-- tools/perf/tests/stat.c | 3 +- tools/perf/tests/topology.c | 30 +++-- tools/perf/util/affinity.c | 2 +- tools/perf/util/auxtrace.c | 12 +- tools/perf/util/auxtrace.h | 5 +- tools/perf/util/cpumap.c | 91 ++++++------- tools/perf/util/cpumap.h | 26 ++-- tools/perf/util/cputopo.c | 6 +- tools/perf/util/env.c | 29 +++-- tools/perf/util/env.h | 3 +- tools/perf/util/evlist.c | 8 +- tools/perf/util/evlist.h | 2 +- tools/perf/util/evsel.c | 6 +- tools/perf/util/expr.c | 2 +- tools/perf/util/header.c | 6 +- tools/perf/util/mmap.c | 19 +-- tools/perf/util/mmap.h | 3 +- tools/perf/util/perf_api_probe.c | 15 ++- tools/perf/util/python.c | 4 +- tools/perf/util/record.c | 11 +- .../scripting-engines/trace-event-python.c | 6 +- tools/perf/util/session.c | 10 +- tools/perf/util/stat-display.c | 34 +++-- tools/perf/util/stat.c | 2 +- tools/perf/util/stat.h | 2 +- tools/perf/util/svghelper.c | 6 +- tools/perf/util/synthetic-events.c | 12 +- tools/perf/util/synthetic-events.h | 3 +- tools/perf/util/util.h | 5 +- 59 files changed, 408 insertions(+), 347 deletions(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index eacea3ab965a..a3afe9ef74ef 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -10,16 +10,27 @@ #include #include =20 +static struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) +{ + struct perf_cpu_map *cpus; + + cpus =3D malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); + if (!cpus) + return NULL; + + cpus->nr =3D 1; + refcount_set(&cpus->refcnt, 1); + return cpus; +} + struct perf_cpu_map *perf_cpu_map__dummy_new(void) { - struct perf_cpu_map *cpus =3D malloc(sizeof(*cpus) + sizeof(int)); + struct perf_cpu_map *cpus =3D perf_cpu_map__alloc(1); =20 - if (cpus !=3D NULL) { - cpus->nr =3D 1; - cpus->map[0] =3D -1; - refcount_set(&cpus->refcnt, 1); - } + if (!cpus) + return NULL; =20 + cpus->map[0].cpu =3D -1; return cpus; } =20 @@ -54,16 +65,12 @@ static struct perf_cpu_map *cpu_map__default_new(void) if (nr_cpus < 0) return NULL; =20 - cpus =3D malloc(sizeof(*cpus) + nr_cpus * sizeof(int)); - if (cpus !=3D NULL) { - int i; - - for (i =3D 0; i < nr_cpus; ++i) - cpus->map[i] =3D i; + cpus =3D perf_cpu_map__alloc(nr_cpus); + if (!cpus) + return NULL; =20 - cpus->nr =3D nr_cpus; - refcount_set(&cpus->refcnt, 1); - } + for (int i =3D 0; i < nr_cpus; ++i) + cpus->map[i].cpu =3D i; =20 return cpus; } @@ -73,31 +80,32 @@ struct perf_cpu_map *perf_cpu_map__default_new(void) return cpu_map__default_new(); } =20 -static int cmp_int(const void *a, const void *b) + +static int cmp_cpu(const void *a, const void *b) { - return *(const int *)a - *(const int*)b; + const struct perf_cpu *cpu_a =3D a, *cpu_b =3D b; + + return cpu_a->cpu - cpu_b->cpu; } =20 -static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, int *tmp_cpus) +static struct perf_cpu_map *cpu_map__trim_new(int nr_cpus, const struct pe= rf_cpu *tmp_cpus) { - size_t payload_size =3D nr_cpus * sizeof(int); - struct perf_cpu_map *cpus =3D malloc(sizeof(*cpus) + payload_size); + size_t payload_size =3D nr_cpus * sizeof(struct perf_cpu); + struct perf_cpu_map *cpus =3D perf_cpu_map__alloc(nr_cpus); int i, j; =20 if (cpus !=3D NULL) { memcpy(cpus->map, tmp_cpus, payload_size); - qsort(cpus->map, nr_cpus, sizeof(int), cmp_int); + qsort(cpus->map, nr_cpus, sizeof(struct perf_cpu), cmp_cpu); /* Remove dups */ j =3D 0; for (i =3D 0; i < nr_cpus; i++) { - if (i =3D=3D 0 || cpus->map[i] !=3D cpus->map[i - 1]) - cpus->map[j++] =3D cpus->map[i]; + if (i =3D=3D 0 || cpus->map[i].cpu !=3D cpus->map[i - 1].cpu) + cpus->map[j++].cpu =3D cpus->map[i].cpu; } cpus->nr =3D j; assert(j <=3D nr_cpus); - refcount_set(&cpus->refcnt, 1); } - return cpus; } =20 @@ -105,7 +113,7 @@ struct perf_cpu_map *perf_cpu_map__read(FILE *file) { struct perf_cpu_map *cpus =3D NULL; int nr_cpus =3D 0; - int *tmp_cpus =3D NULL, *tmp; + struct perf_cpu *tmp_cpus =3D NULL, *tmp; int max_entries =3D 0; int n, cpu, prev; char sep; @@ -124,24 +132,24 @@ struct perf_cpu_map *perf_cpu_map__read(FILE *file) =20 if (new_max >=3D max_entries) { max_entries =3D new_max + MAX_NR_CPUS / 2; - tmp =3D realloc(tmp_cpus, max_entries * sizeof(int)); + tmp =3D realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); if (tmp =3D=3D NULL) goto out_free_tmp; tmp_cpus =3D tmp; } =20 while (++prev < cpu) - tmp_cpus[nr_cpus++] =3D prev; + tmp_cpus[nr_cpus++].cpu =3D prev; } if (nr_cpus =3D=3D max_entries) { max_entries +=3D MAX_NR_CPUS; - tmp =3D realloc(tmp_cpus, max_entries * sizeof(int)); + tmp =3D realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); if (tmp =3D=3D NULL) goto out_free_tmp; tmp_cpus =3D tmp; } =20 - tmp_cpus[nr_cpus++] =3D cpu; + tmp_cpus[nr_cpus++].cpu =3D cpu; if (n =3D=3D 2 && sep =3D=3D '-') prev =3D cpu; else @@ -179,7 +187,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_= list) unsigned long start_cpu, end_cpu =3D 0; char *p =3D NULL; int i, nr_cpus =3D 0; - int *tmp_cpus =3D NULL, *tmp; + struct perf_cpu *tmp_cpus =3D NULL, *tmp; int max_entries =3D 0; =20 if (!cpu_list) @@ -220,17 +228,17 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cp= u_list) for (; start_cpu <=3D end_cpu; start_cpu++) { /* check for duplicates */ for (i =3D 0; i < nr_cpus; i++) - if (tmp_cpus[i] =3D=3D (int)start_cpu) + if (tmp_cpus[i].cpu =3D=3D (int)start_cpu) goto invalid; =20 if (nr_cpus =3D=3D max_entries) { max_entries +=3D MAX_NR_CPUS; - tmp =3D realloc(tmp_cpus, max_entries * sizeof(int)); + tmp =3D realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); if (tmp =3D=3D NULL) goto invalid; tmp_cpus =3D tmp; } - tmp_cpus[nr_cpus++] =3D (int)start_cpu; + tmp_cpus[nr_cpus++].cpu =3D (int)start_cpu; } if (*p) ++p; @@ -250,12 +258,16 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cp= u_list) return cpus; } =20 -int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx) +struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx) { + struct perf_cpu result =3D { + .cpu =3D -1 + }; + if (cpus && idx < cpus->nr) - return cpus->map[idx]; + result =3D cpus->map[idx]; =20 - return -1; + return result; } =20 int perf_cpu_map__nr(const struct perf_cpu_map *cpus) @@ -265,10 +277,10 @@ int perf_cpu_map__nr(const struct perf_cpu_map *cpus) =20 bool perf_cpu_map__empty(const struct perf_cpu_map *map) { - return map ? map->map[0] =3D=3D -1 : true; + return map ? map->map[0].cpu =3D=3D -1 : true; } =20 -int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu) +int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu) { int low, high; =20 @@ -278,13 +290,13 @@ int perf_cpu_map__idx(const struct perf_cpu_map *cpus= , int cpu) low =3D 0; high =3D cpus->nr; while (low < high) { - int idx =3D (low + high) / 2, - cpu_at_idx =3D cpus->map[idx]; + int idx =3D (low + high) / 2; + struct perf_cpu cpu_at_idx =3D cpus->map[idx]; =20 - if (cpu_at_idx =3D=3D cpu) + if (cpu_at_idx.cpu =3D=3D cpu.cpu) return idx; =20 - if (cpu_at_idx > cpu) + if (cpu_at_idx.cpu > cpu.cpu) high =3D idx; else low =3D idx + 1; @@ -293,15 +305,22 @@ int perf_cpu_map__idx(const struct perf_cpu_map *cpus= , int cpu) return -1; } =20 -bool perf_cpu_map__has(const struct perf_cpu_map *cpus, int cpu) +bool perf_cpu_map__has(const struct perf_cpu_map *cpus, struct perf_cpu cp= u) { return perf_cpu_map__idx(cpus, cpu) !=3D -1; } =20 -int perf_cpu_map__max(struct perf_cpu_map *map) +struct perf_cpu perf_cpu_map__max(struct perf_cpu_map *map) { + struct perf_cpu result =3D { + .cpu =3D -1 + }; + // cpu_map__trim_new() qsort()s it, cpu_map__default_new() sorts it as we= ll. - return map->nr > 0 ? map->map[map->nr - 1] : -1; + if (map->nr > 0) + result =3D map->map[map->nr - 1]; + + return result; } =20 /* @@ -315,7 +334,7 @@ int perf_cpu_map__max(struct perf_cpu_map *map) struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *orig, struct perf_cpu_map *other) { - int *tmp_cpus; + struct perf_cpu *tmp_cpus; int tmp_len; int i, j, k; struct perf_cpu_map *merged; @@ -329,19 +348,19 @@ struct perf_cpu_map *perf_cpu_map__merge(struct perf_= cpu_map *orig, if (!other) return orig; if (orig->nr =3D=3D other->nr && - !memcmp(orig->map, other->map, orig->nr * sizeof(int))) + !memcmp(orig->map, other->map, orig->nr * sizeof(struct perf_cpu))) return orig; =20 tmp_len =3D orig->nr + other->nr; - tmp_cpus =3D malloc(tmp_len * sizeof(int)); + tmp_cpus =3D malloc(tmp_len * sizeof(struct perf_cpu)); if (!tmp_cpus) return NULL; =20 /* Standard merge algorithm from wikipedia */ i =3D j =3D k =3D 0; while (i < orig->nr && j < other->nr) { - if (orig->map[i] <=3D other->map[j]) { - if (orig->map[i] =3D=3D other->map[j]) + if (orig->map[i].cpu <=3D other->map[j].cpu) { + if (orig->map[i].cpu =3D=3D other->map[j].cpu) j++; tmp_cpus[k++] =3D orig->map[i++]; } else diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 245acbc53bd3..9a770bfdc804 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -407,7 +407,7 @@ perf_evlist__mmap_cb_get(struct perf_evlist *evlist, bo= ol overwrite, int idx) =20 static int perf_evlist__mmap_cb_mmap(struct perf_mmap *map, struct perf_mmap_param *m= p, - int output, int cpu) + int output, struct perf_cpu cpu) { return perf_mmap__mmap(map, mp, output, cpu); } @@ -426,7 +426,7 @@ mmap_per_evsel(struct perf_evlist *evlist, struct perf_= evlist_mmap_ops *ops, int idx, struct perf_mmap_param *mp, int cpu_idx, int thread, int *_output, int *_output_overwrite) { - int evlist_cpu =3D perf_cpu_map__cpu(evlist->cpus, cpu_idx); + struct perf_cpu evlist_cpu =3D perf_cpu_map__cpu(evlist->cpus, cpu_idx); struct perf_evsel *evsel; int revent; =20 diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c index f1e1665ef4bd..7ea86a44eae5 100644 --- a/tools/lib/perf/evsel.c +++ b/tools/lib/perf/evsel.c @@ -78,10 +78,10 @@ static int perf_evsel__alloc_mmap(struct perf_evsel *ev= sel, int ncpus, int nthre =20 static int sys_perf_event_open(struct perf_event_attr *attr, - pid_t pid, int cpu, int group_fd, + pid_t pid, struct perf_cpu cpu, int group_fd, unsigned long flags) { - return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags); + return syscall(__NR_perf_event_open, attr, pid, cpu.cpu, group_fd, flags); } =20 static int get_group_fd(struct perf_evsel *evsel, int cpu_map_idx, int thr= ead, int *group_fd) @@ -113,7 +113,8 @@ static int get_group_fd(struct perf_evsel *evsel, int c= pu_map_idx, int thread, i int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, struct perf_thread_map *threads) { - int cpu, idx, thread, err =3D 0; + struct perf_cpu cpu; + int idx, thread, err =3D 0; =20 if (cpus =3D=3D NULL) { static struct perf_cpu_map *empty_cpu_map; @@ -252,7 +253,7 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int page= s) for (thread =3D 0; thread < xyarray__max_y(evsel->fd); thread++) { int *fd =3D FD(evsel, idx, thread); struct perf_mmap *map; - int cpu =3D perf_cpu_map__cpu(evsel->cpus, idx); + struct perf_cpu cpu =3D perf_cpu_map__cpu(evsel->cpus, idx); =20 if (fd =3D=3D NULL || *fd < 0) continue; diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/incl= ude/internal/cpumap.h index 71a31ed738c9..581f9ffb4237 100644 --- a/tools/lib/perf/include/internal/cpumap.h +++ b/tools/lib/perf/include/internal/cpumap.h @@ -4,6 +4,11 @@ =20 #include =20 +/** A wrapper around a CPU to avoid confusion with the perf_cpu_map's map'= s indices. */ +struct perf_cpu { + int cpu; +}; + /** * A sized, reference counted, sorted array of integers representing CPU * numbers. This is commonly used to capture which CPUs a PMU is associated @@ -16,13 +21,13 @@ struct perf_cpu_map { /** Length of the map array. */ int nr; /** The CPU values. */ - int map[]; + struct perf_cpu map[]; }; =20 #ifndef MAX_NR_CPUS #define MAX_NR_CPUS 2048 #endif =20 -int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu); +int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu= ); =20 #endif /* __LIBPERF_INTERNAL_CPUMAP_H */ diff --git a/tools/lib/perf/include/internal/evlist.h b/tools/lib/perf/incl= ude/internal/evlist.h index 6f74269a3ad4..4cefade540bd 100644 --- a/tools/lib/perf/include/internal/evlist.h +++ b/tools/lib/perf/include/internal/evlist.h @@ -4,6 +4,7 @@ =20 #include #include +#include #include =20 #define PERF_EVLIST__HLIST_BITS 8 @@ -36,7 +37,7 @@ typedef void typedef struct perf_mmap* (*perf_evlist_mmap__cb_get_t)(struct perf_evlist*, bool, int); typedef int -(*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*,= int, int); +(*perf_evlist_mmap__cb_mmap_t)(struct perf_mmap*, struct perf_mmap_param*,= int, struct perf_cpu); =20 struct perf_evlist_mmap_ops { perf_evlist_mmap__cb_idx_t idx; diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/inclu= de/internal/evsel.h index 1f3eacbad2e8..cfc9ebd7968e 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -6,8 +6,8 @@ #include #include #include +#include =20 -struct perf_cpu_map; struct perf_thread_map; struct xyarray; =20 @@ -27,7 +27,7 @@ struct perf_sample_id { * queue number. */ int idx; - int cpu; + struct perf_cpu cpu; pid_t tid; =20 /* Holds total ID period value for PERF_SAMPLE_READ processing. */ diff --git a/tools/lib/perf/include/internal/mmap.h b/tools/lib/perf/includ= e/internal/mmap.h index 5e3422f40ed5..5a062af8e9d8 100644 --- a/tools/lib/perf/include/internal/mmap.h +++ b/tools/lib/perf/include/internal/mmap.h @@ -6,6 +6,7 @@ #include #include #include +#include =20 /* perf sample has 16 bits size limit */ #define PERF_SAMPLE_MAX_SIZE (1 << 16) @@ -24,7 +25,7 @@ struct perf_mmap { void *base; int mask; int fd; - int cpu; + struct perf_cpu cpu; refcount_t refcnt; u64 prev; u64 start; @@ -46,7 +47,7 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map); void perf_mmap__init(struct perf_mmap *map, struct perf_mmap *prev, bool overwrite, libperf_unmap_cb_t unmap_cb); int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, - int fd, int cpu); + int fd, struct perf_cpu cpu); void perf_mmap__munmap(struct perf_mmap *map); void perf_mmap__get(struct perf_mmap *map); void perf_mmap__put(struct perf_mmap *map); diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/= perf/cpumap.h index 3f1c0afa3ccd..15b8faafd615 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -3,11 +3,10 @@ #define __LIBPERF_CPUMAP_H =20 #include +#include #include #include =20 -struct perf_cpu_map; - LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__default_new(void); LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list); @@ -16,11 +15,11 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(stru= ct perf_cpu_map *map); LIBPERF_API struct perf_cpu_map *perf_cpu_map__merge(struct perf_cpu_map *= orig, struct perf_cpu_map *other); LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map); -LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx= ); +LIBPERF_API struct perf_cpu perf_cpu_map__cpu(const struct perf_cpu_map *c= pus, int idx); LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); LIBPERF_API bool perf_cpu_map__empty(const struct perf_cpu_map *map); -LIBPERF_API int perf_cpu_map__max(struct perf_cpu_map *map); -LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, int cpu= ); +LIBPERF_API struct perf_cpu perf_cpu_map__max(struct perf_cpu_map *map); +LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct = perf_cpu cpu); =20 #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) =3D 0, (cpu) =3D perf_cpu_map__cpu(cpus, idx); \ diff --git a/tools/lib/perf/mmap.c b/tools/lib/perf/mmap.c index aaa457904008..f7ee07cb5818 100644 --- a/tools/lib/perf/mmap.c +++ b/tools/lib/perf/mmap.c @@ -32,7 +32,7 @@ size_t perf_mmap__mmap_len(struct perf_mmap *map) } =20 int perf_mmap__mmap(struct perf_mmap *map, struct perf_mmap_param *mp, - int fd, int cpu) + int fd, struct perf_cpu cpu) { map->prev =3D 0; map->mask =3D mp->mask; diff --git a/tools/perf/bench/epoll-ctl.c b/tools/perf/bench/epoll-ctl.c index ddaca75c3bc0..1a17ec83d3c4 100644 --- a/tools/perf/bench/epoll-ctl.c +++ b/tools/perf/bench/epoll-ctl.c @@ -253,7 +253,7 @@ static int do_threads(struct worker *worker, struct per= f_cpu_map *cpu) =20 if (!noaffinity) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset); =20 ret =3D pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &c= puset); if (ret) diff --git a/tools/perf/bench/epoll-wait.c b/tools/perf/bench/epoll-wait.c index 79d13dbc0a47..0d1dd8879197 100644 --- a/tools/perf/bench/epoll-wait.c +++ b/tools/perf/bench/epoll-wait.c @@ -342,7 +342,7 @@ static int do_threads(struct worker *worker, struct per= f_cpu_map *cpu) =20 if (!noaffinity) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset); =20 ret =3D pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &c= puset); if (ret) diff --git a/tools/perf/bench/futex-hash.c b/tools/perf/bench/futex-hash.c index fcdea3e44937..9627b6ab8670 100644 --- a/tools/perf/bench/futex-hash.c +++ b/tools/perf/bench/futex-hash.c @@ -177,7 +177,7 @@ int bench_futex_hash(int argc, const char **argv) goto errmem; =20 CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset); =20 ret =3D pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cp= uset); if (ret) diff --git a/tools/perf/bench/futex-lock-pi.c b/tools/perf/bench/futex-lock= -pi.c index 137890f78e17..a512a320df74 100644 --- a/tools/perf/bench/futex-lock-pi.c +++ b/tools/perf/bench/futex-lock-pi.c @@ -136,7 +136,7 @@ static void create_threads(struct worker *w, pthread_at= tr_t thread_attr, worker[i].futex =3D &global_futex; =20 CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset); =20 if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset= )) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/bench/futex-requeue.c b/tools/perf/bench/futex-requ= eue.c index f7a5ffebb940..aca47ce8b1e7 100644 --- a/tools/perf/bench/futex-requeue.c +++ b/tools/perf/bench/futex-requeue.c @@ -131,7 +131,7 @@ static void block_threads(pthread_t *w, /* create and block all threads */ for (i =3D 0; i < params.nthreads; i++) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset); =20 if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset= )) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/bench/futex-wake-parallel.c b/tools/perf/bench/fute= x-wake-parallel.c index 0983f40b4b40..888ee6037945 100644 --- a/tools/perf/bench/futex-wake-parallel.c +++ b/tools/perf/bench/futex-wake-parallel.c @@ -152,7 +152,7 @@ static void block_threads(pthread_t *w, pthread_attr_t = thread_attr, /* create and block all threads */ for (i =3D 0; i < params.nthreads; i++) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset); =20 if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset= )) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/bench/futex-wake.c b/tools/perf/bench/futex-wake.c index 2226a475e782..aa82db51c0ab 100644 --- a/tools/perf/bench/futex-wake.c +++ b/tools/perf/bench/futex-wake.c @@ -105,7 +105,7 @@ static void block_threads(pthread_t *w, /* create and block all threads */ for (i =3D 0; i < params.nthreads; i++) { CPU_ZERO(&cpuset); - CPU_SET(cpu->map[i % cpu->nr], &cpuset); + CPU_SET(perf_cpu_map__cpu(cpu, i % perf_cpu_map__nr(cpu)).cpu, &cpuset); =20 if (pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset= )) err(EXIT_FAILURE, "pthread_attr_setaffinity_np"); diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index ad1fbeafc93d..77dd4afacca4 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -2015,7 +2015,8 @@ static int setup_nodes(struct perf_session *session) { struct numa_node *n; unsigned long **nodes; - int node, cpu, idx; + int node, idx; + struct perf_cpu cpu; int *cpu2node; =20 if (c2c.node_info > 2) @@ -2038,8 +2039,8 @@ static int setup_nodes(struct perf_session *session) if (!cpu2node) return -ENOMEM; =20 - for (cpu =3D 0; cpu < c2c.cpus_cnt; cpu++) - cpu2node[cpu] =3D -1; + for (idx =3D 0; idx < c2c.cpus_cnt; idx++) + cpu2node[idx] =3D -1; =20 c2c.cpu2node =3D cpu2node; =20 @@ -2058,12 +2059,12 @@ static int setup_nodes(struct perf_session *session) continue; =20 perf_cpu_map__for_each_cpu(cpu, idx, map) { - set_bit(cpu, set); + set_bit(cpu.cpu, set); =20 - if (WARN_ONCE(cpu2node[cpu] !=3D -1, "node/cpu topology bug")) + if (WARN_ONCE(cpu2node[cpu.cpu] !=3D -1, "node/cpu topology bug")) return -EINVAL; =20 - cpu2node[cpu] =3D node; + cpu2node[cpu.cpu] =3D node; } } =20 diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 5a65dc7a1580..224030c0ef5f 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -303,7 +303,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpu= map) int ret; int last_cpu; =20 - last_cpu =3D perf_cpu_map__cpu(cpumap, cpumap->nr - 1); + last_cpu =3D perf_cpu_map__cpu(cpumap, cpumap->nr - 1).cpu; mask_size =3D last_cpu / 4 + 2; /* one more byte for EOS */ mask_size +=3D last_cpu / 32; /* ',' is needed for every 32th cpus */ =20 diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c index da03a341c63c..99d7ff9a8eff 100644 --- a/tools/perf/builtin-kmem.c +++ b/tools/perf/builtin-kmem.c @@ -192,7 +192,7 @@ static int evsel__process_alloc_node_event(struct evsel= *evsel, struct perf_samp int ret =3D evsel__process_alloc_event(evsel, sample); =20 if (!ret) { - int node1 =3D cpu__get_node(sample->cpu), + int node1 =3D cpu__get_node((struct perf_cpu){.cpu =3D sample->cpu}), node2 =3D evsel__intval(evsel, sample, "node"); =20 if (node1 !=3D node2) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 0338b813585a..dde884dd9510 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2792,7 +2792,7 @@ int cmd_record(int argc, const char **argv) symbol__init(NULL); =20 if (rec->opts.affinity !=3D PERF_AFFINITY_SYS) { - rec->affinity_mask.nbits =3D cpu__max_cpu(); + rec->affinity_mask.nbits =3D cpu__max_cpu().cpu; rec->affinity_mask.bits =3D bitmap_zalloc(rec->affinity_mask.nbits); if (!rec->affinity_mask.bits) { pr_err("Failed to allocate thread mask for %zd cpus\n", rec->affinity_m= ask.nbits); diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c index 9da1da4749c9..72d446de9c60 100644 --- a/tools/perf/builtin-sched.c +++ b/tools/perf/builtin-sched.c @@ -167,7 +167,7 @@ struct trace_sched_handler { =20 struct perf_sched_map { DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS); - int *comp_cpus; + struct perf_cpu *comp_cpus; bool comp; struct perf_thread_map *color_pids; const char *color_pids_str; @@ -191,7 +191,7 @@ struct perf_sched { * Track the current task - that way we can know whether there's any * weird events, such as a task being switched away that is not current. */ - int max_cpu; + struct perf_cpu max_cpu; u32 curr_pid[MAX_CPUS]; struct thread *curr_thread[MAX_CPUS]; char next_shortname1; @@ -1535,28 +1535,31 @@ static int map_switch_event(struct perf_sched *sche= d, struct evsel *evsel, int new_shortname; u64 timestamp0, timestamp =3D sample->time; s64 delta; - int i, this_cpu =3D sample->cpu; + int i; + struct perf_cpu this_cpu =3D { + .cpu =3D sample->cpu, + }; int cpus_nr; bool new_cpu =3D false; const char *color =3D PERF_COLOR_NORMAL; char stimestamp[32]; =20 - BUG_ON(this_cpu >=3D MAX_CPUS || this_cpu < 0); + BUG_ON(this_cpu.cpu >=3D MAX_CPUS || this_cpu.cpu < 0); =20 - if (this_cpu > sched->max_cpu) + if (this_cpu.cpu > sched->max_cpu.cpu) sched->max_cpu =3D this_cpu; =20 if (sched->map.comp) { cpus_nr =3D bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS); - if (!test_and_set_bit(this_cpu, sched->map.comp_cpus_mask)) { + if (!test_and_set_bit(this_cpu.cpu, sched->map.comp_cpus_mask)) { sched->map.comp_cpus[cpus_nr++] =3D this_cpu; new_cpu =3D true; } } else - cpus_nr =3D sched->max_cpu; + cpus_nr =3D sched->max_cpu.cpu; =20 - timestamp0 =3D sched->cpu_last_switched[this_cpu]; - sched->cpu_last_switched[this_cpu] =3D timestamp; + timestamp0 =3D sched->cpu_last_switched[this_cpu.cpu]; + sched->cpu_last_switched[this_cpu.cpu] =3D timestamp; if (timestamp0) delta =3D timestamp - timestamp0; else @@ -1577,7 +1580,7 @@ static int map_switch_event(struct perf_sched *sched,= struct evsel *evsel, return -1; } =20 - sched->curr_thread[this_cpu] =3D thread__get(sched_in); + sched->curr_thread[this_cpu.cpu] =3D thread__get(sched_in); =20 printf(" "); =20 @@ -1608,8 +1611,10 @@ static int map_switch_event(struct perf_sched *sched= , struct evsel *evsel, } =20 for (i =3D 0; i < cpus_nr; i++) { - int cpu =3D sched->map.comp ? sched->map.comp_cpus[i] : i; - struct thread *curr_thread =3D sched->curr_thread[cpu]; + struct perf_cpu cpu =3D { + .cpu =3D sched->map.comp ? sched->map.comp_cpus[i].cpu : i, + }; + struct thread *curr_thread =3D sched->curr_thread[cpu.cpu]; struct thread_runtime *curr_tr; const char *pid_color =3D color; const char *cpu_color =3D color; @@ -1623,13 +1628,13 @@ static int map_switch_event(struct perf_sched *sche= d, struct evsel *evsel, if (sched->map.color_cpus && perf_cpu_map__has(sched->map.color_cpus, cp= u)) cpu_color =3D COLOR_CPUS; =20 - if (cpu !=3D this_cpu) + if (cpu.cpu !=3D this_cpu.cpu) color_fprintf(stdout, color, " "); else color_fprintf(stdout, cpu_color, "*"); =20 - if (sched->curr_thread[cpu]) { - curr_tr =3D thread__get_runtime(sched->curr_thread[cpu]); + if (sched->curr_thread[cpu.cpu]) { + curr_tr =3D thread__get_runtime(sched->curr_thread[cpu.cpu]); if (curr_tr =3D=3D NULL) { thread__put(sched_in); return -1; @@ -1929,7 +1934,7 @@ static char *timehist_get_commstr(struct thread *thre= ad) =20 static void timehist_header(struct perf_sched *sched) { - u32 ncpus =3D sched->max_cpu + 1; + u32 ncpus =3D sched->max_cpu.cpu + 1; u32 i, j; =20 printf("%15s %6s ", "time", "cpu"); @@ -2008,7 +2013,7 @@ static void timehist_print_sample(struct perf_sched *= sched, struct thread_runtime *tr =3D thread__priv(thread); const char *next_comm =3D evsel__strval(evsel, sample, "next_comm"); const u32 next_pid =3D evsel__intval(evsel, sample, "next_pid"); - u32 max_cpus =3D sched->max_cpu + 1; + u32 max_cpus =3D sched->max_cpu.cpu + 1; char tstr[64]; char nstr[30]; u64 wait_time; @@ -2389,7 +2394,7 @@ static void timehist_print_wakeup_event(struct perf_s= ched *sched, timestamp__scnprintf_usec(sample->time, tstr, sizeof(tstr)); printf("%15s [%04d] ", tstr, sample->cpu); if (sched->show_cpu_visual) - printf(" %*s ", sched->max_cpu + 1, ""); + printf(" %*s ", sched->max_cpu.cpu + 1, ""); =20 printf(" %-*s ", comm_width, timehist_get_commstr(thread)); =20 @@ -2449,13 +2454,13 @@ static void timehist_print_migration_event(struct p= erf_sched *sched, { struct thread *thread; char tstr[64]; - u32 max_cpus =3D sched->max_cpu + 1; + u32 max_cpus; u32 ocpu, dcpu; =20 if (sched->summary_only) return; =20 - max_cpus =3D sched->max_cpu + 1; + max_cpus =3D sched->max_cpu.cpu + 1; ocpu =3D evsel__intval(evsel, sample, "orig_cpu"); dcpu =3D evsel__intval(evsel, sample, "dest_cpu"); =20 @@ -2918,7 +2923,7 @@ static void timehist_print_summary(struct perf_sched = *sched, =20 printf(" Total scheduling time (msec): "); print_sched_time(hist_time, 2); - printf(" (x %d)\n", sched->max_cpu); + printf(" (x %d)\n", sched->max_cpu.cpu); } =20 typedef int (*sched_handler)(struct perf_tool *tool, @@ -2935,9 +2940,11 @@ static int perf_timehist__process_sample(struct perf= _tool *tool, { struct perf_sched *sched =3D container_of(tool, struct perf_sched, tool); int err =3D 0; - int this_cpu =3D sample->cpu; + struct perf_cpu this_cpu =3D { + .cpu =3D sample->cpu, + }; =20 - if (this_cpu > sched->max_cpu) + if (this_cpu.cpu > sched->max_cpu.cpu) sched->max_cpu =3D this_cpu; =20 if (evsel->handler !=3D NULL) { @@ -3054,10 +3061,10 @@ static int perf_sched__timehist(struct perf_sched *= sched) goto out; =20 /* pre-allocate struct for per-CPU idle stats */ - sched->max_cpu =3D session->header.env.nr_cpus_online; - if (sched->max_cpu =3D=3D 0) - sched->max_cpu =3D 4; - if (init_idle_threads(sched->max_cpu)) + sched->max_cpu.cpu =3D session->header.env.nr_cpus_online; + if (sched->max_cpu.cpu =3D=3D 0) + sched->max_cpu.cpu =3D 4; + if (init_idle_threads(sched->max_cpu.cpu)) goto out; =20 /* summary_only implies summary option, but don't overwrite summary if se= t */ @@ -3209,10 +3216,10 @@ static int setup_map_cpus(struct perf_sched *sched) { struct perf_cpu_map *map; =20 - sched->max_cpu =3D sysconf(_SC_NPROCESSORS_CONF); + sched->max_cpu.cpu =3D sysconf(_SC_NPROCESSORS_CONF); =20 if (sched->map.comp) { - sched->map.comp_cpus =3D zalloc(sched->max_cpu * sizeof(int)); + sched->map.comp_cpus =3D zalloc(sched->max_cpu.cpu * sizeof(int)); if (!sched->map.comp_cpus) return -1; } diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index de4af7af34c8..aae8a236fa26 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2113,7 +2113,8 @@ static struct scripting_ops *scripting_ops; static void __process_stat(struct evsel *counter, u64 tstamp) { int nthreads =3D perf_thread_map__nr(counter->core.threads); - int idx, cpu, thread; + int idx, thread; + struct perf_cpu cpu; static int header_printed; =20 if (counter->core.system_wide) @@ -2132,7 +2133,7 @@ static void __process_stat(struct evsel *counter, u64= tstamp) counts =3D perf_counts(counter->counts, idx, thread); =20 printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 "= %s\n", - cpu, + cpu.cpu, perf_thread_map__pid(counter->core.threads, thread), counts->val, counts->ena, diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 68543bc7459f..f81c7f595fd9 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -234,7 +234,7 @@ static bool cpus_map_matched(struct evsel *a, struct ev= sel *b) return false; =20 for (int i =3D 0; i < a->core.cpus->nr; i++) { - if (a->core.cpus->map[i] !=3D b->core.cpus->map[i]) + if (a->core.cpus->map[i].cpu !=3D b->core.cpus->map[i].cpu) return false; } =20 @@ -331,7 +331,7 @@ static int evsel__write_stat_event(struct evsel *counte= r, int cpu_map_idx, u32 t struct perf_counts_values *count) { struct perf_sample_id *sid =3D SID(counter, cpu_map_idx, thread); - int cpu =3D perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx); + struct perf_cpu cpu =3D perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_i= dx); =20 return perf_event__synthesize_stat(NULL, cpu, thread, sid->id, count, process_synthesized_event, NULL); @@ -396,7 +396,8 @@ static int read_counter_cpu(struct evsel *counter, stru= ct timespec *rs, int cpu_ fprintf(stat_config.output, "%s: %d: %" PRIu64 " %" PRIu64 " %" PRIu64 "\n", evsel__name(counter), - perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx), + perf_cpu_map__cpu(evsel__cpus(counter), + cpu_map_idx).cpu, count->val, count->ena, count->run); } } @@ -1328,61 +1329,61 @@ static const char *const aggr_mode__string[] =3D { }; =20 static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *c= onfig __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__socket(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_die(struct perf_stat_config *conf= ig __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__die(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_core(struct perf_stat_config *con= fig __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__core(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *con= fig __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__node(cpu, /*data=3D*/NULL); } =20 static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *con= fig, - aggr_get_id_t get_id, int cpu) + aggr_get_id_t get_id, struct perf_cpu cpu) { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 - if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu])) - config->cpus_aggr_map->map[cpu] =3D get_id(config, cpu); + if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) + config->cpus_aggr_map->map[cpu.cpu] =3D get_id(config, cpu); =20 - id =3D config->cpus_aggr_map->map[cpu]; + id =3D config->cpus_aggr_map->map[cpu.cpu]; return id; } =20 static struct aggr_cpu_id perf_stat__get_socket_cached(struct perf_stat_co= nfig *config, - int cpu) + struct perf_cpu cpu) { return perf_stat__get_aggr(config, perf_stat__get_socket, cpu); } =20 static struct aggr_cpu_id perf_stat__get_die_cached(struct perf_stat_confi= g *config, - int cpu) + struct perf_cpu cpu) { return perf_stat__get_aggr(config, perf_stat__get_die, cpu); } =20 static struct aggr_cpu_id perf_stat__get_core_cached(struct perf_stat_conf= ig *config, - int cpu) + struct perf_cpu cpu) { return perf_stat__get_aggr(config, perf_stat__get_core, cpu); } =20 static struct aggr_cpu_id perf_stat__get_node_cached(struct perf_stat_conf= ig *config, - int cpu) + struct perf_cpu cpu) { return perf_stat__get_aggr(config, perf_stat__get_node, cpu); } @@ -1467,7 +1468,7 @@ static int perf_stat_init_aggr_mode(void) * taking the highest cpu number to be the size of * the aggregation translate cpumap. */ - nr =3D perf_cpu_map__max(evsel_list->core.cpus); + nr =3D perf_cpu_map__max(evsel_list->core.cpus).cpu; stat_config.cpus_aggr_map =3D cpu_aggr_map__empty_new(nr + 1); return stat_config.cpus_aggr_map ? 0 : -ENOMEM; } @@ -1495,71 +1496,66 @@ static void perf_stat__exit_aggr_mode(void) stat_config.cpus_aggr_map =3D NULL; } =20 -static inline int perf_env__get_cpu(void *data, struct perf_cpu_map *map, = int idx) +static inline struct perf_cpu perf_env__get_cpu(void *data, struct perf_cp= u_map *map, int idx) { struct perf_env *env =3D data; - int cpu; + struct perf_cpu cpu =3D perf_cpu_map__cpu(map, idx); =20 - if (idx > map->nr) - return -1; - - cpu =3D map->map[idx]; - - if (cpu >=3D env->nr_cpus_avail) - return -1; + if (cpu.cpu >=3D env->nr_cpus_avail) + cpu.cpu =3D -1; =20 return cpu; } =20 -static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(int cpu, void *= data) +static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(struct perf_cpu= cpu, void *data) { struct perf_env *env =3D data; struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 - if (cpu !=3D -1) - id.socket =3D env->cpu[cpu].socket_id; + if (cpu.cpu !=3D -1) + id.socket =3D env->cpu[cpu.cpu].socket_id; =20 return id; } =20 -static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *dat= a) +static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(struct perf_cpu cp= u, void *data) { struct perf_env *env =3D data; struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 - if (cpu !=3D -1) { + if (cpu.cpu !=3D -1) { /* * die_id is relative to socket, so start * with the socket ID and then add die to * make a unique ID. */ - id.socket =3D env->cpu[cpu].socket_id; - id.die =3D env->cpu[cpu].die_id; + id.socket =3D env->cpu[cpu.cpu].socket_id; + id.die =3D env->cpu[cpu.cpu].die_id; } =20 return id; } =20 -static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *da= ta) +static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(struct perf_cpu c= pu, void *data) { struct perf_env *env =3D data; struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 - if (cpu !=3D -1) { + if (cpu.cpu !=3D -1) { /* * core_id is relative to socket and die, * we need a global id. So we set * socket, die id and core id */ - id.socket =3D env->cpu[cpu].socket_id; - id.die =3D env->cpu[cpu].die_id; - id.core =3D env->cpu[cpu].core_id; + id.socket =3D env->cpu[cpu.cpu].socket_id; + id.die =3D env->cpu[cpu.cpu].die_id; + id.core =3D env->cpu[cpu.cpu].core_id; } =20 return id; } =20 -static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *da= ta) +static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(struct perf_cpu c= pu, void *data) { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 @@ -1568,24 +1564,24 @@ static struct aggr_cpu_id perf_env__get_node_aggr_b= y_cpu(int cpu, void *data) } =20 static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_conf= ig *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return perf_env__get_socket_aggr_by_cpu(cpu, &perf_stat.session->header.e= nv); } static struct aggr_cpu_id perf_stat__get_die_file(struct perf_stat_config = *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return perf_env__get_die_aggr_by_cpu(cpu, &perf_stat.session->header.env); } =20 static struct aggr_cpu_id perf_stat__get_core_file(struct perf_stat_config= *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return perf_env__get_core_aggr_by_cpu(cpu, &perf_stat.session->header.env= ); } =20 static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config= *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return perf_env__get_node_aggr_by_cpu(cpu, &perf_stat.session->header.env= ); } diff --git a/tools/perf/tests/attr.c b/tools/perf/tests/attr.c index 0f73e300f207..56fba08a3037 100644 --- a/tools/perf/tests/attr.c +++ b/tools/perf/tests/attr.c @@ -65,7 +65,7 @@ do { \ =20 #define WRITE_ASS(field, fmt) __WRITE_ASS(field, fmt, attr->field) =20 -static int store_event(struct perf_event_attr *attr, pid_t pid, int cpu, +static int store_event(struct perf_event_attr *attr, pid_t pid, struct per= f_cpu cpu, int fd, int group_fd, unsigned long flags) { FILE *file; @@ -93,7 +93,7 @@ static int store_event(struct perf_event_attr *attr, pid_= t pid, int cpu, /* syscall arguments */ __WRITE_ASS(fd, "d", fd); __WRITE_ASS(group_fd, "d", group_fd); - __WRITE_ASS(cpu, "d", cpu); + __WRITE_ASS(cpu, "d", cpu.cpu); __WRITE_ASS(pid, "d", pid); __WRITE_ASS(flags, "lu", flags); =20 @@ -144,7 +144,7 @@ static int store_event(struct perf_event_attr *attr, pi= d_t pid, int cpu, return 0; } =20 -void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, +void test_attr__open(struct perf_event_attr *attr, pid_t pid, struct perf_= cpu cpu, int fd, int group_fd, unsigned long flags) { int errno_saved =3D errno; diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c index 384856347236..0bf399c49849 100644 --- a/tools/perf/tests/bitmap.c +++ b/tools/perf/tests/bitmap.c @@ -18,7 +18,7 @@ static unsigned long *get_bitmap(const char *str, int nbi= ts) =20 if (map && bm) { for (i =3D 0; i < map->nr; i++) - set_bit(map->map[i], bm); + set_bit(map->map[i].cpu, bm); } =20 if (map) diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 89a155092f85..84e87e31f119 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -38,7 +38,7 @@ static int process_event_mask(struct perf_tool *tool __ma= ybe_unused, TEST_ASSERT_VAL("wrong nr", map->nr =3D=3D 20); =20 for (i =3D 0; i < 20; i++) { - TEST_ASSERT_VAL("wrong cpu", map->map[i] =3D=3D i); + TEST_ASSERT_VAL("wrong cpu", map->map[i].cpu =3D=3D i); } =20 perf_cpu_map__put(map); @@ -67,8 +67,8 @@ static int process_event_cpus(struct perf_tool *tool __ma= ybe_unused, =20 map =3D cpu_map__new_data(data); TEST_ASSERT_VAL("wrong nr", map->nr =3D=3D 2); - TEST_ASSERT_VAL("wrong cpu", map->map[0] =3D=3D 1); - TEST_ASSERT_VAL("wrong cpu", map->map[1] =3D=3D 256); + TEST_ASSERT_VAL("wrong cpu", map->map[0].cpu =3D=3D 1); + TEST_ASSERT_VAL("wrong cpu", map->map[1].cpu =3D=3D 256); TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) =3D=3D 1); perf_cpu_map__put(map); return 0; diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_updat= e.c index d01532d40acb..16b6d6f47f38 100644 --- a/tools/perf/tests/event_update.c +++ b/tools/perf/tests/event_update.c @@ -76,9 +76,9 @@ static int process_event_cpus(struct perf_tool *tool __ma= ybe_unused, TEST_ASSERT_VAL("wrong id", ev->id =3D=3D 123); TEST_ASSERT_VAL("wrong type", ev->type =3D=3D PERF_EVENT_UPDATE__CPUS); TEST_ASSERT_VAL("wrong cpus", map->nr =3D=3D 3); - TEST_ASSERT_VAL("wrong cpus", map->map[0] =3D=3D 1); - TEST_ASSERT_VAL("wrong cpus", map->map[1] =3D=3D 2); - TEST_ASSERT_VAL("wrong cpus", map->map[2] =3D=3D 3); + TEST_ASSERT_VAL("wrong cpus", map->map[0].cpu =3D=3D 1); + TEST_ASSERT_VAL("wrong cpus", map->map[1].cpu =3D=3D 2); + TEST_ASSERT_VAL("wrong cpus", map->map[2].cpu =3D=3D 3); perf_cpu_map__put(map); return 0; } diff --git a/tools/perf/tests/mem2node.c b/tools/perf/tests/mem2node.c index b17b86391383..f4a4aba33f76 100644 --- a/tools/perf/tests/mem2node.c +++ b/tools/perf/tests/mem2node.c @@ -31,7 +31,7 @@ static unsigned long *get_bitmap(const char *str, int nbi= ts) =20 if (map && bm) { for (i =3D 0; i < map->nr; i++) { - set_bit(map->map[i], bm); + set_bit(map->map[i].cpu, bm); } } =20 diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c index 90b2feda31ac..0ad62914b4d7 100644 --- a/tools/perf/tests/mmap-basic.c +++ b/tools/perf/tests/mmap-basic.c @@ -59,11 +59,11 @@ static int test__basic_mmap(struct test_suite *test __m= aybe_unused, int subtest } =20 CPU_ZERO(&cpu_set); - CPU_SET(cpus->map[0], &cpu_set); + CPU_SET(cpus->map[0].cpu, &cpu_set); sched_setaffinity(0, sizeof(cpu_set), &cpu_set); if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { pr_debug("sched_setaffinity() failed on CPU %d: %s ", - cpus->map[0], str_error_r(errno, sbuf, sizeof(sbuf))); + cpus->map[0].cpu, str_error_r(errno, sbuf, sizeof(sbuf))); goto out_free_cpus; } =20 diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/= openat-syscall-all-cpus.c index ca0a50e92839..1ab362323d25 100644 --- a/tools/perf/tests/openat-syscall-all-cpus.c +++ b/tools/perf/tests/openat-syscall-all-cpus.c @@ -22,7 +22,8 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test = __maybe_unused, int subtest __maybe_unused) { - int err =3D -1, fd, idx, cpu; + int err =3D -1, fd, idx; + struct perf_cpu cpu; struct perf_cpu_map *cpus; struct evsel *evsel; unsigned int nr_openat_calls =3D 111, i; @@ -66,15 +67,15 @@ static int test__openat_syscall_event_on_all_cpus(struc= t test_suite *test __mayb * without CPU_ALLOC. 1024 cpus in 2010 still seems * a reasonable upper limit tho :-) */ - if (cpu >=3D CPU_SETSIZE) { - pr_debug("Ignoring CPU %d\n", cpu); + if (cpu.cpu >=3D CPU_SETSIZE) { + pr_debug("Ignoring CPU %d\n", cpu.cpu); continue; } =20 - CPU_SET(cpu, &cpu_set); + CPU_SET(cpu.cpu, &cpu_set); if (sched_setaffinity(0, sizeof(cpu_set), &cpu_set) < 0) { pr_debug("sched_setaffinity() failed on CPU %d: %s ", - cpu, + cpu.cpu, str_error_r(errno, sbuf, sizeof(sbuf))); goto out_close_fd; } @@ -82,7 +83,7 @@ static int test__openat_syscall_event_on_all_cpus(struct = test_suite *test __mayb fd =3D openat(0, "/etc/passwd", O_RDONLY); close(fd); } - CPU_CLR(cpu, &cpu_set); + CPU_CLR(cpu.cpu, &cpu_set); } =20 evsel->core.cpus =3D perf_cpu_map__get(cpus); @@ -92,7 +93,7 @@ static int test__openat_syscall_event_on_all_cpus(struct = test_suite *test __mayb perf_cpu_map__for_each_cpu(cpu, idx, cpus) { unsigned int expected; =20 - if (cpu >=3D CPU_SETSIZE) + if (cpu.cpu >=3D CPU_SETSIZE) continue; =20 if (evsel__read_on_cpu(evsel, idx, 0) < 0) { @@ -104,7 +105,7 @@ static int test__openat_syscall_event_on_all_cpus(struc= t test_suite *test __mayb expected =3D nr_openat_calls + idx; if (perf_counts(evsel->counts, idx, 0)->val !=3D expected) { pr_debug("evsel__read_on_cpu: expected to intercept %d calls on cpu %d,= got %" PRIu64 "\n", - expected, cpu, perf_counts(evsel->counts, idx, 0)->val); + expected, cpu.cpu, perf_counts(evsel->counts, idx, 0)->val); err =3D -1; } } diff --git a/tools/perf/tests/stat.c b/tools/perf/tests/stat.c index 2eb096b5e6da..500974040fe3 100644 --- a/tools/perf/tests/stat.c +++ b/tools/perf/tests/stat.c @@ -87,7 +87,8 @@ static int test__synthesize_stat(struct test_suite *test = __maybe_unused, int sub count.run =3D 300; =20 TEST_ASSERT_VAL("failed to synthesize stat_config", - !perf_event__synthesize_stat(NULL, 1, 2, 3, &count, process_stat_event, = NULL)); + !perf_event__synthesize_stat(NULL, (struct perf_cpu){.cpu =3D 1}, 2, 3, + &count, process_stat_event, NULL)); =20 return 0; } diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 33e4cb81265c..c4ef0c7002f1 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -112,7 +112,9 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu= ); =20 for (i =3D 0; i < session->header.env.nr_cpus_avail; i++) { - if (!perf_cpu_map__has(map, i)) + struct perf_cpu cpu =3D { .cpu =3D i }; + + if (!perf_cpu_map__has(map, cpu)) continue; pr_debug("CPU %d, core %d, socket %d\n", i, session->header.env.cpu[i].core_id, @@ -122,15 +124,15 @@ static int check_cpu_topology(char *path, struct perf= _cpu_map *map) // Test that CPU ID contains socket, die, core and CPU for (i =3D 0; i < map->nr; i++) { id =3D aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL); - TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", map->map[i] =3D=3D id.= cpu); + TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", map->map[i].cpu =3D=3D= id.cpu.cpu); =20 TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", - session->header.env.cpu[map->map[i]].core_id =3D=3D id.core); + session->header.env.cpu[map->map[i].cpu].core_id =3D=3D id.core); TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match", - session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", - session->header.env.cpu[map->map[i]].die_id =3D=3D id.die); + session->header.env.cpu[map->map[i].cpu].die_id =3D=3D id.die); TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Cpu map - Thread is set", id.thread =3D=3D -1); } @@ -139,13 +141,13 @@ static int check_cpu_topology(char *path, struct perf= _cpu_map *map) for (i =3D 0; i < map->nr; i++) { id =3D aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Core map - Core ID doesn't match", - session->header.env.cpu[map->map[i]].core_id =3D=3D id.core); + session->header.env.cpu[map->map[i].cpu].core_id =3D=3D id.core); =20 TEST_ASSERT_VAL("Core map - Socket ID doesn't match", - session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Core map - Die ID doesn't match", - session->header.env.cpu[map->map[i]].die_id =3D=3D id.die); + session->header.env.cpu[map->map[i].cpu].die_id =3D=3D id.die); TEST_ASSERT_VAL("Core map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Core map - Thread is set", id.thread =3D=3D -1); } @@ -154,14 +156,14 @@ static int check_cpu_topology(char *path, struct perf= _cpu_map *map) for (i =3D 0; i < map->nr; i++) { id =3D aggr_cpu_id__die(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Die map - Socket ID doesn't match", - session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Die map - Die ID doesn't match", - session->header.env.cpu[map->map[i]].die_id =3D=3D id.die); + session->header.env.cpu[map->map[i].cpu].die_id =3D=3D id.die); =20 TEST_ASSERT_VAL("Die map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Die map - Core is set", id.core =3D=3D -1); - TEST_ASSERT_VAL("Die map - CPU is set", id.cpu =3D=3D -1); + TEST_ASSERT_VAL("Die map - CPU is set", id.cpu.cpu =3D=3D -1); TEST_ASSERT_VAL("Die map - Thread is set", id.thread =3D=3D -1); } =20 @@ -169,12 +171,12 @@ static int check_cpu_topology(char *path, struct perf= _cpu_map *map) for (i =3D 0; i < map->nr; i++) { id =3D aggr_cpu_id__socket(perf_cpu_map__cpu(map, i), NULL); TEST_ASSERT_VAL("Socket map - Socket ID doesn't match", - session->header.env.cpu[map->map[i]].socket_id =3D=3D id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Socket map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Socket map - Die ID is set", id.die =3D=3D -1); TEST_ASSERT_VAL("Socket map - Core is set", id.core =3D=3D -1); - TEST_ASSERT_VAL("Socket map - CPU is set", id.cpu =3D=3D -1); + TEST_ASSERT_VAL("Socket map - CPU is set", id.cpu.cpu =3D=3D -1); TEST_ASSERT_VAL("Socket map - Thread is set", id.thread =3D=3D -1); } =20 @@ -186,7 +188,7 @@ static int check_cpu_topology(char *path, struct perf_c= pu_map *map) TEST_ASSERT_VAL("Node map - Socket is set", id.socket =3D=3D -1); TEST_ASSERT_VAL("Node map - Die ID is set", id.die =3D=3D -1); TEST_ASSERT_VAL("Node map - Core is set", id.core =3D=3D -1); - TEST_ASSERT_VAL("Node map - CPU is set", id.cpu =3D=3D -1); + TEST_ASSERT_VAL("Node map - CPU is set", id.cpu.cpu =3D=3D -1); TEST_ASSERT_VAL("Node map - Thread is set", id.thread =3D=3D -1); } perf_session__delete(session); diff --git a/tools/perf/util/affinity.c b/tools/perf/util/affinity.c index 7b12bd7a3080..f1e30d566db3 100644 --- a/tools/perf/util/affinity.c +++ b/tools/perf/util/affinity.c @@ -11,7 +11,7 @@ =20 static int get_cpu_set_size(void) { - int sz =3D cpu__max_cpu() + 8 - 1; + int sz =3D cpu__max_cpu().cpu + 8 - 1; /* * sched_getaffinity doesn't like masks smaller than the kernel. * Hopefully that's big enough. diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index c679394b898d..5632efc44738 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -123,7 +123,7 @@ int auxtrace_mmap__mmap(struct auxtrace_mmap *mm, mm->prev =3D 0; mm->idx =3D mp->idx; mm->tid =3D mp->tid; - mm->cpu =3D mp->cpu; + mm->cpu =3D mp->cpu.cpu; =20 if (!mp->len) { mm->base =3D NULL; @@ -180,7 +180,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap= _params *mp, else mp->tid =3D -1; } else { - mp->cpu =3D -1; + mp->cpu.cpu =3D -1; mp->tid =3D perf_thread_map__pid(evlist->core.threads, idx); } } @@ -292,7 +292,7 @@ static int auxtrace_queues__queue_buffer(struct auxtrac= e_queues *queues, if (!queue->set) { queue->set =3D true; queue->tid =3D buffer->tid; - queue->cpu =3D buffer->cpu; + queue->cpu =3D buffer->cpu.cpu; } =20 buffer->buffer_nr =3D queues->next_buffer_nr++; @@ -339,11 +339,11 @@ static int auxtrace_queues__split_buffer(struct auxtr= ace_queues *queues, return 0; } =20 -static bool filter_cpu(struct perf_session *session, int cpu) +static bool filter_cpu(struct perf_session *session, struct perf_cpu cpu) { unsigned long *cpu_bitmap =3D session->itrace_synth_opts->cpu_bitmap; =20 - return cpu_bitmap && cpu !=3D -1 && !test_bit(cpu, cpu_bitmap); + return cpu_bitmap && cpu.cpu !=3D -1 && !test_bit(cpu.cpu, cpu_bitmap); } =20 static int auxtrace_queues__add_buffer(struct auxtrace_queues *queues, @@ -399,7 +399,7 @@ int auxtrace_queues__add_event(struct auxtrace_queues *= queues, struct auxtrace_buffer buffer =3D { .pid =3D -1, .tid =3D event->auxtrace.tid, - .cpu =3D event->auxtrace.cpu, + .cpu =3D { event->auxtrace.cpu }, .data_offset =3D data_offset, .offset =3D event->auxtrace.offset, .reference =3D event->auxtrace.reference, diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index bbf0d78c6401..19910b9011f3 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include =20 @@ -240,7 +241,7 @@ struct auxtrace_buffer { size_t size; pid_t pid; pid_t tid; - int cpu; + struct perf_cpu cpu; void *data; off_t data_offset; void *mmap_addr; @@ -350,7 +351,7 @@ struct auxtrace_mmap_params { int prot; int idx; pid_t tid; - int cpu; + struct perf_cpu cpu; }; =20 /** diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index a535fd360d46..d644eaa7cb87 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -13,8 +13,8 @@ #include #include =20 -static int max_cpu_num; -static int max_present_cpu_num; +static struct perf_cpu max_cpu_num; +static struct perf_cpu max_present_cpu_num; static int max_node_num; /** * The numa node X as read from /sys/devices/system/node/nodeX indexed by = the @@ -37,9 +37,9 @@ static struct perf_cpu_map *cpu_map__from_entries(struct = cpu_map_entries *cpus) * otherwise it would become 65535. */ if (cpus->cpu[i] =3D=3D (u16) -1) - map->map[i] =3D -1; + map->map[i].cpu =3D -1; else - map->map[i] =3D (int) cpus->cpu[i]; + map->map[i].cpu =3D (int) cpus->cpu[i]; } } =20 @@ -58,7 +58,7 @@ static struct perf_cpu_map *cpu_map__from_mask(struct per= f_record_record_cpu_map int cpu, i =3D 0; =20 for_each_set_bit(cpu, mask->mask, nbits) - map->map[i++] =3D cpu; + map->map[i++].cpu =3D cpu; } return map; =20 @@ -91,7 +91,7 @@ struct perf_cpu_map *perf_cpu_map__empty_new(int nr) =20 cpus->nr =3D nr; for (i =3D 0; i < nr; i++) - cpus->map[i] =3D -1; + cpus->map[i].cpu =3D -1; =20 refcount_set(&cpus->refcnt, 1); } @@ -126,13 +126,13 @@ static int cpu__get_topology_int(int cpu, const char = *name, int *value) return sysfs__read_int(path, value); } =20 -int cpu__get_socket_id(int cpu) +int cpu__get_socket_id(struct perf_cpu cpu) { - int value, ret =3D cpu__get_topology_int(cpu, "physical_package_id", &val= ue); + int value, ret =3D cpu__get_topology_int(cpu.cpu, "physical_package_id", = &value); return ret ?: value; } =20 -struct aggr_cpu_id aggr_cpu_id__socket(int cpu, void *data __maybe_unused) +struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data __m= aybe_unused) { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 @@ -161,7 +161,8 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct per= f_cpu_map *cpus, aggr_cpu_id_get_t f, void *data) { - int cpu, idx; + int idx; + struct perf_cpu cpu; struct cpu_aggr_map *c =3D cpu_aggr_map__empty_new(cpus->nr); =20 if (!c) @@ -198,14 +199,14 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct p= erf_cpu_map *cpus, =20 } =20 -int cpu__get_die_id(int cpu) +int cpu__get_die_id(struct perf_cpu cpu) { - int value, ret =3D cpu__get_topology_int(cpu, "die_id", &value); + int value, ret =3D cpu__get_topology_int(cpu.cpu, "die_id", &value); =20 return ret ?: value; } =20 -struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data) +struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data) { struct aggr_cpu_id id; int die; @@ -228,13 +229,13 @@ struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *da= ta) return id; } =20 -int cpu__get_core_id(int cpu) +int cpu__get_core_id(struct perf_cpu cpu) { - int value, ret =3D cpu__get_topology_int(cpu, "core_id", &value); + int value, ret =3D cpu__get_topology_int(cpu.cpu, "core_id", &value); return ret ?: value; } =20 -struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data) +struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data) { struct aggr_cpu_id id; int core =3D cpu__get_core_id(cpu); @@ -253,7 +254,7 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *dat= a) =20 } =20 -struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data) +struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data) { struct aggr_cpu_id id; =20 @@ -267,7 +268,7 @@ struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data) =20 } =20 -struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data __maybe_unused) +struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data __may= be_unused) { struct aggr_cpu_id id =3D aggr_cpu_id__empty(); =20 @@ -315,8 +316,8 @@ static void set_max_cpu_num(void) int ret =3D -1; =20 /* set up default */ - max_cpu_num =3D 4096; - max_present_cpu_num =3D 4096; + max_cpu_num.cpu =3D 4096; + max_present_cpu_num.cpu =3D 4096; =20 mnt =3D sysfs__mountpoint(); if (!mnt) @@ -329,7 +330,7 @@ static void set_max_cpu_num(void) goto out; } =20 - ret =3D get_max_num(path, &max_cpu_num); + ret =3D get_max_num(path, &max_cpu_num.cpu); if (ret) goto out; =20 @@ -340,11 +341,11 @@ static void set_max_cpu_num(void) goto out; } =20 - ret =3D get_max_num(path, &max_present_cpu_num); + ret =3D get_max_num(path, &max_present_cpu_num.cpu); =20 out: if (ret) - pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num); + pr_err("Failed to read max cpus, using default of %d\n", max_cpu_num.cpu= ); } =20 /* Determine highest possible node in the system for sparse allocation */ @@ -383,31 +384,31 @@ int cpu__max_node(void) return max_node_num; } =20 -int cpu__max_cpu(void) +struct perf_cpu cpu__max_cpu(void) { - if (unlikely(!max_cpu_num)) + if (unlikely(!max_cpu_num.cpu)) set_max_cpu_num(); =20 return max_cpu_num; } =20 -int cpu__max_present_cpu(void) +struct perf_cpu cpu__max_present_cpu(void) { - if (unlikely(!max_present_cpu_num)) + if (unlikely(!max_present_cpu_num.cpu)) set_max_cpu_num(); =20 return max_present_cpu_num; } =20 =20 -int cpu__get_node(int cpu) +int cpu__get_node(struct perf_cpu cpu) { if (unlikely(cpunode_map =3D=3D NULL)) { pr_debug("cpu_map not initialized\n"); return -1; } =20 - return cpunode_map[cpu]; + return cpunode_map[cpu.cpu]; } =20 static int init_cpunode_map(void) @@ -417,13 +418,13 @@ static int init_cpunode_map(void) set_max_cpu_num(); set_max_node_num(); =20 - cpunode_map =3D calloc(max_cpu_num, sizeof(int)); + cpunode_map =3D calloc(max_cpu_num.cpu, sizeof(int)); if (!cpunode_map) { pr_err("%s: calloc failed\n", __func__); return -1; } =20 - for (i =3D 0; i < max_cpu_num; i++) + for (i =3D 0; i < max_cpu_num.cpu; i++) cpunode_map[i] =3D -1; =20 return 0; @@ -484,35 +485,37 @@ int cpu__setup_cpunode_map(void) =20 size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) { - int i, cpu, start =3D -1; + int i, start =3D -1; bool first =3D true; size_t ret =3D 0; =20 #define COMMA first ? "" : "," =20 for (i =3D 0; i < map->nr + 1; i++) { + struct perf_cpu cpu =3D { .cpu =3D INT_MAX }; bool last =3D i =3D=3D map->nr; =20 - cpu =3D last ? INT_MAX : map->map[i]; + if (!last) + cpu =3D map->map[i]; =20 if (start =3D=3D -1) { start =3D i; if (last) { ret +=3D snprintf(buf + ret, size - ret, "%s%d", COMMA, - map->map[i]); + map->map[i].cpu); } - } else if (((i - start) !=3D (cpu - map->map[start])) || last) { + } else if (((i - start) !=3D (cpu.cpu - map->map[start].cpu)) || last) { int end =3D i - 1; =20 if (start =3D=3D end) { ret +=3D snprintf(buf + ret, size - ret, "%s%d", COMMA, - map->map[start]); + map->map[start].cpu); } else { ret +=3D snprintf(buf + ret, size - ret, "%s%d-%d", COMMA, - map->map[start], map->map[end]); + map->map[start].cpu, map->map[end].cpu); } first =3D false; start =3D i; @@ -539,23 +542,23 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map= , char *buf, size_t size) int i, cpu; char *ptr =3D buf; unsigned char *bitmap; - int last_cpu =3D perf_cpu_map__cpu(map, map->nr - 1); + struct perf_cpu last_cpu =3D perf_cpu_map__cpu(map, map->nr - 1); =20 if (buf =3D=3D NULL) return 0; =20 - bitmap =3D zalloc(last_cpu / 8 + 1); + bitmap =3D zalloc(last_cpu.cpu / 8 + 1); if (bitmap =3D=3D NULL) { buf[0] =3D '\0'; return 0; } =20 for (i =3D 0; i < map->nr; i++) { - cpu =3D perf_cpu_map__cpu(map, i); + cpu =3D perf_cpu_map__cpu(map, i).cpu; bitmap[cpu / 8] |=3D 1 << (cpu % 8); } =20 - for (cpu =3D last_cpu / 4 * 4; cpu >=3D 0; cpu -=3D 4) { + for (cpu =3D last_cpu.cpu / 4 * 4; cpu >=3D 0; cpu -=3D 4) { unsigned char bits =3D bitmap[cpu / 8]; =20 if (cpu % 8) @@ -591,7 +594,7 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, co= nst struct aggr_cpu_id *b a->socket =3D=3D b->socket && a->die =3D=3D b->die && a->core =3D=3D b->core && - a->cpu =3D=3D b->cpu; + a->cpu.cpu =3D=3D b->cpu.cpu; } =20 bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) @@ -601,7 +604,7 @@ bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) a->socket =3D=3D -1 && a->die =3D=3D -1 && a->core =3D=3D -1 && - a->cpu =3D=3D -1; + a->cpu.cpu =3D=3D -1; } =20 struct aggr_cpu_id aggr_cpu_id__empty(void) @@ -612,7 +615,7 @@ struct aggr_cpu_id aggr_cpu_id__empty(void) .socket =3D -1, .die =3D -1, .core =3D -1, - .cpu =3D -1 + .cpu =3D (struct perf_cpu){ .cpu =3D -1 }, }; return ret; } diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 651c6417d3c3..6eedf3d57df5 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -23,7 +23,7 @@ struct aggr_cpu_id { /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_i= d. */ int core; /** CPU aggregation, note there is one CPU for each SMT thread. */ - int cpu; + struct perf_cpu cpu; }; =20 /** A collection of aggr_cpu_id values, the "built" version is sorted and = uniqued. */ @@ -48,28 +48,28 @@ const struct perf_cpu_map *cpu_map__online(void); /* th= read unsafe */ int cpu__setup_cpunode_map(void); =20 int cpu__max_node(void); -int cpu__max_cpu(void); -int cpu__max_present_cpu(void); +struct perf_cpu cpu__max_cpu(void); +struct perf_cpu cpu__max_present_cpu(void); /** * cpu__get_node - Returns the numa node X as read from * /sys/devices/system/node/nodeX for the given CPU. */ -int cpu__get_node(int cpu); +int cpu__get_node(struct perf_cpu cpu); /** * cpu__get_socket_id - Returns the socket number as read from * /sys/devices/system/cpu/cpuX/topology/physical_package_id for the given= CPU. */ -int cpu__get_socket_id(int cpu); +int cpu__get_socket_id(struct perf_cpu cpu); /** * cpu__get_die_id - Returns the die id as read from * /sys/devices/system/cpu/cpuX/topology/die_id for the given CPU. */ -int cpu__get_die_id(int cpu); +int cpu__get_die_id(struct perf_cpu cpu); /** * cpu__get_core_id - Returns the core id as read from * /sys/devices/system/cpu/cpuX/topology/core_id for the given CPU. */ -int cpu__get_core_id(int cpu); +int cpu__get_core_id(struct perf_cpu cpu); =20 /** * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every e= ntry @@ -77,7 +77,7 @@ int cpu__get_core_id(int cpu); */ struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr); =20 -typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(int cpu, void *data); +typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void = *data); =20 /** * cpu_aggr_map__new - Create a cpu_aggr_map with an aggr_cpu_id for each = cpu in @@ -98,29 +98,29 @@ struct aggr_cpu_id aggr_cpu_id__empty(void); * the socket for cpu. The function signature is compatible with * aggr_cpu_id_get_t. */ -struct aggr_cpu_id aggr_cpu_id__socket(int cpu, void *data); +struct aggr_cpu_id aggr_cpu_id__socket(struct perf_cpu cpu, void *data); /** * aggr_cpu_id__die - Create an aggr_cpu_id with the die and socket popula= ted * with the die and socket for cpu. The function signature is compatible w= ith * aggr_cpu_id_get_t. */ -struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data); +struct aggr_cpu_id aggr_cpu_id__die(struct perf_cpu cpu, void *data); /** * aggr_cpu_id__core - Create an aggr_cpu_id with the core, die and socket * populated with the core, die and socket for cpu. The function signature= is * compatible with aggr_cpu_id_get_t. */ -struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data); +struct aggr_cpu_id aggr_cpu_id__core(struct perf_cpu cpu, void *data); /** * aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and s= ocket * populated with the cpu, core, die and socket for cpu. The function sign= ature * is compatible with aggr_cpu_id_get_t. */ -struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data); +struct aggr_cpu_id aggr_cpu_id__cpu(struct perf_cpu cpu, void *data); /** * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated = for * cpu. The function signature is compatible with aggr_cpu_id_get_t. */ -struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data); +struct aggr_cpu_id aggr_cpu_id__node(struct perf_cpu cpu, void *data); =20 #endif /* __PERF_CPUMAP_H */ diff --git a/tools/perf/util/cputopo.c b/tools/perf/util/cputopo.c index 8affb37d90e7..84ca106a3246 100644 --- a/tools/perf/util/cputopo.c +++ b/tools/perf/util/cputopo.c @@ -187,7 +187,7 @@ struct cpu_topology *cpu_topology__new(void) struct perf_cpu_map *map; bool has_die =3D has_die_topology(); =20 - ncpus =3D cpu__max_present_cpu(); + ncpus =3D cpu__max_present_cpu().cpu; =20 /* build online CPU map */ map =3D perf_cpu_map__new(NULL); @@ -218,7 +218,7 @@ struct cpu_topology *cpu_topology__new(void) tp->core_cpus_list =3D addr; =20 for (i =3D 0; i < nr; i++) { - if (!perf_cpu_map__has(map, i)) + if (!perf_cpu_map__has(map, (struct perf_cpu){ .cpu =3D i })) continue; =20 ret =3D build_cpu_topology(tp, i); @@ -333,7 +333,7 @@ struct numa_topology *numa_topology__new(void) tp->nr =3D nr; =20 for (i =3D 0; i < nr; i++) { - if (load_numa_node(&tp->nodes[i], node_map->map[i])) { + if (load_numa_node(&tp->nodes[i], node_map->map[i].cpu)) { numa_topology__delete(tp); tp =3D NULL; break; diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c index fd12c0dcaefb..579e44c59914 100644 --- a/tools/perf/util/env.c +++ b/tools/perf/util/env.c @@ -285,13 +285,13 @@ int perf_env__set_cmdline(struct perf_env *env, int a= rgc, const char *argv[]) =20 int perf_env__read_cpu_topology_map(struct perf_env *env) { - int cpu, nr_cpus; + int idx, nr_cpus; =20 if (env->cpu !=3D NULL) return 0; =20 if (env->nr_cpus_avail =3D=3D 0) - env->nr_cpus_avail =3D cpu__max_present_cpu(); + env->nr_cpus_avail =3D cpu__max_present_cpu().cpu; =20 nr_cpus =3D env->nr_cpus_avail; if (nr_cpus =3D=3D -1) @@ -301,10 +301,12 @@ int perf_env__read_cpu_topology_map(struct perf_env *= env) if (env->cpu =3D=3D NULL) return -ENOMEM; =20 - for (cpu =3D 0; cpu < nr_cpus; ++cpu) { - env->cpu[cpu].core_id =3D cpu__get_core_id(cpu); - env->cpu[cpu].socket_id =3D cpu__get_socket_id(cpu); - env->cpu[cpu].die_id =3D cpu__get_die_id(cpu); + for (idx =3D 0; idx < nr_cpus; ++idx) { + struct perf_cpu cpu =3D { .cpu =3D idx }; + + env->cpu[idx].core_id =3D cpu__get_core_id(cpu); + env->cpu[idx].socket_id =3D cpu__get_socket_id(cpu); + env->cpu[idx].die_id =3D cpu__get_die_id(cpu); } =20 env->nr_cpus_avail =3D nr_cpus; @@ -381,7 +383,7 @@ static int perf_env__read_arch(struct perf_env *env) static int perf_env__read_nr_cpus_avail(struct perf_env *env) { if (env->nr_cpus_avail =3D=3D 0) - env->nr_cpus_avail =3D cpu__max_present_cpu(); + env->nr_cpus_avail =3D cpu__max_present_cpu().cpu; =20 return env->nr_cpus_avail ? 0 : -ENOENT; } @@ -487,7 +489,7 @@ const char *perf_env__pmu_mappings(struct perf_env *env) return env->pmu_mappings; } =20 -int perf_env__numa_node(struct perf_env *env, int cpu) +int perf_env__numa_node(struct perf_env *env, struct perf_cpu cpu) { if (!env->nr_numa_map) { struct numa_node *nn; @@ -495,7 +497,7 @@ int perf_env__numa_node(struct perf_env *env, int cpu) =20 for (i =3D 0; i < env->nr_numa_nodes; i++) { nn =3D &env->numa_nodes[i]; - nr =3D max(nr, perf_cpu_map__max(nn->map)); + nr =3D max(nr, perf_cpu_map__max(nn->map).cpu); } =20 nr++; @@ -514,13 +516,14 @@ int perf_env__numa_node(struct perf_env *env, int cpu) env->nr_numa_map =3D nr; =20 for (i =3D 0; i < env->nr_numa_nodes; i++) { - int tmp, j; + struct perf_cpu tmp; + int j; =20 nn =3D &env->numa_nodes[i]; - perf_cpu_map__for_each_cpu(j, tmp, nn->map) - env->numa_map[j] =3D i; + perf_cpu_map__for_each_cpu(tmp, j, nn->map) + env->numa_map[tmp.cpu] =3D i; } } =20 - return cpu >=3D 0 && cpu < env->nr_numa_map ? env->numa_map[cpu] : -1; + return cpu.cpu >=3D 0 && cpu.cpu < env->nr_numa_map ? env->numa_map[cpu.c= pu] : -1; } diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h index 163e5ec503a2..a3541f98e1fc 100644 --- a/tools/perf/util/env.h +++ b/tools/perf/util/env.h @@ -4,6 +4,7 @@ =20 #include #include +#include "cpumap.h" #include "rwsem.h" =20 struct perf_cpu_map; @@ -170,5 +171,5 @@ struct bpf_prog_info_node *perf_env__find_bpf_prog_info= (struct perf_env *env, bool perf_env__insert_btf(struct perf_env *env, struct btf_node *btf_node); struct btf_node *perf_env__find_btf(struct perf_env *env, __u32 btf_id); =20 -int perf_env__numa_node(struct perf_env *env, int cpu); +int perf_env__numa_node(struct perf_env *env, struct perf_cpu cpu); #endif /* __PERF_ENV_H */ diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 39d294f6c321..11eb95b2106b 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -350,13 +350,13 @@ struct evlist_cpu_iterator evlist__cpu_begin(struct e= vlist *evlist, struct affin .cpu_map_idx =3D 0, .evlist_cpu_map_idx =3D 0, .evlist_cpu_map_nr =3D perf_cpu_map__nr(evlist->core.all_cpus), - .cpu =3D -1, + .cpu =3D (struct perf_cpu){ .cpu =3D -1}, .affinity =3D affinity, }; =20 if (itr.affinity) { itr.cpu =3D perf_cpu_map__cpu(evlist->core.all_cpus, 0); - affinity__set(itr.affinity, itr.cpu); + affinity__set(itr.affinity, itr.cpu.cpu); itr.cpu_map_idx =3D perf_cpu_map__idx(itr.evsel->core.cpus, itr.cpu); /* * If this CPU isn't in the evsel's cpu map then advance through @@ -385,7 +385,7 @@ void evlist_cpu_iterator__next(struct evlist_cpu_iterat= or *evlist_cpu_itr) perf_cpu_map__cpu(evlist_cpu_itr->container->core.all_cpus, evlist_cpu_itr->evlist_cpu_map_idx); if (evlist_cpu_itr->affinity) - affinity__set(evlist_cpu_itr->affinity, evlist_cpu_itr->cpu); + affinity__set(evlist_cpu_itr->affinity, evlist_cpu_itr->cpu.cpu); evlist_cpu_itr->cpu_map_idx =3D perf_cpu_map__idx(evlist_cpu_itr->evsel->core.cpus, evlist_cpu_itr->cpu); @@ -819,7 +819,7 @@ perf_evlist__mmap_cb_get(struct perf_evlist *_evlist, b= ool overwrite, int idx) =20 static int perf_evlist__mmap_cb_mmap(struct perf_mmap *_map, struct perf_mmap_param *= _mp, - int output, int cpu) + int output, struct perf_cpu cpu) { struct mmap *map =3D container_of(_map, struct mmap, core); struct mmap_params *mp =3D container_of(_mp, struct mmap_params, core); diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index 57828ebfcb61..64cba56fbc74 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -344,7 +344,7 @@ struct evlist_cpu_iterator { /** The number of CPU map entries in evlist->core.all_cpus. */ int evlist_cpu_map_nr; /** The current CPU of the iterator. */ - int cpu; + struct perf_cpu cpu; /** If present, used to set the affinity when switching between CPUs. */ struct affinity *affinity; }; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 2b18b29a534f..7b806cb462bb 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1594,7 +1594,7 @@ int __evsel__read_on_cpu(struct evsel *evsel, int cpu= _map_idx, int thread, bool static int evsel__match_other_cpu(struct evsel *evsel, struct evsel *other, int cpu_map_idx) { - int cpu; + struct perf_cpu cpu; =20 cpu =3D perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); return perf_cpu_map__idx(other->core.cpus, cpu); @@ -2020,9 +2020,9 @@ static int evsel__open_cpu(struct evsel *evsel, struc= t perf_cpu_map *cpus, test_attr__ready(); =20 pr_debug2_peo("sys_perf_event_open: pid %d cpu %d group_fd %d flags = %#lx", - pid, cpus->map[idx], group_fd, evsel->open_flags); + pid, cpus->map[idx].cpu, group_fd, evsel->open_flags); =20 - fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpus->map[idx], + fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpus->map[idx].cpu, group_fd, evsel->open_flags); =20 FD(evsel, idx, thread) =3D fd; diff --git a/tools/perf/util/expr.c b/tools/perf/util/expr.c index 1d532b9fed29..164af5505ed5 100644 --- a/tools/perf/util/expr.c +++ b/tools/perf/util/expr.c @@ -400,7 +400,7 @@ double expr__get_literal(const char *literal) return smt_on() > 0 ? 1.0 : 0.0; =20 if (!strcmp("#num_cpus", literal)) - return cpu__max_present_cpu(); + return cpu__max_present_cpu().cpu; =20 /* * Assume that topology strings are consistent, such as CPUs "0-1" diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index e3c1a532d059..6da12e522edc 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -472,7 +472,7 @@ static int write_nrcpus(struct feat_fd *ff, u32 nrc, nra; int ret; =20 - nrc =3D cpu__max_present_cpu(); + nrc =3D cpu__max_present_cpu().cpu; =20 nr =3D sysconf(_SC_NPROCESSORS_ONLN); if (nr < 0) @@ -1163,7 +1163,7 @@ static int build_caches(struct cpu_cache_level caches= [], u32 *cntp) u32 nr, cpu; u16 level; =20 - nr =3D cpu__max_cpu(); + nr =3D cpu__max_cpu().cpu; =20 for (cpu =3D 0; cpu < nr; cpu++) { for (level =3D 0; level < MAX_CACHE_LVL; level++) { @@ -1195,7 +1195,7 @@ static int build_caches(struct cpu_cache_level caches= [], u32 *cntp) static int write_cache(struct feat_fd *ff, struct evlist *evlist __maybe_unused) { - u32 max_caches =3D cpu__max_cpu() * MAX_CACHE_LVL; + u32 max_caches =3D cpu__max_cpu().cpu * MAX_CACHE_LVL; struct cpu_cache_level caches[max_caches]; u32 cnt =3D 0, i, version =3D 1; int ret; diff --git a/tools/perf/util/mmap.c b/tools/perf/util/mmap.c index 23ecdba9e670..12261ed8c15b 100644 --- a/tools/perf/util/mmap.c +++ b/tools/perf/util/mmap.c @@ -94,7 +94,7 @@ static void perf_mmap__aio_free(struct mmap *map, int idx) } } =20 -static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int aff= inity) +static int perf_mmap__aio_bind(struct mmap *map, int idx, struct perf_cpu = cpu, int affinity) { void *data; size_t mmap_len; @@ -138,7 +138,7 @@ static void perf_mmap__aio_free(struct mmap *map, int i= dx) } =20 static int perf_mmap__aio_bind(struct mmap *map __maybe_unused, int idx __= maybe_unused, - int cpu __maybe_unused, int affinity __maybe_unused) + struct perf_cpu cpu __maybe_unused, int affinity __maybe_unused) { return 0; } @@ -240,7 +240,8 @@ void mmap__munmap(struct mmap *map) =20 static void build_node_mask(int node, struct mmap_cpu_mask *mask) { - int c, cpu, nr_cpus; + int idx, nr_cpus; + struct perf_cpu cpu; const struct perf_cpu_map *cpu_map =3D NULL; =20 cpu_map =3D cpu_map__online(); @@ -248,16 +249,16 @@ static void build_node_mask(int node, struct mmap_cpu= _mask *mask) return; =20 nr_cpus =3D perf_cpu_map__nr(cpu_map); - for (c =3D 0; c < nr_cpus; c++) { - cpu =3D cpu_map->map[c]; /* map c index to online cpu index */ + for (idx =3D 0; idx < nr_cpus; idx++) { + cpu =3D cpu_map->map[idx]; /* map c index to online cpu index */ if (cpu__get_node(cpu) =3D=3D node) - set_bit(cpu, mask->bits); + set_bit(cpu.cpu, mask->bits); } } =20 static int perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_pa= rams *mp) { - map->affinity_mask.nbits =3D cpu__max_cpu(); + map->affinity_mask.nbits =3D cpu__max_cpu().cpu; map->affinity_mask.bits =3D bitmap_zalloc(map->affinity_mask.nbits); if (!map->affinity_mask.bits) return -1; @@ -265,12 +266,12 @@ static int perf_mmap__setup_affinity_mask(struct mmap= *map, struct mmap_params * if (mp->affinity =3D=3D PERF_AFFINITY_NODE && cpu__max_node() > 1) build_node_mask(cpu__get_node(map->core.cpu), &map->affinity_mask); else if (mp->affinity =3D=3D PERF_AFFINITY_CPU) - set_bit(map->core.cpu, map->affinity_mask.bits); + set_bit(map->core.cpu.cpu, map->affinity_mask.bits); =20 return 0; } =20 -int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu) +int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, struct pe= rf_cpu cpu) { if (perf_mmap__mmap(&map->core, &mp->core, fd, cpu)) { pr_debug2("failed to mmap perf event ring buffer, error %d\n", diff --git a/tools/perf/util/mmap.h b/tools/perf/util/mmap.h index 8e259b9610f8..83f6bd4d4082 100644 --- a/tools/perf/util/mmap.h +++ b/tools/perf/util/mmap.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include // for cpu_set_t #ifdef HAVE_AIO_SUPPORT @@ -52,7 +53,7 @@ struct mmap_params { struct auxtrace_mmap_params auxtrace_mp; }; =20 -int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, int cpu); +int mmap__mmap(struct mmap *map, struct mmap_params *mp, int fd, struct pe= rf_cpu cpu); void mmap__munmap(struct mmap *map); =20 union perf_event *perf_mmap__read_forward(struct mmap *map); diff --git a/tools/perf/util/perf_api_probe.c b/tools/perf/util/perf_api_pr= obe.c index 020411682a3c..734d006d9a8c 100644 --- a/tools/perf/util/perf_api_probe.c +++ b/tools/perf/util/perf_api_probe.c @@ -11,7 +11,7 @@ =20 typedef void (*setup_probe_fn_t)(struct evsel *evsel); =20 -static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str) +static int perf_do_probe_api(setup_probe_fn_t fn, struct perf_cpu cpu, con= st char *str) { struct evlist *evlist; struct evsel *evsel; @@ -29,7 +29,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu= , const char *str) evsel =3D evlist__first(evlist); =20 while (1) { - fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, flags); + fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpu.cpu, -1, flags); if (fd < 0) { if (pid =3D=3D -1 && errno =3D=3D EACCES) { pid =3D 0; @@ -43,7 +43,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu= , const char *str) =20 fn(evsel); =20 - fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, flags); + fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpu.cpu, -1, flags); if (fd < 0) { if (errno =3D=3D EINVAL) err =3D -EINVAL; @@ -61,7 +61,8 @@ static bool perf_probe_api(setup_probe_fn_t fn) { const char *try[] =3D {"cycles:u", "instructions:u", "cpu-clock:u", NULL}; struct perf_cpu_map *cpus; - int cpu, ret, i =3D 0; + struct perf_cpu cpu; + int ret, i =3D 0; =20 cpus =3D perf_cpu_map__new(NULL); if (!cpus) @@ -136,15 +137,17 @@ bool perf_can_record_cpu_wide(void) .exclude_kernel =3D 1, }; struct perf_cpu_map *cpus; - int cpu, fd; + struct perf_cpu cpu; + int fd; =20 cpus =3D perf_cpu_map__new(NULL); if (!cpus) return false; + cpu =3D cpus->map[0]; perf_cpu_map__put(cpus); =20 - fd =3D sys_perf_event_open(&attr, -1, cpu, -1, 0); + fd =3D sys_perf_event_open(&attr, -1, cpu.cpu, -1, 0); if (fd < 0) return false; close(fd); diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 4b510a1f27d4..577ebcb67fe1 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1057,7 +1057,7 @@ static struct mmap *get_md(struct evlist *evlist, int= cpu) for (i =3D 0; i < evlist->core.nr_mmaps; i++) { struct mmap *md =3D &evlist->mmap[i]; =20 - if (md->core.cpu_map_idx =3D=3D cpu) + if (md->core.cpu =3D=3D cpu) return md; } =20 @@ -1443,7 +1443,7 @@ PyMODINIT_FUNC PyInit_perf(void) * Dummy, to avoid dragging all the test_attr infrastructure in the python * binding. */ -void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, +void test_attr__open(struct perf_event_attr *attr, pid_t pid, struct perf_= cpu cpu, int fd, int group_fd, unsigned long flags) { } diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index bff669b615ee..20461f174991 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -106,7 +106,7 @@ void evlist__config(struct evlist *evlist, struct recor= d_opts *opts, struct call if (opts->group) evlist__set_leader(evlist); =20 - if (evlist->core.cpus->map[0] < 0) + if (evlist->core.cpus->map[0].cpu < 0) opts->no_inherit =3D true; =20 use_comm_exec =3D perf_can_comm_exec(); @@ -229,7 +229,8 @@ bool evlist__can_select_event(struct evlist *evlist, co= nst char *str) { struct evlist *temp_evlist; struct evsel *evsel; - int err, fd, cpu; + int err, fd; + struct perf_cpu cpu =3D { .cpu =3D 0 }; bool ret =3D false; pid_t pid =3D -1; =20 @@ -246,14 +247,16 @@ bool evlist__can_select_event(struct evlist *evlist, = const char *str) if (!evlist || perf_cpu_map__empty(evlist->core.cpus)) { struct perf_cpu_map *cpus =3D perf_cpu_map__new(NULL); =20 - cpu =3D cpus ? cpus->map[0] : 0; + if (cpus) + cpu =3D cpus->map[0]; + perf_cpu_map__put(cpus); } else { cpu =3D evlist->core.cpus->map[0]; } =20 while (1) { - fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, + fd =3D sys_perf_event_open(&evsel->core.attr, pid, cpu.cpu, -1, perf_event_open_cloexec_flag()); if (fd < 0) { if (pid =3D=3D -1 && errno =3D=3D EACCES) { diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools= /perf/util/scripting-engines/trace-event-python.c index c0c010350bc2..6af4ec718852 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1553,7 +1553,7 @@ static void get_handler_name(char *str, size_t size, } =20 static void -process_stat(struct evsel *counter, int cpu, int thread, u64 tstamp, +process_stat(struct evsel *counter, struct perf_cpu cpu, int thread, u64 t= stamp, struct perf_counts_values *count) { PyObject *handler, *t; @@ -1573,7 +1573,7 @@ process_stat(struct evsel *counter, int cpu, int thre= ad, u64 tstamp, return; } =20 - PyTuple_SetItem(t, n++, _PyLong_FromLong(cpu)); + PyTuple_SetItem(t, n++, _PyLong_FromLong(cpu.cpu)); PyTuple_SetItem(t, n++, _PyLong_FromLong(thread)); =20 tuple_set_u64(t, n++, tstamp); @@ -1597,7 +1597,7 @@ static void python_process_stat(struct perf_stat_conf= ig *config, int cpu, thread; =20 if (config->aggr_mode =3D=3D AGGR_GLOBAL) { - process_stat(counter, -1, -1, tstamp, + process_stat(counter, (struct perf_cpu){ .cpu =3D -1 }, -1, tstamp, &counter->counts->aggr); return; } diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index d8857d1b6d7c..eb2c18a8ce02 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2537,15 +2537,15 @@ int perf_session__cpu_bitmap(struct perf_session *s= ession, } =20 for (i =3D 0; i < map->nr; i++) { - int cpu =3D map->map[i]; + struct perf_cpu cpu =3D map->map[i]; =20 - if (cpu >=3D nr_cpus) { + if (cpu.cpu >=3D nr_cpus) { pr_err("Requested CPU %d too large. " - "Consider raising MAX_NR_CPUS\n", cpu); + "Consider raising MAX_NR_CPUS\n", cpu.cpu); goto out_delete_map; } =20 - set_bit(cpu, cpu_bitmap); + set_bit(cpu.cpu, cpu_bitmap); } =20 err =3D 0; @@ -2597,7 +2597,7 @@ int perf_event__process_id_index(struct perf_session = *session, if (!sid) return -ENOENT; sid->idx =3D e->idx; - sid->cpu =3D e->cpu; + sid->cpu.cpu =3D e->cpu; sid->tid =3D e->tid; } return 0; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 81a288a7ae46..066231f10b06 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -121,10 +121,10 @@ static void aggr_printout(struct perf_stat_config *co= nfig, id.die, config->csv_output ? 0 : -3, id.core, config->csv_sep); - } else if (id.cpu > -1) { + } else if (id.cpu.cpu > -1) { fprintf(config->output, "CPU%*d%s", config->csv_output ? 0 : -7, - id.cpu, config->csv_sep); + id.cpu.cpu, config->csv_sep); } break; case AGGR_THREAD: @@ -331,7 +331,8 @@ static int first_shadow_cpu_map_idx(struct perf_stat_co= nfig *config, struct evsel *evsel, const struct aggr_cpu_id *id) { struct perf_cpu_map *cpus =3D evsel__cpus(evsel); - int cpu, idx; + struct perf_cpu cpu; + int idx; =20 if (config->aggr_mode =3D=3D AGGR_NONE) return perf_cpu_map__idx(cpus, id->cpu); @@ -513,7 +514,8 @@ static void printout(struct perf_stat_config *config, s= truct aggr_cpu_id id, int static void aggr_update_shadow(struct perf_stat_config *config, struct evlist *evlist) { - int cpu, idx, s; + int idx, s; + struct perf_cpu cpu; struct aggr_cpu_id s2, id; u64 val; struct evsel *counter; @@ -633,7 +635,8 @@ static void aggr_cb(struct perf_stat_config *config, struct evsel *counter, void *data, bool first) { struct aggr_data *ad =3D data; - int idx, cpu; + int idx; + struct perf_cpu cpu; struct perf_cpu_map *cpus; struct aggr_cpu_id s2; =20 @@ -666,7 +669,7 @@ static void aggr_cb(struct perf_stat_config *config, static void print_counter_aggrdata(struct perf_stat_config *config, struct evsel *counter, int s, char *prefix, bool metric_only, - bool *first, int cpu) + bool *first, struct perf_cpu cpu) { struct aggr_data ad; FILE *output =3D config->output; @@ -696,7 +699,7 @@ static void print_counter_aggrdata(struct perf_stat_con= fig *config, fprintf(output, "%s", prefix); =20 uval =3D val * counter->scale; - if (cpu !=3D -1) + if (cpu.cpu !=3D -1) id =3D aggr_cpu_id__cpu(cpu, /*data=3D*/NULL); =20 printout(config, id, nr, counter, uval, @@ -731,8 +734,8 @@ static void print_aggr(struct perf_stat_config *config, first =3D true; evlist__for_each_entry(evlist, counter) { print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, /*cpu=3D*/-1); + prefix, metric_only, + &first, (struct perf_cpu){ .cpu =3D -1 }); } if (metric_only) fputc('\n', output); @@ -893,7 +896,8 @@ static void print_counter(struct perf_stat_config *conf= ig, FILE *output =3D config->output; u64 ena, run, val; double uval; - int idx, cpu; + int idx; + struct perf_cpu cpu; struct aggr_cpu_id id; =20 perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { @@ -921,7 +925,8 @@ static void print_no_aggr_metric(struct perf_stat_confi= g *config, struct evlist *evlist, char *prefix) { - int all_idx, cpu; + int all_idx; + struct perf_cpu cpu; =20 perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.cpus) { struct evsel *counter; @@ -1211,7 +1216,8 @@ static void print_percore_thread(struct perf_stat_con= fig *config, struct aggr_cpu_id s2, id; struct perf_cpu_map *cpus; bool first =3D true; - int idx, cpu; + int idx; + struct perf_cpu cpu; =20 cpus =3D evsel__cpus(counter); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { @@ -1247,8 +1253,8 @@ static void print_percore(struct perf_stat_config *co= nfig, fprintf(output, "%s", prefix); =20 print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, /*cpu=3D*/-1); + prefix, metric_only, + &first, (struct perf_cpu){ .cpu =3D -1 }); } =20 if (metric_only) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index 7dbd7c4f3c33..ee6f03481215 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -297,7 +297,7 @@ static int check_per_pkg(struct evsel *counter, struct = perf_counts_values *vals, { struct hashmap *mask =3D counter->per_pkg_mask; struct perf_cpu_map *cpus =3D evsel__cpus(counter); - int cpu =3D perf_cpu_map__cpu(cpus, cpu_map_idx); + struct perf_cpu cpu =3D perf_cpu_map__cpu(cpus, cpu_map_idx); int s, d, ret =3D 0; uint64_t *key; =20 diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 691c12fd8976..335d19cc3063 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -108,7 +108,7 @@ struct runtime_stat { struct rblist value_list; }; =20 -typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *confi= g, int cpu); +typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *confi= g, struct perf_cpu cpu); =20 struct perf_stat_config { enum aggr_mode aggr_mode; diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 96f941e01681..4c9f211249db 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -728,7 +728,7 @@ static int str_to_bitmap(char *s, cpumask_t *b, int nr_= cpus) int i; int ret =3D 0; struct perf_cpu_map *m; - int c; + struct perf_cpu c; =20 m =3D perf_cpu_map__new(s); if (!m) @@ -736,12 +736,12 @@ static int str_to_bitmap(char *s, cpumask_t *b, int n= r_cpus) =20 for (i =3D 0; i < m->nr; i++) { c =3D m->map[i]; - if (c >=3D nr_cpus) { + if (c.cpu >=3D nr_cpus) { ret =3D -1; break; } =20 - set_bit(c, cpumask_bits(b)); + set_bit(c.cpu, cpumask_bits(b)); } =20 perf_cpu_map__put(m); diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic= -events.c index 198982109f0f..c9ba8050cc2b 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1191,7 +1191,7 @@ static void synthesize_cpus(struct cpu_map_entries *c= pus, cpus->nr =3D map->nr; =20 for (i =3D 0; i < map->nr; i++) - cpus->cpu[i] =3D map->map[i]; + cpus->cpu[i] =3D map->map[i].cpu; } =20 static void synthesize_mask(struct perf_record_record_cpu_map *mask, @@ -1203,7 +1203,7 @@ static void synthesize_mask(struct perf_record_record= _cpu_map *mask, mask->long_size =3D sizeof(long); =20 for (i =3D 0; i < map->nr; i++) - set_bit(map->map[i], mask->mask); + set_bit(map->map[i].cpu, mask->mask); } =20 static size_t cpus_size(struct perf_cpu_map *map) @@ -1219,7 +1219,7 @@ static size_t mask_size(struct perf_cpu_map *map, int= *max) =20 for (i =3D 0; i < map->nr; i++) { /* bit position of the cpu is + 1 */ - int bit =3D map->map[i] + 1; + int bit =3D map->map[i].cpu + 1; =20 if (bit > *max) *max =3D bit; @@ -1354,7 +1354,7 @@ int perf_event__synthesize_stat_config(struct perf_to= ol *tool, } =20 int perf_event__synthesize_stat(struct perf_tool *tool, - u32 cpu, u32 thread, u64 id, + struct perf_cpu cpu, u32 thread, u64 id, struct perf_counts_values *count, perf_event__handler_t process, struct machine *machine) @@ -1366,7 +1366,7 @@ int perf_event__synthesize_stat(struct perf_tool *too= l, event.header.misc =3D 0; =20 event.id =3D id; - event.cpu =3D cpu; + event.cpu =3D cpu.cpu; event.thread =3D thread; event.val =3D count->val; event.ena =3D count->ena; @@ -1763,7 +1763,7 @@ int perf_event__synthesize_id_index(struct perf_tool = *tool, perf_event__handler_ } =20 e->idx =3D sid->idx; - e->cpu =3D sid->cpu; + e->cpu =3D sid->cpu.cpu; e->tid =3D sid->tid; } } diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic= -events.h index c931433bacbf..78a0450db164 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -6,6 +6,7 @@ #include // pid_t #include #include +#include =20 struct auxtrace_record; struct dso; @@ -63,7 +64,7 @@ int perf_event__synthesize_sample(union perf_event *event= , u64 type, u64 read_fo int perf_event__synthesize_stat_config(struct perf_tool *tool, struct perf= _stat_config *config, perf_event__handler_t process, struct machine *machin= e); int perf_event__synthesize_stat_events(struct perf_stat_config *config, st= ruct perf_tool *tool, struct evlist *evlist, perf_event__handler_t process,= bool attrs); int perf_event__synthesize_stat_round(struct perf_tool *tool, u64 time, u6= 4 type, perf_event__handler_t process, struct machine *machine); -int perf_event__synthesize_stat(struct perf_tool *tool, u32 cpu, u32 threa= d, u64 id, struct perf_counts_values *count, perf_event__handler_t process,= struct machine *machine); +int perf_event__synthesize_stat(struct perf_tool *tool, struct perf_cpu cp= u, u32 thread, u64 id, struct perf_counts_values *count, perf_event__handle= r_t process, struct machine *machine); int perf_event__synthesize_thread_map2(struct perf_tool *tool, struct perf= _thread_map *threads, perf_event__handler_t process, struct machine *machin= e); int perf_event__synthesize_thread_map(struct perf_tool *tool, struct perf_= thread_map *threads, perf_event__handler_t process, struct machine *machine= , bool needs_mmap, bool mmap_data); int perf_event__synthesize_threads(struct perf_tool *tool, perf_event__han= dler_t process, struct machine *machine, bool needs_mmap, bool mmap_data, u= nsigned int nr_threads_synthesize); diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 9f0d36ba77f2..9443c29afa52 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -11,6 +11,9 @@ #include #include #include +#ifndef __cplusplus +#include +#endif =20 /* General helper functions */ void usage(const char *err) __noreturn; @@ -66,6 +69,6 @@ extern bool test_attr__enabled; void test_attr__ready(void); void test_attr__init(void); struct perf_event_attr; -void test_attr__open(struct perf_event_attr *attr, pid_t pid, int cpu, +void test_attr__open(struct perf_event_attr *attr, pid_t pid, struct perf_= cpu cpu, int fd, int group_fd, unsigned long flags); #endif /* GIT_COMPAT_UTIL_H */ --=20 2.34.1.307.g9b7440fafd-goog