The Electronic Components Supply Chain Partner

Product Catalog Contact Us

More Discounts

What is Round-Robin Scheduling? Basic Principles of the Round-Robin Scheduling Algorithm

Release Time: Apr 23, 2024

A microcontroller unit (MCU) serves as the CPU in a system, handling multiple tasks simultaneously, such as communicating with a PC, forwarding received information to a slave device, and monitoring data processing, among other complex and essential tasks. To coordinate these tasks and ensure they are executed smoothly, a suitable algorithm must be used during programming.

General Methodology

Typically, an operating system is ported to the MCU to manage these tasks. However, due to the limited resources of MCUs, this approach is often impractical. Therefore, instead of using an operating system, the round-robin scheduling method is commonly employed to manage tasks in MCUs.

Concept of Time Slices

A time slice, simply put, is the amount of time allocated by the CPU to each program, giving the appearance that multiple programs are running simultaneously without wasting CPU resources.

Macro Perspective: Multiple applications can be opened simultaneously, each running in parallel without interference.

Micro Perspective: Since there is only one CPU, it can handle only a portion of each program's requirements at a time. To manage this fairly, time slices are introduced, allowing each program to run in turns.

Round-Robin Scheduling Algorithm

Round-robin scheduling is an old and simple algorithm widely used in microprocessors without an operating system. In this system, each process is allocated a time slice, which is the period during which the process is allowed to run.

If the process is still running when the time slice ends, the CPU is taken away from it and allocated to another process. If the process blocks or ends before the time slice finishes, the CPU switches immediately. The scheduler maintains a list of ready processes, and when a process exhausts its time slice, it is moved to the end of the queue.

Determining the Length of a Time Slice

One interesting aspect of round-robin scheduling is determining the length of the time slice. Switching from one process to another requires some time, known as context switching time, during which the system saves and loads register values, memory images, and updates various tables and queues. For instance, if a context switch takes 5 milliseconds and the time slice is set to 20 milliseconds, after performing 20 milliseconds of useful work, the CPU will spend 5 milliseconds switching processes, wasting 20% of CPU time on overhead.

If the time slice length is set too short, this overhead becomes more pronounced, reducing CPU utilization efficiency. Therefore, a balance must be struck between the time slice length and CPU utilization.

To improve CPU efficiency, the time slice length can be set longer, reducing the relative time wasted on switching. However, in a time-sharing system, different tasks have varying requirements for time slice lengths. For example, some tasks might need updates every second, while others might need to scan for key presses every few tens of milliseconds or check serial port buffers every few milliseconds. If the time slice is too long, real-time tasks might not get executed promptly, degrading the system's real-time performance.

aa

 

Basic Principle of Round-Robin Scheduling Algorithm

In early round-robin scheduling, all ready processes were queued in a first-come, first-served order. During each scheduling, the CPU is allocated to the process at the head of the queue, allowing it to execute for one time slice.

The size of the time slice ranges from a few milliseconds to a few hundred milliseconds. When the time slice expires, a timer triggers a clock interrupt request, prompting the scheduler to stop the current process and move it to the end of the ready queue. The CPU is then allocated to the next process at the head of the queue, allowing it to execute for one time slice. This ensures that all ready processes get a time slice of CPU execution time within a given period.

Differences Between Time Slice Round-Robin and Time Scheduling in MCUs

Time Slice Round-Robin:

  • Fairness: Ensures each task gets an equal opportunity to execute by rotating the CPU among tasks in fixed time slices.
  • Simplicity: Easy to implement, especially suitable for systems without complex task dependencies or varying priorities.
  • Overhead: Involves some overhead due to context switching, which needs to be minimized by appropriately setting the time slice length.
  • Real-Time Performance: May not be suitable for tasks with stringent real-time requirements, as the fixed time slices might not align with the needs of high-priority or time-sensitive tasks.

Time Scheduling:

  • Flexibility: Can utilize various algorithms and strategies, such as priority-based scheduling, deadline scheduling, or rate-monotonic scheduling, to manage tasks based on their specific requirements.
  • Optimization: Focuses on optimizing system performance, including response time, resource utilization, and task completion rates.
  • Complexity: More complex to implement due to the need to consider multiple factors like task priorities, resource availability, and inter-task dependencies.
  • Real-Time Performance: Better suited for real-time systems where certain tasks must meet strict timing constraints, ensuring timely execution of critical tasks.

Summary

In microcontroller-based systems, managing multiple tasks efficiently is crucial. While porting a full-fledged operating system might not be feasible due to resource constraints, the round-robin scheduling algorithm offers a simple and effective way to ensure that all tasks get CPU time. By dividing CPU time into fixed time slices and rotating through tasks, round-robin scheduling provides a fair and straightforward approach to task management.

However, when higher efficiency or real-time performance is required, more sophisticated time scheduling methods may be necessary. These methods can take into account the specific needs of each task, optimizing overall system performance and ensuring that critical tasks are executed promptly.

By understanding the principles of round-robin scheduling and time scheduling, engineers can choose the appropriate method for their specific application, balancing simplicity, fairness, and performance to meet their system's needs.

Parts Purchasing

Maybe you need to purchase certain parts

Get the latest news
ADUM242E0WBRWZ

ADUM242E0WBRWZ

High-reliability isolation solution for precision electronics

ADUM242E0WBRWZ-RL

ADUM242E0WBRWZ-RL

Reliable digital isolators for secure circuit protection

LTM9013CY-AA#PBF

LTM9013CY-AA#PBF

Fast and accurate data acquisition for test and measurement equipment

ADUM3474ARSZ

ADUM3474ARSZ

Ensure secure signal transmission and precise control with our ADUM3474ARSZ digital isolator's fast switching times and low noise operation