Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Basic Concepts: Operating Systems CS222

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 36

Basic Concepts

Operating Systems
CS222
----¤----

Most Slides contents have been arranged by Dr. Matthew Dailey, based on © Silberschatz, Galvin, and Gagne, 2002

----¤----

1
Operating Systems

The software that turns a hunk of electronics into something you can use.
This semester, we will learn how OS’s work.
As users, this helps us get more out of any OS.
As programmers, this helps us
– build our own large end-user applications
– exploit the special features of particular OS’s

Chapter 1: Introduction for the Operating Systems 2


Outline

I. Purpose of operating systems

II. History of operating systems

III. Interrupts and system calls

Chapter 1: Introduction for the Operating Systems 3


Purpose of Operating Systems

4
Purpose of Operating Systems

The OS is an
intermediary between
the system’s hardware
and its users.

Also called the kernel:


the one program
always running

Chapter 1: Introduction for the Operating Systems 5


Purpose of Operating Systems

Goal of an OS: to provide a convenient and efficient environment


for executing programs.

When there is more than one program or user, an additional goal


is to provide a safe environment.
– Programs should not be able to interfere with other programs.
– Users should not be able to interfere with other user’s programs
or data.

Chapter 1: Introduction for the Operating Systems 6


Chapter 1: Introduction for the Operating Systems 7
Purpose of Operating Systems

Purpose of an OS also depends on


– what hardware is being used.
– who the users are.

User/programmer point of view


– We don’t want to know all the details of the hardware.
– The OS provides a simple abstract system model.

System point of view


– Resources (CPU time, memory, IO devices, etc) need to be
managed.
– The OS is a resource allocator.

Chapter 1: Introduction for the Operating Systems 8


History of Operating Systems

9
History of Operating Systems
The computer’s main memory address space
Early days: mainframe batch systems Memory location 0

Users would submit a job:


– Stack of punch cards operating
– Includes the program, input data, and control system
instructions
Operator would organize jobs and run in batches
– One program resident in memory at any time
user program
Slow operators / card readers / output devices mean area (only
CPU underutilized ONE program)

Memory location 512K

Chapter 1: Introduction for the Operating Systems 10


History of Operating Systems: Multiprogramming
The computer’s main memory address space

Memory location 0

Multiprogrammed Systems: operating


– Keep more than one running job in memory system
– When one job waits for IO, switch to a
different job job 1

job 2
Increases CPU utilization

job 3

job 4
Memory location 512K

Chapter 1: Introduction for the Operating Systems 11


History of Operating Systems: Multiprogramming

Multiprogramming allows time sharing


– Multiple simultaneous users interacting with the system
– CPU switches between jobs fast enough for interactive use

Process execution state diagram:

IO Request
RUNNING BLOCKED

IO Completion
Kernel Selection

READY

Chapter 1: Introduction for the Operating Systems 12


History of Operating Systems: Multiprogramming

Chapter 1: Introduction for the Operating Systems 13


History of Operating Systems: Types of computer systems

Desktop systems:
– Initially simple, with batch operation e.g. MS-DOS
– Evolved multiprogramming and time sharing in 80s and 90s
– Evolved graphical user interfaces
– Maximal convenience for user; efficiency secondary

Multiprocessor systems:
– More than one CPU to divide the workload
– Symmetric multiprocessing: all CPUs run same OS
– Asymmetric multiprocessing: master CPU assigns individual tasks to
slave CPUs
– Increasingly common in network servers and even desktops

Chapter 1: Introduction for the Operating Systems 14


15
16
17
18
19
20
Interrupts and system calls

21
Von Neumann Architecture, Modern Style

Chapter 1: Introduction for the Operating Systems 22


Von Neumann Architecture, Modern Style

CPU and device controllers operate independently, and are


connected by a shared bus to shared memory.

The memory controller synchronizes access to memory.

Chapter 1: Introduction for the Operating Systems 23


Interrupts

Most modern systems are interrupt-driven.


If nothing is happening (no programs are ready to run, no IO devices are
waiting for service, and no users are making requests),
then the system sits idle, waiting for an event.
Events are signaled by interrupts.
• Hardware interrupts: usually triggered when a device enables a line on the system bus,
e.g. IRQn on i386
• Software interrupts (also called traps):
–Software errors (divide by 0, invalid memory access)
–System calls (requests for service by the kernel)

[“Trap” is a metaphor for falling through a door from user space execution to kernel mode execution.]

Chapter 1: Introduction for the Operating Systems 24


Interrupts

When a hardware interrupt occurs,


– CPU stops what it is doing and transfers control to an interrupt
service routine (ISR)
– May be different ISRs for different types of interrupts. The list of
ISR locations is called the interrupt vector.
– Example: the Intel 386 architecture contains 16 interrupt lines
(IRQ0-IRQ15), requiring a 16-element interrupt vector.
– After servicing the interrupt, the CPU returns to what it was
previously doing. This requires save and restore of process
context (program counter, registers, etc.).

Chapter 1: Introduction for the Operating Systems 25


Interrupts during I/O

For a single process accessing output device:


1. Process generates output but continues.
2. Transfer begins. When done, IO device signals an interrupt.
3. CPU switches to ISR, services the interrupt, then returns to the user process.

Chapter 1: Introduction for the Operating Systems 26


Protection

Protection architecture: with resource sharing, processes and their


data must be protected from other processes.

Also, errors detected by hardware (e.g. divide by 0) should not crash


the system. Instead trap to the kernel:
– Kernel logs an error message, dumps process memory, and so on.
– Kernel frees resources associated with the bad process and
continues normal system operation.

Chapter 1: Introduction for the Operating Systems 27


28
29
I/O protection SYSTEM MEMORY


System call system call routine:
Check access privileges
sequence for I/O  Jump to routine for
system call n
MONITOR 
RESIDENT


read routine:
perform the read (2) Perform
return control to user the I/O
(1) Trap to …
Monitor

 …


USER system call n (e.g. a read) (3) Return
PROGRAM … control
 to user

Chapter 1: Introduction for the Operating Systems 30


I/O protection

Typically, all I/O operations are privileged.

User program requesting I/O WHY?


– Issues a system call
– System call generates a software interrupt (trap)
– Trap causes bit flip to kerenal mode and ISR to run
– Kernel ISR checks whether user process has permission to access
the requested device.
– If legal, executes (or queues) the request then flips the mode bit
back to user mode.

Chapter 1: Introduction for the Operating Systems 31


System calls

System calls: the main interface between user programs and


the kernel.

Available as special assembly language instructions or high-


level language function calls.

Chapter 1: Introduction for the Operating Systems 32


System calls

System call categories:


– Process control (creation, deletion, suspension, load, execute,
get/set attributes, wait, allocate memory)
– File management (creation, deletion, open, close, read, write, seek,
get/set attributes)
– Information maintenance (time-of-day, system data)
– Communications (create channel, delete channel, send, receive,
transfer, attach)
Most systems use message passing and/or shared memory for IPC

Chapter 1: Introduction for the Operating Systems 33


System calls

Syscall interface between user processes and kernel (in Unix):

Chapter 1: Introduction for the Operating Systems 34


Operating System Structures: System calls

Sequence of system calls for “cp hw1.pdf hw2.pdf”:


– execve(): morph the child process into a “cp” instance
– Setup: many calls to get OS info, read DLLs into memory, etc.
– stat(“hw1.pdf”) to get file information and status
– stat(“hw2.pdf”)
– open(“hw1.pdf”) to open the file
– open(“hw2.pdf”)
– read() get a block of data from first file
– write() write the block of data to the second file
– (repeat many times)
– close() first file
– close() second file

Chapter 1: Introduction for the Operating Systems 35


What have we learned?

What the OS does for us.


How the modern OS evolved.
Basic computer architecture: interrupts.
How the OS services user programs via system calls.

Chapter 1: Introduction for the Operating Systems 36

You might also like