2009-05-11 19:38:43 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2011-01-10 20:11:20 +01:00
|
|
|
#include <cassert>
|
|
|
|
|
2010-04-02 20:20:32 +02:00
|
|
|
#include "base/cprintf.hh"
|
2010-12-23 06:15:24 +01:00
|
|
|
#include "base/misc.hh"
|
2010-06-11 08:17:07 +02:00
|
|
|
#include "base/stl_helpers.hh"
|
2011-04-15 19:44:32 +02:00
|
|
|
#include "debug/RubyQueue.hh"
|
2009-05-11 19:38:45 +02:00
|
|
|
#include "mem/ruby/buffers/MessageBuffer.hh"
|
2009-07-07 00:49:47 +02:00
|
|
|
#include "mem/ruby/system/System.hh"
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-04-02 20:20:32 +02:00
|
|
|
using namespace std;
|
2010-06-11 08:17:07 +02:00
|
|
|
using m5::stl_helpers::operator<<;
|
2010-04-02 20:20:32 +02:00
|
|
|
|
2009-11-19 01:34:32 +01:00
|
|
|
MessageBuffer::MessageBuffer(const string &name)
|
2013-02-11 04:26:26 +01:00
|
|
|
: m_time_last_time_size_checked(0), m_time_last_time_enqueue(0),
|
|
|
|
m_time_last_time_pop(0), m_last_arrival_time(0)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
m_msg_counter = 0;
|
|
|
|
m_consumer_ptr = NULL;
|
2013-01-14 17:04:21 +01:00
|
|
|
m_clockobj_ptr = NULL;
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
m_ordering_set = false;
|
|
|
|
m_strict_fifo = true;
|
|
|
|
m_size = 0;
|
|
|
|
m_max_size = -1;
|
|
|
|
m_randomization = true;
|
|
|
|
m_size_last_time_size_checked = 0;
|
|
|
|
m_size_at_cycle_start = 0;
|
|
|
|
m_msgs_this_cycle = 0;
|
|
|
|
m_not_avail_count = 0;
|
|
|
|
m_priority_rank = 0;
|
|
|
|
m_name = name;
|
2011-02-07 07:14:19 +01:00
|
|
|
|
|
|
|
m_stall_msg_map.clear();
|
2011-02-14 23:14:54 +01:00
|
|
|
m_input_link_id = 0;
|
|
|
|
m_vnet_id = 0;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
int
|
|
|
|
MessageBuffer::getSize()
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2013-01-14 17:04:21 +01:00
|
|
|
if (m_time_last_time_size_checked == m_clockobj_ptr->curCycle()) {
|
2010-03-23 02:43:53 +01:00
|
|
|
return m_size_last_time_size_checked;
|
|
|
|
} else {
|
2013-01-14 17:04:21 +01:00
|
|
|
m_time_last_time_size_checked = m_clockobj_ptr->curCycle();
|
2010-03-23 02:43:53 +01:00
|
|
|
m_size_last_time_size_checked = m_size;
|
|
|
|
return m_size;
|
|
|
|
}
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
bool
|
|
|
|
MessageBuffer::areNSlotsAvailable(int n)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
// fast path when message buffers have infinite size
|
|
|
|
if (m_max_size == -1) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine my correct size for the current cycle
|
|
|
|
// pop operations shouldn't effect the network's visible size
|
|
|
|
// until next cycle, but enqueue operations effect the visible
|
|
|
|
// size immediately
|
|
|
|
int current_size = max(m_size_at_cycle_start, m_size);
|
2013-01-14 17:04:21 +01:00
|
|
|
if (m_time_last_time_pop < m_clockobj_ptr->curCycle()) {
|
2010-03-23 02:43:53 +01:00
|
|
|
// no pops this cycle - m_size is correct
|
|
|
|
current_size = m_size;
|
|
|
|
} else {
|
2013-01-14 17:04:21 +01:00
|
|
|
if (m_time_last_time_enqueue < m_clockobj_ptr->curCycle()) {
|
2010-03-23 02:43:53 +01:00
|
|
|
// no enqueues this cycle - m_size_at_cycle_start is correct
|
|
|
|
current_size = m_size_at_cycle_start;
|
|
|
|
} else {
|
|
|
|
// both pops and enqueues occured this cycle - add new
|
|
|
|
// enqueued msgs to m_size_at_cycle_start
|
|
|
|
current_size = m_size_at_cycle_start+m_msgs_this_cycle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now compare the new size with our max size
|
|
|
|
if (current_size + n <= m_max_size) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2010-12-01 20:30:04 +01:00
|
|
|
DPRINTF(RubyQueue, "n: %d, current_size: %d, m_size: %d, "
|
|
|
|
"m_max_size: %d\n",
|
|
|
|
n, current_size, m_size, m_max_size);
|
2010-03-23 02:43:53 +01:00
|
|
|
m_not_avail_count++;
|
|
|
|
return false;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
const MsgPtr
|
|
|
|
MessageBuffer::getMsgPtrCopy() const
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
assert(isReady());
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-06-11 08:17:07 +02:00
|
|
|
return m_prio_heap.front().m_msgptr->clone();
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
const Message*
|
|
|
|
MessageBuffer::peekAtHeadOfQueue() const
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2011-05-02 06:16:14 +02:00
|
|
|
DPRINTF(RubyQueue, "Peeking at head of queue.\n");
|
2010-03-23 02:43:53 +01:00
|
|
|
assert(isReady());
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-06-11 08:17:07 +02:00
|
|
|
const Message* msg_ptr = m_prio_heap.front().m_msgptr.get();
|
2010-06-11 08:17:06 +02:00
|
|
|
assert(msg_ptr);
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-12-01 20:30:04 +01:00
|
|
|
DPRINTF(RubyQueue, "Message: %s\n", (*msg_ptr));
|
2010-03-23 02:43:53 +01:00
|
|
|
return msg_ptr;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME - move me somewhere else
|
2013-02-11 04:26:24 +01:00
|
|
|
Cycles
|
2010-03-23 02:43:53 +01:00
|
|
|
random_time()
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2013-02-11 04:26:24 +01:00
|
|
|
Cycles time(1);
|
|
|
|
time += Cycles(random() & 0x3); // [0...3]
|
2010-03-23 02:43:53 +01:00
|
|
|
if ((random() & 0x7) == 0) { // 1 in 8 chance
|
2013-02-11 04:26:24 +01:00
|
|
|
time += Cycles(100 + (random() % 0xf)); // 100 + [1...15]
|
2010-03-23 02:43:53 +01:00
|
|
|
}
|
|
|
|
return time;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
2013-02-11 04:26:24 +01:00
|
|
|
MessageBuffer::enqueue(MsgPtr message, Cycles delta)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
m_msg_counter++;
|
|
|
|
m_size++;
|
|
|
|
|
|
|
|
// record current time incase we have a pop that also adjusts my size
|
2013-01-14 17:04:21 +01:00
|
|
|
if (m_time_last_time_enqueue < m_clockobj_ptr->curCycle()) {
|
2010-03-23 02:43:53 +01:00
|
|
|
m_msgs_this_cycle = 0; // first msg this cycle
|
2013-01-14 17:04:21 +01:00
|
|
|
m_time_last_time_enqueue = m_clockobj_ptr->curCycle();
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
2010-03-23 02:43:53 +01:00
|
|
|
m_msgs_this_cycle++;
|
|
|
|
|
|
|
|
if (!m_ordering_set) {
|
2010-12-23 06:15:24 +01:00
|
|
|
panic("Ordering property of %s has not been set", m_name);
|
2010-03-23 02:43:53 +01:00
|
|
|
}
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
// Calculate the arrival time of the message, that is, the first
|
|
|
|
// cycle the message can be dequeued.
|
|
|
|
assert(delta>0);
|
2013-02-11 04:26:24 +01:00
|
|
|
Cycles current_time(m_clockobj_ptr->curCycle());
|
|
|
|
Cycles arrival_time(0);
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
if (!RubySystem::getRandomization() || (m_randomization == false)) {
|
|
|
|
// No randomization
|
|
|
|
arrival_time = current_time + delta;
|
|
|
|
} else {
|
|
|
|
// Randomization - ignore delta
|
|
|
|
if (m_strict_fifo) {
|
|
|
|
if (m_last_arrival_time < current_time) {
|
|
|
|
m_last_arrival_time = current_time;
|
|
|
|
}
|
|
|
|
arrival_time = m_last_arrival_time + random_time();
|
|
|
|
} else {
|
|
|
|
arrival_time = current_time + random_time();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the arrival time
|
|
|
|
assert(arrival_time > current_time);
|
|
|
|
if (m_strict_fifo) {
|
|
|
|
if (arrival_time < m_last_arrival_time) {
|
2010-12-23 06:15:24 +01:00
|
|
|
panic("FIFO ordering violated: %s name: %s current time: %d "
|
|
|
|
"delta: %d arrival_time: %d last arrival_time: %d\n",
|
2013-01-14 17:04:21 +01:00
|
|
|
*this, m_name, current_time * m_clockobj_ptr->clockPeriod(),
|
|
|
|
delta * m_clockobj_ptr->clockPeriod(),
|
|
|
|
arrival_time * m_clockobj_ptr->clockPeriod(),
|
|
|
|
m_last_arrival_time * m_clockobj_ptr->clockPeriod());
|
2010-03-23 02:43:53 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
// If running a cache trace, don't worry about the last arrival checks
|
|
|
|
if (!g_system_ptr->m_warmup_enabled) {
|
|
|
|
m_last_arrival_time = arrival_time;
|
|
|
|
}
|
2010-03-23 02:43:53 +01:00
|
|
|
|
|
|
|
// compute the delay cycles and set enqueue time
|
2010-06-11 08:17:06 +02:00
|
|
|
Message* msg_ptr = message.get();
|
2010-03-23 02:43:53 +01:00
|
|
|
assert(msg_ptr != NULL);
|
|
|
|
|
2013-01-14 17:04:21 +01:00
|
|
|
assert(m_clockobj_ptr->curCycle() >= msg_ptr->getLastEnqueueTime() &&
|
2010-03-23 02:43:53 +01:00
|
|
|
"ensure we aren't dequeued early");
|
|
|
|
|
2013-01-14 17:04:21 +01:00
|
|
|
msg_ptr->setDelayedCycles(m_clockobj_ptr->curCycle() -
|
2010-03-23 02:43:53 +01:00
|
|
|
msg_ptr->getLastEnqueueTime() +
|
|
|
|
msg_ptr->getDelayedCycles());
|
|
|
|
msg_ptr->setLastEnqueueTime(arrival_time);
|
|
|
|
|
|
|
|
// Insert the message into the priority heap
|
|
|
|
MessageBufferNode thisNode(arrival_time, m_msg_counter, message);
|
2010-06-11 08:17:07 +02:00
|
|
|
m_prio_heap.push_back(thisNode);
|
|
|
|
push_heap(m_prio_heap.begin(), m_prio_heap.end(),
|
|
|
|
greater<MessageBufferNode>());
|
2010-03-23 02:43:53 +01:00
|
|
|
|
2013-01-14 17:04:21 +01:00
|
|
|
DPRINTF(RubyQueue, "Enqueue arrival_time: %lld, Message: %s\n",
|
|
|
|
arrival_time * m_clockobj_ptr->clockPeriod(), *(message.get()));
|
2010-03-23 02:43:53 +01:00
|
|
|
|
|
|
|
// Schedule the wakeup
|
|
|
|
if (m_consumer_ptr != NULL) {
|
2012-08-27 08:00:55 +02:00
|
|
|
m_consumer_ptr->scheduleEventAbsolute(arrival_time);
|
2011-02-14 23:14:54 +01:00
|
|
|
m_consumer_ptr->storeEventInfo(m_vnet_id);
|
2009-05-11 19:38:43 +02:00
|
|
|
} else {
|
2010-12-23 06:15:24 +01:00
|
|
|
panic("No consumer: %s name: %s\n", *this, m_name);
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-11 04:26:26 +01:00
|
|
|
Cycles
|
2010-03-23 02:43:53 +01:00
|
|
|
MessageBuffer::dequeue_getDelayCycles(MsgPtr& message)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
dequeue(message);
|
2013-01-14 17:04:21 +01:00
|
|
|
return setAndReturnDelayCycles(message);
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
MessageBuffer::dequeue(MsgPtr& message)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2011-02-23 06:58:40 +01:00
|
|
|
DPRINTF(RubyQueue, "Dequeueing\n");
|
2010-06-11 08:17:07 +02:00
|
|
|
message = m_prio_heap.front().m_msgptr;
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
pop();
|
2010-12-01 20:30:04 +01:00
|
|
|
DPRINTF(RubyQueue, "Enqueue message is %s\n", (*(message.get())));
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2013-02-11 04:26:26 +01:00
|
|
|
Cycles
|
2010-03-23 02:43:53 +01:00
|
|
|
MessageBuffer::dequeue_getDelayCycles()
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
// get MsgPtr of the message about to be dequeued
|
2010-06-11 08:17:07 +02:00
|
|
|
MsgPtr message = m_prio_heap.front().m_msgptr;
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
// get the delay cycles
|
2013-02-11 04:26:26 +01:00
|
|
|
Cycles delayCycles = setAndReturnDelayCycles(message);
|
2010-03-23 02:43:53 +01:00
|
|
|
dequeue();
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2013-01-14 17:04:21 +01:00
|
|
|
return delayCycles;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
MessageBuffer::pop()
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2011-02-23 06:58:40 +01:00
|
|
|
DPRINTF(RubyQueue, "Popping\n");
|
2010-03-23 02:43:53 +01:00
|
|
|
assert(isReady());
|
2010-06-11 08:17:07 +02:00
|
|
|
pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
|
|
|
|
greater<MessageBufferNode>());
|
|
|
|
m_prio_heap.pop_back();
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
// record previous size and time so the current buffer size isn't
|
|
|
|
// adjusted until next cycle
|
2013-01-14 17:04:21 +01:00
|
|
|
if (m_time_last_time_pop < m_clockobj_ptr->curCycle()) {
|
2010-03-23 02:43:53 +01:00
|
|
|
m_size_at_cycle_start = m_size;
|
2013-01-14 17:04:21 +01:00
|
|
|
m_time_last_time_pop = m_clockobj_ptr->curCycle();
|
2010-03-23 02:43:53 +01:00
|
|
|
}
|
|
|
|
m_size--;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
MessageBuffer::clear()
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-06-11 08:17:07 +02:00
|
|
|
m_prio_heap.clear();
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
m_msg_counter = 0;
|
|
|
|
m_size = 0;
|
2013-02-11 04:26:26 +01:00
|
|
|
m_time_last_time_enqueue = Cycles(0);
|
|
|
|
m_time_last_time_pop = Cycles(0);
|
2010-03-23 02:43:53 +01:00
|
|
|
m_size_at_cycle_start = 0;
|
|
|
|
m_msgs_this_cycle = 0;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
MessageBuffer::recycle()
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2011-02-23 06:58:40 +01:00
|
|
|
DPRINTF(RubyQueue, "Recycling.\n");
|
2010-03-23 02:43:53 +01:00
|
|
|
assert(isReady());
|
2010-06-11 08:17:07 +02:00
|
|
|
MessageBufferNode node = m_prio_heap.front();
|
|
|
|
pop_heap(m_prio_heap.begin(), m_prio_heap.end(),
|
|
|
|
greater<MessageBufferNode>());
|
2013-02-11 04:26:24 +01:00
|
|
|
|
2013-01-14 17:04:21 +01:00
|
|
|
node.m_time = m_clockobj_ptr->curCycle() + m_recycle_latency;
|
2010-06-11 08:17:07 +02:00
|
|
|
m_prio_heap.back() = node;
|
|
|
|
push_heap(m_prio_heap.begin(), m_prio_heap.end(),
|
|
|
|
greater<MessageBufferNode>());
|
2013-01-14 17:04:21 +01:00
|
|
|
m_consumer_ptr->scheduleEventAbsolute(m_clockobj_ptr->curCycle() +
|
2012-08-27 08:00:55 +02:00
|
|
|
m_recycle_latency);
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-08-20 20:46:14 +02:00
|
|
|
void
|
|
|
|
MessageBuffer::reanalyzeMessages(const Address& addr)
|
|
|
|
{
|
2011-02-23 06:58:40 +01:00
|
|
|
DPRINTF(RubyQueue, "ReanalyzeMessages\n");
|
2010-08-20 20:46:14 +02:00
|
|
|
assert(m_stall_msg_map.count(addr) > 0);
|
2013-02-11 04:26:26 +01:00
|
|
|
Cycles nextCycle = m_clockobj_ptr->curCycle() + Cycles(1);
|
2010-08-20 20:46:14 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Put all stalled messages associated with this address back on the
|
|
|
|
// prio heap
|
|
|
|
//
|
|
|
|
while(!m_stall_msg_map[addr].empty()) {
|
|
|
|
m_msg_counter++;
|
2013-02-11 04:26:24 +01:00
|
|
|
MessageBufferNode msgNode(nextCycle, m_msg_counter,
|
2010-08-20 20:46:14 +02:00
|
|
|
m_stall_msg_map[addr].front());
|
|
|
|
|
|
|
|
m_prio_heap.push_back(msgNode);
|
|
|
|
push_heap(m_prio_heap.begin(), m_prio_heap.end(),
|
2011-02-07 07:14:19 +01:00
|
|
|
greater<MessageBufferNode>());
|
2010-08-20 20:46:14 +02:00
|
|
|
|
2012-08-27 08:00:55 +02:00
|
|
|
m_consumer_ptr->scheduleEventAbsolute(msgNode.m_time);
|
2010-08-20 20:46:14 +02:00
|
|
|
m_stall_msg_map[addr].pop_front();
|
|
|
|
}
|
2011-02-07 07:14:19 +01:00
|
|
|
m_stall_msg_map.erase(addr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MessageBuffer::reanalyzeAllMessages()
|
|
|
|
{
|
2011-02-23 06:58:40 +01:00
|
|
|
DPRINTF(RubyQueue, "ReanalyzeAllMessages %s\n");
|
2013-02-11 04:26:26 +01:00
|
|
|
Cycles nextCycle = m_clockobj_ptr->curCycle() + Cycles(1);
|
2011-02-07 07:14:19 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Put all stalled messages associated with this address back on the
|
|
|
|
// prio heap
|
|
|
|
//
|
|
|
|
for (StallMsgMapType::iterator map_iter = m_stall_msg_map.begin();
|
|
|
|
map_iter != m_stall_msg_map.end();
|
|
|
|
++map_iter) {
|
|
|
|
|
|
|
|
while(!(map_iter->second).empty()) {
|
|
|
|
m_msg_counter++;
|
2013-02-11 04:26:24 +01:00
|
|
|
MessageBufferNode msgNode(nextCycle, m_msg_counter,
|
2011-02-07 07:14:19 +01:00
|
|
|
(map_iter->second).front());
|
|
|
|
|
|
|
|
m_prio_heap.push_back(msgNode);
|
|
|
|
push_heap(m_prio_heap.begin(), m_prio_heap.end(),
|
|
|
|
greater<MessageBufferNode>());
|
2013-02-11 04:26:24 +01:00
|
|
|
|
2012-08-27 08:00:55 +02:00
|
|
|
m_consumer_ptr->scheduleEventAbsolute(msgNode.m_time);
|
2011-02-07 07:14:19 +01:00
|
|
|
(map_iter->second).pop_front();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_stall_msg_map.clear();
|
2010-08-20 20:46:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MessageBuffer::stallMessage(const Address& addr)
|
|
|
|
{
|
2011-03-01 22:26:11 +01:00
|
|
|
DPRINTF(RubyQueue, "Stalling due to %s\n", addr);
|
2010-08-20 20:46:14 +02:00
|
|
|
assert(isReady());
|
|
|
|
assert(addr.getOffset() == 0);
|
|
|
|
MsgPtr message = m_prio_heap.front().m_msgptr;
|
|
|
|
|
|
|
|
pop();
|
|
|
|
|
|
|
|
//
|
|
|
|
// Note: no event is scheduled to analyze the map at a later time.
|
|
|
|
// Instead the controller is responsible to call reanalyzeMessages when
|
|
|
|
// these addresses change state.
|
|
|
|
//
|
|
|
|
(m_stall_msg_map[addr]).push_back(message);
|
|
|
|
}
|
|
|
|
|
2013-02-11 04:26:26 +01:00
|
|
|
Cycles
|
2010-06-11 08:17:06 +02:00
|
|
|
MessageBuffer::setAndReturnDelayCycles(MsgPtr msg_ptr)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
// get the delay cycles of the message at the top of the queue
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
// this function should only be called on dequeue
|
|
|
|
// ensure the msg hasn't been enqueued
|
2013-01-14 17:04:21 +01:00
|
|
|
assert(msg_ptr->getLastEnqueueTime() <= m_clockobj_ptr->curCycle());
|
|
|
|
msg_ptr->setDelayedCycles(m_clockobj_ptr->curCycle() -
|
|
|
|
msg_ptr->getLastEnqueueTime() +
|
|
|
|
msg_ptr->getDelayedCycles());
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2013-01-14 17:04:21 +01:00
|
|
|
return msg_ptr->getDelayedCycles();
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
MessageBuffer::print(ostream& out) const
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2011-02-23 06:58:40 +01:00
|
|
|
ccprintf(out, "[MessageBuffer: ");
|
2010-03-23 02:43:53 +01:00
|
|
|
if (m_consumer_ptr != NULL) {
|
2011-02-23 06:58:40 +01:00
|
|
|
ccprintf(out, " consumer-yes ");
|
2010-03-23 02:43:53 +01:00
|
|
|
}
|
2010-06-11 08:17:07 +02:00
|
|
|
|
|
|
|
vector<MessageBufferNode> copy(m_prio_heap);
|
|
|
|
sort_heap(copy.begin(), copy.end(), greater<MessageBufferNode>());
|
2011-02-23 06:58:40 +01:00
|
|
|
ccprintf(out, "%s] %s", copy, m_name);
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
MessageBuffer::printStats(ostream& out)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
out << "MessageBuffer: " << m_name << " stats - msgs:" << m_msg_counter
|
|
|
|
<< " full:" << m_not_avail_count << endl;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
2012-10-16 00:51:57 +02:00
|
|
|
|
|
|
|
bool
|
|
|
|
MessageBuffer::isReady() const
|
|
|
|
{
|
|
|
|
return ((m_prio_heap.size() > 0) &&
|
2013-01-14 17:04:21 +01:00
|
|
|
(m_prio_heap.front().m_time <= m_clockobj_ptr->curCycle()));
|
2012-10-16 00:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MessageBuffer::functionalRead(Packet *pkt)
|
|
|
|
{
|
|
|
|
// Check the priority heap and read any messages that may
|
|
|
|
// correspond to the address in the packet.
|
|
|
|
for (unsigned int i = 0; i < m_prio_heap.size(); ++i) {
|
|
|
|
Message *msg = m_prio_heap[i].m_msgptr.get();
|
|
|
|
if (msg->functionalRead(pkt)) return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the messages in the stall queue that correspond
|
|
|
|
// to the address in the packet.
|
|
|
|
for (StallMsgMapType::iterator map_iter = m_stall_msg_map.begin();
|
|
|
|
map_iter != m_stall_msg_map.end();
|
|
|
|
++map_iter) {
|
|
|
|
|
|
|
|
for (std::list<MsgPtr>::iterator it = (map_iter->second).begin();
|
|
|
|
it != (map_iter->second).end(); ++it) {
|
|
|
|
|
|
|
|
Message *msg = (*it).get();
|
|
|
|
if (msg->functionalRead(pkt)) return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
MessageBuffer::functionalWrite(Packet *pkt)
|
|
|
|
{
|
|
|
|
uint32_t num_functional_writes = 0;
|
|
|
|
|
|
|
|
// Check the priority heap and write any messages that may
|
|
|
|
// correspond to the address in the packet.
|
|
|
|
for (unsigned int i = 0; i < m_prio_heap.size(); ++i) {
|
|
|
|
Message *msg = m_prio_heap[i].m_msgptr.get();
|
|
|
|
if (msg->functionalWrite(pkt)) {
|
|
|
|
num_functional_writes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the stall queue and write any messages that may
|
|
|
|
// correspond to the address in the packet.
|
|
|
|
for (StallMsgMapType::iterator map_iter = m_stall_msg_map.begin();
|
|
|
|
map_iter != m_stall_msg_map.end();
|
|
|
|
++map_iter) {
|
|
|
|
|
|
|
|
for (std::list<MsgPtr>::iterator it = (map_iter->second).begin();
|
|
|
|
it != (map_iter->second).end(); ++it) {
|
|
|
|
|
|
|
|
Message *msg = (*it).get();
|
|
|
|
if (msg->functionalWrite(pkt)) {
|
|
|
|
num_functional_writes++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_functional_writes;
|
|
|
|
}
|