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 "../wrapper/vmalloc.h"
23 #include "../ltt-tracer.h"
26 void lttng_ftrace_handler(unsigned long ip
, unsigned long parent_ip
, void **data
)
28 struct ltt_event
*event
= *data
;
29 struct ltt_channel
*chan
= event
->chan
;
30 struct lib_ring_buffer_ctx ctx
;
33 unsigned long parent_ip
;
37 if (!ACCESS_ONCE(chan
->session
->active
))
39 lib_ring_buffer_ctx_init(&ctx
, chan
->chan
, NULL
,
40 sizeof(payload
), ltt_alignof(payload
), -1);
41 ret
= chan
->ops
->event_reserve(&ctx
);
45 payload
.parent_ip
= parent_ip
;
46 lib_ring_buffer_align_ctx(&ctx
, ltt_alignof(payload
));
47 chan
->ops
->event_write(&ctx
, &payload
, sizeof(payload
));
48 chan
->ops
->event_commit(&ctx
);
53 * Create event description
56 int lttng_create_ftrace_event(const char *name
, struct ltt_event
*event
)
58 struct lttng_event_field
*fields
;
59 struct lttng_event_desc
*desc
;
62 desc
= kzalloc(sizeof(*event
->desc
), GFP_KERNEL
);
65 desc
->name
= kstrdup(name
, GFP_KERNEL
);
71 desc
->fields
= fields
=
72 kzalloc(2 * sizeof(struct lttng_event_field
), GFP_KERNEL
);
77 fields
[0].name
= "ip";
78 fields
[0].type
.atype
= atype_integer
;
79 fields
[0].type
.u
.basic
.integer
.size
= sizeof(unsigned long) * CHAR_BIT
;
80 fields
[0].type
.u
.basic
.integer
.alignment
= ltt_alignof(unsigned long) * CHAR_BIT
;
81 fields
[0].type
.u
.basic
.integer
.signedness
= 0;
82 fields
[0].type
.u
.basic
.integer
.reverse_byte_order
= 0;
83 fields
[0].type
.u
.basic
.integer
.base
= 16;
84 fields
[0].type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
86 fields
[1].name
= "parent_ip";
87 fields
[1].type
.atype
= atype_integer
;
88 fields
[1].type
.u
.basic
.integer
.size
= sizeof(unsigned long) * CHAR_BIT
;
89 fields
[1].type
.u
.basic
.integer
.alignment
= ltt_alignof(unsigned long) * CHAR_BIT
;
90 fields
[1].type
.u
.basic
.integer
.signedness
= 0;
91 fields
[1].type
.u
.basic
.integer
.reverse_byte_order
= 0;
92 fields
[1].type
.u
.basic
.integer
.base
= 16;
93 fields
[1].type
.u
.basic
.integer
.encoding
= lttng_encode_none
;
107 struct ftrace_probe_ops lttng_ftrace_ops
= {
108 .func
= lttng_ftrace_handler
,
111 int lttng_ftrace_register(const char *name
,
112 const char *symbol_name
,
113 struct ltt_event
*event
)
117 ret
= lttng_create_ftrace_event(name
, event
);
121 event
->u
.ftrace
.symbol_name
= kstrdup(name
, GFP_KERNEL
);
122 if (!event
->u
.ftrace
.symbol_name
)
125 /* Ensure the memory we just allocated don't trigger page faults */
126 wrapper_vmalloc_sync_all();
128 ret
= wrapper_register_ftrace_function_probe(event
->u
.ftrace
.symbol_name
,
129 <tng_ftrace_ops
, event
);
135 kfree(event
->u
.ftrace
.symbol_name
);
137 kfree(event
->desc
->name
);
142 EXPORT_SYMBOL_GPL(lttng_ftrace_register
);
144 void lttng_ftrace_unregister(struct ltt_event
*event
)
146 wrapper_unregister_ftrace_function_probe(event
->u
.ftrace
.symbol_name
,
147 <tng_ftrace_ops
, event
);
148 kfree(event
->u
.ftrace
.symbol_name
);
149 kfree(event
->desc
->fields
);
150 kfree(event
->desc
->name
);
153 EXPORT_SYMBOL_GPL(lttng_ftrace_unregister
);
155 /* This module is permanent. */
156 int lttng_ftrace_init(void)
158 wrapper_vmalloc_sync_all();
161 module_init(lttng_ftrace_init
)
163 MODULE_LICENSE("GPL and additional rights");
164 MODULE_AUTHOR("Mathieu Desnoyers");
165 MODULE_DESCRIPTION("Linux Trace Toolkit Ftrace Support");