* [PATCH v4.1] Support CPU list parsing in xentrace.
@ 2015-04-23 13:29 Konrad Rzeszutek Wilk
2015-04-23 13:29 ` [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc Konrad Rzeszutek Wilk
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-04-23 13:29 UTC (permalink / raw)
To: george.dunlap, ian.campbell, ian.jackson, wei.liu2, xen-devel
Hey George, Ian,
Ian: I copied your comment and stuffed it in, please Ack:
[PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu,
already Acked:
[PATCH v4.1 2/3] libxc/xentrace: Use xc_cpumap_t for
George: please review (it is unchanged since v4 posting):
[PATCH v4.1 3/3] xentrace: Implement cpu mask range parsing of human
Since v4 [http://lists.xen.org/archives/html/xen-devel/2015-04/msg00441.html]:
- Lifted comment from Ian about xc_cpumap.
- Added Ian's Ack on one patch.
Since v3 [http://lists.xen.org/archives/html/xen-devel/2015-03/msg02986.html]:
- Rebased code on George's patch.
- Added support for 'all' in CPU parsing.
In v2 [http://lists.xen.org/archives/html/xen-devel/2014-06/msg01835.html]:
- Redid the code per George's feedback.
- Expanded the xc_cpumap_* calls so that we have an 'setbit' variant.
The purpose of these patches is to allow users of xentrace to narrow
down a specific CPU without having to figure out a bit mask. They
fix the limitation of the bit mask which is it can only do up to 32-bits
- which on large machines (say 120CPUs), you can't selectively trace anything
past 32CPUs.
The code expands the -c parameter where you can do -c <starting cpu>-<end cpu>,
or -c <cpu1>,<cpu2>, or a combination of them, or "all". There is also the mode
of
automatic detection, such as: -c -,<cpu2> (so it will assume up to cpu2 - so
0,1, and 2 CPU), or the inverse: -c <cpu2>- (which will figure the max cpus and
do it from cpu2 up to maximum cpu).
This along with 'xl vcpu-list' makes it extremely easy to trace a specific
guest (if pinned).
You can still use the -c 0x<some hex value> option if you prefer.
The patches are also at my git tree:
git://xenbits.xen.org/people/konradwilk/xen.git xentrace.v4.1
tools/libxc/include/xenctrl.h | 11 ++-
tools/libxc/xc_misc.c | 26 ++++++
tools/libxc/xc_tbuf.c | 33 +++++--
tools/xentrace/xentrace.8 | 34 ++++++-
tools/xentrace/xentrace.c | 212 ++++++++++++++++++++++++++++++++++++++----
5 files changed, 285 insertions(+), 31 deletions(-)
George Dunlap (1):
libxc/xentrace: Use xc_cpumap_t for xc_tbuf_set_cpu_mask
Konrad Rzeszutek Wilk (2):
libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc.
xentrace: Implement cpu mask range parsing of human values (-c).
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc.
2015-04-23 13:29 [PATCH v4.1] Support CPU list parsing in xentrace Konrad Rzeszutek Wilk
@ 2015-04-23 13:29 ` Konrad Rzeszutek Wilk
2015-05-08 13:53 ` Ian Campbell
2015-04-23 13:29 ` [PATCH v4.1 2/3] libxc/xentrace: Use xc_cpumap_t for xc_tbuf_set_cpu_mask Konrad Rzeszutek Wilk
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-04-23 13:29 UTC (permalink / raw)
To: george.dunlap, ian.campbell, ian.jackson, wei.liu2, xen-devel
Cc: Konrad Rzeszutek Wilk
We export the xc_cpumap_alloc but not the bit operations.
One could include 'xc_bitops.h' but that is naughty - so instead
we just export the proper functions to do it on the xc_cpumap_t
typedef.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
----
v2: Use our own macro to make sure ARM is not affected negatively
v3: Lifted Ian's explanation.
---
tools/libxc/include/xenctrl.h | 9 +++++++++
tools/libxc/xc_misc.c | 26 ++++++++++++++++++++++++++
2 files changed, 35 insertions(+)
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 6994c51..2c17d78 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -395,6 +395,15 @@ int xc_get_cpumap_size(xc_interface *xch);
/* allocate a cpumap */
xc_cpumap_t xc_cpumap_alloc(xc_interface *xch);
+/* clear an CPU from the cpumap. */
+void xc_cpumap_clearcpu(int cpu, xc_cpumap_t map);
+
+/* set an CPU in the cpumap. */
+void xc_cpumap_setcpu(int cpu, xc_cpumap_t map);
+
+/* Test whether the CPU in cpumap is set. */
+int xc_cpumap_testcpu(int cpu, xc_cpumap_t map);
+
/*
* NODEMAP handling
*/
diff --git a/tools/libxc/xc_misc.c b/tools/libxc/xc_misc.c
index be68291..3a1784b 100644
--- a/tools/libxc/xc_misc.c
+++ b/tools/libxc/xc_misc.c
@@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "xc_bitops.h"
#include "xc_private.h"
#include <xen/hvm/hvm_op.h>
@@ -93,6 +94,31 @@ xc_cpumap_t xc_cpumap_alloc(xc_interface *xch)
return calloc(1, sz);
}
+/*
+ * xc_bitops.h has macros that do this as well - however they assume that
+ * the bitmask is word aligned but xc_cpumap_t is only guaranteed to be
+ * byte aligned and so we need byte versions for architectures which do
+ * not support misaligned accesses (which is basically everyone
+ * but x86, although even on x86 it can be inefficient).
+ */
+#define BITS_PER_CPUMAP(map) (sizeof(*map) * 8)
+#define CPUMAP_ENTRY(cpu, map) ((map))[(cpu) / BITS_PER_CPUMAP(map)]
+#define CPUMAP_SHIFT(cpu, map) ((cpu) % BITS_PER_CPUMAP(map))
+void xc_cpumap_clearcpu(int cpu, xc_cpumap_t map)
+{
+ CPUMAP_ENTRY(cpu, map) &= ~(1U << CPUMAP_SHIFT(cpu, map));
+}
+
+void xc_cpumap_setcpu(int cpu, xc_cpumap_t map)
+{
+ CPUMAP_ENTRY(cpu, map) |= (1U << CPUMAP_SHIFT(cpu, map));
+}
+
+int xc_cpumap_testcpu(int cpu, xc_cpumap_t map)
+{
+ return (CPUMAP_ENTRY(cpu, map) >> CPUMAP_SHIFT(cpu, map)) & 1;
+}
+
xc_nodemap_t xc_nodemap_alloc(xc_interface *xch)
{
int sz;
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4.1 2/3] libxc/xentrace: Use xc_cpumap_t for xc_tbuf_set_cpu_mask
2015-04-23 13:29 [PATCH v4.1] Support CPU list parsing in xentrace Konrad Rzeszutek Wilk
2015-04-23 13:29 ` [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc Konrad Rzeszutek Wilk
@ 2015-04-23 13:29 ` Konrad Rzeszutek Wilk
2015-04-23 13:29 ` [PATCH v4.1 3/3] xentrace: Implement cpu mask range parsing of human values (-c) Konrad Rzeszutek Wilk
2015-05-08 14:58 ` [PATCH v4.1] Support CPU list parsing in xentrace Ian Campbell
3 siblings, 0 replies; 7+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-04-23 13:29 UTC (permalink / raw)
To: george.dunlap, ian.campbell, ian.jackson, wei.liu2, xen-devel
Cc: Konrad Rzeszutek Wilk
From: George Dunlap <george.dunlap@eu.citrix.com>
xentrace is the only caller at the moment. Split the cpu and event
mask setting out into seperate functions, but leave the current limit
of 32 bits for masks passed in from the command-line.
Based on a patch from Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
tools/libxc/include/xenctrl.h | 2 +-
tools/libxc/xc_tbuf.c | 33 ++++++++++++++-------
tools/xentrace/xentrace.c | 68 ++++++++++++++++++++++++++++++++++++-------
3 files changed, 81 insertions(+), 22 deletions(-)
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 2c17d78..a6df95f 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -1588,7 +1588,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 xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask);
diff --git a/tools/libxc/xc_tbuf.c b/tools/libxc/xc_tbuf.c
index 8777492..a4de491 100644
--- a/tools/libxc/xc_tbuf.c
+++ b/tools/libxc/xc_tbuf.c
@@ -113,15 +113,30 @@ 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)
{
DECLARE_SYSCTL;
- DECLARE_HYPERCALL_BUFFER(uint8_t, bytemap);
+ DECLARE_HYPERCALL_BOUNCE(mask, 0, XC_HYPERCALL_BUFFER_BOUNCE_IN);
int ret = -1;
- uint64_t mask64 = mask;
+ int bits, cpusize;
- bytemap = xc_hypercall_buffer_alloc(xch, bytemap, sizeof(mask64));
- if ( bytemap == NULL )
+ cpusize = xc_get_cpumap_size(xch);
+ if (cpusize <= 0)
+ {
+ PERROR("Could not get number of cpus");
+ return -1;
+ }
+
+ HYPERCALL_BOUNCE_SET_SIZE(mask, cpusize);
+
+ bits = xc_get_max_cpus(xch);
+ if (bits <= 0)
+ {
+ PERROR("Could not get number of bits");
+ return -1;
+ }
+
+ if ( xc_hypercall_bounce_pre(xch, mask) )
{
PERROR("Could not allocate memory for xc_tbuf_set_cpu_mask hypercall");
goto out;
@@ -131,14 +146,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;
diff --git a/tools/xentrace/xentrace.c b/tools/xentrace/xentrace.c
index 8a38e32..8b40e88 100644
--- a/tools/xentrace/xentrace.c
+++ b/tools/xentrace/xentrace.c
@@ -521,23 +521,68 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
return &tbufs;
}
+void print_cpu_mask(xc_cpumap_t map)
+{
+ unsigned int v, had_printed = 0;
+ int i;
+
+ fprintf(stderr, "change cpumask to 0x");
+
+ for ( i = xc_get_cpumap_size(xc_handle); i >= 0; i-- )
+ {
+ v = map[i];
+ if ( v || had_printed || !i ) {
+ if (had_printed)
+ fprintf(stderr,"%02x", v);
+ else
+ fprintf(stderr,"%x", v);
+ had_printed = 1;
+ }
+ }
+ fprintf(stderr, "\n");
+}
+
+static void set_cpu_mask(uint32_t mask)
+{
+ int i, ret = 0;
+ xc_cpumap_t map;
+
+ map = xc_cpumap_alloc(xc_handle);
+ if ( !map )
+ goto out;
+
+ /*
+ * If mask is set, copy the bits out of it. This still works for
+ * systems with more than 32 cpus, as the shift will just shift
+ * mask down to zero.
+ */
+ for ( i = 0; i < xc_get_cpumap_size(xc_handle); i++ )
+ map[i] = (mask >> (i * 8)) & 0xff;
+
+ ret = xc_tbuf_set_cpu_mask(xc_handle, map);
+ if ( ret != 0 )
+ goto out;
+
+ print_cpu_mask(map);
+ free(map);
+ return;
+out:
+ PERROR("Failure to get trace buffer pointer from Xen and set the new mask");
+ exit(EXIT_FAILURE);
+}
+
/**
- * set_mask - set the cpu/event mask in HV
+ * set_mask - set the event mask in HV
* @mask: the new mask
* @type: the new mask type,0-event mask, 1-cpu mask
*
*/
-static void set_mask(uint32_t mask, int type)
+static void set_evt_mask(uint32_t mask)
{
int ret = 0;
- if (type == 1) {
- ret = xc_tbuf_set_cpu_mask(xc_handle, mask);
- fprintf(stderr, "change cpumask to 0x%x\n", mask);
- } else if (type == 0) {
- ret = xc_tbuf_set_evt_mask(xc_handle, mask);
- fprintf(stderr, "change evtmask to 0x%x\n", mask);
- }
+ ret = xc_tbuf_set_evt_mask(xc_handle, mask);
+ fprintf(stderr, "change evtmask to 0x%x\n", mask);
if ( ret != 0 )
{
@@ -1018,10 +1063,11 @@ int main(int argc, char **argv)
}
if ( opts.evt_mask != 0 )
- set_mask(opts.evt_mask, 0);
+ set_evt_mask(opts.evt_mask);
+
if ( opts.cpu_mask != 0 )
- set_mask(opts.cpu_mask, 1);
+ set_cpu_mask(opts.cpu_mask);
if ( opts.timeout != 0 )
alarm(opts.timeout);
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v4.1 3/3] xentrace: Implement cpu mask range parsing of human values (-c).
2015-04-23 13:29 [PATCH v4.1] Support CPU list parsing in xentrace Konrad Rzeszutek Wilk
2015-04-23 13:29 ` [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc Konrad Rzeszutek Wilk
2015-04-23 13:29 ` [PATCH v4.1 2/3] libxc/xentrace: Use xc_cpumap_t for xc_tbuf_set_cpu_mask Konrad Rzeszutek Wilk
@ 2015-04-23 13:29 ` Konrad Rzeszutek Wilk
2015-05-08 14:58 ` [PATCH v4.1] Support CPU list parsing in xentrace Ian Campbell
3 siblings, 0 replies; 7+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-04-23 13:29 UTC (permalink / raw)
To: george.dunlap, ian.campbell, ian.jackson, wei.liu2, xen-devel
Cc: Konrad Rzeszutek Wilk
Instead of just using -c 0x<some hex value> we can
also use: -c <starting cpu>-<end cpu>, -c <cpu1>,<cpu2>, or a
combination of them, or 'all' for all cpus.
This new format can include just singular CPUs: -c <cpu1>,
or ranges without an start or end (and xentrace will figure out
the values), such as: -c -<cpu2> (which will include cpu0, cpu1,
and cpu2) or -c <cpu2>- (which will include cpu2 and up to MAX_CPUS).
That should make it easier to trace the right CPU if
using this along with 'xl vcpu-list'.
The code has been lifted from the Linux kernel, see file
lib/bitmap.c, function __bitmap_parselist.
To make the old behavior and the new function work, we check
to see if the arguments have '0x' in them. If they do
we use the old style parsing (limited to 32 CPUs). If that
does not exist we use the new parsing.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
[v4: Fix per George's review]
[v4.0: Redo per George's review]
[v4.1: Fix above comment: s/v5/v4.0/]
---
tools/xentrace/xentrace.8 | 34 +++++++-
tools/xentrace/xentrace.c | 196 ++++++++++++++++++++++++++++++++++++++--------
2 files changed, 195 insertions(+), 35 deletions(-)
diff --git a/tools/xentrace/xentrace.8 b/tools/xentrace/xentrace.8
index ac18e9f..7b3172b 100644
--- a/tools/xentrace/xentrace.8
+++ b/tools/xentrace/xentrace.8
@@ -36,8 +36,38 @@ all new records to the output
set the time, p, (in milliseconds) to sleep between polling the buffers
for new data.
.TP
-.B -c, --cpu-mask=c
-set bitmask of CPUs to trace. It is limited to 32-bits.
+.B -c, --cpu-mask=[\fIc\fP|\fICPU-LIST\fP|\fIall\fP]
+This can be: a hex value (of the form 0xNNNN...), or a set of cpu
+ranges as described below, or the string \fIall\fP. Hex values are limited
+to 32 bits. If not specified, the cpu-mask as set during bootup will be
+constructed. If using the \fICPU-LIST\fP it expects decimal numbers, which
+may be specified as follows:
+
+.RS 4
+.ie n .IP """0-3""" 4
+.el .IP "``0-3''" 4
+.IX Item "0-3"
+Trace only on CPUs 0 through 3
+.ie n .IP """0,2,5-7""" 4
+.el .IP "``0,2,5-7''" 4
+.IX Item "0,2,5-7"
+Trace only on CPUs 0, 2, and 5 through 7.
+.ie n .IP """-3""" 4
+.el .IP "``-3''" 4
+.IX Item "-3"
+Trace only on CPUs 0 through 3
+.ie n .IP """-3,7""" 4
+.el .IP "``-3,7''" 4
+.IX Item "-3,7"
+Trace only on CPUs 0 through 3 and 7
+.ie n .IP """3-""" 4
+.el .IP "``3-''" 4
+.IX Item "-3-"
+Trace only on CPUs 3 up to maximum numbers of CPUs the host has.
+.RE
+.Sp
+
+If using \fIall\fP it will use all of the CPUs the host has.
.TP
.B -e, --evt-mask=e
set event capture mask. If not specified the TRC_ALL will be used.
diff --git a/tools/xentrace/xentrace.c b/tools/xentrace/xentrace.c
index 8b40e88..3db29e9 100644
--- a/tools/xentrace/xentrace.c
+++ b/tools/xentrace/xentrace.c
@@ -23,6 +23,7 @@
#include <string.h>
#include <getopt.h>
#include <assert.h>
+#include <ctype.h>
#include <sys/poll.h>
#include <sys/statvfs.h>
@@ -52,7 +53,7 @@ typedef struct settings_st {
char *outfile;
unsigned long poll_sleep; /* milliseconds to sleep between polls */
uint32_t evt_mask;
- uint32_t cpu_mask;
+ char *cpu_mask_str;
unsigned long tbuf_size;
unsigned long disk_rsvd;
unsigned long timeout;
@@ -542,33 +543,17 @@ void print_cpu_mask(xc_cpumap_t map)
fprintf(stderr, "\n");
}
-static void set_cpu_mask(uint32_t mask)
+static int set_cpu_mask(xc_cpumap_t map)
{
- int i, ret = 0;
- xc_cpumap_t map;
-
- map = xc_cpumap_alloc(xc_handle);
- if ( !map )
- goto out;
-
- /*
- * If mask is set, copy the bits out of it. This still works for
- * systems with more than 32 cpus, as the shift will just shift
- * mask down to zero.
- */
- for ( i = 0; i < xc_get_cpumap_size(xc_handle); i++ )
- map[i] = (mask >> (i * 8)) & 0xff;
-
- ret = xc_tbuf_set_cpu_mask(xc_handle, map);
- if ( ret != 0 )
- goto out;
+ int ret = xc_tbuf_set_cpu_mask(xc_handle, map);
- print_cpu_mask(map);
- free(map);
- return;
-out:
+ if ( ret == 0 )
+ {
+ print_cpu_mask(map);
+ return 0;
+ }
PERROR("Failure to get trace buffer pointer from Xen and set the new mask");
- exit(EXIT_FAILURE);
+ return EXIT_FAILURE;
}
/**
@@ -819,7 +804,8 @@ static void usage(void)
"Usage: xentrace [OPTION...] [output file]\n" \
"Tool to capture Xen trace buffer data\n" \
"\n" \
-" -c, --cpu-mask=c Set cpu-mask\n" \
+" -c, --cpu-mask=c Set cpu-mask, using either hex, CPU ranges, or\n" \
+" for all CPUs\n" \
" -e, --evt-mask=e Set evt-mask\n" \
" -s, --poll-sleep=p Set sleep time, p, in milliseconds between\n" \
" polling the trace buffer for new data\n" \
@@ -951,6 +937,149 @@ static int parse_evtmask(char *arg)
return 0;
}
+#define ZERO_DIGIT '0'
+
+static int parse_cpumask_range(const char *arg, xc_cpumap_t map)
+{
+ unsigned int a, b, buflen = strlen(arg);
+ int c, c_old, totaldigits, nmaskbits;
+ int in_range;
+ const char *s;
+
+ if ( !buflen )
+ {
+ fprintf(stderr, "Invalid option argument: %s\n", arg);
+ errno = EINVAL;
+ return EXIT_FAILURE;
+ }
+
+ nmaskbits = xc_get_max_cpus(xc_handle);
+ if ( nmaskbits <= 0 )
+ {
+ fprintf(stderr, "Failed to get max number of CPUs! rc: %d\n", nmaskbits);
+ return EXIT_FAILURE;
+ }
+
+ c = c_old = totaldigits = 0;
+ s = arg;
+ do {
+ in_range = 0;
+ a = b = 0;
+ /* The buflen can become zero in the '} while(..) below. */
+ while ( buflen )
+ {
+ c_old = c;
+ c = *s++;
+ buflen--;
+
+ if ( isspace(c) )
+ continue;
+
+ if ( totaldigits && c && isspace(c_old) )
+ {
+ fprintf(stderr, "No embedded whitespaces allowed in: %s\n", arg);
+ goto err_out;
+ }
+
+ /* A '\0' or a ',' signal the end of a cpu# or range */
+ if ( c == '\0' || c == ',' )
+ break;
+
+ if ( c == '-' )
+ {
+ if ( in_range )
+ goto err_out;
+ b = 0;
+ in_range = 1;
+ continue;
+ }
+ if ( !isdigit(c) )
+ {
+ fprintf(stderr, "Only digits allowed in: %s\n", arg);
+ goto err_out;
+ }
+ b = b * 10 + (c - ZERO_DIGIT);
+ if ( !in_range )
+ a = b;
+ totaldigits++;
+ }
+ /* Syntax: <digit>-[,] - expand to number of CPUs. */
+ if ( b == 0 && in_range && (c == '-' || c == ',') )
+ b = nmaskbits-1;
+
+ if ( !(a <= b) )
+ {
+ fprintf(stderr, "Wrong order of %d and %d\n", a, b);
+ goto err_out;
+ }
+ if ( b >= nmaskbits )
+ {
+ fprintf(stderr, "Specified higher value then there are CPUS!\n");
+ goto err_out;
+ }
+ while ( a <= b )
+ {
+ xc_cpumap_setcpu(a, map);
+ a++;
+ }
+ } while ( buflen && c == ',' );
+
+ return 0;
+ err_out:
+ errno = EINVAL;
+ return EXIT_FAILURE;
+}
+
+/**
+ * Figure out which of the CPU types the user has provided - either the hex
+ * variant, the cpu-list, or 'all'. Once done set the CPU mask.
+ */
+static int figure_cpu_mask(void)
+{
+ int i, ret = EXIT_FAILURE;
+ xc_cpumap_t map;
+
+ map = xc_cpumap_alloc(xc_handle);
+ if ( !map )
+ goto out;
+
+ if ( strlen(opts.cpu_mask_str) < 1 )
+ {
+ errno = ENOSPC;
+ goto out;
+ }
+
+ ret = 0;
+ if ( strncmp("0x", opts.cpu_mask_str, 2) == 0 )
+ {
+ uint32_t v;
+
+ v = argtol(opts.cpu_mask_str, 0);
+ /*
+ * If mask is set, copy the bits out of it. This still works for
+ * systems with more than 32 cpus, as the shift will just shift
+ * mask down to zero.
+ */
+ for ( i = 0; i < sizeof(uint32_t); i++ )
+ map[i] = (v >> (i * 8)) & 0xff;
+ }
+ else if ( strcmp("all", opts.cpu_mask_str) == 0 )
+ {
+ for ( i = 0; i < xc_get_cpumap_size(xc_handle); i++ )
+ map[i] = 0xff;
+ }
+ else
+ ret = parse_cpumask_range(opts.cpu_mask_str, map);
+
+ if ( !ret )
+ ret = set_cpu_mask(map);
+ out:
+ /* We don't use them pass this point. */
+ free(map);
+ free(opts.cpu_mask_str);
+ return ret;
+}
+
/* parse command line arguments */
static void parse_args(int argc, char **argv)
{
@@ -981,10 +1110,9 @@ static void parse_args(int argc, char **argv)
opts.poll_sleep = argtol(optarg, 0);
break;
- case 'c': /* set new cpu mask for filtering*/
- opts.cpu_mask = argtol(optarg, 0);
+ case 'c': /* set new cpu mask for filtering (when xch is set). */
+ opts.cpu_mask_str = strdup(optarg);
break;
-
case 'e': /* set new event mask for filtering*/
parse_evtmask(optarg);
break;
@@ -1047,7 +1175,7 @@ int main(int argc, char **argv)
opts.outfile = 0;
opts.poll_sleep = POLL_SLEEP_MILLIS;
opts.evt_mask = 0;
- opts.cpu_mask = 0;
+ opts.cpu_mask_str = NULL;
opts.disk_rsvd = 0;
opts.disable_tracing = 1;
opts.start_disabled = 0;
@@ -1065,9 +1193,11 @@ int main(int argc, char **argv)
if ( opts.evt_mask != 0 )
set_evt_mask(opts.evt_mask);
-
- if ( opts.cpu_mask != 0 )
- set_cpu_mask(opts.cpu_mask);
+ if ( opts.cpu_mask_str )
+ {
+ if ( figure_cpu_mask() )
+ exit(EXIT_FAILURE);
+ }
if ( opts.timeout != 0 )
alarm(opts.timeout);
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc.
2015-04-23 13:29 ` [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc Konrad Rzeszutek Wilk
@ 2015-05-08 13:53 ` Ian Campbell
0 siblings, 0 replies; 7+ messages in thread
From: Ian Campbell @ 2015-05-08 13:53 UTC (permalink / raw)
To: Konrad Rzeszutek Wilk; +Cc: george.dunlap, ian.jackson, wei.liu2, xen-devel
On Thu, 2015-04-23 at 09:29 -0400, Konrad Rzeszutek Wilk wrote:
> We export the xc_cpumap_alloc but not the bit operations.
> One could include 'xc_bitops.h' but that is naughty - so instead
> we just export the proper functions to do it on the xc_cpumap_t
> typedef.
>
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4.1] Support CPU list parsing in xentrace.
2015-04-23 13:29 [PATCH v4.1] Support CPU list parsing in xentrace Konrad Rzeszutek Wilk
` (2 preceding siblings ...)
2015-04-23 13:29 ` [PATCH v4.1 3/3] xentrace: Implement cpu mask range parsing of human values (-c) Konrad Rzeszutek Wilk
@ 2015-05-08 14:58 ` Ian Campbell
2015-05-11 14:18 ` Konrad Rzeszutek Wilk
3 siblings, 1 reply; 7+ messages in thread
From: Ian Campbell @ 2015-05-08 14:58 UTC (permalink / raw)
To: Konrad Rzeszutek Wilk; +Cc: george.dunlap, ian.jackson, wei.liu2, xen-devel
On Thu, 2015-04-23 at 09:29 -0400, Konrad Rzeszutek Wilk wrote:
> Hey George, Ian,
>
>
> Ian: I copied your comment and stuffed it in, please Ack:
> [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu,
>
> already Acked:
> [PATCH v4.1 2/3] libxc/xentrace: Use xc_cpumap_t for
Applied these two.
Last one is awaiting George's feedback.
Ian.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4.1] Support CPU list parsing in xentrace.
2015-05-08 14:58 ` [PATCH v4.1] Support CPU list parsing in xentrace Ian Campbell
@ 2015-05-11 14:18 ` Konrad Rzeszutek Wilk
0 siblings, 0 replies; 7+ messages in thread
From: Konrad Rzeszutek Wilk @ 2015-05-11 14:18 UTC (permalink / raw)
To: Ian Campbell; +Cc: george.dunlap, ian.jackson, wei.liu2, xen-devel
On Fri, May 08, 2015 at 03:58:50PM +0100, Ian Campbell wrote:
> On Thu, 2015-04-23 at 09:29 -0400, Konrad Rzeszutek Wilk wrote:
> > Hey George, Ian,
> >
> >
> > Ian: I copied your comment and stuffed it in, please Ack:
> > [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu,
> >
> > already Acked:
> > [PATCH v4.1 2/3] libxc/xentrace: Use xc_cpumap_t for
>
> Applied these two.
Thank you!
>
> Last one is awaiting George's feedback.
OK, he sent an re-worked patch that I hope to be able to look over this week.
>
> Ian.
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2015-05-11 14:18 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-23 13:29 [PATCH v4.1] Support CPU list parsing in xentrace Konrad Rzeszutek Wilk
2015-04-23 13:29 ` [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc Konrad Rzeszutek Wilk
2015-05-08 13:53 ` Ian Campbell
2015-04-23 13:29 ` [PATCH v4.1 2/3] libxc/xentrace: Use xc_cpumap_t for xc_tbuf_set_cpu_mask Konrad Rzeszutek Wilk
2015-04-23 13:29 ` [PATCH v4.1 3/3] xentrace: Implement cpu mask range parsing of human values (-c) Konrad Rzeszutek Wilk
2015-05-08 14:58 ` [PATCH v4.1] Support CPU list parsing in xentrace Ian Campbell
2015-05-11 14:18 ` Konrad Rzeszutek Wilk
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.