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