-
Notifications
You must be signed in to change notification settings - Fork 2
/
C3D.m
1247 lines (1025 loc) · 31.8 KB
/
C3D.m
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
--------------------------------------------------------------------------------
-- Murphi model of C3D protocol:
-- Cheng-Chieh Huang, Rakesh Kumar, Marco Elver, Boris Grot, and Vijay Nagarajan.
-- C3D: Mitigating the NUMA Bottleneck via Coherent DRAM Caches.
-- In IEEE/ACM International Symposium on Microarchitecture (MICRO).
-- Taipei, Taiwan, October 2016.
--
-- Coding convention:
-- * All non-function keywords are lowercase!
-- * All globals (types, functions) are UpperCase.
-- * All variables are lower_case.
-- * Constants (as well as enum constants) are ALL_CAPS.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Constants {{{
--------------------------------------------------------------------------------
const
-- Number of sockets, each with its own private LLCache and DRAMCache.
NODE_COUNT: 3;
DATA_VALUES: 2;
-- Network parameters.
VC_REQ: 0; -- Lowest priority
VC_RES: 1;
VC_UNB: 2; -- Highest priority
NUM_VCS: 3; -- Must match number of VCs above
NET_MAX: (NODE_COUNT * 2) + 1; -- One for each of LLCache and DRAMCache + Directory.
-- }}}
--------------------------------------------------------------------------------
-- Types {{{
--------------------------------------------------------------------------------
type
Socket: scalarset(NODE_COUNT);
Directory: enum { DirMem };
Node: union { Directory, Socket };
Level: enum { DRAMCache, LLCache };
Value: scalarset(DATA_VALUES);
VCType: 0..NUM_VCS-1;
MessageType: enum {
DATA,
DATA_ACK,
DOWNGRADE,
DOWNGRADE_ACK,
GETS,
GETX,
UPGRADE,
UPGRADE_ACK,
INV,
INV_ACK,
LOAD,
PUTX,
PUT_ACK,
REPLACEMENT,
STORE
};
Message:
record
mtype: MessageType;
dst_lvl: Level;
src: Node;
src_lvl: Level;
vc: VCType;
data: Value;
end;
DirectoryState:
record
state: enum {
DIR_I, -- Stable: INVALID
DIR_IM_IA, -- I->M waiting for INV_ACKs
DIR_IM_DA, -- I->M waiting for DATA_ACK
DIR_S, -- Stable: SHARED
DIR_SM_IA, -- S->M waiting for INV_ACKs
DIR_SM_DA, -- S->M waiting for DATA_ACK
DIR_SM_U_IA,-- S->M (via UPGRADE) waiting for INV_ACKs
DIR_M, -- Stable: MODIFIED
DIR_MM_P, -- M->M waiting for PUTX
DIR_MM_DA, -- M->M waiting for DATA_ACK
DIR_MS2, -- M->S waiting for DOWNGRADE_ACK AND PUTX
DIR_MS1, -- M->S waiting for DOWNGRADE_ACK OR PUTX
DIR_MI -- M->I
};
owner: Socket;
sharers: multiset [NODE_COUNT] of Socket;
need_acks: 0..(NODE_COUNT*2);
data: Value;
end;
DRAMCacheState:
record
state: enum {
DC_I, -- Stable: INVALID
DC_IS, -- I->S
DC_IS_I, -- I->S sunk INV ->I
DC_IM, -- I->M
DC_S, -- Stable: SHARED
DC_M, -- Stable: MODIFIED (in L1)
DC_SM, -- S->M
DC_SM_U -- S->M (via UPGRADE)
};
data: Value;
end;
LLCacheState:
record
state: enum {
LLC_I, -- Stable: INVALID
LLC_IS, -- I->S
LLC_IS_I,-- I->S sunk INV ->I
LLC_IM, -- I->M
LLC_IM_S,-- I->M sunk DOWNGRADE ->S
LLC_S, -- Stable: SHARED
LLC_SM, -- S->M
LLC_M, -- Stable: MODIFIED
LLC_MI, -- M->I
LLC_MS -- M->S
};
data: Value;
write: Value;
end;
-- }}}
--------------------------------------------------------------------------------
-- Variables {{{
--------------------------------------------------------------------------------
var
net: array [Node] of multiset [NET_MAX] of Message;
sockets: array [Socket] of
record
dc: DRAMCacheState;
l1c: LLCacheState;
end;
dir: DirectoryState;
-- Auxiliary variables.
aux_last_write: Value;
-- }}}
--------------------------------------------------------------------------------
-- Common functions {{{
--------------------------------------------------------------------------------
procedure Send(mtype:MessageType;
dst:Node;
dst_lvl:Level;
src:Node;
src_lvl:Level;
vc:VCType;
data:Value);
var
msg:Message;
begin
Assert (MultiSetCount(i:net[dst], true) < NET_MAX) "Too many messages";
msg.mtype := mtype;
msg.dst_lvl := dst_lvl;
msg.src := src;
msg.src_lvl := src_lvl;
msg.vc := vc;
msg.data := data;
MultiSetAdd(msg, net[dst]);
end;
procedure ErrorUnhandledMsg();
begin
Error "Unhandled message type!";
end;
procedure ErrorUnhandledState();
begin
Error "Unhandled state!";
end;
-- }}}
--------------------------------------------------------------------------------
-- Directory functions {{{
--------------------------------------------------------------------------------
procedure AddToSharersList(s:Socket);
begin
if MultiSetCount(i:dir.sharers, dir.sharers[i] = s) = 0
then
MultiSetAdd(s, dir.sharers);
endif;
end;
procedure RemoveFromSharersList(s:Socket);
begin
MultiSetRemovePred(i:dir.sharers, dir.sharers[i] = s);
end;
procedure SelectiveBroadcastToSockets(t:MessageType;
dst_lvl:Level;
source:Socket;
vc:VCType);
begin
for n:Node do
if (IsMember(n, Socket) &
MultiSetCount(i:dir.sharers, dir.sharers[i] = n) != 0)
then
if n != source then
if IsUndefined(dst_lvl) then
Send(t, n, LLCache, DirMem, UNDEFINED, vc, UNDEFINED);
Send(t, n, DRAMCache, DirMem, UNDEFINED, vc, UNDEFINED);
else
Send(t, n, dst_lvl, DirMem, UNDEFINED, vc, UNDEFINED);
endif;
endif;
RemoveFromSharersList(n);
endif;
endfor;
end;
procedure BroadcastToSockets(t:MessageType;
dst_lvl:Level;
source:Socket;
vc:VCType);
begin
for n:Node do
if IsMember(n, Socket) then
if n != source then
if IsUndefined(dst_lvl) then
Send(t, n, LLCache, DirMem, UNDEFINED, vc, UNDEFINED);
Send(t, n, DRAMCache, DirMem, UNDEFINED, vc, UNDEFINED);
else
Send(t, n, dst_lvl, DirMem, UNDEFINED, vc, UNDEFINED);
endif;
endif;
endif;
endfor;
end;
function DirectoryReceive(msg:Message) : boolean;
var
num_sharers:0..NODE_COUNT;
is_src_sharer:0..1;
event:MessageType;
begin
num_sharers := MultiSetCount(i:dir.sharers, true);
if MultiSetCount(i:dir.sharers, dir.sharers[i] = msg.src) != 0 then
is_src_sharer := 1;
else
is_src_sharer := 0;
endif;
event := msg.mtype;
switch dir.state
case DIR_I:
switch event
case GETS:
Send(DATA, msg.src, msg.src_lvl, DirMem, UNDEFINED, VC_RES, dir.data);
case GETX:
BroadcastToSockets(INV, DRAMCache, msg.src, VC_REQ);
dir.owner := msg.src;
dir.state := DIR_IM_IA;
dir.need_acks := NODE_COUNT - 1;
case UPGRADE:
BroadcastToSockets(INV, DRAMCache, msg.src, VC_REQ);
dir.owner := msg.src;
-- Possibly modified by other and line evicted since request.
dir.state := DIR_IM_IA;
dir.need_acks := NODE_COUNT - 1;
else
ErrorUnhandledMsg();
endswitch;
case DIR_IM_IA:
switch event
case GETS:
-- stall
return false;
case GETX:
-- stall
return false;
case UPGRADE:
return false;
case INV_ACK:
dir.need_acks := dir.need_acks - 1;
if dir.need_acks = 0 then
Send(DATA, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_RES, dir.data);
dir.state := DIR_IM_DA;
endif;
else
ErrorUnhandledMsg();
endswitch;
case DIR_IM_DA:
switch event
case GETS:
-- stall
return false;
case GETX:
-- stall
return false;
case UPGRADE:
return false;
case DATA_ACK:
dir.state := DIR_M;
case PUTX:
-- XXX: Copy data to memory.
dir.data := msg.data;
Send(PUT_ACK, msg.src, LLCache, DirMem, UNDEFINED, VC_UNB, UNDEFINED);
dir.state := DIR_MI;
else
ErrorUnhandledMsg();
endswitch;
case DIR_S:
switch event
case GETS:
AddToSharersList(msg.src);
Send(DATA, msg.src, msg.src_lvl, DirMem, UNDEFINED, VC_RES, dir.data);
case GETX:
if is_src_sharer = 1 & num_sharers = 1 then
Error "IMPOSSIBLE";
--Send(DATA, msg.src, msg.src_lvl, DirMem, UNDEFINED, VC_RES, dir.data);
--dir.owner := msg.src;
--undefine dir.sharers;
--dir.state := DIR_M;
else
SelectiveBroadcastToSockets(INV, DRAMCache, msg.src, VC_REQ);
dir.owner := msg.src;
dir.state := DIR_SM_IA;
dir.need_acks := num_sharers - is_src_sharer;
endif;
case UPGRADE:
if is_src_sharer = 1 & num_sharers = 1 then
Error "IMPOSSIBLE";
--Send(UPGRADE_ACK, msg.src, msg.src_lvl, DirMem, UNDEFINED, VC_RES, UNDEFINED);
--dir.owner := msg.src;
--undefine dir.sharers;
--dir.state := DIR_M;
else
SelectiveBroadcastToSockets(INV, DRAMCache, msg.src, VC_REQ);
dir.owner := msg.src;
if is_src_sharer = 1 then
dir.state := DIR_SM_U_IA;
else
dir.state := DIR_SM_IA;
endif;
dir.need_acks := num_sharers - is_src_sharer;
endif;
else
ErrorUnhandledMsg();
endswitch;
case DIR_SM_IA:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case INV_ACK:
dir.need_acks := dir.need_acks - 1;
if dir.need_acks = 0 then
Send(DATA, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_RES, dir.data);
dir.state := DIR_SM_DA;
endif;
else
ErrorUnhandledMsg();
endswitch;
case DIR_SM_DA:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case PUTX:
-- XXX: Copy data to memory.
dir.data := msg.data;
Send(PUT_ACK, msg.src, LLCache, DirMem, UNDEFINED, VC_UNB, UNDEFINED);
dir.state := DIR_MI;
case DATA_ACK:
dir.state := DIR_M;
else
ErrorUnhandledMsg();
endswitch;
case DIR_SM_U_IA:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case INV_ACK:
dir.need_acks := dir.need_acks - 1;
if dir.need_acks = 0 then
Send(UPGRADE_ACK, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_RES, UNDEFINED);
dir.state := DIR_SM_DA;
endif;
else
ErrorUnhandledMsg();
endswitch;
case DIR_M:
Assert (IsUndefined(dir.owner) = false) "No owner, but line is in M";
switch event
case GETS:
Send(DOWNGRADE, dir.owner, LLCache, DirMem, UNDEFINED, VC_REQ, UNDEFINED);
AddToSharersList(msg.src);
AddToSharersList(dir.owner);
-- Use owner field as temporary storage for who to send to.
dir.owner := msg.src;
dir.state := DIR_MS2;
case GETX:
Send(INV, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_REQ, UNDEFINED);
undefine dir.sharers;
dir.owner := msg.src;
dir.state := DIR_MM_P;
case UPGRADE:
Send(INV, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_REQ, UNDEFINED);
undefine dir.sharers;
dir.owner := msg.src;
dir.state := DIR_MM_P;
case PUTX:
-- XXX: Copy data to memory
dir.data := msg.data;
Send(PUT_ACK, msg.src, LLCache, DirMem, UNDEFINED, VC_UNB, UNDEFINED);
undefine dir.sharers;
undefine dir.owner;
dir.state := DIR_I;
else
ErrorUnhandledMsg();
endswitch;
case DIR_MM_P:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case PUTX:
-- XXX: Do *not* copy data to memory, but forward on to new owner.
Send(DATA, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_RES, msg.data);
dir.state := DIR_MM_DA;
else
ErrorUnhandledMsg();
endswitch;
case DIR_MM_DA:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case PUTX:
-- XXX: Copy data to memory.
dir.data := msg.data;
Send(PUT_ACK, msg.src, LLCache, DirMem, UNDEFINED, VC_UNB, UNDEFINED);
dir.state := DIR_MI;
case DATA_ACK:
dir.state := DIR_M;
else
ErrorUnhandledMsg();
endswitch;
case DIR_MS2:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case DOWNGRADE_ACK:
dir.state := DIR_MS1;
case PUTX:
-- XXX: Copy data to memory
dir.data := msg.data;
dir.state := DIR_MS1;
else
ErrorUnhandledMsg();
endswitch;
case DIR_MS1:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case DOWNGRADE_ACK:
Send(DATA, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_RES, dir.data);
Send(PUT_ACK, msg.src, LLCache, DirMem, UNDEFINED, VC_UNB, UNDEFINED);
undefine dir.owner;
dir.state := DIR_S;
case PUTX:
-- XXX: Copy data to memory
dir.data := msg.data;
Send(DATA, dir.owner, DRAMCache, DirMem, UNDEFINED, VC_RES, dir.data);
Send(PUT_ACK, msg.src, LLCache, DirMem, UNDEFINED, VC_UNB, UNDEFINED);
undefine dir.owner;
dir.state := DIR_S;
else
ErrorUnhandledMsg();
endswitch;
case DIR_MI:
switch event
case GETS:
return false;
case GETX:
return false;
case UPGRADE:
return false;
case PUTX:
-- XXX: Copy data to memory
dir.data := msg.data;
undefine dir.sharers;
undefine dir.owner;
dir.state := DIR_I;
case DATA_ACK:
undefine dir.sharers;
undefine dir.owner;
dir.state := DIR_I;
case INV_ACK:
undefine dir.sharers;
undefine dir.owner;
dir.state := DIR_I;
else
ErrorUnhandledMsg();
endswitch;
else
ErrorUnhandledState();
endswitch;
return true;
end;
-- }}}
--------------------------------------------------------------------------------
-- DRAMCache functions {{{
--------------------------------------------------------------------------------
function DRAMCacheReceive(msg:Message; s:Socket) : boolean;
var
event:MessageType;
begin
alias dc:sockets[s].dc do
event := msg.mtype;
switch dc.state
case DC_I:
switch event
case GETS:
Send(GETS, DirMem, UNDEFINED, s, DRAMCache, VC_REQ, UNDEFINED);
dc.state := DC_IS;
case GETX:
Send(GETX, DirMem, UNDEFINED, s, DRAMCache, VC_REQ, UNDEFINED);
dc.state := DC_IM;
case UPGRADE:
Send(UPGRADE, DirMem, UNDEFINED, s, DRAMCache, VC_REQ, UNDEFINED);
dc.state := DC_SM_U;
case PUTX:
Send(PUTX, DirMem, UNDEFINED, s, DRAMCache, VC_RES, msg.data);
--dc.state := DC_S; -- enabling this causes a SWMR violation!
case INV:
Send(INV, s, LLCache, msg.src, msg.src_lvl, msg.vc, UNDEFINED);
else
ErrorUnhandledMsg();
endswitch;
case DC_IS:
switch event
case PUTX:
-- XXX: Do *not* copy data to D$.
/*
Race between L1 Replacement PUTX, Directory INV and a new request
by L1. The directory will block until this request has arrived.
*/
-- Forward
Send(PUTX, DirMem, UNDEFINED, msg.src, msg.src_lvl, VC_RES, msg.data);
case INV:
Send(INV, s, LLCache, msg.src, msg.src_lvl, msg.vc, UNDEFINED);
dc.state := DC_IS_I;
case DATA:
-- XXX: Put data in D$
dc.data := msg.data;
Send(DATA, s, LLCache, s, DRAMCache, VC_RES, dc.data);
dc.state := DC_S;
else
ErrorUnhandledMsg();
endswitch;
case DC_IS_I:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, DRAMCache, VC_UNB, UNDEFINED);
case DATA:
-- XXX: No need to put data in D$
Send(DATA, s, LLCache, s, DRAMCache, VC_RES, msg.data);
dc.state := DC_I;
else
ErrorUnhandledMsg();
endswitch;
case DC_IM:
switch event
case PUTX:
-- XXX: Do *not* copy data to D$.
/*
Race between L1 Replacement PUTX, Directory INV and a new request
by L1. The directory will block until this request has arrived.
*/
-- Forward
Send(PUTX, DirMem, UNDEFINED, msg.src, msg.src_lvl, VC_RES, msg.data);
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, DRAMCache, VC_UNB, UNDEFINED);
case DATA:
-- XXX: Put data in D$
dc.data := msg.data;
Send(DATA, s, LLCache, s, DRAMCache, VC_RES, dc.data);
dc.state := DC_M;
else
ErrorUnhandledMsg();
endswitch;
case DC_S:
switch event
case GETS:
Send(DATA, msg.src, msg.src_lvl, s, DRAMCache, VC_RES, dc.data);
case GETX:
--Send(UPGRADE, DirMem, UNDEFINED, s, DRAMCache, VC_REQ, UNDEFINED);
Send(GETX, DirMem, UNDEFINED, s, DRAMCache, VC_REQ, UNDEFINED);
dc.state := DC_SM;
case UPGRADE:
Send(UPGRADE, DirMem, UNDEFINED, s, DRAMCache, VC_REQ, UNDEFINED);
dc.state := DC_SM_U;
case INV:
Send(INV, s, LLCache, msg.src, msg.src_lvl, msg.vc, UNDEFINED);
dc.state := DC_I;
undefine dc.data;
else
ErrorUnhandledMsg();
endswitch;
case DC_M:
switch event
case PUTX:
-- XXX: Update data in D$
dc.data := msg.data;
Send(PUTX, DirMem, UNDEFINED, s, DRAMCache, VC_RES, dc.data);
dc.state := DC_S;
case INV:
Send(INV, s, LLCache, msg.src, msg.src_lvl, msg.vc, UNDEFINED);
dc.state := DC_I;
undefine dc.data;
else
ErrorUnhandledMsg();
endswitch;
case DC_SM:
switch event
case INV:
Send(INV, s, LLCache, msg.src, msg.src_lvl, msg.vc, UNDEFINED);
dc.state := DC_IM;
case DATA:
-- XXX: Copy data
dc.data := msg.data;
Send(DATA, s, LLCache, s, DRAMCache, VC_RES, dc.data);
dc.state := DC_M;
--case UPGRADE_ACK:
-- -- LLCache did not have data, but DRAMCache did.
-- Send(DATA, s, LLCache, s, DRAMCache, VC_RES, dc.data);
-- dc.state := DC_M;
else
ErrorUnhandledMsg();
endswitch;
case DC_SM_U:
switch event
case INV:
Send(INV, s, LLCache, msg.src, msg.src_lvl, msg.vc, UNDEFINED);
dc.state := DC_IM;
case DATA:
-- XXX: Copy data
dc.data := msg.data;
Send(DATA, s, LLCache, s, DRAMCache, VC_RES, dc.data);
dc.state := DC_M;
case UPGRADE_ACK:
Send(UPGRADE_ACK, s, LLCache, s, DRAMCache, VC_RES, UNDEFINED);
dc.state := DC_M;
else
ErrorUnhandledMsg();
endswitch;
else
ErrorUnhandledState();
endswitch;
endalias;
return true;
end;
-- }}}
--------------------------------------------------------------------------------
-- LLCache functions {{{
--------------------------------------------------------------------------------
procedure SatisfyInitialRequest(observed:Value; write:Value);
begin
Assert (observed = aux_last_write) "[Safety] SC PER LOCATION";
if !IsUndefined(write) then
aux_last_write := write;
endif;
end;
function LLCacheReceive(msg:Message; s:Socket) : boolean;
var
event:MessageType;
begin
alias l1c:sockets[s].l1c do
event := msg.mtype;
switch l1c.state
case LLC_I:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
case PUT_ACK:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
else
ErrorUnhandledMsg();
endswitch;
case LLC_IS:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_IS_I;
case PUT_ACK:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_IS_I;
case DATA:
-- XXX: Copy data
SatisfyInitialRequest(msg.data, UNDEFINED);
l1c.data := msg.data;
l1c.state := LLC_S;
else
ErrorUnhandledMsg();
endswitch;
case LLC_IS_I:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
case DATA:
/*
The SatisfyInitialRequest check here would fail as we are checking for SC PER
LOCATION in physical time, but is legal as we are only really interested in SC
PER LOCATION in logical time.
Lemma 1: SC PER LOCATION is not violated after Read in I state that is
satisfied after DATA receipt in IS.
Proof: Via Murphi (see IS.DATA). QED.
Lemma 2: SC PER LOCATION is not violated after Read in I state that is
satisfied after DATA receipt in IS_I.
Proof: Let's assume that the DATA response message contains a stale value (i.e.
not the latest or last seen value). This would imply that we may also violate
SC PER LOCATION after a IS.DATA transition, as the only transition to IS_I is
via an INV in IS that has overtaken an *already in-flight* DATA response.
This, however, contradicts Lemma 1. QED.
*/
-- XXX: No need to copy data.
--SatisfyInitialRequest(msg.data, UNDEFINED);
l1c.state := LLC_I;
else
ErrorUnhandledMsg();
endswitch;
case LLC_IM:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
case PUT_ACK:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
case DOWNGRADE:
Send(DOWNGRADE_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_IM_S;
case DATA:
SatisfyInitialRequest(msg.data, l1c.write);
l1c.data := l1c.write;
undefine l1c.write;
Send(DATA_ACK, DirMem, UNDEFINED, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_M;
else
ErrorUnhandledMsg();
endswitch;
case LLC_IM_S:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
case DATA:
-- XXX: Modify data, and then immediately send again with PUTX.
SatisfyInitialRequest(msg.data, l1c.write);
l1c.data := l1c.write;
undefine l1c.write;
Send(PUTX, s, DRAMCache, s, LLCache, VC_RES, l1c.data);
l1c.state := LLC_MS;
else
ErrorUnhandledMsg();
endswitch;
case LLC_S:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_I;
undefine l1c.data;
else
ErrorUnhandledMsg();
endswitch;
case LLC_SM:
switch event
case INV:
Send(INV_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_IM;
case DATA:
SatisfyInitialRequest(msg.data, l1c.write);
l1c.data := l1c.write;
undefine l1c.write;
Send(DATA_ACK, DirMem, UNDEFINED, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_M;
case UPGRADE_ACK:
SatisfyInitialRequest(l1c.data, l1c.write);
l1c.data := l1c.write;
undefine l1c.write;
Send(DATA_ACK, DirMem, UNDEFINED, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_M;
else
ErrorUnhandledMsg();
endswitch;
case LLC_M:
switch event
case DOWNGRADE:
Send(PUTX, s, DRAMCache, s, LLCache, VC_RES, l1c.data);
Send(DOWNGRADE_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
l1c.state := LLC_MS;
case INV:
Send(PUTX, DirMem, UNDEFINED, s, LLCache, VC_RES, l1c.data);
l1c.state := LLC_I;
undefine l1c.data;
else
ErrorUnhandledMsg();
endswitch;
case LLC_MI:
switch event
case DOWNGRADE:
Send(DOWNGRADE_ACK, msg.src, msg.src_lvl, s, LLCache, VC_UNB, UNDEFINED);
case INV:
l1c.state := LLC_I;
case PUT_ACK:
l1c.state := LLC_I;
else
ErrorUnhandledMsg();
endswitch;
case LLC_MS:
switch event
case PUT_ACK:
l1c.state := LLC_S;