Task processing method and device, terminal and computer readable storage medium
By assigning service quality levels to tasks on terminal devices and dynamically adjusting thread priorities, the problem of lagging when terminal devices are processing tasks is solved, user experience is improved, and resource usage is optimized.
Patent Information
- Application Number
- CN202410710734.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2019-04-11
- Publication Date
- 2024-10-01
AI Technical Summary
Terminal devices are prone to lagging when processing tasks, especially because the low priority of background applications causes task execution times to be too long, affecting user experience.
By assigning service quality levels to tasks, the priorities of threads are dynamically adjusted so that tasks with high service quality levels are processed first, ensuring that tasks are allocated resources on demand and queued in the processing queue to improve execution efficiency.
It effectively avoids lagging caused by long task processing times, improves user experience, and avoids unnecessary power consumption through reasonable allocation of resources.
Smart Images

Figure CN118733254A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a task processing method, device, terminal and computer-readable storage medium. Background Art
[0002] Terminal devices are widely used in people's daily lives. However, as the usage time increases, terminal devices will experience lag when performing tasks. For example, when a terminal device starts an application, the startup time is relatively long. After the APP is started, the display interface of the terminal device can display the content of the application. The display interface will also experience lag while waiting for the application to start. The reason why the application starts slowly is that when the terminal device processes the application startup task, the application process needs to wait in line for a long time before it can be processed. The terminal device can assign priorities to the applications in the system and process tasks related to each application based on the priority level to avoid lag when the terminal device processes tasks.
[0003] At present, task processing can be the following process: the system of the terminal device includes multiple applications, the application displayed on the display interface of the terminal device can be called the foreground application, and the application not displayed on the display interface can be called the background application. The terminal device assigns priority to each application according to whether each application can be displayed on the display interface, wherein the foreground application has a higher priority and the background application has a lower priority. Specifically, when the terminal device is processing the tasks of the foreground application and the background application, it can generate processes related to each application. The terminal device completes the tasks related to the application by processing the processes, wherein the process related to the foreground application has a higher priority and the process related to the background application has a lower priority. For example, when a terminal device processes a task, it calls multiple threads to implement the task. The operating system (e.g., Linux) kernel of the terminal device uses a completely fair scheduler (CFS) to schedule the multiple threads at the scheduling level. In the scheduling process, the Linux kernel can schedule based on the priority of the thread. Specifically, based on the virtual execution time indicated by the virtual clock, the virtual clock of the high-priority thread runs slower, and the virtual clock of the low-priority process runs faster. Although the high and low priority virtual execution times are relatively fair, the execution time of the low-priority process is less than that of the high-priority process. When all the threads required for the task are processed, the task is processed. However, when there are one or more threads in the multiple threads, and the priority of the one or more threads does not match the requirements of the task, it is easy to cause the execution time of the task to be too long. For example, there are one or more threads of background applications in the multiple threads, and the threads of the one or more background applications have a long execution time due to their own low priority, which leads to a long total time consumption of the task. From the user's perspective, the system is perceived to be stuck, thereby reducing the user experience. Summary of the invention
[0004] The embodiments of the present application provide a task processing method, device, terminal, and computer-readable storage medium, etc., which can avoid the jamming problem to a certain extent and improve the user experience of the terminal device. The present application is introduced below through different aspects. It should be understood that the implementation methods and beneficial effects of the following aspects can refer to each other.
[0005] In a first aspect, the present application provides a task processing method, the method comprising: receiving a task request, the task request being used to indicate processing a task related to an application; based on the task request, obtaining a quality of service level of the task; when a first thread is used to process a subtask corresponding to the task request, configuring the quality of service level of the first thread as the quality of service level of the task; and based on a processing order corresponding to the quality of service level (or priority) of the first thread, processing the subtask corresponding to the first thread.
[0006] The aforementioned "thread" may also be a "process". A task is a service provided by the terminal to the user through an application. A task may be a startup task or any task during the running of an application, such as a sliding task. A startup task may be a task for the terminal to start an application, and a sliding task may be a task for the terminal to switch applications on a display interface. Of course, a task may also be other tasks. The embodiments of this application do not specifically limit the specific content of the task.
[0007] In the above method, the service quality level of the task request is newly added and is related to the user's perception. The service quality level of the task request with strong user perception is higher than the service quality level of the task request with weak user perception. This service quality level can be set based on experience or by machine learning.
[0008] The "subtask" here can be understood differently depending on the task. If the task cannot be split or does not need to be split for execution, then the subtask can be understood as the task itself. If the task requires multiple processes or multiple threads to be implemented in parallel or serially in a certain order, that is, the task is decomposed into different processes or threads, then the tasks executed by multiple processes or threads can be understood as the "subtasks" of the task. This application does not limit the specific way of splitting the task.
[0009] The task request may carry the task identifier and object identifier of the task. The object identifier is used to indicate the object of the task. The object may be any application in the terminal. The object identifier may be the name of the object. For example, the task request 1 carries the start identifier start and the object identifier ABC. The task request is used to indicate the start of an application named ABC.
[0010] Based on the above possible implementation, when the first thread is used to process the subtask corresponding to the task request, the service quality level of the first thread is configured as the service quality level of the task, and the subtask corresponding to the first thread is processed based on the processing order corresponding to the service quality level of the first thread, so that in the process of processing the task, the priority of the first thread used is the same as the service quality level of the task, rather than blindly using the original priority. In this way, the processing order when the first thread is processed can be consistent with the service quality level of the task. For tasks with high service quality levels (such as interface drawing tasks that users are more sensitive to, etc.), the thread is executed faster, so that the task is implemented faster and the user experience is better. For example, the first thread may be a thread of a background application. If the thread is executed according to the priority of the background application, the waiting time will be long, which will result in a long execution time of the task. However, since the service quality level of the task is high, the first thread can increase the priority according to the service quality level of the task, thereby reducing the execution waiting time and improving the processing efficiency of the task.
[0011] In one possible implementation, based on the processing order corresponding to the service quality level of the first thread, processing the subtask corresponding to the first thread includes: inserting the subtask into the processing queue before the subtask with a service quality level lower than the service quality level of the thread or without a service quality level, and processing the subtask in the order in the processing queue.
[0012] The processing queue is used to store subtasks of each thread. Based on the above possible implementation, subtasks of threads with higher service quality levels can be queued in the processing queue, so that the terminal can give priority to processing subtasks of threads with higher service levels, and then tasks with higher service levels can be processed first.
[0013] In one possible implementation, the processing of the subtask corresponding to the first thread includes: when the target resource of the subtask is locked, configuring the service quality level of the second thread to the service quality level of the first thread, and the second thread is the thread that locks the target resource; when the second thread releases the lock of the target resource, processing the subtask based on the target resource.
[0014] In one possible implementation, when the target resource of the subtask is locked, configuring the service quality level of the second thread to the service quality level of the first thread includes: when executing the subtask corresponding to the first thread, locking the target resource; when locking the target resource fails, determining the second thread; when the service quality level of the second thread is lower than the service quality level of the first thread, updating the service quality level of the second thread to the service quality level of the first thread.
[0015] The target resource is any resource that can be locked in the system, for example, a memory control block and a Bind node. The lock added by the first thread to the target resource may include any lock such as a mutex lock, a read-write semaphore, a Java lock, and of course other locks. For example, when the first thread needs memory resources, the terminal can lock the memory control block through a read-write semaphore so that the first thread can use the memory resources corresponding to the memory control block. For another example, when the first thread calls other threads through the Binder driver, the terminal can lock the Binder node through a mutex lock so that the first thread can call the thread corresponding to the Binder node. The embodiments of the present application do not specifically limit the locks on the target resources.
[0016] In one possible implementation, when the second thread releases the lock of the target resource, processing the subtask based on the target resource includes: after the second thread releases the lock of the target resource, locking the target resource in an order in a waiting queue of the target resource, and restoring the original service quality level of the second thread, wherein the waiting queue of the target resource is used to store threads to be processed of the target resource; after locking the target resource, processing the subtask based on the target resource.
[0017] Based on the above possible implementation method, when the service quality of the first thread is low, the service quality level of the second thread is updated to the service quality level of the first thread, so that the service quality levels of the first thread and the second thread can be consistent. Then, when the second thread releases the lock, based on the order in the waiting queue of the target resource, the first thread can lock and process the target resource, thereby avoiding priority inversion.
[0018] In a possible implementation, the method further includes: when the first thread calls the third thread, adjusting the service quality levels of the first thread and the third thread according to the amount of data of the first thread cached in the third thread.
[0019] In a possible implementation, when the first thread calls the third thread, adjusting the service quality levels of the first thread and the third thread according to the amount of data of the first thread cached in the third thread includes:
[0020] When the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is less than a data amount threshold, the service quality level of the first thread and the third thread is kept unchanged; when the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the service quality level of the first thread is reduced.
[0021] Based on the above possible implementation methods, the QoS level of the thread executed by the terminal when processing the task request is dynamically adjusted, so that the terminal can execute the first thread at the most appropriate speed, and it can never be avoided that the first thread causes unnecessary power consumption when using system resources, or is insufficient for the lower-level threads.
[0022] In a possible implementation, when the first thread calls the third thread, the service quality levels of the first thread and the third thread are adjusted according to the amount of data of the first thread cached in the third thread, including: when the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is less than a data amount threshold, improving the service quality level of the first thread; when the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, improving the service quality level of the third thread.
[0023] Based on the above possible implementation, when the amount of data of the thread cached in the third thread is less than the data amount threshold, the terminal increases the service quality level of the first thread, so that the amount of data of the first thread in the third thread reaches the data amount threshold, and when the third thread is consumed too quickly suddenly, it can be avoided that the amount of data of the first thread in the third thread cannot keep up with the consumption progress. When the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the terminal increases the service quality level of the third thread, so that the speed of consuming the amount of data of the first thread cached in the third thread is accelerated, so that the data generated by the first thread can be avoided from accumulating in the third thread.
[0024] In a possible implementation manner, the service quality level of the task is determined by a task feature of the task.
[0025] Based on the above possible implementation manner, when the quality of service level of the first thread is configured according to the quality of service level of the task, the quality of service level of the first thread may be correlated with the quality of service level of the task.
[0026] In a possible implementation, the method further includes: when processing the task, if the application is switched from foreground operation to background operation, configuring the service quality level of the thread corresponding to the task to the first target level.
[0027] Based on the above possible implementation methods, by configuring the service level of the thread corresponding to the background running application and the task to the first target level, the terminal does not give priority to the tasks of the background running application, thereby reducing the interference of the background running application on the foreground running application.
[0028] In one possible implementation, configuring the service quality level of the first thread as the service quality level of the task includes: configuring the service quality level field in the thread control block structure of the first thread as the service quality level of the task, and the thread control block structure is used to store thread information.
[0029] In a possible implementation, the method further includes: when the first thread fails to apply for memory resources and the service quality level of the first thread is greater than a second target level, allocating memory resources to the first thread from reserved memory resources.
[0030] Based on the above possible implementations, in the case of memory urgency, by allocating memory to threads with higher service quality levels in reserved memory resources, the processing progress of threads with higher service quality levels can be guaranteed.
[0031] In a possible implementation, different task requests correspond to different task quality levels.
[0032] Based on the possible implementations described above, different service quality levels are configured when the application processes different tasks. According to user needs, threads in the application can have different processing priorities when processing different tasks, thereby reducing the energy consumption of the terminal.
[0033] In a second aspect, the present application provides a task processing method, the method comprising: receiving a task request; based on the task request, obtaining a service quality level corresponding to the task request (or the task corresponding to the task request); when multiple first threads are used to process subtasks corresponding to the task request, configuring the service quality level of the multiple first threads as the service quality level of the task, the multiple first threads belonging to at least two applications; based on the processing order corresponding to the service quality levels of the multiple first threads, processing the subtasks corresponding to the first threads.
[0034] Usually, when executing a task, an application will call multiple threads to implement the task. When multiple threads executing the task are configured with the same priority as the service quality level of the task in the above manner, the waiting problem caused by different priorities of the application can be avoided to a certain extent, thereby avoiding the jamming phenomenon when processing the task.
[0035] In some implementations, the multiple first threads include thread A and thread B, thread A calls thread B to implement the task, and thread A transmits the service quality level of thread A to thread B through a binder mechanism. Thus, the service instruction levels of thread B and thread A are consistent with the service quality level of the task, avoiding priority inversion.
[0036] In some implementations, the multiple first threads include thread A and thread B, thread A calls thread B, and the service quality levels of thread A and thread B are adjusted according to the amount of data of thread A cached in thread B. In this way, the service quality level is dynamically adjusted according to the task execution situation, especially when the amount of data of thread A cached in thread B is large, the service quality level is lowered to avoid excessive supply of resources to thread A and thread B.
[0037] In some implementations, when one of the plurality of first threads accesses a target resource and finds that the target resource is locked, the service quality level of the thread that locks the target resource is configured as the service quality level of the first thread. This can speed up the release of the target resource, thereby speeding up the execution of the first thread, and further speeding up the execution of the task.
[0038] In a third aspect, the present application provides a task processing device for executing the above-mentioned task processing method. Specifically, the task processing device includes a functional module for executing the task processing method provided by any one of the above aspects or any optional manner of any one of the above aspects.
[0039] In a fourth aspect, the present application provides a terminal, which includes a processor and a memory, wherein the memory stores at least one instruction, which is loaded and executed by the processor to implement the operations performed by the above-mentioned task processing method.
[0040] In a fifth aspect, the present application provides a computer-readable storage medium, in which at least one instruction is stored, and the instruction is loaded and executed by a processor to implement the operations performed by the above-mentioned task processing method.
[0041] In a sixth aspect, the present application provides a computer program product (or computer program), in which at least one instruction is stored, and the instruction is loaded and executed by a processor to implement the operations performed by the above-mentioned task processing method. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application, and those skilled in the art can also obtain other drawings based on these drawings.
[0043] Figure 1 is a schematic diagram of the structure of a terminal provided in an embodiment of the present application;
[0044] Figure 2 It is a software structure block diagram of a terminal provided in an embodiment of the present application;
[0045] Figure 3 It is a schematic diagram of an implementation environment provided by an embodiment of the present application;
[0046] Figure 4 is a system schematic diagram of a terminal provided in an embodiment of the present application;
[0047] Figure 5 is a flowchart of a task processing method provided by an embodiment of the present application;
[0048] Figure 6 is a flow chart of a hot start task processing method provided in an embodiment of the present application;
[0049] Figure 7 is a flow chart of a cold start task processing method provided in an embodiment of the present application;
[0050] Figure 8 This is a flow chart of a synchronization service quality level provided by an embodiment of the present application;
[0051] Fig. 9 This is a flowchart of a synchronous mutex lock provided by an embodiment of the present application;
[0052] Fig.10 This is a flow chart of a synchronous read and write signal provided by an embodiment of the present application;
[0053] Fig.11 It is a schematic diagram of a task processing process based on the Android system architecture provided in an embodiment of the present application;
[0054] Fig.12 This is a flow chart of delivering a quality of service level in a sliding scenario provided by an embodiment of the present application;
[0055] Fig.13 is a schematic diagram of a pipeline-based dynamic service quality classification model in a rendering scenario provided by an embodiment of the present application;
[0056] Fig.14 It is a structural device diagram of a task processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0057] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0058] See also Figure 1 , Figure 1 It is a structural diagram of a terminal provided in an embodiment of the present application. The terminal 100 may include a processor 110, an external memory interface 120, an internal memory 311, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0059] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the terminal 100. In other embodiments of the present application, the terminal 100 may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0060] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0061] The controller can generate operation control signals according to the instruction operation code and timing signal to complete the control of instruction fetching and execution.
[0062] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0063] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0064] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example, the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface, thereby realizing the touch function of the terminal 100.
[0065] The I2S interface can be used for audio communication. In some embodiments, the processor 110 can include multiple I2S buses. The processor 110 can be coupled to the audio module 170 via the I2S bus to achieve communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 via the I2S interface to achieve the function of answering a call through a Bluetooth headset.
[0066] The PCM interface can also be used for audio communication, sampling, quantizing and encoding analog signals. In some embodiments, the audio module 170 and the wireless communication module 160 can be coupled via a PCM bus interface. In some embodiments, the audio module 170 can also transmit audio signals to the wireless communication module 160 via the PCM interface to realize the function of answering calls via a Bluetooth headset. Both the I2S interface and the PCM interface can be used for audio communication.
[0067] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.
[0068] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to implement the shooting function of the terminal 100. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the terminal 100.
[0069] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0070] The USB interface 130 is an interface that complies with the USB standard specification, and specifically can be a Mini USB interface, a Micro USB interface, a USB Type C interface, etc. The USB interface 130 can be used to connect a charger to charge the terminal 100, and can also be used to transmit data between the terminal 100 and peripheral devices. It can also be used to connect headphones to play audio through the headphones. The interface can also be used to connect other electronic devices, such as AR devices, etc.
[0071] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the terminal 100. In other embodiments of the present application, the terminal 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0072] The charging management module 140 is used to receive charging input from a charger. The charger may be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger through the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive wireless charging input through a wireless charging coil of the terminal 100. While the charging management module 140 is charging the battery 142, it may also power the electronic device through the power management module 141.
[0073] 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, and supplies power to the processor 110, the internal memory 311, the display screen 194, the camera 193, and the wireless communication module 160. The power management module 141 can also be used to monitor parameters such as battery capacity, battery cycle number, battery health status (leakage, impedance), etc. In some other embodiments, the power management module 141 can also be set in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 can also be set in the same device.
[0074] The wireless communication function of the terminal 100 can be implemented through the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
[0075] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in terminal 100 can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antennas. For example, antenna 1 can be reused as a diversity antenna for a wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0076] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G applied on the terminal 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves from the antenna 1, and filter, amplify, and process the received electromagnetic waves, and transmit them to the modulation and demodulation processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modulation and demodulation processor, and convert it into electromagnetic waves for radiation through the antenna 1. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 can be set in the same device as at least some of the modules of the processor 110.
[0077] The modem processor may include a modulator and a demodulator. Among them, the modulator is used to modulate the low-frequency baseband signal to be sent into a medium-high frequency signal. The demodulator is used to demodulate the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After the low-frequency baseband signal is processed by the baseband processor, it is passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to a speaker 170A, a receiver 170B, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem processor may be an independent device. In other embodiments, the modem processor may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.
[0078] The wireless communication module 160 can provide wireless communication solutions including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), infrared (IR), etc., which are applied to the terminal 100. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, modulates the frequency of the electromagnetic wave signal and performs filtering, and sends the processed signal to the processor 110. The wireless communication module 160 can also receive the signal to be sent from the processor 110, modulate the frequency of it, amplify it, and convert it into electromagnetic waves for radiation through the antenna 2.
[0079] In some embodiments, the antenna 1 of the terminal 100 is coupled to the mobile communication module 150, and the antenna 2 is coupled to the wireless communication module 160, so that the terminal 100 can communicate with the network and other devices through wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general packet radio service (GPRS), code division multiple access (CDMA), wideband code division multiple access (WCDMA), time-division code division multiple access (TD-SCDMA), long term evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technology, etc. The GNSS may include a global positioning system (GPS), a global navigation satellite system (GLONASS), a Beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS) and / or a satellite based augmentation system (SBAS).
[0080] The terminal 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0081] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the terminal 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0082] The terminal 100 can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194 and the application processor.
[0083] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.
[0084] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the terminal 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0085] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the terminal 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0086] Video codecs are used to compress or decompress digital videos. Terminal 100 may support one or more video codecs. Thus, terminal 100 may play or record videos in various coding formats, such as moving picture experts group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0087] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of the terminal 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.
[0088] The external memory interface 120 can be used to connect an external memory card, such as a micro secure digital memory (Micro SD) card, to expand the storage capacity of the terminal 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos can be stored in the external memory card.
[0089] The internal memory 311 can be used to store computer executable program codes, which include instructions. The internal memory 311 may include a program storage area and a data storage area. Among them, the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the terminal 100 (such as audio data, a phone book, etc.), etc. In addition, the internal memory 311 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. The processor 110 executes various functional applications and data processing of the terminal 100 by running instructions stored in the internal memory 311 and / or instructions stored in a memory provided in the processor.
[0090] The terminal 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor.
[0091] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0092] The speaker 170A, also called a "speaker", is used to convert an audio electrical signal into a sound signal. The terminal 100 can listen to music or listen to a hands-free call through the speaker 170A.
[0093] The receiver 170B, also called a "handset", is used to convert audio electrical signals into sound signals. When the terminal 100 receives a call or voice message, the voice can be received by placing the receiver 170B close to the ear.
[0094] Microphone 170C, also called "microphone" or "microphone", is used to convert sound signals into electrical signals. When making a call or sending a voice message, the user can make a sound by putting his mouth close to microphone 170C to input the sound signal into microphone 170C. Terminal 100 may be provided with at least one microphone 170C. In other embodiments, terminal 100 may be provided with two microphones 170C, which can not only collect sound signals but also realize noise reduction function. In other embodiments, terminal 100 may also be provided with three, four or more microphones 170C to realize collection of sound signals, noise reduction, identification of sound source, realization of directional recording function, etc.
[0095] The earphone interface 170D is used to connect a wired earphone and can be a USB interface 130 or a 3.5 mm open mobile terminal platform (OMTP) standard interface or a cellular telecommunications industry association of the USA (CTIA) standard interface.
[0096] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The terminal 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the terminal 100 detects the touch operation intensity according to the pressure sensor 180A. The terminal 100 can also calculate the touch position according to 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. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
[0097] The gyroscope sensor 180B can be used to determine the motion posture of the terminal 100. In some embodiments, the angular velocity of the terminal 100 around three axes (i.e., x, y, and z axes) can be determined by the gyroscope sensor 180B. The gyroscope sensor 180B can be used for anti-shake shooting. Exemplarily, when the shutter is pressed, the gyroscope sensor 180B detects the angle of the terminal 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the terminal 100 through reverse movement to achieve anti-shake. The gyroscope sensor 180B can also be used for navigation and somatosensory game scenes.
[0098] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the terminal 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.
[0099] The magnetic sensor 180D includes a Hall sensor. The terminal 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the terminal 100 is a flip phone, the terminal 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. Then, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, the flip cover automatic unlocking and other features are set.
[0100] The acceleration sensor 180E can detect the magnitude of the acceleration of the terminal 100 in various directions (generally three axes). When the terminal 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device and is applied to applications such as horizontal and vertical screen switching and pedometers.
[0101] The distance sensor 180F is used to measure the distance. The terminal 100 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the terminal 100 can use the distance sensor 180F to measure the distance to achieve fast focusing.
[0102] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The terminal 100 emits infrared light outward through the light emitting diode. The terminal 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the terminal 100. When insufficient reflected light is detected, the terminal 100 can determine that there is no object near the terminal 100. The terminal 100 can use the proximity light sensor 180G to detect that the user holds the terminal 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used in leather case mode and pocket mode to automatically unlock and lock the screen.
[0103] The ambient light sensor 180L is used to sense the ambient light brightness. The terminal 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the terminal 100 is in a pocket to prevent accidental touches.
[0104] The fingerprint sensor 180H is used to collect fingerprints. The terminal 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
[0105] The temperature sensor 180J is used to detect temperature. In some embodiments, the terminal 100 uses the temperature detected by the temperature sensor 180J to execute a temperature processing strategy. For example, when the temperature reported by the temperature sensor 180J exceeds a threshold, the terminal 100 reduces the performance of the processor located near the temperature sensor 180J to reduce power consumption and implement thermal protection. In other embodiments, when the temperature is lower than another threshold, the terminal 100 heats the battery 142 to avoid abnormal shutdown of the terminal 100 due to low temperature. In other embodiments, when the temperature is lower than another threshold, the terminal 100 performs a boost on the output voltage of the battery 142 to avoid abnormal shutdown caused by low temperature.
[0106] The touch sensor 180K is also called a "touch control device". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch control screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the terminal 100, which is different from the position of the display screen 194.
[0107] The bone conduction sensor 180M can obtain a vibration signal. In some embodiments, the bone conduction sensor 180M can obtain a vibration signal of a vibrating bone block of the vocal part of the human body. The bone conduction sensor 180M can also contact the human pulse to receive a blood pressure beat signal. In some embodiments, the bone conduction sensor 180M can also be set in an earphone and combined into a bone conduction earphone. The audio module 170 can parse out a voice signal based on the vibration signal of the vibrating bone block of the vocal part obtained by the bone conduction sensor 180M to realize a voice function. The application processor can parse the heart rate information based on the blood pressure beat signal obtained by the bone conduction sensor 180M to realize a heart rate detection function.
[0108] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The terminal 100 may receive key input and generate key signal input related to user settings and function control of the terminal 100.
[0109] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0110] Indicator 192 may be an indicator light, which may be used to indicate charging status, power changes, messages, missed calls, notifications, etc.
[0111] The SIM card interface 195 is used to connect the SIM card. The SIM card can be connected to and separated from the terminal 100 by inserting it into the SIM card interface 195 or pulling it out from the SIM card interface 195. The terminal 100 can support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 can support Nano SIM cards, Micro SIM cards, SIM cards, etc. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the multiple cards can be the same or different. The SIM card interface 195 can also be compatible with different types of SIM cards. The SIM card interface 195 can also be compatible with external memory cards. The terminal 100 interacts with the network through the SIM card to realize functions such as calls and data communications. In some embodiments, the terminal 100 uses an eSIM, i.e., an embedded SIM card. The eSIM card can be embedded in the terminal 100 and cannot be separated from the terminal 100.
[0112] The software system of the terminal 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the terminal 100.
[0113] Figure 2 This is a software structure diagram of a terminal provided in an embodiment of the present application, see Figure 2 The layered architecture divides the software into several layers, each with clear roles and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the Android runtime (Android runtime), the local layer, and the kernel layer.
[0114] The application layer can include a series of application packages. Figure 2 As shown, the application package may include camera, gallery, calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message and other applications.
[0115] The application framework layer provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer includes some predefined functions.
[0116] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a view system, a phone manager, a resource manager, a notification manager, and the like.
[0117] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.
[0118] Content providers are used to store and retrieve data and make it accessible to applications. The data may include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0119] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.
[0120] The phone manager is used to provide communication functions of the terminal 100, such as management of call status (including connection, disconnection, etc.).
[0121] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0122] The notification manager enables applications to display notification information in the status bar. It can be used to convey notification-type messages and can disappear automatically after a short stay without user interaction. For example, the notification manager is used to notify download completion, message reminders, etc. The notification manager can also be a notification that appears in the system top status bar in the form of a chart or scroll bar text, such as notifications of applications running in the background, or a notification that appears on the screen in the form of a dialog window. For example, a text message is displayed in the status bar, a prompt sound is emitted, an electronic device vibrates, an indicator light flashes, etc.
[0123] Android Runtime includes core libraries and virtual machines. Android runtime is responsible for scheduling and management of the Android system.
[0124] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.
[0125] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.
[0126] The local layer can include multiple functional modules, such as surface manager, hardware composer (HWC), media library, 3D graphics processing library (such as OpenGLES), 2D graphics engine (such as SGL), etc.
[0127] The surface manager is used to manage the display subsystem and provide fusion of 2D and 3D layers for multiple applications. HWC is used to fuse the layers synthesized by SF.
[0128] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.364, MP3, AAC, AMR, JPG, PNG, etc.
[0129] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing, etc. The 2D graphics engine is a drawing engine for 2D drawing.
[0130] The kernel layer is the layer between hardware and software. The kernel layer contains at least display driver, camera driver, audio driver, and sensor driver.
[0131] The following is an example of the workflow of the software and hardware of the terminal 300 in conjunction with the scenario of running an application in the foreground. For example, when any application displays a web page in the foreground, the main process of the application uses various threads to call the 3D graphics processing library or the 2D graphics engine to draw various image frames when displaying the web page, and uses the HWC to fuse the layers, so that the application can display the web page in the foreground.
[0132] Figure 2 The software structure of the terminal is described. In order to show the work done by the software in the terminal when processing tasks related to application programs, see Figure 3 , Figure 3 It is a schematic diagram of an implementation environment provided by an embodiment of the present application, wherein the implementation environment includes a terminal 300, and the terminal 300 may be installed with an Android system. The terminal may be, but is not limited to, a laptop computer, a desktop computer, a mobile phone, a smart phone, a tablet computer, a multimedia player, an e-reader, a smart car device, a smart home appliance, an artificial intelligence device, a wearable device, an Internet of Things device, or a virtual reality / augmented reality / mixed reality device, etc.
[0133] The system architecture of the terminal may include an application layer, an application framework layer, a native layer, and a kernel layer.
[0134] The application layer is used to provide at least one application. The application in the terminal can be in a running state or in a non-running state. When any application is in a running state, the application can be divided into a foreground application and a background application according to the different running locations. The foreground application runs in the foreground and is displayed on the display interface of the terminal, and the background application runs in the background and is not displayed on the display interface of the terminal. The application layer can have at least one foreground application and at least one background application. Each foreground application or background application corresponds to a user interface (UI) thread and a rendering (Render) thread. The UI thread is also the main process, which is used to run the foreground application or the background application. A main process can include at least one thread, each thread is used to complete part of the tasks in the main process, and the rendering thread (Render thread) is a thread in the main process.
[0135] The Framework layer is used to provide system services and various application programming interfaces (APIs) that may be used when building applications. The Framework layer has an activity manager service (AMS) component, which is located in the system server of the Framework layer. For details, see Figure 4 , Figure 4 This is a system diagram of a terminal provided in an embodiment of the present application. The AMS component can be used to create applications and switch applications. Creating applications includes creating foreground applications and creating background applications. Switching applications means switching applications from the background to the foreground, or from the foreground to the background. The AMS component can also be used to set the Quality of Service (QoS) level of the application, wherein the setting of the QoS level is related to the characteristics of the task. The QoS level of the foreground application is higher than the QoS level of the background application. For example, if the UI thread and Render thread of the foreground application are delay-sensitive threads, the QoS level of the UI thread and Render thread of the foreground application can be set to 2. The UI thread and Render thread of the background QoS application will not affect the user's task. As they are delay-insensitive threads, the QoS level of the UI thread and Render thread of the background application can be set to 0. From Figure 4It can be seen that the system service also has a process incubator (Zygote), which is used to create UI threads and configure the QoS level of UI threads. The UI thread at this time is the UI thread of the application at the startup stage. The Framework layer also includes mechanisms for implementing inter-process communication, such as the Binder mechanism.
[0136] The Native layer, also known as the local service layer, is used to provide local services and link dynamic libraries. The Native layer has an Android runtime (ART) virtual machine, Native services, and Native link dynamic libraries. The ART virtual machine can provide an execution environment for Java programs. In the execution environment of the ART virtual machine, when two threads compete for the same Java object synchronization lock, the ART virtual machine can pass the QoS level between the two threads. The Native service and the Native link dynamic library have a surface synthesis service (SF), a media service, and a C function library (Libc), etc., wherein SF is used to synthesize rendering data into various layers, and the media service can play media files such as videos and music in the terminal 300. Libc is used to provide basic Native layer library functions, and the Native layer library functions may include functions for system call encapsulation. The terminal 300 can pass the QoS level between threads competing for the same mutex in the Libc environment of the Native layer.
[0137] The Kernel layer is used to provide the underlying driver for various hardware of the terminal 300. There is a kernel-mode synchronization mechanism on the Kernel layer. Based on the kernel-mode synchronization mechanism, in Mutex, user-mode fast mutex (Futex), read-write semaphore and other locks, when any thread fails to acquire the lock, the terminal 300 can pass the QoS level of the thread to the lock holder thread, and let the thread queue up on the lock waiting queue according to the QoS level of the thread. The Kernel layer also has a Binder driver, a CPU scheduling module, an input / output (I / O) management module and a double data rate (DDR) memory management module. Among them, the Binder driver is the core module of inter-process communication (IPC) on the Android system, which can realize that when a thread with a QoS level requests a Binder service, the thread on the service side inherits the QoS level of the requester. The CPU scheduling module is used to implement thread scheduling in the Android system. The CPU scheduling module has a QoS scheduling module. The QoS scheduling module is used to add a QoS record field to the thread control block structure and initialize the QoS value when the thread is created. For CFS-scheduled threads, the QoS scheduling module is also used to select tasks for execution according to the QoS level when there is a QoS task ready in the ready queue, otherwise the task is selected for execution according to the priority in the CFS scheduling. The I / O scheduling module is used to implement I / O queuing and current limiting according to the QoS level of the thread submitting the I / O request. The DDR memory management module has a new memory reservation module. The memory reservation module is used to directly obtain memory from the reserved memory when a thread with a higher QoS level fails to apply for memory, avoiding entering the native slow path of the Linux kernel. Threads with a higher QoS level can be threads with a QoS level greater than or equal to 2. The Kernel layer also has device nodes, see Figure 4 The device node is configured with a QoS device node, which is used to configure the QoS level and clear the QoS level. The terminal 300 can access the QoS device node through a function (ioctl) in the device driver that manages the I / O channel of the device.
[0138] The above is a description of the hardware and software of the terminal. Further, in order to reflect the process of terminal processing tasks, a specific embodiment is used here for description. Figure 5 , Figure 5 : is a flowchart of a task processing method provided in an embodiment of the present application. The method process provided in an embodiment of the present application includes:
[0139] 501. The terminal sets the service quality level of each task according to the task characteristics of the task.
[0140] The task characteristics of a task can reflect the user's service demand for a certain task. Therefore, different tasks have different task characteristics. Then, different service quality levels can be used to divide the tasks into different service quality levels, so that each service quality level can reflect different service demands. That is, the higher the service quality level of the task, the higher the user's service demand for the task, and the lower the service quality level of the task, the lower the user's service demand for the task.
[0141] The QoS level can be represented by a character string, and different character strings represent different QoS levels. For example, there are 4 QoS levels, which can be level 1, level 2, level 3 and level 4 from low to high, and can also be level A, level B, level C and level D from low to high. According to the service requirements reflected by the task characteristics of the task, the technician can set different QoS levels for different tasks in advance. In a possible implementation, each task corresponds to a task identifier. For any task, according to the task characteristics corresponding to the task identifier of the task, the technician sets the QoS level of the task. Among them, the task identifier is used to indicate the task, and the task identifier can be a start identifier, which is used to indicate the start task. The task identifier can also be a sliding identifier, which is used to indicate the sliding task. Of course, the task identifier can also be represented by the identifier of other tasks. The task identifier can be represented by a character string, and different character strings are used to indicate different task identifiers. For example, the character string "start" is used to indicate the start identifier, and the character string "slip" is used to indicate the sliding identifier. The embodiment of the present application does not specifically limit the task identifier.
[0142] The technicians can set the QoS level of each task in advance in the first QoS level table, wherein the first QoS level table can be used to record the task identifier, task characteristics and QoS level of the task, see Table 1, as can be seen from Table 1, wherein task identifiers 1-4 represent tasks 1-4 respectively, task 1 is a task related to reliability experience, and its QoS level is 4, and the task related to reliability experience can be when the terminal is running a large number of applications, and the user needs to immediately run a task that has not yet run in the foreground. This task is mainly for tasks in extreme scenarios such as degradation recovery. For example, when the user needs to make a call through the terminal, but at this time a large number of applications running in the terminal will occupy a large amount of resources in the terminal, but the task of making a call must be executed immediately, and at this time the task of making a call is a task in an extreme scenario, and the user has a high requirement for the reliability experience of the task. Task 2 is a task related to interaction, and its QoS level is 3. The user's service quality requirement for this task is that the lower the delay requirement, the better under the condition of general energy efficiency ratio, and the main requirement is to reduce the delay of feedback and loading. Task 3 is a rendering-related task, and its QoS level is 2. The user's service quality requirement for this task is to be completed within a certain time limit, and the delay and delay jitter are required to be as low as possible under the best energy efficiency ratio. Task 4 is the default task, which is the task normally executed by the terminal, and its QoS level is 1. Task 5 is a background task, and its QoS level is 0.
[0143] Table 1
[0144] Task ID Task Characteristics QoS Level Task ID 1 Tasks related to reliability experience 4 Mission ID 2 Interaction-related tasks 3 Mission ID 3 Rendering-related tasks 2 Mission ID 4 Default tasks 1 Mission ID 5 Background tasks 0
[0145] Technicians can also set the QoS level of each task by task type. Task type is used to indicate the importance of the task. The more important the task, the higher the QoS level, and the less important the task, the lower the QoS level. Technicians can set the QoS level of each task in advance in the first QoS level table. Task type can also be represented by a string. Different strings are used to represent different task types. For example, the task type "very important" can be represented by the string "A".
[0146] In one possible implementation, a technician may set the QoS level of each task in advance in a second QoS level table, wherein the second QoS level table is used to record the task identification, task type, task characteristics and QoS level of the task, see Table 2, wherein the task type of a task with a QoS level of 4 may be very important, the task type of a task with a QoS level of 3 may be quite important, the task type of a task with a QoS level of 2 may be relatively important, the task type of a task with a QoS level of 1 may be important, and the task type of a task with a QoS level of 3 may be non-important.
[0147] Table 2
[0148] Task ID Task Type Task Characteristics QoS Level Task ID 1 Very important (critical) Tasks related to reliability experience 4 Mission ID 2 Excellent effort Interaction-related tasks 3 Mission ID 3 More important (deadline effort) Rendering-related tasks 2 Mission ID 4 Important (best effort) Default tasks 1 Mission ID 5 Non-important (back ground) Background tasks 0
[0149] It should be noted that the process shown in this step 501 can be the process of the terminal obtaining the QoS level of each task preset by the technician during initialization. The terminal only needs to obtain it once, and the terminal does not need to execute this step 501 during subsequent operation. In the subsequent task processing process, the terminal can directly process the relevant tasks according to the QoS level obtained during initialization.
[0150] 502. The terminal receives a task request, where the task request is used to instruct processing of a task related to an application program.
[0151] The terminal may trigger the execution of step 502 based on the user's operation. Step 502 may be completed by the AMS component in the terminal. Taking the task startup as an example, when the user clicks on the icon of the application named ABC on the terminal display interface, the terminal may send the task request for starting the application ABC to the AMS component through the terminal display interface, so that the AMS component of the terminal may receive the task request.
[0152] 503. The terminal obtains a service quality level of the task based on the task request.
[0153] The terminal can obtain the service quality level of the task based on the task identifier of the task in the task request. In one possible implementation, when the terminal detects the task identifier in the task request, it searches for the QoS level corresponding to the task identifier in the first QoS level table or the second QoS level table to determine the QoS level of the task.
[0154] In some possible implementations, before obtaining the service quality level of the task, the terminal needs to first determine the state of the application corresponding to the task. The terminal can obtain the service quality level of the task only when the application is in the foreground running state or the non-running state. The state of the application includes the running state and the non-running state, wherein the running state of the application includes the foreground running state and the background running state, the foreground running state is used to indicate that the application is running in the foreground, the background running state is used to indicate that the application is running in the background, and the non-running state is used to indicate that the application is not running in the terminal.
[0155] The terminal can detect the current state of the application through the AMS component to determine the state of the application. In one possible implementation, when the terminal receives the task request, the terminal detects the state of the application indicated by the task request through the AMS component. When the state of the application is a foreground running state or a non-running state, the terminal executes this step 503. When the running state of the application is a background running state, the terminal does not execute this step 503 and subsequent steps.
[0156] It should be noted that the embodiments of the present application only illustrate that when the application is running in the foreground or not running, if a task request about the application is obtained, the terminal will obtain the service quality level of the task in real time. That is, once the application is running in the background, the terminal does not need to obtain the service quality level of the task. In some embodiments, the service quality level can also be obtained when performing a specific task while running in the background. The embodiments of the present application do not limit this.
[0157] 504. When the first thread is used to process the subtask corresponding to the task request, the terminal configures the service quality level of the first thread as the service quality level of the task.
[0158] The first thread may belong to the main process of the application or may be another thread. The embodiment of the present application does not specifically limit the first thread. When the terminal is processing a task corresponding to the application, the task may be completed through multiple threads of the application. Each of the multiple threads is used to complete part of the task, and the part of the task may also be regarded as a subtask of the task. When each of the multiple threads completes the corresponding subtask, the terminal completes the task.
[0159] The terminal may configure the service quality level of the first thread in the thread control block structure of the first thread, where the thread control block structure is used to store thread information, such as the service quality level, the number of called threads, etc. In a possible implementation, the terminal configures the service quality level field in the thread control block structure of the first thread of the application program to be the service quality level of the task.
[0160] When the terminal runs an application, it can run the application based on a main process, and the main process can be used to process tasks related to the application, that is, one application corresponds to one main process, and one main process can process multiple tasks. The main process can also use at least one process or at least one thread to process a task, each process can include at least one thread, wherein the main process can also be considered as a thread. When the terminal processes the task based on the main process, this step 504 can be implemented by the process shown in the following steps 5041-5042.
[0161] 5041. The terminal configures the service quality level of the main process of the application as the service quality level of the task.
[0162] The terminal may set the service quality level of the main process in the process control block structure of the main process, where the process control block structure is used to store information of the main process, such as the service quality level, the number of threads, etc. In a possible implementation, in the service quality level field in the process control block structure of the main process, the terminal configures the service quality level of the main process as the service quality level of the task.
[0163] It should be noted that before the terminal sets the service quality level of the main process of the application, the terminal needs to obtain the main process of the application based on the task request. Obtaining the main process of the application means determining the main process of the application or creating the main process of the application. In one possible implementation, the terminal obtains the main process corresponding to the task based on the object identifier of the task in the task request. The terminal can obtain the main process corresponding to the task by any of the following methods 1 and 2.
[0164] Mode 1: When the terminal detects a main process corresponding to the task request, the terminal directly determines the main process.
[0165] The terminal can directly obtain the main process corresponding to the task in the system of the terminal based on the object identifier of the task in the task request, and one object identifier corresponds to one main process. Figure 6 , Figure 6This is a flowchart of a hot start task processing method provided by an embodiment of the present application. The display interface of the terminal sends a task request for starting the task to the AMS component. When the AMS component of the terminal receives the task request, the AMS component detects whether there is a main process corresponding to the object identifier in the system of the terminal. When the AMS component detects the main process in the system of the terminal, it means that the terminal has detected that the application has been started. The terminal calls a start process and sends a main process acquisition request to Zygote through the start process. The main process acquisition request carries the QoS level of the task and the object identifier in the task request. The Zygote obtains the main process corresponding to the task request through the process acquisition request. The terminal switches the application corresponding to the object identifier from the background to the foreground, and displays the content of the application on the display interface of the terminal.
[0166] It should be noted that the above method 1 for determining the main process of the application is performed in a scenario where the application has been started.
[0167] Mode 2: When the terminal detects that there is no main process corresponding to the task request, the terminal creates a main process corresponding to the task request.
[0168] The terminal may create a main process corresponding to the task request based on the task identifier and object identifier of the task in the task request. Figure 7 , Figure 7 It is a flowchart of a cold start task processing method provided by an embodiment of the present application. The display interface of the terminal sends a task request to the AMS component to start the task. When the AMS component of the terminal receives the task request, the AMS component detects whether there is a main process corresponding to the object identifier in the system of the terminal. When the AMS component cannot detect the main process in the system of the terminal, it means that the application has not been started. The terminal calls startprocess, and the terminal sends a main process creation request to Zygote through startprocess. The main process creation request carries the QoS level of the task, the cold start identifier, and the object identifier in the task request. The cold start identifier is used to indicate that the main process to be created is used for cold start. The cold start identifier can be stored in the extended start process parameter field. The Zygote creates a main process corresponding to the task request based on the main process creation request. The embodiment of the present application does not specifically limit the representation form of the cold start identifier.
[0169] It should be noted that the terminal can also obtain the main process corresponding to the task request based on other methods. The embodiment of the present application does not limit other methods of obtaining the main process, and the main process of the application is determined by method 2 in a scenario where the application is not started.
[0170] The terminal can perform this step 5041 through Zygote. The QoS level of the main process is determined by the QoS level of the task to be processed by the main process. Figure 7 When the Zygote creates the main process based on the main process creation request, and the main process is currently used to process the task request, the Zygote configures the QoS level in the main process creation request as the QoS level of the main process.
[0171] It should be noted that different task requests correspond to different task quality levels. Therefore, when the terminal processes different task requests through the first thread of the application, the service quality level of the first thread corresponds to the different task quality levels. The foreground running state of the application is different. The foreground running state includes the startup state, the running state and the sliding state. Among them, the startup state is used to indicate that the application is in the startup process, the running state is used to indicate that the application is running, and the sliding state is used to indicate that the application slides on the display interface of the terminal. See Figure 7 When the content in the application corresponding to the object identifier in the main process acquisition request is displayed on the display interface, it means that the task of starting the application by the terminal has been completed, and the application is not in the startup state. When the application is in the running state, the terminal can reconfigure the QoS level of the main process of the application and the QoS level of the thread. For example, in the rendering scenario, the QoS level of the rendering task of an application is configured to be 2, the QoS level of the startup task is 3, and the QoS level of the background running task is 0. In this way, when the terminal is in the startup state, the service quality level of the main process is configured to 3 (that is, the same as the startup task). When the terminal starts the rendering task, the Zygote configures the QoS level of the main process and the rendering process to 2 (that is, the same as the rendering task).
[0172] It should be noted that when processing the task, if the application is switched from foreground operation to background operation, the terminal configures the service quality level of the thread corresponding to the application and the task to the first target level, wherein the first target level can be any lower level of the service quality level, such as level 0 in Table 1, and the embodiment of the present application does not specifically limit the first target level. It should be noted that when the terminal processes the task request, it switches the application corresponding to the task request from foreground operation to background operation, and the terminal only configures the service quality level of the thread corresponding to the task request, and does not configure the service quality level of the thread corresponding to other task requests.
[0173] In a possible implementation, when processing the task corresponding to the task request, if the terminal detects that any application program is switched from the foreground to the background, the terminal configures the QoS level of the main process or thread of the application program to zero through Zygote, wherein the main process or thread of the application program corresponds to the task request. Figure 6 For example, when the content in the application is displayed on the display interface, it means that the application originally displayed on the display interface switches from foreground running to background running. Then, the terminal configures the QoS level of the thread corresponding to the task request to zero through Zygote, and configures the thread corresponding to other task requests running in the foreground to 2.
[0174] Step 5042: When the main process of the application uses any thread to execute the subtask corresponding to the task request, the terminal configures the service quality level of the thread as the service quality level of the task.
[0175] Among them, any thread used by the main process can be any thread within the main process, or any thread called by the main process, and when any thread processes the subtask corresponding to the task request by calling other threads, the terminal configures the service quality level of the other threads as the service quality level of any thread.
[0176] In one possible implementation, the main process created by Zygote based on the main process creation request is a UI thread. The UI thread creates a Render thread during startup. When Zygote detects that the Render thread has been created, the Zygote configures the QoS level of the Render thread to the QoS level of the UI thread.
[0177] In one possible implementation, when the main process is executing, it can send a thread call request to the Binder driver in the terminal according to the Binder synchronous call mechanism. When the Binder driver determines the target thread called by the main process, the terminal configures the service quality level of the target thread as the service quality level of the main process through the main process. When the terminal completes executing the target thread, the target thread sends the execution result to the main process through the Binder driver, and the target thread updates its own service quality level to its original QoS level.
[0178] It should be noted that any thread used by the main process can also call other threads. When any thread calls other threads, the terminal configures the QoS level of other threads as the service quality level of any thread. In a possible implementation, when the thread calls other threads, the service quality level of the other threads is configured as the service quality level of the task in the service quality level field in the thread control block structure of the other threads.
[0179] See also Figure 8 , Figure 8 : This is a flowchart of a synchronization service quality level provided by an embodiment of the present application. Thread A sends a Binder request to the Binder driver, wherein the service quality level of thread A is 3, and the Binder request is also a thread call request. In the binder_transaction function in the Binder driver, the Binder thread is selected as the target thread to be called. The Binder thread is any thread that can be called by thread A. When the Binder thread is not called, the Binder thread is in sleep mode, and its service quality level is 0. When the Binder thread is called by thread A, thread A configures the QoS level of the Binder thread from 0 to 3 (that is, the QoS level of thread A). When the Binder thread is running, the QoS level of the Binder thread is 3. When the terminal executes the Binder thread, the terminal does not execute thread A temporarily, and thread A is in sleep mode. When the Binder thread is executed, the Binder thread sends the execution result to thread A through the Binder driver, and the Binder thread configures its own QoS level to the original QoS level 0. After thread A receives the execution result, the terminal continues to execute thread A.
[0180] 505. The terminal processes the subtask corresponding to the first thread based on the processing order corresponding to the service quality level of the first thread.
[0181] When processing the task request, the terminal may generate multiple subtasks of the task, and the terminal may use at least one thread or at least one process to complete the multiple subtasks, with each thread being used to complete part of the multiple subtasks.
[0182] The processing order can be determined by the service quality level of the first thread. In one possible implementation, the subtask is inserted into the processing queue before the subtask whose service quality level is lower than the service quality level of the first thread or has no service quality level, and the subtask corresponding to the first thread is processed according to the order in the processing queue.
[0183] When there are multiple types of thread priorities, the QoS class priority is higher than other types of priorities. The QoS class priority is the priority expressed by the QoS level. For example, the priority types include first in first out (FIFO) class priority and QoS class priority. Among them, the FIFO class priority follows the first in first out principle, that is, any subtask of a thread carrying FIFO priority enters the processing queue first, and the terminal prioritizes the subtask that enters the processing queue first compared to the subtask of the thread carrying FIFO priority. When the threads corresponding to the subtasks in the processing queue have the same type of priority, the terminal prioritizes the subtask of the thread with the highest level.
[0184] Then, by configuring the same QoS level for the main process and the threads related to the task, the QoS level of all threads and processes used by the terminal when processing the task request can be the same, so that all threads used to process subtasks can be queued in the queue based on the same QoS level, thereby avoiding the problem of long queuing time due to the low priority of any called thread, thereby avoiding the jamming caused by this problem when processing the task.
[0185] After the terminal obtains the subtask corresponding to the first thread in the processing queue, it can process the subtask corresponding to the first thread. In a possible implementation, when the subtask corresponding to the first thread is at the head of the processing queue, the terminal obtains the subtask corresponding to the first thread and processes the subtask corresponding to the first thread. When the terminal is processing the subtask, the subtask is dequeued from the processing queue, and when the terminal finishes processing the subtask, the terminal obtains the subtask of the next thread at the head of the processing queue.
[0186] It should be noted that when the terminal finishes executing all threads related to the task request, it means that the terminal has completed processing the task request.
[0187] 506. When the target resource of the subtask has been locked, the terminal configures the service quality level of the second thread as the service quality level of the first thread, and the second thread is the thread that locks the target resource.
[0188] It should be noted that, when the original QoS level of the second thread is lower than the QoS level of the first thread, the terminal executes step 506 ; otherwise, the terminal does not execute step 506 .
[0189] In a possible implementation, the terminal may complete step 507 through the process shown in steps 506A-506C below.
[0190] Step 506A: When executing the subtask corresponding to the first thread, the terminal locks the target resource.
[0191] The terminal may perform step 507A through the first thread. Before locking the target resource, the terminal will detect the target resource. When the target resource is in a locked state, the first thread cannot lock the target resource. When the terminal detects that the target resource is in an unlocked state, the first thread may lock the target resource. The locked state indicates that the target resource is locked, and the unlocked state indicates that the target resource is unlocked.
[0192] Step 506B: When locking the target resource fails, the terminal determines the second thread.
[0193] The terminal may perform step 506B through the first thread. When the first thread detects that the state of the target resource is locked, that is, the first thread fails to lock the target resource.
[0194] The terminal can determine the second thread through the target function. In a possible implementation, the terminal determines the second thread through the lock object and the target function. The lock object is the memory data of the lock on the target resource. The memory data stores information that can indicate the first thread. The target function is used to obtain the information of the second thread stored in the memory data of the lock object. For example, if the lock on the target resource is a mutex lock, the terminal can determine the second thread through the target function mutex_lock(A), where A is the lock object and A stores information indicating the second thread. For another example, if the lock on the target resource is a read-write semaphore, the terminal can determine the second thread through the target function rwsem(B), where B is the lock object and B stores information indicating the second thread.
[0195] Step 506C: When the service quality level of the second thread is lower than the service quality level of the first thread, the terminal updates the service quality level of the second thread to the service quality level of the first thread.
[0196] The terminal may perform step 506C through the first thread. The first thread updates the service quality level of the second thread by updating the content in the service quality level field of the thread control block structure of the second thread. In a possible implementation, in the service quality level field of the thread control block structure of the second thread, the first thread configures the service quality level of the second thread as the service quality level of the first thread.
[0197] By updating the service quality level of the second thread to the service quality level of the first thread, the service quality level of the second thread can be made the same as the service quality level of the first thread, so that when the second thread releases the lock of the target resource, the first thread can immediately lock the target resource.
[0198] 507. When the second thread releases the lock of the target resource, the terminal processes the subtask corresponding to the first thread based on the target resource.
[0199] The terminal can execute this step 507 through the first thread. When the first thread fails to lock, the terminal waits in the waiting queue of the target resource based on the service quality level of the first thread. When the second thread releases the lock of the target resource, the first thread processes the subtask corresponding to the first thread based on the target resource. The waiting queue of the target resource is used to store each thread for storing the target resource to be processed.
[0200] Among them, the process of the first thread queuing and waiting in the waiting queue of the target resource based on the service quality level of the first thread is the same as the process of the subtask of the first thread queuing and waiting in the processing queue. Here, the embodiment of the present application does not elaborate on the process of the first thread queuing and waiting in the waiting queue of the target resource based on the service quality level of the first thread.
[0201] In a possible implementation, step 507 may be implemented through the process shown in steps 507A-507B below.
[0202] Step 507A: After the second thread releases the lock of the target resource, the terminal locks the target resource according to the order in the waiting queue of the target resource and restores the original service quality level of the second thread. The waiting queue of the target resource is used to store threads to be processed by the target resource.
[0203] The terminal may lock the target resource through the first thread, and may restore the original service quality level of the second thread through the second thread, wherein the original service quality level of the second thread is the service quality level before the first thread configures the service quality level of the second thread.
[0204] When any thread releases the lock of the resource, a thread that is behind the any thread in the waiting queue of the target resource and adjacent to the any thread locks the target resource. In a possible implementation, when the first thread updates the state of the target resource to a locked state, the first thread successfully locks the target resource.
[0205] When the QoS level of the second thread is low, or there is no QoS level, if the QoS level of the second thread is not reconfigured, then after the second thread releases the lock, the threads of the same level as the second thread will lock the target resource, and the first thread needs to wait in the queue of the target resource until the locks held by the threads with low QoS levels are released. Only then can the first thread lock the target resource according to its position in the waiting queue, resulting in a priority inversion. When the terminal configures the QoS level of the second thread to the same QoS level as the first thread, because the second thread currently holds the lock, then when the first thread is queued in the waiting queue, it is adjacent to the second thread and can also be considered to be at the head of the waiting queue. After the second thread releases the lock, the first thread can immediately lock the target resource, thereby avoiding the priority inversion.
[0206] Step 507B: After locking the target resource, the terminal processes the subtask based on the target resource.
[0207] The terminal can execute this step 507B through the first thread. When the first thread is executing the task request, if it is necessary to perform target processing on the target resource, then after the first thread locks the target resource, the first thread can perform target processing on the target resource. The target processing can be any processing method, for example, reading data or writing data.
[0208] To further illustrate the process shown in steps 506-507, see Fig. 9 , Fig. 9 is a flowchart of a synchronous mutex lock provided by an embodiment of the present application. Fig. 9It can be seen that the current QoS level of thread A is 3. When thread A fails to add a mutex lock to the target resource, according to the target resource, thread A can find the second thread through the mutex_lock function. The second thread is thread B. Thread A sets the content in the QoS field in the thread control block of thread B to the content in the QoS field in the thread control block of thread A, that is, sets the QoS level of thread B to 3; thread A queues in the waiting queue of the target resource according to its own QoS level; when thread B releases the lock, thread B modifies the content in the QoS field in its own thread control block to the original content, thread A locks the target resource, and processes the subtask corresponding to thread A based on the target resource.
[0209] Fig. 9 To synchronize the mutex lock process, in some embodiments, the terminal can also synchronize the reading and writing of semaphores, see Fig.10 , Fig.10 This is a flow chart of a synchronous read and write signal provided by an embodiment of the present application. Fig.10 It can be seen that the current QoS level of thread A is 3. When thread A fails to add a read-write semaphore to the target resource, thread A can find the second thread through the rwsem function. The second thread is thread B. Thread A sets the content of the QoS field in the thread control block of thread B to the content of the QoS field in the thread control block of thread A, that is, the QoS level of thread B is set to 3; thread A queues in the waiting queue according to its own QoS level; when thread B releases the lock, thread B modifies the content of the QoS field in its own thread control block to the original content. Since for any lock resource with a read-write semaphore, multiple read requests or one write request can be processed simultaneously, steps 506-507 can be omitted when processing a read request.
[0210] To further illustrate the process shown in steps 501-507, see Fig.11 , Fig.11 It is a schematic diagram of a task processing process based on the Android system architecture provided in an embodiment of the present application. Fig.11 Used to illustrate the process of transferring service quality levels between different software layers of the system, such as Fig.11 As shown, the UI thread transmits the service quality level to other threads in the application through the IPC mechanism, and the execution segments corresponding to other threads are marked the same as those of the UI thread. When the IPC dependency is released, the thread restores the service quality level and the marking of the execution segment is restored. Fig.11The two processes in the figure are used to illustrate the process of the terminal transmitting the service quality level when a thread call occurs or the target resource is locked during thread execution. Process 1 is the process of transmitting the service quality level when the service quality level is 2, and process 2 is the process of transmitting the service quality level when the service quality level is 1. Process 1 includes the following steps 1.1-1.6.
[0211] Step 1.1: The UI thread of the foreground application is a delay-sensitive thread. The terminal configures the service quality level of the delay-sensitive thread to QoS=2, that is, configures the service quality level of the UI thread to 2.
[0212] Step 1.2, the UI thread calls the thread through the IPC synchronization request in the Binder system. The called thread is the thread used in the execution process of the UI thread, such as the Binder thread in the Android core service. When the Binder thread is determined, the UI thread configures the service quality level of the Binder thread to 2. When the Binder thread needs to call the thread in the application management service during the calling process, the Binder thread configures the service quality level of the called thread to 2. When the Binder thread calls the thread, the thread returns to the original service quality level. When the UI thread calls the Binder thread, the Binder thread returns to the original service quality level.
[0213] Step 1.3: When the UI thread calls the application custom service Binder thread through an IPC synchronization request, the UI thread configures the service quality level of the application custom service Binder thread to 2. After the call is completed, the application custom service Binder thread returns to the original service quality level.
[0214] Step 1.4, the UI thread can also call the logical thread, and the UI thread configures the service quality level of the logical thread to 2. When the logical thread is being called, the logical thread needs to use the target resource indicated by the user state lock, but the application custom service Binder thread holds the user state lock. The logical thread configures the service quality level of the application custom service Binder thread to 2. After the application custom service Binder thread releases the lock, the logical thread locks the target resource, and the application custom service Binder thread restores the original service quality level.
[0215] Step 1.5: When the Binder thread calls a thread in the application management service, if the thread needs to use the target resource indicated by the Java lock during the calling process, but other threads in the application management service hold the Java lock, the called thread configures the service quality level of the other threads to 2. After the other threads release the Java lock, the thread locks the target resource and the other threads return to the original service quality level.
[0216] Step 1.6: When the thread in the application management service calls the driver through a system call, if the driver is locked, the thread will configure the service quality level of the thread that locked the driver to 2. When the thread that locked the driver releases the lock, the thread in the application management service locks the driver, and the locking thread returns to the original service quality level.
[0217] The above is a description of process 1, and process 2 includes the following steps 2.1-2.5.
[0218] Step 2.1: The terminal configures the service quality level of the drawing rendering thread to 1.
[0219] Step 2.2: When the drawing and rendering thread calls the Binder thread in the Android core service through an IPC synchronization request, the drawing and rendering thread configures the service quality level of the Binder thread to 1. After the call to the Binder thread ends, the Binder thread restores the original service quality level.
[0220] Step 2.3: When the Binder thread calls the thread in SF through the IPC synchronization request during the calling process, the Binder thread configures the service quality level of the thread in SF to 1. After the call to the thread in SF is completed, the thread in SF restores the original service quality level.
[0221] Step 2.4: When the terminal needs to use the target resource indicated by the user state lock during the execution of the drawing and rendering thread, the logical thread has locked the target resource, and the drawing and rendering thread configures the service quality level of the logical thread to 1. After the logical thread releases the lock, the drawing and rendering thread locks the target resource, and the logical thread restores the original service quality level.
[0222] Step 2.5: When the terminal executes the drawing and rendering thread and calls the memory resource through the system call, if the memory resource is locked, the drawing and rendering thread configures the service quality level of the thread that locks the memory resource to 1. When the thread that locks the memory resource releases the lock, the drawing and rendering thread locks the memory resource, and the locking thread returns to the original service quality level.
[0223] To further illustrate Figure 8-10 The process shown in FIG. 1 is shown in FIG. 1 , and the embodiment of the present application provides Fig.12 The flowchart of the service quality level transmission in the sliding scenario shown in the figure mainly includes the following steps 1-6:
[0224] Step 1. After the terminal receives the sliding operation, the terminal will receive the sliding task, that is, switching the application from the background to the foreground. When the terminal processes the sliding task, the service quality level of the UI thread of the application is set to 3. Since the service quality level is low when the application is running in the background, the service quality level of the thread of the application running in the background is 2. When the thread is sleeping, the service quality level of the sleeping thread is 2. The service quality level of Binder thread A is 2 when it is dormant. When the UI thread calls Binder thread A in the system service through Binder synchronously, the UI thread updates the service quality level of Binder thread A from 2 to 3. Since the UI thread is calling Binder thread A at this time, the UI thread is in a sleeping state.
[0225] Step 2: When Binder thread A needs to use the lock resource indicated by the user-state lock during execution, but the lock-holding thread holds the user-state lock and the service quality level of the lock-holding thread is 2, Binder thread A updates the service quality level of the lock-holding thread to 3, and Binder thread A is in a sleep state.
[0226] Step 3: After the lock-holding thread releases the user-mode lock, the lock-holding thread restores the original service quality level 2 and wakes up the Binder thread A.
[0227] Other threads may also need to acquire the user-mode lock at the same time, for example Fig.12 The lock contention thread in the QoS level is 2. However, the user state lock is held by the lock holding thread. At this time, the lock contention thread is in a dormant state. If the lock holding thread releases the lock and wakes up the lock contention thread, the original QoS level of the lock contention thread is 2.
[0228] Step 4: After Binder thread A obtains the user state lock, it continues to execute according to service quality level 3.
[0229] Step 5: When the UI thread is executing, it needs to call the resources in the kernel. If the resources have been locked by the kernel thread and the service quality level of the kernel thread is 2, the UI thread updates the service quality level of the kernel thread to 3, and the UI thread is in sleep state.
[0230] Step 6: After the kernel thread releases the lock, the kernel thread wakes up the UI thread, and the kernel thread returns to the original service quality level 3.
[0231] 508. When the first thread calls the third thread, the terminal adjusts the service quality levels of the first thread and the third thread according to the amount of data of the first thread cached in the third thread.
[0232] The third thread is any thread called by the first thread. The terminal can count the amount of data of the first thread cached in the third thread every preset time, and the terminal adjusts the QoS level of the first thread and the third thread based on the relationship between the statistical amount of data of the first thread and the data amount threshold. In a possible implementation, when the amount of data of the first thread cached in the third thread is less than the data amount threshold, the terminal keeps the QoS level of the first thread and the third thread unchanged; when the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the terminal reduces the QoS level of the first thread.
[0233] To further explain this step 508, see Fig.13 , Fig.13 A model for dynamically adjusting the QoS level of a thread in a rendering scenario provided in an embodiment of the present application.
[0234] from Fig.13 It can be seen that the drawing and rendering model of the foreground application on the terminal system is a pipeline model. The UI thread and Render thread of the application are upstream producers, which are used to produce rendering data. The Render thread sends the produced rendering data to SF through Binder. Relative to the application, SF is a downstream consumer, whose role is to synthesize various layers. SF sends the data of the synthesized layers to HWC. For HWC, SF is a producer and HWC is a consumer.
[0235] Before the terminal executes the QoS level of the UI thread and the Render thread of the application, the terminal has already configured the QoS level of the UI thread and the Render thread. Assuming that the QoS level of the UI thread and the Render thread is 2, when the amount of rendering data cached in the SF is less than the data volume threshold, the terminal keeps the QoS level of the SF and the Render thread unchanged, that is, 2. When the amount of rendering data cached in the SF is equal to or greater than the data volume threshold, it means that the consumer SF consumes too slowly or the Render thread produces too quickly, and the terminal reduces the QoS level of the Render thread to 1.
[0236] When the terminal executes the first thread too fast, the first thread uses too many resources and generates too many data resources, thereby causing unnecessary power consumption. When the terminal executes the first thread too slowly, the first thread generates too few data resources, which are not enough for the lower-level threads. By dynamically adjusting the QoS level of the thread through step 508, the terminal can execute the first thread at the most appropriate speed, thus avoiding the situation where the first thread causes unnecessary power consumption or is not enough for the lower-level threads when using system resources.
[0237] In one possible implementation, when the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is less than a data amount threshold, the terminal improves the service quality level of the first thread; when the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the terminal improves the service quality level of the third thread.
[0238] Then, when the amount of data of the thread cached in the third thread is less than the data amount threshold, the terminal increases the service quality level of the first thread, so that the data amount of the first thread in the third thread reaches the data amount threshold. Then, when the third thread is suddenly consumed too fast, it can be avoided that the data amount of the first thread in the third thread cannot keep up with the consumption progress.
[0239] When the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the terminal improves the service quality level of the third thread, thereby accelerating the consumption of the amount of data of the first thread cached in the third thread, thereby avoiding the accumulation of data generated by the first thread in the third thread.
[0240] It should be noted that the terminal may continuously execute step 508 when processing the task request, so as to adjust the QoS level of each thread when processing the task request at any time.
[0241] 509. When the first thread fails to apply for memory resources and the service quality level of the first thread is greater than the second target level, the terminal allocates memory resources to the first thread from the reserved memory resources.
[0242] The second target level may be a level with a higher service quality, for example, the second target level is level 2. The embodiment of the present application does not specifically limit the second target level.
[0243] The reserved memory resources are memory resources reserved in advance by the terminal for emergency use. In a possible implementation, when the terminal is initializing memory resources, the terminal sets part of the terminal's memory resources as reserved memory resources so that threads with higher service quality levels can directly use the reserved memory resources.
[0244] When the terminal needs memory resources to store data required or generated during the execution of the first thread when executing the first thread, the first thread will apply for memory resources from the terminal. When the memory provided for the thread in the terminal is fully occupied and the service quality level of the first thread is greater than the second target level, the first thread fails to apply for memory resources. At this time, the terminal can allocate memory resources to the first thread from the reserved memory resources, so that the first thread can use the allocated memory resources, thereby avoiding the first thread waiting for memory resources to be released. The terminal can then allocate memory resources to the first thread from the released memory resources, thereby improving the efficiency of processing the first thread, because the first thread is a thread with a higher service quality level, which can improve the efficiency of processing tasks.
[0245] The method provided by the embodiment of the present application sets the service quality level of the task, which is related to the user perception, and configures the priority of the thread executing the task as the service quality level of the task, and the priority of the thread is used to indicate the execution order of the thread in the system. Through such a method, the execution order of the thread conforms to the service quality level of the task. In this way, the higher the service quality level of the task (i.e., the stronger the user perception of the task), the faster it is executed, so that the jamming phenomenon caused by the long task processing time can be avoided to a certain extent. In addition, the QoS level of the thread executed by the terminal when processing the task request is dynamically adjusted, so that the terminal can execute the first thread at the most appropriate speed, and can never avoid the first thread from causing unnecessary power consumption when using the system resources, or not enough for the lower-level threads. In addition, when the first thread obtains memory resources from the reserved memory resources, the efficiency of processing tasks can be improved.
[0246] Fig.14 : is a structural device diagram of a task processing device provided in an embodiment of the present application, the device comprising:
[0247] Receiving module 1401, used to execute the above step 502;
[0248] Acquisition module 1402, used to execute the above step 503;
[0249] A first configuration module 1403, configured to execute the above step 504;
[0250] The first processing module 1404 is used to execute the above step 505.
[0251] Optionally, the first processing module 1404 is configured to insert the subtask into the processing queue before a subtask having a lower QoS level than the thread or having no QoS level, and process the subtask in an order in the processing queue.
[0252] Optionally, the first processing module 1404 further includes:
[0253] A configuration unit, configured to execute the above step 506;
[0254] The processing unit is used to execute the above step 507.
[0255] Optionally, the configuration unit is used to perform the above steps 506A-506C.
[0256] Optionally, the processing unit is used for the above steps 507A-507B.
[0257] Optionally, the device further comprises:
[0258] The adjustment module is used to execute step 508.
[0259] Optionally, the adjustment module is used to:
[0260] When the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is less than a data amount threshold, keeping the service quality levels of the first thread and the third thread unchanged;
[0261] When the first process calls the third thread, if the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the service quality level of the first thread is reduced.
[0262] Optionally, the adjustment module is used to:
[0263] When the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is less than a data amount threshold, improving the service quality level of the first thread;
[0264] When the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the service quality level of the third thread is increased.
[0265] Optionally, the service quality level of the task is determined by the task characteristics of the task
[0266] Optionally, the device further comprises:
[0267] The second configuration module is used to configure the service quality level of the thread corresponding to the task to the first target level if the application is switched from foreground operation to background operation when processing the task.
[0268] Optionally, the first configuration module is used to configure the service quality level field in the thread control block structure of the first thread to be the service quality level of the task, and the thread control block structure is used to store thread information.
[0269] Optionally, the device further comprises:
[0270] The allocation module is used to execute the above step 509.
[0271] Optionally, the device further comprises:
[0272] The corresponding module is used for different task requests corresponding to different task quality levels.
[0273] All the above optional technical solutions can be arbitrarily combined to form optional embodiments of the present disclosure, and will not be described in detail here.
[0274] It should be noted that: the above embodiment provides a task processing device, and only uses the division of the above functional modules as an example to illustrate when performing task processing. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the task processing device and the task processing method embodiment provided in the above embodiment belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0275] In addition, the present application provides a computer program product (or computer program), in which at least one instruction is stored, and the instruction is loaded and executed by a processor to implement the operations performed by the above-mentioned task processing method.
[0276] In summary, the solution provided by this application defines the QoS level related to the task according to the importance of the task, and sets the QoS level to the QoS level of the thread that implements the task, thereby improving the execution efficiency of important tasks. Furthermore, the thread QoS level is transferred between threads according to the synchronous IPC call (Binder, Socket and other mechanisms) and lock dependency in the system, and the threads on the thread dependency chain can ensure QoS consistency and avoid reversal and loss. Furthermore, the QoS is adjusted in reverse based on the consumer model drawn by the current system to avoid excessive supply of resources and power consumption overhead.
[0277] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0278] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A task processing method, characterized in that: The method comprises: The terminal receives a task request, the task request is used to instruct processing of a task related to the application; wherein the task is a service provided by the terminal through the application, the task includes a startup task, a sliding task or a rendering task, and can be perceived by the user; Based on the task request, the terminal obtains a priority corresponding to the task; When a first thread is used to process a subtask corresponding to the task request, the terminal configures the priority of the first thread as the priority of the task; Based on the processing order corresponding to the priority of the first thread, the terminal processes the subtask corresponding to the first thread.
2. The method according to claim 1, characterized in that The processing order corresponding to the priority of the first thread includes: processing the subtask corresponding to the first thread. The subtask is inserted into the processing queue before a subtask whose priority is lower than the priority of the thread or has no priority, and the subtask is processed according to the order in the processing queue.
3. The method according to any one of claims 1 to 2, characterized in that: The subtask of processing the first thread includes: When the target resource of the subtask has been locked, configuring the priority of the second thread to be the priority of the first thread, the second thread being the thread that locks the target resource; When the second thread releases the lock of the target resource, the subtask is processed based on the target resource.
4. The method according to claim 3, characterized in that When the target resource of the subtask is locked, configuring the priority of the second thread to be the priority of the first thread includes: When executing the subtask corresponding to the first thread, locking the target resource; When locking the target resource fails, determining the second thread; When the priority of the second thread is lower than the priority of the first thread, the priority of the second thread is updated to the priority of the first thread.
5. The method according to claim 3, characterized in that: When the second thread releases the lock of the target resource, processing the subtask based on the target resource includes: After the second thread releases the lock of the target resource, the target resource is locked according to the order in the waiting queue of the target resource, and the original priority of the second thread is restored. The waiting queue of the target resource is used to store threads to be processed for the target resource; After locking the target resource, the subtask is processed based on the target resource.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: When the first thread calls the third thread, the priorities of the first thread and the third thread are adjusted according to the amount of data of the first thread cached in the third thread.
7. The method according to claim 6, characterized in that When the first thread calls the third thread, adjusting the priorities of the first thread and the third thread according to the amount of data of the first thread cached in the third thread includes: When the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is less than a data amount threshold, keeping the priorities of the first thread and the third thread unchanged; When the first process calls the third thread, if the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the priority of the first thread is reduced.
8. The method according to claim 6, characterized in that When the first thread calls the third thread, adjusting the priorities of the first thread and the third thread according to the amount of data of the first thread cached in the third thread includes: When the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is less than a data amount threshold, increasing the priority of the first thread; When the first thread calls the third thread, if the amount of data of the first thread cached in the third thread is equal to or greater than the data amount threshold, the priority of the third thread is increased.
9. The method according to any one of claims 1 to 8, characterized in that: The method further comprises: When processing the task, if the application is switched from foreground operation to background operation, the priority of the thread corresponding to the task is configured as the first target level.
10. The method according to any one of claims 1 to 9, characterized in that: Said configuring the priority of the first thread as the priority of the task comprises: The priority field in the thread control block structure of the first thread is configured as the priority of the task, and the thread control block structure is used to store thread information.
11. The method according to any one of claims 1 to 10, characterized in that: The method further comprises: The service quality level of the task is set, and the priority of the thread executing the task is configured as the service quality level of the task; wherein the service quality level of the task is related to user perception.
12. A task processing method, characterized in that: The method comprises: The terminal receives a task request, wherein the task request is used to instruct processing of a task related to an application program; wherein the task is a service provided by the terminal through the application program; Based on the task request, the terminal determines the priority corresponding to the task through machine learning; wherein the corresponding priority is related to user perception; When a first thread is used to process a subtask corresponding to the task request, the terminal configures the priority of the first thread as the priority of the task; Based on the processing order corresponding to the priority of the first thread, the terminal processes the subtask corresponding to the first thread.
13. The method according to claim 12, characterized in that The task includes at least one of the following: a task related to reliability experience, a task related to interaction, a task related to rendering, a default task, and a task running in the background.
14. A task processing method, characterized in that: The method comprises: The terminal receives a task request, wherein the task request is used to instruct processing of a task related to an application program; wherein the task is a service provided by the terminal through the application program; Based on the task request, the terminal obtains a priority corresponding to the task; When multiple threads are used to process the subtasks corresponding to the task request, the terminal configures the priorities of the multiple threads as the priority of the task; Based on the processing order corresponding to the priorities of the multiple threads, the terminal processes the subtasks corresponding to the multiple threads.
15. The method according to claim 14, characterized in that The terminal configures the priorities of the plurality of threads as the priorities of the task, including: The terminal increases the priority of a background thread among the plurality of threads.
16. A task processing method, characterized in that: The method comprises: The terminal receives the task request; Based on the task request, the terminal obtains a priority corresponding to the task request, or obtains a priority corresponding to the task corresponding to the task request; When multiple threads are used to process the subtasks corresponding to the task request, the terminal configures the priorities of the multiple threads as the priorities of the task, and the multiple threads belong to at least two applications; The terminal processes the subtasks corresponding to the plurality of threads based on a processing order corresponding to the priorities of the plurality of threads.
17. The method according to claim 16, characterized in that The method further comprises: The plurality of threads include a first thread and a second thread, wherein the first thread calls the second thread; The first thread transfers the priority of the first thread to the second thread through the binder mechanism.
18. The method according to claim 16, characterized in that The method further comprises: When a first thread among the multiple threads determines that the target resource is locked when accessing the target resource, the terminal configures the priority of the thread that locks the target resource to the priority of the first thread.
19. A terminal, characterized in that: The terminal includes one or more processors and one or more memories, wherein the one or more memories store at least one instruction, and the instruction is executed by the one or more processors to implement the task processing method according to any one of claims 1 to 18.
20. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, and the instruction is executed by the processor to implement the task processing method according to any one of claims 1 to 18.
