Good morning,
I'm having strange problems doing periodic sampling of even the most basic
performance counters when it comes to attached processes, to the point that
I can't help wondering if I'm not using the correct API? Or is this a use
case that PAPI simply wasn't designed for (because it seems to be too
simple a problem to be a bug that wasn't caught).
Anyway, I won't bore you with our actual source code, but I modified one of
the PAPI testcases (ctests/attach2.c) to demonstrate the same issue. The
complete source code is attached to this email but here's the diff:
--- attach2.c.orig 2023-06-22 09:59:05.220181155 -0500
+++ attach2.c 2023-06-22 09:59:05.206847812 -0500
@@ -48,7 +48,7 @@ wait_for_attach_and_loop( void )
putenv(newpath);
if (ptrace(PTRACE_TRACEME, 0, 0, 0) == 0) {
- execlp("attach_target","attach_target","100000000",NULL);
+ execlp("attach_target","attach_target","1000000000",NULL);
perror("execl(attach_target) failed");
}
perror("PTRACE_TRACEME");
@@ -176,6 +176,16 @@ main( int argc, char **argv )
return 1;
}
+ sleep(1);
+ retval = PAPI_read(EventSet1, values[0]);
+// retval = PAPI_stop(EventSet1, values[0]);
+ if ( retval != PAPI_OK )
+ test_fail( __FILE__, __LINE__, "PAPI_read", retval );
+ printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] );
+ printf( "%s : \t %12lld\n",event_name, ( values[0] )[1]);
+// retval = PAPI_start(EventSet1);
+// if ( retval != PAPI_OK )
+// test_fail( __FILE__, __LINE__, "PAPI_read", retval );
do {
child = wait( &status );
Basically, I'm invoking PAPI_read() while the attached process is still
running (I increased its runtime to be a couple of seconds on my system so
that the sleep(1) makes sense). And I'm getting garbage results:
must_ptrace is 1
Debugger exited wait() with 27085
Child has stopped due to signal 5 (Trace/breakpoint trap)
After 0
Continuing
PAPI_TOT_CYC : 140737488355327
PAPI_TOT_INS : 140737488355327
Debugger exited wait() with 27085
Child exited with value 0
Test case: 3rd party attach start, stop.
-----------------------------------------------
Default domain is: 1 (PAPI_DOM_USER)
Default granularity is: 1 (PAPI_GRN_THR)
Using 20000000 iterations of c += a*b
-------------------------------------------------------------------------
Test type : 1
PAPI_TOT_CYC :
9145700936
PAPI_TOT_INS : 10000141883
Real usec : 2659234
Real cycles :
7722401191
Virt usec : 242
Virt cycles : 836500
-------------------------------------------------------------------------
Verification: none
PASSED
As you can see from the two added lines immediately following "Continuing",
instead of valid counts I get 2^47-1. I tried doing
PAPI_stop()/PAPI_start() instead of PAPI_read() (see the commented out
code) but that doesn't seem to help.
This is on my old x86 laptop (Intel iCore i7-7500U, Gentoo stable, Linux
kernel version 6.3.3) with the latest release of PAPI (7.0.1) but to check
that I'm not crazy I also compiled it on a login node of the ALCF sunspot
(Intel Xeon Gold 5320, SLES 15-SP3, Linux kernel
5.3.18-150300.59.115-default), with the same outcome.
Could you shed some light on what might be going on here and how to fix it?
Thank you,
Kamil
--
Kamil Iskra, PhD
Argonne National Laboratory, Mathematics and Computer Science Division
9700 South Cass Avenue, Building 240, Lemont, IL 60439, USA
phone:
+1-630-252-7197 fax:
+1-630-252-5986