[lttng-dev] [PATCH 12/20] lttng: dynamically selectable context information
Mathieu Desnoyers
mathieu.desnoyers at efficios.com
Mon Nov 28 07:42:19 EST 2011
Events can be augmented with context information. This is dynamically
configurable from the command line.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
---
drivers/staging/lttng/ltt-context.c | 93 +++++++
drivers/staging/lttng/lttng-context-nice.c | 68 +++++
.../staging/lttng/lttng-context-perf-counters.c | 271 ++++++++++++++++++++
drivers/staging/lttng/lttng-context-pid.c | 68 +++++
drivers/staging/lttng/lttng-context-ppid.c | 71 +++++
drivers/staging/lttng/lttng-context-prio.c | 89 +++++++
drivers/staging/lttng/lttng-context-procname.c | 72 +++++
drivers/staging/lttng/lttng-context-tid.c | 68 +++++
drivers/staging/lttng/lttng-context-vpid.c | 74 ++++++
drivers/staging/lttng/lttng-context-vppid.c | 79 ++++++
drivers/staging/lttng/lttng-context-vtid.c | 74 ++++++
11 files changed, 1027 insertions(+), 0 deletions(-)
create mode 100644 drivers/staging/lttng/ltt-context.c
create mode 100644 drivers/staging/lttng/lttng-context-nice.c
create mode 100644 drivers/staging/lttng/lttng-context-perf-counters.c
create mode 100644 drivers/staging/lttng/lttng-context-pid.c
create mode 100644 drivers/staging/lttng/lttng-context-ppid.c
create mode 100644 drivers/staging/lttng/lttng-context-prio.c
create mode 100644 drivers/staging/lttng/lttng-context-procname.c
create mode 100644 drivers/staging/lttng/lttng-context-tid.c
create mode 100644 drivers/staging/lttng/lttng-context-vpid.c
create mode 100644 drivers/staging/lttng/lttng-context-vppid.c
create mode 100644 drivers/staging/lttng/lttng-context-vtid.c
diff --git a/drivers/staging/lttng/ltt-context.c b/drivers/staging/lttng/ltt-context.c
new file mode 100644
index 0000000..60ea525
--- /dev/null
+++ b/drivers/staging/lttng/ltt-context.c
@@ -0,0 +1,93 @@
+/*
+ * ltt-context.c
+ *
+ * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng trace/channel/event context management.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include "wrapper/vmalloc.h" /* for wrapper_vmalloc_sync_all() */
+#include "ltt-events.h"
+#include "ltt-tracer.h"
+
+int lttng_find_context(struct lttng_ctx *ctx, const char *name)
+{
+ unsigned int i;
+
+ for (i = 0; i < ctx->nr_fields; i++) {
+ /* Skip allocated (but non-initialized) contexts */
+ if (!ctx->fields[i].event_field.name)
+ continue;
+ if (!strcmp(ctx->fields[i].event_field.name, name))
+ return 1;
+ }
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_find_context);
+
+/*
+ * Note: as we append context information, the pointer location may change.
+ */
+struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx_p)
+{
+ struct lttng_ctx_field *field;
+ struct lttng_ctx *ctx;
+
+ if (!*ctx_p) {
+ *ctx_p = kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL);
+ if (!*ctx_p)
+ return NULL;
+ }
+ ctx = *ctx_p;
+ if (ctx->nr_fields + 1 > ctx->allocated_fields) {
+ struct lttng_ctx_field *new_fields;
+
+ ctx->allocated_fields = max_t(size_t, 1, 2 * ctx->allocated_fields);
+ new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL);
+ if (!new_fields)
+ return NULL;
+ if (ctx->fields)
+ memcpy(new_fields, ctx->fields, sizeof(*ctx->fields) * ctx->nr_fields);
+ kfree(ctx->fields);
+ ctx->fields = new_fields;
+ }
+ field = &ctx->fields[ctx->nr_fields];
+ ctx->nr_fields++;
+ return field;
+}
+EXPORT_SYMBOL_GPL(lttng_append_context);
+
+/*
+ * Remove last context field.
+ */
+void lttng_remove_context_field(struct lttng_ctx **ctx_p,
+ struct lttng_ctx_field *field)
+{
+ struct lttng_ctx *ctx;
+
+ ctx = *ctx_p;
+ ctx->nr_fields--;
+ WARN_ON_ONCE(&ctx->fields[ctx->nr_fields] != field);
+ memset(&ctx->fields[ctx->nr_fields], 0, sizeof(struct lttng_ctx_field));
+}
+EXPORT_SYMBOL_GPL(lttng_remove_context_field);
+
+void lttng_destroy_context(struct lttng_ctx *ctx)
+{
+ int i;
+
+ if (!ctx)
+ return;
+ for (i = 0; i < ctx->nr_fields; i++) {
+ if (ctx->fields[i].destroy)
+ ctx->fields[i].destroy(&ctx->fields[i]);
+ }
+ kfree(ctx->fields);
+ kfree(ctx);
+}
diff --git a/drivers/staging/lttng/lttng-context-nice.c b/drivers/staging/lttng/lttng-context-nice.c
new file mode 100644
index 0000000..9b99b54
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-nice.c
@@ -0,0 +1,68 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng nice context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t nice_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(int));
+ size += sizeof(int);
+ return size;
+}
+
+static
+void nice_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ int nice;
+
+ nice = task_nice(current);
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(nice));
+ chan->ops->event_write(ctx, &nice, sizeof(nice));
+}
+
+int lttng_add_nice_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "nice")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "nice";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(int) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(int);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = nice_get_size;
+ field->record = nice_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_nice_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Nice Context");
diff --git a/drivers/staging/lttng/lttng-context-perf-counters.c b/drivers/staging/lttng/lttng-context-perf-counters.c
new file mode 100644
index 0000000..3ae2266
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-perf-counters.c
@@ -0,0 +1,271 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng performance monitoring counters (perf-counters) integration module.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/perf_event.h>
+#include <linux/list.h>
+#include <linux/string.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "wrapper/perf.h"
+#include "ltt-tracer.h"
+
+static
+size_t perf_counter_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(uint64_t));
+ size += sizeof(uint64_t);
+ return size;
+}
+
+static
+void perf_counter_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ struct perf_event *event;
+ uint64_t value;
+
+ event = field->u.perf_counter->e[ctx->cpu];
+ if (likely(event)) {
+ if (unlikely(event->state == PERF_EVENT_STATE_ERROR)) {
+ value = 0;
+ } else {
+ event->pmu->read(event);
+ value = local64_read(&event->count);
+ }
+ } else {
+ /*
+ * Perf chooses not to be clever and not to support enabling a
+ * perf counter before the cpu is brought up. Therefore, we need
+ * to support having events coming (e.g. scheduler events)
+ * before the counter is setup. Write an arbitrary 0 in this
+ * case.
+ */
+ value = 0;
+ }
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(value));
+ chan->ops->event_write(ctx, &value, sizeof(value));
+}
+
+#if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,99))
+static
+void overflow_callback(struct perf_event *event,
+ struct perf_sample_data *data,
+ struct pt_regs *regs)
+{
+}
+#else
+static
+void overflow_callback(struct perf_event *event, int nmi,
+ struct perf_sample_data *data,
+ struct pt_regs *regs)
+{
+}
+#endif
+
+static
+void lttng_destroy_perf_counter_field(struct lttng_ctx_field *field)
+{
+ struct perf_event **events = field->u.perf_counter->e;
+ int cpu;
+
+ get_online_cpus();
+ for_each_online_cpu(cpu)
+ perf_event_release_kernel(events[cpu]);
+ put_online_cpus();
+#ifdef CONFIG_HOTPLUG_CPU
+ unregister_cpu_notifier(&field->u.perf_counter->nb);
+#endif
+ kfree(field->event_field.name);
+ kfree(field->u.perf_counter->attr);
+ kfree(events);
+ kfree(field->u.perf_counter);
+}
+
+#ifdef CONFIG_HOTPLUG_CPU
+
+/**
+ * lttng_perf_counter_hp_callback - CPU hotplug callback
+ * @nb: notifier block
+ * @action: hotplug action to take
+ * @hcpu: CPU number
+ *
+ * Returns the success/failure of the operation. (%NOTIFY_OK, %NOTIFY_BAD)
+ *
+ * We can setup perf counters when the cpu is online (up prepare seems to be too
+ * soon).
+ */
+static
+int __cpuinit lttng_perf_counter_cpu_hp_callback(struct notifier_block *nb,
+ unsigned long action,
+ void *hcpu)
+{
+ unsigned int cpu = (unsigned long) hcpu;
+ struct lttng_perf_counter_field *perf_field =
+ container_of(nb, struct lttng_perf_counter_field, nb);
+ struct perf_event **events = perf_field->e;
+ struct perf_event_attr *attr = perf_field->attr;
+ struct perf_event *pevent;
+
+ if (!perf_field->hp_enable)
+ return NOTIFY_OK;
+
+ switch (action) {
+ case CPU_ONLINE:
+ case CPU_ONLINE_FROZEN:
+ pevent = wrapper_perf_event_create_kernel_counter(attr,
+ cpu, NULL, overflow_callback);
+ if (!pevent || IS_ERR(pevent))
+ return NOTIFY_BAD;
+ if (pevent->state == PERF_EVENT_STATE_ERROR) {
+ perf_event_release_kernel(pevent);
+ return NOTIFY_BAD;
+ }
+ barrier(); /* Create perf counter before setting event */
+ events[cpu] = pevent;
+ break;
+ case CPU_UP_CANCELED:
+ case CPU_UP_CANCELED_FROZEN:
+ case CPU_DEAD:
+ case CPU_DEAD_FROZEN:
+ pevent = events[cpu];
+ events[cpu] = NULL;
+ barrier(); /* NULLify event before perf counter teardown */
+ perf_event_release_kernel(pevent);
+ break;
+ }
+ return NOTIFY_OK;
+}
+
+#endif
+
+int lttng_add_perf_counter_to_ctx(uint32_t type,
+ uint64_t config,
+ const char *name,
+ struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+ struct lttng_perf_counter_field *perf_field;
+ struct perf_event **events;
+ struct perf_event_attr *attr;
+ int ret;
+ int cpu;
+ char *name_alloc;
+
+ events = kzalloc(num_possible_cpus() * sizeof(*events), GFP_KERNEL);
+ if (!events)
+ return -ENOMEM;
+
+ attr = kzalloc(sizeof(struct perf_event_attr), GFP_KERNEL);
+ if (!attr) {
+ ret = -ENOMEM;
+ goto error_attr;
+ }
+
+ attr->type = type;
+ attr->config = config;
+ attr->size = sizeof(struct perf_event_attr);
+ attr->pinned = 1;
+ attr->disabled = 0;
+
+ perf_field = kzalloc(sizeof(struct lttng_perf_counter_field), GFP_KERNEL);
+ if (!perf_field) {
+ ret = -ENOMEM;
+ goto error_alloc_perf_field;
+ }
+ perf_field->e = events;
+ perf_field->attr = attr;
+
+ name_alloc = kstrdup(name, GFP_KERNEL);
+ if (!name_alloc) {
+ ret = -ENOMEM;
+ goto name_alloc_error;
+ }
+
+ field = lttng_append_context(ctx);
+ if (!field) {
+ ret = -ENOMEM;
+ goto append_context_error;
+ }
+ if (lttng_find_context(*ctx, name_alloc)) {
+ ret = -EEXIST;
+ goto find_error;
+ }
+
+#ifdef CONFIG_HOTPLUG_CPU
+ perf_field->nb.notifier_call =
+ lttng_perf_counter_cpu_hp_callback;
+ perf_field->nb.priority = 0;
+ register_cpu_notifier(&perf_field->nb);
+#endif
+
+ get_online_cpus();
+ for_each_online_cpu(cpu) {
+ events[cpu] = wrapper_perf_event_create_kernel_counter(attr,
+ cpu, NULL, overflow_callback);
+ if (!events[cpu] || IS_ERR(events[cpu])) {
+ ret = -EINVAL;
+ goto counter_error;
+ }
+ if (events[cpu]->state == PERF_EVENT_STATE_ERROR) {
+ ret = -EBUSY;
+ goto counter_busy;
+ }
+ }
+ put_online_cpus();
+
+ field->destroy = lttng_destroy_perf_counter_field;
+
+ field->event_field.name = name_alloc;
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(uint64_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(uint64_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(uint64_t);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = perf_counter_get_size;
+ field->record = perf_counter_record;
+ field->u.perf_counter = perf_field;
+ perf_field->hp_enable = 1;
+
+ wrapper_vmalloc_sync_all();
+ return 0;
+
+counter_busy:
+counter_error:
+ for_each_online_cpu(cpu) {
+ if (events[cpu] && !IS_ERR(events[cpu]))
+ perf_event_release_kernel(events[cpu]);
+ }
+ put_online_cpus();
+#ifdef CONFIG_HOTPLUG_CPU
+ unregister_cpu_notifier(&perf_field->nb);
+#endif
+find_error:
+ lttng_remove_context_field(ctx, field);
+append_context_error:
+ kfree(name_alloc);
+name_alloc_error:
+ kfree(perf_field);
+error_alloc_perf_field:
+ kfree(attr);
+error_attr:
+ kfree(events);
+ return ret;
+}
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
diff --git a/drivers/staging/lttng/lttng-context-pid.c b/drivers/staging/lttng/lttng-context-pid.c
new file mode 100644
index 0000000..698b242
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-pid.c
@@ -0,0 +1,68 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng PID context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t pid_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(pid_t));
+ size += sizeof(pid_t);
+ return size;
+}
+
+static
+void pid_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ pid_t pid;
+
+ pid = task_tgid_nr(current);
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(pid));
+ chan->ops->event_write(ctx, &pid, sizeof(pid));
+}
+
+int lttng_add_pid_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "pid")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "pid";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = pid_get_size;
+ field->record = pid_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_pid_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit PID Context");
diff --git a/drivers/staging/lttng/lttng-context-ppid.c b/drivers/staging/lttng/lttng-context-ppid.c
new file mode 100644
index 0000000..738f7e6
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-ppid.c
@@ -0,0 +1,71 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng PPID context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include <linux/syscalls.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t ppid_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(pid_t));
+ size += sizeof(pid_t);
+ return size;
+}
+
+static
+void ppid_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ pid_t ppid;
+
+ rcu_read_lock();
+ ppid = task_tgid_nr(current->real_parent);
+ rcu_read_unlock();
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(ppid));
+ chan->ops->event_write(ctx, &ppid, sizeof(ppid));
+}
+
+int lttng_add_ppid_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "ppid")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "ppid";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = ppid_get_size;
+ field->record = ppid_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_ppid_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit PPID Context");
diff --git a/drivers/staging/lttng/lttng-context-prio.c b/drivers/staging/lttng/lttng-context-prio.c
new file mode 100644
index 0000000..1ee3a54
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-prio.c
@@ -0,0 +1,89 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng priority context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "wrapper/kallsyms.h"
+#include "ltt-tracer.h"
+
+static
+int (*wrapper_task_prio_sym)(struct task_struct *t);
+
+int wrapper_task_prio_init(void)
+{
+ wrapper_task_prio_sym = (void *) kallsyms_lookup_funcptr("task_prio");
+ if (!wrapper_task_prio_sym) {
+ printk(KERN_WARNING "LTTng: task_prio symbol lookup failed.\n");
+ return -EINVAL;
+ }
+ return 0;
+}
+
+static
+size_t prio_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(int));
+ size += sizeof(int);
+ return size;
+}
+
+static
+void prio_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ int prio;
+
+ prio = wrapper_task_prio_sym(current);
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(prio));
+ chan->ops->event_write(ctx, &prio, sizeof(prio));
+}
+
+int lttng_add_prio_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+ int ret;
+
+ if (!wrapper_task_prio_sym) {
+ ret = wrapper_task_prio_init();
+ if (ret)
+ return ret;
+ }
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "prio")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "prio";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(int) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(int) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(int);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = prio_get_size;
+ field->record = prio_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_prio_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Priority Context");
diff --git a/drivers/staging/lttng/lttng-context-procname.c b/drivers/staging/lttng/lttng-context-procname.c
new file mode 100644
index 0000000..c6bc646
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-procname.c
@@ -0,0 +1,72 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng procname context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t procname_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += sizeof(current->comm);
+ return size;
+}
+
+/*
+ * Racy read of procname. We simply copy its whole array size.
+ * Races with /proc/<task>/procname write only.
+ * Otherwise having to take a mutex for each event is cumbersome and
+ * could lead to crash in IRQ context and deadlock of the lockdep tracer.
+ */
+static
+void procname_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ chan->ops->event_write(ctx, current->comm, sizeof(current->comm));
+}
+
+int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "procname")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "procname";
+ field->event_field.type.atype = atype_array;
+ field->event_field.type.u.array.elem_type.atype = atype_integer;
+ field->event_field.type.u.array.elem_type.u.basic.integer.size = sizeof(char) * CHAR_BIT;
+ field->event_field.type.u.array.elem_type.u.basic.integer.alignment = ltt_alignof(char) * CHAR_BIT;
+ field->event_field.type.u.array.elem_type.u.basic.integer.signedness = is_signed_type(char);
+ field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.array.elem_type.u.basic.integer.base = 10;
+ field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8;
+ field->event_field.type.u.array.length = sizeof(current->comm);
+
+ field->get_size = procname_get_size;
+ field->record = procname_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_procname_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
diff --git a/drivers/staging/lttng/lttng-context-tid.c b/drivers/staging/lttng/lttng-context-tid.c
new file mode 100644
index 0000000..d5ccdb6
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-tid.c
@@ -0,0 +1,68 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng TID context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t tid_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(pid_t));
+ size += sizeof(pid_t);
+ return size;
+}
+
+static
+void tid_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ pid_t tid;
+
+ tid = task_pid_nr(current);
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(tid));
+ chan->ops->event_write(ctx, &tid, sizeof(tid));
+}
+
+int lttng_add_tid_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "tid")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "tid";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = tid_get_size;
+ field->record = tid_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_tid_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit TID Context");
diff --git a/drivers/staging/lttng/lttng-context-vpid.c b/drivers/staging/lttng/lttng-context-vpid.c
new file mode 100644
index 0000000..3f16e03
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-vpid.c
@@ -0,0 +1,74 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng vPID context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t vpid_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(pid_t));
+ size += sizeof(pid_t);
+ return size;
+}
+
+static
+void vpid_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ pid_t vpid;
+
+ /*
+ * nsproxy can be NULL when scheduled out of exit.
+ */
+ if (!current->nsproxy)
+ vpid = 0;
+ else
+ vpid = task_tgid_vnr(current);
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(vpid));
+ chan->ops->event_write(ctx, &vpid, sizeof(vpid));
+}
+
+int lttng_add_vpid_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "vpid")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "vpid";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = vpid_get_size;
+ field->record = vpid_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vpid_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit vPID Context");
diff --git a/drivers/staging/lttng/lttng-context-vppid.c b/drivers/staging/lttng/lttng-context-vppid.c
new file mode 100644
index 0000000..f01b020
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-vppid.c
@@ -0,0 +1,79 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng vPPID context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include <linux/syscalls.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t vppid_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(pid_t));
+ size += sizeof(pid_t);
+ return size;
+}
+
+static
+void vppid_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ struct task_struct *parent;
+ pid_t vppid;
+
+ /*
+ * nsproxy can be NULL when scheduled out of exit.
+ */
+ rcu_read_lock();
+ parent = rcu_dereference(current->real_parent);
+ if (!parent->nsproxy)
+ vppid = 0;
+ else
+ vppid = task_tgid_vnr(parent);
+ rcu_read_unlock();
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(vppid));
+ chan->ops->event_write(ctx, &vppid, sizeof(vppid));
+}
+
+int lttng_add_vppid_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "vppid")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "vppid";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = vppid_get_size;
+ field->record = vppid_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vppid_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit vPPID Context");
diff --git a/drivers/staging/lttng/lttng-context-vtid.c b/drivers/staging/lttng/lttng-context-vtid.c
new file mode 100644
index 0000000..264bbb3
--- /dev/null
+++ b/drivers/staging/lttng/lttng-context-vtid.c
@@ -0,0 +1,74 @@
+/*
+ * (C) Copyright 2009-2011 -
+ * Mathieu Desnoyers <mathieu.desnoyers at efficios.com>
+ *
+ * LTTng vTID context.
+ *
+ * Dual LGPL v2.1/GPL v2 license.
+ */
+
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+#include "ltt-events.h"
+#include "wrapper/ringbuffer/frontend_types.h"
+#include "wrapper/vmalloc.h"
+#include "ltt-tracer.h"
+
+static
+size_t vtid_get_size(size_t offset)
+{
+ size_t size = 0;
+
+ size += lib_ring_buffer_align(offset, ltt_alignof(pid_t));
+ size += sizeof(pid_t);
+ return size;
+}
+
+static
+void vtid_record(struct lttng_ctx_field *field,
+ struct lib_ring_buffer_ctx *ctx,
+ struct ltt_channel *chan)
+{
+ pid_t vtid;
+
+ /*
+ * nsproxy can be NULL when scheduled out of exit.
+ */
+ if (!current->nsproxy)
+ vtid = 0;
+ else
+ vtid = task_pid_vnr(current);
+ lib_ring_buffer_align_ctx(ctx, ltt_alignof(vtid));
+ chan->ops->event_write(ctx, &vtid, sizeof(vtid));
+}
+
+int lttng_add_vtid_to_ctx(struct lttng_ctx **ctx)
+{
+ struct lttng_ctx_field *field;
+
+ field = lttng_append_context(ctx);
+ if (!field)
+ return -ENOMEM;
+ if (lttng_find_context(*ctx, "vtid")) {
+ lttng_remove_context_field(ctx, field);
+ return -EEXIST;
+ }
+ field->event_field.name = "vtid";
+ field->event_field.type.atype = atype_integer;
+ field->event_field.type.u.basic.integer.size = sizeof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.alignment = ltt_alignof(pid_t) * CHAR_BIT;
+ field->event_field.type.u.basic.integer.signedness = is_signed_type(pid_t);
+ field->event_field.type.u.basic.integer.reverse_byte_order = 0;
+ field->event_field.type.u.basic.integer.base = 10;
+ field->event_field.type.u.basic.integer.encoding = lttng_encode_none;
+ field->get_size = vtid_get_size;
+ field->record = vtid_record;
+ wrapper_vmalloc_sync_all();
+ return 0;
+}
+EXPORT_SYMBOL_GPL(lttng_add_vtid_to_ctx);
+
+MODULE_LICENSE("GPL and additional rights");
+MODULE_AUTHOR("Mathieu Desnoyers");
+MODULE_DESCRIPTION("Linux Trace Toolkit vTID Context");
--
1.7.2.5
More information about the lttng-dev
mailing list