-
Notifications
You must be signed in to change notification settings - Fork 72
kmh smt support #792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: xs-dev
Are you sure you want to change the base?
kmh smt support #792
Changes from 1 commit
51fa60b
d461056
589b793
04e0f43
3566e2d
1391a92
94c3b8a
1fe2ec0
ab98f29
b022995
c3d6a15
8314234
100e246
0ce2932
de1bbd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,6 +148,8 @@ Fetch::Fetch(CPU *_cpu, const BaseO3CPUParams ¶ms) | |
| threads[tid].data = new uint8_t[fetchBufferSize]; | ||
| } | ||
|
|
||
| initDecodeScheduler(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The decode scheduler policy is still effectively hardcoded.
Also applies to: 393-406 🤖 Prompt for AI Agents |
||
|
|
||
| // Get the size of an instruction. | ||
| // stallReason size should be the same as decodeWidth,renameWidth,dispWidth | ||
| stallReason.resize(decodeWidth, StallReason::NoStall); | ||
|
|
@@ -372,6 +374,41 @@ Fetch::setTimeBuffer(TimeBuffer<TimeStruct> *time_buffer) | |
| fromCommit = timeBuffer->getWire(-commitToFetchDelay); | ||
| } | ||
|
|
||
| void | ||
| Fetch::initDecodeScheduler() | ||
| { | ||
| // Initialize counters (same as before) | ||
| lsqCounter = new InstsCounter(); | ||
| iqCounter = new InstsCounter(); | ||
| robCounter = new InstsCounter(); | ||
| DPRINTF(Fetch, "Initialized SMT Decode Scheduler: 0\n"); | ||
|
|
||
| for (ThreadID tid = 0; tid < numThreads; tid++) | ||
| { | ||
| lsqCounter->setCounter(tid, 0); | ||
| iqCounter->setCounter(tid, 0); | ||
| robCounter->setCounter(tid, 0); | ||
| } | ||
| DPRINTF(Fetch, "Initialized SMT Decode Scheduler: 1\n"); | ||
|
|
||
| if (smtDecodePolicy == "icount") { | ||
| // Use ROB as default counter for icount | ||
| decodeScheduler = new ICountScheduler(numThreads, robCounter); | ||
| } | ||
| else if (smtDecodePolicy == "delayed") { | ||
| decodeScheduler = new DelayedICountScheduler(numThreads, robCounter, delayedSchedulerDelay); | ||
| } | ||
| else if (smtDecodePolicy == "multi_priority") { | ||
| decodeScheduler = new MultiPrioritySched(numThreads, {lsqCounter, iqCounter, robCounter}); | ||
| } | ||
| else { | ||
| // Default: round-robin like (use delayed with thread cycling) | ||
| decodeScheduler = new DelayedICountScheduler(numThreads, robCounter, numThreads); | ||
| } | ||
|
|
||
| DPRINTF(Fetch, "Initialized SMT Decode Scheduler: %s\n", smtDecodePolicy.c_str()); | ||
| } | ||
|
Comment on lines
+396
to
+429
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Memory leak: dynamically allocated objects are never freed. The counters and scheduler are allocated with 🛠️ Suggested fix: store as unique_ptr or delete in destructorConsider using smart pointers for automatic memory management: +// In fetch.hh, change member declarations:
+std::unique_ptr<InstsCounter> lsqCounter;
+std::unique_ptr<InstsCounter> iqCounter;
+std::unique_ptr<InstsCounter> robCounter;
+std::unique_ptr<SMTScheduler> decodeScheduler;
// In initDecodeScheduler():
- lsqCounter = new InstsCounter();
- iqCounter = new InstsCounter();
- robCounter = new InstsCounter();
+ lsqCounter = std::make_unique<InstsCounter>();
+ iqCounter = std::make_unique<InstsCounter>();
+ robCounter = std::make_unique<InstsCounter>();Or alternatively, add cleanup in the destructor. 🤖 Prompt for AI Agents |
||
|
|
||
| void | ||
| Fetch::setActiveThreads(std::list<ThreadID> *at_ptr) | ||
| { | ||
|
|
@@ -1285,6 +1322,32 @@ Fetch::handleInterrupts() | |
| } | ||
| } | ||
|
|
||
| ThreadID | ||
| Fetch::selectUnstalledThread() | ||
| { | ||
|
|
||
| // if (numThreads == 1) { | ||
| // return 0; | ||
| // } | ||
| for (ThreadID tid = 0; tid < numThreads; ++tid) { | ||
| if (!stallSig->blockFetch[tid]) { | ||
| lsqCounter->setCounter(tid, fromIEW->iewInfo[tid].ldstqCount); | ||
| iqCounter->setCounter(tid, fromIEW->iewInfo[tid].iqCount); | ||
| robCounter->setCounter(tid, fromIEW->iewInfo[tid].robCount); | ||
|
|
||
| } else { | ||
| lsqCounter->setCounter(tid, UINT64_MAX); | ||
| iqCounter->setCounter(tid, UINT64_MAX); | ||
| robCounter->setCounter(tid, UINT64_MAX); | ||
|
|
||
| } | ||
| DPRINTF(Fetch, "lsqCounter->setCounter: %d iqCounter->setCounter: %d robCounter->setCounter: %d\n",fromIEW->iewInfo[tid].ldstqCount,fromIEW->iewInfo[tid].iqCount,fromIEW->iewInfo[tid].robCount); | ||
| } | ||
|
|
||
| ThreadID selected = decodeScheduler->getThread(); | ||
| return selected; | ||
| } | ||
|
Comment on lines
+1387
to
+1411
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid selecting threads with empty fetch queues for decode handoff. The selector currently considers only Proposed fix ThreadID
Fetch::selectUnstalledThread()
{
+ bool hasCandidate = false;
for (ThreadID tid = 0; tid < numThreads; ++tid) {
- if (!stallSig->blockFetch[tid]) {
+ if (!stallSig->blockFetch[tid] && !fetchQueue[tid].empty()) {
+ hasCandidate = true;
lsqCounter->setCounter(tid, fromIEW->iewInfo[tid].ldstqCount);
iqCounter->setCounter(tid, fromIEW->iewInfo[tid].iqCount);
robCounter->setCounter(tid, fromIEW->iewInfo[tid].robCount);
} else {
lsqCounter->setCounter(tid, UINT64_MAX);
iqCounter->setCounter(tid, UINT64_MAX);
robCounter->setCounter(tid, UINT64_MAX);
}
}
+ if (!hasCandidate) {
+ return InvalidThreadID;
+ }
ThreadID selected = decodeScheduler->getThread();
return selected;
}- ThreadID tid =selectUnstalledThread();
+ ThreadID tid = selectUnstalledThread();
+ if (tid == InvalidThreadID) {
+ toDecode->fetchStallReason = stallReason;
+ return;
+ }Also applies to: 1387-1408 🤖 Prompt for AI Agents |
||
|
|
||
| void | ||
| Fetch::sendInstructionsToDecode() | ||
| { | ||
|
|
@@ -1321,7 +1384,7 @@ Fetch::sendInstructionsToDecode() | |
| return; | ||
| } | ||
|
|
||
| ThreadID tid = 0; // TODO: smt support | ||
| ThreadID tid =selectUnstalledThread(); | ||
|
|
||
| // fetch totally stalled | ||
| if (stallSig->blockFetch[tid]) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -65,6 +65,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||
| #include "mem/port.hh" | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "sim/eventq.hh" | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "sim/probe/probe.hh" | ||||||||||||||||||||||||||||||||||||||||||||||
| #include "cpu/o3/smt_sched.hh" | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| namespace gem5 | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -233,6 +234,18 @@ class Fetch | |||||||||||||||||||||||||||||||||||||||||||||
| /** To probe when a fetch request is successfully sent. */ | ||||||||||||||||||||||||||||||||||||||||||||||
| ProbePointArg<RequestPtr> *ppFetchRequestSent; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // SMT Decode Scheduler | ||||||||||||||||||||||||||||||||||||||||||||||
| SMTScheduler* decodeScheduler; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Counters from backend structures (to be passed in) | ||||||||||||||||||||||||||||||||||||||||||||||
| InstsCounter* lsqCounter; | ||||||||||||||||||||||||||||||||||||||||||||||
| InstsCounter* iqCounter; | ||||||||||||||||||||||||||||||||||||||||||||||
| InstsCounter* robCounter; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Configuration parameters | ||||||||||||||||||||||||||||||||||||||||||||||
| std::string smtDecodePolicy ="multi_priority"; | ||||||||||||||||||||||||||||||||||||||||||||||
| int delayedSchedulerDelay; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+237
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -C4 'Fetch::Fetch\s*\(|Fetch::~Fetch\s*\(' src/cpu/o3/fetch.ccRepository: OpenXiangShan/GEM5 Length of output: 562 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Get the full constructor from line 89 until the closing brace
sed -n '89,170p' src/cpu/o3/fetch.ccRepository: OpenXiangShan/GEM5 Length of output: 2988 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Find the initDecodeScheduler implementation
rg -n 'initDecodeScheduler' src/cpu/o3/fetch.cc -A 30Repository: OpenXiangShan/GEM5 Length of output: 2212 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Search for where delayedSchedulerDelay is set/initialized
rg -n 'delayedSchedulerDelay\s*=' src/cpu/o3/fetch.ccRepository: OpenXiangShan/GEM5 Length of output: 44 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Check the exact line in the header where delayedSchedulerDelay is declared
rg -n 'delayedSchedulerDelay' src/cpu/o3/fetch.hh -B 1 -A 1Repository: OpenXiangShan/GEM5 Length of output: 156
Line 399 of fetch.cc passes Suggested fix- int delayedSchedulerDelay;
+ int delayedSchedulerDelay = 0;📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||
| /** Fetch constructor. */ | ||||||||||||||||||||||||||||||||||||||||||||||
| Fetch(CPU *_cpu, const BaseO3CPUParams ¶ms); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -299,6 +312,12 @@ class Fetch | |||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| /** For priority-based fetch policies, need to keep update priorityList */ | ||||||||||||||||||||||||||||||||||||||||||||||
| void deactivateThread(ThreadID tid); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Function to initialize scheduler | ||||||||||||||||||||||||||||||||||||||||||||||
| void initDecodeScheduler(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Select a thread that is not fetch-blocked, using scheduler | ||||||||||||||||||||||||||||||||||||||||||||||
| ThreadID selectUnstalledThread(); | ||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||
| /** Reset this pipeline stage */ | ||||||||||||||||||||||||||||||||||||||||||||||
| void resetStage(); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the parameter description to match the new default selector.
At Line 93, the default is
SMTBasedSelector()but the text still says “default: age first”.Proposed fix
📝 Committable suggestion
🧰 Tools
🪛 Ruff (0.15.5)
[error] 93-93:
Parammay be undefined, or defined from star imports(F405)
🤖 Prompt for AI Agents