os fall ’ 02 introduction operating systems fall 2002
Post on 20-Dec-2015
219 views
TRANSCRIPT
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 softwareUser 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
User
Application
Operating System
Hardware
OS Kernel
Hardware
gcc gdb
emacs
vi date
grep
xterm
netscape
diff
OS Fall’02
A better picture
Hardware
OperatingSystem
Privileged instructions
Systemcalls
Machineinstructions
Application
One Hardware
One Operating System
Many applications
OS Fall’02
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
Applicationcoderuns
OS runs
Sleep
ReadyTo run
Interrupt/System call
Wait forI/O completion
I/Ocompleted
Schedule
Resume executionof the app. code
OS Fall’02
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
reactsIt handles the event Schedules another application to run
The event handling must take as little time as possible
Event typesInterrupts and system calls
OS Fall’02
The OS performs Resource Management
Resources for user programsCPU, main memory, disk space
OS internal resourcesDisk 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: pagingTemporarily 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 organizationDisk 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 modeKernel 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 servicesOS kernel executes in the kernel mode
Privileged instructions:To load/store special CPU registersTo map memory pages to the address space of a specific processInstructions to set the interrupt priority levelInstructions 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 APIPackaged as a library
Typical system callsOpen/read/write/close the fileGet the current timeCreate a new processRequest more memory
OS Fall’02
Handling system calls An application executes a special trap
(syscall) instructionCauses 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 exampleopen(“/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 addressAssist 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 managementPaging, virtual memory
File system
OS Fall’02
Advanced topics Distributed systems
Communication, networking, middleware
Other possible topics:Reliable distributed systemsReal-time systems Parallel systemsModern 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