atomic.cc revision 8444
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" 328105Sgblack@eecs.umich.edu#include "arch/mmapped_ipr.hh" 332623SN/A#include "arch/utility.hh" 344040Ssaidi@eecs.umich.edu#include "base/bigint.hh" 356658Snate@binkert.org#include "config/the_isa.hh" 368229Snate@binkert.org#include "cpu/simple/atomic.hh" 372623SN/A#include "cpu/exetrace.hh" 388232Snate@binkert.org#include "debug/ExecFaulting.hh" 398232Snate@binkert.org#include "debug/SimpleCPU.hh" 403348Sbinkertn@umich.edu#include "mem/packet.hh" 413348Sbinkertn@umich.edu#include "mem/packet_access.hh" 424762Snate@binkert.org#include "params/AtomicSimpleCPU.hh" 437678Sgblack@eecs.umich.edu#include "sim/faults.hh" 442901Ssaidi@eecs.umich.edu#include "sim/system.hh" 452623SN/A 462623SN/Ausing namespace std; 472623SN/Ausing namespace TheISA; 482623SN/A 492623SN/AAtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c) 505606Snate@binkert.org : Event(CPU_Tick_Pri), cpu(c) 512623SN/A{ 522623SN/A} 532623SN/A 542623SN/A 552623SN/Avoid 562623SN/AAtomicSimpleCPU::TickEvent::process() 572623SN/A{ 582623SN/A cpu->tick(); 592623SN/A} 602623SN/A 612623SN/Aconst char * 625336Shines@cs.fsu.eduAtomicSimpleCPU::TickEvent::description() const 632623SN/A{ 644873Sstever@eecs.umich.edu return "AtomicSimpleCPU tick"; 652623SN/A} 662623SN/A 672856Srdreslin@umich.eduPort * 686227Snate@binkert.orgAtomicSimpleCPU::getPort(const string &if_name, int idx) 692856Srdreslin@umich.edu{ 702856Srdreslin@umich.edu if (if_name == "dcache_port") 712856Srdreslin@umich.edu return &dcachePort; 722856Srdreslin@umich.edu else if (if_name == "icache_port") 732856Srdreslin@umich.edu return &icachePort; 744968Sacolyte@umich.edu else if (if_name == "physmem_port") { 754968Sacolyte@umich.edu hasPhysMemPort = true; 764968Sacolyte@umich.edu return &physmemPort; 774968Sacolyte@umich.edu } 782856Srdreslin@umich.edu else 792856Srdreslin@umich.edu panic("No Such Port\n"); 802856Srdreslin@umich.edu} 812623SN/A 822623SN/Avoid 832623SN/AAtomicSimpleCPU::init() 842623SN/A{ 852623SN/A BaseCPU::init(); 862623SN/A#if FULL_SYSTEM 876221Snate@binkert.org ThreadID size = threadContexts.size(); 886221Snate@binkert.org for (ThreadID i = 0; i < size; ++i) { 892680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 902623SN/A 912623SN/A // initialize CPU, including PC 925714Shsul@eecs.umich.edu TheISA::initCPU(tc, tc->contextId()); 932623SN/A } 942623SN/A#endif 954968Sacolyte@umich.edu if (hasPhysMemPort) { 964968Sacolyte@umich.edu bool snoop = false; 974968Sacolyte@umich.edu AddrRangeList pmAddrList; 984968Sacolyte@umich.edu physmemPort.getPeerAddressRanges(pmAddrList, snoop); 994968Sacolyte@umich.edu physMemAddr = *pmAddrList.begin(); 1004968Sacolyte@umich.edu } 1015714Shsul@eecs.umich.edu // Atomic doesn't do MT right now, so contextId == threadId 1025712Shsul@eecs.umich.edu ifetch_req.setThreadContext(_cpuId, 0); // Add thread ID if we add MT 1035712Shsul@eecs.umich.edu data_read_req.setThreadContext(_cpuId, 0); // Add thread ID here too 1045712Shsul@eecs.umich.edu data_write_req.setThreadContext(_cpuId, 0); // Add thread ID here too 1052623SN/A} 1062623SN/A 1072623SN/Abool 1083349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvTiming(PacketPtr pkt) 1092623SN/A{ 1103184Srdreslin@umich.edu panic("AtomicSimpleCPU doesn't expect recvTiming callback!"); 1112623SN/A return true; 1122623SN/A} 1132623SN/A 1142623SN/ATick 1153349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt) 1162623SN/A{ 1173310Srdreslin@umich.edu //Snooping a coherence request, just return 1183649Srdreslin@umich.edu return 0; 1192623SN/A} 1202623SN/A 1212623SN/Avoid 1223349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt) 1232623SN/A{ 1243184Srdreslin@umich.edu //No internal storage to update, just return 1253184Srdreslin@umich.edu return; 1262623SN/A} 1272623SN/A 1282623SN/Avoid 1292623SN/AAtomicSimpleCPU::CpuPort::recvStatusChange(Status status) 1302623SN/A{ 1313647Srdreslin@umich.edu if (status == RangeChange) { 1323647Srdreslin@umich.edu if (!snoopRangeSent) { 1333647Srdreslin@umich.edu snoopRangeSent = true; 1343647Srdreslin@umich.edu sendStatusChange(Port::RangeChange); 1353647Srdreslin@umich.edu } 1362626SN/A return; 1373647Srdreslin@umich.edu } 1382626SN/A 1392623SN/A panic("AtomicSimpleCPU doesn't expect recvStatusChange callback!"); 1402623SN/A} 1412623SN/A 1422657Ssaidi@eecs.umich.eduvoid 1432623SN/AAtomicSimpleCPU::CpuPort::recvRetry() 1442623SN/A{ 1452623SN/A panic("AtomicSimpleCPU doesn't expect recvRetry callback!"); 1462623SN/A} 1472623SN/A 1484192Sktlim@umich.eduvoid 1494192Sktlim@umich.eduAtomicSimpleCPU::DcachePort::setPeer(Port *port) 1504192Sktlim@umich.edu{ 1514192Sktlim@umich.edu Port::setPeer(port); 1524192Sktlim@umich.edu 1534192Sktlim@umich.edu#if FULL_SYSTEM 1544192Sktlim@umich.edu // Update the ThreadContext's memory ports (Functional/Virtual 1554192Sktlim@umich.edu // Ports) 1565497Ssaidi@eecs.umich.edu cpu->tcBase()->connectMemPorts(cpu->tcBase()); 1574192Sktlim@umich.edu#endif 1584192Sktlim@umich.edu} 1592623SN/A 1605529Snate@binkert.orgAtomicSimpleCPU::AtomicSimpleCPU(AtomicSimpleCPUParams *p) 1616078Sgblack@eecs.umich.edu : BaseSimpleCPU(p), tickEvent(this), width(p->width), locked(false), 1625487Snate@binkert.org simulate_data_stalls(p->simulate_data_stalls), 1635487Snate@binkert.org simulate_inst_stalls(p->simulate_inst_stalls), 1644968Sacolyte@umich.edu icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this), 1654968Sacolyte@umich.edu physmemPort(name() + "-iport", this), hasPhysMemPort(false) 1662623SN/A{ 1672623SN/A _status = Idle; 1682623SN/A 1693647Srdreslin@umich.edu icachePort.snoopRangeSent = false; 1703647Srdreslin@umich.edu dcachePort.snoopRangeSent = false; 1713647Srdreslin@umich.edu 1722623SN/A} 1732623SN/A 1742623SN/A 1752623SN/AAtomicSimpleCPU::~AtomicSimpleCPU() 1762623SN/A{ 1776775SBrad.Beckmann@amd.com if (tickEvent.scheduled()) { 1786775SBrad.Beckmann@amd.com deschedule(tickEvent); 1796775SBrad.Beckmann@amd.com } 1802623SN/A} 1812623SN/A 1822623SN/Avoid 1832623SN/AAtomicSimpleCPU::serialize(ostream &os) 1842623SN/A{ 1852915Sktlim@umich.edu SimObject::State so_state = SimObject::getState(); 1862915Sktlim@umich.edu SERIALIZE_ENUM(so_state); 1876078Sgblack@eecs.umich.edu SERIALIZE_SCALAR(locked); 1883145Shsul@eecs.umich.edu BaseSimpleCPU::serialize(os); 1892623SN/A nameOut(os, csprintf("%s.tickEvent", name())); 1902623SN/A tickEvent.serialize(os); 1912623SN/A} 1922623SN/A 1932623SN/Avoid 1942623SN/AAtomicSimpleCPU::unserialize(Checkpoint *cp, const string §ion) 1952623SN/A{ 1962915Sktlim@umich.edu SimObject::State so_state; 1972915Sktlim@umich.edu UNSERIALIZE_ENUM(so_state); 1986078Sgblack@eecs.umich.edu UNSERIALIZE_SCALAR(locked); 1993145Shsul@eecs.umich.edu BaseSimpleCPU::unserialize(cp, section); 2002915Sktlim@umich.edu tickEvent.unserialize(cp, csprintf("%s.tickEvent", section)); 2012915Sktlim@umich.edu} 2022915Sktlim@umich.edu 2032915Sktlim@umich.eduvoid 2042915Sktlim@umich.eduAtomicSimpleCPU::resume() 2052915Sktlim@umich.edu{ 2065220Ssaidi@eecs.umich.edu if (_status == Idle || _status == SwitchedOut) 2075220Ssaidi@eecs.umich.edu return; 2085220Ssaidi@eecs.umich.edu 2094940Snate@binkert.org DPRINTF(SimpleCPU, "Resume\n"); 2105220Ssaidi@eecs.umich.edu assert(system->getMemoryMode() == Enums::atomic); 2113324Shsul@eecs.umich.edu 2125220Ssaidi@eecs.umich.edu changeState(SimObject::Running); 2135220Ssaidi@eecs.umich.edu if (thread->status() == ThreadContext::Active) { 2145606Snate@binkert.org if (!tickEvent.scheduled()) 2155606Snate@binkert.org schedule(tickEvent, nextCycle()); 2162915Sktlim@umich.edu } 2177897Shestness@cs.utexas.edu system->totalNumInsts = 0; 2182623SN/A} 2192623SN/A 2202623SN/Avoid 2212798Sktlim@umich.eduAtomicSimpleCPU::switchOut() 2222623SN/A{ 2235496Ssaidi@eecs.umich.edu assert(_status == Running || _status == Idle); 2242798Sktlim@umich.edu _status = SwitchedOut; 2252623SN/A 2262798Sktlim@umich.edu tickEvent.squash(); 2272623SN/A} 2282623SN/A 2292623SN/A 2302623SN/Avoid 2312623SN/AAtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU) 2322623SN/A{ 2334192Sktlim@umich.edu BaseCPU::takeOverFrom(oldCPU, &icachePort, &dcachePort); 2342623SN/A 2352623SN/A assert(!tickEvent.scheduled()); 2362623SN/A 2372680Sktlim@umich.edu // if any of this CPU's ThreadContexts are active, mark the CPU as 2382623SN/A // running and schedule its tick event. 2396221Snate@binkert.org ThreadID size = threadContexts.size(); 2406221Snate@binkert.org for (ThreadID i = 0; i < size; ++i) { 2412680Sktlim@umich.edu ThreadContext *tc = threadContexts[i]; 2422680Sktlim@umich.edu if (tc->status() == ThreadContext::Active && _status != Running) { 2432623SN/A _status = Running; 2445606Snate@binkert.org schedule(tickEvent, nextCycle()); 2452623SN/A break; 2462623SN/A } 2472623SN/A } 2483512Sktlim@umich.edu if (_status != Running) { 2493512Sktlim@umich.edu _status = Idle; 2503512Sktlim@umich.edu } 2515169Ssaidi@eecs.umich.edu assert(threadContexts.size() == 1); 2525712Shsul@eecs.umich.edu ifetch_req.setThreadContext(_cpuId, 0); // Add thread ID if we add MT 2535712Shsul@eecs.umich.edu data_read_req.setThreadContext(_cpuId, 0); // Add thread ID here too 2545712Shsul@eecs.umich.edu data_write_req.setThreadContext(_cpuId, 0); // Add thread ID here too 2552623SN/A} 2562623SN/A 2572623SN/A 2582623SN/Avoid 2592623SN/AAtomicSimpleCPU::activateContext(int thread_num, int delay) 2602623SN/A{ 2614940Snate@binkert.org DPRINTF(SimpleCPU, "ActivateContext %d (%d cycles)\n", thread_num, delay); 2624940Snate@binkert.org 2632623SN/A assert(thread_num == 0); 2642683Sktlim@umich.edu assert(thread); 2652623SN/A 2662623SN/A assert(_status == Idle); 2672623SN/A assert(!tickEvent.scheduled()); 2682623SN/A 2692623SN/A notIdleFraction++; 2705101Ssaidi@eecs.umich.edu numCycles += tickToCycles(thread->lastActivate - thread->lastSuspend); 2713686Sktlim@umich.edu 2723430Sgblack@eecs.umich.edu //Make sure ticks are still on multiples of cycles 2737823Ssteve.reinhardt@amd.com schedule(tickEvent, nextCycle(curTick() + ticks(delay))); 2742623SN/A _status = Running; 2752623SN/A} 2762623SN/A 2772623SN/A 2782623SN/Avoid 2792623SN/AAtomicSimpleCPU::suspendContext(int thread_num) 2802623SN/A{ 2814940Snate@binkert.org DPRINTF(SimpleCPU, "SuspendContext %d\n", thread_num); 2824940Snate@binkert.org 2832623SN/A assert(thread_num == 0); 2842683Sktlim@umich.edu assert(thread); 2852623SN/A 2866043Sgblack@eecs.umich.edu if (_status == Idle) 2876043Sgblack@eecs.umich.edu return; 2886043Sgblack@eecs.umich.edu 2892623SN/A assert(_status == Running); 2902626SN/A 2912626SN/A // tick event may not be scheduled if this gets called from inside 2922626SN/A // an instruction's execution, e.g. "quiesce" 2932626SN/A if (tickEvent.scheduled()) 2945606Snate@binkert.org deschedule(tickEvent); 2952623SN/A 2962623SN/A notIdleFraction--; 2972623SN/A _status = Idle; 2982623SN/A} 2992623SN/A 3002623SN/A 3012623SN/AFault 3028444Sgblack@eecs.umich.eduAtomicSimpleCPU::readMem(Addr addr, uint8_t * data, 3038444Sgblack@eecs.umich.edu unsigned size, unsigned flags) 3042623SN/A{ 3053169Sstever@eecs.umich.edu // use the CPU's statically allocated read request and packet objects 3064870Sstever@eecs.umich.edu Request *req = &data_read_req; 3072623SN/A 3082623SN/A if (traceData) { 3092623SN/A traceData->setAddr(addr); 3102623SN/A } 3112623SN/A 3124999Sgblack@eecs.umich.edu //The block size of our peer. 3136227Snate@binkert.org unsigned blockSize = dcachePort.peerBlockSize(); 3144999Sgblack@eecs.umich.edu //The size of the data we're trying to read. 3157520Sgblack@eecs.umich.edu int fullSize = size; 3162623SN/A 3174999Sgblack@eecs.umich.edu //The address of the second part of this access if it needs to be split 3184999Sgblack@eecs.umich.edu //across a cache line boundary. 3197520Sgblack@eecs.umich.edu Addr secondAddr = roundDown(addr + size - 1, blockSize); 3204999Sgblack@eecs.umich.edu 3217520Sgblack@eecs.umich.edu if (secondAddr > addr) 3227520Sgblack@eecs.umich.edu size = secondAddr - addr; 3234999Sgblack@eecs.umich.edu 3244999Sgblack@eecs.umich.edu dcache_latency = 0; 3254999Sgblack@eecs.umich.edu 3267520Sgblack@eecs.umich.edu while (1) { 3277720Sgblack@eecs.umich.edu req->setVirt(0, addr, size, flags, thread->pcState().instAddr()); 3284999Sgblack@eecs.umich.edu 3294999Sgblack@eecs.umich.edu // translate to physical address 3306023Snate@binkert.org Fault fault = thread->dtb->translateAtomic(req, tc, BaseTLB::Read); 3314999Sgblack@eecs.umich.edu 3324999Sgblack@eecs.umich.edu // Now do the access. 3336623Sgblack@eecs.umich.edu if (fault == NoFault && !req->getFlags().isSet(Request::NO_ACCESS)) { 3344999Sgblack@eecs.umich.edu Packet pkt = Packet(req, 3356102Sgblack@eecs.umich.edu req->isLLSC() ? MemCmd::LoadLockedReq : MemCmd::ReadReq, 3364999Sgblack@eecs.umich.edu Packet::Broadcast); 3377520Sgblack@eecs.umich.edu pkt.dataStatic(data); 3384999Sgblack@eecs.umich.edu 3398105Sgblack@eecs.umich.edu if (req->isMmappedIpr()) 3404999Sgblack@eecs.umich.edu dcache_latency += TheISA::handleIprRead(thread->getTC(), &pkt); 3414999Sgblack@eecs.umich.edu else { 3424999Sgblack@eecs.umich.edu if (hasPhysMemPort && pkt.getAddr() == physMemAddr) 3434999Sgblack@eecs.umich.edu dcache_latency += physmemPort.sendAtomic(&pkt); 3444999Sgblack@eecs.umich.edu else 3454999Sgblack@eecs.umich.edu dcache_latency += dcachePort.sendAtomic(&pkt); 3464999Sgblack@eecs.umich.edu } 3474999Sgblack@eecs.umich.edu dcache_access = true; 3485012Sgblack@eecs.umich.edu 3494999Sgblack@eecs.umich.edu assert(!pkt.isError()); 3504999Sgblack@eecs.umich.edu 3516102Sgblack@eecs.umich.edu if (req->isLLSC()) { 3524999Sgblack@eecs.umich.edu TheISA::handleLockedRead(thread, req); 3534999Sgblack@eecs.umich.edu } 3544968Sacolyte@umich.edu } 3554986Ssaidi@eecs.umich.edu 3564999Sgblack@eecs.umich.edu //If there's a fault, return it 3576739Sgblack@eecs.umich.edu if (fault != NoFault) { 3586739Sgblack@eecs.umich.edu if (req->isPrefetch()) { 3596739Sgblack@eecs.umich.edu return NoFault; 3606739Sgblack@eecs.umich.edu } else { 3616739Sgblack@eecs.umich.edu return fault; 3626739Sgblack@eecs.umich.edu } 3636739Sgblack@eecs.umich.edu } 3646739Sgblack@eecs.umich.edu 3654999Sgblack@eecs.umich.edu //If we don't need to access a second cache line, stop now. 3664999Sgblack@eecs.umich.edu if (secondAddr <= addr) 3674999Sgblack@eecs.umich.edu { 3686078Sgblack@eecs.umich.edu if (req->isLocked() && fault == NoFault) { 3696078Sgblack@eecs.umich.edu assert(!locked); 3706078Sgblack@eecs.umich.edu locked = true; 3716078Sgblack@eecs.umich.edu } 3724999Sgblack@eecs.umich.edu return fault; 3734968Sacolyte@umich.edu } 3743170Sstever@eecs.umich.edu 3754999Sgblack@eecs.umich.edu /* 3764999Sgblack@eecs.umich.edu * Set up for accessing the second cache line. 3774999Sgblack@eecs.umich.edu */ 3784999Sgblack@eecs.umich.edu 3794999Sgblack@eecs.umich.edu //Move the pointer we're reading into to the correct location. 3807520Sgblack@eecs.umich.edu data += size; 3814999Sgblack@eecs.umich.edu //Adjust the size to get the remaining bytes. 3827520Sgblack@eecs.umich.edu size = addr + fullSize - secondAddr; 3834999Sgblack@eecs.umich.edu //And access the right address. 3844999Sgblack@eecs.umich.edu addr = secondAddr; 3852623SN/A } 3862623SN/A} 3872623SN/A 3887520Sgblack@eecs.umich.edu 3892623SN/AFault 3908444Sgblack@eecs.umich.eduAtomicSimpleCPU::writeMem(uint8_t *data, unsigned size, 3918444Sgblack@eecs.umich.edu Addr addr, unsigned flags, uint64_t *res) 3922623SN/A{ 3933169Sstever@eecs.umich.edu // use the CPU's statically allocated write request and packet objects 3944870Sstever@eecs.umich.edu Request *req = &data_write_req; 3952623SN/A 3962623SN/A if (traceData) { 3972623SN/A traceData->setAddr(addr); 3982623SN/A } 3992623SN/A 4004999Sgblack@eecs.umich.edu //The block size of our peer. 4016227Snate@binkert.org unsigned blockSize = dcachePort.peerBlockSize(); 4024999Sgblack@eecs.umich.edu //The size of the data we're trying to read. 4037520Sgblack@eecs.umich.edu int fullSize = size; 4042623SN/A 4054999Sgblack@eecs.umich.edu //The address of the second part of this access if it needs to be split 4064999Sgblack@eecs.umich.edu //across a cache line boundary. 4077520Sgblack@eecs.umich.edu Addr secondAddr = roundDown(addr + size - 1, blockSize); 4084999Sgblack@eecs.umich.edu 4094999Sgblack@eecs.umich.edu if(secondAddr > addr) 4107520Sgblack@eecs.umich.edu size = secondAddr - addr; 4114999Sgblack@eecs.umich.edu 4124999Sgblack@eecs.umich.edu dcache_latency = 0; 4134999Sgblack@eecs.umich.edu 4144999Sgblack@eecs.umich.edu while(1) { 4157720Sgblack@eecs.umich.edu req->setVirt(0, addr, size, flags, thread->pcState().instAddr()); 4164999Sgblack@eecs.umich.edu 4174999Sgblack@eecs.umich.edu // translate to physical address 4186023Snate@binkert.org Fault fault = thread->dtb->translateAtomic(req, tc, BaseTLB::Write); 4194999Sgblack@eecs.umich.edu 4204999Sgblack@eecs.umich.edu // Now do the access. 4214999Sgblack@eecs.umich.edu if (fault == NoFault) { 4224999Sgblack@eecs.umich.edu MemCmd cmd = MemCmd::WriteReq; // default 4234999Sgblack@eecs.umich.edu bool do_access = true; // flag to suppress cache access 4244999Sgblack@eecs.umich.edu 4256102Sgblack@eecs.umich.edu if (req->isLLSC()) { 4264999Sgblack@eecs.umich.edu cmd = MemCmd::StoreCondReq; 4274999Sgblack@eecs.umich.edu do_access = TheISA::handleLockedWrite(thread, req); 4284999Sgblack@eecs.umich.edu } else if (req->isSwap()) { 4294999Sgblack@eecs.umich.edu cmd = MemCmd::SwapReq; 4304999Sgblack@eecs.umich.edu if (req->isCondSwap()) { 4314999Sgblack@eecs.umich.edu assert(res); 4324999Sgblack@eecs.umich.edu req->setExtraData(*res); 4334999Sgblack@eecs.umich.edu } 4344999Sgblack@eecs.umich.edu } 4354999Sgblack@eecs.umich.edu 4366623Sgblack@eecs.umich.edu if (do_access && !req->getFlags().isSet(Request::NO_ACCESS)) { 4374999Sgblack@eecs.umich.edu Packet pkt = Packet(req, cmd, Packet::Broadcast); 4387520Sgblack@eecs.umich.edu pkt.dataStatic(data); 4394999Sgblack@eecs.umich.edu 4408105Sgblack@eecs.umich.edu if (req->isMmappedIpr()) { 4414999Sgblack@eecs.umich.edu dcache_latency += 4424999Sgblack@eecs.umich.edu TheISA::handleIprWrite(thread->getTC(), &pkt); 4434999Sgblack@eecs.umich.edu } else { 4444999Sgblack@eecs.umich.edu if (hasPhysMemPort && pkt.getAddr() == physMemAddr) 4454999Sgblack@eecs.umich.edu dcache_latency += physmemPort.sendAtomic(&pkt); 4464999Sgblack@eecs.umich.edu else 4474999Sgblack@eecs.umich.edu dcache_latency += dcachePort.sendAtomic(&pkt); 4484999Sgblack@eecs.umich.edu } 4494999Sgblack@eecs.umich.edu dcache_access = true; 4504999Sgblack@eecs.umich.edu assert(!pkt.isError()); 4514999Sgblack@eecs.umich.edu 4524999Sgblack@eecs.umich.edu if (req->isSwap()) { 4534999Sgblack@eecs.umich.edu assert(res); 4547520Sgblack@eecs.umich.edu memcpy(res, pkt.getPtr<uint8_t>(), fullSize); 4554999Sgblack@eecs.umich.edu } 4564999Sgblack@eecs.umich.edu } 4574999Sgblack@eecs.umich.edu 4584999Sgblack@eecs.umich.edu if (res && !req->isSwap()) { 4594999Sgblack@eecs.umich.edu *res = req->getExtraData(); 4604878Sstever@eecs.umich.edu } 4614040Ssaidi@eecs.umich.edu } 4624040Ssaidi@eecs.umich.edu 4634999Sgblack@eecs.umich.edu //If there's a fault or we don't need to access a second cache line, 4644999Sgblack@eecs.umich.edu //stop now. 4654999Sgblack@eecs.umich.edu if (fault != NoFault || secondAddr <= addr) 4664999Sgblack@eecs.umich.edu { 4676078Sgblack@eecs.umich.edu if (req->isLocked() && fault == NoFault) { 4686078Sgblack@eecs.umich.edu assert(locked); 4696078Sgblack@eecs.umich.edu locked = false; 4706078Sgblack@eecs.umich.edu } 4716739Sgblack@eecs.umich.edu if (fault != NoFault && req->isPrefetch()) { 4726739Sgblack@eecs.umich.edu return NoFault; 4736739Sgblack@eecs.umich.edu } else { 4746739Sgblack@eecs.umich.edu return fault; 4756739Sgblack@eecs.umich.edu } 4763170Sstever@eecs.umich.edu } 4773170Sstever@eecs.umich.edu 4784999Sgblack@eecs.umich.edu /* 4794999Sgblack@eecs.umich.edu * Set up for accessing the second cache line. 4804999Sgblack@eecs.umich.edu */ 4814999Sgblack@eecs.umich.edu 4824999Sgblack@eecs.umich.edu //Move the pointer we're reading into to the correct location. 4837520Sgblack@eecs.umich.edu data += size; 4844999Sgblack@eecs.umich.edu //Adjust the size to get the remaining bytes. 4857520Sgblack@eecs.umich.edu size = addr + fullSize - secondAddr; 4864999Sgblack@eecs.umich.edu //And access the right address. 4874999Sgblack@eecs.umich.edu addr = secondAddr; 4882623SN/A } 4892623SN/A} 4902623SN/A 4912623SN/A 4922623SN/Avoid 4932623SN/AAtomicSimpleCPU::tick() 4942623SN/A{ 4954940Snate@binkert.org DPRINTF(SimpleCPU, "Tick\n"); 4964940Snate@binkert.org 4975487Snate@binkert.org Tick latency = 0; 4982623SN/A 4996078Sgblack@eecs.umich.edu for (int i = 0; i < width || locked; ++i) { 5002623SN/A numCycles++; 5012623SN/A 5023387Sgblack@eecs.umich.edu if (!curStaticInst || !curStaticInst->isDelayedCommit()) 5033387Sgblack@eecs.umich.edu checkForInterrupts(); 5042626SN/A 5055348Ssaidi@eecs.umich.edu checkPcEventQueue(); 5068143SAli.Saidi@ARM.com // We must have just got suspended by a PC event 5078143SAli.Saidi@ARM.com if (_status == Idle) 5088143SAli.Saidi@ARM.com return; 5095348Ssaidi@eecs.umich.edu 5105669Sgblack@eecs.umich.edu Fault fault = NoFault; 5115669Sgblack@eecs.umich.edu 5127720Sgblack@eecs.umich.edu TheISA::PCState pcState = thread->pcState(); 5137720Sgblack@eecs.umich.edu 5147720Sgblack@eecs.umich.edu bool needToFetch = !isRomMicroPC(pcState.microPC()) && 5157720Sgblack@eecs.umich.edu !curMacroStaticInst; 5167720Sgblack@eecs.umich.edu if (needToFetch) { 5175894Sgblack@eecs.umich.edu setupFetchRequest(&ifetch_req); 5186023Snate@binkert.org fault = thread->itb->translateAtomic(&ifetch_req, tc, 5196023Snate@binkert.org BaseTLB::Execute); 5205894Sgblack@eecs.umich.edu } 5212623SN/A 5222623SN/A if (fault == NoFault) { 5234182Sgblack@eecs.umich.edu Tick icache_latency = 0; 5244182Sgblack@eecs.umich.edu bool icache_access = false; 5254182Sgblack@eecs.umich.edu dcache_access = false; // assume no dcache access 5262662Sstever@eecs.umich.edu 5277720Sgblack@eecs.umich.edu if (needToFetch) { 5285694Sgblack@eecs.umich.edu // This is commented out because the predecoder would act like 5295694Sgblack@eecs.umich.edu // a tiny cache otherwise. It wouldn't be flushed when needed 5305694Sgblack@eecs.umich.edu // like the I cache. It should be flushed, and when that works 5315694Sgblack@eecs.umich.edu // this code should be uncommented. 5325669Sgblack@eecs.umich.edu //Fetch more instruction memory if necessary 5335669Sgblack@eecs.umich.edu //if(predecoder.needMoreBytes()) 5345669Sgblack@eecs.umich.edu //{ 5355669Sgblack@eecs.umich.edu icache_access = true; 5365669Sgblack@eecs.umich.edu Packet ifetch_pkt = Packet(&ifetch_req, MemCmd::ReadReq, 5375669Sgblack@eecs.umich.edu Packet::Broadcast); 5385669Sgblack@eecs.umich.edu ifetch_pkt.dataStatic(&inst); 5392623SN/A 5405669Sgblack@eecs.umich.edu if (hasPhysMemPort && ifetch_pkt.getAddr() == physMemAddr) 5415669Sgblack@eecs.umich.edu icache_latency = physmemPort.sendAtomic(&ifetch_pkt); 5425669Sgblack@eecs.umich.edu else 5435669Sgblack@eecs.umich.edu icache_latency = icachePort.sendAtomic(&ifetch_pkt); 5444968Sacolyte@umich.edu 5455669Sgblack@eecs.umich.edu assert(!ifetch_pkt.isError()); 5464968Sacolyte@umich.edu 5475669Sgblack@eecs.umich.edu // ifetch_req is initialized to read the instruction directly 5485669Sgblack@eecs.umich.edu // into the CPU object's inst field. 5495669Sgblack@eecs.umich.edu //} 5505669Sgblack@eecs.umich.edu } 5514182Sgblack@eecs.umich.edu 5522623SN/A preExecute(); 5533814Ssaidi@eecs.umich.edu 5545001Sgblack@eecs.umich.edu if (curStaticInst) { 5554182Sgblack@eecs.umich.edu fault = curStaticInst->execute(this, traceData); 5564998Sgblack@eecs.umich.edu 5574998Sgblack@eecs.umich.edu // keep an instruction count 5584998Sgblack@eecs.umich.edu if (fault == NoFault) 5594998Sgblack@eecs.umich.edu countInst(); 5607655Sali.saidi@arm.com else if (traceData && !DTRACE(ExecFaulting)) { 5615001Sgblack@eecs.umich.edu delete traceData; 5625001Sgblack@eecs.umich.edu traceData = NULL; 5635001Sgblack@eecs.umich.edu } 5644998Sgblack@eecs.umich.edu 5654182Sgblack@eecs.umich.edu postExecute(); 5664182Sgblack@eecs.umich.edu } 5672623SN/A 5683814Ssaidi@eecs.umich.edu // @todo remove me after debugging with legion done 5694539Sgblack@eecs.umich.edu if (curStaticInst && (!curStaticInst->isMicroop() || 5704539Sgblack@eecs.umich.edu curStaticInst->isFirstMicroop())) 5713814Ssaidi@eecs.umich.edu instCnt++; 5723814Ssaidi@eecs.umich.edu 5735487Snate@binkert.org Tick stall_ticks = 0; 5745487Snate@binkert.org if (simulate_inst_stalls && icache_access) 5755487Snate@binkert.org stall_ticks += icache_latency; 5765487Snate@binkert.org 5775487Snate@binkert.org if (simulate_data_stalls && dcache_access) 5785487Snate@binkert.org stall_ticks += dcache_latency; 5795487Snate@binkert.org 5805487Snate@binkert.org if (stall_ticks) { 5815487Snate@binkert.org Tick stall_cycles = stall_ticks / ticks(1); 5825487Snate@binkert.org Tick aligned_stall_ticks = ticks(stall_cycles); 5835487Snate@binkert.org 5845487Snate@binkert.org if (aligned_stall_ticks < stall_ticks) 5855487Snate@binkert.org aligned_stall_ticks += 1; 5865487Snate@binkert.org 5875487Snate@binkert.org latency += aligned_stall_ticks; 5882623SN/A } 5892623SN/A 5902623SN/A } 5914377Sgblack@eecs.umich.edu if(fault != NoFault || !stayAtPC) 5924182Sgblack@eecs.umich.edu advancePC(fault); 5932623SN/A } 5942623SN/A 5955487Snate@binkert.org // instruction takes at least one cycle 5965487Snate@binkert.org if (latency < ticks(1)) 5975487Snate@binkert.org latency = ticks(1); 5985487Snate@binkert.org 5992626SN/A if (_status != Idle) 6007823Ssteve.reinhardt@amd.com schedule(tickEvent, curTick() + latency); 6012623SN/A} 6022623SN/A 6032623SN/A 6045315Sstever@gmail.comvoid 6055315Sstever@gmail.comAtomicSimpleCPU::printAddr(Addr a) 6065315Sstever@gmail.com{ 6075315Sstever@gmail.com dcachePort.printAddr(a); 6085315Sstever@gmail.com} 6095315Sstever@gmail.com 6105315Sstever@gmail.com 6112623SN/A//////////////////////////////////////////////////////////////////////// 6122623SN/A// 6132623SN/A// AtomicSimpleCPU Simulation Object 6142623SN/A// 6154762Snate@binkert.orgAtomicSimpleCPU * 6164762Snate@binkert.orgAtomicSimpleCPUParams::create() 6172623SN/A{ 6185529Snate@binkert.org numThreads = 1; 6195529Snate@binkert.org#if !FULL_SYSTEM 6204762Snate@binkert.org if (workload.size() != 1) 6214762Snate@binkert.org panic("only one workload allowed"); 6222623SN/A#endif 6235529Snate@binkert.org return new AtomicSimpleCPU(this); 6242623SN/A} 625