Skip to content

Commit bb57418

Browse files
mhnGitHubzmohaonan
andauthored
add frontend and backend smt (#791)
Co-authored-by: mohaonan <mo.haonan1@sanechips.com.cn>
1 parent a6f4a18 commit bb57418

File tree

11 files changed

+313
-29
lines changed

11 files changed

+313
-29
lines changed

src/cpu/o3/FuncScheduler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class PAgeSelector(BaseSelector):
7575

7676
piece = Param.Int(2, "number of instructions in a group")
7777

78+
class SMTBasedSelector(BaseSelector):
79+
type = 'SMTBasedSelector'
80+
cxx_class = 'gem5::o3::SMTBasedSelector'
81+
cxx_header = "cpu/o3/issue_queue.hh"
82+
7883
class IssueQue(SimObject):
7984
type = 'IssueQue'
8085
cxx_class = 'gem5::o3::IssueQue'
@@ -85,7 +90,7 @@ class IssueQue(SimObject):
8590
inports = Param.Int(2, "")
8691
scheduleToExecDelay = Param.Cycles(2, "")
8792
oports = VectorParam.IssuePort("")
88-
sel = Param.BaseSelector(BaseSelector(), "Selector for this IQ (default: age first)")
93+
sel = Param.BaseSelector(SMTBasedSelector(), "Selector for this IQ (default: age first)")
8994

9095
class Scheduler(SimObject):
9196
type = 'Scheduler'

src/cpu/o3/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Import('*')
3232

3333
if env['CONF']['TARGET_ISA'] != 'null':
3434
SimObject('FuncScheduler.py', sim_objects=['FUPool', 'SpecWakeupChannel',
35-
'IssuePort', 'IssueQue', 'BaseSelector', 'PAgeSelector', 'Scheduler'])
35+
'IssuePort', 'IssueQue', 'BaseSelector', 'PAgeSelector', 'SMTBasedSelector', 'Scheduler'])
3636
SimObject('FuncUnitConfig.py', sim_objects=[])
3737
SimObject('BaseO3CPU.py', sim_objects=['BaseO3CPU'], enums=[
3838
'SMTFetchPolicy', 'SMTQueuePolicy', 'CommitPolicy', 'ROBWalkPolicy', 'ROBCompressPolicy', 'PerfRecord'])

src/cpu/o3/comm.hh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ struct IssueStruct
168168
DynInstPtr insts[MaxWidth];
169169
};
170170

171+
struct SquashInfo
172+
{
173+
InstSeqNum squashSn;
174+
ThreadID squashTid;
175+
};
176+
171177
struct SquashVersion
172178
{
173179
uint8_t version;
@@ -246,6 +252,10 @@ struct TimeStruct
246252
};
247253
/** Resolved control-flow PCs produced this cycle (fetch buffers/merges). */
248254
std::vector<ResolvedCFIEntry> resolvedCFIs; // *F
255+
256+
unsigned iqCount;
257+
unsigned ldstqCount;
258+
unsigned robCount;
249259
};
250260

251261
IewComm iewInfo[MaxThreads]; // iew to rename, fetch

src/cpu/o3/fetch.cc

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ Fetch::Fetch(CPU *_cpu, const BaseO3CPUParams &params)
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+
375412
void
376413
Fetch::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+
12881351
void
12891352
Fetch::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]) {

src/cpu/o3/fetch.hh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "mem/port.hh"
6666
#include "sim/eventq.hh"
6767
#include "sim/probe/probe.hh"
68+
#include "cpu/o3/smt_sched.hh"
6869

6970
namespace gem5
7071
{
@@ -233,6 +234,18 @@ class Fetch
233234
/** To probe when a fetch request is successfully sent. */
234235
ProbePointArg<RequestPtr> *ppFetchRequestSent;
235236

237+
// SMT Decode Scheduler
238+
SMTScheduler* decodeScheduler;
239+
240+
// Counters from backend structures (to be passed in)
241+
InstsCounter* lsqCounter;
242+
InstsCounter* iqCounter;
243+
InstsCounter* robCounter;
244+
245+
// Configuration parameters
246+
std::string smtDecodePolicy ="multi_priority";
247+
int delayedSchedulerDelay;
248+
236249
public:
237250
/** Fetch constructor. */
238251
Fetch(CPU *_cpu, const BaseO3CPUParams &params);
@@ -299,6 +312,12 @@ class Fetch
299312

300313
/** For priority-based fetch policies, need to keep update priorityList */
301314
void deactivateThread(ThreadID tid);
315+
316+
// Function to initialize scheduler
317+
void initDecodeScheduler();
318+
319+
// Select a thread that is not fetch-blocked, using scheduler
320+
ThreadID selectUnstalledThread();
302321
private:
303322
/** Reset this pipeline stage */
304323
void resetStage();

src/cpu/o3/iew.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ IEW::squash(ThreadID tid)
525525

526526
for (auto& dp : dispQue) {
527527
for (auto& it : dp) {
528-
if (it->seqNum > fromCommit->commitInfo[tid].doneSeqNum) {
528+
if (it->seqNum > fromCommit->commitInfo[tid].doneSeqNum && (it->threadNumber == tid)) {
529529
it->setSquashed();
530530
}
531531
}
@@ -1533,6 +1533,9 @@ IEW::executeInsts()
15331533
ThreadID tid = *activeThreads->begin();
15341534
toFetch->iewInfo[tid].resolvedCFIs.clear();
15351535

1536+
toFetch->iewInfo[tid].ldstqCount=ldstQueue.getCount(tid);
1537+
toFetch->iewInfo[tid].robCount= rob->getThreadEntries(tid);
1538+
toFetch->iewInfo[tid].iqCount= scheduler->getIQInsts(tid);
15361539
// Execute/writeback any instructions that are available.
15371540
int insts_to_execute = fromIssue->size;
15381541
fromIssue->size = 0;

src/cpu/o3/inst_queue.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ InstructionQueue::InstructionQueue(CPU *cpu_ptr, IEW *iew_ptr,
151151
scheduler->setCPU(cpu_ptr, &iew_ptr->ldstQueue);
152152
scheduler->resetDepGraph(numPhysRegs);
153153
scheduler->setMemDepUnit(memDepUnit);
154-
154+
scheduler->initIQICountSmtScheduler(numThreads);
155+
155156
resetState();
156157
}
157158

@@ -1121,7 +1122,9 @@ InstructionQueue::doSquash(ThreadID tid)
11211122

11221123
DPRINTF(IQ, "[tid:%i] Squashing until sequence number %i!\n",
11231124
tid, squashedSeqNum[tid]);
1124-
scheduler->doSquash(squashedSeqNum[tid]);
1125+
squashInfo.squashTid = tid;
1126+
squashInfo.squashSn = squashedSeqNum[tid];
1127+
scheduler->doSquash(squashInfo);
11251128

11261129
for (auto it = mdpAddrReplayLdInsts.begin(); it != mdpAddrReplayLdInsts.end();) {
11271130
if (!it->inst ||
@@ -1134,7 +1137,7 @@ InstructionQueue::doSquash(ThreadID tid)
11341137
}
11351138

11361139
for (auto it = nonSpecInsts.begin(); it != nonSpecInsts.end();) {
1137-
if (it->first > squashedSeqNum[tid]) {
1140+
if (it->first > squashedSeqNum[tid] && (it->second->threadNumber == tid)) {
11381141
auto& squashed_inst = it->second;
11391142
if (!squashed_inst->isIssued() ||
11401143
(squashed_inst->isMemRef() &&

src/cpu/o3/inst_queue.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ class InstructionQueue
427427

428428
/** The sequence number of the squashed instruction. */
429429
InstSeqNum squashedSeqNum[MaxThreads];
430+
SquashInfo squashInfo;
430431

431432
struct IQStats : public statistics::Group
432433
{

0 commit comments

Comments
 (0)