base.cc revision 13500:6e0a2a7c6d8c
12929Sktlim@umich.edu/* 22929Sktlim@umich.edu * Copyright (c) 2010-2012, 2015, 2017 ARM Limited 32932Sktlim@umich.edu * Copyright (c) 2013 Advanced Micro Devices, Inc. 42929Sktlim@umich.edu * All rights reserved 52929Sktlim@umich.edu * 62929Sktlim@umich.edu * The license below extends only to copyright in the software and shall 72929Sktlim@umich.edu * not be construed as granting a license to any other intellectual 82929Sktlim@umich.edu * property including but not limited to intellectual property relating 92929Sktlim@umich.edu * to a hardware implementation of the functionality of the software 102929Sktlim@umich.edu * licensed hereunder. You may use the software subject to the license 112929Sktlim@umich.edu * terms below provided that you ensure that this notice is replicated 122929Sktlim@umich.edu * unmodified and in its entirety in all distributions of the software, 132929Sktlim@umich.edu * modified or unmodified, in source code or in binary form. 142929Sktlim@umich.edu * 152929Sktlim@umich.edu * Copyright (c) 2002-2005 The Regents of The University of Michigan 162929Sktlim@umich.edu * All rights reserved. 172929Sktlim@umich.edu * 182929Sktlim@umich.edu * Redistribution and use in source and binary forms, with or without 192929Sktlim@umich.edu * modification, are permitted provided that the following conditions are 202929Sktlim@umich.edu * met: redistributions of source code must retain the above copyright 212929Sktlim@umich.edu * notice, this list of conditions and the following disclaimer; 222929Sktlim@umich.edu * redistributions in binary form must reproduce the above copyright 232929Sktlim@umich.edu * notice, this list of conditions and the following disclaimer in the 242929Sktlim@umich.edu * documentation and/or other materials provided with the distribution; 252929Sktlim@umich.edu * neither the name of the copyright holders nor the names of its 262929Sktlim@umich.edu * contributors may be used to endorse or promote products derived from 272929Sktlim@umich.edu * this software without specific prior written permission. 282932Sktlim@umich.edu * 292932Sktlim@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 302932Sktlim@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 312929Sktlim@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 322929Sktlim@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 332929Sktlim@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 342929Sktlim@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 352929Sktlim@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 362929Sktlim@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 372929Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 382929Sktlim@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 392929Sktlim@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 402929Sktlim@umich.edu * 412929Sktlim@umich.edu * Authors: Steve Reinhardt 422929Sktlim@umich.edu */ 432929Sktlim@umich.edu 442929Sktlim@umich.edu#include "cpu/simple/base.hh" 452929Sktlim@umich.edu 462929Sktlim@umich.edu#include "arch/kernel_stats.hh" 472929Sktlim@umich.edu#include "arch/stacktrace.hh" 482929Sktlim@umich.edu#include "arch/utility.hh" 492929Sktlim@umich.edu#include "arch/vtophys.hh" 502929Sktlim@umich.edu#include "base/cp_annotate.hh" 512929Sktlim@umich.edu#include "base/cprintf.hh" 522929Sktlim@umich.edu#include "base/inifile.hh" 532929Sktlim@umich.edu#include "base/loader/symtab.hh" 542929Sktlim@umich.edu#include "base/logging.hh" 552929Sktlim@umich.edu#include "base/pollevent.hh" 562929Sktlim@umich.edu#include "base/trace.hh" 572929Sktlim@umich.edu#include "base/types.hh" 582929Sktlim@umich.edu#include "config/the_isa.hh" 592929Sktlim@umich.edu#include "cpu/base.hh" 602929Sktlim@umich.edu#include "cpu/checker/cpu.hh" 612929Sktlim@umich.edu#include "cpu/checker/thread_context.hh" 622929Sktlim@umich.edu#include "cpu/exetrace.hh" 632929Sktlim@umich.edu#include "cpu/pred/bpred_unit.hh" 643020Sstever@eecs.umich.edu#include "cpu/profile.hh" 653020Sstever@eecs.umich.edu#include "cpu/simple/exec_context.hh" 663020Sstever@eecs.umich.edu#include "cpu/simple_thread.hh" 672929Sktlim@umich.edu#include "cpu/smt.hh" 682929Sktlim@umich.edu#include "cpu/static_inst.hh" 693021Sstever@eecs.umich.edu#include "cpu/thread_context.hh" 702929Sktlim@umich.edu#include "debug/Decode.hh" 712929Sktlim@umich.edu#include "debug/Fetch.hh" 722929Sktlim@umich.edu#include "debug/Quiesce.hh" 732929Sktlim@umich.edu#include "mem/mem_object.hh" 742929Sktlim@umich.edu#include "mem/packet.hh" 752929Sktlim@umich.edu#include "mem/request.hh" 762929Sktlim@umich.edu#include "params/BaseSimpleCPU.hh" 772929Sktlim@umich.edu#include "sim/byteswap.hh" 782929Sktlim@umich.edu#include "sim/debug.hh" 792929Sktlim@umich.edu#include "sim/faults.hh" 802929Sktlim@umich.edu#include "sim/full_system.hh" 812929Sktlim@umich.edu#include "sim/sim_events.hh" 822929Sktlim@umich.edu#include "sim/sim_object.hh" 832929Sktlim@umich.edu#include "sim/stats.hh" 842929Sktlim@umich.edu#include "sim/system.hh" 852929Sktlim@umich.edu 862929Sktlim@umich.eduusing namespace std; 872929Sktlim@umich.eduusing namespace TheISA; 882929Sktlim@umich.edu 892929Sktlim@umich.eduBaseSimpleCPU::BaseSimpleCPU(BaseSimpleCPUParams *p) 902929Sktlim@umich.edu : BaseCPU(p), 912929Sktlim@umich.edu curThread(0), 922929Sktlim@umich.edu branchPred(p->branchPred), 932929Sktlim@umich.edu traceData(NULL), 942929Sktlim@umich.edu inst(), 952929Sktlim@umich.edu _status(Idle) 962929Sktlim@umich.edu{ 972929Sktlim@umich.edu SimpleThread *thread; 982929Sktlim@umich.edu 992929Sktlim@umich.edu for (unsigned i = 0; i < numThreads; i++) { 1002929Sktlim@umich.edu if (FullSystem) { 1012929Sktlim@umich.edu thread = new SimpleThread(this, i, p->system, 1022929Sktlim@umich.edu p->itb, p->dtb, p->isa[i]); 1032929Sktlim@umich.edu } else { 1042929Sktlim@umich.edu thread = new SimpleThread(this, i, p->system, p->workload[i], 1054937Sstever@gmail.com p->itb, p->dtb, p->isa[i]); 1064937Sstever@gmail.com } 1074937Sstever@gmail.com threadInfo.push_back(new SimpleExecContext(this, thread)); 1084937Sstever@gmail.com ThreadContext *tc = thread->getTC(); 1094937Sstever@gmail.com threadContexts.push_back(tc); 1104937Sstever@gmail.com } 1114937Sstever@gmail.com 1124937Sstever@gmail.com if (p->checker) { 1134937Sstever@gmail.com if (numThreads != 1) 1144937Sstever@gmail.com fatal("Checker currently does not support SMT"); 1154937Sstever@gmail.com 1164937Sstever@gmail.com BaseCPU *temp_checker = p->checker; 1174937Sstever@gmail.com checker = dynamic_cast<CheckerCPU *>(temp_checker); 1182929Sktlim@umich.edu checker->setSystem(p->system); 1192929Sktlim@umich.edu // Manipulate thread context 1202929Sktlim@umich.edu ThreadContext *cpu_tc = threadContexts[0]; 1212929Sktlim@umich.edu threadContexts[0] = new CheckerThreadContext<ThreadContext>(cpu_tc, this->checker); 1222929Sktlim@umich.edu } else { 1232929Sktlim@umich.edu checker = NULL; 1242929Sktlim@umich.edu } 1252929Sktlim@umich.edu} 1262929Sktlim@umich.edu 1272929Sktlim@umich.eduvoid 1284937Sstever@gmail.comBaseSimpleCPU::init() 1294937Sstever@gmail.com{ 1304937Sstever@gmail.com BaseCPU::init(); 1314937Sstever@gmail.com 1324937Sstever@gmail.com for (auto tc : threadContexts) { 1334937Sstever@gmail.com // Initialise the ThreadContext's memory proxies 1344937Sstever@gmail.com tc->initMemProxies(tc); 1354937Sstever@gmail.com 1364937Sstever@gmail.com if (FullSystem && !params()->switched_out) { 1374937Sstever@gmail.com // initialize CPU, including PC 1384937Sstever@gmail.com TheISA::initCPU(tc, tc->contextId()); 1394937Sstever@gmail.com } 1404937Sstever@gmail.com } 1414937Sstever@gmail.com} 1424937Sstever@gmail.com 1432929Sktlim@umich.eduvoid 1442929Sktlim@umich.eduBaseSimpleCPU::checkPcEventQueue() 1452929Sktlim@umich.edu{ 1462929Sktlim@umich.edu Addr oldpc, pc = threadInfo[curThread]->thread->instAddr(); 1472929Sktlim@umich.edu do { 1482929Sktlim@umich.edu oldpc = pc; 1492929Sktlim@umich.edu system->pcEventQueue.service(threadContexts[curThread]); 1502929Sktlim@umich.edu pc = threadInfo[curThread]->thread->instAddr(); 1512929Sktlim@umich.edu } while (oldpc != pc); 1522929Sktlim@umich.edu} 1532929Sktlim@umich.edu 1542929Sktlim@umich.eduvoid 1552929Sktlim@umich.eduBaseSimpleCPU::swapActiveThread() 1562929Sktlim@umich.edu{ 1572929Sktlim@umich.edu if (numThreads > 1) { 1582929Sktlim@umich.edu if ((!curStaticInst || !curStaticInst->isDelayedCommit()) && 1592997Sstever@eecs.umich.edu !threadInfo[curThread]->stayAtPC) { 1602997Sstever@eecs.umich.edu // Swap active threads 1612929Sktlim@umich.edu if (!activeThreads.empty()) { 1622997Sstever@eecs.umich.edu curThread = activeThreads.front(); 1632997Sstever@eecs.umich.edu activeThreads.pop_front(); 1642929Sktlim@umich.edu activeThreads.push_back(curThread); 1652997Sstever@eecs.umich.edu } 1662997Sstever@eecs.umich.edu } 1672997Sstever@eecs.umich.edu } 1682929Sktlim@umich.edu} 1692997Sstever@eecs.umich.edu 1702997Sstever@eecs.umich.eduvoid 1712997Sstever@eecs.umich.eduBaseSimpleCPU::countInst() 1722997Sstever@eecs.umich.edu{ 1732997Sstever@eecs.umich.edu SimpleExecContext& t_info = *threadInfo[curThread]; 1742997Sstever@eecs.umich.edu 1752997Sstever@eecs.umich.edu if (!curStaticInst->isMicroop() || curStaticInst->isLastMicroop()) { 1762997Sstever@eecs.umich.edu t_info.numInst++; 1772997Sstever@eecs.umich.edu t_info.numInsts++; 1782997Sstever@eecs.umich.edu } 1792997Sstever@eecs.umich.edu t_info.numOp++; 1802997Sstever@eecs.umich.edu t_info.numOps++; 1815525Sstever@gmail.com 1825526Sstever@gmail.com system->totalNumInsts++; 1835525Sstever@gmail.com t_info.thread->funcExeInst++; 1842997Sstever@eecs.umich.edu} 1852997Sstever@eecs.umich.edu 1862997Sstever@eecs.umich.eduCounter 1875525Sstever@gmail.comBaseSimpleCPU::totalInsts() const 1882997Sstever@eecs.umich.edu{ 1895525Sstever@gmail.com Counter total_inst = 0; 1904781Snate@binkert.org for (auto& t_info : threadInfo) { 1912997Sstever@eecs.umich.edu total_inst += t_info->numInst; 1925525Sstever@gmail.com } 1932929Sktlim@umich.edu 1942997Sstever@eecs.umich.edu return total_inst; 1952997Sstever@eecs.umich.edu} 1962997Sstever@eecs.umich.edu 1972997Sstever@eecs.umich.eduCounter 1982929Sktlim@umich.eduBaseSimpleCPU::totalOps() const 1992997Sstever@eecs.umich.edu{ 2002997Sstever@eecs.umich.edu Counter total_op = 0; 2012997Sstever@eecs.umich.edu for (auto& t_info : threadInfo) { 2022997Sstever@eecs.umich.edu total_op += t_info->numOp; 2032997Sstever@eecs.umich.edu } 2042997Sstever@eecs.umich.edu 2052997Sstever@eecs.umich.edu return total_op; 2062929Sktlim@umich.edu} 2072997Sstever@eecs.umich.edu 2082929Sktlim@umich.eduBaseSimpleCPU::~BaseSimpleCPU() 2092929Sktlim@umich.edu{ 2103005Sstever@eecs.umich.edu} 2113005Sstever@eecs.umich.edu 2123005Sstever@eecs.umich.eduvoid 2133005Sstever@eecs.umich.eduBaseSimpleCPU::haltContext(ThreadID thread_num) 2143005Sstever@eecs.umich.edu{ 2153005Sstever@eecs.umich.edu // for now, these are equivalent 2163005Sstever@eecs.umich.edu suspendContext(thread_num); 2173005Sstever@eecs.umich.edu updateCycleCounters(BaseCPU::CPU_STATE_SLEEP); 2183691Shsul@eecs.umich.edu} 2194781Snate@binkert.org 2204130Ssaidi@eecs.umich.edu 2214130Ssaidi@eecs.umich.eduvoid 2224130Ssaidi@eecs.umich.eduBaseSimpleCPU::regStats() 2233691Shsul@eecs.umich.edu{ 2243005Sstever@eecs.umich.edu using namespace Stats; 2254019Sstever@eecs.umich.edu 2263005Sstever@eecs.umich.edu BaseCPU::regStats(); 2272929Sktlim@umich.edu 2282929Sktlim@umich.edu for (ThreadID tid = 0; tid < numThreads; tid++) { 2293005Sstever@eecs.umich.edu SimpleExecContext& t_info = *threadInfo[tid]; 2302997Sstever@eecs.umich.edu 2312997Sstever@eecs.umich.edu std::string thread_str = name(); 2322997Sstever@eecs.umich.edu if (numThreads > 1) 2332929Sktlim@umich.edu thread_str += ".thread" + std::to_string(tid); 234 235 t_info.numInsts 236 .name(thread_str + ".committedInsts") 237 .desc("Number of instructions committed") 238 ; 239 240 t_info.numOps 241 .name(thread_str + ".committedOps") 242 .desc("Number of ops (including micro ops) committed") 243 ; 244 245 t_info.numIntAluAccesses 246 .name(thread_str + ".num_int_alu_accesses") 247 .desc("Number of integer alu accesses") 248 ; 249 250 t_info.numFpAluAccesses 251 .name(thread_str + ".num_fp_alu_accesses") 252 .desc("Number of float alu accesses") 253 ; 254 255 t_info.numVecAluAccesses 256 .name(thread_str + ".num_vec_alu_accesses") 257 .desc("Number of vector alu accesses") 258 ; 259 260 t_info.numCallsReturns 261 .name(thread_str + ".num_func_calls") 262 .desc("number of times a function call or return occured") 263 ; 264 265 t_info.numCondCtrlInsts 266 .name(thread_str + ".num_conditional_control_insts") 267 .desc("number of instructions that are conditional controls") 268 ; 269 270 t_info.numIntInsts 271 .name(thread_str + ".num_int_insts") 272 .desc("number of integer instructions") 273 ; 274 275 t_info.numFpInsts 276 .name(thread_str + ".num_fp_insts") 277 .desc("number of float instructions") 278 ; 279 280 t_info.numVecInsts 281 .name(thread_str + ".num_vec_insts") 282 .desc("number of vector instructions") 283 ; 284 285 t_info.numIntRegReads 286 .name(thread_str + ".num_int_register_reads") 287 .desc("number of times the integer registers were read") 288 ; 289 290 t_info.numIntRegWrites 291 .name(thread_str + ".num_int_register_writes") 292 .desc("number of times the integer registers were written") 293 ; 294 295 t_info.numFpRegReads 296 .name(thread_str + ".num_fp_register_reads") 297 .desc("number of times the floating registers were read") 298 ; 299 300 t_info.numFpRegWrites 301 .name(thread_str + ".num_fp_register_writes") 302 .desc("number of times the floating registers were written") 303 ; 304 305 t_info.numVecRegReads 306 .name(thread_str + ".num_vec_register_reads") 307 .desc("number of times the vector registers were read") 308 ; 309 310 t_info.numVecRegWrites 311 .name(thread_str + ".num_vec_register_writes") 312 .desc("number of times the vector registers were written") 313 ; 314 315 t_info.numCCRegReads 316 .name(thread_str + ".num_cc_register_reads") 317 .desc("number of times the CC registers were read") 318 .flags(nozero) 319 ; 320 321 t_info.numCCRegWrites 322 .name(thread_str + ".num_cc_register_writes") 323 .desc("number of times the CC registers were written") 324 .flags(nozero) 325 ; 326 327 t_info.numMemRefs 328 .name(thread_str + ".num_mem_refs") 329 .desc("number of memory refs") 330 ; 331 332 t_info.numStoreInsts 333 .name(thread_str + ".num_store_insts") 334 .desc("Number of store instructions") 335 ; 336 337 t_info.numLoadInsts 338 .name(thread_str + ".num_load_insts") 339 .desc("Number of load instructions") 340 ; 341 342 t_info.notIdleFraction 343 .name(thread_str + ".not_idle_fraction") 344 .desc("Percentage of non-idle cycles") 345 ; 346 347 t_info.idleFraction 348 .name(thread_str + ".idle_fraction") 349 .desc("Percentage of idle cycles") 350 ; 351 352 t_info.numBusyCycles 353 .name(thread_str + ".num_busy_cycles") 354 .desc("Number of busy cycles") 355 ; 356 357 t_info.numIdleCycles 358 .name(thread_str + ".num_idle_cycles") 359 .desc("Number of idle cycles") 360 ; 361 362 t_info.icacheStallCycles 363 .name(thread_str + ".icache_stall_cycles") 364 .desc("ICache total stall cycles") 365 .prereq(t_info.icacheStallCycles) 366 ; 367 368 t_info.dcacheStallCycles 369 .name(thread_str + ".dcache_stall_cycles") 370 .desc("DCache total stall cycles") 371 .prereq(t_info.dcacheStallCycles) 372 ; 373 374 t_info.statExecutedInstType 375 .init(Enums::Num_OpClass) 376 .name(thread_str + ".op_class") 377 .desc("Class of executed instruction") 378 .flags(total | pdf | dist) 379 ; 380 381 for (unsigned i = 0; i < Num_OpClasses; ++i) { 382 t_info.statExecutedInstType.subname(i, Enums::OpClassStrings[i]); 383 } 384 385 t_info.idleFraction = constant(1.0) - t_info.notIdleFraction; 386 t_info.numIdleCycles = t_info.idleFraction * numCycles; 387 t_info.numBusyCycles = t_info.notIdleFraction * numCycles; 388 389 t_info.numBranches 390 .name(thread_str + ".Branches") 391 .desc("Number of branches fetched") 392 .prereq(t_info.numBranches); 393 394 t_info.numPredictedBranches 395 .name(thread_str + ".predictedBranches") 396 .desc("Number of branches predicted as taken") 397 .prereq(t_info.numPredictedBranches); 398 399 t_info.numBranchMispred 400 .name(thread_str + ".BranchMispred") 401 .desc("Number of branch mispredictions") 402 .prereq(t_info.numBranchMispred); 403 } 404} 405 406void 407BaseSimpleCPU::resetStats() 408{ 409 for (auto &thread_info : threadInfo) { 410 thread_info->notIdleFraction = (_status != Idle); 411 } 412} 413 414void 415BaseSimpleCPU::serializeThread(CheckpointOut &cp, ThreadID tid) const 416{ 417 assert(_status == Idle || _status == Running); 418 419 threadInfo[tid]->thread->serialize(cp); 420} 421 422void 423BaseSimpleCPU::unserializeThread(CheckpointIn &cp, ThreadID tid) 424{ 425 threadInfo[tid]->thread->unserialize(cp); 426} 427 428void 429change_thread_state(ThreadID tid, int activate, int priority) 430{ 431} 432 433Addr 434BaseSimpleCPU::dbg_vtophys(Addr addr) 435{ 436 return vtophys(threadContexts[curThread], addr); 437} 438 439void 440BaseSimpleCPU::wakeup(ThreadID tid) 441{ 442 getCpuAddrMonitor(tid)->gotWakeup = true; 443 444 if (threadInfo[tid]->thread->status() == ThreadContext::Suspended) { 445 DPRINTF(Quiesce,"[tid:%d] Suspended Processor awoke\n", tid); 446 threadInfo[tid]->thread->activate(); 447 } 448} 449 450void 451BaseSimpleCPU::checkForInterrupts() 452{ 453 SimpleExecContext&t_info = *threadInfo[curThread]; 454 SimpleThread* thread = t_info.thread; 455 ThreadContext* tc = thread->getTC(); 456 457 if (checkInterrupts(tc)) { 458 Fault interrupt = interrupts[curThread]->getInterrupt(tc); 459 460 if (interrupt != NoFault) { 461 t_info.fetchOffset = 0; 462 interrupts[curThread]->updateIntrInfo(tc); 463 interrupt->invoke(tc); 464 thread->decoder.reset(); 465 } 466 } 467} 468 469 470void 471BaseSimpleCPU::setupFetchRequest(const RequestPtr &req) 472{ 473 SimpleExecContext &t_info = *threadInfo[curThread]; 474 SimpleThread* thread = t_info.thread; 475 476 Addr instAddr = thread->instAddr(); 477 Addr fetchPC = (instAddr & PCMask) + t_info.fetchOffset; 478 479 // set up memory request for instruction fetch 480 DPRINTF(Fetch, "Fetch: Inst PC:%08p, Fetch PC:%08p\n", instAddr, fetchPC); 481 482 req->setVirt(0, fetchPC, sizeof(MachInst), Request::INST_FETCH, 483 instMasterId(), instAddr); 484} 485 486 487void 488BaseSimpleCPU::preExecute() 489{ 490 SimpleExecContext &t_info = *threadInfo[curThread]; 491 SimpleThread* thread = t_info.thread; 492 493 // maintain $r0 semantics 494 thread->setIntReg(ZeroReg, 0); 495#if THE_ISA == ALPHA_ISA 496 thread->setFloatRegBits(ZeroReg, 0); 497#endif // ALPHA_ISA 498 499 // check for instruction-count-based events 500 comInstEventQueue[curThread]->serviceEvents(t_info.numInst); 501 system->instEventQueue.serviceEvents(system->totalNumInsts); 502 503 // decode the instruction 504 inst = gtoh(inst); 505 506 TheISA::PCState pcState = thread->pcState(); 507 508 if (isRomMicroPC(pcState.microPC())) { 509 t_info.stayAtPC = false; 510 curStaticInst = microcodeRom.fetchMicroop(pcState.microPC(), 511 curMacroStaticInst); 512 } else if (!curMacroStaticInst) { 513 //We're not in the middle of a macro instruction 514 StaticInstPtr instPtr = NULL; 515 516 TheISA::Decoder *decoder = &(thread->decoder); 517 518 //Predecode, ie bundle up an ExtMachInst 519 //If more fetch data is needed, pass it in. 520 Addr fetchPC = (pcState.instAddr() & PCMask) + t_info.fetchOffset; 521 //if (decoder->needMoreBytes()) 522 decoder->moreBytes(pcState, fetchPC, inst); 523 //else 524 // decoder->process(); 525 526 //Decode an instruction if one is ready. Otherwise, we'll have to 527 //fetch beyond the MachInst at the current pc. 528 instPtr = decoder->decode(pcState); 529 if (instPtr) { 530 t_info.stayAtPC = false; 531 thread->pcState(pcState); 532 } else { 533 t_info.stayAtPC = true; 534 t_info.fetchOffset += sizeof(MachInst); 535 } 536 537 //If we decoded an instruction and it's microcoded, start pulling 538 //out micro ops 539 if (instPtr && instPtr->isMacroop()) { 540 curMacroStaticInst = instPtr; 541 curStaticInst = 542 curMacroStaticInst->fetchMicroop(pcState.microPC()); 543 } else { 544 curStaticInst = instPtr; 545 } 546 } else { 547 //Read the next micro op from the macro op 548 curStaticInst = curMacroStaticInst->fetchMicroop(pcState.microPC()); 549 } 550 551 //If we decoded an instruction this "tick", record information about it. 552 if (curStaticInst) { 553#if TRACING_ON 554 traceData = tracer->getInstRecord(curTick(), thread->getTC(), 555 curStaticInst, thread->pcState(), curMacroStaticInst); 556 557 DPRINTF(Decode,"Decode: Decoded %s instruction: %#x\n", 558 curStaticInst->getName(), curStaticInst->machInst); 559#endif // TRACING_ON 560 } 561 562 if (branchPred && curStaticInst && 563 curStaticInst->isControl()) { 564 // Use a fake sequence number since we only have one 565 // instruction in flight at the same time. 566 const InstSeqNum cur_sn(0); 567 t_info.predPC = thread->pcState(); 568 const bool predict_taken( 569 branchPred->predict(curStaticInst, cur_sn, t_info.predPC, 570 curThread)); 571 572 if (predict_taken) 573 ++t_info.numPredictedBranches; 574 } 575} 576 577void 578BaseSimpleCPU::postExecute() 579{ 580 SimpleExecContext &t_info = *threadInfo[curThread]; 581 SimpleThread* thread = t_info.thread; 582 583 assert(curStaticInst); 584 585 TheISA::PCState pc = threadContexts[curThread]->pcState(); 586 Addr instAddr = pc.instAddr(); 587 if (FullSystem && thread->profile) { 588 bool usermode = TheISA::inUserMode(threadContexts[curThread]); 589 thread->profilePC = usermode ? 1 : instAddr; 590 ProfileNode *node = thread->profile->consume(threadContexts[curThread], 591 curStaticInst); 592 if (node) 593 thread->profileNode = node; 594 } 595 596 if (curStaticInst->isMemRef()) { 597 t_info.numMemRefs++; 598 } 599 600 if (curStaticInst->isLoad()) { 601 ++t_info.numLoad; 602 comLoadEventQueue[curThread]->serviceEvents(t_info.numLoad); 603 } 604 605 if (CPA::available()) { 606 CPA::cpa()->swAutoBegin(threadContexts[curThread], pc.nextInstAddr()); 607 } 608 609 if (curStaticInst->isControl()) { 610 ++t_info.numBranches; 611 } 612 613 /* Power model statistics */ 614 //integer alu accesses 615 if (curStaticInst->isInteger()){ 616 t_info.numIntAluAccesses++; 617 t_info.numIntInsts++; 618 } 619 620 //float alu accesses 621 if (curStaticInst->isFloating()){ 622 t_info.numFpAluAccesses++; 623 t_info.numFpInsts++; 624 } 625 626 //vector alu accesses 627 if (curStaticInst->isVector()){ 628 t_info.numVecAluAccesses++; 629 t_info.numVecInsts++; 630 } 631 632 //number of function calls/returns to get window accesses 633 if (curStaticInst->isCall() || curStaticInst->isReturn()){ 634 t_info.numCallsReturns++; 635 } 636 637 //the number of branch predictions that will be made 638 if (curStaticInst->isCondCtrl()){ 639 t_info.numCondCtrlInsts++; 640 } 641 642 //result bus acceses 643 if (curStaticInst->isLoad()){ 644 t_info.numLoadInsts++; 645 } 646 647 if (curStaticInst->isStore()){ 648 t_info.numStoreInsts++; 649 } 650 /* End power model statistics */ 651 652 t_info.statExecutedInstType[curStaticInst->opClass()]++; 653 654 if (FullSystem) 655 traceFunctions(instAddr); 656 657 if (traceData) { 658 traceData->dump(); 659 delete traceData; 660 traceData = NULL; 661 } 662 663 // Call CPU instruction commit probes 664 probeInstCommit(curStaticInst); 665} 666 667void 668BaseSimpleCPU::advancePC(const Fault &fault) 669{ 670 SimpleExecContext &t_info = *threadInfo[curThread]; 671 SimpleThread* thread = t_info.thread; 672 673 const bool branching(thread->pcState().branching()); 674 675 //Since we're moving to a new pc, zero out the offset 676 t_info.fetchOffset = 0; 677 if (fault != NoFault) { 678 curMacroStaticInst = StaticInst::nullStaticInstPtr; 679 fault->invoke(threadContexts[curThread], curStaticInst); 680 thread->decoder.reset(); 681 } else { 682 if (curStaticInst) { 683 if (curStaticInst->isLastMicroop()) 684 curMacroStaticInst = StaticInst::nullStaticInstPtr; 685 TheISA::PCState pcState = thread->pcState(); 686 TheISA::advancePC(pcState, curStaticInst); 687 thread->pcState(pcState); 688 } 689 } 690 691 if (branchPred && curStaticInst && curStaticInst->isControl()) { 692 // Use a fake sequence number since we only have one 693 // instruction in flight at the same time. 694 const InstSeqNum cur_sn(0); 695 696 if (t_info.predPC == thread->pcState()) { 697 // Correctly predicted branch 698 branchPred->update(cur_sn, curThread); 699 } else { 700 // Mis-predicted branch 701 branchPred->squash(cur_sn, thread->pcState(), branching, curThread); 702 ++t_info.numBranchMispred; 703 } 704 } 705} 706 707void 708BaseSimpleCPU::startup() 709{ 710 BaseCPU::startup(); 711 for (auto& t_info : threadInfo) 712 t_info->thread->startup(); 713} 714