Fix incorrect typing in channel create
[lttng-modules.git] / probes / lttng-ftrace.c
1 /*
2 * (C) Copyright 2009-2011 -
3 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 *
5 * LTTng function tracer integration module.
6 *
7 * Dual LGPL v2.1/GPL v2 license.
8 */
9
10 /*
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).
14 */
15
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"
23
24 static
25 void lttng_ftrace_handler(unsigned long ip, unsigned long parent_ip, void **data)
26 {
27 struct ltt_event *event = *data;
28 struct ltt_channel *chan = event->chan;
29 struct lib_ring_buffer_ctx ctx;
30 struct {
31 unsigned long ip;
32 unsigned long parent_ip;
33 } payload;
34 int ret;
35
36 if (!ACCESS_ONCE(chan->session->active))
37 return;
38 lib_ring_buffer_ctx_init(&ctx, chan->chan, NULL,
39 sizeof(payload), ltt_alignof(payload), -1);
40 ret = chan->ops->event_reserve(&ctx);
41 if (ret < 0)
42 return;
43 payload.ip = ip;
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);
48 return;
49 }
50
51 /*
52 * Create event description
53 */
54 static
55 int lttng_create_ftrace_event(const char *name, struct ltt_event *event)
56 {
57 struct lttng_event_field *fields;
58 struct lttng_event_desc *desc;
59 int ret;
60
61 desc = kzalloc(sizeof(*event->desc), GFP_KERNEL);
62 if (!desc)
63 return -ENOMEM;
64 desc->name = kstrdup(name, GFP_KERNEL);
65 if (!desc->name) {
66 ret = -ENOMEM;
67 goto error_str;
68 }
69 desc->nr_fields = 2;
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;
80
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;
89
90 event->desc = desc;
91
92 return 0;
93
94 error_str:
95 kfree(desc);
96 return ret;
97 }
98
99 static
100 struct ftrace_probe_ops lttng_ftrace_ops = {
101 .func = lttng_ftrace_handler,
102 };
103
104 int lttng_ftrace_register(const char *name,
105 const char *symbol_name,
106 struct ltt_event *event)
107 {
108 int ret;
109
110 ret = lttng_create_ftrace_event(name, event);
111 if (ret)
112 goto error;
113
114 event->u.ftrace.symbol_name = kstrdup(name, GFP_KERNEL);
115 if (!event->u.ftrace.symbol_name)
116 goto name_error;
117
118 ret = wrapper_register_ftrace_function_probe(event->u.ftrace.symbol_name,
119 &lttng_ftrace_ops, event);
120 if (ret)
121 goto register_error;
122 return 0;
123
124 register_error:
125 kfree(event->u.ftrace.symbol_name);
126 name_error:
127 kfree(event->desc->name);
128 kfree(event->desc);
129 error:
130 return ret;
131 }
132 EXPORT_SYMBOL_GPL(lttng_ftrace_register);
133
134 void lttng_ftrace_unregister(struct ltt_event *event)
135 {
136 wrapper_unregister_ftrace_function_probe(event->u.ftrace.symbol_name,
137 &lttng_ftrace_ops, event);
138 kfree(event->u.ftrace.symbol_name);
139 kfree(event->desc->name);
140 kfree(event->desc);
141 }
142 EXPORT_SYMBOL_GPL(lttng_ftrace_unregister);
143
144 /* This module is permanent. */
145 int lttng_ftrace_init(void)
146 {
147 return 0;
148 }
149 module_init(lttng_ftrace_init)
150
151 MODULE_LICENSE("GPL and additional rights");
152 MODULE_AUTHOR("Mathieu Desnoyers");
153 MODULE_DESCRIPTION("Linux Trace Toolkit Ftrace Support");
This page took 0.034022 seconds and 5 git commands to generate.