SimpleNetwork.hh revision 7454
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
667055Snate@binkert.org#include <iostream>
677454Snate@binkert.org#include <vector>
687055Snate@binkert.org
696154Snate@binkert.org#include "mem/ruby/common/Global.hh"
706154Snate@binkert.org#include "mem/ruby/network/Network.hh"
716154Snate@binkert.org#include "mem/ruby/system/NodeID.hh"
727054Snate@binkert.org#include "params/SimpleNetwork.hh"
736876Ssteve.reinhardt@amd.com#include "sim/sim_object.hh"
746145Snate@binkert.org
756145Snate@binkert.orgclass NetDest;
766145Snate@binkert.orgclass MessageBuffer;
776145Snate@binkert.orgclass Throttle;
786145Snate@binkert.orgclass Switch;
796145Snate@binkert.orgclass Topology;
806145Snate@binkert.org
817054Snate@binkert.orgclass SimpleNetwork : public Network
827054Snate@binkert.org{
837054Snate@binkert.org  public:
846876Ssteve.reinhardt@amd.com    typedef SimpleNetworkParams Params;
856876Ssteve.reinhardt@amd.com    SimpleNetwork(const Params *p);
867054Snate@binkert.org    ~SimpleNetwork();
876145Snate@binkert.org
887054Snate@binkert.org    void init();
896145Snate@binkert.org
907055Snate@binkert.org    void printStats(std::ostream& out) const;
917054Snate@binkert.org    void clearStats();
927055Snate@binkert.org    void printConfig(std::ostream& out) const;
936285Snate@binkert.org
947054Snate@binkert.org    void reset();
956145Snate@binkert.org
967054Snate@binkert.org    // returns the queue requested for the given component
977054Snate@binkert.org    MessageBuffer* getToNetQueue(NodeID id, bool ordered, int network_num);
987054Snate@binkert.org    MessageBuffer* getFromNetQueue(NodeID id, bool ordered, int network_num);
997454Snate@binkert.org    virtual const std::vector<Throttle*>* getThrottles(NodeID id) const;
1006145Snate@binkert.org
1017054Snate@binkert.org    bool isVNetOrdered(int vnet) { return m_ordered[vnet]; }
1027054Snate@binkert.org    bool validVirtualNetwork(int vnet) { return m_in_use[vnet]; }
1036145Snate@binkert.org
1047054Snate@binkert.org    int getNumNodes() {return m_nodes; }
1056145Snate@binkert.org
1067054Snate@binkert.org    // Methods used by Topology to setup the network
1077054Snate@binkert.org    void makeOutLink(SwitchID src, NodeID dest,
1087054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency, int link_weight,
1097054Snate@binkert.org        int bw_multiplier, bool isReconfiguration);
1107054Snate@binkert.org    void makeInLink(SwitchID src, NodeID dest,
1117054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency,
1127054Snate@binkert.org        int bw_multiplier, bool isReconfiguration);
1137054Snate@binkert.org    void makeInternalLink(SwitchID src, NodeID dest,
1147054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency, int link_weight,
1157054Snate@binkert.org        int bw_multiplier, bool isReconfiguration);
1166145Snate@binkert.org
1177055Snate@binkert.org    void print(std::ostream& out) const;
1186145Snate@binkert.org
1197054Snate@binkert.org  private:
1207054Snate@binkert.org    void checkNetworkAllocation(NodeID id, bool ordered, int network_num);
1217054Snate@binkert.org    void addLink(SwitchID src, SwitchID dest, int link_latency);
1227054Snate@binkert.org    void makeLink(SwitchID src, SwitchID dest,
1237054Snate@binkert.org        const NetDest& routing_table_entry, int link_latency);
1247054Snate@binkert.org    SwitchID createSwitch();
1257054Snate@binkert.org    void makeTopology();
1267054Snate@binkert.org    void linkTopology();
1276145Snate@binkert.org
1287054Snate@binkert.org    // Private copy constructor and assignment operator
1297054Snate@binkert.org    SimpleNetwork(const SimpleNetwork& obj);
1307054Snate@binkert.org    SimpleNetwork& operator=(const SimpleNetwork& obj);
1316145Snate@binkert.org
1327054Snate@binkert.org    // vector of queues from the components
1337454Snate@binkert.org    std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
1347454Snate@binkert.org    std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
1356145Snate@binkert.org
1367454Snate@binkert.org    std::vector<bool> m_in_use;
1377454Snate@binkert.org    std::vector<bool> m_ordered;
1387454Snate@binkert.org    std::vector<Switch*> m_switch_ptr_vector;
1397454Snate@binkert.org    std::vector<MessageBuffer*> m_buffers_to_free;
1407454Snate@binkert.org    std::vector<Switch*> m_endpoint_switches;
1416145Snate@binkert.org};
1426145Snate@binkert.org
1437055Snate@binkert.orginline std::ostream&
1447055Snate@binkert.orgoperator<<(std::ostream& out, const SimpleNetwork& obj)
1456145Snate@binkert.org{
1467054Snate@binkert.org    obj.print(out);
1477055Snate@binkert.org    out << std::flush;
1487054Snate@binkert.org    return out;
1496145Snate@binkert.org}
1506145Snate@binkert.org
1517054Snate@binkert.org#endif // __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
152