ustctl: Implement ring buffer clear
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 30 May 2018 00:28:01 +0000 (02:28 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 26 Aug 2019 17:26:21 +0000 (13:26 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/ust-ctl.h
liblttng-ust-ctl/ustctl.c
libringbuffer/frontend_internal.h

index 3404d9c74c3e8d576cb8499c1600ef2ea8e140ab..932940babf393304964e039a0cc5256aa50d96c5 100644 (file)
@@ -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 */
 
index 8c38ffaf05dfc169aa82be957ded5d1e4d9aee63..949ece17ace8a2d8ec2a2d624b0451fd5ee83313 100644 (file)
@@ -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,
index 323a8df7f98cd7e5d3aba69302c6c291799b8bbd..4ad921ec0ec8263086cddbf1c11044110dc672f6 100644 (file)
@@ -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,
This page took 0.028555 seconds and 4 git commands to generate.