HPCToolkit
DCPIMetricDesc.hpp
Go to the documentation of this file.
1 // -*-Mode: C++;-*-
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 //***************************************************************************
48 //
49 // File:
50 // DCPIMetricDesc.h
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // See, in particular, the comments associated with 'DCPIProfile'.
57 //
58 //***************************************************************************
59 
60 #ifndef DCPIMetricDesc_H
61 #define DCPIMetricDesc_H
62 
63 //************************* System Include Files ****************************
64 
65 #include <string>
66 
67 //*************************** User Include Files ****************************
68 
69 #include <include/uint.h>
70 
71 #include <lib/isa/ISATypes.hpp>
72 
73 //*************************** Forward Declarations ***************************
74 
75 //****************************************************************************
76 // DCPIMetricDesc
77 //****************************************************************************
78 
79 // ----------------------------------------------------------
80 
81 // Following are bit definitions for DCPI metrics for event types
82 // supported on Alpha 21264a+ (EV67+) processors.
83 //
84 // There are two sets of bits that occupy the same space (an implicit
85 // union): ProfileMe events form one set; non-ProfileMe events form
86 // the other set.
87 //
88 // ProfileMe bits:
89 // Bit layout: <type>[<counter><attribute><trap>]
90 //
91 // NonProfileMe (Regular) bits:
92 // Bit layout: <type><counter>
93 //
94 // The bits are set in such a way as to make certain common
95 // ProfileMe-based queries simple and fast.
96 
97 // For example, given several 'DCPIMetricDesc', suppose we want to
98 // find every ProfileMe metric that retired and was not mispredicted.
99 // We can easily find every such metric using a simple bitwise AND
100 // comparison with the 'DCPIMetricDesc' and the following query
101 // expression:
102 // (DCPI_MTYPE_PM | DCPI_PM_CNTR_count | DCPI_PM_ATTR_retired_T |
103 // DCPI_PM_TRAP_mispredict_F)
104 //
105 // Because each attribute gets two bits (a true and a false bit) we
106 // can easily find those metrics with certain attribute values. Note
107 // that this scheme only allows simple implementation of *conjuctive*
108 // query expressions; disjuctions will require much more work.
109 
110 // ----------------------------------------------------------
111 
112 // Type (2 bits; bit 0-1): DCPI has two distinct metric types:
113 // ProfileMe and 'regular' (traditional, non-ProfileMe metrics). (For
114 // an actual metric, only one of these bits should be set.)
115 
116 #define DCPI_MTYPE_PM UINT64_C(0x0000000000000001)
117 #define DCPI_MTYPE_RM UINT64_C(0x0000000000000002)
118 
119 // ----------------------------------------------------------
120 
121 // ProfileMe counters (6 bits; bits 2-7): The counter name. (There are
122 // three counters associated with each unique set of attributes^trap;
123 // we view each counter as a separate metric.) (For an actual metric,
124 // only one of these bits should be set.)
125 #define DCPI_PM_CNTR_MASK UINT64_C(0x00000000000000fc)
126 
127 #define DCPI_PM_CNTR_count UINT64_C(0x0000000000000004)
128 #define DCPI_PM_CNTR_inflight UINT64_C(0x0000000000000008)
129 #define DCPI_PM_CNTR_retires UINT64_C(0x0000000000000010)
130 #define DCPI_PM_CNTR_retdelay UINT64_C(0x0000000000000020)
131 #define DCPI_PM_CNTR_bcmisses UINT64_C(0x0000000000000040)
132 #define DCPI_PM_CNTR_replays UINT64_C(0x0000000000000080)
133 
134 // ProfileMe instruction attributes (22 bits; bits 8-29): Many
135 // attribute bits may be set in any given sample. Each attribute
136 // takes two bits to represent its presence or absence. (For an
137 // actual metric, only one bit for each attribute should be set.)
138 #define DCPI_PM_ATTR_MASK UINT64_C(0x000000003fffff00)
139 
140 #define DCPI_PM_ATTR_retired_T UINT64_C(0x0000000000000100)
141 #define DCPI_PM_ATTR_retired_F UINT64_C(0x0000000000000200)
142 #define DCPI_PM_ATTR_taken_T UINT64_C(0x0000000000000400)
143 #define DCPI_PM_ATTR_taken_F UINT64_C(0x0000000000000800)
144 #define DCPI_PM_ATTR_cbrmispredict_T UINT64_C(0x0000000000001000)
145 #define DCPI_PM_ATTR_cbrmispredict_F UINT64_C(0x0000000000002000)
146 #define DCPI_PM_ATTR_valid_T UINT64_C(0x0000000000004000)
147 #define DCPI_PM_ATTR_valid_F UINT64_C(0x0000000000008000)
148 #define DCPI_PM_ATTR_nyp_T UINT64_C(0x0000000000010000)
149 #define DCPI_PM_ATTR_nyp_F UINT64_C(0x0000000000020000)
150 #define DCPI_PM_ATTR_ldstorder_T UINT64_C(0x0000000000040000)
151 #define DCPI_PM_ATTR_ldstorder_F UINT64_C(0x0000000000080000)
152 #define DCPI_PM_ATTR_map_stall_T UINT64_C(0x0000000000100000)
153 #define DCPI_PM_ATTR_map_stall_F UINT64_C(0x0000000000200000)
154 #define DCPI_PM_ATTR_early_kill_T UINT64_C(0x0000000000400000)
155 #define DCPI_PM_ATTR_early_kill_F UINT64_C(0x0000000000800000)
156 #define DCPI_PM_ATTR_late_kill_T UINT64_C(0x0000000001000000)
157 #define DCPI_PM_ATTR_late_kill_F UINT64_C(0x0000000002000000)
158 #define DCPI_PM_ATTR_capped_T UINT64_C(0x0000000004000000)
159 #define DCPI_PM_ATTR_capped_F UINT64_C(0x0000000008000000)
160 #define DCPI_PM_ATTR_twnzrd_T UINT64_C(0x0000000010000000)
161 #define DCPI_PM_ATTR_twnzrd_F UINT64_C(0x0000000020000000)
162 
163 // ProfileMe instruction traps (16 bits; bits 32-47): Exactly one trap
164 // (or notrap, meaning none of the other traps) is set in any given
165 // metric. (For an actual metric, only one trap bit should be set.)
166 #define DCPI_PM_TRAP_MASK UINT64_C(0x0000ffff00000000)
167 
168 #define DCPI_PM_TRAP_notrap UINT64_C(0x0000000100000000)
169 #define DCPI_PM_TRAP_mispredict UINT64_C(0x0000000200000000)
170 #define DCPI_PM_TRAP_replays UINT64_C(0x0000000400000000)
171 #define DCPI_PM_TRAP_unaligntrap UINT64_C(0x0000000800000000)
172 #define DCPI_PM_TRAP_dtbmiss UINT64_C(0x0000001000000000)
173 #define DCPI_PM_TRAP_dtb2miss3 UINT64_C(0x0000002000000000)
174 #define DCPI_PM_TRAP_dtb2miss4 UINT64_C(0x0000004000000000)
175 #define DCPI_PM_TRAP_itbmiss UINT64_C(0x0000008000000000)
176 #define DCPI_PM_TRAP_arithtrap UINT64_C(0x0000010000000000)
177 #define DCPI_PM_TRAP_fpdisabledtrap UINT64_C(0x0000020000000000)
178 #define DCPI_PM_TRAP_MT_FPCRtrap UINT64_C(0x0000040000000000)
179 #define DCPI_PM_TRAP_dfaulttrap UINT64_C(0x0000080000000000)
180 #define DCPI_PM_TRAP_iacvtrap UINT64_C(0x0000100000000000)
181 #define DCPI_PM_TRAP_OPCDECtrap UINT64_C(0x0000200000000000)
182 #define DCPI_PM_TRAP_interrupt UINT64_C(0x0000400000000000)
183 #define DCPI_PM_TRAP_mchktrap UINT64_C(0x0000800000000000)
184 
185 // The negative versions of these require setting every bit except the
186 // referenced one.
187 #define DCPI_PM_TRAP_trap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_notrap)
188 #define DCPI_PM_TRAP_N_notrap DCPI_PM_TRAP_trap
189 
190 #define DCPI_PM_TRAP_N_mispredict (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_mispredict)
191 #define DCPI_PM_TRAP_N_replays (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_replays)
192 #define DCPI_PM_TRAP_N_unaligntrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_unaligntrap)
193 #define DCPI_PM_TRAP_N_dtbmiss (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_dtbmiss)
194 #define DCPI_PM_TRAP_N_dtb2miss3 (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_dtb2miss3)
195 #define DCPI_PM_TRAP_N_dtb2miss4 (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_dtb2miss4)
196 #define DCPI_PM_TRAP_N_itbmiss (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_itbmiss)
197 #define DCPI_PM_TRAP_N_arithtrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_arithtrap)
198 #define DCPI_PM_TRAP_N_fpdisabledtrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_fpdisabledtrap)
199 #define DCPI_PM_TRAP_N_MT_FPCRtrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_MT_FPCRtrap)
200 #define DCPI_PM_TRAP_N_dfaulttrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_dfaulttrap)
201 #define DCPI_PM_TRAP_N_iacvtrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_iacvtrap)
202 #define DCPI_PM_TRAP_N_OPCDECtrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_OPCDECtrap)
203 #define DCPI_PM_TRAP_N_interrupt (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_interrupt)
204 #define DCPI_PM_TRAP_N_mchktrap (DCPI_PM_TRAP_MASK & ~DCPI_PM_TRAP_mchktrap)
205 
206 
207 // ----------------------------------------------------------
208 
209 // Non-ProfileMe (regular metric) event types supported on Alpha
210 // 21264a+ (EV67+) processors (4 bits; bits 2-5)
211 #define DCPI_RM_CNTR_MASK UINT64_C(0x000000000000003c)
212 
213 #define DCPI_RM_cycles UINT64_C(0x0000000000000004)
214 #define DCPI_RM_retires UINT64_C(0x0000000000000008)
215 #define DCPI_RM_replaytrap UINT64_C(0x0000000000000010)
216 #define DCPI_RM_bmiss UINT64_C(0x0000000000000020)
217 
218 // ----------------------------------------------------------
219 
220 // DCPIMetricDesc: A complete description of a DCPI metric for event
221 // types supported on Alpha 21264a+ (EV67+) processors.
223 public:
224  typedef uint64_t bitvec_t;
225 
226 public:
227  // A 'DCPIMetricDesc' can be created using either the bit
228  // definitions above or a string of the same format used in
229  // 'dcpicat'.
230  DCPIMetricDesc(bitvec_t bv = 0) : bits(bv) { }
231  DCPIMetricDesc(const char* str);
232  DCPIMetricDesc(const std::string& str);
233  virtual ~DCPIMetricDesc() { }
234 
235  DCPIMetricDesc(const DCPIMetricDesc& x) { *this = x; }
237  bits = x.bits;
238  return *this;
239  }
240 
241  // Some simple queries
242  bool IsTypeProfileMe() { return IsSet(DCPI_MTYPE_PM); }
243  bool IsTypeRegular() { return IsSet(DCPI_MTYPE_RM); }
244 
245  // IsValid: If no bits are set, this must be an invalid descriptor
246  bool IsValid() const { return bits != 0; }
247 
248  // IsSet: Tests to see if *all* the specified bits are set
249  bool IsSet(const bitvec_t bv) const {
250  return (bits & bv) == bv;
251  }
252  bool IsSet(const DCPIMetricDesc& m) const {
253  return (bits & m.bits) == m.bits;
254  }
255  // IsSetAny: Tests to see if *any* of the specified bits are set
256  bool IsSetAny(const bitvec_t bv) const {
257  return (bits & bv) != 0;
258  }
259  bool IsSetAny(const DCPIMetricDesc& m) const {
260  return (bits & m.bits) != 0;
261  }
262  // Set: Set all the specified bits
263  void Set(const bitvec_t bv) {
264  bits = bits | bv;
265  }
266  void Set(const DCPIMetricDesc& m) {
267  bits = bits | m.bits;
268  }
269  // Unset: Clears all the specified bits
270  void Unset(const bitvec_t bv) {
271  bits = bits & ~bv;
272  }
273  void Unset(const DCPIMetricDesc& m) {
274  bits = bits & ~(m.bits);
275  }
276 
277 
278  void Dump(std::ostream& o = std::cerr);
279  void DDump();
280 
281 private:
282  void Ctor(const char* str);
283 
284 protected:
285  bitvec_t bits;
286 private:
287 };
288 
289 
290 // Convert a string describing a DCPI metric into a 'DCPIMetricDesc'.
291 // The string should have the format used in 'dcpicat'. The following
292 // is a slightly modified format used by the DCPI tools (cf. ProfileMe
293 // man page: man dcpiprofileme).
294 //
295 // Assumed format:
296 // string ::= ProfileMe_sample_set *
297 // | ProfileMe_counter *
298 // | ProfileMe_sample_set:ProfileMe_counter
299 // | Regular_counter
300 //
301 // ProfileMe_sample_set ::= bit_value
302 // | ProfileMe_sample_set ^ bit_value
303 // { | any }+
304 //
305 // bit_value ::= <Attr Bit Name>
306 // | ! <Attr Bit Name>
307 // | <Trap Bit Name>
308 // | ! <Trap Bit Name>
309 //
310 // Note: trap can be used as a synonym for !notrap.
311 //
312 // Notes:
313 // * Note that by themselves these are invalid metrics. However we
314 // allow the parsing of subexpressions that can be spliced together to
315 // form a valid event.
316 // + We do not support this.
317 //
318 
320 String2DCPIMetricDesc(const char* str);
321 
322 //****************************************************************************
323 
324 #endif
325 
void Ctor(const char *str)
virtual ~DCPIMetricDesc()
DCPIMetricDesc & operator=(const DCPIMetricDesc &x)
void Set(const DCPIMetricDesc &m)
bool IsSet(const bitvec_t bv) const
bool IsSetAny(const bitvec_t bv) const
bool IsSet(const DCPIMetricDesc &m) const
void Set(const bitvec_t bv)
DCPIMetricDesc String2DCPIMetricDesc(const char *str)
DCPIMetricDesc(const DCPIMetricDesc &x)
#define DCPI_MTYPE_RM
#define DCPI_MTYPE_PM
bool IsValid() const
void Dump(std::ostream &o=std::cerr)
DCPIMetricDesc(bitvec_t bv=0)
void Unset(const DCPIMetricDesc &m)
bool IsSetAny(const DCPIMetricDesc &m) const
void Unset(const bitvec_t bv)