Multi-thread control method and related equipment
Through monitoring and dynamically adjusting the importance of threads, the poor operating experience caused by thread control in high-load scenarios is solved, and the rapid system load reduction in different load scenarios is achieved.
Patent Information
- Application Number
- CN202510336156.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-21
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2045-03-21
AI Technical Summary
In high load scenarios, the existing technology often controls specific threads, resulting in poor operating experience and inability to effectively reduce system load.
By monitoring the system load, traversing some threads, determining their importance according to the number of wake-up times and identification of the threads, and performing thread control operations when the importance is too low, reducing CPU resource usage, and dynamically adjusting the importance of threads to adapt to different load scenarios.
Without affecting the operating experience, the system load is timely reduced, which improves the accuracy of management and control decisions and the speed of load reduction, and adapts to the needs of different load scenarios.
Smart Images

Figure CN119861976B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of terminal technology, and in particular to a system multi-threaded control method and related equipment. Background Art
[0002] The central processing unit (CPU) of an electronic device has limited resources. If the CPU is running many tasks simultaneously, it can easily lead to high CPU load. High CPU load can cause many problems, such as slow startup response, animation lag, and ANR (application not responding) errors. Monitoring high CPU load and controlling non-critical background processes can optimize CPU load in high-load scenarios. However, current high-load scenario control often targets specific threads, which can sometimes lead to a poor user experience. Summary of the Invention
[0003] This application provides a multi-thread management method and related equipment, which can manage different threads in different high-load scenarios, and can reduce the system load in a timely manner without affecting the operating experience, so as to solve the above technical problems.
[0004] In a first aspect, the present application provides a multi-threaded control method, which includes:
[0005] Monitor system load during system operation;
[0006] When it is monitored that the system load exceeds a preset load threshold, traversing at least part of the threads in the system operation process;
[0007] Execute the following command on the first thread traversed:
[0008] Get at least the number of wake-up times and thread ID of the first thread;
[0009] determining the importance of the first thread based at least on the number of wake-up times of the first thread and a 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, wherein the importance of a critical thread is higher than that of a non-critical thread;
[0010] 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;
[0011] wherein the first thread belongs to at least some threads;
[0012] 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 operation of the system, wherein the importance ranking is sorted from high importance to low importance.
[0013] 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 the number of wake-up times of the first thread may be different under different load scenarios. 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, and can reduce the system load in a shorter time compared to the existing technology.
[0014] In conjunction 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 some threads in the system operation process, the multi-thread management method further includes:
[0015] When the first thread is awakened during system operation, the awakening count of the first thread is updated to the current awakening count plus 1; and / or,
[0016] 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.
[0017] 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 based on the updated wake-up count of the first thread can improve the accuracy of the management and control decisions for the first thread and maximize the user experience.
[0018] In conjunction 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 some threads in the system operation process, the multi-thread management method further includes:
[0019] 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
[0020] 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.
[0021] Therefore, the first thread is identified as a critical thread or a non-critical thread through the critical thread identification table, and different values are set for the thread label when the first thread is identified as a critical thread or a non-critical 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, and can quickly reduce the system load in a short time.
[0022] In combination with the first aspect, in some possible embodiments of the present application, the multi-thread management method further includes:
[0023] When the first thread switches from foreground execution to background execution, if 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;
[0024] 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:
[0025] 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.
[0026] Therefore, 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, and 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 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 decisions for the first thread and maximize the user experience.
[0027] 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.
[0028] 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.
[0029] Therefore, these major categories of threads are user-perceivable threads. These major categories of threads are set in the critical thread identification table. When identifying whether the first thread is a critical thread, it can be compared with the critical thread identification table to quickly determine whether the first thread is a critical thread, thereby improving the system operation speed, further improving the system's ability to reduce load, and further shortening the time to reduce the system load.
[0030] In conjunction with the first aspect, in some possible embodiments of the present application, determining the importance of the first thread based on at least the number of wake-up times of the first thread and the thread identifier specifically includes:
[0031] 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.
[0032] 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 further improving the user experience.
[0033] In conjunction 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 some threads in the system operation process, the multi-thread management method further includes:
[0034] During system operation, the wakeup relationship between different threads is recorded. The wakeup relationship is used to represent the relationship between waking up and being awakened between threads.
[0035] Generate a wakeup relationship topology structure according to the wakeup relationship during system operation;
[0036] At least the number of wake-up times and thread ID of the first thread are obtained, including:
[0037] Acquire the wakeup count and 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;
[0038] 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:
[0039] 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.
[0040] 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 evaluated, 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.
[0041] In conjunction 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:
[0042] 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, performing a freezing operation on the first thread;
[0043] 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.
[0044] 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 while optimizing the system load.
[0045] In a second aspect, the present application 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 method of the first aspect.
[0046] In a third aspect, the present application provides a computer-readable storage medium comprising computer instructions. When the computer instructions are executed on an electronic device, the electronic device executes the method of the first aspect.
[0047] 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.
[0048] In a fifth aspect, the present application 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 method of the first aspect.
[0049] 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
[0050] Figure 1 is a structural diagram of an electronic device provided in an embodiment of the present application;
[0051] Figure 2 This is a schematic diagram of the software structure of an electronic device provided in an embodiment of the present application;
[0052] 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 is too high according to an embodiment of the present application;
[0053] Figure 4 This is a logical architecture diagram of multi-threaded control exemplified in an embodiment of the present application;
[0054] Figure 5 A schematic diagram of a wake-up relationship topology structure exemplified in an embodiment of the present application;
[0055] 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;
[0056] Figure 7 A schematic diagram of the process of thread control in a high-load system scenario of an electronic device provided by an embodiment of the present application;
[0057] Figure 8 A schematic diagram of a traversal process in a high-load scenario of the system of an electronic device provided by an embodiment of the present application;
[0058] Figure 9 Schematic diagram of the multi-threaded control method in one embodiment of the present application. DETAILED DESCRIPTION
[0059] The following will be combined with the accompanying 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 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.
[0060] It should be understood that the terms "first," "second," and the like in the specification, claims, and drawings of this application are used to distinguish between different objects, rather than to describe a particular order. Furthermore, the terms "including," "having," and any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, product, or apparatus comprising a series of steps or elements is not limited to the listed steps or elements, but may optionally include steps or elements not listed, or may optionally include other steps or elements inherent to the process, method, product, or apparatus.
[0061] References to "embodiments" in this application mean that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0062] In the embodiments of this 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 this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0063] The central processing unit (CPU) of an electronic device has limited resources. If the CPU is running many tasks simultaneously, it can easily lead to high CPU load. High CPU load can cause many problems, such as slow startup response, animation lag, and ANR (application not responding) errors. Monitoring high CPU load and controlling non-critical background processes can optimize CPU load in high-load scenarios. However, current high-load scenario control often targets specific threads, which can sometimes lead to a poor user experience.
[0064] To this end, the present application provides a multi-threaded management 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.
[0065] The electronic device in the embodiments of the present application may be a mobile phone, a tablet computer, a wearable device, an in-vehicle 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 or a compact camera), etc. The embodiments of the present application do not impose any restrictions on the specific type of the electronic device.
[0066] First, the structure of an electronic device 100 provided in an embodiment of the present application is introduced.
[0067] For example, see Figure 1 , Figure 1 1 is a schematic structural diagram of an electronic device 100 provided in an embodiment of the present application.
[0068] The following describes the embodiment in detail by taking the electronic device 100 as an example. It should be understood that the electronic device 100 may have more Figure 1 More or fewer components may be shown, two or more components may be combined, or the components may be arranged differently. Figure 1 The various components shown in the drawings 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.
[0069] 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.
[0070] 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 processing unit (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). The different processing units may be independent devices or integrated into one or more processors.
[0071] 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.
[0072] 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.
[0073] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly retrieve it from the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0074] The charging management module 140 is configured to receive charging input from a charger, which may be a wireless charger or a wired charger.
[0075] 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 provide power to the processor 110, the internal memory 121, the external memory, the display 194, the camera 193, etc.
[0076] Electronic device 100 implements display functionality through a GPU, display screen 194, and an application processor. A GPU is a microprocessor for image processing that connects display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0077] Display screen 194 is used to display images, videos, and the like. 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 (AMOLED), a flexible light-emitting diode (FLED), a MiniLED, a MicroLED, a Micro-OLED, or a quantum dot light-emitting diode (QLED). In some embodiments, electronic device 100 may include one or N display screens 194, where N is a positive integer greater than one.
[0078] The camera 193 is used to capture still images or videos. The electronic device 100 may include one or N cameras 193, where N is a positive integer greater than one.
[0079] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0080] Video codecs are used to compress or decompress digital videos. Electronic device 100 may support one or more video codecs. In this way, electronic device 100 can play or record videos in multiple encoding formats.
[0081] The NPU is a neural-network (NN) computing processor. Drawing on the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it rapidly processes input information and can continuously self-learn. The NPU enables intelligent cognitive applications in electronic device 100, such as image recognition, face recognition, speech recognition, and text comprehension.
[0082] 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 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.
[0083] 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.
[0084] The electronic device 100 can implement audio functions such as music playback and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0085] 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 provided in the processor 110, or some functional modules of the audio module 170 can be provided in the processor 110.
[0086] The speaker 170A, also called a "speaker", is used to convert audio electrical signals into sound signals. The electronic device 100 can listen to music or listen to hands-free calls through the speaker 170A.
[0087] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals. When the electronic device 100 receives a call or a voice message, the user can place the receiver 170B close to the ear to hear the voice.
[0088] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals.
[0089] The pressure sensor 180A is used to sense pressure signals and convert them into electrical signals. 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 device comprising at least two parallel plates with conductive material. When 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 is applied to 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.
[0090] Touch sensor 180B, also known as a "touch panel," can be disposed on display screen 194. The touch sensor 180B and display screen 194 form a touch screen, also known as a "touch screen." Touch sensor 180B is used to detect touch operations applied thereto or in the vicinity thereof. The touch sensor can transmit the detected touch operations to an application processor to determine the type of touch event. Visual output related to the touch operations can be provided via display screen 194. In other embodiments, touch sensor 180B can also be disposed on the surface of electronic device 100, at a location different from that of display screen 194.
[0091] For example, see Figure 2 , Figure 2 Schematic diagram of the software structure of an electronic device 100 provided in an embodiment of the present application.
[0092] like Figure 2 As shown, the layered architecture divides software into several layers, each with distinct roles and responsibilities. Layers communicate with each other via software interfaces. In some embodiments, the software structure of an electronic device can be divided into two layers: an application layer and an operating system layer, where the operating system layer can be the Android operating system.
[0093] 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.
[0094] The operating system layers from top to bottom are the application framework layer, core library layer and kernel layer.
[0095] The application framework layer provides an application programming interface (API) and programming framework for applications in the application layer. The application framework layer includes predefined functions and may include the window manager, content provider, view system, telephony manager, resource manager, and notification manager.
[0096] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, take screenshots, etc.
[0097] Content providers are used to store and retrieve data and make it accessible to applications. Data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0098] The view system includes visual controls, such as those for displaying text and images. The view system is used to build applications. A display interface can consist of one or more views. For example, a display interface containing a text notification icon might include a view for displaying text and a view for displaying images.
[0099] The phone manager is used to provide communication functions for electronic devices, such as call status management (including answering, hanging up, etc.).
[0100] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0101] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically without user interaction. For example, the Notification Manager is used to notify users of completed downloads and message reminders. The Notification Manager can also display notifications in the top status bar of the system as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Examples include text messages in the status bar, beeps, vibrations on electronic devices, and flashing indicator lights.
[0102] The core library layer consists of two parts: one is the functional functions that need to be called by the programming language (for example, Java language), and the other is the core library of the system.
[0103] The application layer and application framework layer run in a virtual machine. The virtual machine executes application layer and application framework layer programming files (for example, Java files) as binary files. The virtual machine manages object lifecycles, stack management, thread management, security and exception management, and garbage collection.
[0104] The core library layer can include multiple functional modules, such as the surface manager, media libraries, 3D graphics processing library (such as OpenGL ES), and 2D graphics engine (such as SGL).
[0105] 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.
[0106] The media library supports playback and recording of a variety of common audio and video formats, as well as static image files. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0107] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.
[0108] A 2D graphics engine is a drawing engine for 2D drawings.
[0109] The kernel layer is the 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 multi-threaded control method provided in the embodiments of the present application can be implemented as a software module in the kernel layer of this software architecture.
[0110] It should be noted that the various functional modules included in the above software structure are merely exemplary and do not constitute a specific limitation on the software architecture of the mobile phone of this application. In other embodiments, the various functional modules included in the above software structure may be more or less, and this application does not impose any limitation on this. Although the embodiments of this 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.
[0111] 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.
[0112] To meet the diverse functional requirements of electronic device 100, existing operating system kernel development for electronic device 100 typically utilizes multi-threading technology. Multi-threading applies the concurrent execution mechanism of an operating system to a program, dividing the program into multiple subtasks that execute concurrently, with each task representing a thread.
[0113] Threads need to be resource-scheduled to execute tasks, specifically to obtain CPU access. In multi-threaded execution scenarios, CPU resource scheduling can be performed for each thread based on a time-sharing mechanism. For example, all threads can take turns using the CPU, evenly distributing CPU time (CPU resources) to each thread. Alternatively, in multi-threaded execution scenarios, CPU resource allocation can be performed based on thread priority. For example, higher-priority threads can be prioritized. If threads have the same priority, a randomly selected thread will be given priority, receiving first access to the CPU and the CPU time (CPU resources).
[0114] Multithreading can improve program efficiency and maximize CPU utilization. However, each CPU core can only execute one thread at a time. While technology has evolved from single-core processors to multi-core processors, the resources provided by multi-core CPUs are limited. During multithreaded execution, some threads may become blocked while waiting for CPU resources.
[0115] For example, in a scenario where CPU resources are allocated to each thread based on priority, thread A with low priority executes task 1 first, and thread B with high priority executes task 2 later. During the actual task execution process, thread B with high priority may preempt the CPU resources of thread A with 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 for CPU resources to be obtained again before continuing to execute task 1.
[0116] 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.
[0117] Mutual exclusion locks implement a simple form of "mutual exclusion" synchronization and are a common thread synchronization mechanism used to protect mutually exclusive access to shared resources in a multi-threaded environment. Mutual exclusion locks allow only one thread to access a shared resource (such as the CPU) at a time, forcing other threads to wait. For example, thread A can lock a mutex on other threads, causing the other threads to wait for the mutex to be unlocked. Only thread A can use the CPU resources at any given time. After completing its task, thread A can release the mutex, allowing other threads to enter the queue waiting for CPU resources.
[0118] A condition variable is a multithreaded synchronization mechanism used for communication and coordination between multiple threads. A condition variable allows one or more threads to wait for a condition to be met before continuing execution, thus avoiding busy waiting. The principle of a condition variable is based on the wait queue mechanism. When a thread executes and calls a wait function, it adds itself to the wait queue of the condition variable. When the condition is met, the wakeup function selects one or more threads from the wait queue and wakes them up. For example, when thread A waits for the condition variable to be awakened, thread A needs to suspend its task and enter a wait state. In other words, thread A can add itself to the wait queue of the condition variable. When other threads awaken the condition variable by executing other tasks, they can send a wakeup broadcast to all threads in the condition variable's wait queue. Thread A receives the wakeup broadcast and continues executing its corresponding task.
[0119] The execution states of a thread include the new state, ready state, running state, blocked state and dead state.
[0120] Among them, the new state refers to when a thread is created with new, the thread has not yet started running. At this time, the thread is in the new state. A thread in the new state has not yet started running.
[0121] 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.
[0122] When the thread obtains the CPU time (obtains CPU resources), it enters the running state and actually executes the contents of the run() method.
[0123] A thread may enter a blocked state for various reasons during execution: for example, a thread may enter a dormant state (also a blocked state) by calling sleep(). Alternatively, a thread may call an operation that blocks on input / output (I / O), becoming blocked until the I / O operation completes. Alternatively, a thread may become blocked while waiting for a lock to be released. Alternatively, a thread may become blocked while waiting for another triggering condition, such as a condition variable to be activated. A blocked state means that a running thread has not yet completed its execution and is merely temporarily relinquishing CPU resources, awaiting the next opportunity to acquire CPU resources.
[0124] There are two reasons why a thread may die: the run() method ends normally; an uncaught exception terminates the run() method and causes the thread to die suddenly.
[0125] In some scenarios, threads may enter a blocked state due to a mutex lock. For example, after thread A acquires a mutex lock, it enters a blocked state from a running state. If thread B, which holds the mutex lock, is preempted by another thread for CPU resources, thread B's CPU resources will be occupied, preventing it from executing its task. Consequently, the mutex lock cannot be released in a timely manner, and thread A, which holds the mutex lock, will remain blocked. Using the aforementioned lock identification method, potential deadlock situations can be identified.
[0126] In some scenarios, threads may enter a blocked state while waiting for a condition variable. For example, if thread A enters a blocked state from a running state because a condition is not met, or if it is actively blocked, or if it is waiting for a condition variable to be awakened, thread A may enter a blocked state. Thread B, which is waking up the condition variable, may be preempted by another thread, resulting in thread B's CPU resources being occupied and unable to execute the task required to wake up the condition variable. Thread A, which is waiting for the condition variable to be awakened, will remain in a blocked state.
[0127] 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, a communication application includes a main thread, a network thread, a file read / write thread, a database thread, an audio and video thread, an image loading thread, a push thread, a log thread, and a scheduled task thread. A navigation application includes a main thread, a map rendering thread, a positioning thread, a navigation thread, a network request thread, a file read / write thread, a sensor event thread, a log and monitoring thread, a scheduled task thread, a voice broadcast thread, an offline map processing thread, and an animation thread. A game application includes a main thread, a rendering thread, a physics engine thread, a network thread, an audio thread, a resource loading thread, an AI thread, a file I / O thread, and so on. 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 independently managed threads.
[0128] Moreover, there is a priority distinction between threads. When an application is running in the foreground, the application's threads have the highest priority, and the system usually allocates more CPU, memory and other resources to them. When an application switches from running in the foreground to running in the background, at least some of the application's threads will be suspended. Suspension means temporarily removing the thread from the CPU while 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 switches from foreground to 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, when the communication application is running in the background, the previous call can still be continued. For 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), logging 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 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.
[0129] Furthermore, during system operation on electronic device 100, when an application switches from foreground to background operation, the priority of the application's threads may change. For example, when a navigation application is running in the foreground, the thread priorities, from high to low, are as follows: 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 / write thread (medium priority), sensor event thread (medium priority), animation thread (medium priority), logging and monitoring thread (low priority), and scheduled task thread (low priority). When a navigation application switches from foreground to background operation, the thread priorities are as follows: positioning thread (medium to high priority), navigation thread (medium to high priority), network request thread (low to medium priority), logging and monitoring thread (low priority), and scheduled task thread (low priority). Suspended threads include: main thread (UI thread), map rendering thread, animation thread, and sensor event thread. When a 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 execution, 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.
[0130] Generally, only one application is running in the foreground of the electronic device 100, and other applications will be switched to the background to run. The user interface of the application 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, if the user does not manually close the application, 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 system's memory resources. 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 management method to optimize the management strategy for threads that are in a running state and / or in a blocked state during system operation. 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 are required to be 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.
[0131] 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 in 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 awakened at different times. It is understandable that in other embodiments, the CPU can have more or fewer cores. This is only an example and not a limitation. 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 system operation to reduce the load.
[0132] Please refer to Figure 4 , Figure 4This is a logical architecture diagram of multi-thread control exemplified in an embodiment of the present application. Specifically, 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 wake-up and being awakened between threads, and generate a wake-up relationship topology structure based on the wake-up relationship; the thread identification module is used to identify the critical threads and / or non-critical 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 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 critical thread, and the importance of the critical thread is higher than that of the non-critical 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:
[0133] Wake-up relationship recording module
[0134] During the operation of the system, there is a wake-up relationship between threads. The wake-up relationship is used to represent 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_count of the first thread is generally recorded in the list in the wake_node. When the first thread is awakened, the wake_count of the first thread increases by 1, and the wake_count of the first thread in the list is updated to the value of wake_count plus 1. The wake-up direction is used to indicate the direction of wake-up between threads. For example, if thread A wakes up thread B, the wake-up direction is A→B.
[0135] Please refer to Figure 5 The 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 of the thread. Figure 5 The English symbols in each oval in the are only examples and are not limiting. When there is a line between two nodes, it indicates that there is a wake-up relationship between the threads on the two nodes. For example, if there is a line between thread A and thread B, it 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 all point 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 threads are always awakened, the awakened threads need to update the corresponding nodes and / or wake-up relationships in the wake-up relationship topology. 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. Therefore, the wake-up relationship during the operation of the system changes dynamically, and the wake-up relationship topology also changes dynamically.
[0136] Wake-up relationship topology analysis module
[0137] Taking the first thread as an example, the wakeup relationship topology structure can be used to determine the number of wakeups and the wakeup depth of the first thread. The definition of the first thread's wakeup number is as described above. The wakeup depth of the first thread refers to the maximum depth that can be reached along the wakeup relationship chain starting from the first thread. The wakeup depth reflects the complexity of the dependencies and execution order between threads. For example, when thread (A) wakes up another thread (B), a wakeup relationship exists between threads (A) and (B). For another example, when thread (A) wakes up another thread (B), and thread (B) wakes up another thread (C), the wakeup depth of thread (A) is 1, the wakeup depth of thread (B) is 2, and the wakeup depth of thread (C) is 3.
[0138] 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 are obtained according to the wake-up relationship topology structure and provided to the importance determination module for importance calculation.
[0139] 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.
[0140] Thread Identification Module
[0141] Different threads during system operation have different impacts on the user's operational experience. Threads that have a greater impact on the user's operational experience during system operation can be called critical threads, while threads that have less impact or no impact on the user's operational experience during system operation can be called ordinary threads or non-critical threads. Therefore, during system operation, critical threads and / or non-critical threads are identified, so that at least the critical thread has a thread identifier, or at least the non-critical thread has a thread identifier, or the critical thread and non-critical thread each have different thread identifiers. In this way, the system can distinguish between critical threads and non-critical threads based on the thread identifiers.
[0142] Taking the first thread as an example, when the first thread is awakened, it is further identified whether the first thread is a critical thread. When the first thread is identified as the 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 the critical thread;
[0143] When the first thread is identified as a non-critical thread, the thread identifier is set to a second value, the second value being used to indicate that the first thread is a non-critical thread, wherein the first value is different from the second value.
[0144] 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.
[0145] Identifying whether the first thread is a critical thread can be achieved using a critical thread identification table, which lists the categories of all critical threads or the identifiers of specific critical threads. In this way, when the first thread is identified, it can be determined whether the first thread is a critical thread by comparing it with the critical thread identification table.
[0146] The key thread identification table includes the identifiers of foreground threads, background threads, graphics drawing threads, resource management threads, and system service management threads. The identifiers can be name identifiers, symbol identifiers, or other identifiers, which are not limited here.
[0147] 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, 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. 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 2 When the music application shown is playing a song, if the music application is switched to background operation, electronic device 100 will continue playing music. The background threads of the music application may include a main thread (used to control the service lifecycle), a worker thread (handling actual tasks such as audio decoding), a network thread (if data downloading is required), a daemon thread, etc. Background threads may include music playback applications (needing to play music in the background), navigation applications (needing to continuously update location information in the background), download applications (needing to download files or data in the background), instant messaging applications (needing to receive messages in the background), health monitoring applications (needing to continuously monitor sensor data in the background), and other threads that provide real-time sensor data. The graphics drawing thread is used to convert application or desktop graphics data (such as text, images, animations, etc.) into pixels displayed on the screen. Specifically, the graphics drawing thread includes the main thread, rendering thread, animation thread, and synthesis thread. Resource management threads manage the allocation, release, and optimization of system resources (such as CPU, memory, and I / O devices) within the operating system. Specifically, these threads include monitoring threads (data collection), scheduling threads (resource allocation), garbage collection threads (such as Java's GC), and daemon threads (background cleanup). System service management threads control and manage background services, system processes, and applications within the operating system. These threads include binder threads, the main thread, network request threads, file read / write threads, scheduled task threads, logging and monitoring threads, device management threads, and security service threads.
[0148] 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 the background and runs, 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.
[0149] Thus, in some embodiments, the first thread can be a critical thread and an ordinary 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 ordinary 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.
[0150] It is understandable that in some embodiments, different thread identifiers for identifying key threads may be added to different categories of key threads according to the different influences of different key threads on the system operation process.
[0151] 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.
[0152] Among them, when the first thread is awakened by the wake-up function, the 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. Conversely, 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 types of thread identifiers (marks), which are not limited here.
[0153] Thread Identification Module
[0154] Generally, during system operation, the system load will be monitored in real time. When the system load is monitored to exceed the preset load threshold, traversal will be triggered. During the traversal, when traversing to the first thread, the thread identification module will obtain the Task_struct tag of the first thread. Based on the tag, it can be identified whether the first thread is a critical thread.
[0155] Importance determination module
[0156] The importance determination module comprehensively determines the importance of the traversed first thread based on at least one of the wakeup times and wakeup depth of the first thread obtained by the wakeup relationship topology analysis module and the thread identifier obtained by the thread identification module.
[0157] The wakeup relationship of the first thread is positively correlated with the importance of the first thread;
[0158] The wakeup depth of the first thread is positively correlated with the importance of the first thread;
[0159] 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.
[0160] 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.
[0161] It is understandable that there are many ways to comprehensively determine the importance of the first thread by combining at least one of the number of wake-up times and the wake-up depth of the first thread and the thread identifier, such as weighted average, multiplication, addition, division, subtraction, etc., which are not limited here.
[0162] 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.
[0163] 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.
[0164] 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.
[0165] 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 is understood that the above values are only for illustration.
[0166] Therefore, although the first thread has a low number of wake-up times, 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.
[0167] 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.
[0168] 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 further improving the user experience.
[0169] 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.
[0170] In this way, when the first thread is determined to be a critical 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 critical threads with higher importance, thereby improving operation efficiency.
[0171] Thread scheduling module
[0172] The thread scheduling module performs a thread control operation on the first thread found by the traversal 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.
[0173] Therefore, a management operation to reduce 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.
[0174] 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.
[0175] 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 ranking of the first thread is located after a preset ranking position of the importance rankings of all threads during the current operation of the system, wherein the importance ranking is sorted from high importance to low importance.
[0176] 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.
[0177] The termination operation performed on the first thread refers to activating the first thread from the CPU and deleting the context, and the freezing operation performed on the first thread refers to activating the first thread from the CPU but retaining the context.
[0178] Therefore, when the importance of the first thread is too low, different management and control strategies can be selected to manage the first thread according to the importance of the first thread.
[0179] 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. However, the CPU resource utilization of thread C and thread D will be reduced in sequence, that is, thread C and thread D will be frozen or terminated.
[0180] In some other embodiments, when the importance ranking of the first thread is after the 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.
[0181] Using the previous example, thread A is a foreground thread with 2 wakeup times, thread B is a background running thread with 8 wakeup times, and thread C is a suspended background thread with 15 wakeup times. Thread D is a normal thread with 5 wakeup times. Based on the thread ID and wakeup times, thread A's importance is determined to be 52, thread B's importance is 58, thread C's importance is 15, and thread D's importance is 5. The preset sorting position is the second-to-last position. Therefore, based on the importance sorting, the thread after the second-to-last position is determined to be thread D. This reduces thread D's CPU resource usage.
[0182] In other embodiments, while performing control operations to reduce the utilization rate of CPU resources on the first thread with low importance, the corresponding CPU resources of the first thread with higher importance can also be adjusted according to the importance. For example, the first thread with the highest importance obtains the most CPU resources.
[0183] For example, see Figure 7 , Figure 7 A schematic diagram of the thread control process for an electronic device under high system load in an embodiment of the present application. The system load is monitored. When the system load is detected to be above a preset load threshold, a traversal is triggered. When the traversal reaches the first thread, the first thread is assigned a corresponding importance based on its thread identifier and wake-up count. If the importance of the first thread is too low, the first thread is frozen or terminated.
[0184] 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.
[0185] Module 801: Monitor the system load and determine whether the system load exceeds the system load threshold. If yes, execute module 802.
[0186] Module 802: Traverse the root node of the wake-up relationship topology structure.
[0187] Module 803: Starting from the root node, all nodes on the wakeup relationship chain are traversed 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.
[0188] Module 804: Starting from the root node, traverse all nodes on the other wakeup relationship chain in reverse order along the wakeup direction of the other wakeup relationship chain to traverse all threads that directly or indirectly wake up the root node.
[0189] Module 805: Determine whether all root nodes of the wake-up relationship topology structure have been traversed. If so, end; otherwise, return to module 802.
[0190] For each thread traversed, its importance is determined based on at least one of the wakeup count and wakeup depth and the thread identifier, and thread control operations are performed on threads with low importance based on the importance. The thread control operations are used to reduce the thread's utilization of CPU resources.
[0191] Figure 9 The specific process of a multi-threaded control method provided in an embodiment of the present application is exemplified.
[0192] like Figure 9 As shown, the multi-threaded control method includes:
[0193] Step 901: monitoring the system load during system operation;
[0194] Step 902: When the system load is monitored to exceed a preset load threshold, traverse at least part of the threads in the system operation process;
[0195] Step 903: Execute the following for the first thread found:
[0196] Get at least the number of wake-up times and thread ID of the first thread;
[0197] determining the importance of the first thread based at least on the number of wake-up times of the first thread and a 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 a critical thread is higher than the importance of a non-critical thread;
[0198] 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.
[0199] wherein the first thread belongs to at least some threads;
[0200] 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 operation of the system, wherein the importance ranking is sorted from high importance to low importance.
[0201] Among them, the definition of key threads is as described above and will not be repeated here.
[0202] In some embodiments, the 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_count of the first thread is generally recorded in a list in the wake_node. When the first thread is awakened, the wake_count of the first thread is incremented by 1, and the wake_count of the first thread in the list is updated to the value of wake_count plus 1.
[0203] When the first thread is identified as a critical thread, the thread is marked as such. For example, the Task_struct of the first thread is set to critical. Conversely, when the first thread is identified as a non-critical thread by the critical thread identification table, no thread marking is performed. For example, the Task_struct of the first thread is set to null. It is understood that thread identification (marking) can be of various types and is not limited here.
[0204] 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 the number of wake-up times of the first thread may be different under different load scenarios. 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, and can reduce the system load in a shorter time compared to the existing technology.
[0205] In some embodiments, when the system load is monitored to exceed a preset load threshold, before traversing at least some threads in the system operation process, the multi-thread management and control method further includes:
[0206] When the first thread is awakened during system operation, the awakening count of the first thread is updated to the value of the current awakening count plus 1;
[0207] 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.
[0208] 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.
[0209] 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 based on the updated wake-up count of the first thread can improve the accuracy of the management and control decisions for the first thread and maximize the user experience.
[0210] In some embodiments, when the system load is monitored to exceed a preset load threshold, before traversing at least some threads in the system operation process, the multi-thread management and control method further includes:
[0211] 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
[0212] 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.
[0213] When the first thread is identified as a critical thread, the thread is marked as such. For example, the Task_struct of the first thread is set to critical. Conversely, when the first thread is identified as a non-critical thread by the critical thread identification table, no thread marking is performed. For example, the Task_struct of the first thread is set to null. It is understood that thread identification (marking) can be of various types and is not limited here.
[0214] Therefore, the first thread is identified as a critical thread or a non-critical thread through the critical thread identification table, and different values are set for the thread label when the first thread is identified as a critical thread or a non-critical 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, and can quickly reduce the system load in a short time.
[0215] In some embodiments, the multi-thread management method further includes:
[0216] When the first thread switches from foreground execution to background execution, if 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;
[0217] 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:
[0218] 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.
[0219] 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. The importance of the first thread is updated accordingly, which ensures that the importance of the first thread is 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 decisions for the first thread and maximize the user experience.
[0220] In the prior art, when an application is switched from the foreground to the background, the application-related threads will be suspended. Only when the user manually closes the application will the application-related threads disappear. Otherwise, the application will remain in the suspended state in the background.
[0221] In comparison, in this application, when the system is highly loaded, some non-critical threads suspended in the background will first be frozen and / or terminated. This will significantly shorten the duration of the critical thread D state (the thread is in an uninterruptible sleep state). Through trace or log data, the duration of the critical thread D state can also be counted. It will be found that compared with the existing technology, the duration of the critical thread D state in this application is significantly reduced, which can quickly reduce the system load, increase the system operation speed, and bring a better experience to users.
[0222] In some embodiments, the key thread identification table includes relevant identifiers of foreground threads, background running threads, graphics rendering threads, resource management threads, and system service management threads.
[0223] 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.
[0224] 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. Under normal circumstances, 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. 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 2 When the music application shown is playing a song, if the music application is switched to background operation, electronic device 100 will continue playing music. The background threads of the music application may include a main thread (used to control the service lifecycle), a worker thread (handling actual tasks such as audio decoding), a network thread (if data downloading is required), a daemon thread, etc. Background threads may include music playback applications (needing to play music in the background), navigation applications (needing to continuously update location information in the background), download applications (needing to download files or data in the background), instant messaging applications (needing to receive messages in the background), health monitoring applications (needing to continuously monitor sensor data in the background), and other threads that provide real-time sensor data. The graphics drawing thread is used to convert application or desktop graphics data (such as text, images, animations, etc.) into pixels displayed on the screen. Specifically, the graphics drawing thread includes the main thread, rendering thread, animation thread, and synthesis thread. Resource management threads manage the allocation, release, and optimization of system resources (such as CPU, memory, and I / O devices) within the operating system. Specifically, these threads include monitoring threads (data collection), scheduling threads (resource allocation), garbage collection threads (such as Java's GC), and daemon threads (background cleanup). System service management threads control and manage background services, system processes, and applications within the operating system. These threads include binder threads, the main thread, network request threads, file read / write threads, scheduled task threads, logging and monitoring threads, device management threads, and security service threads.
[0225] Therefore, these major categories of threads are user-perceivable threads. These major categories of threads are set in the critical thread identification table. When identifying whether the first thread is a critical thread, it can be compared with the critical thread identification table to quickly determine whether the first thread is a critical thread, thereby improving the system operation speed, further improving the system's ability to reduce load, and further shortening the time to reduce the system load.
[0226] In some embodiments, determining the importance of the first thread based on at least the number of wake-up times of the first thread and the thread identifier specifically includes:
[0227] 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.
[0228] 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 further improving the user experience.
[0229] In some embodiments, when the system load is monitored to exceed a preset load threshold, before traversing at least some threads in the system operation process, the multi-thread management and control method further includes:
[0230] During system operation, the wakeup relationship between different threads is recorded. The wakeup relationship is used to represent the relationship between waking up and being awakened between threads.
[0231] Generate a wakeup relationship topology structure according to the wakeup relationship during system operation;
[0232] At least the number of wake-up times and thread ID of the first thread are obtained, including:
[0233] Acquire the wakeup count and 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;
[0234] 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:
[0235] 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.
[0236] 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.
[0237] 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 will be understood that the above values are only examples.
[0238] Therefore, although the first thread has a low number of wake-up times, 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.
[0239] 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 evaluated, 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.
[0240] In some embodiments, when the importance of the first thread is too low, performing a thread control operation on the first thread specifically includes:
[0241] 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, performing a freezing operation on the first thread;
[0242] 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.
[0243] 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 while optimizing the system load.
[0244] 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.
[0245] 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.
[0246] The present application provides a computer program product, comprising instructions, which implement the above method when the instructions are executed by a processor.
[0247] 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 performs the above method.
[0248] 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, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
[0249] As used in the above embodiments, the term “when” may be interpreted to mean “if” or “after” or “in response to determining that” or “in response to detecting that”, depending on the context. Similarly, the phrases “upon determining that” or “if (stated condition or event) is detected” may be interpreted to mean “if determining that” or “in response to determining that” or “upon detecting (stated condition or event)” or “in response to detecting (stated condition or event)”, depending on the context.
[0250] 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 program or instruction is executed by the processor, the chip system implements the method in any of the above method embodiments.
[0251] Optionally, there may be one or more processors in the chip system. The processor may be implemented in hardware or software. When implemented in hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented in software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.
[0252] Optionally, the memory in the chip system may be one or more. The memory may be integrated with the processor or may be provided separately from the processor, which is not limited in the embodiments of the present application. For example, 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 provided on different chips. The embodiments of the present application do not specifically limit the type of memory or the configuration of the memory and the processor.
[0253] Exemplarily, the chip system may 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.
[0254] It should be understood that each step in the above method embodiment can be completed by hardware integrated logic circuits in a processor or by software instructions. 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.
[0255] In the above embodiments, all or part of the embodiments can be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments can be implemented 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 processes or functions described in the embodiments of the present application are generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, optical fiber, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, hard disk, tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive).
[0256] Those skilled in the art will appreciate that all or part of the process steps in the above-described method embodiments can be implemented by a computer program instructing the relevant hardware. The program can be stored in a computer-readable storage medium, and when executed, the program can include the process steps in the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM or random access memory (RAM), magnetic disks, or optical disks.
Claims
1. A multi-thread management 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, traversing at least part of the threads in the system operation process; Execute the following command on the first thread traversed: Obtain at least the number of wake-up times and the thread identifier of the first thread; determining the importance of the first thread based at least on 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 the importance 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; 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 to low importance; The key thread identification table includes at least one identifier of a foreground thread, a background running thread, a graphics rendering thread, a resource management thread, and a system service management thread.
2. The multi-thread management and control method according to claim 1, characterized in that: 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 system operation, the awakening count of the first thread is updated to 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 management and control method according to claim 1, characterized in that: 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 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 management and control method according to claim 3, characterized in that: The multi-thread control method further includes: When the first thread switches from foreground execution to background execution, if 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 management and control method according to any one of claims 1, 3 or 4, 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.
6. 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.
7. 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 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: During system operation, the wakeup relationship between different threads is recorded. The wakeup relationship is used to represent the relationship between waking up and being awakened between threads. generating a wake-up relationship topology structure according to the wake-up relationship during system operation; The acquiring of at least the number of wake-up times and the thread identifier of the first thread specifically includes: Acquire the wakeup count and 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.
8. 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 ranking of the first thread is located after the preset ranking position and before the first preset ranking position in the importance ranking of all threads in the current running process of the system, 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 during the current operation 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.
9. An electronic device, characterized in that: The electronic device 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 method as described in any one of claims 1 to 8.
10. 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 according to any one of claims 1 to 8.
11. 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 8.
12. 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 performs the method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Systems and methods for prioritizing and assigning threads in a heterogeneous processor architecture
WO2024206942A1
Resource scheduling method and apparatus, and electronic device
WO2025036044A1