Throttle.cc (10301:44839e8febbd) Throttle.cc (10311:ad9c042dce54)
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;

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

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;
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;

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

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;
72 m_vnets = 0;
73
74 assert(link_bandwidth_multiplier > 0);
75 m_link_bandwidth_multiplier = link_bandwidth_multiplier;
72 assert(link_bandwidth_multiplier > 0);
73 m_link_bandwidth_multiplier = link_bandwidth_multiplier;
74
76 m_link_latency = link_latency;
77 m_endpoint_bandwidth = endpoint_bandwidth;
78
79 m_wakeups_wo_switch = 0;
75 m_link_latency = link_latency;
76 m_endpoint_bandwidth = endpoint_bandwidth;
77
78 m_wakeups_wo_switch = 0;
80
81 m_link_utilization_proxy = 0;
82}
83
84void
79 m_link_utilization_proxy = 0;
80}
81
82void
85Throttle::addLinks(const std::vector<MessageBuffer*>& in_vec,
86 const std::vector<MessageBuffer*>& out_vec)
83Throttle::addLinks(const map<int, MessageBuffer*>& in_vec,
84 const map<int, MessageBuffer*>& out_vec)
87{
88 assert(in_vec.size() == out_vec.size());
85{
86 assert(in_vec.size() == out_vec.size());
89 for (int i=0; i<in_vec.size(); i++) {
90 addVirtualNetwork(in_vec[i], out_vec[i]);
87
88 for (auto& it : in_vec) {
89 int vnet = it.first;
90
91 auto jt = out_vec.find(vnet);
92 assert(jt != out_vec.end());
93
94 MessageBuffer *in_ptr = it.second;
95 MessageBuffer *out_ptr = (*jt).second;
96
97 m_in[vnet] = in_ptr;
98 m_out[vnet] = out_ptr;
99 m_units_remaining[vnet] = 0;
100
101 // Set consumer and description
102 in_ptr->setConsumer(this);
103 string desc = "[Queue to Throttle " + to_string(m_sID) + " " +
104 to_string(m_node) + "]";
105 in_ptr->setDescription(desc);
91 }
92}
93
94void
106 }
107}
108
109void
95Throttle::addVirtualNetwork(MessageBuffer* in_ptr, MessageBuffer* out_ptr)
110Throttle::operateVnet(int vnet, int &bw_remaining, bool &schedule_wakeup,
111 MessageBuffer *in, MessageBuffer *out)
96{
112{
97 m_units_remaining.push_back(0);
98 m_in.push_back(in_ptr);
99 m_out.push_back(out_ptr);
113 assert(out != NULL);
114 assert(in != NULL);
115 assert(m_units_remaining[vnet] >= 0);
100
116
101 // Set consumer and description
102 m_in[m_vnets]->setConsumer(this);
117 while (bw_remaining > 0 && (in->isReady() || m_units_remaining[vnet] > 0) &&
118 out->areNSlotsAvailable(1)) {
103
119
104 string desc = "[Queue to Throttle " + to_string(m_sID) + " " +
105 to_string(m_node) + "]";
106 m_in[m_vnets]->setDescription(desc);
107 m_vnets++;
120 // See if we are done transferring the previous message on
121 // this virtual network
122 if (m_units_remaining[vnet] == 0 && in->isReady()) {
123 // Find the size of the message we are moving
124 MsgPtr msg_ptr = in->peekMsgPtr();
125 NetworkMessage* net_msg_ptr =
126 safe_cast<NetworkMessage*>(msg_ptr.get());
127 m_units_remaining[vnet] +=
128 network_message_to_size(net_msg_ptr);
129
130 DPRINTF(RubyNetwork, "throttle: %d my bw %d bw spent "
131 "enqueueing net msg %d time: %lld.\n",
132 m_node, getLinkBandwidth(), m_units_remaining[vnet],
133 g_system_ptr->curCycle());
134
135 // Move the message
136 in->dequeue();
137 out->enqueue(msg_ptr, m_link_latency);
138
139 // Count the message
140 m_msg_counts[net_msg_ptr->getMessageSize()][vnet]++;
141 DPRINTF(RubyNetwork, "%s\n", *out);
142 }
143
144 // Calculate the amount of bandwidth we spent on this message
145 int diff = m_units_remaining[vnet] - bw_remaining;
146 m_units_remaining[vnet] = max(0, diff);
147 bw_remaining = max(0, -diff);
148 }
149
150 if (bw_remaining > 0 && (in->isReady() || m_units_remaining[vnet] > 0) &&
151 !out->areNSlotsAvailable(1)) {
152 DPRINTF(RubyNetwork, "vnet: %d", vnet);
153
154 // schedule me to wakeup again because I'm waiting for my
155 // output queue to become available
156 schedule_wakeup = true;
157 }
108}
109
110void
111Throttle::wakeup()
112{
113 // Limits the number of message sent to a limited number of bytes/cycle.
114 assert(getLinkBandwidth() > 0);
115 int bw_remaining = getLinkBandwidth();
116
158}
159
160void
161Throttle::wakeup()
162{
163 // Limits the number of message sent to a limited number of bytes/cycle.
164 assert(getLinkBandwidth() > 0);
165 int bw_remaining = getLinkBandwidth();
166
117 // Give the highest numbered link priority most of the time
118 m_wakeups_wo_switch++;
167 m_wakeups_wo_switch++;
119 int highest_prio_vnet = m_vnets-1;
120 int lowest_prio_vnet = 0;
121 int counter = 1;
122 bool schedule_wakeup = false;
123
168 bool schedule_wakeup = false;
169
170 // variable for deciding the direction in which to iterate
171 bool iteration_direction = false;
172
173
124 // invert priorities to avoid starvation seen in the component network
125 if (m_wakeups_wo_switch > PRIORITY_SWITCH_LIMIT) {
126 m_wakeups_wo_switch = 0;
174 // invert priorities to avoid starvation seen in the component network
175 if (m_wakeups_wo_switch > PRIORITY_SWITCH_LIMIT) {
176 m_wakeups_wo_switch = 0;
127 highest_prio_vnet = 0;
128 lowest_prio_vnet = m_vnets-1;
129 counter = -1;
177 iteration_direction = true;
130 }
131
178 }
179
132 for (int vnet = highest_prio_vnet;
133 (vnet * counter) >= (counter * lowest_prio_vnet);
134 vnet -= counter) {
135
136 assert(m_out[vnet] != NULL);
137 assert(m_in[vnet] != NULL);
138 assert(m_units_remaining[vnet] >= 0);
139
140 while (bw_remaining > 0 &&
141 (m_in[vnet]->isReady() || m_units_remaining[vnet] > 0) &&
142 m_out[vnet]->areNSlotsAvailable(1)) {
143
144 // See if we are done transferring the previous message on
145 // this virtual network
146 if (m_units_remaining[vnet] == 0 && m_in[vnet]->isReady()) {
147 // Find the size of the message we are moving
148 MsgPtr msg_ptr = m_in[vnet]->peekMsgPtr();
149 NetworkMessage* net_msg_ptr =
150 safe_cast<NetworkMessage*>(msg_ptr.get());
151 m_units_remaining[vnet] +=
152 network_message_to_size(net_msg_ptr);
153
154 DPRINTF(RubyNetwork, "throttle: %d my bw %d bw spent "
155 "enqueueing net msg %d time: %lld.\n",
156 m_node, getLinkBandwidth(), m_units_remaining[vnet],
157 g_system_ptr->curCycle());
158
159 // Move the message
160 m_in[vnet]->dequeue();
161 m_out[vnet]->enqueue(msg_ptr, m_link_latency);
162
163 // Count the message
164 m_msg_counts[net_msg_ptr->getMessageSize()][vnet]++;
165
166 DPRINTF(RubyNetwork, "%s\n", *m_out[vnet]);
167 }
168
169 // Calculate the amount of bandwidth we spent on this message
170 int diff = m_units_remaining[vnet] - bw_remaining;
171 m_units_remaining[vnet] = max(0, diff);
172 bw_remaining = max(0, -diff);
180 if (iteration_direction) {
181 for (auto& it : m_in) {
182 int vnet = it.first;
183 operateVnet(vnet, bw_remaining, schedule_wakeup,
184 it.second, m_out[vnet]);
173 }
185 }
174
175 if (bw_remaining > 0 &&
176 (m_in[vnet]->isReady() || m_units_remaining[vnet] > 0) &&
177 !m_out[vnet]->areNSlotsAvailable(1)) {
178 DPRINTF(RubyNetwork, "vnet: %d", vnet);
179 // schedule me to wakeup again because I'm waiting for my
180 // output queue to become available
181 schedule_wakeup = true;
186 } else {
187 for (auto it = m_in.rbegin(); it != m_in.rend(); ++it) {
188 int vnet = (*it).first;
189 operateVnet(vnet, bw_remaining, schedule_wakeup,
190 (*it).second, m_out[vnet]);
182 }
183 }
184
185 // We should only wake up when we use the bandwidth
186 // This is only mostly true
187 // assert(bw_remaining != getLinkBandwidth());
188
189 // Record that we used some or all of the link bandwidth this cycle

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

210Throttle::regStats(string parent)
211{
212 m_link_utilization
213 .name(parent + csprintf(".throttle%i", m_node) + ".link_utilization");
214
215 for (MessageSizeType type = MessageSizeType_FIRST;
216 type < MessageSizeType_NUM; ++type) {
217 m_msg_counts[(unsigned int)type]
191 }
192 }
193
194 // We should only wake up when we use the bandwidth
195 // This is only mostly true
196 // assert(bw_remaining != getLinkBandwidth());
197
198 // Record that we used some or all of the link bandwidth this cycle

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

219Throttle::regStats(string parent)
220{
221 m_link_utilization
222 .name(parent + csprintf(".throttle%i", m_node) + ".link_utilization");
223
224 for (MessageSizeType type = MessageSizeType_FIRST;
225 type < MessageSizeType_NUM; ++type) {
226 m_msg_counts[(unsigned int)type]
218 .init(m_vnets)
227 .init(Network::getNumberOfVirtualNetworks())
219 .name(parent + csprintf(".throttle%i", m_node) + ".msg_count." +
220 MessageSizeType_to_string(type))
221 .flags(Stats::nozero)
222 ;
223 m_msg_bytes[(unsigned int) type]
224 .name(parent + csprintf(".throttle%i", m_node) + ".msg_bytes." +
225 MessageSizeType_to_string(type))
226 .flags(Stats::nozero)

--- 40 unchanged lines hidden ---
228 .name(parent + csprintf(".throttle%i", m_node) + ".msg_count." +
229 MessageSizeType_to_string(type))
230 .flags(Stats::nozero)
231 ;
232 m_msg_bytes[(unsigned int) type]
233 .name(parent + csprintf(".throttle%i", m_node) + ".msg_bytes." +
234 MessageSizeType_to_string(type))
235 .flags(Stats::nozero)

--- 40 unchanged lines hidden ---