CN114510327A - Method and device for dynamically adjusting priority - Google Patents

Method and device for dynamically adjusting priority Download PDF

Info

Publication number
CN114510327A
CN114510327A CN202210024812.4A CN202210024812A CN114510327A CN 114510327 A CN114510327 A CN 114510327A CN 202210024812 A CN202210024812 A CN 202210024812A CN 114510327 A CN114510327 A CN 114510327A
Authority
CN
China
Prior art keywords
task
priority
target resource
resource
chain table
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210024812.4A
Other languages
Chinese (zh)
Other versions
CN114510327B (en
Inventor
秦民
孙炳彤
苏伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Automotive Innovation Co Ltd
Original Assignee
China Automotive Innovation Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Automotive Innovation Co Ltd filed Critical China Automotive Innovation Co Ltd
Priority to CN202210024812.4A priority Critical patent/CN114510327B/en
Publication of CN114510327A publication Critical patent/CN114510327A/en
Application granted granted Critical
Publication of CN114510327B publication Critical patent/CN114510327B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5011Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
    • G06F9/5022Mechanisms to release resources

Abstract

The invention relates to a method and a device for dynamically adjusting priority, wherein the method comprises the following steps: when a first task sends a request for acquiring a target resource, judging whether the first task sends the request for acquiring the target resource for the first time; if so, acquiring the task priority of the first task, the dynamic priority of the target resource and a second task occupying the target resource currently; when the task priority of the first task is higher than the dynamic priority of the target resource, setting the dynamic priority of the target resource as the task priority of the first task; adding the first task into a task chain table of the target resource, and adding the target resource into a resource chain table of the first task; and adjusting the task priority of the second task occupying the target resource to be the dynamic priority of the target resource. By temporarily increasing the task priority of the task occupying the resources to the dynamic priority of the target resources, the task is ensured to have enough priority to be preferentially operated so as to release the target resources as soon as possible, and the priority inversion is avoided.

Description

Method and device for dynamically adjusting priority
Technical Field
The present invention relates to the field of operating system technologies, and in particular, to a method and an apparatus for dynamically adjusting priority.
Background
Before each job is input into the computer, it is assigned a priority according to certain requirements. For example, the priority of the program is specified according to the important property of the program, and then the computer determines the priority of processing each program according to the priority of each job program, and even in the process of processing, the program with higher priority can be allowed to interrupt the program with lower priority, that is, if the priority of the process to be run is higher than that of the process running, the system can forcibly deprive the CPU of the process running, and the process with higher priority is allowed to run first.
The operating system may have a problem of priority reversal during running, for example, there are three priority tasks a, B, and C, where a has the highest priority, B has the lowest priority, and C has the lowest priority. When a low-priority task C preempts a resource D, if a high-priority task A wants to acquire the resource D, the high-priority task A can acquire the resource D only after the task C releases the resource D, at the moment, an intermediate-priority task B is scheduled to run, does not need the resource, but has higher priority than the lowest-priority task C, so the intermediate-priority task B can be executed, and the condition that the intermediate-priority task B is executed earlier than the high-priority task A occurs at the moment, namely, the priority inversion occurs. The task with lower priority occupies the shared resource for a long time, so that the process applying for the resource with the highest priority is always in a waiting state, at the moment, other tasks with higher priority than the task occupying the resource but lower priority than the process waiting for the resource can obtain the use right of the processor and end before the process in the waiting state with the highest priority, the phenomenon is called priority inversion, the priority inversion can cause the task with high priority not to run in time, and a real-time system can cause fatal problems in some cases.
Therefore, it is desirable to provide a priority dynamic adjustment method that can avoid priority inversion and can dynamically adjust task priorities to solve the above technical problems.
Disclosure of Invention
In order to solve the above technical problem, the present invention provides a method for dynamically adjusting priority. The method solves the technical problems that in the prior art, because the tasks with lower priorities occupy the shared resources for a long time, the tasks with higher priorities than the tasks occupying the resources but lower priorities than the processes waiting for the resources obtain the use right of the processor, the tasks are finished before the processes in the waiting state with the highest priorities, and the task scheduling time is uncertain, so that system crash is possibly caused.
The technical effects of the invention are realized as follows:
a method of dynamic priority adjustment, the method comprising:
when a first task sends a request for acquiring a target resource, judging whether the first task sends the request for acquiring the target resource for the first time;
when a first task sends a request for acquiring a target resource for the first time, acquiring the task priority of the first task, the dynamic priority of the target resource and a second task occupying the target resource at present;
when the task priority of the first task is higher than the dynamic priority of the target resource, setting the dynamic priority of the target resource as the task priority of the first task;
adding the first task into a task chain table of the target resource, and adding the target resource into a resource chain table of the first task;
and adjusting the task priority of the second task occupying the target resource to be the dynamic priority of the target resource so as to ensure that the second task occupying the target resource runs preferentially to release the target resource. The task priority of the task occupying the resources is temporarily improved to the dynamic priority of the target resources, the task is guaranteed to have enough priority to be preferentially operated so as to release the target resources as soon as possible, and the problem of the prior art that the task with lower priority occupies the shared resources for a long time, so that other tasks with higher priority than the task occupying the resources and lower priority than the task waiting for the resources obtain the use right of the processor, and the tasks are finished before the task with the highest priority in the waiting state, the phenomenon of priority inversion occurs, the task scheduling time is uncertain, and further the system crash is possibly caused is solved.
Further, the task priority of the second task occupying the target resource is adjusted to the dynamic priority of the target resource, so that the second task occupying the target resource preferentially runs to release the target resource, and then the method comprises the following steps:
and when the second task finishes running and releases the target resource, the task priority of the second task is restored to the task priority before the second task is adjusted.
Further, the first task issues a request to obtain the target resource, previously comprising:
acquiring all resources in a processing system;
and creating dynamic priority and a task linked list which are in one-to-one correspondence with each resource according to all the resources, wherein the task linked list comprises all tasks needing to use the corresponding resources, and all the tasks are arranged in the task linked list from high to low according to the corresponding task priority. The dynamic priority of the resources is dynamically adjusted along with the establishment and the termination of the tasks by setting a dynamic priority for each resource, so that the task priority of the task needing to use the corresponding resource can be temporarily improved to the dynamic priority of the resource during the period of using the resource, the task occupying the resource has enough priority to preferentially run so as to release the resource as soon as possible, and the reversal of the priority is avoided.
Further, adding the first task to the task chain table of the target resource includes:
acquiring task priorities of other tasks in a task chain table of the target resource;
and adding the first task into the task chain table of the target resource according to the task priority of the first task and the task priorities of other tasks in the target resource.
Further, the first task issues a request to obtain the target resource, previously comprising:
when a new task is created, creating a resource linked list which is in one-to-one correspondence with the task according to the task, wherein the resource linked list comprises all resources needed to be used by the task. By creating the resource linked lists corresponding to the tasks one to one, after the tasks are finished, the resource linked lists required to be used by the tasks can be traversed, and therefore the tasks are deleted from the task linked lists corresponding to each resource in the resource linked lists.
Further, the task priority of the second task occupying the target resource is adjusted to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource, and then the method comprises the following steps:
when the second task is finished, traversing a resource linked list of the second task;
acquiring all resources contained in the second task according to the resource linked list of the second task;
and deleting the second task from the task linked list corresponding to all the resources.
Further, deleting the second task from the task chain table corresponding to all the resources, and then:
judging whether the task priority corresponding to the second task is the highest priority in an original task chain table of the target resource, wherein the original task chain table is a task chain table when the second task runs preferentially;
if so, the task priority of the task with the highest task priority in the current task chain table of the target resource is obtained and is given to the target resource, so that the new dynamic priority corresponding to the target resource is the task priority of the task with the highest task priority in the current task chain table. By setting a task linked list for each resource and arranging the tasks needing to use the corresponding resources in the task linked list according to the sequence of the task priorities, after the task occupying the resources at present is finished, if the finished task is the highest task priority, the task linked list of the resources can be traversed to obtain a new task with the highest task priority, and the task priority of the task is given to the dynamic priority of the resources.
Further, when the task priority of the first task is lower than the dynamic priority of the target resource, the first task is directly added into the task chain table of the target resource, and the target resource is added into the resource chain table of the first task.
Further, when the first task does not send a request for acquiring the target resource for the first time, and when the target resource is in an idle state, the task priority of the first task is adjusted to be the dynamic priority of the target resource, and the target resource is directly used for running the first task; or when the target resource is occupied by the second task, the task priorities of the first task and the second task are adjusted to be the dynamic priorities of the target resource, and the second task runs by using the target resource preferentially.
In addition, a device for dynamically adjusting priority is also provided, the device comprising:
a first task request judgment module: the first task is used for judging whether to send a request for obtaining the target resource for the first time when the first task sends the request for obtaining the target resource;
a task priority acquisition module: the task priority acquiring system is used for acquiring the task priority of a first task, the dynamic priority of a target resource and a second task occupying the target resource at present when the first task sends a request for acquiring the target resource for the first time;
the dynamic priority setting module: the task priority setting module is used for setting the dynamic priority of the target resource as the task priority of the first task when the task priority of the first task is higher than the dynamic priority of the target resource;
a task chain table creation module: the system comprises a task chain table, a resource chain table and a resource chain table, wherein the task chain table is used for adding a first task to a target resource and adding the target resource to the resource chain table of the first task;
a priority adjustment module: and the task priority of the second task occupying the target resource is adjusted to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource.
As described above, the present invention has the following advantageous effects:
1) the task priority of the task occupying the resources is temporarily improved to the dynamic priority of the target resources, the task is guaranteed to have enough priority to be preferentially operated so as to release the target resources as soon as possible, and the problem of the prior art that the task with lower priority occupies the shared resources for a long time, so that other tasks with higher priority than the task occupying the resources and lower priority than the task waiting for the resources obtain the use right of the processor, and the tasks are finished before the task with the highest priority in the waiting state, the phenomenon of priority inversion occurs, the task scheduling time is uncertain, and further the system crash is possibly caused is solved.
2) The dynamic priority of the resources is dynamically adjusted along with the establishment and the termination of the task by setting a dynamic priority for each resource, so that the task priority of the task needing to use the corresponding resource can be temporarily improved to the dynamic priority of the resource during the period of using the resource, the task occupying the resource has enough priority to preferentially run to release the resource as soon as possible, and the reversal of the priority is avoided.
3) By setting a task linked list for each resource and arranging the tasks needing to use the corresponding resources in the task linked list according to the sequence of the task priorities, after the task occupying the resources at present is finished, if the finished task is the highest task priority, the task linked list of the resources can be traversed to obtain a new task with the highest task priority, and the task priority of the task is given to the dynamic priority of the resources.
4) By creating the resource linked lists corresponding to the tasks one to one, after the task occupying the resource at present is finished, the resource linked list required to be used by the task can be traversed, and the task is deleted from the task linked list corresponding to each resource in the resource linked list.
Drawings
In order to more clearly illustrate the technical solution of the present invention, the drawings used in the description of the embodiment or the prior art will be briefly described below. It is obvious that the drawings in the following description are only some embodiments of the invention, and that for a person skilled in the art it is also possible to derive other drawings from these drawings without inventive effort.
Fig. 1 is a flowchart of a method for dynamically adjusting priority according to an embodiment of the present disclosure;
fig. 2 is a flowchart of steps performed after task priorities of second tasks occupying target resources are adjusted to dynamic priorities of the target resources, so that the second tasks occupying the target resources preferentially run to release the target resources according to an embodiment of the present disclosure;
fig. 3 is a flowchart of steps after a second task is deleted from a task chain table corresponding to all resources according to an embodiment of the present specification;
fig. 4 is a schematic structural diagram of a priority dynamic adjustment apparatus according to an embodiment of the present disclosure.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be obtained by a person skilled in the art without making any creative effort based on the embodiments in the present invention, belong to the protection scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used is interchangeable under appropriate circumstances such that the embodiments of the invention described herein are capable of operation in sequences other than those illustrated or described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example 1:
as shown in fig. 1, an embodiment of the present specification provides a method for dynamically adjusting priority, where the method includes:
s100: when a first task sends a request for acquiring a target resource, judging whether the first task sends the request for acquiring the target resource for the first time;
in this embodiment, the real-time operating system schedules the tasks according to the priority levels of the tasks, and preferably deactivates a task scheduler that executes the task with the highest priority level among all the tasks and is in a ready state, so as to execute the task.
S200: when a first task sends a request for acquiring a target resource for the first time, acquiring the task priority of the first task, the dynamic priority of the target resource and a second task occupying the target resource at present;
in a specific embodiment, the step S200, when the first task first sends a request for obtaining the target resource, obtains the task priority of the first task, the dynamic priority of the target resource, and the second task currently occupying the target resource, and includes:
acquiring all resources in a processing system;
creating a dynamic priority and a task linked list which are in one-to-one correspondence with each resource according to all the resources, wherein the task linked list comprises all tasks needing to use the corresponding resources, and all the tasks are arranged in the task linked list from high to low according to the corresponding task priorities;
and creating a resource linked list corresponding to the tasks one by one according to the tasks, wherein the resource linked list comprises all resources required to be used by the tasks.
Specifically, when each task is created, a corresponding resource linked list is maintained, resources in the resource linked list are all resources required to be used for executing the task, and meanwhile, the task is created with task priority, and the real-time operating system determines the sequence of processing each task according to the task priority of each task.
Specifically, a corresponding dynamic priority and a task chain table are set in the resource structure of each resource, and in the task chain table, the task with the high task priority is arranged in front of the task chain table. The resource response mode is that which task runs first, the resource is applied for using the resource first, and the resource is occupied by which task; once the task acquires the resource, even if a task with a higher task priority applies for using the resource later, the task fails to acquire the resource, is blocked in the process of acquiring the resource, and releases the resource after waiting for the task which has acquired the resource to use the resource.
S300: when the task priority of the first task is higher than the dynamic priority of the target resource, setting the dynamic priority of the target resource as the task priority of the first task;
in particular, the dynamic priority of the resource changes dynamically as the task is created. When the resource is in an idle state, a request for acquiring a certain resource is sent by a task, the task priority of the task is compared with the dynamic priority of the resource, when the task priority of the task is higher than the dynamic priority of the resource, the dynamic priority of the resource is set as the task priority of the task, and the task is placed at the forefront of a task chain table, namely the task is taken as the task to use the resource; when the task priority of the task is lower than the dynamic priority of the resource, the task is added to the task chain table of the resource according to the task priority, and the resource can be used only after the task arranged in the task chain table before the task uses the resource.
The specific principle is explained as that when each task sends a request for acquiring a certain resource for the first time, the task priority of the task is compared with the dynamic priority of the resource, and the two situations are divided into two situations:
in the first case: if the task priority is higher than the dynamic priority of the resource, setting the dynamic priority of the resource as the task priority, and simultaneously putting the task into a task chain table of the resource to be sequenced according to the priority of the task, wherein the task with the high task priority is arranged in front of the task chain table; and places the resource in the task's resource chain table. Step 300 is consistent with this scenario.
A second case; and if the task priority of the first task is lower than the dynamic priority of the target resource, directly adding the first task into the task chain table of the target resource, and adding the target resource into the resource chain table of the first task.
The purpose of comparison is to keep the dynamic priority of the resource consistent with the task priority of the task with the highest task priority in the current corresponding task chain table.
If the task is not the task which sends a request for obtaining a certain resource for the first time, namely the request for obtaining the target resource is sent for the second time, the third time or the Nth time, the task is ranked according to the priority of the task and is the task which is about to use the resource:
that is, there is a third case where the resource is in an idle state, the task priority of the task is temporarily increased to the dynamic priority of the resource, the task uses the resource, and the original task priority is restored after using the resource.
That is, there is a fourth case where the task priority of the task and the task priority of the task occupying the resource are both adjusted to the dynamic priority of the resource, so that the task occupying the resource runs preferentially to release the target resource, so that the task currently issuing the request to acquire a certain resource uses the resource immediately.
S400: adding the first task into a task linked list of the target resource, and adding the target resource into a resource linked list of the first task;
in a specific embodiment, the step S400 of adding the first task to the task chain table of the target resource includes:
acquiring task priorities of other tasks in a task chain table of the target resource;
and adding the first task into the task chain table of the target resource according to the task priority of the first task and the task priorities of other tasks in the target resource.
S500: and adjusting the task priority of the second task occupying the target resource to be the dynamic priority of the target resource so as to ensure that the second task occupying the target resource runs preferentially to release the target resource.
Specifically, when the target resource is already occupied by the second task, a first task with a higher task priority uses the target resource for the first time, and according to the specific principle, the system can adjust the dynamic priority of the resource to be the task priority of the first task, and at this time, only the task priority of the second task which already occupies the target resource needs to be temporarily adjusted to be the new dynamic priority after the adjustment of the target resource, so as to ensure that the task which currently occupies the resource has sufficient task priority, and the prior operation is performed, so that the operation is finished to release the resource as soon as possible, and the occurrence of priority inversion is avoided.
It should be noted that, in the prior art, the problem of priority reversal may occur during the operation of the operating system, for example, there are three priority tasks a, B, and C, where a is the highest priority, B is the next, and C is the lowest priority. When a low-priority task C preempts a resource D, if a high-priority task A wants to acquire the resource D, the high-priority task A can acquire the resource D only after the task C releases the resource D, at the moment, an intermediate-priority task B is scheduled to run, and the B does not need the resource or does not need the resource D.
The technical scheme of the application is that the method also comprises three priority tasks A, B and C, wherein the priority A is the highest, the priority B is the next, and the priority C is the lowest. When a task C with low priority preempts a resource D, at the moment, if a task A with high priority also wants to acquire the resource D, the task priority of the task A is higher than the dynamic priority of the resource D, so that the dynamic priority of the resource D is updated to be the task priority of the task A, the task priority of the task C is temporarily and synchronously improved to be the dynamic priority of the resource D, namely the task priority of the task A, after the task A is added to the task C in the task chain table, the task A can acquire the resource D after the task C releases the resource D,
at the moment, a task B with an intermediate priority is scheduled to run, the task B does not need resources or needs resources E, the task C cannot be suspended and continues to execute because the task priority of the task B is lower than that of the task C, so that the resources D are released to the task A as soon as possible, then the task A acquires the resources D to run, and the task B is scheduled to run after the running of the task A is finished,
by adjusting the task priority of the task C, the task C cannot be interrupted by the task B with the intermediate priority in the running process, so that the task A can be smoothly run after the task C is finished, and the problem of reversing the priorities of the task A and the task B is solved.
In a specific embodiment, the step S500 adjusts the task priority of the second task occupying the target resource to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource, and then includes:
and when the second task finishes running and releases the target resource, the task priority of the second task is restored to the task priority before the second task is adjusted.
Specifically, each task using a certain resource temporarily increases the task priority of the task to the dynamic priority of the resource, and after the resource is used up, the task priority of the task is recovered.
As shown in fig. 2: in a specific embodiment, the step S500 adjusts the task priority of the second task occupying the target resource to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource, and then includes:
s510: when the second task is finished, traversing a resource linked list of the second task;
s520: acquiring all resources contained in the second task according to the resource linked list of the second task;
s530: and deleting the second task from the task linked list corresponding to all the resources.
As shown in fig. 3, in a specific embodiment, the deleting the second task from the task chain table corresponding to all the resources in step S530 includes:
s531: judging whether the task priority corresponding to the second task is the highest priority in an original task chain table of the target resource, wherein the original task chain table is a task chain table when the second task runs preferentially;
s532: if so, the task priority of the task with the highest task priority in the current task chain table of the target resource is obtained and assigned to the target resource, so that the new dynamic priority corresponding to the target resource is the task priority of the task with the highest task priority in the current task chain table.
Specifically, the dynamic priority of the resource may change dynamically as the task ends, i.e., the dynamic priority of the resource may change dynamically as the task is created and ended.
For example, the running of the priority task E needs to acquire the resource F and the resource G, and in the task chain table of the resource F, the task E has the highest priority and the task H times.
After the operation of the priority task E is finished, because the resource chain table of the task E includes the resource F and the resource G, the task E needs to be deleted from the task chain tables of the resource F and the resource G,
for the resource D, because the task E is the task with the highest task priority in the task chain table of the resource D, after the task E is deleted from the task chain table of the resource D, the task chain table of the resource D is traversed, and the task priority of the task H with the highest task priority in the current task chain table is assigned to the resource D.
As shown in fig. 4, an embodiment of the present specification further provides a device for dynamically adjusting priority, where the device includes:
the first task request determining module 601: the first task is used for judging whether to send a request for obtaining the target resource for the first time when the first task sends the request for obtaining the target resource;
the task priority acquisition module 602: the task priority acquiring system is used for acquiring the task priority of a first task, the dynamic priority of a target resource and a second task occupying the target resource at present when the first task sends a request for acquiring the target resource for the first time;
the dynamic priority setting module 603: the task priority setting module is used for setting the dynamic priority of the target resource as the task priority of the first task when the task priority of the first task is higher than the dynamic priority of the target resource;
the task list creation module 604: the system comprises a task chain table, a resource chain table and a resource chain table, wherein the task chain table is used for adding a first task to a target resource and adding the target resource to the resource chain table of the first task;
the priority adjustment module 605: and the task priority of the second task occupying the target resource is adjusted to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource.
The embodiments and features of the embodiments described herein above can be combined with each other without conflict.
While the invention has been described in connection with what is presently considered to be the most practical and preferred embodiment, it is to be understood that the invention is not to be limited to the disclosed embodiment, but on the contrary, is intended to cover various modifications and equivalent arrangements included within the spirit and scope of the appended claims.

Claims (10)

1. A method for dynamically adjusting priority, the method comprising:
when a first task sends a request for acquiring a target resource, judging whether the first task sends the request for acquiring the target resource for the first time;
when a first task sends a request for acquiring a target resource for the first time, acquiring the task priority of the first task, the dynamic priority of the target resource and a second task occupying the target resource at present;
when the task priority of the first task is higher than the dynamic priority of the target resource, setting the dynamic priority of the target resource as the task priority of the first task;
adding the first task into a task chain table of the target resource, and adding the target resource into a resource chain table of the first task;
and adjusting the task priority of the second task occupying the target resource to be the dynamic priority of the target resource so as to ensure that the second task occupying the target resource runs preferentially to release the target resource.
2. The method according to claim 1, wherein the task priority of the second task occupying the target resource is adjusted to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource, and then the method comprises:
and when the second task finishes running and releases the target resource, the task priority of the second task is restored to the task priority before the second task is adjusted.
3. The method of claim 2, wherein the first task issues a request to obtain the target resource, and previously comprises:
acquiring all resources in a processing system;
and creating dynamic priority and a task linked list which are in one-to-one correspondence with each resource according to all the resources, wherein the task linked list comprises all tasks needing to use the corresponding resources, and all the tasks are arranged in the task linked list from high to low according to the corresponding task priority.
4. The method of claim 3, wherein adding the first task to the task list of the target resource comprises:
acquiring task priorities of other tasks in a task chain table of the target resource;
and adding the first task into the task chain table of the target resource according to the task priority of the first task and the task priorities of other tasks in the target resource.
5. The method of claim 3, wherein the first task issues a request to obtain the target resource, and previously comprises:
when a new task is created, creating a resource linked list which is in one-to-one correspondence with the task according to the task, wherein the resource linked list comprises all resources needed to be used by the task.
6. The method according to claim 5, wherein the task priority of the second task occupying the target resource is adjusted to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource, and then the method comprises:
when the second task is finished, traversing a resource linked list of the second task;
acquiring all resources contained in the second task according to the resource linked list of the second task;
and deleting the second task from the task linked list corresponding to all the resources.
7. The method according to claim 6, wherein the step of deleting the second task from the task chain table corresponding to all the resources comprises:
judging whether the task priority corresponding to the second task is the highest priority in an original task chain table of the target resource, wherein the original task chain table is a task chain table when the second task runs preferentially;
if so, the task priority of the task with the highest task priority in the current task chain table of the target resource is obtained and assigned to the target resource, so that the new dynamic priority corresponding to the target resource is the task priority of the task with the highest task priority in the current task chain table.
8. The method according to claim 1, wherein when the task priority of the first task is lower than the dynamic priority of the target resource, the first task is directly added to the task chain table of the target resource, and the target resource is added to the resource chain table of the first task.
9. The method according to claim 1, wherein when the first task does not send a request for acquiring the target resource for the first time, and when the target resource is in an idle state, the task priority of the first task is adjusted to the dynamic priority of the target resource, and the target resource is directly used to run the first task; or when the target resource is occupied by the second task, the task priorities of the first task and the second task are adjusted to be the dynamic priorities of the target resource, and the second task runs by using the target resource preferentially.
10. An apparatus for dynamically adjusting priority, the apparatus comprising:
a first task request judgment module: the system comprises a first task and a second task, wherein the first task is used for judging whether to send a request for obtaining target resources for the first time or not when sending the request for obtaining the target resources;
a task priority acquisition module: the task priority acquiring system is used for acquiring the task priority of a first task, the dynamic priority of a target resource and a second task occupying the target resource at present when the first task sends a request for acquiring the target resource for the first time;
the dynamic priority setting module: the task priority setting module is used for setting the dynamic priority of the target resource as the task priority of the first task when the task priority of the first task is higher than the dynamic priority of the target resource;
a task chain table creation module: the system comprises a task chain table, a resource chain table and a resource chain table, wherein the task chain table is used for adding a first task to a target resource and adding the target resource to the resource chain table of the first task;
a priority adjustment module: and the task priority of the second task occupying the target resource is adjusted to the dynamic priority of the target resource, so that the second task occupying the target resource runs preferentially to release the target resource.
CN202210024812.4A 2022-01-07 2022-01-07 Dynamic priority adjustment method and device Active CN114510327B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210024812.4A CN114510327B (en) 2022-01-07 2022-01-07 Dynamic priority adjustment method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210024812.4A CN114510327B (en) 2022-01-07 2022-01-07 Dynamic priority adjustment method and device

Publications (2)

Publication Number Publication Date
CN114510327A true CN114510327A (en) 2022-05-17
CN114510327B CN114510327B (en) 2023-12-22

Family

ID=81549965

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210024812.4A Active CN114510327B (en) 2022-01-07 2022-01-07 Dynamic priority adjustment method and device

Country Status (1)

Country Link
CN (1) CN114510327B (en)

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020133530A1 (en) * 2001-03-15 2002-09-19 Maarten Koning Method for resource control including resource stealing
CN1702623A (en) * 2005-06-13 2005-11-30 浙江大学 Task level resource administration method for micro-kernel embedded real-time operation systems
US20120222035A1 (en) * 2011-02-25 2012-08-30 Qualcomm Incorporated Priority Inheritance in Multithreaded Systems
CN105045563A (en) * 2015-06-19 2015-11-11 陕西科技大学 Conflict management method for speculating nested software transactional memory
CN107291552A (en) * 2017-06-27 2017-10-24 郑州云海信息技术有限公司 A kind of data processing method and device
CN111416780A (en) * 2020-03-10 2020-07-14 延锋伟世通电子科技(上海)有限公司 Real-time priority ceiling optimization method, system, medium and terminal
CN111506438A (en) * 2020-04-03 2020-08-07 华夏龙晖(北京)汽车电子科技股份有限公司 Shared resource access method and device
CN111954236A (en) * 2020-07-27 2020-11-17 河海大学 Hierarchical edge calculation unloading method based on priority
CN112130963A (en) * 2020-09-30 2020-12-25 腾讯科技(深圳)有限公司 Virtual machine task scheduling method and device, computer equipment and storage medium
CN113282381A (en) * 2020-02-19 2021-08-20 中科寒武纪科技股份有限公司 Task scheduling method and device, computer equipment and storage medium

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020133530A1 (en) * 2001-03-15 2002-09-19 Maarten Koning Method for resource control including resource stealing
CN1702623A (en) * 2005-06-13 2005-11-30 浙江大学 Task level resource administration method for micro-kernel embedded real-time operation systems
US20120222035A1 (en) * 2011-02-25 2012-08-30 Qualcomm Incorporated Priority Inheritance in Multithreaded Systems
CN105045563A (en) * 2015-06-19 2015-11-11 陕西科技大学 Conflict management method for speculating nested software transactional memory
CN107291552A (en) * 2017-06-27 2017-10-24 郑州云海信息技术有限公司 A kind of data processing method and device
CN113282381A (en) * 2020-02-19 2021-08-20 中科寒武纪科技股份有限公司 Task scheduling method and device, computer equipment and storage medium
CN111416780A (en) * 2020-03-10 2020-07-14 延锋伟世通电子科技(上海)有限公司 Real-time priority ceiling optimization method, system, medium and terminal
CN111506438A (en) * 2020-04-03 2020-08-07 华夏龙晖(北京)汽车电子科技股份有限公司 Shared resource access method and device
CN111954236A (en) * 2020-07-27 2020-11-17 河海大学 Hierarchical edge calculation unloading method based on priority
CN112130963A (en) * 2020-09-30 2020-12-25 腾讯科技(深圳)有限公司 Virtual machine task scheduling method and device, computer equipment and storage medium

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
JIAN WU等: "Design of task priority model and algorithm for imaging observation problem", 《JOURNAL OF SYSTEMS ENGINEERING AND ELECTRONICS》, vol. 31, no. 2, pages 321 - 334 *
夏恒发: "面向有限资源的物联网终端操作系统设计与实现", 《中国优秀硕士学位论文全文数据库 信息科技辑》, pages 136 - 1340 *
曾小进;陈未如;王银玲;: "嵌入式操作系统SolCS中优先级反转问题研究", 计算机工程与设计, no. 16, pages 37 - 39 *
潘飞: "应用于高铁轨道板多重型AGV交通策略与调度系统的研究", 《中国优秀硕士学位论文全文数据库 (工程科技Ⅱ辑)》, pages 033 - 32 *

Also Published As

Publication number Publication date
CN114510327B (en) 2023-12-22

Similar Documents

Publication Publication Date Title
CN109783218B (en) Kubernetes container cluster-based time-associated container scheduling method
US8832703B2 (en) Dynamically changing job allocation priority based on a restoration rate for each user and time frame
WO2009147802A1 (en) Priority controller and priority control method
CN113032152B (en) Scheduling method, scheduling apparatus, electronic device, storage medium, and program product for deep learning framework
Lipari et al. Schedulability analysis of periodic and aperiodic tasks with resource constraints
KR101073428B1 (en) Method for scheduling task in embedded operating system of automobile
CN114510327A (en) Method and device for dynamically adjusting priority
US8555285B2 (en) Executing a general-purpose operating system as a task under the control of a real-time operating system
CN111143210A (en) Test task scheduling method and system
CN109189581B (en) Job scheduling method and device
US8095695B2 (en) Control apparatus for process input-output device
CN115619002A (en) Flexible dynamic mixed key system scheduling method
CN113986484B (en) Task processing global scheduling method of social software
CN113051005B (en) Loading method and device
JP3005562B1 (en) Task management device and task scheduling method
JP2000259430A (en) Processing method for computer system
JPH11203149A (en) Device and method for scheduling task
WO2012088766A1 (en) Method and device for dynamically scheduling batch processing tasks
JPS63124138A (en) Occupation conflict control method for shared resources
JPH04162155A (en) File transfer control system
JP2890569B2 (en) Process control equipment
JPH06187171A (en) Scheduling system for interruption
JPH03182937A (en) Task control device for multi-task system
JPS62271147A (en) Task control method
JPH01177638A (en) System for scheduling job

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant