From patchwork Thu Feb 1 04:22:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540639 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 A50FFC48292 for ; Thu, 1 Feb 2024 04:23:14 +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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jtV6fKNu2dFdHN8omopP/pPorRQu6ZYUyramDvOQ9EM=; b=TfaaiNwIl+2o7/ ptj4lNfUqtkxwzoybLls4RnXvmvFn7WR51rot7ZO2h5PiCNc1QfHrETHMO126eQbR2irm/4ZrcxF6 hAOmIs67zoyhTqesqoUaWPkhOiVopOhHY0TqwYH5gWCcj0YOB8U/jQpxfSEgufohkzFp/By8jdUT9 enTcqFYVVbs5YEH/wWoTp0YW2CPSNij7PoG8vyzz3WqXWFmAEfcpkB1YZqxutszMuIf2xUs/LLB9f +AzvR4A70Abt3lF434RWZXUqMBT3vPfyx5cp8W1rHaxZv1JfpNwRTF3au+xr2KbaW1f4hprAclxda gAE7oyfWzaNW1TUPIxDg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObQ-00000006URn-1KdX; Thu, 01 Feb 2024 04:23:04 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObF-00000006UJV-3NIc for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:22:55 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5f0fd486b9aso8743147b3.2 for ; Wed, 31 Jan 2024 20:22:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761371; x=1707366171; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=PeitV0yHOpBere8QJtZH8YRXFmaqbWcfFgW9touiCOY=; b=lP4bIiJSL44XUOJukZUBP+ZMR/i483/WI17RrFIVo8Hu5iCvCWR9WRkZi8iajFkZ6c v6hHVcgnaKWiujWYbllSEbP2PwurzRPZm5tfW0uqPD0uWRtU8zKxxR/R14i7oY4pHxSp bCBVPjQ2IDiX2gfBG4dn9bRQ1uHQ257YlpfXxmFej0+PBItnMv2w2N5phVQZnJP2TVaY OGgpkIdl1wAVHXiH6wsrlCDhVDdwwYEOlF6zDI24kghasU6TcmzJGr3je1zCCjLV1XYd ItPWdT/DS+HHURqhjQWDlPYdvw3iEwWBaMeieOmHIcjDFNIBO+kle3KGxqiP4GDl8wYF D/rQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761371; x=1707366171; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PeitV0yHOpBere8QJtZH8YRXFmaqbWcfFgW9touiCOY=; b=IDwkFLsJL0WqU8vZWKhxoE9iUglCUuPBBKLw28+ZcFJAd9J4RyFHhqCv6KnI1cfanP pX1F8fP93FwoVU+gqB/wb+WFLdchjK8mds/NWL4IxkaigC66xyKpQtUL+AmX8e2349/g SPQKpcKsp2H6CnstXBud1vrCwhkXyDNuVdtLUhd2aJvYsszbcgLWerGNHmi00NFFI492 u+y09Vlft7YRx/cmfjNfpaKwo9lsc9/rVRakcNFKGwjdBEOoi+ej9gO+PETohpsN1EPf VryZJp34BLzZeAVdTlCeQNqRxNglimNrCgm+l4j0M+QmHkubr1zCIIf2r7DzYbpUIaPL 4k9w== X-Gm-Message-State: AOJu0YwqGoZontmPHVxJCws1+5uuG0SDVhWj8lhHNltwOKGAaymgPNUX LqbYdKoGSt2poKU2p1/0Opi1tLBXXRd5WQeyblRD9wiAIgrGjzrVghQI6HEw8IIXaU/yKUA1vTv Xk5F1PA== X-Google-Smtp-Source: AGHT+IFM/pA3IJeVDmvTvXS5pxixyVYGQ3hKU8vPfyFZQMkJX3zylJwKIgo/7SF5iVC6oDBpHE6QZwLb8rWS X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a05:690c:39d:b0:5ff:5135:ffcf with SMTP id bh29-20020a05690c039d00b005ff5135ffcfmr196527ywb.4.1706761371160; Wed, 31 Jan 2024 20:22:51 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:29 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-2-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 1/8] libperf cpumap: Add any, empty and min helpers From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202253_864457_86FD7F88 X-CRM114-Status: GOOD ( 16.24 ) 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 Additional helpers to better replace perf_cpu_map__has_any_cpu_or_is_empty. Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 27 +++++++++++++++++++++++++++ tools/lib/perf/include/perf/cpumap.h | 16 ++++++++++++++++ tools/lib/perf/libperf.map | 4 ++++ 3 files changed, 47 insertions(+) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index 4adcd7920d03..ba49552952c5 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -316,6 +316,19 @@ bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map) return map ? __perf_cpu_map__cpu(map, 0).cpu == -1 : true; } +bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map) +{ + if (!map) + return true; + + return __perf_cpu_map__nr(map) == 1 && __perf_cpu_map__cpu(map, 0).cpu == -1; +} + +bool perf_cpu_map__is_empty(const struct perf_cpu_map *map) +{ + return map == NULL; +} + int perf_cpu_map__idx(const struct perf_cpu_map *cpus, struct perf_cpu cpu) { int low, high; @@ -372,6 +385,20 @@ bool perf_cpu_map__has_any_cpu(const struct perf_cpu_map *map) return map && __perf_cpu_map__cpu(map, 0).cpu == -1; } +struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map) +{ + struct perf_cpu cpu, result = { + .cpu = -1 + }; + int idx; + + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) { + result = cpu; + break; + } + return result; +} + struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map) { struct perf_cpu result = { diff --git a/tools/lib/perf/include/perf/cpumap.h b/tools/lib/perf/include/perf/cpumap.h index 228c6c629b0c..90457d17fb2f 100644 --- a/tools/lib/perf/include/perf/cpumap.h +++ b/tools/lib/perf/include/perf/cpumap.h @@ -61,6 +61,22 @@ LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus); * perf_cpu_map__has_any_cpu_or_is_empty - is map either empty or has the "any CPU"/dummy value. */ LIBPERF_API bool perf_cpu_map__has_any_cpu_or_is_empty(const struct perf_cpu_map *map); +/** + * perf_cpu_map__is_any_cpu_or_is_empty - is map either empty or the "any CPU"/dummy value. + */ +LIBPERF_API bool perf_cpu_map__is_any_cpu_or_is_empty(const struct perf_cpu_map *map); +/** + * perf_cpu_map__is_empty - does the map contain no values and it doesn't + * contain the special "any CPU"/dummy value. + */ +LIBPERF_API bool perf_cpu_map__is_empty(const struct perf_cpu_map *map); +/** + * perf_cpu_map__min - the minimum CPU value or -1 if empty or just the "any CPU"/dummy value. + */ +LIBPERF_API struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map); +/** + * perf_cpu_map__max - the maximum CPU value or -1 if empty or just the "any CPU"/dummy value. + */ LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map); LIBPERF_API bool perf_cpu_map__has(const struct perf_cpu_map *map, struct perf_cpu cpu); LIBPERF_API bool perf_cpu_map__equal(const struct perf_cpu_map *lhs, diff --git a/tools/lib/perf/libperf.map b/tools/lib/perf/libperf.map index 10b3f3722642..2aa79b696032 100644 --- a/tools/lib/perf/libperf.map +++ b/tools/lib/perf/libperf.map @@ -10,6 +10,10 @@ LIBPERF_0.0.1 { perf_cpu_map__nr; perf_cpu_map__cpu; perf_cpu_map__has_any_cpu_or_is_empty; + perf_cpu_map__is_any_cpu_or_is_empty; + perf_cpu_map__is_empty; + perf_cpu_map__has_any_cpu; + perf_cpu_map__min; perf_cpu_map__max; perf_cpu_map__has; perf_thread_map__new_array; From patchwork Thu Feb 1 04:22:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540641 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 07699C4828D for ; Thu, 1 Feb 2024 04:23: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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=+thjuj/7Zg5PrGM5GgU0en46CUQib0p/Fkz94XE9gSQ=; b=TsL/47FzLxCRKc M8gz6hOFy/YrOqk9kKtTbcF6ge44LpMLNhw4OuTMjf+ytCTB3hqgZCawNJoeEKYQlG11la1heXrWD W6x1MNrvUod+Tp6BSunIqVJILX1Uo/pq+lXDucjtWz4cc7Ivjt0fE8l1iTMjB9rzahhaNEfbf86P6 bbiMntoqQro6Mn6akLgr9xdiHX9SA+LzQv+HavlqPpIu73WbD0sey6rvttn6UwzwLkym7Ry+m9IN0 ofpgLrsLLF+ZDt2u60FTohPAxjxNHGy4ZDzaeGQaTIxj0Q+zZE/z1oEYqKdwuhKivSDc0Szxp6tWB YCpVYMg99F/IiUQGVTzw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObR-00000006UTN-2eq4; Thu, 01 Feb 2024 04:23:05 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObG-00000006UL1-4A6T for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:22:56 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5efe82b835fso10625227b3.0 for ; Wed, 31 Jan 2024 20:22:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761374; x=1707366174; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1JXSUMX5bbfgnckmTRSZnaB9bhkcugUHtNJBG9b4Oo4=; b=JtGjYZuF+Y0FOL2U9Mc0edgAsa//8ssCJU97HbCT0GVIQ7+qZHodKXIsm/NrTxsakI 0K+RjFKIOX7dnUhW8uylnPV2wOXAg6C24t9W7cPJQpqD9z0DGFvH8VEcKNSOR8lUYLgf wYOfUnSSB8oMSPYi53UOw2bCdIPIQKW8gVNP7Zn8/By9diZvCT0BiEcza6jRCK4yitQG dZL7/upVVFIL11DYWahcvGbyJ6X4uLeQKDtn4Fm/pv02ppaPZYuLN9YgvEan9BiWHZ6+ 6Z5WZOFDi4WLznS7S7FI5ZV2c0eLdQHjVv2thRwjczoFl5+KTlAxeEB3tGVgaYnzTyNN 4xeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761374; x=1707366174; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1JXSUMX5bbfgnckmTRSZnaB9bhkcugUHtNJBG9b4Oo4=; b=epOQN8cU4sVFaGDsbhZjIW25w3jWfYogdU+FhGeJKpXarcnlr3Ptv73vIVcsQifH7C IeOP3RdUmWOUrJUjiFSz5i3JKh15Kz/Rv+B+VHGfQvfUNqr6VEhxOXEWc7bXxPFgIfe7 etH80Syzw5ycM9/mWkkWr0v8BemOY4dO6h0ZPI7G09Lu/K5FszPU75dfVViPXz5iPYQK NMf5FoHi34fC5v+47Ggt718ci7o3tIygMl7oLAUeHryLJjSNYSVBGk9dP6LOPbqSjkyQ ticb37Kzcqa8/jnyyRqSm9xFrpIHuI+CtDJQrvU+rtFh5jBWKrEMkJCVrL4UI5FYCl/X gy/g== X-Gm-Message-State: AOJu0YwzGWjMgydP73nhnSjku2gGcXyR9oU/KD3y4hfL43eZBCy/vJ5v b82QXnoz+N5QvZAymYz5CtpO5FdQaGwpnFNlN6bhqoEMvqR6huScSeDMKNvQNS7sAKE7bNEmMgf QSFEFng== X-Google-Smtp-Source: AGHT+IFTJVPGgTJjz0vfAK3znBckhM+C3f96ATL1D3c1AModrSqCIkbFIqSfHTHrXRFHdRJrEfI2dhkZAVZt X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a81:9a92:0:b0:5ff:a41c:1d19 with SMTP id r140-20020a819a92000000b005ffa41c1d19mr780347ywg.9.1706761373658; Wed, 31 Jan 2024 20:22:53 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:30 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-3-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 2/8] libperf cpumap: Ensure empty cpumap is NULL from alloc From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202255_093764_EBE5FAE6 X-CRM114-Status: GOOD ( 13.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 Potential corner cases could cause a cpumap to be allocated with size 0, but an empty cpumap should be represented as NULL. Add a path in perf_cpu_map__alloc to ensure this. Suggested-by: James Clark Closes: https://lore.kernel.org/lkml/2cd09e7c-eb88-6726-6169-647dcd0a8101@arm.com/ Signed-off-by: Ian Rogers --- tools/lib/perf/cpumap.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/lib/perf/cpumap.c b/tools/lib/perf/cpumap.c index ba49552952c5..cae799ad44e1 100644 --- a/tools/lib/perf/cpumap.c +++ b/tools/lib/perf/cpumap.c @@ -18,9 +18,13 @@ void perf_cpu_map__set_nr(struct perf_cpu_map *map, int nr_cpus) struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) { - RC_STRUCT(perf_cpu_map) *cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); + RC_STRUCT(perf_cpu_map) *cpus; struct perf_cpu_map *result; + if (nr_cpus == 0) + return NULL; + + cpus = malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); if (ADD_RC_CHK(result, cpus)) { cpus->nr = nr_cpus; refcount_set(&cpus->refcnt, 1); From patchwork Thu Feb 1 04:22:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540640 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 0DEE4C48292 for ; Thu, 1 Feb 2024 04:23: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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=69iLZ9mFnoCBZJnV8GkgBHXDAdLqzN5v+XniZMRS76A=; b=KdsxrEvRbMrmHM ZE/8g/bxQJ7zGQ9sxUZ6OaBNcUnSJcpdObJfghWVO2q9Hgw+no/lF0RGs1K/J4MRdR9+v/JREptI0 4qOWgEy4nR3sF5HAgguMYd0cWSwK4KD+WU+WSUbXf2mjRnX4dyAz1JfFPPJyrIYWnwcS0ad4SLCtB DUCkp50JMO+q0A0bG46QjJ8At9j7B5vQxViEhNfBOCWa3rexNG8wtArHRy8Qv+PyDyBb8xBtyqzHI BcS/CbKH+ctQtUVG3OEiLfb+JMNaoJyycrRajq6bZMAfikPkJKygMLnBz0Jrz0GvgQxldEAPnEhLK k4KkueVkPDM/L8F0UmQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObS-00000006UUR-45z1; Thu, 01 Feb 2024 04:23:06 +0000 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObJ-00000006UMX-10gP for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:22:58 +0000 Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-dc6c2643a07so901881276.3 for ; Wed, 31 Jan 2024 20:22:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761376; x=1707366176; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=IpPU/P9Rw6DdLv5FLhNPDNExyhurg221RAp9ZKk92ek=; b=NwewM7JrReLOxanXPk3kJ7hp2ZCvXMK0UpOWA+tWd5v3VZ3PQktba67XcX97Bw+Rpr yl0h3f75RPx+1kVbwdQgu4u5bNbDwGYIgLXZpGLVVaq//7VSxx64VuZmTIPOqbuJyZXw +Nu+WOsNfXFuJOTCVLKCVxjKG2lCICUmE0T/Mpt61/avb7wylclyY7d/j1VNseE/EZWi zVmsX/YeDBcbVjf6K46zbROhY9dyoZflI+3t8U1df2TqwZiv0UjqOr/3HZooGaSvnI+S JGL1Em9tnatYObBS0AZmh3+aXv63812weaqEkKwBdIZr3kysbE7SDF221L+Gq2iJOZtG srnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761376; x=1707366176; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IpPU/P9Rw6DdLv5FLhNPDNExyhurg221RAp9ZKk92ek=; b=lyZl4OVnMTJ4s66JSCcT+++eqpulHddjc9SAk5AOEwhM0KkPY74zbLS9wWexcrwq8T lwB4aF1jxBzlR8bgFLXx8gWdSZFjCe0+dMThBsSQGzQBhlxB3U7UwLhSECRqihgykiKc 7vBbpolj39y1jGDoRq/QG30+43oQSGzZwKZCkcD1sL3REK5rwsiogSQNdLfC2G4W5RKo 3q+FMx3JjHDYZmIaODjwzbll8RHe8DUCYrWLc5aFYXrnm3Gfj4ThmyW7LjMP+c6CmldR g81EDDh5unN1Oy5NmylnQLe4uBhHviFeq+7GdvgoWWls662m5ZAoXPEL+wiYkd1Kov0v cr+Q== X-Gm-Message-State: AOJu0Yw4FofY1rLMBqaGY7peVHmVWc2p/MtAzsT2BGQTp0xCfwx9MOGT lu82rudIoXPNSZVGa4PC6q6gAhEoDtjQQwZjxnG2hQC3YnBJdVl5vmoZrxkgfE44jKk8VuUMx6F lbrGA8Q== X-Google-Smtp-Source: AGHT+IE8wymZahqqeemlY1iaO6CqbNktaK+r6W2Pm1C/Yfoy9QDR7o8EnoDQ7a0APQKk/WVTZRZ/UDTr08z0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a05:6902:e0c:b0:dc2:1f3b:abdd with SMTP id df12-20020a0569020e0c00b00dc21f3babddmr954876ybb.5.1706761376013; Wed, 31 Jan 2024 20:22:56 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:31 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-4-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 3/8] perf arm-spe/cs-etm: Directly iterate CPU maps From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202257_393680_9DAD8D6F X-CRM114-Status: GOOD ( 24.98 ) 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 Rather than iterate all CPUs and see if they are in CPU maps, directly iterate the CPU map. Similarly make use of the intersect function. Switch perf_cpu_map__has_any_cpu_or_is_empty to more appropriate alternatives. Signed-off-by: Ian Rogers --- tools/perf/arch/arm/util/cs-etm.c | 77 ++++++++++++---------------- tools/perf/arch/arm64/util/arm-spe.c | 4 +- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 77e6663c1703..f4378ba0b8d6 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -197,38 +197,32 @@ static int cs_etm_validate_timestamp(struct auxtrace_record *itr, static int cs_etm_validate_config(struct auxtrace_record *itr, struct evsel *evsel) { - int i, err = -EINVAL; + int idx, err = -EINVAL; struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); + struct perf_cpu_map *intersect_cpus = perf_cpu_map__intersect(event_cpus, online_cpus); + struct perf_cpu cpu; - /* Set option of each CPU we have */ - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; - - /* - * In per-cpu case, do the validation for CPUs to work with. - * In per-thread case, the CPU map is empty. Since the traced - * program can run on any CPUs in this case, thus don't skip - * validation. - */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus) && - !perf_cpu_map__has(event_cpus, cpu)) - continue; - - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; + perf_cpu_map__put(online_cpus); - err = cs_etm_validate_context_id(itr, evsel, i); + /* + * Set option of each CPU we have. In per-cpu case, do the validation + * for CPUs to work with. In per-thread case, the CPU map is empty. + * Since the traced program can run on any CPUs in this case, thus don't + * skip validation. + */ + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { + err = cs_etm_validate_context_id(itr, evsel, cpu.cpu); if (err) goto out; - err = cs_etm_validate_timestamp(itr, evsel, i); + err = cs_etm_validate_timestamp(itr, evsel, cpu.cpu); if (err) goto out; } err = 0; out: - perf_cpu_map__put(online_cpus); + perf_cpu_map__put(intersect_cpus); return err; } @@ -435,7 +429,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, * Also the case of per-cpu mmaps, need the contextID in order to be notified * when a context switch happened. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, "timestamp", 1); evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, @@ -461,7 +455,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, evsel->core.attr.sample_period = 1; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) evsel__set_sample_bit(evsel, TIME); err = cs_etm_validate_config(itr, cs_etm_evsel); @@ -533,38 +527,32 @@ static size_t cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, struct evlist *evlist __maybe_unused) { - int i; + int idx; int etmv3 = 0, etmv4 = 0, ete = 0; struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); + struct perf_cpu cpu; /* cpu map is not empty, we have specific CPUs to work with */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; - - if (!perf_cpu_map__has(event_cpus, cpu) || - !perf_cpu_map__has(online_cpus, cpu)) - continue; + if (!perf_cpu_map__is_empty(event_cpus)) { + struct perf_cpu_map *intersect_cpus = + perf_cpu_map__intersect(event_cpus, online_cpus); - if (cs_etm_is_ete(itr, i)) + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { + if (cs_etm_is_ete(itr, cpu.cpu)) ete++; - else if (cs_etm_is_etmv4(itr, i)) + else if (cs_etm_is_etmv4(itr, cpu.cpu)) etmv4++; else etmv3++; } + perf_cpu_map__put(intersect_cpus); } else { /* get configuration for all CPUs in the system */ - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; - - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; - - if (cs_etm_is_ete(itr, i)) + perf_cpu_map__for_each_cpu(cpu, idx, online_cpus) { + if (cs_etm_is_ete(itr, cpu.cpu)) ete++; - else if (cs_etm_is_etmv4(itr, i)) + else if (cs_etm_is_etmv4(itr, cpu.cpu)) etmv4++; else etmv3++; @@ -814,15 +802,14 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, return -EINVAL; /* If the cpu_map is empty all online CPUs are involved */ - if (perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { + if (perf_cpu_map__is_empty(event_cpus)) { cpu_map = online_cpus; } else { /* Make sure all specified CPUs are online */ - for (i = 0; i < perf_cpu_map__nr(event_cpus); i++) { - struct perf_cpu cpu = { .cpu = i, }; + struct perf_cpu cpu; - if (perf_cpu_map__has(event_cpus, cpu) && - !perf_cpu_map__has(online_cpus, cpu)) + perf_cpu_map__for_each_cpu(cpu, i, event_cpus) { + if (!perf_cpu_map__has(online_cpus, cpu)) return -EINVAL; } diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index 51ccbfd3d246..0b52e67edb3b 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -232,7 +232,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, * In the case of per-cpu mmaps, sample CPU for AUX event; * also enable the timestamp tracing for samples correlation. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(arm_spe_evsel, CPU); evsel__set_config_if_unset(arm_spe_pmu, arm_spe_evsel, "ts_enable", 1); @@ -265,7 +265,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, tracking_evsel->core.attr.sample_period = 1; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(tracking_evsel, TIME); evsel__set_sample_bit(tracking_evsel, CPU); From patchwork Thu Feb 1 04:22:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540642 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 79554C4828E for ; Thu, 1 Feb 2024 04:23: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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UDuG1SWf++qjU872GUENZJh+z4GH+7kHYg+Py8ldsuw=; b=e2T0i0EgA1s0r8 5vEMZCfIzPoxmV5DmCz1qy+uPqN80WZ7ja26Hr7Olz67NTRJFYo/jFNEAurXYguDs7J9tdQGMhVcd C4zfRHM2Vv99MI3E5AtcsstA6EK62IsSVmIIQUmblx/EzC4JMteWBfjmoe2iUYJ0fAg2g1NNZWeU2 u2yr9cAMMPJAm+V8ZTYj2CCSjq08YKBnY5e4ELSTXMytbOqMExUl2vzRSG9R9IXhLlZziynD31Iwj WV5begRZ88LNhQv7A0n/3l1AiYZv3lBXDl2HzMaTSDe5yNbcdf8h9CChkYchgDHxjBp0affAyYRRt +ArySIAEzIxEqZ8YaLNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObU-00000006UW9-3rfS; Thu, 01 Feb 2024 04:23:08 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObM-00000006UOc-0fwM for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:23:01 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-6040b27151eso10754777b3.3 for ; Wed, 31 Jan 2024 20:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761378; x=1707366178; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=x5H1VG+iZLkcs4atGUwnj2dxBUXygPFhAbtPAwQlWtQ=; b=ireiOZyl4dxGrBGSolfrhojfiaMYCPj6SA+7NHnYFNnHCFWdDRrB5qfFgN1H2z+Qmb K/IcuisDw8lduhJmHVZua0Ksv/M9y334lCuDrNNZBGtN9rGjlUHlBnNE2wxcoqoKa6JJ XxvKj1peCzMoHBMZvS46KVQ+nOxtoZes/sJaCNHEkkbg6RgwM+3rOia1GfKzekNRZwk3 GCd7iWkAfz9JXwZQjB9bOuog5ZF0iAYT8Jusn0I/Y9KgErH3YXxHxdKCjYs6UZyoesEE tfQ1kMylImgGlWy5e53YVr1la4pU5CCOgW7YGK40hS07VS704HrUjjSYgms43Q0XbShc IJLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761378; x=1707366178; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=x5H1VG+iZLkcs4atGUwnj2dxBUXygPFhAbtPAwQlWtQ=; b=IGO3UH6kjp0RTIqkGSPAm9bFIZnxOOhit6kxO36TyV7iczQdZlCY1+aAQ+rVbQ/Hxc mQ5cwuFkKkdB7t8ARXfnWXoB3hNqrLcHa4s0lxMmV+leBjXYIlITZKQ7Sup+L8g1k+md wuS0SwZUFAkzmub4/afZnuHMIfzUXebVAXWWxdFCQJQ/OtS8SV/hj0PI7DKBv4fz3n// zVRhhbJBZ7qz9zyzoCR+XjffxzDMXpmzjaE4WAdEm2/6ZYHysYWu1wNEQkjzlNkRYR7g pPLa/hTEzNT1mQeE8xGLDQxUmdbkxQjXHLKJLjq1A4Pd/bBNPokulrGRa53phkKmXpsf 33ZA== X-Gm-Message-State: AOJu0Ywn2slhDZ1oyzu+ifguLoygVwVrib8pvySqQkOGOFaI2wXHohjl sURNfo+a3KOtQ2wjc0BMGUcq85ZBVtLx1BRlzGakbaEhX9Qk2e0d+BbYYMdAgdjpYMpVrXxRl+Q CZRaN1g== X-Google-Smtp-Source: AGHT+IE3RH3Ke4eANE6VdqsDS/07MSf52wJfexOO2bfk4oK9JWx8tVpld1JtN4fAkIWLv8ktb9i+9FIBeDm2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a81:4cd5:0:b0:604:9ba:9a03 with SMTP id z204-20020a814cd5000000b0060409ba9a03mr798650ywa.2.1706761378559; Wed, 31 Jan 2024 20:22:58 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:32 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-5-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 4/8] perf intel-pt/intel-bts: Switch perf_cpu_map__has_any_cpu_or_is_empty use From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202300_259616_2ED175A6 X-CRM114-Status: GOOD ( 17.99 ) 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 perf_cpu_map__has_any_cpu_or_is_empty to perf_cpu_map__is_any_cpu_or_is_empty as a CPU map may contain CPUs as well as the dummy event and perf_cpu_map__is_any_cpu_or_is_empty is a more correct alternative. Signed-off-by: Ian Rogers --- tools/perf/arch/x86/util/intel-bts.c | 4 ++-- tools/perf/arch/x86/util/intel-pt.c | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/perf/arch/x86/util/intel-bts.c b/tools/perf/arch/x86/util/intel-bts.c index af8ae4647585..34696f3d3d5d 100644 --- a/tools/perf/arch/x86/util/intel-bts.c +++ b/tools/perf/arch/x86/util/intel-bts.c @@ -143,7 +143,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, if (!opts->full_auxtrace) return 0; - if (opts->full_auxtrace && !perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (opts->full_auxtrace && !perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { pr_err(INTEL_BTS_PMU_NAME " does not support per-cpu recording\n"); return -EINVAL; } @@ -224,7 +224,7 @@ static int intel_bts_recording_options(struct auxtrace_record *itr, * In the case of per-cpu mmaps, we need the CPU on the * AUX event. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) evsel__set_sample_bit(intel_bts_evsel, CPU); } diff --git a/tools/perf/arch/x86/util/intel-pt.c b/tools/perf/arch/x86/util/intel-pt.c index d199619df3ab..6de7e2d21075 100644 --- a/tools/perf/arch/x86/util/intel-pt.c +++ b/tools/perf/arch/x86/util/intel-pt.c @@ -369,7 +369,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr, ui__warning("Intel Processor Trace: TSC not available\n"); } - per_cpu_mmaps = !perf_cpu_map__has_any_cpu_or_is_empty(session->evlist->core.user_requested_cpus); + per_cpu_mmaps = !perf_cpu_map__is_any_cpu_or_is_empty(session->evlist->core.user_requested_cpus); auxtrace_info->type = PERF_AUXTRACE_INTEL_PT; auxtrace_info->priv[INTEL_PT_PMU_TYPE] = intel_pt_pmu->type; @@ -774,7 +774,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, * Per-cpu recording needs sched_switch events to distinguish different * threads. */ - if (have_timing_info && !perf_cpu_map__has_any_cpu_or_is_empty(cpus) && + if (have_timing_info && !perf_cpu_map__is_any_cpu_or_is_empty(cpus) && !record_opts__no_switch_events(opts)) { if (perf_can_record_switch_events()) { bool cpu_wide = !target__none(&opts->target) && @@ -832,7 +832,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, * In the case of per-cpu mmaps, we need the CPU on the * AUX event. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) evsel__set_sample_bit(intel_pt_evsel, CPU); } @@ -858,7 +858,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, tracking_evsel->immediate = true; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(tracking_evsel, TIME); /* And the CPU for switch events */ evsel__set_sample_bit(tracking_evsel, CPU); @@ -870,7 +870,7 @@ static int intel_pt_recording_options(struct auxtrace_record *itr, * Warn the user when we do not have enough information to decode i.e. * per-cpu with no sched_switch (except workload-only). */ - if (!ptr->have_sched_switch && !perf_cpu_map__has_any_cpu_or_is_empty(cpus) && + if (!ptr->have_sched_switch && !perf_cpu_map__is_any_cpu_or_is_empty(cpus) && !target__none(&opts->target) && !intel_pt_evsel->core.attr.exclude_user) ui__warning("Intel Processor Trace decoding will not be possible except for kernel tracing!\n"); From patchwork Thu Feb 1 04:22:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540644 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 932D6C4828E for ; Thu, 1 Feb 2024 04:24:34 +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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=zovqoioC7M7ChqDLFBycZPHaIUbYjdB4U7QTExqXXRg=; b=uIYVjyZA7I1Q8T kpiyRLcQ41htbiZNUyJBqUGnLmZfVChDMg0vt2CPykJwG/nfYu8/pbk+TtrJ92is0lGHnLa1a8P6s neJppd9HhsyaHCo5H2TJWmnau/WwMzFhkcXsumtAWwMpoTFL3DMuClXH2uhGIlFnSZAUjMsPLrhmW vsBjQjT/u5joZKbidpX1dfdES2TepBNuROouqJB2+6/FrNx+HvEe90MShW/79TmPLKlM84EHCKK2J ApkcfP3V4jAZ0cTqLMI9WVASSVzNwRZ5lt6QE4NHN/9RTDNRMPqAn+AmAPqoMjRaGiPqifvVtXi8v I/MWKcZzYn7Coy5vDh2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVOcf-00000006V6z-3m4q; Thu, 01 Feb 2024 04:24:21 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObO-00000006UQ0-20Rd for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:23:04 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc6cd10fd94so928968276.3 for ; Wed, 31 Jan 2024 20:23:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761381; x=1707366181; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=ZaackeHVB/qKw2MvrD7oP7QYNMjIwSaxho/+246ePe0=; b=AzOJZqDeMZUsfE6tvPC/Bg59tWItqem+x6yYhHdPrFYhn80+idh1YvtAr4mqWmsypE GI/4dBNg4R33WyvbNvgymdDqtMgRh7NylI+L9t1IQE7T8T3OQUH/nMN8aVUhDceEXKl5 xtrOxv5zhDq6rNPgqNG4joZTrmt2B9vEojS0BiOSsVf6O4Ljk69zosQeoW2aN5xUP2dk 57l4/chkmKobtJ+m7OiBf7V4+RPpCbXqk4ydbmralzCnUJKOKPGEcT/yi9zR06jsEQsr 97LDvTWaaDB/I9fMaz/bMY2IUD53Awqguq555JaXGc51tFq0kJ6RMESvPUEOInxphrHD kZAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761381; x=1707366181; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ZaackeHVB/qKw2MvrD7oP7QYNMjIwSaxho/+246ePe0=; b=buB6Y+V9J/As0tHyRCl0hYyfVH11nIKmjaCduYUhrz5JRsWYT8TYPuUYO/MgZvgXas YIqocC1m6SMJqZjMzAS582gv9A1WYITFhDerCoeSqLU71QQX0cGGWWSvAV36yG1ED5Lo /SqwioeUCZXr4iqszw5kVM7WXk5kZvYKJ0YaOGT9FrQa2xmFEFCZxw2erj+NQ7OsjrSZ rfA0RqFC87msVr57nsZCEbX1DJjySRV95dhvLD60dAMkan9odQsR5lFK11StqMPc8SF3 siE42OoMQ+ZxcAUkXOE2p8HhBFHjH2VavsBnrDIDeoHWjmL9WcKW2GWPc2j8TBAIIFnq Tv6g== X-Gm-Message-State: AOJu0YxFYRpsIaxWQCE2BW0IoUIAyyk5KYylSdEdqQBnlQxJb4/NOJTu 8o1nGca7sTpcOcFntE7fO0in7xLfbyWKrBJ5kF80sZXDb4LC7B+rLqHr5qucn7TFxzBNrBobXjg Dq6Lp3Q== X-Google-Smtp-Source: AGHT+IEUPC2zlxhPtNWRqxBFUB5XE3UaTGp/yUzEFGp5NGipkKsgllYlB40XOB8TU6jIChbSPsGFseZNtWq5 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a05:6902:2082:b0:dc2:50cd:bee6 with SMTP id di2-20020a056902208200b00dc250cdbee6mr1003483ybb.9.1706761381204; Wed, 31 Jan 2024 20:23:01 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:33 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-6-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 5/8] perf cpumap: Clean up use of perf_cpu_map__has_any_cpu_or_is_empty From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202302_598590_893D03DD X-CRM114-Status: GOOD ( 21.66 ) 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 Most uses of what was perf_cpu_map__empty but is now perf_cpu_map__has_any_cpu_or_is_empty want to do something with the CPU map if it contains CPUs. Replace uses of perf_cpu_map__has_any_cpu_or_is_empty with other helpers so that CPUs within the map can be handled. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/builtin-c2c.c | 6 +----- tools/perf/builtin-stat.c | 9 ++++----- tools/perf/util/auxtrace.c | 4 ++-- tools/perf/util/record.c | 2 +- tools/perf/util/stat.c | 2 +- 5 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c index 16b40f5d43db..24107062c43e 100644 --- a/tools/perf/builtin-c2c.c +++ b/tools/perf/builtin-c2c.c @@ -2319,11 +2319,7 @@ static int setup_nodes(struct perf_session *session) nodes[node] = set; - /* empty node, skip */ - if (perf_cpu_map__has_any_cpu_or_is_empty(map)) - continue; - - perf_cpu_map__for_each_cpu(cpu, idx, map) { + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) { __set_bit(cpu.cpu, set); if (WARN_ONCE(cpu2node[cpu.cpu] != -1, "node/cpu topology bug")) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 5fe9abc6a524..280eb0c99d2b 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1317,10 +1317,9 @@ static int cpu__get_cache_id_from_map(struct perf_cpu cpu, char *map) * be the first online CPU in the cache domain else use the * first online CPU of the cache domain as the ID. */ - if (perf_cpu_map__has_any_cpu_or_is_empty(cpu_map)) + id = perf_cpu_map__min(cpu_map).cpu; + if (id == -1) id = cpu.cpu; - else - id = perf_cpu_map__cpu(cpu_map, 0).cpu; /* Free the perf_cpu_map used to find the cache ID */ perf_cpu_map__put(cpu_map); @@ -1623,7 +1622,7 @@ static int perf_stat_init_aggr_mode(void) * taking the highest cpu number to be the size of * the aggregation translate cpumap. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(evsel_list->core.user_requested_cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(evsel_list->core.user_requested_cpus)) nr = perf_cpu_map__max(evsel_list->core.user_requested_cpus).cpu; else nr = 0; @@ -2290,7 +2289,7 @@ int process_stat_config_event(struct perf_session *session, perf_event__read_stat_config(&stat_config, &event->stat_config); - if (perf_cpu_map__has_any_cpu_or_is_empty(st->cpus)) { + if (perf_cpu_map__is_empty(st->cpus)) { if (st->aggr_mode != AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); } else if (st->aggr_mode != AGGR_UNSET) { diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 3684e6009b63..6b1d4bafad59 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -174,7 +174,7 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp, struct evlist *evlist, struct evsel *evsel, int idx) { - bool per_cpu = !perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus); + bool per_cpu = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); mp->mmap_needed = evsel->needs_auxtrace_mmap; @@ -648,7 +648,7 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr, static int evlist__enable_event_idx(struct evlist *evlist, struct evsel *evsel, int idx) { - bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus); + bool per_cpu_mmaps = !perf_cpu_map__has_any_cpu(evlist->core.user_requested_cpus); if (per_cpu_mmaps) { struct perf_cpu evlist_cpu = perf_cpu_map__cpu(evlist->core.all_cpus, idx); diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c index 87e817b3cf7e..e867de8ddaaa 100644 --- a/tools/perf/util/record.c +++ b/tools/perf/util/record.c @@ -237,7 +237,7 @@ bool evlist__can_select_event(struct evlist *evlist, const char *str) evsel = evlist__last(temp_evlist); - if (!evlist || perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_requested_cpus)) { + if (!evlist || perf_cpu_map__is_any_cpu_or_is_empty(evlist->core.user_requested_cpus)) { struct perf_cpu_map *cpus = perf_cpu_map__new_online_cpus(); if (cpus) diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c index b0bcf92f0f9c..0bd5467389e4 100644 --- a/tools/perf/util/stat.c +++ b/tools/perf/util/stat.c @@ -315,7 +315,7 @@ static int check_per_pkg(struct evsel *counter, struct perf_counts_values *vals, if (!counter->per_pkg) return 0; - if (perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (perf_cpu_map__is_any_cpu_or_is_empty(cpus)) return 0; if (!mask) { From patchwork Thu Feb 1 04:22:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540643 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 88D19C4828D for ; Thu, 1 Feb 2024 04:24:31 +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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1OlK6VauYZnTBbefpaJB6W0ztRvnm6XMH8rqx1K1X3s=; b=wpnzpLvTUS7rZm M+wijTdHEZ0bOvRGZU114cMczz3oyUb+gPTNyl8GollLaCYQICtDSkYX4tVy7+dmDKuCJ26+Rv8fe hxg8kuk2sqZWiUGoSfBEyowODULkTjteGva+iGW823mZK7XHbP0xkSxKzI6Dwsi2qQx3R+BYCzOqa FB1kIHLTEB0QT+yUavH/FFGgmJ06z3LIYacnQ0LrnWKKRz7A8GEWc5WsDQqoHgAPVsdkaWn4EaKfF B+krMFKWUpDSIXAUUuWXGxAcJcqrnogGE03jBMFuTA+bwJwbA73LCmR0xG2+dRObQ25AGe99tIzZ9 ArQvWgPHfXZApQRc6oAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVOcg-00000006V7f-3xrr; Thu, 01 Feb 2024 04:24:22 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObQ-00000006URY-31hX for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:23:06 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6040ffa60ddso10414847b3.2 for ; Wed, 31 Jan 2024 20:23:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761383; x=1707366183; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=RrRDV2OgW3nzJBdkuc2LAITTVB+J1bOMfWE+IFXHyeo=; b=0LggW9VeG93DCFyQAdcSTz7FzuNy7xDrZMJRfscfekTcaDTb1aPtNagbfENxpuiiY4 xom0F7/pbOcW930GiVPWGU6/ZBhyUSabgw/yzEIQFO9/K+X+YgQNag5i8oIrGhz7IxJ/ ud3ldTKgPBS6XNp9auM47vyc23dSiM0Z+Kll0HksSSCaEYcyPpnr53e8kFER7bGPdSGL A1RqP3wmcOxtXBov5ZfkVS6XSthMOo3gpqeaIuBljCNkasHo05PH5QRQT/4KUvkekatT I9TUKkYVa5zWlFjXT6IA/OhlLagjmfEJZ9Nh5IOMHE3FTJUDawBpzZO9Jw3kKYd7FI1b qx7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761383; x=1707366183; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RrRDV2OgW3nzJBdkuc2LAITTVB+J1bOMfWE+IFXHyeo=; b=llHovQIHcAHpMXujZhfuoZd7dHZN9Qn0ORvMaTorUXzjbQ3dx51WvWvh3N2/hvq2MD 4H+fbbZ5ctADbEZBh4yylxqn5zPv2rEZNZ7gtxyGBtGSNt+blFa4m8TGVf0LGrTxd/ec lYMxUs+osaIFj0qpuHDbZOZWl4toFNJ8EsGkvS5pftRmQhrBY1V7El5bAMsvPVzA8LVF q+cwYV0p/H4iG69ZUdNKNVc9xCimS19oH62i+ckWpCiG8w5UOgShHKZ1SQ/tyXUGF4zz C6tMo4Vea0PebtckYVGrTBWI4rqvnz/ESHFE5TYoJyl1sQ6+8I/8pRw5JPTuQdPgpuak e2fA== X-Gm-Message-State: AOJu0YzgPhFY7LX8JXRCpysGa5HirJ1mVd42iQhDZCyivo4uulJrqD4R 2WM6C36QEZj8Z/H36Uz6HXwS9WFf2UKN6rV3HywSJLszgEf2NNHlYSdnhcQvDZa3+QY6SHpZosc tHz9F0w== X-Google-Smtp-Source: AGHT+IHv2O8VUbbF42oYcEoSvj2zyIzzBYr0IR+xIhh6JLaWfzzkVzgzvhvYusGBJ3wuD/mw4QrkRZGlA0nR X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a81:57ca:0:b0:5ff:5866:bc37 with SMTP id l193-20020a8157ca000000b005ff5866bc37mr830069ywb.3.1706761383514; Wed, 31 Jan 2024 20:23:03 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:34 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-7-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 6/8] perf arm64 header: Remove unnecessary CPU map get and put From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202304_899268_D8D8AAD0 X-CRM114-Status: GOOD ( 11.93 ) 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 In both cases the CPU map is known owned by either the caller or a PMU. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm64/util/header.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index 97037499152e..a9de0b5187dd 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -25,8 +25,6 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) if (!sysfs || sz < MIDR_SIZE) return EINVAL; - cpus = perf_cpu_map__get(cpus); - for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { char path[PATH_MAX]; FILE *file; @@ -51,7 +49,6 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) break; } - perf_cpu_map__put(cpus); return ret; } From patchwork Thu Feb 1 04:22:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540646 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 2F1D8C48291 for ; Thu, 1 Feb 2024 04:24:35 +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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gJhwOI2K+/RVJD4Oxec89rMCq4oPwMC7IsHO4HixSBs=; b=sDwxZWjzeZciA8 Q35svqKiOSleGDBJDZXDNk2+w18yWxSeRxYzbth8r6aL/X76GBuaeTiTf9j9FEJp+KakxVbX91rAh bvnE2onWtpBQ/FMkpq3ASIsTUx846q4NEa+evvQyQdn8zu2z4iuy37yCd9YVW6UVBqJCWraNBzxOA /d7H3YdBR8logmFPNhJCjAA6yB0GrkBP4+TCJ1x8Zt8cTUJVpmCSXFXVI5xUDGUPqHaDWo3wo9cm+ gf+CiyLp8E+WZB9+xph3er0Ksv98g4MRxWShbbRj7Z+Oq6miHgi+7YOy1hwovUpn1Lol7/hzpjdBe b3RqJETPC+BMeNgRQykw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVOch-00000006V8A-2hya; Thu, 01 Feb 2024 04:24:23 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObT-00000006UUK-1PKY for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:23:09 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6040b27151eso10755797b3.3 for ; Wed, 31 Jan 2024 20:23:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761386; x=1707366186; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=LqZwZ8AsgQZJFdN47MyZTq1RxCf/Pyb95/3gvsK2ot0=; b=xDR7GrfWCWfcD+MpK0cW1YDNpch4HnV8DfY1FQ0WoY2LwrJ7YOZX/zkHJ48dNF4aLT j9qHshO6TeSxFjECnIQrzhyb6BR6T4DbnIfP/y3VWHyr6XOGrlFTsmJcpwNzEQcFcn+g GcMKhVKlYO/L7IEowTHHyyhjTRnTsY2+ErrThZX5ksI15eFN4VPsP82YT2J4RlNEU2NP 0Z0yFnfvsQWZwM3nec8mjo5ypeSINjFC8VwInkB1wgn4LX+ajID9rMWjlWRjVdv2Tjhf jA8hbagQLXcwmekSMUO/99/MblIv7zDoMgBqnor69yn00l8zEQxmIv3Iq67Toawg0lfk ItCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761386; x=1707366186; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LqZwZ8AsgQZJFdN47MyZTq1RxCf/Pyb95/3gvsK2ot0=; b=CkmeebECzNKwndqrT8GsVFL7L/gnTYgGWe2IFcizbY7Xdj7noHcrLMA5Ebr7vOgFth 2+/VCdAEzS76bWkkRt2QEnkwqvqjcYQvS9X6bN/M0bYUVtJ21/K/Z5yaBToRO2m4+uxx vg7+zKJnQAC51qq2DYvBwLXAP7tfey3PzY+51XHapyBfItvUiQF3c9G+SBeGtKYnEiWN B+Kiqy0Otyk03le3DhM48aYOsHCRQRPsK6HCJ8RxyxRoX/37mRHK7G2rfLPOzmWpq82y guPRJNB9d58oKehEK5/n2w7n56K+5LqHRgO/Nv5uUbaSLqv6Gxjao8cMlCcG62rLiDCw dX8g== X-Gm-Message-State: AOJu0YzzXb4oz5WPTsFT+SwUy8MM6QPNWIpxm91SJWBHgEZbdvIXYV2Q E0ddydGkdgygmbjGAqDqbHtUCLWuapbtrtxlf2lsG5IIqc4VMkcZX0/pM/8LEDU96Psi0QEG+tq nSoioBg== X-Google-Smtp-Source: AGHT+IEbBHPoopwAV46hmLodLw8f6XGcENXHUyhMaiQPvtiJ/0/ATGvBJGXoRGEaXvOe810MmKMKo255lWtS X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a05:6902:2749:b0:dc6:a29d:e0b7 with SMTP id ea9-20020a056902274900b00dc6a29de0b7mr975743ybb.4.1706761385897; Wed, 31 Jan 2024 20:23:05 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:35 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-8-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 7/8] perf stat: Remove duplicate cpus_map_matched function From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202307_701926_8F7C4DB1 X-CRM114-Status: GOOD ( 14.46 ) 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 libperf's perf_cpu_map__equal that performs the same function. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/builtin-stat.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 280eb0c99d2b..d80bad7c73e4 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -164,26 +164,6 @@ static struct perf_stat_config stat_config = { .iostat_run = false, }; -static bool cpus_map_matched(struct evsel *a, struct evsel *b) -{ - if (!a->core.cpus && !b->core.cpus) - return true; - - if (!a->core.cpus || !b->core.cpus) - return false; - - if (perf_cpu_map__nr(a->core.cpus) != perf_cpu_map__nr(b->core.cpus)) - return false; - - for (int i = 0; i < perf_cpu_map__nr(a->core.cpus); i++) { - if (perf_cpu_map__cpu(a->core.cpus, i).cpu != - perf_cpu_map__cpu(b->core.cpus, i).cpu) - return false; - } - - return true; -} - static void evlist__check_cpu_maps(struct evlist *evlist) { struct evsel *evsel, *warned_leader = NULL; @@ -194,7 +174,7 @@ static void evlist__check_cpu_maps(struct evlist *evlist) /* Check that leader matches cpus with each member. */ if (leader == evsel) continue; - if (cpus_map_matched(leader, evsel)) + if (perf_cpu_map__equal(leader->core.cpus, evsel->core.cpus)) continue; /* If there's mismatch disable the group and warn user. */ From patchwork Thu Feb 1 04:22:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13540645 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 21BF5C4828D for ; Thu, 1 Feb 2024 04:24:35 +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:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2M2JT1ZAPq9TTmXa1FpWQBZXreY6s9hbzV7IAAuzzD0=; b=ssJczqXt/FM0eA 0LK3XhTrGcT6sYvOfvRVsNEIxzPiHsMjdemL7N2Tgn4z8tGQYcQfirgjGbqGfIBGYuq+ivkI/hBc0 gxHLCdnj/lmXJUXKdLnA5UosiB1mL3Vba77Ox/eDl258BObf13oWDK6jMcZ52HecwaP5Vzevs4smx MysVSkiFIM6eqCreEq7IP4o2opHhUS6EQFY6g6LiL9GqE4Mf4gtIOg+dmOvl4m+8OoqtQMrEyb/VV 4ilGRqsrWY/8BPa1sncivf6h66Ikq7SgejuACYUtH2G479+qphuDW9DTsY7RmUp5ORQKhg66kILDi n/H5gwt66vxCm0lc9C7g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVOci-00000006V8o-1tYc; Thu, 01 Feb 2024 04:24:24 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVObV-00000006UWG-2ZVT for linux-arm-kernel@lists.infradead.org; Thu, 01 Feb 2024 04:23:13 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dc6c24a4ce1so810703276.2 for ; Wed, 31 Jan 2024 20:23:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761388; x=1707366188; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=hY5FohHp4Dii+HVW+aj7VdYLbpZQQ/NLbocSDzACXdA=; b=a+lLTZEvMozUOVoqf4ITHSPAkFr64kv+B54VWf5ci+rlP4Mj8QsjcBHPHdiPsXwWIE KR51o5Rb61JJzsaWwI48MWYqc0gtSCIl96RJwohmf4+UhKFPciMeN2rxAhZYyQCW/7fr ws9g0r8zjF1YxYTNwGodKvDJe+C0GMCAh9amzSBA5g7GzgIBeVUXLPP2fS/Nt/BFDGAP oRk8osbdDJ7RphyAyeRQ+oDCF/J6fPxHoWJ/6QhEfDT4OAxWl8K4JrX9+Ou+mOIfm6s3 8YXMWjNU6U2tkCbTlUFEzAFFOHrJqcae7oZZx/+Z5S4TP1eHZo1mnaCRXMCSsCe7ta+V k3Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706761388; x=1707366188; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=hY5FohHp4Dii+HVW+aj7VdYLbpZQQ/NLbocSDzACXdA=; b=EnlOb7JMd/l/9eqpaeWVHKyqHNWNsJ7+RELM0ZmV+BNk9Y5bEbSvTettsEzREoCj4F aQmqKfe1i99Qd1yMr9qZ7J2+MsncFLf4joe/Th4X1vWq/pOcEnp883J47khwxaVdscmF MHC3gJRN+rMNOQY6cZFotYxIgDqxPy2t3x2FiRGn4amHECb8DlHhaeziSpZSHJ26dfYb sMMuanA23fLgp9ZyEW3jF4Co0ejULY3FU4FeG6VDkOdtssIPG4lX2MLZHDIk+D5XwEKa Jy1imhwR8lq6PFFMycCKb0HbCTcyuaLgMQlWuHMcLuqn3QrI52u/mpqhUsgC3eYJcVSf zhhA== X-Gm-Message-State: AOJu0Yz/X7qVdhgUq1ZPlmBmNLK2nUw0pztbHwAlAz61hJ1SEGiSY6JP C70aey2cdfLY2leJlZjO3sMS4ePdslJbURM2MbGo0ggtulfq3xzoXgYTUmUwEo93wMNO8hyLbEN yGF3xQw== X-Google-Smtp-Source: AGHT+IEsGr2Zy7n0R7bbjDZUArLriAgHkZNMuMbcHl+0k1dHHS4YjF0m7exyRSYDGIHZOrNbiiOF0mkcHkoF X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:16c5:1feb:bf99:a5d1]) (user=irogers job=sendgmr) by 2002:a05:6902:2082:b0:dc2:48af:bef8 with SMTP id di2-20020a056902208200b00dc248afbef8mr974016ybb.10.1706761388272; Wed, 31 Jan 2024 20:23:08 -0800 (PST) Date: Wed, 31 Jan 2024 20:22:36 -0800 In-Reply-To: <20240201042236.1538928-1-irogers@google.com> Message-Id: <20240201042236.1538928-9-irogers@google.com> Mime-Version: 1.0 References: <20240201042236.1538928-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Subject: [PATCH v2 8/8] perf cpumap: Use perf_cpu_map__for_each_cpu when possible From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240131_202310_062425_424380CC X-CRM114-Status: GOOD ( 22.65 ) 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 Rather than manually iterating the CPU map, use perf_cpu_map__for_each_cpu. When possible tidy local variables. Signed-off-by: Ian Rogers Reviewed-by: James Clark --- tools/perf/arch/arm64/util/header.c | 10 ++-- tools/perf/tests/bitmap.c | 13 +++--- tools/perf/tests/topology.c | 46 +++++++++---------- tools/perf/util/bpf_kwork.c | 16 ++++--- tools/perf/util/bpf_kwork_top.c | 12 ++--- tools/perf/util/cpumap.c | 12 ++--- .../scripting-engines/trace-event-python.c | 12 +++-- tools/perf/util/session.c | 5 +- tools/perf/util/svghelper.c | 20 ++++---- 9 files changed, 72 insertions(+), 74 deletions(-) diff --git a/tools/perf/arch/arm64/util/header.c b/tools/perf/arch/arm64/util/header.c index a9de0b5187dd..741df3614a09 100644 --- a/tools/perf/arch/arm64/util/header.c +++ b/tools/perf/arch/arm64/util/header.c @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include #include #include "debug.h" @@ -19,18 +17,18 @@ static int _get_cpuid(char *buf, size_t sz, struct perf_cpu_map *cpus) { const char *sysfs = sysfs__mountpoint(); - int cpu; - int ret = EINVAL; + struct perf_cpu cpu; + int idx, ret = EINVAL; if (!sysfs || sz < MIDR_SIZE) return EINVAL; - for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { char path[PATH_MAX]; FILE *file; scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, - sysfs, RC_CHK_ACCESS(cpus)->map[cpu].cpu); + sysfs, cpu.cpu); file = fopen(path, "r"); if (!file) { diff --git a/tools/perf/tests/bitmap.c b/tools/perf/tests/bitmap.c index 0173f5402a35..98956e0e0765 100644 --- a/tools/perf/tests/bitmap.c +++ b/tools/perf/tests/bitmap.c @@ -11,18 +11,19 @@ static unsigned long *get_bitmap(const char *str, int nbits) { struct perf_cpu_map *map = perf_cpu_map__new(str); - unsigned long *bm = NULL; - int i; + unsigned long *bm; bm = bitmap_zalloc(nbits); if (map && bm) { - for (i = 0; i < perf_cpu_map__nr(map); i++) - __set_bit(perf_cpu_map__cpu(map, i).cpu, bm); + int i; + struct perf_cpu cpu; + + perf_cpu_map__for_each_cpu(cpu, i, map) + __set_bit(cpu.cpu, bm); } - if (map) - perf_cpu_map__put(map); + perf_cpu_map__put(map); return bm; } diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c index 2a842f53fbb5..a8cb5ba898ab 100644 --- a/tools/perf/tests/topology.c +++ b/tools/perf/tests/topology.c @@ -68,6 +68,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) }; int i; struct aggr_cpu_id id; + struct perf_cpu cpu; session = perf_session__new(&data, NULL); TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); @@ -113,8 +114,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++) { - struct perf_cpu cpu = { .cpu = i }; - + cpu.cpu = i; if (!perf_cpu_map__has(map, cpu)) continue; pr_debug("CPU %d, core %d, socket %d\n", i, @@ -123,48 +123,48 @@ 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 < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__cpu(cpu, NULL); TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", - perf_cpu_map__cpu(map, i).cpu == id.cpu.cpu); + cpu.cpu == id.cpu.cpu); TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].core_id == id.core); + session->header.env.cpu[cpu.cpu].core_id == id.core); TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id == id.die); + session->header.env.cpu[cpu.cpu].die_id == id.die); TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Cpu map - Thread IDX is set", id.thread_idx == -1); } // Test that core ID contains socket, die and core - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__core(cpu, NULL); TEST_ASSERT_VAL("Core map - Core ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].core_id == id.core); + session->header.env.cpu[cpu.cpu].core_id == id.core); TEST_ASSERT_VAL("Core map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Core map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id == id.die); + session->header.env.cpu[cpu.cpu].die_id == id.die); TEST_ASSERT_VAL("Core map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Core map - Thread IDX is set", id.thread_idx == -1); } // Test that die ID contains socket and die - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__die(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__die(cpu, NULL); TEST_ASSERT_VAL("Die map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Die map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id == id.die); + session->header.env.cpu[cpu.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); @@ -173,10 +173,10 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) } // Test that socket ID contains only socket - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__socket(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__socket(cpu, NULL); TEST_ASSERT_VAL("Socket map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id == + session->header.env.cpu[cpu.cpu].socket_id == id.socket); TEST_ASSERT_VAL("Socket map - Node ID is set", id.node == -1); @@ -187,10 +187,10 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) } // Test that node ID contains only node - for (i = 0; i < perf_cpu_map__nr(map); i++) { - id = aggr_cpu_id__node(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id = aggr_cpu_id__node(cpu, NULL); TEST_ASSERT_VAL("Node map - Node ID doesn't match", - cpu__get_node(perf_cpu_map__cpu(map, i)) == id.node); + cpu__get_node(cpu) == id.node); 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); diff --git a/tools/perf/util/bpf_kwork.c b/tools/perf/util/bpf_kwork.c index 6eb2c78fd7f4..44f0f708a15d 100644 --- a/tools/perf/util/bpf_kwork.c +++ b/tools/perf/util/bpf_kwork.c @@ -147,12 +147,12 @@ static bool valid_kwork_class_type(enum kwork_class_type type) static int setup_filters(struct perf_kwork *kwork) { - u8 val = 1; - int i, nr_cpus, key, fd; - struct perf_cpu_map *map; - if (kwork->cpu_list != NULL) { - fd = bpf_map__fd(skel->maps.perf_kwork_cpu_filter); + int idx, nr_cpus; + struct perf_cpu_map *map; + struct perf_cpu cpu; + int fd = bpf_map__fd(skel->maps.perf_kwork_cpu_filter); + if (fd < 0) { pr_debug("Invalid cpu filter fd\n"); return -1; @@ -165,8 +165,8 @@ static int setup_filters(struct perf_kwork *kwork) } nr_cpus = libbpf_num_possible_cpus(); - for (i = 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu = perf_cpu_map__cpu(map, i); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + u8 val = 1; if (cpu.cpu >= nr_cpus) { perf_cpu_map__put(map); @@ -181,6 +181,8 @@ static int setup_filters(struct perf_kwork *kwork) } if (kwork->profile_name != NULL) { + int key, fd; + if (strlen(kwork->profile_name) >= MAX_KWORKNAME) { pr_err("Requested name filter %s too large, limit to %d\n", kwork->profile_name, MAX_KWORKNAME - 1); diff --git a/tools/perf/util/bpf_kwork_top.c b/tools/perf/util/bpf_kwork_top.c index 035e02272790..22a3b00a1e23 100644 --- a/tools/perf/util/bpf_kwork_top.c +++ b/tools/perf/util/bpf_kwork_top.c @@ -122,11 +122,11 @@ static bool valid_kwork_class_type(enum kwork_class_type type) static int setup_filters(struct perf_kwork *kwork) { - u8 val = 1; - int i, nr_cpus, fd; - struct perf_cpu_map *map; - if (kwork->cpu_list) { + int idx, nr_cpus, fd; + struct perf_cpu_map *map; + struct perf_cpu cpu; + fd = bpf_map__fd(skel->maps.kwork_top_cpu_filter); if (fd < 0) { pr_debug("Invalid cpu filter fd\n"); @@ -140,8 +140,8 @@ static int setup_filters(struct perf_kwork *kwork) } nr_cpus = libbpf_num_possible_cpus(); - for (i = 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu = perf_cpu_map__cpu(map, i); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + u8 val = 1; if (cpu.cpu >= nr_cpus) { perf_cpu_map__put(map); diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 0581ee0fa5f2..e2287187babd 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -629,10 +629,10 @@ static char hex_char(unsigned char val) size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size) { - int i, cpu; + int idx; char *ptr = buf; unsigned char *bitmap; - struct perf_cpu last_cpu = perf_cpu_map__cpu(map, perf_cpu_map__nr(map) - 1); + struct perf_cpu c, last_cpu = perf_cpu_map__max(map); if (buf == NULL) return 0; @@ -643,12 +643,10 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size) return 0; } - for (i = 0; i < perf_cpu_map__nr(map); i++) { - cpu = perf_cpu_map__cpu(map, i).cpu; - bitmap[cpu / 8] |= 1 << (cpu % 8); - } + perf_cpu_map__for_each_cpu(c, idx, map) + bitmap[c.cpu / 8] |= 1 << (c.cpu % 8); - for (cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) { + for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) { unsigned char bits = bitmap[cpu / 8]; if (cpu % 8) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 860e1837ba96..8ef0e5ac03c2 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1693,13 +1693,15 @@ static void python_process_stat(struct perf_stat_config *config, { struct perf_thread_map *threads = counter->core.threads; struct perf_cpu_map *cpus = counter->core.cpus; - int cpu, thread; - for (thread = 0; thread < perf_thread_map__nr(threads); thread++) { - for (cpu = 0; cpu < perf_cpu_map__nr(cpus); cpu++) { - process_stat(counter, perf_cpu_map__cpu(cpus, cpu), + for (int thread = 0; thread < perf_thread_map__nr(threads); thread++) { + int idx; + struct perf_cpu cpu; + + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { + process_stat(counter, cpu, perf_thread_map__pid(threads, thread), tstamp, - perf_counts(counter->counts, cpu, thread)); + perf_counts(counter->counts, idx, thread)); } } } diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 199d3e8df315..d52b58344dbc 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2738,6 +2738,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, int i, err = -1; struct perf_cpu_map *map; int nr_cpus = min(session->header.env.nr_cpus_avail, MAX_NR_CPUS); + struct perf_cpu cpu; for (i = 0; i < PERF_TYPE_MAX; ++i) { struct evsel *evsel; @@ -2759,9 +2760,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, return -1; } - for (i = 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu = perf_cpu_map__cpu(map, i); - + perf_cpu_map__for_each_cpu(cpu, i, map) { if (cpu.cpu >= nr_cpus) { pr_err("Requested CPU %d too large. " "Consider raising MAX_NR_CPUS\n", cpu.cpu); diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c index 1892e9b6aa7f..2b04f47f4db0 100644 --- a/tools/perf/util/svghelper.c +++ b/tools/perf/util/svghelper.c @@ -725,26 +725,24 @@ static void scan_core_topology(int *map, struct topology *t, int nr_cpus) static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus) { - int i; - int ret = 0; - struct perf_cpu_map *m; - struct perf_cpu c; + int idx, ret = 0; + struct perf_cpu_map *map; + struct perf_cpu cpu; - m = perf_cpu_map__new(s); - if (!m) + map = perf_cpu_map__new(s); + if (!map) return -1; - for (i = 0; i < perf_cpu_map__nr(m); i++) { - c = perf_cpu_map__cpu(m, i); - if (c.cpu >= nr_cpus) { + perf_cpu_map__for_each_cpu(cpu, idx, map) { + if (cpu.cpu >= nr_cpus) { ret = -1; break; } - __set_bit(c.cpu, cpumask_bits(b)); + __set_bit(cpu.cpu, cpumask_bits(b)); } - perf_cpu_map__put(m); + perf_cpu_map__put(map); return ret; }