fetch_impl.hh revision 7947:6d07db809a81
1/* 2 * Copyright (c) 2010 ARM Limited 3 * All rights reserved. 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Copyright (c) 2004-2006 The Regents of The University of Michigan 15 * All rights reserved. 16 * 17 * Redistribution and use in source and binary forms, with or without 18 * modification, are permitted provided that the following conditions are 19 * met: redistributions of source code must retain the above copyright 20 * notice, this list of conditions and the following disclaimer; 21 * redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in the 23 * documentation and/or other materials provided with the distribution; 24 * neither the name of the copyright holders nor the names of its 25 * contributors may be used to endorse or promote products derived from 26 * this software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 * 40 * Authors: Kevin Lim 41 * Korey Sewell 42 */ 43 44#include <algorithm> 45#include <cstring> 46 47#include "arch/isa_traits.hh" 48#include "arch/utility.hh" 49#include "base/types.hh" 50#include "config/the_isa.hh" 51#include "config/use_checker.hh" 52#include "cpu/checker/cpu.hh" 53#include "cpu/exetrace.hh" 54#include "cpu/o3/fetch.hh" 55#include "mem/packet.hh" 56#include "mem/request.hh" 57#include "params/DerivO3CPU.hh" 58#include "sim/byteswap.hh" 59#include "sim/core.hh" 60 61#if FULL_SYSTEM 62#include "arch/tlb.hh" 63#include "arch/vtophys.hh" 64#include "sim/system.hh" 65#endif // FULL_SYSTEM 66 67using namespace std; 68 69template<class Impl> 70void 71DefaultFetch<Impl>::IcachePort::setPeer(Port *port) 72{ 73 Port::setPeer(port); 74 75 fetch->setIcache(); 76} 77 78template<class Impl> 79Tick 80DefaultFetch<Impl>::IcachePort::recvAtomic(PacketPtr pkt) 81{ 82 panic("DefaultFetch doesn't expect recvAtomic callback!"); 83 return curTick(); 84} 85 86template<class Impl> 87void 88DefaultFetch<Impl>::IcachePort::recvFunctional(PacketPtr pkt) 89{ 90 DPRINTF(Fetch, "DefaultFetch doesn't update its state from a " 91 "functional call."); 92} 93 94template<class Impl> 95void 96DefaultFetch<Impl>::IcachePort::recvStatusChange(Status status) 97{ 98 if (status == RangeChange) { 99 if (!snoopRangeSent) { 100 snoopRangeSent = true; 101 sendStatusChange(Port::RangeChange); 102 } 103 return; 104 } 105 106 panic("DefaultFetch doesn't expect recvStatusChange callback!"); 107} 108 109template<class Impl> 110bool 111DefaultFetch<Impl>::IcachePort::recvTiming(PacketPtr pkt) 112{ 113 DPRINTF(Fetch, "Received timing\n"); 114 if (pkt->isResponse()) { 115 fetch->processCacheCompletion(pkt); 116 } 117 //else Snooped a coherence request, just return 118 return true; 119} 120 121template<class Impl> 122void 123DefaultFetch<Impl>::IcachePort::recvRetry() 124{ 125 fetch->recvRetry(); 126} 127 128template<class Impl> 129DefaultFetch<Impl>::DefaultFetch(O3CPU *_cpu, DerivO3CPUParams *params) 130 : cpu(_cpu), 131 branchPred(params), 132 predecoder(NULL), 133 decodeToFetchDelay(params->decodeToFetchDelay), 134 renameToFetchDelay(params->renameToFetchDelay), 135 iewToFetchDelay(params->iewToFetchDelay), 136 commitToFetchDelay(params->commitToFetchDelay), 137 fetchWidth(params->fetchWidth), 138 cacheBlocked(false), 139 retryPkt(NULL), 140 retryTid(InvalidThreadID), 141 numThreads(params->numThreads), 142 numFetchingThreads(params->smtNumFetchingThreads), 143 interruptPending(false), 144 drainPending(false), 145 switchedOut(false) 146{ 147 if (numThreads > Impl::MaxThreads) 148 fatal("numThreads (%d) is larger than compiled limit (%d),\n" 149 "\tincrease MaxThreads in src/cpu/o3/impl.hh\n", 150 numThreads, static_cast<int>(Impl::MaxThreads)); 151 152 // Set fetch stage's status to inactive. 153 _status = Inactive; 154 155 std::string policy = params->smtFetchPolicy; 156 157 // Convert string to lowercase 158 std::transform(policy.begin(), policy.end(), policy.begin(), 159 (int(*)(int)) tolower); 160 161 // Figure out fetch policy 162 if (policy == "singlethread") { 163 fetchPolicy = SingleThread; 164 if (numThreads > 1) 165 panic("Invalid Fetch Policy for a SMT workload."); 166 } else if (policy == "roundrobin") { 167 fetchPolicy = RoundRobin; 168 DPRINTF(Fetch, "Fetch policy set to Round Robin\n"); 169 } else if (policy == "branch") { 170 fetchPolicy = Branch; 171 DPRINTF(Fetch, "Fetch policy set to Branch Count\n"); 172 } else if (policy == "iqcount") { 173 fetchPolicy = IQ; 174 DPRINTF(Fetch, "Fetch policy set to IQ count\n"); 175 } else if (policy == "lsqcount") { 176 fetchPolicy = LSQ; 177 DPRINTF(Fetch, "Fetch policy set to LSQ count\n"); 178 } else { 179 fatal("Invalid Fetch Policy. Options Are: {SingleThread," 180 " RoundRobin,LSQcount,IQcount}\n"); 181 } 182 183 // Get the size of an instruction. 184 instSize = sizeof(TheISA::MachInst); 185 186 // Name is finally available, so create the port. 187 icachePort = new IcachePort(this); 188 189 icachePort->snoopRangeSent = false; 190 191#if USE_CHECKER 192 if (cpu->checker) { 193 cpu->checker->setIcachePort(icachePort); 194 } 195#endif 196} 197 198template <class Impl> 199std::string 200DefaultFetch<Impl>::name() const 201{ 202 return cpu->name() + ".fetch"; 203} 204 205template <class Impl> 206void 207DefaultFetch<Impl>::regStats() 208{ 209 icacheStallCycles 210 .name(name() + ".icacheStallCycles") 211 .desc("Number of cycles fetch is stalled on an Icache miss") 212 .prereq(icacheStallCycles); 213 214 fetchedInsts 215 .name(name() + ".Insts") 216 .desc("Number of instructions fetch has processed") 217 .prereq(fetchedInsts); 218 219 fetchedBranches 220 .name(name() + ".Branches") 221 .desc("Number of branches that fetch encountered") 222 .prereq(fetchedBranches); 223 224 predictedBranches 225 .name(name() + ".predictedBranches") 226 .desc("Number of branches that fetch has predicted taken") 227 .prereq(predictedBranches); 228 229 fetchCycles 230 .name(name() + ".Cycles") 231 .desc("Number of cycles fetch has run and was not squashing or" 232 " blocked") 233 .prereq(fetchCycles); 234 235 fetchSquashCycles 236 .name(name() + ".SquashCycles") 237 .desc("Number of cycles fetch has spent squashing") 238 .prereq(fetchSquashCycles); 239 240 fetchTlbCycles 241 .name(name() + ".TlbCycles") 242 .desc("Number of cycles fetch has spent waiting for tlb") 243 .prereq(fetchTlbCycles); 244 245 fetchIdleCycles 246 .name(name() + ".IdleCycles") 247 .desc("Number of cycles fetch was idle") 248 .prereq(fetchIdleCycles); 249 250 fetchBlockedCycles 251 .name(name() + ".BlockedCycles") 252 .desc("Number of cycles fetch has spent blocked") 253 .prereq(fetchBlockedCycles); 254 255 fetchedCacheLines 256 .name(name() + ".CacheLines") 257 .desc("Number of cache lines fetched") 258 .prereq(fetchedCacheLines); 259 260 fetchMiscStallCycles 261 .name(name() + ".MiscStallCycles") 262 .desc("Number of cycles fetch has spent waiting on interrupts, or " 263 "bad addresses, or out of MSHRs") 264 .prereq(fetchMiscStallCycles); 265 266 fetchIcacheSquashes 267 .name(name() + ".IcacheSquashes") 268 .desc("Number of outstanding Icache misses that were squashed") 269 .prereq(fetchIcacheSquashes); 270 271 fetchNisnDist 272 .init(/* base value */ 0, 273 /* last value */ fetchWidth, 274 /* bucket size */ 1) 275 .name(name() + ".rateDist") 276 .desc("Number of instructions fetched each cycle (Total)") 277 .flags(Stats::pdf); 278 279 idleRate 280 .name(name() + ".idleRate") 281 .desc("Percent of cycles fetch was idle") 282 .prereq(idleRate); 283 idleRate = fetchIdleCycles * 100 / cpu->numCycles; 284 285 branchRate 286 .name(name() + ".branchRate") 287 .desc("Number of branch fetches per cycle") 288 .flags(Stats::total); 289 branchRate = fetchedBranches / cpu->numCycles; 290 291 fetchRate 292 .name(name() + ".rate") 293 .desc("Number of inst fetches per cycle") 294 .flags(Stats::total); 295 fetchRate = fetchedInsts / cpu->numCycles; 296 297 branchPred.regStats(); 298} 299 300template<class Impl> 301void 302DefaultFetch<Impl>::setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer) 303{ 304 timeBuffer = time_buffer; 305 306 // Create wires to get information from proper places in time buffer. 307 fromDecode = timeBuffer->getWire(-decodeToFetchDelay); 308 fromRename = timeBuffer->getWire(-renameToFetchDelay); 309 fromIEW = timeBuffer->getWire(-iewToFetchDelay); 310 fromCommit = timeBuffer->getWire(-commitToFetchDelay); 311} 312 313template<class Impl> 314void 315DefaultFetch<Impl>::setActiveThreads(std::list<ThreadID> *at_ptr) 316{ 317 activeThreads = at_ptr; 318} 319 320template<class Impl> 321void 322DefaultFetch<Impl>::setFetchQueue(TimeBuffer<FetchStruct> *fq_ptr) 323{ 324 fetchQueue = fq_ptr; 325 326 // Create wire to write information to proper place in fetch queue. 327 toDecode = fetchQueue->getWire(0); 328} 329 330template<class Impl> 331void 332DefaultFetch<Impl>::initStage() 333{ 334 // Setup PC and nextPC with initial state. 335 for (ThreadID tid = 0; tid < numThreads; tid++) { 336 pc[tid] = cpu->pcState(tid); 337 fetchOffset[tid] = 0; 338 macroop[tid] = NULL; 339 } 340 341 for (ThreadID tid = 0; tid < numThreads; tid++) { 342 343 fetchStatus[tid] = Running; 344 345 priorityList.push_back(tid); 346 347 memReq[tid] = NULL; 348 349 stalls[tid].decode = false; 350 stalls[tid].rename = false; 351 stalls[tid].iew = false; 352 stalls[tid].commit = false; 353 } 354 355 // Schedule fetch to get the correct PC from the CPU 356 // scheduleFetchStartupEvent(1); 357 358 // Fetch needs to start fetching instructions at the very beginning, 359 // so it must start up in active state. 360 switchToActive(); 361} 362 363template<class Impl> 364void 365DefaultFetch<Impl>::setIcache() 366{ 367 // Size of cache block. 368 cacheBlkSize = icachePort->peerBlockSize(); 369 370 // Create mask to get rid of offset bits. 371 cacheBlkMask = (cacheBlkSize - 1); 372 373 for (ThreadID tid = 0; tid < numThreads; tid++) { 374 // Create space to store a cache line. 375 cacheData[tid] = new uint8_t[cacheBlkSize]; 376 cacheDataPC[tid] = 0; 377 cacheDataValid[tid] = false; 378 } 379} 380 381template<class Impl> 382void 383DefaultFetch<Impl>::processCacheCompletion(PacketPtr pkt) 384{ 385 ThreadID tid = pkt->req->threadId(); 386 387 DPRINTF(Fetch, "[tid:%u] Waking up from cache miss.\n", tid); 388 389 assert(!pkt->wasNacked()); 390 391 // Only change the status if it's still waiting on the icache access 392 // to return. 393 if (fetchStatus[tid] != IcacheWaitResponse || 394 pkt->req != memReq[tid] || 395 isSwitchedOut()) { 396 ++fetchIcacheSquashes; 397 delete pkt->req; 398 delete pkt; 399 return; 400 } 401 402 memcpy(cacheData[tid], pkt->getPtr<uint8_t>(), cacheBlkSize); 403 cacheDataValid[tid] = true; 404 405 if (!drainPending) { 406 // Wake up the CPU (if it went to sleep and was waiting on 407 // this completion event). 408 cpu->wakeCPU(); 409 410 DPRINTF(Activity, "[tid:%u] Activating fetch due to cache completion\n", 411 tid); 412 413 switchToActive(); 414 } 415 416 // Only switch to IcacheAccessComplete if we're not stalled as well. 417 if (checkStall(tid)) { 418 fetchStatus[tid] = Blocked; 419 } else { 420 fetchStatus[tid] = IcacheAccessComplete; 421 } 422 423 // Reset the mem req to NULL. 424 delete pkt->req; 425 delete pkt; 426 memReq[tid] = NULL; 427} 428 429template <class Impl> 430bool 431DefaultFetch<Impl>::drain() 432{ 433 // Fetch is ready to drain at any time. 434 cpu->signalDrained(); 435 drainPending = true; 436 return true; 437} 438 439template <class Impl> 440void 441DefaultFetch<Impl>::resume() 442{ 443 drainPending = false; 444} 445 446template <class Impl> 447void 448DefaultFetch<Impl>::switchOut() 449{ 450 switchedOut = true; 451 // Branch predictor needs to have its state cleared. 452 branchPred.switchOut(); 453} 454 455template <class Impl> 456void 457DefaultFetch<Impl>::takeOverFrom() 458{ 459 // Reset all state 460 for (ThreadID i = 0; i < Impl::MaxThreads; ++i) { 461 stalls[i].decode = 0; 462 stalls[i].rename = 0; 463 stalls[i].iew = 0; 464 stalls[i].commit = 0; 465 pc[i] = cpu->pcState(i); 466 fetchStatus[i] = Running; 467 } 468 numInst = 0; 469 wroteToTimeBuffer = false; 470 _status = Inactive; 471 switchedOut = false; 472 interruptPending = false; 473 branchPred.takeOverFrom(); 474} 475 476template <class Impl> 477void 478DefaultFetch<Impl>::wakeFromQuiesce() 479{ 480 DPRINTF(Fetch, "Waking up from quiesce\n"); 481 // Hopefully this is safe 482 // @todo: Allow other threads to wake from quiesce. 483 fetchStatus[0] = Running; 484} 485 486template <class Impl> 487inline void 488DefaultFetch<Impl>::switchToActive() 489{ 490 if (_status == Inactive) { 491 DPRINTF(Activity, "Activating stage.\n"); 492 493 cpu->activateStage(O3CPU::FetchIdx); 494 495 _status = Active; 496 } 497} 498 499template <class Impl> 500inline void 501DefaultFetch<Impl>::switchToInactive() 502{ 503 if (_status == Active) { 504 DPRINTF(Activity, "Deactivating stage.\n"); 505 506 cpu->deactivateStage(O3CPU::FetchIdx); 507 508 _status = Inactive; 509 } 510} 511 512template <class Impl> 513bool 514DefaultFetch<Impl>::lookupAndUpdateNextPC( 515 DynInstPtr &inst, TheISA::PCState &nextPC) 516{ 517 // Do branch prediction check here. 518 // A bit of a misnomer...next_PC is actually the current PC until 519 // this function updates it. 520 bool predict_taken; 521 522 if (!inst->isControl()) { 523 TheISA::advancePC(nextPC, inst->staticInst); 524 inst->setPredTarg(nextPC); 525 inst->setPredTaken(false); 526 return false; 527 } 528 529 ThreadID tid = inst->threadNumber; 530 predict_taken = branchPred.predict(inst, nextPC, tid); 531 532 if (predict_taken) { 533 DPRINTF(Fetch, "[tid:%i]: [sn:%i]: Branch predicted to be taken to %s.\n", 534 tid, inst->seqNum, nextPC); 535 } else { 536 DPRINTF(Fetch, "[tid:%i]: [sn:%i]:Branch predicted to be not taken.\n", 537 tid, inst->seqNum); 538 } 539 540 DPRINTF(Fetch, "[tid:%i]: [sn:%i] Branch predicted to go to %s.\n", 541 tid, inst->seqNum, nextPC); 542 inst->setPredTarg(nextPC); 543 inst->setPredTaken(predict_taken); 544 545 ++fetchedBranches; 546 547 if (predict_taken) { 548 ++predictedBranches; 549 } 550 551 return predict_taken; 552} 553 554template <class Impl> 555bool 556DefaultFetch<Impl>::fetchCacheLine(Addr vaddr, ThreadID tid, Addr pc) 557{ 558 Fault fault = NoFault; 559 560 // @todo: not sure if these should block translation. 561 //AlphaDep 562 if (cacheBlocked) { 563 DPRINTF(Fetch, "[tid:%i] Can't fetch cache line, cache blocked\n", 564 tid); 565 return false; 566 } else if (isSwitchedOut()) { 567 DPRINTF(Fetch, "[tid:%i] Can't fetch cache line, switched out\n", 568 tid); 569 return false; 570 } else if (checkInterrupt(pc)) { 571 // Hold off fetch from getting new instructions when: 572 // Cache is blocked, or 573 // while an interrupt is pending and we're not in PAL mode, or 574 // fetch is switched out. 575 DPRINTF(Fetch, "[tid:%i] Can't fetch cache line, interrupt pending\n", 576 tid); 577 return false; 578 } 579 580 // Align the fetch address so it's at the start of a cache block. 581 Addr block_PC = icacheBlockAlignPC(vaddr); 582 583 // Setup the memReq to do a read of the first instruction's address. 584 // Set the appropriate read size and flags as well. 585 // Build request here. 586 RequestPtr mem_req = 587 new Request(tid, block_PC, cacheBlkSize, Request::INST_FETCH, 588 pc, cpu->thread[tid]->contextId(), tid); 589 590 memReq[tid] = mem_req; 591 592 // Initiate translation of the icache block 593 fetchStatus[tid] = ItlbWait; 594 FetchTranslation *trans = new FetchTranslation(this); 595 cpu->itb->translateTiming(mem_req, cpu->thread[tid]->getTC(), 596 trans, BaseTLB::Execute); 597 return true; 598} 599 600template <class Impl> 601void 602DefaultFetch<Impl>::finishTranslation(Fault fault, RequestPtr mem_req) 603{ 604 ThreadID tid = mem_req->threadId(); 605 Addr block_PC = mem_req->getVaddr(); 606 607 // Wake up CPU if it was idle 608 cpu->wakeCPU(); 609 610 // If translation was successful, attempt to read the icache block. 611 if (fault == NoFault) { 612 // Build packet here. 613 PacketPtr data_pkt = new Packet(mem_req, 614 MemCmd::ReadReq, Packet::Broadcast); 615 data_pkt->dataDynamicArray(new uint8_t[cacheBlkSize]); 616 617 cacheDataPC[tid] = block_PC; 618 cacheDataValid[tid] = false; 619 DPRINTF(Fetch, "Fetch: Doing instruction read.\n"); 620 621 fetchedCacheLines++; 622 623 // Access the cache. 624 if (!icachePort->sendTiming(data_pkt)) { 625 assert(retryPkt == NULL); 626 assert(retryTid == InvalidThreadID); 627 DPRINTF(Fetch, "[tid:%i] Out of MSHRs!\n", tid); 628 629 fetchStatus[tid] = IcacheWaitRetry; 630 retryPkt = data_pkt; 631 retryTid = tid; 632 cacheBlocked = true; 633 } else { 634 DPRINTF(Fetch, "[tid:%i]: Doing Icache access.\n", tid); 635 DPRINTF(Activity, "[tid:%i]: Activity: Waiting on I-cache " 636 "response.\n", tid); 637 638 lastIcacheStall[tid] = curTick(); 639 fetchStatus[tid] = IcacheWaitResponse; 640 } 641 } else { 642 // Translation faulted, icache request won't be sent. 643 delete mem_req; 644 memReq[tid] = NULL; 645 646 // Send the fault to commit. This thread will not do anything 647 // until commit handles the fault. The only other way it can 648 // wake up is if a squash comes along and changes the PC. 649 TheISA::PCState fetchPC = pc[tid]; 650 651 // We will use a nop in ordier to carry the fault. 652 DynInstPtr instruction = buildInst(tid, 653 StaticInstPtr(TheISA::NoopMachInst, fetchPC.instAddr()), 654 NULL, fetchPC, fetchPC, false); 655 656 instruction->setPredTarg(fetchPC); 657 instruction->fault = fault; 658 wroteToTimeBuffer = true; 659 660 DPRINTF(Activity, "Activity this cycle.\n"); 661 cpu->activityThisCycle(); 662 663 fetchStatus[tid] = TrapPending; 664 665 DPRINTF(Fetch, "[tid:%i]: Blocked, need to handle the trap.\n", tid); 666 DPRINTF(Fetch, "[tid:%i]: fault (%s) detected @ PC %s.\n", 667 tid, fault->name(), pc[tid]); 668 } 669 _status = updateFetchStatus(); 670} 671 672template <class Impl> 673inline void 674DefaultFetch<Impl>::doSquash(const TheISA::PCState &newPC, ThreadID tid) 675{ 676 DPRINTF(Fetch, "[tid:%i]: Squashing, setting PC to: %s.\n", 677 tid, newPC); 678 679 pc[tid] = newPC; 680 fetchOffset[tid] = 0; 681 macroop[tid] = NULL; 682 predecoder.reset(); 683 684 // Clear the icache miss if it's outstanding. 685 if (fetchStatus[tid] == IcacheWaitResponse) { 686 DPRINTF(Fetch, "[tid:%i]: Squashing outstanding Icache miss.\n", 687 tid); 688 memReq[tid] = NULL; 689 } 690 691 // Get rid of the retrying packet if it was from this thread. 692 if (retryTid == tid) { 693 assert(cacheBlocked); 694 if (retryPkt) { 695 delete retryPkt->req; 696 delete retryPkt; 697 } 698 retryPkt = NULL; 699 retryTid = InvalidThreadID; 700 } 701 702 fetchStatus[tid] = Squashing; 703 704 ++fetchSquashCycles; 705} 706 707template<class Impl> 708void 709DefaultFetch<Impl>::squashFromDecode(const TheISA::PCState &newPC, 710 const InstSeqNum &seq_num, ThreadID tid) 711{ 712 DPRINTF(Fetch, "[tid:%i]: Squashing from decode.\n", tid); 713 714 doSquash(newPC, tid); 715 716 // Tell the CPU to remove any instructions that are in flight between 717 // fetch and decode. 718 cpu->removeInstsUntil(seq_num, tid); 719} 720 721template<class Impl> 722bool 723DefaultFetch<Impl>::checkStall(ThreadID tid) const 724{ 725 bool ret_val = false; 726 727 if (cpu->contextSwitch) { 728 DPRINTF(Fetch,"[tid:%i]: Stalling for a context switch.\n",tid); 729 ret_val = true; 730 } else if (stalls[tid].decode) { 731 DPRINTF(Fetch,"[tid:%i]: Stall from Decode stage detected.\n",tid); 732 ret_val = true; 733 } else if (stalls[tid].rename) { 734 DPRINTF(Fetch,"[tid:%i]: Stall from Rename stage detected.\n",tid); 735 ret_val = true; 736 } else if (stalls[tid].iew) { 737 DPRINTF(Fetch,"[tid:%i]: Stall from IEW stage detected.\n",tid); 738 ret_val = true; 739 } else if (stalls[tid].commit) { 740 DPRINTF(Fetch,"[tid:%i]: Stall from Commit stage detected.\n",tid); 741 ret_val = true; 742 } 743 744 return ret_val; 745} 746 747template<class Impl> 748typename DefaultFetch<Impl>::FetchStatus 749DefaultFetch<Impl>::updateFetchStatus() 750{ 751 //Check Running 752 list<ThreadID>::iterator threads = activeThreads->begin(); 753 list<ThreadID>::iterator end = activeThreads->end(); 754 755 while (threads != end) { 756 ThreadID tid = *threads++; 757 758 if (fetchStatus[tid] == Running || 759 fetchStatus[tid] == Squashing || 760 fetchStatus[tid] == IcacheAccessComplete) { 761 762 if (_status == Inactive) { 763 DPRINTF(Activity, "[tid:%i]: Activating stage.\n",tid); 764 765 if (fetchStatus[tid] == IcacheAccessComplete) { 766 DPRINTF(Activity, "[tid:%i]: Activating fetch due to cache" 767 "completion\n",tid); 768 } 769 770 cpu->activateStage(O3CPU::FetchIdx); 771 } 772 773 return Active; 774 } 775 } 776 777 // Stage is switching from active to inactive, notify CPU of it. 778 if (_status == Active) { 779 DPRINTF(Activity, "Deactivating stage.\n"); 780 781 cpu->deactivateStage(O3CPU::FetchIdx); 782 } 783 784 return Inactive; 785} 786 787template <class Impl> 788void 789DefaultFetch<Impl>::squash(const TheISA::PCState &newPC, 790 const InstSeqNum &seq_num, ThreadID tid) 791{ 792 DPRINTF(Fetch, "[tid:%u]: Squash from commit.\n", tid); 793 794 doSquash(newPC, tid); 795 796 // Tell the CPU to remove any instructions that are not in the ROB. 797 cpu->removeInstsNotInROB(tid); 798} 799 800template <class Impl> 801void 802DefaultFetch<Impl>::tick() 803{ 804 list<ThreadID>::iterator threads = activeThreads->begin(); 805 list<ThreadID>::iterator end = activeThreads->end(); 806 bool status_change = false; 807 808 wroteToTimeBuffer = false; 809 810 while (threads != end) { 811 ThreadID tid = *threads++; 812 813 // Check the signals for each thread to determine the proper status 814 // for each thread. 815 bool updated_status = checkSignalsAndUpdate(tid); 816 status_change = status_change || updated_status; 817 } 818 819 DPRINTF(Fetch, "Running stage.\n"); 820 821 // Reset the number of the instruction we're fetching. 822 numInst = 0; 823 824#if FULL_SYSTEM 825 if (fromCommit->commitInfo[0].interruptPending) { 826 interruptPending = true; 827 } 828 829 if (fromCommit->commitInfo[0].clearInterrupt) { 830 interruptPending = false; 831 } 832#endif 833 834 for (threadFetched = 0; threadFetched < numFetchingThreads; 835 threadFetched++) { 836 // Fetch each of the actively fetching threads. 837 fetch(status_change); 838 } 839 840 // Record number of instructions fetched this cycle for distribution. 841 fetchNisnDist.sample(numInst); 842 843 if (status_change) { 844 // Change the fetch stage status if there was a status change. 845 _status = updateFetchStatus(); 846 } 847 848 // If there was activity this cycle, inform the CPU of it. 849 if (wroteToTimeBuffer || cpu->contextSwitch) { 850 DPRINTF(Activity, "Activity this cycle.\n"); 851 852 cpu->activityThisCycle(); 853 } 854} 855 856template <class Impl> 857bool 858DefaultFetch<Impl>::checkSignalsAndUpdate(ThreadID tid) 859{ 860 // Update the per thread stall statuses. 861 if (fromDecode->decodeBlock[tid]) { 862 stalls[tid].decode = true; 863 } 864 865 if (fromDecode->decodeUnblock[tid]) { 866 assert(stalls[tid].decode); 867 assert(!fromDecode->decodeBlock[tid]); 868 stalls[tid].decode = false; 869 } 870 871 if (fromRename->renameBlock[tid]) { 872 stalls[tid].rename = true; 873 } 874 875 if (fromRename->renameUnblock[tid]) { 876 assert(stalls[tid].rename); 877 assert(!fromRename->renameBlock[tid]); 878 stalls[tid].rename = false; 879 } 880 881 if (fromIEW->iewBlock[tid]) { 882 stalls[tid].iew = true; 883 } 884 885 if (fromIEW->iewUnblock[tid]) { 886 assert(stalls[tid].iew); 887 assert(!fromIEW->iewBlock[tid]); 888 stalls[tid].iew = false; 889 } 890 891 if (fromCommit->commitBlock[tid]) { 892 stalls[tid].commit = true; 893 } 894 895 if (fromCommit->commitUnblock[tid]) { 896 assert(stalls[tid].commit); 897 assert(!fromCommit->commitBlock[tid]); 898 stalls[tid].commit = false; 899 } 900 901 // Check squash signals from commit. 902 if (fromCommit->commitInfo[tid].squash) { 903 904 DPRINTF(Fetch, "[tid:%u]: Squashing instructions due to squash " 905 "from commit.\n",tid); 906 // In any case, squash. 907 squash(fromCommit->commitInfo[tid].pc, 908 fromCommit->commitInfo[tid].doneSeqNum, 909 tid); 910 911 // If it was a branch mispredict on a control instruction, update the 912 // branch predictor with that instruction, otherwise just kill the 913 // invalid state we generated in after sequence number 914 assert(!fromCommit->commitInfo[tid].branchMispredict || 915 fromCommit->commitInfo[tid].mispredictInst); 916 917 if (fromCommit->commitInfo[tid].branchMispredict && 918 fromCommit->commitInfo[tid].mispredictInst->isControl()) { 919 branchPred.squash(fromCommit->commitInfo[tid].doneSeqNum, 920 fromCommit->commitInfo[tid].pc, 921 fromCommit->commitInfo[tid].branchTaken, 922 tid); 923 } else { 924 branchPred.squash(fromCommit->commitInfo[tid].doneSeqNum, 925 tid); 926 } 927 928 return true; 929 } else if (fromCommit->commitInfo[tid].doneSeqNum) { 930 // Update the branch predictor if it wasn't a squashed instruction 931 // that was broadcasted. 932 branchPred.update(fromCommit->commitInfo[tid].doneSeqNum, tid); 933 } 934 935 // Check ROB squash signals from commit. 936 if (fromCommit->commitInfo[tid].robSquashing) { 937 DPRINTF(Fetch, "[tid:%u]: ROB is still squashing.\n", tid); 938 939 // Continue to squash. 940 fetchStatus[tid] = Squashing; 941 942 return true; 943 } 944 945 // Check squash signals from decode. 946 if (fromDecode->decodeInfo[tid].squash) { 947 DPRINTF(Fetch, "[tid:%u]: Squashing instructions due to squash " 948 "from decode.\n",tid); 949 950 // Update the branch predictor. 951 if (fromDecode->decodeInfo[tid].branchMispredict) { 952 branchPred.squash(fromDecode->decodeInfo[tid].doneSeqNum, 953 fromDecode->decodeInfo[tid].nextPC, 954 fromDecode->decodeInfo[tid].branchTaken, 955 tid); 956 } else { 957 branchPred.squash(fromDecode->decodeInfo[tid].doneSeqNum, 958 tid); 959 } 960 961 if (fetchStatus[tid] != Squashing) { 962 963 TheISA::PCState nextPC = fromDecode->decodeInfo[tid].nextPC; 964 DPRINTF(Fetch, "Squashing from decode with PC = %s\n", nextPC); 965 // Squash unless we're already squashing 966 squashFromDecode(fromDecode->decodeInfo[tid].nextPC, 967 fromDecode->decodeInfo[tid].doneSeqNum, 968 tid); 969 970 return true; 971 } 972 } 973 974 if (checkStall(tid) && 975 fetchStatus[tid] != IcacheWaitResponse && 976 fetchStatus[tid] != IcacheWaitRetry) { 977 DPRINTF(Fetch, "[tid:%i]: Setting to blocked\n",tid); 978 979 fetchStatus[tid] = Blocked; 980 981 return true; 982 } 983 984 if (fetchStatus[tid] == Blocked || 985 fetchStatus[tid] == Squashing) { 986 // Switch status to running if fetch isn't being told to block or 987 // squash this cycle. 988 DPRINTF(Fetch, "[tid:%i]: Done squashing, switching to running.\n", 989 tid); 990 991 fetchStatus[tid] = Running; 992 993 return true; 994 } 995 996 // If we've reached this point, we have not gotten any signals that 997 // cause fetch to change its status. Fetch remains the same as before. 998 return false; 999} 1000 1001template<class Impl> 1002typename Impl::DynInstPtr 1003DefaultFetch<Impl>::buildInst(ThreadID tid, StaticInstPtr staticInst, 1004 StaticInstPtr curMacroop, TheISA::PCState thisPC, 1005 TheISA::PCState nextPC, bool trace) 1006{ 1007 // Get a sequence number. 1008 InstSeqNum seq = cpu->getAndIncrementInstSeq(); 1009 1010 // Create a new DynInst from the instruction fetched. 1011 DynInstPtr instruction = 1012 new DynInst(staticInst, thisPC, nextPC, seq, cpu); 1013 instruction->setTid(tid); 1014 1015 instruction->setASID(tid); 1016 1017 instruction->setThreadState(cpu->thread[tid]); 1018 1019 DPRINTF(Fetch, "[tid:%i]: Instruction PC %#x (%d) created " 1020 "[sn:%lli].\n", tid, thisPC.instAddr(), 1021 thisPC.microPC(), seq); 1022 1023 DPRINTF(Fetch, "[tid:%i]: Instruction is: %s\n", tid, 1024 instruction->staticInst-> 1025 disassemble(thisPC.instAddr())); 1026 1027#if TRACING_ON 1028 if (trace) { 1029 instruction->traceData = 1030 cpu->getTracer()->getInstRecord(curTick(), cpu->tcBase(tid), 1031 instruction->staticInst, thisPC, curMacroop); 1032 } 1033#else 1034 instruction->traceData = NULL; 1035#endif 1036 1037 // Add instruction to the CPU's list of instructions. 1038 instruction->setInstListIt(cpu->addInst(instruction)); 1039 1040 // Write the instruction to the first slot in the queue 1041 // that heads to decode. 1042 assert(numInst < fetchWidth); 1043 toDecode->insts[toDecode->size++] = instruction; 1044 1045 return instruction; 1046} 1047 1048template<class Impl> 1049void 1050DefaultFetch<Impl>::fetch(bool &status_change) 1051{ 1052 ////////////////////////////////////////// 1053 // Start actual fetch 1054 ////////////////////////////////////////// 1055 ThreadID tid = getFetchingThread(fetchPolicy); 1056 1057 if (tid == InvalidThreadID || drainPending) { 1058 DPRINTF(Fetch,"There are no more threads available to fetch from.\n"); 1059 1060 // Breaks looping condition in tick() 1061 threadFetched = numFetchingThreads; 1062 return; 1063 } 1064 1065 DPRINTF(Fetch, "Attempting to fetch from [tid:%i]\n", tid); 1066 1067 // The current PC. 1068 TheISA::PCState thisPC = pc[tid]; 1069 1070 Addr pcOffset = fetchOffset[tid]; 1071 Addr fetchAddr = (thisPC.instAddr() + pcOffset) & BaseCPU::PCMask; 1072 1073 // If returning from the delay of a cache miss, then update the status 1074 // to running, otherwise do the cache access. Possibly move this up 1075 // to tick() function. 1076 if (fetchStatus[tid] == IcacheAccessComplete) { 1077 DPRINTF(Fetch, "[tid:%i]: Icache miss is complete.\n", tid); 1078 1079 fetchStatus[tid] = Running; 1080 status_change = true; 1081 } else if (fetchStatus[tid] == Running) { 1082 // Align the fetch PC so its at the start of a cache block. 1083 Addr block_PC = icacheBlockAlignPC(fetchAddr); 1084 1085 // Unless buffer already got the block, fetch it from icache. 1086 if (!cacheDataValid[tid] || block_PC != cacheDataPC[tid]) { 1087 DPRINTF(Fetch, "[tid:%i]: Attempting to translate and read " 1088 "instruction, starting at PC %s.\n", tid, thisPC); 1089 1090 fetchCacheLine(fetchAddr, tid, thisPC.instAddr()); 1091 1092 if (fetchStatus[tid] == IcacheWaitResponse) 1093 ++icacheStallCycles; 1094 else if (fetchStatus[tid] == ItlbWait) 1095 ++fetchTlbCycles; 1096 else 1097 ++fetchMiscStallCycles; 1098 return; 1099 } else if (checkInterrupt(thisPC.instAddr()) || isSwitchedOut()) { 1100 ++fetchMiscStallCycles; 1101 return; 1102 } 1103 } else { 1104 if (fetchStatus[tid] == Idle) { 1105 ++fetchIdleCycles; 1106 DPRINTF(Fetch, "[tid:%i]: Fetch is idle!\n", tid); 1107 } else if (fetchStatus[tid] == Blocked) { 1108 ++fetchBlockedCycles; 1109 DPRINTF(Fetch, "[tid:%i]: Fetch is blocked!\n", tid); 1110 } else if (fetchStatus[tid] == Squashing) { 1111 ++fetchSquashCycles; 1112 DPRINTF(Fetch, "[tid:%i]: Fetch is squashing!\n", tid); 1113 } else if (fetchStatus[tid] == IcacheWaitResponse) { 1114 ++icacheStallCycles; 1115 DPRINTF(Fetch, "[tid:%i]: Fetch is waiting cache response!\n", 1116 tid); 1117 } else if (fetchStatus[tid] == ItlbWait) { 1118 DPRINTF(Fetch, "[tid:%i]: Fetch is waiting ITLB walk to " 1119 "finish! \n", tid); 1120 ++fetchTlbCycles; 1121 } 1122 1123 // Status is Idle, Squashing, Blocked, ItlbWait or IcacheWaitResponse 1124 // so fetch should do nothing. 1125 return; 1126 } 1127 1128 ++fetchCycles; 1129 1130 TheISA::PCState nextPC = thisPC; 1131 1132 StaticInstPtr staticInst = NULL; 1133 StaticInstPtr curMacroop = macroop[tid]; 1134 1135 // If the read of the first instruction was successful, then grab the 1136 // instructions from the rest of the cache line and put them into the 1137 // queue heading to decode. 1138 1139 DPRINTF(Fetch, "[tid:%i]: Adding instructions to queue to " 1140 "decode.\n", tid); 1141 1142 // Need to keep track of whether or not a predicted branch 1143 // ended this fetch block. 1144 bool predictedBranch = false; 1145 1146 TheISA::MachInst *cacheInsts = 1147 reinterpret_cast<TheISA::MachInst *>(cacheData[tid]); 1148 1149 const unsigned numInsts = cacheBlkSize / instSize; 1150 unsigned blkOffset = (fetchAddr - cacheDataPC[tid]) / instSize; 1151 1152 // Loop through instruction memory from the cache. 1153 while (blkOffset < numInsts && 1154 numInst < fetchWidth && 1155 !predictedBranch) { 1156 1157 // If we need to process more memory, do it now. 1158 if (!curMacroop && !predecoder.extMachInstReady()) { 1159 if (ISA_HAS_DELAY_SLOT && pcOffset == 0) { 1160 // Walk past any annulled delay slot instructions. 1161 Addr pcAddr = thisPC.instAddr() & BaseCPU::PCMask; 1162 while (fetchAddr != pcAddr && blkOffset < numInsts) { 1163 blkOffset++; 1164 fetchAddr += instSize; 1165 } 1166 if (blkOffset >= numInsts) 1167 break; 1168 } 1169 MachInst inst = TheISA::gtoh(cacheInsts[blkOffset]); 1170 1171 predecoder.setTC(cpu->thread[tid]->getTC()); 1172 predecoder.moreBytes(thisPC, fetchAddr, inst); 1173 1174 if (predecoder.needMoreBytes()) { 1175 blkOffset++; 1176 fetchAddr += instSize; 1177 pcOffset += instSize; 1178 } 1179 } 1180 1181 // Extract as many instructions and/or microops as we can from 1182 // the memory we've processed so far. 1183 do { 1184 if (!curMacroop) { 1185 if (predecoder.extMachInstReady()) { 1186 ExtMachInst extMachInst; 1187 1188 extMachInst = predecoder.getExtMachInst(thisPC); 1189 staticInst = StaticInstPtr(extMachInst, 1190 thisPC.instAddr()); 1191 1192 // Increment stat of fetched instructions. 1193 ++fetchedInsts; 1194 1195 if (staticInst->isMacroop()) { 1196 curMacroop = staticInst; 1197 } else { 1198 pcOffset = 0; 1199 } 1200 } else { 1201 // We need more bytes for this instruction. 1202 break; 1203 } 1204 } 1205 if (curMacroop) { 1206 staticInst = curMacroop->fetchMicroop(thisPC.microPC()); 1207 if (staticInst->isLastMicroop()) { 1208 curMacroop = NULL; 1209 pcOffset = 0; 1210 } 1211 } 1212 1213 DynInstPtr instruction = 1214 buildInst(tid, staticInst, curMacroop, 1215 thisPC, nextPC, true); 1216 1217 numInst++; 1218 1219 nextPC = thisPC; 1220 1221 // If we're branching after this instruction, quite fetching 1222 // from the same block then. 1223 predictedBranch |= thisPC.branching(); 1224 predictedBranch |= 1225 lookupAndUpdateNextPC(instruction, nextPC); 1226 if (predictedBranch) { 1227 DPRINTF(Fetch, "Branch detected with PC = %s\n", thisPC); 1228 } 1229 1230 // Move to the next instruction, unless we have a branch. 1231 thisPC = nextPC; 1232 1233 if (instruction->isQuiesce()) { 1234 DPRINTF(Fetch, 1235 "Quiesce instruction encountered, halting fetch!"); 1236 fetchStatus[tid] = QuiescePending; 1237 status_change = true; 1238 break; 1239 } 1240 } while ((curMacroop || predecoder.extMachInstReady()) && 1241 numInst < fetchWidth); 1242 } 1243 1244 if (predictedBranch) { 1245 DPRINTF(Fetch, "[tid:%i]: Done fetching, predicted branch " 1246 "instruction encountered.\n", tid); 1247 } else if (numInst >= fetchWidth) { 1248 DPRINTF(Fetch, "[tid:%i]: Done fetching, reached fetch bandwidth " 1249 "for this cycle.\n", tid); 1250 } else if (blkOffset >= cacheBlkSize) { 1251 DPRINTF(Fetch, "[tid:%i]: Done fetching, reached the end of cache " 1252 "block.\n", tid); 1253 } 1254 1255 macroop[tid] = curMacroop; 1256 fetchOffset[tid] = pcOffset; 1257 1258 if (numInst > 0) { 1259 wroteToTimeBuffer = true; 1260 } 1261 1262 pc[tid] = thisPC; 1263} 1264 1265template<class Impl> 1266void 1267DefaultFetch<Impl>::recvRetry() 1268{ 1269 if (retryPkt != NULL) { 1270 assert(cacheBlocked); 1271 assert(retryTid != InvalidThreadID); 1272 assert(fetchStatus[retryTid] == IcacheWaitRetry); 1273 1274 if (icachePort->sendTiming(retryPkt)) { 1275 fetchStatus[retryTid] = IcacheWaitResponse; 1276 retryPkt = NULL; 1277 retryTid = InvalidThreadID; 1278 cacheBlocked = false; 1279 } 1280 } else { 1281 assert(retryTid == InvalidThreadID); 1282 // Access has been squashed since it was sent out. Just clear 1283 // the cache being blocked. 1284 cacheBlocked = false; 1285 } 1286} 1287 1288/////////////////////////////////////// 1289// // 1290// SMT FETCH POLICY MAINTAINED HERE // 1291// // 1292/////////////////////////////////////// 1293template<class Impl> 1294ThreadID 1295DefaultFetch<Impl>::getFetchingThread(FetchPriority &fetch_priority) 1296{ 1297 if (numThreads > 1) { 1298 switch (fetch_priority) { 1299 1300 case SingleThread: 1301 return 0; 1302 1303 case RoundRobin: 1304 return roundRobin(); 1305 1306 case IQ: 1307 return iqCount(); 1308 1309 case LSQ: 1310 return lsqCount(); 1311 1312 case Branch: 1313 return branchCount(); 1314 1315 default: 1316 return InvalidThreadID; 1317 } 1318 } else { 1319 list<ThreadID>::iterator thread = activeThreads->begin(); 1320 if (thread == activeThreads->end()) { 1321 return InvalidThreadID; 1322 } 1323 1324 ThreadID tid = *thread; 1325 1326 if (fetchStatus[tid] == Running || 1327 fetchStatus[tid] == IcacheAccessComplete || 1328 fetchStatus[tid] == Idle) { 1329 return tid; 1330 } else { 1331 return InvalidThreadID; 1332 } 1333 } 1334} 1335 1336 1337template<class Impl> 1338ThreadID 1339DefaultFetch<Impl>::roundRobin() 1340{ 1341 list<ThreadID>::iterator pri_iter = priorityList.begin(); 1342 list<ThreadID>::iterator end = priorityList.end(); 1343 1344 ThreadID high_pri; 1345 1346 while (pri_iter != end) { 1347 high_pri = *pri_iter; 1348 1349 assert(high_pri <= numThreads); 1350 1351 if (fetchStatus[high_pri] == Running || 1352 fetchStatus[high_pri] == IcacheAccessComplete || 1353 fetchStatus[high_pri] == Idle) { 1354 1355 priorityList.erase(pri_iter); 1356 priorityList.push_back(high_pri); 1357 1358 return high_pri; 1359 } 1360 1361 pri_iter++; 1362 } 1363 1364 return InvalidThreadID; 1365} 1366 1367template<class Impl> 1368ThreadID 1369DefaultFetch<Impl>::iqCount() 1370{ 1371 std::priority_queue<ThreadID> PQ; 1372 1373 list<ThreadID>::iterator threads = activeThreads->begin(); 1374 list<ThreadID>::iterator end = activeThreads->end(); 1375 1376 while (threads != end) { 1377 ThreadID tid = *threads++; 1378 1379 PQ.push(fromIEW->iewInfo[tid].iqCount); 1380 } 1381 1382 while (!PQ.empty()) { 1383 ThreadID high_pri = PQ.top(); 1384 1385 if (fetchStatus[high_pri] == Running || 1386 fetchStatus[high_pri] == IcacheAccessComplete || 1387 fetchStatus[high_pri] == Idle) 1388 return high_pri; 1389 else 1390 PQ.pop(); 1391 1392 } 1393 1394 return InvalidThreadID; 1395} 1396 1397template<class Impl> 1398ThreadID 1399DefaultFetch<Impl>::lsqCount() 1400{ 1401 std::priority_queue<ThreadID> PQ; 1402 1403 list<ThreadID>::iterator threads = activeThreads->begin(); 1404 list<ThreadID>::iterator end = activeThreads->end(); 1405 1406 while (threads != end) { 1407 ThreadID tid = *threads++; 1408 1409 PQ.push(fromIEW->iewInfo[tid].ldstqCount); 1410 } 1411 1412 while (!PQ.empty()) { 1413 ThreadID high_pri = PQ.top(); 1414 1415 if (fetchStatus[high_pri] == Running || 1416 fetchStatus[high_pri] == IcacheAccessComplete || 1417 fetchStatus[high_pri] == Idle) 1418 return high_pri; 1419 else 1420 PQ.pop(); 1421 } 1422 1423 return InvalidThreadID; 1424} 1425 1426template<class Impl> 1427ThreadID 1428DefaultFetch<Impl>::branchCount() 1429{ 1430#if 0 1431 list<ThreadID>::iterator thread = activeThreads->begin(); 1432 assert(thread != activeThreads->end()); 1433 ThreadID tid = *thread; 1434#endif 1435 1436 panic("Branch Count Fetch policy unimplemented\n"); 1437 return InvalidThreadID; 1438} 1439