From patchwork Thu Aug 22 13:24:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13773438 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 ED9DEC3DA4A for ; Thu, 22 Aug 2024 13:30:40 +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=bT+ghgr6hpN8o0q3pQWp3B9Z1X URplaY22e0qfk3XGk1QHQ8+6GUowwpLwKYUH/pVipjXE2rO4amS8nr40xi/dZLMxftxRfARAcZypI beTc1AdsEWjqB1pJuHZazxmX08bkwEAWkJBnPIyGifDnNKILa22h4GGOv5vThtudqmWoIHYgScrMd GbbZ7bryclOdkRDXzyuJiYfQMbxPq48kUPRd39zoSZCa422fEG4TUpAdKZES1b62NQQTe/DExM3Qb LgcEycD/VDiJ1ZeM4GgEyWTyXCG0QIJhawlfyaLq3u0SVaTXKQNFecq/sv4WD1pn7M2OzHDbfrCvn SDJrJgEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh7tX-0000000Cx9q-0bb4; Thu, 22 Aug 2024 13:30:31 +0000 Received: from mail-ej1-x62c.google.com ([2a00:1450:4864:20::62c]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sh7q4-0000000CvpF-0ROI for linux-arm-kernel@lists.infradead.org; Thu, 22 Aug 2024 13:26:57 +0000 Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a86933829dcso80337466b.3 for ; Thu, 22 Aug 2024 06:26:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1724333214; x=1724938014; 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=YOkQZaUszKLZ0tPficX9VlOfy4UDORJf3rGetHo02tdig/uv2z6WBxc0WdddbEHNNM 6he6FdDiGegQRWSblNSq0cTS+H+mkfEIdwCS+tmENt6dfuFFOYFsZWM3993RrNU8o8+7 NBtZtw3g6BnDcOaq01a1ndbyw2QorAcsN4ry5SI0pdevGZ61nczhcQwi/ynCljWnaZ7s SPpYGG9qsCXLQ4JMAFOYjWjekYeHBHIXsSa1/p32caPQsSecYlJkm4oW5LSIuxZLop9n 9unOl7jt4vHXz8JCJzKcHjviCydWxhoLJxNSyrJVrIyXfoXfxZTNyVsUqW8/+p8mHmDV MQ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724333214; x=1724938014; 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=fOB8qN7n9LuFhll9ZaIG/sxkEawCCTtrX0/w2G5eLD9xg7G+tXDXyyGpwS+zcAg4EE CQNoJi0Yx0YXxw+fB+tory0wDSITs/dyUYj87Trs72JQx13aB8x4ormIluwWWLabrJXc iIoAfYBd3A/yrjre9wyWu2rLWrGIBh07nNpmjtYvAElkUu6mFQMWxGTvOACSEOh4U3IY fsRyp+1VUXDeziCUR9xHBgazBzRAt70nXiAw5n3R0k+FKL6Yfspxvwm6DilTjWaRufMj dX+5VdiKosxTA0eGDCu0kpRCt6dwLgz9h9QwMe4XROG+x5vcTcdr13H35HoDeJSVOlwF 6LOw== X-Forwarded-Encrypted: i=1; AJvYcCXYaYC/b2CmzqzZurTQciuGHRqx5DGihv5twPHyZDpTLLqjyXCbs5KbgCvtDoBIclAvrtYu8l/Jy/q24i5T94pB@lists.infradead.org X-Gm-Message-State: AOJu0YyEe8jWdLw2lMgxBtdheW/KoA029YuHazTaoVOjOWkU/feFDEJm D4wdXvEdxace68KYAioW/rMHSV6KXxpwbpUZmlVVng0ZRjmDYg2vL8DKzyA3WXI= X-Google-Smtp-Source: AGHT+IHjm7Q+JoZgcM2Zph/tZNRKj+q2DW0doo5EcFiHyW+jdSlZaqVjNw0PmuMr+kvtWO0dxJNqxw== X-Received: by 2002:a17:907:d3c7:b0:a7a:ab1a:2d64 with SMTP id a640c23a62f3a-a866f9d2811mr428685466b.58.1724333213916; Thu, 22 Aug 2024 06:26:53 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a868f4365a9sm119497766b.125.2024.08.22.06.26.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Aug 2024 06:26:53 -0700 (PDT) From: James Clark To: irogers@google.com, linux-perf-users@vger.kernel.org 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 , "Liang, Kan" , Weilin Wang , Athira Rajeev , Dominique Martinet , Colin Ian King , Yang Jihong , Ze Gao , Yunseong Kim , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 4/7] perf evsel x86: Make evsel__has_perf_metrics work for legacy events Date: Thu, 22 Aug 2024 14:24:48 +0100 Message-Id: <20240822132506.1468090-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240822132506.1468090-1-james.clark@linaro.org> References: <20240822132506.1468090-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-20240822_062656_180440_56086F37 X-CRM114-Status: GOOD ( 20.28 ) 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)