source: trunk/lib_ir/AgnerTestP/PMCTest/PMCTest.h @ 4221

Last change on this file since 4221 was 4221, checked in by linmengl, 5 years ago

initial checkin of Agner Fog's performance script

File size: 10.4 KB
Line 
1////// PMCTest.h ///////////////////////////////////////// 2014-09-30 //
2//
3//            Header file for multithreaded PMC Test program
4//
5// This header file is included by PMCTestA.cpp and PMCTestB.cpp.
6// Please see PMCTest.txt for description of the program.
7//
8// This header file contains class declarations, function prototypes,
9// constants and other definitions for this program.
10//
11// Copyright 2005-2014 by Agner Fog. GNU General Public License www.gnu.org/licences
12//////////////////////////////////////////////////////////////////////////////
13#pragma once
14
15// maximum number of threads. Must be 4 or 8.
16#if defined(_M_X64) || defined(__x86_64__) || defined(__amd64)
17#define MAXTHREADS  8
18#else
19#define MAXTHREADS  4
20#endif
21
22#include "MSRDriver.h"
23
24// maximum number of performance counters used
25const int MAXCOUNTERS = 6;
26
27// maximum number of repetitions
28const int MAXREPEAT = 128;
29
30// max name length of counters
31const int COUNTERNAMELEN = 10; 
32
33class CMSRInOutQue {
34public:
35    // constructor
36    CMSRInOutQue();
37    // put record in queue
38    int put (EMSR_COMMAND msr_command, unsigned int register_number,
39        unsigned int value_lo, unsigned int value_hi = 0);
40    // list of entries
41    SMSRInOut queue[MAX_QUE_ENTRIES+1];
42    // get size of queue
43    int GetSize () {return n;}
44protected:
45    // number of entries
46    int n;
47};
48
49#if defined(__WINDOWS__) || defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
50// System-specific definitions for Windows
51#include "PMCTestWin.h"
52#elif defined(__unix__) || defined(__linux__)
53// System-specific definitions for Linux
54#include "PMCTestLinux.h"
55#else
56#error Unknown platform
57#endif
58
59// codes for processor vendor
60enum EProcVendor {VENDOR_UNKNOWN = 0, INTEL, AMD, VIA};
61
62// codes for processor family
63enum EProcFamily {
64    PRUNKNOWN    = 0,                       // unknown. cannot do performance monitoring
65    PRALL        = 0xFFFFFFFF,              // All processors with the specified scheme (Renamed. Previous name P_ALL clashes with <sys/wait.h>)
66    INTEL_P1MMX  = 1,                       // Intel Pentium 1 or Pentium MMX
67    INTEL_P23    = 2,                       // Pentium Pro, Pentium 2, Pentium 3
68    INTEL_PM     = 4,                       // Pentium M, Core, Core 2
69    INTEL_P4     = 8,                       // Pentium 4 and Pentium 4 with EM64T
70    INTEL_CORE   = 0x10,                    // Intel Core Solo/Duo
71    INTEL_P23M   = 0x16,                    // Pentium Pro, Pentium 2, Pentium 3, Pentium M, Core1
72    INTEL_CORE2  = 0x20,                    // Intel Core 2
73    INTEL_7      = 0x40,                    // Intel Core i7, Nehalem, Sandy Bridge
74    INTEL_IVY    = 0x80,                    // Intel Ivy Bridge
75    INTEL_7I     = 0xC0,                    // Nehalem, Sandy Bridge, Ivy bridge
76    INTEL_HASW   = 0x100,                   // Intel Haswell and later
77    INTEL_ATOM   = 0x1000,                  // Intel Atom
78    INTEL_SILV   = 0x2000,                  // Intel Silvermont
79    AMD_ATHLON   = 0x10000,                 // AMD Athlon
80    AMD_ATHLON64 = 0x20000,                 // AMD Athlon 64 or Opteron
81    AMD_BULLD    = 0x80000,                 // AMD Family 15h (Bulldozer)
82    AMD_ALL      = 0xF0000,                 // AMD any processor
83
84    VIA_NANO     = 0x100000,                // VIA Nano (Centaur)
85};
86
87// codes for PMC scheme
88enum EPMCScheme {
89    S_UNKNOWN = 0,                           // unknown. can't do performance monitoring
90    S_P1   = 0x0001,                         // Intel Pentium, Pentium MMX
91    S_P4   = 0x0002,                         // Intel Pentium 4, Netburst
92    S_P2   = 0x0010,                         // Intel Pentium 2, Pentium M
93    S_ID1  = 0x0020,                         // Intel Core solo/duo
94    S_ID2  = 0x0040,                         // Intel Core 2
95    S_ID3  = 0x0080,                         // Intel Core i7 and later and Atom
96    S_P2MC = 0x0030,                         // Intel Pentium 2, Pentium M, Core solo/duo
97    S_ID23 = 0x00C0,                         // Intel Core 2 and later
98    S_INTL = 0x00F0,                         // Most Intel schemes
99    S_AMD  = 0x1000,                         // AMD processors
100    S_VIA  = 0x2000                          // VIA Nano processor and later
101};
102
103
104// record specifying how to count a particular event on a particular CPU family
105struct SCounterDefinition {
106    int          CounterType;                // ID identifying what to count
107    EPMCScheme   PMCScheme;                  // PMC scheme. values may be OR'ed
108    EProcFamily  ProcessorFamily;            // processor family. values may be OR'ed
109    int          CounterFirst, CounterLast;  // counter number or a range of possible alternative counter numbers
110    int          EventSelectReg;             // event select register
111    int          Event;                      // event code
112    int          EventMask;                  // event mask
113    char         Description[COUNTERNAMELEN];// name of counter. length must be < COUNTERNAMELEN
114};
115
116//!!
117class Dummytest {
118public:
119    Dummytest();
120};
121
122
123// class CCounters defines, starts and stops MSR counters
124class CCounters {
125public:
126    CCounters();                             // constructor
127    const char * DefineCounter(int CounterType);   // request a counter setup
128    const char * DefineCounter(SCounterDefinition & CounterDef); // request a counter setup
129    void LockProcessor();                    // Make program and driver use the same processor number
130    void QueueCounters();                    // Put counter definitions in queue
131    int  StartDriver();                      // Install and load driver
132    void StartCounters(int ThreadNum);       // start counting
133    void StopCounters (int ThreadNum);       // stop and reset counters
134    void CleanUp();                          // Any required cleanup of driver etc
135    CMSRDriver msr;                          // interface to MSR access driver
136    char * CounterNames[MAXCOUNTERS];        // name of each counter
137    void Put1 (int num_threads,              // put record into multiple start queues
138        EMSR_COMMAND msr_command, unsigned int register_number,
139        unsigned int value_lo, unsigned int value_hi = 0);
140    void Put2 (int num_threads,              // put record into multiple stop queues
141        EMSR_COMMAND msr_command, unsigned int register_number,
142        unsigned int value_lo, unsigned int value_hi = 0);
143    void GetProcessorVendor();               // get microprocessor vendor
144    void GetProcessorFamily();               // get microprocessor family
145    void GetPMCScheme();                     // get PMC scheme
146protected:
147    CMSRInOutQue queue1[64];                 // que of MSR commands to do by StartCounters()
148    CMSRInOutQue queue2[64];                 // que of MSR commands to do by StopCounters()
149    // translate event select number to register address for P4 processor:
150    static int GetP4EventSelectRegAddress(int CounterNr, int EventSelectNo); 
151    int NumCounterDefinitions;               // number of possible counter definitions in table CounterDefinitions
152    EProcVendor MVendor;                     // microprocessor vendor
153    EProcFamily MFamily;                     // microprocessor type and family
154    EPMCScheme  MScheme;                     // PMC monitoring scheme
155    int NumPMCs;                             // Number of general PMCs
156    int NumFixedPMCs;                        // Number of fixed function PMCs
157    int ProcessorNumber;                     // main thread processor number in multiprocessor systems
158};
159
160
161extern "C" {
162
163    // Link to PMCTestB.cpp, PMCTestB32.asm or PMCTestB64.asm:
164    // The basic test loop containing the code to test
165    int TestLoop (int thread);              // test loop
166
167}
168
169
170//////////////////////////////////////////////////////////////////////////////
171//    Global variables imported from PMCTestBxx module
172//////////////////////////////////////////////////////////////////////////////
173
174extern "C" {
175
176    extern SCounterDefinition CounterDefinitions[]; // List of all possible counters, in PMCTestA.cpp
177
178    extern int NumThreads;                  // number of threads
179    // performance counters used
180    extern int NumCounters;                // Number of PMC counters defined Counters[]
181    extern int MaxNumCounters;             // Maximum number of PMC counters
182    extern int UsePMC;                     // 0 if no PMC counters used
183    extern int CounterTypesDesired[MAXCOUNTERS];// list of desired counter types
184    extern int EventRegistersUsed[MAXCOUNTERS]; // index of counter registers used
185    extern int Counters[MAXCOUNTERS];      // PMC register numbers
186
187    // count results (all threads)
188    extern int * PThreadData;              // Pointer to measured data for all threads
189    extern int ThreadDataSize;             // Size of per-thread counter data block (bytes)
190    extern int ClockResultsOS;             // offset of clock results of first thread into ThreadData (bytes)
191    extern int PMCResultsOS;               // offset of PMC results of first thread into ThreadData (bytes)
192
193    // optional extra output of ratio between two performance counts
194    extern int RatioOut[4];                // RatioOut[0] = 0: no ratio output, 1 = int, 2 = float
195                                           // RatioOut[1] = numerator (0 = clock, 1 = first PMC, etc., -1 = none)
196                                           // RatioOut[2] = denominator (0 = clock, 1 = first PMC, etc., -1 = none)
197                                           // RatioOut[3] = factor, int or float according to RatioOut[0]
198
199    extern int TempOut;                    // Use CountTemp (possibly extended into CountOverhead) for arbitrary output
200                                           // 0 = no extra output
201                                           // 2 = signed 32-bit integer
202                                           // 3 = signed 64-bit integer
203                                           // 4 = 32-bit integer, hexadecimal
204                                           // 5 = 64-bit integer, hexadecimal
205                                           // 6 = float
206                                           // 7 = double
207    extern const char * RatioOutTitle;     // Column heading for optional extra output of ratio
208    extern const char * TempOutTitle;      // Column heading for optional arbitrary output
209}
Note: See TracBrowser for help on using the repository browser.