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: 4.1
11  * Released: 19.5.2016
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) 2016 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 {
84 
89 typedef enum {
90  STATE_NONE = 0,
93 } GroupState;
94 
100 
102 #define EVENT_OPTION_NONE_MASK 0x0ULL
103 
104 #define OPTIONS_TYPE_MASK(type) \
105  (((type == EVENT_OPTION_NONE)||(type >= NUM_EVENT_OPTIONS)) ? \
106  EVENT_OPTION_NONE_MASK : \
107  (1ULL<<type))
108 
109 
111 #define EVENT_OPTION_OPCODE_MASK (1ULL<<EVENT_OPTION_OPCODE)
112 #define EVENT_OPTION_MATCH0_MASK (1ULL<<EVENT_OPTION_MATCH0)
113 #define EVENT_OPTION_MATCH1_MASK (1ULL<<EVENT_OPTION_MATCH1)
114 #define EVENT_OPTION_MATCH2_MASK (1ULL<<EVENT_OPTION_MATCH2)
115 #define EVENT_OPTION_MATCH3_MASK (1ULL<<EVENT_OPTION_MATCH3)
116 #define EVENT_OPTION_MASK0_MASK (1ULL<<EVENT_OPTION_MASK0)
117 #define EVENT_OPTION_MASK1_MASK (1ULL<<EVENT_OPTION_MASK1)
118 #define EVENT_OPTION_MASK2_MASK (1ULL<<EVENT_OPTION_MASK2)
119 #define EVENT_OPTION_MASK3_MASK (1ULL<<EVENT_OPTION_MASK3)
120 #define EVENT_OPTION_NID_MASK (1ULL<<EVENT_OPTION_NID)
121 #define EVENT_OPTION_TID_MASK (1ULL<<EVENT_OPTION_TID)
122 #define EVENT_OPTION_STATE_MASK (1ULL<<EVENT_OPTION_STATE)
123 #define EVENT_OPTION_EDGE_MASK (1ULL<<EVENT_OPTION_EDGE)
124 #define EVENT_OPTION_THRESHOLD_MASK (1ULL<<EVENT_OPTION_THRESHOLD)
125 #define EVENT_OPTION_INVERT_MASK (1ULL<<EVENT_OPTION_INVERT)
126 #define EVENT_OPTION_COUNT_KERNEL_MASK (1ULL<<EVENT_OPTION_COUNT_KERNEL)
127 #define EVENT_OPTION_ANYTHREAD_MASK (1ULL<<EVENT_OPTION_ANYTHREAD)
128 #define EVENT_OPTION_OCCUPANCY_MASK (1ULL<<EVENT_OPTION_OCCUPANCY)
129 #define EVENT_OPTION_OCCUPANCY_FILTER_MASK (1ULL<<EVENT_OPTION_OCCUPANCY_FILTER)
130 #define EVENT_OPTION_OCCUPANCY_EDGE_MASK (1ULL<<EVENT_OPTION_OCCUPANCY_EDGE)
131 #define EVENT_OPTION_OCCUPANCY_INVERT_MASK (1ULL<<EVENT_OPTION_OCCUPANCY_INVERT)
132 #define EVENT_OPTION_IN_TRANS_MASK (1ULL<<EVENT_OPTION_IN_TRANS)
133 #define EVENT_OPTION_IN_TRANS_ABORT_MASK (1ULL<<EVENT_OPTION_IN_TRANS_ABORT)
134 
142 typedef struct {
143  int thread_id;
145 } PerfmonThread;
146 
153 typedef struct {
155  uint64_t value;
157 
165 typedef struct {
166  const char* name;
167  const char* limit;
168  uint16_t eventId;
169  uint8_t umask;
170  uint8_t cfgBits;
171  uint64_t cmask;
172  uint8_t numberOfOptions;
173  uint64_t optionMask;
175 } PerfmonEvent;
176 
183 typedef struct {
184  int init;
185  int id;
186  int overflows;
187  uint64_t startData;
188  uint64_t counterData;
189  double lastResult;
190  double fullResult;
192 
193 
199 typedef struct {
201  RegisterIndex index;
202  RegisterType type;
205 
211 typedef struct {
215  double rdtscTime;
216  double runTime;
217 #ifdef __x86_64
218  __uint128_t regTypeMask;
219 #else
220  uint64_t regTypeMask;
221 #endif
223  GroupInfo group;
225 
232 typedef struct {
240 
243 extern RegisterMap* counter_map;
247 extern BoxMap* box_map;
249 extern PerfmonEvent* eventHash;
251 extern PciDevice* pci_devices;
254 /* perfmon datatypes */
255 extern PerfmonGroupSet *groupSet;
256 extern int perfmon_numCounters;
257 extern int perfmon_numCoreCounters;
258 extern int perfmon_numUncoreCounters;
259 extern int perfmon_numArchEvents;
260 
261 
262 #endif /*PERFMON_TYPES_H*/
Set Thread ID.
Definition: perfmon_types.h:69
Not configured, not started and not stopped.
Definition: perfmon_types.h:90
double rdtscTime
Evaluation of the Time information in seconds.
Definition: perfmon_types.h:215
Mask1 register.
Definition: perfmon_types.h:65
RegisterIndex index
Index of the counter register in the counter map.
Definition: perfmon_types.h:201
Invert filter for occupancy counting.
Definition: perfmon_types.h:79
Count events that aborted during transactions.
Definition: perfmon_types.h:81
int numberOfEvents
Number of eventSets in events.
Definition: perfmon_types.h:212
EventOptionType type
Type of the option.
Definition: perfmon_types.h:154
uint64_t optionMask
Bitmask for fast check of set options.
Definition: perfmon_types.h:173
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:235
const char * name
Name of the event.
Definition: perfmon_types.h:166
Match3 register.
Definition: perfmon_types.h:63
uint64_t regTypeMask
Bitmask for easy checks which types are included in the eventSet.
Definition: perfmon_types.h:220
double fullResult
Aggregated measurement result.
Definition: perfmon_types.h:190
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:1022
uint8_t numberOfOptions
Number of options for the event.
Definition: perfmon_types.h:172
PerfmonEventSetEntry * events
List of eventSets.
Definition: perfmon_types.h:213
uint64_t startData
Start data from the counter.
Definition: perfmon_types.h:187
int id
Offset in higher level control register, e.g. position of enable bit.
Definition: perfmon_types.h:185
uint8_t cfgBits
Misc configuration bits.
Definition: perfmon_types.h:170
Structure specifying event/counter options and their value.
Definition: perfmon_types.h:153
Increment occupancy counter at detection of an edge.
Definition: perfmon_types.h:78
TimerData timer
Time information how long the counters were running.
Definition: perfmon_types.h:214
int init
Flag if corresponding control register is set up properly.
Definition: perfmon_types.h:184
PerfmonEvent event
Event configuration.
Definition: perfmon_types.h:200
Also count events when in kernel space.
Definition: perfmon_types.h:74
Structure specifying an performance monitoring event.
Definition: perfmon_types.h:199
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:216
EventOptionType
Enum of possible event and counter options.
Definition: perfmon_types.h:57
int processorId
Real HW thread ID.
Definition: perfmon_types.h:144
PerfmonThread * threads
List of threads.
Definition: perfmon_types.h:238
uint64_t counterData
Intermediate data from the counters.
Definition: perfmon_types.h:188
double lastResult
Last measurement result.
Definition: perfmon_types.h:189
GroupInfo group
Structure holding the performance group information.
Definition: perfmon_types.h:223
Match opcode.
Definition: perfmon_types.h:59
int numberOfThreads
Amount of threads in threads.
Definition: perfmon_types.h:237
int thread_id
Thread ID how it is used internally.
Definition: perfmon_types.h:143
uint64_t cmask
Misc mask bits.
Definition: perfmon_types.h:171
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:142
Mask3 register.
Definition: perfmon_types.h:67
The event set hold by group is configured.
Definition: perfmon_types.h:91
Match0 register.
Definition: perfmon_types.h:60
const char * limit
Valid counters for the event.
Definition: perfmon_types.h:167
Mask0 register.
Definition: perfmon_types.h:64
Amount of defined options.
Definition: perfmon_types.h:82
Increment only if exceeding threshold.
Definition: perfmon_types.h:72
uint16_t eventId
ID of the event.
Definition: perfmon_types.h:168
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:203
Structure specifying all performance monitoring event groups.
Definition: perfmon_types.h:232
Structure specifying an performance monitoring event group.
Definition: perfmon_types.h:211
int numberOfActiveGroups
Amount of added eventSets. Only those eventSets can be accessed in groups.
Definition: perfmon_types.h:234
RegisterType type
Type of the counter register and event.
Definition: perfmon_types.h:202
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:186
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 value
Value of the option.
Definition: perfmon_types.h:155
Increment counter at each edge.
Definition: perfmon_types.h:71
Structure specifying an performance monitoring event.
Definition: perfmon_types.h:165
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:236
GroupState
Enum of possible states of an event group.
Definition: perfmon_types.h:89
PciDevice * pci_devices
List of PCI devices available for the current architecture.
int numberOfGroups
List length of groups.
Definition: perfmon_types.h:233
Structure describing performance monitoring counter data.
Definition: perfmon_types.h:183
Mask2 register.
Definition: perfmon_types.h:66
uint8_t umask
Most events need to specify a mask to limit counting.
Definition: perfmon_types.h:169
GroupState state
Current state of the event group (configured, started, none)
Definition: perfmon_types.h:222
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:92