You are on page 1of 14

Chapter 1: Introduction

Section 1: What is an operating system?


OS as an extended machine:
The architecture (instruction set, memory
organization, I/O, and bus structure) at
the machine language level is primitive
and awkward to program.
E.g. Disk I/O
OS presents the user with the equivalent of
an extended or virtual machine that is
easier to program.
OS as a resource manager:
OS provides for an orderly and controlled
allocation of the processors, memories,
and I/O devices among the various
programs competing for them, especially
when a computer has multiple users.
Multiplexing in time:
Different programs or users take turns
using it.
Multiplexing in space:
Each one gets part of the resource.
E.g. Memories
Section 2: History of OS
The first generation (1945 - 1955):
Vacuum tubes and plug-boards
Calculating engines:
Howard Aiken at Harvard
John von Neuman at IFAS in Princeton
Others
Originally by electric relays, later by
vacuum tubes.
Original programming by machine language
and wiring up plug-boards, in the early
1950's by punched cards.
For numerical calculations.
The second generation (1955 - 1965):
Transistors and batch systems
Mainframes

Separation between designers, builders,


operators, programmers, and maintenance
personnel.
Assembler or Fortran on punched cards
for scientific calculations.
Batch OS system:
A small computer collects a tray full of
jobs onto an input magnetic tape.
The main computer runs the input tape and
produces outputs on an output tape.
A small computer prints from the output
tape offline (not connected to the main
computer).
The third generation (1965 - 1980):
Integrated circuits (IC) and
multiprogramming
IBM 360:
Software-compatible machines designed to
handle both scientific and commercial
computing (by banks, etc).
OS/360:
Suppose to work on all models:
Small and large computers
Scientific and commercial computing
Multiprogramming:
Different jobs must be held in main
memory at once.
Requires special hardware to protect
each job.
If one job waits for I/O to complete,
another job uses the cpu.
Can read cards directly from cards onto
the disk ready to run
Spooling: Simultaneous peripheral
operation on line
Hours between submitting a job and
getting back the output.
Timesharing: A variant of multi-programming
Each user has an online terminal.
If some users are idle, computer provides
service to others users.
If all are active, timesharing.
Needs the necessary protection hardware.
Multics:

A machine that supports hundreds of


simultaneous timesharing users.
By MIT, Bell Labs, and GE.
Minicomputer:
DEC PDP 1, PDP 11
Unix: By Ken Thompson
A stripped-down one-user version of
Multics
The source code is widely available.
Linux: By Linus Torvalds
A free version of Minix, which is a clone
of Unix for educational purposes.
The fourth generation (1980 - Present):
Personal (micro) computers
Large scale integration (LSI) circuits
Thousands of transistors on 1 square cm
of silicon
Intel 8080: 1974
The first general purpose 8-bit CPU
Control program for microcomputer (CP/M):
by Gary Kindall
IBM PC with Intel 8086/8088: Early 1980's
Disk operating system (DOS) and Basic by
Bill Gates
MS-DOS (Microsoft disk operating system)
by Microsoft (Bill Gates and Tim
Patterson)
Apple Macintosh:
Graphical user interface (GUI) by Steve
Jobs (originally by Doug Engelbart at
Stanford Research Institute).
Windows:
GUI-based system (shell) which runs on
top of MS-DOS.
Windows 95, Windows 98:
A free standing version of Windows.
16-bit Intel assembly language
Windows new technology (NT):
A 32-bit system.
Windows 2000: Renamed from Windows NT 5
The successor both to Windows NT 4 and
98.
Windows Millennium (Me):

Another successor to Windows 98.


Unix:
Strongest on workstations and networks.
X Windows:
GUI on Unix.
Motif:
Complete GUI on Unix.
A network OS:
Can log in to remote machines.
Need: A network interface controller,
some software to drive it, and programs
to achieve login and remote file
access.
Not much different from a single
processor OS.
A distributed OS:
Allow applications to run on several
processors at the same time.
To its users it appears as a single
processor system.
The OS handles automatically and
efficiently where their programs run
and where their files are located.
More complex than a single processor OS.
Algorithms must run with incomplete
information.
Section 3: Computer Hardware Review
Simple PC:
CPU, Memory, I/O
CPU:
General registers: Hold key variables and
temporary results.
Special registers:
Program counter:
Points to the next instruction.
Stack pointer:
Points to the current (top of the)
stack in memory.
Holds temporary results, return address
and parameters for a procedure.
Program status:
Contains bits for the mode (kernel (OS)

or user), results from comparison (=,


!=, >, >=, <, <=), and from addition/
subtraction (=0, 0, >0, <0,
overflow), and other control bits.
Pipeline:
To improve performance, when CPU is
executing the nth instruction by an
execute unit, the decode unit is
decoding the n+1st instruction, and the
fetch unit is fetching the n+2nd
instruction.
In a longer pipeline an instruction will be
executed which shouldn't because the
previous instruction was a jump
instruction.
Super-scalar CPU:
Multiple fetch and decode units which dump
decoded instruction into a holding
buffer, and multiple execute units (eg.
floating, integer, and Boolean).
Instructions may be executed in wrong order
Kernel (supervisor) mode:
Every instructions can be executed
User mode:
A subset of the instructions may be executed
Disallows:
I/O, memory protection, switching to the
kernel mode, etc
Need a system call to obtain services from
OS. (A trap instruction, similar to
interrupt, but not in Intel chips)
Memory:
Registers in CPU: 1ns, < 1KB
Cache: 2ns, 1MB
Expensive
Cache hit: The required bytes are in cache
Cache miss: Must get from main memory
Main memory: 10ns, 512MB
Random access memory (RAM)
Disk: 10ms, 50GB
Rotates at 5400, 7200, or 10800 rpm
Track: All sectors (512/1024 bytes) for
5

given head arm position


Cylinder: All tracks for given head arm
position (multiple platters)
(cylinder = track for a single platter)
Outer tracks may have more sectors.
May have a bad sector.
Tape: 100s, 100GB
Cheap, for backup
Other kind of memory:
Read only memory (ROM):
Holds its contents even when power is
off, cheap, cannot be changed once
written.
Erasable and programmable read only memory
(EPROM) and flash Ram:
Can be erased and rewritten.
CMOS:
Draws very little power, powered by a
battery (for a few years), hold time
and configuration parameters (which
disk to boot, etc).
Multi-programs:
Need to solve:
Protect each program from others.
Relocate.
Solution:
Memory management unit (MMU):
Base register and limit register
All reference must be between 0 and
limit register.
Base register is added to all virtual
address to create physical address.
More sophisticated MMU allows to share
program, but not data.
I/O devices:
Each I/O device has a controller which may
have a small embedded computer.
Device driver:
Software to communicate with an I/O
device
Supplied by the device manufacturer
Must be put into OS in kernel mode
Usually at (re)booting time, OS finds
the drivers and load them.

No driver:
The device can be read and/or written by OS
like ordinary memory.
Access Methods:
Busy waiting:
OS waits until it is ready.
Interrupt:
OS blocks the program which requested I/O.
OS looks for other work to do.
When I/O is ready, it generates an
interrupt.
1. The device signals the interrupt
controller.
2. The controller signals CPU, and
3. the device number on the bus.
4. If CPU accepts interrupt, the address
and the status of the executing
program are saved.
5. CPU reads the device number on the bus
which identifies the address (interrupt
vector) for the interrupt handler for
the device.
6. CPU executes the interrupt handler.
7. The program which was executing before
the interrupt resumes executing.
Direct Memory Access (DMA):
DMA chip controls the flow of bits
between memory and the device
controller without CPU.
CPU sets up DMA chip, which causes an
interrupt when done.
Buses: New PC
ISA (Industry Standard Architecture):
2 bytes at 8.33MHz (16.67MB/s)
Original IBM PC
Included for backward compatibility
PCI (Peripheral Component Interconnect):
A successor to ISA bus by Intel
8 bytes at 66.67MHZ (528MB/s)
Most high speed I/O devices use the PCI
bus now.
A large Pentium system:
Level2
CPU with
cache
level1

PCI
Main
bridge Memory
7

cache

========================================

SCSI
USB
ISA
Graphics
6
7
bridge
Adapter

IDE disk
========================================

Modem
Sound
Printer
card
1:
2:
3:
4:
5:
6:

Cache bus
Local bus
Memory bus
PCI bus
ISA bus
SCSI (Small computer system interface):
Up to 160 MB/s
Macintosh and UNIX, and some Intel systems
7: USB (Universal serial bus):
4 wires; 2 wires supply power.
The single USB device polls the I/O
devices every 1ms; unnecessary to
install a new driver.
An aggregate load of 1.5MB/s
Faster version is coming out.
IEEE 1394 bus:
Serial, 50MB/s
Plug and play:
Before plug and play:
Each I/O card had a fixed interrupt request
level and fixed addresses for its I/O
registers.
If two cards uses the same interrupt, DIP
switches and/or jumpers must be reset.
After:
At a boot time Bios (Basic input output
system) in a flash RAM checks RAM, ISA
and PCI buses to detect all attached
devices.
If there is a new device (not on the list
in CMOS), the new device is configured.
Booting:

From a floppy, a CD-ROM, or the hard disk


The first sector from the boot disk is
executed.
The secondary boot loader is executed and
OS is loaded.
OS queries the BIOS to get the
configuration information.
OS initializes devices' table in kernel.
If a device does not have a driver, OS asks
user to supply its driver.
OS begins a login program.
Section 4: The OS Zoo
Mainframe OS:
Much larger I/O capability than PC
Typical services:
Batch: Jobs without any interactive user
present
Transaction processing: Handles large
numbers of small requests
E.g. Check processing, reservation, etc
Timesharing: Allows multiple remote users
E.g. Querying a big database
E.g. OS/390 (a descendant of OS/360)
Server OS:
Servers may be large PCs, workstations, or
mainframes.
Serves multiple users at once over a
network.
Allows users to share hardware and software
resources.
E.g. Unix, Windows 2000, Linux
Multiprocessor OS:
Connect multiple CPU's into a single system
Also called: Parallel or multi- computers
PC OS:
A good interface to a single user.
E.g. Word processing, spreadsheets,
internet access, etc.
E.g. Windows 98/2000, and Linux.
Real-time OS:
Hard real-time system:

An action must occur at a certain moment.


E.g. Machine control
Soft real-time system:
Occasional missing is acceptable.
E.g. Digital audio, multimedia systems
Embedded OS:
For a palmtop computer or personal digital
assistant, which performs a small number
of functions: Address book, memo pad
Also runs on computers that control TV
sets, microwave ovens, mobile phones, etc
E.g. Palm OS, Windows CE (Consumer
electronics)
Smart card OS:
For credit card-sized devices with a CPU
chip which do one or a few functions.
E.g. electronic payment
Some have Java applets interpreter.
Section 5: Skip
Section 6: System Calls
Systems calls:
Available in procedure library:
Makes it possible to make system calls
from C or other programs.
Like procedure (function) calls except that
system calls enter the kernel.
Example in Unix:
int count = read(file, buffer, bytes);
// read() is in procedure library
// if count == -1, error
// if count < bytes, eof
Compiled in assembly language:
1. Put parameters on stack in reverse order:
C-style
2. Call a procedure library read;
Return address is saved on stack.
3. A procedure library read:
Put a code (one byte) for read from file
in an agreed register.
4. Trap: (Similar to interrupt)

10

5.

6.

7.
8.

Switches from the user mode to the


kernel, and starts execution at a fixed
address.
In the kernel:
Check the code in the register to finds
the address of the correct system call
handler from a table (similar to an
interrupt vector table), and
dispatches there.
Once the system call handler has completed
its work, switches to the user mode,
and returns to the library procedure
(following the Trap).
If the handler cannot complete its work
(e.g. waiting for characters from the key
board), the OS will try to run some
other process.
The library procedure returns to the user
program.
The user program cleans up parameters on
the stack.

Library procedures:
Unix:
About 100 procedures
Most of them call system calls (almost
1-1).
GUI (X Windows and Motif) run in user
space.
Windows: Win32 API (Application Program
Interface):
Over thousands procedures
Only some of them invoke system calls.
A huge number of calls for managing
windows, figures, text, fonts, etc;
The graphics subsystem runs in the
kernel.
Section 7: OS Structure
Monolithic (no layer):
A collection of procedures each of which
can call any others.
No information hiding
Some structure:
A main program invokes the requested
service procedures.

11

Service procedures carry out the systems


(utility) calls.
Utility procedures help the service
calls.
Layered Systems:
Each layer is constructed on the one below
it.
The first layered system:
THE by Dijikstra (1968) and his students
6 layers
Layer 0: Allocation of cpu and
interrupt services (multiprogramming)
Layer 1: Memory management
Layer 2: Communication between each
process and the operator console
Layer 3 and above:
Abstract (nice) I/O
Multics:
A series of rings
A system call is required for a
procedure in an outer ring to call
one in an inner ring.
Easy to extend to structure user
subsystems
Virtual Machines:
VM/370 (originates from OS/360)
Exact copies (virtual machines) of the bare
hardware.
Different virtual machines can run
different OS.
Each piece is simpler, more flexible, and
easier to maintain.
Intel Pentium:
Provides a virtual 8086 mode:
8/16-bit data, 20-bit address (1MB)
Not the exact copy (Pentium)
Old MS-DOS on a Pentium: Two variants
1. MS-DOS is loaded into the virtual 8086.
Trap goes to MS-DOS but I/O are caught
and carried out by the virtual machine
monitor.
2. The virtual machine catches the trap
and does the I/O. Less pure but faster

12

Note:
With VM/370 each user gets an exact copy of
the underlying computer IBM370.
With virtual 8086 mode on the Pentium, each
user gets an exact copy of 8086,
different from the underlying cpu.
Java virtual machine (JVM):
Java compiler produces code for JVM, which
is executed by any computer with a
software JVM interpreter.
Exokernels:
Each user has a clone of the actual
computer with a subset of resources:
E.g. One user has access to 0 to 1023
blocks of the disk, and the other from
1024 to 2047, etc
Exokernel runs in kernel mode at the bottom
layer.
Simpler than other virtual OS: No table to
re-map disk addresses
Client-Server Model:
Microkernel:
The kernel handles only the communication
between client (client processes) and
servers (process server, file server,
memory server) all of which run in the
user mode.
Easy to use in distributed systems
Some special instructions to hardware
must also be done the kernel mode:
1. Do it all in the kernel.
2. Do a minimum amount of mechanism
into the kernel, but leave the
policy decisions up to the server
in user space.
E.g. Writing to or reading from a
certain address in user mode means
writing to or reading from some
I/O device, and the kernel will
take over.
Sections 8, 9, 10, 12: Skip
Section 11: Metric Units

13

1 = unit
10 = 1 deca
100 = 1 hecto
1000 = 1 kilo = 1k
1000000 = 1 mega = 1m
1000000000 = 1 giga = 1g
1000000000000 = 1 tera
0.1 = 1 deci = 1d
0.01 = 1 centi = 1c
0.001 = 1 milli = 1m
0.000001 = 1 micro = 1u
0.000000001 = 1 nano = 1n
0.000000000001 = 1 pico = 1p
Maximum in:
1 byte: 28 = 256
210 = 1024 = 1k
2 bytes: 216 = 65536 = 26 * 210 = 64k
220 = 210 * 210 = 1k * 1k = 1m
3 bytes: 224 = 24 * 220 = 16m
230 = 210 * 210 * 210 = 1k * 1k * 1k
= 1g
4 bytes: 232 = 22 230 = 4g
Examples:
Short integer (2 bytes): -32k to +32k
Long integer (4 bytes): -2g to +2g
Number of RGB colors (3 bytes): 16m

14

You might also like