gem5  v21.1.0.2
Switch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Inria
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 <numeric>
45 
46 #include "base/cast.hh"
47 #include "base/stl_helpers.hh"
50 
51 namespace gem5
52 {
53 
54 namespace ruby
55 {
56 
57 using stl_helpers::operator<<;
58 
60  : BasicRouter(p),
61  perfectSwitch(m_id, this, p.virt_nets), m_num_connected_buffers(0),
62  switchStats(this)
63 {
64  m_port_buffers.reserve(p.port_buffers.size());
65  for (auto& buffer : p.port_buffers) {
66  m_port_buffers.emplace_back(buffer);
67  }
68 }
69 
70 void
72 {
75 }
76 
77 void
79 {
81 }
82 
83 void
85  const NetDest& routing_table_entry,
86  Cycles link_latency, int bw_multiplier)
87 {
88  // Create a throttle
89  throttles.emplace_back(m_id, m_network_ptr->params().ruby_system,
90  throttles.size(), link_latency, bw_multiplier,
92 
93  // Create one buffer per vnet (these are intermediaryQueues)
94  std::vector<MessageBuffer*> intermediateBuffers;
95 
96  for (int i = 0; i < out.size(); ++i) {
97  assert(m_num_connected_buffers < m_port_buffers.size());
98  MessageBuffer* buffer_ptr =
101  intermediateBuffers.push_back(buffer_ptr);
102  }
103 
104  // Hook the queues to the PerfectSwitch
105  perfectSwitch.addOutPort(intermediateBuffers, routing_table_entry);
106 
107  // Hook the queues to the Throttle
108  throttles.back().addLinks(intermediateBuffers, out);
109 }
110 
111 void
113 {
115 
116  for (auto& throttle : throttles) {
117  throttle.regStats();
118  }
119 
120  for (const auto& throttle : throttles) {
121  switchStats.m_avg_utilization += throttle.getUtilization();
122  }
124 
125  for (unsigned int type = MessageSizeType_FIRST;
126  type < MessageSizeType_NUM; ++type) {
128  csprintf("msg_count.%s",
129  MessageSizeType_to_string(MessageSizeType(type))).c_str());
132  ;
133 
135  csprintf("msg_bytes.%s",
136  MessageSizeType_to_string(MessageSizeType(type))).c_str());
139  ;
140 
141  for (const auto& throttle : throttles) {
142  *(switchStats.m_msg_counts[type]) += throttle.getMsgCount(type);
143  }
146  Network::MessageSizeType_to_int(MessageSizeType(type)));
147  }
148 }
149 
150 void
152 {
154  for (auto& throttle : throttles) {
155  throttle.clearStats();
156  }
157 }
158 
159 void
161 {
163  for (auto& throttle : throttles) {
164  throttle.collateStats();
165  }
166 }
167 
168 void
169 Switch::print(std::ostream& out) const
170 {
171  // FIXME printing
172  out << "[Switch]";
173 }
174 
175 bool
177 {
178  for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
179  if (m_port_buffers[i]->functionalRead(pkt))
180  return true;
181  }
182  return false;
183 }
184 
185 bool
187 {
188  bool read = false;
189  for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
190  if (m_port_buffers[i]->functionalRead(pkt, mask))
191  read = true;
192  }
193  return read;
194 }
195 
196 uint32_t
198 {
199  // Access the buffers in the switch for performing a functional write
200  uint32_t num_functional_writes = 0;
201  for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
202  num_functional_writes += m_port_buffers[i]->functionalWrite(pkt);
203  }
204  return num_functional_writes;
205 }
206 
207 Switch::
209  : statistics::Group(parent),
210  m_avg_utilization(this, "percent_links_utilized")
211 {
212 
213 }
214 
215 } // namespace ruby
216 } // namespace gem5
gem5::ruby::WriteMask
Definition: WriteMask.hh:59
gem5::ruby::Switch::addInPort
void addInPort(const std::vector< MessageBuffer * > &in)
Definition: Switch.cc:78
gem5::ruby::Network::MessageSizeType_to_int
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition: Network.cc:164
gem5::ruby::BasicRouter
Definition: BasicRouter.hh:45
gem5::ruby::PerfectSwitch::clearStats
void clearStats()
Definition: PerfectSwitch.cc:321
gem5::ruby::Switch::resetStats
void resetStats()
Callback to reset stats.
Definition: Switch.cc:151
gem5::ruby::Switch::Params
SwitchParams Params
Definition: Switch.hh:80
gem5::ruby::Switch::m_num_connected_buffers
unsigned m_num_connected_buffers
Definition: Switch.hh:112
gem5::statistics::nozero
const FlagsType nozero
Don't print if this is zero.
Definition: info.hh:68
gem5::ruby::Switch::m_port_buffers
std::vector< MessageBuffer * > m_port_buffers
Definition: Switch.hh:113
gem5::ruby::BasicRouter::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: BasicRouter.cc:45
gem5::ruby::BasicRouter::m_id
uint32_t m_id
Definition: BasicRouter.hh:58
SimpleNetwork.hh
cast.hh
gem5::ruby::Switch::collateStats
void collateStats()
Definition: Switch.cc:160
gem5::statistics::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:2536
gem5::ruby::Switch::functionalWrite
uint32_t functionalWrite(Packet *)
Definition: Switch.cc:197
std::vector
STL vector class.
Definition: stl.hh:37
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::ruby::PerfectSwitch::collateStats
void collateStats()
Definition: PerfectSwitch.cc:325
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::ruby::Switch::switchStats
gem5::ruby::Switch::SwitchStats switchStats
gem5::ruby::Switch::SwitchStats::m_msg_bytes
statistics::Formula * m_msg_bytes[MessageSizeType_NUM]
Definition: Switch.hh:124
gem5::mask
constexpr uint64_t mask(unsigned nbits)
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition: bitfield.hh:63
gem5::statistics::constant
Temp constant(T val)
Definition: statistics.hh:2862
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::ruby::Switch::regStats
void regStats()
Callback to set stat parameters.
Definition: Switch.cc:112
gem5::ruby::PerfectSwitch::addInPort
void addInPort(const std::vector< MessageBuffer * > &in)
Definition: PerfectSwitch.cc:76
gem5::ruby::Switch::functionalRead
bool functionalRead(Packet *)
Definition: Switch.cc:176
gem5::SimObject::params
const Params & params() const
Definition: sim_object.hh:176
gem5::ruby::PerfectSwitch::init
void init(SimpleNetwork *)
Definition: PerfectSwitch.cc:66
gem5::ruby::Switch::SwitchStats::SwitchStats
SwitchStats(statistics::Group *parent)
Definition: Switch.cc:208
gem5::Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:283
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::ruby::Switch::SwitchStats::m_msg_counts
statistics::Formula * m_msg_counts[MessageSizeType_NUM]
Definition: Switch.hh:123
gem5::X86ISA::type
type
Definition: misc.hh:733
gem5::ruby::Switch::perfectSwitch
PerfectSwitch perfectSwitch
Definition: Switch.hh:108
gem5::ruby::Switch::m_network_ptr
SimpleNetwork * m_network_ptr
Definition: Switch.hh:109
gem5::ruby::Switch::addOutPort
void addOutPort(const std::vector< MessageBuffer * > &out, const NetDest &routing_table_entry, Cycles link_latency, int bw_multiplier)
Definition: Switch.cc:84
gem5::ruby::Switch::SwitchStats::m_avg_utilization
statistics::Formula m_avg_utilization
Definition: Switch.hh:122
gem5::ruby::Switch::print
void print(std::ostream &out) const
Definition: Switch.cc:169
gem5::statistics::Group::regStats
virtual void regStats()
Callback to set stat parameters.
Definition: group.cc:69
gem5::ruby::NetDest
Definition: NetDest.hh:45
MessageBuffer.hh
gem5::ruby::SimpleNetwork::getEndpointBandwidth
int getEndpointBandwidth()
Definition: SimpleNetwork.hh:71
Switch.hh
gem5::statistics::Group
Statistics container.
Definition: group.hh:93
gem5::statistics::DataWrap::flags
Derived & flags(Flags _flags)
Set the flags and marks this stat to print at the end of simulation.
Definition: statistics.hh:355
gem5::ruby::MessageBuffer
Definition: MessageBuffer.hh:74
gem5::ruby::PerfectSwitch::addOutPort
void addOutPort(const std::vector< MessageBuffer * > &out, const NetDest &routing_table_entry)
Definition: PerfectSwitch.cc:91
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ruby::Switch::throttles
std::list< Throttle > throttles
Definition: Switch.hh:110
stl_helpers.hh
gem5::ruby::Switch::init
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition: Switch.cc:71
gem5::ruby::Switch::Switch
Switch(const Params &p)
Definition: Switch.cc:59

Generated on Tue Sep 21 2021 12:25:41 for gem5 by doxygen 1.8.17