1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
3 * lttng-counter-client-percpu-64-modular.c
5 * LTTng lib counter client. Per-cpu 64-bit counters in overflow
8 * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
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>
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_64_BIT
,
25 static struct lib_counter
*counter_create(size_t nr_dimensions
,
26 const size_t *max_nr_elem
,
27 int64_t global_sum_step
)
29 return lttng_counter_create(&client_config
, nr_dimensions
, max_nr_elem
,
33 static void counter_destroy(struct lib_counter
*counter
)
35 return lttng_counter_destroy(counter
);
38 static int counter_add(struct lib_counter
*counter
, const size_t *dimension_indexes
, int64_t v
)
40 return lttng_counter_add(&client_config
, counter
, dimension_indexes
, v
);
43 static int counter_read(struct lib_counter
*counter
, const size_t *dimension_indexes
, int cpu
,
44 int64_t *value
, bool *overflow
, bool *underflow
)
46 return lttng_counter_read(&client_config
, counter
, dimension_indexes
, cpu
, value
,
50 static int counter_aggregate(struct lib_counter
*counter
, const size_t *dimension_indexes
,
51 int64_t *value
, bool *overflow
, bool *underflow
)
53 return lttng_counter_aggregate(&client_config
, counter
, dimension_indexes
, value
,
57 static int counter_clear(struct lib_counter
*counter
, const size_t *dimension_indexes
)
59 return lttng_counter_clear(&client_config
, counter
, dimension_indexes
);
62 static struct lttng_counter_transport lttng_counter_transport
= {
63 .name
= "counter-per-cpu-64-modular",
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
,
75 static int __init
lttng_counter_client_init(void)
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.
81 wrapper_vmalloc_sync_mappings();
82 lttng_counter_transport_register(<tng_counter_transport
);
86 module_init(lttng_counter_client_init
);
88 static void __exit
lttng_counter_client_exit(void)
90 lttng_counter_transport_unregister(<tng_counter_transport
);
93 module_exit(lttng_counter_client_exit
);
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
);