0.8.28
[lttv.git] / usertrace-fast / ltt / ltt-usertrace-fast.h
index a175d895d8d2c21d13828273ceabb6bceaea13c2..45b8b6c0cf805abbd24fa4de3dcdbba331068fa5 100644 (file)
 #include <pthread.h>
 #include <stdint.h>
 #include <syscall.h>
-#include <linux/futex.h>
 #include <asm/timex.h>
+#include <semaphore.h>
+#include <signal.h>
 
 #include <ltt/ltt-facility-id-user_generic.h>
 #include <ltt/ltt-generic.h>
 
-#ifndef futex
-static inline __attribute__((no_instrument_function))
-       _syscall6(long, futex, unsigned long, uaddr, int, op, int, val,
-               unsigned long, timeout, unsigned long, uaddr2, int, val2)
-#endif //futex
-
-
-
 #ifndef        LTT_N_SUBBUFS
 #define LTT_N_SUBBUFS 2
 #endif //LTT_N_SUBBUFS
 
-#ifndef        LTT_SUBBUF_SIZE_CPU
-#define LTT_SUBBUF_SIZE_CPU 1048576
+#ifndef        LTT_SUBBUF_SIZE_PROCESS
+#define LTT_SUBBUF_SIZE_PROCESS 1048576
 #endif //LTT_BUF_SIZE_CPU
 
-#define LTT_BUF_SIZE_CPU (LTT_SUBBUF_SIZE_CPU * LTT_N_SUBBUFS)
-
-#ifndef        LTT_SUBBUF_SIZE_FACILITIES
-#define LTT_SUBBUF_SIZE_FACILITIES 4096
-#endif //LTT_BUF_SIZE_FACILITIES
-
-#define LTT_BUF_SIZE_FACILITIES  (LTT_SUBBUF_SIZE_FACILITIES * LTT_N_SUBBUFS)
+#define LTT_BUF_SIZE_PROCESS (LTT_SUBBUF_SIZE_PROCESS * LTT_N_SUBBUFS)
 
 #ifndef LTT_USERTRACE_ROOT
 #define LTT_USERTRACE_ROOT "/tmp/ltt-usertrace"
@@ -118,7 +105,7 @@ struct ltt_buf {
 
        atomic_t        events_lost;
        atomic_t        corrupted_subbuffers;
-       atomic_t        full;   /* futex on which the writer waits : 1 : full */
+       sem_t   writer_sem;     /* semaphore on which the writer waits */
        unsigned int    alloc_size;
        unsigned int    subbuf_size;
 };
@@ -129,10 +116,8 @@ struct ltt_trace_info {
        pid_t daemon_id;
        int nesting;
        struct {
-               struct ltt_buf facilities;
-               struct ltt_buf cpu;
-               char facilities_buf[LTT_BUF_SIZE_FACILITIES] __attribute__ ((aligned (8)));
-               char cpu_buf[LTT_BUF_SIZE_CPU] __attribute__ ((aligned (8)));
+               struct ltt_buf process;
+               char process_buf[LTT_BUF_SIZE_PROCESS] __attribute__ ((aligned (8)));
        } channel;
 };
 
@@ -171,7 +156,7 @@ static inline unsigned int __attribute__((no_instrument_function))
                ltt_get_index_from_facility(ltt_facility_t fID,
                                                                                                                                uint8_t eID)
 {
-       return GET_CHANNEL_INDEX(cpu);
+       return GET_CHANNEL_INDEX(process);
 }
 
 
@@ -423,26 +408,37 @@ static inline void * __attribute__((no_instrument_function)) ltt_reserve_slot(
                                                                                                                                                                                 ltt_buf)]);
                        if(reserve_commit_diff == 0) {
                                /* Next buffer not corrupted. */
-                               if((SUBBUF_TRUNC(offset_begin, ltt_buf) 
-                                                               - SUBBUF_TRUNC(atomic_read(&ltt_buf->consumed), ltt_buf))
-                                                                       >= ltt_buf->alloc_size) {
-                                       /* We block until the reader unblocks us */
-                                       atomic_set(&ltt_buf->full, 1);
-                                       /* We block until the reader tells us to wake up.
-                                                Signals will simply cause this loop to restart.
-                                                */
-                                       do {
-                                               ret = futex((unsigned long)&ltt_buf->full, FUTEX_WAIT, 1, 0, 0, 0);
-                                       } while(ret != 0 && ret != EWOULDBLOCK);
+                               //if((SUBBUF_TRUNC(offset_begin, ltt_buf) 
+                               //                              - SUBBUF_TRUNC(atomic_read(&ltt_buf->consumed), ltt_buf))
+                               //                                      >= ltt_buf->alloc_size) {
+                               /* sem_wait is not signal safe. Disable signals around it. */
+                               {
+                                       sigset_t oldset, set;
+
+                                       /* Disable signals */
+                                       ret = sigfillset(&set);
+                                       if(ret) perror("LTT Error in sigfillset\n"); 
+                                       
+                                       ret = pthread_sigmask(SIG_BLOCK, &set, &oldset);
+                                       if(ret) perror("LTT Error in pthread_sigmask\n");
+
+                                       sem_wait(&ltt_buf->writer_sem);
+
+                                       /* Enable signals */
+                                       ret = pthread_sigmask(SIG_SETMASK, &oldset, NULL);
+                                       if(ret) perror("LTT Error in pthread_sigmask\n");
+                               }
+
                                        /* go on with the write */
 
-                               } else {
-                                       /* next buffer not corrupted, we are either in overwrite mode or
-                                        * the buffer is not full. It's safe to write in this new subbuffer.*/
-                               }
+                               //} else {
+                               //      /* next buffer not corrupted, we are either in overwrite mode or
+                               //       * the buffer is not full. It's safe to write in this new subbuffer.*/
+                               //}
                        } else {
                                /* Next subbuffer corrupted. Force pushing reader even in normal
                                 * mode. It's safe to write in this new subbuffer. */
+                               sem_post(&ltt_buf->writer_sem);
                        }
                        size = ltt_get_header_size(trace, ltt_buf->start + offset_begin,
                                        before_hdr_pad, after_hdr_pad, header_size) + data_size;
This page took 0.025794 seconds and 4 git commands to generate.