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.
|
|
|
|
*/
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
#include "base/output.hh"
|
|
|
|
#include "mem/ruby/buffers/MessageBuffer.hh"
|
2009-07-07 00:49:47 +02:00
|
|
|
#include "mem/ruby/common/Address.hh"
|
2009-05-11 19:38:45 +02:00
|
|
|
#include "mem/ruby/network/Network.hh"
|
2010-03-23 02:43:53 +01:00
|
|
|
#include "mem/ruby/profiler/Profiler.hh"
|
2009-07-07 00:49:47 +02:00
|
|
|
#include "mem/ruby/recorder/Tracer.hh"
|
|
|
|
#include "mem/ruby/slicc_interface/AbstractController.hh"
|
2010-03-23 02:43:53 +01:00
|
|
|
#include "mem/ruby/system/MemoryVector.hh"
|
|
|
|
#include "mem/ruby/system/System.hh"
|
2009-07-07 00:49:47 +02:00
|
|
|
|
|
|
|
int RubySystem::m_random_seed;
|
|
|
|
bool RubySystem::m_randomization;
|
2010-01-30 05:29:19 +01:00
|
|
|
Tick RubySystem::m_clock;
|
2009-07-07 00:49:47 +02:00
|
|
|
int RubySystem::m_block_size_bytes;
|
|
|
|
int RubySystem::m_block_size_bits;
|
|
|
|
uint64 RubySystem::m_memory_size_bytes;
|
|
|
|
int RubySystem::m_memory_size_bits;
|
|
|
|
|
|
|
|
Network* RubySystem::m_network_ptr;
|
|
|
|
Profiler* RubySystem::m_profiler_ptr;
|
|
|
|
Tracer* RubySystem::m_tracer_ptr;
|
|
|
|
MemoryVector* RubySystem::m_mem_vec_ptr;
|
|
|
|
|
2010-01-30 05:29:17 +01:00
|
|
|
RubySystem::RubySystem(const Params *p)
|
|
|
|
: SimObject(p)
|
2009-05-11 19:38:46 +02:00
|
|
|
{
|
2010-01-30 05:29:17 +01:00
|
|
|
if (g_system_ptr != NULL)
|
|
|
|
fatal("Only one RubySystem object currently allowed.\n");
|
|
|
|
|
|
|
|
m_random_seed = p->random_seed;
|
|
|
|
srandom(m_random_seed);
|
|
|
|
m_randomization = p->randomization;
|
2010-01-30 05:29:19 +01:00
|
|
|
m_clock = p->clock;
|
2010-01-30 05:29:18 +01:00
|
|
|
|
2010-01-30 05:29:17 +01:00
|
|
|
m_block_size_bytes = p->block_size_bytes;
|
|
|
|
assert(is_power_of_2(m_block_size_bytes));
|
|
|
|
m_block_size_bits = log_int(m_block_size_bytes);
|
2010-01-30 05:29:18 +01:00
|
|
|
|
2010-01-30 05:29:23 +01:00
|
|
|
m_memory_size_bytes = p->mem_size;
|
2010-03-22 05:22:21 +01:00
|
|
|
if (m_memory_size_bytes == 0) {
|
|
|
|
m_memory_size_bits = 0;
|
|
|
|
} else {
|
|
|
|
m_memory_size_bits = log_int(m_memory_size_bytes);
|
|
|
|
}
|
2010-01-30 05:29:18 +01:00
|
|
|
|
2010-01-30 05:29:17 +01:00
|
|
|
m_network_ptr = p->network;
|
|
|
|
g_debug_ptr = p->debug;
|
|
|
|
m_profiler_ptr = p->profiler;
|
|
|
|
m_tracer_ptr = p->tracer;
|
|
|
|
|
2010-01-30 05:29:19 +01:00
|
|
|
g_eventQueue_ptr = new RubyEventQueue(p->eventq, m_clock);
|
2010-01-30 05:29:17 +01:00
|
|
|
g_system_ptr = this;
|
2010-03-22 05:22:21 +01:00
|
|
|
if (p->no_mem_vec) {
|
|
|
|
m_mem_vec_ptr = NULL;
|
|
|
|
} else {
|
|
|
|
m_mem_vec_ptr = new MemoryVector;
|
|
|
|
m_mem_vec_ptr->setSize(m_memory_size_bytes);
|
|
|
|
}
|
2010-01-30 05:29:21 +01:00
|
|
|
|
|
|
|
//
|
|
|
|
// Print ruby configuration and stats at exit
|
|
|
|
//
|
|
|
|
RubyExitCallback* rubyExitCB = new RubyExitCallback(p->stats_filename);
|
|
|
|
registerExitCallback(rubyExitCB);
|
2009-05-11 19:38:46 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubySystem::init()
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
m_profiler_ptr->clearStats();
|
2009-05-11 19:38:46 +02:00
|
|
|
}
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2009-07-07 00:49:47 +02:00
|
|
|
RubySystem::~RubySystem()
|
2009-05-11 19:38:46 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
delete m_network_ptr;
|
|
|
|
delete m_profiler_ptr;
|
|
|
|
delete m_tracer_ptr;
|
|
|
|
if (m_mem_vec_ptr)
|
|
|
|
delete m_mem_vec_ptr;
|
2009-07-07 00:49:47 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubySystem::printSystemConfig(ostream & out)
|
2009-07-07 00:49:47 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
out << "RubySystem config:" << endl
|
|
|
|
<< " random_seed: " << m_random_seed << endl
|
|
|
|
<< " randomization: " << m_randomization << endl
|
|
|
|
<< " cycle_period: " << m_clock << endl
|
|
|
|
<< " block_size_bytes: " << m_block_size_bytes << endl
|
|
|
|
<< " block_size_bits: " << m_block_size_bits << endl
|
|
|
|
<< " memory_size_bytes: " << m_memory_size_bytes << endl
|
|
|
|
<< " memory_size_bits: " << m_memory_size_bits << endl;
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubySystem::printConfig(ostream& out)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
out << "\n================ Begin RubySystem Configuration Print ================\n\n";
|
|
|
|
printSystemConfig(out);
|
|
|
|
m_network_ptr->printConfig(out);
|
|
|
|
m_profiler_ptr->printConfig(out);
|
|
|
|
out << "\n================ End RubySystem Configuration Print ================\n\n";
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubySystem::printStats(ostream& out)
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
const time_t T = time(NULL);
|
|
|
|
tm *localTime = localtime(&T);
|
|
|
|
char buf[100];
|
|
|
|
strftime(buf, 100, "%b/%d/%Y %H:%M:%S", localTime);
|
2009-07-07 00:49:47 +02:00
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
out << "Real time: " << buf << endl;
|
2009-05-11 19:38:43 +02:00
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
m_profiler_ptr->printStats(out);
|
|
|
|
m_network_ptr->printStats(out);
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubySystem::clearStats() const
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
2010-03-23 02:43:53 +01:00
|
|
|
m_profiler_ptr->clearStats();
|
|
|
|
m_network_ptr->clearStats();
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubySystem::recordCacheContents(CacheRecorder& tr) const
|
2009-05-11 19:38:43 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CHECK_COHERENCE
|
|
|
|
// This code will check for cases if the given cache block is exclusive in
|
|
|
|
// one node and shared in another-- a coherence violation
|
|
|
|
//
|
|
|
|
// To use, the SLICC specification must call sequencer.checkCoherence(address)
|
|
|
|
// when the controller changes to a state with new permissions. Do this
|
|
|
|
// in setState. The SLICC spec must also define methods "isBlockShared"
|
|
|
|
// and "isBlockExclusive" that are specific to that protocol
|
|
|
|
//
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubySystem::checkGlobalCoherenceInvariant(const Address& addr)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
NodeID exclusive = -1;
|
|
|
|
bool sharedDetected = false;
|
|
|
|
NodeID lastShared = -1;
|
|
|
|
|
|
|
|
for (int i = 0; i < m_chip_vector.size(); i++) {
|
|
|
|
if (m_chip_vector[i]->isBlockExclusive(addr)) {
|
|
|
|
if (exclusive != -1) {
|
|
|
|
// coherence violation
|
|
|
|
WARN_EXPR(exclusive);
|
|
|
|
WARN_EXPR(m_chip_vector[i]->getID());
|
|
|
|
WARN_EXPR(addr);
|
|
|
|
WARN_EXPR(g_eventQueue_ptr->getTime());
|
|
|
|
ERROR_MSG("Coherence Violation Detected -- 2 exclusive chips");
|
|
|
|
} else if (sharedDetected) {
|
|
|
|
WARN_EXPR(lastShared);
|
|
|
|
WARN_EXPR(m_chip_vector[i]->getID());
|
|
|
|
WARN_EXPR(addr);
|
|
|
|
WARN_EXPR(g_eventQueue_ptr->getTime());
|
|
|
|
ERROR_MSG("Coherence Violation Detected -- exclusive chip with >=1 shared");
|
|
|
|
} else {
|
|
|
|
exclusive = m_chip_vector[i]->getID();
|
|
|
|
}
|
|
|
|
} else if (m_chip_vector[i]->isBlockShared(addr)) {
|
|
|
|
sharedDetected = true;
|
|
|
|
lastShared = m_chip_vector[i]->getID();
|
|
|
|
|
|
|
|
if (exclusive != -1) {
|
|
|
|
WARN_EXPR(lastShared);
|
|
|
|
WARN_EXPR(exclusive);
|
|
|
|
WARN_EXPR(addr);
|
|
|
|
WARN_EXPR(g_eventQueue_ptr->getTime());
|
|
|
|
ERROR_MSG("Coherence Violation Detected -- exclusive chip with >=1 shared");
|
|
|
|
}
|
|
|
|
}
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
2010-03-23 02:43:53 +01:00
|
|
|
#endif
|
2009-05-11 19:38:43 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-01-30 05:29:17 +01:00
|
|
|
RubySystem *
|
|
|
|
RubySystemParams::create()
|
|
|
|
{
|
|
|
|
return new RubySystem(this);
|
|
|
|
}
|
2010-01-30 05:29:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virtual process function that is invoked when the callback
|
|
|
|
* queue is executed.
|
|
|
|
*/
|
2010-03-23 02:43:53 +01:00
|
|
|
void
|
|
|
|
RubyExitCallback::process()
|
2010-01-30 05:29:21 +01:00
|
|
|
{
|
|
|
|
std::ostream *os = simout.create(stats_filename);
|
|
|
|
RubySystem::printConfig(*os);
|
|
|
|
*os << endl;
|
|
|
|
RubySystem::printStats(*os);
|
|
|
|
}
|