Throttle.cc (7024:30883414ad10) Throttle.cc (7054:7d6862b80049)
1
2/*
3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met: redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer;

--- 12 unchanged lines hidden (view full) ---

22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
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;

--- 12 unchanged lines hidden (view full) ---

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.
27 */
28
30/*
31 * $Id$
32 *
33 * Description: see Throttle.hh
34 *
35 */
36
37#include "mem/ruby/network/simple/Throttle.hh"
29#include "base/cprintf.hh"
30#include "mem/protocol/Protocol.hh"
38#include "mem/ruby/buffers/MessageBuffer.hh"
39#include "mem/ruby/network/Network.hh"
31#include "mem/ruby/buffers/MessageBuffer.hh"
32#include "mem/ruby/network/Network.hh"
40#include "mem/ruby/system/System.hh"
33#include "mem/ruby/network/simple/Throttle.hh"
41#include "mem/ruby/slicc_interface/NetworkMessage.hh"
34#include "mem/ruby/slicc_interface/NetworkMessage.hh"
42#include "mem/protocol/Protocol.hh"
35#include "mem/ruby/system/System.hh"
43
44const int HIGH_RANGE = 256;
45const int ADJUST_INTERVAL = 50000;
46const int MESSAGE_SIZE_MULTIPLIER = 1000;
47//const int BROADCAST_SCALING = 4; // Have a 16p system act like a 64p systems
48const int BROADCAST_SCALING = 1;
49const int PRIORITY_SWITCH_LIMIT = 128;
50
51static int network_message_to_size(NetworkMessage* net_msg_ptr);
52
36
37const int HIGH_RANGE = 256;
38const int ADJUST_INTERVAL = 50000;
39const int MESSAGE_SIZE_MULTIPLIER = 1000;
40//const int BROADCAST_SCALING = 4; // Have a 16p system act like a 64p systems
41const int BROADCAST_SCALING = 1;
42const int PRIORITY_SWITCH_LIMIT = 128;
43
44static int network_message_to_size(NetworkMessage* net_msg_ptr);
45
53extern std::ostream * debug_cout_ptr;
46extern std::ostream *debug_cout_ptr;
54
47
55Throttle::Throttle(int sID, NodeID node, int link_latency, int link_bandwidth_multiplier)
48Throttle::Throttle(int sID, NodeID node, int link_latency,
49 int link_bandwidth_multiplier)
56{
50{
57 init(node, link_latency, link_bandwidth_multiplier);
58 m_sID = sID;
51 init(node, link_latency, link_bandwidth_multiplier);
52 m_sID = sID;
59}
60
53}
54
61Throttle::Throttle(NodeID node, int link_latency, int link_bandwidth_multiplier)
55Throttle::Throttle(NodeID node, int link_latency,
56 int link_bandwidth_multiplier)
62{
57{
63 init(node, link_latency, link_bandwidth_multiplier);
64 m_sID = 0;
58 init(node, link_latency, link_bandwidth_multiplier);
59 m_sID = 0;
65}
66
60}
61
67void Throttle::init(NodeID node, int link_latency, int link_bandwidth_multiplier)
62void
63Throttle::init(NodeID node, int link_latency, int link_bandwidth_multiplier)
68{
64{
69 m_node = node;
70 m_vnets = 0;
65 m_node = node;
66 m_vnets = 0;
71
67
72 ASSERT(link_bandwidth_multiplier > 0);
73 m_link_bandwidth_multiplier = link_bandwidth_multiplier;
74 m_link_latency = link_latency;
68 ASSERT(link_bandwidth_multiplier > 0);
69 m_link_bandwidth_multiplier = link_bandwidth_multiplier;
70 m_link_latency = link_latency;
75
71
76 m_wakeups_wo_switch = 0;
77 clearStats();
72 m_wakeups_wo_switch = 0;
73 clearStats();
78}
79
74}
75
80void Throttle::clear()
76void
77Throttle::clear()
81{
78{
82 for (int counter = 0; counter < m_vnets; counter++) {
83 m_in[counter]->clear();
84 m_out[counter]->clear();
85 }
79 for (int counter = 0; counter < m_vnets; counter++) {
80 m_in[counter]->clear();
81 m_out[counter]->clear();
82 }
86}
87
83}
84
88void Throttle::addLinks(const Vector<MessageBuffer*>& in_vec, const Vector<MessageBuffer*>& out_vec)
85void
86Throttle::addLinks(const Vector<MessageBuffer*>& in_vec,
87 const Vector<MessageBuffer*>& out_vec)
89{
88{
90 assert(in_vec.size() == out_vec.size());
91 for (int i=0; i92 addVirtualNetwork(in_vec[i], out_vec[i]);
93 }
89 assert(in_vec.size() == out_vec.size());
90 for (int i=0; i<in_vec.size(); i++) {
91 addVirtualNetwork(in_vec[i], out_vec[i]);
92 }
94
93
95 m_message_counters.setSize(MessageSizeType_NUM);
96 for (int i=0; i<MessageSizeType_NUM; i++) {
97 m_message_counters[i].setSize(in_vec.size());
98 for (int j=0; j<m_message_counters[i].size(); j++) {
99 m_message_counters[i][j] = 0;
94 m_message_counters.setSize(MessageSizeType_NUM);
95 for (int i = 0; i < MessageSizeType_NUM; i++) {
96 m_message_counters[i].setSize(in_vec.size());
97 for (int j = 0; j<m_message_counters[i].size(); j++) {
98 m_message_counters[i][j] = 0;
99 }
100 }
100 }
101 }
102}
103
101}
102
104void Throttle::addVirtualNetwork(MessageBuffer* in_ptr, MessageBuffer* out_ptr)
103void
104Throttle::addVirtualNetwork(MessageBuffer* in_ptr, MessageBuffer* out_ptr)
105{
105{
106 m_units_remaining.insertAtBottom(0);
107 m_in.insertAtBottom(in_ptr);
108 m_out.insertAtBottom(out_ptr);
106 m_units_remaining.insertAtBottom(0);
107 m_in.insertAtBottom(in_ptr);
108 m_out.insertAtBottom(out_ptr);
109
109
110 // Set consumer and description
111 m_in[m_vnets]->setConsumer(this);
112 string desc = "[Queue to Throttle " + NodeIDToString(m_sID) + " " + NodeIDToString(m_node) + "]";
113 m_in[m_vnets]->setDescription(desc);
114 m_vnets++;
110 // Set consumer and description
111 m_in[m_vnets]->setConsumer(this);
112 string desc = "[Queue to Throttle " + NodeIDToString(m_sID) + " " +
113 NodeIDToString(m_node) + "]";
114 m_in[m_vnets]->setDescription(desc);
115 m_vnets++;
115}
116
116}
117
117void Throttle::wakeup()
118void
119Throttle::wakeup()
118{
120{
119 // Limits the number of message sent to a limited number of bytes/cycle.
120 assert(getLinkBandwidth() > 0);
121 int bw_remaining = getLinkBandwidth();
121 // Limits the number of message sent to a limited number of bytes/cycle.
122 assert(getLinkBandwidth() > 0);
123 int bw_remaining = getLinkBandwidth();
122
124
123 // Give the highest numbered link priority most of the time
124 m_wakeups_wo_switch++;
125 int highest_prio_vnet = m_vnets-1;
126 int lowest_prio_vnet = 0;
127 int counter = 1;
128 bool schedule_wakeup = false;
125 // Give the highest numbered link priority most of the time
126 m_wakeups_wo_switch++;
127 int highest_prio_vnet = m_vnets-1;
128 int lowest_prio_vnet = 0;
129 int counter = 1;
130 bool schedule_wakeup = false;
129
131
130 // invert priorities to avoid starvation seen in the component network
131 if (m_wakeups_wo_switch > PRIORITY_SWITCH_LIMIT) {
132 m_wakeups_wo_switch = 0;
133 highest_prio_vnet = 0;
134 lowest_prio_vnet = m_vnets-1;
135 counter = -1;
136 }
132 // invert priorities to avoid starvation seen in the component network
133 if (m_wakeups_wo_switch > PRIORITY_SWITCH_LIMIT) {
134 m_wakeups_wo_switch = 0;
135 highest_prio_vnet = 0;
136 lowest_prio_vnet = m_vnets-1;
137 counter = -1;
138 }
137
139
138 for (int vnet = highest_prio_vnet; (vnet*counter) >= (counter*lowest_prio_vnet); vnet -= counter) {
140 for (int vnet = highest_prio_vnet;
141 (vnet * counter) >= (counter * lowest_prio_vnet);
142 vnet -= counter) {
139
143
140 assert(m_out[vnet] != NULL);
141 assert(m_in[vnet] != NULL);
142 assert(m_units_remaining[vnet] >= 0);
144 assert(m_out[vnet] != NULL);
145 assert(m_in[vnet] != NULL);
146 assert(m_units_remaining[vnet] >= 0);
143
147
144 while ((bw_remaining > 0) && ((m_in[vnet]->isReady()) || (m_units_remaining[vnet] > 0)) && m_out[vnet]->areNSlotsAvailable(1)) {
148 while (bw_remaining > 0 &&
149 (m_in[vnet]->isReady() || m_units_remaining[vnet] > 0) &&
150 m_out[vnet]->areNSlotsAvailable(1)) {
145
151
146 // See if we are done transferring the previous message on this virtual network
147 if (m_units_remaining[vnet] == 0 && m_in[vnet]->isReady()) {
152 // See if we are done transferring the previous message on
153 // this virtual network
154 if (m_units_remaining[vnet] == 0 && m_in[vnet]->isReady()) {
155 // Find the size of the message we are moving
156 MsgPtr msg_ptr = m_in[vnet]->peekMsgPtr();
157 NetworkMessage* net_msg_ptr =
158 safe_cast<NetworkMessage*>(msg_ptr.ref());
159 m_units_remaining[vnet] +=
160 network_message_to_size(net_msg_ptr);
148
161
149 // Find the size of the message we are moving
150 MsgPtr msg_ptr = m_in[vnet]->peekMsgPtr();
151 NetworkMessage* net_msg_ptr = dynamic_cast<NetworkMessage*>(msg_ptr.ref());
152 m_units_remaining[vnet] += network_message_to_size(net_msg_ptr);
162 DEBUG_NEWLINE(NETWORK_COMP,HighPrio);
163 DEBUG_MSG(NETWORK_COMP, HighPrio,
164 csprintf("throttle: %d my bw %d bw spent enqueueing "
165 "net msg %d time: %d.",
166 m_node, getLinkBandwidth(), m_units_remaining[vnet],
167 g_eventQueue_ptr->getTime()));
153
168
154 DEBUG_NEWLINE(NETWORK_COMP,HighPrio);
155 DEBUG_MSG(NETWORK_COMP,HighPrio,"throttle: " + int_to_string(m_node)
156 + " my bw " + int_to_string(getLinkBandwidth())
157 + " bw spent enqueueing net msg " + int_to_string(m_units_remaining[vnet])
158 + " time: " + int_to_string(g_eventQueue_ptr->getTime()) + ".");
169 // Move the message
170 m_out[vnet]->enqueue(m_in[vnet]->peekMsgPtr(), m_link_latency);
171 m_in[vnet]->pop();
159
172
160 // Move the message
161 m_out[vnet]->enqueue(m_in[vnet]->peekMsgPtr(), m_link_latency);
162 m_in[vnet]->pop();
173 // Count the message
174 m_message_counters[net_msg_ptr->getMessageSize()][vnet]++;
163
175
164 // Count the message
165 m_message_counters[net_msg_ptr->getMessageSize()][vnet]++;
176 DEBUG_MSG(NETWORK_COMP,LowPrio,*m_out[vnet]);
177 DEBUG_NEWLINE(NETWORK_COMP,HighPrio);
178 }
166
179
167 DEBUG_MSG(NETWORK_COMP,LowPrio,*m_out[vnet]);
168 DEBUG_NEWLINE(NETWORK_COMP,HighPrio);
169 }
180 // Calculate the amount of bandwidth we spent on this message
181 int diff = m_units_remaining[vnet] - bw_remaining;
182 m_units_remaining[vnet] = max(0, diff);
183 bw_remaining = max(0, -diff);
184 }
170
185
171 // Calculate the amount of bandwidth we spent on this message
172 int diff = m_units_remaining[vnet] - bw_remaining;
173 m_units_remaining[vnet] = max(0, diff);
174 bw_remaining = max(0, -diff);
186 if (bw_remaining > 0 &&
187 (m_in[vnet]->isReady() || m_units_remaining[vnet] > 0) &&
188 !m_out[vnet]->areNSlotsAvailable(1)) {
189 DEBUG_MSG(NETWORK_COMP,LowPrio,vnet);
190 // schedule me to wakeup again because I'm waiting for my
191 // output queue to become available
192 schedule_wakeup = true;
193 }
175 }
176
194 }
195
177 if ((bw_remaining > 0) && ((m_in[vnet]->isReady()) || (m_units_remaining[vnet] > 0)) && !m_out[vnet]->areNSlotsAvailable(1)) {
178 DEBUG_MSG(NETWORK_COMP,LowPrio,vnet);
179 schedule_wakeup = true; // schedule me to wakeup again because I'm waiting for my output queue to become available
180 }
181 }
196 // We should only wake up when we use the bandwidth
197 // This is only mostly true
198 // assert(bw_remaining != getLinkBandwidth());
182
199
183 // We should only wake up when we use the bandwidth
184 // assert(bw_remaining != getLinkBandwidth()); // This is only mostly true
200 // Record that we used some or all of the link bandwidth this cycle
201 double ratio = 1.0 - (double(bw_remaining) / double(getLinkBandwidth()));
185
202
186 // Record that we used some or all of the link bandwidth this cycle
187 double ratio = 1.0-(double(bw_remaining)/double(getLinkBandwidth()));
188 // If ratio = 0, we used no bandwidth, if ratio = 1, we used all
189 linkUtilized(ratio);
203 // If ratio = 0, we used no bandwidth, if ratio = 1, we used all
204 linkUtilized(ratio);
190
205
191 if ((bw_remaining > 0) && !schedule_wakeup) {
192 // We have extra bandwidth and our output buffer was available, so we must not have anything else to do until another message arrives.
193 DEBUG_MSG(NETWORK_COMP,LowPrio,*this);
194 DEBUG_MSG(NETWORK_COMP,LowPrio,"not scheduled again");
195 } else {
196 DEBUG_MSG(NETWORK_COMP,LowPrio,*this);
197 DEBUG_MSG(NETWORK_COMP,LowPrio,"scheduled again");
198 // We are out of bandwidth for this cycle, so wakeup next cycle and continue
199 g_eventQueue_ptr->scheduleEvent(this, 1);
200 }
206 if (bw_remaining > 0 && !schedule_wakeup) {
207 // We have extra bandwidth and our output buffer was
208 // available, so we must not have anything else to do until
209 // another message arrives.
210 DEBUG_MSG(NETWORK_COMP, LowPrio, *this);
211 DEBUG_MSG(NETWORK_COMP, LowPrio, "not scheduled again");
212 } else {
213 DEBUG_MSG(NETWORK_COMP, LowPrio, *this);
214 DEBUG_MSG(NETWORK_COMP, LowPrio, "scheduled again");
215
216 // We are out of bandwidth for this cycle, so wakeup next
217 // cycle and continue
218 g_eventQueue_ptr->scheduleEvent(this, 1);
219 }
201}
202
220}
221
203void Throttle::printStats(ostream& out) const
222void
223Throttle::printStats(ostream& out) const
204{
224{
205 out << "utilized_percent: " << getUtilization() << endl;
225 out << "utilized_percent: " << getUtilization() << endl;
206}
207
226}
227
208void Throttle::clearStats()
228void
229Throttle::clearStats()
209{
230{
210 m_ruby_start = g_eventQueue_ptr->getTime();
211 m_links_utilized = 0.0;
231 m_ruby_start = g_eventQueue_ptr->getTime();
232 m_links_utilized = 0.0;
212
233
213 for (int i=0; i<m_message_counters.size(); i++) {
214 for (int j=0; j<m_message_counters[i].size(); j++) {
215 m_message_counters[i][j] = 0;
234 for (int i = 0; i < m_message_counters.size(); i++) {
235 for (int j = 0; j < m_message_counters[i].size(); j++) {
236 m_message_counters[i][j] = 0;
237 }
216 }
238 }
217 }
218}
219
239}
240
220void Throttle::printConfig(ostream& out) const
241void
242Throttle::printConfig(ostream& out) const
221{
243{
222
223}
224
244}
245
225double Throttle::getUtilization() const
246double
247Throttle::getUtilization() const
226{
248{
227 return (100.0 * double(m_links_utilized)) / (double(g_eventQueue_ptr->getTime()-m_ruby_start));
249 return 100.0 * double(m_links_utilized) /
250 double(g_eventQueue_ptr->getTime()-m_ruby_start);
228}
229
251}
252
230void Throttle::print(ostream& out) const
253void
254Throttle::print(ostream& out) const
231{
255{
232 out << "[Throttle: " << m_sID << " " << m_node << " bw: " << getLinkBandwidth() << "]";
256 out << "[Throttle: " << m_sID << " " << m_node
257 << " bw: " << getLinkBandwidth() << "]";
233}
234
258}
259
235// Helper function
236
237static
238int network_message_to_size(NetworkMessage* net_msg_ptr)
260int
261network_message_to_size(NetworkMessage* net_msg_ptr)
239{
262{
240 assert(net_msg_ptr != NULL);
263 assert(net_msg_ptr != NULL);
241
264
242 // Artificially increase the size of broadcast messages
243 if (BROADCAST_SCALING > 1) {
244 if (net_msg_ptr->getDestination().isBroadcast()) {
245 return (RubySystem::getNetwork()->MessageSizeType_to_int(net_msg_ptr->getMessageSize()) * MESSAGE_SIZE_MULTIPLIER * BROADCAST_SCALING);
246 }
247 }
248 return (RubySystem::getNetwork()->MessageSizeType_to_int(net_msg_ptr->getMessageSize()) * MESSAGE_SIZE_MULTIPLIER);
265 int size = RubySystem::getNetwork()->
266 MessageSizeType_to_int(net_msg_ptr->getMessageSize());
267 size *= MESSAGE_SIZE_MULTIPLIER;
268
269 // Artificially increase the size of broadcast messages
270 if (BROADCAST_SCALING > 1 && net_msg_ptr->getDestination().isBroadcast())
271 size *= BROADCAST_SCALING;
272
273 return size;
249}
274}