Documente Academic
Documente Profesional
Documente Cultură
8/20/2013
Contents
What is a Real Time Operating System? Difference between RTOS & other common OS? Characteristics of a good RTOS? Hard RTOS. Soft RTOS. The Scheduler. Task & Task States. RTOS existing in market. Introduction to RTLinux. Writing RTLinux Modules. Soft & Hard Interrupts. Applications of RTLinux. Conclusion.
8/20/2013
Real Time In OS : The ability of OS to provide a required level of service in a bounded response time.
RTOS : Has a well defined, fixed time constraint. : Processing must be done within the define constraints or the system will fail. : Real Time system is considered to function correctly only if it returns the correct result within any time constraint. : Real Time system is one in which correctness of computations not only depends on logical correctness of the computation but also upon the time at which the result is produced. : If timing constraints of the system are not met , system failure is said to have occurred.
8/20/2013
Most RTOS are actually different from desktop operating systems such as windows & Unix. Firstly, other operating systems takes control as soon as system is turned on and lets you start your applications.Also compilation & linking of application is done separately from operating system. Whereas in case of RTO, at boot time, your application usually gets control first and then it starts the RTOS. So here we link the RTOS with our application. Secondly, many RTOS do not protect themselves as carefully from application as do other desktop operating systems. Finally, RTOS typically includes just the services that you need for your embedded system and no more.This feature of RTOS enables it to save memory
8/20/2013
Saving Memory : One special consideration if you use an RTOS is that each task needs memory space for its stack. Therefore you should ensure that your system allocates only as much stack memory as is needed.So the method for determining how much stack space a task needs is to examine your code.Each function call , function parameter and local variable takes up certain number of bytes on the stack.Then you must add space for the worst case I.e nesting of interrupt routines and some space for RTOS itself. The Interrupt Latency : For every system call, the maximum time it takes should be predictable & independent of number of objects in the system. System Interrupt Level : A good RTOS should have a good documentation, should be delivered with good tools to develop and tune your application. So a RTOS supporting many devices will have more advantageous than a simple very good nano - Kernel.
8/20/2013
Hard RTOS
Hard RTOS guarantees critical task will complete in a given amount of time.For this all delays in the system must be bounded. If a process completes correctly but takes longer than given amount of time, the process fails. The Scheduler plays an important role in Hard RTOS. The Scheduler either admits the process, guaranteeing that the process will complete on time, or it rejects the request if it is impossible.
8/20/2013
Soft RTOS
Soft RTOS are less restrictive than Hard RTOS. In Soft RTOS critical tasks are given priority over non critical tasks. Here also, like Hard RTOS, delays need to be bounded so that critical task do not wait for ever, but these are not as severe as in Hard RTOS. In this if a process completes correctly, but takes longer than its given amount of time, the result may still be useful. Like in Hard RTOS, Scheduler plays an important role in Soft RTOS also. Important aspects of implementing Soft RTOS are : 1) The system must have priority scheduling and the real time process must have highest priority. 2) The dispatch latency must be small.The smaller the latency, the faster the real time process can start executing once it is runnable.
8/20/2013
The Scheduler
The Scheduler keeps the track of state of each task and decides which one should go into running state. It looks at the priorities you assign to the tasks and among the tasks that are not in block state, the one with the highest priority runs and the rest of them waits in the ready state.The lower priority tasks just have to wait. How does the scheduler know when a task has to become Blocked or Unblocked? The RTOS provides a collection of functions that tasks can call to tell the scheduler, what events they want to wait for and to signal those events, which have happened. What happens if all the tasks are blocked ? If all the tasks are blocked then the Scheduler will spin in some tight loop inside of the RTOS, waiting for something to happen. What if two tasks of same priority are ready? It depends on the RTOS that you use. Many systems solve this problem by making it illegal to have same tasks of same priority. Some RTOS have employed the concept of time slicing between two tasks.
8/20/2013
The basic building blocks of software written under an RTOS is the task.Each task in an RTOS is always in one of the three states : 1). Running : Which means that the microprocessor is executing the instruction that make up this task. Unless yours is a multiprocessor system, there will be only one task, which will be in running state at any given time. 2). Ready : Which means that this task is ready for execution but since some other task is undergoing execution presently, this task is waiting for its turn.Any number of tasks can be in this state. 3). Blocked : Which means that this task hasnt got anything to do right now, even if the microprocessor becomes available. Tasks get into this state because they are waiting for some external event to happen.Any number of tasks can be in this state as well.
8/20/2013
Wind River Systems VxWorks. Integrated Systems pSOS. QNX Systems QNX. FSM Labs RTLinux. Kodaks AMX. Microtecs VRTX. Microwares OS/9. Accelerated Technologys Nucleus.
8/20/2013
8/20/2013
Mission: Reaching the destination safely. Controlled System: Car. Operating environment: Road conditions and other cars. Controlling System - Human driver: Sensors - Eyes and Ears of the driver.
8/20/2013
Controls: Accelerator, Steering wheel, Break-pedal. Actuators: Wheels, Engines, and Brakes Critical tasks: Steering and breaking.
8/20/2013
Cost of fulfilling the mission Efficient solution. Reliability of the driver Fault-tolerance is a must
8/20/2013
8/20/2013
A real-time system is a system with performance deadlines on computations and actions; that is, system correctness depends on the timeliness of results. An embedded system is a system that exists within a larger system. A job is a unit of work that is scheduled and executed by the system (Ji,k ). A task is a set of related jobs that provide some system function i = { Ji,1, Ji,2, ... , Ji,n }.
8/20/2013
Latency
The latency (or tardiness) of a task is the difference between the instant of time on which the task should have started (or finished) and the instant of time on which it actually did.
8/20/2013
the timing properties of processor, bus, memory (on-chip cache, off-chip RAM and ROM) and peripheral devices the scheduling properties of the operating system the preemptive ness of its kernel the load on the system (i.e., the number of tasks that want to be scheduled concurrently), and
8/20/2013
Deadlines
The release time (or arrival time) of a job is the time at which the job becomes available for execution ( ri or Ri ). The response time of a job is the length of time between the release time of the job and the time instant when it completes. The relative deadline of a job is the maximum allowable response time of a job ( Di ).
8/20/2013
Deadlines
The absolute deadline of a job is the time at which a job must be completed ( di = ri + Di ).
8/20/2013
Scheduler
A scheduler assigns jobs to processors. A schedule is an assignment of all jobs in the system on available processors (produced by scheduler). The execution time (or run-time) of a job is the amount of time required to complete the execution of a job once it has been scheduled ( ei or Ci ).
8/20/2013
Feasible Schedule
A valid schedule is a feasible schedule if every job meets its timing constraints; e.g., completes execution by its deadline. A set of jobs is schedulable according to a scheduling algorithm if (when) using the algorithm (the scheduler) always produces a feasible schedule. The lateness of a job is the difference between its completion time and its deadline. If the job completes early, its lateness will be negative
8/20/2013
Periodic Task
of jobs with identical parameters with: a period ( pi or Ti ) equal to the minimum length of time between the release times of consecutive jobs, an execution time ( ei or Ci ) equal to the maximum execution time of any job in the task, and a phase ( i ) equal to the release time of the first job in i.
8/20/2013
Standalone Applications
Multiple threads Complicated Synchronization Requirements File system / Network / Windowing support
8/20/2013
Features of RTOSs
Scheduling. Resource Allocation. Interrupt Handling. Other issues like kernel size.
8/20/2013
Scheduling in RTOS
8/20/2013
8/20/2013
Clock Driven
All parameters about jobs (release time/ execution time/deadline) known in advance. Schedule can be computed offline or at some regular time instances. Minimal runtime overhead. Not suitable for many applications.
8/20/2013
Jobs scheduled in FIFO manner Time quantum given to jobs is proportional to its weight Not suitable for precedence constrained jobs.
Job A can run only after Job B. No point in giving time quantum to Job B before Job A.
8/20/2013
Priority Scheduling
Processor never left idle when there are ready tasks Processor allocated to processes according to priorities Priorities
8/20/2013
Priority Scheduling
8/20/2013
Resource Allocation
Example : semaphores
8/20/2013
8/20/2013
T3 obtains a lock on the semaphore S and enters its critical section to use a shared resource. T1 becomes ready to run and preempts T3. Then, T1 tries to enter its critical section by first trying to lock S. But, S is already locked by T3 and hence T1 is blocked. T2 becomes ready to run. Since only T2 and T3 are ready to run, T2 preempts T3 while T3 is in its critical section.
8/20/2013
8/20/2013
Priority Inheritance
The thread holding a resource inherits the priority of the thread blocked on that resource
8/20/2013
8/20/2013
Kernel has to respond to real time events Interrupts should be disabled for minimum possible time
8/20/2013
Scheduling
Optimize average case response time Aim to reduce response times of processes
Resource Allocation
8/20/2013
System calls like fork take a lot of time High priority thread might wait for a low priority thread to complete its system call Context switch takes several hundred microseconds
8/20/2013
RTLinux
Real Time Kernel at the lowest level Linux Kernel is a low priority thread
Interrupts trapped by the Real Time Kernel and passed onto Linux Kernel
8/20/2013
RTLinux (contd)
Real Time Tasks Non Real Time Tasks are developed in Linux Communication
8/20/2013
RT Linux - Approach
RT Linux uses VM concept limited to interrupt emulation. It slips a small, simple, RT OS underneath Linux. Linux becomes an idle task for this OS
8/20/2013
8/20/2013
RTLinux Framework
8/20/2013
RT Linux Approach(Cont..)
A layer of emulation software between Linux kernel and interrupt controller hardware. Prevents disabling of interrupts by Linux
8/20/2013
RT Linux Tasks
Initial Design Each RT task executed in its own address space. High overhead of context switching as TLB had to be invalidated. High overhead of system calls. Now all RT tasks run in the same address space (in the kernel space) and at the highest privilege level.
8/20/2013
RT tasks run as kernel modules. Can be dynamically added. Tasks have integer context for faster context switching (unless FP context is explicitly requested). Hardware context switching provided by x86 is not used. Task resources should be statically allocated (kmalloc etc. should not be used within an RT task).
8/20/2013
RT Linux Scheduling
RT Linux is module based the scheduler is itself a loadable kernel module. Default A simple preemptive priority based scheduler where the tasks are statically assigned priorities. The highest priority task ready to run is scheduled.
8/20/2013
Earliest Deadline First (EDF) A dynamic priority scheduler in which the task with the nearest deadline is scheduled. Rate Monotonic (RM) A static priority scheduler for periodic tasks where the task with the smallest period is assigned the highest priority. This is provably the optimal policy.
8/20/2013
8/20/2013
VxWorks
pSOS
8/20/2013
Introduction To RTLinux
Developed by FSMLabs Inc. in 1995 in New Mexico. It is a Hard RTOS that co-exists with Linux OS. With RTLinux it is possible to create Real Time POSIX.1b Threads that will run at precisely specified moments of time. WARNING : Real Time programs in RTLinux are executed in Kernel space and have little or no protection against bugs in users code. Special care must be taken when programming real time tasks because programming errors may bring the system down. For this RTLinux supplies a debugger within its source tree under the directory debugger. So use of debugger is strongly recommended to reduce the risk of to reduce the risk of system crashes. For those who are primarily interested in hard real time control and not particularly interested in learning how to use RTLinux itself,can take a look at FSM Labs RTiC-Lab at www.rtic-lab.org . RTiC-Lab is a front end to RTLinux that greatly simplifies hard real time control implementation, monitoring and tuning. For those who are interested in running RTLinux on an industry standard PC-104 board or other type of minimal or embedded system,can refer to FSMLabs MiniRTL project , found www.rtlinux.org/ minirtl.html. MiniRTL fits on a single floppy disk and provides full RTLinux capabilities.
8/20/2013
Linux Kernel
8/20/2013
RTLinux Kernel
8/20/2013
Understanding an RTLinux Program : In RTLinux, programs are modelled as modules which are loaded into the Linux kernel space. A Linux module is nothing but an object file, usually created with the -c flag argument to gcc. The module itself is created by compiling an ordinary C language file in which the main () function is replaced by a pair of init/cleanup functions: int init_module(); void cleanup_module(); init_module() function is called when the module is first loaded into the kernel. It should return 0 on success and returns negative value on failure. cleanup_module() is called when module is unloaded. For example :If we assume that a user has created a C file named my mo-dule. c, the code can be converted into a module by typing the following: gcc -c {SOME-FLAGS} my_module.c This command creates a module file named my module.o, which can now be inserted into the kernel. To insert the module into the kernel, we use the insmod command. To remove it, the rmmod command is used.
8/20/2013
A real time application is usually composed of several threads of execution. Threads are light-weight processes which share a common address space. Conceptually, Linux kernel control threads are also RTLinux threads (with one for each CPU in the system). In RTLinux, all threads share the Linux kernel address space. To create a new real time thread, we use the pthread create(3) function. This function must only be called from the Linux kernel thread (i.e., using init module()): #include <pthread.h> int pthread_create(pthread_t * thread, pthread_attr_t * attr, void *(*start_routine)(void *), void * arg); The thread is created using the attributes specified in the attr thread attributes object. If attr is NULL, default attributes are used. The ID of the newly created thread is stored in the location pointed to by thread. The function pointed to by start routine is taken to be the thread code. It is passed the arg argument. To cancel a thread, use the POSIX function: pthread cancel(pthread thread);
8/20/2013
Time Facilities
RTLinux provides several clocks that can be used for timing functionality, such as as referencing for thread scheduling and obtaining timestamps. Here is the general timing API: #include <rtl_time.h> int clock_gettime(clockid_t clock_id, struct timespec *ts); hrtime_t gethrtime(void); struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; To obtain the current clock reading,we use the clock_gettime(3) function where clock_id is the clock to be read and ts is a structure which stores the value obtained. The hrtime_t value is expressed as a single 64-bit number of nanoseconds. Thus, clock_gethrtime(3) is the same as clock_gettime, but returns the time as an hrtime_t rather than as a timespec structure.
8/20/2013
Scheduling Threads
RTLinux provides scheduling, which allows thread code to run at specific times. RTLinux uses a pure priority-driven scheduler, in which the highest priority (ready) thread is always chosen to run. RTLinux uses the following scheduling API: int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param); int pthread_make_periodic_np(pthread_t thread, hrtime_t start_time,hrtime period); int pthread_wait_np(void); int sched_get_priority_max(int policy); int sched_get_priority_min(int policy);
8/20/2013
This program will execute two times per second, and during each iteration it will print the message: Im here, my arg is 0 Program for hello.c : #include <rtl.h> #include <time.h> #include <pthread.h> pthread_t thread; void * start_routine(void *arg) { struct sched_param p; p . sched_priority = 1; pthread_setschedparam (pthread_self(), SCHED_FIFO, &p); pthread_make_periodic_np (pthread_self(), gethrtime(), 500000000); while (1) { pthread_wait_np(); rtl_printf("Im here; my arg is %x\n", (unsigned) arg); } return 0;
8/20/2013
8/20/2013
In order to execute our program, we must first do the following: 1. Compile the source code and create a module. We can normally accomplish this by using the Linux GCC compiler directly from the command line. To simplify things, however, well create a Makefile. Then well only need to type make to compile our code. 2. Locate and copy the rtl.mk file. The rtl.mk file is an include file which contains all the ags needed to compile our code. For simplicity, well copy it from the RTLinux source tree and place it alongside of our hello.c file. 3. Insert the module into the running RTLinux kernel. The resulting object binary must be plugged in to the kernel, where it will be executed by RTLinux. We begin by creating the Makefile that will be used to compile our hello.c program. Type the following into a file called Makefile and put it in the same directory as your hello.c program: hello.o: hello.c gcc $(CFLAGS) hello.c Now, type the following: make -f rtl.mk hello.o This compiles the hello.c program and produces an object file named hello.o.
8/20/2013
We now need to load the RTLinux modules. rtlinux start hello You can check the status of your modules by typing the command: rtlinux status hello For more information about the usage of the rtlinux command: rtlinux help You should now be able to see your hello.o program printing its message twice per second. To stop the program, we need to remove it from the kernel. To do so, type: rtlinux stop hello
8/20/2013
There are two types of interrupts in RTLinux: Soft and Hard. Soft Interrupt: 1). Soft interrupts are normal Linux kernel interrupts. 2). They have the advantage that some Linux kernel functions can be called from them safely. 3). However, for many tasks they do not provide hard real time performance; they may be delayed for considerable periods of time. Hard Interrupt: 1). Hard interrupts (or real time interrupts), on the other hand, have much lower latency. 2). However, just as with real time threads, only a very limited set of kernel functions may be called from the hard interrupt handlers.
8/20/2013
Application of RTLinux
In
Education :
The Center for Experimental Research in Computer Systems (CERCS) at Georgia Institute of Technology uses RTLinux for real-time system instruction and research. The Software Engineering Graduate Program at Mercer University's School of Engineering uses RTLinux in teaching real-time embedded programming.
8/20/2013
NASA's FlightLinux uses RTLinux for onboard spacecraft control and management.
8/20/2013
RTLinux provides hard real-time decisions on optical profiles of microscopic objects in the Union Biometrica COPAS analyser and dispenser .
8/20/2013
8/20/2013
B.M. Ledvina uses RTLinux to do most of the work of a GPS receiver, thus reducing parts count and cost of the whole unit. Cornell University uses RTLinux in Cascade, a software based GPS receiver. Yan Shoumeng uses RTLinux for remote monitoring and surveillance to avoid exposing humans to dangerous environments.
8/20/2013
8/20/2013
8/20/2013
8/20/2013
The Units of Intensive Care in the Hospitals of Peru use RTLinux to do centralized monitoring of patient lung ventilators.
RTLinux is used to control biological experiments at the Cornell University Cardiac Electrodynamics Lab.
8/20/2013
8/20/2013
Conclusion
RT Linux has achieved hard real-time performance by making minimal changes to a freely available Operating System. Provides an alternative to proprietary real-time systems which may be prohibitively expensive. As Linux develops, RT Linux will also ride the wave of its development. Unlike other RT systems, no separate support for RT Linux is needed since support for Linux is already widely available.
8/20/2013
8/20/2013
8/20/2013