From patchwork Tue Sep 10 15:16:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Clark X-Patchwork-Id: 13798786 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 AAA6EEDE99D for ; Tue, 10 Sep 2024 15:24:14 +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=SbXzulT1hvclpO2gUzyU2PPxHH5lSuW+E82Abjkw8Ls=; b=UthabWtDtgWZOht66G7QfWcLXh wX53je2XTxzvnTCkpbnB7jZx2OkGY/I7lOaagW16cgedmpkkRemqNfm3Lpi79RCd6g8eec2XeXG+Q BVib1slJzfoxCxrTk8hf259tX/apQwY+npg/jFnB87g0RvZLaOGYF/D42LCTduLpQC19BAz8gyA3x D7bxDBJK4T5IFZxdz6Pt4i8StkJ9oML8nKLPXBMg6HXptwP7gZhHSpgT/wS03SKNGk5N+ag3zRtAG astlWuw/dBFk/78gSJrTUORVbfpvZPOHEKy3K+921TgJzdIrXcje5zYnJZi0UqaWNFL0IXSR+Z6Y2 0S098g1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1so2io-000000065UB-1iIJ; Tue, 10 Sep 2024 15:24:02 +0000 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1so2d5-000000062qE-0tsW for linux-arm-kernel@lists.infradead.org; Tue, 10 Sep 2024 15:18:08 +0000 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-42cae4eb026so33253005e9.0 for ; Tue, 10 Sep 2024 08:18:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725981485; x=1726586285; 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=SbXzulT1hvclpO2gUzyU2PPxHH5lSuW+E82Abjkw8Ls=; b=upCZvpOmUmXM1f2HZF+NZkaOdBLn1hRfmwqf47CVRqCEVaMaP5OUlx6yhRXYc0Wkde IgZHSRWg7mToJZK+Y87qXJvIC6wwthmidWkWrjv1NRZ7dR0899hrRiqxM7wDk66TcD3U gyWSK4x7OIk49QyP9lUOmlrZZd/lscxCkoo0ZSIhw7JI/aGkdeV9imq320Am+fsxhXNa pTl5+/mUdF9JFAOsjyb6Hj8blE2LfDIbDdcDCQdwAaI0i9aiwkFzdl2MTkYv6EzQ8WnI xE6UiFBS4lRx2ULvRcOIvV7G2WNly/Dqz61R+ViWJ67Ejo4KxQiUQGYx5Ix1BI0UjDDl 3MxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725981485; x=1726586285; 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=SbXzulT1hvclpO2gUzyU2PPxHH5lSuW+E82Abjkw8Ls=; b=NbUk2I0hyHOC7QSTj9rma/Ve4DCCdzRbkP2kJ4Yap9OD7tEuxejwmPA98xKJ0eoxTH HqhRIha/H57LciLZ04k7nx396shoUiUobAqX5ZHsjmG4HXykRgbqPNaED1Zw47AGB8is AfXLnKVdv4heMIIdDYrNfYpO2ckr5b1yCPyi+T1lf5HATklmcNVYE0gaaJIZxJpj06ix Drx2Smwd4QcblH5wyW1aQnyvvGTHd4DDxrMlXK9+BdEp3WWPp6lLE00YQige9Pbcpa6Y MFB7w4M4tXeY9SwPeGCUS0cuuRiQ6tnyjCs6oVRaZ5ZjvzHoZqvHA30ArIJmRs7y5rfZ yZ2A== X-Forwarded-Encrypted: i=1; AJvYcCWv8gpRy1vRd7Fte+nJ1PRaWRbWTGIVOWHFPk6blxNW6FLbqCOUjagUcfhn3X7v1FBhOGRMWym/dI8qxRWD/PLb@lists.infradead.org X-Gm-Message-State: AOJu0YzhFKbvlnVKeZacZj5ykdlCnbboYpnxxwE2HUeGzHnq1sHihWbp Mjm+saz0UBB8yVoRmS01HkfjXIYubAJMIRhrw0B0Klubu8TJ5QkOog5B3EVNIGQ= X-Google-Smtp-Source: AGHT+IGLuI3uuWRzeekOoiV/Leqs/HePhibFQkWY9zQigVvbRn3rucJiuFLpiP3IkkkJklG+SpMqAg== X-Received: by 2002:a05:600c:a4c:b0:426:602d:a246 with SMTP id 5b1f17b1804b1-42c9f9d842cmr118945155e9.32.1725981484964; Tue, 10 Sep 2024 08:18:04 -0700 (PDT) Received: from localhost.localdomain ([89.47.253.130]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37895665517sm9440844f8f.36.2024.09.10.08.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 08:18:04 -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 , Colin Ian King , Athira Rajeev , Yang Jihong , Howard Chu , Ze Gao , Jing Zhang , Sun Haiyong , Yicong Yang , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 4/7] perf evsel x86: Make evsel__has_perf_metrics work for legacy events Date: Tue, 10 Sep 2024 16:16:22 +0100 Message-Id: <20240910151640.907359-5-james.clark@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240910151640.907359-1-james.clark@linaro.org> References: <20240910151640.907359-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-20240910_081807_258421_71A7B8B3 X-CRM114-Status: GOOD ( 20.32 ) 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 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)