Method, device and equipment for task stack memory management and storage medium

By initializing the task stack in RTOS and determining its usage, the task scheduling based on the preset threshold is performed, the stack overflow problem caused by the unreasonable use of the mission stack memory, which improves the stability and reliability of the RTOS.

CN119336497AInactive Publication Date: 2025-01-21镁佳(北京)科技有限公司

Patent Information

Application Number
CN202411371220.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2025-01-21
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Unreasonable use of task stack memory in RTOS may lead to stack overflow, affecting the stability and reliability of RTOS.

Method used

By obtaining the initial number of bytes and starting address when the task stack is initialized, and determining the space usage in the stack before switching to the target task stack, task scheduling is performed based on the preset threshold of task stack usage to ensure reasonable memory planning and usage. .

Benefits of technology

Accurately obtain the task stack memory usage, reasonably plan the task stack memory, optimize RTOS performance, prevent task stack overflow, and improve the stability and reliability of the RTOS system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119336497A_ABST
    Figure CN119336497A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of embedded operating systems, and discloses a task stack memory management method, device and equipment and a storage medium, the method comprises the following steps: under the condition of initializing task stacks, obtaining the initial byte number of each task stack and the initial address of each task stack, and setting the initial value in each task stack as a preset value; before switching to the target task stack, obtaining the number of continuous bytes with the numerical value being a preset value in the target task stack, and determining the in-stack space usage amount of the target task stack based on the ratio of the number of continuous bytes to the number of initial bytes of the target task stack; and performing task scheduling based on a task stack usage amount preset threshold value and the in-stack space usage amount of the target task stack. By means of the method, the task stack memory usage amount can be accurately obtained, the RTOS memory usage condition can be known, the task stack memory is reasonably planned, task scheduling is conducted, RTOS performance is optimized, task stack overflow is prevented, and the stability and reliability of an RTOS system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of embedded operating systems, and in particular to a method, a device, a equipment and a storage medium for task stack memory management. Background Art

[0002] An embedded real-time operating system (RTOS) is an operating system used in embedded systems. When external events or data are generated, it can accept and process them at a fast enough speed. The processing results can be used to control the production process or respond quickly to the processing system within the specified time, and control all real-time tasks to run in a coordinated and consistent manner.

[0003] During the operation of RTOS, the reasonable use of task stack memory is very important. If the usage of task stack memory is not accurately known, it may cause RTOS to have problems such as stack overflow, affecting the stability and reliability of RTOS. Summary of the invention

[0004] In view of this, the present invention provides a method, apparatus, device and storage medium for task stack memory management to solve the problem of unreasonable use of task stack memory, which leads to stack overflow of RTOS and affects the stability and reliability of RTOS.

[0005] In a first aspect, the present invention provides a method for task stack memory management, the method comprising: when initializing the task stack, obtaining the initial number of bytes of each task stack and the starting address of each task stack, and setting the initial value in each task stack to a preset value; before switching to a target task stack, obtaining the number of consecutive bytes in the target task stack whose value is the preset value, and determining the stack space usage of the target task stack based on the ratio of the consecutive number of bytes to the initial number of bytes of the target task stack; and performing task scheduling based on a preset threshold value for task stack usage and the stack space usage of the target task stack.

[0006] In an optional embodiment, task scheduling is performed based on a preset threshold value for task stack usage and the stack space usage of the target task stack, including: if the preset threshold value for task stack usage is greater than the stack space usage of the target task stack, switching to the target task stack, and monitoring the stack space usage of the target task stack during the operation of the target task stack; if the preset threshold value for task stack usage is equal to the stack space usage of the target task stack, issuing an abnormal alarm.

[0007] In an optional implementation, if the preset threshold of the task stack usage is equal to the stack space usage of the target task stack, an abnormal alarm is issued, including: outputting the identifier of the target task stack, the initial number of bytes of the target task stack and the usage of the target task stack.

[0008] In an optional embodiment, task scheduling is performed based on a preset threshold value for task stack usage and the stack space usage of the target task stack, and also includes: if the preset threshold value for task stack usage is less than the stack space usage of the target task stack, stopping switching to the target task stack and jumping to the safe code area.

[0009] In an optional embodiment, the aforementioned method for task stack memory management also includes: if the preset threshold value of the task stack usage is less than or equal to the stack space usage of the target task stack: obtaining the current task stack usage of each of the task stacks; determining the amount of allocatable stack memory based on the total stack memory and the current task stack usage of each of the task stacks; obtaining the increase in stack space that needs to be increased for the target task stack, and if the allocatable stack memory is greater than the increase, adjusting the stack space of the target task stack based on the increase.

[0010] In an optional embodiment, task scheduling is performed based on a preset threshold value for task stack usage and the stack space usage of the target task stack, and also includes: if the preset threshold value for task stack usage is less than the stack space usage of the target task stack, stopping switching to the target task stack and adjusting the external device controlled by the embedded real-time operating system to a controllable state.

[0011] In a second aspect, the present invention provides a device for task stack memory management, the device comprising: an initialization module, for obtaining the initial number of bytes of each task stack and the starting address of each task stack when initializing the task stack, and setting the initial value in each task stack to a preset value; a switching module, for obtaining the number of consecutive bytes in the target task stack whose value is the preset value before switching to the target task stack, and determining the usage of the target task stack based on the ratio of the consecutive number of bytes to the initial number of bytes of the target task stack; a scheduling module, for performing task scheduling based on a preset threshold value for task stack usage and the usage of the target task stack.

[0012] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the method for task stack memory management of the above-mentioned first aspect or any corresponding embodiment thereof by executing the computer instructions.

[0013] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the method for task stack memory management of the first aspect or any corresponding embodiment thereof.

[0014] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the method for task stack memory management of the first aspect or any corresponding embodiment thereof.

[0015] By marking the unused space in the task stack, the usage of the space in each task stack can be obtained. Based on the comparison between the usage of the space in the target task stack and the preset threshold of the task stack usage, the task stack memory usage can be accurately obtained, the RTOS memory usage can be understood, the task stack memory can be reasonably planned, the task scheduling can be performed, the RTOS performance can be optimized, the task stack overflow can be prevented, and the stability and reliability of the RTOS system can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the related technologies, the drawings required for use in the specific embodiments or the related technical descriptions will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0017] Figure 1 A schematic flow chart of a method for task stack memory management provided by an embodiment of the present invention is shown;

[0018] Figure 2 A schematic flow chart of a method for task stack memory management according to an embodiment of the present invention is shown;

[0019] Figure 3 A schematic diagram of the structure of a device for task stack memory management provided by an embodiment of the present invention is shown;

[0020] Figure 4 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution 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 part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.

[0022] According to an embodiment of the present invention, a method embodiment for task stack memory management is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0023] In this embodiment, a method for task stack memory management is provided, which can be used in a terminal or mobile terminal with an embedded operating system, such as an intelligent terminal of the Internet of Things, a mobile phone, a tablet computer, or a desktop computer, etc. Figure 1 A schematic diagram of a process for task stack memory management provided by an embodiment of the present invention is shown, Figure 1 As shown, the process includes the following steps:

[0024] Step S101, when initializing the task stack, obtain the initial number of bytes of each task stack and the starting address of each task stack, and set the initial value in each task stack to a preset value.

[0025] In this step, each task in the RTOS usually has an associated stack to store local variables, function call parameters, return addresses, etc. during the execution of each task. The initial number of bytes of the task stack is determined when the task is created. The initial number of bytes of the task stack determines the memory capacity of the stack, that is, the amount of data that the stack can store. The starting address is the starting position of the stack in memory, which is usually determined by the stack allocation mechanism of the RTOS.

[0026] When initializing the task stack, you can set each byte to a preset value by traversing each byte of the stack. The selection of the preset value depends on the specific application requirements. The preset value can be a specific value, a flag, or a specific data structure. For example, the preset value can be set to a marker of 0x55AAAA55. By marking the preset value, you can distinguish which space in the stack is used and which is not used.

[0027] Step S102, before switching to the target task stack, obtain the number of consecutive bytes in the target task stack whose value is a preset value, and determine the usage of the space in the target task stack based on the ratio of the number of consecutive bytes to the initial number of bytes of the target task stack.

