X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fkernel-consumer%2Fkernel-consumer.c;h=bbc31f8e3be14bdb3927c87a1aabb40e28e777b5;hp=bb95529530161b4a45152609a67f8f018eeca6bd;hb=04fdd819f0eebfd15a4196a9ca98e826352a9b4f;hpb=6bf73bf53464ad309fcf7f02a4dc397d280b81f8 diff --git a/src/common/kernel-consumer/kernel-consumer.c b/src/common/kernel-consumer/kernel-consumer.c index bb9552953..bbc31f8e3 100644 --- a/src/common/kernel-consumer/kernel-consumer.c +++ b/src/common/kernel-consumer/kernel-consumer.c @@ -2,24 +2,22 @@ * Copyright (C) 2011 - Julien Desfossez * Mathieu Desnoyers * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; only version 2 - * of the License. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2 only, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #define _GNU_SOURCE #include -#include #include #include #include @@ -28,10 +26,12 @@ #include #include #include +#include #include #include #include +#include #include "kernel-consumer.h" @@ -44,12 +44,12 @@ extern volatile int consumer_quit; * * Returns the number of bytes written */ -int lttng_kconsumer_on_read_subbuffer_mmap( +ssize_t lttng_kconsumer_on_read_subbuffer_mmap( struct lttng_consumer_local_data *ctx, struct lttng_consumer_stream *stream, unsigned long len) { unsigned long mmap_offset; - long ret = 0; + ssize_t ret = 0; off_t orig_offset = stream->out_fd_offset; int fd = stream->wait_fd; int outfd = stream->out_fd; @@ -72,7 +72,7 @@ int lttng_kconsumer_on_read_subbuffer_mmap( goto end; } /* This won't block, but will start writeout asynchronously */ - sync_file_range(outfd, stream->out_fd_offset, ret, + lttng_sync_file_range(outfd, stream->out_fd_offset, ret, SYNC_FILE_RANGE_WRITE); stream->out_fd_offset += ret; } @@ -90,11 +90,11 @@ end: * * Returns the number of bytes spliced. */ -int lttng_kconsumer_on_read_subbuffer_splice( +ssize_t lttng_kconsumer_on_read_subbuffer_splice( struct lttng_consumer_local_data *ctx, struct lttng_consumer_stream *stream, unsigned long len) { - long ret = 0; + ssize_t ret = 0; loff_t offset = 0; off_t orig_offset = stream->out_fd_offset; int fd = stream->wait_fd; @@ -105,7 +105,7 @@ int lttng_kconsumer_on_read_subbuffer_splice( (unsigned long)offset, fd); ret = splice(fd, &offset, ctx->consumer_thread_pipe[1], NULL, len, SPLICE_F_MOVE | SPLICE_F_MORE); - DBG("splice chan to pipe ret %ld", ret); + DBG("splice chan to pipe ret %zd", ret); if (ret < 0) { errno = -ret; perror("Error in relay splice"); @@ -114,7 +114,7 @@ int lttng_kconsumer_on_read_subbuffer_splice( ret = splice(ctx->consumer_thread_pipe[0], NULL, outfd, NULL, ret, SPLICE_F_MOVE | SPLICE_F_MORE); - DBG("splice pipe to file %ld", ret); + DBG("splice pipe to file %zd", ret); if (ret < 0) { errno = -ret; perror("Error in file splice"); @@ -122,7 +122,7 @@ int lttng_kconsumer_on_read_subbuffer_splice( } len -= ret; /* This won't block, but will start writeout asynchronously */ - sync_file_range(outfd, stream->out_fd_offset, ret, + lttng_sync_file_range(outfd, stream->out_fd_offset, ret, SYNC_FILE_RANGE_WRITE); stream->out_fd_offset += ret; } @@ -295,11 +295,20 @@ int lttng_kconsumer_recv_cmd(struct lttng_consumer_local_data *ctx, break; } end: - /* signal the poll thread */ - ret = write(ctx->consumer_poll_pipe[1], "4", 1); - if (ret < 0) { - perror("write consumer poll"); - } + /* + * Wake-up the other end by writing a null byte in the pipe + * (non-blocking). Important note: Because writing into the + * pipe is non-blocking (and therefore we allow dropping wakeup + * data, as long as there is wakeup data present in the pipe + * buffer to wake up the other end), the other end should + * perform the following sequence for waiting: + * 1) empty the pipe (reads). + * 2) perform update operation. + * 3) wait on the pipe (poll). + */ + do { + ret = write(ctx->consumer_poll_pipe[1], "", 1); + } while (ret == -1UL && errno == EINTR); end_nosignal: return 0; } @@ -307,12 +316,12 @@ end_nosignal: /* * Consume data on a file descriptor and write it on a trace file. */ -int lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, +ssize_t lttng_kconsumer_read_subbuffer(struct lttng_consumer_stream *stream, struct lttng_consumer_local_data *ctx) { unsigned long len; int err; - long ret = 0; + ssize_t ret = 0; int infd = stream->wait_fd; DBG("In read_subbuffer (infd : %d)", infd);