-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathissue_queue.cc
More file actions
1521 lines (1355 loc) · 45.6 KB
/
issue_queue.cc
File metadata and controls
1521 lines (1355 loc) · 45.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "cpu/o3/issue_queue.hh"
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include "base/logging.hh"
#include "base/stats/group.hh"
#include "base/stats/info.hh"
#include "base/trace.hh"
#include "base/types.hh"
#include "cpu/func_unit.hh"
#include "cpu/inst_seq.hh"
#include "cpu/o3/dyn_inst.hh"
#include "cpu/o3/dyn_inst_ptr.hh"
#include "cpu/reg_class.hh"
#include "debug/Counters.hh"
#include "debug/Dispatch.hh"
#include "debug/Schedule.hh"
#include "enums/OpClass.hh"
#include "params/BaseO3CPU.hh"
#include "sim/eventq.hh"
#include "sim/sim_object.hh"
#define POPINST(x) \
do { \
assert(instNum != 0); \
assert((*instNumClassify[x->opClass()]) != 0); \
(*instNumClassify[x->opClass()])--; \
instNum--; \
selector->deallocate(x); \
} while (0)
// must be consistent with FUScheduler.py
// rfTypePortId = regfile typeid + portid
#define MAXVAL_TYPEPORTID (1 << (2 + 4)) // [5:4] is typeid, [3:0] is portid
#define RF_GET_PRIORITY(x) ((x)&0b11)
#define RF_GET_TYPEPORTID(x) (((x) >> 2) & 0b111111)
#define RF_GET_PORTID(x) (((x) >> 2) & 0b1111)
#define RF_GET_TYPEID(x) (((x) >> 6) & 0b11)
#define RF_GET_RDWR(x) (((x) >> 8) & 0b1)
#define RF_MAKE_TYPEPORTID(t, p) (((t) << 4) | (p))
#define RF_INTID 0
#define RF_FPID 1
namespace gem5
{
namespace o3
{
IssuePort::IssuePort(const IssuePortParams& params) : SimObject(params), rp(params.rp), fu(params.fu)
{
for (auto it0 : params.fu) {
for (auto it1 : it0->opDescList) {
opbits.set(it1->opClass);
}
}
}
ReadyQue::iterator
BaseSelector::select(ReadyQue::iterator begin, int portid)
{
// return the oldest
return begin;
}
void
PAgeSelector::setparent(Scheduler* scheduler, IssueQue* iq)
{
BaseSelector::setparent(scheduler, iq);
panic_if(iq->iqsize % numInstperGroup != 0,
"POldSelector: IssueQue size % numInstperGroup != 0, "
"size: %d, numInstperGroup: %d\n",
iq->iqsize, numInstperGroup);
iqselectQ = &iq->selectQ;
for (int i = 0; i < iq->iqsize; i++) {
freelist.push_back(i);
}
}
void
PAgeSelector::allocate(const DynInstPtr& inst)
{
assert(!freelist.empty());
inst->iqtag = freelist.front();
freelist.pop_front();
}
void
PAgeSelector::deallocate(const DynInstPtr& inst)
{
assert(inst->iqtag >= 0 && inst->iqtag < (int)freelist.size());
freelist.push_back(inst->iqtag);
inst->iqtag = -1; // reset
}
ReadyQue::iterator
PAgeSelector::select(ReadyQue::iterator begin, int portid)
{
if (iqselectQ->empty()) {
// first one is oldest
return begin;
} else {
// TODO: speed the searching up
for (auto it = begin; it != end; it++) {
auto& inst = *it;
bool no_group_conflict = true;
for (auto sit = iqselectQ->begin(); sit != iqselectQ->end(); sit++) {
// check group conflict
if ((inst->iqtag % numInstperGroup) == (sit->second->iqtag % numInstperGroup)) {
no_group_conflict = false;
break;
}
}
if (no_group_conflict) {
return it;
}
}
return end;
}
}
bool
IssueQue::select_policy::operator()(const DynInstPtr& a, const DynInstPtr& b) const
{
return a->seqNum < b->seqNum;
}
void
IssueQue::IssueStream::push(const DynInstPtr& inst)
{
assert(size < 8);
insts[size++] = inst;
}
DynInstPtr
IssueQue::IssueStream::pop()
{
assert(size > 0);
return insts[--size];
}
IssueQue::IssueQueStats::IssueQueStats(statistics::Group* parent, IssueQue* que, std::string name)
: Group(parent, name.c_str()),
ADD_STAT(retryMem, statistics::units::Count::get(), "count of load/store retry"),
ADD_STAT(canceledInst, statistics::units::Count::get(), "count of canceled insts"),
ADD_STAT(loadmiss, statistics::units::Count::get(), "count of load miss"),
ADD_STAT(arbFailed, statistics::units::Count::get(), "count of arbitration failed"),
ADD_STAT(tagRefillBlock, statistics::units::Count::get(), "count of blocked due to tag refill"),
ADD_STAT(issueOccupy, statistics::units::Count::get(), "count of replayQ blocked"),
ADD_STAT(insertDist, statistics::units::Count::get(), "distruibution of insert"),
ADD_STAT(issueDist, statistics::units::Count::get(), "distruibution of issue"),
ADD_STAT(portissued, statistics::units::Count::get(), "count each port issues"),
ADD_STAT(portBusy, statistics::units::Count::get(), "count each port busy cycles"),
ADD_STAT(avgInsts, statistics::units::Count::get(), "average insts")
{
insertDist.init(que->inports + 1).flags(statistics::nozero);
issueDist.init(que->outports + 1).flags(statistics::nozero);
portissued.init(que->outports).flags(statistics::nozero);
portBusy.init(que->outports).flags(statistics::nozero);
retryMem.flags(statistics::nozero);
canceledInst.flags(statistics::nozero);
loadmiss.flags(statistics::nozero);
arbFailed.flags(statistics::nozero);
issueOccupy.flags(statistics::nozero);
}
IssueQue::IssueQue(const IssueQueParams& params)
: SimObject(params),
inports(params.inports),
outports(params.oports.size()),
iqsize(params.size),
scheduleToExecDelay(params.scheduleToExecDelay),
iqname(params.name),
selector(params.sel)
{
if (outports > 8) {
panic("%s: outports > 8 is not supported\n", iqname);
}
toIssue.resize(outports);
toFu.resize(outports);
portBusy.resize(outports, 0);
intRdRfTPI.resize(outports);
fpRdRfTPI.resize(outports);
intWrRfTPI.resize(outports);
readyQs.resize(outports, nullptr);
readyQclassify.resize(Num_OpClasses, nullptr);
instNumClassify.resize(enums::Num_OpClass, nullptr);
opPipelined.resize(Num_OpClasses, false);
std::unordered_map<std::bitset<Num_OpClasses>, std::pair<ReadyQue*, uint8_t*>> readyQmap;
for (int i = 0; i < outports; i++) {
auto oport = params.oports[i];
int wr_pri = -1;
for (auto rfp : oport->rp) {
int rf_type = RF_GET_TYPEID(rfp);
int rf_portPri = RF_GET_PRIORITY(rfp);
int is_wr = RF_GET_RDWR(rfp);
int rf_typeportid = RF_GET_TYPEPORTID(rfp);
assert(rf_portPri < (1 << 2)); // 2 bits for priority
assert(rf_typeportid < (1 << 6)); // 6 bits for typeportid
auto rf_typeportid_pair = std::make_pair(rf_typeportid, rf_portPri);
if (is_wr) {
if (rf_type == RF_INTID) {
intWrRfTPI[i].push_back(rf_typeportid_pair);
} else {
panic("%s: Unknown write RF type %d\n", iqname, rf_type);
}
if (rf_portPri > 1) {
panic("Num of write arbitration RF port greater than 2 are not supported \n");
}
wr_pri = rf_portPri;
} else {
if (rf_type == RF_INTID) {
intRdRfTPI[i].push_back(rf_typeportid_pair);
} else if (rf_type == RF_FPID) {
fpRdRfTPI[i].push_back(rf_typeportid_pair);
} else {
panic("%s: Unknown RF type %d\n", iqname, rf_type);
}
}
if (wr_pri != -1 && wr_pri != rf_portPri) {
// if has write RF, all read RF must have the same priority
panic("%s: Found write RF priority with different other's priority\n", iqname);
}
}
// safety check for outports
for (int j = i + 1; j < outports; j++) {
if ((oport->opbits != params.oports[j]->opbits) && (oport->opbits & params.oports[j]->opbits).any()) {
panic("%s: Found the same opClass in different FU, portid: %d and %d\n", iqname, i, j);
}
}
fuDescs.insert(fuDescs.begin(), oport->fu.begin(), oport->fu.end());
portFuDescs.push_back(oport->opbits);
auto it = readyQmap.find(oport->opbits);
ReadyQue* readyQ = nullptr;
uint8_t* counter = nullptr;
if (it == readyQmap.end()) {
// create a new ReadyQue
readyQ = new ReadyQue;
counter = new uint8_t(0);
readyQmap[oport->opbits] = std::make_pair(readyQ, counter);
} else {
// use the existing one
readyQ = it->second.first;
counter = it->second.second;
}
readyQs[i] = readyQ;
bool storePipeAcc = false, loadPipeAcc = false;
for (auto fu : oport->fu) {
for (auto op : fu->opDescList) {
readyQclassify[op->opClass] = readyQ;
instNumClassify[op->opClass] = counter;
opPipelined[op->opClass] = op->pipelined;
if (op->opClass >= MemReadOp && op->opClass <= VectorWholeRegisterLoadOp) {
loadPipeAcc = true;
}
if (op->opClass >= MemWriteOp && op->opClass <= VectorWholeRegisterStoreOp) {
storePipeAcc = true;
}
}
}
if (loadPipeAcc)
numLoadPipe++;
if (storePipeAcc)
numStorePipe++;
}
}
void
IssueQue::setCPU(CPU* cpu)
{
this->cpu = cpu;
_name = cpu->name() + ".scheduler." + getName();
iqstats = new IssueQueStats(cpu, this, "scheduler." + this->getName());
}
void
IssueQue::resetDepGraph(int numPhysRegs)
{
subDepGraph.resize(numPhysRegs);
}
bool
IssueQue::checkScoreboard(const DynInstPtr& inst)
{
for (int i = 0; i < inst->numSrcRegs(); i++) {
auto src = inst->renamedSrcIdx(i);
if (src->isFixedMapping()) [[unlikely]] {
continue;
}
// check bypass data ready or not
if (!scheduler->bypassScoreboard[src->flatIndex()]) [[unlikely]] {
auto dst_inst = scheduler->getInstByDstReg(src->flatIndex());
assert(dst_inst);
if (!dst_inst->isLoad()) panic("dst[sn:%llu] is not load", dst_inst->seqNum);
warn_once(
"Tt's should not happen on classic cache, it may be wrong delay of load wake or missed loadcancel in "
"lsq\n");
DPRINTF(Schedule, "[sn:%llu] %s can't get data from bypassNetwork, dst inst: %s\n", inst->seqNum,
inst->srcRegIdx(i), dst_inst->genDisassembly());
scheduler->loadCancel(dst_inst);
return false;
}
}
return true;
}
void
IssueQue::addToFu(const DynInstPtr& inst)
{
if (inst->isIssued()) [[unlikely]] {
panic("%s [sn:%llu] has alreayd been issued\n", enums::OpClassStrings[inst->opClass()], inst->seqNum);
}
inst->setIssued();
POPINST(inst);
scheduler->addToFU(inst);
}
void
IssueQue::issueToFu()
{
int replayed = 0;
int issued = 0;
int issuedLoad = 0;
int issuedStore = 0;
bool incTagRefillBlockStats = false;
// replay first
for (; !replayQ.empty() && replayed < outports; replayed++) {
auto& inst = replayQ.front();
if (inst->isLoad()) {
// Check if tag write is happening in the next cycle
// if so, load cannot be issued to load pipeline
if (scheduler->lsq->isDcacheRefillTagWrite()) {
incTagRefillBlockStats = true;
break;
}
if (issuedLoad >= numLoadPipe) {
break;
}
issuedLoad++;
}
if (inst->isStore()) {
if (issuedStore >= numStorePipe) {
break;
}
issuedStore++;
}
scheduler->addToFU(inst);
DPRINTF(Schedule, "[sn:%llu] replayed to FU\n", inst->seqNum);
replayQ.pop();
issued++;
}
for (int i = 0; i < outports; i++) {
auto& inst = *toFu[i];
if (!inst) {
continue;
}
// Check if tag write is happening in the next cycle
// if so, load cannot be issued to load pipeline
bool blockLoad = inst->isLoad() && scheduler->lsq->isDcacheRefillTagWrite();
if (blockLoad) {
incTagRefillBlockStats = true;
}
if ((i + replayed >= outports) || (inst->isLoad() && (issuedLoad >= numLoadPipe)) ||
(inst->isStore() && (issuedStore >= numStorePipe)) || blockLoad) {
inst->clearScheduled();
// only for load/store
readyQInsert(inst);
DPRINTF(Schedule, "[sn:%llu] issue failed due to being occupied\n", inst->seqNum);
continue;
}
if (!checkScoreboard(inst)) {
continue;
}
if (inst->isLoad()) {
issuedLoad++;
}
if (inst->isStore()) {
issuedStore++;
}
addToFu(inst);
cpu->perfCCT->updateInstPos(inst->seqNum, PerfRecord::AtIssueReadReg);
issued++;
}
if (issued > 0) {
iqstats->issueDist[issued]++;
}
if (replayed) {
iqstats->issueOccupy += replayed;
}
if (incTagRefillBlockStats) {
iqstats->tagRefillBlock++;
}
}
void
IssueQue::retryMem(const DynInstPtr& inst)
{
assert(!inst->isNonSpeculative());
iqstats->retryMem++;
DPRINTF(Schedule, "retry %s [sn:%llu]\n", enums::OpClassStrings[inst->opClass()], inst->seqNum);
replayQ.push(inst);
}
bool
IssueQue::idle()
{
bool idle = false;
for (auto it : readyQs) {
if (it->size()) {
idle = true;
}
}
idle |= replayQ.size() > 0;
return idle;
}
void
IssueQue::markMemDepDone(const DynInstPtr& inst)
{
assert(inst->isMemRef());
DPRINTF(Schedule, "[sn:%llu] has solved memdependency\n", inst->seqNum);
inst->setMemDepDone();
addIfReady(inst);
}
void
IssueQue::wakeUpDependents(const DynInstPtr& inst, bool speculative)
{
if (speculative && inst->canceled()) [[unlikely]] {
return;
}
for (int i = 0; i < inst->numDestRegs(); i++) {
PhysRegIdPtr dst = inst->renamedDestIdx(i);
if (dst->isFixedMapping() || dst->getNumPinnedWritesToComplete() != 1) [[unlikely]] {
continue;
}
scheduler->regCache.insert(dst->flatIndex(), {});
DPRINTF(Schedule, "was %s woken by p%lu [sn:%llu]\n", speculative ? "spec" : "wb", dst->flatIndex(),
inst->seqNum);
auto& depgraph = subDepGraph[dst->flatIndex()];
for (auto& it : depgraph) {
int srcIdx = it.first;
auto& consumer = it.second;
if (consumer->readySrcIdx(srcIdx)) {
continue;
}
consumer->markSrcRegReady(srcIdx);
DPRINTF(Schedule, "[sn:%llu] src%d was woken\n", consumer->seqNum, srcIdx);
addIfReady(consumer);
}
if (!speculative) {
depgraph.clear();
}
}
}
void
IssueQue::addIfReady(const DynInstPtr& inst)
{
if (inst->readyToIssue()) {
if (inst->readyTick == -1) {
inst->readyTick = curTick();
DPRINTF(Counters, "set readyTick at addIfReady\n");
}
// Add the instruction to the proper ready list.
if (inst->isMemRef()) {
if (inst->memDepSolved()) {
DPRINTF(Schedule, "memRef Dependency was solved can issue\n");
} else {
DPRINTF(Schedule, "memRef Dependency was not solved can't issue\n");
return;
}
}
DPRINTF(Schedule, "[sn:%llu] add to readyInstsQue\n", inst->seqNum);
inst->clearCancel();
if (!inst->inReadyQ()) {
readyQInsert(inst);
}
}
}
void
IssueQue::cancel(const DynInstPtr& inst)
{
// before issued
assert(!inst->isIssued());
inst->setCancel();
if (inst->isScheduled() && !opPipelined[inst->opClass()]) {
inst->clearScheduled();
portBusy[inst->issueportid] = 0;
}
iqstats->canceledInst++;
}
void
IssueQue::selectInst()
{
selectQ.clear();
for (int pi = 0; pi < outports; pi++) {
auto readyQ = readyQs[pi];
selector->begin(readyQ);
for (auto it = selector->select(readyQ->begin(), pi); it != readyQ->end(); it = selector->select(it, pi)) {
auto& inst = *it;
if (inst->canceled()) {
inst->clearInReadyQ();
it = readyQ->erase(it);
continue;
}
int lat = scheduler->getCorrectedOpLat(inst);
uint64_t busy_bit = (lat > 63 ? -1 : (1llu << lat));
if (!(portBusy[pi] & busy_bit)) {
DPRINTF(Schedule, "[sn %ld] was selected\n", inst->seqNum);
// get regfile write port
for (int i = 0; i < inst->numDestRegs(); i++) {
auto pdst = inst->renamedDestIdx(i);
if (pdst->isFixedMapping()) [[unlikely]]
continue;
std::pair<int, int> rfTypePortId;
// write port is point to point with dstid
if (pdst->isIntReg() && intWrRfTPI[pi].size() > i) {
rfTypePortId = intWrRfTPI[pi][i];
scheduler->useRfWrPort(inst, pdst, rfTypePortId.first, rfTypePortId.second);
}
}
// get regfile read port
for (int i = 0; i < inst->numSrcRegs(); i++) {
PhysRegIdPtr psrc = inst->renamedSrcIdx(i);
if (psrc->isFixedMapping())
continue;
std::pair<int, int> rfTypePortId;
// read port is point to point with srcid
if (psrc->isIntReg() && intRdRfTPI[pi].size() > i) {
// TX dynamic port optimization: src1 can borrow src0's port if src0 is in regcache
if (enableMainRdpOpt && i == 1 &&
scheduler->regCache.contains(inst->renamedSrcIdx(0)->flatIndex())) {
rfTypePortId = intRdRfTPI[pi][0]; // borrow src0's port
} else {
rfTypePortId = intRdRfTPI[pi][i];
}
scheduler->useRfRdPort(inst, psrc, rfTypePortId.first, rfTypePortId.second);
} else if (psrc->isFloatReg() && fpRdRfTPI[pi].size() > i) {
rfTypePortId = fpRdRfTPI[pi][i];
scheduler->useRfRdPort(inst, psrc, rfTypePortId.first, rfTypePortId.second);
}
}
selectQ.push_back(std::make_pair(pi, inst));
inst->clearInReadyQ();
readyQ->erase(it);
break;
} else {
iqstats->portBusy[pi]++;
}
it++;
}
}
}
void
IssueQue::scheduleInst()
{
// here is issueStage 0
for (auto& info : selectQ) {
auto& pi = info.first; // issue port id
auto& inst = info.second;
if (inst->canceled()) {
DPRINTF(Schedule, "[sn:%llu] was canceled\n", inst->seqNum);
} else if (inst->arbFailed()) {
DPRINTF(Schedule, "[sn:%llu] arbitration failed, retry\n", inst->seqNum);
iqstats->arbFailed++;
assert(inst->readyToIssue());
readyQInsert(inst);
} else [[likely]] {
DPRINTF(Schedule, "[sn:%llu] no conflict, scheduled\n", inst->seqNum);
iqstats->portissued[pi]++;
inst->setScheduled();
*toIssue[pi] = inst;
inst->issueportid = pi;
if (!opPipelined[inst->opClass()]) {
portBusy[pi] = -1ll;
} else if (scheduler->getCorrectedOpLat(inst) > 1) {
portBusy[pi] |= 1ll << scheduler->getCorrectedOpLat(inst);
}
scheduler->specWakeUpDependents(inst, this);
cpu->perfCCT->updateInstPos(inst->seqNum, PerfRecord::AtIssueArb);
}
inst->clearArbFailed();
}
}
void
IssueQue::tick()
{
iqstats->avgInsts = instNum;
if (instNumInsert > 0) {
iqstats->insertDist[instNumInsert]++;
}
instNumInsert = 0;
scheduleInst();
for (auto& t : portBusy) {
t = t >> 1;
}
}
bool
IssueQue::ready()
{
bool bwFull = instNumInsert >= inports;
bool full = (instNum >= iqsize) || (replayQ.size() > replayQsize);
if (bwFull) {
DPRINTF(Schedule, "can't insert more due to inports exhausted\n");
}
if (full) {
DPRINTF(Schedule, "has full!\n");
}
return !full && !bwFull;
}
void
IssueQue::insert(const DynInstPtr& inst)
{
assert(instNum < iqsize);
(*instNumClassify[inst->opClass()])++;
instNum++;
instNumInsert++;
cpu->perfCCT->updateInstPos(inst->seqNum, PerfRecord::AtIssueQue);
DPRINTF(Schedule, "[sn:%llu] %s insert into %s\n", inst->seqNum, enums::OpClassStrings[inst->opClass()], iqname);
selector->allocate(inst);
inst->issueQue = this;
instList.emplace_back(inst);
bool addToDepGraph = false;
for (int i = 0; i < inst->numSrcRegs(); i++) {
auto src = inst->renamedSrcIdx(i);
if (!inst->readySrcIdx(i) && !src->isFixedMapping()) {
if (scheduler->scoreboard[src->flatIndex()]) {
inst->markSrcRegReady(i);
} else {
if (scheduler->earlyScoreboard[src->flatIndex()]) {
inst->markSrcRegReady(i);
}
DPRINTF(Schedule, "[sn:%llu] src p%d add to depGraph\n", inst->seqNum, src->flatIndex());
subDepGraph[src->flatIndex()].push_back({i, inst});
addToDepGraph = true;
}
}
}
if (!addToDepGraph) {
assert(inst->readyToIssue());
}
/** For memory-related instructions, memory dependency prediction is
* used to determine whether they can be out of order execution.
* -- pass the dependency check: instruction can be schedule.
* -- failed in dependency check: schedule in the store address be computered.
*/
if (inst->isMemRef()) {
// insert and check memDep
scheduler->memDepUnit[inst->threadNumber].insert(inst);
} else {
addIfReady(inst);
}
}
void
IssueQue::insertNonSpec(const DynInstPtr& inst)
{
DPRINTF(Schedule, "[sn:%llu] insertNonSpec into %s\n", inst->seqNum, iqname);
inst->issueQue = this;
if (inst->isMemRef()) {
scheduler->memDepUnit[inst->threadNumber].insertNonSpec(inst);
}
}
void
IssueQue::doCommit(const InstSeqNum seqNum)
{
while (!instList.empty() && instList.front()->seqNum <= seqNum) {
assert(instList.front()->isIssued());
instList.pop_front();
}
}
void
IssueQue::doSquash(const InstSeqNum seqNum)
{
for (auto it = instList.begin(); it != instList.end();) {
if ((*it)->seqNum > seqNum) {
if (!(*it)->isIssued()) {
POPINST((*it));
(*it)->setIssued();
}
if ((*it)->isScheduled() && (*it)->issueportid >= 0 && !opPipelined[(*it)->opClass()]) {
portBusy.at((*it)->issueportid) = 0;
}
(*it)->setSquashedInIQ();
(*it)->setCanCommit();
(*it)->clearScheduled();
(*it)->setCancel();
it = instList.erase(it);
assert(instList.size() >= instNum);
} else {
it++;
}
}
// clear in depGraph
for (auto& entrys : subDepGraph) {
for (auto it = entrys.begin(); it != entrys.end();) {
if ((*it).second->isSquashed()) {
it = entrys.erase(it);
} else {
it++;
}
}
}
}
Scheduler::SpecWakeupCompletion::SpecWakeupCompletion(const DynInstPtr& inst, IssueQue* to,
PendingWakeEventsType* owner)
: Event(Stat_Event_Pri, AutoDelete), inst(inst), owner(owner), to_issue_queue(to)
{
}
void
Scheduler::SpecWakeupCompletion::process()
{
to_issue_queue->wakeUpDependents(inst, true);
(*owner)[inst->seqNum].erase(this);
}
const char*
Scheduler::SpecWakeupCompletion::description() const
{
return "Spec wakeup completion";
}
Scheduler::SchedulerStats::SchedulerStats(statistics::Group* parent)
: statistics::Group(parent),
ADD_STAT(exec_stall_cycle, "SUM(OpsExecuted[= FEW])"),
ADD_STAT(memstall_any_load,
"Cycles with no uops executed and at least X in-flight load that is not completed yet"),
ADD_STAT(memstall_any_store, "Cycles with few uops executed and no more stores can be issued"),
ADD_STAT(memstall_l1miss,
"Cycles with no uops executed and at least X in-flight load that has missed the L1-cache"),
ADD_STAT(memstall_l2miss,
"Cycles with no uops executed and at least X in-flight load that has missed the L2-cache"),
ADD_STAT(memstall_l3miss,
"Cycles with no uops executed and at least X in-flight load that has missed the L3-cache")
{
}
bool
Scheduler::disp_policy::operator()(IssueQue* a, IssueQue* b) const
{
// initNum smaller first
int p0 = *a->instNumClassify[disp_op];
int p1 = *b->instNumClassify[disp_op];
return p0 < p1;
}
Scheduler::Scheduler(const SchedulerParams& params)
: SimObject(params), old_disp(params.useOldDisp),
intRegfileBanks(params.intRegfileBanks), stats(this), issueQues(params.IQs)
{
dispTable.resize(enums::OpClass::Num_OpClass);
opExecTimeTable.resize(enums::OpClass::Num_OpClass, 1);
opPipelined.resize(enums::OpClass::Num_OpClass, false);
boost::dynamic_bitset<> opChecker(enums::Num_OpClass, 0);
std::vector<int> rdRfportChecker(MAXVAL_TYPEPORTID, 0);
std::vector<int> wrRfportChecker(MAXVAL_TYPEPORTID, 0);
int maxRdTypePortId = 0;
int maxWrTypePortId = 0;
for (int i = 0; i < issueQues.size(); i++) {
auto iq = issueQues[i];
issueQues[i]->setIQID(i);
issueQues[i]->scheduler = this;
panic_if(issueQues[i]->fuDescs.size() == 0, "Empty config IssueQue: " + issueQues[i]->getName());
for (int j = 0; j < iq->outports; j++) {
inflightIssues.push_back(TimeBuffer<DynInstPtr>(0, iq->scheduleToExecDelay));
}
for (auto fu : issueQues[i]->fuDescs) {
for (auto op : fu->opDescList) {
opExecTimeTable[op->opClass] = op->opLat;
opPipelined[op->opClass] = op->pipelined;
dispTable[op->opClass].push_back(issueQues[i]);
opChecker.set(op->opClass);
}
}
// read port check
for (auto& rfTypePortId : issueQues[i]->intRdRfTPI) {
for (auto& typePortId : rfTypePortId) {
maxRdTypePortId = std::max(maxRdTypePortId, typePortId.first);
rdRfportChecker[typePortId.first] += 1;
}
}
for (auto& rfTypePortId : issueQues[i]->fpRdRfTPI) {
for (auto& typePortId : rfTypePortId) {
maxRdTypePortId = std::max(maxRdTypePortId, typePortId.first);
rdRfportChecker[typePortId.first] += 1;
}
}
// write port check
for (auto& rfTypePortId : issueQues[i]->intWrRfTPI) {
for (auto& typePortId : rfTypePortId) {
maxWrTypePortId = std::max(maxWrTypePortId, typePortId.first);
wrRfportChecker[typePortId.first] += 1;
}
}
}
maxRdTypePortId += 1;
maxWrTypePortId += 1;
assert(maxRdTypePortId <= MAXVAL_TYPEPORTID);
assert(maxWrTypePortId <= MAXVAL_TYPEPORTID);
rdRfPortOccupancy.resize(intRegfileBanks);
for (int i = 0; i < intRegfileBanks; i++) {
rdRfPortOccupancy[i].resize(maxRdTypePortId, {nullptr, 0});
}
wrRfPortOccupancy.resize(maxWrTypePortId, {nullptr, 0, 0});
int portid = 0;
for (auto iq : issueQues) {
for (int i = 0; i < iq->outports; i++) {
iq->setIssuePipe(inflightIssues[portid], i);
portid++;
}
}
// dispatch distance counter allocate
dispOpdist.resize(Num_OpClasses, nullptr);
totalDispCounter.reserve(Num_OpClasses);
std::vector<std::vector<OpClass>> reuse_table;
for (int i = 0; i < Num_OpClasses; i++) {
bool counter_reuse = false;
int reuse_op = 0;
for (int j = 0; j < Num_OpClasses; j++) {
if (dispTable[i] == dispTable[j]) {
counter_reuse = true;
reuse_op = j; // op "i" can reuse the "j" counter
break;
}
}
if (counter_reuse && dispOpdist[reuse_op]) {
dispOpdist[i] = dispOpdist[reuse_op];
} else {
totalDispCounter.push_back(0);
dispOpdist[i] = &totalDispCounter.back();
reuse_table.push_back(std::vector<OpClass>());
}
reuse_table.back().push_back((OpClass)i);
}
for (auto it : reuse_table) {
std::cout << "Dispatch Grouping: ";
for (auto op : it) {
std::cout << enums::OpClassStrings[op] << " ";
}
std::cout << std::endl;
}
// Set TX dynamic read port optimization for all IssueQues
setMainRdpOpt(params.enableMainRdpOpt);
if (opChecker.count() != enums::Num_OpClass) {
for (int i = 0; i < enums::Num_OpClass; i++) {
if (!opChecker[i]) {
warn("No config for opClass: %s\n", enums::OpClassStrings[i]);
}
}
}
wakeMatrix.resize(issueQues.size());
auto findIQbyname = [this](std::string name) -> IssueQue* {
IssueQue* ret = nullptr;
for (auto it : this->issueQues) {
if (it->getName().compare(name) == 0) {
if (ret) {
panic("has duplicate IQ name: %s\n", name);
}
ret = it;
}
}
warn_if(!ret, "can't find IQ by name: %s\n", name);
return ret;
};
if (params.xbarWakeup) {
for (auto srcIQ : issueQues) {
for (auto dstIQ : issueQues) {
wakeMatrix[srcIQ->getId()].push_back(dstIQ);
DPRINTF(Schedule, "build wakeup channel: %s -> %s\n", srcIQ->getName(), dstIQ->getName());
}
}
} else {
for (auto it : params.specWakeupNetwork) {
for (auto src : it->srcIQs) {
auto srcIQ = findIQbyname(src);
if (srcIQ) {
for (auto dstIQname : it->dstIQs) {
auto dstIQ = findIQbyname(dstIQname);
if (dstIQ) {
wakeMatrix[srcIQ->getId()].push_back(dstIQ);
DPRINTF(Schedule, "build wakeup channel: %s -> %s\n", srcIQ->getName(), dstIQ->getName());
}
}
}
}
}
}
assert(dispTable[MemWriteOp].size() == dispTable[StoreDataOp].size());
dispSeqVec.resize(64);
}
void
Scheduler::setCPU(CPU* cpu, LSQ* lsq)
{
this->cpu = cpu;
this->lsq = lsq;
for (auto it : issueQues) {
it->setCPU(cpu);
}
}
void
Scheduler::resetDepGraph(uint64_t numPhysRegs)
{
scoreboard.resize(numPhysRegs, true);
bypassScoreboard.resize(numPhysRegs, true);
earlyScoreboard.resize(numPhysRegs, true);
for (auto it : issueQues) {
it->resetDepGraph(numPhysRegs);
}
}
void
Scheduler::addToFU(const DynInstPtr& inst)
{