0% found this document useful (0 votes)
11 views

Lecture 2

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

Lecture 2

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

Operating Systems –

IT 1206/CS 1207

Lecture 2 – Operating Systems Structures

Mr. Jude Iyke Nicholars


Tel: +256-703-040979
:+256-782-909117
Email: [email protected]

Operating Systems - Lecture 2


Computer System & OS Structures
 Computer System Operation
 I/O Structure
 Storage Structure, Storage Hierarchy

 Hardware Protection

 Operating System Services, System calls, System


Programs
 Structuring OS
 Virtual Machine Structure and Organization
 OS Design and Implementation
 Process Management, Memory Management, Secondary Storage
Management, I/O System Management, File Management, Protection
System, Networking, Command-Interpreter.
Operating Systems - Lecture 2
Computer System Architecture

Operating Systems - Lecture 2


What happens during execution?
Addr 232-1
R0

R31
F0
Fetch …
… Exec Data1
F30
PC Data0
Inst237
Inst236

Inst5
 Execution sequence:
Inst4
 Fetch Instruction at PC
Inst3 PC
 Decode Inst2
Execute (possibly using registers)
PC

Inst1
 Write results to registers/mem Inst0 PC
 PC = Next Instruction(PC) PC
 Repeat
Addr 0
From Berkeley OS course
Operating Systems - Lecture 2
Computer System Organization
 I/O devices and the CPU execute concurrently.
 Each device controller is in charge of a particular
device type
 Each device controller has a local buffer. I/O is from the
device to local buffer of controller
 CPU moves data from/to main memory to/from the
local buffers
 Device controller interrupts CPU on completion of
I/O

Operating Systems - Lecture 2


Interrupts
Interrupts are part of a hardware mechanism that sends a
notification to the CPU when it wants to gain access to a
particular resource. An interrupt handler receives this
interrupt signal and “tells” the processor to take action
based on the interrupt request.
Interrupt transfers control to the interrupt service routine
 Interrupt Service Routine: Segments of code that determine
action to be taken for each type of interrupt.
 Interrupt vector contains the address of service routines.
OS preserves the state of the CPU
 stores registers and the program counter (address of interrupted
instruction).
Trap
 software generated interrupt caused either by an error or a user
request.
Operating Systems - Lecture 2
Interrupt Handling
 Types of interrupt
 Polling
 Vectored interrupt system

 The interrupt controller must poll (send a signal


out to) each device to determine which one
made the request. The alternative to a polled
interrupt is a vectored interrupt , an interrupt
signal that includes the identity of the device
sending the interrupt signal..

Operating Systems - Lecture 2


I/O Structure
Synchronous I/O mean that some flow of execution (such as a process or
thread) is waiting for the operation to complete. Asynchronous I/O means
that nothing is waiting for the operation to complete and the completion of the
operation itself causes something to happen.
Synchronous I/O
 wait instruction idles CPU until next interrupt
 no simultaneous I/O processing, at most one outstanding I/O request
at a time.
Asynchronous I/O
 After I/O is initiated, control returns to user program without
waiting for I/O completion.
 System call
 Device Status table - holds type, address and state for each device
 OS indexes into I/O device table to determine device status and
modify table entry to include interrupt.

Operating Systems - Lecture 2


Direct Memory Access (DMA)
Many computers avoid burdening the main CPU with programmed I/O
by offloading some of this work to a special purpose processor. This
type of processor is called, a Direct Memory Access (DMA) controller.
A special control unit is used to transfer block of data directly between
an external device and the main memory, without intervention by the
processor. This approach is called Direct Memory Access (DMA).
 Used for high speed I/O devices

Memory
Memory able to transmit information at
close to memory speeds.
 Device controller transfers

blocks of data from buffer


CPU
storage directly to main memory
CPU
I/O instructions
I/O
I/Odevices
devices without CPU intervention.
 Only one interrupt is generated

per block, rather than one per


byte (or word).

Operating Systems - Lecture 2


Storage Structure
 Main memory - only large storage media that the
CPU can access directly.
 Secondary storage - extension of main memory that
has large nonvolatile storage capacity.
 Magnetic disks - rigid metal or glass platters covered with
magnetic recording material.
 Disk surface is logically divided into tracks, subdivided into
sectors.
 Disk controller determines logical interaction between device
and computer.

Operating Systems - Lecture 2


Storage Hierarchy
 Storage systems are organized in a hierarchy based
on
 Speed
 Cost
 Volatility

 Caching - process of copying information into faster


storage system; main memory can be viewed as
fast cache for secondary storage.

Operating Systems - Lecture 2


Storage Device Hierarchy

Operating Systems - Lecture 2


Storage Device Hierarchy…
The memory in a computer can be divided into five hierarchies based on the speed as well as
use. The processor can move from one level to another based on its requirements. The five
hierarchies in the memory are registers, cache, main memory, magnetic discs, and magnetic
tapes. The first three hierarchies are volatile memories which mean when there is no power,
and then automatically they lose their stored data. Whereas the last four hierarchies are not
volatile which means they store the data permanently
Primary Storage
This is also known as the main memory and is the memory directly accessible by the CPU.
All the instructions are executed in the main memory by CPU and the data required by these
instructions is also stored in main memory.
Main memory primarily consists of the RAM which is volatile in nature. It is also quite small
compared to secondary memory and expensive as well.
Secondary Storage
Secondary or external storage is not directly accessible by the CPU. The data from secondary
storage needs to be brought into the primary storage before the CPU can use it.
Secondary storage is non volatile i.e. the data stored is not lost when power is switched off.
Mostly hard drives are used as secondary storage.
Tertiary Storage
This is a third level of storage that mostly contains data that needs to be archived. This is
because it is quite slow. Data is normally retrieved from tertiary storage to primary storage
Operating Systems - Lecture 2
when it needs to be viewed. Tertiary storage is mostly formed of tapes and disks.
Hardware Protection
 Dual Mode Operation

 I/O Protection

 Memory Protection

 CPU Protection

Operating Systems - Lecture 2


Dual-mode operation
 Sharing system resources requires operating
system to ensure that an incorrect program cannot
cause other programs to execute incorrectly.

 Provide hardware support to differentiate between at


least two modes of operation:
1. User mode -- execution done on behalf of a user.
2. Monitor mode (supervisor/kernel/system mode) --
execution done on behalf of operating system.

Operating Systems - Lecture 2


Dual-mode operation(cont.)
 Mode bit added to computer
User
hardware to indicate the
current mode: monitor(0) or
Interrupt/ Set
user(1). fault user
 When an interrupt or fault mode
occurs, hardware switches to
monitor mode.
Monitor
 Privileged instructions only in
monitor mode.

Operating Systems - Lecture 2


I/O Protection
 All I/O instructions are privileged instructions.

 Must ensure that a user program could never gain


control of the computer in monitor mode, for e.g. a
user program that as part of its execution, stores a
new address in the interrupt vector.

Operating Systems - Lecture 2


Memory Protection
 Must provide memory protection
at least for the interrupt vector and 0
0
the interrupt service routines. monitor
256000
 To provide memory protection,
add two registers that determine Job1
Base register
the range of legal addresses a 3000040
program may address. 300040
 Base Register - holds smallest Job 2
legal physical memory address. 420940
 Limit register - contains the size of 120900
Job 3
the range. Limit register
 Memory outside the defined range
880000
is protected.
Job 4
 When executing in monitor mode,
the OS has unrestricted access to 1024000
both monitor and users’ memory.

Operating Systems - Lecture 2


Hardware Address Protection

The load instructions for the base and limit


registers are privileged instructions.

Operating Systems - Lecture 2


More detail: A Program’s Address Space
 Address space  the set of accessible
addresses + state associated with them:
 For a 32-bit processor there are 232 = 4 billion

Program Address Space


addresses
 What happens when you read or write to an
address?
 Perhaps Nothing
 Perhaps acts like regular memory
 Perhaps ignores writes
 Perhaps causes I/O operation
 (Memory-mapped I/O)

