Sequencer.cc revision 6152
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
306145Snate@binkert.org/*
316145Snate@binkert.org * $Id: Sequencer.C 1.131 2006/11/06 17:41:01-06:00 bobba@gratiano.cs.wisc.edu $
326145Snate@binkert.org *
336145Snate@binkert.org */
346145Snate@binkert.org
356145Snate@binkert.org#include "Global.hh"
366145Snate@binkert.org#include "Sequencer.hh"
376145Snate@binkert.org#include "System.hh"
386145Snate@binkert.org#include "Protocol.hh"
396145Snate@binkert.org#include "Profiler.hh"
406145Snate@binkert.org#include "CacheMemory.hh"
416145Snate@binkert.org#include "RubyConfig.hh"
426145Snate@binkert.org//#include "Tracer.hh"
436145Snate@binkert.org#include "AbstractChip.hh"
446145Snate@binkert.org#include "Chip.hh"
456145Snate@binkert.org#include "Tester.hh"
466145Snate@binkert.org#include "SubBlock.hh"
476145Snate@binkert.org#include "Protocol.hh"
486145Snate@binkert.org#include "Map.hh"
496145Snate@binkert.org#include "interface.hh"
506145Snate@binkert.org
516145Snate@binkert.orgSequencer::Sequencer(AbstractChip* chip_ptr, int version) {
526145Snate@binkert.org  m_chip_ptr = chip_ptr;
536145Snate@binkert.org  m_version = version;
546145Snate@binkert.org
556145Snate@binkert.org  m_deadlock_check_scheduled = false;
566145Snate@binkert.org  m_outstanding_count = 0;
576145Snate@binkert.org
586145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
596145Snate@binkert.org  m_writeRequestTable_ptr = new Map<Address, CacheMsg>*[smt_threads];
606145Snate@binkert.org  m_readRequestTable_ptr = new Map<Address, CacheMsg>*[smt_threads];
616145Snate@binkert.org
626145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
636145Snate@binkert.org    m_writeRequestTable_ptr[p] = new Map<Address, CacheMsg>;
646145Snate@binkert.org    m_readRequestTable_ptr[p] = new Map<Address, CacheMsg>;
656145Snate@binkert.org  }
666145Snate@binkert.org
676145Snate@binkert.org}
686145Snate@binkert.org
696145Snate@binkert.orgSequencer::~Sequencer() {
706145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
716145Snate@binkert.org  for(int i=0; i < smt_threads; ++i){
726145Snate@binkert.org    if(m_writeRequestTable_ptr[i]){
736145Snate@binkert.org      delete m_writeRequestTable_ptr[i];
746145Snate@binkert.org    }
756145Snate@binkert.org    if(m_readRequestTable_ptr[i]){
766145Snate@binkert.org      delete m_readRequestTable_ptr[i];
776145Snate@binkert.org    }
786145Snate@binkert.org  }
796145Snate@binkert.org  if(m_writeRequestTable_ptr){
806145Snate@binkert.org    delete [] m_writeRequestTable_ptr;
816145Snate@binkert.org  }
826145Snate@binkert.org  if(m_readRequestTable_ptr){
836145Snate@binkert.org    delete [] m_readRequestTable_ptr;
846145Snate@binkert.org  }
856145Snate@binkert.org}
866145Snate@binkert.org
876145Snate@binkert.orgvoid Sequencer::wakeup() {
886145Snate@binkert.org  // Check for deadlock of any of the requests
896145Snate@binkert.org  Time current_time = g_eventQueue_ptr->getTime();
906145Snate@binkert.org  bool deadlock = false;
916145Snate@binkert.org
926145Snate@binkert.org  // Check across all outstanding requests
936145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
946145Snate@binkert.org  int total_outstanding = 0;
956145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
966145Snate@binkert.org    Vector<Address> keys = m_readRequestTable_ptr[p]->keys();
976145Snate@binkert.org    for (int i=0; i<keys.size(); i++) {
986145Snate@binkert.org      CacheMsg& request = m_readRequestTable_ptr[p]->lookup(keys[i]);
996145Snate@binkert.org      if (current_time - request.getTime() >= g_DEADLOCK_THRESHOLD) {
1006145Snate@binkert.org        WARN_MSG("Possible Deadlock detected");
1016145Snate@binkert.org        WARN_EXPR(request);
1026145Snate@binkert.org        WARN_EXPR(m_chip_ptr->getID());
1036145Snate@binkert.org        WARN_EXPR(m_version);
1046145Snate@binkert.org        WARN_EXPR(keys.size());
1056145Snate@binkert.org        WARN_EXPR(current_time);
1066145Snate@binkert.org        WARN_EXPR(request.getTime());
1076145Snate@binkert.org        WARN_EXPR(current_time - request.getTime());
1086145Snate@binkert.org        WARN_EXPR(*m_readRequestTable_ptr[p]);
1096145Snate@binkert.org        ERROR_MSG("Aborting");
1106145Snate@binkert.org        deadlock = true;
1116145Snate@binkert.org      }
1126145Snate@binkert.org    }
1136145Snate@binkert.org
1146145Snate@binkert.org    keys = m_writeRequestTable_ptr[p]->keys();
1156145Snate@binkert.org    for (int i=0; i<keys.size(); i++) {
1166145Snate@binkert.org      CacheMsg& request = m_writeRequestTable_ptr[p]->lookup(keys[i]);
1176145Snate@binkert.org      if (current_time - request.getTime() >= g_DEADLOCK_THRESHOLD) {
1186145Snate@binkert.org        WARN_MSG("Possible Deadlock detected");
1196145Snate@binkert.org        WARN_EXPR(request);
1206145Snate@binkert.org        WARN_EXPR(m_chip_ptr->getID());
1216145Snate@binkert.org        WARN_EXPR(m_version);
1226145Snate@binkert.org        WARN_EXPR(current_time);
1236145Snate@binkert.org        WARN_EXPR(request.getTime());
1246145Snate@binkert.org        WARN_EXPR(current_time - request.getTime());
1256145Snate@binkert.org        WARN_EXPR(keys.size());
1266145Snate@binkert.org        WARN_EXPR(*m_writeRequestTable_ptr[p]);
1276145Snate@binkert.org        ERROR_MSG("Aborting");
1286145Snate@binkert.org        deadlock = true;
1296145Snate@binkert.org      }
1306145Snate@binkert.org    }
1316145Snate@binkert.org    total_outstanding += m_writeRequestTable_ptr[p]->size() + m_readRequestTable_ptr[p]->size();
1326145Snate@binkert.org  }  // across all request tables
1336145Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
1346145Snate@binkert.org
1356145Snate@binkert.org  if (m_outstanding_count > 0) { // If there are still outstanding requests, keep checking
1366145Snate@binkert.org    g_eventQueue_ptr->scheduleEvent(this, g_DEADLOCK_THRESHOLD);
1376145Snate@binkert.org  } else {
1386145Snate@binkert.org    m_deadlock_check_scheduled = false;
1396145Snate@binkert.org  }
1406145Snate@binkert.org}
1416145Snate@binkert.org
1426145Snate@binkert.org//returns the total number of requests
1436145Snate@binkert.orgint Sequencer::getNumberOutstanding(){
1446145Snate@binkert.org  return m_outstanding_count;
1456145Snate@binkert.org}
1466145Snate@binkert.org
1476145Snate@binkert.org// returns the total number of demand requests
1486145Snate@binkert.orgint Sequencer::getNumberOutstandingDemand(){
1496145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
1506145Snate@binkert.org  int total_demand = 0;
1516145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
1526145Snate@binkert.org    Vector<Address> keys = m_readRequestTable_ptr[p]->keys();
1536145Snate@binkert.org    for (int i=0; i< keys.size(); i++) {
1546145Snate@binkert.org      CacheMsg& request = m_readRequestTable_ptr[p]->lookup(keys[i]);
1556152Sdrh5@cs.wisc.edu      if(request.getPrefetch() == PrefetchBit_No){
1566152Sdrh5@cs.wisc.edu        total_demand++;
1576145Snate@binkert.org      }
1586145Snate@binkert.org    }
1596145Snate@binkert.org
1606145Snate@binkert.org    keys = m_writeRequestTable_ptr[p]->keys();
1616145Snate@binkert.org    for (int i=0; i< keys.size(); i++) {
1626145Snate@binkert.org      CacheMsg& request = m_writeRequestTable_ptr[p]->lookup(keys[i]);
1636145Snate@binkert.org      if(request.getPrefetch() == PrefetchBit_No){
1646145Snate@binkert.org        total_demand++;
1656145Snate@binkert.org      }
1666145Snate@binkert.org    }
1676145Snate@binkert.org  }
1686145Snate@binkert.org
1696145Snate@binkert.org  return total_demand;
1706145Snate@binkert.org}
1716145Snate@binkert.org
1726145Snate@binkert.orgint Sequencer::getNumberOutstandingPrefetch(){
1736145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
1746145Snate@binkert.org  int total_prefetch = 0;
1756145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
1766145Snate@binkert.org    Vector<Address> keys = m_readRequestTable_ptr[p]->keys();
1776145Snate@binkert.org    for (int i=0; i< keys.size(); i++) {
1786145Snate@binkert.org      CacheMsg& request = m_readRequestTable_ptr[p]->lookup(keys[i]);
1796145Snate@binkert.org      if(request.getPrefetch() == PrefetchBit_Yes){
1806145Snate@binkert.org        total_prefetch++;
1816145Snate@binkert.org      }
1826145Snate@binkert.org    }
1836145Snate@binkert.org
1846145Snate@binkert.org    keys = m_writeRequestTable_ptr[p]->keys();
1856145Snate@binkert.org    for (int i=0; i< keys.size(); i++) {
1866145Snate@binkert.org      CacheMsg& request = m_writeRequestTable_ptr[p]->lookup(keys[i]);
1876145Snate@binkert.org      if(request.getPrefetch() == PrefetchBit_Yes){
1886145Snate@binkert.org        total_prefetch++;
1896145Snate@binkert.org      }
1906145Snate@binkert.org    }
1916145Snate@binkert.org  }
1926145Snate@binkert.org
1936145Snate@binkert.org  return total_prefetch;
1946145Snate@binkert.org}
1956145Snate@binkert.org
1966145Snate@binkert.orgbool Sequencer::isPrefetchRequest(const Address & lineaddr){
1976145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
1986145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
1996145Snate@binkert.org    // check load requests
2006145Snate@binkert.org    Vector<Address> keys = m_readRequestTable_ptr[p]->keys();
2016145Snate@binkert.org    for (int i=0; i< keys.size(); i++) {
2026145Snate@binkert.org      CacheMsg& request = m_readRequestTable_ptr[p]->lookup(keys[i]);
2036145Snate@binkert.org      if(line_address(request.getAddress()) == lineaddr){
2046145Snate@binkert.org        if(request.getPrefetch() == PrefetchBit_Yes){
2056145Snate@binkert.org          return true;
2066145Snate@binkert.org        }
2076145Snate@binkert.org        else{
2086145Snate@binkert.org          return false;
2096145Snate@binkert.org        }
2106145Snate@binkert.org      }
2116145Snate@binkert.org    }
2126145Snate@binkert.org
2136145Snate@binkert.org    // check store requests
2146145Snate@binkert.org    keys = m_writeRequestTable_ptr[p]->keys();
2156145Snate@binkert.org    for (int i=0; i< keys.size(); i++) {
2166145Snate@binkert.org      CacheMsg& request = m_writeRequestTable_ptr[p]->lookup(keys[i]);
2176145Snate@binkert.org      if(line_address(request.getAddress()) == lineaddr){
2186145Snate@binkert.org        if(request.getPrefetch() == PrefetchBit_Yes){
2196145Snate@binkert.org          return true;
2206145Snate@binkert.org        }
2216145Snate@binkert.org        else{
2226145Snate@binkert.org          return false;
2236145Snate@binkert.org        }
2246145Snate@binkert.org      }
2256145Snate@binkert.org    }
2266145Snate@binkert.org  }
2276145Snate@binkert.org  // we should've found a matching request
2286145Snate@binkert.org  cout << "isRequestPrefetch() ERROR request NOT FOUND : " << lineaddr << endl;
2296145Snate@binkert.org  printProgress(cout);
2306145Snate@binkert.org  assert(0);
2316145Snate@binkert.org}
2326145Snate@binkert.org
2336145Snate@binkert.orgAccessModeType Sequencer::getAccessModeOfRequest(Address addr, int thread){
2346145Snate@binkert.org  if(m_readRequestTable_ptr[thread]->exist(line_address(addr))){
2356145Snate@binkert.org    CacheMsg& request = m_readRequestTable_ptr[thread]->lookup(addr);
2366145Snate@binkert.org    return request.getAccessMode();
2376145Snate@binkert.org  } else if(m_writeRequestTable_ptr[thread]->exist(line_address(addr))){
2386145Snate@binkert.org    CacheMsg& request = m_writeRequestTable_ptr[thread]->lookup(addr);
2396145Snate@binkert.org    return request.getAccessMode();
2406145Snate@binkert.org  } else {
2416145Snate@binkert.org    printProgress(cout);
2426145Snate@binkert.org    ERROR_MSG("Request not found in RequestTables");
2436145Snate@binkert.org  }
2446145Snate@binkert.org}
2456145Snate@binkert.org
2466145Snate@binkert.orgAddress Sequencer::getLogicalAddressOfRequest(Address addr, int thread){
2476145Snate@binkert.org  assert(thread >= 0);
2486145Snate@binkert.org  if(m_readRequestTable_ptr[thread]->exist(line_address(addr))){
2496145Snate@binkert.org    CacheMsg& request = m_readRequestTable_ptr[thread]->lookup(addr);
2506145Snate@binkert.org    return request.getLogicalAddress();
2516145Snate@binkert.org  } else if(m_writeRequestTable_ptr[thread]->exist(line_address(addr))){
2526145Snate@binkert.org    CacheMsg& request = m_writeRequestTable_ptr[thread]->lookup(addr);
2536145Snate@binkert.org    return request.getLogicalAddress();
2546145Snate@binkert.org  } else {
2556145Snate@binkert.org    printProgress(cout);
2566145Snate@binkert.org    WARN_MSG("Request not found in RequestTables");
2576145Snate@binkert.org    WARN_MSG(addr);
2586145Snate@binkert.org    WARN_MSG(thread);
2596145Snate@binkert.org    ASSERT(0);
2606145Snate@binkert.org  }
2616145Snate@binkert.org}
2626145Snate@binkert.org
2636145Snate@binkert.org// returns the ThreadID of the request
2646145Snate@binkert.orgint Sequencer::getRequestThreadID(const Address & addr){
2656145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
2666145Snate@binkert.org  int thread = -1;
2676145Snate@binkert.org  int num_found = 0;
2686145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
2696145Snate@binkert.org    if(m_readRequestTable_ptr[p]->exist(addr)){
2706145Snate@binkert.org      num_found++;
2716145Snate@binkert.org      thread = p;
2726145Snate@binkert.org    }
2736145Snate@binkert.org    if(m_writeRequestTable_ptr[p]->exist(addr)){
2746145Snate@binkert.org      num_found++;
2756145Snate@binkert.org      thread = p;
2766145Snate@binkert.org    }
2776145Snate@binkert.org  }
2786145Snate@binkert.org  if(num_found != 1){
2796145Snate@binkert.org    cout << "getRequestThreadID ERROR too many matching requests addr = " << addr << endl;
2806145Snate@binkert.org    printProgress(cout);
2816145Snate@binkert.org  }
2826145Snate@binkert.org  ASSERT(num_found == 1);
2836145Snate@binkert.org  ASSERT(thread != -1);
2846145Snate@binkert.org
2856145Snate@binkert.org  return thread;
2866145Snate@binkert.org}
2876145Snate@binkert.org
2886145Snate@binkert.org// given a line address, return the request's physical address
2896145Snate@binkert.orgAddress Sequencer::getRequestPhysicalAddress(const Address & lineaddr){
2906145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
2916145Snate@binkert.org  Address physaddr;
2926145Snate@binkert.org  int num_found = 0;
2936145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
2946145Snate@binkert.org    if(m_readRequestTable_ptr[p]->exist(lineaddr)){
2956145Snate@binkert.org      num_found++;
2966145Snate@binkert.org      physaddr = (m_readRequestTable_ptr[p]->lookup(lineaddr)).getAddress();
2976145Snate@binkert.org    }
2986145Snate@binkert.org    if(m_writeRequestTable_ptr[p]->exist(lineaddr)){
2996145Snate@binkert.org      num_found++;
3006145Snate@binkert.org      physaddr = (m_writeRequestTable_ptr[p]->lookup(lineaddr)).getAddress();
3016145Snate@binkert.org    }
3026145Snate@binkert.org  }
3036145Snate@binkert.org  if(num_found != 1){
3046145Snate@binkert.org    cout << "getRequestPhysicalAddress ERROR too many matching requests addr = " << lineaddr << endl;
3056145Snate@binkert.org    printProgress(cout);
3066145Snate@binkert.org  }
3076145Snate@binkert.org  ASSERT(num_found == 1);
3086145Snate@binkert.org
3096145Snate@binkert.org  return physaddr;
3106145Snate@binkert.org}
3116145Snate@binkert.org
3126145Snate@binkert.orgvoid Sequencer::printProgress(ostream& out) const{
3136145Snate@binkert.org
3146145Snate@binkert.org  int total_demand = 0;
3156145Snate@binkert.org  out << "Sequencer Stats Version " << m_version << endl;
3166145Snate@binkert.org  out << "Current time = " << g_eventQueue_ptr->getTime() << endl;
3176145Snate@binkert.org  out << "---------------" << endl;
3186145Snate@binkert.org  out << "outstanding requests" << endl;
3196145Snate@binkert.org
3206145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
3216145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
3226145Snate@binkert.org    Vector<Address> rkeys = m_readRequestTable_ptr[p]->keys();
3236145Snate@binkert.org    int read_size = rkeys.size();
3246145Snate@binkert.org    out << "proc " << m_chip_ptr->getID() << " thread " << p << " Read Requests = " << read_size << endl;
3256145Snate@binkert.org    // print the request table
3266145Snate@binkert.org    for(int i=0; i < read_size; ++i){
3276145Snate@binkert.org      CacheMsg & request = m_readRequestTable_ptr[p]->lookup(rkeys[i]);
3286145Snate@binkert.org      out << "\tRequest[ " << i << " ] = " << request.getType() << " Address " << rkeys[i]  << " Posted " << request.getTime() << " PF " << request.getPrefetch() << endl;
3296145Snate@binkert.org      if( request.getPrefetch() == PrefetchBit_No ){
3306145Snate@binkert.org        total_demand++;
3316145Snate@binkert.org      }
3326145Snate@binkert.org    }
3336145Snate@binkert.org
3346145Snate@binkert.org    Vector<Address> wkeys = m_writeRequestTable_ptr[p]->keys();
3356145Snate@binkert.org    int write_size = wkeys.size();
3366145Snate@binkert.org    out << "proc " << m_chip_ptr->getID() << " thread " << p << " Write Requests = " << write_size << endl;
3376145Snate@binkert.org    // print the request table
3386145Snate@binkert.org    for(int i=0; i < write_size; ++i){
3396145Snate@binkert.org      CacheMsg & request = m_writeRequestTable_ptr[p]->lookup(wkeys[i]);
3406145Snate@binkert.org      out << "\tRequest[ " << i << " ] = " << request.getType() << " Address " << wkeys[i]  << " Posted " << request.getTime() << " PF " << request.getPrefetch() << endl;
3416145Snate@binkert.org      if( request.getPrefetch() == PrefetchBit_No ){
3426145Snate@binkert.org        total_demand++;
3436145Snate@binkert.org      }
3446145Snate@binkert.org    }
3456145Snate@binkert.org
3466145Snate@binkert.org    out << endl;
3476145Snate@binkert.org  }
3486145Snate@binkert.org  out << "Total Number Outstanding: " << m_outstanding_count << endl;
3496145Snate@binkert.org  out << "Total Number Demand     : " << total_demand << endl;
3506145Snate@binkert.org  out << "Total Number Prefetches : " << m_outstanding_count - total_demand << endl;
3516145Snate@binkert.org  out << endl;
3526145Snate@binkert.org  out << endl;
3536145Snate@binkert.org
3546145Snate@binkert.org}
3556145Snate@binkert.org
3566145Snate@binkert.orgvoid Sequencer::printConfig(ostream& out) {
3576145Snate@binkert.org  if (TSO) {
3586145Snate@binkert.org    out << "sequencer: Sequencer - TSO" << endl;
3596145Snate@binkert.org  } else {
3606145Snate@binkert.org    out << "sequencer: Sequencer - SC" << endl;
3616145Snate@binkert.org  }
3626145Snate@binkert.org  out << "  max_outstanding_requests: " << g_SEQUENCER_OUTSTANDING_REQUESTS << endl;
3636145Snate@binkert.org}
3646145Snate@binkert.org
3656145Snate@binkert.orgbool Sequencer::empty() const {
3666145Snate@binkert.org  return m_outstanding_count == 0;
3676145Snate@binkert.org}
3686145Snate@binkert.org
3696145Snate@binkert.org// Insert the request on the correct request table.  Return true if
3706145Snate@binkert.org// the entry was already present.
3716145Snate@binkert.orgbool Sequencer::insertRequest(const CacheMsg& request) {
3726145Snate@binkert.org  int thread = request.getThreadID();
3736145Snate@binkert.org  assert(thread >= 0);
3746145Snate@binkert.org  int total_outstanding = 0;
3756145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
3766145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
3776145Snate@binkert.org    total_outstanding += m_writeRequestTable_ptr[p]->size() + m_readRequestTable_ptr[p]->size();
3786145Snate@binkert.org  }
3796145Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
3806145Snate@binkert.org
3816145Snate@binkert.org  // See if we should schedule a deadlock check
3826145Snate@binkert.org  if (m_deadlock_check_scheduled == false) {
3836145Snate@binkert.org    g_eventQueue_ptr->scheduleEvent(this, g_DEADLOCK_THRESHOLD);
3846145Snate@binkert.org    m_deadlock_check_scheduled = true;
3856145Snate@binkert.org  }
3866145Snate@binkert.org
3876145Snate@binkert.org  if ((request.getType() == CacheRequestType_ST) ||
3886145Snate@binkert.org      (request.getType() == CacheRequestType_ATOMIC)) {
3896145Snate@binkert.org    if (m_writeRequestTable_ptr[thread]->exist(line_address(request.getAddress()))) {
3906145Snate@binkert.org      m_writeRequestTable_ptr[thread]->lookup(line_address(request.getAddress())) = request;
3916145Snate@binkert.org      return true;
3926145Snate@binkert.org    }
3936145Snate@binkert.org    m_writeRequestTable_ptr[thread]->allocate(line_address(request.getAddress()));
3946145Snate@binkert.org    m_writeRequestTable_ptr[thread]->lookup(line_address(request.getAddress())) = request;
3956145Snate@binkert.org    m_outstanding_count++;
3966145Snate@binkert.org  } else {
3976145Snate@binkert.org    if (m_readRequestTable_ptr[thread]->exist(line_address(request.getAddress()))) {
3986145Snate@binkert.org      m_readRequestTable_ptr[thread]->lookup(line_address(request.getAddress())) = request;
3996145Snate@binkert.org      return true;
4006145Snate@binkert.org    }
4016145Snate@binkert.org    m_readRequestTable_ptr[thread]->allocate(line_address(request.getAddress()));
4026145Snate@binkert.org    m_readRequestTable_ptr[thread]->lookup(line_address(request.getAddress())) = request;
4036145Snate@binkert.org    m_outstanding_count++;
4046145Snate@binkert.org  }
4056145Snate@binkert.org
4066145Snate@binkert.org  g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count);
4076145Snate@binkert.org
4086145Snate@binkert.org  total_outstanding = 0;
4096145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
4106145Snate@binkert.org    total_outstanding += m_writeRequestTable_ptr[p]->size() + m_readRequestTable_ptr[p]->size();
4116145Snate@binkert.org  }
4126145Snate@binkert.org
4136145Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
4146145Snate@binkert.org  return false;
4156145Snate@binkert.org}
4166145Snate@binkert.org
4176145Snate@binkert.orgvoid Sequencer::removeRequest(const CacheMsg& request) {
4186145Snate@binkert.org  int thread = request.getThreadID();
4196145Snate@binkert.org  assert(thread >= 0);
4206145Snate@binkert.org  int total_outstanding = 0;
4216145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
4226145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
4236145Snate@binkert.org    total_outstanding += m_writeRequestTable_ptr[p]->size() + m_readRequestTable_ptr[p]->size();
4246145Snate@binkert.org  }
4256145Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
4266145Snate@binkert.org
4276145Snate@binkert.org  if ((request.getType() == CacheRequestType_ST) ||
4286145Snate@binkert.org      (request.getType() == CacheRequestType_ATOMIC)) {
4296145Snate@binkert.org    m_writeRequestTable_ptr[thread]->deallocate(line_address(request.getAddress()));
4306145Snate@binkert.org  } else {
4316145Snate@binkert.org    m_readRequestTable_ptr[thread]->deallocate(line_address(request.getAddress()));
4326145Snate@binkert.org  }
4336145Snate@binkert.org  m_outstanding_count--;
4346145Snate@binkert.org
4356145Snate@binkert.org  total_outstanding = 0;
4366145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
4376145Snate@binkert.org    total_outstanding += m_writeRequestTable_ptr[p]->size() + m_readRequestTable_ptr[p]->size();
4386145Snate@binkert.org  }
4396145Snate@binkert.org  assert(m_outstanding_count == total_outstanding);
4406145Snate@binkert.org}
4416145Snate@binkert.org
4426145Snate@binkert.orgvoid Sequencer::writeCallback(const Address& address) {
4436145Snate@binkert.org  DataBlock data;
4446145Snate@binkert.org  writeCallback(address, data);
4456145Snate@binkert.org}
4466145Snate@binkert.org
4476145Snate@binkert.orgvoid Sequencer::writeCallback(const Address& address, DataBlock& data) {
4486145Snate@binkert.org  // process oldest thread first
4496145Snate@binkert.org  int thread = -1;
4506145Snate@binkert.org  Time oldest_time = 0;
4516145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
4526145Snate@binkert.org  for(int t=0; t < smt_threads; ++t){
4536145Snate@binkert.org    if(m_writeRequestTable_ptr[t]->exist(address)){
4546145Snate@binkert.org      CacheMsg & request = m_writeRequestTable_ptr[t]->lookup(address);
4556145Snate@binkert.org      if(thread == -1 || (request.getTime() < oldest_time) ){
4566145Snate@binkert.org        thread = t;
4576145Snate@binkert.org        oldest_time = request.getTime();
4586145Snate@binkert.org      }
4596145Snate@binkert.org    }
4606145Snate@binkert.org  }
4616145Snate@binkert.org  // make sure we found an oldest thread
4626145Snate@binkert.org  ASSERT(thread != -1);
4636145Snate@binkert.org
4646145Snate@binkert.org  CacheMsg & request = m_writeRequestTable_ptr[thread]->lookup(address);
4656145Snate@binkert.org
4666145Snate@binkert.org  writeCallback(address, data, GenericMachineType_NULL, PrefetchBit_No, thread);
4676145Snate@binkert.org}
4686145Snate@binkert.org
4696145Snate@binkert.orgvoid Sequencer::writeCallback(const Address& address, DataBlock& data, GenericMachineType respondingMach, PrefetchBit pf, int thread) {
4706145Snate@binkert.org
4716145Snate@binkert.org  assert(address == line_address(address));
4726145Snate@binkert.org  assert(thread >= 0);
4736145Snate@binkert.org  assert(m_writeRequestTable_ptr[thread]->exist(line_address(address)));
4746145Snate@binkert.org
4756145Snate@binkert.org  writeCallback(address, data, respondingMach, thread);
4766145Snate@binkert.org
4776145Snate@binkert.org}
4786145Snate@binkert.org
4796145Snate@binkert.orgvoid Sequencer::writeCallback(const Address& address, DataBlock& data, GenericMachineType respondingMach, int thread) {
4806145Snate@binkert.org  assert(address == line_address(address));
4816145Snate@binkert.org  assert(m_writeRequestTable_ptr[thread]->exist(line_address(address)));
4826145Snate@binkert.org  CacheMsg request = m_writeRequestTable_ptr[thread]->lookup(address);
4836145Snate@binkert.org  assert( request.getThreadID() == thread);
4846145Snate@binkert.org  removeRequest(request);
4856145Snate@binkert.org
4866145Snate@binkert.org  assert((request.getType() == CacheRequestType_ST) ||
4876145Snate@binkert.org         (request.getType() == CacheRequestType_ATOMIC));
4886145Snate@binkert.org
4896145Snate@binkert.org  hitCallback(request, data, respondingMach, thread);
4906145Snate@binkert.org
4916145Snate@binkert.org}
4926145Snate@binkert.org
4936145Snate@binkert.orgvoid Sequencer::readCallback(const Address& address) {
4946145Snate@binkert.org  DataBlock data;
4956145Snate@binkert.org  readCallback(address, data);
4966145Snate@binkert.org}
4976145Snate@binkert.org
4986145Snate@binkert.orgvoid Sequencer::readCallback(const Address& address, DataBlock& data) {
4996145Snate@binkert.org  // process oldest thread first
5006145Snate@binkert.org  int thread = -1;
5016145Snate@binkert.org  Time oldest_time = 0;
5026145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
5036145Snate@binkert.org  for(int t=0; t < smt_threads; ++t){
5046145Snate@binkert.org    if(m_readRequestTable_ptr[t]->exist(address)){
5056145Snate@binkert.org      CacheMsg & request = m_readRequestTable_ptr[t]->lookup(address);
5066145Snate@binkert.org      if(thread == -1 || (request.getTime() < oldest_time) ){
5076145Snate@binkert.org        thread = t;
5086145Snate@binkert.org        oldest_time = request.getTime();
5096145Snate@binkert.org      }
5106145Snate@binkert.org    }
5116145Snate@binkert.org  }
5126145Snate@binkert.org  // make sure we found an oldest thread
5136145Snate@binkert.org  ASSERT(thread != -1);
5146145Snate@binkert.org
5156145Snate@binkert.org  CacheMsg & request = m_readRequestTable_ptr[thread]->lookup(address);
5166145Snate@binkert.org
5176145Snate@binkert.org  readCallback(address, data, GenericMachineType_NULL, PrefetchBit_No, thread);
5186145Snate@binkert.org}
5196145Snate@binkert.org
5206145Snate@binkert.orgvoid Sequencer::readCallback(const Address& address, DataBlock& data, GenericMachineType respondingMach, PrefetchBit pf, int thread) {
5216145Snate@binkert.org
5226145Snate@binkert.org  assert(address == line_address(address));
5236145Snate@binkert.org  assert(m_readRequestTable_ptr[thread]->exist(line_address(address)));
5246145Snate@binkert.org
5256145Snate@binkert.org  readCallback(address, data, respondingMach, thread);
5266145Snate@binkert.org}
5276145Snate@binkert.org
5286145Snate@binkert.orgvoid Sequencer::readCallback(const Address& address, DataBlock& data, GenericMachineType respondingMach, int thread) {
5296145Snate@binkert.org  assert(address == line_address(address));
5306145Snate@binkert.org  assert(m_readRequestTable_ptr[thread]->exist(line_address(address)));
5316145Snate@binkert.org
5326145Snate@binkert.org  CacheMsg request = m_readRequestTable_ptr[thread]->lookup(address);
5336145Snate@binkert.org  assert( request.getThreadID() == thread );
5346145Snate@binkert.org  removeRequest(request);
5356145Snate@binkert.org
5366145Snate@binkert.org  assert((request.getType() == CacheRequestType_LD) ||
5376145Snate@binkert.org         (request.getType() == CacheRequestType_IFETCH)
5386145Snate@binkert.org         );
5396145Snate@binkert.org
5406145Snate@binkert.org  hitCallback(request, data, respondingMach, thread);
5416145Snate@binkert.org}
5426145Snate@binkert.org
5436145Snate@binkert.orgvoid Sequencer::hitCallback(const CacheMsg& request, DataBlock& data, GenericMachineType respondingMach, int thread) {
5446145Snate@binkert.org  int size = request.getSize();
5456145Snate@binkert.org  Address request_address = request.getAddress();
5466145Snate@binkert.org  Address request_logical_address = request.getLogicalAddress();
5476145Snate@binkert.org  Address request_line_address = line_address(request_address);
5486145Snate@binkert.org  CacheRequestType type = request.getType();
5496145Snate@binkert.org  int threadID = request.getThreadID();
5506145Snate@binkert.org  Time issued_time = request.getTime();
5516145Snate@binkert.org  int logical_proc_no = ((m_chip_ptr->getID() * RubyConfig::numberOfProcsPerChip()) + m_version) * RubyConfig::numberofSMTThreads() + threadID;
5526145Snate@binkert.org
5536145Snate@binkert.org  DEBUG_MSG(SEQUENCER_COMP, MedPrio, size);
5546145Snate@binkert.org
5556145Snate@binkert.org  // Set this cache entry to the most recently used
5566145Snate@binkert.org  if (type == CacheRequestType_IFETCH) {
5576145Snate@binkert.org    if (Protocol::m_TwoLevelCache) {
5586145Snate@binkert.org      if (m_chip_ptr->m_L1Cache_L1IcacheMemory_vec[m_version]->isTagPresent(request_line_address)) {
5596145Snate@binkert.org        m_chip_ptr->m_L1Cache_L1IcacheMemory_vec[m_version]->setMRU(request_line_address);
5606145Snate@binkert.org      }
5616145Snate@binkert.org    }
5626145Snate@binkert.org    else {
5636145Snate@binkert.org      if (m_chip_ptr->m_L1Cache_cacheMemory_vec[m_version]->isTagPresent(request_line_address)) {
5646145Snate@binkert.org        m_chip_ptr->m_L1Cache_cacheMemory_vec[m_version]->setMRU(request_line_address);
5656145Snate@binkert.org      }
5666145Snate@binkert.org    }
5676145Snate@binkert.org  } else {
5686145Snate@binkert.org    if (Protocol::m_TwoLevelCache) {
5696145Snate@binkert.org      if (m_chip_ptr->m_L1Cache_L1DcacheMemory_vec[m_version]->isTagPresent(request_line_address)) {
5706145Snate@binkert.org        m_chip_ptr->m_L1Cache_L1DcacheMemory_vec[m_version]->setMRU(request_line_address);
5716145Snate@binkert.org      }
5726145Snate@binkert.org    }
5736145Snate@binkert.org    else {
5746145Snate@binkert.org      if (m_chip_ptr->m_L1Cache_cacheMemory_vec[m_version]->isTagPresent(request_line_address)) {
5756145Snate@binkert.org        m_chip_ptr->m_L1Cache_cacheMemory_vec[m_version]->setMRU(request_line_address);
5766145Snate@binkert.org      }
5776145Snate@binkert.org    }
5786145Snate@binkert.org  }
5796145Snate@binkert.org
5806145Snate@binkert.org  assert(g_eventQueue_ptr->getTime() >= issued_time);
5816145Snate@binkert.org  Time miss_latency = g_eventQueue_ptr->getTime() - issued_time;
5826145Snate@binkert.org
5836145Snate@binkert.org  if (PROTOCOL_DEBUG_TRACE) {
5846145Snate@binkert.org    g_system_ptr->getProfiler()->profileTransition("Seq", (m_chip_ptr->getID()*RubyConfig::numberOfProcsPerChip()+m_version), -1, request.getAddress(), "", "Done", "",
5856145Snate@binkert.org                                                   int_to_string(miss_latency)+" cycles "+GenericMachineType_to_string(respondingMach)+" "+CacheRequestType_to_string(request.getType())+" "+PrefetchBit_to_string(request.getPrefetch()));
5866145Snate@binkert.org  }
5876145Snate@binkert.org
5886145Snate@binkert.org  DEBUG_MSG(SEQUENCER_COMP, MedPrio, request_address);
5896145Snate@binkert.org  DEBUG_MSG(SEQUENCER_COMP, MedPrio, request.getPrefetch());
5906145Snate@binkert.org  if (request.getPrefetch() == PrefetchBit_Yes) {
5916145Snate@binkert.org    DEBUG_MSG(SEQUENCER_COMP, MedPrio, "return");
5926145Snate@binkert.org    g_system_ptr->getProfiler()->swPrefetchLatency(miss_latency, type, respondingMach);
5936145Snate@binkert.org    return; // Ignore the software prefetch, don't callback the driver
5946145Snate@binkert.org  }
5956145Snate@binkert.org
5966145Snate@binkert.org  // Profile the miss latency for all non-zero demand misses
5976145Snate@binkert.org  if (miss_latency != 0) {
5986145Snate@binkert.org    g_system_ptr->getProfiler()->missLatency(miss_latency, type, respondingMach);
5996145Snate@binkert.org
6006151Sdrh5@cs.wisc.edu#if 0
6016151Sdrh5@cs.wisc.edu    uinteger_t tick = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "tick"));
6026151Sdrh5@cs.wisc.edu    uinteger_t tick_cmpr = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "tick_cmpr"));
6036151Sdrh5@cs.wisc.edu    uinteger_t stick = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "stick"));
6046151Sdrh5@cs.wisc.edu    uinteger_t stick_cmpr = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "stick_cmpr"));
6056151Sdrh5@cs.wisc.edu    cout << "END PROC " << m_version << hex << " tick = " << tick << " tick_cmpr = " << tick_cmpr << " stick = " << stick << " stick_cmpr = " << stick_cmpr << " cycle = "<< g_eventQueue_ptr->getTime() << dec << endl;
6066151Sdrh5@cs.wisc.edu#endif
6076145Snate@binkert.org
6086145Snate@binkert.org  }
6096145Snate@binkert.org
6106145Snate@binkert.org  bool write =
6116145Snate@binkert.org    (type == CacheRequestType_ST) ||
6126145Snate@binkert.org    (type == CacheRequestType_ATOMIC);
6136145Snate@binkert.org
6146145Snate@binkert.org  if (TSO && write) {
6156145Snate@binkert.org    m_chip_ptr->m_L1Cache_storeBuffer_vec[m_version]->callBack(line_address(request.getAddress()), data);
6166145Snate@binkert.org  } else {
6176145Snate@binkert.org
6186145Snate@binkert.org    // Copy the correct bytes out of the cache line into the subblock
6196145Snate@binkert.org    SubBlock subblock(request_address, request_logical_address, size);
6206145Snate@binkert.org    subblock.mergeFrom(data);  // copy the correct bytes from DataBlock in the SubBlock
6216145Snate@binkert.org
6226145Snate@binkert.org    // Scan the store buffer to see if there are any outstanding stores we need to collect
6236145Snate@binkert.org    if (TSO) {
6246145Snate@binkert.org      m_chip_ptr->m_L1Cache_storeBuffer_vec[m_version]->updateSubBlock(subblock);
6256145Snate@binkert.org    }
6266145Snate@binkert.org
6276145Snate@binkert.org    // Call into the Driver (Tester or Simics) and let it read and/or modify the sub-block
6286145Snate@binkert.org    g_system_ptr->getDriver()->hitCallback(m_chip_ptr->getID()*RubyConfig::numberOfProcsPerChip()+m_version, subblock, type, threadID);
6296145Snate@binkert.org
6306145Snate@binkert.org    // If the request was a Store or Atomic, apply the changes in the SubBlock to the DataBlock
6316145Snate@binkert.org    // (This is only triggered for the non-TSO case)
6326145Snate@binkert.org    if (write) {
6336145Snate@binkert.org      assert(!TSO);
6346145Snate@binkert.org      subblock.mergeTo(data);    // copy the correct bytes from SubBlock into the DataBlock
6356145Snate@binkert.org    }
6366145Snate@binkert.org  }
6376145Snate@binkert.org}
6386145Snate@binkert.org
6396145Snate@binkert.orgvoid Sequencer::printDebug(){
6406145Snate@binkert.org  //notify driver of debug
6416145Snate@binkert.org  g_system_ptr->getDriver()->printDebug();
6426145Snate@binkert.org}
6436145Snate@binkert.org
6446145Snate@binkert.org// Returns true if the sequencer already has a load or store outstanding
6456151Sdrh5@cs.wisc.edubool
6466151Sdrh5@cs.wisc.eduSequencer::isReady(const Packet* pkt) const
6476151Sdrh5@cs.wisc.edu{
6486145Snate@binkert.org
6496151Sdrh5@cs.wisc.edu  int cpu_number = pkt->req->contextId();
6506151Sdrh5@cs.wisc.edu  la_t logical_addr = pkt->req->getVaddr();
6516151Sdrh5@cs.wisc.edu  pa_t physical_addr = pkt->req->getPaddr();
6526151Sdrh5@cs.wisc.edu  CacheRequestType type_of_request;
6536151Sdrh5@cs.wisc.edu  if ( pkt->req->isInstFetch() ) {
6546151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_IFETCH;
6556151Sdrh5@cs.wisc.edu  } else if ( pkt->req->isLocked() || pkt->req->isSwap() ) {
6566151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_ATOMIC;
6576151Sdrh5@cs.wisc.edu  } else if ( pkt->isRead() ) {
6586151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_LD;
6596151Sdrh5@cs.wisc.edu  } else if ( pkt->isWrite() ) {
6606151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_ST;
6616151Sdrh5@cs.wisc.edu  } else {
6626151Sdrh5@cs.wisc.edu    assert(false);
6636151Sdrh5@cs.wisc.edu  }
6646151Sdrh5@cs.wisc.edu  int thread = pkt->req->threadId();
6656151Sdrh5@cs.wisc.edu
6666151Sdrh5@cs.wisc.edu  CacheMsg request(Address( physical_addr ),
6676151Sdrh5@cs.wisc.edu                   Address( physical_addr ),
6686151Sdrh5@cs.wisc.edu                   type_of_request,
6696151Sdrh5@cs.wisc.edu                   Address(0),
6706151Sdrh5@cs.wisc.edu                   AccessModeType_UserMode,   // User/supervisor mode
6716151Sdrh5@cs.wisc.edu                   0,   // Size in bytes of request
6726151Sdrh5@cs.wisc.edu                   PrefetchBit_No,  // Not a prefetch
6736151Sdrh5@cs.wisc.edu                   0,              // Version number
6746151Sdrh5@cs.wisc.edu                   Address(logical_addr),   // Virtual Address
6756152Sdrh5@cs.wisc.edu                   thread              // SMT thread
6766151Sdrh5@cs.wisc.edu                   );
6776151Sdrh5@cs.wisc.edu  isReady(request);
6786151Sdrh5@cs.wisc.edu}
6796151Sdrh5@cs.wisc.edu
6806151Sdrh5@cs.wisc.edubool
6816151Sdrh5@cs.wisc.eduSequencer::isReady(const CacheMsg& request) const
6826151Sdrh5@cs.wisc.edu{
6836145Snate@binkert.org  if (m_outstanding_count >= g_SEQUENCER_OUTSTANDING_REQUESTS) {
6846145Snate@binkert.org    //cout << "TOO MANY OUTSTANDING: " << m_outstanding_count << " " << g_SEQUENCER_OUTSTANDING_REQUESTS << " VER " << m_version << endl;
6856145Snate@binkert.org    //printProgress(cout);
6866145Snate@binkert.org    return false;
6876145Snate@binkert.org  }
6886145Snate@binkert.org
6896145Snate@binkert.org  // This code allows reads to be performed even when we have a write
6906145Snate@binkert.org  // request outstanding for the line
6916145Snate@binkert.org  bool write =
6926145Snate@binkert.org    (request.getType() == CacheRequestType_ST) ||
6936145Snate@binkert.org    (request.getType() == CacheRequestType_ATOMIC);
6946145Snate@binkert.org
6956145Snate@binkert.org  // LUKE - disallow more than one request type per address
6966145Snate@binkert.org  //     INVARIANT: at most one request type per address, per processor
6976145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
6986145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
6996145Snate@binkert.org    if( m_writeRequestTable_ptr[p]->exist(line_address(request.getAddress())) ||
7006145Snate@binkert.org        m_readRequestTable_ptr[p]->exist(line_address(request.getAddress())) ){
7016145Snate@binkert.org      //cout << "OUTSTANDING REQUEST EXISTS " << p << " VER " << m_version << endl;
7026145Snate@binkert.org      //printProgress(cout);
7036145Snate@binkert.org      return false;
7046145Snate@binkert.org    }
7056145Snate@binkert.org  }
7066145Snate@binkert.org
7076145Snate@binkert.org  if (TSO) {
7086145Snate@binkert.org    return m_chip_ptr->m_L1Cache_storeBuffer_vec[m_version]->isReady();
7096145Snate@binkert.org  }
7106145Snate@binkert.org  return true;
7116145Snate@binkert.org}
7126145Snate@binkert.org
7136145Snate@binkert.org// Called by Driver (Simics or Tester).
7146151Sdrh5@cs.wisc.eduvoid
7156151Sdrh5@cs.wisc.eduSequencer::makeRequest(const Packet* pkt, void* data)
7166151Sdrh5@cs.wisc.edu{
7176151Sdrh5@cs.wisc.edu  int cpu_number = pkt->req->contextId();
7186151Sdrh5@cs.wisc.edu  la_t logical_addr = pkt->req->getVaddr();
7196151Sdrh5@cs.wisc.edu  pa_t physical_addr = pkt->req->getPaddr();
7206151Sdrh5@cs.wisc.edu  int request_size = pkt->getSize();
7216151Sdrh5@cs.wisc.edu  CacheRequestType type_of_request;
7226151Sdrh5@cs.wisc.edu  if ( pkt->req->isInstFetch() ) {
7236151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_IFETCH;
7246151Sdrh5@cs.wisc.edu  } else if ( pkt->req->isLocked() || pkt->req->isSwap() ) {
7256151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_ATOMIC;
7266151Sdrh5@cs.wisc.edu  } else if ( pkt->isRead() ) {
7276151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_LD;
7286151Sdrh5@cs.wisc.edu  } else if ( pkt->isWrite() ) {
7296151Sdrh5@cs.wisc.edu    type_of_request = CacheRequestType_ST;
7306151Sdrh5@cs.wisc.edu  } else {
7316151Sdrh5@cs.wisc.edu    assert(false);
7326151Sdrh5@cs.wisc.edu  }
7336151Sdrh5@cs.wisc.edu  la_t virtual_pc = pkt->req->getPC();
7346151Sdrh5@cs.wisc.edu  int isPriv = false;  // TODO: get permission data
7356151Sdrh5@cs.wisc.edu  int thread = pkt->req->threadId();
7366151Sdrh5@cs.wisc.edu
7376151Sdrh5@cs.wisc.edu  AccessModeType access_mode = AccessModeType_UserMode; // TODO: get actual permission
7386151Sdrh5@cs.wisc.edu
7396151Sdrh5@cs.wisc.edu  CacheMsg request(Address( physical_addr ),
7406151Sdrh5@cs.wisc.edu                   Address( physical_addr ),
7416151Sdrh5@cs.wisc.edu                   type_of_request,
7426151Sdrh5@cs.wisc.edu                   Address(virtual_pc),
7436151Sdrh5@cs.wisc.edu                   access_mode,   // User/supervisor mode
7446151Sdrh5@cs.wisc.edu                   request_size,   // Size in bytes of request
7456151Sdrh5@cs.wisc.edu                   PrefetchBit_No, // Not a prefetch
7466151Sdrh5@cs.wisc.edu                   0,              // Version number
7476151Sdrh5@cs.wisc.edu                   Address(logical_addr),   // Virtual Address
7486152Sdrh5@cs.wisc.edu                   thread         // SMT thread
7496151Sdrh5@cs.wisc.edu                   );
7506151Sdrh5@cs.wisc.edu  makeRequest(request);
7516151Sdrh5@cs.wisc.edu}
7526151Sdrh5@cs.wisc.edu
7536151Sdrh5@cs.wisc.eduvoid
7546151Sdrh5@cs.wisc.eduSequencer::makeRequest(const CacheMsg& request)
7556151Sdrh5@cs.wisc.edu{
7566145Snate@binkert.org  bool write = (request.getType() == CacheRequestType_ST) ||
7576145Snate@binkert.org    (request.getType() == CacheRequestType_ATOMIC);
7586145Snate@binkert.org
7596145Snate@binkert.org  if (TSO && (request.getPrefetch() == PrefetchBit_No) && write) {
7606145Snate@binkert.org    assert(m_chip_ptr->m_L1Cache_storeBuffer_vec[m_version]->isReady());
7616145Snate@binkert.org    m_chip_ptr->m_L1Cache_storeBuffer_vec[m_version]->insertStore(request);
7626145Snate@binkert.org    return;
7636145Snate@binkert.org  }
7646145Snate@binkert.org
7656145Snate@binkert.org  bool hit = doRequest(request);
7666145Snate@binkert.org
7676145Snate@binkert.org}
7686145Snate@binkert.org
7696145Snate@binkert.orgbool Sequencer::doRequest(const CacheMsg& request) {
7706145Snate@binkert.org  bool hit = false;
7716145Snate@binkert.org  // Check the fast path
7726145Snate@binkert.org  DataBlock* data_ptr;
7736145Snate@binkert.org
7746145Snate@binkert.org  int thread = request.getThreadID();
7756145Snate@binkert.org
7766145Snate@binkert.org  hit = tryCacheAccess(line_address(request.getAddress()),
7776145Snate@binkert.org                       request.getType(),
7786145Snate@binkert.org                       request.getProgramCounter(),
7796145Snate@binkert.org                       request.getAccessMode(),
7806145Snate@binkert.org                       request.getSize(),
7816145Snate@binkert.org                       data_ptr);
7826145Snate@binkert.org
7836145Snate@binkert.org  if (hit && (request.getType() == CacheRequestType_IFETCH || !REMOVE_SINGLE_CYCLE_DCACHE_FAST_PATH) ) {
7846145Snate@binkert.org    DEBUG_MSG(SEQUENCER_COMP, MedPrio, "Fast path hit");
7856145Snate@binkert.org    hitCallback(request, *data_ptr, GenericMachineType_L1Cache, thread);
7866145Snate@binkert.org    return true;
7876145Snate@binkert.org  }
7886145Snate@binkert.org
7896151Sdrh5@cs.wisc.edu#if 0
7906145Snate@binkert.org  uinteger_t tick = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "tick"));
7916145Snate@binkert.org  uinteger_t tick_cmpr = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "tick_cmpr"));
7926145Snate@binkert.org  uinteger_t stick = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "stick"));
7936145Snate@binkert.org  uinteger_t stick_cmpr = SIMICS_read_control_register(m_version, SIMICS_get_register_number(m_version, "stick_cmpr"));
7946145Snate@binkert.org  cout << "START PROC " << m_version << hex << " tick = " << tick << " tick_cmpr = " << tick_cmpr << " stick = " << stick << " stick_cmpr = " << stick_cmpr << " cycle = "<< g_eventQueue_ptr->getTime() << dec << endl;;
7956151Sdrh5@cs.wisc.edu#endif
7966145Snate@binkert.org
7976145Snate@binkert.org  if (TSO && (request.getType() == CacheRequestType_LD || request.getType() == CacheRequestType_IFETCH)) {
7986145Snate@binkert.org
7996145Snate@binkert.org    // See if we can satisfy the load entirely from the store buffer
8006145Snate@binkert.org    SubBlock subblock(line_address(request.getAddress()), request.getSize());
8016145Snate@binkert.org    if (m_chip_ptr->m_L1Cache_storeBuffer_vec[m_version]->trySubBlock(subblock)) {
8026145Snate@binkert.org      DataBlock dummy;
8036145Snate@binkert.org      hitCallback(request, dummy, GenericMachineType_NULL, thread);  // Call with an 'empty' datablock, since the data is in the store buffer
8046145Snate@binkert.org      return true;
8056145Snate@binkert.org    }
8066145Snate@binkert.org  }
8076145Snate@binkert.org
8086145Snate@binkert.org  DEBUG_MSG(SEQUENCER_COMP, MedPrio, "Fast path miss");
8096145Snate@binkert.org  issueRequest(request);
8106145Snate@binkert.org  return hit;
8116145Snate@binkert.org}
8126145Snate@binkert.org
8136145Snate@binkert.orgvoid Sequencer::issueRequest(const CacheMsg& request) {
8146145Snate@binkert.org  bool found = insertRequest(request);
8156145Snate@binkert.org
8166145Snate@binkert.org  if (!found) {
8176145Snate@binkert.org    CacheMsg msg = request;
8186145Snate@binkert.org    msg.getAddress() = line_address(request.getAddress()); // Make line address
8196145Snate@binkert.org
8206145Snate@binkert.org    // Fast Path L1 misses are profiled here - all non-fast path misses are profiled within the generated protocol code
8216145Snate@binkert.org    if (!REMOVE_SINGLE_CYCLE_DCACHE_FAST_PATH) {
8226145Snate@binkert.org      g_system_ptr->getProfiler()->addPrimaryStatSample(msg, m_chip_ptr->getID());
8236145Snate@binkert.org    }
8246145Snate@binkert.org
8256145Snate@binkert.org    if (PROTOCOL_DEBUG_TRACE) {
8266145Snate@binkert.org      g_system_ptr->getProfiler()->profileTransition("Seq", (m_chip_ptr->getID()*RubyConfig::numberOfProcsPerChip() + m_version), -1, msg.getAddress(),"", "Begin", "", CacheRequestType_to_string(request.getType()));
8276145Snate@binkert.org    }
8286145Snate@binkert.org
8296145Snate@binkert.org#if 0
8306145Snate@binkert.org    // Commented out by nate binkert because I removed the trace stuff
8316145Snate@binkert.org    if (g_system_ptr->getTracer()->traceEnabled()) {
8326145Snate@binkert.org      g_system_ptr->getTracer()->traceRequest((m_chip_ptr->getID()*RubyConfig::numberOfProcsPerChip()+m_version), msg.getAddress(), msg.getProgramCounter(),
8336145Snate@binkert.org                                              msg.getType(), g_eventQueue_ptr->getTime());
8346145Snate@binkert.org    }
8356145Snate@binkert.org#endif
8366145Snate@binkert.org
8376145Snate@binkert.org    Time latency = 0;  // initialzed to an null value
8386145Snate@binkert.org
8396145Snate@binkert.org    latency = SEQUENCER_TO_CONTROLLER_LATENCY;
8406145Snate@binkert.org
8416145Snate@binkert.org    // Send the message to the cache controller
8426145Snate@binkert.org    assert(latency > 0);
8436145Snate@binkert.org    m_chip_ptr->m_L1Cache_mandatoryQueue_vec[m_version]->enqueue(msg, latency);
8446145Snate@binkert.org
8456145Snate@binkert.org  }  // !found
8466145Snate@binkert.org}
8476145Snate@binkert.org
8486145Snate@binkert.orgbool Sequencer::tryCacheAccess(const Address& addr, CacheRequestType type,
8496145Snate@binkert.org                               const Address& pc, AccessModeType access_mode,
8506145Snate@binkert.org                               int size, DataBlock*& data_ptr) {
8516145Snate@binkert.org  if (type == CacheRequestType_IFETCH) {
8526145Snate@binkert.org    if (Protocol::m_TwoLevelCache) {
8536145Snate@binkert.org      return m_chip_ptr->m_L1Cache_L1IcacheMemory_vec[m_version]->tryCacheAccess(line_address(addr), type, data_ptr);
8546145Snate@binkert.org    }
8556145Snate@binkert.org    else {
8566145Snate@binkert.org      return m_chip_ptr->m_L1Cache_cacheMemory_vec[m_version]->tryCacheAccess(line_address(addr), type, data_ptr);
8576145Snate@binkert.org    }
8586145Snate@binkert.org  } else {
8596145Snate@binkert.org    if (Protocol::m_TwoLevelCache) {
8606145Snate@binkert.org      return m_chip_ptr->m_L1Cache_L1DcacheMemory_vec[m_version]->tryCacheAccess(line_address(addr), type, data_ptr);
8616145Snate@binkert.org    }
8626145Snate@binkert.org    else {
8636145Snate@binkert.org      return m_chip_ptr->m_L1Cache_cacheMemory_vec[m_version]->tryCacheAccess(line_address(addr), type, data_ptr);
8646145Snate@binkert.org    }
8656145Snate@binkert.org  }
8666145Snate@binkert.org}
8676145Snate@binkert.org
8686145Snate@binkert.orgvoid Sequencer::resetRequestTime(const Address& addr, int thread){
8696145Snate@binkert.org  assert(thread >= 0);
8706145Snate@binkert.org  //reset both load and store requests, if they exist
8716145Snate@binkert.org  if(m_readRequestTable_ptr[thread]->exist(line_address(addr))){
8726145Snate@binkert.org    CacheMsg& request = m_readRequestTable_ptr[thread]->lookup(addr);
8736145Snate@binkert.org    if( request.m_AccessMode != AccessModeType_UserMode){
8746145Snate@binkert.org      cout << "resetRequestType ERROR read request addr = " << addr << " thread = "<< thread << " is SUPERVISOR MODE" << endl;
8756145Snate@binkert.org      printProgress(cout);
8766145Snate@binkert.org    }
8776145Snate@binkert.org    //ASSERT(request.m_AccessMode == AccessModeType_UserMode);
8786145Snate@binkert.org    request.setTime(g_eventQueue_ptr->getTime());
8796145Snate@binkert.org  }
8806145Snate@binkert.org  if(m_writeRequestTable_ptr[thread]->exist(line_address(addr))){
8816145Snate@binkert.org    CacheMsg& request = m_writeRequestTable_ptr[thread]->lookup(addr);
8826145Snate@binkert.org    if( request.m_AccessMode != AccessModeType_UserMode){
8836145Snate@binkert.org      cout << "resetRequestType ERROR write request addr = " << addr << " thread = "<< thread << " is SUPERVISOR MODE" << endl;
8846145Snate@binkert.org      printProgress(cout);
8856145Snate@binkert.org    }
8866145Snate@binkert.org    //ASSERT(request.m_AccessMode == AccessModeType_UserMode);
8876145Snate@binkert.org    request.setTime(g_eventQueue_ptr->getTime());
8886145Snate@binkert.org  }
8896145Snate@binkert.org}
8906145Snate@binkert.org
8916145Snate@binkert.org// removes load request from queue
8926145Snate@binkert.orgvoid Sequencer::removeLoadRequest(const Address & addr, int thread){
8936145Snate@binkert.org  removeRequest(getReadRequest(addr, thread));
8946145Snate@binkert.org}
8956145Snate@binkert.org
8966145Snate@binkert.orgvoid Sequencer::removeStoreRequest(const Address & addr, int thread){
8976145Snate@binkert.org  removeRequest(getWriteRequest(addr, thread));
8986145Snate@binkert.org}
8996145Snate@binkert.org
9006145Snate@binkert.org// returns the read CacheMsg
9016145Snate@binkert.orgCacheMsg & Sequencer::getReadRequest( const Address & addr, int thread ){
9026145Snate@binkert.org  Address temp = addr;
9036145Snate@binkert.org  assert(thread >= 0);
9046145Snate@binkert.org  assert(temp == line_address(temp));
9056145Snate@binkert.org  assert(m_readRequestTable_ptr[thread]->exist(addr));
9066145Snate@binkert.org  return m_readRequestTable_ptr[thread]->lookup(addr);
9076145Snate@binkert.org}
9086145Snate@binkert.org
9096145Snate@binkert.orgCacheMsg & Sequencer::getWriteRequest( const Address & addr, int thread){
9106145Snate@binkert.org  Address temp = addr;
9116145Snate@binkert.org  assert(thread >= 0);
9126145Snate@binkert.org  assert(temp == line_address(temp));
9136145Snate@binkert.org  assert(m_writeRequestTable_ptr[thread]->exist(addr));
9146145Snate@binkert.org  return m_writeRequestTable_ptr[thread]->lookup(addr);
9156145Snate@binkert.org}
9166145Snate@binkert.org
9176145Snate@binkert.orgvoid Sequencer::print(ostream& out) const {
9186145Snate@binkert.org  out << "[Sequencer: " << m_chip_ptr->getID()
9196145Snate@binkert.org      << ", outstanding requests: " << m_outstanding_count;
9206145Snate@binkert.org
9216145Snate@binkert.org  int smt_threads = RubyConfig::numberofSMTThreads();
9226145Snate@binkert.org  for(int p=0; p < smt_threads; ++p){
9236145Snate@binkert.org    out << ", read request table[ " << p << " ]: " << *m_readRequestTable_ptr[p]
9246145Snate@binkert.org        << ", write request table[ " << p << " ]: " << *m_writeRequestTable_ptr[p];
9256145Snate@binkert.org  }
9266145Snate@binkert.org  out << "]";
9276145Snate@binkert.org}
9286145Snate@binkert.org
9296145Snate@binkert.org// this can be called from setState whenever coherence permissions are upgraded
9306145Snate@binkert.org// when invoked, coherence violations will be checked for the given block
9316145Snate@binkert.orgvoid Sequencer::checkCoherence(const Address& addr) {
9326145Snate@binkert.org#ifdef CHECK_COHERENCE
9336145Snate@binkert.org  g_system_ptr->checkGlobalCoherenceInvariant(addr);
9346145Snate@binkert.org#endif
9356145Snate@binkert.org}
9366145Snate@binkert.org
9376145Snate@binkert.orgbool Sequencer::getRubyMemoryValue(const Address& addr, char* value,
9386145Snate@binkert.org                                   unsigned int size_in_bytes ) {
9396145Snate@binkert.org  if(g_SIMICS){
9406145Snate@binkert.org    for(unsigned int i=0; i < size_in_bytes; i++) {
9416145Snate@binkert.org      value[i] = SIMICS_read_physical_memory( m_chip_ptr->getID()*RubyConfig::numberOfProcsPerChip()+m_version,
9426145Snate@binkert.org                                              addr.getAddress() + i, 1 );
9436145Snate@binkert.org    }
9446145Snate@binkert.org    return false; // Do nothing?
9456145Snate@binkert.org  } else {
9466145Snate@binkert.org    bool found = false;
9476145Snate@binkert.org    const Address lineAddr = line_address(addr);
9486145Snate@binkert.org    DataBlock data;
9496145Snate@binkert.org    PhysAddress paddr(addr);
9506145Snate@binkert.org    DataBlock* dataPtr = &data;
9516145Snate@binkert.org    Chip* n = dynamic_cast<Chip*>(m_chip_ptr);
9526145Snate@binkert.org    // LUKE - use variable names instead of macros
9536145Snate@binkert.org    assert(n->m_L1Cache_L1IcacheMemory_vec[m_version] != NULL);
9546145Snate@binkert.org    assert(n->m_L1Cache_L1DcacheMemory_vec[m_version] != NULL);
9556145Snate@binkert.org
9566145Snate@binkert.org    MachineID l2_mach = map_L2ChipId_to_L2Cache(addr, m_chip_ptr->getID() );
9576145Snate@binkert.org    int l2_ver = l2_mach.num%RubyConfig::numberOfL2CachePerChip();
9586145Snate@binkert.org
9596145Snate@binkert.org    if (Protocol::m_TwoLevelCache) {
9606145Snate@binkert.org      if(Protocol::m_CMP){
9616145Snate@binkert.org        assert(n->m_L2Cache_L2cacheMemory_vec[l2_ver] != NULL);
9626145Snate@binkert.org      }
9636145Snate@binkert.org      else{
9646145Snate@binkert.org        assert(n->m_L1Cache_cacheMemory_vec[m_version] != NULL);
9656145Snate@binkert.org      }
9666145Snate@binkert.org    }
9676145Snate@binkert.org
9686145Snate@binkert.org    if (n->m_L1Cache_L1IcacheMemory_vec[m_version]->tryCacheAccess(lineAddr, CacheRequestType_IFETCH, dataPtr)){
9696145Snate@binkert.org      n->m_L1Cache_L1IcacheMemory_vec[m_version]->getMemoryValue(addr, value, size_in_bytes);
9706145Snate@binkert.org      found = true;
9716145Snate@binkert.org    } else if (n->m_L1Cache_L1DcacheMemory_vec[m_version]->tryCacheAccess(lineAddr, CacheRequestType_LD, dataPtr)){
9726145Snate@binkert.org      n->m_L1Cache_L1DcacheMemory_vec[m_version]->getMemoryValue(addr, value, size_in_bytes);
9736145Snate@binkert.org      found = true;
9746145Snate@binkert.org    } else if (Protocol::m_CMP && n->m_L2Cache_L2cacheMemory_vec[l2_ver]->tryCacheAccess(lineAddr, CacheRequestType_LD, dataPtr)){
9756145Snate@binkert.org      n->m_L2Cache_L2cacheMemory_vec[l2_ver]->getMemoryValue(addr, value, size_in_bytes);
9766145Snate@binkert.org      found = true;
9776151Sdrh5@cs.wisc.edu      // } else if (n->TBE_TABLE_MEMBER_VARIABLE->isPresent(lineAddr)){
9786151Sdrh5@cs.wisc.edu      //       ASSERT(n->TBE_TABLE_MEMBER_VARIABLE->isPresent(lineAddr));
9796151Sdrh5@cs.wisc.edu      //       L1Cache_TBE tbeEntry = n->TBE_TABLE_MEMBER_VARIABLE->lookup(lineAddr);
9806145Snate@binkert.org
9816151Sdrh5@cs.wisc.edu      //       int offset = addr.getOffset();
9826151Sdrh5@cs.wisc.edu      //       for(int i=0; i<size_in_bytes; ++i){
9836151Sdrh5@cs.wisc.edu      //         value[i] = tbeEntry.getDataBlk().getByte(offset + i);
9846151Sdrh5@cs.wisc.edu      //       }
9856145Snate@binkert.org
9866151Sdrh5@cs.wisc.edu      //       found = true;
9876145Snate@binkert.org    } else {
9886145Snate@binkert.org      // Address not found
9896145Snate@binkert.org      //cout << "  " << m_chip_ptr->getID() << " NOT IN CACHE, Value at Directory is: " << (int) value[0] << endl;
9906145Snate@binkert.org      n = dynamic_cast<Chip*>(g_system_ptr->getChip(map_Address_to_DirectoryNode(addr)/RubyConfig::numberOfDirectoryPerChip()));
9916145Snate@binkert.org      int dir_version = map_Address_to_DirectoryNode(addr)%RubyConfig::numberOfDirectoryPerChip();
9926145Snate@binkert.org      for(unsigned int i=0; i<size_in_bytes; ++i){
9936145Snate@binkert.org        int offset = addr.getOffset();
9946145Snate@binkert.org        value[i] = n->m_Directory_directory_vec[dir_version]->lookup(lineAddr).m_DataBlk.getByte(offset + i);
9956145Snate@binkert.org      }
9966145Snate@binkert.org      // Address not found
9976145Snate@binkert.org      //WARN_MSG("Couldn't find address");
9986145Snate@binkert.org      //WARN_EXPR(addr);
9996145Snate@binkert.org      found = false;
10006145Snate@binkert.org    }
10016145Snate@binkert.org    return true;
10026145Snate@binkert.org  }
10036145Snate@binkert.org}
10046145Snate@binkert.org
10056145Snate@binkert.orgbool Sequencer::setRubyMemoryValue(const Address& addr, char *value,
10066145Snate@binkert.org                                   unsigned int size_in_bytes) {
10076145Snate@binkert.org  char test_buffer[64];
10086145Snate@binkert.org
10096145Snate@binkert.org  if(g_SIMICS){
10106145Snate@binkert.org    return false; // Do nothing?
10116145Snate@binkert.org  } else {
10126145Snate@binkert.org    // idea here is that coherent cache should find the
10136145Snate@binkert.org    // latest data, the update it
10146145Snate@binkert.org    bool found = false;
10156145Snate@binkert.org    const Address lineAddr = line_address(addr);
10166145Snate@binkert.org    PhysAddress paddr(addr);
10176145Snate@binkert.org    DataBlock data;
10186145Snate@binkert.org    DataBlock* dataPtr = &data;
10196145Snate@binkert.org    Chip* n = dynamic_cast<Chip*>(m_chip_ptr);
10206145Snate@binkert.org
10216145Snate@binkert.org    MachineID l2_mach = map_L2ChipId_to_L2Cache(addr, m_chip_ptr->getID() );
10226145Snate@binkert.org    int l2_ver = l2_mach.num%RubyConfig::numberOfL2CachePerChip();
10236145Snate@binkert.org    // LUKE - use variable names instead of macros
10246145Snate@binkert.org    //cout << "number of L2caches per chip = " << RubyConfig::numberOfL2CachePerChip(m_version) << endl;
10256145Snate@binkert.org    //cout << "L1I cache vec size = " << n->m_L1Cache_L1IcacheMemory_vec.size() << endl;
10266145Snate@binkert.org    //cout << "L1D cache vec size = " << n->m_L1Cache_L1DcacheMemory_vec.size() << endl;
10276145Snate@binkert.org    //cout << "L1cache_cachememory size = " << n->m_L1Cache_cacheMemory_vec.size() << endl;
10286145Snate@binkert.org    //cout << "L1cache_l2cachememory size = " << n->m_L1Cache_L2cacheMemory_vec.size() << endl;
10296145Snate@binkert.org    // if (Protocol::m_TwoLevelCache) {
10306151Sdrh5@cs.wisc.edu    //       if(Protocol::m_CMP){
10316151Sdrh5@cs.wisc.edu    //         cout << "CMP L2 cache vec size = " << n->m_L2Cache_L2cacheMemory_vec.size() << endl;
10326151Sdrh5@cs.wisc.edu    //       }
10336151Sdrh5@cs.wisc.edu    //       else{
10346151Sdrh5@cs.wisc.edu    //        cout << "L2 cache vec size = " << n->m_L1Cache_cacheMemory_vec.size() << endl;
10356151Sdrh5@cs.wisc.edu    //       }
10366151Sdrh5@cs.wisc.edu    //     }
10376145Snate@binkert.org
10386145Snate@binkert.org    assert(n->m_L1Cache_L1IcacheMemory_vec[m_version] != NULL);
10396145Snate@binkert.org    assert(n->m_L1Cache_L1DcacheMemory_vec[m_version] != NULL);
10406145Snate@binkert.org    if (Protocol::m_TwoLevelCache) {
10416145Snate@binkert.org      if(Protocol::m_CMP){
10426145Snate@binkert.org        assert(n->m_L2Cache_L2cacheMemory_vec[l2_ver] != NULL);
10436145Snate@binkert.org      }
10446145Snate@binkert.org      else{
10456145Snate@binkert.org        assert(n->m_L1Cache_cacheMemory_vec[m_version] != NULL);
10466145Snate@binkert.org      }
10476145Snate@binkert.org    }
10486145Snate@binkert.org
10496145Snate@binkert.org    if (n->m_L1Cache_L1IcacheMemory_vec[m_version]->tryCacheAccess(lineAddr, CacheRequestType_IFETCH, dataPtr)){
10506145Snate@binkert.org      n->m_L1Cache_L1IcacheMemory_vec[m_version]->setMemoryValue(addr, value, size_in_bytes);
10516145Snate@binkert.org      found = true;
10526145Snate@binkert.org    } else if (n->m_L1Cache_L1DcacheMemory_vec[m_version]->tryCacheAccess(lineAddr, CacheRequestType_LD, dataPtr)){
10536145Snate@binkert.org      n->m_L1Cache_L1DcacheMemory_vec[m_version]->setMemoryValue(addr, value, size_in_bytes);
10546145Snate@binkert.org      found = true;
10556145Snate@binkert.org    } else if (Protocol::m_CMP && n->m_L2Cache_L2cacheMemory_vec[l2_ver]->tryCacheAccess(lineAddr, CacheRequestType_LD, dataPtr)){
10566145Snate@binkert.org      n->m_L2Cache_L2cacheMemory_vec[l2_ver]->setMemoryValue(addr, value, size_in_bytes);
10576145Snate@binkert.org      found = true;
10586151Sdrh5@cs.wisc.edu      // } else if (n->TBE_TABLE_MEMBER_VARIABLE->isTagPresent(lineAddr)){
10596151Sdrh5@cs.wisc.edu      //       L1Cache_TBE& tbeEntry = n->TBE_TABLE_MEMBER_VARIABLE->lookup(lineAddr);
10606151Sdrh5@cs.wisc.edu      //       DataBlock tmpData;
10616151Sdrh5@cs.wisc.edu      //       int offset = addr.getOffset();
10626151Sdrh5@cs.wisc.edu      //       for(int i=0; i<size_in_bytes; ++i){
10636151Sdrh5@cs.wisc.edu      //         tmpData.setByte(offset + i, value[i]);
10646151Sdrh5@cs.wisc.edu      //       }
10656151Sdrh5@cs.wisc.edu      //       tbeEntry.setDataBlk(tmpData);
10666151Sdrh5@cs.wisc.edu      //       tbeEntry.setDirty(true);
10676145Snate@binkert.org    } else {
10686145Snate@binkert.org      // Address not found
10696145Snate@binkert.org      n = dynamic_cast<Chip*>(g_system_ptr->getChip(map_Address_to_DirectoryNode(addr)/RubyConfig::numberOfDirectoryPerChip()));
10706145Snate@binkert.org      int dir_version = map_Address_to_DirectoryNode(addr)%RubyConfig::numberOfDirectoryPerChip();
10716145Snate@binkert.org      for(unsigned int i=0; i<size_in_bytes; ++i){
10726145Snate@binkert.org        int offset = addr.getOffset();
10736145Snate@binkert.org        n->m_Directory_directory_vec[dir_version]->lookup(lineAddr).m_DataBlk.setByte(offset + i, value[i]);
10746145Snate@binkert.org      }
10756145Snate@binkert.org      found = false;
10766145Snate@binkert.org    }
10776145Snate@binkert.org
10786145Snate@binkert.org    if (found){
10796145Snate@binkert.org      found = getRubyMemoryValue(addr, test_buffer, size_in_bytes);
10806145Snate@binkert.org      assert(found);
10816145Snate@binkert.org      if(value[0] != test_buffer[0]){
10826145Snate@binkert.org        WARN_EXPR((int) value[0]);
10836145Snate@binkert.org        WARN_EXPR((int) test_buffer[0]);
10846145Snate@binkert.org        ERROR_MSG("setRubyMemoryValue failed to set value.");
10856145Snate@binkert.org      }
10866145Snate@binkert.org    }
10876145Snate@binkert.org
10886145Snate@binkert.org    return true;
10896145Snate@binkert.org  }
10906145Snate@binkert.org}
1091