CN113495787A - Resource allocation method, device, storage medium and electronic equipment - Google Patents

Resource allocation method, device, storage medium and electronic equipment Download PDF

Info

Publication number
CN113495787A
CN113495787A CN202010261311.9A CN202010261311A CN113495787A CN 113495787 A CN113495787 A CN 113495787A CN 202010261311 A CN202010261311 A CN 202010261311A CN 113495787 A CN113495787 A CN 113495787A
Authority
CN
China
Prior art keywords
thread
scheduled
processor resources
rule
target
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
CN202010261311.9A
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.)
Guangdong Oppo Mobile Telecommunications Corp Ltd
Original Assignee
Guangdong Oppo Mobile Telecommunications Corp 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 Guangdong Oppo Mobile Telecommunications Corp Ltd filed Critical Guangdong Oppo Mobile Telecommunications Corp Ltd
Priority to CN202010261311.9A priority Critical patent/CN113495787A/en
Publication of CN113495787A publication Critical patent/CN113495787A/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/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
    • G06F9/5038Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the execution order of a plurality of tasks, e.g. taking priority or time dependency constraints into consideration
    • 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
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/50Indexing scheme relating to G06F9/50
    • G06F2209/5018Thread allocation

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The embodiment of the application discloses a resource allocation method, a resource allocation device, a storage medium and electronic equipment, wherein when receiving accelerated start prompt information, the embodiment of the application determines a target thread indicated by the accelerated start prompt information and marks the target thread as a preset type thread; when processor resources need to be allocated to the thread to be scheduled, judging whether the thread to be scheduled is a preset type thread; if so, allocating processor resources for the thread to be scheduled according to a first rule; if not, allocating processor resources for the threads to be scheduled according to a second rule, wherein the speed or the number of the processor resources allocated for the threads based on the first rule is greater than the speed or the number of the processor resources allocated for the threads based on the second rule, so that the kernel can allocate the processor resources for the core threads more and more quickly, and the threads can execute tasks more efficiently to reduce the stuck phenomenon of the electronic device.

Description

