Resource allocation method, device, storage medium and electronic device

By marking threads in the Android system and allocating processor resources according to the thread type, the problem that the Linux kernel cannot adapt to usage scenarios is solved, and the operation efficiency and user experience of electronic devices are improved.

CN113495787BActive Publication Date: 2024-12-13GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010261311.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-04-03
Publication Date
2024-12-13
Estimated Expiration
2040-04-03

AI Technical Summary

Technical Problem

In Android systems, the Linux kernel cannot clearly understand the user's usage scenarios, resulting in resource allocation being unable to adapt to the usage scenarios, resulting in lag in electronic devices when there are many threads waiting for execution.

Method used

When receiving the acceleration startup prompt message, mark the target thread as a thread of the preset type, and use different rules to allocate processor resources according to the thread type, giving priority to allocating more and faster resources to the core thread to reduce lag.

Benefits of technology

It effectively reduces the phenomenon of lag in electronic devices and improves thread execution efficiency and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113495787B_ABST
    Figure CN113495787B_ABST
Patent Text Reader

Abstract

An embodiment of the present application discloses a resource allocation method, device, storage medium and electronic device, wherein, when receiving an acceleration startup prompt message, the embodiment of the present application determines the target thread indicated by the acceleration startup prompt message, and marks the target thread as a preset type of thread; when it is necessary to allocate processor resources to the thread to be scheduled, it is determined whether the thread to be scheduled is a preset type of thread; if so, processor resources are allocated to the thread to be scheduled according to a first rule; if not, processor resources are allocated to the thread to be scheduled according to a second rule, wherein the speed or quantity of allocating processor resources to the thread based on the first rule is greater than the speed or quantity of allocating processing resources to the thread based on the second rule, so that the kernel can allocate more and faster processor resources to the core threads, so that these threads can perform tasks more efficiently, so as to reduce the jamming phenomenon of the electronic device.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of electronic equipment, and in particular to a resource allocation method, device, storage medium and electronic equipment. Background Art

[0002] With the continuous improvement of smartphone technology, users' demands for smartphones are no longer limited to basic functions such as calls and text messages. They also have increasing requirements for the running speed of mobile phones. Most smartphones now use the Android system. In the Android system, the Linux kernel at the bottom of the system architecture cannot clearly know the user's usage scenario, resulting in the allocation of resources not being adapted to the usage scenario. When there are many threads waiting to be executed, some threads will not get enough resources, causing the electronic device to freeze. Summary of the invention

[0003] Embodiments of the present application provide a resource allocation method, device, storage medium, and electronic device, which can reduce the lag phenomenon of the electronic device.

[0004] In a first aspect, an embodiment of the present application provides a resource allocation method, including:

[0005] When the acceleration start prompt information is received, determining the target thread indicated by the acceleration start prompt information, and marking the target thread as a thread of a preset type;

[0006] When it is necessary to allocate processor resources to the thread to be scheduled, determining whether the thread to be scheduled is a thread of a preset type;

[0007] When the thread to be scheduled is a thread of the preset type, allocating processor resources to the thread to be scheduled according to a first rule;

[0008] When the thread to be scheduled is not a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a second rule, wherein a speed or quantity of allocating processor resources to the thread based on the first rule is greater than a speed or quantity of allocating processor resources to the thread based on the second rule.

[0009] In a second aspect, an embodiment of the present application further provides a resource allocation device, including:

[0010] A thread marking module, configured to, when receiving the acceleration start prompt information, determine the target thread indicated by the acceleration start prompt information, and mark the target thread as a thread of a preset type;

[0011] A thread determination module, used for determining whether the thread to be scheduled is a thread of a preset type when processor resources need to be allocated to the thread to be scheduled;

[0012] A resource allocation module, configured to allocate processor resources to the thread to be scheduled according to a first rule when the thread to be scheduled is a thread of the preset type;

[0013] Furthermore, when the thread to be scheduled is not a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a second rule, wherein a speed or quantity of allocating processor resources to the thread based on the first rule is greater than a speed or quantity of allocating processor resources to the thread based on the second rule.

[0014] In a third aspect, an embodiment of the present application further provides a storage medium on which a computer program is stored. When the computer program is run on a computer, the computer executes a resource allocation method as provided in any embodiment of the present application.

[0015] In a fourth aspect, an embodiment of the present application further provides an electronic device, comprising a processor and a memory, wherein the memory has a computer program, and the processor executes a resource allocation method as provided in any embodiment of the present application by calling the computer program.

[0016] The technical solution provided by the embodiment of the present application determines the target thread indicated by the acceleration startup prompt information when receiving the acceleration startup prompt information, and marks the target thread as a preset type of thread. When it is necessary to allocate processor resources to the thread to be scheduled, it is determined whether the thread to be scheduled is a preset type of thread. If it is, processor resources are allocated to it according to the first rule. If not, processor resources are allocated to it according to the second rule, wherein the speed or quantity of allocating processor resources to the thread based on the first rule is greater than the speed or quantity of processing resources for the thread allocator based on the second rule. In this way, according to the acceleration startup prompt information, some core threads are marked as threads of preset types, thereby distinguishing these threads from other non-core threads. Moreover, compared with non-core threads, more and faster processor resources are allocated to core threads during the acceleration time period, so that these threads can perform tasks more efficiently, so as to reduce the phenomenon of jamming of electronic devices. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0018] Figure 1 A first flow chart of a resource allocation method provided in an embodiment of the present application.

[0019] Figure 2 A second flow chart of the resource allocation method provided in an embodiment of the present application.

[0020] Figure 3 A schematic diagram of the structure of a resource allocation device provided in an embodiment of the present application.

[0021] Figure 4 A first structural schematic diagram of an electronic device provided in an embodiment of the present application.

[0022] Figure 5 A second structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0023] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.

[0024] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0025] The embodiment of the present application provides a resource allocation method, and the execution subject of the resource allocation method can be the resource allocation device provided in the embodiment of the present application, or an electronic device integrating the resource allocation device, wherein the resource allocation device can be implemented in hardware or software. The electronic device can be a smart phone, a tablet computer, a PDA, a laptop computer, or a desktop computer.

[0026] See also Figure 1 , Figure 1 This is a schematic diagram of a first process flow of the resource allocation method provided in the embodiment of the present application. The specific process flow of the resource allocation method provided in the embodiment of the present application may be as follows:

[0027] In 101, when the acceleration start prompt information is received, a target thread indicated by the acceleration start prompt information is determined, and the target thread is marked as a thread of a preset type.

[0028] In the embodiment of the present application, the operating system of the electronic device may be a system based on the Linux kernel, for example, an Android operating system, etc. When an application installed in the electronic device is running, the system will create a process for it and allocate resources to the process.

[0029] A thread is an execution path of a process, the smallest unit of program execution, and the basic unit of CPU scheduling and dispatching. A process can have multiple threads, but at least one thread. In the embodiment of the present application, when a process has a task to execute, a new thread will be created to execute the task.

[0030] For threads of different priorities, thread scheduling is performed according to different thread scheduling rules, such as CFS (complete fair schedule) scheduling rules. In this embodiment, threads scheduled using CFS scheduling rules are called CFS threads, and the scheduling rules of the CFS scheduler are optimized to improve the execution efficiency of threads related to preset events.

[0031] If the processor of the electronic device is a multi-core processor, each processor core can be regarded as an independent processing unit. For example, if the electronic device is an octa-core processor, each core is an independent processing unit. Each processing unit has its own corresponding task queue, which contains tasks assigned to the processing unit, and each task is executed by a corresponding thread.

[0032] There may be one or more programs running simultaneously in an electronic device. Each program has at least one corresponding process, and a process has at least one thread executing tasks. Therefore, an electronic device will 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 will install the corresponding scheduling mechanism to allocate processing units to threads and select the optimal process to seize processor resources. After a thread is allocated a processing unit, if the thread enters the ready state, it will be added to the task queue of the allocated processing unit and wait to be executed.

[0033] Among them, the life cycle of a thread can be divided into five states: New state (New): After a thread object is created using the new keyword and the Thread class or its subclass, the thread object is in the new state. It maintains this state until the program starts () the thread. Ready state (Runnable): When the thread object calls the start () method, the thread enters the ready state. The thread in the ready state will be added to the ready queue and wait for the thread scheduler to schedule it. Running state (Running): If a thread in the ready state obtains CPU resources, it can execute the run () method. At this time, the thread is in the running state. The thread in the running state can change to the blocked state, the ready state, and the dead state. Blocked state (Blocked): If a thread executes methods such as sleep (sleep) and suspend (suspend), after losing the occupied resources, the thread enters the blocked state from the running state. It can re-enter the ready state after the sleep time has expired or the resources have been obtained. Dead state (Dead): When a thread in the running state completes the task or other termination conditions occur, the thread switches to the terminated state.

[0034] Among them, the default scheduling rules of the CFS scheduler are as follows: allocate processing units to threads according to the load balancing principle. After allocating processing units, allocate CPU usage time to threads according to thread priorities. For example, if two threads with the same priority run on one CPU, each thread will be allocated 50% of the CPU running time, that is, fair scheduling is achieved. When the priorities of the threads are different, the CPU running time will be allocated in proportion to the thread weights. Among them, the weight represents the priority of the thread. The larger the weight, the higher the priority and the greater the proportion of the allocated CPU running time. In general, the weight of a thread is represented by a nice value. The nice value is a specific number, and its value is generally within a preset range. The smaller the value, the higher the priority, which also means a larger weight value.

[0035] If the CFS scheduler always schedules CFS threads according to this rule, the allocation of device resources will not be adapted to the usage scenario. For example, when an Android phone starts an application (cold start is used as an example here), the Linux kernel will create several threads related to the startup process of this application. These threads obey the command of the kernel thread scheduler in the kernel. They compete fairly with other threads for resources and determine resource allocation according to relevant priorities and loads. In other words, the kernel treats startup-related threads and other background processes equally, and does not allocate more resources to these startup-related threads. The overall scheduling and frequency modulation strategy does not take other measures. When the application startup load is large, it will cause the application to start slowly, affecting user use.

