All of lore.kernel.org
 help / color / mirror / Atom feed
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, bigeasy@linutronix.de,
	joel.opensrc@gmail.com, joelaf@google.com,
	mathieu.desnoyers@efficios.com, baohong.liu@intel.com,
	rajvi.jingar@intel.com, linux-kernel@vger.kernel.org,
	linux-rt-users@vger.kernel.org, kernel-team@lge.com
Subject: Re: [PATCH v3 22/33] tracing: Add support for 'field variables'
Date: Thu, 12 Oct 2017 11:52:11 +0900	[thread overview]
Message-ID: <20171012025211.GC9177@sejong> (raw)
In-Reply-To: <4f507b4fc0584f08b9a7d6abf1b8d718f8306c5c.1506105131.git.tom.zanussi@linux.intel.com>

On Fri, Sep 22, 2017 at 03:00:02PM -0500, Tom Zanussi wrote:
> Users should be able to directly specify event fields in hist trigger
> 'actions' rather than being forced to explicitly create a variable for
> that purpose.
> 
> Add support allowing fields to be used directly in actions, which
> essentially does just that - creates 'invisible' variables for each
> bare field specified in an action.  If a bare field refers to a field
> on another (matching) event, it even creates a special histogram for
> the purpose (since variables can't be defined on an existing histogram
> after histogram creation).
> 
> Here's a simple example that demonstrates both.  Basically the
> onmatch() action creates a list of variables corresponding to the
> parameters of the synthetic event to be generated, and then uses those
> values to generate the event.  So for the wakeup_latency synthetic
> event 'call' below the first param, $wakeup_lat, is a variable defined
> explicitly on sched_switch, where 'next_pid' is just a normal field on
> sched_switch, and prio is a normal field on sched_waking.
> 
> Since the mechanism works on variables, those two normal fields just
> have 'invisible' variables created internally for them.  In the case of
> 'prio', which is on another event, we actually need to create an
> additional hist trigger and define the invisible event on that, since

s/event/variable/ ?


> once a hist trigger is defined, variables can't be added to it later.
> 
>   echo 'wakeup_latency u64 lat; pid_t pid; int prio' >>
>        /sys/kernel/debug/tracing/synthetic_events
> 
>   echo 'hist:keys=pid:ts0=$common_timestamp.usecs >>
>        /sys/kernel/debug/tracing/events/sched/sched_waking/trigger
> 
> echo 'hist:keys=next_pid:wakeup_lat=$common_timestamp.usecs-$ts0:
>       onmatch(sched.sched_waking).wakeup_latency($wakeup_lat,next_pid,prio)
>             >> /sys/kernel/debug/tracing/events/sched/sched_switch/trigger
> 
> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
> ---

[SNIP]

> +static bool compatible_keys(struct hist_trigger_data *target_hist_data,
> +			    struct hist_trigger_data *hist_data,
> +			    unsigned int n_keys)
> +{
> +	struct hist_field *target_hist_field, *hist_field;
> +	unsigned int n, i, j;
> +
> +	if (hist_data->n_fields - hist_data->n_vals != n_keys)
> +		return false;
> +
> +	i = hist_data->n_vals;
> +	j = target_hist_data->n_vals;
> +
> +	for (n = 0; n < n_keys; n++) {
> +		hist_field = hist_data->fields[i + n];
> +		target_hist_field = hist_data->fields[j + n];

s/hist_data/target_hist_data/

> +
> +		if (strcmp(hist_field->type, target_hist_field->type) != 0)
> +			return false;
> +		if (hist_field->size != target_hist_field->size)
> +			return false;
> +		if (hist_field->is_signed != target_hist_field->is_signed)
> +			return false;
> +	}
> +
> +	return true;
> +}

[SNIP]

