SimpleNetwork.hh revision 7054
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36145Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
66145Snate@binkert.org * modification, are permitted provided that the following conditions are
76145Snate@binkert.org * met: redistributions of source code must retain the above copyright
86145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
116145Snate@binkert.org * documentation and/or other materials provided with the distribution;
126145Snate@binkert.org * neither the name of the copyright holders nor the names of its
136145Snate@binkert.org * contributors may be used to endorse or promote products derived from
146145Snate@binkert.org * this software without specific prior written permission.
156145Snate@binkert.org *
166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276145Snate@binkert.org */
286145Snate@binkert.org
296145Snate@binkert.org/*
307054Snate@binkert.org * The SimpleNetwork class implements the interconnection
316145Snate@binkert.org * SimpleNetwork between components (processor/cache components and
326145Snate@binkert.org * memory/directory components).  The interconnection network as
336145Snate@binkert.org * described here is not a physical network, but a programming concept
346145Snate@binkert.org * used to implement all communication between components.  Thus parts
356145Snate@binkert.org * of this 'network' may model the on-chip connections between cache
366145Snate@binkert.org * controllers and directory controllers as well as the links between
376145Snate@binkert.org * chip and network switches.
386145Snate@binkert.org *
396145Snate@binkert.org * Two conceptual networks, an address and data network, are modeled.
406145Snate@binkert.org * The data network is unordered, where the address network provides
416145Snate@binkert.org * and conforms to a global ordering of all transactions.
426145Snate@binkert.org *
436145Snate@binkert.org * Currently the data network is point-to-point and the address
446145Snate@binkert.org * network is a broadcast network. These two distinct conceptual
456145Snate@binkert.org * network can be modeled as physically separate networks or
466145Snate@binkert.org * multiplexed over a single physical network.
476145Snate@binkert.org *
486145Snate@binkert.org * The network encapsulates all notion of virtual global time and is
496145Snate@binkert.org * responsible for ordering the network transactions received.  This
506145Snate@binkert.org * hides all of these ordering details from the processor/cache and
516145Snate@binkert.org * directory/memory modules.
526145Snate@binkert.org *
536145Snate@binkert.org * FIXME: Various flavor of networks are provided as a compiler time
546145Snate@binkert.org *        configurable. We currently include this SimpleNetwork in the
556284Snate@binkert.org *        makefile's vpath, so that SimpleNetwork.cc can provide an alternative
566145Snate@binkert.org *        version constructor for the abstract Network class. It is easy to
576145Snate@binkert.org *        modify this to make network a runtime configuable. Just make the
586145Snate@binkert.org *        abstract Network class take a enumeration parameter, and based on
596145Snate@binkert.org *        that to initial proper network. Or even better, just make the ruby
606145Snate@binkert.org *        system initializer choose the proper network to initiate.
616145Snate@binkert.org */
626145Snate@binkert.org
637054Snate@binkert.org#ifndef __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
647054Snate@binkert.org#define __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
656145Snate@binkert.org
667054Snate@binkert.org#include "mem/gems_common/Vector.hh"
676154Snate@binkert.org#include "mem/ruby/common/Global.hh"
686154Snate@binkert.org#include "mem/ruby/network/Network.hh"
696154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
707054Snate@binkert.org#include "params/SimpleNetwork.hh"
716876Ssteve.reinhardt@amd.com#include "sim/sim_object.hh"
726145Snate@binkert.org
736145Snate@binkert.orgclass NetDest;
746145Snate@binkert.orgclass MessageBuffer;
756145Snate@binkert.orgclass Throttle;
766145Snate@binkert.orgclass Switch;
776145Snate@binkert.orgclass Topology;
786145Snate@binkert.org
797054Snate@binkert.orgclass SimpleNetwork : public Network
807054Snate@binkert.org{
817054Snate@binkert.org  public:
826876Ssteve.reinhardt@amd.com    typedef SimpleNetworkParams Params;
836876Ssteve.reinhardt@amd.com    SimpleNetwork(const Params *p);
847054Snate@binkert.org    ~SimpleNetwork();
856145Snate@binkert.org
867054Snate@binkert.org    void init();
876145Snate@binkert.org
887054Snate@binkert.org    void printStats(ostream& out) const;
897054Snate@binkert.org    void clearStats();
907054Snate@binkert.org    void printConfig(ostream& out) const;
916285Snate@binkert.org
927054Snate@binkert.org    void reset();
936145Snate@binkert.org
947054Snate@binkert.org    // returns the queue requested for the given component
957054Snate@binkert.org    MessageBuffer* getToNetQueue(NodeID id, bool ordered, int network_num);
967054Snate@binkert.org    MessageBuffer* getFromNetQueue(NodeID id, bool ordered, int network_num);
977054Snate@binkert.org    virtual const Vector<Throttle*>* getThrottles(NodeID id) const;
986145Snate@binkert.org
997054Snate@binkert.org    bool isVNetOrdered(int vnet) { return m_ordered[vnet]; }
1007054Snate@binkert.org    bool validVirtualNetwork(int vnet) { return m_in_use[vnet]; }
1016145Snate@binkert.org
1027054Snate@binkert.org    int getNumNodes() {return m_nodes; }
1036145Snate@binkert.org
1047054Snate@binkert.org    // Methods used by Topology to setup the network
1057054Snate@binkert.org    void makeOutLink(SwitchID src, NodeID dest,
1067054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency, int link_weight,
1077054Snate@binkert.org        int bw_multiplier, bool isReconfiguration);
1087054Snate@binkert.org    void makeInLink(SwitchID src, NodeID dest,
1097054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency,
1107054Snate@binkert.org        int bw_multiplier, bool isReconfiguration);
1117054Snate@binkert.org    void makeInternalLink(SwitchID src, NodeID dest,
1127054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency, int link_weight,
1137054Snate@binkert.org        int bw_multiplier, bool isReconfiguration);
1146145Snate@binkert.org
1157054Snate@binkert.org    void print(ostream& out) const;
1166145Snate@binkert.org
1177054Snate@binkert.org  private:
1187054Snate@binkert.org    void checkNetworkAllocation(NodeID id, bool ordered, int network_num);
1197054Snate@binkert.org    void addLink(SwitchID src, SwitchID dest, int link_latency);
1207054Snate@binkert.org    void makeLink(SwitchID src, SwitchID dest,
1217054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency);
1227054Snate@binkert.org    SwitchID createSwitch();
1237054Snate@binkert.org    void makeTopology();
1247054Snate@binkert.org    void linkTopology();
1256145Snate@binkert.org
1267054Snate@binkert.org    // Private copy constructor and assignment operator
1277054Snate@binkert.org    SimpleNetwork(const SimpleNetwork& obj);
1287054Snate@binkert.org    SimpleNetwork& operator=(const SimpleNetwork& obj);
1296145Snate@binkert.org
1307054Snate@binkert.org    // vector of queues from the components
1317054Snate@binkert.org    Vector<Vector<MessageBuffer*> > m_toNetQueues;
1327054Snate@binkert.org    Vector<Vector<MessageBuffer*> > m_fromNetQueues;
1336145Snate@binkert.org
1347054Snate@binkert.org    Vector<bool> m_in_use;
1357054Snate@binkert.org    Vector<bool> m_ordered;
1367054Snate@binkert.org    Vector<Switch*> m_switch_ptr_vector;
1377054Snate@binkert.org    Vector<MessageBuffer*> m_buffers_to_free;
1387054Snate@binkert.org    Vector<Switch*> m_endpoint_switches;
1396145Snate@binkert.org};
1406145Snate@binkert.org
1417054Snate@binkert.orginline ostream&
1427054Snate@binkert.orgoperator<<(ostream& out, const SimpleNetwork& obj)
1436145Snate@binkert.org{
1447054Snate@binkert.org    obj.print(out);
1457054Snate@binkert.org    out << flush;
1467054Snate@binkert.org    return out;
1476145Snate@binkert.org}
1486145Snate@binkert.org
1497054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
150