Check.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 "cpu/testers/rubytest/Check.hh" 31#include "mem/ruby/common/SubBlock.hh" 32#include "mem/ruby/system/Sequencer.hh" 33#include "mem/ruby/system/System.hh" 34 35typedef RubyTester::SenderState SenderState; 36 37Check::Check(const Address& address, const Address& pc, 38 int _num_cpu_sequencers, RubyTester* _tester) 39 : m_num_cpu_sequencers(_num_cpu_sequencers), m_tester_ptr(_tester) 40{ 41 m_status = TesterStatus_Idle; 42 43 pickValue(); 44 pickInitiatingNode(); 45 changeAddress(address); 46 m_pc = pc; 47 m_access_mode = RubyAccessMode(random() % RubyAccessMode_NUM); 48 m_store_count = 0; 49} 50 51void 52Check::initiate() 53{ 54 DPRINTF(RubyTest, "initiating\n"); 55 debugPrint(); 56 57 // currently no protocols support prefetches 58 if (false && (random() & 0xf) == 0) { 59 initiatePrefetch(); // Prefetch from random processor 60 } 61 62 if (m_tester_ptr->getCheckFlush() && (random() & 0xff) == 0) { 63 initiateFlush(); // issue a Flush request from random processor 64 } 65 66 if (m_status == TesterStatus_Idle) { 67 initiateAction(); 68 } else if (m_status == TesterStatus_Ready) { 69 initiateCheck(); 70 } else { 71 // Pending - do nothing 72 DPRINTF(RubyTest, 73 "initiating action/check - failed: action/check is pending\n"); 74 } 75} 76 77void 78Check::initiatePrefetch() 79{ 80 DPRINTF(RubyTest, "initiating prefetch\n"); 81 82 int index = random() % m_num_cpu_sequencers; 83 RubyTester::CpuPort* port = 84 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index)); 85 86 Request::Flags flags; 87 flags.set(Request::PREFETCH); 88 89 Packet::Command cmd; 90 91 // 1 in 8 chance this will be an exclusive prefetch 92 if ((random() & 0x7) != 0) { 93 cmd = MemCmd::ReadReq; 94 95 // 50% chance that the request will be an instruction fetch 96 if ((random() & 0x1) == 0) { 97 flags.set(Request::INST_FETCH); 98 } 99 } else { 100 cmd = MemCmd::WriteReq; 101 flags.set(Request::PF_EXCLUSIVE); 102 } 103 104 // Prefetches are assumed to be 0 sized 105 Request *req = new Request(m_address.getAddress(), 0, flags, curTick(), 106 m_pc.getAddress()); 107 108 PacketPtr pkt = new Packet(req, cmd, port->idx); 109 110 // push the subblock onto the sender state. The sequencer will 111 // update the subblock on the return 112 pkt->senderState = 113 new SenderState(m_address, req->getSize(), pkt->senderState); 114 115 if (port->sendTiming(pkt)) { 116 DPRINTF(RubyTest, "successfully initiated prefetch.\n"); 117 } else { 118 // If the packet did not issue, must delete 119 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState); 120 pkt->senderState = senderState->saved; 121 delete senderState; 122 delete pkt->req; 123 delete pkt; 124 125 DPRINTF(RubyTest, 126 "prefetch initiation failed because Port was busy.\n"); 127 } 128} 129 130void 131Check::initiateFlush() 132{ 133 134 DPRINTF(RubyTest, "initiating Flush\n"); 135 136 int index = random() % m_num_cpu_sequencers; 137 RubyTester::CpuPort* port = 138 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index)); 139 140 Request::Flags flags; 141 142 Request *req = new Request(m_address.getAddress(), CHECK_SIZE, flags, curTick(), 143 m_pc.getAddress()); 144 145 Packet::Command cmd; 146 147 cmd = MemCmd::FlushReq; 148 149 PacketPtr pkt = new Packet(req, cmd, port->idx); 150 151 // push the subblock onto the sender state. The sequencer will 152 // update the subblock on the return 153 pkt->senderState = 154 new SenderState(m_address, req->getSize(), pkt->senderState); 155 156 if (port->sendTiming(pkt)) { 157 DPRINTF(RubyTest, "initiating Flush - successful\n"); 158 } 159} 160 161void 162Check::initiateAction() 163{ 164 DPRINTF(RubyTest, "initiating Action\n"); 165 assert(m_status == TesterStatus_Idle); 166 167 int index = random() % m_num_cpu_sequencers; 168 RubyTester::CpuPort* port = 169 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index)); 170 171 Request::Flags flags; 172 173 // Create the particular address for the next byte to be written 174 Address writeAddr(m_address.getAddress() + m_store_count); 175 176 // Stores are assumed to be 1 byte-sized 177 Request *req = new Request(writeAddr.getAddress(), 1, flags, curTick(), 178 m_pc.getAddress()); 179 180 Packet::Command cmd; 181 182 // 1 out of 8 chance, issue an atomic rather than a write 183 // if ((random() & 0x7) == 0) { 184 // cmd = MemCmd::SwapReq; 185 // } else { 186 cmd = MemCmd::WriteReq; 187 // } 188 189 PacketPtr pkt = new Packet(req, cmd, port->idx); 190 uint8_t* writeData = new uint8_t; 191 *writeData = m_value + m_store_count; 192 pkt->dataDynamic(writeData); 193 194 DPRINTF(RubyTest, "data 0x%x check 0x%x\n", 195 *(pkt->getPtr<uint8_t>()), *writeData); 196 197 // push the subblock onto the sender state. The sequencer will 198 // update the subblock on the return 199 pkt->senderState = 200 new SenderState(writeAddr, req->getSize(), pkt->senderState); 201 202 if (port->sendTiming(pkt)) { 203 DPRINTF(RubyTest, "initiating action - successful\n"); 204 DPRINTF(RubyTest, "status before action update: %s\n", 205 (TesterStatus_to_string(m_status)).c_str()); 206 m_status = TesterStatus_Action_Pending; 207 } else { 208 // If the packet did not issue, must delete 209 // Note: No need to delete the data, the packet destructor 210 // will delete it 211 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState); 212 pkt->senderState = senderState->saved; 213 delete senderState; 214 delete pkt->req; 215 delete pkt; 216 217 DPRINTF(RubyTest, "failed to initiate action - sequencer not ready\n"); 218 } 219 220 DPRINTF(RubyTest, "status after action update: %s\n", 221 (TesterStatus_to_string(m_status)).c_str()); 222} 223 224void 225Check::initiateCheck() 226{ 227 DPRINTF(RubyTest, "Initiating Check\n"); 228 assert(m_status == TesterStatus_Ready); 229 230 int index = random() % m_num_cpu_sequencers; 231 RubyTester::CpuPort* port = 232 safe_cast<RubyTester::CpuPort*>(m_tester_ptr->getCpuPort(index)); 233 234 Request::Flags flags; 235 236 // 50% chance that the request will be an instruction fetch 237 if ((random() & 0x1) == 0) { 238 flags.set(Request::INST_FETCH); 239 } 240 241 // Checks are sized depending on the number of bytes written 242 Request *req = new Request(m_address.getAddress(), CHECK_SIZE, flags, 243 curTick(), m_pc.getAddress()); 244 245 PacketPtr pkt = new Packet(req, MemCmd::ReadReq, port->idx); 246 uint8_t* dataArray = new uint8_t[CHECK_SIZE]; 247 pkt->dataDynamicArray(dataArray); 248 249 // push the subblock onto the sender state. The sequencer will 250 // update the subblock on the return 251 pkt->senderState = 252 new SenderState(m_address, req->getSize(), pkt->senderState); 253 254 if (port->sendTiming(pkt)) { 255 DPRINTF(RubyTest, "initiating check - successful\n"); 256 DPRINTF(RubyTest, "status before check update: %s\n", 257 TesterStatus_to_string(m_status).c_str()); 258 m_status = TesterStatus_Check_Pending; 259 } else { 260 // If the packet did not issue, must delete 261 // Note: No need to delete the data, the packet destructor 262 // will delete it 263 SenderState* senderState = safe_cast<SenderState*>(pkt->senderState); 264 pkt->senderState = senderState->saved; 265 delete senderState; 266 delete pkt->req; 267 delete pkt; 268 269 DPRINTF(RubyTest, "failed to initiate check - cpu port not ready\n"); 270 } 271 272 DPRINTF(RubyTest, "status after check update: %s\n", 273 TesterStatus_to_string(m_status).c_str()); 274} 275 276void 277Check::performCallback(NodeID proc, SubBlock* data) 278{ 279 Address address = data->getAddress(); 280 281 // This isn't exactly right since we now have multi-byte checks 282 // assert(getAddress() == address); 283 284 assert(getAddress().getLineAddress() == address.getLineAddress()); 285 assert(data != NULL); 286 287 DPRINTF(RubyTest, "RubyTester Callback\n"); 288 debugPrint(); 289 290 if (m_status == TesterStatus_Action_Pending) { 291 DPRINTF(RubyTest, "Action callback write value: %d, currently %d\n", 292 (m_value + m_store_count), data->getByte(0)); 293 // Perform store one byte at a time 294 data->setByte(0, (m_value + m_store_count)); 295 m_store_count++; 296 if (m_store_count == CHECK_SIZE) { 297 m_status = TesterStatus_Ready; 298 } else { 299 m_status = TesterStatus_Idle; 300 } 301 DPRINTF(RubyTest, "Action callback return data now %d\n", 302 data->getByte(0)); 303 } else if (m_status == TesterStatus_Check_Pending) { 304 DPRINTF(RubyTest, "Check callback\n"); 305 // Perform load/check 306 for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) { 307 if (uint8(m_value + byte_number) != data->getByte(byte_number)) { 308 panic("Action/check failure: proc: %d address: %s data: %s " 309 "byte_number: %d m_value+byte_number: %d byte: %d %s" 310 "Time: %d\n", 311 proc, address, data, byte_number, 312 (int)m_value + byte_number, 313 (int)data->getByte(byte_number), *this, 314 g_eventQueue_ptr->getTime()); 315 } 316 } 317 DPRINTF(RubyTest, "Action/check success\n"); 318 debugPrint(); 319 320 // successful check complete, increment complete 321 m_tester_ptr->incrementCheckCompletions(); 322 323 m_status = TesterStatus_Idle; 324 pickValue(); 325 326 } else { 327 panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s " 328 "time: %d\n", 329 *this, proc, data, m_status, g_eventQueue_ptr->getTime()); 330 } 331 332 DPRINTF(RubyTest, "proc: %d, Address: 0x%x\n", proc, 333 getAddress().getLineAddress()); 334 DPRINTF(RubyTest, "Callback done\n"); 335 debugPrint(); 336} 337 338void 339Check::changeAddress(const Address& address) 340{ 341 assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready); 342 m_status = TesterStatus_Idle; 343 m_address = address; 344 m_store_count = 0; 345} 346 347void 348Check::pickValue() 349{ 350 assert(m_status == TesterStatus_Idle); 351 m_status = TesterStatus_Idle; 352 m_value = random() & 0xff; // One byte 353 m_store_count = 0; 354} 355 356void 357Check::pickInitiatingNode() 358{ 359 assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready); 360 m_status = TesterStatus_Idle; 361 m_initiatingNode = (random() % m_num_cpu_sequencers); 362 DPRINTF(RubyTest, "picked initiating node %d\n", m_initiatingNode); 363 m_store_count = 0; 364} 365 366void 367Check::print(std::ostream& out) const 368{ 369 out << "[" 370 << m_address << ", value: " 371 << (int)m_value << ", status: " 372 << m_status << ", initiating node: " 373 << m_initiatingNode << ", store_count: " 374 << m_store_count 375 << "]" << std::flush; 376} 377 378void 379Check::debugPrint() 380{ 381 DPRINTF(RubyTest, 382 "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n", 383 m_address.getAddress(), (int)m_value, 384 TesterStatus_to_string(m_status).c_str(), 385 m_initiatingNode, m_store_count); 386} 387