AbstractController.hh revision 9996
17161Sgblack@eecs.umich.edu/*
27161Sgblack@eecs.umich.edu * Copyright (c) 2009 Mark D. Hill and David A. Wood
37161Sgblack@eecs.umich.edu * All rights reserved.
47161Sgblack@eecs.umich.edu *
57161Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
67161Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
77161Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
87161Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
97161Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
107161Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
117161Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
127161Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
137161Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
147161Sgblack@eecs.umich.edu * this software without specific prior written permission.
157161Sgblack@eecs.umich.edu *
167161Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177161Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187161Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197161Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207161Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217161Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227161Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237161Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247161Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257161Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267161Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277161Sgblack@eecs.umich.edu */
287161Sgblack@eecs.umich.edu
297161Sgblack@eecs.umich.edu#ifndef __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
307161Sgblack@eecs.umich.edu#define __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
317161Sgblack@eecs.umich.edu
327161Sgblack@eecs.umich.edu#include <iostream>
337161Sgblack@eecs.umich.edu#include <string>
347161Sgblack@eecs.umich.edu
357161Sgblack@eecs.umich.edu#include "base/callback.hh"
367161Sgblack@eecs.umich.edu#include "mem/protocol/AccessPermission.hh"
377161Sgblack@eecs.umich.edu#include "mem/ruby/buffers/MessageBuffer.hh"
387161Sgblack@eecs.umich.edu#include "mem/ruby/common/Address.hh"
397161Sgblack@eecs.umich.edu#include "mem/ruby/common/Consumer.hh"
407161Sgblack@eecs.umich.edu#include "mem/ruby/common/DataBlock.hh"
417161Sgblack@eecs.umich.edu#include "mem/ruby/common/Histogram.hh"
427161Sgblack@eecs.umich.edu#include "mem/ruby/network/Network.hh"
437161Sgblack@eecs.umich.edu#include "mem/ruby/recorder/CacheRecorder.hh"
447161Sgblack@eecs.umich.edu#include "mem/ruby/system/MachineID.hh"
457161Sgblack@eecs.umich.edu#include "mem/packet.hh"
467161Sgblack@eecs.umich.edu#include "params/RubyController.hh"
477161Sgblack@eecs.umich.edu#include "sim/clocked_object.hh"
487161Sgblack@eecs.umich.edu
497161Sgblack@eecs.umich.educlass Network;
507161Sgblack@eecs.umich.edu
517161Sgblack@eecs.umich.educlass AbstractController : public ClockedObject, public Consumer
527162Sgblack@eecs.umich.edu{
537161Sgblack@eecs.umich.edu  public:
547162Sgblack@eecs.umich.edu    typedef RubyControllerParams Params;
557161Sgblack@eecs.umich.edu    AbstractController(const Params *p);
567161Sgblack@eecs.umich.edu    void init();
577161Sgblack@eecs.umich.edu    const Params *params() const { return (const Params *)_params; }
587162Sgblack@eecs.umich.edu
597161Sgblack@eecs.umich.edu    const int & getVersion() const { return m_version; }
607162Sgblack@eecs.umich.edu    void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; }
617161Sgblack@eecs.umich.edu
627161Sgblack@eecs.umich.edu    // return instance name
637162Sgblack@eecs.umich.edu    const std::string getName() const { return m_name; }
647161Sgblack@eecs.umich.edu    void blockOnQueue(Address, MessageBuffer*);
657162Sgblack@eecs.umich.edu    void unblock(Address);
667161Sgblack@eecs.umich.edu
677161Sgblack@eecs.umich.edu    virtual MessageBuffer* getMandatoryQueue() const = 0;
687162Sgblack@eecs.umich.edu    virtual const std::string toString() const = 0;  // returns text version of
697161Sgblack@eecs.umich.edu                                                     // controller type
707162Sgblack@eecs.umich.edu    virtual AccessPermission getAccessPermission(const Address& addr) = 0;
717161Sgblack@eecs.umich.edu    virtual DataBlock& getDataBlock(const Address& addr) = 0;
727161Sgblack@eecs.umich.edu
737161Sgblack@eecs.umich.edu    virtual void print(std::ostream & out) const = 0;
747162Sgblack@eecs.umich.edu    virtual void wakeup() = 0;
757161Sgblack@eecs.umich.edu    virtual void clearStats() = 0;
767162Sgblack@eecs.umich.edu    virtual void regStats() = 0;
777161Sgblack@eecs.umich.edu
787161Sgblack@eecs.umich.edu    virtual void recordCacheTrace(int cntrl, CacheRecorder* tr) = 0;
797161Sgblack@eecs.umich.edu    virtual Sequencer* getSequencer() const = 0;
807162Sgblack@eecs.umich.edu
817161Sgblack@eecs.umich.edu    //! These functions are used by ruby system to read/write the message
827162Sgblack@eecs.umich.edu    //! queues that exist with in the controller.
837161Sgblack@eecs.umich.edu    //! The boolean return value indicates if the read was performed
847161Sgblack@eecs.umich.edu    //! successfully.
857161Sgblack@eecs.umich.edu    virtual bool functionalReadBuffers(PacketPtr&) = 0;
867162Sgblack@eecs.umich.edu    //! The return value indicates the number of messages written with the
877161Sgblack@eecs.umich.edu    //! data from the packet.
887162Sgblack@eecs.umich.edu    virtual uint32_t functionalWriteBuffers(PacketPtr&) = 0;
897161Sgblack@eecs.umich.edu
9012595Ssiddhesh.poyarekar@gmail.com    //! Function for enqueuing a prefetch request
9112595Ssiddhesh.poyarekar@gmail.com    virtual void enqueuePrefetch(const Address&, const RubyRequestType&)
927161Sgblack@eecs.umich.edu    { fatal("Prefetches not implemented!");}
937161Sgblack@eecs.umich.edu
947161Sgblack@eecs.umich.edu    //! Function for collating statistics from all the controllers of this
957161Sgblack@eecs.umich.edu    //! particular type. This function should only be called from the
967161Sgblack@eecs.umich.edu    //! version 0 of this controller type.
977161Sgblack@eecs.umich.edu    virtual void collateStats()
987161Sgblack@eecs.umich.edu    {fatal("collateStats() should be overridden!");}
997161Sgblack@eecs.umich.edu
1007161Sgblack@eecs.umich.edu  public:
1017161Sgblack@eecs.umich.edu    MachineID getMachineID() const { return m_machineID; }
1027161Sgblack@eecs.umich.edu    uint64_t getFullyBusyCycles() const { return m_fully_busy_cycles; }
1037161Sgblack@eecs.umich.edu    uint64_t getRequestCount() const { return m_request_count; }
1047161Sgblack@eecs.umich.edu    const std::map<std::string, uint64_t>& getRequestProfileMap() const
1057161Sgblack@eecs.umich.edu    { return m_requestProfileMap; }
1067161Sgblack@eecs.umich.edu
1077161Sgblack@eecs.umich.edu    Histogram& getDelayHist() { return m_delayHistogram; }
1087161Sgblack@eecs.umich.edu    Histogram& getDelayVCHist(uint32_t index)
1097161Sgblack@eecs.umich.edu    { return m_delayVCHistogram[index]; }
1107162Sgblack@eecs.umich.edu
1117161Sgblack@eecs.umich.edu    MessageBuffer *getPeerQueue(uint32_t pid)
1127162Sgblack@eecs.umich.edu    {
1137161Sgblack@eecs.umich.edu        std::map<uint32_t, MessageBuffer *>::iterator it =
1147162Sgblack@eecs.umich.edu                                        peerQueueMap.find(pid);
1157161Sgblack@eecs.umich.edu        assert(it != peerQueueMap.end());
1167162Sgblack@eecs.umich.edu        return (*it).second;
11712595Ssiddhesh.poyarekar@gmail.com    }
11812595Ssiddhesh.poyarekar@gmail.com
1197161Sgblack@eecs.umich.edu  protected:
1207161Sgblack@eecs.umich.edu    //! Profiles original cache requests including PUTs
1217161Sgblack@eecs.umich.edu    void profileRequest(const std::string &request);
1227161Sgblack@eecs.umich.edu    //! Profiles the delay associated with messages.
1237162Sgblack@eecs.umich.edu    void profileMsgDelay(uint32_t virtualNetwork, Cycles delay);
1247161Sgblack@eecs.umich.edu
1257162Sgblack@eecs.umich.edu    //! Function for connecting peer controllers
1267161Sgblack@eecs.umich.edu    void connectWithPeer(AbstractController *);
1277161Sgblack@eecs.umich.edu    virtual void getQueuesFromPeer(AbstractController *)
1287161Sgblack@eecs.umich.edu    { fatal("getQueuesFromPeer() should be called only if implemented!"); }
1297162Sgblack@eecs.umich.edu
1307161Sgblack@eecs.umich.edu    void stallBuffer(MessageBuffer* buf, Address addr);
1317162Sgblack@eecs.umich.edu    void wakeUpBuffers(Address addr);
1327161Sgblack@eecs.umich.edu    void wakeUpAllBuffers(Address addr);
1337161Sgblack@eecs.umich.edu    void wakeUpAllBuffers();
1347161Sgblack@eecs.umich.edu
1357161Sgblack@eecs.umich.edu  protected:
1367161Sgblack@eecs.umich.edu    int m_transitions_per_cycle;
1377162Sgblack@eecs.umich.edu    int m_buffer_size;
1387161Sgblack@eecs.umich.edu    Cycles m_recycle_latency;
1397162Sgblack@eecs.umich.edu    std::string m_name;
1407161Sgblack@eecs.umich.edu    NodeID m_version;
1417162Sgblack@eecs.umich.edu    Network* m_net_ptr;
1427161Sgblack@eecs.umich.edu    MachineID m_machineID;
1437162Sgblack@eecs.umich.edu    bool m_is_blocking;
14412595Ssiddhesh.poyarekar@gmail.com    std::map<Address, MessageBuffer*> m_block_map;
14512595Ssiddhesh.poyarekar@gmail.com    typedef std::vector<MessageBuffer*> MsgVecType;
1467161Sgblack@eecs.umich.edu    typedef std::map< Address, MsgVecType* > WaitingBufType;
1477161Sgblack@eecs.umich.edu    WaitingBufType m_waiting_buffers;
1487161Sgblack@eecs.umich.edu    unsigned int m_in_ports;
1497161Sgblack@eecs.umich.edu    unsigned int m_cur_in_port;
1507162Sgblack@eecs.umich.edu    int m_number_of_TBEs;
1517161Sgblack@eecs.umich.edu
1527162Sgblack@eecs.umich.edu    //! Map from physical network number to the Message Buffer.
1537161Sgblack@eecs.umich.edu    std::map<uint32_t, MessageBuffer*> peerQueueMap;
1547162Sgblack@eecs.umich.edu
1557161Sgblack@eecs.umich.edu    //! Counter for the number of cycles when the transitions carried out
1567162Sgblack@eecs.umich.edu    //! were equal to the maximum allowed
15712595Ssiddhesh.poyarekar@gmail.com    uint64_t m_fully_busy_cycles;
15812595Ssiddhesh.poyarekar@gmail.com
1597161Sgblack@eecs.umich.edu    //! Map for couting requests of different types. The controller should
16012595Ssiddhesh.poyarekar@gmail.com    //! call requisite function for updating the count.
16112595Ssiddhesh.poyarekar@gmail.com    std::map<std::string, uint64_t> m_requestProfileMap;
1627161Sgblack@eecs.umich.edu    uint64_t m_request_count;
1637161Sgblack@eecs.umich.edu
1647161Sgblack@eecs.umich.edu    //! Histogram for profiling delay for the messages this controller
1657161Sgblack@eecs.umich.edu    //! cares for
1667161Sgblack@eecs.umich.edu    Histogram m_delayHistogram;
1677161Sgblack@eecs.umich.edu    std::vector<Histogram> m_delayVCHistogram;
1687161Sgblack@eecs.umich.edu
1697161Sgblack@eecs.umich.edu    //! Callback class used for collating statistics from all the
1707161Sgblack@eecs.umich.edu    //! controller of this type.
1717161Sgblack@eecs.umich.edu    class StatsCallback : public Callback
1727161Sgblack@eecs.umich.edu    {
1737161Sgblack@eecs.umich.edu      private:
1747161Sgblack@eecs.umich.edu        AbstractController *ctr;
1757161Sgblack@eecs.umich.edu
1767161Sgblack@eecs.umich.edu      public:
1777161Sgblack@eecs.umich.edu        virtual ~StatsCallback() {}
1787161Sgblack@eecs.umich.edu
1797161Sgblack@eecs.umich.edu        StatsCallback(AbstractController *_ctr)
1807161Sgblack@eecs.umich.edu            : ctr(_ctr)
1817161Sgblack@eecs.umich.edu        {
1827161Sgblack@eecs.umich.edu        }
1837162Sgblack@eecs.umich.edu
1847161Sgblack@eecs.umich.edu        void process() {ctr->collateStats();}
1857162Sgblack@eecs.umich.edu    };
1867161Sgblack@eecs.umich.edu};
1877161Sgblack@eecs.umich.edu
1887162Sgblack@eecs.umich.edu#endif // __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
1897161Sgblack@eecs.umich.edu