Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Id checked but not used in <Use perf_event_open for counting> #1352

Open
CpyKing opened this issue Oct 24, 2024 · 1 comment
Open

Id checked but not used in <Use perf_event_open for counting> #1352

CpyKing opened this issue Oct 24, 2024 · 1 comment

Comments

@CpyKing
Copy link

CpyKing commented Oct 24, 2024

I found some code that confused me in Configure multiple counters Section under Use perf_event_open for counting Chapter.
In the code under the annotation // Read the group of counters and print result, it shows like this...

read(fd[0], &counter_results, sizeof(struct read_format));
printf("Num events captured: %"PRIu64"\n", counter_results.nr);
for(int i = 0; i < counter_results.nr; i++) {
  for(int j = 0; j < TOTAL_EVENTS ;j++){
    if(counter_results.values[i].id == id[j]){
      pe_val[i] = counter_results.values[i].value;
    }
  }
}
printf("CPU cycles: %"PRIu64"\n", pe_val[0]);
printf("Instructions retired: %"PRIu64"\n", pe_val[1]);
printf("Frontend stall cycles: %"PRIu64"\n", pe_val[2]);
printf("Backend stall cycles: %"PRIu64"\n", pe_val[3]);
printf("Loads executed speculatively: %"PRIu64"\n", pe_val[4]);
printf("Stores executed speculatively: %"PRIu64"\n", pe_val[5]);

We can see that traverse id[j] here is to check the true_id that value belonged to. However, it assign the value with index i to pe_val with this same index i (not j) and print them sequentially. It make the check part useless.

So, is there any problem around here ?

@jsrz
Copy link
Contributor

jsrz commented Nov 5, 2024

Hi,

Yes, you can get rid of that inner for loop and check. I don't recall exactly why I placed that check there. I was probably paranoid about something and wanted to make sure the data returned in the counters_results was actually indexed the same way as when the events were created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants