Thread management method and device
By identifying and hibernating abnormal threads that do not participate in image rendering in the processing unit of electronic equipment, the problem of CPU preemption and battery life heating caused by foreground threads is solved, and the smooth operation of the system and the optimization of battery life are achieved.
Patent Information
- Application Number
- CN202410811297.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-17
AI Technical Summary
After the application is upgraded, abnormal foreground threads lead to CPU resource preemption, causing system freezes and battery life and heating problems, which are difficult to effectively solve with existing technology.
By determining the time threshold based on historical operating data when running task threads in multiple processing units of the electronic device, finding the thread collection participating in the image rendering task, and sleeping when the task thread running time exceeds the threshold and is not within the rendering task collection, To avoid abnormal threads from seizing CPU resources.
Effectively identify and control abnormal front-end threads to avoid CPU resource preemption, ensure smooth system operation and control battery life and heating issues.
Smart Images

Figure CN118656189A
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of thread management, and specifically relates to a thread management method and device. Background Art
[0002] With the popularity of smart electronic devices, various applications emerge in an endless stream, and the quality of different applications varies. In addition, the iterative updates of application versions will also introduce new problems. For example, for scenarios such as watching videos, browsing products, and updating new seasons of games, problems such as unsmooth interface sliding and overheating of electronic devices often occur after the application is upgraded. Among them, the main reasons for such problems are: the application thread runs at an abnormally high load, occupying CPU (Central Processing Unit) resources, thereby causing power consumption and system freezes.
[0003] At present, in the related technology, for the power consumption and jamming problems caused by abnormally high-load threads, such as Figure 2 As shown, in the case where the abnormally high-load thread is a background thread, system resource restriction operations are performed on the abnormal background thread by limiting the CPU usage of the abnormal background thread, running a small-core CPU, freezing the thread, etc., so as to reduce the CPU resource occupation of the abnormal background thread.
[0004] However, in the case where the abnormally high-load thread is the foreground thread of a foreground application that interacts with the user, since the internal logic between the threads of the third-party applications is unclear, it is impossible to effectively limit the resources of the abnormal foreground thread, thereby failing to solve the abnormal power consumption and system lag problems caused by the abnormal foreground thread, and the electronic device has battery life and heating problems. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a thread management method and device that can identify and control abnormal foreground threads and effectively prevent abnormal foreground threads from occupying CPU resources.
[0006] In a first aspect, an embodiment of the present application provides a thread management method, which is executed by an electronic device, wherein the electronic device includes multiple processing units, and the thread management method includes: when a task thread is running through a first processing unit among the multiple processing units, determining a time threshold for the first processing unit to run the task thread according to historical running data of the task thread in the multiple processing units within a first historical period; searching for threads participating in the rendering task of each frame of an image within the first historical period to obtain a target thread set; when the running time of the task thread reaches the time threshold and the task thread is not in the target thread set, controlling the task thread to sleep.
[0007] In a second aspect, an embodiment of the present application provides a thread management device, which is applied to an electronic device, wherein the electronic device includes multiple processing units, and the thread management device includes: a processing module, which is used to determine, when a task thread is running through a first processing unit among the multiple processing units, a time threshold for the first processing unit to run the task thread based on historical running data of the task thread in the multiple processing units within a first historical period; the processing module is also used to search for threads participating in the rendering task of each frame of an image within the first historical period to obtain a target thread set; and a control module is used to control the task thread to sleep when the running time of the task thread reaches the time threshold and the task thread is not in the target thread set.
[0008] In a third aspect, an embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores programs or instructions that can be run on the processor, and when the programs or instructions are executed by the processor, the steps of the thread management method of the first aspect are implemented.
[0009] In a fourth aspect, an embodiment of the present application provides a readable storage medium having a program or instruction stored thereon, which, when executed by a processor, implements the steps of the thread management method of the first aspect.
[0010] In a fifth aspect, an embodiment of the present application provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the steps of the thread management method of the first aspect.
[0011] In a sixth aspect, an embodiment of the present application provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement the steps of the thread management method of the first aspect.
[0012] In the thread management method provided in the embodiment of the present application, when the task thread is run by the first processing unit among multiple processing units, the time threshold for the first processing unit to run the task thread is determined according to the historical running data of the task thread in multiple processing units in the first historical period; the thread participating in the rendering task of each frame of the image in the first historical period is searched to obtain the target thread set; when the running time of the task thread reaches the time threshold and the task thread is not in the target thread set, the task thread is controlled to sleep. Through the above-mentioned thread management method, when the task thread is run by the first processing unit among multiple processing units of the electronic device, based on the historical running data of the task thread in multiple processing units, the time threshold for the task thread to run in the first processing unit is determined, and then when the running time of the task thread in the first processing unit exceeds the time threshold, and the task thread is a thread that does not participate in the screen display work, the task thread is controlled to temporarily enter sleep. In this way, the foreground abnormal thread can be identified and controlled, thereby effectively avoiding the foreground abnormal thread from occupying CPU resources, while ensuring the smooth operation of the system, effectively controlling the battery life heating problem caused by the foreground abnormal thread. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 A flowchart of a thread management method provided in an embodiment of the present application;
[0014] Figure 2 It is a schematic diagram of a thread management method in the related art;
[0015] Figure 3 One of the principle diagrams of the thread management method provided in the embodiment of the present application;
[0016] Figure 4 The second schematic diagram of the thread management method provided in the embodiment of the present application;
[0017] Figure 5 The third schematic diagram of the thread management method provided in the embodiment of the present application;
[0018] Figure 6 The fourth schematic diagram of the thread management method provided in the embodiment of the present application;
[0019] Figure 7 The fifth schematic diagram of the thread management method provided in the embodiment of the present application;
[0020] Figure 8 A structural block diagram of a thread management device provided in an embodiment of the present application;
[0021] Fig. 9 A structural block diagram of an electronic device provided in an embodiment of the present application;
[0022] Fig.10A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0023] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0024] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way are interchangeable where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0025] The thread management method provided in the embodiment of the present application is described in detail below through specific embodiments and application scenarios in conjunction with the accompanying drawings.
[0026] like Figure 1 As shown, the embodiment of the present application provides a thread management method, which may include the following S102 to S106:
[0027] S102: When a task thread is executed by a first processing unit among multiple processing units, determine a time threshold for the first processing unit to execute the task thread according to historical execution data of the task thread in the multiple processing units within a first historical period.
[0028] The thread management method proposed in the embodiment of the present application is executed by an electronic device, which may specifically be an intelligent electronic device such as a smart phone, a tablet computer, a laptop computer, and a smart watch, and is not specifically limited here.
[0029] The electronic device includes a plurality of processing units.
[0030] In actual application, the above-mentioned multiple processing units may be multiple single-core processors, or multiple processor cores in a multi-core processor, which is not specifically limited here.
[0031] It can be understood that the multiple processing units in the electronic device can be divided into three categories according to the processing capabilities and performances of the processing units.
[0032] For example, for multiple processor cores in a multi-core processor, according to the different processing capabilities and performances of the multiple processor cores, the multiple processor cores can be divided into three clusters, namely, a small core cluster, a medium core cluster and a large core cluster. Each cluster includes one or more processor cores. Furthermore, the processing capabilities of the processor cores in a cluster are the same, and the processing capabilities of the processor cores in different clusters are different. Furthermore, the processor core in the small core cluster is referred to as the small core, the processor core in the medium core cluster is referred to as the medium core, and the processor core in the large core cluster is referred to as the large core. The large core has the highest processing capability and the strongest performance, the medium core has the second highest processing capability and performance, and the small core has the weakest processing capability and performance.
[0033] Exemplarily, a multi-core processor includes 8 processor cores: CPU0, CPU1, CPU2, CPU3, CPU4, CPU5, CPU6 and CPU7. Among them, the small core cluster includes CPU0, CPU1 and CPU2; the medium core cluster includes CPU3, CPU4, CPU5 and CPU6; the large core cluster includes CPU7.
[0034] On this basis, due to the different processing capabilities of processing units in different clusters, the same task thread requires different running time on processing units in different clusters. During the running of the task thread, the scheduler will select one processing unit from multiple processing units to run the task thread. The above-mentioned first processing unit is a processing unit selected by the scheduler from multiple processing units to run the task thread in the current statistical period.
[0035] The above statistical period is related to the screen refresh rate of the electronic device, specifically, T=a / f, where T represents the statistical period, a is a constant, and f represents the screen refresh rate. For example, a=1, the screen refresh rate f=60Hz, then the statistical period T=16ms.
[0036] Furthermore, the task thread is a foreground thread or a background thread. The foreground thread is a thread in the foreground application, which is the application that the current user is interacting with; the background thread is a thread in the background application, which is an application that is invisible to the user and retreats from the foreground to the background.
[0037] Furthermore, the above-mentioned first historical period may include multiple statistical cycles, the starting time of the first historical period may change dynamically based on the running time of the task thread, the duration range of the first historical period may be fixed, and the specific duration range of the above-mentioned first historical period may be set according to actual conditions in this field, and no specific restrictions are made here.
[0038] Furthermore, the above historical operation data includes but is not limited to: the processing unit running the task thread in each statistical period of the first historical period, and the actual running time of the task thread in each statistical period, which is not specifically limited here.
[0039] Furthermore, the time threshold is the maximum running time allowed for the task thread to run in the first processing unit in the current statistical cycle. If the running time of the task thread in the first processing unit in the current statistical cycle exceeds the time threshold, it indicates that the task thread is an abnormally high-load thread.
[0040] Specifically, in the thread management method provided in the embodiment of the present application, when the scheduler selects the first processing unit among multiple processing units of the electronic device to run a task thread within the current statistical period, the maximum running time, i.e., the time threshold, of the task thread allowed to run within the first processing unit within the current statistical period is calculated based on the historical running data of the task thread in the multiple processing units within the first historical period.
[0041] S104: Searching for threads participating in the rendering task of each frame of the image in the first historical period to obtain a target thread set.
[0042] Among them, a frame can be understood as a picture in a video or animation, and video and animation special effects are composed of countless pictures, each of which is a frame.
[0043] It is understandable that the display process of a frame of picture can be simply understood as: the application transmits the rendered data to the graphics through the rendering thread, and finally displays the graphics on the display interface of the electronic device.
[0044] Specifically, in the thread management method provided in the embodiment of the present application, in the process of running the task thread, the threads participating in the rendering task of each frame of the image in the first historical period are recorded in real time to obtain a target thread set.
[0045] S106: When the running time of the task thread reaches the time threshold and the task thread is not in the target thread set, control the task thread to sleep.
[0046] Wherein, when the running time of the task thread in the first processing unit in the current statistical period exceeds the time threshold corresponding to the first processing unit, it indicates that the task thread is an abnormally high-load thread in the current statistical period.
[0047] Furthermore, when the task thread is not in the target thread set, it means that the task thread is a thread that does not participate in the screen display work.
[0048] Specifically, in the thread management method provided in the embodiment of the present application, when the running time of the task thread in the first processing unit reaches the time threshold in the current statistical cycle, and the task thread is not in the target thread set, that is, when it is determined that the task thread is an abnormally high-load thread that does not participate in the screen display work in the current statistical cycle, the task thread is controlled to sleep, so that the task thread gives up CPU resources for other key threads participating in the screen display work in the remaining time of the current statistical cycle, until the next statistical cycle, the processing unit is reselected to run the task thread. In this way, the foreground abnormal thread can be identified and controlled, thereby effectively preventing the foreground abnormal thread from preempting the CPU resources of the key thread participating in the screen display work, and effectively controlling the battery life and heating problems caused by the foreground abnormal thread while ensuring the smooth operation of the system, thereby solving the uncontrollable abnormal problems caused by application upgrades and updates.
[0049] Through the above-mentioned thread management method provided by the embodiment of the present application, when the task thread is run through the first processing unit among multiple processing units, the time threshold for the first processing unit to run the task thread is determined according to the historical running data of the task thread in multiple processing units in the first historical period; the thread participating in the rendering task of each frame of the image in the first historical period is searched to obtain the target thread set; when the running time of the task thread reaches the time threshold and the task thread is not in the target thread set, the task thread is controlled to sleep. Through the above-mentioned thread management method, when the task thread is run through the first processing unit among multiple processing units of the electronic device, based on the historical running data of the task thread in multiple processing units, the time threshold for the task thread to run in the first processing unit is determined, and then when the running time of the task thread in the first processing unit exceeds the time threshold, and the task thread is a thread that does not participate in the screen display work, the task thread is controlled to temporarily enter sleep. In this way, the foreground abnormal thread can be identified and controlled, thereby effectively avoiding the foreground abnormal thread from occupying CPU resources, while ensuring the smooth operation of the system, effectively controlling the battery life and heating problems caused by the foreground abnormal thread.
[0050] In the embodiment of the present application, the step of determining the time threshold for the first processing unit to run the task thread according to the historical running data of the task thread in the plurality of processing units in the first historical period may specifically include the following S108 to S112:
[0051] S108: Counting historical running data of the task thread in the plurality of processing units in the first historical period according to a statistical cycle.
[0052] Among them, the above statistical period is related to the screen refresh rate of the electronic device.
[0053] Furthermore, the above-mentioned first historical period may include multiple statistical cycles, the starting time of the first historical period may change dynamically based on the running time of the task thread, the duration range of the first historical period may be fixed, and the specific duration range of the above-mentioned first historical period may be set according to actual conditions in this field, and no specific restrictions are made here.
[0054] Furthermore, the above historical operation data includes but is not limited to: the processing unit running the task thread in each statistical period of the first historical period, and the actual running time of the task thread in each statistical period, which is not specifically limited here.
[0055] S110: Determine, according to the statistical cycle, the historical operation data and the operation parameters of the plurality of processing units, the actual operation time or the theoretical operation time of the task thread executed by the first processing unit in each statistical cycle of the first historical period.
[0056] The above operating parameters include but are not limited to: the actual operating frequency, maximum operating frequency and maximum computing power value of the processing unit running the task thread in each statistical period of the first historical period, and no specific restrictions are made here.
[0057] Furthermore, the above-mentioned actual running time is the actual running time of the task thread in the first processing unit when the task thread is run through the first processing unit within the statistical period of the first historical period; the above-mentioned theoretical running time is the running time converted to the first processing unit through calculation when the task thread is not run through the first processing unit within the statistical period of the first historical period.
[0058] S112: Determine a time threshold for the first processing unit to execute the task thread according to an actual execution time or a theoretical execution time of the task thread executed by the first processing unit in each statistical period.
[0059] Specifically, in the thread management method provided in the embodiment of the present application, the historical running data of the task thread in the first historical period in multiple processing units are counted according to the statistical cycle, and then the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period is determined according to the statistical cycle, the historical running data and the running parameters of the multiple processing units. On this basis, the time threshold of the first processing unit running the task thread is determined according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period. In this way, based on the actual running time of the task thread running through the first processing unit in each statistical period of the first historical period, or the theoretical running time of the task thread converted to the first processing unit in each statistical period of the first historical period, a reference basis for judging whether the task thread is a high-load thread in the current statistical period, i.e., a time threshold, is provided, which ensures the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0060] In the above-mentioned embodiment provided by the present application, in the process of determining the time threshold for the first processing unit to run the task thread according to the historical running data of the task thread in multiple processing units in the first historical period, the historical running data of the task thread in multiple processing units in the first historical period are counted according to the statistical period; the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period is determined according to the statistical period, the historical running data and the running parameters of the multiple processing units; the time threshold for the first processing unit to run the task thread is determined according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period. In this way, based on the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period, the time threshold for the task thread to be allowed to run in the first processing unit in the current statistical period is calculated, which ensures the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0061] In the embodiment of the present application, the above S112 may specifically include the following S112a and S112b:
[0062] S112a: Calculate the average running time of the task thread running through the first processing unit in the first historical period according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period.
[0063] The above average running time is the average of the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period.
[0064] For example, Figure 4 As shown, the first historical period includes the first statistical period, the second statistical period and the third statistical period. In the first statistical period, the task thread runs in the big core CPU, and the actual running time of the task thread in the big core CPU is t b1 , the theoretical running time of the task thread converted to the medium-core CPU is t m1 , the actual running time of the task thread converted to the small-core CPU is t s1 In the second statistical period, the task thread runs in the middle core CPU, and the actual running time of the task thread in the middle core CPU is t m2 , the theoretical running time of the task thread converted to the large-core CPU is t b2 , the actual running time of the task thread converted to the small-core CPU is t s2 In the third statistical period, the task thread runs in the small-core CPU, and the actual running time of the task thread in the small-core CPU is t s3 , the theoretical running time of the task thread converted to the medium-core CPU is t m3 , the actual running time of the task thread converted to the large-core CPU is t b3 .
[0065] On this basis, when the first processing unit is a large-core CPU, the average running time t of the task thread running through the first processing unit in the first historical period is min =(t b1 +t b2 +t b3 ) / 3. In the case where the first processing unit is a medium-core CPU, the average running time t of the task thread running through the first processing unit in the first historical period min =(t m1 +t m2 +t m3 ) / 3. In the case where the first processing unit is a small-core CPU, the average running time t of the task thread running through the first processing unit in the first historical period min =(t s1 +t s2 +t s3 ) / 3.
[0066] S112b: Determine the product of the average running time and the constant parameter as the time threshold for the first processing unit to run the task thread.
[0067] The values of the above constant parameters are adjustable, and the value range of the above constant parameters is related to the statistical period and the average running time. <c≤(T / t min ), where c represents a constant parameter, T represents a statistical period, and t min Indicates the average running time of the task thread executed by the first processing unit during the first historical period.
[0068] Furthermore, the time threshold t of the first processing unit running the task thread in the current statistical period max =c×t min .
[0069] Exemplarily, the average running time t of the task thread executed by the first processing unit during the first historical period is min =4.8ms, constant parameter c=2, then the time threshold t of the first processing unit running the task thread in the current statistical period max =4.8×2=9.6ms.
[0070] Specifically, in the thread management method provided by the embodiment of the present application, the average value of the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period is determined as the average running time of the task thread running through the first processing unit in the first historical period, and then the product of the average running time and the constant parameter is determined as the time threshold for the first processing unit to run the task thread. In this way, the running time of the task thread on the first processing unit in the current statistical period is predicted through the historical time data of the task thread running on the first processing unit, and the maximum running time allowed for the task thread to run in the first processing unit in the current statistical period is set, i.e., the time threshold, to ensure the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0071] In the above-mentioned embodiment provided by the present application, in the process of determining the time threshold for the first processing unit to run the task thread according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period, the average running time of the task thread running through the first processing unit in the first historical period is calculated according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period; and the product of the average running time and the constant parameter is determined as the time threshold for the first processing unit to run the task thread. In this way, based on the historical time data of the task thread running on the first processing unit, the maximum running time, i.e., the time threshold, which is allowed for the task thread to run in the first processing unit in the current statistical period is dynamically set, thereby ensuring the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0072] In the embodiment of the present application, the above S110 may specifically include the following S110a to S110c:
[0073] S110a: In each statistical period, when the task thread is executed by the first processing unit, an actual running time of the task thread in the statistical period is obtained.
[0074] Specifically, in the thread management method provided in the embodiment of the present application, in each statistical period of the first historical period, if the task thread runs in the first processing unit, the actual running time of the task thread in the statistical period is directly obtained.
[0075] S110b: In each statistical period, when the task thread runs through any second processing unit among the multiple processing units except the first processing unit, the actual running load of the task thread running through the second processing unit in the statistical period is calculated according to the actual running time of the task thread running through the second processing unit in the statistical period, the statistical period and the running parameters of the second processing unit in the statistical period.
[0076] The second processing unit is a processing unit for running a task thread selected by the scheduler from a plurality of processing units within a statistical period of the first historical period, and the second processing unit is different from the first processing unit.
[0077] Furthermore, the operating parameters of the second processing unit in the statistical period include, but are not limited to: an actual operating frequency, a maximum operating frequency, and a maximum computing capacity value of the second processing unit in the statistical period, which are not specifically limited here.
[0078] Specifically, in the thread management method provided in the embodiment of the present application, in each statistical period of the first historical period, if the task thread does not run in the first processing unit, but runs in any second processing unit other than the first processing unit among multiple processing units, the electronic device calculates the actual running load of the task thread running through the second processing unit during the statistical period based on the actual running time of the task thread running in the second processing unit during the statistical period, the statistical period and the running parameters of the second processing unit during the statistical period.
[0079] In the actual application process, the actual running load of the task thread running through the second processing unit during the statistical period is determined by the following formula (1):
[0080]
[0081] Wherein, L represents the actual running load of the task thread running through the second processing unit in the statistical period, t2 represents the actual running time of the task thread running through the second processing unit in the statistical period, T represents the statistical period, f2 represents the actual running frequency of the second processing unit in the statistical period, and f max_2 Indicates the maximum operating frequency of the second processing unit, C max_2 In this way, the actual running load of the task thread is calculated by the actual running time of the task thread, the computing power and running frequency of the processing unit running the task thread, which ensures the accuracy of the actual running load determination and further ensures the accuracy of the subsequent theoretical running time calculation.
[0082] For example, the statistical period T = 16ms, within a statistical period, the task thread runs in the big core CPU7, the actual running time of the task thread in the big core CPU7 is t2 = 4ms, the actual running frequency of the big core CPU7 is f2 = 3.2G, and the maximum running frequency of the big core CPU7 is f max_2 =3.2G, the maximum computing power value of the large core CPU7 is C max_2 = 1024. At this time, the actual running load L of the task thread running through the large core CPU 7 in the statistical period = (4ms×3.2G×1024) / (16ms×3.2G) = 256.
[0083] S110c: Calculate a theoretical running time of the task thread running through the first processing unit in the statistical period according to the statistical period, the actual running load, and the running parameters of the first processing unit in the statistical period.
[0084] The operating parameters of the first processing unit in the statistical period include but are not limited to: the actual operating frequency, the maximum operating frequency and the maximum computing capacity value of the first processing unit in the statistical period, which are not specifically limited here.
[0085] It is understandable that in different statistical periods, the processing units running the task thread may be the same or different. After calculating the actual running load of the task thread running through the second processing unit in a certain statistical period, it can be assumed that the task thread runs through the first processing unit in the statistical period, and based on the actual running load of the task thread running through the second processing unit in the statistical period, the theoretical running time of the task thread running through the first processing unit in the statistical period is converted.
[0086] Specifically, in the thread management method provided by the embodiment of the present application, in each statistical period of the first historical period, if the task thread does not run in the first processing unit, but runs in any second processing unit other than the first processing unit among the multiple processing units, after calculating the actual running load of the task thread running through the second processing unit in the statistical period, the actual running load of the task thread in the statistical period is calculated based on the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period. In this way, based on the actual running load of the task thread in other processing units, the theoretical running time of the task thread in the first processing unit is converted, which ensures the accuracy of the determination of the theoretical running time, and then ensures the accuracy of the subsequent determination of the time threshold, and ensures the accuracy of thread management.
[0087] In actual application, the theoretical running time of the task thread running through the first processing unit within the statistical period is determined by the following formula (2):
[0088]
[0089] Wherein, t1 represents the theoretical running time of the task thread running through the first processing unit in the statistical period, L represents the actual running load of the task thread running through the second processing unit in the statistical period, T represents the statistical period, f1 represents the actual running frequency of the first processing unit in the statistical period, and f max_1 Indicates the maximum operating frequency of the first processing unit, C max_1 Indicates the maximum computing power value of the first processing unit. In this way, the theoretical running time of the task thread running in the first processing unit is converted according to the actual running load of the task thread, the computing power of the first processing unit and the running frequency, which ensures the accuracy of the determination of the theoretical running time, and then ensures the accuracy of the subsequent time threshold determination, and ensures the accuracy of thread management.
[0090] For example, the statistical cycle T = 16ms, in one statistical cycle, the task thread runs in the large core CPU7, and the actual running load L of the task thread running through the large core CPU7 in the statistical cycle = 256. Assume that the task thread runs through the medium core CPU3 in the statistical cycle, the actual running frequency f1 of the medium core CPU3 = 2.8G, and the maximum running frequency f1 of the medium core CPU3 max_1 =2.8G, the maximum computing power value of the medium-core CPU3 is C max_1 = 768. At this time, the theoretical running time of the task thread running through the core CPU3 in this statistical period is t1 = (256 × 16 ms × 2.8 G) / (2.8 G × 758) = 5.3 ms.
[0091] In the above embodiment provided by the present application, in the process of determining the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period according to the statistical period, historical running data and the running parameters of multiple processing units, in each statistical period, when the task thread runs through the first processing unit, the actual running time of the task thread in the statistical period is obtained; in each statistical period, when the task thread runs through any second processing unit other than the first processing unit among the multiple processing units, according to the actual running time of the task thread running through the second processing unit in the statistical period, the statistical period and the running parameters of the second processing unit in the statistical period, the actual running load of the task thread running through the second processing unit in the statistical period is calculated; according to the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period, the theoretical running time of the task thread running through the first processing unit in the statistical period is calculated. In this way, based on the actual running load of the task thread in other processing units, the theoretical running time of the task thread in the first processing unit is converted, which ensures the accuracy of the determination of the theoretical running time, thereby ensuring the accuracy of the subsequent time threshold determination and the accuracy of thread management.
[0092] In the embodiment of the present application, the above S104 may specifically include the following S104a:
[0093] S104a: Taking the rendering thread of each frame of image in the first historical period as the starting point, according to the awakening and awakening relationship between threads, backtrack to find the threads involved in the rendering task of each frame of image, and obtain a target thread set.
[0094] Specifically, in the thread management method provided in the embodiment of the present application, for each frame image in the first historical period, the rendering thread of each frame image is used as the backtracking starting point, and according to the awakening and awakening relationship between threads, the threads involved in the rendering task of each frame image are backtracked to obtain the rendering link thread of each frame image.
[0095] For example, Figure 6 As shown, the rendering thread of the first frame image is awakened by thread A, and thread A is awakened by thread B and thread C. At this time, the rendering chain threads of the first frame image can be obtained as: [thread A, thread B, thread C, rendering thread].
[0096] For example, Figure 7 As shown, the rendering thread of the second frame image is awakened by thread D, thread D is awakened by thread A, and thread A is awakened by thread B. At this time, the rendering chain threads of the second frame image can be obtained as: [thread A, thread B, thread D, rendering thread].
[0097] On this basis, by merging the rendering link threads of each frame of the image in the first historical period, a target thread set participating in the picture display work in the first historical period can be obtained.
[0098] For example, Figure 5 As shown, the first historical period includes the first statistical period, the second statistical period and the third statistical period. The first statistical period includes historical frames Frame0 and Frame1, the second statistical period includes historical frames Frame2 and Frame3, and the third statistical period includes historical frames Frame4 and Frame5. The rendering link thread of Frame0 is [Frame0 rendering link thread], the rendering link thread of Frame1 is [Frame1 rendering link thread], the rendering link thread of Frame2 is [Frame2 rendering link thread], the rendering link thread of Frame3 is [Frame3 rendering link thread], the rendering link thread of Frame4 is [Frame4 rendering link thread], and the rendering link thread of Frame5 is [Frame5 rendering link thread]. On this basis, the target thread set G = {[Frame0 rendering link thread], [Frame1 rendering link thread], [Frame2 rendering link thread], [Frame3 rendering link thread], [Frame4 rendering link thread], [Frame5 rendering link thread]}.
[0099] In the above embodiment provided by the present application, in the process of searching for the threads participating in the rendering task of each frame of the image in the first historical period and obtaining the target thread set, the rendering thread of each frame of the image in the first historical period is taken as the starting point, and according to the awakening and awakening relationship between the threads, the threads participating in the rendering task of each frame of the image are backtracked to obtain the target thread set. In this way, the threads participating in the rendering link of each frame of the image are recorded by tracing back the historical frames to provide a basis for judging whether the current task thread participates in the screen display work, thereby ensuring the accuracy of the obtained target thread set and thus ensuring the accuracy of thread management.
[0100] In summary, in the thread management method provided in the embodiment of the present application, Figure 3As shown, for the foreground thread, when the task thread runs through the first processing unit among multiple processing units, the actual running load of the task thread in each statistical period of the first historical period is calculated, and the running time of the task thread converted to each processing unit in each statistical period is calculated. At the same time, the rendering link thread of each frame of the image in the first historical period is recorded to obtain a set of target threads participating in the screen display work. On this basis, based on the running time of the task thread converted to each processing unit in each statistical period, a reference basis for judging whether the task thread is a high-load thread in the current statistical period, i.e., a time threshold, is provided, and then when the running time of the task thread in the first processing unit exceeds the time threshold, and the task thread is a thread that does not participate in the screen display work, the system resource restriction operation is performed on the abnormal foreground thread by controlling the task thread to temporarily enter sleep mode, so as to effectively avoid the abnormal foreground thread from occupying CPU resources, and effectively control the battery life heating problem caused by the abnormal foreground thread while ensuring the smooth operation of the system.
[0101] The thread management method provided in the embodiment of the present application can be executed by a thread management device. In the embodiment of the present application, the thread management device provided in the embodiment of the present application is described by taking the thread management device executing the above thread management method as an example.
[0102] like Figure 8 As shown, an embodiment of the present application provides a thread management device 800, which is applied to an electronic device. The electronic device includes multiple processing units. The thread management device 800 may include the following processing module 802 and control module 804.
[0103] A processing module 802 is used to determine, when the task thread is executed by a first processing unit among the multiple processing units, a time threshold for the first processing unit to execute the task thread according to historical execution data of the task thread in the multiple processing units within a first historical period;
[0104] The processing module 802 is further used to search for threads participating in the rendering task of each frame of the image in the first historical period to obtain a target thread set;
[0105] The control module 804 is used to control the task thread to sleep when the running time of the task thread reaches a time threshold and the task thread is not in the target thread set.
[0106] Through the thread management device 800 provided in the embodiment of the present application, when the task thread is run through the first processing unit among multiple processing units, the time threshold for the first processing unit to run the task thread is determined according to the historical running data of the task thread in multiple processing units in the first historical period; the thread participating in the rendering task of each frame of the image in the first historical period is searched to obtain the target thread set; when the running time of the task thread reaches the time threshold and the task thread is not in the target thread set, the task thread is controlled to sleep. Through the above-mentioned thread management device 800, when the task thread is run through the first processing unit among multiple processing units of the electronic device, based on the historical running data of the task thread in multiple processing units, the time threshold for the task thread to run in the first processing unit is determined, and then when the running time of the task thread in the first processing unit exceeds the time threshold, and the task thread is a thread that does not participate in the screen display work, the task thread is controlled to temporarily enter sleep. In this way, the foreground abnormal thread can be identified and controlled, thereby effectively avoiding the foreground abnormal thread from occupying CPU resources, while ensuring the smooth operation of the system, effectively controlling the battery life and heating problems caused by the foreground abnormal thread.
[0107] In an embodiment of the present application, the processing module 802 is specifically used to: collect historical running data of the task thread in multiple processing units within the first historical period according to a statistical period; determine the actual running time or theoretical running time of the task thread running through the first processing unit within each statistical period of the first historical period based on the statistical period, the historical running data and the running parameters of the multiple processing units; determine the time threshold for the first processing unit to run the task thread based on the actual running time or theoretical running time of the task thread running through the first processing unit within each statistical period.
[0108] In the above-mentioned embodiment provided by the present application, in the process of determining the time threshold for the first processing unit to run the task thread according to the historical running data of the task thread in multiple processing units in the first historical period, the historical running data of the task thread in multiple processing units in the first historical period are counted according to the statistical period; the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period is determined according to the statistical period, the historical running data and the running parameters of the multiple processing units; the time threshold for the first processing unit to run the task thread is determined according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period. In this way, based on the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period, the time threshold for the task thread to be allowed to run in the first processing unit in the current statistical period is calculated, which ensures the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0109] In an embodiment of the present application, the processing module 802 is specifically used to: calculate the average running time of the task thread running through the first processing unit in the first historical period based on the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period; and determine the product of the average running time and the constant parameter as the time threshold for the first processing unit to run the task thread.
[0110] In the above-mentioned embodiment provided by the present application, in the process of determining the time threshold for the first processing unit to run the task thread according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period, the average running time of the task thread running through the first processing unit in the first historical period is calculated according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period; and the product of the average running time and the constant parameter is determined as the time threshold for the first processing unit to run the task thread. In this way, based on the historical time data of the task thread running on the first processing unit, the maximum running time, i.e., the time threshold, which is allowed for the task thread to run in the first processing unit in the current statistical period is dynamically set, thereby ensuring the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0111] In an embodiment of the present application, the processing module 802 is specifically used to: in each statistical period, when the task thread runs through the first processing unit, obtain the actual running time of the task thread in the statistical period; in each statistical period, when the task thread runs through any second processing unit among multiple processing units except the first processing unit, calculate the actual running load of the task thread running through the second processing unit in the statistical period according to the actual running time of the task thread running through the second processing unit in the statistical period, the statistical period and the running parameters of the second processing unit in the statistical period; calculate the theoretical running time of the task thread running through the first processing unit in the statistical period according to the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period.
[0112] In the above embodiment provided by the present application, in the process of determining the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period according to the statistical period, historical running data and the running parameters of multiple processing units, in each statistical period, when the task thread runs through the first processing unit, the actual running time of the task thread in the statistical period is obtained; in each statistical period, when the task thread runs through any second processing unit other than the first processing unit among the multiple processing units, according to the actual running time of the task thread running through the second processing unit in the statistical period, the statistical period and the running parameters of the second processing unit in the statistical period, the actual running load of the task thread running through the second processing unit in the statistical period is calculated; according to the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period, the theoretical running time of the task thread running through the first processing unit in the statistical period is calculated. In this way, based on the actual running load of the task thread in other processing units, the theoretical running time of the task thread in the first processing unit is converted, which ensures the accuracy of the determination of the theoretical running time, thereby ensuring the accuracy of the subsequent time threshold determination and the accuracy of thread management.
[0113] In an embodiment of the present application, the processing module 802 is specifically used to: take the rendering thread of each frame image in the first historical period as the starting point, and based on the awakening and awakening relationship between threads, backtrack to find the threads involved in the rendering task of each frame image to obtain the target thread set.
[0114] In the above embodiment provided by the present application, in the process of searching for the threads participating in the rendering task of each frame of the image in the first historical period and obtaining the target thread set, the rendering thread of each frame of the image in the first historical period is taken as the starting point, and according to the awakening and awakening relationship between the threads, the threads participating in the rendering task of each frame of the image are backtracked to obtain the target thread set. In this way, the threads participating in the rendering link of each frame of the image are recorded by tracing back the historical frames to provide a basis for judging whether the current task thread participates in the screen display work, thereby ensuring the accuracy of the obtained target thread set and thus ensuring the accuracy of thread management.
[0115] The thread management device 800 in the embodiment of the present application can be an electronic device, or a component in the electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal, or other devices other than a terminal. Exemplarily, the electronic device can be a mobile phone, a tablet computer, a laptop computer, a palmtop computer, a vehicle-mounted electronic device, a mobile Internet device (Mobile Internet Device, MID), an augmented reality (augmented reality, AR) / virtual reality (virtual reality, VR) device, a robot, a wearable device, an ultra-mobile personal computer (ultra-mobile personal computer, UMPC), a netbook or a personal digital assistant (personal digital assistant, PDA), etc., and can also be a server, a network attached storage (Network Attached Storage, NAS), a personal computer (personal computer, PC), a television (television, TV), a teller machine or a self-service machine, etc., which is not specifically limited in the embodiment of the present application.
[0116] The thread management device 800 in the embodiment of the present application may be a device having an operating system. The operating system may be an Android operating system, an iOS operating system, or other possible operating systems, which are not specifically limited in the embodiment of the present application.
[0117] The thread management device 800 provided in the embodiment of the present application can realize Figure 1 To avoid repetition, the various processes implemented by the method embodiment are not described here.
[0118] Alternatively, if Fig. 9As shown, an embodiment of the present application also provides an electronic device 900, including a processor 902 and a memory 904, wherein the memory 904 stores programs or instructions that can be executed on the processor 902, and when the program or instructions are executed by the processor 902, the various steps of the above-mentioned thread management method embodiment are implemented, and the same technical effect can be achieved. To avoid repetition, they are not described here.
[0119] It should be noted that the electronic devices in the embodiments of the present application include the above-mentioned mobile electronic devices and non-mobile electronic devices.
[0120] Fig.10 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of the present application.
[0121] The electronic device 1000 includes but is not limited to: a radio frequency unit 1001, a network module 1002, an audio output unit 1003, an input unit 1004, a sensor 1005, a display unit 1006, a user input unit 1007, an interface unit 1008, a memory 1009 and a processor 1010 and other components.
[0122] Those skilled in the art will appreciate that the electronic device 1000 may also include a power source (such as a battery) for supplying power to each component, and the power source may be logically connected to the processor 1010 through a power management system, thereby implementing functions such as managing charging, discharging, and power consumption management through the power management system. Fig.10 The electronic device structure shown in the figure does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently, which will not be described in detail here.
[0123] Among them, processor 1010 is used to determine the time threshold for the first processing unit to run the task thread according to the historical running data of the task thread in the multiple processing units within the first historical period when the task thread is run through the first processing unit among the multiple processing units.
[0124] The processor 1010 is further configured to search for threads participating in the rendering task of each frame of the image in the first historical period to obtain a target thread set.
[0125] The processor 1010 is further configured to control the task thread to sleep when the running time of the task thread reaches a time threshold and the task thread is not in the target thread set.
[0126] In an embodiment of the present application, when a task thread is run by a first processing unit among multiple processing units, the time threshold for the first processing unit to run the task thread is determined based on the historical running data of the task thread in multiple processing units within the first historical period; the threads participating in the rendering task of each frame of the image within the first historical period are searched to obtain a target thread set; when the running time of the task thread reaches the time threshold and the task thread is not in the target thread set, the task thread is controlled to sleep. In an embodiment of the present application, when a task thread is run by a first processing unit among multiple processing units of an electronic device, the time threshold for the task thread to run in the first processing unit is determined based on the historical running data of the task thread in multiple processing units, and then when the running time of the task thread in the first processing unit exceeds the time threshold and the task thread is a thread that does not participate in the screen display work, the task thread is controlled to temporarily enter sleep. In this way, the foreground abnormal thread can be identified and controlled, thereby effectively avoiding the foreground abnormal thread from occupying CPU resources, and effectively controlling the battery life heating problem caused by the foreground abnormal thread while ensuring the smooth operation of the system.
[0127] Optionally, processor 1010 is specifically used to: count the historical running data of the task thread in multiple processing units within the first historical period according to the statistical period; determine the actual running time or theoretical running time of the task thread running through the first processing unit within each statistical period of the first historical period according to the statistical period, the historical running data and the running parameters of the multiple processing units; determine the time threshold for the first processing unit to run the task thread according to the actual running time or theoretical running time of the task thread running through the first processing unit within each statistical period.
[0128] In the above-mentioned embodiment provided by the present application, in the process of determining the time threshold for the first processing unit to run the task thread according to the historical running data of the task thread in multiple processing units in the first historical period, the historical running data of the task thread in multiple processing units in the first historical period are counted according to the statistical period; the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period is determined according to the statistical period, the historical running data and the running parameters of the multiple processing units; the time threshold for the first processing unit to run the task thread is determined according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period. In this way, based on the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period, the time threshold for the task thread to be allowed to run in the first processing unit in the current statistical period is calculated, which ensures the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0129] Optionally, processor 1010 is specifically used to: calculate the average running time of the task thread running through the first processing unit in the first historical period based on the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period; and determine the product of the average running time and the constant parameter as the time threshold for the first processing unit to run the task thread.
[0130] In the above-mentioned embodiment provided by the present application, in the process of determining the time threshold for the first processing unit to run the task thread according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period, the average running time of the task thread running through the first processing unit in the first historical period is calculated according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period; and the product of the average running time and the constant parameter is determined as the time threshold for the first processing unit to run the task thread. In this way, based on the historical time data of the task thread running on the first processing unit, the maximum running time, i.e., the time threshold, which is allowed for the task thread to run in the first processing unit in the current statistical period is dynamically set, thereby ensuring the accuracy of the time threshold determination, thereby ensuring the accuracy of the subsequent judgment of whether the task thread is a high-load thread, and ensuring the accuracy of thread management.
[0131] Optionally, the processing unit is specifically used to: in each statistical period, when the task thread runs through the first processing unit, obtain the actual running time of the task thread in the statistical period; in each statistical period, when the task thread runs through any second processing unit among multiple processing units except the first processing unit, calculate the actual running load of the task thread running through the second processing unit in the statistical period according to the actual running time of the task thread running through the second processing unit in the statistical period, the statistical period and the running parameters of the second processing unit in the statistical period; calculate the theoretical running time of the task thread running through the first processing unit in the statistical period according to the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period.
[0132] In the above embodiment provided by the present application, in the process of determining the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period of the first historical period according to the statistical period, historical running data and the running parameters of multiple processing units, in each statistical period, when the task thread runs through the first processing unit, the actual running time of the task thread in the statistical period is obtained; in each statistical period, when the task thread runs through any second processing unit other than the first processing unit among the multiple processing units, according to the actual running time of the task thread running through the second processing unit in the statistical period, the statistical period and the running parameters of the second processing unit in the statistical period, the actual running load of the task thread running through the second processing unit in the statistical period is calculated; according to the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period, the theoretical running time of the task thread running through the first processing unit in the statistical period is calculated. In this way, based on the actual running load of the task thread in other processing units, the theoretical running time of the task thread in the first processing unit is converted, which ensures the accuracy of the determination of the theoretical running time, thereby ensuring the accuracy of the subsequent time threshold determination and the accuracy of thread management.
[0133] Optionally, the processor 1010 is specifically configured to: take the rendering thread of each frame image in the first historical period as the starting point, and backtrack to find the threads involved in the rendering task of each frame image according to the awakening and awakening relationship between threads to obtain a target thread set.
[0134] In the above embodiment provided by the present application, in the process of searching for the threads participating in the rendering task of each frame of the image in the first historical period and obtaining the target thread set, the rendering thread of each frame of the image in the first historical period is taken as the starting point, and according to the awakening and awakening relationship between the threads, the threads participating in the rendering task of each frame of the image are backtracked to obtain the target thread set. In this way, the threads participating in the rendering link of each frame of the image are recorded by tracing back the historical frames to provide a basis for judging whether the current task thread participates in the screen display work, thereby ensuring the accuracy of the obtained target thread set and thus ensuring the accuracy of thread management.
[0135] It should be understood that in the embodiment of the present application, the input unit 1004 may include a graphics processor (Graphics Processing Unit, GPU) 10041 and a microphone 10042, and the graphics processor 10041 processes the image data of the static picture or video obtained by the image capture device (such as a camera) in the video capture mode or the image capture mode. The display unit 1006 may include a display panel 10061, and the display panel 10061 may be configured in the form of a liquid crystal display, an organic light emitting diode, etc. The user input unit 1007 includes a touch panel 10071 and at least one of other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include two parts: a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, and a joystick, which will not be repeated here.
[0136] The memory 1009 can be used to store software programs and various data. The memory 1009 may mainly include a first storage area for storing programs or instructions and a second storage area for storing data, wherein the first storage area may store an operating system, an application program or instructions required for at least one function (such as a sound playback function, an image playback function, etc.), etc. In addition, the memory 1009 may include a volatile memory or a non-volatile memory, or the memory 1009 may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), a static random access memory (SRAM), a dynamic random access memory (DRAM), a synchronous dynamic random access memory (SDRAM), a double data rate synchronous dynamic random access memory (DDRSDRAM), an enhanced synchronous dynamic random access memory (ESDRAM), a synchronous link dynamic random access memory (SLDRAM) and a direct memory bus random access memory (DRRAM). The memory 1009 in the embodiment of the present application includes but is not limited to these and any other suitable types of memory.
[0137] The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, wherein the application processor mainly processes operations related to an operating system, a user interface, and application programs, and the modem processor mainly processes wireless communication signals, such as a baseband processor. It is understandable that the modem processor may not be integrated into the processor 1010.
[0138] An embodiment of the present application also provides a readable storage medium, on which a program or instruction is stored. When the program or instruction is executed by a processor, the various processes of the above-mentioned thread management method embodiment are implemented and the same technical effect can be achieved. To avoid repetition, it will not be repeated here.
[0139] The processor is the processor in the electronic device in the above embodiment. The readable storage medium includes a computer readable storage medium, such as a computer read-only memory ROM, a random access memory RAM, a magnetic disk or an optical disk.
[0140] An embodiment of the present application further provides a chip, which includes a processor and a communication interface, wherein the communication interface and the processor are coupled, and the processor is used to run programs or instructions to implement the various processes of the above-mentioned thread management method embodiment, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0141] It should be understood that the chip mentioned in the embodiments of the present application can also be called a system-level chip, a system chip, a chip system or a system-on-chip chip, etc.
[0142] An embodiment of the present application provides a computer program product, which is stored in a storage medium. The program product is executed by at least one processor to implement the various processes of the above-mentioned thread management method embodiment and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0143] It should be noted that, in this article, the terms "comprise", "include" or any other variant thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise one..." do not exclude the presence of other identical elements in the process, method, article or device including the element. In addition, it should be pointed out that the scope of the methods and devices in the embodiments of the present application is not limited to performing functions in the order shown or discussed, and may also include performing functions in a substantially simultaneous manner or in reverse order according to the functions involved, for example, the described method may be performed in an order different from that described, and various steps may also be added, omitted, or combined. In addition, the features described with reference to certain examples may be combined in other examples.
[0144] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a computer software product, which is stored in a storage medium (such as ROM / RAM, a disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods of each embodiment of the present application.
[0145] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A thread management method, characterized in that: Executed by an electronic device, the electronic device comprising a plurality of processing units, the thread management method comprising: In a case where the task thread is executed by a first processing unit among the multiple processing units, determining a time threshold for the first processing unit to execute the task thread according to historical execution data of the task thread in the multiple processing units within a first historical period; Searching for threads participating in the rendering task of each frame of the image in the first historical period to obtain a target thread set; When the running time of the task thread reaches the time threshold and the task thread is not in the target thread set, the task thread is controlled to sleep.
2. The thread management method according to claim 1, characterized in that: The determining, according to historical running data of the task thread on the plurality of processing units in the first historical period, a time threshold for the first processing unit to run the task thread comprises: Collecting historical running data of the task thread in the first historical period in the plurality of processing units according to a statistical period; Determine, according to the statistical period, the historical operation data and the operation parameters of the plurality of processing units, an actual operation time or a theoretical operation time of the task thread executed by the first processing unit in each statistical period of the first historical period; A time threshold for the first processing unit to run the task thread is determined according to an actual running time or a theoretical running time of the task thread run by the first processing unit in each statistical period.
3. The thread management method according to claim 2, characterized in that: Determining a time threshold for the first processing unit to run the task thread according to an actual running time or a theoretical running time of the task thread running through the first processing unit in each statistical period includes: Calculate the average running time of the task thread running through the first processing unit in the first historical period according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period; The product of the average running time and a constant parameter is determined as a time threshold for the first processing unit to run the task thread.
4. The thread management method according to claim 2, characterized in that: The determining, according to the statistical period, the historical operation data and the operation parameters of the plurality of processing units, the actual operation time or the theoretical operation time of the task thread executed by the first processing unit in each statistical period of the first historical period comprises: In each of the statistical periods, when the task thread is executed by the first processing unit, obtaining the actual running time of the task thread in the statistical period; In each of the statistical cycles, when the task thread is executed by any second processing unit among the plurality of processing units except the first processing unit, an actual operation load of the task thread executed by the second processing unit in the statistical cycle is calculated according to the actual operation time of the task thread executed by the second processing unit in the statistical cycle, the statistical cycle and the operation parameters of the second processing unit in the statistical cycle; The theoretical running time of the task thread running through the first processing unit in the statistical period is calculated according to the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period.
5. The thread management method according to any one of claims 1 to 4, characterized in that: The step of searching for threads participating in the rendering task of each frame of the image in the first historical period to obtain a target thread set includes: Taking the rendering thread of each frame of image in the first historical period as the starting point, according to the awakening and awakening relationship between threads, backtracking to find the threads involved in the rendering task of each frame of image, to obtain the target thread set.
6. A thread management device, characterized in that: Applied to an electronic device, the electronic device includes a plurality of processing units, and the thread management device includes: a processing module, configured to determine, when a task thread is executed by a first processing unit among the multiple processing units, a time threshold for the first processing unit to execute the task thread according to historical execution data of the task thread in the multiple processing units within a first historical period; The processing module is further used to search for threads participating in the rendering task of each frame of the image in the first historical period to obtain a target thread set; The control module is used to control the task thread to sleep when the running time of the task thread reaches the time threshold and the task thread is not in the target thread set.
7. The thread management device according to claim 6, characterized in that: The processing module is specifically used for: Collecting historical running data of the task thread in the first historical period in the plurality of processing units according to a statistical period; Determine, according to the statistical period, the historical operation data and the operation parameters of the plurality of processing units, an actual operation time or a theoretical operation time of the task thread executed by the first processing unit in each statistical period of the first historical period; A time threshold for the first processing unit to run the task thread is determined according to an actual running time or a theoretical running time of the task thread run by the first processing unit in each statistical period.
8. The thread management device according to claim 7, characterized in that: The processing module is specifically used for: Calculate the average running time of the task thread running through the first processing unit in the first historical period according to the actual running time or theoretical running time of the task thread running through the first processing unit in each statistical period; The product of the average running time and a constant parameter is determined as a time threshold for the first processing unit to run the task thread.
9. The thread management device according to claim 7, characterized in that: The processing module is specifically used for: In each of the statistical periods, when the task thread is executed by the first processing unit, obtaining the actual running time of the task thread in the statistical period; In each of the statistical cycles, when the task thread is executed by any second processing unit among the plurality of processing units except the first processing unit, an actual operation load of the task thread executed by the second processing unit in the statistical cycle is calculated according to the actual operation time of the task thread executed by the second processing unit in the statistical cycle, the statistical cycle and the operation parameters of the second processing unit in the statistical cycle; The theoretical running time of the task thread running through the first processing unit in the statistical period is calculated according to the statistical period, the actual running load and the running parameters of the first processing unit in the statistical period.
10. The thread management device according to any one of claims 6 to 9, characterized in that: The processing module is specifically used for: Taking the rendering thread of each frame of image in the first historical period as the starting point, according to the awakening and awakening relationship between threads, backtracking to find the threads involved in the rendering task of each frame of image, to obtain the target thread set.
