From: Namhyung Kim <namhyung@kernel.org>
To: Tom Zanussi <tom.zanussi@linux.intel.com>
Cc: rostedt@goodmis.org, tglx@linutronix.de, mhiramat@kernel.org,
vedang.patel@intel.com, linux-kernel@vger.kernel.org,
linux-rt-users@vger.kernel.org, kernel-team@lge.com
Subject: Re: [PATCH 22/32] tracing: Add support for 'synthetic' events
Date: Sun, 23 Jul 2017 21:00:22 +0900 [thread overview]
Message-ID: <20170723120022.GA3902@danjae.aot.lge.com> (raw)
In-Reply-To: <17e9dcfcdd927e42d3d70cb41f7189b0b3682c20.1498510759.git.tom.zanussi@linux.intel.com>
Hi Tom,
On Mon, Jun 26, 2017 at 05:49:23PM -0500, Tom Zanussi wrote:
> Synthetic events are user-defined events generated from hist trigger
> variables saved from one or more other events.
>
> To define a synthetic event, the user writes a simple specification
> consisting of the name of the new event along with one or more
> variables and their type(s), to the tracing/synthetic_events file.
>
> For instance, the following creates a new event named 'wakeup_latency'
> with 3 fields: lat, pid, and prio:
>
> # echo 'wakeup_latency u64 lat; pid_t pid; int prio' >> \
> /sys/kernel/debug/tracing/synthetic_events
>
> Reading the tracing/synthetic_events file lists all the
> currently-defined synthetic events, in this case the event we defined
> above:
>
> # cat /sys/kernel/debug/tracing/synthetic_events
> wakeup_latency u64 lat; pid_t pid; int prio
>
> At this point, the synthetic event is ready to use, and a histogram
> can be defined using it:
>
> # echo 'hist:keys=pid,prio,lat.log2:sort=pid,lat' >> \
> /sys/kernel/debug/tracing/events/synthetic/wakeup_latency/trigger
>
> The new event is created under the tracing/events/synthetic/ directory
> and looks and behaves just like any other event:
>
> # ls /sys/kernel/debug/tracing/events/synthetic/wakeup_latency
> enable filter format hist id trigger
>
> Although a histogram can be defined for it, nothing will happen until
> an action tracing that event via the trace_synth() function occurs.
> The trace_synth() function is very similar to all the other trace_*
> invocations spread throughout the kernel, except in this case the
> trace_ function and its corresponding tracepoint isn't statically
> generated but defined by the user at run-time.
>
> How this can be automatically hooked up via a hist trigger 'action' is
> discussed in a subsequent patch.
>
> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
> ---
> kernel/trace/trace_events_hist.c | 738 +++++++++++++++++++++++++++++++++++++++
> 1 file changed, 738 insertions(+)
>
> diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
> index 338a9d5..e11b3a3 100644
> --- a/kernel/trace/trace_events_hist.c
> +++ b/kernel/trace/trace_events_hist.c
[SNIP]
> @@ -273,6 +294,688 @@ struct action_data {
> unsigned int var_ref_idx;
> };
>
> +static LIST_HEAD(synth_event_list);
> +static DEFINE_MUTEX(synth_event_mutex);
> +
> +struct synth_trace_event {
> + struct trace_entry ent;
> + int n_fields;
> + u64 fields[];
> +};
> +
> +static int synth_event_define_fields(struct trace_event_call *call)
> +{
> + struct synth_trace_event trace;
> + int offset = offsetof(typeof(trace), fields);
> + struct synth_event *event = call->data;
> + unsigned int i, size;
> + char *name, *type;
> + bool is_signed;
> + int ret = 0;
> +
> + for (i = 0; i < event->n_fields; i++) {
> + size = event->fields[i]->size;
> + is_signed = event->fields[i]->is_signed;
> + type = event->fields[i]->type;
> + name = event->fields[i]->name;
> + ret = trace_define_field(call, type, name, offset, size,
> + is_signed, FILTER_OTHER);
> + offset += sizeof(u64);
So you assume size of a field is up to 64-bit, right? Does it
guaranteed somewhere?
> + }
> +
> + return ret;
> +}
> +
> +static enum print_line_t print_synth_event(struct trace_iterator *iter,
> + int flags,
> + struct trace_event *event)
> +{
> + struct trace_array *tr = iter->tr;
> + struct trace_seq *s = &iter->seq;
> + struct synth_trace_event *entry;
> + struct synth_event *se;
> + unsigned int i;
> +
> + entry = (struct synth_trace_event *)iter->ent;
> + se = container_of(event, struct synth_event, call.event);
> +
> + trace_seq_printf(s, "%s: ", se->name);
> +
> + for (i = 0; i < entry->n_fields; i++) {
> + if (trace_seq_has_overflowed(s))
> + goto end;
> +
> + /* parameter types */
> + if (tr->trace_flags & TRACE_ITER_VERBOSE)
> + trace_seq_printf(s, "%s ", "u64");
Why did you hardcode 'u64' here?
> +
> + /* parameter values */
> + trace_seq_printf(s, "%s=%llu%s", se->fields[i]->name,
> + entry->fields[i],
> + i == entry->n_fields - 1 ? "" : ", ");
> + }
> +end:
> + trace_seq_putc(s, '\n');
> +
> + return trace_handle_return(s);
> +}
> +
> +static struct trace_event_functions synth_event_funcs = {
> + .trace = print_synth_event
> +};
> +
[SNIP]
> +static unsigned int synth_field_size(char *type)
> +{
> + unsigned int size = 0;
> +
> + if (strcmp(type, "s64") == 0)
> + size = sizeof(s64);
> + else if (strcmp(type, "u64") == 0)
> + size = sizeof(u64);
> + else if (strcmp(type, "s32") == 0)
> + size = sizeof(s32);
> + else if (strcmp(type, "u32") == 0)
> + size = sizeof(u32);
> + else if (strcmp(type, "s16") == 0)
> + size = sizeof(s16);
> + else if (strcmp(type, "u16") == 0)
> + size = sizeof(u16);
> + else if (strcmp(type, "s8") == 0)
> + size = sizeof(s8);
> + else if (strcmp(type, "u8") == 0)
> + size = sizeof(u8);
> + else if (strcmp(type, "char") == 0)
> + size = sizeof(char);
> + else if (strcmp(type, "unsigned char") == 0)
> + size = sizeof(unsigned char);
> + else if (strcmp(type, "int") == 0)
> + size = sizeof(int);
> + else if (strcmp(type, "unsigned int") == 0)
> + size = sizeof(unsigned int);
> + else if (strcmp(type, "long") == 0)
> + size = sizeof(long);
> + else if (strcmp(type, "unsigned long") == 0)
> + size = sizeof(unsigned long);
> + else if (strcmp(type, "pid_t") == 0)
> + size = sizeof(pid_t);
> + else if (strstr(type, "[") == 0)
> + size = sizeof(u64);
Ah ok, so you don't accept arrays and all supported fields are less
than or equal to 8 bytes.
> +
> + return size;
> +}
> +
[SNIP]
> +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(atomic_read(&tp->key.enabled) > 0)) {
> + struct tracepoint_func *it_func_ptr;
> + void *it_func;
> + void *__data;
> +
> + if (!(cpu_online(raw_smp_processor_id())))
> + return;
> +
> + it_func_ptr = rcu_dereference_sched((tp)->funcs);
> + if (it_func_ptr) {
> + do {
> + it_func = (it_func_ptr)->func;
> + __data = (it_func_ptr)->data;
> + ((void(*)(void *__data, u64 *var_ref_vals, unsigned int var_ref_idx))(it_func))(__data, var_ref_vals, var_ref_idx);
Ouch, why not defining a function pointer?
Thanks,
Namhyung
> + } while ((++it_func_ptr)->func);
> + }
> + }
> +}
next prev parent reply other threads:[~2017-07-23 12:01 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-26 22:49 [PATCH 00/32] tracing: Inter-event (e.g. latency) support Tom Zanussi
2017-06-26 22:49 ` [PATCH 01/32] tracing: Add hist_field_name() accessor Tom Zanussi
2017-07-13 6:49 ` Piotr Gregor
2017-07-13 14:41 ` Tom Zanussi
2017-07-14 2:19 ` Namhyung Kim
2017-06-26 22:49 ` [PATCH 02/32] tracing: Reimplement log2 Tom Zanussi
2017-07-14 2:33 ` Namhyung Kim
2017-07-14 16:13 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 03/32] ring-buffer: Add interface for setting absolute time stamps Tom Zanussi
2017-07-14 5:25 ` Namhyung Kim
2017-07-14 16:14 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 04/32] ring-buffer: Redefine the unimplemented RINGBUF_TIME_TIME_STAMP Tom Zanussi
2017-07-02 8:51 ` Joel Fernandes (Google)
2017-06-26 22:49 ` [PATCH 05/32] tracing: Give event triggers access to ring_buffer_event Tom Zanussi
2017-06-26 22:49 ` [PATCH 06/32] tracing: Add ring buffer event param to hist field functions Tom Zanussi
2017-06-26 22:49 ` [PATCH 07/32] tracing: Increase tracing map KEYS_MAX size Tom Zanussi
2017-06-26 22:49 ` [PATCH 08/32] tracing: Break out hist trigger assignment parsing Tom Zanussi
2017-06-26 22:49 ` [PATCH 09/32] tracing: Make traceprobe parsing code reusable Tom Zanussi
2017-06-26 22:49 ` [PATCH 10/32] tracing: Add NO_DISCARD event file flag Tom Zanussi
2017-06-26 22:49 ` [PATCH 11/32] tracing: Add post-trigger flag to hist trigger command Tom Zanussi
2017-06-26 22:49 ` [PATCH 12/32] tracing: Add hist trigger timestamp support Tom Zanussi
2017-07-17 6:00 ` Namhyung Kim
2017-07-17 16:57 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 13/32] tracing: Add per-element variable support to tracing_map Tom Zanussi
2017-06-26 22:49 ` [PATCH 14/32] tracing: Add hist_data member to hist_field Tom Zanussi
2017-06-26 22:49 ` [PATCH 15/32] tracing: Add usecs modifier for hist trigger timestamps Tom Zanussi
2017-06-26 22:49 ` [PATCH 16/32] tracing: Add variable support to hist triggers Tom Zanussi
2017-07-19 1:07 ` Namhyung Kim
2017-07-19 15:40 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 17/32] tracing: Account for variables in named trigger compatibility Tom Zanussi
2017-06-26 22:49 ` [PATCH 18/32] tracing: Add simple expression support to hist triggers Tom Zanussi
2017-07-21 2:02 ` Namhyung Kim
2017-07-21 16:29 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 19/32] tracing: Add variable reference handling " Tom Zanussi
2017-07-21 3:31 ` Namhyung Kim
2017-07-21 16:41 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 20/32] tracing: Add support for dynamic tracepoints Tom Zanussi
2017-06-26 22:49 ` [PATCH 21/32] tracing: Add hist trigger action hook Tom Zanussi
2017-06-26 22:49 ` [PATCH 22/32] tracing: Add support for 'synthetic' events Tom Zanussi
2017-07-23 12:00 ` Namhyung Kim [this message]
2017-07-24 16:11 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 23/32] tracing: Add 'onmatch' hist trigger action support Tom Zanussi
2017-07-23 15:12 ` Namhyung Kim
2017-07-24 16:17 ` Tom Zanussi
2017-07-26 2:40 ` Namhyung Kim
2017-07-26 16:38 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 24/32] tracing: Add 'onmax' " Tom Zanussi
2017-07-26 3:04 ` Namhyung Kim
2017-07-26 16:45 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 25/32] tracing: Allow whitespace to surround hist trigger filter Tom Zanussi
2017-06-26 22:49 ` [PATCH 26/32] tracing: Make duplicate count from tracing_map available Tom Zanussi
2017-06-26 22:49 ` [PATCH 27/32] tracing: Add cpu field for hist triggers Tom Zanussi
2017-06-26 22:49 ` [PATCH 28/32] tracing: Add hist trigger support for variable reference aliases Tom Zanussi
2017-06-26 22:49 ` [PATCH 29/32] tracing: Add 'last error' error facility for hist triggers Tom Zanussi
2017-07-26 4:39 ` Namhyung Kim
2017-07-26 16:47 ` Tom Zanussi
2017-06-26 22:49 ` [PATCH 30/32] tracing: Add inter-event hist trigger Documentation Tom Zanussi
2017-06-26 22:49 ` [PATCH 31/32] tracing: Make tracing_set_clock() non-static Tom Zanussi
2017-06-26 22:49 ` [PATCH 32/32] tracing: Add a clock attribute for hist triggers Tom Zanussi
2017-06-27 14:58 ` [PATCH 00/32] tracing: Inter-event (e.g. latency) support Steven Rostedt
2017-06-28 14:21 ` Masami Hiramatsu
2017-06-28 19:09 ` Tom Zanussi
2017-07-01 7:01 ` Joel Fernandes (Google)
2017-07-12 19:17 ` Tom Zanussi
2017-07-04 16:12 ` Sebastian Andrzej Siewior
2017-07-12 19:20 ` Tom Zanussi
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=20170723120022.GA3902@danjae.aot.lge.com \
--to=namhyung@kernel.org \
--cc=kernel-team@lge.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=tom.zanussi@linux.intel.com \
--cc=vedang.patel@intel.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).