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