Skip to contentSkip to conversation

Make it possible to run valgrind on code linked with the libxc libraries.

Xen-changelog Muli Ben-Yehuda 2 participants 2 messages Nov 22, 2005 – Nov 23, 2005 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 6 lines · Xen patchbot -unstable

diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xg_private.h

tools/libxc/xg_private.h +0 -0
@@ -15,6 +15,16 @@
 
 #include <xen/linux/privcmd.h>

tools/libxc/xg_private.h line 26

Quoted 10 lines
tools/libxc/xg_private.h +9 -0
 #include <xen/memory.h>
+
+/* valgrind cannot see when a hypercall has filled in some values.  For this
+   reason, we must zero the dom0_op_t instance before a call, if using
+   valgrind.  */
+#ifdef VALGRIND
+#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
+#else
+#define DECLARE_DOM0_OP dom0_op_t op
+#endif

This is pretty ugly IMHO. Also, if someone does

if (foo)

        bla;
else
        DECLARE_DOM0_OP;

it breaks.

Is the micro-optimization of not initializing the structures to 0 worth it? I really doubt it. But if yes, please at least do something like

#ifdef VALGRIND

#define DECLARE_DOM0_OP(name) dom0_op_t name = {
        .cmd = 0,
	.interface_version = 0, 
	.pad = { 0 }
}

#else
#define #define DECLARE_DOM0_OP(name) dom0_op_t name; #endif

Cheers,
Muli

Signature · 2 lines
Muli Ben-Yehuda
http://www.mulix.org | http://mulix.livejournal.com/
#2 lore raw
Quoted 20 lines · Muli Ben-Yehuda
Quoted 6 lines · Xen patchbot -unstable

diff -r c1c8da6f2afe -r 602aefe7bd48 tools/libxc/xg_private.h

tools/libxc/xg_private.h +0 -0
@@ -15,6 +15,16 @@
 
 #include <xen/linux/privcmd.h>

tools/libxc/xg_private.h line 26

Quoted 10 lines
tools/libxc/xg_private.h +9 -0
 #include <xen/memory.h>
+
+/* valgrind cannot see when a hypercall has filled in some values.  For this
+   reason, we must zero the dom0_op_t instance before a call, if using
+   valgrind.  */
+#ifdef VALGRIND
+#define DECLARE_DOM0_OP dom0_op_t op; memset(&op, 0, sizeof(op))
+#else
+#define DECLARE_DOM0_OP dom0_op_t op
+#endif

This is pretty ugly IMHO. Also, if someone does

Quoted 6 lines

if (foo)

        bla;
else
        DECLARE_DOM0_OP;

it breaks.

There's no argument that it's ugly, but you'd have to be pretty strange to be trying to declare a variable inside a single statement else branch.

Quoted 2 lines

Is the micro-optimization of not initializing the structures to 0 worth it? I really doubt it.

I have no idea. Perhaps someone could do some benchmarking? I just tried to make sure I didn't add any overhead when all I was doing was supporting a debugging tool. Personally, I would have no problem with the structures being initialised unconditionally, and spending a few cycles, but other people would disagree I'm sure.

Quoted 4 lines

But if yes, please at least do something
like

#ifdef VALGRIND

Quoted 8 lines
#define DECLARE_DOM0_OP(name) dom0_op_t name = {
        .cmd = 0,
	.interface_version = 0, 
	.pad = { 0 }
}

#else
#define #define DECLARE_DOM0_OP(name) dom0_op_t name; #endif

Keir's already changed it to dom0_op_t op = { 0 } which I think ought to do the trick well enough.

Cheers,

Ewan.