4 * (C) Copyright 2005-2008 -
5 * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
7 * Tracing management internal kernel API. Trace buffer allocation/free, tracing
11 * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
14 * Karim Yaghmour (karim@opersys.com)
15 * Tom Zanussi (zanussi@us.ibm.com)
16 * Bob Wisniewski (bob@watson.ibm.com)
18 * Bob Wisniewski (bob@watson.ibm.com)
21 * 22/09/06, Move to the marker/probes mechanism.
22 * 19/10/05, Complete lockless mechanism.
23 * 27/05/05, Modular redesign and rewrite.
26 #include <linux/time.h>
27 #include <linux/ltt-tracer.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 static void async_wakeup(unsigned long data
);
44 static DEFINE_TIMER(ltt_async_wakeup_timer
, async_wakeup
, 0, 0);
46 /* Default callbacks for modules */
47 notrace
int ltt_filter_control_default(enum ltt_filter_control_msg msg
,
48 struct ltt_trace_struct
*trace
)
53 int ltt_statedump_default(struct ltt_trace_struct
*trace
)
58 /* Callbacks for registered modules */
60 int (*ltt_filter_control_functor
)
61 (enum ltt_filter_control_msg msg
, struct ltt_trace_struct
*trace
) =
62 ltt_filter_control_default
;
63 struct module
*ltt_filter_control_owner
;
65 /* These function pointers are protected by a trace activation check */
66 struct module
*ltt_run_filter_owner
;
67 int (*ltt_statedump_functor
)(struct ltt_trace_struct
*trace
) =
68 ltt_statedump_default
;
69 struct module
*ltt_statedump_owner
;
71 struct chan_info_struct
{
73 unsigned int def_subbufsize
;
74 unsigned int def_subbufcount
;
76 [LTT_CHANNEL_METADATA
] = {
78 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
79 LTT_DEFAULT_N_SUBBUFS_LOW
,
81 [LTT_CHANNEL_FD_STATE
] = {
83 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
84 LTT_DEFAULT_N_SUBBUFS_LOW
,
86 [LTT_CHANNEL_GLOBAL_STATE
] = {
87 LTT_GLOBAL_STATE_CHANNEL
,
88 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
89 LTT_DEFAULT_N_SUBBUFS_LOW
,
91 [LTT_CHANNEL_IRQ_STATE
] = {
92 LTT_IRQ_STATE_CHANNEL
,
93 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
94 LTT_DEFAULT_N_SUBBUFS_LOW
,
96 [LTT_CHANNEL_MODULE_STATE
] = {
97 LTT_MODULE_STATE_CHANNEL
,
98 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
99 LTT_DEFAULT_N_SUBBUFS_LOW
,
101 [LTT_CHANNEL_NETIF_STATE
] = {
102 LTT_NETIF_STATE_CHANNEL
,
103 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
104 LTT_DEFAULT_N_SUBBUFS_LOW
,
106 [LTT_CHANNEL_SOFTIRQ_STATE
] = {
107 LTT_SOFTIRQ_STATE_CHANNEL
,
108 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
109 LTT_DEFAULT_N_SUBBUFS_LOW
,
111 [LTT_CHANNEL_SWAP_STATE
] = {
112 LTT_SWAP_STATE_CHANNEL
,
113 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
114 LTT_DEFAULT_N_SUBBUFS_LOW
,
116 [LTT_CHANNEL_SYSCALL_STATE
] = {
117 LTT_SYSCALL_STATE_CHANNEL
,
118 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
119 LTT_DEFAULT_N_SUBBUFS_LOW
,
121 [LTT_CHANNEL_TASK_STATE
] = {
122 LTT_TASK_STATE_CHANNEL
,
123 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
124 LTT_DEFAULT_N_SUBBUFS_LOW
,
126 [LTT_CHANNEL_VM_STATE
] = {
127 LTT_VM_STATE_CHANNEL
,
128 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
129 LTT_DEFAULT_N_SUBBUFS_LOW
,
133 LTT_DEFAULT_SUBBUF_SIZE_MED
,
134 LTT_DEFAULT_N_SUBBUFS_MED
,
136 [LTT_CHANNEL_INPUT
] = {
138 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
139 LTT_DEFAULT_N_SUBBUFS_LOW
,
141 [LTT_CHANNEL_IPC
] = {
143 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
144 LTT_DEFAULT_N_SUBBUFS_LOW
,
146 [LTT_CHANNEL_KERNEL
] = {
148 LTT_DEFAULT_SUBBUF_SIZE_HIGH
,
149 LTT_DEFAULT_N_SUBBUFS_HIGH
,
153 LTT_DEFAULT_SUBBUF_SIZE_MED
,
154 LTT_DEFAULT_N_SUBBUFS_MED
,
156 [LTT_CHANNEL_RCU
] = {
158 LTT_DEFAULT_SUBBUF_SIZE_MED
,
159 LTT_DEFAULT_N_SUBBUFS_MED
,
161 [LTT_CHANNEL_DEFAULT
] = {
163 LTT_DEFAULT_SUBBUF_SIZE_MED
,
164 LTT_DEFAULT_N_SUBBUFS_MED
,
168 static enum ltt_channels
get_channel_type_from_name(const char *name
)
173 return LTT_CHANNEL_DEFAULT
;
175 for (i
= 0; i
< ARRAY_SIZE(chan_infos
); i
++)
176 if (chan_infos
[i
].name
&& !strcmp(name
, chan_infos
[i
].name
))
177 return (enum ltt_channels
)i
;
179 return LTT_CHANNEL_DEFAULT
;
183 * ltt_module_register - LTT module registration
185 * @function: callback to register
186 * @owner: module which owns the callback
188 * The module calling this registration function must ensure that no
189 * trap-inducing code will be executed by "function". E.g. vmalloc_sync_all()
190 * must be called between a vmalloc and the moment the memory is made visible to
191 * "function". This registration acts as a vmalloc_sync_all. Therefore, only if
192 * the module allocates virtual memory after its registration must it
193 * synchronize the TLBs.
195 int ltt_module_register(enum ltt_module_function name
, void *function
,
196 struct module
*owner
)
201 * Make sure no page fault can be triggered by the module about to be
202 * registered. We deal with this here so we don't have to call
203 * vmalloc_sync_all() in each module's init.
208 case LTT_FUNCTION_RUN_FILTER
:
209 if (ltt_run_filter_owner
!= NULL
) {
213 ltt_filter_register((ltt_run_filter_functor
)function
);
214 ltt_run_filter_owner
= owner
;
216 case LTT_FUNCTION_FILTER_CONTROL
:
217 if (ltt_filter_control_owner
!= NULL
) {
221 ltt_filter_control_functor
=
222 (int (*)(enum ltt_filter_control_msg
,
223 struct ltt_trace_struct
*))function
;
224 ltt_filter_control_owner
= owner
;
226 case LTT_FUNCTION_STATEDUMP
:
227 if (ltt_statedump_owner
!= NULL
) {
231 ltt_statedump_functor
=
232 (int (*)(struct ltt_trace_struct
*))function
;
233 ltt_statedump_owner
= owner
;
241 EXPORT_SYMBOL_GPL(ltt_module_register
);
244 * ltt_module_unregister - LTT module unregistration
247 void ltt_module_unregister(enum ltt_module_function name
)
250 case LTT_FUNCTION_RUN_FILTER
:
251 ltt_filter_unregister();
252 ltt_run_filter_owner
= NULL
;
253 /* Wait for preempt sections to finish */
256 case LTT_FUNCTION_FILTER_CONTROL
:
257 ltt_filter_control_functor
= ltt_filter_control_default
;
258 ltt_filter_control_owner
= NULL
;
260 case LTT_FUNCTION_STATEDUMP
:
261 ltt_statedump_functor
= ltt_statedump_default
;
262 ltt_statedump_owner
= NULL
;
267 EXPORT_SYMBOL_GPL(ltt_module_unregister
);
269 static LIST_HEAD(ltt_transport_list
);
272 * ltt_transport_register - LTT transport registration
273 * @transport: transport structure
275 * Registers a transport which can be used as output to extract the data out of
276 * LTTng. The module calling this registration function must ensure that no
277 * trap-inducing code will be executed by the transport functions. E.g.
278 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
279 * is made visible to the transport function. This registration acts as a
280 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
281 * after its registration must it synchronize the TLBs.
283 void ltt_transport_register(struct ltt_transport
*transport
)
286 * Make sure no page fault can be triggered by the module about to be
287 * registered. We deal with this here so we don't have to call
288 * vmalloc_sync_all() in each module's init.
293 list_add_tail(&transport
->node
, <t_transport_list
);
296 EXPORT_SYMBOL_GPL(ltt_transport_register
);
299 * ltt_transport_unregister - LTT transport unregistration
300 * @transport: transport structure
302 void ltt_transport_unregister(struct ltt_transport
*transport
)
305 list_del(&transport
->node
);
308 EXPORT_SYMBOL_GPL(ltt_transport_unregister
);
310 static inline int is_channel_overwrite(enum ltt_channels chan
,
311 enum trace_mode mode
)
314 case LTT_TRACE_NORMAL
:
316 case LTT_TRACE_FLIGHT
:
318 case LTT_CHANNEL_METADATA
:
323 case LTT_TRACE_HYBRID
:
325 case LTT_CHANNEL_KERNEL
:
328 case LTT_CHANNEL_RCU
:
329 case LTT_CHANNEL_IPC
:
330 case LTT_CHANNEL_INPUT
:
341 * ltt_write_trace_header - Write trace header
342 * @trace: Trace information
343 * @header: Memory address where the information must be written to
345 void notrace
ltt_write_trace_header(struct ltt_trace_struct
*trace
,
346 struct ltt_subbuffer_header
*header
)
348 header
->magic_number
= LTT_TRACER_MAGIC_NUMBER
;
349 header
->major_version
= LTT_TRACER_VERSION_MAJOR
;
350 header
->minor_version
= LTT_TRACER_VERSION_MINOR
;
351 header
->arch_size
= sizeof(void *);
352 header
->alignment
= ltt_get_alignment();
353 header
->start_time_sec
= trace
->start_time
.tv_sec
;
354 header
->start_time_usec
= trace
->start_time
.tv_usec
;
355 header
->start_freq
= trace
->start_freq
;
356 header
->freq_scale
= trace
->freq_scale
;
358 EXPORT_SYMBOL_GPL(ltt_write_trace_header
);
360 static void trace_async_wakeup(struct ltt_trace_struct
*trace
)
363 struct ltt_channel_struct
*chan
;
365 /* Must check each channel for pending read wakeup */
366 for (i
= 0; i
< trace
->nr_channels
; i
++) {
367 chan
= &trace
->channels
[i
];
369 trace
->ops
->wakeup_channel(chan
);
373 /* Timer to send async wakeups to the readers */
374 static void async_wakeup(unsigned long data
)
376 struct ltt_trace_struct
*trace
;
379 * PREEMPT_RT does not allow spinlocks to be taken within preempt
380 * disable sections (spinlock taken in wake_up). However, mainline won't
381 * allow mutex to be taken in interrupt context. Ugly.
382 * A proper way to do this would be to turn the timer into a
383 * periodically woken up thread, but it adds to the footprint.
385 #ifndef CONFIG_PREEMPT_RT
386 rcu_read_lock_sched();
390 list_for_each_entry_rcu(trace
, <t_traces
.head
, list
) {
391 trace_async_wakeup(trace
);
393 #ifndef CONFIG_PREEMPT_RT
394 rcu_read_unlock_sched();
399 mod_timer(<t_async_wakeup_timer
, jiffies
+ LTT_PERCPU_TIMER_INTERVAL
);
403 * _ltt_trace_find - find a trace by given name.
404 * trace_name: trace name
406 * Returns a pointer to the trace structure, NULL if not found.
408 static struct ltt_trace_struct
*_ltt_trace_find(const char *trace_name
)
410 struct ltt_trace_struct
*trace
;
412 list_for_each_entry(trace
, <t_traces
.head
, list
)
413 if (!strncmp(trace
->trace_name
, trace_name
, NAME_MAX
))
419 /* _ltt_trace_find_setup :
420 * find a trace in setup list by given name.
422 * Returns a pointer to the trace structure, NULL if not found.
424 struct ltt_trace_struct
*_ltt_trace_find_setup(const char *trace_name
)
426 struct ltt_trace_struct
*trace
;
428 list_for_each_entry(trace
, <t_traces
.setup_head
, list
)
429 if (!strncmp(trace
->trace_name
, trace_name
, NAME_MAX
))
434 EXPORT_SYMBOL_GPL(_ltt_trace_find_setup
);
437 * ltt_release_transport - Release an LTT transport
438 * @kref : reference count on the transport
440 void ltt_release_transport(struct kref
*kref
)
442 struct ltt_trace_struct
*trace
= container_of(kref
,
443 struct ltt_trace_struct
, ltt_transport_kref
);
444 trace
->ops
->remove_dirs(trace
);
446 EXPORT_SYMBOL_GPL(ltt_release_transport
);
449 * ltt_release_trace - Release a LTT trace
450 * @kref : reference count on the trace
452 void ltt_release_trace(struct kref
*kref
)
454 struct ltt_trace_struct
*trace
= container_of(kref
,
455 struct ltt_trace_struct
, kref
);
456 ltt_channels_trace_free(trace
->channels
);
459 EXPORT_SYMBOL_GPL(ltt_release_trace
);
461 static inline void prepare_chan_size_num(unsigned int *subbuf_size
,
462 unsigned int *n_subbufs
)
464 *subbuf_size
= 1 << get_count_order(*subbuf_size
);
465 *n_subbufs
= 1 << get_count_order(*n_subbufs
);
467 /* Subbuf size and number must both be power of two */
468 WARN_ON(hweight32(*subbuf_size
) != 1);
469 WARN_ON(hweight32(*n_subbufs
) != 1);
472 int _ltt_trace_setup(const char *trace_name
)
475 struct ltt_trace_struct
*new_trace
= NULL
;
478 enum ltt_channels chantype
;
480 if (_ltt_trace_find_setup(trace_name
)) {
481 printk(KERN_ERR
"LTT : Trace name %s already used.\n",
487 if (_ltt_trace_find(trace_name
)) {
488 printk(KERN_ERR
"LTT : Trace name %s already used.\n",
494 new_trace
= kzalloc(sizeof(struct ltt_trace_struct
), GFP_KERNEL
);
497 "LTT : Unable to allocate memory for trace %s\n",
502 strncpy(new_trace
->trace_name
, trace_name
, NAME_MAX
);
503 new_trace
->channels
= ltt_channels_trace_alloc(&new_trace
->nr_channels
,
505 if (!new_trace
->channels
) {
507 "LTT : Unable to allocate memory for chaninfo %s\n",
514 * Force metadata channel to active, no overwrite.
516 metadata_index
= ltt_channels_get_index_from_name("metadata");
517 WARN_ON(metadata_index
< 0);
518 new_trace
->channels
[metadata_index
].overwrite
= 0;
519 new_trace
->channels
[metadata_index
].active
= 1;
522 * Set hardcoded tracer defaults for some channels
524 for (chan
= 0; chan
< new_trace
->nr_channels
; chan
++) {
525 if (!(new_trace
->channels
[chan
].active
))
528 chantype
= get_channel_type_from_name(
529 ltt_channels_get_name_from_index(chan
));
530 new_trace
->channels
[chan
].subbuf_size
=
531 chan_infos
[chantype
].def_subbufsize
;
532 new_trace
->channels
[chan
].subbuf_cnt
=
533 chan_infos
[chantype
].def_subbufcount
;
536 list_add(&new_trace
->list
, <t_traces
.setup_head
);
544 EXPORT_SYMBOL_GPL(_ltt_trace_setup
);
547 int ltt_trace_setup(const char *trace_name
)
551 ret
= _ltt_trace_setup(trace_name
);
555 EXPORT_SYMBOL_GPL(ltt_trace_setup
);
557 /* must be called from within a traces lock. */
558 static void _ltt_trace_free(struct ltt_trace_struct
*trace
)
560 list_del(&trace
->list
);
564 int ltt_trace_set_type(const char *trace_name
, const char *trace_type
)
567 struct ltt_trace_struct
*trace
;
568 struct ltt_transport
*tran_iter
, *transport
= NULL
;
572 trace
= _ltt_trace_find_setup(trace_name
);
574 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
579 list_for_each_entry(tran_iter
, <t_transport_list
, node
) {
580 if (!strcmp(tran_iter
->name
, trace_type
)) {
581 transport
= tran_iter
;
586 printk(KERN_ERR
"LTT : Transport %s is not present.\n",
592 trace
->transport
= transport
;
598 EXPORT_SYMBOL_GPL(ltt_trace_set_type
);
600 int ltt_trace_set_channel_subbufsize(const char *trace_name
,
601 const char *channel_name
, unsigned int size
)
604 struct ltt_trace_struct
*trace
;
609 trace
= _ltt_trace_find_setup(trace_name
);
611 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
616 index
= ltt_channels_get_index_from_name(channel_name
);
618 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
622 trace
->channels
[index
].subbuf_size
= size
;
628 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufsize
);
630 int ltt_trace_set_channel_subbufcount(const char *trace_name
,
631 const char *channel_name
, unsigned int cnt
)
634 struct ltt_trace_struct
*trace
;
639 trace
= _ltt_trace_find_setup(trace_name
);
641 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
646 index
= ltt_channels_get_index_from_name(channel_name
);
648 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
652 trace
->channels
[index
].subbuf_cnt
= cnt
;
658 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufcount
);
660 int ltt_trace_set_channel_enable(const char *trace_name
,
661 const char *channel_name
, unsigned int enable
)
664 struct ltt_trace_struct
*trace
;
669 trace
= _ltt_trace_find_setup(trace_name
);
671 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
677 * Datas in metadata channel(marker info) is necessary to be able to
678 * read the trace, we always enable this channel.
680 if (!enable
&& !strcmp(channel_name
, "metadata")) {
681 printk(KERN_ERR
"LTT : Trying to disable metadata channel\n");
686 index
= ltt_channels_get_index_from_name(channel_name
);
688 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
693 trace
->channels
[index
].active
= enable
;
699 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_enable
);
701 int ltt_trace_set_channel_overwrite(const char *trace_name
,
702 const char *channel_name
, unsigned int overwrite
)
705 struct ltt_trace_struct
*trace
;
710 trace
= _ltt_trace_find_setup(trace_name
);
712 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
718 * Always put the metadata channel in non-overwrite mode :
719 * This is a very low traffic channel and it can't afford to have its
720 * data overwritten : this data (marker info) is necessary to be
721 * able to read the trace.
723 if (overwrite
&& !strcmp(channel_name
, "metadata")) {
724 printk(KERN_ERR
"LTT : Trying to set metadata channel to "
730 index
= ltt_channels_get_index_from_name(channel_name
);
732 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
737 trace
->channels
[index
].overwrite
= overwrite
;
743 EXPORT_SYMBOL_GPL(ltt_trace_set_channel_overwrite
);
745 int ltt_trace_alloc(const char *trace_name
)
748 struct ltt_trace_struct
*trace
;
749 int subbuf_size
, subbuf_cnt
;
752 const char *channel_name
;
756 trace
= _ltt_trace_find_setup(trace_name
);
758 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
763 kref_init(&trace
->kref
);
764 kref_init(&trace
->ltt_transport_kref
);
765 init_waitqueue_head(&trace
->kref_wq
);
768 trace
->freq_scale
= trace_clock_freq_scale();
770 if (!trace
->transport
) {
771 printk(KERN_ERR
"LTT : Transport is not set.\n");
773 goto transport_error
;
775 if (!try_module_get(trace
->transport
->owner
)) {
776 printk(KERN_ERR
"LTT : Can't lock transport module.\n");
778 goto transport_error
;
780 trace
->ops
= &trace
->transport
->ops
;
782 err
= trace
->ops
->create_dirs(trace
);
784 printk(KERN_ERR
"LTT : Can't create dir for trace %s.\n",
789 local_irq_save(flags
);
790 trace
->start_freq
= trace_clock_frequency();
791 trace
->start_tsc
= trace_clock_read64();
792 do_gettimeofday(&trace
->start_time
);
793 local_irq_restore(flags
);
795 for (chan
= 0; chan
< trace
->nr_channels
; chan
++) {
796 if (!(trace
->channels
[chan
].active
))
799 channel_name
= ltt_channels_get_name_from_index(chan
);
800 WARN_ON(!channel_name
);
801 subbuf_size
= trace
->channels
[chan
].subbuf_size
;
802 subbuf_cnt
= trace
->channels
[chan
].subbuf_cnt
;
803 prepare_chan_size_num(&subbuf_size
, &subbuf_cnt
);
804 err
= trace
->ops
->create_channel(trace_name
, trace
,
805 trace
->dentry
.trace_root
,
807 &trace
->channels
[chan
],
810 trace
->channels
[chan
].overwrite
);
812 printk(KERN_ERR
"LTT : Can't create channel %s.\n",
814 goto create_channel_error
;
818 list_del(&trace
->list
);
819 if (list_empty(<t_traces
.head
)) {
820 mod_timer(<t_async_wakeup_timer
,
821 jiffies
+ LTT_PERCPU_TIMER_INTERVAL
);
822 set_kernel_trace_flag_all_tasks();
824 list_add_rcu(&trace
->list
, <t_traces
.head
);
831 create_channel_error
:
832 for (chan
--; chan
>= 0; chan
--)
833 if (trace
->channels
[chan
].active
)
834 trace
->ops
->remove_channel(&trace
->channels
[chan
]);
837 module_put(trace
->transport
->owner
);
844 EXPORT_SYMBOL_GPL(ltt_trace_alloc
);
847 * It is worked as a wrapper for current version of ltt_control.ko.
848 * We will make a new ltt_control based on debugfs, and control each channel's
851 static int ltt_trace_create(const char *trace_name
, const char *trace_type
,
852 enum trace_mode mode
,
853 unsigned int subbuf_size_low
, unsigned int n_subbufs_low
,
854 unsigned int subbuf_size_med
, unsigned int n_subbufs_med
,
855 unsigned int subbuf_size_high
, unsigned int n_subbufs_high
)
859 err
= ltt_trace_setup(trace_name
);
860 if (IS_ERR_VALUE(err
))
863 err
= ltt_trace_set_type(trace_name
, trace_type
);
864 if (IS_ERR_VALUE(err
))
867 err
= ltt_trace_alloc(trace_name
);
868 if (IS_ERR_VALUE(err
))
874 /* Must be called while sure that trace is in the list. */
875 static int _ltt_trace_destroy(struct ltt_trace_struct
*trace
)
885 "LTT : Can't destroy trace %s : tracer is active\n",
890 /* Everything went fine */
891 list_del_rcu(&trace
->list
);
893 if (list_empty(<t_traces
.head
)) {
894 clear_kernel_trace_flag_all_tasks();
896 * We stop the asynchronous delivery of reader wakeup, but
897 * we must make one last check for reader wakeups pending
898 * later in __ltt_trace_destroy.
900 del_timer_sync(<t_async_wakeup_timer
);
910 /* Sleepable part of the destroy */
911 static void __ltt_trace_destroy(struct ltt_trace_struct
*trace
)
914 struct ltt_channel_struct
*chan
;
916 for (i
= 0; i
< trace
->nr_channels
; i
++) {
917 chan
= &trace
->channels
[i
];
919 trace
->ops
->finish_channel(chan
);
922 flush_scheduled_work();
925 * The currently destroyed trace is not in the trace list anymore,
926 * so it's safe to call the async wakeup ourself. It will deliver
927 * the last subbuffers.
929 trace_async_wakeup(trace
);
931 for (i
= 0; i
< trace
->nr_channels
; i
++) {
932 chan
= &trace
->channels
[i
];
934 trace
->ops
->remove_channel(chan
);
937 kref_put(&trace
->ltt_transport_kref
, ltt_release_transport
);
939 module_put(trace
->transport
->owner
);
942 * Wait for lttd readers to release the files, therefore making sure
943 * the last subbuffers have been read.
945 if (atomic_read(&trace
->kref
.refcount
) > 1) {
947 __wait_event_interruptible(trace
->kref_wq
,
948 (atomic_read(&trace
->kref
.refcount
) == 1), ret
);
950 kref_put(&trace
->kref
, ltt_release_trace
);
953 int ltt_trace_destroy(const char *trace_name
)
956 struct ltt_trace_struct
*trace
;
960 trace
= _ltt_trace_find(trace_name
);
962 err
= _ltt_trace_destroy(trace
);
968 __ltt_trace_destroy(trace
);
974 trace
= _ltt_trace_find_setup(trace_name
);
976 _ltt_trace_free(trace
);
988 EXPORT_SYMBOL_GPL(ltt_trace_destroy
);
990 /* must be called from within a traces lock. */
991 static int _ltt_trace_start(struct ltt_trace_struct
*trace
)
1000 printk(KERN_INFO
"LTT : Tracing already active for trace %s\n",
1002 if (!try_module_get(ltt_run_filter_owner
)) {
1004 printk(KERN_ERR
"LTT : Can't lock filter module.\n");
1005 goto get_ltt_run_filter_error
;
1008 /* Read by trace points without protection : be careful */
1009 ltt_traces
.num_active_traces
++;
1012 /* error handling */
1013 get_ltt_run_filter_error
:
1018 int ltt_trace_start(const char *trace_name
)
1021 struct ltt_trace_struct
*trace
;
1025 trace
= _ltt_trace_find(trace_name
);
1026 err
= _ltt_trace_start(trace
);
1030 ltt_unlock_traces();
1033 * Call the kernel state dump.
1034 * Events will be mixed with real kernel events, it's ok.
1035 * Notice that there is no protection on the trace : that's exactly
1036 * why we iterate on the list and check for trace equality instead of
1037 * directly using this trace handle inside the logging function.
1040 ltt_dump_marker_state(trace
);
1042 if (!try_module_get(ltt_statedump_owner
)) {
1045 "LTT : Can't lock state dump module.\n");
1047 ltt_statedump_functor(trace
);
1048 module_put(ltt_statedump_owner
);
1053 /* Error handling */
1055 ltt_unlock_traces();
1058 EXPORT_SYMBOL_GPL(ltt_trace_start
);
1060 /* must be called from within traces lock */
1061 static int _ltt_trace_stop(struct ltt_trace_struct
*trace
)
1065 if (trace
== NULL
) {
1070 printk(KERN_INFO
"LTT : Tracing not active for trace %s\n",
1072 if (trace
->active
) {
1074 ltt_traces
.num_active_traces
--;
1075 synchronize_sched(); /* Wait for each tracing to be finished */
1077 module_put(ltt_run_filter_owner
);
1078 /* Everything went fine */
1081 /* Error handling */
1086 int ltt_trace_stop(const char *trace_name
)
1089 struct ltt_trace_struct
*trace
;
1092 trace
= _ltt_trace_find(trace_name
);
1093 err
= _ltt_trace_stop(trace
);
1094 ltt_unlock_traces();
1097 EXPORT_SYMBOL_GPL(ltt_trace_stop
);
1100 * ltt_control - Trace control in-kernel API
1101 * @msg: Action to perform
1102 * @trace_name: Trace on which the action must be done
1103 * @trace_type: Type of trace (normal, flight, hybrid)
1104 * @args: Arguments specific to the action
1106 int ltt_control(enum ltt_control_msg msg
, const char *trace_name
,
1107 const char *trace_type
, union ltt_control_args args
)
1111 printk(KERN_ALERT
"ltt_control : trace %s\n", trace_name
);
1113 case LTT_CONTROL_START
:
1114 printk(KERN_DEBUG
"Start tracing %s\n", trace_name
);
1115 err
= ltt_trace_start(trace_name
);
1117 case LTT_CONTROL_STOP
:
1118 printk(KERN_DEBUG
"Stop tracing %s\n", trace_name
);
1119 err
= ltt_trace_stop(trace_name
);
1121 case LTT_CONTROL_CREATE_TRACE
:
1122 printk(KERN_DEBUG
"Creating trace %s\n", trace_name
);
1123 err
= ltt_trace_create(trace_name
, trace_type
,
1124 args
.new_trace
.mode
,
1125 args
.new_trace
.subbuf_size_low
,
1126 args
.new_trace
.n_subbufs_low
,
1127 args
.new_trace
.subbuf_size_med
,
1128 args
.new_trace
.n_subbufs_med
,
1129 args
.new_trace
.subbuf_size_high
,
1130 args
.new_trace
.n_subbufs_high
);
1132 case LTT_CONTROL_DESTROY_TRACE
:
1133 printk(KERN_DEBUG
"Destroying trace %s\n", trace_name
);
1134 err
= ltt_trace_destroy(trace_name
);
1139 EXPORT_SYMBOL_GPL(ltt_control
);
1142 * ltt_filter_control - Trace filter control in-kernel API
1143 * @msg: Action to perform on the filter
1144 * @trace_name: Trace on which the action must be done
1146 int ltt_filter_control(enum ltt_filter_control_msg msg
, const char *trace_name
)
1149 struct ltt_trace_struct
*trace
;
1151 printk(KERN_DEBUG
"ltt_filter_control : trace %s\n", trace_name
);
1153 trace
= _ltt_trace_find(trace_name
);
1154 if (trace
== NULL
) {
1156 "Trace does not exist. Cannot proxy control request\n");
1160 if (!try_module_get(ltt_filter_control_owner
)) {
1162 goto get_module_error
;
1165 case LTT_FILTER_DEFAULT_ACCEPT
:
1167 "Proxy filter default accept %s\n", trace_name
);
1168 err
= (*ltt_filter_control_functor
)(msg
, trace
);
1170 case LTT_FILTER_DEFAULT_REJECT
:
1172 "Proxy filter default reject %s\n", trace_name
);
1173 err
= (*ltt_filter_control_functor
)(msg
, trace
);
1178 module_put(ltt_filter_control_owner
);
1182 ltt_unlock_traces();
1185 EXPORT_SYMBOL_GPL(ltt_filter_control
);
1187 int __init
ltt_init(void)
1189 /* Make sure no page fault can be triggered by this module */
1194 module_init(ltt_init
)
1196 static void __exit
ltt_exit(void)
1198 struct ltt_trace_struct
*trace
;
1199 struct list_head
*pos
, *n
;
1202 /* Stop each trace, currently being read by RCU read-side */
1203 list_for_each_entry_rcu(trace
, <t_traces
.head
, list
)
1204 _ltt_trace_stop(trace
);
1205 /* Wait for quiescent state. Readers have preemption disabled. */
1206 synchronize_sched();
1207 /* Safe iteration is now permitted. It does not have to be RCU-safe
1208 * because no readers are left. */
1209 list_for_each_safe(pos
, n
, <t_traces
.head
) {
1210 trace
= container_of(pos
, struct ltt_trace_struct
, list
);
1211 /* _ltt_trace_destroy does a synchronize_sched() */
1212 _ltt_trace_destroy(trace
);
1213 __ltt_trace_destroy(trace
);
1215 /* free traces in pre-alloc status */
1216 list_for_each_safe(pos
, n
, <t_traces
.setup_head
) {
1217 trace
= container_of(pos
, struct ltt_trace_struct
, list
);
1218 _ltt_trace_free(trace
);
1221 ltt_unlock_traces();
1224 module_exit(ltt_exit
)
1226 MODULE_LICENSE("GPL");
1227 MODULE_AUTHOR("Mathieu Desnoyers");
1228 MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Tracer Kernel API");