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> | |
13 | #include <lttng/ust-config.h> | |
14 | #include <urcu/compiler.h> | |
15 | #include "counter-types.h" | |
16 | ||
2208d8b5 MJ |
17 | static inline int lttng_counter_validate_indexes( |
18 | const struct lib_counter_config *config __attribute__((unused)), | |
19 | struct lib_counter *counter, | |
20 | const size_t *dimension_indexes) | |
ebabbf58 MD |
21 | { |
22 | size_t nr_dimensions = counter->nr_dimensions, i; | |
23 | ||
24 | for (i = 0; i < nr_dimensions; i++) { | |
25 | if (caa_unlikely(dimension_indexes[i] >= counter->dimensions[i].max_nr_elem)) | |
26 | return -EOVERFLOW; | |
27 | } | |
28 | return 0; | |
29 | } | |
30 | ||
31 | ||
2208d8b5 MJ |
32 | static inline size_t lttng_counter_get_index( |
33 | const struct lib_counter_config *config __attribute__((unused)), | |
34 | struct lib_counter *counter, | |
35 | const size_t *dimension_indexes) | |
ebabbf58 MD |
36 | { |
37 | size_t nr_dimensions = counter->nr_dimensions, i; | |
38 | size_t index = 0; | |
39 | ||
40 | for (i = 0; i < nr_dimensions; i++) { | |
41 | struct lib_counter_dimension *dimension = &counter->dimensions[i]; | |
42 | const size_t *dimension_index = &dimension_indexes[i]; | |
43 | ||
44 | index += *dimension_index * dimension->stride; | |
45 | } | |
46 | return index; | |
47 | } | |
48 | ||
49 | #endif /* _LTTNG_COUNTER_INTERNAL_H */ |