Transcript lect_2

1.
2.
3.
Single-Processor Systems
Multiprocessor Systems
Clustered Systems
1- Single general-purpose processor
 On a single-processor system, there is
one main CPU capable of executing a
general-purpose instruction set,
including instructions from user
processes.
 Single-processor systems are the most
common.
2- Multiprocessors systems :
are growing in use and importance
 known as parallel systems or tightly-coupled
systems.
 The system have two or more processors in close
communication and sharing the computer bus
memory and peripheral devices.
 Advantages include
1. Increased throughput
2. Economy of scale
3. Increased reliability – graceful degradation or
fault tolerance
2- Multiprocessors systems :
Increased throughput:




By increasing the number of processors, we expect to get more
work done in less time.
The speed-up ratio with N processors is not N x speed of each
one, however, it is less than N x speed of each one.
When multiple processors cooperate on a task, a certain
amount of overhead is incurred in keeping all the parts
working correctly. This overhead, plus using the shared
resources, low the expected gain from additional processors.
Similarly, N programmers working closely together do not
produce N times the amount of work a single programmer
would produce.
2- Multiprocessors systems :
Economy of scale:

Multiprocessor systems can cost less than equivalent multiple
single-processor systems, because they can share peripherals,
mass storage, and power supplies. If several programs operate
on the same set of data, it is cheaper to store those data on one
disk and to have all the processors share them than to have
many computers with local disks and many copies of the data.

2- Multiprocessors systems :
Increased reliability:


If functions can be distributed properly among
several processors, then the failure of one
processor will not halt the system, only slow it
down.
If we have ten processors and one fails, then
each of the remaining nine processors can pick
up a share of the work of the failed processor.
Thus, the entire system runs only 10 percent
slower, rather than failing altogether.

Two types
1. Asymmetric Multiprocessing
2. Symmetric Multiprocessing
1- Asymmetric Multiprocessing
 In which each processor is assigned to a specific task.
 A master processor controls the system.
 The other processors either look to the master for
instruction (Master-slave relationship) or have predefined
tasks.
2- Symmetric Multiprocessing
 The most common systems use symmetric
multiprocessing (SMP).
 Each processor performs all tasks within the operating
system.
 No master–slave relationship exists between processors
 All processors are peers.
 The
difference
between
symmetric
and
asymmetric
multiprocessing may result from either hardware or software.

Special hardware can differentiate the multiple processors or
the software can be written to allow only one master and
multiple slaves.
 For instance, Sun’s operating system SunOS Version 4
provided asymmetric multiprocessing, whereas Version 5
(Solaris) is symmetric on the same hardware.


A recent trend in CPU design is to include
multiple computing cores (a core is the basic
computation (processing) unit of the CPU - it
can run a single program context) on a single
chip.
In the above figure, we show a dual-core design with two cores
on the same chip. In this design, each core has its own register
set as well as its own local cache; other designs might use a
shared cache or a combination of local and shared caches
The CPU design may have multiprocessor
cores per chip or multiple chips with single
cores.
 multiprocessor cores per chip is more efficient
because one-chip communication is faster
than multiple chips communication.
 In addition, one chip with multiple cores uses
significantly less power than multiple singlecore chips.
 Multicore systems are especially well suited
for server systems such as database and Web
servers.

3- Clustered Systems




Definition : The clustered computers
share storage and are closely linked via
LAN networking.
Like multiprocessor systems, but multiple
systems working together.
A clustered system uses multiple CPUs to
complete a task.
It is different from a parallel system in that
a clustered system consists of two or more
individual systems tied together.
17
Provides a high-availability: that is, a service will
continue even if one or more systems in the cluster
fail. Each node can monitor one or more nodes over
the LAN.
 The monitored machine can fail in some cases.
 If the monitored machine fails, the monitoring
machine can take ownership of its storage and restart
the applications that were running on the failed
machine. The users and clients of the applications see
only a brief interruption of a service.

19
The clustered system can be of the following forms:
 Asymmetric clustering: In this form, one machine is in hot
standby mode and other machines are running the application.
The hot standby machine performs nothing. It only monitors
the server. It becomes the active server, if the server fails.
 Symmetric clustering In this mode, two or more machines run
the applications. They also monitor each other at the same
time. This mode is more efficient because it uses all available
machines. It can be used only if multiple applications are
available to be executed.

High-Performance Computing (HPC)
 Applications must be written to use parallelization.
20
21



Multiprogramming
Multiprocessing
Multitasking
22
Multiprogramming:
 A single program cannot, in general, keep either the
CPU or the I/O devices busy at all times
 Multiprogramming increases CPU utilization by
organizing jobs (code and data) so that the CPU always
has one to execute.
 Multiprogramming is a form of parallel processing in
which several programs are run at the same time on a
uniprocessor.
 Since there is only one processor , there can be no true
simultaneous execution of different programs. Instead,
the operating system executes part of one program, then
part of another, and so on.
 To the user, it appears that all programs are executing
at the same time.
23
Multiprogramming:
 The idea is as follows: the operating system keeps
several jobs in memory simultaneously. Since, in
general, main memory is too small to accommodate all
jobs, the jobs are kept initially on the disk in the job
pool.

This pool consists of all processes residing on disk
awaiting allocation of main memory.
 The set of jobs in memory can be a subset of the jobs
kept in the job pool.
 The operating system picks and begins to execute one
of the jobs in memory.
24
•
One job selected and run via job scheduling.
•
When it has to wait (for I/O for example), OS
switches to another job
25
26



Note :
Multiprogramming means: that several
programs in different stages of execution are
coordinated to run on a single I-stream engine
(CPU).
Multiprocessing, which is the coordination of
the simultaneous execution of several
programs running on multiple I-stream
engines (CPUs).
27

Timesharing (multitasking): is logical
extension of multiprogramming in which a
CPU switches between jobs so frequently that
users can interact with each job while it is
running, creating interactive computing.
28

Time sharing requires an interactive (or hands-on)
computer system, which provides direct communication
between the user and the system.

The user gives instructions to the operating system or to
a program directly, using a input device such as a
keyboard or a mouse, and waits for immediate results
on an output device.

Accordingly, the response time should be short—
typically less than one second.
29

A time-shared operating system allows many users to
share the computer simultaneously. Since each action or
command in a time-shared system tends to be short,
only a little CPU time is needed for each user.

As the system switches rapidly from one user to the
next, each user is given the impression that the entire
computer system is dedicated to his use, even though it
is being shared among many users.

30
Response time should be < 1 second.
 Each user has at least one program executing
in memory process.
 When a process executes, it typically executes
for only a short time before it either finishes or
needs to perform I/O.
 Time sharing and multiprogramming require
several jobs to be kept simultaneously in
memory. If several jobs are ready to be
brought into memory, and if there is not
enough room for all of them, then the system
must choose among them. Making this
decision is job scheduling.

31

In a time-sharing system, the operating system
must ensure reasonable response time, which is
sometimes accomplished through swapping,
where processes are swapped in and out of main
memory to the disk.

A more common method for achieving this goal
is a virtual memory, a technique that allows the
execution of a process that is not completely in
memory.

32

The main advantage of the virtualmemory scheme is that it enables users to
run programs that are larger than actual
physical memory.
33

Multiprogramming: the running task keeps running until it
performs an operation that requires waiting for an external event
(e.g. reading from a tape) or until the computer's scheduler
forcibly
swaps
the
running
task
out
of
the
CPU.
Multiprogramming systems are designed to maximize CPU usage.

Multitasking: is a method by which multiple tasks, also known as
processes, share common processing resources such as a CPU. In
the case of a computer with a single CPU, only one task is said to
be running at any point in time, meaning that the CPU is actively
executing instructions for that task.

Multitasking solves the problem by scheduling which task may be
the one running at any given time, and when another waiting task
gets a turn. The act of reassigning a CPU from one task to another
one is called a context switch.

Multiprocessing: : Multiprocessing is a generic term for the use of
two or more central processing units (CPUs) within a single
computer system. There are many variations on this basic theme,
and the definition of multiprocessing can vary with context,
mostly as a function of how CPUs are defined (multiple cores on
one die, multiple chips in one package, multiple packages in one
system
unit,
etc.).






