Commit | Line | Data |
---|---|---|
fdbf8740 PP |
1 | {# |
2 | # The MIT License (MIT) | |
3 | # | |
4 | # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com> | |
5 | # | |
6 | # Permission is hereby granted, free of charge, to any person obtaining | |
7 | # a copy of this software and associated documentation files (the | |
8 | # "Software"), to deal in the Software without restriction, including | |
9 | # without limitation the rights to use, copy, modify, merge, publish, | |
10 | # distribute, sublicense, and/or sell copies of the Software, and to | |
11 | # permit persons to whom the Software is furnished to do so, subject to | |
12 | # the following conditions: | |
13 | # | |
14 | # The above copyright notice and this permission notice shall be | |
15 | # included in all copies or substantial portions of the Software. | |
16 | # | |
17 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
18 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
19 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
20 | # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | |
21 | # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | |
22 | # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | |
23 | # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
24 | #} | |
d6483c83 PP |
25 | {% import 'common.j2' as common %} |
26 | {% import 'c/common.j2' as c_common %} | |
27 | {% import 'c/barectf.c-macros.j2' as macros %} | |
28 | {% set prefix = common.prefix %} | |
29 | {% set ucprefix = common.ucprefix %} | |
30 | {% set ctx_struct_name = c_common.ctx_struct_name %} | |
31 | {% set cg_opts = cfg.options.code_generation_options %} | |
e18cf9d6 | 32 | {% set const_params = true %} |
1cf325c4 | 33 | {% include 'license-header.j2' %} |
e72875eb | 34 | |
d6483c83 PP |
35 | |
36 | #include <stdint.h> | |
37 | #include <string.h> | |
38 | #include <assert.h> | |
39 | ||
40 | #include "{{ header_file_name }}" | |
41 | #include "{{ bitfield_header_file_name }}" | |
42 | ||
629cfd44 PP |
43 | #define _ALIGN(_at_var, _align) \ |
44 | do { \ | |
45 | (_at_var) = ((_at_var) + ((_align) - 1)) & -(_align); \ | |
d6483c83 PP |
46 | } while (0) |
47 | ||
48 | #ifdef __cplusplus | |
49 | # define _TO_VOID_PTR(_value) static_cast<void *>(_value) | |
50 | # define _FROM_VOID_PTR(_type, _value) static_cast<_type *>(_value) | |
51 | #else | |
52 | # define _TO_VOID_PTR(_value) ((void *) (_value)) | |
53 | # define _FROM_VOID_PTR(_type, _value) ((_type *) (_value)) | |
54 | #endif | |
55 | ||
56 | #define _BITS_TO_BYTES(_x) ((_x) >> 3) | |
57 | #define _BYTES_TO_BITS(_x) ((_x) << 3) | |
58 | ||
59 | union _f2u { | |
60 | float f; | |
61 | uint32_t u; | |
62 | }; | |
63 | ||
64 | union _d2u { | |
65 | double f; | |
66 | uint64_t u; | |
67 | }; | |
68 | ||
e18cf9d6 | 69 | uint32_t {{ prefix }}packet_size(const void * const ctx) |
d6483c83 | 70 | { |
e18cf9d6 | 71 | return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, ctx)->packet_size; |
d6483c83 PP |
72 | } |
73 | ||
e18cf9d6 | 74 | int {{ prefix }}packet_is_full(const void * const vctx) |
d6483c83 | 75 | { |
e18cf9d6 | 76 | const struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx); |
d6483c83 PP |
77 | |
78 | return ctx->at == ctx->packet_size; | |
79 | } | |
80 | ||
e18cf9d6 | 81 | int {{ prefix }}packet_is_empty(const void * const vctx) |
d6483c83 | 82 | { |
e18cf9d6 | 83 | const struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx); |
d6483c83 PP |
84 | |
85 | return ctx->at <= ctx->off_content; | |
86 | } | |
87 | ||
e18cf9d6 | 88 | uint32_t {{ prefix }}packet_events_discarded(const void * const vctx) |
d6483c83 | 89 | { |
e18cf9d6 | 90 | return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->events_discarded; |
d6483c83 PP |
91 | } |
92 | ||
e18cf9d6 | 93 | uint8_t *{{ prefix }}packet_buf(const void * const vctx) |
d6483c83 | 94 | { |
e18cf9d6 | 95 | return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->buf; |
d6483c83 PP |
96 | } |
97 | ||
e18cf9d6 | 98 | uint32_t {{ prefix }}packet_buf_size(const void * const vctx) |
d6483c83 | 99 | { |
e18cf9d6 | 100 | const struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx); |
d6483c83 PP |
101 | |
102 | return _BITS_TO_BYTES(ctx->packet_size); | |
103 | } | |
104 | ||
e18cf9d6 PP |
105 | void {{ prefix }}packet_set_buf(void * const vctx, uint8_t * const buf, |
106 | const uint32_t buf_size) | |
d6483c83 | 107 | { |
e18cf9d6 | 108 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
d6483c83 PP |
109 | |
110 | ctx->buf = buf; | |
111 | ctx->packet_size = _BYTES_TO_BITS(buf_size); | |
112 | } | |
113 | ||
e18cf9d6 | 114 | int {{ prefix }}packet_is_open(const void * const vctx) |
d6483c83 | 115 | { |
e18cf9d6 | 116 | return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->packet_is_open; |
d6483c83 PP |
117 | } |
118 | ||
e18cf9d6 | 119 | int {{ prefix }}is_in_tracing_section(const void * const vctx) |
d6483c83 | 120 | { |
e18cf9d6 | 121 | return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->in_tracing_section; |
d6483c83 PP |
122 | } |
123 | ||
e18cf9d6 | 124 | volatile const int *{{ prefix }}is_in_tracing_section_ptr(const void * const vctx) |
d6483c83 | 125 | { |
e18cf9d6 | 126 | return &_FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->in_tracing_section; |
d6483c83 PP |
127 | } |
128 | ||
e18cf9d6 | 129 | int {{ prefix }}is_tracing_enabled(const void * const vctx) |
d6483c83 | 130 | { |
e18cf9d6 | 131 | return _FROM_VOID_PTR(const struct {{ ctx_struct_name }}, vctx)->is_tracing_enabled; |
d6483c83 PP |
132 | } |
133 | ||
e18cf9d6 | 134 | void {{ prefix }}enable_tracing(void * const vctx, const int enable) |
d6483c83 PP |
135 | { |
136 | _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx)->is_tracing_enabled = enable; | |
137 | } | |
138 | ||
139 | static | |
e18cf9d6 | 140 | void _write_c_str(struct {{ ctx_struct_name }} * const ctx, const char * const src) |
d6483c83 | 141 | { |
e18cf9d6 | 142 | const uint32_t sz = strlen(src) + 1; |
d6483c83 PP |
143 | |
144 | memcpy(&ctx->buf[_BITS_TO_BYTES(ctx->at)], src, sz); | |
145 | ctx->at += _BYTES_TO_BITS(sz); | |
146 | } | |
147 | ||
148 | static | |
e8f0d548 | 149 | int _reserve_er_space(void * const vctx, const uint32_t er_size) |
d6483c83 | 150 | { |
d02c7d33 | 151 | int ret; |
e18cf9d6 | 152 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
d6483c83 | 153 | |
9318c705 | 154 | /* Event _cannot_ fit? */ |
e8f0d548 | 155 | if (er_size > (ctx->packet_size - ctx->off_content)) { |
d02c7d33 | 156 | goto no_space; |
d6483c83 PP |
157 | } |
158 | ||
9318c705 | 159 | /* Packet is full? */ |
d6483c83 | 160 | if ({{ prefix }}packet_is_full(ctx)) { |
644b3b4f | 161 | /* Yes: is the back end full? */ |
d6483c83 | 162 | if (ctx->cbs.is_backend_full(ctx->data)) { |
e8f0d548 | 163 | /* Yes: discard event record */ |
d02c7d33 | 164 | goto no_space; |
d6483c83 PP |
165 | } |
166 | ||
9318c705 | 167 | /* Back-end is _not_ full: open new packet */ |
d6483c83 PP |
168 | ctx->use_cur_last_event_ts = 1; |
169 | ctx->cbs.open_packet(ctx->data); | |
170 | ctx->use_cur_last_event_ts = 0; | |
171 | } | |
172 | ||
9318c705 | 173 | /* Event fits the current packet? */ |
e8f0d548 | 174 | if (er_size > (ctx->packet_size - ctx->at)) { |
9318c705 | 175 | /* No: close packet now */ |
d6483c83 PP |
176 | ctx->use_cur_last_event_ts = 1; |
177 | ctx->cbs.close_packet(ctx->data); | |
178 | ctx->use_cur_last_event_ts = 0; | |
179 | ||
644b3b4f | 180 | /* Is the back end full? */ |
d6483c83 | 181 | if (ctx->cbs.is_backend_full(ctx->data)) { |
e8f0d548 | 182 | /* Yes: discard event record */ |
d02c7d33 | 183 | goto no_space; |
d6483c83 PP |
184 | } |
185 | ||
9318c705 | 186 | /* Back-end is _not_ full: open new packet */ |
d6483c83 PP |
187 | ctx->use_cur_last_event_ts = 1; |
188 | ctx->cbs.open_packet(ctx->data); | |
189 | ctx->use_cur_last_event_ts = 0; | |
e8f0d548 | 190 | assert(er_size <= (ctx->packet_size - ctx->at)); |
d6483c83 PP |
191 | } |
192 | ||
d02c7d33 PP |
193 | ret = 1; |
194 | goto end; | |
195 | ||
196 | no_space: | |
197 | ctx->events_discarded++; | |
198 | ret = 0; | |
199 | ||
200 | end: | |
201 | return ret; | |
d6483c83 PP |
202 | } |
203 | ||
204 | static | |
e8f0d548 | 205 | void _commit_er(void * const vctx) |
d6483c83 | 206 | { |
e18cf9d6 | 207 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
d6483c83 | 208 | |
9318c705 | 209 | /* Is the packet full? */ |
d6483c83 | 210 | if ({{ prefix }}packet_is_full(ctx)) { |
9318c705 | 211 | /* Yes: close it now */ |
d6483c83 PP |
212 | ctx->cbs.close_packet(ctx->data); |
213 | } | |
214 | } | |
215 | ||
216 | {% include 'c/ctx-init-func-proto.j2' %} | |
217 | ||
218 | { | |
e18cf9d6 | 219 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
d6483c83 PP |
220 | ctx->cbs = cbs; |
221 | ctx->data = data; | |
222 | ctx->buf = buf; | |
223 | ctx->packet_size = _BYTES_TO_BITS(buf_size); | |
224 | ctx->at = 0; | |
225 | ctx->events_discarded = 0; | |
226 | ctx->packet_is_open = 0; | |
227 | ctx->in_tracing_section = 0; | |
228 | ctx->is_tracing_enabled = 1; | |
229 | ctx->use_cur_last_event_ts = 0; | |
230 | } | |
231 | ||
e8f0d548 PP |
232 | {% for dst in cfg.trace.type.data_stream_types | sort %} |
233 | {% set def_clk_type = dst.default_clock_type %} | |
234 | {% set sctx_name %}{{ prefix }}{{ dst.name }}{% endset %} | |
235 | {% set this_ds_ops = ds_ops[dst] %} | |
d6483c83 PP |
236 | {% include 'c/open-func-proto.j2' %} |
237 | ||
238 | { | |
e8f0d548 | 239 | {{ macros.open_close_func_preamble(dst) | indent_tab }} |
d6483c83 PP |
240 | |
241 | /* | |
242 | * This function is either called by a tracing function, or | |
243 | * directly by the platform. | |
244 | * | |
245 | * If it's called by a tracing function, then | |
246 | * `ctx->in_tracing_section` is 1, so it's safe to open | |
247 | * the packet here (alter the packet), even if tracing was | |
248 | * disabled in the meantime because we're already in a tracing | |
249 | * section (which finishes at the end of the tracing function | |
250 | * call). | |
251 | * | |
252 | * If it's called directly by the platform, then if tracing is | |
253 | * disabled, we don't want to alter the packet, and return | |
254 | * immediately. | |
255 | */ | |
256 | if (!ctx->is_tracing_enabled && !saved_in_tracing_section) { | |
257 | ctx->in_tracing_section = 0; | |
d02c7d33 | 258 | goto end; |
d6483c83 PP |
259 | } |
260 | ||
9318c705 | 261 | /* We can alter the packet */ |
d6483c83 PP |
262 | ctx->in_tracing_section = 1; |
263 | ||
9318c705 | 264 | /* Do not open a packet that is already open */ |
d6483c83 PP |
265 | if (ctx->packet_is_open) { |
266 | ctx->in_tracing_section = saved_in_tracing_section; | |
d02c7d33 | 267 | goto end; |
d6483c83 PP |
268 | } |
269 | ||
270 | ctx->at = 0; | |
e8f0d548 | 271 | {% set pkt_header_op = this_ds_ops.pkt_header_op %} |
2394a4b4 | 272 | {% if pkt_header_op %} |
d6483c83 | 273 | |
e8f0d548 | 274 | {{ pkt_header_op.serialize_str(dst=dst) | indent_tab }} |
d6483c83 PP |
275 | {% endif %} |
276 | ||
e8f0d548 | 277 | {{ this_ds_ops.pkt_ctx_op.serialize_str(dst=dst) | indent_tab }} |
d6483c83 | 278 | |
9318c705 | 279 | /* Save content beginning's offset */ |
d6483c83 PP |
280 | ctx->off_content = ctx->at; |
281 | ||
9318c705 | 282 | /* Mark current packet as open */ |
d6483c83 PP |
283 | ctx->packet_is_open = 1; |
284 | ||
9318c705 | 285 | /* Not tracing anymore */ |
d6483c83 | 286 | ctx->in_tracing_section = saved_in_tracing_section; |
d02c7d33 PP |
287 | |
288 | end: | |
289 | return; | |
d6483c83 PP |
290 | } |
291 | ||
292 | {% include 'c/close-func-proto.j2' %} | |
293 | ||
294 | { | |
e8f0d548 | 295 | {{ macros.open_close_func_preamble(dst) | indent_tab }} |
d6483c83 PP |
296 | |
297 | /* | |
298 | * This function is either called by a tracing function, or | |
299 | * directly by the platform. | |
300 | * | |
301 | * If it's called by a tracing function, then | |
302 | * `ctx->in_tracing_section` is 1, so it's safe to close | |
303 | * the packet here (alter the packet), even if tracing was | |
304 | * disabled in the meantime, because we're already in a tracing | |
305 | * section (which finishes at the end of the tracing function | |
306 | * call). | |
307 | * | |
308 | * If it's called directly by the platform, then if tracing is | |
309 | * disabled, we don't want to alter the packet, and return | |
310 | * immediately. | |
311 | */ | |
312 | if (!ctx->is_tracing_enabled && !saved_in_tracing_section) { | |
313 | ctx->in_tracing_section = 0; | |
d02c7d33 | 314 | goto end; |
d6483c83 PP |
315 | } |
316 | ||
9318c705 | 317 | /* We can alter the packet */ |
d6483c83 PP |
318 | ctx->in_tracing_section = 1; |
319 | ||
9318c705 | 320 | /* Do not close a packet that is not open */ |
d6483c83 PP |
321 | if (!ctx->packet_is_open) { |
322 | ctx->in_tracing_section = saved_in_tracing_section; | |
d02c7d33 | 323 | goto end; |
d6483c83 PP |
324 | } |
325 | ||
9318c705 | 326 | /* Save content size */ |
d6483c83 | 327 | ctx->content_size = ctx->at; |
03088329 | 328 | {% set name = 'timestamp_end' %} |
e8f0d548 PP |
329 | {% if name in dst._pkt_ctx_ft.members %} |
330 | {% set op = ds_op_pkt_ctx_op(dst, name) %} | |
d6483c83 | 331 | |
9318c705 | 332 | /* Go back to `timestamp_end` field offset */ |
6bc97055 | 333 | ctx->at = sctx->off_{{ op | op_src_var_name }}; |
d6483c83 PP |
334 | |
335 | {% set src = 'ts' %} | |
adb5316b | 336 | {% filter indent_tab(indent_first=true) %} |
d6483c83 PP |
337 | {% include 'c/serialize-write-saved-int-statements.j2' %} |
338 | ||
339 | {% endfilter %} | |
340 | {% endif %} | |
03088329 | 341 | {% set name = 'content_size' %} |
e8f0d548 PP |
342 | {% if name in dst._pkt_ctx_ft.members %} |
343 | {% set op = ds_op_pkt_ctx_op(dst, name) %} | |
d6483c83 | 344 | |
9318c705 | 345 | /* Go back to `content_size` field offset */ |
6bc97055 | 346 | ctx->at = sctx->off_{{ op | op_src_var_name }}; |
d6483c83 | 347 | |
03088329 | 348 | {% set src %}ctx->{{ name }}{% endset %} |
adb5316b | 349 | {% filter indent_tab(indent_first=true) %} |
d6483c83 PP |
350 | {% include 'c/serialize-write-saved-int-statements.j2' %} |
351 | ||
352 | {% endfilter %} | |
353 | {% endif %} | |
03088329 | 354 | {% set name = 'events_discarded' %} |
e8f0d548 PP |
355 | {% if name in dst._pkt_ctx_ft.members %} |
356 | {% set op = ds_op_pkt_ctx_op(dst, name) %} | |
d6483c83 | 357 | |
9318c705 | 358 | /* Go back to `events_discarded` field offset */ |
6bc97055 | 359 | ctx->at = sctx->off_{{ op | op_src_var_name }}; |
d6483c83 | 360 | |
03088329 | 361 | {% set src %}ctx->{{ name }}{% endset %} |
adb5316b | 362 | {% filter indent_tab(indent_first=true) %} |
d6483c83 PP |
363 | {% include 'c/serialize-write-saved-int-statements.j2' %} |
364 | ||
365 | {% endfilter %} | |
366 | {% endif %} | |
367 | ||
9318c705 | 368 | /* Go back to end of packet */ |
d6483c83 PP |
369 | ctx->at = ctx->packet_size; |
370 | ||
9318c705 | 371 | /* Mark packet as closed */ |
d6483c83 PP |
372 | ctx->packet_is_open = 0; |
373 | ||
9318c705 | 374 | /* Not tracing anymore */ |
d6483c83 | 375 | ctx->in_tracing_section = saved_in_tracing_section; |
d02c7d33 PP |
376 | |
377 | end: | |
378 | return; | |
d6483c83 | 379 | } |
e8f0d548 | 380 | {% if dst._er_header_ft %} |
d6483c83 | 381 | |
e8f0d548 PP |
382 | static void _serialize_er_header_{{ dst.name }}(void * const vctx, |
383 | const uint32_t ert_id) | |
d6483c83 | 384 | { |
e18cf9d6 | 385 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
d6483c83 | 386 | {% if def_clk_type %} |
e18cf9d6 | 387 | struct {{ sctx_name }}_ctx * const sctx = _FROM_VOID_PTR(struct {{ sctx_name }}_ctx, vctx); |
d6483c83 PP |
388 | const {{ cg_opts.clock_type_c_types[def_clk_type] }} ts = sctx->cur_last_event_ts; |
389 | {% endif %} | |
390 | ||
e8f0d548 | 391 | {{ this_ds_ops.er_header_op.serialize_str(dst=dst) | indent_tab }} |
d6483c83 PP |
392 | } |
393 | {% endif %} | |
e8f0d548 | 394 | {% if dst.event_record_common_context_field_type %} |
d6483c83 | 395 | |
e8f0d548 | 396 | static void _serialize_er_common_ctx_{{ dst.name }}(void * const vctx{{ dst | serialize_er_common_ctx_func_params_str(const_params) }}) |
d6483c83 | 397 | { |
e18cf9d6 | 398 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
d6483c83 | 399 | |
e8f0d548 | 400 | {{ this_ds_ops.er_common_ctx_op.serialize_str(dst=dst) | indent_tab }} |
d6483c83 PP |
401 | } |
402 | {% endif %} | |
403 | {# internal serialization functions #} | |
e8f0d548 | 404 | {% for ert in dst.event_record_types | sort %} |
d6483c83 | 405 | |
e8f0d548 | 406 | static void _serialize_er_{{ dst.name }}_{{ ert.name }}(void * const vctx{{ (dst, ert) | trace_func_params_str(const_params) }}) |
d6483c83 | 407 | { |
e18cf9d6 | 408 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
e8f0d548 | 409 | {% if dst._er_header_ft %} |
d6483c83 | 410 | |
9318c705 | 411 | /* Serialize header */ |
e8f0d548 | 412 | _serialize_er_header_{{ dst.name }}(ctx, {{ ert.id }}); |
d6483c83 | 413 | {% endif %} |
e8f0d548 | 414 | {% if dst.event_record_common_context_field_type %} |
d6483c83 | 415 | |
9318c705 | 416 | /* Serialize common context */ |
e8f0d548 PP |
417 | {% set params = macros.ft_call_params(root_ft_prefixes.ERCC, dst.event_record_common_context_field_type) %} |
418 | _serialize_er_common_ctx_{{ dst.name }}(ctx{{ params }}); | |
d6483c83 | 419 | {% endif %} |
e8f0d548 PP |
420 | {% set this_er_ops = this_ds_ops.er_ops[ert] %} |
421 | {% if this_er_ops.spec_ctx_op %} | |
d6483c83 | 422 | |
e8f0d548 | 423 | {{ this_er_ops.spec_ctx_op.serialize_str(dst=dst, ert=ert) | indent_tab }} |
d6483c83 | 424 | {% endif %} |
e8f0d548 | 425 | {% if this_er_ops.payload_op %} |
d6483c83 | 426 | |
e8f0d548 | 427 | {{ this_er_ops.payload_op.serialize_str(dst=dst, ert=ert) | indent_tab }} |
d6483c83 PP |
428 | {% endif %} |
429 | } | |
430 | {% endfor %} | |
431 | {# internal size functions #} | |
e8f0d548 PP |
432 | {% for ert in dst.event_record_types | sort %} |
433 | {% set this_er_ops = this_ds_ops.er_ops[ert] %} | |
d6483c83 | 434 | |
e8f0d548 | 435 | static uint32_t _er_size_{{ dst.name }}_{{ ert.name }}(void * const vctx{{ (dst, ert) | trace_func_params_str(const_params, only_dyn=true) }}) |
d6483c83 | 436 | { |
e18cf9d6 | 437 | struct {{ ctx_struct_name }} * const ctx = _FROM_VOID_PTR(struct {{ ctx_struct_name }}, vctx); |
d6483c83 | 438 | uint32_t at = ctx->at; |
e8f0d548 | 439 | {% if this_ds_ops.er_header_op %} |
d6483c83 | 440 | |
e8f0d548 | 441 | {{ this_ds_ops.er_header_op.size_str(dst=dst) | indent_tab }} |
d6483c83 | 442 | {% endif %} |
e8f0d548 | 443 | {% if this_ds_ops.er_common_ctx_op %} |
d6483c83 | 444 | |
e8f0d548 | 445 | {{ this_ds_ops.er_common_ctx_op.size_str(dst=dst) | indent_tab }} |
d6483c83 | 446 | {% endif %} |
e8f0d548 | 447 | {% if this_er_ops.spec_ctx_op %} |
d6483c83 | 448 | |
e8f0d548 | 449 | {{ this_er_ops.spec_ctx_op.size_str(dst=dst, ert=ert) | indent_tab }} |
d6483c83 | 450 | {% endif %} |
e8f0d548 | 451 | {% if this_er_ops.payload_op %} |
d6483c83 | 452 | |
e8f0d548 | 453 | {{ this_er_ops.payload_op.size_str(dst=dst, ert=ert) | indent_tab }} |
d6483c83 PP |
454 | {% endif %} |
455 | ||
456 | return at - ctx->at; | |
457 | } | |
458 | {% endfor %} | |
459 | {# public tracing functions #} | |
e8f0d548 | 460 | {% for ert in dst.event_record_types | sort %} |
d6483c83 PP |
461 | |
462 | {% include 'c/trace-func-proto.j2' %} | |
463 | ||
464 | { | |
e18cf9d6 | 465 | struct {{ ctx_struct_name }} * const ctx = &sctx->parent; |
e8f0d548 | 466 | uint32_t er_size; |
d6483c83 PP |
467 | |
468 | {% if def_clk_type %} | |
462e49b3 | 469 | /* Save timestamp */ |
d6483c83 PP |
470 | sctx->cur_last_event_ts = ctx->cbs.{{ def_clk_type.name }}_clock_get_value(ctx->data); |
471 | ||
472 | {% endif %} | |
d6483c83 | 473 | if (!ctx->is_tracing_enabled) { |
d02c7d33 | 474 | goto end; |
d6483c83 PP |
475 | } |
476 | ||
9318c705 | 477 | /* We can alter the packet */ |
d6483c83 PP |
478 | ctx->in_tracing_section = 1; |
479 | ||
e8f0d548 PP |
480 | /* Compute event record size */ |
481 | {% set er_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ERCC, dst.event_record_common_context_field_type, true) %} | |
a7e54146 PP |
482 | {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.ERSC, ert.specific_context_field_type, true) %} |
483 | {% set payload_params = macros.ft_call_params(root_ft_prefixes.ERP, ert.payload_field_type, true) %} | |
e8f0d548 PP |
484 | {% set params %}{{ er_common_ctx_params }}{{ spec_ctx_params }}{{ payload_params }}{% endset %} |
485 | er_size = _er_size_{{ dst.name }}_{{ ert.name }}(_TO_VOID_PTR(ctx){{ params }}); | |
d6483c83 | 486 | |
9318c705 | 487 | /* Is there enough space to serialize? */ |
e8f0d548 | 488 | if (!_reserve_er_space(_TO_VOID_PTR(ctx), er_size)) { |
d6483c83 PP |
489 | /* no: forget this */ |
490 | ctx->in_tracing_section = 0; | |
d02c7d33 | 491 | goto end; |
d6483c83 PP |
492 | } |
493 | ||
e8f0d548 PP |
494 | /* Serialize event record */ |
495 | {% set er_common_ctx_params = macros.ft_call_params(root_ft_prefixes.ERCC, dst.event_record_common_context_field_type) %} | |
a7e54146 PP |
496 | {% set spec_ctx_params = macros.ft_call_params(root_ft_prefixes.ERSC, ert.specific_context_field_type) %} |
497 | {% set payload_params = macros.ft_call_params(root_ft_prefixes.ERP, ert.payload_field_type) %} | |
e8f0d548 PP |
498 | {% set params %}{{ er_common_ctx_params }}{{ spec_ctx_params }}{{ payload_params }}{% endset %} |
499 | _serialize_er_{{ dst.name }}_{{ ert.name }}(_TO_VOID_PTR(ctx){{ params }}); | |
d6483c83 | 500 | |
e8f0d548 PP |
501 | /* Commit event record */ |
502 | _commit_er(_TO_VOID_PTR(ctx)); | |
d6483c83 | 503 | |
9318c705 | 504 | /* Not tracing anymore */ |
d6483c83 | 505 | ctx->in_tracing_section = 0; |
d02c7d33 PP |
506 | |
507 | end: | |
508 | return; | |
d6483c83 PP |
509 | } |
510 | {% endfor %} | |
511 | {% endfor %} |