RubyTester.cc revision 8851
16899SN/A/*
28851Sandreas.hansson@arm.com * Copyright (c) 2012 ARM Limited
38851Sandreas.hansson@arm.com * All rights reserved
48851Sandreas.hansson@arm.com *
58851Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68851Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78851Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88851Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98851Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108851Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118851Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128851Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138851Sandreas.hansson@arm.com *
146899SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
156899SN/A * Copyright (c) 2009 Advanced Micro Devices, Inc.
166899SN/A * All rights reserved.
176899SN/A *
186899SN/A * Redistribution and use in source and binary forms, with or without
196899SN/A * modification, are permitted provided that the following conditions are
206899SN/A * met: redistributions of source code must retain the above copyright
216899SN/A * notice, this list of conditions and the following disclaimer;
226899SN/A * redistributions in binary form must reproduce the above copyright
236899SN/A * notice, this list of conditions and the following disclaimer in the
246899SN/A * documentation and/or other materials provided with the distribution;
256899SN/A * neither the name of the copyright holders nor the names of its
266899SN/A * contributors may be used to endorse or promote products derived from
276899SN/A * this software without specific prior written permission.
286899SN/A *
296899SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
306899SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
316899SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
326899SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
336899SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
346899SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
356899SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
366899SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
376899SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
386899SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
396899SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
406899SN/A */
416899SN/A
427805Snilay@cs.wisc.edu#include "base/misc.hh"
437632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/Check.hh"
447632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/RubyTester.hh"
458232Snate@binkert.org#include "debug/RubyTest.hh"
466899SN/A#include "mem/ruby/common/Global.hh"
477053SN/A#include "mem/ruby/common/SubBlock.hh"
487053SN/A#include "mem/ruby/eventqueue/RubyEventQueue.hh"
496899SN/A#include "mem/ruby/system/System.hh"
506899SN/A#include "sim/sim_exit.hh"
518832SAli.Saidi@ARM.com#include "sim/system.hh"
526899SN/A
536899SN/ARubyTester::RubyTester(const Params *p)
547053SN/A  : MemObject(p), checkStartEvent(this),
558832SAli.Saidi@ARM.com    _masterId(p->system->getMasterId(name())),
566899SN/A    m_checks_to_complete(p->checks_to_complete),
576899SN/A    m_deadlock_threshold(p->deadlock_threshold),
588184Ssomayeh@cs.wisc.edu    m_wakeup_frequency(p->wakeup_frequency),
598184Ssomayeh@cs.wisc.edu    m_check_flush(p->check_flush)
606899SN/A{
617053SN/A    m_checks_completed = 0;
626899SN/A
638851Sandreas.hansson@arm.com    // create the ports
648851Sandreas.hansson@arm.com    for (int i = 0; i < p->port_cpuPort_connection_count; ++i) {
658851Sandreas.hansson@arm.com        ports.push_back(new CpuPort(csprintf("%s-port%d", name(), i),
668851Sandreas.hansson@arm.com                                    this, i));
678851Sandreas.hansson@arm.com    }
688851Sandreas.hansson@arm.com
697053SN/A    // add the check start event to the event queue
707053SN/A    schedule(checkStartEvent, 1);
716899SN/A}
726899SN/A
736899SN/ARubyTester::~RubyTester()
746899SN/A{
757053SN/A    delete m_checkTable_ptr;
767053SN/A    for (int i = 0; i < ports.size(); i++)
777053SN/A        delete ports[i];
786899SN/A}
796899SN/A
807053SN/Avoid
817053SN/ARubyTester::init()
826899SN/A{
837053SN/A    assert(ports.size() > 0);
846899SN/A
857454SN/A    m_last_progress_vector.resize(ports.size());
867053SN/A    for (int i = 0; i < m_last_progress_vector.size(); i++) {
877053SN/A        m_last_progress_vector[i] = 0;
887053SN/A    }
896899SN/A
907053SN/A    m_num_cpu_sequencers = ports.size();
916899SN/A
927053SN/A    m_checkTable_ptr = new CheckTable(m_num_cpu_sequencers, this);
936899SN/A}
946899SN/A
956899SN/APort *
966899SN/ARubyTester::getPort(const std::string &if_name, int idx)
976899SN/A{
986899SN/A    if (if_name != "cpuPort") {
998851Sandreas.hansson@arm.com        panic("RubyTester::getPort: unknown port %s requested\n", if_name);
1006899SN/A    }
1016899SN/A
1028851Sandreas.hansson@arm.com    if (idx >= static_cast<int>(ports.size())) {
1038851Sandreas.hansson@arm.com        panic("RubyTester::getPort: unknown index %d requested\n", idx);
1046899SN/A    }
1056899SN/A
1068851Sandreas.hansson@arm.com    return ports[idx];
1076899SN/A}
1086899SN/A
1096899SN/ATick
1106899SN/ARubyTester::CpuPort::recvAtomic(PacketPtr pkt)
1116899SN/A{
1127053SN/A    panic("RubyTester::CpuPort::recvAtomic() not implemented!\n");
1137053SN/A    return 0;
1146899SN/A}
1156899SN/A
1166899SN/Abool
1176899SN/ARubyTester::CpuPort::recvTiming(PacketPtr pkt)
1186899SN/A{
1197053SN/A    // retrieve the subblock and call hitCallback
1207053SN/A    RubyTester::SenderState* senderState =
1217053SN/A        safe_cast<RubyTester::SenderState*>(pkt->senderState);
1227053SN/A    SubBlock* subblock = senderState->subBlock;
1237053SN/A    assert(subblock != NULL);
1246899SN/A
1257053SN/A    // pop the sender state from the packet
1267053SN/A    pkt->senderState = senderState->saved;
1276899SN/A
1287053SN/A    tester->hitCallback(idx, subblock);
1297053SN/A
1307053SN/A    // Now that the tester has completed, delete the senderState
1317053SN/A    // (includes sublock) and the packet, then return
1327053SN/A    delete senderState;
1337053SN/A    delete pkt->req;
1347053SN/A    delete pkt;
1357053SN/A    return true;
1366899SN/A}
1376899SN/A
1387053SN/APort*
1396899SN/ARubyTester::getCpuPort(int idx)
1406899SN/A{
1417053SN/A    assert(idx >= 0 && idx < ports.size());
1426899SN/A
1437053SN/A    return ports[idx];
1446899SN/A}
1456899SN/A
1467053SN/Avoid
1477053SN/ARubyTester::hitCallback(NodeID proc, SubBlock* data)
1486899SN/A{
1497053SN/A    // Mark that we made progress
1507053SN/A    m_last_progress_vector[proc] = g_eventQueue_ptr->getTime();
1516899SN/A
1527053SN/A    DPRINTF(RubyTest, "completed request for proc: %d\n", proc);
1537053SN/A    DPRINTF(RubyTest, "addr: 0x%x, size: %d, data: ",
1547053SN/A            data->getAddress(), data->getSize());
1557053SN/A    for (int byte = 0; byte < data->getSize(); byte++) {
1567053SN/A        DPRINTF(RubyTest, "%d", data->getByte(byte));
1577053SN/A    }
1587053SN/A    DPRINTF(RubyTest, "\n");
1596899SN/A
1607053SN/A    // This tells us our store has 'completed' or for a load gives us
1617053SN/A    // back the data to make the check
1627053SN/A    Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress());
1637053SN/A    assert(check_ptr != NULL);
1647053SN/A    check_ptr->performCallback(proc, data);
1656899SN/A}
1666899SN/A
1677053SN/Avoid
1687053SN/ARubyTester::wakeup()
1697053SN/A{
1707053SN/A    if (m_checks_completed < m_checks_to_complete) {
1717053SN/A        // Try to perform an action or check
1727053SN/A        Check* check_ptr = m_checkTable_ptr->getRandomCheck();
1737053SN/A        assert(check_ptr != NULL);
1747053SN/A        check_ptr->initiate();
1757053SN/A
1767053SN/A        checkForDeadlock();
1777053SN/A
1787823Ssteve.reinhardt@amd.com        schedule(checkStartEvent, curTick() + m_wakeup_frequency);
1797053SN/A    } else {
1807053SN/A        exitSimLoop("Ruby Tester completed");
1817053SN/A    }
1826899SN/A}
1836899SN/A
1847053SN/Avoid
1857053SN/ARubyTester::checkForDeadlock()
1866899SN/A{
1877053SN/A    int size = m_last_progress_vector.size();
1887053SN/A    Time current_time = g_eventQueue_ptr->getTime();
1897053SN/A    for (int processor = 0; processor < size; processor++) {
1907053SN/A        if ((current_time - m_last_progress_vector[processor]) >
1917053SN/A                m_deadlock_threshold) {
1927805Snilay@cs.wisc.edu            panic("Deadlock detected: current_time: %d last_progress_time: %d "
1937805Snilay@cs.wisc.edu                  "difference:  %d processor: %d\n",
1947805Snilay@cs.wisc.edu                  current_time, m_last_progress_vector[processor],
1957805Snilay@cs.wisc.edu                  current_time - m_last_progress_vector[processor], processor);
1967053SN/A        }
1976899SN/A    }
1986899SN/A}
1996899SN/A
2007053SN/Avoid
2017055SN/ARubyTester::print(std::ostream& out) const
2026899SN/A{
2037055SN/A    out << "[RubyTester]" << std::endl;
2046899SN/A}
2056899SN/A
2066899SN/ARubyTester *
2076899SN/ARubyTesterParams::create()
2086899SN/A{
2096899SN/A    return new RubyTester(this);
2106899SN/A}
211