Sequencer.hh revision 10012
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
297039Snate@binkert.org#ifndef __MEM_RUBY_SYSTEM_SEQUENCER_HH__
307039Snate@binkert.org#define __MEM_RUBY_SYSTEM_SEQUENCER_HH__
316145Snate@binkert.org
327055Snate@binkert.org#include <iostream>
337055Snate@binkert.org
347455Snate@binkert.org#include "base/hashmap.hh"
359773Snilay@cs.wisc.edu#include "mem/protocol/MachineType.hh"
368165Snilay@cs.wisc.edu#include "mem/protocol/RubyRequestType.hh"
379104Shestness@cs.utexas.edu#include "mem/protocol/SequencerRequestType.hh"
387039Snate@binkert.org#include "mem/ruby/common/Address.hh"
399171Snilay@cs.wisc.edu#include "mem/ruby/system/CacheMemory.hh"
406285Snate@binkert.org#include "mem/ruby/system/RubyPort.hh"
419171Snilay@cs.wisc.edu#include "params/RubySequencer.hh"
426145Snate@binkert.org
436145Snate@binkert.orgclass DataBlock;
446145Snate@binkert.org
457039Snate@binkert.orgstruct SequencerRequest
467039Snate@binkert.org{
478615Snilay@cs.wisc.edu    PacketPtr pkt;
488615Snilay@cs.wisc.edu    RubyRequestType m_type;
499501Snilay@cs.wisc.edu    Cycles issue_time;
506285Snate@binkert.org
519501Snilay@cs.wisc.edu    SequencerRequest(PacketPtr _pkt, RubyRequestType _m_type,
529501Snilay@cs.wisc.edu                     Cycles _issue_time)
538615Snilay@cs.wisc.edu        : pkt(_pkt), m_type(_m_type), issue_time(_issue_time)
547039Snate@binkert.org    {}
556285Snate@binkert.org};
566285Snate@binkert.org
576763SBrad.Beckmann@amd.comstd::ostream& operator<<(std::ostream& out, const SequencerRequest& obj);
586763SBrad.Beckmann@amd.com
599171Snilay@cs.wisc.educlass Sequencer : public RubyPort
607039Snate@binkert.org{
617039Snate@binkert.org  public:
626876Ssteve.reinhardt@amd.com    typedef RubySequencerParams Params;
637039Snate@binkert.org    Sequencer(const Params *);
647039Snate@binkert.org    ~Sequencer();
656145Snate@binkert.org
667039Snate@binkert.org    // Public Methods
677039Snate@binkert.org    void wakeup(); // Used only for deadlock detection
687055Snate@binkert.org    void printProgress(std::ostream& out) const;
6910012Snilay@cs.wisc.edu    void resetStats();
7010012Snilay@cs.wisc.edu    void collateStats();
7110012Snilay@cs.wisc.edu    void regStats();
729598Snilay@cs.wisc.edu
739507Snilay@cs.wisc.edu    void writeCallback(const Address& address,
747565SBrad.Beckmann@amd.com                       DataBlock& data,
759773Snilay@cs.wisc.edu                       const bool externalHit = false,
769773Snilay@cs.wisc.edu                       const MachineType mach = MachineType_NUM,
779773Snilay@cs.wisc.edu                       const Cycles initialRequestTime = Cycles(0),
789773Snilay@cs.wisc.edu                       const Cycles forwardRequestTime = Cycles(0),
799773Snilay@cs.wisc.edu                       const Cycles firstResponseTime = Cycles(0));
806145Snate@binkert.org
819507Snilay@cs.wisc.edu    void readCallback(const Address& address,
827565SBrad.Beckmann@amd.com                      DataBlock& data,
839773Snilay@cs.wisc.edu                      const bool externalHit = false,
849773Snilay@cs.wisc.edu                      const MachineType mach = MachineType_NUM,
859773Snilay@cs.wisc.edu                      const Cycles initialRequestTime = Cycles(0),
869773Snilay@cs.wisc.edu                      const Cycles forwardRequestTime = Cycles(0),
879773Snilay@cs.wisc.edu                      const Cycles firstResponseTime = Cycles(0));
887565SBrad.Beckmann@amd.com
898615Snilay@cs.wisc.edu    RequestStatus makeRequest(PacketPtr pkt);
907039Snate@binkert.org    bool empty() const;
918688Snilay@cs.wisc.edu    int outstandingCount() const { return m_outstanding_count; }
928688Snilay@cs.wisc.edu
939598Snilay@cs.wisc.edu    bool isDeadlockEventScheduled() const
949598Snilay@cs.wisc.edu    { return deadlockCheckEvent.scheduled(); }
959598Snilay@cs.wisc.edu
969598Snilay@cs.wisc.edu    void descheduleDeadlockEvent()
979598Snilay@cs.wisc.edu    { deschedule(deadlockCheckEvent); }
986145Snate@binkert.org
997055Snate@binkert.org    void print(std::ostream& out) const;
1007039Snate@binkert.org    void checkCoherence(const Address& address);
1016145Snate@binkert.org
1027455Snate@binkert.org    void markRemoved();
1037039Snate@binkert.org    void removeRequest(SequencerRequest* request);
1048717Snilay@cs.wisc.edu    void evictionCallback(const Address& address);
1059563Sgope@wisc.edu    void invalidateSC(const Address& address);
1066145Snate@binkert.org
1079104Shestness@cs.utexas.edu    void recordRequestType(SequencerRequestType requestType);
10810012Snilay@cs.wisc.edu    Stats::Histogram& getOutstandReqHist() { return m_outstandReqHist; }
1099104Shestness@cs.utexas.edu
11010012Snilay@cs.wisc.edu    Stats::Histogram& getLatencyHist() { return m_latencyHist; }
11110012Snilay@cs.wisc.edu    Stats::Histogram& getTypeLatencyHist(uint32_t t)
11210012Snilay@cs.wisc.edu    { return *m_typeLatencyHist[t]; }
1139773Snilay@cs.wisc.edu
11410012Snilay@cs.wisc.edu    Stats::Histogram& getHitLatencyHist() { return m_hitLatencyHist; }
11510012Snilay@cs.wisc.edu    Stats::Histogram& getHitTypeLatencyHist(uint32_t t)
11610012Snilay@cs.wisc.edu    { return *m_hitTypeLatencyHist[t]; }
1179773Snilay@cs.wisc.edu
11810012Snilay@cs.wisc.edu    Stats::Histogram& getHitMachLatencyHist(uint32_t t)
11910012Snilay@cs.wisc.edu    { return *m_hitMachLatencyHist[t]; }
1209773Snilay@cs.wisc.edu
12110012Snilay@cs.wisc.edu    Stats::Histogram& getHitTypeMachLatencyHist(uint32_t r, uint32_t t)
12210012Snilay@cs.wisc.edu    { return *m_hitTypeMachLatencyHist[r][t]; }
1239773Snilay@cs.wisc.edu
12410012Snilay@cs.wisc.edu    Stats::Histogram& getMissLatencyHist()
12510012Snilay@cs.wisc.edu    { return m_missLatencyHist; }
12610012Snilay@cs.wisc.edu    Stats::Histogram& getMissTypeLatencyHist(uint32_t t)
12710012Snilay@cs.wisc.edu    { return *m_missTypeLatencyHist[t]; }
1289773Snilay@cs.wisc.edu
12910012Snilay@cs.wisc.edu    Stats::Histogram& getMissMachLatencyHist(uint32_t t) const
13010012Snilay@cs.wisc.edu    { return *m_missMachLatencyHist[t]; }
1319773Snilay@cs.wisc.edu
13210012Snilay@cs.wisc.edu    Stats::Histogram&
13310012Snilay@cs.wisc.edu    getMissTypeMachLatencyHist(uint32_t r, uint32_t t) const
13410012Snilay@cs.wisc.edu    { return *m_missTypeMachLatencyHist[r][t]; }
1359773Snilay@cs.wisc.edu
13610012Snilay@cs.wisc.edu    Stats::Histogram& getIssueToInitialDelayHist(uint32_t t) const
13710012Snilay@cs.wisc.edu    { return *m_IssueToInitialDelayHist[t]; }
1389773Snilay@cs.wisc.edu
13910012Snilay@cs.wisc.edu    Stats::Histogram&
14010012Snilay@cs.wisc.edu    getInitialToForwardDelayHist(const MachineType t) const
14110012Snilay@cs.wisc.edu    { return *m_InitialToForwardDelayHist[t]; }
1429773Snilay@cs.wisc.edu
14310012Snilay@cs.wisc.edu    Stats::Histogram&
14410012Snilay@cs.wisc.edu    getForwardRequestToFirstResponseHist(const MachineType t) const
14510012Snilay@cs.wisc.edu    { return *m_ForwardToFirstResponseDelayHist[t]; }
1469773Snilay@cs.wisc.edu
14710012Snilay@cs.wisc.edu    Stats::Histogram&
14810012Snilay@cs.wisc.edu    getFirstResponseToCompletionDelayHist(const MachineType t) const
14910012Snilay@cs.wisc.edu    { return *m_FirstResponseToCompletionDelayHist[t]; }
1509773Snilay@cs.wisc.edu
15110012Snilay@cs.wisc.edu    Stats::Counter getIncompleteTimes(const MachineType t) const
1529773Snilay@cs.wisc.edu    { return m_IncompleteTimes[t]; }
1539773Snilay@cs.wisc.edu
1547039Snate@binkert.org  private:
1558615Snilay@cs.wisc.edu    void issueRequest(PacketPtr pkt, RubyRequestType type);
1566145Snate@binkert.org
1579773Snilay@cs.wisc.edu    void hitCallback(SequencerRequest* request, DataBlock& data,
1589773Snilay@cs.wisc.edu                     bool llscSuccess,
1599773Snilay@cs.wisc.edu                     const MachineType mach, const bool externalHit,
1609773Snilay@cs.wisc.edu                     const Cycles initialRequestTime,
1619773Snilay@cs.wisc.edu                     const Cycles forwardRequestTime,
1629773Snilay@cs.wisc.edu                     const Cycles firstResponseTime);
1639773Snilay@cs.wisc.edu
1649773Snilay@cs.wisc.edu    void recordMissLatency(const Cycles t, const RubyRequestType type,
1659773Snilay@cs.wisc.edu                           const MachineType respondingMach,
1669773Snilay@cs.wisc.edu                           bool isExternalHit, Cycles issuedTime,
1679773Snilay@cs.wisc.edu                           Cycles initialRequestTime,
1689773Snilay@cs.wisc.edu                           Cycles forwardRequestTime, Cycles firstResponseTime,
1699773Snilay@cs.wisc.edu                           Cycles completionTime);
1707546SBrad.Beckmann@amd.com
1718615Snilay@cs.wisc.edu    RequestStatus insertRequest(PacketPtr pkt, RubyRequestType request_type);
1727560SBrad.Beckmann@amd.com    bool handleLlsc(const Address& address, SequencerRequest* request);
1736145Snate@binkert.org
1747039Snate@binkert.org    // Private copy constructor and assignment operator
1757039Snate@binkert.org    Sequencer(const Sequencer& obj);
1767039Snate@binkert.org    Sequencer& operator=(const Sequencer& obj);
1776145Snate@binkert.org
1787039Snate@binkert.org  private:
1797039Snate@binkert.org    int m_max_outstanding_requests;
1809184Sandreas.hansson@arm.com    Cycles m_deadlock_threshold;
1816145Snate@binkert.org
1827039Snate@binkert.org    CacheMemory* m_dataCache_ptr;
1837039Snate@binkert.org    CacheMemory* m_instCache_ptr;
1846285Snate@binkert.org
1857455Snate@binkert.org    typedef m5::hash_map<Address, SequencerRequest*> RequestTable;
1867455Snate@binkert.org    RequestTable m_writeRequestTable;
1877455Snate@binkert.org    RequestTable m_readRequestTable;
1887039Snate@binkert.org    // Global outstanding request count, across all request tables
1897039Snate@binkert.org    int m_outstanding_count;
1907039Snate@binkert.org    bool m_deadlock_check_scheduled;
1916145Snate@binkert.org
19210012Snilay@cs.wisc.edu    //! Counters for recording aliasing information.
19310012Snilay@cs.wisc.edu    Stats::Scalar m_store_waiting_on_load;
19410012Snilay@cs.wisc.edu    Stats::Scalar m_store_waiting_on_store;
19510012Snilay@cs.wisc.edu    Stats::Scalar m_load_waiting_on_store;
19610012Snilay@cs.wisc.edu    Stats::Scalar m_load_waiting_on_load;
1976859Sdrh5@cs.wisc.edu
1988171Stushar@csail.mit.edu    bool m_usingNetworkTester;
1998171Stushar@csail.mit.edu
2009598Snilay@cs.wisc.edu    //! Histogram for number of outstanding requests per cycle.
20110012Snilay@cs.wisc.edu    Stats::Histogram m_outstandReqHist;
2029598Snilay@cs.wisc.edu
2039773Snilay@cs.wisc.edu    //! Histogram for holding latency profile of all requests.
20410012Snilay@cs.wisc.edu    Stats::Histogram m_latencyHist;
20510012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_typeLatencyHist;
2069773Snilay@cs.wisc.edu
2079773Snilay@cs.wisc.edu    //! Histogram for holding latency profile of all requests that
2089773Snilay@cs.wisc.edu    //! hit in the controller connected to this sequencer.
20910012Snilay@cs.wisc.edu    Stats::Histogram m_hitLatencyHist;
21010012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_hitTypeLatencyHist;
2119773Snilay@cs.wisc.edu
2129773Snilay@cs.wisc.edu    //! Histograms for profiling the latencies for requests that
2139773Snilay@cs.wisc.edu    //! did not required external messages.
21410012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_hitMachLatencyHist;
21510012Snilay@cs.wisc.edu    std::vector< std::vector<Stats::Histogram *> > m_hitTypeMachLatencyHist;
2169773Snilay@cs.wisc.edu
2179773Snilay@cs.wisc.edu    //! Histogram for holding latency profile of all requests that
2189773Snilay@cs.wisc.edu    //! miss in the controller connected to this sequencer.
21910012Snilay@cs.wisc.edu    Stats::Histogram m_missLatencyHist;
22010012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_missTypeLatencyHist;
2219773Snilay@cs.wisc.edu
2229773Snilay@cs.wisc.edu    //! Histograms for profiling the latencies for requests that
2239773Snilay@cs.wisc.edu    //! required external messages.
22410012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_missMachLatencyHist;
22510012Snilay@cs.wisc.edu    std::vector< std::vector<Stats::Histogram *> > m_missTypeMachLatencyHist;
2269773Snilay@cs.wisc.edu
2279773Snilay@cs.wisc.edu    //! Histograms for recording the breakdown of miss latency
22810012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_IssueToInitialDelayHist;
22910012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_InitialToForwardDelayHist;
23010012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_ForwardToFirstResponseDelayHist;
23110012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_FirstResponseToCompletionDelayHist;
23210012Snilay@cs.wisc.edu    std::vector<Stats::Counter> m_IncompleteTimes;
2339773Snilay@cs.wisc.edu
2349773Snilay@cs.wisc.edu
2357039Snate@binkert.org    class SequencerWakeupEvent : public Event
2367039Snate@binkert.org    {
2377039Snate@binkert.org      private:
2387039Snate@binkert.org        Sequencer *m_sequencer_ptr;
2396899SBrad.Beckmann@amd.com
2407039Snate@binkert.org      public:
2417039Snate@binkert.org        SequencerWakeupEvent(Sequencer *_seq) : m_sequencer_ptr(_seq) {}
2427039Snate@binkert.org        void process() { m_sequencer_ptr->wakeup(); }
2437039Snate@binkert.org        const char *description() const { return "Sequencer deadlock check"; }
2447039Snate@binkert.org    };
2456886SBrad.Beckmann@amd.com
2467039Snate@binkert.org    SequencerWakeupEvent deadlockCheckEvent;
2476145Snate@binkert.org};
2486145Snate@binkert.org
2497055Snate@binkert.orginline std::ostream&
2507055Snate@binkert.orgoperator<<(std::ostream& out, const Sequencer& obj)
2516145Snate@binkert.org{
2527039Snate@binkert.org    obj.print(out);
2537055Snate@binkert.org    out << std::flush;
2547039Snate@binkert.org    return out;
2556145Snate@binkert.org}
2566145Snate@binkert.org
2577039Snate@binkert.org#endif // __MEM_RUBY_SYSTEM_SEQUENCER_HH__
258