Task scheduling method and device of target operating system and storage medium
By dynamically adjusting the task status in the task scheduling method of the target operating system to ensure that high-priority tasks can be preempted and executed, the diversification and uncertainty of task scheduling in the prior art is solved, and the real-time and security of the system are improved.
Patent Information
- Application Number
- CN202411521752.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-29
- Publication Date
- 2025-02-25
AI Technical Summary
In the OS task scheduling method based on the ARMv7-M architecture, in order to ensure the frequency of task switching and the real-time system, existing methods have diversification and uncertainty, resulting in increased development and maintenance costs and increased the risk of unreliability of system operation.
Provide a task scheduling method for the target operating system, by finding the task with the highest priority in the ready task queue, and dynamically adjusting the task status according to the priority during its execution, ensuring that high-priority tasks can preempt execution.
Improves the real-time, security and flexibility of the target operating system, reduces the risk of unreliability of system operation, and reduces development and maintenance costs.
Smart Images

Figure CN119512705A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of vehicle-mounted embedded operating systems, and in particular to a task scheduling method, device and storage medium for a target operating system. Background Art
[0002] In the development process of OS task scheduling based on ARMv7-M architecture, it is essentially implemented by combining system call SVCall exception, PendSV exception and Systick exception. The common processing method is to start the highest priority task in SVCall exception, perform context switching in PendSV exception and ensure the execution of task scheduling in Systick exception.
[0003] However, from the perspective of specific implementation methods, in order to ensure the frequency of task switching and the real-time requirements of the system, for different series of chip platforms with the same kernel, and limited by the differences between different IDEs, including different compilation tool chains, the OS task scheduling implementation methods have become diversified and uncertain. This diversity and uncertainty not only leads to increased initial development and subsequent maintenance costs, but also makes it easier to increase the risk of unreliable system operation. Summary of the invention
[0004] The present application provides a task scheduling method, device and storage medium for a target operating system, which can improve the real-time performance, security and flexibility of the target operating system.
[0005] On the one hand, the present application provides a task scheduling method for a target operating system, the method comprising:
[0006] If the target operating system receives a clock interrupt request, a first interrupt task is searched in the ready task queue; the first interrupt task is a periodically scheduled task obtained based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is a task in the ready task queue other than the first interrupt task;
[0007] Scheduling the first interrupt task to start execution;
[0008] During the execution of the first interrupt task, if there is a second interrupt task with a higher priority than the first interrupt task, the state of the first interrupt task is updated to a suspended state; the second interrupt task is a scheduling task acquired in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task;
[0009] Updating the state of the second interrupt task to a running state, and scheduling the second interrupt task to start execution;
[0010] If the second interrupt task is executed, an executable task in the ready task queue is obtained; the executable task is a task in the ready task queue whose priority is only lower than the priority of the second interrupt task.
[0011] In an exemplary embodiment, if the second interrupt task is a preemptive task; after updating the state of the second interrupt task to a running state and scheduling the second interrupt task to start execution, the method further includes:
[0012] If there is a task whose priority is higher than the priority of the second interrupt task, use the task as the updated second interrupt task;
[0013] Saving the execution progress information corresponding to the second interrupt task, and updating the state of the second interrupt task to a suspended state;
[0014] Scheduling the updated second interrupt task to start execution, and monitoring and processing the stack memory information corresponding to the second interrupt task;
[0015] If the updated second interrupt task is executed completely, the state of the second interrupt task is updated to a running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task.
[0016] In an exemplary embodiment, if the second interrupt task is a non-preemptive task; after updating the state of the second interrupt task to a running state and scheduling the second interrupt task to start execution, the method further includes:
[0017] If the third interrupt task is triggered, the execution progress information corresponding to the second interrupt task is saved and processed, and the state of the second interrupt task is updated to a suspended state; the third interrupt task is the non-periodic scheduling task;
[0018] Scheduling the third interrupt task to start execution;
[0019] If the execution of the third interrupt task is completed, the state of the second interrupt task is updated to a running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task.
[0020] In an exemplary embodiment, if the target operating system receives a clock interrupt request, before searching for the first interrupt task in the ready task queue, the method further includes:
[0021] If the kernel initialization of the target operating system is completed, obtaining a plurality of real-time ready tasks in the target operating system and a priority number corresponding to each of the real-time ready tasks;
[0022] According to the priority number corresponding to each of the real-time ready tasks, the plurality of real-time ready tasks are sorted by priority to obtain the ready task queue;
[0023] Receive a fourth interrupt instruction, and search for a fourth interrupt task in the ready task queue; the fourth interrupt instruction is used to switch the target operating system to kernel mode; the fourth interrupt task is an initialization task, and the priority of the fourth interrupt task is higher than the priority of the second remaining task; the second remaining task is the task in the ready task queue other than the fourth interrupt task;
[0024] The fourth interrupt task is scheduled to start execution.
[0025] In an exemplary embodiment, after the scheduling of the fourth interrupt task starts to execute, the method further includes:
[0026] If the fourth interrupt task is executed, deleting the fourth interrupt task in the ready task queue;
[0027] Obtaining the next execution task in the ready task queue and re-using it as the second interrupt task;
[0028] Scheduling the second interrupt task to start execution;
[0029] During the execution of the second interrupt task, if the target operating system receives the clock interrupt request and the second interrupt task is a preemptive task, a task with a priority higher than that of the second interrupt task is searched in the ready task queue and is re-used as the first interrupt task;
[0030] During the execution of the second interrupt task, if the target operating system receives the clock interrupt request and the second interrupt task is a non-preemptive task, the second interrupt task is controlled to continue execution.
[0031] In an exemplary embodiment, if the updated second interrupt task is executed completely, the state of the second interrupt task is updated to a running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task, the method further includes:
[0032] If the second interrupt task is executed, calling the second interrupt interface to delete the second interrupt task in the ready task queue;
[0033] Obtain the next execution task in the ready queue task and use it as the second interrupt task again;
[0034] The second interrupt task is scheduled to start execution.
[0035] In an exemplary embodiment, if the second interrupt task is executed completely, calling the second interrupt interface to delete the second interrupt task in the ready task queue includes:
[0036] If the second interrupt task is executed, calling the second interrupt interface;
[0037] Saving the task status information corresponding to the second interrupt task, and updating the status of the second interrupt task to a suspended state;
[0038] Determining a stack overflow result corresponding to the second interrupt task according to the stack memory information corresponding to the second interrupt task;
[0039] If the stack overflow result indicates that the stack corresponding to the second interrupt task overflows, generating an error message;
[0040] The second interrupt task in the ready task queue is deleted.
[0041] On the other hand, a task scheduling device for a target operating system is provided, the device comprising:
[0042] A first interrupt task acquisition module, configured to search for a first interrupt task in a ready task queue if the target operating system receives a clock interrupt request; the first interrupt task is a periodically scheduled task acquired based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is a task in the ready task queue other than the first interrupt task;
[0043] A first interrupt task execution module, used for scheduling the first interrupt task to start execution;
[0044] A state updating module, used for updating the state of the first interrupt task to a suspended state if there is a second interrupt task with a higher priority than the first interrupt task during the execution of the first interrupt task; the second interrupt task is a scheduling task acquired in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task;
[0045] A second interrupt task execution module, used for updating the state of the second interrupt task to a running state, and scheduling the second interrupt task to start execution;
[0046] The first acquisition module is used to acquire the executable task in the ready task queue if the second interrupt task is executed; the executable task is a task in the ready task queue whose priority is only lower than the priority of the second interrupt task.
[0047] On the other hand, an electronic device is provided, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded by the processor and executes the task scheduling method of the target operating system as described above.
[0048] On the other hand, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement the task scheduling method of the target operating system as described above.
[0049] On the other hand, a computer program product or a computer program is provided, the computer program product or the computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes to implement the task scheduling method of the target operating system as described above.
[0050] The present application provides a method, device and storage medium for scheduling tasks in a target operating system, which have the following technical effects:
[0051] In this application, if the target operating system receives a clock interrupt request, the first interrupt task is searched in the ready task queue; the first interrupt task is a periodic scheduling task obtained based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is the task in the ready task queue other than the first interrupt task; the first interrupt task is scheduled to start execution; during the execution of the first interrupt task, if there is a second interrupt task with a priority higher than the priority of the first interrupt task, the state of the first interrupt task is updated to a suspended state; the second interrupt task is a scheduling task obtained in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task; the state of the second interrupt task is updated to a running state, and the second interrupt task is scheduled to start execution; if the second interrupt task is executed, the executable task in the ready task queue is obtained; the executable task is a task in the ready task queue whose priority is only lower than the priority of the second interrupt task. In this application, when the target operating system receives a clock interrupt request, it searches for the highest priority task in the ready task queue, that is, the first interrupt task, and schedules the first interrupt task to start running. When the priority of the second interrupt task is higher than that of the first interrupt task, the first interrupt task is interrupted, and the second interrupt task is preempted and executed. It can be seen that the priority of the second interrupt is higher than that of the first interrupt. After the second interrupt task is executed, it continues to obtain tasks in the ready task queue whose priority is only lower than that of the second interrupt task. By setting the priority of the second interrupt higher than that of the first interrupt, and the second interrupt operation is used to switch tasks in the ready task queue, and the first interrupt operation is used to execute periodic tasks, such a priority setting enables real-time tasks in the target operating system to be executed in real time, thereby improving the real-time performance and flexibility of the target operating system. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the technical solutions and advantages of the embodiments of this specification or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0053] Figure 1 It is a flowchart of a task scheduling method of a target operating system provided by an embodiment of this specification;
[0054] Figure 2 It is a flowchart of a task scheduling method of a target operating system provided by an embodiment of this specification;
[0055] Figure 3It is a flowchart of a task scheduling method of a target operating system provided in an embodiment of this specification;
[0056] Figure 4 It is a flowchart of a task scheduling method of a target operating system provided by an embodiment of this specification;
[0057] Figure 5 It is a flowchart of a task scheduling method of a target operating system provided in an embodiment of this specification;
[0058] Figure 6 It is a flowchart of a task scheduling method of a target operating system provided in an embodiment of this specification;
[0059] Figure 7 It is a flowchart of a task scheduling method of a target operating system provided in an embodiment of this specification;
[0060] Figure 8 It is a flowchart of a task scheduling method of a target operating system provided in an embodiment of this specification;
[0061] Fig. 9 It is a schematic diagram of a specific implementation flow of a task scheduling method for a target operating system provided in an embodiment of this specification;
[0062] Fig.10 It is a schematic diagram of a specific implementation flow of a task scheduling method for a target operating system provided in an embodiment of this specification;
[0063] Fig.11 It is a design schematic diagram of a task scheduling mechanism provided in an embodiment of this specification;
[0064] Fig.12 It is a structural diagram of a task scheduling device of a target operating system provided in an embodiment of this specification.
[0065] Fig.13 It is a structural diagram of a server of a task scheduling method for a target operating system provided in an embodiment of this specification. DETAILED DESCRIPTION
[0066] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0067] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application 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 interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0068] The following describes a task scheduling method for a target operating system of the present application. Figure 1 It is a flowchart of a task scheduling method for a target operating system provided in an embodiment of this specification. This specification provides method operation steps as described in the embodiment or flowchart, but may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the steps among many orders, and does not represent the only execution order. When the actual system or server product is executed, it can be executed in sequence or in parallel (for example, in a parallel processor or multi-threaded processing environment) according to the method shown in the embodiment or the accompanying drawings. Specifically, Figure 1 As shown, the method can be applied to embedded vehicle operating system software, and the method includes:
[0069] S101: If the target operating system receives a clock interrupt request, it searches for a first interrupt task in the ready task queue; the first interrupt task is a periodically scheduled task obtained based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is the task in the ready task queue other than the first interrupt task.
[0070] In the embodiment of this specification, the target operating system is the OS operating system of the ARM Cortex-M3 / M4 / M7 series microcontroller; when the count value of the Systick timer reaches the preset value, an interrupt request, namely a clock interrupt request, will be generated. This interrupt request will enter the interrupt handler of the target operating system, and then trigger the corresponding action. Among them, the Systick timer essentially provides a periodic interrupt signal. Therefore, the target operating system receives the clock interrupt request, which actually triggers the Systick exception, and whenever the Systick exception is triggered, the register identifier corresponding to the Systick exception will display 14, thereby regularly checking the status of the task or executing the periodic scheduling task; the Systick timer generates an interrupt request, which can be realized by the alarm Alarm and the scheduling table. In the periodic scheduling task, due to the different scheduling periods of the task, different task activation methods can be selected. For example, when the task scheduling period is 10ms or 100ms, the task cycle interval is longer, and the alarm Alarm can be selected for task activation; when the task scheduling period is 1ms, 2ms, or 3ms, the task cycle interval is shorter, and the scheduling table can be selected for task activation. After the Systick exception is triggered, the periodic scheduled task corresponding to the current time point is activated, and the periodic task is inserted into the ready task queue. The Systick exception searches for a task in the ready task queue with a priority higher than the priority of the currently executed task, i.e., the first interrupt task. Among them, the ready task queue includes multiple real-time ready tasks in the target operating system sorted by priority, so the ready task queue is actually constantly changing according to the real-time ready tasks; the first interrupt task is the task triggered by the first interrupt, i.e., the Systick exception.
[0071] In the embodiment of this specification, if the target operating system receives a clock interrupt request, before searching for the first interrupt task in the ready task queue, Figure 2 As shown, Figure 2 The following is a program flow diagram of a task scheduling method for a target operating system, wherein the method further comprises:
[0072] S201: If the kernel initialization of the target operating system is completed, obtain a plurality of real-time ready tasks in the target operating system and a priority number corresponding to each of the real-time ready tasks.
[0073] In the embodiment of this specification, when the OS operating system is started, the OS first goes through the initialization phase to implement hardware initialization, memory initialization, interrupt vector table initialization, device driver initialization and kernel initialization. Since each task carries its own priority number in the configuration phase, it is necessary to obtain the real-time ready task and its own priority number so as to subsequently construct the ready task queue, which helps to achieve the real-time response of the target operating system.
[0074] S202: According to the priority number corresponding to each of the real-time ready tasks, the multiple real-time ready tasks are sorted according to their priorities to obtain the ready task queue.
[0075] In the embodiment of this specification, assuming that the lower the priority number, the higher the priority, then according to the priority number corresponding to each real-time ready task, the real-time ready tasks are sorted by priority. Assuming that the high-priority real-time ready task is at the head of the queue, it means that the real-time ready task with the lowest priority number is at the head of the ready task queue, and the real-time ready task with the highest priority number is at the end of the ready task queue. By obtaining the ready task queue, it is helpful to realize efficient task switching and scheduling in the future, and ensure the real-time response of the target operating system.
[0076] S203: Receive a fourth interrupt instruction, and search for a fourth interrupt task in the ready task queue; the fourth interrupt instruction is used to switch the target operating system to kernel mode; the fourth interrupt task is an initialization task, and a priority of the fourth interrupt task is higher than a priority of the second remaining task; the second remaining task is a task in the ready task queue other than the fourth interrupt task.
[0077] In the embodiment of the present specification, the fourth interrupt instruction is an instruction corresponding to the fourth interrupt, the fourth interrupt is the SVCall exception, the fourth interrupt instruction is the svc instruction, after the user-mode program executes the svc instruction, it jumps to the exception vector table, and searches for the SVCall system scheduling in the exception vector table, that is, triggering the SVCall exception, and after the SVCall exception is triggered, the sequence number related to the SVCall exception in the register will be set to 12, at this time the processor state is switched from user mode to kernel mode, and the control right jumps to the SVCall exception handler address in the exception vector table, wherein the SVCall exception is the fourth interrupt. According to the triggered SVCall exception, the first task, namely the fourth interrupt task, is obtained, which is the task with the highest priority in the ready task queue. The fourth interrupt instruction ensures that the user-mode program can only enter the kernel mode under controlled conditions, thereby improving the security of the target operating system; through the ready task queue and the priority mechanism, the scheduling of tasks is ensured to be predictable, which helps to achieve the real-time response of the target operating system.
[0078] S204: Schedule the fourth interrupt task to start execution.
[0079] In the embodiment of the present specification, after the fourth interrupt task is obtained, the context of the fourth interrupt task with the highest configured priority is placed on the top of the stack, and then the process stack is switched to execute the task. The svc instruction ensures that the user-mode program can only enter the kernel mode under controlled conditions, thereby improving the security of the target operating system. The ready task queue and priority mechanism ensure that the scheduling of tasks is predictable, which helps to achieve the real-time response of the target operating system, and the initial tasks are executed in a predetermined order, ensuring the correctness and integrity of the initialization of the target operating system. By triggering the SVCall exception, the decoupling between the kernel function and the user program is achieved, thereby enhancing the modularity and extensibility of the target operating system.
[0080] In the embodiment of this specification, after the scheduling of the fourth interrupt task starts to execute, Figure 3 As shown, Figure 3 The following is a program flow diagram of a task scheduling method for a target operating system, wherein the method further comprises:
[0081] S301: If the fourth interrupt task is executed completely, the fourth interrupt task in the ready task queue is deleted.
[0082] In the embodiment of the present specification, since the fourth interrupt task is an initialization task and is only executed once, after the fourth interrupt task is executed, it is necessary to save the context information of the fourth interrupt task, including the register status, program counter, stack pointer, etc., update the status of the fourth interrupt task from the running status to the suspended status, release the resources occupied by the fourth interrupt task, including memory, stack space, device resources, etc., and remove the completed task, i.e., the fourth interrupt task, from the ready task queue.
[0083] S302: Obtain the next execution task in the ready task queue and use it as the second interrupt task again.
[0084] In the embodiment of the present specification, when the fourth interrupt task is executed, it will jump to the termination scheduling interface, that is, the TerminateTask() function interface, through which the identifier for enabling the second interrupt in the register related to the second interrupt is set to 1, and then jump to the second interrupt, that is, schedule the PendSV exception, select a new highest priority task from the ready queue as the next task to be executed, and re-use it as the second interrupt task. Among them, the second interrupt task appears many times in this specification. In fact, re-using the acquired task as the second interrupt task does not repeat any workflow. The second interrupt task in this specification is used to represent the second interrupt, that is, the task triggered by the PendSV exception.
[0085] S303: Schedule the second interrupt task to start execution.
[0086] In the embodiment of the present specification, a new task is loaded, that is, the context information of the second interrupt task is obtained, and the register state, program counter, stack pointer, etc. of the current processor are set to start executing the second interrupt task.
[0087] S304: During the execution of the second interrupt task, if the target operating system receives the clock interrupt request and the second interrupt task is a preemptive task, search for a task with a priority higher than that of the second interrupt task in the ready task queue and re-select it as the first interrupt task.
[0088] In the embodiment of the present specification, during the execution of the second interrupt task, if the second interrupt task is a preemptive task, and the target operating system receives a clock interrupt request, that is, a Systick exception is triggered, the target operating system first saves the currently executing task, that is, the context information of the second interrupt task, and the target operating system checks the ready task queue to find the task with the highest priority. If the priority of the current task, that is, the second interrupt task, is lower than the highest priority task in the ready task queue, the target operating system will perform task switching, and the target operating system will load a new task, that is, the context information of the first interrupt task, and set the state of the current processor, and execute the first interrupt task by directly calling a specific API or assembly; if the priority of the current task, that is, the second interrupt task, is higher than the highest priority task in the ready task queue, then continue to execute the second interrupt task. Among them, the first interrupt task appears multiple times in this specification, and in fact, reusing the acquired task as the first interrupt task does not repeat any workflow. The first interrupt task in this specification is used to represent the first interrupt, that is, the task triggered by the Systick exception.
[0089] S305: During the execution of the second interrupt task, if the target operating system receives the clock interrupt request and the second interrupt task is a non-preemptive task, control the second interrupt task to continue execution.
[0090] In the embodiments of the present specification, during the execution of the second interrupt task, if the second interrupt task is a non-preemptive task, and the target operating system receives a clock interrupt request, that is, a Systick exception is triggered, since the execution process is only allowed to be interrupted by a type I or type II interrupt during the execution of a non-preemptive task, even if the Systick exception is triggered, the second interrupt task will not be interrupted and will continue to execute. The task activated due to the Systick exception is inserted into the ready task queue, waiting to be scheduled later. By immediately selecting and executing a new highest priority task after the task is executed, the continuity and timeliness of task scheduling are guaranteed; by correctly releasing resources and updating task status, the stability and reliability of the target operating system are improved, and the maintainability and scalability of the target operating system are enhanced; at the same time, in preemptive tasks, by triggering task scheduling through SysTick exceptions, the needs of high-priority tasks can be quickly responded to, ensuring the real-time performance of the target operating system; and whether it is a preemptive or non-preemptive task, by releasing the resources of the completed task, the effective use of system resources is ensured, and problems such as memory leaks are avoided;
[0091] S103: Schedule the first interrupt task to start execution.
[0092] In the embodiment of this specification, the Systick exception schedules the first interrupt task to start execution by directly calling a specific API or assembly, rather than implementing it through a PendSV exception. By directly calling a specific API or assembly code to implement preemptive scheduling related to the Systick exception, the delay of the intermediate links can be reduced, the scheduling logic is simplified, the complexity of the target operating system is reduced, and the real-time response capability and overall efficiency of the target operating system are improved; at the same time, task switching is implemented using a specific assembly code, which can be appropriately adjusted on different hardware platforms to adapt to different architectural characteristics.
[0093] S105: During the execution of the first interrupt task, if there is a second interrupt task whose priority is higher than that of the first interrupt task, the state of the first interrupt task is updated to a suspended state; the second interrupt task is a scheduling task obtained in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task.
[0094] In the embodiment of the present specification, the first interrupt task is a task triggered by the Systick exception, and is a preemptive task, and the second interrupt task is a task triggered by the PendSV exception. At this time, the second interrupt task is a task with a priority higher than the priority of the first interrupt task detected in real time by the target operating system during the execution of the first interrupt task, and the second interrupt task can be a newly activated high-priority non-periodic scheduling task in the target operating system, or a periodic scheduling task that is activated but not scheduled by the Systick exception, and is inserted into the ready task queue after activation for subsequent scheduling. Since the priority of the PendSV exception is higher than the priority of the Systick exception, and the priority of the second interrupt task is higher than the priority of the first interrupt task, the second interrupt task triggers the PendSV exception to obtain the CPU usage right, realizes preemption, and the first interrupt task suspends execution, and updates the state of the first interrupt task to a suspended state. By setting the priority of the PendSV exception to be higher than the priority of the Systick exception, the execution process can be prevented from being interrupted, and the task stack needle can be avoided from being destroyed, which helps to achieve real-time response of the target operating system and quickly realize task switching.
[0095] S107: Update the state of the second interrupt task to a running state, and schedule the second interrupt task to start execution.
[0096] In the embodiment of this specification, the context information of the first interrupt task is saved, the context information of the second interrupt task is loaded, and the state of the current processor is set, that is, the state of the second interrupt task is updated to the running state, and the second interrupt task is started. Preemptive scheduling is implemented through the PendSV exception, which can quickly respond to the needs of high-priority tasks and ensure the real-time performance of the target operating system; through the correct context saving and recovery mechanism, the target operating system is ensured to remain stable during the preemptive scheduling process, thereby enhancing the security performance of the target operating system.
[0097] In the embodiment of this specification, if the second interrupt task is a preemptive task; after the state of the second interrupt task is updated to the running state and the second interrupt task is scheduled to start execution, Figure 4 As shown, Figure 4 The following is a program flow diagram of a task scheduling method for a target operating system, wherein the method further comprises:
[0098] S401: If there is a task whose priority is higher than the priority of the second interrupt task, use the task as an updated second interrupt task.
[0099] In the embodiment of the present specification, since the second interrupt task currently being executed is a preemptive task, and the target operating system will search in real time during the execution of the second interrupt task whether there is a ready task with a priority higher than the priority of the second interrupt task, the updated second interrupt task is found and can be preempted.
[0100] S402: Save the execution progress information corresponding to the second interrupt task, and update the state of the second interrupt task to a suspended state.
[0101] In the embodiment of the present specification, at this time, the target operating system triggers a PendSV exception. In the PendSV exception handler, the execution of the second interrupt task is suspended, and the current task, that is, the context information of the second interrupt task, is saved, that is, the execution progress information corresponding to the second interrupt task, including register values, stack needle values, etc. At the same time, the state of the second interrupt is updated to a suspended state.
[0102] S403: Schedule the updated second interrupt task to start execution, and monitor the stack memory information corresponding to the second interrupt task.
[0103] In an embodiment of the present specification, the context information of the updated second interrupt task is restored, including register status, program counter, stack pointer, etc.; and the preemptive scheduling has a task stack overflow monitoring function, so when the user needs to use this function, the relevant identifier can be set to 1 to enable the task stack overflow monitoring function and check the stack usage of the updated second interrupt task.
[0104] S404: If the updated second interrupt task is executed completely, update the state of the second interrupt task to a running state, and continue to execute the second interrupt task based on the execution progress information corresponding to the second interrupt task.
[0105] In the embodiment of the present specification, when the updated second interrupt task is executed, the status of the second interrupt task is updated to the running status; and in fact, each ready task in the ready task queue is assigned a bit, and whenever a ready task is executed, the bit of the task will be set to 0 to release the task. Therefore, at this time, the bit corresponding to the updated second interrupt task will be set to 0 to release the updated second interrupt task, and trigger the PendSV exception to obtain the next high-priority task in the ready task queue. Assuming that the second highest priority task is the second interrupt task at this time, since the second interrupt task was pushed into the stack when it was interrupted, it is necessary to continue to execute the second interrupt task at this time, then the second interrupt task is popped and jumped to the position that was previously interrupted. The position is determined by the execution progress information corresponding to the second interrupt task. At this time, the second interrupt task continues to be executed based on the interrupted position. Preemptive scheduling is implemented through the PendSV exception, which meets the needs of rapid response to high-priority tasks and ensures the real-time performance of the target operating system. The correct context save and restore mechanism ensures that the target operating system remains stable during preemptive scheduling. The stack overflow monitoring function prevents task crashes or system failures caused by stack overflow, thereby improving the response speed and performance of the target operating system.
[0106] In the embodiment of the present specification, if the updated second interrupt task is executed, the state of the second interrupt task is updated to the running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task, such as Figure 5 As shown, Figure 5 The following is a program flow diagram of a task scheduling method for a target operating system, wherein the method further comprises:
[0107] S501: If the second interrupt task is executed completely, calling a second interrupt interface to delete the second interrupt task in the ready task queue.
[0108] In the embodiment of the present specification, when the second interrupt task is executed, the TerminateTask() function is called at the end point of the second interrupt task, that is, the second interrupt interface is used to release the second interrupt task so as to subsequently find the next task to be executed, thereby improving the response speed and performance of the target operating system.
[0109] In the embodiment of the present specification, if the second interrupt task is executed, before calling the second interrupt interface to delete the second interrupt task in the ready task queue, the method further includes:
[0110] A process information saving sub-interface is constructed according to the preset task and the task execution process information corresponding to the preset task.
[0111] In the embodiment of the present specification, the preset task is used as an execution parameter, and a process information saving sub-interface is constructed to save process information such as the register state, program counter, and stack pointer of the preset task.
[0112] A task status change sub-interface is constructed according to the preset task and the preset task status corresponding to the preset task.
[0113] In an embodiment of the present specification, a preset task and a preset task status corresponding to the preset task are used as execution parameters, wherein the preset task status includes a running status, a suspended status or other inactive status, and a task status change sub-interface is constructed to change the status of the preset task from the status in the previous operation to the current status.
[0114] Get the second interrupt trigger sub-interface.
[0115] In the embodiment of the present specification, the second interrupt triggering sub-interface is used to trigger a PendSV exception so as to perform task switching.
[0116] The process information saving sub-interface, the task status changing sub-interface and the second interrupt triggering sub-interface are merged to obtain the second interrupt interface.
[0117] In the embodiment of this specification, the process information saving sub-interface, the task status changing sub-interface and the second interrupt triggering sub-interface are combined and repackaged to obtain the second interrupt interface to implement the end-type scheduling. This helps the target operating system to respond quickly, implement task switching, and ensure the real-time performance of the target operating system.
[0118] In the embodiment of this specification, if the second interrupt task is executed, the second interrupt interface is called to delete the second interrupt task in the ready task queue, such as Figure 6 As shown, Figure 6 A program flow diagram of a task scheduling method for a target operating system, including:
[0119] S601: If the second interrupt task is executed completely, calling the second interrupt interface.
[0120] In the embodiment of the present specification, when the second interrupt task is executed, the TerminateTask() function is called at the end point of the task to implement termination scheduling, so as to trigger the PendSV exception to perform task switching.
[0121] S602: Save the task status information corresponding to the second interrupt task, and update the status of the second interrupt task to a suspended status.
[0122] In the embodiment of the present specification, the context information of the current task is saved, including the register status, program counter, stack pointer and other information of the second interrupt task, and the status of the second interrupt task is changed to a suspended state.
[0123] S603: Determine a stack overflow result corresponding to the second interrupt task according to the stack memory information corresponding to the second interrupt task.
[0124] In the embodiment of the present specification, the stack overflow result of the second interrupt task is obtained so as to implement stack monitoring of tasks in the target operating system.
[0125] S604: If the stack overflow result indicates that the stack corresponding to the second interrupt task overflows, an error message is generated.
[0126] In the embodiment of the present specification, the stack usage of the second interrupt task is checked, and if a stack overflow is detected, an error message is generated so that the user can obtain the stack overflow information in time. At the same time, the stack pointer of the second interrupt task is reconstructed so that the context can be correctly restored when the task is restored.
[0127] S605: Deleting the second interrupt task in the ready task queue.
[0128] In the embodiment of the present specification, since the second interrupt task has been executed, the bit position corresponding to the second interrupt task in the ready task queue is set to 0, the second interrupt task is released, and the PendSV exception is triggered for subsequent task switching. Preemptive scheduling is achieved by triggering the PendSV exception, which meets the needs of rapid response to high-priority tasks, ensures the real-time performance of the target operating system, and reduces the delay of task switching; through the correct context saving and recovery mechanism, ensures that the target operating system remains stable during task termination and scheduling; checks the stack usage when the task is terminated to prevent task crashes or system failures caused by stack overflow, thereby improving the stability of the target operating system; reconstructs the stack pointer of the current task when the task is terminated to ensure that the context can be correctly restored when the task is resumed, reducing the overhead of context switching; through clear task state management and scheduling logic, the maintainability and scalability of the target operating system are enhanced.
[0129] S502: Obtain the next execution task in the ready queue tasks and use it as the second interrupt task again.
[0130] In the embodiment of the present specification, the task with the highest priority is selected from the ready task queue. Since the task is the task found by traversing the ready task queue triggered by the PendSV exception, the second interrupt task is obtained.
[0131] S503: Schedule the second interrupt task to start execution.
[0132] In the embodiment of this specification, the context information of the second interrupt task, including register status, program counter, stack pointer, etc., is restored to start executing the second interrupt task. By triggering the PendSV exception to implement preemptive scheduling, the needs of high-priority tasks can be quickly responded to, ensuring the real-time performance of the target operating system; when the task terminates, the second interrupt interface is called to implement end-type scheduling, reducing delays; through precise task switching logic, unnecessary context switching is reduced, and the overall efficiency of the target operating system is improved.
[0133] In the embodiment of this specification, if the second interrupt task is a non-preemptive task; the state of the second interrupt task is updated to the running state, and the second interrupt task is scheduled to start execution, such as Figure 7 As shown, Figure 7 The following is a program flow diagram of a task scheduling method for a target operating system, wherein the method further comprises:
[0134] S701: If the third interrupt task is triggered, the execution progress information corresponding to the second interrupt task is saved and the state of the second interrupt task is updated to a suspended state; the third interrupt task is the non-periodic scheduling task.
[0135] In the embodiment of the present specification, the third interrupt task is a task triggered by the third interrupt. The third interrupt can be a Class I interrupt or a Class II interrupt, and the priority of the Class II interrupt is lower than the priority of the Systick exception. The priority of the Class I interrupt is not required, and it can be higher or lower than the priority of the Systick exception, which can be freely configured by the user. If the second interrupt task is a non-preemptive task, it is not allowed to be preempted by other tasks during the execution of the task, but it is allowed to be interrupted by a Class I or Class II interrupt. After the interrupt processing is completed, the execution continues from the interrupted task flow. Therefore, during the execution of the second interrupt task, if the third interrupt is triggered, the target operating system enters the interrupt handler. At the beginning of the interrupt handler, the context information of the second interrupt task is saved, including the register status, program counter, stack pointer, etc., and the status of the second interrupt task is updated to the suspended state.
[0136] S702: Schedule the third interrupt task to start execution.
[0137] In the embodiment of the present specification, the third interrupt task related to the third interrupt is executed. If the third interrupt is a type I interrupt, which has a high priority and is usually used to handle urgent and time-sensitive tasks, the third interrupt task is a task for real-time data acquisition, a task for handling urgent events, and a time-sensitive task; if the third interrupt is a type II interrupt, which has a lower priority than a type I interrupt and is used to handle various conventional interrupt requests, the third interrupt task is a task for device driving or a task for external event processing.
[0138] S703: If the execution of the third interrupt task is completed, the state of the second interrupt task is updated to a running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task.
[0139] In an embodiment of the present specification, after the third interrupt task is executed, the context information of the second interrupt task is restored, and the task is continued from where it was interrupted. The interrupted place is determined based on the execution progress information corresponding to the second interrupt task, including the stack pointer of the second interrupt task, which is used to determine the address corresponding to the continued execution of the second interrupt task. The third interrupt task can be used to preempt preemptive tasks, so that the target operating system can respond quickly to external events or hardware requests to ensure the real-time performance of the target operating system; and the third interrupt task is inserted during the task execution process to ensure that the interrupt request can be processed in time and reduce delays; through the correct context saving and recovery mechanism, it is ensured that the task can continue to execute from the interrupted place after the interrupt processing is completed, so as to maintain the stability of the target operating system;
[0140] S109: If the second interrupt task is executed, obtain an executable task in the ready task queue; the executable task is a task in the ready task queue whose priority is only lower than the priority of the second interrupt task.
[0141] In the embodiment of this specification, when the second interrupt task is executed, the PendSV exception is triggered to trigger the end-type scheduling, thereby obtaining the executable task in the ready task queue, that is, the task in the ready task queue whose priority is only lower than the second interrupt task, and switching to execute the executable task. The real-time switching of tasks in the target operating system is realized through the end-type scheduling, thereby improving the real-time performance of the target operating system.
[0142] In an exemplary embodiment, Figure 8 As shown, Figure 8 A flowchart of a task scheduling method for a target operating system provided in an embodiment of this specification includes:
[0143] S801: Obtain nuclear dynamic information.
[0144] In the embodiment of the present specification, after the operating system OS is started and various objects are initialized, the context information of the current task is saved, including register status, stack pointer, etc., so as to restore the task status of the user space after the system call ends.
[0145] S802: Obtain the context of the current highest priority task.
[0146] In the embodiments of this specification, Fig.11 , as shown, Fig.11 The schematic diagram of the task scheduling mechanism design provided for this specification shows that when the OS is initialized, the SVCall exception is triggered to start the first task, so the highest priority task currently available is found. If a higher priority task is in the ready state, the context information of the highest priority task is obtained, including the stack pointer, program counter, etc., and the task will be scheduled to start execution later.
[0147] S803: triggering a system call exception.
[0148] In the embodiment of the present specification, the system enters the interrupt vector table by executing the svc instruction, thereby triggering a system call exception, namely, an SVCall exception. At this time, the processor switches from user mode to kernel mode and enters kernel space.
[0149] S804: Schedule out to execute the highest priority task.
[0150] In the embodiment of the present specification, the highest priority task is scheduled to start execution. During this process, the kernel will restore the context information of the highest priority task, including the stack pointer, program counter, etc., place the context of the current highest priority task on the top of the stack, and then switch to the process stack to implement task scheduling.
[0151] In this embodiment, through system calls, user space applications can request kernel services in a secure environment, avoiding direct access to kernel data and functions and protecting the stability of the target operating system. During the system call exception handling process, the kernel will save and restore the context information of the task to ensure that the task remains in a consistent state before and after switching. The kernel can manage resources such as files and memory through system calls to ensure the effective use and security of resources.
[0152] In an exemplary embodiment, Fig. 9 As shown, Fig. 9 A flowchart of a task scheduling method for a target operating system provided in an embodiment of this specification includes:
[0153] S901: Triggering a suspended service call.
[0154] In the embodiments of this specification, Fig.11 , as shown, Fig.11 The schematic diagram of the task scheduling mechanism design provided in this manual assumes that the first task is completed. At this time, the first task is released through the TerminateTask() function interface and the PendSV exception is triggered to schedule the next highest priority task. Therefore, when the task needs to be switched or the task execution is completed and the termination scheduling is performed, the suspend service call will be triggered, that is, the PendSV exception.
[0155] S902: Determine whether it is preemptive scheduling. If it is not preemptive scheduling, go to S907;
[0156] In the embodiments of this specification, different scheduling strategies are determined by judging whether the currently executed task is a fully preemptive task or a non-preemptive task, wherein the task attribute, i.e., a fully preemptive task or a non-preemptive task, is determined based on static allocation.
[0157] S903: Save the scene.
[0158] In the embodiments of the present specification, when the currently executing task is a fully preemptive task, preemptive scheduling is performed at this time. In fact, the preemptive scheduling process will be executed when and only when the priority of the newly activated task is higher than the priority of the currently running task, and the task scheduling point insertion timing includes the following four: when the current task is being executed, there is a higher priority task among the activated tasks, and preemptive scheduling is performed, and such task activation can be activated by the application layer interface API function to enter the ready state Ready; when the task scheduling is implemented using a scheduling table, preemptive scheduling is performed, and such task activation can be activated by the alarm Alarm or the scheduling table Schedule to enter the ready state Ready; when the second type of interrupt exits, preemptive scheduling is performed; when the high priority task is in the process of setting / waiting or releasing resources, preemptive scheduling is performed. When preemptive scheduling is required, the currently executing task needs to be saved on-site, that is, the context of the currently executing task needs to be maintained, including but not limited to the register value, stack needle value, and timer value of the currently executing task. At the same time, if the task needs to run, the task status will be updated to the running status Running
[0159] S904: Determine whether stack monitoring is required. If not, proceed to S909;
[0160] In the embodiments of this specification, preemptive scheduling includes a task stack overflow monitoring function. The stack monitoring function can be configured according to user needs, and there is an identifier for controlling whether the stack monitoring processing function is enabled or not.
[0161] S905: Preempt the task to join the team.
[0162] In the embodiments of the present specification, when the stack monitoring and processing function is needed, the relevant identifier is enabled, the stack monitoring and processing function is turned on, and the stack is monitored in time to see if it overflows. When the stack overflows, error processing is performed and the user is notified in time. At the same time, a preemptive task with a higher priority than the currently executing task is inserted into the ready task queue, and the task obtains priority execution rights.
[0163] S906: Find the highest priority task and jump to execute it.
[0164] In the embodiment of the present specification, the task with the highest priority in the ready task queue is searched at this time. In fact, since the currently executing task was the task with the highest priority in the ready task queue before execution, and now, due to the insertion of the preempting task, the task with the highest priority should be the preempting task, so the preempting task is jumped to execute.
[0165] S907: Update nuclear dynamic information.
[0166] In the embodiments of the present specification, when the currently executing task is a non-preemptive task and ends its normal execution, or when the linked task is being processed, or when the currently executing task enters the time or memory protection HOOK and terminates the current task, ChainTask will be executed in these three cases, and the PendSV exception will be triggered to achieve terminal scheduling, and the kernel dynamic information will be updated, including but not limited to recording whether the task is being executed, whether it is suspended, etc., recording the priority of each task to determine which task should be executed first, recording the number of time slices remaining for each task to prevent a task from monopolizing the CPU for a long time, and maintaining the ready task queue, which is helpful for the subsequent scheduling of the task to be normally scheduled.
[0167] S908: Stack needle reconstruction and initialization.
[0168] In the embodiments of the present specification, since the currently executing task has been completed and each task has its own independent stack space for storing temporary variables, function parameters and other information, when the task is switched, it is necessary to ensure that the stack pointer correctly points to the stack space of the new task in order to correctly execute the new task. Therefore, it is necessary to save the stack pointer of the currently executing task before switching the task so that it can be restored later, and set the stack pointer to the stack space address of the new task. If necessary, initialize the stack space of the new task, such as clearing the contents of the stack space, to ensure that there is no data confusion when switching tasks, thereby ensuring the normal execution of the task.
[0169] S909: Find the highest priority task and jump to execute it.
[0170] In the embodiment of the present specification, in the end-type scheduling, the kernel dynamic information is updated, the stack needle of the currently ended task is initialized, the stack needle is reconstructed, and after the context processing is completed, the next highest priority task is searched and jumped for execution.
[0171] This embodiment provides a fast task switching mechanism for both preemptive scheduling and terminal scheduling by triggering the PendSV exception, and the preemptive scheduling logic processing covers context processing, task stack overflow monitoring, and preemptive queuing and scheduling of high-priority tasks. The terminal scheduling logic processing covers context processing, reconstruction of the stack pointer of the currently running task, task stack overflow monitoring, and high-priority task scheduling. The action processing of task activation and termination is processed using specific strategies, so that the real-time system can respond to external events quickly. For example, the Rtos operating system can decide when to switch tasks based on task priority or other strategies, and the PendSV exception is applicable to a variety of processor architectures, improving the versatility and portability of the system. At the same time, by updating the core dynamic information, tasks are better managed and scheduled to ensure that the system can run as expected. Through stack pointer reconstruction and initialization, it can be ensured that there will be no data confusion when switching tasks, thereby ensuring the normal execution of tasks and ensuring the real-time and flexibility of task switching in the target operating system.
[0172] In an exemplary embodiment, Fig.10 As shown, Fig.10 A flowchart of a task scheduling method for a target operating system provided in an embodiment of this specification includes:
[0173] S1001: Trigger system timer interrupt.
[0174] In the embodiments of this specification, Fig.11 , as shown, Fig.11 The schematic diagram of the task scheduling mechanism design provided in this specification, when in the task scheduling process, if the Systick exception is triggered, a new task will be activated and the next task to be executed will be determined. Therefore, when the timer overflows, a system timer interrupt will be generated, that is, a Systick exception. Specifically, it can include the alarm Alarm activating the task or the schedule table activating the task when the timer arrives.
[0175] S1002: Save the scene.
[0176] In the embodiment of the present specification, the priority of the configuration PendSV exception is higher than the priority of the Systick exception, and the priority of the Systick exception is higher than the priority of all Class II interrupts. The Systick exception monitors the timing of inserting the task scheduling point, that is, compares the priority of the currently running task with the highest priority task in the ready queue to schedule the task. At this time, if there is a task in the ready task queue with a priority higher than the priority of the currently executing task, the set event is processed or the task is activated. If the currently executing task is a fully preemptive task, the high-priority task will preempt the currently executing task. Therefore, it is necessary to save the register status and other related information of the currently executing task for later recovery.
[0177] S1003: Update kernel dynamic information.
[0178] In the embodiment of the present specification, after the context processing is completed, the dynamic information related to the Systick exception, such as the timer status, alarm information, etc., is updated.
[0179] S1004: The alarm and the action execution object processing of each overflow point in the scheduling table.
[0180] In the embodiments of this specification, when a scheduling table is used to implement task scheduling, periodic task scheduling is implemented. A task may need to be scheduled once every 1ms, 5ms, 10ms, or 1000ms. Short-period task scheduling, such as 1ms or 5ms intervals, is activated through the scheduling table, and long-period task scheduling is activated through the alarm.
[0181] S1005: Schedule out to execute the highest priority task.
[0182] In the embodiment of the present specification, at this time, the task with the highest priority in the ready task queue is selected for scheduling and execution.
[0183] In this embodiment, when the Systick timer reaches the preset time interval, the Systick exception is triggered, and the system automatically saves the relevant registers and context information of the current task for subsequent recovery and use, updates the kernel status information, which may include but is not limited to task status, resource allocation, etc., and performs corresponding actions according to the settings of the Alarm and the schedule table, including task activation, event setting, callback function execution or timer processing, etc., performs task scheduling, selects and executes the task with the highest priority in the current ready queue, and then the Systick exception processing is completed. Among them, the Systick exception is not only used for simple context processing, but also includes more complex task scheduling functions, such as monitoring the timing of task scheduling point insertion, so as to achieve a more flexible and efficient scheduling strategy; at the same time, the priority of the Systick exception is designed to be higher than all the second-class interrupts, which helps to ensure the security and reliability of the target operating system, especially in application scenarios with high real-time and security requirements; users can adjust the priority of the Systick exception according to actual needs, providing greater flexibility and adaptability; through the fine management of the alarm Alarm and the schedule table, more accurate task scheduling and event processing are achieved, and the overall performance and user experience of the target operating system are improved.
[0184] This specification also provides a task scheduling device for the target operating system, such as Fig.12 As shown, the device comprises:
[0185] The first interrupt task acquisition module 1201 is used for searching the first interrupt task in the ready task queue if the target operating system receives a clock interrupt request; the first interrupt task is a periodically scheduled task acquired based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is the task in the ready task queue other than the first interrupt task;
[0186] A first interrupt task execution module 1202, used for scheduling the first interrupt task to start execution;
[0187] The state updating module 1203 is used for updating the state of the first interrupt task to a suspended state if there is a second interrupt task with a higher priority than the first interrupt task during the execution of the first interrupt task; the second interrupt task is a scheduling task acquired in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task;
[0188] The second interrupt task execution module 1204 is used to update the state of the second interrupt task to the running state, and schedule the second interrupt task to start execution;
[0189] The first acquisition module 1205 is used to acquire the executable tasks in the ready task queue if the second interrupt task is executed completely; the executable tasks are the tasks in the ready task queue whose priority is only lower than the priority of the second interrupt task.
[0190] In some embodiments, the apparatus further comprises:
[0191] The updated second interrupt task module is used to use the task as the updated second interrupt task if there is a task with a priority higher than the priority of the second interrupt task.
[0192] The second interrupt task suspension module is used to save and process the execution progress information corresponding to the second interrupt task, and update the state of the second interrupt task to a suspended state.
[0193] The monitoring module is used to schedule the updated second interrupt task to start execution and monitor the stack memory information corresponding to the second interrupt task.
[0194] The first execution module is used to update the state of the second interrupt task to a running state if the updated second interrupt task is executed completely, and continue to execute the second interrupt task based on the execution progress information corresponding to the second interrupt task.
[0195] In some embodiments, the apparatus further comprises:
[0196] The third interrupt task triggering module is used to save and process the execution progress information corresponding to the second interrupt task and update the state of the second interrupt task to a suspended state if the third interrupt task is triggered; the third interrupt task is the non-periodic scheduling task.
[0197] The third interrupt task execution module is used to schedule the third interrupt task to start execution.
[0198] The second execution module is used to update the state of the second interrupt task to a running state if the execution of the third interrupt task is completed, and continue to execute the second interrupt task based on the execution progress information corresponding to the second interrupt task.
[0199] In some embodiments, the apparatus further comprises:
[0200] The second acquisition module is used to acquire a plurality of real-time ready tasks in the target operating system and a priority number corresponding to each of the real-time ready tasks if the kernel initialization of the target operating system is completed.
[0201] The ready task queue acquisition module is used to sort the multiple real-time ready tasks according to the priority sequence number corresponding to each real-time ready task to obtain the ready task queue.
[0202] A fourth interrupt task search module is used to receive a fourth interrupt instruction and search for a fourth interrupt task in the ready task queue; the fourth interrupt instruction is used to switch the target operating system to kernel mode; the fourth interrupt task is an initialization task, and the priority of the fourth interrupt task is higher than the priority of the second remaining task; the second remaining task is the task in the ready task queue other than the fourth interrupt task.
[0203] The fourth interrupt task execution module is used to schedule the fourth interrupt task to start execution.
[0204] In some embodiments, the apparatus further comprises:
[0205] The fourth interrupt task releasing module is used to delete the fourth interrupt task in the ready task queue if the fourth interrupt task is executed.
[0206] The third acquisition module is used to acquire the next execution task in the ready task queue and use it as the second interrupt task again.
[0207] The third execution module is used to schedule the second interrupt task to start execution.
[0208] A preemption module is used to search for a task with a higher priority than the second interrupt task in the ready task queue and re-use it as the first interrupt task if the target operating system receives the clock interrupt request and the second interrupt task is a preemptive task during the execution of the second interrupt task.
[0209] The preemption prohibiting module is used to control the second interrupt task to continue executing if the target operating system receives the clock interrupt request and the second interrupt task is a preemption prohibiting task during the execution of the second interrupt task.
[0210] In some embodiments, the apparatus further comprises:
[0211] The deleting module is used to call the second interrupt interface to delete the second interrupt task in the ready task queue if the second interrupt task is executed.
[0212] The fourth acquisition module is used to acquire the next execution task in the ready queue task and use it as the second interrupt task again.
[0213] The fourth execution module is used to schedule the second interrupt task to start execution.
[0214] In some embodiments, the deletion module further includes:
[0215] The second interrupt interface calling submodule is used to call the second interrupt interface if the second interrupt task is executed.
[0216] The saving submodule is used to save the task status information corresponding to the second interrupt task and update the status of the second interrupt task to a suspended state.
[0217] The stack overflow result determination submodule is used to determine the stack overflow result corresponding to the second interrupt task according to the stack memory information corresponding to the second interrupt task.
[0218] The error information generating submodule is used to generate error information if the stack overflow result indicates a stack overflow corresponding to the second interrupt task.
[0219] The deleting submodule is used to delete the second interrupt task in the ready task queue.
[0220] The device and method embodiments in the described device embodiments are based on the same inventive concept.
[0221] An embodiment of the present specification provides an automotive electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement a task scheduling method for a target operating system as provided in the above method embodiment.
[0222] An embodiment of the present application also provides a computer storage medium, which can be set in a terminal to store at least one instruction or at least one program related to a task scheduling method for a target operating system in a method embodiment. The at least one instruction or at least one program is loaded and executed by the processor to implement the task scheduling method for the target operating system provided in the above method embodiment.
[0223] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes to implement the task scheduling method of the target operating system provided in the above method embodiment.
[0224] The memory described in the embodiments of this specification can be used to store software programs and modules, and the processor executes various functional applications and data processing by running the software programs and modules stored in the memory. The memory may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, application programs required for functions, etc.; the data storage area may store data created according to the use of the device, etc. In addition, the memory may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory may also include a memory controller to provide the processor with access to the memory.
[0225] The target operating system task scheduling method embodiment provided in the embodiments of this specification can be executed in a mobile terminal, a computer terminal, a server or a similar computing device. Taking running on a server as an example, Fig.13 1 is a hardware structure diagram of a server of a task scheduling method for a target operating system provided in an embodiment of this specification. Fig.13 As shown, the server 1300 may have relatively large differences due to different configurations or performances, and may include one or more central processing units (CPU) 1310 (the central processing unit 1310 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 1330 for storing data, and one or more storage media 1320 (such as one or more mass storage devices) for storing application programs 1323 or data 1322. Among them, the memory 1330 and the storage medium 1320 can be short-term storage or permanent storage. The program stored in the storage medium 1320 may include one or more modules, each of which may include a series of instruction operations on the server. Furthermore, the central processing unit 1310 can be configured to communicate with the storage medium 1320 and execute a series of instruction operations in the storage medium 1320 on the server 1300. The server 1300 may also include one or more power supplies 1360, one or more wired or wireless network interfaces 1350, one or more input and output interfaces 1340, and / or one or more operating systems 1321, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0226] The input / output interface 1340 may be used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the server 1300. In one example, the input / output interface 1340 includes a network adapter (Network Interface Controller, NIC), which may be connected to other network devices through a base station so as to communicate with the Internet. In one example, the input / output interface 1340 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0227] It can be understood by those skilled in the art that Fig.13 The structure shown is for illustration only and does not limit the structure of the above electronic device. Fig.13 More or fewer components as shown, or with Fig.13 Different configurations are shown.
[0228] It can be seen from the embodiments of the task scheduling method, device and storage medium of the target operating system provided by the present application that if the target operating system receives a clock interrupt request, the present application searches for a first interrupt task in the ready task queue; the first interrupt task is a periodic scheduling task obtained based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is a task in the ready task queue other than the first interrupt task; the first interrupt task is scheduled to start execution; during the execution of the first interrupt task, if there is a second interrupt task with a priority higher than the priority of the first interrupt task, the state of the first interrupt task is updated to a suspended state; the second interrupt task is a scheduling task obtained in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task; the state of the second interrupt task is updated to a running state, and the second interrupt task is scheduled to start execution; if the second interrupt task is executed, the executable task in the ready task queue is obtained; the executable task is a task in the ready task queue whose priority is only lower than the priority of the second interrupt task. The logic processing timing inside the PendSV exception and Systick exception API encapsulated in this application is relatively fixed, ensuring the efficiency and consistency of task scheduling; the frequency of task switching and the real-time requirements of the system are guaranteed through the new logic processing mechanism; the priority of the Systick exception is designed to be higher than all Class II interrupts, and the user can adjust the priority of the Systick exception according to actual needs, providing greater flexibility and ensuring the security and reliability of the target operating system; in the task scheduling process, specific functions are added to the calls of PendSV exception and Systick exception, which improves the robustness of the target operating system and reduces potential errors and failures; and the encapsulated API can adapt to different series of chip platforms and different IDE environments, improving the adaptability and flexibility of the target operating system; at the same time, the processing logic combined with the SVCall exception, PendSV exception and Systick exception can be encapsulated twice, avoiding the differences in the implementation of the AUTOSAR OS task scheduling mechanism under different IDEs, greatly improving the reusability and portability of the code, and reducing the AUTOSAR of different series of chip platforms with the same kernel. It reduces the development cost of OS, simplifies the development process, and reduces the risk of unreliable implementation methods of diverse task scheduling in different IDEs. It facilitates the subsequent OS task scheduling development of different series of chip platforms with the same architecture, ensuring the consistency and reliability of development.
[0229] It should be noted that the above sequence of the embodiments of this specification is for description only and does not represent the advantages and disadvantages of the embodiments. The above describes specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0230] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0231] A person skilled in the art will appreciate that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0232] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A task scheduling method for a target operating system, characterized in that: The method comprises: If the target operating system receives a clock interrupt request, a first interrupt task is searched in the ready task queue; the first interrupt task is a periodically scheduled task obtained based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is a task in the ready task queue other than the first interrupt task; Scheduling the first interrupt task to start execution; During the execution of the first interrupt task, if there is a second interrupt task with a higher priority than the first interrupt task, the state of the first interrupt task is updated to a suspended state; the second interrupt task is a scheduling task acquired in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task; Updating the state of the second interrupt task to a running state, and scheduling the second interrupt task to start execution; If the second interrupt task is executed, an executable task in the ready task queue is obtained; the executable task is a task in the ready task queue whose priority is only lower than the priority of the second interrupt task.
2. The method according to claim 1, characterized in that If the second interrupt task is a preemptive task; after updating the state of the second interrupt task to a running state and scheduling the second interrupt task to start execution, the method further includes: If there is a task whose priority is higher than the priority of the second interrupt task, use the task as the updated second interrupt task; Saving the execution progress information corresponding to the second interrupt task, and updating the state of the second interrupt task to a suspended state; Scheduling the updated second interrupt task to start execution, and monitoring and processing the stack memory information corresponding to the second interrupt task; If the updated second interrupt task is executed completely, the state of the second interrupt task is updated to a running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task.
3. The method according to claim 1, characterized in that If the second interrupt task is a non-preemptive task; after updating the state of the second interrupt task to a running state and scheduling the second interrupt task to start execution, the method further includes: If the third interrupt task is triggered, the execution progress information corresponding to the second interrupt task is saved and processed, and the state of the second interrupt task is updated to a suspended state; the third interrupt task is the non-periodic scheduling task; Scheduling the third interrupt task to start execution; If the execution of the third interrupt task is completed, the state of the second interrupt task is updated to a running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task.
4. The method according to claim 1, characterized in that: If the target operating system receives a clock interrupt request, before searching for the first interrupt task in the ready task queue, the method further includes: If the kernel initialization of the target operating system is completed, obtaining a plurality of real-time ready tasks in the target operating system and a priority number corresponding to each of the real-time ready tasks; According to the priority number corresponding to each of the real-time ready tasks, the plurality of real-time ready tasks are sorted by priority to obtain the ready task queue; Receive a fourth interrupt instruction, and search for a fourth interrupt task in the ready task queue; the fourth interrupt instruction is used to switch the target operating system to kernel mode; the fourth interrupt task is an initialization task, and the priority of the fourth interrupt task is higher than the priority of the second remaining task; the second remaining task is the task in the ready task queue other than the fourth interrupt task; The fourth interrupt task is scheduled to start execution.
5. The method according to claim 4, characterized in that After the scheduling of the fourth interrupt task starts to execute, the method further includes: If the fourth interrupt task is executed, deleting the fourth interrupt task in the ready task queue; Obtaining the next execution task in the ready task queue and re-using it as the second interrupt task; Scheduling the second interrupt task to start execution; During the execution of the second interrupt task, if the target operating system receives the clock interrupt request and the second interrupt task is a preemptive task, a task with a priority higher than that of the second interrupt task is searched in the ready task queue and is re-used as the first interrupt task; During the execution of the second interrupt task, if the target operating system receives the clock interrupt request and the second interrupt task is a non-preemptive task, the second interrupt task is controlled to continue execution.
6. The method according to claim 2, characterized in that If the updated second interrupt task is executed completely, the state of the second interrupt task is updated to a running state, and the second interrupt task is continued to be executed based on the execution progress information corresponding to the second interrupt task, the method further includes: If the second interrupt task is executed, calling the second interrupt interface to delete the second interrupt task in the ready task queue; Obtain the next execution task in the ready queue task and use it as the second interrupt task again; The second interrupt task is scheduled to start execution.
7. The method according to claim 6, characterized in that If the second interrupt task is executed completely, calling the second interrupt interface to delete the second interrupt task in the ready task queue includes: If the second interrupt task is executed, calling the second interrupt interface; Saving the task status information corresponding to the second interrupt task, and updating the status of the second interrupt task to a suspended state; Determining a stack overflow result corresponding to the second interrupt task according to the stack memory information corresponding to the second interrupt task; If the stack overflow result indicates that the stack corresponding to the second interrupt task overflows, generating error information; The second interrupt task in the ready task queue is deleted.
8. A task scheduling device for a target operating system, characterized in that: The device comprises: A first interrupt task acquisition module, configured to search for a first interrupt task in a ready task queue if the target operating system receives a clock interrupt request; the first interrupt task is a periodically scheduled task acquired based on the clock interrupt request, and the priority of the first interrupt task is higher than the priority of the first remaining task; the first remaining task is a task in the ready task queue other than the first interrupt task; A first interrupt task execution module, used for scheduling the first interrupt task to start execution; A state updating module, used for updating the state of the first interrupt task to a suspended state if there is a second interrupt task with a higher priority than the first interrupt task during the execution of the first interrupt task; the second interrupt task is a scheduling task acquired in real time; the scheduling task is the periodic scheduling task or the non-periodic scheduling task; A second interrupt task execution module, used for updating the state of the second interrupt task to a running state, and scheduling the second interrupt task to start execution; The first acquisition module is used to acquire the executable task in the ready task queue if the second interrupt task is executed; the executable task is a task in the ready task queue whose priority is only lower than the priority of the second interrupt task.
9. An electronic device, characterized in that: The device includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded by the processor and executes the task scheduling method of the target operating system as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction or at least one program, and the at least one instruction or at least one program is loaded and executed by the processor to implement the task scheduling method of the target operating system as described in any one of claims 1-7.
Citation Information
Cited By
Cortex-M85 kernel-based multi-core operating system synchronous starting method
CN120144213A