gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pmu.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2014 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions are
16  * met: redistributions of source code must retain the above copyright
17  * notice, this list of conditions and the following disclaimer;
18  * redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions and the following disclaimer in the
20  * documentation and/or other materials provided with the distribution;
21  * neither the name of the copyright holders nor the names of its
22  * contributors may be used to endorse or promote products derived from
23  * this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  *
37  * Authors: Dam Sunwoo
38  * Matt Horsnell
39  * Andreas Sandberg
40  */
41 #ifndef __ARCH_ARM_PMU_HH__
42 #define __ARCH_ARM_PMU_HH__
43 
44 #include <map>
45 #include <memory>
46 #include <vector>
47 
48 #include "arch/arm/isa_device.hh"
49 #include "arch/arm/registers.hh"
50 #include "sim/probe/probe.hh"
51 #include "sim/sim_object.hh"
52 
53 class ArmPMUParams;
54 class Platform;
55 class ThreadContext;
56 
57 namespace ArmISA {
58 
59 
91 class PMU : public SimObject, public ArmISA::BaseISADevice {
92  public:
93  PMU(const ArmPMUParams *p);
94  ~PMU();
95 
96  void addEventProbe(unsigned int id, SimObject *obj, const char *name);
97 
98  public: // SimObject and related interfaces
99  void serialize(CheckpointOut &cp) const override;
100  void unserialize(CheckpointIn &cp) override;
101 
102  void drainResume() override;
103 
104 
105  public: // ISA Device interface
112  void setMiscReg(int misc_reg, MiscReg val) override;
119  MiscReg readMiscReg(int misc_reg) override;
120 
121  protected: // PMU register types and constants
122  BitUnion32(PMCR_t)
123  // PMU Enable
124  Bitfield<0> e;
125  // Event counter reset
126  Bitfield<1> p;
127  // Cycle counter reset
128  Bitfield<2> c;
129  // Cycle counter divider enable
130  Bitfield<3> d;
131  // Export enable
132  Bitfield<4> x;
133  // Disable PMCCNTR when event counting is prohibited
134  Bitfield<5> dp;
135  // Long Cycle counter enable
136  Bitfield<6> lc;
137  // Number of event counters implemented
138  Bitfield<15, 11> n;
139  // Implementation ID
140  Bitfield<23, 16> idcode;
141  // Implementer code
142  Bitfield<31, 24> imp;
143  EndBitUnion(PMCR_t)
144 
145  BitUnion32(PMSELR_t)
146  // Performance counter selector
147  Bitfield<4, 0> sel;
148  EndBitUnion(PMSELR_t)
149 
150  BitUnion32(PMEVTYPER_t)
151  Bitfield<9, 0> evtCount;
152 
153  // Secure EL3 filtering
154  Bitfield<26> m;
155  // Non-secure EL2 mode filtering
156  Bitfield<27> nsh;
157  // Non-secure EL0 mode filtering
158  Bitfield<28> nsu;
159  // Non-secure EL1 mode filtering
160  Bitfield<29> nsk;
161  // EL0 filtering
162  Bitfield<30> u;
163  // EL1 filtering
164  Bitfield<31> p;
165  EndBitUnion(PMEVTYPER_t)
166 
174  typedef unsigned int CounterId;
175 
177  static const CounterId PMCCNTR = 31;
178 
184  typedef unsigned int EventTypeId;
185 
187  static const EventTypeId ARCH_EVENT_SW_INCR = 0x00;
188 
189  protected: /* High-level register and interrupt handling */
190  MiscReg readMiscRegInt(int misc_reg);
191 
200  void setControlReg(PMCR_t val);
201 
205  void resetEventCounts();
206 
210  void raiseInterrupt();
211 
222  uint64_t getCounterValue(CounterId id) const {
223  return isValidCounter(id) ? getCounter(id).value : 0;
224  }
225 
233  void setCounterValue(CounterId id, uint64_t val);
234 
246  PMEVTYPER_t getCounterTypeRegister(CounterId id) const;
247 
261  void setCounterTypeRegister(CounterId id, PMEVTYPER_t type);
262 
263  protected: /* Probe handling and counter state */
264  class ProbeListener : public ProbeListenerArgBase<uint64_t>
265  {
266  public:
267  ProbeListener(PMU &_pmu, CounterId _id,
268  ProbeManager *pm, const std::string &name)
269  : ProbeListenerArgBase(pm, name),
270  pmu(_pmu), id(_id) {}
271 
272  void notify(const uint64_t &val) override
273  {
274  pmu.handleEvent(id, val);
275  }
276 
277  protected:
279  const CounterId id;
280  };
281  typedef std::unique_ptr<ProbeListener> ProbeListenerUPtr;
282 
290  struct EventType {
295  EventType(SimObject *_obj, const std::string &_name)
296  : obj(_obj), name(_name) {}
297 
305  std::unique_ptr<ProbeListener> create(PMU &pmu, CounterId cid) const
306  {
307  std::unique_ptr<ProbeListener> ptr;
308  ptr.reset(new ProbeListener(pmu, cid,
309  obj->getProbeManager(), name));
310  return ptr;
311  }
312 
314  SimObject *const obj;
316  const std::string name;
317 
318  private:
319  // Disable the default constructor
320  EventType();
321  };
322 
324  struct CounterState : public Serializable {
326  : eventId(0), filter(0), value(0), enabled(false),
327  overflow64(false) {
328 
329  listeners.reserve(4);
330  }
331 
332  void serialize(CheckpointOut &cp) const override;
333  void unserialize(CheckpointIn &cp) override;
334 
341  bool add(uint64_t delta);
342 
343  public: /* Serializable state */
346 
348  PMEVTYPER_t filter;
349 
351  uint64_t value;
352 
354  bool enabled;
355 
358 
359  public: /* Configuration */
362  };
363 
375  void handleEvent(CounterId id, uint64_t delta);
376 
385  bool isValidCounter(CounterId id) const {
386  return id < counters.size() || id == PMCCNTR;
387  }
388 
396  CounterState &getCounter(CounterId id) {
397  assert(isValidCounter(id));
398  return id == PMCCNTR ? cycleCounter : counters[id];
399  }
400 
401 
409  const CounterState &getCounter(CounterId id) const {
410  assert(isValidCounter(id));
411  return id == PMCCNTR ? cycleCounter : counters[id];
412  }
413 
425  void updateCounter(CounterId id, CounterState &ctr);
426 
433  bool isFiltered(const CounterState &ctr) const;
434 
441  void updateAllCounters();
442 
443  protected: /* State that needs to be serialized */
446 
448  PMCR_t reg_pmcr;
449 
451  PMSELR_t reg_pmselr;
452 
455 
458 
465  uint64_t reg_pmceid;
466 
468  unsigned clock_remainder;
469 
474 
475  protected: /* Configuration and constants */
479  static const MiscReg reg_pmcr_wr_mask;
480 
482  const unsigned int pmuInterrupt;
485 
502  std::multimap<EventTypeId, EventType> pmuEventTypes;
503 };
504 
505 } // namespace ArmISA
506 #endif
const unsigned int pmuInterrupt
Performance monitor interrupt number.
Definition: pmu.hh:482
void updateAllCounters()
Call updateCounter() for each counter in the PMU if the counter's state has changed.
Definition: pmu.cc:335
void drainResume() override
Resume execution after a successful drain.
Definition: pmu.cc:104
void handleEvent(CounterId id, uint64_t delta)
Handle an counting event triggered by a probe.
Definition: pmu.cc:385
unsigned clock_remainder
Remainder part when the clock counter is divided by 64.
Definition: pmu.hh:468
uint64_t getCounterValue(CounterId id) const
Get the value of a performance counter.
Definition: pmu.hh:222
std::unique_ptr< ProbeListener > create(PMU &pmu, CounterId cid) const
Create and attach a probe used to drive this event.
Definition: pmu.hh:305
uint64_t MiscReg
Definition: registers.hh:70
CounterState & getCounter(CounterId id)
Return the state of a counter.
Definition: pmu.hh:396
void addEventProbe(unsigned int id, SimObject *obj, const char *name)
Definition: pmu.cc:91
Bitfield< 31, 24 > imp
Definition: pmu.hh:142
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pmu.cc:563
Model of an ARM PMU version 3.
Definition: pmu.hh:91
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pmu.cc:535
bool isFiltered(const CounterState &ctr) const
Check if a counter's settings allow it to be counted.
Definition: pmu.cc:356
PMSELR_t reg_pmselr
Performance Monitor Selection Register.
Definition: pmu.hh:451
const CounterId id
Definition: pmu.hh:279
PMCR_t reg_pmcr
Performance Monitor Control Register.
Definition: pmu.hh:448
Base class for devices that use the MiscReg interfaces.
Definition: isa_device.hh:58
const CounterState & getCounter(CounterId id) const
Return the state of a counter.
Definition: pmu.hh:409
CounterState cycleCounter
State of the cycle counter.
Definition: pmu.hh:473
ProbeManager is a conduit class that lives on each SimObject, and is used to match up probe listeners...
Definition: probe.hh:152
ProbeListener(PMU &_pmu, CounterId _id, ProbeManager *pm, const std::string &name)
Definition: pmu.hh:267
Bitfield< 23, 16 > idcode
Definition: pmu.hh:140
ThreadContext is the external interface to all thread state for anything outside of the CPU...
MiscReg readMiscReg(int misc_reg) override
Read a register within the PMU.
Definition: pmu.cc:222
MiscReg reg_pmovsr
Performance Monitor Overflow Status Register.
Definition: pmu.hh:457
Bitfield< 63 > val
Definition: misc.hh:770
Bitfield< 5 > dp
Definition: pmu.hh:134
Bitfield< 1 > p
Definition: pmu.hh:126
MiscReg readMiscRegInt(int misc_reg)
Definition: pmu.cc:231
MiscReg reg_pminten
Performance Monitor Interrupt Enable Register.
Definition: pmu.hh:454
Bitfield< 28 > nsu
Definition: pmu.hh:158
Bitfield< 4 > x
Definition: pmu.hh:132
std::vector< CounterState > counters
State of all general-purpose counters supported by PMU.
Definition: pmu.hh:471
SimObject *const obj
SimObject being measured by this probe.
Definition: pmu.hh:314
bool isValidCounter(CounterId id) const
Is this a valid counter ID?
Definition: pmu.hh:385
Platform *const platform
Platform this device belongs to.
Definition: pmu.hh:484
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i.e the notify method on specific type).
Definition: probe.hh:200
void notify(const uint64_t &val) override
Definition: pmu.hh:272
Bitfield< 30 > u
Definition: pmu.hh:162
void raiseInterrupt()
Deliver a PMU interrupt to the GIC.
Definition: pmu.cc:503
uint64_t reg_pmceid
Performance counter ID register.
Definition: pmu.hh:465
Bitfield< 6 > lc
Definition: pmu.hh:136
Event type configuration.
Definition: pmu.hh:290
void setControlReg(PMCR_t val)
PMCR write handling.
Definition: pmu.cc:312
~PMU()
Definition: pmu.cc:86
MiscReg reg_pmcnten
Performance Monitor Count Enable Register.
Definition: pmu.hh:445
void resetEventCounts()
Reset all event counters excluding the cycle counter to zero.
Definition: pmu.cc:445
Bitfield< 27 > nsh
Definition: pmu.hh:156
BitUnion32(PMCR_t) Bitfield< 0 > e
EventType(SimObject *_obj, const std::string &_name)
Definition: pmu.hh:295
static const MiscReg reg_pmcr_wr_mask
PMCR write mask when accessed from the guest.
Definition: pmu.hh:479
Basic support for object serialization.
Definition: serialize.hh:220
PMEVTYPER_t filter
Filtering settings (evtCount is unused)
Definition: pmu.hh:348
void setCounterValue(CounterId id, uint64_t val)
Set the value of a performance counter.
Definition: pmu.cc:452
Bitfield< 9 > e
Definition: miscregs.hh:1376
PMCR_t reg_pmcr_conf
Constant (configuration-dependent) part of the PMCR.
Definition: pmu.hh:477
PMU(const ArmPMUParams *p)
Definition: pmu.cc:58
bool add(uint64_t delta)
Add an event count to the counter and check for overflow.
Definition: pmu.cc:572
type
Definition: misc.hh:728
virtual const std::string name() const
Definition: sim_object.hh:117
void updateCounter(CounterId id, CounterState &ctr)
Depending on counter configuration, add or remove the probes driving the counter. ...
Definition: pmu.cc:412
std::unique_ptr< ProbeListener > ProbeListenerUPtr
Definition: pmu.hh:281
std::ostream CheckpointOut
Definition: serialize.hh:67
const std::string name
Probe name within obj.
Definition: pmu.hh:316
void setMiscReg(int misc_reg, MiscReg val) override
Set a register within the PMU.
Definition: pmu.cc:111
bool overflow64
Is this a 64-bit counter?
Definition: pmu.hh:357
Bitfield< 26 > m
Definition: pmu.hh:154
Bitfield< 29 > nsk
Definition: pmu.hh:160
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:131
Bitfield< 15, 11 > n
Definition: pmu.hh:138
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pmu.cc:516
static const CounterId PMCCNTR
Cycle Count Register Number.
Definition: pmu.hh:177
unsigned int EventTypeId
Event type ID.
Definition: pmu.hh:184
void setCounterTypeRegister(CounterId id, PMEVTYPER_t type)
Set the type and filter settings of a performance counter (PMEVTYPER)
Definition: pmu.cc:479
Bitfield< 2 > c
Definition: pmu.hh:128
std::vector< ProbeListenerUPtr > listeners
Probe listeners driving this counter.
Definition: pmu.hh:361
PMEVTYPER_t getCounterTypeRegister(CounterId id) const
Get the type and filter settings of a counter (PMEVTYPER)
Definition: pmu.cc:465
std::multimap< EventTypeId, EventType > pmuEventTypes
Event types supported by this PMU.
Definition: pmu.hh:502
EventTypeId eventId
Counter event ID.
Definition: pmu.hh:345
Bitfield< 11 > id
Definition: miscregs.hh:124
Bitfield< 3 > d
Definition: pmu.hh:130
static const EventTypeId ARCH_EVENT_SW_INCR
ID of the software increment event.
Definition: pmu.hh:187
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pmu.cc:554
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
State of a counter within the PMU.
Definition: pmu.hh:324
EndBitUnion(PMCR_t) BitUnion32(PMSELR_t) Bitfield<4
uint64_t value
Current value of the counter.
Definition: pmu.hh:351
bool enabled
Is the counter enabled?
Definition: pmu.hh:354

Generated on Fri Jun 9 2017 13:03:39 for gem5 by doxygen 1.8.6