trace: implement memory allocation
[dpdk.git] / lib / librte_eal / common / eal_trace.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2020 Marvell International Ltd.
3  */
4
5 #ifndef __EAL_TRACE_H
6 #define __EAL_TRACE_H
7
8 #include <rte_cycles.h>
9 #include <rte_log.h>
10 #include <rte_malloc.h>
11 #include <rte_spinlock.h>
12 #include <rte_trace.h>
13 #include <rte_trace_point.h>
14 #include <rte_uuid.h>
15
16 #include "eal_private.h"
17 #include "eal_thread.h"
18
19 #define trace_err(fmt, args...) \
20         RTE_LOG(ERR, EAL, "%s():%u " fmt "\n", __func__, __LINE__, ## args)
21
22 #define trace_crit(fmt, args...) \
23         RTE_LOG(CRIT, EAL, "%s():%u " fmt "\n", __func__, __LINE__, ## args)
24
25 #define TRACE_PREFIX_LEN 12
26 #define TRACE_DIR_STR_LEN (sizeof("YYYY-mm-dd-AM-HH-MM-SS") + TRACE_PREFIX_LEN)
27 #define TRACE_CTF_FIELD_SIZE 384
28 #define TRACE_POINT_NAME_SIZE 64
29 #define TRACE_CTF_MAGIC 0xC1FC1FC1
30
31
32 struct trace_point {
33         STAILQ_ENTRY(trace_point) next;
34         rte_trace_point_t *handle;
35         char name[TRACE_POINT_NAME_SIZE];
36         char ctf_field[TRACE_CTF_FIELD_SIZE];
37 };
38
39 enum trace_area_e {
40         TRACE_AREA_HEAP,
41         TRACE_AREA_HUGEPAGE,
42 };
43
44 struct thread_mem_meta {
45         void *mem;
46         enum trace_area_e area;
47 };
48
49 struct trace {
50         char dir[PATH_MAX];
51         int dir_offset;
52         int register_errno;
53         bool status;
54         enum rte_trace_mode mode;
55         rte_uuid_t uuid;
56         uint32_t buff_len;
57         uint32_t nb_trace_points;
58         uint32_t nb_trace_mem_list;
59         struct thread_mem_meta *lcore_meta;
60         uint64_t epoch_sec;
61         uint64_t epoch_nsec;
62         uint64_t uptime_ticks;
63         char *ctf_meta;
64         uint32_t ctf_meta_offset_freq;
65         uint32_t ctf_meta_offset_freq_off_s;
66         uint32_t ctf_meta_offset_freq_off;
67         uint16_t ctf_fixup_done;
68         rte_spinlock_t lock;
69 };
70
71 /* Helper functions */
72 static inline uint16_t
73 trace_id_get(rte_trace_point_t *trace)
74 {
75         return (*trace & __RTE_TRACE_FIELD_ID_MASK) >>
76                 __RTE_TRACE_FIELD_ID_SHIFT;
77 }
78
79 static inline size_t
80 trace_mem_sz(uint32_t len)
81 {
82         return len + sizeof(struct __rte_trace_header);
83 }
84
85 /* Trace object functions */
86 struct trace *trace_obj_get(void);
87
88 /* Trace point list functions */
89 STAILQ_HEAD(trace_point_head, trace_point);
90 struct trace_point_head *trace_list_head_get(void);
91
92 /* Util functions */
93 const char *trace_mode_to_string(enum rte_trace_mode mode);
94 const char *trace_area_to_string(enum trace_area_e area);
95 bool trace_has_duplicate_entry(void);
96 void trace_uuid_generate(void);
97 int trace_metadata_create(void);
98 void trace_metadata_destroy(void);
99 int trace_mkdir(void);
100 int trace_epoch_time_save(void);
101 void trace_mem_per_thread_free(void);
102
103 /* EAL interface */
104 int eal_trace_init(void);
105 void eal_trace_fini(void);
106
107 #endif /* __EAL_TRACE_H */