]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/include/spdk/trace.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / include / spdk / trace.h
CommitLineData
7c673cae
FG
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/**
35 * \file
36 * Tracepoint library
37 */
38
39#ifndef _SPDK_TRACE_H_
40#define _SPDK_TRACE_H_
41
11fdf7f2 42#include "spdk/stdinc.h"
7c673cae
FG
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48#define SPDK_TRACE_SIZE (32 * 1024)
49
50struct spdk_trace_entry {
51 uint64_t tsc;
52 uint16_t tpoint_id;
53 uint16_t poller_id;
54 uint32_t size;
55 uint64_t object_id;
56 uint64_t arg1;
57};
58
59/* If type changes from a uint8_t, change this value. */
60#define SPDK_TRACE_MAX_OWNER (UCHAR_MAX + 1)
61
62struct spdk_trace_owner {
63 uint8_t type;
64 char id_prefix;
65};
66
67/* If type changes from a uint8_t, change this value. */
68#define SPDK_TRACE_MAX_OBJECT (UCHAR_MAX + 1)
69
70struct spdk_trace_object {
71 uint8_t type;
72 char id_prefix;
73};
74
75#define SPDK_TRACE_MAX_GROUP_ID 16
76#define SPDK_TRACE_MAX_TPOINT_ID (SPDK_TRACE_MAX_GROUP_ID * 64)
77#define SPDK_TPOINT_ID(group, tpoint) ((group * 64) + tpoint)
78
79struct spdk_trace_tpoint {
80 char name[44];
81 char short_name[4];
82 uint16_t tpoint_id;
83 uint8_t owner_type;
84 uint8_t object_type;
85 uint8_t new_object;
86 uint8_t arg1_is_ptr;
11fdf7f2 87 uint8_t reserved;
7c673cae
FG
88 char arg1_name[8];
89};
90
91struct spdk_trace_history {
92 /** Logical core number associated with this structure instance. */
93 int lcore;
94
95 /**
96 * Circular buffer of spdk_trace_entry structures for tracing
97 * tpoints on this core. Debug tool spdk_trace reads this
98 * buffer from shared memory to post-process the tpoint entries and
99 * display in a human-readable format.
100 */
101 struct spdk_trace_entry entries[SPDK_TRACE_SIZE];
102
103 /**
104 * Running count of number of occurrences of each tracepoint on this
105 * lcore. Debug tools can use this to easily count tracepoints such as
106 * number of SCSI tasks completed or PDUs read.
107 */
108 uint64_t tpoint_count[SPDK_TRACE_MAX_TPOINT_ID];
109
110 /** Index to next spdk_trace_entry to fill in the circular buffer. */
111 uint32_t next_entry;
112
113};
114
115#define SPDK_TRACE_MAX_LCORE 128
116
11fdf7f2 117struct spdk_trace_flags {
7c673cae
FG
118 uint64_t tsc_rate;
119 uint64_t tpoint_mask[SPDK_TRACE_MAX_GROUP_ID];
7c673cae
FG
120 struct spdk_trace_owner owner[UCHAR_MAX + 1];
121 struct spdk_trace_object object[UCHAR_MAX + 1];
122 struct spdk_trace_tpoint tpoint[SPDK_TRACE_MAX_TPOINT_ID];
123};
11fdf7f2
TL
124extern struct spdk_trace_flags *g_trace_flags;
125extern struct spdk_trace_histories *g_trace_histories;
126
127
128struct spdk_trace_histories {
129 struct spdk_trace_flags flags;
130 struct spdk_trace_history per_lcore_history[SPDK_TRACE_MAX_LCORE];
131};
7c673cae 132
11fdf7f2
TL
133void _spdk_trace_record(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id,
134 uint32_t size, uint64_t object_id, uint64_t arg1);
7c673cae 135
11fdf7f2
TL
136/**
137 * Record the current trace state for tracing tpoints. Debug tool can read the
138 * information from shared memory to post-process the tpoint entries and display
139 * in a human-readable format. This function will call spdk_get_ticks() to get
140 * the current tsc to save in the tracepoint.
141 *
142 * \param tpoint_id Tracepoint id to record.
143 * \param poller_id Poller id to record.
144 * \param size Size to record.
145 * \param object_id Object id to record.
146 * \param arg1 Argument to record.
147 */
148static inline
7c673cae 149void spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size,
11fdf7f2
TL
150 uint64_t object_id, uint64_t arg1)
151{
152 /*
153 * Tracepoint group ID is encoded in the tpoint_id. Lower 6 bits determine the tracepoint
154 * within the group, the remaining upper bits determine the tracepoint group. Each
155 * tracepoint group has its own tracepoint mask.
156 */
157 if (g_trace_histories == NULL ||
158 !((1ULL << (tpoint_id & 0x3F)) & g_trace_histories->flags.tpoint_mask[tpoint_id >> 6])) {
159 return;
160 }
161
162 _spdk_trace_record(0, tpoint_id, poller_id, size, object_id, arg1);
163}
164
165/**
166 * Record the current trace state for tracing tpoints. Debug tool can read the
167 * information from shared memory to post-process the tpoint entries and display
168 * in a human-readable format.
169 *
170 * \param tsc Current tsc.
171 * \param tpoint_id Tracepoint id to record.
172 * \param poller_id Poller id to record.
173 * \param size Size to record.
174 * \param object_id Object id to record.
175 * \param arg1 Argument to record.
176 */
177static inline
178void spdk_trace_record_tsc(uint64_t tsc, uint16_t tpoint_id, uint16_t poller_id,
179 uint32_t size, uint64_t object_id, uint64_t arg1)
180{
181 /*
182 * Tracepoint group ID is encoded in the tpoint_id. Lower 6 bits determine the tracepoint
183 * within the group, the remaining upper bits determine the tracepoint group. Each
184 * tracepoint group has its own tracepoint mask.
185 */
186 if (g_trace_histories == NULL ||
187 !((1ULL << (tpoint_id & 0x3F)) & g_trace_histories->flags.tpoint_mask[tpoint_id >> 6])) {
188 return;
189 }
190
191 _spdk_trace_record(tsc, tpoint_id, poller_id, size, object_id, arg1);
192}
7c673cae 193
11fdf7f2
TL
194/**
195 * Get the current tpoint mask of the given tpoint group.
196 *
197 * \param group_id Tpoint group id associated with the tpoint mask.
198 *
199 * \return current tpoint mask.
200 */
7c673cae
FG
201uint64_t spdk_trace_get_tpoint_mask(uint32_t group_id);
202
11fdf7f2
TL
203/**
204 * Add the specified tpoints to the current tpoint mask for the given tpoint group.
205 *
206 * \param group_id Tpoint group id associated with the tpoint mask.
207 * \param tpoint_mask Tpoint mask which indicates which tpoints to add to the
208 * current tpoint mask.
209 */
7c673cae
FG
210void spdk_trace_set_tpoints(uint32_t group_id, uint64_t tpoint_mask);
211
11fdf7f2
TL
212/**
213 * Clear the specified tpoints from the current tpoint mask for the given tpoint group.
214 *
215 * \param group_id Tpoint group id associated with the tpoint mask.
216 * \param tpoint_mask Tpoint mask which indicates which tpoints to clear from
217 * the current tpoint mask.
218 */
7c673cae
FG
219void spdk_trace_clear_tpoints(uint32_t group_id, uint64_t tpoint_mask);
220
11fdf7f2
TL
221/**
222 * Get a mask of all tracepoint groups which have at least one tracepoint enabled.
223 *
224 * \return a mask of all tracepoint groups.
225 */
7c673cae
FG
226uint64_t spdk_trace_get_tpoint_group_mask(void);
227
11fdf7f2
TL
228/**
229 * For each tpoint group specified in the group mask, enable all of its tpoints.
230 *
231 * \param tpoint_group_mask Tpoint group mask that indicates which tpoints to enable.
232 */
7c673cae
FG
233void spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask);
234
11fdf7f2
TL
235/**
236 * Initialize the trace environment. Debug tool can read the information from
237 * the given shared memory to post-process the tpoint entries and display in a
238 * human-readable format.
239 *
240 * \param shm_name Name of shared memory.
241 * \return 0 on success, else non-zero indicates a failure.
242 */
243int spdk_trace_init(const char *shm_name);
244
245/**
246 * Unmap global trace memory structs.
247 */
7c673cae
FG
248void spdk_trace_cleanup(void);
249
11fdf7f2
TL
250/**
251 * Initialize trace flags.
252 */
253void spdk_trace_flags_init(void);
254
7c673cae
FG
255#define OWNER_NONE 0
256#define OBJECT_NONE 0
257
11fdf7f2
TL
258/**
259 * Register the trace owner.
260 *
261 * \param type Type of the trace owner.
262 * \param id_prefix Prefix of id for the trace owner.
263 */
7c673cae 264void spdk_trace_register_owner(uint8_t type, char id_prefix);
11fdf7f2
TL
265
266/**
267 * Register the trace object.
268 *
269 * \param type Type of the trace object.
270 * \param id_prefix Prefix of id for the trace object.
271 */
7c673cae 272void spdk_trace_register_object(uint8_t type, char id_prefix);
11fdf7f2
TL
273
274/**
275 * Register the description for the tpoint.
276 *
277 * \param name Name for the tpoint.
278 * \param short_name Short name for the tpoint.
279 * \param tpoint_id Id for the tpoint.
280 * \param owner_type Owner type for the tpoint.
281 * \param object_type Object type for the tpoint.
282 * \param new_object New object for the tpoint.
283 * \param arg1_is_ptr This argument indicates whether argument1 is a pointer.
284 * \param arg1_name Name of argument.
285 */
7c673cae
FG
286void spdk_trace_register_description(const char *name, const char *short_name,
287 uint16_t tpoint_id, uint8_t owner_type,
288 uint8_t object_type, uint8_t new_object,
11fdf7f2 289 uint8_t arg1_is_ptr, const char *arg1_name);
7c673cae
FG
290
291struct spdk_trace_register_fn {
292 void (*reg_fn)(void);
293 struct spdk_trace_register_fn *next;
294};
295
11fdf7f2
TL
296/**
297 * Add new trace register function.
298 *
299 * \param reg_fn Trace register function to add.
300 */
7c673cae
FG
301void spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn);
302
11fdf7f2 303#define SPDK_TRACE_REGISTER_FN(fn) \
7c673cae
FG
304 static void fn(void); \
305 struct spdk_trace_register_fn reg_ ## fn = { \
306 .reg_fn = fn, \
307 .next = NULL, \
308 }; \
309 __attribute__((constructor)) static void _ ## fn(void) \
310 { \
311 spdk_trace_add_register_fn(&reg_ ## fn); \
312 } \
313 static void fn(void)
314
315#ifdef __cplusplus
316}
317#endif
318
319#endif