Sie sind auf Seite 1von 188

Operating System Course

http://lms.nthu.edu.tw/course/22911/

Jia-Shung Wang
Department of Computer Science
National Tsing Hua University

Textbook: (A. Silberschatz, P. Galvin and G. Gagne)


Operating System Concepts, 9th Edition (International Student), John Wiley
& Sons, Inc., 2013.

2015/9/23

OS0-2015

2015/9/23

OS0-2015

Scoring
Midterm Exam
n Quiz
n Final Exam
n Exercises
n Term Projects
n

(32%) 9 November, 2015


(10%) 31 November, 2015
(34%) 4 January,
2016
(12%)
(12%)

Office Hour
Friday
2015/9/23

9:00~10:00
OS0-2015

Term Projects
" Will be announced soon

2015/9/23

OS0-2015

Book Information
" http://codex.cs.yale.edu/avi/os-book/OS9/
n

Linux Virtual Machine

Source codes

Solutions to Practice Exercises

2015/9/23

Study Guide to Accompany Operating Systems


Concepts, By Andrew DeNicola

OS0-2015

Early Stage: Von Neumann


Machine, Batch OS,

2015/9/23

OS0-2015

Lately: ARM mbed, IoT Solution,


" http://www.mbed.org/technology/os/

2015/9/23

OS0-2015

1970s: Original UNIX System


The users

(2)

system
programs

(1)

kernel

shells and commands


compilers and interpreters
system libraries
system-call interface to the kernel
signals
terminal

file system CPU scheduling


swapping page replacement

Handling

char I/O
terminal
drivers

block I/O
demand paging
disk and tape
virtual
drivers
memory

kernel interface to the hardware


hardware
2015/9/23

terminal controllers device controllers


terminals
OS0-2015

devices and tapes

memory controllers
physical memory
8

Evolution of Unix and Unix-like systems

2015/9/23

OS0-2015

Overview (1)
pOperating systems are an essential part of any
computer system.

pSimilarly, a course on operating systems is an

essential part of any computer-science education.

pThis field is undergoing change at a rapid rate, as

computers are now prevalent in virtually every


application, from games for children through the
most sophisticated planning tools for governments
and multinational firms.

pPrerequisites: we assume that the reader is familiar


with basic data structures, computer organization,
and a high-level language, such as C, POXIS, Java.

2015/9/23

OS0-2015

10

Overview (2)

pConcepts are presented using intuitive descriptions.


pImportant theoretical results are covered, but
formal proofs are omitted.

pThe bibliographical notes contain pointers to

research papers in which results were first


presented and proved, as well as references to
material for further reading.

pIn place of proofs, figures and examples are used


to suggest why we should expect the result in
question to be true.

2015/9/23

OS0-2015

11

Overview (3)

pThe fundamental concepts and algorithms covered


in the book are often based on those used in
existing commercial operating systems.

pOur aim is to present these concepts and

algorithms in a general setting that is not tied to


one particular operating system.

pThe content of the text corresponds to the

suggestions from Computing Curricula 2001 for


teaching operating systems, published by the Joint
Task Force of the IEEE Computing Society and the
Association for Computing Machinery (ACM).

2015/9/23

OS0-2015

12

Programming Environments (1)


pPOSIX: POSIX (Portable Operating System Interface)

represents a set of standards implemented primarily for


UNIX-based operating systems. POSIX-compliant systems
must implement the POSIX core standard (POSIX .1)--Linux,
Solaris, and Mac OS X. POSIX also defines several extensions
to the standards, including real-time extensions (POSIX 1.b)
and an extension for a threads library (POSIX 1.c, better
known as Pthreads)

Several programming examples written in C and tested on


Linux 2.6, and 3.2 systems, Mac OS X 10.7, and Solaris 10.

pWindows systems: Windows API, which provides a

comprehensive set of functions for managing processes,


threads, memory, and peripheral devices.

2015/9/23

OS0-2015

13

Programming Environments (2)


Java: Java is a widely used programming

language with a rich API and built-in language


Java programs run on any OS supporting a Java
virtual machine (or JVM).

2015/9/23

OS0-2015

14

Linux Virtual Machine


pThis virtual machine also includes a gcc

development environment with compilers and


editors.
pMost of the programming assignments in the book
can be completed on this virtual machine.
pProvide three programming assignments that
modify the Linux kernel through kernel modules:
l
l

Adding a basic kernel module to the Linux kernel.


Adding a kernel module that uses various kernel data
structures.
Adding a kernel module that iterates over tasks in a
running Linux system.

2015/9/23

OS0-2015

15

Contents (9th ed.)

PART ONE
Chapter 1
Chapter 2

OVERVIEW
Introduction
Operating-System Structures

PART TWO
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7

PROCESS MANAGEMENT
Processes
Threads
Process Synchronization
CPU Scheduling
Deadlocks

PART THREE
Chapter 8

STORAGE MANAGEMENT
Memory Management

2015/9/23

OS0-2015

16

Chapter 9

Virtual Memory

PART FOUR
Chapter 10
Chapter 11
Chapter 12
Chapter 13

STORAGE MANAGEMENT
Mass-Storage Structure
File-System Interface
File-System Implementation
I/O Systems

PART FIVE
Chapter 14
Chapter 15

PROTECTION AND SECURITY


Protection
Security

PART SIX
Chapter 16

ADVANCED TOPICS
Virtual Machines

2015/9/23

OS0-2015

17

Chapter 17

Distributed Systems

PART SEVEN

CASE STUDIES

Chapter 18
Chapter 19
Chapter 20
Appendix A
Appendix B
Appendix

2015/9/23

The Linux System


Windows 7
Influential Operating Systems
BSD Unix
The Mach System
The Nachos System

OS0-2015

18

The 9th Edition (1)


" 1: updated coverage of multiprocessor and multicore systems,
as well as a new section on kernel data structures.

" 1: computing environments: includes mobile systems, cloud


computing and an overview of real-time systems.

" 2: user interfaces for mobile devices, including discussions of


iOS and Android.

" 3(Processes): multitasking in mobile OSs, multiprocess model

in Googles Chrome, and zombie and orphan processes in UNIX.

" 4(Threads): parallelism and Amdahls law; a new section on

implicit threading, including OpenMP and Apples Grand Central


Dispatch.

2015/9/23

OS0-2015

19

The 9th Edition (2)


" 5(Process Synchronization): mutex locks, synchronization
using OpenMP, .

" 6(CPU Scheduling): Linux CFS scheduler and Windows usermode scheduling.

" 7 (Main Memory): swapping on mobile systems and Intel 32and 64-bit architectures. A new section for ARM architecture.

" 9 (Virtual Memory): Linux SLUB and SLOB memory


allocators.

" 10 (Mass-Storage Structure): solid-state disks.

2015/9/23

OS0-2015

20

The 8th Edition (1)


" 1: multicore CPUs, open-source operating systems
" 2: updated coverage of virtual machines, multicore CPUs, the
GRUB boot loader, OS debugging

" 3&4 (Processes, Threads): pipes, programming for multicore


systems

" 5(CPU Scheduling): virtual machine scheduling, multicore


architectures

" 6(Process Synchronization): transaction memory

2015/9/23

OS0-2015

21

The 8th Edition (2)


" 8 (Main Memory): discussions of NUMA
" 9 (Virtual Memory) Solaris 10 memory management
" 11 (File-System Implementation) full description of Suns
ZFS file system

" 12 (Mass-Storage Structure): iSCSI, ZFS pool


"

13 (I/O Systems): PCI Express, Hyper-Transport

2015/9/23

OS0-2015

22

1970s: Original UNIX System


The users

(2)

system
programs

(1)

kernel

shells and commands


compilers and interpreters
system libraries
system-call interface to the kernel
signals
terminal

file system CPU scheduling


swapping page replacement

Handling

char I/O
terminal
drivers

block I/O
demand paging
disk and tape
virtual
drivers
memory

kernel interface to the hardware


hardware
2015/9/23

terminal controllers device controllers


terminals
OS0-2015

devices and tapes

memory controllers
physical memory
23

Operating-System Structures
" Operating System Services
" User and Operating-System Interface
" System Calls
" System Programs
" OS Design and Implementation
" Operating-System Structure
" OS Debugging, Generation and System Boot
2015/9/23

OS0-2015

24

Common System Components


" Process Management
" Main Memory Management
" File Management
" I/O System Management
" Secondary Management
" Networking
" Protection System
" Command-Interpreter System
2015/9/23

OS0-2015

25

Historical Perspective
" Mainframe: Batch
" Mainframe: Multiprogramming
" Mainframe: Time-Sharing
" Computer-system Architecture
n

Single-processor Systems
w PCs

Multiprocessor Systems
w Parallel Systems or Tightly Coupled Systems

n
2015/9/23

Cluster Systems
OS0-2015

26

Mainframe: Batch Systems


" Main job of early OS: automatically transfer control
from one job to the next. (resident in memory)

" To speed up processing, jobs with similar needs

were batched together and were running through


the computer as a group.

" A batch operating system


n
n

n
2015/9/23

Programmers submit jobs (program, data, control cards)


Operator sort jobs into batches with similar requirements
(Fortran, Cobol)
OS transfers control from one job the the next.
OS0-2015

27

$END
$RUN
$LOAD
$FNT
$JOB
data for the program

program to be compiled

2015/9/23

OS0-2015

28

Memory Layout for a Simple Batch


System

2015/9/23

OS0-2015

29

" Lack of interaction between the user and the


job while that job is executing.
" CPU is often idle

I/O devices: card reader/printer


n I/O speed << CPU speed (at least 1:1000)
n

" Introduction of Disk technology


Spooling (Simultaneous Peripheral Operation OnLine)
n I/O is done with no CPU intervention
n CPU just needs to be notified when I/O is done
n

2015/9/23

OS0-2015

30

Disk

Card Reader

Memory

Line Printer

CPU
Spooling

2015/9/23

OS0-2015

31

" Spooling overlaps the I/O of one job with the


computation of other jobs.
n

The spooler may be reading the input of one job


while printing the output of a different job.

JBy overlaps, spooling keeps both the CPU and


the I/O devices working at much higher rates.

2015/9/23

OS0-2015

32

Mainframe: Multiprogramming
Batched Systems
" Spooling provides an important data structure: a job

pool, which contains jobs waiting on disk, ready to run.

" Job scheduling becomes possible: OS can select


which job to run next, to increase CPU utilization.

" The most important aspect of job scheduling is the

ability to multiprogram : OS keeps several jobs in


memory at a time.

J Multiprogramming organizes jobs such that CPU

always has one to execute. (When one job is waiting


for I/O, CPU switches to another.)

2015/9/23

OS0-2015

33

Multiprogramming Systems
Several jobs are kept in main memory at the same
time, and the CPU is multiplexed among them. "

2015/9/23

OS0-2015

34

OS Features Needed for


Multiprogramming
" I/O routine supplied by the system.
" Memory management the system must
allocate the memory to several jobs.

" CPU scheduling the system must choose


among several jobs ready to run.

" Allocation of devices.


2015/9/23

OS0-2015

35

Job Scheduling
Operating System
CPU Scheduling
Job 1
CPU

Job 2
Job 3
Job 4

2015/9/23

OS0-2015

Job pool

36

Mainframe: Time-Sharing Systems


L Disadvantages of a multiprogrammed batched
systems
n

No interaction with users: users must set up control cards


for all possible outcomes.
Statically debugging: long turnaround time inhibits
experimentation. (But, it instills good discipline of writing/
testing)

" An interactive (or hand-on) system: allows on-line

communication between users and the system.


(Usually, keyboard/screen are used. Users can see
results immediately.)

2015/9/23

OS0-2015

37

" Time-sharing (or multi-tasking): an


extension of multiprogramming.

CPU switches among jobs frequently such that users


may interact with programs.
n Switch job when
n

w finish
w waiting I/O
w a short period of time

" Early OS: single user, interactive


Batch: good CPU utilization, no interaction
Time-sharing: interaction, reasonable cost
" Combine: Batch + Time sharing (IBM OS/360)
2015/9/23

OS0-2015

38

Time-sharing System
" CPU Scheduling and multiprogramming provide

each user with a small portion of a time-shared


computer.

" CPU-bound and I/O-bound process


" Memory management and Protection
Virtual memory

" File system, Disk management

" Concurrent execution


" Process synchronization and Deadlock
2015/9/23

OS0-2015

39

The Movement of OS
" MULTICS (1965-1970 MIT) for GE 645
" UNIX (Ken Thompson, 1970 Bell Lab) for DEC PDP-11, Clanguage

" UNIX-like OS: System V, XENIX, BSD, Solaris, Linux, Cloud OS


" Workstation: Solaris, RS/6000, NT
" PC: Windows, Unix, Linux, OS/2, MacOS,
" Hand-held: Palm, Windows CE, Linux, Symbian, iOS,
Android,

" Embedded Systems: Linux, Wind River,


2015/9/23

OS0-2015

40

Computer-system Architecture
" Single-processor Systems
n

PCs

" Multiprocessor Systems


n

2015/9/23

Parallel Systems or Tightly Coupled Systems

OS0-2015

41

Desktop Systems

" Personal computers (PC) computer system


dedicated to a single user.

" I/O devices keyboards, mice, display screens,


small printers.

" User convenience and responsiveness.


" Can adopt technology developed for larger

operating system, often individuals have sole use of


computer and do not need advanced CPU utilization
of protection features.

" May run several different types of operating


systems (Windows, MacOS, UNIX, Linux)

2015/9/23

OS0-2015

42

Personal-Computer Systems
PCs: appeared in the 1970s, instead of maximizing
CPU and peripheral utilization, the systems opt for
maximizing user convenience and responsiveness.

" MS-DOS, OS/2, MacOS, Windows, Linux, Android,

" GUI
" Lack of file protection at first: destroy data, system
or even worldwide networks via virus mechanisms.

" LAN, Internet, browser, Social Networks,


2015/9/23

OS0-2015

43

Parallel Systems (1)

" Multiprocessor systems with more than one


CPU in close communication.

" Tightly coupled system processors share

memory and a clock; communication usually


takes place through the shared memory.

" Advantages of parallel systems:


Increased throughput
n Economical
n Increased reliability
n

w graceful degradation
2015/9/23

OS0-2015

44

Parallel Systems (2)


" Symmetric multiprocessing (SMP)
n

Each processor runs an identical copy of the operating


system.
Many processes can run at once without performance
deterioration.
Most modern operating systems support SMP, Solaris
2,

" Asymmetric multiprocessing


n

n
n
2015/9/23

Each processor is assigned a specific task; master


processor schedules and allocated work to slave
processors.
More common in extremely large systems
Grid computing
OS0-2015

45

Symmetric Multiprocessing Architecture


All processors are peer; no master-slave relationship exists between processors.

Shared dynamically
Among PEs
2015/9/23

OS0-2015

46

Uniform Memory Access VS.


Non-Uniform Memory Access (NUMA)
" Uniform Memory Access (UMA)
n

Access to any RAM from any CPU (or Core)


takes the same amount of time.

" Non-Uniform Memory Access (NUMA)

Some part of memory may take longer access


than other parts, creating a performance
penalty. (Section 9.5.4)

2015/9/23

OS0-2015

47

Multi-Core
" On-chip communication is faster than
between-chip communication

" Power Consumption


One chip with multiple cores uses significantly
less power than multiple single-core chips.
Multicore systems are well suited for server
systems such as database and Web servers.
2015/9/23

OS0-2015

48

A Dual-Core Design

other designs:
A combination of
local and shared caches
2015/9/23

blade servers:
Each bladeprocessor board
boots independently and
run its own OS.
OS0-2015

49

Clustered Systems
" Definition: Cluster computers share storage and are
closely linked via a local area network (LAN) or a
faster interconnect, such as InfiniBand.

" Provides high reliability


" Asymmetric clustering: one server runs the application
while other servers standby.

" Symmetric clustering: two or more hosts are running


application and are monitoring each other.

2015/9/23

OS0-2015

50

Parallelization and
Distributed Lock Management
" Parallelization: divide a program in several
components and run in parallel

" Parallel clusters


" Distributed Lock Management (DLM): To

provide the shared access to data, the system


must also supply access control and locking to
ensure that no conflicting operations occur.

2015/9/23

OS0-2015

51

Beowulf Clusters and SANs


" Designed for solving high-performance
computing task.

" Low-cost strategy: PC, Linux, open-source


software, LAN,

" Storage-area networks (SANs)

2015/9/23

OS0-2015

52

Operating System Components

" Timesharing (multitasking) is logical extension in

which CPU switches jobs so frequently that users can


interact with each job while it is running, creating
interactive computing
n
n

Response time should be < 1 second


