AbstractController.hh revision 10012:ec5a5bfb941d
12023SN/A/*
22023SN/A * Copyright (c) 2009 Mark D. Hill and David A. Wood
32023SN/A * All rights reserved.
42023SN/A *
52023SN/A * Redistribution and use in source and binary forms, with or without
62023SN/A * modification, are permitted provided that the following conditions are
72023SN/A * met: redistributions of source code must retain the above copyright
82023SN/A * notice, this list of conditions and the following disclaimer;
92023SN/A * redistributions in binary form must reproduce the above copyright
102023SN/A * notice, this list of conditions and the following disclaimer in the
112023SN/A * documentation and/or other materials provided with the distribution;
122023SN/A * neither the name of the copyright holders nor the names of its
132023SN/A * contributors may be used to endorse or promote products derived from
142023SN/A * this software without specific prior written permission.
152023SN/A *
162023SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172023SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182023SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192023SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202023SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212023SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222023SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232023SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242023SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252023SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262023SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282972Sgblack@eecs.umich.edu
293804Ssaidi@eecs.umich.edu#ifndef __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
302023SN/A#define __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
312023SN/A
322023SN/A#include <iostream>
332023SN/A#include <string>
342023SN/A
358229Snate@binkert.org#include "base/callback.hh"
362972Sgblack@eecs.umich.edu#include "mem/protocol/AccessPermission.hh"
376216Snate@binkert.org#include "mem/ruby/buffers/MessageBuffer.hh"
388542Sgblack@eecs.umich.edu#include "mem/ruby/common/Address.hh"
392023SN/A#include "mem/ruby/common/Consumer.hh"
402458SN/A#include "mem/ruby/common/DataBlock.hh"
412023SN/A#include "mem/ruby/common/Histogram.hh"
422458SN/A#include "mem/ruby/network/Network.hh"
432458SN/A#include "mem/ruby/recorder/CacheRecorder.hh"
447741Sgblack@eecs.umich.edu#include "mem/ruby/system/MachineID.hh"
457741Sgblack@eecs.umich.edu#include "mem/packet.hh"
462972Sgblack@eecs.umich.edu#include "params/RubyController.hh"
477741Sgblack@eecs.umich.edu#include "sim/clocked_object.hh"
487741Sgblack@eecs.umich.edu
493093Sksewell@umich.educlass Network;
507741Sgblack@eecs.umich.edu
519057SAli.Saidi@ARM.comclass AbstractController : public ClockedObject, public Consumer
522972Sgblack@eecs.umich.edu{
537741Sgblack@eecs.umich.edu  public:
547741Sgblack@eecs.umich.edu    typedef RubyControllerParams Params;
557741Sgblack@eecs.umich.edu    AbstractController(const Params *p);
567741Sgblack@eecs.umich.edu    void init();
574070Ssaidi@eecs.umich.edu    const Params *params() const { return (const Params *)_params; }
5810318Sandreas.hansson@arm.com
5910318Sandreas.hansson@arm.com    const NodeID getVersion() const { return m_version; }
602458SN/A    void initNetworkPtr(Network* net_ptr) { m_net_ptr = net_ptr; }
617741Sgblack@eecs.umich.edu
622458SN/A    // return instance name
637741Sgblack@eecs.umich.edu    const std::string getName() const { return m_name; }
647741Sgblack@eecs.umich.edu    void blockOnQueue(Address, MessageBuffer*);
657741Sgblack@eecs.umich.edu    void unblock(Address);
667741Sgblack@eecs.umich.edu
677741Sgblack@eecs.umich.edu    virtual MessageBuffer* getMandatoryQueue() const = 0;
687741Sgblack@eecs.umich.edu    virtual const std::string toString() const = 0;  // returns text version of
693804Ssaidi@eecs.umich.edu                                                     // controller type
707741Sgblack@eecs.umich.edu    virtual AccessPermission getAccessPermission(const Address& addr) = 0;
717741Sgblack@eecs.umich.edu    virtual DataBlock& getDataBlock(const Address& addr) = 0;
727741Sgblack@eecs.umich.edu
737741Sgblack@eecs.umich.edu    virtual void print(std::ostream & out) const = 0;
747741Sgblack@eecs.umich.edu    virtual void wakeup() = 0;
757741Sgblack@eecs.umich.edu    virtual void resetStats() = 0;
767741Sgblack@eecs.umich.edu    virtual void regStats();
777741Sgblack@eecs.umich.edu
787741Sgblack@eecs.umich.edu    virtual void recordCacheTrace(int cntrl, CacheRecorder* tr) = 0;
797741Sgblack@eecs.umich.edu    virtual Sequencer* getSequencer() const = 0;
807741Sgblack@eecs.umich.edu
814103Ssaidi@eecs.umich.edu    //! These functions are used by ruby system to read/write the message
826974Stjones1@inf.ed.ac.uk    //! queues that exist with in the controller.
836974Stjones1@inf.ed.ac.uk    //! The boolean return value indicates if the read was performed
849329Sdam.sunwoo@arm.com    //! successfully.
859329Sdam.sunwoo@arm.com    virtual bool functionalReadBuffers(PacketPtr&) = 0;
869329Sdam.sunwoo@arm.com    //! The return value indicates the number of messages written with the
879329Sdam.sunwoo@arm.com    //! data from the packet.
882458SN/A    virtual uint32_t functionalWriteBuffers(PacketPtr&) = 0;
892458SN/A
902023SN/A    //! Function for enqueuing a prefetch request
91    virtual void enqueuePrefetch(const Address&, const RubyRequestType&)
92    { fatal("Prefetches not implemented!");}
93
94    //! Function for collating statistics from all the controllers of this
95    //! particular type. This function should only be called from the
96    //! version 0 of this controller type.
97    virtual void collateStats()
98    {fatal("collateStats() should be overridden!");}
99
100  public:
101    MachineID getMachineID() const { return m_machineID; }
102
103    Stats::Histogram& getDelayHist() { return m_delayHistogram; }
104    Stats::Histogram& getDelayVCHist(uint32_t index)
105    { return *(m_delayVCHistogram[index]); }
106
107    MessageBuffer *getPeerQueue(uint32_t pid)
108    {
109        std::map<uint32_t, MessageBuffer *>::iterator it =
110                                        peerQueueMap.find(pid);
111        assert(it != peerQueueMap.end());
112        return (*it).second;
113    }
114
115  protected:
116    //! Profiles original cache requests including PUTs
117    void profileRequest(const std::string &request);
118    //! Profiles the delay associated with messages.
119    void profileMsgDelay(uint32_t virtualNetwork, Cycles delay);
120
121    //! Function for connecting peer controllers
122    void connectWithPeer(AbstractController *);
123    virtual void getQueuesFromPeer(AbstractController *)
124    { fatal("getQueuesFromPeer() should be called only if implemented!"); }
125
126    void stallBuffer(MessageBuffer* buf, Address addr);
127    void wakeUpBuffers(Address addr);
128    void wakeUpAllBuffers(Address addr);
129    void wakeUpAllBuffers();
130
131  protected:
132    std::string m_name;
133    NodeID m_version;
134    MachineID m_machineID;
135    NodeID m_clusterID;
136
137    Network* m_net_ptr;
138    bool m_is_blocking;
139    std::map<Address, MessageBuffer*> m_block_map;
140    typedef std::vector<MessageBuffer*> MsgVecType;
141    typedef std::map< Address, MsgVecType* > WaitingBufType;
142    WaitingBufType m_waiting_buffers;
143    unsigned int m_in_ports;
144    unsigned int m_cur_in_port;
145    int m_number_of_TBEs;
146    int m_transitions_per_cycle;
147    int m_buffer_size;
148    Cycles m_recycle_latency;
149
150    //! Map from physical network number to the Message Buffer.
151    std::map<uint32_t, MessageBuffer*> peerQueueMap;
152
153    //! Counter for the number of cycles when the transitions carried out
154    //! were equal to the maximum allowed
155    Stats::Scalar m_fully_busy_cycles;
156
157    //! Histogram for profiling delay for the messages this controller
158    //! cares for
159    Stats::Histogram m_delayHistogram;
160    std::vector<Stats::Histogram *> m_delayVCHistogram;
161
162    //! Callback class used for collating statistics from all the
163    //! controller of this type.
164    class StatsCallback : public Callback
165    {
166      private:
167        AbstractController *ctr;
168
169      public:
170        virtual ~StatsCallback() {}
171        StatsCallback(AbstractController *_ctr) : ctr(_ctr) {}
172        void process() {ctr->collateStats();}
173    };
174};
175
176#endif // __MEM_RUBY_SLICC_INTERFACE_ABSTRACTCONTROLLER_HH__
177