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]
Date:   Wed, 28 Jun 2023 10:29:45 +0000
From:   John Garry <john.g.garry@...cle.com>
To:     acme@...nel.org, irogers@...gle.com, namhyung@...nel.org,
        jolsa@...nel.org
Cc:     linux-arm-kernel@...ts.infradead.org,
        linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
        renyu.zj@...ux.alibaba.com, shangxiaojing@...wei.com,
        zhangshaokun@...ilicon.com, qiangqing.zhang@....com,
        kjain@...ux.ibm.com, kan.liang@...ux.intel.com,
        John Garry <john.g.garry@...cle.com>
Subject: [PATCH RFC 5/9] perf pmu: Refactor pmu_add_sys_aliases_iter_fn()

Refactor pmu_add_sys_aliases_iter_fn() into sub-function
pmu_event_match_pmu(), which is a function which allows us to match a pmu
against a "unit" and "compat" values.

Signed-off-by: John Garry <john.g.garry@...cle.com>
---
 tools/perf/util/pmu.c | 20 +++++++++++++++-----
 tools/perf/util/pmu.h |  2 ++
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 6142e4710a2f..ae1a2a97965c 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -801,6 +801,20 @@ struct pmu_sys_event_iter_data {
 	struct perf_pmu *pmu;
 };
 
+bool pmu_event_match_pmu(const char *event_unit, const char *event_compat, struct perf_pmu *pmu)
+{
+	if (!event_unit || !event_compat)
+		return false;
+
+	if (strcmp(pmu->id, event_compat))
+		return false;
+
+	if (!pmu_uncore_alias_match(event_unit, pmu->name))
+		return false;
+
+	return true;
+}
+
 static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
 				       const struct pmu_events_table *table __maybe_unused,
 				       void *data)
@@ -808,11 +822,7 @@ static int pmu_add_sys_aliases_iter_fn(const struct pmu_event *pe,
 	struct pmu_sys_event_iter_data *idata = data;
 	struct perf_pmu *pmu = idata->pmu;
 
-	if (!pe->compat || !pe->pmu)
-		return 0;
-
-	if (!strcmp(pmu->id, pe->compat) &&
-	    pmu_uncore_alias_match(pe->pmu, pmu->name)) {
+	if (pmu_event_match_pmu(pe->pmu, pe->compat, pmu)) {
 		__perf_pmu__new_alias(idata->head, -1,
 				      (char *)pe->name,
 				      (char *)pe->desc,
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 8807a624e918..8cccbc9b2548 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -288,4 +288,6 @@ int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *filename,
 struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char *lookup_name);
 void perf_pmu__delete(struct perf_pmu *pmu);
 
+bool pmu_event_match_pmu(const char *event_name, const char *event_compat, struct perf_pmu *pmu);
+
 #endif /* __PMU_H */
-- 
2.35.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