1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2020 Marvell International Ltd.
8 #include <rte_common.h>
10 #include <rte_lcore.h>
11 #include <rte_per_lcore.h>
12 #include <rte_string_fns.h>
14 #include "eal_trace.h"
16 RTE_DEFINE_PER_LCORE(volatile int, trace_point_sz);
17 static RTE_DEFINE_PER_LCORE(char, ctf_field[TRACE_CTF_FIELD_SIZE]);
18 static RTE_DEFINE_PER_LCORE(int, ctf_count);
20 static struct trace_point_head tp_list = STAILQ_HEAD_INITIALIZER(tp_list);
21 static struct trace trace;
24 __rte_trace_point_register(rte_trace_point_t *handle, const char *name,
25 void (*register_fn)(void))
27 char *field = RTE_PER_LCORE(ctf_field);
28 struct trace_point *tp;
31 /* Sanity checks of arguments */
32 if (name == NULL || register_fn == NULL || handle == NULL) {
33 trace_err("invalid arguments");
38 /* Check the size of the trace point object */
39 RTE_PER_LCORE(trace_point_sz) = 0;
40 RTE_PER_LCORE(ctf_count) = 0;
42 if (RTE_PER_LCORE(trace_point_sz) == 0) {
43 trace_err("missing rte_trace_emit_header() in register fn");
48 /* Is size overflowed */
49 if (RTE_PER_LCORE(trace_point_sz) > UINT16_MAX) {
50 trace_err("trace point size overflowed");
55 /* Are we running out of space to store trace points? */
56 if (trace.nb_trace_points > UINT16_MAX) {
57 trace_err("trace point exceeds the max count");
62 /* Get the size of the trace point */
63 sz = RTE_PER_LCORE(trace_point_sz);
64 tp = calloc(1, sizeof(struct trace_point));
66 trace_err("fail to allocate trace point memory");
71 /* Initialize the trace point */
72 if (rte_strscpy(tp->name, name, TRACE_POINT_NAME_SIZE) < 0) {
73 trace_err("name is too long");
78 /* Copy the field data for future use */
79 if (rte_strscpy(tp->ctf_field, field, TRACE_CTF_FIELD_SIZE) < 0) {
80 trace_err("CTF field size is too long");
85 /* Clear field memory for the next event */
86 memset(field, 0, TRACE_CTF_FIELD_SIZE);
88 /* Form the trace handle */
90 *handle |= trace.nb_trace_points << __RTE_TRACE_FIELD_ID_SHIFT;
92 trace.nb_trace_points++;
95 /* Add the trace point at tail */
96 STAILQ_INSERT_TAIL(&tp_list, tp, next);
97 __atomic_thread_fence(__ATOMIC_RELEASE);
104 if (trace.register_errno == 0)
105 trace.register_errno = rte_errno;