processes ecf
play

Processes & ECF CS 351: Systems Programming Michael Saelee - PowerPoint PPT Presentation

Processes & ECF CS 351: Systems Programming Michael Saelee <lee@iit.edu> Computer Science Science Agenda - Definition & OS responsibilities - Exceptional control flow - synch vs. asynch exceptions - exception handling


  1. Processes & ECF CS 351: Systems Programming Michael Saelee <lee@iit.edu>

  2. Computer Science Science Agenda - Definition & OS responsibilities - Exceptional control flow - synch vs. asynch exceptions - exception handling procedure

  3. Computer Science Science §Definition & OS responsibilities

  4. Computer Science Science a process is a program in execution

  5. Computer Science Science programs describe what we want done, processes carry out what we want done

  6. Computer Science Science a process comprises ... { code (program) + runtime data (global, local, 
 dynamic) + PC, SP , FP & other registers }

  7. 
 Computer Science Science main() { fnA(); 
 essential to program } 
 execution is predictable, fnA() { 
 logical control flow fnB(); 
 } which requires that fnB() { nothing disrupt the loop { program mid-execution } }

  8. Computer Science Science easiest way to guarantee this is for a process to “own” the CPU for its entire duration ... downsides?

  9. Computer Science Science 1.No multitasking! 2.A malicious (or badly written) program can “take over” the CPU forever 3.An idle process (e.g., waiting for input) will underutilize the CPU

  10. Computer Science Science the operating system presents each process with a simulated, seamless logical control flow many of which can be taking place concurrently on one or more CPUs

  11. Computer Science Science Process A Process B Process C Time Logical control flow

  12. Computer Science Science Process A Process B Process C Time Physical flow (1 CPU)

  13. Computer Science Science to do this, we need (1) a hardware mechanism to periodically interrupt the , (2) an OS current process to load the OS procedure that decides which processes to run, in what order , and (3) a routine for seamlessly transitioning between processes

  14. Computer Science Science (1) is the periodic clock interrupt; 
 (2) is the OS scheduler; 
 (3) is the context switch

  15. Computer Science Science Process A Process B Time User code read Context Kernel code switch User code Disk interrupt Context Kernel code Return switch from read User code Need new diagram that shows context switches triggered by the clock interrupt. Context switches

  16. Computer Science Science to implement scheduling and carry out context switches, the OS must maintain a wealth of per-process metadata

  17. Computer Science Science a process comprises ... { code (program) + runtime data (global, local, 
 dynamic) + PC, SP , FP & other registers + “process control block” ( OS metadata) }

  18. Computer Science Science a process comprises ... { code (program) + runtime data (global, local, 
 dynamic) + PC, SP , FP & other registers + e.g., PID, mem/CPU usage, pending syscalls }

  19. Computer Science Science context switches are external to a process’s logical control flow (dictated by user program) — part of exceptional control flow

  20. Computer Science Science §Exceptional Control Flow

  21. Computer Science Science int main() { while (1) { printf("hello world!\n"); } return 0; }

  22. Computer Science Science logical c.f. int main() { while (1) { printf("hello world!\n"); } return 0; }

  23. Computer Science Science logical c.f. int main() { while (1) { exception! printf("hello world!\n"); } return 0; }

  24. Computer Science Science logical c.f. int main() { while (1) { exception! printf("hello world!\n"); } return 0; } ?

  25. Computer Science Science logical c.f. int main() { while (1) { exception! printf("hello world!\n"); } return 0; } ?

  26. Computer Science Science Two classes of exceptions: I. synchronous II.asynchronous

  27. Computer Science Science I. synchronous exceptions are caused by the currently executing instruction

  28. Computer Science Science 3 subclasses of synchronous exceptions: 1. traps 2. faults 3. aborts

  29. Computer Science Science 1. traps traps are intentionally triggered by a process e.g., to invoke a system call

  30. Computer Science Science mov edx, len mov ecx, str char *str = "hello world"; mov ebx, 1 int len = strlen(str); mov eax, 4 ; syscall #4 write(1, str, len); int 0x80 ; trap to OS

  31. Computer Science Science return from trap (if it happens) resumes execution at the next logical instruction

  32. Computer Science Science 2. faults faults are usually unintentional , and may be recoverable or irrecoverable e.g., segmentation fault, protection fault, page fault, div-by-zero

  33. Computer Science Science often, return from fault will result in retrying the faulting instruction — esp. if the handler “fixes” the problem

  34. Computer Science Science 3. aborts aborts are unintentional and irrecoverable i.e., abort = program/OS termination e.g., memory ECC error

  35. Computer Science Science II. asynchronous exceptions are caused by events external to the current instruction

  36. Computer Science Science int main() { while (1) { printf("hello world!\n"); } return 0; } hello world! hello world! hello world! hello world! ^C $

  37. Computer Science Science hardware initiated asynchronous exceptions are known as interrupts

  38. Computer Science Science e.g., ctrl-C, ctrl-alt-del, power switch

  39. Computer Science Science interrupts are associated with specific processor (hardware) pins - checked after every CPU cycle - associated with interrupt handlers

  40. (system) memory Computer Science Science int. handler 0 code interrupt vector . . . 2 1 0 int #

  41. Computer Science Science interrupt procedure (typical) - save context (e.g., user process) - load OS context - execute handler - load context (for …?) - return

  42. Computer Science Science important: after switching context to the OS (for exception handling), there is no guarantee if / when a process will be 
 switched back in!

  43. Computer Science Science P 0 P 1 P 2 P 3 P 4 OS (kernel)

  44. Computer Science Science P 0 P 1 P 2 P 3 P 4 trap OS (kernel)

  45. Computer Science Science P 0 P 1 P 2 P 3 P 4 trap OS (kernel) handler

  46. Computer Science Science P 0 P 1 P 2 P 3 P 4 OS (kernel) handler

  47. Computer Science Science P 0 P 1 P 2 P 3 P 4 OS (kernel)

  48. Computer Science Science P 0 P 1 P 2 P 3 P 4 trap OS (kernel) handler

  49. Computer Science Science P 0 P 1 P 2 P 3 P 4 OS (kernel) handler

  50. Computer Science Science switching context to the kernel is potentially very expensive — but the only way to invoke system calls and access I/O

  51. Computer Science Science moral (to be reinforced ad nauseum): use system calls (traps) sparingly!

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend