Change consumer_metadata_pipe to be a lttng_pipe
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/3 Change consumer_metadata_pipe to be a lttng_pipe
--- src/common/consumer.c | 42 ++++++++------------------ src/common/consumer.h | 2 +- src/common/kernel-consumer/kernel-consumer.c | 2 +- src/common/ust-consumer/ust-consumer.c | 2 +- 4 files changed, 15 insertions(+), 33 deletions(-)
src/common/consumer.c +12 -30
@@ -77,21 +77,6 @@ static struct lttng_ht *metadata_ht;static struct lttng_ht *data_ht;/* -* Notify a thread pipe to poll back again. This usually means that some global -* state has changed so we just send back the thread in a poll wait call. -*/ -static void notify_thread_pipe (int wpipe) -{ -int ret; - -do { -struct lttng_consumer_stream *null_stream =NULL ; - - ret =write (wpipe, &null_stream,sizeof (null_stream)); - }while (ret <0 && errno ==EINTR ); -} - -/* * Notify a thread lttng pipe to poll back again. This usually means that some * global state has changed so we just send back the thread in a poll wait * call.
@@ -421,7 +406,7 @@ static void cleanup_relayd(struct consumer_relayd_sock_pair *relayd,*/ if (ctx) {notify_thread_lttng_pipe (ctx->consumer_data_pipe); -notify_thread_pipe (ctx->consumer_metadata_pipe[1 ]); +notify_thread_lttng_pipe (ctx->consumer_metadata_pipe); } }
@@ -1204,8 +1189,8 @@ struct lttng_consumer_local_data *lttng_consumer_create( goto error_channel_pipe; } - ret =utils_create_pipe (ctx->consumer_metadata_pipe); -if (ret <0 ) { + ctx->consumer_metadata_pipe =lttng_pipe_open (0 ); +if (!ctx->consumer_metadata_pipe) { goto error_metadata_pipe; }
@@ -1217,7 +1202,7 @@ struct lttng_consumer_local_data *lttng_consumer_create(return ctx; error_splice_pipe: -utils_close_pipe (ctx->consumer_metadata_pipe); +lttng_pipe_destroy (ctx->consumer_metadata_pipe); error_metadata_pipe:utils_close_pipe (ctx->consumer_channel_pipe); error_channel_pipe:
@@ -1252,6 +1237,7 @@ void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx)utils_close_pipe (ctx->consumer_thread_pipe);utils_close_pipe (ctx->consumer_channel_pipe);lttng_pipe_destroy (ctx->consumer_data_pipe); +lttng_pipe_destroy (ctx->consumer_metadata_pipe);utils_close_pipe (ctx->consumer_should_quit);utils_close_pipe (ctx->consumer_splice_metadata_pipe);
@@ -2132,7 +2118,8 @@ void *consumer_thread_metadata_poll(void *data) goto end_poll; } - ret =lttng_poll_add (&events, ctx->consumer_metadata_pipe[0 ],LPOLLIN ); + ret =lttng_poll_add (&events, +lttng_pipe_get_readfd (ctx->consumer_metadata_pipe),LPOLLIN );if (ret <0 ) { goto end; }
@@ -2170,18 +2157,16 @@ restart:continue ; } -if (pollfd == ctx->consumer_metadata_pipe[0 ]) { +if (pollfd ==lttng_pipe_get_readfd (ctx->consumer_metadata_pipe)) {if (revents & (LPOLLERR |LPOLLHUP )) {DBG ("Metadata thread pipe hung up" );/* * Remove the pipe from the poll set and continue the loop * since their might be data to consume. */ -lttng_poll_del (&events, ctx->consumer_metadata_pipe[0 ]); - ret =close (ctx->consumer_metadata_pipe[0 ]); -if (ret <0 ) { -PERROR ("close metadata pipe" ); - } +lttng_poll_del (&events, +lttng_pipe_get_readfd (ctx->consumer_metadata_pipe)); +lttng_pipe_read_close (ctx->consumer_metadata_pipe);continue ; }else if (revents &LPOLLIN ) { do {
@@ -2541,10 +2526,7 @@ end:* only tracked fd in the poll set. The thread will take care of closing * the read side. */ - ret =close (ctx->consumer_metadata_pipe[1 ]); -if (ret <0 ) { -PERROR ("close data pipe" ); - } + (void )lttng_pipe_write_close (ctx->consumer_metadata_pipe);destroy_data_stream_ht (data_ht);
src/common/consumer.h +1 -1
@@ -351,7 +351,7 @@ struct lttng_consumer_local_data {/* to let the signal handler wake up the fd receiver thread */ int consumer_should_quit[2 ];/* Metadata poll thread pipe. Transfer metadata stream to it */ -int consumer_metadata_pipe[2 ]; +struct lttng_pipe *consumer_metadata_pipe; };/*
src/common/kernel-consumer/kernel-consumer.c +1 -1
@@ -288,7 +288,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,/* Get the right pipe where the stream will be sent. */ if (new_stream->metadata_flag) { - stream_pipe = ctx->consumer_metadata_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); }else { stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); }
src/common/ust-consumer/ust-consumer.c +1 -1
@@ -189,7 +189,7 @@ static int send_stream_to_thread(struct lttng_consumer_stream *stream,/* Get the right pipe where the stream will be sent. */ if (stream->metadata_flag) { - stream_pipe = ctx->consumer_metadata_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); }else { stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); }
Signature · 1 line
1.7.10.4
PATCH 3/3 Fix: use lttng pipe to send new stream to thread
In reply to a message not in the archive--- src/common/kernel-consumer/kernel-consumer.c | 15 +++++++-------- src/common/ust-consumer/ust-consumer.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-)
src/common/kernel-consumer/kernel-consumer.c +7 -8
@@ -168,7 +168,8 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, }case LTTNG_CONSUMER_ADD_STREAM : { -int fd, stream_pipe; +int fd; +struct lttng_pipe *stream_pipe;struct consumer_relayd_sock_pair *relayd =NULL ;struct lttng_consumer_stream *new_stream;struct lttng_consumer_channel *channel;
@@ -288,18 +289,16 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,/* Get the right pipe where the stream will be sent. */ if (new_stream->metadata_flag) { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); + stream_pipe = ctx->consumer_metadata_pipe; }else { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); + stream_pipe = ctx->consumer_data_pipe; } -do { - ret =write (stream_pipe, &new_stream,sizeof (new_stream)); - }while (ret <0 && errno ==EINTR ); + ret =lttng_pipe_write (stream_pipe, &new_stream,sizeof (new_stream));if (ret <0 ) { -PERROR ("Consumer write %s stream to pipe %d" , +ERR ("Consumer write %s stream to pipe %d" , new_stream->metadata_flag ?"metadata" :"data" , - stream_pipe); +lttng_pipe_get_writefd (stream_pipe));consumer_del_stream (new_stream,NULL ); goto end_nosignal; }
src/common/ust-consumer/ust-consumer.c +8 -8
@@ -185,21 +185,21 @@ error:static int send_stream_to_thread (struct lttng_consumer_stream *stream,struct lttng_consumer_local_data *ctx) { -int ret, stream_pipe; +int ret; +struct lttng_pipe *stream_pipe;/* Get the right pipe where the stream will be sent. */ if (stream->metadata_flag) { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); + stream_pipe = ctx->consumer_metadata_pipe; }else { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); + stream_pipe = ctx->consumer_data_pipe; } -do { - ret =write (stream_pipe, &stream,sizeof (stream)); - }while (ret <0 && errno ==EINTR ); + ret =lttng_pipe_write (stream_pipe, &stream,sizeof (stream));if (ret <0 ) { -PERROR ("Consumer write %s stream to pipe %d" , - stream->metadata_flag ?"metadata" :"data" , stream_pipe); +ERR ("Consumer write %s stream to pipe %d" , + stream->metadata_flag ?"metadata" :"data" , +lttng_pipe_get_writefd (stream_pipe)); }return ret;
Signature · 1 line
1.7.10.4
Re: [PATCH 1/3 lttng-tools] Change consumer_data_pipe to be a lttng_pipe
In reply to a message not in the archiveQuoted 115 lines · * David Goulet ([email protected]) wrote:
Also, an important change here is that this pipe is no longer in non block mode. Before sending stream's pointer over this pipe, only one byte was written thus making it unlikely to fail in a read/write race condition between threads. Now, 4 bytes are written so keeping this pipe non block with threads is a bit of a "looking for trouble situation".
The lttng pipe wrappers make sure that the read and write side are synchronized between threads using a mutex for each side. Furthermore, the read and write handle partial I/O and EINTR meaning that once the call returns we are sure that either everything was read/written or an error occured thus making it not possible for the read side to block indefinitely after a poll event.
Signed-off-by David Goulet <[email protected]>--- src/common/consumer.c | 53 ++++++++++++-------------- src/common/consumer.h | 3 +- src/common/kernel-consumer/kernel-consumer.c | 3 +- src/common/ust-consumer/ust-consumer.c | 2 +- 4 files changed, 29 insertions(+), 32 deletions(-)src/common/consumer.c +20
-22@@ -91,6 +91,20 @@ static void notify_thread_pipe(int wpipe) }while (ret <0 && errno ==EINTR ); } +/* +* Notify a thread lttng pipe to poll back again. This usually means that some +* global state has changed so we just send back the thread in a poll wait +* call. +*/ +static void notify_thread_lttng_pipe (struct lttng_pipe *pipe) +{ +struct lttng_consumer_stream *null_stream =NULL ; + +assert (pipe); + + (void )lttng_pipe_write (pipe, &null_stream,sizeof (null_stream)); +} + static void notify_channel_pipe(struct lttng_consumer_local_data *ctx, struct lttng_consumer_channel *chan, uint64_t key,@@ -406,7 +420,7 @@ static void cleanup_relayd(struct consumer_relayd_sock_pair *relayd,* read of this status which happens AFTER receiving this notify. */ if (ctx) { -notify_thread_pipe (ctx->consumer_data_pipe[1 ]); +notify_thread_lttng_pipe (ctx->consumer_data_pipe);notify_thread_pipe (ctx->consumer_metadata_pipe[1 ]); } }@@ -971,7 +985,7 @@ static int update_poll_array(struct lttng_consumer_local_data *ctx,* Insert the consumer_data_pipe at the end of the array and don't * increment i so nb_fd is the number of real FD. */ - (*pollfd)[i].fd = ctx->consumer_data_pipe[0 ]; + (*pollfd)[i].fd =lttng_pipe_get_readfd (ctx->consumer_data_pipe); (*pollfd)[i].events =POLLIN |POLLPRI ;return i; }@@ -1167,26 +1181,11 @@ struct lttng_consumer_local_data *lttng_consumer_create( ctx->on_recv_stream = recv_stream; ctx->on_update_stream = update_stream; - ret =pipe (ctx->consumer_data_pipe); -if (ret <0 ) { -PERROR ("Error creating poll pipe" ); + ctx->consumer_data_pipe =lttng_pipe_open (0 ); +if (!ctx->consumer_data_pipe) { goto error_poll_pipe; } -/* set read end of the pipe to non-blocking */ - ret =fcntl (ctx->consumer_data_pipe[0 ],F_SETFL ,O_NONBLOCK ); -if (ret <0 ) { -PERROR ("fcntl O_NONBLOCK" ); - goto error_poll_fcntl; - } - -/* set write end of the pipe to non-blocking */ - ret =fcntl (ctx->consumer_data_pipe[1 ],F_SETFL ,O_NONBLOCK ); -if (ret <0 ) { -PERROR ("fcntl O_NONBLOCK" ); - goto error_poll_fcntl; - } - ret =pipe (ctx->consumer_should_quit);if (ret <0 ) {PERROR ("Error creating recv pipe" );@@ -1225,9 +1224,8 @@ error_channel_pipe:utils_close_pipe (ctx->consumer_thread_pipe); error_thread_pipe:utils_close_pipe (ctx->consumer_should_quit); -error_poll_fcntl: error_quit_pipe: -utils_close_pipe (ctx->consumer_data_pipe); +lttng_pipe_destroy (ctx->consumer_data_pipe); error_poll_pipe:free (ctx); error:@@ -1253,7 +1251,7 @@ void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx) }utils_close_pipe (ctx->consumer_thread_pipe);utils_close_pipe (ctx->consumer_channel_pipe); -utils_close_pipe (ctx->consumer_data_pipe); +lttng_pipe_destroy (ctx->consumer_data_pipe);utils_close_pipe (ctx->consumer_should_quit);utils_close_pipe (ctx->consumer_splice_metadata_pipe);@@ -2402,13 +2400,10 @@ void *consumer_thread_data_poll(void *data)ssize_t pipe_readlen;
src/common/consumer.c void *consumer_thread_data_poll(void *data) · line 2405
Quoted 10 lines
src/common/consumer.c +2
-5DBG ("consumer_data_pipe wake up" ); -/* Consume 1 byte of pipe data */ -do { - pipe_readlen =read (ctx->consumer_data_pipe[0 ], &new_stream, -sizeof (new_stream)); - }while (pipe_readlen ==-1 && errno ==EINTR ); + pipe_readlen =lttng_pipe_read (ctx->consumer_data_pipe, + &new_stream,sizeof (new_stream));if (pipe_readlen <0 ) {
can lttng_pipe_read return a value smaller than sizeof(new_stream) on some error conditions ? (but higher than 0)
Thanks,
Mathieu
Quoted 77 lines
src/common/consumer.c +2
-2-PERROR ("read consumer data pipe" ); +ERR ("Consumer data pipe ret %ld" , pipe_readlen);/* Continue so we can at least handle the current stream(s). */ continue ; }@@ -2968,7 +2963,7 @@ end:* Notify the data poll thread to poll back again and test the * consumer_quit state that we just set so to quit gracefully. */ -notify_thread_pipe (ctx->consumer_data_pipe[1 ]); +notify_thread_lttng_pipe (ctx->consumer_data_pipe);notify_channel_pipe (ctx,NULL ,-1 ,CONSUMER_CHANNEL_QUIT );src/common/consumer.h +2
-1@@ -31,6 +31,7 @@#include <common/compat/fcntl.h> #include <common/compat/uuid.h> #include <common/sessiond-comm/sessiond-comm.h> +#include <common/pipe.h> /* Commands for consumer */ enum lttng_consumer_command {@@ -346,7 +347,7 @@ struct lttng_consumer_local_data {int consumer_channel_pipe[2 ];int consumer_splice_metadata_pipe[2 ];/* Data stream poll thread pipe. To transfer data stream to the thread */ -int consumer_data_pipe[2 ]; +struct lttng_pipe *consumer_data_pipe;/* to let the signal handler wake up the fd receiver thread */ int consumer_should_quit[2 ];/* Metadata poll thread pipe. Transfer metadata stream to it */ src/common/kernel-consumer/kernel-consumer.c +2
-1@@ -34,6 +34,7 @@#include <common/sessiond-comm/sessiond-comm.h> #include <common/sessiond-comm/relayd.h> #include <common/compat/fcntl.h> +#include <common/pipe.h> #include <common/relayd/relayd.h> #include <common/utils.h> @@ -289,7 +290,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,if (new_stream->metadata_flag) { stream_pipe = ctx->consumer_metadata_pipe[1 ]; }else { - stream_pipe = ctx->consumer_data_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); } do {src/common/ust-consumer/ust-consumer.c +1
-1@@ -191,7 +191,7 @@ static int send_stream_to_thread(struct lttng_consumer_stream *stream,if (stream->metadata_flag) { stream_pipe = ctx->consumer_metadata_pipe[1 ]; }else { - stream_pipe = ctx->consumer_data_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); } do {Signature · 7 lines
1.7.10.4 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
A message that is not in the archive (sent off-list or not yet received): [email protected]
why isn't this patch using lttng_pipe_read() ?
Quoted 163 lines · * David Goulet ([email protected]) wrote:
Signed-off-by David Goulet <[email protected]>--- src/common/consumer.c | 42 ++++++++------------------ src/common/consumer.h | 2 +- src/common/kernel-consumer/kernel-consumer.c | 2 +- src/common/ust-consumer/ust-consumer.c | 2 +- 4 files changed, 15 insertions(+), 33 deletions(-)src/common/consumer.c +12
-30@@ -77,21 +77,6 @@ static struct lttng_ht *metadata_ht;static struct lttng_ht *data_ht;/* -* Notify a thread pipe to poll back again. This usually means that some global -* state has changed so we just send back the thread in a poll wait call. -*/ -static void notify_thread_pipe (int wpipe) -{ -int ret; - -do { -struct lttng_consumer_stream *null_stream =NULL ; - - ret =write (wpipe, &null_stream,sizeof (null_stream)); - }while (ret <0 && errno ==EINTR ); -} - -/* * Notify a thread lttng pipe to poll back again. This usually means that some * global state has changed so we just send back the thread in a poll wait * call. @@ -421,7 +406,7 @@ static void cleanup_relayd(struct consumer_relayd_sock_pair *relayd,*/ if (ctx) {notify_thread_lttng_pipe (ctx->consumer_data_pipe); -notify_thread_pipe (ctx->consumer_metadata_pipe[1 ]); +notify_thread_lttng_pipe (ctx->consumer_metadata_pipe); } }@@ -1204,8 +1189,8 @@ struct lttng_consumer_local_data *lttng_consumer_create( goto error_channel_pipe; } - ret =utils_create_pipe (ctx->consumer_metadata_pipe); -if (ret <0 ) { + ctx->consumer_metadata_pipe =lttng_pipe_open (0 ); +if (!ctx->consumer_metadata_pipe) { goto error_metadata_pipe; }@@ -1217,7 +1202,7 @@ struct lttng_consumer_local_data *lttng_consumer_create(return ctx; error_splice_pipe: -utils_close_pipe (ctx->consumer_metadata_pipe); +lttng_pipe_destroy (ctx->consumer_metadata_pipe); error_metadata_pipe:utils_close_pipe (ctx->consumer_channel_pipe); error_channel_pipe:@@ -1252,6 +1237,7 @@ void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx)utils_close_pipe (ctx->consumer_thread_pipe);utils_close_pipe (ctx->consumer_channel_pipe);lttng_pipe_destroy (ctx->consumer_data_pipe); +lttng_pipe_destroy (ctx->consumer_metadata_pipe);utils_close_pipe (ctx->consumer_should_quit);utils_close_pipe (ctx->consumer_splice_metadata_pipe);@@ -2132,7 +2118,8 @@ void *consumer_thread_metadata_poll(void *data) goto end_poll; } - ret =lttng_poll_add (&events, ctx->consumer_metadata_pipe[0 ],LPOLLIN ); + ret =lttng_poll_add (&events, +lttng_pipe_get_readfd (ctx->consumer_metadata_pipe),LPOLLIN );if (ret <0 ) { goto end; }@@ -2170,18 +2157,16 @@ restart:continue ; } -if (pollfd == ctx->consumer_metadata_pipe[0 ]) { +if (pollfd ==lttng_pipe_get_readfd (ctx->consumer_metadata_pipe)) {if (revents & (LPOLLERR |LPOLLHUP )) {DBG ("Metadata thread pipe hung up" );/* * Remove the pipe from the poll set and continue the loop * since their might be data to consume. */ -lttng_poll_del (&events, ctx->consumer_metadata_pipe[0 ]); - ret =close (ctx->consumer_metadata_pipe[0 ]); -if (ret <0 ) { -PERROR ("close metadata pipe" ); - } +lttng_poll_del (&events, +lttng_pipe_get_readfd (ctx->consumer_metadata_pipe)); +lttng_pipe_read_close (ctx->consumer_metadata_pipe);continue ; }else if (revents &LPOLLIN ) { do {@@ -2541,10 +2526,7 @@ end:* only tracked fd in the poll set. The thread will take care of closing * the read side. */ - ret =close (ctx->consumer_metadata_pipe[1 ]); -if (ret <0 ) { -PERROR ("close data pipe" ); - } + (void )lttng_pipe_write_close (ctx->consumer_metadata_pipe);destroy_data_stream_ht (data_ht);src/common/consumer.h +1
-1@@ -351,7 +351,7 @@ struct lttng_consumer_local_data {/* to let the signal handler wake up the fd receiver thread */ int consumer_should_quit[2 ];/* Metadata poll thread pipe. Transfer metadata stream to it */ -int consumer_metadata_pipe[2 ]; +struct lttng_pipe *consumer_metadata_pipe; };/* src/common/kernel-consumer/kernel-consumer.c +1
-1@@ -288,7 +288,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,/* Get the right pipe where the stream will be sent. */ if (new_stream->metadata_flag) { - stream_pipe = ctx->consumer_metadata_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); }else { stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); }src/common/ust-consumer/ust-consumer.c +1
-1@@ -189,7 +189,7 @@ static int send_stream_to_thread(struct lttng_consumer_stream *stream,/* Get the right pipe where the stream will be sent. */ if (stream->metadata_flag) { - stream_pipe = ctx->consumer_metadata_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); }else { stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); }Signature · 7 lines
1.7.10.4 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
A message that is not in the archive (sent off-list or not yet received): 20130515191907.GB12581@Krystal
Oh that's a *really* good catch. My bad, I forgot to change the read() from that pipe in the metadata thread.
I'll be re-sending this one.
Mathieu Desnoyers:
Quoted 167 lines
why isn't this patch using
lttng_pipe_read()?Quoted 163 lines · * David Goulet ([email protected]) wrote:
Signed-off-by David Goulet <[email protected]>--- src/common/consumer.c | 42 ++++++++------------------ src/common/consumer.h | 2 +- src/common/kernel-consumer/kernel-consumer.c | 2 +- src/common/ust-consumer/ust-consumer.c | 2 +- 4 files changed, 15 insertions(+), 33 deletions(-)src/common/consumer.c +12
-30@@ -77,21 +77,6 @@ static struct lttng_ht *metadata_ht;static struct lttng_ht *data_ht;/* -* Notify a thread pipe to poll back again. This usually means that some global -* state has changed so we just send back the thread in a poll wait call. -*/ -static void notify_thread_pipe (int wpipe) -{ -int ret; - -do { -struct lttng_consumer_stream *null_stream =NULL ; - - ret =write (wpipe, &null_stream,sizeof (null_stream)); - }while (ret <0 && errno ==EINTR ); -} - -/* * Notify a thread lttng pipe to poll back again. This usually means that some * global state has changed so we just send back the thread in a poll wait * call. @@ -421,7 +406,7 @@ static void cleanup_relayd(struct consumer_relayd_sock_pair *relayd,*/ if (ctx) {notify_thread_lttng_pipe (ctx->consumer_data_pipe); -notify_thread_pipe (ctx->consumer_metadata_pipe[1 ]); +notify_thread_lttng_pipe (ctx->consumer_metadata_pipe); } }@@ -1204,8 +1189,8 @@ struct lttng_consumer_local_data *lttng_consumer_create( goto error_channel_pipe; } - ret =utils_create_pipe (ctx->consumer_metadata_pipe); -if (ret <0 ) { + ctx->consumer_metadata_pipe =lttng_pipe_open (0 ); +if (!ctx->consumer_metadata_pipe) { goto error_metadata_pipe; }@@ -1217,7 +1202,7 @@ struct lttng_consumer_local_data *lttng_consumer_create(return ctx; error_splice_pipe: -utils_close_pipe (ctx->consumer_metadata_pipe); +lttng_pipe_destroy (ctx->consumer_metadata_pipe); error_metadata_pipe:utils_close_pipe (ctx->consumer_channel_pipe); error_channel_pipe:@@ -1252,6 +1237,7 @@ void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx)utils_close_pipe (ctx->consumer_thread_pipe);utils_close_pipe (ctx->consumer_channel_pipe);lttng_pipe_destroy (ctx->consumer_data_pipe); +lttng_pipe_destroy (ctx->consumer_metadata_pipe);utils_close_pipe (ctx->consumer_should_quit);utils_close_pipe (ctx->consumer_splice_metadata_pipe);@@ -2132,7 +2118,8 @@ void *consumer_thread_metadata_poll(void *data) goto end_poll; } - ret =lttng_poll_add (&events, ctx->consumer_metadata_pipe[0 ],LPOLLIN ); + ret =lttng_poll_add (&events, +lttng_pipe_get_readfd (ctx->consumer_metadata_pipe),LPOLLIN );if (ret <0 ) { goto end; }@@ -2170,18 +2157,16 @@ restart:continue ; } -if (pollfd == ctx->consumer_metadata_pipe[0 ]) { +if (pollfd ==lttng_pipe_get_readfd (ctx->consumer_metadata_pipe)) {if (revents & (LPOLLERR |LPOLLHUP )) {DBG ("Metadata thread pipe hung up" );/* * Remove the pipe from the poll set and continue the loop * since their might be data to consume. */ -lttng_poll_del (&events, ctx->consumer_metadata_pipe[0 ]); - ret =close (ctx->consumer_metadata_pipe[0 ]); -if (ret <0 ) { -PERROR ("close metadata pipe" ); - } +lttng_poll_del (&events, +lttng_pipe_get_readfd (ctx->consumer_metadata_pipe)); +lttng_pipe_read_close (ctx->consumer_metadata_pipe);continue ; }else if (revents &LPOLLIN ) { do {@@ -2541,10 +2526,7 @@ end:* only tracked fd in the poll set. The thread will take care of closing * the read side. */ - ret =close (ctx->consumer_metadata_pipe[1 ]); -if (ret <0 ) { -PERROR ("close data pipe" ); - } + (void )lttng_pipe_write_close (ctx->consumer_metadata_pipe);destroy_data_stream_ht (data_ht);src/common/consumer.h +1
-1@@ -351,7 +351,7 @@ struct lttng_consumer_local_data {/* to let the signal handler wake up the fd receiver thread */ int consumer_should_quit[2 ];/* Metadata poll thread pipe. Transfer metadata stream to it */ -int consumer_metadata_pipe[2 ]; +struct lttng_pipe *consumer_metadata_pipe; };/* src/common/kernel-consumer/kernel-consumer.c +1
-1@@ -288,7 +288,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,/* Get the right pipe where the stream will be sent. */ if (new_stream->metadata_flag) { - stream_pipe = ctx->consumer_metadata_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); }else { stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); }src/common/ust-consumer/ust-consumer.c +1
-1@@ -189,7 +189,7 @@ static int send_stream_to_thread(struct lttng_consumer_stream *stream,/* Get the right pipe where the stream will be sent. */ if (stream->metadata_flag) { - stream_pipe = ctx->consumer_metadata_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); }else { stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); }Signature · 7 lines
1.7.10.4 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3 lttng-tools] Fix: use lttng pipe to send new stream to thread
same question about not using lttng_pipe_read() here.
Thanks,
Mathieu
Quoted 86 lines · * David Goulet ([email protected]) wrote:
Signed-off-by David Goulet <[email protected]>--- src/common/kernel-consumer/kernel-consumer.c | 15 +++++++-------- src/common/ust-consumer/ust-consumer.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-)src/common/kernel-consumer/kernel-consumer.c +7
-8@@ -168,7 +168,8 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, }case LTTNG_CONSUMER_ADD_STREAM : { -int fd, stream_pipe; +int fd; +struct lttng_pipe *stream_pipe;struct consumer_relayd_sock_pair *relayd =NULL ;struct lttng_consumer_stream *new_stream;struct lttng_consumer_channel *channel;@@ -288,18 +289,16 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,/* Get the right pipe where the stream will be sent. */ if (new_stream->metadata_flag) { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); + stream_pipe = ctx->consumer_metadata_pipe; }else { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); + stream_pipe = ctx->consumer_data_pipe; } -do { - ret =write (stream_pipe, &new_stream,sizeof (new_stream)); - }while (ret <0 && errno ==EINTR ); + ret =lttng_pipe_write (stream_pipe, &new_stream,sizeof (new_stream));if (ret <0 ) { -PERROR ("Consumer write %s stream to pipe %d" , +ERR ("Consumer write %s stream to pipe %d" , new_stream->metadata_flag ?"metadata" :"data" , - stream_pipe); +lttng_pipe_get_writefd (stream_pipe));consumer_del_stream (new_stream,NULL ); goto end_nosignal; }src/common/ust-consumer/ust-consumer.c +8
-8@@ -185,21 +185,21 @@ error:static int send_stream_to_thread (struct lttng_consumer_stream *stream,struct lttng_consumer_local_data *ctx) { -int ret, stream_pipe; +int ret; +struct lttng_pipe *stream_pipe;/* Get the right pipe where the stream will be sent. */ if (stream->metadata_flag) { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); + stream_pipe = ctx->consumer_metadata_pipe; }else { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); + stream_pipe = ctx->consumer_data_pipe; } -do { - ret =write (stream_pipe, &stream,sizeof (stream)); - }while (ret <0 && errno ==EINTR ); + ret =lttng_pipe_write (stream_pipe, &stream,sizeof (stream));if (ret <0 ) { -PERROR ("Consumer write %s stream to pipe %d" , - stream->metadata_flag ?"metadata" :"data" , stream_pipe); +ERR ("Consumer write %s stream to pipe %d" , + stream->metadata_flag ?"metadata" :"data" , +lttng_pipe_get_writefd (stream_pipe)); }return ret;Signature · 7 lines
1.7.10.4 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
Signature · 3 lines
Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com
A message that is not in the archive (sent off-list or not yet received): 20130515192038.GC12581@Krystal
Re: [PATCH 3/3 lttng-tools] Fix: use lttng pipe to send new stream to thread
The read() calls are in the thread that were changed by the previous patches. This patch is to completely remove traditional pipe from the sessiond thread for data and metadata streams.
David
Mathieu Desnoyers:
Quoted 94 lines
same question about not using
lttng_pipe_read()here.Thanks,
Mathieu
Quoted 86 lines · * David Goulet ([email protected]) wrote:
Signed-off-by David Goulet <[email protected]>--- src/common/kernel-consumer/kernel-consumer.c | 15 +++++++-------- src/common/ust-consumer/ust-consumer.c | 16 ++++++++-------- 2 files changed, 15 insertions(+), 16 deletions(-)src/common/kernel-consumer/kernel-consumer.c +7
-8@@ -168,7 +168,8 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, }case LTTNG_CONSUMER_ADD_STREAM : { -int fd, stream_pipe; +int fd; +struct lttng_pipe *stream_pipe;struct consumer_relayd_sock_pair *relayd =NULL ;struct lttng_consumer_stream *new_stream;struct lttng_consumer_channel *channel;@@ -288,18 +289,16 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,/* Get the right pipe where the stream will be sent. */ if (new_stream->metadata_flag) { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); + stream_pipe = ctx->consumer_metadata_pipe; }else { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); + stream_pipe = ctx->consumer_data_pipe; } -do { - ret =write (stream_pipe, &new_stream,sizeof (new_stream)); - }while (ret <0 && errno ==EINTR ); + ret =lttng_pipe_write (stream_pipe, &new_stream,sizeof (new_stream));if (ret <0 ) { -PERROR ("Consumer write %s stream to pipe %d" , +ERR ("Consumer write %s stream to pipe %d" , new_stream->metadata_flag ?"metadata" :"data" , - stream_pipe); +lttng_pipe_get_writefd (stream_pipe));consumer_del_stream (new_stream,NULL ); goto end_nosignal; }src/common/ust-consumer/ust-consumer.c +8
-8@@ -185,21 +185,21 @@ error:static int send_stream_to_thread (struct lttng_consumer_stream *stream,struct lttng_consumer_local_data *ctx) { -int ret, stream_pipe; +int ret; +struct lttng_pipe *stream_pipe;/* Get the right pipe where the stream will be sent. */ if (stream->metadata_flag) { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_metadata_pipe); + stream_pipe = ctx->consumer_metadata_pipe; }else { - stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); + stream_pipe = ctx->consumer_data_pipe; } -do { - ret =write (stream_pipe, &stream,sizeof (stream)); - }while (ret <0 && errno ==EINTR ); + ret =lttng_pipe_write (stream_pipe, &stream,sizeof (stream));if (ret <0 ) { -PERROR ("Consumer write %s stream to pipe %d" , - stream->metadata_flag ?"metadata" :"data" , stream_pipe); +ERR ("Consumer write %s stream to pipe %d" , + stream->metadata_flag ?"metadata" :"data" , +lttng_pipe_get_writefd (stream_pipe)); }return ret;Signature · 7 lines
1.7.10.4 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
A message that is not in the archive (sent off-list or not yet received): 20130515191641.GA12581@Krystal
Re: [PATCH 1/3 lttng-tools] Change consumer_data_pipe to be a lttng_pipe
Mathieu Desnoyers:
Quoted 117 lines · * David Goulet ([email protected]) wrote:
Quoted 116 lines
Also, an important change here is that this pipe is no longer in non block mode. Before sending stream's pointer over this pipe, only one byte was written thus making it unlikely to fail in a read/write race condition between threads. Now, 4 bytes are written so keeping this pipe non block with threads is a bit of a "looking for trouble situation".
The lttng pipe wrappers make sure that the read and write side are synchronized between threads using a mutex for each side. Furthermore, the read and write handle partial I/O and EINTR meaning that once the call returns we are sure that either everything was read/written or an error occured thus making it not possible for the read side to block indefinitely after a poll event.
Signed-off-by David Goulet <[email protected]>--- src/common/consumer.c | 53 ++++++++++++-------------- src/common/consumer.h | 3 +- src/common/kernel-consumer/kernel-consumer.c | 3 +- src/common/ust-consumer/ust-consumer.c | 2 +- 4 files changed, 29 insertions(+), 32 deletions(-)src/common/consumer.c +20
-22@@ -91,6 +91,20 @@ static void notify_thread_pipe(int wpipe) }while (ret <0 && errno ==EINTR ); } +/* +* Notify a thread lttng pipe to poll back again. This usually means that some +* global state has changed so we just send back the thread in a poll wait +* call. +*/ +static void notify_thread_lttng_pipe (struct lttng_pipe *pipe) +{ +struct lttng_consumer_stream *null_stream =NULL ; + +assert (pipe); + + (void )lttng_pipe_write (pipe, &null_stream,sizeof (null_stream)); +} + static void notify_channel_pipe(struct lttng_consumer_local_data *ctx, struct lttng_consumer_channel *chan, uint64_t key,@@ -406,7 +420,7 @@ static void cleanup_relayd(struct consumer_relayd_sock_pair *relayd,* read of this status which happens AFTER receiving this notify. */ if (ctx) { -notify_thread_pipe (ctx->consumer_data_pipe[1 ]); +notify_thread_lttng_pipe (ctx->consumer_data_pipe);notify_thread_pipe (ctx->consumer_metadata_pipe[1 ]); } }@@ -971,7 +985,7 @@ static int update_poll_array(struct lttng_consumer_local_data *ctx,* Insert the consumer_data_pipe at the end of the array and don't * increment i so nb_fd is the number of real FD. */ - (*pollfd)[i].fd = ctx->consumer_data_pipe[0 ]; + (*pollfd)[i].fd =lttng_pipe_get_readfd (ctx->consumer_data_pipe); (*pollfd)[i].events =POLLIN |POLLPRI ;return i; }@@ -1167,26 +1181,11 @@ struct lttng_consumer_local_data *lttng_consumer_create( ctx->on_recv_stream = recv_stream; ctx->on_update_stream = update_stream; - ret =pipe (ctx->consumer_data_pipe); -if (ret <0 ) { -PERROR ("Error creating poll pipe" ); + ctx->consumer_data_pipe =lttng_pipe_open (0 ); +if (!ctx->consumer_data_pipe) { goto error_poll_pipe; } -/* set read end of the pipe to non-blocking */ - ret =fcntl (ctx->consumer_data_pipe[0 ],F_SETFL ,O_NONBLOCK ); -if (ret <0 ) { -PERROR ("fcntl O_NONBLOCK" ); - goto error_poll_fcntl; - } - -/* set write end of the pipe to non-blocking */ - ret =fcntl (ctx->consumer_data_pipe[1 ],F_SETFL ,O_NONBLOCK ); -if (ret <0 ) { -PERROR ("fcntl O_NONBLOCK" ); - goto error_poll_fcntl; - } - ret =pipe (ctx->consumer_should_quit);if (ret <0 ) {PERROR ("Error creating recv pipe" );@@ -1225,9 +1224,8 @@ error_channel_pipe:utils_close_pipe (ctx->consumer_thread_pipe); error_thread_pipe:utils_close_pipe (ctx->consumer_should_quit); -error_poll_fcntl: error_quit_pipe: -utils_close_pipe (ctx->consumer_data_pipe); +lttng_pipe_destroy (ctx->consumer_data_pipe); error_poll_pipe:free (ctx); error:@@ -1253,7 +1251,7 @@ void lttng_consumer_destroy(struct lttng_consumer_local_data *ctx) }utils_close_pipe (ctx->consumer_thread_pipe);utils_close_pipe (ctx->consumer_channel_pipe); -utils_close_pipe (ctx->consumer_data_pipe); +lttng_pipe_destroy (ctx->consumer_data_pipe);utils_close_pipe (ctx->consumer_should_quit);utils_close_pipe (ctx->consumer_splice_metadata_pipe);@@ -2402,13 +2400,10 @@ void *consumer_thread_data_poll(void *data)ssize_t pipe_readlen;
Quoted 12 lines
src/common/consumer.c void *consumer_thread_data_poll(void *data) · line 2405
Quoted 9 lines
src/common/consumer.c +2
-5DBG ("consumer_data_pipe wake up" ); -/* Consume 1 byte of pipe data */ -do { - pipe_readlen =read (ctx->consumer_data_pipe[0 ], &new_stream, -sizeof (new_stream)); - }while (pipe_readlen ==-1 && errno ==EINTR ); + pipe_readlen =lttng_pipe_read (ctx->consumer_data_pipe, + &new_stream,sizeof (new_stream));if (pipe_readlen <0 ) {can
lttng_pipe_readreturn a value smaller thansizeof(new_stream)on some error conditions ? (but higher than 0)
As long as the pipe is not in NON BLOCK mode, no. It's either the full number of bytes or a negative value. The wrapper takes care of partial read and EINTR.
David
Quoted 83 lines
Thanks,
Mathieu
Quoted 77 lines
src/common/consumer.c +2
-2-PERROR ("read consumer data pipe" ); +ERR ("Consumer data pipe ret %ld" , pipe_readlen);/* Continue so we can at least handle the current stream(s). */ continue ; }@@ -2968,7 +2963,7 @@ end:* Notify the data poll thread to poll back again and test the * consumer_quit state that we just set so to quit gracefully. */ -notify_thread_pipe (ctx->consumer_data_pipe[1 ]); +notify_thread_lttng_pipe (ctx->consumer_data_pipe);notify_channel_pipe (ctx,NULL ,-1 ,CONSUMER_CHANNEL_QUIT );src/common/consumer.h +2
-1@@ -31,6 +31,7 @@#include <common/compat/fcntl.h> #include <common/compat/uuid.h> #include <common/sessiond-comm/sessiond-comm.h> +#include <common/pipe.h> /* Commands for consumer */ enum lttng_consumer_command {@@ -346,7 +347,7 @@ struct lttng_consumer_local_data {int consumer_channel_pipe[2 ];int consumer_splice_metadata_pipe[2 ];/* Data stream poll thread pipe. To transfer data stream to the thread */ -int consumer_data_pipe[2 ]; +struct lttng_pipe *consumer_data_pipe;/* to let the signal handler wake up the fd receiver thread */ int consumer_should_quit[2 ];/* Metadata poll thread pipe. Transfer metadata stream to it */ src/common/kernel-consumer/kernel-consumer.c +2
-1@@ -34,6 +34,7 @@#include <common/sessiond-comm/sessiond-comm.h> #include <common/sessiond-comm/relayd.h> #include <common/compat/fcntl.h> +#include <common/pipe.h> #include <common/relayd/relayd.h> #include <common/utils.h> @@ -289,7 +290,7 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx,if (new_stream->metadata_flag) { stream_pipe = ctx->consumer_metadata_pipe[1 ]; }else { - stream_pipe = ctx->consumer_data_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); } do {src/common/ust-consumer/ust-consumer.c +1
-1@@ -191,7 +191,7 @@ static int send_stream_to_thread(struct lttng_consumer_stream *stream,if (stream->metadata_flag) { stream_pipe = ctx->consumer_metadata_pipe[1 ]; }else { - stream_pipe = ctx->consumer_data_pipe[1 ]; + stream_pipe =lttng_pipe_get_writefd (ctx->consumer_data_pipe); } do {Signature · 7 lines
1.7.10.4 _______________________________________________ lttng-dev mailing list [email protected] http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev