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; 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. 15 * 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. 27 */ 28 29#include <cassert> 30 31#include "base/cast.hh" 32#include "base/cprintf.hh" 33#include "debug/RubyNetwork.hh"
| 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; 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. 15 * 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. 27 */ 28 29#include <cassert> 30 31#include "base/cast.hh" 32#include "base/cprintf.hh" 33#include "debug/RubyNetwork.hh"
|
34#include "mem/ruby/network/simple/Switch.hh"
| |
35#include "mem/ruby/network/simple/Throttle.hh" 36#include "mem/ruby/network/MessageBuffer.hh" 37#include "mem/ruby/network/Network.hh" 38#include "mem/ruby/slicc_interface/Message.hh" 39#include "mem/ruby/system/System.hh" 40 41using namespace std; 42 43const int MESSAGE_SIZE_MULTIPLIER = 1000; 44//const int BROADCAST_SCALING = 4; // Have a 16p system act like a 64p systems 45const int BROADCAST_SCALING = 1; 46const int PRIORITY_SWITCH_LIMIT = 128; 47 48static int network_message_to_size(Message* net_msg_ptr); 49 50Throttle::Throttle(int sID, RubySystem *rs, NodeID node, Cycles link_latency, 51 int link_bandwidth_multiplier, int endpoint_bandwidth,
| 34#include "mem/ruby/network/simple/Throttle.hh" 35#include "mem/ruby/network/MessageBuffer.hh" 36#include "mem/ruby/network/Network.hh" 37#include "mem/ruby/slicc_interface/Message.hh" 38#include "mem/ruby/system/System.hh" 39 40using namespace std; 41 42const int MESSAGE_SIZE_MULTIPLIER = 1000; 43//const int BROADCAST_SCALING = 4; // Have a 16p system act like a 64p systems 44const int BROADCAST_SCALING = 1; 45const int PRIORITY_SWITCH_LIMIT = 128; 46 47static int network_message_to_size(Message* net_msg_ptr); 48 49Throttle::Throttle(int sID, RubySystem *rs, NodeID node, Cycles link_latency, 50 int link_bandwidth_multiplier, int endpoint_bandwidth,
|
52 Switch *em) 53 : Consumer(em), m_switch_id(sID), m_switch(em), m_node(node), 54 m_ruby_system(rs)
| 51 ClockedObject *em) 52 : Consumer(em), m_ruby_system(rs)
|
55{
| 53{
|
| 54 init(node, link_latency, link_bandwidth_multiplier, endpoint_bandwidth); 55 m_sID = sID; 56} 57 58Throttle::Throttle(RubySystem *rs, NodeID node, Cycles link_latency, 59 int link_bandwidth_multiplier, int endpoint_bandwidth, 60 ClockedObject *em) 61 : Consumer(em), m_ruby_system(rs) 62{ 63 init(node, link_latency, link_bandwidth_multiplier, endpoint_bandwidth); 64 m_sID = 0; 65} 66 67void 68Throttle::init(NodeID node, Cycles link_latency, 69 int link_bandwidth_multiplier, int endpoint_bandwidth) 70{ 71 m_node = node;
|
56 m_vnets = 0; 57 58 assert(link_bandwidth_multiplier > 0); 59 m_link_bandwidth_multiplier = link_bandwidth_multiplier; 60 61 m_link_latency = link_latency; 62 m_endpoint_bandwidth = endpoint_bandwidth; 63 64 m_wakeups_wo_switch = 0; 65 m_link_utilization_proxy = 0; 66} 67 68void 69Throttle::addLinks(const vector<MessageBuffer*>& in_vec, 70 const vector<MessageBuffer*>& out_vec) 71{ 72 assert(in_vec.size() == out_vec.size()); 73 74 for (int vnet = 0; vnet < in_vec.size(); ++vnet) { 75 MessageBuffer *in_ptr = in_vec[vnet]; 76 MessageBuffer *out_ptr = out_vec[vnet]; 77 78 m_vnets++; 79 m_units_remaining.push_back(0); 80 m_in.push_back(in_ptr); 81 m_out.push_back(out_ptr); 82 83 // Set consumer and description 84 in_ptr->setConsumer(this);
| 72 m_vnets = 0; 73 74 assert(link_bandwidth_multiplier > 0); 75 m_link_bandwidth_multiplier = link_bandwidth_multiplier; 76 77 m_link_latency = link_latency; 78 m_endpoint_bandwidth = endpoint_bandwidth; 79 80 m_wakeups_wo_switch = 0; 81 m_link_utilization_proxy = 0; 82} 83 84void 85Throttle::addLinks(const vector<MessageBuffer*>& in_vec, 86 const vector<MessageBuffer*>& out_vec) 87{ 88 assert(in_vec.size() == out_vec.size()); 89 90 for (int vnet = 0; vnet < in_vec.size(); ++vnet) { 91 MessageBuffer *in_ptr = in_vec[vnet]; 92 MessageBuffer *out_ptr = out_vec[vnet]; 93 94 m_vnets++; 95 m_units_remaining.push_back(0); 96 m_in.push_back(in_ptr); 97 m_out.push_back(out_ptr); 98 99 // Set consumer and description 100 in_ptr->setConsumer(this);
|
85 string desc = "[Queue to Throttle " + to_string(m_switch_id) + " " +
| 101 string desc = "[Queue to Throttle " + to_string(m_sID) + " " +
|
86 to_string(m_node) + "]"; 87 } 88} 89 90void 91Throttle::operateVnet(int vnet, int &bw_remaining, bool &schedule_wakeup, 92 MessageBuffer *in, MessageBuffer *out) 93{ 94 if (out == nullptr || in == nullptr) { 95 return; 96 } 97 assert(m_units_remaining[vnet] >= 0); 98 99 while (bw_remaining > 0 && (in->isReady() || m_units_remaining[vnet] > 0) && 100 out->areNSlotsAvailable(1)) { 101 102 // See if we are done transferring the previous message on 103 // this virtual network 104 if (m_units_remaining[vnet] == 0 && in->isReady()) { 105 // Find the size of the message we are moving 106 MsgPtr msg_ptr = in->peekMsgPtr(); 107 Message *net_msg_ptr = msg_ptr.get(); 108 m_units_remaining[vnet] += 109 network_message_to_size(net_msg_ptr); 110 111 DPRINTF(RubyNetwork, "throttle: %d my bw %d bw spent " 112 "enqueueing net msg %d time: %lld.\n", 113 m_node, getLinkBandwidth(), m_units_remaining[vnet], 114 m_ruby_system->curCycle()); 115 116 // Move the message 117 in->dequeue(); 118 out->enqueue(msg_ptr, m_link_latency); 119 120 // Count the message 121 m_msg_counts[net_msg_ptr->getMessageSize()][vnet]++; 122 DPRINTF(RubyNetwork, "%s\n", *out); 123 } 124 125 // Calculate the amount of bandwidth we spent on this message 126 int diff = m_units_remaining[vnet] - bw_remaining; 127 m_units_remaining[vnet] = max(0, diff); 128 bw_remaining = max(0, -diff); 129 } 130 131 if (bw_remaining > 0 && (in->isReady() || m_units_remaining[vnet] > 0) && 132 !out->areNSlotsAvailable(1)) { 133 DPRINTF(RubyNetwork, "vnet: %d", vnet); 134 135 // schedule me to wakeup again because I'm waiting for my 136 // output queue to become available 137 schedule_wakeup = true; 138 } 139} 140 141void 142Throttle::wakeup() 143{ 144 // Limits the number of message sent to a limited number of bytes/cycle. 145 assert(getLinkBandwidth() > 0); 146 int bw_remaining = getLinkBandwidth(); 147 148 m_wakeups_wo_switch++; 149 bool schedule_wakeup = false; 150 151 // variable for deciding the direction in which to iterate 152 bool iteration_direction = false; 153 154 155 // invert priorities to avoid starvation seen in the component network 156 if (m_wakeups_wo_switch > PRIORITY_SWITCH_LIMIT) { 157 m_wakeups_wo_switch = 0; 158 iteration_direction = true; 159 } 160 161 if (iteration_direction) { 162 for (int vnet = 0; vnet < m_vnets; ++vnet) { 163 operateVnet(vnet, bw_remaining, schedule_wakeup, 164 m_in[vnet], m_out[vnet]); 165 } 166 } else { 167 for (int vnet = m_vnets-1; vnet >= 0; --vnet) { 168 operateVnet(vnet, bw_remaining, schedule_wakeup, 169 m_in[vnet], m_out[vnet]); 170 } 171 } 172 173 // We should only wake up when we use the bandwidth 174 // This is only mostly true 175 // assert(bw_remaining != getLinkBandwidth()); 176 177 // Record that we used some or all of the link bandwidth this cycle 178 double ratio = 1.0 - (double(bw_remaining) / double(getLinkBandwidth())); 179 180 // If ratio = 0, we used no bandwidth, if ratio = 1, we used all 181 m_link_utilization_proxy += ratio; 182 183 if (bw_remaining > 0 && !schedule_wakeup) { 184 // We have extra bandwidth and our output buffer was 185 // available, so we must not have anything else to do until 186 // another message arrives. 187 DPRINTF(RubyNetwork, "%s not scheduled again\n", *this); 188 } else { 189 DPRINTF(RubyNetwork, "%s scheduled again\n", *this); 190 191 // We are out of bandwidth for this cycle, so wakeup next 192 // cycle and continue 193 scheduleEvent(Cycles(1)); 194 } 195} 196 197void 198Throttle::regStats(string parent) 199{ 200 m_link_utilization 201 .name(parent + csprintf(".throttle%i", m_node) + ".link_utilization"); 202 203 for (MessageSizeType type = MessageSizeType_FIRST; 204 type < MessageSizeType_NUM; ++type) { 205 m_msg_counts[(unsigned int)type] 206 .init(Network::getNumberOfVirtualNetworks()) 207 .name(parent + csprintf(".throttle%i", m_node) + ".msg_count." + 208 MessageSizeType_to_string(type)) 209 .flags(Stats::nozero) 210 ; 211 m_msg_bytes[(unsigned int) type] 212 .name(parent + csprintf(".throttle%i", m_node) + ".msg_bytes." + 213 MessageSizeType_to_string(type)) 214 .flags(Stats::nozero) 215 ; 216 217 m_msg_bytes[(unsigned int) type] = m_msg_counts[type] * Stats::constant( 218 Network::MessageSizeType_to_int(type)); 219 } 220} 221 222void 223Throttle::clearStats() 224{ 225 m_link_utilization_proxy = 0; 226} 227 228void 229Throttle::collateStats() 230{ 231 double time_delta = double(m_ruby_system->curCycle() - 232 m_ruby_system->getStartCycle()); 233 234 m_link_utilization = 100.0 * m_link_utilization_proxy / time_delta; 235} 236 237void 238Throttle::print(ostream& out) const 239{ 240 ccprintf(out, "[%i bw: %i]", m_node, getLinkBandwidth()); 241} 242 243int 244network_message_to_size(Message *net_msg_ptr) 245{ 246 assert(net_msg_ptr != NULL); 247 248 int size = Network::MessageSizeType_to_int(net_msg_ptr->getMessageSize()); 249 size *= MESSAGE_SIZE_MULTIPLIER; 250 251 // Artificially increase the size of broadcast messages 252 if (BROADCAST_SCALING > 1 && net_msg_ptr->getDestination().isBroadcast()) 253 size *= BROADCAST_SCALING; 254 255 return size; 256}
| 102 to_string(m_node) + "]"; 103 } 104} 105 106void 107Throttle::operateVnet(int vnet, int &bw_remaining, bool &schedule_wakeup, 108 MessageBuffer *in, MessageBuffer *out) 109{ 110 if (out == nullptr || in == nullptr) { 111 return; 112 } 113 assert(m_units_remaining[vnet] >= 0); 114 115 while (bw_remaining > 0 && (in->isReady() || m_units_remaining[vnet] > 0) && 116 out->areNSlotsAvailable(1)) { 117 118 // See if we are done transferring the previous message on 119 // this virtual network 120 if (m_units_remaining[vnet] == 0 && in->isReady()) { 121 // Find the size of the message we are moving 122 MsgPtr msg_ptr = in->peekMsgPtr(); 123 Message *net_msg_ptr = msg_ptr.get(); 124 m_units_remaining[vnet] += 125 network_message_to_size(net_msg_ptr); 126 127 DPRINTF(RubyNetwork, "throttle: %d my bw %d bw spent " 128 "enqueueing net msg %d time: %lld.\n", 129 m_node, getLinkBandwidth(), m_units_remaining[vnet], 130 m_ruby_system->curCycle()); 131 132 // Move the message 133 in->dequeue(); 134 out->enqueue(msg_ptr, m_link_latency); 135 136 // Count the message 137 m_msg_counts[net_msg_ptr->getMessageSize()][vnet]++; 138 DPRINTF(RubyNetwork, "%s\n", *out); 139 } 140 141 // Calculate the amount of bandwidth we spent on this message 142 int diff = m_units_remaining[vnet] - bw_remaining; 143 m_units_remaining[vnet] = max(0, diff); 144 bw_remaining = max(0, -diff); 145 } 146 147 if (bw_remaining > 0 && (in->isReady() || m_units_remaining[vnet] > 0) && 148 !out->areNSlotsAvailable(1)) { 149 DPRINTF(RubyNetwork, "vnet: %d", vnet); 150 151 // schedule me to wakeup again because I'm waiting for my 152 // output queue to become available 153 schedule_wakeup = true; 154 } 155} 156 157void 158Throttle::wakeup() 159{ 160 // Limits the number of message sent to a limited number of bytes/cycle. 161 assert(getLinkBandwidth() > 0); 162 int bw_remaining = getLinkBandwidth(); 163 164 m_wakeups_wo_switch++; 165 bool schedule_wakeup = false; 166 167 // variable for deciding the direction in which to iterate 168 bool iteration_direction = false; 169 170 171 // invert priorities to avoid starvation seen in the component network 172 if (m_wakeups_wo_switch > PRIORITY_SWITCH_LIMIT) { 173 m_wakeups_wo_switch = 0; 174 iteration_direction = true; 175 } 176 177 if (iteration_direction) { 178 for (int vnet = 0; vnet < m_vnets; ++vnet) { 179 operateVnet(vnet, bw_remaining, schedule_wakeup, 180 m_in[vnet], m_out[vnet]); 181 } 182 } else { 183 for (int vnet = m_vnets-1; vnet >= 0; --vnet) { 184 operateVnet(vnet, bw_remaining, schedule_wakeup, 185 m_in[vnet], m_out[vnet]); 186 } 187 } 188 189 // We should only wake up when we use the bandwidth 190 // This is only mostly true 191 // assert(bw_remaining != getLinkBandwidth()); 192 193 // Record that we used some or all of the link bandwidth this cycle 194 double ratio = 1.0 - (double(bw_remaining) / double(getLinkBandwidth())); 195 196 // If ratio = 0, we used no bandwidth, if ratio = 1, we used all 197 m_link_utilization_proxy += ratio; 198 199 if (bw_remaining > 0 && !schedule_wakeup) { 200 // We have extra bandwidth and our output buffer was 201 // available, so we must not have anything else to do until 202 // another message arrives. 203 DPRINTF(RubyNetwork, "%s not scheduled again\n", *this); 204 } else { 205 DPRINTF(RubyNetwork, "%s scheduled again\n", *this); 206 207 // We are out of bandwidth for this cycle, so wakeup next 208 // cycle and continue 209 scheduleEvent(Cycles(1)); 210 } 211} 212 213void 214Throttle::regStats(string parent) 215{ 216 m_link_utilization 217 .name(parent + csprintf(".throttle%i", m_node) + ".link_utilization"); 218 219 for (MessageSizeType type = MessageSizeType_FIRST; 220 type < MessageSizeType_NUM; ++type) { 221 m_msg_counts[(unsigned int)type] 222 .init(Network::getNumberOfVirtualNetworks()) 223 .name(parent + csprintf(".throttle%i", m_node) + ".msg_count." + 224 MessageSizeType_to_string(type)) 225 .flags(Stats::nozero) 226 ; 227 m_msg_bytes[(unsigned int) type] 228 .name(parent + csprintf(".throttle%i", m_node) + ".msg_bytes." + 229 MessageSizeType_to_string(type)) 230 .flags(Stats::nozero) 231 ; 232 233 m_msg_bytes[(unsigned int) type] = m_msg_counts[type] * Stats::constant( 234 Network::MessageSizeType_to_int(type)); 235 } 236} 237 238void 239Throttle::clearStats() 240{ 241 m_link_utilization_proxy = 0; 242} 243 244void 245Throttle::collateStats() 246{ 247 double time_delta = double(m_ruby_system->curCycle() - 248 m_ruby_system->getStartCycle()); 249 250 m_link_utilization = 100.0 * m_link_utilization_proxy / time_delta; 251} 252 253void 254Throttle::print(ostream& out) const 255{ 256 ccprintf(out, "[%i bw: %i]", m_node, getLinkBandwidth()); 257} 258 259int 260network_message_to_size(Message *net_msg_ptr) 261{ 262 assert(net_msg_ptr != NULL); 263 264 int size = Network::MessageSizeType_to_int(net_msg_ptr->getMessageSize()); 265 size *= MESSAGE_SIZE_MULTIPLIER; 266 267 // Artificially increase the size of broadcast messages 268 if (BROADCAST_SCALING > 1 && net_msg_ptr->getDestination().isBroadcast()) 269 size *= BROADCAST_SCALING; 270 271 return size; 272}
|