嵌入式系統(tǒng)課件lecture_第1頁
嵌入式系統(tǒng)課件lecture_第2頁
嵌入式系統(tǒng)課件lecture_第3頁
嵌入式系統(tǒng)課件lecture_第4頁
嵌入式系統(tǒng)課件lecture_第5頁
已閱讀5頁,還剩113頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、EmbeddedSoftware SystemAgendaEmbedded Software ArchitecturesReal time operating systems (RTOS)Software Layers3Survey Of Embedded Software ArchitecturesRound Robin State MachineRound Robin with Interrupts Just interruptsFunction Queue SchedulingReal time operating systems (RTOS)Round RobinRound Robin

2、 / Control LoopEverything is a function call from the main loop void main(void) while(TRUE) if (device_A requires service) service device_Aif (device_B requires service) service device_Bif (device_C requires service) service device_C. and so on until all devices have been serviced, then start over a

3、gainRound RobinLow priority tasks need to be slowed downvoid main(void) while(TRUE) if (device_A requires service) service device_Aif (device_B requires service) service device_Bif (device_A requires service) service device_Aif (device_C requires service) service device_Cif (device_A requires servic

4、e) service device_A. and so on, making sure high-priority device_A is always serviced on time6Round RobinPriority None, everything runs in sequence. Response time The sum of all tasks.Impact of changes Significant. Changing the execution time of tasks or adding tasks impacts all other tasks.Simplici

5、ty, no shared data problems.State Machinewhile(1) switch(state) case IDLE:check_buttons(); LEDisplay_hex(NUM1);if (BUTTON1 | BUTTON2 | BUTTON3)state=SHOW;break; case SHOW:NUM1=0;if (BUTTON1) NUM1 += 0x0001; if (BUTTON2) NUM1 += 0x0010; if (BUTTON3) NUM1 += 0x0100;state=IDLE; break;8State MachineSimi

6、lar to round robin, but only the current state gets executed.Each state determines the next state (non-sequential execution).State MachinePriority Each state determines the priority of the next state.Response time The sum of all tasks. Impact of changes Significant.Changing the execution time of tas

7、ks or adding tasks impacts all other tasks.Simplicity - No shared data problems.Round Robin with InterruptsBOOL flag_A = FALSE; /* Flag for device_A follow-up processing */* Interrupt Service Routine for high priority device_A */ ISR_A(void) . handle urgent requirements for device_A in the ISR, then

8、 set flag for follow-up processing in the main loop .flag_A = TRUE;void main(void) while(TRUE) if (flag_A)flag_A = FALSE. do follow-up processing with data from device_A if (device_B requires service)service device_Bif (device_C requires service) service device_C. and so on until all high and low pr

9、iority devices have been serviced11Round Robin with InterruptsPriority Interrupts get priority over main loopPriority of interrupts as wellResponse time The sum of all tasks orInterrupt execution timeImpact of changes Less significant for interrupt service routines. Same as Round Robin as main loop.

10、Shared data must deal with data shared with interrupt service routinesJust InterruptsSET_VECTOR(P3AD, button_isr); SET_VECTOR(TIMER1, display_isr); while(1) ;Just interruptsCan have problems if too many ISRsIf a high priority interrupt takes longer to execute than lower priority interrupts, then som

11、e will get missed.Or you need to deal with nested interrupts.Just InterruptsPriority Interrupts get priorityResponse time Interrupt execution timeImpact of changes Little significant for interrupt service routines.Shared data Must deal with data shared with interrupt service routinesFunction Queue S

12、chedulingFunction pointers are added to a queue.The main loop cycles through the queue and executes tasks.Tasks or interrupts add new tasks to the function queue.Function Queue Scheduling#define MAX_TASKS 20 typedef int(*FuncPtr)(); FuncPtr tasksMAX_TASKSint current_task = 0;void add_task(FuncPtr fu

13、nc) int n;for(n=current_task+1;nMAX_TASKS-1;n+) if(tasksn=NULL) tasksn=func; return;for(n=0;n=MAX_TASKS) current_task=0;19Function Queue SchedulingPriority Interrupts have priority.Tasks execute in sequenceResponse time Execution time of the longest taskImpact of changes Low. Interrupts manage prior

14、ity functions. Queue manages lower priority.Shared data must deal with data shared with interrupt service routinesFunction Queue ImprovementsInclude time schedulingtypedef int(*FuncPtr);An interrupt decrements all task timers.When it reaches 0 its available for executiontypedef struct long timer; in

15、t status; FuncPtr; Task;Task task_listMAX_TASKS;Function Queue ImprovementsInclude task prioritytypedef int(*FuncPtr);Highest priority tasks get moved to the head of the queue.typedef struct int priority; FuncPtr; Task;Task task_listMAX_TASKS;22Function PointersThe Function Pointer TutorialAgendaEmb

16、edded Software ArchitecturesReal time operating systems (RTOS)General OS m(Linux-like)Operating systemsThe operating system controls resources:who gets the CPU; when I/O takes place;how much memory is allocated.how processes communicate.The most important resource is the CPU itself.Cccess controlled

17、 by the scheduler.RTOS and GPOS相似的功能多任務(wù)級別軟件和硬件資源管理為應(yīng)用提供基本的OS服務(wù)從軟件應(yīng)用抽象硬件RTOS從GPOS中分離出來的不同功能嵌入式應(yīng)用上下文中具有更好的可靠性滿足應(yīng)用需要的剪裁能力更快的特性減少內(nèi)存需求為實時嵌入式系統(tǒng)提供可剪裁的調(diào)度策略支持無盤化嵌入式系統(tǒng),允許從ROM或RAM上引導(dǎo)和運行對不同硬件平臺具有更好的可移植性Real-time operating system (RTOS) featuresreliabilitypredictability, deterministic performancecompactnessscala

18、bilityCommercial RTOSs (partial)AMX (KADAK)C Executive (JMI Software) RTX (CMX Systems)eCos (Red Hat)IN TEGRI T Y (Green Hills Software) LynxOS (LynuxWorks)C/OS-II (Micrium)Neutrino (QNX Software Systems) Nucleus (Mentor Graphics)POSIX (IEEE Standard) FreeRTOS.orgRTOS-32 (OnTime Software)OS-9 (Micro

19、ware)OSE (OSE Systems)pSOSystem (Wind River)QNX (QNX Software Systems)Quadros (RTXC)RTEMS (OAR)ThreadX (Express Logic)Linux/RT (TimeSys)VRTX (Mentor Graphics)VxWorks (Wind River)Real-time Operating System (RTOS)Why use one?flexibilityresponse timeThe elemental component of a real-time operating syst

20、em is a task, and its straightforward to add new tasks or delete obsolete ones because there is no main loop:The RTOS schedules when each task is to run based on its priority.The part of the RTOS called a scheduler keeps track of the state of each task, and decides which one should be running.Real-t

21、ime systemsPerform a computation to conform to external timing constraints.Deadline frequency:Periodic.Aperiodic.Deadline type:Hard: failure to meet deadline causes system failure. Soft: failure to meet deadline causes degraded response.Firm: late response is useless but some late responses can be t

22、olerated.Timing specifications on processesRelease time: time at which process becomes ready.Deadline: time at which process must finish.Release times and deadlinestimeinitiating eventaperiodic processdeadlineP1Release times and deadlinesdeadlineP1timeinitiating eventperiodperiodic process initiated

23、 at start of periodRelease times and deadlinesdeadlineP1timerelease timeperiodperiodic process initiated by eventRate requirements on processesPeriod: interval between process activations.Rate: reciprocal of period.Initiation rate may be higher than period- several copies of process run at once.CPU

24、1CPU 2CPU 3CPU 4timeP11P12P13P14Timing violationsWhat happens if a process doesnt finish by its deadline?Hard deadline: system fails if missed.Soft deadline: user may notice, but system doesnt necessarily fail.Example: Space Shuttle software errorSpace Shuttles first launch was delayed by a software

25、 timing error:Primary control system PASS and backup system BFS. BFS failed to synchronize with PASS.Change to one routine added delay that threw off start time calculation.1 in 67 chance of timing problem.Process execution characteristicsProcess execution time Ti.Execution time in absence of preemp

26、tion. Possible time units: seconds, clock cycles.Worst-case, best-case execution time may be useful in some cases.Sources of variation:Data dependencies. Memory system.CPU pipeline.UtilizationCPU utilization:Fraction of the CPU that is doing useful work.Often calculated assuming no scheduling overhe

27、ad.Utilization:U = (CPU time for useful work)/ (total available CPU time)= S t1 t t2 T(t) / t2 t1= T/tState of a processA process can be in one of three states:executing on the CPU; ready to run;waiting for data.executinggets data and CPUgets CPUpreemptedneeds datagets datareadywaitingneeds dataThe

28、scheduling problemCan we mel deadlines?Must be able to meet deadlines in all cases.How much CPU horsepower do we need to meet our deadlines?Embedded vs. general-purpose schedulingWorkstations try to avoid starving processes of CPU access.Fairness = access to CPU.Embedded systems must meet deadlines.

29、Low-priority processes may not run for a long time.OS process managementOS needs to keep track of:process priorities; scheduling state;process activation record.Processes may be created:statically before system starts;dynamically during execution.Example: incoming telephone callMultitasking OSTask a

30、ctivation recordsOSProcess = unique execution of a programcode + datamultiple processes may share codeeach process has unique data(CPU registers, stack, memory)process defined by its “activation record”Multitasking OSProcess threads (lightweight processes)Task activation recordsOSThreads have own CP

31、U register values, but cohabit same memory space, so they could affect data of another thread.a process may have multiple threadsthreads may run on separate CPU coresTypical process/task activation records (task control blocks)Task IDTask state (running, ready, blocked) Task priorityTask starting ad

32、dress Task stackTask CPU registers Task data pointerTask time (ticks)When can a new thread be dispatched?Under non-preemptive scheduling:When the current thread completes.Under Preemptive scheduling:Upon a timer interruptUpon an I/O interrupt (possibly)When a new thread is created, or one completes.

33、 When the current thread blocks on or releases a mutex When the current thread blocks on a semaphoreWhen a semaphore state is changedWhen the current thread makes any OS callfile system access network access.The Focus Today:How to decide which thread to schedule?Considerations:Preemptive vs. non-pre

34、emptive schedulingPeriodic vs. aperiodiksFixed priority vs. dynamic priority Priority inversion anomaliesOther scheduling anomaliesMetricsHow do we evaluate a scheduling policy?Ability to satisfy all deadlines.CPU utilization-percentage of time devoted to useful work.Scheduling overhead-time require

35、d to make scheduling decision.lateness.total completion time.Preemptive SchedulingAssume all threads have prioritieseither statically assigned (constant for the duration of the thread) or dynamically assigned (can vary).Assume further that the kernel keeps track of which threads are “enabled” (able

36、to execute, e.g. not blocked waiting for a semaphore or a mutex or for a time to expire).Preemptive scheduling:At any instant, the enabled thread with the highest priority is executing.Whenever any thread changes priority or enabled status, the kernel can dispatch a new thread.Rate Monotonic Schedul

37、ingAssume n tasks invoked periodically with:periods T1, . ,Tn (impose real-time constraints) All tasks are independent.worst-case execution times (WCET) C1, . ,Cnassumes no mutexes, semaphores, or blocking I/Ono precedence constraints fixed prioritiesThe time required for context switching is neglig

38、iblepreemptive schedulingTheorem: If any priority assignment yields a feasible schedule, then priorities ordered by period (smallest period has the highest priority) also yields a feasible schedule.RMS is optimal in the sense of feasibility.Liu and Leland, “Scheduling algorithms for multiprogramming

39、 in a hard-real-time environment,” J. ACM, 20(1), 1973.Feasibility for RMSFeasibility is defined for RMS to mean that every task executes to completion once within its designated period.Showing Optimality of RMS: Consider two tasks with different periodsIs a non-preemptive schedule feasible?Showing

40、Optimality of RMS: Consider two tasks with different periodsNon-preemptive schedule is not feasible. Some instance of the Red Task(2) will not finish within its period if we do non-preemptive scheduling.Showing Optimality of RMS: Consider two tasks with different periodsWhat if we had a preemptive s

41、cheduling with higher priority for red task?Showing Optimality of RMS: Consider two tasks with different periodsPreemptive schedule with the red task having higher priority is feasible. Note that preemption of the blue task extends its completion time.Showing Optimality of RMS: Alignment of tasksCom

42、pletion time of the lower priority task is worst when its starting phase matches that of higher priority tasks.Thus, when checking schedule feasibility, it is sufficient to consider only the worst case: All tasks start their cycles at the same time.Showing Optimality of RMS: (for two tasks)It is suf

43、ficient to show that if a non-RMS schedule is feasible, then the RMS schedule is feasible.Consider two tasks as follows:Showing Optimality of RMS: (for two tasks)The non-RMS, fixed priority schedule looks like this:From this, we can see that the non-RMS schedule is feasible if and only ifC1C2T2We ca

44、n then show that this condition implies that the RMS schedule is feasible.Showing Optimality of RMS: (for two tasks)The RMS schedule looks like this: (task with smaller period moves earlier)The condition for the non-RMS schedule feasibility:C1C2T2is clearly sufficient (though not necessary) for feas

45、ibility of the RMS schedule. QED.CommentsThis proof can be extended to an arbitrary number of tasks (though it gets much more tedious).This proof gives optimality only w.r.t. feasibility. It says nothing about other optimality criteria.Practical implementation:Timer interrupt at greatest common divi

46、sor of the periodsMultiple timersRMSSchedulability analysis: A set of periodic tasks is schedulable with RM ifThis condition is sufficient but not necessary.The termdenotes the processor utilization factor U which is the fraction of processor time spent in the execution of the task set.Deadline Driv

47、en Scheduling:1. Jacksons Algorithm: EDD (1955)Given n independent one-time tasks with deadlinesd1, . , dn, schedule them to minimize the defined asum lateness,where fi is the finishing time of task i. Note that this is negative iff all deadlines are met.Earliest Due Date (EDD) algorithm: Execute th

48、em in order of non-decreasing deadlines.Note that this does not require preemption.Theorem: EDD is Optimal in the Sense ofMinimizingum LatenessTo prove, use an interchange argument. Given a schedule S that is not EDD, there must be tasks a and b where a immediately precedes b in the schedule butda d

49、b.Why?We can prove that this schedule can be improved by interchanging a and b.Thus, no non-EDD schedule is achieves smaller max lateness than EDD, so the EDD schedule must be optimal.Consider a non-EDD Schedule SThere must be tasks a and b where a immediately precedes b in the schedule but da dbDea

50、dline Driven Scheduling:1. Horns algorithm: EDF (1974)Extend EDD by allowing tasks to “arrive” (become ready) at any time.Earliest deadline first (EDF): Given a set of n independent tasks with arbitrary arrival times, any algorithm that at any instant executes the task with the earliest absolute dea

51、dline among all arrived tasks is optimal w.r.t.minimizing theum lateness.Proof uses a similar interchange argument.Using EDF for PeriodiksThe EDF algorithm can be applied to periodiks aswell as aperiodiks.Simplest use: Deadline is the end of the period.Alternative use: Separately specify deadline (relative to the period start time) and period.RMS vs. EDF? Which one is better?What are the pros and cons of each?Comparison of EDF and RMSFavor

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論