Embedded RTOS Tasks
Embedded RTOS Tasks
Embedded RTOS Tasks
YZUCSE SYSLAB
Definition of Tasks
A task is an independent thread of execution that can compete with other concurrent tasks for processor execution time. A task is schedulable.
System tasks
Initialization or startup task Idle task Logging task Exception-handling task Debug agent task
Task states
Ready state
In this state, the task actively competes with all other ready tasks for the processors execution time. The kernels scheduler uses the priority of each task to determine which task to move to the running state.
Running state
On a single-processor system, only one task can run at a time. When a task is preempted by a higher priority task, it moves to the ready state. It also can move to the blocked state.
Making a call that requests an unavailable resource Making a call that requests to wait for an event to occur Making a call to delay the task for some duration
CS512 Embedded RTOS
Blocked state
CPU starvation occurs when higher priority tasks use all of the CPU execution time and lower priority tasks do not get to run. The cases when blocking conditions are met
A semaphore token for which a task is waiting is released A message, on which the task is waiting, arrives in a message queue A time delay imposed on the task expires
10
11
User-configurable hooks
A mechanism to execute programmer-supplied functions at the time of specific kernel events
Premature deletion
May get memory or resource leaks
12
Task scheduling
The scheduling can be handled automatically. Many kernels also provide a set of API calls that allows developers to control the state changes.
Manual scheduling
13
Task Scheduling
Scheduling:
Select the most deserving process to run based on system-specific policy
14
Policy Considerations
Policy can control/influence
CPU utilization Average time a process waits for service Average amount of time to complete a job
Equitability Favor very short or long jobs Meet priority requirements Meet deadlines
CS512 Embedded RTOS 15
16
17
Although each process can have its own address space, all processes have to share
Kernel ensure that each such register is loaded with the value it had when the process was suspended
CS512 Embedded RTOS 18
Operations
Save the context of the current process Load the context of new process If have page table, update the page table entries Flush those TLB entries that belonged to the old process
19
20
Delay a task
Allow manual scheduling Wait for an external condition that does not have an associated interrupt
Polling: wait up after a set time to check a specified condition or event had occurred
21
Preemption lock
A pairs of calls used to disable and enable preemption in applications Useful if a task is in a critical section of code
22
23
24
Processes in Linux
YZUCSE SYSLAB
Fs
tty_struct: keep track of tty associated with the process fs_struct: keep track of current directory files_struct: pointers to file descriptors mm_struct: pointer to memory area signal_struct: record signals recived
CS512 Embedded RTOS 26
Files
Suspended/Blocked
TASK_UNINTERRUPIBLE
waiting processes are waiting directly on hardware conditions and cannot be interrupted by signals
YZUCSE SYSLAB [email protected]
27
Zombie
TASK_ZOMBIE Process execution is terminated, but the parent process has not yet issued a wait()-like system call
YZUCSE SYSLAB [email protected]
28
Process 0
The ancestor of all processes, also called
swapper process
Created from scratch during the initialization phase by the start_kernel() function Execute the cpu_idle() function after having created the init process Process 0 is selected by the scheduler only when there are no TASK_RUNNING tasks
YZUCSE SYSLAB [email protected]
30
Process 1
Also called init process Created by process 0 by calling the kernel_thread() function Process 1 creates and monitors the activity of all processes that implement the outer layer of the operating system
For example, routinely issue wait() system to get ride of all zombie processes
CS512 Embedded RTOS
Since it executes the init() function that completes the initialization of the kernel
31
Requires copy the entire address space of the parent However, child may not need so much resources, especially child issues an immediate execve()
CS512 Embedded RTOS 32
33
34
CLONE_FILES: share the table that identifies the open files CLONE_PARENT: Set the parent of the child to the parent of the calling process CLONE_PID: share the PID (only used by Process 0) and used for a multiprocessor system CLONE_PTRACE: a parent is ptraced, also the child
YZUCSE SYSLAB [email protected]
35
36
38
Set the flag filed of the process descriptor as Remove, if necessary, the process descriptor from an IPC semaphore queue Remove, if necessary, the process descriptor from a dynamic timer queue Examine the processs data structure related to paging, filesystem, open file descriptors, and signal handling and remove each of them if no other processes are sharing them
39
All child processes becomes the children of another process or of the init process Set the state field of the process descriptor to TASK_ZOMBIE
40
Thus, kernel are not allowed to discard data included in a process descriptor field right after the process termination
Must be saved until the parent process is notified Why the introduction of TASK_ZOMBIE state
CS512 Embedded RTOS 41
References
Qing Li and Caroline Yao, Real-Time Concepts for Embedded Systems, CMP Books, ISBN: 1-57820-124-1, 2003 D. P. Bovet and M. Cesati, Understanding the Linux Kernel, 2nd edition,, O'Reilly & Associates, 2002. Jean J. Labrosse, "MicroC OS II: The Real Time Kernel," ISBN: 1578201039, CMP Books, June 15, 2002.
YZUCSE SYSLAB [email protected]
42