ENGG4420 CHAPTER 2 HOMEWORK

Similar documents
INTERRUPT MANAGEMENT An interrupt is a hardware mechanism used to service an event that can be external or internal to

Int tmytask() { while(1){ .. } }

Micrium µc/os II RTOS Introduction EE J. E. Lumpp

ENGG4420 CHAPTER 2 LECTURE 6

EE458 - Embedded Systems Lecture 8 Semaphores

Nios II. uc/os-ii porting with Nios II Altera Corporation

Exam TI2720-C/TI2725-C Embedded Software

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

Programming in Real-Time OS (uc/os-ii)

Micrium OS Kernel Labs

Introduction to Real-Time Operating Systems

Schedulability with resource sharing. Priority inheritance protocol Priority ceiling protocol Stack resource policy

NetBurner s uc/os RTOS Library

Micriμm. Getting Started with Micriμm s. Matt Gordon, Sr. Applications Engineer. 9L05I Renesas Electronics America Inc.

message passing model

Real-time operating systems and scheduling

OPERATING SYSTEMS. Prescribed Text Book. Operating System Principles, Seventh Edition. Abraham Silberschatz, Peter Baer Galvin and Greg Gagne

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

In Class Assignment 2

Lab 8 Real-time OS - 1

Real-Time and Concurrent Programming Lecture 4 (F4): Monitors: synchronized, wait and notify

General Objectives: To understand the process management in operating system. Specific Objectives: At the end of the unit you should be able to:

The components in the middle are core and the components on the outside are optional.

Interrupts and Time. Real-Time Systems, Lecture 5. Martina Maggio 28 January Lund University, Department of Automatic Control

Embedded Software TI2726 B. 7. Embedded software design. Koen Langendoen. Embedded Software Group

Lecture 3. Introduction to Real-Time kernels. Real-Time Systems

CHAPTER 3 LabVIEW REAL TIME APPLICATION DEVELOPMENT REFERENCES: [1] NI, Real Time LabVIEW. [2] R. Bishop, LabVIEW 2009.

Revision 1.6 March 26, uc/os RTOS Library

µc/os-ii for the Philips XA

GLOSSARY. VisualDSP++ Kernel (VDK) User s Guide B-1

Interrupts and Time. Interrupts. Content. Real-Time Systems, Lecture 5. External Communication. Interrupts. Interrupts

Multiprocessor scheduling

Zilog Real-Time Kernel

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Introduction to Embedded Systems. Lab Logistics

SYNCHRONIZATION M O D E R N O P E R A T I N G S Y S T E M S R E A D 2. 3 E X C E P T A N D S P R I N G 2018

Tasks. Task Implementation and management

Embedded Systems: OS. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

EECS 571 Principles of Real-Time Embedded Systems. Lecture Note #10: More on Scheduling and Introduction of Real-Time OS

Modern Embedded Systems Programming: Beyond the RTOS

Part B Questions. Unit I

Lecture 3: Concurrency & Tasking

Deadlock. Lecture 4: Synchronization & Communication - Part 2. Necessary conditions. Deadlock handling. Hierarchical resource allocation

Lecture notes Lectures 1 through 5 (up through lecture 5 slide 63) Book Chapters 1-4

DSP/BIOS Kernel Scalable, Real-Time Kernel TM. for TMS320 DSPs. Product Bulletin

What s An OS? Cyclic Executive. Interrupts. Advantages Simple implementation Low overhead Very predictable

Embedded Systems: OS

Verification of Real-Time Systems Resource Sharing

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Lecture 4: Real Time Semaphores

2.5 Timers Continuous Clock Task Timers Application Timers Memory Management

EE458 - Embedded Systems Introduction to uc/os

CLOCK DRIVEN SCHEDULING

FreeRTOS. A Brief Overview. Christopher Kenna. October 1, Avionics. FreeRTOS 1 / 34

Last Class: Synchronization

