CN112764904A - Method for preventing starvation of low priority tasks in multitask-based system - Google Patents

Method for preventing starvation of low priority tasks in multitask-based system Download PDF

Info

Publication number
CN112764904A
CN112764904A CN202110090416.7A CN202110090416A CN112764904A CN 112764904 A CN112764904 A CN 112764904A CN 202110090416 A CN202110090416 A CN 202110090416A CN 112764904 A CN112764904 A CN 112764904A
Authority
CN
China
Prior art keywords
starvation
task
tasks
queue
time
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.)
Pending
Application number
CN202110090416.7A
Other languages
Chinese (zh)
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.)
Zhuhai Eeasy Electronic Tech Co ltd
Original Assignee
Zhuhai Eeasy Electronic Tech 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 Zhuhai Eeasy Electronic Tech Co ltd filed Critical Zhuhai Eeasy Electronic Tech Co ltd
Priority to CN202110090416.7A priority Critical patent/CN112764904A/en
Publication of CN112764904A publication Critical patent/CN112764904A/en
Pending legal-status Critical Current

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/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention relates to a technical scheme based on a method for preventing low-priority tasks from starving in a multitask system, which comprises the following steps: adding corresponding starvation time for each task in a ready queue in the CPU; when the starvation time of any task reaches a starvation threshold, adding the starvation time of any task to a starvation task queue; and sequentially executing the tasks entering the starvation task queue according to the priority by the scheduling clock. The invention has the beneficial effects that: each task only has a unique priority, the priority cannot be dynamically changed, and the management of an operating system is convenient; the starved tasks can be immediately scheduled and executed when the clock is interrupted and returned, and the tasks do not need to wait for the next scheduling time point, so the tasks can be scheduled more timely; the starvation time threshold values of tasks with different priorities and the starvation threshold values of starvation queues can be dynamically configured, and the requirements of different application scenes can be flexibly met.

Description

