From 85b943204bb971fac3e1f0c52f304acbbc44641b Mon Sep 17 00:00:00 2001 From: compudj Date: Thu, 9 Mar 2006 14:00:19 +0000 Subject: [PATCH] use semaphore instead of futex git-svn-id: http://ltt.polymtl.ca/svn@1627 04897980-b3bd-0310-b5e0-8ef037075253 --- usertrace-fast/ltt-usertrace-fast.c | 24 ++++++++++++---------- usertrace-fast/ltt/ltt-usertrace-fast.h | 27 ++++--------------------- 2 files changed, 17 insertions(+), 34 deletions(-) diff --git a/usertrace-fast/ltt-usertrace-fast.c b/usertrace-fast/ltt-usertrace-fast.c index d722460b..edc37b85 100644 --- a/usertrace-fast/ltt-usertrace-fast.c +++ b/usertrace-fast/ltt-usertrace-fast.c @@ -319,14 +319,9 @@ static inline int ltt_buffer_put(struct ltt_buf *ltt_buf, * It can also happen if this is a buffer we never got. */ return -EIO; } else { - if(atomic_inc_return(<t_buf->writer_futex) <= 0) { - atomic_set(<t_buf->writer_futex, 1); - /* tell the client that buffer is now unfull */ - ret = futex((unsigned long)<t_buf->writer_futex, - FUTEX_WAKE, 1, 0, 0, 0); - if(ret != 1) { - dbg_printf("LTT warning : race condition : writer not waiting or too many writers\n"); - } + ret = sem_post(<t_buf->writer_sem); + if(ret < 0) { + printf("error in sem_post"); } } } @@ -471,6 +466,10 @@ static void ltt_usertrace_fast_daemon(struct ltt_trace_info *shared_trace_info, close(fd_process); + ret = sem_destroy(&shared_trace_info->channel.process.writer_sem); + if(ret < 0) { + perror("error in sem_destroy"); + } munmap(shared_trace_info, sizeof(*shared_trace_info)); exit(0); @@ -501,9 +500,12 @@ void ltt_rw_init(void) shared_trace_info->nesting=0; memset(&shared_trace_info->channel.process, 0, sizeof(shared_trace_info->channel.process)); - /* Tricky semaphore : is in a shared memory space, so it's ok for a fast - * mutex (futex). */ - atomic_set(&shared_trace_info->channel.process.writer_futex, LTT_N_SUBBUFS); + //Need NPTL! + ret = sem_init(&shared_trace_info->channel.process.writer_sem, 1, + LTT_N_SUBBUFS); + if(ret < 0) { + perror("error in sem_init"); + } shared_trace_info->channel.process.alloc_size = LTT_BUF_SIZE_PROCESS; shared_trace_info->channel.process.subbuf_size = LTT_SUBBUF_SIZE_PROCESS; shared_trace_info->channel.process.start = diff --git a/usertrace-fast/ltt/ltt-usertrace-fast.h b/usertrace-fast/ltt/ltt-usertrace-fast.h index 77e0594f..318eff6a 100644 --- a/usertrace-fast/ltt/ltt-usertrace-fast.h +++ b/usertrace-fast/ltt/ltt-usertrace-fast.h @@ -15,20 +15,12 @@ #include #include #include -#include #include +#include #include #include -#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 @@ -112,7 +104,7 @@ struct ltt_buf { atomic_t events_lost; atomic_t corrupted_subbuffers; - atomic_t writer_futex; /* futex on which the writer waits */ + sem_t writer_sem; /* semaphore on which the writer waits */ unsigned int alloc_size; unsigned int subbuf_size; }; @@ -418,19 +410,7 @@ static inline void * __attribute__((no_instrument_function)) ltt_reserve_slot( //if((SUBBUF_TRUNC(offset_begin, ltt_buf) // - SUBBUF_TRUNC(atomic_read(<t_buf->consumed), ltt_buf)) // >= ltt_buf->alloc_size) { - if(atomic_dec_return(<t_buf->writer_futex) >= 0) { - /* non contended */ - } else { - /* We block until the reader unblocks us */ - atomic_set(<t_buf->writer_futex, -1); - /* We block until the reader tells us to wake up. - Signals will simply cause this loop to restart. - */ - do { - ret = futex((unsigned long)<t_buf->writer_futex, - FUTEX_WAIT, -1, 0, 0, 0); - } while(ret != 0 && ret != EWOULDBLOCK); - } + sem_wait(<t_buf->writer_sem); /* go on with the write */ //} else { @@ -440,6 +420,7 @@ static inline void * __attribute__((no_instrument_function)) ltt_reserve_slot( } else { /* Next subbuffer corrupted. Force pushing reader even in normal * mode. It's safe to write in this new subbuffer. */ + sem_post(<t_buf->writer_sem); } size = ltt_get_header_size(trace, ltt_buf->start + offset_begin, before_hdr_pad, after_hdr_pad, header_size) + data_size; -- 2.34.1