Hi Stephane,

I did some preliminary work to figure out how to get the perfmon2 code
to run in valgrind.  I added missing system calls to valgrind for x86
and amd64. The attached patch for the valgrind source in
valgrind-3.2.0-3.1.src.rpm provides minimal hooks for the perfmon2
systemcalls.  Currently, there isn't any checking in the perfmon2
systemcall, e.g. checking results etc.  Below is the output for self
on amd64. Looks like some of the code for getpid does some odd
stuff. I am wondering if valgrind handling the following instruction
in getpid correctly.

0x00000000004191d0 <getpid+0>:  mov    %fs:0x94,%edx

$ VALGRIND_LIB=~/rh-rpms/BUILD/valgrind-3.2.0.mod/.in_place ~/rh-rpms/BUILD/valgrind-3.2.0.mod/coregrind/valgrind ./self
==9201== Memcheck, a memory error detector.
==9201== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==9201== Using LibVEX rev 1606, a library for dynamic binary translation.
==9201== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==9201== Using valgrind-3.2.0, a dynamic binary instrumentation framework.
==9201== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==9201== For more details, rerun with: -v
==9201==
[perfsel0=0x510076 emask=0x76 umask=0x0 os=0 usr=1 inv=0 en=1 int=1 edge=0 cnt_mask=0] CPU_CLK_UNHALTED [perfsel1=0x5100c0 emask=0xc0 umask=0x0 os=0 usr=1 inv=0 en=1 int=1 edge=0 cnt_mask=0] RETIRED_INSTRUCTIONS
==9201== Conditional jump or move depends on uninitialised value(s)
==9201== at 0x4191DD: getpid (in /home/wcohen/research/profiling/perfmon2/libpfm-3.2-060621/examples/self)
==9201==    by 0x400566: main (self.c:229)
==9201==
==9201== Conditional jump or move depends on uninitialised value(s)
==9201== at 0x4191E1: getpid (in /home/wcohen/research/profiling/perfmon2/libpfm-3.2-060621/examples/self)
==9201==    by 0x400566: main (self.c:229)
==9201==
==9201== Conditional jump or move depends on uninitialised value(s)
==9201== at 0x4191ED: getpid (in /home/wcohen/research/profiling/perfmon2/libpfm-3.2-060621/examples/self)
==9201==    by 0x400566: main (self.c:229)
==9201==
==9201== Conditional jump or move depends on uninitialised value(s)
==9201== at 0x4191F8: getpid (in /home/wcohen/research/profiling/perfmon2/libpfm-3.2-060621/examples/self)
==9201==    by 0x400566: main (self.c:229)
PMD0          21099802103 CPU_CLK_UNHALTED
PMD1          41475803496 RETIRED_INSTRUCTIONS
==9201==
==9201== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
==9201== malloc/free: in use at exit: 0 bytes in 0 blocks.
==9201== malloc/free: 0 allocs, 0 frees, 0 bytes allocated.
==9201== For counts of detected errors, rerun with: -v
==9201== All heap blocks were freed -- no leaks are possible.


Valgrinds main strengths are being able to track references to
uninitilized regions of memory regardless of whether they are in a
shared library or code that the developer has control over. Valgrind
doesn't do such a great job on tracking out of bound references that
corrupt other initilized variables.

Mudflap has a higher level view of the code due to being working with
the compiler intermediate representation and knowing the size of
various structures of the code being compiled. However, the code needs
to recompiled to make use of mudflap.

Mudflap was able to clearly identify the problem that Phil Mucci
reported. Valgrind shows some issues on the i386, but it isn't as
clear what is going on.
--- valgrind-3.2.0.mod/coregrind/vki_unistd-amd64-linux.h.perfmon	2006-07-24 16:18:14.000000000 -0400
+++ valgrind-3.2.0.mod/coregrind/vki_unistd-amd64-linux.h	2006-07-24 16:38:25.000000000 -0400
@@ -355,5 +355,17 @@
 #define __NR_tee		276
 #define __NR_sync_file_range	277
 #define __NR_vmsplice		278
+#define __NR_pfm_create_context 279
+#define __NR_pfm_write_pmcs     (__NR_pfm_create_context+1)
+#define __NR_pfm_write_pmds     (__NR_pfm_create_context+2)
+#define __NR_pfm_read_pmds      (__NR_pfm_create_context+3)
+#define __NR_pfm_load_context   (__NR_pfm_create_context+4)
+#define __NR_pfm_start          (__NR_pfm_create_context+5)
+#define __NR_pfm_stop           (__NR_pfm_create_context+6)
+#define __NR_pfm_restart        (__NR_pfm_create_context+7)
+#define __NR_pfm_create_evtsets (__NR_pfm_create_context+8)
+#define __NR_pfm_getinfo_evtsets (__NR_pfm_create_context+9)
+#define __NR_pfm_delete_evtsets (__NR_pfm_create_context+10)
+#define __NR_pfm_unload_context (__NR_pfm_create_context+11)
 
 #endif /* __VKI_UNISTD_AMD64_LINUX_H */
