Network.hh revision 10370
12139SN/A/*
22139SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
32139SN/A * All rights reserved.
42139SN/A *
52139SN/A * Redistribution and use in source and binary forms, with or without
62139SN/A * modification, are permitted provided that the following conditions are
72139SN/A * met: redistributions of source code must retain the above copyright
82139SN/A * notice, this list of conditions and the following disclaimer;
92139SN/A * redistributions in binary form must reproduce the above copyright
102139SN/A * notice, this list of conditions and the following disclaimer in the
112139SN/A * documentation and/or other materials provided with the distribution;
122139SN/A * neither the name of the copyright holders nor the names of its
132139SN/A * contributors may be used to endorse or promote products derived from
142139SN/A * this software without specific prior written permission.
152139SN/A *
162139SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172139SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182139SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192139SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202139SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212139SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222139SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232139SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242139SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252139SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262139SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272139SN/A */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu/*
302139SN/A * The Network class is the base class for classes that implement the
312718Sstever@eecs.umich.edu * interconnection network between components (processor/cache
322139SN/A * components and memory/directory components).  The interconnection
332139SN/A * network as described here is not a physical network, but a
342139SN/A * programming concept used to implement all communication between
352139SN/A * components.  Thus parts of this 'network' will model the on-chip
362152SN/A * connections between cache controllers and directory controllers as
372152SN/A * well as the links between chip and network switches.
382152SN/A */
392152SN/A
402139SN/A#ifndef __MEM_RUBY_NETWORK_NETWORK_HH__
412139SN/A#define __MEM_RUBY_NETWORK_NETWORK_HH__
422139SN/A
432139SN/A#include <iostream>
442139SN/A#include <string>
452152SN/A#include <vector>
462152SN/A
472139SN/A#include "mem/protocol/LinkDirection.hh"
482139SN/A#include "mem/protocol/MessageSizeType.hh"
492139SN/A#include "mem/ruby/common/TypeDefines.hh"
502439SN/A#include "mem/ruby/network/Topology.hh"
512439SN/A#include "mem/packet.hh"
522439SN/A#include "params/RubyNetwork.hh"
532139SN/A#include "sim/clocked_object.hh"
542439SN/A
552460SN/Aclass NetDest;
562439SN/Aclass MessageBuffer;
572171SN/A
582439SN/Aclass Network : public ClockedObject
592439SN/A{
602170SN/A  public:
612139SN/A    typedef RubyNetworkParams Params;
622139SN/A    Network(const Params *p);
632139SN/A    const Params * params() const
642139SN/A    { return dynamic_cast<const Params *>(_params);}
652139SN/A
662139SN/A    virtual ~Network();
672139SN/A    virtual void init();
682139SN/A
692139SN/A    static uint32_t getNumberOfVirtualNetworks() { return m_virtual_networks; }
702139SN/A    int getNumNodes() const { return m_nodes; }
712139SN/A
722139SN/A    static uint32_t MessageSizeType_to_int(MessageSizeType size_type);
732139SN/A
742139SN/A    // returns the queue requested for the given component
752139SN/A    virtual void setToNetQueue(NodeID id, bool ordered, int netNumber,
762139SN/A                               std::string vnet_type, MessageBuffer *b) = 0;
772139SN/A    virtual void setFromNetQueue(NodeID id, bool ordered, int netNumber,
782139SN/A                                 std::string vnet_type, MessageBuffer *b) = 0;
792139SN/A
802139SN/A    virtual void makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
812139SN/A                             LinkDirection direction,
822139SN/A                             const NetDest& routing_table_entry) = 0;
832139SN/A    virtual void makeInLink(NodeID src, SwitchID dest, BasicLink* link,
842139SN/A                            LinkDirection direction,
852178SN/A                            const NetDest& routing_table_entry) = 0;
862139SN/A    virtual void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
872139SN/A                                  LinkDirection direction,
882139SN/A                                  const NetDest& routing_table_entry) = 0;
892139SN/A
902139SN/A    virtual void collateStats() = 0;
912139SN/A    virtual void print(std::ostream& out) const = 0;
922139SN/A
932152SN/A    /*
942152SN/A     * Virtual functions for functionally reading and writing packets in
952152SN/A     * the network. Each network needs to implement these for functional
962152SN/A     * accesses to work correctly.
972152SN/A     */
982152SN/A    virtual bool functionalRead(Packet *pkt)
992152SN/A    { fatal("Functional read not implemented.\n"); }
1002152SN/A    virtual uint32_t functionalWrite(Packet *pkt)
1012152SN/A    { fatal("Functional write not implemented.\n"); }
1022152SN/A
1032152SN/A  protected:
1042152SN/A    // Private copy constructor and assignment operator
1052504SN/A    Network(const Network& obj);
1062504SN/A    Network& operator=(const Network& obj);
1072504SN/A
1082504SN/A    uint32_t m_nodes;
1092152SN/A    static uint32_t m_virtual_networks;
1102504SN/A    Topology* m_topology_ptr;
1112152SN/A    static uint32_t m_control_msg_size;
1122152SN/A    static uint32_t m_data_msg_size;
1132152SN/A
1142152SN/A    // vector of queues from the components
1152152SN/A    std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
1162152SN/A    std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
1172152SN/A
1182152SN/A    std::vector<bool> m_in_use;
1192632Sstever@eecs.umich.edu    std::vector<bool> m_ordered;
1202155SN/A
1212155SN/A  private:
1222155SN/A    //! Callback class used for collating statistics from all the
1232155SN/A    //! controller of this type.
1242155SN/A    class StatsCallback : public Callback
1252155SN/A    {
1262155SN/A      private:
1272155SN/A        Network *ctr;
1282155SN/A
1292155SN/A      public:
1302152SN/A        virtual ~StatsCallback() {}
1312766Sktlim@umich.edu
1322766Sktlim@umich.edu        StatsCallback(Network *_ctr)
1332766Sktlim@umich.edu            : ctr(_ctr)
1342766Sktlim@umich.edu        {
1352766Sktlim@umich.edu        }
1362152SN/A
1372152SN/A        void process() {ctr->collateStats();}
1382152SN/A    };
1392155SN/A};
1402152SN/A
1412152SN/Ainline std::ostream&
1422718Sstever@eecs.umich.eduoperator<<(std::ostream& out, const Network& obj)
1432921Sktlim@umich.edu{
1442921Sktlim@umich.edu    obj.print(out);
1452921Sktlim@umich.edu    out << std::flush;
1462921Sktlim@umich.edu    return out;
1472921Sktlim@umich.edu}
1482921Sktlim@umich.edu
1492921Sktlim@umich.edu#endif // __MEM_RUBY_NETWORK_NETWORK_HH__
1502921Sktlim@umich.edu