Computer Systems - BYU Computer Science Students Homepage

advertisement

CS 345

Stalling’s Chapter

1: Computer System Overview

2: Operating System Overview

3: Process Description and Control

4: Threads

5: Concurrency: ME and Synchronization

6: Concurrency: Deadlock and Starvation

7: Memory Management

8: Virtual memory

9: Uniprocessor Scheduling

10: Multiprocessor and Real-Time Scheduling

11: I/O Management and Disk Scheduling

12: File Management

Student Presentations

BYU CS 345

#

4

4

6

6

6

8

6

OS Overview (Chapter 1)

Project

P1: Shell

P2: Tasking

P3: Jurassic Park

P4: Virtual Memory

P5: Scheduling

P6: FAT

1

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 Project 1 - Shell 2

Why CS 345?

BYU CS 345 OS Overview (Chapter 1) 3

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) 4

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) 5

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) 6

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) 7

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.

BYU CS 345 OS Overview (Chapter 1) 8

Chapter 1 – Computer Systems

Let’s figure out what’s inside this thing...

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) 10

Objectives

Computer Systems

What is a computer system?

What are the basic elements of a computer system?

Registers

Interrupts

Caching

Input/Output

Protection

BYU CS 345 OS Overview (Chapter 1) 12

Computer Systems

Registers

Interrupts

Caching

Input/Output

Protection

Summary

BYU CS 345 OS Overview (Chapter 1)

Objectives

13

Registers

CPU

BYU CS 345 OS Overview (Chapter 1) 14

Registers

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

BYU CS 345

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

OS Overview (Chapter 1) 15

Lots of Registers…

Registers

BYU CS 345 OS Overview (Chapter 1) 17

Computer Systems

Registers

Interrupts

Caching

Input/Output

Protection

Summary

BYU CS 345 OS Overview (Chapter 1) 18

Interrupts

Interrupts

The interrupt was the principle tool available to system programmers in developing multitasking 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

BYU CS 345 OS Overview (Chapter 1) 19

Interrupts

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

BYU CS 345 OS Overview (Chapter 1) 20

Interrupts

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

START

BYU CS 345

Fetch Cycle

Fetch Next

Instruction

Execute Cycle Interrupt Cycle

Interrupts

Disabled

Execute

Instruction

Interrupts

Enabled

Check for

Interrupt:

Process Interrupt

HALT

OS Overview (Chapter 1) 21

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?

BYU CS 345 OS Overview (Chapter 1)

Interrupts

23

Computer Systems

Registers

Interrupts

Caching

Input/Output

Protection

Summary

BYU CS 345 OS Overview (Chapter 1) 26

Caching

Memory Hierarchy

More Expensive

Faster & Smaller

Registers

Cache

Main Memory

Disk Cache

Magnetic Disk

Magnetic Tape Optical Disk

BYU CS 345 OS Overview (Chapter 1)

Bigger

Slower

27

Computer Systems

Registers

Interrupts

Caching

Input/Output

Protection

Summary

BYU CS 345 OS Overview (Chapter 1) 31

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

BYU CS 345 OS Overview (Chapter 1)

Input / Output

32

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

BYU CS 345 OS Overview (Chapter 1)

Input / Output

33

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?

BYU CS 345 OS Overview (Chapter 1)

Input / Output

34

Computer Systems

Registers

Interrupts

Caching

Input/Output

Protection

Summary

BYU CS 345 OS Overview (Chapter 1) 35

Protection

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

BYU CS 345 OS Overview (Chapter 1) 36

Summary…

Summary

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

BYU CS 345 OS Overview (Chapter 1) 41

Summary

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

BYU CS 345 OS Overview (Chapter 1) 42

Summary

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

BYU CS 345 OS Overview (Chapter 1) 43

Summary

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

BYU CS 345 OS Overview (Chapter 1) 44

Summary

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

BYU CS 345 OS Overview (Chapter 1) 45

Summary

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?

BYU CS 345 OS Overview (Chapter 1) 46

BYU CS 345 OS Overview (Chapter 1) 47

Topics to Cover…

OS Objectives

OS Services

Resource Manager

Evolution

Achievements

Processes

Memory management

Information protection and security

Scheduling and resource management

System architecture

BYU CS 345 OS Overview (Chapter 1) 48

Download