Processing method and electronic equipment

By elevating the thread scheduling mode to a higher level and allocating priority and usage time, the problem of insufficient CPU resource allocation was solved, enabling fast startup and smooth operation of application functions.

CN120909787APending Publication Date: 2025-11-07LENOVO (BEIJING) LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511062751.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-30
Publication Date
2025-11-07

AI Technical Summary

Technical Problem

Under high load, the CPU has difficulty allocating computing resources to application threads in a timely manner, resulting in slow application startup and affecting user experience.

Method used

By switching threads from the first scheduling mode to the second scheduling mode, the CPU scheduling level is increased, and priority values ​​and usage time are assigned to threads in the second scheduling mode, giving priority to high-priority threads to obtain CPU resources.

Benefits of technology

It improves the continuity and efficiency of thread execution, reduces latency caused by waiting for resources, and enhances application startup speed and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120909787A_ABST
    Figure CN120909787A_ABST
Patent Text Reader

Abstract

The invention discloses a processing method and electronic equipment. The method comprises the following steps: determining a first thread required for running a target application by the electronic equipment; if the load of the electronic equipment meets the target condition, switching the first thread from the first scheduling mode to a second scheduling mode; the central processing unit scheduling level corresponding to the second scheduling mode is higher than the central processing unit scheduling level corresponding to the first scheduling mode; the second scheduling mode at least comprises the operation of the target application by a second thread; the central processing unit scheduling level corresponding to the second scheduling mode is used for improving the continuity of running the target application by the second thread; in the second scheduling mode, the use time of the central processing unit resources is allocated to the second thread; and executing the second thread based on the use time of the resource allocated to the second thread.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, and particularly relates to a processing method and an electronic device. BACKGROUND

[0002] The starting and running of part functions (such as camera functions) of an application are highly dependent on the timely allocation of resources by a CPU (Central Processing Unit) to complete key operations (such as sensor initialization, image processing, etc.). However, under a high load state, the number of processes and tasks that need to be processed by the CPU increases dramatically, making it difficult for the CPU to allocate the required computing resources to the application in the first time. At this time, the thread initiated by the application for performing the key operation can only be suspended and enter the waiting queue because it cannot get the response of the CPU. With the continuation of the high load condition, more and more such threads are continuously accumulated in the waiting queue, eventually leading to slow starting of the application function and affecting the user experience. SUMMARY

[0003] The technical scheme provided by the present application is as follows:

[0004] The first aspect of the present application provides a processing method, comprising:

[0005] determining a first thread required by an electronic device for running a target application;

[0006] if the load of the electronic device meets a target condition, switching the first thread from a first scheduling mode to a second scheduling mode; the central processor scheduling level corresponding to the second scheduling mode is higher than the central processor scheduling level corresponding to the first scheduling mode; the second scheduling mode at least includes running the target application by a second thread; and the central processor scheduling level corresponding to the second scheduling mode is used to improve the continuity of running the target application by the second thread;

[0007] allocating the use time of the central processor resources for the second thread under the second scheduling mode;

[0008] executing the second thread based on the use time of the resources allocated to the second thread.

[0009] allocating the use time of the central processor resources for the second thread under the second scheduling mode, comprising:

[0010] selecting a priority value from a first priority range to determine a candidate priority value under the second scheduling mode;

[0011] switching the second thread from a current priority value to the candidate priority value; the current priority value belongs to a second priority range; priority values in the second priority range represent a priority lower than priority values in the first priority range;

[0012] allocating, based on the candidate priority value, a usage time of central processing unit resource for the second thread.

[0013] the priority represented by the candidate priority value is the highest in the first priority range.

[0014] if there are multiple second threads, the selecting one priority value from the first priority range to determine as the candidate priority value comprises:

[0015] selecting one priority value from the first priority range to determine as the candidate priority value respectively corresponding to each of the second threads; the higher the importance of the second thread is, the higher the priority corresponding to the candidate priority value is.

[0016] the allocating, based on the candidate priority value, a usage time of central processing unit resource for the second thread comprises:

[0017] determining, as the usage time of central processing unit resource for the second thread, a preset usage time corresponding to the candidate priority value.

[0018] the allocating, based on the candidate priority value, a usage time of central processing unit resource for the second thread comprises:

[0019] adjusting, based on the load of the electronic device, the preset usage time corresponding to the candidate priority value, and determining, as the usage time of central processing unit resource for the second thread, the usage time obtained after the adjustment.

[0020] the processing method further comprises:

[0021] switching the first thread from the second scheduling mode to the first scheduling mode when the second thread is not completely stopped.

[0022] the second thread is determined by:

[0023] obtaining activity information of the target application in a starting process;

[0024] based on the activity information, selecting, from multiple threads of the target application, a second thread whose time-consuming duration in the starting process of the target application satisfies a set condition.

[0025] the second thread is determined by:

[0026] In response to a user input, a user-specified thread is determined as a second thread.

[0027] Another aspect of the present application provides an electronic device comprising:

[0028] a memory for storing a computer program;

[0029] a processor for executing the computer program to enable the electronic device to perform the following method steps:

[0030] determining a first thread required for the electronic device to run a target application;

[0031] if a load of the electronic device meets a target condition, switching the first thread from a first scheduling mode to a second scheduling mode; the second scheduling mode corresponds to a central processing unit scheduling level higher than a central processing unit scheduling level corresponding to the first scheduling mode; the second scheduling mode at least comprises running the target application with a second thread; the central processing unit scheduling level corresponding to the second scheduling mode is used to improve continuity of running the target application with the second thread;

[0032] in the second scheduling mode, allocating a usage time of a central processing unit resource for the second thread;

[0033] based on the usage time of the resource allocated for the second thread, executing the second thread. BRIEF DESCRIPTION OF DRAWINGS

[0034] The above and other features, advantages and aspects of embodiments of the present application will become more apparent upon reading the following detailed description in conjunction with the accompanying drawings, in which like reference numerals refer to like elements. It is to be understood that the drawings are designed solely for the purpose of illustration and not as a definition of the limits of the application, for which reference should be made only to the appended claims. Additionally, drawings in which:

[0035] Figure 1 a flowchart of a processing method provided for Embodiment 1 of the present application;

[0036] Figure 2 a flowchart of a processing method provided for Embodiment 2 of the present application;

[0037] Figure 3 a flowchart of a processing method provided for Embodiment 5 of the present application;

[0038] Figure 4 a flowchart of a processing method provided for Embodiment 6 of the present application;

[0039] Figure 5 a flowchart of a processing method provided for Embodiment 7 of the present application;

[0040] Figure 6 An implementation scenario of a processing method provided in the present application is shown in the following figure;

[0041] Figure 7 An effect comparison diagram of a total duration provided in the present application is shown in the following figure;

[0042] Figure 8 A structure diagram of a processing device provided in the present application is shown in the following figure. DETAILED DESCRIPTION

[0043] The embodiments of the present application are described below in conjunction with the accompanying drawings. The terms used in the embodiment part of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0044] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art can know that, with the development of technology and the appearance of new scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.

[0045] The terms "first", "second", and the like in the present application are used to distinguish similar objects, and do not necessarily describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged under appropriate circumstances, which is only a distinguishing way used in the description of the embodiments of the present application to describe the objects with the same attribute. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, so that the processes, methods, systems, products or devices containing a series of units do not have to be limited to those units, but can include other units not clearly listed or inherent to these processes, methods, products or devices.

