Thread (63 messages) 63 messages, 3 authors, 2021-12-11
STALE1635d

[RFC PATCH v1 29/37] perf evlist: add custom fallback to evlist__open

From: Riccardo Mancini <hidden>
Date: 2021-08-21 09:22:22
Also in: lkml
Subsystem: performance events subsystem, the rest · Maintainers: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Linus Torvalds

This patch adds the function evlist__open_custom, which makes it possible
to provide a custom fallback mechanism to evsel__open.
This function will be used in record__open in the following patch.
This could also be used to adapt perf-stat way of opening to the new
multithreaded mechanism.

Signed-off-by: Riccardo Mancini <redacted>
---
 tools/perf/util/evlist.c | 27 +++++++++++++++++++++------
 tools/perf/util/evlist.h |  9 +++++++++
 2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 3472038d719ec7d4..22b9607dcc637a2d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1405,15 +1405,20 @@ static int evlist__create_syswide_maps(struct evlist *evlist)
 	return err;
 }
 
-static int evlist__open_singlethreaded(struct evlist *evlist)
+static int evlist__open_singlethreaded(struct evlist *evlist,
+					struct evlist_open_custom_fallback *cust_fb)
 {
 	struct evsel *evsel;
 	int err;
 
 	evlist__for_each_entry(evlist, evsel) {
+try_again:
 		err = evsel__open(evsel, evsel->core.cpus, evsel->core.threads);
-		if (err < 0)
+		if (err < 0) {
+			if (cust_fb && cust_fb->func(cust_fb, evlist, evsel, err))
+				goto try_again;
 			return err;
+		}
 	}
 
 	return 0;
@@ -1469,7 +1474,8 @@ static void evlist__open_multithreaded_func(struct work_struct *_work)
 	}
 }
 
-static int evlist__open_multithreaded(struct evlist *evlist)
+static int evlist__open_multithreaded(struct evlist *evlist,
+				struct evlist_open_custom_fallback *cust_fb)
 {
 	int cpu, cpuid, cpuidx, thread, err;
 	struct evlist_open_work *works;
@@ -1567,6 +1573,9 @@ static int evlist__open_multithreaded(struct evlist *evlist)
 		if (evsel__detect_missing_features(evsel))
 			goto reprepare;
 
+		if (cust_fb && cust_fb->func(cust_fb, evlist, evsel, err))
+			goto reprepare;
+
 		// no fallback worked, return the error
 		goto out;
 	}
@@ -1579,7 +1588,8 @@ static int evlist__open_multithreaded(struct evlist *evlist)
 	return err;
 }
 
-int evlist__open(struct evlist *evlist)
+int evlist__open_custom(struct evlist *evlist,
+			struct evlist_open_custom_fallback *cust_fb)
 {
 	int err;
 
@@ -1596,9 +1606,9 @@ int evlist__open(struct evlist *evlist)
 	evlist__update_id_pos(evlist);
 
 	if (perf_singlethreaded)
-		err = evlist__open_singlethreaded(evlist);
+		err = evlist__open_singlethreaded(evlist, cust_fb);
 	else
-		err = evlist__open_multithreaded(evlist);
+		err = evlist__open_multithreaded(evlist, cust_fb);
 
 	if (err)
 		goto out_err;
@@ -1610,6 +1620,11 @@ int evlist__open(struct evlist *evlist)
 	return err;
 }
 
+int evlist__open(struct evlist *evlist)
+{
+	return evlist__open_custom(evlist, NULL);
+}
+
 int evlist__prepare_workload(struct evlist *evlist, struct target *target, const char *argv[],
 			     bool pipe_output, void (*exec_error)(int signo, siginfo_t *info, void *ucontext))
 {
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index b0c2da0f9755b2d1..cb753b4c4e70b4ba 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -161,6 +161,15 @@ void evlist__mmap_consume(struct evlist *evlist, int idx);
 int evlist__open(struct evlist *evlist);
 void evlist__close(struct evlist *evlist);
 
+struct evlist_open_custom_fallback;
+typedef bool (*evlist_open_custom_fallback_fn)(struct evlist_open_custom_fallback *fallback,
+					struct evlist *evlist, struct evsel *evsel, int err);
+struct evlist_open_custom_fallback {
+	evlist_open_custom_fallback_fn func;
+};
+int evlist__open_custom(struct evlist *evlist, struct evlist_open_custom_fallback *cust_fb);
+
+
 struct callchain_param;
 
 void evlist__set_id_pos(struct evlist *evlist);
-- 
2.31.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help