[0036] Among them, application cold start means: when the application is started, there is no process of the application in the background, and the system needs to recreate a new process and assign it to the application. This way of starting the application is called cold start.

[0037] In some embodiments, when the execution of a preset event is detected, a target thread created by executing the preset event is determined, and acceleration startup prompt information is generated based on the target thread.

[0038] For example, preset events include but are not limited to the following events: mobile phone cold boot process, mobile phone hot boot process, application installation process, touch response process, payment process, and application startup process, among which the application startup process includes application hot boot process, application warm boot process, and application cold boot process.

[0039] In an embodiment of the present application, the relevant threads when the electronic device executes some events can be marked as core threads. For these core threads, the original scheduling rules of the CFS scheduler are optimized so that the CFS scheduler can allocate more resources to these core threads faster. The resources here include but are not limited to CPU resources (i.e., processor resources). For example, by monitoring the events executed by the electronic device, determine which threads are marked as core threads. For example, in order to speed up the cold start process of the application, when the cold start of the application is detected, determine the threads created by the cold start of the application and mark these threads as core threads. Among them, whether the system will freeze directly affects the user experience. The target thread created by the preset event can be executed as a ux (user experience) thread.

[0040] 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 may be added to the thread to mark the thread as a ux thread.

[0041] In some embodiments, in the embodiments of the present application, when the application framework layer of the system architecture detects a preset event, it determines the target thread and sends an accelerated startup prompt message to the kernel layer. After receiving the prompt message, the kernel layer marks the corresponding target thread as a ux thread.

[0042] After performing this operation, for the CFS scheduler, there are at least two types of threads among all CFS threads, ux threads and non-ux threads. Among them, the importance of ux threads is higher than that of non-ux threads. When allocating resources, the kernel will give priority to ux threads, and its resources will also be tilted towards ux threads.

[0043] In 102, when it is necessary to allocate processor resources to the thread to be scheduled, it is determined whether the thread to be scheduled is a thread of a preset type.

[0044] In 103, when the thread to be scheduled is a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a first rule.

[0045] In 104, when the thread to be scheduled is not a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a second rule, wherein a speed or quantity of allocating processor resources to the thread based on the first rule is greater than a speed or quantity of allocating processor resources to the thread based on the second rule.

[0046] In the embodiment of the present application, two different rules are used to allocate processor resources for ux threads and non-ux threads. For ux threads, allocation is performed according to the first rule, and for non-ux threads, allocation is performed according to the second rule. The speed or quantity of processor resources allocated to threads based on the first rule is greater than the speed or quantity of resources allocated to threads based on the second rule. That is, the first rule is equivalent to the second rule, and resources can be allocated to threads faster and more.

[0047] Among them, when it is determined according to the main scheduling policy of the CFS scheduler that a processing unit needs to be allocated to the thread to be scheduled, the thread to be scheduled needs to be migrated, or the working frequency of the current processing unit of the thread to be scheduled needs to be increased, it can be determined that processor resources need to be allocated to the thread to be scheduled. Among them, core migration refers to migrating the thread from the current core to another core. Take an eight-core CPU as an example, where the eight cores include four large cores and four small cores, where the four large cores form a group and the four small cores form a group. When migrating cores, it can be migration within a group or between different groups.

[0048] For example, when a processor needs to be allocated to a ux thread, a core with a small load or a large core may be preferentially allocated. Alternatively, when a ux thread needs to migrate a core, a large core may be preferentially migrated. For non-ux threads, resources may be allocated 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: allocating processor resources to the thread to be scheduled according to a preset thread scheduling rule.

[0049] In specific implementation, the present application is not limited by the execution order of the various steps described. If no conflict occurs, some steps can be performed in other orders or simultaneously.

[0050] In some embodiments, the allocating processor resources is changing the processing unit; the allocating processor resources to the thread to be scheduled according to the first rule includes: determining the candidate processing unit with the largest computing power from the candidate processing units as the target processing unit; migrating the thread to be scheduled from the current processing unit to the target processing unit for execution.

[0051] In this embodiment, when the CFS scheduler detects that the processing unit of a certain thread needs to be changed, for example, when it is detected that the current computing power of the processing unit where a certain thread is located is insufficient to execute the thread, or when it is detected that the load of the processing unit where a certain thread is located is too high, or when a certain thread needs to be migrated after being awakened, it can be determined that the thread needs to change the processing unit, which is commonly known as core migration. At this time, it is necessary to select a processing unit with higher performance or better computing power from other processing units, and migrate the thread from the current processing unit to the newly selected processing unit. The thread is used as a thread to be scheduled, and it is first determined whether the thread is a ux thread, for example, whether the thread has a ux label. If the thread has a ux label, after determining the candidate processing unit from other processing units other than the current processing unit, the candidate processing unit with the highest performance or the best computing power is selected from the candidate processing units as the 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 then can be executed quickly, so as to speed up the cold start of the application. If the thread does not have a ux label, the CFS scheduler selects a target processing unit from other processing units other than the current processing unit according to the default load balancing rule and performs core migration.

[0052] Linux uses the task_struct structure to describe and record threads. Each thread has its own unique task_struct structure. The task_struct records the thread identifier, state, priority, memory pointer, context data, and other information. Each task_struct has a sched_entity structure. The virtual running time of the process (the virtual running time of the thread recorded by the CFS scheduler, converted from the actual running time according to certain rules) and weight are stored in this structure. The kernel can add a ux tag to the task_struct data to mark the thread as a ux thread.

[0053] In some embodiments, the allocating of processor resources is to increase the operating frequency of the processing unit; the allocating of processor resources to the thread to be scheduled according to the first rule includes: obtaining a frequency adjustment value corresponding to the thread to be scheduled; and increasing the operating frequency of the processing unit where the thread to be scheduled is currently located according to the frequency adjustment value.

[0054] In this embodiment, the CFS scheduler sets a corresponding frequency adjustment value (boost value) for each ux thread, wherein the ux threads may have the same frequency adjustment value, or different boost values ​​may be set according to the priorities of the ux threads. When the CFS scheduler detects that it is necessary to increase the operating frequency of the processing unit where a certain thread is located, commonly known as frequency boosting, the CFS scheduler treats the thread as a thread to be scheduled, and first determines whether the thread is a ux thread. If it is a ux thread, the frequency adjustment value corresponding to the ux thread is obtained; according to the frequency adjustment value, the operating frequency of the processing unit where the ux thread is currently located is increased. If the thread is not a ux thread, the CFS scheduler will increase the frequency of the processing unit where the thread is currently located according to the default load balancing rule.

[0055] In some embodiments, the allocating processor resources is allocating processing units, and the allocating processor resources to the threads to be scheduled according to the first rule includes: determining a candidate processing unit with the largest computing power from the candidate processing units as the target processing unit; and allocating the threads to be scheduled to the target processing unit for execution.

[0056] In this embodiment, when the CFS scheduler needs to allocate a processing unit to a thread in the ready state, the thread is used as a thread to be scheduled, and it is first determined whether the thread is a ux thread. If it is a ux thread, all processing units are used as candidate processing units, and the candidate processing unit with the largest computing power is determined from the candidate processing units as the 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 allocates a processing unit to the thread according to the default load balancing rule.

[0057] As can be seen from the above, the resource allocation method provided in the embodiment of the present application, when receiving the acceleration startup prompt information, determines the target thread indicated by the acceleration startup prompt information, and marks the target thread as a preset type of thread. When it is necessary to allocate processor resources to the thread to be scheduled, it is determined whether the thread to be scheduled is a preset type of thread. If it is, processor resources are allocated to it according to the first rule. If not, processor resources are allocated to it according to the second rule, wherein the speed or quantity of allocating processor resources to the thread based on the first rule is greater than the speed or quantity of processing resources for the thread allocator based on the second rule. In this way, according to the acceleration startup prompt information, some core threads are marked as threads of preset types, thereby distinguishing these threads from other non-core threads. Moreover, compared with non-core threads, more and faster processor resources are allocated to core threads during the acceleration time period, so that these threads can perform tasks more efficiently, so as to reduce the phenomenon of jamming of electronic devices.

[0058] The method described in the above embodiments is further described in detail below with examples.

[0059] See also Figure 2 , Figure 2 A second flow chart of the resource allocation method provided in an embodiment of the present invention.

[0060] In this embodiment, the system architecture of the electronic device includes at least an application framework layer and a kernel layer, wherein the application framework layer executes 201 and 202, and the kernel layer executes 203 to 207. The method includes:

[0061] In 201, when it is detected that a preset event is executed, a target thread created by executing the preset event is determined, and acceleration start prompt information is generated based on the target thread.

[0062] In 202, when it is detected that the execution of the preset event is completed, acceleration termination prompt information is generated based on the target thread.

[0063] Among them, the preset events include but are not limited to the following events: mobile phone cold start process, mobile phone hot start process, application installation process, touch response process, payment process, and application startup process, among which the application startup process includes application hot start process, application warm start process, and application cold start process.

[0064] When the electronic device executes these events, it determines the target thread created by the electronic device executing the preset event, generates acceleration startup prompt information based on the target thread, and sends the acceleration startup prompt information to the kernel layer. When it is detected that the electronic device has completed the execution of the preset event, the application framework layer generates acceleration termination prompt information and sends it to the kernel layer.

[0065] In 203, when the acceleration start prompt information is received, a target thread indicated by the acceleration start prompt information is determined, and the target thread is marked as a thread of a preset type.

[0066] After receiving the prompt information, the kernel layer marks the corresponding target thread as a ux thread.

[0067] In 204, when it is necessary to allocate processor resources to the thread to be scheduled, it is determined whether the thread to be scheduled is a thread of a preset type.

[0068] When the thread to be scheduled is a thread of the preset type, execute 205 ; when the thread to be scheduled is not a thread of the preset type, execute 206 .

[0069] In 205, processor resources are allocated to the thread to be scheduled according to a first rule.

[0070] In 206, processor resources are allocated to the threads to be scheduled according to a second rule, wherein a speed or quantity of allocating processor resources to threads based on the first rule is greater than a speed or quantity of allocating processor resources to threads based on the second rule.

[0071] In the embodiment of the present application, two different rules are used to allocate processor resources for ux threads and non-ux threads. For ux threads, allocation is performed according to the first rule, and for non-ux threads, allocation is performed according to the second rule. The speed or quantity of processor resources allocated to threads based on the first rule is greater than the speed or quantity of resources allocated to threads based on the second rule. That is, the first rule is equivalent to the second rule, and resources can be allocated to threads faster and more.

[0072] When it is determined according to the main scheduling policy of the CFS scheduler that a processing unit needs to be allocated to the thread to be scheduled, it is necessary to migrate the thread to be scheduled, or it is necessary to increase the operating frequency of the current processing unit of the thread to be scheduled, it can be determined that processor resources need to be allocated to the thread to be scheduled. In these cases, resources can be allocated according to the corresponding first rule. For specific allocation, please refer to the above embodiment, which will not be repeated here.

[0073] In 207, when the acceleration termination prompt information is received, the target thread indicated by the acceleration termination prompt information is determined, and the preset tag of the target thread is deleted.

[0074] When the preset event is executed, the application framework layer can send an acceleration termination prompt message to the kernel layer. After receiving the prompt message, the kernel layer cancels the mark of the preset type of thread of the corresponding target thread, for example, deletes the ux tag, so that the thread is called a normal thread again.

[0075] The CFS scheduler performs periodic scheduling. For example, if the scheduling period is a tick, the CFS scheduler performs scheduling every tick. Every tick, the CFS scheduler performs scheduling management based on the execution status of the thread and the load of each processing unit.

[0076] When a ux thread is changed to a non-ux thread during execution, in the next scheduling cycle, the CFS scheduler returns to the default load balancing rule to schedule the thread.

[0077] As can be seen from the above, in the resource allocation method proposed in the embodiment of the present invention, when the application framework layer detects a specific event, the thread based on the specific event sends an acceleration notification to the kernel, and the kernel marks the threads related to these specific events as threads of a preset type to distinguish these threads from other non-core threads. Compared with non-core threads, more and faster processor resources are allocated to core threads during the acceleration period, so that these threads can perform tasks more efficiently, thereby reducing the phenomenon of lag in electronic devices.

[0078] In one embodiment, a resource allocation device is also provided. Figure 3 , Figure 3 The schematic diagram of the structure of the resource allocation device 300 provided in the embodiment of the present application is as follows: The resource allocation device 300 is applied to an electronic device, and the resource allocation device 300 includes a thread marking module 301, a thread determination module 302 and a resource allocation module 303, as follows:

[0079] The thread marking module 301 is used to determine the target thread indicated by the acceleration start prompt information when the acceleration start prompt information is received, and mark the target thread as a thread of a preset type;

[0080] The thread determination module 302 is used to determine whether the thread to be scheduled is a thread of a preset type when processor resources need to be allocated to the thread to be scheduled;

[0081] A resource allocation module 303, configured to allocate processor resources to the thread to be scheduled according to a first rule when the thread to be scheduled is a thread of the preset type;

[0082] Furthermore, when the thread to be scheduled is not a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a second rule, wherein a speed or quantity of allocating processor resources to the thread based on the first rule is greater than a speed or quantity of allocating processor resources to the thread based on the second rule.

[0083] In some embodiments, the allocated processor resources are to change the processing unit; the resource allocation module 303 is also used to: determine the candidate processing unit with the largest computing power from the candidate processing units as the target processing unit; migrate the thread to be scheduled from the current processing unit to the target processing unit for execution.

[0084] In some embodiments, the allocation of processor resources is to increase the operating frequency of the processing unit; the resource allocation module 303 is also used to: obtain the frequency adjustment value corresponding to the thread to be scheduled; and increase the operating frequency of the processing unit where the thread to be scheduled is currently located according to the frequency adjustment value.

[0085] In some embodiments, the allocated processor resources are allocated processing units; the resource allocation module 303 is also used to: determine the candidate processing unit with the largest computing power from the candidate processing units as the target processing unit; and allocate the thread to be scheduled to the target processing unit for execution.

[0086] In some embodiments, the resource allocation device 300 further includes:

[0087] The information generating module is used to determine the target thread created by executing the preset event when detecting the execution of the preset event, and to generate the acceleration start prompt information based on the target thread.

[0088] In some embodiments, the apparatus is applied to an electronic device, and the preset event is startup of the electronic device, startup of an application, or installation of an application.

[0089] In some embodiments, the thread marking module 301 is further used to: add a preset tag to the target thread to mark the target thread as a thread of a preset type;

[0090] And, when the acceleration termination prompt information is received, the target thread indicated by the acceleration termination prompt information is determined, and the preset tag of the target thread is deleted.

[0091] In some embodiments, the resource allocation module 303 is further configured to:

[0092] Processor resources are allocated to the threads to be scheduled according to preset thread scheduling rules.

[0093] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above modules can be found in the previous method embodiments, which will not be repeated here.

[0094] It should be noted that the resource allocation device provided in the embodiment of the present application belongs to the same concept as the resource allocation method in the above embodiment. Any method provided in the resource allocation method embodiment can be run on the resource allocation device. The specific implementation process is detailed in the resource allocation method embodiment and will not be repeated here.

[0095] As can be seen from the above, the resource allocation device proposed in the embodiment of the present application includes a thread marking module 301, a thread judgment module 302, and when receiving the acceleration startup prompt information, the thread marking module 301 determines the target thread indicated by the acceleration startup prompt information, and marks the target thread as a preset type of thread. When it is necessary to allocate processor resources to the thread to be scheduled, the thread judgment module 302 determines whether the thread to be scheduled is a thread of a preset type. If so, the resource allocation module 303 allocates processor resources to it according to the first rule. If not, the resource allocation module 303 allocates processor resources to it according to the second rule, wherein the speed or quantity of allocating processor resources to the thread based on the first rule is greater than the speed or quantity of processing resources for the thread allocator based on the second rule. In this way, according to the acceleration startup prompt information, some core threads are marked as threads of preset types, thereby distinguishing these threads from other non-core threads. Moreover, compared with non-core threads, more and faster processor resources are allocated to core threads during the acceleration time period, so that these threads can perform tasks more efficiently, so as to reduce the phenomenon of jamming of electronic devices.

[0096] The present application also provides an electronic device. The electronic device may be a smart phone, a tablet computer, or other device. Figure 4 , Figure 4 The first structural diagram of the electronic device provided in the embodiment of the present application is as follows: The electronic device 400 includes a processor 401 and a memory 402. The processor 401 is electrically connected to the memory 402.

[0097] The processor 401 is the control center of the electronic device 400. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or calling computer programs stored in the memory 402, and calling data stored in the memory 402, thereby monitoring the electronic device as a whole.

[0098] The memory 402 may be used to store computer programs and data. The computer programs stored in the memory 402 include instructions that can be executed in the processor. The computer programs may constitute various functional modules. The processor 401 executes various functional applications and data processing by calling the computer programs stored in the memory 402.

[0099] In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to the processes of one or more computer programs into the memory 402 according to the following steps, and the processor 401 runs the computer programs stored in the memory 402 to implement various functions:

[0100] When the acceleration start prompt information is received, determining the target thread indicated by the acceleration start prompt information, and marking the target thread as a thread of a preset type;

[0101] When it is necessary to allocate processor resources to the thread to be scheduled, determining whether the thread to be scheduled is a thread of a preset type;

[0102] When the thread to be scheduled is a thread of the preset type, allocating processor resources to the thread to be scheduled according to a first rule;

[0103] When the thread to be scheduled is not a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a second rule, wherein a speed or quantity of allocating processor resources to the thread based on the first rule is greater than a speed or quantity of allocating processor resources to the thread based on the second rule.

[0104] In some embodiments, see Figure 5 , Figure 5 A second structural diagram of an electronic device provided in an embodiment of the present application. The electronic device 400 further includes: a radio frequency circuit 403, a display screen 404, a control circuit 405, an input unit 406, an audio circuit 407, a sensor 408, and a power supply 409. The processor 401 is electrically connected to the radio frequency circuit 403, the display screen 404, the control circuit 405, the input unit 406, the audio circuit 407, the sensor 408, and the power supply 409, respectively.

[0105] The radio frequency circuit 403 is used to send and receive radio frequency signals to communicate with network devices or other electronic devices through wireless communication.

[0106] The display screen 404 may be used to display information input by a user or information provided to a user and various graphical user interfaces of the electronic device. These graphical user interfaces may be composed of images, texts, icons, videos and any combination thereof.

[0107] The control circuit 405 is electrically connected to the display screen 404 and is used to control the display screen 404 to display information.

[0108] The input unit 406 can be used to receive input numbers, character information or user feature information (such as fingerprints), and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control. The input unit 406 can include a fingerprint recognition module.

[0109] The audio circuit 407 can provide an audio interface between the user and the electronic device through a speaker and a microphone. The audio circuit 407 includes a microphone. The microphone is electrically connected to the processor 401. The microphone is used to receive voice information input by the user.

[0110] The sensor 408 is used to collect external environment information. The sensor 408 may include one or more sensors such as an environment brightness sensor, an acceleration sensor, and a gyroscope.

[0111] The power supply 409 is used to supply power to various components of the electronic device 400. In some embodiments, the power supply 409 may be logically connected to the processor 401 through a power management system, so that the power management system can manage charging, discharging, power consumption, and other functions.

[0112] Although not shown in the figure, the electronic device 400 may also include a camera, a Bluetooth module, etc., which will not be described in detail here.

[0113] In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to the processes of one or more computer programs into the memory 402 according to the following steps, and the processor 401 runs the computer programs stored in the memory 402 to implement various functions:

[0114] When the acceleration start prompt information is received, determining the target thread indicated by the acceleration start prompt information, and marking the target thread as a thread of a preset type;

[0115] When it is necessary to allocate processor resources to the thread to be scheduled, determining whether the thread to be scheduled is a thread of a preset type;

[0116] When the thread to be scheduled is a thread of the preset type, allocating processor resources to the thread to be scheduled according to a first rule;

[0117] When the thread to be scheduled is not a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a second rule, wherein a speed or quantity of allocating processor resources to the thread based on the first rule is greater than a speed or quantity of allocating processor resources to the thread based on the second rule.

[0118] In some embodiments, the allocating processor resources is changing the processing unit; when the processor resources are allocated to the thread to be scheduled according to the first rule, the processor 401 executes:

[0119] A candidate processing unit with the largest computing power is determined from the candidate processing units as the target processing unit; and the thread to be scheduled is migrated from the current processing unit to the target processing unit for execution.

[0120] In some embodiments, the allocating processor resources is to increase the operating frequency of the processing unit; when the processor resources are allocated to the thread to be scheduled according to the first rule, the processor 401 executes:

[0121] Obtain a frequency adjustment value corresponding to the thread to be scheduled; and increase the operating frequency of the processing unit where the thread to be scheduled is currently located according to the frequency adjustment value.

[0122] In some embodiments, the allocating processor resources is allocating processing units; when allocating processor resources to the threads to be scheduled according to the first rule, the processor 401 executes:

[0123] A candidate processing unit with the largest computing power is determined from the candidate processing units as the target processing unit; and the thread to be scheduled is allocated to the target processing unit for execution.

[0124] In some embodiments, when the accelerated startup prompt information is received, before determining the target thread indicated by the accelerated startup prompt information and marking the target thread as a thread of a preset type, the processor 401 further executes:

[0125] When it is detected that a preset event is executed, a target thread created by executing the preset event is determined, and acceleration start prompt information is generated based on the target thread.

[0126] In some embodiments, the preset event is startup of the electronic device, startup of an application, or installation of an application.

[0127] In some embodiments, the processor 401 further executes: adding a preset tag to the target thread to mark the target thread as a thread of a preset type;

[0128] When the acceleration termination prompt information is received, the target thread indicated by the acceleration termination prompt information is determined, and the preset tag of the target thread is deleted.

[0129] As can be seen from the above, an embodiment of the present application provides an electronic device, which, when receiving an acceleration startup prompt message, determines the target thread indicated by the acceleration startup prompt message, and marks the target thread as a preset type of thread. When it is necessary to allocate processor resources to the thread to be scheduled, it is determined whether the thread to be scheduled is a preset type of thread. If so, processor resources are allocated to it according to the first rule. If not, processor resources are allocated to it according to the second rule, wherein the speed or quantity of allocating processor resources to the thread based on the first rule is greater than the speed or quantity of processing resources for the thread allocator based on the second rule. In this way, according to the acceleration startup prompt message, some core threads are marked as preset types of threads, thereby distinguishing these threads from other non-core threads. Moreover, compared with non-core threads, more and faster processor resources are allocated to core threads during the acceleration time period, so that these threads can perform tasks more efficiently, so as to reduce the phenomenon of jamming of electronic devices.

[0130] An embodiment of the present application further provides a storage medium, wherein a computer program is stored in the storage medium. When the computer program runs on a computer, the computer executes the resource allocation method described in any of the above embodiments.

[0131] It should be noted that, a person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium, and the storage medium can include but is not limited to: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.

[0132] In addition, the terms "first", "second", and "third" in this application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or device that includes a series of steps or modules is not limited to the listed steps or modules, but some embodiments also include steps or modules that are not listed, or some embodiments also include other steps or modules inherent to these processes, methods, products, or devices.

[0133] The resource allocation method, device, storage medium and electronic device provided in the embodiments of the present application are described in detail above. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and core idea of ​​the present application. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present application.

Claims

1. A resource allocation method, characterized in that: include: When receiving the accelerated startup prompt information, determining the target thread indicated by the accelerated startup prompt information, and marking the target thread as a thread of a preset type, including: when the application framework layer detects a preset event, determining the target thread, and sending the accelerated startup prompt information to the kernel layer, after receiving the prompt information, the kernel layer adds a ux tag to the task_struct data, and marks the target thread as a ux thread; When it is necessary to allocate processor resources to a thread to be scheduled, it is determined whether the thread to be scheduled is a thread of a preset type, wherein when the CFS scheduler detects that the processing unit of a thread needs to be changed, or when the CFS scheduler detects that the operating frequency of the processing unit where a thread is located needs to be increased, or when the CFS scheduler needs to allocate a processing unit to a thread in a ready state, the thread is considered as a thread to be scheduled; When the thread to be scheduled is a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a first rule; when the thread to be scheduled is not a thread of the preset type, processor resources are allocated to the thread to be scheduled according to a second rule, wherein the speed or quantity of allocating processor resources to the thread based on the first rule is greater than the speed or quantity of allocating processor resources to the thread based on the second rule, including: when the thread to be scheduled is a ux thread, a candidate processing unit is determined from other processing units other than the current processing unit, and a candidate processing unit with the highest performance or the best computing power is selected from the candidate processing units as the target processing unit, and the ux thread is migrated from the current processing unit to the newly selected processing unit; when the thread to be scheduled is not a ux thread, the CFS scheduler selects a target processing unit from other processing units other than the current processing unit according to a default load balancing rule, and performs core migration processing; or, when the thread to be scheduled is a ux thread, a frequency adjustment value corresponding to the ux thread is obtained; according to the frequency adjustment value, the working frequency of the processing unit where the ux thread is currently located is increased; when the thread to be scheduled is not a ux thread, the CFS scheduler increases the frequency of the processing unit where the non-ux thread is currently located according to the default load balancing rule.

2. The resource allocation method according to claim 1, characterized in that: The allocating processor resources is to change the processing unit; and the allocating processor resources to the thread to be scheduled according to the first rule includes: Determine a candidate processing unit with the largest computing capability from the candidate processing units as the target processing unit; The thread to be scheduled is migrated from the current processing unit to the target processing unit for execution.

3. The resource allocation method according to claim 1, characterized in that: The allocating processor resources is to increase the operating frequency of the processing unit; and the allocating processor resources to the thread to be scheduled according to the first rule includes: Obtaining a frequency adjustment value corresponding to the thread to be scheduled; According to the frequency adjustment value, the operating frequency of the processing unit where the thread to be scheduled is currently located is increased.

4. The resource allocation method according to claim 1, characterized in that: The allocating processor resources is allocating processing units; the allocating processor resources to the threads to be scheduled according to the first rule includes: Determine a candidate processing unit with the largest computing capability from the candidate processing units as the target processing unit; Allocate the thread to be scheduled to the target processing unit for execution.

5. The resource allocation method according to claim 1, characterized in that: The method further comprises: when receiving the acceleration startup prompt information, determining the target thread indicated by the acceleration startup prompt information, and marking the target thread as a thread of a preset type. When it is detected that a preset event is executed, a target thread created by executing the preset event is determined, and acceleration start prompt information is generated based on the target thread.

6. The resource allocation method according to claim 5, characterized in that: The method is applied to an electronic device, and the preset event is startup of the electronic device, startup of an application program, or installation of an application program.

7. The resource allocation method according to any one of claims 1 to 6, characterized in that: Also includes: The step of marking the target thread as a thread of a preset type includes: Adding a preset tag to the target thread to mark the target thread as a thread of a preset type; The method further comprises: When the acceleration termination prompt information is received, the target thread indicated by the acceleration termination prompt information is determined, and the preset tag of the target thread is deleted.

8. The resource allocation method according to any one of claims 1 to 6, characterized in that: The allocating processor resources to the thread to be scheduled according to the second rule includes: Processor resources are allocated to the threads to be scheduled according to preset thread scheduling rules.

9. A resource allocation device, characterized in that: include: A thread marking module is used to determine the target thread indicated by the acceleration startup prompt information when receiving the acceleration startup prompt information, and mark the target thread as a thread of a preset type, including: when the application framework layer detects a preset event, the application framework layer determines the target thread and sends the acceleration startup prompt information to the kernel layer, and after receiving the prompt information, the kernel layer adds a ux tag to the task_struct data and marks the target thread as a ux thread; A thread determination module, used for determining whether the thread to be scheduled is a thread of a preset type when it is necessary to allocate processor resources to the thread to be scheduled, wherein when the CFS scheduler detects that the processing unit of a certain thread needs to be changed, or when the CFS scheduler detects that the working frequency of the processing unit where a certain thread is located needs to be increased, or when the CFS scheduler needs to allocate a processing unit to a thread in a ready state, the thread is regarded as a thread to be scheduled; A resource allocation module, for allocating processor resources to the thread to be scheduled according to a first rule when the thread to be scheduled is a thread of the preset type; and for allocating processor resources to the thread to be scheduled according to a second rule when the thread to be scheduled is not a thread of the preset type, wherein the speed or quantity of allocating processor resources to the thread based on the first rule is greater than the speed or quantity of allocating processor resources to the thread based on the second rule, including: when the thread to be scheduled is a ux thread, a candidate processing unit is determined from other processing units other than the current processing unit, and the processing unit with the highest performance or the best computing power is selected from the candidate processing units The candidate processing unit is selected as the target processing unit, and the ux thread is migrated from the current processing unit to the newly selected processing unit; when the thread to be scheduled is not a ux thread, the CFS scheduler selects the target processing unit from other processing units other than the current processing unit according to the default load balancing rule, and performs core migration processing; or, when the thread to be scheduled is a ux thread, the frequency adjustment value corresponding to the ux thread is obtained; according to the frequency adjustment value, the working frequency of the processing unit where the ux thread is currently located is increased; when the thread to be scheduled is not a ux thread, the CFS scheduler increases the frequency of the processing unit where the non-ux thread is currently located according to the default load balancing rule.

10. A storage medium having a computer program stored thereon, characterized in that: When the computer program is executed on a computer, the computer is enabled 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, wherein the memory stores a computer program, characterized in that: The processor is configured to execute the resource allocation method according to any one of claims 1 to 8 by calling the computer program.