From patchwork Wed Nov 29 06:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13472240 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8230BC07E98 for ; Wed, 29 Nov 2023 06:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=k0imnKUanZazLllsQ7QX75b6gyobRRMoriz8k7sD/rY=; b=gSzeWGC5mQxs/B aXsd7Zw7W7/5qoLRnS0xmzjkI0n/GFygVnbO8D+oS8i9w3cfFIBHabASqyXRCvz9jNF2Gze06SgvS 1+dGbvScf7Bq07aO8KKNia6P+bnMCPUzVPosIo8hXIUWAiRwcEOBca+cWB5xoLqLac0+eumH48JTZ Xao31EDFvbp89bha2xL2N2R0Quib5oN1QaJm8p7e1RWZlna3T6tR0Z5Liir7x/OzDNKYb7vP5xdgW S5a9a1SLZI1/y4cadi3ShlbYaIS15wu/kzqWRaXNr2aaHzlLky5okou/5bEWoXJ2AYKY3QIzNb6xj V8KJkk3KcSxsuvlTtIvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r8Dey-0079WY-0M; Wed, 29 Nov 2023 06:02:56 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r8Dea-00799g-2S for linux-arm-kernel@lists.infradead.org; Wed, 29 Nov 2023 06:02:35 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5cfd2325a06so51905607b3.1 for ; Tue, 28 Nov 2023 22:02:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701237751; x=1701842551; darn=lists.infradead.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=fls1hKYyOHnf3/bDsf3iPKJd0wwxSBN0A5pCMLik0gc=; b=Higev4BkO8zeGhkFgwM1aflNuAEBQ+Z4u75SZoSvTJyU8eHY4/lGfdD+rjU7Be4gdA /wVJ1tqCOIlANzBlwcRHKKb+UhNq4uXiM5yahgmYtSESo1Pjvw8lA8RHFWUQXhFYqwYf +u6OrbvAla5Ed/D07+GPUOVYc8m3ot4Sdbzc0v0dHo/wFa5HC9bZvRTMJo61gFdcK0V2 2RoTFEW4o89qub4W3uG9R/GZBcLtRUj/K4wL57Gg8aj2HGexOJNbJhaCSJVb4d7wmbAT AEroWWPTXvePcu0ovpi7RWOIfj9Oq/YNwmy7wxxzlXHMEeotz9btq3re0uCmXGHzoF76 Z63w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701237751; x=1701842551; 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=fls1hKYyOHnf3/bDsf3iPKJd0wwxSBN0A5pCMLik0gc=; b=SC7wuQhXLDhUngmzx4RnMtWGIXeLi6psReq2+1qHco/k5lFxMF3qAF8XD5gWZS1DHO O8S8aRpKHPn7jBTIE2Q9Lay5OyRaMMYz/xLTymkLciqrv+iBpjcewtXxmYFjosQMpoVb 5Q8FZzoBXk9CoYucRJ77VyyyU9PckWJ0zaZXxxZdM4u6LQ4pqlUGw2XXQpKLW/CUbzq5 aWEyjFhsH/6KVxat4ItxJj5eSEMa2jzzuk6RasInLNhnbnqzDFy6qhKTqVpueiFCNIgb Bpb7AlV01WvVrawMKxweYBk0Zdh66CwNtE3G9TGSR0+J/SzNLWn7OWhnMpE8t9Dbe4Fk rzJg== X-Gm-Message-State: AOJu0YwOY7CqrqWaxU780AI8SywOqrKNbWp+5K7SZfwP9rKTvtUmvj4n wBg2OOBw1HjxEGrfBzlU1L3UkXrWmFAG X-Google-Smtp-Source: AGHT+IE+lyuX8dfYIgqcySLvvqClEvuXw1syxnF2VGdznLlQKEF0kdQlIAQFG3Eq5mP6kXDREMLbGDtcMcML X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:763b:80fa:23ca:96f8]) (user=irogers job=sendgmr) by 2002:a05:690c:470e:b0:5cb:d80c:3d34 with SMTP id gz14-20020a05690c470e00b005cbd80c3d34mr370105ywb.8.1701237751669; Tue, 28 Nov 2023 22:02:31 -0800 (PST) Date: Tue, 28 Nov 2023 22:02:04 -0800 In-Reply-To: <20231129060211.1890454-1-irogers@google.com> Message-Id: <20231129060211.1890454-8-irogers@google.com> Mime-Version: 1.0 References: <20231129060211.1890454-1-irogers@google.com> X-Mailer: git-send-email 2.43.0.rc1.413.gea7ed67945-goog Subject: [PATCH v1 07/14] perf arm-spe/cs-etm: Directly iterate CPU maps From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Thomas Gleixner , Darren Hart , Davidlohr Bueso , " =?utf-8?q?Andr=C3=A9_Almeida?= " , Kan Liang , K Prateek Nayak , Sean Christopherson , Paolo Bonzini , Kajol Jain , Athira Rajeev , Andrew Jones , Alexandre Ghiti , Atish Patra , "Steinar H. Gunderson" , Yang Jihong , Yang Li , Changbin Du , Sandipan Das , Ravi Bangoria , Paran Lee , Nick Desaulniers , Huacai Chen , Yanteng Si , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231128_220232_825867_AD24EF70 X-CRM114-Status: GOOD ( 24.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Rather than iterate all CPUs and see if they are in CPU maps, directly iterate the CPU map. Similarly make use of the intersect function. Switch perf_cpu_map__has_any_cpu_or_is_empty to more appropriate alternatives. Signed-off-by: Ian Rogers --- tools/perf/arch/arm/util/cs-etm.c | 77 ++++++++++++---------------- tools/perf/arch/arm64/util/arm-spe.c | 4 +- 2 files changed, 34 insertions(+), 47 deletions(-) diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index 77e6663c1703..a68a72f2f668 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -197,38 +197,32 @@ static int cs_etm_validate_timestamp(struct auxtrace_record *itr, static int cs_etm_validate_config(struct auxtrace_record *itr, struct evsel *evsel) { - int i, err = -EINVAL; + int idx, err = -EINVAL; struct perf_cpu_map *event_cpus = evsel->evlist->core.user_requested_cpus; struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); + struct perf_cpu_map *intersect_cpus = perf_cpu_map__intersect(event_cpus, online_cpus); + struct perf_cpu cpu; - /* Set option of each CPU we have */ - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; - - /* - * In per-cpu case, do the validation for CPUs to work with. - * In per-thread case, the CPU map is empty. Since the traced - * program can run on any CPUs in this case, thus don't skip - * validation. - */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus) && - !perf_cpu_map__has(event_cpus, cpu)) - continue; - - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; + perf_cpu_map__put(online_cpus); - err = cs_etm_validate_context_id(itr, evsel, i); + /* + * Set option of each CPU we have. In per-cpu case, do the validation + * for CPUs to work with. In per-thread case, the CPU map is empty. + * Since the traced program can run on any CPUs in this case, thus don't + * skip validation. + */ + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { + err = cs_etm_validate_context_id(itr, evsel, cpu.cpu); if (err) goto out; - err = cs_etm_validate_timestamp(itr, evsel, i); + err = cs_etm_validate_timestamp(itr, evsel, idx); if (err) goto out; } err = 0; out: - perf_cpu_map__put(online_cpus); + perf_cpu_map__put(intersect_cpus); return err; } @@ -435,7 +429,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, * Also the case of per-cpu mmaps, need the contextID in order to be notified * when a context switch happened. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, "timestamp", 1); evsel__set_config_if_unset(cs_etm_pmu, cs_etm_evsel, @@ -461,7 +455,7 @@ static int cs_etm_recording_options(struct auxtrace_record *itr, evsel->core.attr.sample_period = 1; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) evsel__set_sample_bit(evsel, TIME); err = cs_etm_validate_config(itr, cs_etm_evsel); @@ -533,38 +527,32 @@ static size_t cs_etm_info_priv_size(struct auxtrace_record *itr __maybe_unused, struct evlist *evlist __maybe_unused) { - int i; + int idx; int etmv3 = 0, etmv4 = 0, ete = 0; struct perf_cpu_map *event_cpus = evlist->core.user_requested_cpus; struct perf_cpu_map *online_cpus = perf_cpu_map__new_online_cpus(); + struct perf_cpu cpu; /* cpu map is not empty, we have specific CPUs to work with */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; - - if (!perf_cpu_map__has(event_cpus, cpu) || - !perf_cpu_map__has(online_cpus, cpu)) - continue; + if (!perf_cpu_map__is_empty(event_cpus)) { + struct perf_cpu_map *intersect_cpus = + perf_cpu_map__intersect(event_cpus, online_cpus); - if (cs_etm_is_ete(itr, i)) + perf_cpu_map__for_each_cpu_skip_any(cpu, idx, intersect_cpus) { + if (cs_etm_is_ete(itr, cpu.cpu)) ete++; - else if (cs_etm_is_etmv4(itr, i)) + else if (cs_etm_is_etmv4(itr, cpu.cpu)) etmv4++; else etmv3++; } + perf_cpu_map__put(intersect_cpus); } else { /* get configuration for all CPUs in the system */ - for (i = 0; i < cpu__max_cpu().cpu; i++) { - struct perf_cpu cpu = { .cpu = i, }; - - if (!perf_cpu_map__has(online_cpus, cpu)) - continue; - - if (cs_etm_is_ete(itr, i)) + perf_cpu_map__for_each_cpu(cpu, idx, online_cpus) { + if (cs_etm_is_ete(itr, cpu.cpu)) ete++; - else if (cs_etm_is_etmv4(itr, i)) + else if (cs_etm_is_etmv4(itr, cpu.cpu)) etmv4++; else etmv3++; @@ -814,15 +802,14 @@ static int cs_etm_info_fill(struct auxtrace_record *itr, return -EINVAL; /* If the cpu_map is empty all online CPUs are involved */ - if (perf_cpu_map__has_any_cpu_or_is_empty(event_cpus)) { + if (perf_cpu_map__is_empty(event_cpus)) { cpu_map = online_cpus; } else { /* Make sure all specified CPUs are online */ - for (i = 0; i < perf_cpu_map__nr(event_cpus); i++) { - struct perf_cpu cpu = { .cpu = i, }; + struct perf_cpu cpu; - if (perf_cpu_map__has(event_cpus, cpu) && - !perf_cpu_map__has(online_cpus, cpu)) + perf_cpu_map__for_each_cpu(cpu, i, event_cpus) { + if (!perf_cpu_map__has(online_cpus, cpu)) return -EINVAL; } diff --git a/tools/perf/arch/arm64/util/arm-spe.c b/tools/perf/arch/arm64/util/arm-spe.c index 51ccbfd3d246..0b52e67edb3b 100644 --- a/tools/perf/arch/arm64/util/arm-spe.c +++ b/tools/perf/arch/arm64/util/arm-spe.c @@ -232,7 +232,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, * In the case of per-cpu mmaps, sample CPU for AUX event; * also enable the timestamp tracing for samples correlation. */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(arm_spe_evsel, CPU); evsel__set_config_if_unset(arm_spe_pmu, arm_spe_evsel, "ts_enable", 1); @@ -265,7 +265,7 @@ static int arm_spe_recording_options(struct auxtrace_record *itr, tracking_evsel->core.attr.sample_period = 1; /* In per-cpu case, always need the time of mmap events etc */ - if (!perf_cpu_map__has_any_cpu_or_is_empty(cpus)) { + if (!perf_cpu_map__is_any_cpu_or_is_empty(cpus)) { evsel__set_sample_bit(tracking_evsel, TIME); evsel__set_sample_bit(tracking_evsel, CPU);