| 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 | |
| 11 | #include <lttng/ust-events.h> |
| 12 | #include "../libcounter/counter.h" |
| 13 | #include "../libcounter/counter-api.h" |
| 14 | #include "lttng-tracer-core.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_64_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 | int global_counter_fd, |
| 27 | int nr_counter_cpu_fds, |
| 28 | const int *counter_cpu_fds, |
| 29 | bool is_daemon) |
| 30 | { |
| 31 | if (nr_dimensions > LTTNG_COUNTER_DIMENSION_MAX) |
| 32 | return NULL; |
| 33 | return lttng_counter_create(&client_config, nr_dimensions, max_nr_elem, |
| 34 | global_sum_step, global_counter_fd, nr_counter_cpu_fds, |
| 35 | counter_cpu_fds, is_daemon); |
| 36 | } |
| 37 | |
| 38 | static void counter_destroy(struct lib_counter *counter) |
| 39 | { |
| 40 | lttng_counter_destroy(counter); |
| 41 | } |
| 42 | |
| 43 | static int counter_add(struct lib_counter *counter, const size_t *dimension_indexes, int64_t v) |
| 44 | { |
| 45 | return lttng_counter_add(&client_config, counter, dimension_indexes, v); |
| 46 | } |
| 47 | |
| 48 | static int counter_read(struct lib_counter *counter, const size_t *dimension_indexes, int cpu, |
| 49 | int64_t *value, bool *overflow, bool *underflow) |
| 50 | { |
| 51 | return lttng_counter_read(&client_config, counter, dimension_indexes, cpu, value, |
| 52 | overflow, underflow); |
| 53 | } |
| 54 | |
| 55 | static int counter_aggregate(struct lib_counter *counter, const size_t *dimension_indexes, |
| 56 | int64_t *value, bool *overflow, bool *underflow) |
| 57 | { |
| 58 | return lttng_counter_aggregate(&client_config, counter, dimension_indexes, value, |
| 59 | overflow, underflow); |
| 60 | } |
| 61 | |
| 62 | static int counter_clear(struct lib_counter *counter, const size_t *dimension_indexes) |
| 63 | { |
| 64 | return lttng_counter_clear(&client_config, counter, dimension_indexes); |
| 65 | } |
| 66 | |
| 67 | static struct lttng_counter_transport lttng_counter_transport = { |
| 68 | .name = "counter-per-cpu-64-modular", |
| 69 | .ops = { |
| 70 | .counter_create = counter_create, |
| 71 | .counter_destroy = counter_destroy, |
| 72 | .counter_add = counter_add, |
| 73 | .counter_read = counter_read, |
| 74 | .counter_aggregate = counter_aggregate, |
| 75 | .counter_clear = counter_clear, |
| 76 | }, |
| 77 | .client_config = &client_config, |
| 78 | }; |
| 79 | |
| 80 | void lttng_counter_client_percpu_64_modular_init(void) |
| 81 | { |
| 82 | lttng_counter_transport_register(<tng_counter_transport); |
| 83 | } |
| 84 | |
| 85 | void lttng_counter_client_percpu_64_modular_exit(void) |
| 86 | { |
| 87 | lttng_counter_transport_unregister(<tng_counter_transport); |
| 88 | } |