From patchwork Thu Sep 26 14:48:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13813438 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 175E0CDE00E for ; Thu, 26 Sep 2024 14:55: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:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AWSJTlcUZqJc1Q72aDywG6mEPNHoFW3+x51bKeYfGjU=; b=OYWqw/Opt0UsUgq8AJuTffYQ60 IdXFJ0Ts5G4EI/kIWZ6Ap5dkACHYEgxXmEpowyn/qTgrHHesx/vrgMwVyJh5ffROQFQ/Wt7lhiy8S h2O5lXTKcnPYE6uBeLJctxycQKZOGApFRVUoY9ROeFnf0DwY+qikDzZn2b+sWUHYwsvTpmiOcBwZE FCmkPddOB6FAdiWQoZHoCl0/Qo2UkrCq6udVSG4KYz3/ztpUL2kt1e/V9KONblksyj7jb19Ti8raP 2j45K1xhD2qah5RgKnVVrfMA58d2j3tyql2bwlEcqtoHTfIVo6bvPCfS6gU4U5n+mzZp8YFY1R1EC d0BKmdNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stpto-00000008fTb-2tno; Thu, 26 Sep 2024 14:55:20 +0000 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stpoj-00000008eNW-3E39 for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 14:50:07 +0000 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a8d56155f51so129787166b.2 for ; Thu, 26 Sep 2024 07:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727362204; x=1727967004; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=AWSJTlcUZqJc1Q72aDywG6mEPNHoFW3+x51bKeYfGjU=; b=rQUTKQAniCYI2cNIQNaFCjihicYFvyDZivsOpnykL0vlNe/+FJ+Okw4qgM9DGlgB1Q ftRo4GYL5LlB3+uLRuC04kUr+7D6FgZ+tFWUEvxVS510dvTK2z5gGbhquZFOHBiXojMy Yk0rxCCmTqgb0Y/3CDexFxouEJcV/bcPj7mOjZy+ImIyaOEAOqJ9tQW60aTwB31lispL KuIUI+PC0KoggcSJnsMSsaAxkfoWMndrx+Aj+o+Hssg5H4ceYnEQuQjFyZbs8uWAzc0K dv5EJOzjiys3tP11tJX3vNQQ+wrvw2zz9uDUTg/RBrnnn8CSwN8RpXrbI7P6DgXigucR XOBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727362204; x=1727967004; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AWSJTlcUZqJc1Q72aDywG6mEPNHoFW3+x51bKeYfGjU=; b=CnUu4zHTaVZoaqwcr9tcB+NTM1Z+hDQ/Z0QrGHY90MyrApDtQKqJbNx94bVgzQXRUp 8fYmoHCnM/WKZIMytSLpB1TVAL8nGK0qtbWZDskKF+uA9pFAjGSDNAYjriXB+cdZynd9 ifKbbNzwqyHOm37R2vtOTML+Pv1TAHHlAjL/kmc+kg2vL5hqL6xX4R7fZaWAeSGdta9v QmmQSXAzr/Z2Ou1G/ckdKsu//oCBEQuvyriqqxloxytGM54WKp+qomkm9pDWkvKFlEvj shRpFa6Dd026kSoFuLJg9BPNr2XVOgJ7gimCvCTMQ9XIir605HmjJjLirF0rutprvFdW qoUw== X-Forwarded-Encrypted: i=1; AJvYcCX9NT2t7IHmfPJCqu86OiGLAMP9wyIrpFMpbIcYf9wwOD3bq4p8M/PH8zaSkfUhY/QytrzghKGlaaWVcvvIjMHg@lists.infradead.org X-Gm-Message-State: AOJu0YwzZa0D0Gm3z+YuiEClkFBUfTQjO8cMWf4tYPtJr4Iqn0zMqh8c hM8z7H2RF7ErTxY4gN8rFecbwgeown2qqCXF8UU3nTvcssDHmZSpFq9YWDbrPL0= X-Google-Smtp-Source: AGHT+IFVb7sSRn39qxyC7VnF93ZMoZ0TZHVjg1NjGZKl+w/BNqbLDXtVjbZLiCJ0Q6lmV8piIlggjA== X-Received: by 2002:a17:906:dc8f:b0:a86:83f8:f5a2 with SMTP id a640c23a62f3a-a93a038c991mr608744466b.19.1727362204313; Thu, 26 Sep 2024 07:50:04 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c294833asm5589966b.98.2024.09.26.07.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2024 07:50:03 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com, namhyung@kernel.org Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Dominique Martinet , Athira Rajeev , Yang Jihong , Colin Ian King , Howard Chu , Ze Gao , Yunseong Kim , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 4/7] perf evsel x86: Make evsel__has_perf_metrics work for legacy events Date: Thu, 26 Sep 2024 15:48:35 +0100 Message-Id: <20240926144851.245903-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240926144851.245903-1-james.clark@linaro.org> References: <20240926144851.245903-1-james.clark@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_075005_848275_162E6F4D X-CRM114-Status: GOOD ( 21.82 ) 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 From: Ian Rogers Use PMU interface to better detect core PMU for legacy events. Look for slots event on core PMU if it is appropriate for the event. Acked-by: Namhyung Kim Signed-off-by: Ian Rogers Acked-by: Kan Liang Signed-off-by: James Clark --- tools/perf/arch/x86/util/evsel.c | 31 ++++++++++++++++++++++++++----- tools/perf/util/pmu.c | 2 +- tools/perf/util/pmu.h | 1 + 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c index 090d0f371891..ec2ac3bbb76f 100644 --- a/tools/perf/arch/x86/util/evsel.c +++ b/tools/perf/arch/x86/util/evsel.c @@ -21,7 +21,8 @@ void arch_evsel__set_sample_weight(struct evsel *evsel) /* Check whether the evsel's PMU supports the perf metrics */ bool evsel__sys_has_perf_metrics(const struct evsel *evsel) { - const char *pmu_name = evsel->pmu_name ? evsel->pmu_name : "cpu"; + struct perf_pmu *pmu; + u32 type = evsel->core.attr.type; /* * The PERF_TYPE_RAW type is the core PMU type, e.g., "cpu" PMU @@ -31,11 +32,31 @@ bool evsel__sys_has_perf_metrics(const struct evsel *evsel) * Checking both the PERF_TYPE_RAW type and the slots event * should be good enough to detect the perf metrics feature. */ - if ((evsel->core.attr.type == PERF_TYPE_RAW) && - perf_pmus__have_event(pmu_name, "slots")) - return true; +again: + switch (type) { + case PERF_TYPE_HARDWARE: + case PERF_TYPE_HW_CACHE: + type = evsel->core.attr.config >> PERF_PMU_TYPE_SHIFT; + if (type) + goto again; + break; + case PERF_TYPE_RAW: + break; + default: + return false; + } + + pmu = evsel->pmu; + if (pmu && perf_pmu__is_fake(pmu)) + pmu = NULL; - return false; + if (!pmu) { + while ((pmu = perf_pmus__scan_core(pmu)) != NULL) { + if (pmu->type == PERF_TYPE_RAW) + break; + } + } + return pmu && perf_pmu__have_event(pmu, "slots"); } bool arch_evsel__must_be_in_group(const struct evsel *evsel) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index e32d601b48f1..8993b5853687 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -1168,7 +1168,7 @@ struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pm return pmu; } -static bool perf_pmu__is_fake(const struct perf_pmu *pmu) +bool perf_pmu__is_fake(const struct perf_pmu *pmu) { return pmu->type == PERF_PMU_TYPE_FAKE; } diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index f4271395c374..d352d53b8d55 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -281,5 +281,6 @@ struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *core_pm void perf_pmu__delete(struct perf_pmu *pmu); struct perf_pmu *perf_pmus__find_core_pmu(void); const char *perf_pmu__name_from_config(struct perf_pmu *pmu, u64 config); +bool perf_pmu__is_fake(const struct perf_pmu *pmu); #endif /* __PMU_H */