Compositional Sequentialization of Periodic Programs Sagar Chaki 1

  • Slides: 26
Download presentation
Compositional Sequentialization of Periodic Programs Sagar Chaki 1, Arie Gurfinkel 1, Soonho Kong 2,

Compositional Sequentialization of Periodic Programs Sagar Chaki 1, Arie Gurfinkel 1, Soonho Kong 2, Ofer Strichman 3 Jan 22, 2013 1 Software Engineering Institute, CMU 2 Computer Science Department, CMU 3 Technion, Israel Institute of Technology © 2012 Carnegie Mellon University

Time-Bounded Verification of Periodic Programs Periodic Program • Collection of periodic tasks • Execute

Time-Bounded Verification of Periodic Programs Periodic Program • Collection of periodic tasks • Execute concurrently with fixed-priority scheduling • Priorities respect RMS • Communicate through shared memory • Synchronize through preemption and priority ceiling locks Time-Bounded Verification • Assertion A violated within X ms of a system’s execution from initial state I? • A, X , I are user specified • Time bounds map naturally to program’s functionality (e. g. , air bags) Assumptions • System is schedulable • WCET of each task is given Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 2

Motivation: Real-Time Embedded Systems Avionics Mission System* Rate Monotonic Scheduling (RMS) Task Period weapon

Motivation: Real-Time Embedded Systems Avionics Mission System* Rate Monotonic Scheduling (RMS) Task Period weapon release 10 ms radar tracking 40 ms target tracking 40 ms aircraft flight data 50 ms display 50 ms steering 80 ms *Locke, Vogel, Lucas, and Goodenough. “Generic Avionics Software Specification”. SEI/CMU Technical Report CMU/SEI-90 -TR-8 -ESD-TR-90 -209, December, 1990 Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 3

Periodic Program (PP) An N-task periodic program PP is a set of tasks {

Periodic Program (PP) An N-task periodic program PP is a set of tasks { 1, …, N} A task is a tuple I, T, P, C, A , where • • • I is a task identifier T is a task body (i. e. , code) P is a period C is the worst-case execution time A is the release time: the time at which task becomes first enabled Semantics of PP is given by an asynchronous concurrent program: parallel execution w/ priorities blocks task i until next arrival time ki = 0; while (Wait( i, ki)) Ti (); ki = ki + 1; Hyper-period = Least Common Multiple of all periods • Program is harmonic if periods are multiples of each other Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 4

Time Bounded Semantics of Periodic Program Assumptions • (A 1) Time window W is

Time Bounded Semantics of Periodic Program Assumptions • (A 1) Time window W is divisible by the hyper-period (i. e. , W | H ) • (A 2) Each task arrives in time to complete in 1 st period (i. e. , Ai + RTi Pi) The time bound imposes a natural bound on # of jobs: Ji = W / Pi Time-Bounded Semantics of PP is ki = 0; while (ki < Ji && Wait( i, ki)) Ti (); ki = ki + 1; Job-Bounded Abstraction • Abstracts away time • Approximates Wait() by a non-deterministic delay • Preserves logical (time-independent) properties! Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 5

Our tool: REK Supports C programs w/ tasks, priorities, priority ceiling protocol, shared variables

Our tool: REK Supports C programs w/ tasks, priorities, priority ceiling protocol, shared variables Works in two stages: 1. Sequentialization – reduction to sequential program w/ prophecy variables 2. Bounded program analysis: CBMC, HAVOC, others Periodic Program in C Sequential Program Sequentialization OK Analysis BUG + CEX Periods, WCETs, Initial Condition, Time bound Uses non-determinism (prophecy variables) to allow all possible interleavings between jobs Contribution 1: Compositional Sequentialization – allows fewer interleavings between tasks and shorter counterexamples without losing soundness Verifying Periodic Real-Time Software Contribution 2: Empirical evaluation showing improvement Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 6

Example: A Harmonic PP 3 processors 2 1 0 D 12 8 4 E

Example: A Harmonic PP 3 processors 2 1 0 D 12 8 4 E F B 16 G C A Task WCET (Ci) Period (Pi) Arrival Time (Ai) 2 1 4 0 1 2 8 0 0 5 16 0 Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 7

Example: One Task Schedule 1 processor 2 1 0 D 12 8 4 E

Example: One Task Schedule 1 processor 2 1 0 D 12 8 4 E F B 16 G C A A A Task WCET (Ci) Period (Pi) Arrival Time (Ai) 2 1 4 0 1 2 8 0 0 5 16 0 Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 8

Compositional sequentialization Leverages two types of temporal separation between jobs Intra-Hyper-Period • Between jobs

Compositional sequentialization Leverages two types of temporal separation between jobs Intra-Hyper-Period • Between jobs within the same hyper-period • Prevents certain jobs in the same hyper-period from interleaving based on their priorities, arrival times, and worst-case execution times Inter-Hyper-Period • Between jobs across different hyper-periods • Prevents interleaving between jobs from different hyper-periods • Relies on assumption A 2, which guarantees that all jobs in hyper-period i complete before any job in hyper-period (i+1) starts. Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 9

Intra-Hyper-Period Temporal Separation E starts and finishes before F F starts and finishes before

Intra-Hyper-Period Temporal Separation E starts and finishes before F F starts and finishes before C D starts and finishes before B B starts and finishes before A G starts and finished after every other job Monolithic Sequentialization (FMCAD 11) (A) || (B; C) || (D; E; F; G) Compositional Sequentialization (VMCAI 13) D; B; (A || (E; F; C)); G Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 10

Under assumptions A 1 and Inter-Hyper-Period Temporal Separation A 2, All HP 1 jobs

Under assumptions A 1 and Inter-Hyper-Period Temporal Separation A 2, All HP 1 jobs end before any HP 2 job starts HP 1 HP 2 Monolithic Sequentialization (FMCAD 11) (A; A) || (B; C; B; C) || (D; E; F; G; D; E; F; G) Compositional Sequentialization (VMCAI 13) D; B; (A || (E; F; C)); G ; D; B; (A || (E; F; C)); G Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 11

Partition Execution into Rounds Execution starts in round 0 A round ends, and a

Partition Execution into Rounds Execution starts in round 0 A round ends, and a new one begins, each time a job finishes • # rounds == # of jobs 2 D E 0 Rounds F B 1 1 16 G C A 0 12 8 4 A 2 A 3 4 5 6 Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 12

Compositional Sequentialization Sequential Program for execution of R rounds: 1. 2. 3. Define three

Compositional Sequentialization Sequential Program for execution of R rounds: 1. 2. 3. Define three job orderings based on priorities, WCET, and arrival time: /, ", @ for each global variable g, let g[i] be the value of g in round i (Schedule. Jobs) choose for each job j – start round: start[j] – end round: end[j] Constrained by /, ", @ (Run. Jobs) execute job bodies sequentially Ordered by @ – in some well-defined total order – for global variables, use g[i] instead of g when running in round i – non-deterministically decide where to context switch Done as soon as – at a context switch jump to a new round (cannot preempt a higher task) job ending at round i is over. 4. 5. (Check. Assumptions) check that initial value of round i+1 is the final value of round i (Check. Assertions) check user assertions Done as soon as job (containing the assertion) and step 4 are over. Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 13

Job Ordering Priority Departure Time J 1 / J 2 (¼(J 1) · ¼(J

Job Ordering Priority Departure Time J 1 / J 2 (¼(J 1) · ¼(J 2) Æ D(J 1) · D(J 2)) Ç (¼(J 1) > ¼(J 2) Æ A(J 1) · A(J 2)) • J 1 completes before J 2 starts Arrival Time J 1 " J 2 (¼(J 1) < ¼(J 2) Æ A(J 1) < A(J 2) < D(J 1)) • J 1 “could be” (due to WCET) preempted by J 2 J 1 @ J 2 (J 1 / J 2) Ç (J 1 " J 2) • Total order: lexicographic by (A, -¼) (see Lemma 1) Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 14

Compositional Sequentialization: Schedule. Jobs Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie

Compositional Sequentialization: Schedule. Jobs Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 15

Case Study: A Metal Stamping Robot a. k. a. LEGO Turing Machine http: //www.

Case Study: A Metal Stamping Robot a. k. a. LEGO Turing Machine http: //www. youtube. com/watch? v=te. Dyd 0 d 5 M 4 o Image courtesy of Taras Kowaliw Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 16

Turing Machine: Task Structure Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie

Turing Machine: Task Structure Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 17

An Example Property When writer flips a bit, the tape motor and read motor

An Example Property When writer flips a bit, the tape motor and read motor should stop. Controller Task Writer Task Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 18

NXTway-GS: a 2 wheeled self-balancing robot Original: nxt (2 tasks) • balancer (4 ms)

NXTway-GS: a 2 wheeled self-balancing robot Original: nxt (2 tasks) • balancer (4 ms) – Keeps the robot upright and responds to BT commands • obstacle (50 ms) – monitors sonar sensor for obstacle and communicates with balancer to back up the robot Ours: aso (3 tasks) • balancer as above but no BT • obstacle as above • bluetooth (100 ms) – responds to BT commands and communicates with the balancer Verified consistency of communication between tasks Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 19

Results: Turing Machine 400 x speedup Timeout (1 day) success Verifying Periodic Real-Time Software

Results: Turing Machine 400 x speedup Timeout (1 day) success Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 20

Results: Self-Balancing Robot Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon

Results: Self-Balancing Robot Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 21

Results: Self-Balancing Robot Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon

Results: Self-Balancing Robot Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 22

Related Work Sequentialization of Concurrent Programs (Lal & Reps ‘ 08, and others) •

Related Work Sequentialization of Concurrent Programs (Lal & Reps ‘ 08, and others) • • • Context Bounded Analysis of concurrent programs via sequentialization Arbitrary concurrent software Non-deterministic round robin scheduler Preserve executions with bounded number of thread preemptions Allow for arbitrary number of preemptions between tasks Sequentialization of Periodic Programs (Kidd, Jagannathan, Vitek ’ 10) • • Same setting as this work Alternative sol’n: replace preemptions by non-deterministic function calls Additionally, supports recursion and inheritance locks No publicly available implementation – would be interesting to compare Verification of Time Properties of (Models of) Real Time Embedded Systems Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 23

Conclusion Past (FMCAD’ 11) • • Time Bounded Verification of Periodic C Programs Small

Conclusion Past (FMCAD’ 11) • • Time Bounded Verification of Periodic C Programs Small (but hard) toy programs Reader/Writer protocols (with locks and lock-free versions) A robot controller for LEGO MINDSTORM from nxt. OSEK examples Present (VMCAI’ 13) • Taking into account additional timing constraints for improved scheduling – arrival times, harmonicity, etc. • A Lego Metal Stamping Robot (a. k. a. Turing Machine) • http: //www. andrew. cmu. edu/~arieg/Rek (look for Turing Machine demo) Current Work • • Verification without the time bound Back-End Verification engine Abstraction / Refinement Additional communication and synchronization – Priority-inheritance locks, message passing • Modeling physical aspects (i. e. , environment) more faithfully • More Case studies and model problems Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 24

This material is based upon work funded and supported by the Department of Defense

This material is based upon work funded and supported by the Department of Defense under Contract No. FA 8721 -05 -C-0003 with Carnegie Mellon University for the operation of the Software Engineering Institute, a federally funded research and development center. NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN “AS-IS” BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. This material has been approved for public release and unlimited distribution. This material may be reproduced in its entirety, without modification, and freely distributed in written or electronic form without requesting formal permission. Permission is required for any other use. Requests for permission should be directed to the Software Engineering Institute at permission@sei. cmu. edu. Carnegie Mellon® is registered in the U. S. Patent and Trademark Office by Carnegie Mellon University. DM-0000142 Verifying Periodic Real-Time Software Chaki, Gurfinkel, Strichman © 2012 Carnegie Mellon University 25

QUESTIONS? http: //www. andrew. cmu. edu/~arieg/Rek Sagar Chaki [chaki@sei. cmu. edu] © 2012 Carnegie

QUESTIONS? http: //www. andrew. cmu. edu/~arieg/Rek Sagar Chaki [chaki@sei. cmu. edu] © 2012 Carnegie Mellon University