RTS Compiled Notes UNIT 2
RTS Compiled Notes UNIT 2
1. Periodic Tasks:
• Real-time systems often involve tasks that need to be executed at regular
intervals.
• Each task is associated with a specific period, representing the time between
consecutive executions.
2. Clock Interrupts:
• The system's clock generates interrupts at regular intervals.
• These clock interrupts serve as triggers for the initiation of scheduled tasks.
3. Task Scheduling:
• Tasks are scheduled to run at specific points in time, aligned with the clock
interrupts.
• The scheduling algorithm determines the order and timing of task execution
based on their priorities and deadlines.
4. Time-Driven Behavior:
• The system operates in a time-driven manner, where tasks are initiated or
terminated based on the clock signal.
• This approach allows for predictable and deterministic behavior in meeting
timing requirements.
5. Advantages:
• Predictability: The periodic nature of tasks and the regular clock interrupts
contribute to predictable system behavior.
• Control: The clock-driven approach provides control over the timing and
execution of tasks.
6. Disadvantages:
• May not handle dynamic or unpredictable events well.
• Limited flexibility in handling varying workloads or changing task priorities.
7. Examples:
• In embedded systems, tasks like sensor reading, control loops, or
communication processes may be scheduled using a clock-driven approach.
• Real-time operating systems (RTOS) often use clock-driven scheduling to
ensure timely execution of tasks.
PRIORITY-DRIVEN SCHEDULING
Priority-driven scheduling is a type of scheduling algorithm where tasks are executed based on
their priority levels. Tasks with higher priority levels are executed before tasks with lower
priority levels. This ensures that higher-priority tasks are completed in a timely manner,
potentially at the expense of lower-priority tasks. Here's an example to illustrate priority-driven
scheduling:
Let's consider a simplified example where we have four tasks to be scheduled:
1. Task A with priority 1
2. Task B with priority 2
3. Task C with priority 3
4. Task D with priority 1
In this scenario, the higher the priority number, the lower the priority of the task. Therefore,
Task C has the highest priority, followed by Task B, then Task A, and finally Task D.
Now, let's assume each task has a certain execution time:
• Task A requires 5 units of time.
• Task B requires 3 units of time.
• Task C requires 2 units of time.
• Task D requires 4 units of time.
Using a priority-driven scheduling algorithm, tasks will be executed based on their priority
levels. The scheduler will select the task with the highest priority that is ready to execute.
Here's how the scheduling might proceed:
1. Since Task C has the highest priority, it will be executed first. Task C completes in 2
units of time.
2. Next, Task B will be executed as it has the next highest priority. Task B completes in 3
units of time.
3. Task A cannot be executed until both Task C and Task B are completed because they
have higher priorities. Task A completes in 5 units of time.
4. Finally, Task D is executed, as it has the lowest priority among the tasks. Task D
completes in 4 units of time.
Time: 0 1 2 3 4 5 6 7 8 9 10
Task: C C B B B A A A A A D
1. Offline Scheduling:
• In offline scheduling, the entire set of tasks and their characteristics (such as
execution times, deadlines, etc.) are known in advance before scheduling
begins.
• The scheduler can analyze the tasks and optimize the scheduling based on
various criteria such as minimizing the makespan (total completion time),
minimizing the maximum lateness, or maximizing resource utilization.
• Offline scheduling algorithms can be computationally intensive since they often
involve searching for an optimal or near-optimal solution among all possible
schedules.
• Examples of offline scheduling algorithms include Optimal Scheduling, List
Scheduling, and Genetic Algorithms.
2. Online Scheduling:
• In online scheduling, tasks arrive dynamically during execution, and the
scheduler makes decisions without knowing the characteristics of future tasks.
• The scheduler must make decisions based only on the information available at
the time of task arrival or execution.
• Online scheduling algorithms must be efficient and make decisions quickly
since they do not have the luxury of analyzing all future tasks.
• These algorithms often use heuristics or approximation techniques to make
decisions quickly.
• Examples of online scheduling algorithms include First Come First Serve
(FCFS), Shortest Job Next (SJN), and Round Robin.
Comparison:
1. Complexity:
• Offline scheduling algorithms can be more complex since they have access to
complete information about tasks in advance and can optimize based on various
criteria.
• Online scheduling algorithms tend to be simpler and more lightweight since
they must make decisions quickly based on partial information.
2. Performance:
• Offline scheduling algorithms can potentially achieve better performance since
they can optimize schedules based on complete information.
• Online scheduling algorithms may not always produce optimal solutions but are
designed to make reasonable decisions quickly based on available information.
3. Resource Utilization:
• Offline scheduling algorithms can consider future resource utilization more
effectively since they have information about all tasks.
• Online scheduling algorithms must balance resource utilization based on current
information, which may lead to suboptimal resource allocation in some cases.
4. Real-time Systems:
• Online scheduling is more common in real-time systems where tasks arrive
dynamically and must be scheduled quickly to meet deadlines.
• Offline scheduling may be more suitable for batch processing or situations
where tasks are known in advance and can be optimized before execution
begins.
The Least Slack Time (LST) scheduling algorithm is another approach used in real-time
systems to schedule tasks with deadlines. It aims to minimize the slack time of tasks, where
slack time refers to the time remaining until a task's deadline after its execution.
Here's how the LST scheduling algorithm works:
1. Task Arrival: When a new task arrives or becomes ready to execute, its deadline and
computation time are noted.
2. Calculate Slack Time: For each task in the ready queue, calculate its slack time. Slack
time is the difference between the task's deadline and the current time minus the task's
computation time. In other words, it represents how much time is left before the task's
deadline after considering its execution time.
3. Task Selection: Select the task with the least slack time for execution. This means that
tasks with tighter deadlines or less time remaining until their deadlines are given higher
priority.
4. Task Execution: Execute the selected task. If multiple tasks have the same slack time,
additional criteria like priority or arrival time can be used to break ties.
5. Task Completion: After executing a task, update the list of ready tasks if new tasks
have arrived or if the execution time of existing tasks has changed.
6. Repeat: Steps 2 to 5 are repeated as tasks arrive, execute, and complete.
The LST algorithm aims to minimize the likelihood of missing deadlines by prioritizing tasks
that have less time remaining until their deadlines. However, like any scheduling algorithm, it
has its limitations and may not be suitable for all scenarios. Careful analysis of task
characteristics, system requirements, and constraints is necessary to determine whether LST
scheduling is appropriate for a given real-time system.