Skip to content

Commit 04ec7bb

Browse files
committed
tracing: Have the trace_array hold the list of registered func probes
Add a link list to the trace_array to hold func probes that are registered. Currently, all function probes are the same for all instances as it was before, that is, only the top level trace_array holds the function probes. But this lays the ground work to have function probes be attached to individual instances, and having the event trigger only affect events in the given instance. But that work is still to be done. Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 8d70725 commit 04ec7bb

File tree

5 files changed

+56
-30
lines changed

5 files changed

+56
-30
lines changed

kernel/trace/ftrace.c

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,6 @@ static bool update_all_ops;
10961096
# error Dynamic ftrace depends on MCOUNT_RECORD
10971097
#endif
10981098

1099-
static LIST_HEAD(ftrace_func_probes);
1100-
11011099
struct ftrace_func_entry {
11021100
struct hlist_node hlist;
11031101
unsigned long ip;
@@ -3070,6 +3068,8 @@ static void *
30703068
t_probe_next(struct seq_file *m, loff_t *pos)
30713069
{
30723070
struct ftrace_iterator *iter = m->private;
3071+
struct trace_array *tr = global_ops.private;
3072+
struct list_head *func_probes;
30733073
struct ftrace_hash *hash;
30743074
struct list_head *next;
30753075
struct hlist_node *hnd = NULL;
@@ -3079,11 +3079,15 @@ t_probe_next(struct seq_file *m, loff_t *pos)
30793079
(*pos)++;
30803080
iter->pos = *pos;
30813081

3082-
if (list_empty(&ftrace_func_probes))
3082+
if (!tr)
3083+
return NULL;
3084+
3085+
func_probes = &tr->func_probes;
3086+
if (list_empty(func_probes))
30833087
return NULL;
30843088

30853089
if (!iter->probe) {
3086-
next = ftrace_func_probes.next;
3090+
next = func_probes->next;
30873091
iter->probe = list_entry(next, struct ftrace_probe_ops, list);
30883092
}
30893093

@@ -3095,7 +3099,7 @@ t_probe_next(struct seq_file *m, loff_t *pos)
30953099

30963100
retry:
30973101
if (iter->pidx >= size) {
3098-
if (iter->probe->list.next == &ftrace_func_probes)
3102+
if (iter->probe->list.next == func_probes)
30993103
return NULL;
31003104
next = iter->probe->list.next;
31013105
iter->probe = list_entry(next, struct ftrace_probe_ops, list);
@@ -3752,7 +3756,7 @@ static int ftrace_hash_move_and_update_ops(struct ftrace_ops *ops,
37523756
*/
37533757

37543758
static int
3755-
ftrace_mod_callback(struct ftrace_hash *hash,
3759+
ftrace_mod_callback(struct trace_array *tr, struct ftrace_hash *hash,
37563760
char *func, char *cmd, char *module, int enable)
37573761
{
37583762
int ret;
@@ -3942,8 +3946,8 @@ void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
39423946
}
39433947

39443948
int
3945-
register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
3946-
void *data)
3949+
register_ftrace_function_probe(char *glob, struct trace_array *tr,
3950+
struct ftrace_probe_ops *ops, void *data)
39473951
{
39483952
struct ftrace_func_entry *entry;
39493953
struct ftrace_hash **orig_hash;
@@ -3954,6 +3958,9 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
39543958
int ret;
39553959
int i;
39563960

3961+
if (WARN_ON(!tr))
3962+
return -EINVAL;
3963+
39573964
/* We do not support '!' for function probes */
39583965
if (WARN_ON(glob[0] == '!'))
39593966
return -EINVAL;
@@ -4006,7 +4013,7 @@ register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
40064013
goto err_unlock;
40074014

40084015
if (list_empty(&ops->list))
4009-
list_add(&ops->list, &ftrace_func_probes);
4016+
list_add(&ops->list, &tr->func_probes);
40104017

40114018
if (!(ops->ops.flags & FTRACE_OPS_FL_ENABLED))
40124019
ret = ftrace_startup(&ops->ops, 0);
@@ -4192,9 +4199,11 @@ __init int unregister_ftrace_command(struct ftrace_func_command *cmd)
41924199
return ret;
41934200
}
41944201

4195-
static int ftrace_process_regex(struct ftrace_hash *hash,
4202+
static int ftrace_process_regex(struct ftrace_iterator *iter,
41964203
char *buff, int len, int enable)
41974204
{
4205+
struct ftrace_hash *hash = iter->hash;
4206+
struct trace_array *tr = global_ops.private;
41984207
char *func, *command, *next = buff;
41994208
struct ftrace_func_command *p;
42004209
int ret = -EINVAL;
@@ -4214,10 +4223,13 @@ static int ftrace_process_regex(struct ftrace_hash *hash,
42144223

42154224
command = strsep(&next, ":");
42164225

4226+
if (WARN_ON_ONCE(!tr))
4227+
return -EINVAL;
4228+
42174229
mutex_lock(&ftrace_cmd_mutex);
42184230
list_for_each_entry(p, &ftrace_commands, list) {
42194231
if (strcmp(p->name, command) == 0) {
4220-
ret = p->func(hash, func, command, next, enable);
4232+
ret = p->func(tr, hash, func, command, next, enable);
42214233
goto out_unlock;
42224234
}
42234235
}
@@ -4254,7 +4266,7 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
42544266

42554267
if (read >= 0 && trace_parser_loaded(parser) &&
42564268
!trace_parser_cont(parser)) {
4257-
ret = ftrace_process_regex(iter->hash, parser->buffer,
4269+
ret = ftrace_process_regex(iter, parser->buffer,
42584270
parser->idx, enable);
42594271
trace_parser_clear(parser);
42604272
if (ret < 0)
@@ -5441,6 +5453,10 @@ static void ftrace_update_trampoline(struct ftrace_ops *ops)
54415453
arch_ftrace_update_trampoline(ops);
54425454
}
54435455

5456+
void ftrace_init_trace_array(struct trace_array *tr)
5457+
{
5458+
INIT_LIST_HEAD(&tr->func_probes);
5459+
}
54445460
#else
54455461

54465462
static struct ftrace_ops global_ops = {
@@ -5495,6 +5511,7 @@ __init void ftrace_init_global_array_ops(struct trace_array *tr)
54955511
{
54965512
tr->ops = &global_ops;
54975513
tr->ops->private = tr;
5514+
ftrace_init_trace_array(tr);
54985515
}
54995516

55005517
void ftrace_init_array_ops(struct trace_array *tr, ftrace_func_t func)

kernel/trace/trace.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6815,7 +6815,7 @@ static struct ftrace_probe_ops snapshot_count_probe_ops = {
68156815
};
68166816

68176817
static int
6818-
ftrace_trace_snapshot_callback(struct ftrace_hash *hash,
6818+
ftrace_trace_snapshot_callback(struct trace_array *tr, struct ftrace_hash *hash,
68196819
char *glob, char *cmd, char *param, int enable)
68206820
{
68216821
struct ftrace_probe_ops *ops;
@@ -6855,7 +6855,7 @@ ftrace_trace_snapshot_callback(struct ftrace_hash *hash,
68556855
return ret;
68566856

68576857
out_reg:
6858-
ret = register_ftrace_function_probe(glob, ops, count);
6858+
ret = register_ftrace_function_probe(glob, tr, ops, count);
68596859

68606860
if (ret >= 0)
68616861
alloc_snapshot(&global_trace);
@@ -7468,6 +7468,8 @@ static int instance_mkdir(const char *name)
74687468
goto out_free_tr;
74697469
}
74707470

7471+
ftrace_init_trace_array(tr);
7472+
74717473
init_tracer_tracefs(tr, tr->dir);
74727474
init_trace_flags_index(tr);
74737475
__update_tracer_options(tr);

kernel/trace/trace.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@ struct trace_array {
262262
#ifdef CONFIG_FUNCTION_TRACER
263263
struct ftrace_ops *ops;
264264
struct trace_pid_list __rcu *function_pids;
265+
#ifdef CONFIG_DYNAMIC_FTRACE
266+
struct list_head func_probes;
267+
#endif
265268
/* function tracing enabled */
266269
int function_enabled;
267270
#endif
@@ -696,6 +699,9 @@ extern void trace_event_follow_fork(struct trace_array *tr, bool enable);
696699

697700
#ifdef CONFIG_DYNAMIC_FTRACE
698701
extern unsigned long ftrace_update_tot_cnt;
702+
void ftrace_init_trace_array(struct trace_array *tr);
703+
#else
704+
static inline void ftrace_init_trace_array(struct trace_array *tr) { }
699705
#endif
700706
#define DYN_FTRACE_TEST_NAME trace_selftest_dynamic_test_func
701707
extern int DYN_FTRACE_TEST_NAME(void);
@@ -883,7 +889,8 @@ extern struct list_head ftrace_pids;
883889
struct ftrace_func_command {
884890
struct list_head list;
885891
char *name;
886-
int (*func)(struct ftrace_hash *hash,
892+
int (*func)(struct trace_array *tr,
893+
struct ftrace_hash *hash,
887894
char *func, char *cmd,
888895
char *params, int enable);
889896
};
@@ -963,8 +970,8 @@ void free_ftrace_func_mapper(struct ftrace_func_mapper *mapper,
963970
ftrace_mapper_func free_func);
964971

965972
extern int
966-
register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
967-
void *data);
973+
register_ftrace_function_probe(char *glob, struct trace_array *tr,
974+
struct ftrace_probe_ops *ops, void *data);
968975
extern int
969976
unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
970977

kernel/trace/trace_events.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2611,10 +2611,9 @@ static struct ftrace_probe_ops event_disable_count_probe_ops = {
26112611
};
26122612

26132613
static int
2614-
event_enable_func(struct ftrace_hash *hash,
2614+
event_enable_func(struct trace_array *tr, struct ftrace_hash *hash,
26152615
char *glob, char *cmd, char *param, int enabled)
26162616
{
2617-
struct trace_array *tr = top_trace_array();
26182617
struct trace_event_file *file;
26192618
struct ftrace_probe_ops *ops;
26202619
struct event_probe_data *data;
@@ -2701,7 +2700,7 @@ event_enable_func(struct ftrace_hash *hash,
27012700
if (ret < 0)
27022701
goto out_put;
27032702

2704-
ret = register_ftrace_function_probe(glob, ops, data);
2703+
ret = register_ftrace_function_probe(glob, tr, ops, data);
27052704
/*
27062705
* The above returns on success the # of functions enabled,
27072706
* but if it didn't find any functions it returns zero.

kernel/trace/trace_functions.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,8 @@ static struct ftrace_probe_ops stacktrace_probe_ops = {
574574
};
575575

576576
static int
577-
ftrace_trace_probe_callback(struct ftrace_probe_ops *ops,
577+
ftrace_trace_probe_callback(struct trace_array *tr,
578+
struct ftrace_probe_ops *ops,
578579
struct ftrace_hash *hash, char *glob,
579580
char *cmd, char *param, int enable)
580581
{
@@ -612,13 +613,13 @@ ftrace_trace_probe_callback(struct ftrace_probe_ops *ops,
612613
return ret;
613614

614615
out_reg:
615-
ret = register_ftrace_function_probe(glob, ops, count);
616+
ret = register_ftrace_function_probe(glob, tr, ops, count);
616617

617618
return ret < 0 ? ret : 0;
618619
}
619620

620621
static int
621-
ftrace_trace_onoff_callback(struct ftrace_hash *hash,
622+
ftrace_trace_onoff_callback(struct trace_array *tr, struct ftrace_hash *hash,
622623
char *glob, char *cmd, char *param, int enable)
623624
{
624625
struct ftrace_probe_ops *ops;
@@ -629,45 +630,45 @@ ftrace_trace_onoff_callback(struct ftrace_hash *hash,
629630
else
630631
ops = param ? &traceoff_count_probe_ops : &traceoff_probe_ops;
631632

632-
return ftrace_trace_probe_callback(ops, hash, glob, cmd,
633+
return ftrace_trace_probe_callback(tr, ops, hash, glob, cmd,
633634
param, enable);
634635
}
635636

636637
static int
637-
ftrace_stacktrace_callback(struct ftrace_hash *hash,
638+
ftrace_stacktrace_callback(struct trace_array *tr, struct ftrace_hash *hash,
638639
char *glob, char *cmd, char *param, int enable)
639640
{
640641
struct ftrace_probe_ops *ops;
641642

642643
ops = param ? &stacktrace_count_probe_ops : &stacktrace_probe_ops;
643644

644-
return ftrace_trace_probe_callback(ops, hash, glob, cmd,
645+
return ftrace_trace_probe_callback(tr, ops, hash, glob, cmd,
645646
param, enable);
646647
}
647648

648649
static int
649-
ftrace_dump_callback(struct ftrace_hash *hash,
650+
ftrace_dump_callback(struct trace_array *tr, struct ftrace_hash *hash,
650651
char *glob, char *cmd, char *param, int enable)
651652
{
652653
struct ftrace_probe_ops *ops;
653654

654655
ops = &dump_probe_ops;
655656

656657
/* Only dump once. */
657-
return ftrace_trace_probe_callback(ops, hash, glob, cmd,
658+
return ftrace_trace_probe_callback(tr, ops, hash, glob, cmd,
658659
"1", enable);
659660
}
660661

661662
static int
662-
ftrace_cpudump_callback(struct ftrace_hash *hash,
663+
ftrace_cpudump_callback(struct trace_array *tr, struct ftrace_hash *hash,
663664
char *glob, char *cmd, char *param, int enable)
664665
{
665666
struct ftrace_probe_ops *ops;
666667

667668
ops = &cpudump_probe_ops;
668669

669670
/* Only dump once. */
670-
return ftrace_trace_probe_callback(ops, hash, glob, cmd,
671+
return ftrace_trace_probe_callback(tr, ops, hash, glob, cmd,
671672
"1", enable);
672673
}
673674

0 commit comments

Comments
 (0)