Lecture Topics. Announcements. Today: Advanced Scheduling (Stallings, chapter ) Next: Deadlock (Stallings, chapter

6/20/2018. Lecture 5: Real Time Messages

Semaphores. Chapter. verview inary Semaphores for Task Synchronization utex Semaphores to Solve Mutual Exclusion Problems

1 Process Coordination

Distributed Systems - I

Final Exam Study Guide

LabVIEW programming II

Short Term Courses (Including Project Work)

ZiLOG Real-Time Kernel Version 1.2.0

Today: Synchronization. Recap: Synchronization

Lecture 8: September 30

ENGR 3950U / CSCI 3020U UOIT, Fall 2012 Quiz on Process Synchronization SOLUTIONS

Modern Embedded Systems Programming: Beyond the RTOS

CS A320 Operating Systems for Engineers

Efficiency and memory footprint of Xilkernel for the Microblaze soft processor

Concurrency: Deadlock and Starvation

Final Examination. Thursday, December 3, :20PM 620 PM. NAME: Solutions to Selected Problems ID:

CS370 Operating Systems


Multiprocessor and Real- Time Scheduling. Chapter 10

Operating Systems (1DT020 & 1TT802)

Real-Time Programming

Zero-Latency Interrupts and TI-RTOS on C2000 Devices. Todd Mullanix TI-RTOS Apps Manager March, 5, 2018

Embedded Software TI2725 C. 5. Software architectures. Koen Langendoen. Embedded Software Group

EECE.4810/EECE.5730: Operating Systems Spring 2017

Putting it All Together

LabVIEW programming II

Programming Embedded Systems

Systemy RT i embedded Wykład 11 Systemy RTOS

Embedded Software Programming

Introduction to Embedded Systems

Midterm Exam. October 20th, Thursday NSC

CS A331 Programming Language Concepts

CS 162 Midterm Exam. October 18, This is a closed book examination. You have 60 minutes to answer as many questions

embos Real-Time Operating System CPU & Compiler specifics for embos Visual Studio Simulation

REAL-TIME MULTITASKING KERNEL FOR IBM-BASED MICROCOMPUTERS

A New Real-time Kernel development on an embedded platform

2 MARKS Q&A 1 KNREDDY UNIT-I

Concurrency Race Conditions and Deadlocks

CS 318 Principles of Operating Systems

EEL 4744C: Microprocessor Applications. Lecture 7. Part 1. Interrupt. Dr. Tao Li 1

Reading Assignment. Interrupt. Interrupt. Interrupt. EEL 4744C: Microprocessor Applications. Lecture 7. Part 1

Process & Thread Management II. Queues. Sleep() and Sleep Queues CIS 657

Process & Thread Management II CIS 657

Recall from deadlock lecture. Tuesday, October 18, 2011

Transcription:

CHAPTER 2 By Radu Muresan University of Guelph Page 1 TYPICAL MESSAGE QUEUE USE The following are typical ways to use message queues within an application: 1) non interlocked, one way data communication; 2) interlocked, one way data communication; 3) interlocked, two way data communication; 4) broadcast communication ENGG4420 CHAPTER 2 HOMEWORK October 26 10 11:44 AM One of the simplest scenarios for message based communications requires a sending task (also called the message source), a message queue, and a receiving task (also called a message sink), as illustrated in this figure. Non-interlocked, one-way data communication tsource The activities of tsource and tsink are not synchronized tsource () Send message to message queue } Sending task TSink tsink () Receive message from message queue } Receiving task The type of communication is also called non interlocked (or loosely coupled), oneway data communication. The activities of tsource and tsink are not synchronized. tsource simply sends a message; it does not require acknowledgment from tsink. Q: What happen if tsink has a higher or a lower priority? A: If tsink is set to a higher priority, it runs first until it blocks on an empty message queue. As soon as tsource sends a message to the queue, tsink receives the message and starts to execute again. If tsink is set to a lower priority, tsource fills the message queue with messages. Eventually, tsource can be made to block when sending a message to a full message queue. ISRs typically use non interlocked, one way communication. Remember, when ISRs send messages to the message queue, they must do so in a non blocking way. If the message queue becomes full, any additional messages that the ISR sends tot the message queue are lost.

CHAPTER 2 By Radu Muresan University of Guelph Page 2 Interlocked, one-way data communication Interlocked communication is based on the handshake process tsource TSink tsource () Send message to message queue Acquire binary semaphore } Sending task tsink () Receive message from message queue Give binary semaphore } Receiving task In some designs, a sending task might require a handshake (acknowledgement) that the receiving task has been successful in receiving the message. This process is called interlocked communication, in which the sending task sends a message and waits to see if the message is received. This requirement can be useful for reliable communication or task synchronization. For example, if the message for some reason is not received correctly, the sending task can resend it. Using interlock communication can close a synchronization loop. To do so, you can construct a continuous loop in which sending and receiving tasks operate in lockstep with each other. An example is presented in this figure, where tsource and tsink use a binary semaphore initially set to 0 and a message queue with a length of 1 (mailbox). The semaphore in this case acts as a simple synchronization object that ensures that tsource and tsink are in lockstep. This synchronization mechanism also acts as a simple acknowledgement to tsource that it s okay to send the next message.

CHAPTER 2 By Radu Muresan University of Guelph Page 3 Interlocked, two-way data communication Full-duplex or tightly coupled communication (bidirectional) tclient tserver tclient () Send message to the requests queue Wait for message from the server queue } Client task tserver () Receive message from the requests queue Send a message to the client queue } Sever task Sometimes data must flow bidirectionally between tasks, which is called interlocked, two way data communication (also called fullduplex or tightly coupled communication). This form of communication can be useful when designing a client/serverbased system. A diagram is provided in this figure. In this case, tclient sends a request to tserver via a message queue. tserver fulfills that request by sending a message back to tclient. Note that two separate message queues are required for full duplex communication. If any kind of data needs to be exchanged, message queues are required; otherwise, a simple semaphore can be used to synchronize acknowledgement. In the simple client/server example, tserver is typically set to a higher priority, allowing it to quickly fulfill client requests. Q: How do we deal with a situation where we have multiple clients? A: All clients can use the client message queue to post requests, while tserver uses a separate message queue to fulfill the different client s requests.

CHAPTER 2 By Radu Muresan University of Guelph Page 4 Broadcast communication Broadcast communication is a one-to-manytask relationship tbroadcast tsink 1 tsink 2 tsink 3 tbroadcast () Send broadcast message to queue } Sending task tsignal () Receive message on queue } Receiving task Some message queue implementations allow developers to broadcast a copy of the same message to multiple tasks, as shown in this figure. Message broadcasting is a one to many task relationship. tbroadcast sends the message on which multiple tsink are waiting. In this figure scenario, tsink 1, 2, and 3 have all made calls to block on the broadcast message queue, waiting for the message. When tbroadcast executes, it sends one message to the message queue, resulting in all three waiting tasks exiting the blocked state. Note that not all message queue implementations might support the broadcasting facility.

CHAPTER 2 By Radu Muresan University of Guelph Page 5 1. 2. 3. SUMMARY OF COMMON PRACTICAL DESIGN PATTERNS HOMEWORK Synchronous activity synchronization Asynchronous event notification using signals Resource synchronization (1) Synchronous activity synchronization binary semaphore 1 2 -to-task synchronization using binary semaphores Interrupt binary semaphore ISR 2 ISR-to-task synchronization using binary semaphores event register 1 1 0 0 0 0 0 2 -to-task synchronization using event registers Interrupt event register 1 0 0 0 0 0 ISR 2 ISR-to-task synchronization using event registers

CHAPTER 2 By Radu Muresan University of Guelph Page 6 Interrupt counting semaphore ISR 2 ISR-to-task synchronization using counting semaphores message queue 1 1 2 message queue 2 -to-task rendezvous using two message queues Signaled 1 Signal 2 Signal Routine singal_routine() 3 } asr_return() (2) Asynchronous event notification using signals (3) Resource Synchronization; Mutex #1 1 1 #2 shared memory 2 2 Shared Mem with Mutexes

CHAPTER 2 By Radu Muresan University of Guelph Page 7 Interrupt Interrupt lock 1 Interrupt Service Routine shared memory 2 ISR-to-task resource synchronization shared mem guarded by interrupt lock #1 1 Preemption lock 1 shared memory 2 2 Shared memory guarded by preemption lock #1 Control Information shared resource #1 1 #2 counting semaphore 2 MUTEX shared resource #1. shared resource #1 #N Sharing multiple instances of resource using counting semaphores and mutexes

CHAPTER 2 By Radu Muresan University of Guelph Page 8 ENGG4420 CHAPTER 2 ASSIGNMENTS October 26 10 12:12 PM PROBLEM. In a real time kernel, the tasks can be at any given time in one state determined by the kernel. Present the finite state machine (FSM) diagram for the task states supported by the uc/os II kernel. Place all the functions presented in the Functions List bellow on the corresponding arcs of your FSM. Functions List: OSSemPend(), OSTimeDly(), OSIntExit(), OSStart(), OSDel(), OSCreate, OSSemPost(), OSResume(), OSTimeDlyResume(). NOTE: In order to get full marks for this problem make sure that you present the uc/os II state machine not the general 3 states FSM. PROBLEM. A real time application uses tasks T1, T2, T3, Idle and an ISR. The task priorities are: T1_prio = 4; T2_prio = 6; and T3_prio = 8. At a particular moment in time t0, the tasks T1, T2 and T3 are waiting for an event E that needs to be set upon the arrival of an interrupt signal. Knowing the following: the interrupt system is enabled; the interrupt signal arrives at time t1 = t0 + 100 ms; the interrupt service routing (ISR) sets the event E at time t2 = t0 + 150 ms; the user code of the ISR executes for 70 ms; interrupt vectoring takes 1 ms; saving the CPU context takes 3 ms; OSIntEnter() function executes for 2 ms; a context restore takes 4 ms; the return from interrupt (RTI) takes 2 ms; OSIntExit() without context switch takes 3 ms; OSIntExit() with context switch takes 9 ms; (Note: The time values presented above are given only for calculation purposes and are not necessarily realistic) Answer the following questions: a) [1 marks] What task is executing at time t1? b) [1.5 marks] What is the interrupt response time? Show your calculation by indicating all the times included in the interrupt response time. c) [1 marks] What task executes shortly after the event E is set and why, specifically, at time t0 + 158 ms? d) [1.5 marks] What is the task response time for this interrupt scenario and what task executes at the end of the time response? Show your calculation by indicating all the times included in the task response time. e) [2 marks] Draw the diagram that captures the service interrupt scenario presented in this problem. Indicate on your diagram the actions taken by the system that correspond to each time step.

CHAPTER 2 By Radu Muresan University of Guelph Page 9 PROBLEM. A clock tick is a special interrupt that occurs periodically. The interrupt can be viewed as the system s heartbeat. All kernels allow tasks to be delayed for a certain number of clock ticks. The resolution of delayed tasks is one clock tick; however, this does not mean that its accuracy is one clock tick. Consider a system that has 3 tasks T1, T2, and T3 with priorities P1 > P2 > P3, respectively. We want to introduce a delay of one tick for task T3. For this analysis consider the following scenario: The tick interrupt takes place at every 20 ms; The tick ISR has a maximum execution time of 2 ms; s T1 and T2 execute each 20 ms cycle for a minimum time of 3 ms and a maximum time of 12 ms; T3 has a maximum execution time of 6 ms per 20 ms cycle; T3 has a system call to delay for 1 tick (20 ms) that is executed at 2 ms time after task T3 took hold of the CPU; Assume that the release time of all tasks is at the beginning of the tick cycle. (a) Present on Figure 2.1 the worst case scenarios that capture the maximum and minimum delay that can be incurred by task T3 when we consider the execution times described above. Show the times on the diagram in ms and show on your diagram the maximum and minimum delays in ms. Show the execution times for ISR, s T1&T2 combined, and T3.

CHAPTER 2 By Radu Muresan University of Guelph Page 10 DESIGN PROBLEM. Figure below presents a system level diagram for a data acquisition module. Within this system, the analog inputs must be read at regular intervals and offer the flexibility of adaptive acquisition. The ADC (Analog to Digital Conversion) is responsible for sampling the data and the INTELL SAMPLE is responsible for adding intelligence to the system acquisition. The ADC must be able to sample data at regular fixed intervals and at variable intervals controlled dynamically be the Intelligent Sampling (INTELL Sample). The INTELL Sample must communicate to the ADC the inputs to be sampled, the rate increase in the sampling interval, and conversion parameters when necessary. A simple way to accomplish regular interval sampling within a uc/os II environment is by using the OSTimeDly() function. However, in order to implement the intelligence capability of the module, you are required to use a message queue instead of the OSTimeDly() function. (a) Present a message queue based design for this acquisition module. The message queue must be used to solve the sample delay problem and to communicate the intelligent services that are required. Note that the OSQPend service call has a timeout parameter that can be used to solve the time delay sample problem. The design should show the main structure of the main function, and the tasks ADC and INTELL SAMPLE. You are required to use the proper uc/os II system functions that relate to creating the tasks and creating and using the message queue. Use the example programs shown in the lectures and your labs. //variable declarations that you can use, you can add more if needed void *QueueArray [10]; OS_EVENT *QueueSample; OS_STK ADC S [1000]; OS_STK INTELL_Sample S [1000] // Continue with the program showing the main program and the two tasks

CHAPTER 2 By Radu Muresan University of Guelph Page 11 PROBLEM (PIP, PCP). Consider the following tasks with their resource requirements given as: T3 = (0, 10, 3; [S1; 7]), where the task executes for two time units, then requests the resource (critical section) S1. T2 = (4, 8, 2; [S2; 5 [S1; 2][S3; 1]]), where the task executes for one time unit, then requests the resource (critical section) S2 and holds it for one time unit and makes a nested request for S1. After finishing with S1 the task makes a nested request (from S2) for S3. T1 = (8, 10, 1; [S3; 7 [S1; 3][S2; 2]]), where the task executes for one time unit, then requests the resource (critical section) S3 and holds it for one time unit and makes a nested request for S1. After finishing with S1 the task makes a nested request (from S3) for S2. Here, the notation Ti = (ri, ei, πi, [R; t]) indicates that the task Ti is released at time ri, has the execution time ei, priority πi (the lower the value of πi, the higher the priority), and the critical section [R; t] for the resource R and the execution time t (total hold time of R). Note that ei is the total execution time including the times that the task holds the resources; And the representation [R; t [S; w][u;v]] denotes nested critical sections, that is, the usage of resource R includes the usage of resource S and U, and time t includes the time w and v of the critical sections S and U, respectively. Also, this notation indicates that S and U are nested within critical section R and execute sequentially in this order. (a). [3 marks]. Using the grid in Table 4.1 present the schedule of the above tasks based on the priority inversion protocol (PIP). (b). [1 mark]. What is the task status within the PIP schedule at time 20? (c). [1 mark]. Propose a solution to the problem that you identified at (b).

CHAPTER 2 By Radu Muresan University of Guelph Page 12

CHAPTER 2 By Radu Muresan University of Guelph Page 13

END OF CHAPTER 2 CHAPTER 2 By Radu Muresan University of Guelph Page 14