Sequencer.cc revision 6876
16145Snate@binkert.org
26145Snate@binkert.org/*
36145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
46145Snate@binkert.org * All rights reserved.
56145Snate@binkert.org *
66145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
76145Snate@binkert.org * modification, are permitted provided that the following conditions are
86145Snate@binkert.org * met: redistributions of source code must retain the above copyright
96145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
106145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
116145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
126145Snate@binkert.org * documentation and/or other materials provided with the distribution;
136145Snate@binkert.org * neither the name of the copyright holders nor the names of its
146145Snate@binkert.org * contributors may be used to endorse or promote products derived from
156145Snate@binkert.org * this software without specific prior written permission.
166145Snate@binkert.org *
176145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286145Snate@binkert.org */
296145Snate@binkert.org
306845Sdrh5@cs.wisc.edu#include "mem/ruby/libruby.hh"
316154Snate@binkert.org#include "mem/ruby/common/Global.hh"
326154Snate@binkert.org#include "mem/ruby/system/Sequencer.hh"
336154Snate@binkert.org#include "mem/ruby/system/System.hh"
346154Snate@binkert.org#include "mem/protocol/Protocol.hh"
356154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh"
366154Snate@binkert.org#include "mem/ruby/system/CacheMemory.hh"
376285Snate@binkert.org#include "mem/protocol/CacheMsg.hh"
386285Snate@binkert.org#include "mem/ruby/recorder/Tracer.hh"
396154Snate@binkert.org#include "mem/ruby/common/SubBlock.hh"
406154Snate@binkert.org#include "mem/protocol/Protocol.hh"
416154Snate@binkert.org#include "mem/gems_common/Map.hh"
426285Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh"
436285Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh"
446145Snate@binkert.org
456876Ssteve.reinhardt@amd.com#include "params/RubySequencer.hh"
466876Ssteve.reinhardt@amd.com
476285Snate@binkert.org//Sequencer::Sequencer(int core_id, MessageBuffer* mandatory_q)
486145Snate@binkert.org
496355Spdudnik@gmail.com#define LLSC_FAIL -2
506850Spdudnik@gmail.comlong int already = 0;
516876Ssteve.reinhardt@amd.com
526876Ssteve.reinhardt@amd.comSequencer *
536876Ssteve.reinhardt@amd.comRubySequencerParams::create()
546285Snate@binkert.org{
556876Ssteve.reinhardt@amd.com    return new Sequencer(this);
566285Snate@binkert.org}
576876Ssteve.reinhardt@amd.com
586876Ssteve.reinhardt@amd.comSequencer::Sequencer(const Params *p)
596876Ssteve.reinhardt@amd.com    : RubyPort(p)
606876Ssteve.reinhardt@amd.com{
616876Ssteve.reinhardt@amd.com    m_store_waiting_on_load_cycles = 0;
626876Ssteve.reinhardt@amd.com    m_store_waiting_on_store_cycles = 0;
636876Ssteve.reinhardt@amd.com    m_load_waiting_on_store_cycles = 0;
646876Ssteve.reinhardt@amd.com    m_load_waiting_on_load_cycles = 0;
656876Ssteve.reinhardt@amd.com
666876Ssteve.reinhardt@amd.com    m_deadlock_check_scheduled = false;
676876Ssteve.reinhardt@amd.com    m_outstanding_count = 0;
686285Snate@binkert.org
696876Ssteve.reinhardt@amd.com    m_max_outstanding_requests = 0;
706876Ssteve.reinhardt@amd.com    m_deadlock_threshold = 0;
716876Ssteve.reinhardt@amd.com    m_instCache_ptr = NULL;
726876Ssteve.reinhardt@amd.com    m_dataCache_ptr = NULL;
736145Snate@binkert.org
746876Ssteve.reinhardt@amd.com    m_instCache_ptr = p->icache;
756876Ssteve.reinhardt@amd.com    m_dataCache_ptr = p->dcache;
766876Ssteve.reinhardt@amd.com    m_max_outstanding_requests = p->max_outstanding_requests;
776876Ssteve.reinhardt@amd.com    m_deadlock_threshold = p->deadlock_threshold;
786876Ssteve.reinhardt@amd.com
796876Ssteve.reinhardt@amd.com    assert(m_max_outstanding_requests > 0);
806876Ssteve.reinhardt@amd.com    assert(m_deadlock_threshold > 0);
816876Ssteve.reinhardt@amd.com    assert(m_instCache_ptr != NULL);
826876Ssteve.reinhardt@amd.com    assert(m_dataCache_ptr != NULL);
836145Snate@binkert.org}
846145Snate@binkert.org
856145Snate@binkert.orgSequencer::~Sequencer() {
866285Snate@binkert.org
876145Snate@binkert.org}
886145Snate@binkert.org
896145Snate@binkert.orgvoid Sequencer::wakeup() {
906145Snate@binkert.org  // Check for deadlock of any of the requests
916145Snate@binkert.org  Time current_time = g_eventQueue_ptr->getTime();
926145Snate@binkert.org
936145Snate@binkert.org  // Check across all outstanding requests
946145Snate@binkert.org  int total_outstanding = 0;
956285Snate@binkert.org
966285Snate@binkert.org  Vector<Address> keys = m_readRequestTable.keys();
976285Snate@binkert.org  for (int i=0; i<keys.size(); i++) {
986285Snate@binkert.org    SequencerRequest* request = m_readRequestTable.lookup(keys[i]);
996285Snate@binkert.org    if (current_time - request->issue_time >= m_deadlock_threshold) {
1006285Snate@binkert.org      WARN_MSG("Possible Deadlock detected");
1016510Spdudnik@gmail.com      WARN_EXPR(request);
1026285Snate@binkert.org      WARN_EXPR(m_version);
1036825Spdudnik@gmail.com      WARN_EXPR(request->ruby_request.paddr);
1046285Snate@binkert.org      WARN_EXPR(keys.size());
1056285Snate@binkert.org      WARN_EXPR(current_time);
1066285Snate@binkert.org      WARN_EXPR(request->issue_time);
1076285Snate@binkert.org      WARN_EXPR(current_time - request->issue_time);
1086285Snate@binkert.org      ERROR_MSG("Aborting");
1096145Snate@binkert.org    }
1106285Snate@binkert.org  }
1116145Snate@binkert.org
1126285Snate@binkert.org  keys = m_writeRequestTable.keys();
1136285Snate@binkert.org  for (int i=0; i<keys.size(); i++) {
1146285Snate@binkert.org    SequencerRequest* request = m_writeRequestTable.lookup(keys[i]);
1156285Snate@binkert.org    if (current_time - request->issue_time >= m_deadlock_threshold) {
1166285Snate@binkert.org      WARN_MSG("Possible Deadlock detected");
1176510Spdudnik@gmail.com      WARN_EXPR(request);
1186285Snate@binkert.org      WARN_EXPR(m_version);
1196285Snate@binkert.org      WARN_EXPR(current_time);
1206285Snate@binkert.org      WARN_EXPR(request->issue_time);
1216285Snate@binkert.org      WARN_EXPR(current_time - request->issue_time);
1226285Snate@binkert.org      WARN_EXPR(keys.size());
1236285Snate@binkert.org      ERROR_MSG("Aborting");
1246145Snate@binkert.org    }
1256285Snate@binkert.org  }
1266285Snate@binkert.org  total_outstanding += m_writeRequestTable.size() + m_readRequestTable.size();
1276285Snate@binkert.org
1286145Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
1296145Snate@binkert.org
1306145Snate@binkert.org  if (m_outstanding_count > 0) { // If there are still outstanding requests, keep checking
1316285Snate@binkert.org    g_eventQueue_ptr->scheduleEvent(this, m_deadlock_threshold);
1326145Snate@binkert.org  } else {
1336145Snate@binkert.org    m_deadlock_check_scheduled = false;
1346145Snate@binkert.org  }
1356145Snate@binkert.org}
1366145Snate@binkert.org
1376859Sdrh5@cs.wisc.eduvoid Sequencer::printStats(ostream & out) const {
1386859Sdrh5@cs.wisc.edu  out << "Sequencer: " << m_name << endl;
1396859Sdrh5@cs.wisc.edu  out << "  store_waiting_on_load_cycles: " << m_store_waiting_on_load_cycles << endl;
1406859Sdrh5@cs.wisc.edu  out << "  store_waiting_on_store_cycles: " << m_store_waiting_on_store_cycles << endl;
1416859Sdrh5@cs.wisc.edu  out << "  load_waiting_on_load_cycles: " << m_load_waiting_on_load_cycles << endl;
1426859Sdrh5@cs.wisc.edu  out << "  load_waiting_on_store_cycles: " << m_load_waiting_on_store_cycles << endl;
1436859Sdrh5@cs.wisc.edu}
1446859Sdrh5@cs.wisc.edu
1456145Snate@binkert.orgvoid Sequencer::printProgress(ostream& out) const{
1466285Snate@binkert.org  /*
1476145Snate@binkert.org  int total_demand = 0;
1486145Snate@binkert.org  out << "Sequencer Stats Version " << m_version << endl;
1496145Snate@binkert.org  out << "Current time = " << g_eventQueue_ptr->getTime() << endl;
1506145Snate@binkert.org  out << "---------------" << endl;
1516145Snate@binkert.org  out << "outstanding requests" << endl;
1526145Snate@binkert.org
1536285Snate@binkert.org  Vector<Address> rkeys = m_readRequestTable.keys();
1546285Snate@binkert.org  int read_size = rkeys.size();
1556285Snate@binkert.org  out << "proc " << m_version << " Read Requests = " << read_size << endl;
1566285Snate@binkert.org  // print the request table
1576285Snate@binkert.org  for(int i=0; i < read_size; ++i){
1586285Snate@binkert.org    SequencerRequest * request = m_readRequestTable.lookup(rkeys[i]);
1596285Snate@binkert.org    out << "\tRequest[ " << i << " ] = " << request->type << " Address " << rkeys[i]  << " Posted " << request->issue_time << " PF " << PrefetchBit_No << endl;
1606285Snate@binkert.org    total_demand++;
1616285Snate@binkert.org  }
1626145Snate@binkert.org
1636285Snate@binkert.org  Vector<Address> wkeys = m_writeRequestTable.keys();
1646285Snate@binkert.org  int write_size = wkeys.size();
1656285Snate@binkert.org  out << "proc " << m_version << " Write Requests = " << write_size << endl;
1666285Snate@binkert.org  // print the request table
1676285Snate@binkert.org  for(int i=0; i < write_size; ++i){
1686285Snate@binkert.org      CacheMsg & request = m_writeRequestTable.lookup(wkeys[i]);
1696145Snate@binkert.org      out << "\tRequest[ " << i << " ] = " << request.getType() << " Address " << wkeys[i]  << " Posted " << request.getTime() << " PF " << request.getPrefetch() << endl;
1706145Snate@binkert.org      if( request.getPrefetch() == PrefetchBit_No ){
1716145Snate@binkert.org        total_demand++;
1726145Snate@binkert.org      }
1736285Snate@binkert.org  }
1746145Snate@binkert.org
1756285Snate@binkert.org  out << endl;
1766285Snate@binkert.org
1776145Snate@binkert.org  out << "Total Number Outstanding: " << m_outstanding_count << endl;
1786145Snate@binkert.org  out << "Total Number Demand     : " << total_demand << endl;
1796145Snate@binkert.org  out << "Total Number Prefetches : " << m_outstanding_count - total_demand << endl;
1806145Snate@binkert.org  out << endl;
1816145Snate@binkert.org  out << endl;
1826285Snate@binkert.org  */
1836145Snate@binkert.org}
1846145Snate@binkert.org
1856285Snate@binkert.orgvoid Sequencer::printConfig(ostream& out) const {
1866285Snate@binkert.org  out << "Seqeuncer config: " << m_name << endl;
1876285Snate@binkert.org  out << "  controller: " << m_controller->getName() << endl;
1886285Snate@binkert.org  out << "  version: " << m_version << endl;
1896285Snate@binkert.org  out << "  max_outstanding_requests: " << m_max_outstanding_requests << endl;
1906285Snate@binkert.org  out << "  deadlock_threshold: " << m_deadlock_threshold << endl;
1916145Snate@binkert.org}
1926145Snate@binkert.org
1936145Snate@binkert.org// Insert the request on the correct request table.  Return true if
1946145Snate@binkert.org// the entry was already present.
1956285Snate@binkert.orgbool Sequencer::insertRequest(SequencerRequest* request) {
1966285Snate@binkert.org  int total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size();
1976285Snate@binkert.org
1986145Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
1996145Snate@binkert.org
2006145Snate@binkert.org  // See if we should schedule a deadlock check
2016145Snate@binkert.org  if (m_deadlock_check_scheduled == false) {
2026285Snate@binkert.org    g_eventQueue_ptr->scheduleEvent(this, m_deadlock_threshold);
2036145Snate@binkert.org    m_deadlock_check_scheduled = true;
2046145Snate@binkert.org  }
2056145Snate@binkert.org
2066285Snate@binkert.org  Address line_addr(request->ruby_request.paddr);
2076285Snate@binkert.org  line_addr.makeLineAddress();
2086285Snate@binkert.org  if ((request->ruby_request.type == RubyRequestType_ST) ||
2096355Spdudnik@gmail.com      (request->ruby_request.type == RubyRequestType_RMW_Read) ||
2106355Spdudnik@gmail.com      (request->ruby_request.type == RubyRequestType_RMW_Write) ||
2116350Spdudnik@gmail.com      (request->ruby_request.type == RubyRequestType_Locked_Read) ||
2126350Spdudnik@gmail.com      (request->ruby_request.type == RubyRequestType_Locked_Write)) {
2136285Snate@binkert.org    if (m_writeRequestTable.exist(line_addr)) {
2146285Snate@binkert.org      m_writeRequestTable.lookup(line_addr) = request;
2156285Snate@binkert.org      //      return true;
2166285Snate@binkert.org      assert(0); // drh5: isn't this an error?  do you lose the initial request?
2176145Snate@binkert.org    }
2186285Snate@binkert.org    m_writeRequestTable.allocate(line_addr);
2196285Snate@binkert.org    m_writeRequestTable.lookup(line_addr) = request;
2206145Snate@binkert.org    m_outstanding_count++;
2216145Snate@binkert.org  } else {
2226285Snate@binkert.org    if (m_readRequestTable.exist(line_addr)) {
2236285Snate@binkert.org      m_readRequestTable.lookup(line_addr) = request;
2246285Snate@binkert.org      //      return true;
2256285Snate@binkert.org      assert(0); // drh5: isn't this an error?  do you lose the initial request?
2266145Snate@binkert.org    }
2276285Snate@binkert.org    m_readRequestTable.allocate(line_addr);
2286285Snate@binkert.org    m_readRequestTable.lookup(line_addr) = request;
2296145Snate@binkert.org    m_outstanding_count++;
2306145Snate@binkert.org  }
2316145Snate@binkert.org
2326145Snate@binkert.org  g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count);
2336145Snate@binkert.org
2346285Snate@binkert.org  total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size();
2356285Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
2366145Snate@binkert.org
2376145Snate@binkert.org  return false;
2386145Snate@binkert.org}
2396145Snate@binkert.org
2406285Snate@binkert.orgvoid Sequencer::removeRequest(SequencerRequest* srequest) {
2416145Snate@binkert.org
2426285Snate@binkert.org  assert(m_outstanding_count == m_writeRequestTable.size() + m_readRequestTable.size());
2436285Snate@binkert.org
2446285Snate@binkert.org  const RubyRequest & ruby_request = srequest->ruby_request;
2456285Snate@binkert.org  Address line_addr(ruby_request.paddr);
2466285Snate@binkert.org  line_addr.makeLineAddress();
2476285Snate@binkert.org  if ((ruby_request.type == RubyRequestType_ST) ||
2486355Spdudnik@gmail.com      (ruby_request.type == RubyRequestType_RMW_Read) ||
2496355Spdudnik@gmail.com      (ruby_request.type == RubyRequestType_RMW_Write) ||
2506350Spdudnik@gmail.com      (ruby_request.type == RubyRequestType_Locked_Read) ||
2516350Spdudnik@gmail.com      (ruby_request.type == RubyRequestType_Locked_Write)) {
2526285Snate@binkert.org    m_writeRequestTable.deallocate(line_addr);
2536145Snate@binkert.org  } else {
2546285Snate@binkert.org    m_readRequestTable.deallocate(line_addr);
2556145Snate@binkert.org  }
2566145Snate@binkert.org  m_outstanding_count--;
2576145Snate@binkert.org
2586285Snate@binkert.org  assert(m_outstanding_count == m_writeRequestTable.size() + m_readRequestTable.size());
2596145Snate@binkert.org}
2606145Snate@binkert.org
2616145Snate@binkert.orgvoid Sequencer::writeCallback(const Address& address, DataBlock& data) {
2626145Snate@binkert.org
2636145Snate@binkert.org  assert(address == line_address(address));
2646285Snate@binkert.org  assert(m_writeRequestTable.exist(line_address(address)));
2656145Snate@binkert.org
2666285Snate@binkert.org  SequencerRequest* request = m_writeRequestTable.lookup(address);
2676846Spdudnik@cs.wisc.edu
2686145Snate@binkert.org  removeRequest(request);
2696145Snate@binkert.org
2706285Snate@binkert.org  assert((request->ruby_request.type == RubyRequestType_ST) ||
2716355Spdudnik@gmail.com         (request->ruby_request.type == RubyRequestType_RMW_Read) ||
2726355Spdudnik@gmail.com         (request->ruby_request.type == RubyRequestType_RMW_Write) ||
2736350Spdudnik@gmail.com         (request->ruby_request.type == RubyRequestType_Locked_Read) ||
2746350Spdudnik@gmail.com         (request->ruby_request.type == RubyRequestType_Locked_Write));
2756863Sdrh5@cs.wisc.edu
2766350Spdudnik@gmail.com  if (request->ruby_request.type == RubyRequestType_Locked_Read) {
2776347Spdudnik@gmail.com    m_dataCache_ptr->setLocked(address, m_version);
2786347Spdudnik@gmail.com  }
2796506Spdudnik@gmail.com  else if (request->ruby_request.type == RubyRequestType_RMW_Read) {
2806863Sdrh5@cs.wisc.edu    m_controller->blockOnQueue(address, m_mandatory_q_ptr);
2816506Spdudnik@gmail.com  }
2826506Spdudnik@gmail.com  else if (request->ruby_request.type == RubyRequestType_RMW_Write) {
2836863Sdrh5@cs.wisc.edu    m_controller->unblock(address);
2846506Spdudnik@gmail.com  }
2856145Snate@binkert.org
2866285Snate@binkert.org  hitCallback(request, data);
2876145Snate@binkert.org}
2886145Snate@binkert.org
2896145Snate@binkert.orgvoid Sequencer::readCallback(const Address& address, DataBlock& data) {
2906145Snate@binkert.org
2916285Snate@binkert.org  assert(address == line_address(address));
2926285Snate@binkert.org  assert(m_readRequestTable.exist(line_address(address)));
2936145Snate@binkert.org
2946285Snate@binkert.org  SequencerRequest* request = m_readRequestTable.lookup(address);
2956285Snate@binkert.org  removeRequest(request);
2966285Snate@binkert.org
2976285Snate@binkert.org  assert((request->ruby_request.type == RubyRequestType_LD) ||
2986381Sdrh5@cs.wisc.edu	 (request->ruby_request.type == RubyRequestType_RMW_Read) ||
2996285Snate@binkert.org         (request->ruby_request.type == RubyRequestType_IFETCH));
3006285Snate@binkert.org
3016285Snate@binkert.org  hitCallback(request, data);
3026145Snate@binkert.org}
3036145Snate@binkert.org
3046285Snate@binkert.orgvoid Sequencer::hitCallback(SequencerRequest* srequest, DataBlock& data) {
3056285Snate@binkert.org  const RubyRequest & ruby_request = srequest->ruby_request;
3066285Snate@binkert.org  Address request_address(ruby_request.paddr);
3076285Snate@binkert.org  Address request_line_address(ruby_request.paddr);
3086285Snate@binkert.org  request_line_address.makeLineAddress();
3096285Snate@binkert.org  RubyRequestType type = ruby_request.type;
3106285Snate@binkert.org  Time issued_time = srequest->issue_time;
3116145Snate@binkert.org
3126145Snate@binkert.org  // Set this cache entry to the most recently used
3136285Snate@binkert.org  if (type == RubyRequestType_IFETCH) {
3146285Snate@binkert.org    if (m_instCache_ptr->isTagPresent(request_line_address) )
3156285Snate@binkert.org      m_instCache_ptr->setMRU(request_line_address);
3166145Snate@binkert.org  } else {
3176285Snate@binkert.org    if (m_dataCache_ptr->isTagPresent(request_line_address) )
3186285Snate@binkert.org      m_dataCache_ptr->setMRU(request_line_address);
3196145Snate@binkert.org  }
3206145Snate@binkert.org
3216145Snate@binkert.org  assert(g_eventQueue_ptr->getTime() >= issued_time);
3226145Snate@binkert.org  Time miss_latency = g_eventQueue_ptr->getTime() - issued_time;
3236145Snate@binkert.org
3246285Snate@binkert.org  // Profile the miss latency for all non-zero demand misses
3256285Snate@binkert.org  if (miss_latency != 0) {
3266285Snate@binkert.org    g_system_ptr->getProfiler()->missLatency(miss_latency, type);
3276285Snate@binkert.org
3286285Snate@binkert.org    if (Debug::getProtocolTrace()) {
3296285Snate@binkert.org      g_system_ptr->getProfiler()->profileTransition("Seq", m_version, Address(ruby_request.paddr),
3306285Snate@binkert.org                                                     "", "Done", "", int_to_string(miss_latency)+" cycles");
3316285Snate@binkert.org    }
3326285Snate@binkert.org  }
3336285Snate@binkert.org  /*
3346285Snate@binkert.org  if (request.getPrefetch() == PrefetchBit_Yes) {
3356285Snate@binkert.org    return; // Ignore the prefetch
3366285Snate@binkert.org  }
3376285Snate@binkert.org  */
3386285Snate@binkert.org
3396285Snate@binkert.org  // update the data
3406285Snate@binkert.org  if (ruby_request.data != NULL) {
3416285Snate@binkert.org    if ((type == RubyRequestType_LD) ||
3426381Sdrh5@cs.wisc.edu        (type == RubyRequestType_IFETCH) ||
3436381Sdrh5@cs.wisc.edu        (type == RubyRequestType_RMW_Read)) {
3446285Snate@binkert.org      memcpy(ruby_request.data, data.getData(request_address.getOffset(), ruby_request.len), ruby_request.len);
3456285Snate@binkert.org    } else {
3466285Snate@binkert.org      data.setData(ruby_request.data, request_address.getOffset(), ruby_request.len);
3476285Snate@binkert.org    }
3486145Snate@binkert.org  }
3496145Snate@binkert.org
3506285Snate@binkert.org  m_hit_callback(srequest->id);
3516285Snate@binkert.org  delete srequest;
3526285Snate@binkert.org}
3536285Snate@binkert.org
3546285Snate@binkert.org// Returns true if the sequencer already has a load or store outstanding
3556845Sdrh5@cs.wisc.eduint Sequencer::isReady(const RubyRequest& request) {
3566859Sdrh5@cs.wisc.edu  bool is_outstanding_store = m_writeRequestTable.exist(line_address(Address(request.paddr)));
3576859Sdrh5@cs.wisc.edu  bool is_outstanding_load = m_readRequestTable.exist(line_address(Address(request.paddr)));
3586859Sdrh5@cs.wisc.edu  if ( is_outstanding_store ) {
3596859Sdrh5@cs.wisc.edu    if ((request.type == RubyRequestType_LD) ||
3606859Sdrh5@cs.wisc.edu        (request.type == RubyRequestType_IFETCH) ||
3616859Sdrh5@cs.wisc.edu        (request.type == RubyRequestType_RMW_Read)) {
3626859Sdrh5@cs.wisc.edu      m_store_waiting_on_load_cycles++;
3636859Sdrh5@cs.wisc.edu    } else {
3646859Sdrh5@cs.wisc.edu      m_store_waiting_on_store_cycles++;
3656859Sdrh5@cs.wisc.edu    }
3666859Sdrh5@cs.wisc.edu    return LIBRUBY_ALIASED_REQUEST;
3676859Sdrh5@cs.wisc.edu  } else if ( is_outstanding_load ) {
3686859Sdrh5@cs.wisc.edu    if ((request.type == RubyRequestType_ST) ||
3696859Sdrh5@cs.wisc.edu        (request.type == RubyRequestType_RMW_Write) ) {
3706859Sdrh5@cs.wisc.edu      m_load_waiting_on_store_cycles++;
3716859Sdrh5@cs.wisc.edu    } else {
3726859Sdrh5@cs.wisc.edu      m_load_waiting_on_load_cycles++;
3736859Sdrh5@cs.wisc.edu    }
3746856Sdrh5@cs.wisc.edu    return LIBRUBY_ALIASED_REQUEST;
3756145Snate@binkert.org  }
3766145Snate@binkert.org
3776510Spdudnik@gmail.com  if (m_outstanding_count >= m_max_outstanding_requests) {
3786845Sdrh5@cs.wisc.edu    return LIBRUBY_BUFFER_FULL;
3796145Snate@binkert.org  }
3806845Sdrh5@cs.wisc.edu
3816845Sdrh5@cs.wisc.edu  return 1;
3826145Snate@binkert.org}
3836145Snate@binkert.org
3846285Snate@binkert.orgbool Sequencer::empty() const {
3856285Snate@binkert.org  return (m_writeRequestTable.size() == 0) && (m_readRequestTable.size() == 0);
3866145Snate@binkert.org}
3876145Snate@binkert.org
3886349Spdudnik@gmail.com
3896285Snate@binkert.orgint64_t Sequencer::makeRequest(const RubyRequest & request)
3906285Snate@binkert.org{
3916285Snate@binkert.org  assert(Address(request.paddr).getOffset() + request.len <= RubySystem::getBlockSizeBytes());
3926845Sdrh5@cs.wisc.edu  int ready = isReady(request);
3936845Sdrh5@cs.wisc.edu  if (ready > 0) {
3946285Snate@binkert.org    int64_t id = makeUniqueRequestID();
3956285Snate@binkert.org    SequencerRequest *srequest = new SequencerRequest(request, id, g_eventQueue_ptr->getTime());
3966285Snate@binkert.org    bool found = insertRequest(srequest);
3976825Spdudnik@gmail.com    if (!found) {
3986350Spdudnik@gmail.com      if (request.type == RubyRequestType_Locked_Write) {
3996355Spdudnik@gmail.com        // NOTE: it is OK to check the locked flag here as the mandatory queue will be checked first
4006355Spdudnik@gmail.com        // ensuring that nothing comes between checking the flag and servicing the store
4016349Spdudnik@gmail.com        if (!m_dataCache_ptr->isLocked(line_address(Address(request.paddr)), m_version)) {
4026355Spdudnik@gmail.com          return LLSC_FAIL;
4036349Spdudnik@gmail.com        }
4046349Spdudnik@gmail.com        else {
4056349Spdudnik@gmail.com          m_dataCache_ptr->clearLocked(line_address(Address(request.paddr)));
4066349Spdudnik@gmail.com        }
4076349Spdudnik@gmail.com      }
4086285Snate@binkert.org      issueRequest(request);
4096145Snate@binkert.org
4106859Sdrh5@cs.wisc.edu      // TODO: issue hardware prefetches here
4116859Sdrh5@cs.wisc.edu      return id;
4126825Spdudnik@gmail.com    }
4136825Spdudnik@gmail.com    else {
4146825Spdudnik@gmail.com      assert(0);
4156859Sdrh5@cs.wisc.edu      return 0;
4166825Spdudnik@gmail.com    }
4176859Sdrh5@cs.wisc.edu  } else {
4186845Sdrh5@cs.wisc.edu    return ready;
4196145Snate@binkert.org  }
4206145Snate@binkert.org}
4216145Snate@binkert.org
4226285Snate@binkert.orgvoid Sequencer::issueRequest(const RubyRequest& request) {
4236285Snate@binkert.org
4246285Snate@binkert.org  // TODO: get rid of CacheMsg, CacheRequestType, and AccessModeTYpe, & have SLICC use RubyRequest and subtypes natively
4256285Snate@binkert.org  CacheRequestType ctype;
4266285Snate@binkert.org  switch(request.type) {
4276285Snate@binkert.org  case RubyRequestType_IFETCH:
4286285Snate@binkert.org    ctype = CacheRequestType_IFETCH;
4296285Snate@binkert.org    break;
4306285Snate@binkert.org  case RubyRequestType_LD:
4316285Snate@binkert.org    ctype = CacheRequestType_LD;
4326285Snate@binkert.org    break;
4336285Snate@binkert.org  case RubyRequestType_ST:
4346285Snate@binkert.org    ctype = CacheRequestType_ST;
4356285Snate@binkert.org    break;
4366350Spdudnik@gmail.com  case RubyRequestType_Locked_Read:
4376350Spdudnik@gmail.com  case RubyRequestType_Locked_Write:
4386846Spdudnik@cs.wisc.edu    ctype = CacheRequestType_ATOMIC;
4396285Snate@binkert.org    break;
4406355Spdudnik@gmail.com  case RubyRequestType_RMW_Read:
4416355Spdudnik@gmail.com    ctype = CacheRequestType_ATOMIC;
4426355Spdudnik@gmail.com    break;
4436355Spdudnik@gmail.com  case RubyRequestType_RMW_Write:
4446355Spdudnik@gmail.com    ctype = CacheRequestType_ATOMIC;
4456355Spdudnik@gmail.com    break;
4466285Snate@binkert.org  default:
4476285Snate@binkert.org    assert(0);
4486145Snate@binkert.org  }
4496285Snate@binkert.org  AccessModeType amtype;
4506285Snate@binkert.org  switch(request.access_mode){
4516285Snate@binkert.org  case RubyAccessMode_User:
4526285Snate@binkert.org    amtype = AccessModeType_UserMode;
4536285Snate@binkert.org    break;
4546285Snate@binkert.org  case RubyAccessMode_Supervisor:
4556285Snate@binkert.org    amtype = AccessModeType_SupervisorMode;
4566285Snate@binkert.org    break;
4576285Snate@binkert.org  case RubyAccessMode_Device:
4586285Snate@binkert.org    amtype = AccessModeType_UserMode;
4596285Snate@binkert.org    break;
4606285Snate@binkert.org  default:
4616285Snate@binkert.org    assert(0);
4626285Snate@binkert.org  }
4636285Snate@binkert.org  Address line_addr(request.paddr);
4646285Snate@binkert.org  line_addr.makeLineAddress();
4656505Spdudnik@gmail.com  CacheMsg msg(line_addr, Address(request.paddr), ctype, Address(request.pc), amtype, request.len, PrefetchBit_No, request.proc_id);
4666285Snate@binkert.org
4676285Snate@binkert.org  if (Debug::getProtocolTrace()) {
4686285Snate@binkert.org    g_system_ptr->getProfiler()->profileTransition("Seq", m_version, Address(request.paddr),
4696285Snate@binkert.org                                                   "", "Begin", "", RubyRequestType_to_string(request.type));
4706285Snate@binkert.org  }
4716285Snate@binkert.org
4726285Snate@binkert.org  if (g_system_ptr->getTracer()->traceEnabled()) {
4736285Snate@binkert.org    g_system_ptr->getTracer()->traceRequest(m_name, line_addr, Address(request.pc),
4746285Snate@binkert.org                                            request.type, g_eventQueue_ptr->getTime());
4756285Snate@binkert.org  }
4766285Snate@binkert.org
4776285Snate@binkert.org  Time latency = 0;  // initialzed to an null value
4786285Snate@binkert.org
4796285Snate@binkert.org  if (request.type == RubyRequestType_IFETCH)
4806285Snate@binkert.org    latency = m_instCache_ptr->getLatency();
4816285Snate@binkert.org  else
4826285Snate@binkert.org    latency = m_dataCache_ptr->getLatency();
4836285Snate@binkert.org
4846285Snate@binkert.org  // Send the message to the cache controller
4856285Snate@binkert.org  assert(latency > 0);
4866285Snate@binkert.org
4876876Ssteve.reinhardt@amd.com  assert(m_mandatory_q_ptr != NULL);
4886285Snate@binkert.org  m_mandatory_q_ptr->enqueue(msg, latency);
4896285Snate@binkert.org}
4906285Snate@binkert.org/*
4916285Snate@binkert.orgbool Sequencer::tryCacheAccess(const Address& addr, CacheRequestType type,
4926285Snate@binkert.org                               AccessModeType access_mode,
4936285Snate@binkert.org                               int size, DataBlock*& data_ptr) {
4946285Snate@binkert.org  if (type == CacheRequestType_IFETCH) {
4956285Snate@binkert.org    return m_instCache_ptr->tryCacheAccess(line_address(addr), type, data_ptr);
4966285Snate@binkert.org  } else {
4976285Snate@binkert.org    return m_dataCache_ptr->tryCacheAccess(line_address(addr), type, data_ptr);
4986145Snate@binkert.org  }
4996145Snate@binkert.org}
5006285Snate@binkert.org*/
5016145Snate@binkert.org
5026145Snate@binkert.orgvoid Sequencer::print(ostream& out) const {
5036285Snate@binkert.org  out << "[Sequencer: " << m_version
5046145Snate@binkert.org      << ", outstanding requests: " << m_outstanding_count;
5056145Snate@binkert.org
5066285Snate@binkert.org  out << ", read request table: " << m_readRequestTable
5076285Snate@binkert.org      << ", write request table: " << m_writeRequestTable;
5086145Snate@binkert.org  out << "]";
5096145Snate@binkert.org}
5106145Snate@binkert.org
5116145Snate@binkert.org// this can be called from setState whenever coherence permissions are upgraded
5126145Snate@binkert.org// when invoked, coherence violations will be checked for the given block
5136145Snate@binkert.orgvoid Sequencer::checkCoherence(const Address& addr) {
5146145Snate@binkert.org#ifdef CHECK_COHERENCE
5156145Snate@binkert.org  g_system_ptr->checkGlobalCoherenceInvariant(addr);
5166145Snate@binkert.org#endif
5176145Snate@binkert.org}
5186145Snate@binkert.org
519