Each device controller is in charge of a particular
device type (disk drive, video displays etc).
I/O devices and the CPU can execute concurrently.
Each device controller has a local buffer.
CPU moves data from/to main memory to/from
local buffers
I/O is from the device to local buffer of controller.
Device controller informs CPU that it has finished
its operation by causing an interrupt.



To start an I/O operation (read from a key
board), the device driver loads the appropriate
registers within the device controller.
The device controller of a keyboard, in turn,
examines the contents of these registers to
determine what action to take (such as “read a
character from the keyboard”).
The controller starts transferring of data from
the keyboard to its local buffer. Once the
transfer of data is completing, the device
controller informs the device driver via an
interrupt that it has finished its operation.



An interrupt (Cut off) is a hardware or
software -generated change-of-flow within
the system.
Hardware interrupt, e.g. services requests
data from I/O devices.
Software interrupt (trap), e.g. invalid
memory access, division by zero, or system
calls.



Each computer architecture has its own interrupt
mechanism, but several functions are common:
When an interrupt occurs, the control is transferred to
the interrupt service routine which is responsible for
dealing with the interrupt. The interrupt service
routine is generally accessed through an interrupt
vector. An interrupt vector knows where to find the
appropriate interrupt service routine for the current
interrupt.
The interrupt architecture must save the address of the
instruction that has been interrupted (the program
counter).



Incoming interrupts must be disabled if there is an
interrupt currently being processed. This is to prevent
interrupts from being lost or overwritten by newly
arriving interrupts.
An operating system is interrupt driven. This means
that if there are no interrupts (no processes to execute,
no I/O devices to service, and no users to whom to
respond) an operating system will sit quiet, waiting for
something to happen; i.e., the system will be idle.
The operating system must preserve the state of the
CPU by storing the contents of the registers and the
program counter.


The operating system must determine which type of
interrupt has occurred. This can be done either by
polling or by using a vectored interrupt system.
Polling is the systematic checking of each device to see
if it was the device responsible for generating the
interrupt. If the operating system has a vectored
interrupt system, then the identity of the device and
the type of interrupt will be easily identifiable without
checking
each
device.

The operating system must provide a segment of code
that specifies what action is to be taken in the event of
an interrupt. There must be a code segment that is
specific
to
each
type
of
interrupt.
Instruction Cycle with Interrupts
 CPU checks for interrupts after each instruction.
 If no interrupts, then fetch next instruction of current
program.
 If an interrupt is pending, then suspend execution of
the current program. The processor sends an
acknowledgement signal to the device that issued the
interrupt so that the device can remove its interrupt
signal.
 Interrupt architecture saves the address of the
interrupted instruction (and values of other registers).
Instruction Cycle with Interrupts

Interrupt transfers control to the interrupt service
routine (Interrupt Handler), generally through the
interrupt vector, which contains the addresses of all the
interrupt service routines.

Separate segments of code determine what action
should be taken for each type of interrupt.
Interrupt Handler
 A program that determines nature of the
interrupt and performs whatever actions are
needed.
 Control is transferred to this program.
 Generally, it is a part of the operating system.

Interrupt Handling
Save interrupt information .
OS determine the interrupt type (by
polling).
Call the corresponding handlers.
Return to the interrupted job by the
restoring important information (e.g.,
saved return address program counter).
48

System call: It is a mechanism used by an
application for requesting a service from the
operating system.

Examples of the services provided by the
operating system are allocation and de-allocation
of memory, reporting of current date and time
etc. These services can be used by an application
with the help of system calls. Many of the
modern OSes have hundreds of system calls. For
example Linux has 319 different system calls.
49

System calls provide an interface to the services
made available by an operating system. These
calls are generally available as routines written in
C and C++, although certain low-level tasks (for
example, tasks where hardware must be accessed
directly) may need to be written using assemblylanguage instructions.
50

An example to illustrate how system calls are used: writing
a simple program to read data from one file and copy them
to another file (Assignment2).

