4 * (C) Copyright 2005-2008 -
5 * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * Tracing management internal kernel API. Trace buffer allocation/free, tracing
25 * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
28 * Karim Yaghmour (karim@opersys.com)
29 * Tom Zanussi (zanussi@us.ibm.com)
30 * Bob Wisniewski (bob@watson.ibm.com)
32 * Bob Wisniewski (bob@watson.ibm.com)
35 * 22/09/06, Move to the marker/probes mechanism.
36 * 19/10/05, Complete lockless mechanism.
37 * 27/05/05, Modular redesign and rewrite.
40 //ust// #include <linux/time.h>
41 //ust// #include <linux/ltt-tracer.h>
42 //ust// #include <linux/module.h>
43 //ust// #include <linux/string.h>
44 //ust// #include <linux/slab.h>
45 //ust// #include <linux/init.h>
46 //ust// #include <linux/rcupdate.h>
47 //ust// #include <linux/sched.h>
48 //ust// #include <linux/bitops.h>
49 //ust// #include <linux/fs.h>
50 //ust// #include <linux/cpu.h>
51 //ust// #include <linux/kref.h>
52 //ust// #include <linux/delay.h>
53 //ust// #include <linux/vmalloc.h>
54 //ust// #include <asm/atomic.h>
56 #include <urcu/rculist.h>
58 #include <ust/kernelcompat.h>
59 #include "tracercore.h"
63 //ust// static void async_wakeup(unsigned long data);
65 //ust// static DEFINE_TIMER(ltt_async_wakeup_timer, async_wakeup, 0, 0);
67 /* Default callbacks for modules */
68 notrace
int ltt_filter_control_default(enum ltt_filter_control_msg msg
,
69 struct ltt_trace_struct
*trace
)
74 int ltt_statedump_default(struct ltt_trace_struct
*trace
)
79 /* Callbacks for registered modules */
81 int (*ltt_filter_control_functor
)
82 (enum ltt_filter_control_msg msg
, struct ltt_trace_struct
*trace
) =
83 ltt_filter_control_default
;
84 struct module
*ltt_filter_control_owner
;
86 /* These function pointers are protected by a trace activation check */
87 struct module
*ltt_run_filter_owner
;
88 int (*ltt_statedump_functor
)(struct ltt_trace_struct
*trace
) =
89 ltt_statedump_default
;
90 struct module
*ltt_statedump_owner
;
92 struct chan_info_struct
{
94 unsigned int def_subbufsize
;
95 unsigned int def_subbufcount
;
97 [LTT_CHANNEL_METADATA
] = {
99 LTT_DEFAULT_SUBBUF_SIZE_LOW
,
100 LTT_DEFAULT_N_SUBBUFS_LOW
,
102 [LTT_CHANNEL_UST
] = {
104 LTT_DEFAULT_SUBBUF_SIZE_HIGH
,
105 LTT_DEFAULT_N_SUBBUFS_HIGH
,
109 static enum ltt_channels
get_channel_type_from_name(const char *name
)
114 return LTT_CHANNEL_UST
;
116 for (i
= 0; i
< ARRAY_SIZE(chan_infos
); i
++)
117 if (chan_infos
[i
].name
&& !strcmp(name
, chan_infos
[i
].name
))
118 return (enum ltt_channels
)i
;
120 return LTT_CHANNEL_UST
;
124 * ltt_module_register - LTT module registration
126 * @function: callback to register
127 * @owner: module which owns the callback
129 * The module calling this registration function must ensure that no
130 * trap-inducing code will be executed by "function". E.g. vmalloc_sync_all()
131 * must be called between a vmalloc and the moment the memory is made visible to
132 * "function". This registration acts as a vmalloc_sync_all. Therefore, only if
133 * the module allocates virtual memory after its registration must it
134 * synchronize the TLBs.
136 //ust// int ltt_module_register(enum ltt_module_function name, void *function,
137 //ust// struct module *owner)
142 //ust// * Make sure no page fault can be triggered by the module about to be
143 //ust// * registered. We deal with this here so we don't have to call
144 //ust// * vmalloc_sync_all() in each module's init.
146 //ust// vmalloc_sync_all();
148 //ust// switch (name) {
149 //ust// case LTT_FUNCTION_RUN_FILTER:
150 //ust// if (ltt_run_filter_owner != NULL) {
151 //ust// ret = -EEXIST;
154 //ust// ltt_filter_register((ltt_run_filter_functor)function);
155 //ust// ltt_run_filter_owner = owner;
157 //ust// case LTT_FUNCTION_FILTER_CONTROL:
158 //ust// if (ltt_filter_control_owner != NULL) {
159 //ust// ret = -EEXIST;
162 //ust// ltt_filter_control_functor =
163 //ust// (int (*)(enum ltt_filter_control_msg,
164 //ust// struct ltt_trace_struct *))function;
165 //ust// ltt_filter_control_owner = owner;
167 //ust// case LTT_FUNCTION_STATEDUMP:
168 //ust// if (ltt_statedump_owner != NULL) {
169 //ust// ret = -EEXIST;
172 //ust// ltt_statedump_functor =
173 //ust// (int (*)(struct ltt_trace_struct *))function;
174 //ust// ltt_statedump_owner = owner;
182 //ust// EXPORT_SYMBOL_GPL(ltt_module_register);
185 * ltt_module_unregister - LTT module unregistration
188 //ust// void ltt_module_unregister(enum ltt_module_function name)
190 //ust// switch (name) {
191 //ust// case LTT_FUNCTION_RUN_FILTER:
192 //ust// ltt_filter_unregister();
193 //ust// ltt_run_filter_owner = NULL;
194 //ust// /* Wait for preempt sections to finish */
195 //ust// synchronize_sched();
197 //ust// case LTT_FUNCTION_FILTER_CONTROL:
198 //ust// ltt_filter_control_functor = ltt_filter_control_default;
199 //ust// ltt_filter_control_owner = NULL;
201 //ust// case LTT_FUNCTION_STATEDUMP:
202 //ust// ltt_statedump_functor = ltt_statedump_default;
203 //ust// ltt_statedump_owner = NULL;
208 //ust// EXPORT_SYMBOL_GPL(ltt_module_unregister);
210 static LIST_HEAD(ltt_transport_list
);
213 * ltt_transport_register - LTT transport registration
214 * @transport: transport structure
216 * Registers a transport which can be used as output to extract the data out of
217 * LTTng. The module calling this registration function must ensure that no
218 * trap-inducing code will be executed by the transport functions. E.g.
219 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
220 * is made visible to the transport function. This registration acts as a
221 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
222 * after its registration must it synchronize the TLBs.
224 void ltt_transport_register(struct ltt_transport
*transport
)
227 * Make sure no page fault can be triggered by the module about to be
228 * registered. We deal with this here so we don't have to call
229 * vmalloc_sync_all() in each module's init.
231 //ust// vmalloc_sync_all();
234 list_add_tail(&transport
->node
, <t_transport_list
);
237 //ust// EXPORT_SYMBOL_GPL(ltt_transport_register);
240 * ltt_transport_unregister - LTT transport unregistration
241 * @transport: transport structure
243 void ltt_transport_unregister(struct ltt_transport
*transport
)
246 list_del(&transport
->node
);
249 //ust// EXPORT_SYMBOL_GPL(ltt_transport_unregister);
251 static inline int is_channel_overwrite(enum ltt_channels chan
,
252 enum trace_mode mode
)
255 case LTT_TRACE_NORMAL
:
257 case LTT_TRACE_FLIGHT
:
259 case LTT_CHANNEL_METADATA
:
264 case LTT_TRACE_HYBRID
:
266 case LTT_CHANNEL_METADATA
:
277 * ltt_write_trace_header - Write trace header
278 * @trace: Trace information
279 * @header: Memory address where the information must be written to
281 void notrace
ltt_write_trace_header(struct ltt_trace_struct
*trace
,
282 struct ltt_subbuffer_header
*header
)
284 header
->magic_number
= LTT_TRACER_MAGIC_NUMBER
;
285 header
->major_version
= LTT_TRACER_VERSION_MAJOR
;
286 header
->minor_version
= LTT_TRACER_VERSION_MINOR
;
287 header
->arch_size
= sizeof(void *);
288 header
->alignment
= ltt_get_alignment();
289 header
->start_time_sec
= trace
->start_time
.tv_sec
;
290 header
->start_time_usec
= trace
->start_time
.tv_usec
;
291 header
->start_freq
= trace
->start_freq
;
292 header
->freq_scale
= trace
->freq_scale
;
294 //ust// EXPORT_SYMBOL_GPL(ltt_write_trace_header);
296 static void trace_async_wakeup(struct ltt_trace_struct
*trace
)
299 struct ust_channel
*chan
;
301 /* Must check each channel for pending read wakeup */
302 for (i
= 0; i
< trace
->nr_channels
; i
++) {
303 chan
= &trace
->channels
[i
];
305 trace
->ops
->wakeup_channel(chan
);
309 //ust// /* Timer to send async wakeups to the readers */
310 //ust// static void async_wakeup(unsigned long data)
312 //ust// struct ltt_trace_struct *trace;
315 //ust// * PREEMPT_RT does not allow spinlocks to be taken within preempt
316 //ust// * disable sections (spinlock taken in wake_up). However, mainline won't
317 //ust// * allow mutex to be taken in interrupt context. Ugly.
318 //ust// * A proper way to do this would be to turn the timer into a
319 //ust// * periodically woken up thread, but it adds to the footprint.
321 //ust// #ifndef CONFIG_PREEMPT_RT
322 //ust// rcu_read_lock_sched();
324 //ust// ltt_lock_traces();
326 //ust// list_for_each_entry_rcu(trace, <t_traces.head, list) {
327 //ust// trace_async_wakeup(trace);
329 //ust// #ifndef CONFIG_PREEMPT_RT
330 //ust// rcu_read_unlock_sched();
332 //ust// ltt_unlock_traces();
335 //ust// mod_timer(<t_async_wakeup_timer, jiffies + LTT_PERCPU_TIMER_INTERVAL);
339 * _ltt_trace_find - find a trace by given name.
340 * trace_name: trace name
342 * Returns a pointer to the trace structure, NULL if not found.
344 struct ltt_trace_struct
*_ltt_trace_find(const char *trace_name
)
346 struct ltt_trace_struct
*trace
;
348 list_for_each_entry(trace
, <t_traces
.head
, list
)
349 if (!strncmp(trace
->trace_name
, trace_name
, NAME_MAX
))
355 /* _ltt_trace_find_setup :
356 * find a trace in setup list by given name.
358 * Returns a pointer to the trace structure, NULL if not found.
360 struct ltt_trace_struct
*_ltt_trace_find_setup(const char *trace_name
)
362 struct ltt_trace_struct
*trace
;
364 list_for_each_entry(trace
, <t_traces
.setup_head
, list
)
365 if (!strncmp(trace
->trace_name
, trace_name
, NAME_MAX
))
370 //ust// EXPORT_SYMBOL_GPL(_ltt_trace_find_setup);
373 * ltt_release_transport - Release an LTT transport
374 * @kref : reference count on the transport
376 void ltt_release_transport(struct kref
*kref
)
378 //ust// struct ltt_trace_struct *trace = container_of(kref,
379 //ust// struct ltt_trace_struct, ltt_transport_kref);
380 //ust// trace->ops->remove_dirs(trace);
382 //ust// EXPORT_SYMBOL_GPL(ltt_release_transport);
385 * ltt_release_trace - Release a LTT trace
386 * @kref : reference count on the trace
388 void ltt_release_trace(struct kref
*kref
)
390 struct ltt_trace_struct
*trace
= container_of(kref
,
391 struct ltt_trace_struct
, kref
);
392 ltt_channels_trace_free(trace
->channels
);
395 //ust// EXPORT_SYMBOL_GPL(ltt_release_trace);
397 static inline void prepare_chan_size_num(unsigned int *subbuf_size
,
398 unsigned int *n_subbufs
)
400 *subbuf_size
= 1 << get_count_order(*subbuf_size
);
401 *n_subbufs
= 1 << get_count_order(*n_subbufs
);
403 /* Subbuf size and number must both be power of two */
404 WARN_ON(hweight32(*subbuf_size
) != 1);
405 WARN_ON(hweight32(*n_subbufs
) != 1);
408 int _ltt_trace_setup(const char *trace_name
)
411 struct ltt_trace_struct
*new_trace
= NULL
;
414 enum ltt_channels chantype
;
416 if (_ltt_trace_find_setup(trace_name
)) {
417 printk(KERN_ERR
"LTT : Trace name %s already used.\n",
423 if (_ltt_trace_find(trace_name
)) {
424 printk(KERN_ERR
"LTT : Trace name %s already used.\n",
430 new_trace
= kzalloc(sizeof(struct ltt_trace_struct
), GFP_KERNEL
);
433 "LTT : Unable to allocate memory for trace %s\n",
438 strncpy(new_trace
->trace_name
, trace_name
, NAME_MAX
);
439 new_trace
->channels
= ltt_channels_trace_alloc(&new_trace
->nr_channels
,
441 if (!new_trace
->channels
) {
443 "LTT : Unable to allocate memory for chaninfo %s\n",
450 * Force metadata channel to active, no overwrite.
452 metadata_index
= ltt_channels_get_index_from_name("metadata");
453 WARN_ON(metadata_index
< 0);
454 new_trace
->channels
[metadata_index
].overwrite
= 0;
455 new_trace
->channels
[metadata_index
].active
= 1;
458 * Set hardcoded tracer defaults for some channels
460 for (chan
= 0; chan
< new_trace
->nr_channels
; chan
++) {
461 if (!(new_trace
->channels
[chan
].active
))
464 chantype
= get_channel_type_from_name(
465 ltt_channels_get_name_from_index(chan
));
466 new_trace
->channels
[chan
].subbuf_size
=
467 chan_infos
[chantype
].def_subbufsize
;
468 new_trace
->channels
[chan
].subbuf_cnt
=
469 chan_infos
[chantype
].def_subbufcount
;
472 list_add(&new_trace
->list
, <t_traces
.setup_head
);
480 //ust// EXPORT_SYMBOL_GPL(_ltt_trace_setup);
483 int ltt_trace_setup(const char *trace_name
)
487 ret
= _ltt_trace_setup(trace_name
);
491 //ust// EXPORT_SYMBOL_GPL(ltt_trace_setup);
493 /* must be called from within a traces lock. */
494 static void _ltt_trace_free(struct ltt_trace_struct
*trace
)
496 list_del(&trace
->list
);
500 int ltt_trace_set_type(const char *trace_name
, const char *trace_type
)
503 struct ltt_trace_struct
*trace
;
504 struct ltt_transport
*tran_iter
, *transport
= NULL
;
508 trace
= _ltt_trace_find_setup(trace_name
);
510 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
515 list_for_each_entry(tran_iter
, <t_transport_list
, node
) {
516 if (!strcmp(tran_iter
->name
, trace_type
)) {
517 transport
= tran_iter
;
522 printk(KERN_ERR
"LTT : Transport %s is not present.\n",
528 trace
->transport
= transport
;
534 //ust// EXPORT_SYMBOL_GPL(ltt_trace_set_type);
536 int ltt_trace_set_channel_subbufsize(const char *trace_name
,
537 const char *channel_name
, unsigned int size
)
540 struct ltt_trace_struct
*trace
;
545 trace
= _ltt_trace_find_setup(trace_name
);
547 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
552 index
= ltt_channels_get_index_from_name(channel_name
);
554 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
558 trace
->channels
[index
].subbuf_size
= size
;
564 //ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufsize);
566 int ltt_trace_set_channel_subbufcount(const char *trace_name
,
567 const char *channel_name
, unsigned int cnt
)
570 struct ltt_trace_struct
*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
->channels
[index
].subbuf_cnt
= cnt
;
594 //ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufcount);
596 int ltt_trace_set_channel_enable(const char *trace_name
,
597 const char *channel_name
, unsigned int enable
)
600 struct ltt_trace_struct
*trace
;
605 trace
= _ltt_trace_find_setup(trace_name
);
607 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
613 * Datas in metadata channel(marker info) is necessary to be able to
614 * read the trace, we always enable this channel.
616 if (!enable
&& !strcmp(channel_name
, "metadata")) {
617 printk(KERN_ERR
"LTT : Trying to disable metadata channel\n");
622 index
= ltt_channels_get_index_from_name(channel_name
);
624 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
629 trace
->channels
[index
].active
= enable
;
635 //ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_enable);
637 int ltt_trace_set_channel_overwrite(const char *trace_name
,
638 const char *channel_name
, unsigned int overwrite
)
641 struct ltt_trace_struct
*trace
;
646 trace
= _ltt_trace_find_setup(trace_name
);
648 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
654 * Always put the metadata channel in non-overwrite mode :
655 * This is a very low traffic channel and it can't afford to have its
656 * data overwritten : this data (marker info) is necessary to be
657 * able to read the trace.
659 if (overwrite
&& !strcmp(channel_name
, "metadata")) {
660 printk(KERN_ERR
"LTT : Trying to set metadata channel to "
666 index
= ltt_channels_get_index_from_name(channel_name
);
668 printk(KERN_ERR
"LTT : Channel %s not found\n", channel_name
);
673 trace
->channels
[index
].overwrite
= overwrite
;
679 //ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_overwrite);
681 int ltt_trace_alloc(const char *trace_name
)
684 struct ltt_trace_struct
*trace
;
685 unsigned int subbuf_size
, subbuf_cnt
;
686 //ust// unsigned long flags;
688 const char *channel_name
;
692 trace
= _ltt_trace_find_setup(trace_name
);
694 printk(KERN_ERR
"LTT : Trace not found %s\n", trace_name
);
699 kref_init(&trace
->kref
);
700 kref_init(&trace
->ltt_transport_kref
);
701 //ust// init_waitqueue_head(&trace->kref_wq);
703 //ust// get_trace_clock();
704 trace
->freq_scale
= trace_clock_freq_scale();
706 if (!trace
->transport
) {
707 printk(KERN_ERR
"LTT : Transport is not set.\n");
709 goto transport_error
;
711 //ust// if (!try_module_get(trace->transport->owner)) {
712 //ust// printk(KERN_ERR "LTT : Can't lock transport module.\n");
713 //ust// err = -ENODEV;
714 //ust// goto transport_error;
716 trace
->ops
= &trace
->transport
->ops
;
718 //ust// err = trace->ops->create_dirs(trace);
720 //ust// printk(KERN_ERR "LTT : Can't create dir for trace %s.\n",
722 //ust// goto dirs_error;
725 //ust// local_irq_save(flags);
726 trace
->start_freq
= trace_clock_frequency();
727 trace
->start_tsc
= trace_clock_read64();
728 gettimeofday(&trace
->start_time
, NULL
); //ust// changed
729 //ust// local_irq_restore(flags);
731 for (chan
= 0; chan
< trace
->nr_channels
; chan
++) {
732 if (!(trace
->channels
[chan
].active
))
735 channel_name
= ltt_channels_get_name_from_index(chan
);
736 WARN_ON(!channel_name
);
737 subbuf_size
= trace
->channels
[chan
].subbuf_size
;
738 subbuf_cnt
= trace
->channels
[chan
].subbuf_cnt
;
739 prepare_chan_size_num(&subbuf_size
, &subbuf_cnt
);
740 err
= trace
->ops
->create_channel(trace_name
, trace
,
742 &trace
->channels
[chan
],
745 trace
->channels
[chan
].overwrite
);
747 printk(KERN_ERR
"LTT : Can't create channel %s.\n",
749 goto create_channel_error
;
753 list_del(&trace
->list
);
754 //ust// if (list_empty(<t_traces.head)) {
755 //ust// mod_timer(<t_async_wakeup_timer,
756 //ust// jiffies + LTT_PERCPU_TIMER_INTERVAL);
757 //ust// set_kernel_trace_flag_all_tasks();
759 list_add_rcu(&trace
->list
, <t_traces
.head
);
760 //ust// synchronize_sched();
766 create_channel_error
:
767 for (chan
--; chan
>= 0; chan
--)
768 if (trace
->channels
[chan
].active
)
769 trace
->ops
->remove_channel(&trace
->channels
[chan
]);
772 //ust// module_put(trace->transport->owner);
774 //ust// put_trace_clock();
779 //ust// EXPORT_SYMBOL_GPL(ltt_trace_alloc);
782 * It is worked as a wrapper for current version of ltt_control.ko.
783 * We will make a new ltt_control based on debugfs, and control each channel's
786 //ust// static int ltt_trace_create(const char *trace_name, const char *trace_type,
787 //ust// enum trace_mode mode,
788 //ust// unsigned int subbuf_size_low, unsigned int n_subbufs_low,
789 //ust// unsigned int subbuf_size_med, unsigned int n_subbufs_med,
790 //ust// unsigned int subbuf_size_high, unsigned int n_subbufs_high)
794 //ust// err = ltt_trace_setup(trace_name);
795 //ust// if (IS_ERR_VALUE(err))
798 //ust// err = ltt_trace_set_type(trace_name, trace_type);
799 //ust// if (IS_ERR_VALUE(err))
802 //ust// err = ltt_trace_alloc(trace_name);
803 //ust// if (IS_ERR_VALUE(err))
809 /* Must be called while sure that trace is in the list. */
810 static int _ltt_trace_destroy(struct ltt_trace_struct
*trace
)
820 "LTT : Can't destroy trace %s : tracer is active\n",
825 /* Everything went fine */
826 list_del_rcu(&trace
->list
);
828 if (list_empty(<t_traces
.head
)) {
829 //ust// clear_kernel_trace_flag_all_tasks();
831 * We stop the asynchronous delivery of reader wakeup, but
832 * we must make one last check for reader wakeups pending
833 * later in __ltt_trace_destroy.
835 //ust// del_timer_sync(<t_async_wakeup_timer);
845 /* Sleepable part of the destroy */
846 static void __ltt_trace_destroy(struct ltt_trace_struct
*trace
)
849 struct ust_channel
*chan
;
851 for (i
= 0; i
< trace
->nr_channels
; i
++) {
852 chan
= &trace
->channels
[i
];
854 trace
->ops
->finish_channel(chan
);
857 return; /* FIXME: temporary for ust */
858 //ust// flush_scheduled_work();
861 * The currently destroyed trace is not in the trace list anymore,
862 * so it's safe to call the async wakeup ourself. It will deliver
863 * the last subbuffers.
865 trace_async_wakeup(trace
);
867 for (i
= 0; i
< trace
->nr_channels
; i
++) {
868 chan
= &trace
->channels
[i
];
870 trace
->ops
->remove_channel(chan
);
873 kref_put(&trace
->ltt_transport_kref
, ltt_release_transport
);
875 //ust// module_put(trace->transport->owner);
878 * Wait for lttd readers to release the files, therefore making sure
879 * the last subbuffers have been read.
881 //ust// if (atomic_read(&trace->kref.refcount) > 1) {
883 //ust// __wait_event_interruptible(trace->kref_wq,
884 //ust// (atomic_read(&trace->kref.refcount) == 1), ret);
886 kref_put(&trace
->kref
, ltt_release_trace
);
889 int ltt_trace_destroy(const char *trace_name
)
892 struct ltt_trace_struct
*trace
;
896 trace
= _ltt_trace_find(trace_name
);
898 err
= _ltt_trace_destroy(trace
);
904 __ltt_trace_destroy(trace
);
905 //ust// put_trace_clock();
910 trace
= _ltt_trace_find_setup(trace_name
);
912 _ltt_trace_free(trace
);
924 //ust// EXPORT_SYMBOL_GPL(ltt_trace_destroy);
926 /* must be called from within a traces lock. */
927 static int _ltt_trace_start(struct ltt_trace_struct
*trace
)
936 printk(KERN_INFO
"LTT : Tracing already active for trace %s\n",
938 //ust// if (!try_module_get(ltt_run_filter_owner)) {
939 //ust// err = -ENODEV;
940 //ust// printk(KERN_ERR "LTT : Can't lock filter module.\n");
941 //ust// goto get_ltt_run_filter_error;
944 /* Read by trace points without protection : be careful */
945 ltt_traces
.num_active_traces
++;
949 //ust// get_ltt_run_filter_error:
954 int ltt_trace_start(const char *trace_name
)
957 struct ltt_trace_struct
*trace
;
961 trace
= _ltt_trace_find(trace_name
);
962 err
= _ltt_trace_start(trace
);
969 * Call the kernel state dump.
970 * Events will be mixed with real kernel events, it's ok.
971 * Notice that there is no protection on the trace : that's exactly
972 * why we iterate on the list and check for trace equality instead of
973 * directly using this trace handle inside the logging function.
976 ltt_dump_marker_state(trace
);
978 //ust// if (!try_module_get(ltt_statedump_owner)) {
979 //ust// err = -ENODEV;
980 //ust// printk(KERN_ERR
981 //ust// "LTT : Can't lock state dump module.\n");
983 ltt_statedump_functor(trace
);
984 //ust// module_put(ltt_statedump_owner);
994 //ust// EXPORT_SYMBOL_GPL(ltt_trace_start);
996 /* must be called from within traces lock */
997 static int _ltt_trace_stop(struct ltt_trace_struct
*trace
)
1001 if (trace
== NULL
) {
1006 printk(KERN_INFO
"LTT : Tracing not active for trace %s\n",
1008 if (trace
->active
) {
1010 ltt_traces
.num_active_traces
--;
1011 //ust// synchronize_sched(); /* Wait for each tracing to be finished */
1013 //ust// module_put(ltt_run_filter_owner);
1014 /* Everything went fine */
1017 /* Error handling */
1022 int ltt_trace_stop(const char *trace_name
)
1025 struct ltt_trace_struct
*trace
;
1028 trace
= _ltt_trace_find(trace_name
);
1029 err
= _ltt_trace_stop(trace
);
1030 ltt_unlock_traces();
1033 //ust// EXPORT_SYMBOL_GPL(ltt_trace_stop);
1036 * ltt_control - Trace control in-kernel API
1037 * @msg: Action to perform
1038 * @trace_name: Trace on which the action must be done
1039 * @trace_type: Type of trace (normal, flight, hybrid)
1040 * @args: Arguments specific to the action
1042 //ust// int ltt_control(enum ltt_control_msg msg, const char *trace_name,
1043 //ust// const char *trace_type, union ltt_control_args args)
1045 //ust// int err = -EPERM;
1047 //ust// printk(KERN_ALERT "ltt_control : trace %s\n", trace_name);
1048 //ust// switch (msg) {
1049 //ust// case LTT_CONTROL_START:
1050 //ust// printk(KERN_DEBUG "Start tracing %s\n", trace_name);
1051 //ust// err = ltt_trace_start(trace_name);
1053 //ust// case LTT_CONTROL_STOP:
1054 //ust// printk(KERN_DEBUG "Stop tracing %s\n", trace_name);
1055 //ust// err = ltt_trace_stop(trace_name);
1057 //ust// case LTT_CONTROL_CREATE_TRACE:
1058 //ust// printk(KERN_DEBUG "Creating trace %s\n", trace_name);
1059 //ust// err = ltt_trace_create(trace_name, trace_type,
1060 //ust// args.new_trace.mode,
1061 //ust// args.new_trace.subbuf_size_low,
1062 //ust// args.new_trace.n_subbufs_low,
1063 //ust// args.new_trace.subbuf_size_med,
1064 //ust// args.new_trace.n_subbufs_med,
1065 //ust// args.new_trace.subbuf_size_high,
1066 //ust// args.new_trace.n_subbufs_high);
1068 //ust// case LTT_CONTROL_DESTROY_TRACE:
1069 //ust// printk(KERN_DEBUG "Destroying trace %s\n", trace_name);
1070 //ust// err = ltt_trace_destroy(trace_name);
1075 //ust// EXPORT_SYMBOL_GPL(ltt_control);
1078 * ltt_filter_control - Trace filter control in-kernel API
1079 * @msg: Action to perform on the filter
1080 * @trace_name: Trace on which the action must be done
1082 int ltt_filter_control(enum ltt_filter_control_msg msg
, const char *trace_name
)
1085 struct ltt_trace_struct
*trace
;
1087 printk(KERN_DEBUG
"ltt_filter_control : trace %s\n", trace_name
);
1089 trace
= _ltt_trace_find(trace_name
);
1090 if (trace
== NULL
) {
1092 "Trace does not exist. Cannot proxy control request\n");
1096 //ust// if (!try_module_get(ltt_filter_control_owner)) {
1097 //ust// err = -ENODEV;
1098 //ust// goto get_module_error;
1101 case LTT_FILTER_DEFAULT_ACCEPT
:
1103 "Proxy filter default accept %s\n", trace_name
);
1104 err
= (*ltt_filter_control_functor
)(msg
, trace
);
1106 case LTT_FILTER_DEFAULT_REJECT
:
1108 "Proxy filter default reject %s\n", trace_name
);
1109 err
= (*ltt_filter_control_functor
)(msg
, trace
);
1114 //ust// module_put(ltt_filter_control_owner);
1116 //ust// get_module_error:
1118 ltt_unlock_traces();
1121 //ust// EXPORT_SYMBOL_GPL(ltt_filter_control);
1123 //ust// int __init ltt_init(void)
1125 //ust// /* Make sure no page fault can be triggered by this module */
1126 //ust// vmalloc_sync_all();
1130 //ust// module_init(ltt_init)
1132 //ust// static void __exit ltt_exit(void)
1134 //ust// struct ltt_trace_struct *trace;
1135 //ust// struct list_head *pos, *n;
1137 //ust// ltt_lock_traces();
1138 //ust// /* Stop each trace, currently being read by RCU read-side */
1139 //ust// list_for_each_entry_rcu(trace, <t_traces.head, list)
1140 //ust// _ltt_trace_stop(trace);
1141 //ust// /* Wait for quiescent state. Readers have preemption disabled. */
1142 //ust// synchronize_sched();
1143 //ust// /* Safe iteration is now permitted. It does not have to be RCU-safe
1144 //ust// * because no readers are left. */
1145 //ust// list_for_each_safe(pos, n, <t_traces.head) {
1146 //ust// trace = container_of(pos, struct ltt_trace_struct, list);
1147 //ust// /* _ltt_trace_destroy does a synchronize_sched() */
1148 //ust// _ltt_trace_destroy(trace);
1149 //ust// __ltt_trace_destroy(trace);
1151 //ust// /* free traces in pre-alloc status */
1152 //ust// list_for_each_safe(pos, n, <t_traces.setup_head) {
1153 //ust// trace = container_of(pos, struct ltt_trace_struct, list);
1154 //ust// _ltt_trace_free(trace);
1157 //ust// ltt_unlock_traces();
1160 //ust// module_exit(ltt_exit)
1162 //ust// MODULE_LICENSE("GPL");
1163 //ust// MODULE_AUTHOR("Mathieu Desnoyers");
1164 //ust// MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Tracer Kernel API");