Ada and Real-Time. Prof. Lars Asplund. Mälardalen University, Computer Science

Similar documents
Green Hills Software, Inc.

Real-Time Programming

Today s topic: Real Time Programming with Ada

Today s topic: Real Time Programming with Ada

The Ravenscar Tasking Profile for High Integrity Real-Time Programs

Real-Time Programming Languages (ADA and Esterel as Examples)

Ada 2005 An introduction for TTK4145

Introduction to Lab 2

Embedded Systems. 6. Real-Time Operating Systems

AI Non-Preemptive Dispatching. A new dispatching policy is defined for the non-preemptive execution of Ada tasks.

The Ravenscar Tasking Profile for High Integrity Real-Time Programs

Comp2310 & Comp6310 Systems, Networks and Concurrency

On 17 June 2006, the editor provided the following list via an to the convener:

Chapter 13 Topics. Introduction. Introduction

Chapter 13. Concurrency ISBN

Deadlock. Lecture 4: Synchronization & Communication - Part 2. Necessary conditions. Deadlock handling. Hierarchical resource allocation

Outline of the talk. The egg and the hen Or, Which comes first: the problem or the solution? Challenges (2/6) Challenges (1/6) Recall of basics

Chapter Machine instruction level 2. High-level language statement level 3. Unit level 4. Program level

SIDDHARTH GROUP OF INSTITUTIONS :: PUTTUR Siddharth Nagar, Narayanavanam Road QUESTION BANK (DESCRIPTIVE) UNIT I OPERATING SYSTEMS

Short Term Courses (Including Project Work)

Resource management. Real-Time Systems. Resource management. Resource management

Implementing a High-Integrity Executive using Ravenscar

Java: Just Another Version of Ada an overview of Ada 2005

Programming Languages for Real-Time Systems. LS 12, TU Dortmund

CS A331 Programming Language Concepts

Real-time Support in Operating Systems

Introduction to Lab 2

Part B Questions. Unit I

Real-Time Systems. Lecture #4. Professor Jan Jonsson. Department of Computer Science and Engineering Chalmers University of Technology

Hybrid Verification in SPARK 2014: Combining Formal Methods with Testing

Real-Time Programming with GNAT: Specialised Kernels versus POSIX Threads

Real-Time Systems Hermann Härtig Real-Time Programming Languages (ADA and Esterel as Examples)

CSCE 313: Intro to Computer Systems

CSCE 313 Introduction to Computer Systems. Instructor: Dezhen Song

Exercises and Labs. Part I. Exercises

Building Better and Safer Programs Using SPARK and Ada. William Wong 23 March 2019

Short Notes of CS201

Windows 7 Overview. Windows 7. Objectives. The History of Windows. CS140M Fall Lake 1

CS201 - Introduction to Programming Glossary By

Real-Time Systems and Programming Languages

Lab 2 Programming LEGO Mindstorms NXT. Jakaria Abdullah 19 September 2018

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

Systems I: Programming Abstractions

Time Handling in Programming Language

Sistemas Operacionais I. Valeria Menezes Bastos

Multimedia Systems 2011/2012

1 System & Activities

Sanitizing Sensitive Data: How to get it Right (or at least Less Wrong ) Roderick Chapman, 14th June 2017

A simple example... Introduction to Ada95. Literals. Identifiers

Predictable Interrupt Management and Scheduling in the Composite Component-based System

TDDD07 Real-time Systems Lecture 10: Wrapping up & Real-time operating systems

Sanitizing Sensitive Data: How to get it Right (or at least Less Wrong ) Roderick Chapman, 22nd September 2017

NuttX Realtime Programming

Comp2310 & Comp6310 Systems, Networks and Concurrency

Investigation of System Timing Concerns in Embedded Systems: Tool-based Analysis of AADL Models

Guide for the use of the Ada Ravenscar Profile in high integrity systems

Interfacing Ada to Operating Systems

A Predictable RTOS. Mantis Cheng Department of Computer Science University of Victoria

SCOPE OF THE EVALUATION

Microbee Technology FTM-3SE

Embedded Systems: OS. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

2. Introduction to Software for Embedded Systems

Programming. In Ada JOHN BARNES TT ADDISON-WESLEY

Comp2310 & Comp6310 Concurrent and Distributed Systems

Multitasking / Multithreading system Supports multiple tasks

Combined Scheduling of Time-Triggered and Priority-Based Task Sets in Ravenscar

Issueswith using Ravenscar andthe Ada Distributed SystemsAnnex for High-Integrity Systems

Implementing Priority Inheritance Algorithms in an Ada Runtime System

Comp2310 & Comp6310 Systems, Networks and Concurrency

The Real-time Specification for Java

(MCQZ-CS604 Operating Systems)

Mobile Operating Systems Lesson 01 Operating System

Embedded Systems. 5. Operating Systems. Lothar Thiele. Computer Engineering and Networks Laboratory

Lecture 3: Concurrency & Tasking

Implementing Scheduling Algorithms. Real-Time and Embedded Systems (M) Lecture 9

REAL TIME OPERATING SYSTEM PROGRAMMING-I: VxWorks

Implementation Alternatives. Lecture 2: Implementation Alternatives & Concurrent Programming. Current Implementation Alternatives

Embedded Systems: OS

Guide for the use of the Ada Ravenscar Profile in high integrity systems

The Deadline Floor Protocol and Ada

Real-Time Java. Martin Schöberl

Asynchronous Event Handling and Safety Critical Java

Parallel And Distributed Compilers

Concurrent Programming. Implementation Alternatives. Content. Real-Time Systems, Lecture 2. Historical Implementation Alternatives.

Concurrent Programming

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

Concurrency: Deadlock and Starvation. Chapter 6

Solving priority inversion in assembly machines for discrete semiconductors

MaRTE-OS: Minimal Real-Time Operating System for Embedded Applications

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

Programming Language Vulnerabilities within the ISO/IEC Standardization Community

Inter-process communication (IPC)

Reducing Priority Inversion in Interprocessor Synchronization on a Fixed-Priority Bus

Synchronization. CSCI 5103 Operating Systems. Semaphore Usage. Bounded-Buffer Problem With Semaphores. Monitors Other Approaches

Specification. Implementation

Thinking about Ada... Introduction to Ada. for Beginning or Experienced Programmers. J-P. Rosen Adalog.

CSCE Introduction to Computer Systems Spring 2019

Operating Systems Overview. Chapter 2

An Overview of the BLITZ System

CSE 4/521 Introduction to Operating Systems. Lecture 29 Windows 7 (History, Design Principles, System Components, Programmer Interface) Summer 2018

Transcription:

16.070 Ada and Real-Time Prof. Lars Asplund lars.asplund@mdh.se 1 Mälardalen University, Computer Science

History 2 Software Engineering first conference -69 Strawman -> Steelman Ada (ANSI standard 1983); Ada-83 ISO 1987 Revision 1995, Ada-95, ISO (ANSI, IEEE) First standardized Object Oriented Language Full Real-Time Safety Critical

Concurrency Different activities that can run simultaneously Not necessary in parallel 3

Example Flight Control One task to control the engine One task per rudder to implement a control loop One task for main control 4

Computer model Programs Operating System Computer Hardware C++ Process Assembly Instruction Set Micro code/register Model Electronics 5

Computer model Programs Operating System Computer Hardware Ada / java Threads Instruction Set Micro code/register Model Electronics 6

Thread vs Process Thread Process Communication OS-resources Semaphores, memory Share Pipes, signals Own Share data Yes No 7

Building an Ada System (SE) Procedure Compilation units Package Package Package Subprogram Package Package 8 Subprogram

Subprogram function function_name (params ) return type is declarative part statements return ; end function_name; procedure procedure_name (params ) is declarative part statements end procedure_name; 9

Packages package Package_Name is declarative part [private private_part] end Package_Name; package body Package_Name is declarative part subprogram implementations [ statement_part] end Package_Name; 10

Task specification task task_name is entry Entry_Name_1 (Params); entry Entgry_Name_2 (Params); pragma Priority (4); end task_name; 11

Task type and object specification task type task_type_name is entry Entry_Name_1 (Params); entry Entgry_Name_2 (Params); pragma Priority (4); end task_type_name; Task_Name : Task_Type_Name; Another_Task : Task_Type_Name; 12

Task body task body task_name is declarative_part loop Standard_Code delay Duration_Expr; delay until Time_Expr; task_t.entry_name ( ); select end select; [exception] end task_name; 13

Typical instructions for Real-Time delay Duration_Expr; -- delta time delay Time_Expr; -- absolute time entry calls accept statements select - statements abort Task_Name; requeue Entry_Name; task and protected object handling 14

Synchronization and Communication There are two models Rendez Vous Was introduced in Ada-83 A French expression for meeting your secret lover in the evening, or docking space ships Protected Object Was introduced in Ada-95 Like a monitor (critical section) 15

Rendez Vous Two tasks The callee declares an entry, which can have formal arguments The caller calls the entry 16

