Task scheduling method and device, and electronic device
By introducing a critical lock mechanism and parameter information judgment in task scheduling, tasks with target identification information are run first, which solves the system lag problem caused by priority inversion in multi-task operation and improves system performance and user experience.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- VIVO MOBILE COMM CO LTD
- Filing Date
- 2023-01-30
- Publication Date
- 2026-04-14
AI Technical Summary
In existing technologies, system lag caused by priority inversion, especially during multitasking, occurs when high-priority tasks are blocked by low-priority tasks and cannot run in a timely manner, resulting in a decrease in system performance.
By setting up a critical lock mechanism, it is ensured that only one task can acquire the critical lock at a time. By obtaining the task's parameter information, it is determined whether it meets the preset conditions, especially whether it contains target identification information and identification duration, so that special tasks are run first to avoid system congestion and lag.
It effectively avoids system lag, improves task execution efficiency, reduces system power consumption, and enhances user experience.
Smart Images

Figure CN115964180B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of communication technology, and more specifically, relates to a task scheduling method, apparatus and electronic device. Background Technology
[0002] With the continuous development of science and technology, electronic devices are becoming increasingly functional, and more and more applications are running in the background. Typically, when many programs are running simultaneously, the system can adjust resources based on scheduling priorities in its resource scheduling strategy. For example, while a user is browsing WeChat Moments on their phone in the foreground, many other applications are running in the background, such as QQ receiving messages or Xunlei downloading movies. The current system's resource scheduling strategy prioritizes foreground applications, meaning they receive more resources. For example, WeChat might be prioritized for running on the CPU's larger cores with a higher scheduling priority, while background applications have their resource access restricted. For instance, QQ or Xunlei might be restricted to running on the CPU's smaller cores with a lower scheduling priority.
[0003] However, this resource scheduling strategy will greatly exacerbate the priority inversion problem, that is, a high-priority task cannot run because it is blocked by a low-priority task. The high-priority task can only run after the low-priority task releases the system lock, which leads to system lag. Summary of the Invention
[0004] The purpose of this application is to provide a task scheduling method, apparatus, and electronic device that can solve the problem of system lag caused by priority inversion in related technologies.
[0005] In a first aspect, embodiments of this application provide a task scheduling method, the method comprising:
[0006] If the first task acquires the key lock, obtain the parameter information of the first task;
[0007] If the parameter information meets the preset conditions, the first task is run, wherein the parameter information meeting the preset conditions includes target identification information.
[0008] Secondly, embodiments of this application provide a task scheduling device, the device comprising:
[0009] The acquisition module is used to acquire parameter information of the first task when the first task acquires the key lock;
[0010] The control module is used to run the first task when the parameter information meets preset conditions, wherein the parameter information meeting the preset conditions includes target identification information.
[0011] Thirdly, embodiments of this application provide an electronic device including a processor and a memory, the memory storing programs or instructions executable on the processor, the programs or instructions, when executed by the processor, implementing the steps of the method described in the first aspect.
[0012] Fourthly, embodiments of this application provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0013] Fifthly, embodiments of this application provide a chip, the chip including a processor and a communication interface, the communication interface being coupled to the processor, the processor being used to run programs or instructions to implement the method as described in the first aspect.
[0014] In a sixth aspect, embodiments of this application provide a computer program product stored in a storage medium, which is executed by at least one processor to implement the method described in the first aspect.
[0015] In this embodiment, by setting a key lock, it can be ensured that only one task acquires the key lock at a time. This allows multiple tasks to run concurrently, prioritizing their execution based on the time they acquire the key lock, thus avoiding system congestion. By acquiring the parameter information of the first task when it acquires the key lock, and then running the first task only if the parameter information meets preset conditions, the first task with target identification information can be run first, thereby shortening its waiting time and avoiding the system lag caused by priority inversion in related technologies. Attached Figure Description
[0016] Figure 1 A flowchart of the task scheduling method provided in the embodiments of this application;
[0017] Figure 2 A schematic flowchart illustrating an example of this application;
[0018] Figure 3 A schematic flowchart for another example of this application;
[0019] Figure 4 A schematic flowchart for yet another example of this application;
[0020] Figure 5This is a schematic diagram of a task scheduling device according to an embodiment of this application;
[0021] Figure 6 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application;
[0022] Figure 7 This is a schematic diagram of the hardware structure of an electronic device provided in another embodiment of this application. Detailed Implementation
[0023] The technical solutions of the embodiments of this application will be clearly described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this application. All other embodiments obtained by those skilled in the art based on the embodiments of this application are within the scope of protection of this application.
[0024] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and not to describe a specific order or sequence. It should be understood that such use of data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and the number of objects is not limited; for example, a first object can be one or more. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0025] The task scheduling method provided in this application will be described in detail below with reference to the accompanying drawings, through specific embodiments and application scenarios.
[0026] like Figure 1 As shown, this is a task scheduling method provided in an embodiment of this application. The method includes the following steps 101 to 102, which will be described in detail below.
[0027] Step 101: If the first task acquires the key lock, obtain the parameter information of the first task.
[0028] Step 102: If the parameter information meets the preset conditions, run the first task.
[0029] In this embodiment, multiple tasks often run simultaneously in the system of electronic devices. For example, while playing a game on a mobile phone, the game application may be running in the foreground, while other applications such as "Settings," "Music," and "File Manager" may be running in the background. However, due to limitations in the hardware resources of electronic devices, such as the limited number of UFS storage devices in a mobile phone, only one task can access system resources at a time when multiple tasks are calling for them. A key lock can be set at the entry point for data access to ensure that only one task reads system resources at a time. In other words, only one task can acquire the key lock at any given time.
[0030] After setting a critical lock at the entry point for data access, when multiple tasks need to acquire system resources, only one task can acquire the critical lock at a time. Therefore, these tasks acquire the critical lock sequentially according to their time sequence. Once any task acquires the critical lock, it enters a critical section where it is either waiting to run or in operation, and the corresponding system resources are occupied. Typically, the task that acquires the critical lock earlier will run before the task that acquires it later, thus allowing the multiple tasks to run in the order they acquired the critical lock.
[0031] If it is necessary to prioritize the execution of a specific task among multiple tasks, when that task acquires the key lock, it can be marked with target identification information, and this target identification information can be used as one of the parameter information of that task. The target identification information can be used to indicate that its corresponding task is a special task. For example, the target identification information can be a special character, which is used to mark the special task that needs to be executed first. Those skilled in the art should understand that the target identification information is not specifically limited here.
[0032] If the first task acquires the key lock, its parameter information is obtained. If the target identification information is included in the parameter information, the first task is determined to be a special task that meets preset conditions. If the target identification information is not included in the parameter information, the first task is determined to not meet the preset conditions. Here, the first task can be any one of the plurality of tasks.
[0033] If the first task is determined to be a special task that meets preset conditions, the first task is run on the CPU, and other high-priority tasks are prohibited from running.
[0034] For example, if Task 1 and Task 2 acquire the key lock sequentially, and neither Task 1 nor Task 2 has any identification information, then Task 1 and Task 2 will run in the order in which they acquired the key lock. If Task 2 is a special task marked with special characters, and Task 2 acquires the key lock with identification information, then Task 2 will run before Task 1.
[0035] According to the embodiments of this application, by setting a key lock, it can be ensured that only one task acquires the key lock at a time. This allows multiple tasks to run concurrently, prioritizing their execution based on the time they acquire the key lock, thus avoiding system congestion. By acquiring the parameter information of the first task when it acquires the key lock, and then running the first task only if the parameter information meets preset conditions, the first task with target identifier information can be run first, thereby shortening its waiting time and avoiding the system lag caused by priority inversion in related technologies.
[0036] In one embodiment, to avoid the problem of special tasks running for a long time causing other tasks to malfunction and thus reducing user experience, this application embodiment also provides a method for controlling task scheduling based on the identification duration of target identification information. That is, when the parameter information includes target identification information, the parameter information also satisfies the preset condition that the identification duration of the target identification information is less than or equal to a preset duration.
[0037] In this embodiment, when multiple tasks acquire a key lock, a specific task can be marked with the target identification information, and the duration for which the target identification information is used to mark that specific task can be recorded. Furthermore, this marking duration is associated with the corresponding target identification information.
[0038] If the first task acquires the key lock, its parameter information is obtained, and it is first determined whether the parameter information includes target identification information. If the parameter information includes target identification information, it is then determined whether the identification duration of the target identification information is less than or equal to a preset duration. If the identification duration is less than or equal to the preset duration, the parameter information is determined to meet a preset condition, thereby prohibiting other high-priority tasks from running and allowing the first task to run.
[0039] According to the embodiments of this application, when the parameter information includes target identification information, the parameter information also satisfies the preset condition that the identification duration of the target identification information is less than or equal to the preset duration, which can avoid the operation of other tasks being affected by the long-term operation of special tasks, thereby affecting the system's operating speed and reducing the user experience.
[0040] In one embodiment, after obtaining the parameter information of the first task, the method further includes:
[0041] Step 201: If the parameter information does not meet the preset conditions and there is a second task with a higher priority than the first task, run the second task; wherein, the parameter information not meeting the preset conditions includes one of the following: the parameter information does not include the target identification information, or the parameter information includes the target identification information but the identification duration of the target identification information is greater than the preset duration;
[0042] Step 202: After the second task exits, run the first task.
[0043] In this embodiment, if the target identification information is not included in the parameter information of the first task, or if the target identification information is included in the parameter information but the identification duration of the target identification information is greater than the preset duration, it is determined that the parameter information of the first task does not meet the preset conditions.
[0044] If the parameter information of the first task does not meet the preset conditions, and there is a second task with a higher priority than the first task, the second task is run. Furthermore, while the second task is running, the first task is in a waiting state. After the second task exits its execution, the first task is run.
[0045] For example, Task 2 acquires the key lock before Task 1 acquires the key lock, meaning Task 2 has a higher priority than Task 1. Furthermore, Task 1's parameters do not include target identification information, or Task 1's parameters include target identification information but the target identification duration exceeds a preset duration. In this case, Task 1's parameters do not meet the set conditions. Based on priority, Task 2 runs first, and after Task 2 completes and exits, Task 1 runs.
[0046] According to the embodiments of this application, if the parameter information of the first task does not meet the set conditions and there is a second task with a higher priority than the first task, the second task is run. After the second task exits, the first task is run, which can avoid the problem of system lag caused by multi-task running conflicts.
[0047] In one embodiment, to improve system operating speed and reduce system power consumption, this application embodiment further sets a condition for triggering the acquisition of parameter information of the first task. That is, when the first task acquires the key lock, acquiring the parameter information of the first task includes:
[0048] Step 301: When the first task acquires the key lock and the first task occupies system resources, obtain the parameter information of the first task;
[0049] Step 302: When the first task acquires the key lock and the third task occupies the system resources, wait for the first task to be woken up, and when the first task is woken up, obtain the parameter information of the first task; wherein, the first task is woken up when the third task releases the system resources.
[0050] In this embodiment, two conditions are set to trigger the acquisition of parameter information for the first task:
[0051] Condition 1: Obtain the parameter information of the first task when the first task acquires the key lock and the first task occupies system resources.
[0052] If the first task acquires the key lock and does not occupy system resources, it indicates that the first task may be blocked. In this case, no detection is performed on whether the parameter information of the first task meets the preset conditions.
[0053] If the first task acquires the key lock and occupies system resources, it is necessary to determine whether the first task is a special task that meets preset conditions, and then determine the priority order of the first task and other tasks that need to be run. That is, the parameter information of the first task is obtained to check whether the parameter information of the first task meets the preset conditions.
[0054] Condition 2: If the first task acquires the key lock and the third task occupies the system resources, wait for the first task to be woken up, and if the first task is woken up, obtain the parameter information of the first task; wherein the first task is woken up when the third task releases the system resources.
[0055] Condition two addresses the scenario where the first task acquires the key lock, but the third task is occupying system resources. In this case, the execution of the first task may be blocked. For example, if the first task has a nested lock structure, before running the first task, it needs to acquire not only the key lock as the outer lock but also the inner lock used to lock the system resources for its commission adjustment. After the first task acquires the key lock, the inner lock is occupied by the third task, preventing the acquisition of the inner lock. In this situation, the execution of the first task is blocked.
[0056] If the execution of the first task is blocked, other tasks are run in priority order, while the first task remains in a sleep state awaiting activation. The other tasks include the third task. After the third task completes and exits, the internal lock is released. At this time, the first task is activated and can acquire the internal lock, thereby occupying system resources. While the first task is occupying system resources, its parameter information is obtained to check whether it meets the preset conditions.
[0057] According to the embodiments of this application, by further setting the conditions for triggering the acquisition of parameter information of the first task, the system running speed can be improved and the system power consumption reduced. Furthermore, in the event that the first task is blocked, other tasks are run first, and the first task is woken up and its parameter information is acquired when the third task releases the system resources. This also avoids the problem of other low-priority tasks being unable to run due to high-priority tasks being blocked, thus improving the system running speed.
[0058] In one embodiment, after running the first task, the method further includes:
[0059] After the first task releases the key lock, the parameter information of the first task is cleared.
[0060] In this embodiment, after the first task is completed, the first task releases the key lock and clears the parameter information of the first task. Where the parameter information includes target identification information, clearing the parameter information of the first task means clearing the target identification information from the parameter information of the first task. Where the parameter information includes target identification information and the identification duration of the target identification information, clearing the parameter information of the first task means clearing both the target identification information and the identification duration of the target identification information from the parameter information of the first task.
[0061] According to the embodiments of this application, after the first task releases the key lock, the parameter information of the first task is cleared, thereby preventing the target identification information from affecting the normal operation of other tasks after the task with target identification information has been run.
[0062] In one embodiment, after obtaining the parameter information of the first task, the method further includes:
[0063] Step 401: When a set event occurs and the target identification information is included in the parameter information of the first task, obtain the identification duration of the target identification information.
[0064] In this embodiment, the event to be set can be a periodically occurring event. For example, the event to be set can be a Tick interrupt event. As can be understood, a Tick interrupt is a periodic clock interrupt, typically occurring every 4 milliseconds in a mobile phone system. The Tick interrupt can periodically update the task execution time information in the system, and then determine whether the currently running task needs to be scheduled based on this task execution time information.
[0065] During system operation, in the event of a set event, the timeout period for the identification duration of special tasks in the system, which include target identification information, can be determined.
[0066] Step 402: If the identification duration of the target identification information is greater than the preset duration, clear the target identification information from the parameter information of the first task.
[0067] In this embodiment, if the target identifier information's identifier duration exceeds the preset duration—that is, if the first task takes too long to run, the first task may malfunction and enter an infinite loop. In this case, the target identifier information in the first task's parameter information is cleared, and the first task is reordered according to the time it acquired the key lock to prevent it from running indefinitely.
[0068] According to the embodiments of this application, by obtaining the identification duration of the target identification information when a set event occurs and the parameter information of the first task includes the target identification information, and by clearing the target identification information from the parameter information of the first task when the identification duration of the target identification information is greater than the preset duration, the problem of other tasks being unable to run due to abnormal task operation can be avoided, thereby improving the system operation speed.
[0069] <Example 1>
[0070] Figure 2 This is a schematic diagram of a task scheduling method according to an example of the present invention. This example addresses the situation where there is a special task that cannot be preempted, and the special task is executed.
[0071] according to Figure 2 As shown in the example, the specific steps of the task scheduling method may include:
[0072] Step 21: Before the first task acquires system resources, acquire the key lock. When acquiring the key lock, mark the target identification information for the first task and record the marking duration of the target identification information for the first task. Then, use the target identification information and the marking duration of the target identification information as one of the parameter information of the first task.
[0073] Step 22: If the first task acquires the key lock and the first task occupies system resources, obtain the parameter information of the first task.
[0074] In this embodiment, the first task acquires the key lock, signifying that the first task has entered a critical section of waiting or running state, and the first task occupies the CPU. If there is a high-priority second task that needs to run, since the first task preempts the CPU, step 23 is executed to determine the running order of the first and second tasks.
[0075] Step 23: Determine whether the parameter information of the first task includes target identification information, and whether the identification duration of the target identification information of the first task exceeds the preset duration t.
[0076] Step 24. If the parameter information of the first task includes target identification information, and the identification duration of the target identification information is less than or equal to the preset duration t, then the CPU is prohibited from switching to the second task, and the CPU runs the first task.
[0077] Step 25: If the parameter information of the first task does not include target identification information, or the parameter information of the first task includes target identification information but the identification duration has exceeded the preset duration t, then the high-priority second task is run first.
[0078] Step 26: Once the second task is completed, the CPU will switch back to running the first task.
[0079] Step 27: First task: Release the key lock.
[0080] In this embodiment, the release of the key lock by the first task signifies that the first task has exited the critical section.
[0081] Step 28: Clear the target identification information from the parameter information of the first task.
[0082] In this embodiment, if in step 24 it is detected that the parameter information of the first task includes target identification information, and the identification duration of the target identification information is less than or equal to the preset duration t, then the CPU is prohibited from switching to the second task, and the CPU runs the first task, which can shorten the critical section time of the first task. In steps 25 and 26, if it is detected that the parameter information of the first task does not include target identification information, or the parameter information of the first task includes target identification information but the identification duration has exceeded the preset duration t, then the high-priority second task is run first. When the second task is completed, the CPU will switch back to running the first task, which can avoid the problem of system lag caused by priority inversion.
[0083] <Example 2>
[0084] Figure 3 This is a schematic diagram of a task scheduling method according to another example of the present invention, in which the CPU is actively relinquished when the first task is blocked, and then quickly switched back to running on the CPU.
[0085] according to Figure 3 As shown in the example, the specific steps of the task scheduling method may include:
[0086] Step 31: Before the first task acquires system resources, acquire the key lock. When acquiring the key lock, mark the target identification information for the first task and record the marking duration of the target identification information for the first task. Then, use the target identification information and the marking duration of the target identification information as one of the parameter information of the first task.
[0087] Step 32: If the first task acquires the key lock and the third task occupies the system resources, wait for the first task to be woken up.
[0088] In this embodiment, the first task acquires the critical lock, signifying that it has entered the critical section. At this time, the third task occupies the system resources that the first task needs to allocate, blocking the first task. The first task is then in a waiting-to-be-awakened state. The CPU will run other tasks, including the third task.
[0089] Step 33: When the first task is awakened, obtain the parameter information of the first task; wherein the first task is awakened when the third task releases the system resources.
[0090] In this embodiment, when the third task exits and releases system resources, the first task is awakened. Upon awakening of the first task, its parameter information is acquired to determine whether it meets preset conditions.
[0091] Step 34: Determine whether the parameter information of the first task includes target identification information, and whether the identification duration of the target identification information of the first task exceeds the preset duration t.
[0092] Step 35: If the parameter information of the first task includes the target identifier information and there is no timeout, then immediately switch the CPU back to running the first task.
[0093] Step 36: If the parameter information of the first task does not include the target identifier information, or if the parameter information of the first task includes the target identifier information but the identifier duration has expired, then determine whether to switch to other tasks to run based on whether there are other high-priority tasks that need to be run.
[0094] Step 37: After other high-priority tasks exit, the CPU switches back to the first task.
[0095] Step 38: The first task releases the critical lock, marking the first task's exit from the critical section.
[0096] Step 39: Clear the target identification information of the first task.
[0097] In this embodiment, if the first task is blocked, the CPU is proactively relinquished, and the current CPU will run the third task. When the third task exits, the first task is awakened. Upon awakening the first task, it is determined whether the parameter information of the first task meets preset conditions. If the parameter information of the first task includes target identifier information and there is no timeout, the current CPU is immediately switched back to running the first task. This avoids the problem of other tasks being unable to run due to high-priority tasks being blocked, and also improves system operating speed.
[0098] <Example 3>
[0099] Figure 4 This is a schematic diagram of a task scheduling method according to another example of the present invention, which targets the periodic timeout detection of the system to determine whether there is any abnormality in the operation of the task.
[0100] according to Figure 4 As shown in the example, the specific steps of the task scheduling method may include:
[0101] Step 41: A Tick interrupt occurs.
[0102] Step 42: When Tick is interrupted, check whether the first task is a special task that includes target identification information, and whether the identification duration of the target identification information exceeds the preset duration t.
[0103] Step 43: If the first task is a special task that includes target identification information, and its identification duration exceeds the preset duration t, then clear the target identification information of the first task, that is, allow the CPU to run other tasks.
[0104] Step 44: If the first task is not a special task, or if the first task is a special task that includes target identification information, but its identification duration exceeds the preset duration t, then exit the Tick timeout judgment.
[0105] In this embodiment, a Tick interrupt can be used to perform timeout checks on tasks with target identification information in the system. If the identification duration of the target identification information exceeds a preset duration, it indicates that the task has been preempting the CPU for an extended period, potentially leading to operational anomalies and an infinite loop. In this case, the target identification information of the task is cleared, allowing the task to be re-queued. Because the re-queued task has a lower priority, it will be placed further back in the queue, allowing the system to run other tasks. This avoids the problem of other tasks failing to run due to task operational anomalies, thus improving system speed.
[0106] The task scheduling method provided in this application can be executed by a task scheduling device. This application uses the task scheduling device executing the task scheduling method as an example to illustrate the task scheduling device provided in this application.
[0107] like Figure 5 As shown, a task scheduling device 500 provided in an embodiment of this application is included. The device 500 includes:
[0108] The acquisition module 501 is used to acquire parameter information of the first task when the first task acquires the key lock;
[0109] Control module 502 is used to run the first task when the parameter information meets preset conditions, wherein the parameter information meeting preset conditions includes target identification information.
[0110] According to the embodiments of this application, by setting a key lock, it can be ensured that only one task acquires the key lock at a time. This allows multiple tasks to run concurrently, prioritizing their execution based on the time they acquire the key lock, thus avoiding system congestion. By acquiring the parameter information of the first task when it acquires the key lock, and then running the first task only if the parameter information meets preset conditions, the first task with target identifier information can be run first, thereby shortening its waiting time and avoiding the system lag caused by priority inversion in related technologies.
[0111] In one embodiment, when the parameter information includes target identification information, the parameter information satisfying the preset condition further includes: the identification duration of the target identification information is less than or equal to a preset duration.
[0112] According to the embodiments of this application, when the parameter information includes target identification information, the parameter information also satisfies the preset condition that the identification duration of the target identification information is less than or equal to the preset duration, which can avoid the operation of other tasks being affected by the long-term operation of special tasks, thereby affecting the system's operating speed and reducing the user experience.
[0113] In one embodiment, the control module 502 is further configured to run the second task when the parameter information does not meet the preset conditions and there is a second task with a higher priority than the first task; wherein, the parameter information not meeting the preset conditions includes one of the following: the parameter information does not include the target identification information, or the parameter information includes the target identification information but the identification duration of the target identification information is greater than the preset duration;
[0114] After the second task exits, the first task is run.
[0115] According to the embodiments of this application, if the parameter information of the first task does not meet the set conditions and there is a second task with a higher priority than the first task, the second task is run. After the second task exits, the first task is run, which can avoid the problem of system lag caused by multi-task running conflicts.
[0116] In one embodiment, the device further includes: a cleaning module 503.
[0117] The clearing module 503 is used to clear the parameter information of the first task after the first task releases the key lock.
[0118] According to the embodiments of this application, after the first task releases the key lock, the parameter information of the first task is cleared, thereby preventing the target identification information from affecting the normal operation of other tasks after the task with target identification information has been run.
[0119] In one embodiment, the acquisition module 501 is specifically used to acquire parameter information of the first task when the first task acquires the key lock and the first task occupies system resources;
[0120] Alternatively, the acquisition module 501 is specifically used to wait for the first task to be woken up when the first task acquires the key lock and the third task occupies the system resources, and to acquire the parameter information of the first task when the first task is woken up; wherein the first task is woken up when the third task releases the system resources.
[0121] According to the embodiments of this application, by setting conditions to trigger the acquisition of parameter information of the first task, the system running speed can be improved and the system power consumption reduced. Furthermore, if the first task is blocked, other tasks are run first, and the first task is woken up and its parameter information is acquired when the third task releases the system resources. This also avoids the problem of other low-priority tasks being unable to run due to high-priority tasks being blocked, thus improving the system running speed.
[0122] In one embodiment, the acquisition module 501 is used to acquire the identification duration of the target identification information when a set event occurs and the parameter information of the first task includes the target identification information;
[0123] The clearing module 503 is used to clear the target identification information from the parameter information of the first task when the identification duration of the target identification information is greater than the preset duration.
[0124] According to the embodiments of this application, by obtaining the identification duration of the target identification information when a set event occurs and the parameter information of the first task includes the target identification information, and by clearing the target identification information from the parameter information of the first task when the identification duration of the target identification information is greater than the preset duration, the problem of other tasks being unable to run due to abnormal task operation can be avoided, thereby improving the system operation speed.
[0125] The task scheduling device in this application embodiment can be an electronic device or a component within an electronic device, such as an integrated circuit or a chip. The electronic device can be a terminal or other devices besides a terminal. For example, the electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, mobile internet device (MID), augmented reality (AR) / virtual reality (VR) device, robot, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc. It can also be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This application embodiment does not specifically limit the device.
[0126] The task scheduling device in this application embodiment can be a device with an operating system. This operating system can be Android, iOS, or other possible operating systems; this application embodiment does not specifically limit the specific operating system used.
[0127] The task scheduling device provided in this application embodiment can achieve... Figures 1 to 4 The various processes implemented in the method implementation examples will not be described again here to avoid repetition.
[0128] Optionally, such as Figure 6 As shown, this application embodiment also provides an electronic device 600, including a processor 601 and a memory 602. The memory 602 stores a program or instructions that can run on the processor 601. When the program or instructions are executed by the processor 601, they implement the various steps of the above-described task scheduling method embodiment and can achieve the same technical effect. To avoid repetition, they will not be described again here.
[0129] It should be noted that the electronic devices in the embodiments of this application include the mobile electronic devices and non-mobile electronic devices described above.
[0130] Figure 7 A schematic diagram of the hardware structure of an electronic device to implement an embodiment of this application.
[0131] The electronic device 1000 includes, but is not limited to, components such as: radio frequency unit 1001, network module 1002, audio output unit 1003, input unit 1004, sensor 1005, display unit 1006, user input unit 1007, interface unit 1008, memory 1009, and processor 1010.
[0132] Those skilled in the art will understand that the electronic device 1000 may also include a power supply (such as a battery) for supplying power to various components. The power supply may be logically connected to the processor 1010 through a power management system, thereby enabling functions such as managing charging, discharging, and power consumption through the power management system. Figure 7 The electronic device structure shown does not constitute a limitation on the electronic device. The electronic device may include more or fewer components than shown, or combine certain components, or have different component arrangements, which will not be elaborated here.
[0133] The processor 1010 is configured to acquire parameter information of the first task when the first task acquires the key lock; and to run the first task when the parameter information meets preset conditions, wherein the preset conditions include target identification information.
[0134] According to the embodiments of this application, by setting a key lock, it can be ensured that only one task acquires the key lock at a time. This allows multiple tasks to run concurrently, prioritizing their execution based on the time they acquire the key lock, thus avoiding system congestion. By acquiring the parameter information of the first task when it acquires the key lock, and then running the first task only if the parameter information meets preset conditions, the first task with target identifier information can be run first, thereby shortening its waiting time and avoiding the system lag caused by priority inversion in related technologies.
[0135] Optionally, if the parameter information includes target identification information, the parameter information satisfying the preset condition further includes: the identification duration of the target identification information is less than or equal to a preset duration.
[0136] According to the embodiments of this application, when the parameter information includes target identification information, the parameter information also satisfies the preset condition that the identification duration of the target identification information is less than or equal to the preset duration, which can avoid the operation of other tasks being affected by the long-term operation of special tasks, thereby affecting the system's operating speed and reducing the user experience.
[0137] Optionally, the processor 1010 is further configured to run the second task if the parameter information does not meet the preset conditions and there is a second task with a higher priority than the first task; wherein the parameter information not meeting the preset conditions includes one of the following: the parameter information does not include the target identification information, or the parameter information includes the target identification information but the identification duration of the target identification information is greater than the preset duration; the first task is run after the second task exits.
[0138] According to the embodiments of this application, if the parameter information of the first task does not meet the set conditions and there is a second task with a higher priority than the first task, the second task is run. After the second task exits, the first task is run, which can avoid the problem of system lag caused by multi-task running conflicts.
[0139] Optionally, the processor 1010 is configured to clear the parameter information of the first task after the first task releases the key lock.
[0140] According to the embodiments of this application, after the first task releases the key lock, the parameter information of the first task is cleared, thereby preventing the target identification information from affecting the normal operation of other tasks after the task with target identification information has been run.
[0141] Optionally, the processor 1010 is configured to acquire parameter information of the first task when the first task acquires the key lock and the first task occupies system resources; or, when the first task acquires the key lock and the third task occupies the system resources, wait for the first task to be woken up, and acquire parameter information of the first task when the first task is woken up; wherein the first task is woken up when the third task releases the system resources.
[0142] According to the embodiments of this application, by setting conditions to trigger the acquisition of parameter information of the first task, the system running speed can be improved and the system power consumption reduced. Furthermore, if the first task is blocked, other tasks are run first, and the first task is woken up and its parameter information is acquired when the third task releases the system resources. This also avoids the problem of other low-priority tasks being unable to run due to high-priority tasks being blocked, thus improving the system running speed.
[0143] Optionally, the processor 1010 is configured to, when a set event occurs and the parameter information of the first task includes the target identification information, obtain the identification duration of the target identification information; and when the identification duration of the target identification information is greater than the preset duration, clear the target identification information from the parameter information of the first task.
[0144] According to the embodiments of this application, by obtaining the identification duration of the target identification information when a set event occurs and the parameter information of the first task includes the target identification information, and by clearing the target identification information from the parameter information of the first task when the identification duration of the target identification information is greater than the preset duration, the problem of other tasks being unable to run due to abnormal task operation can be avoided, thereby improving the system operation speed.
[0145] It should be understood that, in this embodiment, the input unit 1004 may include a graphics processing unit (GPU) 10041 and a microphone 10042. The GPU 10041 processes image data of still images or videos obtained by an image capture device (such as a camera) in video capture mode or image capture mode. The display unit 1006 may include a display panel 10061, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like. The user input unit 1007 includes a touch panel 10071 and at least one of other input devices 10072. The touch panel 10071 is also called a touch screen. The touch panel 10071 may include a touch detection device and a touch controller. Other input devices 10072 may include, but are not limited to, physical keyboards, function keys (such as volume control buttons, power buttons, etc.), trackballs, mice, and joysticks, which will not be described in detail here.
[0146] The memory 1009 can be used to store software programs and various data. The memory 1009 may primarily include a first storage area for storing programs or instructions and a second storage area for storing data. The first storage area may store the operating system, application programs or instructions required for at least one function (such as sound playback, image playback, etc.). Furthermore, the memory 1009 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct memory bus RAM (DRRAM). The memory 1009 in this embodiment includes, but is not limited to, these and any other suitable types of memory.
[0147] The processor 1010 may include one or more processing units; optionally, the processor 1010 integrates an application processor and a modem processor, wherein the application processor mainly handles operations involving the operating system, user interface, and applications, and the modem processor mainly handles wireless communication signals, such as a baseband processor. It is understood that the aforementioned modem processor may also not be integrated into the processor 1010.
[0148] This application also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described task scheduling method embodiments and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0149] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0150] This application embodiment also provides a chip, which includes a processor and a communication interface. The communication interface is coupled to the processor. The processor is used to run programs or instructions to implement the various processes of the above-described task scheduling method embodiments and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0151] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.
[0152] This application provides a computer program product, which is stored in a storage medium and executed by at least one processor to implement the various processes of the task scheduling method embodiment described above, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0153] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0154] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0155] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.
Claims
1. A task scheduling method, characterized in that, The method includes: If the first task acquires the key lock, the parameter information of the first task is obtained; wherein, the key lock is set at the entry point of the data call to ensure that only one task reads system resources at a time. When the parameter information meets the preset conditions, the first task is run and the execution of other high-priority tasks is prohibited to avoid priority reversal. The priority of the first task is lower than the priority of the other high-priority tasks. The parameter information meeting the preset conditions includes target identification information.
2. The method according to claim 1, characterized in that, When the parameter information includes target identification information, the parameter information also satisfies the preset condition that the identification duration of the target identification information is less than or equal to the preset duration.
3. The method according to claim 2, characterized in that, After obtaining the parameter information of the first task, the method further includes: If the parameter information does not meet the preset conditions and there is a second task with a higher priority than the first task, the second task is run; wherein, the parameter information not meeting the preset conditions includes one of the following: the parameter information does not include the target identification information, or the parameter information includes the target identification information but the identification duration of the target identification information is greater than the preset duration; After the second task exits, the first task is run.
4. The method according to any one of claims 1 to 3, characterized in that, After running the first task, the method further includes: After the first task releases the key lock, the parameter information of the first task is cleared.
5. The method according to any one of claims 1 to 3, characterized in that, When the first task acquires the key lock, the parameter information of the first task is obtained, including: If the first task acquires the key lock and the first task occupies system resources, obtain the parameter information of the first task; Alternatively, if the first task acquires the key lock and the third task occupies the system resources, wait for the first task to be woken up, and if the first task is woken up, obtain the parameter information of the first task; wherein the first task is woken up when the third task releases the system resources.
6. The method according to claim 1, characterized in that, After obtaining the parameter information of the first task, the method further includes: When a set event occurs, and the target identification information is included in the parameter information of the first task, the identification duration of the target identification information is obtained; If the identification duration of the target identification information exceeds a preset duration, the target identification information in the parameter information of the first task is cleared.
7. A task scheduling device, characterized in that, The device includes: The acquisition module is used to acquire parameter information of the first task when the first task acquires the key lock; wherein the key lock is set at the entry point of the call data to ensure that only one task reads system resources at a time. The control module is configured to run the first task and prohibit the execution of other high-priority tasks when the parameter information meets preset conditions, so as to avoid priority reversal. The priority of the first task is lower than the priority of the other high-priority tasks. The parameter information meeting the preset conditions includes target identification information.
8. The apparatus according to claim 7, characterized in that, When the parameter information includes target identification information, the parameter information also satisfies the preset condition that the identification duration of the target identification information is less than or equal to the preset duration.
9. The apparatus according to claim 8, characterized in that, The control module is further configured to run the second task when the parameter information does not meet the preset conditions and there is a second task with a higher priority than the first task; wherein, the parameter information not meeting the preset conditions includes one of the following: the parameter information does not include the target identification information, or the parameter information includes the target identification information but the identification duration of the target identification information is greater than the preset duration; After the second task exits, the first task is run.
10. The apparatus according to any one of claims 7 to 9, characterized in that, The device further includes: a cleaning module, The clearing module is used to clear the parameter information of the first task after the first task releases the key lock.
11. The apparatus according to any one of claims 7 to 9, characterized in that, The acquisition module is specifically used to acquire parameter information of the first task when the first task acquires the key lock and the first task occupies system resources; Alternatively, the acquisition module is specifically used to wait for the first task to be woken up when the first task acquires the key lock and the third task occupies the system resources, and to acquire the parameter information of the first task when the first task is woken up; wherein the first task is woken up when the third task releases the system resources.
12. The apparatus according to claim 7, characterized in that, The acquisition module is used to acquire the identification duration of the target identification information when a set event occurs and the parameter information of the first task includes the target identification information; The clearing module is used to clear the target identification information from the parameter information of the first task when the identification duration of the target identification information is longer than a preset duration.
13. An electronic device, characterized in that, It includes a processor and a memory, the memory storing a program or instructions that can run on the processor, the program or instructions being executed by the processor to implement the steps of the task scheduling method as described in any one of claims 1-6.
Citation Information
Patent Citations
Multi-GPU (Graphics Processing Unit) task real-time scheduling method and device
CN113051059A
Asynchronous task execution method
CN114090207A
Edge computing task processing method, edge server and storage medium
CN115061800A