Learning Outcomes: Chapter 1 - 1.3 Chapter 1.5 - 1.9

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Learning Outcomes

• High-level understand what is an operating


Introduction to Operating system and the role it plays
Systems • A high-level understanding of the structure of
operating systems, applications, and the
relationship between them.
Chapter 1 – 1.3 • Some knowledge of the services provided by
Chapter 1.5 – 1.9 operating systems.
• Exposure to some details of major OS
concepts.

What is an Operating
System?

3 4

Viewing the Operating System as Disk Users


an Abstract Machine
• Extends the basic hardware with added Memory
functionality
• Provides high-level abstractions CPU
– More programmer friendly
– Common core for all applications Network
Bandwidth
• It hides the details of the hardware
– Makes application code portable

5 6

1
Viewing the Operating System Traditional View: the Operating
as a Resource Manager System as the Privileged Component
• Responsible for allocating resources to users
and processes Applications Applications Applications
• Must ensure User Mode Requests (System Calls)

– No Starvation
Privileged Mode
– Progress
– Allocation is according to some desired policy Operating System
• First-come, first-served; Fair share; Weighted fair share;
limits (quotas), etc;
– Overall, that the system is efficiently used Hardware

7 8

The Operating System is


Kernel Privileged
• Portion of the operating system that is • Applications should not be able to interfere or bypass
running in privileged mode the operating system
– OS can enforce the “extended machine”
• Usually resident in main memory – OS can enforce its resource allocation policies
• Contains fundamental functionality – Prevent applications from interfering with each other

– Whatever is required to implement other


• Note: Some Embedded OSs have no privileged
services
component, e.g. PalmOS, Mac OS 9
– Whatever is required to provide security – Can implement OS functionality, but cannot enforce it.
• Contains most-frequently used functions • Note: Some operating systems implement significant
OS functionality in user-mode, e.g. User-mode Linux
• Also called the nucleus or supervisor 9 10

Structure of a Computer System Structure of a Computer System

Application Application Application

System Libraries System Libraries System Libraries


User Mode User Mode
Kernel Mode Kernel Mode
OS interacts via load
and store instructions
Device Device OS
Operating System to all memory, CPU
and device registers,
Device Device and interrupts
Memory Memory

11 12

2
Structure of a Computer System Structure of a Computer System

Applications interact with Interaction via


Application themselves and via Application System Calls
function calls to library
procedures
System Libraries
System Libraries
User Mode User Mode
Kernel Mode Kernel Mode

Device OS Device
OS
Device Device
Memory Memory

13 14

A note on System Libraries Operating System Objectives


• Convenience
– Make the computer more convenient to use
System libraries are just that, libraries of support • Abstraction
functions (procedures, subroutines) – Hardware-independent programming model
– Only a subset of library functions are actually systems calls • Efficiency
• strcmp(), memcpy(), are pure library functions – Allows the computer system to be used in an efficient manner
– manipulate memory within the application, or perform computation
• open(), close(), read(), write() are system calls • Ability to evolve
– they cross the user-kernel boundary, e.g. to read from disk device – Permit effective development, testing, and introduction of new
– System call functions are in the library for convenience system functions without interfering with existing services
• try man syscalls on Linux • Protection
– allow only authorised access to data, computation, services, etc.

15 16

Services Provided by the Services Provided by the


Operating System Operating System
• Program execution • Error detection and response
– Load a program and its data
– internal and external hardware errors
• Access to I/O devices
• memory error
– Display, disk, network, printer, keyboard, camera,
etc. • device failure
• Controlled access to files – software errors
– Access protection • arithmetic overflow
• System access • access forbidden memory locations
– User authentication – operating system cannot grant request of
application
17 18

3
Services Provided by the
Operating System Software
Operating System
• Fundamentally, OS functions the
• Accounting same way as ordinary computer Application

– collect statistics software


– It is a program that is executed System Libraries
– monitor performance (just like apps)
User Mode
• diagnose lack of it – It has more privileges
• Operating system relinquishes Kernel Mode
– used to anticipate future enhancements control of the processor to execute
Device
– used for billing users other programs OS
– Reestablishes control after
• System calls Device
• Interrupts (especially timer Memory
interrupts)

19 20

Major OS Concepts
Processes
(Overview) • A program in execution
• Processes • An instance of a program running on a computer
• The entity that can be assigned to and executed on a
• Concurrency and deadlocks processor
• Memory management • A unit of resource ownership

• Files
• Scheduling and resource management
• Information Security and Protection

21 22

Memory
• Consist of three Process Process
segments Stack
– Text
• contains the code
• Consists of three components
(instructions) – An executable program
– Data
• Global variables
Gap • text
– Stack – Associated data needed by the program
• Activation records of • Data and stack
procedure
• Local variables Data – Execution context of the program
• Note: • All information the operating system needs to
– data can dynamically grow
Text manage the process
up – Registers, program counter, stack pointer, etc;
– The stack can dynamically
grow down
23 24

4
Multiple processes creates
concurrency issues Memory Management
• The view from thirty thousand feet
– Process isolation
• Prevent processes from accessing each others data
– Automatic allocation and management
• Don’t want users to deal with physical memory directly
– Protection and access control
• Still want controlled sharing
– Long-term storage
– OS services
• Virtual memory
• File system

(a) A potential deadlock. (b) an actual deadlock.


25 26

Virtual Memory Virtual Memory Addressing


• Allows programmers to address
memory from a logical point of view
– Gives apps the illusion of having RAM to
themselves
– Logical addresses are independent of
other processes
– Provides isolation of processes from each
other
• Can overlap execution of one process
while swapping in/out others. 27 28

File System Example File System

• Implements long-term store


• Information stored in named objects
called files

29 30

5
Information Protection and Scheduling and Resource
Security Management
• Access control • Fairness
– regulate user access to the system – give equal and fair access to all processes
– Involves authentication • Differential responsiveness
• Information flow control – discriminate between different classes of jobs
– regulate flow of data within the system and • Efficiency
its delivery to users
– maximize throughput, minimize response time,
and accommodate as many uses as possible

31 32

Operating System Operating System Structure


Structure?
• The layered approach
a) Processor allocation
and multiprogramming
b) Memory Management
c) Devices a b c d e
d) File system
e) Users
– Each layer depends on
the inner layers

33 34

Operating System The Monolithic Operating


Structure System Structure
• In practice, layering is only a guide • Also called the
– Operating Systems have many “spaghetti nest”
interdependencies approach
• Scheduling on virtual memory – Everything is
• Virtual memory on I/O to disk tangled up with
• VM on files (page to file) everything else.
• Files on VM (memory mapped files)
• Linux, Windows,
• And many more;
;.
35 36

6
The Monolithic Operating
System Structure
• However, some
reasonable structure
usually prevails
Computer Hardware
Review
Chapter 1.4

Bowman, I. T., Holt, R. C., and Brewster, N. V. 1999. Linux as a case study: its extracted
software architecture. In Proceedings of the 21st international Conference on Software
Engineering (Los Angeles, California, United States, May 16 - 22, 1999). ICSE '99. ACM, 37
New York, NY, 555-563. DOI= http://doi.acm.org/10.1145/302405.302691

Learning Outcomes Operating Systems


• Understand the basic components of • Exploit the hardware available
computer hardware • Provide a set of high-level services that
– CPU, buses, memory, devices controllers, represent or are implemented by the
DMA, Interrupts, hard disks hardware.
• Understand the concepts of memory • Manages the hardware reliably and
hierarchy and caching, and how they efficiently
affect performance. • Understanding operating systems
requires a basic understanding of the
underlying hardware
39 40

Basic Computer Elements Basic Computer Elements


• CPU
– Performs computations
– Load data to/from memory via system bus
• Device controllers
– Control operation of their particular device
– Operate in parallel with CPU
– Can also load/store to memory (Direct Memory Access, DMA)
– Control register appear as memory locations to CPU
• Or I/O ports
– Signal the CPU with “interrupts”
• Memory Controller
– Responsible for refreshing dynamic RAM
– Arbitrating access between different devices and CPU

41 42

7
The real world is logically similar,
but more complex
A Simple Model of CPU
Computation
• The fetch-execute cycle

43 44

A Simple Model of CPU A Simple Model of CPU


Computation Computation
• The fetch-execute cycle • Stack Pointer
CPU Registers • Status Register CPU Registers
– Load memory contents from
– Condition codes
address in program counter • Positive result
(PC) PC: 0x0300 • Zero result PC: 0x0300
• The instruction SP: 0xcbf3 • Negative result SP: 0xcbf3
– Execute the instruction Status • General Purpose Registers Status
– Increment PC R1 – Holds operands of most instructions R1
 – Enables programmers (compiler) to 
– Repeat minimise memory references.
Rn Rn

45 46

