X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=ustd%2Fustd.c;h=c5a3d8bed26b10bbfdcbd885efb189209d67b332;hb=6cb88bc04f67ebc3264d3832f4ce5cca2c642ab4;hp=a4c7e1f3f0c8a6dbdd17ac2fbf349a3fe7cb6f9d;hpb=8cefc1450e2d929de5d2878518e7b8b2b77ff755;p=ust.git diff --git a/ustd/ustd.c b/ustd/ustd.c index a4c7e1f..c5a3d8b 100644 --- a/ustd/ustd.c +++ b/ustd/ustd.c @@ -27,38 +27,12 @@ #include #include +#include "ustd.h" #include "localerr.h" #include "ustcomm.h" struct list_head buffers = LIST_HEAD_INIT(buffers); -struct buffer_info { - char *name; - pid_t pid; - struct ustcomm_connection conn; - - int shmid; - int bufstruct_shmid; - - /* the buffer memory */ - void *mem; - /* buffer size */ - int memlen; - /* number of subbuffers in buffer */ - int n_subbufs; - /* size of each subbuffer */ - int subbuf_size; - - /* the buffer information struct */ - void *bufstruct_mem; - - int file_fd; /* output file */ - - struct list_head list; - - long consumed_old; -}; - /* return value: 0 = subbuffer is finished, it won't produce data anymore * 1 = got subbuffer successfully * <0 = error @@ -170,80 +144,25 @@ ssize_t patient_write(int fd, const void *buf, size_t count) return bufc-(const char *)buf; } -int get_subbuffer_died(struct buffer_info *buf) -{ - return 0; -} - -//int ltt_do_get_subbuf(struct rchan_buf *buf, struct ltt_channel_buf_struct *ltt_buf, long *pconsumed_old) -//{ -// struct ltt_channel_buf_struct *ltt_buf = buf->bufstruct_mem; -// -////ust// struct ltt_channel_struct *ltt_channel = (struct ltt_channel_struct *)buf->chan->private_data; -// long consumed_old, consumed_idx, commit_count, write_offset; -// consumed_old = atomic_long_read(<t_buf->consumed); -// consumed_idx = SUBBUF_INDEX(consumed_old, buf->chan); -// commit_count = local_read(<t_buf->commit_count[consumed_idx]); -// /* -// * Make sure we read the commit count before reading the buffer -// * data and the write offset. Correct consumed offset ordering -// * wrt commit count is insured by the use of cmpxchg to update -// * the consumed offset. -// */ -// smp_rmb(); -// write_offset = local_read(<t_buf->offset); -// /* -// * Check that the subbuffer we are trying to consume has been -// * already fully committed. -// */ -// if (((commit_count - buf->chan->subbuf_size) -// & ltt_channel->commit_count_mask) -// - (BUFFER_TRUNC(consumed_old, buf->chan) -// >> ltt_channel->n_subbufs_order) -// != 0) { -// return -EAGAIN; -// } -// /* -// * Check that we are not about to read the same subbuffer in -// * which the writer head is. -// */ -// if ((SUBBUF_TRUNC(write_offset, buf->chan) -// - SUBBUF_TRUNC(consumed_old, buf->chan)) -// == 0) { -// return -EAGAIN; -// } -// -// *pconsumed_old = consumed_old; -// return 0; -//} - void *consumer_thread(void *arg) { struct buffer_info *buf = (struct buffer_info *) arg; int result; - int died = 0; for(;;) { /* get the subbuffer */ - if(died == 0) { - result = get_subbuffer(buf); - if(result == -1) { - ERR("error getting subbuffer"); - continue; - } - else if(result == GET_SUBBUF_DONE) { - /* this is done */ - break; - } - else if(result == GET_SUBBUF_DIED) { - died = 1; - } + result = get_subbuffer(buf); + if(result == -1) { + ERR("error getting subbuffer"); + continue; } - if(died == 1) { - result = get_subbuffer_died(buf); - if(result <= 0) { - break; - } + else if(result == GET_SUBBUF_DONE) { + /* this is done */ + break; + } + else if(result == GET_SUBBUF_DIED) { + finish_consuming_dead_subbuffer(buf); + break; } /* write data to file */ @@ -254,15 +173,10 @@ void *consumer_thread(void *arg) } /* put the subbuffer */ - if(died == 0) { - result = put_subbuffer(buf); - if(result == -1) { - ERR("error putting subbuffer"); - break; - } - } - else { -// result = put_subbuffer_died(buf); + result = put_subbuffer(buf); + if(result == -1) { + ERR("error putting subbuffer"); + break; } } @@ -359,6 +273,7 @@ int add_buffer(pid_t pid, char *bufname) result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00600); if(result == -1) { PERROR("open"); + ERR("failed opening trace file %s", tmp); return -1; } buf->file_fd = fd;