[lttng-dev] [PATCH lttng-tools] Fix: check lttng-modules ABI version for RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS support

Jonathan Rajotte jonathan.rajotte-julien at efficios.com
Mon May 15 19:37:21 UTC 2017


The RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS was introduced in
lttng-modules ABI version 2.3. When interacting with a kernel tracer
witt ABI versions < 2.3, pass zero as monitor_timer_interval to disable
the monitoring.

Warn during sessiond startup and channel enabling if not supported.

Fixes #1101

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien at efficios.com>
---
 src/bin/lttng-sessiond/cmd.c    | 25 +++++++++++++++++++++++++
 src/bin/lttng-sessiond/kernel.c | 30 ++++++++++++++++++++++++++++++
 src/bin/lttng-sessiond/kernel.h |  1 +
 src/bin/lttng-sessiond/main.c   | 12 ++++++++++++
 4 files changed, 68 insertions(+)

diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c
index f3ff2564..022329c7 100644
--- a/src/bin/lttng-sessiond/cmd.c
+++ b/src/bin/lttng-sessiond/cmd.c
@@ -34,6 +34,7 @@
 #include <lttng/trigger/trigger-internal.h>
 #include <lttng/condition/condition.h>
 #include <lttng/action/action.h>
+#include <lttng/channel.h>
 #include <lttng/channel-internal.h>
 #include <common/string-utils/string-utils.h>
 
@@ -1349,6 +1350,30 @@ int cmd_enable_channel(struct ltt_session *session,
 		attr->attr.switch_timer_interval = 0;
 	}
 
+	/* Check for feature support */
+	switch (domain->type) {
+	case LTTNG_DOMAIN_KERNEL:
+	{
+		if (kernel_support_ring_buffer_snapshot_sample_positions(kernel_tracer_fd) < 1) {
+			/* Sampling position of buffer is not supported */
+			WARN("Kernel tracer does not support buffer monitoring. "
+					"Setting the monitor interval timer to 0 "
+					"(disabled) for channel '%s' of session '%s'",
+					attr-> name, session->name);
+			lttng_channel_set_monitor_timer_interval(attr, 0);
+		}
+		break;
+	}
+	case LTTNG_DOMAIN_UST:
+	case LTTNG_DOMAIN_JUL:
+	case LTTNG_DOMAIN_LOG4J:
+	case LTTNG_DOMAIN_PYTHON:
+		break;
+	default:
+		ret = LTTNG_ERR_UNKNOWN_DOMAIN;
+		goto error;
+	}
+
 	switch (domain->type) {
 	case LTTNG_DOMAIN_KERNEL:
 	{
diff --git a/src/bin/lttng-sessiond/kernel.c b/src/bin/lttng-sessiond/kernel.c
index aa516497..6bff1336 100644
--- a/src/bin/lttng-sessiond/kernel.c
+++ b/src/bin/lttng-sessiond/kernel.c
@@ -1086,3 +1086,33 @@ int kernel_syscall_mask(int chan_fd, char **syscall_mask, uint32_t *nr_bits)
 
 	return kernctl_syscall_mask(chan_fd, syscall_mask, nr_bits);
 }
+
+/*
+ * Check for the support of the RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS via abi
+ * version number.
+ * Return 1 on success, 0 when feature is not supported, negative value in case
+ * of errors.
+ */
+int kernel_support_ring_buffer_snapshot_sample_positions(int tracer_fd)
+{
+	int ret = 0; // Not supported by default
+	struct lttng_kernel_tracer_abi_version abi;
+	ret = kernctl_tracer_abi_version(tracer_fd, &abi);
+	if (ret < 0) {
+		ERR("Failed to retrieve lttng-modules ABI version");
+		goto error;
+	}
+
+	/*
+	 * RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS was introduced in 2.3
+	 */
+	if (abi.major >= 2 && abi.minor >= 3) {
+		/* Supported */
+		ret = 1;
+	} else {
+		/* Not supported */
+		ret = 0;
+	}
+error:
+	return ret;
+}
diff --git a/src/bin/lttng-sessiond/kernel.h b/src/bin/lttng-sessiond/kernel.h
index 233ceffe..8c0959df 100644
--- a/src/bin/lttng-sessiond/kernel.h
+++ b/src/bin/lttng-sessiond/kernel.h
@@ -65,5 +65,6 @@ int kernel_syscall_mask(int chan_fd, char **syscall_mask, uint32_t *nr_bits);
 int init_kernel_workarounds(void);
 ssize_t kernel_list_tracker_pids(struct ltt_kernel_session *session,
 		int **_pids);
+int kernel_support_ring_buffer_snapshot_sample_positions(int tracer_fd);
 
 #endif /* _LTT_KERNEL_CTL_H */
diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c
index b856e126..19e26fb7 100644
--- a/src/bin/lttng-sessiond/main.c
+++ b/src/bin/lttng-sessiond/main.c
@@ -2794,6 +2794,18 @@ static int init_kernel_tracer(void)
 		goto error_modules;
 	}
 
+	ret = kernel_support_ring_buffer_snapshot_sample_positions(kernel_tracer_fd);
+	if (ret < 0) {
+		goto error_modules;
+	}
+
+	if (ret < 1) {
+		WARN("Kernel tracer does not support buffer monitoring. "
+			"Monitor interval timers will be set to 0 (disabled) "
+			"for future channels.");
+	}
+
+
 	DBG("Kernel tracer fd %d", kernel_tracer_fd);
 	return 0;
 
-- 
2.11.0



More information about the lttng-dev mailing list