Unit VI Linux and Real Time Real Time

  • Slides: 25
Download presentation
Unit - VI

Unit - VI

Linux and Real Time: • • • Real Time Tasks Hard and Soft Real

Linux and Real Time: • • • Real Time Tasks Hard and Soft Real Time Tasks Linux Scheduling Latency Kernel Preemption Challenges in Kernel Preemption

Real Time Tasks : • Soft Real Time • Even if deadline is missed

Real Time Tasks : • Soft Real Time • Even if deadline is missed output is accepted. • No catastrophic outcomes. • Hard Real Time • If deadline is missed output is of no use. • Catastrophic outcomes. • Has predictable latency • Often associated with the physical event

Linux Scheduling : • Real Time scheduling Requirement : • A real-time process must

Linux Scheduling : • Real Time scheduling Requirement : • A real-time process must be given absolute priority • Unix and Linux are both designed for fairness in the process scheduling. • All process should get required resources as they need to progress their execution as expected. • This very design objective is a block to the requirement of real time process. • Real Time Task has some real time attributes associated with it that scheduler use to identify it as highest priority process • SCHED_OTHER, SCHED_FIFO, SCHED_RR

Latency :

Latency :

Kernel Preemption : • No kernel preemption till version 1. x • No other

Kernel Preemption : • No kernel preemption till version 1. x • No other process can be scheduled to run , until that process blocked (waits for something) or completed • Kernel preemption allows one process to pre-empt a process running a kernel code (running in kernel space)

Kernel Preemption :

Kernel Preemption :

Challenges : • Originally Linux kernel is designed under a non-preemptable model • Later

Challenges : • Originally Linux kernel is designed under a non-preemptable model • Later kernel patches are incorporated for checking strategic locations where preemption can be allowed. • These points are the only safe point to allow preemption • Drawbacks : • Code for preemption checks were all around the kernel at strategic locations known to be safe for preemption. • Preemption was enabled only at these known-safe points.

Challenges : • Identify the places in the kernel that must be protected from

Challenges : • Identify the places in the kernel that must be protected from preemption • Critical section in the kernel where preemption is not allowed

Kernel Preemption: RT Approach • Real time system requires further minimization of latency in

Kernel Preemption: RT Approach • Real time system requires further minimization of latency in Linux kernel, and needs the following improvements with this respect. • The kernel should be fully preemptable anywhere. • Critical sections or other more specific section should be the only points where preemption is disabled. • Linux do not have support for hard real time in its mainline kernel source. • Few hard real time system patches must be applied to use it in hard real time systems • The patch enables the “Complete Preemption”

Preemption Model Options • PREEMPT_NONE: It means no forced preemption. Average performance in terms

Preemption Model Options • PREEMPT_NONE: It means no forced preemption. Average performance in terms of latency is good but long delays in some occasions are possible. Best suited for applications for which overall throughput is the top design criterion. • PREEMPT_VOLUNTARY: The first stage of reducing the latency. Preemption identifiers or preemption point are places at certain strategic kernel source code location. It reduces latency up to some level. • PREEMPT_DESKTOP: This model allows preemption anywhere in the kernel exception at critical section. Soft real time systems use this model. Useful for soft real-time applications • PREEMPT_RT: With this mode enabled, kernel can be pre-empted anywhere except the part of source code which is protected by preempt_disable().

Preemption Model

Preemption Model

Preemption Model

Preemption Model

Porting Linux : • The term OS porting means to modify or customize an

Porting Linux : • The term OS porting means to modify or customize an OS, which is running on particular hardware architecture, in such a way that it can run on another particular kind of architecture when loaded into one. • if we required loading the Linux OS into an embedded device, we must do something that will enable the OS running on x 86 based hardware to run on ARM based hardware, and we call it Linux Porting.

Linux Kernel Construction : • Building the kernel for target • Configuration • Compilation

Linux Kernel Construction : • Building the kernel for target • Configuration • Compilation • Top level directory • • • . . . / representation of root directory Next level subdirectories contains source code, config files, makefiles. . . / drivers : peripherals, USB, Bluetooth etc. . / arch related source codes (20 processors). . . /ipc, . . . / documentation, etc

Linux Kernel Construction : Kernel Root Directory Arch Directory : . . . /

Linux Kernel Construction : Kernel Root Directory Arch Directory : . . . / arch

Linux Kernel Construction : • Compiling the kernel • Kernel Build Files • •

Linux Kernel Construction : • Compiling the kernel • Kernel Build Files • • Configure for specific architecture Compile to produce Kernel binary file System. map kernel debugging Vmlinux arch specific kernel binary image (ELF format) • Kernel makefiles • Useful for selective compilation • make <makefiele in rootdirectory>

Linux Kernel Construction : • Kernel configuration and compilation • Configuration : Type of

Linux Kernel Construction : • Kernel configuration and compilation • Configuration : Type of Target hardware + required features • Cross Compilation : ARCH and CROSS_COMPILE • make ARCH=<platform_name> CROSS_COMPILE=<cross compiler toolchain> • Prepares kernel for arm architecture • Eg : make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi • Creates kernel image in. . . / arch/ <arch_name>/ boot • Kernel images : vmlinux, u. Image, bz. Image etc

Embedded Android : • • Bootloader Kernel Init Zygote System Server Activity Manager Launcher

Embedded Android : • • Bootloader Kernel Init Zygote System Server Activity Manager Launcher (Home)

Bootloader : • • • Loads on CPU start Located at a fixed address

Bootloader : • • • Loads on CPU start Located at a fixed address Initializes RAM Puts basic hardware in a quiescent state Loads the kernel and RAM disk Jump to Kernel Image

Kernel : • • • Early startup code is very hardware dependent Initializes environment

Kernel : • • • Early startup code is very hardware dependent Initializes environment for the running of C code Jumps to the architecture-independent start_kernel() function. Initializes high-level kernel subsystems Mounts root filesystem Starts the init process

Android Init : • • • Open, parses, and runs /init. rc Create mountpoints

Android Init : • • • Open, parses, and runs /init. rc Create mountpoints and mount filesystems Set up filesystem permissions Set OOM adjustments properties Start daemons: • • • adbd servicemanager (binder context manager) netd vold app_process -Xzygote (Zygote)

Zygote : • • • Daemon that launches apps. app_process command to start Zygote

Zygote : • • • Daemon that launches apps. app_process command to start Zygote by the Android runtime app_process –X Zygote Active only when a new app needs to be launched For faster app launch • Preloads all required java classes and other resources • • Then it listens for connections on its socket On app launch request forks itself “Copy On Write” mechanism Only one copy of the system classes and the resources is ever loaded in RAM as no child updates these system resources.

System Server : • First app created by Zygote • Initialize services and register

System Server : • First app created by Zygote • Initialize services and register to Service Manager • Services hosted by System Server • • Activity Manager Power Manager Headset Widget Notification Manager, etc. • Activity Manager, will end its initialization by sending an intent of type Intent. CATEGORY_HOME • Starts the Launcher App that displays home screen

Android Startup :

Android Startup :