Lect 6
Lect 6
RTOS services
Timers
8.05.2025
rys/CyRobekow
Scope of presentation
1 Last week
2 RTOS services
3 Timers
rys/CyRobekow
Memory management
Virtual memory
memory management technique that provides an idealized
abstraction of the storage resources that are actually available on a
given machine.
Monolithic vs Microkernel
Scheduling
Priority based,
FCFS,
SRTF,
Round-Robin,
rys/CyRobekow
Architecture
Architecture
It ia a high level structure of a software system. Such structure
comprises software elements, relations among them and properties
of both elements and relations.
rys/CyRobekow
Architecture
rys/CyRobekow
QNX
QNX
Rigorous RT system, created in the beginning of 80’s of century by
the Quantum Software System company for PC.
multiple tasks,
added support for networking after some time,
conformity with POSIX standard,
rapid development,
expansion to other architectures in 90’s,
microkernel (scheduling, IPC, interrupts, timers),
device drivers,
fast context switching,
rys/CyRobekow
scheduling based on priorities with preemptive feature.
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures
Xenomai
Xenomai
Hard RT cooperating with Linux kernel providing RT support to
user space applications.
Xenomai – Cobalt
”It is dealing with all time-critical activities, such as handling
interrupts, and scheduling real-time threads. The Cobalt core has
higher priority over the native kernel activities.”
rys/CyRobekow
https://gitlab.denx.de/Xenomai/xenomai/wikis/Start_Here
Xenomai – Mercury
”(...)relying on the real-time capabilities of the native Linux
kernel.(...) Often, applications will require the PREEMPT-RT
extension to be enabled in the target kernel, for delivering real-time
services”
rys/CyRobekow
https://gitlab.denx.de/Xenomai/xenomai/wikis/Start_Here
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures
FreeRTOS
FreeRTOS
RTOS kernel for embedded devices, ported to 35 microcontroller
platforms.
Informations
rys/CyRobekow
Figure 3: https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures
NuttX
NuttX
RTOS for microcontroller platforms (from 8 to 32 bits).
standards compliant,
modular design,
fully preemptible,
naturally scalable,
highly configurable,
realtime, deterministic, with support for priority inheritance,
optional tasks with address environments (Processes).
loadable kernel modules; lightweight, embedded shared
libraries,
rys/CyRobekow
FIFO and RR scheduling available.
http://nuttx.org/
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Last week Kernel and User Space
RTOS services Monolithic vs Microkernel
Timers RTOS Architectures
ChibiOS/RT
ChibiOS/RT
compact and fast RTOS.
preemptive multithreading,
128 priority levels,
round-robin scheduling for threads at the same priority level,
synchronous and asynchronous I/O with timeout capability,
thread-safe memory heap and memory pool allocators,
Hardware Abstraction Layer with support for ADC, CAN, GPT
(general-purpose timer), EXT, I²C, ICU, MAC, MMC/SD,
PAL, PWM, RTC, SDC, Serial, SPI, and USB drivers,
support for the LwIP and uIP TCP/IP stacks,
rys/CyRobekow
support for the FatFs file system library.
http://www.chibios.org/dokuwiki/doku.php
dr inż. Mateusz Cholewiński Real-time Operating Systems Lecture 6
Threads – Xenomai
Pipe
Last week Named Pipe
RTOS services Shared memory
Timers Signals
Message Queues
Serialization
1 RT TASK r e a d e r , w r i t e r ;
2
3 r t t a s k s p a w n (& r e a d e r , ” r e a d e r ” , 0 , 0 , T JOINABLE , &
r e a d e r f u n c , NULL) ;
4 r t t a s k s p a w n (& w r i t e r , ” w r i t e r ” , 0 , 0 , T JOINABLE , &
w r i t e r f u n c , NULL) ;
5
6 r t t a s k j o i n (& r e a d e r ) ;
7 r t t a s k j o i n (& w r i t e r ) ;
rys/CyRobekow
Mutex – Xenomai
Mutex
A mutex is a MUTual EXclusion object, and is useful for protecting
shared data structures from concurrent modifications, and
implementing critical sections and monitors.
A mutex has two possible states: unlocked (not owned by any
task), and locked (owned by one task). A mutex can never be
owned by two different tasks simultaneously. A task attempting to
lock a mutex that is already locked by another task is blocked until
the latter unlocks the mutex first.
rys/CyRobekow
Mutex – Xenomai
1
2 i n t r t m u t e x c r e a t e ( RT MUTEX * mutex ,
3 c o n s t c h a r * name
4
5 int rt mutex acquire ( RT MUTEX * mutex ,
6 RTIME timeout )
7
8 int rt mutex release ( RT MUTEX * mutex )
rys/CyRobekow
Semaphore – Xenomai
Semaphore
A counting semaphore is a synchronization object for controlling
the concurrency level allowed in accessing a resource from multiple
real-time tasks, based on the value of a count variable accessed
atomically. The semaphore is used through the P (”Proberen”,
from the Dutch ”test and decrement”) and V (”Verhogen”,
increment) operations. The P operation decrements the semaphore
count by one if non-zero, or waits until a V operation is issued by
another task. Conversely, the V operation releases a resource by
incrementing the count by one, unblocking the heading task
waiting on the P operation if any. Waiting on a semaphore may
cause a priority inversion. rys/CyRobekow
Semaphore – Xenomai
1 i n t r t s e m c r e a t e ( RT SEM * sem ,
2 c o n s t c h a r * name ,
3 unsigned long icount ,
4 int mode )
5
6 i n t r t s e m p ( RT SEM * sem ,
7 RTIME timeout )
8
9 int rt sem v ( RT SEM * sem )
rys/CyRobekow
Pipe
Figure :)
rys/CyRobekow
Pipe – Xenomai
rys/CyRobekow
ready in filesystem,
needs to be opened with RDONLY or WRONLY,
request for opening pipe not already opened in complementary
mode suspends and waits for other opening in second mode.
Figure :)
rys/CyRobekow
rys/CyRobekow
Shared memory
rys/CyRobekow
1 RT HEAP heap ;
2 char * heap buffer ;
3 ...
4 r t h e a p c r e a t e (&heap , ” heap ” , 1 0 2 4 , H SHARED) ;
5 r t h e a p a l l o c (&heap , 0 , TM NONBLOCK, ( v o i d * * )&
heap buffer ) ;
6 ...
7 memcpy ( h e a p b u f f e r , b u f f e r , BUFF LEN ) ;
8 ...
9 r t h e a p d e l e t e (& heap ) ; rys/CyRobekow
Signals
rys/CyRobekow
asynchronous,
buffered,
limitations.
rys/CyRobekow
Message Queues
rys/CyRobekow
Serialization
Use cases
messaging,
data storage,
calling a remote procedures (SOAP),
objects distribution, CORBA, COM,
detecting changes in time0varying data.
rys/CyRobekow
rys/CyRobekow
Timers – POSIX
rys/CyRobekow
Timers – POSIX
rys/CyRobekow
Timers – POSIX
SIGALARM
POSIX provided real-time programmable timer for each process. It
is called an alarm, is programmed using seconds and when
triggering sends signal SIGALARM.
sleep
method for suspending the process for given number of seconds.
Process during this stage is in standby state; normally it is used for
waiting for resources, blocks, IO operation.
Sleep can end faster that the set number of seconds and it is
possible when process receives signal. In such case sleep returns
number of not used seconds. rys/CyRobekow
Timers – POSIX
Timers
POSIX provides at least 3 timers, which generate signals when
”fired”:
ITIMER REAL,
ITIMER VIRTUAL,
ITIMER PROF,
1 #i n c l u d e <s y s / t i m e . h>
2
3 i n t g e t t i m e r ( i n t which , struct itimerval * value ) ;
4 i n t s e t i t i m e r ( i n t which , c o n s t s t r u c t i t i m e r v a l *
r e s t r i c t value , s t r u c t i t i m e r v a l * r e s t r i c t ovalue ) ;
rys/CyRobekow
Timers – Xenomai
Timers
1 #i n c l u d e < n a t i v e / t a s k . h>
2 #i n c l u d e < n a t i v e / t i m e r . h>
3 #i n c l u d e <r t d k . h>
4
5 c o n s t l o n g l o n g SLEEP TIME = 1 0 0 0 0 0 0 0 0 0 ; / * 1 000 000
000 n s = 1 s * /
6
7 RT TASK t a s k 1 ;
8 RTIME t i m e 1 ;
9 r t t a s k s e t p e r i o d i c (NULL , TM NOW, SLEEP TIME ) ;
10 time1 = r t t i m e r r e a d () ;
11 r t t a s k w a i t p e r i o d (NULL) ;
12 rys/CyRobekow
Alarms – Xenomai
rys/CyRobekow
Bibliography
1 https://xenomai.org/documentation/xenomai-3/html/
xeno3prm/
2 http://sequoia.ict.pwr.wroc.pl/~witold/opsys
rys/CyRobekow