Check.cc revision 11800
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 3011793Sbrandon.potter@amd.com#include "cpu/testers/rubytest/Check.hh" 3111793Sbrandon.potter@amd.com 3210348Sandreas.hansson@arm.com#include "base/random.hh" 3311800Sbrandon.potter@amd.com#include "base/trace.hh" 348232Snate@binkert.org#include "debug/RubyTest.hh" 357053SN/A#include "mem/ruby/common/SubBlock.hh" 366899SN/A 377053SN/Atypedef RubyTester::SenderState SenderState; 387053SN/A 3911025Snilay@cs.wisc.eduCheck::Check(Addr address, Addr pc, int _num_writers, int _num_readers, 4011025Snilay@cs.wisc.edu RubyTester* _tester) 418932SBrad.Beckmann@amd.com : m_num_writers(_num_writers), m_num_readers(_num_readers), 428932SBrad.Beckmann@amd.com m_tester_ptr(_tester) 436899SN/A{ 447053SN/A m_status = TesterStatus_Idle; 456899SN/A 467053SN/A pickValue(); 477053SN/A pickInitiatingNode(); 487053SN/A changeAddress(address); 497053SN/A m_pc = pc; 5010348Sandreas.hansson@arm.com m_access_mode = RubyAccessMode(random_mt.random(0, 5110348Sandreas.hansson@arm.com RubyAccessMode_NUM - 1)); 527053SN/A m_store_count = 0; 536899SN/A} 546899SN/A 557053SN/Avoid 567053SN/ACheck::initiate() 576899SN/A{ 587053SN/A DPRINTF(RubyTest, "initiating\n"); 597053SN/A debugPrint(); 606899SN/A 617053SN/A // currently no protocols support prefetches 6210348Sandreas.hansson@arm.com if (false && (random_mt.random(0, 0xf) == 0)) { 637053SN/A initiatePrefetch(); // Prefetch from random processor 647053SN/A } 656899SN/A 6610348Sandreas.hansson@arm.com if (m_tester_ptr->getCheckFlush() && (random_mt.random(0, 0xff) == 0)) { 678184Ssomayeh@cs.wisc.edu initiateFlush(); // issue a Flush request from random processor 688184Ssomayeh@cs.wisc.edu } 698184Ssomayeh@cs.wisc.edu 707053SN/A if (m_status == TesterStatus_Idle) { 717053SN/A initiateAction(); 727053SN/A } else if (m_status == TesterStatus_Ready) { 737053SN/A initiateCheck(); 747053SN/A } else { 757053SN/A // Pending - do nothing 767053SN/A DPRINTF(RubyTest, 777053SN/A "initiating action/check - failed: action/check is pending\n"); 787053SN/A } 796899SN/A} 806899SN/A 817053SN/Avoid 827053SN/ACheck::initiatePrefetch() 836899SN/A{ 847053SN/A DPRINTF(RubyTest, "initiating prefetch\n"); 856899SN/A 8610348Sandreas.hansson@arm.com int index = random_mt.random(0, m_num_readers - 1); 878950Sandreas.hansson@arm.com MasterPort* port = m_tester_ptr->getReadableCpuPort(index); 886899SN/A 897053SN/A Request::Flags flags; 907053SN/A flags.set(Request::PREFETCH); 916899SN/A 927053SN/A Packet::Command cmd; 936899SN/A 947053SN/A // 1 in 8 chance this will be an exclusive prefetch 9510348Sandreas.hansson@arm.com if (random_mt.random(0, 0x7) != 0) { 967053SN/A cmd = MemCmd::ReadReq; 977053SN/A 988932SBrad.Beckmann@amd.com // if necessary, make the request an instruction fetch 9911266SBrad.Beckmann@amd.com if (m_tester_ptr->isInstOnlyCpuPort(index) || 10011266SBrad.Beckmann@amd.com (m_tester_ptr->isInstDataCpuPort(index) && 10111266SBrad.Beckmann@amd.com (random_mt.random(0, 0x1)))) { 1027053SN/A flags.set(Request::INST_FETCH); 1037053SN/A } 1047053SN/A } else { 1057053SN/A cmd = MemCmd::WriteReq; 1067053SN/A flags.set(Request::PF_EXCLUSIVE); 1076899SN/A } 1086899SN/A 1097568SN/A // Prefetches are assumed to be 0 sized 11011025Snilay@cs.wisc.edu Request *req = new Request(m_address, 0, flags, 11111025Snilay@cs.wisc.edu m_tester_ptr->masterId(), curTick(), m_pc); 11211435Smitch.hayenga@arm.com req->setContext(index); 1137568SN/A 1148949Sandreas.hansson@arm.com PacketPtr pkt = new Packet(req, cmd); 11510562Sandreas.hansson@arm.com // despite the oddity of the 0 size (questionable if this should 11610562Sandreas.hansson@arm.com // even be allowed), a prefetch is still a read and as such needs 11710562Sandreas.hansson@arm.com // a place to store the result 11810566Sandreas.hansson@arm.com uint8_t *data = new uint8_t[1]; 11910562Sandreas.hansson@arm.com pkt->dataDynamic(data); 1206899SN/A 1217053SN/A // push the subblock onto the sender state. The sequencer will 1227053SN/A // update the subblock on the return 1239542Sandreas.hansson@arm.com pkt->senderState = new SenderState(m_address, req->getSize()); 1246899SN/A 1258975Sandreas.hansson@arm.com if (port->sendTimingReq(pkt)) { 1267053SN/A DPRINTF(RubyTest, "successfully initiated prefetch.\n"); 1277053SN/A } else { 1287053SN/A // If the packet did not issue, must delete 1299542Sandreas.hansson@arm.com delete pkt->senderState; 1307053SN/A delete pkt->req; 1317053SN/A delete pkt; 1326899SN/A 1337053SN/A DPRINTF(RubyTest, 1347053SN/A "prefetch initiation failed because Port was busy.\n"); 1357053SN/A } 1366899SN/A} 1376899SN/A 1387053SN/Avoid 1398184Ssomayeh@cs.wisc.eduCheck::initiateFlush() 1408184Ssomayeh@cs.wisc.edu{ 1418184Ssomayeh@cs.wisc.edu 1428184Ssomayeh@cs.wisc.edu DPRINTF(RubyTest, "initiating Flush\n"); 1438184Ssomayeh@cs.wisc.edu 14410348Sandreas.hansson@arm.com int index = random_mt.random(0, m_num_writers - 1); 1458950Sandreas.hansson@arm.com MasterPort* port = m_tester_ptr->getWritableCpuPort(index); 1468184Ssomayeh@cs.wisc.edu 1478184Ssomayeh@cs.wisc.edu Request::Flags flags; 1488184Ssomayeh@cs.wisc.edu 14911025Snilay@cs.wisc.edu Request *req = new Request(m_address, CHECK_SIZE, flags, 15011025Snilay@cs.wisc.edu m_tester_ptr->masterId(), curTick(), m_pc); 1518184Ssomayeh@cs.wisc.edu 1528184Ssomayeh@cs.wisc.edu Packet::Command cmd; 1538184Ssomayeh@cs.wisc.edu 1548184Ssomayeh@cs.wisc.edu cmd = MemCmd::FlushReq; 1558184Ssomayeh@cs.wisc.edu 1568949Sandreas.hansson@arm.com PacketPtr pkt = new Packet(req, cmd); 1578184Ssomayeh@cs.wisc.edu 1588184Ssomayeh@cs.wisc.edu // push the subblock onto the sender state. The sequencer will 1598184Ssomayeh@cs.wisc.edu // update the subblock on the return 1609542Sandreas.hansson@arm.com pkt->senderState = new SenderState(m_address, req->getSize()); 1618184Ssomayeh@cs.wisc.edu 1628975Sandreas.hansson@arm.com if (port->sendTimingReq(pkt)) { 1638184Ssomayeh@cs.wisc.edu DPRINTF(RubyTest, "initiating Flush - successful\n"); 1648184Ssomayeh@cs.wisc.edu } 1658184Ssomayeh@cs.wisc.edu} 1668184Ssomayeh@cs.wisc.edu 1678184Ssomayeh@cs.wisc.eduvoid 1687053SN/ACheck::initiateAction() 1696899SN/A{ 1707053SN/A DPRINTF(RubyTest, "initiating Action\n"); 1717053SN/A assert(m_status == TesterStatus_Idle); 1726899SN/A 17310348Sandreas.hansson@arm.com int index = random_mt.random(0, m_num_writers - 1); 1748950Sandreas.hansson@arm.com MasterPort* port = m_tester_ptr->getWritableCpuPort(index); 1756899SN/A 1767053SN/A Request::Flags flags; 1776899SN/A 1787053SN/A // Create the particular address for the next byte to be written 17911025Snilay@cs.wisc.edu Addr writeAddr(m_address + m_store_count); 1806899SN/A 1817053SN/A // Stores are assumed to be 1 byte-sized 18211025Snilay@cs.wisc.edu Request *req = new Request(writeAddr, 1, flags, m_tester_ptr->masterId(), 18311025Snilay@cs.wisc.edu curTick(), m_pc); 1846899SN/A 18511435Smitch.hayenga@arm.com req->setContext(index); 1867053SN/A Packet::Command cmd; 1877053SN/A 1887053SN/A // 1 out of 8 chance, issue an atomic rather than a write 1897053SN/A // if ((random() & 0x7) == 0) { 1907053SN/A // cmd = MemCmd::SwapReq; 1917053SN/A // } else { 1926899SN/A cmd = MemCmd::WriteReq; 1937053SN/A // } 1946899SN/A 1958949Sandreas.hansson@arm.com PacketPtr pkt = new Packet(req, cmd); 19610566Sandreas.hansson@arm.com uint8_t *writeData = new uint8_t[1]; 1977053SN/A *writeData = m_value + m_store_count; 1987053SN/A pkt->dataDynamic(writeData); 1996899SN/A 20011266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Seq write: index %d data 0x%x check 0x%x\n", index, 20110563Sandreas.hansson@arm.com *(pkt->getConstPtr<uint8_t>()), *writeData); 2026899SN/A 2037053SN/A // push the subblock onto the sender state. The sequencer will 2047053SN/A // update the subblock on the return 2059542Sandreas.hansson@arm.com pkt->senderState = new SenderState(writeAddr, req->getSize()); 2066899SN/A 2078975Sandreas.hansson@arm.com if (port->sendTimingReq(pkt)) { 2087053SN/A DPRINTF(RubyTest, "initiating action - successful\n"); 2097053SN/A DPRINTF(RubyTest, "status before action update: %s\n", 2107053SN/A (TesterStatus_to_string(m_status)).c_str()); 2117053SN/A m_status = TesterStatus_Action_Pending; 21211266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Check %s, State=Action_Pending\n", m_address); 2137053SN/A } else { 2147053SN/A // If the packet did not issue, must delete 2157053SN/A // Note: No need to delete the data, the packet destructor 2167053SN/A // will delete it 2179542Sandreas.hansson@arm.com delete pkt->senderState; 2187053SN/A delete pkt->req; 2197053SN/A delete pkt; 2207053SN/A 2217053SN/A DPRINTF(RubyTest, "failed to initiate action - sequencer not ready\n"); 2227053SN/A } 2237053SN/A 2247053SN/A DPRINTF(RubyTest, "status after action update: %s\n", 2256899SN/A (TesterStatus_to_string(m_status)).c_str()); 2266899SN/A} 2276899SN/A 2287053SN/Avoid 2297053SN/ACheck::initiateCheck() 2306899SN/A{ 2317053SN/A DPRINTF(RubyTest, "Initiating Check\n"); 2327053SN/A assert(m_status == TesterStatus_Ready); 2336899SN/A 23410348Sandreas.hansson@arm.com int index = random_mt.random(0, m_num_readers - 1); 2358950Sandreas.hansson@arm.com MasterPort* port = m_tester_ptr->getReadableCpuPort(index); 2366899SN/A 2377053SN/A Request::Flags flags; 2386899SN/A 2398932SBrad.Beckmann@amd.com // If necessary, make the request an instruction fetch 24011266SBrad.Beckmann@amd.com if (m_tester_ptr->isInstOnlyCpuPort(index) || 24111266SBrad.Beckmann@amd.com (m_tester_ptr->isInstDataCpuPort(index) && 24211266SBrad.Beckmann@amd.com (random_mt.random(0, 0x1)))) { 2437053SN/A flags.set(Request::INST_FETCH); 2447053SN/A } 2456899SN/A 2467568SN/A // Checks are sized depending on the number of bytes written 24711025Snilay@cs.wisc.edu Request *req = new Request(m_address, CHECK_SIZE, flags, 24811025Snilay@cs.wisc.edu m_tester_ptr->masterId(), curTick(), m_pc); 2497568SN/A 25011435Smitch.hayenga@arm.com req->setContext(index); 2518949Sandreas.hansson@arm.com PacketPtr pkt = new Packet(req, MemCmd::ReadReq); 2529208Snilay@cs.wisc.edu uint8_t *dataArray = new uint8_t[CHECK_SIZE]; 25310566Sandreas.hansson@arm.com pkt->dataDynamic(dataArray); 2546899SN/A 25511266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Seq read: index %d\n", index); 25611266SBrad.Beckmann@amd.com 2577053SN/A // push the subblock onto the sender state. The sequencer will 2587053SN/A // update the subblock on the return 2599542Sandreas.hansson@arm.com pkt->senderState = new SenderState(m_address, req->getSize()); 2606899SN/A 2618975Sandreas.hansson@arm.com if (port->sendTimingReq(pkt)) { 2627053SN/A DPRINTF(RubyTest, "initiating check - successful\n"); 2637053SN/A DPRINTF(RubyTest, "status before check update: %s\n", 2647053SN/A TesterStatus_to_string(m_status).c_str()); 2657053SN/A m_status = TesterStatus_Check_Pending; 26611266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Check %s, State=Check_Pending\n", m_address); 2677053SN/A } else { 2687053SN/A // If the packet did not issue, must delete 2697053SN/A // Note: No need to delete the data, the packet destructor 2707053SN/A // will delete it 2719542Sandreas.hansson@arm.com delete pkt->senderState; 2727053SN/A delete pkt->req; 2737053SN/A delete pkt; 2746899SN/A 2757053SN/A DPRINTF(RubyTest, "failed to initiate check - cpu port not ready\n"); 2767053SN/A } 2777053SN/A 2787053SN/A DPRINTF(RubyTest, "status after check update: %s\n", 2797053SN/A TesterStatus_to_string(m_status).c_str()); 2806899SN/A} 2816899SN/A 2827053SN/Avoid 28310302Snilay@cs.wisc.eduCheck::performCallback(NodeID proc, SubBlock* data, Cycles curTime) 2846899SN/A{ 28511025Snilay@cs.wisc.edu Addr address = data->getAddress(); 2866899SN/A 2877053SN/A // This isn't exactly right since we now have multi-byte checks 2887053SN/A // assert(getAddress() == address); 2896899SN/A 29011025Snilay@cs.wisc.edu assert(makeLineAddress(m_address) == makeLineAddress(address)); 2917053SN/A assert(data != NULL); 2927053SN/A 2937053SN/A DPRINTF(RubyTest, "RubyTester Callback\n"); 2946899SN/A debugPrint(); 2956899SN/A 2967053SN/A if (m_status == TesterStatus_Action_Pending) { 2977053SN/A DPRINTF(RubyTest, "Action callback write value: %d, currently %d\n", 2987053SN/A (m_value + m_store_count), data->getByte(0)); 2997053SN/A // Perform store one byte at a time 3007053SN/A data->setByte(0, (m_value + m_store_count)); 3017053SN/A m_store_count++; 3027053SN/A if (m_store_count == CHECK_SIZE) { 3037053SN/A m_status = TesterStatus_Ready; 30411266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Check %s, State=Ready\n", m_address); 3057053SN/A } else { 3067053SN/A m_status = TesterStatus_Idle; 30711266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Check %s, State=Idle store_count: %d\n", 30811266SBrad.Beckmann@amd.com m_address, m_store_count); 3097053SN/A } 3107053SN/A DPRINTF(RubyTest, "Action callback return data now %d\n", 3117053SN/A data->getByte(0)); 3127053SN/A } else if (m_status == TesterStatus_Check_Pending) { 3137053SN/A DPRINTF(RubyTest, "Check callback\n"); 3147053SN/A // Perform load/check 3157053SN/A for (int byte_number=0; byte_number<CHECK_SIZE; byte_number++) { 3169208Snilay@cs.wisc.edu if (uint8_t(m_value + byte_number) != data->getByte(byte_number)) { 3177805Snilay@cs.wisc.edu panic("Action/check failure: proc: %d address: %s data: %s " 3187805Snilay@cs.wisc.edu "byte_number: %d m_value+byte_number: %d byte: %d %s" 3197805Snilay@cs.wisc.edu "Time: %d\n", 3207805Snilay@cs.wisc.edu proc, address, data, byte_number, 3217805Snilay@cs.wisc.edu (int)m_value + byte_number, 3229475Snilay@cs.wisc.edu (int)data->getByte(byte_number), *this, curTime); 3237053SN/A } 3247053SN/A } 3257053SN/A DPRINTF(RubyTest, "Action/check success\n"); 3267053SN/A debugPrint(); 3276899SN/A 3287053SN/A // successful check complete, increment complete 3297053SN/A m_tester_ptr->incrementCheckCompletions(); 3306899SN/A 3317053SN/A m_status = TesterStatus_Idle; 33211266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Check %s, State=Idle\n", m_address); 3337053SN/A pickValue(); 3347053SN/A 3357053SN/A } else { 3367805Snilay@cs.wisc.edu panic("Unexpected TesterStatus: %s proc: %d data: %s m_status: %s " 3379475Snilay@cs.wisc.edu "time: %d\n", *this, proc, data, m_status, curTime); 3387053SN/A } 3397053SN/A 3407053SN/A DPRINTF(RubyTest, "proc: %d, Address: 0x%x\n", proc, 34111025Snilay@cs.wisc.edu makeLineAddress(m_address)); 3427053SN/A DPRINTF(RubyTest, "Callback done\n"); 3437053SN/A debugPrint(); 3446899SN/A} 3456899SN/A 3467053SN/Avoid 34711025Snilay@cs.wisc.eduCheck::changeAddress(Addr address) 3486899SN/A{ 3497053SN/A assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready); 3507053SN/A m_status = TesterStatus_Idle; 3517053SN/A m_address = address; 35211266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Check %s, State=Idle\n", m_address); 3537053SN/A m_store_count = 0; 3546899SN/A} 3556899SN/A 3567053SN/Avoid 3577053SN/ACheck::pickValue() 3586899SN/A{ 3597053SN/A assert(m_status == TesterStatus_Idle); 36010348Sandreas.hansson@arm.com m_value = random_mt.random(0, 0xff); // One byte 3617053SN/A m_store_count = 0; 3626899SN/A} 3636899SN/A 3647053SN/Avoid 3657053SN/ACheck::pickInitiatingNode() 3666899SN/A{ 3677053SN/A assert(m_status == TesterStatus_Idle || m_status == TesterStatus_Ready); 3687053SN/A m_status = TesterStatus_Idle; 36910348Sandreas.hansson@arm.com m_initiatingNode = (random_mt.random(0, m_num_writers - 1)); 37011266SBrad.Beckmann@amd.com DPRINTF(RubyTest, "Check %s, State=Idle, picked initiating node %d\n", 37111266SBrad.Beckmann@amd.com m_address, m_initiatingNode); 3727053SN/A m_store_count = 0; 3736899SN/A} 3746899SN/A 3757053SN/Avoid 3767055SN/ACheck::print(std::ostream& out) const 3776899SN/A{ 3787053SN/A out << "[" 3797053SN/A << m_address << ", value: " 3807053SN/A << (int)m_value << ", status: " 3817053SN/A << m_status << ", initiating node: " 3827053SN/A << m_initiatingNode << ", store_count: " 3837053SN/A << m_store_count 3847055SN/A << "]" << std::flush; 3856899SN/A} 3866899SN/A 3877053SN/Avoid 3887053SN/ACheck::debugPrint() 3896899SN/A{ 3907053SN/A DPRINTF(RubyTest, 3917053SN/A "[%#x, value: %d, status: %s, initiating node: %d, store_count: %d]\n", 39211025Snilay@cs.wisc.edu m_address, (int)m_value, TesterStatus_to_string(m_status).c_str(), 3937053SN/A m_initiatingNode, m_store_count); 3946899SN/A} 395