fixedPriorityScheduler.h from GreenSocs at Krugle
Show fixedPriorityScheduler.h syntax highlighted
/*
Copyright (c) 2006 : Technical University of Braunschweig, Germany
All rights reserved.
Authors: Robert Guenzel, Wolfgang Klingauf, TU Braunschweig, E.I.S.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer. Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution. Neither the name of
the Technical University of Braunschweig, Germany nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __roundRobinScheduler_h__
#define __roundRobinScheduler_h__
#include <systemc.h>
#include "router/genericRouter.h"
#include "router/genericScheduler_if.h"
#include <set>
#include "gstlm/tlm.h"
using namespace tlm;
//--------------------------------------------------------------------------
/**
* This is the comparator used for inserting new requests into the queue.
*/
//--------------------------------------------------------------------------
template <class TRANSACTION_PHASE>
class fixedPrioritySchedulerCmp
{
public:
fixedPrioritySchedulerCmp() {}
fixedPrioritySchedulerCmp(std::map<unsigned int, unsigned int> *masterMap) :
m_pMasterMap(masterMap)
{}
bool operator()(const TRANSACTION_PHASE& x, const TRANSACTION_PHASE& y)
{
GenericRouterAccess& t1 = dynamic_cast<GenericRouterAccess&>(*(x.first));
GenericRouterAccess& t2 = dynamic_cast<GenericRouterAccess&>(*(y.first));
// cout<<"t1.get_mID(): "<<t1.get_mID()<<endl;
// cout<<"t2.get_mID(): "<<t2.get_mID()<<endl;
// cout<<"mastermap[t1.get_mID()]: "<< (*m_pMasterMap)[t1.get_mID()]<<endl;
// cout<<"mastermap[t2.get_mID()]: "<< (*m_pMasterMap)[t2.get_mID()]<<endl;
// sorting criterium is the master connection ordering
return (*m_pMasterMap)[t1.get_mID()]<(*m_pMasterMap)[t2.get_mID()];
}
protected:
std::map<unsigned int, unsigned int> * m_pMasterMap;
};
//--------------------------------------------------------------------------
/**
* A round-robin queue
*/
//--------------------------------------------------------------------------
template <class TRANSACTION,
class PHASE,
class TRANSACTION_P = boost::shared_ptr<TRANSACTION>,
class PHASE_P = PHASE,
class TRANSACTION_PHASE = tlm::unevenpair<TRANSACTION_P, PHASE_P> >
class fixedPriorityScheduler
: public GenericScheduler_if<TRANSACTION, PHASE>,
public sc_module
{
public:
// fixedPriorityScheduler(std::map<unsigned int, unsigned int>* masterMap_)
fixedPriorityScheduler(sc_module_name name_)
: sc_module(name_)
{
GS_TRACE(name(), "I am a fixed-priority scheduler.");
// DUST structure analysis
#ifdef DUST_ENABLE
DUST_SCHEDULER("FixedPriorityScheduler");
#endif
}
typedef std::multiset<TRANSACTION_PHASE, fixedPrioritySchedulerCmp<TRANSACTION_PHASE> > transactionSet;
virtual void enqueue(TRANSACTION_PHASE& t) {
m_queue.insert(t);
#ifdef VERBOSE
GenericRouterAccess& t_ = dynamic_cast<GenericRouterAccess&>(*(t.first));
GS_TRACE(name(), "Queuing a RequestValid atom from master id=0x%x", (unsigned int)t_.get_mID());
GS_TRACE(name(), "Queue size now is %d", m_queue.size());
#endif
}
virtual TRANSACTION_PHASE& dequeue(bool remove) {
if (m_queue.size()==0) {
SC_REPORT_ERROR(name(), "Dequeue was called on empty queue.");
m_last = TRANSACTION_PHASE();
return m_last;
}
m_pos = m_queue.begin();
m_last = (*m_pos);
if (remove)
m_queue.erase(m_pos);
#ifdef VERBOSE
GenericRouterAccess& t_ = dynamic_cast<GenericRouterAccess&>(*(m_last.first));
GS_TRACE(name(), "Popping a request from master id=0x%x", (unsigned int)t_.get_mID());
GS_TRACE(name(), "Queue size now is %d", m_queue.size());
#endif
return m_last;
}
virtual bool isPending() {
return m_queue.size()>0;
}
virtual bool isEmpty() {
return m_queue.size()==0;
}
/**
* Store the master map of the router to get access to the master connection ordering
*/
virtual void setMasterMap(std::map<unsigned int, unsigned int> *masterMap_) {
GS_TRACE(name(), "Master map has been set");
m_cmp = fixedPrioritySchedulerCmp<TRANSACTION_PHASE>(masterMap_);
m_queue = transactionSet(m_cmp);
}
protected:
transactionSet m_queue;
typename transactionSet::iterator m_pos;
fixedPrioritySchedulerCmp<TRANSACTION_PHASE> m_cmp;
TRANSACTION_PHASE m_last;
};
#endif
See more files for this project here