From c24a0d710f6aac1484bd02bb6375e8de7429edd0 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Fri, 3 Jun 2011 15:59:12 -0400 Subject: [PATCH] Update perf counter ABI Signed-off-by: Mathieu Desnoyers --- Makefile | 4 ++++ ltt-debugfs-abi.c | 6 +++++- ltt-debugfs-abi.h | 1 + ltt-events.h | 4 ++++ ...ounters.c => lttng-context-perf-counters.c | 20 ++++++++++++++----- probes/Makefile | 4 ---- 6 files changed, 29 insertions(+), 10 deletions(-) rename probes/lttng-perf-counters.c => lttng-context-perf-counters.c (89%) diff --git a/Makefile b/Makefile index fa337a0f..dc44fd40 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,10 @@ ltt-relay-objs := ltt-events.o ltt-debugfs-abi.o \ lttng-context-pid.o lttng-context-comm.o \ lttng-context-prio.o lttng-context-nice.o +ifneq ($(CONFIG_PERF_EVENTS),) +ltt-relay-objs += lttng-context-perf-counters.o +endif + obj-m += probes/ obj-m += lib/ diff --git a/ltt-debugfs-abi.c b/ltt-debugfs-abi.c index e192474d..1314c663 100644 --- a/ltt-debugfs-abi.c +++ b/ltt-debugfs-abi.c @@ -159,7 +159,11 @@ long lttng_abi_add_context(struct file *file, case LTTNG_KERNEL_CONTEXT_NICE: return lttng_add_nice_to_ctx(ctx); case LTTNG_KERNEL_CONTEXT_PERF_COUNTER: - return -ENOSYS; + context_param.u.perf_counter.name[LTTNG_SYM_NAME_LEN - 1] = '\0'; + return lttng_add_perf_counter_to_ctx(context_param.u.perf_counter.type, + context_param.u.perf_counter.config, + context_param.u.perf_counter.name, + ctx); case LTTNG_KERNEL_CONTEXT_COMM: return lttng_add_comm_to_ctx(ctx); default: diff --git a/ltt-debugfs-abi.h b/ltt-debugfs-abi.h index d91c52d5..87be71bd 100644 --- a/ltt-debugfs-abi.h +++ b/ltt-debugfs-abi.h @@ -74,6 +74,7 @@ enum lttng_kernel_context_type { struct lttng_kernel_perf_counter_ctx { uint32_t type; uint64_t config; + char name[LTTNG_SYM_NAME_LEN]; }; struct lttng_kernel_context { diff --git a/ltt-events.h b/ltt-events.h index de6ae0e7..6244e8c5 100644 --- a/ltt-events.h +++ b/ltt-events.h @@ -278,6 +278,10 @@ int lttng_add_pid_to_ctx(struct lttng_ctx **ctx); int lttng_add_comm_to_ctx(struct lttng_ctx **ctx); int lttng_add_prio_to_ctx(struct lttng_ctx **ctx); int lttng_add_nice_to_ctx(struct lttng_ctx **ctx); +int lttng_add_perf_counter_to_ctx(uint32_t type, + uint64_t config, + const char *name, + struct lttng_ctx **ctx); #ifdef CONFIG_KPROBES int lttng_kprobes_register(const char *name, diff --git a/probes/lttng-perf-counters.c b/lttng-context-perf-counters.c similarity index 89% rename from probes/lttng-perf-counters.c rename to lttng-context-perf-counters.c index cb0bdfc6..e9a57888 100644 --- a/probes/lttng-perf-counters.c +++ b/lttng-context-perf-counters.c @@ -11,10 +11,11 @@ #include #include #include -#include "../ltt-events.h" -#include "../wrapper/ringbuffer/frontend_types.h" -#include "../wrapper/vmalloc.h" -#include "../ltt-tracer.h" +#include +#include "ltt-events.h" +#include "wrapper/ringbuffer/frontend_types.h" +#include "wrapper/vmalloc.h" +#include "ltt-tracer.h" /* * TODO: Add CPU hotplug support. @@ -66,12 +67,14 @@ void lttng_destroy_perf_counter_field(struct lttng_ctx_field *field) for_each_online_cpu(cpu) perf_event_release_kernel(events[cpu]); mutex_unlock(&perf_counter_mutex); + kfree(field->event_field.name); kfree(field->u.perf_counter.attr); kfree(events); } 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; @@ -79,6 +82,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, struct perf_event_attr *attr; int ret; int cpu; + char *name_alloc; events = kzalloc(num_possible_cpus() * sizeof(*events), GFP_KERNEL); if (!events) @@ -107,6 +111,10 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, } } + name_alloc = kstrdup(name, GFP_KERNEL); + if (!field->event_field.name) + goto name_alloc_error; + field = lttng_append_context(ctx); if (!field) { ret = -ENOMEM; @@ -114,7 +122,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, } field->destroy = lttng_destroy_perf_counter_field; - field->event_field.name = "dummyname";//TODO: lookup_counter_name(type, config); + field->event_field.name = name_alloc; field->event_field.type.atype = atype_integer; field->event_field.type.u.basic.integer.size = sizeof(unsigned long) * CHAR_BIT; field->event_field.type.u.basic.integer.alignment = ltt_alignof(unsigned long) * CHAR_BIT; @@ -134,6 +142,8 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, return 0; error: + kfree(name_alloc); +name_alloc_error: for_each_online_cpu(cpu) { if (events[cpu]) perf_event_release_kernel(events[cpu]); diff --git a/probes/Makefile b/probes/Makefile index 554e6ffa..7129e979 100644 --- a/probes/Makefile +++ b/probes/Makefile @@ -24,10 +24,6 @@ ifneq ($(CONFIG_DYNAMIC_FTRACE),) obj-m += lttng-ftrace.o endif -ifneq ($(CONFIG_PERF_EVENTS),) -obj-m += lttng-perf-counters.o -endif - endif else -- 2.34.1