Chapter3 Embedded OS
Chapter3 Embedded OS
Operating Systems
Tien Pham Van, Dr. rer. nat.
Hanoi University of Science and Technology
Compiled with reference to other presentations
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Outlines
• Remarkable features
• Designing approaches
• Real-time systems
• Scheduling algorithms
• Resource accessing
• Embedded Linux
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Reminded features
• Part of larger system
– not a “computer with keyboard, display, etc.”
• HW & SW application-specific – not G.P.
– application is known a-priori
– definition and development concurrent
• Interact (sense, manipulate, communicate)
with the external world
• Never terminate (ideally)
• Operation is time constrained: latency,
throughput
• Other constraints: power, size, weight, heat,
reliability
• Increasingly high-performance (DSP) &
networked
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded System as a Computer
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Operating System?
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
General vs. Embedded
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
When and what needed?
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Operating System
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Task states
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Multitasking
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Illusion of parallelism
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Programs, threads and Tasks
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
• Task- Process- Threads - YouTube
https://www.youtube.com/watch?v=o7zPffv8T2s
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Different Architectures
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Monolithic vs. Micro-kernel
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Characteristics
Real-time operation
• In many embedded system, the correctness of a computation
depends, in part, on the time at which it is delivered. Often, real-
time constraints are dictated by external I/O and control stability
requirements.
Reactive operation
• Embedded software may execute in response to external events. If
these events do not occur periodically or at predictable intervals,
the embedded software may need to take into account worst-case
conditions and set priorities for execution of routines.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Characteristics
Configurability
• Because of the large variety of embedded systems, there is a large
variation in the requirements, both qualitative and quantitative,
for embedded OS functionality. Thus, an embedded OS intended
for use on a variety of embedded systems must lend itself to
flexible configurations so that only the functionality needed for a
specific application and hardware suite is provided.
• For example, the linking and loading functions can be used to
select only the necessary OS modules to load. Conditional
compilation can be used.
• However, verification of the end product can be a problem for
designs with a large number of derived tailored operating systems.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Characteristics
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Characteristics
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Characteristics
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
• Embedded Operating System and
Requirement Specifications of Embedded
Systems 16072020 - YouTube
https://www.youtube.com/watch?v=4szPd-XwQ58
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Approaches for OS
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
From existing OS
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Purpose-built OS
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded OSs in IoT era
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Real-Time Applications Spectrum
Windows NT
General-Purpose
Operating
Soft System
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded (Commercial) Kernels
Stripped down and optimized versions of timesharing OS
• Intended to be fast
– a fast context switch
– external interrupts recognized quickly
– the ability to lock code and data in memory
– special sequential files that can accumulate data at a fast rate
• To deal with timing requirements
– a real-time clock with special alarms and timeouts
– bounded execution time for most primitives
– real-time queuing disciplines such as earliest deadline first,
– primitives to delay/suspend/resume execution
– priority-driven best-effort scheduling or a table-driven mechanism.
• Communication and synchronization via mailboxes, events,
signals, and semaphores.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Real-Time Extensions to
General Purpose Operating Systems
E.g., extending LINUX to RT-LINUX, NT to RT-NT
• Advantage:
– based on a set of familiar interfaces (standards) that speed
development and facilitate portability.
• Disadvantages
– Too many basic and inappropriate underlying assumptions still
exist.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Real-time execution
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Real-time tasks
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Scheduling algorithms (1)
• Clock Driven
– Table-driven
– Cyclic
• Event Driven
– Rate Monotonic Analysis (RMA)
– Earliest Deadline First (EDF)
• Hybrid
– Round-robin
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Usual real-time schedulers
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fixed priority scheduling (1)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fixed priority scheduling (2)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fixed priority scheduling (3)
•Rate Monotonic assignment and non preemptive
scheduling:
Assuming VxWorks priority levels (high=0 ; low=255)
T1 : C1=6, P1=10, Prio1=0 peemptive va nonpeemptive anh
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fixed priority scheduling (4)
• Feasibility/Schedulability tests:
1. Run simulations on hyperperiod = [0, LCM (Pi)]. Sufficient and
necessary (exact result). Any priority assignment and
preemptive/non preemptive scheduling.
Ci 1
U= Σn ≤ n(2n − 1)
i =1 Pi
Rate Monotonic assignment and preemptive scheduling. Sufficient
but not necessary. Does not compute an exact result.
or:
hp(i) is the set of tasks which have a higher priority than task i. x
returns the smallest integer not smaller than x.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fixed priority scheduling (6)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fixed priority scheduling (7)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Fixed priority scheduling (8)
•Aperiodic tasks server: periodic task devoted to the scheduling of
aperiodic tasks.
T1 : C1=4 ; P1=20 (grey) Black=idle
T2 : C2=12 ; P2=30 (white)
S : CS=4 ; PS=10;
A is released at t=4 ; CA=3
B is released at t=9 ; CB=4
A B
AAAB BBB
4 10 12 20 23 27 30
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Earliest Deadline First (2)
2. Select the task: at any time, run the ready task which
has the shortest dynamic deadline.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Earliest Deadline First (3)
uu tien do dang
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Earliest Deadline First (4)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Earliest Deadline First (5)
Ci
U= Σn ≤1
Pi
i=1
FP/RM EDF
Applications critical, static dynamic, less critical
RTOS easy more difficult
implementation
Tasks Periodic only Aperiodic and periodic
Efficiency upto 69 % upto 100 %
Predictability high less than FP/RM if U > 1
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Multiprocessor/distributed (2)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Task dependencies
• Usual dependencies:
1. Shared resources.
2. Precedences between tasks.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Shared resource support (1)
•In real-time scheduling theory, a shared resource is
modeled by a semaphore:
Task i Task j
P(sem) P(sem)
access_shared_resou access_shared_resou
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Shared resource support (1)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Shared resource support (2)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Verification of a real-time system
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Scheduling analysis tools (1)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Scheduling analysis tools (3)
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Case study: Embedded Linux
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Linux OS architecture
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Embedded Linux
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
C library
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
C library
• Embedded systems need small sizes of Glibc
variants
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Boot loader
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Real Time Linux approaches
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Modifying Linux kernel
• Advantages
– Most problems, such as interrupt handling, already
solved
– Less initial labor
• Disadvantages
– No guaranteed performance
– RT tasks don’t always have precedence over non-RT tasks.
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
67
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Running Linux as a process of a second RT kernel
•Advantages
Can make hard real time guarantees
Easy to implement a new scheduler
•Disadvantages
Initial port difficult, must know a lot about underlying hardware
Running a small real-time executive is not a substitute for a full-fledged RTOS
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
68
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Source code implementation
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Further investigation
Embedded Networking Research Group School of Elec. and Telecom - Hanoi University of Science and Technology
Email: [email protected] C9-411, Dai Co Viet str. 1, HBT, Hanoi Tel: +84-243-8693596
Future developments