Commit | Line | Data |
---|---|---|
ebdb334b JR |
1 | /* |
2 | * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com> | |
3 | * | |
4 | * SPDX-License-Identifier: LGPL-2.1-only | |
5 | * | |
6 | */ | |
7 | ||
8 | #ifndef LTTNG_MAP_INTERNAL_H | |
9 | #define LTTNG_MAP_INTERNAL_H | |
10 | ||
11 | #include <common/macros.h> | |
12 | #include <common/optional.h> | |
13 | #include <common/payload.h> | |
14 | #include <common/payload-view.h> | |
15 | #include <urcu/ref.h> | |
16 | ||
17 | #include "map.h" | |
18 | ||
19 | struct lttng_payload; | |
20 | struct lttng_payload_view; | |
21 | ||
22 | struct lttng_map { | |
23 | /* Reference counting is only exposed to internal users. */ | |
24 | struct urcu_ref ref; | |
25 | ||
26 | char *name; | |
27 | LTTNG_OPTIONAL(bool) is_enabled; | |
28 | enum lttng_map_bitness bitness; | |
29 | enum lttng_map_boundary_policy boundary_policy; | |
30 | enum lttng_domain_type domain; | |
31 | enum lttng_buffer_type buffer_type; | |
32 | bool coalesce_hits; | |
33 | unsigned int dimension_count; | |
34 | uint64_t *dimension_sizes; | |
35 | }; | |
36 | ||
37 | struct lttng_map_list { | |
38 | struct lttng_dynamic_pointer_array array; | |
39 | }; | |
40 | ||
41 | struct lttng_map_key_value_pair { | |
42 | char *key; | |
43 | int64_t value; | |
44 | bool has_overflowed; | |
45 | bool has_underflowed; | |
46 | }; | |
47 | ||
48 | struct lttng_map_key_value_pair_list { | |
49 | enum lttng_map_key_value_pair_list_type type; | |
50 | uint64_t id; /* pid_t or uid_t */ | |
51 | uint64_t cpu; | |
52 | bool summed_all_cpus; | |
53 | struct lttng_dynamic_pointer_array array; | |
54 | }; | |
55 | ||
56 | struct lttng_map_content { | |
57 | enum lttng_buffer_type type; | |
58 | struct lttng_dynamic_pointer_array array; | |
59 | }; | |
60 | ||
61 | struct lttng_map_comm { | |
62 | uint32_t name_length /* Includes '\0' */; | |
63 | uint32_t length; | |
64 | uint8_t is_enabled; | |
65 | uint8_t bitness; | |
66 | uint8_t boundary_policy; | |
67 | uint8_t domain; | |
68 | uint8_t buffer_type; | |
69 | uint8_t coalesce_hits;; | |
70 | uint64_t dimension_count; | |
71 | ||
72 | /* length excludes its own length. */ | |
73 | /* A name and dimension sizes follow. */ | |
74 | char payload[]; | |
75 | } LTTNG_PACKED; | |
76 | ||
77 | struct lttng_map_list_comm { | |
78 | uint32_t count; | |
79 | /* Count * lttng_map_comm structure */ | |
80 | char payload[]; | |
81 | } LTTNG_PACKED; | |
82 | ||
83 | struct lttng_map_key_value_pair_comm { | |
84 | uint32_t key_length /* Includes '\0' */; | |
85 | int64_t value; | |
86 | uint8_t has_overflowed; | |
87 | uint8_t has_underflowed; | |
88 | } LTTNG_PACKED; | |
89 | ||
90 | struct lttng_map_key_value_pair_list_comm { | |
91 | uint32_t count; | |
92 | uint8_t type; /* enum lttng_map_key_value_pair_list_type */ | |
93 | uint64_t id; /* pid_t or uid_t */ | |
94 | uint64_t cpu; | |
95 | uint8_t summed_all_cpus; | |
96 | /* Count * lttng_map_key_value_pair_comm structure */ | |
97 | char payload[]; | |
98 | } LTTNG_PACKED; | |
99 | ||
100 | struct lttng_map_content_comm { | |
101 | uint32_t count; | |
102 | uint8_t type; /* enum lttng_buffer_type */ | |
103 | /* Count * lttng_map_key_value_pair_list structure */ | |
104 | char payload[]; | |
105 | }; | |
106 | ||
107 | LTTNG_HIDDEN | |
108 | ssize_t lttng_map_create_from_payload(struct lttng_payload_view *view, | |
109 | struct lttng_map **map); | |
110 | ||
111 | LTTNG_HIDDEN | |
112 | int lttng_map_serialize(const struct lttng_map *map, | |
113 | struct lttng_payload *payload); | |
114 | ||
115 | LTTNG_HIDDEN | |
116 | void lttng_map_get(struct lttng_map *map); | |
117 | ||
118 | LTTNG_HIDDEN | |
119 | void lttng_map_put(struct lttng_map *map); | |
120 | ||
121 | LTTNG_HIDDEN | |
122 | void lttng_map_set_is_enabled(struct lttng_map *map, bool enabled); | |
123 | ||
124 | /* | |
125 | * Allocate a new list of maps. | |
126 | * The returned object must be freed via lttng_map_list_destroy. | |
127 | */ | |
128 | LTTNG_HIDDEN | |
129 | struct lttng_map_list *lttng_map_list_create(void); | |
130 | ||
131 | /* | |
132 | * Add a map to the maps set. | |
133 | * | |
134 | * A reference to the added map is acquired on behalf of the map set | |
135 | * on success. | |
136 | */ | |
137 | LTTNG_HIDDEN | |
138 | enum lttng_map_status lttng_map_list_add(struct lttng_map_list *map_list, | |
139 | struct lttng_map *map); | |
140 | ||
141 | LTTNG_HIDDEN | |
142 | ssize_t lttng_map_list_create_from_payload(struct lttng_payload_view *view, | |
143 | struct lttng_map_list **map_list); | |
144 | ||
145 | /* | |
146 | * Serialize a map list to an lttng_payload object. | |
147 | * Return LTTNG_OK on success, negative lttng error code on error. | |
148 | */ | |
149 | LTTNG_HIDDEN | |
150 | int lttng_map_list_serialize(const struct lttng_map_list *map_list, | |
151 | struct lttng_payload *payload); | |
152 | ||
153 | LTTNG_HIDDEN | |
154 | struct lttng_map_key_value_pair *lttng_map_key_value_pair_create( | |
155 | const char *key, int64_t value); | |
156 | ||
157 | LTTNG_HIDDEN | |
158 | void lttng_map_key_value_pair_set_has_overflowed( | |
159 | struct lttng_map_key_value_pair *key_value); | |
160 | ||
161 | LTTNG_HIDDEN | |
162 | void lttng_map_key_value_pair_set_has_underflowed( | |
163 | struct lttng_map_key_value_pair *key_value); | |
164 | ||
165 | LTTNG_HIDDEN | |
166 | ssize_t lttng_map_key_value_pair_create_from_payload( | |
167 | struct lttng_payload_view *view, | |
168 | struct lttng_map_key_value_pair **key_value); | |
169 | ||
170 | LTTNG_HIDDEN | |
171 | int lttng_map_key_value_pair_serialize( | |
172 | const struct lttng_map_key_value_pair *key_value, | |
173 | struct lttng_payload *payload); | |
174 | ||
175 | LTTNG_HIDDEN | |
176 | void lttng_map_key_value_pair_destroy( | |
177 | struct lttng_map_key_value_pair *key_value); | |
178 | ||
179 | LTTNG_HIDDEN | |
180 | struct lttng_map_key_value_pair_list *lttng_map_key_value_pair_list_create( | |
181 | enum lttng_map_key_value_pair_list_type type, | |
182 | bool summed_all_cpus); | |
183 | ||
184 | LTTNG_HIDDEN | |
185 | enum lttng_map_status lttng_map_key_value_pair_list_set_identifier( | |
186 | struct lttng_map_key_value_pair_list *kv_pair_list, | |
187 | uint64_t identifier); | |
188 | ||
189 | LTTNG_HIDDEN | |
190 | enum lttng_map_status lttng_map_key_value_pair_list_set_cpu( | |
191 | struct lttng_map_key_value_pair_list *kv_pair_list, | |
192 | uint64_t cpu); | |
193 | ||
194 | LTTNG_HIDDEN | |
195 | enum lttng_map_status lttng_map_key_value_pair_list_append_key_value( | |
196 | struct lttng_map_key_value_pair_list *key_values, | |
197 | struct lttng_map_key_value_pair *key_value); | |
198 | ||
199 | LTTNG_HIDDEN | |
200 | ssize_t lttng_map_key_value_pair_list_create_from_payload( | |
201 | struct lttng_payload_view *view, | |
202 | struct lttng_map_key_value_pair_list **key_values); | |
203 | ||
204 | LTTNG_HIDDEN | |
205 | int lttng_map_key_value_pair_list_serialize( | |
206 | const struct lttng_map_key_value_pair_list *key_values, | |
207 | struct lttng_payload *payload); | |
208 | ||
209 | LTTNG_HIDDEN | |
210 | struct lttng_map_content *lttng_map_content_create( | |
211 | enum lttng_buffer_type type); | |
212 | ||
213 | LTTNG_HIDDEN | |
214 | enum lttng_map_status lttng_map_content_append_key_value_list( | |
215 | struct lttng_map_content *map_content, | |
216 | struct lttng_map_key_value_pair_list *kv_list); | |
217 | ||
218 | LTTNG_HIDDEN | |
219 | ssize_t lttng_map_content_create_from_payload( | |
220 | struct lttng_payload_view *view, | |
221 | struct lttng_map_content **map_content); | |
222 | ||
223 | LTTNG_HIDDEN | |
224 | int lttng_map_content_serialize( | |
225 | const struct lttng_map_content *map_content, | |
226 | struct lttng_payload *payload); | |
227 | ||
228 | #endif /* LTTNG_MAP_INTERNAL_H */ |