Method and device for creating real-time operating system task, electronic equipment and medium
By supporting task creation with multiple scheduling methods in a real-time operating system, the problem of only being able to use a single scheduling method in existing technologies is solved, enabling more flexible CPU resource allocation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-01
- Publication Date
- 2026-03-31
AI Technical Summary
Existing real-time operating systems can only use one task scheduling method and cannot simultaneously accommodate preemptive and round-robin scheduling, resulting in inflexible CPU resource allocation.
When creating a real-time task, the scheduling method to be used for the task is determined in advance, supporting both preemptive and time-slice round-robin scheduling methods. Flexible task creation is achieved through the determination module and the task creation module.
It enables both preemptive and round-robin scheduling in a real-time operating system, providing a more flexible way to allocate CPU resources.
Smart Images

Figure CN121764598A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of real-time operating system technology, and in particular to a method and apparatus for creating real-time operating system tasks, electronic devices, and storage media. Background Technology
[0002] In real-time operating systems, real-time task scheduling is a crucial component. The quality and efficiency of task scheduling algorithms directly affect the application scope and real-time performance of the real-time operating system kernel.
[0003] Currently, there are two scheduling methods for real-time tasks. One is preemptive scheduling, where a high-priority task preempts a low-priority task, and the low-priority task cannot obtain executable CPU resources unless the high-priority task actively relinquishes the CPU. The other is scheduling based on the proportion of running time, where a high-priority task can obtain more running time, but when the running time ends, it still has to relinquish the CPU resources so that the operating system can schedule other tasks to run.
[0004] In the process of implementing the embodiments of this disclosure, at least the following problems were found in the related art:
[0005] Based on the inherent real-time task scheduling methods of current operating systems, neither of the two scheduling methods mentioned above can exist simultaneously within an operating system. Real-time tasks created in an operating system can only be executed using one of these two methods; there is no option to selectively employ preemptive or time-proportional scheduling. Summary of the Invention
[0006] To provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not intended as a general commentary, nor is it intended to identify key / important components or describe the scope of protection of these embodiments, but rather as a prelude to the detailed description that follows.
[0007] This disclosure provides a method, apparatus, electronic device, and storage medium for creating real-time operating system tasks, to solve the technical problem of how to make real-time tasks compatible with both preemptive scheduling and round-robin scheduling in a real-time operating system.
[0008] In some embodiments, the method includes: determining a real-time task scheduling mode; the real-time task scheduling mode is any one of the task scheduling modes supported by the real-time operating system; creating a task according to the real-time task scheduling mode to obtain a real-time task that supports the task scheduling mode.
[0009] In some embodiments, the apparatus includes: a determining module configured to determine a real-time task scheduling mode; wherein the real-time task scheduling mode is any one of the task scheduling modes supported by the real-time operating system; and a task creation module configured to create a task according to the real-time task scheduling mode, thereby obtaining a real-time task that supports the task scheduling mode.
[0010] In some embodiments, the electronic device includes a processor and a memory storing program instructions, wherein the processor is configured to, when executing the program instructions, perform a method for creating a real-time operating system task as described above.
[0011] In some embodiments, the storage medium stores program instructions that are executed by a processor to implement the method of creating a real-time operating system task as described above.
[0012] The method, apparatus, electronic device, and storage medium for creating real-time operating system tasks provided in this disclosure can achieve the following technical effects:
[0013] This invention predetermines the real-time task scheduling mode to be used when creating a real-time task, thereby enabling both preemptive and time-slice round-robin real-time task scheduling modes to coexist in the real-time operating system. This provides a more flexible task creation method and achieves better allocation of CPU resources.
[0014] The above general description and the description below are exemplary and illustrative only and are not intended to limit this application. Attached Figure Description
[0015] One or more embodiments are illustrated by way of example with reference to the accompanying drawings. These illustrations and drawings do not constitute a limitation on the embodiments. Elements having the same reference numerals in the drawings are shown as similar elements. The drawings are not to be scaled. And wherein:
[0016] Figure 1 This is a schematic diagram of a method for creating a real-time operating system task provided in an embodiment of this disclosure.
[0017] Figure 2 This is a schematic diagram of an apparatus for creating a real-time operating system task provided in an embodiment of this disclosure;
[0018] Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0019] To provide a more detailed understanding of the features and technical content of the embodiments of this disclosure, the implementation of the embodiments of this disclosure will be described in detail below with reference to the accompanying drawings. The accompanying drawings are for illustrative purposes only and are not intended to limit the embodiments of this disclosure. In the following technical description, for ease of explanation, several details are used to provide a full understanding of the disclosed embodiments. However, one or more embodiments may still be implemented without these details. In other cases, well-known structures and devices may be simplified in their depiction to simplify the drawings.
[0020] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this disclosure described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. The term "corresponding" can refer to an association or binding relationship; A corresponding to B means that there is an association or binding relationship between A and B.
[0021] Unless otherwise stated, the term "multiple" means two or more.
[0022] The method for creating real-time operating system tasks provided in this disclosure is applied to electronic devices.
[0023] In some embodiments, the electronic device is an embedded device, and a real-time operating system that supports multiple different task scheduling methods is installed on the electronic device.
[0024] Combination Figure 1 As shown, this disclosure provides a method for creating a real-time operating system task, including:
[0025] S101, the electronic device determines the real-time task scheduling mode; the real-time task scheduling mode is any one of the task scheduling modes supported by the real-time operating system.
[0026] S102, the electronic device creates a task according to the real-time task scheduling method and obtains a real-time task that supports the task scheduling method.
[0027] The method for creating real-time operating system tasks provided in this disclosure predetermines the real-time task scheduling mode to be used when creating the task, thereby enabling both preemptive and time-slice round-robin real-time task scheduling modes to coexist in the real-time operating system, providing a more flexible task creation method and achieving better allocation of CPU resources.
[0028] In one embodiment, the real-time operating system supports multiple task scheduling methods, including preemptive scheduling and round-robin scheduling.
[0029] In one embodiment, the electronic device responds to a user instruction and determines a real-time task scheduling mode based on the user instruction. The electronic device creates tasks according to the determined real-time task scheduling mode, thereby obtaining real-time tasks that support the implementation of that task scheduling mode.
[0030] In another embodiment, the electronic device responds to a user instruction and determines the type of real-time task to be created based on the user instruction. The electronic device then determines the corresponding real-time task scheduling method based on the real-time task type. Finally, the electronic device creates a task according to the real-time task scheduling method, thus obtaining a real-time task that supports that scheduling method.
[0031] Furthermore, the electronic device determines the real-time task scheduling method corresponding to the real-time task type based on the real-time task type, including: performing a table lookup operation in a preset data table using the real-time task type to find the real-time task scheduling method corresponding to that real-time task type. The data table stores the correspondence between real-time task types and real-time task scheduling methods.
[0032] In one embodiment, after determining the real-time task scheduling mode, the electronic device uses the task creation interface function provided by the real-time operating system at the application layer to control the real-time task scheduling mode used by the created real-time task according to the preset parameters provided by the task creation interface function.
[0033] In one embodiment, when an electronic device creates a real-time task, it follows the rules of the task creation interface described above: when using the first scheduling parameter, the created real-time task is scheduled using a preemptive scheduling method; when using the second scheduling parameter, the created real-time task is scheduled using a time-slice round-robin scheduling method. The first scheduling parameter is a preset parameter characterizing the preemptive scheduling method, and the second scheduling parameter is a preset parameter characterizing the time-slice round-robin scheduling method.
[0034] Optionally, the real-time operating system supports preemptive scheduling and round-robin scheduling; preemptive scheduling schedules tasks based on their priority, while round-robin scheduling schedules tasks based on a proportion of their runtime.
[0035] Since real-time operating systems employ both preemptive and round-robin scheduling for real-time tasks, prioritizing the determination of the real-time task scheduling mode before task creation provides a more flexible task creation method, thereby achieving better allocation of CPU resources.
[0036] Furthermore, the preemptive scheduling method involves real-time task scheduling based on task priority.
[0037] In one embodiment, the preemptive scheduling method is such that after a high-priority task preempts a low-priority task, the low-priority task cannot obtain CPU resources for execution unless the high-priority task actively relinquishes its CPU resources.
[0038] Furthermore, the time-slice round-robin scheduling method involves real-time task scheduling based on task execution time.
[0039] In one embodiment, the time-slice round-robin scheduling method schedules tasks according to the proportion of real-time task execution time. That is, high-priority tasks can get more execution time, but after the preset execution time ends, the task will be paused and the CPU resources occupied by the task will be given to the next task.
[0040] Combination Figure 2 As shown, this disclosure provides an apparatus for creating tasks in a real-time operating system. The real-time operating system supports various task scheduling methods. The apparatus includes a determining module 201 and a task creation module 202. The determining module 201 is configured to determine a real-time task scheduling method, which is any one of the task scheduling methods supported by the real-time operating system. The task creation module 202 is configured to create tasks according to the real-time task scheduling method, thereby obtaining real-time tasks that support the aforementioned task scheduling method.
[0041] The apparatus for creating real-time operating system tasks provided in this disclosure predetermines the real-time task scheduling mode to be used when creating the task, thereby enabling both preemptive and round-robin real-time task scheduling modes to coexist in the real-time operating system, providing a more flexible task creation method and achieving better allocation of CPU resources.
[0042] Optionally, the real-time operating system supports preemptive scheduling and round-robin scheduling. Preemptive scheduling is based on task priority, while round-robin scheduling is based on a proportion of runtime.
[0043] Optionally, the preemptive scheduling method involves real-time task scheduling based on task priority.
[0044] Optionally, the time-slice round-robin scheduling method involves real-time task scheduling based on task execution time.
[0045] Combination Figure 3As shown, this disclosure provides an electronic device 300 for creating a real-time operating system task, including a processor 301 and a memory 302. Optionally, the device may further include a communication interface 303 and a bus 304. The processor 301, communication interface 303, and memory 302 can communicate with each other via the bus 304. The communication interface 303 can be used for information transmission. The processor 301 can call logical instructions in the memory 302 to execute the method for creating a real-time operating system task described in the above embodiment.
[0046] Furthermore, the logic instructions in the aforementioned memory 302 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.
[0047] The memory 302, as a computer-readable storage medium, can be used to store software programs and computer-executable programs, such as program instructions / modules corresponding to the methods in the embodiments of this disclosure. The processor 301 executes functional applications and data processing by running the program instructions / modules stored in the memory 302, that is, it implements the method for creating a real-time operating system task in the above embodiments.
[0048] The memory 302 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the terminal device. Furthermore, the memory 302 may include high-speed random access memory and may also include non-volatile memory.
[0049] This disclosure provides a computer-readable storage medium storing computer-executable instructions configured to perform the above-described method for creating a real-time operating system.
[0050] The aforementioned computer-readable storage medium may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0051] The technical solutions of this disclosure can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes one or more instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in this disclosure. The aforementioned storage medium can be a non-transitory storage medium, including: a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, and other media capable of storing program code; it can also be a transient storage medium.
[0052] The foregoing description and accompanying drawings fully illustrate embodiments of this disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, procedural, and other changes. The embodiments represent only possible variations. Individual components and functions are optional unless explicitly required, and the order of operation may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. Moreover, the terminology used in this application is for describing embodiments only and is not intended to limit the claims. As used in the description of embodiments and claims, the singular forms “a,” “an,” and “the” are intended to equally include the plural forms unless the context clearly indicates otherwise. Similarly, the term “and / or” as used in this application means including one or more of the associated listed items and all possible combinations thereof. Additionally, when used in this application, the term "comprise" and its variations "comprises" and / or "comprising" refer to the presence of stated features, integrals, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components, and / or groups thereof. Without further limitations, an element defined by the phrase "comprising a..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes said element. In this document, each embodiment may focus on the differences from other embodiments, and similar or identical parts between embodiments can be referred to mutually. For methods, products, etc., disclosed in the embodiments, if they correspond to the method section disclosed in the embodiments, the relevant parts can be referred to the description of the method section.
[0053] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this disclosure. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0054] The methods and products (including but not limited to devices and equipment) disclosed in the embodiments herein can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For instance, the division of units may be merely a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the shown or discussed units may be through some interfaces, and the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to implement this embodiment according to actual needs. Furthermore, the functional units in the embodiments of this disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0055] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than that shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks may also occur in a different order than disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. Each block in a block diagram and / or flowchart, and combinations of blocks in a block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
Claims
1. A method for creating a real-time operating system task, characterized in that, The real-time operating system supports multiple different task scheduling methods; the method includes: Determine the real-time task scheduling method; the real-time task scheduling method is any one of the task scheduling methods supported by the real-time operating system. A task is created according to the real-time task scheduling method to obtain a real-time task that supports the task scheduling method.
2. The method according to claim 1, characterized in that, The real-time operating system supports preemptive scheduling and round-robin scheduling; the preemptive scheduling method schedules tasks based on their priority, while the round-robin scheduling method schedules tasks based on a proportion of their runtime.
3. The method according to claim 2, characterized in that, The preemptive scheduling method involves real-time task scheduling based on task priority.
4. The method according to claim 2, characterized in that, The time-slice round-robin scheduling method is to schedule tasks in real time based on the task execution time.
5. An apparatus for creating a real-time operating system task, characterized in that, The real-time operating system supports multiple different task scheduling methods; the device includes: The determination module is configured to determine the real-time task scheduling mode; the real-time task scheduling mode is any one of the task scheduling modes supported by the real-time operating system. The task creation module is configured to create tasks according to the real-time task scheduling method, thereby obtaining real-time tasks that support the task scheduling method.
6. The apparatus according to claim 5, characterized in that, The real-time operating system supports preemptive scheduling and round-robin scheduling. The preemptive scheduling method schedules tasks based on their priority, while the round-robin scheduling method schedules tasks based on their runtime proportions.
7. The apparatus according to claim 6, characterized in that, The preemptive scheduling method performs real-time task scheduling based on task priority.
8. The apparatus according to claim 6, characterized in that, The time-slice round-robin scheduling method performs real-time task scheduling based on the task execution time.
9. An electronic device comprising a processor and a memory storing program instructions, characterized in that, The processor is configured to, when executing the program instructions, perform the method for creating a real-time operating system task as described in any one of claims 1 to 4.
10. A storage medium storing program instructions, characterized in that, The program instructions are executed by the processor to implement the method for creating a real-time operating system task as described in any one of claims 1 to 4.