gem5  v20.0.0.2
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  BasicLink* link,
88  const NetDest& routing_table_entry)
89 {
90  NodeID local_dest = getLocalNodeID(global_dest);
91  assert(local_dest < m_nodes);
92  assert(src < m_switches.size());
93  assert(m_switches[src] != NULL);
94 
95  SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
96 
97  m_switches[src]->addOutPort(m_fromNetQueues[local_dest],
98  routing_table_entry, simple_link->m_latency,
99  simple_link->m_bw_multiplier);
100 }
101 
102 // From an endpoint node to a switch
103 void
105  const NetDest& routing_table_entry)
106 {
107  NodeID local_src = getLocalNodeID(global_src);
108  assert(local_src < m_nodes);
109  m_switches[dest]->addInPort(m_toNetQueues[local_src]);
110 }
111 
112 // From a switch to a switch
113 void
115  const NetDest& routing_table_entry,
116  PortDirection src_outport,
117  PortDirection dst_inport)
118 {
119  // Create a set of new MessageBuffers
121 
122  for (int i = 0; i < m_virtual_networks; i++) {
123  // allocate a buffer
127  queues[i] = buffer_ptr;
128  }
129 
130  // Connect it to the two switches
131  SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
132 
133  m_switches[dest]->addInPort(queues);
134  m_switches[src]->addOutPort(queues, routing_table_entry,
135  simple_link->m_latency,
136  simple_link->m_bw_multiplier);
137 }
138 
139 void
141 {
143 
144  for (MessageSizeType type = MessageSizeType_FIRST;
145  type < MessageSizeType_NUM; ++type) {
146  m_msg_counts[(unsigned int) type]
147  .name(name() + ".msg_count." + MessageSizeType_to_string(type))
148  .flags(Stats::nozero)
149  ;
150  m_msg_bytes[(unsigned int) type]
151  .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
152  .flags(Stats::nozero)
153  ;
154 
155  // Now state what the formula is.
156  for (int i = 0; i < m_switches.size(); i++) {
157  m_msg_counts[(unsigned int) type] +=
158  sum(m_switches[i]->getMsgCount(type));
159  }
160 
161  m_msg_bytes[(unsigned int) type] =
162  m_msg_counts[(unsigned int) type] * Stats::constant(
164  }
165 }
166 
167 void
169 {
170  for (int i = 0; i < m_switches.size(); i++) {
171  m_switches[i]->collateStats();
172  }
173 }
174 
175 void
176 SimpleNetwork::print(ostream& out) const
177 {
178  out << "[SimpleNetwork]";
179 }
180 
182 SimpleNetworkParams::create()
183 {
184  return new SimpleNetwork(this);
185 }
186 
187 /*
188  * The simple network has an array of switches. These switches have buffers
189  * that need to be accessed for functional reads and writes. Also the links
190  * between different switches have buffers that need to be accessed.
191  */
192 bool
194 {
195  for (unsigned int i = 0; i < m_switches.size(); i++) {
196  if (m_switches[i]->functionalRead(pkt))
197  return true;
198  }
199  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
201  return true;
202  }
203 
204  return false;
205 }
206 
207 uint32_t
209 {
210  uint32_t num_functional_writes = 0;
211 
212  for (unsigned int i = 0; i < m_switches.size(); i++) {
213  num_functional_writes += m_switches[i]->functionalWrite(pkt);
214  }
215 
216  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
217  num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
218  }
219  return num_functional_writes;
220 }
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:158
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:153
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:158
RubyNetworkParams Params
Definition: Network.hh:79
void print(std::ostream &out) const
virtual const std::string name() const
Definition: sim_object.hh:128
NodeID getLocalNodeID(NodeID global_id) const
Definition: Network.cc:247
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Network.cc:152
void regStats()
Callback to set stat parameters.
uint32_t m_nodes
Definition: Network.hh:150
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:151
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:159
SimpleNetwork(const Params *p)
int m_num_connected_buffers

Generated on Mon Jun 8 2020 15:45:12 for gem5 by doxygen 1.8.13