1 /******************************************************************************
2  * include/xen/trace.h
3  *
4  * Xen Trace Buffer
5  *
6  * Copyright (C) 2003 by Intel Research Cambridge
7  *
8  * Author: Mark Williamson, mark.a.williamson@intel.com
9  * Date:   January 2004
10  *
11  * Copyright (C) 2005 Bin Ren
12  *
13  * The trace buffer code is designed to allow debugging traces of Xen to be
14  * generated on UP / SMP machines.  Each trace entry is timestamped so that
15  * it's possible to reconstruct a chronological record of trace events.
16  *
17  * Access to the trace buffers is via a dom0 hypervisor op and analysis of
18  * trace buffer contents can then be performed using a userland tool.
19  */
20 
21 #ifndef __XEN_TRACE_H__
22 #define __XEN_TRACE_H__
23 
24 /* Put 'tb_init_done' here because 'asm/trace.h' may use it */
25 #ifdef CONFIG_TRACEBUFFER
26 extern int tb_init_done;
27 #else
28 #define tb_init_done false
29 #endif
30 
31 #include <xen/types.h>
32 #include <public/sysctl.h>
33 #include <public/trace.h>
34 #include <asm/trace.h>
35 
36 #ifdef CONFIG_TRACEBUFFER
37 /* Used to initialise trace buffer functionality */
38 void init_trace_bufs(void);
39 
40 /* used to retrieve the physical address of the trace buffers */
41 int tb_control(struct xen_sysctl_tbuf_op *tbc);
42 
43 int trace_will_trace_event(u32 event);
44 
45 void __trace_var(uint32_t event, bool cycles, unsigned int extra, const void *);
46 
trace_var(uint32_t event,bool cycles,unsigned int extra,const void * extra_data)47 static inline void trace_var(uint32_t event, bool cycles, unsigned int extra,
48                              const void *extra_data)
49 {
50     if ( unlikely(tb_init_done) )
51         __trace_var(event, cycles, extra, extra_data);
52 }
53 
54 void __trace_hypercall(uint32_t event, unsigned long op,
55                        const xen_ulong_t *args);
56 
57 #else /* CONFIG_TRACEBUFFER */
58 
59 #include <xen/errno.h>
60 
init_trace_bufs(void)61 static inline void init_trace_bufs(void) {}
tb_control(struct xen_sysctl_tbuf_op * tbc)62 static inline int tb_control(struct xen_sysctl_tbuf_op *tbc)
63 {
64     return -ENOSYS;
65 }
66 
trace_will_trace_event(uint32_t event)67 static inline int trace_will_trace_event(uint32_t event)
68 {
69     return 0;
70 }
71 
trace_var(uint32_t event,bool cycles,unsigned int extra,const void * extra_data)72 static inline void trace_var(uint32_t event, bool cycles, unsigned int extra,
73                              const void *extra_data) {}
__trace_var(uint32_t event,bool cycles,unsigned int extra,const void * extra_data)74 static inline void __trace_var(uint32_t event, bool cycles, unsigned int extra,
75                                const void *extra_data) {}
__trace_hypercall(uint32_t event,unsigned long op,const xen_ulong_t * args)76 static inline void __trace_hypercall(uint32_t event, unsigned long op,
77                                      const xen_ulong_t *args) {}
78 #endif /* CONFIG_TRACEBUFFER */
79 
80 /* Convenience macros for calling the trace function. */
81 #define TRACE_0D(_e)                            \
82     do {                                        \
83         trace_var(_e, 1, 0, NULL);              \
84     } while ( 0 )
85 
86 /* Common helper for TRACE_{1..6}D() below. */
87 #define TRACE_varD(_e, ...)                             \
88     do {                                                \
89         if ( unlikely(tb_init_done) )                   \
90         {                                               \
91             uint32_t _d[] = { __VA_ARGS__ };            \
92             __trace_var(_e, true, sizeof(_d), _d);      \
93         }                                               \
94     } while ( 0 )
95 
96 #define TRACE_1D(_e, d1) \
97     TRACE_varD(_e, d1)
98 
99 #define TRACE_2D(_e, d1, d2) \
100     TRACE_varD(_e, d1, d2)
101 
102 #define TRACE_3D(_e, d1, d2, d3) \
103     TRACE_varD(_e, d1, d2, d3)
104 
105 #define TRACE_4D(_e, d1, d2, d3, d4) \
106     TRACE_varD(_e, d1, d2, d3, d4)
107 
108 #define TRACE_5D(_e, d1, d2, d3, d4, d5) \
109     TRACE_varD(_e, d1, d2, d3, d4, d5)
110 
111 #define TRACE_6D(_e, d1, d2, d3, d4, d5, d6) \
112     TRACE_varD(_e, d1, d2, d3, d4, d5, d6)
113 
114 #endif /* __XEN_TRACE_H__ */
115