ES-Module4 Part1 Threads Tasks Etc
ES-Module4 Part1 Threads Tasks Etc
Introduction to embedded firmware & operating systems: Boot loader -Realtime kernel-Embedded OS-
Tasks, Processes and Threads, Multiprocessing and Multitasking, Task scheduling, Task communication and
synchronisation, Device Drivers.
Slides courtesy:
Dr Lyla Das
A PC wakes up…. warm /cold Boot
2
2
Functional Layers in a computing system
3
3
Functions of an OS
4
4
Functions of an OS
5
5
Memory Management System
6
6
Boot Loader
Once POST ( power on self test) and other
hardware initialization steps are done by BIOS,
system is ready to run the SOFTWARE BOOTLOADERS in Embedded
OS is in secondary memory ( due to ?) System?
Software responsible for loading OS core (kernel) They also do the same thing
onto main memory
A simple boot loader could be just few “Assembly
But
instructions” to copy OS code from disk to RAM Loads Application program
complex ones allow us to select an OS
Boot loaders are hardware platform dependant
They may allow code to be
8
And ….
9
What is an OS?
10
OS is the manager of the system
It manages
10
What is an OS?
11
General Purpose OS
It is software on top of
which the application Network OS
software runs
Embedded OS
→ System Software
Hence: compatibility issues ☺
Like DataBit length issues
11
Functions Performed By An OS {the manager}
12
Process Management
Memory Management
IO Management
File Management
Multiprogramming
Protection and Security
Network Management
12
DEVICE DRIVERS
13
13
Firmware? { Ascher Opler}
14
Firmware is the
Responsible for controlling
Software which is
the program sent the various peripherals and
/set/that sit inside for generating the desired
ROM in the response in accordance with
embedded module
the functional specification
A code that provides a low
level (?) control for the given by the customer /
device’s specific hardware
market demands
14
Firmware?
15
15
Firmware?
16
16
Firmware vs ?
17
17
KERNEL
18
18
KERNEL -- Ref LYLA DAS
19
Kernel is the first part of OS that gets loaded first into primary memory
Em bedded OS Kernals can be loaded only to appropriate H/W with proper configuration settings
Ty pes
Monolithic kernel
Microkernels - has servers
19
20
FIRMWARE – Super Loop based approach
22
For embedded systems that are not time critical
Tasks - Missing deadlines are acceptable –
eg : Games -- missing a keystroke
22
FIRMWARE – Embedded OS based approach
23
23
FIRMWARE – Embedded OS based approach
24
GPOS
GPOS is used for designs similar to conventional computing machines
ex: patient monitoring systems
Kernal is general and contains all general services
API (Application Programming interface) is provided as the
interface between OS and the applications built on top of
OS
API offers functions, routines, protocols needed to simplify
the END user experience in target code development
Ex:To use ADC in the system, ADC () function is provided
as an API
Ex: Windows Embedded 8.1
24
FIRMWARE – Embedded OS based approach
25
RTOS
RT is debatable
Deterministic behavior is the key
OS must consume only known / expected amount of time regardless of
task → PREDICTABLE BEHAVIOR
Time critical applications governed by strict policies to avoid conflicts
Ex: Windows Embedded compact, VxWorks
Basic functions Process management, scheduling, synchronization,
Error/Exception handling, Interrupt handling, Time management,
Memory management
25
RTOS – how does it handle time critical systems?
26
Switch task or preempt the task when it waits for external event or a
26
30
30
Tasks/Processes
31
31
Tasks/Processes
32
32
Structure of Process
33
Process
Stack
Working registers
Status Registers
PC
33
Memory Organisation of Processes
34
Stack Memory
Data memory
Code memory
34
The FIVE states of a Process/Task
35
The five
states are
named as
New(create)
Ready
Running
Blocked
Exit.
35
TASK/PROCESS - State Transitions
36
New/Created state – the
state at which a process is
being created.
Ready state – state where
process is incepted into
memory and awaiting the
processor time for
execution.
Process is placed in ready list
queue maintained by OS
Resources are attached
Running State – state
where source code
corresponding to the
process is executed.
36
TASK/PROCESS - State Transitions -possibilities
37
Blocked/ wait
state – state where
running process is pushed
into - thus temporarily
suspended from execution
and will not have
immediate access to
resources …… this is called
as “Pre-emption”
Exit/Completed
State – process
completes its
execution [ either
successful completion or
abnormal termination]
37
Process state and state transition
Creation to its
termination is not
single step operation.
38
TASK/PROCESS - State Transitions -possibilities
39
39
Process/Task Control block (PCB)
40
Data
structure
maintained by
OS to control
process states.
Architecture is
dependent on
OS
40
Process/Task Control block (PCB)
41
41
Threads
42
A thread is sometimes
called a ‘lightweight
process’
42
Threads
43
43
Threads and Mutlithreading concept
44
If all subfunctions in a task are executed sequentially, processor utilisation may not be 100%
So instead of single sequential execution of task/process, it is split into different smaller sequential pieces
carrying out relatively independent subfunctionalities
When one thread enter a wait state another thread can be queued up and avoid processor stalling - So ??
????
44
Thread Pre-emption
45
45
Kernal Level Threads
46
Features
If one thread is blocked , kernel can schedule another thread of same process
46
User Level Threads
47
Features:
Does not require kernel mode privileges
Run on any OS
Scheduling can be application specific
Fast to create and manage
47
Threads.. continued
48
48
Multithreading models
49
49
Multithreading models---- Many – to – many
50
50
Multithreading models---- Many – to – One
51
51
Multithreading models---- One– to – One
52
52
Process & Threads
53
Process Thread
Process is a program in execution and Thread is a single unit of execution and part of
contains one or more threads process
Process has it own code memory, data Thread does not have it own code memory, data
memory and stack memory- It shares with other threads of the same
process . But usually maintains a stack of its own
A process contain at least one thread A thread cannot exist independently .. It lives
within process
Process is expensive to create .. Involves Thread is inexpensive to create….in general
OS overhead
Process switching is complex , slow and Thread context switching is fast and relatively
relatively expensive. inexpensive
If a process dies, resources go back to OS If a thread expires, resources are reclaimed by
and all associated threads also die process
53
Process & Threads
54
54
What is…Multitasking and Multiprocessing?
55
55
What is…
56
Multitasking?
56
What is…Multitasking?
57
Psuedo Parallelism by time sharing – each task gets its time slice/
chunk and then task switching is done to relinquish its claim over
resources
TCB has the task context {information} to help pick up when a
relinquished task gets its next turn.
Overhead for OS – switching from one task to another – by saving
the current task’s status
57
How does multitasking affect the user?
58
59
CPU and I/O bound tasks
60
60
61
61
Selection of a Scheduling Algorithm
62
Some aspects
• CPU utilization
• Only one processor and it should not idle
• Response time
• Interval for which a task waits to be taken up for execution by the processor
• Must be minimum
• Turnaround time (TAT)
• Interval between the instant task is presented to the system to the instant it exits
• TAT = Twait in Ready Queue +T service ( including blocked time)
• Throughput rate
• Number of tasks processed in unit time
• Inverse of TAT
62
Scheduling Algorithms -Assumptions
63
63
Scheduling Algorithms -Types
64
Scheduling
Non Pre-
Pre-emptive
emptive
64
Non-preemptive Methods of Scheduling
65
Co-operative Scheduling
Each task is allowed to execute to its finish,
then only the next one is taken up.
While one task executes, the others are willing to
wait and this gives the name ‘co-operative’ to the
scheduling algorithm.
This is also a case of first come first serve scheduling
/ a first in first out scheme (FCFS/FIFO) or last come
first serve scheduling / a last in first out scheme
(LCFS/LIFO)
65
Non-preemptive Methods of Scheduling
66
Non-preemptive Methods of Scheduling
T1 300
FCFS
T2 125
Solution
T3 400
67
T4 150
T5 100
67
Non-preemptive Methods of Scheduling
Queue the tasks such that the one with the shortest
service time gets to execute first
Disadv:
Usually the execution times of tasks are not known in
advance.
The method then is to estimate the service times by
using the recent history of each of the tasks
Additional overhead of past history tracking
68
Non-preemptive Methods of Scheduling
69
Non-preemptive Methods of Scheduling
T1 300
T2 125
T3 400
T4 150
T5 100
70
Non-preemptive Methods of Scheduling
T1 300
T2 125
T3 400
T4 150
T5 100
T6 250
T7 200
71
Non-preemptive Methods of Scheduling
T1 300
Solution T2 125
T3 400
T4 150
T5 100
T6 250
T7 200
72
Non-preemptive Methods of Scheduling
Priority-based Scheduling
73
73
Non-preemptive Methods of Scheduling
74
Non-preemptive Methods of Scheduling
Solution T1
T2
300
125
5
3
T3 400 2
T4 150 12
T5 100 15
75
Non-preemptive Methods of Scheduling
76
Non-preemptive Methods of Scheduling
T1 300 5
T2 125 3
T3 400 2
T4 150 12
T5 100 15
T6 120 0
T7 80 4
T8 3500 6
77
Pre-emptive Scheduling Strategies
78
78
Preemptive Methods of Scheduling
79
Preemptive Methods of Scheduling
80
Preemptive Methods of Scheduling
T1 150
T2 100
T3 200
T4 50
81
Preemptive Methods of Scheduling
82
Preemptive Methods of Scheduling
T1 300
T2 125
T3 400
T4 150
T5 100
83
Preemptive Methods of Scheduling
2.Pre-emptive Priority
84
84
Preemptive Methods of Scheduling
85
Preemptive Methods of Scheduling
T1 300 5
Solution T2 125 3
T3 400 2
T4 150 12
T5 100 15
At time 600 →
T6* 75 1
86
Preemptive Methods of Scheduling
3.Pre-emptive SJN/Shortest Remaining
Time (SRT)
87
In the midst of a schedule, if a new task enters the ready queue, its service time is compared
with the remaining service time of the currently executing task
If the new task has a shorter service time than the remaining time of the current task, it (the
current task) is
pre-empted and the new one serviced until it completes.
87
Preemptive Methods of Scheduling
88
Preemptive Methods of Scheduling
Solution T1 300
T2 125
T3 400
T4 150
T6 50
89
END of presentation
90