atomic.cc revision 3686
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"
322623SN/A#include "arch/utility.hh"
332623SN/A#include "cpu/exetrace.hh"
342623SN/A#include "cpu/simple/atomic.hh"
353348Sbinkertn@umich.edu#include "mem/packet.hh"
363348Sbinkertn@umich.edu#include "mem/packet_access.hh"
372623SN/A#include "sim/builder.hh"
382901Ssaidi@eecs.umich.edu#include "sim/system.hh"
392623SN/A
402623SN/Ausing namespace std;
412623SN/Ausing namespace TheISA;
422623SN/A
432623SN/AAtomicSimpleCPU::TickEvent::TickEvent(AtomicSimpleCPU *c)
442623SN/A    : Event(&mainEventQueue, CPU_Tick_Pri), cpu(c)
452623SN/A{
462623SN/A}
472623SN/A
482623SN/A
492623SN/Avoid
502623SN/AAtomicSimpleCPU::TickEvent::process()
512623SN/A{
522623SN/A    cpu->tick();
532623SN/A}
542623SN/A
552623SN/Aconst char *
562623SN/AAtomicSimpleCPU::TickEvent::description()
572623SN/A{
582623SN/A    return "AtomicSimpleCPU tick event";
592623SN/A}
602623SN/A
612856Srdreslin@umich.eduPort *
622856Srdreslin@umich.eduAtomicSimpleCPU::getPort(const std::string &if_name, int idx)
632856Srdreslin@umich.edu{
642856Srdreslin@umich.edu    if (if_name == "dcache_port")
652856Srdreslin@umich.edu        return &dcachePort;
662856Srdreslin@umich.edu    else if (if_name == "icache_port")
672856Srdreslin@umich.edu        return &icachePort;
682856Srdreslin@umich.edu    else
692856Srdreslin@umich.edu        panic("No Such Port\n");
702856Srdreslin@umich.edu}
712623SN/A
722623SN/Avoid
732623SN/AAtomicSimpleCPU::init()
742623SN/A{
752623SN/A    BaseCPU::init();
762623SN/A#if FULL_SYSTEM
772680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
782680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
792623SN/A
802623SN/A        // initialize CPU, including PC
812680Sktlim@umich.edu        TheISA::initCPU(tc, tc->readCpuId());
822623SN/A    }
832623SN/A#endif
842623SN/A}
852623SN/A
862623SN/Abool
873349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvTiming(PacketPtr pkt)
882623SN/A{
893184Srdreslin@umich.edu    panic("AtomicSimpleCPU doesn't expect recvTiming callback!");
902623SN/A    return true;
912623SN/A}
922623SN/A
932623SN/ATick
943349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt)
952623SN/A{
963310Srdreslin@umich.edu    //Snooping a coherence request, just return
973649Srdreslin@umich.edu    return 0;
982623SN/A}
992623SN/A
1002623SN/Avoid
1013349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt)
1022623SN/A{
1033184Srdreslin@umich.edu    //No internal storage to update, just return
1043184Srdreslin@umich.edu    return;
1052623SN/A}
1062623SN/A
1072623SN/Avoid
1082623SN/AAtomicSimpleCPU::CpuPort::recvStatusChange(Status status)
1092623SN/A{
1103647Srdreslin@umich.edu    if (status == RangeChange) {
1113647Srdreslin@umich.edu        if (!snoopRangeSent) {
1123647Srdreslin@umich.edu            snoopRangeSent = true;
1133647Srdreslin@umich.edu            sendStatusChange(Port::RangeChange);
1143647Srdreslin@umich.edu        }
1152626SN/A        return;
1163647Srdreslin@umich.edu    }
1172626SN/A
1182623SN/A    panic("AtomicSimpleCPU doesn't expect recvStatusChange callback!");
1192623SN/A}
1202623SN/A
1212657Ssaidi@eecs.umich.eduvoid
1222623SN/AAtomicSimpleCPU::CpuPort::recvRetry()
1232623SN/A{
1242623SN/A    panic("AtomicSimpleCPU doesn't expect recvRetry callback!");
1252623SN/A}
1262623SN/A
1272623SN/A
1282623SN/AAtomicSimpleCPU::AtomicSimpleCPU(Params *p)
1292623SN/A    : BaseSimpleCPU(p), tickEvent(this),
1302623SN/A      width(p->width), simulate_stalls(p->simulate_stalls),
1312640Sstever@eecs.umich.edu      icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this)
1322623SN/A{
1332623SN/A    _status = Idle;
1342623SN/A
1353647Srdreslin@umich.edu    icachePort.snoopRangeSent = false;
1363647Srdreslin@umich.edu    dcachePort.snoopRangeSent = false;
1373647Srdreslin@umich.edu
1382663Sstever@eecs.umich.edu    ifetch_req = new Request();
1393170Sstever@eecs.umich.edu    ifetch_req->setThreadContext(p->cpu_id, 0); // Add thread ID if we add MT
1402641Sstever@eecs.umich.edu    ifetch_pkt = new Packet(ifetch_req, Packet::ReadReq, Packet::Broadcast);
1412623SN/A    ifetch_pkt->dataStatic(&inst);
1422623SN/A
1432663Sstever@eecs.umich.edu    data_read_req = new Request();
1443170Sstever@eecs.umich.edu    data_read_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
1452641Sstever@eecs.umich.edu    data_read_pkt = new Packet(data_read_req, Packet::ReadReq,
1462641Sstever@eecs.umich.edu                               Packet::Broadcast);
1472623SN/A    data_read_pkt->dataStatic(&dataReg);
1482623SN/A
1492663Sstever@eecs.umich.edu    data_write_req = new Request();
1503170Sstever@eecs.umich.edu    data_write_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
1512641Sstever@eecs.umich.edu    data_write_pkt = new Packet(data_write_req, Packet::WriteReq,
1522641Sstever@eecs.umich.edu                                Packet::Broadcast);
1532623SN/A}
1542623SN/A
1552623SN/A
1562623SN/AAtomicSimpleCPU::~AtomicSimpleCPU()
1572623SN/A{
1582623SN/A}
1592623SN/A
1602623SN/Avoid
1612623SN/AAtomicSimpleCPU::serialize(ostream &os)
1622623SN/A{
1632915Sktlim@umich.edu    SimObject::State so_state = SimObject::getState();
1642915Sktlim@umich.edu    SERIALIZE_ENUM(so_state);
1653177Shsul@eecs.umich.edu    Status _status = status();
1663177Shsul@eecs.umich.edu    SERIALIZE_ENUM(_status);
1673145Shsul@eecs.umich.edu    BaseSimpleCPU::serialize(os);
1682623SN/A    nameOut(os, csprintf("%s.tickEvent", name()));
1692623SN/A    tickEvent.serialize(os);
1702623SN/A}
1712623SN/A
1722623SN/Avoid
1732623SN/AAtomicSimpleCPU::unserialize(Checkpoint *cp, const string &section)
1742623SN/A{
1752915Sktlim@umich.edu    SimObject::State so_state;
1762915Sktlim@umich.edu    UNSERIALIZE_ENUM(so_state);
1773177Shsul@eecs.umich.edu    UNSERIALIZE_ENUM(_status);
1783145Shsul@eecs.umich.edu    BaseSimpleCPU::unserialize(cp, section);
1792915Sktlim@umich.edu    tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
1802915Sktlim@umich.edu}
1812915Sktlim@umich.edu
1822915Sktlim@umich.eduvoid
1832915Sktlim@umich.eduAtomicSimpleCPU::resume()
1842915Sktlim@umich.edu{
1853324Shsul@eecs.umich.edu    if (_status != SwitchedOut && _status != Idle) {
1863201Shsul@eecs.umich.edu        assert(system->getMemoryMode() == System::Atomic);
1873324Shsul@eecs.umich.edu
1883324Shsul@eecs.umich.edu        changeState(SimObject::Running);
1893324Shsul@eecs.umich.edu        if (thread->status() == ThreadContext::Active) {
1903431Sgblack@eecs.umich.edu            if (!tickEvent.scheduled()) {
1913495Sktlim@umich.edu                tickEvent.schedule(nextCycle());
1923431Sgblack@eecs.umich.edu            }
1933324Shsul@eecs.umich.edu        }
1942915Sktlim@umich.edu    }
1952623SN/A}
1962623SN/A
1972623SN/Avoid
1982798Sktlim@umich.eduAtomicSimpleCPU::switchOut()
1992623SN/A{
2002798Sktlim@umich.edu    assert(status() == Running || status() == Idle);
2012798Sktlim@umich.edu    _status = SwitchedOut;
2022623SN/A
2032798Sktlim@umich.edu    tickEvent.squash();
2042623SN/A}
2052623SN/A
2062623SN/A
2072623SN/Avoid
2082623SN/AAtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
2092623SN/A{
2102623SN/A    BaseCPU::takeOverFrom(oldCPU);
2112623SN/A
2122623SN/A    assert(!tickEvent.scheduled());
2132623SN/A
2142680Sktlim@umich.edu    // if any of this CPU's ThreadContexts are active, mark the CPU as
2152623SN/A    // running and schedule its tick event.
2162680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
2172680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
2182680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
2192623SN/A            _status = Running;
2203495Sktlim@umich.edu            tickEvent.schedule(nextCycle());
2212623SN/A            break;
2222623SN/A        }
2232623SN/A    }
2243512Sktlim@umich.edu    if (_status != Running) {
2253512Sktlim@umich.edu        _status = Idle;
2263512Sktlim@umich.edu    }
2272623SN/A}
2282623SN/A
2292623SN/A
2302623SN/Avoid
2312623SN/AAtomicSimpleCPU::activateContext(int thread_num, int delay)
2322623SN/A{
2332623SN/A    assert(thread_num == 0);
2342683Sktlim@umich.edu    assert(thread);
2352623SN/A
2362623SN/A    assert(_status == Idle);
2372623SN/A    assert(!tickEvent.scheduled());
2382623SN/A
2392623SN/A    notIdleFraction++;
2403686Sktlim@umich.edu
2413686Sktlim@umich.edu#if FULL_SYSTEM
2423686Sktlim@umich.edu    // Connect the ThreadContext's memory ports (Functional/Virtual
2433686Sktlim@umich.edu    // Ports)
2443686Sktlim@umich.edu    tc->connectMemPorts();
2453686Sktlim@umich.edu#endif
2463686Sktlim@umich.edu
2473430Sgblack@eecs.umich.edu    //Make sure ticks are still on multiples of cycles
2483495Sktlim@umich.edu    tickEvent.schedule(nextCycle(curTick + cycles(delay)));
2492623SN/A    _status = Running;
2502623SN/A}
2512623SN/A
2522623SN/A
2532623SN/Avoid
2542623SN/AAtomicSimpleCPU::suspendContext(int thread_num)
2552623SN/A{
2562623SN/A    assert(thread_num == 0);
2572683Sktlim@umich.edu    assert(thread);
2582623SN/A
2592623SN/A    assert(_status == Running);
2602626SN/A
2612626SN/A    // tick event may not be scheduled if this gets called from inside
2622626SN/A    // an instruction's execution, e.g. "quiesce"
2632626SN/A    if (tickEvent.scheduled())
2642626SN/A        tickEvent.deschedule();
2652623SN/A
2662623SN/A    notIdleFraction--;
2672623SN/A    _status = Idle;
2682623SN/A}
2692623SN/A
2702623SN/A
2712623SN/Atemplate <class T>
2722623SN/AFault
2732623SN/AAtomicSimpleCPU::read(Addr addr, T &data, unsigned flags)
2742623SN/A{
2753169Sstever@eecs.umich.edu    // use the CPU's statically allocated read request and packet objects
2763169Sstever@eecs.umich.edu    Request *req = data_read_req;
2773349Sbinkertn@umich.edu    PacketPtr pkt = data_read_pkt;
2783169Sstever@eecs.umich.edu
2793169Sstever@eecs.umich.edu    req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
2802623SN/A
2812623SN/A    if (traceData) {
2822623SN/A        traceData->setAddr(addr);
2832623SN/A    }
2842623SN/A
2852623SN/A    // translate to physical address
2863169Sstever@eecs.umich.edu    Fault fault = thread->translateDataReadReq(req);
2872623SN/A
2882623SN/A    // Now do the access.
2892623SN/A    if (fault == NoFault) {
2903169Sstever@eecs.umich.edu        pkt->reinitFromRequest();
2912623SN/A
2923169Sstever@eecs.umich.edu        dcache_latency = dcachePort.sendAtomic(pkt);
2932623SN/A        dcache_access = true;
2942623SN/A
2953169Sstever@eecs.umich.edu        assert(pkt->result == Packet::Success);
2963169Sstever@eecs.umich.edu        data = pkt->get<T>();
2973170Sstever@eecs.umich.edu
2983170Sstever@eecs.umich.edu        if (req->isLocked()) {
2993170Sstever@eecs.umich.edu            TheISA::handleLockedRead(thread, req);
3003170Sstever@eecs.umich.edu        }
3012623SN/A    }
3022623SN/A
3032623SN/A    // This will need a new way to tell if it has a dcache attached.
3043172Sstever@eecs.umich.edu    if (req->isUncacheable())
3052623SN/A        recordEvent("Uncached Read");
3062623SN/A
3072623SN/A    return fault;
3082623SN/A}
3092623SN/A
3102623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
3112623SN/A
3122623SN/Atemplate
3132623SN/AFault
3142623SN/AAtomicSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags);
3152623SN/A
3162623SN/Atemplate
3172623SN/AFault
3182623SN/AAtomicSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags);
3192623SN/A
3202623SN/Atemplate
3212623SN/AFault
3222623SN/AAtomicSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags);
3232623SN/A
3242623SN/Atemplate
3252623SN/AFault
3262623SN/AAtomicSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags);
3272623SN/A
3282623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
3292623SN/A
3302623SN/Atemplate<>
3312623SN/AFault
3322623SN/AAtomicSimpleCPU::read(Addr addr, double &data, unsigned flags)
3332623SN/A{
3342623SN/A    return read(addr, *(uint64_t*)&data, flags);
3352623SN/A}
3362623SN/A
3372623SN/Atemplate<>
3382623SN/AFault
3392623SN/AAtomicSimpleCPU::read(Addr addr, float &data, unsigned flags)
3402623SN/A{
3412623SN/A    return read(addr, *(uint32_t*)&data, flags);
3422623SN/A}
3432623SN/A
3442623SN/A
3452623SN/Atemplate<>
3462623SN/AFault
3472623SN/AAtomicSimpleCPU::read(Addr addr, int32_t &data, unsigned flags)
3482623SN/A{
3492623SN/A    return read(addr, (uint32_t&)data, flags);
3502623SN/A}
3512623SN/A
3522623SN/A
3532623SN/Atemplate <class T>
3542623SN/AFault
3552623SN/AAtomicSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
3562623SN/A{
3573169Sstever@eecs.umich.edu    // use the CPU's statically allocated write request and packet objects
3583169Sstever@eecs.umich.edu    Request *req = data_write_req;
3593349Sbinkertn@umich.edu    PacketPtr pkt = data_write_pkt;
3603169Sstever@eecs.umich.edu
3613169Sstever@eecs.umich.edu    req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
3622623SN/A
3632623SN/A    if (traceData) {
3642623SN/A        traceData->setAddr(addr);
3652623SN/A    }
3662623SN/A
3672623SN/A    // translate to physical address
3683169Sstever@eecs.umich.edu    Fault fault = thread->translateDataWriteReq(req);
3692623SN/A
3702623SN/A    // Now do the access.
3712623SN/A    if (fault == NoFault) {
3723170Sstever@eecs.umich.edu        bool do_access = true;  // flag to suppress cache access
3732623SN/A
3743170Sstever@eecs.umich.edu        if (req->isLocked()) {
3753170Sstever@eecs.umich.edu            do_access = TheISA::handleLockedWrite(thread, req);
3763170Sstever@eecs.umich.edu        }
3772623SN/A
3783170Sstever@eecs.umich.edu        if (do_access) {
3793170Sstever@eecs.umich.edu            data = htog(data);
3803170Sstever@eecs.umich.edu            pkt->reinitFromRequest();
3813170Sstever@eecs.umich.edu            pkt->dataStatic(&data);
3822631SN/A
3833170Sstever@eecs.umich.edu            dcache_latency = dcachePort.sendAtomic(pkt);
3843170Sstever@eecs.umich.edu            dcache_access = true;
3853170Sstever@eecs.umich.edu
3863170Sstever@eecs.umich.edu            assert(pkt->result == Packet::Success);
3873170Sstever@eecs.umich.edu        }
3883170Sstever@eecs.umich.edu
3893170Sstever@eecs.umich.edu        if (req->isLocked()) {
3903170Sstever@eecs.umich.edu            uint64_t scResult = req->getScResult();
3913170Sstever@eecs.umich.edu            if (scResult != 0) {
3923170Sstever@eecs.umich.edu                // clear failure counter
3933170Sstever@eecs.umich.edu                thread->setStCondFailures(0);
3943170Sstever@eecs.umich.edu            }
3953170Sstever@eecs.umich.edu            if (res) {
3963170Sstever@eecs.umich.edu                *res = req->getScResult();
3973170Sstever@eecs.umich.edu            }
3982631SN/A        }
3992623SN/A    }
4002623SN/A
4012623SN/A    // This will need a new way to tell if it's hooked up to a cache or not.
4023172Sstever@eecs.umich.edu    if (req->isUncacheable())
4032623SN/A        recordEvent("Uncached Write");
4042623SN/A
4052623SN/A    // If the write needs to have a fault on the access, consider calling
4062623SN/A    // changeStatus() and changing it to "bad addr write" or something.
4072623SN/A    return fault;
4082623SN/A}
4092623SN/A
4102623SN/A
4112623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
4122623SN/Atemplate
4132623SN/AFault
4142623SN/AAtomicSimpleCPU::write(uint64_t data, Addr addr,
4152623SN/A                       unsigned flags, uint64_t *res);
4162623SN/A
4172623SN/Atemplate
4182623SN/AFault
4192623SN/AAtomicSimpleCPU::write(uint32_t data, Addr addr,
4202623SN/A                       unsigned flags, uint64_t *res);
4212623SN/A
4222623SN/Atemplate
4232623SN/AFault
4242623SN/AAtomicSimpleCPU::write(uint16_t data, Addr addr,
4252623SN/A                       unsigned flags, uint64_t *res);
4262623SN/A
4272623SN/Atemplate
4282623SN/AFault
4292623SN/AAtomicSimpleCPU::write(uint8_t data, Addr addr,
4302623SN/A                       unsigned flags, uint64_t *res);
4312623SN/A
4322623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
4332623SN/A
4342623SN/Atemplate<>
4352623SN/AFault
4362623SN/AAtomicSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res)
4372623SN/A{
4382623SN/A    return write(*(uint64_t*)&data, addr, flags, res);
4392623SN/A}
4402623SN/A
4412623SN/Atemplate<>
4422623SN/AFault
4432623SN/AAtomicSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res)
4442623SN/A{
4452623SN/A    return write(*(uint32_t*)&data, addr, flags, res);
4462623SN/A}
4472623SN/A
4482623SN/A
4492623SN/Atemplate<>
4502623SN/AFault
4512623SN/AAtomicSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res)
4522623SN/A{
4532623SN/A    return write((uint32_t)data, addr, flags, res);
4542623SN/A}
4552623SN/A
4562623SN/A
4572623SN/Avoid
4582623SN/AAtomicSimpleCPU::tick()
4592623SN/A{
4602623SN/A    Tick latency = cycles(1); // instruction takes one cycle by default
4612623SN/A
4622623SN/A    for (int i = 0; i < width; ++i) {
4632623SN/A        numCycles++;
4642623SN/A
4653387Sgblack@eecs.umich.edu        if (!curStaticInst || !curStaticInst->isDelayedCommit())
4663387Sgblack@eecs.umich.edu            checkForInterrupts();
4672626SN/A
4682662Sstever@eecs.umich.edu        Fault fault = setupFetchRequest(ifetch_req);
4692623SN/A
4702623SN/A        if (fault == NoFault) {
4712662Sstever@eecs.umich.edu            ifetch_pkt->reinitFromRequest();
4722662Sstever@eecs.umich.edu
4732662Sstever@eecs.umich.edu            Tick icache_latency = icachePort.sendAtomic(ifetch_pkt);
4742623SN/A            // ifetch_req is initialized to read the instruction directly
4752623SN/A            // into the CPU object's inst field.
4762623SN/A
4772623SN/A            dcache_access = false; // assume no dcache access
4782623SN/A            preExecute();
4792623SN/A            fault = curStaticInst->execute(this, traceData);
4802623SN/A            postExecute();
4812623SN/A
4822623SN/A            if (simulate_stalls) {
4832662Sstever@eecs.umich.edu                Tick icache_stall = icache_latency - cycles(1);
4842623SN/A                Tick dcache_stall =
4852662Sstever@eecs.umich.edu                    dcache_access ? dcache_latency - cycles(1) : 0;
4862803Ssaidi@eecs.umich.edu                Tick stall_cycles = (icache_stall + dcache_stall) / cycles(1);
4872803Ssaidi@eecs.umich.edu                if (cycles(stall_cycles) < (icache_stall + dcache_stall))
4882803Ssaidi@eecs.umich.edu                    latency += cycles(stall_cycles+1);
4892803Ssaidi@eecs.umich.edu                else
4902803Ssaidi@eecs.umich.edu                    latency += cycles(stall_cycles);
4912623SN/A            }
4922623SN/A
4932623SN/A        }
4942623SN/A
4952623SN/A        advancePC(fault);
4962623SN/A    }
4972623SN/A
4982626SN/A    if (_status != Idle)
4992626SN/A        tickEvent.schedule(curTick + latency);
5002623SN/A}
5012623SN/A
5022623SN/A
5032623SN/A////////////////////////////////////////////////////////////////////////
5042623SN/A//
5052623SN/A//  AtomicSimpleCPU Simulation Object
5062623SN/A//
5072623SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
5082623SN/A
5092623SN/A    Param<Counter> max_insts_any_thread;
5102623SN/A    Param<Counter> max_insts_all_threads;
5112623SN/A    Param<Counter> max_loads_any_thread;
5122623SN/A    Param<Counter> max_loads_all_threads;
5133119Sktlim@umich.edu    Param<Tick> progress_interval;
5142901Ssaidi@eecs.umich.edu    SimObjectParam<System *> system;
5153170Sstever@eecs.umich.edu    Param<int> cpu_id;
5162623SN/A
5172623SN/A#if FULL_SYSTEM
5183453Sgblack@eecs.umich.edu    SimObjectParam<TheISA::ITB *> itb;
5193453Sgblack@eecs.umich.edu    SimObjectParam<TheISA::DTB *> dtb;
5202623SN/A    Param<Tick> profile;
5213617Sbinkertn@umich.edu
5223617Sbinkertn@umich.edu    Param<bool> do_quiesce;
5233617Sbinkertn@umich.edu    Param<bool> do_checkpoint_insts;
5243617Sbinkertn@umich.edu    Param<bool> do_statistics_insts;
5252623SN/A#else
5262623SN/A    SimObjectParam<Process *> workload;
5272623SN/A#endif // FULL_SYSTEM
5282623SN/A
5292623SN/A    Param<int> clock;
5303661Srdreslin@umich.edu    Param<int> phase;
5312623SN/A
5322623SN/A    Param<bool> defer_registration;
5332623SN/A    Param<int> width;
5342623SN/A    Param<bool> function_trace;
5352623SN/A    Param<Tick> function_trace_start;
5362623SN/A    Param<bool> simulate_stalls;
5372623SN/A
5382623SN/AEND_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
5392623SN/A
5402623SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
5412623SN/A
5422623SN/A    INIT_PARAM(max_insts_any_thread,
5432623SN/A               "terminate when any thread reaches this inst count"),
5442623SN/A    INIT_PARAM(max_insts_all_threads,
5452623SN/A               "terminate when all threads have reached this inst count"),
5462623SN/A    INIT_PARAM(max_loads_any_thread,
5472623SN/A               "terminate when any thread reaches this load count"),
5482623SN/A    INIT_PARAM(max_loads_all_threads,
5492623SN/A               "terminate when all threads have reached this load count"),
5503119Sktlim@umich.edu    INIT_PARAM(progress_interval, "Progress interval"),
5512901Ssaidi@eecs.umich.edu    INIT_PARAM(system, "system object"),
5523170Sstever@eecs.umich.edu    INIT_PARAM(cpu_id, "processor ID"),
5532623SN/A
5542623SN/A#if FULL_SYSTEM
5552623SN/A    INIT_PARAM(itb, "Instruction TLB"),
5562623SN/A    INIT_PARAM(dtb, "Data TLB"),
5572623SN/A    INIT_PARAM(profile, ""),
5583617Sbinkertn@umich.edu    INIT_PARAM(do_quiesce, ""),
5593617Sbinkertn@umich.edu    INIT_PARAM(do_checkpoint_insts, ""),
5603617Sbinkertn@umich.edu    INIT_PARAM(do_statistics_insts, ""),
5612623SN/A#else
5622623SN/A    INIT_PARAM(workload, "processes to run"),
5632623SN/A#endif // FULL_SYSTEM
5642623SN/A
5652623SN/A    INIT_PARAM(clock, "clock speed"),
5663661Srdreslin@umich.edu    INIT_PARAM_DFLT(phase, "clock phase", 0),
5672623SN/A    INIT_PARAM(defer_registration, "defer system registration (for sampling)"),
5682623SN/A    INIT_PARAM(width, "cpu width"),
5692623SN/A    INIT_PARAM(function_trace, "Enable function trace"),
5702623SN/A    INIT_PARAM(function_trace_start, "Cycle to start function trace"),
5712623SN/A    INIT_PARAM(simulate_stalls, "Simulate cache stall cycles")
5722623SN/A
5732623SN/AEND_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
5742623SN/A
5752623SN/A
5762623SN/ACREATE_SIM_OBJECT(AtomicSimpleCPU)
5772623SN/A{
5782623SN/A    AtomicSimpleCPU::Params *params = new AtomicSimpleCPU::Params();
5792623SN/A    params->name = getInstanceName();
5802623SN/A    params->numberOfThreads = 1;
5812623SN/A    params->max_insts_any_thread = max_insts_any_thread;
5822623SN/A    params->max_insts_all_threads = max_insts_all_threads;
5832623SN/A    params->max_loads_any_thread = max_loads_any_thread;
5842623SN/A    params->max_loads_all_threads = max_loads_all_threads;
5853119Sktlim@umich.edu    params->progress_interval = progress_interval;
5862623SN/A    params->deferRegistration = defer_registration;
5873661Srdreslin@umich.edu    params->phase = phase;
5882623SN/A    params->clock = clock;
5892623SN/A    params->functionTrace = function_trace;
5902623SN/A    params->functionTraceStart = function_trace_start;
5912623SN/A    params->width = width;
5922623SN/A    params->simulate_stalls = simulate_stalls;
5932901Ssaidi@eecs.umich.edu    params->system = system;
5943170Sstever@eecs.umich.edu    params->cpu_id = cpu_id;
5952623SN/A
5962623SN/A#if FULL_SYSTEM
5972623SN/A    params->itb = itb;
5982623SN/A    params->dtb = dtb;
5992623SN/A    params->profile = profile;
6003617Sbinkertn@umich.edu    params->do_quiesce = do_quiesce;
6013617Sbinkertn@umich.edu    params->do_checkpoint_insts = do_checkpoint_insts;
6023617Sbinkertn@umich.edu    params->do_statistics_insts = do_statistics_insts;
6032623SN/A#else
6042623SN/A    params->process = workload;
6052623SN/A#endif
6062623SN/A
6072623SN/A    AtomicSimpleCPU *cpu = new AtomicSimpleCPU(params);
6082623SN/A    return cpu;
6092623SN/A}
6102623SN/A
6112623SN/AREGISTER_SIM_OBJECT("AtomicSimpleCPU", AtomicSimpleCPU)
6122623SN/A
613