From 6e21424e11f47edb885c7f92ae1cae69eee0ed8e Mon Sep 17 00:00:00 2001 From: Jonathan Rajotte Date: Mon, 15 May 2017 15:37:21 -0400 Subject: [PATCH] Fix: check lttng-modules ABI version for RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS support MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The RING_BUFFER_SNAPSHOT_SAMPLE_POSITIONS was introduced in lttng-modules ABI version 2.3. When interacting with a kernel tracer with 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 Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/cmd.c | 25 +++++++++++++++++++++++++ src/bin/lttng-sessiond/kernel.c | 32 ++++++++++++++++++++++++++++++++ src/bin/lttng-sessiond/kernel.h | 1 + src/bin/lttng-sessiond/main.c | 12 ++++++++++++ 4 files changed, 70 insertions(+) diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index b836f3d8f..58b81477b 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -1357,6 +1358,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_supports_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 e47849933..b32193451 100644 --- a/src/bin/lttng-sessiond/kernel.c +++ b/src/bin/lttng-sessiond/kernel.c @@ -1088,3 +1088,35 @@ 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_supports_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 233ceffea..1b394947b 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_supports_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 e282a9c76..b2745086f 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2797,6 +2797,18 @@ static int init_kernel_tracer(void) goto error_modules; } + ret = kernel_supports_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. " + "The monitoring timer of channels in the kernel domain " + "will be set to 0 (disabled)."); + } + DBG("Kernel tracer fd %d", kernel_tracer_fd); return 0; -- 2.34.1