Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

UNIT IV REAL TIME OPERATING SYSTEMS CONCEPTS 1. Define RTOS.

Operating System with real time task scheduling, interrupt-latency control, Synchronization of tasks with IPCs, predictable timing and synchronization behavior of the system. 2. Name some RTOS services. (i) Basic OS functions (ii) RTOS Main functions (Task Scheduling & interrupt latency control) (iii) Time Management (iv) Predictability 3. Compare OS and RTOS. OS:On a PC, OS takes control of the PC as soon as it is turned on and then it lets the application program to start. OS checks any pointer which passes into a system function for its validity. OS consumes lot of memory space and it contains all in-built functions. RTOS: Application program is linked to the RTOS. At boot-up, application usually gets control first and then it starts RTOS. Many RTOS don not protect themselves and skip the checking process for better performance. To save memory, RTOS has only the functions needed for an application. 4. What is Round Robin or cyclic scheduling? A scheduling algorithm in which the tasks are scheduled in sequence from a list of ready tasks. 5. Explain briefly about Preemptive scheduling. A scheduling algorithm in which a higher priority task is forced (Preempted) to block the low priority task by the scheduler. 6. What is Time Slicing and Fixed real time scheduling? Time Slicing Scheduling A scheduling algorithm in which each task is allotted a time slice after which it is blocked and waits for its turn on the next cycle. Fixed Real Time Scheduling A scheduling strategy in which the time for each task is fixed. 7. Explain briefly the term Task. Task is a subroutine in an application that makes certain action to be performed. A Task that has its independent program counter values and an independent stack. A single CPU system runs one task at a time. 8. What is Task State? A state of a task changes on scheduler directions. A task at an instance can be in one of the four states, idle, ready, blocked ad running that are controlled by the scheduler. 9. Explain Task scheduler. It is part of a RTOS. It keeps track of the state of each task and decides which one task should go into the running state. Scheduler in an RTOS looks at the priorities assigned to tasks, and among the tasks that not in the blocked state, the one with highest priority is allowed to run and the rest of them are made to wait in the ready state. 10. When a blocked task is allowed to run on a processor? When a task is blocked, it never gets the processor. Therefore, an interrupt routine or some another task in the system should signal that whatever the blocked task waiting for has happened. Otherwise, the task will be blocked forever. 11. How does a scheduler know whether a task is blocked or not? RTOS provides a collection of functions that tasks can tell a scheduler what events they wait for and to signal that events have happened.

12. What happens if all the tasks are blocked? If all the tasks are blocked, then the scheduler will spin in some tight loop somewhere inside the RTOS, waiting for something to happen. If nothing ever happens, then it ends in an infinite loop. Therefore care must be taken by programmer to invoke a interrupt routine that call some RTOS function that unblocks a task. 13. What if two tasks with the same priority are ready? There are two options in this situation. (1) RTOS should declare as illegal when two tasks are assigned with same priority. (2) RTOS can time-slice between two tasks that has the same priority. 14. List the rules to decide if a function is Re-entrant. 1. A reentrant function may not use variables in a non-atomic way unless they are stored on the stack of the task that call the function or are otherwise the private variables of that task. 2. A reentrant function may not call any other functions that are not themselves reentrant. 3. A reentrant function may not use the hardware in a non-atomic way. 15. Define Inter process communication (IPC). An output from one task (or process) passed to another task through the scheduler and use of signals, exceptions, semaphores, queues, mailboxes, pipes, sockets, and remote procedure call is known as inter process communication. 16. Define Semaphore. Semaphore is a special variable or function that is used to take note of certain actions to prevent another task or process from proceeding. 17. List the semaphore related problems. Forgetting to take the semaphore Forgetting to release the semaphore Taking the wrong semaphore Holding a semaphore too long 18. Explain Mutex, Counting and Resource Semaphore. Mutex Semaphore A special variable used to take note of certain actions to prevent any task or process from proceeding further and at the same time let another task exclusively proceed further. Counting Semaphore Sometimes, a semaphore can be taken multiple times. A semaphore can be an integer which can be incremented when released and decremented when taken. If a task tries to take a semaphore when the integer value is equal to 0, then the task will be blocked. This is called Counting semaphore. Resource Semaphore Sometimes RTOS allows a semaphore to be released only by the task that has taken them. These semaphores are useful for shared data problem, but cannot be used for communication between two tasks. Such semaphores are called as Resource semaphores. 19. What are the problems that may arise while using semaphores? The problems that may while using semaphores are, Sharing of two semaphores creates a deadlock problem. Without a timeout an ISR worst-case latency may exceed the deadline. If a semaphore is not taken, and another task uses a shared variable. When using multiple semaphores, if an unintended task takes the semaphore, it creates a problem. It may introduce priority inversion problem.

20. What is shared data problem? If a variable is used in two different tasks and another task if interrupts without before the operation on that variable is completed, then the shared data problem arises. 21. List the ways to protect the shared data. Disabling the interrupts Taking semaphores Disabling the task switches 22. Explain briefly Deadly embrace situation. Consider a situation in which two tasks (task1 and task2) are using two semaphores, semaphore_A and semaphore_B. When task1 is run, it takes semaphore_A and before it proceeds further and takes semaphore_B, RTOS switches to task2. Now task2 takes semaphore_B and it waits for release of semaphore_A by task1. None of these tasks are able to proceed further. This situation is called Deadly embrace. 23. What is priority inversion problem? How it can be solved? A problem in which a low priority task unintentionally do not release the semaphore for a higher priority task. This makes the high priority task to wait for low priority task to release the semaphore. This is called Priority Inversion. This problem can be solved by temporarily boosting the low priority task to higher priority task which is called as priority inheritance.

24. Explain the term (i) Message Queue (ii) Mailbox (iii) Pipe (iv) Socket. Message Queue RTOS allows a task to send multiple messages into a FIFO queue for use by another task(s) using queue message as an input. Mailbox RTOS allows a certain no. of messages to be stored in each mailbox. Separate functions are used to identify the appropriate mailbox, to add and read a message from the selected mailbox. Pipe Pipes are like queues. RTOS can create them, write to them, read from them and so on. Socket It provides the logical link using a protocol between the tasks in a clientserver or peer-to-peer environment.

25. List the pitfalls in using Mailbox, Message queues and Pipes. Most of the RTOS do not restrict which tasks can read from or write to any given queue, mailbox or pipe. Therefore, programmer must ensure that tasks use the correct one each time. RTOS cannot ensure that data written onto a queue, mailbox or a pipe will be properly interpreted by the tasks that read it. Running out of space in queues, mailboxes or pipes is usually a disaster for embedded software. Passing pointers from one task to another through a queue, mailbox or pipe is one of the several ways to create shared data inadvertently. 26. What is Timer and counting devices? A Timer gets the inputs from the internal clock of a processor or from system clock and generates a required time delay. Counting device is a unit for getting the count-inputs on the occurrence of events that may be at irregular intervals. 27. What are the types of Timer? There are two types of timer. They are, Hardware timer Software timer 28. What is Timer Overflow or Time-Out? A state in which the number of count inputs exceeded the last acquirable value and on reaching that state, an interrupt can be generated. This state is called Time-Out or Timer Overflow. 29. What is the difference between hardware timer and software timer? Hardware timer gets the inputs from the internal clock with the processor or system clock. A device driver program programs it like any other physical device. Software timer executes a program which increases or decreases a count variable on an interrupt from a timer output or from a real-time clock interrupt. 30. What are the different states in a timer? The different states in a timer are, Reset State Idle State Present State Overflow State Active or Blocked State Done State 31. Is it necessary to have a hardware timer device in a system? How does it work? Yes, it is necessary to have atleast one hardware timer device in a system. It is used as a system clock. The hardware timer gets the input from a clock out signal from the processor and activates the system clock as per the num ticks preset at the hardware timer. 32. What is an Event? An event is essentially a Boolean flag that tasks can set or reset and that other tasks can wait for. Event invokes a interrupt routine that runs a waiting task.

33. Compare Semaphores, Events and Queues/Mailbox/Pipe. Semaphores are usually the fastest and simplest methods. However, not much information can be passed through a semaphore, which passes just a 1-bit message saying that it has been released. Events are a little more complicated than semaphores and take little more of processor time. The advantage of events over semaphores is that a task can wait for any one of the several events at the same time and it can wait for only one semaphore. Queues (also mailboxes & pipes) allow sending a lot of information from one task to another. The drawback of queues (also mailboxes and pipes) is that adding and reading a message is more processor intensive and more prone to insert bugs while programming them. 34. How a block of data is passed using queue? Passing a pointer to a buffer from one task to another through a queue is a common way to pass a block of data. 35. Explain the problem in using malloc() and free() functions for memory management in RT embedded systems. In real time embedded systems, malloc() and free() are avoided because of their slow response and unpredictable execution times. Instead, most of the RTOS offer fast and predictable functions along with free fixed size buffers. 36. List the two rules that an interrupt routine must follow in RTOS environment, that do not apply to task codes. Rule-1: An interrupt routine must not call any RTOS function that might block the caller. Rule-2: An interrupt routine may not call any RTOS function that might cause the RTOS to switch tasks unless the RTOS knows that an interrupt routine, and not a task is executing

You might also like