Imported Upstream version 3.2.2
[debian/gnuradio] / gcell / ibm / sync / spu_source / trace_libsync.h
1 /* --------------------------------------------------------------  */
2 /* (C)Copyright 2007                                               */
3 /* International Business Machines Corporation                     */
4 /* All Rights Reserved.                                            */
5 /*                                                                 */
6 /* Redistribution and use in source and binary forms, with or      */
7 /* without modification, are permitted provided that the           */
8 /* following conditions are met:                                   */
9 /*                                                                 */
10 /* - Redistributions of source code must retain the above copyright*/
11 /*   notice, this list of conditions and the following disclaimer. */
12 /*                                                                 */
13 /* - Redistributions in binary form must reproduce the above       */
14 /*   copyright notice, this list of conditions and the following   */
15 /*   disclaimer in the documentation and/or other materials        */
16 /*   provided with the distribution.                               */
17 /*                                                                 */
18 /* - Neither the name of IBM Corporation nor the names of its      */
19 /*   contributors may be used to endorse or promote products       */
20 /*   derived from this software without specific prior written     */
21 /*   permission.                                                   */
22 /*                                                                 */
23 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND          */
24 /* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,     */
25 /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF        */
26 /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE        */
27 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR            */
28 /* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
29 /* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT    */
30 /* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;    */
31 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)        */
32 /* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN       */
33 /* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    */
34 /* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,  */
35 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              */
36 /* --------------------------------------------------------------  */
37 /* PROLOG END TAG zYx                                              */
38 #ifndef __LIBSYNC_SPU_TRACEHOOKS_H__
39 #define __LIBSYNC_SPU_TRACEHOOKS_H__
40
41 #ifdef LIBSYNC_TRACE
42
43 #include <trace_events.h>
44
45 /*
46  *  last parameter in the trace_even and trace_interval_entry call is
47  *   the stack level to report the PC in the trace record. so 0 means
48  *   the PC of the current frame, 1 means the PC of the caller, etc.
49  *   there's a dilemma here - these macros are included in the inline
50  *   _mutex calls which get called from the (created during build)
51  *   mutex functions in the mutex .c files. in that case, the level
52  *   should be 1 - we don't want the PC of where in the mutex function
53  *   the trace call is happening, we want the PC of whomever is calling
54  *   the mutex function.
55  *
56  *   but.. an app can call the inline functions - it can #include the
57  *   appropriate libsync mutex .h files, and call the inlined _mutex
58  *   function in their code. in that case, the appropriate level for the
59  *   trace calls would be 0 - the user would want to know where in their
60  *   code the call to the _mutex function is.
61  *
62  *   so, we'll assume _LEVEL of 0 which is what the inline funtions need.
63  *   when we build the files for libsync, we'll do a -D_LEVEL=1 
64  */
65 #ifndef _LEVEL
66 #define _LEVEL 0
67 #endif
68
69
70 #define TRACE_EVENT_MUTEX_INIT 0x0403
71
72 #define TRACE_MUTEX_INIT(lock) { \
73   trace_payload_t payload; \
74   payload.dword[0]=(unsigned long)lock; \
75   trace_event(TRACE_EVENT_MUTEX_INIT, 1, &payload, "Event=%d, lock=0x%x", _LEVEL); \
76 }
77
78 #define TRACE_EVENT_MUTEX_LOCK 0x0503
79
80 #define TRACE_MUTEX_LOCK_ENTRY(_INTERVAL) \
81 trace_interval_p _INTERVAL = trace_interval_entry(TRACE_EVENT_MUTEX_LOCK, _LEVEL)
82
83 #define TRACE_MUTEX_LOCK_EXIT(_INTERVAL,lock,miss) { \
84   trace_payload_t payload; \
85   payload.dword[0]=(unsigned long)lock; \
86   payload.word[2]=(unsigned int)miss; \
87   trace_interval_exit(_INTERVAL, 2,  &payload, "Event=%d, lock=0x%x, miss=0x%x"); \
88 }
89
90 #define TRACE_EVENT_MUTEX_TRYLOCK 0x0603
91
92 #define TRACE_MUTEX_TRYLOCK(lock,ret_val) { \
93   trace_payload_t payload; \
94   payload.dword[0]=(unsigned long)lock; \
95   payload.word[2]=(unsigned int)ret_val; \
96   trace_event(TRACE_EVENT_MUTEX_TRYLOCK, 2, &payload, "Event=%d, lock=0x%x, ret_val=0x%x", _LEVEL); \
97 }
98
99 #define TRACE_EVENT_MUTEX_UNLOCK 0x0703
100
101 #define TRACE_MUTEX_UNLOCK(lock) { \
102   trace_payload_t payload; \
103   payload.dword[0]=(unsigned long)lock; \
104   trace_event(TRACE_EVENT_MUTEX_UNLOCK, 1, &payload, "Event=%d, lock=0x%x", _LEVEL); \
105 }
106
107 #else /* LIBSYNC_TRACE */
108
109 #define TRACE_MUTEX_INIT(lock) 
110 #define TRACE_MUTEX_LOCK_ENTRY(_INTERVAL) 
111 #define TRACE_MUTEX_LOCK_EXIT(_INTERVAL,lock,miss)
112 #define TRACE_MUTEX_TRYLOCK(lock,ret_val)
113 #define TRACE_MUTEX_UNLOCK(lock) 
114
115 #endif /* LIBSYNC_TRACE */
116
117 #endif  /* __LIBSYNC_SPU_TRACEHOOKS_H__ */