Skip to contentSkip to conversation

] Add ustctl_snapshot_sample_positions ustctl command

RFC PATCH Superseded Jérémie Galarneau 2 participants 2 messages May 5, 2017 2 messages not in the archive

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#1 lore raw

RFC PATCH v2 1/1 ] Add ustctl_snapshot_sample_positions ustctl command

In reply to a message not in the archive

The major version is bumped as a new API entry point is introduced.

---
 configure.ac                         |  2 +-
 include/lttng/ust-abi.h              |  2 +-
 include/lttng/ust-ctl.h              |  1 +
 liblttng-ust-ctl/ustctl.c            | 19 ++++++++++++++++++
 libringbuffer/frontend.h             |  5 +++++
 libringbuffer/ring_buffer_frontend.c | 38 ++++++++++++++++++++++++++++++++++++
 6 files changed, 65 insertions(+), 2 deletions(-)
configure.ac +1 -1
index 450b43b2..6f9ef451 100644
@@ -22,7 +22,7 @@ AC_SUBST([LTTNG_UST_LIBRARY_VERSION], [0:0:0])
 
 # This is the library version of liblttng-ust-ctl, used internally by
 # liblttng-ust, lttng-sessiond, and lttng-consumerd.
-AC_SUBST([LTTNG_UST_CTL_LIBRARY_VERSION], [2:0:0])
+AC_SUBST([LTTNG_UST_CTL_LIBRARY_VERSION], [3:0:1])
 
 AC_CONFIG_AUX_DIR([config])
 AC_CANONICAL_TARGET
include/lttng/ust-abi.h +1 -1
index 6e8f8d7b..f76d2a9f 100644
@@ -43,7 +43,7 @@
 
 /* Version for ABI between liblttng-ust, sessiond, consumerd */
 #define LTTNG_UST_ABI_MAJOR_VERSION		7
-#define LTTNG_UST_ABI_MINOR_VERSION		1
+#define LTTNG_UST_ABI_MINOR_VERSION		2
 
 enum lttng_ust_instrumentation {
 	LTTNG_UST_TRACEPOINT		= 0,
include/lttng/ust-ctl.h +1 -0
index 7b750fd4..f6c1dc45 100644
@@ -226,6 +226,7 @@ int ustctl_put_next_subbuf(struct ustctl_consumer_stream *stream);
 /* snapshot */
 
 int ustctl_snapshot(struct ustctl_consumer_stream *stream);
+int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream);
 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream,
 		unsigned long *pos);
 int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream,
liblttng-ust-ctl/ustctl.c +19 -0
index 2af79147..a317de96 100644
@@ -1500,6 +1500,25 @@ int ustctl_snapshot(struct ustctl_consumer_stream *stream)
 			&buf->prod_snapshot, consumer_chan->chan->handle);
 }
 
+/*
+ * Get a snapshot of the current ring buffer producer and consumer positions
+ * even if the consumed and produced positions are contained withinin the same
+ * subbuffer.
+ */
+int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream)
+{
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+	return lib_ring_buffer_snapshot_sample_positions(buf,
+			&buf->cons_snapshot, &buf->prod_snapshot,
+			consumer_chan->chan->handle);
+}
+
 /* Get the consumer position (iteration start) */
 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream,
 		unsigned long *pos)
libringbuffer/frontend.h +5 -0
index 160fd455..a2f74596 100644
@@ -131,6 +131,11 @@ extern int lib_ring_buffer_snapshot(struct lttng_ust_lib_ring_buffer *buf,
 				    unsigned long *consumed,
 				    unsigned long *produced,
 				    struct lttng_ust_shm_handle *handle);
+extern int lib_ring_buffer_snapshot_sample_positions(
+				    struct lttng_ust_lib_ring_buffer *buf,
+				    unsigned long *consumed,
+				    unsigned long *produced,
+				    struct lttng_ust_shm_handle *handle);
 extern void lib_ring_buffer_move_consumer(struct lttng_ust_lib_ring_buffer *buf,
 					  unsigned long consumed_new,
 					  struct lttng_ust_shm_handle *handle);
