HPCToolkit
DCPIProfileFilter.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 // DCPIProfileFilter.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 DCPIProfileFilter_H
61 #define DCPIProfileFilter_H
62 
63 //************************* System Include Files ****************************
64 
65 //*************************** User Include Files ****************************
66 
67 #include <include/uint.h>
68 
69 #include "PCProfileFilter.hpp"
70 #include "DCPIMetricDesc.hpp"
71 
72 #include <lib/isa/ISATypes.hpp>
73 
74 #include <lib/binutils/LM.hpp>
75 
76 //*************************** Forward Declarations ***************************
77 
78 class DCPIMetricFilter;
79 
80 //****************************************************************************
81 
82 // GetPredefinedDCPIFilter: Given a metric name, returns a DCPI filter
83 // if available, or NULL. The user is responsible for unallocating
84 // the returned object.
86 GetPredefinedDCPIFilter(const char* metric, binutils::LM* lm);
87 
88 //****************************************************************************
89 // DCPIMetricExpr
90 //****************************************************************************
91 
92 // 'DCPIMetricExpr' extensions to 'DCPIMetricDesc' for representing
93 // DCPI metric query expressions. DCPIMetricDesc bits should be used
94 // to construct an expression.
95 //
96 // The following expressions are allowed:
97 // * Non-ProfileMe expressions
98 // * ProfileMe expressions
99 // Following is a description of valid query expressions. Expressions
100 // are not checked for validity; invalid expressions will report
101 // non-sensical matches or none at all. See documentation for
102 // DCPIMetricDesc bits for more information on bits and their
103 // meanings.
104 //
105 // Non-ProfileMe expressions: <type> && <counter>
106 //
107 // A conjuction between <type> and <counter> subexpressions. <type>
108 // must be DCPI_MTYPE_RM. One and only one counter should be referenced
109 // within <counter>. E.g.:
110 // valid: DCPI_MTYPE_RM | DCPI_RM_cycles
111 // invalid: DCPI_MTYPE_RM | DCPI_RM_cycles | DCPI_RM_retires
112 //
113 // ProfileMe expressions: <type> && <counter> && <attribute> && <trap>
114 //
115 // A conjuction between <type>, <counter>, <attribute> and <trap>
116 // subexpressions. <type> must be DCPI_MTYPE_PM. <counter> should
117 // reference one ProfileMe counter. <attribute> is itself a
118 // conjunction of ProfileMe instruction attributes and may be empty.
119 // Note that setting both the T and F bit for the same attribute will
120 // produce no matches. Because only one ProfileMe trap bit is set for
121 // any sample, the <trap> subexpression is a *disjunction* of trap
122 // bits; it may be empty.
123 // valid: DCPI_MTYPE_PM | DCPI_PM_CNTR_count | DCPI_PM_ATTR_retired_T
125 public:
127  : DCPIMetricDesc(bv) { }
129 
130  DCPIMetricExpr(const DCPIMetricExpr& x) { *this = x; }
132  {
134  return *this;
135  }
136 
137  // IsSatisfied: Test to see if this query expression is satisfied by
138  // the DCPI metric 'm'.
140  return IsSatisfied(DCPIMetricDesc(bv));
141  }
142  bool IsSatisfied(const DCPIMetricDesc& m) {
143  // FIXME: This works for now, but it is technically incorrect
144  // becuase regular metrics do not have the <trap> subexpression.
145 
146  // The <trap> subexpression is a disjuction, so we test it separately
147  bool expr = m.IsSet(bits & ~DCPI_PM_TRAP_MASK);
148  bitvec_t trapbv = bits & DCPI_PM_TRAP_MASK;
149  if (trapbv != 0) {
150  return expr && m.IsSetAny(trapbv);
151  } else {
152  return expr;
153  }
154  }
155 
156 protected:
157 private:
158 
159 };
160 
161 //****************************************************************************
162 // DCPIMetricFilter
163 //****************************************************************************
164 
165 // DCPIMetricFilter: A DCPIMetricFilter divides metrics into two sets
166 // sets, 'in' and 'out'.
168 public:
169  DCPIMetricFilter(DCPIMetricExpr expr_) : expr(expr_) { }
170  virtual ~DCPIMetricFilter() { }
171 
172  // Returns true if 'm' satisfies 'expr'; false otherwise.
173  virtual bool operator()(const PCProfileMetric* m);
174 
175 private:
177 };
178 
179 //****************************************************************************
180 // PredefinedDCPIMetricTable
181 //****************************************************************************
182 
184 public:
185 
186  struct Entry {
187  const char* name;
188  const char* description;
189 
190  uint32_t avail; // condition that must be true for metric to be available
191  const char* availStr; // optional extension to above condition
192 
193  DCPIMetricExpr mexpr; // the metric filter expr
194  InsnClassExpr iexpr; // the instruction filter expr
195  };
196 
197  // Note: these availability tags refer to the raw DCPI metrics (not
198  // derived) (We use enum instead of #define b/c symbolic info is
199  // nice and we know they only need to fit in 32 bits.) RM should
200  // never be used at the same time as PM0-PM3.
201  enum AvailTag {
202  RM = 0x00000001, // the given non ProfileMe (regular) metric must be available
203  PM0 = 0x00000002, // ProfileMe mode 0
204  PM1 = 0x00000004, // ProfileMe mode 1
205  PM2 = 0x00000008, // ProfileMe mode 2
206  PM3 = 0x00000010 // ProfileMe mode 3
207  };
208 
209 public:
212 
213  static Entry* FindEntry(const char* token);
214  static Entry* Index(unsigned int i);
215  static unsigned int GetSize() { return size; }
216 
217 private:
218  // Should not be used
221 
222 private:
223  static Entry table[];
224  static unsigned int size;
225  static bool sorted;
226 };
227 
228 //****************************************************************************
229 
230 #endif
231 
DCPIMetricFilter(DCPIMetricExpr expr_)
static struct perf_mem_metric metric
Definition: pmu_x86.c:114
bool IsSatisfied(const DCPIMetricDesc &m)
DCPIMetricDesc & operator=(const DCPIMetricDesc &x)
DCPIMetricExpr(const DCPIMetricExpr &x)
DCPIMetricExpr & operator=(const DCPIMetricExpr &x)
PredefinedDCPIMetricTable(const PredefinedDCPIMetricTable &p)
bool IsSet(const bitvec_t bv) const
bool IsSetAny(const bitvec_t bv) const
bool IsSatisfied(const DCPIMetricDesc::bitvec_t bv)
DCPIMetricExpr(DCPIMetricDesc::bitvec_t bv)
static unsigned int GetSize()
DCPIMetricDesc(bitvec_t bv=0)
PredefinedDCPIMetricTable & operator=(const PredefinedDCPIMetricTable &p)
PCProfileFilter * GetPredefinedDCPIFilter(const char *metric, binutils::LM *lm)
#define DCPI_PM_TRAP_MASK