Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp477202rwd; Sat, 27 May 2023 00:41:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5PHRSHV0xsZw8xDQ0m7LPe96kwrQ2WajIrXI9Wux63U3K8GVvDNXErazTLa3iqPTGNX/7J X-Received: by 2002:a05:6a21:6d8b:b0:10a:99a9:cb4b with SMTP id wl11-20020a056a216d8b00b0010a99a9cb4bmr2007996pzb.12.1685173315285; Sat, 27 May 2023 00:41:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685173315; cv=none; d=google.com; s=arc-20160816; b=LLtN6PrPZWsQ8HGb6TQM3jELKIIL493Ul1RxpTMhvOB8Dbj6PSkcUuE3aCRWD9srmB hY1DFxaX4KnDE4Gj9QpUbktJBtQmx/zrVnu5WLzAg5W+GB1nzbu8CgOw9JqMEdfxIhgk o5qVHm1TFyEwUcQabpXzTGWusSgfldfMZkTwt6u8e+AMz0LavE6PN0Xl4EHJUKkrwRfE 9OyFaqI8NKFedjPTnSJ6afFsRFU+1/uVb39XmwRspbAu7K6rflG+MErnbwaCD9L9tIAq Xx4/5IskLRKsg3NGGm0Qm42Q7ciXL/ktrFEylT2Por4WTNxKGrHfvJvkQM9LnU+HhCkv gS/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=6VCKvRGvQOyrxybTaQrpXvOpYk1EydxEOVUgh/PqmgI=; b=FXqG6RBZyi5F0kJSmTCr0z6O6uVXQIw2mu6ohmDkbX+SsVSkWI4TNhqlcxgZxot3cA 9XAWVEvbbZlPq6hnCnRjNhg6gZEFTuE6M6/EQr4Z1VuEqu6Hyn2KdSIxVksNDdicoY2A jLZ0awefRWmRXXOEcdQ4GWFfkxLJS/A6OAthwGYXyEFM9g236WtMZ0s2HIW43Uo9SrRW RT751jNsO+q7+h3ukEq0NNaqe2Kn0Rlx6rrRmiqbrvMpT6OCR/vd73cHh4xaAr4s2+n2 M1DijM0d0id7eeiT5jqA4lUX87yQMSRBkZsoOd/b89ThTn1UTWgX0GaQpz1KWCVptO1p m3Mg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=yV1YZNOs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020a637114000000b00502f0d858e9si4188757pgc.174.2023.05.27.00.41.43; Sat, 27 May 2023 00:41:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=yV1YZNOs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231793AbjE0HXS (ORCPT + 99 others); Sat, 27 May 2023 03:23:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231583AbjE0HXD (ORCPT ); Sat, 27 May 2023 03:23:03 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2554E61 for ; Sat, 27 May 2023 00:22:52 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-ba8c3186735so3209461276.3 for ; Sat, 27 May 2023 00:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685172172; x=1687764172; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=6VCKvRGvQOyrxybTaQrpXvOpYk1EydxEOVUgh/PqmgI=; b=yV1YZNOsvfeF4Ft293I2i0bt5grnyJq5eVrNGq/gtSC3F/RgJNaIZhMktW37517hxO rof3nnNYGR/xHOPf25XZqdFVhDeQXyElDr5mQE/HnNITL60AcuZ0Q4xLCR8Po5aWKycf cg26fe0UkDqsuMJP2PbvP4i2YEZKPeV/TC6PHtTivv7tQzoVb06r3uWpM1G1qSi/dhIN dTl2NIeqYJjyTILMSjOxLZiiOhs8MfVJNJpuvSEGaHjlDrvPPyFBDG2Uy1O/6YwW6y1D Z/KMbDXZpkXpfOJosj4KbCDjkf6SnPGvaTheTL0xAm83+xHi4G8/Z3wtNq/ExN3NiZ9V LA7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685172172; x=1687764172; 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=6VCKvRGvQOyrxybTaQrpXvOpYk1EydxEOVUgh/PqmgI=; b=RkyvdBd25qfVd+NURtTcTD4BHS7kz0jyOVg8aGFC5p3Ec+sAc848/UUhwQs5saiscp r1G8Te8uShCQczV521MIshduX0aW9yhSrgG3Gg6eM81sBqZkNpQLtfJI30DbYaZ8sdQr hPOFys8GtBvUBJKjEc7gc1Tgx/jq8CF6CG4TLKZLHSI12YubujNoTK0Q9/pcHIycoXp1 iFPBbewLI07AaI4hw1hCw25HePbpCaNJDnPgYITI79L8N+Ub2AhFb4h7mR0h4sig+BdT Ay51kXlR0TtDonbnHaSk33exoD26ZLLhm9DHkEMsBmR+FfK/vxxVOwckVRTKKV47sBJW 9XGA== X-Gm-Message-State: AC+VfDxYvbNKr2CHz/Gk17N1gHRhYwkxivKkB7I/hr4UAv429sL5gbx9 GaOyuDyaslTbYF5mmr9Q7U6T+cBeoCCZ X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a25:8211:0:b0:ba7:5bec:7772 with SMTP id q17-20020a258211000000b00ba75bec7772mr1632189ybk.5.1685172171783; Sat, 27 May 2023 00:22:51 -0700 (PDT) Date: Sat, 27 May 2023 00:21:44 -0700 In-Reply-To: <20230527072210.2900565-1-irogers@google.com> Message-Id: <20230527072210.2900565-9-irogers@google.com> Mime-Version: 1.0 References: <20230527072210.2900565-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v5 08/34] perf evlist: Propagate user CPU maps intersecting core PMU maps From: Ian Rogers To: Suzuki K Poulose , Mike Leach , Leo Yan , John Garry , Will Deacon , James Clark , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , Kajol Jain , Jing Zhang , Kan Liang , Zhengjun Xing , Ravi Bangoria , Madhavan Srinivasan , Athira Rajeev , Ming Wang , Huacai Chen , Sandipan Das , Dmitrii Dolgov <9erthalion6@gmail.com>, Sean Christopherson , Ali Saidi , Rob Herring , Thomas Richter , Kang Minchul , linux-kernel@vger.kernel.org, coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The CPU map for a non-core PMU gives a default CPU value for perf_event_open. For core PMUs the CPU map lists all CPUs the evsel may be opened on. If there are >1 core PMU, the CPU maps will list the CPUs for that core PMU, but the user_requested_cpus may contain CPUs that are invalid for the PMU and cause perf_event_open to fail. To avoid this, when propagating the CPU map for core PMUs intersect it with the CPU map of the PMU (the evsel's "own_cpus"). Add comments to __perf_evlist__propagate_maps to explain its somewhat complex behavior. Fix the related comments for system_wide in struct perf_evsel. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang --- tools/lib/perf/evlist.c | 25 ++++++++++++++++++++----- tools/lib/perf/include/internal/evsel.h | 6 +++--- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/tools/lib/perf/evlist.c b/tools/lib/perf/evlist.c index 81e8b5fcd8ba..b8b066d0dc5e 100644 --- a/tools/lib/perf/evlist.c +++ b/tools/lib/perf/evlist.c @@ -36,18 +36,33 @@ void perf_evlist__init(struct perf_evlist *evlist) static void __perf_evlist__propagate_maps(struct perf_evlist *evlist, struct perf_evsel *evsel) { - /* - * We already have cpus for evsel (via PMU sysfs) so - * keep it, if there's no target cpu list defined. - */ if (evsel->system_wide) { + /* System wide: set the cpu map of the evsel to all online CPUs. */ perf_cpu_map__put(evsel->cpus); evsel->cpus = perf_cpu_map__new(NULL); + } else if (evlist->has_user_cpus && evsel->is_pmu_core) { + /* + * User requested CPUs on a core PMU, ensure the requested CPUs + * are valid by intersecting with those of the PMU. + */ + perf_cpu_map__put(evsel->cpus); + evsel->cpus = perf_cpu_map__intersect(evlist->user_requested_cpus, evsel->own_cpus); } else if (!evsel->own_cpus || evlist->has_user_cpus || - (!evsel->requires_cpu && perf_cpu_map__empty(evlist->user_requested_cpus))) { + (!evsel->requires_cpu && perf_cpu_map__has_any_cpu(evlist->user_requested_cpus))) { + /* + * The PMU didn't specify a default cpu map, this isn't a core + * event and the user requested CPUs or the evlist user + * requested CPUs have the "any CPU" (aka dummy) CPU value. In + * which case use the user requested CPUs rather than the PMU + * ones. + */ perf_cpu_map__put(evsel->cpus); evsel->cpus = perf_cpu_map__get(evlist->user_requested_cpus); } else if (evsel->cpus != evsel->own_cpus) { + /* + * No user requested cpu map but the PMU cpu map doesn't match + * the evsel's. Reset it back to the PMU cpu map. + */ perf_cpu_map__put(evsel->cpus); evsel->cpus = perf_cpu_map__get(evsel->own_cpus); } diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h index 4d6f2a032f45..5cd220a61962 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -62,9 +62,9 @@ struct perf_evsel { int nr_members; /* * system_wide is for events that need to be on every CPU, irrespective - * of user requested CPUs or threads. Map propagation will set cpus to - * this event's own_cpus, whereby they will contribute to evlist - * all_cpus. + * of user requested CPUs or threads. Tha main example of this is the + * dummy event. Map propagation will set cpus for this event to all CPUs + * as software PMU events like dummy, have a CPU map that is empty. */ bool system_wide; /* -- 2.41.0.rc0.172.g3f132b7071-goog