Each user has at least one program executing in memory
[process
If several jobs ready to run at the same time [ CPU
scheduling
If processes dont fit in memory, swapping moves them in
and out to run
Virtual memory allows execution of processes not
completely in memory

2015/9/23

OS0-2015

53

Dual-mode
" Dual-mode operation allows OS to protect itself and
other system components
n
n

User mode and kernel mode


Mode bit provided by hardware

w Provides ability to distinguish when system is running user code or

kernel code
w Some instructions designated as privileged, only executable in kernel
mode
w System call changes mode to kernel, return from call resets it to user

2015/9/23

OS0-2015

54

System Structures

designer point of view

" Simple structure: DOS


" Layered approach
" Microkernels

2015/9/23

OS0-2015

55

MS-DOS Layer Structure


application program

resident system program


MS-DOS
device drivers

ROM BIOS device drivers


2015/9/23

OS0-2015

56

System Implementation
" Traditionally written in assembly language, operating
systems can now be written in higher-level
languages.

" Code written in a high-level language:


n

can be written faster

is more compact

is easier to understand and debug

" An operating system is far easier to port (move to

some other hardware) if it is written in a high-level


language.

2015/9/23

OS0-2015

57

System Generation (SYSGEN)


" Operating systems are designed to run on any of a

class of machines; the system must be configured for


each specific computer site.

" SYSGEN program obtains information concerning

the specific configuration of the hardware system.


n

CPU type, memory size, devices, OS options, OS


parameters, etc.

" Booting starting a computer by loading the kernel.


" Bootstrap program code stored in ROM that is able

to locate the kernel, load it into memory, and start its


execution.

2015/9/23

OS0-2015

58

Bill Gates VS. Jack Welch





(Crash)





95/98NT/2000 


2015/9/23

OS0-2015

59

Bill Gates VS. Jack Welch


2015/9/23

OS0-2015

60

Chapter 1
Introduction

2015/9/23

OS1-2015

61

Introduction
" What is an Operating System?
" Computer-System Organization
" Computer-System Architecture (OS0-2015)
" Operating-System Operations
" Process, Memory, Storage Management
" Protection and Security
" Kernel Data Structures
" Computing Environments
" Open-Source Operating Systems
2015/9/23

OS1-2015

62

What is an Operating System?


" A program that acts as an intermediary
between a user of a computer and the
computer hardware.

" Operating system goals:


n

Execute user programs and make solving user


problems easier.
Make the computer system convenient to use.

" Use the computer hardware in an efficient


manner.

2015/9/23

OS1-2015

63

Computer System Structures


1. Hardware provides basic computing resources
(CPU, memory, I/O devices).
2. Operating system controls and coordinates the
use of the hardware among the various application
programs for the various users.
3. Applications programs define the ways in which
the system resources are used to solve the
computing problems of the users (compilers,
database systems, video games, business programs).
4. Users (people, machines, other computers).
2015/9/23

OS1-2015

64

Four components of a computer system


User
1

Compiler

User
3

User
2

Assember

Text Editor

User
n

Browser

Application Programs
Operating System
Computer
Hardware

2015/9/23

OS1-2015

65

Operating System Definitions


" Resource allocator manages and allocates
resources.

" Control program controls the execution of


user programs and operations of I/O devices .

" No universally accepted definition


" Kernel the one program running at all times
(all else being system programs or application
programs).

2015/9/23

OS1-2015

66

Goals of OS
" Primary-- convenience
n

make the computer system convenient to


use

" Secondary-- efficiency


n

use the computer hardware in an efficient


manner

1. The two goals are contradictory

sometimes
2. In the past, the secondary goal is more
important.
2015/9/23

OS1-2015

67

Computer

" Original goal: Computing


"
"
"
"

Problem Solving
Next: Reasoning and Proving, AI(?)
Following: Storage and retrieval, Database
Following: Communication, Networking
Following: Multimedia, Consumer

" Following: Internet, Sharing & Searching


" Following: Social Networks (Relationship),
Cloud Computing (Utility)

2015/9/23

OS1-2015

68

Computer-System Organization
n Computer-system operation
n One or more CPUs, device controllers connect through
common bus providing access to shared memory
n Concurrent execution of CPUs and devices competing
for memory cycles

2015/9/23

OS1-2015

69

Computer-System Operation
" I/O devices and the CPU can execute
"
"
"
"
"

concurrently.
Each device controller is in charge of a
particular device type.
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.

2015/9/23

OS1-2015

70

Common Functions of Interrupts

" Interrupt transfers control to the interrupt service


routine generally, through the interrupt vector,
which contains the addresses of all the service
routines.

" Interrupt architecture must save the address of the


interrupted instruction.

" Incoming interrupts are disabled while another


interrupt is being processed to prevent a lost
interrupt.
Nested interrupts

" A trap is a software-generated interrupt caused


either by an error or a user request.

2015/9/23

OS1-2015

71

resident monitor
interrupt
vector

1
2
i
2

perform the service


routine for device i

service routine
for device i

1
an interrupt
from device i
occurs

return to
user

a:=b+c
d:=3*c

user program
2015/9/23

OS1-2015

72

resident monitor

case n

read

perform
I/O

trap to
monitor
system call n

return to
user

d:=3*c
user program
2015/9/23

OS1-2015

73

Interrupt Time Line For a Single Process


Doing Output

2015/9/23

OS1-2015

74

I/O Structure
1. After I/O starts, control returns to user
program only upon I/O completion.

n
n

2015/9/23

Wait instruction idles the CPU until the next


interrupt
Wait loop (Loop: jmp Loop)
At most one I/O request is outstanding at a
time, no simultaneous I/O processing.

OS1-2015

75

I/O Structure
2. After I/O starts, control returns to user

program without waiting for I/O completion.

2015/9/23

System call request to the operating system


to allow user to wait for I/O completion.
Device-status table contains entry for each I/
O device indicating its type, address, and state.
Operating system indexes into I/O device table
to determine device status and to modify table
entry to include interrupt.

OS1-2015

76

Two I/O Methods


Synchronous"

2015/9/23

Asynchronous"

OS1-2015

77

Device-Status Table

2015/9/23

OS1-2015

78

Direct Memory Access Structure


" Used for high-speed I/O devices able to transmit
information at close to memory speeds.

" Device controller transfers blocks of data from


buffer storage directly to main memory
without CPU intervention.

" Only one interrupt is generated per block, rather


than the one interrupt per byte.

" Cycle Stealing


2015/9/23

OS1-2015

79

How a Modern Computer Works

2015/9/23

OS1-2015

80

Storage Structure
" Main memory only large storage media that
the CPU can access directly.

" Secondary storage extension of main memory

that provides large nonvolatile storage capacity.

" Magnetic disks rigid metal or glass platters


covered with magnetic recording material
n

2015/9/23

Disk surface is logically divided into tracks, which are


subdivided into sectors.
The disk controller determines the logical interaction
between the device and the computer.

OS1-2015

81

Moving-Head Disk Mechanism

2015/9/23

OS1-2015

82

Storage Hierarchy
" Storage systems organized in hierarchy.
n Speed
n
n

Cost
Volatility

" Speed of magnetic disk


n
n

transfer rate * size


positioning time (random access time)
w seek time + rotational latency

" Caching copying information into faster

storage system; main memory can be viewed as a


last cache for secondary storage.

2015/9/23

OS1-2015

83

Storage-Device Hierarchy

2015/9/23

OS1-2015

84

Caching (1)
" Important principle, performed at many levels in a

computer (in hardware, operating system, software)

" Information in use copied from slower to faster


storage temporarily

" Faster storage (cache) checked first to determine if


information is there
n
n

If it is, information used directly from the cache (fast)


If not, data copied to cache and used there

" Smaller than storage being cached


n
n

Cache management
Cache size and replacement policy

2015/9/23

OS1-2015

85

Caching (2)
" Use of high-speed memory to hold recently-

accessed data.
" Caching introduces another level in storage
hierarchy. This requires data that is
simultaneously stored in more than one level
to be consistent.

2015/9/23

OS1-2015

86

Performance of Various Levels of


Storage

2015/9/23

OS1-2015

87

Migration of Integer A from Disk to Register

n Multitasking environments must be careful to use most recent


value, not matter where it is stored in the storage hierarchy

n Multiprocessor environment must provide cache coherency


in hardware such that all CPUs have the most recent value in
their cache

n Distributed environment situation even more complex


n
n

Several copies of a datum can exist


Various solutions covered in Chapter 16

2015/9/23

OS1-2015

88

Coherency and Consistency


" In a hierarchical storage system, the same data
may appear in different levels.
n

Change the copy in register make it inconsistent


with other copies
No problem for single task accessing (Highest level
is used)

" Multi-task accessing: need to ensure each


access obtain the most recent value

2015/9/23

OS1-2015

89

" Multiprocessor environment


Each CPU has a local cache.
n Cache coherency problem: make sure that an
update to a copy in one cache is immediately
reflected in all copies of other caches.
n

" Distributed environment


n

Several copies of the same file can be kept on


different computers

2015/9/23

OS1-2015

90

Operating System Components

" Timesharing (multitasking) is logical extension in

which CPU switches jobs so frequently that users can


interact with each job while it is running, creating
interactive computing
n
n

Response time should be < 1 second


Each user has at least one program executing in memory
[process
If several jobs ready to run at the same time [ CPU
scheduling
If processes dont fit in memory, swapping moves them in
and out to run
Virtual memory allows execution of processes not
completely in memory

2015/9/23

OS1-2015

91

Process Management
pA process is a program in execution. It is a unit of work within the
system. Program is a passive entity, process is an active entity.

" Process needs resources to accomplish its task


n

CPU, memory, I/O, files

Initialization data

" Single-threaded process has one program counter specifying


location of next instruction to execute
n

Process executes instructions sequentially, one at a time, until completion

" Multi-threaded process has one program counter per thread


" Typically system has many processes, some user, some operating
system running concurrently on one or more CPUs
n

Concurrency by multiplexing the CPUs among the processes / threads

2015/9/23

OS1-2015

92

Process Management Activities


The operating system is responsible for the
following activities in connection with process
management:
Creating and deleting both user and system
processes
n Suspending and resuming processes
n Providing mechanisms for process synchronization
n Providing mechanisms for process communication
n Providing mechanisms for deadlock handling
n

2015/9/23

OS1-2015

93

Memory Management
" Memory management determines what is in memory
when
n

Optimizing CPU utilization and computer response to users

" Memory management activities


n

Keeping track of which parts of memory are currently


being used and by whom
Deciding which processes (or parts thereof) and data to
move into and out of memory
Allocating and deallocating memory space as needed

2015/9/23

OS1-2015

94

Storage Management
" OS provides uniform, logical view of information storage
n
n

Abstracts physical properties to logical storage unit - file


Each medium is controlled by device (i.e., disk drive, tape drive)
w Varying properties include access speed, capacity, data-transfer rate, access

method (sequential or random)

" File-System management


n
n
n

Files usually organized into directories


Access control on most systems to determine who can access what
OS activities include
w
w
w
w

2015/9/23

Creating and deleting files and directories


Primitives to manipulate files and dirs
Mapping files onto secondary storage
Backup files onto stable (non-volatile) storage media

OS1-2015

95

Mass-Storage Management
" Entire speed of computer operation hinges on disk
subsystem and its algorithms
" OS activities
n
n
n

Free-space management
Storage allocation
Disk scheduling

" Some storage need not be fast


n
n

Tertiary storage includes optical storage, magnetic tape


Varies between WORM (write-once, read-many-times) and
RW (read-write)

2015/9/23

OS1-2015

96

I/O Subsystem

" One purpose of OS is to hide peculiarities of


hardware devices from the user
" I/O subsystem responsible for
n

Memory management of I/O including


w buffering (storing data temporarily while it is being

transferred),

w caching (storing parts of data in faster storage for

performance),

w spooling (the overlapping of output of one job with input

of other jobs)

General device-driver interface

Drivers for specific hardware devices

2015/9/23

OS1-2015

97

Protection and Security


" Protection the mechanism for controlling access
" Security the defense of the system against internal and
external attacks

" Systems generally first distinguish among users, to


determine who can do what
n

User identities (user IDs, security IDs) include name and associated
number, one per user
User ID then associated with all files, processes of that user to
determine access control
Group identifier (group ID) allows set of users to be defined and
controls managed, then also associated with each process, file
Privilege escalation allows user to change to effective ID with
more rights, such as setuid

2015/9/23

OS1-2015

98

Kernel Data Structures


" Many similar to standard programming data structures
" Singly linked list
data

data

data

null

" Doubly linked list


data null

data

data

data

null

" Circular linked list


data

data

data

data

2015/9/23

OS1-2015

99

Kernel Data Structures


" Balanced binary search tree: O(lg n)
n

Linux uses a balanced binary search tree as part its CPU


-scheduling algorithm

" Hash function: takes data as its input, performs a


numeric operation on this data, and returns a
numeric value.
This numeric value can then be used as an index into a
table (typically an array) to quickly retrieve the data.
n hash collision: a linked list at that table location that
contains all of the items with the same hash value.
n

2015/9/23

OS1-2015

100

Kernel Data Structures


hash map: associates (or maps) [key: value] pairs using
a hash function. Once the mapping is established, we can
apply the hash function to the key to obtain the value
from the hash map.
n For example, [user name: password]
n

hash_function(key)

hash map
0

value

" Bitmaps
n

For example, disk blocks. A bitmap can be used to


indicate the availability of each disk block.

2015/9/23

OS1-2015

101

Computing Environments
pTraditional Computing
pMobile Computing
pDistributed Systems
pClient-Server Computing
pPeer-to-Peer Computing
pVirtualization
pCloud Computing
pReal-Time Embedded Systems
2015/9/23

OS1-2015

102

Traditional Computing
" Office environment
n

Web-based computing: network computers (or thin


clients) are used in place of traditional workstations
where more security or easier maintenance is desired.
Mobile computers can synchronize with PCs to allow
very portable use of company information.

" Home networks


n

Networking becoming ubiquitous - even home systems


use firewalls to protect home computers from Internet
attacks.

" Time-sharing systems


2015/9/23

OS1-2015

103

Mobile Computing
" Handheld smartphones, tablets, etc.
n

Extra feature - more OS features (GPS,


gyroscope)
Allows new types of apps like augmented
reality, which overlay information on a display
of the current environment.

" Use IEEE 802.11 wireless, or cellular data networks


(4G, 5G?) for connectivity

" Leaders are Apple iOS and Google Android


2015/9/23

OS1-2015

104

Distributed Systems
" Distributed computing
n

Collection of separate, possibly heterogeneous, systems


networked together with TCP/IP, FTP, NFS, etc.
Local Area Network (LAN), Wide Area Network (WAN),
Metropolitan Area Network (MAN), Personal Area
Network (PAN)

" Network Operating System provides features


between systems across network
n

file sharing across the network, communication scheme


that allows different processes on different computers to
exchange messages
Illusion of a single system

2015/9/23

OS1-2015

105

Client-Server Computing
" Many systems now servers, responding to requests
generated by clients
n

Compute-server provides an interface to client to


request services
File-server provides interface for clients to store and
retrieve files

2015/9/23

OS1-2015

106

Peer-to-Peer Computing
" Another model of distributed systems
" P2P does not distinguish clients and servers
Instead all nodes are considered peers, may each
act as client, server or both
n Node must join P2P networks
n

w Registers its service with central lookup service on

network, or
w Broadcast request for service and respond to requests
for service via discovery protocol
Napster and Gnutella. Skype is another example.

2015/9/23

OS1-2015

107

Virtualization
" Virtualization is a technology that allows operating
systems to run as applications within other
operating systems.
n

one member of a class of software that includes


emulation. Emulation is used when the source CPU type is
different from the target CPU type.
For example, when Apple switched from the IBM Power
CPU to the Intel x86, it included an emulation facility
called Rosetta, which allowed applications compiled
for the IBM CPU to run on the Intel CPU.

2015/9/23

OS1-2015

108

Virtualization
" Virtualization first came about on IBM mainframes as a
method for multiple users to run tasks concurrently.

" Later, in response to problems with running multiple


Microsoft Windows XP applications on the Intel x86 CPU,
VMware created a new virtualization technology in the form
of an application that ran on XP.
n

That application ran one or more guest copies of Windows or other


native x86 operating systems, each running its own applications.

2015/9/23

OS1-2015

109

Cloud Computing
" A type of computing that delivers computing, storage, even apps as a
"

service across a network.


Uses virtualization as the base for it functionality.
n E.g., Amazon Elastic Compute Cloud (EC2)

" Public cloud available via Internet to anyone willing to pay


" Private cloud run by a company for the company's own use
" Hybrid cloud includes both public and private cloud components
" Software as a Service (SaaS) one or more applications available via the
Internet (i.e., word processor)

" Platform as a Service (PaaS) software stack ready for application use via
the Internet (i.e., a database server)

" Infrastructure as a Service (IaaS) servers or storage available over


Internet (i.e., storage available for backup use)

2015/9/23

OS1-2015

110

Cloud Computing
" Cloud computing environments composed of
traditional OS + VMMs + Cloud management tools
(e.g., Vware vCloud Director, Eucalyptus)
n
n

Internet connectivity requires security like firewalls


Load balancers spread traffic across multiple applications
Internet

customer
requests
cloud
customer
interface

firewall
load balancer

2015/9/23

virtual
machines

virtual
machines

servers

servers

OS1-2015

storage

cloud
management
commands
cloud
managment
services

111

Public Cloud


Private Cloud

Service Users

Cloud End-User Services (SaaS)


Cloud Platform Services (PaaS)
Cloud Infrastructure Services (IaaS)
Physical
Infrastructure
2015/9/23

OS1-2015

Cloud Providers

Hybrid
Cloud

Utility,
Scalable,
Virtualization,
Service-oriented architecture,

Service
Providers

Cloud Computing

112
112

Warehouse Scale Computers


(WSC)
" Not just a collection of servers
n
n
n
n

Hundreds to Thousands of servers running in concordance


Typically runs on a virtualized platform
Fault behavior & energy considerations have significant impact
Needs to be considered as a single unit

" Must be highly manageable


n
n

Deployment of software updates


Monitoring & system management

" Affordability
n

Currently power Public Cloud such as Google, Amazon, Yahoo,


Microsofts, etc
Soon to be affordable by Enterprises
w A rack of servers can easily have > 600 cores

2015/9/23

OS1-2015

113

Google Warehouse Style Computer Data


Center

2015/9/23

OS1-2015

114

Software Stack for Cloud OS


Cloud Application Management Tool
Hypervisor
Zen, Cambridge 2003

Physical
Cluster
Deployment
Tool

Power
Management
2015/9/23

Virtual Cluster Provisioning


Physical Compute
Servers

Distributed Main/Secondary Storage

Network/System
Management

Security

All-layer-2 Network
Intra-Virtual-Cluster
Load Balancing
Virtual Machine Management
OS1-2015

115

Real-Time Embedded Systems

" Embedded computers are the most prevalent form of


computers in existence. These devices are found
everywhere, from car engines and manufacturing robots to
Unmanned aerial vehicle (UAV, Drone) and microwave
ovens.

" Embedded systems almost always run real-time operating


systems.

" A real-time system is used when rigid time requirements


have been placed on the operation of a processor or the
flow of data; thus, it is often used as a control device in a
dedicated application.
2015/9/23

OS1-2015

116

Real-Time Embedded Systems

" Sensors bring data to the computer. The computer must


analyze the data and possibly adjust controls to modify the
sensor inputs.

" A real-time system has well-defined, fixed time constraints.


Processing must be done within the defined constraints, or
the system will fail.

" Real-time systems may be either hard or soft real-time.

2015/9/23

OS1-2015

117

Real-Time Embedded Systems


" Hard real-time
n

Guarantees that the critical tasks complete on


time.
Secondary storage limited or absent, data
stored in short term memory, or read-only
memory (ROM)
Conflicts with time-sharing systems, not
supported by general-purpose operating
systems.

" Soft real-time


A critical real-time task gets priority over other
2015/9/23
OS1-2015
118
tasks, and retains that
priority until it
n

Open-Source Operating Systems


" available in source-code rather than just binary
closed-source

" Learning OS by examining the actual source code,


rather than reading summaries of that code, can be
extremely useful. (modify compile run)

" Benefits: community of interested programmers


contribute to the code: debug, analyze, support, and
suggest changes.
n
n
n

More secure than closed-source codes (?)


Version control and services: Red Hat, etc.
Low cost

2015/9/23

OS1-2015

119

Open-Source Operating Systems


" Counter to the copy protection and Digital Rights
Management (DRM) movement

" Free Software Foundation (FSF), which has copyleft


GNU Public License (GPL)

" Examples: GNU/Linux, BSD UNIX (including core of


Mac OS X), and Sun Solaris

" Can use VMM like VMware Player (Free on Windows),


Virtualbox (open source and free on many platforms http://www.virtualbox.com)
2015/9/23

OS1-2015

120

2015/9/23

Chapter 2
Operating-System
Structures

os2-2015

121

Outlines
pOperating System Services
pUser Operating System Interface
pSystem Calls
pSystem Programs
pOperating System Design and Implementation
pOperating System Structure
pVirtual Machines
pHardware Protection
2015/9/23

os2-2015

122

Objectives
" To describe the services an operating system
provides to users, processes, and other
systems

" To discuss the various ways of structuring an


operating system

" To explain how operating systems are

installed and customized and how they boot

2015/9/23

os2-2015

123

Operating System Services (1)

2015/9/23

124

Operating System Services (2)


" User interface - Almost all operating systems have a user
interface (UI)
n Varies between Command-Line (CLI), Graphics User
Interface (GUI), Batch

" Program execution system capability to load a program into


memory and to run it, end execution, either normally or
abnormally (indicating error).

" I/O operations since user programs cannot execute I/O

operations directly, the operating system must provide some


means to perform I/O.

" File-system manipulation programs need to read and write

files and directories, create and delete them, search them, list
file Information, permission management.

2015/9/23

125

Operating System Services (3)


" Communications exchange of information between
processes executing either on the same computer or
on different systems tied together by a network.
Communications via shared memory or message
passing.

" Error detection OS needs to be constantly aware of

possible errors
n May occur in the CPU and memory hardware, in I/O
devices, in user program
n For each type of error, OS should take the appropriate
action to ensure correct and consistent computing
n Debugging facilities can greatly enhance the users and
programmers abilities to efficiently use the system

2015/9/23

126

Additional Operating System Functions


"

Another set of OS functions exists for ensuring the


efficient operation of the system itself via
resource sharing
l

Resource allocation When multiple users or multiple

jobs running concurrently, resources must be allocated to


each of them
Accounting keep track of and record which users use
how much and what kinds of computer resources for
account billing or for accumulating usage statistics.
Protection and Security

2015/9/23

Protection ensuring that all access to system resources is


controlled.
Security of the system from outsiders requires user authentication,
extends to defending external I/O devices from invalid access attempts

127

User OS Interface CLI (1)


CLI allows direct command entry

" Sometimes implemented in kernel, sometimes by


systems program

" Sometimes multiple flavors implemented shells


" Fetches a command from user and executes it

Sometimes commands built-in,


sometimes just names of programs
- adding new features doesnt require shell modification

2015/9/23

128

User OS Interface GUI (2)


" User-friendly desktop metaphor interface
n

Usually mouse, keyboard, and monitor

Icons represent files, programs, actions, etc

Various mouse buttons over objects in the


interface cause various actions (provide
information, options, execute function, open
directory (known as a folder)
Invented at Xerox PARC

2015/9/23

129

User OS Interface GUI (3)


" Many systems now include both CLI and GUI
interfaces
n
n

Microsoft Windows is GUI with CLI command shell


Apple Mac OS X as Aqua GUI interface with UNIX kernel
underneath and shells available.
Unix and Linux have CLI with optional GUI interfaces CDE,
LDE, GNOME (GNU Network Object Model Environment)

" Touch Panel, Multi-finger, Voice and Gesture


controls

2015/9/23

130

Touchscreen and Voice


" Touch screen devices require new interfaces
n

Mouse not possible or not desired

Actions and selection based on gestures

Virtual keyboard for text entry

" Voice secretary


n

Apple Siri, Microsoft Cortana, Google Now,


Amazon Alexa, Facebook M,

2015/9/23

131

System Calls
" System calls provide the interface between a
running program and the operating system

Available as assembly-language instructions


initially
n Languages defined to replace assembly language
for systems programming allow system calls to be
made directly (e.g., C, C++)
n Mostly accessed by programs via a high-level
Application Programming Interface (API) rather
than direct system call use.
n

Win32 , POSIX, Java

2015/9/23

132

An Example of System Calls


" Copy the contents of one file to another file

2015/9/23

133

An Example of Standard API


" Consider the ReadFile() function in the Win32 APIa function for reading from a
file

A description of the parameters passed to ReadFile()


n
n
n
n
n

HANDLE filethe file to be read


LPVOID buffera buffer where the data will be read into and written from
DWORD bytesToReadthe number of bytes to be read into the buffer
LPDWORD bytesReadthe number of bytes read during the last read
LPOVERLAPPED ovlindicates if overlapped I/O is being used

2015/9/23

134

System Call Implementation


" Typically, a number associated with each system
call
n

System-call interface maintains a table indexed


according to these numbers

" The interface invokes the intended system call and


returns status and any return values
" The caller need know nothing about how the
system call is implemented
Most details of OS interface hidden from
programmer by API
n Managed by run-time support library
n

2015/9/23

135

API System Call OS Relationship

2015/9/23

136

System Calls Parameter Passing


" Three general methods are used to pass

parameters between a running program and


the operating system.
Pass parameters in registers
n Store the parameters in a block, or table in
memory, and the table address is passed as a
parameter in a register
n Push (store) the parameters onto the stack by the
program, and pop off the stack by operating
system
n Block and stack methods do not limit the number
or length of parameters being passed
n

2015/9/23

137

Parameter Passing via Table

2015/9/23

138

Types of System Calls


" Process control
" File management
" Device management
" Information maintenance
" Communications
" Protection
2015/9/23

139

Examples: Windows and Unix System Calls

2015/9/23

140

Standard C Library Example


nC program invoking printf() library call, which
calls write() system call

2015/9/23

141

Example: MS-DOS
n Single-tasking
n Shell invoked when system
booted

n Simple method to run


program
n

No process created

n Single memory space


n Loads program into memory,
overwriting all but the
kernel
system startup

n Program exit -> shell


reloaded
2015/9/23

running a program"

"
142

Example: FreeBSD
" Unix variant
" Multitasking
" User login -> invoke users choice of shell
" Shell executes fork() system call to
create process
n
n

Executes exec() to load program into process


Shell waits for process to terminate or
continues with user commands

" Process exits with:


n

code = 0 no error

code > 0 error code

2015/9/23

143

System Programs
" System programs provide a convenient environment for
program development and execution. The can be
divided into:
n

File manipulation

Status information stored in a File modification

Programming language support

Program loading and execution

Communications

Background services

Application programs

" Most users view of the operation system is defined by


system programs, not the actual system calls
2015/9/23

144

Status information
Some ask the system for info - date, time,
amount of available memory, disk space, number
of users
n Others provide detailed performance, logging,
and debugging information
n Typically, these programs format and print the
output to the terminal or other output devices
n Some systems implement a registry - used to
store and retrieve configuration information
n

2015/9/23

145

Background Services
n

Launch at boot time


wSome for system startup, then terminate
wSome from system boot to shutdown

Provide facilities like disk checking, process


scheduling, error logging, printing

Run in user context not kernel context

Known as services, subsystems, daemons

2015/9/23

146

System Programs
" File modification
n
n

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 sometimes


provided

" Program loading and execution- Absolute loaders,

relocatable loaders, linkage editors, and overlayloaders, debugging systems for higher-level and
machine language
2015/9/23

147

System Programs
" Communications - Provide the mechanism for
creating virtual connections among processes,
users, and computer systems
n

Allow users to send messages to one anothers


screens, browse web pages, send electronic-mail
messages, log in remotely, transfer files from one
machine to another

2015/9/23

148

Communication Models

Communication may take place using either message passing


or shared memory.

Msg Passing"

2015/9/23

Shared Memory"

149

Design
" Design and Implementation of OS not solvable, but
some approaches have proven successful

" Internal structure of different Operating Systems can


vary widely

" Start by defining goals and specifications


" Affected by choice of hardware, type of system

2015/9/23

150

Design
" User goals and System goals
n

User goals operating system should be convenient


to use, easy to learn, reliable, safe, and fast
System goals operating system should be easy to
design, implement, and maintain, as well
as flexible, reliable, error-free, and efficient

2015/9/23

151

Mechanisms and Policies


nMechanism: determine how to do something, e.g.,
protect CPU using timer.

nPolicy: decide what will be done, e.g., CPU should be


protected or not?

nThe separation of policy from mechanism is a very


important principle, it allows maximum flexibility if
policy decisions are to be changed later.

nSpecifying and designing an OS is highly creative task


of software engineering

2015/9/23

152

Implementation
n Much variation
n

Early OSes in assembly language

Then system programming languages like Algol, PL/1

Now C, C++

n Actually usually a mix of languages


n

Lowest levels in assembly

Main body in C

Systems programs in C, C++, scripting languages like PERL, Python,


shell scripts

n More high-level language easier to port to other hardware


n

But slower

n Emulation can allow an OS to run on non-native hardware


2015/9/23

153

Operating System Structure


" General-purpose OS is very large program
" Various ways to structure ones
n

Simple structure MS-DOS

More complex - UNIX

Layered - an abstraction

Microkernel - Mach

2015/9/23

154

Simple Structure -- MS-DOS


n MS-DOS written to

provide the most


functionality in the least
space
n
n

Not divided into modules


Although MS-DOS has
some structure, its
interfaces and levels of
functionality are not well
separated

2015/9/23

155

Non Simple Structure -- UNIX


pLimited by hardware functionality, the original

UNIX operating system had limited structuring.


The UNIX OS consists of two separable parts
n

Systems programs

The kernel

Consists of everything below the system-call interface


and above the physical hardware
Provides the file system, CPU scheduling, memory
management, and other operating-system functions; a
large number of functions for one level

2015/9/23

156

UNIX System Structure

2015/9/23

157

Layered Approach
" 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.

" If an error is found during the debugging of a particular layer,

the error must be on that layer, because the layers below it are
already debugged.

" Problems: definition of the layers, less efficient

2015/9/23

158

Microkernel System Structure


" Moves as much from the kernel into user space
" Communication takes place between user modules
using message passing

" Benefits
n
n
n
n

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

" Detriments
n

Performance overhead of user space to kernel space


communication

2015/9/23

159

Microkernel System Structure


Application
Program

File
System

messages

Interprocess
Communication

Device
Driver

user
mode

messages

memory
managment

CPU
scheduling

kernel
mode

microkernel

hardware

2015/9/23

160

Modules
" Most modern operating systems
implement kernel modules

Uses object-oriented approach


n Each core component is separate
n Each talks to the others over known interfaces
n Each is loadable as needed within the kernel
n

" Overall, similar to layers but with more flexible


n

Linux, Solaris, etc

2015/9/23

161

Solaris Modular Approach

2015/9/23

162

Hybrid Systems
" Not one pure model
n

Hybrid combines multiple approaches to address


performance, security, usability needs
Linux and Solaris kernels in kernel address space, so
monolithic, plus modular for dynamic loading of
functionality
Windows mostly monolithic, plus microkernel for
different subsystem personalities

" Apple Mac OS X hybrid, layered, Aqua UI +


Cocoa programming environment

2015/9/23

163

Mac OS X Structure, hybrid structured

I/O kit for device drivers


Dynamically loadable modules
BSD CLI, networking,
file systems,
POSIX APIs
MM, RPCs, IPC,
thread scheduling
Message passing

Mach microkernel + BSD Unix parts + I/O kit + dynamically


loadable modules (called kernel extensions)
2015/9/23

164

iOS
" Apple mobile OS for iPhone, iPad
n

Structured on Mac OS X, added functionality

Does not run OS X applications natively


w Also runs on different CPU architecture (ARM vs. Intel)

Cocoa Touch Objective-C API for developing apps

Media services layer for graphics, audio, video

Core services provides cloud computing, databases

Core operating system, based on Mac OS X kernel

2015/9/23

165

Android
" Open Source: Developed by Open Handset
Alliance (mostly Google)
" Similar stack to IOS
" Based on Linux kernel but modified
n

Provides process, memory, device-driver


management
Adds power management

" Runtime environment includes core set of


libraries and Dalvik virtual machine
n

Apps developed in Java, running in Dalvik VM

" Libraries: web browser (webkit), database


(SQLite), multimedia, smaller libc
2015/9/23

166

Applications

Android Architecture

Application Framework

Libraries

Android runtime

SQLite

openGL

surface
manager

media
framework

webkit

Core Libraries
Dalvik
virtual machine

libc

Linux kernel
2015/9/23

167

Operating-System Debugging
" OS generates log files containing error information
" Failure of an application can generate core dump file capturing
memory of the process

" Operating system failure can generate crash dump file


containing kernel memory

" Beyond crashes, performance tuning can optimize system


performance
n
n

Sometimes using trace listings of activities, recorded for analysis


Profiling is periodic sampling of instruction pointer to look for statistical
trends

p Kernighans Law: Debugging is twice as hard as writing the code in the

first place. Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.
2015/9/23

168

DTrace Tool
" DTrace tool in Solaris,

FreeBSD, Mac OS X allows


live instrumentation on
production systems

" Probes fire when code is

executed within a provider,


capturing state data and
sending it to consumers of
those probes

" Example of following

XEventsQueued system call


move from libc library to
kernel and back

2015/9/23

169

DTrace Tool
" DTrace code to record amount
of time each process with
UserID 101 is in running
mode (on CPU) in
nanoseconds

2015/9/23

170

Virtual Machines (1)


" A virtual machine takes the layered approach to its
logical conclusion
n

It treats hardware and the operating system


kernel as though they were all hardware

" A virtual machine provides an interface identical


to the underlying bare hardware

" The operating system creates the illusion of

multiple processes, each executing on its own


processor with its own (virtual) memory

2015/9/23

171

Virtual Machines (3)

Non-virtual Machine"

2015/9/23

Virtual Machine"

172

Virtual Machines (2)


CPU scheduling, Virtual memory, Spooling,
Virtual Disk,

" The resources of the physical computer are


shared to create the virtual machines.
n

CPU scheduling can create the appearance that users have


their own processor
Spooling and a file system can provide virtual card readers
and virtual line printers
A normal user time-sharing terminal serves as the virtual
machine operators console

2015/9/23

173

Hypervisor, Type I and II


" Hypervisor (virtual machine manager, VMM): is one of
many hardware virtualization techniques that allow
multiple operating systems (guests) to run
concurrently on a host computer. It was first used in
1965 (IBM 360).

" Classification
n

Type I: run directly on the host's hardware to control the


hardware and to manage guest operating systems.
Type II: run within a conventional operating system
environment. With the hypervisor layer as a distinct second
software level, guest operating systems run at the third level
above the hardware.

2015/9/23

174

Advantages/Disadvantages of VM
" The virtual-machine concept provides complete protection of

system resources since each virtual machine is isolated from all


other virtual machines. This isolation, however, permits no
direct sharing of resources

" A virtual-machine system is a perfect vehicle for operating-

systems research and development. System development is


done on the virtual machine, instead of on a physical machine
and so does not disrupt normal system operation

" The virtual machine concept is difficult to implement due to the


effort required to provide an exact duplicate to the underlying
machine

2015/9/23

175

Simulation
" Simulation: the host system has one system

architecture and the guest system was complied for a


different architecture .

" The programs (such as important programs that were

compiled for the old system) could be run in an


emulator that translates each of the outdated systems
instructions into the current instruction set. (disadv.:
10 times slow usually)

2015/9/23

176

Para-virtualization
"

Presents guest with system similar but not


identical to the guests preferred systems.
Guest must be modified to run on para
-virtualized hardware.

"

Solaris 10: creates a virtual layer between


OS and the applications.

"

In this system, only one kernel is installed,


and the hardware is not virtualized, rather,
OS and its devices are virtualized, providing
processes within a containers (zones) with
the impression that they are the only
processes on this system.

"

Zen (Cambridge 2003): under Linux runs


on x86. Open source -> Citrix.

"

Hardware-assisted virtualization: offers new


instructions to support direct calls by a
paravirtualized guest into the hypervisor by
hypercalls.
2015/9/23

177

The Java Virtual Machine

2015/9/23

178

Java Virtual Machine


" Compiled Java programs are platform-neutral

bytecodes executed by a Java Virtual Machine


(JVM)

" JVM consists of


- class loader
- class verifier
- runtime interpreter

" Just-In-Time (JIT) compilers increase performance

2015/9/23

179

Hardware Protection
" Dual-Mode Operation
" I/O Protection
" Memory Protection
" CPU Protection

2015/9/23

180

Dual-Mode Operation
" Sharing system resources requires OS to

ensure that an incorrect program cannot


cause other programs to execute incorrectly

" Provide hardware support to differentiate

between at least two modes of operations


1. User mode execution done on behalf of a user
2. Monitor mode (also kernel mode or system
mode) execution done on behalf of operating
system

2015/9/23

181

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


(i.e., a user program that, as part of its
execution, stores a new address in the
interrupt vector)

User code
2015/9/23

182

Use of A System Call to Perform I/O

2015/9/23

183

Memory Protection
" Must provide memory protection at least for the

interrupt vector and the interrupt service routines

" In order to have memory protection, add two

registers that determine the range of legal addresses


a program may access:
n

Base register holds the smallest legal physical memory


address
Limit register contains the size of the range

" Memory outside the defined range is protected


2015/9/23

184

Use of A Base and Limit Register

2015/9/23

185

Hardware Address Protection

2015/9/23

186

Hardware Protection
" When executing in monitor mode, the

operating system has unrestricted access to


both monitor and users memory.

" The load instructions for the base and limit


registers are privileged instructions.

2015/9/23

187

CPU Protection
" Timer interrupts computer after specified period to
ensure operating system maintains control
n

Timer is decremented every clock tick

When timer reaches the value 0, an interrupt occurs

" Timer commonly used to implement time sharing


" Timer also used to compute the current time.
" Load-timer is a privileged instruction

2015/9/23

188

Das könnte Ihnen auch gefallen