Thread scheduling method and device

By delaying restoring the processing priority of the binder thread, the problem of binder threads being unable to be scheduled in time in terminal devices is solved, which improves task processing efficiency and reduces screen lag.

CN119045981APending Publication Date: 2024-11-29HONOR DEVICE CO LTD
View PDF 0 Cites 3 Cited by

Patent Information

Application Number
CN202310623835.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-05-29
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

In the prior art, the binder thread of the terminal device cannot be scheduled in time, resulting in the terminal device being unable to process new tasks in time and the screen is stuttered.

Method used

By delaying restoring the processing priority of the binder thread, ensuring priority recovery before the next task starts, thereby reducing the time when the binder thread is in the runnable state and improving task processing efficiency.

Benefits of technology

It effectively solves the long-term runnable problem caused by priority recovery of binder threads, improves the task processing efficiency of terminal devices, and reduces picture lag.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045981A_ABST
    Figure CN119045981A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a thread scheduling method and device.The method comprises the steps that at the first moment, in response to a first instruction, terminal equipment modifies the processing priority of a second thread from a first priority to a second priority before executing a first task on the basis of the first instruction, the processing priority of the second priority is higher than the processing priority of the first priority, the second thread carries a first identifier after the first moment, the first identifier is used for indicating that the second thread is in a priority improvement state, and the first instruction is an instruction corresponding to the first task; the terminal equipment executes the first task based on a second thread with a second priority; and at the second moment, when the terminal equipment determines that no to-be-executed task exists in the second thread and the second thread carries the first identifier, the terminal equipment does not recover the processing priority of the second thread. In this way, the terminal equipment can delay recovery of the processing priority of the second thread so as to reduce runnable situations of the second thread.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of terminal technology, and in particular to a thread scheduling method and device. Background Art

[0002] With the development of terminal technology, terminal devices have become important tools in people's lives. Terminal devices need to perform multiple tasks. For example, when processing a task, the terminal device will cache the task data in the cache area and process the task based on the task data in the cache area; then, after processing the task, the terminal device releases the task data in the cache area.

[0003] In the prior art, a terminal device releases task data in a cache area based on a binder thread; the binder thread needs to wait to be scheduled before releasing the task data in the cache area.

[0004] However, the above thread scheduling method may result in the binder thread not being scheduled in time, causing the terminal device to be unable to process new tasks in time. Summary of the invention

[0005] The embodiments of the present application provide a thread scheduling method and apparatus, so that a terminal device can delay the recovery of the processing priority of a second thread to reduce the runnable situation of the second thread.

[0006] In the first aspect, the embodiment of the present application provides a thread scheduling method, which is applied to a terminal device, wherein a first process and a first thread are running in the terminal device, the first thread is a thread for processing tasks, the first process includes a second thread, the second thread is a binder thread, and the second thread includes: a first task, the method includes: at a first moment, in response to a first instruction, the terminal device modifies the processing priority of the second thread from the first priority to the second priority based on the first instruction before executing the first task, wherein the processing priority of the second priority is higher than the processing priority of the first priority, after the first moment, the second thread carries a first identifier, the first identifier is used to indicate that the second thread is in a state of priority enhancement, and the first instruction is an instruction corresponding to the first task shown; the terminal device executes the first task based on the second thread with the second priority; at a second moment, when the terminal device determines that there is no task to be executed in the second thread and the second thread carries the first identifier, the terminal device does not restore the processing priority of the second thread. In this way, the terminal device can delay the restoration of the processing priority of the second thread to reduce the runnable situation of the second thread.

[0007] In one possible implementation, the second thread also includes a second task. After the second moment, the method also includes: at a third moment, in response to the second instruction, when the terminal device determines based on the second instruction to change the processing priority of the second thread from the first priority to the second priority, and the terminal device is at the second priority after the second moment, the terminal device does not restore the processing priority of the second thread, and executes the second task based on the second thread with the second priority, and the second instruction is an instruction corresponding to the second task; or, when the terminal device determines based on the second instruction not to change the processing priority of the second thread from the first priority to the second priority, and the terminal device is at the second priority after the second moment, the terminal device restores the second priority to the first priority, and executes the second task based on the second thread with the first priority.

[0008] It is understandable that before the binder thread in the terminal device executes the next task, the binder driver can determine whether to restore the processing priority of the binder thread, so that the priority recovery process is delayed from the end of the current task to the start of the next task, so as to better solve the problem of long runnable caused by restoring the priority after the current task ends.

[0009] In a possible implementation, the second instruction includes one or more of the following: a binder communication number, an interface descriptor, or an asynchronous communication identifier, the binder communication number is used to indicate a communication interface, the interface descriptor is used to indicate a client and a server for communication, and the asynchronous communication identifier is used to indicate a communication method. The terminal device determines based on the second instruction to modify the processing priority of the second thread from the first priority to the second priority, including: when the second thread is determined based on the second instruction and the second thread meets a preset condition, the terminal device modifies the processing priority of the second thread from the first priority to the second priority, wherein the preset condition includes one or more of the following: the communication interface indicated by the binder communication number is a communication interface between the first thread and the second thread, the interface descriptor indicates that the client for communication is the first thread and the server for communication is the second thread, or the asynchronous communication identifier indicates that the first thread and the second thread are asynchronous binder communications. In this way, the terminal device can realize accurate identification of a certain fixed binder call, so that the terminal device can improve the accuracy of priority processing for the binder thread.

[0010] In a possible implementation, after the first moment and before the third moment, a third thread is running in the terminal device, the third thread is a thread of a binder call initiated by the second thread, and the third thread includes: a fourth task, and the method also includes: the terminal device inserts the third task into the queue executed by the second thread based on the third thread; in response to the third instruction, when the terminal device determines to restore the processing priority of the second thread based on the third instruction and the third task meets the preset first task type, the terminal device does not restore the processing priority of the second thread, and the third instruction is an instruction corresponding to the third task; the terminal device executes the third task based on the second thread with the second priority; the terminal device executes the fourth task. In this way, before executing the task, the binder driver in the terminal device can determine the processing priority of the binder call based on S703-S704, and filter out the preset tasks that make the binder thread restore the priority in advance, so as to reduce the binder thread in the runnable state.

[0011] In a possible implementation, the first task type includes: a task type used to indicate that a communication transaction is completed and handed over to the initiating end for processing, and / or a task type used to indicate that a communication transaction fails and is handed over to the initiating end for processing.

[0012] In a possible implementation, after the first moment and before the third moment, a fourth thread is running in the terminal device, the fourth thread is a thread of a synchronous binder call initiated by the second thread, the fourth thread includes: a fifth task, and the method also includes: after the terminal device executes the fifth task, the sixth task is inserted into the second thread, the sixth task is used to instruct the terminal device to complete the processing of the fifth task; in response to the fourth instruction, when the terminal device determines to restore the processing priority of the second thread based on the fourth instruction and the sixth task meets the preset second task type, the terminal device does not restore the processing priority of the second thread, the fourth instruction is the instruction corresponding to the sixth task; the terminal device executes the sixth task based on the second thread with the second priority; the terminal device executes the fifth task. In this way, before executing the task, the binder driver in the terminal device can determine the processing priority of the binder call based on S703-S704, filter out the preset tasks that make the binder thread restore the priority in advance, so as to reduce the binder thread in the runnable state.

[0013] In a possible implementation, the second task type includes: a task type replied by the server.

[0014] In one possible implementation, the first task is a task identified by the terminal device during an asynchronous binder call, and the second thread also includes: a seventh task, the seventh task is a task identified by the terminal device during a synchronous binder call, and before the second moment, the second thread carries a second identifier, the second identifier is used to indicate that the second thread is an asynchronous binder call, and before the second moment and after the first moment, the method also includes: at a fourth moment, in response to a fifth instruction, when the terminal device detects the seventh task and the second thread with the second identifier, the terminal device restores the processing priority of the second thread before executing the seventh task, and the fifth instruction is an instruction corresponding to the seventh task; at a fifth moment, the terminal device modifies the processing priority of the second thread from the first priority to the second priority, and processes the seventh task based on the second priority; at the fifth moment after the fourth moment, the second thread is in a synchronous binder call state in a first time period after the fifth moment, and the second thread is in an asynchronous binder call state between the fourth moment and the fifth moment. In this way, when the terminal device detects a conflict between the task identified by the synchronous binder and the task identified by the asynchronous binder, the processing priority of the asynchronous call is restored first, and then the processing priority of the synchronous call is improved. It can be understood that for a period of time after the binder driver improves the processing priority of the binder thread synchronous call, the binder thread follows the synchronous binder call scheme.

[0015] In a possible implementation, after the fifth moment, the method further includes: at a sixth moment, the terminal device restores the processing priority of the second thread, and the processing priority of the second thread is at the first priority in a second time period after the sixth moment.

[0016] In a possible implementation, the first thread is a thread for image synthesis, and the first process is a process for image drawing; or, the first process is a process for generating window data of window information, and the first thread is a thread for updating window information of the system.

[0017] In a second aspect, an embodiment of the present application provides a thread scheduling device, in which a first process and a first thread are running, the first thread is a thread for processing tasks, the first process includes a second thread, the second thread is a binder thread, and the second thread includes: a first task, a first moment, in response to a first instruction, a processing unit modifies the processing priority of the second thread from the first priority to the second priority based on the first instruction before executing the first task, wherein the processing priority of the second priority is higher than the processing priority of the first priority, and after the first moment, the second thread carries a first identifier, the first identifier is used to indicate that the second thread is in a state of increased priority, and the first instruction is an instruction corresponding to the first task shown; an execution unit, further used to execute the first task based on the second thread having the second priority; at a second moment, when the terminal device determines that there is no task to be executed in the second thread and the second thread carries the first identifier, the processing unit does not restore the processing priority of the second thread.

[0018] In a third aspect, an embodiment of the present application provides a terminal device, comprising: a processor and a memory, wherein the memory is used to store a computer program; the processor is used to call and execute the computer program so that the terminal device executes the method in the first aspect and any possible implementation thereof.

[0019] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium for storing a computer program. When the computer program is run on a computer, the computer executes the method in the first aspect and any possible implementation thereof.

[0020] In a fifth aspect, the present application provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the method in the first aspect and any possible implementation thereof.

[0021] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can refer to the beneficial effects of the first aspect and any possible implementation thereof, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 A schematic diagram of the hardware structure of a terminal device provided in an embodiment of the present application;

[0023] Figure 2 A schematic diagram of the software structure of a terminal device provided in an embodiment of the present application;

[0024] Figure 3 A schematic diagram of a process of displaying an image on a terminal device provided in an embodiment of the present application;

[0025] Figure 4A schematic diagram of a flow chart of an asynchronous binder call provided in an embodiment of the present application;

[0026] Figure 5 A flowchart of a method for increasing priority in an asynchronous binder call provided in an embodiment of the present application;

[0027] Figure 6 A schematic diagram of viewing a thread status from a trace tool provided in an embodiment of the present application;

[0028] Figure 7 A flowchart of a thread scheduling method provided in an embodiment of the present application;

[0029] Figure 8 Another schematic diagram of viewing thread status from a trace tool provided in an embodiment of the present application;

[0030] Fig. 9 A schematic diagram of viewing a thread status from a trace tool provided in another embodiment of the present application;

[0031] Fig.10 A schematic diagram of another method of viewing a thread status from a trace tool provided in an embodiment of the present application;

[0032] Fig.11 A schematic diagram of another method of viewing a thread status from a trace tool provided in an embodiment of the present application;

[0033] Fig.12 A schematic diagram of a scenario in which a synchronous call and an asynchronous call conflict with each other provided in an embodiment of the present application;

[0034] Fig.13 A schematic diagram of another method of viewing a thread status from a trace tool provided in an embodiment of the present application;

[0035] Fig.14 The architecture of a thread scheduling method based on a terminal device provided in an embodiment of the present application Figure 1 ;

[0036] Fig.15 The architecture of a thread scheduling method based on a terminal device provided in an embodiment of the present application Figure 2 ;

[0037] Fig.16 A schematic diagram of the structure of a thread scheduling device provided in an embodiment of the present application;

[0038] Fig.17 A schematic diagram of the hardware structure of another terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0039] In order to facilitate the clear description of the technical solutions of the embodiments of the present application, in the embodiments of the present application, words such as "first" and "second" are used to distinguish between identical or similar items with substantially the same functions and effects. For example, the first value and the second value are only used to distinguish different values, and their order is not limited. Those skilled in the art can understand that words such as "first" and "second" do not limit the quantity and execution order, and words such as "first" and "second" do not necessarily limit them to be different.

[0040] It should be noted that, in this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations or descriptions. Any embodiment or design described as "exemplary" or "for example" in this application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplary" or "for example" is intended to present related concepts in a specific way.

[0041] In the present application, "at least one" means one or more, and "plurality" means two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can mean: a, b, c, a and b, a and c, b and c, or a, b and c, where a, b, c can be single or multiple.

[0042] It should be noted that the "at..." in the embodiment of the present application can be the instant when a certain situation occurs, or a period of time after a certain situation occurs, and the embodiment of the present application does not specifically limit this. In addition, the display interface provided in the embodiment of the present application is only an example, and the display interface can also include more or less content.

[0043] In order to better understand the embodiment of the present application, the structure of the terminal device of the embodiment of the present application is introduced below. Figure 1 A schematic diagram of the hardware structure of a terminal device provided in an embodiment of the present application.

[0044] The terminal device may be referred to as a terminal, user equipment (UE), mobile station (MS), mobile terminal (MT), etc. For example, the terminal device may be a mobile phone, a smart TV, a wearable device, a tablet computer (Pad), a computer with wireless transceiver function, a virtual reality (VR) terminal device, an augmented reality (AR) terminal device, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in smart grid, a wireless terminal in transportation safety, a wireless terminal in smart city, a wireless terminal in smart home, etc. The embodiments of the present application do not limit the specific technology and specific device form adopted by the terminal device.

[0045] like Figure 1 As shown, the terminal device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, 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, an indicator 192, a camera 193, and a display screen 194, etc.

[0046] The sensor module 180 may include one or more of the following, for example: a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor, an ambient light sensor, or a bone conduction sensor.

[0047] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the terminal device. In other embodiments of the present application, the terminal device 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.

[0048] The processor 110 may include one or more processing units. Different processing units may be independent devices or integrated into one or more processors. The processor 110 may also be provided with a memory for storing instructions and data.

[0049] 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 device, and can also be used to transfer data between the terminal device 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 devices, such as AR devices, etc.

[0050] The charging management module 140 is used to receive charging input from a charger, which may be a wireless charger or a wired charger. The power management module 141 is used to connect the charging management module 140 to the processor 110 .

[0051] The wireless communication function of the terminal device can be implemented through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160 and baseband processor.

[0052] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. The antenna in the terminal device can be used to cover a single or multiple communication frequency bands. Different antennas can also be reused to improve the utilization of the antenna.

[0053] The mobile communication module 150 can provide solutions for wireless communications including 2G / 3G / 4G / 5G, etc., applied to terminal devices. The mobile communication module 150 can 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, etc. the received electromagnetic waves, and transmit them to the modem for demodulation.

[0054] The wireless communication module 160 can provide wireless communication solutions applied to terminal devices, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), etc.

[0055] The modem may include a modulator and a demodulator. 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, a receiver, etc.), or displays an image or video through a display screen 194. In some embodiments, the modem may be an independent device. In other embodiments, the modem may be independent of the processor 110 and be set in the same device as the mobile communication module 150 or other functional modules.

[0056] The terminal device realizes the display function through the GPU, the display screen 194, and the application processor. The GPU is a microprocessor for image processing, connecting the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering.

[0057] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. In some embodiments, the terminal device may include 1 or N display screens 194, where N is a positive integer greater than 1.

[0058] The terminal device can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.

[0059] The camera 193 is used to capture static images or videos. In some embodiments, the terminal device may include 1 or N cameras 193, where N is a positive integer greater than 1.

[0060] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the terminal device. 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.

[0061] The internal memory 121 can be used to store computer executable program codes, and the executable program codes include instructions. The internal memory 121 can include a program storage area and a data storage area.

[0062] The terminal device 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.

[0063] 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. Speaker 170A, also known as "speaker", is used to convert audio electrical signals into sound signals. The terminal device can listen to music or listen to hands-free calls through speaker 170A. Receiver 170B, also known as "earpiece", is used to convert audio electrical signals into sound signals. When the terminal device answers a call or voice message, the voice can be answered by placing receiver 170B close to the human ear. Headphone interface 170D is used to connect wired headphones. Microphone 170C, also known as "microphone" or "microphone", is used to convert sound signals into electrical signals. In an embodiment of the present application, the terminal device may have a microphone 170C.

[0064] The button 190 includes a power button, a volume button, etc. The button 190 may be a mechanical button. It may also be a touch button. The terminal device may receive the button input and generate a key signal input related to the user settings and function control of the terminal device. The indicator 192 may be an indicator light, which may be used to indicate the charging status, power change, message, missed call, notification, etc.

[0065] In addition, on top of the above components, the device also runs an operating system, such as an iOS operating system, an Android operating system, or a Windows operating system, etc. Applications can be installed and run on the operating system.

[0066] The software system of the terminal device can adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture, etc., which will not be described in detail here. 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 device.

[0067] For example, Figure 2 It is a schematic diagram of the software structure of a terminal device provided in an embodiment of the present application.

[0068] 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: the application layer, the application framework layer, the Android runtime and system library, and the kernel layer.

[0069] The application layer can include a series of application packages.

[0070] like Figure 2 As shown, the application package may include applications such as camera, calendar, phone, map, call, music, settings, mailbox, video, social, etc.

[0071] 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.

[0072] like Figure 2 As shown, the application framework layer may include a window manager, a content provider, a resource manager, a view system, a notification manager, and the like.

[0073] The window manager is used to manage window programs. The window manager can obtain the display size, determine whether there is a status bar, lock the screen, touch the screen, drag the screen, capture the screen, etc.

[0074] Content providers are used to store and retrieve data and make it accessible to applications. The data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0075] 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.

[0076] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0077] The system library may include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0078] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple applications.

[0079] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.

[0080] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, compositing, and layer processing.

[0081] A 2D graphics engine is a drawing engine for 2D drawings.

[0082] 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.

[0083] The following is an example of the workflow of the terminal device software and hardware, with reference to the scenario of application startup or interface switching in the application.

[0084] The following is a detailed description of the thread scheduling process based on the application in the terminal device provided by the embodiment of the present application in conjunction with the accompanying drawings. It should be noted that the "at..." in the embodiment of the present application can be the instant when a certain situation occurs, or it can be a period of time after a certain situation occurs, and the embodiment of the present application does not specifically limit this.

[0085] Usually, the interface displayed by the terminal device needs to rely on the steps of drawing, rendering, synthesis and display of the interface by various internal modules. Figure 3 A schematic diagram of a process of displaying an image on a terminal device provided in an embodiment of the present application. Figure 3 As shown, the terminal device may include an application (APP), a surface flinger, a display driver, and the like.

[0086] The display of each frame of image in the terminal device requires three main steps: image drawing and rendering by the APP, image synthesis by the surface flinger, and image display by the display driver. Alternatively, the process from image drawing to display may also include other steps, which are not limited in the embodiments of the present application.

[0087] S301 , the APP may obtain a cache area (buffer area), draw image data, and store the drawn image data in the cache area.

[0088] The APP may include: a process for implementing image drawing and rendering (or referred to as a first process), the first process being used to implement drawing and rendering of image data. For example, when the APP receives a trigger operation from a user, the APP may execute the steps shown in S301.

[0089] S302, the APP passes the drawn image data to the surface flinger.

[0090] S303 , the surface flinger performs image synthesis on the drawn image data, and stores the synthesized image data in a buffer area.

[0091] It is understandable that after S303, S304 and S306 may be executed simultaneously or one after another, and this is not specifically limited in the embodiments of the present application.

[0092] S304 , the surface flinger transmits the synthesized image data to the display driver.

[0093] S305: The display driver performs image display.

[0094] S306 , after passing the completed image data to the display driver, the surface flinger may initiate a request to the APP to release the cache area.

[0095] S307: The APP releases the image data in the cache area, so that the APP can subsequently cache new image data in the cache area and process and subsequently display the new image data.

[0096] In the process of S306-S307 APP releasing the image data in the cache area, the terminal device needs to call the binder thread (or second thread) in the APP for releasing the cache area for processing, and the surface flinger and the APP need to call the binder thread through the binder driver in the kernel kernel. For the specific asynchronous binder call process, please refer to Figure 4 The corresponding embodiments.

[0097] Figure 4 A flowchart of an asynchronous binder call provided in an embodiment of the present application.

[0098] The asynchronous binder call process may involve: client threads, server threads, binder drivers in the kernel layer, and libbinder.so in the native layer. The client thread may be the surfaceflinger thread (or first thread) in the surface flinger, and the server thread may be the binder process (or second thread) in the APP.

[0099] The specific implementation of the S306-S307 process can be: the surface flinger thread sends a request for releasing the cache area to the libbinder.so in the runtime layer (or native layer), and the request for releasing the cache area can be used to initiate an asynchronous binder call. Native can send the asynchronous binder call to the binder driver through the ioctl command, and the binder driver copies the user space data transmitted in the ioctl command, and parses the tasks in the binder asynchronous call and the binder thread of the binder asynchronous call, thereby waking up the binder thread on the server side, and sending the asynchronous binder call to the binder thread through the libbinder.so in the native layer, and the binder thread releases the image data in the cache area. In a non-blocking state, the client thread and the server thread can continue to execute the steps of releasing the image data in the cache area based on the asynchronous binder call.

[0100] It is understandable that the terminal device will execute the above-mentioned asynchronous binder call process after drawing each frame, and use the binder thread to release the image data corresponding to the frame in the cache area. The binder thread usually corresponds to a processing priority. When the processing priority of the binder thread is low and the terminal device is in a high-load scenario, the execution order of other threads with a higher priority than the binder thread will be higher than the binder thread, resulting in the binder thread taking longer to release the cache area, and being in a long waiting state (or runnable state) while waiting for the cache area to be released, which in turn affects the drawing, synthesis and display process of subsequent image frames, causing the terminal device to experience screen freezes. Among them, the runnable state refers to a state in which the thread can run but needs to continue waiting for CPU scheduling.

[0101] Therefore, in order to solve the problem that the terminal device appears to be stuck due to the low processing priority of the binder thread, the embodiment of the present application can provide a method for increasing the priority in the asynchronous binder call (see Figure 5 Corresponding embodiments), so that the terminal device can accurately identify the binder thread used to release the cache area in the APP, and increase the processing priority of the binder thread, so that the binder thread can process tasks at a high priority to improve subsequent screen freezes.

[0102] For example, Figure 5 A flowchart of a method for increasing priority in an asynchronous binder call is provided in an embodiment of the present application.

[0103] S501. The surface flinger thread sends a request for releasing a cache area to a binder driver. The request for releasing the cache area is an asynchronous binder call.

[0104] Among them, the asynchronous binder call can be a binder_ioctl command, which is used to carry one or more of the following information in the request for releasing the cache area: an asynchronous communication identifier, a binder communication number, or an interface descriptor, etc. The asynchronous communication identifier is used to indicate that the binder call is an asynchronous call, the binder communication number is used to indicate the communication interface, and the interface descriptor is used to indicate the client and server for communication.

[0105] S502, the binder driver copies user space data and parses asynchronous Binder calls.

[0106] S503: The binder driver determines whether to increase the processing priority of the binder thread.

[0107] When the asynchronous binder call meets the preset conditions, the binder driver changes the processing priority of the binder thread from the first priority to the second priority; or, when the asynchronous binder call does not meet the preset conditions, the binder driver maintains the first priority. The second priority is higher than the first priority. The binder driver can determine whether to modify the processing priority of the binder thread based on the information carried in the request for releasing the cache area.

[0108] Exemplarily, the preset conditions include one or more of the following: the communication interface indicated by the binder communication number is the communication interface between the surface flinger thread and the binder thread, the interface descriptor indicates that the client for communication is the surface flinger thread and the server for communication is the binder thread, or the asynchronous communication identifier indicates that the communication between the surface flinger thread and the binder thread is asynchronous binder communication.

[0109] In one implementation, if it is determined that the communication interface indicated by the binder communication number is the communication interface between the surface flinger thread and the binder thread, and the interface descriptor indicates that the initiator of the communication is the surface flinger thread and the processing end of the communication is the first process, the processing priority of the binder thread is modified from the first priority to the second priority.

[0110] In another implementation, if it is determined that the communication interface indicated by the binder communication number is the communication interface between the surface flinger thread and the binder thread, and the interface descriptor indicates that the initiator of the communication is the surface flinger thread, the processing end of the communication is the first process, and the asynchronous communication identifier indicates that the communication between the surface flinger thread and the first process is asynchronous binder communication, then the processing priority of the binder thread is modified from the first priority to the second priority.

[0111] Furthermore, the binder driver may wake up the binder after modifying the priority of the binder thread, and then execute the step shown in S504.

[0112] S504: The binder driver initiates an asynchronous binder call to the binder thread.

[0113] S505: The binder thread releases the image data in the cache area.

[0114] After the binder thread releases the image data in the cache area, the binder thread may return to the binder driver (as shown by the dotted line after S505 ), so that the binder driver executes the subsequent steps shown in S506 .

[0115] S506: The binder driver determines whether to restore the processing priority of the binder thread.

[0116] For example, when the binder thread is in an idle state, the binder driver will restore the processing priority of the binder thread, so that the processing priority of the binder thread is restored from the second priority to the first priority; or, when the binder thread is not in an idle state, the binder driver does not restore the processing priority of the binder thread, and the processing priority of the binder thread is still at the second priority.

[0117] The fact that the binder thread is in an idle state can be understood as there is no task (work) to be executed in the binder thread, and the fact that the binder thread is not in an idle state can be understood as there is a task to be executed in the binder thread.

[0118] based on Figure 5In the corresponding embodiment, the scheme for improving the processing priority of the binder thread is that the binder driver can realize accurate identification of the binder thread used to release the cache area in S503, and improve the processing priority of the binder thread before waking up the binder thread, so that the binder thread can run at a high priority. In addition, after the binder thread runs the current task in the queue, the binder driver determines whether the binder thread is currently in an idle state, and restores the processing priority of the binder thread when it is in an idle state, and does not restore the processing priority of the binder when it is not in an idle state.

[0119] However Figure 5 The corresponding embodiments have the following problems:

[0120] Problem 1: In S506, since the binder driver does not restore the processing priority of the binder thread when the binder thread is not in an idle state, the binder thread is in a high priority. When the binder thread processes tasks in the queue, it can occupy important resources in the terminal device based on the high priority, which makes the device resources available to other threads lower, affecting the running ability of other threads.

[0121] Problem 2: In S506, when the binder thread is in an idle state, the binder driver will restore the processing priority of the binder thread, making the binder thread in a low priority state, and other high-priority threads running in the terminal device will seize the CPU, causing the binder thread to switch from the running state to the runnable state. When the load of the terminal device is high, the runnable time will be longer, affecting the operation of the subsequent binder thread.

[0122] Regarding question 2, Figure 6 A schematic diagram of viewing the thread status from a trace tool is provided in an embodiment of the present application. The trace tool can be understood as a tool for viewing the running status of each process (or thread) in the CPU of a terminal device, and the horizontal direction in the trace can be understood as a timeline.

[0123] like Figure 6 As shown in the first line of FIG, the binder thread 601 can be in the running state or the runnable state at different time periods. Figure 6 As shown in the second line in , the specific binder thread 601 can execute the task of releasing the image data in the cache area during the running state.

[0124] It is understandable that, since the binder thread 601 is in an idle state, the binder driver can restore its priority, and other high-priority threads in the terminal device preempt the CPU, resulting in the binder thread 601 being in a runnable state for a period of time after the task is executed.

[0125] The runnable time period before the running state can be understood as the time period in which the binder thread 601 is queuing for CPU scheduling, and the running time period after the last runnable state can be understood as the time period in which the binder thread 601 is finishing its work.

[0126] Among the possible implementations, Figure 6 The process may also include other tasks running in the binder thread 601, which is not limited in the embodiment of the present application.

[0127] In view of Figure 5 In response to the problem described in the corresponding embodiment, the embodiment of the present application provides a thread scheduling method, so that after the binder thread completes the current task, the binder driver can determine that the binder thread is in an idle state and the binder thread has previously increased its priority. The priority of the binder thread will not be restored, so that the binder thread can restore the priority by delaying, thereby reducing the runnable situation of the binder thread.

[0128] Furthermore, before the binder thread executes the next task, the binder driver can determine whether to restore the processing priority of the binder thread, so that the priority recovery process is delayed from the end of the current task to the start of the next task, so as to better solve the problem of long runnable caused by restoring the priority after the current task ends.

