Move the ringbuffer and counter clients to 'src/common/'
[lttng-ust.git] / src / common / counter / counter-internal.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 *
6 * LTTng Counters Internal Header
7 */
8
9 #ifndef _LTTNG_COUNTER_INTERNAL_H
10 #define _LTTNG_COUNTER_INTERNAL_H
11
12 #include <stdint.h>
13 #include <errno.h>
14
15 #include <lttng/ust-config.h>
16 #include <urcu/compiler.h>
17 #include "counter-types.h"
18
19 static inline int lttng_counter_validate_indexes(
20 const struct lib_counter_config *config __attribute__((unused)),
21 struct lib_counter *counter,
22 const size_t *dimension_indexes)
23 {
24 size_t nr_dimensions = counter->nr_dimensions, i;
25
26 for (i = 0; i < nr_dimensions; i++) {
27 if (caa_unlikely(dimension_indexes[i] >= counter->dimensions[i].max_nr_elem))
28 return -EOVERFLOW;
29 }
30 return 0;
31 }
32
33
34 static inline size_t lttng_counter_get_index(
35 const struct lib_counter_config *config __attribute__((unused)),
36 struct lib_counter *counter,
37 const size_t *dimension_indexes)
38 {
39 size_t nr_dimensions = counter->nr_dimensions, i;
40 size_t index = 0;
41
42 for (i = 0; i < nr_dimensions; i++) {
43 struct lib_counter_dimension *dimension = &counter->dimensions[i];
44 const size_t *dimension_index = &dimension_indexes[i];
45
46 index += *dimension_index * dimension->stride;
47 }
48 return index;
49 }
50
51 #endif /* _LTTNG_COUNTER_INTERNAL_H */
This page took 0.034386 seconds and 4 git commands to generate.