0% found this document useful (0 votes)
18 views20 pages

Emb Mod4

Uploaded by

katyaini1511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views20 pages

Emb Mod4

Uploaded by

katyaini1511
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Mod4 Courtesy Prof Lyla B Das

Module 4
2
EMBEDDEDFIRMWARE&OPERATINGSYSTEMCONCEPTS

• Application programs like


1 games- developed by User
API • Utilities are programs
present to support
ancillary activities [like
compilers, linkers..]-
Developed by system
Device Drivers programmer
• OS – program that
shields the user from
having to know anything
about the underlying
hardware – developed by
an expert system
programmer

Dr Binu Paul Dr Binu Paul

What is an OS? Firmware?


3 4

 OS is the manager of the system


 Firmware Software which is the program sent inside ROM in
It manages physical resources ( mouse, memory etc) and logical
resources ( file, variables) the embedded module
Make the system friendly for the end user
“Hide” the complex hardware from the end user / application  Embedded Firmware is the “master brain/ intelligence” of the
program --- “Abstraction – at each level”
 Ex: 1.child- play game… not aware of graphics card embedded system
• 2. network administrator - not aware of MUP but be aware of setting
passwords/ configuration etc.  Responsible for controlling the various peripherals and for
 It is software on top of which the application software generating the desired response in accordance with the
runs System Software
 Hence: compatibility issues , DataBit length issues functional specification given by the customer

 General Purpose OS, Embedded OS, Network OS  Once intelligence is imparted to Hardware { i.e ROM programmed} end

user cannot alter it


Dr Binu Paul Dr Binu Paul

1
Mod4 Courtesy Prof Lyla B Das

Firmware? Functions Performed By An OS {the manager}


5 6

 Process Management
 Adaptability ensured by leaving some
 Memory Management
configuration variables in the Flash RAM
 IO Management
 Firmware developer need to understand the  File Management
 Multiprogramming
application desired, components used in
 Protection and Security
hardware, memory map and a programming  Network Management
language {assembly /C/ Java }

Dr Binu Paul Dr Binu Paul

KERNAL KERNAL -- Ref LYLA DAS


8 9
 The KERNAL is the innermost part or
core of an operating system, and it is  Kernal is the first part of OS that gets loaded first into primary memory
that which provides the basic services
 Its stays there through out the session
for all other parts of the system
 The kernel is sometimes referred to as  It has the highest privilege status

the supervisor, core or internals of the  It has full access to hardware


operating system
 Kernal of every OS is unique and cannot migrate from OS to OS

 It has a protected memory space -

Level 1- less important part of system software  Applications have access to Kernal through “System Call” interface
Level2 –software utilities
 Types
Level 3 – application pgms
Monolithic kernel – complete Kernal as a single unit – so failure is catastrophic- ex:Solaris
Microkernels - broken into sections and some run in user space –these are called servers.. total
crash avoided.. Only those ’servers’ that fails need be reconfigured– hence robust ex: Mach

Dr Binu Paul Dr Binu Paul

2
Mod4 Courtesy Prof Lyla B Das

FIRMWARE – design approaches


11

 Embedded Firmware is the “master brain/ intelligence” of


the embedded system
 Design depends on complexity of application and speed
desired
 Two approaches
Super loop based approach [ conventional Procedural based]
Embedded OS based approach

Dr Binu Paul 10 Dr Binu Paul

FIRMWARE – Super Loop based approach FIRMWARE – Embedded OS based approach


12 13

 For embedded systems that are not time critical


 Tasks Missing deadlines are acceptable –
 The code is executed based on Task scheduling
eg : Games -- missing a keystroke algorithms to maximise the resource utilization
 The code is executed Task by Task in a predetermined order
 Tasks are executed under OS supervision
 If any task hangs, entire code hangs – solved using s/w or h/w Watch
Dog timers  OS supported applications will also have “DEVICE
 The complete code kept in infinite loop.. After nth task, task 1 taken up DRIVER SOFTWARE” for different hardware on
again.
Ref 9.1.1 of Shibu K V to see a sample Embedded C code
the system
 Do not need OS as there is no need to decide which task is to be done  Types- GPOS , RTOS
first – while application is executing
 Simple and straight forward as it is without the OS overhead

Dr Binu Paul Dr Binu Paul

3
Mod4 Courtesy Prof Lyla B Das

FIRMWARE – Embedded OS based approach FIRMWARE – Embedded OS based approach


14 15

GPOS RTOS
RT is debatable
 GPOS is used for designs similar to conventional computing machines –
ex: patient monitoring systems Deterministic behavior is the key
Kernal is general and contains all general services  OS must consume only known / expected amount of time regardless of
API (Application Programming interface) is provided as the task PREDICTABLE BEHAVIOR
interface between OS and the applications built on top of OS Time critical applications governed by strict policies to avoid conflicts
API offers functions, routines, protocols needed to simplify the Ex: Windows Embedded compact, VxWorks
END user experience in target code development Basic functions Process management, scheduling, synchronization,
Ex:To use ADC in the system, ADC () function is provided as an Error/Exception handling, Interrupt handling, Time management,
API
Memory management
 Ex: Windows Embedded 8.1

More a bit later { Ref Shibu K V chap 10 p 394}


Dr Binu Paul Dr Binu Paul

Some Terms Associated with Operating Systems


RTOS – how does it handle time critical systems?
16 17

 Assign priority to tasks when tasks enter ready Queue

 Schedule execution based on the task’s priority


 Low Level Software Utility
 Dynamically change priority on a need basis A specific system program that manages resources or files
 Switch task or preempt the task when it waits for external event or a Ex: pass word protection, disk partitioner etc
system shared resource allocation Provide important services to user

 All this done by the Real – time OS kernel called as RT kernel

 RT Kernal is more sophisticated but contains only those basic functions

desired for that specific application

Dr Binu Paul Dr Binu Paul

4
Mod4 Courtesy Prof Lyla B Das

Some Terms Associated with Operating Systems Some Terms Associated with Operating Systems

18 19

 Boot Loader  User Interface


The software responsible for loading the OS code into main The interface program that helps to send requests USER OS to gain
memory [FLASH memory of processor] when power is access to I/O devices
switched on  Application Programming Interface (API)
 This is done once Power on self test (POST ) is over
Set of functions and protocols to ease the code development
A simple boot loader copies a few assembly lines of OS Code overhead of end user
from secondary memory to Flash
 POSIX
This will then load OS Kernal
Portable Operating System interface - a std by IEEE to help in
Kernal will initiate loading of complete or required part of OS to maintaining portability between OS and application programs
primary memory
So, Any POSIX compliant application program can work on top of
Bootloaders may transfer code via serial port or JTAG port any POSIX compliant OS

Dr Binu Paul Dr Binu Paul

Tasks/Processes
20 21

 The activity of a computer/ Embedded system is to


‘run/execute’ programs.
 A program in execution is formally defined as a
process
Tasks/Processes and Threads  Set of computations processed on a Processor under the
control of the scheduling kernel of an operating system
 Tasks are generic computational blocks with
 Timing constraints
 Synchronization and communication relationships with other tasks
 The term “task”, “job”, “ process ” refers to the same
entity

Dr Binu Paul Dr Binu Paul

5
Mod4 Courtesy Prof Lyla B Das

Tasks/Processes Structure of Process


22 23

 Instance of program in execution.


 Stack- local variables and code associated with
 Multiple process can be executed simultaneously by
quickly switching from one process to the other. process
 Sequential in execution within a process  PC- next executable instruction

 Process executes concurrently Process


 Concurrent execution achieved through sharing of Stack
CPU among processes. Working registers
Status Registers
PC

Dr Binu Paul Dr Binu Paul

Memory Organisation of Processes The FIVE states of a Process/Task


24 25

Stack Memory
 The five states are named as
New(create), Ready, Running, Blocked and Exit.
Stack Memory grows
downwards

Data memory grows upwards

Data memory

Code memory

Dr Binu Paul Dr Binu Paul

6
Mod4 Courtesy Prof Lyla B Das

TASK/PROCESS - State Transitions -possibilities TASK/PROCESS - State Transitions


27 28

 New/Created state – the state at which a process


is being created.
OS recognises a process in this state but no resources allocated to
process
 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.

Dr Binu Paul Dr Binu Paul

TASK/PROCESS - State Transitions -possibilities Process/Task Control block (PCB)


29 30

Data structure maintained by OS to control process states.


 Blocked/ wait state – state where running process is pushed
Architecture is dependent on OS
into - thus temporarily suspended from execution and will not have • Process ID-
immediate access to resources …… this is called as “Pre-emption” – Unique identification for each of the process in operating
system
Process ID
• Process states –
Conditions invoking blocked state : State – Current state of process – ready ,running , waiting
 Waiting for user inputs like keyboard ( wait for an event to occur) • Pointer –
Pointer – Pointer to parent process
 Waiting for accessing shared resources
Priority • Program counter-
 If the awaited event occurs, process is pushed back to ready queue and not directly – Pointer to the address of next instruction to be executed in
to “running” process.
Program counter
• CPU reg-
 Exit/Completed State – process completes its CPU registers – Registers used by task and its values
• I/O status information –
execution [ either successful completion or abnormal termination] I/O information – List of i/o resources allocated to the process.
• Accounting info-
Accounting info – Amount of CPU used for process execution
• Scheduling information
• Priority information about the task

Dr Binu Paul Dr Binu Paul

