From patchwork Thu Dec 30 07:19:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 36BFEC433F5 for ; Thu, 30 Dec 2021 07:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=+OqKgMjIkcEvUMHFugtpSS9oqL4vj2H742g6rKaezSc=; b=ChMrGmMro7WyEZHwVatdomuNMi 6NgPO/1FqYLi2d07CLUfBI79SX3xGwy3DCdskQcf+PsMKHqDMbs2ewKMD/EsgXvQLxjasCvy7RaL0 419i8l4x/ah9jt0HUxni+lhdwbOx14dHQy84TLdrZ8QaVSW4oFjM4rFEx45WHN8LK5WeyEFHBGUkT yUNO9C+iLJL8Uf4m45E7vCMSoD39l2Had0uv8N1+0F1gH/4SDoM9LNgap6aS+CxD+t0J3jy13AJHi wGtIRXHcSk2/Jroj4IPAO5tkhhBLyLXIRxIf6j/vjJSJoR8LoTmQg95RIUySOdOMXv7eL5SywQKw9 b0moUesw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pk4-003jTb-8f; Thu, 30 Dec 2021 07:20:52 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pjs-003jPH-I6 for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:20:41 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id c5-20020a25f305000000b0060bbdf755f7so25223110ybs.14 for ; Wed, 29 Dec 2021 23:20:39 -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=R/ciplz7o8MJIByj4LFS+saOMsnt5V7JtjWFtjIV8fs=; b=hOnDJwZL1uLASJfxt16LE8RbyfAliT6lWhtat21Tok3eL5nEi56QviZgxbrBWkjbvH XcDTOXrfk8KXWSKd/gcxHMDBj8SDtjaQmSDkLF9iI1VtzccOrmo7SKYvF6BdZlEwhkjQ G52a+98JImuc8mE1Iu2+xNB5BY/m2ySBaJFm2e+nI+qUeCpD/NiVam89g+z03DkHfQWr kBkGfTlR3zL8pyYjAmdMbgLdMwagtqYMwfpD/bHcS9dibJZ6T0GjuIaKJP1TdvTHEZUt NCr4gAa47x5rn1N5jy478QfHJXvdXM61fjflTU+q5UEdUTdq+BaOzMnmqs0t8N5+FP67 HCkA== 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=R/ciplz7o8MJIByj4LFS+saOMsnt5V7JtjWFtjIV8fs=; b=gceR3UiAzqCjfRPA7yD4eITW3bMsmTDIYiiMcx/vTeskxhM42LB390KDomcFBMNwmI hzN+eSHliR3szXuqV2LPHWqfLfbTiXzbL9U3MWAYWTo8n788W47WfpK0+qokuEicCsCr vmS3e+rA1aHVrbCOsr1FbELLGSsOgzqfWUqX11iOBlXfVtGhZuCIEzbkZ7jH6Yz17I79 8e3MYYh2e8L//pF971jti8YQF5c/Avs7tiubNvQ8ZmF9EV7MCD7fEkM6JTQlRZdQ9LLg wuV8D0vYGqc7bwv6tDuRhx5vDz/1/ZIv907sdsMhV+wAo8t5Vtt1r1xAoZH3DZ1MHdOf snQQ== X-Gm-Message-State: AOAM531/fbBlAl8hqDYbUonUy3N01ee4UnYx0OUSVhC4h5xq5goIsrt5 BiZN0/r9YvMekS1RQlN7azkrKjUSe4fl X-Google-Smtp-Source: ABdhPJz0suG/e7yZrpxzUx3hVM4B9b7DWdq9+GCwNAbOY3zjXSahtZ9HZi+mnDCm0FVN8zGn882k7ziDe8sp X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a5b:c01:: with SMTP id f1mr38085796ybq.47.1640848838463; Wed, 29 Dec 2021 23:20:38 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:42 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-2-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232040_618079_BCFE248A X-CRM114-Status: GOOD ( 12.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/include/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 @@ #include +/** + * 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 having + * 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[]; }; From patchwork Thu Dec 30 07:19:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EA0ADC433FE for ; Thu, 30 Dec 2021 07:22:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7fcM6t8HGo9NI4b53DZhlCSkiCfeLmgHcsG7OwIuENk=; b=iem5YgLRLcTBSqdbeq5gkHbj7Z YxRsb+Mhmn4FT25t3944LCrC4AVHt35Si4L2Vo5g0BQko5ZIHEPNDC50SlhcXMVSLDId7xbov6ZYy ODnbBJdsiHk/JmelK0+uerwgs6yJpBabKRmCy3DVW+ySG/wMkf25A0y79BSLnkhSan4mQBPFaDTx8 dXm9c7EQxxrU0nD5tnwTjZ+SWBeRwW93JCr7BMpRNG2WOvGjksbt7N9EZPpSEAWf1YBAxTAXO6lWJ uw5nN146p0lkqquoJ9cuWVN5GZ7v871lvDnMRWaq5ODAxN8hxStA3Gb+nuuljmgGqVsXi/GlTFj3a RHySMgCg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkR-003jeK-LY; Thu, 30 Dec 2021 07:21:15 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pjx-003jRK-8J for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:20:46 +0000 Received: by mail-yb1-xb49.google.com with SMTP id k130-20020a255688000000b0060c3dcae580so22462010ybb.6 for ; Wed, 29 Dec 2021 23:20:44 -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=9wDbHdn10g/+9EQEVPDNOOFeLcUHQZE87jycF0w2kms=; b=Vsmc+cYoiqunEsAtIbPHJutmmlAzgbMaSayePjB9AI3yc/s5wPOIjYwkfbP5dxXXhn p+YPNskrY/8HFeT0pmCZow0U5aeqy93tgkxQmepYtoxQP5ifhXBmbc4Ax0itc/cqQfBx Hd9hLaVGM3ID9QInmpoUsUKvbtmPnFD+gQELyqvEvfKWcFezypz3qtKo7FDOEpkTAKUR FDZn7ZzodFPXwL2zuEYw/c1RdI1c46dDuLFbQkmG2JpicEH2t/0HqkijYVpVMiUyJW9Y zfYsy5DjhZpEvdOIuuUY051mtfZg7NyvHPHs5SKoQJVeUWJ96P2P0EqE7TTBmuK9bIf9 zkzA== 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=9wDbHdn10g/+9EQEVPDNOOFeLcUHQZE87jycF0w2kms=; b=HUGlQwhur1WYTWTzCHndzZfTc3KNbwaATkELmawDsuMpsgrg92r/gb4+R4YtsaAMmb cm0OMciVDv7ybewXwsjl8PSFaNY+HksXNzSn+pYvHsRXMp5nzBTQM6G3thocH8FWJPut 6KpkyKAusCMJmOKgoHTD0W9fRSf7F6Af+OhMg990JR8WD6SvHUDcBOSGdFOsAz8ekxPn puGSF6Hf3pFAaz1JOvRSbQ+CEhP7LbtJBCdrPluF2qfNaV3njyHqENDDmOVHd5QWda+y YLy+ThjK8amLNQR41ogCLVMrIaoJtj6YXQZEh2m2HXlBfnoUxAlvItlNkBi5Ja668tF+ OLGQ== X-Gm-Message-State: AOAM532HXmAtnAsY6NlBNwBamuDU6lkxemG06On9P55mvtTI038zJ1TB oXDMmLNFNqoPHMVb6gbiihpHRn+IXV0t X-Google-Smtp-Source: ABdhPJyIhv6zQvgccPus7nZaLKGmc7HJAVbNkg2UN467+wNtOi4KykqCvyIh2no7gXbYIAhgGinqkxmF8oEC X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:d696:: with SMTP id n144mr18608615ybg.13.1640848843690; Wed, 29 Dec 2021 23:20:43 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:44 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-4-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232045_335801_0F9FAE47 X-CRM114-Status: GOOD ( 16.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; } -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 __maybe_unused) { - int cpu; struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - if (idx > map->nr) - return id; - - cpu = map->map[idx]; - id.socket = cpu_map__get_socket_id(cpu); return id; } +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 = (struct aggr_cpu_id *)a_pointer; @@ -200,15 +202,10 @@ int cpu_map__get_die_id(int cpu) return ret ?: value; } -struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, void *data) +struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data) { - int cpu, die; - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - - if (idx > map->nr) - return id; - - cpu = map->map[idx]; + struct aggr_cpu_id id; + int die; die = 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 = cpu_map__get_socket(map, idx, data); + id = cpu_map__get_socket_aggr_by_cpu(cpu, data); if (cpu_map__aggr_cpu_id_is_empty(id)) return id; @@ -228,6 +225,15 @@ struct aggr_cpu_id cpu_map__get_die(struct perf_cpu_map *map, int idx, void *dat return id; } +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 = 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); } -struct aggr_cpu_id cpu_map__get_core(struct perf_cpu_map *map, int idx, void *data) +struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data) { - int cpu; - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - - if (idx > map->nr) - return id; - - cpu = map->map[idx]; - - cpu = cpu_map__get_core_id(cpu); + struct aggr_cpu_id id; + int core = cpu_map__get_core_id(cpu); /* cpu_map__get_die returns a struct with socket and die set*/ - id = cpu_map__get_die(map, idx, data); + id = cpu_map__get_die_aggr_by_cpu(cpu, data); if (cpu_map__aggr_cpu_id_is_empty(id)) return id; @@ -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 = cpu; + id.core = core; return id; + } -struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, void *data __maybe_unused) +struct aggr_cpu_id cpu_map__get_core(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_core_aggr_by_cpu(map->map[idx], data); +} + +struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + id.node = cpu_map__get_node_id(cpu); + return id; +} + +struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, void *data) +{ if (idx < 0 || idx >= map->nr) - return id; + return cpu_map__empty_aggr_cpu_id(); - id.node = cpu_map__get_node_id(map->map[idx]); - return 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_map **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 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, 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, void *data); int cpu_map__get_node_id(int cpu); -struct aggr_cpu_id cpu_map__get_node(struct perf_cpu_map *map, int idx, void *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, void *data); int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **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); From patchwork Thu Dec 30 07:19:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D7E1FC4332F for ; Thu, 30 Dec 2021 07:23:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=qI3P45VQdyRSlwkZHkhEP03qwtfaRVcqcWCoXpRFIx4=; b=b4WfgEQjPvWskkz7GWRH/LdWlL KnDGscgFZHOnaj1dyP/A9vuyecwGO/2iC0CMcCpL5ztrEsXp6fn1TJ2P6TxxMDgnVY8kY85KSKJzc 5H3MDdjglxdBJ7Vvq+neexiDYgK4LIdOpkTeH/WsNvOGrmJxhsyj+L3YIDFCRdalHvjneplx6wkxF MjyOcsMY/C7kp//MPImfNtOU/62mxghBvGpn/ZeJOerbY3NYVh28VXvtgx9KnsDsFSIoB119GMw/z 7bEIxuXf1g2nHUNhKUWpMRbZyexV8H+UMdk+e1v8Db6DbuoeUi+SsNfPwkE5G+lJxCoiKeWJjihK4 NpPp4ddQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkj-003jnn-NS; Thu, 30 Dec 2021 07:21:34 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pjz-003jS3-Ka for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:20:49 +0000 Received: by mail-yb1-xb49.google.com with SMTP id t184-20020a2546c1000000b006008b13c80bso42274544yba.1 for ; Wed, 29 Dec 2021 23:20:46 -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=HQ0F4Wkpc2hZGLs9o4VVEd71gbRETuZn+IEXms79S7Y=; b=FD7ZPImddyL2cAMf3QezttcpbIzDG2J9TwTaFHD3Ruo2dwTWNKkd0Rk3IM7BiKFLlj H8VJPHGgAB+zmaij4pvzxfZaRiSM5VtLO6B+rAJYuzuYfFA9B+bpRODDbGbqHsPdUeik JpToHcLcRG4IusO6rxUxZd8yjkhEBjfFf20SHdgp3wpNbIBtz6vs26epU6ckOpQ/UcIS 9MA6dPnFgqp0+Tc83Xi/mWAsFXUQ8Y4jawSqtzba5jj5zkFbL+ue/lnj7vQWRqeNix8n L36jLP7y2ciGmq6/IaAzgWEsrPk1+K+o78N+KAdNdvmihM5jboVIdbSd+/HoOO2W4Bee dIUA== 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=HQ0F4Wkpc2hZGLs9o4VVEd71gbRETuZn+IEXms79S7Y=; b=r4Xc10eTMNt8DxFdcX9Fk0NmJVUzQD8o3+6pQOP7Oj7L/Ot4/jOGvmCSl4qq7Xcsp8 XQrD02Dnt/Q5bz4haTCixnlDYs/Bv/FTDF/K/6OPzjQnRZfmyHL+zWprtbIVgic/VY3n TcwS7zFiT6okjiNKBzaGksAZkWWhho1ep7AfRzpv98A5FVxmF6c9VdNwbKynwfGAe8wL X2BaS7GJqLMmhrvzLhW4buUph/lD0PAOxEA8/cuts2p0dGQrvWA9zXPCrdfJI5bWcsJo TcLNu59ZuYMdxAtIxbTyYe3y5MxU+VVstDwA2LlACK2p4YU5KaPK6DMZn2IDmYeTBPCQ eMaQ== X-Gm-Message-State: AOAM531Uq+oQDLk06v2hSq/Isw0VIbfRUVUtIb6oK+qaB77n5nHxR1oF UZl6HVNhAHZ2lJBgCNOLmfkEGUJZeMud X-Google-Smtp-Source: ABdhPJwYc6sI6/tU+488uQ6TPKBQHt6h6pGnihwygMdw5SVRUcXB7K6/76412r9nXLTCLzEk+BdjcwqsuW62 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:d78f:: with SMTP id o137mr21538140ybg.19.1640848846260; Wed, 29 Dec 2021 23:20:46 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:45 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-5-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232047_707851_D8849054 X-CRM114-Status: GOOD ( 14.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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_write/ # 103.00 DRAM_BW_Use 1.001102293 S0 1 30.22 MiB uncore_imc/cas_count_read/ 1.001102293 S0 1 1,001,102,293 ns duration_time 1.001102293 S1 1 20.10 MiB uncore_imc/cas_count_write/ # 0.00 DRAM_BW_Use 1.001102293 S1 1 32.74 MiB uncore_imc/cas_count_read/ 1.001102293 S1 0 ns duration_time 2.003517973 S0 1 83.04 MiB uncore_imc/cas_count_write/ # 920.00 DRAM_BW_Use 2.003517973 S0 1 145.95 MiB uncore_imc/cas_count_read/ 2.003517973 S0 1 1,002,415,680 ns duration_time 2.003517973 S1 1 302.45 MiB uncore_imc/cas_count_write/ # 0.00 DRAM_BW_Use 2.003517973 S1 1 290.99 MiB uncore_imc/cas_count_read/ 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_write/ # 54.00 DRAM_BW_Use 1.001080840 S0 1 33.64 MiB uncore_imc/cas_count_read/ 1.001080840 S0 1 1,001,080,840 ns duration_time 1.001080840 S1 1 42.43 MiB uncore_imc/cas_count_write/ # 84.00 DRAM_BW_Use 1.001080840 S1 1 47.05 MiB uncore_imc/cas_count_read/ 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 = 0; for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { - s2 = config->aggr_get_id(config, evlist->core.cpus, cpu); + s2 = config->aggr_get_id(config, evsel__cpus(counter), cpu); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; val += perf_counts(counter->counts, cpu, 0)->val; From patchwork Thu Dec 30 07:19:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701264 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB508C433EF for ; Thu, 30 Dec 2021 07:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=/jbS8pJ3YwnFDHEauhzM9+GlwYR8dom5yAJOLRwRgFM=; b=jWR/gFn0QinhPUwFMCkSi78Qqc 5n7Zt8mVF35kOd3MRDS/WhDiP10+8w2ndps7kQ/Blsha+veRuqnhs/4bQbwj0JyjMlOFpW7XL4xsF 2ybg8Ai1B3dmvEVPY8kYrhyg4LQ3VT8GaIcgsyt+1usyGYZUL7cJJLABuDFaFDvOmhVjblspILD4b YBtmEQAF4oqukIOv0x/aKVEDfoi6/sm4qwKmhDO56qtoVWyGBfB41i1iHE2K2VQSjXKyRqKVZoYzA yJ6nWqrrXN5IQY2Od3BXpR6lrT3CJoLFka3250VGXsFORry06jHw8c3GPjx9x1xvjq8l2/mQLnB0f m8gTIQfA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pla-003kIV-1L; Thu, 30 Dec 2021 07:22:28 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pk2-003jSu-0Y for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:20:51 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id s83-20020a255e56000000b0060c46cc1890so21972031ybb.16 for ; Wed, 29 Dec 2021 23:20:49 -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=g2nak5zfew4oiMxb3Bq8hR7F6MQXwULWW7e4c//RBpw=; b=OqFV3/mckgy62/iZs44KVQxyZhLCwcYZF8nrpzppko36XUHulgUi/uhYYv/sHl2qnG ZG+Y40M43qda/KcB2/0UOpfc3cXcm5hXwP/4TyOl2moCaXr8xwEj/IMwb4xzaF3bqOxn NUwOPMYwUDLVWl8okBp/tU3pL+Bx3X+lkYJA8C61wG8y6GjjhGW6J0xLYDkdCCdx3AJ2 slM6FeI6EUp7ZwF7jok5cLS0BbQ7XYZyKnEFpf07tMrujqV4krQVl6JsFyGcCGONfz4d dK9jULKmyCCDuK+J148qGMk1i5C+fiUwK0kKjpkOnpgSf+tU+6phwIWovKMJNoMVM+Mi INZw== 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=g2nak5zfew4oiMxb3Bq8hR7F6MQXwULWW7e4c//RBpw=; b=BtYDIDPD3ghZ2jcgGsKxsO70o+MVObFbF/wvlfAWqjwikIduhdO4sWbxsBrTeV68mV /qzcQ2Sga/JeZQ88wmhtX9uQhxpHy3B/OQegKPHsmRJUPEIWu7zl5t8D4MMFaFP+5Ux1 Kvj5tW2/RUmGg/tu4Ge5iNsYZPCsxUu8FM/ZcaLhF8eO/SHecWlvX31A9Q8hdck2xu2Y jgAEzNWr5jvd/XVO0QvCqIh7yw3myy34NufMnjHp94IQZMRDUMgbVdDxQp1DQKSE5lqZ xopJ+fh11SnCxpvdR4CBLTwbWOID/fFRbsj905Wx5LvYJgmJ8dT8Bl9EUBaxi2K2nTYq tANg== X-Gm-Message-State: AOAM533JxLqJzeljmHzkl3tgk1e8QOvZi//jw6Kg97BzU83vHPUmiGgV ij8vgPk9N4td7rj2JC8HBSMo7O8dJPeQ X-Google-Smtp-Source: ABdhPJxziueaLUL8eg3hpXl7lnrpGzJLTDgN6CDHeK8HZeJdo3nhqD1DPeVXSp8xHYR1YehIkwuOoeQVzBRD X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:6647:: with SMTP id z7mr14069733ybm.578.1640848848683; Wed, 29 Dec 2021 23:20:48 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:46 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-6-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232050_077844_474FBB0A X-CRM114-Status: GOOD ( 17.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Tidy up the use of cpu and index to hopefully make the code less error prone. Avoid unused warnings with (void) which will be removed in a later patch. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 48 +++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index b0fa81ffce61..efab39a759ff 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -330,8 +330,8 @@ static void print_metric_header(struct perf_stat_config *config, static int first_shadow_cpu(struct perf_stat_config *config, struct evsel *evsel, struct aggr_cpu_id id) { - struct evlist *evlist = evsel->evlist; - int i; + struct perf_cpu_map *cpus; + int cpu, idx; if (config->aggr_mode == AGGR_NONE) return id.core; @@ -339,14 +339,11 @@ static int first_shadow_cpu(struct perf_stat_config *config, if (!config->aggr_get_id) return 0; - for (i = 0; i < evsel__nr_cpus(evsel); i++) { - int cpu2 = evsel__cpus(evsel)->map[i]; - - if (cpu_map__compare_aggr_cpu_id( - config->aggr_get_id(config, evlist->core.cpus, cpu2), - id)) { - return cpu2; - } + cpus = evsel__cpus(evsel); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + if (cpu_map__compare_aggr_cpu_id(config->aggr_get_id(config, cpus, idx), + id)) + return cpu; } return 0; } @@ -516,20 +513,23 @@ static void printout(struct perf_stat_config *config, struct aggr_cpu_id id, int static void aggr_update_shadow(struct perf_stat_config *config, struct evlist *evlist) { - int cpu, s; + int cpu, idx, s; struct aggr_cpu_id s2, id; u64 val; struct evsel *counter; + struct perf_cpu_map *cpus; for (s = 0; s < config->aggr_map->nr; s++) { id = config->aggr_map->map[s]; evlist__for_each_entry(evlist, counter) { + cpus = evsel__cpus(counter); val = 0; - for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { - s2 = config->aggr_get_id(config, evsel__cpus(counter), cpu); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + (void)cpu; + s2 = config->aggr_get_id(config, cpus, idx); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; - val += perf_counts(counter->counts, cpu, 0)->val; + val += perf_counts(counter->counts, idx, 0)->val; } perf_stat__update_shadow_stats(counter, val, first_shadow_cpu(config, counter, id), @@ -634,18 +634,21 @@ static void aggr_cb(struct perf_stat_config *config, struct evsel *counter, void *data, bool first) { struct aggr_data *ad = data; - int cpu; + int idx, cpu; + struct perf_cpu_map *cpus; struct aggr_cpu_id s2; - for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { + cpus = evsel__cpus(counter); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { struct perf_counts_values *counts; - s2 = config->aggr_get_id(config, evsel__cpus(counter), cpu); + (void)cpu; + s2 = config->aggr_get_id(config, cpus, idx); if (!cpu_map__compare_aggr_cpu_id(s2, ad->id)) continue; if (first) ad->nr++; - counts = perf_counts(counter->counts, cpu, 0); + counts = perf_counts(counter->counts, idx, 0); /* * When any result is bad, make them all to give * consistent output in interval mode. @@ -1208,10 +1211,13 @@ static void print_percore_thread(struct perf_stat_config *config, { int s; struct aggr_cpu_id s2, id; + struct perf_cpu_map *cpus; bool first = true; + int idx, cpu; - for (int i = 0; i < evsel__nr_cpus(counter); i++) { - s2 = config->aggr_get_id(config, evsel__cpus(counter), i); + cpus = evsel__cpus(counter); + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + s2 = config->aggr_get_id(config, cpus, idx); for (s = 0; s < config->aggr_map->nr; s++) { id = config->aggr_map->map[s]; if (cpu_map__compare_aggr_cpu_id(s2, id)) @@ -1220,7 +1226,7 @@ static void print_percore_thread(struct perf_stat_config *config, print_counter_aggrdata(config, counter, s, prefix, false, - &first, i); + &first, cpu); } } From patchwork Thu Dec 30 07:19:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701265 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0DA69C433F5 for ; Thu, 30 Dec 2021 07:24:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GhVQp1+/PxIzk7W9LcXJu2XHAQ/FROjRULGHoCANX7M=; b=AQufpK7oeROjUMu1ptKBX9kje0 0f98J/DE5Jdo8lgiaF1ltz1FKdyl4/zdRrfmatafQKES+mNeUwurQhJamL5sIg0vwIkiHU2vJBCF/ h/Hr/G3J2uEwfcYeV3bdP+NAXGJDCOk0f1/ftih8Hpqxk4HBhpfR97cGOimO0J9IsX/iXFp3zS+o+ +IYBzng6zJcCQnU/Pmty+bwb13z56oUfh96B7TYQFtL4Ryolcc3Oie3oyhMPNCaJygFUq9gBC8mIR SA++LWyC4ZAM32+WaVU+e8S9d+9uMnhRdcA/Prq4caDzhjjOZaMQi6IJanStPKOXJV+FchCZ82mGT 4imx95Jw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pmQ-003klS-Rc; Thu, 30 Dec 2021 07:23:19 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pk4-003jTj-RI for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:20:54 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id t184-20020a2546c1000000b006008b13c80bso42274865yba.1 for ; Wed, 29 Dec 2021 23:20:51 -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=s4X02nPqi4F+1EmoUQtjO9/Qbf12X3JymSUrgtvqJrs=; b=l1fWCghrYAW3unWS4+M8bQMkCz6u/L9GDkkw74pkbf37n5GbApMhE6fNv8YzPbRD9C IijpC18jYrQ4rQNVh9rTGCLzY+UkTFsSqJuifjhlMIYtDteT4ARAburHIXZ7Qv+I9Z+A nNMsUhCOSXDDcYxOK/kMOw1WM2TTfsmO4vv3mhj4yH50j/eyG3ISb906QTAgyviVyhLn rcQ42FfoUjYJ0H1Cpzv4b3g+BsbAlJ4XXobYlryAfrUm1Gcd4oXlf92Q8i0+FFCK2g3A L0b4UzVr2uLGWwSgXlDl4cDBtSNlekrU2+kGt6vsdqj60+hS7bAQ/O6v3PbIPyS8w06u s1Qg== 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=s4X02nPqi4F+1EmoUQtjO9/Qbf12X3JymSUrgtvqJrs=; b=SATsb+i0WapKxHWZEgqiqZwHBcOEIwosXTLjg4jWzyRPr54LHNZpBvDhxv+egPpvxF PcaKAcTwxZkxjfekU4rJgcFoO6/9TMgYPGKKpNbS9cNG4YnLZf1y0PO0LVg/ACiMp7EJ YkPop70RA9iCEj7O5r9Wj8ow4XPwE/bEZbfNRMDGLpsG+j2c/t/yXzhaGXs8GIP9tJXk wdymlwe9ehXdx4itHqLv4856vfdniTkqtNeEIqJZhznzD6bORjE4icHgn/GLdOg4X9ri FfLzk3Z6VYACevT1psSQblraZWXxQBBKBWINd4N2BMdiPiPJxQChZII1wOCZFCZCsund ORHg== X-Gm-Message-State: AOAM533Os3Xe3t4d5tPfPUyyHYAHV/cXmMT3joK2RAJxyjIJD8sSHc4i SVgd1HGNEyzsAH/Pswn4laILAyKuiito X-Google-Smtp-Source: ABdhPJxlKgxKCfzRAlpi3oA7tu7yLR4omDu403xKk0YEtb3lwmD4rLoVt0FjL83gGZneAdSK0oZU2SmNz4da X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:4197:: with SMTP id o145mr19892454yba.80.1640848851308; Wed, 29 Dec 2021 23:20:51 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:47 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-7-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232052_926808_469C508B X-CRM114-Status: GOOD ( 16.51 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Avoid bugs where the wrong index is passed with the cpu_map. Reviewed-by: James Clark Signed-off-by: Ian Rogers --- tools/perf/builtin-stat.c | 93 +++++++++++++++++++--------------- tools/perf/util/stat-display.c | 11 ++-- tools/perf/util/stat.h | 3 +- 3 files changed, 57 insertions(+), 50 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index f6ca2b054c5b..9791ae9b1a53 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1323,69 +1323,63 @@ static struct option stat_options[] = { }; static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_socket(map, cpu, NULL); + return cpu_map__get_socket_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_die(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_die(map, cpu, NULL); + return cpu_map__get_die_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_core(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_core(map, cpu, NULL); + return cpu_map__get_core_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int cpu) + int cpu) { - return cpu_map__get_node(map, cpu, NULL); + return cpu_map__get_node_aggr_by_cpu(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, - aggr_get_id_t get_id, struct perf_cpu_map *map, int idx) + aggr_get_id_t get_id, int cpu) { - int cpu; struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - if (idx >= map->nr) - return id; - - cpu = map->map[idx]; - if (cpu_map__aggr_cpu_id_is_empty(config->cpus_aggr_map->map[cpu])) - config->cpus_aggr_map->map[cpu] = get_id(config, map, idx); + config->cpus_aggr_map->map[cpu] = get_id(config, cpu); id = config->cpus_aggr_map->map[cpu]; return id; } static struct aggr_cpu_id perf_stat__get_socket_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_socket, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_socket, cpu); } static struct aggr_cpu_id perf_stat__get_die_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_die, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_die, cpu); } static struct aggr_cpu_id perf_stat__get_core_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_core, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_core, cpu); } static struct aggr_cpu_id perf_stat__get_node_cached(struct perf_stat_config *config, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_stat__get_aggr(config, perf_stat__get_node, map, idx); + return perf_stat__get_aggr(config, perf_stat__get_node, cpu); } static bool term_percore_set(void) @@ -1483,8 +1477,9 @@ static void perf_stat__exit_aggr_mode(void) stat_config.cpus_aggr_map = NULL; } -static inline int perf_env__get_cpu(struct perf_env *env, struct perf_cpu_map *map, int idx) +static inline int perf_env__get_cpu(void *data, struct perf_cpu_map *map, int idx) { + struct perf_env *env = data; int cpu; if (idx > map->nr) @@ -1498,10 +1493,9 @@ static inline int perf_env__get_cpu(struct perf_env *env, struct perf_cpu_map *m return cpu; } -static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; - int cpu = perf_env__get_cpu(env, map, idx); struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); if (cpu != -1) @@ -1510,11 +1504,15 @@ static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, int idx return id; } -static struct aggr_cpu_id perf_env__get_die(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_socket_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + +static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - int cpu = perf_env__get_cpu(env, map, idx); if (cpu != -1) { /* @@ -1529,11 +1527,15 @@ static struct aggr_cpu_id perf_env__get_die(struct perf_cpu_map *map, int idx, v return id; } -static struct aggr_cpu_id perf_env__get_core(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_die(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_die_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + +static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); - int cpu = perf_env__get_cpu(env, map, idx); if (cpu != -1) { /* @@ -1549,15 +1551,24 @@ static struct aggr_cpu_id perf_env__get_core(struct perf_cpu_map *map, int idx, return id; } -static struct aggr_cpu_id perf_env__get_node(struct perf_cpu_map *map, int idx, void *data) +static struct aggr_cpu_id perf_env__get_core(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_core_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + +static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) { - int cpu = perf_env__get_cpu(data, map, idx); struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); id.node = perf_env__numa_node(data, cpu); return id; } +static struct aggr_cpu_id perf_env__get_node(struct perf_cpu_map *map, int idx, void *data) +{ + return perf_env__get_node_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); +} + static int perf_env__build_socket_map(struct perf_env *env, struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp) { @@ -1583,26 +1594,26 @@ static int perf_env__build_node_map(struct perf_env *env, struct perf_cpu_map *c } static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_socket(map, idx, &perf_stat.session->header.env); + return perf_env__get_socket_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_die_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_die(map, idx, &perf_stat.session->header.env); + return perf_env__get_die_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_core_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_core(map, idx, &perf_stat.session->header.env); + return perf_env__get_core_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *config __maybe_unused, - struct perf_cpu_map *map, int idx) + int cpu) { - return perf_env__get_node(map, idx, &perf_stat.session->header.env); + return perf_env__get_node_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static int perf_stat_init_aggr_mode_file(struct perf_stat *st) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index efab39a759ff..6c40b91d5e32 100644 --- a/tools/perf/util/stat-display.c +++ b/tools/perf/util/stat-display.c @@ -341,8 +341,7 @@ static int first_shadow_cpu(struct perf_stat_config *config, cpus = evsel__cpus(evsel); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - if (cpu_map__compare_aggr_cpu_id(config->aggr_get_id(config, cpus, idx), - id)) + if (cpu_map__compare_aggr_cpu_id(config->aggr_get_id(config, cpu), id)) return cpu; } return 0; @@ -525,8 +524,7 @@ static void aggr_update_shadow(struct perf_stat_config *config, cpus = evsel__cpus(counter); val = 0; perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - (void)cpu; - s2 = config->aggr_get_id(config, cpus, idx); + s2 = config->aggr_get_id(config, cpu); if (!cpu_map__compare_aggr_cpu_id(s2, id)) continue; val += perf_counts(counter->counts, idx, 0)->val; @@ -642,8 +640,7 @@ static void aggr_cb(struct perf_stat_config *config, perf_cpu_map__for_each_cpu(cpu, idx, cpus) { struct perf_counts_values *counts; - (void)cpu; - s2 = config->aggr_get_id(config, cpus, idx); + s2 = config->aggr_get_id(config, cpu); if (!cpu_map__compare_aggr_cpu_id(s2, ad->id)) continue; if (first) @@ -1217,7 +1214,7 @@ static void print_percore_thread(struct perf_stat_config *config, cpus = evsel__cpus(counter); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - s2 = config->aggr_get_id(config, cpus, idx); + s2 = config->aggr_get_id(config, cpu); for (s = 0; s < config->aggr_map->nr; s++) { id = config->aggr_map->map[s]; if (cpu_map__compare_aggr_cpu_id(s2, id)) diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 32c8527de347..32cf24186229 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h @@ -108,8 +108,7 @@ struct runtime_stat { struct rblist value_list; }; -typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, - struct perf_cpu_map *m, int cpu); +typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, int cpu); struct perf_stat_config { enum aggr_mode aggr_mode; From patchwork Thu Dec 30 07:19:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701266 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 333EDC433F5 for ; Thu, 30 Dec 2021 07:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=nDSFN91/HnC/KmJPFRg3XNva6LLXllAfiJJMth41Q98=; b=b+OqIvZzO1mBYq9P5hjCDy3AzZ 3P0QNFmIuOMWMgHJZzpFI7KMPqg8/SOu0PRzZH8ULndu4J8TOB6NK0W+h3pDSOeyERjQgRkp92LXa vcalBpq6DbWguRxmGDLWJGdK8FKeSV7gF5sSZU4rRuEUgNfkFHM5gZuXnNQyiZwmwl7tINW+qai5S N6shippFwBxHnCTz78/kY6tykTozBrCr/UC6Qz8q14Oq8808NdKOrXss7r34CIvqB1LunrP2JHEBj LJAlTCq32MQaHq5kgRA6NZ0D/uPJ6OXUlKrMQ3qGrEaXO2HlytzSAwoEj3JAbpPyDsU6VamLFYU6h Yh/qoKYw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pn1-003l2b-TE; Thu, 30 Dec 2021 07:23:56 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pk7-003jVK-9J for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:20:56 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s84-20020a254557000000b0060ac37f4bb1so29558616yba.5 for ; Wed, 29 Dec 2021 23:20:54 -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=0PQ2wkiHIZCukUmO6iPoQYJEB6vBau09xCeEdVn1F2A=; b=qNZLdZrEdI08X5vGbvkJOSqp0tbLm3QgzHLR6GG/e8QeH+QcM84H0tjMudV5532Zga 92Xr/S4p8ncKx4fHOBi+9R6pyEcMj9vfpyTPZ2S0tJBfarzgCILF7E4mvNTVt6IVx80x elvnyxEzK64OyjlN+ltkIwhaRW+J7YHTuLnSxT4HeSd6BnqVbt2oyKfn+QlACdBIIEhz T8gFHyQzKIQ8845mWYK2OOdcy08xO1ucxB234FksPqc0rGTKwSRjCQOLAgjstbIOg5c/ ZVtU6GQFlakYUutxT/bdOh4HZ5PqS1oSuL1wo6zaRMJR0GDLu7BqE5dWmvm4uFfH+zNP oZGw== 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=0PQ2wkiHIZCukUmO6iPoQYJEB6vBau09xCeEdVn1F2A=; b=rArpQOEH27CIr0I8hashaebNsScn7AScmsimfcVe7KbC1aZLOQUsSZ2FqR+/T1mMq/ qMOXWs9SJ7YaLNf4Ir0vuNqzvxadWI/Zw1fujcpnxVKo3Eju96MuVwcDb0KR9Z8/EgTT dRXFMvw0JNLk/p2dtvAYH5ZNJUHlADvsEKkZfu6IXT4fh80jOWtI68guKcvRnyVhOLg6 YjCMakeF7ZxjndZ3yc8aBJDH+0Wq5lHufS6T7XT0pygecWreQl+4Sh0pu2wO3s0L6UTH Q5dneOXuQfFgHH+xzeb9inEZs0JapCxNFMwG9xVgMqweKlvm+CXNSzNLjN5xV84qOUJv 55eA== X-Gm-Message-State: AOAM532FCkxUhC/NkVEvgd6Kw1cyjMKiZrECsOgif8uu/SK4YiuRk2eM ZMKe6TN+HSrxKGLEQHdWnoWiYLP2RIDB X-Google-Smtp-Source: ABdhPJyk7eLr3v7GGHVTj3b0Fg8b8rE03/8EKwtkrKbbkLlkeWKRJLo0uuewYi/mOmaPzFLOBfVLnCEveLRm X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a05:6902:1501:: with SMTP id q1mr44908502ybu.580.1640848853774; Wed, 29 Dec 2021 23:20:53 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:48 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-8-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232055_396551_37957285 X-CRM114-Status: GOOD ( 14.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Avoid 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; } -static struct aggr_cpu_id perf_env__get_socket(struct perf_cpu_map *map, int idx, void *data) -{ - return perf_env__get_socket_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); -} - static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; @@ -1527,11 +1522,6 @@ static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *data) return id; } -static struct aggr_cpu_id perf_env__get_die(struct perf_cpu_map *map, int idx, void *data) -{ - return perf_env__get_die_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); -} - static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; @@ -1551,11 +1541,6 @@ static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *data) return id; } -static struct aggr_cpu_id perf_env__get_core(struct perf_cpu_map *map, int idx, void *data) -{ - return perf_env__get_core_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); -} - static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) { struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); @@ -1564,33 +1549,28 @@ static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) return id; } -static struct aggr_cpu_id perf_env__get_node(struct perf_cpu_map *map, int idx, void *data) -{ - return perf_env__get_node_aggr_by_cpu(perf_env__get_cpu(data, map, idx), data); -} - static int perf_env__build_socket_map(struct perf_env *env, struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp) { - 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); } static int perf_env__build_die_map(struct perf_env *env, struct perf_cpu_map *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); } 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, env); } 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, env); } static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *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) } int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, - 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 = cpus->nr; @@ -178,7 +178,7 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, c->nr = 0; for (cpu = 0; cpu < nr; cpu++) { - s1 = f(cpus, cpu, data); + s1 = f(cpu, data); for (s2 = 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 int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **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, NULL); } 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); } 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, NULL); } 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, NULL); } /* 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); int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, - 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 cpu_map__cpu(struct perf_cpu_map *cpus, int idx); From patchwork Thu Dec 30 07:19:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B02D4C433F5 for ; Thu, 30 Dec 2021 07:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=GsVe+XQb8nDD0zjA1FmW6UW/rg5zgRIkl8sAKvZDK/U=; b=T/wSrZ8ADKuJF8Yochz0tV1WUx mQJwXodADbETs9QLtYextMRltoSlW/l1w+WD3ulm4Gm/YAtu9/U48+MrosueNq3JFyCF4tFLSs0dy L67DrJOwXw37kXy6rruiHrBVfryGunwxy44xrf4ygrtsVonabJaeK2q4GzkXTeLZ2ZK3icJpwH4BH KBbl8X9PMmzwgZcB7kOlUS7UkYlz0Py29UyeLgvFOudsTw8u9so4tIabJoe05hFuwQZrQ9K1HKZkz stE2fa+KFNwMlg7mfSLIaFbOqeWz0CR9NaG0OpVVIXuHMLqStEJp8hcrZ+r8TveWBFN+oAy9hWa9m BvgFZvSg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pnU-003lCb-9Z; Thu, 30 Dec 2021 07:24:24 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkA-003jWI-CA for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:20:59 +0000 Received: by mail-pg1-x549.google.com with SMTP id k1-20020a63d841000000b003417384b156so5950731pgj.13 for ; Wed, 29 Dec 2021 23:20:57 -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=+LqJvo4BVSCC4z/ulo+DXz7muzrQZZ9UxIK0VJ0+cJw=; b=Zk0u1Y2XNOTQKFIxwDfroXvxum3RgRaYfZsIbytO+ukBLPO9fTAUoNU7fPjZWgJ4Yo lrJFeu2zX/DeksXGummcXomq/oZaGgC/c5sBvbXxLag2Ztd3IhyYTwFOz9H9xlKNMPgi NREQ/501fA1hGG2nELiUUdbrFESjSWkYG7kRZqxPOPiDeWvUmvAiTliMJ2HYcKjAwkmS 74VP+tIqqGyvYLYgUgeIVGTi/CURq+mRw46wHbWpx+2/QRk9RHEr1zT/G5wYjFOklOg9 jCdFhcQhqh241c36Fmqa7q7wLePsnCgXi64K7vLjrHer3/P/wL0+lIDo22DP5AKT50uM Mf9Q== 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=+LqJvo4BVSCC4z/ulo+DXz7muzrQZZ9UxIK0VJ0+cJw=; b=KReF7SHICL9ABxAaka/YGzK36xPls6EK/HBADRKYyY/3CCGq1Wcen1dwilxSUf+m6G e+BLa209tPoriqRip46cZXeTuyuc0u+pynf2ngXkHrvYWomVEPRxQX9nnQKIb1Wn5pWf w7SyHyuOfc7g43niwgsrCT1iLotzpYysyy94fYbHLZd3T3W9fTSP+prUm9Wmy4eAWZWc ya2u7DYt7dIhMfaDVQi4Bxa80u+3kkuerZ72ZaEDfEPedanQFHTNbGFq5ZsHMg7uu7bM DZaC/3smn2ak8qkjljkcxwSvUEvfEx8/askV3r+Iqr9gYqQfkMAd8888I5rHw10Lj82j csiQ== X-Gm-Message-State: AOAM533R64Xrn7miVuRJWGEcoC1KI1JcuiQPdCkf3RqeTNqronbPAOY0 q9aBntwMuhDWMcon/3yFSGSXRNmVFArO X-Google-Smtp-Source: ABdhPJyDsBDceOWBSNXUyP+oiQX6volW9+o6TW99zHzgGttRoX0f65hB71Y+QaqZq31SuAWqdGR3cp144g8B X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a17:902:7489:b0:149:2088:8e80 with SMTP id h9-20020a170902748900b0014920888e80mr29859106pll.124.1640848856490; Wed, 29 Dec 2021 23:20:56 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:49 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-9-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232058_447370_9C259C3D X-CRM114-Status: GOOD ( 15.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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_cpu_map *map) // Test that socket ID contains only socket for (i = 0; i < map->nr; i++) { - id = cpu_map__get_socket(map, i, NULL); + id = 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 == id.socket); 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; } -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 = (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, char *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, void *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; - s = cpu_map__get_socket(cpus, cpu, NULL).socket; + s = cpu_map__get_socket_id(cpu); if (s < 0) return -1; From patchwork Thu Dec 30 07:19:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 145CFC433EF for ; Thu, 30 Dec 2021 07:26:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Jzj4Jbz0nDyZZoJp8IdKXytgDDRCOz6FrH/YBUjgr1U=; b=Wr+WXCLSQtL+1TsCi8oK5tEsP1 lAvltEfav5jMvg74cqO7VRJWVxezKSnhwy7bth5tWXVtyJPeyZroRszDsMAhw20eC7S4VF8hCcl5H XSWz9wm9WP/ti93eJe7vCw5iZ1V5lDepzstje8aUi6sLBFouitIqoGPR0pnamwwxpwukGeLGLB2E/ srbkgCT25IrJUxy3Y1EenAR0zbyOKtE1z8FF4wY55aTXSeKB4CUNyCrbL6etvMEvF2YwFVvQBNIEy Poc3Z+lPmlTd5IuNirwQzCE3rHo5x7J7n7fJL8QF1fKuxVOtcMBy7kcyryk1gao4I5GlFYlTfNxAn ZLIL6LwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pnt-003lLR-8N; Thu, 30 Dec 2021 07:24:49 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkC-003jX4-Cb for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:01 +0000 Received: by mail-yb1-xb49.google.com with SMTP id z188-20020a2565c5000000b0060be1f32877so24505772ybb.7 for ; Wed, 29 Dec 2021 23:20:59 -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=I+B8qrA2cd/SP8Q+1EIjfviQAYs+Z/hoSScOqv9Gel0=; b=lCkRWKAn7Fa+jfz0d4hgkdKJv2mjjGswz+NBQBUOuRSoCdOBKJbyl3sEvCZH9S50rw PS4AVhK6dZ8fNZf57BsBrrGwEHk5IejbHwTK9PDcvy3qbM59VWWBOlAyxBkEbBUKzLwa JjQDd3iq9sNkIsH9g5Umm4CJ8rbSoehVuzGnUJIKTvNjp2GOCjWXCD91TgzHAIjaF5vc EuRtkvY2PYQ9GkbyJya3wkcWUDL0iLHN/fbnenkRx8SME6nB7Ga7R3Hu0eZPb1CFRiUU muh9+6RsbFN3cziMaL4lHVrztq3YFrdODhj7VSBN0UZ8Ufjj7wLpanYnbAtheK9k7dfM 65Iw== 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=I+B8qrA2cd/SP8Q+1EIjfviQAYs+Z/hoSScOqv9Gel0=; b=0tUgYR6pFd+bbdBgouTMhNWvRSI3TSWI7KADiQXD6l3U64ZGLglxiqnPUQA3mQWmjT aDuj2XzrmYUpE5PdGwcmxiNdNQU6gvHrfCfbjKwi+K4Zcz8xSH27mdBv+1zSekK/hQ16 l03ZWbJMDP6i4BwRkC2kj6bV0cAIbt5TwwvcEOktwQaNEQFb1KSxhzORGUyDtAac9Vfd IWZK+4KSgQ4fwyi3HbkFeRRwZyGzD3IKH8PkcYwe9eser1TJAQilwRW65KAmF+jY+8EH hoPF+6GRNa+Hru13IQvKX678dzG6hyw0my7e/WywbpXnrXR58BYBX14zlTUnQR6o0Ir2 fu1A== X-Gm-Message-State: AOAM531e81ey2lf87b5kc9R12ByOtG9bXxKqSp5+KT6/9/AfT4lYXwOz tOqWiN9qRJEgscFPS26psCb+XpCyaeLx X-Google-Smtp-Source: ABdhPJwyOytQjn1OiPL02zTtOTw3G5TCU33Bkd3QWN2ohtlxmVv02HGZDXzkKLx1KZIDhEkQYV0+4Ot4P8+n X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:2d6:: with SMTP id 205mr28389439ybc.425.1640848858996; Wed, 29 Dec 2021 23:20:58 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:50 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-10-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232100_457606_046513F1 X-CRM114-Status: GOOD ( 15.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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_cpu_map *map) // Test that die ID contains socket and die for (i = 0; i < map->nr; i++) { - id = cpu_map__get_die(map, i, NULL); + id = 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 == id.socket); 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 cpu, void *data) return id; } -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 = 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, 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, void *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 = 0. * We use hashmap(socket, die) to check the used socket+die pair. */ - d = cpu_map__get_die(cpus, cpu, NULL).die; + d = cpu_map__get_die_id(cpu); if (d < 0) return -1; From patchwork Thu Dec 30 07:19:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F3D0C433F5 for ; Thu, 30 Dec 2021 07:26:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vAlD3k0U2crucfw050PX56qjcZDHixkor4qsATBTyHw=; b=LHfMkDpkjkBBWhe988Lew4sYc7 moZqvVw2yoN+qAB1bLBv92k8SHZTk5h1lkARusBn+lxmsMQchzyWGr9sj0lOuzt9fYY3AQX8brctH zNluxSJlK51Sz/5wmKH4pPoPb6yQ8puXJOra5Fm93XSd+4lC+NxhTADg1WA9WPPI1HpTXIxFXe1T1 50z8gkTHigRBFCL8f1isfxps2Jp346pJFDSB3+Gk7KfWre9RI9PHSJNJblBY0HXQcfOLSwJ85o4V0 uyVWh1mqWaeS0noGO9gIKhaxuYbSfYSMHj0UFll8H7BUt3FnZU+1PQISMszlgPk5zMggsR0dqFjWi chFTLD9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2poM-003lVG-8R; Thu, 30 Dec 2021 07:25:19 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkE-003jYg-VH for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:04 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id c5-20020a25f305000000b0060bbdf755f7so25224524ybs.14 for ; Wed, 29 Dec 2021 23:21:02 -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=Zr180MbAuyMK3FOJ6p+f1v/pd05fFRyT7sFFspoiHfQ=; b=fP1j5ptzi9GlhwtnDvoqIyo74ilM6/YDYz1fP/LS32JpV9WtF2ADtQMONbQeWdcBNr OptvIPdqkgV4kFSvsZ1QsXNS2K/Fcf0b8RpyPjNxGoRbY1N1r2zcDhgqRSs2HDfVqH/+ yXYctxMFAYB0cC6EnjxMGShfoysusAOtFsfnbfE3RPCFMncRBow/76+4W4Lad2WBCEHK 2EiAKWKdDuKOuTbz8zTHq0zJxvWq16YJoFZyje/Ma+OF1LEZSt+XiXcUr6Gtz7wzmTZl ki3l4gK1+P/KlGJoKj19GUMOkhyCD2wB5KNtDjcyHF1aP97A4LhaJ7qQdZgUSvBcqdNv Prng== 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=Zr180MbAuyMK3FOJ6p+f1v/pd05fFRyT7sFFspoiHfQ=; b=Ol5ihufD72Afnl8YtBt2hYUxSQqgiJUidGMTiA5p090RGnw2fZNNCxM0g0SC6+I6Dh fBc0nTvYB9F2Kf4SB8C7D78jOD+EjNK3RqyR48IX/XTVhdkMLGySQe746WBnm92/d2Bm LEcP4qg4T5Qg537yQ1mXftCtckCH7HypSVk4bRvUUelNBOnlpomiFPS6dZY9MNSxq2Iy WNJOpdsDO2Ad6BJ4iEutE20sN4f7dW2DlUY4OASMurFAcNMjxCmN0QRBeFsh1uhhLUtr +zLVWkSICOdgh8VSKwJY452VE1WqTKBsrqr/jEnPhO9V7WZWO6gCjyciGkISn60ARjhD dUig== X-Gm-Message-State: AOAM533dtUj4JvvC92iqTy60BY4KcA6qBZ2gMpPM05FvooauSDCfa9dj sfG00R89+oU7E9b+IEDfQapWuXdWO+AR X-Google-Smtp-Source: ABdhPJx7W8qgBsUFQ6UIrvbnMt3qUKs9cQzNi3g3VfufzTwauI827c+pL7b1ClFQ+Ed/Zjmjs5ush3YBLm1O X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:aa34:: with SMTP id s49mr22340468ybi.356.1640848861508; Wed, 29 Dec 2021 23:21:01 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:51 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-11-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232103_052263_B9CD3841 X-CRM114-Status: GOOD ( 13.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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_cpu_map *map) // Test that core ID contains socket, die and core for (i = 0; i < map->nr; i++) { - id = cpu_map__get_core(map, i, NULL); + id = 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 == id.core); 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 cpu, void *data) } -struct aggr_cpu_id cpu_map__get_core(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_core_aggr_by_cpu(map->map[idx], data); -} - struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id = 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, 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, void *data); From patchwork Thu Dec 30 07:19:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 32F01C433EF for ; Thu, 30 Dec 2021 07:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=A8AtgFDog/b15qj4MxD8ESIVPqznQoBbwpXs7JpEcSU=; b=NHTvvRF4/5fL2ukp634DLs9jpJ k5Epjibx1vF9JSSLsAHbL0ZYSiiXAtMZ9WEbqr4XhAvoq3ZmGIS6SUQxYI4xQg8DItEUjKLj5VkH/ zJ0Ts6ObzXOqHQE3bJX/QXMNyvcoD4zCUCqfra+RxFjaQV9RdzBBPkOD8LKiNwG113q3xMCzMdtWl OKpNQuaSYH63U23OupbaaAbXzvgtCXH9N6XWlGTNrUjeC2I8DlAGpMfGTidn3J6VXgHNH5pez8w9t KnqQbQo5fcvsuPEOTUjeeuUTZqrHoulGuQTk9SUCcPG99Agn1bcCXaP7GNquAr+vkbFuluwQfbk0F hbH7ogjw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pop-003ldw-Qa; Thu, 30 Dec 2021 07:25:49 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkH-003jaA-Dr for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:06 +0000 Received: by mail-yb1-xb49.google.com with SMTP id b10-20020a251b0a000000b0060a7fbb7a64so31552432ybb.23 for ; Wed, 29 Dec 2021 23:21: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=K2wBwOVyFri8+1g7YkCIisUBaXjxQi5efEY6sDY0QS0=; b=CJTUF6zDYeq5qTNs4S2Bgt8Ohq8FeiKDhQOYQrrmiE+mH3/K4cAO+7RKiASdlFsx9s fuRSrF9pAt8UlzdMtMlK45cLLqZbXOUW2YeoVSIuP/nEC3EAvNIER8x2B7E/ZadQ2ZUc Yq/EKywuNW6UICj7/fynWjZ4XSvv3pe7trbZ6mU5am6Mc3jZ7dgOeAz6+nuFSrFqIB06 PGHRFVGjsraigcYwWyRxSEnC+UPxDYqEEBxoIb9UweiFldZ7lmVK8O7rgxrq7MTolwrG WBENKXUoy5MBaa9W47O1tVRb+vWfo1lbRlI9H3a3akkbTikQrHRBHpb7cwviz4pjQDes JrMg== 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=K2wBwOVyFri8+1g7YkCIisUBaXjxQi5efEY6sDY0QS0=; b=kR8ABv6oc/bIqiMbm1uksLgOVQX2y43B7xtZGQFgo5hfIwomvzZUS/oIYDbqmq2lUs om1ZB+XlaoIsIdABS86XGUsc8g2iB6CSpUpDuzfM/qsHDVH0qSVBGyLpoBTQmeg3GMp2 N7YWgO6mVRddyQLvdWtr1OLId9krB0nPKYj9/DcWkjiphUyPSG+RXRdANCbTB6c07bIA 5cZnGNfpYCs680j3yOMGjyY3S7rHwZhZQKkG8MZz3kYG160e3HVsgtOgU/AO68HT+376 9kulQ4eU0m8PKH5ZHhuvnxSMM99itXnEhSFgqUahQLQXyel3U9Iul2yVxw19BZHUSLGi CtPA== X-Gm-Message-State: AOAM532gOqJOdJMZOqPn6baNQ19Jm50lhBnRrFm6qBmtmg/nYo9govmf EgFG1I+ghOh8OJi65tP65fsPS4ACK1bm X-Google-Smtp-Source: ABdhPJzx+tHof3NXGXJpep4lJN+6fWEen68eIw6VbrRqEd2V7NbwMPWJdWJcWVSyB4fa8+3BhPNr9aeISY/l X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:5257:: with SMTP id g84mr19766158ybb.187.1640848863905; Wed, 29 Dec 2021 23:21:03 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:52 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-12-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232105_498360_ADBC9DE8 X-CRM114-Status: GOOD ( 13.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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_cpu_map *map) // Test that node ID contains only node for (i = 0; i < map->nr; i++) { - id = cpu_map__get_node(map, i, NULL); + id = 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]) == id.node); TEST_ASSERT_VAL("Node map - Socket is set", id.socket == -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 cpu, void *data __maybe_unu return id; } -struct aggr_cpu_id cpu_map__get_node(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_node_aggr_by_cpu(map->map[idx], data); -} - int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp) { return cpu_map__build_map(cpus, sockp, cpu_map__get_socket_aggr_by_cpu, NULL); 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, void *data); int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **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); From patchwork Thu Dec 30 07:19:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 58394C433EF for ; Thu, 30 Dec 2021 07:27:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=SvLcobQApLJeZ7si/LAPHl2szenbt+wtKSVujVkDlTM=; b=dyee5E3KAeEVctoQakWEdxIh6W SutttbKcxYdVX+sFr5buz0YWFySZpU3MDRbNrE0im7BcNDAlb9EZAldh/YQOKzapDKG3+CMcFLibs piTeYvK0CsVHmE/BAzj5lsVcOvHHBtkcNJXatsHrW4tzJ8viLY4kHZy5ARsZNCkiyjMfxPmC6lXSj sfEjTNLuenMDoQxbjuZn5cVSQ0qkp524tsQA6u2lgddRRMqGyyB+pUSFiK4a74DqicRWVf97zV1wv Rcl77vWl1tL4kgSWztqmE0R+8R15WCz+RzP9ldyNfPaR4Ba0oMbfk1GIRXf5BmMC/XFK/k00J4re5 51EWMi8w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2ppU-003ltC-Bl; Thu, 30 Dec 2021 07:26:28 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkJ-003jbR-Tg for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:09 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id z188-20020a2565c5000000b0060be1f32877so24506112ybb.7 for ; Wed, 29 Dec 2021 23:21:07 -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=dtLecDqeKsVhu8ABFSrCuZx030SIijpylbO9HpLxlsg=; b=KHZfZvYAwA/IYaOjhai7vtInLxNNN3S9V+/p7Pw5a+z9RAtEqsehux4DGdLx4VhvRT lx08Ihah9sKF6KPqndO2v13LhgiYbjOp/PtAAtuDRbE0I+yZqFAiFrx/1D4l50Btm+aH LaCAyv/7neOqqe/MCaSjbUdtzBPt0K7nbvug6vvmC8wLAscdtQFykMXf00q3lot1pmU6 TaXILKlaHmZam33/JQ/lQbw2o/zeoSbEbkxC2+aIAxdpyxBZIoTXNqxyVavb/yTrDvEE lQaEDyiKyuf1gh92/eBurKqm58eZmc5lEtVefKTfeVth+PzIxpgDqa9pze1+U3Y1t76l TDwg== 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=dtLecDqeKsVhu8ABFSrCuZx030SIijpylbO9HpLxlsg=; b=HLdwlEm1swuO7AbewVuHjDZ4f91x91dHtY9qRb09XyMkO03OrsVVGl74R3C/SQoY9w ACenKOaE/n037hcxYFYY+HWbAQfUMESolumFEmqoD+A8XdXkTILrWF+t+PHvW6Pt3hXJ wTua13jRG8q/TJHuVZzwHLOmiiKeOPUnx499c9TXN7uOEyEQs4to1KgyTE7pBTWYqORi EEDHlcy7Uk+uTZyHNP7dBd/sKtlHZXyr8C6ieEJvPnVONItemt+cqBaEHPWUv8v9KYvA fed5RUdD6sgCt2SB9TuKg4NBHZ5xXeMaP4qMlmQPt8rpXJUhJKXGYake57AGujIVycBz 06zw== X-Gm-Message-State: AOAM5314Q4VPSA67CfnjMBfJnoJ5p3Z4mvVaMUCtyDYSw7iEc0N+xcuY yerD0/jg3BDKZdWhx3o4EFsBg1roE8ha X-Google-Smtp-Source: ABdhPJzwyaiVjQKhyBRyvuUBgewdamGno0nty6HvW40cYTOPvP67uzaLSId11G5eVh0iGsfdFuOgj+Xy95mP X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:6d06:: with SMTP id i6mr7244528ybc.444.1640848866418; Wed, 29 Dec 2021 23:21:06 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:53 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-13-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232107_985094_AD67E5AF X-CRM114-Status: GOOD ( 10.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 +/** 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_id. */ int core; }; From patchwork Thu Dec 30 07:19:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB588C433EF for ; Thu, 30 Dec 2021 07:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hxbF+QT1f/D8Qkf3MoAaN+Ih2RStignQEk3WqC6RmFI=; b=CTz2mnd5XzLwr8Au0T9ks2zeMl 3/xuc+7qukQLOYQDAnFpUqMxk0DmDUfsOlPzMDhwOs14ORL4hJUeW1WN8JDefdmmxUQs6H0RrCZhA gfIie9FcqRvqI3f9rIBpyYWD6ePFtKSRFCpWYzQr4D8e2olt0cZGsT6bLIG2HZL5Nq2uK1ExvdJI+ i4QKRDGxK8bsqV4iHunBQd9ZHgqzBsLcOIpP2A+A2I482BTmXnNdGZHD3wO8H+9GiLtTowXwYjqUc cLDqKfkH6wNvodERz0CmcxHzRo5SdVnN4ykPamptI5+U4moOoRt5o2Wthh8pQjhdyqTXjTJELPYIy H0xWN/5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pqL-003mBi-M8; Thu, 30 Dec 2021 07:27:22 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkM-003jcT-9L for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:11 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id s7-20020a5b0447000000b005fb83901511so42326878ybp.11 for ; Wed, 29 Dec 2021 23:21: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=4MpQqbzavNLo0+7JIiR5CNmzapIg19tJzrEy7JBYf1M=; b=kXoA13WOKQIftVzZWO4HPUuV3ZzbRFc766qGcXsU5lIzsbLaWePjPAChzhTjJw18XB ezxaXy4Uv1c2Du76Ko4gwC91vIrvCM3ggm9zIVTJr4hexeJm4z6dvMdozbh8tGvq+zmd /QnB9H3gMb1zivqVAQeXMeGVnxlaHXv8Y/wELEKdnZWWfFBJBztyK0Z95UQkaz7Y1oOE W6ki6PrsFwHa4/GIZfRZCPC72h4gi1/a62TR89XKPRzbO5VWS/+G836nopw/oJN2MBJC CypKer12qZ2GIMtMWwW1YMrCovGqMQLyh5XqpGWQL7eSMObFVRg7vZAcaLpiqcHRikLJ hRig== 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=4MpQqbzavNLo0+7JIiR5CNmzapIg19tJzrEy7JBYf1M=; b=5AUvULGI/VLUPwfeRBy4FyNKFHPOoFzDZVCFnaD4gciceZCo8b4t6B+wu7+FFg0Hce nAxpt6EVws9IrY2SycwDRfu0728Zertx1HtTOcM68bqXANwO0+mF8RvAoqqWVeItU7tF iyVezmR8GSChDEOyB8U1FwCNTRkl3QoRgrY/GaE+u9yZOWT4mXmhr7ooyvnWxjdDZ34a qu3Za57fAdUCUbgPgMLc0mCZ2GBVPuGftC/44PTR6boaAL/OBuCEKxiUjDD6+ng75TLB 51bS70GPVc79k+7RURbBxs15wtYf+um15nQhpO8+CV0BK85OP+3/iUz+n08YDmTVpFtj utVw== X-Gm-Message-State: AOAM530/jhs9ZT1UExpAujVBMKxtY6N10iRfSVuUgxi0PtR5j0f+mlaP T4Ms5/u6zxZmNlKCHanXqUPV40Bpxaam X-Google-Smtp-Source: ABdhPJwE0WxTfbpAvt6d/swn2WJ5h727lammLK2k1Me4z1oYDnY4PoE78/VcpLfmw8FLS4n+YKUA4Mk3yljz X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:cdc3:: with SMTP id d186mr34482066ybf.400.1640848868720; Wed, 29 Dec 2021 23:21:08 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:54 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-14-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232110_349584_23475675 X-CRM114-Status: UNSURE ( 9.84 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, struct 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 */ -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); int cpu__max_node(void); From patchwork Thu Dec 30 07:19:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27410C433EF for ; Thu, 30 Dec 2021 07:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=s1YYxGXVlWsVZTfytiqiWsDSrVp/qp3Kx5zdf2ECcDk=; b=Qw4jGkPWZU9cW8k1NxFVpX0z+1 3M6Am4ZtSS0GTjxo2NlxWWwarJK9Tpz6CBwRjJTNttEedeXMSlQ3WkREgK9Tdee8LpvTlXCtqXeJ6 K3qx7ggooui9zyH/7zqSfSAqE0AwvAB10C7aUCDSFK1RwT+rZmGecvQlAw6mv49x3vK3PCbTOTQvW EiNiKBTFdtlq2W+6WDUhJ2OJwRTPkVPZUF1FJu7U5PRHR7cMQbKdkvIKlrhPZ//Udhl4kIHDK1/ui 3XIHVBW0kz4VfV7DOPP89a+58cxEj83HgRcNfd86xFbjioA04vKshacCg9IPZ7oDP0U0ol7R+RtMf n3aUiqpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pqu-003mQD-Mu; Thu, 30 Dec 2021 07:27:57 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkO-003jdL-VU for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:14 +0000 Received: by mail-yb1-xb49.google.com with SMTP id e2-20020a25d302000000b0060c57942183so22009010ybf.18 for ; Wed, 29 Dec 2021 23:21: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=Ka4x+Qhl4P+GabpPlEsQWrkqSEfXayZh0UqrTCL7G+c=; b=l4Ll7DnfcKDvo13ASsjpha0DToA1nSjSuNo2LCyuRPyjZeGGMUQIv+zn+iHCvLO1UI eZvqv/EN9EPIVk/I4Em7OIPWKPdealsVBT++pmgrjkRsU7J6lV3/V2Yi6/dyTTSR3j3k S/oFwX1pzrVOQzjT6lErYNGCUHCEq5gIc3rb498cD7tju0Z/r76LKYyI4zQE09XG/OhV TjefGGbgKaLPHJoSv4s4KSjzzkZ3zFAi4QLBqDSy6SykQ3zGW7aLuJQB/CQVWAGACmWX O2rOyMAHuQ4LUWUPL8pA3o9i0lAgAoWt90ifoa1HcKxejWGD9sBfvLF034OPIEoHRvm2 /Gkw== 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=Ka4x+Qhl4P+GabpPlEsQWrkqSEfXayZh0UqrTCL7G+c=; b=ETRDgGqWjW8FCsbvsT1EBwD9KqXFynTD9X3ZaOMNWjivWI+1aJNGc67fWbZff3c1OK qE6kZX6HjwzCWDym1rQLz/NBUcJfLdyFpc12hMypt8PCYGMorBawW5WcEVVBEsSdUQf2 2tu+5J96PvIfZHKkakC6nSs/8OqajWHOe3ARIzwbHzpD74pTTgX7DfeuK7GghdjLuS2K i/6jOnytRCCeLpgKLrJxFOaU0MAPCmTln07OXqG9S2C98pRSeLoNP5viqmcMpq5k50nz NDAkbXVD9psYqYcswjt8EsRpJkS5SOXTwIt8v5TOLHQwcJNWaYCMldZocNJnK4K/cPrC QxLQ== X-Gm-Message-State: AOAM531IMnIK151l8Vm5pvHwJF7R/2dI+xHG4Vbpte/lFNrNKhqAza9w /LKV4zgjboJVQLl/Ltt4+PkWBISqztMd X-Google-Smtp-Source: ABdhPJye+zNl3WxIrWb/2LwLPY3eXtUX25C8uxlJpSxQ5cX6uklGGxiji2nv1xRjInmw/+fGcceTSkA4DLCf X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:41d7:: with SMTP id o206mr12665538yba.78.1640848871248; Wed, 29 Dec 2021 23:21:11 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:55 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-15-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232113_102017_7820D303 X-CRM114-Status: GOOD ( 15.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, struct cpu_aggr_map **res, for (cpu = 0; cpu < nr; cpu++) { s1 = f(cpu, data); for (s2 = 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 == c->nr) { @@ -593,13 +593,13 @@ const struct perf_cpu_map *cpu_map__online(void) /* thread unsafe */ return online; } -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 == b.thread && - a.node == b.node && - a.socket == b.socket && - a.die == b.die && - a.core == b.core; + return a->thread == b->thread && + a->node == b->node && + a->socket == b->socket && + a->die == b->die && + a->core == b->core; } 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); -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); 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_config *config, } 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; if (config->aggr_mode == AGGR_NONE) - return id.core; + return id->core; if (!config->aggr_get_id) return 0; cpus = evsel__cpus(evsel); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { - if (cpu_map__compare_aggr_cpu_id(config->aggr_get_id(config, cpu), id)) + struct aggr_cpu_id cpu_id = 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, struct aggr_cpu_id id, int } 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_config *config, val = 0; perf_cpu_map__for_each_cpu(cpu, idx, cpus) { s2 = config->aggr_get_id(config, cpu); - if (!cpu_map__compare_aggr_cpu_id(s2, id)) + if (!aggr_cpu_id__equal(&s2, &id)) continue; val += 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; s2 = 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_config *config, s2 = config->aggr_get_id(config, cpu); for (s = 0; s < config->aggr_map->nr; s++) { id = config->aggr_map->map[s]; - if (cpu_map__compare_aggr_cpu_id(s2, id)) + if (aggr_cpu_id__equal(&s2, &id)) break; } From patchwork Thu Dec 30 07:19:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 887E6C433EF for ; Thu, 30 Dec 2021 07:30:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=qYtlj/KW47kEDCEqH77rCaWR1aQp5QbLuVi2+Kz94OE=; b=qFVPB1GgfBWn0KGUkwdYcVAx4a TEsd8+3MdimmtIeFQN8bzWjdPa70ENPg7RI2Ak1gTEO8aUWX7lv2uHpy7weErjNLFk9nW8LABz46F BBlB77PQ2JEVY3l0nQwrt//v+lyOJtoBnxWD5SfmmbR0ciJB2/usdg1DLzsCkrXcx3E1J1jJn7kzX 4vPU8LHKvs5qaLWDGSfEaxvEMPwmRCH7dyJrfeJyaQvXL6WInQlspglcnICi4oez1Gzvw0bH85RpR bNOQA/h9VZn0EzFhKH/fUh5PFmwrYK8b4OqT1vmNADFyqO2qbWUWWoCix1Xd4x5d9OqJgBjC2q/hp Z0JrmqlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2prg-003miz-V6; Thu, 30 Dec 2021 07:28:45 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkR-003jeE-2A for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:16 +0000 Received: by mail-yb1-xb49.google.com with SMTP id b10-20020a251b0a000000b0060a7fbb7a64so31552954ybb.23 for ; Wed, 29 Dec 2021 23:21: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=7nJ9aOY2C2GnsWnTQGBnrlJBEwWMod18BO03r+kibPw=; b=KWezbe3kkqPhJVVohiMlaiTOEk+T1iyv7L7SQrNAh7oF1e4VMmdNRhKKa1wNAd2OK6 Qwu0hPZiulgsvcHIj9u6XNurh/w9x++sISOXTc68b9DgjYWvrGewl96FQmNCXz8UyN9L dU495nJujAPGS1Ma12QbKw7l8sEe/zWI8c1+fGPeDz37mk1lEEGU43Jh8c4viwjGOsM7 dolbipQA5ILAJQ+tfw6QMzPP9ReNtr5HUPXvTlzMcCTjn7JeENQjPS+oTkQTGt2aO1G0 w+qxvpUVp0KWbenT+UqojIiKqBrKJVuqq1dK/uYtHMAbQMfOj+XY4qazQhOi3+sriIzX v24w== 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=7nJ9aOY2C2GnsWnTQGBnrlJBEwWMod18BO03r+kibPw=; b=tH3xgP9yvZFdSNXS3P37JnDMvGKNR+/PSPYgYLcehs5fi2HlO+OiBE+yBr3ITmh1wl 1KJKVAkhS5lXHZqQkZLxyQBl69D6zZfz42ahVbSYeF0MrR4QOZHIASQd7INFcHIiViPE ImH7dolnGvPMUHOZUn28nw4n/Rsfp7kKwwxik+5MLQblQD2JomPDY+ZK/ruhpWHMMm5Y 4PPtNf1XW9ZjeNDVqmZ91K0UdSupQjVI23EhSj07kz4UtXsotq2NUOsdtpy4yJ5wJDPk ACR1LQTZ0gQgmPeFf/bUwGrnT/y7ya0S8kLU4sPKaDIZIhRneS65sWg7tj4GeGrDXZRG pRhQ== X-Gm-Message-State: AOAM533h57YgMkPvrGulNLwoFdaIKEGei/8eg/DzkmdMhEXxVyMK2CGb Z5Q19YHrgRfv6uY9CO9J16yyHs1C+ntf X-Google-Smtp-Source: ABdhPJzov2mWeddkNNyT1ptl/wAa61C67X+DyXseDVp52ciwdu0LHcmg4sggAmCr1woeI93RSQ8d4qjzFAXj X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:da4a:: with SMTP id n71mr29939366ybf.600.1640848873588; Wed, 29 Dec 2021 23:21:13 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:56 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-16-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232115_186430_32D31802 X-CRM114-Status: GOOD ( 17.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *config, aggr_get_id_t get_id, int cpu) { - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id = aggr_cpu_id__empty(); - 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] = get_id(config, cpu); id = config->cpus_aggr_map->map[cpu]; @@ -1496,7 +1496,7 @@ static inline int perf_env__get_cpu(void *data, struct 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 = data; - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id = aggr_cpu_id__empty(); if (cpu != -1) id.socket = env->cpu[cpu].socket_id; @@ -1507,7 +1507,7 @@ static struct aggr_cpu_id perf_env__get_socket_aggr_by_cpu(int cpu, void *data) static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id = aggr_cpu_id__empty(); if (cpu != -1) { /* @@ -1525,7 +1525,7 @@ static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *data) static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *data) { struct perf_env *env = data; - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id = aggr_cpu_id__empty(); if (cpu != -1) { /* @@ -1543,7 +1543,7 @@ static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *data) static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) { - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id = aggr_cpu_id__empty(); id.node = 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) cpus->nr = nr; for (i = 0; i < nr; i++) - cpus->map[i] = cpu_map__empty_aggr_cpu_id(); + cpus->map[i] = aggr_cpu_id__empty(); refcount_set(&cpus->refcnt, 1); } @@ -130,7 +130,7 @@ int cpu_map__get_socket_id(int cpu) struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data __maybe_unused) { - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id = aggr_cpu_id__empty(); id.socket = 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 = 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; id.die = die; @@ -234,7 +234,7 @@ struct aggr_cpu_id cpu_map__get_core_aggr_by_cpu(int cpu, void *data) /* cpu_map__get_die returns a struct with socket and die set*/ id = 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; /* @@ -248,7 +248,7 @@ 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 __maybe_unused) { - struct aggr_cpu_id id = cpu_map__empty_aggr_cpu_id(); + struct aggr_cpu_id id = aggr_cpu_id__empty(); id.node = 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 == b->core; } -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 == -1 && - a.node == -1 && - a.socket == -1 && - a.die == -1 && - a.core == -1; + return a->thread == -1 && + a->node == -1 && + a->socket == -1 && + a->die == -1 && + a->core == -1; } -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 = { .thread = -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); 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); #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_config *config, uval = val * counter->scale; if (cpu != -1) { - id = cpu_map__empty_aggr_cpu_id(); + id = aggr_cpu_id__empty(); id.core = cpu; } printout(config, id, nr, counter, uval, @@ -780,7 +780,7 @@ static struct perf_aggr_thread_value *sort_aggr_thread( continue; buf[i].counter = counter; - buf[i].id = cpu_map__empty_aggr_cpu_id(); + buf[i].id = aggr_cpu_id__empty(); buf[i].id.thread = thread; buf[i].uval = uval; buf[i].val = val; @@ -868,7 +868,7 @@ static void print_counter_aggr(struct perf_stat_config *config, fprintf(output, "%s", prefix); uval = 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_running, 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 *config, fprintf(output, "%s", prefix); uval = val * counter->scale; - id = cpu_map__empty_aggr_cpu_id(); + id = aggr_cpu_id__empty(); id.core = 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_config *config, if (prefix) fputs(prefix, config->output); evlist__for_each_entry(evlist, counter) { - id = cpu_map__empty_aggr_cpu_id(); + id = aggr_cpu_id__empty(); id.core = cpu; if (first) { aggr_printout(config, counter, id, 0); From patchwork Thu Dec 30 07:19:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98CA0C433F5 for ; Thu, 30 Dec 2021 07:30:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=HI05I4h3qgqVjkEPwjzqbzBZuGjdPD7mDXOqYPgYjF8=; b=lGzJHbEBSBbEndKaf0ShyyCs9e KVXgX8Hmm6GJ/LDhzi/nVutsfqt6I9V7jQmyhCXitPbO4AbGqRYrwIiJJibzykx8jdOpyiIUJPAoi BgO3BbMOFkGYxmxIVikX7jmtIkWtr7w6RARnjzKvK+u/8ApHtWv3HN10FROAIrcAsG1zZ7Zncy8st ckfRsGkhYwgpg3nR7WSrtBF4smsOA5pQm0oPgHFBTk0F1+5n/y9fO0xNLgVY27GcT/4zwYQkhrD/B 2gvEXaHCkX+bil2ijLgEUSN4lFIf4POgP9L/8oZ0D3/YvPREYweraA7LAzDAuCmHKYUZ1VXX85hJ7 fxM0keBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2ps9-003mtO-9t; Thu, 30 Dec 2021 07:29:13 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkT-003jfI-Fl for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:19 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s83-20020a255e56000000b0060c46cc1890so21973385ybb.16 for ; Wed, 29 Dec 2021 23:21: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=s2CIczuM8teFDrPnQG9a+NBNIXG/EojqlmU2x3Abtwk=; b=No5depfbeojoeyTjZ7X0jeZ5N60dgn1waIhAAPmxijSgjjvbmxpqrbNrUkAB3+Mr69 D9/tyQ+u8+FsA37VLb8//fuHIgaidDofnkwF9plMWNjvW5eDyWJU4IYRgzqK5MzfHXbl DFD39l2AlagIiMWUgF6qC5WZ/PtkCs6uCh2iGeDvSlXlTIGUi+R18PzB1EGfafYHYoWl XD4d4tEj3reWUVc0ZK5+uwsh8k2vT9JMkHEFM23mPzxadL98HC1zIDPmSsNkUVq+Wxd3 cnG+lqKAwTYrG2r8++ivvKdhpB5zQ1WaR8lFH1YePvjKfQFl8FQPs9YKMa0Jv0rxKFPS OE8g== 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=s2CIczuM8teFDrPnQG9a+NBNIXG/EojqlmU2x3Abtwk=; b=RnxCXdKirvRdmzQu1HMxTS7Rpbgiav0d1A6+85SEbOYpmN6RZlS2o5lYnXhLa2cIgB ZB4pK6yd6B5TOZL2IQfkBLaQ1y2LxM6QcqZwtkjeckANM/5+7WL8r0b3ZcGD7A2vP3CB KngTHdUaszjKIteyHquRtxH+dG/QOjXg03eh0beUSSVI2/e5g9jhu5cH1E3yo7v6gkMb anpg2Jf882WfIWruAnhLmYd4WrIHDoy3z/w5UJFmU6qoYNbHgZdWTEUWD77Uql+5HTrh Sl1zl+KXrFODGi9dTZtBel/PDybYZzuv7VxeCABcDFo9SNuJHu8fjc54tHhPKzNhbXN+ OCTQ== X-Gm-Message-State: AOAM532q+p+v6LuxV8PDyqQfFXecJAkF1zsN7G4QXsy6MX9SNGrA1ay3 d4oDtyrqAQDi67e5tZPowFGNSvY6iGZC X-Google-Smtp-Source: ABdhPJy7jq3i4MC7xvQckm3znGI61lzyO5NMel4adhTbckf7FGFpxr8wOmkVWD/Q6KjYeJJ1bXu47PO66c60 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:770f:: with SMTP id s15mr20081478ybc.751.1640848875983; Wed, 29 Dec 2021 23:21:15 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:57 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-17-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232117_598153_ACAA213A X-CRM114-Status: GOOD ( 12.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; 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; } -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 cpu, void *data __maybe_unu { struct aggr_cpu_id id = aggr_cpu_id__empty(); - id.node = cpu_map__get_node_id(cpu); + id.node = cpu__get_node(cpu); return id; } 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_map **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); int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, From patchwork Thu Dec 30 07:19:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ECC13C433F5 for ; Thu, 30 Dec 2021 07:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1lnbOxs7zXuObDPeUzzSbluHGt7cT9FuRCHoEU970Xo=; b=HI+ARM6G8+7mB+2hIRLDHrRlAr WJE/tiJNh6TJZBZQ+8jKT3dRu1rqrKvgz3vyydK7xVD0BgdxzIR+ya78+HRlSEgFj7tT5ZRLfd4XC UnyLZHTxgL+T8LbUhyNRv+QVHY31B4Z9k28zoHNEMVg/Csd+ANfL29zxAG1RVFZLUIHLb90C5iUbR 5WUWyOfjrCMVIegJjdJW3sAoJKXjXN8znL3a3b1+yIHdho/BZ2vXFyWzfNpK+h5BORyBiP8Pp+iGM AUdhziecNT5zbuRR6vsYLWSte9KdtY8pSO5nyujikVEherepRlWVIgdX1IlYvuX3AJcb32sCTa9nX oUWktpWg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2psT-003n1w-Kr; Thu, 30 Dec 2021 07:29:34 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkV-003jgZ-Sh for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:21 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id q81-20020a252a54000000b0060af1d7e063so28809122ybq.17 for ; Wed, 29 Dec 2021 23:21:19 -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=AifZMWGIyf5BgdMB7L7Gxo1hfuqMZZOHTMlvW2tmWZk=; b=EMrauUzDbodQXwVdpajk++8ACumfHsWw5rnrHEA7W2d3tPfcEG+YABoeFwpYO6R8xD OAYOtmihvhRP8ucbPpYNf/Tk2uO30MPBjWuulUKEgCnNgJ9jM7b8fGpF5RaWioZlsnJU mjWVS+a/ICbzBZAn/PJYynTNsrKaHUAxfM/JoS1qbFl3T3KuvA7GYzN4eMfS1PKlcUU4 PCiHpnwRx/hQe/gqNRKKOpmNjZOpkx6h5UgIGsfY9iZl+75ojkXtaNMSIX56awzBkwUl XzKEpYranyKk9o8NN8RevLYYDm56BjHEfS9nKt0K2NxDzQTWviiw2LGkvUAroUFcSGs9 tXZQ== 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=AifZMWGIyf5BgdMB7L7Gxo1hfuqMZZOHTMlvW2tmWZk=; b=hLl19+a6OJWUBZJdMVCvPpf1AP58ZUBNZXHnxwO1gxvzGTwBNQN8BFjgTEKbgkUdJC 3HqUEwC5BY4ljz+3WGQEfBBZjE4H/hTfaVPnt7WGRj1/5fcloYU+g8MXxZ2Z7QHCNpvg I+8My4ut9wDkgDqqmw3s2qZVV4bknDimbOOmm/FRnC2KrUurJ6h2IEe9abAYh5qM4XNX vU/WzuEjXOjoGrW0yNm3fdTIRAseBzye6NqItr/bCoPDXtJ/Nm05zw+DWoFx/yhtWWt3 OiO2LxYYvf2i9MGKsPSb+tQgn2EvgbJkW0hnCjbe1gFgMYLOpIRLHOIAjzjUGmIYmaao hKdQ== X-Gm-Message-State: AOAM533XSk0wb/4jN9pxg1l7JTrOdxqX+hJWEUrIJPLouw0DEHSkEeRQ 89/YIQOeFeo12uU7IwvpaVbIzwfSzXKs X-Google-Smtp-Source: ABdhPJx5b7oGLyLSZ34IJBsIh09xOeq4tVXz+P/kHZaEMUthp6EESwZO6wRsfj1XpyJiLhMx1UViLAGDXLSS X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a05:6902:4f1:: with SMTP id w17mr2969824ybs.647.1640848878567; Wed, 29 Dec 2021 23:21:18 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:58 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-18-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232119_969834_D046F895 X-CRM114-Status: GOOD ( 17.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *name, int *value) return sysfs__read_int(path, value); } -int cpu_map__get_socket_id(int cpu) +int cpu__get_socket_id(int cpu) { int value, ret = cpu__get_topology_int(cpu, "physical_package_id", &value); 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 = aggr_cpu_id__empty(); - id.socket = cpu_map__get_socket_id(cpu); + id.socket = cpu__get_socket_id(cpu); return id; } @@ -190,7 +190,7 @@ int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, return 0; } -int cpu_map__get_die_id(int cpu) +int cpu__get_die_id(int cpu) { int value, ret = cpu__get_topology_int(cpu, "die_id", &value); @@ -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; - die = cpu_map__get_die_id(cpu); + die = cpu__get_die_id(cpu); /* There is no die_id on legacy system. */ if (die == -1) die = 0; @@ -220,7 +220,7 @@ struct aggr_cpu_id cpu_map__get_die_aggr_by_cpu(int cpu, void *data) return id; } -int cpu_map__get_core_id(int cpu) +int cpu__get_core_id(int cpu) { int value, ret = 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 = cpu_map__get_core_id(cpu); + int core = cpu__get_core_id(cpu); /* cpu_map__get_die returns a struct with socket and die set*/ id = 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_record_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 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); -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_map **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); + int cpu_map__build_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **res, 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 *env) return -ENOMEM; for (cpu = 0; cpu < nr_cpus; ++cpu) { - env->cpu[cpu].core_id = cpu_map__get_core_id(cpu); - env->cpu[cpu].socket_id = cpu_map__get_socket_id(cpu); - env->cpu[cpu].die_id = cpu_map__get_die_id(cpu); + env->cpu[cpu].core_id = cpu__get_core_id(cpu); + env->cpu[cpu].socket_id = cpu__get_socket_id(cpu); + env->cpu[cpu].die_id = cpu__get_die_id(cpu); } env->nr_cpus_avail = 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; - s = cpu_map__get_socket_id(cpu); + s = cpu__get_socket_id(cpu); if (s < 0) return -1; @@ -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 = 0. * We use hashmap(socket, die) to check the used socket+die pair. */ - d = cpu_map__get_die_id(cpu); + d = cpu__get_die_id(cpu); if (d < 0) return -1; From patchwork Thu Dec 30 07:19:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A815C433F5 for ; Thu, 30 Dec 2021 07:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LcTqA8CNpzYRrTxyRaMI+QHl1W1HePDXT332cTKgPIQ=; b=Psfwz1fYriIBirvomEMz9Ggxqv F00urypyzuaD3vW/Pr3lc1GX6Xjd8Ak+wrCWx0mUnmvw7enYzFTfG8wKjfkiGhwqP//05EqLZXJpB h0SzzzBhUIbsjA2Hn6QEYl1QnUHXqzGxli/zi9bkx312Jr8D/a+iN1czhr94FXs6Eyuw2lN50jaXV S/NRRHpymaqUGJgCsQ84BayQrlWB3N1eX6XVQBLeoibhqxrRQWb73KgjBLUot3/BuAz61yyK9xGuG 1zCOeQ9qiu3s2NPdmG1bFnDxHqyuRDq3lD/HpvxRF+lREvdim1rB22zKE/p882zdJ7M9Y00m2udxc zp76sYlQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pty-003nbA-OH; Thu, 30 Dec 2021 07:31:07 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkY-003jhr-Jm for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:24 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s84-20020a254557000000b0060ac37f4bb1so29559901yba.5 for ; Wed, 29 Dec 2021 23:21: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=hhL79Wui00dZGSHTjWRVzw6lUcXgmSFmqf1bVRl6br0=; b=W/fRAMC9kpPrEwbcvMgEXG7F9Cl6rN5fk2gbWiip8f1tvb35R7EkbWYsWtjKwnGx31 6458ZpyDPuljmbZitSfAoDeLyp+L4gLiUJOR+kUTuZUBzuGyqKOyU8gwb/VUn1cfu5Xb bSavnCEULtqH35kSm5tKiIv+7db4/OxK1ovSNMRYFHH6jKCDnNHdejGLaK5HH2+iSOGs U0P5lZmaJb7bnm0Zr+VXBFILii+scZ56YZyh67ksndHuLTRM/LlgcQK+aTJw3FiFU95O eupdDGJba1WEO5ZyEk3Pv2W5n3y290I1yiYCoPphHpGJip/SG/QRBLeQxQwg/WiHR1uF HZAg== 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=hhL79Wui00dZGSHTjWRVzw6lUcXgmSFmqf1bVRl6br0=; b=UbSurw5PIYtpSjsxmhU/VhHd4ucvyT6/96/T2uIInrpYMsVkw8nX5VKv4jtOnmd7K8 twO5L7JvkPhlG7PAQrGeDVWBcqQVbALS0Q1TxiIvnNjq/4W8qclDqIxdYiC6SUppaCqk yFz/DOTVBenlnB3WNGrUcM5VK21di5630P/tQi8oV23hGeYR0ugP61bMQi9aTMxabaQl GEFvdGiL5OYSHVQ0tJ0RNbsGTfpLGRSvN4TAxW18QG6QyZ3eMvbTHLXwQq+WO7IYiZTB Q84Ux262ZSRbLPghLmSSR6jApUI2I2qkUmKCBrxuPDVhWQ89+uwT49dEmhYy2/xJL1xj XymQ== X-Gm-Message-State: AOAM532QfbkiYKG6vyDxTAhRIwrX4gjiy+XC8caCfjeMbUVZwF23ScPH gpMeu83RWClaOmWZB0TBpUZvau9VY9CI X-Google-Smtp-Source: ABdhPJw354XwUZfwTBDRfRyvXFfv5WltLOFmo0PhT3He8ODD0IPkVaOuwJseB0/EjcNjYitQD/bT3pZWBsm1 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:186:: with SMTP id 128mr17816765ybb.244.1640848880990; Wed, 29 Dec 2021 23:21:20 -0800 (PST) Date: Wed, 29 Dec 2021 23:19:59 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-19-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232122_687553_1DB003FD X-CRM114-Status: GOOD ( 15.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 2b54e2ddc80a..f16c39a37a52 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -281,7 +281,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap) int ret; int last_cpu; - last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1); + last_cpu = perf_cpu_map__cpu(cpumap, cpumap->nr - 1); mask_size = last_cpu / 4 + 2; /* one more byte for EOS */ mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */ 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) != -1; } -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 = -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 = buf; unsigned char *bitmap; - int last_cpu = cpu_map__cpu(map, map->nr - 1); + int last_cpu = perf_cpu_map__cpu(map, map->nr - 1); if (buf == NULL) return 0; @@ -559,7 +554,7 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size) } for (i = 0; i < map->nr; i++) { - cpu = cpu_map__cpu(map, i); + cpu = perf_cpu_map__cpu(map, i); bitmap[cpu / 8] |= 1 << (cpu % 8); } 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); -int cpu_map__cpu(struct perf_cpu_map *cpus, int idx); 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); From patchwork Thu Dec 30 07:20:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4BA0DC433F5 for ; Thu, 30 Dec 2021 07:34:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=30r838NEWkWqNKQ5+ibUa5DAR2EGMjWF59VSddayovI=; b=RyuTo54+5R44/27LO2C9GBxySK elLzFGKkn93oUJa7y9QOgSLYHQEZuZA8CFMOUmkg7lfej13Ssej9NnTdJT+Ab4wfhSayYBn/Fizcw OdJGXsYSTxOAuyx8XV8/KMYtW6Z8sc6i2QNkmuIw0tYJWcqGWJ60ha7wZY4RFjFiMnP82Qa3uwPh1 unxf98V/51a1619KUtuc57O/MBiYAZjJVlx6h/m+rxzfWDs6BOwY69G7mnBcwgjtSllcJU46UP/bB G3ezdZ8sN+XT6MyiefQcF/5OtjcdR5hPZRXH/YNnhiZVs5sKmtNcY5Yh5yDJHo8YyIon3TRN+bu7p nBm82qjg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pvM-003o8Y-Li; Thu, 30 Dec 2021 07:32:33 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkb-003jjg-1F for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:27 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id p140-20020a257492000000b0060dbb88d8abso11649633ybc.15 for ; Wed, 29 Dec 2021 23:21:24 -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=reTidcldqC4oZu1iw2E8DOw3f09A4KICYcKP4xYiH4s=; b=qi/yL4YKwYAhgGO98IDPHAErh8pDNWejnw0TaI/CcyyTkpxtLTHJIsUg3TFpGjlj6k rnOAroU9YSskwGCQQsY0+yxt7l93xX10rzArxvdmAxxRsjg0nVaOKsajRftEeW4fCSnb iQCU6cZs62pJlIZotXFkKy5qGTj+wkpNdp2IGtxz6TQgXhbWAXvoX14GzMaZ9js1STWN EAiLNR1YuelmmQaLwZUmCj2EAeiIc0OycL8CCm+L90AKYt5gXUN3KB5unJDbQol7UG3B pLNR0NBJHR3S/uNebWvG4TSDZ+mrTeAIyn3QV+iKu0Fpsh7vl6V0CDBAZiwEnCyuLTy+ 1VXw== 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=reTidcldqC4oZu1iw2E8DOw3f09A4KICYcKP4xYiH4s=; b=MOMzla/HdJdvUy3YB9FKz9zdnZsawUqU17mUJcyzrLwghsZzS3UxuaicZIDBIQPENi ntGZvfyG3cDhRFOqf1TCJklEMp/lk16JuuktQRYOPj9pYOjNbWPNC36K8+wwHI2mgV3r kPNC5v+SxIicWfoMH9eFrY/Zw0xgF8nFYK/vU2iqae2dwMozBouG81coXttntcu2fAHL bO6bUTLslLjTBBKiaqZ3d+Hz8HcXfL/nWF0CN1jxkOguKdjyP2jCJ81jXEAEjafitYCY KoaAHwLvIPqp/z84bWDFTffTpIHpC1njO8lgywrRyXVbHNKNt/NU+zTf6IH+k+kzgmJ9 3Pbw== X-Gm-Message-State: AOAM531OwBn9V1O/oY23t0CXe5UfjEhq96uYiwNoGs71jHBTHRp6xzm1 6tz0gaaco4frR+2pEbPLK/g2xrfUHEtW X-Google-Smtp-Source: ABdhPJyJo8mpb/6k+cA/uVv5GF25Z8+31pz7XL2EidKpB5eOJ2F9XxDfyYCAa8vnqz4tMLH/wIiJVtTMdw+Y X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:4197:: with SMTP id o145mr19894151yba.80.1640848883532; Wed, 29 Dec 2021 23:21:23 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:00 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-20-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232125_128714_0CE0E9D3 X-CRM114-Status: GOOD ( 20.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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[] = { OPT_END() }; +static const char *const aggr_mode__string[] = { + [AGGR_CORE] = "core", + [AGGR_DIE] = "die", + [AGGR_GLOBAL] = "global", + [AGGR_NODE] = "node", + [AGGR_NONE] = "none", + [AGGR_SOCKET] = "socket", + [AGGR_THREAD] = "thread", + [AGGR_UNSET] = "unset", +}; + static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *config __maybe_unused, int cpu) { @@ -1394,54 +1405,67 @@ static bool term_percore_set(void) return false; } -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; + } +} - 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_map)) { - perror("cannot build socket map"); - return -1; - } - stat_config.aggr_get_id = 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 = 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 = 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 = 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 = 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 = aggr_mode__get_aggr(stat_config.aggr_mode); + + if (get_id) { + stat_config.aggr_map = cpu_aggr_map__new(evsel_list->core.cpus, + get_id, /*data=*/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 = aggr_mode__get_id(stat_config.aggr_mode); } /* @@ -1549,30 +1573,6 @@ static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) return id; } -static int perf_env__build_socket_map(struct perf_env *env, struct perf_cpu_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_map *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, env); -} - -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, env); -} - static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *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); } -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 = &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; + } +} - 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 = 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.aggr_map)) { - perror("cannot build die map"); - return -1; - } - stat_config.aggr_get_id = 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.aggr_map)) { - perror("cannot build core map"); - return -1; - } - stat_config.aggr_get_id = 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.aggr_map)) { - perror("cannot build core map"); - return -1; - } - stat_config.aggr_get_id = 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 = &st->session->header.env; + aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); + if (!get_id) + return 0; + + stat_config.aggr_map = 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 = aggr_mode__get_id_file(stat_config.aggr_mode); return 0; } 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; } -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 = (struct aggr_cpu_id *)a_pointer; struct aggr_cpu_id *b = (struct aggr_cpu_id *)b_pointer; @@ -157,37 +157,40 @@ static int cmp_aggr_cpu_id(const void *a_pointer, const void *b_pointer) return a->thread - b->thread; } -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) +struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, + aggr_cpu_id_get_t f, + void *data) { - int nr = cpus->nr; - struct cpu_aggr_map *c = cpu_aggr_map__empty_new(nr); - int cpu, s2; - struct aggr_cpu_id s1; + int cpu, idx; + struct cpu_aggr_map *c = cpu_aggr_map__empty_new(cpus->nr); if (!c) - return -1; + return NULL; /* Reset size as it may only be partially filled */ c->nr = 0; - for (cpu = 0; cpu < nr; cpu++) { - s1 = f(cpu, data); - for (s2 = 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 = false; + struct aggr_cpu_id cpu_id = f(cpu, data); + + for (int j = 0; j < c->nr; j++) { + if (aggr_cpu_id__equal(&cpu_id, &c->map[j])) { + duplicate = true; break; + } } - if (s2 == c->nr) { - c->map[c->nr] = s1; + if (!duplicate) { + c->map[c->nr] = 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; - *res = c; - return 0; } int cpu__get_die_id(int cpu) @@ -253,26 +256,6 @@ struct aggr_cpu_id cpu_map__get_node_aggr_by_cpu(int cpu, void *data __maybe_unu return id; } -int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **sockp) -{ - return cpu_map__build_map(cpus, sockp, cpu_map__get_socket_aggr_by_cpu, NULL); -} - -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, NULL); -} - -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, NULL); -} - /* 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 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); -int cpu_map__build_socket_map(struct perf_cpu_map *cpus, struct cpu_aggr_map **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 */ int cpu__setup_cpunode_map(void); @@ -75,10 +71,16 @@ int cpu__get_die_id(int cpu); */ int cpu__get_core_id(int cpu); +typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(int cpu, void *data); -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); +/** + * 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 passed + * 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); bool cpu_map__has(struct perf_cpu_map *cpus, int cpu); From patchwork Thu Dec 30 07:20:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 472DEC433F5 for ; Thu, 30 Dec 2021 07:35:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=sYJDT0VAtFtlsbNgoCNVp5/rIhW3hYUWKApzQjk30/c=; b=Mw2HK7WVYmvs5apMJSNJPP8OLi E1lew6Xmj6snl5JvoyAzzNFdVPiJpOHW/rFnEb+T3NrscLN/JrosKQ1YbT0krqJG/5e/n8XNszpVv 0hbcH+mtLGnBk8PGl5lmsjULluclpBSGD+sVWscYpaDjugglxKdEtpnP7nKNMkKmjYIdbDeSB1y3z THxDiD2qwbEMgCyjWXjW74HpbS+GLAGqsGz96FhCItBMkx/PGLZBjDVQl3IUjhOfgb/kEGTgDHTbN 6OvnjVbyq+8oVlqiedltPY05mlFh4JMoY4zRFkg0+yGhUUHhcKdDTpSqwVpr+Y5LQwO9felYxbf5I gb+22bKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pwt-003ofY-Uf; Thu, 30 Dec 2021 07:34:09 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkd-003jkv-Lj for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:29 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id b10-20020a251b0a000000b0060a7fbb7a64so31553579ybb.23 for ; Wed, 29 Dec 2021 23:21: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=7zTUY944ZaiFUvr/aBDiayJhvAA0WhQgf7pmUnxcZvY=; b=mAbWg8/tMObAV0F/xTx9pyrVHSDU7eQM3cU3SOwJMUzijzWaQpeDPtD7Ne+mLUC6IN CjE+3l2yJcBC99eGcnsM8UgwoNmSHrZgLlfu8dOUbq8RVASQNmuN5TgB92A48mAnT0jK lRdev93Typ3bpowNjoslfS7NFrVK455BePmP4RIypC/7BDjCXWgZf9G8pMBGFWo54Jjb bi8AkCSQNdQP0V9v4N7S0hkg6bQbdGFJX12C2rU8iXneAtoEo/PcUUmX26SlSbe07fqG adoZj9snS7HzXkZh5P27M1CtdXo7Au4VnPtTRwd+zXi6c0kxZccKq81p1lFkyr9B4KK8 NMbA== 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=7zTUY944ZaiFUvr/aBDiayJhvAA0WhQgf7pmUnxcZvY=; b=tfVoG26yG73LZwcVGi1mRLLOGQti4jH8a5tmC2R4beOUY0Fm9nkD0L4w8LoDxfY3Yd dbClQXbmAZgiBB57onwJCVVFv8v16lCUzwWUCTPjCSu60/enjmeXp2A+6xX7yOCwDm9u LOpfBl61UPQ32Ev6Fq5e8HOA8GGT1ODiESdAtewNzg6wga3fpmX07+9DCL6mEXI2Ae1Q Vaegl3kpKVoowtmjoEZwl/ku53oCic/BFrP4Z+wH9M+A9XP4KUkD/D+WKOb/3LTDUDaZ hJHS1X90PdIZYQ+pTt6kFZK/JQZc8GtevHwq5GnjvIATwWOjGvA4fRkVCSoNKaYzBhWI dXaA== X-Gm-Message-State: AOAM530UiILqbcNN9OzC/wzmfPwymCEdBmDR/8U767oWRl6QvFe2UoEX 3nL98XVPwwDqF9qe+TPiCwmmn3467ptB X-Google-Smtp-Source: ABdhPJxCNR5cTJ704J8ilKFXGTpMkKAlSmaHcJGG0XVlpnknDrlL3oVrzVhx0/c5pIL3v5rm8nY7p63k+sCj X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:dc8c:: with SMTP id y134mr11905346ybe.718.1640848886169; Wed, 29 Dec 2021 23:21:26 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:01 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-21-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232127_748638_918E6A3C X-CRM114-Status: GOOD ( 18.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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[] = { static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *config __maybe_unused, int cpu) { - return cpu_map__get_socket_aggr_by_cpu(cpu, /*data=*/NULL); + return aggr_cpu_id__socket(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_die(struct perf_stat_config *config __maybe_unused, int cpu) { - return cpu_map__get_die_aggr_by_cpu(cpu, /*data=*/NULL); + return aggr_cpu_id__die(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_core(struct perf_stat_config *config __maybe_unused, int cpu) { - return cpu_map__get_core_aggr_by_cpu(cpu, /*data=*/NULL); + return aggr_cpu_id__core(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *config __maybe_unused, int cpu) { - return cpu_map__get_node_aggr_by_cpu(cpu, /*data=*/NULL); + return aggr_cpu_id__node(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, @@ -1409,16 +1409,16 @@ static aggr_cpu_id_get_t aggr_mode__get_aggr(enum aggr_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; 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_cpu_map *map) // Test that core ID contains socket, die and core for (i = 0; i < map->nr; i++) { - id = cpu_map__get_core_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id = 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 == id.core); @@ -136,7 +136,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) // Test that die ID contains socket and die for (i = 0; i < map->nr; i++) { - id = cpu_map__get_die_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id = 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 == id.socket); @@ -150,7 +150,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) // Test that socket ID contains only socket for (i = 0; i < map->nr; i++) { - id = cpu_map__get_socket_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id = 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 == id.socket); @@ -162,7 +162,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) // Test that node ID contains only node for (i = 0; i < map->nr; i++) { - id = cpu_map__get_node_aggr_by_cpu(perf_cpu_map__cpu(map, i), NULL); + id = 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]) == id.node); TEST_ASSERT_VAL("Node map - Socket is set", id.socket == -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; } -struct aggr_cpu_id cpu_map__get_socket_aggr_by_cpu(int cpu, void *data __maybe_unused) +struct aggr_cpu_id aggr_cpu_id__socket(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id = aggr_cpu_id__empty(); @@ -200,7 +200,7 @@ int cpu__get_die_id(int cpu) return ret ?: value; } -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 = cpu_map__get_socket_aggr_by_cpu(cpu, data); + id = aggr_cpu_id__socket(cpu, data); if (aggr_cpu_id__is_empty(&id)) return id; @@ -229,13 +229,13 @@ int cpu__get_core_id(int cpu) return ret ?: value; } -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 = cpu__get_core_id(cpu); - /* cpu_map__get_die returns a struct with socket and die set*/ - id = cpu_map__get_die_aggr_by_cpu(cpu, data); + /* aggr_cpu_id__die returns a struct with socket and die set*/ + id = aggr_cpu_id__die(cpu, data); if (aggr_cpu_id__is_empty(&id)) return id; @@ -248,7 +248,7 @@ 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 __maybe_unused) +struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id = aggr_cpu_id__empty(); 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_record_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 size); 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 */ int cpu__setup_cpunode_map(void); @@ -88,4 +84,29 @@ 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); + +/** + * aggr_cpu_id__socket - Create an aggr_cpu_id with the socket populated with + * 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 populated + * with the die and socket for cpu. The function signature is compatible with + * 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 */ From patchwork Thu Dec 30 07:20:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AB306C433F5 for ; Thu, 30 Dec 2021 07:36:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=nOo6tDPfKQWTzyxbW0S/v5uUalhIY6nIHuDxaMjMHho=; b=OzlOOPtf3+IEIc5Bl+l8mwS7dL 8TbqBFynw+nFBYFqPXHYGffIjlEj+GIIZjxasmPz/z75ESWDBajQclsV1hMShVIqUX/L68i8YZ+CS IeknsQISgpltACjs3KLjPOmG3yuHVI+rdblh3RvEJMLrMvcCaRwqS3aPFqB4dEA8n6vlhTXxIHJte qwuzlUWyXxytJEByz8rpT2d8vz7f03Qq+8dRb7N8sn1IR3izfiJrnQstgDWh+pHlAqBTJvgJ/3S3j 3wwFNuVm365verNOsiUZjmFobQioGdQl9Y3BLgGlu30IL4ycqqpm43/hhxjePsSy/hHVF6LBaZ1Co fSgn0wQA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2py3-003p34-4h; Thu, 30 Dec 2021 07:35:19 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkf-003jmI-Tq for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:32 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s7-20020a5b0447000000b005fb83901511so42327817ybp.11 for ; Wed, 29 Dec 2021 23:21:29 -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=/eITL1ud9gY+pNLOxXpUZ+Agv/4R8qHeM61cfQMFl6I=; b=FXQki9PF9/r40bB/B/wEN5JugIfl1eU1ogXEYiMA55Ql0GGr5mdA5DZH2uKWLha1yA UqUiKDBU+mvJ7VhBzF8x4wHWyJNNqD9eTHXIiG0hLFR03LPky8D1BP579qRBhVTBekCd 78Alsd2Pbp529nPqNlMe7SZs8uBrJ1d1EZf9snuTd7OYi5CGOf1IOIfz+jhxyxg6D8eR G0TpFPuaxYpxL1n6f/Ur7ykXeiz0AvePqSo8aF4e1i52iI/ZX4NyMxWOjG2+cbtsXTRe iw/A19LIQ21BsGmNeG8ltnH0utNkvzxKbnZXO8XsM+y6++h9MPw9Dy2tj0kE/DqyCmX2 p/rw== 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=/eITL1ud9gY+pNLOxXpUZ+Agv/4R8qHeM61cfQMFl6I=; b=rKcjNcb53qWK8pL8kvTmnbMdi/Od1S9ZbtiAxyYBafZ31vhgg3LLp7ipg1E3GU3yUs O15cUX2P8gZPFEPQ2qXwr/rSvF46A7U/sOGKAwbp3QlGF01dw0EgynblCwCy9RvC0D2I SCJJjCbEacMyimuplrV86aU0GH+wYEvpEs8iDEusQGqJLyzv1vTXiuP7yLlOZUCuFtP3 dGEtmKY0DQjoSSYsFkiatoRM0XPvqp6NgSXsiHRH8wFI4jEt0rq5BagQb2WtldsAxekD R2FIsq0ki5Orihu0M3l13Tsst2UvfoV05playIWNh8xmQuzsJ8nMNAZadEx4YLEghXVo IBHQ== X-Gm-Message-State: AOAM530qU/JWuPUjS8WiKWWQaq3bkaefrhIQJBjQLOViLYRXKDUkUELz ouDoAhLTsc2pNm2yBGgoT1KvnPW70Ud1 X-Google-Smtp-Source: ABdhPJzEeaDm1Dy0zbYQ2MEb4aZRPZTf9RsIdHeGT3gBRWBmwg0kBQBZkr9mivj91qXcQWl0YNfIXejcTly9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:4188:: with SMTP id o130mr18341081yba.271.1640848888460; Wed, 29 Dec 2021 23:21:28 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:02 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-22-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232130_045120_4C2EDADD X-CRM114-Status: GOOD ( 20.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/Documentation/libperf.txt | 1 + tools/lib/perf/cpumap.c | 7 ++++++- tools/lib/perf/include/internal/cpumap.h | 2 +- tools/lib/perf/include/perf/cpumap.h | 1 + tools/lib/perf/libperf.map | 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 +- 11 files changed, 23 insertions(+), 22 deletions(-) diff --git a/tools/lib/perf/Documentation/libperf.txt b/tools/lib/perf/Documentation/libperf.txt index 63ae5e0195ce..faef9ba3a540 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -48,6 +48,7 @@ SYNOPSIS int perf_cpu_map__nr(const struct perf_cpu_map *cpus); bool perf_cpu_map__empty(const struct perf_cpu_map *map); int perf_cpu_map__max(struct perf_cpu_map *map); + bool perf_cpu_map__has(const struct perf_cpu_map *map, int cpu); #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) -- 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] == -1 : true; } -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 = 0, high = cpus->nr; @@ -288,6 +288,11 @@ int perf_cpu_map__idx(struct perf_cpu_map *cpus, int cpu) return -1; } +bool perf_cpu_map__has(const struct perf_cpu_map *cpus, int cpu) +{ + return perf_cpu_map__idx(cpus, cpu) != -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 well. diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/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 -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); #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_map *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); #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx); \ diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 5979bf92d98f..93696affda2e 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -10,6 +10,7 @@ LIBPERF_0.0.1 { perf_cpu_map__cpu; perf_cpu_map__empty; perf_cpu_map__max; + perf_cpu_map__has; perf_thread_map__new_dummy; perf_thread_map__set_pid; perf_thread_map__comm; diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 8a3d54a86c9c..129c0272d65b 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 *itr, /* Set option of each CPU we have */ for (i = 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; if (option & BIT(ETM_OPT_CTXTID)) { @@ -523,8 +523,8 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, /* cpu map is not empty, we have specific CPUs to work with */ if (!perf_cpu_map__empty(event_cpus)) { for (i = 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; if (cs_etm_is_ete(itr, i)) @@ -537,7 +537,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, } else { /* get configuration for all CPUs in the system */ for (i = 0; i < cpu__max_cpu(); i++) { - if (!cpu_map__has(online_cpus, i)) + if (!perf_cpu_map__has(online_cpus, i)) continue; if (cs_etm_is_ete(itr, i)) @@ -722,8 +722,8 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, } else { /* Make sure all specified CPUs are online */ for (i = 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; } @@ -744,7 +744,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, offset = CS_ETM_SNAPSHOT + 1; for (i = 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); 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 *sched, struct evsel *evsel, if (curr_thread && thread__has_color(curr_thread)) pid_color = COLOR_PIDS; - if (sched->map.cpus && !cpu_map__has(sched->map.cpus, cpu)) + if (sched->map.cpus && !perf_cpu_map__has(sched->map.cpus, cpu)) continue; - 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, cpu)) cpu_color = COLOR_CPUS; if (cpu != this_cpu) @@ -1639,7 +1639,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, color_fprintf(stdout, color, " "); } - 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; 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_cpu_map *map) TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu); for (i = 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; } -bool cpu_map__has(struct perf_cpu_map *cpus, int cpu) -{ - return perf_cpu_map__idx(cpus, cpu) != -1; -} - size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) { int i, cpu, start = -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); -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 = addr; for (i = 0; i < nr; i++) { - if (!cpu_map__has(map, i)) + if (!perf_cpu_map__has(map, i)) continue; ret = build_cpu_topology(tp, i); From patchwork Thu Dec 30 07:20:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701282 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2365FC433EF for ; Thu, 30 Dec 2021 07:37:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fLGH1efE80LQS9NHfe+J6eXRzBXxVUPsw6T5oH0r1os=; b=qeBI/O9N7qFl3U3DKnLTLslo8U +oKviT3Q6V6o0/0T5Lut3MQq96dNIeTcY4QNnUaG+qnZJsxad2MB1DEibybBGKZWcauF+U5VAVVbP AIo+t4M7/ZOvzmk2ii6NncBh+EknBzNplKWprDSApXqMyYYsiB/U5mb4Omy/HK/wmyQl/oG3j7X3E 3yfYHrsV3baSGzqtNOte7DZr9AArqZVwDYcAUsD32EOkFKR24DyDaAZs0ew0K+TR9RELgEnZs8goK ldnbNdGdHFGn5rWsF6elL/c3+6i6LBMTJCvKlhe/bl2ou5mvtlIl0iMEIVfzPGrbNCZvbLLF3tEP9 cX95y7KQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pyu-003pKg-C5; Thu, 30 Dec 2021 07:36:12 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pki-003jni-AA for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:33 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id s127-20020a252c85000000b0060be2b7b8e9so24393408ybs.8 for ; Wed, 29 Dec 2021 23:21: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=qNKIUlySFfRYFL3LsJVvo5UF9vFYVSjFaW2mryRhEhE=; b=gHS0SjBZ6BRQWd+TXVtPnKnWfJcnbY9nHdxIBK+Z7QvS0Q95E+qgPT9Ya5sOks/WiY 4Zem4Fto7v+P7JwneQD9j1lXQ1LbUplJc3+2O8g7ONNy81WKHt6g4Ml2Xs6SkZX025Z8 iDaQa1a1oP6oKjK3egsAXlt8/rJJBzky6vTRmNPGr87FjpRJRfHd7Vw8b0rPq6C+Um49 gbfuwDDOX85qnbbek6UG5obuNQVIjsV0KggtY7T91qLF3UQqN2wlemYjCnF94P7r25UG J1D0DqMFHrItaIXAV0wQ5/imijprO7coWMKhIMUA/pLbQUWgXl1bEwwvk7ZoGd/ysO4o rk6Q== 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=qNKIUlySFfRYFL3LsJVvo5UF9vFYVSjFaW2mryRhEhE=; b=yHhGVgHyU3Va0o3cLiq3L6+WCwaW8ebdrrVi+YhH6eeMA44wJZzD9G0KNMVNeW58KR OWXOMzWztJ1Q4E/liXqKuIfU8svodyGTbM6llstQ+2Pxbc3g5+2zJWBFDAnOkY9ODzHz rrv+ZfpwQRhYw48OfUcvXKoPhmISC6HUhxTDzvJ/CTnBcCI0IVMxX1ayVCCRflg9BGDR e0NFbh/xDxGferhbF4H1PPayR2o+W+qHSmLtKMRODZKiqmjnB16lA7vKtScA2mE+Ihtg W9jZCIsX6gGmRYnhVXKpTIaTWRcb2car/FXrAxncDplPpeDIsRzMxpnJCoyZQQG4Cyh8 ZUcw== X-Gm-Message-State: AOAM532Z3XxVtoz3MspbeZKkV5Mk/ylyl6CuOmBbpN6N5gQ8IPjjanVj Q0RPkyD0Lg7Rh3nv+pY6h+tnROvn1KaM X-Google-Smtp-Source: ABdhPJx57wn5jbgLGLHvQD+JHSSIIVUaMPZPQ5HbrR5jNwrjUX9bWwqhME1VrhI9+q+Qzab4hM5N5+dYdEIJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:abc7:: with SMTP id v65mr13083631ybi.280.1640848890846; Wed, 29 Dec 2021 23:21:30 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:03 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-23-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232132_433309_354776C8 X-CRM114-Status: GOOD ( 12.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }; +/** 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[]; }; struct perf_record_cpu_map_data; struct perf_cpu_map *perf_cpu_map__empty_new(int nr); -struct cpu_aggr_map *cpu_aggr_map__empty_new(int nr); struct perf_cpu_map *cpu_map__new_data(struct perf_record_cpu_map_data *data); 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); +/** + * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry + * 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); /** From patchwork Thu Dec 30 07:20:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A095C433EF for ; Thu, 30 Dec 2021 07:38:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Ej/217H7ME+5SbKhbCo5jpdGA4sYeB9ZzRRAylDvZZI=; b=BkTzmWpISkeL74ye4m5dz/M319 oauebtt9Z6xSZLkonLI/ve356irNcUbgDeh8x1xxSqminEdsVHc2K/5Z2g1+nugPugxioS1PB6D7n 4SWLUfqCZyuFOySOJ6OY3a0CKHFIIm4uhlm3xst6TiHMhTowQkMV7Y851L2O2AR0Z2x+id9D1hkQo pNDQIbz/285VAcEFT0L70Kyvuo8RoFhPp325km9QSOmiv3l4we1t4C62SLa2kDFgL0A0hZbkHB+ew ndxqC8dUS/nt3FkgPYGiU/BZ36mBzR0daXqJildTRojmqJUDYTLSTMdxoSZYhP7MTAVYdXha1amLq XZ/RUUTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pzu-003pem-0c; Thu, 30 Dec 2021 07:37:14 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkl-003jpE-5G for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:36 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id v189-20020a2561c6000000b0060b5814a17eso26924596ybb.22 for ; Wed, 29 Dec 2021 23:21:34 -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=ue3Sc4M2PULu8G7idSi+UKsFDq60wD74fexukfC/fcc=; b=RgPIJ3CxdVKGxX2ivNN+mgiAZhGMJAf1uHegdL57m4nmFBiLW3Qn3c+ZILE9tq9Air xst/+qnStFVCVDhPXd/IPYhpO6+twqIagXmvBSogWBbWSATGCxRP/c6vJZ1On8xt67+M +feHKWUZtWQ7d4J3af5NGYMfnl/axYLQ+162n+io4k8+8CF32Ehr/wotZ/Gff/l695X4 8GVqDKz3Q968rvD/nBwJc9Lr5yg0ntqZwjoxXGuzSSU3X4iuwOdjxDlRRaGT16cF47Wd z1CaKAW6EtsSkJrW0ulwWiq0ciymoN6H0bwPRV+Dar41+Vf1FDKvAXg1SQTcz5aLCSfj kf9Q== 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=ue3Sc4M2PULu8G7idSi+UKsFDq60wD74fexukfC/fcc=; b=1a0L5Tdao8aoxD0zBZCtfa6plcCjQE0Y4w24lnV6ht2BIHct6QiRSIWt/VwgKnK75P I+ABxCs9XJMjoyutZMNNRomnfLBpcTl+9i4BceyYHm1ThjsYD5a3X5Nq+HyobGxF0TZG LLdC4fZfZt062KjkFH6TZdLg5HIw6sIvLUzx9NYk1UHWYjkWfnqXTfqVSSwl13RmXu4i uBac7rg2MDXDkrSjtd/+mLq0lBm64XujsFp7m3KDaXcKrFs4fKtHSG3g6hkp/Fmkp411 AS6Tq69OlcFO+LLADFtu/v42KLadamxovJHBLBCfuL5pU5GvdVdHHHABV5IRB9oXQgj0 L1iw== X-Gm-Message-State: AOAM532MFDFAQKABGRXWJp2oVl10466LFZ1hoyaDOCinJqvJyWYTalQ6 uJPvoRmy/DovRt/pyOSY4JIk8km2sZwz X-Google-Smtp-Source: ABdhPJyIaLxKF2hCbxmhSNGy06maxPg4IbLH5POO5tfbw+284KED4uP0dg5+jywJRRp01yc2Rq36s6WeqcaB X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a05:6902:702:: with SMTP id k2mr470352ybt.66.1640848893417; Wed, 29 Dec 2021 23:21:33 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:04 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-24-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232135_266984_66CFD542 X-CRM114-Status: GOOD ( 13.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 8a72ee996722..3061b4369ab5 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -185,7 +185,15 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, c->nr++; } } - + /* Trim. */ + if (c->nr != cpus->nr) { + struct cpu_aggr_map *trimmed_c = + realloc(c, + sizeof(struct cpu_aggr_map) + sizeof(struct aggr_cpu_id) * c->nr); + + if (trimmed_c) + c = trimmed_c; + } /* ensure we process id in increasing order */ qsort(c->map, c->nr, sizeof(struct aggr_cpu_id), aggr_cpu_id__cmp); From patchwork Thu Dec 30 07:20:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F258FC433EF for ; Thu, 30 Dec 2021 07:39:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Kayvjd5U4BPdHqfjr3P+JZ66lBSPGQnNsz+ShrB841M=; b=r3tXdZEOsejDCn8l+/qdBZqlb+ y0S3qEuKlZFP5yQ/vQDJhwX/2GzvZ9hOiUHxKXlFku9eRG++9YfCVsYBev+B0fqDQVC04hibt45rr N0JDfBS6pJf0Lid5gCuUh4cBWBhFxcCa1vmQbv49wxvv7C7aOho+/XWr7hiPmnCJ5ci67hg0tmwGt CIblfTq8iRkMqvaChj3ZDLHYiDBtfmsAaFquzJLdtowsg7GAH5fcr3wUYfan1TI5gOH/iZddevHwy 8P7Uj1XqT5ChEjmo0F6+pRpxV5bhgyAEtr/KwXNGpE99Sv3aZxVL+WsvttANzrpu72CqtzdaOq5x5 aVqMySwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q0f-003pvU-UI; Thu, 30 Dec 2021 07:38:03 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkn-003jr7-FW for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:38 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id e137-20020a25378f000000b0060c1f2f4939so23367954yba.3 for ; Wed, 29 Dec 2021 23:21:36 -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=r8DPKd9/Sw54Ic+0J53LiDeJxVBy3KIktvCz7ol2teU=; b=Y1olYxL5xdUbS/5Pur5YSEFeIndFNzsuvsDwKkPACbpQcTfSpvtFSjcBTYFJCD3T2R DhjEeBCngbuFsTWdcHY09UHqCJ5h8gHusC2bMXCZSlJpIxdtOxQs5aPD4P7LtihMm8c3 vz5seXS3n8pqgqhoF1uTJlZL1bAVkbmcmebD7kQkYt8wOh4q7GEfPAjLsRqJW7wh/beY +qb3x1Sb8X9eGeDRssv1t7Z04GNyYaojaBVX5aj6vDum9cTWKxXJRhZT7BtTowMAoga/ /XIILBYPx7eY9BDFL3pK0OPbnsrEK5oT/Kjm7eqV7tWYMqgqxHU7Xl+QE6C90QyzAq7j schA== 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=r8DPKd9/Sw54Ic+0J53LiDeJxVBy3KIktvCz7ol2teU=; b=eHPUvLMQfcVmSKwEnKSlCWyKHdRR4NCR29OUo8sQZcJjBw+SZuDMhxizyBCwuW72Yf onedRlovrLdBtNub8zc/fnkg3wSBcKG4DOzhIg01+jyiZYFMT1GIHesGdWPIQGh6Z0Kp NCFia7i66yc6ClePT/VfFOWw25wUivV2m/7NRLqnhhdHMnNPtlZcgFT6AFHiW9iMwCYQ fG6/cRtE3m+BXZFF9sewaB4uxZwjYqBcPPZrWH0hmyTpujGXGuoqUCqZrL7ZNv55e7CE SAYgEI7Z7qvAvvAQ5DMzW2mTkSpTa4mHh4HZNXPFZIoKdS/ySdaDq31sE+PnmGh6PP6J tq1g== X-Gm-Message-State: AOAM532TItupwo4W30nFPn0W+q80ZokyCkZWkLE9UjcqxEfb3aGn0meM 9V2F6UH085ndjIg1dOEg60+HK+r1ljdL X-Google-Smtp-Source: ABdhPJyO73+i/r0f/wr2X4131/M6h8Mhaxy8uZEgH3Y5Xbw/y8CbL842aFLHLlGs6FD/PPgL2o8I90TL0Brz X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:a184:: with SMTP id a4mr36612571ybi.56.1640848895883; Wed, 29 Dec 2021 23:21:35 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:05 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-25-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232137_558639_CFC77910 X-CRM114-Status: GOOD ( 12.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org If the key is already present then free the key used for lookup. Found with: $ perf stat -M IO_Read_BW /bin/true ==1749112==ERROR: 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; *key = (uint64_t)d << 32 | s; - if (hashmap__find(mask, (void *)key, NULL)) + if (hashmap__find(mask, (void *)key, NULL)) { *skip = true; - else + free(key); + } else ret = hashmap__add(mask, (void *)key, (void *)1); return ret; From patchwork Thu Dec 30 07:20:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701286 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A47FCC433EF for ; Thu, 30 Dec 2021 07:40:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=JeM2FBwdauDvF/bdZEd0kkCjEsciUpCDOjp/3R7IWoU=; b=sWk0S/tCH6O7KXW8hto+5/OuuE oKOXeRIflBk8hHdpo791BwJB/vwkZYX9LJSVVwyyzBvNGG6NOBCtaSlNTYcqozVwo3feTiGwE0EYi j6fAiuaFmO5zr15OXT2AOwO7bgyFm8L+PItqLMg+n8YSI6bb97IGARjBrznTGjv8j4FFV3YZ2GCoG qfXqqTIC+27KGWrVuZopTTCBqU6pnb6pdKCKtwK0c0hJP8fNgp+70+b7kMg07RxQmKAi86mIXxCZ0 Dc6T7zl1qhYrY7GYkCZxCwnSOJTk61nKgZTFMXgqptgA5Lzw95rwPV/bZwwosRBqB+wO6pXlLerjW 6E8tlWwQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q1O-003qAq-QG; Thu, 30 Dec 2021 07:38:48 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkp-003jsu-Pw for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:41 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id a9-20020a251a09000000b0060b2c94d515so27974138yba.20 for ; Wed, 29 Dec 2021 23:21: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=JcBOvoOB6bz+f9apalH9PvD6p7uYZTZUpuIqSucas7I=; b=qfPll0zXIpZd0mhursgxv6qAKe/3/oXYx1fBwsAlcFaW/kE0YjlvB0TVLItmDE0W8d taGgpUf1UYP9Sv+AyfeqsOUjOfFEI4Ef6SVvfIClH7QdlHHbkN/h5jo2LJJiFblBYY9r XbUGs/cWiOrrHY+M+KE0TbYGonCiA/lxew3UNpdxzx6ayVp9BGEOc2JpBje5ApVo4Iss QFICFIwvzGJLFnuiqC7tr0ef+9B7u/G5l018X/VBQoztQIkYuRBc3mYKmDWdg+sEnisX Lhten+AkM0QDmesV5dngVBsWWz3jBl4PdfixCZ98AG6y8j2WUya12xlvCQ9ajEBrZBm5 /4bw== 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=JcBOvoOB6bz+f9apalH9PvD6p7uYZTZUpuIqSucas7I=; b=ackzUbs8dmPGXKBfHX+wAtvXiUoderipImJFsw30VbvagUBKA/SKzbY2AGJiMvpc19 3Zd7cPeSdT6UApWI+rwUqkx5b8AxkAvWrlgS+tWnTCem8+Pnukx92efkA0FjoFBP6vWl 3U/RqFlo26O2qVnbUSmqWrRr1puyM55/KTclxPohTRPjKsuFyqmZD1bjUpqFJ/VhSB/7 f4EGQmMYYOxU14kXrrJDPL4jM8Z1YBPHt8fUMXVK2dZVLk6NNkdDw9VXbUHcsKEw/T66 wnbBeyNtPmEuqC7GATAaTyPbUg8tp8woTtEVA9wbyw8+MWXdOOmKKXpwAlKb/8eQTf03 OPvw== X-Gm-Message-State: AOAM530v1EuCjZiYHctwd8Mp/SEgw/FAeVZXmS8Pui6y5/PzWDt6JWr2 KDzM7Byl3ueKsCabLUfo3GObkDkjg+Cv X-Google-Smtp-Source: ABdhPJxY9eLc6Arz6WZuotoqfrpXixRRBcnFUDYcI/QNsjPjwSU/HdSOGNFeLpXf6A0bp9CLH5GKekPWvxwp X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:6d08:: with SMTP id i8mr38499126ybc.706.1640848898352; Wed, 29 Dec 2021 23:21:38 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:06 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-26-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232139_960329_1AD5C68D X-CRM114-Status: GOOD ( 21.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 | 25 +++++++++++++++++++++---- tools/perf/util/cpumap.h | 8 ++++++++ 3 files changed, 48 insertions(+), 4 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); } + // Test that CPU ID contains socket, die, core and CPU + for (i = 0; i < map->nr; i++) { + id = aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL); + TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", map->map[i] == id.cpu); + + TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", + session->header.env.cpu[map->map[i]].core_id == id.core); + TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match", + session->header.env.cpu[map->map[i]].socket_id == id.socket); + + TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", + session->header.env.cpu[map->map[i]].die_id == id.die); + TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node == -1); + TEST_ASSERT_VAL("Cpu map - Thread is set", id.thread == -1); + } + // Test that core ID contains socket, die and core for (i = 0; i < map->nr; i++) { id = aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); @@ -145,6 +161,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) TEST_ASSERT_VAL("Die map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Die map - Core is set", id.core == -1); + TEST_ASSERT_VAL("Die map - CPU is set", id.cpu == -1); TEST_ASSERT_VAL("Die map - Thread is set", id.thread == -1); } @@ -157,6 +174,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) TEST_ASSERT_VAL("Socket map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Socket map - Die ID is set", id.die == -1); TEST_ASSERT_VAL("Socket map - Core is set", id.core == -1); + TEST_ASSERT_VAL("Socket map - CPU is set", id.cpu == -1); TEST_ASSERT_VAL("Socket map - Thread is set", id.thread == -1); } @@ -168,6 +186,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) TEST_ASSERT_VAL("Node map - Socket is set", id.socket == -1); TEST_ASSERT_VAL("Node map - Die ID is set", id.die == -1); TEST_ASSERT_VAL("Node map - Core is set", id.core == -1); + TEST_ASSERT_VAL("Node map - CPU is set", id.cpu == -1); TEST_ASSERT_VAL("Node map - Thread is set", id.thread == -1); } perf_session__delete(session); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 3061b4369ab5..0abbee49f637 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -242,7 +242,7 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data) struct aggr_cpu_id id; int core = cpu__get_core_id(cpu); - /* aggr_cpu_id__die returns a struct with socket and die set*/ + /* aggr_cpu_id__die returns a struct with socket and die set. */ id = aggr_cpu_id__die(cpu, data); if (aggr_cpu_id__is_empty(&id)) return id; @@ -256,6 +256,20 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data) } +struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data) +{ + struct aggr_cpu_id id; + + /* aggr_cpu_id__core returns a struct with socket, die and core set. */ + id = aggr_cpu_id__core(cpu, data); + if (aggr_cpu_id__is_empty(&id)) + return id; + + id.cpu = cpu; + return id; + +} + struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data __maybe_unused) { struct aggr_cpu_id id = aggr_cpu_id__empty(); @@ -579,7 +593,8 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b a->node == b->node && a->socket == b->socket && a->die == b->die && - a->core == b->core; + a->core == b->core && + a->cpu == b->cpu; } bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) @@ -588,7 +603,8 @@ bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) a->node == -1 && a->socket == -1 && a->die == -1 && - a->core == -1; + a->core == -1 && + a->cpu == -1; } struct aggr_cpu_id aggr_cpu_id__empty(void) @@ -598,7 +614,8 @@ struct aggr_cpu_id aggr_cpu_id__empty(void) .node = -1, .socket = -1, .die = -1, - .core = -1 + .core = -1, + .cpu = -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_id. */ int core; + /** CPU aggregation, note there is one CPU for each SMT thread. */ + int cpu; }; /** 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 *data); * 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 socket + * populated with the cpu, core, die and socket for cpu. The function signature + * 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. From patchwork Thu Dec 30 07:20:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4D39EC433EF for ; Thu, 30 Dec 2021 07:41:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=aYHc8JNSkuPEP6nD3vI3zt4INtY0uswgWdXplZoIuuk=; b=CwFNz1GpDst8VwZJfzjG94JWzi dNXEr9a26YGqpfHzKGqJOrLPAFn0tgHh8IFQsyQFWcAg63pyFB3dG83cTteHoa7dv2k4SgntARxon C0W2hxTR1sGRtwDVXzGNDUeJM70V0KhVJtzVBd1Y07dujj1sBsARvfFtuIpLL6WV2rEN+92AxX1nS Mo5kZHVgmyIIqjeH9qmz6/7nizj9wFYB8CNAwDJYk1TUVp9rTsAGkjsxN2FuSRuq8O9oiCqmEmJwC NbaHry/fJ7Lpjpk8Hoc2/tP0YtgwpyRBs4QpwM2xYevZNGpaTJviZIRcwjnQzoh24Ybm31751Bqju A+9ufr+Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q2L-003qVW-AM; Thu, 30 Dec 2021 07:39:46 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pks-003juE-3F for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:43 +0000 Received: by mail-yb1-xb49.google.com with SMTP id c132-20020a251c8a000000b0060c39ab7d36so23100507ybc.12 for ; Wed, 29 Dec 2021 23:21:41 -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=MyX41obsfTbklj5mP7URo6KOdoHhcEiYJDRkMl7AGdI=; b=LObQmT9LTPmbnq9p8gFeTKDRdvi+Xxhm9mKW2yrrqr1LRU3ZF6WGa7V0yeYNIS4Zry NUTNYXdHzrCU3oIbpmoNuJHFNr8Ng0dX7xOg93LGT7MCK6h/96Cb/j9IY+PIU9aRHKqG Vd4GwDaAeVv5FiPnEQdwhSoi6xjxrVFv8uMNcl8/J7FTXqfpE5FmcRHU8FN5OHHDM+4P G7UD8KHB8IRx7wC/Yfq+TYH84JU57Qn7AuwtwCkL0ZGonCLpbr3xAHaLNus6twfEffHk 7tADUxWwhCVTT2OFimaZSXicJDYt8hRNHsXofd8Bv5vB7CCTcsobzpPmZ5N4uwLbrsZF sP8g== 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=MyX41obsfTbklj5mP7URo6KOdoHhcEiYJDRkMl7AGdI=; b=rkmQFIB0FO7RX15V80I7mVlR55Re7kxAY/Z/OqcK6SYgtTzlXIy3KZUAwZb0mjAJA5 ja0pR0tG4HEnEwhjwD1YQevcyVLbH4MxpNSHTealEC8usCQsvdD/osplB0+SbEfx8kM9 q0AcKJJ99hqFdg1k4rjMScU43RwTFgCBYm/ynphkRmstBSITIvFJmr9ZeJZr6nrge0z2 ZHI6DkfDJH5H1qGztlCAXr5fvTR/UCmrO1yzqGeOqhL3WumwqMt4xLbbUNwb3zzgvhFg xBuenHBViKGbsxFDqcXTARjySviAmnqQx1opJQA1cywW0UR9KvByPmbaRDJoFVc3VZ8G bXKg== X-Gm-Message-State: AOAM5325QZQMcpc22CI0Rbi10zRSGndIexlbX+ruiIZAzyNCbtMGUBcs NhgwPInL5eLkRVCYYTtiHXSq4qfW6qJV X-Google-Smtp-Source: ABdhPJxRg4qJJebeV7CpE9vROn1liGtbz9yh2zMu7YKeoig64yqoc+FZQDgbYrhwZMJdAyp1bR9sXlKR/2Ee X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:7dc2:: with SMTP id y185mr35577232ybc.352.1640848900528; Wed, 29 Dec 2021 23:21:40 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:07 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-27-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232142_193199_14A27243 X-CRM114-Status: GOOD ( 15.17 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Correct use of cpumap index in print_no_aggr_metric. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 45 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 870b1db71fbc..f48d1678861c 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 *config, 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 *config, int cpu, idx; if (config->aggr_mode == AGGR_NONE) - return id->core; + return id->cpu; if (!config->aggr_get_id) return 0; @@ -697,10 +696,9 @@ static void print_counter_aggrdata(struct perf_stat_config *config, fprintf(output, "%s", prefix); uval = val * counter->scale; - if (cpu != -1) { - id = aggr_cpu_id__empty(); - id.core = cpu; - } + if (cpu != -1) + id = aggr_cpu_id__cpu(cpu, /*data=*/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 *config, fprintf(output, "%s", prefix); uval = val * counter->scale; - id = aggr_cpu_id__empty(); - id.core = cpu; + id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); printout(config, id, 0, counter, uval, prefix, run, ena, 1.0, &rt_stat); @@ -924,29 +921,31 @@ static void print_no_aggr_metric(struct perf_stat_config *config, struct evlist *evlist, char *prefix) { - int cpu; - int nrcpus = 0; - struct evsel *counter; - u64 ena, run, val; - double uval; - struct aggr_cpu_id id; + int all_idx, cpu; - nrcpus = evlist->core.cpus->nr; - for (cpu = 0; cpu < nrcpus; cpu++) { + perf_cpu_map__for_each_cpu(cpu, all_idx, evlist->core.cpus) { + struct evsel *counter; bool first = true; if (prefix) fputs(prefix, config->output); evlist__for_each_entry(evlist, counter) { - id = aggr_cpu_id__empty(); - id.core = cpu; + u64 ena, run, val; + double uval; + struct aggr_cpu_id id; + int counter_idx = perf_cpu_map__idx(evsel__cpus(counter), cpu); + + if (counter_idx < 0) + continue; + + id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); if (first) { aggr_printout(config, counter, id, 0); first = false; } - val = perf_counts(counter->counts, cpu, 0)->val; - ena = perf_counts(counter->counts, cpu, 0)->ena; - run = perf_counts(counter->counts, cpu, 0)->run; + val = perf_counts(counter->counts, counter_idx, 0)->val; + ena = perf_counts(counter->counts, counter_idx, 0)->ena; + run = perf_counts(counter->counts, counter_idx, 0)->run; uval = val * counter->scale; printout(config, id, 0, counter, uval, prefix, From patchwork Thu Dec 30 07:20:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701288 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 34B18C433F5 for ; Thu, 30 Dec 2021 07:41:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=uBN45QwFwNsgxr4hJLxwh8W+haeYSSYQ51A+heS6T/s=; b=PoktfTl81gpRdU1ZIdbV9p3Sb0 ONDdh3fys0iQcHGXy/+OQgI2JT0AALphYK4FA/F15RquPQs1L+Q3OljnXrlOJQ9dcrSiMHHMxqI4j wjNqQ97IzAPmPgIxKb85te4B4vMl8g3l2wGKKVw4sc+1O1cQs5rGhyy+ytk8EZTqyOAyjDpHTTphO 3NYDkQinGGwABXp/jvRBc8ZU+Gmwe4gM0W75sN0KRWJ22G3qH041WrI0yXUvHGRRAps2Mlp6sxctO b4h6Y0XxF91qITOGYMwLaA4NWRbEfNKn/icI+L1s2RtqIMk/rY5rjpM2z7+em0lv4jZ6ByIfO4L9S wFmHID0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q36-003qn8-Aw; Thu, 30 Dec 2021 07:40:33 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pku-003jvd-FL for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:46 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id e137-20020a25378f000000b0060c1f2f4939so23368297yba.3 for ; Wed, 29 Dec 2021 23:21: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=2sPeS5hD6XhbS/KjXnNo0OQBT3AjJJ8ohyesk40XqcA=; b=tJn/3vBsNja0qeXl883/xxbHELrwxgKo1sNalJX4VKGqHdMaQAmQO/shvgknHoc20k Wy1h3O8ZkUEHFeaMx+GRIgsVrhVg3yzTjiRwQN15CqIvWj5r4hIiGXcXYqvmCDPH7YRa H/7PFZClYW2AgkrSUm7TwyNEOcb5qMG05dElb/aPW+0zYDh0IQ5dBH79SjlQQlQ6O2RU HU/GGDRaz5cfQxdixtftY16QfhgaiWR4rs4hW6qsHHCHReWoLBa6f0J15X0NSTVnOfZM mWvweMatEKnK385MFfoXm4IqO7ZV+yVGamaWCXo2jWQ4NjUmtjf5+g81KRofdroW2HOp 8mOA== 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=2sPeS5hD6XhbS/KjXnNo0OQBT3AjJJ8ohyesk40XqcA=; b=JfYyUxWOmSZ29HhUGSsSNouWlxOG3GhFjyvIsnf6bfqqEjmR5QRsMXWl8s/ML6lwMP l82m5gIy/jftpEayruuKM+Pup1zdBYJ3u3mTy2QN2fQM3xVT9hVxxKV/zO3yd/4S021T 9IPEsXHkhFUEUXFa12pj1zvcjkUyEsS3flgHcI2yiAcs/SkziahoXXwuBfx+gUrg/H7G mJEomyNrR/GeytrzavexuedZqI6e1MrNpK+/qf35Pv9Om/xVmBUxkVw55r1rVMhDJjQ1 xqmez3cBkTz65jmLe0ApBTEU/kWDjPJqC9OMTWh7KzjcIJHPmEL7R1IUwS9SDX4t9EVi hUYQ== X-Gm-Message-State: AOAM5334sEsBZttfTT6frYVB3fzI0ezfP0rAVYWcNL4N92/mj23Jle9q yL2l0FfT857r7tdBASZER19luwSAOX7D X-Google-Smtp-Source: ABdhPJxIJGv5f32bbnWDxoBjOZ4z6bbGu5gRAbrpbKMmKOETGNeJLi2vdjFJ5lE/6B3uh3efUR3ZLq/xtbT7 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:9b02:: with SMTP id y2mr1548457ybn.210.1640848903013; Wed, 29 Dec 2021 23:21:43 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:08 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-28-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232144_575834_34E1ACB9 X-CRM114-Status: GOOD ( 20.87 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 openat-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); } - /* - * 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=%d)\n", cpus->nr); - goto out_close_fd; - } + evsel->core.cpus = perf_cpu_map__get(cpus); err = 0; 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 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); } -int evsel__alloc_counts(struct evsel *evsel, int ncpus, int nthreads) +int evsel__alloc_counts(struct evsel *evsel) { - evsel->counts = perf_counts__new(ncpus, nthreads); + struct perf_cpu_map *cpus = evsel__cpus(evsel); + int nthreads = perf_thread_map__nr(evsel->core.threads); + + evsel->counts = perf_counts__new(cpus ? cpus->nr : 1, nthreads); return evsel->counts != NULL ? 0 : -ENOMEM; } 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); 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); #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; - if (evsel->counts == NULL && evsel__alloc_counts(evsel, cpu + 1, thread + 1) < 0) + if (evsel->counts == NULL && evsel__alloc_counts(evsel) < 0) return -ENOMEM; if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <= 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); } -static int evsel__alloc_prev_raw_counts(struct evsel *evsel, int ncpus, int nthreads) +static int evsel__alloc_prev_raw_counts(struct evsel *evsel) { + int cpu_map_nr = evsel__nr_cpus(evsel); + int nthreads = perf_thread_map__nr(evsel->core.threads); struct perf_counts *counts; - counts = perf_counts__new(ncpus, nthreads); + counts = perf_counts__new(cpu_map_nr, nthreads); if (counts) evsel->prev_raw_counts = counts; @@ -177,12 +179,9 @@ static void evsel__reset_prev_raw_counts(struct evsel *evsel) static int evsel__alloc_stats(struct evsel *evsel, bool alloc_raw) { - int ncpus = evsel__nr_cpus(evsel); - int nthreads = 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; return 0; From patchwork Thu Dec 30 07:20:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C659CC433EF for ; Thu, 30 Dec 2021 07:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=tLHpvrs2P118Ty54LWMhrpvD+YqM/fquXE3zO3UWuXo=; b=STSCeynnRTD73VchB8ZsDWOrRz gTpNgtZ0Nk5Y4VikmNUubUaocsOuyCd3HAhjRFwfsISIa9WYwRKwXe2jhp/UAHuSELaTAUypZy86/ 6i3J0o5FyJHo+EyQ0V7r/Rew2eCZ7X5+FDwEpnAZ78GDuuCTavqugvEYqLwXl4S9638DtDkw8i5US r2n7H8kkIfCEDLbPmxAXmqLRPyB/kWeNpvV7GPYJVu+T7m1n6Z0I12lE2iFB68X8O6Te/M5f7XhL3 a9j6sYpwU67eQL4NoCROVQazmvARwLbigaiAVXDimZMTuX+C3y2f+GmzYGrDJ+4CMT2/2PD7Ew1eM ofvP+emQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q41-003r84-AM; Thu, 30 Dec 2021 07:41:30 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pkx-003jx8-23 for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:49 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id a9-20020a251a09000000b0060b2c94d515so27974432yba.20 for ; Wed, 29 Dec 2021 23:21:46 -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=jSsFFLhWB7MnpKAldIeOinUTQRyOvwUdMysgsTlE4q4=; b=WZTt7fIDiyBo9rt7z2dTw3jUTc3Mqma7DWNCYi+Wv+rmH4n/xtiw8lg4TUvJlS+9ww o7l2oEZcI/1zAOik7aYEnrZdY5HIG7aF2gI3MKerJLTCywCEvCjufgtICX4MPGXaBnOw 5elXjlugQs2PCzOR+HC2Ioa9528XDe0Q5phry+ZuePY5NMDX8syzaCilc4R8o4ir+si7 a23L3yPT+f0KFFqymtpiwn2d6BaruTFHGfku1mkW0o5KDaL+Cj4TMPUWiV/4azfUOW4n FeIJxtdhPsvVBznimjF2PUe9KCLG3X8PPrw767ChK9UvmNjMgIUu9pGrLxe6wD7T1P8r lyUw== 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=jSsFFLhWB7MnpKAldIeOinUTQRyOvwUdMysgsTlE4q4=; b=5zcXIxBANzk3NjluwjgKG3WRPv3hcegwgdGnlcGIy9OQPTiWTM4I1+hkoAaTJZqKQd b9YCR0lkRZtWSqHCL9EQ9pvJdEaoNHr0h4Jroj4nhV/oK+RW8G7qWaqZ/S9ovtrGrBUm mB4obFETGiGXx3J8iNRy+Z1YOcmKHzt7bpf3pG4HrEG+/4EHIGZ57vUEhTXgoG3dTRFJ L/AntB8shR09IfNjRKB5d5CBFVZcoQ7SgFNIUoH4QKdwZo4Iz3TJuzE+x3+3h3S5IXIh 1B+uugdE28U/UoNwXJUj2gCKVKDKO87lb4Tdeh+EaqO973QLPNkB7qj6iVVpYHhmzei/ RYPw== X-Gm-Message-State: AOAM5336OIBvuIyzNdhPDXe+n3fyuhtOeZLSEG9Bzjn9Tleig5kQ0XEq SDVVRZhJovVMeigSB3+gUbCev6puFgI2 X-Google-Smtp-Source: ABdhPJw7fj6ApL9Z9gutmoKsdimI82WAuhQEcciATSD/AQuKtYsrclmu+VR4MS55zWu8zWBrzH7d+Cv5BMy+ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:8c9:: with SMTP id 192mr37166693ybi.102.1640848905438; Wed, 29 Dec 2021 23:21:45 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:09 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-29-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232147_183037_26E2BB63 X-CRM114-Status: GOOD ( 18.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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); } -#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->mmap, 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_map_idx, _thread)) \ + : NULL) int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads) { evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int)); if (evsel->fd) { - int cpu, thread; - for (cpu = 0; cpu < ncpus; cpu++) { + int idx, thread; + + for (idx = 0; idx < ncpus; idx++) { for (thread = 0; thread < nthreads; thread++) { - int *fd = FD(evsel, cpu, thread); + int *fd = FD(evsel, idx, thread); if (fd) *fd = -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); } -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 thread, int *group_fd) { struct perf_evsel *leader = evsel->leader; int *fd; @@ -97,7 +101,7 @@ static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread, int *grou if (!leader->fd) return -ENOTCONN; - fd = FD(leader, cpu, thread); + fd = FD(leader, cpu_map_idx, thread); if (fd == NULL || *fd == -1) return -EBADF; @@ -109,7 +113,7 @@ static int get_group_fd(struct perf_evsel *evsel, int cpu, 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 = 0; + int cpu, idx, thread, err = 0; if (cpus == 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; - for (cpu = 0; cpu < cpus->nr; cpu++) { + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { for (thread = 0; thread < threads->nr; thread++) { int fd, group_fd, *evsel_fd; - evsel_fd = FD(evsel, cpu, thread); + evsel_fd = FD(evsel, idx, thread); if (evsel_fd == NULL) return -EINVAL; - err = get_group_fd(evsel, cpu, thread, &group_fd); + err = get_group_fd(evsel, idx, thread, &group_fd); if (err < 0) return err; fd = sys_perf_event_open(&evsel->attr, threads->map[thread].pid, - cpus->map[cpu], group_fd, 0); + cpu, group_fd, 0); if (fd < 0) return -errno; @@ -165,12 +169,12 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus, return err; } -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; for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) { - int *fd = FD(evsel, cpu, thread); + int *fd = FD(evsel, cpu_map_idx, thread); if (fd && *fd >= 0) { close(*fd); @@ -181,10 +185,8 @@ static void perf_evsel__close_fd_cpu(struct perf_evsel *evsel, int cpu) void perf_evsel__close_fd(struct perf_evsel *evsel) { - int cpu; - - for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) - perf_evsel__close_fd_cpu(evsel, cpu); + for (int idx = 0; idx < xyarray__max_x(evsel->fd); idx++) + perf_evsel__close_fd_cpu(evsel, idx); } 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); } -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 == NULL) return; - perf_evsel__close_fd_cpu(evsel, cpu); + perf_evsel__close_fd_cpu(evsel, cpu_map_idx); } void perf_evsel__munmap(struct perf_evsel *evsel) { - int cpu, thread; + int idx, thread; if (evsel->fd == NULL || evsel->mmap == NULL) return; - for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) { + for (idx = 0; idx < xyarray__max_x(evsel->fd); idx++) { for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { - int *fd = FD(evsel, cpu, thread); + int *fd = FD(evsel, idx, thread); if (fd == NULL || *fd < 0) continue; - perf_mmap__munmap(MMAP(evsel, cpu, thread)); + perf_mmap__munmap(MMAP(evsel, idx, thread)); } } @@ -234,7 +236,7 @@ void perf_evsel__munmap(struct perf_evsel *evsel) int perf_evsel__mmap(struct perf_evsel *evsel, int pages) { - int ret, cpu, thread; + int ret, idx, thread; struct perf_mmap_param mp = { .prot = PROT_READ | PROT_WRITE, .mask = (pages * page_size) - 1, @@ -246,18 +248,18 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int pages) if (perf_evsel__alloc_mmap(evsel, xyarray__max_x(evsel->fd), xyarray__max_y(evsel->fd)) < 0) return -ENOMEM; - for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) { + for (idx = 0; idx < xyarray__max_x(evsel->fd); idx++) { for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { - int *fd = FD(evsel, cpu, thread); + int *fd = FD(evsel, idx, thread); struct perf_mmap *map; if (fd == NULL || *fd < 0) continue; - map = MMAP(evsel, cpu, thread); + map = MMAP(evsel, idx, thread); perf_mmap__init(map, NULL, false, NULL); - ret = perf_mmap__mmap(map, &mp, *fd, cpu); + ret = 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 pages) return 0; } -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 = FD(evsel, cpu, thread); + int *fd = FD(evsel, cpu_map_idx, thread); - if (fd == NULL || *fd < 0 || MMAP(evsel, cpu, thread) == NULL) + if (fd == NULL || *fd < 0 || MMAP(evsel, cpu_map_idx, thread) == NULL) return NULL; - return MMAP(evsel, cpu, thread)->base; + return MMAP(evsel, cpu_map_idx, thread)->base; } int perf_evsel__read_size(struct perf_evsel *evsel) @@ -303,19 +305,19 @@ int perf_evsel__read_size(struct perf_evsel *evsel) return size; } -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 = perf_evsel__read_size(evsel); - int *fd = FD(evsel, cpu, thread); + int *fd = FD(evsel, cpu_map_idx, thread); memset(count, 0, sizeof(*count)); if (fd == NULL || *fd < 0) return -EINVAL; - 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; if (readn(*fd, count->values, size) <= 0) @@ -326,13 +328,13 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread, static int perf_evsel__run_ioctl(struct perf_evsel *evsel, int ioc, void *arg, - int cpu) + int cpu_map_idx) { int thread; for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { int err; - int *fd = FD(evsel, cpu, thread); + int *fd = FD(evsel, cpu_map_idx, thread); if (fd == NULL || *fd < 0) return -1; @@ -346,9 +348,9 @@ static int perf_evsel__run_ioctl(struct perf_evsel *evsel, return 0; } -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); } int perf_evsel__enable(struct perf_evsel *evsel) @@ -361,9 +363,9 @@ int perf_evsel__enable(struct perf_evsel *evsel) return err; } -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); } int perf_evsel__disable(struct perf_evsel *evsel) diff --git a/tools/lib/perf/include/perf/evsel.h b/tools/lib/perf/include/perf/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_map_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 thread, +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_map_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 *evsel); From patchwork Thu Dec 30 07:20:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701290 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 690FEC433EF for ; Thu, 30 Dec 2021 07:43:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TaoQSjFCvizHYNNoCS+IyieEpMTZqTF/mJ3uU8QY4qo=; b=htp9r8gYIEQIRv30SEWqvc3sk1 tPltCgEDgukmQE4yOGc04nwVeCgNg9ihCcaNQMJuh2aKNHjIsNSB5wxOg9K2Qg1QlaUnhIIwUjmI+ wQqlAt1nmYiwv6WZUGksscyv0OeDyAii1wRhtb4B8DfmhacAZthcCV0E3V9gnFeepoPvhthvLFqOf fprmqeCUHx8pUp6pSiqHhQ34wM3YlJlOMT3GJsnqV7NMHGtHvLSIKouv8pKfyqz90V+dgSNjsrSq9 xpuXk063FhIYo8HCVSsCBQ6pc+RibRQ+Vh53QVkptqXLLoObFCYTGvrQsMYqKScCbar6dujW03JCr Npbk+Eow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q4u-003rRa-3e; Thu, 30 Dec 2021 07:42:25 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pl0-003jyY-4Q for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:51 +0000 Received: by mail-pj1-x104a.google.com with SMTP id 35-20020a17090a0fa600b001b160e1ecffso15226768pjz.9 for ; Wed, 29 Dec 2021 23:21: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=awNrzmXXwhgHegLo/XT1TXhJodtpZbEQSRhdkuOAA7A=; b=PG2diDhkb5i7ogEM5VvdDCDHxrJYDQzZwNMq4MtIk6SnVaypQKlShQlUuhPeWSh1Kj 9M8Nl+9CT0Y/Ky1eReJa4PSxNm1ytCwF+LS/7ujzbJjxZ4+XUVv5Bdk8GosiaZTAl/6M 8tcxJEC4yJm/wkb+WvldQ1MQYgmCNlxI8hqiLP/wVqcSslcgrguLVYHYPbbblV48U29N JV+LjNQSQ6vDw1hMQM96+0C/QIZd/mqyfXunlffbLoNv/HbwW2IBG3Ge8ZA0SLLvTEES tJK4vRxJokHa8njyWH4u62vFUlBP1RbQrPlCb7O0keKwoVCaXXVdTVmMZvbTfgRZLWML a7IQ== 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=awNrzmXXwhgHegLo/XT1TXhJodtpZbEQSRhdkuOAA7A=; b=7Sza8XZT20xceKtO50WCGOPOvPD6Ct8YtT7kG0uCFi7cP6ubndtVY2scAuEw451qdo DryC20MClh1te2mI03Z+jvjy0WHU4xVhpKp7Wc9SMNdjiDwAdqoIfRPCwruqrl+f/4GZ JLrOfdwikffMMOQ4tIwBoAXr0VyhnmZElg24qTB4wgcd028MpxDri+IHkY3DXnnFilod TqSVPkDM189LSNjELUKVKwE+sVrzKY9D1ZQTnuYEfL8ze8U71uCay4i0nYa0RjJFx+Pg 1s3ZA/GDw1p4NkTicU8XtLmcwCMUQoxs4l/aejzBsPE0K2z5LGFbWCfIFGlmEzNPCdTy 6Nkw== X-Gm-Message-State: AOAM5331YpPYP8TpeAHIA22515WbLds2hKzhehjYkN6T2pwQw9uaze80 wkF0tBRH4Fy0hbOs96YgFZPXWxSu51yU X-Google-Smtp-Source: ABdhPJzV/t/Mm6XrZ55WBlWiVBPAgYNKl8mk/J4YgsYsaDqr7uQSS9skiOIuSxze7KHWOuzFZh9/58Wx3cG4 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a63:a744:: with SMTP id w4mr4176724pgo.142.1640848908047; Wed, 29 Dec 2021 23:21:48 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:10 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-30-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232150_238121_D1500678 X-CRM114-Status: GOOD ( 12.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 pages) for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { int *fd = FD(evsel, idx, thread); struct perf_mmap *map; + int cpu = perf_cpu_map__cpu(evsel->cpus, idx); if (fd == NULL || *fd < 0) continue; @@ -259,7 +260,7 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int pages) map = MMAP(evsel, idx, thread); perf_mmap__init(map, NULL, false, NULL); - ret = perf_mmap__mmap(map, &mp, *fd, idx); + ret = perf_mmap__mmap(map, &mp, *fd, cpu); if (ret) { perf_evsel__munmap(evsel); return ret; From patchwork Thu Dec 30 07:20:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8F018C433EF for ; Thu, 30 Dec 2021 07:44:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bFPE90Pz+Jxc7nWspke7mnhVkoEe7VHQ0vIjPE/QinY=; b=18CgwwSCoVBppCc+0TfxJ5vqB0 ouVhdVzWubDRwHz2A59ThNXEJ/Gjuxs8vAmu4WnOvLWMSGEPopfe8dD4O3NWTTb6+JJabc8bFlHn9 Qtg54im71knB5ySyN+IFp8dAPyOrCkBJemcH0rDG45guAfDkUIHihheJJ7DvQAE0lYH4+2LVM0Jtz 9/Smh3XqXhresUAnmJoo0V0tmvLfaBPVywoxGv97U+po8i9y3b8M53mTizv2yqMlxosCdG3cajXuT B/epU6v/KBgb14fimeW3dbE379hiBZQ4aYTM0B9uKTG+7BRwHM0GteDBqLzj7gU0itFlC5cIM0NOv J6RDL6dA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q5l-003rjx-I1; Thu, 30 Dec 2021 07:43:18 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pl2-003jzs-9U for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:53 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id c132-20020a251c8a000000b0060c39ab7d36so23100935ybc.12 for ; Wed, 29 Dec 2021 23:21:51 -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=8kii3dU4XUig2NsMBYh2ztP77tNeRDKF26nqmJlinnw=; b=ZHSo2QogBeCKktE3N/YyE3guPCcf/h1gw/biq5AKmUg4GzLO2669grdN+V+1ag5H99 c9w2XJWVYAwtx7P2SqJ/xO56ij3QK1S0NzXUvKQxC7XhO0N8O8RoNxGetqs7QkUqPHCS 58pxmqY8UZUpFb60FfOhNHmDYw1EPGUdByWzIamAxyO6vJhLZzfilDHYwzNTxvAWvTGU UDtvUfmm4b5qWzn5oUT/eR9b83N4dQPJKT0Y+8xGxkXfU/neI2ieuSG8gfbE5zBocxK+ PGOZ5+qDjoWM0lO2LiAZc0g6RjweagNlLMIsnjL49ujCCKDm/ZO79snV4QhczPjC3GaY yswg== 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=8kii3dU4XUig2NsMBYh2ztP77tNeRDKF26nqmJlinnw=; b=AS30/snJ+UnrNDCNrWNFSZAkImVfSovkdLkJkYptcSU+QCXACYHPPe0BbAH35fzAqW NCMy4870aSr3sFc4i+744Q+hXF2rGCK3TQFlIsRbdS9gVgOVSR4yooZilD0k3/YV6aPK HP2/P2TRoIAr00/MKPR7m5KDr5Foga9bTM/F7zyM3JhE0yz8uHNeCMOXEXy+7ucBZVTn uxGfqiaAZa1mCp6SdYVzEfCWKxfm8gmv7kdnlqRlQno/HubKusFf0Uh/uI4W1k7mwQue 39pbxzwNg1FVrVjAorwd6u0NGYywxlCaL0WQ9nQ09CFLtUeKm6I9mI+HEHy9BtuOEzIN jI2w== X-Gm-Message-State: AOAM5304I3zPre0J10IZ48xZFpLX/LO9r2xqHoN3/j0LjGG/CCjlvte0 2TsNP2JXIDhDPetWZWCG9SrZsawK0wxh X-Google-Smtp-Source: ABdhPJyMMa/s/OfZP2MysxB1hBFAyWLxl400jCqqJknIeMSBDfgAktkYlZ98Gg7nJoVPdSu9G6g8w6ryMdDj X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:510:: with SMTP id 16mr24785663ybf.247.1640848910686; Wed, 29 Dec 2021 23:21:50 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:11 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-31-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232152_394566_E3B77899 X-CRM114-Status: GOOD ( 11.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 { 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); } 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 thread) { - return *((bool *) xyarray__entry(counts->loaded, cpu, thread)); + return *((bool *) xyarray__entry(counts->loaded, cpu_map_idx, thread)); } static inline void -perf_counts__set_loaded(struct perf_counts *counts, int cpu, int thread, bool loaded) +perf_counts__set_loaded(struct perf_counts *counts, int cpu_map_idx, int thread, bool loaded) { - *((bool *) xyarray__entry(counts->loaded, cpu, thread)) = loaded; + *((bool *) xyarray__entry(counts->loaded, cpu_map_idx, thread)) = loaded; } struct perf_counts *perf_counts__new(int ncpus, int nthreads); From patchwork Thu Dec 30 07:20:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701292 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E27D9C433F5 for ; Thu, 30 Dec 2021 07:45:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=fS+8qBiEnMcV4CCtH9m9FD8oC8U4nfVs5H7hbrAPKXw=; b=rlrtYu1HBo2BWzREIDZJHaVg1q PVYURRyfMB+3ZAg13zVc/AjOTRhQuAZUEn9BdkdDCZHUN2Bc9ukCSv4DFD/uKsoPJ7n2MC90fBiqt 6q7XBaMQLWauV/6gEvAqYJ2+xzqUOBc39QATqvOOOk2+kBQyWL5w7Um8SKAgmzG8VShTr3jg32Ll9 nKiyVHmZGF774SUcvgvHCqmqyilHZhBxHeXAtgSMLqpeSRJSlJcwgoBzyKbYoIlec9z3fLyquEXim PWDk0LNBQ17YkY+3WY5nfKvvAYXfQQw6uRov6a3kHQsPtvB/V2OTSVVrNcx9n+22rcULGyaGJd/BV n+BZ4qNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q6S-003rxh-1u; Thu, 30 Dec 2021 07:44:01 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pl5-003k1W-HD for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:56 +0000 Received: by mail-pj1-x1049.google.com with SMTP id y13-20020a17090a134d00b001b10368d9dcso15238482pjf.7 for ; Wed, 29 Dec 2021 23:21:54 -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=ewN6TgeYhi7NNspT4fCbrjPDfPPrcTRTO0RxDMRaTEI=; b=INzSbn3pkxSj2o5rY/D2ZDHKiMG80XuFQV1LdJh951/si0ZNvb2AQ/U8J01hhPUcip O4YIgbs5JOUpysdzNjoTE+e1bYWE0QhhGSrmhekuQLSyeuXFeLNHRXgLI6z5rORfe5rL /JvOaK/8/+nxPMe0QcNX43yTndBbtabg8tnrfCR/xKmAEjc7/ntldHYPidBQCpYhqt9W eVMXK0k8df5ymmhFgydv9CnHZlVm96sEswqhFAkTfdlbT0ZrUgJjDaNfKoGWhUEMcjDK KNPzlUm1D0bTZFwRjNxXU4vt3u9OIFi+YN5QgSJFbl/uEQRFxIH4JUviryG9zXNqoalp /1BA== 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=ewN6TgeYhi7NNspT4fCbrjPDfPPrcTRTO0RxDMRaTEI=; b=NzcJRXhuXjm7ZZ9bEdGF4RPvQ16i/4KWs6gJHOCvNUFDiYXKhAAN49RT9tk23k0OKI UDp6WQ/NLqkrEgYBFHgD0Z+On89Z7HJ42WjjLaCtNpDIIVwhiU9PG2IkOKAEhe3pAMPg jCHoU5GJdzjyYRsqnWSRfh4v9Ol4wW42DGaLYTfGdNwmtd3pjLDZdiUh8thyogA9D3dD n7V3o9tpfE+DVWeH1iDgi9d7WDWtAArSAkYCYIWCQc9XXJv9aaGxW2YRCBQSQdgbCEm9 tUioZgqVCAs8M9MBvDaGtVGm7bnnoTD8Y3Zs/5n1fqolTaiQxg66RtOGzeyN0VlSmbyM ERyg== X-Gm-Message-State: AOAM531nITL4JrSOfM0ExKoPyuuuaNb7LQ3FPUMdCvAfDTOESqWWGuGC VkF7CNk0YQ29bQM/w8OIwPUqCtVr2ZJl X-Google-Smtp-Source: ABdhPJxwC04VkqtH3R7KdDCbDUTQi3SLQnP/SiPOIZUMZfH2icNrN1mdP2zY7pRXNCkZkVNGG4IDRp1xSH3H X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a17:90a:638a:: with SMTP id f10mr36302623pjj.187.1640848913549; Wed, 29 Dec 2021 23:21:53 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:12 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-32-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232155_612521_1F812683 X-CRM114-Status: GOOD ( 12.94 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Trying to make cpu maps less error prone. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index f48d1678861c..7e933a8fee68 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; }; 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 = data; - ad->val += perf_counts(counter->counts, ad->cpu, 0)->val; - ad->ena += perf_counts(counter->counts, ad->cpu, 0)->ena; - ad->run += perf_counts(counter->counts, ad->cpu, 0)->run; + ad->val += perf_counts(counter->counts, ad->cpu_map_idx, 0)->val; + ad->ena += perf_counts(counter->counts, ad->cpu_map_idx, 0)->ena; + ad->run += perf_counts(counter->counts, ad->cpu_map_idx, 0)->run; } /* @@ -897,7 +897,7 @@ static void print_counter(struct perf_stat_config *config, struct aggr_cpu_id id; for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { - struct aggr_data ad = { .cpu = cpu }; + struct aggr_data ad = { .cpu_map_idx = cpu }; if (!collect_data(config, counter, counter_cb, &ad)) return; From patchwork Thu Dec 30 07:20:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 09116C433F5 for ; Thu, 30 Dec 2021 07:46:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=70GdaOTsZt/oEHIKE2K7vtDRHtP93GPT3hqy7yFpGuQ=; b=zaT186RmSQ+9GpOZSUYzz4cEOw PtI+DeV/R3uMfYFOfUfBa/F8Re1beqJ/x36TxsQxw08o1aS7UR/ndeRjIsaQ7PVN5NlYuTlmOTYxZ OyrlxqxbGGBP1M42YaSXCphr4HWCQe/Q/oGJKnh7fIr6xYsHx+T9VrxaepsL+rB3MxuvvdyXsAIBe rm0VlvAd1KFpGh+nPpliFXf+1K/P/3H3Z1dDnIj6RDXQaJbq3c8Q1gYK7kUjo4gz7a9qw+7a44oEw sVenDCqxUH+ODWzyA3DjjVM8UhmY6VDDyUMy1rGBHsm3+Om2jNW/8pmjZzxMH7QIGFnCLyn8yjrME 8VuHkh3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q78-003sEn-Ou; Thu, 30 Dec 2021 07:44:43 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pl7-003k2p-GJ for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:21:58 +0000 Received: by mail-yb1-xb49.google.com with SMTP id k130-20020a255688000000b0060c3dcae580so22465481ybb.6 for ; Wed, 29 Dec 2021 23:21: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=cJxFT+Wieuw1JhmOKv6vMYAg7VBOnu+0BYOqRINi2fw=; b=AaHv8eORAJsQxS3I6J+wspo278XHNMt6cWHmkPeINdeVvH11+NxswWMDsad4x7P5iU wFWnpYfbaMzXhlXauKb2YPOklu8N4eAssGnSq3SpBE1EXifP/WJc40XmzDKnA8d15Fau +i4mG9wvHLxQChrj2VP/FX8/FaBAWkCtukNHvtnCP05sy913IDR9iB4lW7pYSaNbjPyP lNYvx7oPqTukT1sc0ZtP25ItEUr9cAINncuZy+9dA1z7aGpk7y/JncbOgnrLiJhgXaLM wSu2ozmiPMQzAyX7ov7N+rNVvThkH8FyKO1rJra4k+4vcaRMPYXd5iAnDC8NQzaERA4b Kk8g== 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=cJxFT+Wieuw1JhmOKv6vMYAg7VBOnu+0BYOqRINi2fw=; b=yXtOEymGDmBI6rvRyvzFuUv0QhzLnEL2Cf/EyA3FzpeRQSXf8tBnkPvIODP9/uBAmK e31auoDNRwRL8wJ5i4v5UZSWRFYXWrllk14DGfCyHRhnI4L0N2ygLdgxRt1wHD9du+2G Z/nI2or3Nhj37vDYlQSHcl4uMGBgXMMQXbV0AtJc3Nj5pw3R3IljGqgzKXdq83VgGFYl tbxxtwe31RdbIUf89Fsj6n5MIBOe6VupmqXzmHgu44YwcsvgBHj4c0KRsjPCUtb/WlEp HKV2kVTZG6GuuwswpmV1wpl8/fXWaCbUKyEa+CwoLO8Fk/5qMasjcYHBrLvtVXgAEMbk AWyg== X-Gm-Message-State: AOAM532zZ0r9MTXvsSTiOidgGxf5rq37YllX30sBLxrW/TjXp2rbf73g Tv2lNNBprU/miCQBgPKpaKVbzgPrGCRz X-Google-Smtp-Source: ABdhPJytWKabroUG8HjyhF2QFoTqO1zK7EFRJ5h2dMTVhrWEAu4oyvBpIf//FFwcyF9lGBO1qvzQX2ZJ23s2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a5b:743:: with SMTP id s3mr22066829ybq.209.1640848916024; Wed, 29 Dec 2021 23:21:56 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:13 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-33-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232157_604810_76243B04 X-CRM114-Status: GOOD ( 12.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Correct in print_counter where an index was being used as a cpu. Signed-off-by: Ian Rogers --- tools/perf/util/stat-display.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index 7e933a8fee68..0f192360b6c6 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=*/-1); } if (metric_only) fputc('\n', output); @@ -893,11 +894,11 @@ static void print_counter(struct perf_stat_config *config, FILE *output = config->output; u64 ena, run, val; double uval; - int cpu; + int idx, cpu; struct aggr_cpu_id id; - for (cpu = 0; cpu < evsel__nr_cpus(counter); cpu++) { - struct aggr_data ad = { .cpu_map_idx = cpu }; + perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { + struct aggr_data ad = { .cpu_map_idx = idx }; if (!collect_data(config, counter, counter_cb, &ad)) return; @@ -1248,7 +1249,7 @@ static void print_percore(struct perf_stat_config *config, print_counter_aggrdata(config, counter, s, prefix, metric_only, - &first, -1); + &first, /*cpu=*/-1); } if (metric_only) From patchwork Thu Dec 30 07:20:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3C625C433EF for ; Thu, 30 Dec 2021 07:47:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=MTvzqnz0tVAOdxuN79V2cAwOygS/QM588LO79ZUb6FU=; b=CWYeCoYqRhaLRHwMT9k+qIBJX2 PjD5tHtZlnlPu/T3PWkB/wNPoxwTYNF6zbRu1ab/CjZzLGEXDlL2MYVrq4aRW81LXue+vhOwbpZtE PQtZkSgA9yll/4iwHDNjxLbKBl3aXDMLZtXReHkUZHYJKDJanCHbs5ZMefkgmXYBRvKabJpTrMDeE vA0qAxUQYW9KtcrhbTlwKhZwk7UNBgU1td9yv2ajMOPwsjefrtf7K6AAJTkwZX5Hw7jX+wjMeMjaf AT5Zy87+Oh237Dd0K8xahb48izMfAd+P3/jRLXgeCypx2Vf91kRq15+C0bDQwhXskzuwuxc/3U3AF 7mmqNNDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q7y-003sV9-BW; Thu, 30 Dec 2021 07:45:35 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plA-003k45-1s for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:01 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id g130-20020a255288000000b0060ba07af29eso25853635ybb.2 for ; Wed, 29 Dec 2021 23:21:59 -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=5E7qCmbhcG6PuyklpswsQQtsh3hwpY8VT2UNYS3McbM=; b=Gfhu9VtJeNHpp94ZAOP6BEURqOQ1GB6YOAeaR/IzzwZeyLURpqc67PaFFz/svrG/5W 8YYk+r4TM/UIFsnt4bxDH4ndbwwA6Jj2rUeBY7fauHo5PJTQkQW7WZ2Dci8Tk5X04IAR qol/PwQ1QT54Q97bUMvleW+hsVQFCdokNqrNhowSMoC001DZ+wUBY8IpZE+LjSDt//NK wZo6RvyyUOOijFXYimwlA1kFDw8a/vPEsykmvv/4UjIBZzxQCtV3qsq6KWVQJMK33Lmn QaiUZCKcANuuBE134rv3z0y1/NmEwPn62XEYEP148inW2xo9A/pQfKz87qGfRLYvIGDB Z+Mw== 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=5E7qCmbhcG6PuyklpswsQQtsh3hwpY8VT2UNYS3McbM=; b=Ovr5YY3JQ5GlOC+dUkPNs00H4XnhVpqo59tQCMNKWFkOfn0YFHqTcss3XtLIlz/vGF FS4toYPKc8ObkSk0kdjYpdOOHIJ7P7gdVG1yaQPL3vUDKw0Lpy9tQqT9nxrl7RVS/8AW bSuLwprbDZu60uinKjXmuwWGn2VEm7FuBAjlQLXJ+Vl7ZihqX3M1xb/HljDAElOgrjKE sfrymZDzDAi5kS+eqUtFERVOFlnz9/ZskglJvifMA1trNrsWME//8zAM9FO/rE+Qc9qG ZhpefUGb5UCkeTFIoew1RzOryYMswCZJLezenR9QvE9aFdg2zukF07pCv+1Kk2Il5ciP YDBQ== X-Gm-Message-State: AOAM531rOspX8gw8JnAb+9hv5SSeDVRFXgFSNQLx9EGSlSdOtDMIl9Ng HlUzDXwbsD53JPmbLAL3Oq+oVPNCQsVb X-Google-Smtp-Source: ABdhPJxZFDLUd2Q0RsMuQCwod5Dec4u0Ta/2jbhXReC6ERU+A1dE0YVQIPPxEVw4ATvDX8Chh3lEQuWY5H0M X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:d914:: with SMTP id q20mr27808227ybg.140.1640848918378; Wed, 29 Dec 2021 23:21:58 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:14 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-34-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232200_156251_0560F9DC X-CRM114-Status: GOOD ( 12.27 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 d308adfd1176..ce9c3c5d881d 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2115,8 +2115,7 @@ static struct scripting_ops *scripting_ops; static void __process_stat(struct evsel *counter, u64 tstamp) { int nthreads = perf_thread_map__nr(counter->core.threads); - int ncpus = evsel__nr_cpus(counter); - int cpu, thread; + int idx, cpu, thread; static int header_printed; if (counter->core.system_wide) @@ -2129,13 +2128,13 @@ static void __process_stat(struct evsel *counter, u64 tstamp) } for (thread = 0; thread < nthreads; thread++) { - for (cpu = 0; cpu < ncpus; cpu++) { + perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { struct perf_counts_values *counts; counts = perf_counts(counter->counts, cpu, thread); 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, From patchwork Thu Dec 30 07:20:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701295 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 88BBDC433F5 for ; Thu, 30 Dec 2021 07:47:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hcmy7TpRF3EVlnnAhJJY8Dn/5ZJG+6n/7hpFZ664Kbo=; b=2ifGIK5OR2fRO71LNNHjoSyiQP XhPiJywqod6/huC8cxfvvWcMFKhX1U4yXm2dj5G4FxOovnuPusEBTmDxp0OrTndJWAOwKsVn+74b5 SWKxS2X1+qcuzYezzi1qS6Z7q29iHe3AM4en9QJ0CpJfEIqyu5yADMgC/6Bwhpi+qZP4PNYPgis+3 tA7Io6sLZH5ZARt7FuQ29t8o/ClJ0HVF/DpD6/PVhCAHm9H45J1jvyB65zVkqAu+t8lO84JxQIeJN jpC3VT5cIvLmUr5+8j/rAg1+FdiVmDgXyFLcNawL4NOVoeIRgGwoX8nnYk0TMozZVKaXR4CQLTCFS eqKdnjgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q8e-003sm0-CV; Thu, 30 Dec 2021 07:46:17 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plC-003k5j-9Z for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:03 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id p140-20020a257492000000b0060dbb88d8abso11651397ybc.15 for ; Wed, 29 Dec 2021 23:22: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=zx3eoMgk2E9Q1m2Vv8UqlZ4wRR3W4iMt/10PWukXDj0=; b=gd7scXcBk1yTnVwoiPe+9oH6SNITUOkpUrx9WTCnO9LW819DoLCEjIc4CjYDRfgbW8 kpIcIaA0WXGx0A1JkH3+CNaDGqB3LbKNQy/dC69uwrapr1aB0K7K+nY8k+xsnN6eF4lR /nyWdqgi8c2eNr7SAmJDNL7ryVZ8uPy9AsDhfVRqK6mGUAbGuF5gKBfiymoyOc/lCu7g ZsKeKPIcAATBQs1wSFE96jQMWMX35qGZpKg86Ex1PLsLGuQ6bIj5+xVqZF25J4HmYKNJ 9nc93dAkDv96SzZ07Mn1s0PVaixDu0PPpFVxb1RLChglabm5T7WAiOU71z4oo0XVwMfL 9YlA== 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=zx3eoMgk2E9Q1m2Vv8UqlZ4wRR3W4iMt/10PWukXDj0=; b=jgf5Co7Ju3333at1hAdraB1HHsy2MJIx3FEmuCFMWd1q8OxvMWH2TKgSt2MjgbPqQi sZK1BbWuCWiqxZkvGWXQIeRwCpdnXTDSN7YwmmcgNGNtcSH163jprdu8d3xK7g2+0VfI B9slajKzgCy8wBXEr6DKaAsQ8abHvN6/CAfncl5UrjfcvBZCIggBkfCl75FxskirVHIt QqOt3OYpKie354/rZ0T5UOBo7mhyvdhuVWH/uwruAfHqJXPg8Rgk1nVbaIewBl0/UGUa /bGZHiRKYgBv0sdhoAz6GcBnXM4c5SObD/1QbUflCvD7MghSAFTdgpSXx601BO5F6Ok2 ywWA== X-Gm-Message-State: AOAM532bzOEr1jGKu2eM8Q0HVJ/l57c1YCh77tuYWX6ihHkB3QUWftXT CDMj1ASXoxxzEQ7s74cQyHJG84inn0Eb X-Google-Smtp-Source: ABdhPJzroPIw7lL2p5xUk8nN/ROAI6MwcBgq9IhE3TcIDiuJTiQS4g8XAkhZduxh5XtQBLj5zuKGhd8qgHpF X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:7b41:: with SMTP id w62mr37995471ybc.164.1640848920800; Wed, 29 Dec 2021 23:22:00 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:15 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-35-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232202_369974_3EE61E22 X-CRM114-Status: GOOD ( 11.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *map) int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu) { - int low = 0, high = cpus->nr; + int low, high; + if (!cpus) + return -1; + + low = 0; + high = cpus->nr; while (low < high) { int idx = (low + high) / 2, cpu_at_idx = cpus->map[idx]; From patchwork Thu Dec 30 07:20:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701296 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2DB24C433EF for ; Thu, 30 Dec 2021 07:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=qWmK8fEcC6bn0kG33IZx7LMQ/WNjGp9gYBR5InY612k=; b=WjhBkQQhRiuUOZ7Yn71plsqY9r ALJUIxzn0FSgBEGotvPCqxL+HsTeP0z1L/LOAHAbnm3JIuJCgh1azm+Mm2I0adckvJlsHTD40vY5O N68ewdiRvznWD2r/qnyK1ICs2XkYehyX2o4/GvJ/AYzEbyugcWLna/ixzyI6Anv7l0mpD5JyqPDac twoGiPiCwdnjHoBpY+kBBkB+gvKW7/dY/djQ9cbd8WmOa54jGixeR77Pc50oO8xK4eeg1OmCU0Mut COC0B9CQBlLL95geHRMeeVn6H9NjLFbdAWsCc9/icf2YNRwDBIND3GpzXZsO33SUETeIwDFvZz5Bf NkDdmRBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2q9P-003t0m-OA; Thu, 30 Dec 2021 07:47:06 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plE-003k7C-UR for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:07 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id k130-20020a255688000000b0060c3dcae580so22465841ybb.6 for ; Wed, 29 Dec 2021 23:22: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=UCK9l+BEdrLTJQZ+dx/4MkTNovKCui/i9rUWPLtd3/I=; b=hyPeUhSX+mOQf1Pa92viBpsjCorgfh51S4CF3pHPFejByXsxu1POCQKmci9yxECaLf rzfYRQ6d9TGGfWKY2zYtdp7yRsG/1fu7aSuf/NxBcFuHwx/c1f1COfT0YAxcXL7HbHxa GcBk9xEOOqtXKCIwsNE9JFtPy35s8pnt6E69FDSLr/KUxzQ+WzK7w2DtBDF1z895tM5M 9YOWYY6KaoOCZoh/lv2/dSVaK0xFLYMJlg3NasLFl+rf3/LZmVkPD572aJ1E2NlvTpF/ iihhDK6BUGrx4UIHob3c56JG/9UjtNQxJ6JM3GidTtqE7Llf3VqVBKeK2ebiu9hVDIfc gvQg== 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=UCK9l+BEdrLTJQZ+dx/4MkTNovKCui/i9rUWPLtd3/I=; b=EBvVLNSZLvdXqmSnyqIX3ILwjjCJYlZMlis8lqg6kkvB7B+n6t/1hnm1MWCj3seyv0 1528A8p3GQNDB22rb5BcjrBTGH4NGs/e5X+QD6F3epUTZ7R5bkMEc8DrAS++DztYTUWZ amP0Dcf35+efvZdc7ltwMfFUwbftyOhwH06A0YozF9zy1u2A6ggB6DrmgOBvwWlwUd8/ yGvpp4j56KgPKUbAvKCm6rHTaycotcV0vajkanegLnuGl1AmS2Ic0iss2SZo10XaohPB UtN/YKHjkqbIfun9pqlL/kL+DxfhLlxdUJyLv+XWkI7YkOtNtEhVMAh6xY1ndI2iMrU1 QwKg== X-Gm-Message-State: AOAM532/lWOfj6x9oVzv9wi9JIDwt+2Sm8kkctoyvq+JIIH5rgnl/0Hi maeEtnHD3lrEx8EcVY8pHbiJ2hsiqJeT X-Google-Smtp-Source: ABdhPJxQrarTUR0IdpNIzrDZkRW/JcESVEeiAJsdgukr29vFWv20oMaxq1jVI+53gpI8UMI8CDqQMjCrulzC X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:b907:: with SMTP id x7mr38358550ybj.566.1640848923425; Wed, 29 Dec 2021 23:22:03 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:16 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-36-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232205_066280_4700C7D6 X-CRM114-Status: GOOD ( 28.72 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, struct timespec *rs, int cpu) 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; if (all_counters_use_bpf) return 0; - if (affinity__setup(&affinity) < 0) + if (!target__has_cpu(&target) || target__has_per_thread(&target)) + affinity = NULL; + else if (affinity__setup(&saved_affinity) < 0) return -1; + else + affinity = &saved_affinity; - ncpus = perf_cpu_map__nr(evsel_list->core.all_cpus); - if (!target__has_cpu(&target) || target__has_per_thread(&target)) - ncpus = 1; - evlist__for_each_cpu(evsel_list, i, cpu) { - if (i >= ncpus) - break; - affinity__set(&affinity, cpu); + evlist__for_each_cpu(evlist_cpu_itr, evsel_list, affinity) { + struct evsel *counter = evlist_cpu_itr.evsel; - 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 = read_counter_cpu(counter, rs, - counter->cpu_iter - 1); - } + if (evsel__is_bpf(counter)) + continue; + + if (!counter->err) { + counter->err = read_counter_cpu(counter, rs, + evlist_cpu_itr.cpu_map_idx); } } - affinity__cleanup(&affinity); + if (affinity) + affinity__cleanup(&saved_affinity); + return 0; } @@ -788,8 +785,9 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) int status = 0; const bool forks = (argc > 0); bool is_pipe = 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 = false; if (forks) { @@ -813,102 +811,97 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx) all_counters_use_bpf = false; } - evlist__for_each_cpu (evsel_list, i, cpu) { + evlist__for_each_cpu(evlist_cpu_itr, evsel_list, &affinity) { + counter = 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); - 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 == EINVAL || errno == EBADF) && + evsel__leader(counter) != counter && + counter->weak_group) { + evlist__reset_weak_group(evsel_list, counter, false); + assert(counter->reset_group); + second_pass = 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 = 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 = 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 = 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 == EINVAL || errno == EBADF) && - evsel__leader(counter) != counter && - counter->weak_group) { - evlist__reset_weak_group(evsel_list, counter, false); - assert(counter->reset_group); - second_pass = true; - continue; - } + evlist_cpu_itr.cpu_map_idx) < 0) { 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 = 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 = true; - } - } - } affinity__cleanup(&affinity); 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); } -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 = 0; -} +struct evlist_cpu_iterator evlist__cpu_begin(struct evlist *evlist, struct affinity *affinity) +{ + struct evlist_cpu_iterator itr = { + .container = evlist, + .evsel = evlist__first(evlist), + .cpu_map_idx = 0, + .evlist_cpu_map_idx = 0, + .evlist_cpu_map_nr = perf_cpu_map__nr(evlist->core.all_cpus), + .cpu = -1, + .affinity = affinity, + }; -bool evsel__cpu_iter_skip_no_inc(struct evsel *ev, int cpu) -{ - if (ev->cpu_iter >= ev->core.cpus->nr) - return true; - if (cpu >= 0 && ev->core.cpus->map[ev->cpu_iter] != cpu) - return true; - return false; + if (itr.affinity) { + itr.cpu = perf_cpu_map__cpu(evlist->core.all_cpus, 0); + affinity__set(itr.affinity, itr.cpu); + itr.cpu_map_idx = 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 == -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 != evlist__last(evlist_cpu_itr->container)) { + evlist_cpu_itr->evsel = evsel__next(evlist_cpu_itr->evsel); + evlist_cpu_itr->cpu_map_idx = + perf_cpu_map__idx(evlist_cpu_itr->evsel->core.cpus, + evlist_cpu_itr->cpu); + if (evlist_cpu_itr->cpu_map_idx != -1) + return; + } + evlist_cpu_itr->evlist_cpu_map_idx++; + if (evlist_cpu_itr->evlist_cpu_map_idx < evlist_cpu_itr->evlist_cpu_map_nr) { + evlist_cpu_itr->evsel = evlist__first(evlist_cpu_itr->container); + evlist_cpu_itr->cpu = + 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 = + 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 == -1) + evlist_cpu_iterator__next(evlist_cpu_itr); + } } -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 >= evlist_cpu_itr->evlist_cpu_map_nr; } 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 = 0; bool has_imm = false; if (affinity__setup(&affinity) < 0) return; /* Disable 'immediate' events last */ - for (imm = 0; imm <= 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 = true; - if (pos->immediate != imm) - continue; - evsel__disable_cpu(pos, pos->cpu_iter - 1); - } + for (int imm = 0; imm <= 1; imm++) { + evlist__for_each_cpu(evlist_cpu_itr, evlist, &affinity) { + pos = 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 = true; + if (pos->immediate != 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, char *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; if (affinity__setup(&affinity) < 0) return; - 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 = 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, struct evsel *evsel) void evlist__close(struct evlist *evlist) { struct evsel *evsel; + struct evlist_cpu_iterator evlist_cpu_itr; struct affinity affinity; - int cpu, i; /* * With perf record core.cpus is usually NULL. @@ -1279,15 +1298,12 @@ void evlist__close(struct evlist *evlist) if (affinity__setup(&affinity) < 0) return; - evlist__for_each_cpu(evlist, i, cpu) { - affinity__set(&affinity, cpu); - 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 evsel *move_evsel); #define evlist__for_each_entry_safe(evlist, tmp, evsel) \ __evlist__for_each_entry_safe(&(evlist)->core.entries, tmp, evsel) -#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 current 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 evlist + * for each evsel on that CPU. When switching between + * 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) = 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); struct evsel *evlist__get_tracking_event(struct evlist *evlist); void evlist__set_tracking_event(struct evlist *evlist, struct evsel *tracking_evsel); -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); 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; From patchwork Thu Dec 30 07:20:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D753C433F5 for ; Thu, 30 Dec 2021 07:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=V54Dc74eY9F8kn7HzOUHG/qlVYdLTYbTXxOl3zvjt5c=; b=2B38o98+srrSsJrsTK9o6cMKxI QQ41CAe6tj4LDcdX/CSyVYOnauDITR6/MX7Uy/nsMUz6c1KCjgWkU+WjClsxmYceiBWwtCkn2SZOg fDs2rI3vYI08IasQACcR7elcwJgmYxVQj5FVeieYG8Z1np4nrZaltaxK82RaNCJfv+uaanCpJbcUg eSc9g0pnDC74K9IdyBlxhN3mqSYurDmqu9DQZo9T6AHT23nxIwccNuOs904UDdubLeBI/bD980GwB qyZ6+WY2VHDQqcv297DQgtXo8g0YbS3woUYhSHO9ReIGAO+YgPjcskTKEqCsrp55Z0bKrUJqr9CmL Gn+rs04g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qA5-003tFR-0w; Thu, 30 Dec 2021 07:47:45 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plH-003k8i-Nm for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:09 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s84-20020a254557000000b0060ac37f4bb1so29562033yba.5 for ; Wed, 29 Dec 2021 23:22: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=dr21UIWlWh08GpstPSt0DXreHsY1rvRjUlHXGQMgUUQ=; b=EzlOdQL0P3mQ5LLCjUBdScAdR4k8fbx3t1xiYbAGiLzrvhfYRNamUq3myYjTNbMt1z z1iM60q9zjlaQAcoCGdA/MylPvkoXxci2/mhvMITTMVzxFMmy1kLRBKwKSdlzO0kFLac rmX36ofvYh41GcgwoFMXtS3/igsv10WDIviUoefVvtAGryPH4lySTaSqzi51hQVUXRp+ ocpdbQPHx5fHXPwVKhz5QvLiwYbqfx4x5Q5vidzBlB7alneeRNnVq+/RWxS64bjPHZdY MsTjekbO8bobE8pPkFVDaDAAyl1NvvRu7QWxrniO69RQBLBeqhVDpkbID3vcTO0EI6LS iryQ== 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=dr21UIWlWh08GpstPSt0DXreHsY1rvRjUlHXGQMgUUQ=; b=TB8xvrRn9PTjzbdFxwTUfhkR6UqUK4gNir979Ci+9zhMvv5Wg91o0duwX8o8+IvNhA XRRPagE9JqFIHPfRUMQjzbY/rDMvSWa90bPglHBRN4t5Gg2k5NHIHSsYkAqnX3Dr56h+ 4/O7X5yEj8WwtFatp8iRjueKKapvvMh8Req1wU9h+BM8rLHgoFSlkUuHvi4MY4+sQH8L JHL8Lv2ST72wTXvJq6sF1ZllM10T31ZHFfkbBcSORffWlHuuRzmSdSy+ghDE0N2ez/sd QzfFSftgG4Gwq8Wm0mK8q3yOhNwMRnm8UXfVeoAdcdVabslMs4IOi30utv309pSglHC1 Wk2w== X-Gm-Message-State: AOAM53148jywVOfxkXjmfJnFpMTk4HjibnroETh3waZ73yscC0TfINB7 aQBSRq2WHXM+NOaKO2e1DG6lugYcu2+N X-Google-Smtp-Source: ABdhPJyRfLGpoQ9H9fJ2Morzmd7n7bmZUL51X8hObRibMpoPCIExOKmteY86oNxmXqhmcVFjCo2lIJ4u9b0N X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:7287:: with SMTP id n129mr36420396ybc.351.1640848926039; Wed, 29 Dec 2021 23:22:06 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:17 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-37-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232207_851508_36F74431 X-CRM114-Status: GOOD ( 12.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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) #define SID(e, x, y) xyarray__entry(e->core.sample_id, x, y) -static int evsel__write_stat_event(struct evsel *counter, u32 cpu, u32 thread, +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 = SID(counter, cpu, thread); + struct perf_sample_id *sid = SID(counter, cpu_map_idx, thread); + int cpu = perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx); return perf_event__synthesize_stat(NULL, cpu, thread, sid->id, count, process_synthesized_event, NULL); From patchwork Thu Dec 30 07:20:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701298 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 87126C433EF for ; Thu, 30 Dec 2021 07:50:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=B0+N47F2Y1kxKHFVTE0puwhsj0ez+9PNLz2JBxs1vrE=; b=wcoY8geEFDCyZw2usOxBg4NBvD gU7XUimeMHRz71jCgRjoKqXYRZ9YL+VVhnKuYpzAdyrsAkY6GrODv67h35JXBxvX+PCk+RLgaFuSZ s4LQ5ZiOjm5WbGsZSiB/pXOv1YMRtQ4Cc4nB6O0Mqm2R3szl3L1wwEvyXDRfLtrus53x4khke57BL zDNL6xBfAmiDd8vl9dwqkO7DJh3OhNgni429NQYCbHy0d5/dri5ZGyVNEJXQ+1yAgxYEOhTWLlRDc 59L3VuhoQo2pV6wway8NKr9/WIMFDKScuM5aP4PNfmN0gvPQFm7qMY0jN3aRtuxvxfJwCrTPhVA90 RmzjKucA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qBE-003teR-Nw; Thu, 30 Dec 2021 07:48:57 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plJ-003kA7-VV for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:11 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id s84-20020a254557000000b0060ac37f4bb1so29562160yba.5 for ; Wed, 29 Dec 2021 23:22: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=VldYUAKeuECWMwyFFC8E6bOGo9BFwwmAcr2cQniUPOk=; b=RKBK6w/QWeEpiShEYi3wM1bR05YaXAoeJOwJcKkaJ8720rXtnblpa+HocuNGx90zUr NwQKHQzdDBarnK8nXcDROdAAEszDSnzLF39SFSsdwhZcoGMgRTWMeHdJyNTKo0W609dI KpT8+E8udZ+BgiMEDIzKpS54D74uE9m3ThseumyGU2UgXrMn5oZuW3jxytP5AgMn2jc0 xFb01pl5P0qrm/XGOZdOXttJCB70DM6DpU9Rf0Ka9HR3kVC3XlIvkhYPJKwtQNqP0Lpf 7QuseeBOqaBqRbv8vy9qk8gQjuxaZi38r5A/8425DcHPGiS3gFxleBT85yw1povhyHSI NRIw== 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=VldYUAKeuECWMwyFFC8E6bOGo9BFwwmAcr2cQniUPOk=; b=bAb/P4vNfklBPEfEt7YZRBEy/Rr9nOw+dTrzW+I0b8snr1i3hAeq3VAlDlvhMu+GsE 69leqtY4rV/d6Ov8U6fPdE6Nk3kffMMI34xHZrFDk2AW8/v9XKqYyDcZblPt5+v9w7hF PNK5YUvNUd4dJb/HyogE3iVVx5ibWWeIOrJTIaDMRHUErRvFPXtPfhVYy+bZBPcxRtOo 5UPfsZIax0ZOR0dhKOtKVizExrju3f6/h0hygmcTBCw42BPZOzcijo1ayN2DSHrCvn66 EHqa2whVQKWy4bQ++P1230qksCcL4sV1Zdzt39Huhc8VEgLlm7JWCtoUoxYpnMjx3h8X 4Z4A== X-Gm-Message-State: AOAM532h31mGk+8aka6bQ0pwGu9jNY9c8ZWXLK69NKwIYJXQekvbAw0Y /dSeanc0L+Nm9T0WA0XUK7sUZ/hZMRxi X-Google-Smtp-Source: ABdhPJwPmt1KvsgrlWg0SA6rcAX61tFvgz7a7DWydQ0EyrMeFCRIsEOMnHqiiAY9VAD7FB4VwCUjJLdjjMuZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:3748:: with SMTP id e69mr30894951yba.378.1640848928536; Wed, 29 Dec 2021 23:22:08 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:18 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-38-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232210_091406_5E9FFA79 X-CRM114-Status: GOOD ( 18.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *counter, int cpu_map_idx, u32 t process_synthesized_event, NULL); } -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 == PERF_TOOL_DURATION_TIME) { u64 val = rs->tv_nsec + rs->tv_sec*1000000000ULL; struct perf_counts_values *count = - perf_counts(counter->counts, cpu, thread); + perf_counts(counter->counts, cpu_map_idx, thread); count->ena = count->run = val; count->val = val; return 0; } - return evsel__read_counter(counter, cpu, thread); + return evsel__read_counter(counter, cpu_map_idx, thread); } /* * 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, int cpu) +static int read_counter_cpu(struct evsel *counter, struct timespec *rs, int cpu_map_idx) { int nthreads = perf_thread_map__nr(evsel_list->core.threads); int thread; @@ -369,24 +369,24 @@ static int read_counter_cpu(struct evsel *counter, struct timespec *rs, int cpu) for (thread = 0; thread < nthreads; thread++) { struct perf_counts_values *count; - count = perf_counts(counter->counts, cpu, thread); + count = perf_counts(counter->counts, cpu_map_idx, thread); /* * 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 = -1; - perf_counts(counter->counts, cpu, thread)->ena = 0; - perf_counts(counter->counts, cpu, thread)->run = 0; + perf_counts(counter->counts, cpu_map_idx, thread)->ena = 0; + perf_counts(counter->counts, cpu_map_idx, thread)->run = 0; return -1; } - perf_counts__set_loaded(counter->counts, cpu, thread, false); + perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, false); 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, struct 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 = count->run - tmp.run; } -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 thread) { - struct perf_counts_values *count = perf_counts(evsel->counts, cpu, thread); + struct perf_counts_values *count = perf_counts(evsel->counts, cpu_map_idx, thread); - return perf_evsel__read(&evsel->core, cpu, thread, count); + return perf_evsel__read(&evsel->core, cpu_map_idx, thread, count); } static void evsel__set_count(struct evsel *counter, int cpu, int thread, u64 val, u64 ena, u64 run) @@ -1530,7 +1530,7 @@ static int evsel__process_group_data(struct evsel *leader, int cpu, int thread, return 0; } -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 thread) { struct perf_stat_evsel *ps = leader->stats; u64 read_format = leader->core.attr.read_format; @@ -1551,42 +1551,42 @@ static int evsel__read_group(struct evsel *leader, int cpu, int thread) ps->group_data = data; } - if (FD(leader, cpu, thread) < 0) + if (FD(leader, cpu_map_idx, thread) < 0) return -EINVAL; - if (readn(FD(leader, cpu, thread), data, size) <= 0) + if (readn(FD(leader, cpu_map_idx, thread), data, size) <= 0) return -errno; - return evsel__process_group_data(leader, cpu, thread, data); + return evsel__process_group_data(leader, cpu_map_idx, thread, data); } -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 = evsel->core.attr.read_format; if (read_format & PERF_FORMAT_GROUP) - return evsel__read_group(evsel, cpu, thread); + return evsel__read_group(evsel, cpu_map_idx, thread); - return evsel__read_one(evsel, cpu, thread); + return evsel__read_one(evsel, cpu_map_idx, thread); } -int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale) +int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread, bool scale) { struct perf_counts_values count; size_t nv = scale ? 3 : 1; - if (FD(evsel, cpu, thread) < 0) + if (FD(evsel, cpu_map_idx, thread) < 0) return -EINVAL; if (evsel->counts == NULL && evsel__alloc_counts(evsel) < 0) return -ENOMEM; - if (readn(FD(evsel, cpu, thread), &count, nv * sizeof(u64)) <= 0) + if (readn(FD(evsel, cpu_map_idx, thread), &count, nv * sizeof(u64)) <= 0) return -errno; - 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) = count; + *perf_counts(evsel->counts, cpu_map_idx, thread) = count; return 0; } 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, struct evsel *e2) (e1->core.attr.config == e2->core.attr.config); } -int evsel__read_counter(struct evsel *evsel, int cpu, int thread); +int evsel__read_counter(struct evsel *evsel, int cpu_map_idx, int thread); -int __evsel__read_on_cpu(struct evsel *evsel, int cpu, int thread, bool scale); +int __evsel__read_on_cpu(struct evsel *evsel, int cpu_map_idx, int thread, bool scale); /** * 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 thread) +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); } /** * evsel__read_on_cpu_scaled - Read out the results on a CPU and thread, scaled * * @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_map_idx, int thread) { - return __evsel__read_on_cpu(evsel, cpu, thread, true); + return __evsel__read_on_cpu(evsel, cpu_map_idx, thread, true); } int evsel__parse_sample(struct evsel *evsel, union perf_event *event, From patchwork Thu Dec 30 07:20:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701299 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 73288C433F5 for ; Thu, 30 Dec 2021 07:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=EgGWcSkKDXNdXN+wrUNH6Sw9nKaBOR1YkWUuQBItfn0=; b=oL2pM+hHyLUUzibJsnkkYrlHRs fI8ZUJvQKdwFU9rW4eiSbk634O24JYb9k1eIQ5HJblqudobjdzGopjqi76+X7QlG2MQQh0QCPIEYZ yExlDuoSn/XUnjGZvOJ/4HARiccxBhIJ+I0pMXD8CHYiqqE1n796SrEbSZ9nt/btgehmXDCw9xJe4 UsA43PzTFYUubeEpr5zTQXUayU4UrV0kKCBN77LgN4L3D0upHVmyVeEPZfOK82GOdA5jQyNxtWQGM fB3oke6QA9g8TJDHj/bUt/M6PObzeorGLiybHm3pUSzNmaV6fdS/yLAbPKAOZzr/FK/B5umYDzR18 ySdnm4dQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qC8-003tx6-Ue; Thu, 30 Dec 2021 07:49:54 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plM-003kC2-NX for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:14 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id c132-20020a251c8a000000b0060c39ab7d36so23101932ybc.12 for ; Wed, 29 Dec 2021 23:22: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=XzElm/I104YF1oOu+ETkQDoVDrD7T7dkjmJMXov3Vlo=; b=Zws7ZZxJY7H+IitPKKiJtRpYWgmcOU08af02CnBL0E0ZTp0HsEyFIQ/E+urT/Mcy/I ACtTpg8FOnc33cCYqZZWs7dKvfmWuNniCUe/LaB5nlMvKX1Ht8DiH95Zmh5nm1NFw0aW zqhVEf/A4A9EvkY4KVaaxGnfeo5OVLPAe42kalPtva5lEH/qq8VRtIokk1FRzPhXtZfz 4SRYvc1feavUGmqNvsJJrCoxuSiwPcAnIdgcPENaWfro2NGedd4CW526lrWGozH3WVEM 6XXxcxnMQnKzvTIIP8WRvmjAwLMeGe8CqTSio+lOi5QBmRlP1m9vlF67du5W8NGUT/Ny lgLw== 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=XzElm/I104YF1oOu+ETkQDoVDrD7T7dkjmJMXov3Vlo=; b=mvg94ksfuNsz7B0/jRFerRldqNe4Mog8ru5RichbcD6F3pAKrXjP8GgpL6EOw24pBI /S3MeNSRY69hMkQuww/gTsGe4S0maokk5w/dZbP+O6qQ4ceHMuuqMS549BOQ8+PiQ+ru 2g1UoelYhdDgmk9dz+eP5x2EJPhB2FeOUYf4HrQ++6Ob+3NewJud7nXz5fZvD9hpE47G Nbwiu7uLDNKIx4ZxvVrGrYnk0HGE8CP97Nm3MsJtYp5SRZ74vaCN9nJ1v8E6GBWAQkY2 Q5n/us8nvfXsspLKTPgxx31ZI9pTXDwr7LV2SY04E8kowytRv+XFQdV9IkY1D5eEr35R pqlQ== X-Gm-Message-State: AOAM530C8yDmCW386cUQxfM2bVDTgjcHyq29RGwGC7zdgT1VHguj7p+d oA5esSnvPhju2ncyeg62E7FFqS6mJ0zO X-Google-Smtp-Source: ABdhPJwigVjXJYZ9ikakB8ZfTP6TpnqITXpuLBJ7OkrF2/KN+V54VA0H735gemfSniV3qXoGU0lsfQ8xraR9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:db8e:: with SMTP id g136mr26355395ybf.401.1640848931018; Wed, 29 Dec 2021 23:22:11 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:19 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-39-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232212_840726_38E7214B X-CRM114-Status: GOOD ( 14.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 cpu_map_idx, int thread, bool } static int evsel__match_other_cpu(struct evsel *evsel, struct evsel *other, - int cpu) + int cpu_map_idx) { - int cpuid; + int cpu; - cpuid = perf_cpu_map__cpu(evsel->core.cpus, cpu); - return perf_cpu_map__idx(other->core.cpus, cpuid); + cpu = perf_cpu_map__cpu(evsel->core.cpus, cpu_map_idx); + return perf_cpu_map__idx(other->core.cpus, cpu); } -static int evsel__hybrid_group_cpu(struct evsel *evsel, int cpu) +static int evsel__hybrid_group_cpu_map_idx(struct evsel *evsel, int cpu_map_idx) { struct evsel *leader = evsel__leader(evsel); 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); } - return cpu; + return cpu_map_idx; } -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 = evsel__leader(evsel); int fd; @@ -1625,11 +1625,11 @@ static int get_group_fd(struct evsel *evsel, int cpu, int thread) */ BUG_ON(!leader->core.fd); - cpu = evsel__hybrid_group_cpu(evsel, cpu); - if (cpu == -1) + cpu_map_idx = evsel__hybrid_group_cpu_map_idx(evsel, cpu_map_idx); + if (cpu_map_idx == -1) return -1; - fd = FD(leader, cpu, thread); + fd = FD(leader, cpu_map_idx, thread); BUG_ON(fd == -1); return fd; From patchwork Thu Dec 30 07:20:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701300 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71D43C433F5 for ; Thu, 30 Dec 2021 07:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=OPaztarcIWufaffQ5WThzGTaMP1rday5upCUSRFn8X0=; b=QU9d06da19c3coJPBFRvX3j0XS FyMZVDIYm95rIEgPkjD2EZ2JB0YwD/xWuW/goXxDkHQw/DZWhbc83egNlS7kuDo5408K1CmIQttDO WIJXAwO+d+xqhpF6GlWrQp/b5PFHwdxtLnwmE2yhEBjh/Nlyz0hXMA9QhRHLZq7U+KCWvyZEGYnpO 5MMLkyIhznDTdb/3ERvOdVzX8a2YvoAPpBvjf/LEvYRf4ttZltA3+Un9uPXXCaF7j474p9j/so+bV 25sIChAZbg8ZNI/dEY6F5Ys69fPKAyEgdnqP3Wn98ysJJok/MbDKc7hcRJbdZadqUBNEWfZwAv+TJ pW8RG4Rw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qCt-003uE4-MO; Thu, 30 Dec 2021 07:50:40 +0000 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plP-003kDk-Nf for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:17 +0000 Received: by mail-qk1-x74a.google.com with SMTP id 189-20020a3703c6000000b00476745338e6so8169277qkd.22 for ; Wed, 29 Dec 2021 23:22: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=z9Tf8Q4+BM5aumLuJFIjYqIwLRxLkiAzP1niqb/X+d4=; b=MXT7SOzW3mUO/kIlAAQ1kcE1y8TLKmLvjCZQz/QOX3ep0WbLoS3Law/ePU1YrUpVE8 xRU0Z9yjFElnlqxBOpCu4x25LofrmfWuiN8sThs5JRDgUCHo6B6/ceEZngmkDoxK5c59 mUJUyYJ5c1JksoFFiGij8J5BiTp15Pzvr5Znk9OzhqEZuNTI50rmvdtwAncFrqajsvzt DuvLPjm9dRoAEycbkTbmRCBMb3aWICHWKiVWoOSD7XXcr8L3kXJ3qjbbeSumO9ijpPoe vZBYNHiHOoIaoYh2yWmayyLQVl5qbkoF+/VgPTkPvqJKz5baYe4GzheldNdKV1JQbXA+ 6luA== 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=z9Tf8Q4+BM5aumLuJFIjYqIwLRxLkiAzP1niqb/X+d4=; b=EcMHJ0RpZiqbxKyRNxE4iuofTZoy2qjRg+s9hI67RfA/jR4gc5zO5LtjCA6M0kJSKo bxp75Q7lSDlQMh6SpIHS/JG3VjWh6SQFLFZVnAhpU7szm7D11Y92KmSfmjUXxRorx8ph aUQRiGht21tBWMZJPKuATfcOWkAbOl2Puvkyqs2p1VjlGdSpUv1F694Z/69byhCEguZ1 KjI2UkwWL8UAg2mbXY3u3bVqDABMWa9xUD6JRSroABZDiZUTbCnC3aYxCffsRh6HyhU/ z2qdy9N0d8lBqo3X2XlwciBmfW7grOJ/56fYK91dzjQPH535HGt9U72do4CJqelQd5Uh DMFA== X-Gm-Message-State: AOAM532uPJDBkcVwyu7JR+Jjgkki6f875FDMKO0XDQaHSsZWpeoBDzTw gm9VzIvnTaMPVLcCvs9QEths7Zyw2eUK X-Google-Smtp-Source: ABdhPJyriU9EL/kaz5i6TWu0zvPwflHtymroAnCGFGjX5zO6Eb+Ly8LdUtfYPsbD0NzuYcHoLBLChDPV+Ita X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a05:622a:1790:: with SMTP id s16mr25339654qtk.634.1640848933373; Wed, 29 Dec 2021 23:22:13 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:20 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-40-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232215_837507_8EA82352 X-CRM114-Status: GOOD ( 12.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; } -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 = perf_thread_map__pid(threads, thread); 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 *evsel); enum rlimit_action { NO_CHANGE, SET_TO_MAX, INCREASED_MAX }; bool evsel__increase_rlimit(enum rlimit_action *set_rlimit); -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); struct perf_sample; From patchwork Thu Dec 30 07:20:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701301 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 52492C433EF for ; Thu, 30 Dec 2021 07:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=tCPUAufZsL0uhezcXbF0qUtV1Ov3uPEj8MkDO/HaPMc=; b=PWoRKB8pHyasTW/2+eDqcACW6D fYPp2Ns5ymZ1IYXgjPlY+EZrevwbcpSE0a49nqOFV5LRrGgNpfAYVA7VugTSf7ajFR9S0E2JmAt4F sN+aFGl3triRCm3OYHhGYWYZQNHxMWbkfsFCZ73ifHslPghenW1NUxtEIjdt9fnYL6iGv36CCKGDF hHxiLe+c1Raut1gD8pHVK9/+GiYk0wd+386JS2bHlnuA8+b8DYdCRHBgW7MicVpbsroaUM0XpQCko QpWczESdpQrB3x+Mh2DgJV5dFG6lBtDuMVLDGDceDRHA1l7J4QKJAM2PKwaNUpyB0HVVwaY7QYM16 iMt1nPuQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qDd-003uU3-4a; Thu, 30 Dec 2021 07:51:25 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plR-003kFh-B4 for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:19 +0000 Received: by mail-yb1-xb49.google.com with SMTP id s84-20020a254557000000b0060ac37f4bb1so29562450yba.5 for ; Wed, 29 Dec 2021 23:22: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=rP8ip1untvKGcveI9MVlNiR5K/ovCndq9tVyyZVMRi8=; b=R4sOJhYmydPctklNw01MJ/rb+re5LguDPGbwngFXgxv2OAZbjNZGN+w0fR1zhyqiyn 5SBC0kFK0Zfab8tsgcluaMnpovdgXFkIwEQ2bZrhjx4RmeW7hJoP2N7mbJdaorcigsG6 7j1tU/+5b82zOJ4Z1ZC9d2CXgdcBy8L3fFmFuixE7eBrENCewYWVwpr7EIv5Dks4LG9K /lqeB3mbDl/bM7cT16tnYqanM6UbII/27YwFJlT+L4+Lo63E+Cen9WwyYo/fNK/3RFC0 YOvhdRqy+joyxuRO8sLQkBd6nNMI5ca2YtGBhJufdD5rlVBSmbU/tOL4am0gd926vSJB ly5w== 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=rP8ip1untvKGcveI9MVlNiR5K/ovCndq9tVyyZVMRi8=; b=PYYzvNT+yUJO4/0BWy3hqzabEIrejIET/3AwJAG39Mc2NadLvrxnzNmaFO9JxaXIbH A+pebEh26v/P6B6LgQ7XPKd/u5Ltk7I+zK+6hpF1k7vPTOpFPI2obh1S8H8pqaL1o9TU zmAm1ZPtrVdjuxzJ+Db278+80w8IqGBE4kW7wvrCWVnOAeQV5in1Hu+DKwj/yOIl9sz5 2upSfoTmkaSfKayWSybrsnWOycCTsLesrOikUzDfPuMN0RAQoYERzUhFUBhRxo0ppYrt gaNwicUqAVyRQufNaUaJTu1owUGQAhZb8ccsrW1oFVFy146wSgcrL2WtQg2X9DXWjEzJ p1MA== X-Gm-Message-State: AOAM532siUqkwQywVl1BJ//uCWk5sffBk+t7FLF8NfukFQo9uGMmdusv Ad0nf12QT5nlxmZNicujUFLphnC3R+sQ X-Google-Smtp-Source: ABdhPJy24aCEeLl9lJG1uM9REA7mFF/LzdTIXcwJMPisp3xe/m0TsayLCWEL/ws9Erxc66hxifFuYV6zoiWI X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a5b:d05:: with SMTP id y5mr25787400ybp.300.1640848935969; Wed, 29 Dec 2021 23:22:15 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:21 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-41-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232217_457736_8DAB8FC4 X-CRM114-Status: GOOD ( 21.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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, const char *filter) } /* 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); } int evsel__enable(struct evsel *evsel) @@ -1387,9 +1387,9 @@ int evsel__enable(struct evsel *evsel) } /* 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); } int evsel__disable(struct evsel *evsel) @@ -1455,7 +1455,7 @@ void evsel__delete(struct evsel *evsel) free(evsel); } -void evsel__compute_deltas(struct evsel *evsel, int cpu, int thread, +void evsel__compute_deltas(struct evsel *evsel, int cpu_map_idx, int thread, 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; - if (cpu == -1) { + if (cpu_map_idx == -1) { tmp = evsel->prev_raw_counts->aggr; evsel->prev_raw_counts->aggr = *count; } else { - tmp = *perf_counts(evsel->prev_raw_counts, cpu, thread); - *perf_counts(evsel->prev_raw_counts, cpu, thread) = *count; + tmp = *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread); + *perf_counts(evsel->prev_raw_counts, cpu_map_idx, thread) = *count; } count->val = 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); } -static void evsel__set_count(struct evsel *counter, int cpu, int thread, u64 val, u64 ena, u64 run) +static void evsel__set_count(struct evsel *counter, int cpu_map_idx, int thread, + u64 val, u64 ena, u64 run) { struct perf_counts_values *count; - count = perf_counts(counter->counts, cpu, thread); + count = perf_counts(counter->counts, cpu_map_idx, thread); count->val = val; count->ena = ena; count->run = run; - perf_counts__set_loaded(counter->counts, cpu, thread, true); + perf_counts__set_loaded(counter->counts, cpu_map_idx, thread, true); } -static int evsel__process_group_data(struct evsel *leader, int cpu, int thread, u64 *data) +static int evsel__process_group_data(struct evsel *leader, int cpu_map_idx, int thread, u64 *data) { u64 read_format = leader->core.attr.read_format; struct sample_read_value *v; @@ -1515,7 +1516,7 @@ static int evsel__process_group_data(struct evsel *leader, int cpu, int thread, v = (struct sample_read_value *) data; - evsel__set_count(leader, cpu, thread, v[0].value, ena, run); + evsel__set_count(leader, cpu_map_idx, thread, v[0].value, ena, run); for (i = 1; i < nr; i++) { struct evsel *counter; @@ -1524,7 +1525,7 @@ static int evsel__process_group_data(struct evsel *leader, int cpu, int thread, if (!counter) return -EINVAL; - evsel__set_count(counter, cpu, thread, v[i].value, ena, run); + evsel__set_count(counter, cpu_map_idx, thread, v[i].value, ena, run); } return 0; @@ -1643,16 +1644,16 @@ static void evsel__remove_fd(struct evsel *pos, int nr_cpus, int nr_threads, int } 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; - if (cpu_idx >= nr_cpus || thread_idx >= nr_threads) + if (cpu_map_idx >= nr_cpus || thread_idx >= nr_threads) return -EINVAL; evlist__for_each_entry(evsel->evlist, pos) { - nr_cpus = pos != evsel ? nr_cpus : cpu_idx; + nr_cpus = pos != evsel ? nr_cpus : cpu_map_idx; evsel__remove_fd(pos, nr_cpus, nr_threads, thread_idx); @@ -1667,7 +1668,7 @@ static int update_fds(struct evsel *evsel, } 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; if (thread_map__remove(threads, thread)) @@ -1974,9 +1975,9 @@ bool evsel__increase_rlimit(enum rlimit_action *set_rlimit) 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 = -1, err, old_errno; enum rlimit_action set_rlimit = NO_CHANGE; @@ -2003,7 +2004,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, display_attr(&evsel->core.attr); - for (cpu = start_cpu; cpu < end_cpu; cpu++) { + for (idx = start_cpu_map_idx; idx < end_cpu_map_idx; idx++) { for (thread = 0; thread < nthreads; thread++) { int fd, group_fd; @@ -2014,17 +2015,17 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, if (!evsel->cgrp && !evsel->core.system_wide) pid = perf_thread_map__pid(threads, thread); - group_fd = get_group_fd(evsel, cpu, thread); + group_fd = get_group_fd(evsel, idx, thread); test_attr__ready(); 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); - fd = sys_perf_event_open(&evsel->core.attr, pid, cpus->map[cpu], + fd = sys_perf_event_open(&evsel->core.attr, pid, cpus->map[idx], group_fd, evsel->open_flags); - FD(evsel, cpu, thread) = fd; + FD(evsel, idx, thread) = fd; if (fd < 0) { err = -errno; @@ -2034,10 +2035,10 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, goto try_fallback; } - bpf_counter__install_pe(evsel, cpu, fd); + bpf_counter__install_pe(evsel, idx, fd); 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); } @@ -2078,7 +2079,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, if (evsel__precise_ip_fallback(evsel)) goto retry_open; - if (evsel__ignore_missing_thread(evsel, cpus->nr, cpu, threads, thread, err)) { + if (evsel__ignore_missing_thread(evsel, cpus->nr, idx, threads, thread, err)) { /* We just removed 1 thread, so lower the upper nthreads limit. */ nthreads--; @@ -2093,7 +2094,7 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, if (err == -EMFILE && evsel__increase_rlimit(&set_rlimit)) goto retry_open; - if (err != -EINVAL || cpu > 0 || thread > 0) + if (err != -EINVAL || idx > 0 || thread > 0) goto out_close; if (evsel__detect_missing_features(evsel)) @@ -2105,12 +2106,12 @@ static int evsel__open_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, old_errno = errno; do { while (--thread >= 0) { - if (FD(evsel, cpu, thread) >= 0) - close(FD(evsel, cpu, thread)); - FD(evsel, cpu, thread) = -1; + if (FD(evsel, idx, thread) >= 0) + close(FD(evsel, idx, thread)); + FD(evsel, idx, thread) = -1; } thread = nthreads; - } while (--cpu >= 0); + } while (--idx >= 0); errno = old_errno; return err; } @@ -2127,13 +2128,13 @@ void evsel__close(struct evsel *evsel) perf_evsel__free_id(&evsel->core); } -int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu) +int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx) { - if (cpu == -1) + if (cpu_map_idx == -1) return evsel__open_cpu(evsel, cpus, NULL, 0, cpus ? cpus->nr : 1); - return evsel__open_cpu(evsel, cpus, NULL, cpu, cpu + 1); + return evsel__open_cpu(evsel, cpus, NULL, cpu_map_idx, cpu_map_idx + 1); } int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads) @@ -2954,15 +2955,15 @@ struct perf_env *evsel__env(struct evsel *evsel) static int store_evsel_ids(struct evsel *evsel, struct evlist *evlist) { - int cpu, thread; + int cpu_map_idx, thread; - for (cpu = 0; cpu < xyarray__max_x(evsel->core.fd); cpu++) { + for (cpu_map_idx = 0; cpu_map_idx < xyarray__max_x(evsel->core.fd); cpu_map_idx++) { for (thread = 0; thread < xyarray__max_y(evsel->core.fd); thread++) { - int fd = FD(evsel, cpu, thread); + int fd = FD(evsel, cpu_map_idx, thread); 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_attr *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); -int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu); +int evsel__open_per_cpu(struct evsel *evsel, struct perf_cpu_map *cpus, int cpu_map_idx); int evsel__open_per_thread(struct evsel *evsel, struct perf_thread_map *threads); 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 = &evsel->core.attr; struct evsel *leader = evsel__leader(evsel); @@ -585,7 +585,7 @@ int create_perf_stat_counter(struct evsel *evsel, } 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); 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); From patchwork Thu Dec 30 07:20:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701302 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA364C433EF for ; Thu, 30 Dec 2021 07:53:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ihoiMmKIH6Qr+s4n345/EWRa6fEwOv9ZbqQtsfTPUos=; b=329zIdb1PWMeEkGTkLVOIpxHra bWERcJzhBvkI248aDzhQCEJFTEdmkIXS7BYg4us23xkPu4jnIBzTu6PQeaNLGIVzmYOQDfsW2bAhh ONAB1risbm4hKEVGzo6lXvleefB4OBGk1StvrUKOjqYBcpHqUJi4NwE6ctxGlAi2zUvPdoc4bUcGv aYvKR7eaMPz57WUM+tjjr9GOiEf1GVw/4cLKflcJgNqsMZHGu/bttTbXmK5JOrFdHI+D+a1RzNeW6 8nCvevP6D1cZJTnyva+SvXiCp61dhBdzViEa5zKOFev9jLo8LPc83hzmpvBIaQKwjkCkSbEBy8kiP JMeYmXPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qEa-003uo3-4k; Thu, 30 Dec 2021 07:52:24 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plU-003kHG-Cr for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:21 +0000 Received: by mail-yb1-xb49.google.com with SMTP id p140-20020a257492000000b0060dbb88d8abso11652288ybc.15 for ; Wed, 29 Dec 2021 23:22:19 -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=zv8Au8yEBbpBWPa207TVw47r1vENU76hbFmK75NTzaI=; b=cm5pC41StIJJ8ZTI6ni5rDmi8zqtUkXa6N2IC/yAHj5WHEzVKTdBu0wB8K3poeDkag QFnOLF4mucomBZ/iPBrTu5/Ng+0C1r7IhfcJA1yYG7aXw0QISw4BpF3cKCajx7mdSXwX 5tifU2Wjrb/tvq2B1mqCm8BnEe8TT076JLDktKfUebxQnSbrVW4TYdKj7FngNVn0jIyP XPggI65FTzvFpqFmsUfZQ7MakRzid3dDp5D68fpgsA9/T+jufiDdRjeJl45r7D/WRcJG TmQDF8Z913vTmA/AZbcV/eFSCLyCm/fmA3PhICJCtRmuyYvFrrbP3BykqknShuMxSrW1 BiOQ== 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=zv8Au8yEBbpBWPa207TVw47r1vENU76hbFmK75NTzaI=; b=URz7O5TH2xv+MWx6UPYuFXWQwyY37FCvfsqLRYpoM+vjIGH7wsxwTvm4Zmp33S5z/m UTgPIJfEW+DQFTkaphmtaJtxXesQCND6uC47aX3AaNm+OZTqMtXtE/JaIeGKEbvSmolL tKGDDed2v6iU0hsWFzcdh0egMVYfnB0kA2NJr2omVmVOaiMm/mySKiWilhAz0PGqnd57 S+Sc3TkDLEe+wYzAzIhBBLforsyIIzCzTZriSneaL2Guj+kcSLKA3T0zD4eZFdyWuNl1 dIgQABliPmKw+byQhFBpMaEV1B7j6fTNMcJV203NTKPeSW/WhOJpVgjDUeP2WeOosn51 RLww== X-Gm-Message-State: AOAM533+jC10tjp6RbA+wUMsNjLxVAXb0PPCdF+hwf3gI9+gCVT+vO0l l8pZn0LddfpdHTr60nnilLqFpWG5BWxG X-Google-Smtp-Source: ABdhPJw1Ll8Ncrw9J+MROnunrWaGDWAMTzviVpnbWMtVY0h4rw0YkaMGyM1QnS6GI4i7Sme5QRz3QetSYd3B X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:2c89:: with SMTP id s131mr23705628ybs.504.1640848938565; Wed, 29 Dec 2021 23:22:18 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:22 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-42-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232220_490953_55FE8C12 X-CRM114-Status: GOOD ( 15.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = -1, fd, cpu; + int err = -1, fd, idx, cpu; struct perf_cpu_map *cpus; struct evsel *evsel; unsigned int nr_openat_calls = 111, i; @@ -58,23 +58,23 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test __mayb goto out_evsel_delete; } - for (cpu = 0; cpu < cpus->nr; ++cpu) { - unsigned int ncalls = nr_openat_calls + cpu; + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + unsigned int ncalls = 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] >= CPU_SETSIZE) { - pr_debug("Ignoring CPU %d\n", cpus->map[cpu]); + if (cpu >= CPU_SETSIZE) { + pr_debug("Ignoring CPU %d\n", cpu); continue; } - 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(struct test_suite *test __mayb fd = openat(0, "/etc/passwd", O_RDONLY); close(fd); } - CPU_CLR(cpus->map[cpu], &cpu_set); + CPU_CLR(cpu, &cpu_set); } evsel->core.cpus = perf_cpu_map__get(cpus); err = 0; - for (cpu = 0; cpu < cpus->nr; ++cpu) { + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { unsigned int expected; - if (cpus->map[cpu] >= CPU_SETSIZE) + if (cpu >= CPU_SETSIZE) continue; - 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 = -1; break; } - expected = nr_openat_calls + cpu; - if (perf_counts(evsel->counts, cpu, 0)->val != expected) { + expected = nr_openat_calls + idx; + if (perf_counts(evsel->counts, idx, 0)->val != 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 = -1; } } From patchwork Thu Dec 30 07:20:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701303 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 40B2DC433F5 for ; Thu, 30 Dec 2021 07:54:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=CSfhPmx62R/s/o1IKvFhnu3J5dq/JH/PeLs1X3d3W4o=; b=S6+aakwMBSYFlc8Lvz3JwDfWoH IyKF1W099Gq+FUxfiywxV41PTguHXo7nbHQZEY92XbBvqYASSoREcE6s0q5T83mp+W3zEj63CwOUz X55eVLj/n7We2LLd6P2fXsIf8nOKeMc1HWJbb5EuzVziZkTcIWUthQ1KdS3ThwF8yn20VK8Wt7a00 MMswGSyiI5FtDSyKApxYAhJAN/Xbv7Vv3mwUttiTmmtBSYc8apxLuyIRfbBH4vtq/3tEvhcGIFV+M N9ouNOYQvlPDcyGpIX0nsxpzoxnChAwZw9ODtH2pA1Y8muoocbkDU6rarKv3HfMJsjRIFpb185BMZ zxoJyBZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qFZ-003v8G-8S; Thu, 30 Dec 2021 07:53:26 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plW-003kIX-NF for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:24 +0000 Received: by mail-yb1-xb49.google.com with SMTP id i65-20020a252244000000b0060b2e5fd54cso27650231ybi.13 for ; Wed, 29 Dec 2021 23:22: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=wNEaBrVID5KM3S+MlzNQlzdEQtierpy9+J1kdBtC9c0=; b=TTTFh460x4r9b2VRMxOY8iKhybAM8PiJtFbVyaJQ+0BhAnhyoi4p3/ga9+9CtkRtVy 7fnbaxN5FngrrBPE0JsqS5uiBRuG4mUEBWmxFJhHxhcaoJToebYhWvBO9e/IAAYGw28P O+PnpVudpwOjp+vWqKDhiOL0P2TVFNdrvgGNBIUOOpSSQfe+0+aSCzyQ9V8q3jXL/qQE oIsCcVPuZHbUq8JCeDnMwJksVHihpJ3qkSsLaakJ8C8f4vKc5y3SStdkzKgq0+jysypY BQM6bQedr+nfmGzX2/uyMeWM1yl+qtNiO/PrDS4msW2sE2j8YFmmkr6E3RP26YmCYCDn KiIw== 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=wNEaBrVID5KM3S+MlzNQlzdEQtierpy9+J1kdBtC9c0=; b=ewxLsTeNU/ROWYIxicNKn6YiqQhXoGnw9Oxa1WXjgUOYPeJVbVQdNBgfbXZlIGkPrG 7dRDwDrf2hd/r9WOd3SaeMhqAA0bW+JbMKYTYJARWfRBeTfGfzMW19K5X1gpGNmmWzqW ZPSqzD/OprgleRpHNoXqAuP/1ajQQADl1NvOP452TUQ6AE6geP5maFcW8vhSmUtfl5+k NsIg2fbkj43dt6I8DkTxZYWPYHJ7H8XareYp2ySkvdZaYutdImTCKk4fig9IFxFyIWWD NexVB7vBJJOry59UJqR47IQl/iwQiHNfdRvZw0Eh6/8Y/MSb/N22MQoseeZoflGDJdT6 YQgQ== X-Gm-Message-State: AOAM531hG6hPsF9ioHup29cWl2KUc9tnuROF7C2tDs/jOKBm4QXRdPmk CeyELpeC4MySbiO6s4cHY2X74432AQd8 X-Google-Smtp-Source: ABdhPJxW/7qLOvo7GcinKItCT/Oygb6bQu4X+oSp1J9l+1rucFRcLP4p2ZKPHw7ErmPDD8fVB6XK875oPE7y X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:a06a:: with SMTP id x97mr40512043ybh.411.1640848941095; Wed, 29 Dec 2021 23:22:21 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:23 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-43-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232222_796969_5A08AFC9 X-CRM114-Status: GOOD ( 12.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 void *__key2, return *key1 == *key2; } -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 = counter->per_pkg_mask; struct perf_cpu_map *cpus = evsel__cpus(counter); + int cpu = perf_cpu_map__cpu(cpus, cpu_map_idx); int s, d, ret = 0; uint64_t *key; From patchwork Thu Dec 30 07:20:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701305 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B5FA0C433EF for ; Thu, 30 Dec 2021 07:57:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BHWWq6MSidfU0FF90aPbJc87Tt25ztLofgL5X+7t2hM=; b=Yybz38VlgRuMf6St2Pd+1bKMUl oVV3eNDYcsRQliBbEFppd4zuZvorT/kbCrTCYiW3iYsj4BdAtducVi2yDX6gs/bkfBc6X6wdLDUm3 UmLhCa4YXOraD6k9MNxIzd3dv2DlHjn2xSPLyhKO/RN4W637yPEQJWSs6RVOJzOolphTT+jSyeWNm OSk9fZiM1bZtwOfzI/q4R5k5VJj0CBSA2Q5PYM5lxW4/lm+aaaaJeCSZdwK45zBIYz1lratQfvOgF 7K9sAN95vzh6DYrYW53s080S47P2WzFbdqIzVrkVbkCSZ7SwtdWj5+YQ9dmmetbdWuufZFfRHq+bK SxWUhShw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qHS-003vla-6J; Thu, 30 Dec 2021 07:55:24 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2pla-003kKa-21 for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:33 +0000 Received: by mail-pf1-x449.google.com with SMTP id t128-20020a628186000000b004bac607ec25so12598152pfd.11 for ; Wed, 29 Dec 2021 23:22:24 -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=4F7qH0ZBCFSqGz+2YAmykAzgrCxPY0T/2XHaaXFr9fE=; b=tiZx92ZPUkncWf4UKN2yw3DX/kfEu11OeeRAO1h7RNNbSn2lC5QFmDM97WTVqJ1QPf WLePGDoHWcTOnvaKTZM5sLcyVSBNJvjxRsQeY5sdU1F2uKH27PM0oMDqFVqa1SBb44y7 AJeZSJJZeTY5ErM1oUNbw6AQ9tPCkUXv13taDrSiWNVqpHr8S9XnAiiDwF3tnnLGCNxD PJIN3JRUNb5LJesu/3t54X8so3TG/2O1cuwUSHSvWdb2zz/nwbZKBW16iGmSJtrBsx9v EbDIUlxACN0nOwfmmMXn4K786umBFMWY5KoE1HeVSaDmZs3Cov6rUYUe9BSh7LTaki0F haLg== 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=4F7qH0ZBCFSqGz+2YAmykAzgrCxPY0T/2XHaaXFr9fE=; b=VaCBsMesf5op8ezt3DRK02NqJUdNY0GOp1W2qV891ZV7X2heMP+nDWJT27dFj41dF1 PLJHgwT4UYozpMpSW+2pJQ0m40aaaDC+oL+otpIDgyLdmHCY/TxREyjGondn8o4lom0k kbyKVy3IZAdhoVud0Z6BhWCGtJJW+VdWjlOUTBFqNORsWvnvaI4p4zWjGTv9LEHQolN2 ag1KiyXZpav2jNHPf8TBKZumqg5wq7w/MQXx3PZ3nT79TdR3H8aerfsysK3vR8qKucNf vDDTu56cELUqlIB/B8kUn9e5ZOXkWWrgm4+EHFFfro6MccjV9Rl64i3h1PA5zYgLW21A mQ7A== X-Gm-Message-State: AOAM533qCmMOKjS8IFmBfvZkgwl/XK52fYbP+yUGjyESpyXO3OiNOFZz aoRphNGjjI52GdtIcptq8aYkSJd37OIk X-Google-Smtp-Source: ABdhPJxjTT4tiEG5fYuhmaeKUE7/MaosMpMW/3+7JKkhPULY9Pea1n/rerMRCEahaYRgUM/0/7BhkwDoy0SO X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a62:e904:0:b0:4a4:b4e3:a712 with SMTP id j4-20020a62e904000000b004a4b4e3a712mr30271843pfh.25.1640848943864; Wed, 29 Dec 2021 23:22:23 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:24 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-44-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232226_246169_AFB77BA4 X-CRM114-Status: GOOD ( 16.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 = entry; - if (a->cpu != b->cpu) - return a->cpu - b->cpu; + if (a->cpu_map_idx != b->cpu_map_idx) + return a->cpu_map_idx - b->cpu_map_idx; /* * Previously the rbtree was used to link generic metrics. @@ -105,7 +105,7 @@ static void saved_value_delete(struct rblist *rblist __maybe_unused, } 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 evsel *evsel, struct rblist *rblist; struct rb_node *nd; struct saved_value dm = { - .cpu = cpu, + .cpu_map_idx = cpu_map_idx, .evsel = evsel, .type = type, .ctx = ctx, @@ -213,10 +213,10 @@ struct runtime_stat_data { 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 = saved_value_lookup(NULL, cpu, true, type, + struct saved_value *v = saved_value_lookup(NULL, cpu_map_idx, true, type, rsd->ctx, st, rsd->cgrp); 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 = count; struct saved_value *v; @@ -241,88 +241,88 @@ void perf_stat__update_shadow_stats(struct evsel *counter, u64 count, count *= counter->scale; 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); if (counter->collect_stat) { - v = saved_value_lookup(counter, cpu, true, STAT_NONE, 0, st, + v = 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 += count; } else if (counter->metric_leader) { v = 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 += count; v->metric_other++; } @@ -464,12 +464,12 @@ void perf_stat__collect_metric_expr(struct evlist *evsel_list) } 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; - v = saved_value_lookup(NULL, cpu, false, type, rsd->ctx, st, rsd->cgrp); + v = saved_value_lookup(NULL, cpu_map_idx, false, type, rsd->ctx, st, rsd->cgrp); if (!v) return 0.0; @@ -477,12 +477,12 @@ static double runtime_stat_avg(struct runtime_stat *st, } 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; - v = saved_value_lookup(NULL, cpu, false, type, rsd->ctx, st, rsd->cgrp); + v = saved_value_lookup(NULL, cpu_map_idx, false, type, rsd->ctx, st, rsd->cgrp); if (!v) return 0.0; @@ -490,7 +490,7 @@ static double runtime_stat_n(struct runtime_stat *st, } 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_stat_config *config, double total, ratio = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_CYCLES, cpu, rsd); + total = runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -513,7 +513,7 @@ static void print_stalled_cycles_frontend(struct perf_stat_config *config, } 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_stat_config *config, double total, ratio = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_CYCLES, cpu, rsd); + total = runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -532,7 +532,7 @@ static void print_stalled_cycles_backend(struct perf_stat_config *config, } 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 = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_BRANCHES, cpu, rsd); + total = runtime_stat_avg(st, STAT_BRANCHES, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -551,7 +551,7 @@ static void print_branch_misses(struct perf_stat_config *config, } 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_config *config, double total, ratio = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_L1_DCACHE, cpu, rsd); + total = runtime_stat_avg(st, STAT_L1_DCACHE, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -570,7 +570,7 @@ static void print_l1_dcache_misses(struct perf_stat_config *config, } 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_config *config, double total, ratio = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_L1_ICACHE, cpu, rsd); + total = runtime_stat_avg(st, STAT_L1_ICACHE, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -588,7 +588,7 @@ static void print_l1_icache_misses(struct perf_stat_config *config, } 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_config *config, double total, ratio = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_DTLB_CACHE, cpu, rsd); + total = runtime_stat_avg(st, STAT_DTLB_CACHE, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -606,7 +606,7 @@ static void print_dtlb_cache_misses(struct perf_stat_config *config, } 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_config *config, double total, ratio = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_ITLB_CACHE, cpu, rsd); + total = runtime_stat_avg(st, STAT_ITLB_CACHE, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -624,7 +624,7 @@ static void print_itlb_cache_misses(struct perf_stat_config *config, } 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_config *config, double total, ratio = 0.0; const char *color; - total = runtime_stat_avg(st, STAT_LL_CACHE, cpu, rsd); + total = runtime_stat_avg(st, STAT_LL_CACHE, cpu_map_idx, rsd); if (total) ratio = avg / total * 100.0; @@ -690,61 +690,61 @@ static double sanitize_val(double x) return x; } -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); } -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 = 0; double total_slots; double total; - total = 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 = runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_ISSUED, cpu_map_idx, rsd) - + runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_RETIRED, cpu_map_idx, rsd) + + runtime_stat_avg(st, STAT_TOPDOWN_RECOVERY_BUBBLES, cpu_map_idx, rsd); - total_slots = td_total_slots(cpu, st, rsd); + total_slots = td_total_slots(cpu_map_idx, st, rsd); if (total_slots) bad_spec = total / total_slots; return sanitize_val(bad_spec); } -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 = 0; - double total_slots = td_total_slots(cpu, st, rsd); + double total_slots = td_total_slots(cpu_map_idx, st, rsd); double ret_slots = runtime_stat_avg(st, STAT_TOPDOWN_SLOTS_RETIRED, - cpu, rsd); + cpu_map_idx, rsd); if (total_slots) retiring = ret_slots / total_slots; return retiring; } -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 = 0; - double total_slots = td_total_slots(cpu, st, rsd); + double total_slots = td_total_slots(cpu_map_idx, st, rsd); double fetch_bub = runtime_stat_avg(st, STAT_TOPDOWN_FETCH_BUBBLES, - cpu, rsd); + cpu_map_idx, rsd); if (total_slots) fe_bound = fetch_bub / total_slots; return fe_bound; } -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 = (td_fe_bound(cpu, st, rsd) + - td_bad_spec(cpu, st, rsd) + - td_retiring(cpu, st, rsd)); + double sum = (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 == 0) return 0; return sanitize_val(1.0 - sum); @@ -755,15 +755,15 @@ static double td_be_bound(int cpu, struct runtime_stat *st, * the ratios we need to recreate the sum. */ -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 = 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 = runtime_stat_avg(stat, type, cpu, rsd); + double sum = 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 = runtime_stat_avg(stat, type, cpu_map_idx, rsd); if (sum) return d / sum; @@ -775,23 +775,23 @@ static double td_metric_ratio(int cpu, enum stat_type type, * We allow two missing. */ -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 = 0; - 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 >= 2; } -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_idx, 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 *config, int cpu, double smi_num, aperf, cycles, cost = 0.0; const char *color = NULL; - smi_num = runtime_stat_avg(st, STAT_SMI_NUM, cpu, rsd); - aperf = runtime_stat_avg(st, STAT_APERF, cpu, rsd); - cycles = runtime_stat_avg(st, STAT_CYCLES, cpu, rsd); + smi_num = runtime_stat_avg(st, STAT_SMI_NUM, cpu_map_idx, rsd); + aperf = runtime_stat_avg(st, STAT_APERF, cpu_map_idx, rsd); + cycles = runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, rsd); if ((cycles == 0) || (aperf == 0)) return; @@ -818,7 +818,7 @@ static void print_smi_cost(struct perf_stat_config *config, 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 = 1e-9; source_count = 1; } else { - v = saved_value_lookup(metric_events[i], cpu, false, + v = 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 *config, 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 *config, return; pctx->runtime = runtime; - i = prepare_metric(metric_events, metric_refs, pctx, cpu, st); + i = 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 *config, expr__ctx_free(pctx); } -double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st) +double test_generic_metric(struct metric_expr *mexp, int cpu_map_idx, struct runtime_stat *st) { struct expr_parse_ctx *pctx; double ratio = 0.0; @@ -943,7 +943,7 @@ double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_sta if (!pctx) return NAN; - 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; if (expr__parse(&ratio, pctx, mexp->metric_expr)) @@ -956,7 +956,7 @@ double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_sta 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_config *config, if (config->iostat_run) { iostat_print_metric(config, evsel, out); } else if (evsel__match(evsel, HARDWARE, HW_INSTRUCTIONS)) { - total = runtime_stat_avg(st, STAT_CYCLES, cpu, &rsd); + total = runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, &rsd); if (total) { ratio = avg / total; @@ -985,11 +985,11 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, print_metric(config, ctxp, NULL, NULL, "insn per cycle", 0); } - total = runtime_stat_avg(st, STAT_STALLED_CYCLES_FRONT, cpu, &rsd); + total = runtime_stat_avg(st, STAT_STALLED_CYCLES_FRONT, cpu_map_idx, &rsd); total = max(total, runtime_stat_avg(st, STAT_STALLED_CYCLES_BACK, - cpu, &rsd)); + cpu_map_idx, &rsd)); if (total && avg) { out->new_line(config, ctxp); @@ -999,8 +999,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, ratio); } } else if (evsel__match(evsel, HARDWARE, HW_BRANCH_MISSES)) { - if (runtime_stat_n(st, STAT_BRANCHES, cpu, &rsd) != 0) - print_branch_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_BRANCHES, cpu_map_idx, &rsd) != 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_config *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { - if (runtime_stat_n(st, STAT_L1_DCACHE, cpu, &rsd) != 0) - print_l1_dcache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_L1_DCACHE, cpu_map_idx, &rsd) != 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_config *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { - if (runtime_stat_n(st, STAT_L1_ICACHE, cpu, &rsd) != 0) - print_l1_icache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_L1_ICACHE, cpu_map_idx, &rsd) != 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_config *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { - if (runtime_stat_n(st, STAT_DTLB_CACHE, cpu, &rsd) != 0) - print_dtlb_cache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_DTLB_CACHE, cpu_map_idx, &rsd) != 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_config *config, ((PERF_COUNT_HW_CACHE_OP_READ) << 8) | ((PERF_COUNT_HW_CACHE_RESULT_MISS) << 16))) { - if (runtime_stat_n(st, STAT_ITLB_CACHE, cpu, &rsd) != 0) - print_itlb_cache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_ITLB_CACHE, cpu_map_idx, &rsd) != 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))) { - if (runtime_stat_n(st, STAT_LL_CACHE, cpu, &rsd) != 0) - print_ll_cache_misses(config, cpu, avg, out, st, &rsd); + if (runtime_stat_n(st, STAT_LL_CACHE, cpu_map_idx, &rsd) != 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 = runtime_stat_avg(st, STAT_CACHEREFS, cpu, &rsd); + total = runtime_stat_avg(st, STAT_CACHEREFS, cpu_map_idx, &rsd); if (total) ratio = avg * 100 / total; - if (runtime_stat_n(st, STAT_CACHEREFS, cpu, &rsd) != 0) + if (runtime_stat_n(st, STAT_CACHEREFS, cpu_map_idx, &rsd) != 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 = runtime_stat_avg(st, STAT_NSECS, cpu, &rsd); + total = runtime_stat_avg(st, STAT_NSECS, cpu_map_idx, &rsd); if (total) { ratio = avg / total; @@ -1078,7 +1078,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, print_metric(config, ctxp, NULL, NULL, "Ghz", 0); } } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX)) { - total = runtime_stat_avg(st, STAT_CYCLES, cpu, &rsd); + total = runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, &rsd); if (total) print_metric(config, ctxp, NULL, @@ -1088,8 +1088,8 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, print_metric(config, ctxp, NULL, NULL, "transactional cycles", 0); } else if (perf_stat_evsel__is(evsel, CYCLES_IN_TX_CP)) { - total = runtime_stat_avg(st, STAT_CYCLES, cpu, &rsd); - total2 = runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu, &rsd); + total = runtime_stat_avg(st, STAT_CYCLES, cpu_map_idx, &rsd); + total2 = runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd); if (total2 < avg) total2 = 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 = runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu, &rsd); + total = runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd); if (avg) ratio = total / avg; - if (runtime_stat_n(st, STAT_CYCLES_IN_TX, cpu, &rsd) != 0) + if (runtime_stat_n(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd) != 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 = runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu, &rsd); + total = runtime_stat_avg(st, STAT_CYCLES_IN_TX, cpu_map_idx, &rsd); if (avg) ratio = 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 = td_fe_bound(cpu, st, &rsd); + double fe_bound = td_fe_bound(cpu_map_idx, st, &rsd); if (fe_bound > 0.2) color = 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 = td_retiring(cpu, st, &rsd); + double retiring = td_retiring(cpu_map_idx, st, &rsd); if (retiring > 0.7) color = 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 = td_bad_spec(cpu, st, &rsd); + double bad_spec = td_bad_spec(cpu_map_idx, st, &rsd); if (bad_spec > 0.1) color = 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 = td_be_bound(cpu, st, &rsd); + double be_bound = td_be_bound(cpu_map_idx, st, &rsd); const char *name = "backend bound"; static int have_recovery_bubbles = -1; @@ -1158,14 +1158,14 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *config, if (be_bound > 0.2) color = 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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double retiring = 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_config *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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double fe_bound = 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_config *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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double be_bound = 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_config *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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd)) { + double bad_spec = 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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double retiring = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_RETIRING, st, &rsd); - double heavy_ops = td_metric_ratio(cpu, + double heavy_ops = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_HEAVY_OPS, st, &rsd); double light_ops = 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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double bad_spec = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BAD_SPEC, st, &rsd); - double br_mis = td_metric_ratio(cpu, + double br_mis = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BR_MISPREDICT, st, &rsd); double m_clears = 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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double fe_bound = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_FE_BOUND, st, &rsd); - double fetch_lat = td_metric_ratio(cpu, + double fetch_lat = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_FETCH_LAT, st, &rsd); double fetch_bw = 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 = td_metric_ratio(cpu, + full_td(cpu_map_idx, st, &rsd) && (config->topdown_level > 1)) { + double be_bound = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_BE_BOUND, st, &rsd); - double mem_bound = td_metric_ratio(cpu, + double mem_bound = td_metric_ratio(cpu_map_idx, STAT_TOPDOWN_MEM_BOUND, st, &rsd); double core_bound = 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) != 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) != 0) { char unit = ' '; char unit_buf[10] = "/sec"; - total = runtime_stat_avg(st, STAT_NSECS, cpu, &rsd); + total = runtime_stat_avg(st, STAT_NSECS, cpu_map_idx, &rsd); if (total) ratio = convert_unit_double(1000000000.0 * avg / total, &unit); @@ -1294,7 +1294,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *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 = 0; } @@ -1307,7 +1307,7 @@ void perf_stat__print_shadow_stats(struct perf_stat_config *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 == 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, struct perf_counts_values *vals, static int process_counter_values(struct perf_stat_config *config, struct evsel *evsel, - int cpu, int thread, + int cpu_map_idx, int thread, struct perf_counts_values *count) { struct perf_counts_values *aggr = &evsel->counts->aggr; static struct perf_counts_values zero; bool skip = false; - 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 *config, 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 == AGGR_NONE) && (!evsel->percore)) { perf_stat__update_shadow_stats(evsel, count->val, - cpu, &rt_stat); + cpu_map_idx, &rt_stat); } if (config->aggr_mode == AGGR_THREAD) { @@ -412,15 +412,15 @@ static int process_counter_maps(struct perf_stat_config *config, { int nthreads = perf_thread_map__nr(counter->core.threads); int ncpus = evsel__nr_cpus(counter); - int cpu, thread; + int idx, thread; if (counter->core.system_wide) nthreads = 1; for (thread = 0; thread < nthreads; thread++) { - for (cpu = 0; cpu < ncpus; cpu++) { - if (process_counter_values(config, counter, cpu, thread, - perf_counts(counter->counts, cpu, thread))) + for (idx = 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, struct perf_stat_config *conf struct target *_target, struct timespec *ts, int argc, const char **argv); struct metric_expr; -double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st); +double test_generic_metric(struct metric_expr *mexp, int cpu_map_idx, struct runtime_stat *st); #endif From patchwork Thu Dec 30 07:20:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701304 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 68D65C433F5 for ; Thu, 30 Dec 2021 07:55:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=G8P5S+8ofyOvhYqFZkOmoZ0kESMCV5DektA2/mmeNYs=; b=IrhW/3Pjs9n4G+rxj+T2+4ooh5 IB5C83aW+MMyISv//aHRw5tCoT//w4ABNy2d0zNd5GRpJ+RDfzVRkNERkwQ94J3p90GIL6C9ONEh3 iyyHBxKFajZ8JwCi4yiHIrrqEw94rvoKcV7kHfJqh60lCaNSoGgbBEnjywp8OxMLWh+wVa49FnHsa tHeRWlsQ8e/g4hiN0GXsJkljFIoY6/NC8u7GnEEX5psV7m6bXyUhxrDaFRflRoUWnjkLBtcGnqngB bhSbbHaiQ337qCG9WXRrrJR3zgjWAPr9OrFNch/LOJHwQyxO7dbDe9SkFVJJQgG02NeSunsSoZbLk 1SR3PykA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qGb-003vUZ-Lk; Thu, 30 Dec 2021 07:54:30 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plc-003kMI-Ql for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:33 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id p140-20020a257492000000b0060dbb88d8abso11652610ybc.15 for ; Wed, 29 Dec 2021 23:22: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=EYvYMoHkX/cH/EEuV/LiHLhSTbFzgAzJd57ZEVR8Iu4=; b=NVVuPj96aldimSuJGWBAOg3INqZBKkVX1HMo9hlPXfRClq62GtJDqNPNzcIapVWz2B WAKxhM6ngSqrwev6kOnNIkzF9I3knUMFdzGJIvAdo+7YPkvx2KSBf5CWVcFS3aNPcSav /nwpL6te2utE0H5Wqs62uXgDrsQogRUnZgMy6TT7XQn2Iu1I9WA0NeEDiCWmvi+vSQy/ nS2dkuvpfCfAyzxmFe470/Xf6GzoIjV2FbjvlZfsu8JtMPu12OqeDdbrvejPjqSXeL9g Pdqx3KpcQ/rtg8ZfkrqeTrsDfzaVzZJTiZSy6bXkni7sPP7PotJcAC0NhsnzMDkFWDtf 3kfw== 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=EYvYMoHkX/cH/EEuV/LiHLhSTbFzgAzJd57ZEVR8Iu4=; b=l2YnSeX7VUQ4fFkUS0dEZUuDbfQWRX4yMGkmclTvGER8CqgWkaXyZOtYgMqqugmhnH ZsDidWnYKhdkMqRvh1L9k1oR4efpayD+oPbYaYKcBxzT6ChhmJBJUdDMFOnZmKshV90u B+2JW8VJpiWFNj2aNaJwwnDPPju+R9mujJE9XnKqmKV+FIbZT3qAwQ7tPgJwSsW/UGeY l9b90a3MztHeXNGMGw3FBJDaI917eeCyda+d9bDQZ+vql+3PDz5tvk9e7CHtIdNPLjYh /sHX43pqm2HMQ9xmeFh5uEUX7XJT43T4sgqiONyCF5JWseXAalYTgsTcF0/yvcRjIK5C u+UA== X-Gm-Message-State: AOAM533dgf4yxWM0bSKYXXt3eVCrzka3UZb4fxYXlfv00vyAsnDgLnFZ QgcuuhvSVQgLxlVNla5hk1G1ETCQOUTi X-Google-Smtp-Source: ABdhPJzprlVuniOvf96Uc4KFiSV+VfOhO1ZJPQT5NEAUi/ZPilJtwj9Sjp7ZAfOpIK+J19M3Y07RDFxxjwJD X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:ab94:: with SMTP id v20mr28886251ybi.338.1640848946562; Wed, 29 Dec 2021 23:22:26 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:25 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-45-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232228_972165_5EEA2571 X-CRM114-Status: GOOD ( 11.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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/Documentation/libperf.txt index faef9ba3a540..32c5051c24eb 100644 --- a/tools/lib/perf/Documentation/libperf.txt +++ b/tools/lib/perf/Documentation/libperf.txt @@ -136,16 +136,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 thread); - 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, int thread); + int perf_evsel__read(struct perf_evsel *evsel, int cpu_map_idx, int thread, 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); From patchwork Thu Dec 30 07:20:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BB3E2C433EF for ; Thu, 30 Dec 2021 07:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hrIyZSQIZSPT7FyWm7Er1Zuia5m0mkvAeWadnB9avO8=; b=xm5A2KgQkwCjakXp8rEJAUGOuU Se6AZvKcek7hKFVl3eiGW4C6hxTcfMMpZTXFB8TpgUBULtXAGT/JnHMdXCfHO/81YXBsDzp79txj1 NwjQy82NR1TTz/WoF9fA2zeiiOR0mOhc56dO23uC6IHWGyl/LVLnHH+aqagB4uSCTaJw/FU5l9ZXe ediJDon6Q931rg+MjI0P48IGBAnTA/m09rWzkFbIyckQ/jVf5Hm2q0JmPwoVUzNqkD8h/JxqE2tT6 8rldNU8vPweKegpbBAnSiXRDc7YL9jvL2Cz7Na1+Fpwe/36hNEAOgWFki1o0yEEau6LoFoniLeKfh z+fqD7MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qIV-003w6K-26; Thu, 30 Dec 2021 07:56:29 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plf-003kNH-46 for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:34 +0000 Received: by mail-yb1-xb49.google.com with SMTP id e2-20020a25d302000000b0060c57942183so22012736ybf.18 for ; Wed, 29 Dec 2021 23:22:29 -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=Uc3y2XubM268HoD+IkmNJwiXqvYvgqQuPR9NEiJZLmc=; b=UU9Pps5USbCJB4bMY54SQPTOXdYoggeqA3PNH6FHoGJpEWCJcemclzPo3evy9MM9Tw PFOiwuSZsYroPQcFSKpYwzB5ZfSSv7dGEOOoc0quUBwg0uPmdY/GztO9m31OIDCEizc5 hmU2hv7EmRANtiTJbTXr1O6zp+YQKyUFq1Bp/1PWYZsvlNdDknRqgzMZDggwdNMcknXP B25Dix/qD0wblGheSYh68qCPU2AIrUHzja2sf/xFx5v79YZKDINeE/Whrz2w7VYK29k2 ZPf1nH4RVbBAyH4aci0WckZMl/RZDFVZ/ryooqZ7YSTBO4Vajwx0CbhtYW9Jw+0WKqfl BI0w== 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=Uc3y2XubM268HoD+IkmNJwiXqvYvgqQuPR9NEiJZLmc=; b=nHH4RgSn+aNs8bfCI+8vWOr2rMEqOtI6Fpc5p+6xppThLVoLLq2KFdpvJaH86gYzEX fLy/R3vgcxHAD8n+FQZYWlyw7CrjHI/QQrwVse4bzDtA9Jk+zsZRfNf706TRZkFgRYXD 4eRqfmrWCZq51qo1R/cWw5vIX4bxZ+AxkJfV6cQawwwVSIlnALgG0M4xBaW2321CKqdT bCjZyxkbVn2YdzHWdLpcdOoflBgvbhSp01WgU09T/Dzh9KrNBicLRUKDJl+dyrp4etSn 7WIocl7eXn6dW8r09XCp1owhk5F0BTaRY+5E3Ct3eyeu65cwv6aSf+ca4saU3FYn4HGy li0g== X-Gm-Message-State: AOAM532jmwmuX+7EsG1AZBjgfexkOndP64p68kpu3airpFm1HMCf/ifE FtsmDzkj8OlXtsiycWfuMPjGZAUCuVH2 X-Google-Smtp-Source: ABdhPJzmwD+JdTmKcnf+ab8su0Q2JjY8n7yE3uUXboDJEjQ387d40mnduQF8z1OV90YmVB5fjNjmBzrjrFrO X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:cc55:: with SMTP id l82mr29556005ybf.433.1640848949072; Wed, 29 Dec 2021 23:22:29 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:26 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-46-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232231_226753_90003370 X-CRM114-Status: GOOD ( 16.60 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 *evsel) return 0; } -static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu, +static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu_map_idx, int fd) { struct bpf_prog_profiler_bpf *skel; @@ -277,7 +277,7 @@ static int bpf_program_profiler__install_pe(struct evsel *evsel, int cpu, assert(skel != NULL); ret = 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 target *target) return err; } -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 = evsel->leader_skel; return bpf_map_update_elem(bpf_map__fd(skel->maps.events), - &cpu, &fd, BPF_ANY); + &cpu_map_idx, &fd, BPF_ANY); } /* @@ -623,9 +623,7 @@ static int bperf__read(struct evsel *evsel) case BPERF_FILTER_GLOBAL: assert(i == 0); - num_cpu = all_cpu_map->nr; - for (j = 0; j < num_cpu; j++) { - cpu = all_cpu_map->map[j]; + perf_cpu_map__for_each_cpu(cpu, j, all_cpu_map) { perf_counts(evsel->counts, cpu, 0)->val = values[cpu].counter; perf_counts(evsel->counts, cpu, 0)->ena = values[cpu].enabled; perf_counts(evsel->counts, cpu, 0)->run = values[cpu].running; @@ -757,11 +755,11 @@ static inline bool bpf_counter_skip(struct evsel *evsel) evsel->follower_skel == NULL; } -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); } 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); 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); #else /* HAVE_BPF_SKEL */ From patchwork Thu Dec 30 07:20:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9BDAC433F5 for ; Thu, 30 Dec 2021 07:58:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=cFW3OOCgHF8mMtUuKDwhRUAAvum0EDyeJxbVrpYWFik=; b=psjdDCLQP6NmMjg1T7XHyMOXQl y9Gdo+ChVJ7XCdF3lAkrebrQIrYHbDiJ6LR5zuudk5SympXRAAlXL99NI+V0OILb3pwEEiLxfNJXo xy2O709/l8PCJjd0Ugi/IB1ZJFkIA72JLqgg6QwDFT9JNUqDHeIe+Q/Koszkr7VWWnYyj9c548IJL gDrsb9PkrnqmJ6+VRXfkn1SWlE09mOq2p6689sq8yDJVCdNKOJn/WNzGwkZnW3P1g3yJH/mYAd+XW x9qqy9N93QK+U/fuxTbOu8Zmg3gNrerGEBO5bNEUEUjSov61y8OXwfAUghdSCtCaiiQcvrIM2PH7Q lIv4HpUQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qJI-003wR4-6I; Thu, 30 Dec 2021 07:57:17 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plh-003kOX-He for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:35 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id t184-20020a2546c1000000b006008b13c80bso42279571yba.1 for ; Wed, 29 Dec 2021 23:22: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=l4aITqAr4kAWUMdh1BRMLGLBNjKWhPafS6IoiJKe+3o=; b=eG/VkvxCAxv7FJdaMjw7BxI6/KZEFoB/JPtBET2zF5N6elUc1+n1tZcMFnSVRzn92A dWMCahCjXzUunPAFJ3rARUiOB/EKWyM5cN1+CzaVLlWO0cs00flPnuLlLeL4KzGfbp3j 0erZlMjNvKHGmrV4rOV2zd+aRP00m40w6sUQrt0+dbGaeN7uRIvazydNUmM1+lAFJAwn OzfE5iaB29vSXL4omRM5aUC1h6pIl3DBtFzZ9bjiNkHEQQqcPUwbxq16EeGX/Sh+siCd nhLbxfDL9cOhigw3uzfRUFWGBr0IYFZAysIa+l8pSc5YoGXgygNhgasPX5PYLGWuiMag qyyw== 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=l4aITqAr4kAWUMdh1BRMLGLBNjKWhPafS6IoiJKe+3o=; b=f7KsvN+NZTAss6s6Hcg+6XVmem5F6a4PVxhqhqFhcw5mWbRXwzx0lFSdFgqB0HDBS8 luVk6zma4EWC6o37o6By1UD/Cg9j9gTMmnW0T/gRxi2MFcV7DZ1MURGySOLO7gd+xW4Z eaxlnY62iiZAfqOAwRCaoUtp4JQTW3gJu9ohiQOnj0y41DEhkUT6XMzgQHF4dF5oE9Vl 8bWiyYcBH9EUhybg9BfeI1rLorZbx7ucENdArxjRFGzamgGSxFMyivQxeNAfNmgf+uZY zndh8Qj6gG5l2E/1IifdJLgw28m87IDJmfa4I5bEdxYGBaeCNTeYo6HUoHnMABon4CE3 54mg== X-Gm-Message-State: AOAM532mFdboS1VsuO9AOhWF1f85V2KUGHZ+xbrMTJutC3zqVCU5W7m+ /gB7LnLKad4izlTPSYDKtIWwzbuN0377 X-Google-Smtp-Source: ABdhPJz4PObQBINBLDM7ybJfAZH1GdUHrMFnx3ClsT9yMsZFN7tl4Vm/ezlizX+D+12RXPI8Dt+8uIx9LRhJ X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:bc85:: with SMTP id e5mr22499668ybk.330.1640848951716; Wed, 29 Dec 2021 23:22:31 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:27 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-47-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232233_643303_91871DAA X-CRM114-Status: GOOD ( 13.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; if (c2c.node_info > 2) @@ -2057,13 +2057,13 @@ static int setup_nodes(struct perf_session *session) if (perf_cpu_map__empty(map)) continue; - for (cpu = 0; cpu < map->nr; cpu++) { - set_bit(map->map[cpu], set); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + set_bit(cpu, set); - if (WARN_ONCE(cpu2node[map->map[cpu]] != -1, "node/cpu topology bug")) + if (WARN_ONCE(cpu2node[cpu] != -1, "node/cpu topology bug")) return -EINVAL; - cpu2node[map->map[cpu]] = node; + cpu2node[cpu] = node; } } From patchwork Thu Dec 30 07:20:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701308 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8C04DC433F5 for ; Thu, 30 Dec 2021 07:59:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=di5gK2Nk9ffOK7irvFUj+87uFadBZ+etsL+i+l2CeNU=; b=k/Rk+5C8FisbJuyjAmJALhDN3X UEfuipwh1Hr+X43xaecWP15A5P9Wa/tnuGWXwaNwVvZuz2CjfXcaBP76vkRc9YQov3WSzaXc0k4sH UFsKMGm2JBXFng6GprxoqFgx0Xdny5i9RsaGOcOaCGu7eX3kXwgRP7yl8N21giDNwtjfHKFb+WIZU 6DDBHJSrY8iMGpq8VtPVZRdzzeqSy6ZMRr3eozDqyhkqqi4OtNedbTrr34xiDdIUsaWWa4iy2PV3S I34bnNgQwciov8P47sZrRQfdYeIJKqmnLjx1iCZOdQLGwR++gidWMOKava1qES+vNWbi38/37xp9l NVM0XoTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qK4-003wio-KS; Thu, 30 Dec 2021 07:58:05 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plj-003kPy-Ux for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:39 +0000 Received: by mail-yb1-xb49.google.com with SMTP id i203-20020a2554d4000000b0060a529902b3so32488804ybb.21 for ; Wed, 29 Dec 2021 23:22:34 -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=nzKeKFAPBZ6rzV0NFigpy2eDVIi9FKR8HBRsYCkfB/U=; b=UsntoWcISBfoeUdNkLtrkqLUCXuV3C/cSCX/5Y8o/iLgg/RnXmD9ffJx2/3iJFFAiR E9jN91+rDWflo53Ca44K7pMJOnOFdSn/F0o2YdLW+qFnBjEGt9hU4LgsHuHAYvCt09Y+ RVanx7aw6p86GEW39zC3HrZjzIH9ExVTp/GX55VPjF9/WTETfPAiO2OYYhKJ4SORVii/ cnyXDwLHR2X8gx2KccxG9IsjhzQQkzkAt3M+BgAPPrNi4S9jPcVhCACQVNEyLafg6JGY IX6SKhcIaHVeS8g6PfOWxtev4/4/J3ZFoxo9fG9qfjIICMoRZHkA6SXhwN6bVVqXS116 42oQ== 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=nzKeKFAPBZ6rzV0NFigpy2eDVIi9FKR8HBRsYCkfB/U=; b=wmPKBxYnswNgtB/7h97uVn7PykjDMbp9/iXMk/tgf4kN9ac0Aj6+M4+Vf6RFSwynU+ BqIO3gbAAXRtz+qUbMkery/m+oJ2B4n3ISwo72NJ9yIincyCnKEqk6377FVQJKWjiZ/A fs8PDGdvcp0WlIHvhC74uecTiQzrwinDM5JpTlfyg/imRfoYa/XiAtMDmB6N4vJZI+c/ qF1/A+mjkQdmailJQt0YAl32iiPDeDGrTURe4lXKDi+OGY70OQkCoP2InztVSQQyNFxW AKQuhiAofMRtRnxK82DiuZAJDYyW0Ye7DhGMdX6TUDQbInsDG4z7WDAfSCYOdHog03Y6 Em3g== X-Gm-Message-State: AOAM531ThBR3CG6S+QR+p5bF9NaoPHaawB17hD8uzLP/ND+K/7RvbPTS DDkc/f2KGvbv3ue+da1ntFcDPXaKXgDL X-Google-Smtp-Source: ABdhPJzuD97DHHQINTddZQ7U07a5i/EHI+5mizcIFnBjhQnvGYZsTgq57fB9oUk9fU7E8+4CAaVUZrl3Zrbf X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:cad1:: with SMTP id a200mr22061820ybg.183.1640848954194; Wed, 29 Dec 2021 23:22:34 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:28 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-48-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232236_068347_201D4224 X-CRM114-Status: GOOD ( 12.49 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 ce9c3c5d881d..935a6edcdcdc 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2131,7 +2131,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; - counts = perf_counts(counter->counts, cpu, thread); + counts = perf_counts(counter->counts, idx, thread); printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %15" PRIu64 " %s\n", cpu, From patchwork Thu Dec 30 07:20:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701309 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9EF81C433EF for ; Thu, 30 Dec 2021 08:00:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=idkmQImD8oQKOSfTLbWJZiwYlShg1NgdI5Y8nl20jE8=; b=gPGfaTg1FLQrguQ2F6sIgwwTCu N5a7nWD1mwCuOqWGM/Jr1AKMwaBTfFuVxUyOsJy+s0/3bu7WRuTAczZXibTvIFTdeUZUPDAXZ9qsk VT07Dhb4mgG6vizLnp1k2PslGb3fzQEnIz14rnxITVxVyIrzyWCJddU0qor6b9RSPpbvkUCEP73EU V8LZnIFGpFyz04b8s479hvD7X2SlQKDGZ+A+dfMxh+udfr4gxOpQ45P9o5bAb3R9+CSbMZ9DPpLig Enshu5zbLMVrXpXZ7HoYtfHBnSq8pNUyWLdWdBdg6A5Cl1Z2mGI/I0AqX+VL4yC6YrYxJn73Z737n s9qD200Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qKp-003x04-8T; Thu, 30 Dec 2021 07:58:52 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plm-003kRi-In for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:41 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id j18-20020a258152000000b006000d292a42so42360120ybm.0 for ; Wed, 29 Dec 2021 23:22: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=on9cMkVsbDIIWgmJUXNGZPB7xxaMgvNoxu0hM4zjpQ4=; b=sQovDeSS1jmqBxyi8qxJA+KJCHl0AO0LQutJiPf1kHryt/x0gH4bjxri2JsVCBPicu nRLqgEPUcnDXxQihf5alINa23pgAV3UpQPVPSM9DyzZv7Ul6K1ERcTDvkyY4FGzIfssJ LeSLcbVvmAM9/jD4nJeYrtx3SMM2OgZs3GZD7ZabjfJ6EZin/unbSFqWcTNca5Q532wq svLlxXJlSCgicDaH4twPedwjgrimmZo6ocAzh0yED6ASiT74eqBTRjgRwuWnBlonGnLG jPXmsMiRgsUVaqjuC73QMBbcCgyRBQ7H540aQX16AaHAqwH+SXvLBbqOdKNnu/mMoOPJ 0t2w== 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=on9cMkVsbDIIWgmJUXNGZPB7xxaMgvNoxu0hM4zjpQ4=; b=oTbo7YxsthBsxt1q6bwZmXKAJsfjN7F5sTpfAtW2AS8WcZ+i/gtUk1P05mHzTjJXEf CBkD7JrY34AXcejbKcyhOUVRbGmiWqY9G6Qi7TpqlYe/ujmlIHU19qY+gt9ydE+ter11 56Rkhq2r7iyckTB3+WqNFF91kQgH3kIdcoLBC45mBya36fkDwmsofMg3Cpx1a9w/QyUz QWO6Ym8baGJtfyEz4t2wNtOorVDTEDTiBirTgPOLuSzO9q0RpPxWSXMKqDMD90aKvbEX /wTgryPKlQa2IJDqN+vXQL6TgAJlwgAvNdhAbk/nNnUhr7Uk0cWIkG69JFJjjJCcnTF9 6NoA== X-Gm-Message-State: AOAM530xRqd+zf70dTX8j1hC4Zp5MTXVFPRVWsywOucn98tiXkgUIhKA BgqoDHOCv/wqFm+l6LnuwDf1NpCmD2pI X-Google-Smtp-Source: ABdhPJzqq/QW5bQnoe90buoTODwyR2SzuN0kDoT9thVbRJhpcfDXrVUv+7YeJTwa7LJD/r1+V+Jdxh6BSnki X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:3716:: with SMTP id e22mr22191982yba.57.1640848956645; Wed, 29 Dec 2021 23:22:36 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:29 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-49-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232238_695165_DA7A2FAD X-CRM114-Status: GOOD ( 13.80 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 0f192360b6c6..ba95379efcfb 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_config *config, fprintf(os->fh, "%*s ", config->metric_only_len, unit); } -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 = evsel__cpus(evsel); int cpu, idx; if (config->aggr_mode == AGGR_NONE) - return id->cpu; + return perf_cpu_map__idx(cpus, id->cpu); if (!config->aggr_get_id) return 0; - cpus = evsel__cpus(evsel); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { struct aggr_cpu_id cpu_id = config->aggr_get_id(config, cpu); 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, struct aggr_cpu_id id, int } 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 += 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); } } From patchwork Thu Dec 30 07:20:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 12701310 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5B4F2C433F5 for ; Thu, 30 Dec 2021 08:02:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=1eFc183oXLXqoO5PJY2kP/r7OPsvmY4C89g1kglDC+g=; b=MGty3PIZDGKGIPBLMjOAJhmf3z iHZ/LEOkAcbHNKku+U41KRZ3qUuWY08v+FAruK9AIcvhCLV9L3/o+2lSeHH1C1HhB3kYZ/oxX3tt7 HCdJ880ltdniF536HF241oYVegApMVXDPRc8HmsDH4NkQnO1yytzy6RMXmpaOVTgoBlDnZGpxhRUU s/FwvClfLUoq8X+Htd6t6cqO4/0YBfgIZIM3FLRyuJnx5h2X4f67RpvzaBSrE/tjGF1eXu9Lcadw9 IQ6DUMv74wb7Z2nbgA37AIY9zbNlz3u8Q7cqWyGbLDBylVh1nudYdg0HkJNeMAoifj30th+uzUiNa fQovrjVg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2qLk-003xJA-Ve; Thu, 30 Dec 2021 07:59:49 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1n2plp-003kSs-Ev for linux-arm-kernel@lists.infradead.org; Thu, 30 Dec 2021 07:22:48 +0000 Received: by mail-yb1-xb49.google.com with SMTP id a9-20020a251a09000000b0060b2c94d515so27977005yba.20 for ; Wed, 29 Dec 2021 23:22: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=PAkAfOINjTuCGiHWDTIf+0Yjva/4FXzSxJX0RgUS+Fo=; b=jPY1leECVUsitlNycDXWvx9/KgNSWtmOTLBaoan2PNngnC8JcJ7oPkGrlOqrMSaMmB HyK/xzzteb6f3ltqkuEbiKu2qamT48sI0mrukDuxd6eMVMpizko8CeEKDInGrKyVilDX YmcNZSDwA0LnnYn9bUfmKy5rfNAYzXL9vS+NbsfSzggYgaXStN7zIUbKMyYPLkUcrU21 ks6PEw+xjNJrGDDNxiFChbI2iaQgV5LGARat0xKPzvFgxkG5ha1w435GVsqjnREcnU0o E4buwC3cGZ5Tfnj0ASzVqimYQ5e+X8YhvUVUjxSjSg5qG+l+zyPysV30OWaBqNNGWtmf 7biA== 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=PAkAfOINjTuCGiHWDTIf+0Yjva/4FXzSxJX0RgUS+Fo=; b=ZqP5cGTnapdI93+5EFEOnn5M5TVmQUCiH3HDFUnXh1cYOmKQORNzRBSZpCn90dz/mz kyaknGPyUYuL0ncoAeRNVdRgpP7vAGl5aEXB6VKhzraN3caQUGmzZOAQCI/8k0HvnEBP t8zWThhA9GI/SX3eTn9fJnESY+osq0713UxTWRcNzSZb8+FXzec4GWiNUsydPPu70bca oGy7GHZ2Wz7SNtBSv2rYNIsRE/a90uScNEyVhQ4Sr+zEh8ckUNAflpXmZIHtU+qV0JJf VEGvhWqUFU0YPaqBF1TCQSYsIViL2W+VK2P7pVzKSCVg0ittvWy2WvUiDvP3iu3GyCCW 4YYA== X-Gm-Message-State: AOAM530gyyKFyBKR9lvCow6VArR6CDsYu7tlaFAUyQxu0R9uF5GaCwGw dxL+Q4Ge8rdZv5N6Nuwj7ZyPS0mISwSw X-Google-Smtp-Source: ABdhPJys0zJphmBgXgRO/KaietI6HLh4+foPlOriFoZs6aJh1km8IUrfeBa4OmsWF4GXL0ToLrRaXyP5WYxA X-Received: from irogers.svl.corp.google.com ([2620:15c:2cd:202:31c4:9539:dba1:a82b]) (user=irogers job=sendgmr) by 2002:a25:d749:: with SMTP id o70mr30307121ybg.415.1640848959353; Wed, 29 Dec 2021 23:22:39 -0800 (PST) Date: Wed, 29 Dec 2021 23:20:30 -0800 In-Reply-To: <20211230072030.302559-1-irogers@google.com> Message-Id: <20211230072030.302559-50-irogers@google.com> Mime-Version: 1.0 References: <20211230072030.302559-1-irogers@google.com> X-Mailer: git-send-email 2.34.1.448.ga2b2bfdf31-goog Subject: [PATCH v3 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, zhengjun.xing@intel.com Cc: eranian@google.com, Ian Rogers X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211229_232241_820216_E5236C9D X-CRM114-Status: GOOD ( 27.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 +static struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) +{ + struct perf_cpu_map *cpus; + + cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); + if (!cpus) + return NULL; + + cpus->nr = 1; + refcount_set(&cpus->refcnt, 1); + return cpus; +} + struct perf_cpu_map *perf_cpu_map__dummy_new(void) { - struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int)); + struct perf_cpu_map *cpus = perf_cpu_map__alloc(1); - if (cpus != NULL) { - cpus->nr = 1; - cpus->map[0] = -1; - refcount_set(&cpus->refcnt, 1); - } + if (!cpus) + return NULL; + cpus->map[0].cpu = -1; return cpus; } @@ -54,16 +65,12 @@ static struct perf_cpu_map *cpu_map__default_new(void) if (nr_cpus < 0) return NULL; - cpus = malloc(sizeof(*cpus) + nr_cpus * sizeof(int)); - if (cpus != NULL) { - int i; - - for (i = 0; i < nr_cpus; ++i) - cpus->map[i] = i; + cpus = perf_cpu_map__alloc(nr_cpus); + if (!cpus) + return NULL; - cpus->nr = nr_cpus; - refcount_set(&cpus->refcnt, 1); - } + for (int i = 0; i < nr_cpus; ++i) + cpus->map[i].cpu = i; return cpus; } @@ -73,31 +80,32 @@ struct perf_cpu_map *perf_cpu_map__default_new(void) return cpu_map__default_new(); } -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 = a, *cpu_b = b; + + return cpu_a->cpu - cpu_b->cpu; } -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 perf_cpu *tmp_cpus) { - size_t payload_size = nr_cpus * sizeof(int); - struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + payload_size); + size_t payload_size = nr_cpus * sizeof(struct perf_cpu); + struct perf_cpu_map *cpus = perf_cpu_map__alloc(nr_cpus); int i, j; if (cpus != 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 = 0; for (i = 0; i < nr_cpus; i++) { - if (i == 0 || cpus->map[i] != cpus->map[i - 1]) - cpus->map[j++] = cpus->map[i]; + if (i == 0 || cpus->map[i].cpu != cpus->map[i - 1].cpu) + cpus->map[j++].cpu = cpus->map[i].cpu; } cpus->nr = j; assert(j <= nr_cpus); - refcount_set(&cpus->refcnt, 1); } - return cpus; } @@ -105,7 +113,7 @@ struct perf_cpu_map *perf_cpu_map__read(FILE *file) { struct perf_cpu_map *cpus = NULL; int nr_cpus = 0; - int *tmp_cpus = NULL, *tmp; + struct perf_cpu *tmp_cpus = NULL, *tmp; int max_entries = 0; int n, cpu, prev; char sep; @@ -124,24 +132,24 @@ struct perf_cpu_map *perf_cpu_map__read(FILE *file) if (new_max >= max_entries) { max_entries = new_max + MAX_NR_CPUS / 2; - tmp = realloc(tmp_cpus, max_entries * sizeof(int)); + tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); if (tmp == NULL) goto out_free_tmp; tmp_cpus = tmp; } while (++prev < cpu) - tmp_cpus[nr_cpus++] = prev; + tmp_cpus[nr_cpus++].cpu = prev; } if (nr_cpus == max_entries) { max_entries += MAX_NR_CPUS; - tmp = realloc(tmp_cpus, max_entries * sizeof(int)); + tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); if (tmp == NULL) goto out_free_tmp; tmp_cpus = tmp; } - tmp_cpus[nr_cpus++] = cpu; + tmp_cpus[nr_cpus++].cpu = cpu; if (n == 2 && sep == '-') prev = cpu; else @@ -179,7 +187,7 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) unsigned long start_cpu, end_cpu = 0; char *p = NULL; int i, nr_cpus = 0; - int *tmp_cpus = NULL, *tmp; + struct perf_cpu *tmp_cpus = NULL, *tmp; int max_entries = 0; if (!cpu_list) @@ -220,17 +228,17 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) for (; start_cpu <= end_cpu; start_cpu++) { /* check for duplicates */ for (i = 0; i < nr_cpus; i++) - if (tmp_cpus[i] == (int)start_cpu) + if (tmp_cpus[i].cpu == (int)start_cpu) goto invalid; if (nr_cpus == max_entries) { max_entries += MAX_NR_CPUS; - tmp = realloc(tmp_cpus, max_entries * sizeof(int)); + tmp = realloc(tmp_cpus, max_entries * sizeof(struct perf_cpu)); if (tmp == NULL) goto invalid; tmp_cpus = tmp; } - tmp_cpus[nr_cpus++] = (int)start_cpu; + tmp_cpus[nr_cpus++].cpu = (int)start_cpu; } if (*p) ++p; @@ -250,12 +258,16 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list) return cpus; } -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 = { + .cpu = -1 + }; + if (cpus && idx < cpus->nr) - return cpus->map[idx]; + result = cpus->map[idx]; - return -1; + return result; } 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) bool perf_cpu_map__empty(const struct perf_cpu_map *map) { - return map ? map->map[0] == -1 : true; + return map ? map->map[0].cpu == -1 : true; } -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; @@ -278,13 +290,13 @@ int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu) low = 0; high = cpus->nr; while (low < high) { - int idx = (low + high) / 2, - cpu_at_idx = cpus->map[idx]; + int idx = (low + high) / 2; + struct perf_cpu cpu_at_idx = cpus->map[idx]; - if (cpu_at_idx == cpu) + if (cpu_at_idx.cpu == cpu.cpu) return idx; - if (cpu_at_idx > cpu) + if (cpu_at_idx.cpu > cpu.cpu) high = idx; else low = idx + 1; @@ -293,15 +305,22 @@ int perf_cpu_map__idx(const struct perf_cpu_map *cpus, int cpu) return -1; } -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 cpu) { return perf_cpu_map__idx(cpus, cpu) != -1; } -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 = { + .cpu = -1 + }; + // cpu_map__trim_new() qsort()s it, cpu_map__default_new() sorts it as well. - return map->nr > 0 ? map->map[map->nr - 1] : -1; + if (map->nr > 0) + result = map->map[map->nr - 1]; + + return result; } /* @@ -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 == other->nr && - !memcmp(orig->map, other->map, orig->nr * sizeof(int))) + !memcmp(orig->map, other->map, orig->nr * sizeof(struct perf_cpu))) return orig; tmp_len = orig->nr + other->nr; - tmp_cpus = malloc(tmp_len * sizeof(int)); + tmp_cpus = malloc(tmp_len * sizeof(struct perf_cpu)); if (!tmp_cpus) return NULL; /* Standard merge algorithm from wikipedia */ i = j = k = 0; while (i < orig->nr && j < other->nr) { - if (orig->map[i] <= other->map[j]) { - if (orig->map[i] == other->map[j]) + if (orig->map[i].cpu <= other->map[j].cpu) { + if (orig->map[i].cpu == other->map[j].cpu) j++; tmp_cpus[k++] = 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, bool overwrite, int idx) 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) { 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 = perf_cpu_map__cpu(evlist->cpus, cpu_idx); + struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->cpus, cpu_idx); struct perf_evsel *evsel; int revent; 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 *evsel, int ncpus, int nthre 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); } static int get_group_fd(struct perf_evsel *evsel, int cpu_map_idx, int thread, int *group_fd) @@ -113,7 +113,8 @@ static int get_group_fd(struct perf_evsel *evsel, int cpu_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 = 0; + struct perf_cpu cpu; + int idx, thread, err = 0; if (cpus == NULL) { static struct perf_cpu_map *empty_cpu_map; @@ -252,7 +253,7 @@ int perf_evsel__mmap(struct perf_evsel *evsel, int pages) for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) { int *fd = FD(evsel, idx, thread); struct perf_mmap *map; - int cpu = perf_cpu_map__cpu(evsel->cpus, idx); + struct perf_cpu cpu = perf_cpu_map__cpu(evsel->cpus, idx); if (fd == NULL || *fd < 0) continue; diff --git a/tools/lib/perf/include/internal/cpumap.h b/tools/lib/perf/include/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 @@ #include +/** 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[]; }; #ifndef MAX_NR_CPUS #define MAX_NR_CPUS 2048 #endif -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); #endif /* __LIBPERF_INTERNAL_CPUMAP_H */ diff --git a/tools/lib/perf/include/internal/evlist.h b/tools/lib/perf/include/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 @@ #include #include +#include #include #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); 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/include/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 -struct perf_cpu_map; struct perf_thread_map; struct xyarray; @@ -27,7 +27,7 @@ struct perf_sample_id { * queue number. */ int idx; - int cpu; + struct perf_cpu cpu; pid_t tid; /* Holds total ID period value for PERF_SAMPLE_READ processing. */ diff --git a/tools/lib/perf/include/internal/mmap.h b/tools/lib/perf/include/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 /* 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 #include +#include #include #include -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(struct 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 *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); +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); #define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \ for ((idx) = 0, (cpu) = 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) } 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 = 0; map->mask = 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 perf_cpu_map *cpu) 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); ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset); 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 perf_cpu_map *cpu) 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); ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset); 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; 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); ret = pthread_attr_setaffinity_np(&thread_attr, sizeof(cpu_set_t), &cpuset); 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_attr_t thread_attr, worker[i].futex = &global_futex; 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); 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-requeue.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 = 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); 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/futex-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 = 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); 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 = 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); 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; if (c2c.node_info > 2) @@ -2038,8 +2039,8 @@ static int setup_nodes(struct perf_session *session) if (!cpu2node) return -ENOMEM; - for (cpu = 0; cpu < c2c.cpus_cnt; cpu++) - cpu2node[cpu] = -1; + for (idx = 0; idx < c2c.cpus_cnt; idx++) + cpu2node[idx] = -1; c2c.cpu2node = cpu2node; @@ -2058,12 +2059,12 @@ static int setup_nodes(struct perf_session *session) continue; perf_cpu_map__for_each_cpu(cpu, idx, map) { - set_bit(cpu, set); + set_bit(cpu.cpu, set); - if (WARN_ONCE(cpu2node[cpu] != -1, "node/cpu topology bug")) + if (WARN_ONCE(cpu2node[cpu.cpu] != -1, "node/cpu topology bug")) return -EINVAL; - cpu2node[cpu] = node; + cpu2node[cpu.cpu] = node; } } diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index f16c39a37a52..71452599f87d 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -281,7 +281,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap) int ret; int last_cpu; - last_cpu = perf_cpu_map__cpu(cpumap, cpumap->nr - 1); + last_cpu = perf_cpu_map__cpu(cpumap, cpumap->nr - 1).cpu; mask_size = last_cpu / 4 + 2; /* one more byte for EOS */ mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */ 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 = evsel__process_alloc_event(evsel, sample); if (!ret) { - int node1 = cpu__get_node(sample->cpu), + int node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu}), node2 = evsel__intval(evsel, sample, "node"); if (node1 != node2) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 6ac2160913ea..0a63295d30f0 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -2796,7 +2796,7 @@ int cmd_record(int argc, const char **argv) symbol__init(NULL); if (rec->opts.affinity != PERF_AFFINITY_SYS) { - rec->affinity_mask.nbits = cpu__max_cpu(); + rec->affinity_mask.nbits = cpu__max_cpu().cpu; rec->affinity_mask.bits = bitmap_zalloc(rec->affinity_mask.nbits); if (!rec->affinity_mask.bits) { pr_err("Failed to allocate thread mask for %zd cpus\n", rec->affinity_mask.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 { 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 *sched, struct evsel *evsel, int new_shortname; u64 timestamp0, timestamp = sample->time; s64 delta; - int i, this_cpu = sample->cpu; + int i; + struct perf_cpu this_cpu = { + .cpu = sample->cpu, + }; int cpus_nr; bool new_cpu = false; const char *color = PERF_COLOR_NORMAL; char stimestamp[32]; - BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0); + BUG_ON(this_cpu.cpu >= MAX_CPUS || this_cpu.cpu < 0); - if (this_cpu > sched->max_cpu) + if (this_cpu.cpu > sched->max_cpu.cpu) sched->max_cpu = this_cpu; if (sched->map.comp) { cpus_nr = 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++] = this_cpu; new_cpu = true; } } else - cpus_nr = sched->max_cpu; + cpus_nr = sched->max_cpu.cpu; - timestamp0 = sched->cpu_last_switched[this_cpu]; - sched->cpu_last_switched[this_cpu] = timestamp; + timestamp0 = sched->cpu_last_switched[this_cpu.cpu]; + sched->cpu_last_switched[this_cpu.cpu] = timestamp; if (timestamp0) delta = timestamp - timestamp0; else @@ -1577,7 +1580,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, return -1; } - sched->curr_thread[this_cpu] = thread__get(sched_in); + sched->curr_thread[this_cpu.cpu] = thread__get(sched_in); printf(" "); @@ -1608,8 +1611,10 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, } for (i = 0; i < cpus_nr; i++) { - int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i; - struct thread *curr_thread = sched->curr_thread[cpu]; + struct perf_cpu cpu = { + .cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i, + }; + struct thread *curr_thread = sched->curr_thread[cpu.cpu]; struct thread_runtime *curr_tr; const char *pid_color = color; const char *cpu_color = color; @@ -1623,13 +1628,13 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, if (sched->map.color_cpus && perf_cpu_map__has(sched->map.color_cpus, cpu)) cpu_color = COLOR_CPUS; - if (cpu != this_cpu) + if (cpu.cpu != this_cpu.cpu) color_fprintf(stdout, color, " "); else color_fprintf(stdout, cpu_color, "*"); - if (sched->curr_thread[cpu]) { - curr_tr = thread__get_runtime(sched->curr_thread[cpu]); + if (sched->curr_thread[cpu.cpu]) { + curr_tr = thread__get_runtime(sched->curr_thread[cpu.cpu]); if (curr_tr == NULL) { thread__put(sched_in); return -1; @@ -1929,7 +1934,7 @@ static char *timehist_get_commstr(struct thread *thread) static void timehist_header(struct perf_sched *sched) { - u32 ncpus = sched->max_cpu + 1; + u32 ncpus = sched->max_cpu.cpu + 1; u32 i, j; printf("%15s %6s ", "time", "cpu"); @@ -2008,7 +2013,7 @@ static void timehist_print_sample(struct perf_sched *sched, struct thread_runtime *tr = thread__priv(thread); const char *next_comm = evsel__strval(evsel, sample, "next_comm"); const u32 next_pid = evsel__intval(evsel, sample, "next_pid"); - u32 max_cpus = sched->max_cpu + 1; + u32 max_cpus = 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_sched *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, ""); printf(" %-*s ", comm_width, timehist_get_commstr(thread)); @@ -2449,13 +2454,13 @@ static void timehist_print_migration_event(struct perf_sched *sched, { struct thread *thread; char tstr[64]; - u32 max_cpus = sched->max_cpu + 1; + u32 max_cpus; u32 ocpu, dcpu; if (sched->summary_only) return; - max_cpus = sched->max_cpu + 1; + max_cpus = sched->max_cpu.cpu + 1; ocpu = evsel__intval(evsel, sample, "orig_cpu"); dcpu = evsel__intval(evsel, sample, "dest_cpu"); @@ -2918,7 +2923,7 @@ static void timehist_print_summary(struct perf_sched *sched, 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); } 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 = container_of(tool, struct perf_sched, tool); int err = 0; - int this_cpu = sample->cpu; + struct perf_cpu this_cpu = { + .cpu = sample->cpu, + }; - if (this_cpu > sched->max_cpu) + if (this_cpu.cpu > sched->max_cpu.cpu) sched->max_cpu = this_cpu; if (evsel->handler != NULL) { @@ -3054,10 +3061,10 @@ static int perf_sched__timehist(struct perf_sched *sched) goto out; /* pre-allocate struct for per-CPU idle stats */ - sched->max_cpu = session->header.env.nr_cpus_online; - if (sched->max_cpu == 0) - sched->max_cpu = 4; - if (init_idle_threads(sched->max_cpu)) + sched->max_cpu.cpu = session->header.env.nr_cpus_online; + if (sched->max_cpu.cpu == 0) + sched->max_cpu.cpu = 4; + if (init_idle_threads(sched->max_cpu.cpu)) goto out; /* summary_only implies summary option, but don't overwrite summary if set */ @@ -3209,10 +3216,10 @@ static int setup_map_cpus(struct perf_sched *sched) { struct perf_cpu_map *map; - sched->max_cpu = sysconf(_SC_NPROCESSORS_CONF); + sched->max_cpu.cpu = sysconf(_SC_NPROCESSORS_CONF); if (sched->map.comp) { - sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int)); + sched->map.comp_cpus = 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 935a6edcdcdc..55f243d4a90b 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2115,7 +2115,8 @@ static struct scripting_ops *scripting_ops; static void __process_stat(struct evsel *counter, u64 tstamp) { int nthreads = perf_thread_map__nr(counter->core.threads); - int idx, cpu, thread; + int idx, thread; + struct perf_cpu cpu; static int header_printed; if (counter->core.system_wide) @@ -2134,7 +2135,7 @@ static void __process_stat(struct evsel *counter, u64 tstamp) counts = perf_counts(counter->counts, idx, thread); 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 evsel *b) return false; for (int i = 0; i < a->core.cpus->nr; i++) { - if (a->core.cpus->map[i] != b->core.cpus->map[i]) + if (a->core.cpus->map[i].cpu != b->core.cpus->map[i].cpu) return false; } @@ -331,7 +331,7 @@ static int evsel__write_stat_event(struct evsel *counter, int cpu_map_idx, u32 t struct perf_counts_values *count) { struct perf_sample_id *sid = SID(counter, cpu_map_idx, thread); - int cpu = perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx); + struct perf_cpu cpu = perf_cpu_map__cpu(evsel__cpus(counter), cpu_map_idx); 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, struct 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[] = { }; static struct aggr_cpu_id perf_stat__get_socket(struct perf_stat_config *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__socket(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_die(struct perf_stat_config *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__die(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_core(struct perf_stat_config *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__core(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_node(struct perf_stat_config *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return aggr_cpu_id__node(cpu, /*data=*/NULL); } static struct aggr_cpu_id perf_stat__get_aggr(struct perf_stat_config *config, - aggr_get_id_t get_id, int cpu) + aggr_get_id_t get_id, struct perf_cpu cpu) { struct aggr_cpu_id id = aggr_cpu_id__empty(); - if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu])) - config->cpus_aggr_map->map[cpu] = get_id(config, cpu); + if (aggr_cpu_id__is_empty(&config->cpus_aggr_map->map[cpu.cpu])) + config->cpus_aggr_map->map[cpu.cpu] = get_id(config, cpu); - id = config->cpus_aggr_map->map[cpu]; + id = config->cpus_aggr_map->map[cpu.cpu]; return id; } static struct aggr_cpu_id perf_stat__get_socket_cached(struct perf_stat_config *config, - int cpu) + struct perf_cpu cpu) { return perf_stat__get_aggr(config, perf_stat__get_socket, cpu); } static struct aggr_cpu_id perf_stat__get_die_cached(struct perf_stat_config *config, - int cpu) + struct perf_cpu cpu) { return perf_stat__get_aggr(config, perf_stat__get_die, cpu); } static struct aggr_cpu_id perf_stat__get_core_cached(struct perf_stat_config *config, - int cpu) + struct perf_cpu cpu) { return perf_stat__get_aggr(config, perf_stat__get_core, cpu); } static struct aggr_cpu_id perf_stat__get_node_cached(struct perf_stat_config *config, - 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 = perf_cpu_map__max(evsel_list->core.cpus); + nr = perf_cpu_map__max(evsel_list->core.cpus).cpu; stat_config.cpus_aggr_map = 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 = NULL; } -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_cpu_map *map, int idx) { struct perf_env *env = data; - int cpu; + struct perf_cpu cpu = perf_cpu_map__cpu(map, idx); - if (idx > map->nr) - return -1; - - cpu = map->map[idx]; - - if (cpu >= env->nr_cpus_avail) - return -1; + if (cpu.cpu >= env->nr_cpus_avail) + cpu.cpu = -1; return cpu; } -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 = data; struct aggr_cpu_id id = aggr_cpu_id__empty(); - if (cpu != -1) - id.socket = env->cpu[cpu].socket_id; + if (cpu.cpu != -1) + id.socket = env->cpu[cpu.cpu].socket_id; return id; } -static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(int cpu, void *data) +static struct aggr_cpu_id perf_env__get_die_aggr_by_cpu(struct perf_cpu cpu, void *data) { struct perf_env *env = data; struct aggr_cpu_id id = aggr_cpu_id__empty(); - if (cpu != -1) { + if (cpu.cpu != -1) { /* * die_id is relative to socket, so start * with the socket ID and then add die to * make a unique ID. */ - id.socket = env->cpu[cpu].socket_id; - id.die = env->cpu[cpu].die_id; + id.socket = env->cpu[cpu.cpu].socket_id; + id.die = env->cpu[cpu.cpu].die_id; } return id; } -static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(int cpu, void *data) +static struct aggr_cpu_id perf_env__get_core_aggr_by_cpu(struct perf_cpu cpu, void *data) { struct perf_env *env = data; struct aggr_cpu_id id = aggr_cpu_id__empty(); - if (cpu != -1) { + if (cpu.cpu != -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 = env->cpu[cpu].socket_id; - id.die = env->cpu[cpu].die_id; - id.core = env->cpu[cpu].core_id; + id.socket = env->cpu[cpu.cpu].socket_id; + id.die = env->cpu[cpu.cpu].die_id; + id.core = env->cpu[cpu.cpu].core_id; } return id; } -static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) +static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(struct perf_cpu cpu, void *data) { struct aggr_cpu_id id = aggr_cpu_id__empty(); @@ -1568,24 +1564,24 @@ static struct aggr_cpu_id perf_env__get_node_aggr_by_cpu(int cpu, void *data) } static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return perf_env__get_socket_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_die_file(struct perf_stat_config *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return perf_env__get_die_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_core_file(struct perf_stat_config *config __maybe_unused, - int cpu) + struct perf_cpu cpu) { return perf_env__get_core_aggr_by_cpu(cpu, &perf_stat.session->header.env); } static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *config __maybe_unused, - 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 { \ #define WRITE_ASS(field, fmt) __WRITE_ASS(field, fmt, attr->field) -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 perf_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); @@ -144,7 +144,7 @@ static int store_event(struct perf_event_attr *attr, pid_t pid, int cpu, return 0; } -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 = 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 nbits) if (map && bm) { for (i = 0; i < map->nr; i++) - set_bit(map->map[i], bm); + set_bit(map->map[i].cpu, bm); } 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 __maybe_unused, TEST_ASSERT_VAL("wrong nr", map->nr == 20); for (i = 0; i < 20; i++) { - TEST_ASSERT_VAL("wrong cpu", map->map[i] == i); + TEST_ASSERT_VAL("wrong cpu", map->map[i].cpu == i); } perf_cpu_map__put(map); @@ -67,8 +67,8 @@ static int process_event_cpus(struct perf_tool *tool __maybe_unused, map = cpu_map__new_data(data); TEST_ASSERT_VAL("wrong nr", map->nr == 2); - TEST_ASSERT_VAL("wrong cpu", map->map[0] == 1); - TEST_ASSERT_VAL("wrong cpu", map->map[1] == 256); + TEST_ASSERT_VAL("wrong cpu", map->map[0].cpu == 1); + TEST_ASSERT_VAL("wrong cpu", map->map[1].cpu == 256); TEST_ASSERT_VAL("wrong refcnt", refcount_read(&map->refcnt) == 1); perf_cpu_map__put(map); return 0; diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.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 __maybe_unused, TEST_ASSERT_VAL("wrong id", ev->id == 123); TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS); TEST_ASSERT_VAL("wrong cpus", map->nr == 3); - TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1); - TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2); - TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3); + TEST_ASSERT_VAL("wrong cpus", map->map[0].cpu == 1); + TEST_ASSERT_VAL("wrong cpus", map->map[1].cpu == 2); + TEST_ASSERT_VAL("wrong cpus", map->map[2].cpu == 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 nbits) if (map && bm) { for (i = 0; i < map->nr; i++) { - set_bit(map->map[i], bm); + set_bit(map->map[i].cpu, bm); } } 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 __maybe_unused, int subtest } 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; } 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 = -1, fd, idx, cpu; + int err = -1, fd, idx; + struct perf_cpu cpu; struct perf_cpu_map *cpus; struct evsel *evsel; unsigned int nr_openat_calls = 111, i; @@ -66,15 +67,15 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test __mayb * without CPU_ALLOC. 1024 cpus in 2010 still seems * a reasonable upper limit tho :-) */ - if (cpu >= CPU_SETSIZE) { - pr_debug("Ignoring CPU %d\n", cpu); + if (cpu.cpu >= CPU_SETSIZE) { + pr_debug("Ignoring CPU %d\n", cpu.cpu); continue; } - 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 = openat(0, "/etc/passwd", O_RDONLY); close(fd); } - CPU_CLR(cpu, &cpu_set); + CPU_CLR(cpu.cpu, &cpu_set); } evsel->core.cpus = 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; - if (cpu >= CPU_SETSIZE) + if (cpu.cpu >= CPU_SETSIZE) continue; if (evsel__read_on_cpu(evsel, idx, 0) < 0) { @@ -104,7 +105,7 @@ static int test__openat_syscall_event_on_all_cpus(struct test_suite *test __mayb expected = nr_openat_calls + idx; if (perf_counts(evsel->counts, idx, 0)->val != 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 = -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 = 300; 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 = 1}, 2, 3, + &count, process_stat_event, NULL)); 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_cpu_map *map) TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu); for (i = 0; i < session->header.env.nr_cpus_avail; i++) { - if (!perf_cpu_map__has(map, i)) + struct perf_cpu cpu = { .cpu = 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 = 0; i < map->nr; i++) { id = aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL); - TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", map->map[i] == id.cpu); + TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", map->map[i].cpu == id.cpu.cpu); TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", - session->header.env.cpu[map->map[i]].core_id == id.core); + session->header.env.cpu[map->map[i].cpu].core_id == id.core); TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match", - session->header.env.cpu[map->map[i]].socket_id == id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id == id.socket); TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", - session->header.env.cpu[map->map[i]].die_id == id.die); + session->header.env.cpu[map->map[i].cpu].die_id == id.die); TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Cpu map - Thread is set", id.thread == -1); } @@ -139,13 +141,13 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) for (i = 0; i < map->nr; i++) { id = 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 == id.core); + session->header.env.cpu[map->map[i].cpu].core_id == id.core); TEST_ASSERT_VAL("Core map - Socket ID doesn't match", - session->header.env.cpu[map->map[i]].socket_id == id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id == id.socket); TEST_ASSERT_VAL("Core map - Die ID doesn't match", - session->header.env.cpu[map->map[i]].die_id == id.die); + session->header.env.cpu[map->map[i].cpu].die_id == id.die); TEST_ASSERT_VAL("Core map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Core map - Thread is set", id.thread == -1); } @@ -154,14 +156,14 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) for (i = 0; i < map->nr; i++) { id = 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 == id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id == id.socket); TEST_ASSERT_VAL("Die map - Die ID doesn't match", - session->header.env.cpu[map->map[i]].die_id == id.die); + session->header.env.cpu[map->map[i].cpu].die_id == id.die); TEST_ASSERT_VAL("Die map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Die map - Core is set", id.core == -1); - TEST_ASSERT_VAL("Die map - CPU is set", id.cpu == -1); + TEST_ASSERT_VAL("Die map - CPU is set", id.cpu.cpu == -1); TEST_ASSERT_VAL("Die map - Thread is set", id.thread == -1); } @@ -169,12 +171,12 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) for (i = 0; i < map->nr; i++) { id = 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 == id.socket); + session->header.env.cpu[map->map[i].cpu].socket_id == id.socket); TEST_ASSERT_VAL("Socket map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Socket map - Die ID is set", id.die == -1); TEST_ASSERT_VAL("Socket map - Core is set", id.core == -1); - TEST_ASSERT_VAL("Socket map - CPU is set", id.cpu == -1); + TEST_ASSERT_VAL("Socket map - CPU is set", id.cpu.cpu == -1); TEST_ASSERT_VAL("Socket map - Thread is set", id.thread == -1); } @@ -186,7 +188,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) TEST_ASSERT_VAL("Node map - Socket is set", id.socket == -1); TEST_ASSERT_VAL("Node map - Die ID is set", id.die == -1); TEST_ASSERT_VAL("Node map - Core is set", id.core == -1); - TEST_ASSERT_VAL("Node map - CPU is set", id.cpu == -1); + TEST_ASSERT_VAL("Node map - CPU is set", id.cpu.cpu == -1); TEST_ASSERT_VAL("Node map - Thread is set", id.thread == -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 @@ static int get_cpu_set_size(void) { - int sz = cpu__max_cpu() + 8 - 1; + int sz = 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 = 0; mm->idx = mp->idx; mm->tid = mp->tid; - mm->cpu = mp->cpu; + mm->cpu = mp->cpu.cpu; if (!mp->len) { mm->base = NULL; @@ -180,7 +180,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, else mp->tid = -1; } else { - mp->cpu = -1; + mp->cpu.cpu = -1; mp->tid = perf_thread_map__pid(evlist->core.threads, idx); } } @@ -292,7 +292,7 @@ static int auxtrace_queues__queue_buffer(struct auxtrace_queues *queues, if (!queue->set) { queue->set = true; queue->tid = buffer->tid; - queue->cpu = buffer->cpu; + queue->cpu = buffer->cpu.cpu; } buffer->buffer_nr = queues->next_buffer_nr++; @@ -339,11 +339,11 @@ static int auxtrace_queues__split_buffer(struct auxtrace_queues *queues, return 0; } -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 = session->itrace_synth_opts->cpu_bitmap; - return cpu_bitmap && cpu != -1 && !test_bit(cpu, cpu_bitmap); + return cpu_bitmap && cpu.cpu != -1 && !test_bit(cpu.cpu, cpu_bitmap); } 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 = { .pid = -1, .tid = event->auxtrace.tid, - .cpu = event->auxtrace.cpu, + .cpu = { event->auxtrace.cpu }, .data_offset = data_offset, .offset = event->auxtrace.offset, .reference = 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 @@ -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; }; /** diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 0abbee49f637..ca48ca0f87a4 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -13,8 +13,8 @@ #include #include -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] == (u16) -1) - map->map[i] = -1; + map->map[i].cpu = -1; else - map->map[i] = (int) cpus->cpu[i]; + map->map[i].cpu = (int) cpus->cpu[i]; } } @@ -58,7 +58,7 @@ static struct perf_cpu_map *cpu_map__from_mask(struct perf_record_record_cpu_map int cpu, i = 0; for_each_set_bit(cpu, mask->mask, nbits) - map->map[i++] = cpu; + map->map[i++].cpu = cpu; } return map; @@ -91,7 +91,7 @@ struct perf_cpu_map *perf_cpu_map__empty_new(int nr) cpus->nr = nr; for (i = 0; i < nr; i++) - cpus->map[i] = -1; + cpus->map[i].cpu = -1; 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); } -int cpu__get_socket_id(int cpu) +int cpu__get_socket_id(struct perf_cpu cpu) { - int value, ret = cpu__get_topology_int(cpu, "physical_package_id", &value); + int value, ret = cpu__get_topology_int(cpu.cpu, "physical_package_id", &value); return ret ?: value; } -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 __maybe_unused) { struct aggr_cpu_id id = aggr_cpu_id__empty(); @@ -161,7 +161,8 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_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 = cpu_aggr_map__empty_new(cpus->nr); if (!c) @@ -201,14 +202,14 @@ struct cpu_aggr_map *cpu_aggr_map__new(const struct perf_cpu_map *cpus, } -int cpu__get_die_id(int cpu) +int cpu__get_die_id(struct perf_cpu cpu) { - int value, ret = cpu__get_topology_int(cpu, "die_id", &value); + int value, ret = cpu__get_topology_int(cpu.cpu, "die_id", &value); return ret ?: value; } -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; @@ -231,13 +232,13 @@ struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data) return id; } -int cpu__get_core_id(int cpu) +int cpu__get_core_id(struct perf_cpu cpu) { - int value, ret = cpu__get_topology_int(cpu, "core_id", &value); + int value, ret = cpu__get_topology_int(cpu.cpu, "core_id", &value); return ret ?: value; } -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 = cpu__get_core_id(cpu); @@ -256,7 +257,7 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data) } -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; @@ -270,7 +271,7 @@ struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data) } -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 __maybe_unused) { struct aggr_cpu_id id = aggr_cpu_id__empty(); @@ -318,8 +319,8 @@ static void set_max_cpu_num(void) int ret = -1; /* set up default */ - max_cpu_num = 4096; - max_present_cpu_num = 4096; + max_cpu_num.cpu = 4096; + max_present_cpu_num.cpu = 4096; mnt = sysfs__mountpoint(); if (!mnt) @@ -332,7 +333,7 @@ static void set_max_cpu_num(void) goto out; } - ret = get_max_num(path, &max_cpu_num); + ret = get_max_num(path, &max_cpu_num.cpu); if (ret) goto out; @@ -343,11 +344,11 @@ static void set_max_cpu_num(void) goto out; } - ret = get_max_num(path, &max_present_cpu_num); + ret = get_max_num(path, &max_present_cpu_num.cpu); 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); } /* Determine highest possible node in the system for sparse allocation */ @@ -386,31 +387,31 @@ int cpu__max_node(void) return max_node_num; } -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(); return max_cpu_num; } -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(); return max_present_cpu_num; } -int cpu__get_node(int cpu) +int cpu__get_node(struct perf_cpu cpu) { if (unlikely(cpunode_map == NULL)) { pr_debug("cpu_map not initialized\n"); return -1; } - return cpunode_map[cpu]; + return cpunode_map[cpu.cpu]; } static int init_cpunode_map(void) @@ -420,13 +421,13 @@ static int init_cpunode_map(void) set_max_cpu_num(); set_max_node_num(); - cpunode_map = calloc(max_cpu_num, sizeof(int)); + cpunode_map = calloc(max_cpu_num.cpu, sizeof(int)); if (!cpunode_map) { pr_err("%s: calloc failed\n", __func__); return -1; } - for (i = 0; i < max_cpu_num; i++) + for (i = 0; i < max_cpu_num.cpu; i++) cpunode_map[i] = -1; return 0; @@ -487,35 +488,37 @@ int cpu__setup_cpunode_map(void) size_t cpu_map__snprint(struct perf_cpu_map *map, char *buf, size_t size) { - int i, cpu, start = -1; + int i, start = -1; bool first = true; size_t ret = 0; #define COMMA first ? "" : "," for (i = 0; i < map->nr + 1; i++) { + struct perf_cpu cpu = { .cpu = INT_MAX }; bool last = i == map->nr; - cpu = last ? INT_MAX : map->map[i]; + if (!last) + cpu = map->map[i]; if (start == -1) { start = i; if (last) { ret += snprintf(buf + ret, size - ret, "%s%d", COMMA, - map->map[i]); + map->map[i].cpu); } - } else if (((i - start) != (cpu - map->map[start])) || last) { + } else if (((i - start) != (cpu.cpu - map->map[start].cpu)) || last) { int end = i - 1; if (start == end) { ret += snprintf(buf + ret, size - ret, "%s%d", COMMA, - map->map[start]); + map->map[start].cpu); } else { ret += snprintf(buf + ret, size - ret, "%s%d-%d", COMMA, - map->map[start], map->map[end]); + map->map[start].cpu, map->map[end].cpu); } first = false; start = i; @@ -542,23 +545,23 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size) int i, cpu; char *ptr = buf; unsigned char *bitmap; - int last_cpu = perf_cpu_map__cpu(map, map->nr - 1); + struct perf_cpu last_cpu = perf_cpu_map__cpu(map, map->nr - 1); if (buf == NULL) return 0; - bitmap = zalloc(last_cpu / 8 + 1); + bitmap = zalloc(last_cpu.cpu / 8 + 1); if (bitmap == NULL) { buf[0] = '\0'; return 0; } for (i = 0; i < map->nr; i++) { - cpu = perf_cpu_map__cpu(map, i); + cpu = perf_cpu_map__cpu(map, i).cpu; bitmap[cpu / 8] |= 1 << (cpu % 8); } - for (cpu = last_cpu / 4 * 4; cpu >= 0; cpu -= 4) { + for (cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) { unsigned char bits = bitmap[cpu / 8]; if (cpu % 8) @@ -594,7 +597,7 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b a->socket == b->socket && a->die == b->die && a->core == b->core && - a->cpu == b->cpu; + a->cpu.cpu == b->cpu.cpu; } bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) @@ -604,7 +607,7 @@ bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) a->socket == -1 && a->die == -1 && a->core == -1 && - a->cpu == -1; + a->cpu.cpu == -1; } struct aggr_cpu_id aggr_cpu_id__empty(void) @@ -615,7 +618,7 @@ struct aggr_cpu_id aggr_cpu_id__empty(void) .socket = -1, .die = -1, .core = -1, - .cpu = -1 + .cpu = (struct perf_cpu){ .cpu = -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_id. */ int core; /** CPU aggregation, note there is one CPU for each SMT thread. */ - int cpu; + struct perf_cpu cpu; }; /** 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); /* thread unsafe */ int cpu__setup_cpunode_map(void); 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); /** * cpu_aggr_map__empty_new - Create a cpu_aggr_map of size nr with every entry @@ -77,7 +77,7 @@ int cpu__get_core_id(int cpu); */ 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); +typedef struct aggr_cpu_id (*aggr_cpu_id_get_t)(struct perf_cpu cpu, void *data); /** * 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 populated * with the die and socket for cpu. The function signature is compatible with * 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 socket * populated with the cpu, core, die and socket for cpu. The function signature * 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); #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 = has_die_topology(); - ncpus = cpu__max_present_cpu(); + ncpus = cpu__max_present_cpu().cpu; /* build online CPU map */ map = perf_cpu_map__new(NULL); @@ -218,7 +218,7 @@ struct cpu_topology *cpu_topology__new(void) tp->core_cpus_list = addr; for (i = 0; i < nr; i++) { - if (!perf_cpu_map__has(map, i)) + if (!perf_cpu_map__has(map, (struct perf_cpu){ .cpu = i })) continue; ret = build_cpu_topology(tp, i); @@ -333,7 +333,7 @@ struct numa_topology *numa_topology__new(void) tp->nr = nr; for (i = 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 = 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 argc, const char *argv[]) int perf_env__read_cpu_topology_map(struct perf_env *env) { - int cpu, nr_cpus; + int idx, nr_cpus; if (env->cpu != NULL) return 0; if (env->nr_cpus_avail == 0) - env->nr_cpus_avail = cpu__max_present_cpu(); + env->nr_cpus_avail = cpu__max_present_cpu().cpu; nr_cpus = env->nr_cpus_avail; if (nr_cpus == -1) @@ -301,10 +301,12 @@ int perf_env__read_cpu_topology_map(struct perf_env *env) if (env->cpu == NULL) return -ENOMEM; - for (cpu = 0; cpu < nr_cpus; ++cpu) { - env->cpu[cpu].core_id = cpu__get_core_id(cpu); - env->cpu[cpu].socket_id = cpu__get_socket_id(cpu); - env->cpu[cpu].die_id = cpu__get_die_id(cpu); + for (idx = 0; idx < nr_cpus; ++idx) { + struct perf_cpu cpu = { .cpu = idx }; + + env->cpu[idx].core_id = cpu__get_core_id(cpu); + env->cpu[idx].socket_id = cpu__get_socket_id(cpu); + env->cpu[idx].die_id = cpu__get_die_id(cpu); } env->nr_cpus_avail = 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 == 0) - env->nr_cpus_avail = cpu__max_present_cpu(); + env->nr_cpus_avail = cpu__max_present_cpu().cpu; 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; } -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) for (i = 0; i < env->nr_numa_nodes; i++) { nn = &env->numa_nodes[i]; - nr = max(nr, perf_cpu_map__max(nn->map)); + nr = max(nr, perf_cpu_map__max(nn->map).cpu); } nr++; @@ -514,13 +516,14 @@ int perf_env__numa_node(struct perf_env *env, int cpu) env->nr_numa_map = nr; for (i = 0; i < env->nr_numa_nodes; i++) { - int tmp, j; + struct perf_cpu tmp; + int j; nn = &env->numa_nodes[i]; - perf_cpu_map__for_each_cpu(j, tmp, nn->map) - env->numa_map[j] = i; + perf_cpu_map__for_each_cpu(tmp, j, nn->map) + env->numa_map[tmp.cpu] = i; } } - return cpu >= 0 && cpu < env->nr_numa_map ? env->numa_map[cpu] : -1; + return cpu.cpu >= 0 && cpu.cpu < env->nr_numa_map ? env->numa_map[cpu.cpu] : -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 @@ #include #include +#include "cpumap.h" #include "rwsem.h" 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); -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 evlist *evlist, struct affin .cpu_map_idx = 0, .evlist_cpu_map_idx = 0, .evlist_cpu_map_nr = perf_cpu_map__nr(evlist->core.all_cpus), - .cpu = -1, + .cpu = (struct perf_cpu){ .cpu = -1}, .affinity = affinity, }; if (itr.affinity) { itr.cpu = 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 = 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_iterator *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 = 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, bool overwrite, int idx) 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 = container_of(_map, struct mmap, core); struct mmap_params *mp = 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; cpu = 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, struct perf_cpu_map *cpus, test_attr__ready(); 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); - fd = sys_perf_event_open(&evsel->core.attr, pid, cpus->map[idx], + fd = sys_perf_event_open(&evsel->core.attr, pid, cpus->map[idx].cpu, group_fd, evsel->open_flags); FD(evsel, idx, thread) = 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; if (!strcmp("#num_cpus", literal)) - return cpu__max_present_cpu(); + return cpu__max_present_cpu().cpu; /* * 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; - nrc = cpu__max_present_cpu(); + nrc = cpu__max_present_cpu().cpu; nr = 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; - nr = cpu__max_cpu(); + nr = cpu__max_cpu().cpu; for (cpu = 0; cpu < nr; cpu++) { for (level = 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 = cpu__max_cpu() * MAX_CACHE_LVL; + u32 max_caches = cpu__max_cpu().cpu * MAX_CACHE_LVL; struct cpu_cache_level caches[max_caches]; u32 cnt = 0, i, version = 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) } } -static int perf_mmap__aio_bind(struct mmap *map, int idx, int cpu, int affinity) +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 idx) } 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) 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 = NULL; cpu_map = cpu_map__online(); @@ -248,16 +249,16 @@ static void build_node_mask(int node, struct mmap_cpu_mask *mask) return; nr_cpus = perf_cpu_map__nr(cpu_map); - for (c = 0; c < nr_cpus; c++) { - cpu = cpu_map->map[c]; /* map c index to online cpu index */ + for (idx = 0; idx < nr_cpus; idx++) { + cpu = cpu_map->map[idx]; /* map c index to online cpu index */ if (cpu__get_node(cpu) == node) - set_bit(cpu, mask->bits); + set_bit(cpu.cpu, mask->bits); } } static int perf_mmap__setup_affinity_mask(struct mmap *map, struct mmap_params *mp) { - map->affinity_mask.nbits = cpu__max_cpu(); + map->affinity_mask.nbits = cpu__max_cpu().cpu; map->affinity_mask.bits = 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 == PERF_AFFINITY_NODE && cpu__max_node() > 1) build_node_mask(cpu__get_node(map->core.cpu), &map->affinity_mask); else if (mp->affinity == PERF_AFFINITY_CPU) - set_bit(map->core.cpu, map->affinity_mask.bits); + set_bit(map->core.cpu.cpu, map->affinity_mask.bits); return 0; } -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 perf_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; }; -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 perf_cpu cpu); void mmap__munmap(struct mmap *map); 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_probe.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 @@ typedef void (*setup_probe_fn_t)(struct evsel *evsel); -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, const 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 = evlist__first(evlist); while (1) { - fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, flags); + fd = sys_perf_event_open(&evsel->core.attr, pid, cpu.cpu, -1, flags); if (fd < 0) { if (pid == -1 && errno == EACCES) { pid = 0; @@ -43,7 +43,7 @@ static int perf_do_probe_api(setup_probe_fn_t fn, int cpu, const char *str) fn(evsel); - fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, flags); + fd = sys_perf_event_open(&evsel->core.attr, pid, cpu.cpu, -1, flags); if (fd < 0) { if (errno == EINVAL) err = -EINVAL; @@ -61,7 +61,8 @@ static bool perf_probe_api(setup_probe_fn_t fn) { const char *try[] = {"cycles:u", "instructions:u", "cpu-clock:u", NULL}; struct perf_cpu_map *cpus; - int cpu, ret, i = 0; + struct perf_cpu cpu; + int ret, i = 0; cpus = perf_cpu_map__new(NULL); if (!cpus) @@ -136,15 +137,17 @@ bool perf_can_record_cpu_wide(void) .exclude_kernel = 1, }; struct perf_cpu_map *cpus; - int cpu, fd; + struct perf_cpu cpu; + int fd; cpus = perf_cpu_map__new(NULL); if (!cpus) return false; + cpu = cpus->map[0]; perf_cpu_map__put(cpus); - fd = sys_perf_event_open(&attr, -1, cpu, -1, 0); + fd = 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 7f782a31bda3..95fb53899bcd 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 = 0; i < evlist->core.nr_mmaps; i++) { struct mmap *md = &evlist->mmap[i]; - if (md->core.cpu == cpu) + if (md->core.cpu.cpu == cpu) return md; } @@ -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 record_opts *opts, struct call if (opts->group) evlist__set_leader(evlist); - if (evlist->core.cpus->map[0] < 0) + if (evlist->core.cpus->map[0].cpu < 0) opts->no_inherit = true; use_comm_exec = perf_can_comm_exec(); @@ -229,7 +229,8 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str) { struct evlist *temp_evlist; struct evsel *evsel; - int err, fd, cpu; + int err, fd; + struct perf_cpu cpu = { .cpu = 0 }; bool ret = false; pid_t pid = -1; @@ -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 = perf_cpu_map__new(NULL); - cpu = cpus ? cpus->map[0] : 0; + if (cpus) + cpu = cpus->map[0]; + perf_cpu_map__put(cpus); } else { cpu = evlist->core.cpus->map[0]; } while (1) { - fd = sys_perf_event_open(&evsel->core.attr, pid, cpu, -1, + fd = sys_perf_event_open(&evsel->core.attr, pid, cpu.cpu, -1, perf_event_open_cloexec_flag()); if (fd < 0) { if (pid == -1 && errno == EACCES) { diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 0445bee9290f..bd95d60018a9 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1555,7 +1555,7 @@ static void get_handler_name(char *str, size_t size, } 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 tstamp, struct perf_counts_values *count) { PyObject *handler, *t; @@ -1575,7 +1575,7 @@ process_stat(struct evsel *counter, int cpu, int thread, u64 tstamp, return; } - PyTuple_SetItem(t, n++, _PyLong_FromLong(cpu)); + PyTuple_SetItem(t, n++, _PyLong_FromLong(cpu.cpu)); PyTuple_SetItem(t, n++, _PyLong_FromLong(thread)); tuple_set_u64(t, n++, tstamp); @@ -1599,7 +1599,7 @@ static void python_process_stat(struct perf_stat_config *config, int cpu, thread; if (config->aggr_mode == AGGR_GLOBAL) { - process_stat(counter, -1, -1, tstamp, + process_stat(counter, (struct perf_cpu){ .cpu = -1 }, -1, tstamp, &counter->counts->aggr); return; } diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index e1a273048681..f19348dddd55 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2538,15 +2538,15 @@ int perf_session__cpu_bitmap(struct perf_session *session, } for (i = 0; i < map->nr; i++) { - int cpu = map->map[i]; + struct perf_cpu cpu = map->map[i]; - if (cpu >= nr_cpus) { + if (cpu.cpu >= 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; } - set_bit(cpu, cpu_bitmap); + set_bit(cpu.cpu, cpu_bitmap); } err = 0; @@ -2598,7 +2598,7 @@ int perf_event__process_id_index(struct perf_session *session, if (!sid) return -ENOENT; sid->idx = e->idx; - sid->cpu = e->cpu; + sid->cpu.cpu = e->cpu; sid->tid = e->tid; } return 0; diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c index ba95379efcfb..5db83e51ceef 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 *config, 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_config *config, struct evsel *evsel, const struct aggr_cpu_id *id) { struct perf_cpu_map *cpus = evsel__cpus(evsel); - int cpu, idx; + struct perf_cpu cpu; + int idx; if (config->aggr_mode == AGGR_NONE) return perf_cpu_map__idx(cpus, id->cpu); @@ -513,7 +514,8 @@ 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, 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 = data; - int idx, cpu; + int idx; + struct perf_cpu cpu; struct perf_cpu_map *cpus; struct aggr_cpu_id s2; @@ -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 = config->output; @@ -696,7 +699,7 @@ static void print_counter_aggrdata(struct perf_stat_config *config, fprintf(output, "%s", prefix); uval = val * counter->scale; - if (cpu != -1) + if (cpu.cpu != -1) id = aggr_cpu_id__cpu(cpu, /*data=*/NULL); printout(config, id, nr, counter, uval, @@ -731,8 +734,8 @@ static void print_aggr(struct perf_stat_config *config, first = true; evlist__for_each_entry(evlist, counter) { print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, /*cpu=*/-1); + prefix, metric_only, + &first, (struct perf_cpu){ .cpu = -1 }); } if (metric_only) fputc('\n', output); @@ -893,7 +896,8 @@ static void print_counter(struct perf_stat_config *config, FILE *output = config->output; u64 ena, run, val; double uval; - int idx, cpu; + int idx; + struct perf_cpu cpu; struct aggr_cpu_id id; perf_cpu_map__for_each_cpu(cpu, idx, evsel__cpus(counter)) { @@ -921,7 +925,8 @@ static void print_no_aggr_metric(struct perf_stat_config *config, struct evlist *evlist, char *prefix) { - int all_idx, cpu; + int all_idx; + struct perf_cpu cpu; 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_config *config, struct aggr_cpu_id s2, id; struct perf_cpu_map *cpus; bool first = true; - int idx, cpu; + int idx; + struct perf_cpu cpu; cpus = evsel__cpus(counter); perf_cpu_map__for_each_cpu(cpu, idx, cpus) { @@ -1247,8 +1253,8 @@ static void print_percore(struct perf_stat_config *config, fprintf(output, "%s", prefix); print_counter_aggrdata(config, counter, s, - prefix, metric_only, - &first, /*cpu=*/-1); + prefix, metric_only, + &first, (struct perf_cpu){ .cpu = -1 }); } 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 = counter->per_pkg_mask; struct perf_cpu_map *cpus = evsel__cpus(counter); - int cpu = perf_cpu_map__cpu(cpus, cpu_map_idx); + struct perf_cpu cpu = perf_cpu_map__cpu(cpus, cpu_map_idx); int s, d, ret = 0; uint64_t *key; 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; }; -typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, int cpu); +typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, struct perf_cpu cpu); 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 = 0; struct perf_cpu_map *m; - int c; + struct perf_cpu c; m = perf_cpu_map__new(s); if (!m) @@ -736,12 +736,12 @@ static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus) for (i = 0; i < m->nr; i++) { c = m->map[i]; - if (c >= nr_cpus) { + if (c.cpu >= nr_cpus) { ret = -1; break; } - set_bit(c, cpumask_bits(b)); + set_bit(c.cpu, cpumask_bits(b)); } 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 *cpus, cpus->nr = map->nr; for (i = 0; i < map->nr; i++) - cpus->cpu[i] = map->map[i]; + cpus->cpu[i] = map->map[i].cpu; } 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 = sizeof(long); for (i = 0; i < map->nr; i++) - set_bit(map->map[i], mask->mask); + set_bit(map->map[i].cpu, mask->mask); } 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) for (i = 0; i < map->nr; i++) { /* bit position of the cpu is + 1 */ - int bit = map->map[i] + 1; + int bit = map->map[i].cpu + 1; if (bit > *max) *max = bit; @@ -1354,7 +1354,7 @@ int perf_event__synthesize_stat_config(struct perf_tool *tool, } 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 *tool, event.header.misc = 0; event.id = id; - event.cpu = cpu; + event.cpu = cpu.cpu; event.thread = thread; event.val = count->val; event.ena = count->ena; @@ -1763,7 +1763,7 @@ int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_ } e->idx = sid->idx; - e->cpu = sid->cpu; + e->cpu = sid->cpu.cpu; e->tid = 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 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 *machine); int perf_event__synthesize_stat_events(struct perf_stat_config *config, struct 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, u64 type, perf_event__handler_t process, struct machine *machine); -int perf_event__synthesize_stat(struct perf_tool *tool, u32 cpu, u32 thread, 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 cpu, u32 thread, u64 id, struct perf_counts_values *count, perf_event__handler_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 *machine); 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__handler_t process, struct machine *machine, bool needs_mmap, bool mmap_data, unsigned 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 /* 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 */