gem5  v20.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
SimpleNetwork.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 ARM Limited
3  * All rights reserved.
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
42 
43 #include <cassert>
44 #include <numeric>
45 
46 #include "base/cast.hh"
53 
54 using namespace std;
55 
57  : Network(p), m_buffer_size(p->buffer_size),
58  m_endpoint_bandwidth(p->endpoint_bandwidth),
59  m_adaptive_routing(p->adaptive_routing)
60 {
61  // record the routers
62  for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
63  i != p->routers.end(); ++i) {
64  Switch* s = safe_cast<Switch*>(*i);
65  m_switches.push_back(s);
66  s->init_net_ptr(this);
67  }
68 
69  m_int_link_buffers = p->int_link_buffers;
71 }
72 
73 void
75 {
76  Network::init();
77 
78  // The topology pointer should have already been initialized in
79  // the parent class network constructor.
80  assert(m_topology_ptr != NULL);
82 }
83 
84 // From a switch to an endpoint node
85 void
87  const NetDest& routing_table_entry)
88 {
89  assert(dest < m_nodes);
90  assert(src < m_switches.size());
91  assert(m_switches[src] != NULL);
92 
93  SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
94 
95  m_switches[src]->addOutPort(m_fromNetQueues[dest], routing_table_entry,
96  simple_link->m_latency,
97  simple_link->m_bw_multiplier);
98 }
99 
100 // From an endpoint node to a switch
101 void
103  const NetDest& routing_table_entry)
104 {
105  assert(src < m_nodes);
106  m_switches[dest]->addInPort(m_toNetQueues[src]);
107 }
108 
109 // From a switch to a switch
110 void
112  const NetDest& routing_table_entry,
113  PortDirection src_outport,
114  PortDirection dst_inport)
115 {
116  // Create a set of new MessageBuffers
118 
119  for (int i = 0; i < m_virtual_networks; i++) {
120  // allocate a buffer
124  queues[i] = buffer_ptr;
125  }
126 
127  // Connect it to the two switches
128  SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
129 
130  m_switches[dest]->addInPort(queues);
131  m_switches[src]->addOutPort(queues, routing_table_entry,
132  simple_link->m_latency,
133  simple_link->m_bw_multiplier);
134 }
135 
136 void
138 {
140 
141  for (MessageSizeType type = MessageSizeType_FIRST;
142  type < MessageSizeType_NUM; ++type) {
143  m_msg_counts[(unsigned int) type]
144  .name(name() + ".msg_count." + MessageSizeType_to_string(type))
145  .flags(Stats::nozero)
146  ;
147  m_msg_bytes[(unsigned int) type]
148  .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
149  .flags(Stats::nozero)
150  ;
151 
152  // Now state what the formula is.
153  for (int i = 0; i < m_switches.size(); i++) {
154  m_msg_counts[(unsigned int) type] +=
155  sum(m_switches[i]->getMsgCount(type));
156  }
157 
158  m_msg_bytes[(unsigned int) type] =
159  m_msg_counts[(unsigned int) type] * Stats::constant(
161  }
162 }
163 
164 void
166 {
167  for (int i = 0; i < m_switches.size(); i++) {
168  m_switches[i]->collateStats();
169  }
170 }
171 
172 void
173 SimpleNetwork::print(ostream& out) const
174 {
175  out << "[SimpleNetwork]";
176 }
177 
179 SimpleNetworkParams::create()
180 {
181  return new SimpleNetwork(this);
182 }
183 
184 /*
185  * The simple network has an array of switches. These switches have buffers
186  * that need to be accessed for functional reads and writes. Also the links
187  * between different switches have buffers that need to be accessed.
188  */
189 bool
191 {
192  for (unsigned int i = 0; i < m_switches.size(); i++) {
193  if (m_switches[i]->functionalRead(pkt))
194  return true;
195  }
196  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
198  return true;
199  }
200 
201  return false;
202 }
203 
204 uint32_t
206 {
207  uint32_t num_functional_writes = 0;
208 
209  for (unsigned int i = 0; i < m_switches.size(); i++) {
210  num_functional_writes += m_switches[i]->functionalWrite(pkt);
211  }
212 
213  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
214  num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
215  }
216  return num_functional_writes;
217 }
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:156
Bitfield< 7 > i
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
void init_net_ptr(SimpleNetwork *net_ptr)
Definition: Switch.hh:79
Stats::Formula m_msg_counts[MessageSizeType_NUM]
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
STL vector class.
Definition: stl.hh:37
Topology * m_topology_ptr
Definition: Network.hh:151
bool functionalRead(Packet *pkt)
Definition: Switch.hh:59
unsigned int NodeID
Definition: TypeDefines.hh:34
uint8_t type
Definition: inet.hh:328
unsigned int SwitchID
Definition: TypeDefines.hh:35
Bitfield< 18 > sum
Definition: registers.hh:610
Bitfield< 4 > s
std::string PortDirection
Definition: Topology.hh:55
uint32_t functionalWrite(Packet *pkt)
Temp constant(T val)
Definition: statistics.hh:3329
std::vector< Switch * > m_switches
void makeInternalLink(SwitchID src, SwitchID dest, BasicLink *link, const NetDest &routing_table_entry, PortDirection src_outport, PortDirection dst_inport)
Stats::Formula m_msg_bytes[MessageSizeType_NUM]
std::vector< MessageBuffer * > m_int_link_buffers
T safe_cast(U ptr)
Definition: cast.hh:59
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:249
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:132
RubyNetworkParams Params
Definition: Network.hh:79
void print(std::ostream &out) const
virtual const std::string name() const
Definition: sim_object.hh:129
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Network.cc:126
void regStats()
Callback to set stat parameters.
uint32_t m_nodes
Definition: Network.hh:148
void makeExtInLink(NodeID src, SwitchID dest, BasicLink *link, const NetDest &routing_table_entry)
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
static uint32_t m_virtual_networks
Definition: Network.hh:149
const FlagsType nozero
Don&#39;t print if this is zero.
Definition: info.hh:57
void createLinks(Network *net)
Definition: Topology.cc:109
Bitfield< 0 > p
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition: Network.hh:157
SimpleNetwork(const Params *p)
int m_num_connected_buffers

Generated on Thu May 28 2020 16:21:34 for gem5 by doxygen 1.8.13