Showing posts with label RTOS. Show all posts
Showing posts with label RTOS. Show all posts

Friday, January 27, 2012

Deadlock


Deadlock is a situation in which the processes waits for the other resource which is occupied by another process in a loop for example take processes P1 and P2 and resources R1 and R2 in the deadlock condition

        P1 -R1 waits for R2
        P2 -R2 waits for R1 

so both processes waits for the other resource to get free for their complete operation.
In such cases - One can avoid deadlocks by following methods

1) Prevention
2) Detection
3) Avoidance
4) Recovery

What is interrupt latency?


It is the time interval between an interrupt has occurred till the time it has been serviced.

Friday, January 13, 2012

Preemptive Scheduler & Priority Inverse

Preemptive Scheduler
A scheduler that may switch between threads at any time.


 Priority Inverse
A situation where a low-priority task holds a resource which a higher-priority task is waiting for.

What is preemption?

The act of suspending the execution of one thread and starting (or resuming) another. The suspended thread is said to have been "preempted" by the new thread.

Message Queue, Semaphore and Mutex

Message Queue
Tasks communicate with each other using message queues.

Semaphore and Mutex
Semaphore / Mutex is mainly used for synchronization between tasks.

Mutex(mutual-exclusion locks) is nothing but a semaphore which semaphore-wait and semaphore-signal should be done with in a task. Mutexes  are used to implement critical sections and protect shared mutable data structures against concurrent accesses.

Semaphore Services
  • Way to synchronize multiple tasks
  • to ensure mutual exclusion
  • Control access to a shared resource

Timeslice & Timeslice Termination

Timeslice
In a multitasking environment, if more than one task having same priority will be executed simultaneously in a short interval of time. This is called Time slice. 

Timeslice Termination
A task needs to voluntarily give up control of the CPU so that another task at the same priority can execute, that is, terminate the current timeslice. This is achieved with the functions:
void task_reschedule (void);
void task_yield (void);

Interrupts

Provide a away for external events to control the CPU. CPU will stop executing the current task and start executing the interrupt handler for that interrupt. Interrupts can be prevented from interrupting the task by using the interrupt_mask() or interrupt_mask_all() functions.

The kernel scheduler

The kernel scheduler can be prevented from preempting or timeslicing the current task, by using the following pair of functions:
void task_lock (void);
void task_unlock (void);

Three states of CPU to schedule

Ready - waiting to run (in ready list)
Running - process (thread or task) is utilizing the processor to execute instructions
Blocked - waiting for resources (I/O, memory, critical section, etc.)

Four main tasks of OS

  • Process Management
        Process creation
        Process execution control
        Interaction of the process with signal events
        Process monitoring
        CPU allocation
        Process termination
  • Interprocess Communication
        Synchronization and coordination
        Deadlock and Livelock detection
        Process Protection
        Data Exchange Mechanisms
  • Memory Management
        Services for file creation, deletion, reposition and protection
  • Input/Output Management
        Handles requests and release subroutines for a variety of peripherals and read, write and reposition 
        programs

Hard real-time & Soft real-time

Hard real-time
Realtime applications can be classified as either hard or soft realtime. Hard realtime applications require a response to events within a predetermined amount of time for the application to function properly. If a hard realtime application fails to meet specified deadlines, the application fails. While many hard realtime applications require high-speed responses, the granularity of the timing is not the central issue in a hard realtime application.

An example of a hard realtime application is Avionic control system where a late response will result fail in operation.

Soft real-time
Soft realtime applications do not fail if a deadline is missed. Some soft realtime applications can process large amounts of data or require a very fast response time, but the key issue is whether or not meeting timing constraints is a condition for success.

An example of a soft realtime application is an hotel reservation system where an occasional delay is tolerable, but unwanted.

RTOS

RTOS is specifically designed for real time applications. It should respond the external events with in a short and predictable time frame. The following devices are using RTOS,
  • Mobiles
  • Set top box
  • Industrial robots
  • Spacecraft
Examples for RTOS,
  •     RTLinux
  •     VxWorks
  •     ST Lite