Commit | Line | Data |
---|---|---|
ebabbf58 | 1 | /* |
c0c0989a | 2 | * SPDX-License-Identifier: MIT |
ebabbf58 MD |
3 | * |
4 | * Copyright (C) 2020 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | * | |
c0c0989a | 6 | * LTTng Counters Internal Header |
ebabbf58 MD |
7 | */ |
8 | ||
9 | #ifndef _LTTNG_COUNTER_INTERNAL_H | |
10 | #define _LTTNG_COUNTER_INTERNAL_H | |
11 | ||
12 | #include <stdint.h> | |
8cd08025 MJ |
13 | #include <errno.h> |
14 | ||
ebabbf58 MD |
15 | #include <lttng/ust-config.h> |
16 | #include <urcu/compiler.h> | |
17 | #include "counter-types.h" | |
18 | ||
2208d8b5 MJ |
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) | |
ebabbf58 MD |
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 | ||
2208d8b5 MJ |
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) | |
ebabbf58 MD |
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 */ |