LIKWID
perfmon_types.h
1 /*
2  * =======================================================================================
3  *
4  * Filename: perfmon_types.h
5  *
6  * Description: Header File of perfmon module.
7  * Configures and reads out performance counters
8  * on x86 based architectures. Supports multi threading.
9  *
10  * Version: <VERSION>
11  * Released: <DATE>
12  *
13  * Author: Jan Treibig (jt), jan.treibig@gmail.com
14  * Thomas Roehl (tr), thomas.roehl@googlemail.com
15  * Project: likwid
16  *
17  * Copyright (C) 2015 RRZE, University Erlangen-Nuremberg
18  *
19  * This program is free software: you can redistribute it and/or modify it under
20  * the terms of the GNU General Public License as published by the Free Software
21  * Foundation, either version 3 of the License, or (at your option) any later
22  * version.
23  *
24  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
25  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
26  * PARTICULAR PURPOSE. See the GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License along with
29  * this program. If not, see <http://www.gnu.org/licenses/>.
30  *
31  * =======================================================================================
32  */
33 
34 #ifndef PERFMON_TYPES_H
35 #define PERFMON_TYPES_H
36 
37 #include <bstrlib.h>
38 #include <timer.h>
39 #include <inttypes.h>
40 #include <perfgroup.h>
41 
42 #define MAX_EVENT_OPTIONS NUM_EVENT_OPTIONS
43 
44 /* ##### EXPORTED TYPE DEFINITIONS #################################### */
45 
49 
57 typedef enum {
82 #ifdef LIKWID_USE_PERFEVENT
83  EVENT_OPTION_PERF_PID,
84  EVENT_OPTION_PERF_FLAGS,
85 #endif
88 
93 typedef enum {
94  STATE_NONE = 0,
97 } GroupState;
98 
104 
106 #define EVENT_OPTION_NONE_MASK 0x0ULL
107 
108 #define OPTIONS_TYPE_MASK(type) \
109  (((type == EVENT_OPTION_NONE)||(type >= NUM_EVENT_OPTIONS)) ? \
110  EVENT_OPTION_NONE_MASK : \
111  (1ULL<<type))
112 
113 
115 #define EVENT_OPTION_OPCODE_MASK (1ULL<<EVENT_OPTION_OPCODE)
116 #define EVENT_OPTION_MATCH0_MASK (1ULL<<EVENT_OPTION_MATCH0)
117 #define EVENT_OPTION_MATCH1_MASK (1ULL<<EVENT_OPTION_MATCH1)
118 #define EVENT_OPTION_MATCH2_MASK (1ULL<<EVENT_OPTION_MATCH2)
119 #define EVENT_OPTION_MATCH3_MASK (1ULL<<EVENT_OPTION_MATCH3)
120 #define EVENT_OPTION_MASK0_MASK (1ULL<<EVENT_OPTION_MASK0)
121 #define EVENT_OPTION_MASK1_MASK (1ULL<<EVENT_OPTION_MASK1)
122 #define EVENT_OPTION_MASK2_MASK (1ULL<<EVENT_OPTION_MASK2)
123 #define EVENT_OPTION_MASK3_MASK (1ULL<<EVENT_OPTION_MASK3)
124 #define EVENT_OPTION_NID_MASK (1ULL<<EVENT_OPTION_NID)
125 #define EVENT_OPTION_TID_MASK (1ULL<<EVENT_OPTION_TID)
126 #define EVENT_OPTION_STATE_MASK (1ULL<<EVENT_OPTION_STATE)
127 #define EVENT_OPTION_EDGE_MASK (1ULL<<EVENT_OPTION_EDGE)
128 #define EVENT_OPTION_THRESHOLD_MASK (1ULL<<EVENT_OPTION_THRESHOLD)
129 #define EVENT_OPTION_INVERT_MASK (1ULL<<EVENT_OPTION_INVERT)
130 #define EVENT_OPTION_COUNT_KERNEL_MASK (1ULL<<EVENT_OPTION_COUNT_KERNEL)
131 #define EVENT_OPTION_ANYTHREAD_MASK (1ULL<<EVENT_OPTION_ANYTHREAD)
132 #define EVENT_OPTION_OCCUPANCY_MASK (1ULL<<EVENT_OPTION_OCCUPANCY)
133 #define EVENT_OPTION_OCCUPANCY_FILTER_MASK (1ULL<<EVENT_OPTION_OCCUPANCY_FILTER)
134 #define EVENT_OPTION_OCCUPANCY_EDGE_MASK (1ULL<<EVENT_OPTION_OCCUPANCY_EDGE)
135 #define EVENT_OPTION_OCCUPANCY_INVERT_MASK (1ULL<<EVENT_OPTION_OCCUPANCY_INVERT)
136 #define EVENT_OPTION_IN_TRANS_MASK (1ULL<<EVENT_OPTION_IN_TRANS)
137 #define EVENT_OPTION_IN_TRANS_ABORT_MASK (1ULL<<EVENT_OPTION_IN_TRANS_ABORT)
138 
146 typedef struct {
147  int thread_id;
149 } PerfmonThread;
150 
157 typedef struct {
159  uint64_t value;
161 
169 typedef struct {
170  const char* name;
171  const char* limit;
172  uint16_t eventId;
173  uint8_t umask;
174  uint8_t cfgBits;
175  uint64_t cmask;
176  uint8_t numberOfOptions;
177  uint64_t optionMask;
179 } PerfmonEvent;
180 
187 typedef struct {
188  int init;
189  int id;
190  int overflows;
191  uint64_t startData;
192  uint64_t counterData;
193  double lastResult;
194  double fullResult;
196 
197 
203 typedef struct {
205  RegisterIndex index;
206  RegisterType type;
209 
215 typedef struct {
219  double rdtscTime;
220  double runTime;
221  uint64_t regTypeMask1;
222  uint64_t regTypeMask2;
223  uint64_t regTypeMask3;
224  uint64_t regTypeMask4;
226  GroupInfo group;
228 
235 typedef struct {
243 
246 extern RegisterMap* counter_map;
250 extern BoxMap* box_map;
252 extern PerfmonEvent* eventHash;
254 extern PciDevice* pci_devices;
257 /* perfmon datatypes */
258 extern PerfmonGroupSet *groupSet;
259 extern int perfmon_numCounters;
260 extern int perfmon_numCoreCounters;
261 extern int perfmon_numUncoreCounters;
262 extern int perfmon_numArchEvents;
263 
264 
265 #endif /*PERFMON_TYPES_H*/
Set Thread ID.
Definition: perfmon_types.h:69
Not configured, not started and not stopped.
Definition: perfmon_types.h:94
double rdtscTime
Evaluation of the Time information in seconds.
Definition: perfmon_types.h:219
Mask1 register.
Definition: perfmon_types.h:65
RegisterIndex index
Index of the counter register in the counter map.
Definition: perfmon_types.h:205
Invert filter for occupancy counting.
Definition: perfmon_types.h:79
Count events that aborted during transactions.
Definition: perfmon_types.h:81
uint64_t regTypeMask1
Bitmask1 for easy checks which types are included in the eventSet.
Definition: perfmon_types.h:221
int numberOfEvents
Number of eventSets in events.
Definition: perfmon_types.h:216
EventOptionType type
Type of the option.
Definition: perfmon_types.h:158
uint64_t optionMask
Bitmask for fast check of set options.
Definition: perfmon_types.h:177
Count events during transactions.
Definition: perfmon_types.h:80
PerfmonEvent * eventHash
List of events available for the current architecture.
int activeGroup
Currently active eventSet.
Definition: perfmon_types.h:238
const char * name
Name of the event.
Definition: perfmon_types.h:170
Match3 register.
Definition: perfmon_types.h:63
double fullResult
Aggregated measurement result.
Definition: perfmon_types.h:194
Match1 register.
Definition: perfmon_types.h:61
Increment counter at events of all HW threads in the core.
Definition: perfmon_types.h:75
Struct defining the start and stop time of a time interval.
Definition: likwid.h:1034
uint8_t numberOfOptions
Number of options for the event.
Definition: perfmon_types.h:176
PerfmonEventSetEntry * events
List of eventSets.
Definition: perfmon_types.h:217
uint64_t startData
Start data from the counter.
Definition: perfmon_types.h:191
int id
Offset in higher level control register, e.g. position of enable bit.
Definition: perfmon_types.h:189
uint8_t cfgBits
Misc configuration bits.
Definition: perfmon_types.h:174
Structure specifying event/counter options and their value.
Definition: perfmon_types.h:157
Increment occupancy counter at detection of an edge.
Definition: perfmon_types.h:78
uint64_t regTypeMask3
Bitmask3 for easy checks which types are included in the eventSet.
Definition: perfmon_types.h:223
TimerData timer
Time information how long the counters were running.
Definition: perfmon_types.h:218
int init
Flag if corresponding control register is set up properly.
Definition: perfmon_types.h:188
PerfmonEvent event
Event configuration.
Definition: perfmon_types.h:204
Also count events when in kernel space.
Definition: perfmon_types.h:74
Structure specifying an performance monitoring event.
Definition: perfmon_types.h:203
char * eventOptionTypeName[NUM_EVENT_OPTIONS]
List of option names.
double runTime
Sum of all time information in seconds that the group was running.
Definition: perfmon_types.h:220
EventOptionType
Enum of possible event and counter options.
Definition: perfmon_types.h:57
int processorId
Real HW thread ID.
Definition: perfmon_types.h:148
PerfmonThread * threads
List of threads.
Definition: perfmon_types.h:241
uint64_t counterData
Intermediate data from the counters.
Definition: perfmon_types.h:192
double lastResult
Last measurement result.
Definition: perfmon_types.h:193
GroupInfo group
Structure holding the performance group information.
Definition: perfmon_types.h:226
Match opcode.
Definition: perfmon_types.h:59
int numberOfThreads
Amount of threads in threads.
Definition: perfmon_types.h:240
int thread_id
Thread ID how it is used internally.
Definition: perfmon_types.h:147
uint64_t cmask
Misc mask bits.
Definition: perfmon_types.h:175
No option, used as False value.
Definition: perfmon_types.h:58
Match for state.
Definition: perfmon_types.h:70
Structure specifying thread to CPU relation.
Definition: perfmon_types.h:146
Mask3 register.
Definition: perfmon_types.h:67
The event set hold by group is configured.
Definition: perfmon_types.h:95
Match0 register.
Definition: perfmon_types.h:60
const char * limit
Valid counters for the event.
Definition: perfmon_types.h:171
Mask0 register.
Definition: perfmon_types.h:64
Amount of defined options.
Definition: perfmon_types.h:86
Increment only if exceeding threshold.
Definition: perfmon_types.h:72
uint16_t eventId
ID of the event.
Definition: perfmon_types.h:172
Set NUMA node ID.
Definition: perfmon_types.h:68
PerfmonCounter * threadCounter
List of counter data for each thread, list length is numberOfThreads in PerfmonGroupSet.
Definition: perfmon_types.h:207
Structure specifying all performance monitoring event groups.
Definition: perfmon_types.h:235
Structure specifying an performance monitoring event group.
Definition: perfmon_types.h:215
int numberOfActiveGroups
Amount of added eventSets. Only those eventSets can be accessed in groups.
Definition: perfmon_types.h:237
RegisterType type
Type of the counter register and event.
Definition: perfmon_types.h:206
Invert behavior of EVENT_OPTION_THRESHOLD, hence increment only below threshold.
Definition: perfmon_types.h:73
int overflows
Amount of overflows.
Definition: perfmon_types.h:190
BoxMap * box_map
List of boxes with name, config register, counter registers and if needed PCI device. Mainly used in Uncore handling but also core-local counters are defined as a box.
uint64_t regTypeMask2
Bitmask2 for easy checks which types are included in the eventSet.
Definition: perfmon_types.h:222
uint64_t value
Value of the option.
Definition: perfmon_types.h:159
Increment counter at each edge.
Definition: perfmon_types.h:71
Structure specifying an performance monitoring event.
Definition: perfmon_types.h:169
RegisterMap * counter_map
List of counter with name, config register, counter registers and if needed PCI device.
Match2 register.
Definition: perfmon_types.h:62
PerfmonEventSet * groups
List of eventSets.
Definition: perfmon_types.h:239
uint64_t regTypeMask4
Bitmask4 for easy checks which types are included in the eventSet.
Definition: perfmon_types.h:224
GroupState
Enum of possible states of an event group.
Definition: perfmon_types.h:93
PciDevice * pci_devices
List of PCI devices available for the current architecture.
int numberOfGroups
List length of groups.
Definition: perfmon_types.h:236
Structure describing performance monitoring counter data.
Definition: perfmon_types.h:187
Mask2 register.
Definition: perfmon_types.h:66
uint8_t umask
Most events need to specify a mask to limit counting.
Definition: perfmon_types.h:173
GroupState state
Current state of the event group (configured, started, none)
Definition: perfmon_types.h:225
Filter for occupancy counting.
Definition: perfmon_types.h:77
Count occupancy not occurrences.
Definition: perfmon_types.h:76
The event set hold by group is current running.
Definition: perfmon_types.h:96