arch-arm: Fix memory leak of PMU events

Memory of PMU events was never being released.

Change-Id: I3cd9583103333008799f0873af3a490f847a21b5
Issued-on: https://gem5.atlassian.net/browse/GEM5-857
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/38703
Reviewed-by: Bobby R. Bruce <bbruce@ucdavis.edu>
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel R. Carvalho
2020-12-24 12:13:39 -03:00
committed by Daniel Carvalho
parent 15924e1bff
commit 7a144c5d59
2 changed files with 13 additions and 17 deletions

View File

@@ -118,7 +118,7 @@ PMU::addSoftwareIncrementEvent(unsigned int id)
fatal_if(old_event != eventMap.end(), "An event with id %d has "
"been previously defined\n", id);
swIncrementEvent = new SWIncrementEvent();
swIncrementEvent = std::make_shared<SWIncrementEvent>();
eventMap[id] = swIncrementEvent;
registerEvent(id);
}
@@ -130,18 +130,14 @@ PMU::addEventProbe(unsigned int id, SimObject *obj, const char *probe_name)
DPRINTF(PMUVerbose, "PMU: Adding Probe Driven event with id '0x%x'"
"as probe %s:%s\n",id, obj->name(), probe_name);
RegularEvent *event = nullptr;
std::shared_ptr<RegularEvent> event;
auto event_entry = eventMap.find(id);
if (event_entry == eventMap.end()) {
event = new RegularEvent();
event = std::make_shared<RegularEvent>();
eventMap[id] = event;
} else {
event = dynamic_cast<RegularEvent*>(event_entry->second);
if (!event) {
fatal("Event with id %d is not probe driven\n", id);
}
event = std::dynamic_pointer_cast<RegularEvent>(event_entry->second);
fatal_if(!event, "Event with id %d is not probe driven\n", id);
}
event->addMicroarchitectureProbe(obj, probe_name);
@@ -182,7 +178,7 @@ PMU::regProbeListeners()
counters.emplace_back(*this, index);
}
PMUEvent *event = getEvent(cycleCounterEventId);
std::shared_ptr<PMUEvent> event = getEvent(cycleCounterEventId);
panic_if(!event, "core cycle event is not present\n");
cycleCounter.enabled = true;
cycleCounter.attach(event);
@@ -531,7 +527,7 @@ PMU::CounterState::detach()
}
void
PMU::CounterState::attach(PMUEvent* event)
PMU::CounterState::attach(const std::shared_ptr<PMUEvent> &event)
{
if (!resetValue) {
value = 0;
@@ -734,7 +730,7 @@ PMU::unserialize(CheckpointIn &cp)
cycleCounter.unserializeSection(cp, "cycleCounter");
}
PMU::PMUEvent*
std::shared_ptr<PMU::PMUEvent>
PMU::getEvent(uint64_t eventId)
{
auto entry = eventMap.find(eventId);

View File

@@ -408,7 +408,7 @@ class PMU : public SimObject, public ArmISA::BaseISADevice
* @param the id of the event to obtain
* @return a pointer to the event with id eventId
*/
PMUEvent* getEvent(uint64_t eventId);
std::shared_ptr<PMUEvent> getEvent(uint64_t eventId);
/** State of a counter within the PMU. **/
struct CounterState : public Serializable
@@ -442,7 +442,7 @@ class PMU : public SimObject, public ArmISA::BaseISADevice
*
* @param the event to attach the counter to
*/
void attach(PMUEvent* event);
void attach(const std::shared_ptr<PMUEvent> &event);
/**
* Obtain the counter id
@@ -482,7 +482,7 @@ class PMU : public SimObject, public ArmISA::BaseISADevice
protected: /* Configuration */
/** PmuEvent currently in use (if any) **/
PMUEvent *sourceEvent;
std::shared_ptr<PMUEvent> sourceEvent;
/** id of the counter instance **/
uint64_t counterId;
@@ -612,7 +612,7 @@ class PMU : public SimObject, public ArmISA::BaseISADevice
const uint64_t cycleCounterEventId;
/** The event that implements the software increment **/
SWIncrementEvent *swIncrementEvent;
std::shared_ptr<SWIncrementEvent> swIncrementEvent;
protected: /* Configuration and constants */
/** Constant (configuration-dependent) part of the PMCR */
@@ -627,7 +627,7 @@ class PMU : public SimObject, public ArmISA::BaseISADevice
/**
* List of event types supported by this PMU.
*/
std::map<EventTypeId, PMUEvent*> eventMap;
std::map<EventTypeId, std::shared_ptr<PMUEvent>> eventMap;
};
} // namespace ArmISA