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 aresource allocation apparatus 300 according to an embodiment of the present disclosure. Theresource allocation apparatus 300 is applied to an electronic device, and theresource allocation apparatus 300 includes athread marking module 301, athread determining module 302, and aresource allocation module 303, as follows:
thethread 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;
thethread 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;
aresource 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; theresource 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; theresource 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; theresource 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, theresource 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, thethread 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, theresource 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 athread marking module 301, athread determining module 302, and when receiving the acceleration start prompting message, thethread 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, thethread determining module 302 determines whether the thread to be scheduled is a preset type of thread, if so, theresource allocating module 303 allocates the processor resources to the thread according to a first rule, and if not, theresource 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. Theelectronic device 400 comprises aprocessor 401 and amemory 402. Theprocessor 401 is electrically connected to thememory 402.
Theprocessor 401 is a control center of theelectronic 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 thememory 402 and calling data stored in thememory 402, thereby performing overall monitoring of the electronic device.
Memory 402 may be used to store computer programs and data. Thememory 402 stores computer programs containing instructions executable in the processor. The computer program may constitute various functional modules. Theprocessor 401 executes various functional applications and data processing by calling a computer program stored in thememory 402.
In this embodiment, theprocessor 401 in theelectronic device 400 loads instructions corresponding to one or more processes of the computer program into thememory 402 according to the following steps, and theprocessor 401 runs the computer program stored in thememory 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. Theelectronic device 400 further comprises:radio frequency circuit 403,display 404,control circuit 405,input unit 406,audio circuit 407,sensor 408, andpower supply 409. Theprocessor 401 is electrically connected to theradio frequency circuit 403, thedisplay 404, thecontrol circuit 405, theinput unit 406, theaudio circuit 407, thesensor 408, and thepower source 409.
Theradio frequency circuit 403 is used for transceiving radio frequency signals to communicate with a network device or other electronic devices through wireless communication.
Thedisplay 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.
Thecontrol circuit 405 is electrically connected to thedisplay screen 404, and is configured to control thedisplay screen 404 to display information.
Theinput 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. Theinput unit 406 may include a fingerprint recognition module.
Theaudio circuit 407 may provide an audio interface between the user and the electronic device through a speaker, microphone. Wherein theaudio circuit 407 comprises a microphone. The microphone is electrically connected to theprocessor 401. The microphone is used for receiving voice information input by a user.
Thesensor 408 is used to collect external environmental information. Thesensors 408 may include one or more of ambient light sensors, acceleration sensors, gyroscopes, etc.
Thepower supply 409 is used to power the various components of theelectronic device 400. In some embodiments, thepower source 409 may be logically connected to theprocessor 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, theelectronic device 400 may further include a camera, a bluetooth module, and the like, which are not described in detail herein.
In this embodiment, theprocessor 401 in theelectronic device 400 loads instructions corresponding to one or more processes of the computer program into thememory 402 according to the following steps, and theprocessor 401 runs the computer program stored in thememory 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, theprocessor 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, theprocessor 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, theprocessor 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, theprocessor 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.