The first input that the program will need is the names of
the two files: the input file and the output file.

One approach is for the program to ask the user for the
names of the two files. In an interactive system, this
approach will require a sequence of system calls, first to
write a prompting message on the screen and then to read
from the keyboard the characters that define the two files.
51

On mouse-based and icon-based systems, a menu of file
names is usually displayed in a window. The user can then
use the mouse to select the source name, and a window can
be opened for the destination name to be specified. This
sequence requires many I/O system calls.

Once the two file names are obtained, the program must
open the input file and create the output file. Each of these
operations requires another system call. There are also
possible error conditions for each operation. When the
program tries to open the input file, it may find that there is
no file of that name or that the file is protected against
access.
52

In these cases, the program should print a message on the console
(another sequence of system calls) and then terminate abnormally
(another system call). If the input file exists, then we must create a
new output file.

We may find that there is already an output file with the same name.
This situation may cause the program to abort (a system call), or we
may delete the existing file (another system call) and create a new
one (another system call).

Another option, in an interactive system, is to ask the user (via a
sequence of system calls to output the prompting message and to
53
read the response from the terminal) whether to replace the existing
file or to abort the program.

Now the both files are set up, we enter a loop that reads from the
input file (a system call) and writes to the output file (another system
call). Each read and write must return status information regarding
various possible error conditions. On input, the program may find
that the end of the file has been reached or that there was a hardware
failure in the read (such as a parity error). The write operation may
encounter various errors, depending on the output device (no more
disk space, printer out of paper, and so on).

Finally, after the entire file is copied, the program may close both
files (another system call), write a message to the console or window
(more system calls), and finally terminate normally (the final system
54
call).




Therefore, simple programs may make heavy use of the
operating system.
Frequently, systems execute thousands of system calls
per second.
Most programmers never see this level of detail,
however. application developers design programs
depending on an application programming interface
(API) of the operating system.
The API specifies a set of functions that are available to
an application programmer, including the parameters
that are passed to each function and the return values
the programmer can expect.
55


The run-time support system (a set of functions built
into libraries included with a compiler) for most
programming languages provides a system-call
interface that serves as the link to system calls made
available by the operating system. The system-call
interface intercepts function calls in the API and
invokes the necessary system calls within the operating
system.
Typically, a number is associated with each system call,
and the system-call interface maintains a table indexed
according to these numbers. The system call interface
then invokes the intended system call in the operatingsystem kernel and returns the status of the system call
56
and any return values.

The caller need know nothing about how the system
call is implemented

Just needs to obey API and understand what OS will
do as a result call.

Most
details
of
OS
interface
hidden
from
programmer by API .
 Managed by run-time support library.
57
58


Three of the most common APIs available to
application programmers are the Win32 API for
Windows systems, the POSIX API for POSIX-based
systems (which include virtually all versions of UNIX,
Linux, and Mac OS X), and the Java API for designing
programs that run on the Java virtual machine.
Behind the scenes, the functions that make up an API
typically invoke the actual system calls on behalf of the
application programmer. For example, the Win32
function
CreateProcess()
actually
calls
the
NTCreateProcess() system call in the Windows kernel.
59

1.
2.
Why would an application programmer prefer
programming according to an API rather than invoking
actual system calls?
An application programmer designing a program
using an API can expect her program to compile and
run on any system that supports the same API (Each
operating system has its own name for each system
call).
Actual system calls can often be more detailed and
difficult to work with than the API available to an
application programmer.
60



Consider the ReadFile() function in the
Win32 API—a function for reading from a file
A description of the parameters passed to ReadFile()
 HANDLE file—the file to be read
 LPVOID buffer—a buffer where the data will be read into and written
from
 DWORD bytesToRead—the number of bytes to be read into the buffer
 LPDWORD bytesRead—the number of bytes read during the last read
 LPOVERLAPPED ovl—indicates if overlapped I/O is being used
61

C program invoking printf() library call, which calls write() system
call
62
63

Three general methods used to pass parameters to the OS

Simplest: pass the parameters in registers
 In some cases, may be more parameters than registers

