From: Tom Zanussi <zanussi@kernel.org>
To: rostedt@goodmis.org
Cc: tglx@linutronix.de, mhiramat@kernel.org, namhyung@kernel.org,
vedang.patel@intel.com, bigeasy@linutronix.de,
joel@joelfernandes.org, mathieu.desnoyers@efficios.com,
julia@ni.com, linux-kernel@vger.kernel.org,
linux-rt-users@vger.kernel.org
Subject: [PATCH v8 19/22] tracing: Remove open-coding of hist trigger var_ref management
Date: Mon, 10 Dec 2018 18:01:33 -0600 [thread overview]
Message-ID: <f096c43e26f46d88f41bc187e620272c02d9d8d8.1544483273.git.tom.zanussi@linux.intel.com> (raw)
In-Reply-To: <cover.1544483272.git.tom.zanussi@linux.intel.com>
In-Reply-To: <cover.1544483272.git.tom.zanussi@linux.intel.com>
From: Tom Zanussi <tom.zanussi@linux.intel.com>
Have create_var_ref() manage the hist trigger's var_ref list, rather
than having similar code doing it in multiple places. This cleans up
the code and makes sure var_refs are always accounted properly.
Also, document the var_ref-related functions to make what their
purpose clearer.
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
---
kernel/trace/trace_events_hist.c | 93 ++++++++++++++++++++++++++++++++--------
1 file changed, 75 insertions(+), 18 deletions(-)
diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 268f56bc12de..d07bb2d75e18 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -1416,6 +1416,17 @@ static u64 hist_field_cpu(struct hist_field *hist_field,
return cpu;
}
+/**
+ * check_field_for_var_ref - Check if a VAR_REF field references a variable
+ * @hist_field: The VAR_REF field to check
+ * @var_data: The hist trigger that owns the variable
+ * @var_idx: The trigger variable identifier
+ *
+ * Check the given VAR_REF field to see whether or not it references
+ * the given variable associated with the given trigger.
+ *
+ * Return: The VAR_REF field if it does reference the variable, NULL if not
+ */
static struct hist_field *
check_field_for_var_ref(struct hist_field *hist_field,
struct hist_trigger_data *var_data,
@@ -1432,6 +1443,18 @@ check_field_for_var_ref(struct hist_field *hist_field,
return found;
}
+/**
+ * find_var_ref - Check if a trigger has a reference to a trigger variable
+ * @hist_data: The hist trigger that might have a reference to the variable
+ * @var_data: The hist trigger that owns the variable
+ * @var_idx: The trigger variable identifier
+ *
+ * Check the list of var_refs[] on the first hist trigger to see
+ * whether any of them are references to the variable on the second
+ * trigger.
+ *
+ * Return: The VAR_REF field referencing the variable if so, NULL if not
+ */
static struct hist_field *find_var_ref(struct hist_trigger_data *hist_data,
struct hist_trigger_data *var_data,
unsigned int var_idx)
@@ -1449,6 +1472,20 @@ static struct hist_field *find_var_ref(struct hist_trigger_data *hist_data,
return found;
}
+/**
+ * find_any_var_ref - Check if there is a reference to a given trigger variable
+ * @hist_data: The hist trigger
+ * @var_idx: The trigger variable identifier
+ *
+ * Check to see whether the given variable is currently referenced by
+ * any other trigger.
+ *
+ * The trigger the variable is defined on is explicitly excluded - the
+ * assumption being that a self-reference doesn't prevent a trigger
+ * from being removed.
+ *
+ * Return: The VAR_REF field referencing the variable if so, NULL if not
+ */
static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
unsigned int var_idx)
{
@@ -1467,6 +1504,19 @@ static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
return found;
}
+/**
+ * check_var_refs - Check if there is a reference to any of trigger's variables
+ * @hist_data: The hist trigger
+ *
+ * A trigger can define one or more variables. If any one of them is
+ * currently referenced by any other trigger, this function will
+ * determine that.
+
+ * Typically used to determine whether or not a trigger can be removed
+ * - if there are any references to a trigger's variables, it cannot.
+ *
+ * Return: True if there is a reference to any of trigger's variables
+ */
static bool check_var_refs(struct hist_trigger_data *hist_data)
{
struct hist_field *field;
@@ -2465,7 +2515,23 @@ static int init_var_ref(struct hist_field *ref_field,
goto out;
}
-static struct hist_field *create_var_ref(struct hist_field *var_field,
+/**
+ * create_var_ref - Create a variable reference and attach it to trigger
+ * @hist_data: The trigger that will be referencing the variable
+ * @var_field: The VAR field to create a reference to
+ * @system: The optional system string
+ * @event_name: The optional event_name string
+ *
+ * Given a variable hist_field, create a VAR_REF hist_field that
+ * represents a reference to it.
+ *
+ * This function also adds the reference to the trigger that
+ * now references the variable.
+ *
+ * Return: The VAR_REF field if successful, NULL if not
+ */
+static struct hist_field *create_var_ref(struct hist_trigger_data *hist_data,
+ struct hist_field *var_field,
char *system, char *event_name)
{
unsigned long flags = HIST_FIELD_FL_VAR_REF;
@@ -2479,6 +2545,9 @@ static struct hist_field *create_var_ref(struct hist_field *var_field,
}
}
+ hist_data->var_refs[hist_data->n_var_refs] = ref_field;
+ ref_field->var_ref_idx = hist_data->n_var_refs++;
+
return ref_field;
}
@@ -2550,7 +2619,8 @@ static struct hist_field *parse_var_ref(struct hist_trigger_data *hist_data,
var_field = find_event_var(hist_data, system, event_name, var_name);
if (var_field)
- ref_field = create_var_ref(var_field, system, event_name);
+ ref_field = create_var_ref(hist_data, var_field,
+ system, event_name);
if (!ref_field)
hist_err_event("Couldn't find variable: $",
@@ -2668,8 +2738,6 @@ static struct hist_field *parse_atom(struct hist_trigger_data *hist_data,
if (!s) {
hist_field = parse_var_ref(hist_data, ref_system, ref_event, ref_var);
if (hist_field) {
- hist_data->var_refs[hist_data->n_var_refs] = hist_field;
- hist_field->var_ref_idx = hist_data->n_var_refs++;
if (var_name) {
hist_field = create_alias(hist_data, hist_field, var_name);
if (!hist_field) {
@@ -3650,7 +3718,6 @@ static int track_data_create(struct hist_trigger_data *hist_data,
struct hist_field *var_field, *ref_field, *track_var = NULL;
struct trace_event_file *file = hist_data->event_file;
char *track_data_var_str;
- unsigned long flags;
int ret = 0;
track_data_var_str = data->track_data.var_str;
@@ -3666,18 +3733,10 @@ static int track_data_create(struct hist_trigger_data *hist_data,
return -EINVAL;
}
- flags = HIST_FIELD_FL_VAR_REF;
- ref_field = create_hist_field(hist_data, NULL, flags, NULL);
+ ref_field = create_var_ref(hist_data, var_field, NULL, NULL);
if (!ref_field)
return -ENOMEM;
- if (init_var_ref(ref_field, var_field, NULL, NULL)) {
- destroy_hist_field(ref_field, 0);
- ret = -ENOMEM;
- goto out;
- }
- hist_data->var_refs[hist_data->n_var_refs] = ref_field;
- ref_field->var_ref_idx = hist_data->n_var_refs++;
data->track_data.var_ref = ref_field;
if (data->handler == HANDLER_ONMAX)
@@ -3944,9 +4003,6 @@ static void save_synth_var_ref(struct hist_trigger_data *hist_data,
struct hist_field *var_ref)
{
hist_data->synth_var_refs[hist_data->n_synth_var_refs++] = var_ref;
-
- hist_data->var_refs[hist_data->n_var_refs] = var_ref;
- var_ref->var_ref_idx = hist_data->n_var_refs++;
}
static int check_synth_field(struct synth_event *event,
@@ -4109,7 +4165,8 @@ static int trace_action_create(struct hist_trigger_data *hist_data,
}
if (check_synth_field(event, hist_field, field_pos) == 0) {
- var_ref = create_var_ref(hist_field, system, event_name);
+ var_ref = create_var_ref(hist_data, hist_field,
+ system, event_name);
if (!var_ref) {
kfree(p);
ret = -ENOMEM;
--
2.14.1
next prev parent reply other threads:[~2018-12-11 0:03 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-11 0:01 [PATCH v8 00/22] tracing: Hist trigger snapshot and onchange additions Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 01/22] tracing: Refactor hist trigger action code Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 02/22] tracing: Make hist trigger Documentation better reflect actions/handlers Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 03/22] tracing: Add hist trigger handler.action documentation to README Tom Zanussi
2018-12-14 13:11 ` Masami Hiramatsu
2018-12-14 17:16 ` Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 04/22] tracing: Split up onmatch action data Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 05/22] tracing: Generalize hist trigger onmax and save action Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 06/22] tracing: Add conditional snapshot Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 07/22] tracing: Add hist trigger snapshot() action Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 08/22] tracing: Add hist trigger snapshot() action Documentation Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 09/22] tracing: Add hist trigger snapshot() action test case Tom Zanussi
2018-12-14 16:14 ` Masami Hiramatsu
2018-12-11 0:01 ` [PATCH v8 10/22] tracing: Add hist trigger onchange() handler Tom Zanussi
2018-12-14 16:09 ` Masami Hiramatsu
2018-12-11 0:01 ` [PATCH v8 11/22] tracing: Add hist trigger onchange() handler Documentation Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 12/22] tracing: Add hist trigger onchange() handler test case Tom Zanussi
2018-12-14 16:18 ` Masami Hiramatsu
2018-12-14 17:17 ` Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 13/22] tracing: Add alternative synthetic event trace action syntax Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 14/22] tracing: Add alternative synthetic event trace action test case Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 15/22] tracing: Add hist trigger action 'expected fail' " Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 16/22] tracing: Add SPDX license GPL-2.0 license identifier to inter-event testcases Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 17/22] tracing: Remove unnecessary hist trigger struct fields Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 18/22] tracing: Use var_refs[] for hist trigger reference checking Tom Zanussi
2018-12-11 0:01 ` Tom Zanussi [this message]
2018-12-11 0:01 ` [PATCH v8 20/22] tracing: Use hist trigger's var_ref array to destroy var_refs Tom Zanussi
2018-12-14 16:31 ` Masami Hiramatsu
2018-12-14 17:29 ` Tom Zanussi
2018-12-15 6:50 ` Namhyung Kim
2018-12-15 21:01 ` Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 21/22] tracing: Remove hist trigger synth_var_refs Tom Zanussi
2018-12-11 0:01 ` [PATCH v8 22/22] tracing: Add hist trigger comments for variable-related fields 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=f096c43e26f46d88f41bc187e620272c02d9d8d8.1544483273.git.tom.zanussi@linux.intel.com \
--to=zanussi@kernel.org \
--cc=bigeasy@linutronix.de \
--cc=joel@joelfernandes.org \
--cc=julia@ni.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=namhyung@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--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).