gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleNetwork.cc
Go to the documentation of this file.
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 
30 
31 #include <cassert>
32 #include <numeric>
33 
34 #include "base/cast.hh"
35 #include "base/stl_helpers.hh"
42 
43 using namespace std;
45 
47  : Network(p), m_buffer_size(p->buffer_size),
48  m_endpoint_bandwidth(p->endpoint_bandwidth),
49  m_adaptive_routing(p->adaptive_routing)
50 {
51  // record the routers
52  for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
53  i != p->routers.end(); ++i) {
54  Switch* s = safe_cast<Switch*>(*i);
55  m_switches.push_back(s);
56  s->init_net_ptr(this);
57  }
58 
59  m_int_link_buffers = p->int_link_buffers;
61 }
62 
63 void
65 {
66  Network::init();
67 
68  // The topology pointer should have already been initialized in
69  // the parent class network constructor.
70  assert(m_topology_ptr != NULL);
72 }
73 
75 {
78 }
79 
80 // From a switch to an endpoint node
81 void
83  const NetDest& routing_table_entry)
84 {
85  assert(dest < m_nodes);
86  assert(src < m_switches.size());
87  assert(m_switches[src] != NULL);
88 
89  SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
90 
91  m_switches[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry,
92  simple_link->m_latency,
93  simple_link->m_bw_multiplier);
94 }
95 
96 // From an endpoint node to a switch
97 void
99  const NetDest& routing_table_entry)
100 {
101  assert(src < m_nodes);
102  m_switches[dest]->addInPort(m_toNetQueues[src]);
103 }
104 
105 // From a switch to a switch
106 void
108  const NetDest& routing_table_entry,
109  PortDirection src_outport,
110  PortDirection dst_inport)
111 {
112  // Create a set of new MessageBuffers
114 
115  for (int i = 0; i < m_virtual_networks; i++) {
116  // allocate a buffer
120  queues[i] = buffer_ptr;
121  }
122 
123  // Connect it to the two switches
124  SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
125 
126  m_switches[dest]->addInPort(queues);
127  m_switches[src]->addOutPort(queues, routing_table_entry,
128  simple_link->m_latency,
129  simple_link->m_bw_multiplier);
130 }
131 
132 void
134 {
136 
137  for (MessageSizeType type = MessageSizeType_FIRST;
138  type < MessageSizeType_NUM; ++type) {
139  m_msg_counts[(unsigned int) type]
140  .name(name() + ".msg_count." + MessageSizeType_to_string(type))
141  .flags(Stats::nozero)
142  ;
143  m_msg_bytes[(unsigned int) type]
144  .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
145  .flags(Stats::nozero)
146  ;
147 
148  // Now state what the formula is.
149  for (int i = 0; i < m_switches.size(); i++) {
150  m_msg_counts[(unsigned int) type] +=
151  sum(m_switches[i]->getMsgCount(type));
152  }
153 
154  m_msg_bytes[(unsigned int) type] =
155  m_msg_counts[(unsigned int) type] * Stats::constant(
157  }
158 }
159 
160 void
162 {
163  for (int i = 0; i < m_switches.size(); i++) {
164  m_switches[i]->collateStats();
165  }
166 }
167 
168 void
169 SimpleNetwork::print(ostream& out) const
170 {
171  out << "[SimpleNetwork]";
172 }
173 
175 SimpleNetworkParams::create()
176 {
177  return new SimpleNetwork(this);
178 }
179 
180 /*
181  * The simple network has an array of switches. These switches have buffers
182  * that need to be accessed for functional reads and writes. Also the links
183  * between different switches have buffers that need to be accessed.
184  */
185 bool
187 {
188  for (unsigned int i = 0; i < m_switches.size(); i++) {
189  if (m_switches[i]->functionalRead(pkt)) {
190  return true;
191  }
192  }
193 
194  return false;
195 }
196 
197 uint32_t
199 {
200  uint32_t num_functional_writes = 0;
201 
202  for (unsigned int i = 0; i < m_switches.size(); i++) {
203  num_functional_writes += m_switches[i]->functionalWrite(pkt);
204  }
205 
206  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
207  num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
208  }
209  return num_functional_writes;
210 }
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:118
Bitfield< 7 > i
Definition: miscregs.hh:1378
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
void print(std::ostream &out) const
void init_net_ptr(SimpleNetwork *net_ptr)
Definition: Switch.hh:79
Stats::Formula m_msg_counts[MessageSizeType_NUM]
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Network.cc:104
STL vector class.
Definition: stl.hh:40
Topology * m_topology_ptr
Definition: Network.hh:113
bool functionalRead(Packet *pkt)
Definition: Switch.hh:57
unsigned int NodeID
Definition: TypeDefines.hh:34
unsigned int SwitchID
Definition: TypeDefines.hh:35
Bitfield< 4 > s
Definition: miscregs.hh:1738
std::string PortDirection
Definition: Topology.hh:55
uint32_t functionalWrite(Packet *pkt)
Temp constant(T val)
Definition: statistics.hh:3211
std::vector< Switch * > m_switches
void makeInternalLink(SwitchID src, SwitchID dest, BasicLink *link, const NetDest &routing_table_entry, PortDirection src_outport, PortDirection dst_inport)
void deletePointers(C< T, A > &container)
Definition: stl_helpers.hh:77
Stats::Formula m_msg_bytes[MessageSizeType_NUM]
std::vector< MessageBuffer * > m_int_link_buffers
T safe_cast(U ptr)
Definition: cast.hh:61
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
void makeExtOutLink(SwitchID src, NodeID dest, BasicLink *link, const NetDest &routing_table_entry)
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:110
RubyNetworkParams Params
Definition: Network.hh:61
Temp sum(Temp val)
Definition: statistics.hh:3224
type
Definition: misc.hh:728
virtual const std::string name() const
Definition: sim_object.hh:117
void regStats()
Register statistics for this object.
uint32_t m_nodes
Definition: Network.hh:110
void makeExtInLink(NodeID src, SwitchID dest, BasicLink *link, const NetDest &routing_table_entry)
static uint32_t m_virtual_networks
Definition: Network.hh:111
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
void createLinks(Network *net)
Definition: Topology.cc:108
Bitfield< 0 > p
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition: Network.hh:119
void regStats() override
Register statistics for this object.
SimpleNetwork(const Params *p)
int m_num_connected_buffers

Generated on Fri Jun 9 2017 13:03:50 for gem5 by doxygen 1.8.6