The Callee 17 task Buffer is entry Put (C : Integer); entry Get (C : out Integer); pragma Priority (4); end Buffer; task body Buffer is Data : Integer; loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

One Caller task Producer; task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); end Producer; 18

Another Caller 19 task Consumer; with Ada.Text_IO; use Ada.Text_IO; package/procedure. task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer;

Some Action 20 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Buffer is running 21 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Buffer is running / suspends 22 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Consumer is running / suspends 23 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Producer is running / Rendez Vous 24 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Producer/Buffer is running / Rendez Vous 25 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); -- i equals 1 end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Producer is running / Suspends 26 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); -- I is now 2 end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; -- equals 1 loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Buffer is running / Suspends 27 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); -- I is now 2 end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; -- equals 1 loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Consumer/Buffer is running / Rendez Vous 28 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); -- I is now 2 end Producer; task body Consumer is My_Value : Integer; -- gets value 1 loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; -- equals 1 loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Consumer is running / Suspends 29 task body Producer is for I in 1..1_000_000 loop Buffer.Put (I); -- I is now 2 end Producer; task body Consumer is My_Value : Integer; -- gets value 1 loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; task body Buffer is Data : Integer; -- equals 1 loop accept Put (C : Integer) do Data := C; end Put; accept Get (C : out Integer) do C := Data; end Get; end Buffer;

Extend the Buffer task body Buffer is type Index is range 0..100; Data : array (Index range 1..Index last) of Integer; Size : Index := 0; In_P, Out_P : Index := 1; loop select accept Put (C : Integer) do In_P := In_P mod Index last + 1; Size := Size + 1; Data (In_P) := C; end Put; or accept Get (C : out Integer) do Out_P := Out_P mod Index last + 1; Size := Size -1; C := Data (Out_P); end Get; end select; There is a potential ERROR here 30 end Buffer;

Final solution of task Buffer 31 task body Buffer is type Index is range 0..100; Data : array (Index range 1..Index last) of Integer; Size : Index := 0; In_P, Out_P : Index := 1; loop select when size < Index last => accept Put (C : Integer) do In_P := In_P mod Index last + 1; Size := Size + 1; Data (In_P) := C; end Put; or when size > 0 => accept Get (C : out Integer) do Out_P := Out_P mod Index last + 1; Size := Size -1; C := Data (Out_P); end Get; end select; end Buffer;

The select statement (1) 32 select [when logical_expr =>] accept Entry_Name do Statements end Entry_Name; or [when logical_expr =>] accept Entry_Name do Statements end Entry_Name; or delay Duration_Expr; Statements or delay Duration_Expr; Statements or delay until Time_Expr; Statements [or terminate;] end select;

The select statement (2) select [when logical_expr =>] accept Entry_Name do Statements end Entry_Name; or [when logical_expr =>] accept Entry_Name do Statements end Entry_Name; else Statements end select; 33

The select statement (3) select Task.Entry_Name; else Statements end select; select Task.Entry_Name; or delay Duration_Expr; Statements end select; 34

The select statement (4) select Task.Entry_Name; then abort Statements end select; select delay [until] Dur/Time; then abort Statements end select; 35

Protected Objects protected Buffer is entry Put (C : Integer); entry Get (C : out Integer); pragma Priority (5); private Data : Buffer; Size : Index; end Buffer; protected type Buffer_T is entry Put (C : Integer); entry Get (C : out Integer); pragma Priority (5); private Data : Buffer; Size : Index; end Buffer_T; 36 Buffer : Buffer_T; Another_Buffer : Buffer_T;

The Protected Object (2) protected body Buffer is entry Put (C : Integer) when size < 100 is In_P := In_P mod Index last + 1; Data (In_P) := C; end Put; entry Get (C : out Integer) when size > 0 is Out_P := Out_P mod Index last + 1; C := Data (Out_P); end Get; end Buffer; 37

Same behaviour but no context switch 38 task Producer is for I in 1..1_000_000 loop Buffer.Put (I); end Producer; task body Consumer is My_Value : Integer; loop Buffer.Get (My_Value); Put_Line (Integer Image(My_Value)); end Consumer; protected body Buffer is entry Put (C : Integer) when size < 100 is In_P := In_P mod Index last + 1; Data (In_P) := C; end Put; entry Get (C : out Integer) when size > 0 is Out_P := Out_P mod Index last + 1; C := Data (Out_P); end Get; end Buffer;

Workstation Systems Using an operating system (Windows NT, VxWorks,...) Ada tasking can be on top or using Threads in the OS. Restrictions to the use of memory, instructions and hardware Virtual Memory Ada program RTK Oper. System HardWare Complete Program Real Memory 39

