class slides (PowerPoint)

Download Report

Transcript class slides (PowerPoint)

Introduction
Operating Systems
Fall 2002
OS Fall’02
What is Operating System?
 It is a program!
 It is the first piece of software to run
after boot
 It coordinates the execution of all other
software
User programs
 It provides various common services
needed by users and applications
OS Fall’02
Today’s plan
 Operating system functionality
 Hardware support for the operating
system
 Course overview, bibliography,
administrative questions
OS Fall’02
The Operating System
controls the machine
gdb
gcc
User
diff
Application
Operating System
Hardware
vi
OS Kernel
Hard
ware
xterm
date
emacs
netscape
OS Fall’02
grep
A better picture
Many
applications
Application
One Operating
System
calls
Operating
System
Machine
instructions
Privileged
instructions
Hardware
OS Fall’02
System
One Hardware
A typical scenario
1. OS executes and schedules an
application to run
2. Application runs
•
•
CPU executes app’s instructions
OS is not involved
3. The system clock interrupts the CPU
•
•
Clock interrupt handler is executed
The handler is the OS function
OS Fall’02
A typical scenario (continued)
4. In handler: OS chooses another
application to run
Context switch
5. The chosen app. runs directly on the
hardware
6. The app. performs a system call to read
from a file
OS Fall’02
A typical scenario (continued)
7. The sys. call causes a trap into the OS


OS sets up the things for I/O and puts the
application to sleep
OS schedules another application to run
8. The third application runs
 Note: At any given time only one
program is running:
OS or a user application
OS Fall’02
The running application state
diagram
Interrupt/
System call
Application
code
runs
Schedule
OS runs
Resume execution
of the app. code
I/O
completed
Wait for
I/O completion
OS Fall’02
Ready
To run
Sleep
A question
 The operating system gets an input,
performs a computation, produces an
output, and quits
Yes or no?
The answer: No
 The operating system is a
reactive program
OS Fall’02
The OS is a reactive program
 It is idly waiting for events
 When an event happens, the OS reacts
It handles the event
Schedules another application to run
 The event handling must take as little
time as possible
 Event types
Interrupts and system calls
OS Fall’02
The OS performs
Resource Management
 Resources for user programs
CPU, main memory, disk space
 OS internal resources
Disk space for paging memory (swap space)
Entries in system tables
 Process table, open file table
Statically allocated
OS Fall’02
CPU management
 How to share one CPU among many
processes
 Time slicing:
Each process is run for a short while and
then preempted
 Scheduling:
The decision about which application to run
next
OS Fall’02
Memory management
 Programs need main memory frames to store
their code, data and stack
 The total amount of memory used by currently
running programs usually exceed the available
main memory
 Solution: paging
Temporarily unused pages are stored on disk
(swapped out)
When they are needed again, they are brought back
into the memory (swapped in)
OS Fall’02
The OS supports abstractions
 Creates an illusion that each application
got the whole machine to run on
In reality: an application can be preempted,
wait for I/O, have its pages being swapped
out, etc…
 A tree-like file system organization
Disk controllers can only write/read blocks
OS Fall’02
Hardware support for OS
 Support for executing certain instructions




in a protected mode
Support for interrupts
Support for handling interrupts
Support for system calls
Support for other services
OS Fall’02
CPU execution modes
 CPU has (at least) 2 execution modes:
User mode
Kernel mode
 Supervisor mode, privileged mode, monitor mode,
system mode
 The execution mode is indicated by a bit
in the processor status word (PSW)
 Some CPU instructions are available only
when executing in the kernel mode
OS Fall’02
Kernel Mode
 OS kernel is a collection of functions
responsible for the most basic services
OS kernel executes in the kernel mode
 Privileged instructions:
To load/store special CPU registers
To map memory pages to the address space
of a specific process
Instructions to set the interrupt priority level
Instructions to activate I/O devices
OS Fall’02
Protecting Kernel mode
 Is it possible for the user program to
cause the CPU to enter kernel mode?
 Yes: This must be possible (system call)
 The problem: how to prevent the user
program from executing privileged
instructions?
 Solution: change the program counter
(PC) to point to the OS code upon switch
OS Fall’02
Handling interrupts
 Interrupts cause the CPU to enter kernel
mode
 The address of the kernel function to
execute is loaded from the interrupt
vector
 The interrupt vector address and the
interrupt numbering is a part of the
hardware specification
Handlers are registered during the boot
OS Fall’02
Interrupt types (I)
 Asynchronous interrupts are generated by
external devices at unpredictable times
Clock interrupt is the basis for time slicing:
 Update the system time, preempt/schedule
processes
I/O device interrupt
 Informs the OS about completion of a requested
I/O
OS Fall’02
Interrupt types (II)
 Internal (synchronous) interrupts are
generated synchronously by CPU as a
result of an exceptional condition
An error condition: the application is trying
to perform an illegal operation:
 E.g., division by 0, issuing a privileged instr., …
 The handler typically kills the application
A temporary problem:
 E.g., the requested page is not in the memory
 Handling: bring the page into the memory
OS Fall’02
System calls
 Used to request a service from the OS
A collection of the system calls is the OS API
Packaged as a library
 Typical system calls
Open/read/write/close the file
Get the current time
Create a new process
Request more memory
OS Fall’02
Handling system calls
 An application executes a special trap
(syscall) instruction
Causes the CPU to enter kernel mode and set
PC to a special system entry point (gate
routine)
 The gate routine address is typically stored
in a predefined interrupt vector entry
Intel architecture: int[80]
A single entry serves all system calls (why?)
OS Fall’02
An example
open(“/tmp/foo”):
store the system call number and the parameters in a
predefined kernel memory location;
trap();
retrieve the response from a predefined kernel
memory location;
return the response to the calling application;
trap():
PC:=&int[80]; // transfer control to the gate routine
Gate routine:
switch(sys_call_num) {
case OPEN: …
}
OS Fall’02
Other hardware support
 Translating virtual address into a physical
address
Assist in supporting the virtual memory
abstraction
 Support for “used” bits for memory pages
Helps to determine which pages can be
swapped out when needed
OS Fall’02
What we are going to study
 Performance evaluation (brief)
 Process handling
Process concept, scheduling, concurrency
control
 Memory management
Paging, virtual memory
 File system
OS Fall’02
Advanced topics
 Distributed systems
Communication, networking, middleware
 Other possible topics:
Reliable distributed systems
Real-time systems
Parallel systems
Modern storage architectures
OS Fall’02
Bibliography
 Notes by Dror Feitelson
Will be published weekly
 Operating System Concepts, by
A. Silberschatz, P. Galvin, G. Gagne
 Operating Systems Internals and Design
Principles, by W. Stallings
 See the notes for more references
OS Fall’02
Next:
 Performance evaluation
OS Fall’02