Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp205551rdb; Thu, 1 Feb 2024 06:25:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IFK7hRReQ/XW8yJa34MQYFmfBF6JmKqdvwa9hCd78CMGfUFl/PJHbnthSCr7ZguRA8wpdVk X-Received: by 2002:a05:6402:3126:b0:55f:7b91:cbd5 with SMTP id dd6-20020a056402312600b0055f7b91cbd5mr3710728edb.8.1706797532676; Thu, 01 Feb 2024 06:25:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706797532; cv=pass; d=google.com; s=arc-20160816; b=SAnPMY2iZtXQUP/YfR4z/AE1xWGnBZ6XyEM44ChxFKxorqkgLHcXvETwQrJ0jetZkp 9VhEGSKXl0/wFBWZ3clFvce1Vrb3rBsqpL5qK04uUWgjRpo3sydhbmt24hzfHbj3mTxY y5do98lzQfm5nAPTiOi7ySgW2OygKAzMTnyD5TufwKU9+OWrhrDBiYSLfcLeuAzzC5HS 3rDQhptOwusLVvyMS9NL3+HfRMRz3y5RC072iGF/tnGHgts7x584oTZoCy3w3ETvtzt0 QEWkZOq9iEhjubcvl6AoPmHnVQ16BNTvXdwbfKp+n8MGqW2tVPDDRa8a7QSmkP7ut+to ymHQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=3oik3gsH7UCRMxBdMG02de4OGV898umiHRSHwrLUdZI=; fh=PZwDIK7ijn0VfO/Wk9vb4KT6esKY3xc7xs1QJaVWuXU=; b=wSNvF1E5yWXKadaOHXKODBbMQZk3mN0yibefx7PZklBVpMmZoSW2vXP0+Z0o2K+xGk lQWo5Cs4Y4R+D0BlrSRJUy2w7+/GUvECL/Is6ksFnaYnflT8WrWQEedj4is9LrDkjvYt 4iw0WBWad1wsSk8xRuBa9hF8gNSQrj6Sax0oNwClhGcQ/Smn/xG8vNxm0xoJBAoy4Fun FdTfTPdJEZ9tYT0CDwagLNNy2PINTPCY+BM4hD3GwkA/f2M+JKBxzKuiDxYBrO/L54PE RKSilukFprjCygxFA1b3cokx9z6Z8k2u/HXG2DcCRjRqfTytNkbfURUwMeQ5h1aoLwOV yamg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vIA7Zmft; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48317-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCUdhG3f8KfCBUZ3dWsVPIsEkFZNCH7THfUOFfeC4gtsj6q0LGIFVUvzK8K+UOidkN5mQE/vZcja/rK2ovs9DhTK0HxmcjtjzuFupSLCVg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q30-20020a056402249e00b0055ced896819si7208634eda.212.2024.02.01.06.25.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Feb 2024 06:25:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-48317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vIA7Zmft; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-48317-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-48317-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 408351F2A03C for ; Thu, 1 Feb 2024 14:25:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C23EC5F497; Thu, 1 Feb 2024 14:25:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="vIA7Zmft" Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 B5C3B5F479 for ; Thu, 1 Feb 2024 14:25:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706797505; cv=none; b=oDsFQvdpThorUV9W1uABZdZToacv+sHWMYriCE89lsyXGY1SjENRon7ZyzoaADKRVBAmiD/JLhS77d/LXZXnFLPXWCNybYLNUqneQJd3dK7327rhhdC2Bl/1Krh7+AmzYpeas41A4cB2dcNpFIZ97xk9cWFjR/riABmi2TbHGUs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706797505; c=relaxed/simple; bh=urTC8c/x4GjOmh3DyV8iK3vfUq7I4Kdkr8Ip1YAlpbU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=kpbUHgXAqb/spuck1yA15L/lzVsZceUMKqpBJRwFQhF//jl3hOuO5TGj3jO3Cr/GosHQ7N8iAGlMrADWCoK9vSQbtRS/XduiIRoUAJkRUkjc4JsSIaMGvcuJdRtRFlizIl8rH/OynYymlhLPghIHB3nq2HK50IlGCNYeReEocLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=vIA7Zmft; arc=none smtp.client-ip=209.85.214.171 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=google.com Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-1d5ce88b51cso202495ad.0 for ; Thu, 01 Feb 2024 06:25:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706797503; x=1707402303; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3oik3gsH7UCRMxBdMG02de4OGV898umiHRSHwrLUdZI=; b=vIA7ZmftqW1QTWmyWPq9JEbOmBVd8wve5m8oPT7SROsE3310AomOg28ZHVHk/uYyOO R5uzmYW5fsNgdv9qw7AlmlBltH76NW+N6kjoamqTj2lcS25gOPFZ5pICobcfAsGeauMF mqkQ9V9kJ8MxLkYEbKieEz8GJD+AVFt6A3J+tpmMnj+KOQ7ID9aCY6SYImXgAQz40psM gDELNuES+y1I1SZda7P+mJmH8Co7iQrHKsH6PTP2ZADsiRFWFewKIuS1Yh15sMw3858m ova2xsQDxokCUNlX5eOYK0ZDaAyOt4vEcxMKEx1yQtq2FS2v9ru2WkBxQu+xMX+HPsCh HTsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706797503; x=1707402303; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3oik3gsH7UCRMxBdMG02de4OGV898umiHRSHwrLUdZI=; b=xMoOcaMVoTZQAK3GmteQ1hlFcmrPEFB+/V9Y6Dc4SgfS76NGVk0zj5QjcU+98VegEr WqquF2+/YPzXw9Cndk/Uco1BlVStv1Q+IZZirbLGEz3Cl+E8Amnoog+8JxADjbR9opyZ 0GqV90hw8eKtc5lDP8zW1sUZXmymYVCz1whZyScMV8nLwU3Wc5qoBAP07gAGeBaCMhYg +Apd/WS/aFZJSwAXKnipgIYOvBBgNp7JoBOM7e2b/tX4rCi1zxswe7Mlut351Z/UTIth o5m6A4ikSJgh6qToDx+EzEHW3QsTEJlB7PI59tTTR28iGz2u5ClEfMQA03YL9qoN+V30 orWw== X-Gm-Message-State: AOJu0YxfGWKMYwIs04aVc/ZgXLl69MPcooM9WSwpleMqNqgQobWqTV/4 d3KLV+Hit/CkRY78TD0sfps4bCKDuE7SozCIqrTZEPSa1mtY+zWULU02tEF4axR1q0ZyZ5ee5iu s2xBvxoDYUtFYOjw3j48bfS9O6bZbvGSnCci2 X-Received: by 2002:a17:903:41cb:b0:1d8:fc6f:e1da with SMTP id u11-20020a17090341cb00b001d8fc6fe1damr245879ple.2.1706797502666; Thu, 01 Feb 2024 06:25:02 -0800 (PST) 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> <20240201042236.1538928-4-irogers@google.com> <9d177173-c66f-a0d3-ba4d-2261f8663fce@arm.com> In-Reply-To: <9d177173-c66f-a0d3-ba4d-2261f8663fce@arm.com> From: Ian Rogers Date: Thu, 1 Feb 2024 06:24:51 -0800 Message-ID: Subject: Re: [PATCH v2 3/8] perf arm-spe/cs-etm: Directly iterate CPU maps To: James Clark Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , =?UTF-8?Q?Andr=C3=A9_Almeida?= , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 1, 2024 at 3:25=E2=80=AFAM James Clark wr= ote: > > > > On 01/02/2024 04:22, Ian Rogers wrote: > > 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/ut= il/cs-etm.c > > index 77e6663c1703..f4378ba0b8d6 100644 > > --- a/tools/perf/arch/arm/util/cs-etm.c > > +++ b/tools/perf/arch/arm/util/cs-etm.c > > @@ -197,38 +197,32 @@ static int cs_etm_validate_timestamp(struct auxtr= ace_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_requ= ested_cpus; > > struct perf_cpu_map *online_cpus =3D perf_cpu_map__new_online_cpu= s(); > > + struct perf_cpu_map *intersect_cpus =3D perf_cpu_map__intersect(e= vent_cpus, online_cpus); > > Hi Ian, > > This has the same issue as V1. 'any' intersect 'online' =3D=3D empty. Now= no > validation happens anymore. For this to be the same as it used to be, > validation has to happen on _all_ cores when event_cpus =3D=3D -1. So it > needs to be 'any' intersect 'online' =3D=3D 'online'. > > Same issue below with cs_etm_info_priv_size() Thanks James, sorry for the churn. I'll work on that for v3. Ian > Thanks > James > > > + struct perf_cpu cpu; > > > > - /* 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 wi= th. > > - * In per-thread case, the CPU map is empty. Since the t= raced > > - * program can run on any CPUs in this case, thus don't s= kip > > - * validation. > > - */ > > - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus) && > > - !perf_cpu_map__has(event_cpus, cpu)) > > - continue; > > - > > - if (!perf_cpu_map__has(online_cpus, cpu)) > > - continue; > > + perf_cpu_map__put(online_cpus); > > > > - err =3D cs_etm_validate_context_id(itr, evsel, i); > > + /* > > + * Set option of each CPU we have. In per-cpu case, do the valida= tion > > + * for CPUs to work with. In per-thread case, the CPU map is emp= ty. > > + * Since the traced program can run on any CPUs in this case, thu= s 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; > > } > > > > err =3D 0; > > out: > > - perf_cpu_map__put(online_cpus); > > + perf_cpu_map__put(intersect_cpus); > > return err; > > } > > > > @@ -435,7 +429,7 @@ static int cs_etm_recording_options(struct auxtrace= _record *itr, > > * Also the case of per-cpu mmaps, need the contextID in order to= be notified > > * when a context switch happened. > > */ > > - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { > > + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { > > evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, > > "timestamp", 1); > > evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, > > @@ -461,7 +455,7 @@ static int cs_etm_recording_options(struct auxtrace= _record *itr, > > evsel->core.attr.sample_period =3D 1; > > > > /* In per-cpu case, always need the time of mmap events etc */ > > - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) > > + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) > > evsel__set_sample_bit(evsel, TIME); > > > > err =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_c= pus; > > struct perf_cpu_map *online_cpus =3D perf_cpu_map__new_online_cpu= s(); > > + struct perf_cpu cpu; > > > > /* cpu map is not empty, we have specific CPUs to work with */ > > - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { > > - for (i =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); > > > > - if (cs_etm_is_ete(itr, i)) > > + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_c= pus) { > > + 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_recor= d *itr, > > return -EINVAL; > > > > /* If the cpu_map is empty all online CPUs are involved */ > > - if (perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { > > + if (perf_cpu_map__is_empty(event_cpus)) { > > cpu_map =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; > > > > - if (perf_cpu_map__has(event_cpus, cpu) && > > - !perf_cpu_map__has(online_cpus, cpu)) > > + perf_cpu_map__for_each_cpu(cpu, i, event_cpus) { > > + if (!perf_cpu_map__has(online_cpus, cpu)) > > return -EINVAL; > > } > > > > diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm= 64/util/arm-spe.c > > index 51ccbfd3d246..0b52e67edb3b 100644 > > --- a/tools/perf/arch/arm64/util/arm-spe.c > > +++ b/tools/perf/arch/arm64/util/arm-spe.c > > @@ -232,7 +232,7 @@ static int arm_spe_recording_options(struct auxtrac= e_record *itr, > > * In the case of per-cpu mmaps, sample CPU for AUX event; > > * also enable the timestamp tracing for samples correlation. > > */ > > - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { > > + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { > > evsel__set_sample_bit(arm_spe_evsel, CPU); > > evsel__set_config_if_unset(arm_spe_pmu, arm_spe_evsel, > > "ts_enable", 1); > > @@ -265,7 +265,7 @@ static int arm_spe_recording_options(struct auxtrac= e_record *itr, > > tracking_evsel->core.attr.sample_period =3D 1; > > > > /* In per-cpu case, always need the time of mmap events etc */ > > - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { > > + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { > > evsel__set_sample_bit(tracking_evsel, TIME); > > evsel__set_sample_bit(tracking_evsel, CPU); > >