Advertisement
Guest User

perfcountdemo.c

a guest
Dec 31st, 2015
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.76 KB | None | 0 0
  1. /* Includes */
  2. #include "libperfcount.h"
  3. #include <ctype.h>
  4. #include <stdint.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8.  
  9.  
  10. /* Function prototypes */
  11. void code1(void);
  12. void code2(void);
  13. void code3(void);
  14. void code4(void);
  15. void code5(void);
  16.  
  17. /* Global variables */
  18. void ((*FN_TABLE[])(void)) = {
  19.     code1,
  20.     code2,
  21.     code3,
  22.     code4,
  23.     code5
  24. };
  25.  
  26.  
  27. /**
  28.  * Code snippets to bench
  29.  */
  30.  
  31. void code1(void){
  32.     asm volatile(
  33.     ".intel_syntax noprefix\n\t"
  34.     "vzeroall\n\t"
  35.     "mov             rcx, 1000000000\n\t"
  36.     "LstartLabel1:\n\t"
  37.     "vfmadd231ps     %%ymm0, %%ymm0, %%ymm0\n\t"
  38.     "vfmadd231ps     ymm1, ymm1, ymm1\n\t"
  39.     "vfmadd231ps     ymm2, ymm2, ymm2\n\t"
  40.     "vfmadd231ps     ymm3, ymm3, ymm3\n\t"
  41.     "vfmadd231ps     ymm4, ymm4, ymm4\n\t"
  42.     "vfmadd231ps     ymm5, ymm5, ymm5\n\t"
  43.     "vfmadd231ps     ymm6, ymm6, ymm6\n\t"
  44.     "vfmadd231ps     ymm7, ymm7, ymm7\n\t"
  45.     "vfmadd231ps     ymm8, ymm8, ymm8\n\t"
  46.     "vfmadd231ps     ymm9, ymm9, ymm9\n\t"
  47.     "vpaddd          ymm10, ymm10, ymm10\n\t"
  48.     "vpaddd          ymm11, ymm11, ymm11\n\t"
  49.     "vpaddd          ymm12, ymm12, ymm12\n\t"
  50.     "vpaddd          ymm13, ymm13, ymm13\n\t"
  51.     "vpaddd          ymm14, ymm14, ymm14\n\t"
  52.     "dec             rcx\n\t"
  53.     "jnz             LstartLabel1\n\t"
  54.     ".att_syntax noprefix\n\t"
  55.     : /* No outputs we care about */
  56.     : /* No inputs we care about */
  57.     : "xmm0",  "xmm1",  "xmm2",  "xmm3",  "xmm4",  "xmm5",  "xmm6",  "xmm7",
  58.       "xmm8",  "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
  59.       "rcx",
  60.       "memory"
  61.     );
  62. }
  63. void code2(void){
  64.    
  65. }
  66. void code3(void){
  67.    
  68. }
  69. void code4(void){
  70.    
  71. }
  72. void code5(void){
  73.    
  74. }
  75.  
  76.  
  77.  
  78. /* Test Schedule */
  79. const char* const SCHEDULE[] = {
  80.     /* Batch */
  81.     "uops_issued.any",
  82.     "uops_issued.any<1",
  83.     "uops_issued.any>=1",
  84.     "uops_issued.any>=2",
  85.     /* Batch */
  86.     "uops_issued.any>=3",
  87.     "uops_issued.any>=4",
  88.     "uops_issued.any>=5",
  89.     "uops_issued.any>=6",
  90.     /* Batch */
  91.     "uops_executed_port.port_0",
  92.     "uops_executed_port.port_1",
  93.     "uops_executed_port.port_2",
  94.     "uops_executed_port.port_3",
  95.     /* Batch */
  96.     "uops_executed_port.port_4",
  97.     "uops_executed_port.port_5",
  98.     "uops_executed_port.port_6",
  99.     "uops_executed_port.port_7",
  100.     /* Batch */
  101.     "resource_stalls.any",
  102.     "resource_stalls.rs",
  103.     "resource_stalls.sb",
  104.     "resource_stalls.rob",
  105.     /* Batch */
  106.     "uops_retired.all",
  107.     "uops_retired.all<1",
  108.     "uops_retired.all>=1",
  109.     "uops_retired.all>=2",
  110.     /* Batch */
  111.     "uops_retired.all>=3",
  112.     "uops_retired.all>=4",
  113.     "uops_retired.all>=5",
  114.     "uops_retired.all>=6",
  115.     /* Batch */
  116.     "inst_retired.any_p",
  117.     "inst_retired.any_p<1",
  118.     "inst_retired.any_p>=1",
  119.     "inst_retired.any_p>=2",
  120.     /* Batch */
  121.     "inst_retired.any_p>=3",
  122.     "inst_retired.any_p>=4",
  123.     "inst_retired.any_p>=5",
  124.     "inst_retired.any_p>=6",
  125.     /* Batch */
  126.     "idq_uops_not_delivered.core",
  127.     "idq_uops_not_delivered.core<1",
  128.     "idq_uops_not_delivered.core>=1",
  129.     "idq_uops_not_delivered.core>=2",
  130.     /* Batch */
  131.     "idq_uops_not_delivered.core>=3",
  132.     "idq_uops_not_delivered.core>=4",
  133.     "rs_events.empty",
  134.     "idq.empty",
  135.     /* Batch */
  136.     "idq.mite_all_uops",
  137.     "idq.mite_all_uops<1",
  138.     "idq.mite_all_uops>=1",
  139.     "idq.mite_all_uops>=2",
  140.     /* Batch */
  141.     "idq.mite_all_uops>=3",
  142.     "idq.mite_all_uops>=4",
  143.     "move_elimination.int_not_eliminated",
  144.     "move_elimination.simd_not_eliminated",
  145.     /* Batch */
  146.     "lsd.uops",
  147.     "lsd.uops<1",
  148.     "lsd.uops>=1",
  149.     "lsd.uops>=2",
  150.     /* Batch */
  151.     "lsd.uops>=3",
  152.     "lsd.uops>=4",
  153.     "ild_stall.lcp",
  154.     "ild_stall.iq_full",
  155.     /* Batch */
  156.     "br_inst_exec.all_branches",
  157.     "br_inst_exec.0x81",
  158.     "br_inst_exec.0x82",
  159.     "icache.misses",
  160.     /* Batch */
  161.     "br_misp_exec.all_branches",
  162.     "br_misp_exec.0x81",
  163.     "br_misp_exec.0x82",
  164.     "fp_assist.any",
  165.     /* Batch */
  166.     "cpu_clk_unhalted.core_clk",
  167.     "cpu_clk_unhalted.ref_xclk",
  168.     "baclears.any"
  169.    
  170. };
  171. const int NUMCOUNTS = sizeof(SCHEDULE)/sizeof(*SCHEDULE);
  172.  
  173.  
  174. /**
  175.  * Main
  176.  */
  177.  
  178. int main(int argc, char* argv[]){
  179.     int i;
  180.    
  181.     /**
  182.      * Initialize
  183.      */
  184.    
  185.     pfcInit();
  186.     if(argc <= 1){
  187.         pfcDumpEvents();
  188.         exit(1);
  189.     }
  190.     pfcPinThread(3);
  191.    
  192.    
  193.     /**
  194.      * Arguments are:
  195.      *
  196.      *     perfcountdemo #codesnippet
  197.      *
  198.      * There is a schedule of configuration that is followed.
  199.      */
  200.    
  201.     void (*fn)(void) = FN_TABLE[strtoull(argv[1], NULL, 0)];
  202.     static const uint64_t ZERO_CNT[7] = {0,0,0,0,0,0,0};
  203.     static const uint64_t ZERO_CFG[7] = {0,0,0,0,0,0,0};
  204.    
  205.     uint64_t cnt[7]                   = {0,0,0,0,0,0,0};
  206.     uint64_t cfg[7]                   = {2,2,2,0,0,0,0};
  207.    
  208.     /* Warmup */
  209.     for(i=0;i<10;i++){
  210.         fn();
  211.     }
  212.    
  213.     /* Run master loop */
  214.     for(i=0;i<NUMCOUNTS;i+=4){
  215.         /* Configure counters */
  216.         const char* sched0 = i+0 < NUMCOUNTS ? SCHEDULE[i+0] : "";
  217.         const char* sched1 = i+1 < NUMCOUNTS ? SCHEDULE[i+1] : "";
  218.         const char* sched2 = i+2 < NUMCOUNTS ? SCHEDULE[i+2] : "";
  219.         const char* sched3 = i+3 < NUMCOUNTS ? SCHEDULE[i+3] : "";
  220.         cfg[3] = pfcParseConfig(sched0);
  221.         cfg[4] = pfcParseConfig(sched1);
  222.         cfg[5] = pfcParseConfig(sched2);
  223.         cfg[6] = pfcParseConfig(sched3);
  224.        
  225.         pfcWrConfigCnts(0, 7, cfg);
  226.         pfcWrCountsCnts(0, 7, ZERO_CNT);
  227.         pfcRdCountsCnts(0, 7, cnt);
  228.         /* ^ Should report 0s, and launch the counters. */
  229.         /************** Hot section **************/
  230.         fn();
  231.         /************ End Hot section ************/
  232.         pfcRdCountsCnts(0, 7, cnt);
  233.         pfcWrConfigCnts(0, 7, ZERO_CFG);
  234.         /* ^ Should clear the counter config and disable them. */
  235.        
  236.         /**
  237.          * Print the lovely results
  238.          */
  239.        
  240.         printf("Instructions Issued                : %20llu\n", cnt[0]);
  241.         printf("Unhalted core cycles               : %20llu\n", cnt[1]);
  242.         printf("Unhalted reference cycles          : %20llu\n", cnt[2]);
  243.         printf("%-35s: %20llu\n", sched0, cnt[3]);
  244.         printf("%-35s: %20llu\n", sched1, cnt[4]);
  245.         printf("%-35s: %20llu\n", sched2, cnt[5]);
  246.         printf("%-35s: %20llu\n", sched3, cnt[6]);
  247.     }
  248.    
  249.     /**
  250.      * Close up shop
  251.      */
  252.    
  253.     pfcFini();
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement