byu cs 345os overview (chapter 1)1 cs 345 stalling’s chapter#project 1: computer system overview...
TRANSCRIPT
BYU CS 345 OS Overview (Chapter 1) 1
CS 345
Stalling’s Chapter # Project
1: Computer System Overview2: Operating System Overview
4 P1: Shell
3: Process Description and Control4: Threads
4 P2: Tasking
5: Concurrency: ME and Synchronization6: Concurrency: Deadlock and Starvation
6 P3: Jurassic Park
7: Memory Management8: Virtual memory
6 P4: Virtual Memory
9: Uniprocessor Scheduling10: Multiprocessor and Real-Time Scheduling
6 P5: Scheduling
11: I/O Management and Disk Scheduling12: File Management
8 P6: FAT
Student Presentations 6
BYU CS 345 Project 1 - Shell 2
1. Compile and Validate
A task is a unit of execution (also referred to as a process). A shell (Command Language Interpreter) is a task that functions as an
interface between the user and an Operating System. A shell interprets textual commands coming either from the user’s
keyboard or from a script file and executes the commands either directly or creates a new child process to execute the command.
For Project 1: Download all the project files from class website.
os345.c, os345interrupts.c, os345signals.c os345tasks.c, os345semaphores.c os345.h, os345config.h, os345signals.h os345p1.c, os345p2.c, os345p3.c, os345p4.c, os345p5.c, os345p6.c os345park.c, os345park.h, os345lc3.c, os345lc3.h, os345mmu.c, os345fat.c,
os345fat.h Edit os345config.h (if necessary) to select host OS/IDE/ISA. (Only enable
one of the following defines: DOS, GCC, MAC, or NET.) Compile and execute your OS.
BYU CS 345 OS Overview (Chapter 1) 3
Why CS 345?
BYU CS 345 OS Overview (Chapter 1) 4
Operating Systems
What is an operating system? Hard to define precisely, because operating systems
arose historically as people needed to solve problems associated with using computers.
How about…“Software that makes computing power available to
users by controlling the hardware.”
“Software executes when nothing else is happening.”
“A collection of software modules including device drivers, libraries, and access routines.”
BYU CS 345 OS Overview (Chapter 1) 5
What Does a Modern OS Do?
Provides Abstractions: Hardware has low-level physical resources with
complicated, idiosyncratic interfaces. OS provides abstractions that present clean interfaces. Goal: make computer easier to use. Examples: Processes, Unbounded Memory, Files,
Synchronization and Communication Mechanisms. Provides Standard Interface:
Goal: portability. Unix runs on many very different computer systems.
BYU CS 345 OS Overview (Chapter 1) 6
What Does a Modern OS Do?
Mediates Resource Usage: Goal: allow multiple users to share resources fairly,
efficiently, safely and securely. Examples:
Multiple processes share one processor. (preemptable resource)
Multiple programs share one physical memory (preemptable resource).
Multiple users and files share one disk. (non-preemptable resource)
Multiple programs share a given amount of disk and network bandwidth (preemptable resource).
Consumes Resources: Solaris takes up about 8 Mbytes physical memory (or about
$400).
BYU CS 345 OS Overview (Chapter 1) 7
The Future…
In the future, computers will continue to become physically smaller and more portable.
Operating systems have to deal with issues like disconnected operation and mobility.
Media rich information within the grasp of common people - information with psuedo-real time components like voice and video.
Operating systems will have to adjust to deliver acceptable performance for these new forms of data.
BYU CS 345 OS Overview (Chapter 1) 8
Finally
Operating systems are so large no one person understands whole system. Outlives any of its original builders.
The major problem facing computer science today is how to build large, reliable software systems.
Operating systems are one of very few examples of existing large software systems, and by studying operating systems we may learn lessons applicable to the construction of larger systems.
Chapter 1 – Computer Systems
Let’s figure out what’s inside this thing...
OS Overview (Chapter 1) 10
Learning Objectives
Describe the basic elements of a computer system and their interrelationship.
Explain the steps taken by a processor to execute an instruction. Understand the concept of interrupts and how and why a processor
uses interrupts List and describe the levels of a typical computer memory
hierarchy. Explain the basic characteristics of multiprocessor and multicore
organization. Discuss the concept of locality and analyze the performance of a
multilevel memory hierarchy. Understand the operation of a stack and its use to support
procedure call and return.
BYU CS 345
OS Overview (Chapter 1) 12BYU CS 345
Computer Systems
Registers Interrupts Caching Input/Output Protection
Objectives
What is a computer system?
What are the basic elements of a computer system?
OS Overview (Chapter 1) 13BYU CS 345
Computer Systems
Registers Interrupts Caching Input/Output Protection Summary
Objectives
OS Overview (Chapter 1) 14BYU CS 345
CPURegisters
OS Overview (Chapter 1) 15BYU CS 345
Processor Registers
User-visible registers May be referenced by machine language Available to all programs - application programs and
system programs Data Registers – can be changed by user Address Registers – could be separate from data register Stack Registers – user / supervisor stacks Condition Codes – results of operations
Control and status registers May or may not be visible
Program Counter (PC) – address of next instruction Instruction Register (IR) – most recently fetched instruction MAR/MBR – memory reference registers Program Status Word (PSW) – condition codes, interrupts,
mode
Registers
OS Overview (Chapter 1) 17BYU CS 345
Lots of Registers…Registers
OS Overview (Chapter 1) 18BYU CS 345
Computer Systems
Registers
Interrupts Caching Input/Output Protection Summary
OS Overview (Chapter 1) 19BYU CS 345
Interrupts
The interrupt was the principle tool available to system programmers in developing multi-tasking systems!
Improves processing efficiency by allowing the processor to execute other instructions while an I/O operation is in progress
A suspension of a process caused by an event external to that process and performed in such a way that the process can be resumed
Interrupts
OS Overview (Chapter 1) 20BYU CS 345
Processing of Interrupts
Classes of Interrupts Program
arithmetic overflow division by zero execute illegal instruction reference outside user’s memory space
Timer I/O Hardware failure
An interrupt handler determines nature of the interrupt and performs whatever actions are needed Control is transferred to this program Generally part of the operating system
Interrupts
OS Overview (Chapter 1) 21BYU CS 345
Interrupt Cycle
Processor checks for interrupts If no interrupts fetch the next instruction for the current
program If an interrupt is pending, suspend execution of the
current program, and execute the interrupt handler
HALT
Fetch NextInstruction
Fetch NextInstruction
ExecuteInstruction
ExecuteInstruction
Check forInterrupt:
Process Interrupt
Check forInterrupt:
Process Interrupt
Fetch Cycle Execute Cycle Interrupt Cycle
InterruptsDisabled
InterruptsEnabled
START
Interrupts
OS Overview (Chapter 1) 23BYU CS 345
Multiple Interrupts
2 Choices Disable Interrupts
Disable upon entering an interrupt handler
Enable upon exiting Allow Interrupts
Allow an interrupt handler to be interrupted
Priorities?
Interrupts
OS Overview (Chapter 1) 26BYU CS 345
Computer Systems
Registers Interrupts
Caching Input/Output Protection Summary
OS Overview (Chapter 1) 27BYU CS 345
Memory Hierarchy
Registers
Cache
Main Memory
Disk Cache
Magnetic Disk
Magnetic Tape Optical Disk
More ExpensiveFaster & Smaller
BiggerSlower
Caching
OS Overview (Chapter 1) 31BYU CS 345
Computer Systems
Registers Interrupts Caching
Input/Output Protection Summary
OS Overview (Chapter 1) 32BYU CS 345
Programmed I/O
I/O module performs the action, not the processor
Sets appropriate bits in the I/O status register
No interrupts occur Processor is kept busy
checking status
Input / Output
OS Overview (Chapter 1) 33BYU CS 345
Interrupt-Driven I/O
Processor is interrupted when I/O module ready to exchange data
Processor is free to do other work
No needless waiting Consumes a lot of processor
time because every word read or written passes through the processor
Input / Output
OS Overview (Chapter 1) 34BYU CS 345
Direct Memory Access
Transfers a block of data directly to or from memory
An interrupt is sent when the task is complete
The processor is only involved at the beginning and end of the transfer
What does this mean with respect to a paged system?
Input / Output
OS Overview (Chapter 1) 35BYU CS 345
Computer Systems
Registers Interrupts Caching Input/Output
Protection Summary
OS Overview (Chapter 1) 36BYU CS 345
Hardware Protection
Why protect hardware? From what?
Shared hardware resources – memory, disk, … Errant programs
How? CPU provides 2 modes of operation
User Mode (non-privileged) Supervisor mode (privileged)
Privileged instructions can only be executed in monitor mode
All I/O instructions are privileged
Protection
Summary…
OS Overview (Chapter 1) 41BYU CS 345
What is an O.S.?
Not always a clear definition as to what constitutes an O.S. and what is an application
CD-Rom Driver Scandisk Internet Explorer
Intermediary between the hardware and the users Allocate resources (CPU, Memory, disk space, etc.) between
programs and users efficiently Allow the user to conveniently access data and programs Protect the system from incorrect or malicious programs and
users
Summary
OS Overview (Chapter 1) 42BYU CS 345
Hardware Review
Elements of a system:· Processor
Registers (address, data, control) Instruction cycle (fetch, decode, execute) Interrupts Usually includes hardware and special instructions to help
the O.S. manage memory, devices, etc.· Memory
Different levels (cache, main memory, disk) Operating system will generally manage memory (both
RAM and disk), and move data back and forth as required· I/O
Usually use Interrupts, DMA Operating system usually controls use of I/O devices
Summary
OS Overview (Chapter 1) 43BYU CS 345
Registers
Used for frequently accessed items User-Visible registers – Available to the programmer and
compiler Data Registers Address Registers (Index, Segment, Stack Pointer) Condition code/flags
Control and Status registers – Used to control the processor
Program Counter/Instruction Pointer Memory address/data Processor Status Word Debugging registers Temp registers Memory Management registers
Summary
OS Overview (Chapter 1) 44BYU CS 345
Interrupts
Interrupts Allow I/O devices to get the CPUs attention at regular
intervals (Program, Timer, I/O, Hardware failure) Helps the O.S. by reducing the time spent monitoring
I/O devices CPU checks for interrupts after each instruction, starts
the handler if needed May allow nested interrupts
I/O techniques Programmed I/O Interrupt-Driven I/O Direct Memory Access
Summary
OS Overview (Chapter 1) 45BYU CS 345
Interrupts and I/O
Handling and Interrupts: Figure 1.10 (pg 23) Device sends interrupt request to CPU CPU finishes current instruction CPU acknowledges request CPU saves PC and PSW CPU loads PC with the address of the first instruction in the
interrupt handler (may get help from interrupt request) Interrupt handler starts, often saves other CPU registers and key
values Interrupt handler responds to the device Interrupt handler restores CPU registers and key values CPU restores PC and PSW and resumes previous program
Summary
OS Overview (Chapter 1) 46BYU CS 345
Memory
Varying types of memory Registers, Cache, RAM, Disk, CD Vary in speed, size, cost CPU and O.S. try to keep frequently used data in faster memory
Cache – Use a small high-speed memory to improve the apparent speed of a larger low-speed memory
Keep track of what is currently being used, load into high-speed memory
Replacement Algorithm – What do we get rid of when we run out of memory?
Write Policy – How do we respond to modifications?
Summary
OS Overview (Chapter 1) 47BYU CS 345
OS Overview (Chapter 1) 48BYU CS 345
Topics to Cover…
OS Objectives OS Services Resource Manager Evolution Achievements
Processes Memory management Information protection and security Scheduling and resource management System architecture