Upload
ashley-murphy
View
227
Download
4
Embed Size (px)
Citation preview
Operating SystemsECE344
Ashvin GoelECE
University of Toronto
OS Design
2
Design of Operating Systems
OS manages h/w resourceso Allows running many programs at the same timeo Allows programs to interact with h/w devices
Hardware
OS Kernel
Program1 UIBackground
tasksProgram2
3
Key Ideas in OS Design
How does OS allow running many programs?o Provides virtualization mechanism that allows programs to
share resources securely
How does OS allow programs to interact with h/w?o Provides a h/w abstraction, implemented via system calls
4
Virtualization
OS provides the illusion that each program is running on its own machineo Program thinks it has full access to CPU, memory, disko This is called virtualization because there is one physical
machine, but the OS provides the illusion of multiple virtual machines
Hardware
OS Kernel
Program1 UIBackground
tasksProgram2
5
Benefits of Virtualization
Virtual machines provide resource isolationo Program is not aware that other programs exist, i.e., each
program is isolated from otherso A program cannot accidentally overwrite another program’s
memory or files, causing it to crasho Ideally, if a program uses too much memory, disk, etc., only its
performance degrades
What are the properties of an “ideal” virtual machine?
6
Implementing Virtualization
OS implements virtual machines by virtualizing each physical resource
Processor -> Threadso OS provides the illusion that a large number of virtual
processors, called threads, are available to programs Run cpu.c
Memory -> Virtual Memoryo OS provides the illusion that each program has access to a
large amount of contiguous, private memory Run mem.c
Disk -> Fileso OS provides the illusion that a large number of virtual disks,
called files, are available to programs
7
Concurrency
Thread abstraction is powerful because it allows a program to perform several tasks in parallel (or concurrently)o E.g., a web server can serve multiple web requests, by using
a thread per request
However, running threads concurrently raises some challenging problemso Run threads-race.c with args 100, 1000, 10000, 100000o Run threads-sync.c
The OS runs multiple programs concurrently, and thus must handle these problems as well
8
System Calls
Programs request h/w access via system callso Similar to procedure calls, but a little more complicatedo System calls provide an abstraction of h/w, making it easier to
write programs
Set of system calls is OS API
Examples:o Create/destroy processo Allocate/deallocate memoryo Read/write a file
9
System Call Example
Program calls read() syscall to read a file from disko Execution goes via a library that generates a trapo Trap invokes the kernel, which accesses disko Kernel returns results to program
Will discuss traps, and need for traps later
Hardware
OS Kernel
Program1 Library
trap
read return results
10
OS Interface
OS Kernel
Video Card
CPU
Monitor
Printer
Disk
MemoryNetwork
Application layer
system calls: thread_create(), read(), write(), thread_join() ...
Device Mgmt File System Network Comm.
Process MgmtProtection Security
Hardware layer
virtual machine interface
physical machine interface
Thread scheduler Memory management
OS interface
11
Summary
Two important OS conceptso OS isolates applications using virtualizationo OS abstracts h/w with a simpler interface
Virtualizationo Each program thinks it owns the machineo Programs don’t need to worry about other running programs
E.g., a program cannot corrupt other programs
Abstractiono Simpler interface to h/w implemented via system callso Eases programing, improves portability