Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lab 4 : Real-Time OS Team #7 P91922003 李彥勳 P90922016 謝嵩淮 R91921030 侯凱文.

Similar presentations


Presentation on theme: "Lab 4 : Real-Time OS Team #7 P91922003 李彥勳 P90922016 謝嵩淮 R91921030 侯凱文."— Presentation transcript:

1 Lab 4 : Real-Time OS Team #7 P91922003 李彥勳 P90922016 謝嵩淮 R91921030 侯凱文

2 Common Pitfall Use a global flag to test whether a shared resource is currently available or not: int buffer_busy; … while (buffer_busy==0); buffer_busy = 1; // write data into buffer

3 Common Pitfall Use a global flag to test whether a shared resource is currently available or not: int buffer_busy; … while (buffer_busy==0); buffer_busy = 1; // write data into buffer Busy Waiting

4 Common Pitfall Use a global flag to test whether a shared resource is currently available or not: int buffer_busy; … while (buffer_busy==0); buffer_busy = 1; // write data into buffer Interrupt

5 Common Pitfall ( continued ) Busy waiting : wasting CPU time. Even in the following situation, CPU load still heavy : while (buffer_busy==0) Sleep(0); Interrupt : if two tasks sharing the same buffer, two tasks may try to write this buffer simultaneously.

6 Common Pitfall ( continued ) This code section is frequently written by many engineers. Solution : using semaphore, mail box … IPC primitives so that the task can actually enter “ Waiting ” state without occupying CPU time-slice. ARM instruction “ SWP ” can be used to achieve “ atomic operation ” : ADR r0, SEMAPHORE SWPBr1,r1,[r0]

7 Critical Section Implementation of uC/OS-II Disable/Enable interrupt ARMDisableInt MRSr12, CPSR ORRr12, r12, #NoInt MSRCPSR_c, r12 MOVpc, lr That ’ s why it is not a “ HARD real time OS ”.

8 Priority Inversion A long existing terminology, recently it becomes a buzzword due to “ Pathfinder ” on Mars (RTOS: VxWorks). It refers to a lot of situation, may even be used intentionally to prevent starvation. Unbounded priority inversion : Priority inversion occurs in unpredictable manners.

9 Priority Inversion (continued)

10 The problem is that τ 1 and τ 3 share a common data structure, locking a mutex to control access to it. Thus, if τ 3 locks the mutex, and τ 1 tries to lock it, τ 1 must wait. Every now and then, when τ 3 has the mutex locked, and τ 1 is waiting for it, τ 2 runs because it has a higher priority than τ 3. Thus, τ 1 must wait for both τ 3 and τ 1 to complete and fails to reset the timer before it expires.

11 Priority Inversion (continued) Solution : priority inheritance protocol and priority ceiling protocol. Priority ceiling : raises the priority of any locking thread to the priority ceiling for each lock. Priority inheritance : raises the priority of a thread only when holding a lock causes it to block a higher priority thread.

12 Lab problems In 4.3.4 (eg3), if we did not define “ SEMIHOSTED ”, the stack will overflow and corrupt “ personal_info ” data structure. OSTimeDly() does not work, must reconfigure ARMulator according to 4.6.2. ( or just don ’ t use it )

13

14 Lab problems (continued) When AXD starts, it sometimes raise the following error, and AXD can ’ t continue : Solution : remove this file (default-1-2-0- 0.ses) and restarts AXD again.

15 Exercise Client task : Input ID Server task: Check the ID Simulate two tasks running in different machines. Server task controls all the important system parameters, and the checking rules. When checking rules or system parameters changed, only server side needs to be modified.

16 Exercise (continued) Client Task ’ s pseudo code : (input/output) while (1) { Obtain system parameters from server; Allocate memory for input strings; Do basic checking to reject strings that are longer than the length limit specified in system parameters; Send strings to server side; //authentication completes, do jobs. Free allocated memory; }

17 Exercise (continued) Server task ’ s pseudo code : (checking) while (1) { Wait for messages from client side; Do checking on the ID strings, and perform actions according to the result (here we display the results); Send system parameters to clients. }

18

19

20 Discussion What are the advantages and disadvantages of using an RTOS? Adv : With RTOS, we can speed up the software development cycle, since it can do “ resource allocation and managements ” for us. Dis : Increase the total code sizes, some embedded OS may took a lot of system resources.

21 Discussion (continued) Dis: may results in un-wanted behavior due to the internal mechanism (such as scheduler), for example, priority inversion. Adv/Dis: Without RTOS, user can take full control of everything, in other words, user must take care of everything, this might lengthen the development cycle according to the complexity of the application.

22 Conclusion If jobs can be done in a single task (simple application), no RTOS is needed. If jobs must be done in many different tasks which contest with each other for many shared resources – use RTOS. (eg: an embedded AP may require web service, telnet service, … )

23 Reference Modern Operating Systems, Andrew S. Tanenbaum. http://www.timesys.com/files/whitepap ers/Priority_Inversion_1.0-TM.pdf


Download ppt "Lab 4 : Real-Time OS Team #7 P91922003 李彥勳 P90922016 謝嵩淮 R91921030 侯凱文."

Similar presentations


Ads by Google