[0129] The following specific embodiments are used to describe in detail the technical solution of the present application and how the technical solution of the present application solves the above technical problems. The following specific embodiments can be implemented independently or in combination with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.

[0130] For example, Figure 7 A flowchart of a thread scheduling method provided in an embodiment of the present application is shown in FIG. Figure 7 As shown, the thread scheduling method may include the following steps:

[0131] S701. The surface flinger thread sends a request for releasing a cache area to a binder driver. The request for releasing the cache area is an asynchronous binder call.

[0132] S702, the binder driver copies user space data and parses asynchronous Binder calls.

[0133] S703: The binder driver determines whether to increase the processing priority of the binder thread.

[0134] When the binder driver determines to increase the processing priority of the binder thread, the binder driver may add a flag (or referred to as a first flag) for indicating the increase of the priority to the binder thread, and the flag may be true.

[0135] The description in S701-S703 can be found in S501-S503, and will not be repeated here.

[0136] S704: The binder driver determines whether to restore the processing priority of the binder thread.

[0137] When the binder thread is currently at the second priority and the binder thread needs to be upgraded to the second priority based on the judgment in S703 (the task in the binder thread has a label indicating that the priority needs to be upgraded), the binder driver does not restore the processing priority of the binder thread, that is, the binder driver keeps the processing priority of the binder thread at the second priority.

[0138] Alternatively, when the binder thread is currently at the second priority and the binder thread does not need to increase its priority based on the judgment in S703 (the task in the binder thread does not carry a label for indicating an increase in priority), the binder driver restores the priority of the binder thread, that is, the processing priority of the binder driver is modified from the second priority to the first priority.

[0139] It can be understood that S703 may be a step executed by the surface flinger thread in the binder driver, and S704 may be a step executed by the binder thread after the binder driver wakes up the binder thread.

[0140] It is understandable that the binder driver can comprehensively determine how to handle the processing priority of the asynchronous binder call in combination with S703 and S704. For example, when the binder driver determines that the asynchronous binder call meets the preset conditions and the binder thread is the second priority, the second priority of the binder thread is maintained; or, when the binder driver determines that the asynchronous binder call does not meet the preset conditions and the binder is the second priority, the first priority of the binder thread is restored.

[0141] S705: The binder driver initiates an asynchronous binder call to the binder thread.

[0142] S706: The binder thread releases the image data in the cache area.

[0143] S707: When the binder thread is in an idle state and the binder thread has a flag indicating a priority increase, the binder driver does not restore the priority of the binder thread, that is, the binder driver maintains the second priority of the binder thread.

[0144] Similarly, when the binder thread is not in an idle state, the binder driver does not restore the processing priority of the binder thread, so that the binder thread maintains the second priority. Therefore, after the binder thread can cache the image data in the area, the priority will not be restored regardless of the current state of the binder thread, so as to achieve the purpose of delaying priority restoration.

[0145] In a possible implementation, after S707, the terminal device may again implement the binder's judgment on the priority before executing the next task based on the steps shown in S701-S704.

[0146] Combination Figure 5 The corresponding embodiments and Figure 7 Corresponding to the embodiment, it can be understood that, Figure 5 In the corresponding embodiment, the binder driver can restore the processing priority of the binder thread when the binder thread completes the release of the image data in the cache area and the binder thread is in an idle state, thereby causing the binder thread to become runnable.

[0147] and Figure 7 In a corresponding embodiment, the binder driver may temporarily not restore the processing priority of the binder thread when the binder thread has completed executing the release of image data in the cache area and the binder thread is in an idle state, and delay the judgment of restoring the priority until the binder thread processes the next task, so as to reduce the runnable problem caused by restoring the binder priority, and ensure that the task of releasing the cache area can run with a high priority.

[0148] For example, Figure 8 Another schematic diagram of viewing thread status from a trace tool provided in an embodiment of the present application. Figure 8As shown, the binder thread 801 can increase the priority before executing the task for the first time, and the processing priority of the binder thread 801 is not restored after the first task is completed. When the binder thread 801 executes the second task, the binder driver determines whether the priority needs to be increased based on S703 and whether the priority needs to be restored based on S704. For example, the binder driver can determine that the binder thread 801 does not need to increase the priority before executing the second task. Similarly, the binder driver performs the processing of not restoring the priority for the third task to the fifth task, so that the binder thread is at the second priority.

[0149] Before the binder thread 801 executes the sixth task, the binder driver determines that the priority of the binder thread needs to be restored based on the judgment of S703-S704. Among them, the processing priority of the first running time period in the sixth task is the second priority, and the processing priority of the second running time period in the sixth task is the first priority, so as to realize the restoration priority.

[0150] exist Figure 7 Based on the corresponding embodiments, the following problems may arise, for example: when the binder thread is in the period of priority enhancement, when the binder thread of the terminal device (such as the second thread) initiates other binder calls (such as initiating a third thread), the binder driver will insert the task corresponding to the other binder call into the queue of the client thread (such as the second thread), so that the binder thread restores the processing priority of the binder thread when processing the task corresponding to the other binder call. In this scenario, the binder thread may appear in the runnable state.

[0151] Normally, in Figure 7 In the corresponding embodiment, when the thread initiates a binder asynchronous call, the binder driver places the current task in the task where the binder asynchronous call is located, and inserts work indicating the completion of the communication transaction into the task queue of the client thread to notify the client thread of the binder asynchronous call.

[0152] It is understandable that each process may include multiple binder threads, and the binder thread is used to communicate with the binder threads in other processes. The binder threads will be uniformly managed in the binder driver, and the queue corresponding to any binder thread may include tasks that the binder thread needs to complete.

[0153] However, when the binder thread (such as the second thread) initiates other binder calls (such as initiating the third thread) during the priority increase period, the binder driver will insert a task for indicating the completion of the communication transaction into the queue where the binder thread (such as the second thread) is located. The binder driver restores the processing priority of the binder thread (such as the second thread) based on the task for indicating the completion of the communication transaction, causing the binder thread to become runnable.

[0154] When the binder thread (such as the second thread) initiates a synchronous binder call (such as initiating the fourth thread) during the priority increase period, the binder thread will receive the binder reply work after the task is completed, and the binder driver will insert the binder reply work into the queue where the binder thread is located. The binder driver restores the processing priority of the binder thread based on the binder reply work, causing the binder thread to become runnable.

[0155] The period during which the binder thread is in a priority enhancement period can be understood as the period from when the binder thread starts executing the first task to when the binder thread starts executing the second task.

[0156] For example, Fig. 9 A schematic diagram of viewing a thread status from a trace tool is provided in another embodiment of the present application. Fig. 9 As shown, binder 901 may be in a priority-enhanced state in the solid-line frame 900 , and the processing priority of binder 901 may be 97 at this time.

[0157] When binder901 is in the process of priority enhancement, when binder901 initiates a call to binder902, the binder driver will insert a work into binder902 and insert a task for indicating the completion of the communication transaction into binder901. The binder driver restores the priority of binder901 in advance based on the task for indicating the completion of the communication transaction in binder901, for example, restores the processing priority of binder901 to 120, and further, uses binder901 to execute the task for indicating the completion of the communication transaction. It can be understood that the processing priority of binder901 in the subsequent running process can be 120, and binder901 may be blocked after the priority is restored. Among them, the higher the priority value, the lower the level of priority processing and the later the processing time.

