what is multitasking ,concept of multi tasking


Multitasking
 Multitasking is the process of scheduling and switching the CPU between several tasks; a single CPU switches its attention between several sequential tasks. Multitasking is like foreground/background with multiple backgrounds [1]. Multitasking maximize the utilization of the CPU and also provides for modular construction of applications. One of the most important aspects of multitasking is that it allows the application programmer to manage complexity inherent in real-time application. Application programs are typically easier to design and maintain if multitasking is used.
Task
 A task is a simple program that thinks it has the CPU all to itself. Each Task has
o   Its own stack space
o   A priority based on its importance
Task is assigned a unique priority .A task contains YOUR application code .A Real-Time application consists of several tasks executing concurrently. Task has its own set of CPU registers (backup in its stack) .Task is the basic unit for scheduling. Task status is stored in Task Control Block (TCB)
Task States
Each task typically is an infinite loop that can be in any one of five states: DORMANT, READY, RUNNING, and WAITING (for an event), and ISR (interrupted). 
Dormant State
It is the state corresponds to a task that resides in memory but has not been made available to the multitasking kernel. Deleting task stored in dormant state.
Ready State
A task is READY when it can execute but its priority is less than the currently running task. Simply say task is READY, but CPU is not available.
Running State
         A task is RUNNING when it as control of the CPU. Simply we can say task under execution is called RUNNING state. kernel-in-ARM-powered-microcontroller6
 Fig 4.1: Task States
Waiting State
         A task is WAITING when it require the occurrence of an event (waiting for an I/O operation to complete , a shared resource to be available ,a timing pulse to occur, time to expire, etc….) .Here CPU is ready, but task is not ready.
ISR State:
         A task is in the ISR state when an interrupt has occurred and the CPU is in the process of servicing the interrupt.
Context Switch (or Task Switch)
When a multitasking kernel decides to run a different task, it simply saves the current task’s context (CPU register) in the current task’s context storage area-its stack [3]. Once this operation is performed, the new task’s context is restored from its storage area then resumes execution of the new task’s code. This process is called a context switch or task switch.  kernel-in-ARM-powered-microcontroller8
 Fig 4.2:  Multitasking using a context switch
Context switching adds overhead to the application. The more registers a CPU has, the higher the overhead. The time required to perform a context switch is determined by how many register has to be saved and restored by the CPU. Performance of a real time kernel should not be judged by how many context switches the kernel is capable of doing per second.

0 comments:

Post a Comment