libringbuffer/ring_buffer_frontend.c +38 -0
index 6dd81e14..9b166852 100644
@@ -1306,6 +1306,44 @@ nodata:
 }
 
 /**
+ * Performs the same function as lib_ring_buffer_snapshot(), but the positions
+ * are saved regardless of whether the consumed and produced positions are
+ * in the same subbuffer.
+ * @buf: ring buffer
+ * @consumed: consumed byte count indicating the last position read
+ * @produced: produced byte count indicating the last position written
+ *
+ * This function is meant to provide information on the exact producer and
+ * consumer positions without regard for the "snapshot" feature.
+ */
+int lib_ring_buffer_snapshot_sample_positions(
+			     struct lttng_ust_lib_ring_buffer *buf,
+			     unsigned long *consumed, unsigned long *produced,
+			     struct lttng_ust_shm_handle *handle)
+{
+	struct channel *chan;
+	const struct lttng_ust_lib_ring_buffer_config *config;
+	unsigned long consumed_cur, write_offset;
+
+	chan = shmp(handle, buf->backend.chan);
+	if (!chan)
+		return -EPERM;
+	config = &chan->backend.config;
+	cmm_smp_rmb();
+	*consumed = uatomic_read(&buf->consumed);
+	/*
+	 * No need to issue a memory barrier between consumed count read and
+	 * write offset read, because consumed count can only change
+	 * concurrently in overwrite mode, and we keep a sequence counter
+	 * identifier derived from the write offset to check we are getting
+	 * the same sub-buffer we are expecting (the sub-buffers are atomically
+	 * "tagged" upon writes, tags are checked upon read).
+	 */
+	*produced = v_read(config, &buf->offset);
+	return 0;
+}
+
+/**
  * lib_ring_buffer_move_consumer - move consumed counter forward
  * @buf: ring buffer
  * @consumed_new: new consumed count value
Signature · 6 lines
2.12.2

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#3 lore raw
In reply to a message not in the archive
Quoted 2 lines · ----- On May 5, 2017, at 10:22 AM, Jeremie Galarneau…

The major version is bumped as a new API entry point is introduced.

First thing, the patch does not apply on master here.

Can you update the changelog ?

One more nit below,

Quoted 55 lines

---

configure.ac                         |  2 +-
include/lttng/ust-abi.h              |  2 +-
include/lttng/ust-ctl.h              |  1 +
liblttng-ust-ctl/ustctl.c            | 19 ++++++++++++++++++
libringbuffer/frontend.h             |  5 +++++
libringbuffer/ring_buffer_frontend.c | 38 ++++++++++++++++++++++++++++++++++++
6 files changed, 65 insertions(+), 2 deletions(-)
configure.ac +1 -1
index 450b43b2..6f9ef451 100644
@@ -22,7 +22,7 @@ AC_SUBST([LTTNG_UST_LIBRARY_VERSION], [0:0:0])
 
 # This is the library version of liblttng-ust-ctl, used internally by
 # liblttng-ust, lttng-sessiond, and lttng-consumerd.
-AC_SUBST([LTTNG_UST_CTL_LIBRARY_VERSION], [2:0:0])
+AC_SUBST([LTTNG_UST_CTL_LIBRARY_VERSION], [3:0:1])
 
 AC_CONFIG_AUX_DIR([config])

AC_CANONICAL_TARGET

include/lttng/ust-abi.h +1 -1
index 6e8f8d7b..f76d2a9f 100644
@@ -43,7 +43,7 @@
 
 /* Version for ABI between liblttng-ust, sessiond, consumerd */
 #define LTTNG_UST_ABI_MAJOR_VERSION		7
-#define LTTNG_UST_ABI_MINOR_VERSION		1
+#define LTTNG_UST_ABI_MINOR_VERSION		2
 
 enum lttng_ust_instrumentation {
 	LTTNG_UST_TRACEPOINT		= 0,
include/lttng/ust-ctl.h +1 -0
index 7b750fd4..f6c1dc45 100644
@@ -226,6 +226,7 @@ int ustctl_put_next_subbuf(struct ustctl_consumer_stream
 *stream);
 /* snapshot */
 
 int ustctl_snapshot(struct ustctl_consumer_stream *stream);
+int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream);
 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream,
 		unsigned long *pos);

