Linux下安装PAPI读取硬件性能计数器数据


零、PAPI简介

    PAPI (Performance Application Programming Interface),它是一套API,通过它可以访问CPU性能计数器,性能性能计数器的数据,

例如 L1/L2 Cache,CPU Cycle,CPU Instruction,TLB等.

    PAPI官网是: http://icl.cs.utk.edu/papi/

一、安装前提

    确保内核中安装了 perfctr 模块并且是动态加载方式(modprobe perfctr),并且支持APIC;
    
    确保 perfctr 使用正常,所有测试实例能够正常运行,例如 perfex -i;
    
   “perfctr 模块安装”请查看“Linux内核编译以及perfctr模块安装” 

二、安装步骤
  
    摘自papi目录下的INSTALL.txt文件, 以下是 papi-3.6.0 的安装步骤,其它版本的安装步骤也是如此。
   
General Installation

1. % ./configure
    % make

2. Check for errors.

 a) Run a simple test case: (This will run ctests/zero)

 % make test  测试,将会出现PASSED, FAILED, or SKIPPED三种结果,正常情况下应该是PASSED

 If you get good counts, you can optionally run all the test programs
 with the included test harness. This will run the tests in quiet mode,
 which will print PASSED, FAILED, or SKIPPED. Tests are SKIPPED if the
 functionality being tested is not supported by that platform.

 % make fulltest (This will run ./run_tests.sh)  所有的测试

 To run the tests in verbose mode:

 % ./run_tests.sh -v

3. Create a PAPI binary distribution or install PAPI directly.

 a) To install PAPI libraries and header files from the build tree:

 % make install  将会安装相关文件到/usr/local下,bin,include,lib

papi默认是安装在 /usr/local 下的,
papi可执行命令安装在bin下,似乎papi-3.6.0下没有papi_version命令,3.7.0有
papi的头文件放在include下,包括papiStdEventDefs.h、papi.h
papi的库文件放在lib下,包括静态库libpapi.a,动态库libpapi.so.3.6.0
[root@hdfs05 lib]# ll *papi*
-rw-r--r-- 1 root root 1842928 08-25 18:02 libpapi.a
lrwxrwxrwx 1 root root      16 08-25 18:02 libpapi.so -> libpapi.so.3.6.0
lrwxrwxrwx 1 root root      16 08-25 18:02 libpapi.so.3 -> libpapi.so.3.6.0
-rwxrwxr-x 1 zkl  zkl   631936 08-25 18:02 libpapi.so.3.6.0
还有share、man目录下也安装了一些东西
          

 b) To install PAPI manual pages from the build tree:

 % make install-man

 c) To install PAPI test programs from the build tree:

 % make install-tests

 d) To install all of the above in one step from the build tree:

 % make install-all

4. 由于papi的相关库安装在 /usr/local/lib 下,而我们编译程序链接动态或者静态库时,默认不会再 /usr/local/lib 下查找相关库的,所以为了在编译程序时可以自动链接/usr/local/lib下的papi相关库(例如: gcc ** -lpapi),我们做如下操作:

将 /usr/local/lib  加入文件 /etc/ld.so.conf 的最后一行,然后执行 ldconfig 命令

5. 编写一个 C 程序,调用 papi 相关函数,使用命令 gcc *.c -lpapi 命令编译,查看是否能够正常使用 PAPI .

相关内容