SimpleNetwork.hh revision 10311
110249Sstephan.diestelhorst@arm.com/*
210249Sstephan.diestelhorst@arm.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
310249Sstephan.diestelhorst@arm.com * All rights reserved.
410249Sstephan.diestelhorst@arm.com *
510249Sstephan.diestelhorst@arm.com * Redistribution and use in source and binary forms, with or without
610249Sstephan.diestelhorst@arm.com * modification, are permitted provided that the following conditions are
710249Sstephan.diestelhorst@arm.com * met: redistributions of source code must retain the above copyright
810249Sstephan.diestelhorst@arm.com * notice, this list of conditions and the following disclaimer;
910249Sstephan.diestelhorst@arm.com * redistributions in binary form must reproduce the above copyright
1010249Sstephan.diestelhorst@arm.com * notice, this list of conditions and the following disclaimer in the
1110249Sstephan.diestelhorst@arm.com * documentation and/or other materials provided with the distribution;
1210249Sstephan.diestelhorst@arm.com * neither the name of the copyright holders nor the names of its
1310249Sstephan.diestelhorst@arm.com * contributors may be used to endorse or promote products derived from
1410249Sstephan.diestelhorst@arm.com * this software without specific prior written permission.
1510249Sstephan.diestelhorst@arm.com *
1610249Sstephan.diestelhorst@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1710249Sstephan.diestelhorst@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1810249Sstephan.diestelhorst@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1910249Sstephan.diestelhorst@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2010249Sstephan.diestelhorst@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2110249Sstephan.diestelhorst@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2210249Sstephan.diestelhorst@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2310249Sstephan.diestelhorst@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2410249Sstephan.diestelhorst@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2510249Sstephan.diestelhorst@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2610249Sstephan.diestelhorst@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2710249Sstephan.diestelhorst@arm.com */
2810249Sstephan.diestelhorst@arm.com
2910249Sstephan.diestelhorst@arm.com#ifndef __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
3010249Sstephan.diestelhorst@arm.com#define __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
3110249Sstephan.diestelhorst@arm.com
3210249Sstephan.diestelhorst@arm.com#include <iostream>
3310249Sstephan.diestelhorst@arm.com#include <vector>
3410249Sstephan.diestelhorst@arm.com
3510249Sstephan.diestelhorst@arm.com#include "mem/ruby/network/Network.hh"
3610249Sstephan.diestelhorst@arm.com#include "params/SimpleNetwork.hh"
3710249Sstephan.diestelhorst@arm.com
3810249Sstephan.diestelhorst@arm.comclass NetDest;
3910249Sstephan.diestelhorst@arm.comclass MessageBuffer;
4010249Sstephan.diestelhorst@arm.comclass Throttle;
4110249Sstephan.diestelhorst@arm.comclass Switch;
4210249Sstephan.diestelhorst@arm.com
4310249Sstephan.diestelhorst@arm.comclass SimpleNetwork : public Network
4410249Sstephan.diestelhorst@arm.com{
4510249Sstephan.diestelhorst@arm.com  public:
4610249Sstephan.diestelhorst@arm.com    typedef SimpleNetworkParams Params;
4710249Sstephan.diestelhorst@arm.com    SimpleNetwork(const Params *p);
4810249Sstephan.diestelhorst@arm.com    ~SimpleNetwork();
4910249Sstephan.diestelhorst@arm.com
5010249Sstephan.diestelhorst@arm.com    void init();
5110249Sstephan.diestelhorst@arm.com
5210249Sstephan.diestelhorst@arm.com    int getBufferSize() { return m_buffer_size; }
5310249Sstephan.diestelhorst@arm.com    int getEndpointBandwidth() { return m_endpoint_bandwidth; }
5410249Sstephan.diestelhorst@arm.com    bool getAdaptiveRouting() {return m_adaptive_routing; }
5510249Sstephan.diestelhorst@arm.com
5610249Sstephan.diestelhorst@arm.com    void collateStats();
5710249Sstephan.diestelhorst@arm.com    void regStats();
5810249Sstephan.diestelhorst@arm.com
5910249Sstephan.diestelhorst@arm.com    // sets the queue requested
6010249Sstephan.diestelhorst@arm.com    void setToNetQueue(NodeID id, bool ordered, int network_num,
6110249Sstephan.diestelhorst@arm.com                       std::string vnet_type, MessageBuffer *b);
6210249Sstephan.diestelhorst@arm.com    void setFromNetQueue(NodeID id, bool ordered, int network_num,
6310249Sstephan.diestelhorst@arm.com                         std::string vnet_type, MessageBuffer *b);
6410249Sstephan.diestelhorst@arm.com
6510249Sstephan.diestelhorst@arm.com    bool isVNetOrdered(int vnet) { return m_ordered[vnet]; }
6611321Ssteve.reinhardt@amd.com    bool validVirtualNetwork(int vnet) { return m_in_use[vnet]; }
6710249Sstephan.diestelhorst@arm.com
6810249Sstephan.diestelhorst@arm.com    // Methods used by Topology to setup the network
6910249Sstephan.diestelhorst@arm.com    void makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
7010249Sstephan.diestelhorst@arm.com                     LinkDirection direction,
7110249Sstephan.diestelhorst@arm.com                     const NetDest& routing_table_entry);
7210249Sstephan.diestelhorst@arm.com    void makeInLink(NodeID src, SwitchID dest, BasicLink* link,
7310249Sstephan.diestelhorst@arm.com                    LinkDirection direction,
7410249Sstephan.diestelhorst@arm.com                    const NetDest& routing_table_entry);
7510249Sstephan.diestelhorst@arm.com    void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
7610249Sstephan.diestelhorst@arm.com                          LinkDirection direction,
7710249Sstephan.diestelhorst@arm.com                          const NetDest& routing_table_entry);
7810249Sstephan.diestelhorst@arm.com
7910249Sstephan.diestelhorst@arm.com    void print(std::ostream& out) const;
8010249Sstephan.diestelhorst@arm.com
8110249Sstephan.diestelhorst@arm.com    bool functionalRead(Packet *pkt);
8210249Sstephan.diestelhorst@arm.com    uint32_t functionalWrite(Packet *pkt);
8310249Sstephan.diestelhorst@arm.com
8410395Sstephan.diestelhorst@arm.com  private:
8510395Sstephan.diestelhorst@arm.com    void checkNetworkAllocation(NodeID id, bool ordered, int network_num);
8610395Sstephan.diestelhorst@arm.com    void addLink(SwitchID src, SwitchID dest, int link_latency);
8710249Sstephan.diestelhorst@arm.com    void makeLink(SwitchID src, SwitchID dest,
8810249Sstephan.diestelhorst@arm.com        const NetDest& routing_table_entry, int link_latency);
8910249Sstephan.diestelhorst@arm.com    void makeTopology();
9010249Sstephan.diestelhorst@arm.com
9110249Sstephan.diestelhorst@arm.com    // Private copy constructor and assignment operator
9210249Sstephan.diestelhorst@arm.com    SimpleNetwork(const SimpleNetwork& obj);
9310395Sstephan.diestelhorst@arm.com    SimpleNetwork& operator=(const SimpleNetwork& obj);
9410395Sstephan.diestelhorst@arm.com
9510395Sstephan.diestelhorst@arm.com    std::vector<Switch*> m_switches;
9610395Sstephan.diestelhorst@arm.com    std::vector<MessageBuffer*> m_buffers_to_free;
9710395Sstephan.diestelhorst@arm.com    std::vector<Switch*> m_endpoint_switches;
9810395Sstephan.diestelhorst@arm.com
9910395Sstephan.diestelhorst@arm.com    int m_buffer_size;
10010395Sstephan.diestelhorst@arm.com    int m_endpoint_bandwidth;
10110395Sstephan.diestelhorst@arm.com    bool m_adaptive_routing;
10210395Sstephan.diestelhorst@arm.com
10310395Sstephan.diestelhorst@arm.com    //Statistical variables
10410249Sstephan.diestelhorst@arm.com    Stats::Formula m_msg_counts[MessageSizeType_NUM];
10510249Sstephan.diestelhorst@arm.com    Stats::Formula m_msg_bytes[MessageSizeType_NUM];
10610249Sstephan.diestelhorst@arm.com};
10710249Sstephan.diestelhorst@arm.com
10810249Sstephan.diestelhorst@arm.cominline std::ostream&
10910249Sstephan.diestelhorst@arm.comoperator<<(std::ostream& out, const SimpleNetwork& obj)
11010249Sstephan.diestelhorst@arm.com{
11110249Sstephan.diestelhorst@arm.com    obj.print(out);
11210249Sstephan.diestelhorst@arm.com    out << std::flush;
11310249Sstephan.diestelhorst@arm.com    return out;
11410249Sstephan.diestelhorst@arm.com}
11510249Sstephan.diestelhorst@arm.com
11610249Sstephan.diestelhorst@arm.com#endif // __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
11710249Sstephan.diestelhorst@arm.com