HPCToolkit
DCPIProfileFilter.cpp
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 // DCPIFilterExpr.C
51 //
52 // Purpose:
53 // [The purpose of this file]
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 //***************************************************************************
59 
60 //************************* System Include Files ****************************
61 
62 #include <iostream>
63 
64 #include <cstring>
65 
66 //*************************** User Include Files ****************************
67 
68 #include "PCProfileFilter.hpp"
69 #include "DCPIProfileFilter.hpp"
70 #include "DCPIProfileMetric.hpp"
71 
73 
74 //*************************** Forward Declarations ***************************
75 
76 using std::endl;
77 using std::hex;
78 using std::dec;
79 
80 
81 //****************************************************************************
82 // PredefinedDCPIMetricTable
83 //****************************************************************************
84 
85 #define TABLE_SZ \
86  sizeof(PredefinedDCPIMetricTable::table) / sizeof(PredefinedDCPIMetricTable::Entry)
87 
88 
89 
90 // --------------------------------------------------------------------------
91 // NOTE:
92 // the availability of non-ProfileMe metrics must be determined
93 // by string matching. Thus, the 'availStr' *must* match the metric names
94 // found in dcpicat output (DCPIProfile)
95 // --------------------------------------------------------------------------
96 
98 
99  // non-ProfileMe metric
100  { "CYCLES", "Processor cycles",
101  RM, "cycles",
104  },
105 
106  // -------------------------------------------------------
107  // Each ProfileMe metric is marked with the modes (PM mode)
108  // in which it is available
109  // -------------------------------------------------------
110 
111  // We generally avoid metrics with early_kill set: When a profiled
112  // instruction is killed early in the pipeline (early_kill is set),
113  // the PC reported by the hardware may be wrong and all counter
114  // values and bits other than valid, early_kill, no_trap, and and
115  // map_stall may be wrong.
116 
117  // available in ProfileMe mode PM1 only
118  {"pmRETDEL", "Delays before retire (excludes all cycles prior to fetch).",
119  PM1, NULL,
123  },
124 
125  // FIXME: Can we cross check with the retire counter for mode 0, 2
126  {"INSTRUCT", "Retired Instructions (includes mispredicted branches)",
127  PM0 | PM1 | PM2 | PM3, NULL,
131  },
132 
133  {"FLOPS", "Retired FP Instructions (includes mispredicted branches)",
134  PM0 | PM1 | PM2 | PM3, NULL,
138  },
139 
140  {"MEMOPS", "Retired Memory Access Instructions",
141  PM0 | PM1 | PM2 | PM3, NULL,
145  },
146 
147  {"INTOPS", "Retired Integer Instructions",
148  PM0 | PM1 | PM2 | PM3, NULL,
152  },
153 
154  {"TRAPS", "Instructions causing traps",
155  PM0 | PM1 | PM2 | PM3, NULL,
159  },
160 
161  {"LSREPLAY", "Replays caused by load/store ordering. [Untested]",
162  PM0 | PM1 | PM2 | PM3, NULL,
166  },
167 
168  {"MPBRANCH", "Mispredicted branches",
169  PM0 | PM1 | PM2 | PM3, NULL,
172  InsnClassExpr(INSN_CLASS_ALL) /* bit is only true for branches */
173  },
174 
175 
176  {"pmBCMISS", "sampled B-cache (L2) misses.",
177  PM0 | PM1 | PM2 | PM3, NULL,
181  },
182 
183  {"TLBMISS", "TLB miss at any level.",
184  PM0 | PM1 | PM2 | PM3, NULL,
189  },
190 
191  {"IMISS", "Lower bound on instruction cache misses",
192  PM0 | PM1 | PM2 | PM3, NULL,
196  },
197 
198 
199 #if 0
200 // "icache_miss_lb", "Lower bound on icache misses"
201 // count + nyp , any insn
202 #endif
203 
204  // -------------------------------------------------------
205  // Metrics available for a specific ProfileMe mode
206  // -------------------------------------------------------
207  // m0: inflight, retires
208  // m1: inflight, retdelay
209  // m2: retires, bcmisses
210  // m3: inflight, replays
211 
212  // FIXME: these are just the raw counters; how best to combine them?
213  {"pmINFLT", "Inflight cycles (excludes fetch stage) for instructions that retired without trapping.",
214  PM0 | PM1 | PM3, NULL,
218  },
219 
220 
221  {"pmRETIRE", "Instruction retires.",
222  PM0 | PM2, NULL,
226  },
227  {"pmREPLAY", "Memory system replay traps.",
228  PM3, NULL,
232  },
233 
234 #if 0
235 // "m0inflight" "Number of cycles instruction was Inflight
236 // "m0retires" Instruction retires --> cross check retired instructions?
237 
238 // "m1inflight" Inflight cycles
239 // "m1retdelay" Delays Retire delay (excludes all cycles prior to fetch)-->
240 
241 // "m2retires" Instruction retires --> cross check retired instructions?
242 // "m2bcmisses" B-cache misses --> b-cache misses
243 
244 // "m3inflight" Inflight cycles
245 // "m3replays" Pipeline replay traps
246 #endif
247 
248  { "RETIRES", "Retired instructions",
249  RM, "retires",
252  },
253 
254  { "MBREPLAY", "Mbox replay traps",
255  RM, "replaytrap",
258  },
259 
260  { "BCMISS", "Bcache misses or long-latency probes",
261  RM, "bmiss",
264  }
265 
266 };
267 
269 
271 
272 #undef TABLE_SZ
273 
274 //****************************************************************************
275 
278 {
279  // FIXME: we should search a quick-sorted table with binary search.
280  // check 'sorted'
281  Entry* found = NULL;
282  for (unsigned int i = 0; i < GetSize(); ++i) {
283  if (strcmp(metric, table[i].name) == 0) {
284  found = &table[i];
285  }
286  }
287  return found;
288 }
289 
292 {
293  if (i >= GetSize()) { return NULL; }
294  return &table[i];
295 }
296 
297 
298 //****************************************************************************
299 //
300 //****************************************************************************
301 
303 GetPredefinedDCPIFilter(const char* metric, binutils::LM* lm)
304 {
307  if (!e) { return NULL; }
308 
310  new InsnFilter(e->iexpr, lm));
311 
312  f->SetName(e->name);
314  return f;
315 }
316 
317 //****************************************************************************
318 // DCPIMetricFilter
319 //****************************************************************************
320 
321 bool
323 {
324  const DCPIProfileMetric* dm = dynamic_cast<const DCPIProfileMetric*>(m);
325  DIAG_Assert(dm, "Internal Error: invalid cast!");
326 
327  const DCPIMetricDesc& mdesc = dm->GetDCPIDesc();
328  return expr.IsSatisfied(mdesc);
329 }
static struct perf_mem_metric metric
Definition: pmu_x86.c:114
#define DCPI_RM_retires
#define DCPI_RM_bmiss
#define DCPI_PM_TRAP_dtbmiss
#define DCPI_PM_ATTR_early_kill_F
#define DCPI_PM_TRAP_trap
#define DCPI_PM_CNTR_count
PCProfileFilter * GetPredefinedDCPIFilter(const char *metric, binutils::LM *lm)
void SetDescription(const char *s)
static Entry * FindEntry(const char *token)
#define DCPI_PM_CNTR_retires
#define DCPI_PM_ATTR_nyp_T
#define INSN_CLASS_FLOP
static Entry * Index(unsigned int i)
#define DCPI_PM_CNTR_replays
#define DCPI_RM_cycles
#define DCPI_PM_CNTR_bcmisses
#define DCPI_MTYPE_RM
#define INSN_CLASS_ALL
#define INSN_CLASS_MEMOP
#define TABLE_SZ
bool found
Definition: cct.c:129
#define DCPI_MTYPE_PM
static unsigned int GetSize()
#define INSN_CLASS_INTOP
#define DCPI_PM_ATTR_ldstorder_T
#define DCPI_PM_TRAP_dtb2miss3
#define DCPI_RM_replaytrap
#define NULL
Definition: ElfHelper.cpp:85
#define DCPI_PM_TRAP_dtb2miss4
const DCPIMetricDesc & GetDCPIDesc() const
void SetName(const char *s)
virtual bool operator()(const PCProfileMetric *m)
#define DCPI_PM_ATTR_cbrmispredict_T
#define DCPI_PM_ATTR_retired_T
#define DCPI_PM_CNTR_inflight
#define DCPI_PM_CNTR_retdelay