Skip to content

Commit af6a29b

Browse files
tzanussirostedt
authored andcommitted
tracing: Generalize per-element hist trigger data
Up until now, hist triggers only needed per-element support for saving 'comm' data, which was saved directly as a private data pointer. In anticipation of the need to save other data besides 'comm', add a new hist_elt_data struct for the purpose, and switch the current 'comm'-related code over to that. Link: http://lkml.kernel.org/r/4502c338c965ddf5fc19fb1ec4764391e001ed4b.1516069914.git.tom.zanussi@linux.intel.com Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent 100719d commit af6a29b

File tree

1 file changed

+43
-33
lines changed

1 file changed

+43
-33
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ static struct hist_field *find_var(struct hist_trigger_data *hist_data,
289289
return NULL;
290290
}
291291

292+
struct hist_elt_data {
293+
char *comm;
294+
};
295+
292296
static const char *hist_field_name(struct hist_field *field,
293297
unsigned int level)
294298
{
@@ -503,45 +507,61 @@ static inline void save_comm(char *comm, struct task_struct *task)
503507
memcpy(comm, task->comm, TASK_COMM_LEN);
504508
}
505509

506-
static void hist_trigger_elt_comm_free(struct tracing_map_elt *elt)
510+
static void hist_elt_data_free(struct hist_elt_data *elt_data)
511+
{
512+
kfree(elt_data->comm);
513+
kfree(elt_data);
514+
}
515+
516+
static void hist_trigger_elt_data_free(struct tracing_map_elt *elt)
507517
{
508-
kfree((char *)elt->private_data);
518+
struct hist_elt_data *elt_data = elt->private_data;
519+
520+
hist_elt_data_free(elt_data);
509521
}
510522

511-
static int hist_trigger_elt_comm_alloc(struct tracing_map_elt *elt)
523+
static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt)
512524
{
513525
struct hist_trigger_data *hist_data = elt->map->private_data;
526+
unsigned int size = TASK_COMM_LEN;
527+
struct hist_elt_data *elt_data;
514528
struct hist_field *key_field;
515529
unsigned int i;
516530

531+
elt_data = kzalloc(sizeof(*elt_data), GFP_KERNEL);
532+
if (!elt_data)
533+
return -ENOMEM;
534+
517535
for_each_hist_key_field(i, hist_data) {
518536
key_field = hist_data->fields[i];
519537

520538
if (key_field->flags & HIST_FIELD_FL_EXECNAME) {
521-
unsigned int size = TASK_COMM_LEN + 1;
522-
523-
elt->private_data = kzalloc(size, GFP_KERNEL);
524-
if (!elt->private_data)
539+
elt_data->comm = kzalloc(size, GFP_KERNEL);
540+
if (!elt_data->comm) {
541+
kfree(elt_data);
525542
return -ENOMEM;
543+
}
526544
break;
527545
}
528546
}
529547

548+
elt->private_data = elt_data;
549+
530550
return 0;
531551
}
532552

533-
static void hist_trigger_elt_comm_init(struct tracing_map_elt *elt)
553+
static void hist_trigger_elt_data_init(struct tracing_map_elt *elt)
534554
{
535-
char *comm = elt->private_data;
555+
struct hist_elt_data *elt_data = elt->private_data;
536556

537-
if (comm)
538-
save_comm(comm, current);
557+
if (elt_data->comm)
558+
save_comm(elt_data->comm, current);
539559
}
540560

541-
static const struct tracing_map_ops hist_trigger_elt_comm_ops = {
542-
.elt_alloc = hist_trigger_elt_comm_alloc,
543-
.elt_free = hist_trigger_elt_comm_free,
544-
.elt_init = hist_trigger_elt_comm_init,
561+
static const struct tracing_map_ops hist_trigger_elt_data_ops = {
562+
.elt_alloc = hist_trigger_elt_data_alloc,
563+
.elt_free = hist_trigger_elt_data_free,
564+
.elt_init = hist_trigger_elt_data_init,
545565
};
546566

547567
static const char *get_hist_field_flags(struct hist_field *hist_field)
@@ -1484,21 +1504,6 @@ static int create_tracing_map_fields(struct hist_trigger_data *hist_data)
14841504
return 0;
14851505
}
14861506

1487-
static bool need_tracing_map_ops(struct hist_trigger_data *hist_data)
1488-
{
1489-
struct hist_field *key_field;
1490-
unsigned int i;
1491-
1492-
for_each_hist_key_field(i, hist_data) {
1493-
key_field = hist_data->fields[i];
1494-
1495-
if (key_field->flags & HIST_FIELD_FL_EXECNAME)
1496-
return true;
1497-
}
1498-
1499-
return false;
1500-
}
1501-
15021507
static struct hist_trigger_data *
15031508
create_hist_data(unsigned int map_bits,
15041509
struct hist_trigger_attrs *attrs,
@@ -1524,8 +1529,7 @@ create_hist_data(unsigned int map_bits,
15241529
if (ret)
15251530
goto free;
15261531

1527-
if (need_tracing_map_ops(hist_data))
1528-
map_ops = &hist_trigger_elt_comm_ops;
1532+
map_ops = &hist_trigger_elt_data_ops;
15291533

15301534
hist_data->map = tracing_map_create(map_bits, hist_data->key_size,
15311535
map_ops, hist_data);
@@ -1713,7 +1717,13 @@ hist_trigger_entry_print(struct seq_file *m,
17131717
seq_printf(m, "%s: [%llx] %-55s", field_name,
17141718
uval, str);
17151719
} else if (key_field->flags & HIST_FIELD_FL_EXECNAME) {
1716-
char *comm = elt->private_data;
1720+
struct hist_elt_data *elt_data = elt->private_data;
1721+
char *comm;
1722+
1723+
if (WARN_ON_ONCE(!elt_data))
1724+
return;
1725+
1726+
comm = elt_data->comm;
17171727

17181728
uval = *(u64 *)(key + key_field->offset);
17191729
seq_printf(m, "%s: %-16s[%10llu]", field_name,

0 commit comments

Comments
 (0)