Title: We will focus on operating system concepts
1- We will focus on operating system concepts
- What does it do? How is it implemented?
- Apply to Windows, Linux, Unix, Solaris, Mac OS X.
- Will discuss differences between implementations.
- Will use programming to enhance our understanding
of basic concepts.
2Todays Topics
- High level view of Operating System
- Interrupts
- Context Switches
- Multiprogramming
- Timesharing
- Protection of system resources.
3Components of a Computer System
User
User
User
User
System and application Programs
Web Browsing Text Editor
Database Compiler
Operating System
Hardware
- System and Application Programs
- Operating System
- Hardware (CPU, memory, I/O devices).
4Components of a Computer System
App1
App2
App3
App4
System and application Programs
Web Browsing Text Editor
Database iTunes
Operating System
Hardware
- System and Application Programs
- Operating System
- Hardware (CPU, memory, I/O devices)
5- System programs make our lives easier but are not
part of the Operating System. - Compilers, editors, linkers, loaders, shells.
- Operating System performs two functions
- Allocates, schedules, manages, and protects
system resources. - Provides a convenient interface to system
resources. - Dont want to have to write device driver to
store files on disk.
6Interrupts
- Operating systems are interrupt-driven.
- Perform action, such as giving control of the CPU
to an application, then does not regain control
of CPU until an interrupt occurs.
7- CPU and other devices can run concurrently.
- Can start I/O operation and start application
executing. - When requested operation completed, device
generates hardware interrupt. - User programs generate interrupts when making
system calls (requesting service from OS) - TRAP instruction.
- Generally termed software interrupt.
8Interrupts
- When an interrupt is generated, the CPU stops
what it is doing and execution is transferred to
the appropriate interrupt handler. - Addresses of interrupt handlers are found in the
interrupt vector. - Table of addresses
- Each device (and TRAP) has a particular offset
within the table
9Interrupt Vector
100 500 800 1500
0
1
2
3
0 I/O Device 1 1 I/O Device 2 2 NIC 3 TRAP
10Interrupts
- Consider some Joe_Program (nickname is JP or Joe)
executing and a device issues an interrupt. - Need to jump to interrupt handler, but
11Interrupts
- Consider some Joe_Program executing and a device
issues an interrupt. - Need to jump to interrupt handler, but
- What do we do with Joe?
12Interrupts
- Consider some Joe_Program executing and a device
issues an interrupt. - Need to jump to interrupt handler, but
- What do we do with Joe?
- What is the minimal information to save to be
able to restart his execution?
13Interrupts
- Consider some Joe_Program executing and a device
issues an interrupt. - What do we do with Joe?
- What is the minimal information to save to be
able to restart his execution? - Address of the next instruction.
14- What if interrupt processing routine needs to use
all of the CPU registers?
15- What if interrupt processing routine needs to use
all of the CPU registers? - Better save a copy of the state of all of the
registers PJ is using.
16- Once interrupt routine completed, how do we get
JP restarted?
17- Once interrupt routine completed, how do we get
JP restarted? - Restore state of registers
- Set the Instruction Pointer to the next
instruction JP was going to execute. - It should appear to JP as if its execution was
never interrupted.
18- Saving and restoring application state is termed
a context switch.
19Operating System Structure
- A key concept of operating systems is
multiprogramming (or multitasking). - Technique developed because CPU and I/O device
time were very expensive. - Basic idea
- Keep multiple jobs in memory.
- When one job blocks on I/O, the CPU immediately
switches to another job.
20- This keeps CPU and I/O devices fully utilized.
- Without multiprogramming, CPU would be idle
during I/O operations. - First developed for batch systems in the 60s.
- No interactions between user and programs.
21Multiprogramming Batch Systems
Problem CPU and I/O very expensive. Solution
Multiplex CPU between multiple jobs.
22Time-Sharing SystemsInteractive Computing
- Logical extension of multiprogramming.
- The CPU is multiplexed among several jobs that
are kept in memory and on disk (the CPU is
allocated to a job only if the job is in memory). - A job swapped in and out of memory to the disk.
- Each user is executing a shell program.
- Takes user command and executes it.
- Waits for the next command.
23Time-Sharing SystemsInteractive Computing
- Goal is to give the illusion that each user has
own machine. - Response time is a priority.
24Protection of System Resources
- I/O Devices
- Memory
- CPU
- Files
25Protection of System Resources
- Based on dual-mode execution
- kernel mode and user mode.
- Privileged instructions can be issued only in
kernel mode. - Mode bit in PSW, checked on every instruction.
26User process executing
Mode Bit1
Continue Execution
System Call
Trap, mode bit 0
Return. Mode bit 1
Execute System Call
27Protection of I/O Devices
- All I/O instructions are privileged instructions.
- Only accessed through system calls.
28Memory Protection
- Must provide memory protection for the interrupt
vector, interrupt service routines, and other
applications address space. - Two registers that determine the range of legal
addresses a program may access - Base register holds the smallest legal physical
memory address. - Limit register contains the size of the range
- Memory outside the defined range is protected.
29Use of A Base and Limit Register
30Hardware Address Protection
31CPU (and OS) Protection
- Keep user from monopolizing CPU.
- Ensure OS regains control of CPU.
32CPU Protection
- Timer interrupts computer after specified
period to ensure operating system maintains
control. - Timer is decremented every clock tick.
- When timer reaches the value 0, an interrupt
occurs. - Timer commonly used to implement time sharing.
33Privileged Instructions
- Load base and limit registers?
34Privileged Instructions
- Load base and limit registers?
- Set the system timer?
35Privileged Instructions
- Load base and limit registers?
- Set the system timer?
- Read the system clock?
36Privileged Instructions
- Set the system timer?
- Read the system clock?
- Load base and limit registers?
- Open a file?
37Privileged Instructions
- Load base and limit registers?
- Set the system timer?
- Read the system clock?
- Open a file?
- Compile a program and create executable?
38Privileged Instructions
- Load base and limit registers?
- Set the system timer?
- Read the system clock?
- Open a file?
- Compile a program and create executable?
- Enable/disable interrupts?