Page 1 of 1

PAPI counters to measure child process?

PostPosted: Thu Apr 26, 2012 7:19 pm
by skabala2
I am trying to use PAPI to measure cache hit rates for child processes. My C program initializes the PAPI library and starts my counters, then forks a child process to execute a benchmark. The parent waits for the child to finish, stops the counters and reports their values. I'm running this program with 'taskset...' to tie the parent & child to a single processor core. It seems that the counters are only counting misses for the parent process, rather than for the processor core. Am I approaching this problem the wrong way? Should this give me measurements for the core or just for the process that makes the calls to PAPI? Any help is greatly appreciated... Thanks.

Re: PAPI counters to measure child process?

PostPosted: Thu Apr 26, 2012 9:43 pm
by jagode00
It sounds like you only initialize PAPI for the main thread before forking a child thread. Did I understand you correctly? If so then it makes sense that you only see misses for the parent thread. When the main thread creates a child thread then the child does not inherit any PAPI information from the calling thread. Have a look at the ctests/fork.c example.
heike

Re: PAPI counters to measure child process?

PostPosted: Sat Apr 28, 2012 4:23 pm
by skabala2
jagode00 wrote:It sounds like you only initialize PAPI for the main thread before forking a child thread. Did I understand you correctly? If so then it makes sense that you only see misses for the parent thread. When the main thread creates a child thread then the child does not inherit any PAPI information from the calling thread. Have a look at the ctests/fork.c example.
heike


Thanks. :) That's almost what I was up to -- I had attached PAPI to the forked child. But, I was using execl("/bin/bash", "/bin/bash", "-c", argv[cmd_arg_idx]) to get metrics for a bash command for the benchmarks. For commands that don't use pipes or indirection, this seemed to work okay. But, for more complex commands -- especially those that use input indirection with '< infile', it turned out I needed to track down bash's own spawned children with ps and attach to them instead. I wound up calling ~ popen("ps --ppid $CHILD_PID -o h") (with some sprintf(...) to write the pid from fork into the string...) to get the list of grandchildren.

Re: PAPI counters to measure child process?

PostPosted: Thu Aug 22, 2013 6:14 am
by faheemkhan
Hi there,

Looking at fork.c, I'm wondering why do you need to init PAPI twice? i.e. once in the parent thread and then again in the forked child?

My problem is, I would like to fork a child, exec() some benchmark and count the number of Instructions executed for example. So I I do something like this:

Code: Select all
main(){
int status, events[], num_events;

printf("Main thread");

if (fork()==0){
  printf("child");
  initi_PAPI();
  PAPI_start_counters(events, num_events);
   
   //start benchmarks
   execve(bench, argv, envp);
  }else{
         wait(&status)
         PAPI_read_counters(values, num_events);
         }
PAPI_shutdown();

}



Am I doing something wrong here?