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 <counter/counter.h>
14 #include <counter/counter-api.h>
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_64_BIT
,
23 static struct lib_counter
*counter_create(size_t nr_dimensions
,
24 const size_t *max_nr_elem
,
25 int64_t global_sum_step
)
27 return lttng_counter_create(&client_config
, nr_dimensions
, max_nr_elem
,
31 static void counter_destroy(struct lib_counter
*counter
)
33 return lttng_counter_destroy(counter
);
36 static int counter_add(struct lib_counter
*counter
, const size_t *dimension_indexes
, int64_t v
)
38 return lttng_counter_add(&client_config
, counter
, dimension_indexes
, v
);
41 static int counter_read(struct lib_counter
*counter
, const size_t *dimension_indexes
, int cpu
,
42 int64_t *value
, bool *overflow
, bool *underflow
)
44 return lttng_counter_read(&client_config
, counter
, dimension_indexes
, cpu
, value
,
48 static int counter_aggregate(struct lib_counter
*counter
, const size_t *dimension_indexes
,
49 int64_t *value
, bool *overflow
, bool *underflow
)
51 return lttng_counter_aggregate(&client_config
, counter
, dimension_indexes
, value
,
55 static int counter_clear(struct lib_counter
*counter
, const size_t *dimension_indexes
)
57 return lttng_counter_clear(&client_config
, counter
, dimension_indexes
);
60 static struct lttng_counter_transport lttng_counter_transport
= {
61 .name
= "counter-per-cpu-64-modular",
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
,
73 static int __init
lttng_counter_client_init(void)
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.
79 wrapper_vmalloc_sync_mappings();
80 lttng_counter_transport_register(<tng_counter_transport
);
84 module_init(lttng_counter_client_init
);
86 static void __exit
lttng_counter_client_exit(void)
88 lttng_counter_transport_unregister(<tng_counter_transport
);
91 module_exit(lttng_counter_client_exit
);
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
);