[0158] In view of this, an embodiment of the present application provides a process scheduling method, so that when the binder driver executes a task, while determining the processing priority of the binder call based on S703-S704, it filters out preset tasks that cause the binder thread to restore its priority in advance.

[0159] The preset task may include: a first task type and a second task type, such as the first task type may include: a work type for indicating that the communication transaction is completed and handed over to the initiator for processing, and a work type for indicating that the communication transaction fails and is handed over to the initiator for processing, etc. The second task type may include: a work type for indicating a reply from the server.

[0160] Among them, the work used to indicate that the communication transaction is completed and handed over to the initiator for processing may include: BINDER_WORK_TRANSACTION_COMPLETE and BINDER_WORK_TRANSACTION_ONEWAY_SPAM_SUSPECT, the work type used to indicate that the communication transaction failed and is handed over to the initiator for processing may include: BINDER_WORK_RETURN_ERROR, and the work type used to indicate the server's reply may include: binder reply work, which is not limited in the embodiments of the present application.

[0161] Exemplarily, when it is determined based on S703 and S704 that the binder thread does not need to increase its priority (or it can also be understood that the processing priority of the binder driver can be restored), and the task executed by the binder thread meets the above-mentioned preset task, the binder driver may not restore the processing priority of the binder thread, so that the processing priority of the binder thread is at the second priority, so as to reduce the problem of the priority being restored in advance during the period when the binder thread is in the priority increase period.

[0162] When another binder call is initiated for the binder thread, the binder driver inserts a task to indicate the completion of the communication transaction into the queue where the binder thread is located, causing the binder thread to become runnable during the priority increase period. By filtering the preset tasks, the binder thread is put into the running state. See Fig.10 The corresponding embodiments.

[0163] For example, Fig.10 Another schematic diagram of viewing thread status from a trace tool is provided in an embodiment of the present application. Fig.10As shown, when binder1001 is in the process of priority enhancement, when binder1001 initiates a call to binder1002, the binder driver inserts a work into binder1002 and inserts a task for indicating the completion of the communication transaction into binder1001. When the binder driver determines that there is no need to enhance the priority at present and detects that the task for indicating the completion of the communication transaction satisfies the preset task, the binder driver will not restore the processing priority of binder1001, so that the subsequent processing priority of binder1001 is 97 and it is always in the running state.

[0164] When another synchronous binder call is initiated for the binder thread, the binder thread receives the binder replywork, which causes the binder thread to become runnable during the priority increase period. By filtering the preset tasks, the binder thread is put into the running state. See Fig.11 The corresponding embodiments.

[0165] For example, Fig.11 Another schematic diagram of viewing thread status from a trace tool is provided in an embodiment of the present application. Fig.11 As shown, when binder1101 is in the process of priority enhancement, when binder1001 initiates a synchronous binder1102 call, the binder driver inserts a work in binder1102, and after binder1102 completes the task, it replies binder reply work to binder1101. When the binder driver determines that there is no need to enhance the priority at present and detects that the binder reply work satisfies the preset task, the binder driver will not restore the processing priority of binder1101, so that the subsequent processing priority of binder1101 is 97, and it is always in the running state.

[0166] exist Figure 7 Based on the corresponding embodiments, the following problems may occur, for example: when the terminal device executes an asynchronous binder call and a synchronous binder call at the same time, a conflict between the asynchronous binder call and the synchronous binder call will cause the screen to freeze.

[0167] The execution process of asynchronous binder call can be seen in Figure 7Corresponding embodiments: During the synchronous binder call process, when the framework layer determines that the surface flinger is a preset important thread, it can pass the processing priority of the important thread to the processing priority of the server-side binder thread in the binder driver, and the binder driver can restore the processing priority of the binder thread when determining the binder thread reply.

[0168] For example, Fig.12 A schematic diagram of a scenario in which a synchronous call and an asynchronous call conflict is provided in an embodiment of the present application.

[0169] like Fig.12 The a in the figure is a scheme based on asynchronous binder call to increase the priority (or asynchronous scheme). When the binder driver detects the first task, the processing priority of the binder thread can be increased (see the solid arrow pointing upward), and the priority can be restored when the next ordinary task is executed (see the implementation arrow pointing downward).

[0170] It can be seen that after the asynchronous solution executes any first task, the priority is not restored immediately, but before executing a common task. The first task can be understood as a task in the binder thread that meets the preset conditions described in S701.

[0171] like Fig.12 b in the figure is a priority-raising scheme based on synchronous binder calls (or synchronous scheme). When the binder driver detects the seventh task, it can raise the processing priority of the binder thread (see the upward dashed arrow) and restore the priority when executing the next ordinary task (see the downward dashed arrow).

[0172] It can be seen that after the synchronization scheme executes any seventh task, the priority will be restored immediately. The seventh task can be a task in an important thread preset in the synchronization binder call.

[0173] like Fig.12 The c in the example is a scheme (or conflict scheme) for increasing the priority of synchronous binder calls and asynchronous binder calls. The binder driver can execute the first task first and then the seventh task.

[0174] The process of identifying the conflicting scheme can be: before executing the first task, the processing priority of the binder thread is increased, and a label is marked on the binder thread to indicate that the asynchronous scheme is in effect, and there is no need to restore the priority in the asynchronous scheme; further, before executing the seventh task, when the binder driver recognizes that the binder thread has a label, the binder driver can determine that a conflict will occur with the synchronous scheme during the period when the asynchronous scheme is in effect.

[0175] Therefore, the binder driver can restore the processing priority of asynchronous calls before the seventh task, and then improve the processing priority of synchronous calls. It can be understood that for a period of time after the binder driver improves the processing priority of the binder thread synchronous call, the binder thread follows the synchronous binder call scheme.

[0176] Combination Fig.12 The description in the corresponding embodiment can be understood as that when the binder driver detects the first task first and then the seventh task, a conflict will occur, and when the binder driver detects the seventh task first and then the first task, no conflict will occur.

[0177] For example, Fig.13 Another schematic diagram of viewing thread status from a trace tool is provided in an embodiment of the present application.

[0178] like Fig.13 As shown, binder 1302 may be a client thread, binder thread 1301 may be a server thread, and binder thread 1302 may be a synchronous binder call.

[0179] The binder thread 1301 can increase the priority of the binder asynchronous call in the first running state. When detecting the task identified by the synchronous binder call, it is determined that a conflict occurs, that is, the binder driver can first restore the processing priority of the asynchronous binder call, and then increase the processing priority of the synchronous binder call in the solid line box where 1300 is located, and then restore the priority of the synchronous binder call.

[0180] It is understandable that the thread scheduling method provided by the embodiment of the present application can be applied not only to the image drawing scene, for example: the first thread is a thread for image synthesis, and the first process is a process for image drawing. Alternatively, the thread scheduling method provided by the embodiment of the present application can also be applied to the window information update scene, for example, the first process is a process for generating window data of window information, and the first thread is a thread for updating the window information of the system.

[0181] Combined with the above Figure 3-Figure 13 Description in the corresponding embodiment. Fig.14 The architecture of a thread scheduling method based on a terminal device provided in an embodiment of the present application Figure 1 .

[0182] like Fig.14 As shown in Figure 1, the terminal device has a kernel layer (Kenrel), a hardware abstraction layer (HAL), a system runtime layer (native), an application framework layer (Framework), and an application layer. Fig.14 The application layer interacts with the cloud platform.

