Hacker News new | ask | show | jobs
by lucian-g 1268 days ago
The current implementation of "default-perfevent" doesn't take into account perf counter multiplexing, so counters may be off if you have other perf measurements running in the background.

https://cpucycles.cr.yp.to/libcpucycles-20230105/cpucycles/d...

    memset(&attr,0,sizeof attr);
    attr.type = PERF_TYPE_HARDWARE;
    attr.size = sizeof(struct perf_event_attr);
    attr.config = PERF_COUNT_HW_CPU_CYCLES;
    attr.disabled = 1;
    attr.exclude_kernel = 1;
    attr.exclude_hv = 1;

    fddev = syscall(__NR_perf_event_open,&attr,0,-1,-1,0);

It needs to read time enabled / time running and scale returned values:

    attr.read_format = PERF_FORMAT_TOTAL_TIME_ENABLED | PERF_FORMAT_TOTAL_TIME_RUNNING;