Parameters stored in a block, or table, in memory, and address of block
passed as a parameter in a register
 This approach taken by Linux and Solaris

Parameters placed, or pushed, onto the stack by the program and popped
off the stack by the operating system

Block and stack methods do not limit the number or length of
parameters being passed.
64
65






Process control.
File management.
Device management.
Information maintenance.
Communications.
Protection.
66
67
(a) At system startup (b) running a program
68
69
70


Provide a convenient environment for program
development and execution.
 Some of them are simply user interfaces. to
system calls; others are considerably more
complex.
File management - Create, delete, copy, rename,
print, dump, list, and generally manipulate files
and directories.
71

Status information
Some ask the system for info - date, time,
amount of available memory, disk space,
number of users.
 Others provide detailed performance, logging,
and debugging information.
 Typically, these programs format and print the
output to the terminal or other output devices.
 Some systems implement a registry - used to
store and retrieve configuration information.

72


File modification
 Text editors to create and modify files.
 Special commands to search contents of files or
perform transformations of the text.
Programming-language support - Compilers,
assemblers, debuggers and interpreters
for
common programming languages are often
provided to the user with the operating system.
73

Program loading and execution- once a program is
assembled or compiled, it must be loaded into ram to
be executed. The OS provide absolute loaders,
reloadable loaders, linkage editors, and overlay-loaders,
debugging systems for higher-level and machine
language.
74

Communications - Provide the mechanism for creating
virtual connections among processes, users, and
computer systems. They allow users to send
messages to one another’s screens, browse web
pages, send electronic-mail messages, log in
remotely, transfer files from one machine to
another.
75
76
There are two fundamental approaches.
• One
provides
a
command-line
interface,
or
command interpreter, that allows users to directly
enter commands to be performed by the operating
system.
• The other allows users to interface with the
operating system via a graphical user interface, or
GUI.
77
1- Command Line Interface (CLI)



Some operating systems include the command
interpreter in the kernel.
Others, such as Windows and UNIX, treat the
command interpreter as a special program that is
running when a job is initiated or when a user
first logs on (on interactive systems).
On systems with multiple command interpreters
to choose from, the interpreters are known as
shells.
78
1- Command Line Interface (CLI)


For example, on UNIX and Linux systems, a
user may choose among several different shells,
including the Bourne shell, C shell, Bourne-Again
shell, Korn shell, and others.
Third-party shells and free user written shells
are also available. Most shells provide similar
functionality, and a user’s choice of which shell
to use is generally based on personal preference.
79
80
1- Command Line Interface (CLI)

The main function of the command interpreter is to get
and execute the next user-specified command.

Many of the commands given at this level manipulate
files: create, delete, list, print, copy, execute, and so on. The
MS-DOS and UNIX shells operate in this way. These
commands can be implemented in two general ways.

81
1- Command Line Interface (CLI)

In one approach, the command interpreter itself contains
the code to execute the command. For example, a
command to delete a file may cause the command
interpreter to jump to a section of its code that sets up
the parameters and makes the appropriate system call. In
this case, the number of commands that can be given
determines the size of the command interpreter, since
each command requires its own implementing code.
82
1- Command Line Interface (CLI)

An alternative approach—used by UNIX, among other
operating
systems
—implements
most
commands
through system programs.

In this case, the command interpreter does not
understand the command in any way; it merely uses the
command to identify a file to be loaded into memory and
executed.

Thus,
the
rm file.txt
UNIX
command
to
delete
a
file
is83
1- Command Line Interface (CLI)

would search for a file called rm, load the file into
memory, and execute it with the parameter file.txt.

The function associated with the rm command would be
defined completely by the code in the file rm.

In this way, programmers can add new commands to
the system easily by creating new files with the proper
names. The command-interpreter program, which can be
small, does not have to be changed for new commands to84
be added.
2- Graphical User Interface (GUI )

A second strategy for interfacing with the operating
system is through a user friendly graphical user
interface, or GUI. Here, rather than entering commands
directly via a command-line interface, users employ a
mouse-based window and-menu system characterized
by a desktop metaphor.
85
2- Graphical User Interface (GUI )

