RubyTester.cc revision 8184
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), 438184Ssomayeh@cs.wisc.edu m_wakeup_frequency(p->wakeup_frequency), 448184Ssomayeh@cs.wisc.edu m_check_flush(p->check_flush) 456899SN/A{ 467053SN/A m_checks_completed = 0; 476899SN/A 487053SN/A // add the check start event to the event queue 497053SN/A schedule(checkStartEvent, 1); 506899SN/A} 516899SN/A 526899SN/ARubyTester::~RubyTester() 536899SN/A{ 547053SN/A delete m_checkTable_ptr; 557053SN/A for (int i = 0; i < ports.size(); i++) 567053SN/A delete ports[i]; 576899SN/A} 586899SN/A 597053SN/Avoid 607053SN/ARubyTester::init() 616899SN/A{ 627053SN/A assert(ports.size() > 0); 636899SN/A 647454SN/A m_last_progress_vector.resize(ports.size()); 657053SN/A for (int i = 0; i < m_last_progress_vector.size(); i++) { 667053SN/A m_last_progress_vector[i] = 0; 677053SN/A } 686899SN/A 697053SN/A m_num_cpu_sequencers = ports.size(); 706899SN/A 717053SN/A m_checkTable_ptr = new CheckTable(m_num_cpu_sequencers, this); 726899SN/A} 736899SN/A 746899SN/APort * 756899SN/ARubyTester::getPort(const std::string &if_name, int idx) 766899SN/A{ 776899SN/A if (if_name != "cpuPort") { 786899SN/A panic("RubyTester::getPort: unknown port %s requested", if_name); 796899SN/A } 806899SN/A 816899SN/A if (idx >= (int)ports.size()) { 826899SN/A ports.resize(idx + 1); 836899SN/A } 846899SN/A 856899SN/A if (ports[idx] != NULL) { 866899SN/A panic("RubyTester::getPort: port %d already assigned", idx); 876899SN/A } 886899SN/A 896899SN/A CpuPort *port = new CpuPort(csprintf("%s-port%d", name(), idx), this, idx); 906899SN/A 916899SN/A ports[idx] = port; 926899SN/A return port; 936899SN/A} 946899SN/A 956899SN/ATick 966899SN/ARubyTester::CpuPort::recvAtomic(PacketPtr pkt) 976899SN/A{ 987053SN/A panic("RubyTester::CpuPort::recvAtomic() not implemented!\n"); 997053SN/A return 0; 1006899SN/A} 1016899SN/A 1026899SN/Abool 1036899SN/ARubyTester::CpuPort::recvTiming(PacketPtr pkt) 1046899SN/A{ 1057053SN/A // retrieve the subblock and call hitCallback 1067053SN/A RubyTester::SenderState* senderState = 1077053SN/A safe_cast<RubyTester::SenderState*>(pkt->senderState); 1087053SN/A SubBlock* subblock = senderState->subBlock; 1097053SN/A assert(subblock != NULL); 1106899SN/A 1117053SN/A // pop the sender state from the packet 1127053SN/A pkt->senderState = senderState->saved; 1136899SN/A 1147053SN/A tester->hitCallback(idx, subblock); 1157053SN/A 1167053SN/A // Now that the tester has completed, delete the senderState 1177053SN/A // (includes sublock) and the packet, then return 1187053SN/A delete senderState; 1197053SN/A delete pkt->req; 1207053SN/A delete pkt; 1217053SN/A return true; 1226899SN/A} 1236899SN/A 1247053SN/APort* 1256899SN/ARubyTester::getCpuPort(int idx) 1266899SN/A{ 1277053SN/A assert(idx >= 0 && idx < ports.size()); 1286899SN/A 1297053SN/A return ports[idx]; 1306899SN/A} 1316899SN/A 1327053SN/Avoid 1337053SN/ARubyTester::hitCallback(NodeID proc, SubBlock* data) 1346899SN/A{ 1357053SN/A // Mark that we made progress 1367053SN/A m_last_progress_vector[proc] = g_eventQueue_ptr->getTime(); 1376899SN/A 1387053SN/A DPRINTF(RubyTest, "completed request for proc: %d\n", proc); 1397053SN/A DPRINTF(RubyTest, "addr: 0x%x, size: %d, data: ", 1407053SN/A data->getAddress(), data->getSize()); 1417053SN/A for (int byte = 0; byte < data->getSize(); byte++) { 1427053SN/A DPRINTF(RubyTest, "%d", data->getByte(byte)); 1437053SN/A } 1447053SN/A DPRINTF(RubyTest, "\n"); 1456899SN/A 1467053SN/A // This tells us our store has 'completed' or for a load gives us 1477053SN/A // back the data to make the check 1487053SN/A Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress()); 1497053SN/A assert(check_ptr != NULL); 1507053SN/A check_ptr->performCallback(proc, data); 1516899SN/A} 1526899SN/A 1537053SN/Avoid 1547053SN/ARubyTester::wakeup() 1557053SN/A{ 1567053SN/A if (m_checks_completed < m_checks_to_complete) { 1577053SN/A // Try to perform an action or check 1587053SN/A Check* check_ptr = m_checkTable_ptr->getRandomCheck(); 1597053SN/A assert(check_ptr != NULL); 1607053SN/A check_ptr->initiate(); 1617053SN/A 1627053SN/A checkForDeadlock(); 1637053SN/A 1647823Ssteve.reinhardt@amd.com schedule(checkStartEvent, curTick() + m_wakeup_frequency); 1657053SN/A } else { 1667053SN/A exitSimLoop("Ruby Tester completed"); 1677053SN/A } 1686899SN/A} 1696899SN/A 1707053SN/Avoid 1717053SN/ARubyTester::checkForDeadlock() 1726899SN/A{ 1737053SN/A int size = m_last_progress_vector.size(); 1747053SN/A Time current_time = g_eventQueue_ptr->getTime(); 1757053SN/A for (int processor = 0; processor < size; processor++) { 1767053SN/A if ((current_time - m_last_progress_vector[processor]) > 1777053SN/A m_deadlock_threshold) { 1787805Snilay@cs.wisc.edu panic("Deadlock detected: current_time: %d last_progress_time: %d " 1797805Snilay@cs.wisc.edu "difference: %d processor: %d\n", 1807805Snilay@cs.wisc.edu current_time, m_last_progress_vector[processor], 1817805Snilay@cs.wisc.edu current_time - m_last_progress_vector[processor], processor); 1827053SN/A } 1836899SN/A } 1846899SN/A} 1856899SN/A 1867053SN/Avoid 1877055SN/ARubyTester::print(std::ostream& out) const 1886899SN/A{ 1897055SN/A out << "[RubyTester]" << std::endl; 1906899SN/A} 1916899SN/A 1926899SN/ARubyTester * 1936899SN/ARubyTesterParams::create() 1946899SN/A{ 1956899SN/A return new RubyTester(this); 1966899SN/A} 197