4 * Copyright (c) 2005-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 * Tracing management internal kernel API. Trace buffer allocation/free, tracing
10 * Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
13 * Karim Yaghmour (karim@opersys.com)
14 * Tom Zanussi (zanussi@us.ibm.com)
15 * Bob Wisniewski (bob@watson.ibm.com)
17 * Bob Wisniewski (bob@watson.ibm.com)
20 * 22/09/06, Move to the marker/probes mechanism.
21 * 19/10/05, Complete lockless mechanism.
22 * 27/05/05, Modular redesign and rewrite.
24 * Dual LGPL v2.1/GPL v2 license.
27 #include <linux/time.h>
28 #include <linux/module.h>
29 #include <linux/string.h>
30 #include <linux/slab.h>
31 #include <linux/init.h>
32 #include <linux/rcupdate.h>
33 #include <linux/sched.h>
34 #include <linux/bitops.h>
36 #include <linux/cpu.h>
37 #include <linux/kref.h>
38 #include <linux/delay.h>
39 #include <linux/vmalloc.h>
40 #include <asm/atomic.h>
42 #include "ltt-tracer.h"
44 static void synchronize_trace(void)
47 #ifdef CONFIG_PREEMPT_RT
52 static void async_wakeup(unsigned long data
);
54 static DEFINE_TIMER(ltt_async_wakeup_timer
, async_wakeup
, 0, 0);
56 /* Default callbacks for modules */
58 int ltt_filter_control_default(enum ltt_filter_control_msg msg
,
59 struct ltt_trace
*trace
)
64 int ltt_statedump_default(struct ltt_trace
*trace
)
69 /* Callbacks for registered modules */
71 int (*ltt_filter_control_functor
)
72 (enum ltt_filter_control_msg msg
, struct ltt_trace
*trace
) =
73 ltt_filter_control_default
;
74 struct module
*ltt_filter_control_owner
;
76 /* These function pointers are protected by a trace activation check */
77 struct module
*ltt_run_filter_owner
;
78 int (*ltt_statedump_functor
)(struct ltt_trace
*trace
) = ltt_statedump_default
;
79 struct module
*ltt_statedump_owner
;
81 struct chan_info_struct
{
83 unsigned int def_sb_size
;
84 unsigned int def_n_sb
;
86 [LTT_CHANNEL_METADATA
] = {
88 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
89 LTT_DEFAULT_N_SUBBUFS_LOW
,
91 [LTT_CHANNEL_FD_STATE
] = {
93 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
94 LTT_DEFAULT_N_SUBBUFS_LOW
,
96 [LTT_CHANNEL_GLOBAL_STATE
] = {
97 LTT_GLOBAL_STATE_CHANNEL
,
98 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
99 LTT_DEFAULT_N_SUBBUFS_LOW
,
101 [LTT_CHANNEL_IRQ_STATE
] = {
102 LTT_IRQ_STATE_CHANNEL
,
103 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
104 LTT_DEFAULT_N_SUBBUFS_LOW
,
106 [LTT_CHANNEL_MODULE_STATE
] = {
107 LTT_MODULE_STATE_CHANNEL
,
108 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
109 LTT_DEFAULT_N_SUBBUFS_LOW
,
111 [LTT_CHANNEL_NETIF_STATE
] = {
112 LTT_NETIF_STATE_CHANNEL
,
113 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
114 LTT_DEFAULT_N_SUBBUFS_LOW
,
116 [LTT_CHANNEL_SOFTIRQ_STATE
] = {
117 LTT_SOFTIRQ_STATE_CHANNEL
,
118 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
119 LTT_DEFAULT_N_SUBBUFS_LOW
,
121 [LTT_CHANNEL_SWAP_STATE
] = {
122 LTT_SWAP_STATE_CHANNEL
,
123 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
124 LTT_DEFAULT_N_SUBBUFS_LOW
,
126 [LTT_CHANNEL_SYSCALL_STATE
] = {
127 LTT_SYSCALL_STATE_CHANNEL
,
128 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
129 LTT_DEFAULT_N_SUBBUFS_LOW
,
131 [LTT_CHANNEL_TASK_STATE
] = {
132 LTT_TASK_STATE_CHANNEL
,
133 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
134 LTT_DEFAULT_N_SUBBUFS_LOW
,
136 [LTT_CHANNEL_VM_STATE
] = {
137 LTT_VM_STATE_CHANNEL
,
138 LTT_DEFAULT_SUBBUF_SIZE_MED
,
139 LTT_DEFAULT_N_SUBBUFS_MED
,
143 LTT_DEFAULT_SUBBUF_SIZE_MED
,
144 LTT_DEFAULT_N_SUBBUFS_MED
,
146 [LTT_CHANNEL_INPUT
] = {
148 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
149 LTT_DEFAULT_N_SUBBUFS_LOW
,
151 [LTT_CHANNEL_IPC
] = {
153 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
154 LTT_DEFAULT_N_SUBBUFS_LOW
,
156 [LTT_CHANNEL_KERNEL
] = {
158 LTT_DEFAULT_SUBBUF_SIZE_HIGH
,
159 LTT_DEFAULT_N_SUBBUFS_HIGH
,
163 LTT_DEFAULT_SUBBUF_SIZE_MED
,
164 LTT_DEFAULT_N_SUBBUFS_MED
,
166 [LTT_CHANNEL_RCU
] = {
168 LTT_DEFAULT_SUBBUF_SIZE_MED
,
169 LTT_DEFAULT_N_SUBBUFS_MED
,
171 [LTT_CHANNEL_DEFAULT
] = {
173 LTT_DEFAULT_SUBBUF_SIZE_MED
,
174 LTT_DEFAULT_N_SUBBUFS_MED
,
178 static enum ltt_channels
get_channel_type_from_name(const char *name
)
183 return LTT_CHANNEL_DEFAULT
;
185 for (i
= 0; i
< ARRAY_SIZE(chan_infos
); i
++)
186 if (chan_infos
[i
].name
&& !strcmp(name
, chan_infos
[i
].name
))
187 return (enum ltt_channels
)i
;
189 return LTT_CHANNEL_DEFAULT
;
193 * ltt_module_register - LTT module registration
195 * @function: callback to register
196 * @owner: module which owns the callback
198 * The module calling this registration function must ensure that no
199 * trap-inducing code will be executed by "function". E.g. vmalloc_sync_all()
200 * must be called between a vmalloc and the moment the memory is made visible to
201 * "function". This registration acts as a vmalloc_sync_all. Therefore, only if
202 * the module allocates virtual memory after its registration must it
203 * synchronize the TLBs.
205 int ltt_module_register(enum ltt_module_function name
, void *function
,
206 struct module
*owner
)
211 * Make sure no page fault can be triggered by the module about to be
212 * registered. We deal with this here so we don't have to call
213 * vmalloc_sync_all() in each module's init.
218 case LTT_FUNCTION_RUN_FILTER
:
219 if (ltt_run_filter_owner
!= NULL
) {
223 ltt_filter_register((ltt_run_filter_functor
)function
);
224 ltt_run_filter_owner
= owner
;
226 case LTT_FUNCTION_FILTER_CONTROL
:
227 if (ltt_filter_control_owner
!= NULL
) {
231 ltt_filter_control_functor
=
232 (int (*)(enum ltt_filter_control_msg
,
233 struct ltt_trace
*))function
;
234 ltt_filter_control_owner
= owner
;
236 case LTT_FUNCTION_STATEDUMP
:
237 if (ltt_statedump_owner
!= NULL
) {
241 ltt_statedump_functor
=
242 (int (*)(struct ltt_trace
*))function
;
243 ltt_statedump_owner
= owner
;
249 EXPORT_SYMBOL_GPL(ltt_module_register
);
252 * ltt_module_unregister - LTT module unregistration
255 void ltt_module_unregister(enum ltt_module_function name
)
258 case LTT_FUNCTION_RUN_FILTER
:
259 ltt_filter_unregister();
260 ltt_run_filter_owner
= NULL
;
261 /* Wait for preempt sections to finish */
264 case LTT_FUNCTION_FILTER_CONTROL
:
265 ltt_filter_control_functor
= ltt_filter_control_default
;
266 ltt_filter_control_owner
= NULL
;
268 case LTT_FUNCTION_STATEDUMP
:
269 ltt_statedump_functor
= ltt_statedump_default
;
270 ltt_statedump_owner
= NULL
;
275 EXPORT_SYMBOL_GPL(ltt_module_unregister
);
277 static LIST_HEAD(ltt_transport_list
);
280 * ltt_transport_register - LTT transport registration
281 * @transport: transport structure
283 * Registers a transport which can be used as output to extract the data out of
284 * LTTng. The module calling this registration function must ensure that no
285 * trap-inducing code will be executed by the transport functions. E.g.
286 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
287 * is made visible to the transport function. This registration acts as a
288 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
289 * after its registration must it synchronize the TLBs.
291 void ltt_transport_register(struct ltt_transport
*transport
)
294 * Make sure no page fault can be triggered by the module about to be
295 * registered. We deal with this here so we don't have to call
296 * vmalloc_sync_all() in each module's init.
301 list_add_tail(&transport
->node
, <t_transport_list
);
304 EXPORT_SYMBOL_GPL(ltt_transport_register
);
307 * ltt_transport_unregister - LTT transport unregistration
308 * @transport: transport structure
310 void ltt_transport_unregister(struct ltt_transport
*transport
)
313 list_del(&transport
->node
);
316 EXPORT_SYMBOL_GPL(ltt_transport_unregister
);
319 int is_channel_overwrite(enum ltt_channels chan
, enum trace_mode mode
)
322 case LTT_TRACE_NORMAL
:
324 case LTT_TRACE_FLIGHT
:
326 case LTT_CHANNEL_METADATA
:
331 case LTT_TRACE_HYBRID
:
333 case LTT_CHANNEL_KERNEL
:
336 case LTT_CHANNEL_RCU
:
337 case LTT_CHANNEL_IPC
:
338 case LTT_CHANNEL_INPUT
:
349 * _ltt_trace_find - find a trace by given name.
350 * trace_name: trace name
352 * Returns a pointer to the trace structure, NULL if not found.
354 static struct ltt_trace
*_ltt_trace_find(const char *trace_name
)
356 struct ltt_trace
*trace
;
358 list_for_each_entry(trace
, <t_traces
.head
, list
)
359 if (!strncmp(trace
->trace_name
, trace_name
, NAME_MAX
))
365 /* _ltt_trace_find_setup :
366 * find a trace in setup list by given name.
368 * Returns a pointer to the trace structure, NULL if not found.
370 struct ltt_trace
*_ltt_trace_find_setup(const char *trace_name
)
372 struct ltt_trace
*trace
;
374 list_for_each_entry(trace
, <t_traces
.setup_head
, list
)
375 if (!strncmp(trace
->trace_name
, trace_name
, NAME_MAX
))
380 EXPORT_SYMBOL_GPL(_ltt_trace_find_setup
);
383 * ltt_release_trace - Release a LTT trace
384 * @kref : reference count on the trace
386 void ltt_release_trace(struct kref
*kref
)
388 struct ltt_trace
*trace
= container_of(kref
, struct ltt_trace
, kref
);
390 trace
->ops
->remove_dirs(trace
);
391 module_put(trace
->transport
->owner
);
392 ltt_channels_trace_free(trace
);
395 EXPORT_SYMBOL_GPL(ltt_release_trace
);
397 static inline void prepare_chan_size_num(unsigned int *subbuf_size
,
398 unsigned int *n_subbufs
)
400 /* Make sure the subbuffer size is larger than a page */
401 *subbuf_size
= max_t(unsigned int, *subbuf_size
, PAGE_SIZE
);
403 /* round to next power of 2 */
404 *subbuf_size
= 1 << get_count_order(*subbuf_size
);
405 *n_subbufs
= 1 << get_count_order(*n_subbufs
);
407 /* Subbuf size and number must both be power of two */
408 WARN_ON(hweight32(*subbuf_size
) != 1);
409 WARN_ON(hweight32(*n_subbufs
) != 1);
412 int _ltt_trace_setup(const char *trace_name
)
415 struct ltt_trace
*new_trace
= NULL
;
418 enum ltt_channels chantype
;
420 if (_ltt_trace_find_setup(trace_name
)) {
421 printk(KERN_ERR
"LTT : Trace name %s already used.\n",
427 if (_ltt_trace_find(trace_name
)) {
428 printk(KERN_ERR
"LTT : Trace name %s already used.\n",
434 new_trace
= kzalloc(sizeof(struct ltt_trace
), GFP_KERNEL
);
437 "LTT : Unable to allocate memory for trace %s\n",
442 strncpy(new_trace
->trace_name
, trace_name
, NAME_MAX
);
443 if (ltt_channels_trace_alloc(&new_trace
->nr_channels
, 0)) {
445 "LTT : Unable to allocate memory for chaninfo %s\n",
452 * Force metadata channel to no overwrite.
454 metadata_index
= ltt_channels_get_index_from_name("metadata");
455 WARN_ON(metadata_index
< 0);
456 new_trace
->settings
[metadata_index
].overwrite
= 0;
459 * Set hardcoded tracer defaults for some channels
461 for (chan
= 0; chan
< new_trace
->nr_channels
; chan
++) {
462 chantype
= get_channel_type_from_name(
463 ltt_channels_get_name_from_index(chan
));
464 new_trace
->settings
[chan
].sb_size
=
465 chan_infos
[chantype
].def_sb_size
;
466 new_trace
->settings
[chan
].n_sb
=
467 chan_infos
[chantype
].def_n_sb
;
470 list_add(&new_trace
->list
, <t_traces
.setup_head
);
478 EXPORT_SYMBOL_GPL(_ltt_trace_setup
);
481 int ltt_trace_setup(const char *trace_name
)
485 ret
= _ltt_trace_setup(trace_name
);
489 EXPORT_SYMBOL_GPL(ltt_trace_setup
);
491 /* must be called from within a traces lock. */
492 static void _ltt_trace_free(struct ltt_trace
*trace
)
494 list_del(&trace
->list
);
498 int ltt_trace_set_type(const char *trace_name
, const char *trace_type
)
501 struct ltt_trace
*trace
;
502 struct ltt_transport
*tran_iter
, *transport
= NULL
;
506 trace
= _ltt_trace_find_setup(trace_name
);
508 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
513 list_for_each_entry(tran_iter
, <t_transport_list
, node
) {
514 if (!strcmp(tran_iter
->name
, trace_type
)) {
515 transport
= tran_iter
;
520 printk(KERN_ERR
"LTT : Transport %s is not present.\n",
526 trace
->transport
= transport
;
532 EXPORT_SYMBOL_GPL(ltt_trace_set_type
);
534 int ltt_trace_set_channel_subbufsize(const char *trace_name
,
535 const char *channel_name
,
539 struct ltt_trace
*trace
;
544 trace
= _ltt_trace_find_setup(trace_name
);
546 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
551 index
= ltt_channels_get_index_from_name(channel_name
);
553 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
557 trace
->settings
[index
].sb_size
= size
;
563 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufsize
);
565 int ltt_trace_set_channel_subbufcount(const char *trace_name
,
566 const char *channel_name
,
570 struct ltt_trace
*trace
;
575 trace
= _ltt_trace_find_setup(trace_name
);
577 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
582 index
= ltt_channels_get_index_from_name(channel_name
);
584 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
588 trace
->settings
[index
].n_sb
= cnt
;
594 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufcount
);
596 int ltt_trace_set_channel_switch_timer(const char *trace_name
,
597 const char *channel_name
,
598 unsigned long interval
)
601 struct ltt_trace
*trace
;
606 trace
= _ltt_trace_find_setup(trace_name
);
608 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
613 index
= ltt_channels_get_index_from_name(channel_name
);
615 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
619 ltt_channels_trace_set_timer(&trace
->settings
[index
], interval
);
625 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_switch_timer
);
627 int ltt_trace_set_channel_overwrite(const char *trace_name
,
628 const char *channel_name
,
629 unsigned int overwrite
)
632 struct ltt_trace
*trace
;
637 trace
= _ltt_trace_find_setup(trace_name
);
639 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
645 * Always put the metadata channel in non-overwrite mode :
646 * This is a very low traffic channel and it can't afford to have its
647 * data overwritten : this data (marker info) is necessary to be
648 * able to read the trace.
650 if (overwrite
&& !strcmp(channel_name
, "metadata")) {
651 printk(KERN_ERR
"LTT : Trying to set metadata channel to "
657 index
= ltt_channels_get_index_from_name(channel_name
);
659 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
664 trace
->settings
[index
].overwrite
= overwrite
;
670 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_overwrite
);
672 int ltt_trace_alloc(const char *trace_name
)
675 struct ltt_trace
*trace
;
679 const char *channel_name
;
683 trace
= _ltt_trace_find_setup(trace_name
);
685 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
690 kref_init(&trace
->kref
);
691 init_waitqueue_head(&trace
->kref_wq
);
694 trace
->freq_scale
= trace_clock_freq_scale();
696 if (!trace
->transport
) {
697 printk(KERN_ERR
"LTT : Transport is not set.\n");
699 goto transport_error
;
701 if (!try_module_get(trace
->transport
->owner
)) {
702 printk(KERN_ERR
"LTT : Can't lock transport module.\n");
704 goto transport_error
;
706 trace
->ops
= &trace
->transport
->ops
;
708 err
= trace
->ops
->create_dirs(trace
);
710 printk(KERN_ERR
"LTT : Can't create dir for trace %s.\n",
715 local_irq_save(flags
);
716 trace
->start_freq
= trace_clock_frequency();
717 trace
->start_tsc
= trace_clock_read64();
718 do_gettimeofday(&trace
->start_time
);
719 local_irq_restore(flags
);
721 for (chan
= 0; chan
< trace
->nr_channels
; chan
++) {
722 channel_name
= ltt_channels_get_name_from_index(chan
);
723 WARN_ON(!channel_name
);
725 * note: sb_size and n_sb will be overwritten with updated
726 * values by channel creation.
728 sb_size
= trace
->settings
[chan
].sb_size
;
729 n_sb
= trace
->settings
[chan
].n_sb
;
730 prepare_chan_size_num(&sb_size
, &n_sb
);
731 trace
->channels
[chan
] = ltt_create_channel(channel_name
,
732 trace
, NULL
, sb_size
, n_sb
,
733 trace
->settings
[chan
].overwrite
,
734 trace
->settings
[chan
].switch_timer_interval
,
735 trace
->settings
[chan
].read_timer_interval
);
737 printk(KERN_ERR
"LTT : Can't create channel %s.\n",
739 goto create_channel_error
;
743 list_del(&trace
->list
);
744 if (list_empty(<t_traces
.head
))
745 set_kernel_trace_flag_all_tasks();
746 list_add_rcu(&trace
->list
, <t_traces
.head
);
753 create_channel_error
:
754 for (chan
--; chan
>= 0; chan
--)
755 ltt_channel_destroy(trace
->channels
[chan
]);
756 trace
->ops
->remove_dirs(trace
);
759 module_put(trace
->transport
->owner
);
766 EXPORT_SYMBOL_GPL(ltt_trace_alloc
);
769 * It is worked as a wrapper for current version of ltt_control.ko.
770 * We will make a new ltt_control based on debugfs, and control each channel's
774 int ltt_trace_create(const char *trace_name
, const char *trace_type
,
775 enum trace_mode mode
,
776 unsigned int subbuf_size_low
, unsigned int n_subbufs_low
,
777 unsigned int subbuf_size_med
, unsigned int n_subbufs_med
,
778 unsigned int subbuf_size_high
, unsigned int n_subbufs_high
)
782 err
= ltt_trace_setup(trace_name
);
783 if (IS_ERR_VALUE(err
))
786 err
= ltt_trace_set_type(trace_name
, trace_type
);
787 if (IS_ERR_VALUE(err
))
790 err
= ltt_trace_alloc(trace_name
);
791 if (IS_ERR_VALUE(err
))
797 /* Must be called while sure that trace is in the list. */
798 static int _ltt_trace_destroy(struct ltt_trace
*trace
)
808 "LTT : Can't destroy trace %s : tracer is active\n",
813 /* Everything went fine */
814 list_del_rcu(&trace
->list
);
816 if (list_empty(<t_traces
.head
)) {
817 clear_kernel_trace_flag_all_tasks();
827 /* Sleepable part of the destroy */
828 static void __ltt_trace_destroy(struct ltt_trace
*trace
)
832 for (i
= 0; i
< trace
->nr_channels
; i
++)
833 ltt_channel_destroy(trace
->channels
[i
]);
834 kref_put(&trace
->kref
, ltt_release_trace
);
837 int ltt_trace_destroy(const char *trace_name
)
840 struct ltt_trace
*trace
;
844 trace
= _ltt_trace_find(trace_name
);
846 err
= _ltt_trace_destroy(trace
);
850 __ltt_trace_destroy(trace
);
857 trace
= _ltt_trace_find_setup(trace_name
);
859 _ltt_trace_free(trace
);
871 EXPORT_SYMBOL_GPL(ltt_trace_destroy
);
873 /* must be called from within a traces lock. */
874 static int _ltt_trace_start(struct ltt_trace
*trace
)
883 printk(KERN_INFO
"LTT : Tracing already active for trace %s\n",
885 if (!try_module_get(ltt_run_filter_owner
)) {
887 printk(KERN_ERR
"LTT : Can't lock filter module.\n");
888 goto get_ltt_run_filter_error
;
891 /* Read by trace points without protection : be careful */
892 ltt_traces
.num_active_traces
++;
896 get_ltt_run_filter_error
:
901 int ltt_trace_start(const char *trace_name
)
904 struct ltt_trace
*trace
;
908 trace
= _ltt_trace_find(trace_name
);
909 err
= _ltt_trace_start(trace
);
916 * Call the kernel state dump.
917 * Events will be mixed with real kernel events, it's ok.
918 * Notice that there is no protection on the trace : that's exactly
919 * why we iterate on the list and check for trace equality instead of
920 * directly using this trace handle inside the logging function.
923 ltt_dump_marker_state(trace
);
925 if (!try_module_get(ltt_statedump_owner
)) {
928 "LTT : Can't lock state dump module.\n");
930 ltt_statedump_functor(trace
);
931 module_put(ltt_statedump_owner
);
941 EXPORT_SYMBOL_GPL(ltt_trace_start
);
943 /* must be called from within traces lock */
944 static int _ltt_trace_stop(struct ltt_trace
*trace
)
953 printk(KERN_INFO
"LTT : Tracing not active for trace %s\n",
957 ltt_traces
.num_active_traces
--;
958 synchronize_trace(); /* Wait for each tracing to be finished */
960 module_put(ltt_run_filter_owner
);
961 /* Everything went fine */
969 int ltt_trace_stop(const char *trace_name
)
972 struct ltt_trace
*trace
;
975 trace
= _ltt_trace_find(trace_name
);
976 err
= _ltt_trace_stop(trace
);
980 EXPORT_SYMBOL_GPL(ltt_trace_stop
);
983 * ltt_control - Trace control in-kernel API
984 * @msg: Action to perform
985 * @trace_name: Trace on which the action must be done
986 * @trace_type: Type of trace (normal, flight, hybrid)
987 * @args: Arguments specific to the action
989 int ltt_control(enum ltt_control_msg msg
, const char *trace_name
,
990 const char *trace_type
, union ltt_control_args args
)
994 printk(KERN_ALERT
"ltt_control : trace %s\n", trace_name
);
996 case LTT_CONTROL_START
:
997 printk(KERN_DEBUG
"Start tracing %s\n", trace_name
);
998 err
= ltt_trace_start(trace_name
);
1000 case LTT_CONTROL_STOP
:
1001 printk(KERN_DEBUG
"Stop tracing %s\n", trace_name
);
1002 err
= ltt_trace_stop(trace_name
);
1004 case LTT_CONTROL_CREATE_TRACE
:
1005 printk(KERN_DEBUG
"Creating trace %s\n", trace_name
);
1006 err
= ltt_trace_create(trace_name
, trace_type
,
1007 args
.new_trace
.mode
,
1008 args
.new_trace
.subbuf_size_low
,
1009 args
.new_trace
.n_subbufs_low
,
1010 args
.new_trace
.subbuf_size_med
,
1011 args
.new_trace
.n_subbufs_med
,
1012 args
.new_trace
.subbuf_size_high
,
1013 args
.new_trace
.n_subbufs_high
);
1015 case LTT_CONTROL_DESTROY_TRACE
:
1016 printk(KERN_DEBUG
"Destroying trace %s\n", trace_name
);
1017 err
= ltt_trace_destroy(trace_name
);
1022 EXPORT_SYMBOL_GPL(ltt_control
);
1025 * ltt_filter_control - Trace filter control in-kernel API
1026 * @msg: Action to perform on the filter
1027 * @trace_name: Trace on which the action must be done
1029 int ltt_filter_control(enum ltt_filter_control_msg msg
, const char *trace_name
)
1032 struct ltt_trace
*trace
;
1034 printk(KERN_DEBUG
"ltt_filter_control : trace %s\n", trace_name
);
1036 trace
= _ltt_trace_find(trace_name
);
1037 if (trace
== NULL
) {
1039 "Trace does not exist. Cannot proxy control request\n");
1043 if (!try_module_get(ltt_filter_control_owner
)) {
1045 goto get_module_error
;
1048 case LTT_FILTER_DEFAULT_ACCEPT
:
1050 "Proxy filter default accept %s\n", trace_name
);
1051 err
= (*ltt_filter_control_functor
)(msg
, trace
);
1053 case LTT_FILTER_DEFAULT_REJECT
:
1055 "Proxy filter default reject %s\n", trace_name
);
1056 err
= (*ltt_filter_control_functor
)(msg
, trace
);
1061 module_put(ltt_filter_control_owner
);
1065 ltt_unlock_traces();
1068 EXPORT_SYMBOL_GPL(ltt_filter_control
);
1070 int __init
ltt_init(void)
1072 /* Make sure no page fault can be triggered by this module */
1074 init_timer_deferrable(<t_async_wakeup_timer
);
1078 module_init(ltt_init
)
1080 static void __exit
ltt_exit(void)
1082 struct ltt_trace
*trace
;
1083 struct list_head
*pos
, *n
;
1086 /* Stop each trace, currently being read by RCU read-side */
1087 list_for_each_entry_rcu(trace
, <t_traces
.head
, list
)
1088 _ltt_trace_stop(trace
);
1089 /* Wait for quiescent state. Readers have preemption disabled. */
1090 synchronize_trace();
1091 /* Safe iteration is now permitted. It does not have to be RCU-safe
1092 * because no readers are left. */
1093 list_for_each_safe(pos
, n
, <t_traces
.head
) {
1094 trace
= container_of(pos
, struct ltt_trace
, list
);
1095 /* _ltt_trace_destroy does a synchronize_trace() */
1096 _ltt_trace_destroy(trace
);
1097 __ltt_trace_destroy(trace
);
1099 /* free traces in pre-alloc status */
1100 list_for_each_safe(pos
, n
, <t_traces
.setup_head
) {
1101 trace
= container_of(pos
, struct ltt_trace
, list
);
1102 _ltt_trace_free(trace
);
1105 ltt_unlock_traces();
1108 module_exit(ltt_exit
)
1110 MODULE_LICENSE("GPL and additional rights");
1111 MODULE_AUTHOR("Mathieu Desnoyers");
1112 MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Tracer Kernel API");