Sequencer.cc revision 11019
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
2910467Sandreas.hansson@arm.com#include "arch/x86/ldstflags.hh"
308229Snate@binkert.org#include "base/misc.hh"
317056Snate@binkert.org#include "base/str.hh"
327632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/RubyTester.hh"
338232Snate@binkert.org#include "debug/MemoryAccess.hh"
348232Snate@binkert.org#include "debug/ProtocolTrace.hh"
358615Snilay@cs.wisc.edu#include "debug/RubySequencer.hh"
369104Shestness@cs.utexas.edu#include "debug/RubyStats.hh"
378615Snilay@cs.wisc.edu#include "mem/protocol/PrefetchBit.hh"
388615Snilay@cs.wisc.edu#include "mem/protocol/RubyAccessMode.hh"
397039Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh"
408229Snate@binkert.org#include "mem/ruby/slicc_interface/RubyRequest.hh"
416154Snate@binkert.org#include "mem/ruby/system/Sequencer.hh"
426154Snate@binkert.org#include "mem/ruby/system/System.hh"
437550SBrad.Beckmann@amd.com#include "mem/packet.hh"
4410467Sandreas.hansson@arm.com#include "sim/system.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)
5510012Snilay@cs.wisc.edu    : RubyPort(p), m_IncompleteTimes(MachineType_NUM), deadlockCheckEvent(this)
566876Ssteve.reinhardt@amd.com{
576876Ssteve.reinhardt@amd.com    m_outstanding_count = 0;
586285Snate@binkert.org
596876Ssteve.reinhardt@amd.com    m_instCache_ptr = p->icache;
606876Ssteve.reinhardt@amd.com    m_dataCache_ptr = p->dcache;
6111019Sjthestness@gmail.com    m_data_cache_hit_latency = p->dcache_hit_latency;
6211019Sjthestness@gmail.com    m_inst_cache_hit_latency = p->icache_hit_latency;
636876Ssteve.reinhardt@amd.com    m_max_outstanding_requests = p->max_outstanding_requests;
646876Ssteve.reinhardt@amd.com    m_deadlock_threshold = p->deadlock_threshold;
656899SBrad.Beckmann@amd.com
666876Ssteve.reinhardt@amd.com    assert(m_max_outstanding_requests > 0);
676876Ssteve.reinhardt@amd.com    assert(m_deadlock_threshold > 0);
686876Ssteve.reinhardt@amd.com    assert(m_instCache_ptr != NULL);
696876Ssteve.reinhardt@amd.com    assert(m_dataCache_ptr != NULL);
7011019Sjthestness@gmail.com    assert(m_data_cache_hit_latency > 0);
7111019Sjthestness@gmail.com    assert(m_inst_cache_hit_latency > 0);
728171Stushar@csail.mit.edu
738171Stushar@csail.mit.edu    m_usingNetworkTester = p->using_network_tester;
746145Snate@binkert.org}
756145Snate@binkert.org
767039Snate@binkert.orgSequencer::~Sequencer()
777039Snate@binkert.org{
786145Snate@binkert.org}
796145Snate@binkert.org
807039Snate@binkert.orgvoid
817039Snate@binkert.orgSequencer::wakeup()
827039Snate@binkert.org{
8310913Sandreas.sandberg@arm.com    assert(drainState() != DrainState::Draining);
849245Shestness@cs.wisc.edu
857039Snate@binkert.org    // Check for deadlock of any of the requests
869501Snilay@cs.wisc.edu    Cycles current_time = curCycle();
876145Snate@binkert.org
887039Snate@binkert.org    // Check across all outstanding requests
897039Snate@binkert.org    int total_outstanding = 0;
906285Snate@binkert.org
917455Snate@binkert.org    RequestTable::iterator read = m_readRequestTable.begin();
927455Snate@binkert.org    RequestTable::iterator read_end = m_readRequestTable.end();
937455Snate@binkert.org    for (; read != read_end; ++read) {
947455Snate@binkert.org        SequencerRequest* request = read->second;
957455Snate@binkert.org        if (current_time - request->issue_time < m_deadlock_threshold)
967455Snate@binkert.org            continue;
977455Snate@binkert.org
987805Snilay@cs.wisc.edu        panic("Possible Deadlock detected. Aborting!\n"
997921SBrad.Beckmann@amd.com             "version: %d request.paddr: 0x%x m_readRequestTable: %d "
1007805Snilay@cs.wisc.edu             "current time: %u issue_time: %d difference: %d\n", m_version,
1018615Snilay@cs.wisc.edu             Address(request->pkt->getAddr()), m_readRequestTable.size(),
1029467Smalek.musleh@gmail.com              current_time * clockPeriod(), request->issue_time * clockPeriod(),
1039467Smalek.musleh@gmail.com              (current_time * clockPeriod()) - (request->issue_time * clockPeriod()));
1046145Snate@binkert.org    }
1056145Snate@binkert.org
1067455Snate@binkert.org    RequestTable::iterator write = m_writeRequestTable.begin();
1077455Snate@binkert.org    RequestTable::iterator write_end = m_writeRequestTable.end();
1087455Snate@binkert.org    for (; write != write_end; ++write) {
1097455Snate@binkert.org        SequencerRequest* request = write->second;
1107455Snate@binkert.org        if (current_time - request->issue_time < m_deadlock_threshold)
1117455Snate@binkert.org            continue;
1127455Snate@binkert.org
1137805Snilay@cs.wisc.edu        panic("Possible Deadlock detected. Aborting!\n"
1147921SBrad.Beckmann@amd.com             "version: %d request.paddr: 0x%x m_writeRequestTable: %d "
1157805Snilay@cs.wisc.edu             "current time: %u issue_time: %d difference: %d\n", m_version,
1168615Snilay@cs.wisc.edu             Address(request->pkt->getAddr()), m_writeRequestTable.size(),
1179467Smalek.musleh@gmail.com              current_time * clockPeriod(), request->issue_time * clockPeriod(),
1189467Smalek.musleh@gmail.com              (current_time * clockPeriod()) - (request->issue_time * clockPeriod()));
1196145Snate@binkert.org    }
1206285Snate@binkert.org
1217039Snate@binkert.org    total_outstanding += m_writeRequestTable.size();
1227039Snate@binkert.org    total_outstanding += m_readRequestTable.size();
1236145Snate@binkert.org
1247039Snate@binkert.org    assert(m_outstanding_count == total_outstanding);
1257039Snate@binkert.org
1267039Snate@binkert.org    if (m_outstanding_count > 0) {
1277039Snate@binkert.org        // If there are still outstanding requests, keep checking
1289465Snilay@cs.wisc.edu        schedule(deadlockCheckEvent, clockEdge(m_deadlock_threshold));
1297039Snate@binkert.org    }
1306145Snate@binkert.org}
1316145Snate@binkert.org
13210012Snilay@cs.wisc.eduvoid Sequencer::resetStats()
1339598Snilay@cs.wisc.edu{
13410012Snilay@cs.wisc.edu    m_latencyHist.reset();
13510012Snilay@cs.wisc.edu    m_hitLatencyHist.reset();
13610012Snilay@cs.wisc.edu    m_missLatencyHist.reset();
1379773Snilay@cs.wisc.edu    for (int i = 0; i < RubyRequestType_NUM; i++) {
13810012Snilay@cs.wisc.edu        m_typeLatencyHist[i]->reset();
13910012Snilay@cs.wisc.edu        m_hitTypeLatencyHist[i]->reset();
14010012Snilay@cs.wisc.edu        m_missTypeLatencyHist[i]->reset();
1419773Snilay@cs.wisc.edu        for (int j = 0; j < MachineType_NUM; j++) {
14210012Snilay@cs.wisc.edu            m_hitTypeMachLatencyHist[i][j]->reset();
14310012Snilay@cs.wisc.edu            m_missTypeMachLatencyHist[i][j]->reset();
1449773Snilay@cs.wisc.edu        }
1459773Snilay@cs.wisc.edu    }
1469773Snilay@cs.wisc.edu
14710012Snilay@cs.wisc.edu    for (int i = 0; i < MachineType_NUM; i++) {
14810012Snilay@cs.wisc.edu        m_missMachLatencyHist[i]->reset();
14910012Snilay@cs.wisc.edu        m_hitMachLatencyHist[i]->reset();
1509773Snilay@cs.wisc.edu
15110012Snilay@cs.wisc.edu        m_IssueToInitialDelayHist[i]->reset();
15210012Snilay@cs.wisc.edu        m_InitialToForwardDelayHist[i]->reset();
15310012Snilay@cs.wisc.edu        m_ForwardToFirstResponseDelayHist[i]->reset();
15410012Snilay@cs.wisc.edu        m_FirstResponseToCompletionDelayHist[i]->reset();
1559773Snilay@cs.wisc.edu
1569773Snilay@cs.wisc.edu        m_IncompleteTimes[i] = 0;
1579773Snilay@cs.wisc.edu    }
1589598Snilay@cs.wisc.edu}
1599598Snilay@cs.wisc.edu
1607039Snate@binkert.orgvoid
1617039Snate@binkert.orgSequencer::printProgress(ostream& out) const
1627039Snate@binkert.org{
1637039Snate@binkert.org#if 0
1647039Snate@binkert.org    int total_demand = 0;
1657039Snate@binkert.org    out << "Sequencer Stats Version " << m_version << endl;
16610919Sbrandon.potter@amd.com    out << "Current time = " << m_ruby_system->getTime() << endl;
1677039Snate@binkert.org    out << "---------------" << endl;
1687039Snate@binkert.org    out << "outstanding requests" << endl;
1696145Snate@binkert.org
1707455Snate@binkert.org    out << "proc " << m_Read
1717455Snate@binkert.org        << " version Requests = " << m_readRequestTable.size() << endl;
1726145Snate@binkert.org
1737039Snate@binkert.org    // print the request table
1747455Snate@binkert.org    RequestTable::iterator read = m_readRequestTable.begin();
1757455Snate@binkert.org    RequestTable::iterator read_end = m_readRequestTable.end();
1767455Snate@binkert.org    for (; read != read_end; ++read) {
1777455Snate@binkert.org        SequencerRequest* request = read->second;
1787039Snate@binkert.org        out << "\tRequest[ " << i << " ] = " << request->type
1797039Snate@binkert.org            << " Address " << rkeys[i]
1807039Snate@binkert.org            << " Posted " << request->issue_time
1817039Snate@binkert.org            << " PF " << PrefetchBit_No << endl;
1826145Snate@binkert.org        total_demand++;
1837039Snate@binkert.org    }
1846145Snate@binkert.org
1857455Snate@binkert.org    out << "proc " << m_version
1867455Snate@binkert.org        << " Write Requests = " << m_writeRequestTable.size << endl;
1876285Snate@binkert.org
1887039Snate@binkert.org    // print the request table
1897455Snate@binkert.org    RequestTable::iterator write = m_writeRequestTable.begin();
1907455Snate@binkert.org    RequestTable::iterator write_end = m_writeRequestTable.end();
1917455Snate@binkert.org    for (; write != write_end; ++write) {
1927455Snate@binkert.org        SequencerRequest* request = write->second;
1937039Snate@binkert.org        out << "\tRequest[ " << i << " ] = " << request.getType()
1947039Snate@binkert.org            << " Address " << wkeys[i]
1957039Snate@binkert.org            << " Posted " << request.getTime()
1967039Snate@binkert.org            << " PF " << request.getPrefetch() << endl;
1977039Snate@binkert.org        if (request.getPrefetch() == PrefetchBit_No) {
1987039Snate@binkert.org            total_demand++;
1997039Snate@binkert.org        }
2007039Snate@binkert.org    }
2017039Snate@binkert.org
2027039Snate@binkert.org    out << endl;
2037039Snate@binkert.org
2047039Snate@binkert.org    out << "Total Number Outstanding: " << m_outstanding_count << endl
2057039Snate@binkert.org        << "Total Number Demand     : " << total_demand << endl
2067039Snate@binkert.org        << "Total Number Prefetches : " << m_outstanding_count - total_demand
2077039Snate@binkert.org        << endl << endl << endl;
2087039Snate@binkert.org#endif
2096145Snate@binkert.org}
2106145Snate@binkert.org
2116145Snate@binkert.org// Insert the request on the correct request table.  Return true if
2126145Snate@binkert.org// the entry was already present.
2138615Snilay@cs.wisc.eduRequestStatus
2148615Snilay@cs.wisc.eduSequencer::insertRequest(PacketPtr pkt, RubyRequestType request_type)
2157039Snate@binkert.org{
2168641Snate@binkert.org    assert(m_outstanding_count ==
2178641Snate@binkert.org        (m_writeRequestTable.size() + m_readRequestTable.size()));
2186145Snate@binkert.org
2197039Snate@binkert.org    // See if we should schedule a deadlock check
2209342SAndreas.Sandberg@arm.com    if (!deadlockCheckEvent.scheduled() &&
22110913Sandreas.sandberg@arm.com        drainState() != DrainState::Draining) {
2229465Snilay@cs.wisc.edu        schedule(deadlockCheckEvent, clockEdge(m_deadlock_threshold));
2237039Snate@binkert.org    }
2246145Snate@binkert.org
2258615Snilay@cs.wisc.edu    Address line_addr(pkt->getAddr());
2267039Snate@binkert.org    line_addr.makeLineAddress();
2279224Sandreas.hansson@arm.com    // Create a default entry, mapping the address to NULL, the cast is
2289224Sandreas.hansson@arm.com    // there to make gcc 4.4 happy
2299224Sandreas.hansson@arm.com    RequestTable::value_type default_entry(line_addr,
2309224Sandreas.hansson@arm.com                                           (SequencerRequest*) NULL);
2319224Sandreas.hansson@arm.com
2328615Snilay@cs.wisc.edu    if ((request_type == RubyRequestType_ST) ||
2338615Snilay@cs.wisc.edu        (request_type == RubyRequestType_RMW_Read) ||
2348615Snilay@cs.wisc.edu        (request_type == RubyRequestType_RMW_Write) ||
2358615Snilay@cs.wisc.edu        (request_type == RubyRequestType_Load_Linked) ||
2368615Snilay@cs.wisc.edu        (request_type == RubyRequestType_Store_Conditional) ||
2378615Snilay@cs.wisc.edu        (request_type == RubyRequestType_Locked_RMW_Read) ||
2388615Snilay@cs.wisc.edu        (request_type == RubyRequestType_Locked_RMW_Write) ||
2398615Snilay@cs.wisc.edu        (request_type == RubyRequestType_FLUSH)) {
2408615Snilay@cs.wisc.edu
2418615Snilay@cs.wisc.edu        // Check if there is any outstanding read request for the same
2428615Snilay@cs.wisc.edu        // cache line.
2438615Snilay@cs.wisc.edu        if (m_readRequestTable.count(line_addr) > 0) {
24410012Snilay@cs.wisc.edu            m_store_waiting_on_load++;
2458615Snilay@cs.wisc.edu            return RequestStatus_Aliased;
2468615Snilay@cs.wisc.edu        }
2478615Snilay@cs.wisc.edu
2487455Snate@binkert.org        pair<RequestTable::iterator, bool> r =
2499224Sandreas.hansson@arm.com            m_writeRequestTable.insert(default_entry);
2508615Snilay@cs.wisc.edu        if (r.second) {
2518615Snilay@cs.wisc.edu            RequestTable::iterator i = r.first;
2529465Snilay@cs.wisc.edu            i->second = new SequencerRequest(pkt, request_type, curCycle());
2538615Snilay@cs.wisc.edu            m_outstanding_count++;
2548615Snilay@cs.wisc.edu        } else {
2558615Snilay@cs.wisc.edu          // There is an outstanding write request for the cache line
25610012Snilay@cs.wisc.edu          m_store_waiting_on_store++;
2578615Snilay@cs.wisc.edu          return RequestStatus_Aliased;
2588615Snilay@cs.wisc.edu        }
2598615Snilay@cs.wisc.edu    } else {
2608615Snilay@cs.wisc.edu        // Check if there is any outstanding write request for the same
2618615Snilay@cs.wisc.edu        // cache line.
2628615Snilay@cs.wisc.edu        if (m_writeRequestTable.count(line_addr) > 0) {
26310012Snilay@cs.wisc.edu            m_load_waiting_on_store++;
2648615Snilay@cs.wisc.edu            return RequestStatus_Aliased;
2658615Snilay@cs.wisc.edu        }
2667039Snate@binkert.org
2677455Snate@binkert.org        pair<RequestTable::iterator, bool> r =
2689224Sandreas.hansson@arm.com            m_readRequestTable.insert(default_entry);
2697039Snate@binkert.org
2708615Snilay@cs.wisc.edu        if (r.second) {
2718615Snilay@cs.wisc.edu            RequestTable::iterator i = r.first;
2729465Snilay@cs.wisc.edu            i->second = new SequencerRequest(pkt, request_type, curCycle());
2738615Snilay@cs.wisc.edu            m_outstanding_count++;
2748615Snilay@cs.wisc.edu        } else {
2758615Snilay@cs.wisc.edu            // There is an outstanding read request for the cache line
27610012Snilay@cs.wisc.edu            m_load_waiting_on_load++;
2778615Snilay@cs.wisc.edu            return RequestStatus_Aliased;
2787039Snate@binkert.org        }
2796145Snate@binkert.org    }
2806145Snate@binkert.org
28110012Snilay@cs.wisc.edu    m_outstandReqHist.sample(m_outstanding_count);
2828641Snate@binkert.org    assert(m_outstanding_count ==
2838641Snate@binkert.org        (m_writeRequestTable.size() + m_readRequestTable.size()));
2846145Snate@binkert.org
2858615Snilay@cs.wisc.edu    return RequestStatus_Ready;
2866145Snate@binkert.org}
2876145Snate@binkert.org
2887039Snate@binkert.orgvoid
2897455Snate@binkert.orgSequencer::markRemoved()
2907455Snate@binkert.org{
2917455Snate@binkert.org    m_outstanding_count--;
2927455Snate@binkert.org    assert(m_outstanding_count ==
2937455Snate@binkert.org           m_writeRequestTable.size() + m_readRequestTable.size());
2947455Snate@binkert.org}
2957455Snate@binkert.org
2967455Snate@binkert.orgvoid
2977039Snate@binkert.orgSequencer::removeRequest(SequencerRequest* srequest)
2987039Snate@binkert.org{
2997039Snate@binkert.org    assert(m_outstanding_count ==
3007039Snate@binkert.org           m_writeRequestTable.size() + m_readRequestTable.size());
3016145Snate@binkert.org
3028615Snilay@cs.wisc.edu    Address line_addr(srequest->pkt->getAddr());
3037039Snate@binkert.org    line_addr.makeLineAddress();
3048615Snilay@cs.wisc.edu    if ((srequest->m_type == RubyRequestType_ST) ||
3058615Snilay@cs.wisc.edu        (srequest->m_type == RubyRequestType_RMW_Read) ||
3068615Snilay@cs.wisc.edu        (srequest->m_type == RubyRequestType_RMW_Write) ||
3078615Snilay@cs.wisc.edu        (srequest->m_type == RubyRequestType_Load_Linked) ||
3088615Snilay@cs.wisc.edu        (srequest->m_type == RubyRequestType_Store_Conditional) ||
3098615Snilay@cs.wisc.edu        (srequest->m_type == RubyRequestType_Locked_RMW_Read) ||
3108615Snilay@cs.wisc.edu        (srequest->m_type == RubyRequestType_Locked_RMW_Write)) {
3117455Snate@binkert.org        m_writeRequestTable.erase(line_addr);
3127039Snate@binkert.org    } else {
3137455Snate@binkert.org        m_readRequestTable.erase(line_addr);
3147039Snate@binkert.org    }
3156285Snate@binkert.org
3167455Snate@binkert.org    markRemoved();
3176145Snate@binkert.org}
3186145Snate@binkert.org
3199563Sgope@wisc.eduvoid
3209563Sgope@wisc.eduSequencer::invalidateSC(const Address& address)
3219563Sgope@wisc.edu{
3229563Sgope@wisc.edu    RequestTable::iterator i = m_writeRequestTable.find(address);
3239563Sgope@wisc.edu    if (i != m_writeRequestTable.end()) {
3249563Sgope@wisc.edu        SequencerRequest* request = i->second;
3259563Sgope@wisc.edu        // The controller has lost the coherence permissions, hence the lock
3269563Sgope@wisc.edu        // on the cache line maintained by the cache should be cleared.
3279563Sgope@wisc.edu        if (request->m_type == RubyRequestType_Store_Conditional) {
3289563Sgope@wisc.edu            m_dataCache_ptr->clearLocked(address);
3299563Sgope@wisc.edu        }
3309563Sgope@wisc.edu    }
3319563Sgope@wisc.edu}
3329563Sgope@wisc.edu
3337560SBrad.Beckmann@amd.combool
3347560SBrad.Beckmann@amd.comSequencer::handleLlsc(const Address& address, SequencerRequest* request)
3357550SBrad.Beckmann@amd.com{
3367560SBrad.Beckmann@amd.com    //
3377560SBrad.Beckmann@amd.com    // The success flag indicates whether the LLSC operation was successful.
3387560SBrad.Beckmann@amd.com    // LL ops will always succeed, but SC may fail if the cache line is no
3397560SBrad.Beckmann@amd.com    // longer locked.
3407560SBrad.Beckmann@amd.com    //
3417560SBrad.Beckmann@amd.com    bool success = true;
3428615Snilay@cs.wisc.edu    if (request->m_type == RubyRequestType_Store_Conditional) {
3437550SBrad.Beckmann@amd.com        if (!m_dataCache_ptr->isLocked(address, m_version)) {
3447550SBrad.Beckmann@amd.com            //
3457550SBrad.Beckmann@amd.com            // For failed SC requests, indicate the failure to the cpu by
3467550SBrad.Beckmann@amd.com            // setting the extra data to zero.
3477550SBrad.Beckmann@amd.com            //
3488615Snilay@cs.wisc.edu            request->pkt->req->setExtraData(0);
3497560SBrad.Beckmann@amd.com            success = false;
3507550SBrad.Beckmann@amd.com        } else {
3517550SBrad.Beckmann@amd.com            //
3527550SBrad.Beckmann@amd.com            // For successful SC requests, indicate the success to the cpu by
35310917Sbrandon.potter@amd.com            // setting the extra data to one.
3547550SBrad.Beckmann@amd.com            //
3558615Snilay@cs.wisc.edu            request->pkt->req->setExtraData(1);
3567550SBrad.Beckmann@amd.com        }
3577560SBrad.Beckmann@amd.com        //
3587560SBrad.Beckmann@amd.com        // Independent of success, all SC operations must clear the lock
3597560SBrad.Beckmann@amd.com        //
3607550SBrad.Beckmann@amd.com        m_dataCache_ptr->clearLocked(address);
3618615Snilay@cs.wisc.edu    } else if (request->m_type == RubyRequestType_Load_Linked) {
3627550SBrad.Beckmann@amd.com        //
3637550SBrad.Beckmann@amd.com        // Note: To fully follow Alpha LLSC semantics, should the LL clear any
3647550SBrad.Beckmann@amd.com        // previously locked cache lines?
3657550SBrad.Beckmann@amd.com        //
3667550SBrad.Beckmann@amd.com        m_dataCache_ptr->setLocked(address, m_version);
3678615Snilay@cs.wisc.edu    } else if ((m_dataCache_ptr->isTagPresent(address)) &&
3688615Snilay@cs.wisc.edu               (m_dataCache_ptr->isLocked(address, m_version))) {
3697550SBrad.Beckmann@amd.com        //
3707550SBrad.Beckmann@amd.com        // Normal writes should clear the locked address
3717550SBrad.Beckmann@amd.com        //
3727550SBrad.Beckmann@amd.com        m_dataCache_ptr->clearLocked(address);
3737550SBrad.Beckmann@amd.com    }
3747560SBrad.Beckmann@amd.com    return success;
3757550SBrad.Beckmann@amd.com}
3767550SBrad.Beckmann@amd.com
3777550SBrad.Beckmann@amd.comvoid
3789773Snilay@cs.wisc.eduSequencer::recordMissLatency(const Cycles cycles, const RubyRequestType type,
3799773Snilay@cs.wisc.edu                             const MachineType respondingMach,
3809773Snilay@cs.wisc.edu                             bool isExternalHit, Cycles issuedTime,
3819773Snilay@cs.wisc.edu                             Cycles initialRequestTime,
3829773Snilay@cs.wisc.edu                             Cycles forwardRequestTime,
3839773Snilay@cs.wisc.edu                             Cycles firstResponseTime, Cycles completionTime)
3847039Snate@binkert.org{
38510012Snilay@cs.wisc.edu    m_latencyHist.sample(cycles);
38610012Snilay@cs.wisc.edu    m_typeLatencyHist[type]->sample(cycles);
3879773Snilay@cs.wisc.edu
3889773Snilay@cs.wisc.edu    if (isExternalHit) {
38910012Snilay@cs.wisc.edu        m_missLatencyHist.sample(cycles);
39010012Snilay@cs.wisc.edu        m_missTypeLatencyHist[type]->sample(cycles);
3919773Snilay@cs.wisc.edu
3929773Snilay@cs.wisc.edu        if (respondingMach != MachineType_NUM) {
39310012Snilay@cs.wisc.edu            m_missMachLatencyHist[respondingMach]->sample(cycles);
39410012Snilay@cs.wisc.edu            m_missTypeMachLatencyHist[type][respondingMach]->sample(cycles);
3959773Snilay@cs.wisc.edu
3969773Snilay@cs.wisc.edu            if ((issuedTime <= initialRequestTime) &&
3979773Snilay@cs.wisc.edu                (initialRequestTime <= forwardRequestTime) &&
3989773Snilay@cs.wisc.edu                (forwardRequestTime <= firstResponseTime) &&
3999773Snilay@cs.wisc.edu                (firstResponseTime <= completionTime)) {
4009773Snilay@cs.wisc.edu
40110012Snilay@cs.wisc.edu                m_IssueToInitialDelayHist[respondingMach]->sample(
4029773Snilay@cs.wisc.edu                    initialRequestTime - issuedTime);
40310012Snilay@cs.wisc.edu                m_InitialToForwardDelayHist[respondingMach]->sample(
4049773Snilay@cs.wisc.edu                    forwardRequestTime - initialRequestTime);
40510012Snilay@cs.wisc.edu                m_ForwardToFirstResponseDelayHist[respondingMach]->sample(
4069773Snilay@cs.wisc.edu                    firstResponseTime - forwardRequestTime);
40710012Snilay@cs.wisc.edu                m_FirstResponseToCompletionDelayHist[respondingMach]->sample(
4089773Snilay@cs.wisc.edu                    completionTime - firstResponseTime);
4099773Snilay@cs.wisc.edu            } else {
4109773Snilay@cs.wisc.edu                m_IncompleteTimes[respondingMach]++;
4119773Snilay@cs.wisc.edu            }
4129773Snilay@cs.wisc.edu        }
4139773Snilay@cs.wisc.edu    } else {
41410012Snilay@cs.wisc.edu        m_hitLatencyHist.sample(cycles);
41510012Snilay@cs.wisc.edu        m_hitTypeLatencyHist[type]->sample(cycles);
4169773Snilay@cs.wisc.edu
4179773Snilay@cs.wisc.edu        if (respondingMach != MachineType_NUM) {
41810012Snilay@cs.wisc.edu            m_hitMachLatencyHist[respondingMach]->sample(cycles);
41910012Snilay@cs.wisc.edu            m_hitTypeMachLatencyHist[type][respondingMach]->sample(cycles);
4209773Snilay@cs.wisc.edu        }
4219773Snilay@cs.wisc.edu    }
4227546SBrad.Beckmann@amd.com}
4237546SBrad.Beckmann@amd.com
4247546SBrad.Beckmann@amd.comvoid
4259773Snilay@cs.wisc.eduSequencer::writeCallback(const Address& address, DataBlock& data,
4269773Snilay@cs.wisc.edu                         const bool externalHit, const MachineType mach,
4279773Snilay@cs.wisc.edu                         const Cycles initialRequestTime,
4289773Snilay@cs.wisc.edu                         const Cycles forwardRequestTime,
4299773Snilay@cs.wisc.edu                         const Cycles firstResponseTime)
4307565SBrad.Beckmann@amd.com{
4317039Snate@binkert.org    assert(address == line_address(address));
4327455Snate@binkert.org    assert(m_writeRequestTable.count(line_address(address)));
4336145Snate@binkert.org
4347455Snate@binkert.org    RequestTable::iterator i = m_writeRequestTable.find(address);
4357455Snate@binkert.org    assert(i != m_writeRequestTable.end());
4367455Snate@binkert.org    SequencerRequest* request = i->second;
4376145Snate@binkert.org
4387455Snate@binkert.org    m_writeRequestTable.erase(i);
4397455Snate@binkert.org    markRemoved();
4406846Spdudnik@cs.wisc.edu
4418615Snilay@cs.wisc.edu    assert((request->m_type == RubyRequestType_ST) ||
4428615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_ATOMIC) ||
4438615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_RMW_Read) ||
4448615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_RMW_Write) ||
4458615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_Load_Linked) ||
4468615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_Store_Conditional) ||
4478615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_Locked_RMW_Read) ||
4488615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_Locked_RMW_Write) ||
4498615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_FLUSH));
4508184Ssomayeh@cs.wisc.edu
4517550SBrad.Beckmann@amd.com    //
4527550SBrad.Beckmann@amd.com    // For Alpha, properly handle LL, SC, and write requests with respect to
4537550SBrad.Beckmann@amd.com    // locked cache blocks.
4547550SBrad.Beckmann@amd.com    //
4558171Stushar@csail.mit.edu    // Not valid for Network_test protocl
4568171Stushar@csail.mit.edu    //
4578171Stushar@csail.mit.edu    bool success = true;
4588171Stushar@csail.mit.edu    if(!m_usingNetworkTester)
4598171Stushar@csail.mit.edu        success = handleLlsc(address, request);
4607550SBrad.Beckmann@amd.com
4618615Snilay@cs.wisc.edu    if (request->m_type == RubyRequestType_Locked_RMW_Read) {
4627039Snate@binkert.org        m_controller->blockOnQueue(address, m_mandatory_q_ptr);
4638615Snilay@cs.wisc.edu    } else if (request->m_type == RubyRequestType_Locked_RMW_Write) {
4647039Snate@binkert.org        m_controller->unblock(address);
4657039Snate@binkert.org    }
4666863Sdrh5@cs.wisc.edu
4679773Snilay@cs.wisc.edu    hitCallback(request, data, success, mach, externalHit,
4687565SBrad.Beckmann@amd.com                initialRequestTime, forwardRequestTime, firstResponseTime);
4696145Snate@binkert.org}
4706145Snate@binkert.org
4717039Snate@binkert.orgvoid
4729773Snilay@cs.wisc.eduSequencer::readCallback(const Address& address, DataBlock& data,
4739773Snilay@cs.wisc.edu                        bool externalHit, const MachineType mach,
4749507Snilay@cs.wisc.edu                        Cycles initialRequestTime,
4759507Snilay@cs.wisc.edu                        Cycles forwardRequestTime,
4769507Snilay@cs.wisc.edu                        Cycles firstResponseTime)
4777565SBrad.Beckmann@amd.com{
4787039Snate@binkert.org    assert(address == line_address(address));
4797455Snate@binkert.org    assert(m_readRequestTable.count(line_address(address)));
4806145Snate@binkert.org
4817455Snate@binkert.org    RequestTable::iterator i = m_readRequestTable.find(address);
4827455Snate@binkert.org    assert(i != m_readRequestTable.end());
4837455Snate@binkert.org    SequencerRequest* request = i->second;
4847455Snate@binkert.org
4857455Snate@binkert.org    m_readRequestTable.erase(i);
4867455Snate@binkert.org    markRemoved();
4876145Snate@binkert.org
4888615Snilay@cs.wisc.edu    assert((request->m_type == RubyRequestType_LD) ||
4898615Snilay@cs.wisc.edu           (request->m_type == RubyRequestType_IFETCH));
4906285Snate@binkert.org
4919773Snilay@cs.wisc.edu    hitCallback(request, data, true, mach, externalHit,
4927565SBrad.Beckmann@amd.com                initialRequestTime, forwardRequestTime, firstResponseTime);
4936145Snate@binkert.org}
4946145Snate@binkert.org
4957039Snate@binkert.orgvoid
4969773Snilay@cs.wisc.eduSequencer::hitCallback(SequencerRequest* srequest, DataBlock& data,
4979773Snilay@cs.wisc.edu                       bool llscSuccess,
4989773Snilay@cs.wisc.edu                       const MachineType mach, const bool externalHit,
4999773Snilay@cs.wisc.edu                       const Cycles initialRequestTime,
5009773Snilay@cs.wisc.edu                       const Cycles forwardRequestTime,
5019773Snilay@cs.wisc.edu                       const Cycles firstResponseTime)
5027039Snate@binkert.org{
5038615Snilay@cs.wisc.edu    PacketPtr pkt = srequest->pkt;
5048615Snilay@cs.wisc.edu    Address request_address(pkt->getAddr());
5058615Snilay@cs.wisc.edu    Address request_line_address(pkt->getAddr());
5067039Snate@binkert.org    request_line_address.makeLineAddress();
5078615Snilay@cs.wisc.edu    RubyRequestType type = srequest->m_type;
5089507Snilay@cs.wisc.edu    Cycles issued_time = srequest->issue_time;
5096145Snate@binkert.org
5107039Snate@binkert.org    // Set this cache entry to the most recently used
5117039Snate@binkert.org    if (type == RubyRequestType_IFETCH) {
5128828Snilay@cs.wisc.edu        m_instCache_ptr->setMRU(request_line_address);
5137039Snate@binkert.org    } else {
5148828Snilay@cs.wisc.edu        m_dataCache_ptr->setMRU(request_line_address);
5157039Snate@binkert.org    }
5166145Snate@binkert.org
5179465Snilay@cs.wisc.edu    assert(curCycle() >= issued_time);
5189773Snilay@cs.wisc.edu    Cycles total_latency = curCycle() - issued_time;
5196145Snate@binkert.org
5209773Snilay@cs.wisc.edu    // Profile the latency for all demand accesses.
5219773Snilay@cs.wisc.edu    recordMissLatency(total_latency, type, mach, externalHit, issued_time,
5229773Snilay@cs.wisc.edu                      initialRequestTime, forwardRequestTime,
5239773Snilay@cs.wisc.edu                      firstResponseTime, curCycle());
5246285Snate@binkert.org
5259773Snilay@cs.wisc.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %d cycles\n",
5269773Snilay@cs.wisc.edu             curTick(), m_version, "Seq",
5279773Snilay@cs.wisc.edu             llscSuccess ? "Done" : "SC_Failed", "", "",
5289773Snilay@cs.wisc.edu             request_address, total_latency);
5296285Snate@binkert.org
53010562Sandreas.hansson@arm.com    // update the data unless it is a non-data-carrying flush
53110837Sjthestness@gmail.com    if (RubySystem::getWarmupEnabled()) {
53210563Sandreas.hansson@arm.com        data.setData(pkt->getConstPtr<uint8_t>(),
5338688Snilay@cs.wisc.edu                     request_address.getOffset(), pkt->getSize());
53410562Sandreas.hansson@arm.com    } else if (!pkt->isFlush()) {
5357039Snate@binkert.org        if ((type == RubyRequestType_LD) ||
5367039Snate@binkert.org            (type == RubyRequestType_IFETCH) ||
5377039Snate@binkert.org            (type == RubyRequestType_RMW_Read) ||
5387908Shestness@cs.utexas.edu            (type == RubyRequestType_Locked_RMW_Read) ||
5397907Shestness@cs.utexas.edu            (type == RubyRequestType_Load_Linked)) {
54010562Sandreas.hansson@arm.com            memcpy(pkt->getPtr<uint8_t>(),
5418615Snilay@cs.wisc.edu                   data.getData(request_address.getOffset(), pkt->getSize()),
5428615Snilay@cs.wisc.edu                   pkt->getSize());
54310954SBrad.Beckmann@amd.com            DPRINTF(RubySequencer, "read data %s\n", data);
5447039Snate@binkert.org        } else {
54510563Sandreas.hansson@arm.com            data.setData(pkt->getConstPtr<uint8_t>(),
5468615Snilay@cs.wisc.edu                         request_address.getOffset(), pkt->getSize());
54710954SBrad.Beckmann@amd.com            DPRINTF(RubySequencer, "set data %s\n", data);
5487039Snate@binkert.org        }
5497039Snate@binkert.org    }
5507023SBrad.Beckmann@amd.com
5517039Snate@binkert.org    // If using the RubyTester, update the RubyTester sender state's
5527039Snate@binkert.org    // subBlock with the recieved data.  The tester will later access
5537039Snate@binkert.org    // this state.
5547039Snate@binkert.org    if (m_usingRubyTester) {
55510657Sandreas.hansson@arm.com        DPRINTF(RubySequencer, "hitCallback %s 0x%x using RubyTester\n",
55610657Sandreas.hansson@arm.com                pkt->cmdString(), pkt->getAddr());
5577039Snate@binkert.org        RubyTester::SenderState* testerSenderState =
55810089Sandreas.hansson@arm.com            pkt->findNextSenderState<RubyTester::SenderState>();
55910089Sandreas.hansson@arm.com        assert(testerSenderState);
5609542Sandreas.hansson@arm.com        testerSenderState->subBlock.mergeFrom(data);
5617039Snate@binkert.org    }
5627023SBrad.Beckmann@amd.com
5637039Snate@binkert.org    delete srequest;
5648688Snilay@cs.wisc.edu
56510919Sbrandon.potter@amd.com    RubySystem *rs = m_ruby_system;
56610837Sjthestness@gmail.com    if (RubySystem::getWarmupEnabled()) {
5679632Sjthestness@gmail.com        assert(pkt->req);
5689632Sjthestness@gmail.com        delete pkt->req;
5698688Snilay@cs.wisc.edu        delete pkt;
57010919Sbrandon.potter@amd.com        rs->m_cache_recorder->enqueueNextFetchRequest();
57110837Sjthestness@gmail.com    } else if (RubySystem::getCooldownEnabled()) {
5728688Snilay@cs.wisc.edu        delete pkt;
57310919Sbrandon.potter@amd.com        rs->m_cache_recorder->enqueueNextFlushRequest();
5748688Snilay@cs.wisc.edu    } else {
5758688Snilay@cs.wisc.edu        ruby_hit_callback(pkt);
5768688Snilay@cs.wisc.edu    }
5776285Snate@binkert.org}
5786285Snate@binkert.org
5797039Snate@binkert.orgbool
5807039Snate@binkert.orgSequencer::empty() const
5817039Snate@binkert.org{
5827455Snate@binkert.org    return m_writeRequestTable.empty() && m_readRequestTable.empty();
5836145Snate@binkert.org}
5846145Snate@binkert.org
5857039Snate@binkert.orgRequestStatus
5868615Snilay@cs.wisc.eduSequencer::makeRequest(PacketPtr pkt)
5877039Snate@binkert.org{
5888615Snilay@cs.wisc.edu    if (m_outstanding_count >= m_max_outstanding_requests) {
5898615Snilay@cs.wisc.edu        return RequestStatus_BufferFull;
5908615Snilay@cs.wisc.edu    }
5918615Snilay@cs.wisc.edu
5928615Snilay@cs.wisc.edu    RubyRequestType primary_type = RubyRequestType_NULL;
5938615Snilay@cs.wisc.edu    RubyRequestType secondary_type = RubyRequestType_NULL;
5948615Snilay@cs.wisc.edu
5958615Snilay@cs.wisc.edu    if (pkt->isLLSC()) {
5968615Snilay@cs.wisc.edu        //
5978615Snilay@cs.wisc.edu        // Alpha LL/SC instructions need to be handled carefully by the cache
5988615Snilay@cs.wisc.edu        // coherence protocol to ensure they follow the proper semantics. In
5998615Snilay@cs.wisc.edu        // particular, by identifying the operations as atomic, the protocol
6008615Snilay@cs.wisc.edu        // should understand that migratory sharing optimizations should not
6018615Snilay@cs.wisc.edu        // be performed (i.e. a load between the LL and SC should not steal
6028615Snilay@cs.wisc.edu        // away exclusive permission).
6038615Snilay@cs.wisc.edu        //
6048615Snilay@cs.wisc.edu        if (pkt->isWrite()) {
6058615Snilay@cs.wisc.edu            DPRINTF(RubySequencer, "Issuing SC\n");
6068615Snilay@cs.wisc.edu            primary_type = RubyRequestType_Store_Conditional;
6078615Snilay@cs.wisc.edu        } else {
6088615Snilay@cs.wisc.edu            DPRINTF(RubySequencer, "Issuing LL\n");
6098615Snilay@cs.wisc.edu            assert(pkt->isRead());
6108615Snilay@cs.wisc.edu            primary_type = RubyRequestType_Load_Linked;
6118615Snilay@cs.wisc.edu        }
6128615Snilay@cs.wisc.edu        secondary_type = RubyRequestType_ATOMIC;
61310760Ssteve.reinhardt@amd.com    } else if (pkt->req->isLockedRMW()) {
6148615Snilay@cs.wisc.edu        //
6158615Snilay@cs.wisc.edu        // x86 locked instructions are translated to store cache coherence
6168615Snilay@cs.wisc.edu        // requests because these requests should always be treated as read
6178615Snilay@cs.wisc.edu        // exclusive operations and should leverage any migratory sharing
6188615Snilay@cs.wisc.edu        // optimization built into the protocol.
6198615Snilay@cs.wisc.edu        //
6208615Snilay@cs.wisc.edu        if (pkt->isWrite()) {
6218615Snilay@cs.wisc.edu            DPRINTF(RubySequencer, "Issuing Locked RMW Write\n");
6228615Snilay@cs.wisc.edu            primary_type = RubyRequestType_Locked_RMW_Write;
6238615Snilay@cs.wisc.edu        } else {
6248615Snilay@cs.wisc.edu            DPRINTF(RubySequencer, "Issuing Locked RMW Read\n");
6258615Snilay@cs.wisc.edu            assert(pkt->isRead());
6268615Snilay@cs.wisc.edu            primary_type = RubyRequestType_Locked_RMW_Read;
6278615Snilay@cs.wisc.edu        }
6288615Snilay@cs.wisc.edu        secondary_type = RubyRequestType_ST;
6298615Snilay@cs.wisc.edu    } else {
6308615Snilay@cs.wisc.edu        if (pkt->isRead()) {
6318615Snilay@cs.wisc.edu            if (pkt->req->isInstFetch()) {
6328615Snilay@cs.wisc.edu                primary_type = secondary_type = RubyRequestType_IFETCH;
6338615Snilay@cs.wisc.edu            } else {
6348615Snilay@cs.wisc.edu                bool storeCheck = false;
63510467Sandreas.hansson@arm.com                // only X86 need the store check
63610467Sandreas.hansson@arm.com                if (system->getArch() == Arch::X86ISA) {
63710467Sandreas.hansson@arm.com                    uint32_t flags = pkt->req->getFlags();
63810467Sandreas.hansson@arm.com                    storeCheck = flags &
63910467Sandreas.hansson@arm.com                        (X86ISA::StoreCheck << X86ISA::FlagShift);
64010467Sandreas.hansson@arm.com                }
6418615Snilay@cs.wisc.edu                if (storeCheck) {
6428615Snilay@cs.wisc.edu                    primary_type = RubyRequestType_RMW_Read;
6438615Snilay@cs.wisc.edu                    secondary_type = RubyRequestType_ST;
6448615Snilay@cs.wisc.edu                } else {
6458615Snilay@cs.wisc.edu                    primary_type = secondary_type = RubyRequestType_LD;
6468615Snilay@cs.wisc.edu                }
6478615Snilay@cs.wisc.edu            }
6488615Snilay@cs.wisc.edu        } else if (pkt->isWrite()) {
6498615Snilay@cs.wisc.edu            //
6508615Snilay@cs.wisc.edu            // Note: M5 packets do not differentiate ST from RMW_Write
6518615Snilay@cs.wisc.edu            //
6528615Snilay@cs.wisc.edu            primary_type = secondary_type = RubyRequestType_ST;
6538615Snilay@cs.wisc.edu        } else if (pkt->isFlush()) {
6548615Snilay@cs.wisc.edu          primary_type = secondary_type = RubyRequestType_FLUSH;
6558615Snilay@cs.wisc.edu        } else {
6568615Snilay@cs.wisc.edu            panic("Unsupported ruby packet type\n");
6578615Snilay@cs.wisc.edu        }
6588615Snilay@cs.wisc.edu    }
6598615Snilay@cs.wisc.edu
6608615Snilay@cs.wisc.edu    RequestStatus status = insertRequest(pkt, primary_type);
6617039Snate@binkert.org    if (status != RequestStatus_Ready)
6627039Snate@binkert.org        return status;
6636349Spdudnik@gmail.com
6648615Snilay@cs.wisc.edu    issueRequest(pkt, secondary_type);
6656145Snate@binkert.org
6667039Snate@binkert.org    // TODO: issue hardware prefetches here
6677039Snate@binkert.org    return RequestStatus_Issued;
6686145Snate@binkert.org}
6696145Snate@binkert.org
6707039Snate@binkert.orgvoid
6718615Snilay@cs.wisc.eduSequencer::issueRequest(PacketPtr pkt, RubyRequestType secondary_type)
6727039Snate@binkert.org{
6739216Sandreas.hansson@arm.com    assert(pkt != NULL);
67411005Sandreas.sandberg@arm.com    ContextID proc_id = pkt->req->hasContextId() ?
67511005Sandreas.sandberg@arm.com        pkt->req->contextId() : InvalidContextID;
6766285Snate@binkert.org
6778615Snilay@cs.wisc.edu    // If valid, copy the pc to the ruby request
6788615Snilay@cs.wisc.edu    Addr pc = 0;
6798615Snilay@cs.wisc.edu    if (pkt->req->hasPC()) {
6808615Snilay@cs.wisc.edu        pc = pkt->req->getPC();
6817039Snate@binkert.org    }
6826285Snate@binkert.org
68310562Sandreas.hansson@arm.com    // check if the packet has data as for example prefetch and flush
68410562Sandreas.hansson@arm.com    // requests do not
68510472Sandreas.hansson@arm.com    std::shared_ptr<RubyRequest> msg =
68610472Sandreas.hansson@arm.com        std::make_shared<RubyRequest>(clockEdge(), pkt->getAddr(),
68710562Sandreas.hansson@arm.com                                      pkt->isFlush() ?
68810562Sandreas.hansson@arm.com                                      nullptr : pkt->getPtr<uint8_t>(),
68910472Sandreas.hansson@arm.com                                      pkt->getSize(), pc, secondary_type,
69010472Sandreas.hansson@arm.com                                      RubyAccessMode_Supervisor, pkt,
69110472Sandreas.hansson@arm.com                                      PrefetchBit_No, proc_id);
6926285Snate@binkert.org
6938266Sksewell@umich.edu    DPRINTFR(ProtocolTrace, "%15s %3s %10s%20s %6s>%-6s %s %s\n",
6948266Sksewell@umich.edu            curTick(), m_version, "Seq", "Begin", "", "",
6958615Snilay@cs.wisc.edu            msg->getPhysicalAddress(),
6968615Snilay@cs.wisc.edu            RubyRequestType_to_string(secondary_type));
6976285Snate@binkert.org
69811019Sjthestness@gmail.com    // The Sequencer currently assesses instruction and data cache hit latency
69911019Sjthestness@gmail.com    // for the top-level caches at the beginning of a memory access.
70011019Sjthestness@gmail.com    // TODO: Eventually, this latency should be moved to represent the actual
70111019Sjthestness@gmail.com    // cache access latency portion of the memory access. This will require
70211019Sjthestness@gmail.com    // changing cache controller protocol files to assess the latency on the
70311019Sjthestness@gmail.com    // access response path.
70411019Sjthestness@gmail.com    Cycles latency(0);  // Initialize to zero to catch misconfigured latency
7058615Snilay@cs.wisc.edu    if (secondary_type == RubyRequestType_IFETCH)
70611019Sjthestness@gmail.com        latency = m_inst_cache_hit_latency;
7077039Snate@binkert.org    else
70811019Sjthestness@gmail.com        latency = m_data_cache_hit_latency;
7096285Snate@binkert.org
7107039Snate@binkert.org    // Send the message to the cache controller
7117039Snate@binkert.org    assert(latency > 0);
7126145Snate@binkert.org
7137039Snate@binkert.org    assert(m_mandatory_q_ptr != NULL);
7147039Snate@binkert.org    m_mandatory_q_ptr->enqueue(msg, latency);
7156145Snate@binkert.org}
7166145Snate@binkert.org
7177455Snate@binkert.orgtemplate <class KEY, class VALUE>
7187455Snate@binkert.orgstd::ostream &
7197455Snate@binkert.orgoperator<<(ostream &out, const m5::hash_map<KEY, VALUE> &map)
7207455Snate@binkert.org{
7217455Snate@binkert.org    typename m5::hash_map<KEY, VALUE>::const_iterator i = map.begin();
7227455Snate@binkert.org    typename m5::hash_map<KEY, VALUE>::const_iterator end = map.end();
7237455Snate@binkert.org
7247455Snate@binkert.org    out << "[";
7257455Snate@binkert.org    for (; i != end; ++i)
7267455Snate@binkert.org        out << " " << i->first << "=" << i->second;
7277455Snate@binkert.org    out << " ]";
7287455Snate@binkert.org
7297455Snate@binkert.org    return out;
7307455Snate@binkert.org}
7317455Snate@binkert.org
7327039Snate@binkert.orgvoid
7337039Snate@binkert.orgSequencer::print(ostream& out) const
7347039Snate@binkert.org{
7357039Snate@binkert.org    out << "[Sequencer: " << m_version
7367039Snate@binkert.org        << ", outstanding requests: " << m_outstanding_count
7377039Snate@binkert.org        << ", read request table: " << m_readRequestTable
7387039Snate@binkert.org        << ", write request table: " << m_writeRequestTable
7397039Snate@binkert.org        << "]";
7407039Snate@binkert.org}
7417039Snate@binkert.org
7427039Snate@binkert.org// this can be called from setState whenever coherence permissions are
7437039Snate@binkert.org// upgraded when invoked, coherence violations will be checked for the
7447039Snate@binkert.org// given block
7457039Snate@binkert.orgvoid
7467039Snate@binkert.orgSequencer::checkCoherence(const Address& addr)
7477039Snate@binkert.org{
7486145Snate@binkert.org#ifdef CHECK_COHERENCE
74910919Sbrandon.potter@amd.com    m_ruby_system->checkGlobalCoherenceInvariant(addr);
7506145Snate@binkert.org#endif
7516145Snate@binkert.org}
7528717Snilay@cs.wisc.edu
7538717Snilay@cs.wisc.eduvoid
7549104Shestness@cs.utexas.eduSequencer::recordRequestType(SequencerRequestType requestType) {
7559104Shestness@cs.utexas.edu    DPRINTF(RubyStats, "Recorded statistic: %s\n",
7569104Shestness@cs.utexas.edu            SequencerRequestType_to_string(requestType));
7579104Shestness@cs.utexas.edu}
7589104Shestness@cs.utexas.edu
7599104Shestness@cs.utexas.edu
7609104Shestness@cs.utexas.eduvoid
7618717Snilay@cs.wisc.eduSequencer::evictionCallback(const Address& address)
7628717Snilay@cs.wisc.edu{
7638717Snilay@cs.wisc.edu    ruby_eviction_callback(address);
7648717Snilay@cs.wisc.edu}
76510012Snilay@cs.wisc.edu
76610012Snilay@cs.wisc.eduvoid
76710012Snilay@cs.wisc.eduSequencer::regStats()
76810012Snilay@cs.wisc.edu{
76910012Snilay@cs.wisc.edu    m_store_waiting_on_load
77010012Snilay@cs.wisc.edu        .name(name() + ".store_waiting_on_load")
77110012Snilay@cs.wisc.edu        .desc("Number of times a store aliased with a pending load")
77210012Snilay@cs.wisc.edu        .flags(Stats::nozero);
77310012Snilay@cs.wisc.edu    m_store_waiting_on_store
77410012Snilay@cs.wisc.edu        .name(name() + ".store_waiting_on_store")
77510012Snilay@cs.wisc.edu        .desc("Number of times a store aliased with a pending store")
77610012Snilay@cs.wisc.edu        .flags(Stats::nozero);
77710012Snilay@cs.wisc.edu    m_load_waiting_on_load
77810012Snilay@cs.wisc.edu        .name(name() + ".load_waiting_on_load")
77910012Snilay@cs.wisc.edu        .desc("Number of times a load aliased with a pending load")
78010012Snilay@cs.wisc.edu        .flags(Stats::nozero);
78110012Snilay@cs.wisc.edu    m_load_waiting_on_store
78210012Snilay@cs.wisc.edu        .name(name() + ".load_waiting_on_store")
78310012Snilay@cs.wisc.edu        .desc("Number of times a load aliased with a pending store")
78410012Snilay@cs.wisc.edu        .flags(Stats::nozero);
78510012Snilay@cs.wisc.edu
78610012Snilay@cs.wisc.edu    // These statistical variables are not for display.
78710012Snilay@cs.wisc.edu    // The profiler will collate these across different
78810012Snilay@cs.wisc.edu    // sequencers and display those collated statistics.
78910012Snilay@cs.wisc.edu    m_outstandReqHist.init(10);
79010012Snilay@cs.wisc.edu    m_latencyHist.init(10);
79110012Snilay@cs.wisc.edu    m_hitLatencyHist.init(10);
79210012Snilay@cs.wisc.edu    m_missLatencyHist.init(10);
79310012Snilay@cs.wisc.edu
79410012Snilay@cs.wisc.edu    for (int i = 0; i < RubyRequestType_NUM; i++) {
79510012Snilay@cs.wisc.edu        m_typeLatencyHist.push_back(new Stats::Histogram());
79610012Snilay@cs.wisc.edu        m_typeLatencyHist[i]->init(10);
79710012Snilay@cs.wisc.edu
79810012Snilay@cs.wisc.edu        m_hitTypeLatencyHist.push_back(new Stats::Histogram());
79910012Snilay@cs.wisc.edu        m_hitTypeLatencyHist[i]->init(10);
80010012Snilay@cs.wisc.edu
80110012Snilay@cs.wisc.edu        m_missTypeLatencyHist.push_back(new Stats::Histogram());
80210012Snilay@cs.wisc.edu        m_missTypeLatencyHist[i]->init(10);
80310012Snilay@cs.wisc.edu    }
80410012Snilay@cs.wisc.edu
80510012Snilay@cs.wisc.edu    for (int i = 0; i < MachineType_NUM; i++) {
80610012Snilay@cs.wisc.edu        m_hitMachLatencyHist.push_back(new Stats::Histogram());
80710012Snilay@cs.wisc.edu        m_hitMachLatencyHist[i]->init(10);
80810012Snilay@cs.wisc.edu
80910012Snilay@cs.wisc.edu        m_missMachLatencyHist.push_back(new Stats::Histogram());
81010012Snilay@cs.wisc.edu        m_missMachLatencyHist[i]->init(10);
81110012Snilay@cs.wisc.edu
81210012Snilay@cs.wisc.edu        m_IssueToInitialDelayHist.push_back(new Stats::Histogram());
81310012Snilay@cs.wisc.edu        m_IssueToInitialDelayHist[i]->init(10);
81410012Snilay@cs.wisc.edu
81510012Snilay@cs.wisc.edu        m_InitialToForwardDelayHist.push_back(new Stats::Histogram());
81610012Snilay@cs.wisc.edu        m_InitialToForwardDelayHist[i]->init(10);
81710012Snilay@cs.wisc.edu
81810012Snilay@cs.wisc.edu        m_ForwardToFirstResponseDelayHist.push_back(new Stats::Histogram());
81910012Snilay@cs.wisc.edu        m_ForwardToFirstResponseDelayHist[i]->init(10);
82010012Snilay@cs.wisc.edu
82110012Snilay@cs.wisc.edu        m_FirstResponseToCompletionDelayHist.push_back(new Stats::Histogram());
82210012Snilay@cs.wisc.edu        m_FirstResponseToCompletionDelayHist[i]->init(10);
82310012Snilay@cs.wisc.edu    }
82410012Snilay@cs.wisc.edu
82510012Snilay@cs.wisc.edu    for (int i = 0; i < RubyRequestType_NUM; i++) {
82610012Snilay@cs.wisc.edu        m_hitTypeMachLatencyHist.push_back(std::vector<Stats::Histogram *>());
82710012Snilay@cs.wisc.edu        m_missTypeMachLatencyHist.push_back(std::vector<Stats::Histogram *>());
82810012Snilay@cs.wisc.edu
82910012Snilay@cs.wisc.edu        for (int j = 0; j < MachineType_NUM; j++) {
83010012Snilay@cs.wisc.edu            m_hitTypeMachLatencyHist[i].push_back(new Stats::Histogram());
83110012Snilay@cs.wisc.edu            m_hitTypeMachLatencyHist[i][j]->init(10);
83210012Snilay@cs.wisc.edu
83310012Snilay@cs.wisc.edu            m_missTypeMachLatencyHist[i].push_back(new Stats::Histogram());
83410012Snilay@cs.wisc.edu            m_missTypeMachLatencyHist[i][j]->init(10);
83510012Snilay@cs.wisc.edu        }
83610012Snilay@cs.wisc.edu    }
83710012Snilay@cs.wisc.edu}
838