gem5  v20.1.0.0
Switch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Inria
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 <numeric>
45 
46 #include "base/cast.hh"
47 #include "base/stl_helpers.hh"
50 
51 using namespace std;
52 using m5::stl_helpers::operator<<;
53 
55  : BasicRouter(p), perfectSwitch(m_id, this, p->virt_nets),
56  m_num_connected_buffers(0)
57 {
58  m_port_buffers.reserve(p->port_buffers.size());
59  for (auto& buffer : p->port_buffers) {
60  m_port_buffers.emplace_back(buffer);
61  }
62 }
63 
64 void
66 {
69 }
70 
71 void
73 {
75 }
76 
77 void
79  const NetDest& routing_table_entry,
80  Cycles link_latency, int bw_multiplier)
81 {
82  // Create a throttle
83  throttles.emplace_back(m_id, m_network_ptr->params()->ruby_system,
84  throttles.size(), link_latency, bw_multiplier,
86 
87  // Create one buffer per vnet (these are intermediaryQueues)
88  vector<MessageBuffer*> intermediateBuffers;
89 
90  for (int i = 0; i < out.size(); ++i) {
91  assert(m_num_connected_buffers < m_port_buffers.size());
92  MessageBuffer* buffer_ptr =
95  intermediateBuffers.push_back(buffer_ptr);
96  }
97 
98  // Hook the queues to the PerfectSwitch
99  perfectSwitch.addOutPort(intermediateBuffers, routing_table_entry);
100 
101  // Hook the queues to the Throttle
102  throttles.back().addLinks(intermediateBuffers, out);
103 }
104 
105 void
107 {
109 
110  for (auto& throttle : throttles) {
111  throttle.regStats(name());
112  }
113 
114  m_avg_utilization.name(name() + ".percent_links_utilized");
115  for (const auto& throttle : throttles) {
116  m_avg_utilization += throttle.getUtilization();
117  }
119 
120  for (unsigned int type = MessageSizeType_FIRST;
121  type < MessageSizeType_NUM; ++type) {
123  .name(name() + ".msg_count." +
124  MessageSizeType_to_string(MessageSizeType(type)))
126  ;
128  .name(name() + ".msg_bytes." +
129  MessageSizeType_to_string(MessageSizeType(type)))
131  ;
132 
133  for (const auto& throttle : throttles) {
134  m_msg_counts[type] += throttle.getMsgCount(type);
135  }
137  Network::MessageSizeType_to_int(MessageSizeType(type)));
138  }
139 }
140 
141 void
143 {
145  for (auto& throttle : throttles) {
146  throttle.clearStats();
147  }
148 }
149 
150 void
152 {
154  for (auto& throttle : throttles) {
155  throttle.collateStats();
156  }
157 }
158 
159 void
160 Switch::print(std::ostream& out) const
161 {
162  // FIXME printing
163  out << "[Switch]";
164 }
165 
166 bool
168 {
169  for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
170  if (m_port_buffers[i]->functionalRead(pkt))
171  return true;
172  }
173  return false;
174 }
175 
176 uint32_t
178 {
179  // Access the buffers in the switch for performing a functional write
180  uint32_t num_functional_writes = 0;
181  for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
182  num_functional_writes += m_port_buffers[i]->functionalWrite(pkt);
183  }
184  return num_functional_writes;
185 }
186 
187 Switch *
188 SwitchParams::create()
189 {
190  return new Switch(this);
191 }
BasicRouter::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: BasicRouter.cc:39
Stats::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:64
PerfectSwitch::collateStats
void collateStats()
Definition: PerfectSwitch.cc:320
PerfectSwitch::addOutPort
void addOutPort(const std::vector< MessageBuffer * > &out, const NetDest &routing_table_entry)
Definition: PerfectSwitch.cc:86
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
BasicRouter::m_id
uint32_t m_id
Definition: BasicRouter.hh:53
type
uint8_t type
Definition: inet.hh:421
Switch::addInPort
void addInPort(const std::vector< MessageBuffer * > &in)
Definition: Switch.cc:72
SimpleNetwork.hh
cast.hh
Switch::m_network_ptr
SimpleNetwork * m_network_ptr
Definition: Switch.hh:90
std::vector< MessageBuffer * >
Switch
Definition: Switch.hh:59
PerfectSwitch::clearStats
void clearStats()
Definition: PerfectSwitch.cc:316
Switch::throttles
std::list< Throttle > throttles
Definition: Switch.hh:91
Switch::resetStats
void resetStats()
Callback to reset stats.
Definition: Switch.cc:142
Stats::DataWrap::flags
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:331
Switch::m_port_buffers
std::vector< MessageBuffer * > m_port_buffers
Definition: Switch.hh:94
BasicRouter::Params
BasicRouterParams Params
Definition: BasicRouter.hh:42
PerfectSwitch::addInPort
void addInPort(const std::vector< MessageBuffer * > &in)
Definition: PerfectSwitch.cc:71
Switch::perfectSwitch
PerfectSwitch perfectSwitch
Definition: Switch.hh:89
Switch::print
void print(std::ostream &out) const
Definition: Switch.cc:160
PerfectSwitch::init
void init(SimpleNetwork *)
Definition: PerfectSwitch.cc:61
BasicRouter
Definition: BasicRouter.hh:39
Switch::m_msg_counts
Stats::Formula m_msg_counts[MessageSizeType_NUM]
Definition: Switch.hh:98
Switch::functionalWrite
uint32_t functionalWrite(Packet *)
Definition: Switch.cc:177
Network::MessageSizeType_to_int
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:160
Switch::regStats
void regStats()
Callback to set stat parameters.
Definition: Switch.cc:106
Switch::m_msg_bytes
Stats::Formula m_msg_bytes[MessageSizeType_NUM]
Definition: Switch.hh:99
Switch::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Switch.cc:65
Stats::DataWrap::name
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:274
Switch::collateStats
void collateStats()
Definition: Switch.cc:151
Stats::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:57
Switch::addOutPort
void addOutPort(const std::vector< MessageBuffer * > &out, const NetDest &routing_table_entry, Cycles link_latency, int bw_multiplier)
Definition: Switch.cc:78
Network::params
const Params * params() const
Definition: Network.hh:81
SimpleNetwork::getEndpointBandwidth
int getEndpointBandwidth()
Definition: SimpleNetwork.hh:53
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
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Switch::m_num_connected_buffers
unsigned m_num_connected_buffers
Definition: Switch.hh:93
Switch::Switch
Switch(const Params *p)
Definition: Switch.cc:54
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Switch::m_avg_utilization
Stats::Formula m_avg_utilization
Definition: Switch.hh:97
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
MessageBuffer
Definition: MessageBuffer.hh:68
stl_helpers.hh
NetDest
Definition: NetDest.hh:39
Stats::constant
Temp constant(T val)
Definition: statistics.hh:3357
Switch::functionalRead
bool functionalRead(Packet *)
Definition: Switch.cc:167

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