The Operating System Machine Level Chapter 6. Operating System Machine Positioning of the operating...

Preview:

Citation preview

The Operating SystemMachine Level

Chapter 6

Operating System Machine

Positioning of the operating system machine level.

overview

a) OSM (Operating System Machine) is always interpreted

b) OSM is optional

c) ISA is sometimes interpreted

d) ISA can run without OSM. OSM can not run without ISA.

e) OSM adds system calls

f) 3 Main areas for this chapter– virtual memory– file I/O– parallel processing

Segmentation

a) Program assigned memory of base plus largest overlay

b) Segmentation is defined by program/compiler

c) Efficiency was controlled by programmer/compiler

d) Virtual memory dynamic– Programmer does not need to be involved– Machine can learn efficiency– Requires OSM

Paging

A mapping in which virtual addresses 4096 to 8191 are mappedonto main memory addresses 0 to 4095.

Virtual Memory

a) Steps for virtual memory – save main memory if required– find data on disk– load data from disk– change address map– continue- program does not know it was interrupted– How would this impact caching?

virtual address space vs. physical address space

Implementation of Paging (1)

The first 64 KB of virtual address space divided into 16 pages, with each page being 4K.

Implementation of Paging (2)

A 32 KB main memory divided up into eight page frames of 4 KB each.

Implementation of Paging (3)

Formation of a main memory

address from a virtual address.

Demand Paging and the Working Set Model

A possible mapping of the first 16 virtual pages

onto a main memory with eight page frames.

virtual memory

a) demanding paging as needed pages loaded into memory

b) page fault – trying to access memory not in memory

c) working set – pages necessary for the last k memlry references

d) Page Replacement– LRU – least recently used– FIFO

Thrashing

Page Replacement Policy

Failure of the LRU algorithm.

Segmentation (1)

In a one-dimensional address space with growing tables, one table may bump into another.

Segmentation (2)

A segmented memory allows each table to grow

or shrink independently of the other tables.

Segmentation (3)

Comparison of paging and segmentation.

Implementation of Segmentation (1)

(a)-(d) Development of external fragmentation. (e) Removal of the external fragmentation by compaction.

Implementation of Segmentation (2)

Conversion of a two-part MULTICS address into a main memory address.

Virtual Memory on the Pentium 4 (1)

A Pentium 4 selector.

A Pentium 4 code segment descriptor. Data segments differ slightly.

Virtual Memory on the Pentium 4 (2)

Conversion of a (selector, offset) pair to a linear address.

Virtual Memory on the Pentium 4 (3)

Mapping of a linear address onto a physical address.

Virtual Memory on the Pentium 4 (4)

Protection on the Pentium 4.

Virtual Memory on the UltraSPARC III (1)

Virtual to physical mappings on the UltraSPARC.

Virtual Memory on the UltraSPARC III (2)

Data structures used in translating virtual addresses on theUltraSPARC. (a) TLB. (b) TSB. (c) Translation table.

Filesa) A disk is a collection of sectors with only a lineal relationship

to each other.

b) A file is s abstraction created by a programmer

c) A record is a abstraction created by a programmer

d) A database is a abstraction created by a programmer

e) Conventions are enforced by software

f) I/O is performed by setting bits and bytes/words in device registers.

g) Error correction shared between hardware and OSM

h) Device properties will control some functions of how the OSM used the device

Implementation of Virtual I/O Instructions (1)

Reading a file consisting of logical records. (a) Before reading record 19. (b) After reading record 19.

Files

a) Pointers (current record) or EOF are maintained by OSM

b) Allocation units and sectors on a disk may be different

c) Programs see records which are different than allocation units or sectors

d) Allocation units may or may not be consecutive (CD-ROM vs. disk)

e) a logical file may consist of more than one OSM file.

f) File organization is all OSM

g) Free space is tracked by OSM bit map vs. free list

h) Processing efficiency argues for large allocation blocks however space utilization argues for small blocks

Implementation of Virtual I/O Instructions (2)

Disk allocation strategies. (a) A file in consecutive sectors.

(b) A file not in consecutive sectors.

Implementation of Virtual I/O Instructions (3)

Two ways of keeping track of available sectors.

(a) A free list. (b) A bit map.

Directory Management Instructions

A user file directory and the contents of a typical entry in a file directory.

Directories

a) OSM functions for disk– Create file– Delete file– Rename file– Change protection status of file– Secure file– Encrypt file– Read file– Write file– Create directories– Delete directories– identify directories– allow embedded directories

Parallel processing

a) Programs and libraries are OSM abstractions

b) Reasons for parallel processing– Limitations of light speed -

http://archives.cnn.com/2000/TECH/space/07/20/speed.of.light.ap/– 1 nanosecond = 1 ft– Cooperating processors can speed calculations over one processor– requires multiple CPU’s– simulate with each process have a small time slot

Process creation

a) program runs as part of a process

b) process has state and address space

c) system call creates process

d) parents may or may not have control of process they start

e) Race condition– consumer– producer– circular buffer– sleep/resume– see program listing pg 464– fatal flaw

