From nobody Thu Dec 25 01:59:03 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 1F1413BB4E for ; Thu, 1 Feb 2024 04:22:52 +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=1706761374; cv=none; b=PFR9jOHMP+RBGF4pLk1P0Aa4otGQd/wq3LFc2lfW1KdbA2uqM8y1iykuHFEC32xentsWWbZCiXImnhGK9BDTbdHGIhbF3Bzic7a4UCcjAuWQ+MMkBBAHd6DiROM5+iGPcoVs9DaBrJyUqN1Mc58zI5VGv4immS7PAZ27G/aefNI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761374; c=relaxed/simple; bh=LEf47llM5ZntjdM1tFx+kv1F7VOaVbLqYPevCFmzKgY=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=JiTbIomy4iA/r5HSAnJiihUUWSyTQMUxw5/Kb4NP/o21wdW3vRFJSpcoVWNUxZMeBZ/tb796soVcrBwfWzdgX8zdPEl86PuBRjIqiU+3d5iExsWtRXnd67WAayc1ZR1cwN3U60QvRXBbf2kmzDT8hXxHxiwS8kIg6U5HaRQSi/4= 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=uoXs6WNQ; 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="uoXs6WNQ" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-60402c8d651so9322257b3.3 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=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=PeitV0yHOpBere8QJtZH8YRXFmaqbWcfFgW9touiCOY=; b=uoXs6WNQULbQNrWWnGVc2G/XXR1mnv8bnYE1QGQF6uO1SIj/i3Nk9ZPoPTBMP2wLQr M877Z2m7yRKf8mY1mhjecatsnEjV6jWPankR3vQIU6U/jKGsYv9FM1I0cQbeEeFBge77 X/AvaRkQmNj9FN03afBInFXFD84ictK1OAdKHLK5odHpYuDIQ2tSmet2ql3uk6locy1G USYHMVF3t83n0pMl0pfSLKVZNFDctlb+Mf8ls3ikKfRGeUsKViZjGACN8gXkeqLUNelt Ec/UL1j/PX6YNhn7Hvgr1m6anSWSUx2EumcAhaJ/Ie0zW5TZIhM+yLYmzxWXIbGCx7ql HUhg== 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=DNYcPabmnVUHg4gFUENwOVXt4PM/z5anoR0/Vk46Z7CG9uXwQw6XfE5LblQTMAyj6h G8+wbSKdAzGkKzg/ZiOUgUUqupmSMNJHsjGRiZXikSFxRV5Q58f/t4E8M/6VIXlcfH5W OkPgP/adSmq1aBHM23GCH63K93+L1t9sMrtn4ewXbekkgHCNvKMX+eeyEH76ld0fjRzI IQVN4yberCb2daF1oWS5zBHhd7dZE+dIveFePH/509CtEnEnUi3UinkMxGuzB39gSYEp SSG++1Vy4Mc9XRibBbuUYxFC4C16tYUx6rptCTEeYVn6o/eEJahIHM/TXSI0AwpSquqd nn5Q== X-Gm-Message-State: AOJu0Yyn+XgYDnYELfj/Xx/k7QbEszpUdgXB6HRn3oK/OVi2F0w8eZPr sPm5A3Za3tJ1oMkhPFItfWIgs766D2BdtLq8vpjg9VGvmlJYYlZXHZ1jzC6uCF4nPwoY0qp/YWr DTfemfw== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 --- 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.429.g432eaa2c6b-goog From nobody Thu Dec 25 01:59:03 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 B18133C6B3 for ; Thu, 1 Feb 2024 04:22:54 +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=1706761376; cv=none; b=JuEQDmHe2h8mi+XfJ08nDCquO7e3TlcBaujslLgiIwon5Mdq1S3CuigEN1b92BzTDl42AqW8/Ug0uM2on+Qg6SXBXY9xd6esaNp2V01gxBqRhpbZjNpjYA9zrPwk/UPFT4AGp/T6DVgYWh7XFOYFOh3OvIzIQ66MpEdBkhV/J6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761376; c=relaxed/simple; bh=sM6e4GJOdVtgwSVAwsLzIbgUpUVCVxBjp1/mDPrXzxA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=DDTU32Z59sEeFKTmDWbDMUJTnPYsNvueQHN1a7A30JEHFK3Ee0XD1j990qyUUQjVSpx4OYD9ffobzwE+qxQ52V+g9tFSKc7hyyGMQ2gEZvkY/yLYKsKqGF9uuxaeMijSQ5YUtYZZGTp4Xo/QS3QWxqK9L2+rSm4bVjrcwki/CnY= 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=QJ5BXYP0; 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="QJ5BXYP0" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5efe82b835fso10625207b3.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=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=1JXSUMX5bbfgnckmTRSZnaB9bhkcugUHtNJBG9b4Oo4=; b=QJ5BXYP0VM7KLbvbyyPr8hcLsap4dW0LPX3aPVHFjUg1pnNcniUzXW75tV7XzDssKH kpP31oxRoTfg7N8lYODWE3A5gE2tp1euUyAKTryMN0c030H87na9wA4cuaQGHsZrcon9 USKhntQtmATztQsPhLsfFmQi7FEFVeOerKTFcnPgvAHkehtvZn2cbGdLVbpAHjFqMcSw wUI7YIrIxOJl/E+qcFFIBxGHVlH8bAm2wfM2/EkgC/uDcd1hjtw1FuYHN97ocH65I9va B9f4J48EKYWlK4NoYf3swTX8FGFWNe8eHHIXgtCa9pnwl1qG9OB3pz+YPITGrq0IcLu8 TRuA== 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=rqzwqFG97dJs5iPRXJqgtLWUXnax+w1FwRenDUcgK700IjLceQX46UlLMFpDI/PB3e 66wQ97yV/Oq+EKYYDUUKpx7MA1BKGHMHa48TSSQVGDK9TsaapWUHykuV/EZO0FoZ/b10 2OzzWAn06hG/+Uuu55cDOhjlr0lxdWtvnma94RhhsuK5CQLNOuvyhlDfceuFf4UJPTFt gw3Cdz03pgwI1jxGZyQYQyLCzCXJ/8IvZbzNrdmC2MDh7zosXF369JDpgLnLDQjOttoT jmrR15G+69Lj+mJS6aFl9/THgdCwI0VnxubkPnTIxMWb70nqRIorK/FUWHi/Cfb6YouH V1AQ== X-Gm-Message-State: AOJu0YyYYBdVUEr/yJehTtwoT/ZN+ghDwMi4E5vh4r9RXpIEa8sy5Xf7 htQFfU0VmJR8zeZlICyX6KSO1bFLGD3SNukEPHXB9GOAedEzw/l49TFmap2Wa20i48Y18hPWqO0 iM44xMA== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 --- 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.429.g432eaa2c6b-goog From nobody Thu Dec 25 01:59:03 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 03FA03CF6D for ; Thu, 1 Feb 2024 04:22:56 +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=1706761378; cv=none; b=O/8BoMMg04g04+ooHWwIaqRcXk7BDAWPx+/MoxRhki6tXS2U70yKXrN4voCxM9nMfl8BFeQUjzB6BqgZnwPOS/MsriDS8Tdja3Cb0OMO5wVrq7w3nOTLMqVCi+NID0RmX8jbOompN8hKXFei/llcHWswncOAbNgTrNCPfodhZfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761378; c=relaxed/simple; bh=kOaO6z2IMzg1r/MyGUpkXjIYsEpcI0zfWB2ic7bf2Xs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=b8aERM3QXGSjvKL484tQ+h38RoPThyZ6N1Wr0c8Cn4onpcbNIZMW8STWBqpkQy3duAayhmziSJerjY0x8dt2CudKOWZt1RGCg0dA9XHaq5F83dWT/wHp+kafVeIt95eehbqDo9oApvXgTZDm633lUdtZkkg2vyoMTnSqi8L3DSA= 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=ziVY/e2+; 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="ziVY/e2+" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6c2643a07so901877276.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=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=IpPU/P9Rw6DdLv5FLhNPDNExyhurg221RAp9ZKk92ek=; b=ziVY/e2+cJiy9QxzXqS/oYiCR2TU3lt13bOhdazyiGC8Sj5NiU1FHpKgGbleB3KWP7 rIAxlFv1GGlAOdImfqefbhLuX951KWFy0HN84o1A0rQUKcIwPyR5IWWu28tOH84cWXuP 9Nh4qLBtzzksNd+i3rxKfdxVVJL6sRRXRGPBMTEy98MgJMP9twIJvlEGBxDIiX+Tcu/V jt1eG835NoyNIhMfb3u6Cj2eDEQECpag8W/dqEUu/6MW/Mxh59OyADnfDtbLKt3OibbE uUQeCkGsuyfflmkQhS5ci3vqjCdZqzP9kikn41+55Wrpp+aLTQ9qt0O0e7PCa0//nIHS ahiQ== 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=CQf0WuOIxUtQPN4MTDNBL9Kfmk508gvYtBQafgfuP82Y4c8T4TA0W3UVo8+o10fFR7 tTqxl80I7s4AL3oHOO8HrMvyp6H/zgYOUxjLaZ+mkCG4ocKBz10FZnIMpg0yoWGqhkUP wqcYzJ6cNOJnanCvjxfgXKk0IVGDOKNkjyuEML0r9NaLGj0gWdbdneTCcFDr5ZolGl25 IPbuKEIU1uyeoZFJA4oYawQj4rsBfoqOK/diGeiYerRJJUgFDUL+OLFPlIMuo1MhbXBJ jYsNhl+8UMkFdSjOl1w51r1kNVCKCN8r93zTzqOAapgtuGY3BiKh2gazbrCj5hVT2eO2 5Cxw== X-Gm-Message-State: AOJu0YxnvOKTqdkef6ngLfyuUCtJ2TfNPqMdtEbIJZ1itH4B/lR/9w6g myB7AN2fHUquAsD94vSD/qQSntSHTi5FKnjReQsUyWavOooVCIlpVcKp/IwHe4irrkRSCLYA1d+ stDiuSw== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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. 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/c= s-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 =3D -EINVAL; + int idx, err =3D -EINVAL; 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(); + struct perf_cpu_map *intersect_cpus =3D perf_cpu_map__intersect(event_cpu= s, online_cpus); + struct perf_cpu cpu; =20 - /* 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, }; - - /* - * 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); =20 - err =3D 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 =3D cs_etm_validate_context_id(itr, evsel, cpu.cpu); if (err) goto out; - err =3D cs_etm_validate_timestamp(itr, evsel, i); + err =3D cs_etm_validate_timestamp(itr, evsel, cpu.cpu); if (err) goto out; } =20 err =3D 0; out: - perf_cpu_map__put(online_cpus); + perf_cpu_map__put(intersect_cpus); return err; } =20 @@ -435,7 +429,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 +455,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,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 =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(); + struct perf_cpu cpu; =20 /* 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, }; - - 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 =3D + perf_cpu_map__intersect(event_cpus, online_cpus); =20 - 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 =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)) + 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 *i= tr, 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 (perf_cpu_map__is_empty(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.429.g432eaa2c6b-goog From nobody Thu Dec 25 01:59:03 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 B2CA43CF45 for ; Thu, 1 Feb 2024 04:22:59 +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=1706761381; cv=none; b=DpVEofFG1y2NFPC8Or/sI+gwxEwSJAC7rGtbo8g/K/Ag5m4dzxmHBvyqlMbydCp9dzDGjqXGyHgEVHNNmqMm1EM3P3qvtTDi/GPqK/evsuyL838KjM41OSOb+kn0TUo7s9vJXRD89jdW6BGzluw1eqt7XswynevueW2IVCqRgD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761381; c=relaxed/simple; bh=k2FrlLoZPdnfNlF2tIYydGHAGX1QUhBl5GI7Pifbd84=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=LCdddSpzyCEw43R64KY4uVio/IB+sEgUQf0u/aUfFCz3pfUM3m2iD4WH590KG+g/anpnkxbT00optU8+nY5IaijkQTCvEwbDUNoRxuVSUju5B/Zlm92XnnAAqECT0/ZV1CnfP9cuTAWyGtj5kX926Xhvzm4nip94PuFUY+us1ac= 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=BFi4jWWN; 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="BFi4jWWN" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6040b27151eso10754757b3.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=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=x5H1VG+iZLkcs4atGUwnj2dxBUXygPFhAbtPAwQlWtQ=; b=BFi4jWWNE2OVOa4iFonbcVf83v6zNDluX307NlY/PgWJJipcQiEd59r9KH1s4e60R5 zyShlqOygxe8HV8RCKvHkMoQlIuCbw0D5skRD35kvlxcwRMJxxLV5MlBepAi7GfXvMqY G0rkb9IYCyUM8gI0OTevUIs7t3CZLSJxcpo9Ygv6etsujmtPqDxV7GevdT/TinBEqSax Ub5YEQ2P6bie7VviPqdlpTSPGkxHzP4YqJ0Il9Ar5nJPUYj53SGKoqP6dNkP9kZBp4ca dGbHXTQhXrsV4MA7+MSCEslL624/a5M1noXc8JB6rJCBirUKqP3mZLcr0EzA6I2wO38a HnvA== 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=LGqB/3VNd3sU6thPxDhbS12c9sCSNsVTBqvi9JdqgO8xSizBDGw+cmT46w52920GIc zERnxE505rBKruUFp/gYDDcq85uiMm2Fh2Ki1Q0vs4ilsNx2AkS/ZUY83jgT1Pzn+XgN yAzr/CtEezUtSXDdIPWfpDaC4GSrCCj5sz4DdYAO/IC9U+n8BUccq1CYtr3F+FJjXolt 4AhrwO8XlA3Bz/Qd4DvkYCV4i2hzbvosvN1IdYvmFMGWTdDiHR5lEpyU6ndM+II9poYj xu2evGRG6r2OswY8/jukrQo0XA0D67BFOF4rc+bvPq97hbgMq0/I7vk986opuMTAlXSH PclQ== X-Gm-Message-State: AOJu0YxY9dZKZ87q1vl0QhFcM7UhaZtIRsTgBA3k/OxQWlKNzC2C461X ICgj2INrM2icmSmJETP8SNAlDQiRhtB3cjF7zLKnlMtC4M1yTKBy71xWXzpktjaqNb90VdQu5qg pMuwEbQ== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 --- 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.429.g432eaa2c6b-goog From nobody Thu Dec 25 01:59:03 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 1E1BB3FB01 for ; Thu, 1 Feb 2024 04:23:02 +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=1706761383; cv=none; b=BJuO2lqCYPJyh1Hto6B048iICGnn89FnkxP6blAnfV3unDOWj8U32AX2E1RtV/YypHKDelQJbaygXv6Yk7/1/oGYuootcp2SII5K2JVhJ5he7aVIzl3azTAiQj0fF2z7OzborZir1QfR5PeL5/+jrJ4/XbynN4YMjin/r1ncXX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761383; c=relaxed/simple; bh=rcLKh3+Pos68LmxJ9Hm/6wnfZr3ChIf03nmHam1edtQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=nIKfEMkYkbLr8Q0xA7N/4cgzN9+g+oLFBXnMH21eSaEopvSoDvChr+RU+f0sSk0KBssElgLhZ/wo1ZnpP87RXMKRjeZXdlYqeqOmIWIAD5TBvshmTdlf7POA1diNTkHB90kmZjt/UPlaTGs84B/ZCiBmdjB+JGz9uNKdEUCy27c= 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=4JhR1+W1; 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="4JhR1+W1" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc6b26ce0bbso1018029276.1 for ; Wed, 31 Jan 2024 20:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761381; x=1707366181; 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=ZaackeHVB/qKw2MvrD7oP7QYNMjIwSaxho/+246ePe0=; b=4JhR1+W1YmqUbpXA7T4AygMApo80I6G3b1PQq9FzIZ/dej7f0oIpEFE3A/GrQPkfVw YxRgxcPboW8nY3qGZ7/5RgUgvvhHT+fKN36BUmuyyvWfEWPEtqBJYzIcq1Qy3A2Lobfh Vm5C96+GBSJ+ckbmkn7KZ62DxY4vc3zP+qVtD5Y3cVfOQUZbXXOtQEtu6MHZKxXTLKyA qwQwe/M1RG+aC/PYGH9oZUjGIjsujZ/7QCp0Iku6J+AkBs/1WNBuxLp9YijQON9+0ZMZ aNMuukIwV3J/SV+rBhF7QPmKQOzpiXqsafSF//aHPq2Xz+dPYdG+MlgNmsnqeDjMBP5h e7Qw== 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=XWIUKAE5ORF6v8wfYiciXJ8UciGMkp91GTduktuBgbwAgldHo4hqAIEY5MPvsSKQJX J3Vd/NTskrFHisMvHiMTq+qaCOg/J7nPBwkUGmDAfK/Om70btvIBZEdApYLVoT8yZd/k MSgpbIOMyXjP/iAkmISn6YWGXSDCyR2Vh/fDprz1VRKqoKYGnTSFxsuKl2rMEXXox/9c ZCQWyAc3HkDc0Muy0tiSJx80+C/k4xXRGvizqsBpIwLz3K1vPFIQTU+wh3Un184/5kN9 yCT/UiQv+UVOI911AUWZ3wbI1NSH4QxEnPkt422G19zOOzPeh1hWl3+9s8amOdFY6JC7 /B5A== X-Gm-Message-State: AOJu0YwSkHtab6h1WIeWkShT9A0cOkznJI4WaMhS3aFYGfxPJXvO0r7t vtYXVL+gWmirUK7nzVRMwdHxePWi/IOi3oEk3d9mKdqxCd+joCok5qpoKfCpP57frkUzUkbVXD/ b2o2kGw== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 --- 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.429.g432eaa2c6b-goog From nobody Thu Dec 25 01:59:03 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 89FF73B199 for ; Thu, 1 Feb 2024 04:23:04 +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=1706761386; cv=none; b=uzuUSBS+FO+p4SZ5eWz+BbxWYTZoUeXUq4Mh6/CzLS7+weRSIExecS0UdK9/EQuFM1w73T14t0vXDvojQCDEDETkQDsLPulx4ADl1OahWA1OGMIEl4RNWpA9CIGhM1m3YeczqNxZ5u+DrQUUQQ4vI6TID9/zCdsFiDCLd+vMq+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761386; c=relaxed/simple; bh=muMEVPjwxm6q3RlQ95/IKAyqTZstFA5meu7x6+UUwZg=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=Az3M5OnLQgya7kipYH9hoVBtHQPM7LJElzk9HTue4Xv8XD8Q1ZZUuiMbbBdApxHEAQBpfUIpZfFjtb6X7RqjlAFJA/b2uQElu83pAgseaKQG9C5u8wXkn4wz8VOzKEl4/xLX0YkYlMR+Y661v/4MzAL3HcM4iwI0UeRwChQtoYs= 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=Gaf4U68S; 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="Gaf4U68S" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60405c0c9b0so12941867b3.1 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=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=RrRDV2OgW3nzJBdkuc2LAITTVB+J1bOMfWE+IFXHyeo=; b=Gaf4U68Sz9/QKPH9L2e8HKiqhb471OZd3yjy6feCZpg9lE2I+Yt0vV9fLFE8L5pz0g SnsBNITjMtVa0Dy29qhlXpe+rqk8okRPuUOPpAujU8j41N4yVTrr4+JIOyNLYVvbQzUP ERAtrSojrsORooiW7q9dVbSk84BC9b2yt11QfzpCJdMny8CIW/4/zQqQM7X5C3QtCvU8 oPdHkjFXcm7jPXTI338Tz/Gwo2ulzdtm//QYmEYE1OGL1bB7DSZAilcNzFqz2sSOII/h 7CANjNTdk+bQg46pELw7fpwayHHvs/ROmVsbkwzo3cAQTfLG8/+T2G+b2ivr3nmp1HA+ 5gfQ== 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=ZrkwLt6cGZ+1CKz4x9TO9BP7fDkgKINsU5cHWEoQvox76AfGpSfZGhnqpR5XeSFIPN k9e1OGCkFqTGvvAVaTxNlJXcNCk6gF1eM2mGtSH8qn0RP99aRsW92qdQEvtV6vcElh87 76Rbh5w1D9Ynw674neIK1gf0aViaNLf6+8nUvrbh5twTF3Vd+kq7ZIP2aOWz9pzFulx+ 3jvCrE6ImNTj8yq7pMOJfXL4UToIl/2k1xXXhYvXr9hNVgA+dFoA0Yh2xjjPx7Pz7Mpd cNVtOKfblD8QfOF8BnJs3OhSbLU6KqvFFJ46i8bsp+FBM2akVRAItQRtQJIlv8WH4trT iDig== X-Gm-Message-State: AOJu0YwCYdDVcInJTQpjR0/a/AFca1uBA7j8RltDeOZMjX6Gry9lRZVh +B+ckvDwVVLS/BHyQ1H8vdrhF4nKhqGA3LWp3/AueZ5NNNus9Snwacylbg+ciFJZogDVfUX/TZX lgu1xfg== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 --- 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.429.g432eaa2c6b-goog From nobody Thu Dec 25 01:59:03 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 3C8CD40BE0 for ; Thu, 1 Feb 2024 04:23:06 +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=1706761388; cv=none; b=eMVHAoFdoSXrERxWwt3Ir+VW4loNyq9BwlztWHpSE1cdgTEPNRJCyVQNmMHPi82nF6y3ZrceHIIpKG2Xwpmf315rMfxK7Bpt7iDjlcLXrlY8ganwCznmypURQPjyN1ttVtExCNwgzRI7SDbeFGC9wAHz5TDckYbH8MR9z7QgvzE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761388; c=relaxed/simple; bh=F7w78dZ7Yg86YXdfWPcsiQMqcZSTmmSk6fh0dJHNA10=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=UpzlFi5Ql11ZfZ6BE6OMeZ+0lWCwPpfnZ6AI386tg69VCEJo4blXT+D9cM/l7eC23tg181eu+EOOJcDiKLL7nFaOCGhxDEUMR/4wexvvZFC9jLbpY9tTHMjjF53yD+T+j76tt7e3YBiASJtDCFGeZToc2m3h7qmpZDefBVYwXQU= 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=lvZv0WWO; 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="lvZv0WWO" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60413725f39so10156827b3.2 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=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=LqZwZ8AsgQZJFdN47MyZTq1RxCf/Pyb95/3gvsK2ot0=; b=lvZv0WWOBmGEUwyBMdWVN5cw2Cl/6sUzdgeLEuRQlKL/cDjb62+GvGz3kOu7jAW4yU LXeF2y06NZ3+zJOLPg9u9XFB6SjkhrKfppJy0a5cRI6Ra2c6W4vHwhh0hQZvOykTWANR AAg4FpIEw4slFQlnub+Kf4xAkWrYPCrPHUEWbob42LqRR+ilpMbdT7+G09sNOQm1+ex/ 5RX2ppkQUgp+1eQFLspevq0S64gqe+IgnIHncGBtaMAvbo75yYnYLDKPGSOZgY9GSEd2 gW1QSOoFDb22p8ancIQYdn8TcnGmPLkzg4tsdZ7UIY1ekAXO89e3NCKvyAlMcvsi+yoD xexg== 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=jNsinOblIF2QO9KVgGTbPSTebeAcsF1/5/pBJRqfrewL+ei/5joLJ9AFM5NkIMbjgU T+TqtzEUYGHunZgV1I8blbF2KlRXTZv60NaEDl09hfRHZMSRV7/Og48pOW8pMqOrdTpy MAYQ/sjL7gcTaGR02PK57Ms07txvZlsjlVsFZiEh4nItddP043T4S8SoP597rM1W6sq+ nS+VDYqJOC4tPrbICUQHtg8Erht/7itGQoX8X9GECOkqdrmh6/6h35yvPRS/rG0djPE+ wlCMpjR7M8f1xA04yZkL4jOKjKcO/DhHIUbuWwH0WsuE56X0c5AA/OMxAtQu85aDs6s9 Q+Zg== X-Gm-Message-State: AOJu0YyUySf3/cRIYqEF0DeRh2w3AUNmaSTu0FS05FKG4rS7fWv+KM74 mVxYXlteadZg6xI1plg/QTAz2yH27v0PkxxhBTHdrFB6dIQCG3pveRlhXS/YNfajkRmfyDi6ekb 45BHDuA== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 --- 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.429.g432eaa2c6b-goog From nobody Thu Dec 25 01:59:03 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 DCD7C41770 for ; Thu, 1 Feb 2024 04:23:09 +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=1706761391; cv=none; b=igYxcvlmjByb+Km352xxfk2iPWk2nd8Z8p0v/I0OlsA3V6lMGOrpAVvQr5gXl0W3qJ9U5g6E5WJ7luq3XEGdccQIOgSrnGp1qcP/0MLYw8ihx/rg4xNtD6dlsEM0Oz5vPMdxqhay0WG8+ocUtMqHGKZFlOUXQSVxHQYUZ2BkO04= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706761391; c=relaxed/simple; bh=6ee1ftjEAWmDYYEvP15e2CVNavi1Il+bUDSOrbFQ8LQ=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Content-Type; b=XjwFpgXqiDjoxsdTRZAHtniE0bB+tOleH5TZxI372taSJINmpKB9HQpAhudZkP1Zxi+M9/66Gcjh4HkEjNhGjJTbLQRR3si+LIYbkmXPJA9VxIQnIFaR2VGp003NhfUXYCEnoBx9nfJYaKskW6GmJJ+F1fx3nLD4a0Yz3glxWZQ= 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=prpu9/BC; 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="prpu9/BC" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-d9a541b720aso875058276.0 for ; Wed, 31 Jan 2024 20:23:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706761388; x=1707366188; 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=hY5FohHp4Dii+HVW+aj7VdYLbpZQQ/NLbocSDzACXdA=; b=prpu9/BCSJzdWL7VbxsSlgTMTyYnzWvHSSQGaGa02E2x87w25tz0GyS4MlvIKVZzAi 8wKgxrMG1pf0uDdTYk07wRnjJJYh8Bmyi/3oflGwLhEbgTz+ILKVAVlc6xzi44gZmRnT KANgzaZwbMgG3spmgoX8LAqKGMwDmDjG9ChMERelJq4EVXxgYAn+qkKN1aMPuJWYvD4m GdSv8IL8FA+WTm4fYOSWSyOWFAHK1BGlv4163fuQB12MsU6WVBWmC/oiMwinP/sfMznR VoF9X71NhqtA3B9oOLznQv67q51/V3bNqzwO81MzjjXNbrQxjsajYuI4owbj5bvmNOso GxnA== 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=n9K6OoeA7+7WATLAY+yCFD93VOqO5ztQ+6TZeqdbUodqM00KBr6G4JsdwGZDqbYdcl Bf/heuUS3YC0BKZi9hmI1vAvSxnkRwWSqA5+eMEqJqLG1GiKmQ2pzE3QvA9iS7I+jgXe 949uHjkMHtEksAnl845pg1h7Ecfc/J8biJ9ugdI2qYCVUPvCJ475QndIU1uHSNirVoi2 8/ygaKv2lep6iXYmQn6C+BU73upg/DdZNTJD7Kd7PWZIb7DYlDibwyQ0RzuoSCLBnpR5 bRrgIzkwJxuQdiCxaUrCtCs3vF/y+eKPb8GZ7MqQ0Ww1qCrlNi+r8ccUFwJmxfazvR6H +Gpg== X-Gm-Message-State: AOJu0YxXRhnZt7M+Rpzir2Q01O+x66oEGymL3Yjryg9DcXPsBrnBervI 2mc3hMjmSWGaoYFMQCktO+4wx2wa0mhtao64HivHCUoP+lHxRDk7xL5uu93ZPV0qHMhS5bDUEje diOn/3g== 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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=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 --- 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.429.g432eaa2c6b-goog