Announcements

• Please return your prerequisite forms if you haven’t done so CS 3204 • My office hours (MCB 637): – Tu 8-9:15am Oppgyerating Systems – Th 1:30pm-3:30pm (2:30pm if no one comes) • TA office hours announced later today, check website Lecture 2 • Start thinking about groups – (but *do not* collaborate on Project 0) Godmar Back • Project 0 due on Sep 7 – Other due dates posted later today

CS 3204 Fall 20088/28/2008 2

Project 0 Outline for today • Implement User-level Memory Allocator • Motivation for teaching OS – Use address-ordered first-fit • Brief history • A survey of core issues OS address • What you should get out of this class start user object user object end

free block used block free list

CS 3204 Fall 20088/28/2008 3 CS 3204 Fall 20088/28/2008 4

Why are OS interesting? What does an OS do?

• OS are “magic” • Software layer that sits – Most people don’t understand them – including sysadmins and computer scientists! between applications and hardware • OS are incredibly complex systems gcc csh X11 – “Hello, World” – program really 1 million lines of code

• Studying OS is learning how to deal with • Performs services complexity – Abstracts hardware – Abstractions (+interfaces) Hardware – Modularity (+structure) – Provides protection CPU Memory Network Disk – Iteration (+learning from experience) – Manages resources

CS 3204 Fall 20088/28/2008 5 CS 3204 Fall 20088/28/2008 6

1 OS vs Kernel Evolution of OS

• Can take a wider view or a narrower definition what an • OSs as a library OS is – Abstracts away hardware, provide neat • Wide view: Windows, , Mac OSX are operating systems interfaces – Includes system programs, system libraries, servers, shells, GUI • Makes software portable; allows software evolution etc. – Single user, single program computers • Narrow definition: • No need for protection: no malicious users, no – OS often equated with the kernel. interactions between programs – The Linux kernel; the Windows executive – the special piece of software that runs with special privileges and actually controls – Disadvantages of uniprogramming model the machine. • Expensive • In this class, usually mean the narrow definition. • Poor utilization • In real life, always take the wider view. (Why?) CS 3204 Fall 20088/28/2008 7 CS 3204 Fall 20088/28/2008 8

Evolution of OS (II) Single Program vs Multiprogramming

• Invent multiprogramming – First multi-programmed batch systems, then time- sharing systems • Idea: – Load multiple programs in memory – Do something else while one program is waiting, don’t sit (see next slide) • Complexity increases: – What if programs interfere with each other (wild writes) – What if programs don’t relinquish control (infinite loop)

CS 3204 Fall 20088/28/2008 9 CS 3204 Fall 20088/28/2008 10

Protection Protection #1: Preemption

• Multiprogramming requires isolation • Resource can be given to program and access • OS must protect/isolate applications from each can be revoked other, and OS from applications – Example: CPU, Memory, Printer, “abstract” resources: • This requirement is absolute files, sockets – In Pintos also: if one application crashes, kernel • CPU Preemption using should not! Bulletproof. – Hardware timer invokes OS, OS checks if • Three techniques current program should be preempted, done every – Preemption 4ms in Linux – Interposition – Solves infinite loop problem! – Privilege • Q.: Does it work with all resources equally?

CS 3204 Fall 20088/28/2008 11 CS 3204 Fall 20088/28/2008 12

2 Protection #2: Interposition Protection #3: Privilege

• OS hides the hardware • Two fundamental modes: – “kernel mode” – privileged • Application have to go through OS to • aka system, supervisor or monitor mode • Intel calls its PL0, Privilege Level 0 on access resources – “user mode” – non-privileged • OS can i n terpose ch ec ks: • PL3 on x 86 • Bit in CPU – controls operation of CPU – Validity (Address Translation) – Protection operations can only – Permission (Security Policy) be performed in kernel mode. int main() Example: hlt { – Resource Constraints (Quotas) asm(“hlt”); – Carefully control transitions } between user & kernel mode

CS 3204 Fall 20088/28/2008 13 CS 3204 Fall 20088/28/2008 14

OS as a Resource Manager Resource Management (2)

• OS provides illusions, examples: • Multiplexing increases complexity – every program is run on its own CPU • Car Analogy (by Rosenblum): – Dedicated road per car would be incredibly inefficient, so cars – every program has all the memory of the share freeway. Must manage this. machine (and more) – (abstraction) different lanes per direction – (sync hron iza tion ) tra ffic li g hts – every program has its own I/O terminal – (increase capacity) build more roads • “Stretches” resources • More utilization creates contention – Possible because resource usage is bursty, – (decrease demand) slow down typically – (backoff/retry) use highway during off-peak hours – (refuse service, quotas) force people into public transportation • Increases utilization – (system collapse) traffic jams

CS 3204 Fall 20088/28/2008 15 CS 3204 Fall 20088/28/2008 16

Resource Management (3) Goals for Resource Management

• OS must decide who gets to use what • Fairness resource – Assign resources equitably • Approach 1: have admin (boss) tell it • Differential Responsiveness – Cater to individual applications ’ needs • Ah2htllitApproach 2: have user tell it • Efficiency – What if user lies? What if user doesn’t know? – Maximize throughput, minimize response • Approach 3: figure it out through feedback time, support as many apps as you can – Problem: how to tell power users from • These goals are often conflicting. resource hogs? – All about trade-offs

CS 3204 Fall 20088/28/2008 17 CS 3204 Fall 20088/28/2008 18

3 Summary: Core OS Functions

• Hardware abstraction through interfaces • Protection: – Preemption – ItInterpositi on – Privilege (user/kernel mode) • Resource Management – Virtualizing of resources – of resources

CS 3204 Fall 20088/28/2008 19

4