Professional Documents
Culture Documents
Implementation of Real-Time
Applications
4.1. Introduction
4.2. Implementation of Simple Controllers under Synchronous Approach
Assumption
4.3. Notions and Concepts
4.4. Real-Time Operation Systems
4.5. Concurrency in Standard Java
4.6. Realtime Java
M = M Bt + Ft
Possibilities:
multiprogramming = multitasking processes or tasks share a single
processor; the processes multiplex their execution on a single processor
multiprocessing multiprocessor with shared memory; the processes
multiplex their execution on a multiprocessor system with tightly coupled
processors
distributed processing multiple processor each with local memory; the
processes multiplex their execution on several central processor unit system
connected through a network
Tiberiu Leia: Real-Time Systems Implementation of Real-Time Applications. 15
Approaches of RTAs Implementation: <<create>>
Created
dynamic)
Priority based scheduling Ready
dispatch
Running
Time slicing - Each task gets the processor for a defined period of time.
This kind of operating systems is applied to: soft, slow (systems) RTAs with
few tasks.
The solution is inflexible, inefficient, and not feasible for complex systems.
Tiberiu Leia: Real-Time Systems Implementation of Real-Time Applications. 16
Why are the threads blocked?
o wait for time (timing)
o wait for external events (ex.: I/O operations, event synchronizations)
o wait for internal events (ex.: semaphore acquire/release, lock/unlock; mutual
exclusions; signal, wait-notify)
c) Cyclic executives
Each task runs in sequence on the processor to completion or periodically
Benefits
o simplistic: no RTOS, no mutual exclusion, etc.
o deterministic: no independent running threads
Problems
o poor responsiveness, especially with many tasks
o failure prone
o rigid and not easily modified
Timers - the ability to set and read high resolution internal timers
Priority scheduling - A priority-based preemptive scheduling - support for
scheduling of real-time processes;
user dynamic resources management
Shared memory -The ability to map common physical space into independent
process-specific virtual spaces
Real-time files - The ability to create and access files with deterministic
performance
Semaphores - Efficient synchronization primitives (acquire P & release - V)
Interprocess communication - Synchronous and asynchronous message-
passing capabilities with facilities for flow and resource control
Asynchronous event notification - A mechanism which provides queuing
capabilities, deterministic delivery, and minimal data passing
Process memory locking - The ability to guarantee memory-residence for
sections of a process virtual address space
Tiberiu Leia: Real-Time Systems Implementation of Real-Time Applications. 26
Asynchronous I/O - The ability to overlap applications processing and I/O
operations initiated by the application.
guaranteed interrupt response
mechanisms for inter-process cooperation
high speed data acquisition
I/O support I/O Synchronized - The ability to establish assurance of I/O
completion time at different logical levels of completion.
Using priority-based scheduling, processes that are Ready to execute are stored
in ReadyQueue according to their priority.
In the real-time system is easier to define the deadline of the processes and then
to decide which process should be executed first. Earliest Deadline First
(EDF) scheduling
nive l nucleu
Interfaa apelurilor de sistem
Planificator cu prioriti
fixe i preemptive Tampoane cache
Gestiunea memoriei
Drive ri periferici
Control hardware
nive l nucleu
nive l hardware
Hardware
The malloc (memory allocation) and free services (system calls) known in C-
language work from a heap.
Tasks can temporarily borrow some memory from the operating systems heap
by calling "malloc", and specifying the size of memory buffer needed.
When this task (or another task) is finishes the usage of this memory buffer it
returns the buffer to the operating system by calling "free."
The operating system will then return the buffer to the heap, where its memory
might be used again, perhaps as part of a larger buffer. Often the buffer may be
broken into several smaller buffers in the future.
fork() Secventa 1
#include <stdio.h>
main () { Heap end
puts ( Inceputul testului
fork);
fork() ; Secventa 2 Secventa 2
puts (Sfarsitul testului Heap
fork);
}
Context switch = load & store Heap start
proces PID 0
stiv
proces PID 1
memorie
comun
proces PID n
Process 1 Stack
(Running) Process 1 pointer
Stack
Secventa 2 Secventa 3
Data area
Heap start
fork() {0 , -1} child , parent Process
# include <stdio.h> variables
main () { Program code
int pid_copil; Program counter
printf (Proces parinte - secventa l\n ); Code for
if ((pid_copil=fork () ) ==0) main process
instructions
printf (Proces copil - secventa 3 \n);
else printf (Proces parinte - secventa 2 \ n);
}
Fig. 2. Memory content of a process.
Tiberiu Leia: Real-Time Systems Implementation of Real-Time Applications. 44
Intertask communication and synchronization
RTOSs offer mechanisms for communication and synchronization between
tasks.
This is necessary in a preemptive environment of many tasks, because without
them the tasks might well communicate corrupted information or otherwise
interfere with each other.
Event signaling
Process1 Process2
............................ ... ...........................
............................... wait(event);
Events signal(event); ............................
synchronous signaling .................................
asynchronous process interrupt
When a process is inserted in TimeQueue the kernel sets up the timer to give an
interrupt at the wake-up time of the first process in TimeQueue.
When the clock interrupt occurs, a context switch to the first process is
performed and the timing chip is set up to give an interrupt at the wake-up time
of the new first process in TimeQueue.
Foreground-Background Scheduler
Foreground tasks (e.g. controllers) execute in interrupt handlers.
The background task runs as the main program loop.
It is a common way to achieve simple concurrency on low-end implementation
platforms that do not support any real-time kernels.