Skip to contentSkip to conversation

Support CPU list parsing in xentrace.

PATCH In review Konrad Rzeszutek Wilk 2 participants 7 messages Apr 23, 2015 – May 11, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support CPU list parsing in xentrace.

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

#1 lore raw

PATCH 1/3 libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc.

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.

----
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(+)
tools/libxc/include/xenctrl.h +9 -0
index 6994c51..2c17d78 100644
@@ -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
  */
tools/libxc/xc_misc.c +26 -0
index be68291..3a1784b 100644
@@ -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;
Signature · 1 line
2.1.0
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH v4.1 1/3] libxl/cpumap: Add xc_cpumap_[setcpu, clearcpu, testcpu] to complement xc_cpumap_alloc.

Quoted 6 lines · 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.

#3 lore raw

PATCH 2/3 libxc/xentrace: Use xc_cpumap_t for xc_tbuf_set_cpu_mask

In reply to Konrad Rzeszutek Wilk

From: George Dunlap <[email protected]>

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 <[email protected]>

---
 tools/libxc/include/xenctrl.h |  2 +-
 tools/libxc/xc_tbuf.c         | 33 ++++++++++++++-------
 tools/xentrace/xentrace.c     | 68 ++++++++++++++++++++++++++++++++++++-------
 3 files changed, 81 insertions(+), 22 deletions(-)
tools/libxc/include/xenctrl.h +1 -1
index 2c17d78..a6df95f 100644
@@ -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);
 
tools/libxc/xc_tbuf.c +23 -10
index 8777492..a4de491 100644
@@ -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;
tools/xentrace/xentrace.c +57 -11

90 lines not on this page · raw message

Signature · 1 line
2.1.0
#4 lore raw

PATCH 3/3 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>, -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.

---
[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(-)
tools/xentrace/xentrace.8 +32 -2
index ac18e9f..7b3172b 100644
@@ -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.
tools/xentrace/xentrace.c +163 -33

248 lines not on this page · raw message

Signature · 1 line
2.1.0
#5 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 8 lines · Konrad Rzeszutek Wilk

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.

#6 lore raw
Quoted 11 lines · Ian Campbell
Quoted 8 lines · Konrad Rzeszutek Wilk

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!

Quoted 2 lines

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.

Quoted 3 lines

Ian.