Sequencer.cc revision 8092
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" 307805Snilay@cs.wisc.edu#include "base/misc.hh" 317632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/RubyTester.hh" 327039Snate@binkert.org#include "mem/protocol/CacheMsg.hh" 337039Snate@binkert.org#include "mem/protocol/Protocol.hh" 347039Snate@binkert.org#include "mem/protocol/Protocol.hh" 357039Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh" 367039Snate@binkert.org#include "mem/ruby/common/Global.hh" 377039Snate@binkert.org#include "mem/ruby/common/SubBlock.hh" 388092Snilay@cs.wisc.edu#include "mem/ruby/slicc_interface/RubyRequest.hh" 397039Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 407039Snate@binkert.org#include "mem/ruby/recorder/Tracer.hh" 417039Snate@binkert.org#include "mem/ruby/slicc_interface/AbstractController.hh" 427039Snate@binkert.org#include "mem/ruby/system/CacheMemory.hh" 436154Snate@binkert.org#include "mem/ruby/system/Sequencer.hh" 446154Snate@binkert.org#include "mem/ruby/system/System.hh" 457550SBrad.Beckmann@amd.com#include "mem/packet.hh" 466876Ssteve.reinhardt@amd.com#include "params/RubySequencer.hh" 476876Ssteve.reinhardt@amd.com 487055Snate@binkert.orgusing namespace std; 497055Snate@binkert.org 506876Ssteve.reinhardt@amd.comSequencer * 516876Ssteve.reinhardt@amd.comRubySequencerParams::create() 526285Snate@binkert.org{ 536876Ssteve.reinhardt@amd.com return new Sequencer(this); 546285Snate@binkert.org} 557039Snate@binkert.org 566876Ssteve.reinhardt@amd.comSequencer::Sequencer(const Params *p) 576886SBrad.Beckmann@amd.com : RubyPort(p), deadlockCheckEvent(this) 586876Ssteve.reinhardt@amd.com{ 596876Ssteve.reinhardt@amd.com m_store_waiting_on_load_cycles = 0; 606876Ssteve.reinhardt@amd.com m_store_waiting_on_store_cycles = 0; 616876Ssteve.reinhardt@amd.com m_load_waiting_on_store_cycles = 0; 626876Ssteve.reinhardt@amd.com m_load_waiting_on_load_cycles = 0; 637039Snate@binkert.org 646876Ssteve.reinhardt@amd.com m_outstanding_count = 0; 656285Snate@binkert.org 666876Ssteve.reinhardt@amd.com m_max_outstanding_requests = 0; 676876Ssteve.reinhardt@amd.com m_deadlock_threshold = 0; 686876Ssteve.reinhardt@amd.com m_instCache_ptr = NULL; 696876Ssteve.reinhardt@amd.com m_dataCache_ptr = NULL; 706145Snate@binkert.org 716876Ssteve.reinhardt@amd.com m_instCache_ptr = p->icache; 726876Ssteve.reinhardt@amd.com m_dataCache_ptr = p->dcache; 736876Ssteve.reinhardt@amd.com m_max_outstanding_requests = p->max_outstanding_requests; 746876Ssteve.reinhardt@amd.com m_deadlock_threshold = p->deadlock_threshold; 756899SBrad.Beckmann@amd.com 766876Ssteve.reinhardt@amd.com assert(m_max_outstanding_requests > 0); 776876Ssteve.reinhardt@amd.com assert(m_deadlock_threshold > 0); 786876Ssteve.reinhardt@amd.com assert(m_instCache_ptr != NULL); 796876Ssteve.reinhardt@amd.com assert(m_dataCache_ptr != NULL); 806145Snate@binkert.org} 816145Snate@binkert.org 827039Snate@binkert.orgSequencer::~Sequencer() 837039Snate@binkert.org{ 846145Snate@binkert.org} 856145Snate@binkert.org 867039Snate@binkert.orgvoid 877039Snate@binkert.orgSequencer::wakeup() 887039Snate@binkert.org{ 897039Snate@binkert.org // Check for deadlock of any of the requests 907039Snate@binkert.org Time current_time = g_eventQueue_ptr->getTime(); 916145Snate@binkert.org 927039Snate@binkert.org // Check across all outstanding requests 937039Snate@binkert.org int total_outstanding = 0; 946285Snate@binkert.org 957455Snate@binkert.org RequestTable::iterator read = m_readRequestTable.begin(); 967455Snate@binkert.org RequestTable::iterator read_end = m_readRequestTable.end(); 977455Snate@binkert.org for (; read != read_end; ++read) { 987455Snate@binkert.org SequencerRequest* request = read->second; 997455Snate@binkert.org if (current_time - request->issue_time < m_deadlock_threshold) 1007455Snate@binkert.org continue; 1017455Snate@binkert.org 1027805Snilay@cs.wisc.edu panic("Possible Deadlock detected. Aborting!\n" 1037921SBrad.Beckmann@amd.com "version: %d request.paddr: 0x%x m_readRequestTable: %d " 1047805Snilay@cs.wisc.edu "current time: %u issue_time: %d difference: %d\n", m_version, 1057805Snilay@cs.wisc.edu request->ruby_request.paddr, m_readRequestTable.size(), 1067805Snilay@cs.wisc.edu current_time, request->issue_time, 1077805Snilay@cs.wisc.edu current_time - request->issue_time); 1086145Snate@binkert.org } 1096145Snate@binkert.org 1107455Snate@binkert.org RequestTable::iterator write = m_writeRequestTable.begin(); 1117455Snate@binkert.org RequestTable::iterator write_end = m_writeRequestTable.end(); 1127455Snate@binkert.org for (; write != write_end; ++write) { 1137455Snate@binkert.org SequencerRequest* request = write->second; 1147455Snate@binkert.org if (current_time - request->issue_time < m_deadlock_threshold) 1157455Snate@binkert.org continue; 1167455Snate@binkert.org 1177805Snilay@cs.wisc.edu panic("Possible Deadlock detected. Aborting!\n" 1187921SBrad.Beckmann@amd.com "version: %d request.paddr: 0x%x m_writeRequestTable: %d " 1197805Snilay@cs.wisc.edu "current time: %u issue_time: %d difference: %d\n", m_version, 1207805Snilay@cs.wisc.edu request->ruby_request.paddr, m_writeRequestTable.size(), 1217805Snilay@cs.wisc.edu current_time, request->issue_time, 1227805Snilay@cs.wisc.edu current_time - request->issue_time); 1236145Snate@binkert.org } 1246285Snate@binkert.org 1257039Snate@binkert.org total_outstanding += m_writeRequestTable.size(); 1267039Snate@binkert.org total_outstanding += m_readRequestTable.size(); 1276145Snate@binkert.org 1287039Snate@binkert.org assert(m_outstanding_count == total_outstanding); 1297039Snate@binkert.org 1307039Snate@binkert.org if (m_outstanding_count > 0) { 1317039Snate@binkert.org // If there are still outstanding requests, keep checking 1327039Snate@binkert.org schedule(deadlockCheckEvent, 1337039Snate@binkert.org m_deadlock_threshold * g_eventQueue_ptr->getClock() + 1347823Ssteve.reinhardt@amd.com curTick()); 1357039Snate@binkert.org } 1366145Snate@binkert.org} 1376145Snate@binkert.org 1387039Snate@binkert.orgvoid 1397039Snate@binkert.orgSequencer::printStats(ostream & out) const 1407039Snate@binkert.org{ 1417039Snate@binkert.org out << "Sequencer: " << m_name << endl 1427039Snate@binkert.org << " store_waiting_on_load_cycles: " 1437039Snate@binkert.org << m_store_waiting_on_load_cycles << endl 1447039Snate@binkert.org << " store_waiting_on_store_cycles: " 1457039Snate@binkert.org << m_store_waiting_on_store_cycles << endl 1467039Snate@binkert.org << " load_waiting_on_load_cycles: " 1477039Snate@binkert.org << m_load_waiting_on_load_cycles << endl 1487039Snate@binkert.org << " load_waiting_on_store_cycles: " 1497039Snate@binkert.org << m_load_waiting_on_store_cycles << endl; 1506859Sdrh5@cs.wisc.edu} 1516859Sdrh5@cs.wisc.edu 1527039Snate@binkert.orgvoid 1537039Snate@binkert.orgSequencer::printProgress(ostream& out) const 1547039Snate@binkert.org{ 1557039Snate@binkert.org#if 0 1567039Snate@binkert.org int total_demand = 0; 1577039Snate@binkert.org out << "Sequencer Stats Version " << m_version << endl; 1587039Snate@binkert.org out << "Current time = " << g_eventQueue_ptr->getTime() << endl; 1597039Snate@binkert.org out << "---------------" << endl; 1607039Snate@binkert.org out << "outstanding requests" << endl; 1616145Snate@binkert.org 1627455Snate@binkert.org out << "proc " << m_Read 1637455Snate@binkert.org << " version Requests = " << m_readRequestTable.size() << endl; 1646145Snate@binkert.org 1657039Snate@binkert.org // print the request table 1667455Snate@binkert.org RequestTable::iterator read = m_readRequestTable.begin(); 1677455Snate@binkert.org RequestTable::iterator read_end = m_readRequestTable.end(); 1687455Snate@binkert.org for (; read != read_end; ++read) { 1697455Snate@binkert.org SequencerRequest* request = read->second; 1707039Snate@binkert.org out << "\tRequest[ " << i << " ] = " << request->type 1717039Snate@binkert.org << " Address " << rkeys[i] 1727039Snate@binkert.org << " Posted " << request->issue_time 1737039Snate@binkert.org << " PF " << PrefetchBit_No << endl; 1746145Snate@binkert.org total_demand++; 1757039Snate@binkert.org } 1766145Snate@binkert.org 1777455Snate@binkert.org out << "proc " << m_version 1787455Snate@binkert.org << " Write Requests = " << m_writeRequestTable.size << endl; 1796285Snate@binkert.org 1807039Snate@binkert.org // print the request table 1817455Snate@binkert.org RequestTable::iterator write = m_writeRequestTable.begin(); 1827455Snate@binkert.org RequestTable::iterator write_end = m_writeRequestTable.end(); 1837455Snate@binkert.org for (; write != write_end; ++write) { 1847455Snate@binkert.org SequencerRequest* request = write->second; 1857039Snate@binkert.org out << "\tRequest[ " << i << " ] = " << request.getType() 1867039Snate@binkert.org << " Address " << wkeys[i] 1877039Snate@binkert.org << " Posted " << request.getTime() 1887039Snate@binkert.org << " PF " << request.getPrefetch() << endl; 1897039Snate@binkert.org if (request.getPrefetch() == PrefetchBit_No) { 1907039Snate@binkert.org total_demand++; 1917039Snate@binkert.org } 1927039Snate@binkert.org } 1937039Snate@binkert.org 1947039Snate@binkert.org out << endl; 1957039Snate@binkert.org 1967039Snate@binkert.org out << "Total Number Outstanding: " << m_outstanding_count << endl 1977039Snate@binkert.org << "Total Number Demand : " << total_demand << endl 1987039Snate@binkert.org << "Total Number Prefetches : " << m_outstanding_count - total_demand 1997039Snate@binkert.org << endl << endl << endl; 2007039Snate@binkert.org#endif 2016145Snate@binkert.org} 2026145Snate@binkert.org 2037039Snate@binkert.orgvoid 2047039Snate@binkert.orgSequencer::printConfig(ostream& out) const 2057039Snate@binkert.org{ 2067039Snate@binkert.org out << "Seqeuncer config: " << m_name << endl 2077039Snate@binkert.org << " controller: " << m_controller->getName() << endl 2087039Snate@binkert.org << " version: " << m_version << endl 2097039Snate@binkert.org << " max_outstanding_requests: " << m_max_outstanding_requests << endl 2107039Snate@binkert.org << " deadlock_threshold: " << m_deadlock_threshold << endl; 2116145Snate@binkert.org} 2126145Snate@binkert.org 2136145Snate@binkert.org// Insert the request on the correct request table. Return true if 2146145Snate@binkert.org// the entry was already present. 2157039Snate@binkert.orgbool 2167039Snate@binkert.orgSequencer::insertRequest(SequencerRequest* request) 2177039Snate@binkert.org{ 2187039Snate@binkert.org int total_outstanding = 2197039Snate@binkert.org m_writeRequestTable.size() + m_readRequestTable.size(); 2206285Snate@binkert.org 2217039Snate@binkert.org assert(m_outstanding_count == total_outstanding); 2226145Snate@binkert.org 2237039Snate@binkert.org // See if we should schedule a deadlock check 2247039Snate@binkert.org if (deadlockCheckEvent.scheduled() == false) { 2257823Ssteve.reinhardt@amd.com schedule(deadlockCheckEvent, m_deadlock_threshold + curTick()); 2267039Snate@binkert.org } 2276145Snate@binkert.org 2287039Snate@binkert.org Address line_addr(request->ruby_request.paddr); 2297039Snate@binkert.org line_addr.makeLineAddress(); 2307039Snate@binkert.org if ((request->ruby_request.type == RubyRequestType_ST) || 2317039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Read) || 2327039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Write) || 2337907Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Load_Linked) || 2347908Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Store_Conditional) || 2357908Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Locked_RMW_Read) || 2367908Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Locked_RMW_Write)) { 2377455Snate@binkert.org pair<RequestTable::iterator, bool> r = 2387455Snate@binkert.org m_writeRequestTable.insert(RequestTable::value_type(line_addr, 0)); 2397455Snate@binkert.org bool success = r.second; 2407455Snate@binkert.org RequestTable::iterator i = r.first; 2417455Snate@binkert.org if (!success) { 2427455Snate@binkert.org i->second = request; 2437039Snate@binkert.org // return true; 2447039Snate@binkert.org 2457039Snate@binkert.org // drh5: isn't this an error? do you lose the initial request? 2467039Snate@binkert.org assert(0); 2477039Snate@binkert.org } 2487455Snate@binkert.org i->second = request; 2497039Snate@binkert.org m_outstanding_count++; 2507039Snate@binkert.org } else { 2517455Snate@binkert.org pair<RequestTable::iterator, bool> r = 2527455Snate@binkert.org m_readRequestTable.insert(RequestTable::value_type(line_addr, 0)); 2537455Snate@binkert.org bool success = r.second; 2547455Snate@binkert.org RequestTable::iterator i = r.first; 2557455Snate@binkert.org if (!success) { 2567455Snate@binkert.org i->second = request; 2577039Snate@binkert.org // return true; 2587039Snate@binkert.org 2597039Snate@binkert.org // drh5: isn't this an error? do you lose the initial request? 2607039Snate@binkert.org assert(0); 2617039Snate@binkert.org } 2627455Snate@binkert.org i->second = request; 2637039Snate@binkert.org m_outstanding_count++; 2646145Snate@binkert.org } 2656145Snate@binkert.org 2667039Snate@binkert.org g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count); 2676145Snate@binkert.org 2687039Snate@binkert.org total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size(); 2697039Snate@binkert.org assert(m_outstanding_count == total_outstanding); 2706145Snate@binkert.org 2717039Snate@binkert.org return false; 2726145Snate@binkert.org} 2736145Snate@binkert.org 2747039Snate@binkert.orgvoid 2757455Snate@binkert.orgSequencer::markRemoved() 2767455Snate@binkert.org{ 2777455Snate@binkert.org m_outstanding_count--; 2787455Snate@binkert.org assert(m_outstanding_count == 2797455Snate@binkert.org m_writeRequestTable.size() + m_readRequestTable.size()); 2807455Snate@binkert.org} 2817455Snate@binkert.org 2827455Snate@binkert.orgvoid 2837039Snate@binkert.orgSequencer::removeRequest(SequencerRequest* srequest) 2847039Snate@binkert.org{ 2857039Snate@binkert.org assert(m_outstanding_count == 2867039Snate@binkert.org m_writeRequestTable.size() + m_readRequestTable.size()); 2876145Snate@binkert.org 2887039Snate@binkert.org const RubyRequest & ruby_request = srequest->ruby_request; 2897039Snate@binkert.org Address line_addr(ruby_request.paddr); 2907039Snate@binkert.org line_addr.makeLineAddress(); 2917039Snate@binkert.org if ((ruby_request.type == RubyRequestType_ST) || 2927039Snate@binkert.org (ruby_request.type == RubyRequestType_RMW_Read) || 2937039Snate@binkert.org (ruby_request.type == RubyRequestType_RMW_Write) || 2947907Shestness@cs.utexas.edu (ruby_request.type == RubyRequestType_Load_Linked) || 2957908Shestness@cs.utexas.edu (ruby_request.type == RubyRequestType_Store_Conditional) || 2967908Shestness@cs.utexas.edu (ruby_request.type == RubyRequestType_Locked_RMW_Read) || 2977908Shestness@cs.utexas.edu (ruby_request.type == RubyRequestType_Locked_RMW_Write)) { 2987455Snate@binkert.org m_writeRequestTable.erase(line_addr); 2997039Snate@binkert.org } else { 3007455Snate@binkert.org m_readRequestTable.erase(line_addr); 3017039Snate@binkert.org } 3026285Snate@binkert.org 3037455Snate@binkert.org markRemoved(); 3046145Snate@binkert.org} 3056145Snate@binkert.org 3067560SBrad.Beckmann@amd.combool 3077560SBrad.Beckmann@amd.comSequencer::handleLlsc(const Address& address, SequencerRequest* request) 3087550SBrad.Beckmann@amd.com{ 3097560SBrad.Beckmann@amd.com // 3107560SBrad.Beckmann@amd.com // The success flag indicates whether the LLSC operation was successful. 3117560SBrad.Beckmann@amd.com // LL ops will always succeed, but SC may fail if the cache line is no 3127560SBrad.Beckmann@amd.com // longer locked. 3137560SBrad.Beckmann@amd.com // 3147560SBrad.Beckmann@amd.com bool success = true; 3157907Shestness@cs.utexas.edu if (request->ruby_request.type == RubyRequestType_Store_Conditional) { 3167550SBrad.Beckmann@amd.com if (!m_dataCache_ptr->isLocked(address, m_version)) { 3177550SBrad.Beckmann@amd.com // 3187550SBrad.Beckmann@amd.com // For failed SC requests, indicate the failure to the cpu by 3197550SBrad.Beckmann@amd.com // setting the extra data to zero. 3207550SBrad.Beckmann@amd.com // 3217550SBrad.Beckmann@amd.com request->ruby_request.pkt->req->setExtraData(0); 3227560SBrad.Beckmann@amd.com success = false; 3237550SBrad.Beckmann@amd.com } else { 3247550SBrad.Beckmann@amd.com // 3257550SBrad.Beckmann@amd.com // For successful SC requests, indicate the success to the cpu by 3267550SBrad.Beckmann@amd.com // setting the extra data to one. 3277550SBrad.Beckmann@amd.com // 3287550SBrad.Beckmann@amd.com request->ruby_request.pkt->req->setExtraData(1); 3297550SBrad.Beckmann@amd.com } 3307560SBrad.Beckmann@amd.com // 3317560SBrad.Beckmann@amd.com // Independent of success, all SC operations must clear the lock 3327560SBrad.Beckmann@amd.com // 3337550SBrad.Beckmann@amd.com m_dataCache_ptr->clearLocked(address); 3347907Shestness@cs.utexas.edu } else if (request->ruby_request.type == RubyRequestType_Load_Linked) { 3357550SBrad.Beckmann@amd.com // 3367550SBrad.Beckmann@amd.com // Note: To fully follow Alpha LLSC semantics, should the LL clear any 3377550SBrad.Beckmann@amd.com // previously locked cache lines? 3387550SBrad.Beckmann@amd.com // 3397550SBrad.Beckmann@amd.com m_dataCache_ptr->setLocked(address, m_version); 3407550SBrad.Beckmann@amd.com } else if (m_dataCache_ptr->isLocked(address, m_version)) { 3417550SBrad.Beckmann@amd.com // 3427550SBrad.Beckmann@amd.com // Normal writes should clear the locked address 3437550SBrad.Beckmann@amd.com // 3447550SBrad.Beckmann@amd.com m_dataCache_ptr->clearLocked(address); 3457550SBrad.Beckmann@amd.com } 3467560SBrad.Beckmann@amd.com return success; 3477550SBrad.Beckmann@amd.com} 3487550SBrad.Beckmann@amd.com 3497550SBrad.Beckmann@amd.comvoid 3507039Snate@binkert.orgSequencer::writeCallback(const Address& address, DataBlock& data) 3517039Snate@binkert.org{ 3527546SBrad.Beckmann@amd.com writeCallback(address, GenericMachineType_NULL, data); 3537546SBrad.Beckmann@amd.com} 3547546SBrad.Beckmann@amd.com 3557546SBrad.Beckmann@amd.comvoid 3567546SBrad.Beckmann@amd.comSequencer::writeCallback(const Address& address, 3577546SBrad.Beckmann@amd.com GenericMachineType mach, 3587546SBrad.Beckmann@amd.com DataBlock& data) 3597546SBrad.Beckmann@amd.com{ 3607565SBrad.Beckmann@amd.com writeCallback(address, mach, data, 0, 0, 0); 3617565SBrad.Beckmann@amd.com} 3627565SBrad.Beckmann@amd.com 3637565SBrad.Beckmann@amd.comvoid 3647565SBrad.Beckmann@amd.comSequencer::writeCallback(const Address& address, 3657565SBrad.Beckmann@amd.com GenericMachineType mach, 3667565SBrad.Beckmann@amd.com DataBlock& data, 3677565SBrad.Beckmann@amd.com Time initialRequestTime, 3687565SBrad.Beckmann@amd.com Time forwardRequestTime, 3697565SBrad.Beckmann@amd.com Time firstResponseTime) 3707565SBrad.Beckmann@amd.com{ 3717039Snate@binkert.org assert(address == line_address(address)); 3727455Snate@binkert.org assert(m_writeRequestTable.count(line_address(address))); 3736145Snate@binkert.org 3747455Snate@binkert.org RequestTable::iterator i = m_writeRequestTable.find(address); 3757455Snate@binkert.org assert(i != m_writeRequestTable.end()); 3767455Snate@binkert.org SequencerRequest* request = i->second; 3776145Snate@binkert.org 3787455Snate@binkert.org m_writeRequestTable.erase(i); 3797455Snate@binkert.org markRemoved(); 3806846Spdudnik@cs.wisc.edu 3817039Snate@binkert.org assert((request->ruby_request.type == RubyRequestType_ST) || 3827039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Read) || 3837039Snate@binkert.org (request->ruby_request.type == RubyRequestType_RMW_Write) || 3847907Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Load_Linked) || 3857908Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Store_Conditional) || 3867908Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Locked_RMW_Read) || 3877908Shestness@cs.utexas.edu (request->ruby_request.type == RubyRequestType_Locked_RMW_Write)); 3886145Snate@binkert.org 3897550SBrad.Beckmann@amd.com // 3907550SBrad.Beckmann@amd.com // For Alpha, properly handle LL, SC, and write requests with respect to 3917550SBrad.Beckmann@amd.com // locked cache blocks. 3927550SBrad.Beckmann@amd.com // 3937560SBrad.Beckmann@amd.com bool success = handleLlsc(address, request); 3947550SBrad.Beckmann@amd.com 3957908Shestness@cs.utexas.edu if (request->ruby_request.type == RubyRequestType_Locked_RMW_Read) { 3967039Snate@binkert.org m_controller->blockOnQueue(address, m_mandatory_q_ptr); 3977908Shestness@cs.utexas.edu } else if (request->ruby_request.type == RubyRequestType_Locked_RMW_Write) { 3987039Snate@binkert.org m_controller->unblock(address); 3997039Snate@binkert.org } 4006863Sdrh5@cs.wisc.edu 4017565SBrad.Beckmann@amd.com hitCallback(request, mach, data, success, 4027565SBrad.Beckmann@amd.com initialRequestTime, forwardRequestTime, firstResponseTime); 4036145Snate@binkert.org} 4046145Snate@binkert.org 4057039Snate@binkert.orgvoid 4067039Snate@binkert.orgSequencer::readCallback(const Address& address, DataBlock& data) 4077039Snate@binkert.org{ 4087546SBrad.Beckmann@amd.com readCallback(address, GenericMachineType_NULL, data); 4097546SBrad.Beckmann@amd.com} 4107546SBrad.Beckmann@amd.com 4117546SBrad.Beckmann@amd.comvoid 4127546SBrad.Beckmann@amd.comSequencer::readCallback(const Address& address, 4137546SBrad.Beckmann@amd.com GenericMachineType mach, 4147546SBrad.Beckmann@amd.com DataBlock& data) 4157546SBrad.Beckmann@amd.com{ 4167565SBrad.Beckmann@amd.com readCallback(address, mach, data, 0, 0, 0); 4177565SBrad.Beckmann@amd.com} 4187565SBrad.Beckmann@amd.com 4197565SBrad.Beckmann@amd.comvoid 4207565SBrad.Beckmann@amd.comSequencer::readCallback(const Address& address, 4217565SBrad.Beckmann@amd.com GenericMachineType mach, 4227565SBrad.Beckmann@amd.com DataBlock& data, 4237565SBrad.Beckmann@amd.com Time initialRequestTime, 4247565SBrad.Beckmann@amd.com Time forwardRequestTime, 4257565SBrad.Beckmann@amd.com Time firstResponseTime) 4267565SBrad.Beckmann@amd.com{ 4277039Snate@binkert.org assert(address == line_address(address)); 4287455Snate@binkert.org assert(m_readRequestTable.count(line_address(address))); 4296145Snate@binkert.org 4307455Snate@binkert.org RequestTable::iterator i = m_readRequestTable.find(address); 4317455Snate@binkert.org assert(i != m_readRequestTable.end()); 4327455Snate@binkert.org SequencerRequest* request = i->second; 4337455Snate@binkert.org 4347455Snate@binkert.org m_readRequestTable.erase(i); 4357455Snate@binkert.org markRemoved(); 4366145Snate@binkert.org 4377039Snate@binkert.org assert((request->ruby_request.type == RubyRequestType_LD) || 4387039Snate@binkert.org (request->ruby_request.type == RubyRequestType_IFETCH)); 4396285Snate@binkert.org 4407565SBrad.Beckmann@amd.com hitCallback(request, mach, data, true, 4417565SBrad.Beckmann@amd.com initialRequestTime, forwardRequestTime, firstResponseTime); 4426145Snate@binkert.org} 4436145Snate@binkert.org 4447039Snate@binkert.orgvoid 4457546SBrad.Beckmann@amd.comSequencer::hitCallback(SequencerRequest* srequest, 4467546SBrad.Beckmann@amd.com GenericMachineType mach, 4477560SBrad.Beckmann@amd.com DataBlock& data, 4487565SBrad.Beckmann@amd.com bool success, 4497565SBrad.Beckmann@amd.com Time initialRequestTime, 4507565SBrad.Beckmann@amd.com Time forwardRequestTime, 4517565SBrad.Beckmann@amd.com Time firstResponseTime) 4527039Snate@binkert.org{ 4537039Snate@binkert.org const RubyRequest & ruby_request = srequest->ruby_request; 4547039Snate@binkert.org Address request_address(ruby_request.paddr); 4557039Snate@binkert.org Address request_line_address(ruby_request.paddr); 4567039Snate@binkert.org request_line_address.makeLineAddress(); 4577039Snate@binkert.org RubyRequestType type = ruby_request.type; 4587039Snate@binkert.org Time issued_time = srequest->issue_time; 4596145Snate@binkert.org 4607039Snate@binkert.org // Set this cache entry to the most recently used 4617039Snate@binkert.org if (type == RubyRequestType_IFETCH) { 4627039Snate@binkert.org if (m_instCache_ptr->isTagPresent(request_line_address)) 4637039Snate@binkert.org m_instCache_ptr->setMRU(request_line_address); 4647039Snate@binkert.org } else { 4657039Snate@binkert.org if (m_dataCache_ptr->isTagPresent(request_line_address)) 4667039Snate@binkert.org m_dataCache_ptr->setMRU(request_line_address); 4677039Snate@binkert.org } 4686145Snate@binkert.org 4697039Snate@binkert.org assert(g_eventQueue_ptr->getTime() >= issued_time); 4707039Snate@binkert.org Time miss_latency = g_eventQueue_ptr->getTime() - issued_time; 4716145Snate@binkert.org 4727039Snate@binkert.org // Profile the miss latency for all non-zero demand misses 4737039Snate@binkert.org if (miss_latency != 0) { 4747546SBrad.Beckmann@amd.com g_system_ptr->getProfiler()->missLatency(miss_latency, type, mach); 4756285Snate@binkert.org 4767565SBrad.Beckmann@amd.com if (mach == GenericMachineType_L1Cache_wCC) { 4777565SBrad.Beckmann@amd.com g_system_ptr->getProfiler()->missLatencyWcc(issued_time, 4787565SBrad.Beckmann@amd.com initialRequestTime, 4797565SBrad.Beckmann@amd.com forwardRequestTime, 4807565SBrad.Beckmann@amd.com firstResponseTime, 4817565SBrad.Beckmann@amd.com g_eventQueue_ptr->getTime()); 4827565SBrad.Beckmann@amd.com } 4837565SBrad.Beckmann@amd.com 4847565SBrad.Beckmann@amd.com if (mach == GenericMachineType_Directory) { 4857565SBrad.Beckmann@amd.com g_system_ptr->getProfiler()->missLatencyDir(issued_time, 4867565SBrad.Beckmann@amd.com initialRequestTime, 4877565SBrad.Beckmann@amd.com forwardRequestTime, 4887565SBrad.Beckmann@amd.com firstResponseTime, 4897565SBrad.Beckmann@amd.com g_eventQueue_ptr->getTime()); 4907565SBrad.Beckmann@amd.com } 4917565SBrad.Beckmann@amd.com 4927832Snate@binkert.org DPRINTFR(ProtocolTrace, "%7s %3s %10s%20s %6s>%-6s %s %d cycles\n", 4937832Snate@binkert.org g_eventQueue_ptr->getTime(), m_version, "Seq", 4947832Snate@binkert.org success ? "Done" : "SC_Failed", "", "", 4957832Snate@binkert.org Address(ruby_request.paddr), miss_latency); 4966285Snate@binkert.org } 4977039Snate@binkert.org#if 0 4987039Snate@binkert.org if (request.getPrefetch() == PrefetchBit_Yes) { 4997039Snate@binkert.org return; // Ignore the prefetch 5007039Snate@binkert.org } 5017039Snate@binkert.org#endif 5026285Snate@binkert.org 5037039Snate@binkert.org // update the data 5047039Snate@binkert.org if (ruby_request.data != NULL) { 5057039Snate@binkert.org if ((type == RubyRequestType_LD) || 5067039Snate@binkert.org (type == RubyRequestType_IFETCH) || 5077039Snate@binkert.org (type == RubyRequestType_RMW_Read) || 5087908Shestness@cs.utexas.edu (type == RubyRequestType_Locked_RMW_Read) || 5097907Shestness@cs.utexas.edu (type == RubyRequestType_Load_Linked)) { 5107039Snate@binkert.org memcpy(ruby_request.data, 5117039Snate@binkert.org data.getData(request_address.getOffset(), ruby_request.len), 5127039Snate@binkert.org ruby_request.len); 5137039Snate@binkert.org } else { 5147039Snate@binkert.org data.setData(ruby_request.data, request_address.getOffset(), 5157039Snate@binkert.org ruby_request.len); 5167039Snate@binkert.org } 5176285Snate@binkert.org } else { 5187039Snate@binkert.org DPRINTF(MemoryAccess, 5197039Snate@binkert.org "WARNING. Data not transfered from Ruby to M5 for type %s\n", 5207039Snate@binkert.org RubyRequestType_to_string(type)); 5217039Snate@binkert.org } 5227023SBrad.Beckmann@amd.com 5237039Snate@binkert.org // If using the RubyTester, update the RubyTester sender state's 5247039Snate@binkert.org // subBlock with the recieved data. The tester will later access 5257039Snate@binkert.org // this state. 5267039Snate@binkert.org // Note: RubyPort will access it's sender state before the 5277039Snate@binkert.org // RubyTester. 5287039Snate@binkert.org if (m_usingRubyTester) { 5297039Snate@binkert.org RubyPort::SenderState *requestSenderState = 5307039Snate@binkert.org safe_cast<RubyPort::SenderState*>(ruby_request.pkt->senderState); 5317039Snate@binkert.org RubyTester::SenderState* testerSenderState = 5327039Snate@binkert.org safe_cast<RubyTester::SenderState*>(requestSenderState->saved); 5337039Snate@binkert.org testerSenderState->subBlock->mergeFrom(data); 5347039Snate@binkert.org } 5357023SBrad.Beckmann@amd.com 5367039Snate@binkert.org ruby_hit_callback(ruby_request.pkt); 5377039Snate@binkert.org delete srequest; 5386285Snate@binkert.org} 5396285Snate@binkert.org 5406285Snate@binkert.org// Returns true if the sequencer already has a load or store outstanding 5417039Snate@binkert.orgRequestStatus 5427039Snate@binkert.orgSequencer::getRequestStatus(const RubyRequest& request) 5437039Snate@binkert.org{ 5447039Snate@binkert.org bool is_outstanding_store = 5457455Snate@binkert.org !!m_writeRequestTable.count(line_address(Address(request.paddr))); 5467039Snate@binkert.org bool is_outstanding_load = 5477455Snate@binkert.org !!m_readRequestTable.count(line_address(Address(request.paddr))); 5487039Snate@binkert.org if (is_outstanding_store) { 5497039Snate@binkert.org if ((request.type == RubyRequestType_LD) || 5507039Snate@binkert.org (request.type == RubyRequestType_IFETCH) || 5517039Snate@binkert.org (request.type == RubyRequestType_RMW_Read)) { 5527039Snate@binkert.org m_store_waiting_on_load_cycles++; 5537039Snate@binkert.org } else { 5547039Snate@binkert.org m_store_waiting_on_store_cycles++; 5557039Snate@binkert.org } 5567039Snate@binkert.org return RequestStatus_Aliased; 5577039Snate@binkert.org } else if (is_outstanding_load) { 5587039Snate@binkert.org if ((request.type == RubyRequestType_ST) || 5597039Snate@binkert.org (request.type == RubyRequestType_RMW_Write)) { 5607039Snate@binkert.org m_load_waiting_on_store_cycles++; 5617039Snate@binkert.org } else { 5627039Snate@binkert.org m_load_waiting_on_load_cycles++; 5637039Snate@binkert.org } 5647039Snate@binkert.org return RequestStatus_Aliased; 5656859Sdrh5@cs.wisc.edu } 5667039Snate@binkert.org 5677039Snate@binkert.org if (m_outstanding_count >= m_max_outstanding_requests) { 5687039Snate@binkert.org return RequestStatus_BufferFull; 5696859Sdrh5@cs.wisc.edu } 5706145Snate@binkert.org 5717039Snate@binkert.org return RequestStatus_Ready; 5726145Snate@binkert.org} 5736145Snate@binkert.org 5747039Snate@binkert.orgbool 5757039Snate@binkert.orgSequencer::empty() const 5767039Snate@binkert.org{ 5777455Snate@binkert.org return m_writeRequestTable.empty() && m_readRequestTable.empty(); 5786145Snate@binkert.org} 5796145Snate@binkert.org 5807039Snate@binkert.orgRequestStatus 5817039Snate@binkert.orgSequencer::makeRequest(const RubyRequest &request) 5827039Snate@binkert.org{ 5837039Snate@binkert.org assert(Address(request.paddr).getOffset() + request.len <= 5847039Snate@binkert.org RubySystem::getBlockSizeBytes()); 5857039Snate@binkert.org RequestStatus status = getRequestStatus(request); 5867039Snate@binkert.org if (status != RequestStatus_Ready) 5877039Snate@binkert.org return status; 5886349Spdudnik@gmail.com 5897039Snate@binkert.org SequencerRequest *srequest = 5907039Snate@binkert.org new SequencerRequest(request, g_eventQueue_ptr->getTime()); 5916285Snate@binkert.org bool found = insertRequest(srequest); 5927039Snate@binkert.org if (found) { 5937039Snate@binkert.org panic("Sequencer::makeRequest should never be called if the " 5947039Snate@binkert.org "request is already outstanding\n"); 5957039Snate@binkert.org return RequestStatus_NULL; 5967039Snate@binkert.org } 5977023SBrad.Beckmann@amd.com 5987039Snate@binkert.org issueRequest(request); 5996145Snate@binkert.org 6007039Snate@binkert.org // TODO: issue hardware prefetches here 6017039Snate@binkert.org return RequestStatus_Issued; 6026145Snate@binkert.org} 6036145Snate@binkert.org 6047039Snate@binkert.orgvoid 6057039Snate@binkert.orgSequencer::issueRequest(const RubyRequest& request) 6067039Snate@binkert.org{ 6077039Snate@binkert.org // TODO: get rid of CacheMsg, CacheRequestType, and 6087039Snate@binkert.org // AccessModeTYpe, & have SLICC use RubyRequest and subtypes 6097039Snate@binkert.org // natively 6107039Snate@binkert.org CacheRequestType ctype; 6117039Snate@binkert.org switch(request.type) { 6127039Snate@binkert.org case RubyRequestType_IFETCH: 6137039Snate@binkert.org ctype = CacheRequestType_IFETCH; 6147039Snate@binkert.org break; 6157039Snate@binkert.org case RubyRequestType_LD: 6167039Snate@binkert.org ctype = CacheRequestType_LD; 6177039Snate@binkert.org break; 6187039Snate@binkert.org case RubyRequestType_ST: 6197908Shestness@cs.utexas.edu case RubyRequestType_RMW_Read: 6207908Shestness@cs.utexas.edu case RubyRequestType_RMW_Write: 6217908Shestness@cs.utexas.edu // 6227908Shestness@cs.utexas.edu // x86 locked instructions are translated to store cache coherence 6237908Shestness@cs.utexas.edu // requests because these requests should always be treated as read 6247908Shestness@cs.utexas.edu // exclusive operations and should leverage any migratory sharing 6257908Shestness@cs.utexas.edu // optimization built into the protocol. 6267908Shestness@cs.utexas.edu // 6277908Shestness@cs.utexas.edu case RubyRequestType_Locked_RMW_Read: 6287908Shestness@cs.utexas.edu case RubyRequestType_Locked_RMW_Write: 6297039Snate@binkert.org ctype = CacheRequestType_ST; 6307039Snate@binkert.org break; 6317908Shestness@cs.utexas.edu // 6327908Shestness@cs.utexas.edu // Alpha LL/SC instructions need to be handled carefully by the cache 6337908Shestness@cs.utexas.edu // coherence protocol to ensure they follow the proper semantics. In 6347908Shestness@cs.utexas.edu // particular, by identifying the operations as atomic, the protocol 6357908Shestness@cs.utexas.edu // should understand that migratory sharing optimizations should not be 6367908Shestness@cs.utexas.edu // performed (i.e. a load between the LL and SC should not steal away 6377908Shestness@cs.utexas.edu // exclusive permission). 6387908Shestness@cs.utexas.edu // 6397907Shestness@cs.utexas.edu case RubyRequestType_Load_Linked: 6407907Shestness@cs.utexas.edu case RubyRequestType_Store_Conditional: 6417039Snate@binkert.org ctype = CacheRequestType_ATOMIC; 6427039Snate@binkert.org break; 6437039Snate@binkert.org default: 6447039Snate@binkert.org assert(0); 6457039Snate@binkert.org } 6466285Snate@binkert.org 6477039Snate@binkert.org AccessModeType amtype; 6487039Snate@binkert.org switch(request.access_mode){ 6497039Snate@binkert.org case RubyAccessMode_User: 6507039Snate@binkert.org amtype = AccessModeType_UserMode; 6517039Snate@binkert.org break; 6527039Snate@binkert.org case RubyAccessMode_Supervisor: 6537039Snate@binkert.org amtype = AccessModeType_SupervisorMode; 6547039Snate@binkert.org break; 6557039Snate@binkert.org case RubyAccessMode_Device: 6567039Snate@binkert.org amtype = AccessModeType_UserMode; 6577039Snate@binkert.org break; 6587039Snate@binkert.org default: 6597039Snate@binkert.org assert(0); 6607039Snate@binkert.org } 6616285Snate@binkert.org 6627039Snate@binkert.org Address line_addr(request.paddr); 6637039Snate@binkert.org line_addr.makeLineAddress(); 6647453Snate@binkert.org CacheMsg *msg = new CacheMsg(line_addr, Address(request.paddr), ctype, 6657453Snate@binkert.org Address(request.pc), amtype, request.len, PrefetchBit_No, 6667453Snate@binkert.org request.proc_id); 6676285Snate@binkert.org 6687832Snate@binkert.org DPRINTFR(ProtocolTrace, "%7s %3s %10s%20s %6s>%-6s %s %s\n", 6697832Snate@binkert.org g_eventQueue_ptr->getTime(), m_version, "Seq", "Begin", "", "", 6707832Snate@binkert.org Address(request.paddr), RubyRequestType_to_string(request.type)); 6716285Snate@binkert.org 6727039Snate@binkert.org Time latency = 0; // initialzed to an null value 6736285Snate@binkert.org 6747039Snate@binkert.org if (request.type == RubyRequestType_IFETCH) 6757039Snate@binkert.org latency = m_instCache_ptr->getLatency(); 6767039Snate@binkert.org else 6777039Snate@binkert.org latency = m_dataCache_ptr->getLatency(); 6786285Snate@binkert.org 6797039Snate@binkert.org // Send the message to the cache controller 6807039Snate@binkert.org assert(latency > 0); 6816145Snate@binkert.org 6827039Snate@binkert.org assert(m_mandatory_q_ptr != NULL); 6837039Snate@binkert.org m_mandatory_q_ptr->enqueue(msg, latency); 6846145Snate@binkert.org} 6856145Snate@binkert.org 6867039Snate@binkert.org#if 0 6877039Snate@binkert.orgbool 6887039Snate@binkert.orgSequencer::tryCacheAccess(const Address& addr, CacheRequestType type, 6897039Snate@binkert.org AccessModeType access_mode, 6907039Snate@binkert.org int size, DataBlock*& data_ptr) 6917039Snate@binkert.org{ 6927039Snate@binkert.org CacheMemory *cache = 6937039Snate@binkert.org (type == CacheRequestType_IFETCH) ? m_instCache_ptr : m_dataCache_ptr; 6947039Snate@binkert.org 6957039Snate@binkert.org return cache->tryCacheAccess(line_address(addr), type, data_ptr); 6967039Snate@binkert.org} 6977039Snate@binkert.org#endif 6987039Snate@binkert.org 6997455Snate@binkert.orgtemplate <class KEY, class VALUE> 7007455Snate@binkert.orgstd::ostream & 7017455Snate@binkert.orgoperator<<(ostream &out, const m5::hash_map<KEY, VALUE> &map) 7027455Snate@binkert.org{ 7037455Snate@binkert.org typename m5::hash_map<KEY, VALUE>::const_iterator i = map.begin(); 7047455Snate@binkert.org typename m5::hash_map<KEY, VALUE>::const_iterator end = map.end(); 7057455Snate@binkert.org 7067455Snate@binkert.org out << "["; 7077455Snate@binkert.org for (; i != end; ++i) 7087455Snate@binkert.org out << " " << i->first << "=" << i->second; 7097455Snate@binkert.org out << " ]"; 7107455Snate@binkert.org 7117455Snate@binkert.org return out; 7127455Snate@binkert.org} 7137455Snate@binkert.org 7147039Snate@binkert.orgvoid 7157039Snate@binkert.orgSequencer::print(ostream& out) const 7167039Snate@binkert.org{ 7177039Snate@binkert.org out << "[Sequencer: " << m_version 7187039Snate@binkert.org << ", outstanding requests: " << m_outstanding_count 7197039Snate@binkert.org << ", read request table: " << m_readRequestTable 7207039Snate@binkert.org << ", write request table: " << m_writeRequestTable 7217039Snate@binkert.org << "]"; 7227039Snate@binkert.org} 7237039Snate@binkert.org 7247039Snate@binkert.org// this can be called from setState whenever coherence permissions are 7257039Snate@binkert.org// upgraded when invoked, coherence violations will be checked for the 7267039Snate@binkert.org// given block 7277039Snate@binkert.orgvoid 7287039Snate@binkert.orgSequencer::checkCoherence(const Address& addr) 7297039Snate@binkert.org{ 7306145Snate@binkert.org#ifdef CHECK_COHERENCE 7317039Snate@binkert.org g_system_ptr->checkGlobalCoherenceInvariant(addr); 7326145Snate@binkert.org#endif 7336145Snate@binkert.org} 734