Sequencer.cc revision 7056
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/gems_common/Map.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"
386845Sdrh5@cs.wisc.edu#include "mem/ruby/libruby.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"
456876Ssteve.reinhardt@amd.com#include "params/RubySequencer.hh"
466876Ssteve.reinhardt@amd.com
477055Snate@binkert.orgusing namespace std;
487055Snate@binkert.org
496876Ssteve.reinhardt@amd.comSequencer *
506876Ssteve.reinhardt@amd.comRubySequencerParams::create()
516285Snate@binkert.org{
526876Ssteve.reinhardt@amd.com    return new Sequencer(this);
536285Snate@binkert.org}
547039Snate@binkert.org
556876Ssteve.reinhardt@amd.comSequencer::Sequencer(const Params *p)
566886SBrad.Beckmann@amd.com    : RubyPort(p), deadlockCheckEvent(this)
576876Ssteve.reinhardt@amd.com{
586876Ssteve.reinhardt@amd.com    m_store_waiting_on_load_cycles = 0;
596876Ssteve.reinhardt@amd.com    m_store_waiting_on_store_cycles = 0;
606876Ssteve.reinhardt@amd.com    m_load_waiting_on_store_cycles = 0;
616876Ssteve.reinhardt@amd.com    m_load_waiting_on_load_cycles = 0;
627039Snate@binkert.org
636876Ssteve.reinhardt@amd.com    m_outstanding_count = 0;
646285Snate@binkert.org
656876Ssteve.reinhardt@amd.com    m_max_outstanding_requests = 0;
666876Ssteve.reinhardt@amd.com    m_deadlock_threshold = 0;
676876Ssteve.reinhardt@amd.com    m_instCache_ptr = NULL;
686876Ssteve.reinhardt@amd.com    m_dataCache_ptr = NULL;
696145Snate@binkert.org
706876Ssteve.reinhardt@amd.com    m_instCache_ptr = p->icache;
716876Ssteve.reinhardt@amd.com    m_dataCache_ptr = p->dcache;
726876Ssteve.reinhardt@amd.com    m_max_outstanding_requests = p->max_outstanding_requests;
736876Ssteve.reinhardt@amd.com    m_deadlock_threshold = p->deadlock_threshold;
746899SBrad.Beckmann@amd.com    m_usingRubyTester = p->using_ruby_tester;
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
957039Snate@binkert.org    Vector<Address> keys = m_readRequestTable.keys();
967039Snate@binkert.org    for (int i = 0; i < keys.size(); i++) {
977039Snate@binkert.org        SequencerRequest* request = m_readRequestTable.lookup(keys[i]);
987039Snate@binkert.org        if (current_time - request->issue_time >= m_deadlock_threshold) {
997039Snate@binkert.org            WARN_MSG("Possible Deadlock detected");
1007039Snate@binkert.org            WARN_EXPR(request);
1017039Snate@binkert.org            WARN_EXPR(m_version);
1027039Snate@binkert.org            WARN_EXPR(request->ruby_request.paddr);
1037039Snate@binkert.org            WARN_EXPR(keys.size());
1047039Snate@binkert.org            WARN_EXPR(current_time);
1057039Snate@binkert.org            WARN_EXPR(request->issue_time);
1067039Snate@binkert.org            WARN_EXPR(current_time - request->issue_time);
1077039Snate@binkert.org            ERROR_MSG("Aborting");
1087039Snate@binkert.org        }
1096145Snate@binkert.org    }
1106145Snate@binkert.org
1117039Snate@binkert.org    keys = m_writeRequestTable.keys();
1127039Snate@binkert.org    for (int i = 0; i < keys.size(); i++) {
1137039Snate@binkert.org        SequencerRequest* request = m_writeRequestTable.lookup(keys[i]);
1147039Snate@binkert.org        if (current_time - request->issue_time >= m_deadlock_threshold) {
1157039Snate@binkert.org            WARN_MSG("Possible Deadlock detected");
1167039Snate@binkert.org            WARN_EXPR(request);
1177039Snate@binkert.org            WARN_EXPR(m_version);
1187039Snate@binkert.org            WARN_EXPR(current_time);
1197039Snate@binkert.org            WARN_EXPR(request->issue_time);
1207039Snate@binkert.org            WARN_EXPR(current_time - request->issue_time);
1217039Snate@binkert.org            WARN_EXPR(keys.size());
1227039Snate@binkert.org            ERROR_MSG("Aborting");
1237039Snate@binkert.org        }
1246145Snate@binkert.org    }
1256285Snate@binkert.org
1267039Snate@binkert.org    total_outstanding += m_writeRequestTable.size();
1277039Snate@binkert.org    total_outstanding += m_readRequestTable.size();
1286145Snate@binkert.org
1297039Snate@binkert.org    assert(m_outstanding_count == total_outstanding);
1307039Snate@binkert.org
1317039Snate@binkert.org    if (m_outstanding_count > 0) {
1327039Snate@binkert.org        // If there are still outstanding requests, keep checking
1337039Snate@binkert.org        schedule(deadlockCheckEvent,
1347039Snate@binkert.org                 m_deadlock_threshold * g_eventQueue_ptr->getClock() +
1357039Snate@binkert.org                 curTick);
1367039Snate@binkert.org    }
1376145Snate@binkert.org}
1386145Snate@binkert.org
1397039Snate@binkert.orgvoid
1407039Snate@binkert.orgSequencer::printStats(ostream & out) const
1417039Snate@binkert.org{
1427039Snate@binkert.org    out << "Sequencer: " << m_name << endl
1437039Snate@binkert.org        << "  store_waiting_on_load_cycles: "
1447039Snate@binkert.org        << m_store_waiting_on_load_cycles << endl
1457039Snate@binkert.org        << "  store_waiting_on_store_cycles: "
1467039Snate@binkert.org        << m_store_waiting_on_store_cycles << endl
1477039Snate@binkert.org        << "  load_waiting_on_load_cycles: "
1487039Snate@binkert.org        << m_load_waiting_on_load_cycles << endl
1497039Snate@binkert.org        << "  load_waiting_on_store_cycles: "
1507039Snate@binkert.org        << m_load_waiting_on_store_cycles << endl;
1516859Sdrh5@cs.wisc.edu}
1526859Sdrh5@cs.wisc.edu
1537039Snate@binkert.orgvoid
1547039Snate@binkert.orgSequencer::printProgress(ostream& out) const
1557039Snate@binkert.org{
1567039Snate@binkert.org#if 0
1577039Snate@binkert.org    int total_demand = 0;
1587039Snate@binkert.org    out << "Sequencer Stats Version " << m_version << endl;
1597039Snate@binkert.org    out << "Current time = " << g_eventQueue_ptr->getTime() << endl;
1607039Snate@binkert.org    out << "---------------" << endl;
1617039Snate@binkert.org    out << "outstanding requests" << endl;
1626145Snate@binkert.org
1637039Snate@binkert.org    Vector<Address> rkeys = m_readRequestTable.keys();
1647039Snate@binkert.org    int read_size = rkeys.size();
1657039Snate@binkert.org    out << "proc " << m_version << " Read Requests = " << read_size << endl;
1666145Snate@binkert.org
1677039Snate@binkert.org    // print the request table
1687039Snate@binkert.org    for (int i = 0; i < read_size; ++i) {
1697039Snate@binkert.org        SequencerRequest *request = m_readRequestTable.lookup(rkeys[i]);
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
1777039Snate@binkert.org    Vector<Address> wkeys = m_writeRequestTable.keys();
1787039Snate@binkert.org    int write_size = wkeys.size();
1797039Snate@binkert.org    out << "proc " << m_version << " Write Requests = " << write_size << endl;
1806285Snate@binkert.org
1817039Snate@binkert.org    // print the request table
1827039Snate@binkert.org    for (int i = 0; i < write_size; ++i){
1837039Snate@binkert.org        CacheMsg &request = m_writeRequestTable.lookup(wkeys[i]);
1847039Snate@binkert.org        out << "\tRequest[ " << i << " ] = " << request.getType()
1857039Snate@binkert.org            << " Address " << wkeys[i]
1867039Snate@binkert.org            << " Posted " << request.getTime()
1877039Snate@binkert.org            << " PF " << request.getPrefetch() << endl;
1887039Snate@binkert.org        if (request.getPrefetch() == PrefetchBit_No) {
1897039Snate@binkert.org            total_demand++;
1907039Snate@binkert.org        }
1917039Snate@binkert.org    }
1927039Snate@binkert.org
1937039Snate@binkert.org    out << endl;
1947039Snate@binkert.org
1957039Snate@binkert.org    out << "Total Number Outstanding: " << m_outstanding_count << endl
1967039Snate@binkert.org        << "Total Number Demand     : " << total_demand << endl
1977039Snate@binkert.org        << "Total Number Prefetches : " << m_outstanding_count - total_demand
1987039Snate@binkert.org        << endl << endl << endl;
1997039Snate@binkert.org#endif
2006145Snate@binkert.org}
2016145Snate@binkert.org
2027039Snate@binkert.orgvoid
2037039Snate@binkert.orgSequencer::printConfig(ostream& out) const
2047039Snate@binkert.org{
2057039Snate@binkert.org    out << "Seqeuncer config: " << m_name << endl
2067039Snate@binkert.org        << "  controller: " << m_controller->getName() << endl
2077039Snate@binkert.org        << "  version: " << m_version << endl
2087039Snate@binkert.org        << "  max_outstanding_requests: " << m_max_outstanding_requests << endl
2097039Snate@binkert.org        << "  deadlock_threshold: " << m_deadlock_threshold << endl;
2106145Snate@binkert.org}
2116145Snate@binkert.org
2126145Snate@binkert.org// Insert the request on the correct request table.  Return true if
2136145Snate@binkert.org// the entry was already present.
2147039Snate@binkert.orgbool
2157039Snate@binkert.orgSequencer::insertRequest(SequencerRequest* request)
2167039Snate@binkert.org{
2177039Snate@binkert.org    int total_outstanding =
2187039Snate@binkert.org        m_writeRequestTable.size() + m_readRequestTable.size();
2196285Snate@binkert.org
2207039Snate@binkert.org    assert(m_outstanding_count == total_outstanding);
2216145Snate@binkert.org
2227039Snate@binkert.org    // See if we should schedule a deadlock check
2237039Snate@binkert.org    if (deadlockCheckEvent.scheduled() == false) {
2247039Snate@binkert.org        schedule(deadlockCheckEvent, m_deadlock_threshold + curTick);
2257039Snate@binkert.org    }
2266145Snate@binkert.org
2277039Snate@binkert.org    Address line_addr(request->ruby_request.paddr);
2287039Snate@binkert.org    line_addr.makeLineAddress();
2297039Snate@binkert.org    if ((request->ruby_request.type == RubyRequestType_ST) ||
2307039Snate@binkert.org        (request->ruby_request.type == RubyRequestType_RMW_Read) ||
2317039Snate@binkert.org        (request->ruby_request.type == RubyRequestType_RMW_Write) ||
2327039Snate@binkert.org        (request->ruby_request.type == RubyRequestType_Locked_Read) ||
2337039Snate@binkert.org        (request->ruby_request.type == RubyRequestType_Locked_Write)) {
2347039Snate@binkert.org        if (m_writeRequestTable.exist(line_addr)) {
2357039Snate@binkert.org            m_writeRequestTable.lookup(line_addr) = request;
2367039Snate@binkert.org            // return true;
2377039Snate@binkert.org
2387039Snate@binkert.org            // drh5: isn't this an error?  do you lose the initial request?
2397039Snate@binkert.org            assert(0);
2407039Snate@binkert.org        }
2417039Snate@binkert.org        m_writeRequestTable.allocate(line_addr);
2427039Snate@binkert.org        m_writeRequestTable.lookup(line_addr) = request;
2437039Snate@binkert.org        m_outstanding_count++;
2447039Snate@binkert.org    } else {
2457039Snate@binkert.org        if (m_readRequestTable.exist(line_addr)) {
2467039Snate@binkert.org            m_readRequestTable.lookup(line_addr) = request;
2477039Snate@binkert.org            // return true;
2487039Snate@binkert.org
2497039Snate@binkert.org            // drh5: isn't this an error?  do you lose the initial request?
2507039Snate@binkert.org            assert(0);
2517039Snate@binkert.org        }
2527039Snate@binkert.org        m_readRequestTable.allocate(line_addr);
2537039Snate@binkert.org        m_readRequestTable.lookup(line_addr) = request;
2547039Snate@binkert.org        m_outstanding_count++;
2556145Snate@binkert.org    }
2566145Snate@binkert.org
2577039Snate@binkert.org    g_system_ptr->getProfiler()->sequencerRequests(m_outstanding_count);
2586145Snate@binkert.org
2597039Snate@binkert.org    total_outstanding = m_writeRequestTable.size() + m_readRequestTable.size();
2607039Snate@binkert.org    assert(m_outstanding_count == total_outstanding);
2616145Snate@binkert.org
2627039Snate@binkert.org    return false;
2636145Snate@binkert.org}
2646145Snate@binkert.org
2657039Snate@binkert.orgvoid
2667039Snate@binkert.orgSequencer::removeRequest(SequencerRequest* srequest)
2677039Snate@binkert.org{
2687039Snate@binkert.org    assert(m_outstanding_count ==
2697039Snate@binkert.org           m_writeRequestTable.size() + m_readRequestTable.size());
2706145Snate@binkert.org
2717039Snate@binkert.org    const RubyRequest & ruby_request = srequest->ruby_request;
2727039Snate@binkert.org    Address line_addr(ruby_request.paddr);
2737039Snate@binkert.org    line_addr.makeLineAddress();
2747039Snate@binkert.org    if ((ruby_request.type == RubyRequestType_ST) ||
2757039Snate@binkert.org        (ruby_request.type == RubyRequestType_RMW_Read) ||
2767039Snate@binkert.org        (ruby_request.type == RubyRequestType_RMW_Write) ||
2777039Snate@binkert.org        (ruby_request.type == RubyRequestType_Locked_Read) ||
2787039Snate@binkert.org        (ruby_request.type == RubyRequestType_Locked_Write)) {
2797039Snate@binkert.org        m_writeRequestTable.deallocate(line_addr);
2807039Snate@binkert.org    } else {
2817039Snate@binkert.org        m_readRequestTable.deallocate(line_addr);
2827039Snate@binkert.org    }
2837039Snate@binkert.org    m_outstanding_count--;
2846285Snate@binkert.org
2857039Snate@binkert.org    assert(m_outstanding_count == m_writeRequestTable.size() + m_readRequestTable.size());
2866145Snate@binkert.org}
2876145Snate@binkert.org
2887039Snate@binkert.orgvoid
2897039Snate@binkert.orgSequencer::writeCallback(const Address& address, DataBlock& data)
2907039Snate@binkert.org{
2917039Snate@binkert.org    assert(address == line_address(address));
2927039Snate@binkert.org    assert(m_writeRequestTable.exist(line_address(address)));
2936145Snate@binkert.org
2947039Snate@binkert.org    SequencerRequest* request = m_writeRequestTable.lookup(address);
2956145Snate@binkert.org
2967039Snate@binkert.org    removeRequest(request);
2976846Spdudnik@cs.wisc.edu
2987039Snate@binkert.org    assert((request->ruby_request.type == RubyRequestType_ST) ||
2997039Snate@binkert.org           (request->ruby_request.type == RubyRequestType_RMW_Read) ||
3007039Snate@binkert.org           (request->ruby_request.type == RubyRequestType_RMW_Write) ||
3017039Snate@binkert.org           (request->ruby_request.type == RubyRequestType_Locked_Read) ||
3027039Snate@binkert.org           (request->ruby_request.type == RubyRequestType_Locked_Write));
3036145Snate@binkert.org
3047039Snate@binkert.org    if (request->ruby_request.type == RubyRequestType_Locked_Read) {
3057039Snate@binkert.org        m_dataCache_ptr->setLocked(address, m_version);
3067039Snate@binkert.org    } else if (request->ruby_request.type == RubyRequestType_RMW_Read) {
3077039Snate@binkert.org        m_controller->blockOnQueue(address, m_mandatory_q_ptr);
3087039Snate@binkert.org    } else if (request->ruby_request.type == RubyRequestType_RMW_Write) {
3097039Snate@binkert.org        m_controller->unblock(address);
3107039Snate@binkert.org    }
3116863Sdrh5@cs.wisc.edu
3127039Snate@binkert.org    hitCallback(request, data);
3136145Snate@binkert.org}
3146145Snate@binkert.org
3157039Snate@binkert.orgvoid
3167039Snate@binkert.orgSequencer::readCallback(const Address& address, DataBlock& data)
3177039Snate@binkert.org{
3187039Snate@binkert.org    assert(address == line_address(address));
3197039Snate@binkert.org    assert(m_readRequestTable.exist(line_address(address)));
3206145Snate@binkert.org
3217039Snate@binkert.org    SequencerRequest* request = m_readRequestTable.lookup(address);
3227039Snate@binkert.org    removeRequest(request);
3236145Snate@binkert.org
3247039Snate@binkert.org    assert((request->ruby_request.type == RubyRequestType_LD) ||
3257039Snate@binkert.org           (request->ruby_request.type == RubyRequestType_RMW_Read) ||
3267039Snate@binkert.org           (request->ruby_request.type == RubyRequestType_IFETCH));
3276285Snate@binkert.org
3287039Snate@binkert.org    hitCallback(request, data);
3296145Snate@binkert.org}
3306145Snate@binkert.org
3317039Snate@binkert.orgvoid
3327039Snate@binkert.orgSequencer::hitCallback(SequencerRequest* srequest, DataBlock& data)
3337039Snate@binkert.org{
3347039Snate@binkert.org    const RubyRequest & ruby_request = srequest->ruby_request;
3357039Snate@binkert.org    Address request_address(ruby_request.paddr);
3367039Snate@binkert.org    Address request_line_address(ruby_request.paddr);
3377039Snate@binkert.org    request_line_address.makeLineAddress();
3387039Snate@binkert.org    RubyRequestType type = ruby_request.type;
3397039Snate@binkert.org    Time issued_time = srequest->issue_time;
3406145Snate@binkert.org
3417039Snate@binkert.org    // Set this cache entry to the most recently used
3427039Snate@binkert.org    if (type == RubyRequestType_IFETCH) {
3437039Snate@binkert.org        if (m_instCache_ptr->isTagPresent(request_line_address))
3447039Snate@binkert.org            m_instCache_ptr->setMRU(request_line_address);
3457039Snate@binkert.org    } else {
3467039Snate@binkert.org        if (m_dataCache_ptr->isTagPresent(request_line_address))
3477039Snate@binkert.org            m_dataCache_ptr->setMRU(request_line_address);
3487039Snate@binkert.org    }
3496145Snate@binkert.org
3507039Snate@binkert.org    assert(g_eventQueue_ptr->getTime() >= issued_time);
3517039Snate@binkert.org    Time miss_latency = g_eventQueue_ptr->getTime() - issued_time;
3526145Snate@binkert.org
3537039Snate@binkert.org    // Profile the miss latency for all non-zero demand misses
3547039Snate@binkert.org    if (miss_latency != 0) {
3557039Snate@binkert.org        g_system_ptr->getProfiler()->missLatency(miss_latency, type);
3566285Snate@binkert.org
3577039Snate@binkert.org        if (Debug::getProtocolTrace()) {
3587039Snate@binkert.org            g_system_ptr->getProfiler()->
3597039Snate@binkert.org                profileTransition("Seq", m_version,
3607039Snate@binkert.org                                  Address(ruby_request.paddr), "", "Done", "",
3617039Snate@binkert.org                                  csprintf("%d cycles", miss_latency));
3627039Snate@binkert.org        }
3636285Snate@binkert.org    }
3647039Snate@binkert.org#if 0
3657039Snate@binkert.org    if (request.getPrefetch() == PrefetchBit_Yes) {
3667039Snate@binkert.org        return; // Ignore the prefetch
3677039Snate@binkert.org    }
3687039Snate@binkert.org#endif
3696285Snate@binkert.org
3707039Snate@binkert.org    // update the data
3717039Snate@binkert.org    if (ruby_request.data != NULL) {
3727039Snate@binkert.org        if ((type == RubyRequestType_LD) ||
3737039Snate@binkert.org            (type == RubyRequestType_IFETCH) ||
3747039Snate@binkert.org            (type == RubyRequestType_RMW_Read) ||
3757039Snate@binkert.org            (type == RubyRequestType_Locked_Read)) {
3767023SBrad.Beckmann@amd.com
3777039Snate@binkert.org            memcpy(ruby_request.data,
3787039Snate@binkert.org                   data.getData(request_address.getOffset(), ruby_request.len),
3797039Snate@binkert.org                   ruby_request.len);
3807039Snate@binkert.org        } else {
3817039Snate@binkert.org            data.setData(ruby_request.data, request_address.getOffset(),
3827039Snate@binkert.org                         ruby_request.len);
3837039Snate@binkert.org        }
3846285Snate@binkert.org    } else {
3857039Snate@binkert.org        DPRINTF(MemoryAccess,
3867039Snate@binkert.org                "WARNING.  Data not transfered from Ruby to M5 for type %s\n",
3877039Snate@binkert.org                RubyRequestType_to_string(type));
3887039Snate@binkert.org    }
3897023SBrad.Beckmann@amd.com
3907039Snate@binkert.org    // If using the RubyTester, update the RubyTester sender state's
3917039Snate@binkert.org    // subBlock with the recieved data.  The tester will later access
3927039Snate@binkert.org    // this state.
3937039Snate@binkert.org    // Note: RubyPort will access it's sender state before the
3947039Snate@binkert.org    // RubyTester.
3957039Snate@binkert.org    if (m_usingRubyTester) {
3967039Snate@binkert.org        RubyPort::SenderState *requestSenderState =
3977039Snate@binkert.org            safe_cast<RubyPort::SenderState*>(ruby_request.pkt->senderState);
3987039Snate@binkert.org        RubyTester::SenderState* testerSenderState =
3997039Snate@binkert.org            safe_cast<RubyTester::SenderState*>(requestSenderState->saved);
4007039Snate@binkert.org        testerSenderState->subBlock->mergeFrom(data);
4017039Snate@binkert.org    }
4027023SBrad.Beckmann@amd.com
4037039Snate@binkert.org    ruby_hit_callback(ruby_request.pkt);
4047039Snate@binkert.org    delete srequest;
4056285Snate@binkert.org}
4066285Snate@binkert.org
4076285Snate@binkert.org// Returns true if the sequencer already has a load or store outstanding
4087039Snate@binkert.orgRequestStatus
4097039Snate@binkert.orgSequencer::getRequestStatus(const RubyRequest& request)
4107039Snate@binkert.org{
4117039Snate@binkert.org    bool is_outstanding_store =
4127039Snate@binkert.org        m_writeRequestTable.exist(line_address(Address(request.paddr)));
4137039Snate@binkert.org    bool is_outstanding_load =
4147039Snate@binkert.org        m_readRequestTable.exist(line_address(Address(request.paddr)));
4157039Snate@binkert.org    if (is_outstanding_store) {
4167039Snate@binkert.org        if ((request.type == RubyRequestType_LD) ||
4177039Snate@binkert.org            (request.type == RubyRequestType_IFETCH) ||
4187039Snate@binkert.org            (request.type == RubyRequestType_RMW_Read)) {
4197039Snate@binkert.org            m_store_waiting_on_load_cycles++;
4207039Snate@binkert.org        } else {
4217039Snate@binkert.org            m_store_waiting_on_store_cycles++;
4227039Snate@binkert.org        }
4237039Snate@binkert.org        return RequestStatus_Aliased;
4247039Snate@binkert.org    } else if (is_outstanding_load) {
4257039Snate@binkert.org        if ((request.type == RubyRequestType_ST) ||
4267039Snate@binkert.org            (request.type == RubyRequestType_RMW_Write)) {
4277039Snate@binkert.org            m_load_waiting_on_store_cycles++;
4287039Snate@binkert.org        } else {
4297039Snate@binkert.org            m_load_waiting_on_load_cycles++;
4307039Snate@binkert.org        }
4317039Snate@binkert.org        return RequestStatus_Aliased;
4326859Sdrh5@cs.wisc.edu    }
4337039Snate@binkert.org
4347039Snate@binkert.org    if (m_outstanding_count >= m_max_outstanding_requests) {
4357039Snate@binkert.org        return RequestStatus_BufferFull;
4366859Sdrh5@cs.wisc.edu    }
4376145Snate@binkert.org
4387039Snate@binkert.org    return RequestStatus_Ready;
4396145Snate@binkert.org}
4406145Snate@binkert.org
4417039Snate@binkert.orgbool
4427039Snate@binkert.orgSequencer::empty() const
4437039Snate@binkert.org{
4447039Snate@binkert.org    return m_writeRequestTable.size() == 0 && m_readRequestTable.size() == 0;
4456145Snate@binkert.org}
4466145Snate@binkert.org
4477039Snate@binkert.orgRequestStatus
4487039Snate@binkert.orgSequencer::makeRequest(const RubyRequest &request)
4497039Snate@binkert.org{
4507039Snate@binkert.org    assert(Address(request.paddr).getOffset() + request.len <=
4517039Snate@binkert.org           RubySystem::getBlockSizeBytes());
4527039Snate@binkert.org    RequestStatus status = getRequestStatus(request);
4537039Snate@binkert.org    if (status != RequestStatus_Ready)
4547039Snate@binkert.org        return status;
4556349Spdudnik@gmail.com
4567039Snate@binkert.org    SequencerRequest *srequest =
4577039Snate@binkert.org        new SequencerRequest(request, g_eventQueue_ptr->getTime());
4586285Snate@binkert.org    bool found = insertRequest(srequest);
4597039Snate@binkert.org    if (found) {
4607039Snate@binkert.org        panic("Sequencer::makeRequest should never be called if the "
4617039Snate@binkert.org              "request is already outstanding\n");
4627039Snate@binkert.org        return RequestStatus_NULL;
4637039Snate@binkert.org    }
4647023SBrad.Beckmann@amd.com
4657039Snate@binkert.org    if (request.type == RubyRequestType_Locked_Write) {
4667039Snate@binkert.org        // NOTE: it is OK to check the locked flag here as the
4677039Snate@binkert.org        // mandatory queue will be checked first ensuring that nothing
4687039Snate@binkert.org        // comes between checking the flag and servicing the store.
4697023SBrad.Beckmann@amd.com
4707039Snate@binkert.org        Address line_addr = line_address(Address(request.paddr));
4717039Snate@binkert.org        if (!m_dataCache_ptr->isLocked(line_addr, m_version)) {
4727039Snate@binkert.org            removeRequest(srequest);
4737039Snate@binkert.org            if (Debug::getProtocolTrace()) {
4747039Snate@binkert.org                g_system_ptr->getProfiler()->
4757039Snate@binkert.org                    profileTransition("Seq", m_version,
4767039Snate@binkert.org                                      Address(request.paddr),
4777039Snate@binkert.org                                      "", "SC Fail", "",
4787039Snate@binkert.org                                      RubyRequestType_to_string(request.type));
4797023SBrad.Beckmann@amd.com            }
4807023SBrad.Beckmann@amd.com            return RequestStatus_LlscFailed;
4817039Snate@binkert.org        } else {
4827039Snate@binkert.org            m_dataCache_ptr->clearLocked(line_addr);
4836349Spdudnik@gmail.com        }
4847039Snate@binkert.org    }
4857039Snate@binkert.org    issueRequest(request);
4866145Snate@binkert.org
4877039Snate@binkert.org    // TODO: issue hardware prefetches here
4887039Snate@binkert.org    return RequestStatus_Issued;
4896145Snate@binkert.org}
4906145Snate@binkert.org
4917039Snate@binkert.orgvoid
4927039Snate@binkert.orgSequencer::issueRequest(const RubyRequest& request)
4937039Snate@binkert.org{
4947039Snate@binkert.org    // TODO: get rid of CacheMsg, CacheRequestType, and
4957039Snate@binkert.org    // AccessModeTYpe, & have SLICC use RubyRequest and subtypes
4967039Snate@binkert.org    // natively
4977039Snate@binkert.org    CacheRequestType ctype;
4987039Snate@binkert.org    switch(request.type) {
4997039Snate@binkert.org      case RubyRequestType_IFETCH:
5007039Snate@binkert.org        ctype = CacheRequestType_IFETCH;
5017039Snate@binkert.org        break;
5027039Snate@binkert.org      case RubyRequestType_LD:
5037039Snate@binkert.org        ctype = CacheRequestType_LD;
5047039Snate@binkert.org        break;
5057039Snate@binkert.org      case RubyRequestType_ST:
5067039Snate@binkert.org        ctype = CacheRequestType_ST;
5077039Snate@binkert.org        break;
5087039Snate@binkert.org      case RubyRequestType_Locked_Read:
5097039Snate@binkert.org      case RubyRequestType_Locked_Write:
5107039Snate@binkert.org        ctype = CacheRequestType_ATOMIC;
5117039Snate@binkert.org        break;
5127039Snate@binkert.org      case RubyRequestType_RMW_Read:
5137039Snate@binkert.org        ctype = CacheRequestType_ATOMIC;
5147039Snate@binkert.org        break;
5157039Snate@binkert.org      case RubyRequestType_RMW_Write:
5167039Snate@binkert.org        ctype = CacheRequestType_ATOMIC;
5177039Snate@binkert.org        break;
5187039Snate@binkert.org      default:
5197039Snate@binkert.org        assert(0);
5207039Snate@binkert.org    }
5216285Snate@binkert.org
5227039Snate@binkert.org    AccessModeType amtype;
5237039Snate@binkert.org    switch(request.access_mode){
5247039Snate@binkert.org      case RubyAccessMode_User:
5257039Snate@binkert.org        amtype = AccessModeType_UserMode;
5267039Snate@binkert.org        break;
5277039Snate@binkert.org      case RubyAccessMode_Supervisor:
5287039Snate@binkert.org        amtype = AccessModeType_SupervisorMode;
5297039Snate@binkert.org        break;
5307039Snate@binkert.org      case RubyAccessMode_Device:
5317039Snate@binkert.org        amtype = AccessModeType_UserMode;
5327039Snate@binkert.org        break;
5337039Snate@binkert.org      default:
5347039Snate@binkert.org        assert(0);
5357039Snate@binkert.org    }
5366285Snate@binkert.org
5377039Snate@binkert.org    Address line_addr(request.paddr);
5387039Snate@binkert.org    line_addr.makeLineAddress();
5397039Snate@binkert.org    CacheMsg msg(line_addr, Address(request.paddr), ctype,
5407039Snate@binkert.org                 Address(request.pc), amtype, request.len, PrefetchBit_No,
5417039Snate@binkert.org                 request.proc_id);
5426285Snate@binkert.org
5437039Snate@binkert.org    if (Debug::getProtocolTrace()) {
5447039Snate@binkert.org        g_system_ptr->getProfiler()->
5457039Snate@binkert.org            profileTransition("Seq", m_version, Address(request.paddr),
5467039Snate@binkert.org                              "", "Begin", "",
5477039Snate@binkert.org                              RubyRequestType_to_string(request.type));
5487039Snate@binkert.org    }
5496285Snate@binkert.org
5507039Snate@binkert.org    if (g_system_ptr->getTracer()->traceEnabled()) {
5517039Snate@binkert.org        g_system_ptr->getTracer()->
5527039Snate@binkert.org            traceRequest(this, line_addr, Address(request.pc),
5537039Snate@binkert.org                         request.type, g_eventQueue_ptr->getTime());
5547039Snate@binkert.org    }
5556285Snate@binkert.org
5567039Snate@binkert.org    Time latency = 0;  // initialzed to an null value
5576285Snate@binkert.org
5587039Snate@binkert.org    if (request.type == RubyRequestType_IFETCH)
5597039Snate@binkert.org        latency = m_instCache_ptr->getLatency();
5607039Snate@binkert.org    else
5617039Snate@binkert.org        latency = m_dataCache_ptr->getLatency();
5626285Snate@binkert.org
5637039Snate@binkert.org    // Send the message to the cache controller
5647039Snate@binkert.org    assert(latency > 0);
5656145Snate@binkert.org
5667039Snate@binkert.org    assert(m_mandatory_q_ptr != NULL);
5677039Snate@binkert.org    m_mandatory_q_ptr->enqueue(msg, latency);
5686145Snate@binkert.org}
5696145Snate@binkert.org
5707039Snate@binkert.org#if 0
5717039Snate@binkert.orgbool
5727039Snate@binkert.orgSequencer::tryCacheAccess(const Address& addr, CacheRequestType type,
5737039Snate@binkert.org                          AccessModeType access_mode,
5747039Snate@binkert.org                          int size, DataBlock*& data_ptr)
5757039Snate@binkert.org{
5767039Snate@binkert.org    CacheMemory *cache =
5777039Snate@binkert.org        (type == CacheRequestType_IFETCH) ? m_instCache_ptr : m_dataCache_ptr;
5787039Snate@binkert.org
5797039Snate@binkert.org    return cache->tryCacheAccess(line_address(addr), type, data_ptr);
5807039Snate@binkert.org}
5817039Snate@binkert.org#endif
5827039Snate@binkert.org
5837039Snate@binkert.orgvoid
5847039Snate@binkert.orgSequencer::print(ostream& out) const
5857039Snate@binkert.org{
5867039Snate@binkert.org    out << "[Sequencer: " << m_version
5877039Snate@binkert.org        << ", outstanding requests: " << m_outstanding_count
5887039Snate@binkert.org        << ", read request table: " << m_readRequestTable
5897039Snate@binkert.org        << ", write request table: " << m_writeRequestTable
5907039Snate@binkert.org        << "]";
5917039Snate@binkert.org}
5927039Snate@binkert.org
5937039Snate@binkert.org// this can be called from setState whenever coherence permissions are
5947039Snate@binkert.org// upgraded when invoked, coherence violations will be checked for the
5957039Snate@binkert.org// given block
5967039Snate@binkert.orgvoid
5977039Snate@binkert.orgSequencer::checkCoherence(const Address& addr)
5987039Snate@binkert.org{
5996145Snate@binkert.org#ifdef CHECK_COHERENCE
6007039Snate@binkert.org    g_system_ptr->checkGlobalCoherenceInvariant(addr);
6016145Snate@binkert.org#endif
6026145Snate@binkert.org}
603