Perhaps causes exception (fault)

Operating Systems - Lecture 2


Providing the Illusion of Separate Address Spaces

Data 2
Code Code
Stack 1
Data Data
Heap 1
Heap Heap
Code 1
Stack Stack
Stack 2

Prog 1 Data 1
Prog 2
Virtual Virtual
Address Heap 2 Address
Space 1 Code 2
Space 2

OS code

Translation Map 1 OS data


Translation Map 2
OS heap & Load new Translation Map on Switch
Stacks

Physical Address
Operating Systems - LectureSpace
2
CPU Protection
 Timer - interrupts computer after specified period to
ensure that OS maintains control.
 Timer is decremented every clock tick.
 When timer reaches a value of 0, an interrupt occurs.
 Timer is commonly used to implement time sharing.
 Timer is also used to compute the current time.
 Load timer is a privileged instruction.

Operating Systems - Lecture 2


General System Architecture
 Given the I/O instructions are privileged, how do
users perform I/O?

 Via system calls - the method used by a process to


request action by the operating system.

Operating Systems - Lecture 2


System Calls
 Interface between running
program and the OS.
 Assembly language
instructions (macros and
subroutines)
 Some higher level languages
allow system calls to be made
directly (e.g. C)
 Passing parameters between a
running program and OS via
registers, memory tables or
stack.
 Unix has about 32 system calls
 read(), write(), open(), close(),
fork(), exec(), ioctl(),…..

Operating Systems - Lecture 2


Operating System Services
 Services that provide user-interfaces to OS
 Program execution - load program into memory and run it
 I/O Operations - since users cannot execute I/O operations
directly
 File System Manipulation - read, write, create, delete files
 Communications - interprocess and intersystem
 Error Detection - in hardware, I/O devices, user programs
 Services for providing efficient system operation
 Resource Allocation - for simultaneously executing jobs
 Accounting - for account billing and usage statistics
 Protection - ensure access to system resources is controlled

Operating Systems - Lecture 2


System Programs
 Convenient environment for program development
and execution. User view of OS is defined by
system programs, not system calls.
 Command Interpreter (sh, csh, ksh) - parses/executes other
system programs
 File manipulation - copy (cp), print (lpr), compare(cmp, diff)
 File modification - editing (ed, vi, emacs)
 Application programs - send mail (mail), read news (rn)
 Programming language support (cc)
 Status information, communication
 etc….

Operating Systems - Lecture 2


Command Interpreter System
 Commands that are given to the operating system
via command statements that execute
 Process creation and deletion, I/O handling, Secondary
Storage Management, Main Memory Management, File
System Access, Protection, Networking.
 Obtains the next command and executes it.
 Programs that read and interpret control statements
also called -
 Control card interpreter, command-line interpreter, shell (in
UNIX)

Operating Systems - Lecture 2


System Design and Implementation
 Establish design goals
 User Goals
 System Goals
 Software Engineering -
 Separate mechanism from policy. Policies determine what
needs to be done, mechanisms determine how they are
done.
 Choose a high-level implementation language
 faster implementation, more compact, easier to debug

Operating Systems - Lecture 2


System Generation
 OS written for a class of machines, must be
configured for each specific site.
 SYSGEN program obtains info about specific hardware
configuration and creates version of OS for hardware
 Booting
 Bootstrap program - loader program loads kernel,
kernel loads rest of OS.
 Bootstrap program stored in ROM

Operating Systems - Lecture 2


Operating Systems: How are they
organized?
 Simple
 Only one or two levels of code
 Layered
 Lower levels independent of upper levels
 Microkernel
 OS built from many user-level processes
 Modular
 Core kernel with Dynamically loadable modules

Operating Systems - Lecture 2


OS Structure - Simple Approach
 MS-DOS - provides a lot of functionality in little
space.
 Not divided into modules, Interfaces and levels of
functionality are not well separated

Operating Systems - Lecture 2


UNIX System Structure
 UNIX - limited
structuring, has 2
separable parts
 Systems programs
 Kernel
 everything below system
call interface and above
physical hardware.
 Filesystem, CPU
scheduling, memory
management

Operating Systems - Lecture 2


Layered OS Structure
 OS divided into number of
layers - bottom layer is
hardware, highest layer is
the user interface.

 Each layer uses functions


and services of only lower-
level layers.

 THE Operating System


Kernel has successive
layers of abstraction.

Operating Systems - Lecture 2


Layered Operating System

Operating Systems - Lecture 2


Microkernel Structure
 Moves as much from the kernel into “user” space
 Small core OS running at kernel level
 OS Services built from many independent user-level processes

 Communication between modules with message passing


 Benefits:
 Easier to extend a microkernel
 Easier to port OS to new architectures
 More reliable (less code is running in kernel mode)
 Fault Isolation (parts of kernel protected from other parts)
 More secure

 Detriments:
 Performance overhead severe for naïve implementation

Operating Systems - Lecture 2


Modules-based Structure
 Most modern operating systems implement modules
 Uses object-oriented approach
 Each core component is separate
 Each talks to the others over known interfaces
 Each is loadable as needed within the kernel
 Overall, similar to layers but with more flexible

Operating Systems - Lecture 2


OS Task: Process Management
 Process - fundamental concept in OS
 Process is a program in execution.
 Process needs resources - CPU time, memory, files/data
and I/O devices.
 OS is responsible for the following process
management activities.
 Process creation and deletion
 Process suspension and resumption
 Process synchronization and interprocess communication
 Process interactions - deadlock detection, avoidance and
correction

Operating Systems - Lecture 2


OS Task: Memory Management
 Main Memory is an array of addressable words or
bytes that is quickly accessible.
 Main Memory is volatile.
 OS is responsible for:
 Allocate and deallocate memory to processes.
 Managing multiple processes within memory - keep
track of which parts of memory are used by which
processes. Manage the sharing of memory between
processes.
 Determining which processes to load when memory
becomes available.

Operating Systems - Lecture 2


OS Task: Secondary Storage and I/O
Management
 Since primary storage is expensive and volatile,
secondary storage is required for backup.
 Disk is the primary form of secondary storage.
 OS performs storage allocation, free-space management
and disk scheduling.
 I/O system in the OS consists of
 Buffer caching and management
 Device driver interface that abstracts device details
 Drivers for specific hardware devices

Operating Systems - Lecture 2


OS Task: File System Management

 File is a collection of related information defined by


creator - represents programs and data.

 OS is responsible for
 File creation and deletion
 Directory creation and deletion
 Supporting primitives for file/directory manipulation.
 Mapping files to disks (secondary storage).
 Backup files on archival media (tapes).

Operating Systems - Lecture 2


OS Task: Protection and Security
 Protection mechanisms control access of programs and
processes to user and system resources.
 Protect user from himself, user from other users, system from
users.
 Protection mechanisms must:
 Distinguish between authorized and unauthorized use.

 Specify access controls to be imposed on use.

 Provide mechanisms for enforcement of access control.

 Security mechanisms provide trust in system and privacy

 authentication, certification, encryption etc.

Operating Systems - Lecture 2


OS Task: Networking
 Connecting processors in a distributed system
 Distributed System is a collection of processors that
do not share memory or a clock.
 Processors are connected via a communication
network.
 Advantages:
 Allows users and system to exchange information
 provide computational speedup
 increased reliability and availability of information

Operating Systems - Lecture 2


Virtual Machines
Virtual Machine abstracts the hardware of a computer system
such as CPU, disk drives, memory, NIC (Network Interface
Card) etc, into many different execution environments as per
requirements, hence giving a feel that each execution
environment is a single computer. For example, Virtual Box.
 Logically treats hardware
and OS kernel as hardware

 Provides interface identical


to underlying bare hardware.

 Creates illusion of multiple


processes - each with its
own processor and virtual
memory

Operating Systems - Lecture 2


Summary of OS Structures
 Operating System Concepts

 Operating System Services, System Programs and


System calls

 Operating System Design and Implementation

 Structuring Operating Systems

Operating Systems - Lecture 2

You might also like