]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/include/spdk/trace.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / spdk / include / spdk / trace.h
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
42 #include <inttypes.h>
43 #include <limits.h>
44
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48
49 #define SPDK_TRACE_SIZE (32 * 1024)
50
51 struct spdk_trace_entry {
52 uint64_t tsc;
53 uint16_t tpoint_id;
54 uint16_t poller_id;
55 uint32_t size;
56 uint64_t object_id;
57 uint64_t arg1;
58 };
59
60 /* If type changes from a uint8_t, change this value. */
61 #define SPDK_TRACE_MAX_OWNER (UCHAR_MAX + 1)
62
63 struct spdk_trace_owner {
64 uint8_t type;
65 char id_prefix;
66 };
67
68 /* If type changes from a uint8_t, change this value. */
69 #define SPDK_TRACE_MAX_OBJECT (UCHAR_MAX + 1)
70
71 struct spdk_trace_object {
72 uint8_t type;
73 char id_prefix;
74 };
75
76 #define SPDK_TRACE_MAX_GROUP_ID 16
77 #define SPDK_TRACE_MAX_TPOINT_ID (SPDK_TRACE_MAX_GROUP_ID * 64)
78 #define SPDK_TPOINT_ID(group, tpoint) ((group * 64) + tpoint)
79
80 struct spdk_trace_tpoint {
81 char name[44];
82 char short_name[4];
83 uint16_t tpoint_id;
84 uint8_t owner_type;
85 uint8_t object_type;
86 uint8_t new_object;
87 uint8_t arg1_is_ptr;
88 uint8_t arg1_is_alias;
89 char arg1_name[8];
90 };
91
92 struct spdk_trace_history {
93 /** Logical core number associated with this structure instance. */
94 int lcore;
95
96 /**
97 * Circular buffer of spdk_trace_entry structures for tracing
98 * tpoints on this core. Debug tool spdk_trace reads this
99 * buffer from shared memory to post-process the tpoint entries and
100 * display in a human-readable format.
101 */
102 struct spdk_trace_entry entries[SPDK_TRACE_SIZE];
103
104 /**
105 * Running count of number of occurrences of each tracepoint on this
106 * lcore. Debug tools can use this to easily count tracepoints such as
107 * number of SCSI tasks completed or PDUs read.
108 */
109 uint64_t tpoint_count[SPDK_TRACE_MAX_TPOINT_ID];
110
111 /** Index to next spdk_trace_entry to fill in the circular buffer. */
112 uint32_t next_entry;
113
114 };
115
116 #define SPDK_TRACE_MAX_LCORE 128
117
118 struct spdk_trace_histories {
119 uint64_t tsc_rate;
120 uint64_t tpoint_mask[SPDK_TRACE_MAX_GROUP_ID];
121 struct spdk_trace_history per_lcore_history[SPDK_TRACE_MAX_LCORE];
122 struct spdk_trace_owner owner[UCHAR_MAX + 1];
123 struct spdk_trace_object object[UCHAR_MAX + 1];
124 struct spdk_trace_tpoint tpoint[SPDK_TRACE_MAX_TPOINT_ID];
125 };
126
127
128 void spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size,
129 uint64_t object_id, uint64_t arg1);
130
131 /** Returns the current tpoint mask. */
132 uint64_t spdk_trace_get_tpoint_mask(uint32_t group_id);
133
134 /** Adds the specified tpoints to the current tpoint mask for the given tpoint group. */
135 void spdk_trace_set_tpoints(uint32_t group_id, uint64_t tpoint_mask);
136
137 /** Clears the specified tpoints from the current tpoint mask for the given tpoint group. */
138 void spdk_trace_clear_tpoints(uint32_t group_id, uint64_t tpoint_mask);
139
140 /** Returns a mask of all tracepoint groups which have at least one tracepoint enabled. */
141 uint64_t spdk_trace_get_tpoint_group_mask(void);
142
143 /** For each tpoint group specified in the group mask, enable all of its tpoints. */
144 void spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask);
145
146 void spdk_trace_init(const char *shm_name);
147 void spdk_trace_cleanup(void);
148
149 #define OWNER_NONE 0
150 #define OBJECT_NONE 0
151
152 void spdk_trace_register_owner(uint8_t type, char id_prefix);
153 void spdk_trace_register_object(uint8_t type, char id_prefix);
154 void spdk_trace_register_description(const char *name, const char *short_name,
155 uint16_t tpoint_id, uint8_t owner_type,
156 uint8_t object_type, uint8_t new_object,
157 uint8_t arg1_is_ptr, uint8_t arg1_is_alias,
158 const char *arg1_name);
159
160 struct spdk_trace_register_fn {
161 void (*reg_fn)(void);
162 struct spdk_trace_register_fn *next;
163 };
164
165 void spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn);
166
167 #define SPDK_TRACE_REGISTER_FN(fn) \
168 static void fn(void); \
169 struct spdk_trace_register_fn reg_ ## fn = { \
170 .reg_fn = fn, \
171 .next = NULL, \
172 }; \
173 __attribute__((constructor)) static void _ ## fn(void) \
174 { \
175 spdk_trace_add_register_fn(&reg_ ## fn); \
176 } \
177 static void fn(void)
178
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif