libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU mask with xc_cpumap_t instead of uint32_t
PATCH 1/1 libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU mask with xc_cpumap_t instead of uint32_t
We replace the implementation of xc_tbuf_set_cpu_mask with an xc_cpumap_t instead of a uint32_t. This means we can use an arbitrary bitmap without being limited to the 32-bits as previously we were. Furthermore since there is only one user of xc_tbuf_set_cpu_mask we just replace it and its user in one go.
We also add an macro which can be used by both libxc and xentrace.
And update the man page to describe this behavior.
--- tools/libxc/include/xenctrl.h | 7 ++- tools/libxc/xc_tbuf.c | 26 +++++++---- tools/xentrace/xentrace.8 | 3 ++ tools/xentrace/xentrace.c | 106 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 116 insertions(+), 26 deletions(-)
tools/libxc/include/xenctrl.h +6 -1
@@ -1534,6 +1534,11 @@ int xc_availheap(xc_interface *xch, int min_width, int max_width, int node,*/ /** +* Useful macro for converting byte arrays to bitmaps. +*/ +#define XC_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) + +/** * xc_tbuf_enable - enable tracing buffers * * @parm xch a handle to an open hypervisor interface
@@ -1574,7 +1579,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 (xc_interface *xch,xc_cpumap_t mask,int bits);int xc_tbuf_set_evt_mask (xc_interface *xch,uint32_t mask);
tools/libxc/xc_tbuf.c +16 -10
@@ -113,15 +113,23 @@ int xc_tbuf_disable(xc_interface *xch)return tbuf_enable (xch,0 ); } -int xc_tbuf_set_cpu_mask (xc_interface *xch,uint32_t mask) +int xc_tbuf_set_cpu_mask (xc_interface *xch,xc_cpumap_t mask,int bits) {DECLARE_SYSCTL ; -DECLARE_HYPERCALL_BUFFER (uint8_t, bytemap); +DECLARE_HYPERCALL_BOUNCE (mask,XC_DIV_ROUND_UP (bits,8 ),XC_HYPERCALL_BUFFER_BOUNCE_IN );int ret =-1 ; -uint64_t mask64 = mask; +int local_bits; - bytemap =xc_hypercall_buffer_alloc (xch, bytemap,sizeof (mask64)); -if ( bytemap ==NULL ) +if ( bits <=0 ) + goto out; + + local_bits =xc_get_max_cpus (xch); +if ( bits > local_bits ) + { +PERROR ("Wrong amount of bits supplied: %d > %d!\n" , bits, local_bits); + goto out; + } +if (xc_hypercall_bounce_pre (xch, mask) ) {PERROR ("Could not allocate memory for xc_tbuf_set_cpu_mask hypercall" ); goto out;
@@ -131,14 +139,12 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, uint32_t mask) sysctl.interface_version =XEN_SYSCTL_INTERFACE_VERSION ; sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_cpu_mask; -bitmap_64_to_byte (bytemap, &mask64,sizeof (mask64) *8 ); - -set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); - sysctl.u.tbuf_op.cpu_mask.nr_bits =sizeof (bytemap) *8 ; +set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, mask); + sysctl.u.tbuf_op.cpu_mask.nr_bits = bits; ret =do_sysctl (xch, &sysctl); -xc_hypercall_buffer_free (xch, bytemap); +xc_hypercall_bounce_post (xch, mask); out:return ret;
tools/xentrace/xentrace.8 +3 -0
@@ -38,6 +38,9 @@ for new data. .TP .B -c, --cpu-mask=c set bitmask of CPUs to trace. It is limited to 32-bits. +If not specified, the cpu-mask of all of the available CPUs will be +constructed. + .TP .B -e, --evt-mask=e set event capture mask. If not specified the TRC_ALL will be used.
tools/xentrace/xentrace.c +91 -15
151 lines not on this page · raw message
Signature · 1 line
2.1.0
Quoted 6 lines · Konrad Rzeszutek Wilk
tools/xentrace/xentrace.c +6
-0+static int parse_cpumask (const char *arg) +{ +xc_cpumap_t map; +uint32_t v, i; +int bits =0 ; +
tools/xentrace/xentrace.c static int parse_evtmask(char *arg) · line 970
Quoted 10 lines
tools/xentrace/xentrace.c +10
-0+ map =malloc (sizeof (uint32_t )); +if ( !map ) +return -ENOMEM ; + + v =argtol (arg,0 ); +for ( i =0 ; i <sizeof (uint32_t ) ; i++ ) + map[i] = (v >> (i *8 )) &0xff ; + +for ( i =0 ; v; v >>=1 ) + bits += v &1 ;
Uum, it looks like this is counting the 1-bits in v, not the total number of bist. So "0x8000" would finish with bits == 1 ; but we would this to finish with bits == 16, don't we?
Or am I confused?
-George
Konrad Rzeszutek Wilk
Acked-by Ian CampbellQuoted 13 lines · George Dunlap
Quoted 12 lines · Konrad Rzeszutek Wilk
(quoted diff) +12
-0+static int parse_cpumask(const char *arg) +{ + xc_cpumap_t map; + uint32_t v, i; + int bits = 0; + + map = malloc(sizeof(uint32_t)); + if ( !map ) + return -ENOMEM; + + v = argtol(arg, 0); + for ( i = 0; i < sizeof(uint32_t) ; i++ )
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ map[i] = (v >> (i * 8)) & 0xff; + + for ( i = 0; v; v >>= 1) + bits += v & 1;Uum, it looks like this is counting the 1-bits in v, not the total number of bist. So "
0x8000" would finish with bits == 1 ; but we would this to finish with bits == 16, don't we?
Duh!
It should be:
for ( bits = 0; v; v >>= 1 ) bits ++;
And the 'int bits = 0' can now be 'int bits'.
See patch:
Quoted 1 line
From
aa8a0ddc295161f55531c7f5ac643aadbfe70917Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <[email protected]>
Date: Fri, 20 Jun 2014 15:34:53 -0400
Subject: [PATCH] libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU mask
with xc_cpumap_t instead of uint32_t
We replace the implementation of xc_tbuf_set_cpu_mask with an xc_cpumap_t instead of a uint32_t. This means we can use an arbitrary bitmap without being limited to the 32-bits as previously we were. Furthermore since there is only one user of xc_tbuf_set_cpu_mask we just replace it and its user in one go.
We also add an macro which can be used by both libxc and xentrace.
And update the man page to describe this behavior.
[v2: Fix up the bit mask counting.
--- tools/libxc/include/xenctrl.h | 7 ++- tools/libxc/xc_tbuf.c | 26 +++++++---- tools/xentrace/xentrace.8 | 3 ++ tools/xentrace/xentrace.c | 106 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 116 insertions(+), 26 deletions(-)
tools/libxc/include/xenctrl.h +6 -1
@@ -1534,6 +1534,11 @@ int xc_availheap(xc_interface *xch, int min_width, int max_width, int node,*/ /** +* Useful macro for converting byte arrays to bitmaps. +*/ +#define XC_DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) + +/** * xc_tbuf_enable - enable tracing buffers * * @parm xch a handle to an open hypervisor interface
@@ -1574,7 +1579,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 (xc_interface *xch,xc_cpumap_t mask,int bits);int xc_tbuf_set_evt_mask (xc_interface *xch,uint32_t mask);
tools/libxc/xc_tbuf.c +16 -10
@@ -113,15 +113,23 @@ int xc_tbuf_disable(xc_interface *xch)return tbuf_enable (xch,0 ); } -int xc_tbuf_set_cpu_mask (xc_interface *xch,uint32_t mask) +int xc_tbuf_set_cpu_mask (xc_interface *xch,xc_cpumap_t mask,int bits) {DECLARE_SYSCTL ; -DECLARE_HYPERCALL_BUFFER (uint8_t, bytemap); +DECLARE_HYPERCALL_BOUNCE (mask,XC_DIV_ROUND_UP (bits,8 ),XC_HYPERCALL_BUFFER_BOUNCE_IN );int ret =-1 ; -uint64_t mask64 = mask; +int local_bits; - bytemap =xc_hypercall_buffer_alloc (xch, bytemap,sizeof (mask64)); -if ( bytemap ==NULL ) +if ( bits <=0 ) + goto out; + + local_bits =xc_get_max_cpus (xch); +if ( bits > local_bits ) + { +PERROR ("Wrong amount of bits supplied: %d > %d!\n" , bits, local_bits); + goto out; + } +if (xc_hypercall_bounce_pre (xch, mask) ) {PERROR ("Could not allocate memory for xc_tbuf_set_cpu_mask hypercall" ); goto out;
@@ -131,14 +139,12 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, uint32_t mask) sysctl.interface_version =XEN_SYSCTL_INTERFACE_VERSION ; sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_cpu_mask; -bitmap_64_to_byte (bytemap, &mask64,sizeof (mask64) *8 ); - -set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); - sysctl.u.tbuf_op.cpu_mask.nr_bits =sizeof (bytemap) *8 ; +set_xen_guest_handle (sysctl.u.tbuf_op.cpu_mask.bitmap, mask); + sysctl.u.tbuf_op.cpu_mask.nr_bits = bits; ret =do_sysctl (xch, &sysctl); -xc_hypercall_buffer_free (xch, bytemap); +xc_hypercall_bounce_post (xch, mask); out:return ret;
tools/xentrace/xentrace.8 +3 -0
@@ -38,6 +38,9 @@ for new data. .TP .B -c, --cpu-mask=c set bitmask of CPUs to trace. It is limited to 32-bits. +If not specified, the cpu-mask of all of the available CPUs will be +constructed. + .TP .B -e, --evt-mask=e set event capture mask. If not specified the TRC_ALL will be used.
tools/xentrace/xentrace.c +91 -15
151 lines not on this page · raw message
Signature · 1 line
2.1.0