gem5  v21.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) 2020 Advanced Micro Devices, Inc.
3  * Copyright (c) 2019,2021 ARM Limited
4  * All rights reserved.
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
43 
44 #include <cassert>
45 #include <numeric>
46 
47 #include "base/cast.hh"
54 
56  : Network(p), m_buffer_size(p.buffer_size),
57  m_endpoint_bandwidth(p.endpoint_bandwidth),
58  m_adaptive_routing(p.adaptive_routing),
59  networkStats(this)
60 {
61  // record the routers
62  for (std::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  std::vector<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[0], simple_link->m_latency,
99  simple_link->m_bw_multiplier);
100 }
101 
102 // From an endpoint node to a switch
103 void
105  std::vector<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  std::vector<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[0],
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  networkStats.m_msg_counts[(unsigned int) type] =
148  csprintf("msg_count.%s", MessageSizeType_to_string(type)).c_str());
149  networkStats.m_msg_counts[(unsigned int) type]
150  ->flags(Stats::nozero)
151  ;
152 
153  networkStats.m_msg_bytes[(unsigned int) type] =
155  csprintf("msg_byte.%s", MessageSizeType_to_string(type)).c_str());
156  networkStats.m_msg_bytes[(unsigned int) type]
157  ->flags(Stats::nozero)
158  ;
159 
160  // Now state what the formula is.
161  for (int i = 0; i < m_switches.size(); i++) {
162  *(networkStats.m_msg_counts[(unsigned int) type]) +=
163  sum(m_switches[i]->getMsgCount(type));
164  }
165 
166  *(networkStats.m_msg_bytes[(unsigned int) type]) =
167  *(networkStats.m_msg_counts[(unsigned int) type]) *
169  }
170 }
171 
172 void
174 {
175  for (int i = 0; i < m_switches.size(); i++) {
176  m_switches[i]->collateStats();
177  }
178 }
179 
180 void
181 SimpleNetwork::print(std::ostream& out) const
182 {
183  out << "[SimpleNetwork]";
184 }
185 
186 /*
187  * The simple network has an array of switches. These switches have buffers
188  * that need to be accessed for functional reads and writes. Also the links
189  * between different switches have buffers that need to be accessed.
190  */
191 bool
193 {
194  for (unsigned int i = 0; i < m_switches.size(); i++) {
195  if (m_switches[i]->functionalRead(pkt))
196  return true;
197  }
198  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
200  return true;
201  }
202 
203  return false;
204 }
205 
206 bool
208 {
209  bool read = false;
210  for (unsigned int i = 0; i < m_switches.size(); i++) {
211  if (m_switches[i]->functionalRead(pkt, mask))
212  read = true;
213  }
214  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
216  read = true;
217  }
218  return read;
219 }
220 
221 uint32_t
223 {
224  uint32_t num_functional_writes = 0;
225 
226  for (unsigned int i = 0; i < m_switches.size(); i++) {
227  num_functional_writes += m_switches[i]->functionalWrite(pkt);
228  }
229 
230  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
231  num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
232  }
233  return num_functional_writes;
234 }
235 
238  : Stats::Group(parent)
239 {
240 
241 }
SimpleNetwork::makeExtInLink
void makeExtInLink(NodeID src, SwitchID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
Definition: SimpleNetwork.cc:104
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:63
Profiler.hh
SimpleNetwork::collateStats
void collateStats()
Definition: SimpleNetwork.cc:173
RiscvISA::sum
Bitfield< 18 > sum
Definition: registers.hh:634
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Network::m_toNetQueues
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:157
cast.hh
SimpleNetwork.hh
std::vector
STL vector class.
Definition: stl.hh:37
Network::m_virtual_networks
static uint32_t m_virtual_networks
Definition: Network.hh:150
Switch
Definition: Switch.hh:71
Throttle.hh
SimpleNetwork::networkStats
SimpleNetwork::NetworkStats networkStats
SimpleNetwork::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: SimpleNetwork.cc:74
SimpleNetwork::Params
SimpleNetworkParams Params
Definition: SimpleNetwork.hh:58
SimpleNetwork::functionalRead
bool functionalRead(Packet *pkt)
Definition: SimpleNetwork.cc:192
SimpleNetwork::m_num_connected_buffers
int m_num_connected_buffers
Definition: SimpleNetwork.hh:101
Network::getLocalNodeID
NodeID getLocalNodeID(NodeID global_id) const
Definition: Network.cc:247
SimpleNetwork::m_int_link_buffers
std::vector< MessageBuffer * > m_int_link_buffers
Definition: SimpleNetwork.hh:100
SimpleNetwork::makeInternalLink
void makeInternalLink(SwitchID src, SwitchID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry, PortDirection src_outport, PortDirection dst_inport)
Definition: SimpleNetwork.cc:114
SimpleNetwork::makeExtOutLink
void makeExtOutLink(SwitchID src, NodeID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
Definition: SimpleNetwork.cc:86
Network::MessageSizeType_to_int
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:158
SimpleNetwork::print
void print(std::ostream &out) const
Definition: SimpleNetwork.cc:181
Network
Definition: Network.hh:76
Stats::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:58
Network::m_fromNetQueues
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition: Network.hh:158
MessageBuffer.hh
Switch.hh
SimpleNetwork::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: SimpleNetwork.cc:222
Stats::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2538
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:258
Stats::Group
Statistics container.
Definition: group.hh:87
SimpleNetwork::m_switches
std::vector< Switch * > m_switches
Definition: SimpleNetwork.hh:99
Topology::createLinks
void createLinks(Network *net)
Definition: Topology.cc:109
SimpleNetwork::SimpleNetwork
SimpleNetwork(const Params &p)
Definition: SimpleNetwork.cc:55
SimObject::init
virtual void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: sim_object.cc:70
PortDirection
std::string PortDirection
Definition: Topology.hh:62
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
X86ISA::type
type
Definition: misc.hh:727
Stats
Definition: statistics.cc:53
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MessageBuffer
Definition: MessageBuffer.hh:68
SimpleNetwork::NetworkStats::m_msg_counts
Stats::Formula * m_msg_counts[MessageSizeType_NUM]
Definition: SimpleNetwork.hh:112
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
SimpleNetwork::NetworkStats::m_msg_bytes
Stats::Formula * m_msg_bytes[MessageSizeType_NUM]
Definition: SimpleNetwork.hh:113
SimpleNetwork::NetworkStats::NetworkStats
NetworkStats(Stats::Group *parent)
Definition: SimpleNetwork.cc:237
Network::m_nodes
uint32_t m_nodes
Definition: Network.hh:149
SimpleNetwork::regStats
void regStats()
Callback to set stat parameters.
Definition: SimpleNetwork.cc:140
WriteMask
Definition: WriteMask.hh:53
csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:158
NetDest.hh
SwitchID
unsigned int SwitchID
Definition: TypeDefines.hh:35
ArmISA::mask
Bitfield< 28, 24 > mask
Definition: miscregs_types.hh:711
Stats::constant
Temp constant(T val)
Definition: statistics.hh:2864
Network::m_topology_ptr
Topology * m_topology_ptr
Definition: Network.hh:152

Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17