gem5  v20.1.0.0
SimpleNetwork.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Advanced Micro Devices, Inc.
3  * Copyright (c) 2019 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 
55 using namespace std;
56 
58  : Network(p), m_buffer_size(p->buffer_size),
59  m_endpoint_bandwidth(p->endpoint_bandwidth),
60  m_adaptive_routing(p->adaptive_routing)
61 {
62  // record the routers
63  for (vector<BasicRouter*>::const_iterator i = p->routers.begin();
64  i != p->routers.end(); ++i) {
65  Switch* s = safe_cast<Switch*>(*i);
66  m_switches.push_back(s);
67  s->init_net_ptr(this);
68  }
69 
70  m_int_link_buffers = p->int_link_buffers;
72 }
73 
74 void
76 {
77  Network::init();
78 
79  // The topology pointer should have already been initialized in
80  // the parent class network constructor.
81  assert(m_topology_ptr != NULL);
83 }
84 
85 // From a switch to an endpoint node
86 void
88  BasicLink* link,
89  std::vector<NetDest>& routing_table_entry)
90 {
91  NodeID local_dest = getLocalNodeID(global_dest);
92  assert(local_dest < m_nodes);
93  assert(src < m_switches.size());
94  assert(m_switches[src] != NULL);
95 
96  SimpleExtLink *simple_link = safe_cast<SimpleExtLink*>(link);
97 
98  m_switches[src]->addOutPort(m_fromNetQueues[local_dest],
99  routing_table_entry[0], simple_link->m_latency,
100  simple_link->m_bw_multiplier);
101 }
102 
103 // From an endpoint node to a switch
104 void
106  std::vector<NetDest>& routing_table_entry)
107 {
108  NodeID local_src = getLocalNodeID(global_src);
109  assert(local_src < m_nodes);
110  m_switches[dest]->addInPort(m_toNetQueues[local_src]);
111 }
112 
113 // From a switch to a switch
114 void
116  std::vector<NetDest>& routing_table_entry,
117  PortDirection src_outport,
118  PortDirection dst_inport)
119 {
120  // Create a set of new MessageBuffers
122 
123  for (int i = 0; i < m_virtual_networks; i++) {
124  // allocate a buffer
128  queues[i] = buffer_ptr;
129  }
130 
131  // Connect it to the two switches
132  SimpleIntLink *simple_link = safe_cast<SimpleIntLink*>(link);
133 
134  m_switches[dest]->addInPort(queues);
135  m_switches[src]->addOutPort(queues, routing_table_entry[0],
136  simple_link->m_latency,
137  simple_link->m_bw_multiplier);
138 }
139 
140 void
142 {
144 
145  for (MessageSizeType type = MessageSizeType_FIRST;
146  type < MessageSizeType_NUM; ++type) {
147  m_msg_counts[(unsigned int) type]
148  .name(name() + ".msg_count." + MessageSizeType_to_string(type))
149  .flags(Stats::nozero)
150  ;
151  m_msg_bytes[(unsigned int) type]
152  .name(name() + ".msg_byte." + MessageSizeType_to_string(type))
153  .flags(Stats::nozero)
154  ;
155 
156  // Now state what the formula is.
157  for (int i = 0; i < m_switches.size(); i++) {
158  m_msg_counts[(unsigned int) type] +=
159  sum(m_switches[i]->getMsgCount(type));
160  }
161 
162  m_msg_bytes[(unsigned int) type] =
163  m_msg_counts[(unsigned int) type] * Stats::constant(
165  }
166 }
167 
168 void
170 {
171  for (int i = 0; i < m_switches.size(); i++) {
172  m_switches[i]->collateStats();
173  }
174 }
175 
176 void
177 SimpleNetwork::print(ostream& out) const
178 {
179  out << "[SimpleNetwork]";
180 }
181 
183 SimpleNetworkParams::create()
184 {
185  return new SimpleNetwork(this);
186 }
187 
188 /*
189  * The simple network has an array of switches. These switches have buffers
190  * that need to be accessed for functional reads and writes. Also the links
191  * between different switches have buffers that need to be accessed.
192  */
193 bool
195 {
196  for (unsigned int i = 0; i < m_switches.size(); i++) {
197  if (m_switches[i]->functionalRead(pkt))
198  return true;
199  }
200  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
202  return true;
203  }
204 
205  return false;
206 }
207 
208 uint32_t
210 {
211  uint32_t num_functional_writes = 0;
212 
213  for (unsigned int i = 0; i < m_switches.size(); i++) {
214  num_functional_writes += m_switches[i]->functionalWrite(pkt);
215  }
216 
217  for (unsigned int i = 0; i < m_int_link_buffers.size(); ++i) {
218  num_functional_writes += m_int_link_buffers[i]->functionalWrite(pkt);
219  }
220  return num_functional_writes;
221 }
SimpleNetwork::makeExtInLink
void makeExtInLink(NodeID src, SwitchID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
Definition: SimpleNetwork.cc:105
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
Profiler.hh
SimpleNetwork::collateStats
void collateStats()
Definition: SimpleNetwork.cc:169
RiscvISA::sum
Bitfield< 18 > sum
Definition: registers.hh:609
Network::Params
RubyNetworkParams Params
Definition: Network.hh:79
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Network::m_toNetQueues
std::vector< std::vector< MessageBuffer * > > m_toNetQueues
Definition: Network.hh:158
type
uint8_t type
Definition: inet.hh:421
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:151
Network::init
void init() override
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Network.cc:154
Switch
Definition: Switch.hh:59
SimpleNetwork::SimpleNetwork
SimpleNetwork(const Params *p)
Definition: SimpleNetwork.cc:57
Throttle.hh
SimpleNetwork::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: SimpleNetwork.cc:75
SimpleNetwork::m_msg_counts
Stats::Formula m_msg_counts[MessageSizeType_NUM]
Definition: SimpleNetwork.hh:94
SimpleNetwork::functionalRead
bool functionalRead(Packet *pkt)
Definition: SimpleNetwork.cc:194
SimpleNetwork::m_num_connected_buffers
int m_num_connected_buffers
Definition: SimpleNetwork.hh:88
Network::getLocalNodeID
NodeID getLocalNodeID(NodeID global_id) const
Definition: Network.cc:249
SimpleNetwork::m_int_link_buffers
std::vector< MessageBuffer * > m_int_link_buffers
Definition: SimpleNetwork.hh:87
SimpleNetwork
Definition: SimpleNetwork.hh:43
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:115
SimpleNetwork::m_msg_bytes
Stats::Formula m_msg_bytes[MessageSizeType_NUM]
Definition: SimpleNetwork.hh:95
SimpleNetwork::makeExtOutLink
void makeExtOutLink(SwitchID src, NodeID dest, BasicLink *link, std::vector< NetDest > &routing_table_entry)
Definition: SimpleNetwork.cc:87
Network::MessageSizeType_to_int
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:160
SimpleNetwork::print
void print(std::ostream &out) const
Definition: SimpleNetwork.cc:177
Network
Definition: Network.hh:76
Stats::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
Network::m_fromNetQueues
std::vector< std::vector< MessageBuffer * > > m_fromNetQueues
Definition: Network.hh:159
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
MessageBuffer.hh
Switch.hh
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
SimpleNetwork::functionalWrite
uint32_t functionalWrite(Packet *pkt)
Definition: SimpleNetwork.cc:209
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
SimpleNetwork::m_switches
std::vector< Switch * > m_switches
Definition: SimpleNetwork.hh:86
Topology::createLinks
void createLinks(Network *net)
Definition: Topology.cc:111
PortDirection
std::string PortDirection
Definition: Topology.hh:62
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MessageBuffer
Definition: MessageBuffer.hh:68
ArmISA::s
Bitfield< 4 > s
Definition: miscregs_types.hh:556
Network::m_nodes
uint32_t m_nodes
Definition: Network.hh:150
SimpleNetwork::regStats
void regStats()
Callback to set stat parameters.
Definition: SimpleNetwork.cc:141
NetDest.hh
SwitchID
unsigned int SwitchID
Definition: TypeDefines.hh:35
Stats::constant
Temp constant(T val)
Definition: statistics.hh:3357
Network::m_topology_ptr
Topology * m_topology_ptr
Definition: Network.hh:153

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17