memtest.cc revision 9814
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665SN/A * 282665SN/A * Authors: Erik Hallnor 292665SN/A * Steve Reinhardt 302SN/A */ 312SN/A 322SN/A// FIX ME: make trackBlkAddr use blocksize from actual cache, not hard coded 332SN/A 341298SN/A#include <iomanip> 351298SN/A#include <set> 361259SN/A#include <string> 372SN/A#include <vector> 382SN/A 39146SN/A#include "base/misc.hh" 40146SN/A#include "base/statistics.hh" 417632SBrad.Beckmann@amd.com#include "cpu/testers/memtest/memtest.hh" 428232Snate@binkert.org#include "debug/MemTest.hh" 433348SN/A#include "mem/mem_object.hh" 448229Snate@binkert.org#include "mem/packet.hh" 453348SN/A#include "mem/port.hh" 463348SN/A#include "mem/request.hh" 4756SN/A#include "sim/sim_events.hh" 48695SN/A#include "sim/stats.hh" 498832SAli.Saidi@ARM.com#include "sim/system.hh" 502SN/A 512SN/Ausing namespace std; 522SN/A 531298SN/Aint TESTER_ALLOCATOR=0; 541298SN/A 553187SN/Abool 568975Sandreas.hansson@arm.comMemTest::CpuPort::recvTimingResp(PacketPtr pkt) 573187SN/A{ 588948Sandreas.hansson@arm.com memtest->completeRequest(pkt); 593187SN/A return true; 603187SN/A} 613187SN/A 623187SN/Avoid 633187SN/AMemTest::CpuPort::recvRetry() 643187SN/A{ 653187SN/A memtest->doRetry(); 663187SN/A} 673187SN/A 683262SN/Avoid 693349SN/AMemTest::sendPkt(PacketPtr pkt) { 703262SN/A if (atomic) { 713262SN/A cachePort.sendAtomic(pkt); 723262SN/A completeRequest(pkt); 733262SN/A } 748975Sandreas.hansson@arm.com else if (!cachePort.sendTimingReq(pkt)) { 757544SN/A DPRINTF(MemTest, "accessRetry setting to true\n"); 767544SN/A 777544SN/A // 787544SN/A // dma requests should never be retried 797544SN/A // 807544SN/A if (issueDmas) { 817544SN/A panic("Nacked DMA requests are not supported\n"); 827544SN/A } 833262SN/A accessRetry = true; 843262SN/A retryPkt = pkt; 857544SN/A } else { 867544SN/A if (issueDmas) { 877544SN/A dmaOutstanding = true; 887544SN/A } 893262SN/A } 903262SN/A 913262SN/A} 923262SN/A 935034SN/AMemTest::MemTest(const Params *p) 945034SN/A : MemObject(p), 952SN/A tickEvent(this), 963187SN/A cachePort("test", this), 973187SN/A funcPort("functional", this), 989814Sandreas.hansson@arm.com funcProxy(funcPort, p->sys->cacheLineSize()), 993187SN/A retryPkt(NULL), 1003187SN/A// mainMem(main_mem), 1013187SN/A// checkMem(check_mem), 1025034SN/A size(p->memory_size), 1035034SN/A percentReads(p->percent_reads), 1045034SN/A percentFunctional(p->percent_functional), 1055034SN/A percentUncacheable(p->percent_uncacheable), 1067544SN/A issueDmas(p->issue_dmas), 1078832SAli.Saidi@ARM.com masterId(p->sys->getMasterId(name())), 1089814Sandreas.hansson@arm.com blockSize(p->sys->cacheLineSize()), 1095034SN/A progressInterval(p->progress_interval), 1105034SN/A nextProgressMessage(p->progress_interval), 1115034SN/A percentSourceUnaligned(p->percent_source_unaligned), 1125034SN/A percentDestUnaligned(p->percent_dest_unaligned), 1135034SN/A maxLoads(p->max_loads), 1148436SBrad.Beckmann@amd.com atomic(p->atomic), 1158436SBrad.Beckmann@amd.com suppress_func_warnings(p->suppress_func_warnings) 1162SN/A{ 1177544SN/A id = TESTER_ALLOCATOR++; 1187544SN/A 1193187SN/A // Needs to be masked off once we know the block size. 1205034SN/A traceBlockAddr = p->trace_addr; 1212SN/A baseAddr1 = 0x100000; 1222SN/A baseAddr2 = 0x400000; 1232SN/A uncacheAddr = 0x800000; 1242SN/A 1259814Sandreas.hansson@arm.com blockAddrMask = blockSize - 1; 1269814Sandreas.hansson@arm.com traceBlockAddr = blockAddr(traceBlockAddr); 1279814Sandreas.hansson@arm.com 1282SN/A // set up counters 1292SN/A noResponseCycles = 0; 1302SN/A numReads = 0; 1318436SBrad.Beckmann@amd.com numWrites = 0; 1325606SN/A schedule(tickEvent, 0); 1331298SN/A 1343187SN/A accessRetry = false; 1357544SN/A dmaOutstanding = false; 1363187SN/A} 1373187SN/A 1389294Sandreas.hansson@arm.comBaseMasterPort & 1399294Sandreas.hansson@arm.comMemTest::getMasterPort(const std::string &if_name, PortID idx) 1403187SN/A{ 1413187SN/A if (if_name == "functional") 1428922Swilliam.wang@arm.com return funcPort; 1433187SN/A else if (if_name == "test") 1448922Swilliam.wang@arm.com return cachePort; 1453187SN/A else 1468922Swilliam.wang@arm.com return MemObject::getMasterPort(if_name, idx); 1473187SN/A} 1483187SN/A 1493187SN/Avoid 1503187SN/AMemTest::init() 1513187SN/A{ 1524579SN/A // initial memory contents for both physical memory and functional 1534579SN/A // memory should be 0; no need to initialize them. 1542SN/A} 1552SN/A 1562SN/A 1572SN/Avoid 1583349SN/AMemTest::completeRequest(PacketPtr pkt) 1592SN/A{ 1604628SN/A Request *req = pkt->req; 1614628SN/A 1627544SN/A if (issueDmas) { 1637544SN/A dmaOutstanding = false; 1647544SN/A } 1657544SN/A 1668436SBrad.Beckmann@amd.com DPRINTF(MemTest, "completing %s at address %x (blk %x) %s\n", 1674628SN/A pkt->isWrite() ? "write" : "read", 1688436SBrad.Beckmann@amd.com req->getPaddr(), blockAddr(req->getPaddr()), 1698436SBrad.Beckmann@amd.com pkt->isError() ? "error" : "success"); 1704628SN/A 1713187SN/A MemTestSenderState *state = 1723187SN/A dynamic_cast<MemTestSenderState *>(pkt->senderState); 1733187SN/A 1743187SN/A uint8_t *data = state->data; 1753187SN/A uint8_t *pkt_data = pkt->getPtr<uint8_t>(); 1763187SN/A 1771298SN/A //Remove the address from the list of outstanding 1784628SN/A std::set<unsigned>::iterator removeAddr = 1794628SN/A outstandingAddrs.find(req->getPaddr()); 1801298SN/A assert(removeAddr != outstandingAddrs.end()); 1811298SN/A outstandingAddrs.erase(removeAddr); 1821298SN/A 1838436SBrad.Beckmann@amd.com if (pkt->isError()) { 1848436SBrad.Beckmann@amd.com if (!suppress_func_warnings) { 1859301Snilay@cs.wisc.edu warn("Functional %s access failed at %#x\n", 1868436SBrad.Beckmann@amd.com pkt->isWrite() ? "write" : "read", req->getPaddr()); 1872SN/A } 1888436SBrad.Beckmann@amd.com } else { 1898436SBrad.Beckmann@amd.com if (pkt->isRead()) { 1908436SBrad.Beckmann@amd.com if (memcmp(pkt_data, data, pkt->getSize()) != 0) { 1918436SBrad.Beckmann@amd.com panic("%s: read of %x (blk %x) @ cycle %d " 1928436SBrad.Beckmann@amd.com "returns %x, expected %x\n", name(), 1938436SBrad.Beckmann@amd.com req->getPaddr(), blockAddr(req->getPaddr()), curTick(), 1948436SBrad.Beckmann@amd.com *pkt_data, *data); 1958436SBrad.Beckmann@amd.com } 1962SN/A 1978436SBrad.Beckmann@amd.com numReads++; 1988436SBrad.Beckmann@amd.com numReadsStat++; 1992SN/A 2008436SBrad.Beckmann@amd.com if (numReads == (uint64_t)nextProgressMessage) { 2018436SBrad.Beckmann@amd.com ccprintf(cerr, "%s: completed %d read, %d write accesses @%d\n", 2028436SBrad.Beckmann@amd.com name(), numReads, numWrites, curTick()); 2038436SBrad.Beckmann@amd.com nextProgressMessage += progressInterval; 2048436SBrad.Beckmann@amd.com } 2058436SBrad.Beckmann@amd.com 2068436SBrad.Beckmann@amd.com if (maxLoads != 0 && numReads >= maxLoads) 2078436SBrad.Beckmann@amd.com exitSimLoop("maximum number of loads reached"); 2088436SBrad.Beckmann@amd.com } else { 2098436SBrad.Beckmann@amd.com assert(pkt->isWrite()); 2108853Sandreas.hansson@arm.com funcProxy.writeBlob(req->getPaddr(), pkt_data, req->getSize()); 2118436SBrad.Beckmann@amd.com numWrites++; 2128436SBrad.Beckmann@amd.com numWritesStat++; 2132SN/A } 2142SN/A } 2152SN/A 2162SN/A noResponseCycles = 0; 2173187SN/A delete state; 2182SN/A delete [] data; 2193187SN/A delete pkt->req; 2203187SN/A delete pkt; 2212SN/A} 2222SN/A 2232SN/Avoid 2242SN/AMemTest::regStats() 2252SN/A{ 226729SN/A using namespace Stats; 2272SN/A 228695SN/A numReadsStat 2292SN/A .name(name() + ".num_reads") 2302SN/A .desc("number of read accesses completed") 2312SN/A ; 2322SN/A 233695SN/A numWritesStat 2342SN/A .name(name() + ".num_writes") 2352SN/A .desc("number of write accesses completed") 2362SN/A ; 2372SN/A 238695SN/A numCopiesStat 2392SN/A .name(name() + ".num_copies") 2402SN/A .desc("number of copy accesses completed") 2412SN/A ; 2422SN/A} 2432SN/A 2442SN/Avoid 2452SN/AMemTest::tick() 2462SN/A{ 2472SN/A if (!tickEvent.scheduled()) 2489180Sandreas.hansson@arm.com schedule(tickEvent, clockEdge(Cycles(1))); 2492SN/A 2501298SN/A if (++noResponseCycles >= 500000) { 2517544SN/A if (issueDmas) { 2527544SN/A cerr << "DMA tester "; 2537544SN/A } 2547823Ssteve.reinhardt@amd.com cerr << name() << ": deadlocked at cycle " << curTick() << endl; 2552SN/A fatal(""); 2562SN/A } 2572SN/A 2587544SN/A if (accessRetry || (issueDmas && dmaOutstanding)) { 2597544SN/A DPRINTF(MemTest, "MemTester waiting on accessRetry or DMA response\n"); 2602SN/A return; 2612SN/A } 2622SN/A 2632SN/A //make new request 2641899SN/A unsigned cmd = random() % 100; 2651899SN/A unsigned offset = random() % size; 2662SN/A unsigned base = random() % 2; 2672SN/A uint64_t data = random(); 2682SN/A unsigned access_size = random() % 4; 2695736SN/A bool uncacheable = (random() % 100) < percentUncacheable; 2702SN/A 2717544SN/A unsigned dma_access_size = random() % 4; 2727544SN/A 2731298SN/A //If we aren't doing copies, use id as offset, and do a false sharing 2741298SN/A //mem tester 2753187SN/A //We can eliminate the lower bits of the offset, and then use the id 2763187SN/A //to offset within the blks 2774628SN/A offset = blockAddr(offset); 2783187SN/A offset += id; 2793187SN/A access_size = 0; 2807544SN/A dma_access_size = 0; 2811298SN/A 2825736SN/A Request::Flags flags; 2833187SN/A Addr paddr; 2842SN/A 2855736SN/A if (uncacheable) { 2865736SN/A flags.set(Request::UNCACHEABLE); 2873187SN/A paddr = uncacheAddr + offset; 2887544SN/A } else { 2893187SN/A paddr = ((base) ? baseAddr1 : baseAddr2) + offset; 2902SN/A } 2919301Snilay@cs.wisc.edu 2929301Snilay@cs.wisc.edu // For now we only allow one outstanding request per address 2939301Snilay@cs.wisc.edu // per tester This means we assume CPU does write forwarding 2949301Snilay@cs.wisc.edu // to reads that alias something in the cpu store buffer. 2959301Snilay@cs.wisc.edu if (outstandingAddrs.find(paddr) != outstandingAddrs.end()) { 2969301Snilay@cs.wisc.edu return; 2979301Snilay@cs.wisc.edu } 2989301Snilay@cs.wisc.edu 2997657Ssteve.reinhardt@amd.com bool do_functional = (random() % 100 < percentFunctional) && !uncacheable; 3009301Snilay@cs.wisc.edu Request *req = new Request(); 3019301Snilay@cs.wisc.edu uint8_t *result = new uint8_t[8]; 3022SN/A 3037544SN/A if (issueDmas) { 3047544SN/A paddr &= ~((1 << dma_access_size) - 1); 3058832SAli.Saidi@ARM.com req->setPhys(paddr, 1 << dma_access_size, flags, masterId); 3067544SN/A req->setThreadContext(id,0); 3077544SN/A } else { 3087544SN/A paddr &= ~((1 << access_size) - 1); 3098832SAli.Saidi@ARM.com req->setPhys(paddr, 1 << access_size, flags, masterId); 3107544SN/A req->setThreadContext(id,0); 3117544SN/A } 3127544SN/A assert(req->getSize() == 1); 3133187SN/A 3142SN/A if (cmd < percentReads) { 3152SN/A // read 3164628SN/A outstandingAddrs.insert(paddr); 3171298SN/A 3183187SN/A // ***** NOTE FOR RON: I'm not sure how to access checkMem. - Kevin 3198853Sandreas.hansson@arm.com funcProxy.readBlob(req->getPaddr(), result, req->getSize()); 3203187SN/A 3214628SN/A DPRINTF(MemTest, 3227657Ssteve.reinhardt@amd.com "id %d initiating %sread at addr %x (blk %x) expecting %x\n", 3237657Ssteve.reinhardt@amd.com id, do_functional ? "functional " : "", req->getPaddr(), 3247657Ssteve.reinhardt@amd.com blockAddr(req->getPaddr()), *result); 3253187SN/A 3268949Sandreas.hansson@arm.com PacketPtr pkt = new Packet(req, MemCmd::ReadReq); 3273187SN/A pkt->dataDynamicArray(new uint8_t[req->getSize()]); 3283187SN/A MemTestSenderState *state = new MemTestSenderState(result); 3293187SN/A pkt->senderState = state; 3303187SN/A 3317657Ssteve.reinhardt@amd.com if (do_functional) { 3328436SBrad.Beckmann@amd.com assert(pkt->needsResponse()); 3338436SBrad.Beckmann@amd.com pkt->setSuppressFuncError(); 3343187SN/A cachePort.sendFunctional(pkt); 3353204SN/A completeRequest(pkt); 336145SN/A } else { 3373262SN/A sendPkt(pkt); 338145SN/A } 3393187SN/A } else { 3402SN/A // write 3414628SN/A outstandingAddrs.insert(paddr); 3421298SN/A 3437657Ssteve.reinhardt@amd.com DPRINTF(MemTest, "initiating %swrite at addr %x (blk %x) value %x\n", 3447657Ssteve.reinhardt@amd.com do_functional ? "functional " : "", req->getPaddr(), 3457657Ssteve.reinhardt@amd.com blockAddr(req->getPaddr()), data & 0xff); 3464628SN/A 3478949Sandreas.hansson@arm.com PacketPtr pkt = new Packet(req, MemCmd::WriteReq); 3483187SN/A uint8_t *pkt_data = new uint8_t[req->getSize()]; 3493187SN/A pkt->dataDynamicArray(pkt_data); 3503187SN/A memcpy(pkt_data, &data, req->getSize()); 3513187SN/A MemTestSenderState *state = new MemTestSenderState(result); 3523187SN/A pkt->senderState = state; 3533187SN/A 3547657Ssteve.reinhardt@amd.com if (do_functional) { 3558436SBrad.Beckmann@amd.com pkt->setSuppressFuncError(); 3563187SN/A cachePort.sendFunctional(pkt); 3573262SN/A completeRequest(pkt); 358145SN/A } else { 3593262SN/A sendPkt(pkt); 360145SN/A } 3613187SN/A } 3622SN/A} 3632SN/A 3642SN/Avoid 3653187SN/AMemTest::doRetry() 3662SN/A{ 3678975Sandreas.hansson@arm.com if (cachePort.sendTimingReq(retryPkt)) { 3687544SN/A DPRINTF(MemTest, "accessRetry setting to false\n"); 3693187SN/A accessRetry = false; 3703187SN/A retryPkt = NULL; 3713187SN/A } 3722SN/A} 3732SN/A 3745314SN/A 3755314SN/Avoid 3765314SN/AMemTest::printAddr(Addr a) 3775314SN/A{ 3785314SN/A cachePort.printAddr(a); 3795314SN/A} 3805315SN/A 3815315SN/A 3825315SN/AMemTest * 3835315SN/AMemTestParams::create() 3845315SN/A{ 3855315SN/A return new MemTest(this); 3865315SN/A} 387