Resource allocation method, device, storage medium and electronic equipment
Technical Field
The present application relates to the field of electronic device technologies, and in particular, to a resource allocation method, an apparatus, a storage medium, and an electronic device.
Background
With the continuous improvement of the smart phone technology, the requirements of users on smart phones are not limited to basic functions such as conversation short messages, and the requirements of the users on the operation speed of the mobile phones are increasing. At present, android systems are mostly used for smart phones, and in the android systems, linux kernels at the bottom of a system architecture cannot clearly and clearly know scenes when users use the smart phones, so that the allocation of resources cannot be adapted to the use scenes. When there are many threads waiting to be executed, a situation may occur in which some threads may not have sufficient resources to cause the electronic device to become stuck.
Disclosure of Invention
The embodiment of the application provides a resource allocation method, a resource allocation device, a storage medium and an electronic device, which can reduce the phenomenon of jamming of the electronic device.
In a first aspect, an embodiment of the present application provides a resource allocation method, including:
when acceleration starting prompt information is received, determining a target thread indicated by the acceleration starting prompt information, and marking the target thread as a preset type thread;
when processor resources need to be allocated to a thread to be scheduled, judging whether the thread to be scheduled is a preset type thread;
when the thread to be scheduled is the thread of the preset type, allocating processor resources for the thread to be scheduled according to a first rule;
and when the thread to be scheduled is not the thread of the preset type, allocating processor resources to the thread to be scheduled according to a second rule, wherein the speed or the quantity of the processor resources allocated to the thread based on the first rule is greater than the speed or the quantity of the processor resources allocated to the thread allocator based on the second rule.
In a second aspect, an embodiment of the present application further provides a resource allocation apparatus, including:
the thread marking module is used for determining a target thread indicated by the accelerated start prompt information when the accelerated start prompt information is received, and marking the target thread as a preset type thread;
the thread judging module is used for judging whether the thread to be dispatched is a preset type thread or not when the processor resources are required to be allocated to the thread to be dispatched;
the resource allocation module is used for allocating processor resources to the thread to be scheduled according to a first rule when the thread to be scheduled is the thread of the preset type;
and when the thread to be scheduled is not the preset type of thread, allocating processor resources to the thread to be scheduled according to a second rule, wherein the speed or the number of the processor resources allocated to the thread based on the first rule is greater than the speed or the number of the processor resources allocated to the thread allocator based on the second rule.
In a third aspect, an embodiment of the present application further provides a storage medium, on which a computer program is stored, and when the computer program runs on a computer, the computer is caused to execute the resource allocation method provided in any embodiment of the present application.
In a fourth aspect, an embodiment of the present application further provides an electronic device, including a processor and a memory, where the memory has a computer program, and the processor is configured to execute the resource allocation method provided in any embodiment of the present application by calling the computer program.
According to the technical scheme provided by the embodiment of the application, when the accelerated start prompt message is received, the target thread indicated by the accelerated start prompt message is determined, and the target thread is marked as the thread of the preset type. When the processor resources are required to be allocated to the thread to be scheduled, judging whether the thread to be scheduled is a thread of a preset type, if so, allocating the processor resources to the thread according to a first rule, and if not, allocating the processor resources to the thread according to a second rule, wherein the speed or the number of the processor resources allocated to the thread based on the first rule is greater than the speed or the number of the processor resources allocated to the thread allocator based on the second rule. In this way, some core threads are marked as threads of a preset type according to the acceleration start prompting information, and then the threads are distinguished from other non-core threads. And compared with non-core threads, more and faster processor resources are allocated to the core threads in the acceleration time period, so that the threads can execute tasks more efficiently, and the phenomenon that the electronic equipment is stuck is reduced.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a first flowchart of a resource allocation method according to an embodiment of the present application.
Fig. 2 is a second flowchart of a resource allocation method according to an embodiment of the present application.
Fig. 3 is a schematic structural diagram of a resource allocation apparatus according to an embodiment of the present application.
Fig. 4 is a first structural schematic diagram of an electronic device according to an embodiment of the present application.
Fig. 5 is a second structural schematic diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application. It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without inventive step, are within the scope of the present application.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
An execution main body of the resource allocation method may be the resource allocation apparatus provided in the embodiment of the present application, or an electronic device integrated with the resource allocation apparatus, where the resource allocation apparatus may be implemented in a hardware or software manner. The electronic device may be a smart phone, a tablet computer, a palm computer, a notebook computer, or a desktop computer.
Referring to fig. 1, fig. 1 is a first flowchart illustrating a resource allocation method according to an embodiment of the present disclosure. The specific process of the resource allocation method provided by the embodiment of the application can be as follows:
in 101, when acceleration start prompting information is received, a target thread indicated by the acceleration start prompting information is determined, and the target thread is marked as a preset type thread.
In this embodiment, the operating system of the electronic device may be a linux kernel-based system, such as an android operating system. When an application installed in the electronic device runs, the system creates a process for the application and allocates resources for the process.
A thread is an execution path of a process, is the minimum unit for program execution, and is also the basic unit for CPU scheduling and dispatch. A process may have multiple threads but at least one thread. In the embodiment of the application, when a process has a task to be executed, a new thread is created to execute the task.
And for the threads with different priorities, carrying out thread scheduling according to different thread scheduling rules. For example, CFS (complete fair scheduling) scheduling rules, etc. In this embodiment, the thread that is scheduled by using the CFS scheduling rule is referred to as a CFS thread, and the scheduling rule of the CFS scheduler is optimized to improve the execution efficiency of the thread related to the preset event.
If the processor of the electronic device is a multi-core processor, each processor core may be treated as an independent processing unit. For example, if the electronic device is an eight-core processor, each core is an independent processing unit. Each processing unit has a respective task queue containing tasks assigned to the processing unit, each task being executed by a respective thread.
One or more programs may be running simultaneously in an electronic device, each program having at least one corresponding process, and a process having at least one thread executing a task. Therefore, the electronic device may have multiple threads to execute, and CPU resources need to be allocated for the execution of these threads. The main scheduling strategy of the CFS scheduler installs a corresponding scheduling mechanism to allocate processing units for the threads, and selects an optimal process to preempt processor resources. After a thread is allocated to a processing unit, if the thread enters a ready state, the thread is added to a task queue of the allocated processing unit and waits to be executed.
The life cycle of a thread can be divided into 5 states: new state (New): after a Thread object is built by using the new keyword and the Thread class or the subclass thereof, the Thread object is in a new state. It holds this state until the program start () thread. Ready state (Runnable): when a thread object calls the start () method, the thread enters the ready state. Threads in a ready state are added to the ready queue, waiting for the thread scheduler to schedule. Running state (Running): if a thread in the ready state acquires CPU resources, a run () method may be executed, at which point the thread is in the running state, and the running thread may become blocked, ready, and dead. Blocked state (Blocked): if a thread executes sleep, suspend, etc., the thread enters the blocking state from the running state after losing occupied resources. The ready state may be re-entered after the sleep time has expired or acquired resources. Death status (Dead): a thread in a run state switches to a termination state when it completes a task or other termination condition occurs.
The default scheduling rule of the CFS scheduler is as follows: and allocating processing units for the threads according to a load balancing principle, and after the processing units are allocated, allocating CPU (Central processing Unit) use time for the threads according to the priority of the threads. For example, if two threads with the same priority run on one CPU, each thread will be allocated 50% of the CPU running time, i.e. fair scheduling is achieved. And when the priority of the threads is different, the CPU running time is distributed according to the weight proportion of the threads. The weight represents the priority of the thread, and the higher the weight is, the higher the priority is, and the larger the proportion of the CPU running time is distributed. In general, the weight of a thread is represented by a nice value, which is a specific number and generally takes on a preset range. Smaller values represent higher priority and also mean higher weight values.
If the CFS scheduler always schedules the CFS thread according to the rule, the allocation of the equipment resources cannot be adapted to the use scene. For example, when an application is started (here, cold start is taken as an example), the linux kernel creates a plurality of threads related to the starting process of the application, the threads obey the command of the kernel thread scheduler in the kernel, and the threads compete for resources fairly with other threads to decide resource allocation according to the related priority and load. That is to say, the kernel looks like the threads related to the startup with other background processes, and does not allocate more resources to the threads related to the startup process, and the overall scheduling and frequency modulation policy does not take other measures, which may cause slow startup of the application and affect the use of the user when the startup load of the application is large.
Wherein, applying cold start means: when an application is started, the background does not have a process of the application, the system needs to recreate a new process to be allocated to the application, and the starting mode of the application is cold starting.
In some embodiments, when a preset event is detected to be executed, a target thread created by executing the preset event is determined, and accelerated start prompt information is generated based on the target thread.
For example, the preset event includes, but is not limited to, the following events: the mobile phone comprises a mobile phone cold start-up process, a mobile phone hot start-up process, an application program installation process, a touch response process, a payment process, an application program starting process and the like, wherein the application program starting process comprises an application hot start process, an application warm start process and an application cold start process.
In the embodiment of the present application, the relevant threads when the electronic device executes some events may be marked as core threads, and for these core threads, the original scheduling rules of the CFS scheduler are optimized, so that the CFS scheduler can allocate more and more resources for these core threads, where the resources include but are not limited to CPU resources (i.e., processor resources). For example, monitoring of events performed by the electronic device determines which threads to mark as core threads. For example, in order to speed up the cold start process of the application program, when the cold start of the application program is detected, the threads created by the cold start of the application program are determined to be executed, and the threads are marked as core threads. Wherein, the user experience is directly influenced because whether the system is blocked or not. The target thread created by the execution of the preset event is marked as a ux (user experience) thread.
In some embodiments, the target thread may be marked as a thread of a preset type by adding a preset tag to the target thread. For example, a ux tag is added to a thread to mark the thread as a ux thread.
In some embodiments, in the embodiment of the present application, when an application framework (frame) layer of a system architecture detects a preset event, a target thread is determined, and prompt information for accelerating start is sent to a kernel layer, and after receiving the prompt information, the kernel layer marks the corresponding target thread as an ux thread.
After the operation is executed, for the CFS scheduler, there are at least two threads, a ux thread and a non-ux thread, in all CFS threads, where the importance of the ux thread is higher than that of the non-ux thread, and when the kernel performs resource allocation, the kernel allocates the ux thread preferentially, and its resources are also tilted to the ux thread.
In 102, when processor resources need to be allocated to a thread to be scheduled, it is determined whether the thread to be scheduled is a preset type of thread.
In 103, when the thread to be scheduled is the thread of the preset type, allocating processor resources to the thread to be scheduled according to a first rule.
At 104, when the thread to be scheduled is not the thread of the preset type, allocating processor resources to the thread to be scheduled according to a second rule, wherein a speed or a quantity of allocating processor resources to the thread based on the first rule is greater than a speed or a quantity of processing resources to the thread allocator based on the second rule.
In the embodiment of the application, two different rules are adopted for the allocation of the processor resources for the ux thread and the non-ux thread. For a ux thread, allocating according to a first rule, and for a non-ux thread, allocating according to a second rule, the speed or amount of processor resources allocated to the thread based on the first rule is greater than the speed or amount of processor resources allocated to the thread based on the second rule, that is, the first rule is equivalent to the second rule, and resources can be allocated to the thread more quickly.
When it is determined according to the main scheduling policy of the CFS scheduler that a processing unit needs to be allocated to a thread to be scheduled, a kernel needs to be migrated to the thread to be scheduled, or the operating frequency of the current processing unit of the thread to be scheduled needs to be increased, it may be determined that processor resources need to be allocated to the thread to be scheduled. The core migration refers to migrating a thread from a core where the thread is currently located to another core, taking an eight-core CPU as an example, where the eight cores include four large cores and four small cores, where the four large cores are in one group, and the four small cores are in one group, and when the core migration is performed, the core migration may be performed in a group or between different groups.
For example, when a processor needs to be allocated for a ux thread, a core with a small load or a large core may be preferentially selected for allocation. Or when the ux thread needs to migrate the core, the large core is preferentially selected for migration. And for non-ux threads, resource allocation can be carried out according to the default load balancing rule of the CFS scheduler. For example, allocating processor resources to the thread to be scheduled according to the second rule may include: and allocating processor resources for the thread to be scheduled according to a preset thread scheduling rule.
In particular implementation, the present application is not limited by the execution sequence of the described steps, and some steps may be performed in other sequences or simultaneously without conflict.
In some embodiments, the allocating processor resources is a change processing unit; the allocating processor resources to the thread to be scheduled according to the first rule includes: determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit; and migrating the thread to be scheduled from the current processing unit to the target processing unit for execution.
In this embodiment, the CFS scheduler may determine that a thread needs to change a processing unit, which is called a migration core, when detecting that the processing unit of the thread is not enough to execute the thread, or when detecting that the processing unit of the thread is too heavily loaded, or when a thread needs to perform migration processing after being awakened. At this time, it is necessary to select one processing unit with higher performance or better computing capability from other processing units, and migrate the thread from the current processing unit to the newly selected processing unit. The thread is taken as a thread to be scheduled, whether the thread is a ux thread is judged first, for example, whether the thread has a ux label is judged, if the thread has the ux label, after candidate processing units are determined from other processing units except the current processing unit, the candidate processing unit with the highest performance or the best computing capacity is selected from the candidate processing units to be used as a target processing unit, and the thread is migrated from the current processing unit to the newly selected processing unit, so that the ux thread can obtain more processor resources, and can be executed quickly to accelerate the application cold start speed. And if the thread does not have the ux label, the CFS scheduler selects a target processing unit from other processing units except the current processing unit according to a default load balancing rule and performs the migrating core processing.
The Linux uses a task _ struct structure to describe and record threads, and each thread has a unique task _ struct structure. the task _ struct records information such as thread identifiers, states, priorities, memory pointers, context data and the like, each task _ struct has a scheduled _ entry structure, and the virtual running time (the thread virtual running time recorded by the CFS scheduler and converted according to a certain rule and the actual running time) and the weight of a process are stored in the structure. The kernel may add a ux tag in the task _ struct data to mark the thread as a ux thread.
In some embodiments, the allocating processor resources is increasing an operating frequency of the processing unit; the allocating processor resources to the thread to be scheduled according to the first rule includes: acquiring a frequency adjustment value corresponding to the thread to be scheduled; and increasing the working frequency of the processing unit where the thread to be scheduled is located according to the frequency adjustment value.
In this embodiment, the CFS scheduler sets a corresponding frequency adjustment value (boost value) for each ux thread, where the ux threads may have the same frequency adjustment value, and may also set different boost values according to different priorities of the ux threads. When a CFS scheduler detects that the working frequency of a processing unit where a certain thread is located needs to be increased, namely, the commonly known frequency increasing, the CFS scheduler takes the thread as a thread to be scheduled, firstly, whether the thread is a ux thread is judged, and if the thread is the ux thread, a frequency adjustment value corresponding to the ux thread is obtained; and increasing the working frequency of the processing unit where the ux thread is currently located according to the frequency adjustment value. And if the thread is not the ux thread, the CFS scheduler performs frequency boosting on the processing unit where the thread is currently located according to a default load balancing rule.
In some embodiments, the allocating processor resources is allocating processing units, and the allocating processor resources to the thread to be scheduled according to the first rule includes: determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit; and allocating the thread to be scheduled to the target processing unit for execution.
In this embodiment, when the CFS scheduler needs to allocate a processing unit to a thread in a ready state, the thread is used as a thread to be scheduled, it is first determined whether the thread is a ux thread, if the thread is a ux thread, all processing units are used as candidate processing units, a candidate processing unit with the largest computing capability is determined from the candidate processing units, and the candidate processing unit is used as a target processing unit, and the ux is allocated to the target processing unit for execution. If the thread is not a ux thread, the CFS scheduler assigns a processing unit for the thread according to default load balancing rules.
As can be seen from the above, in the resource allocation method provided in the embodiment of the present application, when the accelerated start prompt information is received, the target thread indicated by the accelerated start prompt information is determined, and the target thread is marked as a preset type thread. When the processor resources are required to be allocated to the thread to be scheduled, judging whether the thread to be scheduled is a thread of a preset type, if so, allocating the processor resources to the thread according to a first rule, and if not, allocating the processor resources to the thread according to a second rule, wherein the speed or the number of the processor resources allocated to the thread based on the first rule is greater than the speed or the number of the processor resources allocated to the thread allocator based on the second rule. In this way, some core threads are marked as threads of a preset type according to the acceleration start prompting information, and then the threads are distinguished from other non-core threads. And compared with non-core threads, more and faster processor resources are allocated to the core threads in the acceleration time period, so that the threads can execute tasks more efficiently, and the phenomenon that the electronic equipment is stuck is reduced.
The method according to the preceding embodiment is illustrated in further detail below by way of example.
Referring to fig. 2, fig. 2 is a second flow chart of a resource allocation method according to an embodiment of the invention.
In this embodiment, the system architecture of the electronic device includes at least an application framework layer and a kernel layer, where the application framework layer executes 201 and 202 and the kernel layer executes 203 to 207. The method comprises the following steps:
in 201, when a preset event is detected to be executed, a target thread created by executing the preset event is determined, and acceleration starting prompt information is generated based on the target thread.
In 202, when the execution of the execution preset event is detected to be finished, the acceleration termination prompt message is generated based on the target thread.
The preset event includes, but is not limited to, the following events: the mobile phone comprises a mobile phone cold start-up process, a mobile phone hot start-up process, an application program installation process, a touch response process, a payment process, an application program starting process and the like, wherein the application program starting process comprises an application hot start process, an application warm start process and an application cold start process.
When the electronic equipment executes the events, determining a target thread created by the electronic equipment executing the preset events, generating accelerated start prompting information based on the target thread, and sending the accelerated start prompting information to the kernel layer. And when the preset event is detected to be completed by the electronic equipment, the application framework layer generates acceleration termination prompt information and sends the acceleration termination prompt information to the kernel layer.
In 203, when the acceleration start prompting message is received, the target thread indicated by the acceleration start prompting message is determined, and the target thread is marked as a preset type thread.
And after receiving the prompt message, the kernel layer marks the corresponding target thread as a ux thread.
In 204, when the processor resource needs to be allocated to the thread to be scheduled, it is determined whether the thread to be scheduled is a preset type of thread.
When the thread to be scheduled is the thread of the preset type, executing 205; and executing 206 when the thread to be scheduled is not the preset type of thread.
In 205, processor resources are allocated to the thread to be scheduled according to a first rule.
At 206, processor resources are allocated to the thread to be scheduled according to a second rule, wherein a speed or amount of processor resources allocated to the thread based on the first rule is greater than a speed or amount of processor resources allocated to the thread based on the second rule.
In the embodiment of the application, two different rules are adopted for the allocation of the processor resources for the ux thread and the non-ux thread. For a ux thread, allocating according to a first rule, and for a non-ux thread, allocating according to a second rule, the speed or amount of processor resources allocated to the thread based on the first rule is greater than the speed or amount of processor resources allocated to the thread based on the second rule, that is, the first rule is equivalent to the second rule, and resources can be allocated to the thread more quickly.
When it is determined according to the main scheduling policy of the CFS scheduler that a processing unit needs to be allocated to a thread to be scheduled, a kernel needs to be migrated to the thread to be scheduled, or the operating frequency of the current processing unit of the thread to be scheduled needs to be raised, it may be determined that processor resources need to be allocated to the thread to be scheduled. In these cases, the resource allocation may be performed according to the corresponding first rule, respectively. For the specific allocation, reference is made to the above embodiments, which are not described herein again.
In 207, when the acceleration termination prompt message is received, the target thread indicated by the acceleration termination prompt message is determined, and the preset tag of the target thread is deleted.
When the execution of the preset event is completed, the application framework layer may send an acceleration termination prompt message to the kernel layer, and after the kernel layer receives the prompt message, the kernel layer cancels the mark of the preset type thread of the corresponding target thread, for example, deletes the ux tag, so that the thread is also called as a normal thread.
The CFS scheduler performs periodic scheduling, for example, a scheduling period of the CFS scheduler is marked as a tick, and the CFS scheduler performs scheduling once every other tick. And each interval of one tick, the CFS scheduler performs scheduling management according to the execution condition of the thread and the load of each processing unit.
And after one ux thread is changed into a non-ux thread in the execution process, in the next scheduling period, the CFS scheduler returns to the default load balancing rule to schedule the thread.
As can be seen from the above, in the resource allocation method provided in the embodiment of the present invention, when a specific event is detected, the application framework layer sends an acceleration notification to the kernel based on the thread of the specific event, and the kernel marks the threads related to the specific event as threads of a preset type, so as to distinguish the threads from other non-core threads. The processor resources are allocated to the core threads more and more quickly in the acceleration period relative to the non-core threads, so that the threads can execute tasks more efficiently, and the phenomenon that the electronic device is stuck is reduced.
In one embodiment, a resource allocation apparatus is also provided. Referring to fig. 3, fig. 3 is a schematic structural diagram of a resource allocation apparatus 300 according to an embodiment of the present disclosure. The resource allocation apparatus 300 is applied to an electronic device, and the resource allocation apparatus 300 includes a thread marking module 301, a thread determining module 302, and a resource allocation module 303, as follows:
the thread marking module 301 is configured to determine a target thread indicated by the accelerated start prompt message when the accelerated start prompt message is received, and mark the target thread as a preset type of thread;
the thread judging module 302 is configured to, when processor resources need to be allocated to a thread to be scheduled, judge whether the thread to be scheduled is a preset type of thread;
a resource allocation module 303, configured to, when the thread to be scheduled is the thread of the preset type, allocate processor resources to the thread to be scheduled according to a first rule;
and when the thread to be scheduled is not the preset type of thread, allocating processor resources to the thread to be scheduled according to a second rule, wherein the speed or the number of the processor resources allocated to the thread based on the first rule is greater than the speed or the number of the processor resources allocated to the thread allocator based on the second rule.
In some embodiments, the allocating processor resources is a change processing unit; the resource allocation module 303 is further configured to: determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit; and migrating the thread to be scheduled from the current processing unit to the target processing unit for execution.
In some embodiments, the allocating processor resources is increasing an operating frequency of the processing unit; the resource allocation module 303 is further configured to: acquiring a frequency adjustment value corresponding to the thread to be scheduled; and increasing the working frequency of the processing unit where the thread to be scheduled is located according to the frequency adjustment value.
In some embodiments, the allocation processor resource is an allocation processing unit; the resource allocation module 303 is further configured to: determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit; and allocating the thread to be scheduled to the target processing unit for execution.
In some embodiments, the resource allocation apparatus 300 further comprises:
the information generation module is used for determining a target thread created by executing a preset event when the execution of the preset event is detected, and generating acceleration starting prompt information based on the target thread.
In some embodiments, the apparatus is applied to an electronic device, and the preset event is the start of the electronic device, the start of an application program, or the installation of the application program.
In some embodiments, the thread marking module 301 is further configured to: adding a preset label to the target thread to mark the target thread as a thread of a preset type;
and when receiving the acceleration termination prompt message, determining the target thread indicated by the acceleration termination prompt message, and deleting the preset label of the target thread.
In some embodiments, the resource allocation module 303 is further configured to:
and allocating processor resources for the thread to be scheduled according to a preset thread scheduling rule.
In specific implementation, the above modules may be implemented as independent entities, or may be combined arbitrarily to be implemented as the same or several entities, and specific implementation of the above modules may refer to the foregoing method embodiments, which are not described herein again.
It should be noted that the resource allocation apparatus provided in this embodiment of the present application and the resource allocation method in the foregoing embodiment belong to the same concept, and any method provided in the resource allocation method embodiment may be run on the resource allocation apparatus, and a specific implementation process thereof is described in detail in the resource allocation method embodiment and is not described herein again.
As can be seen from the above, the resource allocation apparatus provided in the embodiment of the present application includes a thread marking module 301, a thread determining module 302, and when receiving the acceleration start prompting message, the thread marking module 301 determines a target thread indicated by the acceleration start prompting message, and marks the target thread as a preset type thread. When the processor resources need to be allocated to the thread to be scheduled, the thread determining module 302 determines whether the thread to be scheduled is a preset type of thread, if so, the resource allocating module 303 allocates the processor resources to the thread according to a first rule, and if not, the resource allocating module 303 allocates the processor resources to the thread according to a second rule, wherein the speed or the number of allocating the processor resources to the thread based on the first rule is greater than the speed or the number of processing the resources to the thread allocator based on the second rule. In this way, some core threads are marked as threads of a preset type according to the acceleration start prompting information, and then the threads are distinguished from other non-core threads. And compared with non-core threads, more and faster processor resources are allocated to the core threads in the acceleration time period, so that the threads can execute tasks more efficiently, and the phenomenon that the electronic equipment is stuck is reduced.
The embodiment of the application also provides the electronic equipment. The electronic device can be a smart phone, a tablet computer and the like. Referring to fig. 4, fig. 4 is a schematic structural diagram of an electronic device according to an embodiment of the present disclosure. The electronic device 400 comprises a processor 401 and a memory 402. The processor 401 is electrically connected to the memory 402.
The processor 401 is a control center of the electronic device 400, connects various parts of the entire electronic device using various interfaces and lines, and performs various functions of the electronic device and processes data by running or calling a computer program stored in the memory 402 and calling data stored in the memory 402, thereby performing overall monitoring of the electronic device.
Memory 402 may be used to store computer programs and data. The memory 402 stores computer programs containing instructions executable in the processor. The computer program may constitute various functional modules. The processor 401 executes various functional applications and data processing by calling a computer program stored in the memory 402.
In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to one or more processes of the computer program into the memory 402 according to the following steps, and the processor 401 runs the computer program stored in the memory 402, so as to implement various functions:
when acceleration starting prompt information is received, determining a target thread indicated by the acceleration starting prompt information, and marking the target thread as a preset type thread;
when processor resources need to be allocated to a thread to be scheduled, judging whether the thread to be scheduled is a preset type thread;
when the thread to be scheduled is the thread of the preset type, allocating processor resources for the thread to be scheduled according to a first rule;
and when the thread to be scheduled is not the thread of the preset type, allocating processor resources to the thread to be scheduled according to a second rule, wherein the speed or the quantity of the processor resources allocated to the thread based on the first rule is greater than the speed or the quantity of the processor resources allocated to the thread allocator based on the second rule.
In some embodiments, please refer to fig. 5, and fig. 5 is a second structural diagram of an electronic device according to an embodiment of the present disclosure. The electronic device 400 further comprises: radio frequency circuit 403, display 404, control circuit 405, input unit 406, audio circuit 407, sensor 408, and power supply 409. The processor 401 is electrically connected to the radio frequency circuit 403, the display 404, the control circuit 405, the input unit 406, the audio circuit 407, the sensor 408, and the power source 409.
The radio frequency circuit 403 is used for transceiving radio frequency signals to communicate with a network device or other electronic devices through wireless communication.
The display screen 404 may be used to display information entered by or provided to the user as well as various graphical user interfaces of the electronic device, which may be comprised of images, text, icons, video, and any combination thereof.
The control circuit 405 is electrically connected to the display screen 404, and is configured to control the display screen 404 to display information.
The input unit 406 may be used to receive input numbers, character information, or user characteristic information (e.g., fingerprint), and to generate keyboard, mouse, joystick, optical, or trackball signal inputs related to user settings and function control. The input unit 406 may include a fingerprint recognition module.
The audio circuit 407 may provide an audio interface between the user and the electronic device through a speaker, microphone. Wherein the audio circuit 407 comprises a microphone. The microphone is electrically connected to the processor 401. The microphone is used for receiving voice information input by a user.
The sensor 408 is used to collect external environmental information. The sensors 408 may include one or more of ambient light sensors, acceleration sensors, gyroscopes, etc.
The power supply 409 is used to power the various components of the electronic device 400. In some embodiments, the power source 409 may be logically connected to the processor 401 through a power management system, so that functions of managing charging, discharging, and power consumption are implemented through the power management system.
Although not shown in the drawings, the electronic device 400 may further include a camera, a bluetooth module, and the like, which are not described in detail herein.
In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to one or more processes of the computer program into the memory 402 according to the following steps, and the processor 401 runs the computer program stored in the memory 402, so as to implement various functions:
when acceleration starting prompt information is received, determining a target thread indicated by the acceleration starting prompt information, and marking the target thread as a preset type thread;
when processor resources need to be allocated to a thread to be scheduled, judging whether the thread to be scheduled is a preset type thread;
when the thread to be scheduled is the thread of the preset type, allocating processor resources for the thread to be scheduled according to a first rule;
and when the thread to be scheduled is not the thread of the preset type, allocating processor resources to the thread to be scheduled according to a second rule, wherein the speed or the quantity of the processor resources allocated to the thread based on the first rule is greater than the speed or the quantity of the processor resources allocated to the thread allocator based on the second rule.
In some embodiments, the allocating processor resources is a change processing unit; when the processor resource is allocated to the thread to be scheduled according to the first rule, the processor 401 executes:
determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit; and migrating the thread to be scheduled from the current processing unit to the target processing unit for execution.
In some embodiments, the allocating processor resources is increasing an operating frequency of the processing unit; when the processor resource is allocated to the thread to be scheduled according to the first rule, the processor 401 executes:
acquiring a frequency adjustment value corresponding to the thread to be scheduled; and increasing the working frequency of the processing unit where the thread to be scheduled is located according to the frequency adjustment value.
In some embodiments, the allocation processor resource is an allocation processing unit; when allocating processor resources to the thread to be scheduled according to the first rule, the processor 401 executes:
determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit; and allocating the thread to be scheduled to the target processing unit for execution.
In some embodiments, when the accelerated start prompt is received, before determining the target thread indicated by the accelerated start prompt and marking the target thread as a preset type of thread, the processor 401 further performs:
when the execution of a preset event is detected, determining a target thread created by executing the preset event, and generating acceleration starting prompt information based on the target thread.
In some embodiments, the preset event is the electronic device starting, the application program starting or the application program installing.
In some embodiments, processor 401 further performs: adding a preset label to the target thread to mark the target thread as a thread of a preset type;
when acceleration termination prompt information is received, determining a target thread indicated by the acceleration termination prompt information, and deleting a preset label of the target thread.
Therefore, the electronic device determines the target thread indicated by the accelerated start prompt information when receiving the accelerated start prompt information, and marks the target thread as a preset type of thread. When the processor resources are required to be allocated to the thread to be scheduled, judging whether the thread to be scheduled is a thread of a preset type, if so, allocating the processor resources to the thread according to a first rule, and if not, allocating the processor resources to the thread according to a second rule, wherein the speed or the number of the processor resources allocated to the thread based on the first rule is greater than the speed or the number of the processor resources allocated to the thread allocator based on the second rule. In this way, some core threads are marked as threads of a preset type according to the acceleration start prompting information, and then the threads are distinguished from other non-core threads. And compared with non-core threads, more and faster processor resources are allocated to the core threads in the acceleration time period, so that the threads can execute tasks more efficiently, and the phenomenon that the electronic equipment is stuck is reduced.
An embodiment of the present application further provides a storage medium, where a computer program is stored in the storage medium, and when the computer program runs on a computer, the computer executes the resource allocation method according to any of the above embodiments.
It should be noted that, all or part of the steps in the methods of the above embodiments may be implemented by hardware related to instructions of a computer program, which may be stored in a computer-readable storage medium, which may include, but is not limited to: read Only Memory (ROM), Random Access Memory (RAM), magnetic or optical disks, and the like.
Furthermore, the terms "first", "second", and "third", etc. in this application are used to distinguish different objects, and are not used to describe a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or modules is not limited to only those steps or modules listed, but rather, some embodiments may include other steps or modules not listed or inherent to such process, method, article, or apparatus.
The resource allocation method, the resource allocation device, the storage medium, and the electronic device provided in the embodiments of the present application are described in detail above. The principle and the implementation of the present application are explained herein by applying specific examples, and the above description of the embodiments is only used to help understand the method and the core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.

Claims (11)

1. A method for resource allocation, comprising:
when acceleration starting prompt information is received, determining a target thread indicated by the acceleration starting prompt information, and marking the target thread as a preset type thread;
when processor resources need to be allocated to a thread to be scheduled, judging whether the thread to be scheduled is a preset type thread;
when the thread to be scheduled is the thread of the preset type, allocating processor resources for the thread to be scheduled according to a first rule;
and when the thread to be scheduled is not the thread of the preset type, allocating processor resources to the thread to be scheduled according to a second rule, wherein the speed or the quantity of the processor resources allocated to the thread based on the first rule is greater than the speed or the quantity of the processor resources allocated to the thread allocator based on the second rule.
2. The method of resource allocation according to claim 1, wherein said allocating processor resources is a change processing unit; the allocating processor resources to the thread to be scheduled according to the first rule includes:
determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit;
and migrating the thread to be scheduled from the current processing unit to the target processing unit for execution.
3. The method of claim 1, wherein said allocating processor resources is increasing an operating frequency of a processing unit; the allocating processor resources to the thread to be scheduled according to the first rule includes:
acquiring a frequency adjustment value corresponding to the thread to be scheduled;
and increasing the working frequency of the processing unit where the thread to be scheduled is located according to the frequency adjustment value.
4. The resource allocation method of claim 1, wherein said allocation processor resource is an allocation processing unit; the allocating processor resources to the thread to be scheduled according to the first rule includes:
determining a candidate processing unit with the maximum computing power from the candidate processing units as a target processing unit;
and allocating the thread to be scheduled to the target processing unit for execution.
5. The method for allocating resources according to claim 1, wherein when receiving the accelerated start prompt message, determining a target thread indicated by the accelerated start prompt message and marking the target thread as a preset type of thread is preceded by the steps of:
when the execution of a preset event is detected, determining a target thread created by executing the preset event, and generating acceleration starting prompt information based on the target thread.
6. The resource allocation method according to claim 5, wherein the method is applied to an electronic device, and the preset event is the electronic device starting, the application program starting or the application program installation.
7. The resource allocation method of any one of claims 1 to 6, further comprising: the marking the target thread as a preset type thread comprises:
adding a preset label to the target thread to mark the target thread as a thread of a preset type;
the method further comprises the following steps:
when acceleration termination prompt information is received, determining a target thread indicated by the acceleration termination prompt information, and deleting a preset label of the target thread.
8. The method of any of claims 1 to 6, wherein said allocating processor resources to said thread to be scheduled according to a second rule comprises:
and allocating processor resources for the thread to be scheduled according to a preset thread scheduling rule.
9. A resource allocation apparatus, comprising:
the thread marking module is used for determining a target thread indicated by the accelerated start prompt information when the accelerated start prompt information is received, and marking the target thread as a preset type thread;
the thread judging module is used for judging whether the thread to be dispatched is a preset type thread or not when the processor resources are required to be allocated to the thread to be dispatched;
the resource allocation module is used for allocating processor resources to the thread to be scheduled according to a first rule when the thread to be scheduled is the thread of the preset type;
and when the thread to be scheduled is not the preset type of thread, allocating processor resources to the thread to be scheduled according to a second rule, wherein the speed or the number of the processor resources allocated to the thread based on the first rule is greater than the speed or the number of the processor resources allocated to the thread allocator based on the second rule.
10. A storage medium having stored thereon a computer program, characterized in that, when the computer program is run on a computer, it causes the computer to execute the resource allocation method according to any one of claims 1 to 8.
11. An electronic device comprising a processor and a memory, said memory storing a computer program, wherein said processor is adapted to perform the resource allocation method of any of claims 1 to 8 by invoking said computer program.
CN202010261311.9A 2020-04-03 2020-04-03 Resource allocation method, device, storage medium and electronic equipment Pending CN113495787A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010261311.9A CN113495787A (en) 2020-04-03 2020-04-03 Resource allocation method, device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010261311.9A CN113495787A (en) 2020-04-03 2020-04-03 Resource allocation method, device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN113495787A true CN113495787A (en) 2021-10-12

Family

ID=77995361

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010261311.9A Pending CN113495787A (en) 2020-04-03 2020-04-03 Resource allocation method, device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN113495787A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024007970A1 (en) * 2022-07-06 2024-01-11 华为技术有限公司 Thread scheduling method and electronic device

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2024007970A1 (en) * 2022-07-06 2024-01-11 华为技术有限公司 Thread scheduling method and electronic device

Similar Documents

Publication Publication Date Title
US10628216B2 (en) I/O request scheduling method and apparatus by adjusting queue depth associated with storage device based on hige or low priority status
EP2893444B1 (en) Quota-based resource management
US8650570B2 (en) Method of assigning instructions in a process to a plurality of scheduler instances based on the instruction, in which each scheduler instance is allocated a set of negoitaited processor resources
CN107479951B (en) Process control method and device, storage medium and electronic equipment
CN111597042A (en) Service thread running method and device, storage medium and electronic equipment
CN110968415B (en) Scheduling method and device of multi-core processor and terminal
CN111831414A (en) Thread migration method and device, storage medium and electronic equipment
CN111831434A (en) Resource allocation method, device, storage medium and electronic equipment
CN111813521A (en) Thread scheduling method and device, storage medium and electronic equipment
CN111831433A (en) Resource allocation method, device, storage medium and electronic equipment
CN113535251A (en) Thread management method and device
CN111831432B (en) IO request scheduling method and device, storage medium and electronic equipment
CN111475299B (en) Memory allocation method and device, storage medium and electronic equipment
CN113495780A (en) Task scheduling method and device, storage medium and electronic equipment
CN111831436A (en) Scheduling method and device of IO (input/output) request, storage medium and electronic equipment
CN113495787A (en) Resource allocation method, device, storage medium and electronic equipment
US20200379804A1 (en) Multi-level scheduling
CN116578422A (en) Resource allocation method and electronic equipment
CN111831439A (en) IO request processing method and device, storage medium and electronic equipment
CN111831437A (en) Device management method, device, storage medium and electronic device
CN111831442A (en) Resource allocation method, device, storage medium and electronic equipment
CN111831438A (en) Resource allocation method, device, storage medium and electronic equipment
CN111831409B (en) Thread scheduling method and device, storage medium and electronic equipment
CN116069209A (en) Focus window processing method, device, equipment and storage medium
CN111078405B (en) Memory allocation method and device, storage medium and electronic equipment

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