-
Notifications
You must be signed in to change notification settings - Fork 0
/
gem5_k800_pipe_view_parser.js
936 lines (799 loc) · 31.8 KB
/
gem5_k800_pipe_view_parser.js
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
let Op = require("./op").Op;
let OpList = require("./op_list").OpList;
let { ParsingOpList } = require("./op_list");
let Dependency = require("./op").Dependency;
let Stage = require("./stage").Stage;
let StageLevelMap = require("./stage").StageLevelMap;
let Lane = require("./stage").Lane;
// To avoid conflicts with node.js internal FileReader, use a different name.
let InternalFileReader = require("./file_reader").FileReader; // eslint-disable-line
class Gem5K800PipeViewExLogInfo {
constructor() {
/** @type {string[][]} */
this.logList = [];
this.srcs = [];
this.dsts = [];
}
}
class Gem5K800PipeViewParser {
constructor() {
// ファイルリーダ
/** @type {InternalFileReader} */
this.file_ = null;
// Callback handlers on update, finish, and error
this.updateCallback_ = null;
this.finishCallback_ = null;
this.errorCallback_ = null;
// 現在の行番号
this.curLine_ = 1;
// 現在読み出し中の ID/サイクル
this.curCycle_ = 0;
// Op のリスト
/** @type {OpList} */
this.opListBody_ = new OpList();
/** @type {ParsingOpList} */
this.secondParsingOpList_ = new ParsingOpList();
/** @type {number} - 最後に読み出された命令の ID*/
this.lastGID_ = -1; // seqNum
this.lastNotFlushedID = -1; // 最後に正常にリタイアした命令の id
// seq_num, flush flag, and tick for a currently parsed instruction
this.curParsingSeqNum_ = 0;
this.curParsingInsnFlushed_ = false; // seq_num
this.curParsingInsnCycle_ = -1; // This is used when instruction is flushed
this.allocateRid = 0;
// パース中の op のリスト
// ファイル内の op の順序はほぼランダムなため,一回ここに貯めたあと
// 再度 id と rid の割り付ける
// こいつは連続していないので,辞書になっている
/** @type {Object.<string, Op>} */
this.parsingOpList_ = {};
// パース中の K800PipeView 以外のログ
/** @type {Object.<string, Gem5K800PipeViewExLogInfo>} */
this.parsingExLog_ = {};
// K800PipeView 以外のログで最後に現れた SN
this.parsingExLogLastGID_ = -1;
// A table for dependency tracking
/** @type {Object.<string, Op>} */
this.depTable_ = {};
// パース完了
this.complete_ = false;
// 出現したレーンのマップ
this.laneMap_ = {};
this.recordState = [0, 0, 0, 0];
this.recordThread = -1;
// ステージの出現順序を記録するマップ
this.stageLevelMap_ = new StageLevelMap();
// 読み出し開始時間
this.startTime_ = 0;
// 更新間隔のタイマ
this.updateTimer_ = 100; // 初回は100行読んだら1回表示するようにしとく
// 更新ハンドラの呼び出し回数
this.updateCount_ = 0;
// 強制終了
this.closed_ = false;
// ticks(ps) per clock in GEM5.
// The default value is 1000 (1000 ps = 1 clock in 1GHz)
this.ticks_per_clock_ = 1;
// 開始時の tick
this.cycle_begin_ = -1;
// 開始時の GID (seq number)
this.gidBegin_ = -1;
// K800PipeView のタグが現れたかどうか
this.isGem5K800PipeView = false;
// この行数までに K800PipeView のタグが現れなかったら諦める
this.GIVING_UP_LINE = 20000;
// Stage ID
this.STAGE_ID_FETCH_ = 0;
this.STAGE_ID_DECODE_ = 1;
this.STAGE_ID_RENAME_ = 2;
this.STAGE_ID_DISPATCH_ = 3;
this.STAGE_ID_ISSUE_ = 4;
this.STAGE_ID_TVURECV = 5;
this.STAGE_ID_READPRF_ = 6;
this.STAGE_ID_READPRF_DONE_ = 7;
this.STAGE_ID_SPLIT_ = 8;
this.STAGE_ID_SEND_DM_ = 9;
this.STAGE_ID_DM_DONE_ = 10;
this.STAGE_ID_TPIPE_ = 11;
this.STAGE_ID_VPIPE = 12;
this.STAGE_ID_DIV_ = 13;
this.STAGE_ID_WR_PRF_ = 14;
this.STAGE_ID_SEND_WB_ = 15;
this.STAGE_ID_COMPLETE_ = 16;
this.STAGE_ID_RETIRE_ = 17;
this.STAGE_ID_MEM_COMPLETE_ = 18;
this.STAGE_ID_MAP_ = {
"fetch": this.STAGE_ID_FETCH_,
"decode": this.STAGE_ID_DECODE_,
"rename": this.STAGE_ID_RENAME_,
"dispatch": this.STAGE_ID_DISPATCH_,
"issue": this.STAGE_ID_ISSUE_,
"tvuRecv": this.STAGE_ID_TVURECV,
"readPRFTick": this.STAGE_ID_READPRF_,
"readPRFDoneTick": this.STAGE_ID_READPRF_DONE_,
"splitReqTick": this.STAGE_ID_SPLIT_,
"sendDMTick": this.STAGE_ID_SEND_DM_,
"accessDMDoneTick": this.STAGE_ID_DM_DONE_,
"sendToTPipe": this.STAGE_ID_TPIPE_,
"sendToVPipe": this.STAGE_ID_VPIPE,
"sendToDiv": this.STAGE_ID_DIV_,
"writePRFTick": this.STAGE_ID_WR_PRF_,
"sendToWBTick": this.STAGE_ID_SEND_WB_,
"complete": this.STAGE_ID_COMPLETE_,
"retire": this.STAGE_ID_RETIRE_,
"mem_complete": this.STAGE_ID_MEM_COMPLETE_ // 追加ログの解析結果より追加
};
this.STAGE_LABEL_MAP_ = [
/*0*/ "F",
/*1*/ "Dc",
/*2*/ "Rn",
/*3*/ "Ds",
/*4*/ "Is",
/*5*/ "Tr",
/*6*/ "Rd",
/*7*/ "Rdd",
/*8*/ "Sp",
/*9*/ "Dm",
/*10*/"Dmd",
/*11*/"St",
/*12*/"Sv",
/*13*/"Sd",
/*14*/"Wp",
/*15*/"Sw",
/*16*/"Cm",
/*17*/"Rt",
/*18*/"Mc",
];
this.SERIAL_NUMBER_PATTERN = new RegExp("sn:(\\d+)");
}
// Public methods
// 閉じる
close() {
this.closed_ = true;
this.opListBody_.close();
// パージ
this.parsingOpList_ = {};
this.parsingExLog_ = {};
this.depTable_ = {};
this.laneMap_ = {};
}
/**
* @return {string} パーサーの名前を返す
*/
get name() {
return "Gem5K800PipeViewParser";
}
/**
* @param {InternalFileReader} file - ファイルリーダ
* @param {function} updateCallback -
* (percent, count): 読み出し状況を 0 から 1.0 で渡す.count は呼び出し回数
* @param {function} finishCallback - 終了時に呼び出される
* @param {function} errorCallback - エラー時に呼び出される
*/
setFile(file, updateCallback, finishCallback, errorCallback) {
this.file_ = file;
this.updateCallback_ = updateCallback;
this.finishCallback_ = finishCallback;
this.errorCallback_ = errorCallback;
this.startTime_ = (new Date()).getTime();
this.startParsing();
file.readlines(
this.parseLine.bind(this),
this.finishParsing.bind(this)
);
}
getOp(id, resolution = 0) {
return this.opListBody_.getParsedOp(id, resolution);
}
getOpFromRID(rid, resolution = 0) {
return this.opListBody_.getParsedOpFromRID(rid, resolution);
}
get lastID() {
return this.opListBody_.parsedLastID;
}
get lastRID() {
return this.opListBody_.parsedLastRID;
}
/** @returns {Object.<string, number>} */
get laneMap() {
return this.laneMap_;
}
get stageLevelMap() {
return this.stageLevelMap_;
}
/** @returns {number} */
get lastCycle() {
return this.curCycle_;
}
startParsing() {
this.complete_ = false;
this.curCycle_ = 0;
}
/**
* @param {string} line
*/
parseLine(line) {
try {
this.parseLineBody_(line);
}
catch (e) {
// fileNotSupport, exception
this.errorCallback_(false, e);
}
}
/**
* @param {string} line
*/
parseLineBody_(line) {
if (this.closed_) {
// Node.js はファイル読み出しが中断されクローズされた後も,
// バッファにたまっている分はコールバック読み出しを行うため,
// きちんと無視する必要がある
return;
}
let args = line.split(":");
// File format detection
if (args[0] != "K800PipeView") {
this.curLine_++;
if (!this.isGem5K800PipeView && this.curLine_ > this.GIVING_UP_LINE) {
// fileNotSupport, exception
this.errorCallback_(true);
}
// K800PipeView 以外のログで sn:数字 の形式を持っている行は一旦 parsingLog_ に保持
let sn = this.parsingExLogLastGID_;
let matched = this.SERIAL_NUMBER_PATTERN.exec(line);
if (matched) {
sn = Number(matched[1]);
this.parsingExLogLastGID_ = sn;
}
if (this.parsingExLogLastGID_ == -1 || sn <= this.opListBody_.parsedLastID) { // 既にドレインされたものは諦める
//console.log("Drop a drained op");
}
else {
if (!(sn in this.parsingExLog_)) {
this.parsingExLog_[sn] = new Gem5K800PipeViewExLogInfo();
}
if (args[0].match(/^\s*\d+/)) { // 先頭に tick があるものだけ保存
this.parsingExLog_[sn].logList.push(args);
}
else {
this.parsingExLogLastGID_ = -1;
}
}
}
else {
this.isGem5K800PipeView = true;
if (args[1] == "fetch") {
if (this.recordState[Number(args[3])] == 2) {
if (args[7] == "add zero, zero, tp")
this.recordState[Number(args[3])] = 0;
} else if (this.recordState[Number(args[3])] == 1) {
this.recordState[Number(args[3])] = this.recordState[Number(args[3])] + 1;
} else if (this.recordState[Number(args[3])] == 0) {
if (args[7] == "add zero, zero, tp")
this.recordState[Number(args[3])] = this.recordState[Number(args[3])] + 1;
}
this.recordThread = Number(args[3])
}
if (this.recordState[this.recordThread] == 2) {
this.parseCommand(args);
}
this.curLine_++;
}
this.updateTimer_--;
if (this.updateTimer_ < 0) {
this.updateTimer_ = 1024 * 16;
// Call update callback, which updates progress bars
this.updateCallback_(
1.0 * this.file_.bytesRead / this.file_.fileSize,
this.updateCount_
);
this.updateCount_++;
if (this.isGem5K800PipeView) {
this.drainParsingOps_(false);
}
}
}
detectTicksPerClock(force) {
if (this.ticks_per_clock_ != -1) {
return;
}
// Collect all outputted ticks
let ticks = {};
let minSeqNum = -1;
for (let seqNumStr in this.parsingOpList_) {
let seqNum = Number(seqNumStr);
let op = this.parsingOpList_[seqNum];
if (!op.flush && !op.retired) {
break; // A next op has not been parsed yet.
}
ticks[op.fetchedCycle] = 1;
ticks[op.retiredCycle] = 1;
for (let laneID in op.lanes) {
let lane = op.lanes[laneID];
for (let stage of lane.stages) {
ticks[stage.startCycle] = 1;
ticks[stage.endCycle] = 1;
//if (stage.endCycle == 0 || stage.startCycle == 0)
// lane = lane;
}
}
if (minSeqNum == -1 || minSeqNum > seqNum) {
minSeqNum = seqNum;
}
}
// Sort as numbers
let rawTicks = [];
for (let i of Object.keys(ticks)) {
rawTicks.push(Number(i));
}
let sortedTicks = rawTicks.sort((a, b) => { return a - b; });
// If there is not enough ticks, detection is not performed.
if (!force && sortedTicks.length < 1024) {
return;
}
// Detect minimum delta
let minDelta = 0;
let prevTick = sortedTicks[0];
for (let i of sortedTicks) {
let delta = i - prevTick;
if (minDelta == 0 || (delta > 0 && delta < minDelta)) {
minDelta = delta;
}
prevTick = i;
}
if (minDelta > 0) {
this.ticks_per_clock_ = minDelta;
this.cycle_begin_ = sortedTicks[0] / this.ticks_per_clock_;
this.gidBegin_ = minSeqNum;
console.log("Detected ticks per clock: " + minDelta);
}
}
// Update opList from parsingOpList
/** @param {boolean} force */
drainParsingOps_(force) {
this.detectTicksPerClock(force);
if (this.ticks_per_clock_ == -1) {
return;
}
// GEM5 の K800PipeView はかなり out-of-order に出力されるので,
// バッファしておく(1万以上平気で seq num がさかのぼることがある)
let BUFFERED_SIZE = 1024 * 16;
let seqNumList = Object.keys(this.parsingOpList_).sort((a, b) => { return Number(a) - Number(b); });
let drainCount = seqNumList.length - BUFFERED_SIZE;
if (!force && drainCount < 0) {
return;
}
for (let seqNumStr of seqNumList) {
let op = this.parsingOpList_[seqNumStr];
if (!force && !op.flush && !op.retired) {
continue; // This op has not been parsed yet.
}
if (!force && drainCount <= 0) {
break;
}
drainCount--;
let seqNum = Number(seqNumStr); // Object 型からは文字列のみがでてくる
// Update clock cycles
op.fetchedCycle = op.fetchedCycle / this.ticks_per_clock_ - this.cycle_begin_;
op.retiredCycle = op.retiredCycle / this.ticks_per_clock_ - this.cycle_begin_;
// フェッチステージのみを実行したあとにフラッシュされると,
// リタイアのサイクルが 0 → fetchedCycle と同じに設定されるため,
// その場合に fetch を表示するために1つ遅らせる
if (op.flush && op.fetchedCycle == op.retiredCycle) {
op.retiredCycle++;
}
if (op.prodCycle != -1)
op.prodCycle = op.prodCycle / this.ticks_per_clock_ - this.cycle_begin_;
if (op.consCycle != -1)
op.consCycle = op.consCycle / this.ticks_per_clock_ - this.cycle_begin_;
for (let laneID in op.lanes) {
let lane = op.lanes[laneID];
for (let stage of lane.stages) {
stage.startCycle = stage.startCycle / this.ticks_per_clock_ - this.cycle_begin_;
stage.endCycle = stage.endCycle / this.ticks_per_clock_ - this.cycle_begin_;
// 特定のステージが開始されたあとにフラッシュされると,
// そのステージの終わりが 0 → startCycle と同じに設定されるため,
// その場合にそのステージを最低ひとつ表示するために1つ遅らせる
// つまりsたとえば fetch:1000, decode:0 ときたときに,
// fetch が 1000->1000 となるので,これを 1000->1001 に書き換える
if (op.flush && stage.startCycle == stage.endCycle) {
stage.endCycle++;
}
}
}
// Add an op to opList and remove it from parsingOpList.
// At this time, op.id is not determined.
this.secondParsingOpList_.setOp(seqNum - this.gidBegin_, op);
delete this.parsingOpList_[seqNumStr];
if (this.lastGID_ > seqNum) {
console.log(`Miss parsed op: seqNum: ${seqNum} lastGID: ${this.lastGID_}. BUFFERED_SIZE must be bigger.`);
}
}
// GEM5 の K800PipeView はたまに out-of-order で出力されるので,
// ある程度バッファしておく
for (let i = this.opListBody_.parsedLastID + 1; i <= this.secondParsingOpList_.parsingLastID; i++) {
let op = this.secondParsingOpList_.getParsingOp(i);
if (op == null) {
continue;
}
// op.id is determined
op.id = i;
this.secondParsingOpList_.purge(i);
this.opListBody_.setOp(i, op);
this.opListBody_.setParsedLastID(i);
this.lastGID_ = op.gid;
if (op.retiredCycle > this.curCycle_) {
this.curCycle_ = op.retiredCycle;
}
if (!op.flush) {
// op.rid = this.opListBody_.parsedLastRID + 1;
this.opListBody_.setParsedRetiredOp(op.rid, op);
this.lastNotFlushedID = this.opListBody_.parsedLastID;
}
else { // in a flushing phase
// Dummy RID
// op.rid = this.opListBody_.parsedLastRID + this.lastID - this.lastNotFlushedID;
}
// ExLog post process
let seqNum = op.id + this.gidBegin_;
if (seqNum in this.parsingExLog_) {
let exLog = this.parsingExLog_[seqNum];
for (let s of exLog.srcs) {
let type = 0; // default
if (s in this.depTable_) {
let prod = this.depTable_[s];
if (prod.prodCycle < op.consCycle) {
op.prods.push(new Dependency(prod.id, type, op.prodCycle));
prod.cons.push(new Dependency(op.id, type, op.consCycle));
}
}
}
//if (!op.flush) {
for (let d of exLog.dsts) {
this.depTable_[d] = op;
}
delete this.parsingExLog_[seqNum];
}
this.opListBody_.setOp(i, op);
}
}
finishParsing() {
if (this.closed_) {
return;
}
if (!this.isGem5K800PipeView) {
// fileNotSupport, exception
this.errorCallback_(true);
return;
}
// 未処理の命令を強制処理
this.drainParsingOps_(true);
// リタイア処理が行われなかった終端部分の後処理
let i = this.secondParsingOpList_.parsingLastID;
while (i >= 0) {
let op = this.secondParsingOpList_.getParsingOp(i);
i--;
if (op == null) {
continue;
}
if (op.retired && !op.flush) {
break; // コミットされた命令がきたら終了
}
if (op.flush) {
continue; // フラッシュされた命令には特になにもしない
}
op.retiredCycle = this.curParsingInsnCycle_ / this.ticks_per_clock_;
op.eof = true;
this.unescapeLabels(op);
this.secondParsingOpList_.purge(i);
this.opListBody_.setOp(i, op);
}
this.opListBody_.setParsedLastID(this.secondParsingOpList_.parsingLastID);
this.complete_ = true;
let elapsed = ((new Date()).getTime() - this.startTime_);
this.updateCallback_(1.0, this.updateCount_);
this.finishCallback_();
// Release
this.parsingOpList_ = {};
this.parsingExLog_ = {};
this.depTable_ = {};
console.log(`Parsed (${this.name}): ${elapsed} ms`);
}
/** @param {Op} op */
unescapeLabels(op) {
// op 内のラベルのエスケープされている \n を戻す
// v8 エンジンでは,文字列を結合すると cons 文字列という形式で
// 文字列のリストとして保持するが,これはメモリ効率が悪いが,
// 正規表現をかけるとそれが平坦化されるのでメモリ効率もあがる
// (op 1つあたり 2KB ぐらいメモリ使用量が減る
op.labelName = op.labelName.replace(/\\n/g, "\n");
op.labelDetail = op.labelDetail.replace(/\\n/g, "\n");
for (let laneName in op.lanes) {
for (let stage of op.lanes[laneName].stages) {
stage.labels = stage.labels.replace(/\\n/g, "\n");
}
}
}
/**
* @param {string[]} args
* @return {Op}
*/
parseInitialCommand(args) {
// 特定の命令に関するコマンド出力の開始
// old K800PipeView:fetch:2132747000:0x004ea8f4:0:4: add w6, w6, w7
// new K800PipeView:fetch:2132747000:0:0x004ea8f4:0:4: add w6, w6, w7
// 0 1 2 3 4 5 6 7
let tick = Number(args[2]);
let tid = Number(args[3]);
if (!store.activeTab.allThread.includes(tid)) {
store.activeTab.allThread.push(tid)
store.activeTab.allThread.sort((a, b) => a - b)
}
let insnAddr = args[4];
//let microPC = Number(args[4]);
let seqNum = Number(args[6]);
let disasm = args[7];
this.recordThread = tid;
// Even if ":" is inserted after the 6th, it is disassembled text
for (let i = 8; i < args.length; i++) {
disasm += ":" + args[8];
}
let op = new Op();
op.id = -1; // この段階ではまだ未定
op.gid = seqNum;
op.tid = tid;
op.rid = this.allocateRid + 1;
this.allocateRid = op.rid;
op.fetchedCycle = tick;
op.line = this.curLine_;
op.labelName += `${insnAddr}: ${disasm}`;
op.labelDetail += `Fetched Tick: ${tick}`;
this.parsingOpList_[seqNum] = op;
// Reset the current context
this.curParsingSeqNum_ = seqNum;
this.curParsingInsnFlushed_ = false;
this.curParsingInsnCycle_ = op.fetchedCycle;
this.parseStartCommand(seqNum, op, args);
return op;
}
parseStartCommand(seqNum, op, args) {
// K800PipeView:fetch:2132747000:0x004ea8f4:0:4: add w6, w6, w7
// K800PipeView:decode:2132807000
let cmd = args[1];
let tick = Number(args[2]);
let stageID = this.STAGE_ID_MAP_[cmd];
let stageName = this.STAGE_LABEL_MAP_[stageID];
if (!store.activeTab.allStage.includes(stageName)) {
store.activeTab.allStage.push(stageName)
store.activeTab.allStage.sort((a, b) => {
this.STAGE_LABEL_MAP_.indexOf(a) - this.STAGE_LABEL_MAP_.indexOf(b)
})
}
//if (seqNum == 7) {
// seqNum = seqNum;
//}
// If tick is 0, this op is flushed.
if (tick == 0) {
this.curParsingInsnFlushed_ = true;
tick = this.curParsingInsnCycle_; // Set a last valid tick
// Stages after flush are skipped.
return;
}
else {
this.curParsingInsnCycle_ = tick;
}
let laneName = "0"; // Default lane
let stage = new Stage();
stage.name = stageName;
stage.startCycle = tick;
if (!(laneName in op.lanes)) {
op.lanes[laneName] = new Lane;
}
let laneInfo = op.lanes[laneName];
laneInfo.stages.push(stage);
op.lastParsedStage = stage;
op.lastParsedCycle = tick;
// Cm を名前に含むステージは実行ステージと見なす
if (stageName == "Cm") {
op.consCycle = tick;
op.prodCycle = tick;
}
if (stageName == "Mw") {
op.prodCycle = tick;
}
// レーンのマップに登録
if (!(laneName in this.laneMap_)) {
this.laneMap_[laneName] = 1;
}
// ステージのマップに登録
this.stageLevelMap_.update(laneName, stageName, laneInfo);
}
/**
* @param {number} seqNum
* @param {Op} op
* @param {string[]} args
*/
parseEndCommand(seqNum, op, args) {
let tick = Number(args[2]);
if (tick == 0 && this.curParsingInsnFlushed_) {
// Stages after flush are skipped.
// If curParsingInsnFlushed_ is not set, this stage has not been closed and should be closed.
return;
}
let laneName = "0"; // Default lane
let stageName = op.lastParsedStage.name;
op.lastParsedCycle = tick;
let stage = null;
let laneInfo = op.lanes[laneName];
let lane = laneInfo.stages;
for (let i = lane.length - 1; i >= 0; i--) {
if (lane[i].name == stageName) {
stage = lane[i];
break;
}
}
if (stage == null) {
return;
}
stage.endCycle = tick;
// レベルの更新
// フラッシュで無理矢理閉じられることがあるので,
// stageNameMap への登録はここでやってはいけない.
if (stage.startCycle != stage.endCycle) {
laneInfo.level++;
}
}
parseRetireCommand(seqNum, op, args) {
//if (seqNum == 11) {
// seqNum = seqNum;
//}
let tick = Number(args[2]);
// If tick is 0, this op is flushed.
if (tick == 0) {
this.curParsingInsnFlushed_ = true;
tick = this.curParsingInsnCycle_; // Set the last valid tick
}
op.retiredCycle = tick + 1;
op.lastParsedCycle = tick;
if (this.curParsingInsnFlushed_) {
op.flush = true;
op.retired = false;
}
else {
op.flush = false;
op.retired = true;
}
// Decode label strings
this.unescapeLabels(op);
// 閉じていないステージがあった場合はここで閉じる
for (let laneName in op.lanes) {
let stages = op.lanes[laneName].stages;
for (let stage of stages) {
if (stage.endCycle == 0) {
stage.endCycle = tick;
}
if (stage.name == "Rt")
stage.endCycle = stage.endCycle + 1;
}
}
// console.log(op)
}
parseCommand(args) {
let seqNum = this.curParsingSeqNum_;
/** @type {Op} */
let op = null;
if (seqNum in this.parsingOpList_) {
op = this.parsingOpList_[seqNum];
}
let cmd = args[1];
let tick = Number(args[2]);
switch (cmd) {
case "fetch":
op = this.parseInitialCommand(args);
break;
case "decode":
case "rename":
case "dispatch":
case "issue":
case "tvuRecv":
case "readPRFTick":
// case "readPRFDoneTick":
case "splitReqTick":
case "sendDMTick":
// case "accessDMDoneTick":
case "sendToTPipe":
case "sendToVPipe":
case "sendToDiv":
case "writePRFTick":
case "sendToWBTick":
case "complete":
this.parseExLog(op, tick);
this.parseEndCommand(seqNum, op, args);
this.parseStartCommand(seqNum, op, args);
break;
case "retire":
this.parseExLog(op, tick);
this.parseEndCommand(seqNum, op, args);
this.parseStartCommand(seqNum, op, args);
this.parseRetireCommand(seqNum, op, args);
break;
} // switch end
}
/**
* parseCycleRange までの追加ログをパースして op に追加
* 追加ログのパース中にステージの追加が行われることがあるため,
* parseCommand と同期して処理する必要がある.
* @param {Op} op
* @param {number} parseCycleRange
*/
parseExLog(op, parseCycleRange) {
/** @param {number} seqNum */
let seqNum = op.gid;
if (!(seqNum in this.parsingExLog_)) {
return;
}
let opExLog = this.parsingExLog_[seqNum];
let logList = opExLog.logList;
while (logList.length) {
let args = logList[0]; // args にはコロンで split されたトークンが入る
let tick = args[0];
if (Number(tick) >= parseCycleRange) {
break;
}
if (args[1] == " user") {
// 3260000: user:
// register values
op.labelDetail += "\n " + args.join(":");
}
else if (args[1] == " global" && args[2] == " RegFile") {
// register values
// 3260000: global: RegFile: Setting int register 125 to 0x4af000
op.labelDetail += "\n " + args[3];
}
else if (args[1].match(/\.memDep/) && args[2].match(/ Completed mem/)) {
// Memory write back
// 3260000: system.cpu.iq: Completing mem instruction PC: (0x436018=>0x43601c).(0=>1) [sn:157]
let dummyArgs = ["K800PipeView", "mem_complete", tick];
this.parseEndCommand(seqNum, op, dummyArgs);
this.parseStartCommand(seqNum, op, dummyArgs);
}
else if (args[1].match(/\.rename/)) {
// コロンの入る個数がたまに変わるので,ループでリネーム関係の文字列を探す
for (let i = 2; i < args.length; i++) {
// Renaming: dst をリネーム
// Looking: src をリネーム
if (args[i].match(/ (Renaming)|(Looking)/)) {
op.labelDetail += "\n " + args[i];
// 3271000: system.cpu.rename: [tid:0]: Renaming arch reg 1 (IntRegClass) to physical reg 152 (152).
// 157067000: system.cpu.rename: [tid:0] Renaming arch reg 0 (invalid) to physical reg 65535 (65535).
let dst = args[i].match(/\(([a-zA-Z]+)\) to physical reg (\d+) \(\d+\)/);
if (dst && dst[2] != "invalid") {
opExLog.dsts.push(String(dst[1]) + dst[2]);
}
// 157067000: system.cpu.rename: [tid:0] Looking up integer arch reg 17, got phys reg 220 (integer)
// 2340100: system.cpu.rename: [tid:0]: Looking up IntRegClass arch reg 43, got phys reg 72 (IntRegClass)
let src = args[i].match(/got phys reg (\d+) \(([a-zA-Z]+)\)/);
if (src && src[2] != "invalid") {
opExLog.srcs.push(String(src[2]) + src[1]);
}
}
}
}
else if (
args[1].match(/\.iew.lsq.thread/) &&
args[2].match(/ (Read called)|(Doing write)/)
) {
// Load/store addr
// 3757000: system.cpu.iew.lsq.thread0: Read called, load idx: 14, store idx: -1, storeHead: 24 addr: 0x1efed0
op.labelDetail += "\n " + args.slice(2, 7).join(":");
}
// Add log to each stage
if (op.lastParsedStage.labels != "")
op.lastParsedStage.labels += "\n";
op.lastParsedStage.labels += args.join(":");
logList.shift();
}
}
}
module.exports.Gem5K800PipeViewParser = Gem5K800PipeViewParser;