| 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
| 2 | * |
| 3 | * lttng-counter-client-percpu-32-modular.c |
| 4 | * |
| 5 | * LTTng lib counter client. Per-cpu 32-bit counters in overflow |
| 6 | * arithmetic. |
| 7 | * |
| 8 | * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <lttng/tracer.h> |
| 13 | #include <lttng/events.h> |
| 14 | #include <lttng/events-internal.h> |
| 15 | #include <counter/counter.h> |
| 16 | #include <counter/counter-api.h> |
| 17 | |
| 18 | static const struct lib_counter_config client_config = { |
| 19 | .alloc = COUNTER_ALLOC_PER_CPU, |
| 20 | .sync = COUNTER_SYNC_PER_CPU, |
| 21 | .arithmetic = COUNTER_ARITHMETIC_MODULAR, |
| 22 | .counter_size = COUNTER_SIZE_32_BIT, |
| 23 | }; |
| 24 | |
| 25 | static struct lib_counter *counter_create(size_t nr_dimensions, |
| 26 | const size_t *max_nr_elem, |
| 27 | int64_t global_sum_step) |
| 28 | { |
| 29 | return lttng_counter_create(&client_config, nr_dimensions, max_nr_elem, |
| 30 | global_sum_step); |
| 31 | } |
| 32 | |
| 33 | static void counter_destroy(struct lib_counter *counter) |
| 34 | { |
| 35 | return lttng_counter_destroy(counter); |
| 36 | } |
| 37 | |
| 38 | static int counter_add(struct lib_counter *counter, const size_t *dimension_indexes, int64_t v) |
| 39 | { |
| 40 | return lttng_counter_add(&client_config, counter, dimension_indexes, v); |
| 41 | } |
| 42 | |
| 43 | static int counter_read(struct lib_counter *counter, const size_t *dimension_indexes, int cpu, |
| 44 | int64_t *value, bool *overflow, bool *underflow) |
| 45 | { |
| 46 | return lttng_counter_read(&client_config, counter, dimension_indexes, cpu, value, |
| 47 | overflow, underflow); |
| 48 | } |
| 49 | |
| 50 | static int counter_aggregate(struct lib_counter *counter, const size_t *dimension_indexes, |
| 51 | int64_t *value, bool *overflow, bool *underflow) |
| 52 | { |
| 53 | return lttng_counter_aggregate(&client_config, counter, dimension_indexes, value, |
| 54 | overflow, underflow); |
| 55 | } |
| 56 | |
| 57 | static int counter_clear(struct lib_counter *counter, const size_t *dimension_indexes) |
| 58 | { |
| 59 | return lttng_counter_clear(&client_config, counter, dimension_indexes); |
| 60 | } |
| 61 | |
| 62 | static struct lttng_counter_transport lttng_counter_transport = { |
| 63 | .name = "counter-per-cpu-32-modular", |
| 64 | .owner = THIS_MODULE, |
| 65 | .ops = { |
| 66 | .counter_create = counter_create, |
| 67 | .counter_destroy = counter_destroy, |
| 68 | .counter_add = counter_add, |
| 69 | .counter_read = counter_read, |
| 70 | .counter_aggregate = counter_aggregate, |
| 71 | .counter_clear = counter_clear, |
| 72 | }, |
| 73 | }; |
| 74 | |
| 75 | static int __init lttng_counter_client_init(void) |
| 76 | { |
| 77 | /* |
| 78 | * This vmalloc sync all also takes care of the lib counter |
| 79 | * vmalloc'd module pages when it is built as a module into LTTng. |
| 80 | */ |
| 81 | wrapper_vmalloc_sync_mappings(); |
| 82 | lttng_counter_transport_register(<tng_counter_transport); |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | module_init(lttng_counter_client_init); |
| 87 | |
| 88 | static void __exit lttng_counter_client_exit(void) |
| 89 | { |
| 90 | lttng_counter_transport_unregister(<tng_counter_transport); |
| 91 | } |
| 92 | |
| 93 | module_exit(lttng_counter_client_exit); |
| 94 | |
| 95 | MODULE_LICENSE("GPL and additional rights"); |
| 96 | MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>"); |
| 97 | MODULE_DESCRIPTION("LTTng counter per-cpu 32-bit overflow client"); |
| 98 | MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "." |
| 99 | __stringify(LTTNG_MODULES_MINOR_VERSION) "." |
| 100 | __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION) |
| 101 | LTTNG_MODULES_EXTRAVERSION); |