Skip to contentSkip to conversation

tracing: Add triggers to trace_marker writes

PATCH In review Steven Rostedt 3 participants 28 messages May 16, 2018 – May 30, 2018

Subsystems (5)
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

v3 cover tracing: Add triggers to trace_marker writes

A few people have asked for this in the past, and I finally got around to implementing it. What this does is to allow writes into trace_marker to initiate a trigger.

The trace_marker event is described in:

tracefs/events/ftrace/print

Thus the trigger file is added there:

tracefs/events/ftrace/print/trigger

As there's already a "hist" file there, everything appears to work just like any other trigger to an event. See the last patch for documentation on how to use the triggers to a trace_marker write.

By the way, the patch:

tracing: Prevent further users of zero size static arrays in trace events

May prevent your kernel from building if you include Xen. You will need to add this patch to make it work (or include the git repo below).

http://lkml.kernel.org/r/[email protected]

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
ftrace/core

Head SHA1: dded7b759602085b4bd2c5581f58f6b179912d89

Steven Rostedt (VMware) (14):
tracing: Do not reference event data in post call triggers
tracing: Add __find_event_file() to find event files without restrictions
tracing: Have event_trace_init() called by trace_init_tracefs()
tracing: Add brackets in ftrace event dynamic arrays
tracing: Do not show filter file for ftrace internal events
tracing: Add trigger file for trace_markers tracefs/ftrace/print
tracing: Have zero size length in filter logic be full string
tracing: Prevent further users of zero size static arrays in trace events
tracing: Allow histogram triggers to access ftrace internal events
tracing: Document trace_marker triggers
ftrace/selftest: Have the reset_trigger code be a bit more careful ftrace/selftest: Fix reset_trigger() to handle triggers with filters tracing/selftest: Add selftests to test trace_marker histogram triggers tracing/selftest: Add test to test hist trigger between kernel event and trace_marker

----
Changes since v2:

- typo fixes in documentation (Tom Zanussi)
- Rename trigger-trace-marker{-hist} in selftest (Masami Hiramatsu)
- Fix onmatch(sched.sched_waking) (Namhyung Kim)
- Rename test to say trace_marker trigger from event trigger (Steven Rostedt)

Diff from v2 below.

 Documentation/trace/events.rst                     |   6 +-
 Documentation/trace/ftrace.rst                     |   5 +
 Documentation/trace/histogram.txt                  | 546 ++++++++++++++++++++-
 include/linux/trace_events.h                       |   3 +-
 include/trace/trace_events.h                       |   1 +
 kernel/trace/trace.c                               |  19 +
 kernel/trace/trace.h                               |   9 +-
 kernel/trace/trace_entries.h                       |   6 +-
 kernel/trace/trace_events.c                        |  36 +-
 kernel/trace/trace_events_filter.c                 |  23 +-
 kernel/trace/trace_events_hist.c                   |   2 +-
 kernel/trace/trace_events_trigger.c                |   6 +-
 kernel/trace/trace_export.c                        |   9 +-
 tools/testing/selftests/ftrace/test.d/functions    |  23 +-
 .../test.d/trigger/trigger-trace-marker-hist.tc    |  49 ++
 .../trigger/trigger-trace-marker-synthetic.tc      |  88 ++++
 16 files changed, 790 insertions(+), 41 deletions(-)
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc
Documentation/trace/histogram.txt +5 -5
index 8c871f0c0e33..ae2d4f9d0a62 100644
@@ -2005,7 +2005,7 @@ and after it wakes up, something like this:
 
 static void traceputs(char *str)
 {
-	/* tracemark_fd is the trace_marker file descripto */
+	/* tracemark_fd is the trace_marker file descriptor */
 	if (tracemark_fd < 0)
 		return;
 	/* write the tracemark message */
@@ -2048,7 +2048,7 @@ Now running cyclictest with:
 
 Note, the -b 1000 is used just to make --tracemark available.
 
-The we can see the histogram created by this with:
+Then we can see the histogram created by this with:
 
  # cat events/synthetic/latency/hist
 # event histogram
@@ -2360,7 +2360,7 @@ kernel with trace_marker.
 
 The difference this time is that instead of using the trace_marker to start
 the latency, the sched_waking event is used, matching the common_pid for the
-trace_marker write with the pid that is being worken by sched_waking.
+trace_marker write with the pid that is being woken by sched_waking.
 
 After running cyclictest again with the same parameters, we now have:
 
@@ -2535,5 +2535,5 @@ Totals:
     Dropped: 0
 
 This doesn't tell us any information about how late cyclictest may have
-worken up, but it does show us a nice histogram of how long it took from
-the time that cyclictest was worken to the time it made it into user space.
+woken up, but it does show us a nice histogram of how long it took from
+the time that cyclictest was woken to the time it made it into user space.
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc renamed from tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker.tc +1 -1
similarity index 93%
rename from tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker.tc
rename to tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc
index 48e7ac1ccbc1..2acbfe2c0c0c 100644
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-# description: event trigger - test histogram trigger
+# description: trace_marker trigger - test histogram trigger
 # flags: instance
 
 do_reset() {
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
index d8cfc36f228b..b06996ecd5e0 100644
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-# description: event trigger - test histogram with synthetic event
+# description: trace_marker trigger - test histogram with synthetic event
 # flags:
 
 do_reset() {
@@ -72,7 +72,7 @@ echo "Test histogram kernel event to trace_marker latency histogram trigger"
 
 echo 'latency u64 lat' > synthetic_events
 echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat)' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
 sleep 1
 echo "hello" > trace_marker
author maintainer
#1 lore raw

PATCH v3 1/14 tracing: Do not reference event data in post call triggers

From: "Steven Rostedt (VMware)" <[email protected]>

Trace event triggers can be called before or after the event has been committed. If it has been called after the commit, there's a possibility that the event no longer exists. Currently, the two post callers is the trigger to disable tracing (traceoff) and the one that will record a stack dump (stacktrace). Neither of them reference the trace event entry record, as that would lead to a race condition that could pass in corrupted data.

To prevent any other users of the post data triggers from using the trace event record, pass in NULL to the post call trigger functions for the event record, as they should never need to use them in the first place.

This does not fix any bug, but prevents bugs from happening by new post call trigger users.

---
 include/linux/trace_events.h        | 3 +--
 kernel/trace/trace.h                | 4 ++--
 kernel/trace/trace_events_trigger.c | 6 ++----
 3 files changed, 5 insertions(+), 8 deletions(-)
include/linux/trace_events.h +1 -2
index 2bde3eff564c..d1c442d9bd85 100644
@@ -435,8 +435,7 @@ event_triggers_call(struct trace_event_file *file, void *rec,
 		    struct ring_buffer_event *event);
 extern void
 event_triggers_post_call(struct trace_event_file *file,
-			 enum event_trigger_type tt,
-			 void *rec, struct ring_buffer_event *event);
+			 enum event_trigger_type tt);
 
 bool trace_event_ignore_this_pid(struct trace_event_file *trace_file);
 
kernel/trace/trace.h +2 -2
index 6fb46a06c9dc..24b666891eaf 100644
@@ -1334,7 +1334,7 @@ event_trigger_unlock_commit(struct trace_event_file *file,
 		trace_buffer_unlock_commit(file->tr, buffer, event, irq_flags, pc);
 
 	if (tt)
-		event_triggers_post_call(file, tt, entry, event);
+		event_triggers_post_call(file, tt);
 }
 
 /**
@@ -1367,7 +1367,7 @@ event_trigger_unlock_commit_regs(struct trace_event_file *file,
 						irq_flags, pc, regs);
 
 	if (tt)
-		event_triggers_post_call(file, tt, entry, event);
+		event_triggers_post_call(file, tt);
 }
 
 #define FILTER_PRED_INVALID	((unsigned short)-1)
kernel/trace/trace_events_trigger.c +2 -4
index d251cabcf69a..cc4148bfc01a 100644
@@ -97,7 +97,6 @@ EXPORT_SYMBOL_GPL(event_triggers_call);
  * event_triggers_post_call - Call 'post_triggers' for a trace event
  * @file: The trace_event_file associated with the event
  * @tt: enum event_trigger_type containing a set bit for each trigger to invoke
- * @rec: The trace entry for the event
  *
  * For each trigger associated with an event, invoke the trigger
  * function registered with the associated trigger command, if the
@@ -108,8 +107,7 @@ EXPORT_SYMBOL_GPL(event_triggers_call);
  */
 void
 event_triggers_post_call(struct trace_event_file *file,
-			 enum event_trigger_type tt,
-			 void *rec, struct ring_buffer_event *event)
+			 enum event_trigger_type tt)
 {
 	struct event_trigger_data *data;
 
@@ -117,7 +115,7 @@ event_triggers_post_call(struct trace_event_file *file,
 		if (data->paused)
 			continue;
 		if (data->cmd_ops->trigger_type & tt)
-			data->ops->func(data, rec, event);
+			data->ops->func(data, NULL, NULL);
 	}
 }
 EXPORT_SYMBOL_GPL(event_triggers_post_call);
