ia64/xen-unstable

view xen/include/xen/trace.h @ 6538:84ee014ebd41

Merge xen-vtx-unstable.hg
author adsharma@los-vmm.sc.intel.com
date Wed Aug 17 12:34:38 2005 -0800 (2005-08-17)
parents 23979fb12c49 ca873c2f5ca2
children 99914b54f7bf
line source
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 * See also common/trace.c and the dom0 op in include/public/dom0_ops.h
21 */
23 #ifndef __XEN_TRACE_H__
24 #define __XEN_TRACE_H__
26 #ifdef TRACE_BUFFER
28 #include <asm/page.h>
29 #include <xen/types.h>
30 #include <xen/sched.h>
31 #include <asm/atomic.h>
32 #include <asm/current.h>
33 #include <asm/msr.h>
34 #include <public/dom0_ops.h>
35 #include <public/trace.h>
37 extern struct t_buf *t_bufs[];
38 extern int tb_init_done;
39 extern unsigned long tb_cpu_mask;
40 extern u32 tb_event_mask;
42 /* Used to initialise trace buffer functionality */
43 void init_trace_bufs(void);
45 /* used to retrieve the physical address of the trace buffers */
46 int tb_control(dom0_tbufcontrol_t *tbc);
48 /**
49 * trace - Enters a trace tuple into the trace buffer for the current CPU.
50 * @event: the event type being logged
51 * @d1...d5: the data items for the event being logged
52 *
53 * Logs a trace record into the appropriate buffer. Returns nonzero on
54 * failure, otherwise 0. Failure occurs only if the trace buffers are not yet
55 * initialised.
56 */
57 static inline int trace(u32 event, unsigned long d1, unsigned long d2,
58 unsigned long d3, unsigned long d4, unsigned long d5)
59 {
60 atomic_t old, new, seen;
61 struct t_buf *buf;
62 struct t_rec *rec;
64 if ( !tb_init_done )
65 return -1;
67 if ( (tb_event_mask & event) == 0 )
68 return 0;
70 /* match class */
71 if ( ((tb_event_mask >> TRC_CLS_SHIFT) & (event >> TRC_CLS_SHIFT)) == 0 )
72 return 0;
74 /* then match subclass */
75 if ( (((tb_event_mask >> TRC_SUBCLS_SHIFT) & 0xf )
76 & ((event >> TRC_SUBCLS_SHIFT) & 0xf )) == 0 )
77 return 0;
79 if ( (tb_cpu_mask & (1UL << smp_processor_id())) == 0 )
80 return 0;
82 buf = t_bufs[smp_processor_id()];
84 do
85 {
86 old = buf->rec_idx;
87 _atomic_set(new, (_atomic_read(old) + 1) % buf->rec_num);
88 seen = atomic_compareandswap(old, new, &buf->rec_idx);
89 }
90 while ( unlikely(_atomic_read(seen) != _atomic_read(old)) );
92 wmb();
94 rec = &buf->rec[_atomic_read(old)];
95 rdtscll(rec->cycles);
96 rec->event = event;
97 rec->data[0] = d1;
98 rec->data[1] = d2;
99 rec->data[2] = d3;
100 rec->data[3] = d4;
101 rec->data[4] = d5;
103 return 0;
104 }
106 /* Avoids troubling the caller with casting their arguments to a trace macro */
107 #define trace_do_casts(e,d1,d2,d3,d4,d5) \
108 trace(e, \
109 (unsigned long)d1, \
110 (unsigned long)d2, \
111 (unsigned long)d3, \
112 (unsigned long)d4, \
113 (unsigned long)d5)
115 /* Convenience macros for calling the trace function. */
116 #define TRACE_0D(event) trace_do_casts(event,0, 0, 0, 0, 0 )
117 #define TRACE_1D(event,d) trace_do_casts(event,d, 0, 0, 0, 0 )
118 #define TRACE_2D(event,d1,d2) trace_do_casts(event,d1,d2,0, 0, 0 )
119 #define TRACE_3D(event,d1,d2,d3) trace_do_casts(event,d1,d2,d3,0, 0 )
120 #define TRACE_4D(event,d1,d2,d3,d4) trace_do_casts(event,d1,d2,d3,d4,0 )
121 #define TRACE_5D(event,d1,d2,d3,d4,d5) trace_do_casts(event,d1,d2,d3,d4,d5)
123 #else
125 #define init_trace_bufs() ((void)0)
127 #define TRACE_0D(event) ((void)0)
128 #define TRACE_1D(event,d) ((void)0)
129 #define TRACE_2D(event,d1,d2) ((void)0)
130 #define TRACE_3D(event,d1,d2,d3) ((void)0)
131 #define TRACE_4D(event,d1,d2,d3,d4) ((void)0)
132 #define TRACE_5D(event,d1,d2,d3,d4,d5) ((void)0)
134 #endif /* TRACE_BUFFER */
136 #endif /* __XEN_TRACE_H__ */