Sequencer.cc revision 7546
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297056Snate@binkert.org#include "base/str.hh" 307039Snate@binkert.org#include "cpu/rubytest/RubyTester.hh" 317039Snate@binkert.org#include "mem/protocol/CacheMsg.hh" 327039Snate@binkert.org#include "mem/protocol/Protocol.hh" 337039Snate@binkert.org#include "mem/protocol/Protocol.hh" 347039Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh" 357039Snate@binkert.org#include "mem/ruby/common/Global.hh" 367039Snate@binkert.org#include "mem/ruby/common/SubBlock.hh" 376845Sdrh5@cs.wisc.edu#include "mem/ruby/libruby.hh" 387039Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 397039Snate@binkert.org#include "mem/ruby/recorder/Tracer.hh" 407039Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 417039Snate@binkert.org#include "mem/ruby/system/CacheMemory.hh" 426154Snate@binkert.org#include "mem/ruby/system/Sequencer.hh" 436154Snate@binkert.org#include "mem/ruby/system/System.hh" 446876Ssteve.reinhardt@amd.com#include "params/RubySequencer.hh" 456876Ssteve.reinhardt@amd.com 467055Snate@binkert.orgusing namespace std; 477055Snate@binkert.org 486876Ssteve.reinhardt@amd.comSequencer * 496876Ssteve.reinhardt@amd.comRubySequencerParams::create() 506285Snate@binkert.org{ 516876Ssteve.reinhardt@amd.com return new Sequencer(this); 526285Snate@binkert.org} 537039Snate@binkert.org 546876Ssteve.reinhardt@amd.comSequencer::Sequencer(const Params *p) 556886SBrad.Beckmann@amd.com : RubyPort(p), deadlockCheckEvent(this) 566876Ssteve.reinhardt@amd.com{ 576876Ssteve.reinhardt@amd.com m_store_waiting_on_load_cycles = 0; 586876Ssteve.reinhardt@amd.com m_store_waiting_on_store_cycles = 0; 596876Ssteve.reinhardt@amd.com m_load_waiting_on_store_cycles = 0; 606876Ssteve.reinhardt@amd.com m_load_waiting_on_load_cycles = 0; 617039Snate@binkert.org 626876Ssteve.reinhardt@amd.com m_outstanding_count = 0; 636285Snate@binkert.org 646876Ssteve.reinhardt@amd.com m_max_outstanding_requests = 0; 656876Ssteve.reinhardt@amd.com m_deadlock_threshold = 0; 666876Ssteve.reinhardt@amd.com m_instCache_ptr = NULL; 676876Ssteve.reinhardt@amd.com m_dataCache_ptr = NULL; 686145Snate@binkert.org 696876Ssteve.reinhardt@amd.com m_instCache_ptr = p->icache; 706876Ssteve.reinhardt@amd.com m_dataCache_ptr = p->dcache; 716876Ssteve.reinhardt@amd.com m_max_outstanding_requests = p->max_outstanding_requests; 726876Ssteve.reinhardt@amd.com m_deadlock_threshold = p->deadlock_threshold; 736899SBrad.Beckmann@amd.com m_usingRubyTester = p->using_ruby_tester; 746899SBrad.Beckmann@amd.com 756876Ssteve.reinhardt@amd.com assert(m_max_outstanding_requests > 0); 766876Ssteve.reinhardt@amd.com assert(m_deadlock_threshold > 0); 776876Ssteve.reinhardt@amd.com assert(m_instCache_ptr != NULL); 786876Ssteve.reinhardt@amd.com assert(m_dataCache_ptr != NULL); 796145Snate@binkert.org} 806145Snate@binkert.org 817039Snate@binkert.orgSequencer::~Sequencer() 827039Snate@binkert.org{ 836145Snate@binkert.org} 846145Snate@binkert.org 857039Snate@binkert.orgvoid 867039Snate@binkert.orgSequencer::wakeup() 877039Snate@binkert.org{ 887039Snate@binkert.org // Check for deadlock of any of the requests 897039Snate@binkert.org Time current_time = g_eventQueue_ptr->getTime(); 906145Snate@binkert.org 917039Snate@binkert.org // Check across all outstanding requests 927039Snate@binkert.org int total_outstanding = 0; 936285Snate@binkert.org 947455Snate@binkert.org RequestTable::iterator read = m_readRequestTable.begin(); 957455Snate@binkert.org RequestTable::iterator read_end = m_readRequestTable.end(); 967455Snate@binkert.org for (; read != read_end; ++read) { 977455Snate@binkert.org SequencerRequest* request = read->second; 987455Snate@binkert.org if (current_time - request->issue_time < m_deadlock_threshold) 997455Snate@binkert.org continue; 1007455Snate@binkert.org 1017455Snate@binkert.org WARN_MSG("Possible Deadlock detected"); 1027455Snate@binkert.org WARN_EXPR(m_version); 1037455Snate@binkert.org WARN_EXPR(request->ruby_request.paddr); 1047455Snate@binkert.org WARN_EXPR(m_readRequestTable.size()); 1057455Snate@binkert.org WARN_EXPR(current_time); 1067455Snate@binkert.org WARN_EXPR(request->issue_time); 1077455Snate@binkert.org WARN_EXPR(current_time - request->issue_time); 1087455Snate@binkert.org ERROR_MSG("Aborting"); 1096145Snate@binkert.org } 1106145Snate@binkert.org 1117455Snate@binkert.org RequestTable::iterator write = m_writeRequestTable.begin(); 1127455Snate@binkert.org RequestTable::iterator write_end = m_writeRequestTable.end(); 1137455Snate@binkert.org for (; write != write_end; ++write) { 1147455Snate@binkert.org SequencerRequest* request = write->second; 1157455Snate@binkert.org if (current_time - request->issue_time < m_deadlock_threshold) 1167455Snate@binkert.org continue; 1177455Snate@binkert.org 1187455Snate@binkert.org WARN_MSG("Possible Deadlock detected"); 1197455Snate@binkert.org WARN_EXPR(m_version); 1207537SBrad.Beckmann@amd.com WARN_EXPR(request->ruby_request.paddr); 1217455Snate@binkert.org WARN_EXPR(current_time); 1227455Snate@binkert.org WARN_EXPR(request->issue_time); 1237455Snate@binkert.org WARN_EXPR(current_time - request->issue_time); 1247455Snate@binkert.org WARN_EXPR(m_writeRequestTable.size()); 1257455Snate@binkert.org ERROR_MSG("Aborting"); 1266145Snate@binkert.org } 1276285Snate@binkert.org 1287039Snate@binkert.org total_outstanding += m_writeRequestTable.size(); 1297039Snate@binkert.org total_outstanding += m_readRequestTable.size(); 1306145Snate@binkert.org 1317039Snate@binkert.org assert(m_outstanding_count == total_outstanding); 1327039Snate@binkert.org 1337039Snate@binkert.org if (m_outstanding_count > 0) { 1347039Snate@binkert.org // If there are still outstanding requests, keep checking 1357039Snate@binkert.org schedule(deadlockCheckEvent, 1367039Snate@binkert.org m_deadlock_threshold * g_eventQueue_ptr->getClock() + 1377039Snate@binkert.org curTick); 1387039Snate@binkert.org } 1396145Snate@binkert.org} 1406145Snate@binkert.org 1417039Snate@binkert.orgvoid 1427039Snate@binkert.orgSequencer::printStats(ostream & out) const 1437039Snate@binkert.org{ 1447039Snate@binkert.org out << "Sequencer: " << m_name << endl 1457039Snate@binkert.org << " store_waiting_on_load_cycles: " 1467039Snate@binkert.org << m_store_waiting_on_load_cycles << endl 1477039Snate@binkert.org << " store_waiting_on_store_cycles: " 1487039Snate@binkert.org << m_store_waiting_on_store_cycles << endl 1497039Snate@binkert.org << " load_waiting_on_load_cycles: " 1507039Snate@binkert.org << m_load_waiting_on_load_cycles << endl 1517039Snate@binkert.org << " load_waiting_on_store_cycles: " 1527039Snate@binkert.org << m_load_waiting_on_store_cycles << endl; 1536859Sdrh5@cs.wisc.edu} 1546859Sdrh5@cs.wisc.edu 1557039Snate@binkert.orgvoid 1567039Snate@binkert.orgSequencer::printProgress(ostream& out) const 1577039Snate@binkert.org{ 1587039Snate@binkert.org#if 0 1597039Snate@binkert.org int total_demand = 0; 1607039Snate@binkert.org out << "Sequencer Stats Version " << m_version << endl; 1617039Snate@binkert.org out << "Current time = " << g_eventQueue_ptr->getTime() << endl; 1627039Snate@binkert.org out << "---------------" << endl; 1637039Snate@binkert.org out << "outstanding requests" << endl; 1646145Snate@binkert.org 1657455Snate@binkert.org out << "proc " << m_Read 1667455Snate@binkert.org << " version Requests = " << m_readRequestTable.size() << endl; 1676145Snate@binkert.org 1687039Snate@binkert.org // print the request table 1697455Snate@binkert.org RequestTable::iterator read = m_readRequestTable.begin(); 1707455Snate@binkert.org RequestTable::iterator read_end = m_readRequestTable.end(); 1717455Snate@binkert.org for (; read != read_end; ++read) { 1727455Snate@binkert.org SequencerRequest* request = read->second; 1737039Snate@binkert.org out << "\tRequest[ " << i << " ] = " << request->type 1747039Snate@binkert.org << " Address " << rkeys[i] 1757039Snate@binkert.org << " Posted " << request->issue_time 1767039Snate@binkert.org << " PF " << PrefetchBit_No << endl; 1776145Snate@binkert.org total_demand++; 1787039Snate@binkert.org } 1796145Snate@binkert.org 1807455Snate@binkert.org out << "proc " << m_version 1817455Snate@binkert.org << " Write Requests = " << m_writeRequestTable.size << endl; 1826285Snate@binkert.org 1837039Snate@binkert.org // print the request table 1847455Snate@binkert.org RequestTable::iterator write = m_writeRequestTable.begin(); 1857455Snate@binkert.org RequestTable::iterator write_end = m_writeRequestTable.end(); 1867455Snate@binkert.org for (; write != write_end; ++write) { 1877455Snate@binkert.org SequencerRequest* request = write->second; 1887039Snate@binkert.org out << "\tRequest[ " << i << " ] = " << request.getType() 1897039Snate@binkert.org << " Address " << wkeys[i] 1907039Snate@binkert.org << " Posted " << request.getTime() 1917039Snate@binkert.org << " PF " << request.getPrefetch() << endl; 1927039Snate@binkert.org if (request.getPrefetch() == PrefetchBit_No) { 1937039Snate@binkert.org total_demand++; 1947039Snate@binkert.org } 1957039Snate@binkert.org } 1967039Snate@binkert.org 1977039Snate@binkert.org out << endl; 1987039Snate@binkert.org 1997039Snate@binkert.org out << "Total Number Outstanding: " << m_outstanding_count << endl 2007039Snate@binkert.org << "Total Number Demand : " << total_demand << endl 2017039Snate@binkert.org << "Total Number Prefetches : " << m_outstanding_count - total_demand 2027039Snate@binkert.org << endl << endl << endl; 2037039Snate@binkert.org#endif 2046145Snate@binkert.org} 2056145Snate@binkert.org 2067039Snate@binkert.orgvoid 2077039Snate@binkert.orgSequencer::printConfig(ostream& out) const 2087039Snate@binkert.org{ 2097039Snate@binkert.org out << "Seqeuncer config: " << m_name << endl 2107039Snate@binkert.org << " controller: " << m_controller->getName() << endl 2117039Snate@binkert.org << " version: " << m_version << endl 2127039Snate@binkert.org << " max_outstanding_requests: " << m_max_outstanding_requests << endl 2137039Snate@binkert.org << " deadlock_threshold: " << m_deadlock_threshold << endl; 2146145Snate@binkert.org} 2156145Snate@binkert.org 2166145Snate@binkert.org// Insert the request on the correct request table. Return true if 2176145Snate@binkert.org// the entry was already present. 2187039Snate@binkert.orgbool 2197039Snate@binkert.orgSequencer::insertRequest(SequencerRequest* request) 2207039Snate@binkert.org{ 2217039Snate@binkert.org int total_outstanding = 2227039Snate@binkert.org m_writeRequestTable.size() + m_readRequestTable.size(); 2236285Snate@binkert.org 2247039Snate@binkert.org assert(m_outstanding_count == total_outstanding); 2256145Snate@binkert.org 2267039Snate@binkert.org // See if we should schedule a deadlock check 2277039Snate@binkert.org if (deadlockCheckEvent.scheduled() == false) { 2287039Snate@binkert.org schedule(deadlockCheckEvent, m_deadlock_threshold + curTick); 2297039Snate@binkert.org } 2306145Snate@binkert.org 2317039Snate@binkert.org Address line_addr(request->ruby_request.paddr); 2327039Snate@binkert.org line_addr.makeLineAddress(); 2337039Snate@binkert.org if ((request->ruby_request.type == RubyRequestType_ST) || 2347039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Read) || 2357039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Write) || 2367039Snate@binkert.org (request->ruby_request.type == RubyRequestType_Locked_Read) || 2377039Snate@binkert.org (request->ruby_request.type == RubyRequestType_Locked_Write)) { 2387455Snate@binkert.org pair<RequestTable::iterator, bool> r = 2397455Snate@binkert.org m_writeRequestTable.insert(RequestTable::value_type(line_addr, 0)); 2407455Snate@binkert.org bool success = r.second; 2417455Snate@binkert.org RequestTable::iterator i = r.first; 2427455Snate@binkert.org if (!success) { 2437455Snate@binkert.org i->second = request; 2447039Snate@binkert.org // return true; 2457039Snate@binkert.org 2467039Snate@binkert.org // drh5: isn't this an error? do you lose the initial request? 2477039Snate@binkert.org assert(0); 2487039Snate@binkert.org } 2497455Snate@binkert.org i->second = request; 2507039Snate@binkert.org m_outstanding_count++; 2517039Snate@binkert.org } else { 2527455Snate@binkert.org pair<RequestTable::iterator, bool> r = 2537455Snate@binkert.org m_readRequestTable.insert(RequestTable::value_type(line_addr, 0)); 2547455Snate@binkert.org bool success = r.second; 2557455Snate@binkert.org RequestTable::iterator i = r.first; 2567455Snate@binkert.org if (!success) { 2577455Snate@binkert.org i->second = request; 2587039Snate@binkert.org // return true; 2597039Snate@binkert.org 2607039Snate@binkert.org // drh5: isn't this an error? do you lose the initial request? 2617039Snate@binkert.org assert(0); 2627039Snate@binkert.org } 2637455Snate@binkert.org i->second = request; 2647039Snate@binkert.org m_outstanding_count++; 2656145Snate@binkert.org } 2666145Snate@binkert.org 2677039Snate@binkert.org g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count); 2686145Snate@binkert.org 2697039Snate@binkert.org total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size(); 2707039Snate@binkert.org assert(m_outstanding_count == total_outstanding); 2716145Snate@binkert.org 2727039Snate@binkert.org return false; 2736145Snate@binkert.org} 2746145Snate@binkert.org 2757039Snate@binkert.orgvoid 2767455Snate@binkert.orgSequencer::markRemoved() 2777455Snate@binkert.org{ 2787455Snate@binkert.org m_outstanding_count--; 2797455Snate@binkert.org assert(m_outstanding_count == 2807455Snate@binkert.org m_writeRequestTable.size() + m_readRequestTable.size()); 2817455Snate@binkert.org} 2827455Snate@binkert.org 2837455Snate@binkert.orgvoid 2847039Snate@binkert.orgSequencer::removeRequest(SequencerRequest* srequest) 2857039Snate@binkert.org{ 2867039Snate@binkert.org assert(m_outstanding_count == 2877039Snate@binkert.org m_writeRequestTable.size() + m_readRequestTable.size()); 2886145Snate@binkert.org 2897039Snate@binkert.org const RubyRequest & ruby_request = srequest->ruby_request; 2907039Snate@binkert.org Address line_addr(ruby_request.paddr); 2917039Snate@binkert.org line_addr.makeLineAddress(); 2927039Snate@binkert.org if ((ruby_request.type == RubyRequestType_ST) || 2937039Snate@binkert.org (ruby_request.type == RubyRequestType_RMW_Read) || 2947039Snate@binkert.org (ruby_request.type == RubyRequestType_RMW_Write) || 2957039Snate@binkert.org (ruby_request.type == RubyRequestType_Locked_Read) || 2967039Snate@binkert.org (ruby_request.type == RubyRequestType_Locked_Write)) { 2977455Snate@binkert.org m_writeRequestTable.erase(line_addr); 2987039Snate@binkert.org } else { 2997455Snate@binkert.org m_readRequestTable.erase(line_addr); 3007039Snate@binkert.org } 3016285Snate@binkert.org 3027455Snate@binkert.org markRemoved(); 3036145Snate@binkert.org} 3046145Snate@binkert.org 3057039Snate@binkert.orgvoid 3067039Snate@binkert.orgSequencer::writeCallback(const Address& address, DataBlock& data) 3077039Snate@binkert.org{ 3087546SBrad.Beckmann@amd.com writeCallback(address, GenericMachineType_NULL, data); 3097546SBrad.Beckmann@amd.com} 3107546SBrad.Beckmann@amd.com 3117546SBrad.Beckmann@amd.comvoid 3127546SBrad.Beckmann@amd.comSequencer::writeCallback(const Address& address, 3137546SBrad.Beckmann@amd.com GenericMachineType mach, 3147546SBrad.Beckmann@amd.com DataBlock& data) 3157546SBrad.Beckmann@amd.com{ 3167039Snate@binkert.org assert(address == line_address(address)); 3177455Snate@binkert.org assert(m_writeRequestTable.count(line_address(address))); 3186145Snate@binkert.org 3197455Snate@binkert.org RequestTable::iterator i = m_writeRequestTable.find(address); 3207455Snate@binkert.org assert(i != m_writeRequestTable.end()); 3217455Snate@binkert.org SequencerRequest* request = i->second; 3226145Snate@binkert.org 3237455Snate@binkert.org m_writeRequestTable.erase(i); 3247455Snate@binkert.org markRemoved(); 3256846Spdudnik@cs.wisc.edu 3267039Snate@binkert.org assert((request->ruby_request.type == RubyRequestType_ST) || 3277039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Read) || 3287039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Write) || 3297039Snate@binkert.org (request->ruby_request.type == RubyRequestType_Locked_Read) || 3307039Snate@binkert.org (request->ruby_request.type == RubyRequestType_Locked_Write)); 3316145Snate@binkert.org 3327039Snate@binkert.org if (request->ruby_request.type == RubyRequestType_Locked_Read) { 3337039Snate@binkert.org m_dataCache_ptr->setLocked(address, m_version); 3347039Snate@binkert.org } else if (request->ruby_request.type == RubyRequestType_RMW_Read) { 3357039Snate@binkert.org m_controller->blockOnQueue(address, m_mandatory_q_ptr); 3367039Snate@binkert.org } else if (request->ruby_request.type == RubyRequestType_RMW_Write) { 3377039Snate@binkert.org m_controller->unblock(address); 3387039Snate@binkert.org } 3396863Sdrh5@cs.wisc.edu 3407546SBrad.Beckmann@amd.com hitCallback(request, mach, data); 3416145Snate@binkert.org} 3426145Snate@binkert.org 3437039Snate@binkert.orgvoid 3447039Snate@binkert.orgSequencer::readCallback(const Address& address, DataBlock& data) 3457039Snate@binkert.org{ 3467546SBrad.Beckmann@amd.com readCallback(address, GenericMachineType_NULL, data); 3477546SBrad.Beckmann@amd.com} 3487546SBrad.Beckmann@amd.com 3497546SBrad.Beckmann@amd.comvoid 3507546SBrad.Beckmann@amd.comSequencer::readCallback(const Address& address, 3517546SBrad.Beckmann@amd.com GenericMachineType mach, 3527546SBrad.Beckmann@amd.com DataBlock& data) 3537546SBrad.Beckmann@amd.com{ 3547039Snate@binkert.org assert(address == line_address(address)); 3557455Snate@binkert.org assert(m_readRequestTable.count(line_address(address))); 3566145Snate@binkert.org 3577455Snate@binkert.org RequestTable::iterator i = m_readRequestTable.find(address); 3587455Snate@binkert.org assert(i != m_readRequestTable.end()); 3597455Snate@binkert.org SequencerRequest* request = i->second; 3607455Snate@binkert.org 3617455Snate@binkert.org m_readRequestTable.erase(i); 3627455Snate@binkert.org markRemoved(); 3636145Snate@binkert.org 3647039Snate@binkert.org assert((request->ruby_request.type == RubyRequestType_LD) || 3657039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Read) || 3667039Snate@binkert.org (request->ruby_request.type == RubyRequestType_IFETCH)); 3676285Snate@binkert.org 3687546SBrad.Beckmann@amd.com hitCallback(request, mach, data); 3696145Snate@binkert.org} 3706145Snate@binkert.org 3717039Snate@binkert.orgvoid 3727546SBrad.Beckmann@amd.comSequencer::hitCallback(SequencerRequest* srequest, 3737546SBrad.Beckmann@amd.com GenericMachineType mach, 3747546SBrad.Beckmann@amd.com DataBlock& data) 3757039Snate@binkert.org{ 3767039Snate@binkert.org const RubyRequest & ruby_request = srequest->ruby_request; 3777039Snate@binkert.org Address request_address(ruby_request.paddr); 3787039Snate@binkert.org Address request_line_address(ruby_request.paddr); 3797039Snate@binkert.org request_line_address.makeLineAddress(); 3807039Snate@binkert.org RubyRequestType type = ruby_request.type; 3817039Snate@binkert.org Time issued_time = srequest->issue_time; 3826145Snate@binkert.org 3837039Snate@binkert.org // Set this cache entry to the most recently used 3847039Snate@binkert.org if (type == RubyRequestType_IFETCH) { 3857039Snate@binkert.org if (m_instCache_ptr->isTagPresent(request_line_address)) 3867039Snate@binkert.org m_instCache_ptr->setMRU(request_line_address); 3877039Snate@binkert.org } else { 3887039Snate@binkert.org if (m_dataCache_ptr->isTagPresent(request_line_address)) 3897039Snate@binkert.org m_dataCache_ptr->setMRU(request_line_address); 3907039Snate@binkert.org } 3916145Snate@binkert.org 3927039Snate@binkert.org assert(g_eventQueue_ptr->getTime() >= issued_time); 3937039Snate@binkert.org Time miss_latency = g_eventQueue_ptr->getTime() - issued_time; 3946145Snate@binkert.org 3957039Snate@binkert.org // Profile the miss latency for all non-zero demand misses 3967039Snate@binkert.org if (miss_latency != 0) { 3977546SBrad.Beckmann@amd.com g_system_ptr->getProfiler()->missLatency(miss_latency, type, mach); 3986285Snate@binkert.org 3997039Snate@binkert.org if (Debug::getProtocolTrace()) { 4007039Snate@binkert.org g_system_ptr->getProfiler()-> 4017039Snate@binkert.org profileTransition("Seq", m_version, 4027039Snate@binkert.org Address(ruby_request.paddr), "", "Done", "", 4037039Snate@binkert.org csprintf("%d cycles", miss_latency)); 4047039Snate@binkert.org } 4056285Snate@binkert.org } 4067039Snate@binkert.org#if 0 4077039Snate@binkert.org if (request.getPrefetch() == PrefetchBit_Yes) { 4087039Snate@binkert.org return; // Ignore the prefetch 4097039Snate@binkert.org } 4107039Snate@binkert.org#endif 4116285Snate@binkert.org 4127039Snate@binkert.org // update the data 4137039Snate@binkert.org if (ruby_request.data != NULL) { 4147039Snate@binkert.org if ((type == RubyRequestType_LD) || 4157039Snate@binkert.org (type == RubyRequestType_IFETCH) || 4167039Snate@binkert.org (type == RubyRequestType_RMW_Read) || 4177039Snate@binkert.org (type == RubyRequestType_Locked_Read)) { 4187023SBrad.Beckmann@amd.com 4197039Snate@binkert.org memcpy(ruby_request.data, 4207039Snate@binkert.org data.getData(request_address.getOffset(), ruby_request.len), 4217039Snate@binkert.org ruby_request.len); 4227039Snate@binkert.org } else { 4237039Snate@binkert.org data.setData(ruby_request.data, request_address.getOffset(), 4247039Snate@binkert.org ruby_request.len); 4257039Snate@binkert.org } 4266285Snate@binkert.org } else { 4277039Snate@binkert.org DPRINTF(MemoryAccess, 4287039Snate@binkert.org "WARNING. Data not transfered from Ruby to M5 for type %s\n", 4297039Snate@binkert.org RubyRequestType_to_string(type)); 4307039Snate@binkert.org } 4317023SBrad.Beckmann@amd.com 4327039Snate@binkert.org // If using the RubyTester, update the RubyTester sender state's 4337039Snate@binkert.org // subBlock with the recieved data. The tester will later access 4347039Snate@binkert.org // this state. 4357039Snate@binkert.org // Note: RubyPort will access it's sender state before the 4367039Snate@binkert.org // RubyTester. 4377039Snate@binkert.org if (m_usingRubyTester) { 4387039Snate@binkert.org RubyPort::SenderState *requestSenderState = 4397039Snate@binkert.org safe_cast<RubyPort::SenderState*>(ruby_request.pkt->senderState); 4407039Snate@binkert.org RubyTester::SenderState* testerSenderState = 4417039Snate@binkert.org safe_cast<RubyTester::SenderState*>(requestSenderState->saved); 4427039Snate@binkert.org testerSenderState->subBlock->mergeFrom(data); 4437039Snate@binkert.org } 4447023SBrad.Beckmann@amd.com 4457039Snate@binkert.org ruby_hit_callback(ruby_request.pkt); 4467039Snate@binkert.org delete srequest; 4476285Snate@binkert.org} 4486285Snate@binkert.org 4496285Snate@binkert.org// Returns true if the sequencer already has a load or store outstanding 4507039Snate@binkert.orgRequestStatus 4517039Snate@binkert.orgSequencer::getRequestStatus(const RubyRequest& request) 4527039Snate@binkert.org{ 4537039Snate@binkert.org bool is_outstanding_store = 4547455Snate@binkert.org !!m_writeRequestTable.count(line_address(Address(request.paddr))); 4557039Snate@binkert.org bool is_outstanding_load = 4567455Snate@binkert.org !!m_readRequestTable.count(line_address(Address(request.paddr))); 4577039Snate@binkert.org if (is_outstanding_store) { 4587039Snate@binkert.org if ((request.type == RubyRequestType_LD) || 4597039Snate@binkert.org (request.type == RubyRequestType_IFETCH) || 4607039Snate@binkert.org (request.type == RubyRequestType_RMW_Read)) { 4617039Snate@binkert.org m_store_waiting_on_load_cycles++; 4627039Snate@binkert.org } else { 4637039Snate@binkert.org m_store_waiting_on_store_cycles++; 4647039Snate@binkert.org } 4657039Snate@binkert.org return RequestStatus_Aliased; 4667039Snate@binkert.org } else if (is_outstanding_load) { 4677039Snate@binkert.org if ((request.type == RubyRequestType_ST) || 4687039Snate@binkert.org (request.type == RubyRequestType_RMW_Write)) { 4697039Snate@binkert.org m_load_waiting_on_store_cycles++; 4707039Snate@binkert.org } else { 4717039Snate@binkert.org m_load_waiting_on_load_cycles++; 4727039Snate@binkert.org } 4737039Snate@binkert.org return RequestStatus_Aliased; 4746859Sdrh5@cs.wisc.edu } 4757039Snate@binkert.org 4767039Snate@binkert.org if (m_outstanding_count >= m_max_outstanding_requests) { 4777039Snate@binkert.org return RequestStatus_BufferFull; 4786859Sdrh5@cs.wisc.edu } 4796145Snate@binkert.org 4807039Snate@binkert.org return RequestStatus_Ready; 4816145Snate@binkert.org} 4826145Snate@binkert.org 4837039Snate@binkert.orgbool 4847039Snate@binkert.orgSequencer::empty() const 4857039Snate@binkert.org{ 4867455Snate@binkert.org return m_writeRequestTable.empty() && m_readRequestTable.empty(); 4876145Snate@binkert.org} 4886145Snate@binkert.org 4897039Snate@binkert.orgRequestStatus 4907039Snate@binkert.orgSequencer::makeRequest(const RubyRequest &request) 4917039Snate@binkert.org{ 4927039Snate@binkert.org assert(Address(request.paddr).getOffset() + request.len <= 4937039Snate@binkert.org RubySystem::getBlockSizeBytes()); 4947039Snate@binkert.org RequestStatus status = getRequestStatus(request); 4957039Snate@binkert.org if (status != RequestStatus_Ready) 4967039Snate@binkert.org return status; 4976349Spdudnik@gmail.com 4987039Snate@binkert.org SequencerRequest *srequest = 4997039Snate@binkert.org new SequencerRequest(request, g_eventQueue_ptr->getTime()); 5006285Snate@binkert.org bool found = insertRequest(srequest); 5017039Snate@binkert.org if (found) { 5027039Snate@binkert.org panic("Sequencer::makeRequest should never be called if the " 5037039Snate@binkert.org "request is already outstanding\n"); 5047039Snate@binkert.org return RequestStatus_NULL; 5057039Snate@binkert.org } 5067023SBrad.Beckmann@amd.com 5077039Snate@binkert.org if (request.type == RubyRequestType_Locked_Write) { 5087039Snate@binkert.org // NOTE: it is OK to check the locked flag here as the 5097039Snate@binkert.org // mandatory queue will be checked first ensuring that nothing 5107039Snate@binkert.org // comes between checking the flag and servicing the store. 5117023SBrad.Beckmann@amd.com 5127039Snate@binkert.org Address line_addr = line_address(Address(request.paddr)); 5137039Snate@binkert.org if (!m_dataCache_ptr->isLocked(line_addr, m_version)) { 5147039Snate@binkert.org removeRequest(srequest); 5157039Snate@binkert.org if (Debug::getProtocolTrace()) { 5167039Snate@binkert.org g_system_ptr->getProfiler()-> 5177039Snate@binkert.org profileTransition("Seq", m_version, 5187039Snate@binkert.org Address(request.paddr), 5197039Snate@binkert.org "", "SC Fail", "", 5207039Snate@binkert.org RubyRequestType_to_string(request.type)); 5217023SBrad.Beckmann@amd.com } 5227023SBrad.Beckmann@amd.com return RequestStatus_LlscFailed; 5237039Snate@binkert.org } else { 5247039Snate@binkert.org m_dataCache_ptr->clearLocked(line_addr); 5256349Spdudnik@gmail.com } 5267039Snate@binkert.org } 5277039Snate@binkert.org issueRequest(request); 5286145Snate@binkert.org 5297039Snate@binkert.org // TODO: issue hardware prefetches here 5307039Snate@binkert.org return RequestStatus_Issued; 5316145Snate@binkert.org} 5326145Snate@binkert.org 5337039Snate@binkert.orgvoid 5347039Snate@binkert.orgSequencer::issueRequest(const RubyRequest& request) 5357039Snate@binkert.org{ 5367039Snate@binkert.org // TODO: get rid of CacheMsg, CacheRequestType, and 5377039Snate@binkert.org // AccessModeTYpe, & have SLICC use RubyRequest and subtypes 5387039Snate@binkert.org // natively 5397039Snate@binkert.org CacheRequestType ctype; 5407039Snate@binkert.org switch(request.type) { 5417039Snate@binkert.org case RubyRequestType_IFETCH: 5427039Snate@binkert.org ctype = CacheRequestType_IFETCH; 5437039Snate@binkert.org break; 5447039Snate@binkert.org case RubyRequestType_LD: 5457039Snate@binkert.org ctype = CacheRequestType_LD; 5467039Snate@binkert.org break; 5477039Snate@binkert.org case RubyRequestType_ST: 5487039Snate@binkert.org ctype = CacheRequestType_ST; 5497039Snate@binkert.org break; 5507039Snate@binkert.org case RubyRequestType_Locked_Read: 5517039Snate@binkert.org case RubyRequestType_Locked_Write: 5527039Snate@binkert.org ctype = CacheRequestType_ATOMIC; 5537039Snate@binkert.org break; 5547039Snate@binkert.org case RubyRequestType_RMW_Read: 5557039Snate@binkert.org ctype = CacheRequestType_ATOMIC; 5567039Snate@binkert.org break; 5577039Snate@binkert.org case RubyRequestType_RMW_Write: 5587039Snate@binkert.org ctype = CacheRequestType_ATOMIC; 5597039Snate@binkert.org break; 5607039Snate@binkert.org default: 5617039Snate@binkert.org assert(0); 5627039Snate@binkert.org } 5636285Snate@binkert.org 5647039Snate@binkert.org AccessModeType amtype; 5657039Snate@binkert.org switch(request.access_mode){ 5667039Snate@binkert.org case RubyAccessMode_User: 5677039Snate@binkert.org amtype = AccessModeType_UserMode; 5687039Snate@binkert.org break; 5697039Snate@binkert.org case RubyAccessMode_Supervisor: 5707039Snate@binkert.org amtype = AccessModeType_SupervisorMode; 5717039Snate@binkert.org break; 5727039Snate@binkert.org case RubyAccessMode_Device: 5737039Snate@binkert.org amtype = AccessModeType_UserMode; 5747039Snate@binkert.org break; 5757039Snate@binkert.org default: 5767039Snate@binkert.org assert(0); 5777039Snate@binkert.org } 5786285Snate@binkert.org 5797039Snate@binkert.org Address line_addr(request.paddr); 5807039Snate@binkert.org line_addr.makeLineAddress(); 5817453Snate@binkert.org CacheMsg *msg = new CacheMsg(line_addr, Address(request.paddr), ctype, 5827453Snate@binkert.org Address(request.pc), amtype, request.len, PrefetchBit_No, 5837453Snate@binkert.org request.proc_id); 5846285Snate@binkert.org 5857039Snate@binkert.org if (Debug::getProtocolTrace()) { 5867039Snate@binkert.org g_system_ptr->getProfiler()-> 5877039Snate@binkert.org profileTransition("Seq", m_version, Address(request.paddr), 5887039Snate@binkert.org "", "Begin", "", 5897039Snate@binkert.org RubyRequestType_to_string(request.type)); 5907039Snate@binkert.org } 5916285Snate@binkert.org 5927039Snate@binkert.org if (g_system_ptr->getTracer()->traceEnabled()) { 5937039Snate@binkert.org g_system_ptr->getTracer()-> 5947039Snate@binkert.org traceRequest(this, line_addr, Address(request.pc), 5957039Snate@binkert.org request.type, g_eventQueue_ptr->getTime()); 5967039Snate@binkert.org } 5976285Snate@binkert.org 5987039Snate@binkert.org Time latency = 0; // initialzed to an null value 5996285Snate@binkert.org 6007039Snate@binkert.org if (request.type == RubyRequestType_IFETCH) 6017039Snate@binkert.org latency = m_instCache_ptr->getLatency(); 6027039Snate@binkert.org else 6037039Snate@binkert.org latency = m_dataCache_ptr->getLatency(); 6046285Snate@binkert.org 6057039Snate@binkert.org // Send the message to the cache controller 6067039Snate@binkert.org assert(latency > 0); 6076145Snate@binkert.org 6087039Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 6097039Snate@binkert.org m_mandatory_q_ptr->enqueue(msg, latency); 6106145Snate@binkert.org} 6116145Snate@binkert.org 6127039Snate@binkert.org#if 0 6137039Snate@binkert.orgbool 6147039Snate@binkert.orgSequencer::tryCacheAccess(const Address& addr, CacheRequestType type, 6157039Snate@binkert.org AccessModeType access_mode, 6167039Snate@binkert.org int size, DataBlock*& data_ptr) 6177039Snate@binkert.org{ 6187039Snate@binkert.org CacheMemory *cache = 6197039Snate@binkert.org (type == CacheRequestType_IFETCH) ? m_instCache_ptr : m_dataCache_ptr; 6207039Snate@binkert.org 6217039Snate@binkert.org return cache->tryCacheAccess(line_address(addr), type, data_ptr); 6227039Snate@binkert.org} 6237039Snate@binkert.org#endif 6247039Snate@binkert.org 6257455Snate@binkert.orgtemplate <class KEY, class VALUE> 6267455Snate@binkert.orgstd::ostream & 6277455Snate@binkert.orgoperator<<(ostream &out, const m5::hash_map<KEY, VALUE> &map) 6287455Snate@binkert.org{ 6297455Snate@binkert.org typename m5::hash_map<KEY, VALUE>::const_iterator i = map.begin(); 6307455Snate@binkert.org typename m5::hash_map<KEY, VALUE>::const_iterator end = map.end(); 6317455Snate@binkert.org 6327455Snate@binkert.org out << "["; 6337455Snate@binkert.org for (; i != end; ++i) 6347455Snate@binkert.org out << " " << i->first << "=" << i->second; 6357455Snate@binkert.org out << " ]"; 6367455Snate@binkert.org 6377455Snate@binkert.org return out; 6387455Snate@binkert.org} 6397455Snate@binkert.org 6407039Snate@binkert.orgvoid 6417039Snate@binkert.orgSequencer::print(ostream& out) const 6427039Snate@binkert.org{ 6437039Snate@binkert.org out << "[Sequencer: " << m_version 6447039Snate@binkert.org << ", outstanding requests: " << m_outstanding_count 6457039Snate@binkert.org << ", read request table: " << m_readRequestTable 6467039Snate@binkert.org << ", write request table: " << m_writeRequestTable 6477039Snate@binkert.org << "]"; 6487039Snate@binkert.org} 6497039Snate@binkert.org 6507039Snate@binkert.org// this can be called from setState whenever coherence permissions are 6517039Snate@binkert.org// upgraded when invoked, coherence violations will be checked for the 6527039Snate@binkert.org// given block 6537039Snate@binkert.orgvoid 6547039Snate@binkert.orgSequencer::checkCoherence(const Address& addr) 6557039Snate@binkert.org{ 6566145Snate@binkert.org#ifdef CHECK_COHERENCE 6577039Snate@binkert.org g_system_ptr->checkGlobalCoherenceInvariant(addr); 6586145Snate@binkert.org#endif 6596145Snate@binkert.org} 660