Operating Systems - PowerPoint PPT Presentation

About This Presentation
Title:

Operating Systems

Description:

It is the first piece of software to run after boot ... Handlers are registered during the boot. OS Fall'02. Interrupt types (I) ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 31
Provided by: GregoryC9
Category:

less

Transcript and Presenter's Notes

Title: Operating Systems


1
Introduction
  • Operating Systems
  • Fall 2002

2
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

3
Todays plan
  • Operating system functionality
  • Hardware support for the operating system
  • Course overview, bibliography, administrative
    questions

4
The Operating System controls the machine
gdb
gcc
User
OS Kernel
grep
diff
Hard ware
Application
date
vi
Operating System
xterm
emacs
Hardware
netscape
5
A better picture
Many applications
Application
One Operating System
System calls
Operating System
One Hardware
Privileged instructions
Machine instructions
Hardware
6
A typical scenario
  • OS executes and schedules an application to run
  • Application runs
  • CPU executes apps instructions
  • OS is not involved
  • The system clock interrupts the CPU
  • Clock interrupt handler is executed
  • The handler is the OS function

7
A typical scenario (continued)
  • In handler OS chooses another application to run
  • Context switch
  • The chosen app. runs directly on the hardware
  • The app. performs a system call to read from a
    file

8
A typical scenario (continued)
  • 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
  • The third application runs
  • Note At any given time only one program is
    running
  • OS or a user application

9
The running application state diagram
Interrupt/ System call
Ready To run
Schedule
I/O completed
Application code runs
OS runs
Wait for I/O completion
Sleep
Resume execution of the app. code
10
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

11
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

12
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

13
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

14
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)

15
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

16
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

17
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

18
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

19
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

20
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

21
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

22
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

23
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

24
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 int80
  • A single entry serves all system calls (why?)

25
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() PCint80 // transfer
control to the gate routine Gate
routine switch(sys_call_num) case OPEN
26
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

27
What we are going to study
  • Performance evaluation (brief)
  • Process handling
  • Process concept, scheduling, concurrency control
  • Memory management
  • Paging, virtual memory
  • File system

28
Advanced topics
  • Distributed systems
  • Communication, networking, middleware
  • Other possible topics
  • Reliable distributed systems
  • Real-time systems
  • Parallel systems
  • Modern storage architectures

29
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

30
Next
  • Performance evaluation
Write a Comment
User Comments (0)
About PowerShow.com