threads, smp, and microkernels. processes zresource ownership - process is allocated a virtual...

33
Threads, SMP, and Microkernels

Upload: grace-nichols

Post on 14-Jan-2016

219 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Threads, SMP, and Microkernels

Page 2: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Processes

Resource ownership - process is allocated a virtual address space to hold the process image

Dispatched - process is an execution path through one or more programs execution may be interleaved with other

processesThese two characteristics are treated

independently by the operating system

Page 3: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Processes

Dispatching is referred to as a threadResource of ownership is referred to

as a process or task

Page 4: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Multithreading

Operating system supports multiple threads of execution within a single process

MS-DOS supports a single threadUNIX supports multiple user processes

but only supports one thread per processWindows NT, Solaris, Linux supports

multiple threads

Page 5: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Threads and Processes

one processone thread

multiple processesone thread per process

one processmultiple threads

multiple processesmultiple threads per process

Page 6: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Processes

Have a virtual address space which holds the process image

Protected access to processors, other processes, files, and I/O resources

Page 7: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Threads

Has an execution state (running, ready, etc.)

Saves thread context when not runningHas an execution stackHas some per-thread static storage for

local variablesHas access to the memory and resources

of its process all threads of a process share this

Page 8: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Single Threaded and Multithreaded Process Models

ThreadControlBlock

UserStack

UserStack

KernelStack

KernelStack

UserAddressSpace

UserAddressSpace

ProcessControlBlock

ProcessControlBlock

Thread

Single-ThreadedProcess Model

MultithreadedProcess Model

ThreadControlBlock

UserStack

KernelStack

Thread

ThreadControlBlock

UserStack

KernelStack

Thread

Page 9: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Benefits of ThreadsTakes less time to create a new thread than

a processLess time to terminate a thread than a

processLess time to switch between two threads

within the same processSince threads within the same process share

memory and files, they can communicate with each other without invoking the kernel

Page 10: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Threads

Suspending a process involves suspending all threads of the process since all threads share the same address space

Termination of a process, terminates all threads within the process

Thread operations: spawn, block, unblock, finish (no suspend, only active)

Page 11: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

User-Level Threads

All thread management is done by the application, and is fast

The kernel is not aware of the existence of threads

Thread switching does not require kernel mode privileges

Scheduling is application specific

Page 12: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Kernel-Level Threads

Windows NT, Linux and OS/2 are examples of this approach

Kernel maintains context information for the process and the threads

Switching between threads requires the kernel and may be slower than user-level

Page 13: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Combined Approaches for Threads

Example is SolarisThread creation done in the user

spaceBulk of scheduling and

synchronization of threads done in the user space

Page 14: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Relationship Between Threads and Processes

Threads:Process Description Example Systems

1:1 Each thread of execution is aunique process with its ownaddress space and resources.

Most UNIX implementations

M:1 A process defines an addressspace and dynamic resourceownership. Multiple threadsmay be created and executedwithin that process.

Windows NT, Solaris, Linux, OS/2, OS/390, MACH

Page 15: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Relationship Between Threads and Processes

Threads:Process Description Example Systems

1:M A thread may migrate from oneprocess environment toanother. This allows a threadto be easily moved amongdistinct systems.

Ra (Clouds), Emerald

M:M Combines attributes of M:1and 1:M cases

TRIX

Page 16: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Categories of Computer Systems

Single Instruction Single Data (SISD) single processor executes a single

instruction stream to operate on data stored in a single memory

Single Instruction Multiple Data (SIMD) one instruction is executed on a different

set of data by the different processors

Page 17: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Categories of Computer Systems

Multiple Instruction Single Data (MISD) a sequence of data is transmitted to a set

of processors, each of which executes a different instruction sequence. Never implemented

Multiple Instruction Multiple Data (MIMD) a set of processors simultaneously

execute different instruction sequences on different data sets

Page 18: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Parallel Processor Architecture

MIMD

Shared memorymultiprocessor

Distributed memory(self-contained computers)

Clusters

Master/SlaveSymmetricmultiprocessors(SMP)

Page 19: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Symmetric Multiprocessing

Kernel can execute on any processorTypically each processor does self-

scheduling from the pool of available process or threads

portions of the kernel can execute in parallel in different processors

Page 20: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Symmetric Multiprocessor Organization

MainMemory

Processor Processor Processor

Cache CacheCache

I/OSubsystem

. . .

Page 21: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Multiprocessor OS requirements

Must provide functionality of a multiprogramming OS plus additional features to support multiple processors

Simultaneous concurrent processes or threads: kernel routines need to be reentrant

Scheduling done by any processor, can create conflicts.

Synchronization through locks is required. Memory management needs to be coordinated in the

different processors Much more complex than just multiprogramming OS.

Page 22: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

MicrokernelSmall operating system coreContains only essential operating systems

functionsMany services traditionally included in the

operating system are now external subsystems device drivers file systems virtual memory manager windowing system and security services

Page 23: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Benefits of a Microkernel Organization

Uniform interface on request made by a process all services are provided by means of

message passingExtensibility

allows the addition of new servicesFlexibility

existing features can be subtracted

Page 24: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Benefits of a Microkernel Organization

Portability changes needed to port the system to a

new processor is changed in the microkernel - not in the other services

Reliability modular design small microkernel can be rigorously

tested

Page 25: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Benefits of Microkernel Organization

Distributed system support message are sent without knowing what

the target machine isObject-oriented operating system

components are objects with clearly defined interfaces that can be interconnected to form software

Page 26: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Microkernel Design

Primitive memory management mapping each virtual page to a physical

page frameInter-process communicationI/O and interrupt management

Page 27: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Windows NT Processes

Implemented as objectsAn executable process may contain

one or more threadsBoth process and thread objects

have built-in synchronization capabilities

Page 28: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Windows NT Process Object Attributes

Process IDSecurity DescriptorBase priorityDefault processor affinityQuota limitsExecution timeI/O countersVM operation countersException/debugging portsExit status

Page 29: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Windows NT Thread Object Attributes

Thread IDThread contextDynamic priorityBase priorityThread processor affinityThread execution timeAlert statusSuspension countImpersonation tokenTermination portThread exit status

Page 30: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

NT Thread Status

ResourceAvailable

Unblock/ResumeResource Available

UnblockResource Not Available

Block/Suspend

Terminate

SwitchPick toRun

Preempted

Transition Waiting Terminated

Not Runnable

Runnable

Ready

Standby

Running

Page 31: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Solaris

Process includes the user’s address space, stack, and process control block

User-level threadsLightweight processesKernel threads

Page 32: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Solaris User Level Threads

Stop

Stop Sleep

Dispatch

Stop

WakeupContinue

Preempt

Stopped

Runnable

Active

Sleeping

Page 33: Threads, SMP, and Microkernels. Processes zResource ownership - process is allocated a virtual address space to hold the process image zDispatched - process

Solaris Lightweight Processes

Timesliceor Preempt

WakeupStop

BlockingSystem

Call

WakeupDispatch

Runnable

Running

Active

Stopped

Continue

Stop