AbstractController.hh revision 9819
17008Snate@binkert.org/*
27008Snate@binkert.org * Copyright (c) 2009 Mark D. Hill and David A. Wood
37008Snate@binkert.org * All rights reserved.
47008Snate@binkert.org *
57008Snate@binkert.org * Redistribution and use in source and binary forms, with or without
67008Snate@binkert.org * modification, are permitted provided that the following conditions are
77008Snate@binkert.org * met: redistributions of source code must retain the above copyright
87008Snate@binkert.org * notice, this list of conditions and the following disclaimer;
97008Snate@binkert.org * redistributions in binary form must reproduce the above copyright
107008Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
117008Snate@binkert.org * documentation and/or other materials provided with the distribution;
127008Snate@binkert.org * neither the name of the copyright holders nor the names of its
137008Snate@binkert.org * contributors may be used to endorse or promote products derived from
147008Snate@binkert.org * this software without specific prior written permission.
157008Snate@binkert.org *
167008Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177008Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187008Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197008Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207008Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217008Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227008Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237008Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247008Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257008Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267008Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277008Snate@binkert.org */
286285Snate@binkert.org
297039Snate@binkert.org#ifndef __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
307039Snate@binkert.org#define __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
316285Snate@binkert.org
327055Snate@binkert.org#include <iostream>
337055Snate@binkert.org#include <string>
346876Ssteve.reinhardt@amd.com
359745Snilay@cs.wisc.edu#include "base/callback.hh"
368341Snilay@cs.wisc.edu#include "mem/protocol/AccessPermission.hh"
379596Snilay@cs.wisc.edu#include "mem/ruby/buffers/MessageBuffer.hh"
386506Spdudnik@gmail.com#include "mem/ruby/common/Address.hh"
397055Snate@binkert.org#include "mem/ruby/common/Consumer.hh"
408436SBrad.Beckmann@amd.com#include "mem/ruby/common/DataBlock.hh"
419497Snilay@cs.wisc.edu#include "mem/ruby/common/Histogram.hh"
426881SBrad.Beckmann@amd.com#include "mem/ruby/network/Network.hh"
438683Snilay@cs.wisc.edu#include "mem/ruby/recorder/CacheRecorder.hh"
449364Snilay@cs.wisc.edu#include "mem/ruby/system/MachineID.hh"
459364Snilay@cs.wisc.edu#include "mem/packet.hh"
467055Snate@binkert.org#include "params/RubyController.hh"
479465Snilay@cs.wisc.edu#include "sim/clocked_object.hh"
486285Snate@binkert.org
496285Snate@binkert.orgclass Network;
506285Snate@binkert.org
519465Snilay@cs.wisc.educlass AbstractController : public ClockedObject, public Consumer
527039Snate@binkert.org{
537039Snate@binkert.org  public:
546876Ssteve.reinhardt@amd.com    typedef RubyControllerParams Params;
558436SBrad.Beckmann@amd.com    AbstractController(const Params *p);
569496Snilay@cs.wisc.edu    void init();
578257SBrad.Beckmann@amd.com    const Params *params() const { return (const Params *)_params; }
589745Snilay@cs.wisc.edu
599819Snilay@cs.wisc.edu    const int & getVersion() const { return m_version; }
609819Snilay@cs.wisc.edu    void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; }
619819Snilay@cs.wisc.edu
629819Snilay@cs.wisc.edu    // return instance name
639819Snilay@cs.wisc.edu    const std::string getName() const { return m_name; }
649819Snilay@cs.wisc.edu    void blockOnQueue(Address, MessageBuffer*);
659819Snilay@cs.wisc.edu    void unblock(Address);
669819Snilay@cs.wisc.edu
677039Snate@binkert.org    virtual MessageBuffer* getMandatoryQueue() const = 0;
687055Snate@binkert.org    virtual const std::string toString() const = 0;  // returns text version of
697055Snate@binkert.org                                                     // controller type
708531Snilay@cs.wisc.edu    virtual AccessPermission getAccessPermission(const Address& addr) = 0;
718531Snilay@cs.wisc.edu    virtual DataBlock& getDataBlock(const Address& addr) = 0;
726285Snate@binkert.org
737055Snate@binkert.org    virtual void print(std::ostream & out) const = 0;
747055Snate@binkert.org    virtual void printStats(std::ostream & out) const = 0;
757039Snate@binkert.org    virtual void wakeup() = 0;
767039Snate@binkert.org    virtual void clearStats() = 0;
779745Snilay@cs.wisc.edu    virtual void regStats() = 0;
789745Snilay@cs.wisc.edu
798683Snilay@cs.wisc.edu    virtual void recordCacheTrace(int cntrl, CacheRecorder* tr) = 0;
808683Snilay@cs.wisc.edu    virtual Sequencer* getSequencer() const = 0;
819302Snilay@cs.wisc.edu
829302Snilay@cs.wisc.edu    //! These functions are used by ruby system to read/write the message
839302Snilay@cs.wisc.edu    //! queues that exist with in the controller.
849302Snilay@cs.wisc.edu    //! The boolean return value indicates if the read was performed
859302Snilay@cs.wisc.edu    //! successfully.
869302Snilay@cs.wisc.edu    virtual bool functionalReadBuffers(PacketPtr&) = 0;
879302Snilay@cs.wisc.edu    //! The return value indicates the number of messages written with the
889302Snilay@cs.wisc.edu    //! data from the packet.
899302Snilay@cs.wisc.edu    virtual uint32_t functionalWriteBuffers(PacketPtr&) = 0;
909363Snilay@cs.wisc.edu
919363Snilay@cs.wisc.edu    //! Function for enqueuing a prefetch request
929363Snilay@cs.wisc.edu    virtual void enqueuePrefetch(const Address&, const RubyRequestType&)
939363Snilay@cs.wisc.edu    { fatal("Prefetches not implemented!");}
949364Snilay@cs.wisc.edu
959745Snilay@cs.wisc.edu    //! Function for collating statistics from all the controllers of this
969745Snilay@cs.wisc.edu    //! particular type. This function should only be called from the
979745Snilay@cs.wisc.edu    //! version 0 of this controller type.
989745Snilay@cs.wisc.edu    virtual void collateStats()
999745Snilay@cs.wisc.edu    {fatal("collateStats() should be overridden!");}
1009745Snilay@cs.wisc.edu
1019496Snilay@cs.wisc.edu  public:
1029496Snilay@cs.wisc.edu    MachineID getMachineID() const { return m_machineID; }
1039496Snilay@cs.wisc.edu    uint64_t getFullyBusyCycles() const { return m_fully_busy_cycles; }
1049496Snilay@cs.wisc.edu    uint64_t getRequestCount() const { return m_request_count; }
1059496Snilay@cs.wisc.edu    const std::map<std::string, uint64_t>& getRequestProfileMap() const
1069496Snilay@cs.wisc.edu    { return m_requestProfileMap; }
1079496Snilay@cs.wisc.edu
1089497Snilay@cs.wisc.edu    Histogram& getDelayHist() { return m_delayHistogram; }
1099497Snilay@cs.wisc.edu    Histogram& getDelayVCHist(uint32_t index)
1109497Snilay@cs.wisc.edu    { return m_delayVCHistogram[index]; }
1119497Snilay@cs.wisc.edu
1129595Snilay@cs.wisc.edu    MessageBuffer *getPeerQueue(uint32_t pid)
1139595Snilay@cs.wisc.edu    {
1149595Snilay@cs.wisc.edu        std::map<uint32_t, MessageBuffer *>::iterator it =
1159595Snilay@cs.wisc.edu                                        peerQueueMap.find(pid);
1169595Snilay@cs.wisc.edu        assert(it != peerQueueMap.end());
1179595Snilay@cs.wisc.edu        return (*it).second;
1189595Snilay@cs.wisc.edu    }
1199595Snilay@cs.wisc.edu
1209496Snilay@cs.wisc.edu  protected:
1219496Snilay@cs.wisc.edu    //! Profiles original cache requests including PUTs
1229496Snilay@cs.wisc.edu    void profileRequest(const std::string &request);
1239497Snilay@cs.wisc.edu    //! Profiles the delay associated with messages.
1249507Snilay@cs.wisc.edu    void profileMsgDelay(uint32_t virtualNetwork, Cycles delay);
1259496Snilay@cs.wisc.edu
1269595Snilay@cs.wisc.edu    //! Function for connecting peer controllers
1279595Snilay@cs.wisc.edu    void connectWithPeer(AbstractController *);
1289595Snilay@cs.wisc.edu    virtual void getQueuesFromPeer(AbstractController *)
1299595Snilay@cs.wisc.edu    { fatal("getQueuesFromPeer() should be called only if implemented!"); }
1309595Snilay@cs.wisc.edu
1319596Snilay@cs.wisc.edu    void stallBuffer(MessageBuffer* buf, Address addr);
1329596Snilay@cs.wisc.edu    void wakeUpBuffers(Address addr);
1339596Snilay@cs.wisc.edu    void wakeUpAllBuffers(Address addr);
1349596Snilay@cs.wisc.edu    void wakeUpAllBuffers();
1359596Snilay@cs.wisc.edu
1369364Snilay@cs.wisc.edu  protected:
1379364Snilay@cs.wisc.edu    int m_transitions_per_cycle;
1389364Snilay@cs.wisc.edu    int m_buffer_size;
1399499Snilay@cs.wisc.edu    Cycles m_recycle_latency;
1409364Snilay@cs.wisc.edu    std::string m_name;
1419364Snilay@cs.wisc.edu    NodeID m_version;
1429364Snilay@cs.wisc.edu    Network* m_net_ptr;
1439364Snilay@cs.wisc.edu    MachineID m_machineID;
1449364Snilay@cs.wisc.edu    bool m_is_blocking;
1459364Snilay@cs.wisc.edu    std::map<Address, MessageBuffer*> m_block_map;
1469364Snilay@cs.wisc.edu    typedef std::vector<MessageBuffer*> MsgVecType;
1479364Snilay@cs.wisc.edu    typedef std::map< Address, MsgVecType* > WaitingBufType;
1489364Snilay@cs.wisc.edu    WaitingBufType m_waiting_buffers;
1499364Snilay@cs.wisc.edu    int m_max_in_port_rank;
1509364Snilay@cs.wisc.edu    int m_cur_in_port_rank;
1519364Snilay@cs.wisc.edu    int m_number_of_TBEs;
1529496Snilay@cs.wisc.edu
1539595Snilay@cs.wisc.edu    //! Map from physical network number to the Message Buffer.
1549595Snilay@cs.wisc.edu    std::map<uint32_t, MessageBuffer*> peerQueueMap;
1559595Snilay@cs.wisc.edu
1569496Snilay@cs.wisc.edu    //! Counter for the number of cycles when the transitions carried out
1579496Snilay@cs.wisc.edu    //! were equal to the maximum allowed
1589496Snilay@cs.wisc.edu    uint64_t m_fully_busy_cycles;
1599496Snilay@cs.wisc.edu
1609496Snilay@cs.wisc.edu    //! Map for couting requests of different types. The controller should
1619496Snilay@cs.wisc.edu    //! call requisite function for updating the count.
1629496Snilay@cs.wisc.edu    std::map<std::string, uint64_t> m_requestProfileMap;
1639496Snilay@cs.wisc.edu    uint64_t m_request_count;
1649497Snilay@cs.wisc.edu
1659497Snilay@cs.wisc.edu    //! Histogram for profiling delay for the messages this controller
1669497Snilay@cs.wisc.edu    //! cares for
1679497Snilay@cs.wisc.edu    Histogram m_delayHistogram;
1689497Snilay@cs.wisc.edu    std::vector<Histogram> m_delayVCHistogram;
1699745Snilay@cs.wisc.edu
1709745Snilay@cs.wisc.edu    //! Callback class used for collating statistics from all the
1719745Snilay@cs.wisc.edu    //! controller of this type.
1729745Snilay@cs.wisc.edu    class StatsCallback : public Callback
1739745Snilay@cs.wisc.edu    {
1749745Snilay@cs.wisc.edu      private:
1759745Snilay@cs.wisc.edu        AbstractController *ctr;
1769745Snilay@cs.wisc.edu
1779745Snilay@cs.wisc.edu      public:
1789745Snilay@cs.wisc.edu        virtual ~StatsCallback() {}
1799745Snilay@cs.wisc.edu
1809745Snilay@cs.wisc.edu        StatsCallback(AbstractController *_ctr)
1819745Snilay@cs.wisc.edu            : ctr(_ctr)
1829745Snilay@cs.wisc.edu        {
1839745Snilay@cs.wisc.edu        }
1849745Snilay@cs.wisc.edu
1859745Snilay@cs.wisc.edu        void process() {ctr->collateStats();}
1869745Snilay@cs.wisc.edu    };
1876285Snate@binkert.org};
1886285Snate@binkert.org
1897039Snate@binkert.org#endif // __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
190