3
(include-book "cstate")
4
(include-book "pstate")
5
(include-book "lstate")
7
;; At this point we start associating cstates with pstates (because
8
;; processes alter connections).
10
(defun something-to-receive (hpid fd css)
11
(declare (xargs :guard (and (hpidp hpid)
14
(cond ((atom css) nil)
15
((and (equal hpid (third (first (car css))))
16
(equal fd (fourth (first (car css))))
17
(consp (inboxq (car css)))) t)
18
(t (something-to-receive hpid fd (cdr css)))))
20
(defun message-to-select (hpid css)
21
(declare (xargs :guard (and (hpidp hpid)
23
(cond ((atom css) nil)
24
((and (equal hpid (third (first (car css))))
25
(consp (inboxq (car css)))) t)
26
(t (message-to-select hpid (cdr css)))))
28
(in-theory (enable hpid-fdp))
30
(defun request-to-select (hpid lss)
31
(declare (xargs :guard (and (hpidp hpid)
33
(cond ((atom lss) nil)
34
((and (equal hpid (first (first (car lss))))
35
(consp (requestq (car lss)))) t)
36
(t (request-to-select hpid (cdr lss)))))
38
(in-theory (disable hpid-fdp))
40
(in-theory (enable statementp))
42
(defun pstate-status (ps css lss)
43
(declare (xargs :guard (and (pstatep ps)
46
(let ((stmt (if (zp (cc ps)) nil (ith (cc ps) (code ps)))))
47
(cond ((atom stmt) 'idle) ;; cc 0 or out of range
48
((equal (car stmt) 'receive)
49
(let ((fd (evl2 (second stmt) (memory ps))))
50
(cond ((not (fdp fd)) 'active) ;; handle error elsewhere
51
(t (if (something-to-receive (car ps) fd css)
53
((equal (car stmt) 'select)
54
(if (or (message-to-select (car ps) css)
55
(request-to-select (car ps) lss))
57
;; We should also check here if the process is waiting for
58
;; a connect or waiting for an accept. As it is, the
59
;; simulator will attempt these, so it might spin.
62
(in-theory (disable statementp))
64
(defun waiting-pstates (pss css lss)
65
;; Return the number of processes hanging in receive or select.
66
(declare (xargs :guard (and (pstate-listp pss)
70
(t (+ (if (equal (pstate-status (car pss) css lss)
72
(waiting-pstates (cdr pss) css lss)))))
74
(defun active-pstates (pss css lss)
75
;; Return the number of processes with something to do.
76
(declare (xargs :guard (and (pstate-listp pss)
80
(t (+ (if (equal (pstate-status (car pss) css lss)
82
(active-pstates (cdr pss) css lss)))))
84
(defun ith-active-pstate (n pss css lss) ;; This counts from 1.
85
(declare (xargs :guard (and (pos-integerp n)
89
(cond ((atom pss) nil)
90
((equal (pstate-status (car pss) css lss) 'active)
93
(ith-active-pstate (- n 1) (cdr pss) css lss)))
94
(t (ith-active-pstate n (cdr pss) css lss))))
96
(defthm ith-active-pstate-properties
97
(implies (and (pstate-listp pss)
102
(<= n (active-pstates pss css lss)))
103
(and (pstatep (ith-active-pstate n pss css lss))
104
(member-equal (ith-active-pstate n pss css lss) pss)))
106
:in-theory (disable pstatep))))
108
;;----------------------------------------
109
;; prog: (program-name program-code)
112
(declare (xargs :guard t))
118
(defun program-listp (x)
119
(declare (xargs :guard t))
120
(cond ((atom x) (null x))
121
(t (and (progp (car x))
122
(program-listp (cdr x))))))
124
(defthm program-listp-is-alistp
125
(implies (program-listp pgms)
127
:rule-classes :forward-chaining)
129
;;----------------------------------------
130
;; mstate -- multiprocess state
133
(declare (xargs :guard t))
134
(and (equal (len x) 4)
135
(pstate-listp (first x))
136
(cstate-listp (second x))
137
(lstate-listp (third x))
138
(program-listp (fourth x))))
140
(defun pstates (ms) ;; get the list of pstates from an mstate
141
(declare (xargs :guard (mstatep ms)))
144
(defun cstates (ms) ;; get the list of cstates from an mstate
145
(declare (xargs :guard (mstatep ms)))
148
(defun lstates (ms) ;; get the list of lstates from an mstate
149
(declare (xargs :guard (mstatep ms)))
152
(defun programs (ms) ;; get the list of programs from an mstate
153
(declare (xargs :guard (mstatep ms)))
156
(defun update-pstates (ms pss)
157
(declare (xargs :guard (and (mstatep ms)
158
(pstate-listp pss))))
159
(update-first ms pss))
161
(defun update-cstates (ms css)
162
(declare (xargs :guard (and (mstatep ms)
163
(cstate-listp css))))
164
(update-second ms css))
166
(defun update-lstates (ms lss)
167
(declare (xargs :guard (and (mstatep ms)
168
(lstate-listp lss))))
169
(update-third ms lss))
175
((lutra 320) ((asgn z 6)) 13 nil ((x . 4) (y . 6)))
176
((gyro 440) ((procedure handle)) 14 nil nil)
180
(((lutra 320) 5 (gyro 440) 6) ('m3 'm4) ('m1 'm2))
183
(((gyro 440) 15) 8585 nil)
184
(((lutra 320) 14) 7483 (((cosmo 354) 16)))
185
(((donner 320) 17) 3535 (((fire 444) 18)))
191
(defthm true-listp-append-list
192
(true-listp (append a (list x))))
194
(defthm evaluated-expression-append
195
(implies (and (evaluated-expression-listp a)
196
(evaluated-expressionp x))
197
(evaluated-expression-listp (append a (list x)))))
199
(defun deliver-message (ms cs)
200
(declare (xargs :guard (and (mstatep ms)
202
(member-equal cs (cstates ms))
203
(message-to-transfer cs))))
208
(transfer-message cs)
215
((lutra 320) ((asgn z 6)) 13 nil ((x . 4) (y . 6)))
216
((gyro 440) ((procedure handle)) 14 nil nil)
219
(((lutra 320) 5 (gyro 440) 6) ('m3 'm4) ('m1 'm2))
224
'(((lutra 320) 5 (gyro 440) 6) ('m3 'm4) ('m1 'm2)))
227
(defthm mstatep-deliver-message
228
(implies (and (mstatep ms)
230
(mstatep (deliver-message ms cs))))
234
(defun make-mstate (pstates cstates lstates programs)
235
(declare (xargs :guard (and (pstate-listp pstates)
236
(cstate-listp cstates)
237
(lstate-listp lstates)
238
(program-listp programs)
240
(list pstates cstates lstates programs))