> +static struct hist_field *
> +create_field_var_hist(struct hist_trigger_data *target_hist_data,
> +		      char *system, char *event_name, char *field_name)
> +{
> +	struct trace_array *tr = target_hist_data->event_file->tr;
> +	struct hist_field *event_var = ERR_PTR(-EINVAL);
> +	struct hist_trigger_data *hist_data;
> +	unsigned int i, n, first = true;
> +	struct field_var_hist *var_hist;
> +	struct trace_event_file *file;
> +	struct hist_field *key_field;
> +	char *saved_filter;
> +	char *cmd;
> +	int ret;
> +
> +	if (target_hist_data->n_field_var_hists >= SYNTH_FIELDS_MAX)
> +		return ERR_PTR(-EINVAL);
> +
> +	file = event_file(tr, system, event_name);
> +
> +	if (IS_ERR(file)) {
> +		ret = PTR_ERR(file);
> +		return ERR_PTR(ret);
> +	}
> +
> +	hist_data = find_compatible_hist(target_hist_data, file);
> +	if (!hist_data)
> +		return ERR_PTR(-EINVAL);
> +
> +	var_hist = kzalloc(sizeof(*var_hist), GFP_KERNEL);
> +	if (!var_hist)
> +		return ERR_PTR(-ENOMEM);
> +
> +	cmd = kzalloc(MAX_FILTER_STR_VAL, GFP_KERNEL);
> +	if (!cmd) {
> +		kfree(var_hist);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	strcat(cmd, "keys=");
> +
> +	for_each_hist_key_field(i, hist_data) {
> +		key_field = hist_data->fields[i];
> +		if (!first)
> +			strcat(cmd, ",");
> +		strcat(cmd, key_field->field->name);
> +		first = false;
> +	}
> +
> +	strcat(cmd, ":synthetic_");
> +	strcat(cmd, field_name);
> +	strcat(cmd, "=");
> +	strcat(cmd, field_name);
> +
> +	saved_filter = find_trigger_filter(hist_data, file);
> +	if (saved_filter) {
> +		strcat(cmd, " if ");
> +		strcat(cmd, saved_filter);
> +	}
> +
> +	var_hist->cmd = kstrdup(cmd, GFP_KERNEL);
> +	if (!var_hist->cmd) {
> +		kfree(cmd);
> +		kfree(var_hist);
> +		return ERR_PTR(-ENOMEM);
> +	}
> +
> +	var_hist->hist_data = hist_data;

Hmm.. so it's a compatible hist data, not the newly created one,
right?  Might confuse someone later.. ;-)


> +
> +	ret = event_hist_trigger_func(&trigger_hist_cmd, file,
> +				      "", "hist", cmd);
> +	if (ret) {
> +		kfree(cmd);
> +		kfree(var_hist->cmd);
> +		kfree(var_hist);
> +		return ERR_PTR(ret);
> +	}

What if two different event want to create synthetic variables for a
same field?  I suspect one failed because the variable names are same
but it could continue since the variable is there anyway.  Probably it
would be better to use a different error code for the case..

Thanks,
Namhyung


> +
> +	strcpy(cmd, "synthetic_");
> +	strcat(cmd, field_name);
> +
> +	event_var = find_event_var(tr, system, event_name, cmd);
> +	if (!event_var) {
> +		kfree(cmd);
> +		kfree(var_hist->cmd);
> +		kfree(var_hist);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	n = target_hist_data->n_field_var_hists;
> +	target_hist_data->field_var_hists[n] = var_hist;
> +	target_hist_data->n_field_var_hists++;
> +
> +	return event_var;
> +}

  reply	other threads:[~2017-10-12  2:52 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-22 19:59 [PATCH v3 00/33] tracing: Inter-event (e.g. latency) support Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 01/33] tracing: Add support to detect and avoid duplicates Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 02/33] tracing: Remove code which merges duplicates Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 03/33] ring-buffer: Add interface for setting absolute time stamps Tom Zanussi
