RubyTester.cc revision 8851
1/* 2 * Copyright (c) 2012 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 15 * Copyright (c) 2009 Advanced Micro Devices, Inc. 16 * All rights reserved. 17 * 18 * Redistribution and use in source and binary forms, with or without 19 * modification, are permitted provided that the following conditions are 20 * met: redistributions of source code must retain the above copyright 21 * notice, this list of conditions and the following disclaimer; 22 * redistributions in binary form must reproduce the above copyright 23 * notice, this list of conditions and the following disclaimer in the 24 * documentation and/or other materials provided with the distribution; 25 * neither the name of the copyright holders nor the names of its 26 * contributors may be used to endorse or promote products derived from 27 * this software without specific prior written permission. 28 * 29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 40 */ 41 42#include "base/misc.hh" 43#include "cpu/testers/rubytest/Check.hh" 44#include "cpu/testers/rubytest/RubyTester.hh" 45#include "debug/RubyTest.hh" 46#include "mem/ruby/common/Global.hh" 47#include "mem/ruby/common/SubBlock.hh" 48#include "mem/ruby/eventqueue/RubyEventQueue.hh" 49#include "mem/ruby/system/System.hh" 50#include "sim/sim_exit.hh" 51#include "sim/system.hh" 52 53RubyTester::RubyTester(const Params *p) 54 : MemObject(p), checkStartEvent(this), 55 _masterId(p->system->getMasterId(name())), 56 m_checks_to_complete(p->checks_to_complete), 57 m_deadlock_threshold(p->deadlock_threshold), 58 m_wakeup_frequency(p->wakeup_frequency), 59 m_check_flush(p->check_flush) 60{ 61 m_checks_completed = 0; 62 63 // create the ports 64 for (int i = 0; i < p->port_cpuPort_connection_count; ++i) { 65 ports.push_back(new CpuPort(csprintf("%s-port%d", name(), i), 66 this, i)); 67 } 68 69 // add the check start event to the event queue 70 schedule(checkStartEvent, 1); 71} 72 73RubyTester::~RubyTester() 74{ 75 delete m_checkTable_ptr; 76 for (int i = 0; i < ports.size(); i++) 77 delete ports[i]; 78} 79 80void 81RubyTester::init() 82{ 83 assert(ports.size() > 0); 84 85 m_last_progress_vector.resize(ports.size()); 86 for (int i = 0; i < m_last_progress_vector.size(); i++) { 87 m_last_progress_vector[i] = 0; 88 } 89 90 m_num_cpu_sequencers = ports.size(); 91 92 m_checkTable_ptr = new CheckTable(m_num_cpu_sequencers, this); 93} 94 95Port * 96RubyTester::getPort(const std::string &if_name, int idx) 97{ 98 if (if_name != "cpuPort") { 99 panic("RubyTester::getPort: unknown port %s requested\n", if_name); 100 } 101 102 if (idx >= static_cast<int>(ports.size())) { 103 panic("RubyTester::getPort: unknown index %d requested\n", idx); 104 } 105 106 return ports[idx]; 107} 108 109Tick 110RubyTester::CpuPort::recvAtomic(PacketPtr pkt) 111{ 112 panic("RubyTester::CpuPort::recvAtomic() not implemented!\n"); 113 return 0; 114} 115 116bool 117RubyTester::CpuPort::recvTiming(PacketPtr pkt) 118{ 119 // retrieve the subblock and call hitCallback 120 RubyTester::SenderState* senderState = 121 safe_cast<RubyTester::SenderState*>(pkt->senderState); 122 SubBlock* subblock = senderState->subBlock; 123 assert(subblock != NULL); 124 125 // pop the sender state from the packet 126 pkt->senderState = senderState->saved; 127 128 tester->hitCallback(idx, subblock); 129 130 // Now that the tester has completed, delete the senderState 131 // (includes sublock) and the packet, then return 132 delete senderState; 133 delete pkt->req; 134 delete pkt; 135 return true; 136} 137 138Port* 139RubyTester::getCpuPort(int idx) 140{ 141 assert(idx >= 0 && idx < ports.size()); 142 143 return ports[idx]; 144} 145 146void 147RubyTester::hitCallback(NodeID proc, SubBlock* data) 148{ 149 // Mark that we made progress 150 m_last_progress_vector[proc] = g_eventQueue_ptr->getTime(); 151 152 DPRINTF(RubyTest, "completed request for proc: %d\n", proc); 153 DPRINTF(RubyTest, "addr: 0x%x, size: %d, data: ", 154 data->getAddress(), data->getSize()); 155 for (int byte = 0; byte < data->getSize(); byte++) { 156 DPRINTF(RubyTest, "%d", data->getByte(byte)); 157 } 158 DPRINTF(RubyTest, "\n"); 159 160 // This tells us our store has 'completed' or for a load gives us 161 // back the data to make the check 162 Check* check_ptr = m_checkTable_ptr->getCheck(data->getAddress()); 163 assert(check_ptr != NULL); 164 check_ptr->performCallback(proc, data); 165} 166 167void 168RubyTester::wakeup() 169{ 170 if (m_checks_completed < m_checks_to_complete) { 171 // Try to perform an action or check 172 Check* check_ptr = m_checkTable_ptr->getRandomCheck(); 173 assert(check_ptr != NULL); 174 check_ptr->initiate(); 175 176 checkForDeadlock(); 177 178 schedule(checkStartEvent, curTick() + m_wakeup_frequency); 179 } else { 180 exitSimLoop("Ruby Tester completed"); 181 } 182} 183 184void 185RubyTester::checkForDeadlock() 186{ 187 int size = m_last_progress_vector.size(); 188 Time current_time = g_eventQueue_ptr->getTime(); 189 for (int processor = 0; processor < size; processor++) { 190 if ((current_time - m_last_progress_vector[processor]) > 191 m_deadlock_threshold) { 192 panic("Deadlock detected: current_time: %d last_progress_time: %d " 193 "difference: %d processor: %d\n", 194 current_time, m_last_progress_vector[processor], 195 current_time - m_last_progress_vector[processor], processor); 196 } 197 } 198} 199 200void 201RubyTester::print(std::ostream& out) const 202{ 203 out << "[RubyTester]" << std::endl; 204} 205 206RubyTester * 207RubyTesterParams::create() 208{ 209 return new RubyTester(this); 210} 211