RubyTester.cc revision 8832
16899SN/A/*
26899SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
36899SN/A * Copyright (c) 2009 Advanced Micro Devices, Inc.
46899SN/A * All rights reserved.
56899SN/A *
66899SN/A * Redistribution and use in source and binary forms, with or without
76899SN/A * modification, are permitted provided that the following conditions are
86899SN/A * met: redistributions of source code must retain the above copyright
96899SN/A * notice, this list of conditions and the following disclaimer;
106899SN/A * redistributions in binary form must reproduce the above copyright
116899SN/A * notice, this list of conditions and the following disclaimer in the
126899SN/A * documentation and/or other materials provided with the distribution;
136899SN/A * neither the name of the copyright holders nor the names of its
146899SN/A * contributors may be used to endorse or promote products derived from
156899SN/A * this software without specific prior written permission.
166899SN/A *
176899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
186899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
196899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
206899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
216899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
226899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
236899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
246899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
256899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
266899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
276899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
286899SN/A */
296899SN/A
307805Snilay@cs.wisc.edu#include "base/misc.hh"
317632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/Check.hh"
327632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/RubyTester.hh"
338232Snate@binkert.org#include "debug/RubyTest.hh"
346899SN/A#include "mem/ruby/common/Global.hh"
357053SN/A#include "mem/ruby/common/SubBlock.hh"
367053SN/A#include "mem/ruby/eventqueue/RubyEventQueue.hh"
376899SN/A#include "mem/ruby/system/System.hh"
386899SN/A#include "sim/sim_exit.hh"
398832SAli.Saidi@ARM.com#include "sim/system.hh"
406899SN/A
416899SN/ARubyTester::RubyTester(const Params *p)
427053SN/A  : MemObject(p), checkStartEvent(this),
438832SAli.Saidi@ARM.com    _masterId(p->system->getMasterId(name())),
446899SN/A    m_checks_to_complete(p->checks_to_complete),
456899SN/A    m_deadlock_threshold(p->deadlock_threshold),
468184Ssomayeh@cs.wisc.edu    m_wakeup_frequency(p->wakeup_frequency),
478184Ssomayeh@cs.wisc.edu    m_check_flush(p->check_flush)
486899SN/A{
497053SN/A    m_checks_completed = 0;
506899SN/A
517053SN/A    // add the check start event to the event queue
527053SN/A    schedule(checkStartEvent, 1);
536899SN/A}
546899SN/A
556899SN/ARubyTester::~RubyTester()
566899SN/A{
577053SN/A    delete m_checkTable_ptr;
587053SN/A    for (int i = 0; i < ports.size(); i++)
597053SN/A        delete ports[i];
606899SN/A}
616899SN/A
627053SN/Avoid
637053SN/ARubyTester::init()
646899SN/A{
657053SN/A    assert(ports.size() > 0);
666899SN/A
677454SN/A    m_last_progress_vector.resize(ports.size());
687053SN/A    for (int i = 0; i < m_last_progress_vector.size(); i++) {
697053SN/A        m_last_progress_vector[i] = 0;
707053SN/A    }
716899SN/A
727053SN/A    m_num_cpu_sequencers = ports.size();
736899SN/A
747053SN/A    m_checkTable_ptr = new CheckTable(m_num_cpu_sequencers, this);
756899SN/A}
766899SN/A
776899SN/APort *
786899SN/ARubyTester::getPort(const std::string &if_name, int idx)
796899SN/A{
806899SN/A    if (if_name != "cpuPort") {
816899SN/A        panic("RubyTester::getPort: unknown port %s requested", if_name);
826899SN/A    }
836899SN/A
846899SN/A    if (idx >= (int)ports.size()) {
856899SN/A        ports.resize(idx + 1);
866899SN/A    }
876899SN/A
886899SN/A    if (ports[idx] != NULL) {
896899SN/A        panic("RubyTester::getPort: port %d already assigned", idx);
906899SN/A    }
916899SN/A
926899SN/A    CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx);
936899SN/A
946899SN/A    ports[idx] = port;
956899SN/A    return port;
966899SN/A}
976899SN/A
986899SN/ATick
996899SN/ARubyTester::CpuPort::recvAtomic(PacketPtr pkt)
1006899SN/A{
1017053SN/A    panic("RubyTester::CpuPort::recvAtomic() not implemented!\n");
1027053SN/A    return 0;
1036899SN/A}
1046899SN/A
1056899SN/Abool
1066899SN/ARubyTester::CpuPort::recvTiming(PacketPtr pkt)
1076899SN/A{
1087053SN/A    // retrieve the subblock and call hitCallback
1097053SN/A    RubyTester::SenderState* senderState =
1107053SN/A        safe_cast<RubyTester::SenderState*>(pkt->senderState);
1117053SN/A    SubBlock* subblock = senderState->subBlock;
1127053SN/A    assert(subblock != NULL);
1136899SN/A
1147053SN/A    // pop the sender state from the packet
1157053SN/A    pkt->senderState = senderState->saved;
1166899SN/A
1177053SN/A    tester->hitCallback(idx, subblock);
1187053SN/A
1197053SN/A    // Now that the tester has completed, delete the senderState
1207053SN/A    // (includes sublock) and the packet, then return
1217053SN/A    delete senderState;
1227053SN/A    delete pkt->req;
1237053SN/A    delete pkt;
1247053SN/A    return true;
1256899SN/A}
1266899SN/A
1277053SN/APort*
1286899SN/ARubyTester::getCpuPort(int idx)
1296899SN/A{
1307053SN/A    assert(idx >= 0 && idx < ports.size());
1316899SN/A
1327053SN/A    return ports[idx];
1336899SN/A}
1346899SN/A
1357053SN/Avoid
1367053SN/ARubyTester::hitCallback(NodeID proc, SubBlock* data)
1376899SN/A{
1387053SN/A    // Mark that we made progress
1397053SN/A    m_last_progress_vector[proc] = g_eventQueue_ptr->getTime();
1406899SN/A
1417053SN/A    DPRINTF(RubyTest, "completed request for proc: %d\n", proc);
1427053SN/A    DPRINTF(RubyTest, "addr: 0x%x, size: %d, data: ",
1437053SN/A            data->getAddress(), data->getSize());
1447053SN/A    for (int byte = 0; byte < data->getSize(); byte++) {
1457053SN/A        DPRINTF(RubyTest, "%d", data->getByte(byte));
1467053SN/A    }
1477053SN/A    DPRINTF(RubyTest, "\n");
1486899SN/A
1497053SN/A    // This tells us our store has 'completed' or for a load gives us
1507053SN/A    // back the data to make the check
1517053SN/A    Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress());
1527053SN/A    assert(check_ptr != NULL);
1537053SN/A    check_ptr->performCallback(proc, data);
1546899SN/A}
1556899SN/A
1567053SN/Avoid
1577053SN/ARubyTester::wakeup()
1587053SN/A{
1597053SN/A    if (m_checks_completed < m_checks_to_complete) {
1607053SN/A        // Try to perform an action or check
1617053SN/A        Check* check_ptr = m_checkTable_ptr->getRandomCheck();
1627053SN/A        assert(check_ptr != NULL);
1637053SN/A        check_ptr->initiate();
1647053SN/A
1657053SN/A        checkForDeadlock();
1667053SN/A
1677823Ssteve.reinhardt@amd.com        schedule(checkStartEvent, curTick() + m_wakeup_frequency);
1687053SN/A    } else {
1697053SN/A        exitSimLoop("Ruby Tester completed");
1707053SN/A    }
1716899SN/A}
1726899SN/A
1737053SN/Avoid
1747053SN/ARubyTester::checkForDeadlock()
1756899SN/A{
1767053SN/A    int size = m_last_progress_vector.size();
1777053SN/A    Time current_time = g_eventQueue_ptr->getTime();
1787053SN/A    for (int processor = 0; processor < size; processor++) {
1797053SN/A        if ((current_time - m_last_progress_vector[processor]) >
1807053SN/A                m_deadlock_threshold) {
1817805Snilay@cs.wisc.edu            panic("Deadlock detected: current_time: %d last_progress_time: %d "
1827805Snilay@cs.wisc.edu                  "difference:  %d processor: %d\n",
1837805Snilay@cs.wisc.edu                  current_time, m_last_progress_vector[processor],
1847805Snilay@cs.wisc.edu                  current_time - m_last_progress_vector[processor], processor);
1857053SN/A        }
1866899SN/A    }
1876899SN/A}
1886899SN/A
1897053SN/Avoid
1907055SN/ARubyTester::print(std::ostream& out) const
1916899SN/A{
1927055SN/A    out << "[RubyTester]" << std::endl;
1936899SN/A}
1946899SN/A
1956899SN/ARubyTester *
1966899SN/ARubyTesterParams::create()
1976899SN/A{
1986899SN/A    return new RubyTester(this);
1996899SN/A}
200