Introduction

Download Report

Transcript Introduction

CSCE451/851
Introduction to Operating Systems
http://cse.unl.edu/~ylu/csce451
https://piazza.com/unl/spring2017/csce451/home
Chapter 1 -Introduction
What is an operating system?
Interface between application programs and hardware
Basic purpose of an operating system?
Provide services to application programs
Control functioning of hardware
From a user’s point of view
Ease of use <-> maximize work (or play) that user performs
From a system’s point of view
Resource allocator
Components of a Computer
System
user1
user2
editor
ie
user n
calc
app x
applications
Operating System
hardware
1.2 Computer System Organization
Most (if not all) modern CPU design is based on interrupts
The CPU has various lines thru which a signal can be sent
(interrupt)
Interrupts can originate from hardware, cpu(trap),
software(system call)
Interrupts are provided as a way to improve processor
performance
Hardware interrupts can happen very frequently and must be
handled promptly and efficiently
Handling an Interrupt
Interrupt vector – an array of pointers to interrupt service
routines indexed by the interrupt number
When the CPU is interrupted:
CPU saves address of interrupted instruction
Invokes interrupt service routine whose address is stored in the
Interrupt vector
After the interrupt is serviced, the saved instruction address (and
state) is restored and CPU resumes
Program Flow of Control
I/O Structures (1.2.3)
A large part of operating system code is dedicated to managing
I/O
Reliability
Performance
Various types of devices available
I/O is achieved through synchronization between
Operating system code called device drivers
Device controllers which transfer data between hardware and
internal buffers
Interrupts which invoke the correct device drivers
Device Controller Interface
.. busy done Error codes ..
Primary
Memory
Cpu
Instruction
Status
Data
Data
Dev. Ctrlr.
Logic
Data n-1
Device
I/O Structures (Character I/O)
Example of slow input device-keyboard
DC loads data register and interrupts CPU
CPU invokes DD - Interrupt Vector
DD fetches data from DC data register and transfers data to
memory location
Example of serial output device-printer
OS Invokes DD
DD loads data/instruction register on DC
DC interrupts CPU when its done
DD checks status registers, raises error or loads next
data/instruction on DC
I/O Structure – Block Devices
Character I/O is not effective enough for bulk data movement,
Disks etc.
An alternative to character I/O is block I/O (DMA)
O/S sets up registers (instruction, buffer address, size etc.) in
the DC
DC transfers data directly to memory, interrupts CPU only to
signal completion/error
Interrupt I/O vs. Direct Memory Access
Primary
Memory
Input
Primary
Memory
LOAD COMMAND*
INTERRUPT CPU
GET STATUS
Input/Output
XFER DATA
LOAD COM., ADD. & SIZE
Cpu
Cpu
XFER DATA
Interrupt CPU on Completion
Output
Dev. Ctrlr.
XFER DATA
GET STATUS
Dev. Ctrlr.
LOAD COMMAND
INTERRUPT CPU
GET STATUS
Device
Device
1.3 Computer System Architecture
Self Read
Must know the difference between Symmetric and Asymmetric
systems.
The evolution of OS
1.4 Operating System Structure
Multiprogramming - keep multiple jobs
in memory, switching between them
when the CPU is idle. Improve
utilization of computer system
OS
Time sharing – switching between jobs
based on timer
Switches between jobs very frequently
Each user/process is given the
impression that they have sole access
to the system
Job 1
Job 2
Job 3
Job n
Multitasking and Timesharing
First multitasking operating systems such as DOS were
introduced to improve CPU efficiency
Then Time shared systems such as Unix and Windows to allow
multiple “simultaneous” program execution
The O/S need to save the state of each program during
interrupts, it needs to schedule the programs etc.
To support the above and other issues, the concept of a
process was created (Chapter 3)
1.5 Modes of Operation
How do we prevent user processes from writing to Device
Controller registers?
Most systems support at least two modes of operation: the user
mode and the kernel mode
Dual-Mode Operation
Only User code is allowed to execute when CPU is in user mode
All Operating System code is available when CPU is in Kernel mode
What if a user process needs some OS service?
System calls (S/C) provide the means for a user program to ask the OS to perform
tasks reserved for the OS on the user program’s behalf
Process Scheduler
USB Device Driver
Create File S/C
Create Process S/C
Virtual memory Mgr
PCI Device Driver
Read File S/C
Kill Process S/C
Write File S/C
Signal Process S/C
Inter Process
Communication
Locks & Synch.
Dual Mode Operation
To support a stable and secure system, a dual-mode CPU was
introduced
Various instructions and memory addresses could only be
accessed in Kernel mode
To access service routines only available in the kernel (open a
file, write a character to terminal, etc), a user process makes
system calls
Interrupt handlers are invoked to handle these system calls
Dual Mode Operation
A system call allows a user process to request a protected
service form the operating system
The system call number along with arguments are stored in
well defined registers and a special instruction is executed
The cpu is placed in kernel mode and the system call service
routine is executed
The operating system determines the service the user
process is requesting and verifies the arguments
When complete, results are placed in the users process
space and the cpu is placed back in user mode
Execution continues with the next instruction
Dual Mode Operation
The CPU is placed in kernel mode when an
interrupt/trap/system call is received
User process
call sys call
resume user process
user mode
mode bit=1
return
mode bit = 1
mode bit = 0
Execute Sys Call
kernel mode
mode bit=0
The Timer
The CPU timer interrupts the CPU during predetermined
intervals
Most timers are variables and can be set to interrupt the CPU
after the user process has executed for a predetermined
amount of time
Instructions that update the timer must be privileged
instructions
Ensures that the OS maintains control of the CPU
OS always sets time before turning over control to user
Other O/S Responsibilities
Discuss tasks the operating system would be responsible for
each of the subsystems listed below
Memory management (Chap 1.7)
Process management (Chap 1.6)
Storage management (Chap 1.8)
Protection and Security (Chap 1.9)
Reading Assignment.
By this Friday
Read Chapter 3