Virtual Instructions for Parallel Processing

(a) True parallel processing with multiple CPUs.

(b) Parallel processing simulated by switching one CPU among three processes.

Race Conditions (1)

Use of a circular buffer.

Race Conditions (2)

Parallel processing with a fatal race condition.

Race Conditions (3)

Parallel processing with a fatal race condition.

Race Conditions (4)

Parallel processing with a fatal race condition.

Race Conditions (5)

Failure of the producer-consumer communication mechanism.

Process Synchronization Using Semaphores (1)

The effect of a semaphore operation.

Process Synchronization Using Semaphores (2)

Parallel processing using semaphores.

Process Synchronization Using Semaphores (3)

Parallel processing using semaphores.

Process Synchronization Using Semaphores (4)

Parallel processing using semaphores.

Unixa) UNIX – written in C

b) Berkley added paged virtual memory, long file names and TCP/IP

c) ATT came up with System III and then System V incompatible with Berkley UNIX

d) POSIX – standard for basic UNIX system

e) MINIX lead to Linux

f) All may have calls that go beyond standard

g) Caused by MSDOS being backward compatiable and running code on any version

h) Berkley was responsible for networking (sockets)

MINIX

a) http://www.minix3.org/

UNIX (1)

A rough breakdown of the UNIX system calls.

UNIX (2)

The structure of a typical UNIX system.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

Streams

a) Originally each device driver was responsible for all functions

b) Streams allows modules to be shared by device drivers for flow control

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

Windows XP

a) MS-DOS 1.0 was 8 k single user command line OS

b) MS-DOS 2.0 and 3.0 etc. add new features but kept command line format

c) Windows thru 3.x were front ends to DOS

d) Windows 95 (1995) still used DOS file system except for long names and increased number of blocks on disk

e) Windows 98 had improvements leading to DOJ law suit

f) Windows ME – slightly improved(?)

g) Windows NT complete rewrite

h) Windows 2000 – upgrade of NT

i) Windows XP – upgrade of 2000

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

Windows XP

a) XP has server and client versions

b) XP– 32 bit operating system with each user having their own 32-bit demand page virtual address

c) .

Windows XP

The structure of Windows XP.

UNIX Virtual Memory

The address space of a single UNIX process.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

UNIX virtual memory

a) Berkley demand page virtual memory one address space

b) System V and Solaris include map file or portion of into memory

Windows XP Virtual Memory

The principal Windows XP API calls for managing virtual memory.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

XP Virtual Memory

a) Every user process has it’s own virtual address space

b) 2 GB for application and 2 GB for Kernel

c) demand page with 4 KB page size

d) 3 states free, reserved or committed– free – not in use –auto pagefault– committed code or data mapped to it– reserved – not available for mapping

Allows for memory mapped files

UNIX Virtual I/O (1)

The principal UNIX file system calls.

UNIX Virtual I/O (2)

A program fragment for copying a file using the UNIX systemcalls. This fragment is in C because Java hides the

low-level system calls and we are trying to expose them.

UNIX Virtual I/O (3)

Part of a typical UNIX

directory system.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

UNIX IO

a) root directory is where directories start

b) subdirectories are under root

c) Special directories include bin, dev, lib and usr

d) Standard files o= Standard Input, 1 = Standard output and 2 = Standard Error

e) path starting a root is absolute path

f) link path to an existing file

g) inode contains file information including type, protection, lick

count, owner, length, owner group, disk addresses

UNIX Virtual I/O (4)

The principal UNIX directory management calls.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

XP Virtual IO

a) Supports FAT and NTFS

b) Uses ACL and SID for security

c) MFT – master file table

Windows XP Virtual I/O (1)

The principal Win32 API functions for file I/O.

The second column gives the nearest UNIX equivalent.

Windows XP Virtual I/O (2)

A program fragment for copying a file using the Windows XP APIfunctions. This fragment is in C because Java hides the low-level

system calls and we are trying to expose them.

Windows XP Virtual I/O (3)

The principal Win32 API functions for directory management.The second column gives the nearest UNIX equivalent, when one

exists.

Windows XP Virtual I/O (4)

The Windows XP master file table.

UNIX Process Management (1)

A process tree in UNIX.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

UNIX Process

a) parent/child via fork

b) one of the fork can then exec a program

c) Parent can continue or wait

d) processes communicate via pipes

e) Some UNIX systems use message queues

f) Threads are also allowed. Threads share address space

g) Threads synchronize by using mutexes

UNIX Process Management (2)

The principal POSIX thread calls.

Tanenbaum, Structured Computer Organization, Fifth Edition, (c) 2006 Pearson Education, Inc. All rights reserved. 0-13-148521-0

XP Process Management

a) XP supports multiple processes

b) Each process has at least one thread

c) Scheduling is by thread

d) fibers are threads created in user space

e) Communicate thru pipes, named pipes, mailslots, sockets, remote procedure calls and shared files

f) threads synchronize by semaphores, mutexes, critical sections, and events

Recommended