From: Mathieu Desnoyers Date: Wed, 30 May 2018 00:28:01 +0000 (+0200) Subject: ustctl: Implement ring buffer clear X-Git-Tag: v2.12.0-rc1~25 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=beca55a1aa4ff272188d7c37c19eb0540f811c8b;p=lttng-ust.git ustctl: Implement ring buffer clear Signed-off-by: Mathieu Desnoyers --- diff --git a/include/lttng/ust-ctl.h b/include/lttng/ust-ctl.h index 3404d9c7..932940ba 100644 --- a/include/lttng/ust-ctl.h +++ b/include/lttng/ust-ctl.h @@ -242,6 +242,7 @@ int ustctl_put_subbuf(struct ustctl_consumer_stream *stream); void ustctl_flush_buffer(struct ustctl_consumer_stream *stream, int producer_active); +void ustctl_clear_buffer(struct ustctl_consumer_stream *stream); /* index */ diff --git a/liblttng-ust-ctl/ustctl.c b/liblttng-ust-ctl/ustctl.c index 8c38ffaf..949ece17 100644 --- a/liblttng-ust-ctl/ustctl.c +++ b/liblttng-ust-ctl/ustctl.c @@ -1590,6 +1590,19 @@ void ustctl_flush_buffer(struct ustctl_consumer_stream *stream, consumer_chan->chan->handle); } +void ustctl_clear_buffer(struct ustctl_consumer_stream *stream) +{ + struct lttng_ust_lib_ring_buffer *buf; + struct ustctl_consumer_channel *consumer_chan; + + assert(stream); + buf = stream->buf; + consumer_chan = stream->chan; + lib_ring_buffer_switch_slow(buf, SWITCH_ACTIVE, + consumer_chan->chan->handle); + lib_ring_buffer_clear_reader(buf, consumer_chan->chan->handle); +} + static struct lttng_ust_client_lib_ring_buffer_client_cb *get_client_cb( struct lttng_ust_lib_ring_buffer *buf, diff --git a/libringbuffer/frontend_internal.h b/libringbuffer/frontend_internal.h index 323a8df7..4ad921ec 100644 --- a/libringbuffer/frontend_internal.h +++ b/libringbuffer/frontend_internal.h @@ -205,6 +205,32 @@ void lib_ring_buffer_reserve_push_reader(struct lttng_ust_lib_ring_buffer *buf, consumed_new) != consumed_old)); } +static inline +void lib_ring_buffer_clear_reader(struct lttng_ust_lib_ring_buffer *buf, + struct lttng_ust_shm_handle *handle) +{ + struct channel *chan; + const struct lttng_ust_lib_ring_buffer_config *config; + unsigned long offset, consumed_old, consumed_new; + + chan = shmp(handle, buf->backend.chan); + if (!chan) + return; + config = &chan->backend.config; + + do { + offset = v_read(config, &buf->offset); + consumed_old = uatomic_read(&buf->consumed); + if (caa_unlikely(subbuf_trunc(offset, chan) + - subbuf_trunc(consumed_old, chan) + > 0)) + consumed_new = subbuf_trunc(offset, chan); + else + return; + } while (caa_unlikely(uatomic_cmpxchg(&buf->consumed, consumed_old, + consumed_new) != consumed_old)); +} + static inline int lib_ring_buffer_pending_data(const struct lttng_ust_lib_ring_buffer_config *config, struct lttng_ust_lib_ring_buffer *buf,