From: Mathieu Desnoyers Date: Thu, 28 Jul 2011 16:40:20 +0000 (-0400) Subject: Perf counter support: check if busy X-Git-Tag: v2.0-pre3 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=7b745a9662e0552f2715391147bc994ad17ae29c;p=lttng-modules.git Perf counter support: check if busy Signed-off-by: Mathieu Desnoyers --- diff --git a/lttng-context-perf-counters.c b/lttng-context-perf-counters.c index 005c6510..2f131d61 100644 --- a/lttng-context-perf-counters.c +++ b/lttng-context-perf-counters.c @@ -37,8 +37,12 @@ void perf_counter_record(struct lttng_ctx_field *field, event = field->u.perf_counter->e[ctx->cpu]; if (likely(event)) { - event->pmu->read(event); - value = local64_read(&event->count); + 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 @@ -114,6 +118,10 @@ int __cpuinit lttng_perf_counter_cpu_hp_callback(struct notifier_block *nb, 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; @@ -200,6 +208,10 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, ret = -EINVAL; goto counter_error; } + if (events[cpu]->state == PERF_EVENT_STATE_ERROR) { + ret = -EBUSY; + goto counter_busy; + } } put_online_cpus(); @@ -221,6 +233,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, wrapper_vmalloc_sync_all(); return 0; +counter_busy: counter_error: for_each_online_cpu(cpu) { if (events[cpu] && !IS_ERR(events[cpu]))