bertogna_fp_theory.v 39.6 KB
Newer Older
Felipe Cerqueira's avatar
Felipe Cerqueira committed
1
Require Import rt.util.all.
2 3 4 5 6
Require Import rt.model.arrival.basic.task rt.model.arrival.basic.job rt.model.priority rt.model.arrival.basic.task_arrival.
Require Import rt.model.schedule.global.workload rt.model.schedule.global.schedulability
               rt.model.schedule.global.response_time.
Require Import rt.model.schedule.global.basic.schedule rt.model.schedule.global.basic.platform
               rt.model.schedule.global.basic.constrained_deadlines rt.model.schedule.global.basic.interference.
7 8
Require Import rt.analysis.global.basic.workload_bound
               rt.analysis.global.basic.interference_bound_fp.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
9
From mathcomp Require Import ssreflect ssrbool eqtype ssrnat seq fintype bigop div path.
10 11 12

Module ResponseTimeAnalysisFP.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
13 14
  Export Job SporadicTaskset ScheduleOfSporadicTask Workload Interference
         InterferenceBoundFP Platform Schedulability ResponseTime
15
         Priority TaskArrival WorkloadBound ConstrainedDeadlines.
16

Felipe Cerqueira's avatar
Felipe Cerqueira committed
17 18 19 20
  (* In this section, we prove that any fixed point in Bertogna and
     Cirinei's RTA for FP scheduling is a safe response-time bound.
     This analysis can be found in Chapter 18.2 of Baruah et al.'s
     book Multiprocessor Scheduling for Real-time Systems. *)
21 22 23
  Section ResponseTimeBound.

    Context {sporadic_task: eqType}.
24 25 26
    Variable task_cost: sporadic_task -> time.
    Variable task_period: sporadic_task -> time.
    Variable task_deadline: sporadic_task -> time.
27 28
    
    Context {Job: eqType}.
29
    Variable job_arrival: Job -> time.
30 31
    Variable job_cost: Job -> time.
    Variable job_deadline: Job -> time.
32 33 34
    Variable job_task: Job -> sporadic_task.
    
    (* Assume any job arrival sequence... *)
35
    Variable arr_seq: arrival_sequence Job.
36 37 38

    (* ... in which jobs arrive sporadically and have valid parameters. *)
    Hypothesis H_sporadic_tasks:
39
      sporadic_task_model task_period job_arrival job_task arr_seq.
40
    Hypothesis H_valid_job_parameters:
41 42
      forall j,
        arrives_in arr_seq j ->
43 44
        valid_sporadic_job task_cost task_deadline job_cost job_deadline job_task j.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
45 46 47 48 49 50 51 52 53 54
    (* Assume that we have a task set where all tasks have valid
       parameters and constrained deadlines, ... *)
    Variable ts: taskset_of sporadic_task.
    Hypothesis H_valid_task_parameters:
      valid_sporadic_taskset task_cost task_period task_deadline ts.
    Hypothesis H_constrained_deadlines:
      forall tsk, tsk \in ts -> task_deadline tsk <= task_period tsk.

    (* ... and that all jobs in the arrival sequence come from the task set. *)
    Hypothesis H_all_jobs_from_taskset:
55
      forall j, arrives_in arr_seq j -> job_task j \in ts.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
56 57

    (* Next, consider any schedule such that...*)
58
    Variable num_cpus: nat.
59 60 61
    Variable sched: schedule Job num_cpus.
    Hypothesis H_jobs_come_from_arrival_sequence:
      jobs_come_from_arrival_sequence sched arr_seq.
62

Felipe Cerqueira's avatar
Felipe Cerqueira committed
63 64 65
    (* ...jobs are sequential and do not execute before their
       arrival times nor longer than their execution costs. *)
    Hypothesis H_sequential_jobs: sequential_jobs sched.
66 67
    Hypothesis H_jobs_must_arrive_to_execute: jobs_must_arrive_to_execute job_arrival sched.
    Hypothesis H_completed_jobs_dont_execute: completed_jobs_dont_execute job_cost sched.
68

Felipe Cerqueira's avatar
Felipe Cerqueira committed
69
    (* Assume that there exists at least one processor. *)
70
    Hypothesis H_at_least_one_cpu: num_cpus > 0.
71

Felipe Cerqueira's avatar
Felipe Cerqueira committed
72 73
    (* Consider a given FP policy, ... *)
    Variable higher_eq_priority: FP_policy sporadic_task.
74

Felipe Cerqueira's avatar
Felipe Cerqueira committed
75
    (* ... and assume that the schedule is a work-conserving
76
       schedule that respects this policy. *)
77
    Hypothesis H_work_conserving: work_conserving job_arrival job_cost arr_seq sched.
78
    Hypothesis H_respects_FP_policy:
79
      respects_FP_policy job_arrival job_cost job_task arr_seq sched higher_eq_priority.
80

Felipe Cerqueira's avatar
Felipe Cerqueira committed
81
    (* Let's define some local names to avoid passing many parameters. *)    
82
    Let no_deadline_is_missed_by_tsk (tsk: sporadic_task) :=
83
      task_misses_no_deadline job_arrival job_cost job_deadline job_task arr_seq sched tsk.
84
    Let response_time_bounded_by (tsk: sporadic_task) :=
85
      is_response_time_bound_of_task job_arrival job_cost job_task arr_seq sched tsk.
86

Felipe Cerqueira's avatar
Felipe Cerqueira committed
87 88 89 90 91 92 93 94
    (* Next, we consider the response-time recurrence.
       Let tsk be a task in ts that is to be analyzed. *)
    Variable tsk: sporadic_task.
    Hypothesis task_in_ts: tsk \in ts.

    (* Let is_hp_task denote whether a task is a higher-priority task
       (with respect to tsk). *)
    Let is_hp_task := higher_priority_task higher_eq_priority tsk.
95

96 97 98
    (* Assume a response-time bound is known... *)
    Let task_with_response_time := (sporadic_task * time)%type.
    Variable hp_bounds: seq task_with_response_time.
99 100 101
    Hypothesis H_response_time_of_interfering_tasks_is_known:
      forall hp_tsk R,
        (hp_tsk, R) \in hp_bounds ->
102
        response_time_bounded_by hp_tsk R.
103
    
Felipe Cerqueira's avatar
Felipe Cerqueira committed
104
    (* ... for every higher-priority task. *)
105
    Hypothesis H_hp_bounds_has_interfering_tasks:
Felipe Cerqueira's avatar
Felipe Cerqueira committed
106 107 108 109
      forall hp_tsk,
        hp_tsk \in ts ->
        is_hp_task hp_tsk ->
          exists R, (hp_tsk, R) \in hp_bounds.
110 111 112 113 114 115

    (* Assume that the response-time bounds are larger than task costs. *)
    Hypothesis H_response_time_bounds_ge_cost:
      forall hp_tsk R,
        (hp_tsk, R) \in hp_bounds -> R >= task_cost hp_tsk.
    
Felipe Cerqueira's avatar
Felipe Cerqueira committed
116
    (* Assume that no deadline is missed by any higher-priority task. *)
117 118 119 120 121 122 123 124 125
    Hypothesis H_interfering_tasks_miss_no_deadlines:
      forall hp_tsk R,
        (hp_tsk, R) \in hp_bounds -> R <= task_deadline hp_tsk.

    (* Let R be the fixed point of Bertogna and Cirinei's recurrence, ...*)
    Variable R: time.
    Hypothesis H_response_time_recurrence_holds :
      R = task_cost tsk +
          div_floor
Felipe Cerqueira's avatar
Felipe Cerqueira committed
126
            (total_interference_bound_fp task_cost task_period tsk hp_bounds R)
127 128 129 130 131 132
            num_cpus.

    (* ... and assume that R is no larger than the deadline of tsk.*)
    Hypothesis H_response_time_no_larger_than_deadline:
      R <= task_deadline tsk.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
133
    (* In order to prove that R is a response-time bound, we first provide some lemmas. *)
134 135 136
    Section Lemmas.

      (* Consider any job j of tsk. *)
137 138
      Variable j: Job.
      Hypothesis H_j_arrives: arrives_in arr_seq j.
139 140 141 142 143
      Hypothesis H_job_of_tsk: job_task j = tsk.

      (* Assume that job j is the first job of tsk not to complete by the response time bound. *)
      Hypothesis H_j_not_completed: ~~ completed job_cost sched j (job_arrival j + R).
      Hypothesis H_previous_jobs_of_tsk_completed :
144 145
        forall j0,
          arrives_in arr_seq j0 ->
146 147 148 149 150 151
          job_task j0 = tsk ->
          job_arrival j0 < job_arrival j ->
          completed job_cost sched j0 (job_arrival j0 + R).
      
      (* Let's call x the interference incurred by job j due to tsk_other, ...*)
      Let x (tsk_other: sporadic_task) :=
152
        task_interference job_arrival job_cost job_task sched j tsk_other
153
                          (job_arrival j) (job_arrival j + R).
154

Felipe Cerqueira's avatar
Felipe Cerqueira committed
155
      (* ...and X the total interference incurred by job j due to any task. *)
156
      Let X := total_interference job_arrival job_cost sched j (job_arrival j) (job_arrival j + R).
157 158 159 160 161

      (* Recall Bertogna and Cirinei's workload bound. *)
      Let workload_bound (tsk_other: sporadic_task) (R_other: time) :=
        W task_cost task_period tsk_other R_other R.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
162 163
      (* Let hp_tasks denote the set of higher-priority tasks. *)
      Let hp_tasks := [seq tsk_other <- ts | is_hp_task tsk_other].
164

Felipe Cerqueira's avatar
Felipe Cerqueira committed
165 166
      (* Now we establish results about the higher-priority tasks. *)
      Section LemmasAboutHPTasks.
167 168 169 170 171 172 173 174 175 176 177 178
        
        (* Let (tsk_other, R_other) be any pair of higher-priority task and
           response-time bound computed in previous iterations. *)
        Variable tsk_other: sporadic_task.
        Variable R_other: time.
        Hypothesis H_response_time_of_tsk_other: (tsk_other, R_other) \in hp_bounds.

        (* Since tsk_other cannot interfere more than it executes, we show that
           the interference caused by tsk_other is no larger than workload bound W. *)
        Lemma bertogna_fp_workload_bounds_interference :
          x tsk_other <= workload_bound tsk_other R_other.
        Proof.
179
          unfold response_time_bounded_by, is_response_time_bound_of_task,
180 181
                 completed, completed_jobs_dont_execute, valid_sporadic_job in *.
          rename H_valid_job_parameters into PARAMS,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
182
                 H_all_jobs_from_taskset into FROMTS,
183
                 H_valid_task_parameters into TASK_PARAMS,
184
                 H_constrained_deadlines into RESTR,
185 186 187 188
                 H_response_time_of_interfering_tasks_is_known into RESP,
                 H_interfering_tasks_miss_no_deadlines into NOMISS,
                 H_response_time_bounds_ge_cost into GE_COST.
          unfold x, workload_bound.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
          destruct ([exists t: 'I_(job_arrival j + R),
                       task_is_scheduled job_task sched tsk_other t]) eqn: SCHED;
            last first.
          {
            apply negbT in SCHED; rewrite negb_exists in SCHED.
            move: SCHED => /forallP SCHED.
            apply leq_trans with (n := 0); last by done.
            apply leq_trans with (n := \sum_(job_arrival j <= t < job_arrival j + R) 0);
              last by rewrite big1.
            apply leq_sum_nat; move => i /andP [_ LTi] _.
            specialize (SCHED (Ordinal LTi)).
            rewrite negb_exists in SCHED; move: SCHED => /forallP SCHED.
            rewrite big1 //; intros cpu _.
            specialize (SCHED cpu); apply negbTE in SCHED.
            by rewrite SCHED andbF.
          }
          move: SCHED => /existsP [t /existsP [cpu SCHED]].
          unfold task_scheduled_on in SCHED.
207
          destruct (sched cpu t) as [j0 |] eqn:SCHED'; last by done.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
208
          assert (INts: tsk_other \in ts).
209 210 211 212
          {
            move: SCHED => /eqP <-. apply FROMTS, (H_jobs_come_from_arrival_sequence j0 t).
            by apply/existsP; exists cpu; apply/eqP.
          }
213 214
          apply leq_trans with (n := workload job_task sched tsk_other
                                              (job_arrival j) (job_arrival j + R));
215
            first by apply task_interference_le_workload.
216 217
          by apply workload_bounded_by_W with (task_deadline0 := task_deadline) (arr_seq0 := arr_seq)
             (job_arrival0 := job_arrival) (job_cost0 := job_cost) (job_deadline0 := job_deadline);
218 219 220 221 222 223 224 225
            try (by ins); last 2 first;
              [ by ins; apply GE_COST 
              | by ins; apply NOMISS
              | by ins; apply TASK_PARAMS
              | by ins; apply RESTR
              | by ins; apply RESP with (hp_tsk := tsk_other)].
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
226
      End LemmasAboutHPTasks.
227 228 229 230 231 232 233 234 235 236

      (* Next we prove some lemmas that help to derive a contradiction.*)
      Section DerivingContradiction.

        (* 0) Since job j did not complete by its response time bound, it follows that
              the total interference X >= R - e_k + 1. *)
        Lemma bertogna_fp_too_much_interference : X >= R - task_cost tsk + 1.
        Proof.
          rename H_completed_jobs_dont_execute into COMP,
                 H_valid_job_parameters into PARAMS,
237 238
                 H_response_time_recurrence_holds into REC,
                 H_job_of_tsk into JOBtsk, H_j_not_completed into NOTCOMP.
239
          unfold completed, valid_sporadic_job in *.
240 241 242 243 244 245 246
          unfold X, total_interference; rewrite addn1.
          rewrite -(ltn_add2r (task_cost tsk)).
          rewrite subh1; last by rewrite [R](REC) // leq_addr.
          rewrite -addnBA // subnn addn0.
          move: (NOTCOMP) => /negP NOTCOMP'.
          rewrite neq_ltn in NOTCOMP.
          move: NOTCOMP => /orP [LT | BUG]; last first.
247
          {
248 249
            exfalso; rewrite ltnNge in BUG; move: BUG => /negP BUG; apply BUG.
            by apply cumulative_service_le_job_cost.
250
          }
251
          apply leq_ltn_trans with (n := (\sum_(job_arrival j <= t < job_arrival j + R)
252
                                       backlogged job_arrival job_cost sched j t) +
253
                                     service sched j (job_arrival j + R)); last first.
254
          {
255 256
            rewrite -addn1 -addnA leq_add2l addn1.
            apply leq_trans with (n := job_cost j); first by done.
257
            by specialize (PARAMS j H_j_arrives); des; rewrite -JOBtsk.
258
          }
259 260 261 262 263 264
          unfold service; rewrite service_before_arrival_eq_service_during //.
          rewrite -big_split /=.
          apply leq_trans with (n := \sum_(job_arrival j <= i < job_arrival j + R) 1);
            first by rewrite big_const_nat iter_addn mul1n addn0 addKn.
          rewrite big_nat_cond [\sum_(_ <= _ < _ | true) _]big_nat_cond.
          apply leq_sum; move => i /andP [/andP [GEi LTi] _].
265
          destruct (backlogged job_arrival job_cost sched j i) eqn:BACK;
266 267 268 269 270 271 272 273
            first by rewrite -addn1 addnC; apply leq_add.
          apply negbT in BACK.
          rewrite add0n lt0n -not_scheduled_no_service negbK.
          rewrite /backlogged negb_and negbK in BACK.
          move: BACK => /orP [/negP NOTPENDING | SCHED]; last by done.
          exfalso; apply NOTPENDING; unfold pending; apply/andP; split; first by done.
          apply/negP; red; intro BUG; apply NOTCOMP'.
          by apply completion_monotonic with (t := i); try (by done); apply ltnW.
274 275
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
276 277 278 279 280
        (* 1) Next, we prove that during the scheduling window of j, any job that is
              scheduled while j is backlogged comes from a different task.
              This follows from the fact that j is the first job not to complete
              by its response-time bound, so previous jobs of j's task must have
              completed by their periods and cannot be pending. *)
281 282 283
        Lemma bertogna_fp_interference_by_different_tasks :
          forall t j_other,
            job_arrival j <= t < job_arrival j + R ->
284 285
            arrives_in arr_seq j_other ->
            backlogged job_arrival job_cost sched j t ->
286 287 288 289 290 291 292 293 294 295
            scheduled sched j_other t ->
            job_task j_other != tsk.
        Proof.
          rename H_all_jobs_from_taskset into FROMTS,
                 H_valid_task_parameters into PARAMS,
                 H_job_of_tsk into JOBtsk, H_sporadic_tasks into SPO,
                 H_work_conserving into WORK,
                 H_constrained_deadlines into CONSTR,
                 H_previous_jobs_of_tsk_completed into PREV,
                 H_response_time_no_larger_than_deadline into NOMISS.
296
          move => t j_other /andP [LEt GEt] ARRother BACK SCHED.
297 298 299 300 301 302
          apply/eqP; red; intro SAMEtsk.
          move: SCHED => /existsP [cpu SCHED].
          assert (SCHED': scheduled sched j_other t).
            by apply/existsP; exists cpu.
          clear SCHED; rename SCHED' into SCHED.
          move: (SCHED) => PENDING.
303 304
          apply scheduled_implies_pending with (job_arrival0 := job_arrival)
                                               (job_cost0 := job_cost) in PENDING; try (by done).
305 306 307
          destruct (ltnP (job_arrival j_other) (job_arrival j)) as [BEFOREother | BEFOREj].
           {
            move: (BEFOREother) => LT; rewrite -(ltn_add2r R) in LT.
308
            specialize (PREV j_other ARRother SAMEtsk BEFOREother).
309 310 311 312 313 314 315
            move: PENDING => /andP [_ /negP NOTCOMP]; apply NOTCOMP.
            apply completion_monotonic with (t0 := job_arrival j_other + R); try (by done).
            apply leq_trans with (n := job_arrival j); last by done.
            apply leq_trans with (n := job_arrival j_other + task_deadline tsk);
              first by rewrite leq_add2l; apply NOMISS.
            apply leq_trans with (n := job_arrival j_other + task_period tsk);
              first by rewrite leq_add2l; apply CONSTR; rewrite -JOBtsk FROMTS.
316
            rewrite -SAMEtsk; apply SPO; try (by done); [ | by rewrite JOBtsk | by apply ltnW].
317 318 319 320
            by intro EQ; subst j_other; rewrite ltnn in BEFOREother.
          }
          {
            move: PENDING => /andP [ARRIVED _].
321
            exploit (SPO j j_other); try (by done); [ | by rewrite SAMEtsk | ]; last first.
322 323 324 325 326 327 328 329 330 331
            {
              apply/negP; rewrite -ltnNge.
              apply leq_ltn_trans with (n := t); first by done.
              apply leq_trans with (n := job_arrival j + R); first by done.
              by rewrite leq_add2l; apply leq_trans with (n := task_deadline tsk);
                [by apply NOMISS | by rewrite JOBtsk CONSTR // -JOBtsk FROMTS].
            }
            by red; intros EQtsk; subst j_other; rewrite /backlogged SCHED andbF in BACK.
          }
        Qed.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
332 333 334 335 336 337 338 339 340 341 342 343

        (* Let's define a predicate to identify the other tasks that are scheduled. *)
        Let other_scheduled_task (t: time) (tsk_other: sporadic_task) :=
          task_is_scheduled job_task sched tsk_other t &&
          is_hp_task tsk_other.
      
        (* 2) Now we prove that, at all times that j is backlogged, the number
              of tasks other than tsk that are scheduled is exactly the number
              of processors in the system. This is required to prove lemma (3). *)
        Lemma bertogna_fp_all_cpus_are_busy:
          forall t,
            job_arrival j <= t < job_arrival j + R ->
344
            backlogged job_arrival job_cost sched j t ->
Felipe Cerqueira's avatar
Felipe Cerqueira committed
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
            count (other_scheduled_task t) ts = num_cpus.
        Proof.
          rename H_valid_task_parameters into PARAMS,
                 H_all_jobs_from_taskset into FROMTS,
                 H_job_of_tsk into JOBtsk,
                 H_sporadic_tasks into SPO,
                 H_valid_job_parameters into JOBPARAMS,
                 H_constrained_deadlines into RESTR,
                 H_hp_bounds_has_interfering_tasks into HAS,
                 H_interfering_tasks_miss_no_deadlines into NOMISS,
                 H_response_time_of_interfering_tasks_is_known into PREV.
          unfold sporadic_task_model, is_response_time_bound_of_task in *.
          move => t /andP [LEt LTt] BACK.
          apply platform_fp_cpus_busy_with_interfering_tasks with (task_cost0 := task_cost)
          (task_period0 := task_period) (task_deadline0 := task_deadline) (job_task0 := job_task)
360 361
          (arr_seq0 := arr_seq) (ts0 := ts) (tsk0 := tsk) (higher_eq_priority0 := higher_eq_priority)
            in BACK; try (by done); first by apply PARAMS.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
362 363 364 365 366 367
          {
            apply leq_trans with (n := job_arrival j + R); first by done.
            rewrite leq_add2l.
            by apply leq_trans with (n := task_deadline tsk); last by apply RESTR.
          }      
          {
368
            intros j_other tsk_other ARRother JOBother INTERF.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
            feed (HAS tsk_other); first by rewrite -JOBother FROMTS.
            move: (HAS INTERF) => [R' IN].
            apply completion_monotonic with (t0 := job_arrival j_other + R'); try (by done);
              last by apply PREV with (hp_tsk := tsk_other).
            {
              rewrite leq_add2l.
              apply leq_trans with (n := task_deadline tsk_other); first by apply NOMISS.
              by apply RESTR; rewrite -JOBother FROMTS.
            }
          }
          {
            ins; apply completion_monotonic with (t0 := job_arrival j0 + R); try (by done);
              last by apply H_previous_jobs_of_tsk_completed.
            rewrite leq_add2l.
            by apply leq_trans with (n := task_deadline tsk); last by apply RESTR.
          }
        Qed.
386
        
Felipe Cerqueira's avatar
Felipe Cerqueira committed
387 388 389 390 391
        (* 3) Now we prove that, at all times that j is backlogged, the number
              of tasks other than tsk that are scheduled is exactly the number
              of processors in the system. This is required to prove lemma (4). *)
        Lemma bertogna_fp_interference_on_all_cpus :
          \sum_(tsk_k <- hp_tasks) x tsk_k = X * num_cpus.
392
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
393
          have DIFFTASK := bertogna_fp_interference_by_different_tasks.
394
          rename H_work_conserving into WORK, H_respects_FP_policy into FP,
395
                 H_jobs_come_from_arrival_sequence into SEQ,
396 397
                 H_all_jobs_from_taskset into FROMTS, H_job_of_tsk into JOBtsk.
          unfold sporadic_task_model in *.
398
          unfold x, X, total_interference, task_interference.
399
          rewrite -big_mkcond -exchange_big big_distrl /= mul1n.
400
          rewrite [\sum_(_ <= _ < _ | backlogged _ _ _ _ _) _]big_mkcond.
401
          apply eq_big_nat; move => t /andP [GEt LTt].
402
          destruct (backlogged job_arrival job_cost sched j t) eqn:BACK;
403 404 405 406 407
            last by rewrite big1 //; ins; rewrite big1.
          rewrite big_mkcond /=.
          rewrite exchange_big /=.
          apply eq_trans with (y := \sum_(cpu < num_cpus) 1); last by simpl_sum_const.
          apply eq_bigr; intros cpu _.
408
          move: (WORK j t H_j_arrives BACK cpu) => [j_other /eqP SCHED]; unfold scheduled_on in *.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
409
          rewrite (bigD1_seq (job_task j_other)) /=; last by rewrite filter_uniq; destruct ts.
410
          {
411 412 413 414
            rewrite (eq_bigr (fun i => 0));
              last by intros i DIFF; rewrite /task_scheduled_on SCHED;apply/eqP;rewrite eqb0 eq_sym.
            rewrite big_const_seq iter_addn mul0n 2!addn0; apply/eqP; rewrite eqb1.
            by unfold task_scheduled_on; rewrite SCHED.
415
          }
416 417
          have ARRother: arrives_in arr_seq j_other.
            by apply (SEQ j_other t); apply/existsP; exists cpu; apply/eqP.
418
          rewrite mem_filter; apply/andP; split; last by apply FROMTS.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
419
          apply/andP; split.
420 421 422 423
          {
            rewrite -JOBtsk; apply FP with (t := t); try by done.
            by apply/existsP; exists cpu; apply/eqP.
          }
424
          apply DIFFTASK with (t := t); try (by done); first by auto.
425
          by apply/existsP; exists cpu; apply/eqP.
426 427
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
428 429 430
        (* Before stating the next lemma, let (num_tasks_exceeding delta) be the
           number of interfering tasks whose interference x is larger than delta. *)
        Let num_tasks_exceeding delta := count (fun i => x i >= delta) (hp_tasks).
431

Felipe Cerqueira's avatar
Felipe Cerqueira committed
432 433 434 435 436
        (* 4) Now we prove that, for any delta, if (num_task_exceeding delta > 0), then the
              cumulative interference caused by the complementary set of interfering tasks fills
              the remaining, not-completely-full (num_cpus - num_tasks_exceeding delta)
              processors. *)
        Lemma bertogna_fp_interference_in_non_full_processors :
437
          forall delta,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
438 439
            0 < num_tasks_exceeding delta < num_cpus ->
            \sum_(i <- hp_tasks | x i < delta) x i >= delta * (num_cpus - num_tasks_exceeding delta).
Felipe Cerqueira's avatar
Felipe Cerqueira committed
440
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
441
          have INV := bertogna_fp_all_cpus_are_busy.
442 443 444
          rename H_all_jobs_from_taskset into FROMTS, H_jobs_come_from_arrival_sequence into FROMSEQ,
                 H_valid_task_parameters into PARAMS, H_job_of_tsk into JOBtsk,
                 H_sporadic_tasks into SPO, H_previous_jobs_of_tsk_completed into BEFOREok,
445
                 H_response_time_no_larger_than_deadline into NOMISS,
446 447
                 H_constrained_deadlines into CONSTR, H_sequential_jobs into SEQ,
                 H_respects_FP_policy into FP, H_hp_bounds_has_interfering_tasks into HASHP,
448 449 450 451 452
                 H_interfering_tasks_miss_no_deadlines into NOMISSHP.
          unfold sporadic_task_model in *.
          move => delta /andP [HAS LT]. 
          rewrite -has_count in HAS.

453
          set some_interference_A := fun t =>
454
            has (fun tsk_k => backlogged job_arrival job_cost sched j t &&
455
                              (x tsk_k >= delta) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
456
                              task_is_scheduled job_task sched tsk_k t) hp_tasks.
457
          set total_interference_B := fun t =>
458
              backlogged job_arrival job_cost sched j t *
459
              count (fun tsk_k => (x tsk_k < delta) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
460
                    task_is_scheduled job_task sched tsk_k t) hp_tasks.
461 462

          apply leq_trans with ((\sum_(job_arrival j <= t < job_arrival j + R)
Felipe Cerqueira's avatar
Felipe Cerqueira committed
463
                                some_interference_A t) * (num_cpus - num_tasks_exceeding delta)).
464 465 466 467 468
          {
            rewrite leq_mul2r; apply/orP; right.
            move: HAS => /hasP HAS; destruct HAS as [tsk_a INa LEa].
            apply leq_trans with (n := x tsk_a); first by apply LEa.
            unfold x, task_interference, some_interference_A.
469
            apply leq_sum_nat; move => t /andP [GEt LTt] _.
470
            destruct (backlogged job_arrival job_cost sched j t) eqn:BACK;
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
              last by rewrite (eq_bigr (fun x => 0)); [by simpl_sum_const | by ins].
            destruct ([exists cpu, task_scheduled_on job_task sched tsk_a cpu t]) eqn:SCHED;
              last first.
            {
              apply negbT in SCHED; rewrite negb_exists in SCHED; move: SCHED => /forallP ALL.
              rewrite (eq_bigr (fun x => 0)); first by simpl_sum_const.
              by intros cpu _; specialize (ALL cpu); apply negbTE in ALL; rewrite ALL.
            }
            move: SCHED => /existsP [cpu SCHED].
            apply leq_trans with (n := 1); last first.
            {
              rewrite lt0b; apply/hasP; exists tsk_a; first by done.
              by rewrite LEa 2!andTb; apply/existsP; exists cpu.
            }
            rewrite (bigD1 cpu) /= // SCHED.
            rewrite (eq_bigr (fun x => 0)); first by simpl_sum_const; rewrite leq_b1.
            intros cpu' DIFF.
            apply/eqP; rewrite eqb0; apply/negP.
            intros SCHED'. 
            move: DIFF => /negP DIFF; apply DIFF; apply/eqP.
            unfold task_scheduled_on in *.
            destruct (sched cpu t) as [j1|] eqn:SCHED1; last by done.
            destruct (sched cpu' t) as [j2|] eqn:SCHED2; last by done.
            move: SCHED SCHED' => /eqP JOB /eqP JOB'.
            subst tsk_a; symmetry in JOB'.
496 497 498 499 500
            have ARR1: arrives_in arr_seq j1.
              by apply (FROMSEQ j1 t); apply/existsP; exists cpu; apply/eqP. 
            have ARR2: arrives_in arr_seq j2.
              by apply (FROMSEQ j2 t); apply/existsP; exists cpu'; apply/eqP. 
            assert (PENDING1: pending job_arrival job_cost sched j1 t).
501 502 503 504
            {
              apply scheduled_implies_pending; try by done.
              by apply/existsP; exists cpu; apply/eqP.
            }
505
            assert (PENDING2: pending job_arrival job_cost sched j2 t).
506 507 508 509 510 511 512 513 514 515 516
            {
              apply scheduled_implies_pending; try by done.
              by apply/existsP; exists cpu'; apply/eqP.
            }
            assert (BUG: j1 = j2).
            {
              destruct (job_task j1 == tsk) eqn:SAMEtsk.
              {
                move: SAMEtsk => /eqP SAMEtsk.
                move: (PENDING1) => SAMEjob. 
                apply platform_fp_no_multiple_jobs_of_tsk with (task_cost0 := task_cost)
517
                  (arr_seq0 := arr_seq) (task_period0 := task_period) (task_deadline0 := task_deadline)
518 519 520 521 522 523 524
                  (job_task0 := job_task) (tsk0 := tsk) (j0 := j) in SAMEjob; try (by done);
                  [ | by apply PARAMS | |]; last 2 first.
                  {
                    apply (leq_trans LTt); rewrite leq_add2l.
                    by apply leq_trans with (n := task_deadline tsk); last by apply CONSTR.
                  }
                  {
525
                    intros j0 ARR0 JOB0 LT0.
526 527 528 529 530 531 532 533 534
                    apply completion_monotonic with (t0 := job_arrival j0 + R); try (by done);
                      last by apply BEFOREok.
                    rewrite leq_add2l.
                    by apply leq_trans with (n := task_deadline tsk); last by apply CONSTR.
                  }
                move: BACK => /andP [_ /negP NOTSCHED]; exfalso; apply NOTSCHED.
                by rewrite -SAMEjob; apply/existsP; exists cpu; apply/eqP.
              }
              {
Felipe Cerqueira's avatar
Felipe Cerqueira committed
535
                assert (INTERF: is_hp_task (job_task j1)).
536 537
                {
                  apply/andP; split; last by rewrite SAMEtsk.
538
                  rewrite -JOBtsk; apply FP with (t := t); try (by done).
539 540 541
                  by apply/existsP; exists cpu; apply/eqP.
                }
                apply platform_fp_no_multiple_jobs_of_interfering_tasks with
542 543 544
                  (job_arrival0 := job_arrival) (arr_seq0 := arr_seq) (task_period0 := task_period)
                  (tsk0 := tsk) (higher_eq_priority0 := higher_eq_priority)
                  (job_cost0 := job_cost) (job_task0 := job_task) (sched0 := sched) (t0 := t);
545 546
                  rewrite ?JOBtsk ?SAMEtsk //.
                {
547
                  intros j0 tsk0 ARR0 JOB0 INTERF0.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
548 549
                  feed (HASHP tsk0); first by rewrite -JOB0 FROMTS.
                  move: (HASHP INTERF0) => [R0 IN0].
550
                  apply completion_monotonic with (t0 := job_arrival j0 + R0); try (by done);
Felipe Cerqueira's avatar
Felipe Cerqueira committed
551
                    last by eapply H_response_time_of_interfering_tasks_is_known; first by apply IN0.
552 553 554 555 556 557 558
                  rewrite leq_add2l.
                  by apply leq_trans with (n := task_deadline tsk0);
                    [by apply NOMISSHP | by apply CONSTR; rewrite -JOB0 FROMTS].
                }
              }
            }
            by subst j2; apply SEQ with (j := j1) (t := t).
559
          }
560

561 562 563 564
          apply leq_trans with (\sum_(job_arrival j <= t < job_arrival j + R)
                                     total_interference_B t).
          {
            rewrite big_distrl /=.
565
            apply leq_sum_nat; move => t LEt _.
566
            unfold some_interference_A, total_interference_B. 
567
            destruct (backlogged job_arrival job_cost sched j t) eqn:BACK;
568 569
              [rewrite mul1n /= | by rewrite has_pred0 //].

570
            destruct (has (fun tsk_k : sporadic_task => (delta <= x tsk_k) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
571
                       task_is_scheduled job_task sched tsk_k t) hp_tasks) eqn:HAS';
572
              last by done.
573
            rewrite mul1n; move: HAS => /hasP [tsk_k INk LEk].
Felipe Cerqueira's avatar
Felipe Cerqueira committed
574
            unfold num_tasks_exceeding.
575 576
            apply leq_trans with (n := num_cpus -
                         count (fun i => (x i >= delta) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
577
                            task_is_scheduled job_task sched i t) hp_tasks).
578 579 580 581 582
            {
              apply leq_sub2l.
              rewrite -2!sum1_count big_mkcond /=.
              rewrite [\sum_(_ <- _ | _ <= _)_]big_mkcond /=.
              apply leq_sum; intros i _.
583
              by destruct (task_is_scheduled job_task sched i t);
584 585
                [by rewrite andbT | by rewrite andbF].
            }
Felipe Cerqueira's avatar
Felipe Cerqueira committed
586
            rewrite -count_filter -[count _ hp_tasks]count_filter.
587 588 589
            eapply leq_trans with (n := count (predC (fun tsk => delta <= x tsk)) _);
              last by apply eq_leq, eq_in_count; red; ins; rewrite ltnNge.
            rewrite leq_subLR count_predC size_filter.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
590
            apply leq_trans with (n := count (other_scheduled_task t) ts);
Felipe Cerqueira's avatar
Felipe Cerqueira committed
591
              [by rewrite INV | by rewrite count_filter].
592 593
          }
          {
594 595
            unfold x at 2, total_interference_B.
            rewrite exchange_big /=; apply leq_sum; intros t _.
596
            destruct (backlogged job_arrival job_cost sched j t) eqn:BACK; last by ins.
597
            rewrite mul1n -sum1_count.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
598
            rewrite big_mkcond [\sum_(i <- hp_tasks | _ < _) _]big_mkcond /=.
599 600 601 602 603
            apply leq_sum_seq; move => tsk_k IN _.
            destruct (x tsk_k < delta); [rewrite andTb | by rewrite andFb].
            destruct (task_is_scheduled job_task sched tsk_k t) eqn:SCHED; last by done.
            move: SCHED => /existsP [cpu SCHED].
            by rewrite (bigD1 cpu) /= // SCHED.
604 605 606
          }
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
607 608 609
        (* 5) Based on lemma (4), we prove that, for any interval delta, if the sum of per-task
              interference exceeds (delta * num_cpus), the same applies for the
              sum of the minimum of the interference and delta. *)
610 611
        Lemma bertogna_fp_minimum_exceeds_interference :
          forall delta,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
612 613
            \sum_(tsk_k <- hp_tasks) x tsk_k >= delta * num_cpus ->
               \sum_(tsk_k <- hp_tasks) minn (x tsk_k) delta >=
614 615 616 617 618 619 620 621 622 623 624 625 626
               delta * num_cpus.
        Proof.
          intros delta SUMLESS.
          set more_interf := fun tsk_k => x tsk_k >= delta.
          rewrite [\sum_(_ <- _) minn _ _](bigID more_interf) /=.
          unfold more_interf, minn.
          rewrite [\sum_(_ <- _ | delta <= _)_](eq_bigr (fun i => delta));
            last by intros i COND; rewrite leqNgt in COND; destruct (delta > x i).
          rewrite [\sum_(_ <- _ | ~~_)_](eq_big (fun i => x i < delta)
                                                (fun i => x i));
            [| by red; ins; rewrite ltnNge
             | by intros i COND; rewrite -ltnNge in COND; rewrite COND].

Felipe Cerqueira's avatar
Felipe Cerqueira committed
627 628
          (* Case 1: num_tasks_exceeding = 0 *)
          destruct (~~ has (fun i => delta <= x i) hp_tasks) eqn:HASa.
629 630 631
          {
            rewrite [\sum_(_ <- _ | _ <= _) _]big_hasC; last by apply HASa.
            rewrite big_seq_cond; move: HASa => /hasPn HASa.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
632 633
            rewrite add0n (eq_bigl (fun i => (i \in hp_tasks) && true));
              last by red; intros tsk_k; destruct (tsk_k \in hp_tasks) eqn:INk;
634 635 636 637
                [by rewrite andTb ltnNge; apply HASa | by rewrite andFb].
            by rewrite -big_seq_cond.
          } apply negbFE in HASa.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
638 639
          (* Case 2: num_tasks_exceeding >= num_cpus *)
          destruct (num_tasks_exceeding delta >= num_cpus) eqn:CARD.
640
          {
Felipe Cerqueira's avatar
Felipe Cerqueira committed
641
            apply leq_trans with (delta * num_tasks_exceeding delta);
642
              first by rewrite leq_mul2l; apply/orP; right.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
643
            unfold num_tasks_exceeding; rewrite -sum1_count big_distrr /=.
644 645 646 647
            rewrite -[\sum_(_ <- _ | _) _]addn0.
            by apply leq_add; [by apply leq_sum; ins; rewrite muln1|by ins].
          } apply negbT in CARD; rewrite -ltnNge in CARD.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
648 649 650 651
          (* Case 3: num_tasks_exceeding < num_cpus *)
          rewrite big_const_seq iter_addn addn0; fold num_tasks_exceeding.
          apply leq_trans with (n := delta * num_tasks_exceeding delta +
                                     delta * (num_cpus - num_tasks_exceeding delta));
652
            first by rewrite -mulnDr subnKC //; apply ltnW.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
653
          rewrite leq_add2l; apply bertogna_fp_interference_in_non_full_processors.
654
          by apply/andP; split; first by rewrite -has_count.
655 656
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
657 658 659
        (* 6) Next, using lemmas (0), (3) and (5) we prove that the reduction-based
              interference bound is not enough to cover the sum of the minima over all tasks
              (artifact of the proof by contradiction). *)
660 661 662
        Lemma bertogna_fp_sum_exceeds_total_interference:
          \sum_((tsk_k, R_k) <- hp_bounds)
            minn (x tsk_k) (R - task_cost tsk + 1) >
Felipe Cerqueira's avatar
Felipe Cerqueira committed
663
          total_interference_bound_fp task_cost task_period tsk hp_bounds R.
664
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
665
          have EXCEEDS := bertogna_fp_minimum_exceeds_interference.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
666
          have ALLBUSY := bertogna_fp_interference_on_all_cpus.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
667
          have TOOMUCH := bertogna_fp_too_much_interference.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
668
          rename H_hp_bounds_has_interfering_tasks into HAS,
669
                 H_response_time_recurrence_holds into REC.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
670
          apply leq_trans with (n := \sum_(tsk_k <- hp_tasks) minn (x tsk_k) (R - task_cost tsk + 1));
671 672 673 674
            last first.
          {
            rewrite (eq_bigr (fun i => minn (x (fst i)) (R - task_cost tsk + 1)));
              last by ins; destruct i.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
675 676 677 678 679 680 681 682 683
            have MAP := @big_map _ 0 addn _ _ (fun x => fst x) hp_bounds (fun x => true) (fun y => minn (x y) (R - task_cost tsk + 1)).
            rewrite -MAP.
            apply leq_sum_sub_uniq; first by apply filter_uniq; destruct ts.
            red; move => tsk0 IN0.
            rewrite mem_filter in IN0; move: IN0 => /andP [INTERF0 IN0].
            apply/mapP.
            feed (HAS tsk0); first by done.
            move: (HAS INTERF0) => [R0 IN].
            by exists (tsk0, R0).
684 685 686 687 688 689 690
          }
          apply ltn_div_trunc with (d := num_cpus);
            first by apply H_at_least_one_cpu.
          rewrite -(ltn_add2l (task_cost tsk)) -REC.
          rewrite -addn1 -leq_subLR.
          rewrite -[R + 1 - _]subh1; last by rewrite REC; apply leq_addr.
          rewrite leq_divRL; last by apply H_at_least_one_cpu.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
691 692 693
          apply EXCEEDS.
          apply leq_trans with (n := X * num_cpus); last by rewrite ALLBUSY.
          by rewrite leq_mul2r; apply/orP; right; apply TOOMUCH.
694 695
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
696 697 698 699 700
        (* 7) After concluding that the sum of the minima exceeds (R - e_i + 1),
              we prove that there exists a tuple (tsk_k, R_k) that satisfies
              min (x_k, R - e_i + 1) > min (W_k, R - e_i + 1).
              This implies that x_k > W_k, which is of course a contradiction,
              since W_k is a valid task interference bound. *)
701 702 703 704 705 706
        Lemma bertogna_fp_exists_task_that_exceeds_bound :
          exists tsk_k R_k,
            (tsk_k, R_k) \in hp_bounds /\
            (minn (x tsk_k) (R - task_cost tsk + 1) >
              minn (workload_bound tsk_k R_k) (R - task_cost tsk + 1)).
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
707
          have SUM := bertogna_fp_sum_exceeds_total_interference.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
708
          rename H_hp_bounds_has_interfering_tasks into HASHP.
709
          assert (HAS: has (fun tup : task_with_response_time =>
Felipe Cerqueira's avatar
Felipe Cerqueira committed
710
                            let (tsk_k, R_k) := tup in
711 712 713 714
                               (minn (x tsk_k) (R - task_cost tsk + 1) >
                                minn (workload_bound tsk_k R_k)(R - task_cost tsk + 1)))
                            hp_bounds).
          {
Felipe Cerqueira's avatar
Felipe Cerqueira committed
715 716 717 718 719 720 721 722 723 724 725 726
              apply/negP; unfold not; intro NOTHAS.
              move: NOTHAS => /negP /hasPn ALL.
              rewrite -[_ < _]negbK in SUM.
              move: SUM => /negP SUM; apply SUM; rewrite -leqNgt.
              rewrite (eq_bigr (fun i => minn (x (fst i)) (R - task_cost tsk + 1)));
                last by ins; destruct i.
              unfold total_interference_bound_fp.
              rewrite big_seq_cond.
              rewrite [\sum_(_ <- _ | true)_]big_seq_cond.
              apply leq_sum.
              intros p; rewrite andbT; intros IN.
              by specialize (ALL p IN); destruct p; rewrite leqNgt.
727 728 729 730 731 732 733 734 735 736 737
          }
          move: HAS => /hasP HAS; destruct HAS as [[tsk_k R_k] HPk MINk]; exists tsk_k, R_k.
          by repeat split.
        Qed.

      End DerivingContradiction.

    End Lemmas.
    
    (* Using the lemmas above, we prove that R bounds the response time of task tsk. *)
    Theorem bertogna_cirinei_response_time_bound_fp :
738
      response_time_bounded_by tsk R.
739
    Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
740 741
      have WORKLOAD := bertogna_fp_workload_bounds_interference.
      have EX := bertogna_fp_exists_task_that_exceeds_bound.
742 743 744 745
      rename H_response_time_bounds_ge_cost into GE_COST,
             H_interfering_tasks_miss_no_deadlines into NOMISS,
             H_response_time_recurrence_holds into REC,
             H_response_time_of_interfering_tasks_is_known into RESP,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
746
             H_hp_bounds_has_interfering_tasks into HAS,
747
             H_response_time_no_larger_than_deadline into LEdl.
748
      intros j ARRj JOBtsk.
749 750 751 752 753 754 755 756
       
      (* First, rewrite the claim in terms of the *absolute* response-time bound (arrival + R) *)
      remember (job_arrival j + R) as ctime.
      
      (* Now, we apply strong induction on the absolute response-time bound. *)
      generalize dependent j.
      induction ctime as [ctime IH] using strong_ind.

757
      intros j ARRj JOBtsk EQc; subst ctime.
758 759

      (* First, let's simplify the induction hypothesis. *)
760 761
      assert (BEFOREok: forall j0,
                          arrives_in arr_seq j0 ->
762 763 764 765 766 767 768
                          job_task j0 = tsk ->
                          job_arrival j0 < job_arrival j ->
                          service sched j0 (job_arrival j0 + R) == job_cost j0).
      {
        by ins; apply IH; try (by done); rewrite ltn_add2r.
      } clear IH.
              
769
      unfold response_time_bounded_by, is_response_time_bound_of_task,
770 771 772 773 774 775 776 777 778
             completed, completed_jobs_dont_execute, valid_sporadic_job in *.

      (* Now we start the proof. Assume by contradiction that job j
         is not complete at time (job_arrival j + R). *)
      destruct (completed job_cost sched j (job_arrival j + R)) eqn:NOTCOMP;
        first by done.
      apply negbT in NOTCOMP; exfalso.

      (* We derive a contradiction using the previous lemmas. *)
779
      specialize (EX j ARRj JOBtsk NOTCOMP BEFOREok).
780 781
      destruct EX as [tsk_k [R_k [HPk LTmin]]].
      unfold minn at 1 in LTmin.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
782
      specialize (WORKLOAD j tsk_k R_k HPk).
783 784 785 786 787 788 789 790 791 792
      destruct (W task_cost task_period tsk_k R_k R < R - task_cost tsk + 1); rewrite leq_min in LTmin; 
        last by move: LTmin => /andP [_ BUG]; rewrite ltnn in BUG.
      move: LTmin => /andP [BUG _]; des.
      apply leq_trans with (p := W task_cost task_period tsk_k R_k R) in BUG; last by done.
      by rewrite ltnn in BUG.
    Qed.

  End ResponseTimeBound.

End ResponseTimeAnalysisFP.