[0183] The application layer includes multiple applications (APPs); the application layer runs a first process; and the application layer runs management software. For example, the first process may be a Launcher process.

[0184] The application framework layer includes the application framework of the system. For example, when this solution is applied to the Android system, the application framework of the system is the Android Framework. The application framework layer includes the process management module; the non-real-time processing subsystem in the process management module. The non-real-time processing subsystem includes the feature management module, the configuration management module, and the feature switch module.

[0185] The application layer interacts with the application framework layer to transmit start events (Start events), end events (End events) and feature switches.

[0186] The system runtime layer includes Libs and ART modules. Libs includes a processing module, and Libs runs the first thread (surfaceflinger thread).

[0187] The application framework layer interacts with the system runtime layer to set the feature switch value. The first process supports asynchronous biander communication. Thus, the application framework layer transmits the feature switch value to the system runtime layer.

[0188] The kernel layer includes the Linux kernel and the kernel extension subsystem. The kernel layer also performs binder communication.

[0189] The system runtime layer interacts with the kernel layer to set the feature switch value. Thus, the system runtime layer transmits the feature switch value to the kernel layer.

[0190] Furthermore, the kernel layer of the processor obtains the encapsulated data transmitted by the application framework layer (Framework) or the system runtime layer (native), and the encapsulated data includes the binder communication number, the interface descriptor and the asynchronous communication identifier.

[0191] Fig.15 The architecture of a thread scheduling method based on a terminal device provided in an embodiment of the present application Figure 2 .like Fig.15 As shown in Figure 1. The terminal device has a kernel layer (Kenrel), a hardware abstraction layer (HAL), a system runtime layer (native), an application framework layer (Framework), and an application layer. Fig.15 The application layer interacts with the cloud platform.

[0192] The application layer includes multiple applications (APPs); the application layer runs a first process; and the application layer runs management software. For example, the first process is a Launcher process.

[0193] The first process includes a first setting module, which is used to read the feature configuration (i.e., read the feature switch), and to send a start event and an end event. It can be seen that the first setting module is used to read the start information and the close information. The start information and the close information are stored in the configuration management module of the application framework layer; the feature configuration is the start information or the close information; wherein, the start information indicates the start of the priority modification of the second thread; the close information indicates the close of the priority modification of the second thread. The start event (i.e., the first event) represents the start of the priority modification of the second thread. The end event (i.e., the second event) represents the close of the priority modification of the second thread.

[0194] The first process sends a start event (ie, a first event) to the application framework layer based on the start information read. The first process sends an end event (ie, a second event) to the application framework layer based on the end information read.

[0195] The application layer interacts with the application framework layer to transmit start events (Start events), end events (End events) and feature switches.

[0196] The application framework layer includes the application framework of the system. For example, when this solution is applied to the Android system, the application framework of the system is the Android Framework. The application framework layer includes the process management module; the non-real-time processing subsystem in the process management module. The non-real-time processing subsystem includes the second setting module and the configuration management module.

[0197] The second setting module is used to obtain the feature switch value. Wherein, the first process supports asynchronous biander communication. The configuration management module is used to store and read the feature configuration (ie, store and read the feature switch).

[0198] The application framework layer passes the feature switch value to the system runtime layer.

[0199] The system runtime layer includes Libs and ART modules. Libs includes a processing module, and Libs runs the first thread (surfaceflinger thread).

[0200] The processing module is used to obtain the feature switch value. The first thread is used to initiate asynchronous binder communication, thereby triggering the second thread (binder thread) to trigger the release of the cache area (buffer). For example, the first thread is a surfaceflinger thread

[0201] The system runtime layer transmits the feature switch value to the kernel layer. In addition, the first thread of the system runtime layer initiates asynchronous binder communication and increases the processing priority of the second thread (binder thread).

[0202] The kernel layer includes the Linux kernel and the boost module. The Linux kernel is used to store the process number of the Launcher process. The boost module is used to increase the processing priority of the second thread (binder thread).

[0203] Combined with the above Figure 3-Figure 15 , the method provided in the embodiment of the present application is explained, and the device for executing the above method provided in the embodiment of the present application is described below.

[0204] For example, Fig.16 A structural schematic diagram of a thread scheduling device provided in an embodiment of the present application. The thread scheduling device may be a router in an embodiment of the present application, or a chip or chip system in a router.

[0205] like Fig.16 As shown, the thread scheduling device 1600 can be used in a communication device, circuit, hardware component or chip, and the thread scheduling device includes: a processing unit 1601 and an execution unit 1602. The processing unit 1601 is used to support the thread scheduling device 1600 to perform information processing steps, and the execution unit 1602 is used to support the thread scheduling device 1600 to perform task execution steps.

[0206] In a possible embodiment, the thread scheduling device may further include: a communication unit 1603. The communication unit 1603 is used to support the thread scheduling device 1600 to execute the steps of sending and receiving data. The communication unit 1603 may be an input or output interface, a pin or a circuit.

[0207] In a possible embodiment, the thread scheduling device may further include: a storage unit 1604. The processing unit 1601 and the storage unit 1604 are connected via a line. The storage unit 1604 may include one or more memories, and the memory may be a device used to store programs or data in one or more devices or circuits. The storage unit 1604 may exist independently and be connected to the processing unit 1601 of the thread scheduling device via a communication line. The storage unit 1604 may also be integrated with the processing unit 1601.

[0208] The storage unit 1604 may store computer-executable instructions of the method in the router so that the processing unit 1601 executes the method in the above embodiment. The storage unit 1604 may be a register, a cache, or a RAM, etc. The storage unit 1604 may be integrated with the processing unit 1601. The storage unit 1604 may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, and the storage unit 1604 may be independent of the processing unit 1601.

[0209] Fig.17 A schematic diagram of the hardware structure of another terminal device provided in an embodiment of the present application is shown in FIG. Fig.17 As shown, the terminal device may include a processor 1701, a communication line 1704 and at least one communication interface ( Fig.17 The communication interface 1703 is used as an example for explanation).

[0210] Processor 1701 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.

[0211] Communications link 1704 may include circuitry to transmit information between the above-described components.

[0212] The communication interface 1703 uses any transceiver or other device for communicating with other terminal devices or communication networks, such as Ethernet, wireless local area networks (WLAN), etc.

[0213] Possibly, the terminal device may further include a memory 1702 .

[0214] The memory 1702 may be a read-only memory (ROM) or other types of static storage terminal devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage terminal devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage terminal device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a communication line 1704. The memory may also be integrated with the processor.

[0215] The memory 1702 is used to store computer-executable instructions for executing the solution of the present application, and the execution is controlled by the processor 1701. The processor 1701 is used to execute the computer-executable instructions stored in the memory 1702, thereby implementing the method provided by the embodiment of the present application.

[0216] Possibly, the computer-executable instructions in the embodiments of the present application may also be referred to as application code, and the embodiments of the present application do not specifically limit this.

[0217] In a specific implementation, as an embodiment, the processor 1701 may include one or more CPUs, such as Fig.17 CPU0 and CPU1 in.