2017-10-04 17:14   ` Steven Rostedt
2017-10-05 11:34     ` Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 04/33] ring-buffer: Redefine the unimplemented RINGBUF_TIME_TIME_STAMP Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 05/33] tracing: Give event triggers access to ring_buffer_event Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 06/33] tracing: Add ring buffer event param to hist field functions Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 07/33] tracing: Break out hist trigger assignment parsing Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 08/33] tracing: Add hist trigger timestamp support Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 09/33] tracing: Add per-element variable support to tracing_map Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 10/33] tracing: Add hist_data member to hist_field Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 11/33] tracing: Add usecs modifier for hist trigger timestamps Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 12/33] tracing: Add variable support to hist triggers Tom Zanussi
2017-10-09  3:27   ` Namhyung Kim
2017-10-11 13:33     ` Tom Zanussi
2017-10-11 23:23       ` Namhyung Kim
2017-10-12 15:51         ` Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 13/33] tracing: Account for variables in named trigger compatibility Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 14/33] tracing: Move get_hist_field_flags() Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 15/33] tracing: Add simple expression support to hist triggers Tom Zanussi
2017-10-09 12:54   ` Namhyung Kim
2017-10-11 14:08     ` Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 16/33] tracing: Generalize per-element hist trigger data Tom Zanussi
2017-10-04 17:34   ` Steven Rostedt
2017-10-04 19:22     ` Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 17/33] tracing: Pass tracing_map_elt to hist_field accessor functions Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 18/33] tracing: Add hist_field 'type' field Tom Zanussi
2017-09-22 19:59 ` [PATCH v3 19/33] tracing: Add variable reference handling to hist triggers Tom Zanussi
2017-10-09 12:46   ` Namhyung Kim
2017-10-11 14:07     ` Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 20/33] tracing: Add hist trigger action hook Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 21/33] tracing: Add support for 'synthetic' events Tom Zanussi
2017-10-04 18:08   ` Steven Rostedt
2017-10-04 19:50     ` Tom Zanussi
2017-10-12  0:53       ` Namhyung Kim
2017-09-22 20:00 ` [PATCH v3 22/33] tracing: Add support for 'field variables' Tom Zanussi
2017-10-12  2:52   ` Namhyung Kim [this message]
2017-10-12 21:35     ` Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 23/33] tracing: Add 'onmatch' hist trigger action support Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 24/33] tracing: Add 'onmax' " Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 25/33] tracing: Allow whitespace to surround hist trigger filter Tom Zanussi
2017-10-04 18:11   ` Steven Rostedt
2017-10-04 19:05     ` Tom Zanussi
2017-10-04 19:28       ` Steven Rostedt
2017-10-18  3:00       ` Namhyung Kim
2017-10-18 14:11         ` Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 26/33] tracing: Add cpu field for hist triggers Tom Zanussi
2017-10-04 18:12   ` Steven Rostedt
2017-10-04 19:21     ` Tom Zanussi
2017-10-04 19:30       ` Steven Rostedt
2017-09-22 20:00 ` [PATCH v3 27/33] tracing: Add hist trigger support for variable reference aliases Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 28/33] tracing: Add 'last error' error facility for hist triggers Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 29/33] tracing: Add inter-event hist trigger Documentation Tom Zanussi
2017-10-18  1:36   ` Steven Rostedt
2017-10-18 14:07     ` Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 30/33] tracing: Make tracing_set_clock() non-static Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 31/33] tracing: Add a clock attribute for hist triggers Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 32/33] tracing: Increase trace_recursive_lock() limit for synthetic events Tom Zanussi
2017-09-22 20:00 ` [PATCH v3 33/33] tracing: Add inter-event blurb to HIST_TRIGGERS config option 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=20171012025211.GC9177@sejong \
    --to=namhyung@kernel.org \
    --cc=baohong.liu@intel.com \
    --cc=bigeasy@linutronix.de \
    --cc=joel.opensrc@gmail.com \
    --cc=joelaf@google.com \
    --cc=kernel-team@lge.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-users@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mhiramat@kernel.org \
    --cc=rajvi.jingar@intel.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.