Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1675182

[PATCH 27/32] tracing: Add cpu field for hist triggers

From Tom Zanussi <tom.zanussi@linux.intel.com>
Newsgroups linux.kernel
Subject [PATCH 27/32] tracing: Add cpu field for hist triggers
Date 2017-06-27 01:00 +0200
Message-ID <tWL9a-8u4-91@gated-at.bofh.it> (permalink)
References <tWKZs-8nP-19@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


A common key to use in a histogram is the cpuid - add a new cpu
'synthetic' field for that purpose.  This field is named cpu rather
than $cpu or $common_cpu because 'cpu' already exists as a special
filter field and it makes more sense to match that rather than add
another name for the same thing.

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
 Documentation/trace/events.txt   | 18 ++++++++++++++++++
 kernel/trace/trace_events_hist.c | 30 +++++++++++++++++++++++++++---
 2 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/Documentation/trace/events.txt b/Documentation/trace/events.txt
index 2cc08d4..9717688 100644
--- a/Documentation/trace/events.txt
+++ b/Documentation/trace/events.txt
@@ -668,6 +668,24 @@ The following commands are supported:
   The examples below provide a more concrete illustration of the
   concepts and typical usage patterns discussed above.
 
+  'synthetic' event fields
+  ------------------------
+
+  There are a number of 'synthetic fields' available for use as keys
+  or values in a hist trigger.  These look like and behave as if they
+  were event fields, but aren't actually part of the event's field
+  definition or format file.  They are however available for any
+  event, and can be used anywhere an actual event field could be.
+  'Synthetic' field names are always prefixed with a '$' character to
+  indicate that they're not normal fields (with the exception of
+  'cpu', for compatibility with existing filter usage):
+
+    $common_timestamp      u64 - timestamp (from ring buffer) associated
+                                 with the event, in nanoseconds.  May be
+				 modified by .usecs to have timestamps
+				 interpreted as microseconds.
+    cpu                    int - the cpu on which the event occurred.
+
 
 6.2 'hist' trigger examples
 ---------------------------
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index ab94e2a..904a635 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -224,6 +224,7 @@ enum hist_field_flags {
 	HIST_FIELD_FL_VAR_ONLY		= 8192,
 	HIST_FIELD_FL_EXPR		= 16384,
 	HIST_FIELD_FL_VAR_REF		= 32768,
+	HIST_FIELD_FL_CPU		= 65536,
 };
 
 struct hist_trigger_attrs {
@@ -1081,6 +1082,16 @@ static u64 hist_field_timestamp(struct hist_field *hist_field,
 	return ts;
 }
 
+static u64 hist_field_cpu(struct hist_field *hist_field,
+			  struct tracing_map_elt *elt,
+			  struct ring_buffer_event *rbe,
+			  void *event)
+{
+	int cpu = raw_smp_processor_id();
+
+	return cpu;
+}
+
 static struct hist_field *check_var_ref(struct hist_field *hist_field,
 					struct hist_trigger_data *var_data,
 					unsigned int var_idx)
@@ -1407,6 +1418,8 @@ static const char *hist_field_name(struct hist_field *field,
 		field_name = hist_field_name(field->operands[0], ++level);
 	else if (field->flags & HIST_FIELD_FL_TIMESTAMP)
 		field_name = "$common_timestamp";
+	else if (field->flags & HIST_FIELD_FL_CPU)
+		field_name = "cpu";
 	else if (field->flags & HIST_FIELD_FL_EXPR ||
 		 field->flags & HIST_FIELD_FL_VAR_REF)
 		field_name = field->name;
@@ -1848,6 +1861,15 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
 		goto out;
 	}
 
+	if (flags & HIST_FIELD_FL_CPU) {
+		hist_field->fn = hist_field_cpu;
+		hist_field->size = sizeof(int);
+		hist_field->type = kstrdup("int", GFP_KERNEL);
+		if (!hist_field->type)
+			goto free;
+		goto out;
+	}
+
 	if (WARN_ON_ONCE(!field))
 		goto out;
 
@@ -1980,7 +2002,9 @@ static struct hist_field *parse_var_ref(char *system, char *event_name,
 		hist_data->enable_timestamps = true;
 		if (*flags & HIST_FIELD_FL_TIMESTAMP_USECS)
 			hist_data->attrs->ts_in_usecs = true;
-	} else {
+	} else if (strcmp(field_name, "cpu") == 0)
+		*flags |= HIST_FIELD_FL_CPU;
+	else {
 		field = trace_find_event_field(file->event_call, field_name);
 		if (!field)
 			return ERR_PTR(-EINVAL);
@@ -3019,7 +3043,6 @@ static int onmatch_create(struct hist_trigger_data *hist_data,
 				goto out;
 			}
 		}
-
 		if (param[0] == '$')
 			hist_field = onmatch_find_var(hist_data, data, system,
 						      event_name, param);
@@ -3034,7 +3057,6 @@ static int onmatch_create(struct hist_trigger_data *hist_data,
 			ret = -EINVAL;
 			goto out;
 		}
-
 		if (check_synth_field(event, hist_field, field_pos) == 0) {
 			var_ref = create_var_ref(hist_field);
 			if (!var_ref) {
@@ -4128,6 +4150,8 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
 
 	if (hist_field->flags & HIST_FIELD_FL_TIMESTAMP)
 		seq_puts(m, "$common_timestamp");
+	else if (hist_field->flags & HIST_FIELD_FL_CPU)
+		seq_puts(m, "cpu");
 	else if (field_name)
 		seq_printf(m, "%s", field_name);
 
-- 
1.9.3

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 00/32]  tracing: Inter-event (e.g. latency) support Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 00:50 +0200
  [PATCH 17/32] tracing: Account for variables in named trigger compatibility Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 02/32] tracing: Reimplement log2 Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 10/32] tracing: Add NO_DISCARD event file flag Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 11/32] tracing: Add post-trigger flag to hist trigger command Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 19/32] tracing: Add variable reference handling to hist triggers Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 29/32] tracing: Add 'last error' error facility for hist triggers Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 04/32] ring-buffer: Redefine the unimplemented RINGBUF_TIME_TIME_STAMP Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
    Re: [PATCH 04/32] ring-buffer: Redefine the unimplemented RINGBUF_TIME_TIME_STAMP "Joel Fernandes (Google)" <joel.opensrc@gmail.com> - 2017-07-02 11:00 +0200
  [PATCH 06/32] tracing: Add ring buffer event param to hist field functions Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 16/32] tracing: Add variable support to hist triggers Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 20/32] tracing: Add support for dynamic tracepoints Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 24/32] tracing: Add 'onmax' hist trigger action support Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 03/32] ring-buffer: Add interface for setting absolute time stamps Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 13/32] tracing: Add per-element variable support to tracing_map Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 09/32] tracing: Make traceprobe parsing code reusable Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 28/32] tracing: Add hist trigger support for variable reference aliases Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 32/32] tracing: Add a clock attribute for hist triggers Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 25/32] tracing: Allow whitespace to surround hist trigger filter Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 05/32] tracing: Give event triggers access to ring_buffer_event Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 21/32] tracing: Add hist trigger action hook Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 07/32] tracing: Increase tracing map KEYS_MAX size Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 30/32] tracing: Add inter-event hist trigger Documentation Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 31/32] tracing: Make tracing_set_clock() non-static Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 22/32] tracing: Add support for 'synthetic' events Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 12/32] tracing: Add hist trigger timestamp support Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 18/32] tracing: Add simple expression support to hist triggers Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 08/32] tracing: Break out hist trigger assignment parsing Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 15/32] tracing: Add usecs modifier for hist trigger timestamps Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 23/32] tracing: Add 'onmatch' hist trigger action support Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 14/32] tracing: Add hist_data member to hist_field Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 26/32] tracing: Make duplicate count from tracing_map available Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 01/32] tracing: Add hist_field_name() accessor Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  [PATCH 27/32] tracing: Add cpu field for hist triggers Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-27 01:00 +0200
  Re: [PATCH 00/32]  tracing: Inter-event (e.g. latency) support Steven Rostedt <rostedt@goodmis.org> - 2017-06-27 17:10 +0200
  Re: [PATCH 00/32]  tracing: Inter-event (e.g. latency) support Masami Hiramatsu <mhiramat@kernel.org> - 2017-06-28 16:30 +0200
    Re: [PATCH 00/32]  tracing: Inter-event (e.g. latency) support Tom Zanussi <tom.zanussi@linux.intel.com> - 2017-06-28 21:20 +0200
  Re: [PATCH 00/32] tracing: Inter-event (e.g. latency) support "Joel Fernandes (Google)" <joel.opensrc@gmail.com> - 2017-07-01 09:10 +0200

csiph-web