[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v1 2/5] libxc/trace: Add xc_tbuf_set_cpu_mask_array a variant of xc_tbuf_set_cpu_mask (v3)
which uses an xc_cpumap_t instead of a uint32_t. This means we can use an arbitrary bitmap without being limited to the 32-bits the xc_tbuf_set_cpu_mask_array can only do. We also add an macro which can be used by both libxc and xentrace. Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx> [v2: Use DIV_ROUND_UP macro as suggested by Daniel] [v3: Use 'int' for bits instead of 'unsigned int' as spotted by Boris] --- tools/libxc/xc_bitops.h | 2 ++ tools/libxc/xc_tbuf.c | 40 ++++++++++++++++++++++++++++++++++++++++ tools/libxc/xenctrl.h | 1 + 3 files changed, 43 insertions(+) diff --git a/tools/libxc/xc_bitops.h b/tools/libxc/xc_bitops.h index d8e0c16..b8cf2bd 100644 --- a/tools/libxc/xc_bitops.h +++ b/tools/libxc/xc_bitops.h @@ -12,6 +12,8 @@ #define BITMAP_ENTRY(_nr,_bmap) ((_bmap))[(_nr)/BITS_PER_LONG] #define BITMAP_SHIFT(_nr) ((_nr) % BITS_PER_LONG) +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) + /* calculate required space for number of longs needed to hold nr_bits */ static inline int bitmap_size(int nr_bits) { diff --git a/tools/libxc/xc_tbuf.c b/tools/libxc/xc_tbuf.c index 4fb7bb1..efa8094 100644 --- a/tools/libxc/xc_tbuf.c +++ b/tools/libxc/xc_tbuf.c @@ -24,6 +24,7 @@ */ #include "xc_private.h" +#include "xc_bitops.h" #include <xen/trace.h> static int tbuf_enable(xc_interface *xch, int enable) @@ -143,6 +144,45 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, uint32_t mask) out: return ret; } +int xc_tbuf_set_cpu_mask_array(xc_interface *xch, xc_cpumap_t mask, int bits) +{ + DECLARE_SYSCTL; + DECLARE_HYPERCALL_BUFFER(uint8_t, bytemap); + int ret = -1; + int local_bits; + + if ( bits <= 0 ) + goto out; + + local_bits = xc_get_max_cpus(xch); + if ( bits > local_bits ) + { + PERROR("Wrong amount of bits supplied: %u, using %u\n", bits, local_bits); + bits = local_bits; + } + bytemap = xc_hypercall_buffer_alloc(xch, bytemap, DIV_ROUND_UP(bits, 8)); + if ( bytemap == NULL ) + { + PERROR("Could not allocate memory for xc_tbuf_set_cpu_mask_array hypercall"); + goto out; + } + + memcpy(bytemap, mask, DIV_ROUND_UP(bits, 8)); + + sysctl.cmd = XEN_SYSCTL_tbuf_op; + sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION; + sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_cpu_mask; + + set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); + sysctl.u.tbuf_op.cpu_mask.nr_bits = bits; + + ret = do_sysctl(xch, &sysctl); + + xc_hypercall_buffer_free(xch, bytemap); + + out: + return ret; +} int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask) { diff --git a/tools/libxc/xenctrl.h b/tools/libxc/xenctrl.h index 400f0df..df9eb46 100644 --- a/tools/libxc/xenctrl.h +++ b/tools/libxc/xenctrl.h @@ -1472,6 +1472,7 @@ int xc_tbuf_set_size(xc_interface *xch, unsigned long size); int xc_tbuf_get_size(xc_interface *xch, unsigned long *size); int xc_tbuf_set_cpu_mask(xc_interface *xch, uint32_t mask); +int xc_tbuf_set_cpu_mask_array(xc_interface *xch, xc_cpumap_t mask, int bits); int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask); -- 1.9.3 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |