From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D8E5C77B73 for ; Fri, 26 May 2023 21:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244193AbjEZVzJ (ORCPT ); Fri, 26 May 2023 17:55:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244157AbjEZVyt (ORCPT ); Fri, 26 May 2023 17:54:49 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B394FE66 for ; Fri, 26 May 2023 14:54:35 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-561bad0999aso31284027b3.0 for ; Fri, 26 May 2023 14:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138074; x=1687730074; 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=uEP9U0nKmj8Ymr7ZepfrEW5aT5lelMPt3agjhkx5Hd62wHoNVyQhPIarzyb93cTaof qEF+JjQRput/yCXcaSUK5c1Y8Wi10/o9AbUmWWegqf0kGgW9uFoDO4soCi43EdVVKJd6 DnW5dGgnk6Km784NW11TV6D4IV4hTP8xcRzkmg4p23zhYWpZVgGVoBBkYr5blhiSHZ7s vszRrPl3ILHCVfGuPJhQ/110ab+lNdLR2JIKoQQQEe4oJj0dtKVuP4NNXHgU1v6AQrgD qwyf2BrAM6o97lBuBJetI3C+KdgQNUVXjHFi1IL1DVK0PPXiy7Q3f8KtllQeWaSkVlsN paQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138074; x=1687730074; 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=MgcpJK3dl/rI2LVbP4IBG8O5aHn1mSWNQN3DeDbxNxamUYJz02xzu3GAy+MGepMlmz JlEWruf09NeyfRkA0yIqNfqvfsUS2lunbZxM9kGt8GwN6sa2Y2pBnD7PHFza4q0LY29h /+2DpeyJVL+xi7adQJb6582ViyEIU00M2YNKy7ciuORtYOaWr/22lre6zn1QM3XzIWVS mBiIe4fBv/y6k02gamS3j1MQA1eKowdhV/xbPHdgSGB0Is1HuVDCp4fRSoOHsOg/5Kup x9GT4+h2zHMtS5fn7bFuuyX9bomAv2c0y8lrx+eHdRwu31E0zbtI/onaO/B0QvrQiNqp IMuQ== X-Gm-Message-State: AC+VfDxIrXaa4KAvN0PWWtGVSrPQc8B/liOfO0tVtLzgI6UVhxQ3C2v2 jfWmqqY1Vfrt3MGJnwWgs1ZQ7n7eCESw X-Google-Smtp-Source: ACHHUZ5T/7yAUIvjTc4+VaRWlhjcegjXRqmqsz6bUjSqb1T23XSW4W+5lov5726eTFuZg5EgBmj4O/Ky+rzg X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:de06:0:b0:561:856f:69d3 with SMTP id k6-20020a81de06000000b00561856f69d3mr1828697ywj.7.1685138074694; Fri, 26 May 2023 14:54:34 -0700 (PDT) Date: Fri, 26 May 2023 14:53:44 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-10-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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 Content-Type: text/plain; charset="UTF-8" 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 From mboxrd@z Thu Jan 1 00:00:00 1970 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 5A2E1C7EE23 for ; Fri, 26 May 2023 22:41: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=fhRceLReb21qlVc36yMFknqObFAPxlOduvpu3kUR3DE=; b=yqG/6f78dLroLm ZbpXGx4kAEodUIEVgs9MBhasoXxODiOC6suTZATINfWidGWWKhTca2lBKxC6VxBYcqxfh8pM36tmH kH+4GaRl18nA+BCZdI4AenWVtkkRCQzdTD4NFr1I4p9P8VAiFLSINDAMfJE0ZSyBMJElOngn3HnBQ LO162WuKat75YVxdNyD5Mo5aCshC0BEBOTgIV5/qDz/e5HofKo6G6N6JtaNkkiwIEE1oWwF/FthFB 2Xrmk17Qc7Wbl1BCPHdWvFEqDkMiprsnID1e+ftTDqcOweMNwRW6KRHVbJHnGwr6Y3AeUg58GblF7 RLeQdcmjU3CbwR4u06Kw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1q2g79-004A4u-0U; Fri, 26 May 2023 22:40:51 +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 1q2g6l-0049ty-20 for linux-arm-kernel@bombadil.infradead.org; Fri, 26 May 2023 22:40:27 +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=6VCKvRGvQOyrxybTaQrpXvOpYk1EydxEOVUgh/PqmgI=; b=KX8VUG2z9BwPuNapql7k8eHpao YwZLDcNbggSKCU9jb8B+Unh/G07ZMpZmfKR0yzppHjQoDXx7kcMfJE0m4WBaeC9hUXsFYnFoSLATV X0lPan3w4+8wBEvTWaf0ImFErasV+wt1ksDpMNbO81UQMmhBPjwy6mD3eQbpuDah6xGGLdI/hzrZ6 k2GtqnN11K7Vf2p2ejKH0aPNX/cYgzxcuIeSEpaPOTnGbhJnPxmal115U412ZKFuYWfX7/P+XkA0v 1FMB6ewFvNxFqgk6JkG27+yaBhL6R87LEI8cYYTD8wLAVqFSPwWUn2UloiZASmgyNaFSRxBqW+b60 6yM2Xdyw==; Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1q2fOP-007ipb-0A for linux-arm-kernel@lists.infradead.org; Fri, 26 May 2023 21:54:38 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5654c7f991bso30763727b3.3 for ; Fri, 26 May 2023 14:54:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685138074; x=1687730074; 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=uEP9U0nKmj8Ymr7ZepfrEW5aT5lelMPt3agjhkx5Hd62wHoNVyQhPIarzyb93cTaof qEF+JjQRput/yCXcaSUK5c1Y8Wi10/o9AbUmWWegqf0kGgW9uFoDO4soCi43EdVVKJd6 DnW5dGgnk6Km784NW11TV6D4IV4hTP8xcRzkmg4p23zhYWpZVgGVoBBkYr5blhiSHZ7s vszRrPl3ILHCVfGuPJhQ/110ab+lNdLR2JIKoQQQEe4oJj0dtKVuP4NNXHgU1v6AQrgD qwyf2BrAM6o97lBuBJetI3C+KdgQNUVXjHFi1IL1DVK0PPXiy7Q3f8KtllQeWaSkVlsN paQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685138074; x=1687730074; 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=L55CB8Ni9yd3VzD0g22F+GFmeIxfb9Ht+JkZC0xVmz1z4fkJMMCOS2mhKkwLRcI5ln jSDPrcAmGLmY7fBszeMR32AmbMba5/Nh0uBmOsZgU/17orgRV+OgKEa1w9MC48AmrBbt M/0KOzg5WQlu36lhtw2U/j0E3639QLOY02OumvHL+z41gEgk73y5G2vTEpVSTYiO1cNA XsubsnWL9pWTItTfeVHmAZOChlntTaSoBFljnCSUxW8Hjquipk8Ws+IqesAq3mB+udNx Sevxhjk9acEeNzWW/lcsdbCAIxyjRDBLSuz8bwZTP0ozVMbFgF6LgOmFCm5lVOCjbL3P oDwA== X-Gm-Message-State: AC+VfDxBFOdRDy9/ZtWhf8PyoLsgxgG0rD3kgWxPXPcYBARKvqTgEPPG au/eytbSR4QWMhCY7p2NKwsqXrqslrvV X-Google-Smtp-Source: ACHHUZ5T/7yAUIvjTc4+VaRWlhjcegjXRqmqsz6bUjSqb1T23XSW4W+5lov5726eTFuZg5EgBmj4O/Ky+rzg X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:3b4e:312c:644:a642]) (user=irogers job=sendgmr) by 2002:a81:de06:0:b0:561:856f:69d3 with SMTP id k6-20020a81de06000000b00561856f69d3mr1828697ywj.7.1685138074694; Fri, 26 May 2023 14:54:34 -0700 (PDT) Date: Fri, 26 May 2023 14:53:44 -0700 In-Reply-To: <20230526215410.2435674-1-irogers@google.com> Message-Id: <20230526215410.2435674-10-irogers@google.com> Mime-Version: 1.0 References: <20230526215410.2435674-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog Subject: [PATCH v4 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-20230526_225437_149123_D249BD93 X-CRM114-Status: GOOD ( 21.14 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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. 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel