Professional Documents
Culture Documents
PROPRIETARY MATERIAL. © 2009 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
1
@ McGraw-Hill Education
2
@ McGraw-Hill Education
PROPRIETARY MATERIAL. © 2009 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
3
@ McGraw-Hill Education
6
@ McGraw-Hill Education
✔ Process Management
✔ Deals with managing the processes/tasks.
✔ Includes setting up the memory space for the
process, loading the process’s code into
memory space, allocating system resources,
✔ scheduling and managing the execution of the
process,
✔ Setting up and managing the Process Control
Block (PCB)
✔ Inter Process Communication and
synchronisation, process termination/deletion,
etc. 8
@ McGraw-Hill Education
9
@ McGraw-Hill Education
10
@ McGraw-Hill Education
12
@ McGraw-Hill Education
✔ Protection
✔ Through multiple users with different levels of
access permissions
✔ Windows XP- ‘Administrator’, ‘Standard’,
Restricted’…
✔ Interrupt Handling
✔ Kernel provides handler mechanism for all ext./int
interrupts generated by the system
13
@ McGraw-Hill Education
16
@ McGraw-Hill Education
17
@ McGraw-Hill Education
19
@ McGraw-Hill Education
23
@ McGraw-Hill Education
24
@ McGraw-Hill Education
30
@ McGraw-Hill Education
31
@ McGraw-Hill Education
33
@ McGraw-Hill Education
34
@ McGraw-Hill Education
35
@ McGraw-Hill Education
37
@ McGraw-Hill Education
38
@ McGraw-Hill Education
40
@ McGraw-Hill Education
42
@ McGraw-Hill Education
Designing with RTOS
Process States & State Transition
• Blocked State/Wait State: Refers to a state where a running
process is temporarily suspended from execution and does not
have immediate access to resources. The blocked state might
have invoked by various conditions like- the process enters a
wait state for an event to occur (E.g. Waiting for user inputs such
as keyboard input) or waiting for getting access to a shared
resource like semaphore, mutex etc
• Completed State: A state where the process completes its
execution
✔ The transition of a process from one state to another is known as
‘State transition’
✔ When a process changes its state from Ready to running or from
running to blocked or terminated or from blocked to running, the
CPU allocation for the process may also change 43
@ McGraw-Hill Education
44
@ McGraw-Hill Education
45
The Concept of multithreading
@ McGraw-Hill Education
46
@ McGraw-Hill Education
47
@ McGraw-Hill Education
49
@ McGraw-Hill Education
Designing with RTOS
•Java Threads: Java threads are the threads supported by Java programming
Language. The java thread class ‘Thread’ is defined in the package ‘java.lang’.
This package needs to be imported for using the thread creation functions
supported by the Java thread class. There are two ways of creating threads in
Java: Either by extending the base ‘Thread’ class or by implementing an
interface. Extending the thread class allows inheriting the methods and variables
of the parent class (Thread class) only whereas interface allows a way to achieve
the requirements for a set of classes
import java.lang.*; Java Thread Creation
public class MyThread extends Thread
{ public void run()
{
System.out.println("Hello from MyThread!");
}
public static void main(String args[])
{
(new MyThread()).start();
}
50
}
@ McGraw-Hill Education
Designing with RTOS
User & Kernel level threads
51
@ McGraw-Hill Education
Designing with RTOS
User & Kernel level threads
• Kernel Level/System Level Thread: Kernel level threads are
individual units of execution, which the OS treats as separate
threads. The OS interrupts the execution of the currently running
kernel thread and switches the execution to another kernel thread
based on the scheduling policies implemented by the OS.
✔ The execution switching (thread context switching) of user level
threads happen only when the currently executing user level
thread is voluntarily blocked. Hence, no OS intervention and
system calls are involved in the context switching of user level
threads. This makes context switching of user level threads very
fast.
✔ Kernel level threads involve lots of kernel overhead and involve
system calls for context switching. However, kernel threads
maintain a clear layer of abstraction and allow threads to use
52
system calls independently
@ McGraw-Hill Education
53
@ McGraw-Hill Education
Thread Process
Thread is a single unit of Process is a program in execution
execution and is part of process. and contains one or more threads.
A thread does not have its own Process has its own code memory,
data memory and heap memory. data memory and stack memory.
It shares the data memory and
heap memory with other threads
of the same process.
54
@ McGraw-Hill Education
57
@ McGraw-Hill Education
58
@ McGraw-Hill Education
59
@ McGraw-Hill Education
60
@ McGraw-Hill Education
62
@ McGraw-Hill Education
65
@ McGraw-Hill Education
66
@ McGraw-Hill Education
67
@ McGraw-Hill Education
✔ Allocates CPU time to the processes based on the order in which they enters the
‘Ready’ queue
✔ The first entered process is serviced first
✔ It is same as any real world application where queue systems are used; E.g.
Ticketing
Drawbacks:
✔ Favors monopoly of process. A process, which does not contain any I/O
operation, continues its execution until it finishes its task
✔ In general, FCFS favors CPU bound processes and I/O bound processes may have to
wait until the completion of CPU bound process, if the currently executing process is a
CPU bound process. This leads to poor device utilization.
✔ The average waiting time is not minimal for FCFS scheduling algorithm
68
@ McGraw-Hill Education
Assuming the CPU is readily available at the time of arrival of P1, P1 starts
executing without any waiting in the ‘Ready’ queue. Hence the waiting time for
P1 is zero.
69
@ McGraw-Hill Education
✔ Allocates CPU time to the processes based on the order in which they are
entered in the ‘Ready’ queue
✔ The last entered process is serviced first
✔ LCFS scheduling is also known as Last In First Out (LIFO) where the process,
which is put last into the ‘Ready’ queue, is serviced first
Drawbacks:
✔ Favors monopoly of process. A process, which does not contain any I/O
operation, continues its execution until it finishes its task
✔ In general, LCFS favors CPU bound processes and I/O bound processes may
have to wait until the completion of CPU bound process, if the currently
executing process is a CPU bound process. This leads to poor device utilization.
✔ The average waiting time is not minimal for LCFS scheduling algorithm
71
@ McGraw-Hill Education
Initially there is only P1 available in the Ready queue and the scheduling sequence will be P1, P3, P2.
P4 enters the queue during the execution of P1 and becomes the last process entered the ‘Ready’
queue. Now the order of execution changes to P1, P4, P3, and P2 as given below.
72
@ McGraw-Hill Education
Turn Around Time (TAT) for P1 = 10 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P4 = 11 ms (Time spent in Ready Queue + Execution Time = (Execution Start Time – Arrival
Time) + Estimated Execution Time = (10-5) + 6 = 5 + 6)
Turn Around Time (TAT) for P3 = 23 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P2 = 28 ms (Time spent in Ready Queue + Execution Time)
Average Turn Around Time = (Turn Around Time for all processes) / No. of Processes
= (Turn Around Time for (P1+P4+P3+P2)) / 4
= (10+11+23+28)/4 = 72/4
= 18 milliseconds
73
@ McGraw-Hill Education
✔ Allocates CPU time to the processes based on the execution completion time
for tasks
✔ The average waiting time for a given set of processes is minimal in SJF
scheduling
✔ Optimal compared to other non-preemptive scheduling like FCFS
Drawbacks:
✔ A process whose estimated execution completion time is high may not get a
chance to execute if more and more processes with least estimated execution
time enters the ‘Ready’ queue before the process with longest estimated
execution time starts its execution
✔ May lead to the ‘Starvation’ of processes with high estimated completion time
✔ Difficult to know in advance the next shortest process in the ‘Ready’ queue for
scheduling since new processes with different estimated execution time keep
entering the ‘Ready’ queue at any point of time.
74
@ McGraw-Hill Education
• Three processes with process IDs P1, P2, P3 with estimated completion time 10, 5, 7 milliseconds
respectively enters the ready queue together in the order P1, P2, P3 (Assume only P1 is present in
the ‘Ready’ queue when the scheduler picks up it and P2, P3 entered ‘Ready’ queue after that). Now
a new process P4 with estimated completion time 6ms enters the ‘Ready’ queue after 5ms of
scheduling P1. Calculate the waiting time and Turn Around Time (TAT) for each process and the
Average waiting time and Turn Around Time (Assuming there is no I/O waiting for the
processes).Assume all the processes contain only CPU operation and no I/O operations are involved.
Initially there is only P1 available in the Ready queue and the scheduling sequence will be P1, P3, P2.
P4 enters the queue during the execution of P1 and becomes the last process entered the ‘Ready’
queue. Now the order of execution changes to P1, P4, P3, and P2 as given below.
75
@ McGraw-Hill Education
Turn Around Time (TAT) for P1 = 10 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P4 = 11 ms (Time spent in Ready Queue + Execution Time = (Execution Start Time – Arrival
Time) + Estimated Execution Time = (10-5) + 6 = 5 + 6)
Turn Around Time (TAT) for P3 = 23 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P2 = 28 ms (Time spent in Ready Queue + Execution Time)
Average Turn Around Time = (Turn Around Time for all processes) / No. of Processes
= (Turn Around Time for (P1+P4+P3+P2)) / 4
= (10+11+23+28)/4 = 72/4
= 18 milliseconds
76
@ McGraw-Hill Education
77
@ McGraw-Hill Education
• Three processes with process IDs P1, P2, P3 with estimated completion time 10, 5, 7 milliseconds
and priorities 0, 3, 2 (0- highest priority, 3 lowest priority) respectively enters the ready queue
together. Calculate the waiting time and Turn Around Time (TAT) for each process and the
Average waiting time and Turn Around Time (Assuming there is no I/O waiting for the processes)
in priority based scheduling algorithm.
• The scheduler sorts the ‘Ready’ queue based on the priority and schedules the process with the
highest priority (P1 with priority number 0) first and the next high priority process (P3 with
priority number 2) as second and so on. The order in which the processes are scheduled for
execution is represented as
78
@ McGraw-Hill Education
Average waiting time = (Waiting time for all processes) / No. of Processes
= (Waiting time for (P1+P3+P2)) / 3
= (0+10+17)/3 = 27/3
= 9 milliseconds
Turn Around Time (TAT) for P1 = 10 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P3 = 17 ms (-Do-)
Turn Around Time (TAT) for P2 = 22 ms (-Do-)
Average Turn Around Time = (Turn Around Time for all processes) / No. of Processes
= (Turn Around Time for (P1+P3+P2)) / 3
= (10+17+22)/3 = 49/3
= 16.33 milliseconds
79
@ McGraw-Hill Education
80
@ McGraw-Hill Education
82
@ McGraw-Hill Education
• Three processes with process IDs P1, P2, P3 with estimated completion time 10, 5, 7 milliseconds
respectively enters the ready queue together. A new process P4 with estimated completion time
2ms enters the ‘Ready’ queue after 2ms. Assume all the processes contain only CPU operation
and no I/O operations are involved.
• At the beginning, there are only three processes (P1, P2 and P3) available in the ‘Ready’ queue
and the SRT scheduler picks up the process with the Shortest remaining time for execution
completion (In this example P2 with remaining time 5ms) for scheduling. Now process P4 with
estimated execution completion time 2ms enters the ‘Ready’ queue after 2ms of start of execution
of P2. The processes are re-scheduled for execution in the following order
83
@ McGraw-Hill Education
Waiting Time for P2 = 0 ms + (4 -2) ms = 2ms (P2 starts executing first and is interrupted by P4 and has to wait till the completion of
P4 to get the next CPU slot)
Waiting Time for P4 = 0 ms (P4 starts executing by preempting P2 since the execution time for completion of P4 (2ms) is less than
that of the Remaining time for execution completion of P2 (Here it is 3ms))
Waiting Time for P3 = 7 ms (P3 starts executing after completing P4 and P2)
Waiting Time for P1 = 14 ms (P1 starts executing after completing P4, P2 and P3)
Average waiting time = (Waiting time for all the processes) / No. of Processes
= (Waiting time for (P4+P2+P3+P1)) / 4
= (0 + 2 + 7 + 14)/4 = 23/4
= 5.75 milliseconds
Turn Around Time (TAT) for P2 = 7 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P4 = 2 ms
(Time spent in Ready Queue + Execution Time = (Execution Start Time – Arrival Time) + Estimated Execution Time = (2-2) + 2)
Turn Around Time (TAT) for P3 = 14 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P1 = 24 ms (Time spent in Ready Queue + Execution Time)
Average Turn Around Time = (Turn Around Time for all the processes) / No. of Processes
= (Turn Around Time for (P2+P4+P3+P1)) / 4
= (7+2+14+24)/4 = 47/4
= 11.75 milliseconds
84
@ McGraw-Hill Education
• Three processes with process IDs P1, P2, P3 with estimated completion time 6, 4, 2 milliseconds
respectively, enters the ready queue together in the order P1, P2, P3. Calculate the waiting time and
Turn Around Time (TAT) for each process and the Average waiting time and Turn Around Time
(Assuming there is no I/O waiting for the processes) in RR algorithm with Time slice= 2ms.
• The scheduler sorts the ‘Ready’ queue based on the FCFS policy and picks up the first process P1
from the ‘Ready’ queue and executes it for the time slice 2ms. When the time slice is expired, P1 is
preempted and P2 is scheduled for execution. The Time slice expires after 2ms of execution of P2.
Now P2 is preempted and P3 is picked up for execution. P3 completes its execution within the time
slice and the scheduler picks P1 again for execution for the next time slice. This procedure is
repeated till all the processes are serviced. The order in which the processes are scheduled for
execution is represented as
86
@ McGraw-Hill Education
Waiting Time for P1 = 0 + (6-2) + (10-8) = 0+4+2= 6ms (P1 starts executing first and waits for two time slices to get
execution back and again 1 time slice for getting CPU time)
Waiting Time for P2 = (2-0) + (8-4) = 2+4 = 6ms (P2 starts executing after P1 executes for 1 time slice and waits for two
time slices to get the CPU time)
Waiting Time for P3 = (4 -0) = 4ms (P3 starts executing after completing the first time slices for P1 and P2 and completes its
execution in a single time slice.)
Average waiting time = (Waiting time for all the processes) / No. of Processes
= (Waiting time for (P1+P2+P3)) / 3
= (6+6+4)/3 = 16/3
= 5.33 milliseconds
Turn Around Time (TAT) for P1 = 12 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P2 = 10 ms (-Do-)
Turn Around Time (TAT) for P3 = 6 ms (-Do-)
Average Turn Around Time = (Turn Around Time for all the processes) / No. of Processes
= (Turn Around Time for (P1+P2+P3)) / 3
= (12+10+6)/3 = 28/3
= 9.33 milliseconds
87
@ McGraw-Hill Education
✔ Same as that of the non-preemptive priority based scheduling except for the
switching of execution between tasks
✔ In preemptive priority based scheduling, any high priority process entering the
‘Ready’ queue is immediately scheduled for execution whereas in the
non-preemptive scheduling any high priority process entering the ‘Ready’
queue is scheduled only after the currently executing process completes its
execution or only when it voluntarily releases the CPU
✔ The priority of a task/process in preemptive priority based scheduling is
indicated in the same way as that of the mechanisms adopted for
non-preemptive multitasking
88
@ McGraw-Hill Education
• Three processes with process IDs P1, P2, P3 with estimated completion time 10, 5, 7 milliseconds
and priorities 1, 3, 2 (0- highest priority, 3 lowest priority) respectively enters the ready queue
together. A new process P4 with estimated completion time 6ms and priority 0 enters the ‘Ready’
queue after 5ms of start of execution of P1. Assume all the processes contain only CPU operation
and no I/O operations are involved.
• At the beginning, there are only three processes (P1, P2 and P3) available in the ‘Ready’ queue
and the scheduler picks up the process with the highest priority (In this example P1 with priority
1) for scheduling. Now process P4 with estimated execution completion time 6ms and priority 0
enters the ‘Ready’ queue after 5ms of start of execution of P1. The processes are re-scheduled for
execution in the following order
89
@ McGraw-Hill Education
Waiting Time for P1 = 0 + (11-5) = 0+6 =6 ms (P1 starts executing first and gets preempted by P4 after 5ms and
again gets the CPU time after completion of P4)
Waiting Time for P4 = 0 ms (P4 starts executing immediately on entering the ‘Ready’ queue, by preempting P1)
Waiting Time for P3 = 16 ms (P3 starts executing after completing P1 and P4)
Waiting Time for P2 = 23 ms (P2 starts executing after completing P1, P4 and P3)
Average waiting time = (Waiting time for all the processes) / No. of Processes
= (Waiting time for (P1+P4+P3+P2)) / 4
= (6 + 0 + 16 + 23)/4 = 45/4
= 11.25 milliseconds
Turn Around Time (TAT) for P1 = 16 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P4 = 6ms (Time spent in Ready Queue + Execution Time = (Execution Start Time –
Arrival Time) + Estimated Execution Time = (5-5) + 6 = 0 + 6)
Turn Around Time (TAT) for P3 = 23 ms (Time spent in Ready Queue + Execution Time)
Turn Around Time (TAT) for P2 = 28 ms (Time spent in Ready Queue + Execution Time)
Average Turn Around Time = (Turn Around Time for all the processes) / No. of Processes
= (Turn Around Time for (P2+P4+P3+P1)) / 4
= (16+6+23+28)/4 = 73/4
= 18.25 milliseconds
90
@ McGraw-Hill Education
91
@ McGraw-Hill Education
93
@ McGraw-Hill Education
• Co-operating Processes: In the co-operating interaction model one process requires the
inputs from other processes to complete its execution.
• Competing Processes: The competing processes do not share anything among
themselves but they share the system resources. The competing processes compete for
the system resources such as file, display device etc
94
@ McGraw-Hill Education
95
@ McGraw-Hill Education
96
@ McGraw-Hill Education
10
1
@ McGraw-Hill Education
// Maps a view of the memory mapped object to the address space of the calling process
10
3
@ McGraw-Hill Education
10
4
@ McGraw-Hill Education
10
5
@ McGraw-Hill Education
10
6
@ McGraw-Hill Education
10
9
@ McGraw-Hill Education
11
0
@ McGraw-Hill Education
11
1
@ McGraw-Hill Education
PROPRIETARY MATERIAL. © 2009 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
11
2
@ McGraw-Hill Education
11
3
@ McGraw-Hill Education
11
6
@ McGraw-Hill Education
11
7
@ McGraw-Hill Education
11
8
@ McGraw-Hill Education
Process A holds a resource ‘x’ and it wants a resource ‘y’ held by Process B.
Process B is currently holding resource ‘y’ and it wants the resource ‘x’ which
is currently held by Process A. Both hold the respective resources and they
compete each other to get the resource held by the respective processes
Deadlock Visualization 11
Scenarios leading to Deadlock
9
@ McGraw-Hill Education
12
0
@ McGraw-Hill Education
12
2
@ McGraw-Hill Education
12
3
@ McGraw-Hill Education
12
4
@ McGraw-Hill Education
❑ Starvation
In the task synchronization issue context, starvation is the
condition in which a process does not get the resources required to
continue its execution for a long time. As time progresses the
process starves on resource. Starvation may arise due to various
conditions like byproduct of preventive measures of deadlock,
scheduling policies favoring high priority tasks and tasks with
shortest execution time etc.
12
7
@ McGraw-Hill Education
12
8
@ McGraw-Hill Education
12
9
@ McGraw-Hill Education
13
1
@ McGraw-Hill Education
13
2
@ McGraw-Hill Education
13
3
@ McGraw-Hill Education
13
7
@ McGraw-Hill Education
13
Priority Inversion Avoidance Policy: Priority Inheritance 8
@ McGraw-Hill Education
A priority is associated with each shared resource. The priority associated to each
resource is the priority of the highest priority task which uses this shared resource.
This priority level is called Ceiling priority. Whenever a task accesses a shared
resource, the scheduler elevates the priority of the task to that of the ceiling priority
of the resource. If the task which accesses the shared resource is a low priority task,
its priority is temporarily boosted to the priority of the highest priority task to which
the resource is also shared. This eliminates the pre-emption of the task by other
medium priority tasks leading to priority inversion. The priority of the task is
brought back to the original level once the task completes the accessing of the shared
resource. ‘Priority Ceiling’ brings the added advantage of sharing resources without
the need for synchronization techniques like locks. Since the priority of the task
accessing a shared resource is boosted to the highest priority of the task among
which the resource is shared, the concurrent access of shared resource is
automatically handled. Another advantage of ‘Priority Ceiling’ technique is that all
the overheads are at compile time instead of run-time 13
9
@ McGraw-Hill Education
14
1
@ McGraw-Hill Education
14
2
@ McGraw-Hill Education
14
3
@ McGraw-Hill Education
PROPRIETARY MATERIAL. © 2009 The McGraw-Hill Companies, Inc. All rights reserved. No part of this PowerPoint slide may be displayed, reproduced or distributed
in any form or by any means, without the prior written permission of the publisher, or used beyond the limited distribution to teachers and educators permitted by McGraw-Hill
for their individual course preparation. If you are a student using this PowerPoint slide, you are using it without permission.
14
4
@ McGraw-Hill Education
14
6
@ McGraw-Hill Education
14
7
@ McGraw-Hill Education
15
1
@ McGraw-Hill Education
15
2
@ McGraw-Hill Education
CMPXCHG dest,src
15
3
@ McGraw-Hill Education
15
4
@ McGraw-Hill Education
#include "stdafx.h"
#include <intrin.h>
#include <windows.h>
void child_thread(void)
{
//Inside the child thread of a process
//Check the lock for availability & acquire the lock if available.
//The lock can be set by any other threads
while (_InterlockedCompareExchange (&bFlag, 1, 0) == 1);
//Check the lock for availability & acquire the lock if available.
//The lock can be set by any other threads
while (_InterlockedCompareExchange (&bFlag, 1, 0) == 1);
004113DE mov ecx,1
004113E3 mov edx,offset bFlag (417178h)
004113E8 xor eax,eax
004113EA lock cmpxchg dword ptr [edx],ecx
004113EE cmp eax,1
004113F1 jne child_thread+35h (4113F5h)
004113F3 jmp child_thread+1Eh (4113DEh)
//Rest of the source code dealing with shared resource access
15
//........................................................... 7
@ McGraw-Hill Education
✔ The lock based mutual exclusion implementation always checks the state of a lock and
waits till the lock is available. This keeps the processes/threads always busy and forces
the processes/threads to wait for the availability of the lock for proceeding further.
✔ The ‘Busy waiting’ technique can also be visualized as a lock around which the
process/thread spins, checking for its availability
✔ Spin locks are useful in handling scenarios where the processes/threads are likely to be
blocked for a shorter period of time on waiting the lock, as they avoid OS overheads on
context saving and process re-scheduling
✔ Another drawback of Spin lock based synchronization is that if the lock is being held for
a long time by a process and if it is preempted by the OS, the other threads waiting for
this lock may have to spin a longer time for getting it.
✔ The ‘Busy waiting’ mechanism keeps the process/threads always active, performing a
task which is not useful and leads to the wastage of processor time and high power
consumption.
15
8
@ McGraw-Hill Education
15
9
@ McGraw-Hill Education
16
0
@ McGraw-Hill Education
16
1
@ McGraw-Hill Education
16
2
@ McGraw-Hill Education
16
3
@ McGraw-Hill Education
16
4
@ McGraw-Hill Education
16
8
@ McGraw-Hill Education
17
1
@ McGraw-Hill Education
ES Development Environment
• Various Tools used
• Various steps followed
• Input/Output files
17
2
@ McGraw-Hill Education
• Introduction
– Application programs are typically developed, compiled, and run on host system
– Embedded programs are targeted to a target processor (different from the development/host
processor and operating environment) that drives a device or controls
– What tools are needed to develop, test, and locate embedded software into the target processor
and its operating environment?
• Distinction
– Host: Where the embedded software is developed, compiled, tested, debugged, optimized, and
prior to its translation into target device. (Because the host has keyboards, editors, monitors,
printers, more memory, etc. for development, while the target may have not of these
capabilities for developing the software.)
– Target: After development, the code is cross-compiled, translated – cross-assembled, linked
(into target processor instruction set) and located into the target
17
3
@ McGraw-Hill Education
• 9.1 Introduction – 1
• Cross-Compilers –
– Native tools are good for host, but to port/locate embedded code to target, the host must have a tool-chain
that includes a cross-compiler, one which runs on the host but produces code for the target processor
– Cross-compiling doesn’t guarantee correct target code due to (e.g., differences in word sizes, instruction
sizes, variable declarations, library functions)
17
4
@ McGraw-Hill Education
Development Tools
17
5
@ McGraw-Hill Education
Development Tools
• Software Tools
– Compiler, Assembler, Linker
– Librarian/ Archives
– CPLD (Complex Programmable Logic Devices) , FPGA
Compilers
– Schematics Generation, PCB Layout Design – EDA Tools,
Electronic Design Automation
– etc……
17
6
@ McGraw-Hill Education
Development Tools
• Hardware Tools
– Device Programmers
• Mainly used to download code to memory on board
• Uses many types interface serial , parallel, JTAG
• An aid to make the embedded system run independently
– CPU Simulators
• Application program which runs on the host machine
• Not connected to any target but will simulate the target CPU
instruction execution on host machine
• Can be used only for logical source level debugging
– CPU Emulators
• Generally uses JTAG, older versions use parallel & serial
interfaces
• Emulates the processor on the host machine
• Is very useful in source level debugging 17
7
@ McGraw-Hill Education
Development Tools
• Hardware Tools
– Multimeter
• Used for basic electrical measurements like voltage and current
measurements
• Can be used as a debugging tool to check continuity in hardware
• Some high end multimeters provide scope facility for low
frequencies
– Oscilloscope
• Used to measure signals - A powerful hardware debugging tool
• Most of the hardware issues can be resolved using a oscilloscope
• Mainly of 2 types storage and real time oscilloscopes
17
8
@ McGraw-Hill Education
17
9
@ McGraw-Hill Education
18
0
@ McGraw-Hill Education
Development Tools
18
2
@ McGraw-Hill Education
Development Tools
Software Development
Flow – Embedded
Application
Assembly
CPU
18
3
@ McGraw-Hill Education
• Address Resolution –
– Native Linker: produces host machine code on the hard-drive (in a
named file), which the loader loads into RAM, and then schedules (under
the OS control) the program to go to the CPU.
18
4
@ McGraw-Hill Education
18
5
@ McGraw-Hill Education
– Locator: produces target machine code (which the locator glues into the
RTOS) and the combined code (called map) gets copied into the target
ROM. The locator doesn’t stay in the target environment, hence all
addresses are resolved, guided by locating-tools and directives, prior to
running the code (See Figs)
18
6
@ McGraw-Hill Education
18
7
@ McGraw-Hill Education
18
8
@ McGraw-Hill Education
• Unchanging embedded program (binary code) and constants must be kept in ROM to be
remembered even on power-off
• Changing program segments (e.g., variables) must be kept in RAM
• Chain tools separate program parts using segments concept
• Chain tools (for embedded systems) also require a ‘start-up’ code to be in a separate
segment and ‘located’ at a microprocessor-defined location where the program starts
execution
• Some cross-compilers have default or allow programmer to specify segments for
program parts, but cross-assemblers have no default behavior and programmer must
specify segments for program parts
18
9
@ McGraw-Hill Education
19
0
@ McGraw-Hill Education
19
1
@ McGraw-Hill Education
19
2
@ McGraw-Hill Education
• Segments with initialized values in ROM are shadowed (or copied into RAM) for correct reset of
initialized variables, in RAM, each time the system comes up (esp. for initial values that are take
#define constants, and which can be changed)
• In C programs, a host compiler may set all uninitialized variable to zero or null, but this is not
generally the case for embedded software cross-compilers (unless the startup code in ROM does so
• If part(s) of a constant string is(are) expected to be changed during run-time, the cross-compiler
must generate a code to allow ‘shadowing’ of the string from ROM
19
3
@ McGraw-Hill Education
• An ‘advanced’ locator is capable of running (albeit slowly) a startup code in ROM, which (could
decompress and) load the embedded code from ROM into RAM to execute quickly since RAM is
faster, especially for RISC microprocessors
19
4
@ McGraw-Hill Education
19
5
@ McGraw-Hill Education
19
6
@ McGraw-Hill Education
• Moving maps into ROM or PROM, is to create a ROM using hardware tools or a PROM
programmer (for small and changeable software, during debugging)
• If PROM programmer is used (for changing or debugging software), place PROM in a socket
(which makes it erasable – for EPROM, or removable/replaceable) rather than ‘burnt’ into circuitry
• PROM’s can be pushed into sockets by hand, and pulled using a chip puller
• The PROM programmer must be compatible with the format (syntax/semantics) of the Map
19
7
@ McGraw-Hill Education
• ROM Emulators – Another approach is using a ROM emulator (hardware) which emulates the
target system, has all the ROM circuitry, and a serial or network interface to the host system. The
locator loads the Map into the emulator, especially, for debugging purposes.
• Software on the host that loads the Map file into the emulator must understand (be compatible
with) the Map’s syntax/semantics
19
8
@ McGraw-Hill Education
19
9
@ McGraw-Hill Education
• No need to pull the flash (unlike PROM) for debugging different embedded code
• Transferring code into flash (over a network) is faster and hassle-free
• New versions of embedded software (supplied by vendor) can be loaded into flash memory by customers over a
network - Requires a) protecting the flash programmer, saving it in RAM and executing from there, and reloading into
flash after new version is written and b) the ability to complete loading new version even if there are crashes and
protecting the startup code as in (a)
• Modifying and/or debugging the flash programming software requires moving it into RAM, modify/debug, and
reloading it into target flash memory using above methods
20
0
@ McGraw-Hill Education
Development Tools
Compiler,Assembler, Peripherals,…
20
1