Skip to content

Commit b5f081b

Browse files
committed
tracing: Pass the trace_array into ftrace_probe_ops functions
Pass the trace_array associated to a ftrace_probe_ops into the probe_ops func(), init() and free() functions. The trace_array is the descriptor that describes a tracing instance. This will help create the infrastructure that will allow having function probes unique to tracing instances. Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 04ec7bb commit b5f081b

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

kernel/trace/ftrace.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3791,6 +3791,7 @@ static void function_trace_probe_call(unsigned long ip, unsigned long parent_ip,
37913791
struct ftrace_ops *op, struct pt_regs *pt_regs)
37923792
{
37933793
struct ftrace_probe_ops *probe_ops;
3794+
struct trace_array *tr = op->private;
37943795

37953796
probe_ops = container_of(op, struct ftrace_probe_ops, ops);
37963797

@@ -3800,7 +3801,7 @@ static void function_trace_probe_call(unsigned long ip, unsigned long parent_ip,
38003801
* on the hash. rcu_read_lock is too dangerous here.
38013802
*/
38023803
preempt_disable_notrace();
3803-
probe_ops->func(ip, parent_ip, probe_ops, NULL);
3804+
probe_ops->func(ip, parent_ip, tr, probe_ops, NULL);
38043805
preempt_enable_notrace();
38053806
}
38063807

@@ -3969,6 +3970,7 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr,
39693970
ops->ops.func = function_trace_probe_call;
39703971
ftrace_ops_init(&ops->ops);
39713972
INIT_LIST_HEAD(&ops->list);
3973+
ops->ops.private = tr;
39723974
}
39733975

39743976
mutex_lock(&ops->ops.func_hash->regex_lock);
@@ -3997,7 +3999,7 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr,
39973999
* to give the caller an opportunity to do so.
39984000
*/
39994001
if (ops->init) {
4000-
ret = ops->init(ops, entry->ip, data);
4002+
ret = ops->init(ops, tr, entry->ip, data);
40014003
if (ret < 0)
40024004
goto out;
40034005
}
@@ -4038,7 +4040,7 @@ register_ftrace_function_probe(char *glob, struct trace_array *tr,
40384040
hlist_for_each_entry(entry, &hash->buckets[i], hlist) {
40394041
if (ftrace_lookup_ip(old_hash, entry->ip))
40404042
continue;
4041-
ops->free(ops, entry->ip, NULL);
4043+
ops->free(ops, tr, entry->ip, NULL);
40424044
}
40434045
}
40444046
goto out_unlock;
@@ -4055,13 +4057,16 @@ unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
40554057
struct ftrace_hash *hash = NULL;
40564058
struct hlist_node *tmp;
40574059
struct hlist_head hhd;
4060+
struct trace_array *tr;
40584061
char str[KSYM_SYMBOL_LEN];
40594062
int i, ret;
40604063
int size;
40614064

40624065
if (!(ops->ops.flags & FTRACE_OPS_FL_INITIALIZED))
40634066
return -EINVAL;
40644067

4068+
tr = ops->ops.private;
4069+
40654070
if (glob && (strcmp(glob, "*") == 0 || !strlen(glob)))
40664071
func_g.search = NULL;
40674072
else if (glob) {
@@ -4139,7 +4144,7 @@ unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops)
41394144
hlist_for_each_entry_safe(entry, tmp, &hhd, hlist) {
41404145
hlist_del(&entry->hlist);
41414146
if (ops->free)
4142-
ops->free(ops, entry->ip, NULL);
4147+
ops->free(ops, tr, entry->ip, NULL);
41434148
kfree(entry);
41444149
}
41454150
mutex_unlock(&ftrace_lock);

kernel/trace/trace.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6736,14 +6736,16 @@ static const struct file_operations tracing_dyn_info_fops = {
67366736
#if defined(CONFIG_TRACER_SNAPSHOT) && defined(CONFIG_DYNAMIC_FTRACE)
67376737
static void
67386738
ftrace_snapshot(unsigned long ip, unsigned long parent_ip,
6739-
struct ftrace_probe_ops *ops, void **data)
6739+
struct trace_array *tr, struct ftrace_probe_ops *ops,
6740+
void **data)
67406741
{
67416742
tracing_snapshot();
67426743
}
67436744

67446745
static void
67456746
ftrace_count_snapshot(unsigned long ip, unsigned long parent_ip,
6746-
struct ftrace_probe_ops *ops, void **data)
6747+
struct trace_array *tr, struct ftrace_probe_ops *ops,
6748+
void **data)
67476749
{
67486750
struct ftrace_func_mapper *mapper = ops->private_data;
67496751
long *count = NULL;
@@ -6785,17 +6787,17 @@ ftrace_snapshot_print(struct seq_file *m, unsigned long ip,
67856787
}
67866788

67876789
static int
6788-
ftrace_snapshot_init(struct ftrace_probe_ops *ops, unsigned long ip,
6789-
void *data)
6790+
ftrace_snapshot_init(struct ftrace_probe_ops *ops, struct trace_array *tr,
6791+
unsigned long ip, void *data)
67906792
{
67916793
struct ftrace_func_mapper *mapper = ops->private_data;
67926794

67936795
return ftrace_func_mapper_add_ip(mapper, ip, data);
67946796
}
67956797

67966798
static void
6797-
ftrace_snapshot_free(struct ftrace_probe_ops *ops, unsigned long ip,
6798-
void **_data)
6799+
ftrace_snapshot_free(struct ftrace_probe_ops *ops, struct trace_array *tr,
6800+
unsigned long ip, void **data)
67996801
{
68006802
struct ftrace_func_mapper *mapper = ops->private_data;
68016803

kernel/trace/trace.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,11 +943,14 @@ struct ftrace_probe_ops {
943943
struct list_head list;
944944
void (*func)(unsigned long ip,
945945
unsigned long parent_ip,
946+
struct trace_array *tr,
946947
struct ftrace_probe_ops *ops,
947948
void **data);
948949
int (*init)(struct ftrace_probe_ops *ops,
950+
struct trace_array *tr,
949951
unsigned long ip, void *data);
950952
void (*free)(struct ftrace_probe_ops *ops,
953+
struct trace_array *tr,
951954
unsigned long ip, void **data);
952955
int (*print)(struct seq_file *m,
953956
unsigned long ip,

kernel/trace/trace_events.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,8 @@ static void update_event_probe(struct event_probe_data *data)
24702470

24712471
static void
24722472
event_enable_probe(unsigned long ip, unsigned long parent_ip,
2473-
struct ftrace_probe_ops *ops, void **_data)
2473+
struct trace_array *tr, struct ftrace_probe_ops *ops,
2474+
void **_data)
24742475
{
24752476
struct ftrace_func_mapper *mapper = ops->private_data;
24762477
struct event_probe_data *data;
@@ -2486,7 +2487,8 @@ event_enable_probe(unsigned long ip, unsigned long parent_ip,
24862487

24872488
static void
24882489
event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
2489-
struct ftrace_probe_ops *ops, void **_data)
2490+
struct trace_array *tr, struct ftrace_probe_ops *ops,
2491+
void **_data)
24902492
{
24912493
struct ftrace_func_mapper *mapper = ops->private_data;
24922494
struct event_probe_data *data;
@@ -2513,7 +2515,7 @@ event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
25132515

25142516
static int
25152517
event_enable_print(struct seq_file *m, unsigned long ip,
2516-
struct ftrace_probe_ops *ops, void *_data)
2518+
struct ftrace_probe_ops *ops, void *_data)
25172519
{
25182520
struct ftrace_func_mapper *mapper = ops->private_data;
25192521
struct event_probe_data *data;
@@ -2542,8 +2544,8 @@ event_enable_print(struct seq_file *m, unsigned long ip,
25422544
}
25432545

25442546
static int
2545-
event_enable_init(struct ftrace_probe_ops *ops, unsigned long ip,
2546-
void *_data)
2547+
event_enable_init(struct ftrace_probe_ops *ops, struct trace_array *tr,
2548+
unsigned long ip, void *_data)
25472549
{
25482550
struct ftrace_func_mapper *mapper = ops->private_data;
25492551
struct event_probe_data *data = _data;
@@ -2559,8 +2561,8 @@ event_enable_init(struct ftrace_probe_ops *ops, unsigned long ip,
25592561
}
25602562

25612563
static void
2562-
event_enable_free(struct ftrace_probe_ops *ops, unsigned long ip,
2563-
void **_data)
2564+
event_enable_free(struct ftrace_probe_ops *ops, struct trace_array *tr,
2565+
unsigned long ip, void **_data)
25642566
{
25652567
struct ftrace_func_mapper *mapper = ops->private_data;
25662568
struct event_probe_data *data;

kernel/trace/trace_functions.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,24 @@ static void update_traceon_count(struct ftrace_probe_ops *ops,
328328

329329
static void
330330
ftrace_traceon_count(unsigned long ip, unsigned long parent_ip,
331-
struct ftrace_probe_ops *ops, void **data)
331+
struct trace_array *tr, struct ftrace_probe_ops *ops,
332+
void **data)
332333
{
333334
update_traceon_count(ops, ip, 1);
334335
}
335336

336337
static void
337338
ftrace_traceoff_count(unsigned long ip, unsigned long parent_ip,
338-
struct ftrace_probe_ops *ops, void **data)
339+
struct trace_array *tr, struct ftrace_probe_ops *ops,
340+
void **data)
339341
{
340342
update_traceon_count(ops, ip, 0);
341343
}
342344

343345
static void
344346
ftrace_traceon(unsigned long ip, unsigned long parent_ip,
345-
struct ftrace_probe_ops *ops, void **data)
347+
struct trace_array *tr, struct ftrace_probe_ops *ops,
348+
void **data)
346349
{
347350
if (tracing_is_on())
348351
return;
@@ -352,7 +355,8 @@ ftrace_traceon(unsigned long ip, unsigned long parent_ip,
352355

353356
static void
354357
ftrace_traceoff(unsigned long ip, unsigned long parent_ip,
355-
struct ftrace_probe_ops *ops, void **data)
358+
struct trace_array *tr, struct ftrace_probe_ops *ops,
359+
void **data)
356360
{
357361
if (!tracing_is_on())
358362
return;
@@ -371,14 +375,16 @@ ftrace_traceoff(unsigned long ip, unsigned long parent_ip,
371375

372376
static void
373377
ftrace_stacktrace(unsigned long ip, unsigned long parent_ip,
374-
struct ftrace_probe_ops *ops, void **data)
378+
struct trace_array *tr, struct ftrace_probe_ops *ops,
379+
void **data)
375380
{
376381
trace_dump_stack(STACK_SKIP);
377382
}
378383

379384
static void
380385
ftrace_stacktrace_count(unsigned long ip, unsigned long parent_ip,
381-
struct ftrace_probe_ops *ops, void **data)
386+
struct trace_array *tr, struct ftrace_probe_ops *ops,
387+
void **data)
382388
{
383389
struct ftrace_func_mapper *mapper = ops->private_data;
384390
long *count;
@@ -436,7 +442,8 @@ static int update_count(struct ftrace_probe_ops *ops, unsigned long ip)
436442

437443
static void
438444
ftrace_dump_probe(unsigned long ip, unsigned long parent_ip,
439-
struct ftrace_probe_ops *ops, void **data)
445+
struct trace_array *tr, struct ftrace_probe_ops *ops,
446+
void **data)
440447
{
441448
if (update_count(ops, ip))
442449
ftrace_dump(DUMP_ALL);
@@ -445,7 +452,8 @@ ftrace_dump_probe(unsigned long ip, unsigned long parent_ip,
445452
/* Only dump the current CPU buffer. */
446453
static void
447454
ftrace_cpudump_probe(unsigned long ip, unsigned long parent_ip,
448-
struct ftrace_probe_ops *ops, void **data)
455+
struct trace_array *tr, struct ftrace_probe_ops *ops,
456+
void **data)
449457
{
450458
if (update_count(ops, ip))
451459
ftrace_dump(DUMP_ORIG);
@@ -473,7 +481,8 @@ ftrace_probe_print(const char *name, struct seq_file *m,
473481

474482
static int
475483
ftrace_traceon_print(struct seq_file *m, unsigned long ip,
476-
struct ftrace_probe_ops *ops, void *data)
484+
struct ftrace_probe_ops *ops,
485+
void *data)
477486
{
478487
return ftrace_probe_print("traceon", m, ip, ops);
479488
}
@@ -508,17 +517,17 @@ ftrace_cpudump_print(struct seq_file *m, unsigned long ip,
508517

509518

510519
static int
511-
ftrace_count_init(struct ftrace_probe_ops *ops, unsigned long ip,
512-
void *data)
520+
ftrace_count_init(struct ftrace_probe_ops *ops, struct trace_array *tr,
521+
unsigned long ip, void *data)
513522
{
514523
struct ftrace_func_mapper *mapper = ops->private_data;
515524

516525
return ftrace_func_mapper_add_ip(mapper, ip, data);
517526
}
518527

519528
static void
520-
ftrace_count_free(struct ftrace_probe_ops *ops, unsigned long ip,
521-
void **_data)
529+
ftrace_count_free(struct ftrace_probe_ops *ops, struct trace_array *tr,
530+
unsigned long ip, void **_data)
522531
{
523532
struct ftrace_func_mapper *mapper = ops->private_data;
524533

0 commit comments

Comments
 (0)