atomic.cc revision 3387
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    //Create Memory Ports (conect them up)
762856Srdreslin@umich.edu//    Port *mem_dport = mem->getPort("");
772856Srdreslin@umich.edu//    dcachePort.setPeer(mem_dport);
782856Srdreslin@umich.edu//    mem_dport->setPeer(&dcachePort);
792623SN/A
802856Srdreslin@umich.edu//    Port *mem_iport = mem->getPort("");
812856Srdreslin@umich.edu//    icachePort.setPeer(mem_iport);
822856Srdreslin@umich.edu//    mem_iport->setPeer(&icachePort);
832623SN/A
842623SN/A    BaseCPU::init();
852623SN/A#if FULL_SYSTEM
862680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
872680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
882623SN/A
892623SN/A        // initialize CPU, including PC
902680Sktlim@umich.edu        TheISA::initCPU(tc, tc->readCpuId());
912623SN/A    }
922623SN/A#endif
932623SN/A}
942623SN/A
952623SN/Abool
963349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvTiming(PacketPtr pkt)
972623SN/A{
983184Srdreslin@umich.edu    panic("AtomicSimpleCPU doesn't expect recvTiming callback!");
992623SN/A    return true;
1002623SN/A}
1012623SN/A
1022623SN/ATick
1033349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvAtomic(PacketPtr pkt)
1042623SN/A{
1053310Srdreslin@umich.edu    //Snooping a coherence request, just return
1062623SN/A    return curTick;
1072623SN/A}
1082623SN/A
1092623SN/Avoid
1103349Sbinkertn@umich.eduAtomicSimpleCPU::CpuPort::recvFunctional(PacketPtr pkt)
1112623SN/A{
1123184Srdreslin@umich.edu    //No internal storage to update, just return
1133184Srdreslin@umich.edu    return;
1142623SN/A}
1152623SN/A
1162623SN/Avoid
1172623SN/AAtomicSimpleCPU::CpuPort::recvStatusChange(Status status)
1182623SN/A{
1192626SN/A    if (status == RangeChange)
1202626SN/A        return;
1212626SN/A
1222623SN/A    panic("AtomicSimpleCPU doesn't expect recvStatusChange callback!");
1232623SN/A}
1242623SN/A
1252657Ssaidi@eecs.umich.eduvoid
1262623SN/AAtomicSimpleCPU::CpuPort::recvRetry()
1272623SN/A{
1282623SN/A    panic("AtomicSimpleCPU doesn't expect recvRetry callback!");
1292623SN/A}
1302623SN/A
1312623SN/A
1322623SN/AAtomicSimpleCPU::AtomicSimpleCPU(Params *p)
1332623SN/A    : BaseSimpleCPU(p), tickEvent(this),
1342623SN/A      width(p->width), simulate_stalls(p->simulate_stalls),
1352640Sstever@eecs.umich.edu      icachePort(name() + "-iport", this), dcachePort(name() + "-iport", this)
1362623SN/A{
1372623SN/A    _status = Idle;
1382623SN/A
1392663Sstever@eecs.umich.edu    ifetch_req = new Request();
1403170Sstever@eecs.umich.edu    ifetch_req->setThreadContext(p->cpu_id, 0); // Add thread ID if we add MT
1412641Sstever@eecs.umich.edu    ifetch_pkt = new Packet(ifetch_req, Packet::ReadReq, Packet::Broadcast);
1422623SN/A    ifetch_pkt->dataStatic(&inst);
1432623SN/A
1442663Sstever@eecs.umich.edu    data_read_req = new Request();
1453170Sstever@eecs.umich.edu    data_read_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
1462641Sstever@eecs.umich.edu    data_read_pkt = new Packet(data_read_req, Packet::ReadReq,
1472641Sstever@eecs.umich.edu                               Packet::Broadcast);
1482623SN/A    data_read_pkt->dataStatic(&dataReg);
1492623SN/A
1502663Sstever@eecs.umich.edu    data_write_req = new Request();
1513170Sstever@eecs.umich.edu    data_write_req->setThreadContext(p->cpu_id, 0); // Add thread ID here too
1522641Sstever@eecs.umich.edu    data_write_pkt = new Packet(data_write_req, Packet::WriteReq,
1532641Sstever@eecs.umich.edu                                Packet::Broadcast);
1542623SN/A}
1552623SN/A
1562623SN/A
1572623SN/AAtomicSimpleCPU::~AtomicSimpleCPU()
1582623SN/A{
1592623SN/A}
1602623SN/A
1612623SN/Avoid
1622623SN/AAtomicSimpleCPU::serialize(ostream &os)
1632623SN/A{
1642915Sktlim@umich.edu    SimObject::State so_state = SimObject::getState();
1652915Sktlim@umich.edu    SERIALIZE_ENUM(so_state);
1663177Shsul@eecs.umich.edu    Status _status = status();
1673177Shsul@eecs.umich.edu    SERIALIZE_ENUM(_status);
1683145Shsul@eecs.umich.edu    BaseSimpleCPU::serialize(os);
1692623SN/A    nameOut(os, csprintf("%s.tickEvent", name()));
1702623SN/A    tickEvent.serialize(os);
1712623SN/A}
1722623SN/A
1732623SN/Avoid
1742623SN/AAtomicSimpleCPU::unserialize(Checkpoint *cp, const string &section)
1752623SN/A{
1762915Sktlim@umich.edu    SimObject::State so_state;
1772915Sktlim@umich.edu    UNSERIALIZE_ENUM(so_state);
1783177Shsul@eecs.umich.edu    UNSERIALIZE_ENUM(_status);
1793145Shsul@eecs.umich.edu    BaseSimpleCPU::unserialize(cp, section);
1802915Sktlim@umich.edu    tickEvent.unserialize(cp, csprintf("%s.tickEvent", section));
1812915Sktlim@umich.edu}
1822915Sktlim@umich.edu
1832915Sktlim@umich.eduvoid
1842915Sktlim@umich.eduAtomicSimpleCPU::resume()
1852915Sktlim@umich.edu{
1862926Sktlim@umich.edu    changeState(SimObject::Running);
1872915Sktlim@umich.edu    if (thread->status() == ThreadContext::Active) {
1883201Shsul@eecs.umich.edu        assert(system->getMemoryMode() == System::Atomic);
1892915Sktlim@umich.edu        if (!tickEvent.scheduled())
1902915Sktlim@umich.edu            tickEvent.schedule(curTick);
1912915Sktlim@umich.edu    }
1922623SN/A}
1932623SN/A
1942623SN/Avoid
1952798Sktlim@umich.eduAtomicSimpleCPU::switchOut()
1962623SN/A{
1972798Sktlim@umich.edu    assert(status() == Running || status() == Idle);
1982798Sktlim@umich.edu    _status = SwitchedOut;
1992623SN/A
2002798Sktlim@umich.edu    tickEvent.squash();
2012623SN/A}
2022623SN/A
2032623SN/A
2042623SN/Avoid
2052623SN/AAtomicSimpleCPU::takeOverFrom(BaseCPU *oldCPU)
2062623SN/A{
2072623SN/A    BaseCPU::takeOverFrom(oldCPU);
2082623SN/A
2092623SN/A    assert(!tickEvent.scheduled());
2102623SN/A
2112680Sktlim@umich.edu    // if any of this CPU's ThreadContexts are active, mark the CPU as
2122623SN/A    // running and schedule its tick event.
2132680Sktlim@umich.edu    for (int i = 0; i < threadContexts.size(); ++i) {
2142680Sktlim@umich.edu        ThreadContext *tc = threadContexts[i];
2152680Sktlim@umich.edu        if (tc->status() == ThreadContext::Active && _status != Running) {
2162623SN/A            _status = Running;
2172623SN/A            tickEvent.schedule(curTick);
2182623SN/A            break;
2192623SN/A        }
2202623SN/A    }
2212623SN/A}
2222623SN/A
2232623SN/A
2242623SN/Avoid
2252623SN/AAtomicSimpleCPU::activateContext(int thread_num, int delay)
2262623SN/A{
2272623SN/A    assert(thread_num == 0);
2282683Sktlim@umich.edu    assert(thread);
2292623SN/A
2302623SN/A    assert(_status == Idle);
2312623SN/A    assert(!tickEvent.scheduled());
2322623SN/A
2332623SN/A    notIdleFraction++;
2342623SN/A    tickEvent.schedule(curTick + cycles(delay));
2352623SN/A    _status = Running;
2362623SN/A}
2372623SN/A
2382623SN/A
2392623SN/Avoid
2402623SN/AAtomicSimpleCPU::suspendContext(int thread_num)
2412623SN/A{
2422623SN/A    assert(thread_num == 0);
2432683Sktlim@umich.edu    assert(thread);
2442623SN/A
2452623SN/A    assert(_status == Running);
2462626SN/A
2472626SN/A    // tick event may not be scheduled if this gets called from inside
2482626SN/A    // an instruction's execution, e.g. "quiesce"
2492626SN/A    if (tickEvent.scheduled())
2502626SN/A        tickEvent.deschedule();
2512623SN/A
2522623SN/A    notIdleFraction--;
2532623SN/A    _status = Idle;
2542623SN/A}
2552623SN/A
2562623SN/A
2572623SN/Atemplate <class T>
2582623SN/AFault
2592623SN/AAtomicSimpleCPU::read(Addr addr, T &data, unsigned flags)
2602623SN/A{
2613169Sstever@eecs.umich.edu    // use the CPU's statically allocated read request and packet objects
2623169Sstever@eecs.umich.edu    Request *req = data_read_req;
2633349Sbinkertn@umich.edu    PacketPtr pkt = data_read_pkt;
2643169Sstever@eecs.umich.edu
2653169Sstever@eecs.umich.edu    req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
2662623SN/A
2672623SN/A    if (traceData) {
2682623SN/A        traceData->setAddr(addr);
2692623SN/A    }
2702623SN/A
2712623SN/A    // translate to physical address
2723169Sstever@eecs.umich.edu    Fault fault = thread->translateDataReadReq(req);
2732623SN/A
2742623SN/A    // Now do the access.
2752623SN/A    if (fault == NoFault) {
2763169Sstever@eecs.umich.edu        pkt->reinitFromRequest();
2772623SN/A
2783169Sstever@eecs.umich.edu        dcache_latency = dcachePort.sendAtomic(pkt);
2792623SN/A        dcache_access = true;
2802623SN/A
2813169Sstever@eecs.umich.edu        assert(pkt->result == Packet::Success);
2823169Sstever@eecs.umich.edu        data = pkt->get<T>();
2833170Sstever@eecs.umich.edu
2843170Sstever@eecs.umich.edu        if (req->isLocked()) {
2853170Sstever@eecs.umich.edu            TheISA::handleLockedRead(thread, req);
2863170Sstever@eecs.umich.edu        }
2872623SN/A    }
2882623SN/A
2892623SN/A    // This will need a new way to tell if it has a dcache attached.
2903172Sstever@eecs.umich.edu    if (req->isUncacheable())
2912623SN/A        recordEvent("Uncached Read");
2922623SN/A
2932623SN/A    return fault;
2942623SN/A}
2952623SN/A
2962623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
2972623SN/A
2982623SN/Atemplate
2992623SN/AFault
3002623SN/AAtomicSimpleCPU::read(Addr addr, uint64_t &data, unsigned flags);
3012623SN/A
3022623SN/Atemplate
3032623SN/AFault
3042623SN/AAtomicSimpleCPU::read(Addr addr, uint32_t &data, unsigned flags);
3052623SN/A
3062623SN/Atemplate
3072623SN/AFault
3082623SN/AAtomicSimpleCPU::read(Addr addr, uint16_t &data, unsigned flags);
3092623SN/A
3102623SN/Atemplate
3112623SN/AFault
3122623SN/AAtomicSimpleCPU::read(Addr addr, uint8_t &data, unsigned flags);
3132623SN/A
3142623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
3152623SN/A
3162623SN/Atemplate<>
3172623SN/AFault
3182623SN/AAtomicSimpleCPU::read(Addr addr, double &data, unsigned flags)
3192623SN/A{
3202623SN/A    return read(addr, *(uint64_t*)&data, flags);
3212623SN/A}
3222623SN/A
3232623SN/Atemplate<>
3242623SN/AFault
3252623SN/AAtomicSimpleCPU::read(Addr addr, float &data, unsigned flags)
3262623SN/A{
3272623SN/A    return read(addr, *(uint32_t*)&data, flags);
3282623SN/A}
3292623SN/A
3302623SN/A
3312623SN/Atemplate<>
3322623SN/AFault
3332623SN/AAtomicSimpleCPU::read(Addr addr, int32_t &data, unsigned flags)
3342623SN/A{
3352623SN/A    return read(addr, (uint32_t&)data, flags);
3362623SN/A}
3372623SN/A
3382623SN/A
3392623SN/Atemplate <class T>
3402623SN/AFault
3412623SN/AAtomicSimpleCPU::write(T data, Addr addr, unsigned flags, uint64_t *res)
3422623SN/A{
3433169Sstever@eecs.umich.edu    // use the CPU's statically allocated write request and packet objects
3443169Sstever@eecs.umich.edu    Request *req = data_write_req;
3453349Sbinkertn@umich.edu    PacketPtr pkt = data_write_pkt;
3463169Sstever@eecs.umich.edu
3473169Sstever@eecs.umich.edu    req->setVirt(0, addr, sizeof(T), flags, thread->readPC());
3482623SN/A
3492623SN/A    if (traceData) {
3502623SN/A        traceData->setAddr(addr);
3512623SN/A    }
3522623SN/A
3532623SN/A    // translate to physical address
3543169Sstever@eecs.umich.edu    Fault fault = thread->translateDataWriteReq(req);
3552623SN/A
3562623SN/A    // Now do the access.
3572623SN/A    if (fault == NoFault) {
3583170Sstever@eecs.umich.edu        bool do_access = true;  // flag to suppress cache access
3592623SN/A
3603170Sstever@eecs.umich.edu        if (req->isLocked()) {
3613170Sstever@eecs.umich.edu            do_access = TheISA::handleLockedWrite(thread, req);
3623170Sstever@eecs.umich.edu        }
3632623SN/A
3643170Sstever@eecs.umich.edu        if (do_access) {
3653170Sstever@eecs.umich.edu            data = htog(data);
3663170Sstever@eecs.umich.edu            pkt->reinitFromRequest();
3673170Sstever@eecs.umich.edu            pkt->dataStatic(&data);
3682631SN/A
3693170Sstever@eecs.umich.edu            dcache_latency = dcachePort.sendAtomic(pkt);
3703170Sstever@eecs.umich.edu            dcache_access = true;
3713170Sstever@eecs.umich.edu
3723170Sstever@eecs.umich.edu            assert(pkt->result == Packet::Success);
3733170Sstever@eecs.umich.edu        }
3743170Sstever@eecs.umich.edu
3753170Sstever@eecs.umich.edu        if (req->isLocked()) {
3763170Sstever@eecs.umich.edu            uint64_t scResult = req->getScResult();
3773170Sstever@eecs.umich.edu            if (scResult != 0) {
3783170Sstever@eecs.umich.edu                // clear failure counter
3793170Sstever@eecs.umich.edu                thread->setStCondFailures(0);
3803170Sstever@eecs.umich.edu            }
3813170Sstever@eecs.umich.edu            if (res) {
3823170Sstever@eecs.umich.edu                *res = req->getScResult();
3833170Sstever@eecs.umich.edu            }
3842631SN/A        }
3852623SN/A    }
3862623SN/A
3872623SN/A    // This will need a new way to tell if it's hooked up to a cache or not.
3883172Sstever@eecs.umich.edu    if (req->isUncacheable())
3892623SN/A        recordEvent("Uncached Write");
3902623SN/A
3912623SN/A    // If the write needs to have a fault on the access, consider calling
3922623SN/A    // changeStatus() and changing it to "bad addr write" or something.
3932623SN/A    return fault;
3942623SN/A}
3952623SN/A
3962623SN/A
3972623SN/A#ifndef DOXYGEN_SHOULD_SKIP_THIS
3982623SN/Atemplate
3992623SN/AFault
4002623SN/AAtomicSimpleCPU::write(uint64_t data, Addr addr,
4012623SN/A                       unsigned flags, uint64_t *res);
4022623SN/A
4032623SN/Atemplate
4042623SN/AFault
4052623SN/AAtomicSimpleCPU::write(uint32_t data, Addr addr,
4062623SN/A                       unsigned flags, uint64_t *res);
4072623SN/A
4082623SN/Atemplate
4092623SN/AFault
4102623SN/AAtomicSimpleCPU::write(uint16_t data, Addr addr,
4112623SN/A                       unsigned flags, uint64_t *res);
4122623SN/A
4132623SN/Atemplate
4142623SN/AFault
4152623SN/AAtomicSimpleCPU::write(uint8_t data, Addr addr,
4162623SN/A                       unsigned flags, uint64_t *res);
4172623SN/A
4182623SN/A#endif //DOXYGEN_SHOULD_SKIP_THIS
4192623SN/A
4202623SN/Atemplate<>
4212623SN/AFault
4222623SN/AAtomicSimpleCPU::write(double data, Addr addr, unsigned flags, uint64_t *res)
4232623SN/A{
4242623SN/A    return write(*(uint64_t*)&data, addr, flags, res);
4252623SN/A}
4262623SN/A
4272623SN/Atemplate<>
4282623SN/AFault
4292623SN/AAtomicSimpleCPU::write(float data, Addr addr, unsigned flags, uint64_t *res)
4302623SN/A{
4312623SN/A    return write(*(uint32_t*)&data, addr, flags, res);
4322623SN/A}
4332623SN/A
4342623SN/A
4352623SN/Atemplate<>
4362623SN/AFault
4372623SN/AAtomicSimpleCPU::write(int32_t data, Addr addr, unsigned flags, uint64_t *res)
4382623SN/A{
4392623SN/A    return write((uint32_t)data, addr, flags, res);
4402623SN/A}
4412623SN/A
4422623SN/A
4432623SN/Avoid
4442623SN/AAtomicSimpleCPU::tick()
4452623SN/A{
4462623SN/A    Tick latency = cycles(1); // instruction takes one cycle by default
4472623SN/A
4482623SN/A    for (int i = 0; i < width; ++i) {
4492623SN/A        numCycles++;
4502623SN/A
4513387Sgblack@eecs.umich.edu        if (!curStaticInst || !curStaticInst->isDelayedCommit())
4523387Sgblack@eecs.umich.edu            checkForInterrupts();
4532626SN/A
4542662Sstever@eecs.umich.edu        Fault fault = setupFetchRequest(ifetch_req);
4552623SN/A
4562623SN/A        if (fault == NoFault) {
4572662Sstever@eecs.umich.edu            ifetch_pkt->reinitFromRequest();
4582662Sstever@eecs.umich.edu
4592662Sstever@eecs.umich.edu            Tick icache_latency = icachePort.sendAtomic(ifetch_pkt);
4602623SN/A            // ifetch_req is initialized to read the instruction directly
4612623SN/A            // into the CPU object's inst field.
4622623SN/A
4632623SN/A            dcache_access = false; // assume no dcache access
4642623SN/A            preExecute();
4652623SN/A            fault = curStaticInst->execute(this, traceData);
4662623SN/A            postExecute();
4672623SN/A
4682623SN/A            if (simulate_stalls) {
4692662Sstever@eecs.umich.edu                Tick icache_stall = icache_latency - cycles(1);
4702623SN/A                Tick dcache_stall =
4712662Sstever@eecs.umich.edu                    dcache_access ? dcache_latency - cycles(1) : 0;
4722803Ssaidi@eecs.umich.edu                Tick stall_cycles = (icache_stall + dcache_stall) / cycles(1);
4732803Ssaidi@eecs.umich.edu                if (cycles(stall_cycles) < (icache_stall + dcache_stall))
4742803Ssaidi@eecs.umich.edu                    latency += cycles(stall_cycles+1);
4752803Ssaidi@eecs.umich.edu                else
4762803Ssaidi@eecs.umich.edu                    latency += cycles(stall_cycles);
4772623SN/A            }
4782623SN/A
4792623SN/A        }
4802623SN/A
4812623SN/A        advancePC(fault);
4822623SN/A    }
4832623SN/A
4842626SN/A    if (_status != Idle)
4852626SN/A        tickEvent.schedule(curTick + latency);
4862623SN/A}
4872623SN/A
4882623SN/A
4892623SN/A////////////////////////////////////////////////////////////////////////
4902623SN/A//
4912623SN/A//  AtomicSimpleCPU Simulation Object
4922623SN/A//
4932623SN/ABEGIN_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
4942623SN/A
4952623SN/A    Param<Counter> max_insts_any_thread;
4962623SN/A    Param<Counter> max_insts_all_threads;
4972623SN/A    Param<Counter> max_loads_any_thread;
4982623SN/A    Param<Counter> max_loads_all_threads;
4993119Sktlim@umich.edu    Param<Tick> progress_interval;
5002623SN/A    SimObjectParam<MemObject *> mem;
5012901Ssaidi@eecs.umich.edu    SimObjectParam<System *> system;
5023170Sstever@eecs.umich.edu    Param<int> cpu_id;
5032623SN/A
5042623SN/A#if FULL_SYSTEM
5052623SN/A    SimObjectParam<AlphaITB *> itb;
5062623SN/A    SimObjectParam<AlphaDTB *> dtb;
5072623SN/A    Param<Tick> profile;
5082623SN/A#else
5092623SN/A    SimObjectParam<Process *> workload;
5102623SN/A#endif // FULL_SYSTEM
5112623SN/A
5122623SN/A    Param<int> clock;
5132623SN/A
5142623SN/A    Param<bool> defer_registration;
5152623SN/A    Param<int> width;
5162623SN/A    Param<bool> function_trace;
5172623SN/A    Param<Tick> function_trace_start;
5182623SN/A    Param<bool> simulate_stalls;
5192623SN/A
5202623SN/AEND_DECLARE_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
5212623SN/A
5222623SN/ABEGIN_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
5232623SN/A
5242623SN/A    INIT_PARAM(max_insts_any_thread,
5252623SN/A               "terminate when any thread reaches this inst count"),
5262623SN/A    INIT_PARAM(max_insts_all_threads,
5272623SN/A               "terminate when all threads have reached this inst count"),
5282623SN/A    INIT_PARAM(max_loads_any_thread,
5292623SN/A               "terminate when any thread reaches this load count"),
5302623SN/A    INIT_PARAM(max_loads_all_threads,
5312623SN/A               "terminate when all threads have reached this load count"),
5323119Sktlim@umich.edu    INIT_PARAM(progress_interval, "Progress interval"),
5332623SN/A    INIT_PARAM(mem, "memory"),
5342901Ssaidi@eecs.umich.edu    INIT_PARAM(system, "system object"),
5353170Sstever@eecs.umich.edu    INIT_PARAM(cpu_id, "processor ID"),
5362623SN/A
5372623SN/A#if FULL_SYSTEM
5382623SN/A    INIT_PARAM(itb, "Instruction TLB"),
5392623SN/A    INIT_PARAM(dtb, "Data TLB"),
5402623SN/A    INIT_PARAM(profile, ""),
5412623SN/A#else
5422623SN/A    INIT_PARAM(workload, "processes to run"),
5432623SN/A#endif // FULL_SYSTEM
5442623SN/A
5452623SN/A    INIT_PARAM(clock, "clock speed"),
5462623SN/A    INIT_PARAM(defer_registration, "defer system registration (for sampling)"),
5472623SN/A    INIT_PARAM(width, "cpu width"),
5482623SN/A    INIT_PARAM(function_trace, "Enable function trace"),
5492623SN/A    INIT_PARAM(function_trace_start, "Cycle to start function trace"),
5502623SN/A    INIT_PARAM(simulate_stalls, "Simulate cache stall cycles")
5512623SN/A
5522623SN/AEND_INIT_SIM_OBJECT_PARAMS(AtomicSimpleCPU)
5532623SN/A
5542623SN/A
5552623SN/ACREATE_SIM_OBJECT(AtomicSimpleCPU)
5562623SN/A{
5572623SN/A    AtomicSimpleCPU::Params *params = new AtomicSimpleCPU::Params();
5582623SN/A    params->name = getInstanceName();
5592623SN/A    params->numberOfThreads = 1;
5602623SN/A    params->max_insts_any_thread = max_insts_any_thread;
5612623SN/A    params->max_insts_all_threads = max_insts_all_threads;
5622623SN/A    params->max_loads_any_thread = max_loads_any_thread;
5632623SN/A    params->max_loads_all_threads = max_loads_all_threads;
5643119Sktlim@umich.edu    params->progress_interval = progress_interval;
5652623SN/A    params->deferRegistration = defer_registration;
5662623SN/A    params->clock = clock;
5672623SN/A    params->functionTrace = function_trace;
5682623SN/A    params->functionTraceStart = function_trace_start;
5692623SN/A    params->width = width;
5702623SN/A    params->simulate_stalls = simulate_stalls;
5712623SN/A    params->mem = mem;
5722901Ssaidi@eecs.umich.edu    params->system = system;
5733170Sstever@eecs.umich.edu    params->cpu_id = cpu_id;
5742623SN/A
5752623SN/A#if FULL_SYSTEM
5762623SN/A    params->itb = itb;
5772623SN/A    params->dtb = dtb;
5782623SN/A    params->profile = profile;
5792623SN/A#else
5802623SN/A    params->process = workload;
5812623SN/A#endif
5822623SN/A
5832623SN/A    AtomicSimpleCPU *cpu = new AtomicSimpleCPU(params);
5842623SN/A    return cpu;
5852623SN/A}
5862623SN/A
5872623SN/AREGISTER_SIM_OBJECT("AtomicSimpleCPU", AtomicSimpleCPU)
5882623SN/A
589