SimpleNetwork.hh revision 8608:02d7ac5fb855
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
30#define __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
31
32#include <iostream>
33#include <vector>
34
35#include "mem/ruby/common/Global.hh"
36#include "mem/ruby/network/Network.hh"
37#include "params/SimpleNetwork.hh"
38#include "sim/sim_object.hh"
39
40class NetDest;
41class MessageBuffer;
42class Throttle;
43class Switch;
44class Topology;
45
46class SimpleNetwork : public Network
47{
48  public:
49    typedef SimpleNetworkParams Params;
50    SimpleNetwork(const Params *p);
51    ~SimpleNetwork();
52
53    void init();
54
55    int getBufferSize() { return m_buffer_size; }
56    int getEndpointBandwidth() { return m_endpoint_bandwidth; }
57    bool getAdaptiveRouting() {return m_adaptive_routing; }
58
59    void printStats(std::ostream& out) const;
60    void clearStats();
61    void printConfig(std::ostream& out) const;
62
63    void reset();
64
65    // returns the queue requested for the given component
66    MessageBuffer* getToNetQueue(NodeID id, bool ordered, int network_num, std::string vnet_type);
67    MessageBuffer* getFromNetQueue(NodeID id, bool ordered, int network_num, std::string vnet_type);
68    virtual const std::vector<Throttle*>* getThrottles(NodeID id) const;
69
70    bool isVNetOrdered(int vnet) { return m_ordered[vnet]; }
71    bool validVirtualNetwork(int vnet) { return m_in_use[vnet]; }
72
73    int getNumNodes() {return m_nodes; }
74
75    // Methods used by Topology to setup the network
76    void makeOutLink(SwitchID src, NodeID dest, BasicLink* link,
77                     LinkDirection direction,
78                     const NetDest& routing_table_entry,
79                     bool isReconfiguration);
80    void makeInLink(NodeID src, SwitchID dest, BasicLink* link,
81                    LinkDirection direction,
82                    const NetDest& routing_table_entry,
83                    bool isReconfiguration);
84    void makeInternalLink(SwitchID src, SwitchID dest, BasicLink* link,
85                          LinkDirection direction,
86                          const NetDest& routing_table_entry,
87                          bool isReconfiguration);
88
89    void print(std::ostream& out) const;
90
91  private:
92    void checkNetworkAllocation(NodeID id, bool ordered, int network_num);
93    void addLink(SwitchID src, SwitchID dest, int link_latency);
94    void makeLink(SwitchID src, SwitchID dest,
95        const NetDest& routing_table_entry, int link_latency);
96    SwitchID createSwitch();
97    void makeTopology();
98    void linkTopology();
99
100    // Private copy constructor and assignment operator
101    SimpleNetwork(const SimpleNetwork& obj);
102    SimpleNetwork& operator=(const SimpleNetwork& obj);
103
104    // vector of queues from the components
105    std::vector<std::vector<MessageBuffer*> > m_toNetQueues;
106    std::vector<std::vector<MessageBuffer*> > m_fromNetQueues;
107
108    std::vector<bool> m_in_use;
109    std::vector<bool> m_ordered;
110    std::vector<Switch*> m_switch_ptr_vector;
111    std::vector<MessageBuffer*> m_buffers_to_free;
112    std::vector<Switch*> m_endpoint_switches;
113
114    int m_buffer_size;
115    int m_endpoint_bandwidth;
116    bool m_adaptive_routing;
117};
118
119inline std::ostream&
120operator<<(std::ostream& out, const SimpleNetwork& obj)
121{
122    obj.print(out);
123    out << std::flush;
124    return out;
125}
126
127#endif // __MEM_RUBY_NETWORK_SIMPLE_SIMPLENETWORK_HH__
128