--- valgrind-3.2.0.mod/coregrind/vki_unistd-x86-linux.h.perfmon	2006-07-25 11:43:42.000000000 -0400
+++ valgrind-3.2.0.mod/coregrind/vki_unistd-x86-linux.h	2006-07-25 11:45:47.000000000 -0400
@@ -346,5 +346,17 @@
 #define __NR_sync_file_range	314
 #define __NR_tee		315
 #define __NR_vmsplice		316
+#define __NR_pfm_create_context 317
+#define __NR_pfm_write_pmcs     (__NR_pfm_create_context+1)
+#define __NR_pfm_write_pmds     (__NR_pfm_create_context+2)
+#define __NR_pfm_read_pmds      (__NR_pfm_create_context+3)
+#define __NR_pfm_load_context   (__NR_pfm_create_context+4)
+#define __NR_pfm_start          (__NR_pfm_create_context+5)
+#define __NR_pfm_stop           (__NR_pfm_create_context+6)
+#define __NR_pfm_restart        (__NR_pfm_create_context+7)
+#define __NR_pfm_create_evtsets (__NR_pfm_create_context+8)
+#define __NR_pfm_getinfo_evtsets (__NR_pfm_create_context+9)
+#define __NR_pfm_delete_evtsets (__NR_pfm_create_context+10)
+#define __NR_pfm_unload_context (__NR_pfm_create_context+11)
 
 #endif /* __VKI_UNISTD_X86_LINUX_H */
--- valgrind-3.2.0.mod/coregrind/m_syswrap/syswrap-x86-linux.c.perfmon	2006-07-25 11:36:51.000000000 -0400
+++ valgrind-3.2.0.mod/coregrind/m_syswrap/syswrap-x86-linux.c	2006-07-25 11:42:23.000000000 -0400
@@ -2174,6 +2174,19 @@
 //   LINX_(__NR_unshare,		 sys_unshare),          // 310
    LINX_(__NR_set_robust_list,	 sys_set_robust_list),  // 311
    LINXY(__NR_get_robust_list,	 sys_get_robust_list),  // 312
+
+   LINX_(__NR_pfm_create_context,	sys_pfm_create_context),	// 317
+   LINX_(__NR_pfm_write_pmcs,	sys_pfm_write_pmcs),	// 318
+   LINX_(__NR_pfm_write_pmds,	sys_pfm_write_pmds),	// 319
+   LINX_(__NR_pfm_read_pmds,	sys_pfm_read_pmds),	// 320
+   LINX_(__NR_pfm_load_context,	sys_pfm_load_context),	// 321
+   LINX_(__NR_pfm_start,	sys_pfm_start),		// 322
+   LINX_(__NR_pfm_stop,		sys_pfm_stop),		// 323
+   LINX_(__NR_pfm_restart,	sys_pfm_restart),	// 324
+   LINX_(__NR_pfm_create_evtsets,	sys_pfm_create_evtsets),	// 325
+   LINX_(__NR_pfm_getinfo_evtsets,	sys_pfm_getinfo_evtsets),	// 326
+   LINX_(__NR_pfm_delete_evtsets,	sys_pfm_delete_evtsets),	// 327
+   LINX_(__NR_pfm_unload_context,	sys_pfm_unload_context), // 328
 };
 
 const UInt ML_(syscall_table_size) = 
--- valgrind-3.2.0.mod/coregrind/m_syswrap/priv_syswrap-linux.h.perfmon	2006-07-24 17:08:20.000000000 -0400
+++ valgrind-3.2.0.mod/coregrind/m_syswrap/priv_syswrap-linux.h	2006-07-24 17:09:32.000000000 -0400
@@ -213,6 +213,20 @@
 DECL_TEMPLATE(linux, sys_rt_sigqueueinfo);
 DECL_TEMPLATE(linux, sys_rt_sigsuspend);
 
+/* declarations for linux perfmon support */
+DECL_TEMPLATE(linux, sys_pfm_create_context);
+DECL_TEMPLATE(linux, sys_pfm_write_pmcs);
+DECL_TEMPLATE(linux, sys_pfm_write_pmds);
+DECL_TEMPLATE(linux, sys_pfm_read_pmds);
+DECL_TEMPLATE(linux, sys_pfm_load_context);
+DECL_TEMPLATE(linux, sys_pfm_start);
+DECL_TEMPLATE(linux, sys_pfm_stop);
+DECL_TEMPLATE(linux, sys_pfm_restart);
+DECL_TEMPLATE(linux, sys_pfm_create_evtsets);
+DECL_TEMPLATE(linux, sys_pfm_getinfo_evtsets);
+DECL_TEMPLATE(linux, sys_pfm_delete_evtsets);
+DECL_TEMPLATE(linux, sys_pfm_unload_context);
+
 /* ---------------------------------------------------------------------
    Wrappers for sockets and ipc-ery.  These are split into standalone
    procedures because x86-linux hides them inside multiplexors
--- valgrind-3.2.0.mod/coregrind/m_syswrap/syswrap-amd64-linux.c.perfmon	2006-07-25 11:36:21.000000000 -0400
+++ valgrind-3.2.0.mod/coregrind/m_syswrap/syswrap-amd64-linux.c	2006-07-25 11:05:50.000000000 -0400
@@ -1330,6 +1330,18 @@
 //   LINX_(__NR_unshare,		 sys_unshare),          // 272
    LINX_(__NR_set_robust_list,	 sys_set_robust_list),  // 273
    LINXY(__NR_get_robust_list,	 sys_get_robust_list),  // 274
+   LINX_(__NR_pfm_create_context,	sys_pfm_create_context),	// 279
+   LINX_(__NR_pfm_write_pmcs,	sys_pfm_write_pmcs),	// 280
+   LINX_(__NR_pfm_write_pmds,	sys_pfm_write_pmds),	// 281
+   LINX_(__NR_pfm_read_pmds,	sys_pfm_read_pmds),	// 282
+   LINX_(__NR_pfm_load_context,	sys_pfm_load_context),	// 283
+   LINX_(__NR_pfm_start,	sys_pfm_start),		// 284
+   LINX_(__NR_pfm_stop,		sys_pfm_stop),		// 285
+   LINX_(__NR_pfm_restart,	sys_pfm_restart),	// 286
+   LINX_(__NR_pfm_create_evtsets,	sys_pfm_create_evtsets),	// 287
+   LINX_(__NR_pfm_getinfo_evtsets,	sys_pfm_getinfo_evtsets),	// 288
+   LINX_(__NR_pfm_delete_evtsets,	sys_pfm_delete_evtsets),	// 289
+   LINX_(__NR_pfm_unload_context,	sys_pfm_unload_context), // 290
 };
 
 const UInt ML_(syscall_table_size) = 
--- valgrind-3.2.0.mod/coregrind/m_syswrap/syswrap-linux.c.perfmon	2006-07-25 10:36:17.000000000 -0400
+++ valgrind-3.2.0.mod/coregrind/m_syswrap/syswrap-linux.c	2006-07-25 10:37:02.000000000 -0400
@@ -2505,6 +2505,42 @@
    PRE_MEM_RASCIIZ( "faccessat(pathname)", ARG2 );
 }
 
+PRE(sys_pfm_create_context) {}
+POST(sys_pfm_create_context) {}
+
+PRE(sys_pfm_write_pmcs) {}
+POST(sys_pfm_write_pmcs) {}
+
+PRE(sys_pfm_write_pmds) {}
+POST(sys_pfm_write_pmds) {}
+
+PRE(sys_pfm_read_pmds) {}
+POST(sys_pfm_read_pmds) {}
+
+PRE(sys_pfm_load_context) {}
+POST(sys_pfm_load_context) {}
+
+PRE(sys_pfm_start) {}
+POST(sys_pfm_start) {}
+
+PRE(sys_pfm_stop) {}
+POST(sys_pfm_stop) {}
+
+PRE(sys_pfm_restart) {}
+POST(sys_pfm_restart) {}
+
+PRE(sys_pfm_create_evtsets) {}
+POST(sys_pfm_create_evtsets) {}
+
+PRE(sys_pfm_getinfo_evtsets) {}
+POST(sys_pfm_getinfo_evtsets) {}
+
+PRE(sys_pfm_delete_evtsets) {}
+POST(sys_pfm_delete_evtsets) {}
+
+PRE(sys_pfm_unload_context) {}
+POST(sys_pfm_unload_context) {}
+
 #undef PRE
 #undef POST
 
--- valgrind-3.2.0.mod/coregrind/m_syswrap/priv_syswrap-generic.h.perfmon	2006-07-24 17:04:12.000000000 -0400
+++ valgrind-3.2.0.mod/coregrind/m_syswrap/priv_syswrap-generic.h	2006-07-24 17:08:34.000000000 -0400
@@ -196,6 +196,8 @@
 DECL_TEMPLATE(generic, sys_fstatfs64);             // * (?)
 
 
+
+
 /* ---------------------------------------------------------------------
    Wrappers for sockets and ipc-ery.  These are split into standalone
    procedures because x86-linux hides them inside multiplexors
_______________________________________________
perfmon mailing list
[email protected]
http://www.hpl.hp.com/hosted/linux/mail-archives/perfmon/

Reply via email to