AbstractController.hh revision 12065
17008Snate@binkert.org/*
212065Snikos.nikoleris@arm.com * Copyright (c) 2017 ARM Limited
312065Snikos.nikoleris@arm.com * All rights reserved.
412065Snikos.nikoleris@arm.com *
512065Snikos.nikoleris@arm.com * The license below extends only to copyright in the software and shall
612065Snikos.nikoleris@arm.com * not be construed as granting a license to any other intellectual
712065Snikos.nikoleris@arm.com * property including but not limited to intellectual property relating
812065Snikos.nikoleris@arm.com * to a hardware implementation of the functionality of the software
912065Snikos.nikoleris@arm.com * licensed hereunder.  You may use the software subject to the license
1012065Snikos.nikoleris@arm.com * terms below provided that you ensure that this notice is replicated
1112065Snikos.nikoleris@arm.com * unmodified and in its entirety in all distributions of the software,
1212065Snikos.nikoleris@arm.com * modified or unmodified, in source code or in binary form.
1312065Snikos.nikoleris@arm.com *
1410524Snilay@cs.wisc.edu * Copyright (c) 2009-2014 Mark D. Hill and David A. Wood
157008Snate@binkert.org * All rights reserved.
167008Snate@binkert.org *
177008Snate@binkert.org * Redistribution and use in source and binary forms, with or without
187008Snate@binkert.org * modification, are permitted provided that the following conditions are
197008Snate@binkert.org * met: redistributions of source code must retain the above copyright
207008Snate@binkert.org * notice, this list of conditions and the following disclaimer;
217008Snate@binkert.org * redistributions in binary form must reproduce the above copyright
227008Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
237008Snate@binkert.org * documentation and/or other materials provided with the distribution;
247008Snate@binkert.org * neither the name of the copyright holders nor the names of its
257008Snate@binkert.org * contributors may be used to endorse or promote products derived from
267008Snate@binkert.org * this software without specific prior written permission.
277008Snate@binkert.org *
287008Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
297008Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
307008Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
317008Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
327008Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
337008Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
347008Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
357008Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
367008Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
377008Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
387008Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
397008Snate@binkert.org */
406285Snate@binkert.org
417039Snate@binkert.org#ifndef __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
427039Snate@binkert.org#define __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
436285Snate@binkert.org
4410963Sdavid.hashe@amd.com#include <exception>
457055Snate@binkert.org#include <iostream>
467055Snate@binkert.org#include <string>
476876Ssteve.reinhardt@amd.com
4812065Snikos.nikoleris@arm.com#include "base/addr_range.hh"
499745Snilay@cs.wisc.edu#include "base/callback.hh"
5012065Snikos.nikoleris@arm.com#include "mem/mem_object.hh"
5112065Snikos.nikoleris@arm.com#include "mem/packet.hh"
528341Snilay@cs.wisc.edu#include "mem/protocol/AccessPermission.hh"
5312065Snikos.nikoleris@arm.com#include "mem/qport.hh"
546506Spdudnik@gmail.com#include "mem/ruby/common/Address.hh"
557055Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
568436SBrad.Beckmann@amd.com#include "mem/ruby/common/DataBlock.hh"
579497Snilay@cs.wisc.edu#include "mem/ruby/common/Histogram.hh"
5810301Snilay@cs.wisc.edu#include "mem/ruby/common/MachineID.hh"
5910301Snilay@cs.wisc.edu#include "mem/ruby/network/MessageBuffer.hh"
6010301Snilay@cs.wisc.edu#include "mem/ruby/system/CacheRecorder.hh"
617055Snate@binkert.org#include "params/RubyController.hh"
626285Snate@binkert.org
636285Snate@binkert.orgclass Network;
6411309Sdavid.hashe@amd.comclass GPUCoalescer;
656285Snate@binkert.org
6610963Sdavid.hashe@amd.com// used to communicate that an in_port peeked the wrong message type
6710963Sdavid.hashe@amd.comclass RejectException: public std::exception
6810963Sdavid.hashe@amd.com{
6910963Sdavid.hashe@amd.com    virtual const char* what() const throw()
7010963Sdavid.hashe@amd.com    { return "Port rejected message based on type"; }
7110963Sdavid.hashe@amd.com};
7210963Sdavid.hashe@amd.com
7310524Snilay@cs.wisc.educlass AbstractController : public MemObject, public Consumer
747039Snate@binkert.org{
757039Snate@binkert.org  public:
766876Ssteve.reinhardt@amd.com    typedef RubyControllerParams Params;
778436SBrad.Beckmann@amd.com    AbstractController(const Params *p);
789496Snilay@cs.wisc.edu    void init();
798257SBrad.Beckmann@amd.com    const Params *params() const { return (const Params *)_params; }
809745Snilay@cs.wisc.edu
8111294Sandreas.hansson@arm.com    NodeID getVersion() const { return m_machineID.getNum(); }
8211294Sandreas.hansson@arm.com    MachineType getType() const { return m_machineID.getType(); }
8310078Snilay@cs.wisc.edu
849819Snilay@cs.wisc.edu    void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; }
859819Snilay@cs.wisc.edu
869819Snilay@cs.wisc.edu    // return instance name
8711025Snilay@cs.wisc.edu    void blockOnQueue(Addr, MessageBuffer*);
8811448Sjthestness@gmail.com    bool isBlocked(Addr) const;
8911025Snilay@cs.wisc.edu    void unblock(Addr);
9011308Santhony.gutierrez@amd.com    bool isBlocked(Addr);
919819Snilay@cs.wisc.edu
927039Snate@binkert.org    virtual MessageBuffer* getMandatoryQueue() const = 0;
9311021Sjthestness@gmail.com    virtual MessageBuffer* getMemoryQueue() const = 0;
9411025Snilay@cs.wisc.edu    virtual AccessPermission getAccessPermission(const Addr &addr) = 0;
956285Snate@binkert.org
967055Snate@binkert.org    virtual void print(std::ostream & out) const = 0;
977039Snate@binkert.org    virtual void wakeup() = 0;
9810012Snilay@cs.wisc.edu    virtual void resetStats() = 0;
9910012Snilay@cs.wisc.edu    virtual void regStats();
1009745Snilay@cs.wisc.edu
1018683Snilay@cs.wisc.edu    virtual void recordCacheTrace(int cntrl, CacheRecorder* tr) = 0;
10211308Santhony.gutierrez@amd.com    virtual Sequencer* getCPUSequencer() const = 0;
10311309Sdavid.hashe@amd.com    virtual GPUCoalescer* getGPUCoalescer() const = 0;
1049302Snilay@cs.wisc.edu
10510523Snilay@cs.wisc.edu    //! These functions are used by ruby system to read/write the data blocks
10610523Snilay@cs.wisc.edu    //! that exist with in the controller.
10711025Snilay@cs.wisc.edu    virtual void functionalRead(const Addr &addr, PacketPtr) = 0;
10810524Snilay@cs.wisc.edu    void functionalMemoryRead(PacketPtr);
1099302Snilay@cs.wisc.edu    //! The return value indicates the number of messages written with the
1109302Snilay@cs.wisc.edu    //! data from the packet.
11110524Snilay@cs.wisc.edu    virtual int functionalWriteBuffers(PacketPtr&) = 0;
11211025Snilay@cs.wisc.edu    virtual int functionalWrite(const Addr &addr, PacketPtr) = 0;
11310524Snilay@cs.wisc.edu    int functionalMemoryWrite(PacketPtr);
1149363Snilay@cs.wisc.edu
1159363Snilay@cs.wisc.edu    //! Function for enqueuing a prefetch request
11611025Snilay@cs.wisc.edu    virtual void enqueuePrefetch(const Addr &, const RubyRequestType&)
1179363Snilay@cs.wisc.edu    { fatal("Prefetches not implemented!");}
1189364Snilay@cs.wisc.edu
1199745Snilay@cs.wisc.edu    //! Function for collating statistics from all the controllers of this
1209745Snilay@cs.wisc.edu    //! particular type. This function should only be called from the
1219745Snilay@cs.wisc.edu    //! version 0 of this controller type.
1229745Snilay@cs.wisc.edu    virtual void collateStats()
1239745Snilay@cs.wisc.edu    {fatal("collateStats() should be overridden!");}
1249745Snilay@cs.wisc.edu
12511021Sjthestness@gmail.com    //! Initialize the message buffers.
12611021Sjthestness@gmail.com    virtual void initNetQueues() = 0;
12710311Snilay@cs.wisc.edu
12810524Snilay@cs.wisc.edu    /** A function used to return the port associated with this bus object. */
12910524Snilay@cs.wisc.edu    BaseMasterPort& getMasterPort(const std::string& if_name,
13010524Snilay@cs.wisc.edu                                  PortID idx = InvalidPortID);
13110524Snilay@cs.wisc.edu
13211025Snilay@cs.wisc.edu    void queueMemoryRead(const MachineID &id, Addr addr, Cycles latency);
13311025Snilay@cs.wisc.edu    void queueMemoryWrite(const MachineID &id, Addr addr, Cycles latency,
13410524Snilay@cs.wisc.edu                          const DataBlock &block);
13511025Snilay@cs.wisc.edu    void queueMemoryWritePartial(const MachineID &id, Addr addr, Cycles latency,
13610524Snilay@cs.wisc.edu                                 const DataBlock &block, int size);
13710524Snilay@cs.wisc.edu    void recvTimingResp(PacketPtr pkt);
13810524Snilay@cs.wisc.edu
13912065Snikos.nikoleris@arm.com    const AddrRangeList &getAddrRanges() const { return addrRanges; }
14012065Snikos.nikoleris@arm.com
1419496Snilay@cs.wisc.edu  public:
1429496Snilay@cs.wisc.edu    MachineID getMachineID() const { return m_machineID; }
1439496Snilay@cs.wisc.edu
14410012Snilay@cs.wisc.edu    Stats::Histogram& getDelayHist() { return m_delayHistogram; }
14510012Snilay@cs.wisc.edu    Stats::Histogram& getDelayVCHist(uint32_t index)
14610012Snilay@cs.wisc.edu    { return *(m_delayVCHistogram[index]); }
1479497Snilay@cs.wisc.edu
14812065Snikos.nikoleris@arm.com    /**
14912065Snikos.nikoleris@arm.com     * Map an address to the correct MachineID
15012065Snikos.nikoleris@arm.com     *
15112065Snikos.nikoleris@arm.com     * This function querries the network for the NodeID of the
15212065Snikos.nikoleris@arm.com     * destination for a given request using its address and the type
15312065Snikos.nikoleris@arm.com     * of the destination. For example for a request with a given
15412065Snikos.nikoleris@arm.com     * address to a directory it will return the MachineID of the
15512065Snikos.nikoleris@arm.com     * authorative directory.
15612065Snikos.nikoleris@arm.com     *
15712065Snikos.nikoleris@arm.com     * @param the destination address
15812065Snikos.nikoleris@arm.com     * @param the type of the destination
15912065Snikos.nikoleris@arm.com     * @return the MachineID of the destination
16012065Snikos.nikoleris@arm.com     */
16112065Snikos.nikoleris@arm.com    MachineID mapAddressToMachine(Addr addr, MachineType mtype) const;
16212065Snikos.nikoleris@arm.com
1639496Snilay@cs.wisc.edu  protected:
1649496Snilay@cs.wisc.edu    //! Profiles original cache requests including PUTs
1659496Snilay@cs.wisc.edu    void profileRequest(const std::string &request);
1669497Snilay@cs.wisc.edu    //! Profiles the delay associated with messages.
1679507Snilay@cs.wisc.edu    void profileMsgDelay(uint32_t virtualNetwork, Cycles delay);
1689496Snilay@cs.wisc.edu
16911025Snilay@cs.wisc.edu    void stallBuffer(MessageBuffer* buf, Addr addr);
17011025Snilay@cs.wisc.edu    void wakeUpBuffers(Addr addr);
17111025Snilay@cs.wisc.edu    void wakeUpAllBuffers(Addr addr);
1729596Snilay@cs.wisc.edu    void wakeUpAllBuffers();
1739596Snilay@cs.wisc.edu
1749364Snilay@cs.wisc.edu  protected:
17511121Snilay@cs.wisc.edu    const NodeID m_version;
17610005Snilay@cs.wisc.edu    MachineID m_machineID;
17711121Snilay@cs.wisc.edu    const NodeID m_clusterID;
17810005Snilay@cs.wisc.edu
17910524Snilay@cs.wisc.edu    // MasterID used by some components of gem5.
18011121Snilay@cs.wisc.edu    const MasterID m_masterId;
18110524Snilay@cs.wisc.edu
18211121Snilay@cs.wisc.edu    Network *m_net_ptr;
1839364Snilay@cs.wisc.edu    bool m_is_blocking;
18411025Snilay@cs.wisc.edu    std::map<Addr, MessageBuffer*> m_block_map;
18510087Snilay@cs.wisc.edu
1869364Snilay@cs.wisc.edu    typedef std::vector<MessageBuffer*> MsgVecType;
18710977Sdavid.hashe@amd.com    typedef std::set<MessageBuffer*> MsgBufType;
18811025Snilay@cs.wisc.edu    typedef std::map<Addr, MsgVecType* > WaitingBufType;
1899364Snilay@cs.wisc.edu    WaitingBufType m_waiting_buffers;
19010087Snilay@cs.wisc.edu
1919996Snilay@cs.wisc.edu    unsigned int m_in_ports;
1929996Snilay@cs.wisc.edu    unsigned int m_cur_in_port;
19311121Snilay@cs.wisc.edu    const int m_number_of_TBEs;
19411121Snilay@cs.wisc.edu    const int m_transitions_per_cycle;
19511121Snilay@cs.wisc.edu    const unsigned int m_buffer_size;
19610005Snilay@cs.wisc.edu    Cycles m_recycle_latency;
1979496Snilay@cs.wisc.edu
1989496Snilay@cs.wisc.edu    //! Counter for the number of cycles when the transitions carried out
1999496Snilay@cs.wisc.edu    //! were equal to the maximum allowed
20010012Snilay@cs.wisc.edu    Stats::Scalar m_fully_busy_cycles;
2019497Snilay@cs.wisc.edu
2029497Snilay@cs.wisc.edu    //! Histogram for profiling delay for the messages this controller
2039497Snilay@cs.wisc.edu    //! cares for
20410012Snilay@cs.wisc.edu    Stats::Histogram m_delayHistogram;
20510012Snilay@cs.wisc.edu    std::vector<Stats::Histogram *> m_delayVCHistogram;
2069745Snilay@cs.wisc.edu
2079745Snilay@cs.wisc.edu    //! Callback class used for collating statistics from all the
2089745Snilay@cs.wisc.edu    //! controller of this type.
2099745Snilay@cs.wisc.edu    class StatsCallback : public Callback
2109745Snilay@cs.wisc.edu    {
2119745Snilay@cs.wisc.edu      private:
2129745Snilay@cs.wisc.edu        AbstractController *ctr;
2139745Snilay@cs.wisc.edu
2149745Snilay@cs.wisc.edu      public:
2159745Snilay@cs.wisc.edu        virtual ~StatsCallback() {}
21610012Snilay@cs.wisc.edu        StatsCallback(AbstractController *_ctr) : ctr(_ctr) {}
2179745Snilay@cs.wisc.edu        void process() {ctr->collateStats();}
2189745Snilay@cs.wisc.edu    };
21910524Snilay@cs.wisc.edu
22010524Snilay@cs.wisc.edu    /**
22110524Snilay@cs.wisc.edu     * Port that forwards requests and receives responses from the
22210524Snilay@cs.wisc.edu     * memory controller.  It has a queue of packets not yet sent.
22310524Snilay@cs.wisc.edu     */
22410524Snilay@cs.wisc.edu    class MemoryPort : public QueuedMasterPort
22510524Snilay@cs.wisc.edu    {
22610524Snilay@cs.wisc.edu      private:
22710713Sandreas.hansson@arm.com        // Packet queues used to store outgoing requests and snoop responses.
22810713Sandreas.hansson@arm.com        ReqPacketQueue reqQueue;
22910713Sandreas.hansson@arm.com        SnoopRespPacketQueue snoopRespQueue;
23010524Snilay@cs.wisc.edu
23110524Snilay@cs.wisc.edu        // Controller that operates this port.
23210524Snilay@cs.wisc.edu        AbstractController *controller;
23310524Snilay@cs.wisc.edu
23410524Snilay@cs.wisc.edu      public:
23510524Snilay@cs.wisc.edu        MemoryPort(const std::string &_name, AbstractController *_controller,
23610524Snilay@cs.wisc.edu                   const std::string &_label);
23710524Snilay@cs.wisc.edu
23810524Snilay@cs.wisc.edu        // Function for receiving a timing response from the peer port.
23910524Snilay@cs.wisc.edu        // Currently the pkt is handed to the coherence controller
24010524Snilay@cs.wisc.edu        // associated with this port.
24110524Snilay@cs.wisc.edu        bool recvTimingResp(PacketPtr pkt);
24210524Snilay@cs.wisc.edu    };
24310524Snilay@cs.wisc.edu
24410524Snilay@cs.wisc.edu    /* Master port to the memory controller. */
24510524Snilay@cs.wisc.edu    MemoryPort memoryPort;
24610524Snilay@cs.wisc.edu
24710524Snilay@cs.wisc.edu    // State that is stored in packets sent to the memory controller.
24810524Snilay@cs.wisc.edu    struct SenderState : public Packet::SenderState
24910524Snilay@cs.wisc.edu    {
25010524Snilay@cs.wisc.edu        // Id of the machine from which the request originated.
25110524Snilay@cs.wisc.edu        MachineID id;
25210524Snilay@cs.wisc.edu
25310524Snilay@cs.wisc.edu        SenderState(MachineID _id) : id(_id)
25410524Snilay@cs.wisc.edu        {}
25510524Snilay@cs.wisc.edu    };
25612065Snikos.nikoleris@arm.com
25712065Snikos.nikoleris@arm.com  private:
25812065Snikos.nikoleris@arm.com    /** The address range to which the controller responds on the CPU side. */
25912065Snikos.nikoleris@arm.com    const AddrRangeList addrRanges;
2606285Snate@binkert.org};
2616285Snate@binkert.org
2627039Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
263