Skip to content

Commit f4a84b6

Browse files
committed
cpu-o3: add 3 types smt shceduler
Change-Id: I680c7c043c418db1a7046162686d319b5d3542bc
1 parent a0be485 commit f4a84b6

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

src/cpu/o3/smt_sched.hh

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#ifndef __GEM5_O3_SMT_SCHED_HH__
2+
#define __GEM5_O3_SMT_SCHED_HH__
3+
4+
5+
#include <vector>
6+
7+
#include <boost/circular_buffer.hpp>
8+
9+
#include "base/types.hh"
10+
#include "cpu/o3/limits.hh"
11+
12+
namespace gem5
13+
{
14+
15+
namespace o3
16+
{
17+
18+
class InstsCounter
19+
{
20+
// can be placed in ftq、rob、lsq、iq, etc. to count the number of instructions
21+
uint64_t counter[MaxThreads];
22+
public:
23+
InstsCounter() {
24+
for (int i = 0; i < MaxThreads; ++i) {
25+
counter[i] = 0;
26+
}
27+
}
28+
29+
uint64_t getCounter(ThreadID tid) { return counter[tid]; }
30+
void setCounter(ThreadID tid, uint64_t value) { counter[tid] = value; }
31+
};
32+
33+
class SMTScheduler
34+
{
35+
protected:
36+
int numThreads;
37+
public:
38+
SMTScheduler(int numThreads) : numThreads(numThreads) {}
39+
virtual ThreadID getThread();
40+
};
41+
42+
43+
class ICountScheduler : public SMTScheduler
44+
{
45+
// count of inst based smt shceduler
46+
protected:
47+
InstsCounter* counter;
48+
49+
public:
50+
ICountScheduler(int numThreads, InstsCounter* counter) : SMTScheduler(numThreads), counter(counter) {}
51+
52+
ThreadID getThread() override
53+
{
54+
// return the thread with the least number of instructions executed
55+
ThreadID selectedTid = 0;
56+
uint64_t minCount = counter->getCounter(0);
57+
for (ThreadID tid = 1; tid < numThreads; ++tid) {
58+
uint64_t count = counter->getCounter(tid);
59+
if (count < minCount) {
60+
minCount = count;
61+
selectedTid = tid;
62+
}
63+
}
64+
return selectedTid;
65+
}
66+
};
67+
68+
class DelayedICountScheduler : public ICountScheduler
69+
{
70+
// delayed count of inst based smt shceduler, which can be used to implement round-robin scheduling
71+
protected:
72+
boost::circular_buffer<ThreadID> timebuffer;
73+
74+
public:
75+
DelayedICountScheduler(int numThreads, InstsCounter* counter, int delay) : ICountScheduler(numThreads, counter)
76+
{
77+
timebuffer.set_capacity(delay);
78+
for (int i = 0; i < delay; ++i) {
79+
timebuffer.push_back(i % numThreads);
80+
}
81+
}
82+
83+
ThreadID getThread() override
84+
{
85+
// return the thread with the least number of instructions executed among the threads in the timebuffer
86+
ThreadID selectedTid = timebuffer.front();
87+
timebuffer.pop_front();
88+
timebuffer.push_back(ICountScheduler::getThread());
89+
return selectedTid;
90+
}
91+
};
92+
93+
94+
class MultiPrioritySched : public SMTScheduler
95+
{
96+
// multi priority based smt scheduler
97+
private:
98+
std::vector<InstsCounter*> counter;
99+
100+
public:
101+
// priority: higest -> lowest
102+
MultiPrioritySched(int numThreads, std::initializer_list<InstsCounter*> counters)
103+
: SMTScheduler(numThreads), counter(counters) {}
104+
105+
ThreadID getThread() override
106+
{
107+
// return the thread with the highest priority (lowest count) among the counters
108+
ThreadID selectedTid = 0;
109+
uint64_t minCount = counter[0]->getCounter(0);
110+
for (size_t i = 0; i < counter.size(); ++i) {
111+
for (ThreadID tid = 0; tid < numThreads; ++tid) {
112+
uint64_t count = counter[i]->getCounter(tid);
113+
if (count < minCount) {
114+
minCount = count;
115+
selectedTid = tid;
116+
}
117+
}
118+
}
119+
return selectedTid;
120+
}
121+
};
122+
123+
124+
125+
}}
126+
#endif

0 commit comments

Comments
 (0)