RubyTester.cc revision 7632
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
307632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/Check.hh"
317632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/RubyTester.hh"
326899SN/A#include "mem/ruby/common/Global.hh"
337053SN/A#include "mem/ruby/common/SubBlock.hh"
347053SN/A#include "mem/ruby/eventqueue/RubyEventQueue.hh"
356899SN/A#include "mem/ruby/system/System.hh"
366899SN/A#include "sim/sim_exit.hh"
376899SN/A
386899SN/ARubyTester::RubyTester(const Params *p)
397053SN/A  : MemObject(p), checkStartEvent(this),
406899SN/A    m_checks_to_complete(p->checks_to_complete),
416899SN/A    m_deadlock_threshold(p->deadlock_threshold),
426899SN/A    m_wakeup_frequency(p->wakeup_frequency)
436899SN/A{
447053SN/A    m_checks_completed = 0;
456899SN/A
467053SN/A    // add the check start event to the event queue
477053SN/A    schedule(checkStartEvent, 1);
486899SN/A}
496899SN/A
506899SN/ARubyTester::~RubyTester()
516899SN/A{
527053SN/A    delete m_checkTable_ptr;
537053SN/A    for (int i = 0; i < ports.size(); i++)
547053SN/A        delete ports[i];
556899SN/A}
566899SN/A
577053SN/Avoid
587053SN/ARubyTester::init()
596899SN/A{
607053SN/A    assert(ports.size() > 0);
616899SN/A
627454SN/A    m_last_progress_vector.resize(ports.size());
637053SN/A    for (int i = 0; i < m_last_progress_vector.size(); i++) {
647053SN/A        m_last_progress_vector[i] = 0;
657053SN/A    }
666899SN/A
677053SN/A    m_num_cpu_sequencers = ports.size();
686899SN/A
697053SN/A    m_checkTable_ptr = new CheckTable(m_num_cpu_sequencers, this);
706899SN/A}
716899SN/A
726899SN/APort *
736899SN/ARubyTester::getPort(const std::string &if_name, int idx)
746899SN/A{
756899SN/A    if (if_name != "cpuPort") {
766899SN/A        panic("RubyTester::getPort: unknown port %s requested", if_name);
776899SN/A    }
786899SN/A
796899SN/A    if (idx >= (int)ports.size()) {
806899SN/A        ports.resize(idx + 1);
816899SN/A    }
826899SN/A
836899SN/A    if (ports[idx] != NULL) {
846899SN/A        panic("RubyTester::getPort: port %d already assigned", idx);
856899SN/A    }
866899SN/A
876899SN/A    CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx);
886899SN/A
896899SN/A    ports[idx] = port;
906899SN/A    return port;
916899SN/A}
926899SN/A
936899SN/ATick
946899SN/ARubyTester::CpuPort::recvAtomic(PacketPtr pkt)
956899SN/A{
967053SN/A    panic("RubyTester::CpuPort::recvAtomic() not implemented!\n");
977053SN/A    return 0;
986899SN/A}
996899SN/A
1006899SN/Abool
1016899SN/ARubyTester::CpuPort::recvTiming(PacketPtr pkt)
1026899SN/A{
1037053SN/A    // retrieve the subblock and call hitCallback
1047053SN/A    RubyTester::SenderState* senderState =
1057053SN/A        safe_cast<RubyTester::SenderState*>(pkt->senderState);
1067053SN/A    SubBlock* subblock = senderState->subBlock;
1077053SN/A    assert(subblock != NULL);
1086899SN/A
1097053SN/A    // pop the sender state from the packet
1107053SN/A    pkt->senderState = senderState->saved;
1116899SN/A
1127053SN/A    tester->hitCallback(idx, subblock);
1137053SN/A
1147053SN/A    // Now that the tester has completed, delete the senderState
1157053SN/A    // (includes sublock) and the packet, then return
1167053SN/A    delete senderState;
1177053SN/A    delete pkt->req;
1187053SN/A    delete pkt;
1197053SN/A    return true;
1206899SN/A}
1216899SN/A
1227053SN/APort*
1236899SN/ARubyTester::getCpuPort(int idx)
1246899SN/A{
1257053SN/A    assert(idx >= 0 && idx < ports.size());
1266899SN/A
1277053SN/A    return ports[idx];
1286899SN/A}
1296899SN/A
1307053SN/Avoid
1317053SN/ARubyTester::hitCallback(NodeID proc, SubBlock* data)
1326899SN/A{
1337053SN/A    // Mark that we made progress
1347053SN/A    m_last_progress_vector[proc] = g_eventQueue_ptr->getTime();
1356899SN/A
1367053SN/A    DPRINTF(RubyTest, "completed request for proc: %d\n", proc);
1377053SN/A    DPRINTF(RubyTest, "addr: 0x%x, size: %d, data: ",
1387053SN/A            data->getAddress(), data->getSize());
1397053SN/A    for (int byte = 0; byte < data->getSize(); byte++) {
1407053SN/A        DPRINTF(RubyTest, "%d", data->getByte(byte));
1417053SN/A    }
1427053SN/A    DPRINTF(RubyTest, "\n");
1436899SN/A
1447053SN/A    // This tells us our store has 'completed' or for a load gives us
1457053SN/A    // back the data to make the check
1467053SN/A    Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress());
1477053SN/A    assert(check_ptr != NULL);
1487053SN/A    check_ptr->performCallback(proc, data);
1496899SN/A}
1506899SN/A
1517053SN/Avoid
1527053SN/ARubyTester::wakeup()
1537053SN/A{
1547053SN/A    if (m_checks_completed < m_checks_to_complete) {
1557053SN/A        // Try to perform an action or check
1567053SN/A        Check* check_ptr = m_checkTable_ptr->getRandomCheck();
1577053SN/A        assert(check_ptr != NULL);
1587053SN/A        check_ptr->initiate();
1597053SN/A
1607053SN/A        checkForDeadlock();
1617053SN/A
1627053SN/A        schedule(checkStartEvent, curTick + m_wakeup_frequency);
1637053SN/A    } else {
1647053SN/A        exitSimLoop("Ruby Tester completed");
1657053SN/A    }
1666899SN/A}
1676899SN/A
1687053SN/Avoid
1697053SN/ARubyTester::checkForDeadlock()
1706899SN/A{
1717053SN/A    int size = m_last_progress_vector.size();
1727053SN/A    Time current_time = g_eventQueue_ptr->getTime();
1737053SN/A    for (int processor = 0; processor < size; processor++) {
1747053SN/A        if ((current_time - m_last_progress_vector[processor]) >
1757053SN/A                m_deadlock_threshold) {
1767053SN/A            WARN_EXPR(current_time);
1777053SN/A            WARN_EXPR(m_last_progress_vector[processor]);
1787053SN/A            WARN_EXPR(current_time - m_last_progress_vector[processor]);
1797053SN/A            WARN_EXPR(processor);
1807053SN/A            ERROR_MSG("Deadlock detected.");
1817053SN/A        }
1826899SN/A    }
1836899SN/A}
1846899SN/A
1857053SN/Avoid
1867055SN/ARubyTester::print(std::ostream& out) const
1876899SN/A{
1887055SN/A    out << "[RubyTester]" << std::endl;
1896899SN/A}
1906899SN/A
1916899SN/ARubyTester *
1926899SN/ARubyTesterParams::create()
1936899SN/A{
1946899SN/A    return new RubyTester(this);
1956899SN/A}
196