[0218] In a specific implementation, as an embodiment, the terminal device may include multiple processors, such as Fig.17 1701 and 1705 in the embodiment of the present invention. Each of these processors may be a single-CPU processor or a multi-CPU processor. The processor here may refer to one or more terminal devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0219] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the process or function according to the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (digital subscriber line, DSL) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a server or data center that includes one or more available media integrated. For example, the available medium can include a magnetic medium (e.g., a floppy disk, a hard disk or a tape), an optical medium (e.g., a digital versatile disc (digital versatile disc, DVD)), or a semiconductor medium (e.g., a solid state drive (solid state disk, SSD)), etc.

[0220] The embodiments of the present application also provide a computer-readable storage medium. The methods described in the above embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. Computer-readable media may include computer storage media and communication media, and may also include any medium that can transfer a computer program from one place to another. The storage medium may be any target medium that can be accessed by a computer.

[0221] As a possible design, the computer readable medium may include a compact disc read-only memory (CD-ROM), RAM, ROM, EEPROM or other optical disc storage; the computer readable medium may include a magnetic disk storage or other magnetic disk storage device. Moreover, any connection line may also be appropriately referred to as a computer readable medium. For example, if the software is transmitted from a website, server or other remote source using a coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology (such as infrared, radio and microwave), the coaxial cable, fiber optic cable, twisted pair, DSL or wireless technology such as infrared, radio and microwave are included in the definition of medium. Disk and disc as used herein include compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, where disks usually reproduce data magnetically, while optical discs reproduce data optically using lasers.

[0222] The above combinations should also be included in the scope of computer-readable media. The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A thread scheduling method, It is characterized in that Applied to a terminal device, wherein a first process and a first thread are running in the terminal device, wherein the first thread is a thread for processing tasks, wherein the first process includes a second thread, wherein the second thread is a binder thread, and wherein the second thread includes: a first task, wherein the method includes: At a first moment, in response to a first instruction, the terminal device modifies the processing priority of the second thread from the first priority to the second priority before executing the first task based on the first instruction, wherein the processing priority of the second priority is higher than the processing priority of the first priority, and after the first moment, the second thread carries a first identifier, the first identifier is used to indicate that the second thread is in a priority-enhanced state, and the first instruction is an instruction corresponding to the first task; The terminal device executes the first task based on a second thread having the second priority; At the second moment, when the terminal device determines that there is no task to be executed in the second thread and the second thread carries the first identifier, the terminal device does not restore the processing priority of the second thread.

2. The method according to claim 1, It is characterized in that The second thread also includes a second task. After the second moment, the method further includes: At a third moment, in response to a second instruction, when the terminal device determines to modify the processing priority of the second thread from the first priority to the second priority based on the second instruction, and the terminal device is at the second priority after the second moment, the terminal device does not restore the processing priority of the second thread, and executes the second task based on the second thread with the second priority, and the second instruction is an instruction corresponding to the second task; Alternatively, when the terminal device determines not to change the processing priority of the second thread from the first priority to the second priority based on the second instruction, and the terminal device is at the second priority after the second moment, the terminal device restores the second priority to the first priority, and executes the second task based on the second thread with the first priority.

3. The method according to claim 2, It is characterized in that The second instruction includes one or more of the following: a binder communication number, an interface descriptor, or an asynchronous communication identifier, the binder communication number is used to indicate a communication interface, the interface descriptor is used to indicate a client and a server for communication, and the asynchronous communication identifier is used to indicate a communication mode, and the terminal device determines to modify the processing priority of the second thread from the first priority to the second priority based on the second instruction, including: When it is determined based on the second instruction that the second thread satisfies a preset condition, the terminal device modifies the processing priority of the second thread from the first priority to the second priority, Among them, the preset conditions include one or more of the following: the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, the interface descriptor indicates that the client for communication is the first thread and the server for communication is the second thread, or the asynchronous communication identifier indicates that the communication between the first thread and the second thread is asynchronous binder communication.

4. The method according to claim 2, It is characterized in that After the first moment and before the third moment, a third thread is running in the terminal device, the third thread is a thread called by the binder initiated by the second thread, the third thread includes: a fourth task, and the method further includes: The terminal device inserts a third task into a queue executed by the second thread based on the third thread; In response to a third instruction, when the terminal device determines to restore the processing priority of the second thread based on the third instruction and the third task meets the preset first task type, the terminal device does not restore the processing priority of the second thread, and the third instruction is an instruction corresponding to the third task; The terminal device executes the third task based on the second thread with the second priority; The terminal device performs the fourth task.

5. The method according to claim 4, It is characterized in that The first task type includes: a task type used to indicate that a communication transaction is completed and handed over to the initiating end for processing, and / or a task type used to indicate that a communication transaction fails and is handed over to the initiating end for processing.

6. The method according to any one of claims 2 to 5, It is characterized in that After the first moment and before the third moment, a fourth thread is running in the terminal device, the fourth thread is a thread of synchronous binder call initiated by the second thread, the fourth thread includes: a fifth task, and the method further includes: After executing the fifth task, the terminal device inserts a sixth task into the second thread, wherein the sixth task is used to instruct the terminal device to complete processing of the fifth task; In response to a fourth instruction, when the terminal device determines to restore the processing priority of the second thread based on the fourth instruction and the sixth task meets the preset second task type, the terminal device does not restore the processing priority of the second thread, and the fourth instruction is an instruction corresponding to the sixth task; The terminal device executes the sixth task based on the second thread having the second priority; The terminal device performs the fifth task.

7. The method according to claim 6, It is characterized in that The second task type includes: the task type replied by the server.

8. The method according to any one of claims 1 to 7, It is characterized in that The first task is a task identified by the terminal device when an asynchronous binder call is made, the second thread further includes: a seventh task, the seventh task is a task identified by the terminal device when a synchronous binder call is made, before the second moment, the second thread carries a second identifier, the second identifier is used to indicate that the second thread is an asynchronous binder call, before the second moment and after the first moment, the method further includes: At a fourth moment, in response to a fifth instruction, when the terminal device detects the seventh task and the second thread with the second identifier, the terminal device restores the processing priority of the second thread before executing the seventh task, and the fifth instruction is an instruction corresponding to the seventh task; At the fifth moment, the terminal device changes the processing priority of the second thread from the first priority to the second priority, and processes the seventh task based on the second priority; at the fifth moment after the fourth moment, the second thread is in the state of the synchronous binder call within the first time period after the fifth moment, and the second thread is in the state of the asynchronous binder call between the fourth moment and the fifth moment.

9. The method according to claim 8, It is characterized in that After the fifth moment, the method further includes: At a sixth moment, the terminal device restores the processing priority of the second thread, and the processing priority of the second thread is at the first priority in a second time period after the sixth moment.

10. The method according to any one of claims 1 to 9, It is characterized in that The first thread is a thread for image synthesis, and the first process is a process for image drawing; or, the first process is a process for generating window data of window information, and the first thread is a thread for updating window information of a system.

11. A terminal device, It is characterized in that include: processor and memory, wherein The memory is used to store computer programs; The processor is used to call and execute the computer program so that the terminal device executes the method according to any one of claims 1 to 10.

12. A computer-readable storage medium, It is characterized in that Used to store a computer program, which, when executed on a computer, causes the computer to execute the method according to any one of claims 1 to 10.

Citation Information

Cited By

  • Preemption management method and device, equipment, storage medium and program product

    CN120510017A

  • Thread scheduling method and apparatus

    EP4647915A1

  • Thread scheduling method and apparatus

    WO2024244591A1