debuggers.hg

view tools/libxc/xc_tbuf.c @ 20968:4b2aa9c350e6

libxc: fix bug in xc_tbuf_get_size()

The size in pages of trace buffer should be t_info->tbuf_size
rather than t_info pages.

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Feb 10 13:30:16 2010 +0000 (2010-02-10)
parents 475f4323b86a
children 3ffdb094c2c0
line source
1 /******************************************************************************
2 * xc_tbuf.c
3 *
4 * API for manipulating and accessing trace buffer parameters
5 *
6 * Copyright (c) 2005, Rob Gardner
7 *
8 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
9 * Use is subject to license terms.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation, version 2 of the
14 * License.
15 */
17 #include "xc_private.h"
18 #include <xen/trace.h>
20 static int tbuf_enable(int xc_handle, int enable)
21 {
22 DECLARE_SYSCTL;
24 sysctl.cmd = XEN_SYSCTL_tbuf_op;
25 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
26 if (enable)
27 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_enable;
28 else
29 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_disable;
31 return xc_sysctl(xc_handle, &sysctl);
32 }
34 int xc_tbuf_set_size(int xc_handle, unsigned long size)
35 {
36 DECLARE_SYSCTL;
38 sysctl.cmd = XEN_SYSCTL_tbuf_op;
39 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
40 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_size;
41 sysctl.u.tbuf_op.size = size;
43 return xc_sysctl(xc_handle, &sysctl);
44 }
46 int xc_tbuf_get_size(int xc_handle, unsigned long *size)
47 {
48 struct t_info *t_info;
49 int rc;
50 DECLARE_SYSCTL;
52 sysctl.cmd = XEN_SYSCTL_tbuf_op;
53 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
54 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_get_info;
56 rc = xc_sysctl(xc_handle, &sysctl);
57 if ( rc != 0 )
58 return rc;
60 t_info = xc_map_foreign_range(xc_handle, DOMID_XEN,
61 sysctl.u.tbuf_op.size, PROT_READ | PROT_WRITE,
62 sysctl.u.tbuf_op.buffer_mfn);
64 if ( t_info == NULL || t_info->tbuf_size == 0 )
65 return -1;
67 *size = t_info->tbuf_size;
69 return 0;
70 }
72 int xc_tbuf_enable(int xc_handle, unsigned long pages, unsigned long *mfn,
73 unsigned long *size)
74 {
75 DECLARE_SYSCTL;
76 int rc;
78 /*
79 * Ignore errors (at least for now) as we get an error if size is already
80 * set (since trace buffers cannot be reallocated). If we really have no
81 * buffers at all then tbuf_enable() will fail, so this is safe.
82 */
83 (void)xc_tbuf_set_size(xc_handle, pages);
85 if ( tbuf_enable(xc_handle, 1) != 0 )
86 return -1;
88 sysctl.cmd = XEN_SYSCTL_tbuf_op;
89 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
90 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_get_info;
92 rc = xc_sysctl(xc_handle, &sysctl);
93 if ( rc == 0 )
94 {
95 *size = sysctl.u.tbuf_op.size;
96 *mfn = sysctl.u.tbuf_op.buffer_mfn;
97 }
99 return 0;
100 }
102 int xc_tbuf_disable(int xc_handle)
103 {
104 return tbuf_enable(xc_handle, 0);
105 }
107 int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
108 {
109 DECLARE_SYSCTL;
110 int ret = -1;
111 uint64_t mask64 = mask;
112 uint8_t bytemap[sizeof(mask64)];
114 sysctl.cmd = XEN_SYSCTL_tbuf_op;
115 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
116 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_cpu_mask;
118 bitmap_64_to_byte(bytemap, &mask64, sizeof (mask64) * 8);
120 set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap);
121 sysctl.u.tbuf_op.cpu_mask.nr_cpus = sizeof(bytemap) * 8;
123 if ( lock_pages(&bytemap, sizeof(bytemap)) != 0 )
124 {
125 PERROR("Could not lock memory for Xen hypercall");
126 goto out;
127 }
129 ret = do_sysctl(xc_handle, &sysctl);
131 unlock_pages(&bytemap, sizeof(bytemap));
133 out:
134 return ret;
135 }
137 int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask)
138 {
139 DECLARE_SYSCTL;
141 sysctl.cmd = XEN_SYSCTL_tbuf_op;
142 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
143 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_evt_mask;
144 sysctl.u.tbuf_op.evt_mask = mask;
146 return do_sysctl(xc_handle, &sysctl);
147 }