From patchwork Wed Aug 28 14:07:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13781346 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 E9772C5AE5A for ; Wed, 28 Aug 2024 14:12:27 +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=/sTIhS9Xw4BDPOQB2/gkPZMsu+IQ4A0gbxPA3JWu3jQ=; b=KO+mqGDOfB7kMDoob8oRYRAW8a deyz0HAdKlo5L8vXKHbEOAacwGwEe9u0dcVDUl612MsyL1vl5HEfsMIE1RFX8gFxCLD10KrMYxpcV aqMAzag+9XcILBsJCjhFtCwO24vKrJg8KYh2g+otyeWc/wKo+UzV28t7JaNZXrrLCI0sl9hBBdAcZ gQqZpFnMjDGE46uRlU6Hor/r7vehhuAo4yyxRN5EHo5EmXPuqpTM2LW5Qu0N5Ynn/RrYbc6uK4I+V ZpQaa/qHZheNgCUTmE0bQ6H3H4yda8q+3IwZy3BMtLPZOdldrnVu03uPXhZ22tIMgwr68zgaKgCVw ygE2JRiQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjJPG-0000000Fgvz-1Uhc; Wed, 28 Aug 2024 14:12:18 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjJM9-0000000FfvA-0nud for linux-arm-kernel@lists.infradead.org; Wed, 28 Aug 2024 14:09:07 +0000 Received: by mail-ed1-x533.google.com with SMTP id 4fb4d7f45d1cf-5bec4e00978so6477427a12.0 for ; Wed, 28 Aug 2024 07:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724854143; x=1725458943; 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=/sTIhS9Xw4BDPOQB2/gkPZMsu+IQ4A0gbxPA3JWu3jQ=; b=mjfJy1dgliHW82qBnvYK5g/YYeqArp9NPAitlwe9InrJvK3t+mK2n30EuCKG5s2mM/ tlcSIG1F4VqBj2FNFOwni7p3jGU5bOQvf97PMnm2m1AxIxgwCV8z9Axs9j+XqNPmez18 FClCttH+ROP6e4NgCPD/MLMdnk5j9lppBqLCqWCPSwJChToCXStpBiijX5mJl+/Q/z+s N8pTUNC05PwcVkce0vPWnODwRbVJvxHCHiUmT2dIsTkkCfGwQVPDGc6S69P3Hs2ocZve 2BNGTu//s0g0GmHdFV/a0Ot/WUWH4f2qy8Wfias8uBGoyHmMzH7a9Np2vRAa/t6Gm89R fnVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724854143; x=1725458943; 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=/sTIhS9Xw4BDPOQB2/gkPZMsu+IQ4A0gbxPA3JWu3jQ=; b=c1JOwy4sq9gK6eonuQOv3tlmfBAlg1epiZDyIKETGLuFG9scP1DWqeZfSQy5ZIvTSn QcKnPAhY6OZltoMUWVZ+8Fx7XghYgXZJq4dWZQaDW+R/iksHwXc7bRiFgB+g2VmpWI+p MLPNXG/UI1TYOXjmemlvTGgNb9RJyo6HrVt3T1W3omdaj7dzURCr8699o08varPPX5y4 jmlncWUZRyVajUpVxx32JS+LQfMLPNMM+NdbV/Gs7zAo7Kb+dCACOX+roiteHT9G28EX 2M87fy9sM87oXf9qQm2y9oYc158kNpS28u4jCHeJqZMW/2gN72L9Avl4a0f9GA3vahMe 3slQ== X-Forwarded-Encrypted: i=1; AJvYcCVkBH1bbre4K/ntqZYxHFCd8gNJVj4MnxbIsDGuVMvQsbu9J3ybJS8BJZznN1KM4FmO+4OBkgFLizV9sr7MeB0O@lists.infradead.org X-Gm-Message-State: AOJu0YxLsW8uZqYdOTA18xj69ZM66Vhfz72lgDAL0FSsHTyvbH4HK87N E1r62Bi1hEJCA6BShw6xR5Oup7knD3wt1OAK6pAV/W7qbdb37lmKHCV1qmeoU5E= X-Google-Smtp-Source: AGHT+IGamSH+hxEvqf/wJhui3D/jzrZ5i+zWZOp+8vazvps8M4Uh6pYxZyTr3OpCAb2zab1HQy4wJw== X-Received: by 2002:a17:907:96a5:b0:a77:cf09:9c70 with SMTP id a640c23a62f3a-a86a54b9cafmr1229096666b.43.1724854142718; Wed, 28 Aug 2024 07:09:02 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a86e5832855sm251302666b.130.2024.08.28.07.09.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2024 07:09:01 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org, kan.liang@linux.intel.com, ak@linux.intel.com Cc: James Clark , John Garry , Will Deacon , Mike Leach , Leo Yan , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Adrian Hunter , Weilin Wang , Athira Rajeev , Dominique Martinet , Colin Ian King , Yang Jihong , Ze Gao , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v5 4/7] perf evsel x86: Make evsel__has_perf_metrics work for legacy events Date: Wed, 28 Aug 2024 15:07:18 +0100 Message-Id: <20240828140736.156703-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240828140736.156703-1-james.clark@linaro.org> References: <20240828140736.156703-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-20240828_070905_267333_AAE74587 X-CRM114-Status: GOOD ( 19.94 ) 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. Signed-off-by: Ian Rogers Signed-off-by: James Clark --- tools/perf/arch/x86/util/evsel.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/perf/arch/x86/util/evsel.c b/tools/perf/arch/x86/util/evsel.c index 090d0f371891..1eaae8819c5e 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__fake) + 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)