[0046] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0047] Reference Figure 1 A flow diagram of a processing method provided in Embodiment 1 of the present application is shown in the following figure, which can include but is not limited to the following steps: Figure 1

[0048] Step S101, determining a first thread required by the electronic device to run a target application.

[0049] In the present embodiment, the first thread can be the first thread related to the target application created by the operating system of the electronic device when the target application starts the related function operation.

[0050] The first thread can be used to create a second thread. The second thread can be used to implement the specific function of the target application. ​

[0051] Next, take WeChat as an example of the target application to illustrate the first thread and the second thread. For example, when the user clicks the WeChat camera button, the operating system can respond and create an original thread (i.e., an implementation of the first thread). After receiving the WeChat camera request, the original thread can create main threads such as a preview thread, an ISP (Image Signal Processing) thread, and a shooting thread (i.e., an implementation of the second thread).

[0052] The preview thread can be responsible for acquiring image data from the camera sensor in real time and displaying it on the screen after preliminary processing, providing the user with a real-time camera preview, allowing the user to see the current shooting scene and adjust the shooting angle and composition.

[0053] At the same time, the ISP thread undertakes the heavy task of deep processing and optimization of the collected raw image data. It performs a series of operations such as noise reduction, color correction, contrast adjustment, etc., to improve the quality and visual effect of the image.

[0054] The shooting thread is activated when the user presses the shooting button, responsible for the final storage of the image data processed by the preview and ISP, saving the photo to the storage medium of the electronic device to complete the shooting operation.

[0055] Step S102, if the load of the electronic device meets the target condition, switch the first thread from the first scheduling mode to the second scheduling mode; the central processor scheduling level corresponding to the second scheduling mode is higher than the central processor scheduling level corresponding to the first scheduling mode.

[0056] The second scheduling mode at least includes running the target application with the second thread.

[0057] The central processor scheduling level corresponding to the second scheduling mode is used to improve the continuity of running the target application with the second thread.

[0058] In this embodiment, the CPU usage can be monitored, but not limited to, when the CPU usage continuously exceeds the preset threshold (e.g., 80%) and lasts for a certain period of time (e.g., 5 minutes), it can be determined that the load of the electronic device meets the target condition.

[0059] Alternatively, the number of currently running processes can be counted, and if the number of processes exceeds the upper limit of the safe number of processes set by the system, it can also be determined that the load of the electronic device meets the target condition. In addition, the memory usage situation can also be combined, and when the remaining memory space is lower than a certain percentage (such as 20%), it is also one of the reference factors for determining that the load meets the target condition. By combining these indicators, the load state of the device is comprehensively evaluated through a certain algorithm (such as a weighted average algorithm), and when the comprehensive evaluation result reaches the set threshold, it is determined that the load of the electronic device meets the target condition.

[0060] In the second scheduling mode of the first thread, the CPU time slice can be preferentially allocated to the first thread in the second scheduling mode, so that the first thread can obtain CPU resources more timely, reduce the delay caused by waiting for resources, and thus complete the initialization, coordination and other key tasks related to the target application more quickly. For example, in a camera application, after the user clicks the shooting button, if the device is in a high load state at this time, the original thread (the first thread) may still be in the first scheduling mode, which may delay the initialization of the camera sensor, the display of the preview screen and other operations due to the inability to obtain CPU resources in time. After switching to the second scheduling mode, the original thread can quickly obtain CPU resources and quickly complete these preliminary preparations, laying a foundation for the normal execution of subsequent shooting functions.

[0061] When the first thread is switched from the first scheduling mode to the second scheduling mode, since the second thread is created by the first thread, in the creation process, the second thread can inherit the scheduling mode attribute of the current first thread, that is, it can follow the second scheduling mode after the first thread is switched. In this way, it can be ensured that the second thread is in a higher central processor scheduling level from the beginning of creation, can obtain CPU resources more timely, and guarantee the smooth execution of the target application function. For example, in the camera shooting function, after the original thread (the first thread) is switched to the second scheduling mode, the preview thread, ISP thread and shooting thread (the second thread) created by it will inherit this high central processor scheduling level scheduling mode, so that they can better obtain CPU resources in subsequent running.

[0062] In the second scheduling mode, the use time of the central processor resource is allocated to the second thread.

[0063] When multiple threads compete for CPU resources, the order of allocating CPU time slices can be determined according to the central processor scheduling levels of the threads. Among them, the second threads in the second scheduling mode are given priority, and CPU time slices can be allocated to them preferentially. In contrast, threads in the first scheduling mode or other low-priority scheduling modes need to wait for the second threads to complete their tasks or take turns to obtain CPU resources according to certain rules. For example, in an electronic device running multiple application programs simultaneously, when the second thread of the camera application (such as the photographing thread) is in the second scheduling mode, even if the threads of other application programs are also competing for CPU resources, the photographing thread can still obtain CPU time slices more frequently, thereby completing the photographing operation faster.

[0064] In the second scheduling mode, since the second thread can obtain CPU resources more timely, the interruptions and pauses caused by waiting for resources during its running process can be greatly reduced, thereby improving the efficiency of running the target application. For example, in a video playing application, if the video decoding thread is in a higher central processor scheduling level, it can decode video data more continuously, avoiding the phenomenon of freezing due to waiting for CPU resources, and ensuring the smoothness of video playing.

[0065] Step S104, executing the second thread based on the use time of the central processor resource allocated to the second thread.

[0066] During the use time of the central processor resource allocated to the second thread, the CPU can sequentially perform data reading, calculation processing, result storage and other operations according to the instruction sequence of the second thread, to complete the specific function in the target application undertaken by the second thread. For example, if the second thread is a video decoding thread in a video playing application, during the use time of the allocated resource, the CPU can decode and calculate video data according to the video encoding format, to restore compressed video data to image data that can be displayed.

[0067] When the use time of the central processor resource allocated to the second thread is exhausted, the CPU can pause the execution of the second thread, and process other threads or tasks that need CPU resources at the same time. The current task execution state (such as data in the register, position of the program counter, etc.) of the paused second thread can be saved, so that when the second thread obtains the use time of the central processor resource again next time, it can continue to execute from the paused place, ensuring the continuity and integrity of the task.

[0068] In the embodiment, by determining a first thread required by the electronic device to run a target application, if a load of the electronic device meets a target condition, the first thread is switched from a first scheduling mode to a second scheduling mode, the central processing unit scheduling level of the first thread can be improved, the improvement of the first thread scheduling level can drive the central processing unit scheduling level of the second thread to be improved, so that the second thread has more advantages in resource competition. On this basis, in the second scheduling mode, the second thread is allocated a use time of the central processing unit resource, so that the second thread can be more timely allocated to the use time of the central processing unit resource, and then, based on the use time of the resource allocated to the second thread, the second thread is executed, so that the continuity of the second thread running the target application is improved, the interruption is reduced, the execution efficiency of the second thread is improved, and the function startup time of the target application is accelerated.

[0069] As another optional embodiment of the present application, referring to Figure 2 , a flowchart of a processing method provided in Embodiment 2 of the present application, the present embodiment is mainly an implementation of the above step S103, as shown in Figure 2 , which can specifically include but is not limited to the following steps:

[0070] Step S1031, in the second scheduling mode, a priority value in the first priority range is selected as a candidate priority value.

