From patchwork Wed May 24 22:18:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13254580 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 B90D4C77B73 for ; Wed, 24 May 2023 22:42:31 +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=tm+HMQGRoioTdRT3mKfkn1F+sYvyLF7vBWIKo3k0WLo=; b=hLVh/QdJMBaPNi sgu4GDs9qU+0b+SZCUtqlG00iqVbn7twm9QB4Xe98Z/Zpy+cg39cEIp1zvDCi+zNYGHXXwCAfL7BU 2bcdQTIKI7rV++/zUkW16UZ0Iz7u7rxToOcSz198ytmGBdqFLUnOmzDUV05U45zwnt/ndMhFH+Jt+ 6+syA/HL8sRoulZta3I6t5yOgwjFLakCdIYBZv5vU+khXOLY1uIUBcDq8K/9nejXUJ4r5U9YCHZ0X VST2VJR170CanNmhIdPJ9WDbY4hy8lbBAjcMqGJfyGW6cN23POgdJeAmJxXMCyIvTdXaESiJz1Y3e Ru0aCT9lgciiDluWuOaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q1xBH-00EpzR-0f; Wed, 24 May 2023 22:42:07 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1xB4-00Eps4-2P for linux-arm-kernel@bombadil.infradead.org; Wed, 24 May 2023 22:41:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Cy7gJw+E0ntMAmmRtEPYe8LOCyWrq0W20Q546Olgu7k=; b=WJGdL3SeXJnCC7AiY5a6Movj5b Gaxox3X4AWrGoWlMQBCsr/4IHC4/G9E/s8wwC+mIfvRv642rOgYNFQOIZuKit6XtSavygliEJapGc EohMr19cCnjpfQKR8kV84Q2b8W5VI6vPWklxeft5EbPtNEQA18LTOA8BLyxsbmrWhVxy6PvCcLhot 2x3Rv9m844uAkvnbBtPzAHW/sxEC2QLCFciLqu731UABPfGHdD5I5GII0B71dyFIU2bAa7TYLJ+XN 15/hdKdcALi1AgrHxpjI7z7jG6NFjSR0269Hw7YJDDfoQzzPADRlaBnZ/y2Cwl/64Qv9cW7MHiQVQ 6R0uPs+A==; Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q1woz-0056cF-1q for linux-arm-kernel@lists.infradead.org; Wed, 24 May 2023 22:19:08 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-56552a72cfbso29683667b3.3 for ; Wed, 24 May 2023 15:18:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1684966735; x=1687558735; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=Cy7gJw+E0ntMAmmRtEPYe8LOCyWrq0W20Q546Olgu7k=; b=mczbeLVP6vX9XhKEziiSA4SHBbGgx2XKtK4C8T3nL2qBfrmK8L0ktZhE+3H+9hl3wO vZBzFZdDzO387cRVpPmDkguqDFclulv6SykRF7vHY81JkGOb3sxhp1Jr7cAI2qNBeIco MKYHE6p0rfCgmH5GZ3JTHfaMHatUYVk/wSF4UxFUjqLXJFh3oBytoVa0EENGQJ4fuVF1 kM2BtrC35B9cQwKcRzeuKSH00qpZ7cthUKCBntTvCVwwX5aKebznc7SOtjQBl1NnYD7y A7P1KhlD3aEUqrQ2DS2ennyo05n4LJide3clV07VmLmnno5PPoUIi9vPNlmkIouyd6js R77w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684966735; x=1687558735; 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=Cy7gJw+E0ntMAmmRtEPYe8LOCyWrq0W20Q546Olgu7k=; b=lDPLVx56yziLlbl7TRq7FwaRXNc3EqMjYG/IbNyYEMAeysF/uNnG2+VZgQuXbYdc3Y V7FlX1/f1Bd4GmbbQKuj92ynU4vNNk3qVqC2JX3YwUlHYZFLLwQOUA5N9sCHWoLVGAdq m2eG7o1if8PFm2DDI6ZkrvG5ICLWWLu9uauufJJBHvO3c43hQlTrU4Ic+6BTEfHk5gAw o4UG9N/LDAyBDOlR3KGtS2y0oxKQkOCx4hvSFIya5p3LTOelYCRIYhXZN68jt2WAbd6w /BP9SFZaet1ny8zQBAHkvY1lo6bogs+F62q8fUHiIH+Kq892bzzlxZYVTqu8n585gHhK QQkw== X-Gm-Message-State: AC+VfDxMuzrWTjK4Oe4BB/kM2ckiLwQtial1CMwf3Z8w7ZHnSwqlGB0b r3d4fNBH1PlamPh9lykt6h/Lp/8OdVSH X-Google-Smtp-Source: ACHHUZ4+pI9OmzMNkQ1yM/rYnP9CZDetV7ZHH1aIpmqtDz+7oLUAKsSkrbsqtJtcIdRYOtffR7G25A/eVQXh X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:7aa7:3d2d:76ae:8e96]) (user=irogers job=sendgmr) by 2002:a81:b717:0:b0:560:d237:43dc with SMTP id v23-20020a81b717000000b00560d23743dcmr11977209ywh.3.1684966735605; Wed, 24 May 2023 15:18:55 -0700 (PDT) Date: Wed, 24 May 2023 15:18:05 -0700 In-Reply-To: <20230524221831.1741381-1-irogers@google.com> Message-Id: <20230524221831.1741381-10-irogers@google.com> Mime-Version: 1.0 References: <20230524221831.1741381-1-irogers@google.com> X-Mailer: git-send-email 2.40.1.698.g37aff9b760-goog Subject: [PATCH v3 09/35] 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230524_231906_434863_DBF45A18 X-CRM114-Status: GOOD ( 18.62 ) 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 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. Signed-off-by: Ian Rogers --- tools/lib/perf/evlist.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 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); }