‘Safe’ registers and


Privileged-mode Operation
CPU Registers instructions
• To protect operating system Interrupt Mask • Registers and instructions are safe if
execution, two or more CPU Exception Type
modes of operation exist – Only affect the state of the application itself
MMU regs
– Privileged mode (system-, Others – They cannot be used to uncontrollably
kernel-mode) PC: 0x0300 interfere with
• All instructions and registers are SP: 0xcbf3
available
• The operating system
Status
– User-mode • Other applications
R1
• Uses ‘safe’ subset of the
 – They cannot be used to violate a correctly
instruction set
– E.g. no disable interrupts Rn implemented operating system.
instruction
• Only ‘safe’ registers are 47 48
accessible

8
Privileged-mode Operation I/O and Interrupts
Memory Address Space • I/O events (keyboard, mouse, incoming network
packets) happen at unpredictable times
• The accessibility of 0xFFFFFFFF • How does the CPU know when to service an I/O
Accessible only
addresses within an to event?
address space Kernel-mode
changes depending 0x80000000
on operating mode
– To protect kernel code Accessible to
User- and
and data
Kernel-mode

0x00000000
49 50

Interrupts Interrupt Cycle


• An interruption of the normal sequence of • Processor checks for interrupts
execution
• If no interrupts, fetch the next instruction
• A suspension of processing caused by an event
• If an interrupt is pending, divert to the
external to that processing, and performed in
interrupt handler
such a way that the processing can be resumed.
• Improves processing efficiency
– Allows the processor to execute other instructions
while an I/O operation is in progress
– Avoids unnecessary completion checking (polling)

51 52

Classes of Interrupts Interrupt Handler


• Program exceptions • A software routine that determines the
(also called synchronous interrupts) nature of the interrupt and performs
– Arithmetic overflow whatever actions are needed.
– Division by zero
– Executing an illegal/privileged instruction • Control is transferred to the handler by
– Reference outside user’s memory space. hardware.
• Asynchronous (external) events • The handler is generally part of the
– Timer operating system.
– I/O
– Hardware or power failure 53 54

9
Memory Hierarchy
Simple Interrupt • Going down the
hierarchy
Application – Decreasing cost per
User Mode
bit
– Increasing capacity
– Increasing access
time
– Decreasing
Kernel Mode frequency of access
to the memory by the
processor
Interrupt • Hopefully
Handler • Principle of locality!!!!!
55 56

Cache
Memory Hierarchy Word Transfer Block Transfer

CPU
• Rough (somewhat dated) approximation of Registers
Cache Main Memory

memory hierarchy
• Cache is fast memory placed between the CPU and main memory
– 1 to a few cycles access time compared to RAM access time of tens –
hundreds of cycles
• Holds recently used data or instructions to save memory accesses.
• Matches slow RAM access time to CPU speed if high hit rate
• Is hardware maintained and (mostly) transparent to software
• Sizes range from few kB to several MB.
• Usually a hierarchy of caches (2–5 levels), on- and off-chip.
• Block transfers can achieve higher transfer bandwidth than single
words.
– Also assumes probability of using newly fetch data is higher than the
probability of reuse ejected data.

57 58

Moving-Head Disk Mechanism Example Disk Access Times


• Disk can read/write data relatively fast
– 15,000 rpm drive - 80 MB/sec
– 1 KB block is read in 12 microseconds
• Access time dominated by time to locate the
head over data
– Rotational latency
• Half one rotation is 2 milliseconds
– Seek time
• Full inside to outside is 8 milliseconds
• Track to track .5 milliseconds
• 2 milliseconds is 164KB in “lost bandwidth”
59 60

10
A Strategy: Avoid Waiting for Two-level Memories and Hit
Disk Access Rates
• Keep a subset of the disk’s data in • Given a two-level memory,
memory – cache memory and main memory (RAM)
⇒ Main memory acts as a cache of disk – main memory and disk
contents what is the effective access time?

• Answer: It depends on the hit rate in the


first level.
61 62

Effective Access Time Example


• Cache memory access time 1ns
• Main memory access time 10ns
Teff = H × T 1 + (1 − H ) × T 2 • Hit rate of 95%
T 1 = access time of memory 1
T 2 = access time of memory 2 Teff = 0.95 ×10 −9 +
H = hit rate in memory 1
Teff = effective access time of system
(1 − 0.95) × (10 −9 + 10 × 10 −9 )
= 1.5 × 10 −9
63 64

11

You might also like