/*
- * ltt/ltt-tracer.c
+ * tracer.c
*
* (C) Copyright 2005-2008 -
* Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
*
- * Tracing management internal kernel API. Trace buffer allocation/free, tracing
- * start/stop.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
*
- * Author:
- * Mathieu Desnoyers (mathieu.desnoyers@polymtl.ca)
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Inspired from LTT :
* Karim Yaghmour (karim@opersys.com)
* 27/05/05, Modular redesign and rewrite.
*/
-//ust// #include <linux/time.h>
-//ust// #include <linux/ltt-tracer.h>
-//ust// #include <linux/module.h>
-//ust// #include <linux/string.h>
-//ust// #include <linux/slab.h>
-//ust// #include <linux/init.h>
-//ust// #include <linux/rcupdate.h>
-//ust// #include <linux/sched.h>
-//ust// #include <linux/bitops.h>
-//ust// #include <linux/fs.h>
-//ust// #include <linux/cpu.h>
-//ust// #include <linux/kref.h>
-//ust// #include <linux/delay.h>
-//ust// #include <linux/vmalloc.h>
-//ust// #include <asm/atomic.h>
-#include <kcompat/rculist.h>
-
-#include "kernelcompat.h"
+#include <urcu-bp.h>
+#include <urcu/rculist.h>
+
+#include <ust/kernelcompat.h>
#include "tracercore.h"
#include "tracer.h"
#include "usterr.h"
//ust//
//ust// return ret;
//ust// }
-//ust// EXPORT_SYMBOL_GPL(ltt_module_register);
/**
* ltt_module_unregister - LTT module unregistration
//ust// }
//ust//
//ust// }
-//ust// EXPORT_SYMBOL_GPL(ltt_module_unregister);
static LIST_HEAD(ltt_transport_list);
list_add_tail(&transport->node, <t_transport_list);
ltt_unlock_traces();
}
-//ust// EXPORT_SYMBOL_GPL(ltt_transport_register);
/**
* ltt_transport_unregister - LTT transport unregistration
list_del(&transport->node);
ltt_unlock_traces();
}
-//ust// EXPORT_SYMBOL_GPL(ltt_transport_unregister);
static inline int is_channel_overwrite(enum ltt_channels chan,
enum trace_mode mode)
header->start_freq = trace->start_freq;
header->freq_scale = trace->freq_scale;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_write_trace_header);
static void trace_async_wakeup(struct ltt_trace_struct *trace)
{
int i;
- struct ltt_channel_struct *chan;
+ struct ust_channel *chan;
/* Must check each channel for pending read wakeup */
for (i = 0; i < trace->nr_channels; i++) {
return NULL;
}
-//ust// EXPORT_SYMBOL_GPL(_ltt_trace_find_setup);
/**
* ltt_release_transport - Release an LTT transport
*/
void ltt_release_transport(struct kref *kref)
{
- struct ltt_trace_struct *trace = container_of(kref,
- struct ltt_trace_struct, ltt_transport_kref);
-//ust// trace->ops->remove_dirs(trace);
+//ust// struct ltt_trace_struct *trace = container_of(kref,
+//ust// struct ltt_trace_struct, ltt_transport_kref);
+//ust// trace->ops->remove_dirs(trace);
}
-//ust// EXPORT_SYMBOL_GPL(ltt_release_transport);
/**
* ltt_release_trace - Release a LTT trace
ltt_channels_trace_free(trace->channels);
kfree(trace);
}
-//ust// EXPORT_SYMBOL_GPL(ltt_release_trace);
static inline void prepare_chan_size_num(unsigned int *subbuf_size,
unsigned int *n_subbufs)
enum ltt_channels chantype;
if (_ltt_trace_find_setup(trace_name)) {
- printk(KERN_ERR "LTT : Trace name %s already used.\n",
- trace_name);
+ ERR("Trace name %s already used", trace_name);
err = -EEXIST;
goto traces_error;
}
if (_ltt_trace_find(trace_name)) {
- printk(KERN_ERR "LTT : Trace name %s already used.\n",
- trace_name);
+ ERR("Trace name %s already used", trace_name);
err = -EEXIST;
goto traces_error;
}
new_trace = kzalloc(sizeof(struct ltt_trace_struct), GFP_KERNEL);
if (!new_trace) {
- printk(KERN_ERR
- "LTT : Unable to allocate memory for trace %s\n",
- trace_name);
+ ERR("Unable to allocate memory for trace %s", trace_name);
err = -ENOMEM;
goto traces_error;
}
new_trace->channels = ltt_channels_trace_alloc(&new_trace->nr_channels,
0, 1);
if (!new_trace->channels) {
- printk(KERN_ERR
- "LTT : Unable to allocate memory for chaninfo %s\n",
- trace_name);
+ ERR("Unable to allocate memory for chaninfo %s\n", trace_name);
err = -ENOMEM;
goto trace_free;
}
traces_error:
return err;
}
-//ust// EXPORT_SYMBOL_GPL(_ltt_trace_setup);
int ltt_trace_setup(const char *trace_name)
ltt_unlock_traces();
return ret;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_setup);
/* must be called from within a traces lock. */
static void _ltt_trace_free(struct ltt_trace_struct *trace)
trace = _ltt_trace_find_setup(trace_name);
if (!trace) {
- printk(KERN_ERR "LTT : Trace not found %s\n", trace_name);
+ ERR("Trace not found %s", trace_name);
err = -ENOENT;
goto traces_error;
}
}
}
if (!transport) {
- printk(KERN_ERR "LTT : Transport %s is not present.\n",
- trace_type);
+ ERR("Transport %s is not present", trace_type);
err = -EINVAL;
goto traces_error;
}
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_set_type);
int ltt_trace_set_channel_subbufsize(const char *trace_name,
const char *channel_name, unsigned int size)
trace = _ltt_trace_find_setup(trace_name);
if (!trace) {
- printk(KERN_ERR "LTT : Trace not found %s\n", trace_name);
+ ERR("Trace not found %s", trace_name);
err = -ENOENT;
goto traces_error;
}
index = ltt_channels_get_index_from_name(channel_name);
if (index < 0) {
- printk(KERN_ERR "LTT : Channel %s not found\n", channel_name);
+ ERR("Channel %s not found", channel_name);
err = -ENOENT;
goto traces_error;
}
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufsize);
int ltt_trace_set_channel_subbufcount(const char *trace_name,
const char *channel_name, unsigned int cnt)
trace = _ltt_trace_find_setup(trace_name);
if (!trace) {
- printk(KERN_ERR "LTT : Trace not found %s\n", trace_name);
+ ERR("Trace not found %s", trace_name);
err = -ENOENT;
goto traces_error;
}
index = ltt_channels_get_index_from_name(channel_name);
if (index < 0) {
- printk(KERN_ERR "LTT : Channel %s not found\n", channel_name);
+ ERR("Channel %s not found", channel_name);
err = -ENOENT;
goto traces_error;
}
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_subbufcount);
int ltt_trace_set_channel_enable(const char *trace_name,
const char *channel_name, unsigned int enable)
trace = _ltt_trace_find_setup(trace_name);
if (!trace) {
- printk(KERN_ERR "LTT : Trace not found %s\n", trace_name);
+ ERR("Trace not found %s", trace_name);
err = -ENOENT;
goto traces_error;
}
* read the trace, we always enable this channel.
*/
if (!enable && !strcmp(channel_name, "metadata")) {
- printk(KERN_ERR "LTT : Trying to disable metadata channel\n");
+ ERR("Trying to disable metadata channel");
err = -EINVAL;
goto traces_error;
}
index = ltt_channels_get_index_from_name(channel_name);
if (index < 0) {
- printk(KERN_ERR "LTT : Channel %s not found\n", channel_name);
+ ERR("Channel %s not found", channel_name);
err = -ENOENT;
goto traces_error;
}
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_enable);
int ltt_trace_set_channel_overwrite(const char *trace_name,
const char *channel_name, unsigned int overwrite)
trace = _ltt_trace_find_setup(trace_name);
if (!trace) {
- printk(KERN_ERR "LTT : Trace not found %s\n", trace_name);
+ ERR("Trace not found %s", trace_name);
err = -ENOENT;
goto traces_error;
}
* able to read the trace.
*/
if (overwrite && !strcmp(channel_name, "metadata")) {
- printk(KERN_ERR "LTT : Trying to set metadata channel to "
- "overwrite mode\n");
+ ERR("Trying to set metadata channel to overwrite mode");
err = -EINVAL;
goto traces_error;
}
index = ltt_channels_get_index_from_name(channel_name);
if (index < 0) {
- printk(KERN_ERR "LTT : Channel %s not found\n", channel_name);
+ ERR("Channel %s not found", channel_name);
err = -ENOENT;
goto traces_error;
}
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_set_channel_overwrite);
int ltt_trace_alloc(const char *trace_name)
{
int err = 0;
struct ltt_trace_struct *trace;
unsigned int subbuf_size, subbuf_cnt;
- unsigned long flags;
+//ust// unsigned long flags;
int chan;
const char *channel_name;
trace = _ltt_trace_find_setup(trace_name);
if (!trace) {
- printk(KERN_ERR "LTT : Trace not found %s\n", trace_name);
+ ERR("Trace not found %s", trace_name);
err = -ENOENT;
goto traces_error;
}
trace->freq_scale = trace_clock_freq_scale();
if (!trace->transport) {
- printk(KERN_ERR "LTT : Transport is not set.\n");
+ ERR("Transport is not set");
err = -EINVAL;
goto transport_error;
}
//ust// if (!try_module_get(trace->transport->owner)) {
-//ust// printk(KERN_ERR "LTT : Can't lock transport module.\n");
+//ust// ERR("Can't lock transport module");
//ust// err = -ENODEV;
//ust// goto transport_error;
//ust// }
//ust// err = trace->ops->create_dirs(trace);
//ust// if (err) {
-//ust// printk(KERN_ERR "LTT : Can't create dir for trace %s.\n",
-//ust// trace_name);
+//ust// ERR("Can't create dir for trace %s", trace_name);
//ust// goto dirs_error;
//ust// }
//ust// local_irq_save(flags);
trace->start_freq = trace_clock_frequency();
trace->start_tsc = trace_clock_read64();
- gettimeofday(&trace->start_time, NULL); //ust// changed
+ gettimeofday(&trace->start_time, NULL); //ust// changed /* FIXME: is this ok? */
//ust// local_irq_restore(flags);
for (chan = 0; chan < trace->nr_channels; chan++) {
subbuf_cnt = trace->channels[chan].subbuf_cnt;
prepare_chan_size_num(&subbuf_size, &subbuf_cnt);
err = trace->ops->create_channel(trace_name, trace,
- trace->dentry.trace_root,
channel_name,
&trace->channels[chan],
subbuf_size,
subbuf_cnt,
trace->channels[chan].overwrite);
if (err != 0) {
- printk(KERN_ERR "LTT : Can't create channel %s.\n",
- channel_name);
+ ERR("Cannot create channel %s", channel_name);
goto create_channel_error;
}
}
if (trace->channels[chan].active)
trace->ops->remove_channel(&trace->channels[chan]);
-dirs_error:
+//ust// dirs_error:
//ust// module_put(trace->transport->owner);
transport_error:
//ust// put_trace_clock();
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_alloc);
/*
* It is worked as a wrapper for current version of ltt_control.ko.
* We will make a new ltt_control based on debugfs, and control each channel's
* buffer.
*/
-static int ltt_trace_create(const char *trace_name, const char *trace_type,
- enum trace_mode mode,
- unsigned int subbuf_size_low, unsigned int n_subbufs_low,
- unsigned int subbuf_size_med, unsigned int n_subbufs_med,
- unsigned int subbuf_size_high, unsigned int n_subbufs_high)
-{
- int err = 0;
-
- err = ltt_trace_setup(trace_name);
- if (IS_ERR_VALUE(err))
- return err;
-
- err = ltt_trace_set_type(trace_name, trace_type);
- if (IS_ERR_VALUE(err))
- return err;
-
- err = ltt_trace_alloc(trace_name);
- if (IS_ERR_VALUE(err))
- return err;
-
- return err;
-}
+//ust// static int ltt_trace_create(const char *trace_name, const char *trace_type,
+//ust// enum trace_mode mode,
+//ust// unsigned int subbuf_size_low, unsigned int n_subbufs_low,
+//ust// unsigned int subbuf_size_med, unsigned int n_subbufs_med,
+//ust// unsigned int subbuf_size_high, unsigned int n_subbufs_high)
+//ust// {
+//ust// int err = 0;
+//ust//
+//ust// err = ltt_trace_setup(trace_name);
+//ust// if (IS_ERR_VALUE(err))
+//ust// return err;
+//ust//
+//ust// err = ltt_trace_set_type(trace_name, trace_type);
+//ust// if (IS_ERR_VALUE(err))
+//ust// return err;
+//ust//
+//ust// err = ltt_trace_alloc(trace_name);
+//ust// if (IS_ERR_VALUE(err))
+//ust// return err;
+//ust//
+//ust// return err;
+//ust// }
/* Must be called while sure that trace is in the list. */
-static int _ltt_trace_destroy(struct ltt_trace_struct *trace)
+static int _ltt_trace_destroy(struct ltt_trace_struct *trace)
{
int err = -EPERM;
goto traces_error;
}
if (trace->active) {
- printk(KERN_ERR
- "LTT : Can't destroy trace %s : tracer is active\n",
- trace->trace_name);
+ ERR("Can't destroy trace %s : tracer is active", trace->trace_name);
err = -EBUSY;
goto active_error;
}
/* Everything went fine */
-//ust// list_del_rcu(&trace->list);
-//ust// synchronize_sched();
+ list_del_rcu(&trace->list);
+ synchronize_rcu();
if (list_empty(<t_traces.head)) {
//ust// clear_kernel_trace_flag_all_tasks();
/*
static void __ltt_trace_destroy(struct ltt_trace_struct *trace)
{
int i;
- struct ltt_channel_struct *chan;
+ struct ust_channel *chan;
for (i = 0; i < trace->nr_channels; i++) {
chan = &trace->channels[i];
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_destroy);
/* must be called from within a traces lock. */
static int _ltt_trace_start(struct ltt_trace_struct *trace)
goto traces_error;
}
if (trace->active)
- printk(KERN_INFO "LTT : Tracing already active for trace %s\n",
- trace->trace_name);
+ DBG("Tracing already active for trace %s", trace->trace_name);
//ust// if (!try_module_get(ltt_run_filter_owner)) {
//ust// err = -ENODEV;
-//ust// printk(KERN_ERR "LTT : Can't lock filter module.\n");
+//ust// ERR("Cannot lock filter module");
//ust// goto get_ltt_run_filter_error;
//ust// }
trace->active = 1;
return err;
/* error handling */
-get_ltt_run_filter_error:
+//ust// get_ltt_run_filter_error:
traces_error:
return err;
}
//ust// if (!try_module_get(ltt_statedump_owner)) {
//ust// err = -ENODEV;
-//ust// printk(KERN_ERR
-//ust// "LTT : Can't lock state dump module.\n");
+//ust// ERR("Cannot lock state dump module");
//ust// } else {
ltt_statedump_functor(trace);
//ust// module_put(ltt_statedump_owner);
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_start);
/* must be called from within traces lock */
static int _ltt_trace_stop(struct ltt_trace_struct *trace)
goto traces_error;
}
if (!trace->active)
- printk(KERN_INFO "LTT : Tracing not active for trace %s\n",
- trace->trace_name);
+ DBG("LTT : Tracing not active for trace %s", trace->trace_name);
if (trace->active) {
trace->active = 0;
ltt_traces.num_active_traces--;
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_trace_stop);
-
-/**
- * ltt_control - Trace control in-kernel API
- * @msg: Action to perform
- * @trace_name: Trace on which the action must be done
- * @trace_type: Type of trace (normal, flight, hybrid)
- * @args: Arguments specific to the action
- */
-//ust// int ltt_control(enum ltt_control_msg msg, const char *trace_name,
-//ust// const char *trace_type, union ltt_control_args args)
-//ust// {
-//ust// int err = -EPERM;
-//ust//
-//ust// printk(KERN_ALERT "ltt_control : trace %s\n", trace_name);
-//ust// switch (msg) {
-//ust// case LTT_CONTROL_START:
-//ust// printk(KERN_DEBUG "Start tracing %s\n", trace_name);
-//ust// err = ltt_trace_start(trace_name);
-//ust// break;
-//ust// case LTT_CONTROL_STOP:
-//ust// printk(KERN_DEBUG "Stop tracing %s\n", trace_name);
-//ust// err = ltt_trace_stop(trace_name);
-//ust// break;
-//ust// case LTT_CONTROL_CREATE_TRACE:
-//ust// printk(KERN_DEBUG "Creating trace %s\n", trace_name);
-//ust// err = ltt_trace_create(trace_name, trace_type,
-//ust// args.new_trace.mode,
-//ust// args.new_trace.subbuf_size_low,
-//ust// args.new_trace.n_subbufs_low,
-//ust// args.new_trace.subbuf_size_med,
-//ust// args.new_trace.n_subbufs_med,
-//ust// args.new_trace.subbuf_size_high,
-//ust// args.new_trace.n_subbufs_high);
-//ust// break;
-//ust// case LTT_CONTROL_DESTROY_TRACE:
-//ust// printk(KERN_DEBUG "Destroying trace %s\n", trace_name);
-//ust// err = ltt_trace_destroy(trace_name);
-//ust// break;
-//ust// }
-//ust// return err;
-//ust// }
-//ust// EXPORT_SYMBOL_GPL(ltt_control);
/**
* ltt_filter_control - Trace filter control in-kernel API
int err;
struct ltt_trace_struct *trace;
- printk(KERN_DEBUG "ltt_filter_control : trace %s\n", trace_name);
+ DBG("ltt_filter_control : trace %s", trace_name);
ltt_lock_traces();
trace = _ltt_trace_find(trace_name);
if (trace == NULL) {
- printk(KERN_ALERT
- "Trace does not exist. Cannot proxy control request\n");
+ ERR("Trace does not exist. Cannot proxy control request");
err = -ENOENT;
goto trace_error;
}
//ust// }
switch (msg) {
case LTT_FILTER_DEFAULT_ACCEPT:
- printk(KERN_DEBUG
- "Proxy filter default accept %s\n", trace_name);
+ DBG("Proxy filter default accept %s", trace_name);
err = (*ltt_filter_control_functor)(msg, trace);
break;
case LTT_FILTER_DEFAULT_REJECT:
- printk(KERN_DEBUG
- "Proxy filter default reject %s\n", trace_name);
+ DBG("Proxy filter default reject %s", trace_name);
err = (*ltt_filter_control_functor)(msg, trace);
break;
default:
}
//ust// module_put(ltt_filter_control_owner);
-get_module_error:
+//ust// get_module_error:
trace_error:
ltt_unlock_traces();
return err;
}
-//ust// EXPORT_SYMBOL_GPL(ltt_filter_control);
-
-//ust// int __init ltt_init(void)
-//ust// {
-//ust// /* Make sure no page fault can be triggered by this module */
-//ust// vmalloc_sync_all();
-//ust// return 0;
-//ust// }
-
-//ust// module_init(ltt_init)
-
-//ust// static void __exit ltt_exit(void)
-//ust// {
-//ust// struct ltt_trace_struct *trace;
-//ust// struct list_head *pos, *n;
-//ust//
-//ust// ltt_lock_traces();
-//ust// /* Stop each trace, currently being read by RCU read-side */
-//ust// list_for_each_entry_rcu(trace, <t_traces.head, list)
-//ust// _ltt_trace_stop(trace);
-//ust// /* Wait for quiescent state. Readers have preemption disabled. */
-//ust// synchronize_sched();
-//ust// /* Safe iteration is now permitted. It does not have to be RCU-safe
-//ust// * because no readers are left. */
-//ust// list_for_each_safe(pos, n, <t_traces.head) {
-//ust// trace = container_of(pos, struct ltt_trace_struct, list);
-//ust// /* _ltt_trace_destroy does a synchronize_sched() */
-//ust// _ltt_trace_destroy(trace);
-//ust// __ltt_trace_destroy(trace);
-//ust// }
-//ust// /* free traces in pre-alloc status */
-//ust// list_for_each_safe(pos, n, <t_traces.setup_head) {
-//ust// trace = container_of(pos, struct ltt_trace_struct, list);
-//ust// _ltt_trace_free(trace);
-//ust// }
-//ust//
-//ust// ltt_unlock_traces();
-//ust// }
-
-//ust// module_exit(ltt_exit)
-
-//ust// MODULE_LICENSE("GPL");
-//ust// MODULE_AUTHOR("Mathieu Desnoyers");
-//ust// MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Tracer Kernel API");