assembly - How to obtain raw perf events for my host arch to use in libpfm4? - Stack Overflow

admin2025-04-16  4

I can not find any instructions on how to compile a list of human readable event mappings that libpfm4's pfm_get_os_event_encoding() will map to the corresponding values that i can pass to rdpmc. Every time i try anything but cycles or instructions from e.g the output of perf list libpfm4 can't find it.

I can not find any instructions on how to compile a list of human readable event mappings that libpfm4's pfm_get_os_event_encoding() will map to the corresponding values that i can pass to rdpmc. Every time i try anything but cycles or instructions from e.g the output of perf list libpfm4 can't find it.

Share Improve this question edited yesterday drip asked Feb 3 at 21:11 dripdrip 234 bronze badges 5
  • There are a couple fixed counters, one dedicated to cycles and one to instructions. So the same numbers in ECX for rdpmc will always work. The other counters are programmable, with the kernel having to program one of the other counters with the event and mask (documentation specific to each microarchitecture). rdpmc can index one of those, too, but you have to know which counter is programmed to count what. And If you didn't program them to count an event with perf or pfm functions, they won't be counting anything. I haven't used libpfm, but you can't just use ECX values. – Peter Cordes Commented Feb 4 at 3:32
  • If you're asking about Intel CPUs (rather than AMD), the tag [intel-pmu] would apply. – Peter Cordes Commented Feb 4 at 20:59
  • Please provide enough code so others can better understand or reproduce the problem. – Community Bot Commented Feb 6 at 1:17
  • @PeterCordes sorry my question was vague. I was looking for code to list all of the supported and active events for the current host system. i found code in the libpfm4 docs. – drip Commented Feb 14 at 13:32
  • Please post answers as answers; use the "answer your own question" button, and roll back the question to just ask a question without also answering it. Thanks for sharing what you found to help out future readers. – Peter Cordes Commented Feb 14 at 22:15
Add a comment  | 

1 Answer 1

Reset to default 1

EDIT/SOLUTION: There is example code hidden in the docs to list available events for every PMU:

void list_pmu_events(pfm_pmu_t pmu)
{
   pfm_event_info_t info;
   pfm_pmu_info_t pinfo;
   int i, ret;

   memset(&info, 0, sizeof(info));
   memset(&pinfo, 0, sizeof(pinfo));

   info.size = sizeof(info);
   pinfo.size = sizeof(pinfo);

   ret = pfm_get_pmu_info(pmu, &pinfo);
   if (ret != PFM_SUCCESS)
    return;
      errx(1, "cannot get pmu info");

   for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) {
      ret = pfm_get_event_info(i, PFM_OS_PERF_EVENT_EXT, &info);
      if (ret != PFM_SUCCESS)
        errx(1, "cannot get event info");

        if (pfm_find_event(info.name) && pinfo.is_present) {
            printf("Event: %s::%s\n",
                    pinfo.name, info.name);
        }
  }
}
转载请注明原文地址:http://www.anycun.com/QandA/1744749660a87073.html