Signature · 1 line
2.17.0
author maintainer
#2 lore raw

PATCH v3 2/14 tracing: Add __find_event_file() to find event files without restrictions

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

By adding the function __find_event_file() that can search for files without restrictions, such as if the event associated with the file has a reg function, or if it has the "ignore" flag set, the files that are associated to ftrace internal events (like trace_marker and function events) can be found and used.

find_event_file() still returns a "filtered" file, as most callers need a valid trace event file. One created by the trace_events.h macros and not one created for parsing ftrace specific events.

---
 kernel/trace/trace.h        |  3 +++
 kernel/trace/trace_events.c | 22 +++++++++++++++++-----
 2 files changed, 20 insertions(+), 5 deletions(-)
kernel/trace/trace.h +3 -0
index 24b666891eaf..8ecca43d6aea 100644
@@ -1454,6 +1454,9 @@ extern void trace_event_enable_tgid_record(bool enable);
 extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
 extern int event_trace_del_tracer(struct trace_array *tr);
 
+extern struct trace_event_file *__find_event_file(struct trace_array *tr,
+						  const char *system,
+						  const char *event);
 extern struct trace_event_file *find_event_file(struct trace_array *tr,
 						const char *system,
 						const char *event);
kernel/trace/trace_events.c +17 -5
index 05c7172c6667..caf76355f0a3 100644
@@ -2473,8 +2473,9 @@ __trace_add_event_dirs(struct trace_array *tr)
 	}
 }
 
+/* Returns any file that matches the system and event */
 struct trace_event_file *
-find_event_file(struct trace_array *tr, const char *system,  const char *event)
+__find_event_file(struct trace_array *tr, const char *system, const char *event)
 {
 	struct trace_event_file *file;
 	struct trace_event_call *call;
@@ -2485,10 +2486,7 @@ find_event_file(struct trace_array *tr, const char *system,  const char *event)
 		call = file->event_call;
 		name = trace_event_name(call);
 
-		if (!name || !call->class || !call->class->reg)
-			continue;
-
-		if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
+		if (!name || !call->class)
 			continue;
 
 		if (strcmp(event, name) == 0 &&
@@ -2498,6 +2496,20 @@ find_event_file(struct trace_array *tr, const char *system,  const char *event)
 	return NULL;
 }
 
+/* Returns valid trace event files that match system and event */
+struct trace_event_file *
+find_event_file(struct trace_array *tr, const char *system, const char *event)
+{
+	struct trace_event_file *file;
+
+	file = __find_event_file(tr, system, event);
+	if (!file || !file->event_call->class->reg ||
+	    file->event_call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)
+		return NULL;
+
+	return file;
+}
+
 #ifdef CONFIG_DYNAMIC_FTRACE
 
 /* Avoid typos */
Signature · 1 line
2.17.0
author maintainer
#3 lore raw

PATCH v3 3/14 tracing: Have event_trace_init() called by trace_init_tracefs()

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Instead of having both trace_init_tracefs() and event_trace_init() be called by fs_initcall() routines, have event_trace_init() called directly by trace_init_tracefs(). This will guarantee order of how the events are created with respect to the rest of the ftrace infrastructure. This is needed to be able to assoctiate event files with ftrace internal events, such as the trace_marker.

---
 kernel/trace/trace.c        | 2 ++
 kernel/trace/trace.h        | 1 +
 kernel/trace/trace_events.c | 4 +---
 3 files changed, 4 insertions(+), 3 deletions(-)
kernel/trace/trace.c +2 -0
index 414d7210b2ec..e0d6ffb76985 100644
@@ -8111,6 +8111,8 @@ static __init int tracer_init_tracefs(void)
 	if (IS_ERR(d_tracer))
 		return 0;
 
+	event_trace_init();
+
 	init_tracer_tracefs(&global_trace, d_tracer);
 	ftrace_init_tracefs_toplevel(&global_trace, d_tracer);
 
kernel/trace/trace.h +1 -0
index 8ecca43d6aea..2414fd72dedd 100644
@@ -1451,6 +1451,7 @@ trace_find_event_field(struct trace_event_call *call, char *name);
 extern void trace_event_enable_cmd_record(bool enable);
 extern void trace_event_enable_tgid_record(bool enable);
 
+extern int event_trace_init(void);
 extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
 extern int event_trace_del_tracer(struct trace_array *tr);
 
kernel/trace/trace_events.c +1 -3
index caf76355f0a3..5b647904a65b 100644
@@ -3144,7 +3144,7 @@ static __init int event_trace_enable_again(void)
 
 early_initcall(event_trace_enable_again);
 
-static __init int event_trace_init(void)
+__init int event_trace_init(void)
 {
 	struct trace_array *tr;
 	struct dentry *d_tracer;
@@ -3189,8 +3189,6 @@ void __init trace_event_init(void)
 	event_trace_enable();
 }
 
-fs_initcall(event_trace_init);
-
 #ifdef CONFIG_FTRACE_STARTUP_TEST
 
 static DEFINE_SPINLOCK(test_spinlock);
Signature · 1 line
2.17.0
author maintainer
#4 lore raw

PATCH v3 4/14 tracing: Add brackets in ftrace event dynamic arrays

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

The dynamic arrays defined for ftrace internal events, such as the buf field for trace_marker (ftrace/print) did not have brackets which makes the filter code not accept it as a string. This is not currently an issues because the filter code doesn't do anything for these events, but they will in the future, and this needs to be fixed for when it does.

---
 kernel/trace/trace_export.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_export.c +1 -1
index 548e62eb5c46..d842f1eadfe5 100644
@@ -117,7 +117,7 @@ static void __always_unused ____ftrace_check_##name(void)		\
 
 #undef __dynamic_array
 #define __dynamic_array(type, item)					\
-	ret = trace_define_field(event_call, #type, #item,		\
+	ret = trace_define_field(event_call, #type "[]", #item,  \
 				 offsetof(typeof(field), item),		\
 				 0, is_signed_type(type), filter_type);\
 	if (ret)							\
Signature · 1 line
2.17.0
author maintainer
#5 lore raw

PATCH v3 5/14 tracing: Do not show filter file for ftrace internal events

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

The filter file in the ftrace internal events, like in /sys/kernel/tracing/events/ftrace/function/filter is not attached to any functionality. Do not create them as they are meaningless.

In the future, if an ftrace internal event gets filter functionality, then it will need to create it directly.

---
 kernel/trace/trace_events.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
kernel/trace/trace_events.c +6 -4
index 5b647904a65b..14ff4ff3caab 100644
@@ -2007,16 +2007,18 @@ event_create_dir(struct dentry *parent, struct trace_event_file *file)
 			return -1;
 		}
 	}
-	trace_create_file("filter", 0644, file->dir, file,
-			  &ftrace_event_filter_fops);
 
 	/*
 	 * Only event directories that can be enabled should have
-	 * triggers.
+	 * triggers or filters.
 	 */
-	if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE))
+	if (!(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) {
+		trace_create_file("filter", 0644, file->dir, file,
+				  &ftrace_event_filter_fops);
+
 		trace_create_file("trigger", 0644, file->dir, file,
 				  &event_trigger_fops);
+	}
 
 #ifdef CONFIG_HIST_TRIGGERS
 	trace_create_file("hist", 0444, file->dir, file,
Signature · 1 line
2.17.0
author maintainer
#6 lore raw

PATCH v3 6/14 tracing: Add trigger file for trace_markers tracefs/ftrace/print

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

Had to create a ftrace_event_register() function that will become the trace_marker print event's reg() function. This is required because of how triggers are enabled:

  event_trigger_write() {
    event_trigger_regex_write() {
      trigger_process_regex() {
        for p in trigger_commands {
          p->func(); /* trigger_snapshot_cmd->func */
            event_trigger_callback() {
              cmd_ops->reg() /* register_trigger() */ {
                trace_event_trigger_enable_disable() {
                  trace_event_enable_disable() {
                    call->class->reg();

Without the reg() function, the trigger code will call a NULL pointer and crash the system.

Cc Tom Zanussi <[email protected]>
Cc Clark Williams <[email protected]>
Cc Karim Yaghmour <[email protected]>
Cc Brendan Gregg <[email protected]>
---
 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(-)
kernel/trace/trace.c +17 -0
index e0d6ffb76985..f11b89fa5049 100644
@@ -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);
 
kernel/trace/trace.h +1 -0
index 2414fd72dedd..c7fa58d31a84 100644
@@ -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
kernel/trace/trace_entries.h +4 -2
index e3a658bac10f..1d67464ed95e 100644
@@ -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,
kernel/trace/trace_export.c +7 -0
index d842f1eadfe5..45630a76ed3a 100644
@@ -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
 
Signature · 1 line
2.17.0
author maintainer
#7 lore raw

PATCH v3 7/14 tracing: Have zero size length in filter logic be full string

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

As strings in trace events may not have a nul terminating character, the filter string compares use the defined string length for the field for the compares.

The trace_marker records data slightly different than do normal events. It's size is zero, meaning that the string is the rest of the array, and that the string also ends with '\0'.

If the size is zero, assume that the string is nul terminated and read the string in question as is.

---
 kernel/trace/trace_events_filter.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
kernel/trace/trace_events_filter.c +12 -11
index 7d306b74230f..0171407d231f 100644
@@ -750,31 +750,32 @@ static int filter_pred_none(struct filter_pred *pred, void *event)
  *
  * Note:
  * - @str might not be NULL-terminated if it's of type DYN_STRING
- *   or STATIC_STRING
+ *   or STATIC_STRING, unless @len is zero.
  */
 
 static int regex_match_full(char *str, struct regex *r, int len)
 {
-	if (strncmp(str, r->pattern, len) == 0)
-		return 1;
-	return 0;
+	/* len of zero means str is dynamic and ends with '\0' */
+	if (!len)
+		return strcmp(str, r->pattern) == 0;
+
+	return strncmp(str, r->pattern, len) == 0;
 }
 
 static int regex_match_front(char *str, struct regex *r, int len)
 {
-	if (len < r->len)
+	if (len && len < r->len)
 		return 0;
 
-	if (strncmp(str, r->pattern, r->len) == 0)
-		return 1;
-	return 0;
+	return strncmp(str, r->pattern, r->len) == 0;
 }
 
 static int regex_match_middle(char *str, struct regex *r, int len)
 {
-	if (strnstr(str, r->pattern, len))
-		return 1;
-	return 0;
+	if (!len)
+		return strstr(str, r->pattern) != NULL;
+
+	return strnstr(str, r->pattern, len) != NULL;
 }
 
 static int regex_match_end(char *str, struct regex *r, int len)
Signature · 1 line
2.17.0
author maintainer
#8 lore raw

PATCH v3 8/14 tracing: Prevent further users of zero size static arrays in trace events

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

A zero size static array has special meaning in the ftrace infrastructure. Trace events are for recording data in the trace buffers that is normally difficult to obtain via probes or function tracing. There is no reason for any trace event to declare a zero size static array.

If one does, BUILD_BUG_ON() will trigger and prevent the kernel from compiling.

---
 include/trace/trace_events.h | 1 +
 1 file changed, 1 insertion(+)
include/trace/trace_events.h +1 -0
index bfda803b0a09..4ecdfe2e3580 100644
@@ -422,6 +422,7 @@ static struct trace_event_functions trace_event_type_funcs_##call = {	\
 	do {								\
 		char *type_str = #type"["__stringify(len)"]";		\
 		BUILD_BUG_ON(len > MAX_FILTER_STR_VAL);			\
+		BUILD_BUG_ON(len <= 0);					\
 		ret = trace_define_field(event_call, type_str, #item,	\
 				 offsetof(typeof(field), item),		\
 				 sizeof(field.item),			\
Signature · 1 line
2.17.0
author maintainer
#9 lore raw

PATCH v3 9/14 tracing: Allow histogram triggers to access ftrace internal events

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Now that trace_marker can have triggers, including a histogram triggers, the onmatch() and onmax() access the trace event. To do so, the search routine to find the event file needs to use the raw __find_event_file() that does not filter out ftrace events.

---
 kernel/trace/trace_events_hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_hist.c +1 -1
index b9061ed59bbd..046c716a6536 100644
@@ -2865,7 +2865,7 @@ static struct trace_event_file *event_file(struct trace_array *tr,
 {
 	struct trace_event_file *file;
 
-	file = find_event_file(tr, system, event_name);
+	file = __find_event_file(tr, system, event_name);
 	if (!file)
 		return ERR_PTR(-EINVAL);
 
Signature · 1 line
2.17.0
author maintainer
#10 lore raw

PATCH v3 10/14 tracing: Document trace_marker triggers

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Add documentation and an example on how to use trace_marker triggers.

---
 Documentation/trace/events.rst    |   6 +-
 Documentation/trace/ftrace.rst    |   5 +
 Documentation/trace/histogram.txt | 546 +++++++++++++++++++++++++++++-
 3 files changed, 555 insertions(+), 2 deletions(-)
Documentation/trace/events.rst +5 -1
index a5ea2cb0082b..1afae55dc55c 100644
@@ -338,10 +338,14 @@ used for conditionally invoking triggers.
 
 The syntax for event triggers is roughly based on the syntax for
 set_ftrace_filter 'ftrace filter commands' (see the 'Filter commands'
-section of Documentation/trace/ftrace.txt), but there are major
+section of Documentation/trace/ftrace.rst), but there are major
 differences and the implementation isn't currently tied to it in any
 way, so beware about making generalizations between the two.
 
+Note: Writing into trace_marker (See Documentation/trace/ftrace.rst)
+     can also enable triggers that are written into
+     /sys/kernel/tracing/events/ftrace/print/trigger
+
 6.1 Expression syntax
 ---------------------
 
Documentation/trace/ftrace.rst +5 -0
index 67d9c38e95eb..aad4776c0f5d 100644
@@ -507,6 +507,11 @@ of ftrace. Here is a list of some of the key files:
 
 		trace_fd = open("trace_marker", WR_ONLY);
 
+	Note: Writing into the trace_marker file can also initiate triggers
+	      that are written into /sys/kernel/tracing/events/ftrace/print/trigger
+	      See "Event triggers" in Documentation/trace/events.rst and an
+              example in Documentation/trace/histogram.rst (Section 3.)
+
   trace_marker_raw:
 
 	This is similar to trace_marker above, but is meant for for binary data
Documentation/trace/histogram.txt +545 -1

555 lines not on this page · raw message

Signature · 1 line
2.17.0
author maintainer
#11 lore raw

PATCH v3 10/14 tracing: Document trace_marker triggers

From: "Steven Rostedt (VMware)" <[email protected]>

Add documentation and an example on how to use trace_marker triggers.

---
Sending this as 3.5 as I don't want to spam for a simple change.

Changes from v3:

- Removed cut and paste extra line to remove a histogram trigger (Tom Zanussi)

 Documentation/trace/events.rst    |   6 +-
 Documentation/trace/ftrace.rst    |   5 +
 Documentation/trace/histogram.txt | 545 +++++++++++++++++++++++++++++++++++++-
 3 files changed, 554 insertions(+), 2 deletions(-)
Documentation/trace/events.rst +5 -1
index a5ea2cb0082b..1afae55dc55c 100644
@@ -338,10 +338,14 @@ used for conditionally invoking triggers.
 
 The syntax for event triggers is roughly based on the syntax for
 set_ftrace_filter 'ftrace filter commands' (see the 'Filter commands'
-section of Documentation/trace/ftrace.txt), but there are major
+section of Documentation/trace/ftrace.rst), but there are major
 differences and the implementation isn't currently tied to it in any
 way, so beware about making generalizations between the two.
 
+Note: Writing into trace_marker (See Documentation/trace/ftrace.rst)
+     can also enable triggers that are written into
+     /sys/kernel/tracing/events/ftrace/print/trigger
+
 6.1 Expression syntax
 ---------------------
 
Documentation/trace/ftrace.rst +5 -0
index 67d9c38e95eb..aad4776c0f5d 100644
@@ -507,6 +507,11 @@ of ftrace. Here is a list of some of the key files:
 
 		trace_fd = open("trace_marker", WR_ONLY);
 
+	Note: Writing into the trace_marker file can also initiate triggers
+	      that are written into /sys/kernel/tracing/events/ftrace/print/trigger
+	      See "Event triggers" in Documentation/trace/events.rst and an
+              example in Documentation/trace/histogram.rst (Section 3.)
+
   trace_marker_raw:
 
 	This is similar to trace_marker above, but is meant for for binary data
Documentation/trace/histogram.txt +544 -1

554 lines not on this page · raw message

Signature · 1 line
2.13.6
author maintainer
#12 lore raw

PATCH v3 11/14 ftrace/selftest: Have the reset_trigger code be a bit more careful

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

The trigger code is picky in how it can be disabled as there may be dependencies between different events and synthetic events. Change the order on how triggers are reset.

1) Reset triggers of all synthetic events first
2) Remove triggers with actions attached to them
3) Remove all other triggers

If this order isn't followed, then some triggers will not be reset, and an error may happen because a trigger is busy.

Fixes cfa0963dc474f ("kselftests/ftrace : Add event trigger testcases")
---
 .../testing/selftests/ftrace/test.d/functions | 21 ++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +18 -3
index 2a4f16fc9819..8393b1c06027 100644
@@ -15,14 +15,29 @@ reset_tracer() { # reset the current tracer
     echo nop > current_tracer
 }
 
-reset_trigger() { # reset all current setting triggers
-    grep -v ^# events/*/*/trigger |
+reset_trigger_file() {
+    # remove action triggers first
+    grep -H ':on[^:]*(' $@ |
+    while read line; do
+        cmd=`echo $line | cut -f2- -d: | cut -f1 -d" "`
+	file=`echo $line | cut -f1 -d:`
+	echo "!$cmd" >> $file
+    done
+    grep -Hv ^# $@ |
     while read line; do
         cmd=`echo $line | cut -f2- -d: | cut -f1 -d" "`
-	echo "!$cmd" > `echo $line | cut -f1 -d:`
+	file=`echo $line | cut -f1 -d:`
+	echo "!$cmd" > $file
     done
 }
 
+reset_trigger() { # reset all current setting triggers
+    if [ -d events/synthetic ]; then
+        reset_trigger_file events/synthetic/*/trigger
+    fi
+    reset_trigger_file events/*/*/trigger
+}
+
 reset_events_filter() { # reset all current setting filters
     grep -v ^none events/*/*/filter |
     while read line; do
Signature · 1 line
2.17.0
author maintainer
#13 lore raw

PATCH v3 12/14 ftrace/selftest: Fix reset_trigger() to handle triggers with filters

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

The reset_trigger() function breaks up the command by a space ' '. This is useful to ignore the '[active]' word for triggers when removing them. But if the trigger has a filter (ie. "if prio < 10") then the filter needs to be attached to the line that is written into the trigger file to remove it. But the truncation removes the filter and the triggers are not cleared properly.

Before, reset_trigger() did this:

 # echo 'hist:keys=common_pid if prev_prio < 10' > events/sched/sched_switch/trigger
 # echo 'hist:keys=common_pid if next_prio < 10' >> events/sched/sched_switch/trigger
 # cat events/sched/sched_switch/trigger
hist:keys=common_pid:vals=hitcount:sort=hitcount:size=2048 if prev_prio < 10 [active]
hist:keys=common_pid:vals=hitcount:sort=hitcount:size=2048 if next_prio < 10 [active]

reset_trigger() {
echo '!hist:keys=common_pid:vals=hitcount:sort=hitcount:size=2048' >> events/sched/sched_switch/trigger
}

 # cat events/sched/sched_switch/trigger
hist:keys=common_pid:vals=hitcount:sort=hitcount:size=2048 if prev_prio < 10 [active]
hist:keys=common_pid:vals=hitcount:sort=hitcount:size=2048 if next_prio < 10 [active]

After, where it includes the filter:

reset_trigger() {
echo '!hist:keys=common_pid:vals=hitcount:sort=hitcount:size=2048 if prev_prio < 10' >> events/sched/sched_switch/trigger
}

 # cat events/sched/sched_switch/trigger
hist:keys=common_pid:vals=hitcount:sort=hitcount:size=2048 if next_prio < 10 [active]
Fixes cfa0963dc474f ("kselftests/ftrace : Add event trigger testcases")
---
 tools/testing/selftests/ftrace/test.d/functions | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/ftrace/test.d/functions +2 -2
index 8393b1c06027..e4645d5e3126 100644
@@ -19,13 +19,13 @@ reset_trigger_file() {
     # remove action triggers first
     grep -H ':on[^:]*(' $@ |
     while read line; do
-        cmd=`echo $line | cut -f2- -d: | cut -f1 -d" "`
+        cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
 	file=`echo $line | cut -f1 -d:`
 	echo "!$cmd" >> $file
     done
     grep -Hv ^# $@ |
     while read line; do
-        cmd=`echo $line | cut -f2- -d: | cut -f1 -d" "`
+        cmd=`echo $line | cut -f2- -d: | cut -f1 -d"["`
 	file=`echo $line | cut -f1 -d:`
 	echo "!$cmd" > $file
     done
Signature · 1 line
2.17.0
author maintainer
#14 lore raw

PATCH v3 13/14 tracing/selftest: Add selftests to test trace_marker histogram triggers

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Add a couple of tests that test the trace_marker histogram triggers. One does a straight histogram test, the other will create a synthetic event and test the latency between two different writes (using filters to differentiate between them).

---
 .../trigger/trigger-trace-marker-hist.tc      | 49 ++++++++++++++
 .../trigger/trigger-trace-marker-synthetic.tc | 66 +++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc new file +49 -0
new file mode 100644
index 000000000000..2acbfe2c0c0c
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram trigger
+# flags: instance
+
+do_reset() {
+    reset_trigger
+    echo > set_event
+    clear_trace
+}
+
+fail() { #msg
+    do_reset
+    echo $1
+    exit_fail
+}
+
+if [ ! -f set_event ]; then
+    echo "event tracing is not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/ftrace/print ]; then
+    echo "event trace_marker is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/trigger ]; then
+    echo "event trigger is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/hist ]; then
+    echo "hist trigger is not supported"
+    exit_unsupported
+fi
+
+do_reset
+
+echo "Test histogram trace_marker tigger"
+
+echo 'hist:keys=common_pid' > events/ftrace/print/trigger
+for i in `seq 1 10` ; do echo "hello" > trace_marker; done
+grep 'hitcount: *10$' events/ftrace/print/hist > /dev/null || \
+    fail "hist trigger did not trigger correct times on trace_marker"
+
+do_reset
+
+exit 0
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
2.17.0
maintainer Acked-by on v3 13/14
#15 lore raw

Re: [PATCH v3 13/14] tracing/selftest: Add selftests to test trace_marker histogram triggers

Quoted 7 lines · On Wed, 16 May 2018 11:00:25 -0400 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

Add a couple of tests that test the trace_marker histogram triggers. One does a straight histogram test, the other will create a synthetic event and test the latency between two different writes (using filters to differentiate between them).

This looks good to me.

BTW, would you plan to add simplar test case for the marker? (like just write a marker and read trace log, and run a simple
trigger, like taking a snapshot by marker)

Thanks,

Quoted 139 lines
---
 .../trigger/trigger-trace-marker-hist.tc      | 49 ++++++++++++++
 .../trigger/trigger-trace-marker-synthetic.tc | 66 +++++++++++++++++++
 2 files changed, 115 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc new file +49 -0
new file mode 100644
index 000000000000..2acbfe2c0c0c
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram trigger
+# flags: instance
+
+do_reset() {
+    reset_trigger
+    echo > set_event
+    clear_trace
+}
+
+fail() { #msg
+    do_reset
+    echo $1
+    exit_fail
+}
+
+if [ ! -f set_event ]; then
+    echo "event tracing is not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/ftrace/print ]; then
+    echo "event trace_marker is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/trigger ]; then
+    echo "event trigger is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/hist ]; then
+    echo "hist trigger is not supported"
+    exit_unsupported
+fi
+
+do_reset
+
+echo "Test histogram trace_marker tigger"
+
+echo 'hist:keys=common_pid' > events/ftrace/print/trigger
+for i in `seq 1 10` ; do echo "hello" > trace_marker; done
+grep 'hitcount: *10$' events/ftrace/print/hist > /dev/null || \
+    fail "hist trigger did not trigger correct times on trace_marker"
+
+do_reset
+
+exit 0
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc new file +66 -0
new file mode 100644
index 000000000000..3666dd6ab02a
@@ -0,0 +1,66 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram with synthetic event
+# flags:
+
+do_reset() {
+    reset_trigger
+    echo > set_event
+    echo > synthetic_events
+    clear_trace
+}
+
+fail() { #msg
+    do_reset
+    echo $1
+    exit_fail
+}
+
+if [ ! -f set_event ]; then
+    echo "event tracing is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+    echo "synthetic events not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/ftrace/print ]; then
+    echo "event trace_marker is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/trigger ]; then
+    echo "event trigger is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/hist ]; then
+    echo "hist trigger is not supported"
+    exit_unsupported
+fi
+
+do_reset
+
+echo "Test histogram trace_marker to trace_marker latency histogram trigger"
+
+echo 'latency u64 lat' > synthetic_events
+echo 'hist:keys=common_pid:ts0=common_timestamp.usecs if buf == "start"' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat) if buf == "end"' >> events/ftrace/print/trigger
+echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+echo -n "start" > trace_marker
+echo -n "end" > trace_marker
+
+cnt=`grep 'hitcount: *1$' events/ftrace/print/hist | wc -l`
+
+if [ $cnt -ne 2 ]; then
+    fail "hist trace_marker trigger did not trigger correctly"
+fi
+
+grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
+    fail "hist trigger did not trigger "
+
+do_reset
+
+exit 0
Signature · 1 line
2.17.0
Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#16 lore raw

Re: [PATCH v3 13/14] tracing/selftest: Add selftests to test trace_marker histogram triggers

Quoted 3 lines · On Wed, 23 May 2018 23:13:31 +0900 Masami Hiramatsu <[email protected]> wrote:

This looks good to me.

Thanks!

Quoted 4 lines

BTW, would you plan to add simplar test case for the marker? (like just write a marker and read trace log, and run a simple
trigger, like taking a snapshot by marker)

I wasn't planning to, but I could.

-- Steve

author maintainer
#17 lore raw

Re: [PATCH v3 13/14] tracing/selftest: Add selftests to test trace_marker histogram triggers

Quoted 6 lines · On Fri, 25 May 2018 14:07:31 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 4 lines

BTW, would you plan to add simplar test case for the marker? (like just write a marker and read trace log, and run a simple
trigger, like taking a snapshot by marker)

I wasn't planning to, but I could.

Like something like this?

I had to remove the "instance" flag because it triggered a bug, that is unrelated to this patch series. But that's a good thing. It found a bug :-)

-- Steve

#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# description: trace_marker trigger - test snapshot trigger # flags:

do_reset() {
reset_trigger
echo > set_event
echo 0 > snapshot
clear_trace
}

fail() { #msg

    do_reset
    echo $1
    exit_fail
}

if [ ! -f set_event ]; then
echo "event tracing is not supported"
exit_unsupported
fi

if [ ! -f snapshot ]; then
echo "snapshot is not supported"
exit_unsupported
fi

if [ ! -d events/ftrace/print ]; then
echo "event trace_marker is not supported"
exit_unsupported
fi

if [ ! -f events/ftrace/print/trigger ]; then
echo "event trigger is not supported"
exit_unsupported
fi

test_trace() {
    file=$1
    x=$2

    cat $file | while read line; do
	if [ "$line" != "${line/\#/}" ]; then
	    continue
	fi
	echo "testing $line for >$x<"
	if [ "$line" == "${line/>$x</}" ]; then
	    fail "$line does not have >$x< in it"
	fi
	let x=$x+2
    done
}

do_reset

echo "Test snapshot trace_marker tigger"

echo 'snapshot' > events/ftrace/print/trigger

# make sure the snapshot is allocated

grep -q 'Snapshot is allocated' snapshot

for i in seq 1 10 ; do echo "hello >$i<" > trace_marker; done

test_trace trace 1
test_trace snapshot 2

do_reset

exit 0

author maintainer
#18 lore raw

Re: [PATCH v3 13/14] tracing/selftest: Add selftests to test trace_marker histogram triggers

Quoted 1 line · On Fri, 25 May 2018 17:12:29 -0400 Steven Rostedt <[email protected]> wrote:

#!/bin/sh

Hmm, I think I need to make this #!/bin/bash

Quoted 10 lines
test_trace() {
    file=$1
    x=$2

    cat $file | while read line; do
	if [ "$line" != "${line/\#/}" ]; then
	    continue
	fi
	echo "testing $line for >$x<"
	if [ "$line" == "${line/>$x</}" ]; then

The ${line/>$x</} is unique to bash I believe.

-- Steve

Quoted 6 lines
	    fail "$line does not have >$x< in it"
	fi
	let x=$x+2
    done
}
maintainer
#19 lore raw

Re: [PATCH v3 13/14] tracing/selftest: Add selftests to test trace_marker histogram triggers

Hi Steve,

Quoted 12 lines · On Fri, 25 May 2018 17:13:53 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 1 line · On Fri, 25 May 2018 17:12:29 -0400 Steven Rostedt <[email protected]> wrote:

#!/bin/sh

Hmm, I think I need to make this #!/bin/bash

Quoted 4 lines
test_trace() {
    file=$1
    x=$2
Quoted 8 lines
Quoted 6 lines

cat $file | while read line; do
if [ "$line" != "${line/\#/}" ]; then
continue
fi
echo "testing $line for >$x<"
if [ "$line" == "${line/>$x</}" ]; then

The ${line/>$x</} is unique to bash I believe.

Hmm, could you try to use only posix-shell based test ? Since I would like to keep this can run on small environment, like busybox, etc.

Thank you,

Quoted 9 lines

-- Steve

Quoted 6 lines
	    fail "$line does not have >$x< in it"
	fi
	let x=$x+2
    done
}
Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#20 lore raw

Re: [PATCH v3 13/14] tracing/selftest: Add selftests to test trace_marker histogram triggers

Quoted 24 lines · On Mon, 28 May 2018 01:32:58 +0900 Masami Hiramatsu <[email protected]> wrote:

Hi Steve,

Quoted 19 lines · On Fri, 25 May 2018 17:13:53 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 1 line · On Fri, 25 May 2018 17:12:29 -0400 Steven Rostedt <[email protected]> wrote:

#!/bin/sh

Hmm, I think I need to make this #!/bin/bash

Quoted 10 lines
test_trace() {
    file=$1
    x=$2

    cat $file | while read line; do
	if [ "$line" != "${line/\#/}" ]; then
	    continue
	fi
	echo "testing $line for >$x<"
	if [ "$line" == "${line/>$x</}" ]; then  
Quoted 6 lines
Quoted 1 line

The ${line/>$x</} is unique to bash I believe.

Hmm, could you try to use only posix-shell based test ? Since I would like to keep this can run on small environment, like busybox, etc.

Like something like this?

-- Steve

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-snapshot.tc +4 -2
index c6c50a2..3a3c33d 100644
@@ -41,11 +41,13 @@ test_trace() {
     x=$2
 
     cat $file | while read line; do
-	if [ "$line" != "${line/\#/}" ]; then
+	comment=`echo $line | sed -e 's/^#//'`
+	if [ "$line" != "$comment" ]; then
 	    continue
 	fi
 	echo "testing $line for >$x<"
-	if [ "$line" == "${line/>$x</}" ]; then
+	match=`echo $line | sed -e "s/>$x<//"`
+	if [ "$line" == "$match" ]; then
 	    fail "$line does not have >$x< in it"
 	fi
 	let x=$x+2
maintainer Acked-by
#21 lore raw

Re: [PATCH v3 13/14] tracing/selftest: Add selftests to test trace_marker histogram triggers

Quoted 27 lines · On Mon, 28 May 2018 21:20:55 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 24 lines · On Mon, 28 May 2018 01:32:58 +0900 Masami Hiramatsu <[email protected]> wrote:

Hi Steve,

Quoted 19 lines · On Fri, 25 May 2018 17:13:53 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 1 line · On Fri, 25 May 2018 17:12:29 -0400 Steven Rostedt <[email protected]> wrote:

#!/bin/sh

Hmm, I think I need to make this #!/bin/bash

Quoted 10 lines
test_trace() {
    file=$1
    x=$2

    cat $file | while read line; do
	if [ "$line" != "${line/\#/}" ]; then
	    continue
	fi
	echo "testing $line for >$x<"
	if [ "$line" == "${line/>$x</}" ]; then  
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

The ${line/>$x</} is unique to bash I believe.

Hmm, could you try to use only posix-shell based test ? Since I would like to keep this can run on small environment, like busybox, etc.

Like something like this?

This looks good to me. :)

Thanks,

Quoted 23 lines

-- Steve

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-snapshot.tc +4 -2
index c6c50a2..3a3c33d 100644
@@ -41,11 +41,13 @@ test_trace() {
     x=$2
 
     cat $file | while read line; do
-	if [ "$line" != "${line/\#/}" ]; then
+	comment=`echo $line | sed -e 's/^#//'`
+	if [ "$line" != "$comment" ]; then
 	    continue
 	fi
 	echo "testing $line for >$x<"
-	if [ "$line" == "${line/>$x</}" ]; then
+	match=`echo $line | sed -e "s/>$x<//"`
+	if [ "$line" == "$match" ]; then
 	    fail "$line does not have >$x< in it"
 	fi
 	let x=$x+2
Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#22 lore raw

PATCH v3 14/14 tracing/selftest: Add test to test hist trigger between kernel event and trace_marker

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

Add a test that tests a trigger that is initiated by a kernel event (sched_waking) and compared to a write to the trace_marker.

---
 .../trigger/trigger-trace-marker-synthetic.tc | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +22 -0
index 3666dd6ab02a..b06996ecd5e0 100644
@@ -31,6 +31,11 @@ if [ ! -d events/ftrace/print ]; then
     exit_unsupported
 fi
 
+if [ ! -d events/sched/sched_waking ]; then
+    echo "event sched_waking is not supported"
+    exit_unsupported
+fi
+
 if [ ! -f events/ftrace/print/trigger ]; then
     echo "event trigger is not supported"
     exit_unsupported
@@ -63,4 +68,21 @@ grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
 
 do_reset
 
+echo "Test histogram kernel event to trace_marker latency histogram trigger"
+
+echo 'latency u64 lat' > synthetic_events
+echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+sleep 1
+echo "hello" > trace_marker
+
+grep 'hitcount: *1$' events/ftrace/print/hist > /dev/null || \
+    fail "hist trigger did not trigger correct times on trace_marker"
+
+grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
+    fail "hist trigger did not trigger "
+
+do_reset
+
 exit 0
Signature · 1 line
2.17.0
maintainer
#23 lore raw

Re: [PATCH v3 14/14] tracing/selftest: Add test to test hist trigger between kernel event and trace_marker

Quoted 15 lines · On Wed, 16 May 2018 11:00:26 -0400 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

Add a test that tests a trigger that is initiated by a kernel event (sched_waking) and compared to a write to the trace_marker.

---
 .../trigger/trigger-trace-marker-synthetic.tc | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +0 -0
index 3666dd6ab02a..b06996ecd5e0 100644

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc if [ ! -d events/ftrace/print ]; then · line 37

Quoted 7 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +4 -0
@@ -31,6 +31,11 @@ if [ ! -d events/ftrace/print ]; then
     exit_unsupported
 fi
 
+if [ ! -d events/sched/sched_waking ]; then
+    echo "event sched_waking is not supported"
+    exit_unsupported
+fi

Hmm, this looks no good sign... Can you split this out to another testcase, since this check is only for new test case below?

[..]

Quoted 11 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +7 -0
@@ -63,4 +68,21 @@ grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
 
 do_reset
 
+echo "Test histogram kernel event to trace_marker latency histogram trigger"
+
+echo 'latency u64 lat' > synthetic_events
+echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+sleep 1

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \ · line 87

Quoted 10 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +10 -0
+echo "hello" > trace_marker
+
+grep 'hitcount: *1$' events/ftrace/print/hist > /dev/null || \
+    fail "hist trigger did not trigger correct times on trace_marker"
+
+grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
+    fail "hist trigger did not trigger "
+
+do_reset
+

Thank you,

Signature · 1 line
Masami Hiramatsu <[email protected]>
author maintainer
#24 lore raw

Re: [PATCH v3 14/14] tracing/selftest: Add test to test hist trigger between kernel event and trace_marker

Quoted 21 lines · On Wed, 23 May 2018 23:15:59 +0900 Masami Hiramatsu <[email protected]> wrote:
Quoted 18 lines · On Wed, 16 May 2018 11:00:26 -0400 Steven Rostedt <[email protected]> wrote:

From: "Steven Rostedt (VMware)" <[email protected]>

Add a test that tests a trigger that is initiated by a kernel event (sched_waking) and compared to a write to the trace_marker.

---
 .../trigger/trigger-trace-marker-synthetic.tc | 22 +++++++++++++++++++
 1 file changed, 22 insertions(+)
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +0 -0
index 3666dd6ab02a..b06996ecd5e0 100644
@@ -31,6 +31,11 @@ if [ ! -d events/ftrace/print ]; then
     exit_unsupported
 fi
 
Quoted 8 lines

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc if [ ! -d events/ftrace/print ]; then · line 37

Quoted 4 lines
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +4 -0
+if [ ! -d events/sched/sched_waking ]; then
+    echo "event sched_waking is not supported"
+    exit_unsupported
+fi  

Hmm, this looks no good sign... Can you split this out to another testcase, since this check is only for new test case below?

You mean like this?

-- Steve

Quoted 1 line

From 9a34a00fb3c44e5adebb31e6e7d9e8c233797200 Mon Sep 17 00:00:00 2001

From: "Steven Rostedt (VMware)" <[email protected]>
Date: Mon, 14 May 2018 15:47:07 -0400
Subject: [PATCH] tracing/selftest: Add test to test hist trigger between
kernel event and trace_marker

Add a test that tests a trigger that is initiated by a kernel event (sched_waking) and compared to a write to the trace_marker.

---
 .../trigger-trace-marker-synthetic-kernel.tc       | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc new file +68 -0
new file mode 100644
index 000000000000..447df015c56f
@@ -0,0 +1,68 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram with synthetic event
+# flags:
+
+do_reset() {
+    reset_trigger
+    echo > set_event
+    echo > synthetic_events
+    clear_trace
+}
+
+fail() { #msg
+    do_reset
+    echo $1
+    exit_fail
+}
+
+if [ ! -f set_event ]; then
+    echo "event tracing is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+    echo "synthetic events not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/ftrace/print ]; then
+    echo "event trace_marker is not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/sched/sched_waking ]; then
+    echo "event sched_waking is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/trigger ]; then
+    echo "event trigger is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/hist ]; then
+    echo "hist trigger is not supported"
+    exit_unsupported
+fi
+
+do_reset
+
+echo "Test histogram kernel event to trace_marker latency histogram trigger"
+
+echo 'latency u64 lat' > synthetic_events
+echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+sleep 1
+echo "hello" > trace_marker
+
+grep 'hitcount: *1$' events/ftrace/print/hist > /dev/null || \
+    fail "hist trigger did not trigger correct times on trace_marker"
+
+grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
+    fail "hist trigger did not trigger "
+
+do_reset
+
+exit 0
Signature · 1 line
2.13.6
author maintainer
#25 lore raw

Re: [PATCH v3 14/14] tracing/selftest: Add test to test hist trigger between kernel event and trace_marker

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc line 5

Quoted 11 lines · On Fri, 25 May 2018 14:15:06 -0400 Steven Rostedt <[email protected]> wrote:
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc new file +5 -0
new file mode 100644
index 000000000000..447df015c56f
@@ -0,0 +1,68 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram with synthetic event
+# flags:
+

I forgot to update the description. Here's the new patch:

-- Steve

Quoted 1 line

From 9699fdb67ba8ea9981bd0af1802209b0011a86ab Mon Sep 17 00:00:00 2001

From: "Steven Rostedt (VMware)" <[email protected]>
Date: Mon, 14 May 2018 15:47:07 -0400
Subject: [PATCH] tracing/selftest: Add test to test hist trigger between
kernel event and trace_marker

Add a test that tests a trigger that is initiated by a kernel event (sched_waking) and compared to a write to the trace_marker.

---
 .../trigger-trace-marker-synthetic-kernel.tc       | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc new file +68 -0
new file mode 100644
index 000000000000..0a69c5d1cda8
@@ -0,0 +1,68 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram with synthetic event against kernel event
+# flags:
+
+do_reset() {
+    reset_trigger
+    echo > set_event
+    echo > synthetic_events
+    clear_trace
+}
+
+fail() { #msg
+    do_reset
+    echo $1
+    exit_fail
+}
+
+if [ ! -f set_event ]; then
+    echo "event tracing is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+    echo "synthetic events not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/ftrace/print ]; then
+    echo "event trace_marker is not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/sched/sched_waking ]; then
+    echo "event sched_waking is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/trigger ]; then
+    echo "event trigger is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/hist ]; then
+    echo "hist trigger is not supported"
+    exit_unsupported
+fi
+
+do_reset
+
+echo "Test histogram kernel event to trace_marker latency histogram trigger"
+
+echo 'latency u64 lat' > synthetic_events
+echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+sleep 1
+echo "hello" > trace_marker
+
+grep 'hitcount: *1$' events/ftrace/print/hist > /dev/null || \
+    fail "hist trigger did not trigger correct times on trace_marker"
+
+grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
+    fail "hist trigger did not trigger "
+
+do_reset
+
+exit 0
Signature · 1 line
2.13.6
maintainer Acked-by
#26 lore raw

Re: [PATCH v3 14/14] tracing/selftest: Add test to test hist trigger between kernel event and trace_marker

Quoted 19 lines · On Fri, 25 May 2018 14:19:43 -0400 Steven Rostedt <[email protected]> wrote:

tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc line 5

Quoted 11 lines · On Fri, 25 May 2018 14:15:06 -0400 Steven Rostedt <[email protected]> wrote:
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc new file +5 -0
new file mode 100644
index 000000000000..447df015c56f
@@ -0,0 +1,68 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram with synthetic event
+# flags:
+

I forgot to update the description. Here's the new patch:

-- Steve

Quoted 9 lines

From 9699fdb67ba8ea9981bd0af1802209b0011a86ab Mon Sep 17 00:00:00 2001
From: "Steven Rostedt (VMware)" <[email protected]>
Date: Mon, 14 May 2018 15:47:07 -0400
Subject: [PATCH] tracing/selftest: Add test to test hist trigger between
kernel event and trace_marker

Add a test that tests a trigger that is initiated by a kernel event (sched_waking) and compared to a write to the trace_marker.

Yeah, this looks good to me :)

Thanks!

Quoted 83 lines
---
 .../trigger-trace-marker-synthetic-kernel.tc       | 68 ++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic-kernel.tc new file +68 -0
new file mode 100644
index 000000000000..0a69c5d1cda8
@@ -0,0 +1,68 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0
+# description: trace_marker trigger - test histogram with synthetic event against kernel event
+# flags:
+
+do_reset() {
+    reset_trigger
+    echo > set_event
+    echo > synthetic_events
+    clear_trace
+}
+
+fail() { #msg
+    do_reset
+    echo $1
+    exit_fail
+}
+
+if [ ! -f set_event ]; then
+    echo "event tracing is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f synthetic_events ]; then
+    echo "synthetic events not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/ftrace/print ]; then
+    echo "event trace_marker is not supported"
+    exit_unsupported
+fi
+
+if [ ! -d events/sched/sched_waking ]; then
+    echo "event sched_waking is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/trigger ]; then
+    echo "event trigger is not supported"
+    exit_unsupported
+fi
+
+if [ ! -f events/ftrace/print/hist ]; then
+    echo "hist trigger is not supported"
+    exit_unsupported
+fi
+
+do_reset
+
+echo "Test histogram kernel event to trace_marker latency histogram trigger"
+
+echo 'latency u64 lat' > synthetic_events
+echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
+sleep 1
+echo "hello" > trace_marker
+
+grep 'hitcount: *1$' events/ftrace/print/hist > /dev/null || \
+    fail "hist trigger did not trigger correct times on trace_marker"
+
+grep 'hitcount: *1$' events/synthetic/latency/hist > /dev/null || \
+    fail "hist trigger did not trigger "
+
+do_reset
+
+exit 0
Signature · 1 line
2.13.6
Signature · 1 line
Masami Hiramatsu <[email protected]>
Reviewed-by on the v3 series
#27 lore raw
In reply to Steven Rostedt

Hi Steve,

Quoted 48 lines · Steven Rostedt

A few people have asked for this in the past, and I finally got around to implementing it. What this does is to allow writes into trace_marker to initiate a trigger.

The trace_marker event is described in:

tracefs/events/ftrace/print

Thus the trigger file is added there:

tracefs/events/ftrace/print/trigger

As there's already a "hist" file there, everything appears to work just like any other trigger to an event. See the last patch for documentation on how to use the triggers to a trace_marker write.

By the way, the patch:

tracing: Prevent further users of zero size static arrays in trace events

May prevent your kernel from building if you include Xen. You will need to add this patch to make it work (or include the git repo below).

http://lkml.kernel.org/r/[email protected]

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
ftrace/core

Head SHA1: dded7b759602085b4bd2c5581f58f6b179912d89

Steven Rostedt (VMware) (14):
tracing: Do not reference event data in post call triggers
tracing: Add __find_event_file() to find event files without restrictions
tracing: Have event_trace_init() called by trace_init_tracefs()
tracing: Add brackets in ftrace event dynamic arrays
tracing: Do not show filter file for ftrace internal events
tracing: Add trigger file for trace_markers tracefs/ftrace/print
tracing: Have zero size length in filter logic be full string
tracing: Prevent further users of zero size static arrays in trace events
tracing: Allow histogram triggers to access ftrace internal events
tracing: Document trace_marker triggers
ftrace/selftest: Have the reset_trigger code be a bit more careful ftrace/selftest: Fix reset_trigger() to handle triggers with filters tracing/selftest: Add selftests to test trace_marker histogram triggers tracing/selftest: Add test to test hist trigger between kernel event and trace_marker

Quoted 1 line

----

For the series:

Thanks,
Namhyung

Quoted 105 lines

Changes since v2:

- typo fixes in documentation (Tom Zanussi)
- Rename trigger-trace-marker{-hist} in selftest (Masami Hiramatsu)
- Fix onmatch(sched.sched_waking) (Namhyung Kim)
- Rename test to say trace_marker trigger from event trigger (Steven Rostedt)

Diff from v2 below.

 Documentation/trace/events.rst                     |   6 +-
 Documentation/trace/ftrace.rst                     |   5 +
 Documentation/trace/histogram.txt                  | 546 ++++++++++++++++++++-
 include/linux/trace_events.h                       |   3 +-
 include/trace/trace_events.h                       |   1 +
 kernel/trace/trace.c                               |  19 +
 kernel/trace/trace.h                               |   9 +-
 kernel/trace/trace_entries.h                       |   6 +-
 kernel/trace/trace_events.c                        |  36 +-
 kernel/trace/trace_events_filter.c                 |  23 +-
 kernel/trace/trace_events_hist.c                   |   2 +-
 kernel/trace/trace_events_trigger.c                |   6 +-
 kernel/trace/trace_export.c                        |   9 +-
 tools/testing/selftests/ftrace/test.d/functions    |  23 +-
 .../test.d/trigger/trigger-trace-marker-hist.tc    |  49 ++
 .../trigger/trigger-trace-marker-synthetic.tc      |  88 ++++
 16 files changed, 790 insertions(+), 41 deletions(-)
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc
 create mode 100644 tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc
Documentation/trace/histogram.txt +5 -5
index 8c871f0c0e33..ae2d4f9d0a62 100644
@@ -2005,7 +2005,7 @@ and after it wakes up, something like this:
 
 static void traceputs(char *str)
 {
-	/* tracemark_fd is the trace_marker file descripto */
+	/* tracemark_fd is the trace_marker file descriptor */
 	if (tracemark_fd < 0)
 		return;
 	/* write the tracemark message */
@@ -2048,7 +2048,7 @@ Now running cyclictest with:
 
 Note, the -b 1000 is used just to make --tracemark available.
 
-The we can see the histogram created by this with:
+Then we can see the histogram created by this with:
 
  # cat events/synthetic/latency/hist
 # event histogram
@@ -2360,7 +2360,7 @@ kernel with trace_marker.
 
 The difference this time is that instead of using the trace_marker to start
 the latency, the sched_waking event is used, matching the common_pid for the
-trace_marker write with the pid that is being worken by sched_waking.
+trace_marker write with the pid that is being woken by sched_waking.
 
 After running cyclictest again with the same parameters, we now have:
 
@@ -2535,5 +2535,5 @@ Totals:
     Dropped: 0
 
 This doesn't tell us any information about how late cyclictest may have
-worken up, but it does show us a nice histogram of how long it took from
-the time that cyclictest was worken to the time it made it into user space.
+woken up, but it does show us a nice histogram of how long it took from
+the time that cyclictest was woken to the time it made it into user space.
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc renamed from tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker.tc +1 -1
similarity index 93%
rename from tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker.tc
rename to tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-hist.tc
index 48e7ac1ccbc1..2acbfe2c0c0c 100644
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-# description: event trigger - test histogram trigger
+# description: trace_marker trigger - test histogram trigger
 # flags: instance
 
 do_reset() {
tools/testing/selftests/ftrace/test.d/trigger/trigger-trace-marker-synthetic.tc +2 -2
index d8cfc36f228b..b06996ecd5e0 100644
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0
-# description: event trigger - test histogram with synthetic event
+# description: trace_marker trigger - test histogram with synthetic event
 # flags:
 
 do_reset() {
@@ -72,7 +72,7 @@ echo "Test histogram kernel event to trace_marker latency histogram trigger"
 
 echo 'latency u64 lat' > synthetic_events
 echo 'hist:keys=pid:ts0=common_timestamp.usecs' > events/sched/sched_waking/trigger
-echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(ftrace.print).latency($lat)' > events/ftrace/print/trigger
+echo 'hist:keys=common_pid:lat=common_timestamp.usecs-$ts0:onmatch(sched.sched_waking).latency($lat)' > events/ftrace/print/trigger
 echo 'hist:keys=common_pid,lat:sort=lat' > events/synthetic/latency/trigger
 sleep 1
 echo "hello" > trace_marker