CS 444544 Operating Systems II Quiz 2 Review

  • Slides: 32
Download presentation
CS 444/544 Operating Systems II Quiz 2 Review Yeongjin Jang

CS 444/544 Operating Systems II Quiz 2 Review Yeongjin Jang

Lab 2 & 3 Grade Released • Please check if you pushed all your

Lab 2 & 3 Grade Released • Please check if you pushed all your commit • Make sure you can see your tags and commits at gitlab web • For late submissions (75% until 6/12) • I will run grading script twice a week

Quiz 2 Statistics

Quiz 2 Statistics

Q 1: Virtual Memory Mapping in JOS • We copied entries from kernel page

Q 1: Virtual Memory Mapping in JOS • We copied entries from kernel page directory for the entries for managing kernel memory. • In this regard, how JOS manages those memory area, inaccessible from the user environment? • For kernel memory, we did not set PTE_U, and thereby, user cannot access those area

Q 1: Virtual Memory Mapping in JOS • We copied entries from kernel page

Q 1: Virtual Memory Mapping in JOS • We copied entries from kernel page directory for the entries for managing kernel memory. • In this regard, how JOS manages those memory area is not accessible from the user environment?

Q 2: Calculating Memory Overhead

Q 2: Calculating Memory Overhead

Q 2: Calculating Memory Overhead IDX Start VA End VA PDE 0 0 x

Q 2: Calculating Memory Overhead IDX Start VA End VA PDE 0 0 x 400000 INVALID 1 0 x 400000 0 x 800000 INVALID 2 0 x 800000 0 xc 00000 VALID 3 0 xc 00000 0 x 1000000 VALID 4 0 x 1000000 0 x 1400000 VALID 5 0 x 1400000 0 x 1800000 VALID … 1 page directory, 4 page tables: 5 pages 5 * 4 KB = 20 KB

Q 2: Calculating Memory Overhead 1 page directory, 4 page tables: 5 pages 5

Q 2: Calculating Memory Overhead 1 page directory, 4 page tables: 5 pages 5 * 4 KB = 20 KB

Q 3: Interrupt Handling Handled divzero, which is not a recoverable exception What will

Q 3: Interrupt Handling Handled divzero, which is not a recoverable exception What will happen? ?

Q 3: Interrupt Handling a = 1/0 idiv %ecx Divide by zero! t_divzero _alltraps

Q 3: Interrupt Handling a = 1/0 idiv %ecx Divide by zero! t_divzero _alltraps trap() trap_dispatch() return; env_run() env_pop_tf() iret

Q 4: JOS Trapframe tf_err tf_eip tf_cs tf_eflags tf_esp tf_ss

Q 4: JOS Trapframe tf_err tf_eip tf_cs tf_eflags tf_esp tf_ss

Q 4: JOS Trapframe tf_err tf_eip tf_cs tf_eflags tf_esp tf_ss

Q 4: JOS Trapframe tf_err tf_eip tf_cs tf_eflags tf_esp tf_ss

Q 5: Page Fault

Q 5: Page Fault

Q 5: Page Fault

Q 5: Page Fault

Q 5: Page Fault tf_eip cr 2 tf_err

Q 5: Page Fault tf_eip cr 2 tf_err

Q 6: Page Fault cr 2 = 0 x 4141 err = 0 x

Q 6: Page Fault cr 2 = 0 x 4141 err = 0 x 2 == 0010, P = 0, W = 1… Write! cs = 0 x 8 == 1000, last 2 bits == 0, ring 0! Ring 0 Write access 0 x 4141

Q 7: Preemptive Multitasking • How modern OSes supports preemptive multitasking, which can avoid

Q 7: Preemptive Multitasking • How modern OSes supports preemptive multitasking, which can avoid while(1); from user execution stop the entire system?

User Execution Strawman 3 After 1 ms • Preemptive Multitasking (Lab 4) Ring 3

User Execution Strawman 3 After 1 ms • Preemptive Multitasking (Lab 4) Ring 3 • CPU generates an interrupt to force execution at kernel after some time quantum • E. g. , 1000 Hz, on each 1 ms. . OS Kernel (Ring 0) Timer interrupt! 18

User Execution Strawman 3 • Preemptive Multitasking (Lab 4) Ring 3 • CPU generates

User Execution Strawman 3 • Preemptive Multitasking (Lab 4) Ring 3 • CPU generates an interrupt to force execution at kernel after some time quantum • E. g. , 1000 Hz, on each 1 ms. . OS Kernel (Ring 0) • Guaranteed execution in kernel • Let kernel mediate resource contention 19

User Execution Strawman 3 • Preemptive Multitasking (Lab 4) Ring 3 • CPU generates

User Execution Strawman 3 • Preemptive Multitasking (Lab 4) Ring 3 • CPU generates an interrupt to force execution at kernel after some time quantum iret (ring 0 to ring 3) Schedule() • E. g. , 1000 Hz, on each 1 ms. . OS Kernel (Ring 0) • Guaranteed execution in kernel • Let kernel mediate resource contention 20

Q 7: Preemptive Multitasking • How modern OSes supports preemptive multitasking, which can avoid

Q 7: Preemptive Multitasking • How modern OSes supports preemptive multitasking, which can avoid while(1); from user execution stop the entire system?

Q 8: User-Kernel Context Switch • Privilege level of the exec. .

Q 8: User-Kernel Context Switch • Privilege level of the exec. .

System Call Handling Routine (User) • User calls a function • cprintf -> calls

System Call Handling Routine (User) • User calls a function • cprintf -> calls sys_cputs() • sys_cputs() at user code will call syscall() (lib/syscall. c) • This syscall() is at lib/syscall. c • Set args in the register and then • int $0 x 30 • Now kernel execution starts… 23

System Call Handling Routine (Kernel) • CPU gets software interrupt • TRAPHANDLER_NOEC(T_SYSCALL…) • _alltraps()

System Call Handling Routine (Kernel) • CPU gets software interrupt • TRAPHANDLER_NOEC(T_SYSCALL…) • _alltraps() • trap_dispatch() • Get registers that store arguments from struct Trapframe *tf • Call syscall() using those registers • This syscall() is at kern/syscall. c 24

System Call Handling Routine (Return to User) • Finishing handling of syscall (return of

System Call Handling Routine (Return to User) • Finishing handling of syscall (return of syscall()) • trap() calls env_run() • Get back to the user environment! • env_pop_tf() • Runs iret Restore the CPU state from the trap frame • Back to Ring 3! 25

Q 8: User-Kernel Context Switch USER KERNEL KERNEL USER

Q 8: User-Kernel Context Switch USER KERNEL KERNEL USER

Q 8: User-Kernel Context Switch USER KERNEL KERNEL USER

Q 8: User-Kernel Context Switch USER KERNEL KERNEL USER

Q 9: Copy-on-Write

Q 9: Copy-on-Write

Q 9: Copy-on-Write P|U P|W|U

Q 9: Copy-on-Write P|U P|W|U

Q 9: Copy-on-Write P|U pte & PTE_COW == 1 Write access! Page Fault! P|U|PTE_COW

Q 9: Copy-on-Write P|U pte & PTE_COW == 1 Write access! Page Fault! P|U|PTE_COW Read-only!

Q 9: Copy-on-Write P|U pte & PTE_COW == 1 Write access! Page Fault! P|U|PTE_COW

Q 9: Copy-on-Write P|U pte & PTE_COW == 1 Write access! Page Fault! P|U|PTE_COW Read-only! Copy!

Q 9: Copy-on-Write P|U pte & PTE_COW == 1 Write access! Page Fault! P|U|W

Q 9: Copy-on-Write P|U pte & PTE_COW == 1 Write access! Page Fault! P|U|W Read-only! Copy!