System resource adjustment method, device and readable storage medium
By adjusting the priority of terminal system resources, the lag problem caused by the foreground application display thread waiting for the background thread to return data is solved, and the smooth running of the application is achieved.
Patent Information
- Application Number
- CN201910916214.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-09-25
- Publication Date
- 2024-10-01
- Estimated Expiration
- 2039-09-25
AI Technical Summary
The existing technology cannot effectively solve the stuck problem caused by the terminal foreground application display thread waiting for the background thread to return data.
By obtaining the resources to be optimized from the current system resources and adjusting their priorities according to the preset strategy, the priority of the resources to be optimized is higher than or equal to the priority of the current system resources, thereby accelerating the operation of the resources to be optimized and avoiding terminal running lag. Dayton.
It improves the running fluency of the application, ensures that the display thread obtains the required data in time, and avoids lags.
Smart Images

Figure CN110704187B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of system resources, and in particular to a method and device for adjusting system resources and a readable storage medium. Background Art
[0002] In the prior art, the operation of the foreground application of the terminal often depends on the data returned by the background application to run. The resource configuration optimization of the running system carried by the terminal has always been an urgent problem to be solved in the operation process of the terminal. In order to solve the above problems, in some patent documents, by obtaining the available computing resource information for executing the task, and determining the resource consumption information of each task in the task set; comparing the resource consumption information with the available computing resource information, and determining the task whose comparison result meets the preset task scheduling conditions as the target task, thereby optimizing the resource utilization of the task scheduling process and improving the processing performance of the data warehouse; or, by starting the timing from the switching moment when the target application is switched to the background, if the target application is not relied on by the foreground application within the first preset time from the timing moment to the timing time reaching the first preset time, then the target application is subjected to resource restriction processing, thereby preventing the restriction on the target application from affecting the foreground application, and improving the flexibility of the electronic device to process the application; for example, in some other patent documents, the CPU frequency modulation mode in the terminal is adjusted by the acquired process package and the pre-stored frequency modulation mode list, optimizing the existing frequency modulation mode adjustment technology, reducing the power consumption of the mobile terminal, and improving the performance of the mobile terminal. For example, in some patent documents, by embedding SDK in the target application, the target application can send its own application running information to the operating system through the API interface provided by the SDK, so that the operating system can formulate corresponding resource allocation strategies based on the application running information, thereby allocating corresponding system resources to the target application according to the resource allocation strategy; compared with simply improving the hardware performance of the terminal, the operating system in this embodiment can allocate corresponding system resources to the application according to the running state of the application, so that the application can achieve good running results in different running states and reduce dependence on terminal hardware.
[0003] However, in the prior art, the current display thread of the foreground application of the terminal usually needs to obtain the data returned by the background thread before it can run. The background thread needs to wait for other processes to complete before it can execute and obtain the corresponding data and return it to the display thread, resulting in the display thread not being able to execute in time, causing the foreground application to freeze. The prior art cannot solve the problem of the display thread of the foreground application freezing.
[0004] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of the present invention is to provide a method for adjusting system resources, aiming to solve the problem of foreground application freeze in the prior art.
[0006] To achieve the above object, the present invention provides a method for adjusting system resources, wherein the method comprises the following steps:
[0007] S1: Obtain the resources to be optimized corresponding to the current system resources;
[0008] S2: Adjust the resources to be optimized according to a preset strategy.
[0009] Optionally, the S2 step includes:
[0010] When there is communication between the current system resource and the resource to be optimized, obtaining the priority of the current system resource and the corresponding communication request;
[0011] Obtaining the priority of the resource to be optimized in response to the communication request;
[0012] The priority of the current system resource and / or the resource to be optimized is adjusted so that the priority of the resource to be optimized is higher than or equal to the priority of the current system resource.
[0013] Optionally, the step S2 further includes:
[0014] Storing the resource information of the resource to be optimized in the stack of the current system resources;
[0015] After the resource to be optimized has finished running, and when the resource information of the resource to be optimized matches the top information of the stack, the top information of the stack is retrieved to restore the initial priority of the resource to be optimized.
[0016] Optionally, the S2 step includes:
[0017] When the resource to be optimized is a preset resource, the priority of the preset resource is adjusted to be higher than or equal to the priority of the current system resource.
[0018] Optionally, the step S2 further includes:
[0019] Storing resource information of preset resources into the stack of current system resources;
[0020] After the preset resource is finished running, the preset resource is controlled to release the corresponding resource, and when the resource information of the preset resource matches the stack top information of the stack, the stack top information is taken out to restore the initial priority of the preset resource.
[0021] Optionally, the adjustment method further includes:
[0022] When at least one of a switching instruction corresponding to the current system resource is received and an error occurs in the current system resource, the resource information stored in the stack is retrieved.
[0023] Optionally, before the step S1, the method further includes:
[0024] In a preset time period and / or a preset geographic fence, system resources with a usage duration greater than or equal to a preset duration and / or an opening frequency greater than or equal to a preset frequency are regarded as preset resources;
[0025] When the resource corresponding to the current system resource is the preset resource, the step of obtaining the resource to be optimized corresponding to the current system resource is performed.
[0026] Optionally, the current system resources and / or the resources to be optimized include at least one of an application, a process, and a thread.
[0027] To achieve the above-mentioned purpose, the present invention also provides a system resource adjustment device, which includes a memory, a processor, and a system resource adjustment program stored in the memory and executable on the processor, and the system resource adjustment program, when executed by the processor, implements the steps of the system resource adjustment method as described in any one of the above items.
[0028] To achieve the above objectives, the present invention also provides a computer-readable storage medium, on which a system resource adjustment program is stored. When the system resource adjustment program is executed by a processor, the steps of the system resource adjustment method as described in any one of the above items are implemented.
[0029] The technical solution of the present invention obtains the resources to be optimized corresponding to the current system resources; adjusts the resources to be optimized according to a preset strategy to increase the priority of the resources to be optimized on which the current system resources depend, thereby allowing the resources to be optimized to run faster, thereby avoiding terminal operation jams and improving application operation fluency. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 It is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present invention;
[0031] Figure 2 A schematic diagram of a flow chart of an embodiment of a method for adjusting system resources of the present invention;
[0032] Figure 3 A specific flow chart of step S2 of an embodiment of the method for adjusting system resources of the present invention;
[0033] Figure 4 A flowchart of another embodiment of a method for adjusting system resources of the present invention;
[0034] Figure 5 A specific flow chart of another embodiment of step S2 of the method for adjusting system resources of the present invention;
[0035] Figure 6 The flowchart of another embodiment of the method for adjusting system resources of the present invention is shown in FIG.
[0036] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0037] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0038] The technical solution of the present invention is mainly:
[0039] S1: Obtain the resources to be optimized corresponding to the current system resources;
[0040] S2: Adjust the resources to be optimized according to a preset strategy.
[0041] In the prior art, the current display thread of the foreground application of the terminal usually needs to obtain the data returned by the background thread before it can run. The background thread needs to wait for other processes to complete before it can execute and obtain the corresponding data and return it to the display thread, resulting in the display thread not being able to execute in time, resulting in the foreground application being stuck. The prior art cannot solve the problem of the display thread of the foreground application being stuck.
[0042] The technical solution of the present invention obtains the resources to be optimized corresponding to the current system resources; adjusts the resources to be optimized according to a preset strategy to increase the priority of the resources to be optimized on which the current system resources depend, thereby allowing the resources to be optimized to run faster, thereby avoiding terminal operation jams and improving application operation fluency.
[0043] like Figure 1 As shown, Figure 1 It is a schematic diagram of the hardware operating environment of the terminal involved in the embodiment of the present invention.
[0044] The terminal in the embodiment of the present invention is a mobile terminal or a fixed terminal, such as a mobile phone. Figure 1As shown, the terminal may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and a remote controller. Optionally, the user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a memory (non-volatile memory), such as a disk storage. The memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0045] Those skilled in the art will understand that Figure 1 The structure of the terminal shown in the figure does not constitute a limitation on the terminal, and may include more or less components than shown in the figure, or combine certain components, or arrange the components differently.
[0046] like Figure 1 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a control program of the device.
[0047] exist Figure 1 In the terminal shown, the network interface 1004 is mainly used to connect to the backend server and perform data communication with the backend server; the user interface 1003 is mainly used to connect to the client (user end) and perform data communication with the client; and the processor 1001 can be used to call the control program of the device stored in the memory 1005 and perform the following operations:
[0048] S1: Obtain the resources to be optimized corresponding to the current system resources;
[0049] S2: Adjust the resources to be optimized according to a preset strategy.
[0050] Further, the processor 1001 may call the control program of the device stored in the memory 1005, and also perform the following operations:
[0051] When there is communication between the current system resource and the resource to be optimized, obtaining the priority of the current system resource and the corresponding communication request;
[0052] Storing the resource information of the resource to be optimized in the stack of the current system resources;
[0053] After the resource to be optimized has finished running, and when the resource information of the resource to be optimized matches the top information of the stack, the top information of the stack is retrieved to restore the initial priority of the resource to be optimized.
[0054] Further, the processor 1001 may call the control program of the device stored in the memory 1005, and also perform the following operations:
[0055] Storing the resource information of the resource to be optimized in the stack of the current system resources;
[0056] After the resource to be optimized has finished running, and when the resource information of the resource to be optimized matches the top information of the stack, the top information of the stack is retrieved to restore the initial priority of the resource to be optimized.
[0057] Further, the processor 1001 may call the control program of the device stored in the memory 1005, and also perform the following operations:
[0058] When the resource to be optimized is a preset resource, the priority of the preset resource is adjusted to be higher than or equal to the priority of the current system resource.
[0059] Further, the processor 1001 may call the control program of the device stored in the memory 1005, and also perform the following operations:
[0060] Storing resource information of preset resources into the stack of current system resources;
[0061] After the preset resource is finished running, the preset resource is controlled to release the corresponding resource, and when the resource information of the preset resource matches the stack top information of the stack, the stack top information is taken out to restore the initial priority of the preset resource.
[0062] Further, the processor 1001 may call the control program of the device stored in the memory 1005, and also perform the following operations:
[0063] When at least one of a switching instruction corresponding to the current system resource is received and an error occurs in the current system resource, the resource information stored in the stack is retrieved.
[0064] Further, the processor 1001 may call the control program of the device stored in the memory 1005, and also perform the following operations:
[0065] In a preset time period and / or a preset geographic fence, system resources with a usage duration greater than or equal to a preset duration and / or an opening frequency greater than or equal to a preset frequency are regarded as preset resources;
[0066] When the resource corresponding to the current system resource is the preset resource, the step of obtaining the resource to be optimized corresponding to the current system resource is performed.
[0067] Further, the processor 1001 may call the control program of the device stored in the memory 1005, and also perform the following operations:
[0068] The current system resources and / or the resources to be optimized include at least one of applications, processes, and threads.
[0069] Please refer to Figure 2 In the first embodiment of the present invention, the method for adjusting system resources comprises the following steps:
[0070] Step S1, obtaining resources to be optimized corresponding to current system resources.
[0071] In this embodiment, the current system resource and / or the resource to be optimized include at least one of an application, a process, and a thread. The following description is made by taking the current system resource as the current running thread and the resource to be optimized as the thread to be optimized as an example. It can be understood that in all the following embodiments, the current running thread can be replaced with the current running application and the corresponding current running process, and the thread to be optimized can be replaced with the application to be optimized or the corresponding process to be optimized.
[0072] In this embodiment, applications can be divided into foreground applications and background applications according to the running state. Foreground applications refer to applications running in the foreground of the terminal. Foreground applications can be displayed in the foreground and interact with users. Background applications refer to applications running in the background of the terminal. Background applications generally cannot be displayed in the foreground and interact with users. The terminal can control the switching of foreground and background operations between different applications. The operation of an application (Application, referred to as APP) is usually reflected by the operation of multiple related processes. A process is a running activity of a program in a computer on a certain data set. It is the basic unit for resource allocation and scheduling of the system and the basis of the operating system structure. A thread is an entity of a process and the basic unit for scheduling and dispatching by the central processing unit (CPU). It is a basic unit that can run independently and is smaller than a process. The process of an application running includes at least one or more threads. A thread can create and cancel another thread; multiple threads in the same process can be executed concurrently. The application in this embodiment can be a game application, a music application, a social application, or a payment application. For example, a user can play games through a game application, watch videos through a video application, and play music through a music application.
[0073] In this embodiment, dependency means that an application needs to use the data of another or more applications to successfully execute the application. The two applications in a dependency relationship are the dependent application and the dependent application. Since the operation of an application is usually reflected by the operation of multiple related processes, the dependency between applications is also manifested as the dependency between processes. For example, a process a in application A depends on a process b in application B, that is, process b is dependent on process a, and process a needs to use the data of process b to execute process a. It also shows that application A depends on application B, or application B is dependent on application A, and application A needs to use the data of application B to execute application A. At this time, application A is the dependent application. It can be understood that the dependent application may also be a foreground application, and the dependent application may be a background application. The terminal can detect from the background application set to query whether there is a background application that is dependent on the foreground application.
[0074] In this embodiment, the currently running thread may be a display thread in the process corresponding to the foreground application when it is running, or a background thread in the process corresponding to the background application when it is running. The following description is made by taking the currently running thread as the display process of the terminal display interface as an example. In one embodiment, the thread to be optimized corresponding to the currently running thread, that is, a thread of the background application that the currently running thread depends on, the currently running thread needs the application to be optimized that it depends on to return corresponding data before it can continue to execute. It can be understood that since the currently running thread needs the corresponding application to be optimized to return corresponding data before it can continue to execute, the thread to be optimized must be executed first before the currently running thread. At this time, the application to be optimized is transformed into the currently running thread. After the dependent thread executes and returns corresponding data to the dependent thread, the dependent thread can continue to run. It can be seen that the currently running thread is the thread currently running on the terminal. The currently running thread can be a thread that depends on other threads, or a thread that is depended on by other threads.
[0075] In one embodiment, the thread corresponding to the currently running thread may be one or more threads. For example, when taking a photo using the WeChat application, the current display thread of WeChat needs to call the camera thread; when video chatting through the WeChat application, it may be necessary to call the camera thread and the microphone thread at the same time.
[0076] Step S20, adjusting the resource to be optimized according to a preset strategy. In this embodiment, the purpose of adjusting the adjustment strategy is to increase the system priority of the resource to be optimized, so that the priority of the resource to be optimized is higher than the priority before adjustment, so that the resource to be optimized runs faster to return the data required for operation to the current system resource. For example, when the current system resource is the current running thread and the resource to be optimized is the thread to be optimized, the thread to be optimized is the thread on which the current running thread depends. The result of adjusting the priority of the thread to be optimized is that the priority of the thread to be optimized after adjustment is equal to or higher than the priority of the current running thread. Priority represents the priority level of resource occupancy of the application thread, which is used to reflect the importance of the corresponding thread. Priority can include multiple levels, and the priorities of different threads are not necessarily the same. The priority of each thread can be set in advance. For example, the thread of the system-level application can be set to a higher priority, and the thread of the third-party application can be set to a lower priority. Resources refer to the software or hardware resources that a terminal must use when processing application events, such as the terminal's CPU (Central Processing Unit), memory, hardware, network resources, IO (Input-Output), etc.
[0077] In one embodiment, the priority of the thread to be optimized may be the relative size of the resources that the thread to be optimized can obtain, which is generally expressed by a value or ratio. For example, the priority value corresponding to the currently running thread is 100, and the priority value corresponding to the priority of the thread to be optimized is 80, then the priority corresponding to the currently running thread is higher than the priority of the thread to be optimized; for another example, the priority ratio corresponding to the currently running thread is 1%, and the priority value corresponding to the priority of the thread to be optimized is 2%, then the priority corresponding to the currently running thread is lower than the priority of the thread to be optimized.
[0078] In this embodiment, after the currently running thread obtains the corresponding thread to be optimized, which is the thread to be optimized that the currently running thread depends on, the priority of the thread to be optimized is adjusted so that the adjusted priority of the thread to be optimized is equal to or higher than the priority of the currently running thread. For example, when the priority value corresponding to the currently running thread is 100, and the priority value corresponding to the priority of the thread to be optimized is 80, the priority of the thread to be optimized is adjusted to be equal to 100 or greater than 100. When the currently running thread enters a dormant state and the thread to be optimized is controlled to execute first, the system can give the thread to be optimized resources corresponding to its priority (adjusted priority), so that when the thread to be optimized (the dependent thread) is executed, it has resources equal to or more than the original resources of the dependent thread, so as to complete the running process faster and return the corresponding data to the dependent thread. When the currently running thread is the above-mentioned display thread, the display thread can obtain the data required for execution in a timely manner to avoid the display process from being stuck.
[0079] Preferably, the priority of the thread to be optimized is adjusted to be equal to the priority of the currently running thread, that is, when the thread to be optimized (dependent thread) is running, it has resources equal to the original resources of the dependent thread, so that the thread to be optimized (dependent thread) can be executed quickly, and at the same time, the thread to be optimized (dependent thread) can be prevented from having more resources than the original resources of the dependent thread, which will affect the priorities of other threads in the system.
[0080] In another embodiment, the thread to be optimized corresponding to the currently running thread is not the thread on which the currently running thread depends, but a thread that has no dependency relationship with the currently running thread. By reducing the priority of the thread to be optimized, the priority of the thread to be optimized is lower than or equal to the priority of the currently running thread. Since priority is a relative concept, the priority of the thread that the currently running thread does not depend on is reduced, so the priority of the thread on which the currently running thread depends will increase. In this way, the background thread on which the currently running thread depends can also be executed quickly and return the corresponding data to the currently running thread. When the currently running thread is the above-mentioned display thread, the display thread can also obtain the data required for execution in time to avoid the display process from being stuck. It should be noted that in the following embodiments, the thread to be optimized corresponding to the currently running thread is explained as the background thread on which the currently running thread depends. In another embodiment, the priority of the thread to be optimized can also be increased by reducing the priority of the currently running thread.
[0081] In summary, the technical solution of the present invention obtains the thread to be optimized corresponding to the currently running thread, and adjusts the priority of the thread to be optimized so that the priority of the thread to be optimized is equal to or higher than the priority of the currently running thread. When the thread to be optimized is running, it has equal or more CPU resources than the currently running thread, so that the thread to be optimized can complete the running process faster and return the corresponding data to the currently running thread. When the currently running thread is the display thread of the terminal, the display thread can obtain the data required for execution in time to avoid the display process from being stuck, and improve the smoothness of the foreground application. Similarly, the resources in the technical solution of the present invention include at least one of applications, threads and processes. By obtaining the resources to be optimized corresponding to the current system resources; adjusting the resources to be optimized according to the preset strategy, so that the priority of the resources to be optimized on which the current system resources depend is improved, so that the resources to be optimized can run faster, thereby avoiding the terminal running stuck and improving the smoothness of the application running.
[0082] Optionally, in the second embodiment, as Figure 3 As shown, based on the first embodiment, step S20 includes:
[0083] Step S21, when there is communication between the current system resource and the resource to be optimized, obtaining the priority of the current system resource and the corresponding communication request;
[0084] Step S22, obtaining the priority of the resource to be optimized in response to the communication request;
[0085] Step S23: adjusting the priority of the current system resources and / or the resources to be optimized so that the priority of the resources to be optimized is higher than or equal to the priority of the current system resources.
[0086] In this embodiment, the adjustment process may be, when the priority of the currently running thread is higher than the priority of the thread to be optimized, adjusting the priority of the thread to be optimized to be equal to or higher than the priority of the currently running thread; the adjustment process may also be, adjusting the priority of the currently running thread to be equal to or lower than the priority of the thread to be optimized, in this way, the effect of making the priority of the thread to be optimized equal to or higher than the priority of the currently running thread can also be achieved. The following is an explanation of adjusting the priority of the thread to be optimized so that the priority of the thread to be optimized is equal to or higher than the priority of the current thread.
[0087] In this embodiment, the resource is a thread as an example for explanation. The currently running thread and the thread to be optimized can be two threads in the same process, or two threads belonging to different processes. When the currently running thread and the thread to be optimized are two threads belonging to different processes, there is inter-process communication (IPC) between the currently running thread and the thread to be optimized. Common inter-process communication mechanisms include Binder communication, pipe, signal and trace, socket, message queue, shared memory, semaphore, etc.
[0088] The following is an example of the Binder communication mechanism: the current running thread is the thread corresponding to the communication request created by the Binder client (also called the Client, the requester, and the sender) to request the Binder server (also called the Server) to return data. The thread to be optimized is the thread corresponding to the Binder server responding to the communication request, and obtains the corresponding data and returns it to the thread corresponding to the Binder client. When receiving the communication request from the Binder client, while saving the communication request, obtain the priority of the thread corresponding to the communication request, that is, the current running thread (dependent thread), and when the priority of the current running thread is higher than the priority of the thread to be optimized, adjust the priority of the thread to be optimized so that the adjusted priority of the thread to be optimized is equal to or higher than the priority of the current running thread; when the priority of the current running thread is equal to or lower than the priority of the thread to be optimized, retain the priority of the thread to be optimized without adjustment, so as to ensure that the thread executed by the Binder server quickly obtains the corresponding data and returns it to the thread waiting to receive data in the Binder client, that is, the current running thread (dependent thread), to ensure that the current running thread runs quickly.
[0089] Optionally, in the third embodiment, as Figure 4 As shown, based on the above-mentioned Embodiment 1-2, while executing step S20, the following steps are executed:
[0090] Step S30, storing the resource information of the resource to be optimized into the stack of the current system resources;
[0091] Step S40, after the resource to be optimized has finished running, and when the resource information of the resource to be optimized matches the top information of the stack, the top information of the stack is retrieved to restore the initial priority of the resource to be optimized.
[0092] In this embodiment, taking the resource as a thread as an example, the system creates a stack for the currently running thread to save the thread information of the thread to be optimized (the thread information is also one of the resource information mentioned above. It can be understood that when the resource is an application, the resource information is the application information; when the resource is a process, the resource information is the process information), wherein the thread information includes at least the thread identification information such as the thread number, the initial priority of the thread, and the thread status. While executing the step S20, that is, while adjusting the priority of the thread to be optimized, of course, before adjusting the priority of the thread to be optimized, the thread information of the thread to be optimized is stored in the stack, and after the execution of the thread to be optimized is completed, the thread information of the thread to be optimized in the stack is taken out to restore the initial priority of the thread to be optimized. The reason for restoring the initial priority of the thread to be optimized is that the priority of the thread to be optimized (dependent thread) after adjustment is for the currently running thread (dependent thread), and is used to ensure the fast execution of the currently running thread (dependent thread). After the execution of the thread to be optimized (dependent thread) is completed and the corresponding data is returned to the currently running thread (dependent thread), the priority of the thread to be optimized (dependent thread) after adjustment is no longer targeted, in order to avoid the adjusted priority of the thread to be optimized (dependent thread) affecting the priorities of other threads in the system, and to ensure that other threads in the system are executed according to their respective priorities.
[0093] In this embodiment, the dependent thread and the dependent thread are relative. For example, the currently running thread A is the dependent thread, and the thread B to be optimized is the dependent thread. The thread to be optimized may also depend on thread C for execution. At this time, relative to thread C, the thread B to be optimized is the dependent thread, that is, threads A, B, and C depend on each other in sequence, and the priorities of threads B and C are adjusted in sequence. When thread B is executed first, the thread information of thread B needs to be stored in the stack first. Because thread B depends on thread C, thread C needs to be executed before thread B, so the thread information of thread C needs to be stored in the stack. At this time, the stack contains thread C and thread B. , and because the thread information of thread C is pushed into the stack later than the thread information of thread B, the thread information of thread C is at the top of the stack; after thread C is executed and the data is put back to thread B, thread C needs to be matched with the stack top information, and when the match is successful, the stack top information, i.e., the thread information of thread C, is taken out to restore the initial priority of thread C; thread B continues to execute after receiving the data returned by thread C, and after thread B is executed and the data is put back to thread A, thread B needs to be matched with the stack top information, and when the match is successful, the stack top information, i.e., the thread information of thread B, is taken out to restore the initial priority of thread B. Therefore, when multiple threads depend on each other in sequence, the thread information of the threads needs to be pushed into the stack in sequence, and popped out in sequence after the threads are executed in order to restore the initial priorities of multiple threads.
[0094] Optionally, in a fourth embodiment, based on the above-mentioned first to third embodiments, step S20 includes:
[0095] Step S24: When the resource to be optimized is a preset resource, adjust the priority of the preset resource to be higher than or equal to the priority of the current system resource.
[0096] In this embodiment, the preset resource is taken as a lock-holding thread as an example for explanation. When the preset resource is a lock-holding thread, the priority of the lock-holding thread is adjusted to be equal to or higher than the priority of the currently running thread; the thread to be optimized (dependent thread) is a lock-holding thread, and the currently running thread (dependent thread) needs to obtain the lock before it can continue to execute. Therefore, the lock-holding thread needs to release the lock, and the lock-holding thread must be released before the lock-holding thread is executed first. Therefore, in this embodiment, the priority of the lock-holding thread is adjusted so that the priority of the lock-holding thread is equal to or higher than the priority of the currently running thread, so that the lock-holding thread can execute quickly, and after the lock-holding thread is executed, the lock is released and data is returned to the currently running thread. The currently running thread continues to execute after obtaining the lock and the data returned by the lock-holding thread, so as to avoid the foreground application corresponding to the currently running thread from being stuck, and improve the fluidity of the foreground application when running.
[0097] Preferably, the priority of the lock-holding thread is adjusted to be equal to the priority of the currently running thread, that is, when the lock-holding thread (dependent thread) runs, it has resources equal to the original resources of the dependent thread, so that the lock-holding thread (dependent thread) can be executed quickly, and at the same time, the lock-holding thread (dependent thread) can be prevented from having more resources than the original dependent thread, which will affect the priorities of other threads in the system.
[0098] Optionally, in the fifth embodiment, as Figure 5 As shown, based on the fourth embodiment, while executing step S20, the following steps are executed:
[0099] Step S24, storing the resource information of the preset resource into the stack of the current system resources;
[0100] Step S25, after the preset resource is finished running, control the preset resource to release the corresponding resource, and when the resource information of the preset resource matches the stack top information of the stack, take out the stack top information to restore the initial priority of the preset resource.
[0101] In this embodiment, the preset resource is taken as a lock-holding thread as an example for explanation, and the system creates a stack for the currently running thread to store the thread information of the lock-holding thread. While executing the step S20, that is, while adjusting the priority of the lock-holding thread, of course, before adjusting the priority of the thread to be optimized, the thread information of the lock-holding thread can be stored in the stack. After the execution of the lock-holding thread is completed, the thread information of the lock-holding thread in the stack is taken out to restore the initial priority of the lock-holding thread, so as to avoid the adjusted priority of the lock-holding thread (dependent thread) affecting the priorities of other threads in the system, and ensure that other threads in the system are executed according to their respective priorities. In this implementation, controlling the preset resource to release the corresponding resource can be controlling the lock-holding thread to release the lock, that is, controlling the resources occupied by the lock-holding thread.
[0102] In this embodiment, when there are multiple interdependent threads, there may be multiple thread locks in the multiple interdependent threads. Therefore, after the lock-holding thread has finished running, the lock-holding thread is controlled to release the lock, and the lock-holding thread needs to be matched with the top information of the stack. When the lock-holding thread matches the top information, the top information is taken out to restore the initial priority of the lock-holding thread, so as to avoid the priority of a lock-holding thread D being erroneously restored to the priority of another lock-holding thread E when the lock-holding thread does not match the top information due to the existence of multiple thread locks.
[0103] Optionally, in a sixth embodiment, based on the third or fifth embodiment, the adjustment method further includes:
[0104] Step S50, when at least one of the following situations occurs: a switching instruction corresponding to the current system resource is received, or an error occurs in the current system resource, the resource information stored in the stack is retrieved. In this embodiment, the current system resource is a locked thread as an example for explanation. When a switching instruction of a foreground application is received, it indicates that the user needs to switch the foreground application. At this time, the priority of the thread adjusted before the switch is no longer applicable to the foreground application after the switch. Therefore, the thread information of all threads stored in the stack is retrieved to restore the initial priority of the adjusted thread, and the priority of the process on which the display process of the foreground application after the switch depends is adjusted to ensure the smoothness of the operation of the foreground application after the switch. Similarly, when the process corresponding to the currently running thread has an error due to an unexpected situation, such as a thread crash, the thread information of all threads stored in the stack is also retrieved to restore the initial priority of the adjusted thread. The threads include the above-mentioned locked threads and unlocked threads. The threads in the stack do not need to be matched with the stack top information after execution, but can be retrieved in sequence, thereby improving the efficiency of popping the thread information.
[0105] Optionally, in the seventh embodiment, as Figure 6 As shown, based on the above-mentioned embodiments 1 to 6, the step before step S10 includes:
[0106] Step S60, within a preset time period and / or a preset geographic fence, using system resources with a usage duration greater than or equal to a preset duration and / or an activation frequency greater than or equal to a preset frequency as preset resources;
[0107] When the resource corresponding to the current system resource is the preset resource, the step of obtaining the resource to be optimized corresponding to the current system resource is performed.
[0108] In this embodiment, the current system resource is used as an application as an example for explanation. For example, the preset time period can be one day. In one day, applications with a usage time greater than the preset time, such as 5 hours, and / or an opening frequency greater than the preset frequency, such as 10 times, are used as preset applications; for another example, the preset time period can be one hour. In one hour, applications with a usage time greater than the preset time, such as 20 minutes, and / or an opening frequency greater than the preset frequency, such as 2 times, are used as preset applications; the priority of the thread to be optimized corresponding to the thread of the preset application is adjusted, and the priority of the thread to be optimized corresponding to the thread that does not belong to the preset application is not adjusted, thereby avoiding adjusting the priority of the thread to be optimized corresponding to all threads, reducing system power consumption, and only adjusting the priority of the thread to be optimized corresponding to the thread of the preset application. In the user's view, it not only meets the user's daily needs, but also improves the smoothness of the foreground application. Further, in this embodiment, in order to reduce the number of priority adjustments and the system power consumption, only the application with the longest usage time and / or the highest opening frequency within the preset time can be used as the preset application.
[0109] In this embodiment, a preset geographic fence divides a preset virtual geographic area, such as a user's home, a user's office, or a large shopping mall. Within the preset geographic fence, applications with a usage time greater than a preset time and / or an activation frequency greater than a preset frequency are used as preset applications. The usage time and activation frequency can be relative to the total time the terminal is within the preset geographic fence, or relative to a preset period of time the terminal is within the preset geographic fence. The preset time and activation frequency can be adjusted according to actual conditions; for example, if the total time the terminal is within the preset geographic fence such as at home is 10,000 hours, then The preset duration can be set to 2000 hours. If the preset period of the terminal in the preset geographic fence is one month, the preset duration can be 200 hours, and the preset frequency can be adjusted in the same way. In this embodiment, the priority of the thread to be optimized corresponding to the thread of the preset application is adjusted, and the priority of the thread to be optimized corresponding to the thread that does not belong to the preset application is not adjusted, thereby avoiding adjusting the priority of the thread to be optimized corresponding to all threads, reducing system power consumption, and only adjusting the priority of the thread to be optimized corresponding to the thread of the preset application. From the user's point of view, it not only meets the user's daily needs, but also improves the smoothness of the foreground application. Furthermore, in this embodiment, in order to reduce the number of priority adjustments and the system power consumption, only the application with the longest usage time and / or the highest opening frequency within the preset geographic fence can be used as the preset application.
[0110] To achieve the above-mentioned purpose, the present invention also provides a system resource adjustment device, which includes a memory, a processor, and a system resource adjustment program stored in the memory and executable on the processor. When the system resource adjustment program is executed by the processor, the steps of the system resource adjustment method described above are implemented.
[0111] To achieve the above objectives, the present invention also provides a computer-readable storage medium, on which a system resource adjustment program is stored. When the system resource adjustment program is executed by a processor, the steps of the system resource adjustment method described above are implemented.
[0112] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0113] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for a terminal device (which can be a TV, mobile phone, computer, server, device, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0114] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for adjusting system resources, characterized in that: Adjustment of system resources includes the following steps: S1: Obtain the resources to be optimized corresponding to the current system resources; S2: adjusting the resource to be optimized according to a preset strategy, including: when the resource to be optimized is a preset resource, adjusting the priority of the preset resource to be higher than or equal to the priority of the current system resource, wherein the preset resource includes a system resource whose usage time within a preset time period and / or a preset geographic fence is greater than or equal to a preset time, and / or whose activation frequency is greater than or equal to a preset frequency; and / or storing resource information of the resource to be optimized and / or preset resource through the stack of the current system resources; The S2 step further includes: When there is communication between the current system resource and the resource to be optimized, obtaining the priority of the current system resource and the corresponding communication request; Obtaining the priority of the resource to be optimized in response to the communication request; The priority of the current system resource and / or the resource to be optimized is adjusted so that the priority of the resource to be optimized is higher than or equal to the priority of the current system resource.
2. The method for adjusting system resources according to claim 1, characterized in that: The step S2 further includes: Storing the resource information of the resource to be optimized in the stack of the current system resources; After the resource to be optimized has finished running, and when the resource information of the resource to be optimized matches the top information of the stack, the top information of the stack is retrieved to restore the initial priority of the resource to be optimized.
3. The method for adjusting system resources according to claim 1, characterized in that: The step S2 further includes: Storing resource information of preset resources into the stack of current system resources; After the preset resource is finished running, the preset resource is controlled to release the corresponding resource, and when the resource information of the preset resource matches the stack top information of the stack, the stack top information is taken out to restore the initial priority of the preset resource.
4. The method for adjusting system resources according to claim 2 or 3, characterized in that: The adjustment method further comprises: When at least one of a switching instruction corresponding to the current system resource is received and an error occurs in the current system resource, the resource information stored in the stack is retrieved.
5. The method for adjusting system resources according to claim 1, characterized in that: Before the S1 step, it also includes: In a preset time period and / or a preset geographic fence, system resources with a usage duration greater than or equal to a preset duration and / or an opening frequency greater than or equal to a preset frequency are regarded as preset resources; When the resource corresponding to the current system resource is the preset resource, the step of acquiring the resource to be optimized corresponding to the current system resource is performed.
6. The method for adjusting system resources according to claim 4, characterized in that: The current system resources and / or the resources to be optimized include at least one of applications, processes, and threads.
7. A system resource adjustment device, characterized in that: The system resource adjustment device includes a memory, a processor, and a system resource adjustment program stored in the memory and executable on the processor. When the system resource adjustment program is executed by the processor, the steps of the system resource adjustment method as described in any one of claims 1 to 6 are implemented.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a system resource adjustment program, and when the system resource adjustment program is executed by a processor, the steps of the system resource adjustment method according to any one of claims 1 to 6 are implemented.
