slides - Simon Fraser University

Download Report

Transcript slides - Simon Fraser University

School of Computing Science
Simon Fraser University
CMPT 300: Operating Systems I
Dr. Mohamed Hefeeda
1
Course Objective
 Understand the basic principles of designing and
implementing operating systems
 Why study OS?
 Be better developer (system and application levels)
 Be better computer user
 Use OS concepts in many different CS areas and
courses
2
Course Info
 Textbook
 Silberschatz, Galvin, Gagne, Operating System
Concepts, (We will refer to it as OSC)
 Grading
 Assignments: 25% (problem sets and programming
projects)
 Midterm exam: 25%
 Final exam:
50%
 Web page
 http://www.cs.sfu.ca/~mhefeeda/
3
Topics
 Operating System Structures
 Processes and Threads
 CPU Scheduling and Process Coordination
 Memory Management
 Storage Management and File Systems
 I/O Systems
 Security and Protection (time permits)
4
Chapter 1: Introduction
5
Objectives
 To provide coverage of basic computer system
organization
 To provide a grand tour of the major operating
system components
6
Computer System Structure
 Computer system has four components
 Hardware – provides basic computing resources
• CPU, memory, I/O devices
 Operating system
• Controls and coordinates use of hardware among
various applications and users
 Application programs – define the ways in which system
resources are used to solve computing problems
• Word processors, compilers, web browsers,
database systems, video games
 Users
• People, machines, other computers
7
Computer System Components
8
Operating System Definition
 OS is a program that acts as an intermediary
between users and computer hardware
 OS is a resource allocator
 Manages all resources
 Decides between conflicting requests for efficient and
fair resource use
 OS is a control program
 Controls execution of programs to prevent errors and
improper use of the computer
 OS performs no useful function by itself;
 It provides environment for programs to do useful work
 Can you give an example entity from real life?
 Well, the government!
9
Operating System Goals
 Make the computer system convenient to use
 Execute user programs and make solving user
problems easier
 Emphasized in PCs, handheld devices
 Use computer hardware in efficient manner
 Emphasized in large-scale computers with many users
and expensive hardware (e.g., airline reservation
system)
 Note:
 The OS kernel: is a program running at all times
 Everything else is either a system program (ships with
the operating system) or an application program
10
Computer System Organization
 One or more CPUs, device controllers connect
through common bus to a shared memory
11
Computer System Operation
 I/O devices and CPU can execute concurrently
 Each device controller
 is in charge of a particular device type
 has a local buffer
 I/O is performed from device to local buffer
 CPU moves data between main memory and local
buffers
 Device controller informs CPU that it has finished
its operation by causing an interrupt
12
Interrupt Handling
 OS preserves state of CPU by storing registers and
the program counter
 The corresponding interrupt handler is called to
process the interrupt
 How would OS locate the correct handler?
 In many systems (Windows, Linux), an interrupt vector is
stored in the lowest memory locations
 Each entry contains the address of a handler routine in
the memory
 Each interrupt number is mapped to an entry in the
interrupt vector
13
Storage Systems: Hierarchy
 Storage
systems
 Speed
 Cost
 Volatility
14
Comparison of Storage Systems
15
Caching
 Caching
 Information is copied from slower to faster storage
 performed at many levels in a computer (HW, OS, SW)
 Faster storage (cache) checked first to
determine if information is there
 If it is, information used directly from cache (fast)
 If not, data copied to cache and used there
16
Caching Example:
Migration of Integer A from Disk to Register
 Movement between levels of storage hierarchy
can be explicit or implicit
 Multitasking environments must be careful to use
most recent value, no matter where it is in the
storage hierarchy
Cache consistency
17
Operating System Operations
 OS is interrupt (event) driven: sits idle till
something happens
 Interrupts are generated by hardware devices
 Traps (or exceptions) are software-generated interrupts
due to
• software errors, e.g., divide by zero, illegal memory
access
• Request for operating system services (system calls)
 OS operates in two modes
 User mode and kernel mode
 Mode bit provided by hardware to indicate current mode
18
Operating System Operations (cont’d)
 Privileged Instructions
 Subset of instructions that may harm the system
 Can only be executed in kernel mode
 E.g., I/O control, timer management, interrupt
management
 Why dual mode?
 To enable OS to protect the hardware and itself from
users’ codes (which may be buggy and/or malicious), and
to protect users from each other
 If privileged instructions can only be executed in
kernel mode, how can users’ codes use them?
 Using System Calls (interrupts generated by software)
19
Transition from User to Kernel Mode
 User’s code issues a system call
 Mode is changed to kernel mode
 OS first checks that everything (e.g., parameter values) is in
order and legal
 Then, OS executes system call which may contain multiple
privileged instructions
 mode is set again to user mode
20
More Protection: Timer
 Timer to prevent program from holding
resources (CPU) for too long, e.g., infinite loop
 How it works
 Before giving control to a user program, OS sets a
timer to a specific value
 After period expires, an interrupt is issued and OS
regains control
 OS then decides whether to grant more time for the
program or terminate it
21
Multiprogramming in OS
 Multiprogramming
 Multiple jobs are kept in memory so that
CPU always has something to execute
 needed for efficiency, a single job may
not keep CPU and I/O devices busy at all
times
 One job is selected to run via CPU
scheduler
 When the job has to wait (for I/O for
example), OS switches to another job
 Timesharing (multitasking)
 CPU switches jobs so frequently that
users can interact with each job while it
is running, creating interactive
computing
22
Summary
 OS is a layer between user and hardware to make life
easier for user and use hardware efficiently
 Computer organization
 CPU(s), memory, and I/O devices connect to a common bus
 Devices request CPU attention through interrupts
 Storage hierarchy: speed, cost, volatility
 Caching: copy frequently-used data to faster storage
 Multiprogramming: multiple jobs in memory  efficiency
 Timesharing: frequently switch between jobs  interactive
 Dual mode operation: user and kernel modes
 Protect OS and users from each other
 Privileged instructions executed only in kernel mode
 Timer to prevent processes from holding resources forever
23