ia64/xen-unstable

view xen/common/trace.c @ 3368:7b517e31b8e4

bitkeeper revision 1.1159.170.77 (41d59bfcre8NxFXZIV6T50LQhiAhYQ)

Merge tempest.cl.cam.ac.uk:/auto/groups/xeno/BK/xen-2.0-testing.bk
into tempest.cl.cam.ac.uk:/local/scratch/smh22/testing/xen-2.0-testing.bk
author smh22@tempest.cl.cam.ac.uk
date Fri Dec 31 18:35:40 2004 +0000 (2004-12-31)
parents 60e5912b6b28 14b2b7a4615f
children 825be9fa1b66
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 <xen/init.h>
29 #include <asm/atomic.h>
30 #include <public/dom0_ops.h>
32 /* opt_tbuf_size: trace buffer size (in pages) */
33 static unsigned int opt_tbuf_size = 10;
34 integer_param("tbuf_size", opt_tbuf_size);
36 /* Pointers to the meta-data objects for all system trace buffers */
37 struct t_buf *t_bufs[NR_CPUS];
39 /* a flag recording whether initialisation has been done */
40 int tb_init_done = 0;
42 /**
43 * init_trace_bufs - performs initialisation of the per-cpu trace buffers.
44 *
45 * This function is called at start of day in order to initialise the per-cpu
46 * trace buffers. The trace buffers are then available for debugging use, via
47 * the %TRACE_xD macros exported in <xen/trace.h>.
48 */
49 void init_trace_bufs(void)
50 {
51 int i, order;
52 unsigned long nr_pages;
53 char *rawbuf;
54 struct t_buf *buf;
56 if ( opt_tbuf_size == 0 )
57 {
58 printk("Xen trace buffers: disabled\n");
59 return;
60 }
62 nr_pages = smp_num_cpus * opt_tbuf_size;
63 order = get_order(nr_pages * PAGE_SIZE);
65 if ( (rawbuf = (char *)alloc_xenheap_pages(order)) == NULL )
66 {
67 printk("Xen trace buffers: memory allocation failed\n");
68 return;
69 }
71 /* Share pages so that xentrace can map them. */
73 for ( i = 0; i < nr_pages; i++ )
74 SHARE_PFN_WITH_DOMAIN(virt_to_page(rawbuf+(i*PAGE_SIZE)), dom0);
76 for ( i = 0; i < smp_num_cpus; i++ )
77 {
78 buf = t_bufs[i] = (struct t_buf *)&rawbuf[i*opt_tbuf_size*PAGE_SIZE];
80 /* For use in Xen. */
81 buf->vdata = (struct t_rec *)(buf+1);
82 buf->head_ptr = buf->vdata;
84 /* For use in user space. */
85 buf->data = __pa(buf->vdata);
86 buf->head = 0;
88 /* For use in both. */
89 buf->size = (opt_tbuf_size * PAGE_SIZE - sizeof(struct t_buf))
90 / sizeof(struct t_rec);
91 }
93 printk("Xen trace buffers: initialised\n");
95 wmb(); /* above must be visible before tb_init_done flag set */
97 tb_init_done = 1;
98 }
100 /**
101 * get_tb_info - get trace buffer details
102 * @st: a pointer to a dom0_gettbufs_t to be filled out
103 *
104 * Called by the %DOM0_GETTBUFS dom0 op to fetch the machine address of the
105 * trace buffers.
106 */
107 int get_tb_info(dom0_gettbufs_t *st)
108 {
109 if ( tb_init_done )
110 {
111 st->mach_addr = __pa(t_bufs[0]);
112 st->size = opt_tbuf_size * PAGE_SIZE;
114 return 0;
115 }
116 else
117 {
118 st->mach_addr = 0;
119 st->size = 0;
120 return -ENODATA;
121 }
122 }