#
ifneq ($(KERNELRELEASE),)
-ifneq ($(CONFIG_MARKERS),)
+ifneq ($(CONFIG_TRACEPOINTS),)
obj-m += ltt-core.o
-obj-m += ltt-tracer.o
-obj-m += ltt-marker-control.o
+obj-m += ltt-debugfs-abi.o
+obj-m += ltt-events.o
+obj-m += ltt-ring-buffer-client-discard.o
+obj-m += ltt-ring-buffer-client-overwrite.o
obj-m += ltt-relay.o
ltt-relay-objs := ltt-event-header.o ltt-serialize.o ltt-type-serializer.o
+
+#obj-m += ltt-marker-control.o
+#obj-m += ltt-trace-control.o
#ltt-ascii.o
-obj-m += ltt-statedump.o
-obj-m += ltt-trace-control.o
-obj-m += ltt-userspace-event.o
-obj-m += ltt-filter.o
-obj-m += ltt-kprobes.o
-obj-m += probes/
+#obj-m += ltt-statedump.o
+#obj-m += ltt-userspace-event.o
+#obj-m += ltt-filter.o
+#obj-m += ltt-kprobes.o
+#obj-m += probes/
endif
* - Takes instrumentation source specific arguments.
*/
+#include <linux/module.h>
#include <linux/debugfs.h>
+#include <linux/anon_inodes.h>
+#include <linux/file.h>
+#include <linux/uaccess.h>
+#include <linux/slab.h>
+#include <linux/ringbuffer/vfs.h>
+#include "ltt-debugfs-abi.h"
#include "ltt-events.h"
/*
static const struct file_operations lttng_channel_fops;
static const struct file_operations lttng_event_fops;
-/*
- * LTTng DebugFS ABI structures.
- */
-
-struct lttng_channel {
- int overwrite; /* 1: overwrite, 0: discard */
- u64 subbuf_size;
- u64 num_subbuf;
- unsigned int switch_timer_interval;
- unsigned int read_timer_interval;
-};
-
-struct lttng_event {
- enum instrum_type itype;
- char name[];
-};
-
static
int lttng_abi_create_session(void)
{
struct ltt_session *session;
struct file *session_file;
- int session_fd;
+ int session_fd, ret;
session = ltt_session_create();
if (!session)
#ifdef CONFIG_COMPAT
.compat_ioctl = lttng_ioctl,
#endif
-}
+};
int lttng_abi_create_channel(struct file *session_file,
struct lttng_channel __user *uchan_param)
* We tolerate no failure path after channel creation. It will stay
* invariant for the rest of the session.
*/
- chan = ltt_channel_create(session, chan_param->overwrite, NULL,
- chan_param->subbuf_size,
- chan_param->num_subbuf,
- chan_param->switch_timer_interval,
- chan_param->read_timer_interval);
+ chan = ltt_channel_create(session, chan_param.overwrite, NULL,
+ chan_param.subbuf_size,
+ chan_param.num_subbuf,
+ chan_param.switch_timer_interval,
+ chan_param.read_timer_interval);
if (!chan) {
ret = -ENOMEM;
goto chan_error;
}
- channel->file = chan_file;
+ chan->file = chan_file;
chan_file->private_data = chan;
fd_install(chan_fd, chan_file);
/* The channel created holds a reference on the session */
return ltt_session_start(session);
case LTTNG_SESSION_STOP:
return ltt_session_stop(session);
- case LTTNG_SESSION_FINALIZE:
- return ltt_session_finalize(session);
default:
return -ENOIOCTLCMD;
}
int lttng_session_release(struct inode *inode, struct file *file)
{
struct ltt_session *session = file->private_data;
- return ltt_session_destroy(session);
+ ltt_session_destroy(session);
+ return 0;
}
static const struct file_operations lttng_session_fops = {
#ifdef CONFIG_COMPAT
.compat_ioctl = lttng_session_ioctl,
#endif
-}
+};
static
int lttng_abi_open_stream(struct file *channel_file)
struct ltt_channel *channel = channel_file->private_data;
struct lib_ring_buffer *buf;
int stream_fd, ret;
+ struct file *stream_file;
- buf = ltt_buffer_read_open(channel->chan);
+ buf = channel->ops->buffer_read_open(channel->chan);
if (!buf)
return -ENOENT;
file_error:
put_unused_fd(stream_fd);
fd_error:
- ltt_buffer_read_close(buf);
+ channel->ops->buffer_read_close(buf);
return ret;
}
char *event_name;
struct lttng_event event_param;
int event_fd, ret;
+ struct file *event_file;
if (copy_from_user(&event_param, uevent_param, sizeof(event_param)))
return -EFAULT;
event_name = kmalloc(PATH_MAX, GFP_KERNEL);
if (!event_name)
return -ENOMEM;
- if (strncpy_from_user(event_name, &uevent_param->name, PATH_MAX)) {
+ if (strncpy_from_user(event_name, uevent_param->name, PATH_MAX)) {
ret = -EFAULT;
goto name_error;
}
* We tolerate no failure path after event creation. It will stay
* invariant for the rest of the session.
*/
- event = ltt_event_create(channel, event_param->itype, event_name, NULL);
+ event = ltt_event_create(channel, event_name, event_param.itype,
+ NULL, NULL); /* TODO non-null probe */
if (!event) {
goto event_error;
ret = -EEXIST;
#ifdef CONFIG_COMPAT
.compat_ioctl = lttng_channel_ioctl,
#endif
-}
+};
static
int lttng_event_release(struct inode *inode, struct file *file)
/* TODO: filter control ioctl */
static const struct file_operations lttng_event_fops = {
.release = lttng_event_release,
-}
+};
static int __init ltt_debugfs_abi_init(void)
{
int ret = 0;
- lttng_dentry = debugfs_create_file("lttng", NULL);
- if (IS_ERR(lttng_dentry) || !lttng_dentry)
+ lttng_dentry = debugfs_create_file("lttng", S_IWUSR, NULL, NULL,
+ <tng_session_fops);
+ if (IS_ERR(lttng_dentry) || !lttng_dentry) {
printk(KERN_ERR "Error creating LTTng control file\n");
ret = -ENOMEM;
goto error;
return ret;
}
+module_init(ltt_debugfs_abi_init);
+
static void __exit ltt_debugfs_abi_exit(void)
{
- debugfs_remote(lttng_dentry);
+ debugfs_remove(lttng_dentry);
}
+
+module_exit(ltt_debugfs_abi_exit);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation DebugFS ABI");
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h> /* For vmalloc_sync_all */
#include "ltt-events.h"
static LIST_HEAD(sessions);
struct ltt_session *session;
mutex_lock(&sessions_mutex);
- session = kmalloc(sizeof(struct ltt_session));
+ session = kmalloc(sizeof(struct ltt_session), GFP_KERNEL);
if (!session)
return NULL;
INIT_LIST_HEAD(&session->chan);
list_add(&session->list, &sessions);
mutex_unlock(&sessions_mutex);
return session;
-
-exist:
- mutex_unlock(&sessions_mutex);
- return NULL;
}
-int ltt_session_destroy(struct ltt_session *session)
+void ltt_session_destroy(struct ltt_session *session)
{
struct ltt_channel *chan, *tmpchan;
struct ltt_event *event, *tmpevent;
synchronize_trace(); /* Wait for in-flight events to complete */
end:
mutex_unlock(&sessions_mutex);
- return ret
+ return ret;
}
int ltt_session_stop(struct ltt_session *session)
synchronize_trace(); /* Wait for in-flight events to complete */
end:
mutex_unlock(&sessions_mutex);
- return ret
+ return ret;
}
struct ltt_channel *ltt_channel_create(struct ltt_session *session,
goto nomem;
chan->session = session;
init_waitqueue_head(&chan->notify_wait);
- transport->ops.channel_create(session, buf_addr, subbuf_size,
- num_subbuf, switch_timer_interval,
- read_timer_interval);
+ chan->chan = transport->ops.channel_create("[lttng]", session, buf_addr,
+ subbuf_size, num_subbuf, switch_timer_interval,
+ read_timer_interval);
+ chan->ops = &transport->ops;
list_add(&chan->list, &session->chan);
mutex_unlock(&sessions_mutex);
return chan;
/*
* Only used internally at session destruction.
*/
-int _ltt_channel_destroy(struct ltt_channel *chan)
+void _ltt_channel_destroy(struct ltt_channel *chan)
{
- transport->ops.channel_destroy(chan);
+ chan->ops->channel_destroy(chan->chan);
list_del(&chan->list);
kfree(chan);
}
list_for_each_entry(event, &chan->session->events, list)
if (!strcmp(event->name, name))
goto exist;
- event = kmem_cache_zalloc(events_cache, GFP_KERNEL);
+ event = kmem_cache_zalloc(event_cache, GFP_KERNEL);
if (!event)
goto cache_error;
event->name = kmalloc(strlen(name) + 1, GFP_KERNEL);
if (!event->name)
- goto error;
+ goto name_error;
strcpy(event->name, name);
event->chan = chan;
event->probe = probe;
event->filter = filter;
event->id = chan->free_event_id++;
event->itype = itype;
- mutex_unlock(&sessions_mutex);
/* Populate ltt_event structure before tracepoint registration. */
smp_wmb();
switch (itype) {
case INSTRUM_TRACEPOINTS:
ret = tracepoint_probe_register(name, probe, event);
+ if (ret)
+ goto register_error;
break;
default:
WARN_ON_ONCE(1);
}
+ mutex_unlock(&sessions_mutex);
return event;
-error:
- kmem_cache_free(event);
+register_error:
+ kfree(event->name);
+name_error:
+ kmem_cache_free(event_cache, event);
cache_error:
exist:
full:
*/
int _ltt_event_destroy(struct ltt_event *event)
{
+ int ret = -EINVAL;
+
switch (event->itype) {
case INSTRUM_TRACEPOINTS:
- ret = tracepoint_probe_unregister(name, event->probe, event);
+ ret = tracepoint_probe_unregister(event->name, event->probe,
+ event);
+ if (ret)
+ return ret;
break;
default:
WARN_ON_ONCE(1);
}
kfree(event->name);
- kmem_cache_free(event);
+ kmem_cache_free(event_cache, event);
+ return ret;
}
/**
static int __init ltt_events_init(void)
{
- int ret;
-
- events_cache = KMEM_CACHE(ltt_event, 0);
- if (!events_cache)
+ event_cache = KMEM_CACHE(ltt_event, 0);
+ if (!event_cache)
return -ENOMEM;
return 0;
}
+module_init(ltt_events_init);
+
static void __exit ltt_events_exit(void)
{
struct ltt_session *session, *tmpsession;
list_for_each_entry_safe(session, tmpsession, &sessions, list)
ltt_session_destroy(session);
- kmem_cache_destroy(events_cache);
+ kmem_cache_destroy(event_cache);
}
+module_exit(ltt_events_exit);
+
MODULE_LICENSE("GPL and additional rights");
MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
MODULE_DESCRIPTION("LTTng Events");
+#ifndef _LTT_EVENTS_H
+#define _LTT_EVENTS_H
+
/*
* ltt-events.h
*
*/
#include <linux/list.h>
+#include "ltt-debugfs-abi.h"
struct ltt_channel;
struct ltt_session;
-enum instrum_type itype {
- INSTRUM_TRACEPOINTS,
-};
-
/*
* ltt_event structure is referred to by the tracing fast path. It must be
* kept small.
struct list_head list; /* Event list */
};
+struct ltt_channel_ops {
+ struct channel *(*channel_create)(const char *name,
+ struct ltt_session *session,
+ void *buf_addr,
+ size_t subbuf_size, size_t num_subbuf,
+ unsigned int switch_timer_interval,
+ unsigned int read_timer_interval);
+ void (*channel_destroy)(struct channel *chan);
+ struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
+ struct lib_ring_buffer *(*buffer_read_close)(struct lib_ring_buffer *buf);
+};
+
struct ltt_channel {
struct channel *chan; /* Channel buffers */
/* Event ID management */
unsigned int free_event_id; /* Next event ID to allocate */
struct list_head list; /* Channel list */
wait_queue_head_t notify_wait; /* Channel addition notif. waitqueue */
+ struct ltt_channel_ops *ops;
};
struct ltt_session {
struct list_head list; /* Session list */
};
-struct ltt_trace_ops {
- struct channel *(*channel_create)(const char *name,
- struct ltt_trace *trace,
- void *buf_addr,
- size_t subbuf_size, size_t num_subbuf,
- unsigned int switch_timer_interval,
- unsigned int read_timer_interval);
- void (*channel_destroy)(struct channel *chan);
- struct lib_ring_buffer *(*buffer_read_open)(struct channel *chan);
- struct lib_ring_buffer *(*buffer_read_close)(struct lib_ring_buffer *buf);
-};
-
struct ltt_transport {
char *name;
struct module *owner;
struct list_head node;
- struct ltt_trace_ops ops;
+ struct ltt_channel_ops ops;
};
struct ltt_session *ltt_session_create(void);
int ltt_session_start(struct ltt_session *session);
int ltt_session_stop(struct ltt_session *session);
-int ltt_session_destroy(struct ltt_session *session);
+void ltt_session_destroy(struct ltt_session *session);
struct ltt_channel *ltt_channel_create(struct ltt_session *session,
int overwrite, void *buf_addr,
size_t subbuf_size, size_t num_subbuf,
unsigned int switch_timer_interval,
unsigned int read_timer_interval);
-int _ltt_channel_destroy(struct ltt_channel *chan);
+void _ltt_channel_destroy(struct ltt_channel *chan);
struct ltt_event *ltt_event_create(struct ltt_channel *chan,
- enum instrum_type itype,
char *name,
- void *filter);
+ enum instrum_type itype,
+ void *probe, void *filter);
int _ltt_event_destroy(struct ltt_event *event);
void ltt_transport_register(struct ltt_transport *transport);
void ltt_transport_unregister(struct ltt_transport *transport);
+
+#endif /* _LTT_EVENTS_H */
#include <linux/kernel.h>
#include <linux/timex.h>
#include <linux/wait.h>
-#include <linux/marker.h>
#include <linux/trace-clock.h>
#include <asm/atomic.h>
#include <asm/local.h>
#include "ltt-tracer-core.h"
-#include "ltt-channels.h"
/* Number of bytes to log with a read/write event */
#define LTT_LOG_RW_SIZE 32L
-struct ltt_active_marker;
-
/* Maximum number of callbacks per marker */
#define LTT_NR_CALLBACKS 10
+struct ltt_serialize_closure;
+
+/* Serialization callback */
+typedef size_t (*ltt_serialize_cb)(struct lib_ring_buffer *buf,
+ size_t buf_offset,
+ struct ltt_serialize_closure *closure,
+ void *serialize_private,
+ unsigned int stack_pos_ctx,
+ int *largest_align,
+ const char *fmt, va_list *args);
+
struct ltt_serialize_closure {
ltt_serialize_cb *callbacks;
long cb_args[LTT_NR_CALLBACKS];
unsigned int cb_idx;
};
-size_t ltt_serialize_data(struct ltt_chanbuf *buf, size_t buf_offset,
+size_t ltt_serialize_data(struct lib_ring_buffer *buf, size_t buf_offset,
struct ltt_serialize_closure *closure,
void *serialize_private, unsigned int stack_pos_ctx,
int *largest_align, const char *fmt, va_list *args);
-struct ltt_available_probe {
- const char *name; /* probe name */
- const char *format;
- marker_probe_func *probe_func;
- ltt_serialize_cb callbacks[LTT_NR_CALLBACKS];
- struct list_head node; /* registered probes list */
-};
-
enum ltt_channels {
LTT_CHANNEL_METADATA,
LTT_CHANNEL_FD_STATE,
LTT_CHANNEL_DEFAULT,
};
-struct ltt_active_marker {
- struct list_head node; /* active markers list */
- const char *channel;
- const char *name;
- const char *format;
- struct ltt_available_probe *probe;
-};
-
-extern void ltt_vtrace(const struct marker *mdata, void *probe_data,
- void *call_data, const char *fmt, va_list *args);
-extern void ltt_trace(const struct marker *mdata, void *probe_data,
- void *call_data, const char *fmt, ...);
-
-size_t ltt_serialize_printf(struct ltt_chanbuf *buf, unsigned long buf_offset,
+#if 0
+size_t ltt_serialize_printf(struct lib_ring_buffer *buf, unsigned long buf_offset,
size_t *msg_size, char *output, size_t outlen,
const char *fmt);
#define CHANNEL_FLAG_ENABLE (1U<<0)
#define CHANNEL_FLAG_OVERWRITE (1U<<1)
+#endif //0
#if 0
/* Per-trace information - each trace/flight recorder represented by one */
#include <linux/ringbuffer/api.h>
extern
-size_t ltt_write_event_header_slow(struct ltt_chanbuf_alloc *bufa,
- struct ltt_chan_alloc *chana,
- long buf_offset, u16 eID, u32 event_size,
- u64 tsc, unsigned int rflags);
+size_t ltt_write_event_header_slow(const struct lib_ring_buffer_config *config,
+ struct lib_ring_buffer_ctx *ctx,
+ u16 eID, u32 event_size);
/*
* ltt_write_event_header
void ltt_write_trace_header(void *priv,
struct subbuffer_header *header)
{
- struct ltt_trace *trace = priv;
+ struct ltt_session *session = priv;
header->magic_number = LTT_TRACER_MAGIC_NUMBER;
header->major_version = LTT_TRACER_VERSION_MAJOR;
header->minor_version = LTT_TRACER_VERSION_MINOR;
header->arch_size = sizeof(void *);
header->alignment = lib_ring_buffer_get_alignment();
- header->start_time_sec = trace->start_time.tv_sec;
- header->start_time_usec = trace->start_time.tv_usec;
- header->start_freq = trace->start_freq;
- header->freq_scale = trace->freq_scale;
+ header->start_time_sec = session->start_time.tv_sec;
+ header->start_time_usec = session->start_time.tv_usec;
+ header->start_freq = session->start_freq;
+ header->freq_scale = session->freq_scale;
}
/*
void ltt_core_unregister(void);
-extern int ltt_probe_register(struct ltt_available_probe *pdata);
-extern int ltt_probe_unregister(struct ltt_available_probe *pdata);
extern int ltt_marker_connect(const char *channel, const char *mname,
const char *pname);
extern int ltt_marker_disconnect(const char *channel, const char *mname,