cpu.cc

来自「M5,一个功能强大的多处理器系统模拟器.很多针对处理器架构,性能的研究都使用它作」· CC 代码 · 共 1,477 行 · 第 1/3 页

CC
1,477
字号
            tickEvent.schedule(nextCycle());        }    }    if (!tickEvent.scheduled())        tickEvent.schedule(nextCycle());}template <class Impl>uint64_tFullO3CPU<Impl>::readIntReg(int reg_idx){    return regFile.readIntReg(reg_idx);}template <class Impl>FloatRegFullO3CPU<Impl>::readFloatReg(int reg_idx, int width){    return regFile.readFloatReg(reg_idx, width);}template <class Impl>FloatRegFullO3CPU<Impl>::readFloatReg(int reg_idx){    return regFile.readFloatReg(reg_idx);}template <class Impl>FloatRegBitsFullO3CPU<Impl>::readFloatRegBits(int reg_idx, int width){    return regFile.readFloatRegBits(reg_idx, width);}template <class Impl>FloatRegBitsFullO3CPU<Impl>::readFloatRegBits(int reg_idx){    return regFile.readFloatRegBits(reg_idx);}template <class Impl>voidFullO3CPU<Impl>::setIntReg(int reg_idx, uint64_t val){    regFile.setIntReg(reg_idx, val);}template <class Impl>voidFullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val, int width){    regFile.setFloatReg(reg_idx, val, width);}template <class Impl>voidFullO3CPU<Impl>::setFloatReg(int reg_idx, FloatReg val){    regFile.setFloatReg(reg_idx, val);}template <class Impl>voidFullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val, int width){    regFile.setFloatRegBits(reg_idx, val, width);}template <class Impl>voidFullO3CPU<Impl>::setFloatRegBits(int reg_idx, FloatRegBits val){    regFile.setFloatRegBits(reg_idx, val);}template <class Impl>uint64_tFullO3CPU<Impl>::readArchIntReg(int reg_idx, unsigned tid){    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);    return regFile.readIntReg(phys_reg);}template <class Impl>floatFullO3CPU<Impl>::readArchFloatRegSingle(int reg_idx, unsigned tid){    int idx = reg_idx + TheISA::FP_Base_DepTag;    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);    return regFile.readFloatReg(phys_reg);}template <class Impl>doubleFullO3CPU<Impl>::readArchFloatRegDouble(int reg_idx, unsigned tid){    int idx = reg_idx + TheISA::FP_Base_DepTag;    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);    return regFile.readFloatReg(phys_reg, 64);}template <class Impl>uint64_tFullO3CPU<Impl>::readArchFloatRegInt(int reg_idx, unsigned tid){    int idx = reg_idx + TheISA::FP_Base_DepTag;    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);    return regFile.readFloatRegBits(phys_reg);}template <class Impl>voidFullO3CPU<Impl>::setArchIntReg(int reg_idx, uint64_t val, unsigned tid){    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(reg_idx);    regFile.setIntReg(phys_reg, val);}template <class Impl>voidFullO3CPU<Impl>::setArchFloatRegSingle(int reg_idx, float val, unsigned tid){    int idx = reg_idx + TheISA::FP_Base_DepTag;    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);    regFile.setFloatReg(phys_reg, val);}template <class Impl>voidFullO3CPU<Impl>::setArchFloatRegDouble(int reg_idx, double val, unsigned tid){    int idx = reg_idx + TheISA::FP_Base_DepTag;    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);    regFile.setFloatReg(phys_reg, val, 64);}template <class Impl>voidFullO3CPU<Impl>::setArchFloatRegInt(int reg_idx, uint64_t val, unsigned tid){    int idx = reg_idx + TheISA::FP_Base_DepTag;    PhysRegIndex phys_reg = commitRenameMap[tid].lookup(idx);    regFile.setFloatRegBits(phys_reg, val);}template <class Impl>uint64_tFullO3CPU<Impl>::readPC(unsigned tid){    return commit.readPC(tid);}template <class Impl>voidFullO3CPU<Impl>::setPC(Addr new_PC,unsigned tid){    commit.setPC(new_PC, tid);}template <class Impl>uint64_tFullO3CPU<Impl>::readMicroPC(unsigned tid){    return commit.readMicroPC(tid);}template <class Impl>voidFullO3CPU<Impl>::setMicroPC(Addr new_PC,unsigned tid){    commit.setMicroPC(new_PC, tid);}template <class Impl>uint64_tFullO3CPU<Impl>::readNextPC(unsigned tid){    return commit.readNextPC(tid);}template <class Impl>voidFullO3CPU<Impl>::setNextPC(uint64_t val,unsigned tid){    commit.setNextPC(val, tid);}template <class Impl>uint64_tFullO3CPU<Impl>::readNextNPC(unsigned tid){    return commit.readNextNPC(tid);}template <class Impl>voidFullO3CPU<Impl>::setNextNPC(uint64_t val,unsigned tid){    commit.setNextNPC(val, tid);}template <class Impl>uint64_tFullO3CPU<Impl>::readNextMicroPC(unsigned tid){    return commit.readNextMicroPC(tid);}template <class Impl>voidFullO3CPU<Impl>::setNextMicroPC(Addr new_PC,unsigned tid){    commit.setNextMicroPC(new_PC, tid);}template <class Impl>typename FullO3CPU<Impl>::ListItFullO3CPU<Impl>::addInst(DynInstPtr &inst){    instList.push_back(inst);    return --(instList.end());}template <class Impl>voidFullO3CPU<Impl>::instDone(unsigned tid){    // Keep an instruction count.    thread[tid]->numInst++;    thread[tid]->numInsts++;    committedInsts[tid]++;    totalCommittedInsts++;    // Check for instruction-count-based events.    comInstEventQueue[tid]->serviceEvents(thread[tid]->numInst);}template <class Impl>voidFullO3CPU<Impl>::addToRemoveList(DynInstPtr &inst){    removeInstsThisCycle = true;    removeList.push(inst->getInstListIt());}template <class Impl>voidFullO3CPU<Impl>::removeFrontInst(DynInstPtr &inst){    DPRINTF(O3CPU, "Removing committed instruction [tid:%i] PC %#x "            "[sn:%lli]\n",            inst->threadNumber, inst->readPC(), inst->seqNum);    removeInstsThisCycle = true;    // Remove the front instruction.    removeList.push(inst->getInstListIt());}template <class Impl>voidFullO3CPU<Impl>::removeInstsNotInROB(unsigned tid){    DPRINTF(O3CPU, "Thread %i: Deleting instructions from instruction"            " list.\n", tid);    ListIt end_it;    bool rob_empty = false;    if (instList.empty()) {        return;    } else if (rob.isEmpty(/*tid*/)) {        DPRINTF(O3CPU, "ROB is empty, squashing all insts.\n");        end_it = instList.begin();        rob_empty = true;    } else {        end_it = (rob.readTailInst(tid))->getInstListIt();        DPRINTF(O3CPU, "ROB is not empty, squashing insts not in ROB.\n");    }    removeInstsThisCycle = true;    ListIt inst_it = instList.end();    inst_it--;    // Walk through the instruction list, removing any instructions    // that were inserted after the given instruction iterator, end_it.    while (inst_it != end_it) {        assert(!instList.empty());        squashInstIt(inst_it, tid);        inst_it--;    }    // If the ROB was empty, then we actually need to remove the first    // instruction as well.    if (rob_empty) {        squashInstIt(inst_it, tid);    }}template <class Impl>voidFullO3CPU<Impl>::removeInstsUntil(const InstSeqNum &seq_num,                                  unsigned tid){    assert(!instList.empty());    removeInstsThisCycle = true;    ListIt inst_iter = instList.end();    inst_iter--;    DPRINTF(O3CPU, "Deleting instructions from instruction "            "list that are from [tid:%i] and above [sn:%lli] (end=%lli).\n",            tid, seq_num, (*inst_iter)->seqNum);    while ((*inst_iter)->seqNum > seq_num) {        bool break_loop = (inst_iter == instList.begin());        squashInstIt(inst_iter, tid);        inst_iter--;        if (break_loop)            break;    }}template <class Impl>inline voidFullO3CPU<Impl>::squashInstIt(const ListIt &instIt, const unsigned &tid){    if ((*instIt)->threadNumber == tid) {        DPRINTF(O3CPU, "Squashing instruction, "                "[tid:%i] [sn:%lli] PC %#x\n",                (*instIt)->threadNumber,                (*instIt)->seqNum,                (*instIt)->readPC());        // Mark it as squashed.        (*instIt)->setSquashed();        // @todo: Formulate a consistent method for deleting        // instructions from the instruction list        // Remove the instruction from the list.        removeList.push(instIt);    }}template <class Impl>voidFullO3CPU<Impl>::cleanUpRemovedInsts(){    while (!removeList.empty()) {        DPRINTF(O3CPU, "Removing instruction, "                "[tid:%i] [sn:%lli] PC %#x\n",                (*removeList.front())->threadNumber,                (*removeList.front())->seqNum,                (*removeList.front())->readPC());        instList.erase(removeList.front());        removeList.pop();    }    removeInstsThisCycle = false;}/*template <class Impl>voidFullO3CPU<Impl>::removeAllInsts(){    instList.clear();}*/template <class Impl>voidFullO3CPU<Impl>::dumpInsts(){    int num = 0;    ListIt inst_list_it = instList.begin();    cprintf("Dumping Instruction List\n");    while (inst_list_it != instList.end()) {        cprintf("Instruction:%i\nPC:%#x\n[tid:%i]\n[sn:%lli]\nIssued:%i\n"                "Squashed:%i\n\n",                num, (*inst_list_it)->readPC(), (*inst_list_it)->threadNumber,                (*inst_list_it)->seqNum, (*inst_list_it)->isIssued(),                (*inst_list_it)->isSquashed());        inst_list_it++;        ++num;    }}/*template <class Impl>voidFullO3CPU<Impl>::wakeDependents(DynInstPtr &inst){    iew.wakeDependents(inst);}*/template <class Impl>voidFullO3CPU<Impl>::wakeCPU(){    if (activityRec.active() || tickEvent.scheduled()) {        DPRINTF(Activity, "CPU already running.\n");        return;    }    DPRINTF(Activity, "Waking up CPU\n");    idleCycles += tickToCycles((curTick - 1) - lastRunningCycle);    numCycles += tickToCycles((curTick - 1) - lastRunningCycle);    tickEvent.schedule(nextCycle());}template <class Impl>intFullO3CPU<Impl>::getFreeTid(){    for (int i=0; i < numThreads; i++) {        if (!tids[i]) {            tids[i] = true;            return i;        }    }    return -1;}template <class Impl>voidFullO3CPU<Impl>::doContextSwitch(){    if (contextSwitch) {        //ADD CODE TO DEACTIVE THREAD HERE (???)        for (int tid=0; tid < cpuWaitList.size(); tid++) {            activateWhenReady(tid);        }        if (cpuWaitList.size() == 0)            contextSwitch = true;    }}template <class Impl>voidFullO3CPU<Impl>::updateThreadPriority(){    if (activeThreads.size() > 1)    {        //DEFAULT TO ROUND ROBIN SCHEME        //e.g. Move highest priority to end of thread list        std::list<unsigned>::iterator list_begin = activeThreads.begin();        std::list<unsigned>::iterator list_end   = activeThreads.end();        unsigned high_thread = *list_begin;        activeThreads.erase(list_begin);        activeThreads.push_back(high_thread);    }}// Forward declaration of FullO3CPU.template class FullO3CPU<O3CPUImpl>;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?