LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Tom Zanussi <tom.zanussi@linux.intel.com>,
	Clark Williams <williams@redhat.com>,
	Karim Yaghmour <karim.yaghmour@opersys.com>,
	Brendan Gregg <bgregg@netflix.com>,
	Joel Fernandes <joelaf@google.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	linux-rt-users@vger.kernel.org
Subject: [RFC][PATCH 06/10] tracing: Add trigger file for trace_markers tracefs/ftrace/print
Date: Fri, 11 May 2018 15:49:33 -0400	[thread overview]
Message-ID: <20180511195340.876528094@goodmis.org> (raw)
In-Reply-To: <20180511194927.190877137@goodmis.org>

[-- Attachment #1: 0006-tracing-Add-trigger-file-for-trace_markers-tracefs-f.patch --]
[-- Type: text/plain, Size: 4138 bytes --]

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Allow writing to the trace_markers file initiate triggers defined in
tracefs/ftrace/print/trigger file. This will allow of user space to trigger
the same type of triggers (including histograms) that the trace events use.

Cc: Tom Zanussi <tom.zanussi@linux.intel.com>
Cc: Clark Williams <williams@redhat.com>
Cc: Karim Yaghmour <karim.yaghmour@opersys.com>
Cc: Brendan Gregg <bgregg@netflix.com>
Suggested-by: Joel Fernandes <joelaf@google.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/trace.c         | 17 +++++++++++++++++
 kernel/trace/trace.h         |  1 +
 kernel/trace/trace_entries.h |  6 ++++--
 kernel/trace/trace_export.c  |  7 +++++++
 4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index e0d6ffb76985..f11b89fa5049 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -6074,6 +6074,7 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 {
 	struct trace_array *tr = filp->private_data;
 	struct ring_buffer_event *event;
+	enum event_trigger_type tt = ETT_NONE;
 	struct ring_buffer *buffer;
 	struct print_entry *entry;
 	unsigned long irq_flags;
@@ -6122,6 +6123,12 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 		written = cnt;
 	len = cnt;
 
+	if (tr->trace_marker_file && !list_empty(&tr->trace_marker_file->triggers)) {
+		/* do not add \n before testing triggers, but add \0 */
+		entry->buf[cnt] = '\0';
+		tt = event_triggers_call(tr->trace_marker_file, entry, event);
+	}
+
 	if (entry->buf[cnt - 1] != '\n') {
 		entry->buf[cnt] = '\n';
 		entry->buf[cnt + 1] = '\0';
@@ -6130,6 +6137,9 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 
 	__buffer_unlock_commit(buffer, event);
 
+	if (tt)
+		event_triggers_post_call(tr->trace_marker_file, tt);
+
 	if (written > 0)
 		*fpos += written;
 
@@ -7896,6 +7906,7 @@ static __init void create_trace_instances(struct dentry *d_tracer)
 static void
 init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
 {
+	struct trace_event_file *file;
 	int cpu;
 
 	trace_create_file("available_tracers", 0444, d_tracer,
@@ -7928,6 +7939,12 @@ init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer)
 	trace_create_file("trace_marker", 0220, d_tracer,
 			  tr, &tracing_mark_fops);
 
+	file = __find_event_file(tr, "ftrace", "print");
+	if (file && file->dir)
+		trace_create_file("trigger", 0644, file->dir, file,
+				  &event_trigger_fops);
+	tr->trace_marker_file = file;
+
 	trace_create_file("trace_marker_raw", 0220, d_tracer,
 			  tr, &tracing_mark_raw_fops);
 
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 2414fd72dedd..c7fa58d31a84 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -259,6 +259,7 @@ struct trace_array {
 	struct trace_options	*topts;
 	struct list_head	systems;
 	struct list_head	events;
+	struct trace_event_file *trace_marker_file;
 	cpumask_var_t		tracing_cpumask; /* only trace on set CPUs */
 	int			ref;
 #ifdef CONFIG_FUNCTION_TRACER
diff --git a/kernel/trace/trace_entries.h b/kernel/trace/trace_entries.h
index e3a658bac10f..de3fce14cd00 100644
--- a/kernel/trace/trace_entries.h
+++ b/kernel/trace/trace_entries.h
@@ -230,7 +230,7 @@ FTRACE_ENTRY(bprint, bprint_entry,
 	FILTER_OTHER
 );
 
-FTRACE_ENTRY(print, print_entry,
+FTRACE_ENTRY_REG(print, print_entry,
 
 	TRACE_PRINT,
 
@@ -242,7 +242,9 @@ FTRACE_ENTRY(print, print_entry,
 	F_printk("%ps: %s",
 		 (void *)__entry->ip, __entry->buf),
 
-	FILTER_OTHER
+	FILTER_OTHER,
+
+	 ftrace_event_register
 );
 
 FTRACE_ENTRY(raw_data, raw_data_entry,
diff --git a/kernel/trace/trace_export.c b/kernel/trace/trace_export.c
index d842f1eadfe5..45630a76ed3a 100644
--- a/kernel/trace/trace_export.c
+++ b/kernel/trace/trace_export.c
@@ -14,6 +14,13 @@
 
 #include "trace_output.h"
 
+/* Stub function for events with triggers */
+static int ftrace_event_register(struct trace_event_call *call,
+				 enum trace_reg type, void *data)
+{
+	return 0;
+}
+
 #undef TRACE_SYSTEM
 #define TRACE_SYSTEM	ftrace
 
-- 
2.17.0

  parent reply	other threads:[~2018-05-11 19:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-11 19:49 [RFC][PATCH 00/10] tracing: Add triggers to trace_marker writes Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 01/10] tracing: Do not reference event data in post call triggers Steven Rostedt
2018-05-12 12:04   ` Masami Hiramatsu
2018-05-11 19:49 ` [RFC][PATCH 02/10] tracing: Add __find_event_file() to find event files without restrictions Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 03/10] tracing: Have event_trace_init() called by trace_init_tracefs() Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 04/10] tracing: Add brackets in ftrace event dynamic arrays Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 05/10] tracing: Do not show filter file for ftrace internal events Steven Rostedt
2018-05-11 19:49 ` Steven Rostedt [this message]
2018-05-14  3:13   ` [RFC][PATCH 06/10] tracing: Add trigger file for trace_markers tracefs/ftrace/print Namhyung Kim
2018-05-14 15:04     ` Steven Rostedt
2018-05-16  7:49       ` Namhyung Kim
2018-05-16 10:37         ` Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 07/10] tracing: Have zero size length in filter logic be full string Steven Rostedt
2018-05-12 12:40   ` Masami Hiramatsu
2018-05-12 17:27     ` Steven Rostedt
2018-05-12 18:32   ` Yann Ylavic
2018-05-14  2:23     ` Namhyung Kim
2018-05-14 14:12     ` Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 08/10] tracing: Prevent further users of zero size static arrays in trace events Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 09/10] tracing: Allow histogram triggers to access ftrace internal events Steven Rostedt
2018-05-11 19:49 ` [RFC][PATCH 10/10] tracing: Document trace_marker triggers Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180511195340.876528094@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=bgregg@netflix.com \
    --cc=joelaf@google.com \
    --cc=karim.yaghmour@opersys.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tom.zanussi@linux.intel.com \
    --cc=williams@redhat.com \
    --subject='Re: [RFC][PATCH 06/10] tracing: Add trigger file for trace_markers tracefs/ftrace/print' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).