//ust// #include <linux/cpu.h>
//ust// #include <linux/splice.h>
//ust// #include <linux/bitops.h>
-#include "kernelcompat.h"
+#include <ust/kernelcompat.h>
#include <sys/mman.h>
#include <sys/ipc.h>
#include <sys/shm.h>
-#include "list.h"
+#include <fcntl.h>
+//#include "list.h"
#include "relay.h"
#include "channels.h"
-#include "kref.h"
+#include <kcompat/kref.h>
#include "tracer.h"
#include "tracercore.h"
#include "usterr.h"
*size = PAGE_ALIGN(*size);
result = buf->shmid = shmget(getpid(), *size, IPC_CREAT | IPC_EXCL | 0700);
- if(buf->shmid == -1) {
+ if(result == -1 && errno == EINVAL) {
+ ERR("shmget() returned EINVAL; maybe /proc/sys/kernel/shmmax should be increased.");
+ return -1;
+ }
+ else if(result == -1) {
PERROR("shmget");
return -1;
}
static void relay_destroy_buf(struct rchan_buf *buf)
{
struct rchan *chan = buf->chan;
- struct buf_page *buf_page, *n;
+//ust// struct buf_page *buf_page;
int result;
result = munmap(buf->buf_data, buf->buf_size);
/*
* create_buf_file_create() default callback. Does nothing.
*/
-static struct dentry *create_buf_file_default_callback(const char *filename,
- struct dentry *parent,
- int mode,
- struct rchan_buf *buf)
-{
- return NULL;
-}
+//ust// static struct dentry *create_buf_file_default_callback(const char *filename,
+//ust// struct dentry *parent,
+//ust// int mode,
+//ust// struct rchan_buf *buf)
+//ust// {
+//ust// return NULL;
+//ust// }
-/*
- * remove_buf_file() default callback. Does nothing.
- */
-static int remove_buf_file_default_callback(struct dentry *dentry)
-{
- return -EINVAL;
-}
+//ust// /*
+//ust// * remove_buf_file() default callback. Does nothing.
+//ust// */
+//ust// static int remove_buf_file_default_callback(struct dentry *dentry)
+//ust// {
+//ust// return -EINVAL;
+//ust// }
/**
* wakeup_readers - wake up readers waiting on a channel
//ust// init_waitqueue_head(&buf->read_wait);
kref_init(&buf->kref);
//ust// setup_timer(&buf->timer, wakeup_readers, (unsigned long)buf);
- } else
+ } //ust// else
//ust// del_timer_sync(&buf->timer);
buf->finalized = 0;
static struct rchan_buf *relay_open_buf(struct rchan *chan)
{
struct rchan_buf *buf = NULL;
- struct dentry *dentry;
+//ust// struct dentry *dentry;
//ust// char *tmpname;
//ust// tmpname = kzalloc(NAME_MAX + 1, GFP_KERNEL);
goto free_name;
-free_buf:
+//ust//free_buf:
relay_destroy_buf(buf);
buf = NULL;
free_name:
//ust// kfree(tmpname);
-end:
+//ust//end:
return buf;
}
size_t n_subbufs,
void *private_data)
{
- unsigned int i;
+//ust// unsigned int i;
struct rchan *chan;
//ust// if (!base_filename)
//ust// return NULL;
*/
void ltt_relay_close(struct rchan *chan)
{
- unsigned int i;
+//ust// unsigned int i;
if (!chan)
return;
return NULL;
}
-static int ltt_remove_buf_file_callback(struct rchan_buf *buf)
-{
-//ust// struct rchan_buf *buf = dentry->d_inode->i_private;
- struct ltt_channel_struct *ltt_chan = buf->chan->private_data;
-
-//ust// debugfs_remove(dentry);
- ltt_relay_destroy_buffer(ltt_chan);
-
- return 0;
-}
+//ust// static int ltt_remove_buf_file_callback(struct rchan_buf *buf)
+//ust// {
+//ust// //ust// struct rchan_buf *buf = dentry->d_inode->i_private;
+//ust// struct ltt_channel_struct *ltt_chan = buf->chan->private_data;
+//ust//
+//ust// //ust// debugfs_remove(dentry);
+//ust// ltt_relay_destroy_buffer(ltt_chan);
+//ust//
+//ust// return 0;
+//ust// }
/*
* Wake writers :
ltt_buf->data_ready_fd_read = fds[0];
ltt_buf->data_ready_fd_write = fds[1];
+ /* FIXME: do we actually need this? */
+ result = fcntl(fds[0], F_SETFL, O_NONBLOCK);
+ if(result == -1) {
+ PERROR("fcntl");
+ }
+
//ust// ltt_buf->commit_seq = malloc(sizeof(ltt_buf->commit_seq) * n_subbufs);
//ust// if(!ltt_buf->commit_seq) {
//ust// return -1;
result = ltt_chan->buf_shmid = shmget(getpid(), size, IPC_CREAT | IPC_EXCL | 0700);
if(ltt_chan->buf_shmid == -1) {
PERROR("shmget");
- return -1;
+ return;
}
ptr = shmat(ltt_chan->buf_shmid, NULL, 0);
result = shmctl(ltt_chan->buf_shmid, IPC_RMID, NULL);
if(result == -1) {
perror("shmctl");
- return -1;
+ return;
}
ltt_chan->buf = ptr;
- return 0;
+ return;
destroy_shmem:
result = shmctl(ltt_chan->buf_shmid, IPC_RMID, NULL);
perror("shmctl");
}
- return -1;
+ return;
}
/*
static void ltt_relay_finish_buffer(struct ltt_channel_struct *ltt_channel)
{
struct rchan *rchan = ltt_channel->trans_channel_data;
- int result;
+// int result;
if (rchan->buf) {
struct ltt_channel_buf_struct *ltt_buf = ltt_channel->buf;
static void ltt_relay_finish_channel(struct ltt_channel_struct *ltt_channel)
{
- unsigned int i;
+//ust// unsigned int i;
//ust// for_each_possible_cpu(i)
ltt_relay_finish_buffer(ltt_channel);
- (local_read(<t_buf->commit_count[subbuf_index])
& ltt_channel->commit_count_mask);
if (offsets->reserve_commit_diff == 0) {
+ long consumed;
+
+ consumed = atomic_long_read(<t_buf->consumed);
+
/* Next buffer not corrupted. */
if (!ltt_channel->overwrite &&
(SUBBUF_TRUNC(offsets->begin, buf->chan)
- - SUBBUF_TRUNC(atomic_long_read(
- <t_buf->consumed),
- buf->chan))
+ - SUBBUF_TRUNC(consumed, buf->chan))
>= rchan->alloc_size) {
+
+ long consumed_idx = SUBBUF_INDEX(consumed, buf->chan);
+ long commit_count = local_read(<t_buf->commit_count[consumed_idx]);
+ if(((commit_count - buf->chan->subbuf_size) & ltt_channel->commit_count_mask) - (BUFFER_TRUNC(consumed, buf->chan) >> ltt_channel->n_subbufs_order) != 0) {
+ WARN("Event dropped. Caused by non-committed event.");
+ }
+ else {
+ WARN("Event dropped. Caused by non-consumed buffer.");
+ }
/*
* We do not overwrite non consumed buffers
* and we are full : event is lost.
*/
ltt_write_commit_counter(buf, ltt_buf, endidx,
buf_offset, commit_count, data_size);
-
- DBG("commited slot. now commit count is %ld", commit_count);
}
}
}
-static void __exit ltt_relay_exit(void)
+static void __attribute__((destructor)) ltt_relay_exit(void)
{
//ust// printk(KERN_INFO "LTT : ltt-relay exit\n");