How to get perf_event results for 2nd Nexus7 with Krait CPU

心不动则不痛 提交于 2020-01-02 18:57:29

问题


all.

I try to get PMUs information such as Instructions, Cycle, Cache miss and etc. on 2nd Nexus7 with Krait CPU.

The perf tool is not working correctly.

Therefore, I am using follow a sample source code in perf_event tutorials.

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

    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_CPU_CYCLES;
    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 leader %llx\n", pe.config);
       exit(EXIT_FAILURE);
    }

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

    printf("Measuring Cycles for this printf\n");

    ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
    read(fd, &count, sizeof(long long));

    printf("Used %lld Cycles", count);

    close(fd);
}

I tried to run this code on x86 linux machine. The result show that "Used 123123 Cycles."

However, I couldn't get any PMUs event on 2nd nexus7. It always returns "Used 0 Cycles."

The PMU driver is enabled as follows.

<6>[ 0.152832] hw perfevents: enabled with ARMv7 Krait PMU driver, 5 counters available

Also, I can find perf_event_msm_krait.c in the flo kernel 3.4 which is used for my Nexus7. (I found a patch for supporting the Krait CPU; http://www.serverphorums.com/read.php?12,850329 . That includes perf_event_cpu.c file but I couldn't find it in kernel source. Is that way correct in order to support PMU for Nexus7 with Krait?)

Thank you in advance.

来源:https://stackoverflow.com/questions/21592301/how-to-get-perf-event-results-for-2nd-nexus7-with-krait-cpu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!