atomic.cc revision 5101
12623SN/A/* 22623SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 32623SN/A * All rights reserved. 42623SN/A * 52623SN/A * Redistribution and use in source and binary forms, with or without 62623SN/A * modification, are permitted provided that the following conditions are 72623SN/A * met: redistributions of source code must retain the above copyright 82623SN/A * notice, this list of conditions and the following disclaimer; 92623SN/A * redistributions in binary form must reproduce the above copyright 102623SN/A * notice, this list of conditions and the following disclaimer in the 112623SN/A * documentation and/or other materials provided with the distribution; 122623SN/A * neither the name of the copyright holders nor the names of its 132623SN/A * contributors may be used to endorse or promote products derived from 142623SN/A * this software without specific prior written permission. 152623SN/A * 162623SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172623SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182623SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192623SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202623SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212623SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222623SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232623SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242623SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252623SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262623SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Reinhardt 292623SN/A */ 302623SN/A 313170Sstever@eecs.umich.edu#include "arch/locked_mem.hh" 323806Ssaidi@eecs.umich.edu#include "arch/mmaped_ipr.hh" 332623SN/A#include "arch/utility.hh" 344040Ssaidi@eecs.umich.edu#include "base/bigint.hh" 352623SN/A#include "cpu/exetrace.hh" 362623SN/A#include "cpu/simple/atomic.hh" 373348Sbinkertn@umich.edu#include "mem/packet.hh" 383348Sbinkertn@umich.edu#include "mem/packet_access.hh" 394762Snate@binkert.org#include "params/AtomicSimpleCPU.hh" 402901Ssaidi@eecs.umich.edu#include "sim/system.hh" 412623SN/A 422623SN/Ausing namespace std; 432623SN/Ausing namespace TheISA; 442623SN/A 452623SN/AAtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c) 462623SN/A : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c) 472623SN/A{ 482623SN/A} 492623SN/A 502623SN/A 512623SN/Avoid 522623SN/AAtomicSimpleCPU::TickEvent::process() 532623SN/A{ 542623SN/A cpu->tick(); 552623SN/A} 562623SN/A 572623SN/Aconst char * 582623SN/AAtomicSimpleCPU::TickEvent::description() 592623SN/A{ 604873Sstever@eecs.umich.edu return "AtomicSimpleCPU tick"; 612623SN/A} 622623SN/A 632856Srdreslin@umich.eduPort * 642856Srdreslin@umich.eduAtomicSimpleCPU::getPort(const std::string &if_name, int idx) 652856Srdreslin@umich.edu{ 662856Srdreslin@umich.edu if (if_name == "dcache_port") 672856Srdreslin@umich.edu return &dcachePort; 682856Srdreslin@umich.edu else if (if_name == "icache_port") 692856Srdreslin@umich.edu return &icachePort; 704968Sacolyte@umich.edu else if (if_name == "physmem_port") { 714968Sacolyte@umich.edu hasPhysMemPort = true; 724968Sacolyte@umich.edu return &physmemPort; 734968Sacolyte@umich.edu } 742856Srdreslin@umich.edu else 752856Srdreslin@umich.edu panic("No Such Port\n"); 762856Srdreslin@umich.edu} 772623SN/A 782623SN/Avoid 792623SN/AAtomicSimpleCPU::init() 802623SN/A{ 812623SN/A BaseCPU::init(); 822623SN/A#if FULL_SYSTEM 832680Sktlim@umich.edu for (int i = 0; i < threadContexts.size(); ++i) { 842680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 852623SN/A 862623SN/A // initialize CPU, including PC 872680Sktlim@umich.edu TheISA::initCPU(tc, tc->readCpuId()); 882623SN/A } 892623SN/A#endif 904968Sacolyte@umich.edu if (hasPhysMemPort) { 914968Sacolyte@umich.edu bool snoop = false; 924968Sacolyte@umich.edu AddrRangeList pmAddrList; 934968Sacolyte@umich.edu physmemPort.getPeerAddressRanges(pmAddrList, snoop); 944968Sacolyte@umich.edu physMemAddr = *pmAddrList.begin(); 954968Sacolyte@umich.edu } 962623SN/A} 972623SN/A 982623SN/Abool 993349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvTiming(PacketPtr pkt) 1002623SN/A{ 1013184Srdreslin@umich.edu panic("AtomicSimpleCPU doesn't expect recvTiming callback!"); 1022623SN/A return true; 1032623SN/A} 1042623SN/A 1052623SN/ATick 1063349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt) 1072623SN/A{ 1083310Srdreslin@umich.edu //Snooping a coherence request, just return 1093649Srdreslin@umich.edu return 0; 1102623SN/A} 1112623SN/A 1122623SN/Avoid 1133349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt) 1142623SN/A{ 1153184Srdreslin@umich.edu //No internal storage to update, just return 1163184Srdreslin@umich.edu return; 1172623SN/A} 1182623SN/A 1192623SN/Avoid 1202623SN/AAtomicSimpleCPU::CpuPort::recvStatusChange(Status status) 1212623SN/A{ 1223647Srdreslin@umich.edu if (status == RangeChange) { 1233647Srdreslin@umich.edu if (!snoopRangeSent) { 1243647Srdreslin@umich.edu snoopRangeSent = true; 1253647Srdreslin@umich.edu sendStatusChange(Port::RangeChange); 1263647Srdreslin@umich.edu } 1272626SN/A return; 1283647Srdreslin@umich.edu } 1292626SN/A 1302623SN/A panic("AtomicSimpleCPU doesn't expect recvStatusChange callback!"); 1312623SN/A} 1322623SN/A 1332657Ssaidi@eecs.umich.eduvoid 1342623SN/AAtomicSimpleCPU::CpuPort::recvRetry() 1352623SN/A{ 1362623SN/A panic("AtomicSimpleCPU doesn't expect recvRetry callback!"); 1372623SN/A} 1382623SN/A 1394192Sktlim@umich.eduvoid 1404192Sktlim@umich.eduAtomicSimpleCPU::DcachePort::setPeer(Port *port) 1414192Sktlim@umich.edu{ 1424192Sktlim@umich.edu Port::setPeer(port); 1434192Sktlim@umich.edu 1444192Sktlim@umich.edu#if FULL_SYSTEM 1454192Sktlim@umich.edu // Update the ThreadContext's memory ports (Functional/Virtual 1464192Sktlim@umich.edu // Ports) 1474192Sktlim@umich.edu cpu->tcBase()->connectMemPorts(); 1484192Sktlim@umich.edu#endif 1494192Sktlim@umich.edu} 1502623SN/A 1512623SN/AAtomicSimpleCPU::AtomicSimpleCPU(Params *p) 1522623SN/A : BaseSimpleCPU(p), tickEvent(this), 1532623SN/A width(p->width), simulate_stalls(p->simulate_stalls), 1544968Sacolyte@umich.edu icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this), 1554968Sacolyte@umich.edu physmemPort(name() + "-iport", this), hasPhysMemPort(false) 1562623SN/A{ 1572623SN/A _status = Idle; 1582623SN/A 1593647Srdreslin@umich.edu icachePort.snoopRangeSent = false; 1603647Srdreslin@umich.edu dcachePort.snoopRangeSent = false; 1613647Srdreslin@umich.edu 1624870Sstever@eecs.umich.edu ifetch_req.setThreadContext(p->cpu_id, 0); // Add thread ID if we add MT 1634870Sstever@eecs.umich.edu data_read_req.setThreadContext(p->cpu_id, 0); // Add thread ID here too 1644870Sstever@eecs.umich.edu data_write_req.setThreadContext(p->cpu_id, 0); // Add thread ID here too 1652623SN/A} 1662623SN/A 1672623SN/A 1682623SN/AAtomicSimpleCPU::~AtomicSimpleCPU() 1692623SN/A{ 1702623SN/A} 1712623SN/A 1722623SN/Avoid 1732623SN/AAtomicSimpleCPU::serialize(ostream &os) 1742623SN/A{ 1752915Sktlim@umich.edu SimObject::State so_state = SimObject::getState(); 1762915Sktlim@umich.edu SERIALIZE_ENUM(so_state); 1773177Shsul@eecs.umich.edu Status _status = status(); 1783177Shsul@eecs.umich.edu SERIALIZE_ENUM(_status); 1793145Shsul@eecs.umich.edu BaseSimpleCPU::serialize(os); 1802623SN/A nameOut(os, csprintf("%s.tickEvent", name())); 1812623SN/A tickEvent.serialize(os); 1822623SN/A} 1832623SN/A 1842623SN/Avoid 1852623SN/AAtomicSimpleCPU::unserialize(Checkpoint *cp, const string §ion) 1862623SN/A{ 1872915Sktlim@umich.edu SimObject::State so_state; 1882915Sktlim@umich.edu UNSERIALIZE_ENUM(so_state); 1893177Shsul@eecs.umich.edu UNSERIALIZE_ENUM(_status); 1903145Shsul@eecs.umich.edu BaseSimpleCPU::unserialize(cp, section); 1912915Sktlim@umich.edu tickEvent.unserialize(cp, csprintf("%s.tickEvent", section)); 1922915Sktlim@umich.edu} 1932915Sktlim@umich.edu 1942915Sktlim@umich.eduvoid 1952915Sktlim@umich.eduAtomicSimpleCPU::resume() 1962915Sktlim@umich.edu{ 1974940Snate@binkert.org DPRINTF(SimpleCPU, "Resume\n"); 1983324Shsul@eecs.umich.edu if (_status != SwitchedOut && _status != Idle) { 1994762Snate@binkert.org assert(system->getMemoryMode() == Enums::atomic); 2003324Shsul@eecs.umich.edu 2013324Shsul@eecs.umich.edu changeState(SimObject::Running); 2023324Shsul@eecs.umich.edu if (thread->status() == ThreadContext::Active) { 2033431Sgblack@eecs.umich.edu if (!tickEvent.scheduled()) { 2043495Sktlim@umich.edu tickEvent.schedule(nextCycle()); 2053431Sgblack@eecs.umich.edu } 2063324Shsul@eecs.umich.edu } 2072915Sktlim@umich.edu } 2082623SN/A} 2092623SN/A 2102623SN/Avoid 2112798Sktlim@umich.eduAtomicSimpleCPU::switchOut() 2122623SN/A{ 2132798Sktlim@umich.edu assert(status() == Running || status() == Idle); 2142798Sktlim@umich.edu _status = SwitchedOut; 2152623SN/A 2162798Sktlim@umich.edu tickEvent.squash(); 2172623SN/A} 2182623SN/A 2192623SN/A 2202623SN/Avoid 2212623SN/AAtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU) 2222623SN/A{ 2234192Sktlim@umich.edu BaseCPU::takeOverFrom(oldCPU, &icachePort, &dcachePort); 2242623SN/A 2252623SN/A assert(!tickEvent.scheduled()); 2262623SN/A 2272680Sktlim@umich.edu // if any of this CPU's ThreadContexts are active, mark the CPU as 2282623SN/A // running and schedule its tick event. 2292680Sktlim@umich.edu for (int i = 0; i < threadContexts.size(); ++i) { 2302680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 2312680Sktlim@umich.edu if (tc->status() == ThreadContext::Active && _status != Running) { 2322623SN/A _status = Running; 2333495Sktlim@umich.edu tickEvent.schedule(nextCycle()); 2342623SN/A break; 2352623SN/A } 2362623SN/A } 2373512Sktlim@umich.edu if (_status != Running) { 2383512Sktlim@umich.edu _status = Idle; 2393512Sktlim@umich.edu } 2402623SN/A} 2412623SN/A 2422623SN/A 2432623SN/Avoid 2442623SN/AAtomicSimpleCPU::activateContext(int thread_num, int delay) 2452623SN/A{ 2464940Snate@binkert.org DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay); 2474940Snate@binkert.org 2482623SN/A assert(thread_num == 0); 2492683Sktlim@umich.edu assert(thread); 2502623SN/A 2512623SN/A assert(_status == Idle); 2522623SN/A assert(!tickEvent.scheduled()); 2532623SN/A 2542623SN/A notIdleFraction++; 2555101Ssaidi@eecs.umich.edu numCycles += tickToCycles(thread->lastActivate - thread->lastSuspend); 2563686Sktlim@umich.edu 2573430Sgblack@eecs.umich.edu //Make sure ticks are still on multiples of cycles 2585100Ssaidi@eecs.umich.edu tickEvent.schedule(nextCycle(curTick + ticks(delay))); 2592623SN/A _status = Running; 2602623SN/A} 2612623SN/A 2622623SN/A 2632623SN/Avoid 2642623SN/AAtomicSimpleCPU::suspendContext(int thread_num) 2652623SN/A{ 2664940Snate@binkert.org DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num); 2674940Snate@binkert.org 2682623SN/A assert(thread_num == 0); 2692683Sktlim@umich.edu assert(thread); 2702623SN/A 2712623SN/A assert(_status == Running); 2722626SN/A 2732626SN/A // tick event may not be scheduled if this gets called from inside 2742626SN/A // an instruction's execution, e.g. "quiesce" 2752626SN/A if (tickEvent.scheduled()) 2762626SN/A tickEvent.deschedule(); 2772623SN/A 2782623SN/A notIdleFraction--; 2792623SN/A _status = Idle; 2802623SN/A} 2812623SN/A 2822623SN/A 2832623SN/Atemplate <class T> 2842623SN/AFault 2852623SN/AAtomicSimpleCPU::read(Addr addr, T &data, unsigned flags) 2862623SN/A{ 2873169Sstever@eecs.umich.edu // use the CPU's statically allocated read request and packet objects 2884870Sstever@eecs.umich.edu Request *req = &data_read_req; 2892623SN/A 2902623SN/A if (traceData) { 2912623SN/A traceData->setAddr(addr); 2922623SN/A } 2932623SN/A 2944999Sgblack@eecs.umich.edu //The block size of our peer. 2954999Sgblack@eecs.umich.edu int blockSize = dcachePort.peerBlockSize(); 2964999Sgblack@eecs.umich.edu //The size of the data we're trying to read. 2974999Sgblack@eecs.umich.edu int dataSize = sizeof(T); 2982623SN/A 2994999Sgblack@eecs.umich.edu uint8_t * dataPtr = (uint8_t *)&data; 3002623SN/A 3014999Sgblack@eecs.umich.edu //The address of the second part of this access if it needs to be split 3024999Sgblack@eecs.umich.edu //across a cache line boundary. 3034999Sgblack@eecs.umich.edu Addr secondAddr = roundDown(addr + dataSize - 1, blockSize); 3044999Sgblack@eecs.umich.edu 3054999Sgblack@eecs.umich.edu if(secondAddr > addr) 3064999Sgblack@eecs.umich.edu dataSize = secondAddr - addr; 3074999Sgblack@eecs.umich.edu 3084999Sgblack@eecs.umich.edu dcache_latency = 0; 3094999Sgblack@eecs.umich.edu 3104999Sgblack@eecs.umich.edu while(1) { 3114999Sgblack@eecs.umich.edu req->setVirt(0, addr, dataSize, flags, thread->readPC()); 3124999Sgblack@eecs.umich.edu 3134999Sgblack@eecs.umich.edu // translate to physical address 3144999Sgblack@eecs.umich.edu Fault fault = thread->translateDataReadReq(req); 3154999Sgblack@eecs.umich.edu 3164999Sgblack@eecs.umich.edu // Now do the access. 3174999Sgblack@eecs.umich.edu if (fault == NoFault) { 3184999Sgblack@eecs.umich.edu Packet pkt = Packet(req, 3194999Sgblack@eecs.umich.edu req->isLocked() ? MemCmd::LoadLockedReq : MemCmd::ReadReq, 3204999Sgblack@eecs.umich.edu Packet::Broadcast); 3214999Sgblack@eecs.umich.edu pkt.dataStatic(dataPtr); 3224999Sgblack@eecs.umich.edu 3234999Sgblack@eecs.umich.edu if (req->isMmapedIpr()) 3244999Sgblack@eecs.umich.edu dcache_latency += TheISA::handleIprRead(thread->getTC(), &pkt); 3254999Sgblack@eecs.umich.edu else { 3264999Sgblack@eecs.umich.edu if (hasPhysMemPort && pkt.getAddr() == physMemAddr) 3274999Sgblack@eecs.umich.edu dcache_latency += physmemPort.sendAtomic(&pkt); 3284999Sgblack@eecs.umich.edu else 3294999Sgblack@eecs.umich.edu dcache_latency += dcachePort.sendAtomic(&pkt); 3304999Sgblack@eecs.umich.edu } 3314999Sgblack@eecs.umich.edu dcache_access = true; 3325012Sgblack@eecs.umich.edu 3334999Sgblack@eecs.umich.edu assert(!pkt.isError()); 3344999Sgblack@eecs.umich.edu 3354999Sgblack@eecs.umich.edu if (req->isLocked()) { 3364999Sgblack@eecs.umich.edu TheISA::handleLockedRead(thread, req); 3374999Sgblack@eecs.umich.edu } 3384968Sacolyte@umich.edu } 3394986Ssaidi@eecs.umich.edu 3404999Sgblack@eecs.umich.edu // This will need a new way to tell if it has a dcache attached. 3414999Sgblack@eecs.umich.edu if (req->isUncacheable()) 3424999Sgblack@eecs.umich.edu recordEvent("Uncached Read"); 3434762Snate@binkert.org 3444999Sgblack@eecs.umich.edu //If there's a fault, return it 3454999Sgblack@eecs.umich.edu if (fault != NoFault) 3464999Sgblack@eecs.umich.edu return fault; 3474999Sgblack@eecs.umich.edu //If we don't need to access a second cache line, stop now. 3484999Sgblack@eecs.umich.edu if (secondAddr <= addr) 3494999Sgblack@eecs.umich.edu { 3504999Sgblack@eecs.umich.edu data = gtoh(data); 3514999Sgblack@eecs.umich.edu return fault; 3524968Sacolyte@umich.edu } 3533170Sstever@eecs.umich.edu 3544999Sgblack@eecs.umich.edu /* 3554999Sgblack@eecs.umich.edu * Set up for accessing the second cache line. 3564999Sgblack@eecs.umich.edu */ 3574999Sgblack@eecs.umich.edu 3584999Sgblack@eecs.umich.edu //Move the pointer we're reading into to the correct location. 3594999Sgblack@eecs.umich.edu dataPtr += dataSize; 3604999Sgblack@eecs.umich.edu //Adjust the size to get the remaining bytes. 3614999Sgblack@eecs.umich.edu dataSize = addr + sizeof(T) - secondAddr; 3624999Sgblack@eecs.umich.edu //And access the right address. 3634999Sgblack@eecs.umich.edu addr = secondAddr; 3642623SN/A } 3652623SN/A} 3662623SN/A 3672623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS 3682623SN/A 3692623SN/Atemplate 3702623SN/AFault 3714115Ssaidi@eecs.umich.eduAtomicSimpleCPU::read(Addr addr, Twin32_t &data, unsigned flags); 3724115Ssaidi@eecs.umich.edu 3734115Ssaidi@eecs.umich.edutemplate 3744115Ssaidi@eecs.umich.eduFault 3754040Ssaidi@eecs.umich.eduAtomicSimpleCPU::read(Addr addr, Twin64_t &data, unsigned flags); 3764040Ssaidi@eecs.umich.edu 3774040Ssaidi@eecs.umich.edutemplate 3784040Ssaidi@eecs.umich.eduFault 3792623SN/AAtomicSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags); 3802623SN/A 3812623SN/Atemplate 3822623SN/AFault 3832623SN/AAtomicSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags); 3842623SN/A 3852623SN/Atemplate 3862623SN/AFault 3872623SN/AAtomicSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags); 3882623SN/A 3892623SN/Atemplate 3902623SN/AFault 3912623SN/AAtomicSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags); 3922623SN/A 3932623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS 3942623SN/A 3952623SN/Atemplate<> 3962623SN/AFault 3972623SN/AAtomicSimpleCPU::read(Addr addr, double &data, unsigned flags) 3982623SN/A{ 3992623SN/A return read(addr, *(uint64_t*)&data, flags); 4002623SN/A} 4012623SN/A 4022623SN/Atemplate<> 4032623SN/AFault 4042623SN/AAtomicSimpleCPU::read(Addr addr, float &data, unsigned flags) 4052623SN/A{ 4062623SN/A return read(addr, *(uint32_t*)&data, flags); 4072623SN/A} 4082623SN/A 4092623SN/A 4102623SN/Atemplate<> 4112623SN/AFault 4122623SN/AAtomicSimpleCPU::read(Addr addr, int32_t &data, unsigned flags) 4132623SN/A{ 4142623SN/A return read(addr, (uint32_t&)data, flags); 4152623SN/A} 4162623SN/A 4172623SN/A 4182623SN/Atemplate <class T> 4192623SN/AFault 4202623SN/AAtomicSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res) 4212623SN/A{ 4223169Sstever@eecs.umich.edu // use the CPU's statically allocated write request and packet objects 4234870Sstever@eecs.umich.edu Request *req = &data_write_req; 4242623SN/A 4252623SN/A if (traceData) { 4262623SN/A traceData->setAddr(addr); 4272623SN/A } 4282623SN/A 4294999Sgblack@eecs.umich.edu //The block size of our peer. 4304999Sgblack@eecs.umich.edu int blockSize = dcachePort.peerBlockSize(); 4314999Sgblack@eecs.umich.edu //The size of the data we're trying to read. 4324999Sgblack@eecs.umich.edu int dataSize = sizeof(T); 4332623SN/A 4344999Sgblack@eecs.umich.edu uint8_t * dataPtr = (uint8_t *)&data; 4352623SN/A 4364999Sgblack@eecs.umich.edu //The address of the second part of this access if it needs to be split 4374999Sgblack@eecs.umich.edu //across a cache line boundary. 4384999Sgblack@eecs.umich.edu Addr secondAddr = roundDown(addr + dataSize - 1, blockSize); 4394999Sgblack@eecs.umich.edu 4404999Sgblack@eecs.umich.edu if(secondAddr > addr) 4414999Sgblack@eecs.umich.edu dataSize = secondAddr - addr; 4424999Sgblack@eecs.umich.edu 4434999Sgblack@eecs.umich.edu dcache_latency = 0; 4444999Sgblack@eecs.umich.edu 4454999Sgblack@eecs.umich.edu while(1) { 4464999Sgblack@eecs.umich.edu req->setVirt(0, addr, dataSize, flags, thread->readPC()); 4474999Sgblack@eecs.umich.edu 4484999Sgblack@eecs.umich.edu // translate to physical address 4494999Sgblack@eecs.umich.edu Fault fault = thread->translateDataWriteReq(req); 4504999Sgblack@eecs.umich.edu 4514999Sgblack@eecs.umich.edu // Now do the access. 4524999Sgblack@eecs.umich.edu if (fault == NoFault) { 4534999Sgblack@eecs.umich.edu MemCmd cmd = MemCmd::WriteReq; // default 4544999Sgblack@eecs.umich.edu bool do_access = true; // flag to suppress cache access 4554999Sgblack@eecs.umich.edu 4564999Sgblack@eecs.umich.edu if (req->isLocked()) { 4574999Sgblack@eecs.umich.edu cmd = MemCmd::StoreCondReq; 4584999Sgblack@eecs.umich.edu do_access = TheISA::handleLockedWrite(thread, req); 4594999Sgblack@eecs.umich.edu } else if (req->isSwap()) { 4604999Sgblack@eecs.umich.edu cmd = MemCmd::SwapReq; 4614999Sgblack@eecs.umich.edu if (req->isCondSwap()) { 4624999Sgblack@eecs.umich.edu assert(res); 4634999Sgblack@eecs.umich.edu req->setExtraData(*res); 4644999Sgblack@eecs.umich.edu } 4654999Sgblack@eecs.umich.edu } 4664999Sgblack@eecs.umich.edu 4674999Sgblack@eecs.umich.edu if (do_access) { 4684999Sgblack@eecs.umich.edu Packet pkt = Packet(req, cmd, Packet::Broadcast); 4694999Sgblack@eecs.umich.edu pkt.dataStatic(dataPtr); 4704999Sgblack@eecs.umich.edu 4714999Sgblack@eecs.umich.edu if (req->isMmapedIpr()) { 4724999Sgblack@eecs.umich.edu dcache_latency += 4734999Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread->getTC(), &pkt); 4744999Sgblack@eecs.umich.edu } else { 4754999Sgblack@eecs.umich.edu //XXX This needs to be outside of the loop in order to 4764999Sgblack@eecs.umich.edu //work properly for cache line boundary crossing 4774999Sgblack@eecs.umich.edu //accesses in transendian simulations. 4784999Sgblack@eecs.umich.edu data = htog(data); 4794999Sgblack@eecs.umich.edu if (hasPhysMemPort && pkt.getAddr() == physMemAddr) 4804999Sgblack@eecs.umich.edu dcache_latency += physmemPort.sendAtomic(&pkt); 4814999Sgblack@eecs.umich.edu else 4824999Sgblack@eecs.umich.edu dcache_latency += dcachePort.sendAtomic(&pkt); 4834999Sgblack@eecs.umich.edu } 4844999Sgblack@eecs.umich.edu dcache_access = true; 4854999Sgblack@eecs.umich.edu assert(!pkt.isError()); 4864999Sgblack@eecs.umich.edu 4874999Sgblack@eecs.umich.edu if (req->isSwap()) { 4884999Sgblack@eecs.umich.edu assert(res); 4894999Sgblack@eecs.umich.edu *res = pkt.get<T>(); 4904999Sgblack@eecs.umich.edu } 4914999Sgblack@eecs.umich.edu } 4924999Sgblack@eecs.umich.edu 4934999Sgblack@eecs.umich.edu if (res && !req->isSwap()) { 4944999Sgblack@eecs.umich.edu *res = req->getExtraData(); 4954878Sstever@eecs.umich.edu } 4964040Ssaidi@eecs.umich.edu } 4974040Ssaidi@eecs.umich.edu 4984999Sgblack@eecs.umich.edu // This will need a new way to tell if it's hooked up to a cache or not. 4994999Sgblack@eecs.umich.edu if (req->isUncacheable()) 5004999Sgblack@eecs.umich.edu recordEvent("Uncached Write"); 5012631SN/A 5024999Sgblack@eecs.umich.edu //If there's a fault or we don't need to access a second cache line, 5034999Sgblack@eecs.umich.edu //stop now. 5044999Sgblack@eecs.umich.edu if (fault != NoFault || secondAddr <= addr) 5054999Sgblack@eecs.umich.edu { 5064999Sgblack@eecs.umich.edu // If the write needs to have a fault on the access, consider 5074999Sgblack@eecs.umich.edu // calling changeStatus() and changing it to "bad addr write" 5084999Sgblack@eecs.umich.edu // or something. 5094999Sgblack@eecs.umich.edu return fault; 5103170Sstever@eecs.umich.edu } 5113170Sstever@eecs.umich.edu 5124999Sgblack@eecs.umich.edu /* 5134999Sgblack@eecs.umich.edu * Set up for accessing the second cache line. 5144999Sgblack@eecs.umich.edu */ 5154999Sgblack@eecs.umich.edu 5164999Sgblack@eecs.umich.edu //Move the pointer we're reading into to the correct location. 5174999Sgblack@eecs.umich.edu dataPtr += dataSize; 5184999Sgblack@eecs.umich.edu //Adjust the size to get the remaining bytes. 5194999Sgblack@eecs.umich.edu dataSize = addr + sizeof(T) - secondAddr; 5204999Sgblack@eecs.umich.edu //And access the right address. 5214999Sgblack@eecs.umich.edu addr = secondAddr; 5222623SN/A } 5232623SN/A} 5242623SN/A 5252623SN/A 5262623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS 5274224Sgblack@eecs.umich.edu 5284224Sgblack@eecs.umich.edutemplate 5294224Sgblack@eecs.umich.eduFault 5304224Sgblack@eecs.umich.eduAtomicSimpleCPU::write(Twin32_t data, Addr addr, 5314224Sgblack@eecs.umich.edu unsigned flags, uint64_t *res); 5324224Sgblack@eecs.umich.edu 5334224Sgblack@eecs.umich.edutemplate 5344224Sgblack@eecs.umich.eduFault 5354224Sgblack@eecs.umich.eduAtomicSimpleCPU::write(Twin64_t data, Addr addr, 5364224Sgblack@eecs.umich.edu unsigned flags, uint64_t *res); 5374224Sgblack@eecs.umich.edu 5382623SN/Atemplate 5392623SN/AFault 5402623SN/AAtomicSimpleCPU::write(uint64_t data, Addr addr, 5412623SN/A unsigned flags, uint64_t *res); 5422623SN/A 5432623SN/Atemplate 5442623SN/AFault 5452623SN/AAtomicSimpleCPU::write(uint32_t data, Addr addr, 5462623SN/A unsigned flags, uint64_t *res); 5472623SN/A 5482623SN/Atemplate 5492623SN/AFault 5502623SN/AAtomicSimpleCPU::write(uint16_t data, Addr addr, 5512623SN/A unsigned flags, uint64_t *res); 5522623SN/A 5532623SN/Atemplate 5542623SN/AFault 5552623SN/AAtomicSimpleCPU::write(uint8_t data, Addr addr, 5562623SN/A unsigned flags, uint64_t *res); 5572623SN/A 5582623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS 5592623SN/A 5602623SN/Atemplate<> 5612623SN/AFault 5622623SN/AAtomicSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res) 5632623SN/A{ 5642623SN/A return write(*(uint64_t*)&data, addr, flags, res); 5652623SN/A} 5662623SN/A 5672623SN/Atemplate<> 5682623SN/AFault 5692623SN/AAtomicSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res) 5702623SN/A{ 5712623SN/A return write(*(uint32_t*)&data, addr, flags, res); 5722623SN/A} 5732623SN/A 5742623SN/A 5752623SN/Atemplate<> 5762623SN/AFault 5772623SN/AAtomicSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res) 5782623SN/A{ 5792623SN/A return write((uint32_t)data, addr, flags, res); 5802623SN/A} 5812623SN/A 5822623SN/A 5832623SN/Avoid 5842623SN/AAtomicSimpleCPU::tick() 5852623SN/A{ 5864940Snate@binkert.org DPRINTF(SimpleCPU, "Tick\n"); 5874940Snate@binkert.org 5885100Ssaidi@eecs.umich.edu Tick latency = ticks(1); // instruction takes one cycle by default 5892623SN/A 5902623SN/A for (int i = 0; i < width; ++i) { 5912623SN/A numCycles++; 5922623SN/A 5933387Sgblack@eecs.umich.edu if (!curStaticInst || !curStaticInst->isDelayedCommit()) 5943387Sgblack@eecs.umich.edu checkForInterrupts(); 5952626SN/A 5964870Sstever@eecs.umich.edu Fault fault = setupFetchRequest(&ifetch_req); 5972623SN/A 5982623SN/A if (fault == NoFault) { 5994182Sgblack@eecs.umich.edu Tick icache_latency = 0; 6004182Sgblack@eecs.umich.edu bool icache_access = false; 6014182Sgblack@eecs.umich.edu dcache_access = false; // assume no dcache access 6022662Sstever@eecs.umich.edu 6034182Sgblack@eecs.umich.edu //Fetch more instruction memory if necessary 6044593Sgblack@eecs.umich.edu //if(predecoder.needMoreBytes()) 6054593Sgblack@eecs.umich.edu //{ 6064182Sgblack@eecs.umich.edu icache_access = true; 6074870Sstever@eecs.umich.edu Packet ifetch_pkt = Packet(&ifetch_req, MemCmd::ReadReq, 6084870Sstever@eecs.umich.edu Packet::Broadcast); 6094870Sstever@eecs.umich.edu ifetch_pkt.dataStatic(&inst); 6102623SN/A 6114968Sacolyte@umich.edu if (hasPhysMemPort && ifetch_pkt.getAddr() == physMemAddr) 6124968Sacolyte@umich.edu icache_latency = physmemPort.sendAtomic(&ifetch_pkt); 6134968Sacolyte@umich.edu else 6144968Sacolyte@umich.edu icache_latency = icachePort.sendAtomic(&ifetch_pkt); 6154968Sacolyte@umich.edu 6164986Ssaidi@eecs.umich.edu assert(!ifetch_pkt.isError()); 6174968Sacolyte@umich.edu 6184182Sgblack@eecs.umich.edu // ifetch_req is initialized to read the instruction directly 6194182Sgblack@eecs.umich.edu // into the CPU object's inst field. 6204593Sgblack@eecs.umich.edu //} 6214182Sgblack@eecs.umich.edu 6222623SN/A preExecute(); 6233814Ssaidi@eecs.umich.edu 6245001Sgblack@eecs.umich.edu if (curStaticInst) { 6254182Sgblack@eecs.umich.edu fault = curStaticInst->execute(this, traceData); 6264998Sgblack@eecs.umich.edu 6274998Sgblack@eecs.umich.edu // keep an instruction count 6284998Sgblack@eecs.umich.edu if (fault == NoFault) 6294998Sgblack@eecs.umich.edu countInst(); 6305001Sgblack@eecs.umich.edu else if (traceData) { 6315001Sgblack@eecs.umich.edu // If there was a fault, we should trace this instruction. 6325001Sgblack@eecs.umich.edu delete traceData; 6335001Sgblack@eecs.umich.edu traceData = NULL; 6345001Sgblack@eecs.umich.edu } 6354998Sgblack@eecs.umich.edu 6364182Sgblack@eecs.umich.edu postExecute(); 6374182Sgblack@eecs.umich.edu } 6382623SN/A 6393814Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 6404539Sgblack@eecs.umich.edu if (curStaticInst && (!curStaticInst->isMicroop() || 6414539Sgblack@eecs.umich.edu curStaticInst->isFirstMicroop())) 6423814Ssaidi@eecs.umich.edu instCnt++; 6433814Ssaidi@eecs.umich.edu 6442623SN/A if (simulate_stalls) { 6454182Sgblack@eecs.umich.edu Tick icache_stall = 6465100Ssaidi@eecs.umich.edu icache_access ? icache_latency - ticks(1) : 0; 6472623SN/A Tick dcache_stall = 6485100Ssaidi@eecs.umich.edu dcache_access ? dcache_latency - ticks(1) : 0; 6495100Ssaidi@eecs.umich.edu Tick stall_cycles = (icache_stall + dcache_stall) / ticks(1); 6505100Ssaidi@eecs.umich.edu if (ticks(stall_cycles) < (icache_stall + dcache_stall)) 6515100Ssaidi@eecs.umich.edu latency += ticks(stall_cycles+1); 6522803Ssaidi@eecs.umich.edu else 6535100Ssaidi@eecs.umich.edu latency += ticks(stall_cycles); 6542623SN/A } 6552623SN/A 6562623SN/A } 6574377Sgblack@eecs.umich.edu if(fault != NoFault || !stayAtPC) 6584182Sgblack@eecs.umich.edu advancePC(fault); 6592623SN/A } 6602623SN/A 6612626SN/A if (_status != Idle) 6622626SN/A tickEvent.schedule(curTick + latency); 6632623SN/A} 6642623SN/A 6652623SN/A 6662623SN/A//////////////////////////////////////////////////////////////////////// 6672623SN/A// 6682623SN/A// AtomicSimpleCPU Simulation Object 6692623SN/A// 6704762Snate@binkert.orgAtomicSimpleCPU * 6714762Snate@binkert.orgAtomicSimpleCPUParams::create() 6722623SN/A{ 6732623SN/A AtomicSimpleCPU::Params *params = new AtomicSimpleCPU::Params(); 6744762Snate@binkert.org params->name = name; 6752623SN/A params->numberOfThreads = 1; 6762623SN/A params->max_insts_any_thread = max_insts_any_thread; 6772623SN/A params->max_insts_all_threads = max_insts_all_threads; 6782623SN/A params->max_loads_any_thread = max_loads_any_thread; 6792623SN/A params->max_loads_all_threads = max_loads_all_threads; 6803119Sktlim@umich.edu params->progress_interval = progress_interval; 6812623SN/A params->deferRegistration = defer_registration; 6823661Srdreslin@umich.edu params->phase = phase; 6832623SN/A params->clock = clock; 6842623SN/A params->functionTrace = function_trace; 6852623SN/A params->functionTraceStart = function_trace_start; 6862623SN/A params->width = width; 6872623SN/A params->simulate_stalls = simulate_stalls; 6882901Ssaidi@eecs.umich.edu params->system = system; 6893170Sstever@eecs.umich.edu params->cpu_id = cpu_id; 6904776Sgblack@eecs.umich.edu params->tracer = tracer; 6912623SN/A 6922623SN/A params->itb = itb; 6932623SN/A params->dtb = dtb; 6944997Sgblack@eecs.umich.edu#if FULL_SYSTEM 6952623SN/A params->profile = profile; 6963617Sbinkertn@umich.edu params->do_quiesce = do_quiesce; 6973617Sbinkertn@umich.edu params->do_checkpoint_insts = do_checkpoint_insts; 6983617Sbinkertn@umich.edu params->do_statistics_insts = do_statistics_insts; 6992623SN/A#else 7004762Snate@binkert.org if (workload.size() != 1) 7014762Snate@binkert.org panic("only one workload allowed"); 7024762Snate@binkert.org params->process = workload[0]; 7032623SN/A#endif 7042623SN/A 7052623SN/A AtomicSimpleCPU *cpu = new AtomicSimpleCPU(params); 7062623SN/A return cpu; 7072623SN/A} 708