RubyTester.cc revision 11800
16899SN/A/* 29542Sandreas.hansson@arm.com * Copyright (c) 2012-2013 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 4211793Sbrandon.potter@amd.com#include "cpu/testers/rubytest/RubyTester.hh" 4311793Sbrandon.potter@amd.com 447805Snilay@cs.wisc.edu#include "base/misc.hh" 4511800Sbrandon.potter@amd.com#include "base/trace.hh" 467632SBrad.Beckmann@amd.com#include "cpu/testers/rubytest/Check.hh" 478232Snate@binkert.org#include "debug/RubyTest.hh" 487053SN/A#include "mem/ruby/common/SubBlock.hh" 496899SN/A#include "sim/sim_exit.hh" 508832SAli.Saidi@ARM.com#include "sim/system.hh" 516899SN/A 526899SN/ARubyTester::RubyTester(const Params *p) 537053SN/A : MemObject(p), checkStartEvent(this), 548832SAli.Saidi@ARM.com _masterId(p->system->getMasterId(name())), 5510412Sandreas.hansson@arm.com m_checkTable_ptr(nullptr), 568932SBrad.Beckmann@amd.com m_num_cpus(p->num_cpus), 576899SN/A m_checks_to_complete(p->checks_to_complete), 586899SN/A m_deadlock_threshold(p->deadlock_threshold), 5910412Sandreas.hansson@arm.com m_num_writers(0), 6010412Sandreas.hansson@arm.com m_num_readers(0), 618184Ssomayeh@cs.wisc.edu m_wakeup_frequency(p->wakeup_frequency), 628932SBrad.Beckmann@amd.com m_check_flush(p->check_flush), 6311266SBrad.Beckmann@amd.com m_num_inst_only_ports(p->port_cpuInstPort_connection_count), 6411266SBrad.Beckmann@amd.com m_num_inst_data_ports(p->port_cpuInstDataPort_connection_count) 656899SN/A{ 667053SN/A m_checks_completed = 0; 676899SN/A 688932SBrad.Beckmann@amd.com // 698932SBrad.Beckmann@amd.com // Create the requested inst and data ports and place them on the 708932SBrad.Beckmann@amd.com // appropriate read and write port lists. The reason for the subtle 718932SBrad.Beckmann@amd.com // difference between inst and data ports vs. read and write ports is 728932SBrad.Beckmann@amd.com // from the tester's perspective, it only needs to know whether a port 738932SBrad.Beckmann@amd.com // supports reads (checks) or writes (actions). Meanwhile, the protocol 748932SBrad.Beckmann@amd.com // controllers have data ports (support read and writes) or inst ports 758932SBrad.Beckmann@amd.com // (support only reads). 768932SBrad.Beckmann@amd.com // Note: the inst ports are the lowest elements of the readPort vector, 778932SBrad.Beckmann@amd.com // then the data ports are added to the readPort vector 788932SBrad.Beckmann@amd.com // 7911266SBrad.Beckmann@amd.com int idx = 0; 808932SBrad.Beckmann@amd.com for (int i = 0; i < p->port_cpuInstPort_connection_count; ++i) { 818932SBrad.Beckmann@amd.com readPorts.push_back(new CpuPort(csprintf("%s-instPort%d", name(), i), 8211266SBrad.Beckmann@amd.com this, i, idx)); 8311266SBrad.Beckmann@amd.com idx++; 8411266SBrad.Beckmann@amd.com } 8511266SBrad.Beckmann@amd.com for (int i = 0; i < p->port_cpuInstDataPort_connection_count; ++i) { 8611266SBrad.Beckmann@amd.com CpuPort *port = new CpuPort(csprintf("%s-instDataPort%d", name(), i), 8711266SBrad.Beckmann@amd.com this, i, idx); 8811266SBrad.Beckmann@amd.com readPorts.push_back(port); 8911266SBrad.Beckmann@amd.com writePorts.push_back(port); 9011266SBrad.Beckmann@amd.com idx++; 918932SBrad.Beckmann@amd.com } 928932SBrad.Beckmann@amd.com for (int i = 0; i < p->port_cpuDataPort_connection_count; ++i) { 938950Sandreas.hansson@arm.com CpuPort *port = new CpuPort(csprintf("%s-dataPort%d", name(), i), 9411266SBrad.Beckmann@amd.com this, i, idx); 958932SBrad.Beckmann@amd.com readPorts.push_back(port); 968932SBrad.Beckmann@amd.com writePorts.push_back(port); 9711266SBrad.Beckmann@amd.com idx++; 988851Sandreas.hansson@arm.com } 998851Sandreas.hansson@arm.com 1007053SN/A // add the check start event to the event queue 1017053SN/A schedule(checkStartEvent, 1); 1026899SN/A} 1036899SN/A 1046899SN/ARubyTester::~RubyTester() 1056899SN/A{ 1067053SN/A delete m_checkTable_ptr; 1078932SBrad.Beckmann@amd.com // Only delete the readPorts since the writePorts are just a subset 1088932SBrad.Beckmann@amd.com for (int i = 0; i < readPorts.size(); i++) 1098932SBrad.Beckmann@amd.com delete readPorts[i]; 1106899SN/A} 1116899SN/A 1127053SN/Avoid 1137053SN/ARubyTester::init() 1146899SN/A{ 1158932SBrad.Beckmann@amd.com assert(writePorts.size() > 0 && readPorts.size() > 0); 1166899SN/A 1178932SBrad.Beckmann@amd.com m_last_progress_vector.resize(m_num_cpus); 1187053SN/A for (int i = 0; i < m_last_progress_vector.size(); i++) { 11910302Snilay@cs.wisc.edu m_last_progress_vector[i] = Cycles(0); 1207053SN/A } 1216899SN/A 1228932SBrad.Beckmann@amd.com m_num_writers = writePorts.size(); 1238932SBrad.Beckmann@amd.com m_num_readers = readPorts.size(); 12411266SBrad.Beckmann@amd.com assert(m_num_readers == m_num_cpus); 1256899SN/A 1268932SBrad.Beckmann@amd.com m_checkTable_ptr = new CheckTable(m_num_writers, m_num_readers, this); 1276899SN/A} 1286899SN/A 1299294Sandreas.hansson@arm.comBaseMasterPort & 1309294Sandreas.hansson@arm.comRubyTester::getMasterPort(const std::string &if_name, PortID idx) 1316899SN/A{ 13211266SBrad.Beckmann@amd.com if (if_name != "cpuInstPort" && if_name != "cpuInstDataPort" && 13311266SBrad.Beckmann@amd.com if_name != "cpuDataPort") { 1348922Swilliam.wang@arm.com // pass it along to our super class 1358922Swilliam.wang@arm.com return MemObject::getMasterPort(if_name, idx); 1368922Swilliam.wang@arm.com } else { 1378932SBrad.Beckmann@amd.com if (if_name == "cpuInstPort") { 13811266SBrad.Beckmann@amd.com if (idx > m_num_inst_only_ports) { 13911266SBrad.Beckmann@amd.com panic("RubyTester::getMasterPort: unknown inst port %d\n", 1408932SBrad.Beckmann@amd.com idx); 1418932SBrad.Beckmann@amd.com } 1428932SBrad.Beckmann@amd.com // 14311266SBrad.Beckmann@amd.com // inst ports map to the lowest readPort elements 1448932SBrad.Beckmann@amd.com // 1458932SBrad.Beckmann@amd.com return *readPorts[idx]; 14611266SBrad.Beckmann@amd.com } else if (if_name == "cpuInstDataPort") { 14711266SBrad.Beckmann@amd.com if (idx > m_num_inst_data_ports) { 14811266SBrad.Beckmann@amd.com panic("RubyTester::getMasterPort: unknown inst+data port %d\n", 14911266SBrad.Beckmann@amd.com idx); 15011266SBrad.Beckmann@amd.com } 15111266SBrad.Beckmann@amd.com int read_idx = idx + m_num_inst_only_ports; 15211266SBrad.Beckmann@amd.com // 15311266SBrad.Beckmann@amd.com // inst+data ports map to the next readPort elements 15411266SBrad.Beckmann@amd.com // 15511266SBrad.Beckmann@amd.com return *readPorts[read_idx]; 1568932SBrad.Beckmann@amd.com } else { 1578932SBrad.Beckmann@amd.com assert(if_name == "cpuDataPort"); 1588932SBrad.Beckmann@amd.com // 15911266SBrad.Beckmann@amd.com // data only ports map to the final readPort elements 1608932SBrad.Beckmann@amd.com // 16111266SBrad.Beckmann@amd.com if (idx > (static_cast<int>(readPorts.size()) - 16211266SBrad.Beckmann@amd.com (m_num_inst_only_ports + m_num_inst_data_ports))) { 16311266SBrad.Beckmann@amd.com panic("RubyTester::getMasterPort: unknown data port %d\n", 1648932SBrad.Beckmann@amd.com idx); 1658932SBrad.Beckmann@amd.com } 16611266SBrad.Beckmann@amd.com int read_idx = idx + m_num_inst_only_ports + m_num_inst_data_ports; 1678932SBrad.Beckmann@amd.com return *readPorts[read_idx]; 1688922Swilliam.wang@arm.com } 16911266SBrad.Beckmann@amd.com // Note: currently the Ruby Tester does not support write only ports 17011266SBrad.Beckmann@amd.com // but that could easily be added here 1716899SN/A } 1726899SN/A} 1736899SN/A 1746899SN/Abool 1758975Sandreas.hansson@arm.comRubyTester::CpuPort::recvTimingResp(PacketPtr pkt) 1766899SN/A{ 1777053SN/A // retrieve the subblock and call hitCallback 1787053SN/A RubyTester::SenderState* senderState = 1797053SN/A safe_cast<RubyTester::SenderState*>(pkt->senderState); 1809542Sandreas.hansson@arm.com SubBlock& subblock = senderState->subBlock; 1816899SN/A 18211266SBrad.Beckmann@amd.com tester->hitCallback(globalIdx, &subblock); 1837053SN/A 1847053SN/A // Now that the tester has completed, delete the senderState 1857053SN/A // (includes sublock) and the packet, then return 1869542Sandreas.hansson@arm.com delete pkt->senderState; 1877053SN/A delete pkt->req; 1887053SN/A delete pkt; 1897053SN/A return true; 1906899SN/A} 1916899SN/A 1928950Sandreas.hansson@arm.combool 19311266SBrad.Beckmann@amd.comRubyTester::isInstOnlyCpuPort(int idx) 1948950Sandreas.hansson@arm.com{ 19511266SBrad.Beckmann@amd.com return idx < m_num_inst_only_ports; 19611266SBrad.Beckmann@amd.com} 19711266SBrad.Beckmann@amd.com 19811266SBrad.Beckmann@amd.combool 19911266SBrad.Beckmann@amd.comRubyTester::isInstDataCpuPort(int idx) 20011266SBrad.Beckmann@amd.com{ 20111266SBrad.Beckmann@amd.com return ((idx >= m_num_inst_only_ports) && 20211266SBrad.Beckmann@amd.com (idx < (m_num_inst_only_ports + m_num_inst_data_ports))); 2038950Sandreas.hansson@arm.com} 2048950Sandreas.hansson@arm.com 2058922Swilliam.wang@arm.comMasterPort* 2068932SBrad.Beckmann@amd.comRubyTester::getReadableCpuPort(int idx) 2076899SN/A{ 2088932SBrad.Beckmann@amd.com assert(idx >= 0 && idx < readPorts.size()); 2096899SN/A 2108932SBrad.Beckmann@amd.com return readPorts[idx]; 2118932SBrad.Beckmann@amd.com} 2128932SBrad.Beckmann@amd.com 2138932SBrad.Beckmann@amd.comMasterPort* 2148932SBrad.Beckmann@amd.comRubyTester::getWritableCpuPort(int idx) 2158932SBrad.Beckmann@amd.com{ 2168932SBrad.Beckmann@amd.com assert(idx >= 0 && idx < writePorts.size()); 2178932SBrad.Beckmann@amd.com 2188932SBrad.Beckmann@amd.com return writePorts[idx]; 2196899SN/A} 2206899SN/A 2217053SN/Avoid 2227053SN/ARubyTester::hitCallback(NodeID proc, SubBlock* data) 2236899SN/A{ 2247053SN/A // Mark that we made progress 2259475Snilay@cs.wisc.edu m_last_progress_vector[proc] = curCycle(); 2266899SN/A 22711266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "completed request for proc: %d", proc); 22811266SBrad.Beckmann@amd.com DPRINTFR(RubyTest, " addr: 0x%x, size: %d, data: ", 2297053SN/A data->getAddress(), data->getSize()); 2307053SN/A for (int byte = 0; byte < data->getSize(); byte++) { 23111266SBrad.Beckmann@amd.com DPRINTFR(RubyTest, "%d ", data->getByte(byte)); 2327053SN/A } 23311266SBrad.Beckmann@amd.com DPRINTFR(RubyTest, "\n"); 2346899SN/A 2357053SN/A // This tells us our store has 'completed' or for a load gives us 2367053SN/A // back the data to make the check 2377053SN/A Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress()); 2387053SN/A assert(check_ptr != NULL); 2399475Snilay@cs.wisc.edu check_ptr->performCallback(proc, data, curCycle()); 2406899SN/A} 2416899SN/A 2427053SN/Avoid 2437053SN/ARubyTester::wakeup() 2447053SN/A{ 2457053SN/A if (m_checks_completed < m_checks_to_complete) { 2467053SN/A // Try to perform an action or check 2477053SN/A Check* check_ptr = m_checkTable_ptr->getRandomCheck(); 2487053SN/A assert(check_ptr != NULL); 2497053SN/A check_ptr->initiate(); 2507053SN/A 2517053SN/A checkForDeadlock(); 2527053SN/A 2537823Ssteve.reinhardt@amd.com schedule(checkStartEvent, curTick() + m_wakeup_frequency); 2547053SN/A } else { 2557053SN/A exitSimLoop("Ruby Tester completed"); 2567053SN/A } 2576899SN/A} 2586899SN/A 2597053SN/Avoid 2607053SN/ARubyTester::checkForDeadlock() 2616899SN/A{ 2627053SN/A int size = m_last_progress_vector.size(); 26310302Snilay@cs.wisc.edu Cycles current_time = curCycle(); 2647053SN/A for (int processor = 0; processor < size; processor++) { 2657053SN/A if ((current_time - m_last_progress_vector[processor]) > 2667053SN/A m_deadlock_threshold) { 2677805Snilay@cs.wisc.edu panic("Deadlock detected: current_time: %d last_progress_time: %d " 2687805Snilay@cs.wisc.edu "difference: %d processor: %d\n", 2697805Snilay@cs.wisc.edu current_time, m_last_progress_vector[processor], 2707805Snilay@cs.wisc.edu current_time - m_last_progress_vector[processor], processor); 2717053SN/A } 2726899SN/A } 2736899SN/A} 2746899SN/A 2757053SN/Avoid 2767055SN/ARubyTester::print(std::ostream& out) const 2776899SN/A{ 2787055SN/A out << "[RubyTester]" << std::endl; 2796899SN/A} 2806899SN/A 2816899SN/ARubyTester * 2826899SN/ARubyTesterParams::create() 2836899SN/A{ 2846899SN/A return new RubyTester(this); 2856899SN/A} 286