#include <linux/seq_file.h>
#include <linux/file.h>
#include <linux/anon_inodes.h>
-#include "wrapper/file.h"
+#include <wrapper/file.h>
#include <linux/jhash.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
-#include "wrapper/uuid.h"
-#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
-#include "wrapper/random.h"
-#include "wrapper/tracepoint.h"
-#include "wrapper/list.h"
-#include "lttng-kernel-version.h"
-#include "lttng-events.h"
-#include "lttng-tracer.h"
-#include "lttng-abi-old.h"
-#include "wrapper/vzalloc.h"
+#include <wrapper/uuid.h>
+#include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/random.h>
+#include <wrapper/tracepoint.h>
+#include <wrapper/list.h>
+#include <lttng-kernel-version.h>
+#include <lttng-events.h>
+#include <lttng-tracer.h>
+#include <lttng-abi-old.h>
+#include <lttng-endian.h>
+#include <wrapper/vzalloc.h>
+#include <wrapper/ringbuffer/backend.h>
+#include <wrapper/ringbuffer/frontend.h>
#define METADATA_CACHE_DEFAULT_SIZE 4096
/* We need to sync enablers with session before activation. */
lttng_session_sync_enablers(session);
+ /* Clear each stream's quiescent state. */
+ list_for_each_entry(chan, &session->chan, list) {
+ if (chan->channel_type != METADATA_CHANNEL)
+ lib_ring_buffer_clear_quiescent_channel(chan->chan);
+ }
+
ACCESS_ONCE(session->active) = 1;
ACCESS_ONCE(session->been_active) = 1;
ret = _lttng_session_metadata_statedump(session);
int lttng_session_disable(struct lttng_session *session)
{
int ret = 0;
+ struct lttng_channel *chan;
mutex_lock(&sessions_mutex);
if (!session->active) {
/* Set transient enabler state to "disabled" */
session->tstate = 0;
lttng_session_sync_enablers(session);
+
+ /* Set each stream's quiescent state. */
+ list_for_each_entry(chan, &session->chan, list) {
+ if (chan->channel_type != METADATA_CHANNEL)
+ lib_ring_buffer_set_quiescent_channel(chan->chan);
+ }
end:
mutex_unlock(&sessions_mutex);
return ret;
ret = PTR_ERR(tracker_pids_list_file);
goto file_error;
}
+ if (atomic_long_add_unless(&session->file->f_count,
+ 1, INT_MAX) == INT_MAX) {
+ goto refcount_error;
+ }
ret = lttng_tracker_pids_list_fops.open(NULL, tracker_pids_list_file);
if (ret < 0)
goto open_error;
m = tracker_pids_list_file->private_data;
m->private = session;
fd_install(file_fd, tracker_pids_list_file);
- atomic_long_inc(&session->file->f_count);
return file_fd;
open_error:
+ atomic_long_dec(&session->file->f_count);
+refcount_error:
fput(tracker_pids_list_file);
file_error:
put_unused_fd(file_fd);
? "UTF8"
: "ASCII",
field->type.u.basic.integer.base,
-#ifdef __BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
#else
field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
const struct lttng_basic_type *elem_type;
elem_type = &field->type.u.array.elem_type;
+ if (field->type.u.array.elem_alignment) {
+ ret = lttng_metadata_printf(session,
+ " struct { } align(%u) _%s_padding;\n",
+ field->type.u.array.elem_alignment * CHAR_BIT,
+ field->name);
+ if (ret)
+ return ret;
+ }
ret = lttng_metadata_printf(session,
" integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
elem_type->u.basic.integer.size,
? "UTF8"
: "ASCII",
elem_type->u.basic.integer.base,
-#ifdef __BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
#else
elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
? "UTF8"
: "ASCII"),
length_type->u.basic.integer.base,
-#ifdef __BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
#else
length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
if (ret)
return ret;
+ if (field->type.u.sequence.elem_alignment) {
+ ret = lttng_metadata_printf(session,
+ " struct { } align(%u) _%s_padding;\n",
+ field->type.u.sequence.elem_alignment * CHAR_BIT,
+ field->name);
+ if (ret)
+ return ret;
+ }
ret = lttng_metadata_printf(session,
" integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
elem_type->u.basic.integer.size,
? "UTF8"
: "ASCII"),
elem_type->u.basic.integer.base,
-#ifdef __BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
#else
elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
* taken at start of trace.
* Yes, this is only an approximation. Yes, we can (and will) do better
* in future versions.
+ * This function may return a negative offset. It may happen if the
+ * system sets the REALTIME clock to 0 after boot.
*/
static
-uint64_t measure_clock_offset(void)
+int64_t measure_clock_offset(void)
{
- uint64_t offset, monotonic[2], realtime;
+ uint64_t monotonic_avg, monotonic[2], realtime;
+ uint64_t tcf = trace_clock_freq();
+ int64_t offset;
struct timespec rts = { 0, 0 };
unsigned long flags;
monotonic[1] = trace_clock_read64();
local_irq_restore(flags);
- offset = (monotonic[0] + monotonic[1]) >> 1;
- realtime = (uint64_t) rts.tv_sec * NSEC_PER_SEC;
- realtime += rts.tv_nsec;
- offset = realtime - offset;
+ monotonic_avg = (monotonic[0] + monotonic[1]) >> 1;
+ realtime = (uint64_t) rts.tv_sec * tcf;
+ if (tcf == NSEC_PER_SEC) {
+ realtime += rts.tv_nsec;
+ } else {
+ uint64_t n = rts.tv_nsec * tcf;
+
+ do_div(n, NSEC_PER_SEC);
+ realtime += n;
+ }
+ offset = (int64_t) realtime - monotonic_avg;
return offset;
}
CTF_SPEC_MAJOR,
CTF_SPEC_MINOR,
uuid_s,
-#ifdef __BIG_ENDIAN
+#if __BYTE_ORDER == __BIG_ENDIAN
"be"
#else
"le"
ret = lttng_metadata_printf(session,
"clock {\n"
- " name = %s;\n",
- "monotonic"
+ " name = \"%s\";\n",
+ trace_clock_name()
);
if (ret)
goto end;
}
ret = lttng_metadata_printf(session,
- " description = \"Monotonic Clock\";\n"
+ " description = \"%s\";\n"
" freq = %llu; /* Frequency, in Hz */\n"
" /* clock value offset from Epoch is: offset * (1/freq) */\n"
- " offset = %llu;\n"
+ " offset = %lld;\n"
"};\n\n",
+ trace_clock_description(),
(unsigned long long) trace_clock_freq(),
- (unsigned long long) measure_clock_offset()
+ (long long) measure_clock_offset()
);
if (ret)
goto end;
ret = lttng_metadata_printf(session,
"typealias integer {\n"
" size = 27; align = 1; signed = false;\n"
- " map = clock.monotonic.value;\n"
+ " map = clock.%s.value;\n"
"} := uint27_clock_monotonic_t;\n"
"\n"
"typealias integer {\n"
" size = 32; align = %u; signed = false;\n"
- " map = clock.monotonic.value;\n"
+ " map = clock.%s.value;\n"
"} := uint32_clock_monotonic_t;\n"
"\n"
"typealias integer {\n"
" size = 64; align = %u; signed = false;\n"
- " map = clock.monotonic.value;\n"
+ " map = clock.%s.value;\n"
"} := uint64_clock_monotonic_t;\n\n",
+ trace_clock_name(),
lttng_alignof(uint32_t) * CHAR_BIT,
- lttng_alignof(uint64_t) * CHAR_BIT
+ trace_clock_name(),
+ lttng_alignof(uint64_t) * CHAR_BIT,
+ trace_clock_name()
);
if (ret)
goto end;
}
EXPORT_SYMBOL_GPL(lttng_transport_unregister);
+#if (defined(CONFIG_HOTPLUG_CPU) && (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)))
+
+enum cpuhp_state lttng_hp_prepare;
+enum cpuhp_state lttng_hp_online;
+
+static int lttng_hotplug_prepare(unsigned int cpu, struct hlist_node *node)
+{
+ struct lttng_cpuhp_node *lttng_node;
+
+ lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+ switch (lttng_node->component) {
+ case LTTNG_RING_BUFFER_FRONTEND:
+ return 0;
+ case LTTNG_RING_BUFFER_BACKEND:
+ return lttng_cpuhp_rb_backend_prepare(cpu, lttng_node);
+ case LTTNG_RING_BUFFER_ITER:
+ return 0;
+ case LTTNG_CONTEXT_PERF_COUNTERS:
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
+static int lttng_hotplug_dead(unsigned int cpu, struct hlist_node *node)
+{
+ struct lttng_cpuhp_node *lttng_node;
+
+ lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+ switch (lttng_node->component) {
+ case LTTNG_RING_BUFFER_FRONTEND:
+ return lttng_cpuhp_rb_frontend_dead(cpu, lttng_node);
+ case LTTNG_RING_BUFFER_BACKEND:
+ return 0;
+ case LTTNG_RING_BUFFER_ITER:
+ return 0;
+ case LTTNG_CONTEXT_PERF_COUNTERS:
+ return lttng_cpuhp_perf_counter_dead(cpu, lttng_node);
+ default:
+ return -EINVAL;
+ }
+}
+
+static int lttng_hotplug_online(unsigned int cpu, struct hlist_node *node)
+{
+ struct lttng_cpuhp_node *lttng_node;
+
+ lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+ switch (lttng_node->component) {
+ case LTTNG_RING_BUFFER_FRONTEND:
+ return lttng_cpuhp_rb_frontend_online(cpu, lttng_node);
+ case LTTNG_RING_BUFFER_BACKEND:
+ return 0;
+ case LTTNG_RING_BUFFER_ITER:
+ return lttng_cpuhp_rb_iter_online(cpu, lttng_node);
+ case LTTNG_CONTEXT_PERF_COUNTERS:
+ return lttng_cpuhp_perf_counter_online(cpu, lttng_node);
+ default:
+ return -EINVAL;
+ }
+}
+
+static int lttng_hotplug_offline(unsigned int cpu, struct hlist_node *node)
+{
+ struct lttng_cpuhp_node *lttng_node;
+
+ lttng_node = container_of(node, struct lttng_cpuhp_node, node);
+ switch (lttng_node->component) {
+ case LTTNG_RING_BUFFER_FRONTEND:
+ return lttng_cpuhp_rb_frontend_offline(cpu, lttng_node);
+ case LTTNG_RING_BUFFER_BACKEND:
+ return 0;
+ case LTTNG_RING_BUFFER_ITER:
+ return 0;
+ case LTTNG_CONTEXT_PERF_COUNTERS:
+ return 0;
+ default:
+ return -EINVAL;
+ }
+}
+
+static int __init lttng_init_cpu_hotplug(void)
+{
+ int ret;
+
+ ret = cpuhp_setup_state_multi(CPUHP_BP_PREPARE_DYN, "lttng:prepare",
+ lttng_hotplug_prepare,
+ lttng_hotplug_dead);
+ if (ret < 0) {
+ return ret;
+ }
+ lttng_hp_prepare = ret;
+ lttng_rb_set_hp_prepare(ret);
+
+ ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "lttng:online",
+ lttng_hotplug_online,
+ lttng_hotplug_offline);
+ if (ret < 0) {
+ cpuhp_remove_multi_state(lttng_hp_prepare);
+ lttng_hp_prepare = 0;
+ return ret;
+ }
+ lttng_hp_online = ret;
+ lttng_rb_set_hp_online(ret);
+
+ return 0;
+}
+
+static void __exit lttng_exit_cpu_hotplug(void)
+{
+ lttng_rb_set_hp_online(0);
+ cpuhp_remove_multi_state(lttng_hp_online);
+ lttng_rb_set_hp_prepare(0);
+ cpuhp_remove_multi_state(lttng_hp_prepare);
+}
+
+#else /* #if (CONFIG_HOTPLUG_CPU && (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))) */
+static int lttng_init_cpu_hotplug(void)
+{
+ return 0;
+}
+static void lttng_exit_cpu_hotplug(void)
+{
+}
+#endif /* #else #if (CONFIG_HOTPLUG_CPU && (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))) */
+
+
static int __init lttng_events_init(void)
{
int ret;
if (ret)
return ret;
ret = wrapper_get_pfnblock_flags_mask_init();
+ if (ret)
+ return ret;
+ ret = wrapper_get_pageblock_flags_mask_init();
if (ret)
return ret;
ret = lttng_context_init();
ret = lttng_logger_init();
if (ret)
goto error_logger;
+ ret = lttng_init_cpu_hotplug();
+ if (ret)
+ goto error_hotplug;
return 0;
+error_hotplug:
+ lttng_logger_exit();
error_logger:
lttng_abi_exit();
error_abi:
{
struct lttng_session *session, *tmpsession;
+ lttng_exit_cpu_hotplug();
lttng_logger_exit();
lttng_abi_exit();
list_for_each_entry_safe(session, tmpsession, &sessions, list)