File: snoopy.pml

package info (click to toggle)
spin 6.5.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,512 kB
  • sloc: ansic: 39,876; yacc: 1,021; makefile: 58; sh: 13
file content (263 lines) | stat: -rwxr-xr-x 5,021 bytes parent folder | download | duplicates (4)
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
/* Snooping cache algorithm
 * used in a study at Bell Labs in the early eighties, and
 * said to be based on Goodman's work. Compare for instance:
 * "Using cache memory to reduce processor memory traffic",
 * by J.R. Goodman,  Proc. 10th Int. Symp. on Computer Architecture,
 * June 1983, pp. 124-131.
 */

#define QSZ	2

mtype = {	r, w, raw,
		RD, WR, RX,
		MX, MXdone,
		req0, req1,
		CtoB, BtoC,
		grant, done
	};

chan tocpu0	= [QSZ] of { mtype };
chan fromcpu0	= [QSZ] of { mtype };
chan tobus0	= [QSZ] of { mtype };
chan frombus0	= [QSZ] of { mtype };
chan grant0	= [QSZ] of { mtype };

chan tocpu1	= [QSZ] of { mtype };
chan fromcpu1	= [QSZ] of { mtype };
chan tobus1	= [QSZ] of { mtype };
chan frombus1	= [QSZ] of { mtype };
chan grant1	= [QSZ] of { mtype };

chan claim0	= [QSZ] of { mtype };
chan claim1	= [QSZ] of { mtype };
chan release0	= [QSZ] of { mtype };
chan release1	= [QSZ] of { mtype };

#define W	1
#define R	2
#define X	3

proctype cpu0()
{
	xs fromcpu0;
	xr tocpu0;
	do
	:: fromcpu0!r   -> tocpu0?done
	:: fromcpu0!w   -> tocpu0?done
	:: fromcpu0!raw -> tocpu0?done
	od
}

proctype cpu1()
{
	xs fromcpu1;
	xr tocpu1;
	do
	:: fromcpu1!r   -> tocpu1?done
	:: fromcpu1!w   -> tocpu1?done
	:: fromcpu1!raw -> tocpu1?done
	od
}

proctype cache0()
{	byte state = X;
	byte which;

	xr frombus0;
	xr fromcpu0;
	xs tocpu0;
	xs tobus0;
	xr grant0;
	xs claim0;
	xs release0;
resume:
	do
	:: frombus0?RD ->
		if
		:: (state == W) -> state = R; tobus0!CtoB
		:: (state != W) -> tobus0!done
		fi
	:: frombus0?MX -> state = X; tobus0!MXdone
	:: frombus0?RX ->
		if
		:: (state == W) -> state = X; tobus0!CtoB
		:: (state == R) -> state = X; tobus0!done
		:: (state == X) -> tobus0!done
		fi

	:: fromcpu0?r ->
		if
		:: (state != X) -> tocpu0!done
		:: (state == X) -> which = RD; goto buscycle
		fi
	:: fromcpu0?w ->
		if
		:: (state == W) -> tocpu0!done
		:: (state != W) -> which = MX; goto buscycle
		fi
	:: fromcpu0?raw ->
		if
		:: (state == W) -> tocpu0!done
		:: (state != W) -> which = RX; goto buscycle
		fi
	od;
buscycle:
	claim0!req0;
	do
	:: frombus0?RD ->
		if
		:: (state == W) -> state = R; tobus0!CtoB
		:: (state != W) -> tobus0!done
		fi
	:: frombus0?MX -> state = X; tobus0!MXdone
	:: frombus0?RX ->
		if
		:: (state == W) -> state = X; tobus0!CtoB
		:: (state == R) -> state = X; tobus0!done
		:: (state == X) -> tobus0!done
		fi
	:: grant0?grant ->
		if
		:: (which == RD) -> state = R
		:: (which == MX) -> state = W
		:: (which == RX) -> state = W
		fi;
		tocpu0!done;
		break
	od;
	release0!done;

	if
	:: (which == RD) -> tobus0!RD -> frombus0?BtoC
	:: (which == MX) -> tobus0!MX -> frombus0?done
	:: (which == RX) -> tobus0!RX -> frombus0?BtoC
	fi;
	goto resume
}

proctype cache1()
{	byte state = X;
	byte which;

	xr frombus1;
	xr fromcpu1;
	xs tobus1;
	xs tocpu1;
	xr grant1;
	xs claim1;
	xs release1;
resume:
	do
	:: frombus1?RD ->
		if
		:: (state == W) -> state = R; tobus1!CtoB
		:: (state != W) -> tobus1!done
		fi
	:: frombus1?MX -> state = X; tobus1!MXdone
	:: frombus1?RX ->
		if
		:: (state == W) -> state = X; tobus1!CtoB
		:: (state == R) -> state = X; tobus1!done
		:: (state == X) -> tobus1!done
		fi

	:: fromcpu1?r ->
		if
		:: (state != X) -> tocpu1!done
		:: (state == X) -> which = RD; goto buscycle
		fi
	:: fromcpu1?w ->
		if
		:: (state == W) -> tocpu1!done
		:: (state != W) -> which = MX; goto buscycle
		fi
	:: fromcpu1?raw ->
		if
		:: (state == W) -> tocpu1!done
		:: (state != W) -> which = RX; goto buscycle
		fi
	od;
buscycle:
	claim1!req1;
	do
	:: frombus1?RD ->
		if
		:: (state == W) -> state = R; tobus1!CtoB
		:: (state != W) -> tobus1!done
		fi
	:: frombus1?MX -> state = X; tobus1!MXdone
	:: frombus1?RX ->
		if
		:: (state == W) -> state = X; tobus1!CtoB
		:: (state == R) -> state = X; tobus1!done
		:: (state == X) -> tobus1!done
		fi
	:: grant1?grant ->
		if
		:: (which == RD) -> state = R
		:: (which == MX) -> state = W
		:: (which == RX) -> state = W
		fi;
		tocpu1!done;
		break
	od;
	release1!done;

	if
	:: (which == RD) -> tobus1!RD -> frombus1?BtoC
	:: (which == MX) -> tobus1!MX -> frombus1?done
	:: (which == RX) -> tobus1!RX -> frombus1?BtoC
	fi;
	goto resume
}

proctype busarbiter()
{
	xs grant0;
	xs grant1;
	xr claim0;
	xr claim1;
	xr release0;
	xr release1;

	do
	:: claim0?req0 -> grant0!grant; release0?done
	:: claim1?req1 -> grant1!grant; release1?done
	od
}

proctype bus()		/* models real bus + main memory */
{
	xs frombus1;
	xs frombus0;
	xr tobus0;
	xr tobus1;

	do
	:: tobus0?CtoB -> frombus1!BtoC
	:: tobus1?CtoB -> frombus0!BtoC

	:: tobus0?done -> /* M -> B */ frombus1!BtoC
	:: tobus1?done -> /* M -> B */ frombus0!BtoC

	:: tobus0?MXdone -> /* B -> M */ frombus1!done
	:: tobus1?MXdone -> /* B -> M */ frombus0!done

	:: tobus0?RD -> frombus1!RD
	:: tobus1?RD -> frombus0!RD

	:: tobus0?MX -> frombus1!MX
	:: tobus1?MX -> frombus0!MX

	:: tobus0?RX -> frombus1!RX
	:: tobus1?RX -> frombus0!RX
	od
}

init {
	atomic {
		run cpu0(); run cpu1();
		run cache0(); run cache1();
		run bus(); run busarbiter()
	}
}