From patchwork Wed Sep 25 14:13:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13812039 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 0704FCF9C6F for ; Wed, 25 Sep 2024 14:21:10 +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=hbrFzlrnUu+8X/JET7kR2akCW+mI8AJmFw0wQB6l0Uw=; b=XIMtKVOyBfF/+dGW4uqJO6jwfo DHgEIm+63JfPLvMNSHcLDhBWrDTXp+2QfvyEwGv8LVdzJLkKWoOSEVR//om5IXwlSm3Sd1kHjx4kB WD+IqhP83uHLFPXRA+snpeh0oLK6anFsNCCAlpy7FpmLzV3pcVZODDBTNQS47nyKYzNB8m1NXO0iG QYsQTeWDvAotgLpLFWtqSo4l8rB4y85JiRI36MzaUEI0PnuloQVXYyOfvQuift5ktlSaAB8vcZ5YO Il7fPyw62DufpnP1xliZHg98lBhR5qgwYpwSE+iTbazD3kS8tH1Q1Lf6LUm8BbChjkdDEndVp+AJb u+2Ujyuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stSsw-00000005b61-1HAi; Wed, 25 Sep 2024 14:20:54 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stSny-00000005ZdM-1UPG for linux-arm-kernel@lists.infradead.org; Wed, 25 Sep 2024 14:15:47 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-5c5b6161022so6752079a12.3 for ; Wed, 25 Sep 2024 07:15:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727273745; x=1727878545; 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=hbrFzlrnUu+8X/JET7kR2akCW+mI8AJmFw0wQB6l0Uw=; b=Ko3MbAcFEUClRPoWx2z2JbqclXBkgULnTvnLvThyVwZ1icsBIy2d/Kxs99Lqw9gphP xE0nkJIIwD0t7XzljU6GAE2vL3vIo40PxndnHf2wXUCQmf+TyjB4WdLJLgQ1U2WN4dSt qy+fbsCUYhaU7N3OIZf/PadLLdqnFGGEhfrjxhuIZ243ZYkR44tPvosd5n0wKOSOt/QE 2ajgdPqokrjLwee9/WFKggOsMKFKA3JkuFHT9CGlwRd/jT1fAKeqCYtOAshzcDlNBeZa Qv/OgxxSGqz27/Ur6Y38pzrp8q1/Uah5lz/oMPFNrBIh5RBPjxCb6TbJZs5JlLglV3XB V3ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727273745; x=1727878545; 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=hbrFzlrnUu+8X/JET7kR2akCW+mI8AJmFw0wQB6l0Uw=; b=OOFdfIqNHz90bWMHYkY6aQm1MmVDJaqQnezSQIQP/fArB7YhgFkHkMtdHox27tJgdr pcx5auDxp+H/rxrmjecC05yyOvOYZanWV511oCrsXdla6zgclEIVNv+dc9IVOWWIbfAv 8saHdLv45w8DhArYI28jllkayiukjfcEXykdTtMj1eAmz7CpCV+iX9JBJldBomUWO1c3 4nvI0WgAUoenLjNa1Bn5aG9YG1OCK/bb95KRX5S/aCFLN3g+fMJz/pQj5vODn/G6O7+e pM806Y5Ui1zaudFQktGyOT/zyJeKYhvszKhtailMpu2BuoPVYlTODYPY7K4Ye9EkVMzS xZDQ== X-Forwarded-Encrypted: i=1; AJvYcCWcxqjfHtNwrWKv48mW3a5VpKvE1tc+3bDCioTS1GmLeyBEY3T7v+JtuEc5WfqzrWDGXfWPwVYx0Z8zfUp9hvzD@lists.infradead.org X-Gm-Message-State: AOJu0YzOJyPCK8kbA/LUaJnW6QCNiU+BdmueOzdtXzN879DH1WteDdwZ 71mAXytFG6m7u8HRn1GT3D4Kv4i9uhYeoSzrTPYsXJ3T4EKhUoadd7JclZnt0EQ= X-Google-Smtp-Source: AGHT+IFQn8YnDCsIX7UjafdBPe6+oR3SG2XsFVa/A70LleDb3uEn+exPHpjHzg07dI1HfR4LZuzs7w== X-Received: by 2002:a05:6402:1e8d:b0:5c2:524b:7711 with SMTP id 4fb4d7f45d1cf-5c72073d459mr2550246a12.33.1727273744720; Wed, 25 Sep 2024 07:15:44 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4968f4sm1888005a12.27.2024.09.25.07.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 07:15:44 -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 , Yang Li , Colin Ian King , Yang Jihong , Athira Rajeev , Howard Chu , Ze Gao , Sun Haiyong , Jing Zhang , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 4/7] perf evsel x86: Make evsel__has_perf_metrics work for legacy events Date: Wed, 25 Sep 2024 15:13:42 +0100 Message-Id: <20240925141357.1033087-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240925141357.1033087-1-james.clark@linaro.org> References: <20240925141357.1033087-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-20240925_071546_440468_368070AB X-CRM114-Status: GOOD ( 22.20 ) 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..4a0229d601d4 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 (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 */