Thread Scheduling Method, Terminal Device, and Medium Based on a Terminal Device
By increasing the processing priority of binder threads at the kernel layer, the problem of binder threads being unable to be scheduled in time in terminal devices is solved, ensuring timely release and processing of task data, and improving the response speed and user experience of terminal devices.
Patent Information
- Application Number
- CN202211349182.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-31
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2042-10-31
AI Technical Summary
The binder thread in the terminal device cannot be scheduled in time, resulting in the task data in the cache area being unable to be released in time, affecting the terminal device to process new tasks.
By modifying the processing priority of the binder thread at the kernel layer, it will be upgraded from non-real-time scheduling priority to real-time scheduling priority, ensuring that the binder thread can timely release task data in the cache area.
It realizes timely scheduling of binder threads, ensures that the terminal equipment can process task data in a timely manner, avoids lag and frame drops, and improves the response speed of the terminal equipment.
Smart Images

Figure CN117950847B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of terminals, and in particular, to a thread scheduling method based on a terminal device, a terminal device, and a medium. Background Art
[0002] Currently, with the development of terminal technology, terminal devices have become important tools in people's lives. Terminal devices require many tasks; for example, there are multiple applications in a terminal device, and during the operation of an application, the terminal device needs to display an animated image. For another example, the terminal device needs to update the window information of the system. During the process of processing tasks, the terminal device will cache the task data of the task in a cache area and process the task based on the task data in the cache area; then after the terminal device finishes processing the task, it releases the task data in the cache area.
[0003] In the prior art, the terminal device releases the task data in the cache area based on the binder thread; the binder thread needs to wait to be scheduled before it can release the task data in the cache area.
[0004] However, in the above method, the binder thread is often not scheduled in time, so that the terminal device cannot release the task data in the cache area based on the binder thread in time; resulting in the terminal device being unable to process new tasks in time. Summary of the Invention
[0005] Embodiments of this application provide a thread scheduling method based on a terminal device, a terminal device, and a medium, which are applied to the technical field of terminals and can schedule the binder thread to release the task data in the cache area in time, avoiding the problem that the terminal device cannot process new tasks in time.
[0006] In a first aspect, embodiments of this application propose a thread scheduling method based on a terminal device. The method is applied to a processor of the terminal device. A first thread and a first process are running in the processor. A cache area is set in the processor. Among them, 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 cache area is used to cache the task data of the task. The method includes:
[0007] When it is determined based on the first thread that the buffer area needs to be released, a release instruction is sent to the kernel layer of the processor based on the first thread, and the release instruction is used to indicate the release of the task data in the buffer area; based on the kernel layer, according to the release instruction, the processing priority of the second thread is modified from the first priority to the second priority; wherein, the processing priority of the second priority is higher than that of the first priority; based on the kernel layer of the processor sending the release instruction to the second thread in the first process, based on the second thread with the second priority, the task data in the buffer area is released.
[0008] In this way, when it is necessary to release the task data in the buffer area, the processor priority of the second thread can be first increased, so that the second thread will be preferentially scheduled to release the task data in the buffer area. That is, the priority of the second thread of the first process is increased during the execution of releaseBufferCallback, so that the second thread can be scheduled in time to release the buffer area.
[0009] Since the second thread can be retrieved in time, the second thread can release the task data in the buffer area in time, further enabling the first process to cache the new task data in the buffer area in time, so that the first thread can obtain the new task data from the buffer area in time to process the task; avoiding the problem that the terminal device cannot perform the task based on the new task data. Thus, the terminal device can process the task in time.
[0010] In a possible implementation manner, the first priority is a priority characterizing non-real-time scheduling, and the second priority is a priority characterizing real-time scheduling. In this way, it is ensured that the second priority is the RT priority.
[0011] In a possible implementation manner, based on the kernel layer, according to the release instruction, modifying the processing priority of the second thread from the first priority to the second priority includes:
[0012] Based on the kernel layer, according to the release instruction, if it is determined that the first thread and the first process meet the preset conditions, the processing priority of the second thread is modified from the first priority to the second priority.
[0013] In this way, when it is determined that certain conditions are met, the processing priority of the second thread will be increased to ensure that other threads can also process tasks normally.
[0014] In a possible implementation manner, the kernel layer stores a binder communication number and an interface descriptor, the binder communication number is used to indicate the communication interface, and the interface descriptor is used to indicate the initiating end and the processing end of the communication.
[0015] Based on the kernel layer according to the release instruction, if it is determined that the first thread and the first process meet the preset conditions, the processing priority of the second thread is modified from the first priority to the second priority, including: based on the kernel layer according to the release instruction, if it is determined that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiator of the communication is the first thread and the processing end of the communication is the first process, the processing priority of the second thread is modified from the first priority to the second priority.
[0016] In this way, the kernel layer of the processor determines that the processing priority of the second thread can be increased only after determining that the first thread initiates communication to the first process.
[0017] In a possible implementation, the kernel layer further stores an asynchronous communication identifier, and the asynchronous communication identifier is used to indicate a communication mode.
[0018] Before changing the processing priority of the second thread from the first priority to the second priority, it also includes: based on the kernel layer, if it is determined that the asynchronous communication identifier indicates that the first thread and the first process are asynchronous binder communication, the processing priority of the second thread is changed from the first priority to the second priority.
[0019] In this way, after further determining that the communication between the first thread and the first process is asynchronous binder communication, the kernel layer of the processor determines that the processing priority of the second thread can be increased.
[0020] In a possible implementation, the method further includes: acquiring a first process ID based on the kernel layer, wherein the first process ID is used to indicate a process ID of the first process.
[0021] Before changing the processing priority of the second thread from the first priority to the second priority, the method further includes:
[0022] If it is determined based on the kernel layer that the first process number is consistent with the pre-stored second process number, and the pre-stored thread name is the thread name of the first thread, the processing priority of the second thread is modified from the first priority to the second priority; wherein, the pre-stored second process number is used to indicate the process number of the first process.
[0023] In this way, based on the binder communication number, it is determined that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread. It is determined that the initiator of the communication indicated by the interface descriptor is the first thread, and moreover, it is determined that the processing end of the communication indicated by the interface descriptor is the first process. Thus, the kernel layer of the processor determines that the first thread initiates communication with the first process. And the communication between the first thread and the first process is asynchronous binder communication, thereby excluding synchronous communication. Further, based on the process number and the thread name, it is further determined that it is the first process communicating with the first thread, and then the processing priority of the second thread is increased. In a possible implementation manner, obtaining the first process number based on the kernel layer includes:
[0024] Obtaining first switch information based on the first process, where the first switch information characterizes starting to modify the priority of the second thread; obtaining a first event based on the first process according to the first switch information, where the first event characterizes starting to modify the priority of the second thread; obtaining the first process number based on the first process according to the first event; and sending the first process number to the kernel layer based on the first process.
[0025] In this way, it is ensured that the kernel layer can obtain the process number of the first process to complete the judgment of the first process number.
[0026] In a possible implementation manner, the method further includes: if the second thread is in an idle state based on the kernel layer, then based on the kernel layer, restoring the processing priority of the second thread from the second priority to the first priority.
[0027] In this way, after each release of the cache area by the second thread is completed, the priority of the second thread is restored to ensure that other processes can execute normally.
[0028] In a possible implementation manner, the method further includes: obtaining second switch information based on the first process, where the second switch information characterizes closing the modification of the priority of the second thread; obtaining a second event based on the first process according to the second switch information, where the second event characterizes closing the modification of the priority of the second thread; and writing indication information into a preset file node based on the first process according to the second event, where the indication information characterizes closing the modification of the priority of the second thread.
[0029] In this way, when there is no need to process tasks anymore, the process of modifying the priority of the second thread in this solution is closed, and the modification of the priority of the second thread is no longer repeatedly executed. It saves the instructions of the processor and avoids unnecessary signaling overhead.
[0030] In a possible implementation, the first thread is a thread for synthesizing the animated effect image of the application, the first process is the desktop process, and the first process is a process for rendering the image data of the animated effect image.
[0031] In this way, the second thread of the first process has its priority elevated during the execution of releaseBufferCallback, so that the second thread can be scheduled in a timely manner to release the cache area. Since the second thread can be retrieved in a timely manner, the second thread can release the image data in the cache area in a timely manner, further enabling the first process to cache new image data in the cache area in a timely manner, so that the first thread can obtain new image data from the cache area in a timely manner to generate image frames; preventing the animated effect image displayed by the application from lagging. Moreover, since new image frames can be generated in a timely manner without frame drops, the animated effect image displayed by the application is prevented from experiencing frame drop phenomena.
[0032] In a possible implementation, the first thread is a thread for updating the window information of the system, and the first process is a process for generating the window data of the window information.
[0033] In this way, since the second thread can be retrieved in a timely manner, the second thread can release the window data in the cache area in a timely manner, further enabling the first process to cache new window data in the cache area in a timely manner, so that the first thread can obtain new window data from the cache area in a timely manner to update the window information of the system.
[0034] In a second aspect, an embodiment of the present application provides a terminal device, which can also be referred to as a terminal (terminal), user equipment (UE), mobile station (MS), mobile terminal (MT), etc. The terminal device can be a mobile phone, smart TV, wearable device, tablet computer (Pad), computer with wireless transceiver function, virtual reality (VR) terminal device, augmented reality (AR) terminal device, wireless terminal in industrial control, wireless terminal in self-driving, wireless terminal in remote medical surgery, wireless terminal in smart grid, wireless terminal in transportation safety, wireless terminal in smart city, wireless terminal in smart home, and so on.
[0035] The terminal device includes: a processor and a memory; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, so that the terminal device executes the method according to the first aspect.
[0036] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the method according to the first aspect is implemented.
[0037] In a fourth aspect, an embodiment of the present application provides a computer program product, and the computer program product includes a computer program. When the computer program is run, a computer is caused to execute the method according to the first aspect.
[0038] In a fifth aspect, an embodiment of the present application provides a chip, and the chip includes a processor. The processor is used to call a computer program in a memory to execute the method according to the first aspect.
[0039] It should be understood that the second to fifth aspects of the present application correspond to the technical solutions of the first aspect of the present application, and the beneficial effects obtained by each aspect and the corresponding feasible implementation manners are similar, and will not be elaborated herein. Description of the Drawings
[0040] Figure 1 A schematic diagram of a scenario applicable to the thread scheduling method based on a terminal device according to an embodiment of the present application is shown;
[0041] Figure 2 A schematic diagram of the structure of the terminal device 100 is shown;
[0042] Figure 3 It is a software structure block diagram of the terminal device 100 according to an embodiment of the present application;
[0043] Figure 4 Signaling of a thread scheduling method based on a terminal device provided by an embodiment of the present application Figure 1 ;
[0044] Figure 5 A schematic diagram of the frame drop percentage of the animated image provided by an embodiment of the present application;
[0045] Figure 6a A communication process of a thread scheduling method based on a terminal device provided by an embodiment of the present application Figure 1 ;
[0046] Figure 6b A communication process of a thread scheduling method based on a terminal device provided by an embodiment of the present application Figure 2 ;
[0047] Figure 7 The architecture of a thread scheduling method based on a terminal device provided by an embodiment of this application Figure 1 ;
[0048] Figure 8 The architecture of a thread scheduling method based on a terminal device provided by an embodiment of this application Figure 2 ;
[0049] Figure 9 The signaling of a thread scheduling method based on a terminal device provided by an embodiment of this application Figure 2 ;
[0050] Figure 10 The signaling of a thread scheduling method based on a terminal device provided by an embodiment of this application Figure 3 ;
[0051] Figure 11 The signaling of a thread scheduling method based on a terminal device provided by an embodiment of this application Figure 4 ;
[0052] Figure 12 The signaling of a thread scheduling method based on a terminal device provided by an embodiment of this application Figure 5 ;
[0053] Figure 13 The structural schematic diagram of a chip provided by an embodiment of this application;
[0054] Figure 14 The structural schematic diagram of a terminal device provided by an embodiment of this application. Detailed implementation manners
[0055] For the convenience of clearly describing the technical solutions of the embodiments of this application, in the embodiments of this application, words such as "exemplary" or "for example" are used to represent examples, illustrations or explanations. Any embodiment or design solution described as "exemplary" or "for example" in this application should not be construed as being more preferred or having more advantages than other embodiments or design solutions. Exactly speaking, using words such as "exemplary" or "for example" aims to present related concepts in a specific manner.
[0056] In the embodiments of the present application, "at least one" means one or more, and "a 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 may represent: A exists alone, A and B exist simultaneously, and B exists alone, where A and B may be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one (item)" or its similar expression refers to any combination of these items, including any combination of single item (s) or plural item (s). For example, at least one (item) of a, b, or c may represent: a, b, c, a - b, a - c, b - c, or a - b - c, where a, b, and c may be single or multiple.
[0057] It should be noted that "when... " in the embodiments of the present application may be at the instant when a certain situation occurs, or within a period of time after a certain situation occurs. The embodiments of the present application do not make specific limitations on this. In addition, the display interface provided in the embodiments of the present application is only an example, and the display interface may also include more or less content.
[0058] Currently, with the development of terminal technology, terminal devices have become important tools in people's lives. Terminal devices need to perform many tasks; for example, there are multiple applications in a terminal device, and during the process of running an application, the terminal device needs to display an animation image. For another example, the terminal device needs to update the window information of the system. During the process of processing tasks, the terminal device will cache the task data of the tasks in a cache area and process the tasks based on the task data in the cache area; then after the terminal device finishes processing the tasks, it releases the task data in the cache area.
[0059] In the prior art, the terminal device releases the task data in the cache area based on the binder thread; the binder thread needs to wait to be scheduled before it can release the task data in the cache area.
[0060] However, in the above - mentioned method, the situation where the binder thread cannot be scheduled in time often occurs, so that the terminal device cannot release the task data in the cache area based on the binder thread in time; as a result, the terminal device cannot process new tasks in time.
[0061] In one example, there are multiple applications in a terminal device, and the application needs to display an animation image. For example, when the application starts, it needs to display the animation image of the application based on the application; when the application closes, it needs to display the animation image of the application based on the application. During the process of the terminal device displaying the animation image, it needs to store the image data of the animation image in a cache area; the terminal device generates an animation image according to the image data in the cache area, and then releases the image data in the cache area.
[0062] The terminal device releases the image data in the cache area based on the binder thread; the binder thread needs to wait to be scheduled before it can release the image data in the cache area.
[0063] However, in the above method, during the process of the terminal device displaying the animated images of the application, the binder thread is often not scheduled in time, so that the terminal device cannot release the image data in the cache area based on the binder thread in time; as a result, the terminal device cannot generate new animated images in time, resulting in stuttering and frame dropping during the process of the terminal device displaying the animated images.
[0064] In view of this, the thread scheduling method, terminal device and medium based on the terminal device provided in the embodiments of the present application can schedule the binder thread in time to release the task data in the cache area, avoiding the problem that the terminal device cannot process new tasks in time.
[0065] Figure 1 The schematic diagram of the scenario applicable to the thread scheduling method based on the terminal device in the embodiments of the present application is shown. As Figure 1 shown, the terminal device 100 needs to process the tasks in the terminal device. For example, the terminal device 100 is used to display an application; when the application is started, the terminal device needs to display the animated images of the application based on the application; when the application is closed, the terminal device needs to display the animated images of the application based on the application.
[0066] The terminal device 100 can also be referred to as a terminal, user equipment (UE), mobile station (MS), mobile terminal (MT), etc. The terminal device can be a mobile phone, smart TV, wearable device, tablet computer (Pad), computer with wireless transceiver function, virtual reality (VR) terminal device, augmented reality (AR) terminal device, wireless terminal in industrial control, wireless terminal in self-driving, wireless terminal in remote medical surgery, wireless terminal in smart grid, wireless terminal in transportation safety, wireless terminal in smart city, wireless terminal in smart home, etc. The embodiments of the present application do not limit the specific technologies and specific device forms adopted by the terminal device.
[0067] The terminal device 100 has the function of a display interface.
[0068] To better understand the embodiments of the present application, the structure of the terminal device in the embodiments of the present application will be introduced below:
[0069] Figure 2 A schematic structural diagram of the terminal device 100 is shown. The terminal device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an 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, a headphone interface 170D, a sensor module 180, a key 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. Among them, the sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0070] It can be understood that the structure schematically shown in the embodiments of the present application does not constitute a specific limitation on the terminal device 100. In other embodiments of the present application, the terminal device 100 may include more or fewer components than shown, or combine certain components, or split certain components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0071] The processor 110 may include one or more processing units. For example, the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units may be independent devices or integrated in one or more processors.
[0072] The controller may generate operation control signals according to the instruction operation code and timing signals to complete the control of fetching and executing instructions.
[0073] A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory may save the instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be called from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0074] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0075] It should be understood that the interface connection relationships between the modules illustrated in the embodiments of the present application are for illustrative purposes only and do not constitute a structural limitation on the terminal device 100. In other embodiments of the present application, the terminal device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0076] The wireless communication function of the terminal device 100 can be implemented by the antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modulation and demodulation processor, and baseband processor, etc.
[0077] The antenna 1 and the antenna 2 are used to transmit and receive electromagnetic wave signals. The antennas in the terminal device 100 can be used to cover single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization rate of the antennas. For example: the antenna 1 can be multiplexed as the diversity antenna of the wireless local area network. In some other embodiments, the antenna can be used in combination with a tuning switch.
[0078] The terminal device 100 realizes the display function through the GPU, the display screen 194, and the application processor, etc. The GPU is a microprocessor for image processing, and is connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs, which execute program instructions to generate or change display information.
[0079] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can adopt a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Miniled, a MicroLed, a Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the terminal device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0080] The terminal device 100 can realize the shooting function through the ISP, the camera 193, the video codec, the GPU, the display screen 194, and the application processor, etc.
[0081] 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. Among them, the program storage area can store an operating system, application programs required for at least one function (such as a sound playback function, an image playback function, etc.). The data storage area can store data created during the use of the terminal device 100 (such as audio data, a phone book, etc.). In addition, the internal memory 121 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc. The processor 110 executes various functional applications and data processing of the terminal device 100 by running the instructions stored in the internal memory 121 and / or the instructions stored in the memory provided in the processor.
[0082] The terminal device 100 can implement audio functions through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone interface 170D, and the application processor, etc. Such as music playback, recording, etc.
[0083] The software system of the terminal device 100 can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservices architecture, or a cloud architecture, etc. In the embodiments of the present application, taking the Android system with a layered architecture as an example, the software structure of the terminal device 100 is exemplarily described.
[0084] Figure 3 It is the software structure block diagram of the terminal device 100 in the embodiments of the present application.
[0085] The layered architecture divides the software into several layers, and each layer has a clear role 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 are the application layer, the application framework layer, the Android runtime and the system libraries, and the kernel layer.
[0086] The application layer can include a series of application packages.
[0087] As Figure 3 shown, the application packages can include applications such as a camera, a calendar, a phone, a map, a phone, music, settings, an email, a video, and social applications.
[0088] The application framework layer provides application programming interfaces (APIs) and programming frameworks for the applications in the application layer. The application framework layer includes some predefined functions.
[0089] As shown Figure 3 in the figure, the application framework layer may include a window manager, a content provider, a resource manager, a view system, a notification manager, etc.
[0090] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, touch the screen, drag the screen, capture the screen, etc.
[0091] The content provider is used to store and obtain data, and make this data accessible to application programs. The data may include videos, images, audio, incoming and outgoing calls, browsing history and bookmarks, phone books, etc.
[0092] The view system includes visible controls, such as controls for displaying text, controls for displaying pictures, etc. The view system can be used to build application programs. The display interface can be composed of one or more views. For example, a display interface including a text message notification icon may include a view for displaying text and a view for displaying pictures.
[0093] The resource manager provides various resources for application programs, such as localized strings, icons, pictures, layout files, video files, etc.
[0094] The system library may include multiple functional modules. For example: surface manager, Media Libraries, 3D graphics processing library (e.g., OpenGL ES), 2D graphics engine (e.g., SGL), etc.
[0095] The surface manager is used to manage the display subsystem and provide the fusion of 2D and 3D layers for multiple application programs.
[0096] The media library supports the playback and recording of various common audio and video formats, as well as static image files, etc. The media library can support multiple audio and video coding formats, such as: MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, etc.
[0097] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis, and layer processing, etc.
[0098] The 2D graphics engine is a drawing engine for 2D drawing.
[0099] The kernel layer is the layer between hardware and software. The kernel layer at least includes a display driver, a camera driver, an audio driver, and a sensor driver.
[0100] Next, in combination with the scenario of application startup or interface switching in an application, the working processes of the software and hardware of the terminal device 100 will be exemplarily described.
[0101] The following will introduce in detail the process of thread scheduling based on applications in a terminal device in conjunction with the accompanying drawings. It should be noted that in the embodiments of the present application, "when..." can be at the instant when a certain situation occurs or within a period of time after a certain situation occurs. The embodiments of the present application do not make specific limitations on this.
[0102] Figure 4 Signaling for a thread scheduling method provided by an embodiment of the present application based on a terminal device Figure 1 As Figure 4 shown, the method may include:
[0103] S401. Obtain a first process number based on the kernel layer, where the first process number is used to indicate the process number of a first process.
[0104] Among them, a first thread and a first process are running in the processor, a cache area is set in the processor, where 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 cache area is used to cache task data of the task.
[0105] In one example, the first thread is a thread for synthesizing the animated image of the application, the first process is the desktop process, and the first process is a process for drawing the image data of the animated image. Or, the first thread is a thread for updating the window information of the system, and the first process is a process for generating the window data of the window information.
[0106] In one example, step S401 includes the following process:
[0107] Obtain first switch information based on the first process, where the first switch information represents starting to modify the priority of the second thread;
[0108] Obtain a first event based on the first process according to the first switch information; where the first event represents starting to modify the priority of the second thread;
[0109] Obtain the first process number based on the first process according to the first event; and send the first process number to the kernel layer based on the first process.
[0110] Exemplarily, with the development of terminal technology, terminal devices have become important tools in people's lives. Terminal devices require many tasks. In the process of processing tasks, terminal devices need to generate task data for tasks; then, terminal devices process tasks based on the task data.
[0111] The processor of the terminal device runs a first thread and a first process. Among them, the first process includes multiple threads, and the first process includes a second thread, and the second thread is a binder thread.
[0112] The processor of the terminal device has a cache area (buffer area), and the cache area is used to cache the task data of the tasks of the terminal device.
[0113] During the process of the terminal device processing a task, the terminal device generates task data based on other threads in the first process; the generation of the task data takes a certain amount of time. Then, the processor stores the task data into the cache area based on the first process, and then caches the task data based on the cache area.
[0114] The processor obtains the task data from the cache area based on the first thread, and the processor processes the obtained task data based on the first thread to obtain the processed task data; at this time, the task data in the cache area will not be deleted or moved. For example, the processor synthesizes and processes the obtained task data in the cache area based on the first thread; or, the processor copies the task data from the cache area based on the first thread to obtain the copied task data, and then the processor processes the copied task data based on the first thread.
[0115] Then, the processor processes the task based on the processed task data.
[0116] Then, the processor notifies the second thread based on the first thread to release the task data in the cache area. Then, the process of generating the task data and releasing the cache area is repeated again. The above process of releasing the cache area can be called releaseBufferCallback.
[0117] However, during the above process of releasing the cache area, the processor needs to notify the second thread in the first process based on the first thread to release the task data in the cache area. At this time, it is necessary to schedule the second thread to release the task data in the cache area. The second thread is a type of binder thread. After the processor notifies the second thread in the first process based on the first thread, the second thread of the processor needs to wait before it can process the task data in the cache area; the scheduling process of the second thread requires a certain queuing time. Especially when the processor is under high load, the second thread needs to wait for a long time before it can be scheduled to release the task data in the cache area, and the second thread may even never be scheduled. Thus, the second thread is in a waiting state for a long time (runnable state, where the runnable state means that the thread is runnable but needs to continue waiting).
[0118] As a result, since the second thread is in a waiting state for a long time, it cannot release the task data in the cache area in a timely manner, resulting in the first process being unable to cache new task data in the cache area in a timely manner. Consequently, the first thread cannot obtain new task data from the cache area in a timely manner to process tasks, leading to the terminal device being unable to process tasks in a timely manner.
[0119] In one example, the terminal device has multiple applications. During the process of running the applications, the terminal device needs to display animated images. The terminal device has multiple applications, and the applications need to display animated images. The applications running on the terminal device have key animated scenarios, that is, the applications on the terminal device need to display animated images. For example, when an application starts, it is necessary to display the animated image of the application based on the application; when an application is closed, it is necessary to display the animated image of the application based on the application. The animation of the application is composed of multiple frames of animated images (i.e., image frames).
[0120] The processor of the terminal device runs a first process and a first thread. Among them, the first process is the desktop process (Launcher process), and the first thread is the surfaceFlinger thread. The first process is a process for drawing image data; the first process includes multiple threads. The desktop process includes the desktop main thread (UIThread), the rendering thread (render thread), the second thread, and so on; the second thread is the binder thread. The first thread is a thread for synthesizing the animated images of the application.
[0121] The processor of the terminal device has a cache area (buffer area), and the cache area is used to cache the image data of the animated images of the application.
[0122] During the process of the terminal device displaying animated images, the processor draws image data based on the desktop main thread and the rendering thread in the first process. For example, it takes about 48 milliseconds (ms) for the desktop main thread and the rendering thread to draw image data. Then, the processor stores the image data in the cache area based on the first process, and further caches the image data based on the cache area.
[0123] The processor obtains image data from the cache area based on the first thread, and the processor performs synthesis processing on the obtained image data based on the first thread to obtain an animated image; at this time, the image data in the cache area will not be deleted or moved.
[0124] Then, the processor displays the animated image based on the first thread, and further enables the application of the terminal device to display the animated image.
[0125] Then, the processor notifies the second thread to release the image data in the cache area based on the first thread. Then, the first process can cache new image data in the cache area; thus, the first process and the first thread can continue to use the image data in the cache area. Then, the process of generating the animated image and releasing the cache area is repeated again.
[0126] However, in the above process of releasing the cache area, the processor needs to notify the second thread in the first process to release the image data in the cache area based on the first thread. At this time, it is necessary to schedule the second thread to release the image data in the cache area. The second thread is a binder thread. After the processor notifies the second thread based on the first thread, the second thread of the processor needs to wait before it can process the image data in the cache area; thus, the scheduling process of the second thread requires a certain queuing time; especially when the processor is under high load, the second thread needs to wait for a long time before it can be scheduled to release the image data in the cache area, and the second thread may even never be scheduled. Thus, the second thread is in a waiting state for a long time.
[0127] Thus, because the second thread is in a waiting state for a long time, the second thread cannot release the image data in the cache area in time, resulting in the first process not being able to cache new image data in the cache area in time, and thus the first thread cannot obtain new image data from the cache area in time to generate image frames; resulting in stuttering of the animated image displayed by the application. Also, because it takes a certain amount of time to generate each image frame, and new image frames cannot be generated in time, image frames will be lost, and subsequent image frames will be directly displayed, resulting in frame drops; for example, the first image frame has been generated, and it takes 16 ms to generate one image frame, but it has waited for 48 ms, so it may result in the loss of the second and third image frames, and the fourth image frame is directly displayed, resulting in a frame drop phenomenon.
[0128] Also, through experimental analysis, Figure 5 is a schematic diagram of the frame drop percentage of the animated image provided by the embodiment of the present application. As Figure 5 shown, Figure 5 the abscissa of Figure 5 is the version of the terminal device, Figure 5 and the ordinate of
[0129] is the frame drop percentage (percentage); thus, it can be seen from that when the application of the terminal device is started or closed, frame drops and stuttering often occur. Especially when the application is continuously exited, frame drops and stuttering often occur.Moreover, through code analysis of the reasons for frame drops and freezes, it is found that the scheduling of releaseBufferCallback is not timely, resulting in a relatively large number of frame drops and freezes. That is, the scheduling of the binder thread is not timely, resulting in a relatively large number of frame drops and freezes. The frame drops and freezes caused by the untimely scheduling of releaseBufferCallback account for 35% of the reasons for frame drops and freezes.
[0130] In another example, there are multiple applications in the terminal device. During the operation of the applications, the terminal device needs to update the window information of the system.
[0131] The processor of the terminal device runs a first process and a first thread. Among them, the first process is a system service process (system service process), and the first thread is a surfaceFlinger thread. Among them, the first process is a process for generating window data for window information; the first process includes multiple threads, such as the first process includes a second thread, etc.; the second thread is a binder thread. The first thread is a thread for updating the window information of the system.
[0132] There is a buffer area (buffer area) in the processor of the terminal device, and the buffer area is used to cache window data.
[0133] During the process of the terminal device processing tasks, the terminal device generates window data based on other threads in the first process; the generation of window data takes a certain amount of time. Then, the processor stores the window data into the buffer area based on the first process, and then caches the window data based on the buffer area.
[0134] The processor obtains the window data from the buffer area based on the first thread, and the processor processes the obtained window data based on the first thread to obtain the processed window data; at this time, the window data in the buffer area will not be deleted or moved. For example, the processor synthesizes and processes the obtained window data in the buffer area based on the first thread; or, the processor copies the window data from the buffer area based on the first thread to obtain the copied window data, and then the processor processes the copied window data based on the first thread.
[0135] Then, the processor updates the window information of the system based on the processed window data.
[0136] Then, the processor notifies the second thread to release the window data in the buffer area based on the first thread. Then, the first process can cache the new window data into the buffer area; thus, the first process and the first thread can continue to use the window data in the buffer area. Then, the process of generating window data and releasing the buffer area is repeated again.
[0137] However, in the process of releasing the cache area mentioned above, the processor needs to notify the second thread in the first process to release the window data in the cache area based on the first thread. At this time, it is necessary to schedule the second thread to release the window data in the cache area. The second thread is a binder thread. After the processor notifies the second thread based on the first thread, the second thread of the processor needs to wait before it can process the window data in the cache area. Therefore, there is a certain queuing time in the scheduling process of the second thread. Especially when the processor is under high load, the second thread needs to wait for a long time before it can be scheduled to release the window data in the cache area, and the second thread may even never be scheduled. Thus, the second thread is in a waiting state for a long time.
[0138] Therefore, due to the long waiting state of the second thread, the second thread cannot release the window data in the cache area in time, resulting in the first process being unable to cache the new window data into the cache area in time, and thus the first thread cannot obtain the new window data from the cache area in time; this causes the terminal device to be unable to update the window information in time.
[0139] Therefore, based on the thread scheduling method for the terminal device provided in this embodiment, it is possible to avoid the terminal device from being unable to process tasks in time.
[0140] Among them, the processor of the terminal device runs a first thread and a first process. The first thread is a thread for processing tasks; the first process includes multiple threads, and the first process includes a second thread, and the second thread is a binder thread. The processor of the terminal device has a cache area for caching task data. The cache area can be independent of the first thread, that is, the cache area is not set in the first thread.
[0141] During the process of the processor of the terminal device processing tasks, the processor needs to pass the first process ID to the kernel layer; the first process ID is the process ID of the first process.
[0142] The process of passing the first process ID is as follows: The first process of the processor first obtains the first switch information, where the first switch information indicates the start of modifying the priority of the second thread, that is, the first switch information indicates the start of this solution. Then, the first process of the processor obtains the first event according to the first switch information, and the first event indicates the start of modifying the priority of the second thread. Then, the first process of the processor obtains the first process ID according to the first event, that is, obtains the process ID of the first process; then the first process of the processor sends the first process ID to the second thread. The second thread belongs to the first process; the first process includes multiple threads.
[0143] In one example, the processor of the terminal device runs a first process and a first thread. Among them, the first process is the desktop process (Launcher process), and the first thread is the surfaceFlinger thread. Among them, the first process is a process for drawing image data; the first process includes multiple threads, the first process includes the desktop main thread (UIThread), the rendering thread (render thread), the second thread, and so on; the second thread is the binder thread. The first thread is a thread for synthesizing the dynamic effect images of the application.
[0144] The processor of the terminal device has a buffer area (buffer region), and the buffer area is used to cache the image data of the dynamic effect images of the application.
[0145] The processor of the terminal device has a buffer area, and the buffer area is used to cache the image data of the dynamic effect images of the application. Among them, the buffer area can be independent of the first thread, that is, the buffer area is no longer set in the first thread.
[0146] During the process of the terminal device displaying the dynamic effect images, the processor performs the drawing of the image data based on the desktop main thread and the rendering thread in the first process.
[0147] When the processor starts or closes an application, the application needs to display a dynamic effect. Thus, the processor first passes the first process ID to the second thread through the first process, where the first process ID is the process ID of the first process.
[0148] The process of passing the first process ID (that is, the process ID of the first process) is as follows: The first process of the processor first obtains the first switch information, where the first switch information indicates the start of modifying the priority of the second thread, that is, the first switch information indicates the start of this solution. Then, the first process of the processor obtains the first event according to the first switch information, and the first event indicates the start of modifying the priority of the second thread. Then, the first process of the processor obtains the first process ID according to the first event, that is, obtains the process ID of the first process; then the first process of the processor sends the first process ID to the second thread. Among them, the second thread belongs to the first process; the first process includes multiple threads.
[0149] S402. When it is determined that the buffer area needs to be released based on the first thread, a release instruction is sent to the kernel layer of the processor based on the first thread, and the release instruction is used to indicate the release of the task data in the buffer area.
[0150] Exemplarily, during the process of the terminal device processing a task, other processes in the first process of the processor of the terminal device generate task data; among them, the generation of the task data takes a certain amount of time.
[0151] Then, the first process of the processor stores the task data in the cache area, and then caches the task data based on the cache area.
[0152] The first thread of the processor obtains the task data from the cache area. The first thread of the processor processes the obtained task data to obtain the processed task data, and the task data in the cache area will not be deleted or moved. For example, the first thread of the processor performs a synthesis process on the obtained task data in the cache area; or, the first thread of the processor copies the task data from the cache area to obtain the copied task data, and then the first thread of the processor performs a synthesis process on the copied task data.
[0153] Then, the first thread of the processor processes the task according to the processed task data.
[0154] Then, after completing a task processing process, the first thread of the processor can determine that the cache area needs to be released. The first thread of the processor sends a release instruction to the kernel layer of the processor, and the release instruction is used to indicate the release of the task data in the cache area.
[0155] In an example, during the process of the terminal device displaying an animated image, the desktop main thread and the rendering thread in the first process of the processor perform the drawing of image data. For example, it takes about 48 milliseconds (ms) for the desktop main thread and the rendering thread to draw the image data. Then, the first process of the processor stores the image data in the cache area, and then caches the image data based on the cache area.
[0156] The first thread of the processor obtains the image data from the cache area. The first thread of the processor performs a synthesis process on the obtained image data to obtain an animated image; at this time, the image data in the cache area will not be deleted or moved. For example, the first thread of the processor performs a synthesis process on the obtained image data in the cache area; or, the first thread of the processor copies the image data from the cache area to obtain the copied image data, and then the first thread of the processor performs a synthesis process on the copied image data.
[0157] Then, the first thread of the processor displays the animated image, thereby enabling the application of the terminal device to display the key animation effect.
[0158] Then, since a display process is completed, the first thread of the processor can determine that the cache area needs to be released. The first thread of the processor sends a release instruction to the kernel layer of the processor, and the release instruction is used to indicate the release of the image data in the cache area.
[0159] S403. Based on the kernel layer, according to the release instruction, modify the processing priority of the second thread from the first priority to the second priority; wherein, the processing priority of the second priority is higher than that of the first priority.
[0160] In one example, the first priority is the priority representing non-real-time scheduling, and the second priority is the priority representing real-time scheduling.
[0161] In one example, step S403 includes: based on the kernel layer, according to the release instruction, if it is determined that the first thread and the first process meet the preset conditions, then modify the processing priority of the second thread from the first priority to the second priority.
[0162] In one example, step S403 includes the following implementation manners:
[0163] The first implementation manner of step S403: The kernel layer stores a binder communication number and an interface descriptor. The binder communication number is used to indicate the communication interface, and the interface descriptor is used to indicate the initiating end and the processing end of the communication.
[0164] Based on the kernel layer, according to the release instruction, if it is determined that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiating end of the communication is the first thread and the processing end of the communication is the first process, then modify the processing priority of the second thread from the first priority to the second priority.
[0165] The second implementation manner of step S403: The kernel layer stores a binder communication number and an interface descriptor. The binder communication number is used to indicate the communication interface, and the interface descriptor is used to indicate the initiating end and the processing end of the communication; the kernel layer also stores an asynchronous communication identifier, and the asynchronous communication identifier is used to indicate the communication mode.
[0166] Based on the kernel layer, according to the release instruction, if it is determined that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiating end of the communication is the first thread and the processing end of the communication is the first process, and the asynchronous communication identifier indicates that the communication between the first thread and the first process is an asynchronous binder communication, then modify the processing priority of the second thread from the first priority to the second priority.
[0167] The third implementation manner of step S403: The kernel layer stores a binder communication number and an interface descriptor. The binder communication number is used to indicate the communication interface, and the interface descriptor is used to indicate the initiating end and the processing end of the communication; the kernel layer also stores an asynchronous communication identifier, and the asynchronous communication identifier is used to indicate the communication mode.
[0168] Based on the kernel layer according to the release instruction, if it is determined that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiating end of the communication is the first thread and the processing end of the communication is the first process, and the asynchronous communication identifier indicates that the asynchronous binder communication is between the first thread and the first process, and the first process ID is consistent with the pre-stored second process ID, and the pre-stored thread name is the thread name of the first thread, then the processing priority of the second thread is modified from the first priority to the second priority.
[0169] Exemplarily, the kernel layer of the processor can directly respond to the first release instruction to modify the processing priority of the second thread, changing the processing priority of the second thread from the first priority to the second priority, thereby enhancing the processing priority of the second thread; wherein, the processing priority of the second priority is higher than that of the first priority.
[0170] The kernel layer of the processor can also respond to the release instruction to determine whether it is necessary to increase the priority of the second thread. If the kernel layer of the processor determines that the first thread and the first process meet the preset conditions, then the processing priority of the second thread is enhanced.
[0171] In one example, the binder communication number and the interface descriptor are stored in the kernel layer of the processor. During the process of processing tasks, the kernel layer of the processor obtains the encapsulated data passed from the application framework layer (Framework) or the system runtime library layer (native), and the encapsulated data includes the binder communication number and the interface descriptor.
[0172] Among them, the binder communication number is used to indicate the communication interface. Thus, the binder communication number can indicate that there is a communication between classes of 2 processes (or between classes of 2 threads, or between a class of 1 process and a class of 1 thread); the binder communication number can indicate which communication interface is the communication interface between 2 classes.
[0173] The interface descriptor is used to indicate the initiating end and the processing end of the communication. Thus, the interface descriptor can indicate which thread (or process) is the initiating end of the communication and which process (or thread) is the initiating end of the communication. That is, the interface descriptor indicates which 2 classes are to communicate.
[0174] Based on the release instruction, if the kernel layer of the processor determines that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, determines that the interface descriptor indicates that the initiating end of the communication is the first thread, and determines that the interface descriptor indicates that the processing end of the communication is the first process, then the kernel layer of the processor determines that the first thread initiates communication with the first process. Then, the kernel layer of the processor determines that it can adjust the processing priority of the second thread, and the kernel layer of the processor changes the processing priority of the second thread from the first priority to the second priority, thereby enhancing the processing priority of the second thread.
[0175] In another example, the binder communication number, the interface descriptor, and the asynchronous communication identifier are stored in the kernel layer of the processor. During the process of processing tasks, the kernel layer of the processor obtains the encapsulated data passed from the application framework layer (Framework) or the system runtime library layer (native). The encapsulated data includes the binder communication number, the interface descriptor, and the asynchronous communication identifier.
[0176] Among them, the binder communication number is used to indicate the communication interface. Thus, the binder communication number can indicate that there is communication between classes of two processes (or between classes of two threads, or between a class of one process and a class of one thread); the binder communication number can indicate which communication interface is the communication interface between two classes.
[0177] The interface descriptor is used to indicate the initiating end and the processing end of the communication. Thus, the interface descriptor can indicate which thread (or process) is the initiating end of the communication, and which process (or thread) is the initiating end of the communication. That is, the interface descriptor indicates which two classes are to communicate.
[0178] The asynchronous communication identifier is used to indicate the communication method. Thus, the asynchronous communication identifier can indicate the communication method between the initiating end and the processing end of the communication, whether it is asynchronous binder communication.
[0179] Based on the release instruction, if the kernel layer of the processor determines that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, determines that the interface descriptor indicates that the initiating end of the communication is the first thread, and determines that the interface descriptor indicates that the processing end of the communication is the first process, then the kernel layer of the processor determines that the first thread initiates communication with the first process, and the communication between the first thread and the first process is asynchronous binder communication. Then, the kernel layer of the processor determines that it can adjust the processing priority of the second thread, and the kernel layer of the processor changes the processing priority of the second thread from the first priority to the second priority, thereby enhancing the processing priority of the second thread.
[0180] In another example, a binder communication number, an interface descriptor, and an asynchronous communication identifier are stored in the kernel layer of the processor. During the process of processing tasks, the kernel layer of the processor obtains the encapsulated data passed from the application framework layer (Framework) or the system runtime library layer (native). The encapsulated data includes a binder communication number, an interface descriptor, and an asynchronous communication identifier.
[0181] Among them, the binder communication number is used to indicate the communication interface. Thus, the binder communication number can indicate that communication is to occur between classes of two processes (or between classes of two threads, or between a class of one process and a class of one thread); the binder communication number can indicate which communication interface is the communication interface between two classes.
[0182] The interface descriptor is used to indicate the initiating end and the processing end of the communication. Thus, the interface descriptor can indicate which thread (or process) is the initiating end of the communication, and which process (or thread) is the initiating end of the communication. That is, the interface descriptor indicates which two classes are to communicate.
[0183] The asynchronous communication identifier is used to indicate the communication method. Thus, the asynchronous communication identifier can indicate the communication method between the initiating end and the processing end of the communication, whether it is an asynchronous binder communication.
[0184] Moreover, during the process of the processor processing tasks, the data maintained by the kernel layer of the processor includes the process ID of the first process, that is, the kernel layer of the processor stores the process ID of the second process. The data maintained by the kernel layer of the processor also includes the thread name of the first thread, that is, the kernel layer of the processor stores the pre-stored thread name.
[0185] During the process of processing tasks, since the kernel layer of the processor has obtained the first process ID, the first process ID is used to indicate the process ID of the first process.
[0186] Thus, the kernel layer of the processor can first determine that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, determine that the interface descriptor indicates that the initiating end of the communication is the first thread, and determine that the interface descriptor indicates that the processing end of the communication is the first process. Thus, the kernel layer of the processor determines that the first thread initiates communication with the first process, and the communication between the first thread and the first process is an asynchronous binder communication.
[0187] Then, the kernel layer of the processor determines whether the first process ID is the same as the pre-stored second process ID and whether the pre-stored thread name is the thread name of the first thread. If the kernel layer of the processor determines that the first process ID is the same as the pre-stored second process ID and the pre-stored thread name is the thread name of the first thread, it can further determine that the first thread initiates communication with the first process.
[0188] Then, the kernel layer of the processor determines that the processing priority of the second thread can be adjusted. The kernel layer of the processor modifies the processing priority of the second thread from the first priority to the second priority, thereby enhancing the processing priority of the second thread.
[0189] Among them, during the process of releasing the image data in the cache area, the initiating end is the surfaceflinger thread, and the processing end is the Launcher process. During the process of releasing the window data in the cache area, the initiating end is the surfaceflinger thread, and the processing end is the system service process.
[0190] Among them, the first priority is the priority of non-real-time scheduling, and the processing priority of the first priority is low; for example, the processing priority of the first priority is 120. The second priority is the priority representing real-time scheduling, and the processing priority of the second priority is higher. The processing priority of the second priority is higher than that of the first priority; for example, the second priority is the RT priority.
[0191] Thus, after the kernel layer of the processor modifies the processing priority of the second thread from the first priority to the second priority, the processing priority of the second thread can be enhanced.
[0192] Among them, the above asynchronous communication means that after the first thread notifies the second thread in the first process that the task data in the cache area needs to be released, the first thread continues to process other tasks, and the second thread in the first process releases the task data in the cache area.
[0193] Moreover, the first thread needs to initiate asynchronous binder communication to release the cache area, and the second thread belongs to the threads in the first process. Thus, during the process of releasing the task data in the cache area, the initiating end is the first thread, and the processing end is the first process. The first thread needs to modify the processing priority of the second thread through the kernel layer of the processor; it can be seen that the first thread needs to send a release instruction to the kernel layer, and then after the kernel layer modifies the processing priority of the second thread, the kernel layer sends a release instruction to the second thread to trigger the second thread to release the task data in the cache area.
[0194] S404. Based on the kernel layer of the processor, send a release instruction to the second thread in the first process.
[0195] Exemplarily, the kernel layer of the processor sends a release instruction to the second thread, and the release instruction is used to indicate the release of the image data in the cache area.
[0196] S405. Release the task data in the cache area based on the second thread with the second priority.
[0197] Exemplarily, the second thread of the processor has the second priority, and the second priority is the RT priority; thus, the second thread of the processor will be preferentially scheduled.
[0198] Then, the second thread of the processor releases the task data in the cache area. Then, the first process can cache the new task data into the cache area, and then overwrite the task data in the cache area with the new task data; thus, the first process and the first thread can continue to use the task data in the cache area. Then, the process of generating the task data and the process of releasing the cache area in this solution are repeated again.
[0199] Thus, through the process of this embodiment, when it is necessary to release the task data in the cache area, the processor priority of the second thread can be first increased, so that the second thread will be preferentially scheduled to release the task data in the cache area. That is, the second thread of the first process is increased in priority during the execution of releaseBufferCallback, so that the second thread can be scheduled in time to release the cache area.
[0200] Since the second thread can be retrieved in time, the second thread can release the task data in the cache area in time, further enabling the first process to cache the new task data into the cache area in time, so that the first thread can obtain the new task data from the cache area in time to process the task; avoiding the problem that the terminal device cannot perform the task based on the new task data. Thus, the terminal device can process the task in time.
[0201] In one example, the second thread of the processor will be preferentially scheduled; then, the second thread of the processor releases the image data in the cache area. The second thread of the processor modifies the first identifier of the image data in the cache area to a second identifier, where the first identifier indicates that the image data is being used, and the second identifier indicates that the image data is not being used; thus, the second thread of the processor releases the image data in the cache area. Then, the first process can cache the new image data into the cache area, and then overwrite the image data in the cache area with the new image data; thus, the first process and the first thread can continue to use the image data in the cache area. Then, the process of generating the animated image and the process of releasing the cache area in this solution are repeated again.
[0202] Thus, through the process of this embodiment, when it is necessary to release the image data in the cache area, the processor priority of the second thread can be first increased, so that the second thread will be preferentially scheduled to release the image data in the cache area. That is, the priority of the second thread of the first process is increased during the execution of releaseBufferCallback, so that the second thread can be scheduled in time to release the cache area.
[0203] Since the second thread can be retrieved in time, the second thread can release the image data in the cache area in time, further enabling the first process to cache new image data in the cache area in time, so that the first thread can obtain new image data from the cache area in time to generate an image frame; avoiding jitter in the dynamic effect images displayed by the application. And, since new image frames can be generated in time without frame loss, avoiding frame loss in the dynamic effect images displayed by the application.
[0204] By applying the solution of this embodiment, through comparison of experimental data, it can be known that the frame loss rate can be effectively reduced. For example, when the application is continuously started or continuously exited, by applying the solution of this embodiment, the frame loss rate can be reduced by more than 20%.
[0205] Figure 6a The communication process of a thread scheduling method based on a terminal device provided by an embodiment of the present application Figure 1 As Figure 6a shown.
[0206] S601a. The first thread sends a release instruction to the kernel layer, and the release instruction is used to indicate the release of task data in the cache area.
[0207] For example, the first thread is the (surfaceflinger thread).
[0208] S602a. The kernel layer modifies the processing priority of the second thread, changing the processing priority of the second thread from the first priority to the second priority.
[0209] Among them, the processing priority of the second priority is higher than the processing priority of the first priority.
[0210] S603a. The kernel layer finds the first process of the application, and the kernel layer initiates asynchronous binder communication. The kernel layer sends a release instruction to the second thread of the first process, and the release instruction is used to indicate the release of task data in the cache area.
[0211] It can be known that the second thread is a binder thread for releasing the cache area, and the second thread is a thread in the first process of the application. For example, the first process is the desktop process (Launcher process)
[0212] S604a. The second thread releases the task data in the cache area.
[0213] Thus, through steps S601a - S604a, the first thread notifies the second thread to release the cache area through the kernel layer. The kernel layer first promotes the second thread, so that the second thread with a high priority can be preferentially scheduled, and the second thread with a high priority releases the cache area.
[0214] Figure 6b This is the communication process of a thread scheduling method based on a terminal device provided by an embodiment of the present application. Figure 2 As Figure 6b shown.
[0215] S601b. The first thread sends a release instruction to the kernel layer, and the release instruction is used to indicate the release of the image data in the cache area.
[0216] Among them, the first thread is a thread for synthesizing the dynamic effect image of the application, the first process is the desktop process, and the first process is a process for drawing the image data of the dynamic effect image. The first thread is (the surfaceflinger thread).
[0217] S602b. The kernel layer modifies the processing priority of the second thread, and changes the processing priority of the second thread from the first priority to the second priority.
[0218] Among them, the processing priority of the second priority is higher than the processing priority of the first priority.
[0219] S603b. The kernel layer finds the first process of the application, the kernel layer initiates asynchronous binder communication, and the kernel layer sends a release instruction to the second thread of the first process, and the release instruction is used to indicate the release of the image data in the cache area.
[0220] It can be seen that the second thread is a binder thread for releasing the cache area, and the second thread is a thread in the first process of the application. For example, the first process is the desktop process (Launcher process)
[0221] S604b. The second thread releases the image data in the cache area.
[0222] Thus, through steps S601 - S604, the first thread notifies the second thread to release the cache area through the kernel layer. The kernel layer first promotes the second thread, so that the second thread with a high priority can be preferentially scheduled, and the second thread with a high priority releases the cache area.
[0223] S406. Based on the kernel layer, if the second thread is in an idle state, then based on the kernel layer, the processing priority of the second thread is restored from the second priority to the first priority.
[0224] Exemplarily, after the second thread finishes releasing the task data in the cache area, the second thread will be in an idle state; then, since the kernel layer of the processor maintains each process and thread, the kernel layer of the processor can directly determine that the second thread has finished releasing the task data in the cache area. Then, the kernel layer of the processor restores the processing priority of the second thread from the second priority to the first priority.
[0225] Each time it is necessary to release the cache area, the above steps S402 - S406 are executed.
[0226] In one example, the method provided in this embodiment further includes the following process:
[0227] Obtain second switch information based on the first process, where the second switch information represents turning off the priority modification of the second thread;
[0228] Obtain a second event based on the first process according to the second switch information; where the second event represents turning off the priority modification of the second thread;
[0229] Write indication information into a preset file node based on the first process according to the second event, where the indication information represents turning off the priority modification of the second thread.
[0230] Exemplarily, this embodiment can be closed, that is, it is determined not to execute the process of modifying the priority in this embodiment. At this time, the first process of the processor obtains the second switch information, where the second switch information represents turning off the priority modification of the second thread. Then, the first process of the processor obtains the second event; where the second event represents turning off the priority modification of the second thread.
[0231] Then, the first process of the processor writes indication information into the preset file node, and further writes information indicating turning off the priority modification of the second thread into the preset file node. Thus, the process of modifying the processing priority of the second thread is not executed.
[0232] Through the above steps, the priority modification of the second thread can be turned off, and the process of modifying the processing priority of the second thread is not executed.
[0233] Figure 7 For the architecture of a thread scheduling method based on a terminal device provided in an embodiment of the present application Figure 1 . Such as Figure 7As shown. The terminal device has a kernel layer (Kenrel), a hardware abstraction layer (HAL), a native layer, an application framework layer (Framwork), and an application layer. Among them, the hardware abstraction layer is not shown in Figure 7 The application layer interacts with the cloud platform for information.
[0234] The application layer includes multiple applications (APPs); a first process runs in the application layer; management software runs in the application layer. For example, the first process is the Launcher process.
[0235] The application framework layer includes the system's application framework. For example, in this solution applied to the Android system, the system's application framework is Android Framework. The application framework layer includes a process management module; a non-real-time processing subsystem in the process management module. The non-real-time processing subsystem includes a feature management module, a configuration management module, and a feature switch module.
[0236] The application layer interacts with the application framework layer, and then transmits start events (Start events), end events (End events), and feature switches.
[0237] The native layer includes Libs and ART modules. The Libs includes a processing module, and a first thread (surfaceflinger thread) runs in the Libs.
[0238] The application framework layer interacts with the native layer, and then sets the process ID of the first process. Among them, the first process supports asynchronous biander communication. Thus, the application framework layer passes the process ID of the first process to the native layer.
[0239] The kernel layer includes a Linux kernel (Linux Kernel) and a kernel extension subsystem. The kernel layer also performs binder communication.
[0240] The native layer interacts with the kernel layer, and then sets the process ID of the first process. Thus, the native layer passes the process ID of the first process (i.e., the first process ID) to the kernel layer.
[0241] Moreover, the kernel layer of the processor obtains the encapsulated data transmitted by the application framework layer (Framwork) or the native layer. The encapsulated data includes a binder communication number, an interface descriptor, and an asynchronous communication identifier.
[0242] Figure 8 This is the architecture of a thread scheduling method based on a terminal device provided by an embodiment of the present applicationFigure 2 As shown in Figure 8 . The terminal device has a kernel layer (Kenrel), a hardware abstraction layer (hardware abstraction layer, HAL), a system runtime library layer (native), an application framework layer (Framwork), and an application layer. Among them, the hardware abstraction layer is not shown in Figure 8 . The application layer interacts with the cloud platform for information.
[0243] The application layer includes multiple applications (APPs); a first process runs in the application layer; management software runs in the application layer. For example, the first process is the Launcher process.
[0244] The first process includes a first setting module. The first setting module is used to read the feature configuration (i.e., read the feature switch), and is used to send start events and end events. It can be seen that the first setting module is used to read the enable information and disable information. The enable information and disable information are stored in the configuration management module of the application framework layer; the feature configuration is the enable information or the disable information; among them, the enable information indicates the start of modifying the priority of the second thread; the disable information indicates the end of modifying the priority of the second thread. The start event (i.e., the first event) represents the start of modifying the priority of the second thread. The end event (i.e., the second event) represents the end of modifying the priority of the second thread.
[0245] Based on the read start information, the first process sends a start event (i.e., the first event) to the application framework layer. Based on the read end information, the first process sends an end event (i.e., the second event) to the application framework layer.
[0246] The application layer and the application framework layer interact, and then transmit the start event (Start event), the end event (End event), and the feature switch.
[0247] The application framework layer includes the application framework of the system. For example, in this solution, the Android system is applied, and the application framework of the system is Android Framework. The application framework layer includes a process management module; a non-real-time processing subsystem in the process management module. The non-real-time processing subsystem includes a second setting module and a configuration management module.
[0248] The second setting module is used to obtain the process ID of the first process (i.e., the first process ID). Among them, the first process supports asynchronous biander communication. The configuration management module is used to store and read the feature configuration (i.e., store and read the feature switch).
[0249] The application framework layer passes the process ID of the first process (i.e., the first process ID) to the system runtime library layer.
[0250] The system runtime library layer includes the Libs and ART modules. The Libs includes a processing module, and the Libs runs the first thread (the surfaceflinger thread).
[0251] The processing module is used to obtain the process ID of the first process. The first thread is used to initiate asynchronous binder communication, thereby triggering the second thread (the binder thread) to release the buffer area (buffer). For example, the first thread is the surfaceflinger thread
[0252] The system runtime library layer passes the process ID of the first process (i.e., the first process ID) to the kernel layer. Moreover, the first thread of the system runtime library layer initiates asynchronous binder communication and elevates the processing priority of the second thread (the binder thread).
[0253] The kernel layer includes the Linux Kernel and an elevation module. The Linux Kernel is used to store the process ID of the Launcher process. The elevation module is used to elevate the processing priority of the second thread (the binder thread).
[0254] Based on Figure 8 the shown architecture, the first process can obtain the feature switch from the configuration management module of the application framework layer, so as to obtain the enable information or the disable information, where the enable information indicates to start modifying the priority of the second thread; the disable information indicates to close the modification of the priority of the second thread.
[0255] Based on the read start information, the first process sends a start event (i.e., the first event) to the application framework layer, and the start event (i.e., the first event) represents starting to modify the priority of the second thread. Based on the read end information, the first process sends an end event (i.e., the second event) to the application framework layer, and the end event (i.e., the second event) represents closing the modification of the priority of the second thread.
[0256] The application framework layer can obtain the process ID of the first process, that is, the first process ID. The application framework layer passes the obtained first process ID to the kernel layer through the system runtime library layer.
[0257] When the application starts, the processing module of the system runtime library layer can obtain the feature switch from the configuration management module of the non-real-time processing subsystem, so as to obtain the enable information or the disable information.
[0258] When the application starts or shuts down, the application needs to display an animation effect. Thus, the first process notifies the second setting module in the application framework layer to obtain the process ID of the Launcher process. The second setting module in the application framework layer sets the process ID of the Launcher process in the processing module of the system operation layer. Then, the processing module of the system operation layer writes the process ID of the Launcher process into the file node in the kernel layer.
[0259] During the period when the application displays the animation effect, the first thread (the surfaceflinger thread) notifies the second thread (the binder thread) in the first process of the application to release the cache area through the asynchronous binder communication mechanism. Before releasing the cache area, the binder driver in the kernel layer first analyzes the binder communication number, interface descriptor, and asynchronous communication identifier, and can also determine whether the process ID of the processing end is the process ID of the first process (i.e., whether the first process ID is the same as the pre-stored second process ID), and whether the thread name of the initiating end is the thread name of the first thread (i.e., whether the pre-stored thread name is the thread name of the first thread). The binder driver in the kernel layer then raises the processing priority of the second thread to the RT priority.
[0260] Moreover, the kernel layer of the processor obtains the encapsulated data passed from the application framework layer (Framework) or the system runtime library layer (native), and the encapsulated data includes the binder communication number, interface descriptor, and asynchronous communication identifier.
[0261] Moreover, during the process of processing tasks, the kernel layer of the processor can obtain and store the second process ID and the pre-stored thread name, where the second process ID is used to indicate the process ID of the first process, and the pre-stored thread name is used to indicate the thread name of the first thread.
[0262] Figure 9 A signaling for a thread scheduling method based on a terminal device provided by an embodiment of the present application Figure 2 . As Figure 9 shown, there are provided: a configuration management module, a dynamic setting module, and a promotion module.
[0263] Among them, the configuration management module is the Figure 8 configuration management module in Figure 8 . The dynamic setting module includes the Figure 8 first setting module and the second setting module in
[0264] . The promotion module is the
[0265] Figure 9 The method shown includes the following processes:
[0266] S901. When the application starts, the reading sub-module reads the feature configuration (i.e., the feature switch). The reading sub-module caches the read feature configuration in the memory.
[0267] Among them, the feature configuration is an enabling message or a disabling message; among them, the enabling message indicates to start modifying the priority of the second thread; the disabling message indicates to close the modification of the priority of the second thread.
[0268] S902. Determine to perform the initialization process, and the management sub-module obtains the feature configuration in the memory.
[0269] S903. If the management sub-module determines that the feature configuration is an enabling message, and the enabling message indicates to start modifying the priority of the second thread, then the management sub-module generates a start event (i.e., the first event), and the start event represents starting to modify the priority of the second thread.
[0270] Among them, the management sub-module starts a new thread and delays for 30 seconds to obtain the feature configuration from the memory through the SDK interface.
[0271] S904. The management sub-module determines that the current process is the first process, and writes the obtained first process ID into the first file node, where the first process ID is used to indicate the process ID of the first process.
[0272] Among them, the management sub-module, in response to the start event, determines whether the current process is the first process. The management sub-module, in response to the start event, obtains the first process ID, and the first process ID represents whether the current process is the first process. If the management sub-module determines that the current process is the first process, then through the interface of the MTM service, it writes the first process ID into the first file node. And, the management sub-module determines to enable the modification of the priority of the second thread in this application.
[0273] S905. The management sub-module sends the start message and the first process ID to the processing sub-module.
[0274] S906. The processing sub-module performs the verification process.
[0275] Among them, the verification process of the processing sub-module is: verifying the permission of the first thread, verifying the thread name of the first thread, verifying other parameters, etc. Verifying the permission of the first thread is to check whether the first thread is the initiator (i.e., checking whether the first thread name is the same as the second thread name). Verifying the thread name of the first thread is to check whether the thread name of the first thread meets the standard and is correct.
[0276] If the processing sub-module determines that the verification is passed, the processing sub-module writes the first process ID into the second file node to indicate the start of modifying the processing priority of the second thread.
[0277] S908. The transmission sub-module obtains a release instruction for instructing to release the task data in the buffer area and sends the release instruction to the second listening sub-module.
[0278] Among them, after the first thread (surfaceflinger thread) completes the synthesis of a frame of image, the first thread initiates asynchronous binder communication to trigger the second thread (binder thread) to release the buffer area. Thus, the first thread sends a release instruction to the transmission sub-module, and the release instruction is used to indicate releasing the task data in the buffer area.
[0279] S909. The second listening sub-module determines to initiate asynchronous binder communication.
[0280] S910. The promotion sub-module promotes the processing priority of the second thread to RT priority.
[0281] Among them, before step S910, the binder driver in the kernel layer needs to analyze the binder communication number, interface descriptor, and asynchronous communication identifier, and can also determine whether the process ID of the processing end is the process ID of the first process (that is, whether the first process ID is the same as the pre-stored second process ID), and whether the thread name of the initiating end is the thread name of the first thread (that is, whether the pre-stored thread name is the thread name of the first thread). The binder driver in the kernel layer then promotes the processing priority of the second thread to RT priority.
[0282] S911. The first listening sub-module releases the task data in the buffer area based on the second thread.
[0283] S912. After determining that the second thread has released the buffer area, the management sub-module generates an end event (that is, the second event), and the end event indicates closing the modification of the priority of the second thread.
[0284] S913. The management sub-module determines that the current process is the first process and writes the obtained first process ID into the first file node, where the first process ID is used to indicate the process ID of the first process.
[0285] Among them, in response to the end event, the management sub-module determines whether the current process is the first process (Launcher process). In response to the end event, if it is determined that the current process is the first process, the management sub-module writes the first process ID into the first file node through the interface of the MTM service. And the management sub-module determines to close the modification of the priority of the second thread in this application.
[0286] S914. The management sub-module sends the end information to the processing sub-module.
[0287] S915. The processing sub-module performs a verification process.
[0288] Among them, the verification process of the processing sub-module is as follows: verifying the permission of the first thread, verifying the thread ID of the first thread, verifying other parameters, and so on. Verifying the permission of the first thread is to check whether the first thread is the initiator (that is, to check whether the first thread name is the same as the second thread name). Verifying the thread ID of the first thread is to check whether the thread ID of the first thread meets the standard and is correct.
[0289] S916. If the processing sub-module determines that the verification is passed, then the processing sub-module writes 0 to the second file node to indicate closing the modification of the processing priority of the second thread.
[0290] Thus, through the process of this embodiment, when it is necessary to release the task data in the cache area, the processor priority of the second thread can be first increased, so that the second thread will be preferentially scheduled to release the task data in the cache area. That is, the second thread of the first process is increased in priority during the execution of releaseBufferCallback, so that the second thread can be timely scheduled to release the cache area.
[0291] Since the second thread can be timely retrieved, the second thread can timely release the task data in the cache area, further enabling the first process to timely cache the new task data into the cache area, so that the first thread timely obtains the new task data from the cache area to process the task. The terminal device can timely process the task.
[0292] In one example, the first process is the desktop process (Launcher process), and the first thread is the surfaceFlinger thread. Among them, the first process is a process for rendering image data; the first process includes multiple threads, the desktop process includes the desktop main thread (UI Thread), the rendering thread (render thread), the second thread, and so on; the second thread is the binder thread. The first thread is a thread for synthesizing the dynamic effect images of the application. The processor of the terminal device has a cache area (buffer area), and the cache area is used to cache the image data of the dynamic effect images of the application.
[0293] Thus, through the solution of this embodiment, new image data can be timely obtained from the cache area to generate new generated image frames; avoiding the dynamic effect images displayed by the application from being stuck. And, since new image frames can be timely generated and there will be no frame loss, avoiding the phenomenon of frame loss in the dynamic effect images displayed by the application.
[0294] In another example, the first process is a system service process (system service process), and the first thread is the surfaceFlinger thread. Among them, the first process is a process for generating window data of window information; the first process includes multiple threads, and the first process includes the second thread, etc.; the second thread is a binder thread. The first thread is a thread for updating the window information of the system. There is a buffer area (buffer area) in the processor of the terminal device, and the buffer area is used to cache window data.
[0295] Therefore, through the solution of this embodiment, new window data can be obtained from the buffer area in a timely manner to update the window information of the system, avoiding the inability to update the window information in a timely manner.
[0296] Figure 10 The signaling for a thread scheduling method based on a terminal device provided by an embodiment of the present application Figure 3 As Figure 10 shown, there are provided: a process module of the client, a kernel layer, and a process module of the server.
[0297] Among them, the process module of the client includes a first processing module, a second processing module, and a third processing module. The kernel layer includes a fourth processing module. The process module of the server includes a fifth processing module, a sixth processing module, and a seventh processing module.
[0298] Among them, Figure 10 the provided solution is Figure 9 a refinement process of steps S908 - S911 in
[0299] S1001. The first processing module encapsulates the data to be processed to obtain encapsulated data. Among them, the data to be processed is used to release the data in the buffer area.
[0300] Among them, the data to be processed represents the need to release the buffer area and the data required to release the buffer area.
[0301] Among them, the data to be processed includes a binder communication number, an interface descriptor, and an asynchronous communication identifier. Therefore, the encapsulated data includes a binder communication number, an interface descriptor, and an asynchronous communication identifier.
[0302] S1002. The first processing module obtains flag information (Flag). Among them, the flag information is data representing that the communication between the first thread and the first process is an asynchronous binder communication method.
[0303] S1003. The first processing module sends the encapsulated data and the flag information to the second processing module.
[0304] S1004. The second processing module converts the identification information into kernel-mode identification information.
[0305] Thus, the second processing module converts the user-mode identification representing asynchronous communication into kernel-mode identification.
[0306] S1005. The second processing module sends the encapsulated data to the third processing module.
[0307] S1006. The third processing module unpacks the obtained encapsulated data to obtain the data to be processed; the third processing module encapsulates the data to be processed and writes it into the output file node.
[0308] S1007. The third processing module waits for a reply from the kernel space.
[0309] S1008. The third processing module communicates with the binder driver in the kernel layer.
[0310] S1009. The third processing module repackages the data to be processed in the output file node to obtain encapsulated data.
[0311] S1010. The third processing module transfers the communication identification and the encapsulated data to the fourth processing module in the kernel layer.
[0312] S1011. The fourth processing module in the kernel layer determines whether the communication between the first thread and the first process is asynchronous binder communication.
[0313] S1012. The fourth processing module copies the encapsulated data obtained from the third processing module from the user space to the kernel space.
[0314] S1013. The fourth processing module determines whether the binder communication is initiated by the process module of the client.
[0315] Among them, in step S1013, the fourth processing module determines whether the first thread name is the same as the pre-stored second thread name; if the fourth processing module determines that the first thread name is the same as the second thread name, it determines that the thread name of the initiating end is the thread name of the first thread, and further determines that the initiating end is the first thread (surfaceflinger thread), that is, it determines that the binder communication is initiated by the process module of the client.
[0316] S1014. The fourth processing module performs a determination process: the fourth processing module determines whether the first thread name is the same as the pre-stored second thread name, whether the first thread name is the same as the pre-stored second thread name, and whether the communication between the first thread and the first process is asynchronous communication.
[0317] S1015. If the fourth processing module determines that the first thread name is the same as the second thread name, the first process ID is the same as the second process ID, and the communication between the first thread and the first process is asynchronous communication, the encapsulated data is copied to the first process (Launcher process). In addition, the fourth processing module sets the preset flag bit to 1.
[0318] S1016. When the fourth processing module determines that the preset flag bit is 1, it raises the priority of the second thread to the RT priority.
[0319] S1017. The fourth processing module sends a notification message to the third processing module, and the notification message indicates that the priority of the second thread has been raised. Thus, the third processing module determines that the priority elevation is completed.
[0320] S1018. The fourth processing module notifies the fifth processing module to release the cache area.
[0321] S1019. The fourth processing module sends the encapsulated data to the fifth processing module.
[0322] S1020. The fifth processing module sends the encapsulated data to the sixth processing module.
[0323] S1021. The sixth processing module sends the encapsulated data to the seventh processing module.
[0324] S1022. Based on the encapsulated data, the seventh processing module releases the task data in the cache area.
[0325] Among them, the seventh processing module obtains the data to be processed in the encapsulated data; since the data to be processed indicates that the cache area needs to be released and the data required for releasing the cache area, the seventh processing module releases the task data in the cache area based on the obtained data to be processed.
[0326] S1023. After the seventh processing module determines that the release of the cache area is completed, it sends a result message to the sixth processing module, and the result message indicates that the release of the cache area is completed.
[0327] S1024. After the sixth processing module determines that the release of the cache area is completed, it sends a result message to the fifth processing module, and the result message indicates that the release of the cache area is completed.
[0328] Thus, based on Figure 10In the provided process, when it is necessary to release the task data in the cache area, the processor priority of the second thread can be raised first, so that the second thread will be preferentially scheduled to release the task data in the cache area. That is, the priority of the second thread of the first process is raised during the execution of releaseBufferCallback, so that the second thread can be scheduled in time to release the cache area.
[0329] Figure 11 Signaling for a thread scheduling method based on a terminal device provided in an embodiment of the present application Figure 4 As Figure 11 shown, the following are provided: a first control sub-module, a second control sub-module, a third control sub-module, a fourth control sub-module, a fifth control sub-module, a sixth control sub-module, and a seventh control sub-module.
[0330] Among them, Figure 11 the provided solution is Figure 9 a refinement process of steps S903 - S907 and steps S912 - S916 in
[0331] S1101a. When it is determined to start the display animation effect, the first control sub-module receives a start message; the start message indicates to start modifying the priority of the second thread.
[0332] S1102a. The first control sub-module generates a start event (i.e., the first event) according to the start message, and the start event represents starting to modify the priority of the second thread.
[0333] S1103a. The first control sub-module determines whether the current process is the first process (Launcher process).
[0334] Among them, the management sub-module obtains the first process ID in response to the start event, and the first process ID represents whether the current process is the first process. Furthermore, the first control sub-module can determine whether the current process is the first process (Launcher process).
[0335] S1104a. The first control sub-module obtains the first process ID in response to the start event.
[0336] Among them, if it is determined that the current process is the first process, the first process ID is written into the first file node through the interface of the MTM service. And the management sub-module determines to start modifying the priority of the second thread of the present application. Among them, since it has been determined that the current process is the first process, the first process ID is used to indicate the process ID of the first process.
[0337] S1105a. The first control sub-module sends the start information and the first process number to the second control sub-module. Here, the first process number is used to indicate the process number of the first process.
[0338] S1106a. The second control sub-module sends the first process number to the third control sub-module.
[0339] S1107a. The third control sub-module sends the first process number to the fourth control sub-module.
[0340] S1108a. The fourth control sub-module sends the first process number to the fifth control sub-module.
[0341] S1109a. The fifth control sub-module sends the first process number to the sixth control sub-module.
[0342] S1110a. The sixth control sub-module performs a verification process.
[0343] Among them, the verification process of the sixth control sub-module is as follows: verifying the permission of the first thread, verifying the thread number of the first thread, verifying other parameters, and so on. Verifying the permission of the first thread is to check whether the first thread is the initiator (that is, to check whether the first thread name is the same as the second thread name). Verifying the thread number of the first thread is to check whether the thread number of the first thread meets the standard and is correct.
[0344] S1111a. If the sixth control sub-module determines that the verification is passed, then the sixth control sub-module sends a message to the seventh control sub-module. This message is used to indicate writing the first process number into the second file node.
[0345] S1112a. The seventh control sub-module writes the first process number into the second file node to represent the start of modifying the processing priority of the second thread.
[0346] S1101b. When determining to exit the display animation effect, the first control sub-module receives the end information; the start information indicates to close the modification of the priority of the second thread.
[0347] S1102b. The first control sub-module generates an end event (that is, the second event) according to the end information. The end event represents closing the modification of the priority of the second thread.
[0348] S1103b. The first control sub-module determines whether the current process is the first process (Launcher process).
[0349] Among them, the management sub-module obtains the first process number in response to the end event. The first process number represents whether the current process is the first process. Furthermore, the first control sub-module can determine whether the current process is the first process (Launcher process).
[0350] S1104b. The first control sub-module obtains the first process number in response to the end event.
[0351] Among them, if it is determined that the current process is the first process, then through the interface of the MTM service, 0 is written into the first file node. And the management sub-module determines to end the modification of the priority of the second thread of this application. Among them, since it has been determined that the current process is the first process, thus, the first process number is used to indicate the process number of the first process.
[0352] S1105b. The first control sub-module sends the end information and the first process number to the second control sub-module. Among them, the first process number is used to indicate the process number of the first process.
[0353] S1106b. The second control sub-module sends the first process number to the third control sub-module.
[0354] S1107b. The third control sub-module sends the first process number to the fourth control sub-module.
[0355] S1108b. The fourth control sub-module sends the first process number to the fifth control sub-module.
[0356] S1109b. The fifth control sub-module sends the first process number to the sixth control sub-module.
[0357] S1110b. The sixth control sub-module performs a verification process.
[0358] Among them, the verification process of the sixth control sub-module is: verifying the permission of the first thread, verifying the thread number of the first thread, verifying other parameters, etc. Verifying the permission of the first thread is to check whether the first thread is the initiator (that is, to check whether the first thread name is the same as the second thread name). Verifying the thread number of the first thread is to check whether the thread number of the first thread meets the standard and is correct.
[0359] S1111b. If the sixth control sub-module determines that the verification is passed, then the sixth control sub-module sends a message to the seventh control sub-module, and this message is used to indicate writing 0 into the second file node.
[0360] S1112b. The seventh control sub-module writes 0 into the second file node to represent closing the modification of the processing priority of the second thread.
[0361] Through Figure 11 the process mentioned above, the modification of the processing priority of the second thread is started, or the modification of the processing priority of the second thread is closed.
[0362] Figure 12Signaling for a thread scheduling method based on a terminal device provided by an embodiment of the present application Figure 5 . As Figure 12 shown, the method may include:
[0363] S1201. When it is determined based on the first thread that the cache area needs to be released, a release instruction is sent to the kernel layer of the processor based on the first thread, and the release instruction is used to indicate releasing the task data in the cache area.
[0364] Among them, the first thread and the first process are running in the processor, and a cache area is set in the processor. Among them, 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 cache area is used to cache the task data of the tasks.
[0365] Exemplarily, this step can refer to the introduction in the above embodiment and will not be elaborated here.
[0366] S1202. When it is determined based on the first thread that the cache area needs to be released, a release instruction is sent to the kernel layer of the processor based on the first thread, and the release instruction is used to indicate releasing the task data in the cache area.
[0367] Exemplarily, this step can refer to the introduction in the above embodiment.
[0368] The kernel layer of the processor can directly respond to the first release instruction to modify the processing priority of the second thread, changing the processing priority of the second thread from the first priority to the second priority, thereby improving the processing priority of the second thread; among them, the processing priority of the second priority is higher than that of the first priority.
[0369] The kernel layer of the processor can also respond to the release instruction to determine whether the priority of the second thread needs to be increased. If the kernel layer of the processor determines that the first thread and the first process meet the preset conditions, the processing priority of the second thread is increased.
[0370] The preset condition is: the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread.
[0371] Or, the preset condition is: the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiating end of the communication is the first thread and the processing end of the communication is the first process.
[0372] Alternatively, the preset conditions are as follows: the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiating end of the communication is the first thread, the processing end of the communication is the first process, and the communication between the first thread and the first process is an asynchronous binder communication.
[0373] Alternatively, the preset conditions are as follows: the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiating end of the communication is the first thread, the processing end of the communication is the first process, and the communication between the first thread and the first process is an asynchronous binder communication. Moreover, the first process number is consistent with the pre-stored second process number, and the pre-stored thread name is the thread name of the first thread. S1203. The kernel layer based on the processor sends a release instruction to the second thread in the first process, and based on the second thread with the second priority, releases the task data in the cache area.
[0374] Exemplarily, this step can refer to the introduction in the above embodiment and will not be elaborated here.
[0375] In this embodiment, when it is necessary to release the task data in the cache area, the processor priority of the second thread can be first increased, so that the second thread will be preferentially scheduled to release the task data in the cache area. That is, the priority of the second thread in the first process is increased during the execution of releaseBufferCallback, so that the second thread can be scheduled in time to release the cache area. Since the second thread can be retrieved in time, the second thread can release the task data in the cache area in time, further enabling the first process to cache the new task data in the cache area in time, so that the first thread can obtain the new task data from the cache area in time to process the task. Thus, the terminal device can process the task in time.
[0376] The above mainly introduces the solution provided by the embodiments of the present application from the perspective of the method. To implement the above functions, it includes the corresponding hardware structure and / or software module for executing each function. Those skilled in the art should easily realize that, combining the method steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in the way of hardware or computer software driving the hardware depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.
[0377] The embodiments of the present application may divide the device of the above method into functional modules according to the above method examples. For example, each functional module may be divided corresponding to each function, or two or more functions may be integrated into one processing module. The above integrated module may be implemented in the form of hardware or in the form of a software functional module. It should be noted that the division of modules in the embodiments of the present application is illustrative, and is only a logical function division. There may be other division methods in actual implementation.
[0378] As Figure 13 shown is a schematic structural diagram of a chip provided by an embodiment of the present application. The chip 1300 includes one or more (including two) processors 1301, a communication line 1302, a communication interface 1303, and a memory 1304.
[0379] In some embodiments, the memory 1304 stores the following elements: executable modules or data structures, or subsets thereof, or extended sets thereof.
[0380] The methods described in the above embodiments of the present application may be applied to the processor 1301 or implemented by the processor 1301. The processor 1301 may be an integrated circuit chip with signal processing capabilities. In the implementation process, the steps of the method executed by the above terminal device may be completed by the integrated logic circuit in hardware or instructions in software form in the processor 1301. The above processor 1301 may be a general-purpose processor (e.g., a microprocessor or a conventional processor), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate, transistor logic devices, or discrete hardware components. The processor 1301 may implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present application.
[0381] The steps of the method disclosed in the embodiments of the present application can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. Among them, the software module can be located in mature storage media in the art such as random access memory, read-only memory, programmable read-only memory, or electrically erasable programmable read-only memory (EEPROM). This storage medium is located in the memory 1304, and the processor 1301 reads the information in the memory 1304 and combines its hardware to complete the steps of the above method.
[0382] The processor 1301, the memory 1304, and the communication interface 1303 can communicate with each other through the communication line 1302.
[0383] Figure 14 It is a schematic structural diagram of a terminal device provided by an embodiment of the present application. As Figure 14 shown, the terminal device 1400 includes the above-mentioned chip and a display unit. An integrated circuit panel is provided in the display unit, and the integrated circuit panel is used to issue periodic interrupt events. Among them, the integrated circuit panel removes the integrated circuit unit for calculating the coordinate information corresponding to the touch operation.
[0384] The thread scheduling method based on an application in a terminal device provided by an embodiment of the present application can be applied to an electronic device with a communication function. The electronic device includes a terminal device, and the specific device form of the terminal device and the like can refer to the above relevant description, which will not be elaborated here.
[0385] An embodiment of the present application provides a terminal device, which includes: a processor and a memory; the memory stores computer execution instructions; the processor executes the computer execution instructions stored in the memory, so that the terminal device executes the above method.
[0386] An embodiment of the present application provides a chip. The chip includes a processor, and the processor is used to call a computer program in the memory to execute the technical solutions in the above embodiments. Its implementation principle and technical effects are similar to those of the above relevant embodiments, which will not be elaborated here.
[0387] The embodiments of the present application also provide a computer-readable storage medium. The computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the above method is implemented. The methods described in the above embodiments can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. If implemented in software, the functions can be stored on or transmitted over a computer-readable medium as one or more instructions or codes. The computer-readable medium can include a computer storage medium and a communication medium, and can also include any medium that can transfer a computer program from one place to another. The storage medium can be any target medium accessible by a computer.
[0388] In a possible implementation, the computer-readable medium may include RAM, ROM, a compact disc read-only memory (CD-ROM), or other optical disc storage, a magnetic disk storage, or other magnetic storage devices, or any other medium targeted to carry the required program code in the form of instructions or data structures and accessible by a computer. Moreover, any connection is properly termed a computer-readable medium. For example, if software is transmitted from a website, server, or other remote source using coaxial cable, fiber optic cable, twisted pair, Digital Subscriber Line (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of the medium. As used herein, disk and disc include optical disc, laser disc, optical disc, Digital Versatile Disc (DVD), floppy disk, and Blu-ray disc, where disks usually reproduce data magnetically, while discs reproduce data optically using lasers. The above combinations should also be included within the scope of the computer-readable medium.
[0389] The embodiments of the present application provide a computer program product. The computer program product includes a computer program. When the computer program is run, the computer is caused to execute the above method.
[0390] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combinations of flows and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to the processing unit of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable devices to generate a machine, such that the instructions executed by the processing unit of the computer or other programmable data processing devices generate for implementing in the process Figure 1means for the functions specified in one or more processes and / or boxes Figure 1 means for the functions specified in one or more boxes.
[0391] In the above specific embodiments, the purpose, technical solution and beneficial effects of the present invention have been further described in detail. It should be understood that the above are only specific embodiments of the present invention, and are not used to limit the protection scope of the present invention. Any modifications, equivalent replacements, improvements, etc. made on the basis of the technical solution of the present invention shall be included in the protection scope of the present invention.
Claims
1. A thread scheduling method based on a terminal device, characterized in that The method is applied to a processor of a terminal device. A first thread and a first process are running in the processor. A cache area is set in the processor. Wherein, the first thread is a thread for processing tasks, the first process includes a second thread, and the second thread is a binder thread. The cache area is used for caching task data of the tasks. The method includes: When it is determined based on the first thread that the cache area needs to be released, a release instruction is sent to the kernel layer of the processor based on the first thread. The release instruction is used to indicate releasing the task data in the cache area; Based on the kernel layer, according to the release instruction, modify the processing priority of the second thread from a first priority to a second priority; wherein, the processing priority of the second priority is higher than that of the first priority, and the second priority is a priority representing real-time scheduling; Based on the kernel layer of the processor sending the release instruction to the second thread in the first process, and based on the second thread with the second priority, release the task data in the cache area.
2. The method according to claim 1, wherein The first priority is a priority representing non-real-time scheduling.
3. The method according to claim 1 or 2, characterized in that, Based on the kernel layer, according to the release instruction, modifying the processing priority of the second thread from a first priority to a second priority includes: Based on the kernel layer, according to the release instruction, if it is determined that the first thread and the first process meet a preset condition, then modify the processing priority of the second thread from a first priority to a second priority.
4. The method according to claim 3, wherein The kernel layer stores a binder communication number and an interface descriptor. The binder communication number is used to indicate a communication interface, and the interface descriptor is used to indicate an initiating end and a processing end for communication; Based on the kernel layer, according to the release instruction, if it is determined that the first thread and the first process meet a preset condition, then modify the processing priority of the second thread from a first priority to a second priority includes: Based on the kernel layer, according to the release instruction, if it is determined that the communication interface indicated by the binder communication number is the communication interface between the first thread and the second thread, and the interface descriptor indicates that the initiating end for communication is the first thread and the processing end for communication is the first process, then modify the processing priority of the second thread from a first priority to a second priority.
5. The method according to claim 4, characterized in that, The kernel layer also stores an asynchronous communication identifier, and the asynchronous communication identifier is used to indicate a communication method; before modifying the processing priority of the second thread from a first priority to a second priority, it further includes: Based on the kernel layer, if it is determined that the asynchronous communication identifier indicates that the communication between the first thread and the first process is asynchronous binder communication, then modify the processing priority of the second thread from a first priority to a second priority.
6. The method according to claim 4 or 5, characterized in that, The method further includes: obtaining a first process number based on the kernel layer, where the first process number is used to indicate the process number of the first process; Before modifying the processing priority of the second thread from a first priority to a second priority, it further includes: If it is determined based on the kernel layer that the first process number is consistent with the pre-stored second process number and the pre-stored thread name is the thread name of the first thread, then modify the processing priority of the second thread from the first priority to the second priority; wherein, the pre-stored second process number is used to indicate the process number of the first process.
7. The method according to claim 6, wherein obtaining the first process number based on the kernel layer includes: Obtaining first switch information based on the first process, wherein the first switch information characterizes the start of modifying the priority of the second thread; Obtaining a first event based on the first process according to the first switch information; wherein the first event characterizes the start of modifying the priority of the second thread; Obtaining the first process number based on the first process according to the first event; and sending the first process number to the kernel layer based on the first process.
8. The method according to any one of claims 1-2, 4-5, 7, characterized in that, The method further includes: If the second thread is in an idle state based on the kernel layer, then based on the kernel layer, restore the processing priority of the second thread from the second priority to the first priority.
9. The method according to any one of claims 1-2, 4-5, and 7, characterized in that The method further includes: Obtaining second switch information based on the first process, wherein the second switch information characterizes the closing of modifying the priority of the second thread; Obtaining a second event based on the first process according to the second switch information; wherein the second event characterizes the closing of modifying the priority of the second thread; Writing indication information into a preset file node based on the first process according to the second event, wherein the indication information characterizes the closing of modifying the priority of the second thread.
10. The method according to any one of claims 1-2, 4-5, 7, characterized in that, The first thread is a thread for synthesizing the animated image of the application, the first process is the desktop process, and the first process is a process for drawing the image data of the animated image; Or, the first thread is a thread for updating the window information of the system, and the first process is a process for generating the window data of the window information.
11. A terminal device, characterized in that, Including: A processor and a memory; The memory stores computer execution instructions; The processor executes the computer execution instructions stored in the memory, so that the terminal device executes the method according to any one of claims 1-10.
12. A computer-readable storage medium storing a computer program, characterized in that, The computer program, when executed by the processor, implements the method according to any one of claims 1-10.
13. A computer program product, characterized in that, Including a computer program, when the computer program is run, it causes the computer to execute the method according to any one of claims 1-10.
Citation Information
Patent Citations
Resource scheduling method and electronic equipment
CN112527476A
Method and device for implementing computer multi-tasking via virtual threading
CN1592886A