7
Mod4 Courtesy Prof Lyla B Das

Process/Task Control block (PCB) Threads


31 32

 A thread is sometimes called a


‘lightweight process’
 In a program which goes into
execution (and becomes a
process/task), a number of
subsidiary activities may be
needed
 Each of these subsidiary activities
are handled as separate threads
 Each thread owns its status – i.e
processor Register values, PC,
Stack etc,

Dr Binu Paul Dr Binu Paul

Threads Threads and Mutlithreading concept


33 34

 Definition Is the single Stack Memory for thread 1  If all subfunctions in a task are executed sequentially,
sequential flow of execution processor utilisation may not be 100%
Stack Memory for thread 2
through the process code
 So instead of single sequential execution of task/process, it is
 Each thread belongs to exactly 1 : split into different smaller sequential pieces carrying out
process and no thread can exist :
: relatively independent subfunctionalities
outside a process
 When one thread enter a wait state another thread can br
 Types of thread: Data memory for process
queued up and avoid processor stalling- process becomes
User level threads
Code memory for process faster
Kernel level threads
 Disadv: management overhead
Memory Organisation for Threads

Dr Binu Paul Dr Binu Paul

8
Mod4 Courtesy Prof Lyla B Das

Thread Pre-emption Kernal Level Threads


35 36

 Features
If one thread is blocked , kernel can schedule another thread of
 Is the act of pre empting currently running thread same process
Slower to create and manage
temporarily
 Thread management done by kernel
 The procedure depends on whether thread is user level or  Kernel threads are Supported directly by OS
kernel level  Pre-emptive
 Kernel performs
Creation
Scheduling
management

Dr Binu Paul Dr Binu Paul

User Level Threads Threads.. continued


37 38

 Features: User level threads Kernel level threads


 Does not require kernel mode privileges
 Run on any OS
 Scheduling can be application specific Faster to create and manage Slower to create and manage
 Fast to create and manage

 User managed threads Implementation is by thread library OS supports creation of kernel threads
 Kernel is not aware of the existence of threads
i.e even if there are multiple threads in user task, KERNAL sees it as a
single thread only Generic and run on any OS Specific to the OS
 No OS intervention needed for thread switching
 Thread library contains code for- Multi-threaded applications cannot Kernel routines themselves can be
 Creating,destroying take advantage of multiprocessing.. As multithreaded
 Passing message and data between threads KERNAL is ignorant of user thread
 Scheduling thread execution existence in general
 Saving and restoring thread contexts.

Dr Binu Paul Dr Binu Paul

9
Mod4 Courtesy Prof Lyla B Das

Multithreading models Multithreading models ------ Many – to – many


39 40

 Some OS provide combined user level thread and


kernel level thread facility.
 In a combined system, multiple threads within the  User level threads allowed to be mapped to many
same process can run in parallel on multiple kernel threads
processors  This model provides Best accuracy on concurrency
 The binding of user level threads to Kernal level  Switching happens when one thread voluntarily
threads follow different approaches or model relinquishes the processor
 3 types of modelling  When one thread performs a blocking call, kernel
 Many – to – many
can schedule another thread for execution.
 Many – to – one
 One – to –one

Dr Binu Paul Dr Binu Paul

Multithreading models ----- Many – to – One Multithreading models ------ One– to – One
41 42

 Many user level threads are mapped to single kernel  One thread in user to one thread in kernel
thread  More concurrency than many- to- one model
 Thread management is done by thread library  Allows another thread to run when a thread makes
 When thread makes a blocking system call, entire blocking system call
process will be blocked.  Supports multiple threads to execute in parallel
 Only one thread can access kernel at a time, so
multiple threads are unable to run in parallel.

Dr Binu Paul Dr Binu Paul

10
Mod4 Courtesy Prof Lyla B Das

Process & Threads Process & Threads


43 44
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

Dr Binu Paul Dr Binu Paul

What is…Multitasking and Multiprocessing What is…


45 46

 At OS level multiprocessing refers to ability to  Multitasking?


execute multiple processess simultaneously
and it must multiple processors in its hardware  How does multitasking affect the user?
 In UNI processor scenario what we claim is only pseudo
parallelism
 So multiprocessing systems are in general multiprocessor as well
 Task (Process) scheduling?
 At OS level, the ability of OS to handle multiple
processes by fast switching between different
processes is Multitasking
 So every process has a virtual processor derived from physical
processor on a time shared basis under the supervision of OS
scheduler

Dr Binu Paul Dr Binu Paul

11
Mod4 Courtesy Prof Lyla B Das

What is…Multitasking? How does multitasking affect the user?


47 48

 One processor - but multiple tasks awaiting its service

 So NO one task should be allowed monopolize the processor  Multitasking is time multiplexing effect at a high rate
 Psuedo Parallelism by time sharing – each task gets its time a  User is unaware of task switching happening at
