public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] tracing: Expose functions to trace a synth event
@ 2025-03-18 18:08 Douglas RAILLARD
  2025-03-18 18:08 ` [PATCH 2/3] tracing: Rename find_synth_event() into synth_event_find() Douglas RAILLARD
  2025-03-18 18:08 ` [PATCH 3/3] tracing: Rename trace_synth() to synth_event_trace2() Douglas RAILLARD
  0 siblings, 2 replies; 12+ messages in thread
From: Douglas RAILLARD @ 2025-03-18 18:08 UTC (permalink / raw)
  To: rostedt
  Cc: douglas.raillard, Masami Hiramatsu, Mathieu Desnoyers,
	linux-kernel, linux-trace-kernel

From: Douglas Raillard <douglas.raillard@arm.com>

The current API for synth event only allow tracing by getting a "struct
trace_event_file *", which is associated with a specific ftrace instance
that has to be looked up ahead of time. In order to be able to emit such
synth event in all instances where the event has been enabled by a user,
another function is required, using a "struct synth_event *" that then
uses the underlying tracepoint system that the tracefs interface
manipulates.

Such function already exists for the histogram feature, so simply move
it to the common trace_events_synth.c code.

Signed-off-by: Douglas Raillard <douglas.raillard@arm.com>
---
 include/linux/trace_events.h      |  7 +++++++
 kernel/trace/trace_events_hist.c  | 27 ---------------------------
 kernel/trace/trace_events_synth.c | 29 +++++++++++++++++++++++++++++
 kernel/trace/trace_synth.h        |  2 --
 4 files changed, 36 insertions(+), 29 deletions(-)

diff --git a/include/linux/trace_events.h b/include/linux/trace_events.h
index 5caea596fef0..cbe389d0e144 100644
--- a/include/linux/trace_events.h
+++ b/include/linux/trace_events.h
@@ -517,6 +517,13 @@ struct dynevent_cmd {
 
 extern int dynevent_create(struct dynevent_cmd *cmd);
 
+struct synth_event;
+
+extern struct synth_event *find_synth_event(const char *name);
+
+extern void trace_synth(struct synth_event *event, u64 *var_ref_vals,
+			       unsigned int *var_ref_idx);
+
 extern int synth_event_delete(const char *name);
 
 extern void synth_event_cmd_init(struct dynevent_cmd *cmd,
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 53dc6719181e..a2bc7a972763 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -814,33 +814,6 @@ static void hist_err_clear(void)
 	last_cmd_loc[0] = '\0';
 }
 
-typedef void (*synth_probe_func_t) (void *__data, u64 *var_ref_vals,
-				    unsigned int *var_ref_idx);
-
-static inline void trace_synth(struct synth_event *event, u64 *var_ref_vals,
-			       unsigned int *var_ref_idx)
-{
-	struct tracepoint *tp = event->tp;
-
-	if (unlikely(static_key_enabled(&tp->key))) {
-		struct tracepoint_func *probe_func_ptr;
-		synth_probe_func_t probe_func;
-		void *__data;
-
-		if (!(cpu_online(raw_smp_processor_id())))
-			return;
-
-		probe_func_ptr = rcu_dereference_sched((tp)->funcs);
-		if (probe_func_ptr) {
-			do {
-				probe_func = probe_func_ptr->func;
-				__data = probe_func_ptr->data;
-				probe_func(__data, var_ref_vals, var_ref_idx);
-			} while ((++probe_func_ptr)->func);
-		}
-	}
-}
-
 static void action_trace(struct hist_trigger_data *hist_data,
 			 struct tracing_map_elt *elt,
 			 struct trace_buffer *buffer, void *rec,
diff --git a/kernel/trace/trace_events_synth.c b/kernel/trace/trace_events_synth.c
index e3f7d09e5512..9f0817eec3c2 100644
--- a/kernel/trace/trace_events_synth.c
+++ b/kernel/trace/trace_events_synth.c
@@ -845,6 +845,35 @@ struct synth_event *find_synth_event(const char *name)
 
 	return NULL;
 }
+EXPORT_SYMBOL_GPL(find_synth_event);
+
+typedef void (*synth_probe_func_t) (void *__data, u64 *var_ref_vals,
+				    unsigned int *var_ref_idx);
+
+void trace_synth(struct synth_event *event, u64 *var_ref_vals,
+			       unsigned int *var_ref_idx)
+{
+	struct tracepoint *tp = event->tp;
+
+	if (unlikely(static_key_enabled(&tp->key))) {
+		struct tracepoint_func *probe_func_ptr;
+		synth_probe_func_t probe_func;
+		void *__data;
+
+		if (!(cpu_online(raw_smp_processor_id())))
+			return;
+
+		probe_func_ptr = rcu_dereference_sched((tp)->funcs);
+		if (probe_func_ptr) {
+			do {
+				probe_func = probe_func_ptr->func;
+				__data = probe_func_ptr->data;
+				probe_func(__data, var_ref_vals, var_ref_idx);
+			} while ((++probe_func_ptr)->func);
+		}
+	}
+}
+EXPORT_SYMBOL_GPL(trace_synth);
 
 static struct trace_event_fields synth_event_fields_array[] = {
 	{ .type = TRACE_FUNCTION_TYPE,
diff --git a/kernel/trace/trace_synth.h b/kernel/trace/trace_synth.h
index 43f6fb6078db..425a0ec7c773 100644
--- a/kernel/trace/trace_synth.h
+++ b/kernel/trace/trace_synth.h
@@ -36,6 +36,4 @@ struct synth_event {
 	struct module				*mod;
 };
 
-extern struct synth_event *find_synth_event(const char *name);
-
 #endif /* __TRACE_SYNTH_H */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* Re: [PATCH 3/3] tracing: Rename trace_synth() to synth_event_trace2()
@ 2025-03-25 21:40 Adnan-khan Ruzwan1
  0 siblings, 0 replies; 12+ messages in thread
From: Adnan-khan Ruzwan1 @ 2025-03-25 21:40 UTC (permalink / raw)
  To: douglas.raillard
  Cc: aliceryhl, linux-kernel, linux-trace-kernel, mathieu.desnoyers,
	mhiramat, rostedt


Sent from my iPhone

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-03-25 21:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-18 18:08 [PATCH 1/3] tracing: Expose functions to trace a synth event Douglas RAILLARD
2025-03-18 18:08 ` [PATCH 2/3] tracing: Rename find_synth_event() into synth_event_find() Douglas RAILLARD
2025-03-18 18:08 ` [PATCH 3/3] tracing: Rename trace_synth() to synth_event_trace2() Douglas RAILLARD
2025-03-19 13:37   ` Masami Hiramatsu
2025-03-19 14:51     ` Douglas Raillard
2025-03-24  6:29       ` Masami Hiramatsu
2025-03-24 14:30         ` Steven Rostedt
2025-03-25 16:05         ` Douglas Raillard
2025-03-25 16:25           ` Steven Rostedt
2025-03-25 18:16             ` Douglas Raillard
2025-03-25 20:13               ` Douglas Raillard
  -- strict thread matches above, loose matches on Subject: below --
2025-03-25 21:40 Adnan-khan Ruzwan1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox