X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=lttng-context-perf-counters.c;h=58fbbe6159a7e77be2d45d9ba8ed4173c2ff8543;hb=refs%2Fheads%2Fstable-2.12;hp=843cda6ef907d6e266dd7f4f047cdbd3fdd9125b;hpb=1e36732678d7cc650940b4508031acf2f6ffcd1b;p=lttng-modules.git diff --git a/lttng-context-perf-counters.c b/lttng-context-perf-counters.c index 843cda6e..58fbbe61 100644 --- a/lttng-context-perf-counters.c +++ b/lttng-context-perf-counters.c @@ -1,23 +1,10 @@ -/* +/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1) + * * lttng-context-perf-counters.c * * LTTng performance monitoring counters (perf-counters) integration module. * * Copyright (C) 2009-2012 Mathieu Desnoyers - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; only - * version 2.1 of the License. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -28,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -72,7 +60,7 @@ void perf_counter_record(struct lttng_ctx_field *field, chan->ops->event_write(ctx, &value, sizeof(value)); } -#if defined(CONFIG_PERF_EVENTS) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,99)) +#if defined(CONFIG_PERF_EVENTS) && (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(3,1,0)) static void overflow_callback(struct perf_event *event, struct perf_sample_data *data, @@ -93,7 +81,7 @@ void lttng_destroy_perf_counter_field(struct lttng_ctx_field *field) { struct perf_event **events = field->u.perf_counter->e; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) { int ret; @@ -104,26 +92,26 @@ void lttng_destroy_perf_counter_field(struct lttng_ctx_field *field) &field->u.perf_counter->cpuhp_prepare.node); WARN_ON(ret); } -#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ +#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */ { int cpu; - get_online_cpus(); + lttng_cpus_read_lock(); for_each_online_cpu(cpu) perf_event_release_kernel(events[cpu]); - put_online_cpus(); + lttng_cpus_read_unlock(); #ifdef CONFIG_HOTPLUG_CPU unregister_cpu_notifier(&field->u.perf_counter->nb); #endif } -#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ +#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */ kfree(field->event_field.name); kfree(field->u.perf_counter->attr); - kfree(events); + lttng_kvfree(events); kfree(field->u.perf_counter); } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) int lttng_cpuhp_perf_counter_online(unsigned int cpu, struct lttng_cpuhp_node *node) @@ -164,7 +152,7 @@ int lttng_cpuhp_perf_counter_dead(unsigned int cpu, return 0; } -#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ +#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */ #ifdef CONFIG_HOTPLUG_CPU @@ -223,7 +211,7 @@ int lttng_perf_counter_cpu_hp_callback(struct notifier_block *nb, #endif -#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ +#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */ int lttng_add_perf_counter_to_ctx(uint32_t type, uint64_t config, @@ -237,7 +225,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, int ret; char *name_alloc; - events = kzalloc(num_possible_cpus() * sizeof(*events), GFP_KERNEL); + events = lttng_kvzalloc(num_possible_cpus() * sizeof(*events), GFP_KERNEL); if (!events) return -ENOMEM; @@ -277,7 +265,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, goto find_error; } -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) perf_field->cpuhp_prepare.component = LTTNG_CONTEXT_PERF_COUNTERS; ret = cpuhp_state_add_instance(lttng_hp_prepare, @@ -291,7 +279,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, if (ret) goto cpuhp_online_error; -#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ +#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */ { int cpu; @@ -301,7 +289,7 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, perf_field->nb.priority = 0; register_cpu_notifier(&perf_field->nb); #endif - get_online_cpus(); + lttng_cpus_read_lock(); for_each_online_cpu(cpu) { events[cpu] = wrapper_perf_event_create_kernel_counter(attr, cpu, NULL, overflow_callback); @@ -314,10 +302,10 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, goto counter_busy; } } - put_online_cpus(); + lttng_cpus_read_unlock(); perf_field->hp_enable = 1; } -#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ +#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */ field->destroy = lttng_destroy_perf_counter_field; @@ -334,10 +322,10 @@ int lttng_add_perf_counter_to_ctx(uint32_t type, field->u.perf_counter = perf_field; lttng_context_update(*ctx); - wrapper_vmalloc_sync_all(); + wrapper_vmalloc_sync_mappings(); return 0; -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) cpuhp_online_error: { int remove_ret; @@ -347,18 +335,22 @@ cpuhp_online_error: WARN_ON(remove_ret); } cpuhp_prepare_error: -#else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ +#else /* #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,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(); + { + int cpu; + + for_each_online_cpu(cpu) { + if (events[cpu] && !IS_ERR(events[cpu])) + perf_event_release_kernel(events[cpu]); + } + lttng_cpus_read_unlock(); #ifdef CONFIG_HOTPLUG_CPU - unregister_cpu_notifier(&perf_field->nb); + unregister_cpu_notifier(&perf_field->nb); #endif -#endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */ + } +#endif /* #else #if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(4,10,0)) */ find_error: lttng_remove_context_field(ctx, field); append_context_error: @@ -368,6 +360,6 @@ name_alloc_error: error_alloc_perf_field: kfree(attr); error_attr: - kfree(events); + lttng_kvfree(events); return ret; }