Task scheduling method and device based on process preemption, electronic equipment and storage medium

By adopting a process preemption-based task scheduling method in a multi-task operating system, the problem of task scheduling relies on fixed priority and time slice allocation in the existing technology, resulting in slow response speed and low task efficiency, and high priority is achieved Timely processing of tasks and system stability and reliability.

CN119473537APending Publication Date: 2025-02-18CHINA SOUTHERN POWER GRID COMPANY
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202411503541.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

In the prior art, task scheduling methods rely on fixed priority and time slice allocation, resulting in high priority tasks being blocked by low priority tasks for a long time, affecting the system response speed and overall performance.

Method used

Using a task scheduling method based on process preemption, when receiving a task that needs to be executed through the target process, determine the scheduling priority and execution time slice of the task, and interrupt its execution when the priority is higher than the current task, and record context information for recovery. .

Benefits of technology

Ensure that high-priority tasks are processed in a timely manner, improve the real-time and response speed of the system, ensure the continuity and consistency of tasks when resuming execution, and ensure the stability and reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119473537A_ABST
    Figure CN119473537A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a task scheduling method and device based on process preemption, electronic equipment and a storage medium, and the method comprises the steps: under the condition that a first task needing to be executed through a target process is received, determining a first scheduling priority and an execution time slice of the target task, and executing the first scheduling priority and the execution time slice of the target task; obtaining a second scheduling priority of a second task being executed by the target process; and when the first scheduling priority is higher than the second scheduling priority, interrupting the second task, recording context information of the second task, and executing the first task through the target process, so that the first task with high priority can be preferentially processed, the real-time performance and the response speed of the system are improved, and the user experience is improved. And the context information of the interrupted second task is recorded, so that the continuity and the consistency when the tasks are recovered to be executed are ensured, and the stability and the reliability of the system are ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the technical field of computer operating system scheduling, and in particular to a task scheduling method, device, electronic device and storage medium based on process preemption. Background Art

[0002] In a multitasking operating system, the management of priorities and execution time slices of different tasks is the key to ensure efficient operation of the system.

[0003] Task scheduling methods in related technologies often rely on fixed priorities and time slice allocations, which may cause high-priority tasks to be blocked by low-priority tasks for a long time, thereby affecting the response speed and overall performance of the system. Summary of the invention

[0004] The embodiments of the present invention provide a task scheduling method, device, electronic device and storage medium based on process preemption, so as to realize flexible adjustment of scheduling priority and execution time slice according to actual requirements of the task.

[0005] In a first aspect, an embodiment of the present invention provides a task scheduling method based on process preemption, the method comprising:

[0006] In case of receiving a first task that needs to be executed by a target process, determining a first scheduling priority and an execution time slice of the target task, and obtaining a second scheduling priority of a second task being executed by the target process;

[0007] In a case where the first scheduling priority is higher than the second scheduling priority, the second task is interrupted, context information of the second task is recorded, and the first task is executed through the target process.

[0008] In a second aspect, an embodiment of the present invention further provides a task scheduling device based on process preemption, the device comprising:

[0009] A task receiving module, configured to, upon receiving a first task that needs to be executed by a target process, determine a first scheduling priority and an execution time slice of the target task, and obtain a second scheduling priority of a second task being executed by the target process;

[0010] A task scheduling module is used to interrupt the second task, record the context information of the second task, and execute the first task through the target process when the first scheduling priority is higher than the second scheduling priority.

[0011] In a third aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:

[0012] one or more processors;

[0013] a storage device for storing one or more programs,

[0014] When the one or more programs are executed by the one or more processors, the one or more processors implement the task scheduling method based on process preemption provided by any embodiment of the present invention.

[0015] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the task scheduling method based on process preemption provided by any embodiment of the present invention.

[0016] In a fifth aspect, an embodiment of the present invention further provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the task scheduling method based on process preemption provided by any embodiment of the present invention.

[0017] The technical solution of the embodiment of the present invention, first, by determining the first scheduling priority and execution time slice of the target task when receiving the first task that needs to be executed by the target process, and obtaining the second scheduling priority of the second task being executed by the target process, multiple tasks can be effectively managed and scheduled; then, when the first scheduling priority is higher than the second scheduling priority, the second task is interrupted, the context information of the second task is recorded, and the first task is executed by the target process, which helps to ensure that the high-priority first task is processed in time, solves the problems of relying on fixed priority and time slice allocation, slow response speed and low task efficiency in the related technology, can ensure that the high-priority first task is processed first, improve the real-time and response speed of the system, and record the context information of the interrupted second task, ensure the continuity and consistency when the task resumes execution, and ensure the stability and reliability of the system.

