Received: by 10.223.164.202 with SMTP id h10csp94673wrb; Tue, 14 Nov 2017 11:43:13 -0800 (PST) X-Google-Smtp-Source: AGs4zMZ2gbzZFoPDvcwHIaiL1tblltvAuHuEoi2gkw4W7bNb8jzTdlA137sTLVKHtgw/VJQSkn7s X-Received: by 10.99.114.82 with SMTP id c18mr13244734pgn.221.1510688593150; Tue, 14 Nov 2017 11:43:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510688593; cv=none; d=google.com; s=arc-20160816; b=n2ZoNbQUm/tO648orS8C+TqInXSDeY0UirYLrxbBlPbtF3eCbg3h7odF6eawLxob9T UECyHbltZoDvjeRvHcbpMGyGa+OmmbC282oRhAQzCfI2an3yXowk/fFJi8HXIqFSdOfs ozg1ldkj78Sxz6V0J8NSofC7KxcZqKWrbLnqi1Fo1VawPHQGFrd5/XIQjA9+P9RiCWTx OpaIyYAepw45tbqaPLwrzgDrjgud7qQsCwh7vHkKgoFRMCMvjxfHB00Ods9gFt2E8vG9 zG11CjtLhOp8P0O3wVKaPvWzB5EKQAFzhp1xjabZ6bHaK0j0LjXXkLw4/YWaS54AYh7u YxzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=ASdMvb/UaAJB2l5Pifw5w8XI4GBvrw8hUjZyODUU5GY=; b=FuvRp7+6kS6hru1NEwvp06hDzkobfrxuJgi8wjLTZkntXTczsyZxMMmz/1jJNHbHHh 3U/W8dvz5ntou1FcKxMJH7HJzYhzkq4VPCbBuvSxIxrtihiUQhreNsEawjt3kKzzvFzS AOxfK3wVCBNXmQn9OvJULiuHXoxWGjugmEd9aWOAf7QnD/fWBivYOTxHeEpovdVCkanH azlI16r9cMWCeUm8FPUkayskLPQYn6iZfSfitY538QS+yqD3jjJNAhBjtGerx1ichKFm e52QzHa5HROI9sS2VWjb41aIqKdTtANrVTWu2v5MzwRmZQbB7C46ZDKlwb0tGY82k6EO P3Jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h82si10525938pfa.196.2017.11.14.11.43.00; Tue, 14 Nov 2017 11:43:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756394AbdKNTei (ORCPT + 88 others); Tue, 14 Nov 2017 14:34:38 -0500 Received: from mga11.intel.com ([192.55.52.93]:60487 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755030AbdKNTe3 (ORCPT ); Tue, 14 Nov 2017 14:34:29 -0500 Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Nov 2017 11:34:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,396,1505804400"; d="scan'208";a="173522171" Received: from smiddela-mobl6.amr.corp.intel.com (HELO [10.252.130.219]) ([10.252.130.219]) by orsmga005.jf.intel.com with ESMTP; 14 Nov 2017 11:34:26 -0800 Message-ID: <1510688065.25348.11.camel@tzanussi-mobl.amr.corp.intel.com> Subject: Re: [PATCH v5 24/37] tracing: Add support for 'synthetic' events From: Tom Zanussi To: Namhyung Kim Cc: rostedt@goodmis.org, tglx@linutronix.de, mhiramat@kernel.org, vedang.patel@intel.com, bigeasy@linutronix.de, joel.opensrc@gmail.com, joelaf@google.com, mathieu.desnoyers@efficios.com, baohong.liu@intel.com, rajvi.jingar@intel.com, julia@ni.com, linux-kernel@vger.kernel.org, linux-rt-users@vger.kernel.org, kernel-team@lge.com Date: Tue, 14 Nov 2017 13:34:25 -0600 In-Reply-To: <20171114100647.GA20669@sejong> References: <20171114100647.GA20669@sejong> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Namhyung, On Tue, 2017-11-14 at 19:06 +0900, Namhyung Kim wrote: > On Thu, Nov 09, 2017 at 02:33:55PM -0600, 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 > > --- > > kernel/trace/trace_events_hist.c | 908 ++++++++++++++++++++++++++++++++++++++- > > 1 file changed, 906 insertions(+), 2 deletions(-) > > > > diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c > > index 3504aa8..510b10d 100644 > > --- a/kernel/trace/trace_events_hist.c > > +++ b/kernel/trace/trace_events_hist.c > > @@ -20,10 +20,16 @@ > > #include > > #include > > #include > > +#include > > > > #include "tracing_map.h" > > #include "trace.h" > > > > +#define SYNTH_SYSTEM "synthetic" > > +#define SYNTH_FIELDS_MAX 16 > > + > > +#define STR_VAR_LEN_MAX 32 /* must be multiple of sizeof(u64) */ > > + > > struct hist_field; > > > > typedef u64 (*hist_field_fn_t) (struct hist_field *field, > > @@ -270,6 +276,26 @@ struct hist_trigger_data { > > unsigned int n_actions; > > }; > > > > +struct synth_field { > > + char *type; > > + char *name; > > + size_t size; > > + bool is_signed; > > + bool is_string; > > +}; > > + > > +struct synth_event { > > + struct list_head list; > > + int ref; > > + char *name; > > + struct synth_field **fields; > > + unsigned int n_fields; > > + unsigned int n_u64; > > + struct trace_event_class class; > > + struct trace_event_call call; > > + struct tracepoint *tp; > > +}; > > + > > struct action_data; > > > > typedef void (*action_fn_t) (struct hist_trigger_data *hist_data, > > @@ -282,6 +308,803 @@ 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; > > + 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, n_u64; > > + char *name, *type; > > + bool is_signed; > > + int ret = 0; > > + > > + for (i = 0, n_u64 = 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); > > + if (ret) > > + break; > > + > > + if (event->fields[i]->is_string) { > > + offset += STR_VAR_LEN_MAX; > > + n_u64 += STR_VAR_LEN_MAX / sizeof(u64); > > Did you use fixed size array for strings? > Yes, for a string field, I allocate enough for the maximum string size, regardless of how long it may be. Not the most efficient, but strings are relatively rare, and it simplifies the code overall. > > > + } else { > > + offset += sizeof(u64); > > + n_u64++; > > + } > > + } > > + > > + event->n_u64 = n_u64; > > + > > + return ret; > > +} > > + > > +static bool synth_field_signed(char *type) > > +{ > > + if (strncmp(type, "u", 1) == 0) > > + return false; > > + > > + return true; > > +} > > + > > +static int synth_field_is_string(char *type) > > +{ > > + if (strstr(type, "char[") != NULL) > > + return true; > > + > > + return false; > > +} > > + > > +static int synth_field_string_size(char *type) > > +{ > > + char buf[4], *end, *start; > > + unsigned int len; > > + int size, err; > > + > > + start = strstr(type, "char["); > > + if (start == NULL) > > + return -EINVAL; > > + start += strlen("char["); > > + > > + end = strchr(type, ']'); > > + if (!end || end < start) > > + return -EINVAL; > > + > > + len = end - start; > > + if (len > 3) > > + return -EINVAL; > > + > > + strncpy(buf, start, len); > > + buf[len] = '\0'; > > + > > + err = kstrtouint(buf, 0, &size); > > + if (err) > > + return err; > > + > > + if (size > STR_VAR_LEN_MAX) > > + return -EINVAL; > > + > > + return size; > > +} > > But this seems to use the actual array size for string.. > Yeah, we still track the actual size for the string in the event field, regardless of the 'container' reserved for it. > [SNIP] > > + > > +static notrace void trace_event_raw_event_synth(void *__data, > > + u64 *var_ref_vals, > > + unsigned int var_ref_idx) > > +{ > > + struct trace_event_file *trace_file = __data; > > + struct synth_trace_event *entry; > > + struct trace_event_buffer fbuffer; > > + struct synth_event *event; > > + unsigned int i, n_u64; > > + int fields_size = 0; > > + > > + event = trace_file->event_call->data; > > + > > + if (trace_trigger_soft_disabled(trace_file)) > > + return; > > + > > + fields_size = event->n_u64 * sizeof(u64); > > + > > + entry = trace_event_buffer_reserve(&fbuffer, trace_file, > > + sizeof(*entry) + fields_size); > > + if (!entry) > > + return; > > + > > + for (i = 0, n_u64 = 0; i < event->n_fields; i++) { > > + if (event->fields[i]->is_string) { > > + char *str_val = (char *)(long)var_ref_vals[var_ref_idx + i]; > > + char *str_field = (char *)&entry->fields[n_u64]; > > + > > + strncpy(str_field, str_val, STR_VAR_LEN_MAX); > > + n_u64 += STR_VAR_LEN_MAX / sizeof(u64); > > Here it uses the fixed size again.. > Right, that's as designed - we always reserve the maximum string size. It's not as efficient and will waste some buffer space, but it simplifies things overall by not having to keep track of variable-length strings in events. I could change this or submit a more efficient scheme later, but I'm not sure it's really worth it... Thanks, Tom > Thanks, > Namhyung > > > > + } else { > > + entry->fields[i] = var_ref_vals[var_ref_idx + i]; > > + n_u64++; > > + } > > + } > > + > > + trace_event_buffer_commit(&fbuffer); > > +} From 1584036401432534170@xxx Tue Nov 14 10:20:32 +0000 2017 X-GM-THRID: 1583622470364079689 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread