Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2020 Marvell International Ltd.
3 : : */
4 : :
5 : : #ifndef _RTE_TRACE_POINT_H_
6 : : #define _RTE_TRACE_POINT_H_
7 : :
8 : : /**
9 : : * @file
10 : : *
11 : : * RTE Tracepoint API
12 : : *
13 : : * This file provides the tracepoint API to RTE applications.
14 : : *
15 : : * @warning
16 : : * @b EXPERIMENTAL: this API may change without prior notice
17 : : */
18 : :
19 : : #ifdef __cplusplus
20 : : extern "C" {
21 : : #endif
22 : :
23 : : #include <stdbool.h>
24 : : #include <stdio.h>
25 : :
26 : : #include <rte_branch_prediction.h>
27 : : #include <rte_common.h>
28 : : #include <rte_compat.h>
29 : : #include <rte_cycles.h>
30 : : #include <rte_per_lcore.h>
31 : : #include <rte_stdatomic.h>
32 : : #include <rte_string_fns.h>
33 : : #include <rte_uuid.h>
34 : :
35 : : /** The tracepoint object. */
36 : : typedef RTE_ATOMIC(uint64_t) rte_trace_point_t;
37 : :
38 : : /**
39 : : * Macro to define the tracepoint arguments in RTE_TRACE_POINT macro.
40 : :
41 : : * @see RTE_TRACE_POINT, RTE_TRACE_POINT_FP
42 : : */
43 : : #define RTE_TRACE_POINT_ARGS
44 : :
45 : : /** @internal Helper macro to support RTE_TRACE_POINT and RTE_TRACE_POINT_FP */
46 : : #define __RTE_TRACE_POINT(_mode, _tp, _args, ...) \
47 : : extern rte_trace_point_t __##_tp; \
48 : : static __rte_always_inline void \
49 : : _tp _args \
50 : : { \
51 : : __rte_trace_point_emit_header_##_mode(&__##_tp); \
52 : : __VA_ARGS__ \
53 : : }
54 : :
55 : : /**
56 : : * Create a tracepoint.
57 : : *
58 : : * A tracepoint is defined by specifying:
59 : : * - its input arguments: they are the C function style parameters to define
60 : : * the arguments of tracepoint function. These input arguments are embedded
61 : : * using the RTE_TRACE_POINT_ARGS macro.
62 : : * - its output event fields: they are the sources of event fields that form
63 : : * the payload of any event that the execution of the tracepoint macro emits
64 : : * for this particular tracepoint. The application uses
65 : : * rte_trace_point_emit_* macros to emit the output event fields.
66 : : *
67 : : * @param tp
68 : : * Tracepoint object. Before using the tracepoint, an application needs to
69 : : * define the tracepoint using RTE_TRACE_POINT_REGISTER macro.
70 : : * @param args
71 : : * C function style input arguments to define the arguments to tracepoint
72 : : * function.
73 : : * @param ...
74 : : * Define the payload of trace function. The payload will be formed using
75 : : * rte_trace_point_emit_* macros. Use ";" delimiter between two payloads.
76 : : *
77 : : * @see RTE_TRACE_POINT_ARGS, RTE_TRACE_POINT_REGISTER, rte_trace_point_emit_*
78 : : */
79 : : #define RTE_TRACE_POINT(tp, args, ...) \
80 : : __RTE_TRACE_POINT(generic, tp, args, __VA_ARGS__)
81 : :
82 : : /**
83 : : * Create a tracepoint for fast path.
84 : : *
85 : : * Similar to RTE_TRACE_POINT, except that it is removed at compilation time
86 : : * unless the RTE_ENABLE_TRACE_FP configuration parameter is set.
87 : : *
88 : : * @param tp
89 : : * Tracepoint object. Before using the tracepoint, an application needs to
90 : : * define the tracepoint using RTE_TRACE_POINT_REGISTER macro.
91 : : * @param args
92 : : * C function style input arguments to define the arguments to tracepoint.
93 : : * function.
94 : : * @param ...
95 : : * Define the payload of trace function. The payload will be formed using
96 : : * rte_trace_point_emit_* macros, Use ";" delimiter between two payloads.
97 : : *
98 : : * @see RTE_TRACE_POINT
99 : : */
100 : : #define RTE_TRACE_POINT_FP(tp, args, ...) \
101 : : __RTE_TRACE_POINT(fp, tp, args, __VA_ARGS__)
102 : :
103 : : #ifdef __DOXYGEN__
104 : :
105 : : /**
106 : : * Register a tracepoint.
107 : : *
108 : : * @param trace
109 : : * The tracepoint object created using RTE_TRACE_POINT_REGISTER.
110 : : * @param name
111 : : * The name of the tracepoint object.
112 : : * @return
113 : : * - 0: Successfully registered the tracepoint.
114 : : * - <0: Failure to register the tracepoint.
115 : : */
116 : : #define RTE_TRACE_POINT_REGISTER(trace, name)
117 : :
118 : : /** Tracepoint function payload for uint64_t datatype */
119 : : #define rte_trace_point_emit_u64(val)
120 : : /** Tracepoint function payload for int64_t datatype */
121 : : #define rte_trace_point_emit_i64(val)
122 : : /** Tracepoint function payload for uint32_t datatype */
123 : : #define rte_trace_point_emit_u32(val)
124 : : /** Tracepoint function payload for int32_t datatype */
125 : : #define rte_trace_point_emit_i32(val)
126 : : /** Tracepoint function payload for uint16_t datatype */
127 : : #define rte_trace_point_emit_u16(val)
128 : : /** Tracepoint function payload for int16_t datatype */
129 : : #define rte_trace_point_emit_i16(val)
130 : : /** Tracepoint function payload for uint8_t datatype */
131 : : #define rte_trace_point_emit_u8(val)
132 : : /** Tracepoint function payload for int8_t datatype */
133 : : #define rte_trace_point_emit_i8(val)
134 : : /** Tracepoint function payload for int datatype */
135 : : #define rte_trace_point_emit_int(val)
136 : : /** Tracepoint function payload for long datatype */
137 : : #define rte_trace_point_emit_long(val)
138 : : /** Tracepoint function payload for size_t datatype */
139 : : #define rte_trace_point_emit_size_t(val)
140 : : /** Tracepoint function payload for float datatype */
141 : : #define rte_trace_point_emit_float(val)
142 : : /** Tracepoint function payload for double datatype */
143 : : #define rte_trace_point_emit_double(val)
144 : : /** Tracepoint function payload for pointer datatype */
145 : : #define rte_trace_point_emit_ptr(val)
146 : : /** Tracepoint function payload for string datatype */
147 : : #define rte_trace_point_emit_string(val)
148 : : /**
149 : : * Tracepoint function to capture a blob.
150 : : *
151 : : * @param val
152 : : * Pointer to the array to be captured.
153 : : * @param len
154 : : * Length to be captured. The maximum supported length is
155 : : * RTE_TRACE_BLOB_LEN_MAX bytes.
156 : : */
157 : : #define rte_trace_point_emit_blob(val, len)
158 : :
159 : : #endif /* __DOXYGEN__ */
160 : :
161 : : /** @internal Macro to define maximum emit length of string datatype. */
162 : : #define __RTE_TRACE_EMIT_STRING_LEN_MAX 32
163 : : /** @internal Macro to define event header size. */
164 : : #define __RTE_TRACE_EVENT_HEADER_SZ sizeof(uint64_t)
165 : :
166 : : /** Macro to define maximum emit length of blob. */
167 : : #define RTE_TRACE_BLOB_LEN_MAX 64
168 : :
169 : : /**
170 : : * Enable recording events of the given tracepoint in the trace buffer.
171 : : *
172 : : * @param tp
173 : : * The tracepoint object to enable.
174 : : * @return
175 : : * - 0: Success.
176 : : * - (-ERANGE): Trace object is not registered.
177 : : */
178 : : __rte_experimental
179 : : int rte_trace_point_enable(rte_trace_point_t *tp);
180 : :
181 : : /**
182 : : * Disable recording events of the given tracepoint in the trace buffer.
183 : : *
184 : : * @param tp
185 : : * The tracepoint object to disable.
186 : : * @return
187 : : * - 0: Success.
188 : : * - (-ERANGE): Trace object is not registered.
189 : : */
190 : : __rte_experimental
191 : : int rte_trace_point_disable(rte_trace_point_t *tp);
192 : :
193 : : /**
194 : : * Test if recording events from the given tracepoint is enabled.
195 : : *
196 : : * @param tp
197 : : * The tracepoint object.
198 : : * @return
199 : : * true if tracepoint is enabled, false otherwise.
200 : : */
201 : : __rte_experimental
202 : : bool rte_trace_point_is_enabled(rte_trace_point_t *tp);
203 : :
204 : : /**
205 : : * Lookup a tracepoint object from its name.
206 : : *
207 : : * @param name
208 : : * The name of the tracepoint.
209 : : * @return
210 : : * The tracepoint object or NULL if not found.
211 : : */
212 : : __rte_experimental
213 : : rte_trace_point_t *rte_trace_point_lookup(const char *name);
214 : :
215 : : /**
216 : : * @internal
217 : : *
218 : : * Test if the tracepoint fast path compile-time option is enabled.
219 : : *
220 : : * @return
221 : : * true if tracepoint fast path enabled, false otherwise.
222 : : */
223 : : __rte_experimental
224 : : static __rte_always_inline bool
225 : : __rte_trace_point_fp_is_enabled(void)
226 : : {
227 : : #ifdef RTE_ENABLE_TRACE_FP
228 : : return true;
229 : : #else
230 : : return false;
231 : : #endif
232 : : }
233 : :
234 : : /**
235 : : * @internal
236 : : *
237 : : * Allocate trace memory buffer per thread.
238 : : */
239 : : __rte_experimental
240 : : void __rte_trace_mem_per_thread_alloc(void);
241 : :
242 : : /**
243 : : * @internal
244 : : *
245 : : * Helper function to emit field.
246 : : *
247 : : * @param sz
248 : : * The tracepoint size.
249 : : * @param field
250 : : * The name of the trace event.
251 : : * @param type
252 : : * The datatype of the trace event as string.
253 : : * @return
254 : : * - 0: Success.
255 : : * - <0: Failure.
256 : : */
257 : : __rte_experimental
258 : : void __rte_trace_point_emit_field(size_t sz, const char *field,
259 : : const char *type);
260 : :
261 : : /**
262 : : * @internal
263 : : *
264 : : * Helper function to register a dynamic tracepoint.
265 : : * Use RTE_TRACE_POINT_REGISTER macro for tracepoint registration.
266 : : *
267 : : * @param trace
268 : : * The tracepoint object created using RTE_TRACE_POINT_REGISTER.
269 : : * @param name
270 : : * The name of the tracepoint object.
271 : : * @param register_fn
272 : : * Trace registration function.
273 : : * @return
274 : : * - 0: Successfully registered the tracepoint.
275 : : * - <0: Failure to register the tracepoint.
276 : : */
277 : : __rte_experimental
278 : : int __rte_trace_point_register(rte_trace_point_t *trace, const char *name,
279 : : void (*register_fn)(void));
280 : :
281 : : #ifndef __DOXYGEN__
282 : :
283 : : #ifndef _RTE_TRACE_POINT_REGISTER_H_
284 : : #ifdef ALLOW_EXPERIMENTAL_API
285 : :
286 : : #define __RTE_TRACE_EVENT_HEADER_ID_SHIFT (48)
287 : :
288 : : #define __RTE_TRACE_FIELD_SIZE_SHIFT 0
289 : : #define __RTE_TRACE_FIELD_SIZE_MASK (0xffffULL << __RTE_TRACE_FIELD_SIZE_SHIFT)
290 : : #define __RTE_TRACE_FIELD_ID_SHIFT (16)
291 : : #define __RTE_TRACE_FIELD_ID_MASK (0xffffULL << __RTE_TRACE_FIELD_ID_SHIFT)
292 : : #define __RTE_TRACE_FIELD_ENABLE_MASK (1ULL << 63)
293 : : #define __RTE_TRACE_FIELD_ENABLE_DISCARD (1ULL << 62)
294 : :
295 : : struct __rte_trace_stream_header {
296 : : uint32_t magic;
297 : : rte_uuid_t uuid;
298 : : uint32_t lcore_id;
299 : : char thread_name[__RTE_TRACE_EMIT_STRING_LEN_MAX];
300 : : } __rte_packed;
301 : :
302 : : struct __rte_trace_header {
303 : : uint32_t offset;
304 : : uint32_t len;
305 : : struct __rte_trace_stream_header stream_header;
306 : : uint8_t mem[];
307 : : };
308 : :
309 : : RTE_DECLARE_PER_LCORE(void *, trace_mem);
310 : :
311 : : static __rte_always_inline void *
312 : : __rte_trace_mem_get(uint64_t in)
313 : : {
314 : 37 : struct __rte_trace_header *trace =
315 : : (struct __rte_trace_header *)(RTE_PER_LCORE(trace_mem));
316 : 37 : const uint16_t sz = in & __RTE_TRACE_FIELD_SIZE_MASK;
317 : :
318 : : /* Trace memory is not initialized for this thread */
319 [ - + - + : 37 : if (unlikely(trace == NULL)) {
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - -
+ + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
320 : 1 : __rte_trace_mem_per_thread_alloc();
321 : 1 : trace = (struct __rte_trace_header *)(RTE_PER_LCORE(trace_mem));
322 [ - - - - : 1 : if (unlikely(trace == NULL))
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
+ - # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
323 : : return NULL;
324 : : }
325 : : /* Check the wrap around case */
326 : 37 : uint32_t offset = trace->offset;
327 [ - + - + : 37 : if (unlikely((offset + sz) >= trace->len)) {
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - +
- + - + -
+ - + - -
- + # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
328 : : /* Disable the trace event if it in DISCARD mode */
329 [ # # # # : 0 : if (unlikely(in & __RTE_TRACE_FIELD_ENABLE_DISCARD))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
330 : : return NULL;
331 : :
332 : : offset = 0;
333 : : }
334 : : /* Align to event header size */
335 : 37 : offset = RTE_ALIGN_CEIL(offset, __RTE_TRACE_EVENT_HEADER_SZ);
336 : 37 : void *mem = RTE_PTR_ADD(&trace->mem[0], offset);
337 : 37 : offset += sz;
338 : 37 : trace->offset = offset;
339 : :
340 : 37 : return mem;
341 : : }
342 : :
343 : : static __rte_always_inline void *
344 : : __rte_trace_point_emit_ev_header(void *mem, uint64_t in)
345 : : {
346 : : uint64_t val;
347 : :
348 : : /* Event header [63:0] = id [63:48] | timestamp [47:0] */
349 : 37 : val = rte_get_tsc_cycles() &
350 : : ~(0xffffULL << __RTE_TRACE_EVENT_HEADER_ID_SHIFT);
351 : 37 : val |= ((in & __RTE_TRACE_FIELD_ID_MASK) <<
352 : : (__RTE_TRACE_EVENT_HEADER_ID_SHIFT -
353 : : __RTE_TRACE_FIELD_ID_SHIFT));
354 : :
355 : 15 : *(uint64_t *)mem = val;
356 [ + + + + : 36 : return RTE_PTR_ADD(mem, __RTE_TRACE_EVENT_HEADER_SZ);
- + - + #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
357 : : }
358 : :
359 : : #define __rte_trace_point_emit_header_generic(t) \
360 : : void *mem; \
361 : : do { \
362 : : const uint64_t val = rte_atomic_load_explicit(t, rte_memory_order_acquire); \
363 : : if (likely(!(val & __RTE_TRACE_FIELD_ENABLE_MASK))) \
364 : : return; \
365 : : mem = __rte_trace_mem_get(val); \
366 : : if (unlikely(mem == NULL)) \
367 : : return; \
368 : : mem = __rte_trace_point_emit_ev_header(mem, val); \
369 : : } while (0)
370 : :
371 : : #define __rte_trace_point_emit_header_fp(t) \
372 : : if (!__rte_trace_point_fp_is_enabled()) \
373 : : return; \
374 : : __rte_trace_point_emit_header_generic(t)
375 : :
376 : : #define __rte_trace_point_emit(in, type) \
377 : : do { \
378 : : memcpy(mem, &(in), sizeof(in)); \
379 : : mem = RTE_PTR_ADD(mem, sizeof(in)); \
380 : : } while (0)
381 : :
382 : : #define rte_trace_point_emit_string(in) \
383 : : do { \
384 : : if (unlikely(in == NULL)) \
385 : : return; \
386 : : rte_strscpy((char *)mem, in, __RTE_TRACE_EMIT_STRING_LEN_MAX); \
387 : : mem = RTE_PTR_ADD(mem, __RTE_TRACE_EMIT_STRING_LEN_MAX); \
388 : : } while (0)
389 : :
390 : : #define rte_trace_point_emit_blob(in, len) \
391 : : do { \
392 : : if (unlikely(in == NULL)) \
393 : : return; \
394 : : if (len > RTE_TRACE_BLOB_LEN_MAX) \
395 : : len = RTE_TRACE_BLOB_LEN_MAX; \
396 : : __rte_trace_point_emit(len, uint8_t); \
397 : : memcpy(mem, in, len); \
398 : : memset(RTE_PTR_ADD(mem, len), 0, RTE_TRACE_BLOB_LEN_MAX - len); \
399 : : mem = RTE_PTR_ADD(mem, RTE_TRACE_BLOB_LEN_MAX); \
400 : : } while (0)
401 : :
402 : : #else
403 : :
404 : : #define __rte_trace_point_emit_header_generic(t) RTE_SET_USED(t)
405 : : #define __rte_trace_point_emit_header_fp(t) RTE_SET_USED(t)
406 : : #define __rte_trace_point_emit(in, type) RTE_SET_USED(in)
407 : : #define rte_trace_point_emit_string(in) RTE_SET_USED(in)
408 : : #define rte_trace_point_emit_blob(in, len) \
409 : : do { \
410 : : RTE_SET_USED(in); \
411 : : RTE_SET_USED(len); \
412 : : } while (0)
413 : :
414 : :
415 : : #endif /* ALLOW_EXPERIMENTAL_API */
416 : : #endif /* _RTE_TRACE_POINT_REGISTER_H_ */
417 : :
418 : : #define rte_trace_point_emit_u64(in) __rte_trace_point_emit(in, uint64_t)
419 : : #define rte_trace_point_emit_i64(in) __rte_trace_point_emit(in, int64_t)
420 : : #define rte_trace_point_emit_u32(in) __rte_trace_point_emit(in, uint32_t)
421 : : #define rte_trace_point_emit_i32(in) __rte_trace_point_emit(in, int32_t)
422 : : #define rte_trace_point_emit_u16(in) __rte_trace_point_emit(in, uint16_t)
423 : : #define rte_trace_point_emit_i16(in) __rte_trace_point_emit(in, int16_t)
424 : : #define rte_trace_point_emit_u8(in) __rte_trace_point_emit(in, uint8_t)
425 : : #define rte_trace_point_emit_i8(in) __rte_trace_point_emit(in, int8_t)
426 : : #define rte_trace_point_emit_int(in) __rte_trace_point_emit(in, int32_t)
427 : : #define rte_trace_point_emit_long(in) __rte_trace_point_emit(in, long)
428 : : #define rte_trace_point_emit_size_t(in) __rte_trace_point_emit(in, size_t)
429 : : #define rte_trace_point_emit_float(in) __rte_trace_point_emit(in, float)
430 : : #define rte_trace_point_emit_double(in) __rte_trace_point_emit(in, double)
431 : : #define rte_trace_point_emit_ptr(in) __rte_trace_point_emit(in, uintptr_t)
432 : :
433 : : #endif /* __DOXYGEN__ */
434 : :
435 : : #ifdef __cplusplus
436 : : }
437 : : #endif
438 : :
439 : : #endif /* _RTE_TRACE_POINT_H_ */
|