Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (C) 2017 Intel Corporation.
3 : : * All rights reserved.
4 : : */
5 : :
6 : : #include "spdk/stdinc.h"
7 : :
8 : : #include "spdk/env.h"
9 : : #include "spdk/trace.h"
10 : : #include "spdk/log.h"
11 : : #include "spdk/util.h"
12 : : #include "trace_internal.h"
13 : : #include "spdk/bit_array.h"
14 : :
15 : : static struct spdk_trace_register_fn *g_reg_fn_head = NULL;
16 : : static struct {
17 : : uint16_t *ring;
18 : : uint32_t head;
19 : : uint32_t tail;
20 : : uint32_t size;
21 : : pthread_spinlock_t lock;
22 : : } g_owner_ids;
23 : :
24 : 3222 : SPDK_LOG_REGISTER_COMPONENT(trace)
25 : :
26 : : uint64_t
27 : 540 : spdk_trace_get_tpoint_mask(uint32_t group_id)
28 : : {
29 [ - + ]: 540 : if (group_id >= SPDK_TRACE_MAX_GROUP_ID) {
30 : 0 : SPDK_ERRLOG("invalid group ID %d\n", group_id);
31 : 0 : return 0ULL;
32 : : }
33 : :
34 [ - + ]: 540 : if (g_trace_file == NULL) {
35 : 0 : return 0ULL;
36 : : }
37 : :
38 : 540 : return g_trace_file->tpoint_mask[group_id];
39 : : }
40 : :
41 : : void
42 : 3216 : spdk_trace_set_tpoints(uint32_t group_id, uint64_t tpoint_mask)
43 : : {
44 [ - + ]: 3216 : if (g_trace_file == NULL) {
45 : 0 : SPDK_ERRLOG("trace is not initialized\n");
46 : 0 : return;
47 : : }
48 : :
49 [ - + ]: 3216 : if (group_id >= SPDK_TRACE_MAX_GROUP_ID) {
50 : 0 : SPDK_ERRLOG("invalid group ID %d\n", group_id);
51 : 0 : return;
52 : : }
53 : :
54 : 3216 : g_trace_file->tpoint_mask[group_id] |= tpoint_mask;
55 : : }
56 : :
57 : : void
58 : 0 : spdk_trace_clear_tpoints(uint32_t group_id, uint64_t tpoint_mask)
59 : : {
60 [ # # ]: 0 : if (g_trace_file == NULL) {
61 : 0 : SPDK_ERRLOG("trace is not initialized\n");
62 : 0 : return;
63 : : }
64 : :
65 [ # # ]: 0 : if (group_id >= SPDK_TRACE_MAX_GROUP_ID) {
66 : 0 : SPDK_ERRLOG("invalid group ID %d\n", group_id);
67 : 0 : return;
68 : : }
69 : :
70 : 0 : g_trace_file->tpoint_mask[group_id] &= ~tpoint_mask;
71 : : }
72 : :
73 : : uint64_t
74 : 18 : spdk_trace_get_tpoint_group_mask(void)
75 : : {
76 : 18 : uint64_t mask = 0x0;
77 : : int i;
78 : :
79 [ + + ]: 306 : for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) {
80 [ + + ]: 288 : if (spdk_trace_get_tpoint_mask(i) != 0) {
81 [ - + ]: 18 : mask |= (1ULL << i);
82 : : }
83 : : }
84 : :
85 : 18 : return mask;
86 : : }
87 : :
88 : : void
89 : 0 : spdk_trace_set_tpoint_group_mask(uint64_t tpoint_group_mask)
90 : : {
91 : : int i;
92 : :
93 [ # # ]: 0 : if (g_trace_file == NULL) {
94 : 0 : SPDK_ERRLOG("trace is not initialized\n");
95 : 0 : return;
96 : : }
97 : :
98 [ # # ]: 0 : for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) {
99 [ # # # # ]: 0 : if (tpoint_group_mask & (1ULL << i)) {
100 : 0 : spdk_trace_set_tpoints(i, -1ULL);
101 : : }
102 : : }
103 : : }
104 : :
105 : : void
106 : 0 : spdk_trace_clear_tpoint_group_mask(uint64_t tpoint_group_mask)
107 : : {
108 : : int i;
109 : :
110 [ # # ]: 0 : if (g_trace_file == NULL) {
111 : 0 : SPDK_ERRLOG("trace is not initialized\n");
112 : 0 : return;
113 : : }
114 : :
115 [ # # ]: 0 : for (i = 0; i < SPDK_TRACE_MAX_GROUP_ID; i++) {
116 [ # # # # ]: 0 : if (tpoint_group_mask & (1ULL << i)) {
117 : 0 : spdk_trace_clear_tpoints(i, -1ULL);
118 : : }
119 : : }
120 : : }
121 : :
122 : : struct spdk_trace_register_fn *
123 : 39 : spdk_trace_get_first_register_fn(void)
124 : : {
125 : 39 : return g_reg_fn_head;
126 : : }
127 : :
128 : : struct spdk_trace_register_fn *
129 : 314 : spdk_trace_get_next_register_fn(struct spdk_trace_register_fn *register_fn)
130 : : {
131 : 314 : return register_fn->next;
132 : : }
133 : :
134 : : uint64_t
135 : 21 : spdk_trace_create_tpoint_group_mask(const char *group_name)
136 : : {
137 : 21 : uint64_t tpoint_group_mask = 0;
138 : : struct spdk_trace_register_fn *register_fn;
139 : :
140 : 21 : register_fn = spdk_trace_get_first_register_fn();
141 [ - + + + ]: 21 : if (strcmp(group_name, "all") == 0) {
142 [ + + ]: 26 : while (register_fn) {
143 [ - + ]: 24 : tpoint_group_mask |= (1UL << register_fn->tgroup_id);
144 : :
145 : 24 : register_fn = spdk_trace_get_next_register_fn(register_fn);
146 : : }
147 : : } else {
148 [ + - ]: 57 : while (register_fn) {
149 [ + + - + : 57 : if (strcmp(group_name, register_fn->name) == 0) {
+ + ]
150 : 19 : break;
151 : : }
152 : :
153 : 38 : register_fn = spdk_trace_get_next_register_fn(register_fn);
154 : : }
155 : :
156 [ + - ]: 19 : if (register_fn != NULL) {
157 [ - + ]: 19 : tpoint_group_mask |= (1UL << register_fn->tgroup_id);
158 : : }
159 : : }
160 : :
161 : 21 : return tpoint_group_mask;
162 : : }
163 : :
164 : : int
165 : 0 : spdk_trace_enable_tpoint_group(const char *group_name)
166 : : {
167 : 0 : uint64_t tpoint_group_mask = 0;
168 : :
169 [ # # ]: 0 : if (g_trace_file == NULL) {
170 : 0 : return -1;
171 : : }
172 : :
173 : 0 : tpoint_group_mask = spdk_trace_create_tpoint_group_mask(group_name);
174 [ # # ]: 0 : if (tpoint_group_mask == 0) {
175 : 0 : return -1;
176 : : }
177 : :
178 : 0 : spdk_trace_set_tpoint_group_mask(tpoint_group_mask);
179 : 0 : return 0;
180 : : }
181 : :
182 : : int
183 : 0 : spdk_trace_disable_tpoint_group(const char *group_name)
184 : : {
185 : 0 : uint64_t tpoint_group_mask = 0;
186 : :
187 [ # # ]: 0 : if (g_trace_file == NULL) {
188 : 0 : return -1;
189 : : }
190 : :
191 : 0 : tpoint_group_mask = spdk_trace_create_tpoint_group_mask(group_name);
192 [ # # ]: 0 : if (tpoint_group_mask == 0) {
193 : 0 : return -1;
194 : : }
195 : :
196 : 0 : spdk_trace_clear_tpoint_group_mask(tpoint_group_mask);
197 : 0 : return 0;
198 : : }
199 : :
200 : : void
201 : 35 : spdk_trace_mask_usage(FILE *f, const char *tmask_arg)
202 : : {
203 : : #define LINE_PREFIX " "
204 : : #define ENTRY_SEPARATOR ", "
205 : : #define MAX_LINE_LENGTH 100
206 : 35 : uint64_t prefix_len = strlen(LINE_PREFIX);
207 : 35 : uint64_t separator_len = strlen(ENTRY_SEPARATOR);
208 : 35 : const char *first_entry = "group_name - tracepoint group name for spdk trace buffers (";
209 : 35 : const char *last_entry = "all).";
210 : : uint64_t curr_line_len;
211 : : uint64_t curr_entry_len;
212 : : struct spdk_trace_register_fn *register_fn;
213 : :
214 [ - + ]: 35 : fprintf(f, " %s, --tpoint-group <group-name>[:<tpoint_mask>]\n", tmask_arg);
215 [ - + ]: 35 : fprintf(f, "%s%s", LINE_PREFIX, first_entry);
216 [ - + ]: 35 : curr_line_len = prefix_len + strlen(first_entry);
217 : :
218 : 35 : register_fn = g_reg_fn_head;
219 [ + - ]: 146 : while (register_fn) {
220 [ - + ]: 146 : curr_entry_len = strlen(register_fn->name);
221 [ + + ]: 146 : if ((curr_line_len + curr_entry_len + separator_len > MAX_LINE_LENGTH)) {
222 [ - + ]: 26 : fprintf(f, "\n%s", LINE_PREFIX);
223 : 26 : curr_line_len = prefix_len;
224 : : }
225 : :
226 [ - + ]: 146 : fprintf(f, "%s%s", register_fn->name, ENTRY_SEPARATOR);
227 : 146 : curr_line_len += curr_entry_len + separator_len;
228 : :
229 [ + + ]: 146 : if (register_fn->next == NULL) {
230 [ - + + + ]: 35 : if (curr_line_len + strlen(last_entry) > MAX_LINE_LENGTH) {
231 [ - + ]: 3 : fprintf(f, " ");
232 : : }
233 [ - + ]: 35 : fprintf(f, "%s\n", last_entry);
234 : 35 : break;
235 : : }
236 : :
237 : 111 : register_fn = register_fn->next;
238 : : }
239 : :
240 [ - + ]: 35 : fprintf(f, "%stpoint_mask - tracepoint mask for enabling individual tpoints inside\n",
241 : : LINE_PREFIX);
242 [ - + ]: 35 : fprintf(f, "%sa tracepoint group. First tpoint inside a group can be enabled by\n",
243 : : LINE_PREFIX);
244 [ - + ]: 35 : fprintf(f, "%ssetting tpoint_mask to 1 (e.g. bdev:0x1). Groups and masks can be\n",
245 : : LINE_PREFIX);
246 [ - + ]: 35 : fprintf(f, "%scombined (e.g. thread,bdev:0x1). All available tpoints can be found\n",
247 : : LINE_PREFIX);
248 [ - + ]: 35 : fprintf(f, "%sin /include/spdk_internal/trace_defs.h\n", LINE_PREFIX);
249 : 35 : }
250 : :
251 : : void
252 : 11980 : spdk_trace_register_owner_type(uint8_t type, char id_prefix)
253 : : {
254 : : struct spdk_trace_owner_type *owner_type;
255 : :
256 [ - + ]: 11980 : assert(type != OWNER_TYPE_NONE);
257 : :
258 [ - + ]: 11980 : if (g_trace_file == NULL) {
259 : 0 : SPDK_ERRLOG("trace is not initialized\n");
260 : 0 : return;
261 : : }
262 : :
263 : : /* 'owner_type' has 256 entries and since 'type' is a uint8_t, it
264 : : * can't overrun the array.
265 : : */
266 : 11980 : owner_type = &g_trace_file->owner_type[type];
267 [ - + ]: 11980 : assert(owner_type->type == 0);
268 : :
269 : 11980 : owner_type->type = type;
270 : 11980 : owner_type->id_prefix = id_prefix;
271 : : }
272 : :
273 : : static void
274 : 16597 : _owner_set_description(uint16_t owner_id, const char *description, bool append)
275 : : {
276 : : struct spdk_trace_owner *owner;
277 : 16597 : char old[256] = {};
278 : :
279 [ - + ]: 16597 : assert(sizeof(old) >= g_trace_file->owner_description_size);
280 : 16597 : owner = spdk_get_trace_owner(g_trace_file, owner_id);
281 [ - + ]: 16597 : assert(owner != NULL);
282 [ + + ]: 16597 : if (append) {
283 [ - + - + ]: 4854 : memcpy(old, owner->description, g_trace_file->owner_description_size);
284 : : }
285 : :
286 [ + + - + ]: 16597 : snprintf(owner->description, g_trace_file->owner_description_size,
287 : : "%s%s%s", old, append ? " " : "", description);
288 : 16597 : }
289 : :
290 : : uint16_t
291 : 12471 : spdk_trace_register_owner(uint8_t owner_type, const char *description)
292 : : {
293 : : struct spdk_trace_owner *owner;
294 : : uint32_t owner_id;
295 : :
296 [ + + ]: 12471 : if (g_owner_ids.ring == NULL) {
297 : : /* Help the unit test environment by simply returning instead
298 : : * of requiring it to initialize the trace library.
299 : : */
300 : 728 : return 0;
301 : : }
302 : :
303 [ - + ]: 11743 : pthread_spin_lock(&g_owner_ids.lock);
304 : :
305 [ - + ]: 11743 : if (g_owner_ids.head == g_owner_ids.tail) {
306 : : /* No owner ids available. Return 0 which means no owner. */
307 [ # # ]: 0 : pthread_spin_unlock(&g_owner_ids.lock);
308 : 0 : return 0;
309 : : }
310 : :
311 : 11743 : owner_id = g_owner_ids.ring[g_owner_ids.head];
312 [ - + ]: 11743 : if (++g_owner_ids.head == g_owner_ids.size) {
313 : 0 : g_owner_ids.head = 0;
314 : : }
315 : :
316 : 11743 : owner = spdk_get_trace_owner(g_trace_file, owner_id);
317 : 11743 : owner->tsc = spdk_get_ticks();
318 : 11743 : owner->type = owner_type;
319 : 11743 : _owner_set_description(owner_id, description, false);
320 [ - + ]: 11743 : pthread_spin_unlock(&g_owner_ids.lock);
321 : 11743 : return owner_id;
322 : : }
323 : :
324 : : void
325 : 11923 : spdk_trace_unregister_owner(uint16_t owner_id)
326 : : {
327 [ + + ]: 11923 : if (g_owner_ids.ring == NULL) {
328 : : /* Help the unit test environment by simply returning instead
329 : : * of requiring it to initialize the trace library.
330 : : */
331 : 731 : return;
332 : : }
333 : :
334 [ - + ]: 11192 : if (owner_id == 0) {
335 : : /* owner_id 0 means no owner. Allow this to be passed here, it
336 : : * avoids caller having to do extra checking.
337 : : */
338 : 0 : return;
339 : : }
340 : :
341 [ - + ]: 11192 : pthread_spin_lock(&g_owner_ids.lock);
342 : 11192 : g_owner_ids.ring[g_owner_ids.tail] = owner_id;
343 [ + + ]: 11192 : if (++g_owner_ids.tail == g_owner_ids.size) {
344 : 2 : g_owner_ids.tail = 0;
345 : : }
346 [ - + ]: 11192 : pthread_spin_unlock(&g_owner_ids.lock);
347 : : }
348 : :
349 : : void
350 : 0 : spdk_trace_owner_set_description(uint16_t owner_id, const char *description)
351 : : {
352 [ # # ]: 0 : if (g_owner_ids.ring == NULL) {
353 : : /* Help the unit test environment by simply returning instead
354 : : * of requiring it to initialize the trace library.
355 : : */
356 : 0 : return;
357 : : }
358 : :
359 [ # # ]: 0 : pthread_spin_lock(&g_owner_ids.lock);
360 : 0 : _owner_set_description(owner_id, description, false);
361 [ # # ]: 0 : pthread_spin_unlock(&g_owner_ids.lock);
362 : : }
363 : :
364 : : void
365 : 6402 : spdk_trace_owner_append_description(uint16_t owner_id, const char *description)
366 : : {
367 [ + + ]: 6402 : if (g_owner_ids.ring == NULL) {
368 : : /* Help the unit test environment by simply returning instead
369 : : * of requiring it to initialize the trace library.
370 : : */
371 : 30 : return;
372 : : }
373 : :
374 [ + + ]: 6372 : if (owner_id == 0) {
375 : : /* owner_id 0 means no owner. Allow this to be passed here, it
376 : : * avoids caller having to do extra checking.
377 : : */
378 : 1518 : return;
379 : : }
380 : :
381 [ - + ]: 4854 : pthread_spin_lock(&g_owner_ids.lock);
382 : 4854 : _owner_set_description(owner_id, description, true);
383 [ - + ]: 4854 : pthread_spin_unlock(&g_owner_ids.lock);
384 : : }
385 : :
386 : : void
387 : 12727 : spdk_trace_register_object(uint8_t type, char id_prefix)
388 : : {
389 : : struct spdk_trace_object *object;
390 : :
391 [ - + ]: 12727 : assert(type != OBJECT_NONE);
392 : :
393 [ - + ]: 12727 : if (g_trace_file == NULL) {
394 : 0 : SPDK_ERRLOG("trace is not initialized\n");
395 : 0 : return;
396 : : }
397 : :
398 : : /* 'object' has 256 entries and since 'type' is a uint8_t, it
399 : : * can't overrun the array.
400 : : */
401 : 12727 : object = &g_trace_file->object[type];
402 [ - + ]: 12727 : assert(object->type == 0);
403 : :
404 : 12727 : object->type = type;
405 : 12727 : object->id_prefix = id_prefix;
406 : : }
407 : :
408 : : static void
409 : 160766 : trace_register_description(const struct spdk_trace_tpoint_opts *opts)
410 : : {
411 : : struct spdk_trace_tpoint *tpoint;
412 : : size_t i, max_name_length;
413 : :
414 [ - + ]: 160766 : assert(opts->tpoint_id < SPDK_TRACE_MAX_TPOINT_ID);
415 : :
416 [ - + - + ]: 160766 : if (strnlen(opts->name, sizeof(tpoint->name)) == sizeof(tpoint->name)) {
417 : 0 : SPDK_ERRLOG("name (%s) too long\n", opts->name);
418 : : }
419 : :
420 : 160766 : tpoint = &g_trace_file->tpoint[opts->tpoint_id];
421 [ - + ]: 160766 : assert(tpoint->tpoint_id == 0);
422 : :
423 : 160766 : snprintf(tpoint->name, sizeof(tpoint->name), "%s", opts->name);
424 : 160766 : tpoint->tpoint_id = opts->tpoint_id;
425 : 160766 : tpoint->object_type = opts->object_type;
426 : 160766 : tpoint->owner_type = opts->owner_type;
427 : 160766 : tpoint->new_object = opts->new_object;
428 : :
429 : 160766 : max_name_length = sizeof(tpoint->args[0].name);
430 [ + - ]: 346715 : for (i = 0; i < SPDK_TRACE_MAX_ARGS_COUNT; ++i) {
431 [ + + + + ]: 346715 : if (!opts->args[i].name || opts->args[i].name[0] == '\0') {
432 : : break;
433 : : }
434 : :
435 [ + + - ]: 185949 : switch (opts->args[i].type) {
436 : 174231 : case SPDK_TRACE_ARG_TYPE_INT:
437 : : case SPDK_TRACE_ARG_TYPE_PTR:
438 : : /* The integers and pointers have to be exactly 4 or 8 bytes */
439 [ + + - + ]: 174231 : assert(opts->args[i].size == 4 || opts->args[i].size == 8);
440 : 174231 : break;
441 : 11718 : case SPDK_TRACE_ARG_TYPE_STR:
442 : : /* Strings need to have at least one byte for the NULL terminator */
443 [ - + ]: 11718 : assert(opts->args[i].size > 0);
444 : 11718 : break;
445 : 0 : default:
446 : 0 : assert(0 && "invalid trace argument type");
447 : : break;
448 : : }
449 : :
450 [ - + - + ]: 185949 : if (strnlen(opts->args[i].name, max_name_length) == max_name_length) {
451 : 0 : SPDK_ERRLOG("argument name (%s) is too long\n", opts->args[i].name);
452 : : }
453 : :
454 : 185949 : snprintf(tpoint->args[i].name, sizeof(tpoint->args[i].name),
455 : 165932 : "%s", opts->args[i].name);
456 : 185949 : tpoint->args[i].type = opts->args[i].type;
457 : 185949 : tpoint->args[i].size = opts->args[i].size;
458 : : }
459 : :
460 : 160766 : tpoint->num_args = i;
461 : 160766 : }
462 : :
463 : : void
464 : 131666 : spdk_trace_register_description_ext(const struct spdk_trace_tpoint_opts *opts, size_t num_opts)
465 : : {
466 : : size_t i;
467 : :
468 [ - + ]: 131666 : if (g_trace_file == NULL) {
469 : 0 : SPDK_ERRLOG("trace is not initialized\n");
470 : 0 : return;
471 : : }
472 : :
473 [ + + ]: 292432 : for (i = 0; i < num_opts; ++i) {
474 : 160766 : trace_register_description(&opts[i]);
475 : : }
476 : : }
477 : :
478 : : void
479 : 116490 : spdk_trace_register_description(const char *name, uint16_t tpoint_id, uint8_t owner_type,
480 : : uint8_t object_type, uint8_t new_object,
481 : : uint8_t arg1_type, const char *arg1_name)
482 : : {
483 : 116490 : struct spdk_trace_tpoint_opts opts = {
484 : : .name = name,
485 : : .tpoint_id = tpoint_id,
486 : : .owner_type = owner_type,
487 : : .object_type = object_type,
488 : : .new_object = new_object,
489 : : .args = {{
490 : : .name = arg1_name,
491 : : .type = arg1_type,
492 : : .size = sizeof(uint64_t)
493 : : }
494 : : }
495 : : };
496 : :
497 : 116490 : spdk_trace_register_description_ext(&opts, 1);
498 : 116490 : }
499 : :
500 : : void
501 : 24652 : spdk_trace_tpoint_register_relation(uint16_t tpoint_id, uint8_t object_type, uint8_t arg_index)
502 : : {
503 : : struct spdk_trace_tpoint *tpoint;
504 : : uint16_t i;
505 : :
506 [ - + ]: 24652 : assert(object_type != OBJECT_NONE);
507 [ - + ]: 24652 : assert(tpoint_id != OBJECT_NONE);
508 : :
509 [ - + ]: 24652 : if (g_trace_file == NULL) {
510 : 0 : SPDK_ERRLOG("trace is not initialized\n");
511 : 0 : return;
512 : : }
513 : :
514 : : /* We do not check whether a tpoint_id exists here, because
515 : : * there is no order in which trace definitions are registered.
516 : : * This way we can create relations between tpoint and objects
517 : : * that will be declared later. */
518 : 24652 : tpoint = &g_trace_file->tpoint[tpoint_id];
519 [ + - ]: 31759 : for (i = 0; i < SPDK_COUNTOF(tpoint->related_objects); ++i) {
520 [ + + ]: 31759 : if (tpoint->related_objects[i].object_type == OBJECT_NONE) {
521 : 24652 : tpoint->related_objects[i].object_type = object_type;
522 : 24652 : tpoint->related_objects[i].arg_index = arg_index;
523 : 24652 : return;
524 : : }
525 : : }
526 : 0 : SPDK_ERRLOG("Unable to register new relation for tpoint %" PRIu16 ", object %" PRIu8 "\n",
527 : : tpoint_id, object_type);
528 : : }
529 : :
530 : : void
531 : 27228 : spdk_trace_add_register_fn(struct spdk_trace_register_fn *reg_fn)
532 : : {
533 : : struct spdk_trace_register_fn *_reg_fn;
534 : :
535 [ - + ]: 27228 : if (reg_fn->name == NULL) {
536 : 0 : SPDK_ERRLOG("missing name for registering spdk trace tpoint group\n");
537 : 0 : assert(false);
538 : : return;
539 : : }
540 : :
541 [ - + - + ]: 27228 : if (strcmp(reg_fn->name, "all") == 0) {
542 : 0 : SPDK_ERRLOG("illegal name (%s) for tpoint group\n", reg_fn->name);
543 : 0 : assert(false);
544 : : return;
545 : : }
546 : :
547 : : /* Ensure that no trace point group IDs and names are ever duplicated */
548 [ + + ]: 159206 : for (_reg_fn = g_reg_fn_head; _reg_fn; _reg_fn = _reg_fn->next) {
549 [ - + ]: 131978 : if (reg_fn->tgroup_id == _reg_fn->tgroup_id) {
550 : 0 : SPDK_ERRLOG("group %d, %s has duplicate tgroup_id with %s\n",
551 : : reg_fn->tgroup_id, reg_fn->name, _reg_fn->name);
552 : 0 : assert(false);
553 : : return;
554 : : }
555 : :
556 [ - + - + : 131978 : if (strcmp(reg_fn->name, _reg_fn->name) == 0) {
- + ]
557 : 0 : SPDK_ERRLOG("name %s is duplicated between groups with ids %d and %d\n",
558 : : reg_fn->name, reg_fn->tgroup_id, _reg_fn->tgroup_id);
559 : 0 : assert(false);
560 : : return;
561 : : }
562 : : }
563 : :
564 : : /* Arrange trace registration in order on tgroup_id */
565 [ + + + + ]: 27228 : if (g_reg_fn_head == NULL || reg_fn->tgroup_id < g_reg_fn_head->tgroup_id) {
566 : 8925 : reg_fn->next = g_reg_fn_head;
567 : 8925 : g_reg_fn_head = reg_fn;
568 : 8925 : return;
569 : : }
570 : :
571 [ + - ]: 67161 : for (_reg_fn = g_reg_fn_head; _reg_fn; _reg_fn = _reg_fn->next) {
572 [ + + + + ]: 67161 : if (_reg_fn->next == NULL || reg_fn->tgroup_id < _reg_fn->next->tgroup_id) {
573 : 18303 : reg_fn->next = _reg_fn->next;
574 : 18303 : _reg_fn->next = reg_fn;
575 : 18303 : return;
576 : : }
577 : : }
578 : : }
579 : :
580 : : int
581 : 2554 : trace_flags_init(void)
582 : : {
583 : : struct spdk_trace_register_fn *reg_fn;
584 : : uint16_t i;
585 : : uint16_t owner_id_start;
586 : : int rc;
587 : :
588 : 2554 : reg_fn = g_reg_fn_head;
589 [ + + ]: 26417 : while (reg_fn) {
590 : 23863 : reg_fn->reg_fn();
591 : 23863 : reg_fn = reg_fn->next;
592 : : }
593 : :
594 : : /* We will not use owner_id 0, it will be reserved to mean "no owner".
595 : : * But for now, we will start with owner_id 256 instead of owner_id 1.
596 : : * This will account for some libraries and modules which pass a
597 : : * "poller_id" to spdk_trace_record() which is now an owner_id. Until
598 : : * all of those libraries and modules are converted, we will start
599 : : * owner_ids at 256 to avoid collisions.
600 : : */
601 : 2554 : owner_id_start = 256;
602 : 2554 : g_owner_ids.ring = calloc(g_trace_file->num_owners, sizeof(uint16_t));
603 [ - + ]: 2554 : if (g_owner_ids.ring == NULL) {
604 : 0 : SPDK_ERRLOG("could not allocate g_owner_ids.ring\n");
605 : 0 : return -ENOMEM;
606 : : }
607 : 2554 : g_owner_ids.head = 0;
608 : 2554 : g_owner_ids.tail = g_trace_file->num_owners - owner_id_start;
609 : 2554 : g_owner_ids.size = g_trace_file->num_owners;
610 [ + + ]: 41193465 : for (i = 0; i < g_owner_ids.tail; i++) {
611 : 41190910 : g_owner_ids.ring[i] = i + owner_id_start;
612 : : }
613 : :
614 [ - + ]: 2554 : rc = pthread_spin_init(&g_owner_ids.lock, PTHREAD_PROCESS_PRIVATE);
615 [ - + ]: 2554 : if (rc != 0) {
616 : 0 : free(g_owner_ids.ring);
617 : 0 : g_owner_ids.ring = NULL;
618 : : }
619 : :
620 : 2554 : return rc;
621 : : }
622 : :
623 : : void
624 : 2554 : trace_flags_fini(void)
625 : : {
626 [ - + ]: 2554 : if (g_owner_ids.ring == NULL) {
627 : 0 : return;
628 : : }
629 [ - + ]: 2554 : pthread_spin_destroy(&g_owner_ids.lock);
630 : 2554 : free(g_owner_ids.ring);
631 : 2554 : g_owner_ids.ring = NULL;
632 : : }
|