Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [RFC PATCH] libtracefs: Add tracefs_iterate_stop()
@ 2021-07-05 12:27 Yordan Karadzhov (VMware)
  0 siblings, 0 replies; only message in thread
From: Yordan Karadzhov (VMware) @ 2021-07-05 12:27 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel, Yordan Karadzhov (VMware)

In the API for data streaming we implemented a special
function (tracefs_trace_pipe_stop()) that can be called from
the user in order to terminate the continuous streaming of the
tracing data. Here we add similar functionality that can be
used to terminate the continuous iteration over the raw events.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 include/tracefs-local.h |  1 +
 include/tracefs.h       |  1 +
 src/tracefs-events.c    | 27 ++++++++++++++++++++++++---
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/include/tracefs-local.h b/include/tracefs-local.h
index 73698e8..5a469f9 100644
--- a/include/tracefs-local.h
+++ b/include/tracefs-local.h
@@ -31,6 +31,7 @@ struct tracefs_instance {
 	int				ftrace_marker_fd;
 	int				ftrace_marker_raw_fd;
 	bool				pipe_keep_going;
+	bool				iterate_keep_going;
 };
 
 extern pthread_mutex_t toplevel_lock;
diff --git a/include/tracefs.h b/include/tracefs.h
index 1c8703a..07124ef 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -97,6 +97,7 @@ int tracefs_iterate_raw_events(struct tep_handle *tep,
 						struct tep_record *,
 						int, void *),
 				void *callback_context);
+void tracefs_iterate_stop(struct tracefs_instance *instance);
 
 char **tracefs_tracers(const char *tracing_dir);
 
diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 568bfe6..3093bdd 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -109,7 +109,8 @@ static int read_cpu_pages(struct tep_handle *tep, struct cpu_iterate *cpus, int
 			  int (*callback)(struct tep_event *,
 					  struct tep_record *,
 					  int, void *),
-			  void *callback_context)
+			  void *callback_context,
+			  bool *keep_going)
 {
 	bool has_data = false;
 	int ret;
@@ -121,7 +122,7 @@ static int read_cpu_pages(struct tep_handle *tep, struct cpu_iterate *cpus, int
 			has_data = true;
 	}
 
-	while (has_data) {
+	while (has_data && *(volatile bool *)keep_going) {
 		j = count;
 		for (i = 0; i < count; i++) {
 			if (!cpus[i].event)
@@ -205,6 +206,8 @@ out:
 	return ret;
 }
 
+static bool top_iterate_keep_going;
+
 /*
  * tracefs_iterate_raw_events - Iterate through events in trace_pipe_raw,
  *				per CPU trace buffers
@@ -230,18 +233,24 @@ int tracefs_iterate_raw_events(struct tep_handle *tep,
 						int, void *),
 				void *callback_context)
 {
+	bool *keep_going = instance ? &instance->pipe_keep_going :
+				      &top_iterate_keep_going;
 	struct cpu_iterate *all_cpus = NULL;
 	int count = 0;
 	int ret;
 	int i;
 
+	(*(volatile bool *)keep_going) = true;
+
 	if (!tep || !callback)
 		return -1;
 
 	ret = open_cpu_files(instance, cpus, cpu_size, &all_cpus, &count);
 	if (ret < 0)
 		goto out;
-	ret = read_cpu_pages(tep, all_cpus, count, callback, callback_context);
+	ret = read_cpu_pages(tep, all_cpus, count,
+			     callback, callback_context,
+			     keep_going);
 
 out:
 	if (all_cpus) {
@@ -256,6 +265,18 @@ out:
 	return ret;
 }
 
+/**
+ * tracefs_iterate_stop - stop the iteration over the raw events.
+ * @instance: ftrace instance, can be NULL for top tracing instance.
+ */
+void tracefs_iterate_stop(struct tracefs_instance *instance)
+{
+	if (instance)
+		instance->iterate_keep_going = false;
+	else
+		top_iterate_keep_going = false;
+}
+
 static char **add_list_string(char **list, const char *name, int len)
 {
 	if (!list)
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-05 12:27 [RFC PATCH] libtracefs: Add tracefs_iterate_stop() Yordan Karadzhov (VMware)

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git