I am still looking at this code with the idea of trying to eliminate the libpfm4 changes while at the same time not duplicating libpfm4 code in PAPI.
I found the libpfm4 function pfm_get_event_next which I now use to step through the events on a pmu when PAPI lists events. This has eliminated the need for PAPI to use the function pfmlib_idx2pidx.
The other libpfm4 funtion which papi is still using is idx2pmu. This function is used by PAPI after listing the last event on a pmu. It gives PAPI the pmu number from the last event processed. This is needed so we can find the next pmu of a particular type then we get the first event from the next pmu to continue listing events.
Does libpfm4 provide another way for PAPI to get the next pmu of a particular type ??
Maybe a libpfm4 function like pfm_get_pmu_next (int idx) would be the best way to solve this problem.
If you like this approach, I can build one and get it working with PAPI.
If you have a different suggestion, please share it.