0% found this document useful (0 votes)
97 views6 pages

Real Time Operating Systems

This document discusses real-time embedded systems and concepts related to time-critical applications. It outlines that real-time systems must guarantee both logical and temporal correctness of output by meeting timing deadlines. There are hard and soft real-time systems, with hard systems requiring all deadlines to be met. Common real-time applications include process control, factories, medical devices, and automotive/avionics systems. Real-time does not necessarily mean fast computing, but rather meeting timing constraints through predictability and analyzability. The document also covers concepts like preemptive multitasking, foreground/background systems, concurrency, and real-time system terminology.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views6 pages

Real Time Operating Systems

This document discusses real-time embedded systems and concepts related to time-critical applications. It outlines that real-time systems must guarantee both logical and temporal correctness of output by meeting timing deadlines. There are hard and soft real-time systems, with hard systems requiring all deadlines to be met. Common real-time applications include process control, factories, medical devices, and automotive/avionics systems. Real-time does not necessarily mean fast computing, but rather meeting timing constraints through predictability and analyzability. The document also covers concepts like preemptive multitasking, foreground/background systems, concurrency, and real-time system terminology.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

05-Dec-22

EE 128
Lecture 17
Outline Embedded Systems Are Often Time-Critical
Electrical and Computer Engineering

Sensing and Actuation for Embedded Systems • Real-Time Systems Concepts • Real-Time: timing correctness is part of the system correctness
• Preemptive vs. non-preemptive – Both logical & temporal correctness of output should be guaranteed
• OS and Task Management • Hard real-time systems
– Deadlines must be met
– If any hard deadline is ever missed, then the system is incorrect

Real-Time Operating Systems – E.g., Automotive safety features, nuclear power plant

• Soft real-time systems


By Hyoseung Kim with additions by Roman Chomko – Missing a deadline is not catastrophic
– Deadline may occasionally be missed
– E.g., Video streaming

2 3

Example Real-Time Applications Real-Time Does Not Mean “Fast” Common Misconceptions About Real-Time
• Process Control (Chemical Plants)
• Factories (Automotive Assembly Plants)
• Supervisory Control and Data Acquisition (Utilities)
• Real-time? Real Fast? • Real-time computing is equivalent to fast computing
• Medical Devices and Healthcare (Medical Robots and Equipment) – Fast = doing something quickly
• Computer Peripherals (Laser printers) – Real-time = meeting timing constraints (deadlines) • Advances in supercomputing hardware will take care of real-time
• Automotive (Engine controls) • Real-time system can be slow requirements
• Telecommunications (Cellphone Infrastructure) • Fast system can be non-real-time
• Aerospace (avionics) • Real-time programming = assembly or low-level language
• Of course, most real-time systems are designed to be fast and to programming
• Internet and Multimedia (Videoconferencing, IPTV, Skype)
• Consumer Electronics (Mobile phones, TVs, set=top boxes)
operate at high speeds
• Military systems (missile guidance systems, radar systems) • “Real time” is performance tweaking
• Space systems (planetary rovers, rockets, satellites) Real-time != Real Fast
Predictability & Analyzability

4 5 6
05-Dec-22

Example of Real-Time Control System Foreground/Background Systems Foreground/Background Systems


• Digital control system • Small, simple systems without an OS
– Periodically perform the following tasks: – An application consists of an infinite loop that calls functions to perform
• Senses the system status various tasks in the “Background” Foreground processes refer to applications you are running
• Actuates the system according to its current status – Interrupt Service Routines (ISRs) handle asynchronous events in the that you are currently interacting with, and which applies
– May also have aperiodic tasks (e.g., button presses) “Foreground” equally to graphical user interfaces as it does to the command
– Foreground = interrupt level line.
Real-time systems – Background = task level
Computing Background processes refer to applications that are running
Sensors Actuators
System but not being interacted with by the user.

Physical
environment

7 8 9

Arduino Concurrency & Multi-tasking Terminology


• How do we organize multiple activities in an application? • Task: a sequence of (recurrent) computational events/activities
– Especially if some of them are time sensitive? – Requires resources to execute (e.g., CPU, network, I/Os, …)
• Concurrency: ability to execute more than one tasks
– Does not mean that all tasks run simultaneously • Release time of a task
• Concurrent execution != parallel execution – The time instant the task becomes ready to execute
Initialization – How? switching among multiple tasks quickly and frequently
• Absolute deadline of a task
• Can we put everything in ISRs? – The time instant by which the task must complete execution
– Foreground only • Relative deadline of a task
– Response time dominated by the longest ISR, even if low priority Deadline: Imposed by the environment
– “Absolute deadline − Release time”
Background • Common practice & specified by the designer
• Response time of a task
(tasks) – Make ISR very short, perform only timing-sensitive I/O-related activities
– Implement concurrent “tasks” in background and schedule them!
– “Completion time − Release time”

10 11 12
05-Dec-22

Example How to meet deadlines?


Periodic Task
• Repeats regularly according to a given period
Task release Task deadline
– Period: fixed time interval between releases of a task • Tasks need resources to execute (e.g., CPU, network, I/Os, …)
• Must finish before start of next cycle – Ways of managing system resources affect the timing of tasks
• Has a hard deadline • Scheduler: resource allocator
– When multiple tasks are ready, it decides which task to use the resource
• e.g., if a periodic task has ...
• Task is released at time 3 • e.g., CPU scheduling, disk scheduling, network scheduling, ...
– Released at time 2
• Its absolute deadline is at time 10 may execute like this: – If the scheduler picks the wrong task, deadlines may be missed
– Period = 5
• Its relative deadline is 7 – Execution time = 2
• Real-time schedulers need to deal with the worst-case behavior
• Its response time is 6 – (Relative) Deadline = 5
Deadline

Task release
13 14 15

Preemptive vs. Non-preemptive What is an Operating System? Computer System Components

• Non-preemptive scheduling • The software layer that lies between a computer user and the • Hardware
– Task runs to completion, even if other tasks want service computer hardware – Provides basic computing resources: CPU, memory, I/O (disk, mouse,
• e.g., put everything in a while loop in background/foreground systems – Hides details of programming low-level devices keyboard, display), network interfaces
– What happens if one task takes very long time to complete? • Provides resource abstraction • Operating System
– Manages system resource sharing – Controls and coordinates the use of the hardware among various
• Preemptive scheduling application programs for different users
– Separates users and processes from one another
– Task is suspended immediately when some other task wants service, then
restarted at a later time • Application Programs
– Better to provide shorter latency – Define the ways in which the system resources are used to solve the
computing problems of users
– e.g., task scheduling in most operating systems
• e.g. database systems, 3D games, business applications
– Needs support from operating systems
• Task management: task state, scheduler, context switching • Users
– People, machines, and other computers

16 17 18
05-Dec-22

Abstract View of System Components Operating System Concepts Task Management

• Task Management • Task is a program in execution within its own address space
• Memory Management – Also called process or thread
– A task includes the current activity of the program
• File Management
• PC, Stack pointer, values in register set
• I/O Management – Each task has its own text, data, heap and stack section
• Networking – Tasks need certain resources, including CPU time, memory, files, and I/O
• User Security devices

• … • OS is responsible for the following activities for task


management
– Task creation and deletion
– Task suspension and resumption
– Others: synchronization, inter-task communication

19 20 21

Task State Task State Diagram Task Control Block


• Task control block (TCB)
• As a task executes, it changes state • A task can be in any one of many different states – Also called a Process Control Block (PCB)
– New: The task is being created – Information associated with each process stored by the OS
– Ready: The task is waiting to be assigned to a CPU • Task state: new, ready, running, waited, halted, etc.
– Running: The task is executing on the CPU • Program counter
– Waiting: The task is waiting for some event (e.g. I/O, timeout) to occur • CPU registers
– Terminated: The task has completed execution • CPU scheduling information
– e.g., priority and scheduling parameters
• Memory-management information
– e.g., page table, shared memory
• Accounting information
– e.g., PID, user time, constraint
• I/O status information
– e.g., I/O devices allocated, open files, signals

22 23 24
05-Dec-22

Context Switch Switch From Task 0 to Task 1


Task Control Block
Task 0 OS Task 1
• TCB of FreeRTOS • The replacement of the currently-running task with a new one
– Needed for “preemptive task scheduling”
typedef struct tskTaskControlBlock
{
volatile StackType_t *pxTopOfStack; // Stack Pointer
• Simply saves the old context and “restores” the new one
ListItem_t xStateListItem; /*< state list (Ready, Blocked, Suspended ). */ 1. Current task is interrupted
ListItem_t xEventListItem;/*< Used to reference a task from an event list. */
UBaseType_t uxPriority;/*< The priority of the task. 0 is the lowest priority. */ 2. CPU’s registers for that task are saved in its TCB
StackType_t *pxStack;/*< Points to the start of the stack. */
char pcTaskName[ configMAX_TASK_NAME_LEN ]; 3. Task is placed on the “ready” list
StackType_t *pxEndOfStack; /*< Points to the highest valid address for the stack. */ 4. Memory usage, priority level, etc. is updated in the TCB (if needed)
.... 5. New task’s registers and status are loaded into the CPU
} tskTCB; 6. This generally includes changing the stack pointer, the PC and the SR
(status register)
7. New task starts to run

25 26 27

Task Scheduler Round-Robin Scheduling Priority-based Scheduling


• What is the scheduler? • Each task is executed for a small amount of time called a time-
– Part of the OS that decides which task (process) to run next slice (or time quantum) • Priority-based scheduling assigns a priority to each task and
– Uses a scheduling algorithm that enforces some kind of policy that is • When the time slice expires, the next task is executed in a those with higher priorities are run first
designed to meet some criteria round-robin order – Priorities are generally represented by numbers, e.g., 0..7, 0..4095
– No general rule about whether zero represents high or low priority
• Criteria may vary • Each time slice is often several timer ticks
– We'll assume that higher numbers represent higher priorities
– CPU utilization - keep the CPU as busy as possible
– Throughput - maximize the number of tasks completed per time unit Tasks Execution time Time quantum = 10 msec Tasks Execution time Priority
– Turnaround time - minimize a task’s latency (run time), i.e., time between P1 40 msec
P1 40 msec 2
task submission and termination P2 30 msec
P1 P2 P3 P4 P1 P2 P3 P4 P1 P2 P4 P1 P4
P2 30 msec 3 P3 P2 P1 P4
– Response time - minimize the wait time for interactive tasks P3 20 msec
P3 20 msec 4
– Real-time - must meet specific deadlines to prevent “bad things” from P4 40 msec
P4 40 msec 1
happening

28 29 30
05-Dec-22

What’s Important in Real-Time Classification of Scheduling Algorithms Scheduling Algorithms (Fixed-Priority)

• Metrics for real-time systems differ from that for general- • Scheduler: resource allocator that affects the timing of tasks • Fixed-priority based
purpose systems – Some tasks have more importance (higher priority) than others
All scheduling algorithms – Once a task’s priority is assigned, it cannot change during run-time
General-purpose systems Real-time systems
Capacity High throughput Schedulability • Rate Monotonic (RM)
Responsiveness Fast average response Ensured worst-case response – Shorter the period, the higher the priority of the task
Overload Fairness Stability Static scheduling Dynamic scheduling – Assigns fixed priorities in reverse order of period length
(or offline, or clock-driven) (or online, or priority-driven) – Tasks requiring frequent attention have higher priority and get scheduled
– Schedulability is the ability to meet task deadlines earlier
– Worse-case latency is the maximum response time to events in the worst-
case scenario • Deadline Monotonic (DM)
Fixed-priority Dynamic-priority – Similar to RM (if period = deadline, RM = DM)
– Stability in overload means the system meets critical deadlines when not
scheduling scheduling – Shorter the deadline, the higher the priority of the task
all deadlines can be met

31 32 33

Scheduling Algorithms (Dynamic-Priority) Summary of Lecture

• Dynamic-priority based • Real-Time Systems


– Some tasks have more importance (higher priority) than others – Real-time goals are:
– Task’s priority may change at runtime • Predictable response,
• guaranteed deadlines, and
• Earliest Deadline First (EDF) • stability in overload
– Ready task with the earliest future deadline gets scheduled first – Any scheduling approach may be used, but all real-time systems should be
analyzed for timing
• Least Slack Time (LST) • OS Task Management
– Ready task with the smallest amount of free/slack time within its period – Supports preemptive task scheduling
gets scheduled first • Task control block
• Context switch
– Priority-based scheduler

34 35

You might also like