CS 423: Operating Systems Design
Tianyin Xu (alm almost t bac ack! k!)
CS 423 Operating System Design: Midterm Review Tianyin Xu ( alm - - PowerPoint PPT Presentation
CS 423 Operating System Design: Midterm Review Tianyin Xu ( alm almost t bac ack! k! ) CS 423: Operating Systems Design Midterm Details In-Class or Online, March 12th (75 minutes). Close book : No textbooks, no paper notes, no
CS 423: Operating Systems Design
Tianyin Xu (alm almost t bac ack! k!)
CS 423: Operating Systems Design
2
CS 423: Operating Systems Design
3
CS 423: Operating Systems Design
4
CS 423: Operating Systems Design
5
before tomorrow.
CS 423: Operating Systems Design
6
CS 423: Operating Systems Design
7
CS 423: Operating Systems Design 8
Network Hardware
Machine specific part
Web Server Browser Slack Pop Mail Application Software
Read/Write Standard Output Device Control File System Communication
Operating System (machine independent part)
Standard Operating System Interface
Hardware Abstraction Layer
CS423: Operating Systems Design
Role #1: Referee
Role #2: Illusionist
Role #3: Glue
9
CS 423: Operating Systems Design
10
Caller and callee are in the same Process
CS 423: Operating Systems Design
11
■ Possible process states
■ Running (occupy CPU) ■ Blocked ■ Ready (does not occupy CPU) ■ Other states: suspended, terminated
Question: in a single processor machine, how many process can be in running state?
CS 423: Operating Systems Design
12
Environment (resource) execution
■ (a) Three processes each with one thread ■ (b) One process with three threads
Environment (resource) execution
12
CS 423: Operating Systems Design
13
CS 423: Operating Systems Design
14
Program Counter Program instructions Code Segment Offset Heap Data Segment
Operand
Data Operand
OpCode
Stack Segment Stack Pointer Registers Stack Program Counter Program instructions Code Segment Offset Heap Data Segment
Operand
Data Operand
OpCode
Stack Segment Stack Pointer Stack
Save State (Context) Load State (Context)
Registers
CS 423: Operating Systems Design 15
The state for processes that are not running on the CPU are maintained in the Process Control Block (PCB) data structure
Updated during context switch
An alternate PCB diagram
CS 423: Operating Systems Design
16
The Hardware (CPU) “Virtual” CPU
Context Switching + Scheduling
“Virtual” CPU “Virtual” CPU External Devices Interrupt Handler Interrupt Handler Interrupt Handler
CS 423: Operating Systems Design
17
HALT START Fetch next instruction Execute Instruction
interrupts disabled
Check for INT, init INT handler
Interrupt Stage Execute Stage Fetch Stage
CS423: Operating Systems Design
18
CS 423: Operating Systems Design
19
read (fd, buffer, nbytes)
CS423: Operating Systems Design
20
CS423: Operating Systems Design
21
CS423: Operating Systems Design
22
CS 423: Operating Systems Design
23
Lock::acquire() { disableInterrupts(); if (value == BUSY) { waiting.add(myTCB); myTCB->state = WAITING; next = readyList.remove(); switch(myTCB, next); myTCB->state = RUNNING; } else { value = BUSY; } enableInterrupts(); } Lock::release() { disableInterrupts(); if (!waiting.Empty()) { next = waiting.remove(); next->state = READY; readyList.add(next); } else { value = FREE; } enableInterrupts(); }
CS 423: Operating Systems Design
back to memory
24
CS 423: Operating Systems Design
(set) to a memory location and return its old value as a single atomic (i.e., non-interruptible) operation. If multiple processes may access the same memory location, and if a process is currently performing a test-and-set, no other process may begin another test- and-set until the first process's test-and-set is finished.
25
lock:acquire() { } lock:release() { }
CS423: Operating Systems Design
26
CS423: Operating Systems Design
27
CS423: Operating Systems Design
28
Spinlock::acquire() { while (testAndSet(&lockValue) == BUSY) ; } Spinlock::release() { lockValue = FREE; memorybarrier(); }
CS423: Operating Systems Design
29
CS 423: Operating Systems Design
30
■ Basic scheduling algorithms
■
■
■
■ What is an optimal algorithm in the sense
CS 423: Operating Systems Design
31
CS 423: Operating Systems Design 32
CS 423: Operating Systems Design
33
■ Linux 1.2: circular queue w/ round-robin policy.
■ Simple and minimal. ■ Did not meet many of the aforementioned goals
■ Linux 2.2: introduced scheduling classes (real-
/* Scheduling Policies */ #define SCHED_OTHER 0 // Normal user tasks (default) #define SCHED_FIFO 1 // RT: Will almost never be preempted #define SCHED_RR 2 // RT: Prioritized RR queues
CS 423: Operating Systems Design
34
■ Merged into the 2.6.23 release of the Linux kernel
■ Scheduler maintains a red-black tree where nodes are
■ Node with smallest virtual received execution time is
■ Priorities determine accumulation rate of virtual
■ Higher priority à
slower accumulation rate
CS 423: Operating Systems Design
35
■ CFS dispenses with a run queue and instead
An RB tree is a BST w/ the constraints:
descendent NIL leaves contains the same number of black nodes Takeaway: In an RB Tree, the path from the root to the farthest leaf is no more than twice as long as the path from the root to the nearest leaf.
CS 423: Operating Systems Design
36
CS 423: Operating Systems Design
37
■ Provide user with virtual memory that is as big as
■ Store virtual memory on disk ■ Cache parts of virtual memory being used in real
■ Load and store cached virtual memory without user
CS 423: Operating Systems Design
38
■ Fixed partitions
■ Internal fragmentation
■ Segmentation (variable partition)
■ External fragmentation
■ Paging
1 2 3 4
Memory Virtual Memory Stored on Disk 1 2 3 4 5 6 7 8 1 2 3 4 Page Table
Monitor Job 1 Job 2 Job 3 Job 4 Free 1
CS 423: Operating Systems Design
39
■ Occur when we access a virtual page that is not
■ A fault is triggered by hardware
■ Page fault handler (in OS’s VM subsystem)
■ Find if there is any free physical page available
■ If no, evict some resident page to disk (swapping space)
■ Allocate a free physical page ■ Load the faulted virtual page to the prepared physical
■ Modify the page table