Skip to contentSkip to conversation

Support CPU-list parsing in xentrace.

PATCH Superseded Konrad Rzeszutek Wilk 4 participants 14 messages Jun 13, 2014 – Jun 18, 2014

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Support CPU-list parsing in xentrace.

Hey George, Ian:

Since v1 posting (http://comments.gmane.org/gmane.comp.emulators.xen.devel/201962)
I've incorporated all the feedback I've received. If I missed something - please remind me.

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. 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.

Comments:

[PATCH v2 1/4] xentrace: Use PERROR from xc_private. instead of our

is needed to use 'xc_private.h' instead of 'xc_bitops.h' in the xentrace.c file. However, the

[PATCH v2 2/4] libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU

still needs the 'xc_bitops.h' for bit manipulations so the initial goal of shuffling DIV_ROUND_UP to a different header had been meet - but we still need to include the other header.

[PATCH v2 3/4] libxc/tbuf: Use the xc_hypercall_bounce_[pre|post]

Can be squashed in the "2/4 libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU" if desired. However the 2/4 patch is busy enough that I was a bit uncomfortable to squash it myself. Naturally if the maintainers want it that way I will be thrilled to do it.

 tools/libxc/xc_private.h  |   2 +
 tools/libxc/xc_tbuf.c     |  28 +++--
 tools/libxc/xenctrl.h     |   2 +-
 tools/xentrace/xentrace.8 |  22 +++-
 tools/xentrace/xentrace.c | 266 ++++++++++++++++++++++++++++++++++++++++------
 5 files changed, 273 insertions(+), 47 deletions(-)

Konrad Rzeszutek Wilk (4):
xentrace: Use PERROR from xc_private. instead of our own.
libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU mask with xc_cpumap_t instead of uint32_t libxc/tbuf: Use the xc_hypercall_bounce_[pre|post] instead of memcpy
xentrace: Implement cpu mask range parsing of human values (-c).

#1 lore raw

PATCH v2 1/4 xentrace: Use PERROR from xc_private. instead of our own.

However, the xc_private PERROR uses 'xch' while we call said structure 'xc_handle' - so this patch also changes the variable to xch.

---
 tools/xentrace/xentrace.c |   28 ++++++++++------------------
 1 files changed, 10 insertions(+), 18 deletions(-)
tools/xentrace/xentrace.c +10 -18
index 8a38e32..16034e3 100644
@@ -30,15 +30,7 @@
 #include <xen/trace.h>
 
 #include <xenctrl.h>
-
-#define PERROR(_m, _a...)                                       \
-do {                                                            \
-    int __saved_errno = errno;                                  \
-    fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,       \
-            __saved_errno, strerror(__saved_errno));            \
-    errno = __saved_errno;                                      \
-} while (0)
-
+#include "xc_private.h"
 
 /***** Compile time configuration of defaults ********************************/
 
@@ -72,7 +64,7 @@ settings_t opts;
 
 int interrupted = 0; /* gets set if we get a SIGHUP */
 
-static xc_interface *xc_handle;
+static xc_interface *xch;
 static xc_evtchn *xce_handle = NULL;
 static int virq_port = -1;
 static int outfd = 1;
@@ -447,7 +439,7 @@ static void get_tbufs(unsigned long *mfn, unsigned long *size)
     if(!opts.tbuf_size)
       opts.tbuf_size = DEFAULT_TBUF_SIZE;
 
