Code Search for Developers
 
 
  

dynamicPriorityScheduler.h from GreenSocs at Krugle


Show dynamicPriorityScheduler.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 __PLBScheduler_h__
#define __PLBScheduler_h__

#include <systemc.h>
#include "router/genericRouter.h"
#include "router/genericScheduler_if.h"
#include <set>
#include "gstlm/tlm.h"
#include "protocol/PLB.h"
#include "protocol/generic.h"

using namespace tlm;
using namespace PLB;

struct unevenpair_with_prio_and_time {
  public:
  typedef tlm::unevenpair<GenericTransaction_P,GenericPhase> TRANSACTION_PHASE;
  TRANSACTION_PHASE m_tp;
  sc_time m_enqueue_time;
  unsigned int m_prio;
  
  unevenpair_with_prio_and_time(TRANSACTION_PHASE tp, sc_time enqueue_time, unsigned int prio) :
  m_tp(tp), m_enqueue_time(enqueue_time), m_prio(prio){};

};

class PLBCmpScheme {

  typedef tlm::unevenpair<GenericTransaction_P,GenericPhase> TRANSACTION_PHASE;

public:
  PLBCmpScheme(std::map<unsigned int, unsigned int>* masterMap_): m_pMasterMap(masterMap_) {
  }

  PLBCmpScheme(): m_pMasterMap(NULL) {
  }

  bool operator()(const unevenpair_with_prio_and_time& x,
                  const unevenpair_with_prio_and_time& y){
    bool temp(false);
    if(x.m_prio == y.m_prio)
      temp=(*m_pMasterMap)[x.m_tp.first->get_mID()]<(*m_pMasterMap)[y.m_tp.first->get_mID()];
    else
      temp = x.m_prio > y.m_prio;
    return temp;
  }

private:
  std::map<unsigned int, unsigned int>* m_pMasterMap;

};

class dynamicPriorityScheduler 
: public GenericScheduler_if<GenericTransaction, GenericPhase>,
  public sc_module
{

  typedef tlm::unevenpair<GenericTransaction_P,GenericPhase> TRANSACTION_PHASE;

public:
  dynamicPriorityScheduler(sc_module_name name_, double time, sc_time_unit base)
    : sc_module(name_),m_isPendingWasCalled(false), m_clkPeriod(time,base)
  {    
    GS_TRACE(name(), "I am a PLB queue.");

    // DUST structure analysis
#ifdef DUST_ENABLE
    DUST_SCHEDULER("DynamicPriorityScheduler");
#endif
  }

  typedef std::multiset<unevenpair_with_prio_and_time, PLBCmpScheme > transactionSet;

  virtual void enqueue(TRANSACTION_PHASE& t) {
    PLBTransaction_P test=boost::dynamic_pointer_cast<PLBTransaction>((t.first));
    if (test) {
      m_queue.insert(unevenpair_with_prio_and_time(t, sc_time_stamp(), test->get_mPrio()));
    }
    else {
      m_queue.insert(unevenpair_with_prio_and_time(t, sc_time_stamp(), 2));
    }
  }


  virtual TRANSACTION_PHASE& dequeue(bool remove) {
    if(!m_isPendingWasCalled){
      SC_REPORT_ERROR(name(), "Dequeue was called without preceeding isPending(). This is not allowed.");
      m_last = TRANSACTION_PHASE();
      return m_last;
    }
    if (m_queue.size()==0) {
      SC_REPORT_ERROR(name(), "Dequeue was called on empty queue.");
      m_last = TRANSACTION_PHASE();
      return m_last;
    }
    if (remove){
      m_queue.erase(m_pos);
      m_isPendingWasCalled=false;
    }
    m_last = (m_pos->m_tp);
    return m_last;
  }

  
  virtual bool isPending() {
    m_isPendingWasCalled=true;
    for(m_pos=m_queue.begin(); m_pos!=m_queue.end();++m_pos){
      if(m_pos->m_enqueue_time+m_clkPeriod<=sc_time_stamp()){
        return true;
      }
    }
    return false;
  }

  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_) {
    m_cmp = PLBCmpScheme(masterMap_);
    m_queue = transactionSet(m_cmp);
  }


protected:
  bool m_isPendingWasCalled;
  transactionSet m_queue;
  transactionSet::iterator m_pos;
  PLBCmpScheme m_cmp;
  TRANSACTION_PHASE m_last;
  sc_time m_clkPeriod;
};
  


#endif




See more files for this project here

GreenSocs

To develop SystemC infrustructure, basic IP, patches and add on library code for eventual standerdization.\r\nThe GreenSocs project is made up of a number of contributions (sub projects). Please visit www.greensocs.com for more information.

Project homepage: http://sourceforge.net/projects/greensocs
Programming language(s): C,C++,Java,Perl,XML
License: other

  dynamicPriorityScheduler.h
  fixedPriorityScheduler.h