lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241011110207.1032235-2-dapeng1.mi@linux.intel.com>
Date: Fri, 11 Oct 2024 11:02:07 +0000
From: Dapeng Mi <dapeng1.mi@...ux.intel.com>
To: Peter Zijlstra <peterz@...radead.org>,
	Ingo Molnar <mingo@...hat.com>,
	Arnaldo Carvalho de Melo <acme@...nel.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Ian Rogers <irogers@...gle.com>,
	Adrian Hunter <adrian.hunter@...el.com>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
	Kan Liang <kan.liang@...ux.intel.com>
Cc: linux-perf-users@...r.kernel.org,
	linux-kernel@...r.kernel.org,
	Dapeng Mi <dapeng1.mi@...el.com>,
	Dapeng Mi <dapeng1.mi@...ux.intel.com>
Subject: [PATCH 2/2] perf x86/topdown: Refine helper arch_is_topdown_metrics()

Leverage the existed function perf_pmu__name_from_config() to check if
an event is topdown metrics event. perf_pmu__name_from_config() goes
through the defined formats and figures out the config of pre-defined
topdown events.

This avoids to figure out the config of topdown pre-defined events with
hard-coded format strings "event=" and "umask=" and provides more
flexibility.

Suggested-by: Ian Rogers <irogers@...gle.com>
Signed-off-by: Dapeng Mi <dapeng1.mi@...ux.intel.com>
---
 tools/perf/arch/x86/util/topdown.c | 39 +++++++-----------------------
 1 file changed, 9 insertions(+), 30 deletions(-)

diff --git a/tools/perf/arch/x86/util/topdown.c b/tools/perf/arch/x86/util/topdown.c
index cb2c64928bc4..f63747d0abdf 100644
--- a/tools/perf/arch/x86/util/topdown.c
+++ b/tools/perf/arch/x86/util/topdown.c
@@ -41,43 +41,22 @@ bool arch_is_topdown_slots(const struct evsel *evsel)
 	return false;
 }
 
-static int compare_topdown_event(void *vstate, struct pmu_event_info *info)
-{
-	int *config = vstate;
-	int event = 0;
-	int umask = 0;
-	char *str;
-
-	if (!strcasestr(info->name, "topdown"))
-		return 0;
-
-	str = strcasestr(info->str, "event=");
-	if (str)
-		sscanf(str, "event=%x", &event);
-
-	str = strcasestr(info->str, "umask=");
-	if (str)
-		sscanf(str, "umask=%x", &umask);
-
-	if (event == 0 && *config == (event | umask << 8))
-		return 1;
-
-	return 0;
-}
-
 bool arch_is_topdown_metrics(const struct evsel *evsel)
 {
-	struct perf_pmu *pmu = evsel__find_pmu(evsel);
 	int config = evsel->core.attr.config;
+	const char *name_from_config;
+	struct perf_pmu *pmu;
 
-	if (!pmu || !pmu->is_core)
+	/* All topdown events have an event code of 0. */
+	if ((config & 0xFF) != 0)
 		return false;
 
-	if (perf_pmu__for_each_event(pmu, false, &config,
-				     compare_topdown_event))
-		return true;
+	pmu = evsel__find_pmu(evsel);
+	if (!pmu || !pmu->is_core)
+		return false;
 
-	return false;
+	name_from_config = perf_pmu__name_from_config(pmu, config);
+	return name_from_config && strcasestr(name_from_config, "topdown");
 }
 
 /*
-- 
2.40.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