[0018] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the following briefly introduces the drawings required to describe the embodiments. Obviously, the drawings introduced are only drawings of a part of the embodiments to be described in the present invention, rather than all the drawings. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0020] Figure 1 A flowchart of a task scheduling method based on process preemption provided in the first embodiment of the present invention;

[0021] Figure 2 A schematic diagram of the structure of a task scheduling device based on process preemption provided in Embodiment 2 of the present invention;

[0022] Figure 3 This is a schematic diagram of the structure of an electronic device provided in Embodiment 1 of the present invention. DETAILED DESCRIPTION

[0023] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0024] It should also be noted that, for ease of description, only the part relevant to the present invention but not all content is shown in the accompanying drawings. It should be mentioned before discussing exemplary embodiments in more detail that some exemplary embodiments are described as processing or methods depicted as flow charts. Although the flow chart describes each operation (or step) as sequential processing, many operations therein can be implemented in parallel, concurrently or simultaneously. In addition, the order of each operation can be rearranged. When its operation is completed, the processing can be terminated, but it can also have additional steps not included in the accompanying drawings. The processing can correspond to methods, functions, procedures, subroutines, subprograms, etc.

[0025] Embodiment 1

[0026] Figure 1 A flow chart of a task scheduling method based on process preemption provided in the first embodiment of the present invention. This embodiment can be applied to a multi-tasking operating system that needs to dynamically adjust task priorities and resource allocation to ensure timely execution of high-priority tasks. The method can be executed by a task scheduling device based on process preemption, which can be implemented by software and / or hardware and can be configured in a terminal and / or server to implement the task scheduling method based on process preemption in the embodiment of the present invention.

[0027] like Figure 1 As shown, the method of this embodiment may specifically include:

[0028] S110. When a first task that needs to be executed by a target process is received, a first scheduling priority and an execution time slice of the first task are determined, and a second scheduling priority of a second task being executed by the target process is obtained.

[0029] The target process can be understood as a program instance currently operating in the operating system. The target process may include one or more threads, each of which performs different tasks. The first task can be understood as a new task to be assigned to the target process for execution. The first task can be generated according to a user request, a system event, or the interaction of other processes. The first scheduling priority can be understood as the priority assigned to the first task, which is used to determine the execution order of the first task relative to other tasks. It can be understood that in a multi-tasking operating system, high-priority tasks usually obtain processor resources before low-priority tasks. The execution time slice can be understood as the time allocated by the operating system to each process, which is used to limit the time that the process continuously occupies the processor. Exemplarily, after the execution time slice of a process is used up, even if it has not been completed, it will be suspended to give other waiting processes a chance to execute. The second task can be understood as the task currently being executed by the target process. It can be understood that in a multi-tasking environment, a target process can process multiple tasks at the same time, but from the perspective of the processor's processing, at any given moment, a processor can only execute one task. The second scheduling priority can be understood as the priority of the second task, which, similar to the first scheduling priority, affects the execution order of the second task in the target process.

[0030] Based on the above scheme, optionally, determining the first scheduling priority and execution time slice of the target task includes: obtaining execution task information corresponding to the first task, and determining the first scheduling priority and execution time slice of the target task according to the execution task information.

[0031] The execution task information may be understood as various attributes and data information associated with the first task. Exemplarily, the execution task information may include at least one of a task identifier, a task priority, an execution time limit, an urgency, a dependency, and resource requirement information. The task identifier may be understood as an identifier for each task, which is used to distinguish different tasks in the target process. The task identifier may be a number, a string, or a tag in other forms. The task identifier helps to accurately track and manage each task. The task priority may be understood as a measure of the importance and urgency of the task, which may be expressed as a numerical value. It is understood that a high-priority task will be given priority in obtaining processor resources during scheduling. The task priority may be set automatically by the system, or may be set manually by a user or an application, which is not limited here. The execution time limit may be understood as a time limit within which the first task must be completed before a certain time. It is understood that for real-time or application processes with strict time requirements, the execution time limit is an important measurement parameter, and tasks that exceed the execution time limit may cause system performance degradation or functional failure. The urgency may be understood as another measure of the importance and urgency of the task, which is similar to the task priority, and emphasizes the immediacy of the task. Tasks with high urgency usually need to be processed as soon as possible. The dependency relationship can be understood as the relationship between the first task and other tasks, that is, the first task may need to wait for other tasks to complete before it can start execution. The management of dependency relationships helps to ensure that the first task is executed in the correct order and avoids task execution failure or delay due to dependency errors. The resource requirement information can be understood as the various system resources required by the first task during execution. The resource requirement information may include but is not limited to processor time, memory, disk space, and network bandwidth. The resource requirement information helps the scheduler to reasonably allocate resources to ensure that the first task can be executed smoothly.

[0032] The above scheme, by obtaining the execution task information corresponding to the first task, can more accurately determine the scheduling priority and execution time slice of the target task, which not only improves the efficiency and accuracy of task scheduling, but also ensures that key tasks can be completed in time, thereby improving the overall performance and response speed of the system and optimizing resource utilization.

[0033] Based on the above scheme, optionally, after determining the first scheduling priority and execution time slice of the target task, and obtaining the second scheduling priority of the second task being executed by the target process, it also includes: when the first scheduling priority is lower than or equal to the second scheduling priority, obtaining a task list corresponding to the target process; obtaining the third scheduling priority of the third task, and adding the first task to the task list according to the first scheduling priority and the third scheduling priority.

[0034] Among them, the task list can be understood as a collection of all tasks to be executed in the target process. The task list can be arranged in order of priority, which helps the scheduler to determine the tasks to be executed based on the task information in the task list. The task list is used to store the third task waiting to be executed by the target process. The third task can be understood as a task that already exists in the task list. It can be understood that before adding the first task to the task list, it is necessary to check the priorities of other tasks in the task list to ensure the orderliness of the task list. The third scheduling priority can be understood as the priority of the third task. The third scheduling priority is used to compare with the first scheduling priority of the first task, which helps the scheduler determine the position of the first task in the task list.

[0035] In the above scheme, when the priority of the first task is lower than or equal to that of the second task, by obtaining the task list of the target process and inserting the first task into the appropriate position according to the priorities of the first task and the third task, it is possible to ensure that the task list is arranged in order according to priority, which not only improves the efficiency and accuracy of task scheduling, but also ensures that high-priority tasks can be executed in a timely manner, thereby improving the overall performance and response speed of the system and optimizing resource utilization.

[0036] S120. When the first scheduling priority is higher than the second scheduling priority, interrupt the second task, record context information of the second task, and execute the first task through the target process.

[0037] The context information may be understood as the relevant information that needs to be saved and restored when the task is interrupted, so that the task can continue to execute after the interruption. The context information may include but is not limited to stack status, memory status, and call status.

[0038] In an optional implementation, when it is detected that the first scheduling priority of the first task is higher than the second scheduling priority of the second task currently being executed, the execution of the second task will be interrupted; when the second task is interrupted, the context information of the second task will be saved. When the second task is interrupted and the context information is recorded, the processor resources will be allocated to the first task, and the first task will be executed through the target process.

[0039] The above scheme, by interrupting and recording the context information of the second task and executing the first task when the first scheduling priority is higher than the second scheduling priority, can ensure that high-priority tasks are processed in a timely manner, improve the responsiveness and real-time performance of the system, and not only optimize resource utilization but also enhance the overall performance of the system.

[0040] Based on the above scheme, optionally, after interrupting the second task and recording the context information of the second task, it also includes: when the first task is completed within the execution time slice corresponding to the first task, executing the second task according to the remaining execution time slice of the second task based on the context information of the second task.

[0041] An optional implementation manner includes detecting the execution status of a first task and determining whether the first task is completed within an allocated execution time slice; if the first task is completed within an allocated execution time slice, saving the execution result of the first task for subsequent processing or recording; restoring the state of a second task from previously saved context information, including a stack state, a memory state, and a call state, etc.; calculating the remaining execution time slice of the second task before being interrupted by subtracting the execution time slice already used by the second task; reallocating processor resources to the second task, and continuing to execute the second task according to the calculated remaining execution time slice.

[0042] The above scheme ensures that the first high-priority task is processed in a timely manner, and after the high-priority task is completed, the low-priority task can continue to execute from the interruption point, thereby maintaining the continuity of tasks and the stability of the system. This not only improves the responsiveness and efficiency of the system, but also ensures the fairness of task scheduling and the effective use of resources.

[0043] Based on the above scheme, optionally, after interrupting the second task and recording the context information of the second task, it also includes: when the first task is not completed within the execution time slice corresponding to the first task and no task higher than the first scheduling priority to be executed by the target process is detected, an overtime time slice is allocated to the first task, and the first task is executed according to the overtime time slice.

[0044] The overtime time slice can be understood as the additional execution time allocated by the system for the first task that is not completed within the allocated execution time slice. The overtime time slice allows the first task to continue to execute until it is completed or preempted by a task with a higher priority.

[0045] An optional implementation manner detects the execution status of the first task and determines whether the first task is completed within the allocated execution time slice; if the first task is not completed within the allocated execution time slice and if it is checked that there is no other task in the target process whose priority is higher than the first scheduling priority of the first task, allocates an overtime time slice for the first task and continues to execute the first task according to the allocated overtime time slice.

[0046] For example, suppose there is a task A, and the initially allocated execution time slice is 10 time units. Task A fails to complete within 10 time units, and it is detected that there are no other tasks with a priority higher than the first scheduling priority of the first task. In this case, an overtime time slice, such as an overtime time slice of 5 time units, can be allocated to task A. Task A will continue to execute these 5 time units until it is completed or preempted by a higher priority task again.

[0047] On the basis of the above scheme, optionally, the task scheduling method for process preemption also includes: when all tasks that need to be completed by the target process are completed according to the execution time slice corresponding to the task, the task completion status corresponding to each task is determined separately, and the task completion status is fed back to the requesting end of the task.

[0048] The task completion status can be understood as the status information of each task after execution, which is used to evaluate the execution status and results of the task. Specifically, the task completion status may include but is not limited to whether the task is successfully completed, the time of completion and result data, etc. The requesting end can be understood as the party that initiates the task request. Exemplarily, the requesting end may include but is not limited to the user end, application or system component, etc. It is understandable that the requesting end needs to determine the task completion status in order to perform subsequent processing or decision-making, etc.

[0049] The above solution can ensure that the execution status of all tasks is accurately recorded and fed back, which not only helps the requesting end to understand the execution status of the task in a timely manner and make corresponding decisions and processing, but also ensures the efficient operation and reliability of the system.

[0050] On the basis of the above scheme, optionally, the process preemptive task scheduling method further includes: when all tasks that need to be executed by the target process are completed according to the execution time slice corresponding to the task, releasing the task processing resources allocated to the target process.

[0051] The task processing resources may be understood as various system resources allocated to the target process, including but not limited to processor time, memory, disk space, and network bandwidth.

[0052] The above scheme can optimize resource utilization, improve performance, enhance stability, avoid resource waste, and ensure efficient operation of the system by releasing the resources allocated to the target process after all tasks are executed.

[0053] Based on the above solution, optionally, the task scheduling method for process preemption also includes:

[0054] Before executing the first task through the target process, task processing resources are reserved to cope with sudden high-priority task demands.

[0055] The technical solution of this embodiment, first, by determining the first scheduling priority and execution time slice of the target task when receiving the first task that needs to be executed by the target process, and obtaining the second scheduling priority of the second task being executed by the target process, multiple tasks can be effectively managed and scheduled; then, in a case where the first scheduling priority is higher than the second scheduling priority, the second task is interrupted, the context information of the second task is recorded, and the first task is executed by the target process, which helps to ensure that the high-priority first task is processed in time, solves the problems of relying on fixed priority and time slice allocation, slow response speed and low task efficiency in the related technology, can ensure that the high-priority first task is processed first, improves the real-time and response speed of the system, and records the context information of the interrupted second task, ensures the continuity and consistency when the task resumes execution, and ensures the stability and reliability of the system.

[0056] Embodiment 2

[0057] Figure 2 The structure diagram of a task scheduling device based on process preemption provided in the second embodiment of the present invention is shown in FIG. The task scheduling device based on process preemption provided in this embodiment can be implemented by software and / or hardware, and can be configured in a terminal and / or a server to implement the task scheduling method based on process preemption in the embodiment of the present invention. The device can specifically include: a task receiving module 210 and a task scheduling module 220.

[0058] Among them, the task receiving module 210 is used to determine the first scheduling priority and execution time slice of the target task when receiving the first task that needs to be executed through the target process, and to obtain the second scheduling priority of the second task being executed by the target process; the task scheduling module 220 is used to interrupt the second task when the first scheduling priority is higher than the second scheduling priority, record the context information of the second task, and execute the first task through the target process.

[0059] The technical solution implemented in the present invention can effectively manage and schedule multiple tasks by determining the first scheduling priority and execution time slice of the target task and obtaining the second scheduling priority of the second task being executed by the target process through the task receiving module 210 when the first scheduling priority is received and the second scheduling priority of the second task being executed by the target process; then, by interrupting the second task and recording the context information of the second task when the first scheduling priority is higher than the second scheduling priority through the task scheduling module 220, and executing the first task through the target process, which helps to ensure that the high-priority first task is processed in time, solves the problems of relying on fixed priority and time slice allocation, slow response speed and low task efficiency in the related technology, can ensure that the high-priority first task is processed first, improves the real-time and response speed of the system, and records the context information of the interrupted second task, ensures the continuity and consistency when the task resumes execution, and ensures the stability and reliability of the system.

[0060] Based on any optional technical solution in the embodiments of the present invention, optionally, the task receiving module includes: an execution time slice determination submodule.

[0061] Among them, the execution time slice determination submodule is used to obtain the execution task information corresponding to the first task, and determine the first scheduling priority and execution time slice of the target task according to the execution task information; wherein, the execution task information includes at least one of the task identification, task priority, execution time limit, urgency, dependency and resource requirement information.

[0062] On the basis of any optional technical solution in the embodiments of the present invention, optionally, the task scheduling device based on process preemption further includes: a task list acquisition module and a task list adding module.

[0063] Among them, the task list acquisition module is used to obtain the task list corresponding to the target process after determining the first scheduling priority and execution time slice of the target task and obtaining the second scheduling priority of the second task being executed by the target process, when the first scheduling priority is lower than or equal to the second scheduling priority, wherein the task list is used to store the third task waiting to be executed by the target process; the task list adding module obtains the third scheduling priority of the third task, and adds the first task to the task list according to the first scheduling priority and the third scheduling priority.

[0064] On the basis of any optional technical solution in the embodiments of the present invention, optionally, the task scheduling device based on process preemption further includes: a second task execution module.

[0065] Among them, the second task execution module is used to execute the second task according to the remaining execution time slice of the second task according to the context information of the second task after interrupting the second task and recording the context information of the second task, when the first task is completed within the time slice corresponding to the first task.

[0066] On the basis of any optional technical solution in the embodiments of the present invention, optionally, the task scheduling device based on process preemption further includes: a first task execution module.

[0067] Among them, the first task execution module is used to allocate an overtime time slice to the first task after interrupting the second task and recording the context information of the second task, and execute the first task according to the overtime time slice if the first task has not been completed within the time slice corresponding to the first task and no task higher than the first scheduling priority to be executed by the target process is detected.

[0068] On the basis of any optional technical solution in the embodiments of the present invention, optionally, the task scheduling device based on process preemption further includes: a task completion status feedback module.

[0069] Among them, the task completion status feedback module is used to determine the task completion status corresponding to each task respectively when all tasks that need to pass the target process are executed according to the execution time slice corresponding to the task, and feedback the task completion status to the request end of the task.

[0070] On the basis of any optional technical solution in the embodiments of the present invention, optionally, the task scheduling device based on process preemption further includes: a task processing resource releasing module.

[0071] The task processing resource releasing module is used to release the task processing resources allocated to the target process when all tasks that need to be executed by the target process are completed according to the execution time slices corresponding to the tasks.

[0072] The above-mentioned device can execute the task scheduling method based on process preemption provided by any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0073] Embodiment 3

[0074] Figure 3 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present invention. Figure 3 A block diagram of an exemplary electronic device 12 suitable for use in implementing embodiments of the present invention is shown. Figure 3The electronic device 12 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0075] like Figure 3 As shown, the electronic device 12 is in the form of a general purpose computing device. The components of the electronic device 12 may include, but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 that connects various system components (including the system memory 28 and the processing unit 16).

[0076] Bus 18 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.

[0077] The electronic device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 12, including volatile and non-volatile media, removable and non-removable media.

[0078] The system memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. The electronic device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 34 may be used to read and write non-removable, non-volatile magnetic media ( Figure 3 not shown, usually called a "hard drive"). Although Figure 3 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 18 via one or more data medium interfaces. The system memory 28 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present invention.

[0079] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in system memory 28, such program modules 42 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 42 generally perform the functions and / or methods of the embodiments described herein.

[0080] The electronic device 12 may also communicate with one or more external devices 14 (e.g., keyboards, pointing devices, displays 24, etc.), one or more devices that enable a user to interact with the electronic device 12, and / or any device that enables the electronic device 12 to communicate with one or more other computing devices (e.g., network cards, modems, etc.). Such communication may be performed through an input / output (I / O) interface 22. Furthermore, the electronic device 12 may also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 20. Figure 3 As shown, the network adapter 20 communicates with other modules of the electronic device 12 via the bus 18. It should be understood that although Figure 3 Not shown, other hardware and / or software modules may be used in conjunction with the electronic device 12, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0081] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing a task scheduling method based on process preemption provided in an embodiment of the present invention.

[0082] Embodiment 4

[0083] Embodiment 4 of the present invention further provides a storage medium including computer executable instructions, wherein the computer executable instructions are used to execute a task scheduling method based on process preemption when executed by a computer processor, the method comprising:

[0084] In case of receiving a first task that needs to be executed by a target process, determining a first scheduling priority and an execution time slice of the first task, and obtaining a second scheduling priority of a second task being executed by the target process;

[0085] In a case where the first scheduling priority is higher than the second scheduling priority, the second task is interrupted, context information of the second task is recorded, and the first task is executed through the target process.

[0086] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0087] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0088] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0089] Computer program code for performing the operation of embodiments of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0090] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A task scheduling method based on process preemption, characterized in that: include: In case of receiving a first task that needs to be executed by a target process, determining a first scheduling priority and an execution time slice of the first task, and obtaining a second scheduling priority of a second task being executed by the target process; In a case where the first scheduling priority is higher than the second scheduling priority, the second task is interrupted, context information of the second task is recorded, and the first task is executed through the target process.

2. The method according to claim 1, characterized in that The determining of the first scheduling priority and execution time slice of the target task includes: Obtain execution task information corresponding to the first task, and determine the first scheduling priority and execution time slice of the target task based on the execution task information; wherein the execution task information includes at least one of task identification, task priority, execution time limit, urgency, dependency, and resource requirement information.

3. The method according to claim 1, characterized in that After determining the first scheduling priority and execution time slice of the target task, and obtaining the second scheduling priority of the second task being executed by the target process, the method further includes: When the first scheduling priority is lower than or equal to the second scheduling priority, obtaining a task list corresponding to the target process, wherein the task list is used to store a third task waiting to be executed by the target process; A third scheduling priority of the third task is obtained, and the first task is added to the task list according to the first scheduling priority and the third scheduling priority.

4. The method according to claim 1, characterized in that After interrupting the second task and recording the context information of the second task, the method further includes: When the first task is completed within the execution time slice corresponding to the first task, the second task is executed according to the remaining execution time slice of the second task according to the context information of the second task.

5. The method according to claim 1, characterized in that: After interrupting the second task and recording the context information of the second task, the method further includes: When the first task is not completely executed within the execution time slice corresponding to the first task and no task with a higher scheduling priority than the first scheduling priority to be executed by the target process is detected, an overtime time slice is allocated to the first task and the first task is executed according to the overtime time slice.

6. The method according to claim 1, characterized in that Also includes: When all tasks that need to pass through the target process are completed according to the execution time slices corresponding to the tasks, the task completion status corresponding to each task is determined respectively, and the task completion status is fed back to the requesting end of the task.

7. The method according to claim 1, characterized in that Also includes: When all tasks that need to be processed by the target process are completed according to the execution time slices corresponding to the tasks, the task processing resources allocated to the target process are released.

8. A task scheduling device based on process preemption, characterized in that: include: A task receiving module, configured to, upon receiving a first task that needs to be executed by a target process, determine a first scheduling priority and an execution time slice of the target task, and obtain a second scheduling priority of a second task being executed by the target process; A task scheduling module is used to interrupt the second task, record the context information of the second task, and execute the first task through the target process when the first scheduling priority is higher than the second scheduling priority.

9. An electronic device, characterized in that: The electronic device comprises: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the task scheduling method based on process preemption as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the task scheduling method based on process preemption as described in any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Design method and system capable of nesting DSR priorities

    CN119883574A

  • Scheduling method and device of satellite communication terminal, equipment and medium

    CN120110486A

  • Preemption management method and device, equipment, storage medium and program product

    CN120510017A

  • Interrupt processing method, processor, chip, storage medium and program product

    CN121233251A