嵌入式操作系统.ppt
《嵌入式操作系统.ppt》由会员分享,可在线阅读,更多相关《嵌入式操作系统.ppt(66页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、Ch4 Process and Operating System,Content,Motivation for processesThe process abstractionContext switching and MultitaskingOperating SystemScheduling policies:RMS;EDF.Interprocess communication.,Multi-task System,Multiple tasksmanage timing complexity:multiple ratesmultimediaautomotiveasynchronous in
2、putuser interfacescommunication systems,Life without processes,Code turns into a mess:interruptions of one task for anotherspaghetti 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(); .,Co-routines,ADR r14,co2aco1a ADR r13,co1bMOV r15,r14co1b ADR r13,
3、co1cMOV r15,r14co1c .,co2a ADR r14,co2bMOV r15,r13co2b ADR r14,co2cMOV r15,r13co2c ,Co-routine 1,Co-routine 2,Co-routine methodology,Like subroutine, but caller determines the return address.Co-routines voluntarily give up control to other co-routines.Pattern of control transfers is embedded in the
4、code.,Foreground/background system,又称超循环系统(super loops)应用程序是一个无限循环,循环中调用相应的函数完成相应的操作,可以看作后台行为(任务级);中断服务程序处理异步事件,可以看作前台行为(中断级)。,Processes,A process is a unique execution of a program.Several copies of a program may run simultaneously or at different times.A process has its own state:registers;memory.
5、The operating system manages processes.,Processes and CPUs,Activation record: copy of process state.Context switch:current CPU context goes out;new CPU context goes in.,CPU,PC,registers,process 1,process 2,.,memory,Terms,Thread = lightweight process: a process that shares memory space with other pro
6、cesses.Reentrancy: ability of a program to be executed several times with the same results.,可重入函数,可重入函数:可以被多个进程同时调用不必担心数据破坏的函数。两种情况:只使用局部变量,即变量保存在寄存器或堆栈中;使用全局变量,则对全局变量进行保护,Examples,Processes in POSIX,Create a process with fork:parent process keeps executing old program;child process executes new pro
7、gram.,process a,process a,process b,fork(),The fork process creates child:childid = fork();if (childid = 0) /* child operations */ else /* parent operations */,execv(),Overlays child code:childid = fork();if (childid = 0) execv(“mychild”,childargs);perror(“execv”);exit(1);,file with child code,Conte
8、xt switching,Who controls when the context is switched?How is the context switched?,Co-operative multitasking,Improvement on co-routines:hides context switching mechanism;still relies on processes to give up CPU.Each process allows a context switch at cswitch() call.Separate scheduler chooses which
9、process runs next.,Problems with co-operative multitasking,Programming errors can keep other processes out:process never gives up CPU;process waits too long to switch, missing input.,Preemptive multitasking,Most powerful form of multitasking:OS controls when contexts switches;OS determines what proc
10、ess runs next.Use timer to call OS, switch contexts:,CPU,timer,interrupt,Flow of control with preemption,time,P1,OS,P1,OS,P2,interrupt,interrupt,Preemptive context switching,Timer interrupt gives control to OS, which saves interrupted processs state in an activation record.OS chooses next process to
11、 run.OS installs desired activation record as current CPU state.,Context switching,Must copy all registers to activation record, keeping proper return value for PC.Must copy new activation record into CPU state.,Context switching in ARM,Save old process:STMIA r13,r0-r14MRS r0,CPSRSTMDB r13,r0,r15,St
12、art new process:ADR r0,NEXTPROCLDR r13,r0LDMDB r13,r0,r14MSR CPSR,r0LDMIA r13,r0-r14MOVS pc,r14,Processes and UML,A process is an active class-independent thread of control.,processClass1,myOperations(),startresume,myAttributes,Signals,UML signals,Signal: object that is passed between processes for
13、active communication:,acomm: datasignal,Designing with active objects,Can mix normal and active objects:,p1: processClass1,master: masterClass,w: wrapperClass,a: rawMsg,ahat: fullMsg,Operating systems,The operating system controls resources:who gets the CPU;when I/O takes place;how much memory is al
14、located.The most important resource is the CPU itself.CPU access controlled by the scheduler.,Process state,A process can be in one of three states:executing on the CPU;ready to run;waiting for data.,executing,ready,waiting,gets dataand CPU,needsdata,gets data,needs data,preempted,getsCPU,Priority-d
15、riven scheduling,Each process has a priority.CPU goes to highest-priority process that is ready.Priorities determine scheduling policy:fixed priority;time-varying priorities.,Priority-driven scheduling example,Rules:each process has a fixed priority (1 highest);highest-priority ready process gets CP
16、U;process continues until done.ProcessesP1: priority 1, execution time 10P2: priority 2, execution time 30P3: priority 3, execution time 20,Priority-driven scheduling example,time,0,30,10,20,60,40,50,P2,P2,P1,P3,Operating system structure,OS needs to keep track of:process priorities;scheduling state
17、;process activation record.Processes may be created:statically before system starts;dynamically during execution.,Embedded vs. general-purpose scheduling,Workstations try to avoid starving processes of CPU access.Fairness = access to CPU.Embedded systems must meet deadlines.Low-priority processes ma
18、y not run for a long time.,Interprocess communication,Interprocess communication (IPC): OS provides mechanisms so that processes can pass data.Two types of semantics:blocking: sending process waits for response;non-blocking: sending process continues.,IPC styles,Shared memory:processes have some mem
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 嵌入式 操作系统
限制150内