Fix: wrapper random documentation
[lttng-modules.git] / lib / ringbuffer / frontend_internal.h
index d02a73d32c2a46bc8a26469e1fddb0fb6eb762f1..39f2b7701783c4b57b6ce1a6cd0c6028263b5323 100644 (file)
@@ -1,4 +1,4 @@
-/* SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1)
+/* SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only)
  *
  * linux/ringbuffer/frontend_internal.h
  *
@@ -154,6 +154,8 @@ extern
 void lib_ring_buffer_switch_remote(struct lib_ring_buffer *buf);
 extern
 void lib_ring_buffer_switch_remote_empty(struct lib_ring_buffer *buf);
+extern
+void lib_ring_buffer_clear(struct lib_ring_buffer *buf);
 
 /* Buffer write helpers */
 
@@ -185,6 +187,33 @@ void lib_ring_buffer_reserve_push_reader(struct lib_ring_buffer *buf,
                                              consumed_new) != consumed_old));
 }
 
+/*
+ * Move consumed position to the beginning of subbuffer in which the
+ * write offset is. Should only be used on ring buffers that are not
+ * actively being written into, because clear_reader does not take into
+ * account the commit counters when moving the consumed position, which
+ * can make concurrent trace producers or consumers observe consumed
+ * position further than the write offset, which breaks ring buffer
+ * algorithm guarantees.
+ */
+static inline
+void lib_ring_buffer_clear_reader(struct lib_ring_buffer *buf,
+                                 struct channel *chan)
+{
+       const struct lib_ring_buffer_config *config = &chan->backend.config;
+       unsigned long offset, consumed_old, consumed_new;
+
+       do {
+               offset = v_read(config, &buf->offset);
+               consumed_old = atomic_long_read(&buf->consumed);
+               CHAN_WARN_ON(chan, (long) (subbuf_trunc(offset, chan)
+                               - subbuf_trunc(consumed_old, chan))
+                               < 0);
+               consumed_new = subbuf_trunc(offset, chan);
+       } while (unlikely(atomic_long_cmpxchg(&buf->consumed, consumed_old,
+                                             consumed_new) != consumed_old));
+}
+
 static inline
 int lib_ring_buffer_pending_data(const struct lib_ring_buffer_config *config,
                                 struct lib_ring_buffer *buf,
This page took 0.024261 seconds and 4 git commands to generate.