RubySystem.cc revision 7039
12SN/A/*
211147Smitch.hayenga@arm.com * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
39920Syasuko.eckert@amd.com * All rights reserved.
48733Sgeoffrey.blake@arm.com *
58733Sgeoffrey.blake@arm.com * Redistribution and use in source and binary forms, with or without
68733Sgeoffrey.blake@arm.com * modification, are permitted provided that the following conditions are
78733Sgeoffrey.blake@arm.com * met: redistributions of source code must retain the above copyright
88733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer;
98733Sgeoffrey.blake@arm.com * redistributions in binary form must reproduce the above copyright
108733Sgeoffrey.blake@arm.com * notice, this list of conditions and the following disclaimer in the
118733Sgeoffrey.blake@arm.com * documentation and/or other materials provided with the distribution;
128733Sgeoffrey.blake@arm.com * neither the name of the copyright holders nor the names of its
138733Sgeoffrey.blake@arm.com * contributors may be used to endorse or promote products derived from
148733Sgeoffrey.blake@arm.com * this software without specific prior written permission.
151762SN/A *
162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272SN/A */
282SN/A
292SN/A#include "base/output.hh"
302SN/A#include "mem/ruby/buffers/MessageBuffer.hh"
312SN/A#include "mem/ruby/common/Address.hh"
322SN/A#include "mem/ruby/network/Network.hh"
332SN/A#include "mem/ruby/profiler/Profiler.hh"
342SN/A#include "mem/ruby/recorder/Tracer.hh"
352SN/A#include "mem/ruby/slicc_interface/AbstractController.hh"
362SN/A#include "mem/ruby/system/MemoryVector.hh"
372SN/A#include "mem/ruby/system/System.hh"
382SN/A
392SN/Aint RubySystem::m_random_seed;
402665Ssaidi@eecs.umich.edubool RubySystem::m_randomization;
412665Ssaidi@eecs.umich.eduTick RubySystem::m_clock;
422665Ssaidi@eecs.umich.eduint RubySystem::m_block_size_bytes;
432665Ssaidi@eecs.umich.eduint RubySystem::m_block_size_bits;
442SN/Auint64 RubySystem::m_memory_size_bytes;
452SN/Aint RubySystem::m_memory_size_bits;
462623SN/A
472623SN/ANetwork* RubySystem::m_network_ptr;
482SN/AProfiler* RubySystem::m_profiler_ptr;
491354SN/ATracer* RubySystem::m_tracer_ptr;
506658Snate@binkert.orgMemoryVector* RubySystem::m_mem_vec_ptr;
511717SN/A
528887Sgeoffrey.blake@arm.comRubySystem::RubySystem(const Params *p)
5310319SAndreas.Sandberg@ARM.com    : SimObject(p)
548229Snate@binkert.org{
552683Sktlim@umich.edu    if (g_system_ptr != NULL)
561354SN/A        fatal("Only one RubySystem object currently allowed.\n");
572387SN/A
582387SN/A    m_random_seed = p->random_seed;
592387SN/A    srandom(m_random_seed);
6056SN/A    m_randomization = p->randomization;
618779Sgblack@eecs.umich.edu    m_clock = p->clock;
625348Ssaidi@eecs.umich.edu
632SN/A    m_block_size_bytes = p->block_size_bytes;
642SN/A    assert(is_power_of_2(m_block_size_bytes));
658779Sgblack@eecs.umich.edu    m_block_size_bits = log_int(m_block_size_bytes);
668779Sgblack@eecs.umich.edu
672SN/A    m_memory_size_bytes = p->mem_size;
688779Sgblack@eecs.umich.edu    if (m_memory_size_bytes == 0) {
692SN/A        m_memory_size_bits = 0;
704182Sgblack@eecs.umich.edu    } else {
714182Sgblack@eecs.umich.edu        m_memory_size_bits = log_int(m_memory_size_bytes);
728779Sgblack@eecs.umich.edu    }
738779Sgblack@eecs.umich.edu
744182Sgblack@eecs.umich.edu    m_network_ptr = p->network;
752SN/A    g_debug_ptr = p->debug;
762SN/A    m_profiler_ptr = p->profiler;
772SN/A    m_tracer_ptr = p->tracer;
782SN/A
792SN/A    g_eventQueue_ptr = new RubyEventQueue(p->eventq, m_clock);
808737Skoansin.tan@gmail.com    g_system_ptr = this;
8110061Sandreas@sandberg.pp.se    if (p->no_mem_vec) {
8211147Smitch.hayenga@arm.com        m_mem_vec_ptr = NULL;
832420SN/A    } else {
8411147Smitch.hayenga@arm.com        m_mem_vec_ptr = new MemoryVector;
852SN/A        m_mem_vec_ptr->setSize(m_memory_size_bytes);
862107SN/A    }
8711147Smitch.hayenga@arm.com
8810061Sandreas@sandberg.pp.se    //
8910061Sandreas@sandberg.pp.se    // Print ruby configuration and stats at exit
9011147Smitch.hayenga@arm.com    //
9111147Smitch.hayenga@arm.com    RubyExitCallback* rubyExitCB = new RubyExitCallback(p->stats_filename);
922SN/A    registerExitCallback(rubyExitCB);
931400SN/A}
945529Snate@binkert.org
952623SN/Avoid
9611168Sandreas.hansson@arm.comRubySystem::init()
9711169Sandreas.hansson@arm.com{
981400SN/A    m_profiler_ptr->clearStats();
9911147Smitch.hayenga@arm.com}
1008733Sgeoffrey.blake@arm.com
1018887Sgeoffrey.blake@arm.comRubySystem::~RubySystem()
10211147Smitch.hayenga@arm.com{
10311147Smitch.hayenga@arm.com    delete m_network_ptr;
10411147Smitch.hayenga@arm.com    delete m_profiler_ptr;
10511147Smitch.hayenga@arm.com    delete m_tracer_ptr;
10611147Smitch.hayenga@arm.com    if (m_mem_vec_ptr)
10711147Smitch.hayenga@arm.com        delete m_mem_vec_ptr;
10811147Smitch.hayenga@arm.com}
10911147Smitch.hayenga@arm.com
1105169Ssaidi@eecs.umich.eduvoid
1115496Ssaidi@eecs.umich.eduRubySystem::printSystemConfig(ostream & out)
1125496Ssaidi@eecs.umich.edu{
1135496Ssaidi@eecs.umich.edu    out << "RubySystem config:" << endl
1148276SAli.Saidi@ARM.com        << "  random_seed: " << m_random_seed << endl
1155894Sgblack@eecs.umich.edu        << "  randomization: " << m_randomization << endl
1165496Ssaidi@eecs.umich.edu        << "  cycle_period: " << m_clock << endl
1175496Ssaidi@eecs.umich.edu        << "  block_size_bytes: " << m_block_size_bytes << endl
1185496Ssaidi@eecs.umich.edu        << "  block_size_bits: " << m_block_size_bits << endl
1195894Sgblack@eecs.umich.edu        << "  memory_size_bytes: " << m_memory_size_bytes << endl
1205496Ssaidi@eecs.umich.edu        << "  memory_size_bits: " << m_memory_size_bits << endl;
1215496Ssaidi@eecs.umich.edu}
1225496Ssaidi@eecs.umich.edu
1235496Ssaidi@eecs.umich.eduvoid
1245496Ssaidi@eecs.umich.eduRubySystem::printConfig(ostream& out)
1255496Ssaidi@eecs.umich.edu{
1265496Ssaidi@eecs.umich.edu    out << "\n================ Begin RubySystem Configuration Print ================\n\n";
1275169Ssaidi@eecs.umich.edu    printSystemConfig(out);
1282SN/A    m_network_ptr->printConfig(out);
1292SN/A    m_profiler_ptr->printConfig(out);
1304377Sgblack@eecs.umich.edu    out << "\n================ End RubySystem Configuration Print ================\n\n";
1312623SN/A}
13212749Sgiacomo.travaglini@arm.com
1332623SN/Avoid
1342623SN/ARubySystem::printStats(ostream& out)
13510379Sandreas.hansson@arm.com{
136180SN/A    const time_t T = time(NULL);
13711169Sandreas.hansson@arm.com    tm *localTime = localtime(&T);
1382SN/A    char buf[100];
1392SN/A    strftime(buf, 100, "%b/%d/%Y %H:%M:%S", localTime);
14011169Sandreas.hansson@arm.com
14111169Sandreas.hansson@arm.com    out << "Real time: " << buf << endl;
1422SN/A
14311169Sandreas.hansson@arm.com    m_profiler_ptr->printStats(out);
1449461Snilay@cs.wisc.edu    m_network_ptr->printStats(out);
14511147Smitch.hayenga@arm.com}
14611608Snikos.nikoleris@arm.com
147707SN/Avoid
14811608Snikos.nikoleris@arm.comRubySystem::clearStats() const
14911608Snikos.nikoleris@arm.com{
15011303Ssteve.reinhardt@amd.com    m_profiler_ptr->clearStats();
15111147Smitch.hayenga@arm.com    m_network_ptr->clearStats();
15211608Snikos.nikoleris@arm.com}
1538834Satgutier@umich.edu
15411147Smitch.hayenga@arm.comvoid
15511169Sandreas.hansson@arm.comRubySystem::recordCacheContents(CacheRecorder& tr) const
15611169Sandreas.hansson@arm.com{
15710193SCurtis.Dunham@arm.com}
15811168Sandreas.hansson@arm.com
15911168Sandreas.hansson@arm.com#ifdef CHECK_COHERENCE
1602SN/A// This code will check for cases if the given cache block is exclusive in
1612SN/A// one node and shared in another-- a coherence violation
1622SN/A//
1632623SN/A// To use, the SLICC specification must call sequencer.checkCoherence(address)
164// when the controller changes to a state with new permissions.  Do this
165// in setState.  The SLICC spec must also define methods "isBlockShared"
166// and "isBlockExclusive" that are specific to that protocol
167//
168void
169RubySystem::checkGlobalCoherenceInvariant(const Address& addr)
170{
171#if 0
172    NodeID exclusive = -1;
173    bool sharedDetected = false;
174    NodeID lastShared = -1;
175
176    for (int i = 0; i < m_chip_vector.size(); i++) {
177        if (m_chip_vector[i]->isBlockExclusive(addr)) {
178            if (exclusive != -1) {
179                // coherence violation
180                WARN_EXPR(exclusive);
181                WARN_EXPR(m_chip_vector[i]->getID());
182                WARN_EXPR(addr);
183                WARN_EXPR(g_eventQueue_ptr->getTime());
184                ERROR_MSG("Coherence Violation Detected -- 2 exclusive chips");
185            } else if (sharedDetected) {
186                WARN_EXPR(lastShared);
187                WARN_EXPR(m_chip_vector[i]->getID());
188                WARN_EXPR(addr);
189                WARN_EXPR(g_eventQueue_ptr->getTime());
190                ERROR_MSG("Coherence Violation Detected -- exclusive chip with >=1 shared");
191            } else {
192                exclusive = m_chip_vector[i]->getID();
193            }
194        } else if (m_chip_vector[i]->isBlockShared(addr)) {
195            sharedDetected = true;
196            lastShared = m_chip_vector[i]->getID();
197
198            if (exclusive != -1) {
199                WARN_EXPR(lastShared);
200                WARN_EXPR(exclusive);
201                WARN_EXPR(addr);
202                WARN_EXPR(g_eventQueue_ptr->getTime());
203                ERROR_MSG("Coherence Violation Detected -- exclusive chip with >=1 shared");
204            }
205        }
206    }
207#endif
208}
209#endif
210
211RubySystem *
212RubySystemParams::create()
213{
214    return new RubySystem(this);
215}
216
217/**
218 * virtual process function that is invoked when the callback
219 * queue is executed.
220 */
221void
222RubyExitCallback::process()
223{
224    std::ostream *os = simout.create(stats_filename);
225    RubySystem::printConfig(*os);
226    *os << endl;
227    RubySystem::printStats(*os);
228}
229