mercredi 5 mars 2014

[Q] How to get the PERF_COUNT_HW_INSTRUCTION event with perf_event on Nexus 7 2013? topic




I'm trying to get hardware performance counter events on Nexus 7 2013.

I've tested on ASOP 4.3, 4.4, CyanogenMod 11, google original kernel 3.4, and codeaurora msm-3.4 kernel.

I already tested that CPU_CYCLE(PERF_COUNT_HW_CPU_CYCLES) and L2 Cache related events are working.

However, I couldn't get an executed instrunction event (PERF_COUNT_HW_INSTRUCTION) which is one of the default HPC events.

It always returns zero!

I'm stuck for 2 weeks.:crying:

Please somebody help me!

Thanks in advance.

My test code is as follow.


Code:


#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/ioctl.h>
#include <linux/perf_event.h>
#include <asm/unistd.h>

static long
perf_event_open(struct perf_event_attr *hw_event, pid_t pid,
                int cpu, int group_fd, unsigned long flags)
{
    int ret;

    ret = syscall(__NR_perf_event_open, hw_event, pid, cpu,
                  group_fd, flags);
    return ret;
}

int
main(int argc, char **argv)
{
    struct perf_event_attr pe;
    long long count;
    int fd;
    int i=0;
    memset(&pe, 0, sizeof(struct perf_event_attr));
    pe.type = PERF_TYPE_HARDWARE;
    pe.size = sizeof(struct perf_event_attr);
    pe.config = PERF_COUNT_HW_INSTRUCTIONS; //PERF_COUNT_HW_CPU_CYCLES;
    pe.disabled = 1;
    pe.exclude_kernel = 1;
    pe.exclude_hv = 1;

    fd = perf_event_open(&pe, 0, 0, -1, 0);
    if (fd == -1) {
      fprintf(stderr, "Error opening leader %llx\n", pe.config);
      exit(EXIT_FAILURE);
    }

    ioctl(fd, PERF_EVENT_IOC_RESET, 0);
    ioctl(fd, PERF_EVENT_IOC_ENABLE, 0);

    for (i=0; i< 10000; i++)
                printf("%d = %d * %d\n", i*(i+1), i, i+1);

    ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
    read(fd, &count, sizeof(long long));
    printf("%lld events\n", count);
   
    close(fd);
}







Aucun commentaire:

Enregistrer un commentaire