From 5f54827b88b093974e4bf58f67490036718644c7 Mon Sep 17 00:00:00 2001 From: Pierre-Marc Fournier Date: Tue, 10 Feb 2009 16:15:41 -0500 Subject: [PATCH] ust: continue work --- hello/Makefile | 2 +- hello/hello.c | 57 +++++-- hello/run | 2 +- libtracing/channels.c | 9 +- libtracing/relay-alloc.c | 270 +++++++++++++++++-------------- libtracing/relay.c | 331 +++++++++++++++++++++++---------------- libtracing/tracer.c | 26 +-- libtracing/tracer.h | 6 +- share/kernelcompat.h | 20 ++- share/usterr.h | 2 +- 10 files changed, 429 insertions(+), 296 deletions(-) diff --git a/hello/Makefile b/hello/Makefile index 077f59b..d68b545 100644 --- a/hello/Makefile +++ b/hello/Makefile @@ -1,7 +1,7 @@ all: hello hello: hello.c - gcc -g -I../libmarkers -I../share -L../libmarkers -lmarkers -L../libtracectl -ltracectl -L../libtracing -ltracing -o hello hello.c + gcc -g -I../libmarkers -I../share -I../libtracing -L../libmarkers -lmarkers -L../libtracectl -ltracectl -L../libtracing -ltracing -o hello hello.c clean: rm -rf hello *.o diff --git a/hello/hello.c b/hello/hello.c index 5197986..44aa882 100644 --- a/hello/hello.c +++ b/hello/hello.c @@ -3,6 +3,8 @@ #include #include "../libmarkers/marker.h" +#include "usterr.h" +#include "tracer.h" void probe(const struct marker *mdata, void *probe_private, void *call_private, @@ -11,30 +13,55 @@ void probe(const struct marker *mdata, printf("In probe\n"); } -void try_map() +//ust// void try_map() +//ust// { +//ust// char *m; +//ust// +//ust// /* maybe add MAP_LOCKED */ +//ust// m = mmap(NULL, 4096, PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE , -1, 0); +//ust// if(m == (char*)-1) { +//ust// perror("mmap"); +//ust// return; +//ust// } +//ust// +//ust// printf("The mapping is at %p.\n", m); +//ust// strcpy(m, "Hello, Mapping!"); +//ust// } + +int main() { - char *m; + int result; + + init_ustrelay_transport(); + + char trace_name[] = "theusttrace"; + char trace_type[] = "usttrace"; + + marker_probe_register("abc", "testmark", "", probe, NULL); + marker_probe_register("metadata", "core_marker_id", "channel %s name %s event_id %hu int #1u%zu long #1u%zu pointer #1u%zu size_t #1u%zu alignment #1u%u", probe, NULL); - /* maybe add MAP_LOCKED */ - m = mmap(NULL, 4096, PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_POPULATE , -1, 0); - if(m == (char*)-1) { - perror("mmap"); - return; + result = ltt_trace_setup(trace_name); + if(result < 0) { + ERR("ltt_trace_setup failed"); + return 1; } - printf("The mapping is at %p.\n", m); - strcpy(m, "Hello, Mapping!"); -} +//ust// result = ltt_trace_set_type(trace_name, trace_type); +//ust// if(result < 0) { +//ust// ERR("ltt_trace_set_type failed"); +//ust// return 1; +//ust// } -int main() -{ - //ltt_trace_create(); + result = ltt_trace_alloc(trace_name); + if(result < 0) { + ERR("ltt_trace_alloc failed"); + return 1; + } - try_map(); +// try_map(); printf("Hello, World!\n"); - marker_probe_register("abc", "testmark", "", probe, NULL); trace_mark(abc, testmark, "", MARK_NOARGS); diff --git a/hello/run b/hello/run index 6f72e22..c741944 100755 --- a/hello/run +++ b/hello/run @@ -1,3 +1,3 @@ #!/bin/sh -LD_LIBRARY_PATH=../libtracectl:../libmarkers ./hello +LD_LIBRARY_PATH=../libtracectl:../libmarkers:../libtracing gdb ./hello diff --git a/libtracing/channels.c b/libtracing/channels.c index 1a23afe..fc0db8e 100644 --- a/libtracing/channels.c +++ b/libtracing/channels.c @@ -16,6 +16,7 @@ #include "kernelcompat.h" #include "channels.h" +#include "usterr.h" /* * ltt_channel_mutex may be nested inside the LTT trace mutex. @@ -239,8 +240,10 @@ struct ltt_channel_struct *ltt_channels_trace_alloc(unsigned int *nr_channels, struct ltt_channel_setting *iter; mutex_lock(<t_channel_mutex); - if (!free_index) + if (!free_index) { + WARN("ltt_channels_trace_alloc: no free_index; are there any probes connected?"); goto end; + } if (!atomic_read(&index_kref.refcount)) kref_init(&index_kref); else @@ -248,8 +251,10 @@ struct ltt_channel_struct *ltt_channels_trace_alloc(unsigned int *nr_channels, *nr_channels = free_index; channel = kzalloc(sizeof(struct ltt_channel_struct) * free_index, GFP_KERNEL); - if (!channel) + if (!channel) { + WARN("ltt_channel_struct: channel null after alloc"); goto end; + } list_for_each_entry(iter, <t_channels, list) { if (!atomic_read(&iter->kref.refcount)) continue; diff --git a/libtracing/relay-alloc.c b/libtracing/relay-alloc.c index 0f92518..ed401ab 100644 --- a/libtracing/relay-alloc.c +++ b/libtracing/relay-alloc.c @@ -11,17 +11,23 @@ * * This file is released under the GPL. */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +//ust// #include +#include +#include "kernelcompat.h" +#include "list.h" +#include "relay.h" +#include "channels.h" +#include "kref.h" /* list of open channels, for cpu hotplug */ static DEFINE_MUTEX(relay_channels_mutex); @@ -32,48 +38,70 @@ static LIST_HEAD(relay_channels); * @buf: the buffer struct * @size: total size of the buffer */ +//ust// static int relay_alloc_buf(struct rchan_buf *buf, size_t *size) +//ust//{ +//ust// unsigned int i, n_pages; +//ust// struct buf_page *buf_page, *n; +//ust// +//ust// *size = PAGE_ALIGN(*size); +//ust// n_pages = *size >> PAGE_SHIFT; +//ust// +//ust// INIT_LIST_HEAD(&buf->pages); +//ust// +//ust// for (i = 0; i < n_pages; i++) { +//ust// buf_page = kmalloc_node(sizeof(*buf_page), GFP_KERNEL, +//ust// cpu_to_node(buf->cpu)); +//ust// if (unlikely(!buf_page)) +//ust// goto depopulate; +//ust// buf_page->page = alloc_pages_node(cpu_to_node(buf->cpu), +//ust// GFP_KERNEL | __GFP_ZERO, 0); +//ust// if (unlikely(!buf_page->page)) { +//ust// kfree(buf_page); +//ust// goto depopulate; +//ust// } +//ust// list_add_tail(&buf_page->list, &buf->pages); +//ust// buf_page->offset = (size_t)i << PAGE_SHIFT; +//ust// buf_page->buf = buf; +//ust// set_page_private(buf_page->page, (unsigned long)buf_page); +//ust// if (i == 0) { +//ust// buf->wpage = buf_page; +//ust// buf->hpage[0] = buf_page; +//ust// buf->hpage[1] = buf_page; +//ust// buf->rpage = buf_page; +//ust// } +//ust// } +//ust// buf->page_count = n_pages; +//ust// return 0; +//ust// +//ust//depopulate: +//ust// list_for_each_entry_safe(buf_page, n, &buf->pages, list) { +//ust// list_del_init(&buf_page->list); +//ust// __free_page(buf_page->page); +//ust// kfree(buf_page); +//ust// } +//ust// return -ENOMEM; +//ust//} + static int relay_alloc_buf(struct rchan_buf *buf, size_t *size) { - unsigned int i, n_pages; + unsigned int n_pages; struct buf_page *buf_page, *n; + void *result; + *size = PAGE_ALIGN(*size); - n_pages = *size >> PAGE_SHIFT; - - INIT_LIST_HEAD(&buf->pages); - - for (i = 0; i < n_pages; i++) { - buf_page = kmalloc_node(sizeof(*buf_page), GFP_KERNEL, - cpu_to_node(buf->cpu)); - if (unlikely(!buf_page)) - goto depopulate; - buf_page->page = alloc_pages_node(cpu_to_node(buf->cpu), - GFP_KERNEL | __GFP_ZERO, 0); - if (unlikely(!buf_page->page)) { - kfree(buf_page); - goto depopulate; - } - list_add_tail(&buf_page->list, &buf->pages); - buf_page->offset = (size_t)i << PAGE_SHIFT; - buf_page->buf = buf; - set_page_private(buf_page->page, (unsigned long)buf_page); - if (i == 0) { - buf->wpage = buf_page; - buf->hpage[0] = buf_page; - buf->hpage[1] = buf_page; - buf->rpage = buf_page; - } - } - buf->page_count = n_pages; - return 0; -depopulate: - list_for_each_entry_safe(buf_page, n, &buf->pages, list) { - list_del_init(&buf_page->list); - __free_page(buf_page->page); - kfree(buf_page); + /* Maybe do read-ahead */ + result = mmap(NULL, *size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1, 0); + if(result == MAP_FAILED) { + PERROR("mmap"); + return -1; } - return -ENOMEM; + + buf->buf_data = result; + buf->buf_size = *size; + + return 0; } /** @@ -90,7 +118,7 @@ static struct rchan_buf *relay_create_buf(struct rchan *chan, int cpu) if (!buf) return NULL; - buf->cpu = cpu; +// buf->cpu = cpu; ret = relay_alloc_buf(buf, &chan->alloc_size); if (ret) goto free_buf; @@ -124,13 +152,13 @@ static void relay_destroy_buf(struct rchan_buf *buf) { struct rchan *chan = buf->chan; struct buf_page *buf_page, *n; + int result; - list_for_each_entry_safe(buf_page, n, &buf->pages, list) { - list_del_init(&buf_page->list); - __free_page(buf_page->page); - kfree(buf_page); - } - chan->buf[buf->cpu] = NULL; + result = munmap(buf->buf_data, buf->buf_size); + if(result == -1) { + PERROR("munmap"); + +//ust// chan->buf[buf->cpu] = NULL; kfree(buf); kref_put(&chan->kref, relay_destroy_channel); } @@ -238,12 +266,12 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan, unsigned int cpu) __relay_reset(buf, 1); /* Create file in fs */ - dentry = chan->cb->create_buf_file(tmpname, chan->parent, S_IRUSR, - buf); - if (!dentry) - goto free_buf; - - buf->dentry = dentry; +//ust// dentry = chan->cb->create_buf_file(tmpname, chan->parent, S_IRUSR, +//ust// buf); +//ust// if (!dentry) +//ust// goto free_buf; +//ust// +//ust// buf->dentry = dentry; goto free_name; @@ -293,39 +321,39 @@ static void setup_callbacks(struct rchan *chan, * * Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD) */ -static int __cpuinit relay_hotcpu_callback(struct notifier_block *nb, - unsigned long action, - void *hcpu) -{ - unsigned int hotcpu = (unsigned long)hcpu; - struct rchan *chan; - - switch (action) { - case CPU_UP_PREPARE: - case CPU_UP_PREPARE_FROZEN: - mutex_lock(&relay_channels_mutex); - list_for_each_entry(chan, &relay_channels, list) { - if (chan->buf[hotcpu]) - continue; - chan->buf[hotcpu] = relay_open_buf(chan, hotcpu); - if (!chan->buf[hotcpu]) { - printk(KERN_ERR - "relay_hotcpu_callback: cpu %d buffer " - "creation failed\n", hotcpu); - mutex_unlock(&relay_channels_mutex); - return NOTIFY_BAD; - } - } - mutex_unlock(&relay_channels_mutex); - break; - case CPU_DEAD: - case CPU_DEAD_FROZEN: - /* No need to flush the cpu : will be flushed upon - * final relay_flush() call. */ - break; - } - return NOTIFY_OK; -} +//ust// static int __cpuinit relay_hotcpu_callback(struct notifier_block *nb, +//ust// unsigned long action, +//ust// void *hcpu) +//ust// { +//ust// unsigned int hotcpu = (unsigned long)hcpu; +//ust// struct rchan *chan; +//ust// +//ust// switch (action) { +//ust// case CPU_UP_PREPARE: +//ust// case CPU_UP_PREPARE_FROZEN: +//ust// mutex_lock(&relay_channels_mutex); +//ust// list_for_each_entry(chan, &relay_channels, list) { +//ust// if (chan->buf[hotcpu]) +//ust// continue; +//ust// chan->buf[hotcpu] = relay_open_buf(chan, hotcpu); +//ust// if (!chan->buf[hotcpu]) { +//ust// printk(KERN_ERR +//ust// "relay_hotcpu_callback: cpu %d buffer " +//ust// "creation failed\n", hotcpu); +//ust// mutex_unlock(&relay_channels_mutex); +//ust// return NOTIFY_BAD; +//ust// } +//ust// } +//ust// mutex_unlock(&relay_channels_mutex); +//ust// break; +//ust// case CPU_DEAD: +//ust// case CPU_DEAD_FROZEN: +//ust// /* No need to flush the cpu : will be flushed upon +//ust// * final relay_flush() call. */ +//ust// break; +//ust// } +//ust// return NOTIFY_OK; +//ust// } /** * ltt_relay_open - create a new relay channel @@ -574,16 +602,16 @@ EXPORT_SYMBOL_GPL(ltt_relay_read); * @buf : buffer * @offset : offset within the buffer */ -struct buf_page *ltt_relay_read_get_page(struct rchan_buf *buf, size_t offset) -{ - struct buf_page *page; +//ust// struct buf_page *ltt_relay_read_get_page(struct rchan_buf *buf, size_t offset) +//ust// { +//ust// struct buf_page *page; - offset &= buf->chan->alloc_size - 1; - page = buf->rpage; - page = ltt_relay_cache_page(buf, &buf->rpage, page, offset); - return page; -} -EXPORT_SYMBOL_GPL(ltt_relay_read_get_page); +//ust// offset &= buf->chan->alloc_size - 1; +//ust// page = buf->rpage; +//ust// page = ltt_relay_cache_page(buf, &buf->rpage, page, offset); +//ust// return page; +//ust// } +//ust// EXPORT_SYMBOL_GPL(ltt_relay_read_get_page); /** * ltt_relay_offset_address - get address of a location within the buffer @@ -608,7 +636,7 @@ void *ltt_relay_offset_address(struct rchan_buf *buf, size_t offset) page = ltt_relay_cache_page(buf, &buf->hpage[odd], page, offset); return page_address(page->page) + (offset & ~PAGE_MASK); } -EXPORT_SYMBOL_GPL(ltt_relay_offset_address); +//ust// EXPORT_SYMBOL_GPL(ltt_relay_offset_address); /** * relay_file_open - open file op for relay files @@ -617,14 +645,14 @@ EXPORT_SYMBOL_GPL(ltt_relay_offset_address); * * Increments the channel buffer refcount. */ -static int relay_file_open(struct inode *inode, struct file *filp) -{ - struct rchan_buf *buf = inode->i_private; - kref_get(&buf->kref); - filp->private_data = buf; - - return nonseekable_open(inode, filp); -} +//ust// static int relay_file_open(struct inode *inode, struct file *filp) +//ust// { +//ust// struct rchan_buf *buf = inode->i_private; +//ust// kref_get(&buf->kref); +//ust// filp->private_data = buf; +//ust// +//ust// return nonseekable_open(inode, filp); +//ust// } /** * relay_file_release - release file op for relay files @@ -642,16 +670,16 @@ static int relay_file_release(struct inode *inode, struct file *filp) return 0; } -const struct file_operations ltt_relay_file_operations = { - .open = relay_file_open, - .release = relay_file_release, -}; -EXPORT_SYMBOL_GPL(ltt_relay_file_operations); +//ust// const struct file_operations ltt_relay_file_operations = { +//ust// .open = relay_file_open, +//ust// .release = relay_file_release, +//ust// }; +//ust// EXPORT_SYMBOL_GPL(ltt_relay_file_operations); -static __init int relay_init(void) -{ - hotcpu_notifier(relay_hotcpu_callback, 5); - return 0; -} +//ust// static __init int relay_init(void) +//ust// { +//ust// hotcpu_notifier(relay_hotcpu_callback, 5); +//ust// return 0; +//ust// } -module_init(relay_init); +//ust// module_init(relay_init); diff --git a/libtracing/relay.c b/libtracing/relay.c index f8bff41..ac2008c 100644 --- a/libtracing/relay.c +++ b/libtracing/relay.c @@ -130,7 +130,7 @@ static inline int last_tsc_overflow(struct ltt_channel_buf_struct *ltt_buf, } #endif -static struct file_operations ltt_file_operations; +//ust// static struct file_operations ltt_file_operations; /* * A switch is done during tracing or as a final flush after tracing (so it @@ -209,7 +209,7 @@ static struct dentry *ltt_create_buf_file_callback(const char *filename, { struct ltt_channel_struct *ltt_chan; int err; - struct dentry *dentry; +//ust// struct dentry *dentry; ltt_chan = buf->chan->private_data; err = ltt_relay_create_buffer(ltt_chan->trace, ltt_chan, @@ -218,12 +218,12 @@ static struct dentry *ltt_create_buf_file_callback(const char *filename, if (err) return ERR_PTR(err); - dentry = debugfs_create_file(filename, mode, parent, buf, - <t_file_operations); - if (!dentry) - goto error; - return dentry; -error: +//ust// dentry = debugfs_create_file(filename, mode, parent, buf, +//ust// <t_file_operations); +//ust// if (!dentry) +//ust// goto error; +//ust// return dentry; +//ust//error: ltt_relay_destroy_buffer(ltt_chan, buf->cpu); return NULL; } @@ -233,7 +233,7 @@ static int ltt_remove_buf_file_callback(struct dentry *dentry) struct rchan_buf *buf = dentry->d_inode->i_private; struct ltt_channel_struct *ltt_chan = buf->chan->private_data; - debugfs_remove(dentry); +//ust// debugfs_remove(dentry); ltt_relay_destroy_buffer(ltt_chan, buf->cpu); return 0; @@ -448,79 +448,79 @@ static int ltt_do_put_subbuf(struct rchan_buf *buf, struct ltt_channel_buf_struc * RELAY_GET_SUBBUF_SIZE * returns the size of the sub buffers. */ -static int ltt_ioctl(struct inode *inode, struct file *filp, - unsigned int cmd, unsigned long arg) -{ - struct rchan_buf *buf = inode->i_private; - struct ltt_channel_struct *ltt_channel = - (struct ltt_channel_struct *)buf->chan->private_data; - struct ltt_channel_buf_struct *ltt_buf = - percpu_ptr(ltt_channel->buf, buf->cpu); - u32 __user *argp = (u32 __user *)arg; - - WARN_ON(atomic_long_read(<t_buf->active_readers) != 1); - switch (cmd) { - case RELAY_GET_SUBBUF: - { - int ret; - ret = ltt_do_get_subbuf(buf, ltt_buf, &consumed_old); - if(ret < 0) - return ret; - return put_user((u32)consumed_old, argp); - } - case RELAY_PUT_SUBBUF: - { - int ret; - u32 uconsumed_old; - ret = get_user(uconsumed_old, argp); - if (ret) - return ret; /* will return -EFAULT */ - return ltt_do_put_subbuf(buf, ltt_buf, uconsumed_old); - } - case RELAY_GET_N_SUBBUFS: - return put_user((u32)buf->chan->n_subbufs, argp); - break; - case RELAY_GET_SUBBUF_SIZE: - return put_user((u32)buf->chan->subbuf_size, argp); - break; - default: - return -ENOIOCTLCMD; - } - return 0; -} - -#ifdef CONFIG_COMPAT -static long ltt_compat_ioctl(struct file *file, unsigned int cmd, - unsigned long arg) -{ - long ret = -ENOIOCTLCMD; - - lock_kernel(); - ret = ltt_ioctl(file->f_dentry->d_inode, file, cmd, arg); - unlock_kernel(); - - return ret; -} -#endif - -static void ltt_relay_pipe_buf_release(struct pipe_inode_info *pipe, - struct pipe_buffer *pbuf) -{ -} - -static struct pipe_buf_operations ltt_relay_pipe_buf_ops = { - .can_merge = 0, - .map = generic_pipe_buf_map, - .unmap = generic_pipe_buf_unmap, - .confirm = generic_pipe_buf_confirm, - .release = ltt_relay_pipe_buf_release, - .steal = generic_pipe_buf_steal, - .get = generic_pipe_buf_get, -}; - -static void ltt_relay_page_release(struct splice_pipe_desc *spd, unsigned int i) -{ -} +//ust// static int ltt_ioctl(struct inode *inode, struct file *filp, +//ust// unsigned int cmd, unsigned long arg) +//ust// { +//ust// struct rchan_buf *buf = inode->i_private; +//ust// struct ltt_channel_struct *ltt_channel = +//ust// (struct ltt_channel_struct *)buf->chan->private_data; +//ust// struct ltt_channel_buf_struct *ltt_buf = +//ust// percpu_ptr(ltt_channel->buf, buf->cpu); +//ust// u32 __user *argp = (u32 __user *)arg; +//ust// +//ust// WARN_ON(atomic_long_read(<t_buf->active_readers) != 1); +//ust// switch (cmd) { +//ust// case RELAY_GET_SUBBUF: +//ust// { +//ust// int ret; +//ust// ret = ltt_do_get_subbuf(buf, ltt_buf, &consumed_old); +//ust// if(ret < 0) +//ust// return ret; +//ust// return put_user((u32)consumed_old, argp); +//ust// } +//ust// case RELAY_PUT_SUBBUF: +//ust// { +//ust// int ret; +//ust// u32 uconsumed_old; +//ust// ret = get_user(uconsumed_old, argp); +//ust// if (ret) +//ust// return ret; /* will return -EFAULT */ +//ust// return ltt_do_put_subbuf(buf, ltt_buf, uconsumed_old); +//ust// } +//ust// case RELAY_GET_N_SUBBUFS: +//ust// return put_user((u32)buf->chan->n_subbufs, argp); +//ust// break; +//ust// case RELAY_GET_SUBBUF_SIZE: +//ust// return put_user((u32)buf->chan->subbuf_size, argp); +//ust// break; +//ust// default: +//ust// return -ENOIOCTLCMD; +//ust// } +//ust// return 0; +//ust// } + +//ust// #ifdef CONFIG_COMPAT +//ust// static long ltt_compat_ioctl(struct file *file, unsigned int cmd, +//ust// unsigned long arg) +//ust// { +//ust// long ret = -ENOIOCTLCMD; +//ust// +//ust// lock_kernel(); +//ust// ret = ltt_ioctl(file->f_dentry->d_inode, file, cmd, arg); +//ust// unlock_kernel(); +//ust// +//ust// return ret; +//ust// } +//ust// #endif + +//ust// static void ltt_relay_pipe_buf_release(struct pipe_inode_info *pipe, +//ust// struct pipe_buffer *pbuf) +//ust// { +//ust// } +//ust// +//ust// static struct pipe_buf_operations ltt_relay_pipe_buf_ops = { +//ust// .can_merge = 0, +//ust// .map = generic_pipe_buf_map, +//ust// .unmap = generic_pipe_buf_unmap, +//ust// .confirm = generic_pipe_buf_confirm, +//ust// .release = ltt_relay_pipe_buf_release, +//ust// .steal = generic_pipe_buf_steal, +//ust// .get = generic_pipe_buf_get, +//ust// }; + +//ust// static void ltt_relay_page_release(struct splice_pipe_desc *spd, unsigned int i) +//ust// { +//ust// } /* * subbuf_splice_actor - splice up to one subbuf's worth of data @@ -711,10 +711,10 @@ static void ltt_relay_print_buffer_errors(struct ltt_channel_struct *ltt_chan, ltt_relay_print_errors(trace, ltt_chan, cpu); } -static void ltt_relay_remove_dirs(struct ltt_trace_struct *trace) -{ - debugfs_remove(trace->dentry.trace_root); -} +//ust// static void ltt_relay_remove_dirs(struct ltt_trace_struct *trace) +//ust// { +//ust// debugfs_remove(trace->dentry.trace_root); +//ust// } static void ltt_relay_release_channel(struct kref *kref) { @@ -726,38 +726,71 @@ static void ltt_relay_release_channel(struct kref *kref) /* * Create ltt buffer. */ +//ust// static int ltt_relay_create_buffer(struct ltt_trace_struct *trace, +//ust// struct ltt_channel_struct *ltt_chan, struct rchan_buf *buf, +//ust// unsigned int cpu, unsigned int n_subbufs) +//ust// { +//ust// struct ltt_channel_buf_struct *ltt_buf = +//ust// percpu_ptr(ltt_chan->buf, cpu); +//ust// unsigned int j; +//ust// +//ust// ltt_buf->commit_count = +//ust// kzalloc_node(sizeof(ltt_buf->commit_count) * n_subbufs, +//ust// GFP_KERNEL, cpu_to_node(cpu)); +//ust// if (!ltt_buf->commit_count) +//ust// return -ENOMEM; +//ust// kref_get(&trace->kref); +//ust// kref_get(&trace->ltt_transport_kref); +//ust// kref_get(<t_chan->kref); +//ust// local_set(<t_buf->offset, ltt_subbuffer_header_size()); +//ust// atomic_long_set(<t_buf->consumed, 0); +//ust// atomic_long_set(<t_buf->active_readers, 0); +//ust// for (j = 0; j < n_subbufs; j++) +//ust// local_set(<t_buf->commit_count[j], 0); +//ust// init_waitqueue_head(<t_buf->write_wait); +//ust// atomic_set(<t_buf->wakeup_readers, 0); +//ust// spin_lock_init(<t_buf->full_lock); +//ust// +//ust// ltt_buffer_begin_callback(buf, trace->start_tsc, 0); +//ust// /* atomic_add made on local variable on data that belongs to +//ust// * various CPUs : ok because tracing not started (for this cpu). */ +//ust// local_add(ltt_subbuffer_header_size(), <t_buf->commit_count[0]); +//ust// +//ust// local_set(<t_buf->events_lost, 0); +//ust// local_set(<t_buf->corrupted_subbuffers, 0); +//ust// +//ust// return 0; +//ust// } + static int ltt_relay_create_buffer(struct ltt_trace_struct *trace, struct ltt_channel_struct *ltt_chan, struct rchan_buf *buf, unsigned int cpu, unsigned int n_subbufs) { - struct ltt_channel_buf_struct *ltt_buf = - percpu_ptr(ltt_chan->buf, cpu); + struct ltt_channel_buf_struct *ltt_buf = ltt_chan->buf; unsigned int j; ltt_buf->commit_count = - kzalloc_node(sizeof(ltt_buf->commit_count) * n_subbufs, - GFP_KERNEL, cpu_to_node(cpu)); + malloc(sizeof(ltt_buf->commit_count) * n_subbufs); if (!ltt_buf->commit_count) return -ENOMEM; kref_get(&trace->kref); kref_get(&trace->ltt_transport_kref); kref_get(<t_chan->kref); - local_set(<t_buf->offset, ltt_subbuffer_header_size()); + ltt_buf->offset = ltt_subbuffer_header_size(); atomic_long_set(<t_buf->consumed, 0); atomic_long_set(<t_buf->active_readers, 0); for (j = 0; j < n_subbufs; j++) local_set(<t_buf->commit_count[j], 0); - init_waitqueue_head(<t_buf->write_wait); +//ust// init_waitqueue_head(<t_buf->write_wait); atomic_set(<t_buf->wakeup_readers, 0); spin_lock_init(<t_buf->full_lock); ltt_buffer_begin_callback(buf, trace->start_tsc, 0); - /* atomic_add made on local variable on data that belongs to - * various CPUs : ok because tracing not started (for this cpu). */ - local_add(ltt_subbuffer_header_size(), <t_buf->commit_count[0]); - local_set(<t_buf->events_lost, 0); - local_set(<t_buf->corrupted_subbuffers, 0); + ltt_buf->commit_count[0] += ltt_subbuffer_header_size(); + + ltt_buf->events_lost = 0; + ltt_buf->corrupted_subbuffers = 0; return 0; } @@ -845,21 +878,21 @@ end: return err; } -static int ltt_relay_create_dirs(struct ltt_trace_struct *new_trace) -{ - new_trace->dentry.trace_root = debugfs_create_dir(new_trace->trace_name, - get_ltt_root()); - if (new_trace->dentry.trace_root == NULL) { - printk(KERN_ERR "LTT : Trace directory name %s already taken\n", - new_trace->trace_name); - return EEXIST; - } - - new_trace->callbacks.create_buf_file = ltt_create_buf_file_callback; - new_trace->callbacks.remove_buf_file = ltt_remove_buf_file_callback; - - return 0; -} +//ust// static int ltt_relay_create_dirs(struct ltt_trace_struct *new_trace) +//ust// { +//ust// new_trace->dentry.trace_root = debugfs_create_dir(new_trace->trace_name, +//ust// get_ltt_root()); +//ust// if (new_trace->dentry.trace_root == NULL) { +//ust// printk(KERN_ERR "LTT : Trace directory name %s already taken\n", +//ust// new_trace->trace_name); +//ust// return EEXIST; +//ust// } +//ust// +//ust// new_trace->callbacks.create_buf_file = ltt_create_buf_file_callback; +//ust// new_trace->callbacks.remove_buf_file = ltt_remove_buf_file_callback; +//ust// +//ust// return 0; +//ust// } /* * LTTng channel flush function. @@ -1619,8 +1652,25 @@ static void ltt_relay_print_user_errors(struct ltt_trace_struct *trace, dbg->write, dbg->read); } -static struct ltt_transport ltt_relay_transport = { - .name = "relay", +//ust// static struct ltt_transport ltt_relay_transport = { +//ust// .name = "relay", +//ust// .owner = THIS_MODULE, +//ust// .ops = { +//ust// .create_dirs = ltt_relay_create_dirs, +//ust// .remove_dirs = ltt_relay_remove_dirs, +//ust// .create_channel = ltt_relay_create_channel, +//ust// .finish_channel = ltt_relay_finish_channel, +//ust// .remove_channel = ltt_relay_remove_channel, +//ust// .wakeup_channel = ltt_relay_async_wakeup_chan, +//ust// .commit_slot = ltt_relay_commit_slot, +//ust// .reserve_slot = ltt_relay_reserve_slot, +//ust// .user_blocking = ltt_relay_user_blocking, +//ust// .user_errors = ltt_relay_print_user_errors, +//ust// }, +//ust// }; + +static struct ltt_transport ust_relay_transport = { + .name = "ustrelay", .owner = THIS_MODULE, .ops = { .create_dirs = ltt_relay_create_dirs, @@ -1636,36 +1686,41 @@ static struct ltt_transport ltt_relay_transport = { }, }; -static int __init ltt_relay_init(void) +//ust// static int __init ltt_relay_init(void) +//ust// { +//ust// printk(KERN_INFO "LTT : ltt-relay init\n"); +//ust// +//ust// ltt_file_operations = ltt_relay_file_operations; +//ust// ltt_file_operations.owner = THIS_MODULE; +//ust// ltt_file_operations.open = ltt_open; +//ust// ltt_file_operations.release = ltt_release; +//ust// ltt_file_operations.poll = ltt_poll; +//ust// ltt_file_operations.splice_read = ltt_relay_file_splice_read, +//ust// ltt_file_operations.ioctl = ltt_ioctl; +//ust//#ifdef CONFIG_COMPAT +//ust// ltt_file_operations.compat_ioctl = ltt_compat_ioctl; +//ust//#endif +//ust// +//ust// ltt_transport_register(<t_relay_transport); +//ust// +//ust// return 0; +//ust// } + +void init_ustrelay_transport(void) { - printk(KERN_INFO "LTT : ltt-relay init\n"); - - ltt_file_operations = ltt_relay_file_operations; - ltt_file_operations.owner = THIS_MODULE; - ltt_file_operations.open = ltt_open; - ltt_file_operations.release = ltt_release; - ltt_file_operations.poll = ltt_poll; - ltt_file_operations.splice_read = ltt_relay_file_splice_read, - ltt_file_operations.ioctl = ltt_ioctl; -#ifdef CONFIG_COMPAT - ltt_file_operations.compat_ioctl = ltt_compat_ioctl; -#endif - - ltt_transport_register(<t_relay_transport); - - return 0; + ltt_transport_register(&ust_relay_transport); } static void __exit ltt_relay_exit(void) { - printk(KERN_INFO "LTT : ltt-relay exit\n"); +//ust// printk(KERN_INFO "LTT : ltt-relay exit\n"); ltt_transport_unregister(<t_relay_transport); } -module_init(ltt_relay_init); -module_exit(ltt_relay_exit); - -MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Mathieu Desnoyers"); -MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Lockless Relay"); +//ust// module_init(ltt_relay_init); +//ust// module_exit(ltt_relay_exit); +//ust// +//ust// MODULE_LICENSE("GPL"); +//ust// MODULE_AUTHOR("Mathieu Desnoyers"); +//ust// MODULE_DESCRIPTION("Linux Trace Toolkit Next Generation Lockless Relay"); diff --git a/libtracing/tracer.c b/libtracing/tracer.c index 2dfde4a..012acea 100644 --- a/libtracing/tracer.c +++ b/libtracing/tracer.c @@ -204,19 +204,19 @@ static LIST_HEAD(ltt_transport_list); * vmalloc_sync_all. Therefore, only if the module allocates virtual memory * after its registration must it synchronize the TLBs. */ -//ust// void ltt_transport_register(struct ltt_transport *transport) -//ust// { -//ust// /* -//ust// * Make sure no page fault can be triggered by the module about to be -//ust// * registered. We deal with this here so we don't have to call -//ust// * vmalloc_sync_all() in each module's init. -//ust// */ -//ust// vmalloc_sync_all(); -//ust// -//ust// ltt_lock_traces(); -//ust// list_add_tail(&transport->node, <t_transport_list); -//ust// ltt_unlock_traces(); -//ust// } +void ltt_transport_register(struct ltt_transport *transport) +{ + /* + * Make sure no page fault can be triggered by the module about to be + * registered. We deal with this here so we don't have to call + * vmalloc_sync_all() in each module's init. + */ + vmalloc_sync_all(); + + ltt_lock_traces(); + list_add_tail(&transport->node, <t_transport_list); + ltt_unlock_traces(); +} //ust// EXPORT_SYMBOL_GPL(ltt_transport_register); /** diff --git a/libtracing/tracer.h b/libtracing/tracer.h index 6e98f2b..3143ab1 100644 --- a/libtracing/tracer.h +++ b/libtracing/tracer.h @@ -150,9 +150,9 @@ struct ltt_trace_ops { void **transport_data, long buf_offset, size_t slot_size); void (*wakeup_channel) (struct ltt_channel_struct *ltt_channel); - int (*user_blocking) (struct ltt_trace_struct *trace, - unsigned int index, size_t data_size, - struct user_dbg_data *dbg); +//ust// int (*user_blocking) (struct ltt_trace_struct *trace, +//ust// unsigned int index, size_t data_size, +//ust// struct user_dbg_data *dbg); //ust// /* End of first 32 bytes cacheline */ //ust// int (*create_dirs) (struct ltt_trace_struct *new_trace); //ust// void (*remove_dirs) (struct ltt_trace_struct *new_trace); diff --git a/share/kernelcompat.h b/share/kernelcompat.h index 5bd8e87..6bc09ca 100644 --- a/share/kernelcompat.h +++ b/share/kernelcompat.h @@ -124,9 +124,15 @@ static int atomic_read(atomic_t *p) return p->counter; } -/* CACHE */ +/* LOCAL OPS */ + + + +/* ATTRIBUTES */ #define ____cacheline_aligned +#define __init +#define __exit /* MATH */ @@ -166,6 +172,18 @@ static __inline__ int get_count_order(unsigned int count) } + + +#include + +#define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1) +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) +#define PAGE_SIZE sysconf(_SC_PAGE_SIZE) + + + + /* ARRAYS */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/share/usterr.h b/share/usterr.h index 2ab3662..a2f915b 100644 --- a/share/usterr.h +++ b/share/usterr.h @@ -7,6 +7,6 @@ #define PERROR(call) perror("usertrace: ERROR: " call) #define BUG_ON(condition) do { if (unlikely(condition)) ERR("condition not respected (BUG)"); } while(0) -#define WARN_ON(condition) do { if (unlikely(condition)) WARN("condition not respected"); } while(0) +#define WARN_ON(condition) do { if (unlikely(condition)) WARN("condition not respected on line %s:%d", __FILE__, __LINE__); } while(0) #endif /* USTERR_H */ -- 2.34.1