RubyTester.cc revision 7805
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" 336899SN/A#include "mem/ruby/common/Global.hh" 347053SN/A#include "mem/ruby/common/SubBlock.hh" 357053SN/A#include "mem/ruby/eventqueue/RubyEventQueue.hh" 366899SN/A#include "mem/ruby/system/System.hh" 376899SN/A#include "sim/sim_exit.hh" 386899SN/A 396899SN/ARubyTester::RubyTester(const Params *p) 407053SN/A : MemObject(p), checkStartEvent(this), 416899SN/A m_checks_to_complete(p->checks_to_complete), 426899SN/A m_deadlock_threshold(p->deadlock_threshold), 436899SN/A m_wakeup_frequency(p->wakeup_frequency) 446899SN/A{ 457053SN/A m_checks_completed = 0; 466899SN/A 477053SN/A // add the check start event to the event queue 487053SN/A schedule(checkStartEvent, 1); 496899SN/A} 506899SN/A 516899SN/ARubyTester::~RubyTester() 526899SN/A{ 537053SN/A delete m_checkTable_ptr; 547053SN/A for (int i = 0; i < ports.size(); i++) 557053SN/A delete ports[i]; 566899SN/A} 576899SN/A 587053SN/Avoid 597053SN/ARubyTester::init() 606899SN/A{ 617053SN/A assert(ports.size() > 0); 626899SN/A 637454SN/A m_last_progress_vector.resize(ports.size()); 647053SN/A for (int i = 0; i < m_last_progress_vector.size(); i++) { 657053SN/A m_last_progress_vector[i] = 0; 667053SN/A } 676899SN/A 687053SN/A m_num_cpu_sequencers = ports.size(); 696899SN/A 707053SN/A m_checkTable_ptr = new CheckTable(m_num_cpu_sequencers, this); 716899SN/A} 726899SN/A 736899SN/APort * 746899SN/ARubyTester::getPort(const std::string &if_name, int idx) 756899SN/A{ 766899SN/A if (if_name != "cpuPort") { 776899SN/A panic("RubyTester::getPort: unknown port %s requested", if_name); 786899SN/A } 796899SN/A 806899SN/A if (idx >= (int)ports.size()) { 816899SN/A ports.resize(idx + 1); 826899SN/A } 836899SN/A 846899SN/A if (ports[idx] != NULL) { 856899SN/A panic("RubyTester::getPort: port %d already assigned", idx); 866899SN/A } 876899SN/A 886899SN/A CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx); 896899SN/A 906899SN/A ports[idx] = port; 916899SN/A return port; 926899SN/A} 936899SN/A 946899SN/ATick 956899SN/ARubyTester::CpuPort::recvAtomic(PacketPtr pkt) 966899SN/A{ 977053SN/A panic("RubyTester::CpuPort::recvAtomic() not implemented!\n"); 987053SN/A return 0; 996899SN/A} 1006899SN/A 1016899SN/Abool 1026899SN/ARubyTester::CpuPort::recvTiming(PacketPtr pkt) 1036899SN/A{ 1047053SN/A // retrieve the subblock and call hitCallback 1057053SN/A RubyTester::SenderState* senderState = 1067053SN/A safe_cast<RubyTester::SenderState*>(pkt->senderState); 1077053SN/A SubBlock* subblock = senderState->subBlock; 1087053SN/A assert(subblock != NULL); 1096899SN/A 1107053SN/A // pop the sender state from the packet 1117053SN/A pkt->senderState = senderState->saved; 1126899SN/A 1137053SN/A tester->hitCallback(idx, subblock); 1147053SN/A 1157053SN/A // Now that the tester has completed, delete the senderState 1167053SN/A // (includes sublock) and the packet, then return 1177053SN/A delete senderState; 1187053SN/A delete pkt->req; 1197053SN/A delete pkt; 1207053SN/A return true; 1216899SN/A} 1226899SN/A 1237053SN/APort* 1246899SN/ARubyTester::getCpuPort(int idx) 1256899SN/A{ 1267053SN/A assert(idx >= 0 && idx < ports.size()); 1276899SN/A 1287053SN/A return ports[idx]; 1296899SN/A} 1306899SN/A 1317053SN/Avoid 1327053SN/ARubyTester::hitCallback(NodeID proc, SubBlock* data) 1336899SN/A{ 1347053SN/A // Mark that we made progress 1357053SN/A m_last_progress_vector[proc] = g_eventQueue_ptr->getTime(); 1366899SN/A 1377053SN/A DPRINTF(RubyTest, "completed request for proc: %d\n", proc); 1387053SN/A DPRINTF(RubyTest, "addr: 0x%x, size: %d, data: ", 1397053SN/A data->getAddress(), data->getSize()); 1407053SN/A for (int byte = 0; byte < data->getSize(); byte++) { 1417053SN/A DPRINTF(RubyTest, "%d", data->getByte(byte)); 1427053SN/A } 1437053SN/A DPRINTF(RubyTest, "\n"); 1446899SN/A 1457053SN/A // This tells us our store has 'completed' or for a load gives us 1467053SN/A // back the data to make the check 1477053SN/A Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress()); 1487053SN/A assert(check_ptr != NULL); 1497053SN/A check_ptr->performCallback(proc, data); 1506899SN/A} 1516899SN/A 1527053SN/Avoid 1537053SN/ARubyTester::wakeup() 1547053SN/A{ 1557053SN/A if (m_checks_completed < m_checks_to_complete) { 1567053SN/A // Try to perform an action or check 1577053SN/A Check* check_ptr = m_checkTable_ptr->getRandomCheck(); 1587053SN/A assert(check_ptr != NULL); 1597053SN/A check_ptr->initiate(); 1607053SN/A 1617053SN/A checkForDeadlock(); 1627053SN/A 1637053SN/A schedule(checkStartEvent, curTick + m_wakeup_frequency); 1647053SN/A } else { 1657053SN/A exitSimLoop("Ruby Tester completed"); 1667053SN/A } 1676899SN/A} 1686899SN/A 1697053SN/Avoid 1707053SN/ARubyTester::checkForDeadlock() 1716899SN/A{ 1727053SN/A int size = m_last_progress_vector.size(); 1737053SN/A Time current_time = g_eventQueue_ptr->getTime(); 1747053SN/A for (int processor = 0; processor < size; processor++) { 1757053SN/A if ((current_time - m_last_progress_vector[processor]) > 1767053SN/A m_deadlock_threshold) { 1777805Snilay@cs.wisc.edu panic("Deadlock detected: current_time: %d last_progress_time: %d " 1787805Snilay@cs.wisc.edu "difference: %d processor: %d\n", 1797805Snilay@cs.wisc.edu current_time, m_last_progress_vector[processor], 1807805Snilay@cs.wisc.edu current_time - m_last_progress_vector[processor], processor); 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