2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "base/cast.hh"
32 #include "base/stl_helpers.hh"
33 #include "mem/ruby/network/MessageBuffer.hh"
34 #include "mem/ruby/network/simple/PerfectSwitch.hh"
35 #include "mem/ruby/network/simple/SimpleNetwork.hh"
36 #include "mem/ruby/network/simple/Switch.hh"
37 #include "mem/ruby/network/simple/Throttle.hh"
40 using m5::stl_helpers::deletePointers
;
41 using m5::stl_helpers::operator<<;
43 Switch::Switch(const Params
*p
) : BasicRouter(p
)
45 m_perfect_switch
= new PerfectSwitch(m_id
, this, p
->virt_nets
);
50 delete m_perfect_switch
;
52 // Delete throttles (one per output port)
53 deletePointers(m_throttles
);
55 // Delete MessageBuffers
56 deletePointers(m_buffers_to_free
);
63 m_perfect_switch
->init(m_network_ptr
);
67 Switch::addInPort(const map
<int, MessageBuffer
*>& in
)
69 m_perfect_switch
->addInPort(in
);
72 it
.second
->setReceiver(this);
77 Switch::addOutPort(const map
<int, MessageBuffer
*>& out
,
78 const NetDest
& routing_table_entry
,
79 Cycles link_latency
, int bw_multiplier
)
82 Throttle
* throttle_ptr
= new Throttle(m_id
, m_throttles
.size(),
83 link_latency
, bw_multiplier
,
84 m_network_ptr
->getEndpointBandwidth(),
87 m_throttles
.push_back(throttle_ptr
);
89 // Create one buffer per vnet (these are intermediaryQueues)
90 map
<int, MessageBuffer
*> intermediateBuffers
;
92 for (auto& it
: out
) {
93 it
.second
->setSender(this);
95 MessageBuffer
* buffer_ptr
= new MessageBuffer
;
96 // Make these queues ordered
97 buffer_ptr
->setOrdering(true);
98 if (m_network_ptr
->getBufferSize() > 0) {
99 buffer_ptr
->resize(m_network_ptr
->getBufferSize());
102 intermediateBuffers
[it
.first
] = buffer_ptr
;
103 m_buffers_to_free
.push_back(buffer_ptr
);
105 buffer_ptr
->setSender(this);
106 buffer_ptr
->setReceiver(this);
109 // Hook the queues to the PerfectSwitch
110 m_perfect_switch
->addOutPort(intermediateBuffers
, routing_table_entry
);
112 // Hook the queues to the Throttle
113 throttle_ptr
->addLinks(intermediateBuffers
, out
);
117 Switch::getThrottle(LinkID link_number
) const
119 assert(m_throttles
[link_number
] != NULL
);
120 return m_throttles
[link_number
];
126 for (int link
= 0; link
< m_throttles
.size(); link
++) {
127 m_throttles
[link
]->regStats(name());
130 m_avg_utilization
.name(name() + ".percent_links_utilized");
131 for (unsigned int i
= 0; i
< m_throttles
.size(); i
++) {
132 m_avg_utilization
+= m_throttles
[i
]->getUtilization();
134 m_avg_utilization
/= Stats::constant(m_throttles
.size());
136 for (unsigned int type
= MessageSizeType_FIRST
;
137 type
< MessageSizeType_NUM
; ++type
) {
139 .name(name() + ".msg_count." +
140 MessageSizeType_to_string(MessageSizeType(type
)))
141 .flags(Stats::nozero
)
144 .name(name() + ".msg_bytes." +
145 MessageSizeType_to_string(MessageSizeType(type
)))
146 .flags(Stats::nozero
)
149 for (unsigned int i
= 0; i
< m_throttles
.size(); i
++) {
150 m_msg_counts
[type
] += m_throttles
[i
]->getMsgCount(type
);
152 m_msg_bytes
[type
] = m_msg_counts
[type
] * Stats::constant(
153 Network::MessageSizeType_to_int(MessageSizeType(type
)));
160 m_perfect_switch
->clearStats();
161 for (int i
= 0; i
< m_throttles
.size(); i
++) {
162 m_throttles
[i
]->clearStats();
167 Switch::collateStats()
169 m_perfect_switch
->collateStats();
170 for (int i
= 0; i
< m_throttles
.size(); i
++) {
171 m_throttles
[i
]->collateStats();
176 Switch::print(std::ostream
& out
) const
183 Switch::functionalRead(Packet
*pkt
)
185 // Access the buffers in the switch for performing a functional read
186 for (unsigned int i
= 0; i
< m_buffers_to_free
.size(); ++i
) {
187 if (m_buffers_to_free
[i
]->functionalRead(pkt
)) {
195 Switch::functionalWrite(Packet
*pkt
)
197 // Access the buffers in the switch for performing a functional write
198 uint32_t num_functional_writes
= 0;
199 for (unsigned int i
= 0; i
< m_buffers_to_free
.size(); ++i
) {
200 num_functional_writes
+= m_buffers_to_free
[i
]->functionalWrite(pkt
);
202 return num_functional_writes
;
206 SwitchParams::create()
208 return new Switch(this);