Low-power-consumption real-time operating system adaptive to RISC-V discrete frequency hardware
By designing a low-power real-time operating system that is adapted to RISC-V discrete frequency hardware, using energy consumption decision modules and dynamic voltage frequency adjustment, the energy consumption optimization problem of RISC-V discrete frequency hardware is solved, and the energy saving effect and adaptability of the system are improved.
Patent Information
- Application Number
- CN202510486140.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-08-08
AI Technical Summary
Existing low-power solutions are difficult to adapt to RISC-V discrete frequency hardware, resulting in low energy consumption optimization efficiency, and most hardware uses high-frequency operation to cause energy waste.
A low-power real-time operating system adapted to RISC-V discrete frequency hardware is designed, including energy consumption decision module, task scheduling module, task ready module, task delay module and voltage frequency regulation module. By calculating the optimal frequency and dynamic voltage regulation, task execution and resource allocation are optimized.
It realizes the energy consumption optimization of RISC-V discrete frequency hardware, improves the energy saving effect of the system, enhances adaptability and scalability, and is adapted to domestic RISC-V architecture processors.
Smart Images

Figure CN120448058A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of operating systems, and in particular to a low-power real-time operating system adapted to RISC-V discrete frequency hardware. Background Art
[0002] Embedded systems, as the core carriers of industrial control and IoT terminals, have a direct impact on device endurance and reliability. With the widespread adoption of the RISC-V architecture, low-power technologies based on this architecture have become a hot topic in embedded system research. However, existing low-power solutions mostly use a continuous frequency modulation model, making them difficult to adapt to hardware that only supports discrete frequencies. This results in inefficient energy optimization on RISC-V hardware platforms.
[0003] Dynamic voltage and frequency scaling (DVFS) is a key technology for optimizing energy consumption in embedded systems. Low-power algorithms associated with DVFS rely on continuous-frequency hardware, but most hardware only supports discrete-frequency switching. This adaptability issue forces tasks to run at high frequencies to avoid timeouts, which wastes energy. Therefore, there is an urgent need to optimize energy consumption in RISC-V discrete-frequency hardware and find a low-power solution. Summary of the Invention
[0004] In view of the above problems, the present invention proposes a low-power real-time operating system adapted to RISC-V discrete frequency hardware to overcome the shortcomings of the existing technology.
[0005] An embodiment of the present invention provides a low-power real-time operating system adapted to RISC-V discrete frequency hardware, the low-power real-time operating system comprising: an energy consumption decision module, a task scheduling module, a task ready module, a task delay module, and a voltage and frequency adjustment module;
[0006] The energy consumption decision module is used to calculate the offline frequency and the second highest discrete frequency of the processor, allocate all idle time to each task in the task queue, and calculate the optimal frequency for the execution of the first task in the queue and send it to the voltage and frequency adjustment module;
[0007] The task scheduling module is used to input all idle time into the energy consumption decision module, and schedule the head task in the task ready module to the processor for execution, and reclaim its idle time resources after the task execution in the processor is completed, and place it in the task delay module to wait for the next cycle scheduling;
[0008] The task ready module is used to sort all tasks according to the strategy of shortest deadline first to form a task queue;
[0009] The task delay module is used to maintain each task that is dormant after completion;
[0010] The voltage and frequency adjustment module is used to adjust the frequency and voltage of the processor when executing the head-of-queue task according to the optimal frequency.
[0011] Optionally, the energy consumption decision module is used to calculate the offline frequency and the second highest discrete frequency of the processor before the head task is scheduled to the processor for execution, allocate all idle time to each task in the task queue, and calculate the optimal frequency for the execution of the head task and send it to the voltage and frequency adjustment module.
[0012] Optionally, the energy consumption decision module calculates the offline frequency and the second highest discrete frequency of the processor, allocates all idle time to each task in the task queue, and calculates the optimal frequency for executing the first task in the queue, including:
[0013] Calculating a theoretical offline frequency of a task set formed by all tasks in the task queue;
[0014] The operating frequency of the processor that is closest to and not less than the theoretical offline frequency is set as the offline frequency, and the operating frequency less than the offline frequency is set as the second highest discrete frequency;
[0015] When the low-power real-time operating system is started, the processor runs at an offline frequency.
[0016] Based on whether the task in the processor is preempted by a higher priority task during execution, determine whether to restore the offline frequency, reclaim its idle time resources after the task in the processor is completed, allocate all idle time to each task in the task queue, and calculate the optimal frequency for executing the first task in the queue.
[0017] Optionally, determining whether to restore the offline frequency according to whether a task in the processor is preempted by a higher priority task during execution includes:
[0018] If a task in the processor is preempted by a higher priority task during execution, the processor immediately saves the state of the current task and restores the offline frequency. The task ready module sets the higher priority task as the new head task and executes the higher priority task.
[0019] If the first task in the task queue is not preempted by a higher priority task during execution, the first task will be executed until the task is completed.
[0020] After the first task in the task queue is completed, its idle time is recovered and added to the task delay queue, and the optimal frequency of execution of each task is calculated.
[0021] Optionally, after the first task is completed, its idle time resources are reclaimed, all idle time is allocated to each task in the task queue, and the optimal frequency of executing the first task is calculated, including:
[0022] Traversing the task queue and calculating the greedy energy-saving frequency of each task;
[0023] If there is a target task whose greedy energy-saving frequency is not greater than the second highest discrete frequency, then the target time is allocated to the target task from all idle times, and all the remaining idle time is allocated to the head task in the task queue, wherein the target task is the task whose greedy energy-saving frequency is not greater than the second highest discrete frequency, the target time is the theoretical time of executing the target task at the second highest discrete frequency minus the remaining executable time of the target task, and the remaining idle time is the time remaining after deducting all the target times from all the idle times;
[0024] The optimal frequency for executing the head task is calculated according to the relationship between the greedy energy-saving frequency of the head task and the second highest discrete frequency, and the relationship between the greedy energy-saving frequency of the head task and the offline frequency.
[0025] Optionally, determining the optimal frequency for executing the head task of the queue according to a relationship between the greedy energy-saving frequency of the head task of the queue and the second highest discrete frequency, and a relationship between the greedy energy-saving frequency of the head task of the queue and the offline frequency includes:
[0026] If the greedy energy-saving frequency of the first task is not greater than the second highest discrete frequency, executing the first task at a discrete frequency that is closest to and not less than the greedy energy-saving frequency;
[0027] If the greedy energy-saving frequency of the first task in the queue is greater than the second highest discrete frequency, determining whether the greedy energy-saving frequency of the first task in the queue is equal to the offline frequency;
[0028] If the greedy energy-saving frequency of the first task is equal to the offline frequency, executing the first task at the offline frequency;
[0029] If the greedy energy-saving frequency of the first task is not equal to the offline frequency, the frequency of the two-stage frequency modulation is calculated, and the first task is executed with different frequencies in two stages.
[0030] Optionally, calculating the frequencies of the two-stage frequency modulation and performing the team-head task at different frequencies in the two stages includes:
[0031] Calculate the available run time of the first stage frequency modulation to the second highest discrete frequency, and set a timer with a timing duration equal to the available run time;
[0032] When the timer reaches zero, the second stage of frequency modulation is triggered, and the frequency is adjusted to the offline frequency for operation until the first task of the team is completed.
[0033] Optionally, calculating the greedy energy saving frequency of each task includes:
[0034] According to the worst execution time and remaining executable time of each task, the corresponding greedy energy-saving frequency is calculated.
[0035] Optionally, the task scheduling module is further configured to update the task attributes of any dormant task after the next cycle rescheduling is completed and re-add the task to the task queue in the task ready module.
[0036] Optionally, the low-power real-time operating system uses the embedded RISC-V processor with Kanzhi K210 as the core as the system hardware platform, and its development environment selects the Kanzhi development tool KendryteIDE and FreeRTOS real-time operating system.
[0037] The present invention proposes a low-power real-time operating system adapted to RISC-V discrete frequency hardware. It creatively proposes a low-power frequency modulation algorithm to construct a low-power real-time operating system adapted to RISC-V discrete frequency hardware. It also creatively proposes an energy consumption decision module that allocates all idle time to each task in the task queue and calculates the optimal frequency for executing the head task. The task scheduling module, unlike traditional methods that only schedule tasks, inputs all idle time into the energy consumption decision module, schedules the head task in the task ready module to the processor for execution, and reclaims the idle time resource after the task in the processor completes execution, placing it in the task delay module to await the next cycle scheduling.
[0038] The Task Readiness Module differs from traditional fixed-priority task queues by proposing a strategy that prioritizes all tasks by shortest deadline, forming a task queue. It also creatively proposes the control and modification of task attributes within the task queue—remaining executable time and idle time—a feature not found in traditional task queues. The Task Delay Module maintains each dormant task after completion. It also creatively proposes an Energy Consumption Decision Module, which allocates all idle time to each task in the task queue and calculates the optimal execution frequency for the head task, inputting this into the Voltage and Frequency Regulation Module. The Voltage and Frequency Regulation Module then adjusts the processor's frequency and voltage for each task according to the optimal frequency. Ultimately, this module achieves dynamic voltage and frequency regulation under task deadline constraints, solving the energy optimization problem of RISC-V discrete frequency hardware and improving the overall system's energy efficiency. Furthermore, the system's adaptability and scalability are enhanced by its compatibility with domestic RISC-V architecture processors, promising broad application prospects and high practicality. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Various other advantages and benefits will become apparent to those skilled in the art upon reading the detailed description of the preferred embodiment below. The accompanying drawings are for illustration purposes only and are not to be considered as limiting the present invention. The same reference symbols are used throughout the drawings to represent the same components. In the drawings:
[0040] Figure 1 This is a system structure diagram of a low-power real-time operating system adapted to RISC-V discrete frequency hardware proposed in an embodiment of the present application;
[0041] Figure 2 This is an overview flow chart of how a low-power real-time operating system achieves low power consumption in an embodiment of the present application. DETAILED DESCRIPTION
[0042] In order to make the above-mentioned objects, features and advantages of the present invention more clearly understood, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only intended to explain the present invention, are only part of the embodiments of the present invention, not all of the embodiments, and are not intended to limit the present invention.
[0043] The present invention proposes a low-power real-time operating system adapted to RISC-V discrete frequency hardware, referring to Figure 1 The system architecture shown in the figure includes an energy consumption decision module, a task scheduling module, a task readiness module, a task delay module, and a voltage and frequency regulation module. It should be noted that these modules are preferably integrated into the processor. However, it is also possible to integrate one or more of them into the processor, while the remaining modules interact with the processor in a non-integrated manner. Figure 1 The functional module is the module that executes each task and realizes the rest of the functions of the embedded system. The task set is the set of all tasks in the task queue of the task ready module.
[0044] The energy consumption decision module is used to calculate the offline frequency and the second highest discrete frequency of the processor, allocate all idle time to each task in the task queue, and calculate the optimal frequency for the execution of the first task in the queue and send it to the voltage and frequency regulation module; the task scheduling module is used to input all idle time into the energy consumption decision module, and schedule the first task in the task ready module to the processor for execution, and reclaim the idle time resources after the task execution in the processor is completed, and place it in the task delay module to wait for the next cycle scheduling.
[0045] The task ready module is used to sort all tasks according to the shortest deadline priority strategy to form a task queue; the task delay module is used to maintain each task in hibernation after completion; the voltage and frequency adjustment module is used to adjust the frequency and voltage of the processor when executing the first task in the queue according to the optimal frequency.
[0046] In one embodiment of the present invention, the energy consumption decision module is configured to calculate the processor's offline frequency and second-highest discrete frequency before the head-of-the-queue task is scheduled for execution, allocate all idle time to each task in the task queue, and calculate the optimal frequency for the head-of-the-queue task based on the idle time allocated to the head-of-the-queue task and send it to the processor. In other words, the optimal frequency is calculated before the task is executed by the processor.
[0047] In one embodiment of the present invention, the energy consumption decision module calculates the offline frequency and the second highest discrete frequency of the processor, allocates all idle time to each task in the task queue, and calculates the optimal frequency for executing the first task in the queue. The preferred method includes:
[0048] First, the theoretical offline frequency of the task set formed by all tasks in the task queue is calculated; then, the operating frequency of the processor that is closest to and not less than the theoretical offline frequency is set as the offline frequency, and the operating frequency less than the offline frequency is set as the second highest discrete frequency; finally, based on whether the task in the processor is preempted by a higher-priority task during execution, it is determined whether to restore the offline frequency, reclaim its idle time resources after the task in the processor is completed, allocate all idle time to each task in the task queue, and calculate the optimal frequency for executing the head task.
[0049] For example, if the processor's discrete frequencies are 2GHz, 2.5GHz, and 3GHz, and the calculated theoretical offline frequency is 2.8GHz, then the offline frequency is 3GHz, and the next highest discrete frequency is 2.5GHz. It is understandable that if the calculated offline frequency is 2.1GHz, then the offline frequency is 2.5GHz, and the next highest discrete frequency is 2GHz.
[0050] The above-mentioned processor is a RISC-V processor. The better choice is: Kanzhi K210 RISC-V architecture processor. This processor chip has the characteristics of low power consumption, high performance, and adjustable frequency, which can effectively meet the needs of low-power real-time operating systems.
[0051] In one embodiment of the present invention, the method for determining whether to restore the offline frequency according to whether a task in the processor is preempted by a higher priority task during execution includes:
[0052] If a task in the processor is preempted by a higher-priority task during execution, the processor immediately saves the state of the current head-of-the-line task, restores the offline frequency, and the task-ready module sets the higher-priority task as the new head-of-the-line task. The processor then switches to executing the preempted task (i.e., the higher-priority task). Of course, it is understandable that if a task in the processor is not preempted by a higher-priority task during execution, the current task will be executed until it is completed.
[0053] After the tasks in the processor are completed, their idle time is recovered and added to the task delay queue. The idle time resources are recovered, all idle time is allocated to each task in the task queue, and the optimal frequency of execution of the first task in the queue is calculated. An innovative method for allocating all idle time to each task in the task queue and calculating the optimal frequency of execution of the first task in the queue includes:
[0054] Traverse the task queue and calculate the greedy energy-saving frequency of each task; specifically, the corresponding greedy energy-saving frequency can be calculated based on the worst execution time and remaining executable time of each task.
[0055] If there is a target task whose greedy energy-saving frequency is no greater than the second-highest discrete frequency, the target time is allocated to the target task from all available idle time, and the remaining idle time is allocated to the first task in the task queue. The target task is the task whose greedy energy-saving frequency is no greater than the second-highest discrete frequency. The target time is the theoretical time required to execute the target task at the second-highest discrete frequency minus the remaining executable time. The remaining idle time is the remaining time after subtracting all target times from all available idle time. Suppose there are 10 tasks in the task queue, numbered 1 to 10. Of these, the greedy energy-saving frequencies of tasks 1 and 6 are no greater than the second-highest discrete frequency, while the greedy energy-saving frequencies of the remaining 8 tasks are all greater than the second-highest discrete frequency. Then, tasks 1 and 6 can be defined as the target tasks. From all available idle time, the theoretical time required to execute tasks 1 and 6 at the second-highest discrete frequency minus their respective remaining executable times is allocated to tasks 1 and 6, respectively, and the remaining idle time is allocated to the first task in the task queue, task 1. It can be understood that if the task with sequence number 2 is defined as the target task, then the theoretical time of executing the task with sequence number 2 at the second highest discrete frequency minus its remaining executable time is allocated to the task with sequence number 2 from all the idle time, and then all the remaining idle time is allocated to the task with sequence number 1.
[0056] After the above time allocation is completed, the frequency of executing the first task in the queue is determined based on the relationship between the greedy energy-saving frequency of the first task in the queue and the second highest discrete frequency, as well as the relationship between the greedy energy-saving frequency of the first task in the queue and the offline frequency. A better method for determining the frequency of executing the first task in the queue includes:
[0057] If the greedy energy-saving frequency of the team leader task is not greater than the second highest discrete frequency, the team leader task is executed at the discrete frequency that is closest to and not less than the greedy energy-saving frequency; if the greedy energy-saving frequency of the team leader task is greater than the second highest discrete frequency, it is necessary to further determine whether the greedy energy-saving frequency of the team leader task is equal to the offline frequency.
[0058] If the greedy energy-saving frequency of the first task in the queue is equal to the offline frequency, the first task in the queue is executed at the offline frequency. In this case, there is actually not enough idle time for two-stage frequency adjustment, that is, there is no idle time for frequency reduction. At this time, the offline frequency is directly restored and the first task in the queue is executed at the offline frequency.
[0059] If the greedy energy-saving frequency of the first task is not equal to the offline frequency, the frequency of the two-stage frequency modulation is calculated, and the first task is executed at two different frequencies. The specific method of executing the first task at two different frequencies includes:
[0060] Calculate the runnable time of the first-stage frequency modulation to the second-highest discrete frequency, and set a timer with a timing duration equal to the aforementioned runnable time; when the timer reaches zero, trigger the second-stage frequency modulation, and adjust the current second-highest discrete frequency to the offline frequency until the first task in the team is completed.
[0061] When the processor executes a task, the voltage and frequency adjustment module adjusts the frequency and voltage of the processor to execute each task according to the optimal frequency. Preferably, the processor is encapsulated with a voltage and frequency control interface, through which the corresponding frequency is adjusted to execute the task.
[0062] After a task in the processor is completed, the task scheduling module reclaims its idle time resources and re-includes them in all idle time. It also sends the completed task to the task delay module, which waits for the next cycle to be triggered before rescheduling it to the task queue of the task ready module for execution, thus completing a closed-loop energy-saving scheduling process. The task scheduling module is also used to update the task attributes of any dormant task after rescheduling it in the next cycle and re-add it to the task queue of the task ready module.
[0063] In order to better understand the above content, let's take a specific example to illustrate:
[0064] Assume the processor's discrete frequencies are {1 GHz, 1.5 GHz, 2 GHz, 4 GHz}. The remaining executable time after a task completes is the reclaimed idle time resource. The task set consists of Task 1 (the first task in the queue) and Task 2.
[0065] When initializing the task, the worst execution time of Task 1 is 2 time units, the remaining executable time is 2 time units (before each task is executed, the remaining executable time is reinitialized and equal to the worst execution time, because the remaining executable time will gradually decrease during the task execution), and the task period is 4 time units.
[0066] Assume that the worst execution time of task 2 is 1 unit time, the remaining executable time is 1 unit time, and the task period is 10.
[0067] When the low-power real-time operating system starts, the theoretical offline frequency is calculated: this is equal to the worst-case execution time of each task divided by the sum of the task periods, multiplied by the maximum frequency (4 GHz), ((2 / 4 + 1 / 10) * 4 GHz = 2.4 GHz). The processor frequency closest to but not less than the theoretical offline frequency is used as the offline frequency, that is, 4 GHz. The next highest discrete frequency is 2 GHz.
[0068] Task 1 begins execution (Task 1's deadline is 4, Task 2's deadline is 10, Task 1 executes first, and its deadline is equal to the duration of the task cycle * (number of executions + 1)). It was originally scheduled to execute at 4 GHz. In the worst case, it would take 2 units of time to execute, but it actually executed 1 unit of time. The remaining executable time upon completion is 1 unit of time, and the reclaimed idle time is (remaining executable time upon completion = 1 unit of idle time). Task 1 is added to the task delay queue, and Task 2 is set as the new head of the queue. Before being scheduled onto the processor, all idle time is allocated to each task in the task queue, and the optimal frequency for executing the head task (i.e., Task 2) is calculated.
[0069] All idle time is allocated to each task in the task queue, and Task 2 receives 1 unit of idle time. (During the traversal, the theoretical time required to execute Task 2 at the next highest discrete frequency minus the target task's remaining executable time is calculated: the theoretical time required to execute Task 2 at the next highest discrete frequency = 2 units of time, the time minus the target task's remaining executable time = 2 units of time - 1 unit of time = 1 unit of time, resulting in 0 remaining idle time.) The remaining executable time plus the allocated idle time equals the new remaining executable time, which is 2 units of idle time. The greedy power-saving frequency is 2 GHz. Since the greedy power-saving frequency is not greater than the next highest discrete frequency, the first task in the queue (Task 2 is currently the first task in the queue) is executed at the discrete frequency closest to, but not less than, the greedy power-saving frequency (2 GHz).
[0070] If preemption occurs during execution, the higher-priority task (the preempting task) is set as the head of the queue and is scheduled to execute on the processor. The task in the original processor waits for the preempted task to complete before continuing to execute.
[0071] To sum up, the energy consumption decision module of the present invention integrates a low-power frequency modulation algorithm, allocates all idle time to each task in the task queue, and determines the optimal frequency for executing the first task in the queue through the above method. For tasks that can perform two-stage frequency modulation, two-stage frequency modulation is used to execute them. Through the voltage and frequency adjustment module, the task starts to run at a low frequency to reduce energy consumption, and then switches to a discrete frequency when the task is executed, maximizing the use of system idle time to improve energy saving effects.
[0072] The voltage and frequency regulation module uses the voltage and frequency control interface provided by the processor to achieve millisecond-level processor voltage and frequency switching, and ensure the stability of the low-power real-time operating system during the switching process. The task scheduling module, as the task scheduler of the low-power real-time operating system, maintains the task queue in the task ready module and the dormant tasks in the task delay module, inputs all idle time into the energy consumption decision module, and schedules the first task in the queue (i.e., the task with the shortest deadline) to the processor for execution according to the scheduling strategy of prioritizing the task with the shortest deadline. After the task in the processor is completed, the idle time resources are recovered and placed in the task delay module to await the next cycle scheduling, thus achieving energy efficiency balance while ensuring the real-time performance of the low-power real-time operating system.
[0073] The Task Ready module maintains ready periodic tasks, sorting them by their earliest deadlines, with the earliest deadlines prioritized. The Task Delay module maintains dormant periodic tasks, setting timers for each of the best tasks to periodically wake them up. Once a timer is triggered, the Task Scheduling module immediately moves dormant tasks to the Task Ready module's task queue, ensuring real-time performance.
[0074] The low-power real-time operating system adapted to RISC-V discrete frequency hardware proposed in the present invention can preferably use the embedded RISC-V processor with Kanzhi K210 as the core as the system hardware platform, and its software platform design can preferably use the RISC-V development board and related development tools for software design and development. If the development environment is better, you can choose the Kanzhi development tool KendryteIDE and the FreeRTOS real-time operating system. Implement the energy consumption decision module, voltage and frequency adjustment module, task scheduling module (also called FreeRTOS task scheduling module), task ready module and task delay module on the Kanzhi K210 RISC-V development board. Its implementation logic is combined Figure 2 The overview flow chart shown can be summarized as:
[0075] First, a task set is created through the Task Ready module. After this, the task queue in the Task Ready module needs to be initialized. A periodic task set is created, and all tasks are queued by shortest deadline. The low-power real-time operating system (RTOS) starts running at the offline frequency to ensure that tasks meet real-time constraints.
[0076] Next, regarding task execution and preemption: If a task in a processor is preempted by a higher-priority task, the processor immediately saves its current state and restores its offline frequency. The task scheduling module schedules the preempted task to the processor, which then executes it. If the task in the processor is not preempted, the task in the processor continues to execute until it completes. After the task in the processor completes, it is added to the task delay module and its idle time is reclaimed.
[0077] After the above process is completed, the optimal frequency of the first task in the queue is dynamically allocated and calculated according to all idle time: when the low-power real-time operating system has idle time and the task queue is not empty, it is determined to traverse the task queue and check whether the traversal is completed. The traversal of the task queue is essentially to allocate the corresponding idle time so that the task can meet the requirements of running the task at the second highest discrete frequency, that is, Figure 2 Is there enough idle time for the traversed task to run at the second highest discrete frequency? If so, allocate enough idle time for the task to run at the second highest discrete frequency. If not, return to the process of "Traversing the Task Queue, Is the Traversal Complete?"
[0078] After the allocation, all the remaining idle time will be allocated to the team leader task, and it will be determined whether the greedy energy-saving frequency of the team leader task is greater than the second highest discrete frequency. If it is not greater than the second highest discrete frequency, it will be run at the discrete frequency that is closest to and not less than the greedy energy-saving frequency; if the greedy energy-saving frequency of the team leader task is greater than the second highest discrete frequency, it will be determined whether the greedy energy-saving frequency of the team leader task is equal to the offline frequency.
[0079] If the greedy energy-saving frequency of the first task in the queue is equal to the offline frequency, there is no idle time for frequency reduction (that is, two-stage frequency modulation cannot be performed), and the offline frequency operation is restored; if the greedy energy-saving frequency of the first task in the queue is not equal to the offline frequency, two-stage frequency modulation is performed, and a timer is set to restore the offline frequency operation in the middle of the execution until the first task in the queue is completed.
[0080] In summary, the present invention proposes a low-power real-time operating system adapted to RISC-V discrete frequency hardware, creatively proposes a low-power frequency modulation algorithm, and constructs a low-power real-time operating system adapted to RISC-V discrete frequency hardware. A creative energy consumption decision module is proposed, which can allocate all idle time to each task in the task queue and calculate the optimal frequency for executing the head task. The task scheduling module is different from the traditional function of only scheduling tasks. Instead, it inputs all idle time into the energy consumption decision module, schedules the head task in the task ready module to the processor for execution, and reclaims the idle time resources after the task execution in the processor is completed, placing them in the task delay module to wait for the next cycle scheduling.
[0081] The Task Readiness Module differs from traditional fixed-priority task queues by proposing a strategy that prioritizes all tasks by shortest deadline, forming a task queue. It also creatively implements control and modification of task attributes within the task queue—remaining executable time and idle time—a feature not found in traditional task queues. The Task Delay Module maintains each dormant task after completion. It also creatively proposes an Energy Consumption Decision Module, which allocates all idle time to each task in the task queue and calculates the optimal frequency for the head task to execute. This frequency is then fed into the Voltage and Frequency Regulator module, which then adjusts the processor's frequency and voltage to the optimal frequency for executing the head task. This ultimately achieves dynamic voltage and frequency regulation under task deadline constraints, solving the energy optimization problem of RISC-V discrete-frequency hardware and improving the overall system's energy efficiency. Furthermore, the system's adaptability and scalability are enhanced by its compatibility with domestic RISC-V architecture processors, promising broad application prospects and high practicality.
[0082] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic creative concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0083] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.
[0084] The embodiments of the present invention are described above in conjunction with the accompanying drawings, but the present invention is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present invention, ordinary technicians in this field can also make many forms without departing from the scope of protection of the present invention and the claims, all of which are protected by the present invention.
Claims
1. A low-power real-time operating system adapted to RISC-V discrete frequency hardware, characterized in that: The low-power real-time operating system includes: an energy consumption decision module, a task scheduling module, a task ready module, a task delay module and a voltage and frequency adjustment module; The energy consumption decision module is used to calculate the offline frequency and the second highest discrete frequency of the processor, allocate all idle time to each task in the task queue, and calculate the optimal frequency for the execution of the first task in the queue and send it to the voltage and frequency adjustment module; The task scheduling module is used to input all idle time into the energy consumption decision module, and schedule the head task in the task ready module to the processor for execution, and reclaim its idle time resources after the task in the processor is completed, and place it in the task delay module to wait for the next cycle scheduling; The task ready module is used to sort all tasks according to the strategy of shortest deadline first to form a task queue; The task delay module is used to maintain each task that is dormant after completion; The voltage and frequency adjustment module is used to adjust the frequency and voltage of the processor when executing a task according to the optimal frequency.
2. The low-power real-time operating system according to claim 1, characterized in that: The energy consumption decision module is used to calculate the offline frequency and the second highest discrete frequency of the processor before the first task in the queue is scheduled to the processor for execution, allocate all idle time to each task in the task queue, and calculate the optimal frequency for executing the first task in the queue and send it to the voltage and frequency adjustment module.
3. The low-power real-time operating system according to claim 1, characterized in that: The energy consumption decision module calculates the offline frequency and the second highest discrete frequency of the processor, allocates all idle time to each task in the task queue, and calculates the optimal frequency for executing the first task in the queue. The method includes: Calculating a theoretical offline frequency of a task set formed by all tasks in the task queue; The operating frequency of the processor that is closest to and not less than the theoretical offline frequency is set as the offline frequency, and the operating frequency less than the offline frequency is set as the second highest discrete frequency; When the low-power real-time operating system is started, the processor runs at an offline frequency. Based on whether the task in the processor is preempted by a higher priority task during execution, determine whether to restore the offline frequency, reclaim its idle time resources after the task in the processor is completed, allocate all idle time to each task in the task queue, and calculate the optimal frequency for executing the first task in the queue.
4. The low-power real-time operating system according to claim 3, characterized in that: Determining whether to restore the offline frequency according to whether a task in the processor is preempted by a higher priority task during execution includes: If a task in the processor is preempted by a higher priority task during execution, the processor immediately saves the state of the current task and restores the offline frequency. The task ready module sets the higher priority task as the new head task in the queue, and the task scheduling module schedules it to the processor for execution. If the task in the processor is not preempted by a higher priority task during execution, the task is executed until completion.
5. The low-power real-time operating system according to claim 3, characterized in that: After the tasks in the processor are completed, its idle time resources are reclaimed, all idle time is allocated to each task in the task queue, and the optimal frequency of executing the first task in the queue is calculated, including: Traversing the task queue and calculating the greedy energy saving frequency of each task; If there is a target task whose greedy energy-saving frequency is not greater than the second highest discrete frequency, then the target time is allocated to the target task from all idle times, and all the remaining idle time is allocated to the head task in the task queue, wherein the target task is the task whose greedy energy-saving frequency is not greater than the second highest discrete frequency, the target time is the theoretical time of executing the target task at the second highest discrete frequency minus the remaining executable time of the target task, and the remaining idle time is the time remaining after deducting all the target times from all the idle times; The optimal frequency for executing the head task is calculated according to the relationship between the greedy energy-saving frequency of the head task and the second highest discrete frequency, and the relationship between the greedy energy-saving frequency of the head task and the offline frequency.
6. The low-power real-time operating system according to claim 5, characterized in that: Calculating the optimal frequency for executing the head task of the queue according to the relationship between the greedy energy-saving frequency of the head task of the queue and the second highest discrete frequency, and the relationship between the greedy energy-saving frequency of the head task of the queue and the offline frequency, including: If the greedy energy-saving frequency of the first task is not greater than the second highest discrete frequency, executing the first task at a discrete frequency that is closest to and not less than the greedy energy-saving frequency; If the greedy energy-saving frequency of the first task in the queue is greater than the second highest discrete frequency, determining whether the greedy energy-saving frequency of the first task in the queue is equal to the offline frequency; If the greedy energy-saving frequency of the first task is equal to the offline frequency, executing the first task at the offline frequency; If the greedy energy-saving frequency of the first task is not equal to the offline frequency, the frequency of the two-stage frequency modulation is calculated, and the first task is executed with different frequencies in two stages.
7. The low-power real-time operating system according to claim 6, characterized in that: Calculating the frequencies of the two-stage frequency modulation and executing the team-leading task at the two-stage different frequencies includes: Calculate the available run time of the first stage frequency modulation to the second highest discrete frequency, and set a timer with a timing duration equal to the available run time; When the timer reaches zero, the second stage of frequency modulation is triggered, and the frequency is adjusted to the offline frequency for operation until the first task of the team is completed.
8. The low-power real-time operating system according to claim 5, characterized in that: Calculating the greedy energy-saving frequency of each task includes: According to the worst execution time and remaining executable time of each task, the corresponding greedy energy-saving frequency is calculated.
9. The low-power real-time operating system according to claim 1, characterized in that: The task scheduling module is further configured to update the task attributes of any dormant task after the next cycle rescheduling is completed and re-add the task to the task queue in the task ready module.
10. The low-power real-time operating system according to claim 1, characterized in that: The low-power real-time operating system uses the embedded RISC-V processor with Kanzhi K210 as the core as the system hardware platform, and its development environment selects the Kanzhi development tool KendryteIDE and FreeRTOS real-time operating system.