chunk of it and then task switching is done to relinquish its claim processor level
over resources  User - made to believe – that all tasks are going on
 TCB has the task context {information} to help pick up when a in parallel
relinquished task gets its next turn.  As number of tasks increase, “system will slowdown”

Dr Binu Paul Dr Binu Paul

Task (Process) scheduling? CPU and I/O bound tasks


49 50

 Role of Scheduler is to give the resources to a requesting


task, ensuring zero wastage of resources and processor
time
 Policy must ensure that all tasks/processes are given
proper attention

Dr Binu Paul Dr Binu Paul

12
Mod4 Courtesy Prof Lyla B Das

Selection of a Scheduling Algorithm


51 52

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

Dr Binu Paul Dr Binu Paul

Scheduling Algorithms-Assumptions Scheduling Algorithms -Types


53 54

Scheduling

Non Pre-
Pre-emptive
emptive

Pre-emptive
Shortest Job Pre-emptive SJN/Shortest
Co operative Priority Based Round robin
Next SJN Priority Remaining
Time

Dr Binu Paul Dr Binu Paul

13
Mod4 Courtesy Prof Lyla B Das

Non-preemptive Methods of Scheduling


55

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)
Dr Binu Paul Dr Binu Paul 56

T1 300
FCFS
T2 125
Solution Shortest Job Next (SJN) /Shortest Job First
T3 400
57 58
T4 150

T5 100

 Here the method is to queue the tasks such that the


one with the shortest service time gets to execute
first .
 But the problem is that, 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.

Dr Binu Paul Dr Binu Paul

14
Mod4 Courtesy Prof Lyla B Das

T1 300
T2 125
T3 400
T4 150
T5 100

Dr Binu Paul 59 Dr Binu Paul 60

T1 300

T1 300
Solution T2 125

T2 125 T3 400

T3 400 T4 150

T4 150 T5 100

T5 100 T6 250

T6 250 T7 200

T7 200

Dr Binu Paul 61 Dr Binu Paul 62

15
Mod4 Courtesy Prof Lyla B Das

Priority-based Scheduling
63

 In such a system, tasks have priorities which are


represented in terms of numbers .

 The convention is to have 0 to 255 as the numbers


representing priorities, with 0 representing the
highest priority, and higher numbers indicating
lower priorities .

Dr Binu Paul Dr Binu Paul 64

Solution
T1 300 5
T2 125 3
T3 400 2
T4 150 12
T5 100 15

Dr Binu Paul 65 Dr Binu Paul 66

16
Mod4 Courtesy Prof Lyla B Das

T1 300 5 Pre-emptive Scheduling Strategies


T2 125 3
68
T3 400 2

 In this set, when a task is running (i.e. using the


T4 150 12
T5 100 15
T6 120 0 processor), it is pushed out from the ‘running’ state
T7
T8
80
3500
4
6
to the ‘ready’ state and another task from the ready
queue is taken up.
 Task has been pre-empted (removed and replaced).
 Various strategies are …….

Dr Binu Paul 67 Dr Binu Paul

1. Round Robin Scheduling


69

 Here, time slices are defined.


 Suppose there are n tasks in a system, each of them
is allowed to execute for a period equal to the time
slice.
 After this, the next task gets its turn, but can use the
CPU only for a time equal to the defined time slice.
 This is also called a time sharing or time slice system

Dr Binu Paul Dr Binu Paul 70

17
Mod4 Courtesy Prof Lyla B Das

T1 150
T2 100
T3 200
T4 50

Dr Binu Paul 71 Dr Binu Paul 72

T1 300 2.Pre-emptive Priority


T2 125
T3 400 74
T4 150
T5 100  In this method, at any time it should be ensured that
it is the highest priority task in the ready queue that
should be running.
 If, at any time, a task with a higher priority than the
one that is currently running enters the ready queue,
the current task is pre-empted and the new one
is taken up.

Dr Binu Paul 73 Dr Binu Paul

18
Mod4 Courtesy Prof Lyla B Das

T1 300 5
Solution T2 125 3
T3 400 2
T4 150 12
T5 100 15

T6* 75 1

Dr Binu Paul 75 Dr Binu Paul 76

3.Pre-emptive SJN/Shortest Remaining


Time (SRT)
77

 Normally the scheduling is in the order of increasing


service times. Thus, tasks with the shortest service times
are executed earlier.

 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.

Dr Binu Paul Dr Binu Paul 78

19
Mod4 Courtesy Prof Lyla B Das

Solution T1 300
T2 125 END of presentation
T3 400
T4 150
T5 100

T6 50

Dr Binu Paul 79 Dr Binu Paul 80

20

You might also like