gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
commit.cc
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google, Inc.
3 * Copyright (c) 2010-2014, 2017, 2020, 2025 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2004-2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#include "cpu/o3/commit.hh"
43
44#include <algorithm>
45#include <set>
46#include <string>
47
48#include "base/compiler.hh"
49#include "base/loader/symtab.hh"
50#include "base/logging.hh"
51#include "cpu/base.hh"
52#include "cpu/checker/cpu.hh"
53#include "cpu/exetrace.hh"
54#include "cpu/o3/cpu.hh"
55#include "cpu/o3/dyn_inst.hh"
56#include "cpu/o3/limits.hh"
58#include "cpu/timebuf.hh"
59#include "debug/Activity.hh"
60#include "debug/Commit.hh"
61#include "debug/CommitRate.hh"
62#include "debug/Drain.hh"
63#include "debug/ExecFaulting.hh"
64#include "debug/HtmCpu.hh"
65#include "params/BaseO3CPU.hh"
66#include "sim/faults.hh"
67#include "sim/full_system.hh"
68
69namespace gem5
70{
71
72namespace o3
73{
74
75void
77{
78 // This will get reset by commit if it was switched out at the
79 // time of this event processing.
80 trapSquash[tid] = true;
81}
82
83Commit::Commit(CPU *_cpu, const BaseO3CPUParams &params)
84 : commitPolicy(params.smtCommitPolicy),
85 cpu(_cpu),
89 fetchToCommitDelay(params.commitToFetchDelay),
92 numThreads(params.numThreads),
93 drainPending(false),
94 drainImminent(false),
98 stats(_cpu, this)
99{
100 if (commitWidth > MaxWidth)
101 fatal("commitWidth (%d) is larger than compiled limit (%d),\n"
102 "\tincrease MaxWidth in src/cpu/o3/limits.hh\n",
103 commitWidth, static_cast<int>(MaxWidth));
104
105 _status = Active;
107
108 if (commitPolicy == CommitPolicy::RoundRobin) {
109 //Set-Up Priority List
110 for (ThreadID tid = 0; tid < numThreads; tid++) {
111 priority_list.push_back(tid);
112 }
113 }
114
115 for (ThreadID tid = 0; tid < MaxThreads; tid++) {
116 commitStatus[tid] = Idle;
117 changedROBNumEntries[tid] = false;
118 trapSquash[tid] = false;
119 tcSquash[tid] = false;
120 squashAfterInst[tid] = nullptr;
121 pc[tid].reset(params.isa[0]->newPCState());
122 youngestSeqNum[tid] = 0;
123 lastCommitedSeqNum[tid] = 0;
124 trapInFlight[tid] = false;
125 committedStores[tid] = false;
126 checkEmptyROB[tid] = false;
127 renameMap[tid] = nullptr;
128 htmStarts[tid] = 0;
129 htmStops[tid] = 0;
130 }
132}
133
134std::string Commit::name() const { return cpu->name() + ".commit"; }
135
136void
138{
140 cpu->getProbeManager(), "Commit");
142 cpu->getProbeManager(), "CommitStall");
144 cpu->getProbeManager(), "Squash");
145}
146
148 : statistics::Group(cpu, "commit"),
150 "The number of squashed insts skipped by commit"),
152 "The number of times commit has been forced to stall to "
153 "communicate backwards"),
155 "The number of times a branch was mispredicted"),
157 "Number of insts commited each cycle"),
158 ADD_STAT(amos, statistics::units::Count::get(),
159 "Number of atomic instructions committed"),
160 ADD_STAT(membars, statistics::units::Count::get(),
161 "Number of memory barriers committed"),
163 "Class of committed instruction"),
165 "number cycles where commit BW limit reached")
166{
167 using namespace statistics;
168
172
174 .init(0,commit->commitWidth,1)
175 .flags(statistics::pdf);
176
177 amos
178 .init(cpu->numThreads)
179 .flags(total);
180
181 membars
182 .init(cpu->numThreads)
183 .flags(total);
184
186 .init(commit->numThreads,enums::Num_OpClass)
187 .flags(total | pdf | dist);
188
189 committedInstType.ysubnames(enums::OpClassStrings);
190}
191
192void
194{
195 thread = threads;
196}
197
198void
200{
201 timeBuffer = tb_ptr;
202
203 // Setup wire to send information back to IEW.
204 toIEW = timeBuffer->getWire(0);
205
206 // Setup wire to read data from IEW (for the ROB).
208}
209
210void
212{
213 fetchQueue = fq_ptr;
214
215 // Setup wire to get instructions from rename (for the ROB).
217}
218
219void
221{
222 renameQueue = rq_ptr;
223
224 // Setup wire to get instructions from rename (for the ROB).
226}
227
228void
230{
231 iewQueue = iq_ptr;
232
233 // Setup wire to get instructions from IEW.
234 fromIEW = iewQueue->getWire(-iewToCommitDelay);
235}
236
237void
239{
240 iewStage = iew_stage;
241}
242
243void
248
249void
251{
252 for (ThreadID tid = 0; tid < numThreads; tid++)
253 renameMap[tid] = &rm_ptr[tid];
254}
255
256void Commit::setROB(ROB *rob_ptr) { rob = rob_ptr; }
257
258void
260{
261 rob->setActiveThreads(activeThreads);
262 rob->resetEntries();
263
264 // Broadcast the number of free entries.
265 for (ThreadID tid = 0; tid < numThreads; tid++) {
266 toIEW->commitInfo[tid].usedROB = true;
267 toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid);
268 toIEW->commitInfo[tid].emptyROB = true;
269 }
270
271 // Commit must broadcast the number of free entries it has at the
272 // start of the simulation, so it starts as active.
273 cpu->activateStage(CPU::CommitIdx);
274
275 cpu->activityThisCycle();
276}
277
278void
280{
281 commitStatus[tid] = Idle;
282 changedROBNumEntries[tid] = false;
283 checkEmptyROB[tid] = false;
284 trapInFlight[tid] = false;
285 committedStores[tid] = false;
286 trapSquash[tid] = false;
287 tcSquash[tid] = false;
288 pc[tid].reset(cpu->tcBase(tid)->getIsaPtr()->newPCState());
289 lastCommitedSeqNum[tid] = 0;
290 squashAfterInst[tid] = NULL;
291
292 // Clear out any of this thread's instructions being sent to prior stages.
293 for (int i = -cpu->timeBuffer.getPast(); i <= cpu->timeBuffer.getFuture();
294 ++i) {
295 cpu->timeBuffer[i].commitInfo[tid] = {};
296 }
297}
298
299void Commit::drain() { drainPending = true; }
300
301void
303{
304 drainPending = false;
305 drainImminent = false;
306}
307
308void
310{
311 assert(isDrained());
312 rob->drainSanityCheck();
313
314 // hardware transactional memory
315 // cannot drain partially through a transaction
316 for (ThreadID tid = 0; tid < numThreads; tid++) {
317 if (executingHtmTransaction(tid)) {
318 panic("cannot drain partially through a HTM transaction");
319 }
320 }
321}
322
323bool
325{
326 /* Make sure no one is executing microcode. There are two reasons
327 * for this:
328 * - Hardware virtualized CPUs can't switch into the middle of a
329 * microcode sequence.
330 * - The current fetch implementation will most likely get very
331 * confused if it tries to start fetching an instruction that
332 * is executing in the middle of a ucode sequence that changes
333 * address mappings. This can happen on for example x86.
334 */
335 for (ThreadID tid = 0; tid < numThreads; tid++) {
336 if (pc[tid]->microPC() != 0)
337 return false;
338 }
339
340 /* Make sure that all instructions have finished committing before
341 * declaring the system as drained. We want the pipeline to be
342 * completely empty when we declare the CPU to be drained. This
343 * makes debugging easier since CPU handover and restoring from a
344 * checkpoint with a different CPU should have the same timing.
345 */
346 return rob->isEmpty() &&
348}
349
350void
352{
353 _status = Active;
355 for (ThreadID tid = 0; tid < numThreads; tid++) {
356 commitStatus[tid] = Idle;
357 changedROBNumEntries[tid] = false;
358 trapSquash[tid] = false;
359 tcSquash[tid] = false;
360 squashAfterInst[tid] = NULL;
361 }
362 rob->takeOverFrom();
363}
364
365void
367{
368 auto thread_it = std::find(
369 priority_list.begin(), priority_list.end(), tid);
370
371 if (thread_it != priority_list.end()) {
372 priority_list.erase(thread_it);
373 }
374}
375
376bool
378{
379 if (tid == InvalidThreadID)
380 return false;
381 else
382 return (htmStarts[tid] > htmStops[tid]);
383}
384
385void
387{
388 if (tid != InvalidThreadID)
389 {
390 htmStarts[tid] = 0;
391 htmStops[tid] = 0;
392 }
393}
394
395
396void
398{
399 // reset ROB changed variable
400 for (ThreadID tid : *activeThreads) {
401 changedROBNumEntries[tid] = false;
402
403 // Also check if any of the threads has a trap pending
404 if (commitStatus[tid] == TrapPending ||
407 }
408 }
409
410 if (_nextStatus == Inactive && _status == Active) {
411 DPRINTF(Activity, "Deactivating stage.\n");
412 cpu->deactivateStage(CPU::CommitIdx);
413 } else if (_nextStatus == Active && _status == Inactive) {
414 DPRINTF(Activity, "Activating stage.\n");
415 cpu->activateStage(CPU::CommitIdx);
416 }
417
419}
420
421bool
423{
424 for (ThreadID tid : *activeThreads) {
425 if (changedROBNumEntries[tid]) {
426 return true;
427 }
428 }
429
430 return false;
431}
432
433size_t
435{
436 return rob->numFreeEntries(tid);
437}
438
439void
441{
442 DPRINTF(Commit, "Generating trap event for [tid:%i]\n", tid);
443
445 [this, tid]{ processTrapEvent(tid); },
446 "Trap", true, Event::CPU_Tick_Pri);
447
448 Cycles latency = std::dynamic_pointer_cast<SyscallRetryFault>(inst_fault) ?
449 cpu->syscallRetryLatency : trapLatency;
450
451 // hardware transactional memory
452 if (inst_fault != nullptr &&
453 std::dynamic_pointer_cast<GenericHtmFailureFault>(inst_fault)) {
454 // TODO
455 // latency = default abort/restore latency
456 // could also do some kind of exponential back off if desired
457 }
458
459 cpu->schedule(trap, cpu->clockEdge(latency));
460 trapInFlight[tid] = true;
461 thread[tid]->trapPending = true;
462 toIEW->commitInfo[tid].trapPending = true;
463}
464
465void
467{
468 assert(!trapInFlight[tid]);
469 DPRINTF(Commit, "Generating TC squash event for [tid:%i]\n", tid);
470
471 tcSquash[tid] = true;
472}
473
474void
476{
477 // If we want to include the squashing instruction in the squash,
478 // then use one older sequence number.
479 // Hopefully this doesn't mess things up. Basically I want to squash
480 // all instructions of this thread.
481 InstSeqNum squashed_inst = rob->isEmpty(tid) ?
482 lastCommitedSeqNum[tid] : rob->readHeadInst(tid)->seqNum - 1;
483
484 // All younger instructions will be squashed. Set the sequence
485 // number as the youngest instruction in the ROB (0 in this case.
486 // Hopefully nothing breaks.)
488
489 rob->squash(squashed_inst, tid);
490 changedROBNumEntries[tid] = true;
491
492 // Send back the sequence number of the squashed instruction.
493 toIEW->commitInfo[tid].doneSeqNum = squashed_inst;
494
495 // Send back the squash signal to tell stages that they should
496 // squash.
497 toIEW->commitInfo[tid].squash = true;
498
499 // Send back the rob squashing signal so other stages know that
500 // the ROB is in the process of squashing.
501 toIEW->commitInfo[tid].robSquashing = true;
502
503 toIEW->commitInfo[tid].mispredictInst = NULL;
504 toIEW->commitInfo[tid].squashInst = NULL;
505
506 set(toIEW->commitInfo[tid].pc, pc[tid]);
507}
508
509void
511{
512 squashAll(tid);
513
514 DPRINTF(Commit, "Squashing from trap, restarting at PC %s\n", *pc[tid]);
515
516 thread[tid]->trapPending = false;
517 thread[tid]->noSquashFromTC = false;
518 trapInFlight[tid] = false;
519 toIEW->commitInfo[tid].trapPending = false;
520
521 trapSquash[tid] = false;
522
524 cpu->activityThisCycle();
525}
526
527void
529{
530 squashAll(tid);
531
532 DPRINTF(Commit, "Squashing from TC, restarting at PC %s\n", *pc[tid]);
533
534 thread[tid]->noSquashFromTC = false;
535 assert(!thread[tid]->trapPending);
536
538 cpu->activityThisCycle();
539
540 tcSquash[tid] = false;
541}
542
543void
545{
546 DPRINTF(Commit, "Squashing after squash after request, "
547 "restarting at PC %s\n", *pc[tid]);
548
549 squashAll(tid);
550 // Make sure to inform the fetch stage of which instruction caused
551 // the squash. It'll try to re-fetch an instruction executing in
552 // microcode unless this is set.
553 toIEW->commitInfo[tid].squashInst = squashAfterInst[tid];
554 squashAfterInst[tid] = NULL;
555
557 cpu->activityThisCycle();
558}
559
560void
562{
563 DPRINTF(Commit, "Executing squash after for [tid:%i] inst [sn:%llu]\n",
564 tid, head_inst->seqNum);
565
566 assert(!squashAfterInst[tid] || squashAfterInst[tid] == head_inst);
568 squashAfterInst[tid] = head_inst;
569}
570
571void
573{
574 wroteToTimeBuffer = false;
576
577 if (activeThreads->empty())
578 return;
579
580 // Check if any of the threads are done squashing. Change the
581 // status if they are done.
582 for (ThreadID tid : *activeThreads) {
583 // Clear the bit saying if the thread has committed stores
584 // this cycle.
585 committedStores[tid] = false;
586
587 if (commitStatus[tid] == ROBSquashing) {
588
589 if (rob->isDoneSquashing(tid)) {
590 commitStatus[tid] = Running;
591 } else {
592 DPRINTF(Commit,"[tid:%i] Still Squashing, cannot commit any"
593 " insts this cycle.\n", tid);
594 rob->doSquash(tid);
595 toIEW->commitInfo[tid].robSquashing = true;
596 wroteToTimeBuffer = true;
597 }
598 }
599 }
600
601 commit();
602
604
605 for (ThreadID tid : *activeThreads) {
606 if (!rob->isEmpty(tid) && rob->readHeadInst(tid)->readyToCommit()) {
607 // The ROB has more instructions it can commit. Its next status
608 // will be active.
610
611 [[maybe_unused]] const DynInstPtr &inst = rob->readHeadInst(tid);
612
613 DPRINTF(Commit,"[tid:%i] Instruction [sn:%llu] PC %s is head of"
614 " ROB and ready to commit\n",
615 tid, inst->seqNum, inst->pcState());
616
617 } else if (!rob->isEmpty(tid)) {
618 const DynInstPtr &inst = rob->readHeadInst(tid);
619
620 ppCommitStall->notify(inst);
621
622 DPRINTF(Commit,"[tid:%i] Can't commit, Instruction [sn:%llu] PC "
623 "%s is head of ROB and not ready\n",
624 tid, inst->seqNum, inst->pcState());
625 }
626
627 DPRINTF(Commit, "[tid:%i] ROB has %d insts & %d free entries.\n",
628 tid, rob->countInsts(tid), rob->numFreeEntries(tid));
629 }
630
631
632 if (wroteToTimeBuffer) {
633 DPRINTF(Activity, "Activity This Cycle.\n");
634 cpu->activityThisCycle();
635 }
636
637 updateStatus();
638}
639
640void
642{
643 // Verify that we still have an interrupt to handle
644 if (!cpu->checkInterrupts(0)) {
645 DPRINTF(Commit, "Pending interrupt is cleared by requestor before "
646 "it got handled. Restart fetching from the orig path.\n");
647 toIEW->commitInfo[0].clearInterrupt = true;
650 return;
651 }
652
653 // Wait until all in flight instructions are finished before enterring
654 // the interrupt.
655 if (canHandleInterrupts && cpu->instList.empty()) {
656 // Squash or record that I need to squash this cycle if
657 // an interrupt needed to be handled.
658 DPRINTF(Commit, "Interrupt detected.\n");
659
660 // Clear the interrupt now that it's going to be handled
661 toIEW->commitInfo[0].clearInterrupt = true;
662
663 assert(!thread[0]->noSquashFromTC);
664 thread[0]->noSquashFromTC = true;
665
666 if (cpu->checker) {
667 cpu->checker->handlePendingInt();
668 }
669
670 // CPU will handle interrupt. Note that we ignore the local copy of
671 // interrupt. This is because the local copy may no longer be the
672 // interrupt that the interrupt controller thinks is being handled.
673 cpu->processInterrupts(cpu->getInterrupts());
674
675 thread[0]->noSquashFromTC = false;
676
678
680
681 // Generate trap squash event.
683
684 avoidQuiesceLiveLock = false;
685 } else {
686 DPRINTF(Commit, "Interrupt pending: instruction is %sin "
687 "flight, ROB is %sempty\n",
688 canHandleInterrupts ? "not " : "",
689 cpu->instList.empty() ? "" : "not " );
690 }
691}
692
693void
695{
696 // Don't propagate intterupts if we are currently handling a trap or
697 // in draining and the last observable instruction has been committed.
698 if (commitStatus[0] == TrapPending || interrupt || trapSquash[0] ||
700 return;
701
702 // Process interrupts if interrupts are enabled, not in PAL
703 // mode, and no other traps or external squashes are currently
704 // pending.
705 // @todo: Allow other threads to handle interrupts.
706
707 // Get any interrupt that happened
708 interrupt = cpu->getInterrupts();
709
710 // Tell fetch that there is an interrupt pending. This
711 // will make fetch wait until it sees a non PAL-mode PC,
712 // at which point it stops fetching instructions.
713 if (interrupt != NoFault)
714 toIEW->commitInfo[0].interruptPending = true;
715}
716
717void
719{
720 if (FullSystem) {
721 // Check if we have a interrupt and get read to handle it
722 if (cpu->checkInterrupts(0))
724 }
725
727 // Check for any possible squashes, handle them first
729
730 int num_squashing_threads = 0;
731 for (ThreadID tid : *activeThreads) {
732 // Not sure which one takes priority. I think if we have
733 // both, that's a bad sign.
734 if (trapSquash[tid]) {
735 assert(!tcSquash[tid]);
736 squashFromTrap(tid);
737
738 // If the thread is trying to exit (i.e., an exit syscall was
739 // executed), this trapSquash was originated by the exit
740 // syscall earlier. In this case, schedule an exit event in
741 // the next cycle to fully terminate this thread
742 if (cpu->isThreadExiting(tid))
743 cpu->scheduleThreadExitEvent(tid);
744 } else if (tcSquash[tid]) {
745 assert(commitStatus[tid] != TrapPending);
746 squashFromTC(tid);
747 } else if (commitStatus[tid] == SquashAfterPending) {
748 // A squash from the previous cycle of the commit stage (i.e.,
749 // commitInsts() called squashAfter) is pending. Squash the
750 // thread now.
752 }
753
754 // Squashed sequence number must be older than youngest valid
755 // instruction in the ROB. This prevents squashes from younger
756 // instructions overriding squashes from older instructions.
757 if (fromIEW->squash[tid] &&
758 commitStatus[tid] != TrapPending &&
759 fromIEW->squashedSeqNum[tid] <= youngestSeqNum[tid]) {
760
761 if (fromIEW->mispredictInst[tid]) {
763 "[tid:%i] Squashing due to branch mispred "
764 "PC:%#x [sn:%llu]\n",
765 tid,
766 fromIEW->mispredictInst[tid]->pcState().instAddr(),
767 fromIEW->squashedSeqNum[tid]);
768 } else {
770 "[tid:%i] Squashing due to order violation [sn:%llu]\n",
771 tid, fromIEW->squashedSeqNum[tid]);
772 }
773
774 DPRINTF(Commit, "[tid:%i] Redirecting to PC %#x\n",
775 tid, *fromIEW->pc[tid]);
776
778
779 // If we want to include the squashing instruction in the squash,
780 // then use one older sequence number.
781 InstSeqNum squashed_inst = fromIEW->squashedSeqNum[tid];
782
783 if (fromIEW->includeSquashInst[tid]) {
784 squashed_inst--;
785 }
786
787 // All younger instructions will be squashed. Set the sequence
788 // number as the youngest instruction in the ROB.
789 youngestSeqNum[tid] = squashed_inst;
790
791 rob->squash(squashed_inst, tid);
792 changedROBNumEntries[tid] = true;
793
794 toIEW->commitInfo[tid].doneSeqNum = squashed_inst;
795
796 toIEW->commitInfo[tid].squash = true;
797
798 // Send back the rob squashing signal so other stages know that
799 // the ROB is in the process of squashing.
800 toIEW->commitInfo[tid].robSquashing = true;
801
802 toIEW->commitInfo[tid].mispredictInst =
803 fromIEW->mispredictInst[tid];
804 toIEW->commitInfo[tid].branchTaken =
805 fromIEW->branchTaken[tid];
806 toIEW->commitInfo[tid].squashInst =
807 rob->findInst(tid, squashed_inst);
808 if (toIEW->commitInfo[tid].mispredictInst) {
809 if (toIEW->commitInfo[tid].mispredictInst->isUncondCtrl()) {
810 toIEW->commitInfo[tid].branchTaken = true;
811 }
812 ++stats.branchMispredicts;
813 }
814
815 set(toIEW->commitInfo[tid].pc, fromIEW->pc[tid]);
816 }
817
818 if (commitStatus[tid] == ROBSquashing) {
819 num_squashing_threads++;
820 }
821 }
822
823 // If commit is currently squashing, then it will have activity for the
824 // next cycle. Set its next status as active.
825 if (num_squashing_threads) {
827 }
828
829 if (num_squashing_threads != numThreads) {
830 // If we're not currently squashing, then get instructions.
831 getInsts();
832
833 // Try to commit any instructions.
834 commitInsts();
835 }
836
837 //Check for any activity
838 for (ThreadID tid : *activeThreads) {
839 if (changedROBNumEntries[tid]) {
840 toIEW->commitInfo[tid].usedROB = true;
841 toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid);
842
843 wroteToTimeBuffer = true;
844 changedROBNumEntries[tid] = false;
845 if (rob->isEmpty(tid))
846 checkEmptyROB[tid] = true;
847 }
848
849 // ROB is only considered "empty" for previous stages if: a)
850 // ROB is empty, b) there are no outstanding stores, c) IEW
851 // stage has received any information regarding stores that
852 // committed.
853 // c) is checked by making sure to not consider the ROB empty
854 // on the same cycle as when stores have been committed.
855 // @todo: Make this handle multi-cycle communication between
856 // commit and IEW.
857 if (checkEmptyROB[tid] && rob->isEmpty(tid) &&
858 !iewStage->hasStoresToWB(tid) && !committedStores[tid]) {
859 checkEmptyROB[tid] = false;
860 toIEW->commitInfo[tid].usedROB = true;
861 toIEW->commitInfo[tid].emptyROB = true;
862 toIEW->commitInfo[tid].freeROBEntries = rob->numFreeEntries(tid);
863 wroteToTimeBuffer = true;
864 }
865
866 }
867}
868
869void
871{
873 // Handle commit
874 // Note that commit will be handled prior to putting new
875 // instructions in the ROB so that the ROB only tries to commit
876 // instructions it has in this current cycle, and not instructions
877 // it is writing in during this cycle. Can't commit and squash
878 // things at the same time...
880
881 DPRINTF(Commit, "Trying to commit instructions in the ROB.\n");
882
883 unsigned num_committed = 0;
884
885 DynInstPtr head_inst;
886
887 // Commit as many instructions as possible until the commit bandwidth
888 // limit is reached, or it becomes impossible to commit any more.
889 while (num_committed < commitWidth) {
890 // hardware transactionally memory
891 // If executing within a transaction,
892 // need to handle interrupts specially
893
894 ThreadID commit_thread = getCommittingThread();
895
896 // Check for any interrupt that we've already squashed for
897 // and start processing it.
898 if (interrupt != NoFault) {
899 // If inside a transaction, postpone interrupts
900 if (executingHtmTransaction(commit_thread)) {
901 cpu->clearInterrupts(0);
902 toIEW->commitInfo[0].clearInterrupt = true;
905 } else {
907 }
908 }
909
910 // ThreadID commit_thread = getCommittingThread();
911
912 if (commit_thread == -1 || !rob->isHeadReady(commit_thread))
913 break;
914
915 head_inst = rob->readHeadInst(commit_thread);
916
917 ThreadID tid = head_inst->threadNumber;
918
919 assert(tid == commit_thread);
920
922 "Trying to commit head instruction, [tid:%i] [sn:%llu]\n",
923 tid, head_inst->seqNum);
924
925 // If the head instruction is squashed, it is ready to retire
926 // (be removed from the ROB) at any time.
927 if (head_inst->isSquashed()) {
928
929 DPRINTF(Commit, "Retiring squashed instruction from "
930 "ROB.\n");
931
932 rob->retireHead(commit_thread);
933
934 ++stats.commitSquashedInsts;
935 // Notify potential listeners that this instruction is squashed
936 ppSquash->notify(head_inst);
937
938 // Record that the number of ROB entries has changed.
939 changedROBNumEntries[tid] = true;
940 // Inst at head of ROB cannot execute because the CPU
941 // does not know how to (lack of FU). This is a misconfiguration,
942 // so panic.
943 } else if (head_inst->noCapableFU() &&
944 head_inst->getFault() == NoFault) {
945 panic("CPU cannot execute [sn:%llu] op_class: %s but"
946 " did not trigger a fault. Do you need to update"
947 " the configuration and add a functional unit for"
948 " that op class?\n",
949 head_inst->seqNum,
950 enums::OpClassStrings[head_inst->opClass()]);
951 } else {
952 set(pc[tid], head_inst->pcState());
953
954 // Try to commit the head instruction.
955 bool commit_success = commitHead(head_inst, num_committed);
956
957 if (commit_success) {
958 ++num_committed;
959 cpu->commitStats[tid]
960 ->committedInstType[head_inst->opClass()]++;
961 stats.committedInstType[tid][head_inst->opClass()]++;
962 ppCommit->notify(head_inst);
963
964 // hardware transactional memory
965
966 // update nesting depth
967 if (head_inst->isHtmStart())
968 htmStarts[tid]++;
969
970 // sanity check
971 if (head_inst->inHtmTransactionalState()) {
972 assert(executingHtmTransaction(tid));
973 } else {
974 assert(!executingHtmTransaction(tid));
975 }
976
977 // update nesting depth
978 if (head_inst->isHtmStop())
979 htmStops[tid]++;
980
981 changedROBNumEntries[tid] = true;
982
983 // Set the doneSeqNum to the youngest committed instruction.
984 toIEW->commitInfo[tid].doneSeqNum = head_inst->seqNum;
985
986 if (tid == 0)
987 canHandleInterrupts = !head_inst->isDelayedCommit();
988
989 // at this point store conditionals should either have
990 // been completed or predicated false
991 assert(!head_inst->isStoreConditional() ||
992 head_inst->isCompleted() ||
993 !head_inst->readPredicate());
994
995 // Updates misc. registers.
996 head_inst->updateMiscRegs();
997
998 // Check instruction execution if it successfully commits and
999 // is not carrying a fault.
1000 if (cpu->checker) {
1001 cpu->checker->verify(head_inst);
1002 }
1003
1004 cpu->traceFunctions(pc[tid]->instAddr());
1005
1006 head_inst->staticInst->advancePC(*pc[tid]);
1007
1008 // Keep track of the last sequence number commited
1009 lastCommitedSeqNum[tid] = head_inst->seqNum;
1010
1011 // If this is an instruction that doesn't play nicely with
1012 // others squash everything and restart fetch
1013 if (head_inst->isSquashAfter())
1014 squashAfter(tid, head_inst);
1015
1016 if (drainPending) {
1017 if (pc[tid]->microPC() == 0 && interrupt == NoFault &&
1018 !thread[tid]->trapPending) {
1019 // Last architectually committed instruction.
1020 // Squash the pipeline, stall fetch, and use
1021 // drainImminent to disable interrupts
1022 DPRINTF(Drain, "Draining: %i:%s\n", tid, *pc[tid]);
1023 squashAfter(tid, head_inst);
1024 cpu->commitDrained(tid);
1025 drainImminent = true;
1026 }
1027 }
1028
1029 bool onInstBoundary = !head_inst->isMicroop() ||
1030 head_inst->isLastMicroop() ||
1031 !head_inst->isDelayedCommit();
1032
1033 if (onInstBoundary) {
1034 int count = 0;
1035 Addr oldpc;
1036 // Make sure we're not currently updating state while
1037 // handling PC events.
1038 assert(!thread[tid]->noSquashFromTC &&
1039 !thread[tid]->trapPending);
1040 do {
1041 oldpc = pc[tid]->instAddr();
1042 thread[tid]->pcEventQueue.service(
1043 oldpc, thread[tid]->getTC());
1044 count++;
1045 } while (oldpc != pc[tid]->instAddr());
1046 if (count > 1) {
1048 "PC skip function event, stopping commit\n");
1049 break;
1050 }
1051 }
1052
1053 // Check if an instruction just enabled interrupts and we've
1054 // previously had an interrupt pending that was not handled
1055 // because interrupts were subsequently disabled before the
1056 // pipeline reached a place to handle the interrupt. In that
1057 // case squash now to make sure the interrupt is handled.
1058 //
1059 // If we don't do this, we might end up in a live lock
1060 // situation.
1062 onInstBoundary && cpu->checkInterrupts(0))
1063 squashAfter(tid, head_inst);
1064 } else {
1065 DPRINTF(Commit, "Unable to commit head instruction PC:%s "
1066 "[tid:%i] [sn:%llu].\n",
1067 head_inst->pcState(), tid ,head_inst->seqNum);
1068 break;
1069 }
1070 }
1071 }
1072
1073 DPRINTF(CommitRate, "%i\n", num_committed);
1074 stats.numCommittedDist.sample(num_committed);
1075
1076 if (num_committed == commitWidth) {
1077 stats.commitEligibleSamples++;
1078 }
1079}
1080
1081bool
1082Commit::commitHead(const DynInstPtr &head_inst, unsigned inst_num)
1083{
1084 assert(head_inst);
1085
1086 ThreadID tid = head_inst->threadNumber;
1087
1088 // If the instruction is not executed yet, then it will need extra
1089 // handling. Signal backwards that it should be executed.
1090 if (!head_inst->isExecuted()) {
1091 // Make sure we are only trying to commit un-executed instructions we
1092 // think are possible.
1093 assert(head_inst->isNonSpeculative() || head_inst->isStoreConditional()
1094 || head_inst->isReadBarrier() || head_inst->isWriteBarrier()
1095 || head_inst->isAtomic()
1096 || (head_inst->isLoad() && head_inst->strictlyOrdered()));
1097
1099 "Encountered a barrier or non-speculative "
1100 "instruction [tid:%i] [sn:%llu] "
1101 "at the head of the ROB, PC %s.\n",
1102 tid, head_inst->seqNum, head_inst->pcState());
1103
1104 if (inst_num > 0 || iewStage->hasStoresToWB(tid)) {
1106 "[tid:%i] [sn:%llu] "
1107 "Waiting for all stores to writeback.\n",
1108 tid, head_inst->seqNum);
1109 return false;
1110 }
1111
1112 toIEW->commitInfo[tid].nonSpecSeqNum = head_inst->seqNum;
1113
1114 // Change the instruction so it won't try to commit again until
1115 // it is executed.
1116 head_inst->clearCanCommit();
1117
1118 if (head_inst->isLoad() && head_inst->strictlyOrdered()) {
1119 DPRINTF(Commit, "[tid:%i] [sn:%llu] "
1120 "Strictly ordered load, PC %s.\n",
1121 tid, head_inst->seqNum, head_inst->pcState());
1122 toIEW->commitInfo[tid].strictlyOrdered = true;
1123 toIEW->commitInfo[tid].strictlyOrderedLoad = head_inst;
1124 } else {
1125 ++stats.commitNonSpecStalls;
1126 }
1127
1128 return false;
1129 }
1130
1131 // Check if the instruction caused a fault. If so, trap.
1132 Fault inst_fault = head_inst->getFault();
1133
1134 // hardware transactional memory
1135 // if a fault occurred within a HTM transaction
1136 // ensure that the transaction aborts
1137 if (inst_fault != NoFault && head_inst->inHtmTransactionalState()) {
1138 // There exists a generic HTM fault common to all ISAs
1139 if (!std::dynamic_pointer_cast<GenericHtmFailureFault>(inst_fault)) {
1140 DPRINTF(HtmCpu, "%s - fault (%s) encountered within transaction"
1141 " - converting to GenericHtmFailureFault\n",
1142 head_inst->staticInst->getName(), inst_fault->name());
1143 inst_fault = std::make_shared<GenericHtmFailureFault>(
1144 head_inst->getHtmTransactionUid(),
1146 }
1147 // If this point is reached and the fault inherits from the HTM fault,
1148 // then there is no need to raise a new fault
1149 }
1150
1151 // Stores mark themselves as completed.
1152 if (!head_inst->isStore() && inst_fault == NoFault) {
1153 head_inst->setCompleted();
1154 }
1155
1156 if (inst_fault != NoFault) {
1157 DPRINTF(Commit, "Inst [tid:%i] [sn:%llu] PC %s has a fault\n",
1158 tid, head_inst->seqNum, head_inst->pcState());
1159
1160 if (iewStage->hasStoresToWB(tid) || inst_num > 0) {
1162 "[tid:%i] [sn:%llu] "
1163 "Stores outstanding, fault must wait.\n",
1164 tid, head_inst->seqNum);
1165 return false;
1166 }
1167
1168 head_inst->setCompleted();
1169
1170 // If instruction has faulted, let the checker execute it and
1171 // check if it sees the same fault and control flow.
1172 if (cpu->checker) {
1173 // Need to check the instruction before its fault is processed
1174 cpu->checker->verify(head_inst);
1175 }
1176
1177 assert(!thread[tid]->noSquashFromTC);
1178
1179 // Mark that we're in state update mode so that the trap's
1180 // execution doesn't generate extra squashes.
1181 thread[tid]->noSquashFromTC = true;
1182
1183 // Execute the trap. Although it's slightly unrealistic in
1184 // terms of timing (as it doesn't wait for the full timing of
1185 // the trap event to complete before updating state), it's
1186 // needed to update the state as soon as possible. This
1187 // prevents external agents from changing any specific state
1188 // that the trap need.
1189 cpu->trap(inst_fault, tid,
1190 head_inst->notAnInst() ? nullStaticInstPtr :
1191 head_inst->staticInst);
1192
1193 // Exit state update mode to avoid accidental updating.
1194 thread[tid]->noSquashFromTC = false;
1195
1197
1199 "[tid:%i] [sn:%llu] Committing instruction with fault\n",
1200 tid, head_inst->seqNum);
1201 if (head_inst->traceData) {
1202 // We ignore ReExecution "faults" here as they are not real
1203 // (architectural) faults but signal flush/replays.
1204 if (debug::ExecFaulting
1205 && dynamic_cast<ReExec*>(inst_fault.get()) == nullptr) {
1206
1207 head_inst->traceData->setFaulting(true);
1208 head_inst->traceData->setFetchSeq(head_inst->seqNum);
1209 head_inst->traceData->setCPSeq(thread[tid]->numOp);
1210 head_inst->traceData->dump();
1211 }
1212 delete head_inst->traceData;
1213 head_inst->traceData = NULL;
1214 }
1215
1216 // Generate trap squash event.
1217 generateTrapEvent(tid, inst_fault);
1218 return false;
1219 }
1220
1221 updateComInstStats(head_inst);
1222
1224 "[tid:%i] [sn:%llu] Committing instruction with PC %s\n",
1225 tid, head_inst->seqNum, head_inst->pcState());
1226
1227 if (head_inst->isReturn()) {
1229 "[tid:%i] [sn:%llu] Return Instruction Committed PC %s \n",
1230 tid, head_inst->seqNum, head_inst->pcState());
1231 }
1232
1233 // Update the commit rename map
1234 for (int i = 0; i < head_inst->numDestRegs(); i++) {
1235 renameMap[tid]->setEntry(head_inst->flattenedDestIdx(i),
1236 head_inst->renamedDestIdx(i));
1237 }
1238
1239 // hardware transactional memory
1240 // the HTM UID is purely for correctness and debugging purposes
1241 if (head_inst->isHtmStart())
1242 iewStage->setLastRetiredHtmUid(tid, head_inst->getHtmTransactionUid());
1243
1244 // Finally clear the head ROB entry.
1245 rob->retireHead(tid);
1246
1247 head_inst->commitTick = curTick() - head_inst->fetchTick;
1248
1249 if (head_inst->traceData) {
1250 head_inst->traceData->setFetchSeq(head_inst->seqNum);
1251 head_inst->traceData->setCPSeq(thread[tid]->numOp);
1252 head_inst->traceData->dump();
1253 delete head_inst->traceData;
1254 head_inst->traceData = NULL;
1255 }
1256
1257 // If this was a store, record it for this cycle.
1258 if (head_inst->isStore() || head_inst->isAtomic())
1259 committedStores[tid] = true;
1260
1261 // Return true to indicate that we have committed an instruction.
1262 return true;
1263}
1264
1265void
1267{
1268 DPRINTF(Commit, "Getting instructions from Rename stage.\n");
1269
1270 // Read any renamed instructions and place them into the ROB.
1271 int insts_to_process = std::min((int)renameWidth, fromRename->size);
1272
1273 for (int inst_num = 0; inst_num < insts_to_process; ++inst_num) {
1274 const DynInstPtr &inst = fromRename->insts[inst_num];
1275 ThreadID tid = inst->threadNumber;
1276
1277 if (!inst->isSquashed() &&
1278 commitStatus[tid] != ROBSquashing &&
1279 commitStatus[tid] != TrapPending) {
1280 changedROBNumEntries[tid] = true;
1281
1282 DPRINTF(Commit, "[tid:%i] [sn:%llu] Inserting PC %s into ROB.\n",
1283 tid, inst->seqNum, inst->pcState());
1284
1285 rob->insertInst(inst);
1286
1287 assert(rob->getThreadEntries(tid) <= rob->getMaxEntries(tid));
1288
1289 youngestSeqNum[tid] = inst->seqNum;
1290 } else {
1291 DPRINTF(Commit, "[tid:%i] [sn:%llu] "
1292 "Instruction PC %s was squashed, skipping.\n",
1293 tid, inst->seqNum, inst->pcState());
1294 }
1295 }
1296}
1297
1298void
1300{
1301 // Grab completed insts out of the IEW instruction queue, and mark
1302 // instructions completed within the ROB.
1303 for (int inst_num = 0; inst_num < fromIEW->size; ++inst_num) {
1304 assert(fromIEW->insts[inst_num]);
1305 if (!fromIEW->insts[inst_num]->isSquashed()) {
1306 DPRINTF(Commit, "[tid:%i] Marking PC %s, [sn:%llu] ready "
1307 "within ROB.\n",
1308 fromIEW->insts[inst_num]->threadNumber,
1309 fromIEW->insts[inst_num]->pcState(),
1310 fromIEW->insts[inst_num]->seqNum);
1311
1312 // Mark the instruction as ready to commit.
1313 fromIEW->insts[inst_num]->setCanCommit();
1314 }
1315 }
1316}
1317
1318void
1320{
1321 const ThreadID tid = inst->threadNumber;
1322 const bool in_user_mode = cpu->inUserMode(tid);
1323
1324 // Count number of instructions, ensure we don't
1325 // double count Microops as insts.
1326 if (!inst->isMicroop() || inst->isLastMicroop()) {
1327 cpu->commitStats[tid]->numInsts++;
1328 cpu->baseStats.numInsts++;
1329 if (in_user_mode) {
1330 cpu->commitStats[tid]->numUserInsts++;
1331 }
1332 }
1333
1334 cpu->commitStats[tid]->numOps++;
1335 if (in_user_mode) {
1336 cpu->commitStats[tid]->numUserOps++;
1337 }
1338
1339 // To match the old model, don't count nops and instruction
1340 // prefetches towards the total commit count.
1341 if (!inst->isNop() && !inst->isInstPrefetch()) {
1342 cpu->instDone(tid, inst);
1343 }
1344
1345 //
1346 // Control Instructions
1347 //
1348 cpu->commitStats[tid]->updateComCtrlStats(inst->staticInst);
1349
1350 //
1351 // Memory references
1352 //
1353 if (inst->isMemRef()) {
1354 cpu->commitStats[tid]->numMemRefs++;
1355
1356 if (inst->isLoad()) {
1357 cpu->commitStats[tid]->numLoadInsts++;
1358 }
1359
1360 if (inst->isStore() || inst->isAtomic()) {
1361 cpu->commitStats[tid]->numStoreInsts++;
1362 }
1363 }
1364
1365 if (inst->isFullMemBarrier()) {
1366 stats.membars[tid]++;
1367 }
1368
1369 // Integer Instruction
1370 if (inst->isInteger()) {
1371 cpu->commitStats[tid]->numIntInsts++;
1372 }
1373
1374 // Floating Point Instruction
1375 if (inst->isFloating()) {
1376 cpu->commitStats[tid]->numFpInsts++;
1377 }
1378 // Vector Instruction
1379 if (inst->isVector()) {
1380 cpu->commitStats[tid]->numVecInsts++;
1381 }
1382
1383 // Function Calls
1384 if (inst->isCall()) {
1385 cpu->commitStats[tid]->functionCalls++;
1386 }
1387
1388 if (inst->isCall() || inst->isReturn()) {
1389 cpu->commitStats[tid]->numCallsReturns++;
1390 }
1391}
1392
1394// //
1395// SMT COMMIT POLICY MAINTAINED HERE //
1396// //
1400{
1401 if (numThreads > 1) {
1402 // If a thread is exiting, we need to ensure that *all* of its
1403 // instructions will be retired in this cycle, because the
1404 // thread will be removed from the CPU at the end of this cycle.
1405 // To ensure this, we prioritize committing from exiting threads
1406 // before we consider other threads using the specified SMT
1407 // commit policy.
1408 for (ThreadID tid : *activeThreads) {
1409 if (cpu->isThreadExiting(tid) &&
1410 !rob->isEmpty(tid) &&
1411 (commitStatus[tid] == Running ||
1412 commitStatus[tid] == Idle ||
1413 commitStatus[tid] == FetchTrapPending)) {
1414 assert(rob->isHeadReady(tid) &&
1415 rob->readHeadInst(tid)->isSquashed());
1416 return tid;
1417 }
1418 }
1419
1420 switch (commitPolicy) {
1421 case CommitPolicy::RoundRobin:
1422 return roundRobin();
1423
1424 case CommitPolicy::OldestReady:
1425 return oldestReady();
1426
1427 default:
1428 return InvalidThreadID;
1429 }
1430 } else {
1431 assert(!activeThreads->empty());
1432 ThreadID tid = activeThreads->front();
1433
1434 if (commitStatus[tid] == Running ||
1435 commitStatus[tid] == Idle ||
1437 return tid;
1438 } else {
1439 return InvalidThreadID;
1440 }
1441 }
1442}
1443
1446{
1447 auto pri_iter = priority_list.begin();
1448 auto end = priority_list.end();
1449
1450 while (pri_iter != end) {
1451 ThreadID tid = *pri_iter;
1452
1453 if (commitStatus[tid] == Running ||
1454 commitStatus[tid] == Idle ||
1456
1457 if (rob->isHeadReady(tid)) {
1458 priority_list.erase(pri_iter);
1459 priority_list.push_back(tid);
1460
1461 return tid;
1462 }
1463 }
1464
1465 pri_iter++;
1466 }
1467
1468 return InvalidThreadID;
1469}
1470
1473{
1474 unsigned oldest = 0;
1475 unsigned oldest_seq_num = 0;
1476 bool first = true;
1477
1478 for (ThreadID tid : *activeThreads) {
1479 if (!rob->isEmpty(tid) &&
1480 (commitStatus[tid] == Running ||
1481 commitStatus[tid] == Idle ||
1482 commitStatus[tid] == FetchTrapPending)) {
1483
1484 if (rob->isHeadReady(tid)) {
1485
1486 const DynInstPtr &head_inst = rob->readHeadInst(tid);
1487
1488 if (first) {
1489 oldest = tid;
1490 oldest_seq_num = head_inst->seqNum;
1491 first = false;
1492 } else if (head_inst->seqNum < oldest_seq_num) {
1493 oldest = tid;
1494 oldest_seq_num = head_inst->seqNum;
1495 }
1496 }
1497 }
1498 }
1499
1500 if (!first) {
1501 return oldest;
1502 } else {
1503 return InvalidThreadID;
1504 }
1505}
1506
1507} // namespace o3
1508} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:209
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
ProbePointArg generates a point for the class of Arg.
Definition probe.hh:273
O3CPU class, has each of the stages (fetch through commit) within it, as well as all of the time buff...
Definition cpu.hh:97
ThreadStatus commitStatus[MaxThreads]
Per-thread status.
Definition commit.hh:120
TimeBuffer< IEWStruct >::wire fromIEW
Wire to read information from IEW queue.
Definition commit.hh:332
std::vector< ThreadState * > thread
Vector of all of the threads.
Definition commit.hh:349
ThreadID oldestReady()
Returns the thread ID to use based on an oldest instruction policy.
Definition commit.cc:1472
ProbePointArg< DynInstPtr > * ppCommitStall
Definition commit.hh:126
int htmStops[MaxThreads]
Definition commit.hh:462
void squashFromSquashAfter(ThreadID tid)
Handles a squash from a squashAfter() request.
Definition commit.cc:544
void squashAll(ThreadID tid)
Squashes all in flight instructions.
Definition commit.cc:475
void startupStage()
Initializes stage by sending back the number of free entries.
Definition commit.cc:259
bool changedROBNumEntries[MaxThreads]
Records if the number of ROB entries has changed this cycle.
Definition commit.hh:359
bool changedROBEntries()
Returns if any of the threads have the number of ROB entries changed on this cycle.
Definition commit.cc:422
DynInstPtr squashAfterInst[MaxThreads]
Instruction passed to squashAfter().
Definition commit.hh:374
bool executingHtmTransaction(ThreadID) const
Is the CPU currently processing a HTM transaction?
Definition commit.cc:377
CommitStatus _status
Overall commit status.
Definition commit.hh:116
gem5::o3::Commit::CommitStats stats
void setIEWQueue(TimeBuffer< IEWStruct > *iq_ptr)
Sets the pointer to the queue coming from IEW.
Definition commit.cc:229
size_t numROBFreeEntries(ThreadID tid)
Returns the number of free ROB entries for a specific thread.
Definition commit.cc:434
void setFetchQueue(TimeBuffer< FetchStruct > *fq_ptr)
Definition commit.cc:211
ROB * rob
ROB interface.
Definition commit.hh:342
void processTrapEvent(ThreadID tid)
Mark the thread as processing a trap.
Definition commit.cc:76
void setRenameQueue(TimeBuffer< RenameStruct > *rq_ptr)
Sets the pointer to the queue coming from rename.
Definition commit.cc:220
bool checkEmptyROB[MaxThreads]
Records if commit should check if the ROB is truly empty (see commit_impl.hh).
Definition commit.hh:440
void generateTrapEvent(ThreadID tid, Fault inst_fault)
Generates an event to schedule a squash due to a trap.
Definition commit.cc:440
void deactivateThread(ThreadID tid)
Deschedules a thread from scheduling.
Definition commit.cc:366
TimeBuffer< TimeStruct >::wire toIEW
Wire to write information heading to previous stages.
Definition commit.hh:319
CPU * cpu
Pointer to O3CPU.
Definition commit.hh:346
void squashFromTC(ThreadID tid)
Handles squashing due to an TC write.
Definition commit.cc:528
const ThreadID numThreads
Number of Active Threads.
Definition commit.hh:399
ProbePointArg< DynInstPtr > * ppSquash
To probe when an instruction is squashed.
Definition commit.hh:128
Commit(CPU *_cpu, const BaseO3CPUParams &params)
Construct a Commit with the given parameters.
Definition commit.cc:83
bool trapInFlight[MaxThreads]
Records if there is a trap currently in flight.
Definition commit.hh:433
void handleInterrupt()
Handles processing an interrupt.
Definition commit.cc:641
const Cycles fetchToCommitDelay
Definition commit.hh:388
void propagateInterrupt()
Get fetch redirecting so we can handle an interrupt.
Definition commit.cc:694
std::string name() const
Returns the name of the Commit.
Definition commit.cc:134
TimeBuffer< FetchStruct > * fetchQueue
Definition commit.hh:324
void setROB(ROB *rob_ptr)
Sets pointer to the ROB.
Definition commit.cc:256
int htmStarts[MaxThreads]
Definition commit.hh:461
CommitPolicy commitPolicy
Commit policy used in SMT mode.
Definition commit.hh:122
TimeBuffer< TimeStruct >::wire robInfoFromIEW
Wire to read information from IEW (for ROB).
Definition commit.hh:322
void tick()
Ticks the commit stage, which tries to commit instructions.
Definition commit.cc:572
void setIEWStage(IEW *iew_stage)
Sets the pointer to the IEW stage.
Definition commit.cc:238
const unsigned renameWidth
Rename width, in instructions.
Definition commit.hh:393
bool drainPending
Is a drain pending?
Definition commit.hh:404
const Cycles trapLatency
The latency to handle a trap.
Definition commit.hh:416
ProbePointArg< DynInstPtr > * ppCommit
Probe Points.
Definition commit.hh:125
bool wroteToTimeBuffer
Records that commit has written to the time buffer this cycle.
Definition commit.hh:354
TimeBuffer< IEWStruct > * iewQueue
IEW instruction queue interface.
Definition commit.hh:329
void setTimeBuffer(TimeBuffer< TimeStruct > *tb_ptr)
Sets the main time buffer pointer, used for backwards communication.
Definition commit.cc:199
void setActiveThreads(std::list< ThreadID > *at_ptr)
Sets pointer to list of active threads.
Definition commit.cc:244
const Cycles renameToROBDelay
Rename to ROB delay.
Definition commit.hh:386
std::list< ThreadID > * activeThreads
Pointer to the list of active threads.
Definition commit.hh:443
void updateStatus()
Updates the overall status of commit with the nextStatus, and tell the CPU if commit is active/inacti...
Definition commit.cc:397
void squashAfter(ThreadID tid, const DynInstPtr &head_inst)
Handle squashing from instruction with SquashAfter set.
Definition commit.cc:561
bool commitHead(const DynInstPtr &head_inst, unsigned inst_num)
Tries to commit the head ROB instruction passed in.
Definition commit.cc:1082
void resetHtmStartsStops(ThreadID)
Definition commit.cc:386
void getInsts()
Gets instructions from rename and inserts them into the ROB.
Definition commit.cc:1266
bool tcSquash[MaxThreads]
Records if a thread has to squash this cycle due to an XC write.
Definition commit.hh:365
const Cycles commitToIEWDelay
Commit to IEW delay.
Definition commit.hh:383
void drainSanityCheck() const
Perform sanity checks after a drain.
Definition commit.cc:309
void takeOverFrom()
Takes over from another CPU's thread.
Definition commit.cc:351
void clearStates(ThreadID tid)
Clear all thread-specific states.
Definition commit.cc:279
void drainResume()
Resumes execution after draining.
Definition commit.cc:302
TimeBuffer< RenameStruct > * renameQueue
Rename instruction queue interface, for ROB.
Definition commit.hh:335
void drain()
Initializes the draining of commit.
Definition commit.cc:299
bool trapSquash[MaxThreads]
Records if a thread has to squash this cycle due to a trap.
Definition commit.hh:362
InstSeqNum youngestSeqNum[MaxThreads]
The sequence number of the youngest valid instruction in the ROB.
Definition commit.hh:427
InstSeqNum lastCommitedSeqNum[MaxThreads]
The sequence number of the last commited instruction.
Definition commit.hh:430
CommitStatus _nextStatus
Next commit status, to be set at the end of the cycle.
Definition commit.hh:118
bool drainImminent
Is a drain imminent?
Definition commit.hh:411
void commitInsts()
Commits as many instructions as possible.
Definition commit.cc:870
void markCompletedInsts()
Marks completed instructions using information sent from IEW.
Definition commit.cc:1299
bool canHandleInterrupts
True if last committed microop can be followed by an interrupt.
Definition commit.hh:449
TimeBuffer< TimeStruct > * timeBuffer
Time buffer interface.
Definition commit.hh:316
TimeBuffer< RenameStruct >::wire fromRename
Wire to read information from rename queue.
Definition commit.hh:338
ThreadID roundRobin()
Returns the thread ID to use based on a round robin policy.
Definition commit.cc:1445
void generateTCEvent(ThreadID tid)
Records that commit needs to initiate a squash due to an external state update through the TC.
Definition commit.cc:466
std::unique_ptr< PCStateBase > pc[MaxThreads]
The commit PC state of each thread.
Definition commit.hh:424
void regProbePoints()
Registers probes.
Definition commit.cc:137
IEW * iewStage
The pointer to the IEW stage.
Definition commit.hh:164
void setThreads(std::vector< ThreadState * > &threads)
Sets the list of threads.
Definition commit.cc:193
void updateComInstStats(const DynInstPtr &inst)
Updates commit stats based on this instruction.
Definition commit.cc:1319
ThreadID getCommittingThread()
Gets the thread to commit, based on the SMT policy.
Definition commit.cc:1399
const Cycles iewToCommitDelay
IEW to Commit delay.
Definition commit.hh:380
bool avoidQuiesceLiveLock
Have we had an interrupt pending and then seen it de-asserted because of a masking change?
Definition commit.hh:455
std::list< ThreadID > priority_list
Priority List used for Commit Policy.
Definition commit.hh:377
void commit()
Handles any squashes that are sent from IEW, and adds instructions to the ROB and tries to commit ins...
Definition commit.cc:718
UnifiedRenameMap * renameMap[MaxThreads]
Rename map interface.
Definition commit.hh:446
void setRenameMap(UnifiedRenameMap::PerThreadUnifiedRenameMap &rm_ptr)
Sets pointer to the commited state rename map.
Definition commit.cc:250
void squashFromTrap(ThreadID tid)
Handles squashing due to a trap.
Definition commit.cc:510
bool committedStores[MaxThreads]
Records if there were any stores committed this cycle.
Definition commit.hh:436
const unsigned commitWidth
Commit width, in instructions.
Definition commit.hh:396
bool isDrained() const
Has the stage drained?
Definition commit.cc:324
Fault interrupt
The interrupt fault.
Definition commit.hh:419
TimeBuffer< FetchStruct >::wire fromFetch
Definition commit.hh:326
IEW handles both single threaded and SMT IEW (issue/execute/writeback).
Definition iew.hh:88
ROB class.
Definition rob.hh:72
std::array< UnifiedRenameMap, MaxThreads > PerThreadUnifiedRenameMap
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition group.hh:75
static const Priority CPU_Tick_Pri
CPU ticks must come after other associated CPU events (such as writebacks).
Definition eventq.hh:207
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:220
#define fatal(...)
This implements a cprintf based fatal() function.
Definition logging.hh:232
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 12, 11 > set
static constexpr int MaxThreads
Definition limits.hh:38
RefCountingPtr< DynInst > DynInstPtr
static constexpr int MaxWidth
Definition limits.hh:37
Units for Stats.
Definition units.hh:113
const FlagsType pdf
Print the percent of the total that this entry represents.
Definition info.hh:61
const FlagsType total
Print the total.
Definition info.hh:59
const FlagsType dist
Print the distribution.
Definition info.hh:65
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::shared_ptr< FaultBase > Fault
Definition types.hh:249
int16_t ThreadID
Thread index/ID type.
Definition types.hh:235
const ThreadID InvalidThreadID
Definition types.hh:236
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition root.cc:220
const StaticInstPtr nullStaticInstPtr
Statically allocated null StaticInstPtr.
constexpr decltype(nullptr) NoFault
Definition types.hh:253
uint64_t InstSeqNum
Definition inst_seq.hh:40
statistics::Vector amos
Stat for the total number of committed atomics.
Definition commit.hh:483
CommitStats(CPU *cpu, Commit *commit)
Definition commit.cc:147
statistics::Distribution numCommittedDist
Distribution of the number of committed instructions each cycle.
Definition commit.hh:480
statistics::Scalar commitNonSpecStalls
Stat for the total number of times commit has had to stall due to a non-speculative instruction reach...
Definition commit.hh:474
statistics::Scalar commitEligibleSamples
Number of cycles where the commit bandwidth limit is reached.
Definition commit.hh:490
statistics::Scalar commitSquashedInsts
Stat for the total number of squashed instructions discarded by commit.
Definition commit.hh:470
statistics::Scalar branchMispredicts
Stat for the total number of branch mispredicts that caused a squash.
Definition commit.hh:478
statistics::Vector2d committedInstType
Committed instructions by instruction type (OpClass)
Definition commit.hh:487
statistics::Vector membars
Total number of committed memory barriers.
Definition commit.hh:485

Generated on Mon Oct 27 2025 04:13:00 for gem5 by doxygen 1.14.0