cec 450 real-time systems - embry–riddle aeronautical...

18
September 16, 2019 Sam Siewert CEC 450 Real - Time Systems Lecture 4 Rate Monotonic Theory Part 2

Upload: others

Post on 25-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

  • September 16, 2019 Sam Siewert

    CEC 450Real-Time Systems

    Lecture 4 – Rate Monotonic TheoryPart 2

  • Quiz Results86% Average, 73 low, 100 high

    Goal is to learn what you’re not learning yet– Motivation to keep up with reading– Practice and prepare for future Exams– 4 Total Quizzes + Take-away Quiz (replaces lowest)

    2 on Fundamental concepts

    One before each Mid-term exam as well

    Sam Siewert 2

  • Assignment #1 – Scheduling LinuxLook over candidate solution for scheduling - lab1.cNote Method for Enabling all CPU cores on Jetson– Set processor affinity for an AMP RT core– Use binary semaphore to BLOCK and to release Services – Set SCHED_FIFO RT priorities– Timed Execution for C, based on benchmark synthetic load– Cache warmup (first few iterations are invalid)– Use of SW nanosleep vs. SW interval timer and signal vs. HW

    interval timer and ISR– Resulting predictability - ISR driven request for service is best

    Limitations of Linux and “user space” processes and threadsLinux provides predictable responseRTOS more deterministicHW state machine most deterministic

    Sam Siewert 3

    http://mercury.pr.erau.edu/%7Esiewerts/cec450/code/sequencer/lab1.c

  • Scheduling Linuxlab1.c

    Modify the Sequencer loop for specific RMA Scenario over Major Period

    Scale Time Units by 10

    Sam Siewert 4

    Example A#1 T1 2 C1 1 U1 0.5 LCM = 10T2 5 C2 2 U2 0.4

    Utot = 0.9

    RM Schedule 1 2 3 4 5 6 7 8 9 10F10F20S3

    System has 4 processors configured and 4 available.Using CPUS=1 from total available.Pthread Policy is SCHED_FIFOPTHREAD SCOPE SYSTEMrt_max_prio=99rt_min_prio=1Service threads will run on 1 CPU coresF10 runtime calibration 0.101834 msec per 100 test cycles, so 98 requiredF20 runtime calibration 0.101417 msec per 100 test cycles, so 197 requiredStart sequencerStarting Sequencer: [S1, T1=20, C1=10], [S2, T2=50, C2=20], U=0.9, LCM=100

    **** CI t=0.004333F10 start 1 @ 0.241167 on core 3F10 complete 1 @ 10.001917, 98 loopsF20 start 1 @ 10.184167 on core 3t=20.259917F10 start 2 @ 20.353500 on core 3F10 complete 2 @ 30.146167, 98 loopsF20 complete 1 @ 39.858917, 197 loopst=40.539083F10 start 3 @ 40.659917 on core 3F10 complete 3 @ 50.289333, 98 loopst=50.713667F20 start 2 @ 50.799833 on core 3t=60.833167F10 start 4 @ 60.917250 on core 3F10 complete 4 @ 70.678500, 98 loopsF20 complete 2 @ 80.251417, 197 loopst=80.985000F10 start 5 @ 81.078167 on core 3F10 complete 5 @ 90.812750, 98 loops

    http://mercury.pr.erau.edu/%7Esiewerts/cec450/code/sequencer/lab1.c

  • General Rate Observations

    Sam Siewert 5

    Rate Clock Measure Human Interaction

    Thread Context

    ISR Instructions FPGA / ASIC

    1 Hz sec seconds X X

    10 Hz 1/10thsec

    millisec X X

    100 Hz 1/100thsec

    millisec X

    1000 Hz (KHz)

    millisec microsec X X

    MHz microsec nannosec X X X

    GHz nanosec picosec X X

    THz picosec femtosec sub-nanosecond

    CPU cores run at 100’s MHz to several GHz1000 Instructions in one microsecond on GHz CPU coreThread scheduled processing down to 1 millisecondISR processing down to 1 microsecondCo-processor, Instruction below 1 microsecond to sub-nanosecond

  • Sam Siewert 6

    A Service Release and ResponseCi WCETInput/Output LatencyInterference Time

    EventSensed Interrupt Dispatch Preemption Dispatch

    Interference

    Completion(IO Queued)

    Actuation(IO Completion)

    Input-Latency

    Dispatch-Latency

    Execution Execution

    Output-Latency

    Time

    Response Time = TimeActuation – TimeSensed(From Release to Response)

  • Sam Siewert 7

    RM Assumptions and Constraints

    • A1: All Services Requested on Periodic Basis, the Period is Constant

    • A2: Completion-Time < Period

    • A3: Service Requests are Independent (No Known Phasing)

    • A4: Run-time is Known and Deterministic (WCET may be Used)

    • C1: Deadline = Period by Definition

    • C2: Fixed Priority, Preemptive, Run-to-Completion Scheduling

    • Critical Instant: longest response time for a service occurs when all system services are requested simultaneously (maximum interference case for lowest priority service)

    • No Other Shared Resources – Not in Paper, but key assumption – e.g. shared memory

  • Sam Siewert 8

    Derivation of RM LUB for 2 TasksClaim - General RM Least Upper Bound:(Guarantees that all Service Releases Can meet Deadlines)

    Goal - Derive RM LUB For 2 Tasks:

    For a System, Can All C’s fit in largest T over LCM time?Given: Services S1, S2 with periods T1 and T2 and C1 and C2, Assume T2 > T1E.g. T1=2, T2=5, C1=1, C2= 1, then if prio(S1) > prio(S2), we can see that ...

    )12()/(1

    1

    −≤=∑=

    m

    i

    mmTiCiU

    83.0)12(2// 21

    2211 ≤−≤+= TCTCU

    1/ 2 1/ 5 0.7U = + = 22112 / TCCTT ≤+

    T2T1

    C.I.

    S1S2

    22112 / TCCTT ≤+

    83.0)12(27.0 21

    ≤−≤=U

  • Sam Siewert 9

    Can You Safely Exceed LUB?YES!In some cases, but RM LUB will never pass an infeasible systemRM LUB is a SUFFICIENT Feasibility TestRM LUB is NOT a NECESSARY and SUFFICIENT Feasibility Test(Systems with Harmonic Periods can often have U=1.0 and be feasible!)

    Example Where RM LUB is Safely Exceeded:Given: Services S1, S2 with periods T1 and T2 and C1 and C2, Assume T2 > T1E.g. T1=2, T2=5, C1=1, C2= 2, then if prio(S1) > prio(S2), note that:

    9.05/22/1 =+=U

    83.09.0)12(29.0 2

    1

    >=−>=

    UU

    22112 / TCCTT ≤+

    T2T1

    C.I.

    S1S2

    22112 / TCCTT ≤+

  • Sam Siewert 10

    RM Priority Assignment PolicyRM Policy:Given: services S1, S2 with periods T1 and T2 and C1 and C2 with T2 > T1E.g. T1=2, T2=5, C1=1, C2=2, then if prio(S1) > prio(S2), note that:

    S1S2T2T1

    S1 Makes Deadline if prio(S1) > prio(S2)

    D1 D1 D2

  • Sam Siewert 11

    RM Priority Assignment PolicyConsider Alternative Policy:Given: services S1, S2 with periods T1 and T2 and C1 and C2 with T2 > T1E.g. T1=2, T2=5, C1=1, C2=2, then if prio(S2) > prio(S1), note that:

    S1S2T2T1

    S1 Misses Deadline if prio(S2) > prio(S1)

    Conclusion:If {Sn} feasible with prio(S2) > prio(S1), then {Sn} is also always feasible given prio(S1) > prio(S2), but converse is not necessarily TRUE!!Therefore, prio(S1) > prio(S2) is OPTIMAL

  • Sam Siewert 12

    RM LUB Derivation

    LUB Derivation Strategy:Case 1: C1 short enough to fit all 3 releases in T2 (fits S2 critical time zone)Case 2: C1 too large to fit last release in T2 (doesn’t fit S2 critical time zone)Examine U in both cases to find common U bound.

    12 /TT

    T2T1

    C.I.S1

    S2

    #1 #2 #3

    Finding RM Safe Upper Bound (LUB):If system feasible over LCM with RM policy, then by Worst-Case Analysis, it is safe!Note that there can be up to releases of S1 during T2!

  • Sam Siewert 13

    RM LUB Derivation

    LUB Derivation Strategy:Case 1: C1 short enough to fit all 3 releases in T2 (fits S2 critical time zone)Case 2: C1 too large to fit last release in T2 (doesn’t fit S2 critical time zone)Examine U in both cases to find common U bound.

    12 /TT

    T2T1

    C.I.S1

    S2

    #1 #2 #3

    Finding RM Safe Upper Bound (LUB):If system feasible over LCM with RM policy, then by inspection, can we say that it is safe? Certainly feasible!Note that there can be up to releases of S1 during T2!

  • Sam Siewert 14

    RM LUB DerivationCase 1 (All 3 C1 releases fit in T2):

    2

    2

    1

    1

    12122

    12121

    //

    TC

    TCU

    TTCTCTTTTC

    +=

    −=−≤

    [ ]

    ( )

    −+=

    −+=

    2

    1211

    2

    1212

    1

    1

    //11

    /

    TTTTCU

    TTTCT

    TCUPlugging C2 Expression into U:

    U monotonically decreaseswith increasing C1 when (T2>T1)

    T2T1

    C.I.S1

    S2

    #1 #2 #3

    (I.e, C2 = T2 - Interference from C1 releases)

    (I.e, C1 is small enough to fit into fractional 3rd T1 shown below as )

  • Sam Siewert 15

    Proof that U Monotonically Decreases in Case-1

  • Sam Siewert 16

    RM LUB DerivationCase 2 (Last C1 release does not fit in T2):

    2

    2

    1

    1

    1211212

    12121

    ///

    TC

    TCU

    TTCTTTCTTTTC

    +=

    −=−≥

    T2T1

    C.I.#1 #2 #3S1

    S2

    ( ) ( ) ( )

    1 2 1 1 2 11

    1 2

    1 2 2 1 1 1 2 2 1

    / /

    / / 1/ 1/ /

    T T T C T TCUT T

    U T T T T C T T T T

    − = +

    = + −

    Plugging C2 Expression into U:

    U monotonically increaseswith increasing C1 when (T2>T1)

  • Sam Siewert 17

    Proof that U Monotonically Increases in Case-2

  • Sam Siewert 18

    RM LUB DerivationGiven Cases 1 and 2 (T1=2, T2=5)

    2

    2

    1

    1

    1211212

    12121

    ///

    TC

    TCU

    TTCTTTCTTTTC

    +=

    −=−=

    Case 1 Case 2

    U

    C1

    2

    2

    1

    1

    1211212

    12121

    ///

    TC

    TCU

    TTCTTTCTTTTC

    +=

    −=−≥

    2

    2

    1

    1

    12122

    12121

    //

    TC

    TCU

    TTCTCTTTTC

    +=

    −=−≤

    =?

    1.0

    LUB

    Intersection

    Note: we want the LUB for any given T2 and T1, not the ones assumed here in particular, so the general LUB could be something other than 0.9, and must be found in terms of T1 and T2 only for general LUB.

    T1= 2 T2= 5Case 1 Case 2C1 U C1 U

    0 1 0 0.80.1 0.99 0.1 0.810.2 0.98 0.2 0.820.3 0.97 0.3 0.830.4 0.96 0.4 0.840.5 0.95 0.5 0.850.6 0.94 0.6 0.860.7 0.93 0.7 0.870.8 0.92 0.8 0.880.9 0.91 0.9 0.89

    1 0.9 1 0.9

    ( ) ( ) ( ) [ ]122111221 //1/1// TTTTCTTTTU −+=

    ( )

    −+=

    2

    1211

    //11T

    TTTCUCase 1:

    Case 2:

    Sheet1

    T1=2T2=5

    Case 1Case 2

    C1UC1U

    0100.8

    0.10.990.10.81

    0.20.980.20.82

    0.30.970.30.83

    0.40.960.40.84

    0.50.950.50.85

    0.60.940.60.86

    0.70.930.70.87

    0.80.920.80.88

    0.90.910.90.89

    10.910.9

    Sheet2

    Sheet3

    CEC 450�Real-Time SystemsQuiz ResultsAssignment #1 – Scheduling LinuxScheduling LinuxGeneral Rate ObservationsA Service Release and ResponseRM Assumptions and ConstraintsDerivation of RM LUB for 2 TasksCan You Safely Exceed LUB?RM Priority Assignment PolicyRM Priority Assignment PolicyRM LUB DerivationRM LUB DerivationRM LUB DerivationProof that U Monotonically Decreases in Case-1RM LUB DerivationProof that U Monotonically Increases in Case-2RM LUB Derivation