[0071] In the second scheduling mode, the priority values in the first priority range can represent the order in which the threads obtain the CPU resources, and the smaller the value, the earlier the allocation order of the use time of the corresponding CPU resources.

[0072] In the second scheduling mode, the second thread can be but is not limited to being scheduled based on the time slice round robin scheduling algorithm (SCHED_RR). The time slice round robin scheduling algorithm can manage multiple queues, each of which corresponds to a different priority in the first priority range. The time slice round robin scheduling algorithm can scan the multiple queues in descending order of priority, and when a non-empty queue is scanned, the threads in the non-empty queue can be executed in turn in a round robin manner. The CPU resource use time (i.e. time slice) allocated to each second thread in the same queue can be the same.

[0073] In the second scheduling mode, the second thread can but is not limited to enter the queue corresponding to the candidate priority value in the multiple queues managed based on the time slice round robin scheduling algorithm (SCHED_RR).

[0074] Step S1032, the second thread is switched from a current priority value to the candidate priority value; the current priority value belongs to the second priority range.

[0075] The current priority value can be set for the second thread in the first scheduling mode. The priority value within the second priority range can represent a lower priority than the priority value within the first priority range.

[0076] In the first scheduling mode, the second thread can be scheduled based on the time-sharing scheduling strategy (SCHED_OTHER), but is not limited to it.

[0077] Unlike round-robin scheduling, time-sharing scheduling manages a queue containing threads with different priorities. The time-sharing strategy determines the allocation weight of CPU resource usage time based on the thread priorities in the queue, and then allocates CPU resource usage time to threads based on this weight. The lower the priority value in the queue, the greater the weight it receives in CPU resource time allocation; a higher weight means more frequent access to CPU resource usage time.

[0078] Step S1033: Based on the candidate priority value, allocate CPU resource usage time to the second thread.

[0079] In this embodiment, under the second scheduling mode, when the queue corresponding to the candidate priority value is not empty when the time-slice round-robin scheduling algorithm scans, each thread in the queue corresponding to the candidate priority value can be traversed. When the second thread is traversed, the CPU resource usage time allocated to the queue corresponding to the candidate priority value is taken as the CPU resource usage time of the second thread.

[0080] When the second thread is allocated CPU time, it gains CPU execution rights and can continue to execute until the CPU time is completely consumed, or the second thread voluntarily relinquishes CPU execution rights, or it is preempted by a higher priority thread.

[0081] For example, the first priority range can include 0-99, and the second priority range can include 100-139 (the smaller the value, the higher the weight).

[0082] Current priority value: The current priority value of the second thread is 120, which falls within the second priority range. After selecting 50 from 0-99 as a candidate priority value, the priority value of the second thread can be switched from 120 to 50, and it can be moved into the queue with a priority value of 50 managed by the time-slice round-robin scheduling algorithm.

[0083] When the current priority value of the second thread is 120, the second thread shares a global queue with other threads having priority values in the range 100-139, and CPU time is allocated by weight. For example, a thread with priority value 120 has a low weight and can wait for a long time.

[0084] The second thread enters a separate queue with priority value 50, which has a higher priority than all threads in the global queue covering priority values 100-139, and threads in the queue are allocated time slices in a round-robin manner.

[0085] In the second scheduling mode, scanning can be performed from the queue with priority value 0 based on a time slice round-robin scheduling algorithm.

[0086] Assuming that the queues with priority values 0-49 are empty, when the queue with priority value 50 (non-empty, containing the second thread and other threads) is scanned, scanning of lower priority queues is immediately stopped.

[0087] In the case where the queue with priority value 50 is allocated a usage time of CPU resources (assuming 10 ms), if the second thread is the first thread in the queue, the second thread can obtain the first 10 ms time slice and start execution. When the 10 ms time slice of the second thread is exhausted, the second thread can be moved to the tail of the queue, wait for the next round of scheduling, and 10 ms later, the next thread (such as thread B) in the queue is switched to and allocated a new 10 ms time slice. When the other threads in the queue are executed, the second thread can again be queued at the head. The above process is repeated until the queue is empty or preempted by a higher priority.

[0088] Although the second thread is moved to the tail of the queue, when the next scheduling is initiated, the queue with priority value 50 can still be scanned first,

[0089] Although the second thread is moved to the tail of the queue after the time slice is exhausted, since the priority value of the queue with priority value 50 is fixed and each time of scheduling will preferentially scan high-priority queues, as long as the queue with priority value 50 is non-empty, time slices can be continuously allocated to the queue to avoid being interrupted by lower priority queues (such as 51-99), thereby improving the continuity of execution of the second thread.

[0090] When all separate queues with priority values 0-99 are empty, the global queue covering priority values 100-139 is processed.

[0091] In the second scheduling mode, a priority value in the first priority range is selected as a candidate priority value, and the second thread is switched from the current priority value to the candidate priority value. This can improve the advantage of the second thread in resource competition, so that the second thread can be selected and executed faster, thereby reducing the delay caused by waiting for resources and improving the response speed and running efficiency of the target application. Moreover, the thread with high priority is less likely to be preempted by other threads during execution, thereby reducing interruptions and pauses caused by resource competition and improving the continuity of execution of the second thread.

[0092] As another optional embodiment of the present application, the processing method provided in Embodiment 3 of the present application mainly provides an implementation of the candidate priority value, which can include but is not limited to the following.

[0093] The priority value represented by the candidate priority value is the highest in the first priority range.

[0094] From the essential characteristics of the priority value, the priority value in the first priority range is naturally higher than the priority value in the second priority range in terms of numerical level. This difference in numerical value fundamentally provides a prerequisite for the thread to have an advantage in resource competition, so that the thread in the first priority range has stronger competitiveness in subsequent resource allocation.

[0095] On this basis, the priority value representing the highest priority in the first priority range can be selected as the candidate priority value. The candidate priority value is at the top of the first priority range, representing the highest competitiveness of the second thread in resource competition under the current scheduling environment. Subsequently, the second thread can enter the queue corresponding to the first priority range to wait for further resource allocation and scheduling execution. This can further improve the advantage of the second thread in resource competition and ensure that the second thread can obtain CPU resource usage time in a more preferential order relative to other queues, thereby minimizing the delay caused by waiting for resources and improving the response speed and running efficiency of the target application.

[0096] For example, the first priority range is 0-99, and the second priority range is 100-139. In the first scheduling mode, the current priority value of the second thread is 120, which belongs to the second priority range. At this time, the second thread shares a global queue with threads having priority values in the range of 100-139, and the CPU time is allocated by weight. For example, the thread with a priority value of 120 has a low weight, and may have to wait for a long time to obtain CPU resource usage time, and is also susceptible to resource preemption by other threads during execution, resulting in discontinuous execution and phenomena such as freezing.

[0097] When the load of the electronic device meets the target condition, the highest priority value 0 is selected from the first priority range 0-99 as the candidate priority value after the first thread is switched from the first scheduling mode to the second scheduling mode. Then the priority value of the second thread is switched from 120 to 0, and it is moved into the queue with the priority value 0 managed by the time slice round-robin scheduling algorithm.

[0098] In the second scheduling mode, the queue with the priority value 0 is scanned based on the time slice round-robin scheduling algorithm. Since the queue with the priority value 0 is the highest priority queue in the first priority range, as long as the queue is not empty, scanning lower priority queues (such as queues with priority values 1-99) can be stopped immediately, and the queue with the priority value 0 is processed preferentially. Assuming that the queue is allocated a CPU resource usage time (assuming 10 ms), in the queue, no matter where the second thread is located in the queue, when it is the turn of the order, it can immediately obtain the 10 ms time slice and start executing the task.

[0099] In the 10 ms time slice, the second thread can continue to execute until the time slice is exhausted or the second thread voluntarily gives up the CPU execution right or is preempted by a higher priority thread (in the second scheduling mode, there is usually no higher priority thread than the selected highest priority value to preempt). When the 10 ms time slice of the second thread is exhausted, the second thread can be moved to the tail of the queue, wait for the next round of scheduling, and 10 ms later, switch to the next thread (such as thread B) in the queue and allocate a new 10 ms time slice. When the other threads in the queue have finished executing, the second thread can again be in the head of the queue and repeat the above process until the queue is empty or preempted by a higher priority.

[0100] In this way, compared to only switching the second thread to the first priority range (such as selecting a priority value 50), selecting the highest priority value 0 in the first priority range as the candidate priority value can further improve the position of the second thread in resource competition. When allocating resources, the queue with the priority value 0 is always scanned and processed first, ensuring that the second thread can obtain CPU resources more timely, greatly reducing the delay caused by waiting for resources, and improving the response speed and running efficiency of the target application. At the same time, high-priority threads are less likely to be preempted by other threads during execution, further reducing interruptions and pauses caused by resource competition, and further improving the continuity of the execution of the second thread, ensuring the smooth execution of the target application function.

[0101] As another optional embodiment of the present application, the processing method provided in Embodiment 4 of the present application, the above-mentioned embodiment of selecting a priority value from the first priority range to determine a candidate priority value can specifically include but is not limited to the following steps:

[0102] Step S11: Selecting a priority value from the first priority range for each second thread to determine a candidate priority value.

[0103] The higher the importance of the second thread, the higher the priority corresponding to the candidate priority value.

[0104] In actual applications, a target application usually includes multiple functional modules, each of which is implemented by a corresponding second thread. Different functional modules have different influences on the performance and user experience of the application, and therefore the second threads can be classified according to the importance of the functional modules. For example, for a key functional module with high real-time requirements and directly affecting user experience, the priority represented by the candidate priority value of the corresponding second thread is relatively high; and for some auxiliary functional modules, the priority represented by the candidate priority value of the corresponding second thread can be relatively low.

[0105] After each second thread obtains its own candidate priority value, each second thread can enter an independent queue corresponding to the candidate priority value. In the second scheduling mode, the queues are scanned based on the time slice round-robin scheduling algorithm. When scanning the queues, the second threads with higher importance are scanned in earlier order, and accordingly, the second threads obtain CPU resource usage time in earlier order.

[0106] Next, a video conference application (i.e., an embodiment of the target application) is taken as an example for illustration. For example, the application can include the following multiple second threads:

[0107] Video capture and encoding thread: responsible for capturing video data from a camera in real time and performing encoding compression for transmission over the network. The smoothness and real-time performance of the video are critical to the video conference, and if the thread cannot obtain CPU resources in time, it will cause video lag and delay, which will seriously affect the conference experience. Therefore, this thread has a very high importance in the target application.

[0108] Audio capture and encoding thread: real-time transmission of audio is also important, and clear voice communication is the basis of the conference. If the audio lags or delays, it will affect the communication effect of the conference. Therefore, the importance of this thread is also high.

[0109] Chat message processing thread: This thread is responsible for handling chat messages in the meeting, including receiving, displaying, and sending messages. While chat functionality is also commonly used in meetings, the processing of chat messages can have some delay compared to the real-time requirements of video and audio, and will not have a significant impact on the core experience of the meeting. Therefore, the importance of this thread is relatively low.

[0110] Screen sharing thread: The screen sharing function allows participants to share their screen content, which is very important for some meeting scenarios that need to show materials or demonstrate operations. However, if there is a short pause in screen sharing, it will not directly affect the basic communication of the meeting as much as video and audio problems. Therefore, the importance of this thread is at a medium level.

[0111] In the second scheduling mode, candidate priority values are selected for each of the above-mentioned second threads from the first priority range (assuming 0-99):

[0112] Since the video capture and encoding thread has the highest importance, the highest priority value 0 in the first priority range is selected as its candidate priority value. In this way, when resources are allocated, this thread will be scheduled first and will be able to obtain CPU resources first, ensuring real-time capture and encoding of video data.

[0113] The audio capture and encoding thread has the second highest importance, and the priority value 10 is selected as its candidate priority value. Although the priority is lower than the video thread, it can still wait for resource allocation in a higher priority queue to ensure real-time transmission of audio.

[0114] The screen sharing thread has a medium importance, and the priority value 30 is selected as its candidate priority value. This thread will obtain resources after the video and audio threads, but it can still complete the screen sharing task within a relatively reasonable time.

[0115] The chat message processing thread has the lowest importance, and the priority value 50 is selected as its candidate priority value. This thread will obtain CPU resources to process chat messages after other important threads have completed their tasks, and even with some delay, it will not have a significant impact on the overall experience of the meeting.

[0116] In this way, in the second scheduling mode, second threads of different importance can be allocated CPU resources according to their priorities, ensuring that the key functions of the video conference application (video and audio) can run stably and smoothly, while also considering other auxiliary functions (screen sharing and chat message processing), improving the overall performance and user experience of the application.

[0117] In the second scheduling mode, one priority value corresponding to each second thread in the first priority range is selected as a candidate priority value, and the higher the importance of the second thread, the higher the priority corresponding to the candidate priority value. The second thread is switched from the current priority value to the candidate priority value, which can improve the advantage of the second thread in resource competition, reduce the delay caused by waiting for resources, improve the response speed and running efficiency of the target application, and at the same time, make the limited resources more concentratedly allocated to the second thread with high importance, ensure the smooth execution of the target application, and improve the user experience.

[0118] As another optional embodiment of the present application, referring to Figure 3 , the present embodiment mainly provides an implementation of the above step S1033. As shown in Figure 3 , step S1033 can specifically include but is not limited to the following steps:

[0119] Step S10331, determining the preset use time corresponding to the candidate priority value as the use time of the central processing unit resource of the second thread.

[0120] In the present embodiment, a mapping table between priority values and preset use times can be established according to performance tests and actual application scenario analysis. For example, if the first priority range is 0-99, a preset use time is set for each priority value in this range. For example, when the priority value is 0, the preset use time can be 50 ms; when the priority value is 10, the preset use time can be 45 ms; and so on, until the priority value is 99, the preset use time can be 10 ms.

[0121] When the candidate priority value of the second thread is determined, the preset use time corresponding to the candidate priority value can be found in the mapping table, and then this preset use time is directly allocated to the second thread as the use time of the CPU resource available for the second thread this time. For example, if the candidate priority value of the second thread is 20, the corresponding preset use time is found to be 40 ms in the mapping table, and then 40 ms can be used as the CPU resource use time of the second thread.

[0122] Next, taking a real-time battle game (i.e., an embodiment of the target application) as an example, for example, the character movement thread, skill release thread and picture rendering thread in the game are all second threads. The character movement thread is crucial to the smoothness of the game and the operation experience of the player, so it can be assigned a higher candidate priority value, such as 15. According to the preset mapping table, the preset use time corresponding to the priority value 15 is 42ms, so the character movement thread can be allocated 42ms of CPU resource use time to ensure that it can respond to the player's operation instructions in time and realize smooth character movement. Although the picture rendering thread is also important, it has relatively lower real-time requirements than the character movement thread, and can be assigned a priority value of 30, corresponding to a preset use time of 35ms. In this way, while ensuring smooth character movement, the picture rendering thread can also be reasonably allocated resources to achieve overall smooth operation of the game.

[0123] In this embodiment, by pre-setting a corresponding preset use time for each priority value in the first priority range, when the candidate priority value of the second thread is determined, the preset use time corresponding to the candidate priority value can be directly used as the central processor resource time available to the second thread this time. This way can quickly allocate resource use time to the second thread, reduce the computational complexity in the scheduling process, and improve the scheduling efficiency. At the same time, since the preset use time is determined through system optimization and testing, it can to some extent guarantee that different priority threads obtain relatively reasonable resource allocation and meet the basic needs of thread running time in different application scenarios.

[0124] As another optional embodiment of the present application, referring to Figure 4 The flowchart of a processing method provided by Embodiment 6 of the present application is shown in the figure, and this embodiment is mainly an embodiment of the above step S1033. As shown in the figure, step S1033 can specifically include but is not limited to the following steps: Figure 4

[0125] Step S10332, based on the load of the electronic device, adjusting the preset use time corresponding to the candidate priority value, and determining the use time obtained after adjustment as the use time of the central processor resource of the second thread.

[0126] ​In this embodiment, the load of the electronic device can be measured by various indicators, such as CPU usage, memory usage, disk I / O operation frequency, and the like. For example, the electronic device can collect data such as CPU usage and memory usage once every certain time (such as 100 ms), and process the data to obtain a load value reflecting the current load state of the device. The load value can be a specific numerical value, or a graded state, such as low load, medium load, high load, and the like.

[0127] When the load value indicates that the electronic device is in a low load state, the preset usage time can be increased by a certain percentage, such as 20%. For example, if the preset usage time corresponding to the candidate priority value is 40 ms, after increasing by 20%, the adjusted usage time is 40 x (1 + 20%) = 48 ms.

[0128] When the load value indicates that the electronic device is in a medium load state, the preset usage time can be kept unchanged.

[0129] When the load value indicates that the electronic device is in a high load state, the preset usage time can be decreased by a certain percentage, such as 20%. For example, if the preset usage time is 40 ms, after decreasing by 20%, the adjusted usage time is 40 x (1 - 20%) = 32 ms.

[0130] The adjusted usage time will be used as the central processing unit resource time available to the second thread this time.

[0131] In this embodiment, taking a smartphone (which is one embodiment of the electronic device) running multiple applications simultaneously as an example, when the user only opens a simple word processing application, the load of the smartphone is low. At this time, if there is a thread (second thread) in the word processing application for saving the document in real time, the preset usage time corresponding to the candidate priority value of the thread is 30 ms. Since the load of the smartphone is low, the usage time can be increased by 20%, and after adjustment, it is 36 ms. In this way, the thread for saving the document in real time can obtain more CPU resource usage time, complete the document saving operation faster, and improve the response speed of the application.

[0132] When the user simultaneously opens multiple large-scale games and video playback applications, the load of the smartphone will become very high. At this time, a character animation rendering thread (second thread) in the game, the preset usage time corresponding to the candidate priority value of the thread is 50 ms. Since the load of the smartphone is high, the usage time can be decreased by 20%, and after adjustment, it is 40 ms. In this way, the occupation of CPU resources by the thread can be reduced, so that other more important threads (such as system critical processes, real-time threads of other applications, etc.) can also obtain sufficient resources, ensuring the stable operation of the smartphone system, and avoiding problems such as lag or death.

[0133] In the second scheduling mode, if scheduling is performed based on the time slice round-robin scheduling algorithm, each independent queue can be adjusted as a whole for the preset usage time, and the adjusted usage time is determined as the usage time of the CPU resource of each second thread in the independent queue, so as to ensure the consistency of the usage time of the CPU resource of each second thread in the same queue.

[0134] In the second scheduling mode, in the embodiment, one priority value is selected from the first priority range to determine a candidate priority value, and the second thread is switched from the current priority value to the candidate priority value, which can improve the advantage of the second thread in resource competition, so that the second thread can be selected and executed faster, thereby reducing the delay caused by waiting for resources and improving the response speed and running efficiency of the target application. Moreover, the thread with high priority is less likely to be preempted by other threads during execution, thereby reducing the interruption and pause caused by resource competition, improving the continuity of the execution of the second thread, and further ensuring the smoothness of the running of the target application.

[0135] At the same time, the load of the electronic device is not constant, but a dynamic parameter. Different load states have different requirements for thread resource allocation. When the device load is light, the system has sufficient resources to allocate. At this time, appropriately increasing the resource usage time of the second thread can make the second thread more fully utilize the CPU resource, deeply and completely execute its task, avoid frequent interruption due to insufficient resource allocation, and further improve the running efficiency, so that the target application can run in a more optimal state in a low-load environment. On the contrary, when the device load is heavy, the system resource becomes tight, and the competition for resources by numerous threads becomes more intense. In this case, it is particularly necessary to reduce the resource usage time of the second thread. In this way, sufficient resources can be released for other important threads to ensure that they can also successfully execute critical tasks, avoid the situation that other threads cannot normally execute due to excessive concentration of resources on the second thread, and further prevent serious problems such as system freezing or even crash, thereby ensuring the stable running of the system in a heavy-load environment.

[0136] As another optional embodiment of the present application, refer to Figure 5 The flowchart of a processing method provided in Embodiment 7 of the present application is shown in FIG. 7, which can include but is not limited to the following steps: Figure 5

[0137] Step S201, determining a first thread required by an electronic device to run a target application.

[0138] ​Step S202, if the load of the electronic device meets a target condition, switching the first thread from a first scheduling mode to a second scheduling mode; the second scheduling mode corresponds to a central processing unit scheduling level higher than a central processing unit scheduling level corresponding to the first scheduling mode.

[0139] The second scheduling mode at least comprises running the target application by a second thread.

[0140] The central processing unit scheduling level corresponding to the second scheduling mode is used to improve the continuity of running the target application by the second thread.

[0141] Step S203, in the second scheduling mode, allocating a usage time of a central processing unit resource for the second thread.

[0142] Step S204, executing the second thread based on the usage time of the resource allocated for the second thread.

[0143] The detailed processes of steps S201-S204 can be referred to the related introduction of steps S101-S104 in embodiment 1, and will not be repeated here.

[0144] Step S205, when the second thread is not completely stopped, switching the first thread from the second scheduling mode to the first scheduling mode.

[0145] In the embodiment, the second thread not being completely stopped can be understood as that the second thread has completed a main function task (for example, the camera shooting thread has completed the shooting storage operation), but there can be some subsequent cleaning work (for example, the operation of releasing and arranging the temporary resources used in the execution process), state updating work (for example, the operation of modifying and synchronizing the state information of the object itself or the system related object according to the execution result of the main function task) or the process of information exchange and collaborative operation with other threads, components or external entities of the system, etc. which have not been completed and have not released the CPU resources occupied.

[0146] When the first thread is switched from the second scheduling mode to the first scheduling mode, since the second thread is created by the first thread, the second thread can inherit the current scheduling mode attribute of the first thread, that is, the first scheduling mode after the switching of the first thread can be followed.