The user moves the mouse to position its pointer on
images, or icons, on the screen (the desktop) that
represent programs, files, directories, and system
functions.

Various mouse buttons over objects in the interface
cause various actions (provide information, options,
execute function, open directory (known as a folder).
86
2- Graphical User Interface (GUI )

Graphical user interfaces first appeared due in part to
research taking place in the early 1970s at Xerox PARC
research facility.

The first GUI appeared on the Xerox Alto computer in
1973. However, graphical interfaces became more
widespread with the advent of Apple Macintosh
computers in the 1980s.
87
2- Graphical User Interface (GUI )

The user interface for the Macintosh operating system
(Mac OS) has undergone various changes over the
years, the most significant being the adoption of the
Aqua interface that appeared with Mac OS X.

Microsoft’s first version of Windows—Version 1.0—was
based on the addition of a GUI interface to the MS-DOS
operating system.
88
2- Graphical User Interface (GUI )

Later versions of Windows have made cosmetic changes
in the appearance of the GUI along with several
enhancements in its functionality, including Windows
Explorer.
89

Many systems now include both CLI and
GUI interfaces
 Microsoft Windows is GUI with CLI
“command” shell
 Apple Mac OS X as “Aqua” GUI
interface with UNIX kernel underneath
and shells available
 Solaris is CLI with optional GUI
interfaces (Java Desktop, KDE)
90
92


Called “no structure”
The operating system is a collection of
procedures, each of which call any of the
other whenever it requires their needs.
93

MS-DOS – written to provide the most
functionality in the least space


Not divided into modules
Although MS-DOS has some structure, its
interfaces and levels of functionality are not
well separated
94
95
96


The operating system is divided into a
number of layers (levels), each built on top
of lower layers. The bottom layer (layer
0), is the hardware; the highest (layer N) is
the user interface.
With modularity, layers are selected such
that each uses functions (operations) and
services of only lower-level layers
97
98


Philosophy of microkernel is to have the
bare essentials in the kernel.
Removing all non-essential components
from kernel and implement them in
system-and -user level. Program thst
results a smaller kernel called microkernal.
99
100



Moves as much from the kernel into “user”
space.
Communication takes place between user
modules using message passing.
Benefits:




Easier to extend a microkernel
Easier to port the operating system to new
architectures
More reliable (less code is running in kernel
mode)
More secure
101
Process


An operating system executes a
variety of programs:
 Batch system – jobs
 Time-shared systems – user
programs or tasks
The terms job and process almost
interchangeably
104




A program in execution
An instance of a program running on
a computer
The entity that can be assigned to and
executed on a processor
A unit of activity characterized by the
execution of a sequence of
instructions, a current state, and an
associated set of system instructions
105

Process – a program in execution;
process execution must progress in
sequential fashion
106
A process consists of
1. An executable (i.e., code)
2. Associated data needed by



the program (global data,
dynamic data, shared data)
3. Execution context (or state) of the program, e.g.,
Contents of data registers
 Program counter, stack pointer
 Memory allocation
 Open file (pointers)

108



Program : Passive entity (executable file)
Process: Active entity (progam counter
specify next instruction).
A program becomes process when
executable file is loaded into memory
109

As a process executes, it changes state
new: The process is being created
 running: Instructions are being executed
 waiting: The process is waiting for some
event to occur
 ready: The process is waiting to be assigned
to a processor
 terminated: The process has finished
execution

110
111
Information associated with each process
 Process state
 Program counter
 CPU registers
 CPU scheduling information
 Memory-management information
 Accounting information
 I/O status information
112
113
Process State
PROCESS CONTROL BLOCK:
CONTAINS INFORMATION ASSOCIATED WITH EACH
PROCESS:
It's a data structure holding:

PC, CPU registers,

memory management information,

accounting ( time used, ID, ... )

I/O status ( such as file resources ),

scheduling data ( relative priority, etc. )

Process State (so running, suspended, etc. is
simply a field in the PCB ).
3: Processes
114
115
Trace of Process
116
117