Course Overview Who am I? Jonathan Walpole Professor at PSU since - - PowerPoint PPT Presentation

course overview who am i
SMART_READER_LITE
LIVE PREVIEW

Course Overview Who am I? Jonathan Walpole Professor at PSU since - - PowerPoint PPT Presentation

CS510 Operating System Foundations Jonathan Walpole Course Overview Who am I? Jonathan Walpole Professor at PSU since 2004, OGI 1989 2004 Research Interests: Operating System Design, Parallel and Distributed Computing Systems


slide-1
SLIDE 1

CS510 Operating System Foundations

Jonathan Walpole

slide-2
SLIDE 2

Course Overview

slide-3
SLIDE 3

Who am I?

Jonathan Walpole Professor at PSU since 2004, OGI 1989 – 2004 Research Interests: Operating System Design, Parallel and Distributed Computing Systems http://www.cs.pdx.edu/~walpole

slide-4
SLIDE 4

Class Goals

An OS foundations course for graduate students with little or no OS background Understand the basic concepts of operating systems

designing & building operating systems, not just using them!

Gain some practical experience so that it is not just words!

slide-5
SLIDE 5

Expectations

Our contract:

  • You try to understand the material
  • I try to help you understand the material
  • We all participate enthusiastically in the class
  • No cheating!

Its all about education, not earning credits

slide-6
SLIDE 6

Resources

Class mailing list

https://mailhost.cecs.pdx.edu/mailman/listinfo/cs510walpole

Teaching Assistant

  • Amit Joshi

Learn from me, Amit and from each other!

slide-7
SLIDE 7

Text Book

“Operating Systems: Three Easy Pieces” by

  • R. Arpaci-Dusseau

and A. Arpaci-Dusseau “The BLITZ System” by Harry Porter All are available freely on line.

slide-8
SLIDE 8

Programming Project

You will read, understand and write operating system code! We will use the BLITZ system

CPU emulator, assembler, high-level language, operating system, and debugging environment Simple enough to understand in detail how everything works! Realistic enough to understand in detail how everything works! Runs on x86/Linux, Mac, Sun etc You will implement locks, condition variables, concurrent resource managers, a threads pool, memory manager, system calls including fork(), and print “hello world” the hard way.

slide-9
SLIDE 9

Grading

Yes, you do need to come to class and do all

  • f the programming assignments!

Your grade will be based equally on:

  • Project (programming assignments)
  • Mid-term exam
  • Final exam

Don’t waste these opportunities to convince me that you have understood the material!

slide-10
SLIDE 10

Useful Links

Class web site

www.cs.pdx.edu/~walpole/class/cs510/fall2017/home.html Find my website from the faculty listing on the department

  • website. Follow teaching link to current classes
slide-11
SLIDE 11

What to do Next?

Assignment 0 Read the class web site Help me learn who you are:

  • send me an email with your photo

Assignment 1 Download, install and experiment with Blitz Read the Blitz documents Due one week from today! See class web site for project assignments

slide-12
SLIDE 12

Introduction to Operating Systems

  • 1. What is an Operating System?
  • 2. Review of OS-Related Hardware
slide-13
SLIDE 13

What is an Operating System?

A concurrent program that controls the execution of application programs and implements an interface between them and the computer hardware

slide-14
SLIDE 14

Operating System Roles

Abstract machine

Hide complex details of the underlying hardware Provide common API to applications and services Simplify application writing

The challenges:

Deciding what to hide and what to expose Defining suitable abstractions Efficient mapping to hardware

slide-15
SLIDE 15

Operating System Roles

Resource Manager

Control access to shared resources Implement global allocation policies

The challenges:

concurrency security performance

slide-16
SLIDE 16

Early Operating Systems

Before operating systems, application writers had to program all device access directly:

Load device command codes into device registers Handle initialization, recalibration, sensing, timing Understand physical characteristics and data layout Control motors Interpret return codes ...

I/O complicated application programs Application programs were difficult to maintain and port

The device code could be written just once and then shared!

slide-17
SLIDE 17

How to Access the Shared OS

Hardware

CPU, Memory, Disk, Network, Display, Mouse etc

Operating System

Software in high and low level languages

Applications

Software in high and low level languages

slide-18
SLIDE 18

Operating System Structure

Hardware

CPU, Memory, Disk, Network, Display, Mouse etc

Operating System Kernel

Abstractions: Processes, Threads, Files, Sockets, etc

System Call Interface

Calls: fork(), exec(), read(), write(), kill(), getpid() etc

Applications

slide-19
SLIDE 19

The Resource Manager Role

Allocating resources to applications

time sharing resources space sharing resources

Making efficient use of limited resources

improving utilization minimizing overhead improving throughput/good put

Protection via enforcement of allocations

slide-20
SLIDE 20

Resources to Allocate

Time Share Space Share CPU ? ? Memory ? ? Disk ? ? Network ? ?

slide-21
SLIDE 21

Enforcement by OS

Can the OS protect itself from applications? Can it protect applications from each other? Can it prevent direct access to hardware? Should it prevent direct access to hardware? The OS is just a program! How can it do all this?

slide-22
SLIDE 22

OS Needs Help from Hardware

The OS dilemma:

The OS is just a program!

When it is not running, it can’t do anything!

The OS’s goal is to run applications, not itself!

The OS needs help from the hardware in

  • rder to detect and prevent certain

activities, and to enforce allocations

slide-23
SLIDE 23

Brief Review of Hardware

Instruction sets define all that a CPU can do

They differ among CPU architectures But all have load and store instructions to move data between memory and registers Many instructions for comparing and combining values in registers

Examine the Blitz instruction set

Similar to SUN SPARC instruction set

slide-24
SLIDE 24

Basic Anatomy of a CPU

Program Counter (PC)

24

slide-25
SLIDE 25

Basic Anatomy of a CPU

Program Counter (PC)

Holds the memory address of the next instruction

25

slide-26
SLIDE 26

Basic Anatomy of a CPU

Program Counter (PC)

Holds the memory address of the next instruction

Instruction Register

26

slide-27
SLIDE 27

Basic Anatomy of a CPU

Program Counter (PC)

Holds the memory address of the next instruction

Instruction Register

Holds the instruction currently being executed

27

slide-28
SLIDE 28

Basic Anatomy of a CPU

Program Counter (PC)

Holds the memory address of the next instruction

Instruction Register

holds the instruction currently being executed

General Purpose Registers

28

slide-29
SLIDE 29

Basic Anatomy of a CPU

Program Counter (PC)

Holds the memory address of the next instruction

Instruction Register

holds the instruction currently being executed

General Purpose Registers

hold variables and temporary results

29

slide-30
SLIDE 30

Basic Anatomy of a CPU

Program Counter (PC)

Holds the memory address of the next instruction

Instruction Register

holds the instruction currently being executed

General Purpose Registers

hold variables and temporary results

Arithmetic and Logic Unit (ALU)

30

slide-31
SLIDE 31

Basic Anatomy of a CPU

Program Counter (PC)

Holds the memory address of the next instruction

Instruction Register

holds the instruction currently being executed

General Purpose Registers

hold variables and temporary results

Arithmetic and Logic Unit (ALU)

performs arithmetic functions and logic operations

31

slide-32
SLIDE 32

Basic Anatomy of a CPU

Stack Pointer (SP)

32

slide-33
SLIDE 33

Basic Anatomy of a CPU

Stack Pointer (SP)

holds memory address of a stack top

  • ne frame for parameters & local variables of each

active procedure

33

slide-34
SLIDE 34

Basic Anatomy of a CPU

Stack Pointer (SP)

holds memory address of a stack top

  • ne frame for parameters & local variables of each

active procedure

Status Register

34

slide-35
SLIDE 35

Basic Anatomy of a CPU

Stack Pointer (SP)

holds memory address of a stack top

  • ne frame for parameters & local variables of each

active procedure

Status Register

A word full of control flags/bits Includes the mode bit to determine whether the CPU will execute privileged instructions

35

slide-36
SLIDE 36

Program Execution

The Fetch/Decode/Execute cycle

  • fetch next instruction pointed to by PC
  • decode it to find its type and operands
  • execute it
  • repeat

At a fundamental level, this is all a CPU does -

  • It does not know which program it is executing!

36

slide-37
SLIDE 37

Fetch/Decode/Execute Cycle

PC IR

  • Reg. n
  • Reg. 1

… ALU CPU Memory

37

slide-38
SLIDE 38

The OS is Just a Program!

The OS is just a sequence of instructions that the CPU will fetch/decode/execute How can the OS cause application programs to run? How can applications cause the OS to run?

38

slide-39
SLIDE 39

How Can an OS Run Applications?

39

slide-40
SLIDE 40

How Can an OS Run Applications?

The OS must load the address of the application’s starting instruction into the PC Example:

  • computer boots and begins running the OS
  • OS code must get into memory somehow
  • fetch/decode/execute OS instructions
  • OS requests user input to identify application program/file
  • OS loads application (executable file) into memory
  • OS loads the address of the app’s first instruction into the PC
  • CPU fetches/decodes/executes the application’s instructions

40

slide-41
SLIDE 41

Will the OS Ever Run Again?

How can the OS guarantee that it will run again?

41

slide-42
SLIDE 42

How Can the OS Regain Control?

What if an application doesn’t call the OS and instead just hogs the CPU?

  • OS needs something to interrupt the CPU and

load OS instructions again

  • interrupts can be generated from a timer device
  • OS must register a future timer interrupt before

handing control of the CPU over to an application

  • When the timer interrupt goes off the hardware

starts running the OS at a pre-specified location called an interrupt handler

42

slide-43
SLIDE 43

What is an Interrupt?

Interrupt:

Hardware event that loads an address of an instruction into the PC

Interrupt handler:

An instruction sequence that has been associated with an interrupt Address of first instruction is registered with the interrupt hardware by filling in an interrupt vector

43

slide-44
SLIDE 44

Interrupts

Interrupts are a form of event-based programming

Also known as reactive programming

Interrupt handlers are invoked in response to hardware events

Invocation order is not known a priori Their execution is interleaved with existing execution sequences, unless prevented by disabling interrupts

44

slide-45
SLIDE 45

Can Applications Cheat the Timer?

Can the application disable the future timer interrupt so that the OS can not take control back from it?

45

slide-46
SLIDE 46

Can Applications Cheat the Timer?

Disabling interrupts must be a privileged instruction that is not executable by applications The CPU knows whether or not to execute privileged instructions based on the value of the mode bit in the status register Privileged instructions are only executed if the mode bit is set

  • attempted execution in non-privileged mode generally

causes an interrupt (trap) to occur

46

slide-47
SLIDE 47

Can Applications Set the Mode Bit?

How is the mode bit set?

Via a privileged instruction? If so, is this instruction privileged?

47

slide-48
SLIDE 48

Can Applications Set the Mode Bit?

The mode bit is set via interrupts, traps, faults, and exceptions These are all hardware events that cause the address

  • f a previously registered instruction to be loaded

into the PC

This instruction is the start of an interrupt/trap/fault handler that is part of the OS!

48

slide-49
SLIDE 49

Are There Other Ways to Cheat?

What stops the running application from modifying the interrupt vector, or the handlers associated with various interrupts, traps and faults?

  • eg. modifying the timer interrupt handler to jump

control back to the application?

49

slide-50
SLIDE 50

What Stops Applications From Modifying the Interrupt Vector?

50

slide-51
SLIDE 51

What Stops Applications From Modifying the Interrupt Vector?

Doing so requires privileged instructions!

51

slide-52
SLIDE 52

What Stops Applications From Modifying the OS?

i.e, modifying the interrupt, trap, fault handler instructions in memory?

52

slide-53
SLIDE 53

What Stops Applications From Modifying the OS?

Memory protection! Certain areas of memory are off-limits unless the correct values are loaded into memory protection registers

... and accessing those registers requires use of privileged instructions ... they can only be changed if the mode bit is set

53

slide-54
SLIDE 54

How Can the OS Maintain Control?

Why must the OS fill in the interrupt vectors before handing control over to applications Why must it register a future timer interrupt? Why must it set memory protections? Why must it clear the mode bit? What if it forgets to do one of the above?

54

slide-55
SLIDE 55

How Can Applications Invoke the OS?

Why not just set PC to an OS instruction address and transfer control that way? How would the mode bit get set?

55

slide-56
SLIDE 56

How Can Applications Invoke the OS?

Special trap instruction causes a kind of interrupt

  • changes PC to point to a predetermined OS entry

point instruction

  • simultaneously sets the mode bit
  • CPU is now running in privileged mode

Application calls a library procedure that includes the appropriate trap instruction fetch/decode/execute cycle begins at a pre-specified OS entry point called a system call handler

56

slide-57
SLIDE 57

Are Traps Interrupts?

Traps, like interrupts, are hardware events But traps are synchronous whereas interrupts are asynchronous traps are caused by the executing program rather

than by a device that is external to the CPU

slide-58
SLIDE 58

Interrupts, Traps, Faults and Exceptions

Synchronous? Intentional? Error? Interrupt No No No Trap Yes Yes No Fault Yes No No Exception Yes Maybe Sometimes

slide-59
SLIDE 59

Review Questions

Why do we need a timer device? Why do we need an interrupt mechanism? Why do we need two instruction types and a mode bit? Why are system calls different to procedure calls? How are system calls different to interrupts? Why is memory protection necessary?

59

slide-60
SLIDE 60

What to do before next class

Assignment 0 – read class web page Email a picture of yourself to me Start project 1 – Introduction to BLITZ

60