44 #include "debug/Checkpoint.hh"
45 #include "debug/PMUVerbose.hh"
48 #include "params/ArmPMU.hh"
59 reg_pmcnten(0), reg_pmcr(0),
60 reg_pmselr(0), reg_pminten(0), reg_pmovsr(0),
61 reg_pmceid0(0),reg_pmceid1(0),
63 maximumCounterCount(
p.eventCounters),
64 cycleCounter(*this, maximumCounterCount),
65 cycleCounterEventId(
p.cycleEventId),
66 swIncrementEvent(nullptr),
70 DPRINTF(PMUVerbose,
"Initializing the PMU.\n");
73 fatal(
"The PMU can only accept 31 counters, %d counters requested.\n",
77 warn_if(!
p.interrupt,
"ARM PMU: No interrupt specified, interrupt " \
78 "delivery disabled.\n");
98 const auto &pmu_params =
static_cast<const ArmPMUParams &
>(
params());
100 if (pmu_params.interrupt)
101 interrupt = pmu_params.interrupt->get(tc);
108 DPRINTF(PMUVerbose,
"PMU: Adding SW increment event with id '0x%x'\n",
id);
113 "Trying to add a software increment event with multiple"
114 "IDs. This is not supported.\n");
119 "been previously defined\n",
id);
130 DPRINTF(PMUVerbose,
"PMU: Adding Probe Driven event with id '0x%x'"
131 "as probe %s:%s\n",
id, obj->
name(), probe_name);
133 std::shared_ptr<RegularEvent>
event;
134 auto event_entry =
eventMap.find(
id);
135 if (event_entry ==
eventMap.end()) {
136 event = std::make_shared<RegularEvent>();
139 event = std::dynamic_pointer_cast<RegularEvent>(event_entry->second);
140 fatal_if(!
event,
"Event with id %d is not probe driven\n",
id);
142 event->addMicroarchitectureProbe(obj, probe_name);
155 }
else if (
id > 0x20 &&
id < 0x40) {
157 }
else if (
id >= 0x4000 &&
id < 0x4020) {
158 reg_pmceid0 |= ((uint64_t)1) << (
id - 0x4000 + 32);
159 }
else if (
id >= 0x4020 &&
id < 0x4040) {
160 reg_pmceid1 |= ((uint64_t)1) << (
id - 0x4020 + 32);
190 DPRINTF(PMUVerbose,
"setMiscReg(%s, 0x%x)\n",
246 DPRINTF(PMUVerbose,
"Setting PMCCFILTR: 0x%x\n",
val);
253 DPRINTF(PMUVerbose,
"Setting counter type: "
254 "[PMSELR: 0x%x, PMSELER.sel: 0x%x, EVTYPER: 0x%x]\n",
292 warn(
"Not doing anything for write to miscreg %s\n",
300 DPRINTF(PMUVerbose,
"readMiscReg(%s): 0x%x\n",
390 warn(
"Not doing anything for read from miscreg %s\n",
398 DPRINTF(PMUVerbose,
"Set Control Reg 0x%08x.\n",
val);
401 DPRINTF(PMUVerbose,
"PMU reset all events to zero.\n");
406 DPRINTF(PMUVerbose,
"PMU reset cycle counter to zero.\n");
421 const bool global_enable(
reg_pmcr.e);
452 for (
auto& counter: userCounters) {
460 userCounters.erase(user);
462 if (userCounters.empty()) {
470 parentEvent->increment(
val);
476 for (
auto& subEvents: microArchitectureEventSet) {
477 attachedProbePointList.emplace_back(
478 new RegularProbe(
this, subEvents.first, subEvents.second));
485 attachedProbePointList.clear();
493 const PMEVTYPER_t filter(this->filter);
495 const bool secure(pmu.isa->inSecureState());
499 return secure ? filter.u : (filter.u != filter.nsu);
502 return secure ? filter.p : (filter.p != filter.nsk);
508 return filter.p != filter.m;
511 panic(
"Unexpected execution level in PMU::isFiltered.\n");
519 sourceEvent->detachEvent(
this);
520 sourceEvent =
nullptr;
522 debugCounter(
"detaching event not currently attached"
535 sourceEvent->attachEvent(
this);
542 sourceEvent->updateAttachedCounters();
544 debugCounter(
"attempted to get value from a counter without"
545 " an associated event\n");
557 sourceEvent->updateAttachedCounters();
559 debugCounter(
"attempted to set value from a counter without"
560 " an associated event\n");
568 DPRINTF(PMUVerbose,
"updateCounter(%i): Disabling counter\n",
573 DPRINTF(PMUVerbose,
"updateCounter(%i): Enable event id 0x%x\n",
577 if (sourceEvent ==
eventMap.end()) {
578 warn(
"Can't enable PMU counter of type '0x%x': "
579 "No such event type.\n", ctr.
eventId);
581 ctr.
attach(sourceEvent->second);
598 warn_once(
"Can't change counter value: Counter %i does not exist.\n",
624 DPRINTF(PMUVerbose,
"Set Event [%d] = 0x%08x\n",
id,
val);
626 warn_once(
"Can't change counter type: Counter %i does not exist.\n",
639 if (
id !=
PMCCNTR && old_event_id !=
val.evtCount) {
649 const bool int_new = new_val != 0;
652 if (int_old && !int_new) {
663 DPRINTF(PMUVerbose,
"Delivering PMU interrupt.\n");
666 warn_once(
"Dropping PMU interrupt as no interrupt has "
675 DPRINTF(PMUVerbose,
"Clearing PMU interrupt.\n");
678 warn_once(
"Dropping PMU interrupt as no interrupt has "
686 DPRINTF(Checkpoint,
"Serializing Arm PMU\n");
706 DPRINTF(Checkpoint,
"Unserializing Arm PMU\n");
731 std::shared_ptr<PMU::PMUEvent>
734 auto entry =
eventMap.find(eventId);
737 warn(
"event %d does not exist\n", eventId);
740 return entry->second;
763 uint64_t value_until_overflow;
765 value_until_overflow = UINT64_MAX - value;
767 value_until_overflow = UINT32_MAX - (uint32_t)value;
771 return value_until_overflow;
780 if (delta > value_until_overflow) {
784 pmu.reg_pmovsr |= (1 << counterId);
788 if (pmu.reg_pminten & (1 << counterId)) {
789 pmu.raiseInterrupt();
791 return overflow64 ? UINT64_MAX : UINT32_MAX;
793 return value_until_overflow - delta + 1;
799 for (
auto& counter: userCounters) {
800 if (
val & (0x1 << counter->getCounterId())) {
Base class for ARM GIC implementations.
Base class for devices that use the MiscReg interfaces.
void write(uint64_t val)
write on the sw increment register inducing an increment of the counters with this event selected acc...
void regProbeListeners() override
Register probe listeners for this object.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
void setControlReg(PMCR_t val)
PMCR write handling.
void raiseInterrupt()
Deliver a PMU interrupt to the GIC.
PMCR_t reg_pmcr_conf
Constant (configuration-dependent) part of the PMCR.
RegVal readMiscReg(int misc_reg) override
Read a register within the PMU.
RegVal reg_pmcnten
Performance Monitor Count Enable Register.
std::shared_ptr< PMUEvent > getEvent(uint64_t eventId)
Obtain the event of a given id.
void clearInterrupt()
Clear a PMU interrupt.
const uint64_t cycleCounterEventId
The id of the counter hardwired to the cpu cycle counter.
uint64_t maximumCounterCount
The number of regular event counters.
static const RegVal reg_pmcr_wr_mask
PMCR write mask when accessed from the guest.
bool isFiltered(const CounterState &ctr) const
Check if a counter's settings allow it to be counted.
PMEVTYPER_t getCounterTypeRegister(CounterId id) const
Get the type and filter settings of a counter (PMEVTYPER)
unsigned clock_remainder
Remainder part when the clock counter is divided by 64.
void updateAllCounters()
Call updateCounter() for each counter in the PMU if the counter's state has changed.
void resetEventCounts()
Reset all event counters excluding the cycle counter to zero.
void registerEvent(uint32_t id)
void setOverflowStatus(RegVal new_val)
Used for writing the Overflow Flag Status Register (SET/CLR)
PMSELR_t reg_pmselr
Performance Monitor Selection Register.
std::map< EventTypeId, std::shared_ptr< PMUEvent > > eventMap
List of event types supported by this PMU.
static const CounterId PMCCNTR
Cycle Count Register Number.
void setThreadContext(ThreadContext *tc) override
CounterState & getCounter(CounterId id)
Return the state of a counter.
std::vector< CounterState > counters
State of all general-purpose counters supported by PMU.
void setCounterTypeRegister(CounterId id, PMEVTYPER_t type)
Set the type and filter settings of a performance counter (PMEVTYPER)
void drainResume() override
Resume execution after a successful drain.
PMU(const ArmPMUParams &p)
RegVal readMiscRegInt(int misc_reg)
void setMiscReg(int misc_reg, RegVal val) override
Set a register within the PMU.
CounterState cycleCounter
State of the cycle counter.
uint64_t reg_pmceid0
Performance counter ID register.
bool isValidCounter(CounterId id) const
Is this a valid counter ID?
PMCR_t reg_pmcr
Performance Monitor Control Register.
RegVal reg_pmovsr
Performance Monitor Overflow Status Register.
ArmInterruptPin * interrupt
Performance monitor interrupt number.
void addSoftwareIncrementEvent(unsigned int id)
std::shared_ptr< SWIncrementEvent > swIncrementEvent
The event that implements the software increment.
uint64_t getCounterValue(CounterId id) const
Get the value of a performance counter.
unsigned int EventTypeId
Event type ID.
void setCounterValue(CounterId id, uint64_t val)
Set the value of a performance counter.
RegVal reg_pminten
Performance Monitor Interrupt Enable Register.
void updateCounter(CounterState &ctr)
Depending on counter configuration, add or remove the probes driving the counter.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void addEventProbe(unsigned int id, SimObject *obj, const char *name)
virtual void clear()=0
Clear a signalled interrupt.
virtual void raise()=0
Signal an interrupt.
virtual std::string name() const
Abstract superclass for simulation objects.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual ContextID contextId() const =0
This module implements the global system counter and the local per-CPU architected timers as specifie...
#define panic(...)
This implements a cprintf based panic() function.
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
#define fatal(...)
This implements a cprintf based fatal() function.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
#define UNSERIALIZE_OPT_SCALAR(scalar)
void serializeSection(CheckpointOut &cp, const char *name) const
Serialize an object into a new section.
void unserializeSection(CheckpointIn &cp, const char *name)
Unserialize an a child object.
const Params & params() const
#define warn_if(cond,...)
Conditional warning macro that checks the supplied condition and only prints a warning if the conditi...
@ MISCREG_PMXEVTYPER_PMCCFILTR
int unflattenMiscReg(int reg)
const char *const miscRegName[]
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::ostream CheckpointOut
void paramIn(CheckpointIn &cp, const std::string &name, ExtMachInst &machInst)
std::string csprintf(const char *format, const Args &...args)
#define UNSERIALIZE_SCALAR(scalar)
#define SERIALIZE_SCALAR(scalar)
State of a counter within the PMU.
void attach(const std::shared_ptr< PMUEvent > &event)
Attach this counter to an event.
PMEVTYPER_t filter
Filtering settings (evtCount is unused)
void detach()
Detach the counter from its event.
EventTypeId eventId
Counter event ID.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
uint64_t getCounterId() const
Obtain the counter id.
uint64_t getValue() const
rReturn the counter value
bool enabled
Is the counter enabled?
uint64_t add(uint64_t delta)
Add an event count to the counter and check for overflow.
void serialize(CheckpointOut &cp) const override
Serialize an object.
void setValue(uint64_t val)
overwrite the value of the counter
void attachEvent(PMU::CounterState *user)
attach this event to a given counter
virtual void enable()=0
Enable the current event.
std::set< PMU::CounterState * > userCounters
set of counters using this event
virtual void updateAttachedCounters()
Method called immediately before a counter access in order for the associated event to update its sta...
void detachEvent(PMU::CounterState *user)
detach this event from a given counter
virtual void increment(const uint64_t val)
notify an event increment of val units, all the attached counters' value is incremented by val units.
void notify(const uint64_t &val)
void enable() override
Enable the current event.
void disable() override
Disable the current event.