I want to count and sample memory load operations that happen in a chunk of code while running it on an AMD machine. I know that the following code can be used to count memory loads happening in a code on Intel machine.
int
main(int argc, char **argv)
{
struct perf_event_attr pe;
long long count;
int fd;
memset(&pe, 0, sizeof(struct perf_event_attr));
pe.type = PERF_TYPE_RAW;
pe.size = sizeof(struct perf_event_attr);
/* event number of MEM_UOPS_RETIRED.ALL_LOADS
event is 81d0 */
pe.config = 0x81d0;
pe.disabled = 1;
pe.exclude_kernel = 1;
pe.exclude_hv = 1;
fd = perf_event_open(&pe, 0, -1, -1, 0);
if (fd == -1) {
fprintf(stderr, "Error opening %llx\n", pe.config);
exit(EXIT_FAILURE);
}
ioctl(fd, PERF_EVENT_IOC_RESET, 0);
ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);
// code chunk to be profiled is here
ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
read(fd, &count, sizeof(long long));
printf("Number of load operations: %lld\n", count);
close(fd);
}
However, I don't know how to get the count of the same event from AMD machine. I have read AMD's document on performance counter and IBS in https://www.amd.com/system/files/TechDocs/24593.pdf sections 13.2 and 13.3. Yet, there is no mention of any hardware event number for memory load that can be passed to pe.config in the above code.
So, how can I count or sample memory load operations in an AMD machine by using perf_event_open?
PS: The AMD processor that I am using is AMD EPYC 7551 32-Core.