bertogna_edf_theory.v 43.6 KB
Newer Older
Felipe Cerqueira's avatar
Felipe Cerqueira committed
1
Require Import rt.util.all.
2 3 4 5 6 7
Require Import rt.model.arrival.basic.task 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.jitter.job rt.model.schedule.global.jitter.schedule
               rt.model.schedule.global.jitter.platform rt.model.schedule.global.jitter.interference
               rt.model.schedule.global.jitter.constrained_deadlines.
8 9
Require Import rt.analysis.global.jitter.workload_bound
               rt.analysis.global.jitter.interference_bound_edf.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
10
From mathcomp Require Import ssreflect ssrbool eqtype ssrnat seq fintype bigop div path.
11 12 13

Module ResponseTimeAnalysisEDFJitter.

14
  Export JobWithJitter SporadicTaskset ScheduleOfSporadicTaskWithJitter Workload
15
         Schedulability ResponseTime Priority TaskArrival WorkloadBoundJitter
Felipe Cerqueira's avatar
Felipe Cerqueira committed
16
         InterferenceBoundEDFJitter Platform Interference ConstrainedDeadlines.
17

Felipe Cerqueira's avatar
Felipe Cerqueira committed
18 19 20 21 22
  (* In this section, we prove that any fixed point in Bertogna and
     Cirinei's RTA for EDF scheduling modified to account for jitter
     yields a safe response-time bound. This is an extension of the
     analysis found in Chapter 17.1.2 of Baruah et al.'s book
     Multiprocessor Scheduling for Real-time Systems. *)
23 24 25
  Section ResponseTimeBound.

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

    (* ... in which jobs arrive sporadically and have valid parameters.
       Note: the jitter of a valid job is bounded by the jitter of its task. *)
    Hypothesis H_sporadic_tasks:
44
      sporadic_task_model task_period job_arrival job_task arr_seq.
45
    Hypothesis H_valid_job_parameters:
46 47
      forall j,
        arrives_in arr_seq j ->
48 49 50
        valid_sporadic_job_with_jitter task_cost task_deadline task_jitter job_cost
                                                 job_deadline job_task job_jitter j.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
51 52 53 54 55 56 57 58 59 60
    (* 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:
61 62 63
      forall j,
        arrives_in arr_seq j ->
        job_task j \in ts.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
64 65

    (* Next, consider any schedule such that...*)
66
    Variable num_cpus: nat.
67 68 69
    Variable sched: schedule Job num_cpus.
    Hypothesis H_jobs_come_from_arrival_sequence:
      jobs_come_from_arrival_sequence sched arr_seq.
70

Felipe Cerqueira's avatar
Felipe Cerqueira committed
71 72 73 74
    (* ...jobs are sequential, do not execute before the
       jitter has passed and nor longer than their execution costs. *)
    Hypothesis H_sequential_jobs: sequential_jobs sched.
    Hypothesis H_execute_after_jitter:
75
      jobs_execute_after_jitter job_arrival job_jitter sched.
76 77 78
    Hypothesis H_completed_jobs_dont_execute:
      completed_jobs_dont_execute job_cost sched.

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

Felipe Cerqueira's avatar
Felipe Cerqueira committed
82
    (* Assume that the schedule is a work-conserving EDF schedule. *)
83 84 85
    Hypothesis H_work_conserving: work_conserving job_arrival job_cost job_jitter arr_seq sched.
    Hypothesis H_edf_policy: respects_JLFP_policy job_arrival job_cost job_jitter arr_seq sched
                                                  (EDF job_arrival job_deadline).
86

Felipe Cerqueira's avatar
Felipe Cerqueira committed
87
    (* Let's define some local names to avoid passing many parameters. *)
88
    Let no_deadline_is_missed_by_tsk (tsk: sporadic_task) :=
89
      task_misses_no_deadline job_arrival job_cost job_deadline job_task arr_seq sched tsk.
90
    Let response_time_bounded_by (tsk: sporadic_task) :=
91
      is_response_time_bound_of_task job_arrival job_cost job_task arr_seq sched tsk.
92

Felipe Cerqueira's avatar
Felipe Cerqueira committed
93 94
    (* Next we consider the response-time recurrence.
       Assume that a response-time bound R is known...  *)
95 96 97
    Let task_with_response_time := (sporadic_task * time)%type.
    Variable rt_bounds: seq task_with_response_time.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
98
    (* ...for any task in the task set, ... *)
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    Hypothesis H_rt_bounds_contains_all_tasks: unzip1 rt_bounds = ts.

    (* Also, assume that R is a fixed-point of the response-time recurrence, ... *)
    Let I (tsk: sporadic_task) (delta: time) :=
      total_interference_bound_edf task_cost task_period task_deadline task_jitter tsk rt_bounds delta.
    Hypothesis H_response_time_is_fixed_point :
      forall tsk R,
        (tsk, R) \in rt_bounds ->
        R = task_cost tsk + div_floor (I tsk R) num_cpus.
    
    (* ..., and R is no larger than the deadline. *)
    Hypothesis H_tasks_miss_no_deadlines:
      forall tsk R,
        (tsk, R) \in rt_bounds ->
        task_jitter tsk + R <= task_deadline tsk.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
115
    (* In order to prove that R is a response-time bound, we first provide some lemmas. *)
116 117 118 119 120 121 122 123
    Section Lemmas.

      (* Let (tsk, R) be any task to be analyzed, with its response-time bound R. *)
      Variable tsk: sporadic_task.
      Variable R: time.
      Hypothesis H_tsk_R_in_rt_bounds: (tsk, R) \in rt_bounds.

      (* Consider any job j of tsk. *)
124 125
      Variable j: Job.
      Hypothesis H_j_arrives: arrives_in arr_seq j.
126 127 128 129 130 131 132 133
      Hypothesis H_job_of_tsk: job_task j = tsk.

      (* Let t1 be the first point in time where j can actually be scheduled. *)
      Let t1 := job_arrival j + job_jitter j.

      (* Assume that job j did not complete on time, ... *)
      Hypothesis H_j_not_completed: ~~ completed job_cost sched j (t1 + R).

Felipe Cerqueira's avatar
Felipe Cerqueira committed
134
      (* ...and that it is the first job not to satisfy its response-time bound. *)
135
      Hypothesis H_all_previous_jobs_completed_on_time :
136 137
        forall j_other tsk_other R_other,
          arrives_in arr_seq j_other ->
138 139 140 141 142 143 144
          job_task j_other = tsk_other ->
          (tsk_other, R_other) \in rt_bounds ->
          job_arrival j_other + task_jitter tsk_other + R_other < job_arrival j + task_jitter tsk + R ->
          completed job_cost sched j_other (job_arrival j_other + task_jitter tsk_other + R_other).

      (* Let's call x the interference incurred by job j due to tsk_other, ...*)
      Let x (tsk_other: sporadic_task) :=
145
        task_interference job_arrival job_cost job_task job_jitter sched j tsk_other t1 (t1 + R).
146 147

      (* and X the total interference incurred by job j due to any task. *)
148
      Let X := total_interference job_arrival job_cost job_jitter sched j t1 (t1 + R).
149 150 151 152 153 154 155 156 157 158 159 160 161

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

      (*... and the EDF-specific bound, ... *)
      Let edf_specific_bound (tsk_other: sporadic_task) (R_other: time) :=
        edf_specific_interference_bound task_cost task_period task_deadline task_jitter tsk tsk_other R_other.

      (* ... which combined form the interference bound. *)
      Let interference_bound (tsk_other: sporadic_task) (R_other: time) :=
        interference_bound_edf task_cost task_period task_deadline task_jitter tsk R (tsk_other, R_other). 
      
Felipe Cerqueira's avatar
Felipe Cerqueira committed
162 163 164 165 166 167
      (* Based on the definition of a different task, ... *)
      Let other_task := different_task tsk.

      (* ...let other_tasks denote the set of tasks that are different from tsk. *)
      Let other_tasks :=
        [seq tsk_other <- ts | other_task tsk_other].
168

Felipe Cerqueira's avatar
Felipe Cerqueira committed
169
      (* Now we establish results the interfering tasks. *)
170 171 172 173 174 175 176 177 178 179 180
      Section LemmasAboutInterferingTasks.
        
        (* 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 rt_bounds.

        (* Note that tsk_other is in task set ts ...*)
        Lemma bertogna_edf_tsk_other_in_ts: tsk_other \in ts.
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
181
          by rewrite set_mem -H_rt_bounds_contains_all_tasks; apply/mapP; exists (tsk_other, R_other).
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        Qed.

        (* Also, R_other is larger than the cost of tsk_other. *)
        Lemma bertogna_edf_R_other_ge_cost :
          R_other >= task_cost tsk_other.
        Proof.
          by rewrite [R_other](H_response_time_is_fixed_point tsk_other);
            first by apply leq_addr.
        Qed.

        (* 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_edf_workload_bounds_interference :
          x tsk_other <= workload_bound tsk_other R_other.
        Proof.
          unfold valid_sporadic_job in *.
          rename H_all_previous_jobs_completed_on_time into BEFOREok,
                 H_valid_job_parameters into PARAMS,
                 H_valid_task_parameters into TASK_PARAMS,
201
                 H_constrained_deadlines into RESTR,
202 203 204 205 206
                 H_tasks_miss_no_deadlines into NOMISS.
          unfold x, task_interference, valid_sporadic_job_with_jitter, valid_sporadic_job in *.
          have INts := bertogna_edf_tsk_other_in_ts.
          apply leq_trans with (n := workload job_task sched tsk_other t1 (t1 + R));
            first by apply task_interference_le_workload.
207 208 209
          have BOUND := workload_bounded_by_W task_cost task_period task_deadline task_jitter
            job_arrival job_cost job_task job_deadline job_jitter arr_seq _ sched.            
          apply BOUND; try (by done); last 2 first; 
210 211 212 213 214
            [ by apply NOMISS |
            | by ins; apply TASK_PARAMS
            | by apply RESTR
            | by apply bertogna_edf_R_other_ge_cost].
          {
215
            intros j0 ARR0 JOB0 LT0; apply BEFOREok; try (by done).
216 217 218
            unfold t1 in *.
            apply leq_trans with (n := job_arrival j + job_jitter j + R); first by done.
            rewrite leq_add2r leq_add2l.
219
            specialize (PARAMS j H_j_arrives); des.
220 221 222 223 224 225 226 227 228
            rewrite -H_job_of_tsk; apply PARAMS0.
          }
        Qed.

        (* Recall that the edf-specific interference bound also holds. *)
        Lemma bertogna_edf_specific_bound_holds :
          x tsk_other <= edf_specific_bound tsk_other R_other.
        Proof.
          by apply interference_bound_edf_bounds_interference with (job_deadline0 := job_deadline)
229
                   (arr_seq0 := arr_seq) (ts0 := ts); try (by done);
230
          [  by apply bertogna_edf_tsk_other_in_ts
231
          |  by apply H_tasks_miss_no_deadlines         
232 233 234 235 236 237 238 239 240 241 242 243 244
          |  by ins; apply H_all_previous_jobs_completed_on_time with (tsk_other := tsk_other)].
        Qed.
        
      End LemmasAboutInterferingTasks.

      (* 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_edf_too_much_interference : X >= R - task_cost tsk + 1.
        Proof.
          rename H_completed_jobs_dont_execute into COMP,
245 246
                 H_valid_job_parameters into PARAMS, H_response_time_is_fixed_point into REC,
                 H_job_of_tsk into JOBtsk, H_j_not_completed into NOTCOMP.
247
          unfold completed, valid_sporadic_job_with_jitter, valid_sporadic_job in *.
248 249 250 251 252
          unfold X, total_interference; rewrite addn1.
          rewrite -(ltn_add2r (task_cost tsk)).
          rewrite subh1; last by rewrite [R](REC tsk) // leq_addr.
          rewrite -addnBA // subnn addn0.
          move: (NOTCOMP) => /negP NOTCOMP'.
253
          rewrite -ltnNge in NOTCOMP.
254
          apply leq_ltn_trans with (n := (\sum_(t1 <= t < t1 + R)
255
                                       backlogged job_arrival job_cost job_jitter sched j t) +
256
                                     service sched j (t1 + R)); last first.
257
          {
258 259
            rewrite -addn1 -addnA leq_add2l addn1.
            apply leq_trans with (n := job_cost j); first by done.
260
            by specialize (PARAMS j H_j_arrives); des; rewrite -JOBtsk.
261
          }
262 263
          unfold service.
          rewrite -> big_cat_nat with (n := t1) (m := 0); rewrite ?leq_addr // /=.
264
          rewrite (cumulative_service_before_jitter_zero job_arrival job_jitter) // add0n.
265 266 267 268
          rewrite -big_split /=.
          apply leq_trans with (n := \sum_(t1 <= i < t1 + R) 1);
            first by simpl_sum_const; rewrite addKn.
          apply leq_sum_nat; move => i /andP [GEi LTi] _.
269
          destruct (backlogged job_arrival job_cost job_jitter sched j i) eqn:BACK;
270 271 272 273 274 275 276 277
            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.
278 279
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
280 281 282 283 284
      (* 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. *)
285 286 287
        Lemma bertogna_edf_interference_by_different_tasks :
          forall t j_other,
            t1 <= t < t1 + R ->
288
            backlogged job_arrival job_cost job_jitter sched j t ->
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
            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_valid_job_parameters into JOBPARAMS,
                 H_job_of_tsk into JOBtsk, H_sporadic_tasks into SPO,
                 H_work_conserving into WORK,
                 H_tsk_R_in_rt_bounds into INbounds,
                 H_all_previous_jobs_completed_on_time into BEFOREok,
                 H_tasks_miss_no_deadlines into NOMISS,
                 H_constrained_deadlines into CONSTR.
          unfold valid_sporadic_job_with_jitter, valid_sporadic_job in *.
          move => t j_other /andP [LEt GEt] BACK SCHED.
          apply/eqP; red; intro SAMEtsk.
          move: SCHED => /existsP [cpu SCHED].
305
          have SCHED': scheduled sched j_other t by apply/existsP; exists cpu.
306
          clear SCHED; rename SCHED' into SCHED.
307 308
          have ARRother: arrives_in arr_seq j_other.
            by apply (H_jobs_come_from_arrival_sequence j_other t).
309 310
          move: (SCHED) => PENDING.
          apply scheduled_implies_pending with (job_cost0 := job_cost) (job_jitter0 := job_jitter)
311
            (job_arrival0 := job_arrival) in PENDING; try (by done).
312 313 314
          destruct (ltnP (job_arrival j_other) (job_arrival j)) as [BEFOREother | BEFOREj].
          {
            move: (BEFOREother) => LT; rewrite -(ltn_add2r R) in LT.
315
            exploit (BEFOREok j_other tsk R ARRother SAMEtsk INbounds).
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
            {
              rewrite -addnA [_ + R]addnC addnA -[(_ + _) + R]addnA [_ tsk + R]addnC addnA.
              by rewrite ltn_add2r.
            }
            intros COMP.
            move: PENDING => /andP [_ /negP NOTCOMP]; apply NOTCOMP.
            apply completion_monotonic with (t0 := job_arrival j_other + task_jitter tsk + R);
              try by done.
            apply leq_trans with (n := job_arrival j);
              last by apply leq_trans with (n := t1); [by apply leq_addr | by done].
            apply leq_trans with (n := job_arrival j_other + task_period tsk).
            {
              rewrite -addnA leq_add2l.
              by apply leq_trans with (n := task_deadline tsk);
                [by apply NOMISS | by apply CONSTR; rewrite -JOBtsk FROMTS].
            }
332
            rewrite -SAMEtsk; apply SPO; [ | by done | by done| by rewrite JOBtsk | by apply ltnW].
333 334 335 336
            by red; intro EQ; subst; rewrite ltnn in BEFOREother.
          }
          {
            move: PENDING => /andP [ARRIVED _].
337
            exploit (SPO j j_other); try (by done); [ | by rewrite SAMEtsk | ]; last first.
338 339 340 341 342 343 344 345 346
            {
              apply/negP; rewrite -ltnNge JOBtsk.
              apply leq_trans with (n := job_arrival j + task_deadline tsk);
                last by rewrite leq_add2l; apply CONSTR; rewrite -JOBtsk FROMTS.
              apply leq_trans with (n := job_arrival j + task_jitter tsk + R);
                last by rewrite -addnA leq_add2l; apply NOMISS.
              apply leq_trans with (n := t1 + R); last first.
              {
                rewrite leq_add2r leq_add2l -JOBtsk.
347
                by specialize (JOBPARAMS j H_j_arrives); des.
348 349 350 351 352 353 354 355 356
              }
              apply leq_ltn_trans with (n := job_arrival j_other + job_jitter j_other);
                first by apply leq_addr.
              by apply leq_ltn_trans with (n := t).
            }
            by intros EQtsk; subst j_other; rewrite /backlogged SCHED andbF in BACK.
          }
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
357 358 359 360 361 362
      (* 2) In order to use the lemmas in constrained_deadlines.v, we show that
            all jobs released before the end of the interval complete by their
            periods. This follows trivially from the hypothesis that all jobs
            before (t1 + R) complete by their response-time bounds. 
            With this lemma, we can conclude that during job j's scheduling
            window there cannot be multiple pending jobs of each task.*)
363
        Lemma bertogna_edf_all_previous_jobs_complete_by_their_period:
364
          forall t j0,
365
            t < t1 + R ->
366
            arrives_in arr_seq j0 ->
367 368 369 370 371 372 373 374 375 376 377 378
            job_arrival j0 + task_period (job_task j0) <= t ->
            completed job_cost sched j0
               (job_arrival j0 + task_period (job_task j0)).
        Proof.
          rename H_valid_job_parameters into JOBPARAMS,
                 H_rt_bounds_contains_all_tasks into UNZIP,
                 H_job_of_tsk into JOBtsk,
                 H_constrained_deadlines into CONSTR,
                 H_tasks_miss_no_deadlines into NOMISS,
                 H_all_jobs_from_taskset into FROMTS,
                 H_all_previous_jobs_completed_on_time into BEFOREok.
          unfold valid_sporadic_job_with_jitter, valid_sporadic_job in *.
379
          intros t j0 LEt ARR0 LE.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
380 381
          cut ((job_task j0) \in unzip1 rt_bounds = true); last by rewrite UNZIP FROMTS.
          move => /mapP [p IN EQ]; destruct p as [tsk' R0]; simpl in *; subst tsk'.
382
          apply completion_monotonic with (t0 := job_arrival j0 + task_jitter (job_task j0) + R0).
383 384 385 386 387 388 389 390 391 392
          {
            rewrite -addnA leq_add2l.
            apply leq_trans with (n := task_deadline (job_task j0));
              [by apply NOMISS | by apply CONSTR; rewrite FROMTS].
          }
          apply BEFOREok with (tsk_other := (job_task j0)); try by done.
          apply leq_ltn_trans with (n := t); last first.
          {
            apply leq_trans with (n := t1 + R); first by done.
            rewrite leq_add2r leq_add2l -JOBtsk.
393
            by specialize (JOBPARAMS j H_j_arrives); des.
394 395 396 397 398
          }
          apply leq_trans with (n := job_arrival j0 + task_period (job_task j0)); last by done.
          by rewrite -addnA leq_add2l; apply leq_trans with (n := task_deadline (job_task j0));
            [by apply NOMISS | apply CONSTR; rewrite FROMTS].
        Qed.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
399 400 401 402 403 404 405 406 407 408 409 410 411


        (* 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 &&
          other_task tsk_other.
      
        (* 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_edf_all_cpus_are_busy:
          forall t,
            t1 <= t < t1 + R ->
412
            backlogged job_arrival job_cost job_jitter sched j t ->
Felipe Cerqueira's avatar
Felipe Cerqueira committed
413 414 415 416 417
            count (other_scheduled_task t) ts = num_cpus.
        Proof.
          rename H_all_jobs_from_taskset into FROMTS,
                 H_valid_task_parameters into PARAMS,
                 H_valid_job_parameters into JOBPARAMS,
418
                 H_job_of_tsk into JOBtsk, H_jobs_come_from_arrival_sequence into FROMSEQ,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
419 420 421 422 423 424 425 426 427 428
                 H_sporadic_tasks into SPO,
                 H_tsk_R_in_rt_bounds into INbounds,
                 H_all_previous_jobs_completed_on_time into BEFOREok,
                 H_tasks_miss_no_deadlines into NOMISS,
                 H_rt_bounds_contains_all_tasks into UNZIP,
                 H_constrained_deadlines into RESTR,
                 H_work_conserving into WORK.
          unfold x, X, total_interference, task_interference,
                 valid_sporadic_job_with_jitter, valid_sporadic_job in *.
          move => t /andP [LEt LTt] BACK.
429 430 431 432 433 434 435 436
          have PLAT := platform_cpus_busy_with_interfering_tasks task_cost task_period task_deadline
            job_arrival job_cost job_task job_jitter arr_seq sched FROMSEQ WORK.
          apply PLAT with (j := j); try (by done);
            [by apply PARAMS; rewrite -JOBtsk; apply FROMTS | clear PLAT].
          intros j0 tsk0 ARR0 TSK0 LE.
          cut (tsk0 \in unzip1 rt_bounds = true); last by rewrite UNZIP -TSK0 FROMTS //.
          move => /mapP [p IN EQ]; destruct p as [tsk' R0]; simpl in *; subst tsk'.
          apply completion_monotonic with (t0 := job_arrival j0 + task_jitter tsk0 + R0); try (by done).
Felipe Cerqueira's avatar
Felipe Cerqueira committed
437
          {
438 439 440 441 442 443 444 445 446 447 448 449 450
            rewrite -addnA leq_add2l TSK0.
            apply leq_trans with (n := task_deadline tsk0); first by apply NOMISS.
            by apply RESTR; rewrite -TSK0 FROMTS.
          }
          {
            apply BEFOREok with (tsk_other := tsk0); try (by done).
            apply leq_trans with (n := t1 + R);
              last by rewrite leq_add2r leq_add2l -JOBtsk; specialize (JOBPARAMS j H_j_arrives); des.
            apply leq_ltn_trans with (n := t); last by done.
            apply leq_trans with (n := job_arrival j0 + task_period tsk0); last by done.
            rewrite -addnA leq_add2l.
            apply leq_trans with (n := task_deadline tsk0); first by apply NOMISS.
            by apply RESTR; rewrite -TSK0; apply FROMTS.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
451 452 453 454 455 456 457 458 459 460 461 462
          }
        Qed.

      (* 4) Next, we prove that the sum of the interference of each task is equal
          to the total interference multiplied by the number of processors. This
          holds because interference only occurs when all processors are busy.
          With this lemma we can relate per-task interference with the total
          interference incurred by j (backlogged time). *)
        Lemma bertogna_edf_interference_on_all_cpus :
          \sum_(tsk_k <- other_tasks) x tsk_k = X * num_cpus.
        Proof.
          have DIFFTASK := bertogna_edf_interference_by_different_tasks.
463
          rename H_all_jobs_from_taskset into FROMTS, H_valid_task_parameters into PARAMS,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
464
                 H_job_of_tsk into JOBtsk, H_sporadic_tasks into SPO,
465
                 H_work_conserving into WORK, H_jobs_come_from_arrival_sequence into FROMSEQ,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
466 467
                 H_tsk_R_in_rt_bounds into INbounds,
                 H_all_previous_jobs_completed_on_time into BEFOREok,
468
                 H_tasks_miss_no_deadlines into NOMISS, H_rt_bounds_contains_all_tasks into UNZIP,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
469 470 471 472
                 H_constrained_deadlines into CONSTR.
          unfold sporadic_task_model in *.
          unfold x, X, total_interference, task_interference.
          rewrite -big_mkcond -exchange_big big_distrl /= mul1n.
473
          rewrite [\sum_(_ <= _ < _ | backlogged _ _ _ _ _ _) _]big_mkcond.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
474
          apply eq_big_nat; move => t /andP [GEt LTt].
475
          destruct (backlogged job_arrival job_cost job_jitter sched j t) eqn:BACK;
Felipe Cerqueira's avatar
Felipe Cerqueira committed
476 477 478 479 480
            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 _.
481 482 483
          move: (WORK j t H_j_arrives BACK cpu) => [j_other /eqP SCHED]; unfold scheduled_on in *.
          have ARRother: arrives_in arr_seq j_other.
            by apply (FROMSEQ j_other t); apply/existsP; exists cpu; apply/eqP.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504
          rewrite (bigD1_seq (job_task j_other)) /=; last by rewrite filter_uniq; destruct ts.
          {
            rewrite (eq_bigr (fun i => 0));
              last by intros i DIFF; rewrite /task_scheduled_on SCHED;apply/eqP;rewrite eqb0 eq_sym.
            simpl_sum_const; apply/eqP; rewrite eqb1.
            by unfold task_scheduled_on; rewrite SCHED.
          }
          rewrite mem_filter; apply/andP; split; last by apply FROMTS.
          apply DIFFTASK with (t := t); [by auto | by done |].
          by apply/existsP; exists cpu; apply/eqP.
        Qed.

        (* 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) (other_tasks).

        (* 5) 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_edf_interference_in_non_full_processors :
505
          forall delta,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
506 507
            0 < num_tasks_exceeding delta < num_cpus ->
            \sum_(i <- other_tasks | x i < delta) x i >= delta * (num_cpus - num_tasks_exceeding delta).
508
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
509
          have COMP := bertogna_edf_all_previous_jobs_complete_by_their_period.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
510
          have INV := bertogna_edf_all_cpus_are_busy.
511
          rename H_all_jobs_from_taskset into FROMTS, H_valid_task_parameters into PARAMS,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
512
                 H_job_of_tsk into JOBtsk, H_sporadic_tasks into SPO,
513
                 H_tsk_R_in_rt_bounds into INbounds, H_jobs_come_from_arrival_sequence into FROMSEQ,
514 515
                 H_all_previous_jobs_completed_on_time into BEFOREok,
                 H_tasks_miss_no_deadlines into NOMISS,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
516
                 H_constrained_deadlines into CONSTR, H_sequential_jobs into SEQ.
517
          unfold sporadic_task_model in *.
518 519 520
          move => delta /andP [HAS LT]. 
          rewrite -has_count in HAS.

521
          set some_interference_A := fun t =>
522
            has (fun tsk_k => backlogged job_arrival job_cost job_jitter sched j t &&
523
                              (x tsk_k >= delta) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
524
                              task_is_scheduled job_task sched tsk_k t) other_tasks.
525
          set total_interference_B := fun t =>
526
              backlogged job_arrival job_cost job_jitter sched j t *
527
              count (fun tsk_k => (x tsk_k < delta) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
528
                    task_is_scheduled job_task sched tsk_k t) other_tasks.
529 530

          apply leq_trans with ((\sum_(t1 <= t < t1 + R)
Felipe Cerqueira's avatar
Felipe Cerqueira committed
531
                                some_interference_A t) * (num_cpus - num_tasks_exceeding delta)).
532 533 534 535 536
          {
            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.
537
            apply leq_sum_nat; move => t /andP [GEt LTt] _.
538
            destruct (backlogged job_arrival job_cost job_jitter sched j t) eqn:BACK;
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
              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'.
564 565 566 567 568
            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 job_jitter sched j1 t).
569 570 571 572
            {
              apply scheduled_implies_pending; try by done.
              by apply/existsP; exists cpu; apply/eqP.
            }
573
            assert (PENDING2: pending job_arrival job_cost job_jitter sched j2 t).
574 575 576 577 578 579 580 581
            {
              apply scheduled_implies_pending; try by done.
              by apply/existsP; exists cpu'; apply/eqP.
            }
            assert (BUG: j1 = j2).
            {
              apply platform_at_most_one_pending_job_of_each_task with (task_cost0 := task_cost)
               (job_jitter0 := job_jitter) (task_period0 := task_period) (job_cost0 := job_cost)
582 583
               (task_deadline0 := task_deadline) (tsk0 := tsk) (job_task0 := job_task)
               (sched0 := sched) (job_arrival0 := job_arrival) (arr_seq0 := arr_seq)
584 585
               (j0 := j) (t0 := t);
              rewrite ?JOBtsk ?SAMEtsk //; first by apply PARAMS; rewrite -JOBtsk FROMTS.
586
              by intros j0 tsk0 ARR0 TSK0 LE; apply (COMP t); rewrite ?TSK0.
587 588
            }
            by subst j2; apply SEQ with (j := j1) (t := t).
589
          }
590 591

          apply leq_trans with (\sum_(t1 <= t < t1 + R) total_interference_B t).
592 593
          {
            rewrite big_distrl /=.
594
            apply leq_sum_nat; move => t LEt _.
595
            unfold some_interference_A, total_interference_B. 
596
            destruct (backlogged job_arrival job_cost job_jitter sched j t) eqn:BACK;
597 598
              [rewrite mul1n /= | by rewrite has_pred0 //].

599
            destruct (has (fun tsk_k : sporadic_task => (delta <= x tsk_k) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
600
                       task_is_scheduled job_task sched tsk_k t) other_tasks) eqn:HAS';
601
              last by done.
602
            rewrite mul1n; move: HAS => /hasP [tsk_k INk LEk].
Felipe Cerqueira's avatar
Felipe Cerqueira committed
603
            unfold num_tasks_exceeding.
604 605
            apply leq_trans with (n := num_cpus -
                         count (fun i => (x i >= delta) &&
Felipe Cerqueira's avatar
Felipe Cerqueira committed
606
                            task_is_scheduled job_task sched i t) other_tasks).
607 608 609 610 611
            {
              apply leq_sub2l.
              rewrite -2!sum1_count big_mkcond /=.
              rewrite [\sum_(_ <- _ | _ <= _)_]big_mkcond /=.
              apply leq_sum; intros i _.
612
              by destruct (task_is_scheduled job_task sched i t);
613 614
                [by rewrite andbT | by rewrite andbF].
            }
Felipe Cerqueira's avatar
Felipe Cerqueira committed
615
            rewrite -count_filter -[count _ other_tasks]count_filter.
616 617 618
            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
619
            by apply leq_trans with (n := count (other_scheduled_task t) ts);
Felipe Cerqueira's avatar
Felipe Cerqueira committed
620
              [by rewrite INV | by rewrite count_filter].
621 622
          }
          {
623 624
            unfold x at 2, total_interference_B.
            rewrite exchange_big /=; apply leq_sum; intros t _.
625
            destruct (backlogged job_arrival job_cost job_jitter sched j t) eqn:BACK; last by ins.
626
            rewrite mul1n -sum1_count.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
627
            rewrite big_mkcond [\sum_(i <- other_tasks | _ < _) _]big_mkcond /=.
628 629 630 631 632
            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.
633 634 635
          }
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
636 637 638
        (* 6) Based on lemma (5), 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. *)
639 640
        Lemma bertogna_edf_minimum_exceeds_interference :
          forall delta,
Felipe Cerqueira's avatar
Felipe Cerqueira committed
641 642
            \sum_(tsk_k <- other_tasks) x tsk_k >= delta * num_cpus ->
               \sum_(tsk_k <- other_tasks) minn (x tsk_k) delta >=
643 644 645 646 647 648 649 650 651 652 653 654 655
               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
656 657
          (* Case 1: num_tasks_exceeding = 0 *)
          destruct (~~ has (fun i => delta <= x i) other_tasks) eqn:HASa.
658 659 660
          {
            rewrite [\sum_(_ <- _ | _ <= _) _]big_hasC; last by apply HASa.
            rewrite big_seq_cond; move: HASa => /hasPn HASa.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
661 662
            rewrite add0n (eq_bigl (fun i => (i \in other_tasks) && true));
              last by red; intros tsk_k; destruct (tsk_k \in other_tasks) eqn:INk;
663 664 665 666
                [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
667 668
          (* Case 2: num_tasks_exceeding >= num_cpus *)
          destruct (num_tasks_exceeding delta >= num_cpus) eqn:CARD.
669
          {
Felipe Cerqueira's avatar
Felipe Cerqueira committed
670
            apply leq_trans with (delta * num_tasks_exceeding delta);
671
              first by rewrite leq_mul2l; apply/orP; right.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
672
            unfold num_tasks_exceeding; rewrite -sum1_count big_distrr /=.
673 674 675 676
            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
677 678 679 680
          (* 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));
681
            first by rewrite -mulnDr subnKC //; apply ltnW.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
682
          rewrite leq_add2l; apply bertogna_edf_interference_in_non_full_processors.
683
          by apply/andP; split; first by rewrite -has_count.
684 685
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
686 687 688
        (* 7) Next, using lemmas (0), (4) and (6) 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). *)
689
        Lemma bertogna_edf_sum_exceeds_total_interference:
Felipe Cerqueira's avatar
Felipe Cerqueira committed
690
          \sum_((tsk_other, R_other) <- rt_bounds | other_task tsk_other)
691 692
            minn (x tsk_other) (R - task_cost tsk + 1) > I tsk R.
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
693 694
          have GE_COST := bertogna_edf_R_other_ge_cost.
          have EXCEEDS := bertogna_edf_minimum_exceeds_interference.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
695
          have ALLBUSY := bertogna_edf_interference_on_all_cpus.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
696
          have TOOMUCH := bertogna_edf_too_much_interference.
697 698
          rename H_rt_bounds_contains_all_tasks into UNZIP,
            H_response_time_is_fixed_point into REC.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
699
          apply leq_trans with (n := \sum_(tsk_other <- other_tasks) minn (x tsk_other) (R - task_cost tsk + 1));
700 701 702 703 704
            last first.
          {
            rewrite (eq_bigr (fun i => minn (x (fst i)) (R - task_cost tsk + 1)));
              last by ins; destruct i.
            move: UNZIP => UNZIP.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
705 706
            assert (FILTER: filter other_task (unzip1 rt_bounds) =
                            filter other_task ts).
707
              by f_equal.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
708
            unfold other_tasks; rewrite -FILTER; clear FILTER.
709 710
            rewrite -[\sum_(_ <- rt_bounds | _)_]big_filter.
            assert (SUBST: [seq i <- rt_bounds
Felipe Cerqueira's avatar
Felipe Cerqueira committed
711 712
                             | let '(tsk_other, _) := i in other_task tsk_other] =
                           [seq i <- rt_bounds | other_task (fst i)]).
713 714 715 716 717 718 719 720 721 722 723 724
            {
              by apply eq_filter; red; intro i; destruct i.
            } rewrite SUBST; clear SUBST.         
            have MAP := big_map (fun x => fst x) (fun i => true) (fun i => minn (x i) (R - task_cost tsk + 1)).
            by rewrite -MAP; apply eq_leq; f_equal; rewrite filter_map.
          }

          apply ltn_div_trunc with (d := num_cpus); first by apply H_at_least_one_cpu.
          rewrite -(ltn_add2l (task_cost tsk)) -REC; last by done.
          rewrite -addn1 -leq_subLR.
          rewrite -[R + 1 - _]subh1; last by apply GE_COST.
          rewrite leq_divRL; last by apply H_at_least_one_cpu.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
725 726 727
          apply EXCEEDS.
          apply leq_trans with (n := X * num_cpus); last by rewrite ALLBUSY.
          by rewrite leq_mul2r; apply/orP; right; apply TOOMUCH.
728 729
        Qed.

Felipe Cerqueira's avatar
Felipe Cerqueira committed
730 731 732 733 734
        (* 8) 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, I_edf, R - e_i + 1).
              This implies that either x_k > W_k or x_k > I_edf, which is a contradiction,
              since both W_k and I_edf are valid task interference bounds. *)
735 736 737 738 739
        Lemma bertogna_edf_exists_task_that_exceeds_bound :
          exists tsk_other R_other,
            (tsk_other, R_other) \in rt_bounds /\
            (minn (x tsk_other) (R - task_cost tsk + 1) > interference_bound tsk_other R_other).
        Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
740 741 742
          have SUM := bertogna_edf_sum_exceeds_total_interference.
          have BOUND := bertogna_edf_workload_bounds_interference.
          have EDFBOUND := bertogna_edf_specific_bound_holds.
743 744 745
          rename H_rt_bounds_contains_all_tasks into UNZIP.
          assert (HAS: has (fun tup : task_with_response_time =>
                              let (tsk_other, R_other) := tup in
Felipe Cerqueira's avatar
Felipe Cerqueira committed
746
                              (tsk_other \in ts) && other_task tsk_other &&
747 748 749 750 751 752 753 754 755
                                (minn (x tsk_other) (R - task_cost tsk + 1)  >
                                interference_bound tsk_other R_other))
                           rt_bounds).
          {
            apply/negP; unfold not; intro NOTHAS.
            move: NOTHAS => /negP /hasPn ALL.
            rewrite -[_ < _]negbK in SUM.
            move: SUM => /negP SUM; apply SUM; rewrite -leqNgt.
            unfold I, total_interference_bound_edf.
756
            rewrite big_seq_cond [X in _ <= X]big_seq_cond.
757 758 759 760 761 762 763
            apply leq_sum; move => tsk_k /andP [INBOUNDSk INTERFk]; destruct tsk_k as [tsk_k R_k].
            specialize (ALL (tsk_k, R_k) INBOUNDSk).
            unfold interference_bound_edf; simpl in *.
            rewrite leq_min; apply/andP; split.
            {
              unfold interference_bound; rewrite leq_min; apply/andP; split;
                last by rewrite geq_minr.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
764 765
              by apply leq_trans with (n := x tsk_k);
                [by rewrite geq_minl | by apply BOUND].
766 767 768
            }
            {
              apply leq_trans with (n := x tsk_k); first by rewrite geq_minl.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
769
              by apply EDFBOUND.
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791
            }
          }
          move: HAS => /hasP HAS; destruct HAS as [[tsk_k R_k] HPk MIN].
          move: MIN => /andP [/andP [INts INTERFk] MINk].
          by exists tsk_k, R_k; repeat split.
        Qed.

      End DerivingContradiction.
      
    End Lemmas.

    Section MainProof.
      
      (* Let (tsk, R) be any task to be analyzed, with its response-time bound R. *)
      Variable tsk: sporadic_task.
      Variable R: time.
      Hypothesis H_tsk_R_in_rt_bounds: (tsk, R) \in rt_bounds.

      (* Using the lemmas above, we prove that R bounds the response time of task tsk. *)
      Theorem bertogna_cirinei_response_time_bound_edf :
        response_time_bounded_by tsk (task_jitter tsk + R).
      Proof.
Felipe Cerqueira's avatar
Felipe Cerqueira committed
792 793 794
        have EXISTS := bertogna_edf_exists_task_that_exceeds_bound.
        have BASICBOUND := bertogna_edf_workload_bounds_interference.
        have EDFBOUND := bertogna_edf_specific_bound_holds.
795 796
        rename H_valid_job_parameters into JOBPARAMS.
        unfold valid_sporadic_job_with_jitter, valid_sporadic_job in *.
797
        intros j ARRj JOBtsk.
798 799 800 801 802 803 804 805 806 807 808

        rewrite addnA.
        (* First, rewrite the claim in terms of the *absolute* response-time bound (arrival + R) *)
        remember (job_arrival j + task_jitter tsk + R) as ctime.

        revert H_tsk_R_in_rt_bounds.
        generalize dependent R; generalize dependent tsk; generalize dependent j.
      
        (* Now, we apply strong induction on the absolute response-time bound. *)
        induction ctime as [ctime IH] using strong_ind.

809
        intros j ARRj tsk' JOBtsk R' EQc INbounds; subst ctime.
810 811

        (* First, let's simplify the induction hypothesis. *)
812 813
        assert (BEFOREok: forall j0 tsk R0,
                                 arrives_in arr_seq j0 ->
814 815 816
                                 job_task j0 = tsk ->
                               (tsk, R0) \in rt_bounds ->
                               job_arrival j0 + task_jitter tsk + R0 < job_arrival j + task_jitter tsk' + R' ->
817
                               service sched j0 (job_arrival j0 + task_jitter tsk + R0) >= job_cost j0).
818 819 820 821 822 823 824 825 826 827 828 829
        {
            by ins; apply IH with (tsk := tsk0) (R := R0).
        }
        clear IH.
        
        (* The proof follows by contradiction. Assume that job j does not complete by its
           response-time bound. By the induction hypothesis, all jobs with absolute
           response-time bound t < (job_arrival j + R) have correct response-time bounds. *)
        destruct (completed job_cost sched j (job_arrival j + job_jitter j + R')) eqn:NOTCOMP.
        {
          apply completion_monotonic with (t := job_arrival j + job_jitter j + R'); try (by done).
          rewrite leq_add2r leq_add2l.
830
          specialize (JOBPARAMS j ARRj); des.
831 832 833 834 835
          by rewrite -JOBtsk; apply JOBPARAMS0.
        }
        apply negbT in NOTCOMP; exfalso.
        
        (* Next, we derive a contradiction using the previous lemmas. *)
836
        exploit (EXISTS tsk' R' INbounds j ARRj JOBtsk NOTCOMP).
837 838 839 840 841 842
        {
          by ins; apply IH with (tsk := tsk_other) (R := R_other).
        } 
        intro EX; destruct EX as [tsk_other [R_other [HP LTmin]]].
        unfold interference_bound_edf, interference_bound_generic in LTmin.
        rewrite minnAC in LTmin; apply min_lt_same in LTmin.
843
        specialize (BASICBOUND tsk' R' j ARRj JOBtsk BEFOREok tsk_other R_other HP).
844
        specialize (EDFBOUND tsk' R' j ARRj JOBtsk BEFOREok tsk_other R_other HP).
845 846 847 848 849 850 851 852 853 854 855 856 857 858
        unfold minn in LTmin; clear -LTmin HP BASICBOUND EDFBOUND tsk; desf.
        {
          by apply (leq_ltn_trans BASICBOUND) in LTmin; rewrite ltnn in LTmin. 
        }
        {
          by apply (leq_ltn_trans EDFBOUND) in LTmin; rewrite ltnn in LTmin.
        }
      Qed.

    End MainProof.
    
  End ResponseTimeBound.

End ResponseTimeAnalysisEDFJitter.