Download presentation
Presentation is loading. Please wait.
Published byBrice Burns Modified over 9 years ago
1
© 2000 Morgan Kaufman Overheads for Computers as Components Processes and operating systems zMotivation for processes. zThe process abstraction. zContext switching. zMultitasking. zProcesses and UML.
2
© 2000 Morgan Kaufman Overheads for Computers as Components Why multiple processes? zProcesses help us manage timing complexity: ymultiple rates xmultimedia xautomotive yasynchronous input xuser interfaces xcommunication systems
3
© 2000 Morgan Kaufman Overheads for Computers as Components Example: engine control zTasks: yspark control ycrankshaft sensing yfuel/air mixture yoxygen sensor yKalman filter engine controller
4
© 2000 Morgan Kaufman Overheads for Computers as Components Life without processes zCode turns into a mess: yinterruptions of one task for another yspaghetti code time A B C A C A_code(); … B_code(); … if (C) C_code(); … A_code(); … switch (x) { case C: C(); case D: D();...
5
© 2000 Morgan Kaufman Overheads for Computers as Components Co-routines ADR r14,co2a co1a … ADR r13,co1b MOV r15,r14 co1b … ADR r13,co1c MOV r15,r14 co1c... co2a … ADR r13,co2b MOV r15,r13 co2b … ADR r13,co2c MOV r15,r13 co2c … Co-routine 1 Co-routine 2
6
© 2000 Morgan Kaufman Overheads for Computers as Components Co-routine methodology zLike subroutine, but caller determines the return address. zCo-routines voluntarily give up control to other co-routines. zPattern of control transfers is embedded in the code.
7
© 2000 Morgan Kaufman Overheads for Computers as Components Processes zA process is a unique execution of a program. ySeveral copies of a program may run simultaneously or at different times. zA process has its own state: yregisters; ymemory. zThe operating system manages processes.
8
© 2000 Morgan Kaufman Overheads for Computers as Components Processes and CPUs zActivation record: copy of process state. zContext switch: ycurrent CPU context goes out; ynew CPU context goes in. CPU PC registers process 1 process 2... memory
9
© 2000 Morgan Kaufman Overheads for Computers as Components Terms zThread = lightweight process: a process that shares memory space with other processes. zReentrancy: ability of a program to be executed several times with the same results.
10
© 2000 Morgan Kaufman Overheads for Computers as Components Processes in POSIX zCreate a process with fork: yparent process keeps executing old program; ychild process executes new program. process a process b
11
© 2000 Morgan Kaufman Overheads for Computers as Components fork() zThe fork process creates child: childid = fork(); if (childid == 0) { /* child operations */ } else { /* parent operations */ }
12
© 2000 Morgan Kaufman Overheads for Computers as Components execv() zOverlays child code: childid = fork(); if (childid == 0) { execv(“mychild”,childargs); perror(“execv”); exit(1); } file with child code
13
© 2000 Morgan Kaufman Overheads for Computers as Components Context switching zWho controls when the context is switched? zHow is the context switched?
14
© 2000 Morgan Kaufman Overheads for Computers as Components Co-operative multitasking zImprovement on co-routines: yhides context switching mechanism; ystill relies on processes to give up CPU. zEach process allows a context switch at cswitch() call. zSeparate scheduler chooses which process runs next.
15
© 2000 Morgan Kaufman Overheads for Computers as Components Problems with co- operative multitasking zProgramming errors can keep other processes out: yprocess never gives up CPU; yprocess waits too long to switch, missing input.
16
© 2000 Morgan Kaufman Overheads for Computers as Components Context switching zMust copy all registers to activation record, keeping proper return value for PC. zMust copy new activation record into CPU state. zHow does the program that copies the context keep its own context?
17
© 2000 Morgan Kaufman Overheads for Computers as Components Context switching in ARM zSave old process: STMIA r13,{r0-r14}^ MRS r0,SPSR STMDB r13,{r0,r15} z Start new process: ADR r0,NEXTPROC LDR r13,[r0] LDMDB r13,{r0,r14} MSR SPSR,r0 LDMIA r13,{r0-r14}^ MOVS pc,r14
18
© 2000 Morgan Kaufman Overheads for Computers as Components Preemptive multitasking zMost powerful form of multitasking: yOS controls when contexts switches; yOS determines what process runs next. zUse timer to call OS, switch contexts: CPU timer interrupt
19
© 2000 Morgan Kaufman Overheads for Computers as Components Flow of control with preemption time P1OSP1OSP2 interrupt
20
© 2000 Morgan Kaufman Overheads for Computers as Components Preemptive context switching zTimer interrupt gives control to OS, which saves interrupted process’s state in an activation record. zOS chooses next process to run. zOS installs desired activation record as current CPU state.
21
© 2000 Morgan Kaufman Overheads for Computers as Components Why not use interrupts? zWe could change the interrupt vector at every period, but: ywe would need management code anyway; ywe would have to know the next period’s process at the start of the current process.
22
© 2000 Morgan Kaufman Overheads for Computers as Components Processes and UML zA process is an active class---independent thread of control. processClass1 myOperations() start resume myAttributes Signals
23
© 2000 Morgan Kaufman Overheads for Computers as Components UML signals zSignal: object that is passed between processes for active communication: acomm: datasignal
24
© 2000 Morgan Kaufman Overheads for Computers as Components Designing with active objects zCan mix normal and active objects: p1: processClass1 master: masterClass w: wrapperClass a: rawMsg ahat: fullMsg
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.