Skip to content

Commit 85d0254

Browse files
committed
wip
1 parent c0f804c commit 85d0254

File tree

3 files changed

+87
-72
lines changed

3 files changed

+87
-72
lines changed

src/cpu/o3/issue_queue.cc

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@
3636
selector->deallocate(x); \
3737
} while (0)
3838

39-
#define READYQ_PUSH(x) \
40-
do { \
41-
(x)->setInReadyQ(); \
42-
auto& readyQ = readyQclassify[(x)->opClass()]; \
43-
auto it = std::lower_bound(readyQ->begin(), readyQ->end(), (x), select_policy()); \
44-
readyQ->insert(it, (x)); \
45-
} while (0)
46-
4739
// must be consistent with FUScheduler.py
4840
// rfTypePortId = regfile typeid + portid
4941
#define MAXVAL_TYPEPORTID (1 << (2 + 4)) // [5:4] is typeid, [3:0] is portid
@@ -191,21 +183,18 @@ IssueQue::IssueQue(const IssueQueParams& params)
191183
iqsize(params.size),
192184
scheduleToExecDelay(params.scheduleToExecDelay),
193185
iqname(params.name),
194-
inflightIssues(scheduleToExecDelay, 0),
195186
selector(params.sel)
196187
{
197-
toIssue = inflightIssues.getWire(0);
198-
toFu = inflightIssues.getWire(-scheduleToExecDelay);
199188
if (outports > 8) {
200189
panic("%s: outports > 8 is not supported\n", iqname);
201190
}
191+
toIssue.resize(outports);
192+
toFu.resize(outports);
202193

203194
portBusy.resize(outports, 0);
204-
205195
intRdRfTPI.resize(outports);
206196
fpRdRfTPI.resize(outports);
207197
intWrRfTPI.resize(outports);
208-
209198
readyQs.resize(outports, nullptr);
210199

211200
readyQclassify.resize(Num_OpClasses, nullptr);
@@ -355,7 +344,6 @@ IssueQue::addToFu(const DynInstPtr& inst)
355344
void
356345
IssueQue::issueToFu()
357346
{
358-
int size = toFu->size;
359347
int replayed = 0;
360348
int issued = 0;
361349

@@ -393,8 +381,8 @@ IssueQue::issueToFu()
393381
issued++;
394382
}
395383

396-
for (int i = 0; i < size; i++) {
397-
auto inst = toFu->pop();
384+
for (int i = 0; i < outports; i++) {
385+
auto& inst = *toFu[i];
398386
if (!inst) {
399387
continue;
400388
}
@@ -409,7 +397,7 @@ IssueQue::issueToFu()
409397
(inst->isStore() && (issuedStore >= numStorePipe)) || blockLoad) {
410398
inst->clearScheduled();
411399
// only for load/store
412-
READYQ_PUSH(inst);
400+
readyQInsert(inst);
413401
DPRINTF(Schedule, "[sn:%llu] issue failed due to being occupied\n", inst->seqNum);
414402
continue;
415403
}
@@ -526,7 +514,7 @@ IssueQue::addIfReady(const DynInstPtr& inst)
526514
DPRINTF(Schedule, "[sn:%llu] add to readyInstsQue\n", inst->seqNum);
527515
inst->clearCancel();
528516
if (!inst->inReadyQ()) {
529-
READYQ_PUSH(inst);
517+
readyQInsert(inst);
530518
}
531519
}
532520
}
@@ -629,12 +617,12 @@ IssueQue::scheduleInst()
629617
iqstats->arbFailed++;
630618
assert(inst->readyToIssue());
631619

632-
READYQ_PUSH(inst);
620+
readyQInsert(inst);
633621
} else [[likely]] {
634622
DPRINTF(Schedule, "[sn:%llu] no conflict, scheduled\n", inst->seqNum);
635623
iqstats->portissued[pi]++;
636624
inst->setScheduled();
637-
toIssue->push(inst);
625+
*toIssue[pi] = inst;
638626
inst->issueportid = pi;
639627

640628
if (!opPipelined[inst->opClass()]) {
@@ -661,7 +649,6 @@ IssueQue::tick()
661649
instNumInsert = 0;
662650

663651
scheduleInst();
664-
inflightIssues.advance();
665652

666653
for (auto& t : portBusy) {
667654
t = t >> 1;
@@ -774,16 +761,6 @@ IssueQue::doSquash(const InstSeqNum seqNum)
774761
}
775762
}
776763

777-
for (int i = 0; i <= getIssueStages(); i++) {
778-
int size = inflightIssues[-i].size;
779-
for (int j = 0; j < size; j++) {
780-
auto& inst = inflightIssues[-i].insts[j];
781-
if (inst && inst->isSquashed()) {
782-
inst = nullptr;
783-
}
784-
}
785-
}
786-
787764
// clear in depGraph
788765
for (auto& entrys : subDepGraph) {
789766
for (auto it = entrys.begin(); it != entrys.end();) {
@@ -853,10 +830,13 @@ Scheduler::Scheduler(const SchedulerParams& params)
853830
int maxRdTypePortId = 0;
854831
int maxWrTypePortId = 0;
855832
for (int i = 0; i < issueQues.size(); i++) {
833+
auto iq = issueQues[i];
856834
issueQues[i]->setIQID(i);
857835
issueQues[i]->scheduler = this;
858-
combinedFus += issueQues[i]->outports;
859836
panic_if(issueQues[i]->fuDescs.size() == 0, "Empty config IssueQue: " + issueQues[i]->getName());
837+
for (int j = 0; j < iq->outports; j++) {
838+
inflightIssues.push_back(TimeBuffer<DynInstPtr>(0, iq->scheduleToExecDelay));
839+
}
860840
for (auto fu : issueQues[i]->fuDescs) {
861841
for (auto op : fu->opDescList) {
862842
opExecTimeTable[op->opClass] = op->opLat;
@@ -899,6 +879,13 @@ Scheduler::Scheduler(const SchedulerParams& params)
899879
}
900880
wrRfPortOccupancy.resize(maxWrTypePortId, {nullptr, 0, 0});
901881

882+
int portid = 0;
883+
for (auto iq : issueQues) {
884+
for (int i = 0; i < iq->outports; i++) {
885+
iq->setIssuePipe(inflightIssues[portid], i);
886+
portid++;
887+
}
888+
}
902889

903890
// dispatch distance counter allocate
904891
dispOpdist.resize(Num_OpClasses, nullptr);
@@ -1027,6 +1014,10 @@ Scheduler::tick()
10271014
for (auto it : issueQues) {
10281015
it->tick();
10291016
}
1017+
1018+
for (auto& it : inflightIssues) {
1019+
it.advance();
1020+
}
10301021
}
10311022

10321023
void
@@ -1392,14 +1383,11 @@ Scheduler::loadCancel(const DynInstPtr& inst)
13921383
}
13931384
}
13941385

1395-
for (auto iq : issueQues) {
1396-
for (int i = 0; i <= iq->getIssueStages(); i++) {
1397-
int size = iq->inflightIssues[-i].size;
1398-
for (int j = 0; j < size; j++) {
1399-
auto& inst = iq->inflightIssues[-i].insts[j];
1400-
if (inst && inst->canceled()) {
1401-
inst = nullptr;
1402-
}
1386+
for (auto& it : inflightIssues) {
1387+
for(int i = 0; i < it.getSize(); i++) {
1388+
auto& inst = it[i];
1389+
if (inst && inst->canceled()) {
1390+
inst = nullptr;
14031391
}
14041392
}
14051393
}
@@ -1500,6 +1488,15 @@ Scheduler::doSquash(const InstSeqNum seqNum)
15001488
for (auto it : issueQues) {
15011489
it->doSquash(seqNum);
15021490
}
1491+
1492+
for (auto& it : inflightIssues) {
1493+
for(int i = 0; i < it.getSize(); i++) {
1494+
auto& inst = it[i];
1495+
if (inst && inst->isSquashed()) {
1496+
inst = nullptr;
1497+
}
1498+
}
1499+
}
15031500
}
15041501

15051502
uint32_t

src/cpu/o3/issue_queue.hh

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,15 @@ class IssueQue : public SimObject
106106
friend class PAgeSelector;
107107

108108
std::string _name;
109+
public:
109110
const int inports;
110111
const int outports;
111112
const int iqsize;
112113
const int replayQsize = 32;
113114
const int scheduleToExecDelay;
114115
const std::string iqname;
116+
117+
private:
115118
std::vector<std::bitset<Num_OpClasses>> portFuDescs;
116119
std::vector<FUDesc*> fuDescs;
117120
std::vector<bool> opPipelined;
@@ -133,10 +136,8 @@ class IssueQue : public SimObject
133136
DynInstPtr pop();
134137
};
135138

136-
std::vector<DynInstPtr> skidBuffer;
137-
TimeBuffer<IssueStream> inflightIssues;
138-
TimeBuffer<IssueStream>::wire toIssue;
139-
TimeBuffer<IssueStream>::wire toFu;
139+
std::vector<TimeBuffer<DynInstPtr>::wire> toIssue;
140+
std::vector<TimeBuffer<DynInstPtr>::wire> toFu;
140141

141142
std::list<DynInstPtr> instList;
142143
uint64_t instNumInsert = 0;
@@ -196,9 +197,20 @@ class IssueQue : public SimObject
196197
void scheduleInst();
197198
void addIfReady(const DynInstPtr& inst);
198199
void cancel(const DynInstPtr& inst);
200+
inline void readyQInsert(const DynInstPtr& x) {
201+
x->setInReadyQ();
202+
auto& readyQ = readyQclassify[x->opClass()];
203+
auto it = std::lower_bound(readyQ->begin(), readyQ->end(), x, select_policy());
204+
readyQ->insert(it, x);
205+
}
206+
199207

200208
public:
201209
inline void clearBusy(uint32_t pi) { portBusy.at(pi) = 0; }
210+
inline void setIssuePipe(TimeBuffer<DynInstPtr>& issuepipe, int pi) {
211+
toIssue[pi] = issuepipe.getWire(scheduleToExecDelay);
212+
toFu[pi] = issuepipe.getWire(0);
213+
}
202214

203215
IssueQue(const IssueQueParams& params);
204216
void setIQID(int id) { IQID = id; }
@@ -288,11 +300,12 @@ class Scheduler : public SimObject
288300
std::vector<IQGroup> dispTable;
289301
std::vector<IssueQue*> issueQues;
290302
std::vector<std::vector<IssueQue*>> wakeMatrix;
291-
uint32_t combinedFus;
292303

293304
std::vector<uint8_t> totalDispCounter;
294305
std::vector<uint8_t*> dispOpdist;
295306

307+
// Centralized management
308+
std::vector<TimeBuffer<DynInstPtr>> inflightIssues;
296309
std::vector<DynInstPtr> instsToFu;
297310

298311
std::vector<bool> earlyScoreboard;

src/cpu/timebuf.hh

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ template <class T>
4040
class TimeBuffer
4141
{
4242
protected:
43-
int past;
44-
int future;
45-
unsigned size;
46-
int _id;
47-
48-
char *data;
49-
std::vector<char *> index;
50-
unsigned base;
43+
int _id = -1;
44+
int past = 0;
45+
int future = 0;
46+
unsigned size = 0;
47+
unsigned base = 0;
48+
T* datas = nullptr;
5149

5250
void valid(int idx) const
5351
{
@@ -138,31 +136,38 @@ class TimeBuffer
138136

139137
public:
140138
TimeBuffer(int p, int f)
141-
: past(p), future(f), size(past + future + 1),
142-
data(new char[size * sizeof(T)]), index(size), base(0)
139+
: past(p), future(f), size(past + future + 1)
143140
{
144141
assert(past >= 0 && future >= 0);
145-
char *ptr = data;
142+
datas = (T*)new char[sizeof(T) * size];
143+
std::memset((void*)datas, 0, sizeof(T) * size);
146144
for (unsigned i = 0; i < size; i++) {
147-
index[i] = ptr;
148-
std::memset(ptr, 0, sizeof(T));
149-
new (ptr) T;
150-
ptr += sizeof(T);
145+
new (datas + i) T;
151146
}
152-
153147
_id = -1;
154148
}
155149

156-
TimeBuffer()
157-
: data(NULL)
150+
TimeBuffer() {}
151+
152+
TimeBuffer(const TimeBuffer<T> &other)
153+
: _id(other._id), past(other.past), future(other.future), size(other.size), base(other.base)
154+
{
155+
datas = new T[size];
156+
for (unsigned i = 0; i < size; i++) {
157+
datas[i] = other.datas[i]; // must use explicit copy to handle non-POD types
158+
}
159+
}
160+
161+
TimeBuffer(TimeBuffer<T> &&other) noexcept
162+
: _id(other._id), past(other.past), future(other.future), size(other.size), base(other.base), datas(other.datas)
158163
{
164+
// Null out the other datas pointer to avoid double deletion
165+
other.datas = nullptr;
159166
}
160167

161168
~TimeBuffer()
162169
{
163-
for (unsigned i = 0; i < size; ++i)
164-
(reinterpret_cast<T *>(index[i]))->~T();
165-
delete [] data;
170+
delete [] datas;
166171
}
167172

168173
void id(int id)
@@ -184,9 +189,9 @@ class TimeBuffer
184189
int ptr = base + future;
185190
if (ptr >= (int)size)
186191
ptr -= size;
187-
(reinterpret_cast<T *>(index[ptr]))->~T();
188-
std::memset(index[ptr], 0, sizeof(T));
189-
new (index[ptr]) T;
192+
datas[ptr].~T();
193+
std::memset((void*)(datas + ptr), 0, sizeof(T));
194+
new (datas + ptr) T;
190195
}
191196

192197
protected:
@@ -212,21 +217,21 @@ class TimeBuffer
212217
{
213218
int vector_index = calculateVectorIndex(idx);
214219

215-
return reinterpret_cast<T *>(index[vector_index]);
220+
return datas + vector_index;
216221
}
217222

218223
T &operator[](int idx)
219224
{
220225
int vector_index = calculateVectorIndex(idx);
221226

222-
return reinterpret_cast<T &>(*index[vector_index]);
227+
return datas[vector_index];
223228
}
224229

225230
const T &operator[] (int idx) const
226231
{
227232
int vector_index = calculateVectorIndex(idx);
228233

229-
return reinterpret_cast<const T &>(*index[vector_index]);
234+
return datas[vector_index];
230235
}
231236

232237
wire getWire(int idx)

0 commit comments

Comments
 (0)