Sequencer.cc revision 7537
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{ 3087039Snate@binkert.org assert(address == line_address(address)); 3097455Snate@binkert.org assert(m_writeRequestTable.count(line_address(address))); 3106145Snate@binkert.org 3117455Snate@binkert.org RequestTable::iterator i = m_writeRequestTable.find(address); 3127455Snate@binkert.org assert(i != m_writeRequestTable.end()); 3137455Snate@binkert.org SequencerRequest* request = i->second; 3146145Snate@binkert.org 3157455Snate@binkert.org m_writeRequestTable.erase(i); 3167455Snate@binkert.org markRemoved(); 3176846Spdudnik@cs.wisc.edu 3187039Snate@binkert.org assert((request->ruby_request.type == RubyRequestType_ST) || 3197039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Read) || 3207039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Write) || 3217039Snate@binkert.org (request->ruby_request.type == RubyRequestType_Locked_Read) || 3227039Snate@binkert.org (request->ruby_request.type == RubyRequestType_Locked_Write)); 3236145Snate@binkert.org 3247039Snate@binkert.org if (request->ruby_request.type == RubyRequestType_Locked_Read) { 3257039Snate@binkert.org m_dataCache_ptr->setLocked(address, m_version); 3267039Snate@binkert.org } else if (request->ruby_request.type == RubyRequestType_RMW_Read) { 3277039Snate@binkert.org m_controller->blockOnQueue(address, m_mandatory_q_ptr); 3287039Snate@binkert.org } else if (request->ruby_request.type == RubyRequestType_RMW_Write) { 3297039Snate@binkert.org m_controller->unblock(address); 3307039Snate@binkert.org } 3316863Sdrh5@cs.wisc.edu 3327039Snate@binkert.org hitCallback(request, data); 3336145Snate@binkert.org} 3346145Snate@binkert.org 3357039Snate@binkert.orgvoid 3367039Snate@binkert.orgSequencer::readCallback(const Address& address, DataBlock& data) 3377039Snate@binkert.org{ 3387039Snate@binkert.org assert(address == line_address(address)); 3397455Snate@binkert.org assert(m_readRequestTable.count(line_address(address))); 3406145Snate@binkert.org 3417455Snate@binkert.org RequestTable::iterator i = m_readRequestTable.find(address); 3427455Snate@binkert.org assert(i != m_readRequestTable.end()); 3437455Snate@binkert.org SequencerRequest* request = i->second; 3447455Snate@binkert.org 3457455Snate@binkert.org m_readRequestTable.erase(i); 3467455Snate@binkert.org markRemoved(); 3476145Snate@binkert.org 3487039Snate@binkert.org assert((request->ruby_request.type == RubyRequestType_LD) || 3497039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Read) || 3507039Snate@binkert.org (request->ruby_request.type == RubyRequestType_IFETCH)); 3516285Snate@binkert.org 3527039Snate@binkert.org hitCallback(request, data); 3536145Snate@binkert.org} 3546145Snate@binkert.org 3557039Snate@binkert.orgvoid 3567039Snate@binkert.orgSequencer::hitCallback(SequencerRequest* srequest, DataBlock& data) 3577039Snate@binkert.org{ 3587039Snate@binkert.org const RubyRequest & ruby_request = srequest->ruby_request; 3597039Snate@binkert.org Address request_address(ruby_request.paddr); 3607039Snate@binkert.org Address request_line_address(ruby_request.paddr); 3617039Snate@binkert.org request_line_address.makeLineAddress(); 3627039Snate@binkert.org RubyRequestType type = ruby_request.type; 3637039Snate@binkert.org Time issued_time = srequest->issue_time; 3646145Snate@binkert.org 3657039Snate@binkert.org // Set this cache entry to the most recently used 3667039Snate@binkert.org if (type == RubyRequestType_IFETCH) { 3677039Snate@binkert.org if (m_instCache_ptr->isTagPresent(request_line_address)) 3687039Snate@binkert.org m_instCache_ptr->setMRU(request_line_address); 3697039Snate@binkert.org } else { 3707039Snate@binkert.org if (m_dataCache_ptr->isTagPresent(request_line_address)) 3717039Snate@binkert.org m_dataCache_ptr->setMRU(request_line_address); 3727039Snate@binkert.org } 3736145Snate@binkert.org 3747039Snate@binkert.org assert(g_eventQueue_ptr->getTime() >= issued_time); 3757039Snate@binkert.org Time miss_latency = g_eventQueue_ptr->getTime() - issued_time; 3766145Snate@binkert.org 3777039Snate@binkert.org // Profile the miss latency for all non-zero demand misses 3787039Snate@binkert.org if (miss_latency != 0) { 3797039Snate@binkert.org g_system_ptr->getProfiler()->missLatency(miss_latency, type); 3806285Snate@binkert.org 3817039Snate@binkert.org if (Debug::getProtocolTrace()) { 3827039Snate@binkert.org g_system_ptr->getProfiler()-> 3837039Snate@binkert.org profileTransition("Seq", m_version, 3847039Snate@binkert.org Address(ruby_request.paddr), "", "Done", "", 3857039Snate@binkert.org csprintf("%d cycles", miss_latency)); 3867039Snate@binkert.org } 3876285Snate@binkert.org } 3887039Snate@binkert.org#if 0 3897039Snate@binkert.org if (request.getPrefetch() == PrefetchBit_Yes) { 3907039Snate@binkert.org return; // Ignore the prefetch 3917039Snate@binkert.org } 3927039Snate@binkert.org#endif 3936285Snate@binkert.org 3947039Snate@binkert.org // update the data 3957039Snate@binkert.org if (ruby_request.data != NULL) { 3967039Snate@binkert.org if ((type == RubyRequestType_LD) || 3977039Snate@binkert.org (type == RubyRequestType_IFETCH) || 3987039Snate@binkert.org (type == RubyRequestType_RMW_Read) || 3997039Snate@binkert.org (type == RubyRequestType_Locked_Read)) { 4007023SBrad.Beckmann@amd.com 4017039Snate@binkert.org memcpy(ruby_request.data, 4027039Snate@binkert.org data.getData(request_address.getOffset(), ruby_request.len), 4037039Snate@binkert.org ruby_request.len); 4047039Snate@binkert.org } else { 4057039Snate@binkert.org data.setData(ruby_request.data, request_address.getOffset(), 4067039Snate@binkert.org ruby_request.len); 4077039Snate@binkert.org } 4086285Snate@binkert.org } else { 4097039Snate@binkert.org DPRINTF(MemoryAccess, 4107039Snate@binkert.org "WARNING. Data not transfered from Ruby to M5 for type %s\n", 4117039Snate@binkert.org RubyRequestType_to_string(type)); 4127039Snate@binkert.org } 4137023SBrad.Beckmann@amd.com 4147039Snate@binkert.org // If using the RubyTester, update the RubyTester sender state's 4157039Snate@binkert.org // subBlock with the recieved data. The tester will later access 4167039Snate@binkert.org // this state. 4177039Snate@binkert.org // Note: RubyPort will access it's sender state before the 4187039Snate@binkert.org // RubyTester. 4197039Snate@binkert.org if (m_usingRubyTester) { 4207039Snate@binkert.org RubyPort::SenderState *requestSenderState = 4217039Snate@binkert.org safe_cast<RubyPort::SenderState*>(ruby_request.pkt->senderState); 4227039Snate@binkert.org RubyTester::SenderState* testerSenderState = 4237039Snate@binkert.org safe_cast<RubyTester::SenderState*>(requestSenderState->saved); 4247039Snate@binkert.org testerSenderState->subBlock->mergeFrom(data); 4257039Snate@binkert.org } 4267023SBrad.Beckmann@amd.com 4277039Snate@binkert.org ruby_hit_callback(ruby_request.pkt); 4287039Snate@binkert.org delete srequest; 4296285Snate@binkert.org} 4306285Snate@binkert.org 4316285Snate@binkert.org// Returns true if the sequencer already has a load or store outstanding 4327039Snate@binkert.orgRequestStatus 4337039Snate@binkert.orgSequencer::getRequestStatus(const RubyRequest& request) 4347039Snate@binkert.org{ 4357039Snate@binkert.org bool is_outstanding_store = 4367455Snate@binkert.org !!m_writeRequestTable.count(line_address(Address(request.paddr))); 4377039Snate@binkert.org bool is_outstanding_load = 4387455Snate@binkert.org !!m_readRequestTable.count(line_address(Address(request.paddr))); 4397039Snate@binkert.org if (is_outstanding_store) { 4407039Snate@binkert.org if ((request.type == RubyRequestType_LD) || 4417039Snate@binkert.org (request.type == RubyRequestType_IFETCH) || 4427039Snate@binkert.org (request.type == RubyRequestType_RMW_Read)) { 4437039Snate@binkert.org m_store_waiting_on_load_cycles++; 4447039Snate@binkert.org } else { 4457039Snate@binkert.org m_store_waiting_on_store_cycles++; 4467039Snate@binkert.org } 4477039Snate@binkert.org return RequestStatus_Aliased; 4487039Snate@binkert.org } else if (is_outstanding_load) { 4497039Snate@binkert.org if ((request.type == RubyRequestType_ST) || 4507039Snate@binkert.org (request.type == RubyRequestType_RMW_Write)) { 4517039Snate@binkert.org m_load_waiting_on_store_cycles++; 4527039Snate@binkert.org } else { 4537039Snate@binkert.org m_load_waiting_on_load_cycles++; 4547039Snate@binkert.org } 4557039Snate@binkert.org return RequestStatus_Aliased; 4566859Sdrh5@cs.wisc.edu } 4577039Snate@binkert.org 4587039Snate@binkert.org if (m_outstanding_count >= m_max_outstanding_requests) { 4597039Snate@binkert.org return RequestStatus_BufferFull; 4606859Sdrh5@cs.wisc.edu } 4616145Snate@binkert.org 4627039Snate@binkert.org return RequestStatus_Ready; 4636145Snate@binkert.org} 4646145Snate@binkert.org 4657039Snate@binkert.orgbool 4667039Snate@binkert.orgSequencer::empty() const 4677039Snate@binkert.org{ 4687455Snate@binkert.org return m_writeRequestTable.empty() && m_readRequestTable.empty(); 4696145Snate@binkert.org} 4706145Snate@binkert.org 4717039Snate@binkert.orgRequestStatus 4727039Snate@binkert.orgSequencer::makeRequest(const RubyRequest &request) 4737039Snate@binkert.org{ 4747039Snate@binkert.org assert(Address(request.paddr).getOffset() + request.len <= 4757039Snate@binkert.org RubySystem::getBlockSizeBytes()); 4767039Snate@binkert.org RequestStatus status = getRequestStatus(request); 4777039Snate@binkert.org if (status != RequestStatus_Ready) 4787039Snate@binkert.org return status; 4796349Spdudnik@gmail.com 4807039Snate@binkert.org SequencerRequest *srequest = 4817039Snate@binkert.org new SequencerRequest(request, g_eventQueue_ptr->getTime()); 4826285Snate@binkert.org bool found = insertRequest(srequest); 4837039Snate@binkert.org if (found) { 4847039Snate@binkert.org panic("Sequencer::makeRequest should never be called if the " 4857039Snate@binkert.org "request is already outstanding\n"); 4867039Snate@binkert.org return RequestStatus_NULL; 4877039Snate@binkert.org } 4887023SBrad.Beckmann@amd.com 4897039Snate@binkert.org if (request.type == RubyRequestType_Locked_Write) { 4907039Snate@binkert.org // NOTE: it is OK to check the locked flag here as the 4917039Snate@binkert.org // mandatory queue will be checked first ensuring that nothing 4927039Snate@binkert.org // comes between checking the flag and servicing the store. 4937023SBrad.Beckmann@amd.com 4947039Snate@binkert.org Address line_addr = line_address(Address(request.paddr)); 4957039Snate@binkert.org if (!m_dataCache_ptr->isLocked(line_addr, m_version)) { 4967039Snate@binkert.org removeRequest(srequest); 4977039Snate@binkert.org if (Debug::getProtocolTrace()) { 4987039Snate@binkert.org g_system_ptr->getProfiler()-> 4997039Snate@binkert.org profileTransition("Seq", m_version, 5007039Snate@binkert.org Address(request.paddr), 5017039Snate@binkert.org "", "SC Fail", "", 5027039Snate@binkert.org RubyRequestType_to_string(request.type)); 5037023SBrad.Beckmann@amd.com } 5047023SBrad.Beckmann@amd.com return RequestStatus_LlscFailed; 5057039Snate@binkert.org } else { 5067039Snate@binkert.org m_dataCache_ptr->clearLocked(line_addr); 5076349Spdudnik@gmail.com } 5087039Snate@binkert.org } 5097039Snate@binkert.org issueRequest(request); 5106145Snate@binkert.org 5117039Snate@binkert.org // TODO: issue hardware prefetches here 5127039Snate@binkert.org return RequestStatus_Issued; 5136145Snate@binkert.org} 5146145Snate@binkert.org 5157039Snate@binkert.orgvoid 5167039Snate@binkert.orgSequencer::issueRequest(const RubyRequest& request) 5177039Snate@binkert.org{ 5187039Snate@binkert.org // TODO: get rid of CacheMsg, CacheRequestType, and 5197039Snate@binkert.org // AccessModeTYpe, & have SLICC use RubyRequest and subtypes 5207039Snate@binkert.org // natively 5217039Snate@binkert.org CacheRequestType ctype; 5227039Snate@binkert.org switch(request.type) { 5237039Snate@binkert.org case RubyRequestType_IFETCH: 5247039Snate@binkert.org ctype = CacheRequestType_IFETCH; 5257039Snate@binkert.org break; 5267039Snate@binkert.org case RubyRequestType_LD: 5277039Snate@binkert.org ctype = CacheRequestType_LD; 5287039Snate@binkert.org break; 5297039Snate@binkert.org case RubyRequestType_ST: 5307039Snate@binkert.org ctype = CacheRequestType_ST; 5317039Snate@binkert.org break; 5327039Snate@binkert.org case RubyRequestType_Locked_Read: 5337039Snate@binkert.org case RubyRequestType_Locked_Write: 5347039Snate@binkert.org ctype = CacheRequestType_ATOMIC; 5357039Snate@binkert.org break; 5367039Snate@binkert.org case RubyRequestType_RMW_Read: 5377039Snate@binkert.org ctype = CacheRequestType_ATOMIC; 5387039Snate@binkert.org break; 5397039Snate@binkert.org case RubyRequestType_RMW_Write: 5407039Snate@binkert.org ctype = CacheRequestType_ATOMIC; 5417039Snate@binkert.org break; 5427039Snate@binkert.org default: 5437039Snate@binkert.org assert(0); 5447039Snate@binkert.org } 5456285Snate@binkert.org 5467039Snate@binkert.org AccessModeType amtype; 5477039Snate@binkert.org switch(request.access_mode){ 5487039Snate@binkert.org case RubyAccessMode_User: 5497039Snate@binkert.org amtype = AccessModeType_UserMode; 5507039Snate@binkert.org break; 5517039Snate@binkert.org case RubyAccessMode_Supervisor: 5527039Snate@binkert.org amtype = AccessModeType_SupervisorMode; 5537039Snate@binkert.org break; 5547039Snate@binkert.org case RubyAccessMode_Device: 5557039Snate@binkert.org amtype = AccessModeType_UserMode; 5567039Snate@binkert.org break; 5577039Snate@binkert.org default: 5587039Snate@binkert.org assert(0); 5597039Snate@binkert.org } 5606285Snate@binkert.org 5617039Snate@binkert.org Address line_addr(request.paddr); 5627039Snate@binkert.org line_addr.makeLineAddress(); 5637453Snate@binkert.org CacheMsg *msg = new CacheMsg(line_addr, Address(request.paddr), ctype, 5647453Snate@binkert.org Address(request.pc), amtype, request.len, PrefetchBit_No, 5657453Snate@binkert.org request.proc_id); 5666285Snate@binkert.org 5677039Snate@binkert.org if (Debug::getProtocolTrace()) { 5687039Snate@binkert.org g_system_ptr->getProfiler()-> 5697039Snate@binkert.org profileTransition("Seq", m_version, Address(request.paddr), 5707039Snate@binkert.org "", "Begin", "", 5717039Snate@binkert.org RubyRequestType_to_string(request.type)); 5727039Snate@binkert.org } 5736285Snate@binkert.org 5747039Snate@binkert.org if (g_system_ptr->getTracer()->traceEnabled()) { 5757039Snate@binkert.org g_system_ptr->getTracer()-> 5767039Snate@binkert.org traceRequest(this, line_addr, Address(request.pc), 5777039Snate@binkert.org request.type, g_eventQueue_ptr->getTime()); 5787039Snate@binkert.org } 5796285Snate@binkert.org 5807039Snate@binkert.org Time latency = 0; // initialzed to an null value 5816285Snate@binkert.org 5827039Snate@binkert.org if (request.type == RubyRequestType_IFETCH) 5837039Snate@binkert.org latency = m_instCache_ptr->getLatency(); 5847039Snate@binkert.org else 5857039Snate@binkert.org latency = m_dataCache_ptr->getLatency(); 5866285Snate@binkert.org 5877039Snate@binkert.org // Send the message to the cache controller 5887039Snate@binkert.org assert(latency > 0); 5896145Snate@binkert.org 5907039Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 5917039Snate@binkert.org m_mandatory_q_ptr->enqueue(msg, latency); 5926145Snate@binkert.org} 5936145Snate@binkert.org 5947039Snate@binkert.org#if 0 5957039Snate@binkert.orgbool 5967039Snate@binkert.orgSequencer::tryCacheAccess(const Address& addr, CacheRequestType type, 5977039Snate@binkert.org AccessModeType access_mode, 5987039Snate@binkert.org int size, DataBlock*& data_ptr) 5997039Snate@binkert.org{ 6007039Snate@binkert.org CacheMemory *cache = 6017039Snate@binkert.org (type == CacheRequestType_IFETCH) ? m_instCache_ptr : m_dataCache_ptr; 6027039Snate@binkert.org 6037039Snate@binkert.org return cache->tryCacheAccess(line_address(addr), type, data_ptr); 6047039Snate@binkert.org} 6057039Snate@binkert.org#endif 6067039Snate@binkert.org 6077455Snate@binkert.orgtemplate <class KEY, class VALUE> 6087455Snate@binkert.orgstd::ostream & 6097455Snate@binkert.orgoperator<<(ostream &out, const m5::hash_map<KEY, VALUE> &map) 6107455Snate@binkert.org{ 6117455Snate@binkert.org typename m5::hash_map<KEY, VALUE>::const_iterator i = map.begin(); 6127455Snate@binkert.org typename m5::hash_map<KEY, VALUE>::const_iterator end = map.end(); 6137455Snate@binkert.org 6147455Snate@binkert.org out << "["; 6157455Snate@binkert.org for (; i != end; ++i) 6167455Snate@binkert.org out << " " << i->first << "=" << i->second; 6177455Snate@binkert.org out << " ]"; 6187455Snate@binkert.org 6197455Snate@binkert.org return out; 6207455Snate@binkert.org} 6217455Snate@binkert.org 6227039Snate@binkert.orgvoid 6237039Snate@binkert.orgSequencer::print(ostream& out) const 6247039Snate@binkert.org{ 6257039Snate@binkert.org out << "[Sequencer: " << m_version 6267039Snate@binkert.org << ", outstanding requests: " << m_outstanding_count 6277039Snate@binkert.org << ", read request table: " << m_readRequestTable 6287039Snate@binkert.org << ", write request table: " << m_writeRequestTable 6297039Snate@binkert.org << "]"; 6307039Snate@binkert.org} 6317039Snate@binkert.org 6327039Snate@binkert.org// this can be called from setState whenever coherence permissions are 6337039Snate@binkert.org// upgraded when invoked, coherence violations will be checked for the 6347039Snate@binkert.org// given block 6357039Snate@binkert.orgvoid 6367039Snate@binkert.orgSequencer::checkCoherence(const Address& addr) 6377039Snate@binkert.org{ 6386145Snate@binkert.org#ifdef CHECK_COHERENCE 6397039Snate@binkert.org g_system_ptr->checkGlobalCoherenceInvariant(addr); 6406145Snate@binkert.org#endif 6416145Snate@binkert.org} 642