1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2015 Intel Corporation 3 */ 4 5 #ifndef LTHREAD_DIAG_H_ 6 #define LTHREAD_DIAG_H_ 7 8 #ifdef __cplusplus 9 extern "C" { 10 #endif 11 12 #include <stdint.h> 13 #include <inttypes.h> 14 15 #include <rte_log.h> 16 #include <rte_common.h> 17 18 #include "lthread_api.h" 19 #include "lthread_diag_api.h" 20 21 extern diag_callback diag_cb; 22 23 extern const char *diag_event_text[]; 24 extern uint64_t diag_mask; 25 26 /* max size of name strings */ 27 #define LT_MAX_NAME_SIZE 64 28 29 #if LTHREAD_DIAG 30 #define DISPLAY_OBJCACHE_QUEUES 1 31 32 /* 33 * Generate a diagnostic trace or event in the case where an object is created. 34 * 35 * The value returned by the callback is stored in the object. 36 * 37 * @ param obj 38 * pointer to the object that was created 39 * @ param ev 40 * the event code 41 * 42 */ 43 #define DIAG_CREATE_EVENT(obj, ev) do { \ 44 struct lthread *ct = RTE_PER_LCORE(this_sched)->current_lthread;\ 45 if ((BIT(ev) & diag_mask) && (ev < LT_DIAG_EVENT_MAX)) { \ 46 (obj)->diag_ref = (diag_cb)(rte_rdtsc(), \ 47 ct, \ 48 (ev), \ 49 0, \ 50 diag_event_text[(ev)], \ 51 (uint64_t)obj, \ 52 0); \ 53 } \ 54 } while (0) 55 56 /* 57 * Generate a diagnostic trace event. 58 * 59 * @ param obj 60 * pointer to the lthread, cond or mutex object 61 * @ param ev 62 * the event code 63 * @ param p1 64 * object specific value ( see lthread_diag_api.h ) 65 * @ param p2 66 * object specific value ( see lthread_diag_api.h ) 67 */ 68 #define DIAG_EVENT(obj, ev, p1, p2) do { \ 69 struct lthread *ct = RTE_PER_LCORE(this_sched)->current_lthread;\ 70 if ((BIT(ev) & diag_mask) && (ev < LT_DIAG_EVENT_MAX)) { \ 71 (diag_cb)(rte_rdtsc(), \ 72 ct, \ 73 ev, \ 74 (obj)->diag_ref, \ 75 diag_event_text[(ev)], \ 76 (uint64_t)(p1), \ 77 (uint64_t)(p2)); \ 78 } \ 79 } while (0) 80 81 #define DIAG_COUNT_DEFINE(x) rte_atomic64_t count_##x 82 #define DIAG_COUNT_INIT(o, x) rte_atomic64_init(&((o)->count_##x)) 83 #define DIAG_COUNT_INC(o, x) rte_atomic64_inc(&((o)->count_##x)) 84 #define DIAG_COUNT_DEC(o, x) rte_atomic64_dec(&((o)->count_##x)) 85 #define DIAG_COUNT(o, x) rte_atomic64_read(&((o)->count_##x)) 86 87 #define DIAG_USED 88 89 #else 90 91 /* no diagnostics configured */ 92 93 #define DISPLAY_OBJCACHE_QUEUES 0 94 95 #define DIAG_CREATE_EVENT(obj, ev) 96 #define DIAG_EVENT(obj, ev, p1, p) 97 98 #define DIAG_COUNT_DEFINE(x) 99 #define DIAG_COUNT_INIT(o, x) do {} while (0) 100 #define DIAG_COUNT_INC(o, x) do {} while (0) 101 #define DIAG_COUNT_DEC(o, x) do {} while (0) 102 #define DIAG_COUNT(o, x) 0 103 104 #define DIAG_USED __rte_unused 105 106 #endif /* LTHREAD_DIAG */ 107 108 #ifdef __cplusplus 109 } 110 #endif 111 112 #endif /* LTHREAD_DIAG_H_ */ 113