lec03-concurrency
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Wang Xueyi Software College @ NEU 2010 Lec 3.4
8/31/2010
Goals for Today • How do we provide multiprogramming? • What are Processes? • How are they related to Threads and Address Spaces?
• OS Has to coordinate all activity
– Multiple users, I/O interrupts, … – How can it keep all these things straight?
• Basic Idea: Use Virtual Machine abstraction
Wang Xueyi Software College @ NEU 2010
Lec 3.7
Recall (61C): What happens during execution?
R0 … R31 F0 … F30 PC
Addr 232-1
Fetch Exec
• Execution sequence:
– – – – – – Fetch Instruction at PC Decode Execute (possibly using registers) Write results to registers/mem PC = Next Instruction(PC) Repeat
… Data1 Data0 Inst237 Inst236 … Inst5 Inst4 Inst3 Inst2 Inst1 Inst0
Note: Some slides and/or pictures in the following are adapted from slides © 2005 Silberschatz, Galvin, and Gagne. Gagne Many slides generated from my lecture notes by Kubiatowicz.
8/31/2010
Wang Xueyi Software College @ NEU 2010
Lec 3.3
Review: Implementation Issues (How is the OS implemented?)
源自文库
• Policy vs. Mechanism
• Algorithms used
• Event models used
• Backward compatability issues
• System generation/configuration
– Very important for Windows 2000/XP/Vista/… – POSIX tries to help here – How to make generic OS fit on specific hardware
• Why Study?
– To understand how user needs and hardware constraints influenced (and will influence) operating systems
– Hardware Expensive, Humans Cheap – Hardware Cheaper, Humans Expensive – Hardware Really Cheap, Humans Really Expensive
»
»
Every task does not have access to all memory
Every task does not have access to every device
2. Protection of I/O devices 3. Protection of Access to Processor: Preemptive switching from task to task
» » Use of timer Must not be possible to disable timer from usercode
8/31/2010
Wang Xueyi Software College @ NEU 2010
Lec 3.11
Recall: Program’s Address Space
– Policy: What do you want to do? – Mechanism: How are you going to do it? – Should be separated, since policies change – Linear, Tree-based, Log Structured, etc… – threads vs event loops
• This (unprotected) model common in:
– Embedded applications – Windows 3.1/Machintosh (switch only with yield) – Windows 95—ME? (switch with both yield and timer)
• Uniprogramming: one thread at a time
• Multiprogramming: more than one thread at a time
– Multics, UNIX/Linux, OS/2, Windows NT/2000/XP, Mac OS X – Often called ―multitasking‖, but multitasking has other meanings (talk about this later)
Shared Memory
Time
• Assume a single processor. How do we provide the illusion of multiple processors? • Each virtual ―CPU‖ needs a structure to hold: • How switch from one CPU to the next? • What triggers switch?
Lec 3.6
The Basic Problem of Concurrency • The basic problem of concurrency involves resources:
– Hardware: single CPU, single DRAM, single I/O devices – Multiprogramming API: users think they have exclusive access to shared resources
Wang Xueyi Software College @ NEU 2010 Lec 3.9
Properties of this simple multiprogramming technique • All virtual CPUs share same non-CPU resources
– I/O devices the same – Memory the same
The principle and security of operating system Lecture 3 Concurrency: Processes, Threads, and Address Spaces
August 30th, 2010 Wang Xueyi
Review: History of OS
» PCs, Workstations, Rise of GUIs » Ubiquitous devices, Widespread networking » Eniac, … Multics
• Several Distinct Phases:
• Rapid Change in Hardware Leads to changing OS
• Situation today is much like the late 60s
8/31/2010
– Batch Multiprogramming Timeshare Graphical UI Ubiquitous Devices Cyberspace?? – Gradual Migration of Features into Smaller Machines
– MS/DOS, early Macintosh, Batch processing – Does this make sense for personal computers?
• Multiprogramming
8/31/2010
Wang Xueyi Software College @ NEU 2010
– Decompose hard problem into simpler ones – Abstract the notion of an executing program – Then, worry about multiplexing these abstract machines
8/31/2010
8/31/2010 Wang Xueyi Software College @ NEU 2010 Lec 3.10
How to protect threads from one another? • Need three important things:
1. Protection of memory
– Small OS: 100K lines/Large: 10M lines (5M browser!) – 100-1000 people-years
Wang Xueyi Software College @ NEU 2010
Lec 3.2
Review: Migration of OS Concepts and Features
8/31/2010
– Multiplex in time!
– Program Counter (PC), Stack Pointer (SP) – Registers (Integer, Floating point, others…?)
– Save PC, SP, and registers in current state block – Load PC, SP, and registers from new state block – Timer, voluntary yield, I/O, other things
Addr 0
PC PC PC PC
Lec 3.8
8/31/2010
Wang Xueyi Software College @ NEU 2010
How can we give the illusion of multiple processors?
CPU1 CPU2 CPU3
CPU1 CPU2 CPU3 CPU1 CPU2
8/31/2010 Wang Xueyi Software College @ NEU 2010 Lec 3.5
Concurrency • ―Thread‖ of execution
– Independent Fetch/Decode/Execute loop – Operating in some Address space
• Consequence of sharing:
– Each thread can access the data of every other thread (good for sharing, bad for protection) – Threads can share instructions (good for sharing, bad for protection) – Can threads overwrite OS functions?
8/31/2010
Goals for Today • How do we provide multiprogramming? • What are Processes? • How are they related to Threads and Address Spaces?
• OS Has to coordinate all activity
– Multiple users, I/O interrupts, … – How can it keep all these things straight?
• Basic Idea: Use Virtual Machine abstraction
Wang Xueyi Software College @ NEU 2010
Lec 3.7
Recall (61C): What happens during execution?
R0 … R31 F0 … F30 PC
Addr 232-1
Fetch Exec
• Execution sequence:
– – – – – – Fetch Instruction at PC Decode Execute (possibly using registers) Write results to registers/mem PC = Next Instruction(PC) Repeat
… Data1 Data0 Inst237 Inst236 … Inst5 Inst4 Inst3 Inst2 Inst1 Inst0
Note: Some slides and/or pictures in the following are adapted from slides © 2005 Silberschatz, Galvin, and Gagne. Gagne Many slides generated from my lecture notes by Kubiatowicz.
8/31/2010
Wang Xueyi Software College @ NEU 2010
Lec 3.3
Review: Implementation Issues (How is the OS implemented?)
源自文库
• Policy vs. Mechanism
• Algorithms used
• Event models used
• Backward compatability issues
• System generation/configuration
– Very important for Windows 2000/XP/Vista/… – POSIX tries to help here – How to make generic OS fit on specific hardware
• Why Study?
– To understand how user needs and hardware constraints influenced (and will influence) operating systems
– Hardware Expensive, Humans Cheap – Hardware Cheaper, Humans Expensive – Hardware Really Cheap, Humans Really Expensive
»
»
Every task does not have access to all memory
Every task does not have access to every device
2. Protection of I/O devices 3. Protection of Access to Processor: Preemptive switching from task to task
» » Use of timer Must not be possible to disable timer from usercode
8/31/2010
Wang Xueyi Software College @ NEU 2010
Lec 3.11
Recall: Program’s Address Space
– Policy: What do you want to do? – Mechanism: How are you going to do it? – Should be separated, since policies change – Linear, Tree-based, Log Structured, etc… – threads vs event loops
• This (unprotected) model common in:
– Embedded applications – Windows 3.1/Machintosh (switch only with yield) – Windows 95—ME? (switch with both yield and timer)
• Uniprogramming: one thread at a time
• Multiprogramming: more than one thread at a time
– Multics, UNIX/Linux, OS/2, Windows NT/2000/XP, Mac OS X – Often called ―multitasking‖, but multitasking has other meanings (talk about this later)
Shared Memory
Time
• Assume a single processor. How do we provide the illusion of multiple processors? • Each virtual ―CPU‖ needs a structure to hold: • How switch from one CPU to the next? • What triggers switch?
Lec 3.6
The Basic Problem of Concurrency • The basic problem of concurrency involves resources:
– Hardware: single CPU, single DRAM, single I/O devices – Multiprogramming API: users think they have exclusive access to shared resources
Wang Xueyi Software College @ NEU 2010 Lec 3.9
Properties of this simple multiprogramming technique • All virtual CPUs share same non-CPU resources
– I/O devices the same – Memory the same
The principle and security of operating system Lecture 3 Concurrency: Processes, Threads, and Address Spaces
August 30th, 2010 Wang Xueyi
Review: History of OS
» PCs, Workstations, Rise of GUIs » Ubiquitous devices, Widespread networking » Eniac, … Multics
• Several Distinct Phases:
• Rapid Change in Hardware Leads to changing OS
• Situation today is much like the late 60s
8/31/2010
– Batch Multiprogramming Timeshare Graphical UI Ubiquitous Devices Cyberspace?? – Gradual Migration of Features into Smaller Machines
– MS/DOS, early Macintosh, Batch processing – Does this make sense for personal computers?
• Multiprogramming
8/31/2010
Wang Xueyi Software College @ NEU 2010
– Decompose hard problem into simpler ones – Abstract the notion of an executing program – Then, worry about multiplexing these abstract machines
8/31/2010
8/31/2010 Wang Xueyi Software College @ NEU 2010 Lec 3.10
How to protect threads from one another? • Need three important things:
1. Protection of memory
– Small OS: 100K lines/Large: 10M lines (5M browser!) – 100-1000 people-years
Wang Xueyi Software College @ NEU 2010
Lec 3.2
Review: Migration of OS Concepts and Features
8/31/2010
– Multiplex in time!
– Program Counter (PC), Stack Pointer (SP) – Registers (Integer, Floating point, others…?)
– Save PC, SP, and registers in current state block – Load PC, SP, and registers from new state block – Timer, voluntary yield, I/O, other things
Addr 0
PC PC PC PC
Lec 3.8
8/31/2010
Wang Xueyi Software College @ NEU 2010
How can we give the illusion of multiple processors?
CPU1 CPU2 CPU3
CPU1 CPU2 CPU3 CPU1 CPU2
8/31/2010 Wang Xueyi Software College @ NEU 2010 Lec 3.5
Concurrency • ―Thread‖ of execution
– Independent Fetch/Decode/Execute loop – Operating in some Address space
• Consequence of sharing:
– Each thread can access the data of every other thread (good for sharing, bad for protection) – Threads can share instructions (good for sharing, bad for protection) – Can threads overwrite OS functions?