Add context management infrastructure
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 May 2011 21:20:30 +0000 (17:20 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 May 2011 21:20:30 +0000 (17:20 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Makefile
ltt-context.c [new file with mode: 0644]
ltt-events.h
probes/lttng-perf-counters.c

index d2d6cbabe15cd6adc5a38f4b3a496a15f39e3e06..169b7cdd89eb2132353827d917607a8415b32f0d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ obj-m += ltt-ring-buffer-metadata-client.o
 
 obj-m += ltt-relay.o
 ltt-relay-objs :=  ltt-events.o ltt-debugfs-abi.o \
-                       ltt-probes.o ltt-core.o
+                       ltt-probes.o ltt-core.o ltt-context.o
 
 obj-m += probes/
 obj-m += lib/
diff --git a/ltt-context.c b/ltt-context.c
new file mode 100644 (file)
index 0000000..cc9633a
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * ltt-context.c
+ *
+ * Copyright 2011 (c) - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * LTTng trace/channel/event context management.
+ */
+
+#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"
+
+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 = min_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, 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);
+
+void lttng_destroy_context(struct lttng_ctx *ctx)
+{
+       int i;
+
+       for (i = 0; i < ctx->nr_fields; i++)
+               ctx->fields[i].destroy(&ctx->fields[i]);
+       kfree(ctx->fields);
+       kfree(ctx);
+}
index ce030ae3173c58127505d828b44f4792fdbf74e4..bacef0a82e69c92f4dca34291a70db7426ccb86b 100644 (file)
@@ -125,6 +125,7 @@ struct lttng_ctx_field {
                        struct perf_event_attr *attr;
                } perf_counter;
        } u;
+       void (*destroy)(struct lttng_ctx_field *field);
 };
 
 struct lttng_ctx {
@@ -261,6 +262,8 @@ const struct lttng_event_desc *ltt_event_get(const char *name);
 void ltt_event_put(const struct lttng_event_desc *desc);
 int ltt_probes_init(void);
 void ltt_probes_exit(void);
+struct lttng_ctx_field *lttng_append_context(struct lttng_ctx **ctx);
+void lttng_destroy_context(struct lttng_ctx *ctx);
 
 #ifdef CONFIG_KPROBES
 int lttng_kprobes_register(const char *name,
index cdda48337cb68c6789e3b6a9d096de140861f104..c6620713c44d72f8f3ed8d082cb1e8ee65062ae3 100644 (file)
@@ -46,9 +46,24 @@ void overflow_callback(struct perf_event *event, int nmi,
 {
 }
 
+static
+void lttng_destroy_perf_counter_field(struct lttng_ctx_field *field)
+{
+       struct perf_event **events = field->u.perf_counter.e;
+       int cpu;
+
+       mutex_lock(&perf_counter_mutex);
+       list_del(&field->u.perf_counter.head);
+       for_each_online_cpu(cpu)
+               perf_event_release_kernel(events[cpu]);
+       mutex_unlock(&perf_counter_mutex);
+       kfree(field->u.perf_counter.attr);
+       kfree(events);
+}
+
 int lttng_add_perf_counter_to_ctx(uint32_t type,
                                  uint64_t config,
-                                 struct lttng_ctx *ctx)
+                                 struct lttng_ctx **ctx)
 {
        struct lttng_ctx_field *field;
        struct perf_event **events;
@@ -83,22 +98,12 @@ int lttng_add_perf_counter_to_ctx(uint32_t type,
                }
        }
 
-       ctx->nr_fields++;
-       if (ctx->nr_fields > ctx->allocated_fields) {
-               struct lttng_ctx_field *new_fields;
-
-               ctx->allocated_fields = min_t(size_t, 1, 2 * ctx->allocated_fields);
-               new_fields = kzalloc(ctx->allocated_fields * sizeof(struct lttng_ctx_field), GFP_KERNEL);
-               if (!new_fields) {
-                       ret = -ENOMEM;
-                       goto error;
-               }
-               if (ctx->fields)
-                       memcpy(new_fields, ctx->fields, ctx->nr_fields - 1);
-               kfree(ctx->fields);
-               ctx->fields = new_fields;
+       field = lttng_append_context(ctx);
+       if (!field) {
+               ret = -ENOMEM;
+               goto error;
        }
-       field = &ctx->fields[ctx->nr_fields - 1];
+       field->destroy = lttng_destroy_perf_counter_field;
 
        field->name = "dummyname";//TODO: lookup_counter_name(type, config);
        field->type.atype = atype_integer;
@@ -130,31 +135,6 @@ error_attr:
        return ret;
 }
 
-struct lttng_ctx *lttng_create_perf_counter_ctx(void)
-{
-       return kzalloc(sizeof(struct lttng_ctx), GFP_KERNEL);
-}
-
-void lttng_destroy_perf_counter_ctx(struct lttng_ctx *ctx)
-{
-       int i;
-
-       for (i = 0; i < ctx->nr_fields; i++) {
-               struct perf_event **events = ctx->fields[i].u.perf_counter.e;
-               int cpu;
-
-               mutex_lock(&perf_counter_mutex);
-               list_del(&ctx->fields[i].u.perf_counter.head);
-               for_each_online_cpu(cpu)
-                       perf_event_release_kernel(events[cpu]);
-               mutex_unlock(&perf_counter_mutex);
-               kfree(ctx->fields[i].u.perf_counter.attr);
-               kfree(events);
-       }
-       kfree(ctx->fields);
-       kfree(ctx);
-}
-
 MODULE_LICENSE("GPL and additional rights");
 MODULE_AUTHOR("Mathieu Desnoyers");
 MODULE_DESCRIPTION("Linux Trace Toolkit Perf Support");
This page took 0.03662 seconds and 4 git commands to generate.