Task space distribution method, system and device of real-time operating system
By introducing adjustment marking bits and adjustment completion marking bits in the real-time operating system, the task memory space is automatically adjusted, and the problem of wasted resource allocation and manual adjustment in the existing technology is solved, and the optimal allocation of task memory space and the improvement of system resource utilization is achieved.
Patent Information
- Application Number
- CN202411974417.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-25
AI Technical Summary
The existing real-time operating system has problems such as wasting resources and manual adjustment in task memory allocation, resulting in low system resource utilization and increased cost.
By introducing adjustment mark bits and adjustment completion mark bits in the real-time operating system, the memory space of the task is automatically adjusted, and the memory space threshold is dynamically adjusted according to the maximum memory space and remaining memory space required for task operation to achieve the optimal allocation of task memory space.
It realizes automatic adjustment of task memory space, improves system resource utilization, reduces the cost of RAM memory chips, and improves software debugging efficiency.
Smart Images

Figure CN119883632A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of task memory allocation, and in particular to a task space allocation method, system and device for a real-time operating system. Background Art
[0002] Real-time operating systems are generally used for multi-tasking in embedded devices, and the on-chip RAM (Random Access Memory) resources of embedded devices are generally tight. The creation of a task requires the allocation of stack memory space, which consumes the storage space of the on-chip RAM. When the memory allocation of a task is too large, the task does not need so much memory space to run, resulting in a waste of system resources and increased cost consumption; when the memory allocation of a task is too small, the task cannot run normally, and the stack overflow causes the system to crash.
[0003] In the related technology 1, the memory space is manually allocated based on experience according to the complexity of the task. In the related technology 2, the task is manually allocated and debugged one by one, and the memory space of the task is continuously modified to meet the system operation requirements. Both solutions require manual adjustment of the memory space required for task operation, which is laborious and time-consuming, and the memory space set for each task is not optimal, resulting in a waste of system resources and increasing the cost of RAM storage chips. Summary of the invention
[0004] The purpose of the present invention is to provide a task space allocation method, system and device for a real-time operating system in order to accurately and automatically adjust the optimal memory space required for each task to run.
[0005] To achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:
[0006] In the first aspect, an embodiment of the present application provides a task space allocation method for a real-time operating system, comprising: during the boot loader running stage at startup, adjusting the memory space corresponding to the task according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of each task stored in the ROM; creating the task according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task; during the running stage of the task, simulating the task to determine the maximum memory space and the remaining memory space required to run the task, and updating the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task according to the maximum memory space, the remaining memory space, and a preset remaining memory space threshold ratio range; determining whether the task needs to be restarted according to the updated value of the adjustment mark bit and the value of the adjustment completion mark bit of the task; when the task needs to be restarted, restarting the software corresponding to the task to restart the task.
[0007] In one embodiment, adjusting the memory space corresponding to the task according to the value of the adjustment flag bit and the value of the adjustment completion flag bit of each task stored in the ROM includes: determining whether the value of the adjustment completion flag bit of the task is 0; when the value of the adjustment completion flag bit is 0, determining that the memory space of the task needs to be adjusted, and determining the value of the adjustment flag bit of the task; when the value of the adjustment completion flag bit is 1, determining that the memory space of the task does not need to be adjusted; when the value of the adjustment flag bit of the task is 1, determining that the memory space of the task is insufficient, and expanding the memory space of the task; when the value of the adjustment flag bit of the task is 0, determining that the memory space of the task is sufficient, and reducing the memory space of the task.
[0008] In one implementation, the expanding the memory space of the task includes: reading the memory space of the task, and increasing the memory space of the task by n%; the n% includes 5%.
[0009] In one implementation, reducing the memory space of the task includes: reading the memory space of the task, and reducing the memory space of the task by m%; the m% includes 3%.
[0010] In one embodiment, the task is created according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task, including: when the value of the task creation quantity is 0, determining that the task is created for the first time, and creating the task according to the preset memory space; when the value of the task creation quantity is not 0, determining that the task is not created for the first time, and creating the task according to the adjusted memory space of the task; adding 1 to the value of the task creation quantity of the task.
[0011] In one embodiment, updating the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task according to the maximum memory space, the remaining memory space, and the preset remaining memory space threshold ratio range includes: determining the preset remaining memory space threshold range according to the maximum memory space and the preset remaining memory space threshold ratio range; updating the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task according to the remaining memory space and the preset remaining memory space threshold range.
[0012] In one embodiment, the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task are updated according to the remaining memory space and the preset remaining memory space threshold range, including: when the remaining memory space of the task is lower than the lower limit of the preset remaining memory space threshold range, the value of the adjustment flag bit of the task is updated to 1; when the remaining memory space of the task is higher than the upper limit of the preset remaining memory space threshold range, the value of the adjustment flag bit of the task is updated to 0; when the remaining memory space of the task is within the preset remaining memory space threshold range within a preset time length, the value of the adjustment completion flag bit of the task is updated to 1.
[0013] In one embodiment, determining whether the task needs to be restarted based on the updated value of the adjustment mark bit and the value of the adjustment completion mark bit of the task includes: when the value of the adjustment mark bit of the task is 1, determining that the task needs to be restarted; when the values of the adjustment completion mark bits of all the tasks are 1, determining that the task needs to be restarted.
[0014] In the second aspect, an embodiment of the present application also provides a task space allocation device for a real-time operating system, comprising: a first processing module, configured to adjust the memory space corresponding to the task according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of each task stored in the ROM during the boot loader running stage; a task creation module, configured to create the task according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task; a second processing module, configured to simulate the task during the running stage of the task, determine the maximum memory space and the remaining memory space required to run the task, and update the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task according to the maximum memory space, the remaining memory space, and the preset remaining memory space threshold ratio range; a third processing module, configured to determine whether the task needs to be restarted according to the updated value of the adjustment mark bit and the value of the adjustment completion mark bit of the task; when the task needs to be restarted, restart the software corresponding to the task to restart the task.
[0015] In one embodiment, the first processing module is configured to: determine whether the value of the adjustment completion mark bit of the task is 0; when the value of the adjustment completion mark bit is 0, determine that the memory space of the task needs to be adjusted, and determine the value of the adjustment mark bit of the task; when the value of the adjustment completion mark bit is 1, determine that the memory space of the task does not need to be adjusted; when the value of the adjustment mark bit of the task is 1, determine that the memory space of the task is insufficient, and expand the memory space of the task; when the value of the adjustment mark bit of the task is 0, determine that the memory space of the task is sufficient, and reduce the memory space of the task.
[0016] In one embodiment, the first processing module is configured to: read the memory space of the task, and increase the memory space of the task by n%; the n% includes 5%.
[0017] In one implementation, the first processing module is configured to: read the memory space of the task, and reduce the memory space of the task by m%; the m% includes 3%.
[0018] In one embodiment, the task creation module is configured as follows: when the value of the task creation quantity is 0, it is determined that the task is created for the first time, and the task is created according to a preset memory space; when the value of the task creation quantity is not 0, it is determined that the task is not created for the first time, and the task is created according to an adjusted memory space of the task; and the value of the task creation quantity of the task is increased by 1.
[0019] In one embodiment, the second processing module is configured to: determine the preset remaining memory space threshold range based on the maximum memory space and the preset remaining memory space threshold ratio range; and update the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task based on the remaining memory space and the preset remaining memory space threshold range.
[0020] In one embodiment, the second processing module is configured to: when the remaining memory space of the task is lower than the lower limit of the preset remaining memory space threshold range, update the value of the adjustment flag bit of the task to 1; when the remaining memory space of the task is higher than the upper limit of the preset remaining memory space threshold range, update the value of the adjustment flag bit of the task to 0; when the remaining memory space of the task within the preset time length is within the preset remaining memory space threshold range, update the value of the adjustment completion flag bit of the task to 1.
[0021] In one embodiment, the third processing module is configured to: when the value of the adjustment mark bit of the task is 1, determine that the task needs to be restarted; when the value of the adjustment completion mark bit of all the tasks is 1, determine that the task needs to be restarted.
[0022] In the third aspect, an embodiment of the present application also provides a task space allocation system for a real-time operating system, including: a main control chip CPU; a real-time operating system runs on the main control chip CPU; the main control chip CPU is connected to RAM and ROM; the running overhead of the task is on the RAM, and the running status parameters of the task are stored in the ROM.
[0023] In a fourth aspect, an embodiment of the present application further provides a computer device, comprising: a processor, a storage medium and a bus, wherein the storage medium stores program instructions executable by the processor, and when the computer device is running, the processor communicates with the storage medium through the bus, and the processor executes the program instructions to perform the steps of any one of the above methods.
[0024] In a fifth aspect, an embodiment of the present application further provides a non-volatile computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of any one of the above methods are executed.
[0025] The beneficial effects of the present application are: by adjusting the remaining space threshold of the task, the remaining space size of the task is dynamically adjusted to a fixed range, and the optimal memory space required for the operation of each task can be automatically adjusted. The method can be repeated after the software is modified, and the adjustment results can be presented to the debugger in a visual form or other form. All processes are completed automatically without manual adjustment, which greatly improves the debugging process and work efficiency of the software code, greatly improves the utilization rate of RAM memory space, and further reduces the cost of using the chip. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0027] Figure 1 A flowchart of a task space allocation method for a real-time operating system provided in an embodiment of the present application;
[0028] Figure 2 A flowchart of a task space allocation method for a real-time operating system provided in an embodiment of the present application;
[0029] Figure 3 A flowchart of a task space allocation method for a real-time operating system provided in an embodiment of the present application;
[0030] Figure 4 A flowchart of a task space allocation method for a real-time operating system provided in an embodiment of the present application;
[0031] Figure 5 A flowchart of a task space allocation method for a real-time operating system provided in an embodiment of the present application;
[0032] Figure 6 A flowchart of a task space allocation method for a real-time operating system provided in an embodiment of the present application;
[0033] Figure 7 A structural diagram of a task space allocation device for a real-time operating system provided in an embodiment of the present application;
[0034] Figure 8 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments.
[0036] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application for which protection is sought, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0037] In the description of the present application, it should be noted that if the terms "upper", "lower", etc. appear, the orientation or position relationship indicated is based on the orientation or position relationship shown in the drawings, or is the orientation or position relationship in which the product of the application is usually placed when used. It is only for the convenience of describing the present application and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present application.
[0038] In addition, the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0039] It should be noted that, in the absence of conflict, the features in the embodiments of the present application may be combined with each other.
[0040] Figure 1 A flowchart of a task space allocation method for a real-time operating system provided in an embodiment of the present application; Figure 1 As shown, the method includes:
[0041] Step 110: During the boot loader operation phase, the memory space of the corresponding task is adjusted according to the value of the adjustment mark bit of each task and the value of the adjustment completion mark bit stored in the ROM.
[0042] Among them, a real-time operating system (RTOS) is an operating system that can respond and process external events or data at a sufficiently fast speed when they are generated.
[0043] RAM (Random Access Memory) is an internal memory that directly exchanges data with the CPU. It serves as a temporary data storage medium for the operating system or other running programs. The data will be lost when the power is off.
[0044] The biggest difference between ROM (Read Only Memory) and RAM is that data is not lost when power is off.
[0045] Task: Each task is responsible for handling an independent event. It is an independent and looping code block. Each task consumes on-chip RAM when running. The switching between tasks is completed by the task scheduler of the operating system.
[0046] Generally, when the system is turned on, the Bootloader will be run first. During the bootloader running stage, the task memory space is adjusted according to the value of the task adjustment flag and adjustment completion flag stored in the ROM. Figure 2 As shown, the above step 110 may include the following steps 210 and 220:
[0047] Step 210, determine whether the value of the adjustment completion flag bit of the task is 0. When the value of the adjustment completion flag bit is 0, determine that the memory space of the task needs to be adjusted, and determine the value of the adjustment flag bit of the task; when the value of the adjustment completion flag bit is 1, determine that the memory space of the task does not need to be adjusted.
[0048] Each task includes the value of the adjustment flag, the value of the adjustment completion flag, and the memory space. Different values of the adjustment flag and the adjustment completion flag have different meanings. Usually, the value of the adjustment completion flag is 1, indicating that the adjustment is completed and no adjustment is required; the value of the adjustment completion flag is 0, indicating that the memory space of the task needs to be optimized.
[0049] Generally, the value of the adjustment completion flag is determined first. When the value of the adjustment completion flag is 0, it indicates that the memory space of the task needs to be optimized. At this time, the value of the adjustment flag is further determined.
[0050] Step 220: When the value of the adjustment flag of the task is 1, it is determined that the memory space of the task is insufficient, and the memory space of the task is expanded; when the value of the adjustment flag of the task is 0, it is determined that the memory space of the task is sufficient, and the memory space of the task is reduced.
[0051] The value of the adjustment flag is 1, indicating that the memory space of the task is insufficient; the value of the adjustment flag is 0, indicating that the memory space of the task is sufficient.
[0052] Generally, when the value of the adjustment flag is 1, it means that the memory space of the task is insufficient. At this time, the memory space of the task is further determined and the memory space of the task is expanded according to the memory space of the task. When the value of the adjustment flag is 0, it means that the memory space of the task is sufficient. At this time, the memory space of the task is further determined and the memory space of the task is reduced according to the memory space of the task. Specifically, the task space is expanded through the following steps:
[0053] Read the task's memory space and increase the task's memory space by n%.
[0054] Here, n% includes 5%.
[0055] In actual operation, n has no value range and is related to the RAM space size and adjustment speed, and can be fixed at 5%.
[0056] Increase of memory space: When the operating system creates a task, the software applies for and allocates memory based on the stored memory space value by the operating system RTOS, such as increasing the memory size from 10k to 12k. No specific operation steps are required and it is set by the software.
[0057] Specifically, the task space is reduced through the following steps:
[0058] Read the task's memory space and reduce the task's memory space by m%.
[0059] Among them, m% includes 3%.
[0060] In actual operation, m has no value range and is related to the RAM space size and adjustment speed, and can be fixed at 3%.
[0061] Reduction of memory space: When the operating system creates a task, the software applies for and allocates memory based on the stored memory space value by the operating system RTOS, such as reducing the memory size from 12k to 10k. No specific operation steps are required and it is set by the software.
[0062] Step 120: Create a task according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task.
[0063] The value of the number of tasks created can indicate whether the task is created for the first time. In different cases, the memory space of the task is adjusted according to the corresponding strategy. Figure 3 As shown, the above step 120 may include the following steps 310 to 330:
[0064] Step 310: When the value of the task creation quantity is 0, it is determined that the task is created for the first time, and the task is created according to the preset memory space.
[0065] Among them, the preset memory space is a given default value.
[0066] When the value of the task creation quantity is 0, it indicates that the task is created for the first time. At this time, the task can be created directly. When creating, the memory space is determined according to the given default value (preset memory space), the given default value is written to the storage area of the memory space, and the task is created.
[0067] Step 320: When the value of the task creation quantity is not 0, it is determined that the task is not created for the first time, and the task is created according to the adjusted memory space of the task.
[0068] Among them, when the value of the task creation quantity is 1, it indicates that the task is not created for the first time. At this time, the memory space of the task adjusted in the above step 110 is determined as the memory space required to create the task, and the memory space of the task adjusted in the above step 110 is written into the storage area of the memory space, and the task is created.
[0069] Step 330: Increase the value of the task creation quantity of the task by 1.
[0070] In actual operation, after creating a task, it is also necessary to update the value of the task creation quantity of the task. The value of the task creation quantity is stored in the ROM. After creating the task, the value of the task creation quantity of the task stored in the ROM is increased by 1.
[0071] Step 130, during the task running phase, simulate the task, determine the maximum memory space and remaining memory space required to run the task, and update the value of the task's adjustment mark bit and the value of the adjustment completion mark bit according to the maximum memory space, the remaining memory space, and the preset remaining memory space threshold ratio range.
[0072] During the task running phase, the entire scenario of each task can be simulated manually or automatically by software and run at full performance to obtain the maximum memory space and remaining memory space required for the task running.
[0073] The preset remaining memory space threshold ratio range is a ratio range, that is, a percentage range; it can be set based on experience or by referring to relevant literature, and is not limited here; for example: the preset remaining memory space threshold ratio range is set to 5% to 10%.
[0074] The preset remaining memory space threshold range can be obtained according to the ratio range of the maximum memory space and the preset remaining memory space threshold range, and whether the memory is sufficient can be determined according to the remaining memory space and the preset remaining memory space threshold range, so as to update the value of the adjustment mark bit, and then update the value of the adjustment completion mark bit according to the updated adjustment mark bit. Specifically, Figure 4 As shown, the above step 130 may include the following steps 410 and 420:
[0075] Step 410: Determine a preset remaining memory space threshold range according to the maximum memory space and the preset remaining memory space threshold ratio range.
[0076] Among them, the maximum memory space is multiplied by the upper limit value and the lower limit value of the preset remaining memory space threshold ratio range to obtain the preset remaining memory space threshold range; for example: the maximum memory space is 100M, the remaining memory space threshold ratio range is set to 5%~10%, then the preset remaining memory space threshold range is 5~10M.
[0077] Step 420: Update the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task according to the remaining memory space and the preset remaining memory space threshold range.
[0078] Among them, by comparing the remaining memory space with the preset remaining memory space threshold range, it can be determined whether the remaining memory space (memory space) is sufficient, and then the value of the adjustment flag is updated; further, the value of the adjustment completion flag is updated according to the value of the adjustment flag. Figure 5 As shown, the above step 420 may include the following steps 510 to 530:
[0079] Step 510: When the remaining memory space of the task is lower than the lower limit of the preset remaining memory space threshold range, the value of the adjustment flag bit of the task is updated to 1.
[0080] Among them, when the remaining memory space is less than the lower limit value of the preset remaining memory space threshold range, it indicates that the remaining memory space is insufficient, that is, the memory space is insufficient. At this time, the value of the adjustment mark bit is updated to 1.
[0081] Step 520: When the remaining memory space of the task is higher than the upper limit of the preset remaining memory space threshold range, the value of the adjustment flag bit of the task is updated to 0.
[0082] Among them, when the remaining memory space is greater than the upper limit value of the preset remaining memory space threshold range, it indicates that the remaining memory space is sufficient, that is, the memory space is sufficient. At this time, the value of the adjustment mark bit is updated to 0.
[0083] Step 530: When the remaining memory space of the task within the preset duration is within a preset remaining memory space threshold range, the value of the adjustment completion flag bit of the task is updated to 1.
[0084] When the remaining memory space of the task within the preset duration is within the preset remaining memory space threshold range, it indicates that the memory space of the task does not need to be adjusted. At this time, the value of the adjustment completion flag bit of the task is updated to 1.
[0085] Step 140: determine whether the task needs to be restarted according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of the updated task; when the task needs to be restarted, restart the software corresponding to the task to restart the task.
[0086] There are two types of restarts: one is when a single task needs to be restarted to continue adjusting the memory space; the other is when all tasks are restarted after the adjustment is completed. In general, the task is restarted by the software corresponding to the restart task. Figure 6 As shown, the above step 140 may include the following steps 610 and 620:
[0087] Step 610: When the value of the adjustment flag bit of the task is 1, it is determined that the task needs to be restarted.
[0088] Among them, the value of the adjustment flag bit of the task is 1, indicating that the memory space of the task is insufficient and needs to be further adjusted. In this case, the task needs to be restarted; the value of the adjustment flag bit is 0, indicating that the memory space of the task is sufficient and the task does not need to be restarted.
[0089] Step 620: When the values of the adjustment completion flag bits of all tasks are 1, it is determined that the task needs to be restarted.
[0090] Among them, when the values of the adjustment completion flag bits of all tasks are 1, it indicates that all tasks have been adjusted and the software is restarted at this time.
[0091] After the software is restarted, the above steps 110 to 130 are repeated.
[0092] The task space allocation method of the real-time operating system provided in the embodiment of the present application is as follows: first, during the boot loader running stage at startup, the memory space of the corresponding task is adjusted according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of each task stored in the ROM; secondly, the task is created according to the value of the task creation quantity stored in the ROM and the memory space of the adjusted task; thirdly, during the task running stage, the task is simulated to determine the maximum memory space and the remaining memory space required to run the task, and the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task are updated according to the maximum memory space, the remaining memory space, and the preset remaining memory space threshold ratio range; finally, according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task after the update, it is determined whether the task needs to be restarted; when the task needs to be restarted, the software corresponding to the task is restarted to realize the restart of the task. In this way, by adjusting the remaining space threshold of the task, the remaining space size of the task can be dynamically adjusted to a fixed range, which can automatically adjust the optimal memory space required for the operation of each task. This method can be repeated after the software is modified, and the adjustment results can be presented to the debugger in a visual or other form. All processes are completed automatically without manual adjustment, which greatly improves the debugging process and work efficiency of the software code, greatly improves the utilization rate of RAM memory space, and further reduces the cost of using the chip.
[0093] After introducing the task space allocation method of the real-time operating system according to the exemplary embodiment of the present disclosure, next, the task space allocation system of the real-time operating system according to the exemplary embodiment of the present disclosure will be described.
[0094] The task space allocation system of the real-time operating system includes:
[0095] Main control chip CPU;
[0096] A real-time operating system runs on the main control chip CPU;
[0097] The main control chip CPU is connected to RAM and ROM; the running overhead of the task is on RAM, and the running status parameters of the task are stored in ROM.
[0098] After introducing the task space allocation method of the real-time operating system according to the exemplary embodiment of the present disclosure, Figure 7 , a task space allocation device 700 of a real-time operating system according to an exemplary embodiment of the present disclosure is described.
[0099] refer to Figure 7 The task space allocation device 700 of the real-time operating system includes: a first processing module 710, which is configured to adjust the memory space of the corresponding task according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of each task stored in the ROM during the boot loader operation stage; a task creation module 720, which is configured to create the task according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task; a second processing module 730, which is configured to simulate the task during the task operation stage, determine the maximum memory space and the remaining memory space required to run the task, and update the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task according to the maximum memory space, the remaining memory space, and the preset remaining memory space threshold ratio range; a third processing module 740, which is configured to determine whether the task needs to be restarted according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task after the update; when the task needs to be restarted, restart the software corresponding to the task to restart the task.
[0100] In one embodiment, the first processing module 710 is configured to: determine whether the value of the adjustment completion mark bit of the task is 0; when the value of the adjustment completion mark bit is 0, determine that the memory space of the task needs to be adjusted, and determine the value of the adjustment mark bit of the task; when the value of the adjustment completion mark bit is 1, determine that the memory space of the task does not need to be adjusted; when the value of the adjustment mark bit of the task is 1, determine that the memory space of the task is insufficient, and expand the memory space of the task; when the value of the adjustment mark bit of the task is 0, determine that the memory space of the task is sufficient, and reduce the memory space of the task.
[0101] In one implementation, the first processing module 710 is configured to: read the memory space of the task, and increase the memory space of the task by n%; where n% includes 5%.
[0102] In one implementation, the first processing module 710 is configured to: read the memory space of the task, and reduce the memory space of the task by m%; m% includes 3%.
[0103] In one embodiment, the task creation module 720 is configured as follows: when the value of the task creation quantity is 0, it is determined that the task is created for the first time, and the task is created according to a preset memory space; when the value of the task creation quantity is non-0, it is determined that the task is not created for the first time, and the task is created according to an adjusted memory space of the task; the value of the task creation quantity of the task is increased by 1.
[0104] In one embodiment, the second processing module 730 is configured to: determine the preset remaining memory space threshold range based on the maximum memory space and the preset remaining memory space threshold ratio range; update the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task based on the remaining memory space and the preset remaining memory space threshold range.
[0105] In one embodiment, the second processing module 730 is configured as follows: when the remaining memory space of the task is lower than the lower limit of the preset remaining memory space threshold range, the value of the adjustment mark bit of the task is updated to 1; when the remaining memory space of the task is higher than the upper limit of the preset remaining memory space threshold range, the value of the adjustment mark bit of the task is updated to 0; when the remaining memory space of the task within the preset time length is within the preset remaining memory space threshold range, the value of the adjustment completion mark bit of the task is updated to 1.
[0106] In one implementation, the third processing module 740 is configured to: when the value of the adjustment mark bit of the task is 1, determine that the task needs to be restarted; when the values of the adjustment completion mark bits of all tasks are 1, determine that the task needs to be restarted.
[0107] The above-mentioned device is used to execute the method provided by the aforementioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.
[0108] The above modules may be one or more integrated circuits configured to implement the above methods, such as one or more application specific integrated circuits (ASICs), or one or more microprocessors, or one or more field programmable gate arrays (FPGAs). For another example, when a module is implemented in the form of a processing element scheduling program code, the processing element may be a general-purpose processor, such as a central processing unit (CPU) or other processor that can call program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0109] Figure 8A schematic diagram of a computer device provided in an embodiment of the present application. The device can be integrated into a terminal device or a chip of a terminal device. The terminal can be a computing device with data processing capabilities.
[0110] The device includes: a processor 801 , a storage medium 802 and a bus 803 .
[0111] The storage medium 802 stores program instructions executable by the processor 801. When the computer device 800 is running, the processor 801 communicates with the storage medium 802 via the bus 803. The processor 801 executes the program instructions to perform the above method embodiment. The specific implementation method and technical effect are similar and will not be repeated here.
[0112] Optionally, the present invention also provides a program product, such as a computer-readable storage medium, comprising a program, which is used to execute the above method embodiment when executed by a processor.
[0113] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0114] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0115] In addition, each functional unit in each embodiment of the present invention 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. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0116] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (English: Read-Only Memory, abbreviated: ROM), random access memory (English: Random Access Memory, abbreviated: RAM), disk or optical disk and other media that can store program codes.
[0117] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A task space allocation method for a real-time operating system, characterized in that: include: During the boot loader program running phase, the memory space corresponding to each task is adjusted according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of each task stored in the ROM; Creating the task according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task; During the running phase of the task, simulating the task, determining the maximum memory space and remaining memory space required to run the task, and updating the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task according to the maximum memory space, the remaining memory space, and a preset remaining memory space threshold ratio range; Determine whether the task needs to be restarted according to the updated value of the adjustment mark bit and the value of the adjustment completion mark bit of the task; when the task needs to be restarted, restart the software corresponding to the task to restart the task.
2. The method according to claim 1, characterized in that The step of adjusting the memory space corresponding to each task according to the value of the adjustment flag bit and the value of the adjustment completion flag bit of each task stored in the ROM includes: Determine whether the value of the adjustment completion flag bit of the task is 0; when the value of the adjustment completion flag bit is 0, determine that the memory space of the task needs to be adjusted, and determine the value of the adjustment flag bit of the task; when the value of the adjustment completion flag bit is 1, determine that the memory space of the task does not need to be adjusted; When the value of the adjustment mark bit of the task is 1, it is determined that the memory space of the task is insufficient, and the memory space of the task is expanded; when the value of the adjustment mark bit of the task is 0, it is determined that the memory space of the task is sufficient, and the memory space of the task is reduced.
3. The method according to claim 2, characterized in that The expanding the memory space of the task includes: The memory space of the task is read, and the memory space of the task is increased by n%, wherein n% includes 5%.
4. The method according to claim 2, characterized in that: The reducing the memory space of the task includes: The memory space of the task is read, and the memory space of the task is reduced by m%, wherein the m% includes 3%.
5. The method according to claim 1, characterized in that The step of creating the task according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task includes: When the value of the task creation quantity is 0, it is determined that the task is created for the first time, and the task is created according to the preset memory space; When the value of the task creation quantity is not 0, it is determined that the task is not created for the first time, and the task is created according to the adjusted memory space of the task; Increase the value of the task creation quantity of the task by 1.
6. The method according to claim 1, characterized in that The updating of the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task according to the maximum memory space, the remaining memory space, and the preset remaining memory space threshold ratio range includes: Determine a preset remaining memory space threshold range according to the maximum memory space and the preset remaining memory space threshold ratio range; According to the remaining memory space and the preset remaining memory space threshold range, the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task are updated.
7. The method according to claim 6, characterized in that The updating, according to the remaining memory space and the preset remaining memory space threshold range, of the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task includes: When the remaining memory space of the task is lower than the lower limit of the preset remaining memory space threshold range, updating the value of the adjustment flag bit of the task to 1; When the remaining memory space of the task is higher than the upper limit of the preset remaining memory space threshold range, updating the value of the adjustment flag bit of the task to 0; When the remaining memory space of the task within the preset time period is within the preset remaining memory space threshold range, the value of the adjustment completion flag bit of the task is updated to 1.
8. The method according to claim 1, characterized in that The determining whether the task needs to be restarted according to the updated value of the adjustment flag bit of the task and the value of the adjustment completion flag bit includes: When the value of the adjustment flag bit of the task is 1, it is determined that the task needs to be restarted; When the values of the adjustment completion flag bits of all the tasks are 1, it is determined that the task needs to be restarted.
9. A task space allocation system for a real-time operating system, characterized in that: include: Main control chip CPU; A real-time operating system runs on the main control chip CPU; The main control chip CPU is connected with RAM and ROM; The running overhead of the task is stored in the RAM, and the running status parameters of the task are stored in the ROM.
10. A task space allocation device for a real-time operating system, characterized in that: include: The first processing module is configured to adjust the memory space corresponding to the task according to the value of the adjustment mark bit and the value of the adjustment completion mark bit of each task stored in the ROM during the boot loader running stage; A task creation module, configured to create the task according to the value of the task creation quantity stored in the ROM and the adjusted memory space of the task; A second processing module is configured to simulate the task during the running phase of the task, determine the maximum memory space and the remaining memory space required to run the task, and update the value of the adjustment flag bit and the value of the adjustment completion flag bit of the task according to the maximum memory space, the remaining memory space, and a preset remaining memory space threshold ratio range; The third processing module is configured to determine whether the task needs to be restarted based on the value of the adjustment mark bit and the value of the adjustment completion mark bit of the task after update; when the task needs to be restarted, restart the software corresponding to the task to restart the task.