gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
pmu.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2014, 2017-2018 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 "arch/arm/system.hh"
51 #include "base/cprintf.hh"
52 #include "cpu/base.hh"
53 #include "debug/PMUVerbose.hh"
54 #include "sim/eventq.hh"
55 #include "sim/sim_object.hh"
56 #include "sim/system.hh"
57 
58 class ArmPMUParams;
59 class Platform;
60 class ThreadContext;
61 class ArmInterruptPin;
62 
63 namespace ArmISA {
64 
65 
97 class PMU : public SimObject, public ArmISA::BaseISADevice {
98  public:
99  PMU(const ArmPMUParams *p);
100  ~PMU();
101 
102  void addEventProbe(unsigned int id, SimObject *obj, const char *name);
103  void addSoftwareIncrementEvent(unsigned int id);
104 
105  void registerEvent(uint32_t id);
106 
107  public: // SimObject and related interfaces
108  void serialize(CheckpointOut &cp) const override;
109  void unserialize(CheckpointIn &cp) override;
110 
111  void drainResume() override;
112 
113  void regProbeListeners() override;
114 
115  public: // ISA Device interface
116  void setThreadContext(ThreadContext *tc) override;
117 
124  void setMiscReg(int misc_reg, RegVal val) override;
131  RegVal readMiscReg(int misc_reg) override;
132 
133  protected: // PMU register types and constants
134  BitUnion32(PMCR_t)
135  // PMU Enable
136  Bitfield<0> e;
137  // Event counter reset
138  Bitfield<1> p;
139  // Cycle counter reset
140  Bitfield<2> c;
141  // Cycle counter divider enable
142  Bitfield<3> d;
143  // Export enable
144  Bitfield<4> x;
145  // Disable PMCCNTR when event counting is prohibited
146  Bitfield<5> dp;
147  // Long Cycle counter enable
148  Bitfield<6> lc;
149  // Number of event counters implemented
150  Bitfield<15, 11> n;
151  // Implementation ID
152  Bitfield<23, 16> idcode;
153  // Implementer code
154  Bitfield<31, 24> imp;
155  EndBitUnion(PMCR_t)
156 
157  BitUnion32(PMSELR_t)
158  // Performance counter selector
159  Bitfield<4, 0> sel;
160  EndBitUnion(PMSELR_t)
161 
162  BitUnion32(PMEVTYPER_t)
163  Bitfield<15, 0> evtCount;
164 
165  // Secure EL3 filtering
166  Bitfield<26> m;
167  // Non-secure EL2 mode filtering
168  Bitfield<27> nsh;
169  // Non-secure EL0 mode filtering
170  Bitfield<28> nsu;
171  // Non-secure EL1 mode filtering
172  Bitfield<29> nsk;
173  // EL0 filtering
174  Bitfield<30> u;
175  // EL1 filtering
176  Bitfield<31> p;
177  EndBitUnion(PMEVTYPER_t)
178 
186  typedef unsigned int CounterId;
187 
189  static const CounterId PMCCNTR = 31;
190 
196  typedef unsigned int EventTypeId;
197 
198  protected: /* High-level register and interrupt handling */
199  RegVal readMiscRegInt(int misc_reg);
200 
209  void setControlReg(PMCR_t val);
210 
214  void resetEventCounts();
215 
219  void raiseInterrupt();
220 
224  void clearInterrupt();
225 
236  uint64_t getCounterValue(CounterId id) const {
237  return isValidCounter(id) ? getCounter(id).getValue() : 0;
238  }
239 
247  void setCounterValue(CounterId id, uint64_t val);
248 
260  PMEVTYPER_t getCounterTypeRegister(CounterId id) const;
261 
275  void setCounterTypeRegister(CounterId id, PMEVTYPER_t type);
276 
287  void setOverflowStatus(RegVal new_val);
288 
289  protected: /* Probe handling and counter state */
290  struct CounterState;
291 
295  struct PMUEvent {
296 
297  PMUEvent() {}
298 
299  virtual ~PMUEvent() {}
300 
307 
313  void detachEvent(PMU::CounterState *user);
314 
322  virtual void increment(const uint64_t val);
323 
327  virtual void enable() = 0;
328 
332  virtual void disable() = 0;
333 
338  virtual void updateAttachedCounters() {}
339 
340  protected:
341 
343  std::set<PMU::CounterState*> userCounters;
344  };
345 
346  struct RegularEvent : public PMUEvent {
348 
350  std::string name) {
351 
352  panic_if(!object,"malformed probe-point"
353  " definition with name %s\n", name);
354 
355  microArchitectureEventSet.emplace(object, name);
356  }
357 
358  protected:
359  struct RegularProbe: public ProbeListenerArgBase<uint64_t>
360  {
362  std::string name)
363  : ProbeListenerArgBase(obj->getProbeManager(), name),
364  parentEvent(parent) {}
365 
366  RegularProbe() = delete;
367 
368  void notify(const uint64_t &val);
369 
370  protected:
372  };
373 
375  std::set<EventTypeEntry> microArchitectureEventSet;
376 
381 
382  void enable() override;
383 
384  void disable() override;
385  };
386 
387  class SWIncrementEvent : public PMUEvent
388  {
389  void enable() override {}
390  void disable() override {}
391 
392  public:
393 
400  void write(uint64_t val);
401  };
402 
409  PMUEvent* getEvent(uint64_t eventId);
410 
412  struct CounterState : public Serializable {
413  CounterState(PMU &pmuReference, uint64_t counter_id)
414  : eventId(0), filter(0), enabled(false),
415  overflow64(false), sourceEvent(nullptr),
416  counterId(counter_id), value(0), resetValue(false),
417  pmu(pmuReference) {}
418 
419  void serialize(CheckpointOut &cp) const override;
420  void unserialize(CheckpointIn &cp) override;
421 
428  uint64_t add(uint64_t delta);
429 
430  bool isFiltered() const;
431 
435  void detach();
436 
442  void attach(PMUEvent* event);
443 
449  uint64_t getCounterId() const{
450  return counterId;
451  }
452 
458  uint64_t getValue() const;
459 
465  void setValue(uint64_t val);
466 
467  public: /* Serializable state */
470 
472  PMEVTYPER_t filter;
473 
475  bool enabled;
476 
479 
480  protected: /* Configuration */
483 
485  uint64_t counterId;
486 
488  uint64_t value;
489 
492 
494 
495  template <typename ...Args>
496  void debugCounter(const char* mainString, Args &...args) const {
497 
498  std::string userString = csprintf(mainString, args...);
499 
500  warn("[counterId = %d, eventId = %d, sourceEvent = 0x%x] %s",
501  counterId, eventId, sourceEvent, userString.c_str());
502 
503  }
504  };
505 
514  bool isValidCounter(CounterId id) const {
515  return id < counters.size() || id == PMCCNTR;
516  }
517 
525  CounterState &getCounter(CounterId id) {
526  assert(isValidCounter(id));
527  return id == PMCCNTR ? cycleCounter : counters[id];
528  }
529 
537  const CounterState &getCounter(CounterId id) const {
538  assert(isValidCounter(id));
539  return id == PMCCNTR ? cycleCounter : counters[id];
540  }
541 
553  void updateCounter(CounterState &ctr);
554 
561  bool isFiltered(const CounterState &ctr) const;
562 
569  void updateAllCounters();
570 
571  protected: /* State that needs to be serialized */
574 
576  PMCR_t reg_pmcr;
577 
579  PMSELR_t reg_pmselr;
580 
583 
586 
593  uint64_t reg_pmceid0;
594  uint64_t reg_pmceid1;
595 
597  unsigned clock_remainder;
598 
601 
604 
607 
609  const uint64_t cycleCounterEventId;
610 
613 
614  protected: /* Configuration and constants */
617 
619  static const RegVal reg_pmcr_wr_mask;
620 
623 
627  std::map<EventTypeId, PMUEvent*> eventMap;
628 };
629 
630 } // namespace ArmISA
631 #endif
RegVal reg_pminten
Performance Monitor Interrupt Enable Register.
Definition: pmu.hh:582
void updateAllCounters()
Call updateCounter() for each counter in the PMU if the counter&#39;s state has changed.
Definition: pmu.cc:425
void drainResume() override
Resume execution after a successful drain.
Definition: pmu.cc:171
unsigned clock_remainder
Remainder part when the clock counter is divided by 64.
Definition: pmu.hh:597
RegVal reg_pmcnten
Performance Monitor Count Enable Register.
Definition: pmu.hh:573
void detachEvent(PMU::CounterState *user)
detach this event from a given counter
Definition: pmu.cc:464
STL pair class.
Definition: stl.hh:61
uint64_t reg_pmceid0
Performance counter ID register.
Definition: pmu.hh:593
virtual ~PMUEvent()
Definition: pmu.hh:299
CounterState & getCounter(CounterId id)
Return the state of a counter.
Definition: pmu.hh:525
void addEventProbe(unsigned int id, SimObject *obj, const char *name)
Definition: pmu.cc:129
Bitfield< 31, 24 > imp
Definition: pmu.hh:154
Model of an ARM PMU version 3.
Definition: pmu.hh:97
std::map< EventTypeId, PMUEvent * > eventMap
List of event types supported by this PMU.
Definition: pmu.hh:627
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: pmu.cc:712
RegVal readMiscRegInt(int misc_reg)
Definition: pmu.cc:312
PMSELR_t reg_pmselr
Performance Monitor Selection Register.
Definition: pmu.hh:579
void clearInterrupt()
Clear a PMU interrupt.
Definition: pmu.cc:680
PMCR_t reg_pmcr
Performance Monitor Control Register.
Definition: pmu.hh:576
Base class for devices that use the MiscReg interfaces.
Definition: isa_device.hh:60
uint64_t RegVal
Definition: types.hh:168
bool isFiltered(const CounterState &ctr) const
Check if a counter&#39;s settings allow it to be counted.
CounterState cycleCounter
State of the cycle counter.
Definition: pmu.hh:606
Definition: ccregs.hh:42
uint64_t getCounterValue(CounterId id) const
Get the value of a performance counter.
Definition: pmu.hh:236
const uint64_t cycleCounterEventId
The id of the counter hardwired to the cpu cycle counter.
Definition: pmu.hh:609
void disable() override
Disable the current event.
Definition: pmu.hh:390
Event definition base class.
Definition: pmu.hh:295
void regProbeListeners() override
Register probe listeners for this object.
Definition: pmu.cc:178
void setThreadContext(ThreadContext *tc) override
Definition: pmu.cc:97
Definition: cprintf.cc:42
PMUEvent * sourceEvent
PmuEvent currently in use (if any)
Definition: pmu.hh:482
Bitfield< 23, 16 > idcode
Definition: pmu.hh:152
ThreadContext is the external interface to all thread state for anything outside of the CPU...
STL vector class.
Definition: stl.hh:40
Bitfield< 33 > id
Bitfield< 63 > val
Definition: misc.hh:771
virtual void disable()=0
Disable the current event.
Bitfield< 5 > dp
Definition: pmu.hh:146
Bitfield< 1 > p
Definition: pmu.hh:138
std::set< PMU::CounterState * > userCounters
set of counters using this event
Definition: pmu.hh:343
uint64_t maximumCounterCount
The number of regular event counters.
Definition: pmu.hh:600
void addSoftwareIncrementEvent(unsigned int id)
Definition: pmu.cc:107
Bitfield< 28 > nsu
Definition: pmu.hh:170
uint8_t type
Definition: inet.hh:333
bool resetValue
Flag keeping track if the counter has been reset.
Definition: pmu.hh:491
Bitfield< 4 > x
Definition: pmu.hh:144
virtual void enable()=0
Enable the current event.
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:162
std::vector< CounterState > counters
State of all general-purpose counters supported by PMU.
Definition: pmu.hh:603
void setOverflowStatus(RegVal new_val)
Used for writing the Overflow Flag Status Register (SET/CLR)
Definition: pmu.cc:654
void enable() override
Enable the current event.
Definition: pmu.hh:389
ArmInterruptPin * interrupt
Performance monitor interrupt number.
Definition: pmu.hh:622
ProbeListenerArgBase is used to define the base interface to a ProbeListenerArg (i.e the notify method on specific type).
Definition: probe.hh:200
Bitfield< 30 > u
Definition: pmu.hh:174
void raiseInterrupt()
Deliver a PMU interrupt to the GIC.
Definition: pmu.cc:668
void registerEvent(uint32_t id)
Definition: pmu.cc:155
uint64_t getValue() const
rReturn the counter value
Definition: pmu.cc:547
Bitfield< 6 > lc
Definition: pmu.hh:148
void setControlReg(PMCR_t val)
PMCR write handling.
Definition: pmu.cc:402
~PMU()
Definition: pmu.cc:92
virtual void increment(const uint64_t val)
notify an event increment of val units, all the attached counters&#39; value is incremented by val units...
Definition: pmu.cc:456
void resetEventCounts()
Reset all event counters excluding the cycle counter to zero.
Definition: pmu.cc:596
Bitfield< 27 > nsh
Definition: pmu.hh:168
BitUnion32(PMCR_t) Bitfield< 0 > e
virtual const std::string name() const
Definition: sim_object.hh:120
std::set< EventTypeEntry > microArchitectureEventSet
The set of events driving the event value.
Definition: pmu.hh:375
void addMicroarchitectureProbe(SimObject *object, std::string name)
Definition: pmu.hh:349
Bitfield< 10, 5 > event
Basic support for object serialization.
Definition: serialize.hh:153
bool enabled()
Definition: statistics.cc:546
EndBitUnion(PMCR_t) BitUnion32(PMSELR_t) Bitfield< 4
void updateCounter(CounterState &ctr)
Depending on counter configuration, add or remove the probes driving the counter. ...
Definition: pmu.cc:573
PMEVTYPER_t filter
Filtering settings (evtCount is unused)
Definition: pmu.hh:472
RegularProbe(RegularEvent *parent, SimObject *obj, std::string name)
Definition: pmu.hh:361
virtual void updateAttachedCounters()
Method called immediately before a counter access in order for the associated event to update its sta...
Definition: pmu.hh:338
uint64_t reg_pmceid1
Definition: pmu.hh:594
void setCounterValue(CounterId id, uint64_t val)
Set the value of a performance counter.
Definition: pmu.cc:603
bool isValidCounter(CounterId id) const
Is this a valid counter ID?
Definition: pmu.hh:514
Bitfield< 9 > e
PMCR_t reg_pmcr_conf
Constant (configuration-dependent) part of the PMCR.
Definition: pmu.hh:616
PMU(const ArmPMUParams *p)
Definition: pmu.cc:59
void attachEvent(PMU::CounterState *user)
attach this event to a given counter
Definition: pmu.cc:446
RegVal reg_pmovsr
Performance Monitor Overflow Status Register.
Definition: pmu.hh:585
SWIncrementEvent * swIncrementEvent
The event that implements the software increment.
Definition: pmu.hh:612
std::ostream CheckpointOut
Definition: serialize.hh:68
bool overflow64
Is this a 64-bit counter?
Definition: pmu.hh:478
PMUEvent * getEvent(uint64_t eventId)
Obtain the event of a given id.
Definition: pmu.cc:740
Bitfield< 26 > m
Definition: pmu.hh:166
void debugCounter(const char *mainString, Args &...args) const
Definition: pmu.hh:496
Bitfield< 29 > nsk
Definition: pmu.hh:172
std::vector< std::unique_ptr< RegularProbe > > attachedProbePointList
Set of probe listeners tapping onto each of the input micro-arch events which compose this pmu event...
Definition: pmu.hh:380
ProbeManager * getProbeManager()
Get the probe manager for this object.
Definition: sim_object.cc:120
Bitfield< 15, 11 > n
Definition: pmu.hh:150
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: pmu.cc:692
static const CounterId PMCCNTR
Cycle Count Register Number.
Definition: pmu.hh:189
CounterState(PMU &pmuReference, uint64_t counter_id)
Definition: pmu.hh:413
unsigned int EventTypeId
Event type ID.
Definition: pmu.hh:196
const CounterState & getCounter(CounterId id) const
Return the state of a counter.
Definition: pmu.hh:537
void setCounterTypeRegister(CounterId id, PMEVTYPER_t type)
Set the type and filter settings of a performance counter (PMEVTYPER)
Definition: pmu.cc:630
Bitfield< 2 > c
Definition: pmu.hh:140
void setMiscReg(int misc_reg, RegVal val) override
Set a register within the PMU.
Definition: pmu.cc:194
RegVal readMiscReg(int misc_reg) override
Read a register within the PMU.
Definition: pmu.cc:303
#define warn(...)
Definition: logging.hh:212
EventTypeId eventId
Counter event ID.
Definition: pmu.hh:469
uint64_t getCounterId() const
Obtain the counter id.
Definition: pmu.hh:449
Bitfield< 3 > d
Definition: pmu.hh:142
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:185
PMEVTYPER_t getCounterTypeRegister(CounterId id) const
Get the type and filter settings of a counter (PMEVTYPER)
Definition: pmu.cc:616
Generic representation of an Arm interrupt pin.
Definition: base_gic.hh:178
uint64_t counterId
id of the counter instance
Definition: pmu.hh:485
static const RegVal reg_pmcr_wr_mask
PMCR write mask when accessed from the guest.
Definition: pmu.hh:619
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
std::pair< SimObject *, std::string > EventTypeEntry
Definition: pmu.hh:347
State of a counter within the PMU.
Definition: pmu.hh:412
uint64_t value
Current value of the counter.
Definition: pmu.hh:488
bool enabled
Is the counter enabled?
Definition: pmu.hh:475

Generated on Fri Feb 28 2020 16:26:57 for gem5 by doxygen 1.8.13