3dce8e0eb9fa62b3c6bb5d0157816002280f3ed4
[deb_dpdk.git] / examples / performance-thread / common / lthread_diag.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015  Intel Corporation. All rights reserved.
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 #ifndef LTHREAD_DIAG_H_
35 #define LTHREAD_DIAG_H_
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 #include <stdint.h>
42 #include <inttypes.h>
43
44 #include <rte_log.h>
45 #include <rte_common.h>
46
47 #include "lthread_api.h"
48 #include "lthread_diag_api.h"
49
50 extern diag_callback diag_cb;
51
52 extern const char *diag_event_text[];
53 extern uint64_t diag_mask;
54
55 /* max size of name strings */
56 #define LT_MAX_NAME_SIZE 64
57
58 #if LTHREAD_DIAG
59 #define DISPLAY_OBJCACHE_QUEUES 1
60
61 /*
62  * Generate a diagnostic trace or event in the case where an object is created.
63  *
64  * The value returned by the callback is stored in the object.
65  *
66  * @ param obj
67  *  pointer to the object that was created
68  * @ param ev
69  *  the event code
70  *
71  */
72 #define DIAG_CREATE_EVENT(obj, ev) do {                                 \
73         struct lthread *ct = RTE_PER_LCORE(this_sched)->current_lthread;\
74         if ((BIT(ev) & diag_mask) && (ev < LT_DIAG_EVENT_MAX)) {        \
75                 (obj)->diag_ref = (diag_cb)(rte_rdtsc(),                \
76                                         ct,                             \
77                                         (ev),                           \
78                                         0,                              \
79                                         diag_event_text[(ev)],          \
80                                         (uint64_t)obj,                  \
81                                         0);                             \
82         }                                                               \
83 } while (0)
84
85 /*
86  * Generate a diagnostic trace event.
87  *
88  * @ param obj
89  *  pointer to the lthread, cond or mutex object
90  * @ param ev
91  *  the event code
92  * @ param p1
93  *  object specific value ( see lthread_diag_api.h )
94  * @ param p2
95  *  object specific value ( see lthread_diag_api.h )
96  */
97 #define DIAG_EVENT(obj, ev, p1, p2) do {                                \
98         struct lthread *ct = RTE_PER_LCORE(this_sched)->current_lthread;\
99         if ((BIT(ev) & diag_mask) && (ev < LT_DIAG_EVENT_MAX)) {        \
100                 (diag_cb)(rte_rdtsc(),                                  \
101                                 ct,                                     \
102                                 ev,                                     \
103                                 (obj)->diag_ref,                        \
104                                 diag_event_text[(ev)],                  \
105                                 (uint64_t)(p1),                         \
106                                 (uint64_t)(p2));                        \
107         }                                                               \
108 } while (0)
109
110 #define DIAG_COUNT_DEFINE(x) rte_atomic64_t count_##x
111 #define DIAG_COUNT_INIT(o, x) rte_atomic64_init(&((o)->count_##x))
112 #define DIAG_COUNT_INC(o, x) rte_atomic64_inc(&((o)->count_##x))
113 #define DIAG_COUNT_DEC(o, x) rte_atomic64_dec(&((o)->count_##x))
114 #define DIAG_COUNT(o, x) rte_atomic64_read(&((o)->count_##x))
115
116 #define DIAG_USED
117
118 #else
119
120 /* no diagnostics configured */
121
122 #define DISPLAY_OBJCACHE_QUEUES 0
123
124 #define DIAG_CREATE_EVENT(obj, ev)
125 #define DIAG_EVENT(obj, ev, p1, p)
126
127 #define DIAG_COUNT_DEFINE(x)
128 #define DIAG_COUNT_INIT(o, x) do {} while (0)
129 #define DIAG_COUNT_INC(o, x) do {} while (0)
130 #define DIAG_COUNT_DEC(o, x) do {} while (0)
131 #define DIAG_COUNT(o, x) 0
132
133 #define DIAG_USED __rte_unused
134
135 #endif                          /* LTHREAD_DIAG */
136
137 #ifdef __cplusplus
138 }
139 #endif
140
141 #endif                          /* LTHREAD_DIAG_H_ */