debuggers.hg

view xen/common/trace.c @ 3349:c754bd0be650

bitkeeper revision 1.1159.1.496 (41c85faeMBUejFtICiJueb_Xdh8yJA)

Priv-op emulation in Xen, for RDMSR/WRMSR/WBINVD. Cleaned up Linux
a bit as a result.
author kaf24@scramble.cl.cam.ac.uk
date Tue Dec 21 17:38:54 2004 +0000 (2004-12-21)
parents b7f0cff13881
children b2fa96909734
line source
1 /******************************************************************************
2 * common/trace.c
3 *
4 * Xen Trace Buffer
5 *
6 * Copyright (C) 2004 by Intel Research Cambridge
7 *
8 * Author: Mark Williamson, mark.a.williamson@intel.com
9 * Date: January 2004
10 *
11 * The trace buffer code is designed to allow debugging traces of Xen to be
12 * generated on UP / SMP machines. Each trace entry is timestamped so that
13 * it's possible to reconstruct a chronological record of trace events.
14 *
15 * See also include/xen/trace.h and the dom0 op in
16 * include/public/dom0_ops.h
17 */
19 #include <xen/config.h>
20 #include <asm/types.h>
21 #include <asm/io.h>
22 #include <xen/lib.h>
23 #include <xen/sched.h>
24 #include <xen/slab.h>
25 #include <xen/smp.h>
26 #include <xen/trace.h>
27 #include <xen/errno.h>
28 #include <asm/atomic.h>
29 #include <public/dom0_ops.h>
31 extern unsigned int opt_tbuf_size;
33 /* Pointers to the meta-data objects for all system trace buffers */
34 struct t_buf *t_bufs[NR_CPUS];
36 /* a flag recording whether initialisation has been done */
37 int tb_init_done = 0;
39 /**
40 * init_trace_bufs - performs initialisation of the per-cpu trace buffers.
41 *
42 * This function is called at start of day in order to initialise the per-cpu
43 * trace buffers. The trace buffers are then available for debugging use, via
44 * the %TRACE_xD macros exported in <xen/trace.h>.
45 */
46 void init_trace_bufs(void)
47 {
48 int i, order;
49 unsigned long nr_pages;
50 char *rawbuf;
51 struct t_buf *buf;
53 if ( opt_tbuf_size == 0 )
54 {
55 printk("Xen trace buffers: disabled\n");
56 return;
57 }
59 nr_pages = smp_num_cpus * opt_tbuf_size;
60 order = get_order(nr_pages * PAGE_SIZE);
62 if ( (rawbuf = (char *)alloc_xenheap_pages(order)) == NULL )
63 {
64 printk("Xen trace buffers: memory allocation failed\n");
65 return;
66 }
68 /* Share pages so that xentrace can map them. */
70 for ( i = 0; i < nr_pages; i++ )
71 SHARE_PFN_WITH_DOMAIN(virt_to_page(rawbuf+(i*PAGE_SIZE)), dom0);
73 for ( i = 0; i < smp_num_cpus; i++ )
74 {
75 buf = t_bufs[i] = (struct t_buf *)&rawbuf[i*opt_tbuf_size*PAGE_SIZE];
77 /* For use in Xen. */
78 buf->vdata = (struct t_rec *)(buf+1);
79 buf->head_ptr = buf->vdata;
81 /* For use in user space. */
82 buf->data = __pa(buf->vdata);
83 buf->head = 0;
85 /* For use in both. */
86 buf->size = (opt_tbuf_size * PAGE_SIZE - sizeof(struct t_buf))
87 / sizeof(struct t_rec);
88 }
90 printk("Xen trace buffers: initialised\n");
92 wmb(); /* above must be visible before tb_init_done flag set */
94 tb_init_done = 1;
95 }
97 /**
98 * get_tb_info - get trace buffer details
99 * @st: a pointer to a dom0_gettbufs_t to be filled out
100 *
101 * Called by the %DOM0_GETTBUFS dom0 op to fetch the machine address of the
102 * trace buffers.
103 */
104 int get_tb_info(dom0_gettbufs_t *st)
105 {
106 if ( tb_init_done )
107 {
108 st->mach_addr = __pa(t_bufs[0]);
109 st->size = opt_tbuf_size * PAGE_SIZE;
111 return 0;
112 }
113 else
114 {
115 st->mach_addr = 0;
116 st->size = 0;
117 return -ENODATA;
118 }
119 }