int ustctl_snapshot_get_produced(struct ustctl_consumer_stream *stream,

liblttng-ust-ctl/ustctl.c +0 -0
index 2af79147..a317de96 100644

liblttng-ust-ctl/ustctl.c int ustctl_snapshot(struct ustctl_consumer_stream · line 1506

Quoted 7 lines
liblttng-ust-ctl/ustctl.c +3 -0
@@ -1500,6 +1500,25 @@ int ustctl_snapshot(struct ustctl_consumer_stream
 *stream)
 			&buf->prod_snapshot, consumer_chan->chan->handle);
 }
 
+/*
+ * Get a snapshot of the current ring buffer producer and consumer positions
+ * even if the consumed and produced positions are contained withinin the same

withinin -> within

Thanks,

Mathieu

Quoted 88 lines
liblttng-ust-ctl/ustctl.c +16 -0
+ * subbuffer.
+ */
+int ustctl_snapshot_sample_positions(struct ustctl_consumer_stream *stream)
+{
+	struct lttng_ust_lib_ring_buffer *buf;
+	struct ustctl_consumer_channel *consumer_chan;
+
+	if (!stream)
+		return -EINVAL;
+	buf = stream->buf;
+	consumer_chan = stream->chan;
+	return lib_ring_buffer_snapshot_sample_positions(buf,
+			&buf->cons_snapshot, &buf->prod_snapshot,
+			consumer_chan->chan->handle);
+}
+
 /* Get the consumer position (iteration start) */
 int ustctl_snapshot_get_consumed(struct ustctl_consumer_stream *stream,

unsigned long *pos)

libringbuffer/frontend.h +5 -0
index 160fd455..a2f74596 100644
@@ -131,6 +131,11 @@ extern int lib_ring_buffer_snapshot(struct
 lttng_ust_lib_ring_buffer *buf,
 				    unsigned long *consumed,
 				    unsigned long *produced,
 				    struct lttng_ust_shm_handle *handle);
+extern int lib_ring_buffer_snapshot_sample_positions(
+				    struct lttng_ust_lib_ring_buffer *buf,
+				    unsigned long *consumed,
+				    unsigned long *produced,
+				    struct lttng_ust_shm_handle *handle);
 extern void lib_ring_buffer_move_consumer(struct lttng_ust_lib_ring_buffer *buf,
 					  unsigned long consumed_new,
					  struct lttng_ust_shm_handle *handle);
libringbuffer/ring_buffer_frontend.c +38 -1
index 6dd81e14..9b166852 100644
@@ -1306,6 +1306,44 @@ nodata:
 }
 
 /**
+ * Performs the same function as lib_ring_buffer_snapshot(), but the positions
+ * are saved regardless of whether the consumed and produced positions are
+ * in the same subbuffer.
+ * @buf: ring buffer
+ * @consumed: consumed byte count indicating the last position read
+ * @produced: produced byte count indicating the last position written
+ *
+ * This function is meant to provide information on the exact producer and
+ * consumer positions without regard for the "snapshot" feature.
+ */
+int lib_ring_buffer_snapshot_sample_positions(
+			     struct lttng_ust_lib_ring_buffer *buf,
+			     unsigned long *consumed, unsigned long *produced,
+			     struct lttng_ust_shm_handle *handle)
+{
+	struct channel *chan;
+	const struct lttng_ust_lib_ring_buffer_config *config;
+	unsigned long consumed_cur, write_offset;
+
+	chan = shmp(handle, buf->backend.chan);
+	if (!chan)
+		return -EPERM;
+	config = &chan->backend.config;
+	cmm_smp_rmb();
+	*consumed = uatomic_read(&buf->consumed);
+	/*
+	 * No need to issue a memory barrier between consumed count read and
+	 * write offset read, because consumed count can only change
+	 * concurrently in overwrite mode, and we keep a sequence counter
+	 * identifier derived from the write offset to check we are getting
+	 * the same sub-buffer we are expecting (the sub-buffers are atomically
+	 * "tagged" upon writes, tags are checked upon read).
+	 */
+	*produced = v_read(config, &buf->offset);
+	return 0;
+}
+
+/**
 * lib_ring_buffer_move_consumer - move consumed counter forward
 * @buf: ring buffer
 * @consumed_new: new consumed count value
--

2.12.2

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev