Design and Implementation of LST Based Dynamic Scheduler on Real Time OS

Size: px
Start display at page:

Download "Design and Implementation of LST Based Dynamic Scheduler on Real Time OS"

Transcription

1 Design and Implementation of LST Based Dynamic Scheduler on Real Time OS Prasad M Kamath, Rakesh Belagali, Sushant S Kulkarni, Vinayak Hegde, Geetishree Mishra Department of Electronics and Communication, BMSCE, Bangalore, India Abstract: Real-time systems have to complete the execution of a task within the predetermined time while ensuring that the execution results are logically correct. Such systems require scheduling methods that can adequately distribute the given tasks to a processor.the current paper presents the implementation of a least slack time first dynamic scheduling algorithm based on laxity of a task to support number of real time applications on a single processor. The proposed algorithm overcomes the limitation of real-time static algorithm in tracking the task and provides more controllability and predictability to dynamic algorithm. The proposed algorithm is simulated for independent, preemptive and periodic tasks. The algorithm was implemented on development board TIVA TMC4GXL123 and results are verified. Keywords: least slack time first, RTOS, Real-Time System and Scheduler, context switching, periodic task. 107 I. INTRODUCTION The use of computers to control safety-critical real-time functions has increased rapidly over the past few years. As a consequence, real-time systems computer systems where the correctness of a computation is dependent on both the logical results of the computation and the time at which these results are produced have become the focus of much study. The real-time system is a system where timely response to external action is vital. The real time systems accept commands from external peripherals, process the data and then perform the desired action. Such a system runs tasks that have deadlines. Each task must be executed within its allocated time i.e. deadline. Real time systems not only complete tasks within the predetermined time but also obtain logically correct results. [1] In addition to providing these functions, such systems also have to satisfy basic requirements such as reliability, predictability, and adaptability in singleprocessor and multiprocessor environments. According to the extent to which the value of an executed result satisfies the requirements, systems are categorized as a hard or a soft real-time system. A hard real-time system has to complete all given tasks within each predetermined deadline, otherwise some of the results would be useless and a serious disaster could occur. In a soft real-time system, the faster the finish time is, the greater the usefulness of the system is. Even if the execution of the task is completed after its deadline, its result is still useful. [4] r i r i D i e i d i Fig1: Timeline of a Task All tasks in real-time systems have timing constraints that basically comprises the release time, relative deadline, absolute deadline, and execution time, as shown in figure 1. The release time (ri) represents the time when a task arrives in a ready queue for execution. The relative deadline (Di, or di-ri) is the maximum amount of time within which a task should be completed. The absolute deadline (di, or Di+ri) is the time at which the execution of a task should be completed. Finally, the execution time (ei) represents the amount of time (theoretical minimum execution time) required for the task process [1]. Many tasks occur simultaneously and each has its own timing constraints. For satisfying these constraints, especially task deadline, systems require scheduling methods that suitably distribute tasks to a processor. They are classified into dynamic and static (fixed) priority scheduling algorithms according to the scheduling method used [1]. Dynamic priority scheduling algorithms such as EDF (Earliest Deadline First) and LST (Least Slack Time First) assign different priorities to an individual job in each task. On the other hand, static priority scheduling algorithms such as RM (Rate Monotonic) and DM (Deadline Monotonic) assign the same priority to all jobs in each task. In the current paper, we propose a dynamic priority scheduling algorithm called Least Slack Time First (LSTF) for a single processor environment. The algorithm can feasibly assign all of tasks into processor. Section II describes the background of this research such as Scheduler, LST, FreeRTOS and limitations of existing scheduling algorithms. In section III, the proposed algorithm and implementation have been explained exhaustively. Section IV describes the test methodology and section V the performance evaluation t

2 of the proposed algorithm. In section VI the work done is concluded. II. RELATED WORK A study of definitions and specific features of existing scheduling algorithms was done. Based on these studies, LSTF algorithm was designed and implemented. A. Static Priority Algorithm Static or fixed-priority preemptive scheduling is a scheduling algorithm commonly used in real-time systems. [2] With fixed priority preemptive scheduling, the scheduler ensures that at any given time, the processor executes the highest priority task of all those tasks that are currently ready to execute. B. Earliest Deadline First (EDF) EDF is a very simple and famous algorithm that the earlier the deadline, the higher the priority; the scheduler operates when each processor task is completed or when a task wakes up in the ready queue. Let us assume three tasks with time constraints in a ready queue, as shown in table 1. Each task scheduled is divided into several jobs. According to the timing constraints listed in table 1, the scheduling process is carried out like table 2. [3] Task Table 1. Three Tasks With Timing Constraints r i T T D i e i The three tasks are released at the initial time (t = 0). The scheduler attempts to compare the deadlines of each task and then assigns the highest priority to T1 because its deadline is the smallest as value 2. Therefore, a job (J1) of T1 is executed on the processor. At t = 1, the scheduler wakes up since T1 has just completed. The scheduler then determines that T2 has the highest priority. When t = 2, T1 is awakened due to its period, and between T1 and T3, the scheduler selects T1 (T2 is already finished when t = 2). T3 is then processed by the scheduler for the first time when t = 4. The three tasks are processed while each timing constraint is satisfied through iterative operations. [4] C. Latest Release Time First (LRT) LRT determines that the later the release time is, the higher the priority is. This is the opposite of EDF. In other words, LRT considers the release time and relative deadlines and schedules jobs in the reverse order, starting from the latest deadline among all jobs. If LRT schedules the same task of table 1 then, the result is same to table 2 scheduled by EDF. [4] D. Least Slack Time First (LST) LST algorithm follows a rule that the smaller slack time, the higher priority. The slack time means the remaining spare time (d i - e r i - t) at the current time. The r e i represents the time required to complete the remaining work of a task. It can be considered to be the optimal algorithm for a single processor. i e i r Slack T r i t d i r i : Release time, D i : relative deadline, e i : execution time, the tasks are periodic and the deadline coincides with the period. Table 2. Scheduling Process Using EDF Algorithm T T T T Fig 2: Timeline of a Task in LST III. ALGORITHM A dynamic priority scheduler is more efficient in meeting deadlines required for time critical application processes. While designing a real time scheduling algorithm the following conditions were imposed and satisfied The task set is feasible, in the sense that all task execute after their release time and finish before their deadlines. The task set is schedulable. The schedule-ability criterion is met:.(1) 108

3 The tasks in a task set are periodic with the relative deadline equal to its period. The tasks in the task set are independent and have no precedence constraints. The task has minimum pre-emption overhead. The most significant operation in a task is processing as compared to I/O requirements. [5] Fig 4. Flowchart of LST Algorithm Fig 3: Block Diagram of Implementation The Least Slack time first algorithm is implemented in C on FreeRTOS an open source Real time operating system. The algorithm is as shown in figure 4 All tasks are released at t=0. Initially, based on their static slacks the task with lowest slack time is assigned the highest priority and occupies the top most ready queue, the subsequent tasks are added to their appropriate queues based on priority. On completion of execution the tasks wake at their next period. This process is illustrated by means of a block diagram in figure 3 The slack time for each task is calculated using the equation: (2) The switching is done in the following manner. If a task has a slack time higher than the task in the ready list i, then the task is compared with other lists and appropriately inserted. If the slack times are equal then it is inserted in the same list at the tail of the queue. If the slack time is lesser than the task in the list i then it is added to the list i+1 and the currently executing task will yield and pass control to the new one. In this manner, it is ensured that all tasks meet their deadlines effectively. IV. TEST METHODOLGY For the testing of our project, we have used the serial monitor and LED present on the Tiva TM4C123GXL board to indicate the task which is being executed and also the state of the other tasks when they are not being executed. The LED blinks to indicate the task being run. The serial monitor on the Energia HyperTerminal also gives information on the states of the other tasks and the state of the ready queues. Each periodic task is indicated whether it is ready, has been blocked, is inactive or is executing. By allowing us to view the different states of the tasks, we were able to identify and rectify any cases where a particular task was missing its deadline or was not being executed correctly. A multiple of test cases were used to ensure the correct working of the code. The two scheduling algorithms, EDF and LST are run on the Tiva TM4C123GXL board and the following tests are performed: 1. All tasks are independent of each other and are Schedulable according to the condition for scheduleability i.e...(3) 2. All Tasks are Schedulable, with different Execution Times and different Deadlines. Here the tasks will have definite priorities. By priority we mean that tasks which have lower slack will be executed earlier than other tasks. A variety of cases can be achieved by varying the deadline and execution times which is illustrated through different test cases. By doing so tasks with various processor utilization are scheduled and the performance is compared between the two scheduling algorithms. 109

4 Test Case 1 Tasks Execution time (in seconds) Deadline (in seconds) Task1 2 4 Task2 2 6 Task Table 3: Test Case Parameter List 1. Static Scheduler: The tasks were scheduled based on the static priority assigned at the time of their creation. A low priority task executes only when all the higher priority tasks are in the wait list. For the first burst of execution (i.e. 18 seconds), Task3 starts at 3923ms but ends at 22560ms. But, the deadline of Task3 is 18000ms. Task3 has missed its deadline. Thus, it is observed that in case of a static scheduler the lower priority task is starved and hence misses deadline. 2. EDF Scheduler: The tasks were scheduled based on the execution time and their deadlines. The periodic task is pre-empted at moments where another task with lesser deadline arrives such that none of the tasks miss their deadlines. The tasks finish their execution and are inserted into a wait list until it wakes up again. The tasks which are pre-empted are rearranged in the ready queue such that a higher priority task is allowed to execute. Within the first burst of execution (i.e. 18 seconds), Task3 executes from 10142ms to 12000ms. Thus, Task3 meets its deadline of 18000ms.CPU utilization is 94.44%. Fig 6: Timeline For Test Case 1 of EDF Algorithm Fig 5: Screenshot of Serial Monitor Output of Static Scheduler 110 Fig 7: Screenshot of Serial Monitor Output of EDF Algorithm 3. LST Scheduler: The tasks were scheduled based on the slack times. The periodic task is pre-empted at moments where another task with lesser slack time arrives such that none of the tasks miss their deadlines.

5 The tasks finish their execution and are inserted into a wait list until it wakes up again. The tasks which are pre-empted are rearranged in the ready queue such that a higher priority task is allowed to execute. In cases where one of tasks finishes execution early another task maybe scheduled so as to guarantee highest possible utilization of the processor. Within the first burst of execution (i.e. 18 seconds), Task3 starts executing at 3975ms and is pre-empted at 4000ms. From 4000ms to 10000ms Task3 will be in the ready queue where its slack will keep decreasing with time. It is rescheduled at 10000ms when its slack becomes lesser than all other tasks. It completes execution at 11832ms. Thus, Task3 meets its deadline of 18000ms.CPU utilization is 94.44%. LST Test case 2: Tasks Execution time (in Seconds) Deadline (in Seconds) Task1 2 4 Fig 8: Timeline For Test Case 1 of LST Algorithm Task2 2 6 Task Table 4: Test Case2 for LST and its Parameters Fig 9: Screenshot of Serial Monitor Output For LST Algorithm 111

6 EDF which can be a huge plus point when large number of tasks are running. VI. CONCLUSION The dynamic scheduler that was developed is better compared to static scheduler. The same application that was successfully executed on dynamic scheduler fails in static scheduler. The starvation of tasks with later deadlines is reduced in LST as compared to EDF. Fig 10: Screenshot of Serial Monitor Output of LST Algorithm For Test Case 2 A second case was used to test LST with CPU Utilization of 99.9%. Within the first burst of execution (i.e. 18 seconds), Task3 starts executing at 10181ms and is pre-empted at 12000ms. From 12000ms to 16457ms Task3 will be in the ready queue where its slack will keep decreasing with time. It is rescheduled at 16457ms when its slack becomes lesser than all other tasks. It completes execution at 16465ms. Thus, Task3 meets its deadline of 18000ms.CPU utilization is 99.99%. V. PERFORMANCE EVALUATION The Dynamic Scheduler that we have developed is tested on TIVA TM4C123G board. Scheduler makes use of least slack time (LST) and earliest deadline first (EDF) algorithms. Scheduler is tested with an application involving three tasks having same execution times of 2 seconds and deadlines of 4, 6, 18 seconds. Each task comes back to the ready queue periodically. Scheduler making use of EDF algorithm assigns the priority depending on approach of deadlines of tasks. Deadlines of different tasks are compared at every instants and assigned priorities accordingly. Scheduler making use of LST algorithm assigns the priorities based on the slack times of tasks. Slack times of different tasks are compared at every instants. The task having least slack time is assigned highest priority. The static scheduler misses deadline. Both EDF and LST schedulers successfully meet deadlines of all tasks. LST performs slightly better than EDF. This is justified by comparing the waiting time taken by task 3 in LST and EDF. Task 3 has lesser waiting time in LST than in VII. REFERENCES [1] Wikipedia, Embedded System, Available at [2] [3] Raj Kamal, Embedded Systems Architecture Programming and Design, Second Edition, Tata McGraw Hill, 2008 [4] Least Slack Time Rate First: New Scheduling Algorithm for Multi-Processor Environment, CONFERENCE PAPER JANUARY 2010 [5] Design and Implementation of Deadline based EDF Algorithm on ARM LPC2148, Proceedings of 2013 IEEE Conference on Information and Communication Technologies (ICT 2013) [6] M. Kaladevi, S. Sathiyabama, A Comparative Study of Scheduling Algorithms for Real Time Task, International Journal of Advances in Science and Technology, Vol. 1, No. 4, [7] Giorio C. Buttazzo, Hard Real-Time Computing Systems: Predictable Scheduling Algorithms and Applications, Third Edition, Springer, [8] Philip A. Laplante, Real Time Systems Design and Analysis, Third Edition, Wiley India, 2005 [9] Jianxiong Xiao, Project Report of a Small Real Time Operating System USTOS [10] Implementing Scheduling Algorithms, Real- Time and Embedded Systems (M) Lecture 9, University of Glasgow [11] Introduction to Free-RTOS, Deepak D'Souza,Department of Computer Science and Automation Indian Institute of Science, Bangalore. [12] RTOS Tutorial, YouTube Lecture Series, Available at: A [13] FreeRTOS Task and Queues Tutorials by Millsinghion Available at: 112