[0147] In the first scheduling mode, the second thread can be scheduled based on a time-sharing scheduling strategy. The specific scheduling principle can be referred to the related introduction of the time-sharing scheduling strategy in embodiment 2, and will not be repeated here.

[0148] In the embodiment, switching the first thread from the second scheduling mode to the first scheduling mode when the second thread is not completely stopped can reduce the impact on subsequent other threads, reasonably allocate system resources, and ensure the overall running efficiency and stability of the system. For example, assume that a camera application and a music playing application are running simultaneously on the electronic device. When the user uses the camera application to take a photo, in the initial stage, the camera application is started, and the operating system creates an original thread (i.e., an embodiment of the first thread), which then creates a preview thread, an ISP thread, a photo taking thread, and the like (i.e., an embodiment of the second thread). At this time, if the load of the electronic device meets the target condition, the first thread is switched to the second scheduling mode, and the second thread inherits the mode to obtain a higher CPU scheduling level, ensuring that the photo taking function can be quickly and smoothly executed, such as real-time display of the preview screen, rapid image processing, and timely storage of the photo, and the like.

[0149] In the photo taking completion stage, after the user presses the photo taking button, the photo taking thread completes the photo storage operation, at which time the main task of the photo taking function has been completed, but the photo taking thread can still have some subsequent work, such as updating the state information of the camera application (such as restoring the shooting mode to the default, updating the album thumbnail, and the like), or interacting with other system components (such as notifying the media library to update the photo information). In this stage, although the core function of the photo taking thread has ended, the photo taking thread has not yet completely stopped. If the first thread is not switched from the second scheduling mode back to the first scheduling mode at this time, since the second thread inherits the high scheduling level of the first thread, more CPU resources will be continuously occupied. At this time, the user can wish to continue using the music playing application, and the audio decoding thread in the music playing application also needs CPU resources to ensure smooth music playing. However, since the camera application related threads are still at a high scheduling level, the threads of the music playing application can not obtain sufficient CPU resources in time, resulting in a lag phenomenon in the music playing.

[0150] After the first thread is switched from the second scheduling mode to the first scheduling mode when the second thread is not completely stopped, the scheduling level of the camera application related threads is reduced, and the occupation of the CPU resources is reduced. In this way, the threads of the music playing application have more opportunities to obtain CPU resources, can more smoothly perform audio decoding and the like, and ensure normal music playing, thereby reducing the impact on subsequent other threads (such as the music playing thread), improving the utilization efficiency of system resources, and the overall running effect.

[0151] As another optional embodiment of the present application, the present application provides a processing method for the embodiment 8, which mainly is an embodiment of the determination method of the second thread, and can include but is not limited to the following steps:

[0152] Step S21, obtaining the activity information of the target application in the startup process.

[0153] In the startup of the target application, the monitoring tool or interface provided by the system can be used to collect the relevant activity information of each thread in the startup process of the target application in real time. The activity information can include but is not limited to the start time and end time of each operation executed by the thread.

[0154] For example, for a camera application under a platform such as MTK Platform or Qcom Platform, multiple levels of thread activities may be involved in the startup process, such as Camera HAL Layer and Cameraserver Layer.

[0155] In the Camera HAL Layer, the following threads can be included:

[0156] The Open thread can be responsible for initializing the connection of the camera hardware and establishing a communication channel with the camera driver. When the Open thread is executed, the system attempts to access the camera hardware, performs necessary hardware detection and initialization settings, such as checking whether the camera sensor is working properly, setting initial hardware parameters, etc. If there is a fault in the camera hardware or the driver loading is abnormal, the Open thread may fail, resulting in the camera application unable to start normally.

[0157] The ConfigureStream thread can be mainly used to configure parameters such as frame rate, resolution, or enable / disable certain functions for camera input and output streams. Its execution process may need to make complex parameter adjustments according to different application requirements. For example, a user may want to shoot a video at a high frame rate (such as 60fps) and a specific resolution (such as 1080p). The ConfigureStream thread can configure the camera data stream accordingly according to these requirements, involving interaction with the camera hardware and underlying driver to ensure that data can be transmitted and processed according to the set parameters.

[0158] The Create and Init Pipelines thread can be used to create nodes for various algorithms required for graphics processing and link them together, while initializing some ISP (Image Signal Processor) parameter configurations. This process involves a large number of algorithm initialization and node connection operations. For example, nodes for image noise reduction, color correction, sharpening, etc. algorithms are created and connected in a certain order to form a complete image processing pipeline. At the same time, the ISP needs to be initialized to set its working mode and parameters to ensure that it can correctly process the image data collected from the camera sensor.

[0159] PrepareFinalizePipeline thread can be used to start the relevant threads of algorithm nodes, and initialize some parameters required by the graph, such as the display format of the image, the color space, etc., to prepare for the final image output.

[0160] Begin StreamOn thread can mark the formal start of camera data stream transmission. After completing the previous series of initialization operations, Begin StreamOn can send instructions to the camera hardware to start collecting image data and transmitting the data to the subsequent processing link according to the predetermined data stream format.

[0161] Pipeline Process Stream Data thread can be used to process the data stream collected by the camera. In this process, the image data will pass through the image processing pipeline created and initialized in the previous step, and be processed by each algorithm node in turn, such as noise reduction, color correction, sharpening, etc., to finally obtain the processed image data.

[0162] Callback First Frame thread can trigger a callback function after the camera successfully collects and processes the first frame of image data, notifying the upper layer application that the first frame of image is ready. This is very important for some applications that need to display the camera screen in real time, as it marks that the camera can normally output image data, and the application can start subsequent display and processing operations.

[0163] In the Cameraserver Layer, the following threads can be included:

[0164] connectDevice thread can be used to establish a connection with the camera device. It may involve interaction with the underlying device management module, obtaining access rights to the camera device, and making necessary connection settings.

[0165] ConfigureStream thread is similar to ConfigureStream thread in Camera HAL Layer, and is also used to configure the relevant parameters of the camera data stream. In Cameraserver Layer, ConfigureStream thread may focus more on coordination with other system modules, such as interaction with display modules, storage modules, etc., to ensure that the camera collected data can be transmitted and stored according to system requirements.

[0166] The setRepeatingRequests thread can start the process of out-stream preview. When the camera application is started, the user wants to see the picture collected by the camera in real time, and the setRepeatingRequests thread is responsible for starting this preview process. It sends instructions to the camera hardware to continuously collect image data according to the predetermined parameters (such as frame rate, resolution, etc.), and transmits the data to the display module for real-time display.

[0167] The start time and end time of each operation performed by each thread in the camera application can be obtained through the system interface.

[0168] In step S22, based on the activity information, a second thread is selected from the multiple threads of the target application, where the time length of the target application in the startup process meets a set condition.

[0169] In this embodiment, the set condition can be set according to the characteristics and performance requirements of the target application, which is not limited in this application. For example, the set condition can be a set time threshold, or a set time proportion.

[0170] In this embodiment, the sum of the execution time lengths of all operations can be determined according to the start time and end time of each operation in the thread, and the sum of the execution time lengths of all operations is determined as the time length of the thread in the startup process.

[0171] If the time length is greater than the set time threshold, or the time length of the thread is greater than the set time proportion in all threads, the thread can be regarded as a second thread.

[0172] For example, in the camera application, in the Camera HAL Layer, it is determined that the time length of the Open thread, the ConfigureStream thread, the Create and Init Pipelines thread, and the PrepareFinalizePipeline thread all meet the set condition, and these threads can all be regarded as second threads.

[0173] In this embodiment, a public class can be created in the software code of the target application, which can encapsulate the logic of judging whether to start the optimization strategy (such as judging whether the load of the electronic device meets the target condition) and switching the scheduling mode (such as switching the first thread from the first scheduling mode to the second scheduling mode).

[0174] In a second thread, the interface of a public class can be called, allowing the system to dynamically adjust the scheduling mode based on the current load of the electronic device to optimize the startup performance of the target application. If this interface is not called in other threads, the system will not perform the load assessment and mode switching operations, and these threads will run according to the default scheduling mode (e.g., the first scheduling mode). This approach allows for targeted optimization based on the importance of different threads and their impact on the startup performance of the target application, avoiding the performance overhead caused by unnecessary mode switching.

[0175] For example, such as Figure 6 As shown, the second thread, such as the Open thread, ConfigureStream thread, Create and InitPipelines thread, or PrepareFinalizePipeline thread, can call the interface of the public class, so that the system can determine whether the load of the electronic device is greater than 75%. If so, it switches from the first scheduling mode to the second scheduling mode. In the first scheduling mode, scheduling is based on SCHED_OTHER, and in the second scheduling mode, scheduling is based on SCHED_RR.

[0176] If there are 5 threads in the Task Consumer Queue, that is, the cpu sched (an implementation of a subsystem for allocating the usage time of CPU resources in an operating system) has allocated the usage time of CPU resources for 5 threads. At the same time, there are 8 threads waiting for execution, which are a thread, b thread, c thread, d thread, e thread, f thread, g thread, ConfigureStream thread (that is, an implementation of the second thread), and the Task_Queue can represent the global execution order of the 8 threads waiting for execution. These threads are currently in the global queue managed by SCHED_OTHER, and wait for CPU resources in turn according to the global execution order. Among them, the global execution order of the a thread is 6, and the global execution order of the ConfigureStream thread is 13. When the ConfigureStream thread calls the interface of the public class, the system judges that the load of the electronic device is greater than 75% (that is, an implementation of the load of the electronic device satisfying the set condition) and switches the scheduling mode (Change Cpu Algo), specifically from the first scheduling mode to the second scheduling mode. In the second scheduling mode, the ConfigureStream thread enters the independent queue managed by SCHED_RR, so that the ConfigureStream thread is switched from the global execution order of 13 to the global execution order of 6, which can reduce the delay of the ConfigureStream thread caused by waiting for resources (for example, the time length of its Runable (in the waiting state) is shortened from 45.939 ms to 0.081 ms), and improve the response speed and running efficiency of the camera application. Moreover, the high-priority thread is less likely to be preempted by other threads during execution, thereby reducing interruptions and pauses caused by resource competition and improving the continuity of ConfigureStream thread execution.

[0177] When the scheduling mode switching strategy described above is adopted, the global execution order of the Open thread, ConfigureStream thread, Create and Init Pipelines thread, and PrepareFinalizePipeline thread, and other second threads are all advanced, and the overall waiting time of the entire camera application thread group is significantly reduced.

[0178] In order to intuitively present this optimization effect, it can be explained in combination with FIG. 7. The running of the camera application is a dynamic and continuous process, and its running state is different at different times, and the Total Time (that is, the total time length from the start of the camera to the completion of a series of key operations) also fluctuates. In order to accurately obtain the change of the Total Time in different states, a sampling analysis method can be used.

[0179] In FIG. 7, the abscissa can be used to represent the sampling times, which can reflect the time sequence and frequency of data collection. From the increase of the abscissa, the time advancing process of data collection can be clearly seen; the ordinate can represent the Total Time, and the Total Time data obtained by each sampling is corresponded to the ordinate and connected by a curve, which can intuitively show the change trend of the Total Time at different sampling times.

[0180] By comparing the curves in the two cases of starting the optimization strategy (that is, implementing the above scheduling mode switching strategy) (which can be represented as After optimization) and not starting the optimization strategy (which can be represented as Before optimization), it can be clearly seen that after starting the optimization strategy, the Total Time is obviously shortened. This significant change can indicate that the scheduling mode switching strategy can effectively reduce the waiting time of the camera application thread group, speed up the running speed of the camera application, and effectively improve the performance of the camera application, bringing a smoother and more efficient use experience for users.

[0181] In this embodiment, by obtaining the activity information of the target application in the startup process, including the start time and end time of each thread operation, etc. Based on these detailed activity information, the time length of each thread in the startup process can be accurately calculated. According to the set conditions, the second thread whose time length meets the conditions is accurately selected from a plurality of threads, which can avoid indiscriminate optimization of all threads, and can concentrate resources to optimize the key threads that affect the startup performance of the target application, thereby improving the optimization efficiency.

[0182] As another optional embodiment of the present application, the present application provides a processing method for the embodiment 9 of the present application. The embodiment mainly provides an implementation of the above-mentioned determination method of the second thread, which can specifically include but is not limited to the following steps:

[0183] Step S31, in response to a user input, determining the thread specified by the user as the second thread.

[0184] The user input can be in various forms, such as a touch operation through a touch screen of the electronic device, for example, long pressing a specific area in the target application interface, sliding a specific icon, etc.; a pressing operation through a physical button, for example, a custom button in a camera application for specifying a key thread; or a voice instruction, for example, the user saying "set this thread as a key thread" and the like, and the electronic device triggers the corresponding operation after recognizing the voice instruction through a voice recognition system.

[0185] After determining the user-specified thread as the second thread, the thread will participate in the subsequent scheduling mode switching and resource allocation process. As described above, when the electronic device load meets the target condition, the first thread will switch to the second scheduling mode, and the second thread can inherit the scheduling mode attribute after the first thread switches, thereby obtaining a higher central processing unit scheduling level. This means that the user-specified key thread can obtain CPU resources more timely, reduce the delay caused by waiting for resources, and ensure that the function that the user pays attention to in the target application can run more smoothly and efficiently. For example, the user specifies the video decoding thread in the video playback application as the second thread, and when the device load is high, the video decoding thread can obtain CPU resources preferentially, more continuously decodes video data, avoids the occurrence of a lag phenomenon, improves the smoothness of video playback, and meets the user's requirements for video viewing experience.

[0186] In this embodiment, the user can flexibly specify a key thread according to actual needs and use scenarios, so that the electronic device can more accurately allocate resources and preferentially ensure the running of the function that the user pays attention to, effectively improving the response speed and running efficiency of the target application, and bringing a better use experience to the user.

[0187] Next, the processing device provided by the present application is introduced. The processing device introduced below can be referred to in correspondence with the processing method introduced above.

[0188] Reference Figure 8 The processing device includes a first determination module 100, a first switching module 200, an allocation module 300, and an execution module 400.

[0189] The first determination module 100 is configured to determine a first thread required by an electronic device to run a target application.

[0190] The first switching module 200 is configured to switch the first thread from the first scheduling mode to a second scheduling mode if a load of the electronic device meets a target condition; the second scheduling mode corresponds to a central processing unit scheduling level higher than a central processing unit scheduling level corresponding to the first scheduling mode; the second scheduling mode at least includes running the target application by a second thread; and the central processing unit scheduling level corresponding to the second scheduling mode is used to improve continuity of running the target application by the second thread.

[0191] The allocation module 300 is configured to allocate a use time of a central processing unit resource for the second thread in the second scheduling mode.

[0192] The execution module 400 is configured to execute the second thread based on the use time of the resource allocated for the second thread.

[0193] The allocation module 300 can be specifically configured to:

[0194] select a priority value from a first priority range as a candidate priority value in the second scheduling mode;

[0195] switch the second thread from a current priority value to the candidate priority value; the current priority value belongs to a second priority range; and a priority represented by a priority value in the second priority range is lower than a priority represented by a priority value in the first priority range;

[0196] allocate a use time of a central processing unit resource for the second thread based on the candidate priority value.

[0197] The priority represented by the candidate priority value can be the highest in the first priority range.

[0198] If the second thread is multiple, the allocation module 300 can specifically include the following steps:

[0199] select a priority value from the first priority range as a candidate priority value corresponding to each of the second threads respectively; and the higher the importance of the second thread is, the higher the priority corresponding to the candidate priority value is.

[0200] The allocation module 300 can specifically include the following steps:

[0201] determine a preset use time corresponding to the candidate priority value as the use time of the central processing unit resource for the second thread.

[0202] The allocation module 300 allocates the use time of the central processor resource for the second thread based on the candidate priority value, and specifically can include:

[0203] Based on the load of the electronic device, the preset use time corresponding to the candidate priority value is adjusted, and the use time obtained after the adjustment is determined as the use time of the central processor resource of the second thread.

[0204] The processing device can further include:

[0205] The second switching module is configured to switch the first thread from the second scheduling mode to the first scheduling mode when the second thread is not completely stopped.

[0206] The processing device can further include:

[0207] The second determination module is configured to:

[0208] Obtain activity information of the target application during the startup process;

[0209] Based on the activity information, select a second thread from a plurality of threads of the target application, wherein the second thread satisfies a set condition in terms of time consumption during the startup process of the target application.

[0210] The processing device can further include:

[0211] The third determination module is configured to determine a thread specified by a user as the second thread in response to a user input.

[0212] In another embodiment of the present application, an electronic device is provided, comprising:

[0213] A memory for storing a computer program;

[0214] A processor for executing the computer program to enable the electronic device to perform the following method steps:

[0215] Determine a first thread required for the electronic device to run a target application;

[0216] If the load of the electronic device satisfies a target condition, switch the first thread from a first scheduling mode to a second scheduling mode; the central processor scheduling level corresponding to the second scheduling mode is higher than the central processor scheduling level corresponding to the first scheduling mode; the second scheduling mode at least includes running the target application with a second thread; and the central processor scheduling level corresponding to the second scheduling mode is used to improve the continuity of running the target application by the second thread;

[0217] In the second scheduling mode, allocate the use time of the central processor resource for the second thread;

[0218] based on a usage time of the resource to which the second thread is assigned, executing the second thread.

[0219] In addition, it should be noted that the above-described apparatus embodiments are merely illustrative, wherein the units described as separate components can or can not be physically separate, and the components displayed as units can or can not be physical units, i.e., can be located in one place, or can be distributed on a plurality of network units. Part or all of the modules can be selected according to actual needs to achieve the purpose of the present embodiment. In addition, the connection relationship between the modules in the apparatus embodiments provided in the present application indicates that there is a communication connection between them, which can be implemented as one or more communication buses or signal lines.

[0220] Through the above description of the embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software and the necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. Generally, functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure for implementing the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better embodiment. Based on this understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, U disk, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., including a plurality of instructions to make a computer device (which can be a personal computer, training device, or network device, etc.) execute the methods described in various embodiments of the present application.

[0221] In the above embodiments, all or part can be realized by software, hardware, firmware or any combination thereof. When realized by software, it can be realized in the form of a computer program product in whole or in part.

[0222] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium, for example, the computer instructions can be transmitted from one website, computer, training device or data center to another website, computer, training device or data center through wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be stored by the computer or a data storage device such as a training device, a data center, etc. integrated with one or more available media sets. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)), etc.

Claims

1.A processing method, comprising: determining a first thread required for an electronic device to run a target application; switching the first thread from a first scheduling mode to a second scheduling mode if a load of the electronic device meets a target condition; the second scheduling mode corresponds to a central processing unit scheduling level higher than a central processing unit scheduling level corresponding to the first scheduling mode; the second scheduling mode at least comprises running the target application by a second thread; the central processing unit scheduling level corresponding to the second scheduling mode is used to improve continuity of running the target application by the second thread; allocating a usage time of a central processing unit resource for the second thread in the second scheduling mode; and executing the second thread based on the usage time of the resource allocated for the second thread. 2.The processing method of claim 1, wherein the allocating a usage time of a central processing unit resource for the second thread in the second scheduling mode comprises: selecting a priority value from a first priority range to determine a candidate priority value in the second scheduling mode; switching the second thread from a current priority value to the candidate priority value; the current priority value belongs to a second priority range; priority values in the second priority range represent a lower priority than priority values in the first priority range; allocating a usage time of a central processing unit resource for the second thread based on the candidate priority value. 3.The processing method of claim 2, wherein the candidate priority value represents the highest priority in the first priority range. 4.The processing method of claim 2, wherein if there are multiple second threads, the selecting a priority value from a first priority range to determine a candidate priority value comprises: selecting a priority value from a first priority range to determine a candidate priority value respectively corresponding to each of the second threads; the higher the importance of the second thread, the higher the priority corresponding to the candidate priority value. 5.The processing method of claim 2, wherein the allocating a usage time of a central processing unit resource for the second thread based on the candidate priority value comprises: determining a preset usage time corresponding to the candidate priority value as the usage time of the central processing unit resource for the second thread. 6.The processing method of claim 2, wherein the allocating a usage time of a central processing unit resource for the second thread based on the candidate priority value comprises: adjusting a preset usage time corresponding to the candidate priority value based on a load of the electronic device, and determining an adjusted usage time as the usage time of the central processing unit resource for the second thread. 7.The processing method of claim 1, further comprising: switching the first thread from the second scheduling mode to the first scheduling mode when the second thread is not completely stopped. 8.The processing method of claim 1, wherein the second thread is determined by: obtaining activity information of the target application in a starting process. Based on the activity information, a second thread is selected from the multiple threads of the target application, wherein the second thread is determined to satisfy a set condition in terms of time consumption during a starting process of the target application. 9.The processing method of claim 1, wherein the second thread is determined in the following manner: In response to a user input, a thread specified by a user is determined as the second thread. 10.An electronic device comprising: a memory for storing a computer program; a processor for executing the computer program to enable the electronic device to perform the following method steps: determining a first thread required for the electronic device to run a target application; if a load of the electronic device satisfies a target condition, switching the first thread from a first scheduling mode to a second scheduling mode; the second scheduling mode corresponds to a central processing unit scheduling level higher than a central processing unit scheduling level corresponding to the first scheduling mode; the second scheduling mode at least includes running the target application in a second thread; the central processing unit scheduling level corresponding to the second scheduling mode is used to improve continuity of running the target application in the second thread; in the second scheduling mode, allocating a usage time of a central processing unit resource for the second thread; and based on the usage time of the resource allocated to the second thread, executing the second thread.