Multi-thread management and control method and related equipment
By monitoring the system load and determining its importance based on the number of threads wake-up times and thread identification, the multi-threaded management and control method for different threads in the high-load scenario of CPU, solving the problem of controlling affecting the operation experience in the existing technology, and achieving the effect of rapidly reducing system load.
Patent Information
- Application Number
- CN202510336156.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-04-22
- Estimated Expiration
- 2045-03-21
AI Technical Summary
When handling CPU high-load scenarios, the prior art usually controls specific threads, which can easily affect the operation experience.
It provides a multi-threaded management method, which can monitor the system load, traverse some threads, determine its importance according to the number of threads wake-up times and thread identification, and perform thread control operations when the importance is too low, reducing the CPU resource usage rate.
In different high-load scenarios, different threads can be controlled to ensure that the operating experience is not affected and the system load is quickly reduced.
Smart Images

Figure CN119861976A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a system multi-thread control method and related equipment. Background Art
[0002] The resources of the central processing unit (CPU) of electronic devices are limited. If there are many tasks running on the CPU at the same time, it is easy to cause high CPU load. There are many problems caused by high CPU load, such as slow startup response, animation lag, ANR (application unresponsiveness), etc. Monitoring the high CPU load and controlling non-critical background processes can optimize the CPU load in high-load scenarios. However, the current high-load scenario control is often carried out for specific threads, and sometimes the control leads to a poor operating experience. Summary of the invention
[0003] The present application provides a multi-thread management and control method and related equipment, which can manage different threads in different high-load scenarios, and can reduce the system load in time without affecting the operating experience, so as to solve the above-mentioned technical problems.
[0004] In a first aspect, the present application provides a multi-thread control method, which includes: Monitor system load during system operation; When it is monitored that the system load exceeds a preset load threshold, traverse at least part of the threads in the system operation process; Execute the following command on the first thread traversed: At least obtain the wake-up count and thread ID of the first thread; Determine the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier, wherein the number of wake-up times of the first thread is positively correlated with the importance of the first thread, and the thread identifier is used to identify whether the first thread is a critical thread, and the importance of the critical thread is higher than that of a non-critical thread; When the importance of the first thread is too low, performing a thread control operation on the first thread, where the control operation is used to reduce the utilization rate of the CPU resources by the first thread; wherein the first thread belongs to at least some of the threads; Among them, the importance of the first thread is too low means that the importance of the first thread is lower than a preset importance threshold or the importance ranking of the first thread is located after the preset ranking position of the importance ranking of all threads in the current running process of the system, wherein the importance ranking is sorted in a direction from high importance to low importance.
[0005] Therefore, the present application can determine the importance of the first thread based on the number of wake-up times and the thread identifier of the first thread, and perform a thread control operation on the first thread when the importance of the first thread is too low. The control operation is used to reduce the utilization rate of CPU resources by the first thread. Under different load scenarios, the first thread may be a critical thread or a non-critical thread; and, under different load scenarios, the number of wake-up times of the first thread may be different. Therefore, under different load scenarios, it can be comprehensively determined based on the number of wake-up times and the thread identifier of the first thread whether to perform a thread control operation on the first thread to reduce the utilization rate of CPU resources by the first thread. This can timely reduce the system load while ensuring the user's operating experience. Compared with the prior art, the system load can be reduced in a shorter time.
[0006] In combination with the first aspect, in some possible embodiments of the present application, when the system load is monitored to exceed a preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread control method further includes: When the first thread is awakened during the operation of the system, the awakening count of the first thread is updated to the value of the current awakening count plus 1; and / or, When the first thread wakes up the next thread during system operation, the wake-up count of the first thread is updated to the value of the current wake-up count plus 1.
[0007] Thus, when the first thread is awakened, the wake-up count of the first thread is updated, and / or, when the first thread wakes up the next thread, the wake-up count of the first thread is also updated. It can be seen that the wake-up count of the first thread changes dynamically, and the importance of the first thread can be updated accordingly based on the updated wake-up count. This ensures that the importance of the first thread is updated in real time during system operation. Moreover, under different load scenarios, the wake-up count of the first thread also changes dynamically. Re-determining the importance of the first thread in combination with the updated wake-up count of the first thread can improve the accuracy of the management and control decisions on the first thread and maximize the user experience.
[0008] In combination with the first aspect, in some possible embodiments of the present application, when the system load is monitored to exceed a preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread control method further includes: When the first thread is identified as a key thread through the key thread identification table, the thread identifier is set to a first value, where the first value is used to indicate that the first thread is a key thread; or, When the first thread is identified as a non-critical thread through the critical thread list, the thread identifier is set to a second value, where the second value is used to indicate that the first thread is a non-critical thread.
[0009] Thus, the key thread identification table is used to identify whether the first thread is a key thread or a non-key thread, and different values are set for the thread label when the first thread is identified as a key thread or a non-key thread, respectively, so as to facilitate the rapid determination of the importance of the first thread during the traversal process, speed up the traversal speed, and increase the speed of reducing the system load, so as to quickly reduce the system load in a short time.
[0010] In combination with the first aspect, in some possible embodiments of the present application, the multi-thread management method further includes: When the first thread switches from foreground operation to background operation, when the first thread is identified as a non-critical thread according to the critical thread identification table, the thread identifier of the first thread is updated to a second value, where the second value is used to indicate that the first thread is a non-critical thread; Determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: The importance of the first thread is updated at least according to the number of wake-up times of the first thread and the updated thread identifier.
[0011] Thus, when the first thread switches from foreground operation to background operation, when the first thread is no longer a critical thread, the thread identifier of the first thread is updated to a second value, where the second value is used to indicate that the first thread is a non-critical thread, and the importance of the first thread is updated accordingly. This ensures that the importance of the first thread is updated in real time during system operation. Moreover, under different load scenarios, the thread identifier of the first thread also changes dynamically. Redetermining the importance of the first thread in combination with the updated thread identifier of the first thread can improve the accuracy of the management and control decisions on the first thread and maximize the user experience.
[0012] In combination with the first aspect, in some possible embodiments of the present application, the key thread identification table includes relevant identifiers of foreground threads, background running threads, graphics drawing threads, resource management threads, and system service management threads.
[0013] In combination with the first aspect, in some possible embodiments of the present application, the foreground thread is used to run in the system foreground; the background running thread is used to run in the system background to provide related services; the resource management thread is used to manage the allocation, release and optimization of system resources in the operating system; the system service management thread is used to control and manage background services, system processes and applications in the operating system.
[0014] Therefore, these major categories of threads are user-perceivable threads. These major categories of threads are set in the key thread identification table. When identifying whether the first thread is a key thread, it can be compared with the key thread identification table to quickly determine whether the first thread is a key thread, thereby improving the system operation speed, further improving the system's ability to reduce load, and further shortening the time for reducing the system load.
[0015] In combination with the first aspect, in some possible embodiments of the present application, determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: When the first thread is determined to be a non-critical thread according to its thread identifier, the importance of the first thread is determined in combination with the number of wake-up times and the priority of the first thread, wherein the priority of the first thread is positively correlated with the importance of the first thread.
[0016] Therefore, when the first thread is determined to be a non-critical thread based on the thread identifier of the first thread, the importance of the first thread can also be calculated in combination with the priority of the first thread. This can more comprehensively judge the importance of the first thread in the system operation process, making the system's judgment on the importance of the first thread more accurate, improving the accuracy of thread management and control, and further improving the user experience.
[0017] In combination with the first aspect, in some possible embodiments of the present application, when the system load is monitored to exceed a preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread control method further includes: The wakeup relationship between different threads is recorded during the system operation. The wakeup relationship is used to indicate the relationship between waking up and being awakened between threads. Generate a wake-up relationship topology structure according to the wake-up relationship during the system operation process; At least the wake-up times and thread ID of the first thread are obtained, including: Acquire the wakeup times and the wakeup depth of the first thread according to the wakeup relationship topology structure, where the wakeup depth is the maximum depth that can be reached along the wakeup relationship chain of the wakeup relationship topology structure starting from the first thread; Determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: The importance of the first thread is determined according to the number of wake-up times, the wake-up depth, and the thread identifier of the first thread, wherein the wake-up depth of the first thread is positively correlated with the importance of the first thread.
[0018] Therefore, the importance of the first thread can also be determined in combination with the wake-up depth of the first thread, so that the importance of the first thread in the system operation process can be more comprehensively judged, making the system's judgment on the importance of the first thread more accurate, improving the accuracy of thread management, and further improving the user experience.
[0019] In combination with the first aspect, in some possible embodiments of the present application, when the importance of the first thread is too low, performing a thread control operation on the first thread specifically includes: When the importance of the first thread is lower than a preset importance threshold and higher than or equal to the first importance threshold, or when the importance of the first thread is ranked after a preset ranking position of the importance rankings of all threads in the current running process of the system and before the first preset ranking position, a freezing operation is performed on the first thread; When the importance of the first thread is lower than the first importance threshold, or when the importance ranking of the first thread is located after the first preset ranking position of the importance ranking of all threads in the current running process of the system, a termination operation is performed on the first thread, the first importance threshold is lower than the preset importance threshold, and the first preset ranking position is located after the preset ranking position.
[0020] Therefore, different control operations can be performed on the first thread according to different importance levels, and the impact of thread control on the operating experience can be further reduced under the premise of optimizing the system load.
[0021] In a second aspect, the present application provides an electronic device, the electronic device comprising a memory and one or more processors; the memory is coupled to the processor; computer program code is stored in the memory, the computer program code comprises computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the method of the first aspect.
[0022] In a third aspect, the present application provides a computer-readable storage medium, comprising computer instructions, which, when executed on an electronic device, causes the electronic device to execute the method of the first aspect.
[0023] In a fourth aspect, the present application provides a computer program product, comprising instructions, which implement the method of the first aspect when the instructions are executed by a processor.
[0024] In a fifth aspect, the present application provides a chip, comprising a processor and a memory, wherein the memory is used to store computer programs or computer instructions, and the processor is used to execute the computer programs or computer instructions stored in the memory, so that the chip executes the method of the first aspect.
[0025] The solutions provided in the second to fifth aspects are used to implement or cooperate with the corresponding methods provided in the first aspect, and therefore can achieve the same or corresponding beneficial effects as the corresponding methods in the first aspect, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application; Figure 2 It is a schematic diagram of the software structure of an electronic device provided in an embodiment of the present application; Figure 3 A schematic diagram of the time slices of each core of the CPU when the system load of the electronic device is too high according to an embodiment of the present application; Figure 4 A logical architecture diagram of multi-threaded control exemplified in an embodiment of the present application; Figure 5 A schematic diagram of a wake-up relationship topology structure exemplified in an embodiment of the present application; Figure 6 A schematic diagram of recording the number of wake-up times and identifying key threads during system operation of an electronic device provided by an embodiment of the present application; Figure 7 A schematic diagram of a process for performing thread control in a high-load scenario of a system of an electronic device provided in an embodiment of the present application; Figure 8 A schematic diagram of a traversal process in a high-load scenario of a system of an electronic device provided in an embodiment of the present application; Fig. 9 Schematic diagram of the process of a multi-thread control method in one embodiment of the present application. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in the text is only a description of the association relationship of the associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0028] It should be understood that the terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units that are not listed, or may optionally include other steps or units that are inherent to these processes, methods, products or devices.
[0029] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0030] In the embodiments of the present application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.
[0031] The resources of the central processing unit (CPU) of electronic devices are limited. If there are many tasks running on the CPU at the same time, it is easy to cause high CPU load. There are many problems caused by high CPU load, such as slow startup response, animation lag, ANR (application unresponsiveness), etc. Monitoring the high CPU load and controlling non-critical background processes can optimize the CPU load in high-load scenarios. However, the current high-load scenario control is often carried out for specific threads, and sometimes the control leads to a poor operating experience.
[0032] To this end, the present application provides a multi-threaded management and control method and related equipment, which can manage different threads according to different high-load scenarios, and can reduce the system load in a timely manner without affecting the operating experience.
[0033] The electronic device in the embodiments of the present application may be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA) or a dedicated camera (such as a SLR camera, a card camera), etc. The embodiments of the present application do not impose any restrictions on the specific type of the electronic device.
[0034] First, the structure of an electronic device 100 provided in an embodiment of the present application is introduced.
[0035] For example, see Figure 1 , Figure 1 It is a schematic diagram of the structure of the electronic device 100 provided in an embodiment of the present application.
[0036] The following is a detailed description of the embodiment using the electronic device 100 as an example. It should be understood that the electronic device 100 may have more than Figure 1 More or fewer components may be shown, two or more components may be combined, or there may be a different configuration of components. Figure 1 The various components shown in the EMBODIMENTS 2000 may be implemented in hardware, software, or a combination of hardware and software, including one or more signal processing and / or application specific integrated circuits.
[0037] The electronic device 100 may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a camera 193, a display screen 194, etc. The sensor module 180 may include a pressure sensor 180A, a touch sensor 180B, etc.
[0038] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0039] Among them, the application processor (AP) usually serves as the main processor (CPU), responsible for running the operating system, coordinating task scheduling, processing user applications and other core functions. It is the "brain" of the system.
[0040] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0041] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0042] The charging management module 140 is used to receive charging input from a charger, where the charger can be a wireless charger or a wired charger.
[0043] The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 to power the processor 110, the internal memory 121, the external memory, the display screen 194, the camera 193, etc.
[0044] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0045] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light emitting diode or an active-matrix organic light emitting diode (AMOLED), a flexible light-emitting diode (FLED), MiniLED, MicroLED, Micro-OLED, quantum dot light-emitting diodes (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0046] The camera 193 is used to capture still images or videos. The electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0047] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0048] The video codec is used to compress or decompress digital video. The electronic device 100 may support one or more video codecs. In this way, the electronic device 100 may play or record videos in multiple coding formats.
[0049] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of the electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.
[0050] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function, such as storing music, video and other files in the external memory card.
[0051] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The processor 110 executes various functional applications and data processing of the electronic device 100 by running the instructions stored in the internal memory 121. The internal memory 121 may include a program storage area and a data storage area. The program storage area may store an operating system, applications required for at least one function (such as face recognition function, fingerprint recognition function, mobile payment function, etc.), etc. The data storage area may store data created during the use of the electronic device 100 (such as face information template data, fingerprint information template, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0052] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0053] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0054] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The electronic device 100 can listen to music or listen to a hands-free call through the speaker 170A.
[0055] The receiver 170B, also called a "earpiece", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the human ear.
[0056] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals.
[0057] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. A capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure based on the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the intensity of the touch operation based on the pressure sensor 180A. The electronic device 100 can also calculate the position of the touch based on the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions.
[0058] The touch sensor 180B is also called a "touch panel". The touch sensor 180B can be arranged on the display screen 194, and the touch sensor 180B and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180B is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180B can also be arranged on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0059] For example, see Figure 2 , Figure 2 It is a schematic diagram of the software structure of an electronic device 100 provided in an embodiment of the present application.
[0060] like Figure 2 As shown, the layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the software structure of the electronic device can be divided into two layers: an application layer and an operating system layer, wherein the operating system layer can be an Android operating system.
[0061] The application layer may include a series of application packages, which may include camera, calendar, map, communication, music, short message, gallery, call, navigation, game, video, etc.
[0062] The operating system layers from top to bottom are the application framework layer, core library layer and kernel layer.
[0063] The application framework layer provides an application programming interface (API) and a programming framework for applications in the application layer. The application framework layer includes some predefined functions. The application framework layer can include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, etc.
[0064] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0065] Content providers are used to store and retrieve data and make it accessible to applications. The data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0066] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0067] The phone manager is used to provide communication functions for electronic devices, such as the management of call status (including answering, hanging up, etc.).
[0068] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0069] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0070] The core library layer consists of two parts: one part is the function that the programming language (for example, Java language) needs to call, and the other part is the core library of the system.
[0071] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the programming files of the application layer and the application framework layer (for example, java files) as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0072] The core library layer can include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.
[0073] The surface manager is used to manage the display subsystem and provides the fusion of two-dimensional (2D) and three-dimensional (3D) layers for multiple applications.
[0074] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0075] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0076] A 2D graphics engine is a drawing engine for 2D drawings.
[0077] The kernel layer is a layer between hardware and software. The kernel layer includes at least a display driver, a camera driver, an audio driver, a sensor driver, and a virtual card driver. The multithreaded control method provided in the embodiment of the present application can be implemented as a software module in the kernel layer of the software structure.
[0078] It should be noted that the various functional modules included in the above software structure are only exemplary and do not constitute a specific limitation on the software architecture of the mobile phone of the present application. In other embodiments, the various functional modules included in the above software structure may be more or less, and the present application does not limit this. Although the embodiments of the present application are described using the Android system as an example, the basic principles are also applicable to electronic devices based on operating systems such as iOS or Windows.
[0079] The following describes the working principle of the multi-threaded control method applied to the electronic device 100 in an embodiment of the present application.
[0080] In order to meet the various functional requirements of the electronic device 100, the existing operating system kernel development of the electronic device 100 basically adopts multi-threaded development technology. Multi-threading is to apply the concurrent execution mechanism principle in the operating system to a program, divide a program into several subtasks, and execute multiple subtasks concurrently, and each task is a thread.
[0081] Threads need to schedule resources when executing tasks, that is, to obtain the right to use the CPU. In the scenario of multi-threaded execution, the CPU resources of each thread can be scheduled according to the time-sharing scheduling mechanism. For example, all threads use the CPU in turn, and the time each thread occupies the CPU (CPU resources) is evenly distributed. Alternatively, in the scenario of multi-threaded execution, the CPU resources of each thread can be allocated according to the priority of each thread. For example, the thread with a high priority is given priority to use the CPU. If the threads have the same priority, a thread will be randomly selected to use the CPU first and get priority to occupy the CPU time (CPU resources).
[0082] Multithreading can improve program running efficiency and make CPU usage more efficient. However, for one CPU core, only one thread can be executed at a time. Although with the development of technology, single-core processors have evolved into multi-core processors, the resources that multi-core CPUs can provide are also limited. In the process of executing tasks, some threads in multithreading may be blocked due to waiting for CPU resources.
[0083] For example, in a scenario where CPU resources are allocated to each thread based on priority, thread A with a low priority executes task 1 first, and thread B with a high priority executes task 2 later. In the actual task execution process, thread B with a high priority may preempt the CPU resources of thread A with a low priority. Thread B preempts the CPU resources and executes task 2 first, forcing thread A to suspend the execution of task 1 and wait to obtain CPU resources again before continuing to execute task 1.
[0084] With the development of multi-threading technology, mechanisms such as mutex locks and conditional variables have emerged to solve various problems such as thread blocking and thread synchronization in multi-threading scenarios.
[0085] Among them, the mutex lock implements a simple form of "mutual exclusion" synchronization, which is a common thread synchronization mechanism used to protect mutual exclusive access to shared resources in a multi-threaded environment. The mutex lock allows only one thread to access shared resources (for example, CPU resources) at the same time, and other threads need to wait. For example, thread A can lock other threads with a mutex lock, so that other threads with the mutex lock are waiting to be unlocked. Only thread A can use CPU resources at the same time. After executing the task, thread A can release the mutex lock, and other threads can enter the queue waiting to obtain CPU resources after releasing the mutex lock.
[0086] Condition variables are a multi-threaded synchronization mechanism used for communication and coordination between multiple threads. Condition variables allow one or more threads to wait for a certain condition to be met before continuing to execute, thereby avoiding busy waiting of threads. The principle of condition variables is based on the waiting queue mechanism. When a thread executes to call the waiting function, it will add itself to the waiting queue of the condition variable. When the condition is met, the wake-up function will select one or more threads from the waiting queue and wake them up. For example, when thread A waits for the condition variable to be awakened, thread A needs to suspend the task in a waiting state, that is, thread A can add itself to the waiting queue of the condition variable. When other threads wake up the condition variable by executing other tasks, other threads can send a wake-up broadcast to all threads in the waiting queue of the condition variable. Thread A receives the wake-up broadcast and continues to execute its corresponding tasks.
[0087] The execution states of a thread include the new state, ready state, running state, blocked state, and dead state.
[0088] The new state means that when a thread is created with new, the thread has not started running yet. At this time, the thread is in the new state. A thread in the new state has not started running yet.
[0089] A newly created thread does not run automatically. To execute the thread, you need to manually call the thread start() method. When the start() method returns, the thread is in the ready state, waiting to be scheduled by the processor.
[0090] When the thread obtains the CPU time (obtains CPU resources), it enters the running state and actually executes the contents of the run() method.
[0091] During the running process of a thread, it may enter a blocked state for various reasons: for example, a thread calls sleep() to enter a dormant state (also a blocked state). Or, a thread calls an operation that is blocked on input / output (I / O), and is in a blocked state before the I / O operation is completed. Or, a thread is blocked while waiting for a lock to be released. Or, a thread is blocked while waiting for other triggering conditions, for example, a thread is blocked while waiting for a condition variable to be awakened. The blocked state means that the running thread has not finished running, but has temporarily given up the CPU resources and is waiting to obtain the CPU resources next time.
[0092] There are two reasons that can cause a thread to die: the run() method ends normally; an uncaught exception terminates the run() method and causes the thread to die suddenly.
[0093] In some scenarios, threads will enter a blocked state due to a mutex lock. For example, after thread A is locked with a mutex, it enters a blocked state from a running state. If thread B with a mutex lock is preempted by other threads for CPU resources, thread B's CPU resources will be occupied and unable to execute the corresponding task, resulting in the mutex lock not being released in time, and thread A with a mutex lock will remain in a blocked state. The aforementioned lock identification can identify potential deadlock situations.
[0094] In some scenarios, threads will enter a blocked state while waiting for a condition variable. For example, when thread A is blocked because a condition is not met, or it is actively blocked, or it is waiting for a condition variable to be awakened, thread A enters a blocked state from a running state. Thread B, which awakens the condition variable, may be preempted by other threads for CPU resources, resulting in the CPU resources of thread B being occupied and unable to execute the corresponding task to awaken the condition variable. Thread A, which is waiting for the condition variable to be awakened, will also remain in a blocked state.
[0095] It should be noted that if Figure 2 Each application in the application layer shown can run in the foreground or be switched to the background. Each application can include multiple threads to perform different tasks. For example, the communication application includes the main thread, network thread, file read and write thread, database thread, audio and video thread, picture loading thread, push thread, log thread and scheduled task thread, etc. The navigation application includes the main thread, map rendering thread, positioning thread, navigation thread, network request thread, file read and write thread, sensor event thread, log and monitoring thread, scheduled task thread, voice broadcast thread, offline map processing thread and animation thread, etc. The game application includes the main thread, rendering thread, physics engine thread, network thread, audio thread, resource loading thread, AI thread, file I / O thread, etc. Moreover, the threads of different applications are managed separately, for example, the main thread of the communication application, the main thread of the navigation application and the main thread of the game application are three independent and separately managed threads.
[0096] Moreover, threads have different priorities. When an application is running in the foreground, the application's threads have the highest priority, and the system usually allocates more CPU and memory resources to them. When an application switches from the foreground to the background, at least some of the application's threads will be suspended. Suspension means temporarily calling the thread out of the CPU but retaining the context. Suspension is a special blocking state where the thread is forced to suspend execution until it is explicitly resumed. Other threads can continue to run on the CPU, but their priority will be reduced. For example, Figure 2When the communication application shown in the figure switches from the foreground to the background, the threads that continue to work (still running on the CPU) may include network threads, push threads, audio and video processing threads (if a call is in progress), log and monitoring threads (in some cases), scheduled task threads, etc. The suspended threads may include the main thread (UI thread), image loading and rendering threads, file reading and writing threads, database operation threads, etc. Therefore, the previous call can still be continued when the communication application is running in the background. For another example, Figure 2 The threads that continue to work when the navigation application switches from the foreground to the background may include: positioning thread (if background positioning is allowed), navigation thread (if navigation is in progress), log and monitoring thread (in some cases), scheduled task thread (limited), etc. The suspended threads may include the main thread (UI thread), map rendering thread, animation thread, sensor event thread, etc. Therefore, the navigation voice can be played normally and the location information can be obtained normally. For another example, Figure 2 In the music application, if it is switched to background operation during music playing, some threads are still allocated time slices and run on the CPU, so the music can be played normally.
[0097] In addition, during the system operation on the electronic device 100, the priority of the application's thread will change during the process of switching from foreground operation to background operation. For example, when the navigation application is running in the foreground, the priority of the thread is roughly as follows from high to low: main thread (UI thread) (highest priority), map rendering thread (high priority), positioning thread (high priority), navigation thread (high priority), network request thread (medium priority), file read and write thread (medium priority), sensor event thread (medium priority), animation thread (medium priority), log and monitoring thread (low priority), timed task thread (low priority). When the navigation application switches from foreground operation to background operation, the thread priorities are: positioning thread (medium to high priority), navigation thread (medium to high priority), network request thread (low to medium priority), log and monitoring thread (low priority), timed task thread (low priority), suspended thread: main thread (UI thread), map rendering thread, animation thread, sensor event thread. When the game application is running in the foreground, the main thread, rendering thread, and physics engine thread maintain high priority, the network thread and audio thread maintain medium priority, and the resource loading thread, AI thread, and file I / O thread maintain low priority. When a game application switches from foreground to background, the priority of the main thread, rendering thread, and physics engine thread is reduced; the priority of the network thread and audio thread is further reduced or paused; the resource loading thread, AI thread, and file I / O thread may be suspended or terminated.
[0098] Generally, only one application program of the electronic device 100 is running in the foreground, and other applications will be switched to the background. The user interface of the application program running in the foreground usually occupies the entire screen or part of the screen (in split-screen mode). However, in split-screen mode, picture-in-picture mode or floating window mode, the electronic device 100 can run two or more applications in the foreground at the same time. Moreover, in the prior art, when there is no user manually closing the application program, there will be many applications running in the background of the electronic device 100, and most of the threads of these applications are in a suspended state, thus occupying the memory resources of the system. In addition, some other threads of these applications may still occupy CPU resources, increasing the system load. Therefore, there is an urgent need for a multi-threaded control method to optimize the control strategy for threads in a running state and / or a blocked state during the operation of the system. Especially in some high-load scenarios, such as high-performance games, video recording and editing, multitasking, AR / VR applications, AI computing and machine learning, 5G networks and high-speed downloads, high-resolution screens and high refresh rates, long-term navigation and positioning, large file transfers and backups, etc., the CPU resources required are relatively high and the data processing volume is large. It is particularly necessary to optimize the thread management strategy so that the system load can be reduced more quickly to enhance the user experience, reduce the heat generation of the electronic device 100, and improve the battery life of the electronic device 100.
[0099] Please refer to Figure 3 , Figure 3 This is a schematic diagram of the time slices of each core of the CPU when the system load of the electronic device 100 is too high according to an embodiment of the present application. Figure 3 It can be seen that the CPU of the electronic device 100 of the embodiment of the present application is an 8-core processor (CPU0-CPU8), each core corresponds to a time bar from left to right, and the time bar is divided into multiple time segments, each time segment is the running time of the corresponding thread on the core, and different segments are the running time of different threads on the core, or the running time of the same thread when it is awakened at different times. It can be understood that in other embodiments, the CPU can have more cores or fewer cores, which is only an example and not limited here. Figure 3 It can be seen that the CPU of the electronic device 100 in the embodiment of the present application is running at full load, and the processing pressure of the CPU is very high. It is urgent to control some threads during the operation of the system to reduce the load.
[0100] Please refer to Figure 4 , Figure 4The logical architecture diagram of multi-thread control exemplified in the embodiment of the present application. Specifically, the multi-thread control includes a wake-up relationship recording module, a thread identification module, a wake-up relationship topology analysis module, a thread identification module, an importance determination module and a thread scheduling module. Among them, the wake-up relationship recording module is used to record the wake-up relationship between threads during the operation of the system, and the wake-up relationship is used to represent the relationship between awakening and being awakened between threads, and generate a wake-up relationship topology structure according to the wake-up relationship; the thread identification module is used to identify the key threads and / or non-key threads during the operation of the system; the wake-up relationship topology analysis module is used to obtain the number of wake-up times, wake-up depth, etc. of the thread according to the wake-up relationship topology structure; the thread identification module is used to identify the thread identification of the thread; the importance determination module is used to determine the importance of the thread according to at least one of the wake-up relationship and the wake-up depth and the thread identification; wherein the wake-up relationship and the wake-up depth are respectively positively correlated with the importance of the thread, and the thread identification is used to identify whether the thread is a key thread, and the importance of the key thread is higher than that of the non-key thread. The thread scheduling module is used to perform control operations on the thread when the importance of the thread is too low, and the control operation is used to reduce the CPU occupancy of the thread. Specifically as follows: Wake-up relationship recording module During the operation of the system, there is a wake-up relationship between threads. The wake-up relationship is used to indicate the relationship between waking up and being awakened between threads. The wake-up relationship recording module is used to record the wake-up relationship between threads during the operation of the system. It can be understood that the wake-up relationship recording module is used to obtain and record the wake-up relationship between threads through operating system tools (such as / proc, perf, performance monitor), tools provided by programming languages (such as ThreadMXBean) or debugging tools (such as GDB, Valgrind), etc. when the current thread is awakened by other threads through a wake-up function and / or the current thread wakes up other threads through a wake-up function. The wake-up relationship includes the wake-up count wake_count and the wake-up direction. For the convenience of description, the multi-threaded control strategy is explained below using the first thread as an example, wherein the first thread is one of the multiple threads during the operation of the system. The wake-up count wake_count of the first thread is the sum of the number of times the first thread is awakened by other threads and the number of times the first thread wakes up other threads. The wake-up times wake_count of the first thread is generally recorded in the list in wake_node. When the first thread is awakened, the wake-up times wake_count of the first thread increases by 1, and the wake_count of the first thread in the list will be updated to the value of wake_count plus 1. The wake-up direction is used to indicate the wake-up direction between threads. For example, if thread A wakes up thread B, then the wake-up direction is A→B.
[0101] Please refer to Figure 5The wake-up relationship recording module also generates a wake-up relationship topology structure based on the recorded wake-up relationship. Figure 5 It can be seen that the wake-up relationship topology is a mesh, where each ellipse is a node, each node represents a thread, and the English logo (A, B...G, etc.) in each ellipse is the name logo of the thread. Figure 5 The English symbols in each oval in are only examples and are not limited. When there is a line between two nodes, it means that there is a wake-up relationship between the threads on the two nodes. For example, there is a line between thread A and thread B, which means that there is a wake-up relationship between thread A and thread B. The arrow of the line indicates the wake-up direction between the two threads. For example, if the arrow points from thread A to thread B, it means that thread A wakes up thread B. If there are multiple lines between thread A and thread B and the arrows of the lines are all pointing to thread B, it means that thread A wakes up thread B multiple times. In addition, some nodes' threads will only wake up threads of other nodes, such as thread A, and some nodes' threads will only be awakened by threads of other nodes, such as thread D and thread G. During the operation of the system, since there are always threads being awakened, the awakened threads need to update the corresponding nodes and / or wake-up relationships in the wake-up relationship topology structure. Some threads may enter a dead state because the related applications are closed or have been executed. The nodes of the dead threads need to be deleted from the wake-up relationship topology structure. Therefore, the wake-up relationship during the operation of the system changes dynamically, and the wake-up relationship topology structure also changes dynamically.
[0102] Wake-up relationship topology analysis module Taking the first thread as an example, the number of wake-up times and the wake-up depth of the first thread can be obtained from the wake-up relationship topology. The definition of the number of wake-up times of the first thread is as above. The wake-up depth of the first thread refers to the maximum depth that can be reached along the wake-up relationship chain starting from the first thread. The wake-up depth reflects the complexity of the dependency relationship and execution order between threads. For example, when thread (A) wakes up another thread (B), there is a wake-up relationship between thread (A) and thread (B). For another example, when thread (A) wakes up another thread (B), and thread (B) wakes up another thread (C), the wake-up depth of thread (A) is 1, the wake-up depth of thread (B) is 2, and the wake-up depth of thread (C) is 3.
[0103] It should be noted that during the operation of the system, the system load is monitored in real time. When the system load is monitored to exceed the preset load threshold, traversal is triggered. During the traversal, when traversing to the first thread, the number of wake-up times and / or wake-up depth of the first thread is obtained according to the wake-up relationship topological structure and provided to the importance determination module for importance calculation.
[0104] It should be noted that the wake-up relationship topology structure may include but is not limited to a root node, and the traversal generally starts from the root node of the wake-up relationship topology structure.
[0105] Thread Identification Module Different threads in the system operation process have different effects on the user's operating experience. For threads that have a greater impact on the user's operating experience during the system operation, we can call them key threads, and for threads that have a smaller impact or no impact on the user's operating experience during the system operation, we can call them ordinary threads or non-key threads. Therefore, during the system operation, key threads and / or non-key threads are identified, so that at least the key thread has a thread identification, or at least the non-key thread has a thread identification, or the key thread and the non-key thread have different thread identifications, so that the system can distinguish between key threads and non-key threads based on the thread identification.
[0106] Taking the first thread as an example, when the first thread is awakened, it is also identified whether the first thread is a critical thread. When the first thread is identified as a critical thread, the thread identifier of the first thread is set to a first value, and the first value is used to indicate that the first thread is a critical thread; When the first thread is identified as a non-critical thread, the thread identifier is set to a second value, the second value is used to indicate that the first thread is a non-critical thread, wherein the first value is different from the second value.
[0107] In this way, whether the first thread is a critical thread or a non-critical thread can be distinguished through the first value and the second value of the thread identifier.
[0108] The identification of whether the first thread is a key thread can be implemented in the form of a key thread identification table, which lists the categories of all key threads or the identification list of specific key threads. In this way, when the first thread is identified, it can be identified whether the first thread is a key thread by comparing it with the key thread identification table.
[0109] The key thread identification table includes the related identifiers of the foreground thread, the background running thread, the graphics drawing thread, the resource management thread, and the system service management thread. The identifier can be a name identifier, a symbol identifier, or other identifiers, which are not limited here.
[0110] Among them, the foreground thread is used to run in the system foreground; specifically, the foreground thread refers to the thread of the application that the user is currently interacting with. Under normal circumstances, the user is interacting with one application, but in split-screen mode, picture-in-picture mode, or floating window mode, there may be two or more applications. The background running thread is used to run in the system background to provide related services; specifically, the background running thread is a thread that is still allocated CPU time slices to perform some tasks visible to the user when it is switched to background operation, so it still maintains the foreground attribute. For example, Figure 2 When the music application shown plays a song, if the music application is switched to the background, the electronic device 100 will continue to play music. The background running threads of the music application may include the main thread (used to control the service life cycle), the working thread (processing actual tasks, such as audio decoding), the network thread (if data needs to be downloaded), the daemon thread, etc. The background running threads may be music playing applications (if music needs to be played in the background), navigation applications (if location information needs to be continuously updated in the background), download applications (need to download files or data in the background), instant messaging applications (need to receive messages in the background), health monitoring applications: (if sensor data needs to be continuously monitored in the background) threads running in the background and other threads that provide real-time acquisition of sensor data. The graphics drawing thread is used to convert the graphics data (such as text, images, animations, etc.) of the application or desktop into pixels displayed on the screen. Specifically, the graphics drawing thread includes the main thread, rendering thread, animation thread, synthesis thread, etc. Resource management threads are responsible for managing the allocation, release and optimization of system resources (such as CPU, memory, I / O devices, etc.) in the operating system. Specifically, resource management threads include monitoring threads (collecting data), scheduling threads (allocating resources), garbage collection threads (such as Java's GC) and daemon threads (background cleanup), etc. System service management threads are used to control and manage background services, system processes and applications in the operating system, including Binder threads, main threads, network request threads, file read and write threads, scheduled task threads, log and monitoring threads, device management threads, security service threads, etc.
[0111] When identifying whether the first thread is a critical thread, it can be determined whether the first thread belongs to the major categories of threads such as foreground threads, background running threads, graphics drawing threads, resource management threads, and system service management threads. If so, the first thread is determined to be a critical thread. For example, when the first thread is a thread of a foreground application, when the first thread is awakened, the first thread is compared with the critical thread identification table, and it is found that the first thread belongs to the foreground thread, then the first thread is determined to be a critical thread. When the first thread is switched to run in the background, the first thread is compared with the critical thread identification table again, and it is found that the first thread does not belong to the foreground thread, nor does it belong to the background running thread, graphics drawing thread, resource management thread, or system service management thread. Therefore, the first thread is determined to be an ordinary thread. For another example, when the first thread is identified as a background running thread, the first thread is determined to be a critical thread.
[0112] Thus, in some embodiments, the first thread can be a critical thread and a common thread when running in the foreground and the background, respectively. Therefore, as the first thread switches between the foreground and the background, the first thread can switch between the critical thread and the common thread. The thread identifier of the first thread also needs to be updated accordingly during the process of switching the first thread between the foreground and the background.
[0113] It is understandable that, in some embodiments, different thread identifiers for identifying key threads may be added to key threads of different categories according to the different influences of different key threads on the system operation process.
[0114] Please refer to Figure 6 , Figure 6 A schematic diagram of recording the number of wake-up times and identifying key threads during system operation of an electronic device provided in an embodiment of the present application.
[0115] Among them, when the first thread is awakened by the wake-up function, the wake-up count wake_count of the first thread is updated to the value of wake_count plus 1, and the first thread is identified as a critical thread through the critical thread identification table. When the first thread is identified as a critical thread, the critical thread is marked, that is, the thread identifier of the first thread is assigned a first value. For example, the Task_struct of the first thread is set and marked as critical. On the contrary, when the first thread is identified as a non-critical thread through the critical thread identification table, no mark is made, that is, the thread identifier of the first thread is assigned a second value, for example, the Task_struct of the first thread is set and marked as null. It can be understood that there can be many kinds of thread identifiers (marks), which are not limited here.
[0116] Thread Identification Module Generally, the system load is monitored in real time during system operation. When the system load is monitored to exceed the preset load threshold, traversal is triggered. During the traversal, when traversing to the first thread, the thread identification module obtains the Task_struct mark of the first thread, and can identify whether the first thread is a critical thread based on the mark.
[0117] Importance determination module The importance determination module comprehensively determines the importance of the traversed first thread according to at least one of the wakeup times and the wakeup depth of the first thread obtained by the wakeup relationship topology analysis module and the thread identifier obtained by the thread identification module.
[0118] Among them, the wake-up relationship of the first thread is positively correlated with the importance of the first thread; Among them, the awakening depth of the first thread is positively correlated with the importance of the first thread; The thread identifier is used to identify whether the first thread is a critical thread, and the importance of a critical thread is higher than that of a non-critical thread.
[0119] Therefore, the importance of the first thread can be comprehensively determined by combining at least one of the wakeup times and the wakeup depth of the first thread and the thread identifier.
[0120] It is understandable that there are many ways to comprehensively determine the importance of the first thread by combining at least one of the wakeup times and the wakeup depth of the first thread and the thread identifier, such as weighted average, multiplication, addition, division, subtraction, etc., which are not limited here.
[0121] In some embodiments, the importance of the first thread is comprehensively determined by combining the number of wake-up times of the first thread and the thread identifier.
[0122] For example, the number of wake-up times of the first thread is 20, and the thread identifier is critical, then the importance of the first thread is determined to be 70.
[0123] In some other embodiments, the importance of the first thread is comprehensively determined by combining the number of wake-up times, the wake-up depth, and the thread identifier of the first thread.
[0124] For example, if the number of wake-up times of the first thread is 5, the wake-up depth is 3, and the thread identifier is critical, the importance of the first thread is determined to be 85. It can be understood that the above values are only for illustration.
[0125] Therefore, although the first thread has a low wake-up frequency, it can still obtain a higher importance when the wake-up depth is relatively deep, which can reduce the impact on system operation when the CPU usage of the first thread with a relatively deep wake-up depth is limited.
[0126] It can be understood that in other embodiments, when the first thread is determined to be a non-critical thread based on the thread identifier of the first thread, the importance of the first thread is determined in combination with the number of wake-up times and the priority of the first thread, wherein the priority of the first thread is positively correlated with the importance of the first thread.
[0127] In this way, when the first thread is determined to be a non-critical thread based on the thread identifier of the first thread, the importance of the first thread can also be calculated in combination with the priority of the first thread. This can more comprehensively judge the importance of the first thread in the system operation process, making the system's judgment on the importance of the first thread more accurate, improving the accuracy of thread management and control, and further improving the user experience.
[0128] It can be understood that in other embodiments, when the first thread is determined to be a critical thread based on the thread identifier of the first thread, the importance of the first thread is determined in combination with the number of wake-up times and the priority of the first thread, wherein the priority of the first thread is positively correlated with the importance of the first thread.
[0129] In this way, when the first thread is determined as a key thread according to its thread identifier, the importance of the first thread can be determined in combination with the priority, so that more CPU resources can be allocated to key threads with higher importance to improve operation efficiency.
[0130] Thread scheduling module The thread scheduling module performs a thread control operation on the traversed first thread when the importance of the first thread is too low, and the control operation is used to reduce the utilization rate of the CPU resources by the first thread.
[0131] Therefore, a management and control operation of reducing the utilization rate of CPU resources can be performed on the first thread with low importance during system operation, so as to release CPU and memory resources in time, reduce system load, and improve user experience.
[0132] Here, reducing the utilization rate of the CPU resources by the first thread may be removing the first thread from the CPU or reducing the utilization rate of the CPU resources by the first thread although the first thread is still running on the CPU.
[0133] In some embodiments, the importance of the first thread is too low when the importance of the first thread is lower than a preset importance threshold or the importance of the first thread is ranked after a preset ranking position of the importance of all threads in the current running process of the system, wherein the importance ranking is ranked from high importance to low importance.
[0134] In other embodiments, when the importance of the first thread is lower than a preset importance threshold and higher than or equal to the first importance threshold, a freeze operation is performed on the first thread; when the importance of the first thread is lower than the first importance threshold, a termination operation is performed on the first thread, and the first importance threshold is lower than the preset importance threshold.
[0135] The termination operation performed on the first thread refers to calling the first thread out of the CPU and deleting the context, and the freezing operation performed on the first thread refers to calling the first thread out of the CPU but retaining the context.
[0136] Therefore, when the importance of the first thread is too low, different control strategies can be selected to control the first thread according to the importance of the first thread.
[0137] For example, thread A is a foreground thread with 2 wake-up times, thread B is a background running thread with 8 wake-up times, and thread C is a background suspended thread with 15 wake-up times. Thread D is a normal thread with 5 wake-up times. According to the thread ID and the wake-up times, the importance of thread A is 52, the importance of thread B is 58, the importance of thread C is 15, and the importance of thread D is 5. The preset importance threshold is 50. Therefore, when a high load is monitored, thread A, thread B, thread C, and thread D are traversed in sequence. Since the importance of thread A and thread B are both higher than 50, their CPU resource utilization will not be reduced. Thread C and thread D will have their CPU resource utilization reduced in sequence, that is, thread C and thread D will be frozen or terminated.
[0138] In some other embodiments, when the importance ranking of the first thread is after a preset ranking position of the importance ranking of all threads in the current running process of the system and before the first preset ranking position, a freeze operation is performed on the first thread; or, when the importance ranking of the first thread is after the first preset ranking position of the importance ranking of all threads in the current running process of the system, a termination operation is performed on the first thread.
[0139] Still using the previous example, for example, thread A is a foreground thread, and the number of wake-ups is 2 times, thread B is a background running thread, and the number of wake-ups is 8 times, and thread C is a background suspended thread, and the number of wake-ups is 15 times. Thread D is a normal thread, and the number of wake-ups is 5 times. According to the thread identifier and the number of wake-ups, the importance of thread A is determined to be 52, the importance of thread B is 58, the importance of thread C is 15, and the importance of thread D is 5. The preset sorting position is the second to last position. Therefore, according to the importance sorting, the thread after the second to last position is determined to be thread D. Therefore, the utilization rate of CPU resources by thread D is reduced.
[0140] In other embodiments, while performing control operations to reduce the utilization rate of CPU resources on a first thread with a low importance level, the corresponding CPU resources of a first thread with a higher importance level can also be adjusted according to the importance level. For example, the first thread with the highest importance obtains the most CPU resources.
[0141] For example, see Figure 7 , Figure 7 A schematic diagram of the process of thread control in a high-load scenario of the system of an electronic device provided in an embodiment of the present application. The system load is monitored, and when the system load is monitored to be higher than a preset load threshold, traversal is triggered, and when traversing to the first thread, the first thread is assigned a corresponding importance according to the thread identifier and the number of wake-up times of the first thread; when the importance of the first thread is too low, the first thread is frozen or terminated.
[0142] Please refer to Figure 8 , Figure 8 A schematic diagram of the process of traversal in a high-load scenario of the system of an electronic device provided in an embodiment of the present application.
[0143] Module 801: monitor the system load and determine whether the system load exceeds the system load threshold. If yes, execute module 802.
[0144] Module 802: traverse the root node of the wake-up relationship topology structure.
[0145] Module 803: starting from the root node, traverse all nodes on the wakeup relationship chain in sequence along the wakeup direction of the wakeup relationship chain to traverse all threads on the nodes directly or indirectly awakened by the root node.
[0146] Module 804: Starting from the root node, traverse all nodes on another wakeup relationship chain in reverse order in the wakeup direction of another wakeup relationship chain to traverse all threads that directly or indirectly wake up the root node.
[0147] Module 805: Determine whether all root nodes of the wake-up relationship topology structure have been traversed. If yes, end; otherwise, return to module 802.
[0148] For each traversed thread, its importance is determined according to at least one of the wake-up times and the wake-up depth and the thread identifier, and thread control operations are performed on threads with too low importance according to the importance. The thread control operations are used to reduce the thread's utilization of CPU resources.
[0149] Fig. 9 The specific process of a multi-threaded control method provided in an embodiment of the present application is exemplified.
[0150] like Fig. 9 As shown, the multi-threaded control method includes: Step 901: monitoring the system load during system operation; Step 902: When it is monitored that the system load exceeds a preset load threshold, traverse at least part of the threads in the system operation process; Step 903: Execute the following for the first thread traversed: At least obtain the wake-up count and thread ID of the first thread; Determine the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier, wherein the number of wake-up times of the first thread is positively correlated with the importance of the first thread, and the thread identifier is used to identify whether the first thread is a critical thread, and the importance of the critical thread is higher than that of a non-critical thread; When the importance of the first thread is too low, a thread control operation is performed on the first thread, where the control operation is used to reduce the utilization rate of the CPU resources by the first thread.
[0151] wherein the first thread belongs to at least some of the threads; Among them, the importance of the first thread is too low means that the importance of the first thread is lower than a preset importance threshold or the importance ranking of the first thread is located after the preset ranking position of the importance ranking of all threads in the current running process of the system, wherein the importance ranking is sorted in a direction from high importance to low importance.
[0152] Among them, the definition of key threads is as mentioned above and will not be repeated here.
[0153] In some embodiments, the wake-up count wake_count of the first thread is one of the number of times the first thread is awakened by other threads and the number of times the first thread wakes up other threads, or the sum thereof. The wake-up count wake_count of the first thread is generally recorded in the list in wake_node. When the first thread is awakened, the wake-up count wake_count of the first thread is increased by 1, and the wake_count of the first thread in the list is updated to the value of wake_count plus 1.
[0154] When the first thread is identified as a critical thread, the critical thread is marked, for example, Task_struct of the first thread is set to be marked as critical. On the contrary, when the first thread is identified as a non-critical thread through the critical thread identification table, no marking is performed, for example, Task_struct of the first thread is set to be marked as null. It can be understood that there can be many kinds of thread identifiers (marks), which are not limited here.
[0155] Therefore, the present application can determine the importance of the first thread based on the number of wake-up times and the thread identifier of the first thread, and perform a thread control operation on the first thread when the importance of the first thread is too low. The control operation is used to reduce the utilization rate of CPU resources by the first thread. Under different load scenarios, the first thread may be a critical thread or a non-critical thread; and, under different load scenarios, the number of wake-up times of the first thread may be different. Therefore, under different load scenarios, it can be comprehensively determined based on the number of wake-up times and the thread identifier of the first thread whether to perform a thread control operation on the first thread to reduce the utilization rate of CPU resources by the first thread. This can timely reduce the system load while ensuring the user's operating experience. Compared with the prior art, the system load can be reduced in a shorter time.
[0156] In some embodiments, when the system load is monitored to exceed a preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread management and control method further includes: When the first thread is awakened during the operation of the system, the awakening count of the first thread is updated to the value of the current awakening count plus 1; When the first thread wakes up the next thread during system operation, the wake-up count of the first thread is updated to the value of the current wake-up count plus 1.
[0157] In some embodiments, the wake-up count wake_count of the first thread is the sum of the number of times the first thread is awakened by other threads and the number of times the first thread wakes up other threads.
[0158] Thus, when the first thread is awakened, the wake-up count of the first thread is updated, and / or, when the first thread wakes up the next thread, the wake-up count of the first thread is also updated. It can be seen that the wake-up count of the first thread changes dynamically, and the importance of the first thread can be updated accordingly based on the updated wake-up count. This ensures that the importance of the first thread is updated in real time during system operation. Moreover, under different load scenarios, the wake-up count of the first thread also changes dynamically. Re-determining the importance of the first thread in combination with the updated wake-up count of the first thread can improve the accuracy of the management and control decisions on the first thread and maximize the user experience.
[0159] In some embodiments, when the system load is monitored to exceed a preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread management and control method further includes: When the first thread is identified as a key thread through the key thread identification table, the thread identifier is set to a first value, where the first value is used to indicate that the first thread is a key thread; or, When the first thread is identified as a non-critical thread through the critical thread list, the thread identifier is set to a second value, where the second value is used to indicate that the first thread is a non-critical thread.
[0160] When the first thread is identified as a critical thread, the critical thread is marked, for example, Task_struct of the first thread is set to be marked as critical. On the contrary, when the first thread is identified as a non-critical thread through the critical thread identification table, no marking is performed, for example, Task_struct of the first thread is set to be marked as null. It can be understood that there can be many kinds of thread identifiers (marks), which are not limited here.
[0161] Thus, the key thread identification table is used to identify whether the first thread is a key thread or a non-key thread, and different values are set for the thread label when the first thread is identified as a key thread or a non-key thread, respectively, so as to facilitate the rapid determination of the importance of the first thread during the traversal process, speed up the traversal speed, and increase the speed of reducing the system load, so as to quickly reduce the system load in a short time.
[0162] In some embodiments, the multi-thread management method further includes: When the first thread switches from foreground operation to background operation, when the first thread is identified as a non-critical thread according to the critical thread identification table, the thread identifier of the first thread is updated to a second value, where the second value is used to indicate that the first thread is a non-critical thread; Determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: The importance of the first thread is updated at least according to the number of wake-up times of the first thread and the updated thread identifier.
[0163] Thus, when the first thread switches from the foreground to the background, when the first thread is no longer a critical thread, the thread identifier of the first thread is updated to a second value, and the second value is used to indicate that the first thread is a non-critical thread. Moreover, at this time, the trace software will find that the thread identifier of the first thread (the thread identifier of the critical thread, for example, critical) has disappeared. At this time, when the importance of the first thread is too low and the system is highly loaded, the first thread will be terminated. And the importance of the first thread is updated accordingly, so that the importance of the first thread can be updated in real time during the operation of the system. Moreover, under different load scenarios, the thread identifier of the first thread also changes dynamically. Re-determining the importance of the first thread in combination with the updated thread identifier of the first thread can improve the accuracy of the management and control decision of the first thread and maximize the user experience.
[0164] In the prior art, when an application is switched from the foreground to the background, threads associated with the application will be suspended. Only when the user manually closes the application will the threads associated with the application disappear. Otherwise, the application will remain suspended in the background.
[0165] In comparison, in the present application, when the system is highly loaded, some non-critical threads suspended in the background will first be frozen and / or terminated, which will significantly shorten the duration of the critical thread D state (the thread is in an uninterruptible sleep state). Through trace or log flow, the duration of the critical thread D state can also be counted. It can be found that compared with the prior art, the duration of the critical thread D state in the present application is significantly reduced, which can quickly reduce the system load, increase the system running speed, and bring a better experience to users.
[0166] In some embodiments, the key thread identification table includes relevant identifiers of foreground threads, background running threads, graphics drawing threads, resource management threads, and system service management threads.
[0167] In combination with the first aspect, in some possible embodiments of the present application, the foreground thread is used to run in the system foreground; the background running thread is used to run in the system background to provide related services; the resource management thread is used to manage the allocation, release and optimization of system resources in the operating system; the system service management thread is used to control and manage background services, system processes and applications in the operating system.
[0168] Specifically, as mentioned above, the foreground thread is used to run in the system foreground; specifically, the foreground thread refers to the thread of the application that the user is currently interacting with. Normally, there is only one application that the user is interacting with, but in split-screen mode, picture-in-picture mode, or floating window mode, there may be two or more applications. The background running thread is used to run in the system background to provide related services; specifically, the background running thread is a thread that is still allocated CPU time slices to perform some tasks visible to the user when it is switched to background operation, and therefore, it still maintains the foreground attribute. For example, Figure 2When the music application shown plays a song, if the music application is switched to the background, the electronic device 100 will continue to play music. The background running threads of the music application may include the main thread (used to control the service life cycle), the working thread (processing actual tasks, such as audio decoding), the network thread (if data needs to be downloaded), the daemon thread, etc. The background running threads may be music playing applications (if music needs to be played in the background), navigation applications (if location information needs to be continuously updated in the background), download applications (need to download files or data in the background), instant messaging applications (need to receive messages in the background), health monitoring applications: (if sensor data needs to be continuously monitored in the background) threads running in the background and other threads that provide real-time acquisition of sensor data. The graphics drawing thread is used to convert the graphics data (such as text, images, animations, etc.) of the application or desktop into pixels displayed on the screen. Specifically, the graphics drawing thread includes the main thread, rendering thread, animation thread, synthesis thread, etc. Resource management threads are responsible for managing the allocation, release and optimization of system resources (such as CPU, memory, I / O devices, etc.) in the operating system. Specifically, resource management threads include monitoring threads (collecting data), scheduling threads (allocating resources), garbage collection threads (such as Java's GC) and daemon threads (background cleanup), etc. System service management threads are used to control and manage background services, system processes and applications in the operating system, including Binder threads, main threads, network request threads, file read and write threads, scheduled task threads, log and monitoring threads, device management threads, security service threads, etc.
[0169] Therefore, these major categories of threads are user-perceivable threads. These major categories of threads are set in the key thread identification table. When identifying whether the first thread is a key thread, it can be compared with the key thread identification table to quickly determine whether the first thread is a key thread, thereby improving the system operation speed, further improving the system's ability to reduce load, and further shortening the time for reducing the system load.
[0170] In some embodiments, determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: When the first thread is determined to be a non-critical thread according to its thread identifier, the importance of the first thread is determined in combination with the number of wake-up times and the priority of the first thread, wherein the priority of the first thread is positively correlated with the importance of the first thread.
[0171] Therefore, when the first thread is determined to be a non-critical thread based on the thread identifier of the first thread, the importance of the first thread can also be calculated in combination with the priority of the first thread. This can more comprehensively judge the importance of the first thread in the system operation process, making the system's judgment on the importance of the first thread more accurate, improving the accuracy of thread management and control, and further improving the user experience.
[0172] In some embodiments, when the system load is monitored to exceed a preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread management and control method further includes: The wakeup relationship between different threads is recorded during the system operation. The wakeup relationship is used to indicate the relationship between waking up and being awakened between threads. Generate a wake-up relationship topology structure according to the wake-up relationship during the system operation process; At least the wake-up times and thread ID of the first thread are obtained, including: Acquire the wakeup times and the wakeup depth of the first thread according to the wakeup relationship topology structure, where the wakeup depth is the maximum depth that can be reached along the wakeup relationship chain of the wakeup relationship topology structure starting from the first thread; Determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: The importance of the first thread is determined according to the number of wake-up times, the wake-up depth, and the thread identifier of the first thread, wherein the wake-up depth of the first thread is positively correlated with the importance of the first thread.
[0173] For example, if the number of wake-up times of the first thread is 20, the wake-up depth is 1, and the thread identifier is critical, then the importance of the first thread is determined to be 80.
[0174] For another example, if the number of wake-up times of the first thread is 5, the wake-up depth is 3, and the thread identifier is critical, the importance of the first thread is determined to be 85. It can be understood that the above values are only for illustration.
[0175] Therefore, although the first thread has a low wake-up frequency, it can still obtain a higher importance when the wake-up depth is relatively deep, which can reduce the impact on system operation when the CPU usage of the first thread with a relatively deep wake-up depth is limited.
[0176] Therefore, the importance of the first thread can also be determined in combination with the wake-up depth of the first thread, so that the importance of the first thread in the system operation process can be more comprehensively judged, making the system's judgment on the importance of the first thread more accurate, improving the accuracy of thread management, and further improving the user experience.
[0177] In some embodiments, when the importance of the first thread is too low, performing a thread control operation on the first thread specifically includes: When the importance of the first thread is lower than a preset importance threshold and higher than or equal to the first importance threshold, or when the importance of the first thread is ranked after a preset ranking position of the importance rankings of all threads in the current running process of the system and before the first preset ranking position, a freezing operation is performed on the first thread; When the importance of the first thread is lower than the first importance threshold, or when the importance ranking of the first thread is located after the first preset ranking position of the importance ranking of all threads in the current running process of the system, a termination operation is performed on the first thread, the first importance threshold is lower than the preset importance threshold, and the first preset ranking position is located after the preset ranking position.
[0178] Therefore, different control operations can be performed on the first thread according to different importance levels, and the impact of thread control on the operating experience can be further reduced under the premise of optimizing the system load.
[0179] The present application also provides an electronic device, which includes a memory and one or more processors; the memory is coupled to the processor; computer program code is stored in the memory, and the computer program code includes computer instructions. When the computer instructions are executed by the processor, the electronic device executes the above method.
[0180] The present application provides a computer-readable storage medium, including computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the above method.
[0181] The present application provides a computer program product, including instructions, which implement the above method when the instructions are executed by a processor.
[0182] The present application also provides a chip, which includes a processor and a memory, wherein the memory is used to store computer programs or computer instructions, and the processor is used to execute the computer programs or computer instructions stored in the memory, so that the chip executes the above method.
[0183] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
[0184] As used in the above embodiments, the term "when..." may be interpreted to mean "if..." or "after..." or "in response to determining..." or "in response to detecting...", depending on the context. Similarly, the phrases "upon determining..." or "if (the stated condition or event) is detected" may be interpreted to mean "if determining..." or "in response to determining..." or "upon detecting (the stated condition or event)" or "in response to detecting (the stated condition or event)", depending on the context.
[0185] An embodiment of the present application provides a chip system, including: a processor, the processor is coupled to a memory, the memory is used to store programs or instructions, and when the programs or instructions are executed by the processor, the chip system implements a method in any of the above method embodiments.
[0186] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0187] Optionally, the memory in the chip system may also be one or more. The memory may be integrated with the processor or may be separately arranged with the processor, which is not limited in the embodiments of the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be arranged on different chips respectively. The embodiments of the present application do not specifically limit the type of memory and the arrangement of the memory and the processor.
[0188] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.
[0189] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.
[0190] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may 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 may be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk), etc.
[0191] Those skilled in the art can understand that to implement all or part of the processes in the above-mentioned embodiments, the processes can be completed by computer programs to instruct related hardware, and the programs can be stored in computer-readable storage media. When the programs are executed, they can include the processes of the above-mentioned method embodiments. The aforementioned storage media include: ROM or random access memory RAM, magnetic disk or optical disk and other media that can store program codes.
Claims
1. A multi-thread management and control method, characterized in that: The multi-thread control method includes: Monitor system load during system operation; When it is monitored that the system load exceeds a preset load threshold, traverse at least part of the threads in the system operation process; Execute the following command on the first thread traversed: At least obtaining the wake-up count and thread identifier of the first thread; determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier, wherein the number of wake-up times of the first thread is positively correlated with the importance of the first thread, the thread identifier is used to identify whether the first thread is a critical thread, and the importance of the critical thread is higher than that of a non-critical thread; When the importance of the first thread is too low, performing a thread control operation on the first thread, wherein the control operation is used to reduce the utilization rate of CPU resources by the first thread; wherein, the first thread belongs to the at least part of the threads; Among them, the importance of the first thread is too low when the importance of the first thread is lower than a preset importance threshold or the importance ranking of the first thread is located after a preset ranking position of the importance rankings of all threads in the current running process of the system, wherein the importance ranking is sorted in a direction from high importance to low importance.
2. The multi-thread control method according to claim 1, characterized in that: When the system load is monitored to exceed the preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread control method further includes: When the first thread is awakened during the operation of the system, the awakening count of the first thread is updated to the value of the current awakening count plus 1; and / or, When the first thread wakes up the next thread during system operation, the wake-up count of the first thread is updated to a value of the current wake-up count plus 1.
3. The multi-thread control method according to claim 1, characterized in that: When the system load is monitored to exceed the preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread control method further includes: When the first thread is identified as a key thread through a key thread identification table, the thread identifier is set to a first value, where the first value is used to indicate that the first thread is a key thread; or, When the first thread is identified as a non-critical thread through the critical thread list, the thread identifier is set to a second value, where the second value is used to indicate that the first thread is a non-critical thread.
4. The multi-thread control method according to claim 3, characterized in that: The multi-thread control method also includes: When the first thread switches from foreground operation to background operation, when the first thread is identified as a non-critical thread according to the critical thread identification table, updating the thread identifier of the first thread to a second value, where the second value is used to indicate that the first thread is a non-critical thread; The determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: The importance of the first thread is updated at least according to the number of wake-up times of the first thread and the updated thread identifier.
5. The multi-thread control method according to claim 3 or 4, characterized in that: The key thread identification table includes at least one identifier of a foreground thread, a background running thread, a graphics drawing thread, a resource management thread, and a system service management thread.
6. The multi-thread control method according to claim 5, characterized in that: The foreground thread is used to run in the system foreground; the background running thread is used to run in the system background to provide related services; the resource management thread is used to manage the allocation, release and optimization of system resources in the operating system; the system service management thread is used to control and manage background services, system processes and applications in the operating system.
7. The multi-thread management and control method according to any one of claims 1 to 4, characterized in that: The determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: When the first thread is determined to be a non-critical thread according to the thread identifier of the first thread, the importance of the first thread is determined in combination with the number of wake-up times and the priority of the first thread, wherein the priority of the first thread is positively correlated with the importance of the first thread.
8. The multi-thread management and control method according to any one of claims 1 to 4, characterized in that: When the system load is monitored to exceed the preset load threshold, before traversing at least part of the threads in the system operation process, the multi-thread control method further includes: During the operation of the system, the wake-up relationship between different threads is recorded, and the wake-up relationship is used to represent the relationship between waking up and being awakened between threads; Generate a wake-up relationship topology structure according to the wake-up relationship during system operation; The obtaining of at least the number of wake-up times and the thread identifier of the first thread specifically includes: Acquire the wakeup times and the wakeup depth of the first thread according to the wakeup relationship topology structure, where the wakeup depth is the maximum depth that can be reached along the wakeup relationship chain of the wakeup relationship topology structure starting from the first thread; The determining the importance of the first thread at least according to the number of wake-up times of the first thread and the thread identifier specifically includes: The importance of the first thread is determined according to the number of wake-up times, the wake-up depth, and the thread identifier of the first thread, wherein the wake-up depth of the first thread is positively correlated with the importance of the first thread.
9. The multi-thread management and control method according to any one of claims 1 to 4, characterized in that: When the importance of the first thread is too low, performing a thread control operation on the first thread specifically includes: When the importance of the first thread is lower than the preset importance threshold and higher than or equal to the first importance threshold, or when the importance of the first thread is ranked after the preset ranking position of the importance rankings of all threads in the current running process of the system and before the first preset ranking position, performing a freezing operation on the first thread; When the importance of the first thread is lower than the first importance threshold, or when the importance ranking of the first thread is located after the first preset ranking position of the importance ranking of all threads in the current running process of the system, a termination operation is performed on the first thread, the first importance threshold is lower than the preset importance threshold, and the first preset ranking position is located after the preset ranking position.
10. An electronic device, characterized in that: The electronic device includes a memory and one or more processors; the memory is coupled to the processor; the memory stores computer program code, the computer program code includes computer instructions, and when the computer instructions are executed by the processor, the electronic device executes the method as described in any one of claims 1-9.
11. A computer-readable storage medium, characterized in that: The method comprises computer instructions, which, when executed on an electronic device, cause the electronic device to execute the method as claimed in any one of claims 1 to 9.
12. A computer program product, characterized in that The method comprises instructions, which, when executed by a processor, implement the method according to any one of claims 1 to 9.
13. A chip, characterized in that: The chip includes a processor and a memory, the memory is used to store computer programs or computer instructions, and the processor is used to execute the computer programs or computer instructions stored in the memory, so that the chip executes the method as claimed in any one of claims 1 to 9.
Citation Information
Patent Citations
Method and device for writing data based on common Internet file system
CN109309631A
Wake-up relationship determination method and device, electronic equipment and storage medium
CN119473405A
Methods and apparatuses for thread management of multi-threading
CN1853166A
Systems and methods for prioritizing and assigning threads in a heterogeneous processor architecture
WO2024206942A1
Resource scheduling method and apparatus, and electronic device
WO2025036044A1
Cited By
Method and device for determining threshold value of number of times of programming suspension, equipment and medium
CN120690265A