From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB0FA12D742 for ; Fri, 2 Feb 2024 23:41:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917274; cv=none; b=Q4GSlunXzKIEV77Cf8Jq3wIv3937/3xjrcpdsF9ZMaJI07AD0K47EP+OaELltPgl2wjWNnJMGezUa2zQqgq5PfO64YrD8z/3ameViIpOkMrtM0/6Zsi3jdZ1Edyh/OfF67C5lnPJ/G1mg5xj6XtJ+rJq2mTZ3iurZHWQiftj7Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917274; c=relaxed/simple; bh=5nIG5LyKHW7GTVpxwdG8LHaYQ9yDY/AHj79BA34oOvg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=l3bHyxCrUW63iQgj8w9tihCz0tzPZx5hiHz4eHb65bVqpcwvY9Lql5zVQtAlmOA1+Zm9FcVqOyJC8BYsAAvr/km3dy8eFjs4yrwBZCcKBfUhcF55Ud23/whyRptG0UE3N6q9YHBGEzqnfqJ6Ka/vfm0Lt6NRn/VwbWdUZh19jSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1RE9Oql0; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1RE9Oql0" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ee22efe5eeso45172277b3.3 for ; Fri, 02 Feb 2024 15:41:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917272; x=1707522072; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wSD742trI5qRJtx2AyB70ygbW0HL0IXuRRmpkhMUb0U=; b=1RE9Oql00b8bPBF3nUtfAXNGCQbTSxEVTWp1T12bs3BJpQiGm6DBZglgALGxC+P0nV ztrQK/V728stfHu8CfWoxgnRrIZIOjeVFjLFz3KWZk1suK5Uyw38d2wbATnGz1apj88W chYS/yULOLkaiHhgtNMLCy1StLX6ljs3/opYsz72tpFvW3hSs7votYj/WpgH6OkHfVWI lrSQEayy05D/htOuLZ8FDbLRcUspZTM28F6GGs/xwESLapxH5F7MUpkPhCgdAOZCNAO/ ASNFwH7I2Y6O17+85IxqbjPSKD3VjmQGYigjUdblyMKZ/NSIZ3QigkvpGhVc30y1MiIB NTlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917272; x=1707522072; 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=wSD742trI5qRJtx2AyB70ygbW0HL0IXuRRmpkhMUb0U=; b=SWBz/T8AHhgP4O6VaAwTwKhLabcR81q/kj0dUNFxSCEmMRbGrxR/fpZoNiTBgydmro lpKM66cKAASs5M5Zm3omFB1UTyUuMweQRR/lF/Uw9N6c31y746DZCmi8NRLfFdWamuTH Nmfwt8u0z1OYRi0408EeHY40keT9qF1L0u5KVUHQxefnOuKWylJ3TwSwTgbn22Rk3laG oChJjEhZVfKCvBB2J8QcJomp4KGygR1gdAI9acaxGGvRz3Q2jb1s2lta6sNUSEPWIWe3 Ij9bE9GoXB+r1OAdbAldbQARO2ucrI0DsJDTK3nqXu1d2Hl9FbYCE9VCompCi7Pxy7pC Vn2A== X-Gm-Message-State: AOJu0YziWGDvJbtGGavsGR1Pf+owURLnJAox46x69Wxa75WcW0T6wBmT WuVanPC7ddyDhcOH/UM1X3hKufgaHAWiODUEPvcX0uut9RcFsRiSDmEAejB+ZfCB9AFHBlDwV5F puCuNiA== X-Google-Smtp-Source: AGHT+IFpfQ/GB+TYId1WD/szhEjcveN+IJCbuqBsttndI2uyVlYhHJ+PI+A6jwtdVpkd6bSuixIHY+dBTIMG X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:690c:19:b0:600:2492:f962 with SMTP id bc25-20020a05690c001900b006002492f962mr1161790ywb.8.1706917271761; Fri, 02 Feb 2024 15:41:11 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:50 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-2-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Additional helpers to better replace perf_cpu_map__has_any_cpu_or_is_empty. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- 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 struc= t perf_cpu_map *map) return map ? __perf_cpu_map__cpu(map, 0).cpu =3D=3D -1 : true; } =20 +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) =3D=3D 1 && __perf_cpu_map__cpu(map, 0).cp= u =3D=3D -1; +} + +bool perf_cpu_map__is_empty(const struct perf_cpu_map *map) +{ + return map =3D=3D 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_m= ap *map) return map && __perf_cpu_map__cpu(map, 0).cpu =3D=3D -1; } =20 +struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *map) +{ + struct perf_cpu cpu, result =3D { + .cpu =3D -1 + }; + int idx; + + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, map) { + result =3D cpu; + break; + } + return result; +} + struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *map) { struct perf_cpu result =3D { 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_m= ap *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_c= pu_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_cp= u_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 "a= ny CPU"/dummy value. + */ +LIBPERF_API struct perf_cpu perf_cpu_map__min(const struct perf_cpu_map *m= ap); +/** + * perf_cpu_map__max - the maximum CPU value or -1 if empty or just the "a= ny CPU"/dummy value. + */ LIBPERF_API struct perf_cpu perf_cpu_map__max(const struct perf_cpu_map *m= ap); 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; --=20 2.43.0.594.gd9cf4e227d-goog From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CA9212D779 for ; Fri, 2 Feb 2024 23:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917277; cv=none; b=q8i2BwUoUuwPQdVM4q+GQygAFM+SPdcudjqE/70YYDPd/Dg5nRKaqLSwf91Xmfu/5G2rSkHYfupsIHc/0woUyx8qbUG6ViNVUaU3BW4/cGB6rz4cPgGaXsNdGxhWH+fsNzfKJw0b+UpxeEIIWsQiPFaz03bZdxlaMtBLclZPCLQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917277; c=relaxed/simple; bh=R7HDLt+WXCKcw0UAraBcZnWD54QthkXyaQu13uOf35M=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JH+fbjxihsSQWLtf2SaB2TxVc/f1s4Ezf/vcNnocDD+ojPf/md3AXWjAl4ThngaKwdLOyuiNDy7GvS2+P/wGvsCr8bNF4pagm48Dm7vHaJ1SPe/afZrVkiRXwCeQWE7yPrAMZfz5+ee4Pn220g3/srRwHV9pgvWxsJL9yBbtRnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AyrvHKJj; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AyrvHKJj" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b9f4a513so4065541276.3 for ; Fri, 02 Feb 2024 15:41:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917274; x=1707522074; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wOc7/ot5clrlqkd/XVVApb41eylij+dgoGLfSlWPOp0=; b=AyrvHKJjjXcpTnTw4Q1Oh72rOi5vJrbZ3NSKSgFRcmHrdQ9urAxqzaDeeAWfqmw1CL V2OIprdiY9MJ0htwTWHjbjukLdw7GmjOkyqarwZWfqn2/8Nov6Ocp/QbJOAyaHPZqEhv hziwunHjYpud1MfPnxCijqL4At/8TCLcXP3ITG/sHjJf5dLMZBDCWVnSsVuJpt8WizXl wZDeqrqXusMSV10naS2Ovb/WYhlAqQRr2Xtbkc0txIShOu29QlZQm42MK7Ezu4CBW1H2 OxpzDQzCpQwQLEealrpbXlNFI9Pleu4GOdpHUI3AnJSzmnPwCCL/ker674WkFBkQGxwz OW2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917274; x=1707522074; 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=wOc7/ot5clrlqkd/XVVApb41eylij+dgoGLfSlWPOp0=; b=s0CHHmfWSUx/vLlekIpxwyw2nm3WhU1a0InuFyvicCZnvj0QCfxNoJ9Zmz/6HTFEbS q8cBTXxMK+uigQp6fohlY7xUVvDETdQ0OBGy9ZZIOmHdrY8fYnMh4jArljW0Xb36mVgA BbT/5ck7YKsHhEo8F6FzZrjk2XL/yvvnoQt2I7EbyNjX6m7O6BjNPCLGSNP2seTB7UpF s5PPNANemFd2qD3nHld0OM47BKaR9M/XOTJjlhlwWNjJBPlyq5Unx7m8wTBVxh9vm9sh XAyMAe9Ki4vnjqN0wkcWw83QmLQJ997BSIp8qXKtqxsNt4AHAaeSVddjWfAReX/wrwK/ hKYg== X-Gm-Message-State: AOJu0Yw1veCrCusjYhRQDA8GBA2mm66YBIHSRPXT+KcAEJz5IB9+CZSx uJnxMWkqqMV6hLMQOpGCvyhzsA/79kBOxlcpbsFZ8qS+K0vXsdRssycsuSnMyWaLux4UWGOKf/S R1hQlDA== X-Google-Smtp-Source: AGHT+IHFL6+6WJT+TDjsN0v4AycgXqtEdFuE4PFoyenBnNnNjcCA2pFf3NUeukXxzibAja4cMAtIanSVNF3E X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:1b08:b0:dc2:398d:a671 with SMTP id eh8-20020a0569021b0800b00dc2398da671mr1024554ybb.10.1706917274174; Fri, 02 Feb 2024 15:41:14 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:51 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-3-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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@a= rm.com/ Signed-off-by: Ian Rogers Acked-by: Namhyung Kim --- 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) =20 struct perf_cpu_map *perf_cpu_map__alloc(int nr_cpus) { - RC_STRUCT(perf_cpu_map) *cpus =3D malloc(sizeof(*cpus) + sizeof(struct pe= rf_cpu) * nr_cpus); + RC_STRUCT(perf_cpu_map) *cpus; struct perf_cpu_map *result; =20 + if (nr_cpus =3D=3D 0) + return NULL; + + cpus =3D malloc(sizeof(*cpus) + sizeof(struct perf_cpu) * nr_cpus); if (ADD_RC_CHK(result, cpus)) { cpus->nr =3D nr_cpus; refcount_set(&cpus->refcnt, 1); --=20 2.43.0.594.gd9cf4e227d-goog From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C46C12F38C for ; Fri, 2 Feb 2024 23:41:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917279; cv=none; b=pk3MTd45rgugQ9fhcGdXovx4sj0A6qFMJWjkrWaNNmDQQyW7jCJJejMR4r2YSeugPb7b6uezDBuUSzWoVaYw1X3Gg+S0hoQdT4VL8Q0t5Jd0K4Pw2mW6pW9O8ynokroqj5JOope+1oF0zQbpWzVEQYPoC4Yv+GqliZAHhOlzRXI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917279; c=relaxed/simple; bh=2CEX69l8jHviwD08AVVrjec2O+3gxN5VKnRqORpifeQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MchgCXk4d5rH746gdBKdg3fffxDUwGToXCKlX4dQTr5BNkv6N4gkNUsfF0xTAaDLjKze5BUAY7ZwaB4ceYErVbBBqEq2L/FQFhMQaR/FEqkiS9sVOPX9FZsbtuRCo2QDrmFSDudyY1WDZg940dgOQcCysszO0+KtrCxyFBUWwJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Q2SurpQR; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q2SurpQR" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc3645a6790so4709056276.0 for ; Fri, 02 Feb 2024 15:41:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917276; x=1707522076; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Xzvhj+a0qyhqfnlkJlD6nNip1T9+Dz0mvAMEktGGdDs=; b=Q2SurpQRaQR+Y1ACtUW51Dydq5v+1OzPqkkPVLGHwTb717kWrZcZfvskPLtNK/MhLU n1o+FZ5aOx9PFmqJBzmUBKJBCU9L1XQtaZg7mkx+CWCD9R2uzO4Jx7Ck+xvCkq3na/EY h9eBZQtGcZjsCWJ7HF2HFeteZTucJ++HtL79fNMqU5JdcZnij8i/wUqB44at2bvUzJVx BQ5eptnmMoCBQmlC7XR+o+o1WcaGq2/6ppJh8Xg07JNteT0AA/wYWKwhfhnc1PEM+mG5 Z1l/L2AKBdjdg3r4Y52zKLvSeT43gSbNGqfB3LBmbKU2CCLWwEVjPjt+LS/M/+H2HMmF Igng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917276; x=1707522076; 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=Xzvhj+a0qyhqfnlkJlD6nNip1T9+Dz0mvAMEktGGdDs=; b=xMJmc5Gg0MA55go3kSY5IzUgUcAuu3jMVzGSafP9WAUIcKivdYO4W5j57htncMe+ws 7CiK9zD98HpLbbCTsQ8FddLO7ooyTJSwqUxW1nONAz18U+bL/YRo2P/mrRc0zSx1Y4zG 3QpV+dL3VatdD1UJVeNvLKN/JnzqYMXOmW3GtdEQUkoWSWvMw4xjK7iwX3DnYI0lrA4P ex6++djptYlSL8pdOC/1ARb8WZsTWSYtu4AS5H8ylpWYH3hWryyYl8FAM5njlikjZPVE sEsNqlYkhBh9hWlzJTe70obquTGcb2kJy1qAmATFxGiyODnHAhpPwv9vXqDnF8fCZCAH JBEQ== X-Gm-Message-State: AOJu0Yw2wXozvnJ7/TOAOQ5tpXccCv09Q+pqxh1VaynXicg0R/r8e99E 8h/olUSFM/jlnU/TA38pWzRzPd20TwBvFA9mrd3HxONj5xt7oPWLXN97PxLRWV7JIOwSSiwEBTZ VMq4XFA== X-Google-Smtp-Source: AGHT+IH1P3pzKL0QWpOjxn7DF+fg6zdcOTDx/JJDNSMOI0pZaXnlYiFdp7LpbTqNMeVndnj73uZ3TS4lpO3f X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:138e:b0:dc2:1cd6:346e with SMTP id x14-20020a056902138e00b00dc21cd6346emr2454938ybu.8.1706917276279; Fri, 02 Feb 2024 15:41:16 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:52 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-4-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 taking care for when "any" CPU is specified. Switch perf_cpu_map__has_any_cpu_or_is_empty to more appropriate alternatives. Signed-off-by: Ian Rogers Acked-by: Namhyung Kim Reviewed-by: James Clark --- tools/perf/arch/arm/util/cs-etm.c | 114 ++++++++++++--------------- tools/perf/arch/arm64/util/arm-spe.c | 4 +- 2 files changed, 51 insertions(+), 67 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/c= s-etm.c index 77e6663c1703..07be32d99805 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -197,38 +197,37 @@ 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 =3D -EINVAL; + int idx, err =3D 0; struct perf_cpu_map *event_cpus =3D evsel->evlist->core.user_requested_cp= us; - struct perf_cpu_map *online_cpus =3D perf_cpu_map__new_online_cpus(); - - /* Set option of each CPU we have */ - for (i =3D 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu =3D { .cpu =3D i, }; + struct perf_cpu_map *intersect_cpus; + struct perf_cpu cpu; =20 - /* - * 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; + /* + * 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 has the "any" + * CPU value. Since the traced program can run on any CPUs in this case, + * thus don't skip validation. + */ + if (!perf_cpu_map__has_any_cpu(event_cpus)) { + struct perf_cpu_map *online_cpus =3D perf_cpu_map__new_online_cpus(); =20 - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; + intersect_cpus =3D perf_cpu_map__intersect(event_cpus, online_cpus); + perf_cpu_map__put(online_cpus); + } else { + intersect_cpus =3D perf_cpu_map__new_online_cpus(); + } =20 - err =3D cs_etm_validate_context_id(itr, evsel, i); + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { + err =3D cs_etm_validate_context_id(itr, evsel, cpu.cpu); if (err) - goto out; - err =3D cs_etm_validate_timestamp(itr, evsel, i); + break; + + err =3D cs_etm_validate_timestamp(itr, evsel, cpu.cpu); if (err) - goto out; + break; } =20 - err =3D 0; -out: - perf_cpu_map__put(online_cpus); + perf_cpu_map__put(intersect_cpus); return err; } =20 @@ -435,7 +434,7 @@ static int cs_etm_recording_options(struct auxtrace_rec= ord *itr, * Also the case of per-cpu mmaps, need the contextID in order to be noti= fied * 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 +460,7 @@ static int cs_etm_recording_options(struct auxtrace_rec= ord *itr, evsel->core.attr.sample_period =3D 1; =20 /* 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); =20 err =3D cs_etm_validate_config(itr, cs_etm_evsel); @@ -533,45 +532,31 @@ 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 =3D 0, etmv4 =3D 0, ete =3D 0; struct perf_cpu_map *event_cpus =3D evlist->core.user_requested_cpus; - struct perf_cpu_map *online_cpus =3D perf_cpu_map__new_online_cpus(); - - /* 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 =3D 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu =3D { .cpu =3D i, }; + struct perf_cpu_map *intersect_cpus; + struct perf_cpu cpu; =20 - if (!perf_cpu_map__has(event_cpus, cpu) || - !perf_cpu_map__has(online_cpus, cpu)) - continue; + if (!perf_cpu_map__has_any_cpu(event_cpus)) { + /* cpu map is not "any" CPU , we have specific CPUs to work with */ + struct perf_cpu_map *online_cpus =3D perf_cpu_map__new_online_cpus(); =20 - if (cs_etm_is_ete(itr, i)) - ete++; - else if (cs_etm_is_etmv4(itr, i)) - etmv4++; - else - etmv3++; - } + intersect_cpus =3D perf_cpu_map__intersect(event_cpus, online_cpus); + perf_cpu_map__put(online_cpus); } else { - /* get configuration for all CPUs in the system */ - for (i =3D 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu =3D { .cpu =3D i, }; - - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; - - if (cs_etm_is_ete(itr, i)) - ete++; - else if (cs_etm_is_etmv4(itr, i)) - etmv4++; - else - etmv3++; - } + /* Event can be "any" CPU so count all online CPUs. */ + intersect_cpus =3D perf_cpu_map__new_online_cpus(); } - - perf_cpu_map__put(online_cpus); + 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, cpu.cpu)) + etmv4++; + else + etmv3++; + } + perf_cpu_map__put(intersect_cpus); =20 return (CS_ETM_HEADER_SIZE + (ete * CS_ETE_PRIV_SIZE) + @@ -813,16 +798,15 @@ static int cs_etm_info_fill(struct auxtrace_record *i= tr, if (!session->evlist->core.nr_mmaps) return -EINVAL; =20 - /* If the cpu_map is empty all online CPUs are involved */ - if (perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { + /* If the cpu_map has the "any" CPU all online CPUs are involved */ + if (perf_cpu_map__has_any_cpu(event_cpus)) { cpu_map =3D online_cpus; } else { /* Make sure all specified CPUs are online */ - for (i =3D 0; i < perf_cpu_map__nr(event_cpus); i++) { - struct perf_cpu cpu =3D { .cpu =3D i, }; + struct perf_cpu cpu; =20 - 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; } =20 diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/u= til/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_re= cord *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_re= cord *itr, tracking_evsel->core.attr.sample_period =3D 1; =20 /* 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); =20 --=20 2.43.0.594.gd9cf4e227d-goog From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 800CF130AD0 for ; Fri, 2 Feb 2024 23:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917281; cv=none; b=ujS+kMvM66pKUbMRrdXLu1COCGa+2RQcSTG/z5rra5QwpitrQ159IZveX68zobm+FBH+4duR+3KsoxmPsp+VRRkuziMsIIrPfgRZ618IfSBZPhpmZQHLpnGWJKn2whjFNMIinau7UWzElbT9Is2BwWMkgIDgfhqcVY9UW0zQV9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917281; c=relaxed/simple; bh=vrKD5r788IsBMcWd7p/Y0rFlE9n9DwipYIJHOz74tOw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=F39gbAn2DDa6VQGl7Ogphkov2BlVzW9Hznv8e0EgWvXjfpNDtW6iIEipmk5q3nunwBg9MjCnhYQYS3rQnOXSVkcSmDpwBdGPQIR+ELtsw0TLAAPh44XgpbPILZBvl90W5MmshmSXhNLQZ70GA1z199vCmAlZYN1ZdDZuMcCvtHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=4w0kFDQh; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="4w0kFDQh" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5ee22efe5eeso45173697b3.3 for ; Fri, 02 Feb 2024 15:41:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917278; x=1707522078; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=wr65K6vWppDQ/+c7LXR1fsKtLh163OjTy8d5391wuIk=; b=4w0kFDQhOhQz0WvuFPLIj+zyJzPgZ2QMlZ8lOM2cYWh6Z4Ij6FGdLBiXomLeP0p71c DA/VgJmxdEYjbM45a1wHLR1NS3uNSD1HcXFzNRby4Z5vUmGTVEwz3bkjCY3wUSEr8rQU w+UZk3cT0KO9U80IG7izxhul43cDXV94QRsCXmCZvr8cseO4t7p5445D+s2YJji64eWt cueuLaf1fo3+B/IlixcdhaF2bLIT88OWgL+1Y3HCIQHgPOGZBeO/sEo+ShO/n91sV0DQ EqCSpaIRpEloNRKb8nYA/9DdeiGhuv/gTENpBB+eKYcqnQ7+QmQSUAHTAm+B5zVmzasB MLUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917278; x=1707522078; 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=wr65K6vWppDQ/+c7LXR1fsKtLh163OjTy8d5391wuIk=; b=Ks2U58cGoNxbM7CzV0tRV44pEeVYHIf9BcZeNOwXNAi1kXyCoqfWTg8K7NtEWxhmPH KQTKVgd3uq5nPk0cOW6aQRFaa2N65x6U/OJfuOo3G80cIxglrcDuN3+wTWG8ZUI6sk4m D/nlOyaWk7Wf5iLpYKtWsQXoh2ed2l4Indn4+Zcj47y4QOeIrzW97uL0nrXCBLjW+cjF lFJvgv9gbiBo/+ZUravHB8nc7e081ykBBbvWKop/7k0x20mBnrbbrvOZvRIcOCfqeZWI F9pnm6zo/HFw88QOzi41NVqVMTTiWie/Bih8+yQzSE500ZuMd+YOrPjKHRGkUbo6K67M kzzA== X-Gm-Message-State: AOJu0Yxy7tJ8R+VTo9PjPOB7jxl/Fj0YCm3aQ4kQQqBCCGPb40IGofzJ MhnrbJD9IH84ys2Y/6Lgy7VsYeo2MrVWAwbbAqQVr8wHiuczy93UYw2gPP/z0pvK9k8NwPV1mYZ tPG968A== X-Google-Smtp-Source: AGHT+IGiumDXxsvYIccaz3gyylhqySyEc2Gp6C4lsSrfI9fwfZwbahfbAwRGdXwWOlR7Ts4vtw193bh3ieUX X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:690c:f8d:b0:5ff:b07b:fb83 with SMTP id df13-20020a05690c0f8d00b005ffb07bfb83mr1162438ywb.4.1706917278493; Fri, 02 Feb 2024 15:41:18 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:53 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-5-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Namhyung Kim --- 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/uti= l/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; =20 - 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); } =20 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 *i= tr, ui__warning("Intel Processor Trace: TSC not available\n"); } =20 - per_cpu_mmaps =3D !perf_cpu_map__has_any_cpu_or_is_empty(session->evlist-= >core.user_requested_cpus); + per_cpu_mmaps =3D !perf_cpu_map__is_any_cpu_or_is_empty(session->evlist->= core.user_requested_cpus); =20 auxtrace_info->type =3D PERF_AUXTRACE_INTEL_PT; auxtrace_info->priv[INTEL_PT_PMU_TYPE] =3D intel_pt_pmu->type; @@ -774,7 +774,7 @@ static int intel_pt_recording_options(struct auxtrace_r= ecord *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 =3D !target__none(&opts->target) && @@ -832,7 +832,7 @@ static int intel_pt_recording_options(struct auxtrace_r= ecord *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); } =20 @@ -858,7 +858,7 @@ static int intel_pt_recording_options(struct auxtrace_r= ecord *itr, tracking_evsel->immediate =3D true; =20 /* 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_r= ecord *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(cpu= s) && + 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"); --=20 2.43.0.594.gd9cf4e227d-goog From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C0E53130AF2 for ; Fri, 2 Feb 2024 23:41:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917283; cv=none; b=Drct7RqBXuicnBw7sBcKTNTeakDYm05wYBD8+k071ihzoUGheFMXCk9yZTt6yis6gFYZxN6/RyvGLABT8uHTiN7GlDMjZDt+YXFx6dtADoUGFexqOsMKUqjD3ar+2dyEumgVT8DzhbpZWpX5JedUR/VbWe5Qj9I8lNJygVCwtXM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917283; c=relaxed/simple; bh=TXC4fY94F4QG3R5rAXB5MKDuVhvys01fhTTOf+9TuDM=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=MjNbVMywgfqJ9LSTHKtNUxeBm0VDZwjh4ocVqygFBJ/htOvHj7Haz8Ac0lPElod0mZsRaGftS8rsnh5uQlJPRUMbn8tYIIWPyNVZGoMFwTedbNxRTGd8+Ka8xWshsj8TMZOK6McG2BFgfjFKlZifjdnRhtD37+xbMdwgo3Vb/h0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=sMuuW/oA; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sMuuW/oA" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc64f63d768so4754962276.2 for ; Fri, 02 Feb 2024 15:41:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917281; x=1707522081; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=9PKn59qI/eEru2iRWjl8r3A2NQszSA8YlNSVgwlBz0k=; b=sMuuW/oAwOEVa93y3Ljf4HwsW9FKQ/j+oHFKLOuY1zE1iGOnRqhmjnRRaE4Z8jwLR3 gEQcjNhVLPW1yyMJWUR9nnCwtNM1m8j9Q6zssgfYlyUWfiC7mEo2LyLETLlD/dU0kqhO ejm/n+48PbiQFl4x9qw9MB73KRCtRZJZ8A8q2kzTUwZr06x7IyiWJPjJAi9XbbssnAYz JmqupUkqXZy52FfPvWgUSeqAddd5T9PmV8fiH8wwTV1VyiQKNaK5hnkd+hEc2tovNRhO ifi4wFsNI43STWImWgqqeBtMCdXi2saFTZ4DT1sEVa4E2GhDd/VzKPWLOOv5bloQu7+o zo9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917281; x=1707522081; 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=9PKn59qI/eEru2iRWjl8r3A2NQszSA8YlNSVgwlBz0k=; b=e1mTl/WwXSNiAuk5GfFs9CxyUEDciOhnLwcu4xSekOU6KDdyvZ362O4Oacas1NDxxD /+cPuFkGo2Op1+z0IJmjAz85X4vOu+GW1Vktyn/Ylzn/mdGJVjtd5/t7CrypmMT/How8 UqzE4NsQ3BCLr4zUuXHFqqopLr/UbkO/v23P3AzzHODfEFZAfqzkgDAqxMji8jc9NG+2 bNnjAc6Ti5WmcbKkRUv5OlHnVGs0xDntXYTHSIWewHJNlPMOV3JmqgEU7EHIR+0cUxKw NNUPgtALy9W6LJBiGPjSLh9SLLX9u5iICvEeSAVtyXNNQt+TS+215fPDcHi+Pt/VuoYY lVhg== X-Gm-Message-State: AOJu0YyV6SaGw6m9PIPsAJYVtQaOjk9Vhl20FBGUuQ9v48wDly3F5Pmv RFCYF/Ezj/Ax770KAqP8tKzmx9sHZR49MwbqUmnvkjEOIBPOJ3+5StljvlOmU2CSYWdieDrhsAa ROoqFCQ== X-Google-Smtp-Source: AGHT+IHWmLxSFYG5o2YfD0f8kFtxG69QWwfC87vLwnlWGI5t07xlvynFj+vFP0PXcxWx19/9iJha3k0Bf84P X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:2512:b0:dc2:1dd0:c517 with SMTP id dt18-20020a056902251200b00dc21dd0c517mr2454050ybb.7.1706917280766; Fri, 02 Feb 2024 15:41:20 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:54 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-6-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Namhyung Kim --- 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) =20 nodes[node] =3D set; =20 - /* 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); =20 if (WARN_ONCE(cpu2node[cpu.cpu] !=3D -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_cp= u 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 =3D perf_cpu_map__min(cpu_map).cpu; + if (id =3D=3D -1) id =3D cpu.cpu; - else - id =3D perf_cpu_map__cpu(cpu_map, 0).cpu; =20 /* 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_requeste= d_cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(evsel_list->core.user_requested= _cpus)) nr =3D perf_cpu_map__max(evsel_list->core.user_requested_cpus).cpu; else nr =3D 0; @@ -2290,7 +2289,7 @@ int process_stat_config_event(struct perf_session *se= ssion, =20 perf_event__read_stat_config(&stat_config, &event->stat_config); =20 - if (perf_cpu_map__has_any_cpu_or_is_empty(st->cpus)) { + if (perf_cpu_map__is_empty(st->cpus)) { if (st->aggr_mode !=3D AGGR_UNSET) pr_warning("warning: processing task data, aggregation mode not set\n"); } else if (st->aggr_mode !=3D 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 =3D !perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user= _requested_cpus); + bool per_cpu =3D !perf_cpu_map__has_any_cpu(evlist->core.user_requested_c= pus); =20 mp->mmap_needed =3D evsel->needs_auxtrace_mmap; =20 @@ -648,7 +648,7 @@ int auxtrace_parse_snapshot_options(struct auxtrace_rec= ord *itr, =20 static int evlist__enable_event_idx(struct evlist *evlist, struct evsel *e= vsel, int idx) { - bool per_cpu_mmaps =3D !perf_cpu_map__has_any_cpu_or_is_empty(evlist->cor= e.user_requested_cpus); + bool per_cpu_mmaps =3D !perf_cpu_map__has_any_cpu(evlist->core.user_reque= sted_cpus); =20 if (per_cpu_mmaps) { struct perf_cpu evlist_cpu =3D 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, co= nst char *str) =20 evsel =3D evlist__last(temp_evlist); =20 - if (!evlist || perf_cpu_map__has_any_cpu_or_is_empty(evlist->core.user_re= quested_cpus)) { + if (!evlist || perf_cpu_map__is_any_cpu_or_is_empty(evlist->core.user_req= uested_cpus)) { struct perf_cpu_map *cpus =3D perf_cpu_map__new_online_cpus(); =20 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; =20 - if (perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (perf_cpu_map__is_any_cpu_or_is_empty(cpus)) return 0; =20 if (!mask) { --=20 2.43.0.594.gd9cf4e227d-goog From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06493132476 for ; Fri, 2 Feb 2024 23:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917285; cv=none; b=Qn9cUdApkxvUi5OiqCJzivZhteXs2kz+O44AognBn0nw2mNuRAE3SZurFU0CPWzfE62RzxFp6DnWrLXGVc092jnsGOMOCzpq4B1wQLWiK2uWCuakox2ak/FK3l6h+LiQECT7Tzt83bfiUnXzJBZangI18jp5rBuHhcMDXCwZnN8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917285; c=relaxed/simple; bh=0FiaP31PDhjVbhEu1bCl/SbTIvgKTkMX5fOyfQItO7k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=cPdlq5ZfeuXRqUfHCzv8JfHd7EOfZ+lADlR10213G1ZLeGPdOOuVZDr7ujuQkcpnOkX10RMVE85sqMgxYd6ZKl4C9VxuCqXgM/LtM5rxaQxwZP7zauu0y9wsRh7IhJTVRo/ZH7aM4ldWDpvQRr/X5Dur/vQOgIhOWZtnLSrs7WM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=xcg4W7LX; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xcg4W7LX" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6041dbb7a78so40617437b3.0 for ; Fri, 02 Feb 2024 15:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917283; x=1707522083; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Jm6+rGnwaR5/dop0r40XD+HXuvjfQ9BLsYsO2f1XDQM=; b=xcg4W7LXC/Lm4VGyXDbJWnjemFnNierLSmeKZwGDaq3FvGbLOZhjL6RBHwSmrdg4LN 4J/YBgwjz3bsuDcyhPgpfadd5FHgi9N4n5s/f2wq5JNeVjpZuA6HhlGVvNAmOHG4ss2v 2h6xH4iBi4gCpxIRixZVuXLwUGNIYdeDf9Q7hXNnlDlouj/WdZKoHZhgnuuG8BjnxU7l cASRrINfBVW5Yhob+Ry4VRjch4EP2OdQAI1+4ZrcY+ngfS1xjJXTIYJoAPbevkdWeAqp 1WF1sk3zSgoBMJfV7/jT/PSA4p8XTVayJ+EkOCCyPrY8MWn7L7+u3C9qQilaklEgpf6f g2pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917283; x=1707522083; 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=Jm6+rGnwaR5/dop0r40XD+HXuvjfQ9BLsYsO2f1XDQM=; b=QgnbzoZwVmE3v63aLuXx07oQLYZI2FuDBPz80uD+FM1HSy9PYpEvM5ODvxpbW/Dvjz sbTG6bIr0WskZrZRNNN5LeyM5xvxQDjlYKOK5oiY598GfZPh1ik70zl0aWQAIU7eOXG9 MHhR5E/SH8N6sDSjD12lVh1ITYZfCtHeelKHnQLtZExYE/qOyhYAr5fQ786xCfau/VYI ejYDFH2NrtyyRvJd64kN6tNpqVy8sRVCTS4aLUsFX5148SmidA2GGrjQzuZ+yZxtmGy8 Y4E7ZpV0ugyhNmigfOpMdseo5SQTk4ecu0skAYSGWye24BTu4VD0DFF3ekSsGfwX9crf jGrA== X-Gm-Message-State: AOJu0YxHkgSDCPMbXHqCMzkHOcnJ42cg+Bay9N6wUjpGB3SwIHS3L0ex yknLSdq6jr9rwS0krHGXz7ME949Xlv+CavYCC4Txmeu8irhVREVokBNohWqylnNq1sEMNHpFjLm KkY4KMg== X-Google-Smtp-Source: AGHT+IEIf9VK/cffpyCYFMB/1zS7sPl9WTUUnXn9QcSaGnk7G6TAqWm/KHwq9Yo8DYBPsZvSFAYyXv5pPTH8 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a81:994c:0:b0:5ff:dac0:6524 with SMTP id q73-20020a81994c000000b005ffdac06524mr2160038ywg.3.1706917283080; Fri, 02 Feb 2024 15:41:23 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:55 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Namhyung Kim --- 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/ut= il/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_c= pu_map *cpus) if (!sysfs || sz < MIDR_SIZE) return EINVAL; =20 - cpus =3D perf_cpu_map__get(cpus); - for (cpu =3D 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_c= pu_map *cpus) break; } =20 - perf_cpu_map__put(cpus); return ret; } =20 --=20 2.43.0.594.gd9cf4e227d-goog From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1FE4A13329F for ; Fri, 2 Feb 2024 23:41:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917287; cv=none; b=u1MK03Mp4v+Ht6Qo3BWw71NxM9RAOFVa5wHAEowuTm+RiFE+6RIshpYdYj9FD8W/tn7ERsvWZ+ueQayUe7jP4Upb2Lg9+AulM7Gn4ke/tgKv2s0dcLE+KJDeb1fqaY0bRr4kmg5jmKWoIHKnEPtGPgx+baY2J9jiqfV2Iavr7Ro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917287; c=relaxed/simple; bh=ML8a9VBGcxJuZQepK7vQffZ+xRnwx4f8S25ZVo2Pqug=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=g62YuHiUO8hVo1BUpCe+9fV2ZDyT4PLT7znVbKLtS19lvOTwfwuNRiOLTsojJx1iFjZSVVK5w5miAZ8UE0Wshad/1aqyw8V+0TPZFAWevgoNplnWUCmEoQvfpgbryHl37FjSddCy3Shbrq21rf9z4Idi+IgAyjLRxh7coV9xFYI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=rs1AoA1s; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="rs1AoA1s" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-603c0e020a6so39111077b3.0 for ; Fri, 02 Feb 2024 15:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917285; x=1707522085; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=TiTDOvBVexFioWtZi7idM6N1b6RuopqNxCQfkxi6/RE=; b=rs1AoA1sMgUgRfo019U4kngZCVdoq/iho4cU6+aGabvBnBWzaZCvru9y4Sg20/ISzP TnyyjgvBkfR5OdtjfFX4pyHoOJKdhORc9lK7iXe1lCr3YyXBEuGxGp3F4tbonGoN5cAA NVdq4J73jzcpbC9VzgYZ5sluqWEdZWO5HfVB8aDzjPiBd5uF2+nFYSaABd1ZgCyvFdVD 42b4EDJW3JKSDfPanU1ZjL6KbjC7hasxHnCKG3elkFUiOkRvhMW60N+Ta4iRJhO9y8fc 5aGTAlW2H5+469+wYepYDM4j+C+cI6mK3lM5bMH14TXqL4tDITzytRDODjcJFmjs2has M3Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917285; x=1707522085; 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=TiTDOvBVexFioWtZi7idM6N1b6RuopqNxCQfkxi6/RE=; b=kB14sIwASZuD5XeGbWBQKcWhHNkwmLT5Kx5GscNSkgdaQY77OOixr9STTt37YyFP1k UjH9jwqUNJKwA5jJNyH4lA/zOeTA+k7rh67tHDkmH5nhropfyAClncUyLHZDFRVI3GTH MjfSaz+4b5yP8TH/ufrM6NBr92sIvsHK91HtoUM5CyfX+fBGKEw5nhfuEUtP6mQYq6pa xfO0nKWivBkZo89zmh52jseDp09YlABI8lJAMGYcNWA22jGF9d8LD/esh17zPjzbar5S MfUqbjzZH+Ux676CO55x3WdEVV5YJwOgva6PVNH2pQVf/l5cO62Fa4inuOdxOMEXYCkC YvEg== X-Gm-Message-State: AOJu0Yzeh82uyLVxRRXAoglML0PTZxOzcESomX/uiQPSpekPz5nasuJ2 Is9WnzKjypHRkVUnGq9JtSRwGntFsOzbNI9QtyS2G4Z6CXOKjG7vEh66nhJJd6l7HxHSK+Z28V1 vFnTOzQ== X-Google-Smtp-Source: AGHT+IFC29Z279Ff/N0YDvDBynRGWs9YKG/N71yuGRqZ0vDb73/HoBrgLOta7fz6IgJNl/gCwXQX0m26WJMv X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a81:9b4b:0:b0:5ff:6041:c17d with SMTP id s72-20020a819b4b000000b005ff6041c17dmr1156128ywg.2.1706917285199; Fri, 02 Feb 2024 15:41:25 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:56 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-8-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Use libperf's perf_cpu_map__equal that performs the same function. Signed-off-by: Ian Rogers Reviewed-by: James Clark Acked-by: Namhyung Kim --- 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 =3D { .iostat_run =3D false, }; =20 -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) !=3D perf_cpu_map__nr(b->core.cpus)) - return false; - - for (int i =3D 0; i < perf_cpu_map__nr(a->core.cpus); i++) { - if (perf_cpu_map__cpu(a->core.cpus, i).cpu !=3D - 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 =3D NULL; @@ -194,7 +174,7 @@ static void evlist__check_cpu_maps(struct evlist *evlis= t) /* Check that leader matches cpus with each member. */ if (leader =3D=3D evsel) continue; - if (cpus_map_matched(leader, evsel)) + if (perf_cpu_map__equal(leader->core.cpus, evsel->core.cpus)) continue; =20 /* If there's mismatch disable the group and warn user. */ --=20 2.43.0.594.gd9cf4e227d-goog From nobody Tue Dec 23 18:11:12 2025 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC19312D75D for ; Fri, 2 Feb 2024 23:41:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917290; cv=none; b=TLmLkCitR8Wro8AsVosm07Ogs7VOVU08XwaRs+ZbyaPxMk6QC7AqP0RXJc7WsQD1O/DLjiZnHhkPBae3OJhZZuKDi7JWue63lJdGs6oB8plY4V+99Va0m0WnUvNl5M2WgJ5uK+4Y4q+G6Lqicr4D0IJDQTpuecklr0kMEOSenxg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706917290; c=relaxed/simple; bh=Pj322BHyXG2gYzt70812aeyUBm7YX+GP878Iql8M7M0=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=SmT5BGC/BCSty2Q0X0xTv4saNPkPE5vh4TpYcBgt26I3BpMbcfX7qDQsipzu2RTWKa+Yd5SWjMJniyCD7oMsbLz/q8IygEvg7VeNI/ue43/Gzlh4Lvon8r5wS+w/oqtbT9JPdanszAKf35L/Qr+ndZW1bQDjje914Xb5z8UMbo8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DIuNlx0u; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DIuNlx0u" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf216080f5so4152676276.1 for ; Fri, 02 Feb 2024 15:41:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706917287; x=1707522087; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=oAZu4qV7GRrZlOn2fzXe1/O/dsnDVPHUY/jAFql6qE8=; b=DIuNlx0u6wSWGys6ouJSMYxes9hEfYlyXok/OWotLRxVI35LFDYpfJH8coIYc0681B b9NXDeLR2MwM0bjymnAnENA9wDAJIPZ1pXNLfwC9jyhjYcpOXKEr7Zx8c/uXW0f5+yOR WOlNjjAKMX44JyyITWLYLd2jrMM6Cwe8DP/iJgOMPFCGUI4e0YOmmQPEHupBuc+JTlNW R4ltew9kBb8wstgn6E6eZXSGGmSmJyOoMxX9ab3V/XMLI0t4CQ9RziX+aAGsWZXnIJi7 69xRVNVv9to9TYv5c0GRE3SqaEO/jvrCEA3eM3o6gqv5lWvaVpbHXmIJPOMN8AFkgJuJ rVzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706917287; x=1707522087; 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=oAZu4qV7GRrZlOn2fzXe1/O/dsnDVPHUY/jAFql6qE8=; b=ZjXaJy6k8POyne3w1PagUBpMIUDSQO9Fsp3He10L1CZ3D12OmemOOEuozBnhy23Rsz c9K/dlygirWMqFT+8TIwTrmpHfLnyL+DxuJ51oMm99MiFfm0x3/QatPO10z+CMEEQbER /ODjH3nrFNDv8EEdFES0Sxed5ARCo3aLNMucOyLfmETpePqHXzeqnmK+iWDWWiejV7Gd oikHrWzLdie5BljzerowIpLyr6a7uldsgCW8ZuWQl8O64nVa3tbgh5WFMnY8rdSOsFpc u0xQer6LGJftEUybsr8ppN0sZWS85yRpnSy576E+hjOuZjcNm96kesFVMVjqitpiTSMH vaYw== X-Gm-Message-State: AOJu0YwFbQcQfTcNzdWaUIcXdMhxn08m2L0FrpZCg+44aS1Xe7aYOaUF K7AG9L/41ewLLK0a0pUUBhYkWk3tlP9IdGwmdbfTepKZRR6uK4+FHnAAW9wlJAgbo3kG4w7sSWT xTBumrg== X-Google-Smtp-Source: AGHT+IGWKHJPQ+srMx8iTQjHmNcONKoF9irN1wBz1oJLHeiCGaYjrokUE8W5/hfZBgPHowpVLv93UI3h+uEW X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7732:d863:503:f53d]) (user=irogers job=sendgmr) by 2002:a05:6902:1b90:b0:dc6:de8c:f4fb with SMTP id ei16-20020a0569021b9000b00dc6de8cf4fbmr1026637ybb.9.1706917287710; Fri, 02 Feb 2024 15:41:27 -0800 (PST) Date: Fri, 2 Feb 2024 15:40:57 -0800 In-Reply-To: <20240202234057.2085863-1-irogers@google.com> Message-Id: <20240202234057.2085863-9-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240202234057.2085863-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog Subject: [PATCH v3 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=20Almeida?=" , 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 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Acked-by: Namhyung Kim --- 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/ut= il/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 =3D sysfs__mountpoint(); - int cpu; - int ret =3D EINVAL; + struct perf_cpu cpu; + int idx, ret =3D EINVAL; =20 if (!sysfs || sz < MIDR_SIZE) return EINVAL; =20 - for (cpu =3D 0; cpu < perf_cpu_map__nr(cpus); cpu++) { + perf_cpu_map__for_each_cpu(cpu, idx, cpus) { char path[PATH_MAX]; FILE *file; =20 scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d" MIDR, - sysfs, RC_CHK_ACCESS(cpus)->map[cpu].cpu); + sysfs, cpu.cpu); =20 file =3D 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 =3D perf_cpu_map__new(str); - unsigned long *bm =3D NULL; - int i; + unsigned long *bm; =20 bm =3D bitmap_zalloc(nbits); =20 if (map && bm) { - for (i =3D 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); } =20 - if (map) - perf_cpu_map__put(map); + perf_cpu_map__put(map); return bm; } =20 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; =20 session =3D 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_c= pu_map *map) TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu= ); =20 for (i =3D 0; i < session->header.env.nr_cpus_avail; i++) { - struct perf_cpu cpu =3D { .cpu =3D i }; - + cpu.cpu =3D 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) } =20 // Test that CPU ID contains socket, die, core and CPU - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - id =3D aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id =3D aggr_cpu_id__cpu(cpu, NULL); TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", - perf_cpu_map__cpu(map, i).cpu =3D=3D id.cpu.cpu); + cpu.cpu =3D=3D id.cpu.cpu); =20 TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].core_id =3D=3D i= d.core); + session->header.env.cpu[cpu.cpu].core_id =3D=3D 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 =3D=3D + session->header.env.cpu[cpu.cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id =3D=3D id= .die); + session->header.env.cpu[cpu.cpu].die_id =3D=3D id.die); TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Cpu map - Thread IDX is set", id.thread_idx =3D=3D -1); } =20 // Test that core ID contains socket, die and core - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - id =3D aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id =3D 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 =3D=3D i= d.core); + session->header.env.cpu[cpu.cpu].core_id =3D=3D id.core); =20 TEST_ASSERT_VAL("Core map - Socket ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].socket_id =3D=3D + session->header.env.cpu[cpu.cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Core map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id =3D=3D id= .die); + session->header.env.cpu[cpu.cpu].die_id =3D=3D id.die); TEST_ASSERT_VAL("Core map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Core map - Thread IDX is set", id.thread_idx =3D=3D -1); } =20 // Test that die ID contains socket and die - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - id =3D aggr_cpu_id__die(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id =3D 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 =3D=3D + session->header.env.cpu[cpu.cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Die map - Die ID doesn't match", - session->header.env.cpu[perf_cpu_map__cpu(map, i).cpu].die_id =3D=3D id= .die); + session->header.env.cpu[cpu.cpu].die_id =3D=3D id.die); =20 TEST_ASSERT_VAL("Die map - Node ID is set", id.node =3D=3D -1); TEST_ASSERT_VAL("Die map - Core is set", id.core =3D=3D -1); @@ -173,10 +173,10 @@ static int check_cpu_topology(char *path, struct perf= _cpu_map *map) } =20 // Test that socket ID contains only socket - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - id =3D aggr_cpu_id__socket(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id =3D 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 =3D=3D + session->header.env.cpu[cpu.cpu].socket_id =3D=3D id.socket); =20 TEST_ASSERT_VAL("Socket map - Node ID is set", id.node =3D=3D -1); @@ -187,10 +187,10 @@ static int check_cpu_topology(char *path, struct perf= _cpu_map *map) } =20 // Test that node ID contains only node - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - id =3D aggr_cpu_id__node(perf_cpu_map__cpu(map, i), NULL); + perf_cpu_map__for_each_cpu(cpu, i, map) { + id =3D 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)) =3D=3D id.node); + cpu__get_node(cpu) =3D=3D id.node); TEST_ASSERT_VAL("Node map - Socket is set", id.socket =3D=3D -1); TEST_ASSERT_VAL("Node map - Die ID is set", id.die =3D=3D -1); TEST_ASSERT_VAL("Node map - Core is set", id.core =3D=3D -1); 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_t= ype type) =20 static int setup_filters(struct perf_kwork *kwork) { - u8 val =3D 1; - int i, nr_cpus, key, fd; - struct perf_cpu_map *map; - if (kwork->cpu_list !=3D NULL) { - fd =3D bpf_map__fd(skel->maps.perf_kwork_cpu_filter); + int idx, nr_cpus; + struct perf_cpu_map *map; + struct perf_cpu cpu; + int fd =3D 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) } =20 nr_cpus =3D libbpf_num_possible_cpus(); - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu =3D perf_cpu_map__cpu(map, i); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + u8 val =3D 1; =20 if (cpu.cpu >=3D nr_cpus) { perf_cpu_map__put(map); @@ -181,6 +181,8 @@ static int setup_filters(struct perf_kwork *kwork) } =20 if (kwork->profile_name !=3D NULL) { + int key, fd; + if (strlen(kwork->profile_name) >=3D 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_to= p.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_t= ype type) =20 static int setup_filters(struct perf_kwork *kwork) { - u8 val =3D 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 =3D 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) } =20 nr_cpus =3D libbpf_num_possible_cpus(); - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu =3D perf_cpu_map__cpu(map, i); + perf_cpu_map__for_each_cpu(cpu, idx, map) { + u8 val =3D 1; =20 if (cpu.cpu >=3D 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) =20 size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t s= ize) { - int i, cpu; + int idx; char *ptr =3D buf; unsigned char *bitmap; - struct perf_cpu last_cpu =3D perf_cpu_map__cpu(map, perf_cpu_map__nr(map)= - 1); + struct perf_cpu c, last_cpu =3D perf_cpu_map__max(map); =20 if (buf =3D=3D 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; } =20 - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - cpu =3D perf_cpu_map__cpu(map, i).cpu; - bitmap[cpu / 8] |=3D 1 << (cpu % 8); - } + perf_cpu_map__for_each_cpu(c, idx, map) + bitmap[c.cpu / 8] |=3D 1 << (c.cpu % 8); =20 - for (cpu =3D last_cpu.cpu / 4 * 4; cpu >=3D 0; cpu -=3D 4) { + for (int cpu =3D last_cpu.cpu / 4 * 4; cpu >=3D 0; cpu -=3D 4) { unsigned char bits =3D bitmap[cpu / 8]; =20 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_co= nfig *config, { struct perf_thread_map *threads =3D counter->core.threads; struct perf_cpu_map *cpus =3D counter->core.cpus; - int cpu, thread; =20 - for (thread =3D 0; thread < perf_thread_map__nr(threads); thread++) { - for (cpu =3D 0; cpu < perf_cpu_map__nr(cpus); cpu++) { - process_stat(counter, perf_cpu_map__cpu(cpus, cpu), + for (int thread =3D 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 *ses= sion, int i, err =3D -1; struct perf_cpu_map *map; int nr_cpus =3D min(session->header.env.nr_cpus_avail, MAX_NR_CPUS); + struct perf_cpu cpu; =20 for (i =3D 0; i < PERF_TYPE_MAX; ++i) { struct evsel *evsel; @@ -2759,9 +2760,7 @@ int perf_session__cpu_bitmap(struct perf_session *ses= sion, return -1; } =20 - for (i =3D 0; i < perf_cpu_map__nr(map); i++) { - struct perf_cpu cpu =3D perf_cpu_map__cpu(map, i); - + perf_cpu_map__for_each_cpu(cpu, i, map) { if (cpu.cpu >=3D 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 topol= ogy *t, int nr_cpus) =20 static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus) { - int i; - int ret =3D 0; - struct perf_cpu_map *m; - struct perf_cpu c; + int idx, ret =3D 0; + struct perf_cpu_map *map; + struct perf_cpu cpu; =20 - m =3D perf_cpu_map__new(s); - if (!m) + map =3D perf_cpu_map__new(s); + if (!map) return -1; =20 - for (i =3D 0; i < perf_cpu_map__nr(m); i++) { - c =3D perf_cpu_map__cpu(m, i); - if (c.cpu >=3D nr_cpus) { + perf_cpu_map__for_each_cpu(cpu, idx, map) { + if (cpu.cpu >=3D nr_cpus) { ret =3D -1; break; } =20 - __set_bit(c.cpu, cpumask_bits(b)); + __set_bit(cpu.cpu, cpumask_bits(b)); } =20 - perf_cpu_map__put(m); + perf_cpu_map__put(map); =20 return ret; } --=20 2.43.0.594.gd9cf4e227d-goog