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