Deleted Added
sdiff udiff text old ( 10837:ecbab2522757 ) new ( 10893:f567e80c0714 )
full compact
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;

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

117}
118
119const Message*
120MessageBuffer::peek() const
121{
122 DPRINTF(RubyQueue, "Peeking at head of queue.\n");
123 assert(isReady());
124
125 const Message* msg_ptr = m_prio_heap.front().m_msgptr.get();
126 assert(msg_ptr);
127
128 DPRINTF(RubyQueue, "Message: %s\n", (*msg_ptr));
129 return msg_ptr;
130}
131
132// FIXME - move me somewhere else
133Cycles

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

199 Message* msg_ptr = message.get();
200 assert(msg_ptr != NULL);
201
202 assert(m_sender->clockEdge() >= msg_ptr->getLastEnqueueTime() &&
203 "ensure we aren't dequeued early");
204
205 msg_ptr->updateDelayedTicks(m_sender->clockEdge());
206 msg_ptr->setLastEnqueueTime(arrival_time);
207
208 // Insert the message into the priority heap
209 MessageBufferNode thisNode(arrival_time, m_msg_counter, message);
210 m_prio_heap.push_back(thisNode);
211 push_heap(m_prio_heap.begin(), m_prio_heap.end(),
212 greater<MessageBufferNode>());
213
214 DPRINTF(RubyQueue, "Enqueue arrival_time: %lld, Message: %s\n",
215 arrival_time, *(message.get()));
216
217 // Schedule the wakeup
218 assert(m_consumer != NULL);
219 m_consumer->scheduleEventAbsolute(arrival_time);
220 m_consumer->storeEventInfo(m_vnet_id);
221}
222
223Cycles
224MessageBuffer::dequeue()
225{
226 DPRINTF(RubyQueue, "Popping\n");
227 assert(isReady());
228
229 // get MsgPtr of the message about to be dequeued
230 MsgPtr message = m_prio_heap.front().m_msgptr;
231
232 // get the delay cycles
233 message->updateDelayedTicks(m_receiver->clockEdge());
234 Cycles delayCycles =
235 m_receiver->ticksToCycles(message->getDelayedTicks());
236
237 // record previous size and time so the current buffer size isn't
238 // adjusted until next cycle
239 if (m_time_last_time_pop < m_receiver->clockEdge()) {
240 m_size_at_cycle_start = m_prio_heap.size();
241 m_time_last_time_pop = m_receiver->clockEdge();
242 }
243
244 pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
245 greater<MessageBufferNode>());
246 m_prio_heap.pop_back();
247
248 return delayCycles;
249}
250
251void
252MessageBuffer::clear()
253{

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

260 m_msgs_this_cycle = 0;
261}
262
263void
264MessageBuffer::recycle()
265{
266 DPRINTF(RubyQueue, "Recycling.\n");
267 assert(isReady());
268 MessageBufferNode node = m_prio_heap.front();
269 pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
270 greater<MessageBufferNode>());
271
272 node.m_time = m_receiver->clockEdge(m_recycle_latency);
273 m_prio_heap.back() = node;
274 push_heap(m_prio_heap.begin(), m_prio_heap.end(),
275 greater<MessageBufferNode>());
276 m_consumer->
277 scheduleEventAbsolute(m_receiver->clockEdge(m_recycle_latency));
278}
279
280void
281MessageBuffer::reanalyzeList(list<MsgPtr> &lt, Tick nextTick)
282{
283 while(!lt.empty()) {
284 m_msg_counter++;
285 MessageBufferNode msgNode(nextTick, m_msg_counter, lt.front());
286
287 m_prio_heap.push_back(msgNode);
288 push_heap(m_prio_heap.begin(), m_prio_heap.end(),
289 greater<MessageBufferNode>());
290
291 m_consumer->scheduleEventAbsolute(nextTick);
292 lt.pop_front();
293 }
294}
295
296void
297MessageBuffer::reanalyzeMessages(const Address& addr)

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

326}
327
328void
329MessageBuffer::stallMessage(const Address& addr)
330{
331 DPRINTF(RubyQueue, "Stalling due to %s\n", addr);
332 assert(isReady());
333 assert(addr.getOffset() == 0);
334 MsgPtr message = m_prio_heap.front().m_msgptr;
335
336 dequeue();
337
338 //
339 // Note: no event is scheduled to analyze the map at a later time.
340 // Instead the controller is responsible to call reanalyzeMessages when
341 // these addresses change state.
342 //
343 (m_stall_msg_map[addr]).push_back(message);
344}
345
346void
347MessageBuffer::print(ostream& out) const
348{
349 ccprintf(out, "[MessageBuffer: ");
350 if (m_consumer != NULL) {
351 ccprintf(out, " consumer-yes ");
352 }
353
354 vector<MessageBufferNode> copy(m_prio_heap);
355 sort_heap(copy.begin(), copy.end(), greater<MessageBufferNode>());
356 ccprintf(out, "%s] %s", copy, m_name);
357}
358
359bool
360MessageBuffer::isReady() const
361{
362 return ((m_prio_heap.size() > 0) &&
363 (m_prio_heap.front().m_time <= m_receiver->clockEdge()));
364}
365
366bool
367MessageBuffer::functionalRead(Packet *pkt)
368{
369 // Check the priority heap and read any messages that may
370 // correspond to the address in the packet.
371 for (unsigned int i = 0; i < m_prio_heap.size(); ++i) {
372 Message *msg = m_prio_heap[i].m_msgptr.get();
373 if (msg->functionalRead(pkt)) return true;
374 }
375
376 // Read the messages in the stall queue that correspond
377 // to the address in the packet.
378 for (StallMsgMapType::iterator map_iter = m_stall_msg_map.begin();
379 map_iter != m_stall_msg_map.end();
380 ++map_iter) {

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

392uint32_t
393MessageBuffer::functionalWrite(Packet *pkt)
394{
395 uint32_t num_functional_writes = 0;
396
397 // Check the priority heap and write any messages that may
398 // correspond to the address in the packet.
399 for (unsigned int i = 0; i < m_prio_heap.size(); ++i) {
400 Message *msg = m_prio_heap[i].m_msgptr.get();
401 if (msg->functionalWrite(pkt)) {
402 num_functional_writes++;
403 }
404 }
405
406 // Check the stall queue and write any messages that may
407 // correspond to the address in the packet.
408 for (StallMsgMapType::iterator map_iter = m_stall_msg_map.begin();

--- 15 unchanged lines hidden ---