Method for preventing starvation of low priority tasks in multitask-based system
Technical Field
The invention relates to the field of computers, in particular to a method for preventing low-priority tasks from being starved based on a multitask system.
Background
With the development of computers and electronic technologies, multitask operating systems have become indispensable components in the IT field, and are widely applied to the fields of servers, desktop computers, embedded systems and the like. In small and medium-sized application scenarios, such as the embedded field, priority and time slice-based operating systems still play an important role, and they are continuously favored by various application manufacturers due to advantages of code simplification, high real-time performance, low power consumption, and the like.
Referring to fig. 1, one of the main functions of the operating system is to perform task scheduling, i.e. to manage and allocate processor resources to each task according to the actual operation requirement. Tasks can be generally divided into three states: ready state, running state, waiting resource state. In contrast, there are generally two types of task queues in the system: ready queue, wait queue. After the task is created, entering a ready queue to wait for being scheduled to run; when a task is scheduled to run, it is removed from the ready queue and becomes the currently running task; when a running task is suspended by waiting for some resources, or actively sleeping, it enters a wait queue.
Referring to the waiting task queue in the operating system of fig. 2, the conventional method is to temporarily raise the priority of a task to be the same as the task with the highest priority in the ready queue when it is found that the task is starved because the CPU resource is not available. Thus, the task has the opportunity to be run in the following scheduling process. And after the next scheduling operation of the task is completed, putting the task into the queue with the original priority again. The method firstly causes the priority confusion of tasks, each task has original priority and dynamic priority, and the dynamic priority is changed and is not beneficial to the management of an operating system. Secondly, the starved task cannot be scheduled to run immediately, and must wait for the next scheduling time point, and in the worst case, wait for nearly a complete task time slice. And after the tasks starved to death are scheduled and executed, a complete time slice is executed, so that other ready tasks with high priority cannot be scheduled and run in time, and long scheduling delay is caused.
Disclosure of Invention
The invention aims to solve at least one technical problem in the prior art, provides a method for preventing starvation of low-priority tasks in a multitask system, and realizes game performance optimization with low manpower consumption.
The technical scheme of the invention comprises a method for preventing starvation of low-priority tasks based on a multitask system, which is characterized by comprising the following steps:
adding corresponding starvation time for each task in a ready queue in the CPU;
when the starvation time of any task reaches a starvation threshold, adding the starvation time of any task to a starvation task queue;
sequentially executing the tasks entering the starvation task queue according to the priority by a scheduling clock;
wherein the starvation time is incremented with the latency of the task.
According to the method for preventing starvation of low-priority tasks in the multitask-based system, the step of sequentially executing the tasks entering the starved task queue according to the priority by the scheduling clock further comprises the following steps: executing each task by a time slice, wherein the time slice is set as a clock interrupt period, and the time slice can be also set by self; adding the executed task to the ready queue.
According to the method for preventing starvation of low priority tasks in a multi-tasking-based system, the method further comprises: traversing the starvation queue at each scheduling point in time of the scheduling clock; if the starvation queue is empty, executing normal scheduling, and selecting the next task from the ready queue to run at the next scheduling time point; and if the starvation queue is not empty, judging whether the total time of the continuous operation of the starvation queue task at this time reaches a starvation threshold, and if so, suspending the operation of the tasks in the starvation queue and operating the tasks in the ready queue.
According to the method for preventing starvation of low priority tasks in a multi-tasking-based system, wherein the starvation threshold is configured to: and dynamically setting according to the number of tasks in the starvation queue and a starvation threshold value.
According to the method for preventing the starvation of the low-priority tasks in the multitask-based system, the tasks of the starvation queue store the tasks with different priorities in a linked list mode, and the priorities of the tasks in the starvation queue cannot be modified.
The technical solution of the present invention also includes an apparatus for preventing starvation of low priority tasks in a multitasking based system, the apparatus comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor executes any of the method steps described in the computer program.
The present invention also includes a computer-readable storage medium, in which a computer program is stored, wherein the computer program, when executed by a processor, implements any of the method steps.
The invention has the beneficial effects that: each task only has a unique priority, the priority cannot be dynamically changed, and the management of an operating system is convenient; the starved tasks can be immediately scheduled and executed when the clock is interrupted and returned, and the tasks do not need to wait for the next scheduling time point, so the tasks can be scheduled more timely; the starvation time threshold values of tasks with different priorities and the starvation threshold values of starvation queues can be dynamically configured, and the requirements of different application scenes can be flexibly met.
Drawings
The invention is further described below with reference to the accompanying drawings and examples;
FIG. 1 illustrates a ready task queue in an operating system;
FIG. 2 illustrates a wait queue in an operating system;
FIG. 3 illustrates an overall flow diagram according to an embodiment of the invention;
FIG. 4 is a diagram illustrating a starved task queue according to an embodiment of the present invention;
FIG. 5 is a flow diagram illustrating task scheduling in clock interrupts according to an embodiment of the present invention;
fig. 6 shows a diagram of an apparatus according to an embodiment of the invention.
Detailed Description
Reference will now be made in detail to the present preferred embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like reference numerals refer to like elements throughout.
In the description of the present invention, the meaning of a plurality of means is one or more, the meaning of a plurality of means is two or more, and larger, smaller, larger, etc. are understood as excluding the number, and larger, smaller, inner, etc. are understood as including the number.
In the description of the present invention, the consecutive reference numbers of the method steps are for convenience of examination and understanding, and the implementation order between the steps is adjusted without affecting the technical effect achieved by the technical solution of the present invention by combining the whole technical solution of the present invention and the logical relationship between the steps.
In the description of the present invention, unless otherwise explicitly defined, terms such as set, etc. should be broadly construed, and those skilled in the art can reasonably determine the specific meanings of the above terms in the present invention in combination with the detailed contents of the technical solutions.
Interpretation of terms:
SMP: symmetric Multi-Processor, a symmetric multiprocessor. The method comprises the steps that a group of processors (CPUs) are collected on a computer, and a memory subsystem and a bus structure are shared among the CPUs;
a CPU: a Central Processing Unit, i.e. a Central Processing Unit, which is called a processor for short;
number of cores of CPU: the number of CPU processors contained in the chip;
a multiprocessor: i.e., multi-core, multi-processor core, multi-CPU;
and OS: operating System;
and (4) Cache: i.e. a cache internal to the CPU;
cache Line: i.e., a cache line, is the smallest unit of CPU cache access. When the Cache Line is rewritten by the CPU and is not updated to the main memory, the Cache Line is said to be in Dirty state.
A main memory: the internal memory, the main memory and the main memory are used for temporarily storing the transportation data of the CPU, and the data can be lost after power failure.
Fig. 3 shows a general flow chart according to an embodiment of the invention, the flow chart comprising: adding corresponding starvation time for each task in a ready queue in the CPU; when the starvation time of any task reaches a starvation threshold, adding the starvation time of any task to a starvation task queue; and sequentially executing the tasks entering the starvation task queue according to the priority by the scheduling clock.
Referring to fig. 4, where tasks a, b, c and d are in different starvation queues, the technical solution of the present invention adds a variable describing the degree of starvation, called starvation time, to each task. When the task enters the ready queue, the starvation time is cleared to 0, and then if the task is not scheduled to be executed in time, the starvation time is continuously increased. When the task is increased to a certain set value, the task is in an starvation state and needs to be immediately scheduled to be executed. This set value is called the starvation threshold, which is different for different priority tasks. The higher the priority, the lower tolerance to starvation conditions, and the smaller its starvation threshold.
If a plurality of tasks in the system are in the starvation state, the tasks with high priority are naturally executed preferentially, and the tasks in the starvation state are managed through the starvation queue. Similar to the ready queue, different priorities correspond to a linked list respectively, and all tasks in starvation state of the priority are above the linked list.
Fig. 5 is a flowchart illustrating task scheduling in clock interrupt according to an embodiment of the present invention, which is described in detail as follows:
referring to fig. 5, when the system is very busy, the number of tasks in the starvation queue may be large instantaneously, and if all tasks in the starvation queue are scheduled once and then executed again, new tasks in the ready queue may be starved. A time threshold is therefore set, which the total time cannot exceed each time a task of the starvation queue is processed, and is referred to as the starvation threshold. When the starvation queue processing time exceeds the starvation threshold, scheduling of starved tasks is suspended, and tasks in the ready queue are scheduled. By the mode, tasks starved to death can be scheduled in time, tasks in a ready queue can be scheduled in time, and new tasks starved to death are prevented from being generated.
In the processing flow of system clock interrupt, the starvation condition of the task is tracked, and the task in the starvation queue is scheduled according to the requirement.
Firstly, the waiting time of all the tasks in the ready queue is increased, and when the waiting time of a new task exceeds the starvation time threshold corresponding to the priority task, the task is added to the starvation queue. And then judging the starvation queue, if the starvation queue is empty, indicating that no task is in a starvation state, executing normal scheduling, namely selecting the next task from the ready queue to run at the next scheduling time point.
And if the starvation queue is not empty, judging whether the total time of the continuous running of the starvation queue task reaches a starvation understanding threshold value. If the threshold is reached, the running time of the starvation queue task is too long, and the starvation queue task needs to be suspended, so that the tasks in the ready queue have an opportunity to run. Therefore, at the next scheduling time point, the task in the starvation queue can not be scheduled any more, and the task in the ready queue is scheduled to run. If the total time of continuous running of the starvation queue task does not reach the starvation threshold value, the next scheduling point does not need to be waited, and the task running is selected from the starvation queue before the interruption returns. As previously described, each task in the starvation queue is allowed to run for only a relatively small time slice at a time, and thus does not generally have a large impact on the scheduling of ready queue tasks.
The setting of the starvation threshold needs to be based on the statistical information of the number of tasks in the starvation queue. If the setting is too large, the waiting time of the tasks in the ready queue is too long and a new task is starved when a lot of tasks in the starvation queue are met; if the setting is too small, the starvation queue tasks may not be scheduled and completed in time, so that the starvation queue has tasks all the time, and the scheduling of the ready queue is also affected. And actually, the starvation threshold value can be dynamically set according to the scene needs.
According to the technical scheme of the invention, each task only has unique priority, the priority cannot be dynamically changed, and the management of an operating system is convenient. Secondly, the starved task can be scheduled to be executed immediately when the clock interrupt returns, and the task does not need to wait for the next scheduling time point, so that the task can be scheduled more timely. In addition, each task in the starvation queue runs for a short time, so that the scheduling of the ready queue is not greatly influenced. Meanwhile, starvation time thresholds of tasks with different priorities and starvation thresholds of starvation queues can be dynamically configured, and the requirements of different application scenes can be flexibly met.
Fig. 6 shows a diagram of an apparatus according to an embodiment of the invention. The apparatus comprises a memory 100 and a processor 200, wherein the processor 200 stores a computer program for performing: adding corresponding starvation time for each task in a ready queue in the CPU; when the starvation time of any task reaches a starvation threshold, adding the starvation time of any task to a starvation task queue; and sequentially executing the tasks entering the starvation task queue according to the priority by the scheduling clock. Wherein the memory 100 is used for storing data.
The embodiments of the present invention have been described in detail with reference to the accompanying drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge of those skilled in the art without departing from the gist of the present invention.

Claims (7)

1. A method for preventing starvation of low priority tasks in a multitasking based system, the method comprising:
adding corresponding starvation time for each task in a ready queue in the CPU;
when the starvation time of any task reaches a starvation threshold, adding the starvation time of any task to a starvation task queue;
sequentially executing the tasks entering the starvation task queue according to the priority by a scheduling clock;
wherein the starvation time is incremented with the latency of the task.
2. The method of claim 1, wherein the scheduling clock sequentially executes tasks entering the starved task queue according to priority, further comprising: executing each task by a time slice, wherein the time slice is set as a clock interrupt period, and the time slice can be also set by self; adding the executed task to the ready queue.
3. A method for preventing starvation of low priority tasks in a multi-tasking-based system as recited in claim 1, further comprising:
traversing the starvation queue at each scheduling point in time of the scheduling clock;
if the starvation queue is empty, executing normal scheduling, and selecting the next task from the ready queue to run at the next scheduling time point;
and if the starvation queue is not empty, judging whether the total time of the continuous operation of the starvation queue task at this time reaches a starvation threshold, and if so, suspending the operation of the tasks in the starvation queue and operating the tasks in the ready queue.
4. A method for preventing starvation of low priority tasks in a multi-tasking-based system as claimed in claim 3, wherein the starvation threshold is configured to:
and dynamically setting according to the number of tasks in the starvation queue and a starvation threshold value.
5. The method for preventing starvation of low priority tasks in a multitasking based system according to claim 1, wherein the tasks in the starvation queue are stored in a linked list form for tasks of different priorities, and the priorities of the tasks in the starvation queue cannot be modified.
6. An apparatus for preventing starvation of low priority tasks in a multitasking based system, the apparatus comprising a memory, a processor and a computer program stored in said memory and being executable on said processor, wherein said processor when executing said computer program is adapted to carry out the method steps of any of claims 1-5.
7. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the method steps of any one of claims 1 to 5.
CN202110090416.7A 2021-01-22 2021-01-22 Method for preventing starvation of low priority tasks in multitask-based system Pending CN112764904A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110090416.7A CN112764904A (en) 2021-01-22 2021-01-22 Method for preventing starvation of low priority tasks in multitask-based system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110090416.7A CN112764904A (en) 2021-01-22 2021-01-22 Method for preventing starvation of low priority tasks in multitask-based system

Publications (1)

Publication Number Publication Date
CN112764904A true CN112764904A (en) 2021-05-07

Family

ID=75706735

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110090416.7A Pending CN112764904A (en) 2021-01-22 2021-01-22 Method for preventing starvation of low priority tasks in multitask-based system

Country Status (1)

Country Link
CN (1) CN112764904A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113590030A (en) * 2021-06-30 2021-11-02 济南浪潮数据技术有限公司 Queue scheduling method, system, equipment and medium
CN113590289A (en) * 2021-07-30 2021-11-02 中科曙光国际信息产业有限公司 Job scheduling method, system, device, computer equipment and storage medium
CN113835861A (en) * 2021-09-24 2021-12-24 中汽创智科技有限公司 Process scheduling method, device, equipment and storage medium
CN116700913A (en) * 2022-09-13 2023-09-05 荣耀终端有限公司 Scheduling method, equipment and storage medium of embedded file system
CN116737673A (en) * 2022-09-13 2023-09-12 荣耀终端有限公司 Scheduling method, equipment and storage medium of file system in embedded operating system

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2004045120A1 (en) * 2002-11-13 2004-05-27 Agere Systems Inc. Managing priority queues and escalation in wireless communication systems
CN1529845A (en) * 2001-06-22 2004-09-15 ض� Methoa dn apparatus for resolving instruction starvation in multithreaded processor
CN104778080A (en) * 2014-01-14 2015-07-15 中兴通讯股份有限公司 Job scheduling processing method and device based on coprocessor
US20160077870A1 (en) * 2014-09-16 2016-03-17 Freescale Semiconductor, Inc. Starvation control in a data processing system
CN111488210A (en) * 2020-04-02 2020-08-04 腾讯科技(深圳)有限公司 Task scheduling method and device based on cloud computing and computer equipment

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1529845A (en) * 2001-06-22 2004-09-15 ض� Methoa dn apparatus for resolving instruction starvation in multithreaded processor
WO2004045120A1 (en) * 2002-11-13 2004-05-27 Agere Systems Inc. Managing priority queues and escalation in wireless communication systems
CN104778080A (en) * 2014-01-14 2015-07-15 中兴通讯股份有限公司 Job scheduling processing method and device based on coprocessor
US20160077870A1 (en) * 2014-09-16 2016-03-17 Freescale Semiconductor, Inc. Starvation control in a data processing system
CN111488210A (en) * 2020-04-02 2020-08-04 腾讯科技(深圳)有限公司 Task scheduling method and device based on cloud computing and computer equipment

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
侯芬, 朱祥华: "基于混合服务策略轮询系统的性能分析", 计算机工程与应用, no. 24 *
王新政;程小辉;周华茂;: "实时操作系统任务调度策略的研究与设计", 微计算机信息, no. 11 *

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113590030A (en) * 2021-06-30 2021-11-02 济南浪潮数据技术有限公司 Queue scheduling method, system, equipment and medium
CN113590030B (en) * 2021-06-30 2023-12-26 济南浪潮数据技术有限公司 Queue scheduling method, system, equipment and medium
CN113590289A (en) * 2021-07-30 2021-11-02 中科曙光国际信息产业有限公司 Job scheduling method, system, device, computer equipment and storage medium
CN113835861A (en) * 2021-09-24 2021-12-24 中汽创智科技有限公司 Process scheduling method, device, equipment and storage medium
CN116700913A (en) * 2022-09-13 2023-09-05 荣耀终端有限公司 Scheduling method, equipment and storage medium of embedded file system
CN116737673A (en) * 2022-09-13 2023-09-12 荣耀终端有限公司 Scheduling method, equipment and storage medium of file system in embedded operating system
CN116737673B (en) * 2022-09-13 2024-03-15 荣耀终端有限公司 Scheduling method, equipment and storage medium of file system in embedded operating system

Similar Documents

Publication Publication Date Title
CN112764904A (en) Method for preventing starvation of low priority tasks in multitask-based system
US11550627B2 (en) Hardware accelerated dynamic work creation on a graphics processing unit
CN109997112B (en) Data processing
US8245207B1 (en) Technique for dynamically restricting thread concurrency without rewriting thread code
US7318128B1 (en) Methods and apparatus for selecting processes for execution
JP4694595B2 (en) Sleep queue management
US10552213B2 (en) Thread pool and task queuing method and system
US20060037017A1 (en) System, apparatus and method of reducing adverse performance impact due to migration of processes from one CPU to another
US9507633B2 (en) Scheduling method and system
US20120297216A1 (en) Dynamically selecting active polling or timed waits
US20130097382A1 (en) Multi-core processor system, computer product, and control method
US20060037021A1 (en) System, apparatus and method of adaptively queueing processes for execution scheduling
US20190286582A1 (en) Method for processing client requests in a cluster system, a method and an apparatus for processing i/o according to the client requests
US9547576B2 (en) Multi-core processor system and control method
KR101373786B1 (en) Resource-based scheduler
US20230315526A1 (en) Lock-free work-stealing thread scheduler
US7765548B2 (en) System, method and medium for using and/or providing operating system information to acquire a hybrid user/operating system lock
CN112925616A (en) Task allocation method and device, storage medium and electronic equipment
CN112860387A (en) Distributed task scheduling method and device, computer equipment and storage medium
CN111045800A (en) Method and system for optimizing GPU (graphics processing Unit) performance based on short job priority
CN114461365A (en) Process scheduling processing method, device, equipment and storage medium
CN110716805A (en) Task allocation method and device of graphic processor, electronic equipment and storage medium
JP7346649B2 (en) Synchronous control system and method
US10360652B2 (en) Wavefront resource virtualization
CN115904644A (en) Task scheduling method, electronic device and computer program product

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