Remove All Ads from XDA

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

1 posts
Thanks Meter: 0
By M. J. Cho, Junior Member on 6th March 2014, 12:56 AM
Post Reply Email Thread
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.

Please somebody help me!

Thanks in advance.

My test code is as follow.

#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;

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.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);

    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);
20th June 2014, 07:36 AM |#2  
Junior Member
Thanks Meter: 0
Same here
I've also had no luck I'm actually not able to get any hardware counters (they are all zero or errno 2). I only got some software counters like the clock. Did you need cygenomod to get cycles/cache counters working? I figured this should work even without custom builds. Did you need to run as root while querying them?
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes