
Recall: What is an operating system? CS162! • Special layer of software that provides application software access to Operating Systems and! hardware resources Systems Programming! – Convenient abstraction of complex hardware devices Lecture 2! – Protected access to shared resources ! – Security and authentication – Communication amongst logical entities Introduction to Processes appln appln August 28th, 2017 appln OS Prof. Ion Stoica http://cs162.eecs.Berkeley.edu Hardware 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.2 Very Brief History of OS Very Brief History of OS • Several Distinct Phases: • Several Distinct Phases: – Hardware Expensive, Humans Cheap » Eniac, … Multics “I think there is a world market for maybe five computers.” – Thomas Watson, chairman of IBM, 1943 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.3 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.4 Page 1 Very Brief History of OS Very Brief History of OS • Several Distinct Phases: • Several Distinct Phases: – Hardware Expensive, Humans Cheap – Hardware Expensive, Humans Cheap » Eniac, … Multics » Eniac, … Multics – Hardware Cheaper, Humans Expensive » PCs, Workstations, Rise of GUIs Thomas Watson was often called “the worlds greatest salesman” by the time of his death in 1956 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.5 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.6 Very Brief History of OS Very Brief History of OS • Several Distinct Phases: • Several Distinct Phases: – Hardware Expensive, Humans Cheap – Hardware Expensive, Humans Cheap » Eniac, … Multics » Eniac, … Multics – Hardware Cheaper, Humans Expensive – Hardware Cheaper, Humans Expensive » PCs, Workstations, Rise of GUIs » PCs, Workstations, Rise of GUIs – Hardware Really Cheap, Humans Really Expensive – Hardware Really Cheap, Humans Really Expensive » Ubiquitous devices, Widespread networking » Ubiquitous devices, Widespread networking • Rapid change in hardware leads to changing OS – Batch ⇒ Multiprogramming ⇒ Timesharing ⇒ Graphical UI ⇒ Ubiquitous Devices – Gradual migration of features into smaller machines • Today – Small OS: 100K lines / Large: 10M lines (5M browser!) – 100-1000 people-years 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.7 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.8 Page 2 OS Archaeology Migration of OS Concepts and Features • Because of the cost of developing an OS from scratch, most modern OSes have a long lineage: • Multics à AT&T Unix à BSD Unix à Ultrix, SunOS, NetBSD,… • Mach (micro-kernel) + BSD à NextStep à XNU à ! Apple OS X, iPhone iOS • MINIX à Linux à Android OS, Chrome OS, RedHat, Ubuntu, Fedora, Debian, Suse,… • CP/M à QDOS à MS-DOS à Windows 3.1 à NT à 95 à 98 à 2000 à XP à Vista à 7 à 8 à 10 à phone à … 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.9 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.10 Today: Four Fundamental OS Concepts OS Bottom Line: Run Programs 0xFFF… • Thread Executable – Single unique execution context: fully describes program state Program Source OS – Program Counter, Registers, Execution Flags, Stack int main() { … ; data stack Memory • Address space (with translation) } compiler editor – Programs execute in an address space that is distinct from the memory Load & Execute instructions heap space of the physical machine data • Process foo.c a.out – An instance of an executing program is a process consisting of an address space and one or more threads of control • Load instruction and data segments of instructions executable file into memory • Dual mode operation / Protection 0x000… • Create stack and heap – Only the “system” has the ability to access certain resources PC: • “Transfer control to program” – The OS and the hardware are protected from user programs and user registers programs are isolated from one another by controlling the translation • Provide services to program Processor from program virtual addresses to machine physical addresses • While protecting OS and program 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.11 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.12 Page 3 Recall (61B): Instruction Fetch/Decode/Execute Recall (61C): What happens during program execution? The instruction cycle Addr 232-1 Memory R0 Processor next … … PC: R31 Fetch Data1 F0 Data0 Instruction fetch instruction … Exec F30 Inst237 Decode decode PC Inst236 … Registers Inst5 • Execution sequence: Inst4 – Fetch Instruction at PC Execute Inst3 PC – Decode ALU Inst2! PC – Execute (possibly using registers) Inst1 PC data – Write results to registers/mem Inst0 PC – PC = Next Instruction(PC) Addr 0 – Repeat 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.13 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.14 First OS Concept: Thread of Control Second OS Concept: Program’s Address Space 0xFFF… • Certain registers hold the context of thread • Address space ⇒ the set of accessible stack addresses + state associated with them: – Stack pointer holds the address of the top of stack – For a 32-bit processor there are 232 = 4 » Other conventions: Frame pointer, Heap pointer, Data billion addresses heap – May be defined by the instruction set architecture or by compiler Static Data conventions • What happens when you read or write to • Thread: Single unique execution context an address? code – Program Counter, Registers, Execution Flags, Stack – Perhaps nothing 0x000… • A thread is executing on a processor when it is resident in the – Perhaps acts like regular memory processor registers. – Perhaps ignores writes • PC register holds the address of executing instruction in the – Perhaps causes I/O operation thread » (Memory-mapped I/O) – Perhaps causes exception (fault) • Registers hold the root state of the thread. – The rest is “in memory” 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.15 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.16 Page 4 Address Space: In a Picture Multiprogramming - Multiple Threads of Control 0xFFF… stack stack PC: Proc Proc Proc SP: 1 2 … n heap heap Static Data Processor OS code Static Data registers stack instruction Code Segment heap Static Data 0x000… code • What’s in the code segment? Static data segment? • What’s in the Stack Segment? stack – How is it allocated? How big is it? heap Static Data • What’s in the Heap Segment? code – How is it allocated? How big? 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.17 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.18 Administrivia: Getting started How can we give the illusion of multiple processors? • Start homework 0 immediately ⇒ Due next Monday (9/4)! – cs162-xx account, Github account, registration survey vCPU1 vCPU2 vCPU3 – Vagrant and VirtualBox – VM environment for the course vCPU1 vCPU2 vCPU3 vCPU1 vCPU2 » Consistent, managed environment on your machine Shared Memory Time – Get familiar with all the cs162 tools, submit to autograder via git • Assume a single processor. How do we provide the illusion of – Homework slip days: You have 3 slip days multiple processors? – Multiplex in time! • THIS Friday (9/1) is early drop day! Very hard to drop afterwards… • Each virtual “CPU” needs a structure to hold: – Program Counter (PC), Stack Pointer (SP) • Should be going to section already! – Registers (Integer, Floating point, others…?) • Group sign up form will be out after drop deadline • How switch from one virtual CPU to the next? – Save PC, SP, and registers in current state block – Work on finding groups ASAP: 4 people in a group! – Load PC, SP, and registers from new state block – Try to attend either same section or 2 sections by same TA • What triggers switch? – Timer, voluntary yield, I/O, other things 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.19 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.20 Page 5 The Basic Problem of Concurrency Properties of this simple multiprogramming technique • The basic problem of concurrency involves resources: • All virtual CPUs share same non-CPU resources – Hardware: single CPU, single DRAM, single I/O devices – I/O devices the same – Multiprogramming API: processes think they have exclusive access to – Memory the same shared resources • Consequence of sharing: • OS has to coordinate all activity – Each thread can access the data of every other thread (good for – Multiple processes, I/O interrupts, … sharing, bad for protection) – How can it keep all these things straight? – Threads can share instructions! (good for sharing, bad for protection) • Basic Idea: Use Virtual Machine abstraction – Can threads overwrite OS functions? – Simple machine abstraction for processes • This (unprotected) model is common in: – Multiplex these abstract machines – Embedded applications • Dijkstra did this for the “THE system” – Windows 3.1/Early Macintosh (switch only with yield) – Few thousand lines vs 1 million lines in OS 360 (1K bugs) – Windows 95—ME (switch with both yield and timer) 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.21 8/28/17 Stoica CS162 ©UCB Fall 2017 Lec 2.22 Protection Third OS Concept: Process • Operating System must protect itself from user programs • Process: execution environment with Restricted Rights – Reliability: compromising the operating system generally causes it to – Address Space with One or More Threads crash – Owns memory (address space) – Security: limit the scope of what processes can do – Owns file descriptors, file system context, … – Privacy: limit each process to the data it is permitted to access – Encapsulate one or more threads sharing process resources – Fairness: each should be limited to its appropriate share of system • Why processes? resources (CPU time, memory, I/O, etc) – Protected from each other! • It must protect User programs from one another – OS Protected from them • Primary Mechanism: limit
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages11 Page
-
File Size-