-    ret = xc_tbuf_enable(xc_handle, opts.tbuf_size, mfn, size);
+    ret = xc_tbuf_enable(xch, opts.tbuf_size, mfn, size);
 
     if ( ret != 0 )
     {
@@ -471,7 +463,7 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
     int i;
 
     /* Map t_info metadata structure */
-    tbufs.t_info = xc_map_foreign_range(xc_handle, DOMID_XEN, tinfo_size,
+    tbufs.t_info = xc_map_foreign_range(xch, DOMID_XEN, tinfo_size,
                                         PROT_READ, tbufs_mfn);
 
     if ( tbufs.t_info == 0 ) 
@@ -506,7 +498,7 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
         for ( j=0; j<tbufs.t_info->tbuf_size; j++)
             pfn_list[j] = (xen_pfn_t)mfn_list[j];
 
-        tbufs.meta[i] = xc_map_foreign_batch(xc_handle, DOMID_XEN,
+        tbufs.meta[i] = xc_map_foreign_batch(xch, DOMID_XEN,
                                              PROT_READ | PROT_WRITE,
                                              pfn_list,
                                              tbufs.t_info->tbuf_size);
@@ -532,10 +524,10 @@ static void set_mask(uint32_t mask, int type)
     int ret = 0;
 
     if (type == 1) {
-        ret = xc_tbuf_set_cpu_mask(xc_handle, mask);
+        ret = xc_tbuf_set_cpu_mask(xch, mask);
         fprintf(stderr, "change cpumask to 0x%x\n", mask);
     } else if (type == 0) {
-        ret = xc_tbuf_set_evt_mask(xc_handle, mask);
+        ret = xc_tbuf_set_evt_mask(xch, mask);
         fprintf(stderr, "change evtmask to 0x%x\n", mask);
     }
 
@@ -554,7 +546,7 @@ static unsigned int get_num_cpus(void)
     xc_physinfo_t physinfo = { 0 };
     int ret;
     
-    ret = xc_physinfo(xc_handle, &physinfo);
+    ret = xc_physinfo(xch, &physinfo);
     
     if ( ret != 0 )
     {
@@ -1010,8 +1002,8 @@ int main(int argc, char **argv)
 
     parse_args(argc, argv);
 
-    xc_handle = xc_interface_open(0,0,0);
-    if ( !xc_handle ) 
+    xch = xc_interface_open(0,0,0);
+    if ( !xch )
     {
         perror("xenctrl interface open");
         exit(EXIT_FAILURE);
Signature · 1 line
1.7.7.6
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] xentrace: Use PERROR from xc_private. instead of our own.

Quoted 5 lines · Konrad Rzeszutek Wilk

However, the xc_private PERROR uses 'xch' while we call said structure 'xc_handle' - so this patch also changes the variable to xch.

I wasn't sure whether "xc_private.h" was intended to be included by tools outside the libxc directory, but it seems to be included by xenpaging and a couple of random things inside tools/misc; so:

#3 lore raw

Re: [PATCH v2 1/4] xentrace: Use PERROR from xc_private. instead of our own.

Quoted 10 lines · George Dunlap
Quoted 5 lines · Konrad Rzeszutek Wilk

However, the xc_private PERROR uses 'xch' while we call said structure 'xc_handle' - so this patch also changes the variable to xch.

I wasn't sure whether "xc_private.h" was intended to be included by tools outside the libxc directory, but it seems to be included by xenpaging and a couple of random things inside tools/misc;

Despite this it's really not supposed to be used outside of libxc itself. We'd like to get rid of those included with time. Things outside of libxc itself should use the xtl_* interface I think.

Quoted 5 lines

so:

#4 lore raw

Re: [PATCH v2 1/4] xentrace: Use PERROR from xc_private. instead of our own.

In reply to George Dunlap
Quoted 5 lines · George Dunlap
Quoted 4 lines · Konrad Rzeszutek Wilk

However, the xc_private PERROR uses 'xch' while we call said structure 'xc_handle' - so this patch also changes the variable to xch.

Quoted 7 lines
Quoted 1 line

I wasn't sure whether "xc_private.h" was intended to be included by tools outside the libxc directory, but it seems to be included by xenpaging and a couple of random things inside tools/misc; so:

I disagree - xc_private.h is private to libxc and should not be used outside of tools/libxc/*

There are some naughty examples which should be fixed.

If there are bits in xc_private.h which are needed by outside programs, then they should move to xen{ctrl,guest}.h as appropriate.

~Andrew

#5 lore raw

Re: [PATCH v2 1/4] xentrace: Use PERROR from xc_private. instead of our own.

Quoted 14 lines · Andrew Cooper
Quoted 5 lines · George Dunlap
Quoted 4 lines · Konrad Rzeszutek Wilk

However, the xc_private PERROR uses 'xch' while we call said structure 'xc_handle' - so this patch also changes the variable to xch.

Quoted 7 lines
Quoted 1 line

I wasn't sure whether "xc_private.h" was intended to be included by tools outside the libxc directory, but it seems to be included by xenpaging and a couple of random things inside tools/misc; so:

Quoted 7 lines

I disagree - xc_private.h is private to libxc and should not be used outside of tools/libxc/*

There are some naughty examples which should be fixed.

If there are bits in xc_private.h which are needed by outside programs, then they should move to xen{ctrl,guest}.h as appropriate.

Heh. All of this started with me wanting to have 'DIV_ROUNDS_UP' being a header shared between libxc and xentrace.

It can be in the 'xc_bitsops.h" or in the "trace.h" file. Ian Campbell didn't want in xc_bitops.h so would "trace.h" file be OK?

Quoted 2 lines

~Andrew

#6 lore raw

PATCH v2 2/4 libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU mask with xc_cpumap_t instead of uint32_t

In reply to Konrad Rzeszutek Wilk

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: Use DIV_ROUND_UP macro as suggested by Daniel]
[v3: Use 'int' for bits instead of 'unsigned int' as spotted by Boris]
[v4: Move DIV_ROUND_UP in xc_private instead of xc_bitops]
---
 tools/libxc/xc_private.h  |    2 +
 tools/libxc/xc_tbuf.c     |   19 ++++++--
 tools/libxc/xenctrl.h     |    2 +-
 tools/xentrace/xentrace.8 |    3 +
 tools/xentrace/xentrace.c |   97 ++++++++++++++++++++++++++++++++++++++-------
 5 files changed, 102 insertions(+), 21 deletions(-)
tools/libxc/xc_private.h +2 -0
index c7730f2..4bd1528 100644
@@ -66,6 +66,8 @@
 #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
 #endif
 
+#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+
 /*
 ** Define max dirty page cache to permit during save/restore -- need to balance 
 ** keeping cache usage down with CPU impact of invalidating too often.
tools/libxc/xc_tbuf.c +14 -5
index 8777492..2828aee 100644
@@ -113,14 +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);
     int ret = -1;
-    uint64_t mask64 = mask;
+    int local_bits;
 
-    bytemap = xc_hypercall_buffer_alloc(xch, bytemap, sizeof(mask64));
+    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;
+    }
+    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 hypercall");
@@ -131,10 +140,10 @@ 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);
+    memcpy(bytemap, mask, DIV_ROUND_UP(bits, 8));
 
     set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap);
-    sysctl.u.tbuf_op.cpu_mask.nr_bits = sizeof(bytemap) * 8;
+    sysctl.u.tbuf_op.cpu_mask.nr_bits = bits;
 
     ret = do_sysctl(xch, &sysctl);
 
tools/libxc/xenctrl.h +1 -1
index b55d857..4f30db0 100644
@@ -1489,7 +1489,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/xentrace/xentrace.8 +3 -0
index ac18e9f..c176a96 100644
@@ -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 +82 -15

142 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#7 lore raw

Re: [PATCH v2 2/4] libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU mask with xc_cpumap_t instead of uint32_t

Quoted 7 lines · Konrad Rzeszutek Wilk

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.

Quoted 6 lines

We also add an macro which can be used by both libxc and xentrace.

And update the man page to describe this behavior.

xentrace side looks good to me, with one minor thing...

Quoted 10 lines
tools/xentrace/xentrace.c +6 -0
@@ -513,23 +513,66 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
      return &tbufs;
  }
 
+void print_cpu_mask(xc_cpumap_t mask, int bits)
+{
+    unsigned int v, had_printed = 0;
+    int i;
+
+    fprintf(stderr, "change cpumask to 0x");

tools/xentrace/xentrace.c static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num, · line 531

Quoted 10 lines
tools/xentrace/xentrace.c +10 -0
+
+    for ( i = DIV_ROUND_UP(bits, 8); i >= 0; i-- )
+    {
+        v = mask[i];
+        if ( v || had_printed ) {
+            fprintf(stderr,"%x", v);
+            had_printed = 1;
+        }
+   }
+   fprintf(stderr, "\n");

If I'm reading this right, if the user enters "-c 0x0", the output of this will be as follows:

change cpumask to 0x

Maybe we should add "i==0" (or "!i") to the conditions under which it will print the mask?

-George

#8 lore raw

Re: [PATCH v2 2/4] libxc/xentrace: Replace xc_tbuf_set_cpu_mask with CPU mask with xc_cpumap_t instead of uint32_t

Quoted 40 lines · George Dunlap
Quoted 7 lines · Konrad Rzeszutek Wilk

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.

Quoted 6 lines

We also add an macro which can be used by both libxc and xentrace.

And update the man page to describe this behavior.

xentrace side looks good to me, with one minor thing...

Quoted 9 lines
tools/xentrace/xentrace.c +6 -0
@@ -513,23 +513,66 @@ static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num,
     return &tbufs;
 }
+void print_cpu_mask(xc_cpumap_t mask, int bits)
+{
+    unsigned int v, had_printed = 0;
+    int i;
+
+    fprintf(stderr, "change cpumask to 0x");

tools/xentrace/xentrace.c static struct t_struct *map_tbufs(unsigned long tbufs_mfn, unsigned int num, · line 530

Quoted 10 lines
tools/xentrace/xentrace.c +10 -0
+
+    for ( i = DIV_ROUND_UP(bits, 8); i >= 0; i-- )
+    {
+        v = mask[i];
+        if ( v || had_printed ) {
+            fprintf(stderr,"%x", v);
+            had_printed = 1;
+        }
+   }
+   fprintf(stderr, "\n");

If I'm reading this right, if the user enters "-c 0x0", the output of this will be as follows:

Quoted 4 lines

change cpumask to 0x

Maybe we should add "i==0" (or "!i") to the conditions under which it will print the mask?

Will do in the next posting!

Quoted 3 lines

-George

#9 lore raw

PATCH v2 3/4 libxc/tbuf: Use the xc_hypercall_bounce_[pre|post] instead of memcpy

In reply to Konrad Rzeszutek Wilk

for bounce buffer of the xc_cpumask_t.

---
 tools/libxc/xc_tbuf.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
tools/libxc/xc_tbuf.c +6 -7
index 2828aee..85156dd 100644
@@ -116,7 +116,7 @@ int xc_tbuf_disable(xc_interface *xch)
 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, 0, XC_HYPERCALL_BUFFER_BOUNCE_IN);
     int ret = -1;
     int local_bits;
 
@@ -129,8 +129,9 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, xc_cpumap_t mask, int bits)
         PERROR("Wrong amount of bits supplied: %d > %d!\n", bits, local_bits);
         goto out;
     }
-    bytemap = xc_hypercall_buffer_alloc(xch, bytemap, DIV_ROUND_UP(bits, 8));
-    if ( bytemap == NULL )
+
+    HYPERCALL_BOUNCE_SET_SIZE(mask, DIV_ROUND_UP(bits, 8));
+    if ( xc_hypercall_bounce_pre(xch, mask) )
     {
         PERROR("Could not allocate memory for xc_tbuf_set_cpu_mask hypercall");
         goto out;
@@ -140,14 +141,12 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, xc_cpumap_t mask, int bits)
     sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION;
     sysctl.u.tbuf_op.cmd  = XEN_SYSCTL_TBUFOP_set_cpu_mask;
 
-    memcpy(bytemap, mask, DIV_ROUND_UP(bits, 8));
-
-    set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap);
+    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;
Signature · 1 line
1.7.7.6
#10 lore raw

Re: [PATCH v2 3/4] libxc/tbuf: Use the xc_hypercall_bounce_[pre|post] instead of memcpy

Quoted 1 line · Konrad Rzeszutek Wilk

for bounce buffer of the xc_cpumask_t.

You just added this stuff in the previous patch. Why not fold?

Quoted 10 lines
---
 tools/libxc/xc_tbuf.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
tools/libxc/xc_tbuf.c +0 -0
index 2828aee..85156dd 100644

tools/libxc/xc_tbuf.c int xc_tbuf_disable(xc_interface *xch) · line 119

Quoted 5 lines
tools/libxc/xc_tbuf.c +1 -1
@@ -116,7 +116,7 @@ int xc_tbuf_disable(xc_interface *xch)
 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, 0, XC_HYPERCALL_BUFFER_BOUNCE_IN);

s/0/DIV_ROUND_UP(bits, 8)/ works here and avoids the need for HYPERCALL_BOUNCE_SET_SIZE (I think).

The SET_SIZE macro is only generally used when you don't know the size at declaration time (i.e. because you need to query it first).

Ian.

#11 lore raw

Re: [PATCH v2 3/4] libxc/tbuf: Use the xc_hypercall_bounce_[pre|post] instead of memcpy

Quoted 4 lines · Ian Campbell
Quoted 1 line · Konrad Rzeszutek Wilk

for bounce buffer of the xc_cpumask_t.

You just added this stuff in the previous patch. Why not fold?

I was thinking it might be a bit too busy.

But I will be more than happy to fold it in.

Quoted 6 lines
Quoted 6 lines
---
 tools/libxc/xc_tbuf.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
Quoted 13 lines

tools/libxc/xc_tbuf.c int xc_tbuf_disable(xc_interface *xch) · line 119

Quoted 10 lines
tools/libxc/xc_tbuf.c +1 -1
index 2828aee..85156dd 100644
@@ -116,7 +116,7 @@ int xc_tbuf_disable(xc_interface *xch)
 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, 0, XC_HYPERCALL_BUFFER_BOUNCE_IN);

s/0/DIV_ROUND_UP(bits, 8)/ works here and avoids the need for HYPERCALL_BOUNCE_SET_SIZE (I think).

<nods>

Quoted 6 lines

The SET_SIZE macro is only generally used when you don't know the size at declaration time (i.e. because you need to query it first).

Ian.

#12 lore raw

PATCH v2 4/4 xentrace: Implement cpu mask range parsing of human values (-c).

In reply to Konrad Rzeszutek Wilk

Instead of just using -c 0x<some hex value> we can also use -c <starting cpu>-<end cpu> or -c <cpu1>,<cpu2> or a combination of them.

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.

---
 tools/xentrace/xentrace.8 |   21 +++++-
 tools/xentrace/xentrace.c |  155 ++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 165 insertions(+), 11 deletions(-)
tools/xentrace/xentrace.8 +18 -3
index c176a96..9beb72d 100644
@@ -36,11 +36,26 @@ 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]
+set bitmask of CPUs to trace. It is limited to 32-bits if using hex digits.
 If not specified, the cpu-mask of all of the available CPUs will be
-constructed.
+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.
+.RE
+.Sp
+
+If this option is not specified, xentrace will trace all of the physical
+CPUs on the machine.
 .TP
 .B -e, --evt-mask=e
 set event capture mask. If not specified the TRC_ALL will be used.
tools/xentrace/xentrace.c +147 -8

205 lines not on this page · raw message

Signature · 1 line
1.7.7.6
#13 lore raw

Re: [PATCH v2 4/4] xentrace: Implement cpu mask range parsing of human values (-c).

Quoted 26 lines · Konrad Rzeszutek Wilk

Instead of just using -c 0x<some hex value> we can also use -c <starting cpu>-<end cpu> or -c <cpu1>,<cpu2> or a combination of them.

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.

---
  tools/xentrace/xentrace.8 |   21 +++++-
  tools/xentrace/xentrace.c |  155 ++++++++++++++++++++++++++++++++++++++++++---
  2 files changed, 165 insertions(+), 11 deletions(-)
tools/xentrace/xentrace.8 +0 -0
index c176a96..9beb72d 100644

tools/xentrace/xentrace.8 all new records to the output · line 42

Quoted 9 lines
tools/xentrace/xentrace.8 +2 -2
@@ -36,11 +36,26 @@ 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]
+set bitmask of CPUs to trace.
  It is limited to 32-bits if using hex digits.
  If not specified, the cpu-mask of all of the available CPUs will be

I think something like this would be better:

"This can be either a hex value (of the form 0xNNNN...), or a set of cpu ranges as described below. Hex values are limited to 32 bits. If not specified..."

Quoted 8 lines
tools/xentrace/xentrace.8 +6 -1
-constructed.
+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"

tools/xentrace/xentrace.8 all new records to the output · line 58

Quoted 10 lines
tools/xentrace/xentrace.8 +10 -0
+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.
+.RE
+.Sp
+
+If this option is not specified, xentrace will trace all of the physical
+CPUs on the machine.

This was already said above. I'm not sure whether here or at the beginning is better, but it should only be said once.

Quoted 32 lines
tools/xentrace/xentrace.8 +0 -0
  .TP
  .B -e, --evt-mask=e

set event capture mask. If not specified the TRC_ALL will be used.

tools/xentrace/xentrace.c +3 -0
index 03b5537..45b0597 100644
@@ -23,6 +23,7 @@
  #include <string.h>
  #include <getopt.h>
  #include <assert.h>
+#include <ctype.h>
  #include <sys/poll.h>
  #include <sys/statvfs.h>
 
@@ -31,6 +32,7 @@
 
  #include <xenctrl.h>
  #include "xc_private.h"
+#include "xc_bitops.h" /* for set_bit */
 
  /***** Compile time configuration of defaults ********************************/
 
@@ -45,6 +47,7 @@ typedef struct settings_st {
      unsigned long poll_sleep; /* milliseconds to sleep between polls */
      uint32_t evt_mask;
      xc_cpumap_t cpu_mask;
+    char *cpu_mask_str;
      unsigned long tbuf_size;
      unsigned long disk_rsvd;
      unsigned long timeout;

tools/xentrace/xentrace.c static void usage(void) · line 815

Quoted 5 lines
tools/xentrace/xentrace.c +1 -1
@@ -809,7 +812,7 @@ 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 hex and CPU ranges\n" \

"Set cpu-mask, using either hex or CPU ranges"

Quoted 14 lines
tools/xentrace/xentrace.c +14 -0
+static int check_for_hex(const char *s)
+{
+    int buflen;
+    int c_old, c;
+
+    buflen = strlen(s);
+    c_old = c = 0;
+    do {
+            c = *s++;
+            buflen--;
+
+            if ( isspace(c) && c_old != ZERO_DIGIT )
+                continue;
+

tools/xentrace/xentrace.c static int parse_cpumask(const char *arg) · line 1079

Quoted 10 lines
tools/xentrace/xentrace.c +10 -0
+            if ( c == '\0' )
+                return -1;
+
+            if ( c == ZERO_DIGIT )
+                c_old = c;
+
+            if ( c == 'x' && c_old == ZERO_DIGIT )
+                return 1;
+
+     } while ( buflen );

I'm a bit confused why you don't just do strcmp("0x", s) here.

Quoted 16 lines
tools/xentrace/xentrace.c +7 -4
@@ -989,14 +1112,25 @@ static void parse_args(int argc, char **argv)
              break;
 
          case 'c': /* set new cpu mask for filtering*/
-            /* Set opts.cpu_mask later as we don't have 'xch' set yet. */
-            if ( parse_cpumask(optarg) )
              {
-                perror("Not enough memory!");
-                exit(EXIT_FAILURE);
+                int ret = check_for_hex(optarg);
+
+                if ( ret < 0 )
+                    usage();
+
+                if ( ret )
+                    ret = parse_cpumask(optarg);

tools/xentrace/xentrace.c static void parse_args(int argc, char **argv) · line 1132

Quoted 10 lines
tools/xentrace/xentrace.c +10 -0
+                else
+                    /* Set opts.cpu_mask later as we don't have 'xch' set yet.*/
+                    opts.cpu_mask_str = strdup(optarg);
+
+                if ( ret )
+                {
+                    perror("Not enough memory!");
+                    exit(EXIT_FAILURE);
+                }
+                break;

While we're at it, is there any chance we could put all the parsing stuff in the same place? If we can't call parse_cpumask_range here, I'd prefer to just do a strdup() always, and then do the check_for_hex() and parse_cpumask() or parse_cpumask_range() down below.

-George