gem5/src/mem/ruby/network/MessageBuffer.cc

399 lines
12 KiB
C++
Raw Normal View History

/*
* 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.
*/
#include <cassert>
#include "base/cprintf.hh"
#include "base/misc.hh"
#include "base/random.hh"
#include "base/stl_helpers.hh"
#include "debug/RubyQueue.hh"
ruby: move files from ruby/system to ruby/structures The directory ruby/system is crowded and unorganized. Hence, the files the hold actual physical structures, are being moved to the directory ruby/structures. This includes Cache Memory, Directory Memory, Memory Controller, Wire Buffer, TBE Table, Perfect Cache Memory, Timer Table, Bank Array. The directory ruby/systems has the glue code that holds these structures together. --HG-- rename : src/mem/ruby/system/MachineID.hh => src/mem/ruby/common/MachineID.hh rename : src/mem/ruby/buffers/MessageBuffer.cc => src/mem/ruby/network/MessageBuffer.cc rename : src/mem/ruby/buffers/MessageBuffer.hh => src/mem/ruby/network/MessageBuffer.hh rename : src/mem/ruby/buffers/MessageBufferNode.cc => src/mem/ruby/network/MessageBufferNode.cc rename : src/mem/ruby/buffers/MessageBufferNode.hh => src/mem/ruby/network/MessageBufferNode.hh rename : src/mem/ruby/system/AbstractReplacementPolicy.hh => src/mem/ruby/structures/AbstractReplacementPolicy.hh rename : src/mem/ruby/system/BankedArray.cc => src/mem/ruby/structures/BankedArray.cc rename : src/mem/ruby/system/BankedArray.hh => src/mem/ruby/structures/BankedArray.hh rename : src/mem/ruby/system/Cache.py => src/mem/ruby/structures/Cache.py rename : src/mem/ruby/system/CacheMemory.cc => src/mem/ruby/structures/CacheMemory.cc rename : src/mem/ruby/system/CacheMemory.hh => src/mem/ruby/structures/CacheMemory.hh rename : src/mem/ruby/system/DirectoryMemory.cc => src/mem/ruby/structures/DirectoryMemory.cc rename : src/mem/ruby/system/DirectoryMemory.hh => src/mem/ruby/structures/DirectoryMemory.hh rename : src/mem/ruby/system/DirectoryMemory.py => src/mem/ruby/structures/DirectoryMemory.py rename : src/mem/ruby/system/LRUPolicy.hh => src/mem/ruby/structures/LRUPolicy.hh rename : src/mem/ruby/system/MemoryControl.cc => src/mem/ruby/structures/MemoryControl.cc rename : src/mem/ruby/system/MemoryControl.hh => src/mem/ruby/structures/MemoryControl.hh rename : src/mem/ruby/system/MemoryControl.py => src/mem/ruby/structures/MemoryControl.py rename : src/mem/ruby/system/MemoryNode.cc => src/mem/ruby/structures/MemoryNode.cc rename : src/mem/ruby/system/MemoryNode.hh => src/mem/ruby/structures/MemoryNode.hh rename : src/mem/ruby/system/MemoryVector.hh => src/mem/ruby/structures/MemoryVector.hh rename : src/mem/ruby/system/PerfectCacheMemory.hh => src/mem/ruby/structures/PerfectCacheMemory.hh rename : src/mem/ruby/system/PersistentTable.cc => src/mem/ruby/structures/PersistentTable.cc rename : src/mem/ruby/system/PersistentTable.hh => src/mem/ruby/structures/PersistentTable.hh rename : src/mem/ruby/system/PseudoLRUPolicy.hh => src/mem/ruby/structures/PseudoLRUPolicy.hh rename : src/mem/ruby/system/RubyMemoryControl.cc => src/mem/ruby/structures/RubyMemoryControl.cc rename : src/mem/ruby/system/RubyMemoryControl.hh => src/mem/ruby/structures/RubyMemoryControl.hh rename : src/mem/ruby/system/RubyMemoryControl.py => src/mem/ruby/structures/RubyMemoryControl.py rename : src/mem/ruby/system/SparseMemory.cc => src/mem/ruby/structures/SparseMemory.cc rename : src/mem/ruby/system/SparseMemory.hh => src/mem/ruby/structures/SparseMemory.hh rename : src/mem/ruby/system/TBETable.hh => src/mem/ruby/structures/TBETable.hh rename : src/mem/ruby/system/TimerTable.cc => src/mem/ruby/structures/TimerTable.cc rename : src/mem/ruby/system/TimerTable.hh => src/mem/ruby/structures/TimerTable.hh rename : src/mem/ruby/system/WireBuffer.cc => src/mem/ruby/structures/WireBuffer.cc rename : src/mem/ruby/system/WireBuffer.hh => src/mem/ruby/structures/WireBuffer.hh rename : src/mem/ruby/system/WireBuffer.py => src/mem/ruby/structures/WireBuffer.py rename : src/mem/ruby/recorder/CacheRecorder.cc => src/mem/ruby/system/CacheRecorder.cc rename : src/mem/ruby/recorder/CacheRecorder.hh => src/mem/ruby/system/CacheRecorder.hh
2014-09-01 23:55:40 +02:00
#include "mem/ruby/network/MessageBuffer.hh"
#include "mem/ruby/system/RubySystem.hh"
using namespace std;
using m5::stl_helpers::operator<<;
ruby: Expose MessageBuffers as SimObjects Expose MessageBuffers from SLICC controllers as SimObjects that can be manipulated in Python. This patch has numerous benefits: 1) First and foremost, it exposes MessageBuffers as SimObjects that can be manipulated in Python code. This allows parameters to be set and checked in Python code to avoid obfuscating parameters within protocol files. Further, now as SimObjects, MessageBuffer parameters are printed to config output files as a way to track parameters across simulations (e.g. buffer sizes) 2) Cleans up special-case code for responseFromMemory buffers, and aligns their instantiation and use with mandatoryQueue buffers. These two special buffers are the only MessageBuffers that are exposed to components outside of SLICC controllers, and they're both slave ends of these buffers. They should be exposed outside of SLICC in the same way, and this patch does it. 3) Distinguishes buffer-specific parameters from buffer-to-network parameters. Specifically, buffer size, randomization, ordering, recycle latency, and ports are all specific to a MessageBuffer, while the virtual network ID and type are intrinsics of how the buffer is connected to network ports. The former are specified in the Python object, while the latter are specified in the controller *.sm files. Unlike buffer-specific parameters, which may need to change depending on the simulated system structure, buffer-to-network parameters can be specified statically for most or all different simulated systems.
2015-08-14 07:19:44 +02:00
MessageBuffer::MessageBuffer(const Params *p)
: SimObject(p),
ruby: Expose MessageBuffers as SimObjects Expose MessageBuffers from SLICC controllers as SimObjects that can be manipulated in Python. This patch has numerous benefits: 1) First and foremost, it exposes MessageBuffers as SimObjects that can be manipulated in Python code. This allows parameters to be set and checked in Python code to avoid obfuscating parameters within protocol files. Further, now as SimObjects, MessageBuffer parameters are printed to config output files as a way to track parameters across simulations (e.g. buffer sizes) 2) Cleans up special-case code for responseFromMemory buffers, and aligns their instantiation and use with mandatoryQueue buffers. These two special buffers are the only MessageBuffers that are exposed to components outside of SLICC controllers, and they're both slave ends of these buffers. They should be exposed outside of SLICC in the same way, and this patch does it. 3) Distinguishes buffer-specific parameters from buffer-to-network parameters. Specifically, buffer size, randomization, ordering, recycle latency, and ports are all specific to a MessageBuffer, while the virtual network ID and type are intrinsics of how the buffer is connected to network ports. The former are specified in the Python object, while the latter are specified in the controller *.sm files. Unlike buffer-specific parameters, which may need to change depending on the simulated system structure, buffer-to-network parameters can be specified statically for most or all different simulated systems.
2015-08-14 07:19:44 +02:00
m_max_size(p->buffer_size), m_time_last_time_size_checked(0),
m_time_last_time_enqueue(0), m_time_last_time_pop(0),
m_last_arrival_time(0), m_strict_fifo(p->ordered),
m_randomization(p->randomization)
{
2010-03-23 02:43:53 +01:00
m_msg_counter = 0;
m_consumer = NULL;
2010-03-23 02:43:53 +01:00
m_size_last_time_size_checked = 0;
m_size_at_cycle_start = 0;
m_msgs_this_cycle = 0;
m_priority_rank = 0;
m_stall_msg_map.clear();
m_input_link_id = 0;
m_vnet_id = 0;
}
unsigned int
MessageBuffer::getSize(Tick curTime)
{
if (m_time_last_time_size_checked != curTime) {
m_time_last_time_size_checked = curTime;
m_size_last_time_size_checked = m_prio_heap.size();
2010-03-23 02:43:53 +01:00
}
return m_size_last_time_size_checked;
}
2010-03-23 02:43:53 +01:00
bool
MessageBuffer::areNSlotsAvailable(unsigned int n, Tick current_time)
{
2010-03-23 02:43:53 +01:00
// fast path when message buffers have infinite size
if (m_max_size == 0) {
2010-03-23 02:43:53 +01:00
return true;
}
// determine the correct size for the current cycle
2010-03-23 02:43:53 +01:00
// pop operations shouldn't effect the network's visible size
// until schd cycle, but enqueue operations effect the visible
2010-03-23 02:43:53 +01:00
// size immediately
unsigned int current_size = 0;
if (m_time_last_time_pop < current_time) {
// no pops this cycle - heap size is correct
current_size = m_prio_heap.size();
2010-03-23 02:43:53 +01:00
} else {
if (m_time_last_time_enqueue < current_time) {
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;
2010-03-23 02:43:53 +01:00
}
}
// now compare the new size with our max size
if (current_size + n <= m_max_size) {
return true;
} else {
DPRINTF(RubyQueue, "n: %d, current_size: %d, heap size: %d, "
"m_max_size: %d\n",
n, current_size, m_prio_heap.size(), m_max_size);
2010-03-23 02:43:53 +01:00
m_not_avail_count++;
return false;
}
}
2010-03-23 02:43:53 +01:00
const Message*
MessageBuffer::peek() const
{
DPRINTF(RubyQueue, "Peeking at head of queue.\n");
const Message* msg_ptr = m_prio_heap.front().get();
assert(msg_ptr);
DPRINTF(RubyQueue, "Message: %s\n", (*msg_ptr));
2010-03-23 02:43:53 +01:00
return msg_ptr;
}
// FIXME - move me somewhere else
Tick
2010-03-23 02:43:53 +01:00
random_time()
{
Tick time = 1;
time += random_mt.random(0, 3); // [0...3]
if (random_mt.random(0, 7) == 0) { // 1 in 8 chance
time += 100 + random_mt.random(1, 15); // 100 + [1...15]
2010-03-23 02:43:53 +01:00
}
return time;
}
2010-03-23 02:43:53 +01:00
void
MessageBuffer::enqueue(MsgPtr message, Tick current_time, Tick delta)
{
2010-03-23 02:43:53 +01:00
// record current time incase we have a pop that also adjusts my size
if (m_time_last_time_enqueue < current_time) {
2010-03-23 02:43:53 +01:00
m_msgs_this_cycle = 0; // first msg this cycle
m_time_last_time_enqueue = current_time;
}
2010-03-23 02:43:53 +01:00
m_msg_counter++;
m_msgs_this_cycle++;
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);
Tick arrival_time = 0;
if (!RubySystem::getRandomization() || !m_randomization) {
2010-03-23 02:43:53 +01:00
// No randomization
arrival_time = current_time + delta;
2010-03-23 02:43:53 +01:00
} 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();
2010-03-23 02:43:53 +01:00
} else {
arrival_time = current_time + random_time();
2010-03-23 02:43:53 +01:00
}
}
// Check the arrival time
assert(arrival_time > current_time);
if (m_strict_fifo) {
if (arrival_time < m_last_arrival_time) {
panic("FIFO ordering violated: %s name: %s current time: %d "
"delta: %d arrival_time: %d last arrival_time: %d\n",
*this, name(), current_time, delta, arrival_time,
m_last_arrival_time);
2010-03-23 02:43:53 +01:00
}
}
// If running a cache trace, don't worry about the last arrival checks
if (!RubySystem::getWarmupEnabled()) {
m_last_arrival_time = arrival_time;
}
2010-03-23 02:43:53 +01:00
// compute the delay cycles and set enqueue time
Message* msg_ptr = message.get();
2010-03-23 02:43:53 +01:00
assert(msg_ptr != NULL);
assert(current_time >= msg_ptr->getLastEnqueueTime() &&
2010-03-23 02:43:53 +01:00
"ensure we aren't dequeued early");
msg_ptr->updateDelayedTicks(current_time);
msg_ptr->setLastEnqueueTime(arrival_time);
msg_ptr->setMsgCounter(m_msg_counter);
2010-03-23 02:43:53 +01:00
// Insert the message into the priority heap
m_prio_heap.push_back(message);
push_heap(m_prio_heap.begin(), m_prio_heap.end(), greater<MsgPtr>());
2010-03-23 02:43:53 +01:00
DPRINTF(RubyQueue, "Enqueue arrival_time: %lld, Message: %s\n",
arrival_time, *(message.get()));
2010-03-23 02:43:53 +01:00
// Schedule the wakeup
assert(m_consumer != NULL);
m_consumer->scheduleEventAbsolute(arrival_time);
m_consumer->storeEventInfo(m_vnet_id);
}
Tick
MessageBuffer::dequeue(Tick current_time)
{
DPRINTF(RubyQueue, "Popping\n");
assert(isReady(current_time));
2010-03-23 02:43:53 +01:00
// get MsgPtr of the message about to be dequeued
MsgPtr message = m_prio_heap.front();
2010-03-23 02:43:53 +01:00
// get the delay cycles
message->updateDelayedTicks(current_time);
Tick delay = message->getDelayedTicks();
2010-03-23 02:43:53 +01:00
// record previous size and time so the current buffer size isn't
// adjusted until schd cycle
if (m_time_last_time_pop < current_time) {
m_size_at_cycle_start = m_prio_heap.size();
m_time_last_time_pop = current_time;
2010-03-23 02:43:53 +01:00
}
pop_heap(m_prio_heap.begin(), m_prio_heap.end(), greater<MsgPtr>());
m_prio_heap.pop_back();
return delay;
}
2010-03-23 02:43:53 +01:00
void
MessageBuffer::clear()
{
m_prio_heap.clear();
2010-03-23 02:43:53 +01:00
m_msg_counter = 0;
m_time_last_time_enqueue = 0;
m_time_last_time_pop = 0;
2010-03-23 02:43:53 +01:00
m_size_at_cycle_start = 0;
m_msgs_this_cycle = 0;
}
2010-03-23 02:43:53 +01:00
void
MessageBuffer::recycle(Tick current_time, Tick recycle_latency)
{
DPRINTF(RubyQueue, "Recycling.\n");
assert(isReady(current_time));
MsgPtr node = m_prio_heap.front();
pop_heap(m_prio_heap.begin(), m_prio_heap.end(), greater<MsgPtr>());
Tick future_time = current_time + recycle_latency;
node->setLastEnqueueTime(future_time);
m_prio_heap.back() = node;
push_heap(m_prio_heap.begin(), m_prio_heap.end(), greater<MsgPtr>());
m_consumer->scheduleEventAbsolute(future_time);
}
void
MessageBuffer::reanalyzeList(list<MsgPtr> &lt, Tick schdTick)
{
while (!lt.empty()) {
m_msg_counter++;
MsgPtr m = lt.front();
m->setLastEnqueueTime(schdTick);
m->setMsgCounter(m_msg_counter);
m_prio_heap.push_back(m);
push_heap(m_prio_heap.begin(), m_prio_heap.end(),
greater<MsgPtr>());
m_consumer->scheduleEventAbsolute(schdTick);
lt.pop_front();
}
}
void
MessageBuffer::reanalyzeMessages(Addr addr, Tick current_time)
{
DPRINTF(RubyQueue, "ReanalyzeMessages %#x\n", addr);
assert(m_stall_msg_map.count(addr) > 0);
//
// Put all stalled messages associated with this address back on the
// prio heap. The reanalyzeList call will make sure the consumer is
// scheduled for the current cycle so that the previously stalled messages
// will be observed before any younger messages that may arrive this cycle
//
reanalyzeList(m_stall_msg_map[addr], current_time);
m_stall_msg_map.erase(addr);
}
void
MessageBuffer::reanalyzeAllMessages(Tick current_time)
{
DPRINTF(RubyQueue, "ReanalyzeAllMessages\n");
//
// Put all stalled messages associated with this address back on the
// prio heap. The reanalyzeList call will make sure the consumer is
// scheduled for the current cycle so that the previously stalled messages
// will be observed before any younger messages that may arrive this cycle.
//
for (StallMsgMapType::iterator map_iter = m_stall_msg_map.begin();
map_iter != m_stall_msg_map.end(); ++map_iter) {
reanalyzeList(map_iter->second, current_time);
}
m_stall_msg_map.clear();
}
void
MessageBuffer::stallMessage(Addr addr, Tick current_time)
{
DPRINTF(RubyQueue, "Stalling due to %#x\n", addr);
assert(isReady(current_time));
assert(getOffset(addr) == 0);
MsgPtr message = m_prio_heap.front();
dequeue(current_time);
//
// 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);
}
2010-03-23 02:43:53 +01:00
void
MessageBuffer::print(ostream& out) const
{
ccprintf(out, "[MessageBuffer: ");
if (m_consumer != NULL) {
ccprintf(out, " consumer-yes ");
2010-03-23 02:43:53 +01:00
}
vector<MsgPtr> copy(m_prio_heap);
sort_heap(copy.begin(), copy.end(), greater<MsgPtr>());
ruby: Expose MessageBuffers as SimObjects Expose MessageBuffers from SLICC controllers as SimObjects that can be manipulated in Python. This patch has numerous benefits: 1) First and foremost, it exposes MessageBuffers as SimObjects that can be manipulated in Python code. This allows parameters to be set and checked in Python code to avoid obfuscating parameters within protocol files. Further, now as SimObjects, MessageBuffer parameters are printed to config output files as a way to track parameters across simulations (e.g. buffer sizes) 2) Cleans up special-case code for responseFromMemory buffers, and aligns their instantiation and use with mandatoryQueue buffers. These two special buffers are the only MessageBuffers that are exposed to components outside of SLICC controllers, and they're both slave ends of these buffers. They should be exposed outside of SLICC in the same way, and this patch does it. 3) Distinguishes buffer-specific parameters from buffer-to-network parameters. Specifically, buffer size, randomization, ordering, recycle latency, and ports are all specific to a MessageBuffer, while the virtual network ID and type are intrinsics of how the buffer is connected to network ports. The former are specified in the Python object, while the latter are specified in the controller *.sm files. Unlike buffer-specific parameters, which may need to change depending on the simulated system structure, buffer-to-network parameters can be specified statically for most or all different simulated systems.
2015-08-14 07:19:44 +02:00
ccprintf(out, "%s] %s", copy, name());
}
bool
MessageBuffer::isReady(Tick current_time) const
{
return ((m_prio_heap.size() > 0) &&
(m_prio_heap.front()->getLastEnqueueTime() <= current_time));
}
void
MessageBuffer::regStats()
{
m_not_avail_count
.name(name() + ".not_avail_count")
.desc("Number of times this buffer did not have N slots available")
.flags(Stats::nozero);
}
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].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;
}
ruby: Expose MessageBuffers as SimObjects Expose MessageBuffers from SLICC controllers as SimObjects that can be manipulated in Python. This patch has numerous benefits: 1) First and foremost, it exposes MessageBuffers as SimObjects that can be manipulated in Python code. This allows parameters to be set and checked in Python code to avoid obfuscating parameters within protocol files. Further, now as SimObjects, MessageBuffer parameters are printed to config output files as a way to track parameters across simulations (e.g. buffer sizes) 2) Cleans up special-case code for responseFromMemory buffers, and aligns their instantiation and use with mandatoryQueue buffers. These two special buffers are the only MessageBuffers that are exposed to components outside of SLICC controllers, and they're both slave ends of these buffers. They should be exposed outside of SLICC in the same way, and this patch does it. 3) Distinguishes buffer-specific parameters from buffer-to-network parameters. Specifically, buffer size, randomization, ordering, recycle latency, and ports are all specific to a MessageBuffer, while the virtual network ID and type are intrinsics of how the buffer is connected to network ports. The former are specified in the Python object, while the latter are specified in the controller *.sm files. Unlike buffer-specific parameters, which may need to change depending on the simulated system structure, buffer-to-network parameters can be specified statically for most or all different simulated systems.
2015-08-14 07:19:44 +02:00
MessageBuffer *
MessageBufferParams::create()
{
return new MessageBuffer(this);
}