Embedded Systems In an embedded system (no OS) Ada tasking (RTK) is linked with the code No restrictions in access to underlying hardware There is an environment 40 Real Memory Ada program RTK HardWare Complete Program Default IO-base = $FF80 0000 Default Offset = $4000 Port 1= Offset 0; address $FF80 4000 Port 2=Offset 2; address $FF80 4002

Embedded Systems High end system: A Pentium with 128Mbyte of RAM, Windows NT Medium sized system: VME-board with dram, VxWorks, VRTX or Lynx Small sized systems: Bare but RT-OS may work, but only one process (VxWorks) Eight bit microcontrollers: No Ada - yet 41

Core and Annexes A Predefined Language Environment B Interface to Other Languages C Systems Programming D Real-Time Systems E Distributed Systems F Information Systems G Numerics H Safety and Security B E A Core D C 42

Systems Programming (C) The annex starts with chapter 13 Representation specifications Package System Unchecked conversions B Storage Management Annex C Interrupt support Task Identification and Attributes E A Core D C 13 43

Real-Time Systems (D) Priorities Scheduling Policies Entry Queuing Policies Dynamic Priorities Monotonic Time Synchronous Task Control Asynchronous Task Control... B E A Core D C 13 44

Systems Programming Specification of Representation of Data Layout Address Size Address manipulation Very low level programming (ports, machine code) Interrupt Handling 45

How to reach the bits A register in an IO-device has several bits (bit-fields). Low Level C or assembler use and/or operations Ada use records and rep-specs 46

Representation Attributes X Address=XXXXA X Alignment =2 X Size=8*8 XXXXF XXXXE XXXXD XXXXC XXXXB XXXXA XXXX9 XXXX8 XXXX7 XXXX6 XXXX5 XXXX4 XXXX3 XXXX2 XXXX1 XXXX0 Automatic Placement 47

τ Deadline monotonic Like Rate monotonic, but deadline (D) Set of tasks T Period C computational time D deadline B Blocking J Jitter R Response P Priority Low D => higher P 48

τ Basic concepts (1) R C D T 49

τ Basic concepts (2) R B I I C T D I Interference (interrupted by high priority tasks) B Blocking (low priority tasks) 50

51 Basic concepts (3) T B D R I I I Interference (interrupted by high priority tasks) B Blocking (low priority tasks) C J I hp J J J I I I I C T J R B C R + + + = ) ( τ

τ Priority Ceiling and Inheritance Priority of a Task T Priority of a PO used by T Inheritance Task T inherits the ceiling of PO when entering the PO protected type PO is entry ; pragma Priority (5); end PO; task type T is entry ; pragma Prioriy (4); end T; 52

Immediate Inheritance As soon as you enter a PO you recieve the PO-priority cf when PO requested => all blocking before start => no priority inversion T3 uses PO4; T2 uses PO2 T1 uses PO4 and PO2 T1 is running takes PO4; is preempted by T2 T2 is running takes PO2; is preempted by T3 T3 needs PO4; T1 starts to run; needs PO2 before releasing PO4; run T2 53

Ada for Safety Critical Applications Today's safety critical systems use cyclic executives. Research take for granted that a system consists of processes (scheduling, priorities), and that there is communications between these. Process based safety critical systems - formal methods (Raven, Enea ) 54

Ada 83 Ada 83 Tasking Rendez-vous Dynamic Hierarchy Termination... Complex Run-Time No Formal Proofs For High Integrity Systems Subsets: SPARK (No tasking) Boeing... 55

Ada 95 Ada 83 Ada 95 Subsets: GNORT (Gnat NO Run-Time) SPARK-95 Tasking Rendez-vous Dynamic Hierarchy Termination... Protected objects ATC Requeue Delay until New interrupts Task discriminants... Ravenscar Tasking Protected objects Delay until New interrupts Task discriminants 56

Ravenscar The Ravenscar profile has been proposed as a possible standard runtime support system suitable for safety critical real-time Ada 95 applications. The subset provides enough functionality for targeted systems. 57

Ravenscar - tasking Library level No dynamic creation No unchecked deallocation Non-terminating No entries No user defined attributes Keep task discriminants No ATC 58

Ravenscar - Protected Objects Single Entry Barrier a single Boolean Only one task in the entry queue 59

Ravenscar - Communication No Rendez vous No requeue No select statement Interrupts are mapped only to PO procedures 60

Ravenscar - Real Time delay until for delays No Calendar Clock from Real-Time package No dynamic priorities Immediate Ceiling Priority 61