-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScoreboard.vr
3072 lines (2682 loc) · 110 KB
/
Scoreboard.vr
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
/*************************************************************************
** From Perforce:
**
** $Id: //Smart_design/Smash_rel/TestCommonLib/Quad/Scoreboard.vr#4 $ID$
** $DateTime: 2008/05/01 00:20:07 $
** $Change: 6703 $
** $Author: zasgar $
*************************************************************************/
#ifndef INC_SCOREBOARD_VR
#define INC_SCOREBOARD_VR
//////////////////////////////////////////////////////////////////////////////
// File name: Scoreboard.vr
//
// This file includes the Implementation of the Scoreboard,
// which will eventually use different algorithms to determine
// whether a series of loads and stores is possibly or probably
// legal.It will throw an error if not.
//
//////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
//----- Include Related Files Here
//------------------------------------------------------------------------------
// Main source file for quad testbench
#include <vera_defines.vrh>
#include <VeraErrorHandler.vrh>
// define interfaces, and verilog_node here if necessary
#include "Quad_def.vrh"
#include "QuadTasks.vrh"
// declare external tasks/classes/functions here if necessary
#include "generic_trans.vrh"
#include "sim_io.vrh"
#include "generic_master.vrh"
#include "generic_memory.vrh"
#include "Trace_trans.vrh"
#include "Trace_trans_Q.vrh"
#include "Scoreboard_Address.vrh"
#include "tcc_constants.h"
#include "TCC_Transaction.vrh"
#include "Store_Queue.vrh"
//------------------------------------------------------------------------------
//----- Place Special Definitions and Extern Declarations Here
//------------------------------------------------------------------------------
extern generic_memory MainMem;
extern bit InitializationDone;
/*The amount of time we can "assume" that it takes a Store to complete (I will
think more carefully about synch stores in the future). We can RAISE this
if it causes too many problems, or LOWER it if it doesn't seem to do anything.
*/
#define DEFAULT_MAX_STORE_TIME 1500
#define INTERESTING 32'h40000000
#define CPUS_PER_TILE 2
//------------------------------------------------------------------------------
//----- Place Main Class Declaration Here
//------------------------------------------------------------------------------
class Scoreboard extends GENERIC_master
{
// control variables
//-------------------
protected integer active;
protected string my_agent_name;
protected integer my_agent_ID;
protected string my_prefix;
protected integer _DEBUG_;
//Count how many transactions were actually added to the scoreboard.
protected integer transaction_counter;
protected integer semID; /*semaphore for controlling the scoreboard when adding a trans.*/
// Queues
//-----------------------------
protected Trace_trans_Q Trace_Q_Array[];
protected Trace_trans_Q Trace_Q_Freelist[$];
protected Trace_trans Trace_trans_Freelist[$];
protected Scoreboard_Address ignoreAddress;
protected Scoreboard_Address tccAddress;
protected TCC_Transaction Tcc_Array[*];
protected Store_Queue Store_Queues[*];
protected bit[8:0] BackupMem[];
// How long until stores can be expected to be completed.
protected integer MaxStoreTime;
//keep track of the latest time of a transaction
//completed by
// each processor
protected integer last_transaction_time[*];
//keep track of the minimum last_transaction_time,
// this is the "invalidate_time": any transactions
// invalid before this can be garbage collected.
protected bit[63:0] invalidate_time;
// how many CPUS (ie, 8 for single-quad, 32 for 4-quad)
protected integer num_cpus;
// Handles to log files:
//----------------------
integer Scoreboard_log_file_handle;
integer Scoreboard_usage_file_handle;
// Constructor
//------------
task new(integer _DEBUG, string my_agent_name_,
integer my_agent_ID_, string my_prefix_, integer num_cpus);
// Main Scoreboard Task: add a transaction to the scoreboard.
//--------------------------------------------------------
task AddTransToSB(Trace_trans trac);
//Lock an address to prevent garbage collection (ie at the start of a load)
task LockAddress(integer senderID, bit [31:0] addr, integer operation);
task UnlockAddress(integer senderID, bit [31:0] addr, integer operation);
//new outside-callable scoreboard task (usually for synch stores, etc, where
//you know when they have completed), trace should already be in the
// scoreboard.
task CompleteTransInSB(Trace_trans trac);
//New scoreboard task: indicate a mem-bar operation. THis could be done
// by sending an entire transaction to the scoreboard, but as mem-bar is a quality
// of many operations, and it doesnt make sense to have all the fields as another
// transaction, this is done just with a function.
task SetMemBarInSB(bit[63:0] cycle, integer senderID);
// Scoreboard Check Tasks/Functions:
//--------------------------------------------------------
//wrapper function for performing the check.
protected task CheckScoreboard(Trace_trans last_trans, Trace_trans_Q added_to_q);
//function that performs a check on the queue and returns -1 if
// there is an error, as well as printing out an error.
function integer CheckLastReceived(Trace_trans last_trans, Trace_trans_Q added_to_q);
//function for syncops that checks the possibility that the F/E bit
// was set as required.
function integer CheckLastFullEmpty(Trace_trans sync_trans, Trace_trans_Q added_to_q);
// Scoreboard Update Tasks/Functions:
//----------------------------------------
//wrapper function for performing the update.
protected task UpdateScoreboard(Trace_trans last_trans, Trace_trans_Q added_to_q);
/* function to update the data structures once a second store to the same
* address by the same CPU was spoted
*/
protected function integer UpdateSimple(Trace_trans store_trans, Trace_trans_Q added_to_q);
//function that invalidates earlier stores to an address by a processor
// if a value is read that was written by that proc.
protected function integer UpdateAfterRead(Trace_trans last_trans, Trace_trans_Q added_to_q);
//function that invalidates stores which have definately already completed,
// after some other value is read.
function integer UpdateAfterReadForOtherProcs(Trace_trans read_trans,
Trace_trans_Q added_to_q);
//Add outstanding stores to a supplementary data structure for each processor.
// These can be removed from this structure in various ways.
function integer UpdateAddToStoreQueue(Trace_trans last_trans);
//function used for TSO: once a value has definately already completed,
//invalidate all earlier stores by the processor TO ALL ADDRESSES. Actually,
// no need to INVALIDATE the stores, but simply to mark their completion
// times.
function integer UpdateAfterReadTSO(Trace_trans read_trans,
Trace_trans_Q added_to_q);
//function that simply records the time that this processor's latest
// transaction began. Any transactions the processor makes now
// will be later than that. This is to
// make garbage collection possible.
protected function integer UpdateRecordTransTime(Trace_trans last_trans);
//function that invalidates stores based on how far in time they occured
// from other stores -- 2 stores far apart, the second will definately
// win the race.
protected function integer UpdateAfterStoreTimeBased(Trace_trans store_trans, Trace_trans_Q added_to_q);
//function that invalidates synch stores. Because a synch store is
// guaranteed to have already completed, then a second
//synch store to the same address will invalidate all earlier
//synch stores.
protected function integer UpdateAfterSynchStore(Trace_trans store_trans);
//function that monitors the F/E bit for each word
protected function integer UpdateFullEmpty(Trace_trans last_trans, Trace_trans_Q added_to_q);
// (UNUSED)function that will record that a read was completed by a processor
// at this address at this time. Once all processors have read something
// at this time, then we know all invalid stores to this address can be gc'ed.
protected function integer UpdateAfterReadGC(Trace_trans last_trans);
// function that simply removes the last xaction if it was a read.
protected function integer UpdateRemoveRead(Trace_trans last_trans, Trace_trans_Q added_to_q);
// function that does some violation checks for loads
protected function integer UpdateAfterReadTCC(Trace_trans read_trans, Trace_trans_Q added_to_q);
//function that updates the TCC state when transactions are added. This means
// setting them to be invalid for all but the issuing processor, and
// adding them to the processors TCC Transaction structure.
protected function integer UpdateTCC(Trace_trans last_trans, Trace_trans_Q added_to_q);
//function called when a TCC transaction commits successfully and definately.
protected function integer UpdateAfterTCCCommit(Trace_trans store_trans);
// Auxiliary Tasks/Functions:
//----------------------------------------
//Task to throw an error, rather than crashing all the time.
protected task scoreboard_fail();
//Task that runs in the background doing garbage collection
// of old invalid transactions
task GarbageCollector();
/* functions for recycling transactions and transaction queues in
* order to save time and memory.
* (getNewTraceTrans is public so that the aop links can use this
*/
public function Trace_trans getNewTraceTrans();
protected function Trace_trans_Q getNewTraceTransQ(bit[31:0] addr,
bit readFromBackup);
// Task to handle special commands (TCC dummy commands)
protected function bit HandleSpecCmd(Trace_trans trac);
protected function bit HandleTccStart(Trace_trans specTrans);
protected function bit HandleTccCommitStart(Trace_trans specTrans);
protected function bit HandleTccCommitEnd(Trace_trans specTrans);
protected function bit HandleTccViolation(Trace_trans specTrans);
protected function bit HandleTccEnd(Trace_trans specTrans);
// Global activation/termination functions:
//--------------------------------------------
task run();
task stop_me();
}
//------------------------------------------------------------------------------
//----- Place Implementation of Methods Here
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Scoreboard::new()
task Scoreboard::new(integer _DEBUG, string my_agent_name_,
integer my_agent_ID_, string my_prefix_, integer my_num_cpus)
{
//////////////////////////////////////////////////////////
// In the common case this method should not be changed //
//////////////////////////////////////////////////////////
Trace_trans Trace_trans_dummy;
integer proc;
_DEBUG_ = _DEBUG;
if ( _DEBUG_ ) printf ("%s: New Scoreboard was created\n",my_agent_name_);
active = 0; // initial monitor as not active.
my_agent_name = my_agent_name_;
my_agent_ID = my_agent_ID_;
my_prefix = my_prefix_;
/*Initialize counter for number of transactions added to sb.*/
transaction_counter = 0;
if (my_num_cpus <= 0){
printf("SCOREBOARD ERROR: Scoreboard can't handle 0 or fewer CPUs\n");
active = 0;
repeat (2) @(posedge CLOCK);
exit(1);
}
num_cpus = my_num_cpus;
// Open Scoreboard log file
Scoreboard_log_file_handle = fopen({my_prefix, "Scoreboard.log"}, "w");
Scoreboard_usage_file_handle = fopen({my_prefix, "Scoreboard_Size.log"}, "w");
if (Scoreboard_log_file_handle == 0)
{
printf("SCOREBOARD ERROR: VERA Can't open %sScoreboard.log for writing\n", my_prefix);
active = 0;
repeat (2) @(posedge CLOCK);
exit(1);
}
else
{
fprintf (Scoreboard_log_file_handle,"File: %sScoreboard.log\n", my_prefix);
fprintf (Scoreboard_log_file_handle,"********************************\n" );
fprintf (Scoreboard_log_file_handle,"\n\n");
fprintf (Scoreboard_log_file_handle,
"|TransID |Sndr|O |Addr |D |Start |End |T|Comment\n"
"| | ID |p | |a |Time |Time |C|\n"
"| | |c | |t | | |C|\n"
"| | |o | |a | | | |\n"
"| | |d | | | | | |\n"
"| | |e | | | | | |\n"
"| | | | | | | | |\n"
"|--------|----|-----|--------|--|--------|--------|-|\n");
fflush(Scoreboard_log_file_handle);
}
// initialize the accesses semaphore
// random semaphore ID, #semaphores, keys per semaphore
semID=alloc(SEMAPHORE, 0 , 1 , 1 );
if (! semID)
{
printf("SCOREBOARD ERROR: VERA Can't Allocate Semaphores\n");
exit (1);
}
//Initialize the trace trans by creating a dummy transaction,
// this is to set the ID counter to zero.
Trace_trans_dummy = new(num_cpus);
Trace_trans_dummy.Init();
/*initialize last transaction times*/
last_transaction_time = new[num_cpus];
for (proc = 0; proc < num_cpus; proc ++){
last_transaction_time[proc] = 0;
}
/*initialize TCC transactions*/
Tcc_Array = new[num_cpus/CPUS_PER_TILE];
for (proc = 0; proc < num_cpus/CPUS_PER_TILE; proc++){
Tcc_Array[proc] = new(_DEBUG, proc);
}
/*Initialize Store Queues*/
Store_Queues = new[num_cpus];
for (proc = 0; proc < num_cpus; proc++){
Store_Queues[proc] = new(_DEBUG);
}
// finally enroll to the masters list
EnrollToMastersList(); //defined in GENERIC_master
}
//------------------------------------------------------------------------------
// Scoreboard::run()
task Scoreboard::run()
{
// Check if scoreboard is necessary
if(get_plus_arg(CHECK, "use_quad_sb"))
{
active = 1;
printf ("%s: Scoreboard was activated\n",my_agent_name);
if (get_plus_arg(CHECK, "ScoreboardMaxStoreTime=")){
MaxStoreTime = get_plus_arg(NUM, "ScoreboardMaxStoreTime=");
}
else {
MaxStoreTime = DEFAULT_MAX_STORE_TIME;
}
if (get_plus_arg(CHECK, "ScoreboardIgnore=")){
string ignoreStr;
reg [2047:0] bit_str; //max 256 char
string current, remainder;
bit[31:0] low;
bit[31:0] high;
ignoreAddress = new(_DEBUG_, "SCOREBOARD_IGNORE");
bit_str = get_plus_arg(STR, "ScoreboardIgnore=");
ignoreStr.bittostr(bit_str);
while(ignoreStr.match("-")){
current = ignoreStr.prematch();
low = current.atohex();
ignoreStr = ignoreStr.postmatch();
if (ignoreStr.match(",")){
current = ignoreStr.prematch();
high = current.atohex();
ignoreAddress.addRange(low,high);
ignoreStr = ignoreStr.postmatch();
}
else{
current = ignoreStr;
high = current.atohex();
ignoreAddress.addRange(low,high);
break;
}
}
ignoreAddress.logMeToFile(Scoreboard_log_file_handle);
}
else{
ignoreAddress = new(_DEBUG_, "SCOREBOARD_IGNORE");
ignoreAddress.addRange(32'h20000000, 32'h2fffffff);
ignoreAddress.logMeToFile(Scoreboard_log_file_handle);
}
if (get_plus_arg(CHECK, "TccCoherent=")){
string tccStr;
reg [2047:0] bit_str; //max 256 char
string current, remainder;
bit[31:0] low;
bit[31:0] high;
tccAddress = new(_DEBUG_, "TCC_RANGE");
bit_str = get_plus_arg(STR, "TccCoherent=");
tccStr.bittostr(bit_str);
while(tccStr.match("-")){
current = tccStr.prematch();
low = current.atohex();
tccStr = tccStr.postmatch();
if (tccStr.match(",")){
current = tccStr.prematch();
high = current.atohex();
tccAddress.addRange(low,high);
tccStr = tccStr.postmatch();
}
else{
current = tccStr;
high = current.atohex();
tccAddress.addRange(low,high);
break;
}
}
tccAddress.logMeToFile(Scoreboard_log_file_handle);
}
else{
tccAddress = new(_DEBUG_, "TCC_RANGE");
/*add TCC coherent range*/
tccAddress.addRange(32'ha0000000, 32'hafffffff);
/*add TCC buffered range*/
tccAddress.addRange(32'hd0000000, 32'hdfffffff);
tccAddress.logMeToFile(Scoreboard_log_file_handle);
}
// Start the garbage collection thread
fork
{ GarbageCollector(); }
join none
}
else{
printf ("%s: Scoreboard is idle\n",my_agent_name);
active = 0;
}
}
//------------------------------------------------------------------------------
// Scoreboard::stop_me()
task Scoreboard::stop_me()
{
//////////////////////////////////////////////////////////
// In the common case this method should not be changed //
//////////////////////////////////////////////////////////
fprintf(Scoreboard_log_file_handle,
"Number of transactions added to sb: %d\n",
transaction_counter);
if ( _DEBUG_ ) printf ("%s: Scoreboard was terminated\n",my_agent_name);
active = 0;
fclose (Scoreboard_log_file_handle);
}
//------------------------------------------------------------------------------
/* AddTransToSB(Trace_trans trac) -
* This is the main function that adds transactions to the scoreboard
* and initiate all the checks.
*
* The task consists of the following stages:
* 1. Check validity of input transaction (scoreboard active, trans!=null, etc)
* 2. Translate the address and add the transaction to the queue
* 3. Start the checking mechanism
* 4. Start invalidation of old transactions mechanism
*/
task Scoreboard::AddTransToSB(Trace_trans trac)
{
Trace_trans_Q added_to_q;
/*****************************************************************************
* 1. Check validity of input transaction
****************************************************************************/
/*check our active status: do nothing if not active.*/
if (active == 0 || InitializationDone == 0){
return;
}
/*make sure it is not a null transaction*/
if (trac == null){
printf(" SCOREBOARD ERROR: Trace_trans trace was NULL in "
"call to Scoreboard::AddTransToSB ");
exit(1);
}
// If the transaction was valid => lock semaphore:
semaphore_get(WAIT, semID, 1);
/*****************************************************************************
* 2. Translate the address and add the transaction to the queue
****************************************************************************/
/* translate the address */
/* Some cases does not require translation: */
/*Check the operation. If it is a special command, do
* not translate the address
*/
if (trac.operation === SPEC_CMD){
bit err = HandleSpecCmd(trac);
if (err){
//printf("SCOREBOARD ERROR in HandleSpecCmd\n");
}
//relese semaphore before leaving!!
semaphore_put(semID,1);
return;
}
/*check if the address is in the area to be ignored by the scoreboard,
*before translation.
*/
if (ignoreAddress != null){
if (ignoreAddress.fallsInRange(trac.destinationAddr)){
if (trac.operation != SYNCH_STORE && trac.operation != SET_STORE){
Trace_trans_Freelist.push_front(trac);
}
if (_DEBUG_){
printf("Ignoring transaction:\n");
trac.LogMeToFileShort(stdout);
}
//relese semaphore before leaving!!
semaphore_put(semID,1);
return;
}
}
if (trac.senderID != MAINMEM_ID && trac.senderID != TESTER_ID )
{
trac.destinationAddr = TranslateAddress(trac.senderID, trac.destinationAddr, trac.operation);
}
/*is there already a queue at this address location?*/
if (!assoc_index(CHECK, Trace_Q_Array, trac.destinationAddr))
{
/*is there a value in the backup memory already?*/
if (!assoc_index(CHECK, BackupMem, trac.destinationAddr)){
Trace_Q_Array[trac.destinationAddr] =
getNewTraceTransQ(trac.destinationAddr, 0);
}
else{
Trace_Q_Array[trac.destinationAddr] =
getNewTraceTransQ(trac.destinationAddr,
1);
}
}
Trace_Q_Array[trac.destinationAddr].push_back(trac);
added_to_q = Trace_Q_Array[trac.destinationAddr];
transaction_counter = transaction_counter + 1;
/*****************************************************************************
* 3. Start the checking mechanism
****************************************************************************/
/*HACK: set the transactional flag here so check can use it.*/
if (trac.senderID < num_cpus
&& Tcc_Array[trac.senderID/CPUS_PER_TILE].valid
&& tccAddress.fallsInRange(trac.destinationAddr)){
trac.transactional = 1;
}
/*log the transaction to the Scoreboard log file*/
if (_DEBUG_){
trac.LogMeToFileShort(Scoreboard_log_file_handle);
if (trac.destinationAddr == INTERESTING){
fprintf(Scoreboard_log_file_handle, "INFO: BEFORE UPDATES\n");
Trace_Q_Array[trac.destinationAddr].logMeToFile(Scoreboard_log_file_handle);
}
}
CheckScoreboard(trac, added_to_q);
/*****************************************************************************
* 4. Start invalidation of old transactions mechanism
****************************************************************************/
UpdateScoreboard(trac, added_to_q);
if (_DEBUG_ > 15){
trac.LogMeToFileShort(Scoreboard_log_file_handle);
if (trac.destinationAddr == INTERESTING){
fprintf(Scoreboard_log_file_handle, "INFO: AFTER UPDATES\n");
Trace_Q_Array[trac.destinationAddr].logMeToFile(Scoreboard_log_file_handle);
}
}
// Finally, release semaphore before leaving
semaphore_put(semID,1);
}
//Lock an address to prevent garbage collection (ie at the start of a load)
task Scoreboard::LockAddress(integer senderID, bit [31:0] addr, integer operation){
/*check our active status: do nothing if not active.*/
if (active == 0 || InitializationDone == 0){
return;
}
// If the transaction was valid => lock semaphore:
//semaphore_get(WAIT, semID, 1);
/*check if the address is in the area to be ignored by the scoreboard,
*before translation.
*/
if (ignoreAddress != null){
if (ignoreAddress.fallsInRange(addr)){
//relese semaphore before leaving!!
//semaphore_put(semID,1);
return;
}
}
/*****************************************************************************
* 2. Translate the address and add the transaction to the queue
****************************************************************************/
/* translate the address */
/* Some cases does not require translation: */
if (senderID != MAINMEM_ID && senderID != TESTER_ID )
{
addr = TranslateAddress(senderID, addr, operation);
}
/*is there already a queue at this address location?*/
if (!assoc_index(CHECK, Trace_Q_Array, addr))
{
/*is there a value in the backup memory already?*/
if (!assoc_index(CHECK, BackupMem, addr)){
Trace_Q_Array[addr] = getNewTraceTransQ(addr, 0);
}
else{
Trace_Q_Array[addr] = getNewTraceTransQ(addr,1);
}
}
Trace_Q_Array[addr].lock(senderID);
}
task Scoreboard::UnlockAddress(integer senderID, bit [31:0] addr, integer operation){
/*check our active status: do nothing if not active.*/
if (active == 0 || InitializationDone == 0){
return;
}
// If the transaction was valid => lock semaphore:
//semaphore_get(WAIT, semID, 1);
/*check if the address is in the area to be ignored by the scoreboard,
*before translation.
*/
if (ignoreAddress != null){
if (ignoreAddress.fallsInRange(addr)){
//relese semaphore before leaving!!
//semaphore_put(semID,1);
return;
}
}
/*****************************************************************************
* 2. Translate the address and add the transaction to the queue
****************************************************************************/
/* translate the address */
/* Some cases does not require translation: */
if (senderID != MAINMEM_ID && senderID != TESTER_ID )
{
addr = TranslateAddress(senderID, addr, operation);
}
/*is there already a queue at this address location?*/
if (assoc_index(CHECK, Trace_Q_Array, addr))
{
Trace_Q_Array[addr].unlock(senderID);
}
}
//------------------------------------------------------------------------------
/* CompleteTransInSB(Trace_trans trac) -
* This is an external function, which should be called
* for stores which have a known commit time (synchronous stores).
* This is necessary because we want to put the store into the
* SB as soon as possible, but also want to use the information
* we get from knowing when a synch store completes.
*/
task Scoreboard::CompleteTransInSB(Trace_trans trac){
bit UpdateScoreboard_error = 1'b0;
if (active == 0 ){ //do nothing.
return;
}
/*make sure it is not a null transaction*/
if (trac == null){
printf(" SCOREBOARD ERROR: Trace_trans trace was NULL in "
"call to Scoreboard::CompleteTransInSB ");
exit(1);
}
/*currently this is only used for synchronous stores, where
* we know when they complete.
*/
if (trac.operation != SYNCH_STORE &&
trac.operation != SET_STORE){
return;
}
UpdateScoreboard_error = UpdateAfterSynchStore(trac);
if (UpdateScoreboard_error)
{
printf ("\n\nSCOREBOARD ERROR: t=%d: Scoreboard Error while doing updates in CompleteTransInSB\n", get_cycle());
if (Scoreboard_log_file_handle)
{
fprintf(Scoreboard_log_file_handle,"\n\nSCOREBOARD ERROR: t=%d: Scoreboard Error "
"while doing updates\n", get_cycle());
fprintf(Scoreboard_log_file_handle, " \n\n Current Queue at that Address:\n\n");
if (assoc_index(CHECK, Trace_Q_Array, trac.destinationAddr)){
Trace_Q_Array[trac.destinationAddr].logMeToFile(Scoreboard_log_file_handle);
}
}
scoreboard_fail ();
return;
}
}
/* SetMemBarInSB: external function which indicates that all earlier stores
* for this sender have completed. Iterate over all the scoreboard and set
* end times for outstanding stores. Mark any earlier stores invalid immediately.
*/
task Scoreboard::SetMemBarInSB(bit[63:0] cycle, integer senderID){
integer i;
integer jdx, idx;
integer qidx;
if (active == 0){
return;
}
i = 0;
semaphore_get(WAIT, semID, 1);
if (_DEBUG_){
printf("SetMemBarInSB called at cycle %d for sender %d\n", cycle, senderID);
if (Scoreboard_log_file_handle){
fprintf(Scoreboard_log_file_handle, "SetMemBarInSB called at cycle %d for sender %d\n", cycle, senderID);
}
}
foreach(Trace_Q_Array, qidx){
Trace_trans_Q q;
Trace_trans trac_to_membar;
q = Trace_Q_Array[qidx];
if (q == null){
continue;
}
for (jdx = 0; jdx < q.size(); jdx++){
bit latest_for_this_sender = 1;
trac_to_membar = q.at(jdx);
if (trac_to_membar.senderID == senderID){
if ((trac_to_membar.operation == S_STORE)
||(trac_to_membar.operation == SYNCH_STORE)
||(trac_to_membar.operation == RAW_STORE)
||(trac_to_membar.operation == SET_STORE)){
if ((trac_to_membar.operation == SYNCH_STORE || trac_to_membar.operation == SET_STORE) && trac_to_membar.timeEnd == INFINITY){
/*this is a sync-op that is still going, probably the one that caused this membar.*/
latest_for_this_sender = 0;
continue;
}
if (trac_to_membar.transactional){
latest_for_this_sender = 0;
continue;
}
trac_to_membar.timeEnd = trac_to_membar.timeEnd < cycle? trac_to_membar.timeEnd:cycle;
if (latest_for_this_sender){
latest_for_this_sender = 0;
}
else{
/*now can be more agrresive about the invalidation time for this, don't need to wait
* MaxStoreTime cycles.
*/
for (idx = 0; idx < num_cpus; idx ++){
trac_to_membar.is_valid_for_cpu[idx] = (trac_to_membar.is_valid_for_cpu[idx] < cycle?
trac_to_membar.is_valid_for_cpu[idx]:cycle);
}
}
}
}
}
}
semaphore_put(semID, 1);
}
//-------------------------------------------------------------------------------
/* CheckScoreboard:
* This task initiate all the checks for the given transaction
*/
task Scoreboard::CheckScoreboard(Trace_trans last_trans,
Trace_trans_Q added_to_q){
bit CheckScoreboard_error = 1'b0;
// Put all checks here in sequence. Each check must return 0 if good, 1 otherwise
//-------------------------------------------------------------------------------
CheckScoreboard_error = CheckScoreboard_error | CheckLastReceived(last_trans, added_to_q);
//CheckScoreboard_error = CheckScoreboard_error | CheckLastFullEmpty(last_trans);
//CheckScoreboard_error = CheckScoreboard_error | <my_second_check>();
//CheckScoreboard_error = CheckScoreboard_error | <my_third_check>();
// Finally, after all checks are done, look at the error bit and initiate an error message
//-------------------------------------------------------------------------------
if (CheckScoreboard_error)
{
printf ("\n\nSCOREBOARD ERROR: t=%d: ", get_cycle());
last_trans.PrintMeShort();
if (Scoreboard_log_file_handle)
{
fprintf(Scoreboard_log_file_handle,"\n\nSCOREBOARD ERROR: t=%d: Scoreboard Error for "
"received transaction:\n", get_cycle());
last_trans.LogMeToFileShort(Scoreboard_log_file_handle);
fprintf(Scoreboard_log_file_handle, " \n\n Current Queue at that Address:\n\n");
if (assoc_index(CHECK, Trace_Q_Array, last_trans.destinationAddr)){
Trace_Q_Array[last_trans.destinationAddr].logMeToFile(Scoreboard_log_file_handle);
}
scoreboard_fail();
return;
}
}
}
//-------------------------------------------------------------------------------
/* UpdateScoreboard:
* This task initiate all the updates for the scoreboard (i.e. invalidating old
* transactions etc).
*/
task Scoreboard::UpdateScoreboard(Trace_trans last_trans, Trace_trans_Q added_to_q)
{
bit UpdateScoreboard_error = 1'b0;
// Put all updates here in sequence. Each update must return 0 if good, 1 otherwise
//-------------------------------------------------------------------------------
UpdateScoreboard_error = UpdateScoreboard_error | UpdateTCC(last_trans, added_to_q);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateSimple(last_trans, added_to_q);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateAddToStoreQueue(last_trans);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateAfterRead(last_trans, added_to_q);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateAfterReadForOtherProcs(last_trans, added_to_q);
//UpdateScoreboard_error = UpdateScoreboard_error | UpdateAfterReadTSO(last_trans, added_to_q);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateRecordTransTime(last_trans);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateAfterStoreTimeBased(last_trans, added_to_q);
//UpdateScoreboard_error = UpdateScoreboard_error | UpdateAfterSynchStore(last_trans);
//UpdateScoreboard_error = UpdateScoreboard_error | UpdateAfterReadTimeBased(last_trans);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateAfterReadTCC(last_trans, added_to_q);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateFullEmpty(last_trans, added_to_q);
UpdateScoreboard_error = UpdateScoreboard_error | UpdateRemoveRead(last_trans, added_to_q);
//UpdateScoreboard_error = UpdateScoreboard_error | <my_third_update>();
// Finally, after all updates are done, look at the error bit and initiate an error message
//-------------------------------------------------------------------------------
if (UpdateScoreboard_error)
{
printf ("\n\nSCOREBOARD ERROR: t=%d: Scoreboard Error while doing updates\n", get_cycle());
if (Scoreboard_log_file_handle)
{
fprintf(Scoreboard_log_file_handle,"\n\nSCOREBOARD ERROR: t=%d: Scoreboard Error "
"while doing updates\n", get_cycle());
fprintf(Scoreboard_log_file_handle, " \n\n Current Queue at that Address:\n\n");
if (assoc_index(CHECK, Trace_Q_Array, last_trans.destinationAddr)){
Trace_Q_Array[last_trans.destinationAddr].logMeToFile(Scoreboard_log_file_handle);
}
}
scoreboard_fail();
return;
}
}
//-------------------------------------------------------------------------
//---------------------- Check tasks/functions
//-------------------------------------------------------------------------
/* CheckLastReceived -
* This is a chceck that make sure that the received LOAD transaction
* was previously saved.
* For this check, any older value stored is consider good.
* The function returns 0 if successful, 1 otherwise.
*/
function integer Scoreboard::CheckLastReceived(Trace_trans last_trans, Trace_trans_Q added_to_q)
{
integer jdx = 0;
integer q_size = 0;
bit[31:0] last_addr = last_trans.destinationAddr;
Trace_trans trac_to_compare_with;
integer value_was_not_stored;
/*keep track if this processor has done a store here,
* in case this is the first load. If the processor
* has not done a store and this is the first load,
* then allow it.
*/
bit this_proc_stored_here = 0;
// Initial return value is 1 (as in data not found)
CheckLastReceived = 1;
value_was_not_stored = 1;
/* This function only checks for regular S_LOAD transactions
* For any other case, return 0
* MAW- actually now it will check the simple part of the load
* transaction (is there some valid data?). Later other functions
* will check things like F/E bits or memory barrier operation.
*/
if ((last_trans.operation != S_LOAD)
&& (last_trans.operation != RAW_LOAD)
&& (last_trans.operation != SYNCH_LOAD)
&& (last_trans.operation != FUTURE_LOAD)
&& (last_trans.operation != RESET_LOAD))
{
CheckLastReceived = 0;
return;
}
// First make sure that this queue was ever used:
//if (assoc_index(CHECK, Trace_Q_Array, last_addr) && (Trace_Q_Array[last_addr] !=null))
if (added_to_q != null)
{
// Get the relevant queue size:
q_size = added_to_q.size();
// Now look at all earlier transactions
for (jdx = q_size-2; jdx >=0; jdx--) /* To Me:
* Trace_Q_Arr[last_addr].at(q_size-1)
* is the current trans (last_trans)
* and thus we start with jdx=q_size-2.
*/
{
trac_to_compare_with = added_to_q.at(jdx);
/* We now compare the current S_LOAD transaction with any S_STORE
* transaction which is valid for the sender cpu of this current S_LOAD
* transaction.
*/
if (trac_to_compare_with.operation == S_STORE ||
trac_to_compare_with.operation == RAW_STORE ||
trac_to_compare_with.operation == SYNCH_STORE ||
trac_to_compare_with.operation == SET_STORE){
if (last_trans.senderID >= 0 && last_trans.senderID <= num_cpus-1){
if((trac_to_compare_with.is_valid_for_cpu[last_trans.senderID] >= last_trans.timeStart))
{
if (last_trans.data == trac_to_compare_with.data)
{
value_was_not_stored = 0;
break; // if the value was found, no need to continue the loop
}
}
}
else {/*this transaction doesn't come from a processor. go easy on checking it*/
if (last_trans.data == trac_to_compare_with.data){
value_was_not_stored = 0;