Move the getcpu plugin implementation to liblttn-ust-common
[lttng-ust.git] / src / lib / lttng-ust / lttng-counter-client-percpu-64-modular.c
CommitLineData
ebabbf58
MD
1/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
2 *
3 * lttng-counter-client-percpu-64-modular.c
4 *
5 * LTTng lib counter client. Per-cpu 64-bit counters in modular
6 * arithmetic.
7 *
8 * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 */
10
36c52fff 11#include "lib/lttng-ust/events.h"
cdff92e0
MJ
12#include "common/counter/counter.h"
13#include "common/counter/counter-api.h"
23d128de 14#include "lttng-tracer-core.h"
b62f8205 15#include "lttng-counter-client.h"
ebabbf58
MD
16
17static const struct lib_counter_config client_config = {
18 .alloc = COUNTER_ALLOC_PER_CPU,
19 .sync = COUNTER_SYNC_PER_CPU,
20 .arithmetic = COUNTER_ARITHMETIC_MODULAR,
21 .counter_size = COUNTER_SIZE_64_BIT,
22};
23
24static struct lib_counter *counter_create(size_t nr_dimensions,
25 const struct lttng_counter_dimension *dimensions,
26 int64_t global_sum_step,
27 int global_counter_fd,
28 int nr_counter_cpu_fds,
29 const int *counter_cpu_fds,
30 bool is_daemon)
31{
32 size_t max_nr_elem[LTTNG_COUNTER_DIMENSION_MAX], i;
33
34 if (nr_dimensions > LTTNG_COUNTER_DIMENSION_MAX)
35 return NULL;
36 for (i = 0; i < nr_dimensions; i++) {
37 if (dimensions[i].has_underflow || dimensions[i].has_overflow)
38 return NULL;
39 max_nr_elem[i] = dimensions[i].size;
40 }
41 return lttng_counter_create(&client_config, nr_dimensions, max_nr_elem,
42 global_sum_step, global_counter_fd, nr_counter_cpu_fds,
43 counter_cpu_fds, is_daemon);
44}
45
46static void counter_destroy(struct lib_counter *counter)
47{
48 lttng_counter_destroy(counter);
49}
50
51static int counter_add(struct lib_counter *counter, const size_t *dimension_indexes, int64_t v)
52{
53 return lttng_counter_add(&client_config, counter, dimension_indexes, v);
54}
55
56static int counter_read(struct lib_counter *counter, const size_t *dimension_indexes, int cpu,
57 int64_t *value, bool *overflow, bool *underflow)
58{
59 return lttng_counter_read(&client_config, counter, dimension_indexes, cpu, value,
60 overflow, underflow);
61}
62
63static int counter_aggregate(struct lib_counter *counter, const size_t *dimension_indexes,
64 int64_t *value, bool *overflow, bool *underflow)
65{
66 return lttng_counter_aggregate(&client_config, counter, dimension_indexes, value,
67 overflow, underflow);
68}
69
70static int counter_clear(struct lib_counter *counter, const size_t *dimension_indexes)
71{
72 return lttng_counter_clear(&client_config, counter, dimension_indexes);
73}
74
75static struct lttng_counter_transport lttng_counter_transport = {
76 .name = "counter-per-cpu-64-modular",
77 .ops = {
78 .counter_create = counter_create,
79 .counter_destroy = counter_destroy,
80 .counter_add = counter_add,
81 .counter_read = counter_read,
82 .counter_aggregate = counter_aggregate,
83 .counter_clear = counter_clear,
84 },
85 .client_config = &client_config,
86};
87
88void lttng_counter_client_percpu_64_modular_init(void)
89{
90 lttng_counter_transport_register(&lttng_counter_transport);
91}
92
93void lttng_counter_client_percpu_64_modular_exit(void)
94{
95 lttng_counter_transport_unregister(&lttng_counter_transport);
96}
This page took 0.028882 seconds and 4 git commands to generate.