chapter 6 - implementing processes, threads and resources kris hansen shelby davis jeffery brass...

22
Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05

Post on 22-Dec-2015

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Chapter 6 - Implementing

Processes, Threads and Resources

Chapter 6 - Implementing

Processes, Threads and Resources

Kris HansenShelby DavisJeffery Brass

3/7/05 & 3/9/05

Kris HansenShelby DavisJeffery Brass

3/7/05 & 3/9/05

Page 2: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

What’s CoveredWhat’s CoveredDifferent Process and Thread Types

Hardware Processes

The Abstract Machine Interface

Process Abstraction

Thread Abstraction

State Diagrams

Resource Managers

Page 3: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

What’s CoveredWhat’s CoveredDifferent Process and Thread Types

Hardware Processes

The Abstract Machine Interface

Page 4: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

ProcessesProcesses

Two Definitions of Process

Classic Process: a program in execution in a von Neumann computer

Modern Process: an OS abstraction that defines the execution environment for a thread or set of threads

Page 5: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

ThreadThread

Definition: unit of computation with the minimal internal state and resources

Threads keep track of code execution in a given process

Modern operating systems are built with modern processes and threads in mind

Page 6: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

The Abstract Machine

The Abstract Machine

The modern OS uses multiprogramming, the illusion that applications each reside inside of there own computer

The OS manages the virtual machines, via services

Services are invoked by calling API Functions

Page 7: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

APIsAPIs

• API stands for Application Programming Interface

• API functions are implemented by different parts of the OS:

• Device Manager

• Process Manager

• Memory Manager

• File Manager

Page 8: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Adding ThreadsAdding ThreadsIn a classic system, only one thread can be running per processor, the base thread

In a modern OS, additional threads can share the host process’ resources

When an abstract machine is given it’s own multiprogrammed OS, then it is a user space thread implementation

the OS implements classic processes, and the user space thread library runs on top to simulate multiprocessing

Page 9: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Adding ThreadsAdding Threads

Other modern OSs are built for threads, i.e. Windows, and support kernel threads

When kernel threads are supported, the notions of threads and processes are completely separate by managing both as separate entities

Page 10: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

ResourcesResourcesA resource is anything that a process can request

If not available, the process is blocked

A request for a resource is made via an API call

Allocation results in the resource being configured for the abstract machine

Each resource has a unique system-wide resource identifier

Page 11: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Process Address Space

Process Address Space

The process address space is the collection of addresses that a thread can reference

Addresses link to memory locations or other abstract machine elements

Memory-mapped resources - those resources bound to a collection of addresses in the address space

The address space provides a uniform access method for getting memory-mapped resources

Page 12: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Processes Address Space

Processes Address Space

Each resource manager must bind (associate, or link) addresses to resources

The OS uses the address space system to control what processes have access to resources

Modern OSs usually have 232 address (about 4GB worth,) with some supporting (or planning to support) 264 addresses

Page 13: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

OS FamiliesOS Families

The abstract interface is determined by the host’s hardware and set of functions released by the OS

The definition of an OS is important, both for how it works on the technical side and what software is available on the business side

Page 14: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Process Manager Responsibilities

Process Manager Responsibilities

Process Creation and Termination

Thread Creation and Termination

Process/Thread Synchronization

Resource Allocation

Resource Protection

Cooperation w/ Device Manager on IO

Address Space Implementation

Page 15: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Final Process CompositionFinal Process Composition

Address Space

Program

Data

Resources

Process Identifier

Page 16: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Final Thread CompositionFinal Thread Composition

Host Process Environment

Thread Specific Data

Thread Identifier

Page 17: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

The Hardware Process

The Hardware Process

When a system boots up, there are no distinctions like processes and threads

On booting, all the computer knows is its basic hardware start up instructions, known as a bootstrap

This single thread of execution is known as the hardware process

Page 18: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Bootstrap & LoaderBootstrap & LoaderThe bootstrap must execute first

Executing the bootstrap leads to the loader, which starts loading the OS

After loading, the OS can initialize, polling and initializing hardware and data structures

Only after this can threads and processes be handled, by way of launching thread and process managers

Page 19: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Initial StructuresInitial Structures

When the OS loads, before normal execution can take place, an initial process and thread are created

It acts as a placeholder for all of the other threads and processes, it actually does nothing

This is also the idle thread (or idle process,) as this process is executed when no other processes are running

Page 20: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

The Abstract Machine Interface

The Abstract Machine Interface

In an OS, there are two types of instructions: user mode instructions and OS (supervisor mode) instructions

This protects from a program being able to access resources completely unchecked

When a certain resource is needed, or a system call is necessary, then a call must be made to the OS, which directs the call into the supervisor mode via a trap instruction

Page 21: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

Comparing System Call Interfaces

Comparing System Call Interfaces

Linux Kernel version 2.0.36 has 166 system functions

Kernel version 2.4 has over 200

Win32 has over 2,000

The number of system calls increases the functionality of the OS, along with the overhead needed to run it

Page 22: Chapter 6 - Implementing Processes, Threads and Resources Kris Hansen Shelby Davis Jeffery Brass 3/7/05 & 3/9/05 Kris Hansen Shelby Davis Jeffery Brass

SourceSource

Nutt, Gary. Operating Systems. Boston: Pearson Education, 2004.