Move kernelcompat.h to include/ust/ and share.h, usterr.h to include/
[ust.git] / libust / relay.c
index 4c57424a5ba9392f14b0a93b0bf980c6fb712694..408ce906f82c7f0262d71c2ea59270790f82b052 100644 (file)
 //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 <fcntl.h>
 //#include "list.h"
 #include "relay.h"
 #include "channels.h"
@@ -101,7 +102,11 @@ static int relay_alloc_buf(struct rchan_buf *buf, size_t *size)
        *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;
        }
@@ -182,7 +187,7 @@ static void relay_destroy_channel(struct kref *kref)
 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);
@@ -222,21 +227,21 @@ static void relay_remove_buf(struct kref *kref)
 /*
  * 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
@@ -263,7 +268,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
 //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;
@@ -277,7 +282,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
 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);
@@ -304,12 +309,12 @@ static struct rchan_buf *relay_open_buf(struct rchan *chan)
 
        goto free_name;
 
-free_buf:
+//ust//free_buf:
        relay_destroy_buf(buf);
        buf = NULL;
 free_name:
 //ust//        kfree(tmpname);
-end:
+//ust//end:
        return buf;
 }
 
@@ -406,7 +411,7 @@ struct rchan *ltt_relay_open(const char *base_filename,
                         size_t n_subbufs,
                         void *private_data)
 {
-       unsigned int i;
+//ust//        unsigned int i;
        struct rchan *chan;
 //ust//        if (!base_filename)
 //ust//                return NULL;
@@ -462,7 +467,7 @@ struct rchan *ltt_relay_open(const char *base_filename,
  */
 void ltt_relay_close(struct rchan *chan)
 {
-       unsigned int i;
+//ust//        unsigned int i;
 
        if (!chan)
                return;
@@ -929,16 +934,16 @@ static struct dentry *ltt_create_buf_file_callback(struct rchan_buf *buf)
        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 :
@@ -1499,6 +1504,12 @@ static int ltt_relay_create_buffer(struct ltt_trace_struct *trace,
        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;
@@ -1537,7 +1548,7 @@ static void ltt_chan_alloc_ltt_buf(struct ltt_channel_struct *ltt_chan)
        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);
@@ -1552,12 +1563,12 @@ static void ltt_chan_alloc_ltt_buf(struct ltt_channel_struct *ltt_chan)
        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);
@@ -1565,7 +1576,7 @@ static void ltt_chan_alloc_ltt_buf(struct ltt_channel_struct *ltt_chan)
                perror("shmctl");
        }
 
-       return -1;
+       return;
 }
 
 /*
@@ -1694,7 +1705,7 @@ static void ltt_relay_async_wakeup_chan(struct ltt_channel_struct *ltt_channel)
 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;
@@ -1714,7 +1725,7 @@ static void ltt_relay_finish_buffer(struct ltt_channel_struct *ltt_channel)
 
 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);
@@ -1787,13 +1798,24 @@ static inline int ltt_relay_try_reserve(
                        - (local_read(&ltt_buf->commit_count[subbuf_index])
                                & ltt_channel->commit_count_mask);
                if (offsets->reserve_commit_diff == 0) {
+                       long consumed;
+
+                       consumed = atomic_long_read(&ltt_buf->consumed);
+
                        /* Next buffer not corrupted. */
                        if (!ltt_channel->overwrite &&
                                (SUBBUF_TRUNC(offsets->begin, buf->chan)
-                                - SUBBUF_TRUNC(atomic_long_read(
-                                                       &ltt_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(&ltt_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.
@@ -2466,8 +2488,6 @@ static /* inline */ void ltt_write_commit_counter(struct rchan_buf *buf,
         */
        ltt_write_commit_counter(buf, ltt_buf, endidx,
                                 buf_offset, commit_count, data_size);
-
-       DBG("commited slot. now commit count is %ld", commit_count);
 }
 
 
@@ -2481,7 +2501,7 @@ void __attribute__((constructor)) init_ustrelay_transport(void)
        }
 }
 
-static void __exit ltt_relay_exit(void)
+static void __attribute__((destructor)) ltt_relay_exit(void)
 {
 //ust//        printk(KERN_INFO "LTT : ltt-relay exit\n");
 
This page took 0.026911 seconds and 4 git commands to generate.