Skip to content

Commit de40f03

Browse files
tzanussirostedt
authored andcommitted
tracing: Remove open-coding of hist trigger var_ref management
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. Link: http://lkml.kernel.org/r/05ddae93ff514e66fc03897d6665231892939913.1545161087.git.tom.zanussi@linux.intel.com Acked-by: Namhyung Kim <namhyung@kernel.org> Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org> Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent e4f6d24 commit de40f03

File tree

1 file changed

+75
-18
lines changed

1 file changed

+75
-18
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,17 @@ static u64 hist_field_cpu(struct hist_field *hist_field,
12921292
return cpu;
12931293
}
12941294

1295+
/**
1296+
* check_field_for_var_ref - Check if a VAR_REF field references a variable
1297+
* @hist_field: The VAR_REF field to check
1298+
* @var_data: The hist trigger that owns the variable
1299+
* @var_idx: The trigger variable identifier
1300+
*
1301+
* Check the given VAR_REF field to see whether or not it references
1302+
* the given variable associated with the given trigger.
1303+
*
1304+
* Return: The VAR_REF field if it does reference the variable, NULL if not
1305+
*/
12951306
static struct hist_field *
12961307
check_field_for_var_ref(struct hist_field *hist_field,
12971308
struct hist_trigger_data *var_data,
@@ -1306,6 +1317,18 @@ check_field_for_var_ref(struct hist_field *hist_field,
13061317
return NULL;
13071318
}
13081319

1320+
/**
1321+
* find_var_ref - Check if a trigger has a reference to a trigger variable
1322+
* @hist_data: The hist trigger that might have a reference to the variable
1323+
* @var_data: The hist trigger that owns the variable
1324+
* @var_idx: The trigger variable identifier
1325+
*
1326+
* Check the list of var_refs[] on the first hist trigger to see
1327+
* whether any of them are references to the variable on the second
1328+
* trigger.
1329+
*
1330+
* Return: The VAR_REF field referencing the variable if so, NULL if not
1331+
*/
13091332
static struct hist_field *find_var_ref(struct hist_trigger_data *hist_data,
13101333
struct hist_trigger_data *var_data,
13111334
unsigned int var_idx)
@@ -1322,6 +1345,20 @@ static struct hist_field *find_var_ref(struct hist_trigger_data *hist_data,
13221345
return NULL;
13231346
}
13241347

1348+
/**
1349+
* find_any_var_ref - Check if there is a reference to a given trigger variable
1350+
* @hist_data: The hist trigger
1351+
* @var_idx: The trigger variable identifier
1352+
*
1353+
* Check to see whether the given variable is currently referenced by
1354+
* any other trigger.
1355+
*
1356+
* The trigger the variable is defined on is explicitly excluded - the
1357+
* assumption being that a self-reference doesn't prevent a trigger
1358+
* from being removed.
1359+
*
1360+
* Return: The VAR_REF field referencing the variable if so, NULL if not
1361+
*/
13251362
static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
13261363
unsigned int var_idx)
13271364
{
@@ -1340,6 +1377,19 @@ static struct hist_field *find_any_var_ref(struct hist_trigger_data *hist_data,
13401377
return found;
13411378
}
13421379

1380+
/**
1381+
* check_var_refs - Check if there is a reference to any of trigger's variables
1382+
* @hist_data: The hist trigger
1383+
*
1384+
* A trigger can define one or more variables. If any one of them is
1385+
* currently referenced by any other trigger, this function will
1386+
* determine that.
1387+
1388+
* Typically used to determine whether or not a trigger can be removed
1389+
* - if there are any references to a trigger's variables, it cannot.
1390+
*
1391+
* Return: True if there is a reference to any of trigger's variables
1392+
*/
13431393
static bool check_var_refs(struct hist_trigger_data *hist_data)
13441394
{
13451395
struct hist_field *field;
@@ -2343,7 +2393,23 @@ static int init_var_ref(struct hist_field *ref_field,
23432393
goto out;
23442394
}
23452395

2346-
static struct hist_field *create_var_ref(struct hist_field *var_field,
2396+
/**
2397+
* create_var_ref - Create a variable reference and attach it to trigger
2398+
* @hist_data: The trigger that will be referencing the variable
2399+
* @var_field: The VAR field to create a reference to
2400+
* @system: The optional system string
2401+
* @event_name: The optional event_name string
2402+
*
2403+
* Given a variable hist_field, create a VAR_REF hist_field that
2404+
* represents a reference to it.
2405+
*
2406+
* This function also adds the reference to the trigger that
2407+
* now references the variable.
2408+
*
2409+
* Return: The VAR_REF field if successful, NULL if not
2410+
*/
2411+
static struct hist_field *create_var_ref(struct hist_trigger_data *hist_data,
2412+
struct hist_field *var_field,
23472413
char *system, char *event_name)
23482414
{
23492415
unsigned long flags = HIST_FIELD_FL_VAR_REF;
@@ -2355,6 +2421,9 @@ static struct hist_field *create_var_ref(struct hist_field *var_field,
23552421
destroy_hist_field(ref_field, 0);
23562422
return NULL;
23572423
}
2424+
2425+
hist_data->var_refs[hist_data->n_var_refs] = ref_field;
2426+
ref_field->var_ref_idx = hist_data->n_var_refs++;
23582427
}
23592428

23602429
return ref_field;
@@ -2428,7 +2497,8 @@ static struct hist_field *parse_var_ref(struct hist_trigger_data *hist_data,
24282497

24292498
var_field = find_event_var(hist_data, system, event_name, var_name);
24302499
if (var_field)
2431-
ref_field = create_var_ref(var_field, system, event_name);
2500+
ref_field = create_var_ref(hist_data, var_field,
2501+
system, event_name);
24322502

24332503
if (!ref_field)
24342504
hist_err_event("Couldn't find variable: $",
@@ -2546,8 +2616,6 @@ static struct hist_field *parse_atom(struct hist_trigger_data *hist_data,
25462616
if (!s) {
25472617
hist_field = parse_var_ref(hist_data, ref_system, ref_event, ref_var);
25482618
if (hist_field) {
2549-
hist_data->var_refs[hist_data->n_var_refs] = hist_field;
2550-
hist_field->var_ref_idx = hist_data->n_var_refs++;
25512619
if (var_name) {
25522620
hist_field = create_alias(hist_data, hist_field, var_name);
25532621
if (!hist_field) {
@@ -3321,7 +3389,6 @@ static int onmax_create(struct hist_trigger_data *hist_data,
33213389
unsigned int var_ref_idx = hist_data->n_var_refs;
33223390
struct field_var *field_var;
33233391
char *onmax_var_str, *param;
3324-
unsigned long flags;
33253392
unsigned int i;
33263393
int ret = 0;
33273394

@@ -3338,18 +3405,10 @@ static int onmax_create(struct hist_trigger_data *hist_data,
33383405
return -EINVAL;
33393406
}
33403407

3341-
flags = HIST_FIELD_FL_VAR_REF;
3342-
ref_field = create_hist_field(hist_data, NULL, flags, NULL);
3408+
ref_field = create_var_ref(hist_data, var_field, NULL, NULL);
33433409
if (!ref_field)
33443410
return -ENOMEM;
33453411

3346-
if (init_var_ref(ref_field, var_field, NULL, NULL)) {
3347-
destroy_hist_field(ref_field, 0);
3348-
ret = -ENOMEM;
3349-
goto out;
3350-
}
3351-
hist_data->var_refs[hist_data->n_var_refs] = ref_field;
3352-
ref_field->var_ref_idx = hist_data->n_var_refs++;
33533412
data->onmax.var = ref_field;
33543413

33553414
data->fn = onmax_save;
@@ -3538,9 +3597,6 @@ static void save_synth_var_ref(struct hist_trigger_data *hist_data,
35383597
struct hist_field *var_ref)
35393598
{
35403599
hist_data->synth_var_refs[hist_data->n_synth_var_refs++] = var_ref;
3541-
3542-
hist_data->var_refs[hist_data->n_var_refs] = var_ref;
3543-
var_ref->var_ref_idx = hist_data->n_var_refs++;
35443600
}
35453601

35463602
static int check_synth_field(struct synth_event *event,
@@ -3694,7 +3750,8 @@ static int onmatch_create(struct hist_trigger_data *hist_data,
36943750
}
36953751

36963752
if (check_synth_field(event, hist_field, field_pos) == 0) {
3697-
var_ref = create_var_ref(hist_field, system, event_name);
3753+
var_ref = create_var_ref(hist_data, hist_field,
3754+
system, event_name);
36983755
if (!var_ref) {
36993756
kfree(p);
37003757
ret = -ENOMEM;

0 commit comments

Comments
 (0)