Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

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

OP M. J. Cho

6th March 2014, 01:56 AM   |  #1  
OP Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Mar 2014
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.

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);
}
Last edited by M. J. Cho; 6th March 2014 at 02:01 AM.
20th June 2014, 08:36 AM   |  #2  
Junior Member
Thanks Meter: 0
 
1 posts
Join Date:Joined: Jun 2014
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?
Last edited by WizardOfOzzz; 20th June 2014 at 11:01 PM.
Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes