2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 * LTTng function tracer integration module.
7 * Dual LGPL v2.1/GPL v2 license.
11 * Ftrace function tracer does not seem to provide synchronization between probe
12 * teardown and callback execution. Therefore, we make this module permanently
13 * loaded (unloadable).
16 #include <linux/module.h>
17 #include <linux/ftrace.h>
18 #include <linux/slab.h>
19 #include "../ltt-events.h"
20 #include "../wrapper/ringbuffer/frontend_types.h"
21 #include "../wrapper/ftrace.h"
22 #include "../ltt-tracer.h"
25 void lttng_ftrace_handler(unsigned long ip
, unsigned long parent_ip
, void **data
)
27 struct ltt_event
*event
= *data
;
28 struct ltt_channel
*chan
= event
->chan
;
29 struct lib_ring_buffer_ctx ctx
;
32 unsigned long parent_ip
;
36 if (!ACCESS_ONCE(chan
->session
->active
))
38 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
,
39 sizeof(payload
), ltt_alignof(payload
), -1);
40 ret
= chan
->ops
->event_reserve(&ctx
);
44 payload
.parent_ip
= parent_ip
;
45 lib_ring_buffer_align_ctx(&ctx
, ltt_alignof(payload
));
46 chan
->ops
->event_write(&ctx
, &payload
, sizeof(payload
));
47 chan
->ops
->event_commit(&ctx
);
52 * Create event description
55 int lttng_create_ftrace_event(const char *name
, struct ltt_event
*event
)
57 struct lttng_event_field
*fields
;
58 struct lttng_event_desc
*desc
;
61 desc
= kzalloc(sizeof(*event
->desc
), GFP_KERNEL
);
64 desc
->name
= kstrdup(name
, GFP_KERNEL
);
70 desc
->fields
= fields
=
71 kzalloc(2 * sizeof(struct lttng_event_field
), GFP_KERNEL
);
72 fields
[0].name
= "ip";
73 fields
[0].type
.atype
= atype_integer
;
74 fields
[0].type
.u
.basic
.integer
.size
= sizeof(unsigned long);
75 fields
[0].type
.u
.basic
.integer
.alignment
= ltt_alignof(unsigned long);
76 fields
[0].type
.u
.basic
.integer
.signedness
= 0;
77 fields
[0].type
.u
.basic
.integer
.reverse_byte_order
= 0;
78 fields
[0].type
.u
.basic
.integer
.base
= 16;
79 fields
[0].type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
81 fields
[1].name
= "parent_ip";
82 fields
[1].type
.atype
= atype_integer
;
83 fields
[1].type
.u
.basic
.integer
.size
= sizeof(unsigned long);
84 fields
[1].type
.u
.basic
.integer
.alignment
= ltt_alignof(unsigned long);
85 fields
[1].type
.u
.basic
.integer
.signedness
= 0;
86 fields
[1].type
.u
.basic
.integer
.reverse_byte_order
= 0;
87 fields
[1].type
.u
.basic
.integer
.base
= 16;
88 fields
[1].type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
100 struct ftrace_probe_ops lttng_ftrace_ops
= {
101 .func
= lttng_ftrace_handler
,
104 int lttng_ftrace_register(const char *name
,
105 const char *symbol_name
,
106 struct ltt_event
*event
)
110 ret
= lttng_create_ftrace_event(name
, event
);
114 event
->u
.ftrace
.symbol_name
= kstrdup(name
, GFP_KERNEL
);
115 if (!event
->u
.ftrace
.symbol_name
)
118 ret
= wrapper_register_ftrace_function_probe(event
->u
.ftrace
.symbol_name
,
119 <tng_ftrace_ops
, event
);
125 kfree(event
->u
.ftrace
.symbol_name
);
127 kfree(event
->desc
->name
);
132 EXPORT_SYMBOL_GPL(lttng_ftrace_register
);
134 void lttng_ftrace_unregister(struct ltt_event
*event
)
136 wrapper_unregister_ftrace_function_probe(event
->u
.ftrace
.symbol_name
,
137 <tng_ftrace_ops
, event
);
138 kfree(event
->u
.ftrace
.symbol_name
);
139 kfree(event
->desc
->name
);
142 EXPORT_SYMBOL_GPL(lttng_ftrace_unregister
);
144 /* This module is permanent. */
145 int lttng_ftrace_init(void)
149 module_init(lttng_ftrace_init
)
151 MODULE_LICENSE("GPL and additional rights");
152 MODULE_AUTHOR("Mathieu Desnoyers");
153 MODULE_DESCRIPTION("Linux Trace Toolkit Ftrace Support");