Renamed EventList -> EventManager (refactoring).

git-svn-id: https://www4.informatik.uni-erlangen.de/i4svn/danceos/trunk/devel/fail@1387 8c4709b5-6ec9-48aa-a5cd-a96041d1645a
This commit is contained in:
adrian
2012-06-27 11:15:42 +00:00
parent 1dd7f40e30
commit ac5dee6549
11 changed files with 55 additions and 59 deletions

View File

@ -2,12 +2,12 @@
#include <vector> #include <vector>
#include "BufferCache.hpp" #include "BufferCache.hpp"
#include "Event.hpp" #include "Event.hpp"
#include "EventList.hpp" #include "EventManager.hpp"
namespace fail { namespace fail {
template<class T> template<class T>
typename BufferCache<T>::iterator BufferCache<T>::makeActive(EventList &ev_list, BufferCache<T>::iterator idx) typename BufferCache<T>::iterator BufferCache<T>::makeActive(EventManager &ev_list, BufferCache<T>::iterator idx)
{ {
assert(idx != end() && assert(idx != end() &&
"FATAL ERROR: Index larger than cache!"); "FATAL ERROR: Index larger than cache!");
@ -20,7 +20,7 @@ typename BufferCache<T>::iterator BufferCache<T>::makeActive(EventList &ev_list,
ev->resetCounter(); ev->resetCounter();
// Note: This is the one and only situation in which remove() should NOT // Note: This is the one and only situation in which remove() should NOT
// store the removed item in the delete-list. // store the removed item in the delete-list.
EventList::iterator it = std::find(ev_list.begin(), ev_list.end(), static_cast<BaseEvent*>(ev)); EventManager::iterator it = std::find(ev_list.begin(), ev_list.end(), static_cast<BaseEvent*>(ev));
ev_list.m_remove(it, true); // remove event from buffer-list ev_list.m_remove(it, true); // remove event from buffer-list
ev_list.m_FireList.push_back(ev); ev_list.m_FireList.push_back(ev);
return erase(idx); return erase(idx);

View File

@ -6,7 +6,7 @@
namespace fail { namespace fail {
class EventList; class EventManager;
/** /**
* \class BufferCache * \class BufferCache
@ -20,7 +20,7 @@ template<class T>
class BufferCache { class BufferCache {
public: public:
/** /**
* The list type inherent to this class. Like bufferlist_t in EventList.hpp, * The list type inherent to this class. Like bufferlist_t in EventManager.hpp,
* but dynamically typed. * but dynamically typed.
*/ */
typedef std::list<T> cachelist_t; typedef std::list<T> cachelist_t;
@ -34,8 +34,8 @@ public:
private: private:
cachelist_t m_Buffer; //!< The list holding the cached elements cachelist_t m_Buffer; //!< The list holding the cached elements
public: public:
BufferCache() {} BufferCache() { }
~BufferCache() {} ~BufferCache() { }
/** /**
* Add an element to the array. The object pointed to remains untouched. * Add an element to the array. The object pointed to remains untouched.
* @param val the element to add * @param val the element to add
@ -79,14 +79,14 @@ public:
*/ */
inline iterator end() { return m_Buffer.end(); } inline iterator end() { return m_Buffer.end(); }
/** /**
* Acts as a replacement for EventList::makeActive, manipulating * Acts as a replacement for EventManager::makeActive, manipulating
* the buffer cache exclusively. EventList::fireActiveEvents needs * the buffer cache exclusively. EventManager::fireActiveEvents needs
* to be called to fire the active events (see there). * to be called to fire the active events (see there).
* This method is declared as a friend method in EventList. * This method is declared as a friend method in EventManager.
* @param idx the index of the event to trigger * @param idx the index of the event to trigger
* @returns an updated index which can be used to update a loop counter * @returns an updated index which can be used to update a loop counter
*/ */
iterator makeActive(EventList &ev_list, iterator idx); iterator makeActive(EventManager &ev_list, iterator idx);
}; };
} // end-of-namespace: fail } // end-of-namespace: fail

View File

@ -2,7 +2,7 @@ if(BUILD_BOCHS)
set(SRCS set(SRCS
BufferCache.cc BufferCache.cc
Event.cc Event.cc
EventList.cc EventManager.cc
Memory.cc Memory.cc
Register.cc Register.cc
SimulatorController.cc SimulatorController.cc
@ -13,7 +13,7 @@ else()
set(SRCS set(SRCS
BufferCache.cc BufferCache.cc
Event.cc Event.cc
EventList.cc EventManager.cc
Memory.cc Memory.cc
Register.cc Register.cc
SimulatorController.cc SimulatorController.cc

View File

@ -17,7 +17,7 @@ class ExperimentFlow;
typedef unsigned long event_id_t; //!< type of event ids typedef unsigned long event_id_t; //!< type of event ids
//! invalid event id (used as a return indicator) //! invalid event id (used as a return indicator)
const event_id_t INVALID_EVENT = static_cast<event_id_t>(-1); const event_id_t INVALID_EVENT = static_cast<event_id_t>(-1);
//! address wildcard (e.g. for BPEvent's) //! address wildcard (e.g. for BPEvent's)
const address_t ANY_ADDR = static_cast<address_t>(-1); const address_t ANY_ADDR = static_cast<address_t>(-1);
//! instruction wildcard //! instruction wildcard
@ -144,13 +144,11 @@ public:
/** /**
* Returns the address space register of this event. * Returns the address space register of this event.
*/ */
address_t getCR3() const address_t getCR3() const { return m_CR3; }
{ return m_CR3; }
/** /**
* Sets the address space register for this event. * Sets the address space register for this event.
*/ */
void setCR3(address_t iptr) void setCR3(address_t iptr) { m_CR3 = iptr; }
{ m_CR3 = iptr; }
/** /**
* Checks whether a given address space is matching. * Checks whether a given address space is matching.
*/ */
@ -162,14 +160,12 @@ public:
/** /**
* Returns the instruction pointer that triggered this event. * Returns the instruction pointer that triggered this event.
*/ */
address_t getTriggerInstructionPointer() const address_t getTriggerInstructionPointer() const { return m_TriggerInstrPtr; }
{ return m_TriggerInstrPtr; }
/** /**
* Sets the instruction pointer that triggered this event. Should not * Sets the instruction pointer that triggered this event. Should not
* be used by experiment code. * be used by experiment code.
*/ */
void setTriggerInstructionPointer(address_t iptr) void setTriggerInstructionPointer(address_t iptr) { m_TriggerInstrPtr = iptr; }
{ m_TriggerInstrPtr = iptr; }
}; };
/** /**

View File

@ -1,11 +1,11 @@
#include <set> #include <set>
#include "EventList.hpp" #include "EventManager.hpp"
#include "SALInst.hpp" #include "SALInst.hpp"
namespace fail { namespace fail {
void EventList::addToCaches(BaseEvent *ev) void EventManager::addToCaches(BaseEvent *ev)
{ {
BPEvent *bps_ev; BPEvent *bps_ev;
if ((bps_ev = dynamic_cast<BPEvent*>(ev)) != NULL) if ((bps_ev = dynamic_cast<BPEvent*>(ev)) != NULL)
@ -16,7 +16,7 @@ void EventList::addToCaches(BaseEvent *ev)
m_Io_cache.add(io_ev); m_Io_cache.add(io_ev);
} }
void EventList::removeFromCaches(BaseEvent *ev) void EventManager::removeFromCaches(BaseEvent *ev)
{ {
BPEvent *bpr_ev; BPEvent *bpr_ev;
if ((bpr_ev = dynamic_cast<BPEvent*>(ev)) != NULL) if ((bpr_ev = dynamic_cast<BPEvent*>(ev)) != NULL)
@ -27,13 +27,13 @@ void EventList::removeFromCaches(BaseEvent *ev)
m_Io_cache.remove(io_ev); m_Io_cache.remove(io_ev);
} }
void EventList::clearCaches() void EventManager::clearCaches()
{ {
m_Bp_cache.clear(); m_Bp_cache.clear();
m_Io_cache.clear(); m_Io_cache.clear();
} }
event_id_t EventList::add(BaseEvent* ev, ExperimentFlow* pExp) event_id_t EventManager::add(BaseEvent* ev, ExperimentFlow* pExp)
{ {
assert(ev != NULL && "FATAL ERROR: Event (of base type BaseEvent*) cannot be NULL!"); assert(ev != NULL && "FATAL ERROR: Event (of base type BaseEvent*) cannot be NULL!");
// a zero counter does not make sense // a zero counter does not make sense
@ -45,7 +45,7 @@ event_id_t EventList::add(BaseEvent* ev, ExperimentFlow* pExp)
return ev->getId(); return ev->getId();
} }
void EventList::remove(BaseEvent* ev) void EventManager::remove(BaseEvent* ev)
{ {
// possible cases: // possible cases:
// - ev == 0 -> remove all events // - ev == 0 -> remove all events
@ -77,12 +77,12 @@ void EventList::remove(BaseEvent* ev)
} }
} }
EventList::iterator EventList::remove(iterator it) EventManager::iterator EventManager::remove(iterator it)
{ {
return m_remove(it, false); return m_remove(it, false);
} }
EventList::iterator EventList::m_remove(iterator it, bool skip_deletelist) EventManager::iterator EventManager::m_remove(iterator it, bool skip_deletelist)
{ {
if (!skip_deletelist) { if (!skip_deletelist) {
// If skip_deletelist = true, m_remove was called from makeActive. Accordingly, we // If skip_deletelist = true, m_remove was called from makeActive. Accordingly, we
@ -105,7 +105,7 @@ EventList::iterator EventList::m_remove(iterator it, bool skip_deletelist)
return m_BufferList.erase(it); return m_BufferList.erase(it);
} }
void EventList::remove(ExperimentFlow* flow) void EventManager::remove(ExperimentFlow* flow)
{ {
// all events? // all events?
if (flow == 0) { if (flow == 0) {
@ -141,12 +141,12 @@ void EventList::remove(ExperimentFlow* flow)
} }
} }
EventList::~EventList() EventManager::~EventManager()
{ {
// nothing to do here yet // nothing to do here yet
} }
BaseEvent* EventList::getEventFromId(event_id_t id) BaseEvent* EventManager::getEventFromId(event_id_t id)
{ {
// Loop through all events: // Loop through all events:
for (bufferlist_t::iterator it = m_BufferList.begin(); for (bufferlist_t::iterator it = m_BufferList.begin();
@ -156,7 +156,7 @@ BaseEvent* EventList::getEventFromId(event_id_t id)
return NULL; // Nothing found. return NULL; // Nothing found.
} }
EventList::iterator EventList::makeActive(iterator it) EventManager::iterator EventManager::makeActive(iterator it)
{ {
assert(it != m_BufferList.end() && assert(it != m_BufferList.end() &&
"FATAL ERROR: Iterator has already reached the end!"); "FATAL ERROR: Iterator has already reached the end!");
@ -174,7 +174,7 @@ EventList::iterator EventList::makeActive(iterator it)
return it_next; return it_next;
} }
void EventList::fireActiveEvents() void EventManager::fireActiveEvents()
{ {
for (firelist_t::iterator it = m_FireList.begin(); for (firelist_t::iterator it = m_FireList.begin();
it != m_FireList.end(); it++) { it != m_FireList.end(); it++) {
@ -194,7 +194,7 @@ void EventList::fireActiveEvents()
// Note: Do NOT call any event handlers here! // Note: Do NOT call any event handlers here!
} }
size_t EventList::getContextCount() const size_t EventManager::getContextCount() const
{ {
std::set<ExperimentFlow*> uniqueFlows; // count unique ExperimentFlow-ptr std::set<ExperimentFlow*> uniqueFlows; // count unique ExperimentFlow-ptr
for (bufferlist_t::const_iterator it = m_BufferList.begin(); for (bufferlist_t::const_iterator it = m_BufferList.begin();

View File

@ -1,5 +1,5 @@
#ifndef __EVENT_LIST_HPP__ #ifndef __EVENT_MANAGER_HPP__
#define __EVENT_LIST_HPP__ #define __EVENT_MANAGER_HPP__
#include <cassert> #include <cassert>
#include <list> #include <list>
@ -39,7 +39,7 @@ typedef bp_cache_t::iterator bp_iter_t;
typedef BufferCache<IOPortEvent*> io_cache_t; typedef BufferCache<IOPortEvent*> io_cache_t;
typedef io_cache_t::iterator io_iter_t; typedef io_cache_t::iterator io_iter_t;
/** /**
* \class EventList * \class EventManager
* *
* \brief This class manages the events of the Fail* implementation. * \brief This class manages the events of the Fail* implementation.
* *
@ -50,10 +50,10 @@ typedef io_cache_t::iterator io_iter_t;
* be added to a -so called- delete-list. This ensures to prevent triggering * be added to a -so called- delete-list. This ensures to prevent triggering
* "active" events which have already been deleted by a previous experiment * "active" events which have already been deleted by a previous experiment
* flow. (See makeActive() and fireActiveEvent() for implementation specific * flow. (See makeActive() and fireActiveEvent() for implementation specific
* details.) EventList is part of the SimulatorController and "outsources" * details.) EventManager is part of the SimulatorController and "outsources"
* it's event management. * it's event management.
*/ */
class EventList { class EventManager {
private: private:
// TODO: List separation of "critical types"? Hashing/sorted lists? (-> performance!) // TODO: List separation of "critical types"? Hashing/sorted lists? (-> performance!)
bufferlist_t m_BufferList; //!< the storage for events added by exp. bufferlist_t m_BufferList; //!< the storage for events added by exp.
@ -62,8 +62,8 @@ private:
BaseEvent* m_pFired; //!< the recently fired Event-object BaseEvent* m_pFired; //!< the recently fired Event-object
bp_cache_t m_Bp_cache; //!< the storage cache for breakpoint events bp_cache_t m_Bp_cache; //!< the storage cache for breakpoint events
io_cache_t m_Io_cache; //!< the storage cache for port i/o events io_cache_t m_Io_cache; //!< the storage cache for port i/o events
friend bp_iter_t bp_cache_t::makeActive(EventList &ev_list, bp_iter_t idx); friend bp_iter_t bp_cache_t::makeActive(EventManager &ev_list, bp_iter_t idx);
friend io_iter_t io_cache_t::makeActive(EventList &ev_list, io_iter_t idx); friend io_iter_t io_cache_t::makeActive(EventManager &ev_list, io_iter_t idx);
public: public:
/** /**
* The iterator of this class used to loop through the list of * The iterator of this class used to loop through the list of
@ -73,8 +73,8 @@ public:
*/ */
typedef bufferlist_t::iterator iterator; typedef bufferlist_t::iterator iterator;
EventList() : m_pFired(NULL) { } EventManager() : m_pFired(NULL) { }
~EventList(); ~EventManager();
/** /**
* Adds the specified event object for the given ExperimentFlow to the * Adds the specified event object for the given ExperimentFlow to the
* list of events to be watched for. * list of events to be watched for.
@ -220,4 +220,4 @@ private:
} // end-of-namespace: fail } // end-of-namespace: fail
#endif // __EVENT_LIST_HPP__ #endif // __EVENT_MANAGER_HPP__

View File

@ -50,7 +50,7 @@ void SimulatorController::onBreakpointEvent(address_t instrPtr, address_t addres
// FIXME: Improve performance! // FIXME: Improve performance!
// Loop through all events of type BP*Event: // Loop through all events of type BP*Event:
EventList::iterator it = m_EvList.begin(); EventManager::iterator it = m_EvList.begin();
while (it != m_EvList.end()) { while (it != m_EvList.end()) {
BaseEvent* pev = *it; BaseEvent* pev = *it;
BPSingleEvent* pbp; BPRangeEvent* pbpr; BPSingleEvent* pbp; BPRangeEvent* pbpr;
@ -79,7 +79,7 @@ void SimulatorController::onMemoryAccessEvent(address_t addr, size_t len,
is_write ? MemAccessEvent::MEM_WRITE is_write ? MemAccessEvent::MEM_WRITE
: MemAccessEvent::MEM_READ; : MemAccessEvent::MEM_READ;
EventList::iterator it = m_EvList.begin(); EventManager::iterator it = m_EvList.begin();
while (it != m_EvList.end()) { // check for active events while (it != m_EvList.end()) { // check for active events
BaseEvent* pev = *it; BaseEvent* pev = *it;
MemAccessEvent* ev = dynamic_cast<MemAccessEvent*>(pev); MemAccessEvent* ev = dynamic_cast<MemAccessEvent*>(pev);
@ -99,7 +99,7 @@ void SimulatorController::onMemoryAccessEvent(address_t addr, size_t len,
void SimulatorController::onInterruptEvent(unsigned interruptNum, bool nmi) void SimulatorController::onInterruptEvent(unsigned interruptNum, bool nmi)
{ {
EventList::iterator it = m_EvList.begin(); EventManager::iterator it = m_EvList.begin();
while (it != m_EvList.end()) { // check for active events while (it != m_EvList.end()) { // check for active events
BaseEvent* pev = *it; BaseEvent* pev = *it;
InterruptEvent* pie = dynamic_cast<InterruptEvent*>(pev); InterruptEvent* pie = dynamic_cast<InterruptEvent*>(pev);
@ -157,7 +157,7 @@ bool SimulatorController::removeSuppressedInterrupt(unsigned interruptNum)
void SimulatorController::onTrapEvent(unsigned trapNum) void SimulatorController::onTrapEvent(unsigned trapNum)
{ {
EventList::iterator it = m_EvList.begin(); EventManager::iterator it = m_EvList.begin();
while(it != m_EvList.end()) { // check for active events while(it != m_EvList.end()) { // check for active events
BaseEvent* pev = *it; BaseEvent* pev = *it;
TrapEvent* pte = dynamic_cast<TrapEvent*>(pev); TrapEvent* pte = dynamic_cast<TrapEvent*>(pev);
@ -173,7 +173,7 @@ void SimulatorController::onTrapEvent(unsigned trapNum)
void SimulatorController::onGuestSystemEvent(char data, unsigned port) void SimulatorController::onGuestSystemEvent(char data, unsigned port)
{ {
EventList::iterator it = m_EvList.begin(); EventManager::iterator it = m_EvList.begin();
while (it != m_EvList.end()) { // check for active events while (it != m_EvList.end()) { // check for active events
BaseEvent* pev = *it; BaseEvent* pev = *it;
GuestEvent* pge = dynamic_cast<GuestEvent*>(pev); GuestEvent* pge = dynamic_cast<GuestEvent*>(pev);
@ -190,7 +190,7 @@ void SimulatorController::onGuestSystemEvent(char data, unsigned port)
void SimulatorController::onJumpEvent(bool flagTriggered, unsigned opcode) void SimulatorController::onJumpEvent(bool flagTriggered, unsigned opcode)
{ {
EventList::iterator it = m_EvList.begin(); EventManager::iterator it = m_EvList.begin();
while (it != m_EvList.end()) { // check for active events while (it != m_EvList.end()) { // check for active events
JumpEvent* pje = dynamic_cast<JumpEvent*>(*it); JumpEvent* pje = dynamic_cast<JumpEvent*>(*it);
if (pje != NULL) { if (pje != NULL) {

View File

@ -7,7 +7,7 @@
#include <vector> #include <vector>
#include "efw/CoroutineManager.hpp" #include "efw/CoroutineManager.hpp"
#include "EventList.hpp" #include "EventManager.hpp"
#include "SALConfig.hpp" #include "SALConfig.hpp"
#include "Event.hpp" #include "Event.hpp"
@ -33,13 +33,13 @@ class MemoryManager;
*/ */
class SimulatorController { class SimulatorController {
protected: protected:
EventList m_EvList; //!< storage where events are being buffered EventManager m_EvList; //!< storage where events are being buffered
CoroutineManager m_Flows; //!< managed experiment flows CoroutineManager m_Flows; //!< managed experiment flows
RegisterManager *m_Regs; //!< access to cpu register RegisterManager *m_Regs; //!< access to cpu register
MemoryManager *m_Mem; //!< access to memory pool MemoryManager *m_Mem; //!< access to memory pool
//! list of suppressed interrupts //! list of suppressed interrupts
std::vector<unsigned> m_SuppressedInterrupts; std::vector<unsigned> m_SuppressedInterrupts;
friend class EventList; //!< "outsources" the event management friend class EventManager; //!< "outsources" the event management
public: public:
SimulatorController() SimulatorController()
: m_Regs(NULL), m_Mem(NULL) { } : m_Regs(NULL), m_Mem(NULL) { }

View File

@ -218,7 +218,7 @@ void BochsController::onTimerTrigger(void* thisPtr)
TimerEvent* pTmEv = static_cast<TimerEvent*>(thisPtr); TimerEvent* pTmEv = static_cast<TimerEvent*>(thisPtr);
// Check for a matching TimerEvent. (In fact, we are only // Check for a matching TimerEvent. (In fact, we are only
// interessted in the iterator pointing at pTmEv.): // interessted in the iterator pointing at pTmEv.):
EventList::iterator it = std::find(simulator.m_EvList.begin(), EventManager::iterator it = std::find(simulator.m_EvList.begin(),
simulator.m_EvList.end(), pTmEv); simulator.m_EvList.end(), pTmEv);
// TODO: This has O(|m_EvList|) time complexity. We can further improve this // TODO: This has O(|m_EvList|) time complexity. We can further improve this
// by creating a method such that makeActive(pTmEv) works as well, // by creating a method such that makeActive(pTmEv) works as well,

View File

@ -61,7 +61,7 @@ public:
/** /**
* Static internal event handler for TimerEvents. This static function is * Static internal event handler for TimerEvents. This static function is
* called when a previously registered (Bochs) timer triggers. This function * called when a previously registered (Bochs) timer triggers. This function
* searches for the provided TimerEvent object within the EventList and * searches for the provided TimerEvent object within the EventManager and
* fires such an event by calling \c fireActiveEvents(). * fires such an event by calling \c fireActiveEvents().
* @param thisPtr a pointer to the TimerEvent-object triggered * @param thisPtr a pointer to the TimerEvent-object triggered
* *

View File

@ -85,10 +85,10 @@ void OVPController::onInstrPtrChanged(address_t instrPtr)
// << " R0: 0x" << hex << r0 << " ST: 0x" << hex << st << endl; // << " R0: 0x" << hex << r0 << " ST: 0x" << hex << st << endl;
// Check for active breakpoint-events: // Check for active breakpoint-events:
EventList::iterator it = m_EvList.begin(); EventManager::iterator it = m_EvList.begin();
while (it != m_EvList.end()) { while (it != m_EvList.end()) {
// FIXME: Performance verbessern (dazu muss entsprechend auch die Speicherung // FIXME: Performance verbessern (dazu muss entsprechend auch die Speicherung
// in EventList(.cc|.hpp) angepasst bzw. verbessert werden). // in EventManager(.cc|.hpp) angepasst bzw. verbessert werden).
BPSingleEvent* pEvBreakpt = dynamic_cast<BPSingleEvent*>(*it); BPSingleEvent* pEvBreakpt = dynamic_cast<BPSingleEvent*>(*it);
if (pEvBreakpt && (instrPtr == pEvBreakpt->getWatchInstructionPointer() || if (pEvBreakpt && (instrPtr == pEvBreakpt->getWatchInstructionPointer() ||
pEvBreakpt->getWatchInstructionPointer() == ANY_ADDR)) { pEvBreakpt->getWatchInstructionPointer() == ANY_ADDR)) {