3
;; Generic Scheduling Module of GeNoC
5
;; File: GeNoC-scheduling.lisp
6
;; Amr HELMY Revised and modified January 24th 2008
7
;;edited by Amr HELMY, Laurence Pierre august 22nd of august 2007
12
(begin-book);$ACL2s-Preamble$|#
15
(include-book "GeNoC-nodeset")
16
(include-book "GeNoC-misc") ;; imports also GeNoC-types
17
(include-book "GeNoC-ntkstate")#|ACL2s-ToDo-Line|#
19
;; Inputs: TrLst = ( ... (Id org frm route) ...), measure, NodeSet, and
20
;; the current network state
21
;; outputs: TrLst updated, arrived missives, new state of the network,
25
(defspec GenericScheduling
26
;; Function Scheduling represents the scheduling policy of the
28
;; arguments: TrLst measure P
29
;; outputs: newTrLst Arrived newP newMeasure
30
(((scheduling * * * *) => (mv * * * *))
31
((get_next_priority *)=> *)
32
((scheduling-assumptions * * * *) => *)
33
((legal-measure * * * * *) => *)
34
((initial-measure * * * *) => *))
36
(local (defun get_next_priority (port)
38
(local (defun scheduling-assumptions (TrLst NodeSet ntkstate order)
39
(declare (ignore TrLst NodeSet ntkstate order))
41
(local (defun legal-measure (measure trlst nodeset ntkstate order)
42
(declare (ignore measure trlst nodeset ntkstate order))
44
(local (defun initial-measure (trlst nodeset ntkstate order)
45
(declare (ignore trlst nodeset ntkstate order))
47
(local (defun scheduling (TrLst NodeSet ntkstate order)
51
(if (not (scheduling-assumptions TrLst NodeSet ntkstate order))
55
;(if (is-base-measure measure)
64
;; Proof obligations (also named constraints)
65
;; -----------------------------------------
66
(defthm scheduled-nil-nil
67
;; the result of the scheduling function in the case of empty
68
;; input list is equal to nil
69
(equal (car (scheduling nil nodeset ntkstate order)) nil))
71
;; 1/ Types of newTrLst, Arrived and P (state)
72
;; ---------------------------------
73
;; The type of newTrLst is a valid traveling missives list
75
(defthm tmissivesp-newTrlst
76
(implies (trlstp TrLst nodeset)
77
(tmissivesp (mv-nth 0 (scheduling TrLst NodeSet ntkstate order))
80
;; so is the list of Arrived
81
(defthm trlstp-Arrived ;; OK
82
(implies (trlstp TrLst nodeset)
83
(trlstp (mv-nth 1 (scheduling TrLst NodeSet ntkstate order))
86
;; the state list P is a ValidState
87
(defthm Valid-state-ntkstate
88
(implies (validstate ntkstate)
89
(validstate (mv-nth 3 (scheduling TrLst NodeSet ntkstate order)))))
92
;; 2/ the measure provided to GeNoC must be decreasing.
93
;; ------------------------------------------------------
94
;; scheduling-assumptions must be a boolean
95
(defthm booleanp-assumptions
96
(booleanp (scheduling-assumptions TrLst NodeSet ntkstate order))
97
:rule-classes :type-prescription)
99
;; legal-measure nust be a boolean
100
(defthm booleanp-legal-measure
101
(booleanp (legal-measure measure trlst nodeset ntkstate order))
102
:rule-classes :type-prescription)
104
;; the measure must decrease on each call of scheduling
105
(defthm measure-decreases
106
(implies (and (legal-measure measure trlst nodeset ntkstate order)
107
(scheduling-assumptions trlst NodeSet ntkstate order))
108
(O< (acl2-count (mv-nth 2 (scheduling TrLst NodeSet ntkstate order)))
109
(acl2-count measure))))
112
;; 3/ Correctness of the arrived missives
113
;; ------------------------------------------------------------------
114
;; For any arrived missive arr, there exists a unique travel
115
;; tr in the initial TrLst, such that IdV(arr) = IdV(tr)
116
;; and FrmV(arr) = FrmV(tr) and RoutesV(arr) is a
117
;; sublist of RoutesV(tr).
118
;; In ACL2, the uniqueness of the ids is given by the predicate
120
;; -------------------------------------------------------------------
122
;; First, let us define this correctness
123
(defun s/d-travel-correctness (arr-TrLst TrLst/arr-ids)
125
(if (endp TrLst/arr-ids)
128
(let* ((arr-tr (car arr-TrLst))
129
(tr (car TrLst/arr-ids)))
130
(and (equal (FrmV arr-tr) (FrmV tr))
131
(equal (IdV arr-tr) (IdV tr))
132
(equal (OrgV arr-tr) (OrgV tr))
133
(equal (FlitV arr-tr) (FlitV tr))
134
(equal (timeV arr-tr) (TimeV tr))
135
(subsetp (RoutesV arr-tr) (RoutesV tr))
136
(s/d-travel-correctness (cdr arr-TrLst)
137
(cdr TrLst/arr-ids))))))
140
(defthm s/d-travel-correctness-unitary
141
(implies (trlstp x nodeset)
142
(s/d-travel-correctness x x)))
144
(defthm arrived-travels-correctness
145
(mv-let (newTrLst Arrived newMeasure newstate )
146
(scheduling TrLst NodeSet ntkstate order)
147
(declare (ignore newTrLst newMeasure newstate ))
148
(implies (TrLstp TrLst nodeset)
149
(s/d-travel-correctness
151
(extract-sublst TrLst (V-ids Arrived)))))
152
:hints (("Goal" :in-theory (disable trlstp))))
154
(defthm subsetp-arrived-newTrLst-ids
155
;; this should be provable from the two lemmas above
156
;; but it will always be trivial to prove, and it is
157
;; useful in subsequent proofs.
158
(mv-let (newTrLst Arrived newMeasure newstate )
159
(scheduling TrLst NodeSet ntkstate order)
160
(declare (ignore newMeasure newstate ))
161
(implies (TrLstp TrLst nodeset)
162
(and (subsetp (v-ids Arrived) (v-ids Trlst))
163
(subsetp (Tm-ids newTrLst) (v-ids TrLst))))))
166
;; 4. Correctness of the newTrLst travels
167
;; -------------------------------------
168
;; the correctness of the newTrLst travels differs from
169
;; the correctness of the Arrived travels because,
170
;; for the Arrived travels we will generally keep only
171
;; one route, but for the newTrLst travels we will not modify
172
;; the travels and keep all the routes. In fact, by
173
;; converting a travel back to a missive we will remove the
175
;; ---------------------------------------------------------
177
;; the list newTrLst is equal to filtering the initial
178
;; TrLst according to the Ids of newTrLst
182
(defthm newTrLst-travel-correctness ;; OK
183
;; the correctness of newtrlst is the equivalence of the transformation
184
;;of the newtrlst into missives, and the transformation of the
185
;;initial trlst (input to the scheduling function)
186
;;into tmissives and then to missives
187
;; this rule will cause an infinite number of rewrites that's why
188
;; it's in rule-classes nil, we have to create an instance to use
190
(mv-let (newTrLst Arrived newMeasure newstate )
191
(scheduling TrLst NodeSet ntkstate order)
192
(declare (ignore Arrived newMeasure newstate))
193
(implies (TrLstp TrLst nodeset)
194
(equal (tomissives newTrLst)
195
(extract-sublst (tomissives(totmissives
197
(Tm-ids newTrLst)))))
201
;; 6/ if scheduling assumptions are not met, measure is nil
202
(defthm mv-nth-2-scheduling-on-zero-measure ;; OK
203
;; if the scheduling measure is 0
204
;; the new measure is equal to the initial one
205
(implies (and (not (scheduling-assumptions TrLst NodeSet ntkstate order))
206
(TrLstp trlst nodeset))
207
(equal (mv-nth 2 (scheduling TrLst NodeSet ntkstate order)) ;; new measure
210
(defthm mv-nth-0-scheduling-on-zero-measure ;; OK
211
;; if the scheduling measure is 0
212
;; the set of newTrLst s is equal to the initial TrLst
213
(implies (not (scheduling-assumptions TrLst NodeSet ntkstate order))
215
(mv-nth 0 (scheduling TrLst NodeSet ntkstate order))
216
(totmissives TrLst))))
218
;; 7/ The intersection of the ids of the Arrived travels and those
219
;; of the newTrLst travels is empty
220
;; -----------------------------------------------------------------
222
(defthm not-in-newTrLst-Arrived ;; OK
223
(mv-let (newTrLst Arrived newmeasure newstate )
224
(scheduling TrLst NodeSet ntkstate order)
225
(declare (ignore newmeasure newstate ))
226
(implies (TrLstp TrLst nodeset)
227
(not-in (Tm-ids newTrLst) (v-ids Arrived)))))
229
;; some constraints required because we do not have a definition
231
(defthm consp-scheduling ;; OK
233
(consp (scheduling TrLst NodeSet ntkstate order))
234
:rule-classes :type-prescription)
236
(defthm true-listp-car-scheduling ;; OK
237
(implies (true-listp TrLst)
238
(true-listp (mv-nth 0 (scheduling TrLst NodeSet
241
:rule-classes :type-prescription)
243
(defthm true-listp-mv-nth-1-sched-1 ;; OK
244
(implies (true-listp TrLst)
245
(true-listp (mv-nth 1 (scheduling TrLst NodeSet
248
:rule-classes :type-prescription)
250
(defthm true-listp-mv-nth-1-sched-2 ;; OK
251
(implies (TrLstp TrLst nodeset)
252
(true-listp (mv-nth 1 (scheduling TrLst NodeSet
255
:rule-classes :type-prescription)
257
) ;; end of scheduling
260
(defthm correctroutesp-s/d-travel-correctness ;; OK
261
;; correctroutesp between trlst/ids and it's transformation into
262
;; tmissves, and the s/d-travel-correctness, between trlst/ids and
264
;; implies the correctroutesp between trlst1 and trlst/ids
265
(implies (and (CorrectRoutesp TrLst/ids (ToTMissives TrLst/ids) NodeSet)
266
(s/d-travel-correctness TrLst1 TrLst/ids))
267
(CorrectRoutesp TrLst1
268
(ToTMissives TrLst/ids) NodeSet)))
271
(defthm scheduling-preserves-route-correctness ;; OK
272
;; we prove that sheduling preserve the correctness of the routes
273
;; after the transformation
274
(mv-let (newTrLst Arrived newmeasure newstate )
275
(scheduling TrLst NodeSet ntkstate order)
276
(declare (ignore newTrLst newstate newmeasure ))
277
(implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet)
278
(TrLstp TrLst nodeset))
279
(CorrectRoutesp Arrived
287
:do-not '(eliminate-destructors generalize)
290
(disable mv-nth ;; to have my rules used
291
ToTMissives-extract-sublst TrLstp))))
294
(defthm TMissivesp-mv-nth-0-scheduling ;; OK
295
(let ((NodeSet (NodeSetGenerator Params)))
296
(implies (and (CorrectRoutesp TrLst (ToTMissives TrLst) NodeSet)
297
(ValidParamsp Params)
298
(TrLstp TrLst nodeset))
299
(TMissivesp (mv-nth 0 (scheduling TrLst NodeSet
305
(:instance tmissivesp-newTrlst
306
(nodeset (NodeSetGenerator Params))))))