我编写了以下代码来获取L3缓存未命中信息 .

#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <papi.h>

int main( int argc, char *argv[] ) {
  int i;

  long long counters[3];
  counters[0] = counters[1] = counters[2] = 0;
  int PAPI_events[] = {
    PAPI_TOT_CYC,
    PAPI_L3_TCM,
    PAPI_L3_DCA };

  PAPI_library_init(PAPI_VER_CURRENT);

  i = PAPI_start_counters(PAPI_events, 3);

  printf("Measuring instruction count for this printf\n");

  PAPI_read_counters(counters, 3);

  printf("%lld L3 cache misses %lld L3 cache accesses in %lld cycles"
   counters[1], counters[2], counters[0] );

  return 0;
}

但我得到一个错误和计数器零值如下 . 可能有什么不对?

PAPI Error: pfm_find_full_event(RETIRED_MISPREDICTED_BRANCH_INSTRUCTIONS,0x7fff22fe65a0): event not found.
PAPI Error: 1 of 4 events in papi_events.csv were not valid.
Measuring instruction count for this printf
0 L3 cache misses 0 L3 cache accesses in 0 cycles

我用papi_avail -a检查了可用的计数器,似乎支持计数器 . CPU信息如下 .

Available events and hardware information.
--------------------------------------------------------------------------------
PAPI Version             : 5.1.1.0
Vendor string and code   : GenuineIntel (1)
Model string and code    : Intel(R) Xeon(R) CPU E7- 4830  @ 2.13GHz (47)
CPU Revision             : 2.000000
CPUID Info               : Family: 6  Model: 47  Stepping: 2
CPU Max Megahertz        : 2128
CPU Min Megahertz        : 2128
Hdw Threads per core     : 1
Cores per Socket         : 8
NUMA Nodes               : 4
CPUs per Node            : 8
Total CPUs               : 32
Running in a VM          : no
Number Hardware Counters : 7
Max Multiplex Counters   : 64

uname输出

2.6.32-431.17.1.el6.x86_64 #1 SMP Fri Apr 11 17:27:00 EDT 2014 x86_64 x86_64 x86_64 GNU/Linux