@@ -148,6 +148,8 @@ Fetch::Fetch(CPU *_cpu, const BaseO3CPUParams ¶ms)
148148 threads[tid].data = new uint8_t [fetchBufferSize];
149149 }
150150
151+ initDecodeScheduler ();
152+
151153 // Get the size of an instruction.
152154 // stallReason size should be the same as decodeWidth,renameWidth,dispWidth
153155 stallReason.resize (decodeWidth, StallReason::NoStall);
@@ -372,6 +374,41 @@ Fetch::setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer)
372374 fromCommit = timeBuffer->getWire (-commitToFetchDelay);
373375}
374376
377+ void
378+ Fetch::initDecodeScheduler ()
379+ {
380+ // Initialize counters (same as before)
381+ lsqCounter = new InstsCounter ();
382+ iqCounter = new InstsCounter ();
383+ robCounter = new InstsCounter ();
384+ DPRINTF (Fetch, " Initialized SMT Decode Scheduler: 0\n " );
385+
386+ for (ThreadID tid = 0 ; tid < numThreads; tid++)
387+ {
388+ lsqCounter->setCounter (tid, 0 );
389+ iqCounter->setCounter (tid, 0 );
390+ robCounter->setCounter (tid, 0 );
391+ }
392+ DPRINTF (Fetch, " Initialized SMT Decode Scheduler: 1\n " );
393+
394+ if (smtDecodePolicy == " icount" ) {
395+ // Use ROB as default counter for icount
396+ decodeScheduler = new ICountScheduler (numThreads, robCounter);
397+ }
398+ else if (smtDecodePolicy == " delayed" ) {
399+ decodeScheduler = new DelayedICountScheduler (numThreads, robCounter, delayedSchedulerDelay);
400+ }
401+ else if (smtDecodePolicy == " multi_priority" ) {
402+ decodeScheduler = new MultiPrioritySched (numThreads, {lsqCounter, iqCounter, robCounter});
403+ }
404+ else {
405+ // Default: round-robin like (use delayed with thread cycling)
406+ decodeScheduler = new DelayedICountScheduler (numThreads, robCounter, numThreads);
407+ }
408+
409+ DPRINTF (Fetch, " Initialized SMT Decode Scheduler: %s\n " , smtDecodePolicy.c_str ());
410+ }
411+
375412void
376413Fetch::setActiveThreads (std::list<ThreadID> *at_ptr)
377414{
@@ -1285,6 +1322,32 @@ Fetch::handleInterrupts()
12851322 }
12861323}
12871324
1325+ ThreadID
1326+ Fetch::selectUnstalledThread ()
1327+ {
1328+
1329+ // if (numThreads == 1) {
1330+ // return 0;
1331+ // }
1332+ for (ThreadID tid = 0 ; tid < numThreads; ++tid) {
1333+ if (!stallSig->blockFetch [tid]) {
1334+ lsqCounter->setCounter (tid, fromIEW->iewInfo [tid].ldstqCount );
1335+ iqCounter->setCounter (tid, fromIEW->iewInfo [tid].iqCount );
1336+ robCounter->setCounter (tid, fromIEW->iewInfo [tid].robCount );
1337+
1338+ } else {
1339+ lsqCounter->setCounter (tid, UINT64_MAX);
1340+ iqCounter->setCounter (tid, UINT64_MAX);
1341+ robCounter->setCounter (tid, UINT64_MAX);
1342+
1343+ }
1344+ DPRINTF (Fetch, " lsqCounter->setCounter: %d iqCounter->setCounter: %d robCounter->setCounter: %d\n " ,fromIEW->iewInfo [tid].ldstqCount ,fromIEW->iewInfo [tid].iqCount ,fromIEW->iewInfo [tid].robCount );
1345+ }
1346+
1347+ ThreadID selected = decodeScheduler->getThread ();
1348+ return selected;
1349+ }
1350+
12881351void
12891352Fetch::sendInstructionsToDecode ()
12901353{
@@ -1321,7 +1384,7 @@ Fetch::sendInstructionsToDecode()
13211384 return ;
13221385 }
13231386
1324- ThreadID tid = 0 ; // TODO: smt support
1387+ ThreadID tid =selectUnstalledThread ();
13251388
13261389 // fetch totally stalled
13271390 if (stallSig->blockFetch [tid]) {
0 commit comments