gem5 [DEVELOP-FOR-25.0]
Loading...
Searching...
No Matches
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
51namespace gem5
52{
53
54namespace ruby
55{
56
57using stl_helpers::operator<<;
58
60 : BasicRouter(p),
61 perfectSwitch(m_id, this, p.virt_nets),
62 m_int_routing_latency(p.int_routing_latency),
63 m_ext_routing_latency(p.ext_routing_latency),
64 m_routing_unit(*p.routing_unit), m_num_connected_buffers(0),
65 switchStats(this)
66{
67 m_port_buffers.reserve(p.port_buffers.size());
68 for (auto& buffer : p.port_buffers) {
69 m_port_buffers.emplace_back(buffer);
70 }
71}
72
73void
75{
78 m_routing_unit.init_parent(this);
79}
80
81void
83{
84 perfectSwitch.addInPort(in);
85}
86
87void
88Switch::addOutPort(std::string link_name,
90 const NetDest& routing_table_entry,
91 Cycles link_latency, int link_weight,
92 int bw_multiplier,
93 bool is_external,
94 PortDirection dst_inport)
95{
96 const std::vector<int> &physical_vnets_channels =
97 m_network_ptr->params().physical_vnets_channels;
98
99 // Create a throttle
100 if (physical_vnets_channels.size() > 0 && !out.empty()) {
101 // Assign a different bandwith for each vnet channel if specified by
102 // physical_vnets_bandwidth, otherwise all channels use bw_multiplier
103 std::vector<int> physical_vnets_bandwidth =
104 m_network_ptr->params().physical_vnets_bandwidth;
105 physical_vnets_bandwidth.resize(out.size(), bw_multiplier);
106
107 throttles.emplace_back(m_id, m_network_ptr->params().ruby_system,
108 throttles.size(), link_latency,
109 physical_vnets_channels, physical_vnets_bandwidth,
110 m_network_ptr->getEndpointBandwidth(), this, link_name);
111 } else {
112 throttles.emplace_back(m_id, m_network_ptr->params().ruby_system,
113 throttles.size(), link_latency, bw_multiplier,
114 m_network_ptr->getEndpointBandwidth(), this, link_name);
115 }
116
117 // Create one buffer per vnet (these are intermediaryQueues)
118 std::vector<MessageBuffer*> intermediateBuffers;
119
120 for (int i = 0; i < out.size(); ++i) {
122 MessageBuffer* buffer_ptr =
125 intermediateBuffers.push_back(buffer_ptr);
126 }
127
128 Tick routing_latency = is_external ? cyclesToTicks(m_ext_routing_latency) :
130 // Hook the queues to the PerfectSwitch
131 perfectSwitch.addOutPort(intermediateBuffers, routing_table_entry,
132 dst_inport, routing_latency, link_weight);
133
134 // Hook the queues to the Throttle
135 throttles.back().addLinks(intermediateBuffers, out);
136}
137
138void
140{
142
143 for (const auto& throttle : throttles) {
144 switchStats.m_avg_utilization += throttle.getUtilization();
145 }
146 switchStats.m_avg_utilization /= statistics::constant(throttles.size());
147
148 for (unsigned int type = MessageSizeType_FIRST;
149 type < MessageSizeType_NUM; ++type) {
150 switchStats.m_msg_counts[type] = new statistics::Formula(&switchStats,
151 csprintf("msg_count.%s",
152 MessageSizeType_to_string(MessageSizeType(type))).c_str());
153 switchStats.m_msg_counts[type]
154 ->flags(statistics::nozero)
155 ;
156
157 switchStats.m_msg_bytes[type] = new statistics::Formula(&switchStats,
158 csprintf("msg_bytes.%s",
159 MessageSizeType_to_string(MessageSizeType(type))).c_str());
160 switchStats.m_msg_bytes[type]
161 ->flags(statistics::nozero)
162 ;
163
164 for (const auto& throttle : throttles) {
165 *(switchStats.m_msg_counts[type]) += throttle.getMsgCount(type);
166 }
167 *(switchStats.m_msg_bytes[type]) =
168 *(switchStats.m_msg_counts[type]) * statistics::constant(
169 Network::MessageSizeType_to_int(MessageSizeType(type)));
170 }
171}
172
173void
175{
176 perfectSwitch.clearStats();
177}
178
179void
181{
182 perfectSwitch.collateStats();
183}
184
185void
186Switch::print(std::ostream& out) const
187{
188 // FIXME printing
189 out << "[Switch]";
190}
191
192bool
194{
195 for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
197 return true;
198 }
199 return false;
200}
201
202bool
204{
205 bool read = false;
206 for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
208 read = true;
209 }
210 return read;
211}
212
213uint32_t
215{
216 // Access the buffers in the switch for performing a functional write
217 uint32_t num_functional_writes = 0;
218 for (unsigned int i = 0; i < m_port_buffers.size(); ++i) {
219 num_functional_writes += m_port_buffers[i]->functionalWrite(pkt);
220 }
221 return num_functional_writes;
222}
223
226 : statistics::Group(parent),
227 m_avg_utilization(this, "percent_links_utilized")
228{
229
230}
231
232} // namespace ruby
233} // namespace gem5
Tick cyclesToTicks(Cycles c) const
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition packet.hh:295
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
BasicRouter(const Params &p)
static uint32_t MessageSizeType_to_int(MessageSizeType size_type)
Definition Network.cc:166
void addInPort(const std::vector< MessageBuffer * > &in)
Definition Switch.cc:82
void init()
init() is called after all C++ SimObjects have been created and all ports are connected.
Definition Switch.cc:74
BaseRoutingUnit & m_routing_unit
Definition Switch.hh:128
const Cycles m_int_routing_latency
Definition Switch.hh:125
PerfectSwitch perfectSwitch
Definition Switch.hh:121
SwitchParams Params
Definition Switch.hh:87
bool functionalRead(Packet *)
Definition Switch.cc:193
uint32_t functionalWrite(Packet *)
Definition Switch.cc:214
SimpleNetwork * m_network_ptr
Definition Switch.hh:122
void print(std::ostream &out) const
Definition Switch.cc:186
Switch(const Params &p)
Definition Switch.cc:59
const Cycles m_ext_routing_latency
Definition Switch.hh:126
void addOutPort(std::string switch_name, const std::vector< MessageBuffer * > &out, const NetDest &routing_table_entry, Cycles link_latency, int link_weight, int bw_multiplier, bool is_external, PortDirection dst_inport="")
Definition Switch.cc:88
unsigned m_num_connected_buffers
Definition Switch.hh:130
std::vector< MessageBuffer * > m_port_buffers
Definition Switch.hh:131
std::list< Throttle > throttles
Definition Switch.hh:123
void resetStats()
Callback to reset stats.
Definition Switch.cc:174
void collateStats()
Definition Switch.cc:180
void regStats()
Callback to set stat parameters.
Definition Switch.cc:139
gem5::ruby::Switch::SwitchStats switchStats
A formula for statistics that is calculated when printed.
Statistics container.
Definition group.hh:93
STL vector class.
Definition stl.hh:37
virtual void regStats()
Callback to set stat parameters.
Definition group.cc:68
Bitfield< 3, 0 > mask
Definition pcstate.hh:63
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 0 > p
std::string PortDirection
const FlagsType nozero
Don't print if this is zero.
Definition info.hh:67
Temp constant(T val)
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161
SwitchStats(statistics::Group *parent)
Definition Switch.cc:225
statistics::Formula m_avg_utilization
Definition Switch.hh:140

Generated on Mon May 26 2025 09:19:12 for gem5 by doxygen 1.13.2