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