direct-io.hg

view tools/libxc/xc_tbuf.c @ 13504:1a45828882e9

[LIBXC] Handle trace-buffer cpumap endianness.
Original patch from Jimi Xenidis <jimix@watson.ibm.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Fri Jan 19 14:41:17 2007 +0000 (2007-01-19)
parents 58f28e00001e
children
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"
19 static int tbuf_enable(int xc_handle, int enable)
20 {
21 DECLARE_SYSCTL;
23 sysctl.cmd = XEN_SYSCTL_tbuf_op;
24 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
25 if (enable)
26 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_enable;
27 else
28 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_disable;
30 return xc_sysctl(xc_handle, &sysctl);
31 }
33 int xc_tbuf_set_size(int xc_handle, unsigned long size)
34 {
35 DECLARE_SYSCTL;
37 sysctl.cmd = XEN_SYSCTL_tbuf_op;
38 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
39 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_size;
40 sysctl.u.tbuf_op.size = size;
42 return xc_sysctl(xc_handle, &sysctl);
43 }
45 int xc_tbuf_get_size(int xc_handle, unsigned long *size)
46 {
47 int rc;
48 DECLARE_SYSCTL;
50 sysctl.cmd = XEN_SYSCTL_tbuf_op;
51 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
52 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_get_info;
54 rc = xc_sysctl(xc_handle, &sysctl);
55 if (rc == 0)
56 *size = sysctl.u.tbuf_op.size;
57 return rc;
58 }
60 int xc_tbuf_enable(int xc_handle, unsigned long pages, unsigned long *mfn,
61 unsigned long *size)
62 {
63 DECLARE_SYSCTL;
64 int rc;
66 /*
67 * Ignore errors (at least for now) as we get an error if size is already
68 * set (since trace buffers cannot be reallocated). If we really have no
69 * buffers at all then tbuf_enable() will fail, so this is safe.
70 */
71 (void)xc_tbuf_set_size(xc_handle, pages);
73 if ( tbuf_enable(xc_handle, 1) != 0 )
74 return -1;
76 sysctl.cmd = XEN_SYSCTL_tbuf_op;
77 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
78 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_get_info;
80 rc = xc_sysctl(xc_handle, &sysctl);
81 if ( rc == 0 )
82 {
83 *size = sysctl.u.tbuf_op.size;
84 *mfn = sysctl.u.tbuf_op.buffer_mfn;
85 }
87 return 0;
88 }
90 int xc_tbuf_disable(int xc_handle)
91 {
92 return tbuf_enable(xc_handle, 0);
93 }
95 int xc_tbuf_set_cpu_mask(int xc_handle, uint32_t mask)
96 {
97 DECLARE_SYSCTL;
98 int ret = -1;
99 uint64_t mask64 = mask;
100 uint8_t bytemap[sizeof(mask64)];
102 sysctl.cmd = XEN_SYSCTL_tbuf_op;
103 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
104 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_cpu_mask;
106 bitmap_64_to_byte(bytemap, &mask64, sizeof (mask64));
108 set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap);
109 sysctl.u.tbuf_op.cpu_mask.nr_cpus = sizeof(bytemap) * 8;
111 if ( lock_pages(&bytemap, sizeof(bytemap)) != 0 )
112 {
113 PERROR("Could not lock memory for Xen hypercall");
114 goto out;
115 }
117 ret = do_sysctl(xc_handle, &sysctl);
119 unlock_pages(&bytemap, sizeof(bytemap));
121 out:
122 return ret;
123 }
125 int xc_tbuf_set_evt_mask(int xc_handle, uint32_t mask)
126 {
127 DECLARE_SYSCTL;
129 sysctl.cmd = XEN_SYSCTL_tbuf_op;
130 sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
131 sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_evt_mask;
132 sysctl.u.tbuf_op.evt_mask = mask;
134 return do_sysctl(xc_handle, &sysctl);
135 }