[0028] In this step, when a task switch occurs, the state of the current task stack will be saved so that the execution environment of the task can be restored when the task is scheduled again. Traverse the target task stack, starting from the top or bottom of the stack based on the specific implementation of the RTOS and the growth direction of the stack, and search for consecutive bytes with a preset value. Record the starting position and length of this continuous byte. The ratio of the number of consecutive bytes to the initial number of bytes of the target task stack reflects the amount of free space in the stack of the target task stack, and can also determine the usage of the stack space of the target task stack.

[0029] You can use systemtick to switch tasks. Before switching tasks, scan the number of consecutive bytes in the target task stack that have a preset value. Based on the total number of bytes of each task stack and the corresponding number of consecutive bytes obtained by the scan, calculate the usage of the stack space of each task stack.

[0030] Step S103 , performing task scheduling based on the preset threshold of task stack usage and the stack space usage of the target task stack.

[0031] In this step, setting the preset threshold for task stack usage can help RTOS manage system resources. When the stack space of the target task stack approaches or exceeds the preset threshold for task stack usage, RTOS can take corresponding measures, such as adjusting the task execution order, allocating more resources, or triggering a stack overflow hook function; when the stack space of the target task stack is less than the preset threshold for task stack usage, it can switch to the target task stack.

[0032] The method for task stack memory management provided in this embodiment can obtain the usage of the space in each task stack by marking the unused space in the task stack. Based on the comparison between the usage of the space in the target task stack and the preset threshold of the task stack usage, the task stack memory usage can be accurately obtained, the RTOS memory usage can be understood, the task stack memory can be reasonably planned, tasks can be scheduled, the RTOS performance can be optimized, the task stack overflow can be prevented, and the stability and reliability of the RTOS system can be improved.

[0033] In this embodiment, a method for task stack memory management is provided, which can be used in a terminal or mobile terminal with an embedded operating system, such as an intelligent terminal of the Internet of Things, a mobile phone, a tablet computer, or a desktop computer, etc. Figure 2 A schematic diagram of a process for task stack memory management according to an embodiment of the present invention is shown. Figure 2 As shown, the process includes the following steps:

[0034] Step S201, when initializing the task stack, obtain the initial byte number and the starting address of each task stack, and set the initial value in each task stack to a preset value. Figure 1Step S101 of the illustrated embodiment will not be described in detail here.

[0035] Step S202, before switching to the target task stack, obtain the number of consecutive bytes in the target task stack whose value is a preset value, and determine the stack space usage of the target task stack based on the ratio of the consecutive bytes to the initial bytes of the target task stack. Figure 1 Step S102 of the illustrated embodiment will not be described in detail here.

[0036] Step S203 , performing task scheduling based on the preset threshold of task stack usage and the stack space usage of the target task stack.

[0037] Specifically, the above step S203 includes:

[0038] Step S2031 , if the preset threshold value of the task stack usage is greater than the stack space usage of the target task stack, switch to the target task stack, and monitor the stack space usage of the target task stack during the operation of the target task stack.

[0039] In this step, if the preset threshold of task stack usage is greater than the stack space usage of the target task stack, it indicates that the current stack space usage of the target task stack has not reached the preset limit, and the target task stack has enough space to continue execution or accept new tasks. In this case, the RTOS can safely switch to the target task stack and perform related task operations.

[0040] Specifically, after checking that the preset threshold of task stack usage is greater than the stack space usage of the target task stack, if other tasks are currently being executed, the RTOS will save its context, including register values ​​or stack pointers, so that the execution of the task can be resumed later. The RTOS updates the stack pointer and points the stack pointer to the top of the target task stack or an appropriate location. If the target task has been suspended or paused before, the RTOS will restore its context, including register values ​​or local variables. After the context of the target task is restored, the RTOS will start executing the tasks in the target task stack. During the execution of the target task, the RTOS will continue to monitor the usage of its stack to ensure that the stack space usage of the target task stack does not exceed the preset threshold of the task stack usage.

[0041] In this way, RTOS can efficiently manage multiple tasks and ensure that each task can be executed safely within the limited stack space.

[0042] Step S2032: If the preset threshold of the task stack usage is equal to the stack space usage of the target task stack, an abnormal alarm is issued.

[0043] In this step, if the preset threshold of task stack usage is equal to the stack space usage of the target task stack, it indicates that the stack space usage of the target task stack is high, and an abnormal alarm can be issued. After the abnormal alarm, the usage of the target task stack can be analyzed, and the stack space can be increased, the task code can be optimized, or the task load can be reduced.

[0044] This abnormal warning mechanism can help developers and administrators to promptly discover and handle problems such as insufficient task stack space, thereby avoiding system crashes or instability.

[0045] In some optional implementations, the above step S2031 includes:

[0046] Step a1, outputting the identifier of the target task stack, the initial number of bytes of the target task stack and the usage of the target task stack.

[0047] In this step, the name of the target task stack, the number of unused bytes of the target task stack, the ratio of used task stack, etc. can also be output. The aforementioned information can be output through a serial port, a universal serial bus, or an Ethernet, and the information output method in step a1 can also be determined according to actual needs.

[0048] In this way, based on the output of alarm information, developers can promptly discover and handle the problem of insufficient stack space, facilitate problem location, prevent system crashes, improve debugging efficiency, and enhance system stability and maintainability; at the same time, it can avoid waste of resources.

[0049] In some optional implementations, step S203 further includes:

[0050] Step a2: If the preset threshold value of the task stack usage is less than the stack space usage of the target task stack, stop switching to the target task stack and jump to the safe code area.

[0051] In this step, the security code area can be a function with an infinite loop. After entering the security code area, task scheduling stops and interrupts are disabled. By jumping to the security code area, the system waits for a reset or external intervention.

[0052] In this way, an extra layer of protection can be provided to the system in case of task stack abnormalities, thereby preventing potential stack overflow problems and improving the stability and reliability of the RTOS.

[0053] In some optional embodiments, the above step S203 also includes: if the preset threshold of task stack usage is less than or equal to the stack space usage of the target task stack: obtaining the current task stack usage of each task stack; determining the amount of stack memory that can be allocated based on the total stack memory and the current task stack usage of each task stack; obtaining the increase in stack space that needs to be increased for the target task stack, and if the amount of stack memory that can be allocated is greater than the increase, adjusting the stack space of the target task stack based on the increase.

[0054] In this embodiment, in addition to setting a preset value when the task stack is initialized to obtain the current task stack usage of the task stack, the task stack usage can also be obtained by embedding monitoring code in the task stack, using hardware monitoring functions, or using an application program interface provided by the RTOS. The amount of stack memory that can be allocated can be determined by subtracting the current usage of all task stacks from the total stack memory.

[0055] The amount of stack space that needs to be increased can be determined by factors such as the nested function calls of the task, the size of local variables, the CPU context storage space, and the interrupt processing site preservation. If there is enough allocatable stack memory in the RTOS to meet the needs of the target task stack, the stack space of the target task stack can be adjusted. After adjusting the stack space of the target task stack, the RTOS can update the related task stack usage and memory allocation information to ensure that the system's memory management status is accurate.

[0056] In this way, the size of the task stack in the RTOS can be effectively increased to ensure the stable operation of the task.

[0057] In some optional implementations, the above step S203 further includes: if the preset threshold of the task stack usage is less than the stack space usage of the target task stack, stop switching to the target task stack, and adjust the external device controlled by the embedded real-time operating system to a controllable state.

[0058] In this embodiment, adjusting the external device controlled by the embedded real-time operating system to a controllable state may involve shutting down the device, reducing the performance of the device, putting the device in standby mode, or performing other necessary operations to ensure that the device does not get out of control due to a task stack problem. Specifically, it can be determined based on actual project requirements, such as stopping the engine, stopping heating, or issuing an audible and visual alarm.

[0059] In this way, external devices can be kept under control, which helps protect the stability and security of the system and reduces potential damage or risks.

[0060] In the present embodiment, a device for task stack memory management is also provided, and the device is used to implement the above-mentioned embodiment and preferred implementation mode, and the description has been made no further. As used below, the term "module" can implement the combination of software and / or hardware of the predetermined function. Although the device described in the following embodiments is preferably implemented with software, the implementation of hardware, or the combination of software and hardware is also possible and conceived.

[0061] Figure 3 FIG. 1 is a schematic diagram showing a structure of a device for task stack memory management provided by an embodiment of the present invention. This embodiment provides a device for task stack memory management, such as Figure 3 As shown, including:

[0062] The initialization module 301 is used to obtain the initial number of bytes of each task stack and the starting address of each task stack when initializing the task stack, and set the initial value in each task stack to a preset value.

[0063] The switching module 302 is used to obtain the number of consecutive bytes in the target task stack with a preset value before switching to the target task stack, and determine the usage of the target task stack based on the ratio of the consecutive bytes to the initial bytes of the target task stack.

[0064] The scheduling module 303 is used to schedule tasks based on a preset threshold of task stack usage and a usage of a target task stack.

[0065] In some optional implementations, the scheduling module 303 includes:

[0066] The first scheduling unit is used to switch to the target task stack if the preset threshold of the task stack usage is greater than the stack space usage of the target task stack, and monitor the stack space usage of the target task stack during the operation of the target task stack.

[0067] The second scheduling unit is used to issue an abnormal alarm if the preset threshold of the task stack usage is equal to the stack space usage of the target task stack.

[0068] In some optional implementations, the second scheduling unit includes:

[0069] The second scheduling first subunit is used to output the identifier of the target task stack, the initial number of bytes of the target task stack and the usage of the target task stack.

[0070] In some optional implementations, the scheduling module 303 further includes:

[0071] The third scheduling unit is used to stop switching to the target task stack and jump to the safe code area if the preset threshold of the task stack usage is less than the stack space usage of the target task stack.

[0072] In some optional implementations, the scheduling module 303 further includes:

[0073] The fourth scheduling unit is used to: if the preset threshold value of the task stack usage is less than or equal to the stack space usage of the target task stack: obtain the current task stack usage of each task stack; determine the amount of stack memory that can be allocated based on the total stack memory and the current task stack usage of each task stack; obtain the increase in stack space that needs to be increased for the target task stack, and if the allocatable stack memory is greater than the increase, adjust the stack space of the target task stack based on the increase.

[0074] In some optional implementations, the scheduling module 303 further includes:

[0075] The fifth scheduling unit is used to stop switching to the target task stack if the preset threshold of the task stack usage is less than the stack space usage of the target task stack, and adjust the external device controlled by the embedded real-time operating system to a controllable state.

[0076] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.

[0077] The device for task stack memory management provided by the embodiment of the present invention can obtain the usage of the space in each task stack by marking the unused space in the task stack. Based on the comparison of the usage of the space in the target task stack with the preset threshold of the task stack usage, the task stack memory usage can be accurately obtained, the RTOS memory usage can be understood, the task stack memory can be reasonably planned, the task scheduling can be performed, the RTOS performance can be optimized, the task stack overflow can be prevented, and the stability and reliability of the RTOS system can be improved.

[0078] The device for task stack memory management in this embodiment is presented in the form of a functional unit, where the unit refers to an application specific integrated circuit (ASIC) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.

[0079] The embodiment of the present invention also provides a computer device having the above Figure 3 The device shown is used for task stack memory management.

[0080] See also Figure 4 , Figure 4 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 4As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the computer device, including instructions stored in or on the memory to display graphical information of a graphical user interface on an external input / output device (such as a display device coupled to an interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 4 A processor 10 is taken as an example.

[0081] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.

[0082] The aforementioned memory 20 stores instructions executable by at least one processor 10, so that the aforementioned at least one processor 10 executes the method shown in the above embodiment.

[0083] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0084] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.

[0085] The computer device also includes an input device 30 and an output device 40. The processor 10, the memory 20, the input device 30 and the output device 40 may be connected via a bus or other means. Figure 4 The example of connecting through bus is taken in the following.

[0086] The input device 30 can receive input digital or character information, and generate key signal input related to the user settings and function control of the computer device, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator rod, one or more mouse buttons, a trackball, a joystick, etc. The output device 40 may include a display device, an auxiliary lighting device (such as a light emitting diode) and a tactile feedback device (such as a vibration motor), etc. The above-mentioned display device includes but is not limited to a liquid crystal display, a light emitting diode, a display and a plasma display. In some optional embodiments, the display device can be a touch screen.

[0087] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.

[0088] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.

[0089] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.

Claims

1. A method for task stack memory management, characterized in that: The method comprises: When initializing the task stack, obtaining the initial number of bytes of each task stack and the starting address of each task stack, and setting the initial value in each task stack to a preset value; Before switching to the target task stack, obtaining the number of consecutive bytes in the target task stack whose value is the preset value, and determining the stack space usage of the target task stack based on the ratio of the consecutive bytes to the initial bytes of the target task stack; Task scheduling is performed based on a preset threshold value of task stack usage and the stack space usage of the target task stack.

2. The method according to claim 1, characterized in that The task scheduling is performed based on a preset threshold value of the task stack usage and the stack space usage of the target task stack, including: If the preset threshold value of the task stack usage is greater than the stack space usage of the target task stack, switch to the target task stack, and monitor the stack space usage of the target task stack during the operation of the target task stack; If the preset threshold value of the task stack usage is equal to the stack space usage of the target task stack, an abnormal alarm is issued.

3. The method according to claim 2, characterized in that If the preset threshold value of the task stack usage is equal to the stack space usage of the target task stack, an abnormal alarm is issued, including: The identifier of the target task stack, the initial number of bytes of the target task stack, and the usage of the target task stack are output.

4. The method according to claim 2, characterized in that: The method further comprises: performing task scheduling based on a preset threshold value of task stack usage and the stack space usage of the target task stack; If the preset threshold value of the task stack usage is less than the stack space usage of the target task stack, the switching to the target task stack is stopped and the process jumps to the safe code area.

5. The method according to claim 4, characterized in that The method further includes, if the preset threshold value of the task stack usage is less than or equal to the stack space usage of the target task stack: Obtaining the current task stack usage of each of the task stacks; Determining an allocatable amount of stack memory based on the total stack memory and the current task stack usage of each of the task stacks; The amount of stack space increase required for the target task stack is obtained, and if the allocatable stack memory amount is greater than the amount of increase, the stack space of the target task stack is adjusted based on the amount of increase.

6. The method according to claim 4 or 5, characterized in that: The method further comprises: performing task scheduling based on a preset threshold value of task stack usage and the stack space usage of the target task stack; If the preset threshold value of the task stack usage is less than the stack space usage of the target task stack, the switching to the target task stack is stopped, and the external device controlled by the embedded real-time operating system is adjusted to a controllable state.

7. A device for task stack memory management, characterized in that: The device comprises: An initialization module, used for obtaining the initial number of bytes of each task stack and the starting address of each task stack when initializing the task stack, and setting the initial value in each task stack to a preset value; A switching module, used for obtaining the number of consecutive bytes in the target task stack whose value is the preset value before switching to the target task stack, and determining the usage of the target task stack based on the ratio of the number of consecutive bytes to the initial number of bytes of the target task stack; The scheduling module is used to schedule tasks based on a preset threshold of task stack usage and the usage of the target task stack.

8. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the method for task stack memory management described in any one of claims 1 to 6 by executing the computer instructions.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the method for task stack memory management according to any one of claims 1 to 6.

10. A computer program product, characterized in that The method comprises computer instructions, wherein the computer instructions are used to cause a computer to execute the method for task stack memory management according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Processor with granular add immediates capability & methods

    CN104834503A

  • Task scheduling method and system and electronic equipment

    CN117806788A

  • Software Enabled Network Storage Accelerator (SENSA) - Hardware Real Time Operating System (RTOS) Optimized for Network-Storage Stack applications

    US20150254099A1

  • Method and system for providing stack memory management in real-time operating systems

    US20150277977A1

Cited By

  • Static allocation method for stack space in battery management system and battery management system

    CN119862018A