Move kernelcompat.h to include/ust/ and share.h, usterr.h to include/
[ust.git] / libust / relay.c
index 1235a9a7cd481a17dd5dd9adc3bebed76e879826..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;
        }
@@ -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;
@@ -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;
@@ -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);
 }
 
 
This page took 0.02486 seconds and 4 git commands to generate.