Electronic device, task scheduling method therefor, and medium
By converting the execution relationships between tasks in a nested task scenario, the execution delay problem caused by parent tasks waiting for child tasks is solved, and the resource utilization and processing efficiency of the operating system are improved.
Patent Information
- Application Number
- PCT/CN2023/140350
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-02-28
- Filing Date
- 2023-12-20
- Publication Date
- 2024-09-06
AI Technical Summary
In a nested task scenario, the parent task needs to wait for the execution of the subtask to complete, resulting in a delay in the execution time of subsequent tasks and affecting the resource utilization of the operating system.
By detecting the data dependency between the parent task and the child task, the execution association between the parent task and the child task is converted into the execution association between the child task and the subsequent task, so that the parent task can exit directly after the writing is completed. , to avoid subsequent tasks waiting for subtasks to complete.
It is possible to start other tasks in time after the execution of the parent task is completed, avoiding the execution time delay of subsequent tasks and improving the processing efficiency of the operating system.
Smart Images

Figure CN2023140350_06092024_PF_FP
Abstract
Description
Electronic device and task scheduling method and medium thereof
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on February 28, 2023, with application number 202310232901.2 and application name “Electronic device and its task scheduling method and medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the technical field of operating systems, and more particularly to an electronic device and a task scheduling method and medium thereof. Background Art
[0003] Task parallelism describes the number of tasks that can be executed in parallel by an operating system (also known as a terminal system). The operating system establishes dependencies between tasks submitted or generated by applications (users). These dependencies can take the form of indirect dependencies (data dependencies) based on the task's data and direct dependencies (task dependencies) based on the task's execution. Once these dependencies are established, the operating system can access these dependencies during runtime, make scheduling decisions, achieve parallel execution, and optimize operating system resource utilization.
[0004] Figures 1a and 1b illustrate how an operating system schedules task execution using task dependency and data dependency, respectively. As shown in Figure 1a, when the dependency is task dependency, the execution of Task 2 depends on the execution of Task 1. As shown in Figure 1b, when the dependency is data dependency, Data 1 is written during the execution of Task 1 and read during the execution of Task 2. Therefore, the execution data of Task 2 depends on the execution of Task 1.
[0005] However, for nested task scenarios, that is, when a new task is generated during the execution of a task, the new task can be called a subtask, and the original task is called a parent task. If there is a data dependency between the parent task and the subtask on the first data, the parent task needs to synchronize the results of the subtask (that is, the parent task needs to wait for the subtask to be completed before it can be completed, so that the subsequent task that has a data dependency with the parent task on the second data can start to execute), which will cause delays in the execution of the subsequent tasks and affect the parallelism of multiple tasks.
[0006] Summary of the Invention
[0007] The present application provides an electronic device and a task scheduling method and medium thereof.
[0008] In a first aspect, an embodiment of the present application provides a task scheduling method, applied to a processor of an electronic device, the method comprising:
[0009] Executing a first task, the first task including performing a write operation on first data, the first data including first sub-data and second sub-data; generating a second task during the execution of the first task, wherein the second task includes performing a write operation on the first sub-data; confirming that a third task includes performing a read operation on the first sub-data, and an execution association relationship has been established between the third task and the first task; during the period when the first task is completed and the second task is executed, converting the execution association relationship between the third task and the first task into an execution association relationship between the third task and the second task; and executing a fourth task after the first task is completed, wherein the fourth task performs a read operation on the second sub-data.
[0010] In an embodiment of the present application, the electronic device here may be a terminal device installed with an operating system, and the processor may be an application processor, a modem processor, a graphics processor, an image signal processor, etc. of the terminal device. The first task, the second task, the third task, and the fourth task here may be tasks that an application can submit to the processor through the operating system of the electronic device, and are a series of instructions for reading or writing data stored in the memory of the electronic device. During the execution of the first task, the second task is generated. The first task can be called the parent task of the second task, and the second task is called the child task of the first task. The first task and the second task are in a nested task relationship. During the process of the first task writing the first sub-data and the second sub-data, the second task is generated. The subsequent task of the first task, that is, the third task only reads the first sub-data, the fourth task (another subsequent task of the first task) only reads the second sub-data, and the second task reads the first sub-data. When the first task is completed before the second task, the execution association relationship of the third task to the first task (the data dependency relationship on the first sub-data) can be converted between the third task and the second task, and the first task can exit directly after completion. Since there is no execution association relationship between the fourth task and the second task (ie, there is no data dependency relationship on the second sub-data), the fourth task can be executed promptly following the completion of the first task.
[0011] It can be seen that after implementing the task scheduling method provided in the embodiment of the present application, among other tasks that have a dependency relationship with the parent task, tasks that have no data dependency relationship with the child task can start execution in time after the parent task is completed, avoiding the problem that subsequent tasks need to wait for the child task to be completed, causing delays in the execution time of subsequent tasks.
[0012] In a possible implementation of the first aspect, the method further includes:
[0013] After the second task is completed, the third task is executed.
[0014] In the embodiment of the present application, there is an execution association relationship (data dependency relationship) between the third task and the second task regarding the second sub-data, and the third task can only start execution after the second task is completed.
[0015] In a possible implementation of the first aspect, confirming that the third task includes performing a read operation on the first sub-data and an execution association relationship has been established between the third task and the first task includes:
[0016] A first task list corresponding to the first sub-data is obtained, and based on the first task list, it is confirmed that an execution association relationship has been established between the third task and the first task.
[0017] In an embodiment of the present application, the first task list here can be a data version linked list, that is, the first sub-data can generate multiple data versions, and all data versions corresponding to the first sub-data can be managed in a linked list manner. The execution association relationship here can include a write relationship and a read relationship. The write relationship can be that the first task needs to perform a write operation such as update or delete on the first sub-data, and the read relationship can be that the third task needs to perform a read operation on the first sub-data after the first task has performed the write operation. The third task needs to rely on the execution result of the first task.
[0018] In a possible implementation of the first aspect, converting the execution association relationship between the third task and the first task into an execution association relationship between the third task and the second task includes:
[0019] In the first task list, the reading relationship of the third task reading the first sub-data through the first task is modified to the third task reading the first sub-data through the second task.
[0020] In an embodiment of the present application, since the second task also needs to perform update, deletion and other write operations on the first sub-data, the third task needs to rely on the execution result of the second task, and the data dependency of the third task on the first task is converted to the data dependency of the third task on the second task.
[0021] In a possible implementation of the first aspect, the first task list includes multiple versions of sub-data corresponding to the first sub-data;
[0022] In the first task list, the reading relationship between the third task and the first sub-data through the first task includes a reading relationship between the third task and the first version sub-data among multiple versions of the first sub-data, and a writing relationship between the first task and the first version sub-data.
[0023] In an embodiment of the present application, the version sub-data herein may be multiple data versions of the first sub-data, where the first version sub-data corresponds to the first sub-data that the first task needs to perform a write operation on. The third task needs to perform a read operation on the first sub-data corresponding to the first version sub-data after the first task has performed the write operation on it.
[0024] In a possible implementation of the first aspect, the reading relationship of the third task reading the first sub-data through the first task is modified to the third task reading the first sub-data through the second task, including:
[0025] In the first task list, the read relationship between the third task and the first version sub-data is modified to a read relationship between the third task and the second version sub-data, wherein the second task and the second version sub-data have a write relationship.
[0026] In the embodiment of the present application, the write relationship here can be that the second task also needs to perform a write operation such as update or delete on the first sub-data, and a second version sub-data is added to the first sub-data that the second task needs to perform a write operation on.
[0027] In a possible implementation of the first aspect above, a first task list corresponding to the first sub-data is obtained, and based on the first task list, it is confirmed that an execution association relationship has been established between the third task and the first task, including: the first version sub-data is located at the end of the first task list; the first task includes a first write data list, and the first write data list includes the first version sub-data, wherein the first version sub-data includes a first data status, and the first data status indicates that the first task has not yet completed the write operation on the first sub-data; the third task includes a third read data list, and the third read data list includes the first version sub-data; the first version sub-data includes the first read task list, and the first read task list includes the third task.
[0028] In an embodiment of the present application, a first task list of the first sub-data, that is, a data version list, is obtained, wherein the first task list is stored in a linked list;
[0029] Generate a first version sub-data of the first sub-data corresponding to the first task, and insert the first version sub-data at the end of the first task list, wherein the first version sub-data includes a write task list and a read task list, the read task list (i.e., the consumer task list) is used to record tasks that perform read operations on the first sub-data of the first version sub-data, and the write task list (i.e., the next producer task) is used to record tasks that perform write operations on the first sub-data of the first version sub-data; add the first data version to the write data version list of the first task, i.e., the output data version list.
[0030] In a possible implementation of the first aspect, the second task and the second version sub-data have a write relationship, including: when the first task and the second task are in a nested task relationship, in the first task list, the second version sub-data is located before the first version sub-data;
[0031] The second task includes a second write data list, and the second write data list includes second version sub-data, wherein the second version sub-data includes the first data state.
[0032] In an embodiment of the present application, a first task list of the first sub-data is obtained; when the first task and the second task are in a nested task relationship, the first version sub-data of the first sub-data corresponding to the first task is obtained according to the write data version list of the first task; the second version sub-data of the first sub-data corresponding to the second task is generated, and the second version sub-data is inserted before the first version sub-data in the first task list, wherein the second version sub-data also includes a write task list and a read task list; the second version sub-data is added to the write data version list of the second task, that is, the output data version list.
[0033] In a possible implementation of the first aspect above, in the first task list, the reading relationship between the third task and the first version sub-data is modified to a reading relationship between the third task and the second version sub-data, including: the second version sub-data includes the second reading task list, and the second reading task list includes the third task; the third reading data list of the third task includes the second version sub-data; the first version sub-data includes the second data state, and the second data state indicates that the first task has completed the write operation on the first sub-data.
[0034] In an embodiment of the present application, based on the write data version list of the first task, the first version sub-data of the first sub-data corresponding to the first task is obtained, wherein the first version sub-data includes a first data state; the second version sub-data that precedes the first version sub-data in the first task list is obtained; a third task is added to the read task list of the second version sub-data; the third task in the read task list of the first version sub-data is obtained, and the first version sub-data in the read data version list of the third task is replaced with the second version sub-data. The first version sub-data is updated from the first data state to the second data state, wherein the second data state indicates that the first task has completed the write operation on the first sub-data.
[0035] In a possible implementation of the first aspect, after the second task is completed, a third task is performed, including: the second version sub-data includes a second data state.
[0036] In an embodiment of the present application, the second version sub-data is updated from a first data state to a second data state, wherein the second data state indicates that the second task completes the write operation on the first sub-data.
[0037] In a possible implementation of the first aspect, the method further includes:
[0038] A second task list corresponding to the second sub-data is obtained, and based on the second task list, it is confirmed that an execution association relationship has been established between the fourth task and the first task.
[0039] In an embodiment of the present application, the second task list can be a linked list of data versions. That is, the second sub-data can generate multiple data versions, and all data versions corresponding to the second sub-data can be managed in a linked list manner. The execution association relationship here can include a write relationship and a read relationship. The write relationship can be that the first task needs to perform a write operation such as update or delete on the second sub-data. The read relationship can be that the fourth task needs to perform a read operation on the second sub-data after the first task has performed the write operation. The fourth task needs to rely on the execution result of the first task.
[0040] In a possible implementation of the first aspect above, the second task list is in the form of a linked list;
[0041] The second task list includes a plurality of version sub-data corresponding to the second sub-data, and
[0042] In the second task list, there is an execution association relationship between the fourth task and the first task, and the following relationship exists:
[0043] The fourth task has a reading relationship with the third version of the second sub-data among the multiple versions of the second sub-data, and the first task has a writing relationship with the third version of the second sub-data.
[0044] In an embodiment of the present application, the version sub-data herein may be multiple data versions of the second sub-data, wherein the third version sub-data herein corresponds to the second sub-data to which the first task needs to perform a write operation. The fourth task needs to perform a read operation on the second sub-data corresponding to the third version sub-data to which the first task has completed the write operation.
[0045] In a possible implementation of the first aspect, the method further includes:
[0046] After the first task is completed, the writing relationship between the first task and the third version sub-data in the second task list is terminated.
[0047] In an embodiment of the present application, after the first task writes the second sub-data, the fourth task may read the second sub-data.
[0048] In a possible implementation of the first aspect above, in the second task list, the reading relationship in which the fourth task reads the second sub-data through the first task includes: the third version sub-data is located at the end of the second task list; the first task includes a first write data list, and the first write data list includes the third version sub-data, wherein the third version sub-data includes the first data state; the fourth task includes a fourth read data list, and the fourth read data list includes the third version sub-data; the third version sub-data includes a third read task list, and the third read task list includes the fourth task.
[0049] In an embodiment of the present application, a second task list of the second sub-data is obtained, and the third version sub-data of the second sub-data corresponding to the first task of the second task list is determined, wherein the third version sub-data is located at the end of the second sub-data version list; if the third version sub-data includes the first data state, the third version sub-data is added to the read data version list of the fourth task and the fourth task is added to the read task list of the third version sub-data.
[0050] In a possible implementation of the first aspect above, the third version sub-data further includes the second data state.
[0051] In an embodiment of the present application, after the first task writes the second sub-data, the third version sub-data of the second sub-data corresponding to the first task is obtained, and the third version sub-data is updated from the first data state to the second data state.
[0052] In a second aspect, an embodiment of the present application provides a readable medium having instructions stored thereon, which, when executed on an electronic device, causes the electronic device to execute the task scheduling method of the first aspect.
[0053] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0054] a memory for storing instructions to be executed by one or more processors of the electronic device, and
[0055] The processor is one of the processors of the electronic device and is used to execute the task scheduling method of the first aspect.
[0056] In a fourth aspect, an embodiment of the present application provides a computer program product, comprising: a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium contains a computer program code for executing the task scheduling method of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] FIG1a and FIG1b are schematic diagrams of an operating system according to an embodiment of the present application that schedules task execution based on task dependency and data dependency;
[0058] 2a to 2d are schematic diagrams of an operating system scheduling task execution based on data dependencies in a nested task scenario provided by an embodiment of the present application;
[0059] 3a to 3c are schematic diagrams illustrating, by way of example, how an operating system schedules task execution based on data dependencies between subsequent tasks and parent tasks in a nested task scenario;
[0060] FIG4a is a software structure block diagram of an operating system provided in an embodiment of the present application;
[0061] FIG4 b is a software module architecture of a task scheduling module in a software structure diagram of an operating system provided by an embodiment of the present application;
[0062] FIG4c is a flowchart of a task scheduling method provided in an embodiment of the present application;
[0063] 5a and 5b are schematic diagrams of data dependency relationships between tasks acting as producers or consumers provided in an embodiment of the present application;
[0064] FIG6 is a schematic diagram of data versions corresponding to data dependencies between tasks as producers or consumers provided in an embodiment of the present application;
[0065] 7a to 7c are schematic diagrams of a process for establishing data dependencies between tasks in a task submission process according to an embodiment of the present application;
[0066] 8a to 8d are schematic diagrams of scenarios in which data dependencies are established between tasks in the task submission processing flow provided in an embodiment of the present application;
[0067] 9a to 9c are schematic diagrams of a process for removing data dependencies between tasks in a task completion process according to an embodiment of the present application;
[0068] 10a to 10d are schematic diagrams of scenarios in which data dependencies between tasks are released in a task completion process according to an embodiment of the present application;
[0069] 11 and 12 are schematic diagrams of a process for establishing and removing data dependencies between tasks in a task submission process and a task completion process in a nested task scenario provided by an embodiment of the present application;
[0070] 13a to 13d are schematic diagrams of a scenario in which an operating system establishes data dependencies between tasks based on input data and output data corresponding to the tasks in a task submission process according to an embodiment of the present application;
[0071] 14a to 14d are schematic diagrams of a scenario in which an operating system removes data dependencies between tasks based on input data and output data corresponding to the tasks in a task completion process according to an embodiment of the present application;
[0072] 15 and 16 are flow charts illustrating how to establish and remove data dependencies between tasks in the task submission process and task completion process in a nested task scenario, according to an embodiment of the present application;
[0073] 17a to 17d are schematic diagrams of a scenario in which an operating system establishes data dependencies between tasks based on input data and output data corresponding to the tasks in a task submission process according to an embodiment of the present application;
[0074] 18a to 18d are schematic diagrams of a scenario in which an operating system removes data dependencies between tasks based on input data and output data corresponding to the tasks in a task completion process according to an embodiment of the present application;
[0075] FIG19 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0076] The technical solutions in the embodiments of the present application will be described clearly and in detail below with reference to the accompanying drawings.
[0077] 2a to 2d , which exemplarily illustrate schematic diagrams of an operating system scheduling task execution based on data dependencies in a nested task scenario provided by an embodiment of the present application.
[0078] As shown in Figure 2a, Task 1 can be a series of instructions generated by an application installed on the electronic device 100 to read or write data stored in the memory of the electronic device 100. The application can submit tasks to the processor through the operating system of the electronic device 100, and the processor can execute the instructions corresponding to the task. During the execution of Task 1, Task 1.1 is generated. Task 1 can be called the parent task of Task 1.1, and Task 1.1 is called the child task of Task 1. There is a nested task relationship between Task 1 and Task 1.1, and the child task can be executed in parallel with the parent task. In the process of writing functions run by the operating system, nested task relationships often appear. For example, if a recursive function is encapsulated into a task, it will generate nested tasks, i.e., subtasks, during its execution; for another example, if a complex function is encapsulated into a task, the code segments inside the function can be encapsulated into multiple subtasks.
[0079] In a nested task scenario, since subtasks and parent tasks may be executed in parallel, the parent task may need to synchronize the results of the subtasks.
[0080] The following briefly introduces several different types of nested tasks.
[0081] Figure 2b illustrates a nested task type where the parent task does not synchronize its child tasks. In Figure 2b, Task 1's corresponding child task is Task 1.1. After Task 1 completes writing Data 1, Task 1.1 is generated. Task 1.1 does not write to Data 1, but only writes to Data 2. Task 2 (the subsequent task) only reads Data 1. That is, after Task 1 completes, Task 2 can read the correct Data 1, even if Task 1.1 has not yet completed. Therefore, Task 1.1 does not affect the execution of Task 2.
[0082] Figures 2c and 2d each illustrate a type of nested task where a parent task needs to synchronize with a child task. In Figure 2c, Task 1 generates Task 1.1 during execution. Task 1.1 needs to write to Data 1. Since Task 1 needs to write to Data 1 after generating Task 1.1, Task 1 must synchronize with Task 1.1 before continuing. In other words, Task 1 needs to synchronize with the results of Task 1.1. If Task 1 completes writing to Data 1 before Task 1.1 has completed, Task 2 (Task 1's successor) will read Data 1 while Task 1.1 is writing, resulting in an incorrect output. Similarly, as shown in Figure 2d, Task 1 generates Task 1.1 after Task 1 completes writing to Data 1. Since Task 1 also needs to write to Data 1, if Task 1 completes, Task 2 (Task 1's successor) will also read Data 1 while Task 1.1 is writing, resulting in an incorrect output.
[0083] It can be seen that the scenarios shown in Figures 2a to 2d only describe that the parent task (task 1) has one subsequent task (task 2). Referring to Figures 3a to 3b below, Figures 3a to 3b exemplarily show that in a nested task scenario, a parent task has multiple subsequent tasks, and the operating system schedules task execution through the data dependency relationship between the subsequent tasks and the parent task.
[0084] As shown in Figure 3a, after Task 1 completes writing Data 2, Task 1.1 is generated. Task 1 needs to write Data 1. Task 2 (the subsequent task) only reads Data 1, and Task 3 (the subsequent task) only reads Data 2. To ensure that Task 2 can read Data 1, which will be written to Task 1.1, Task 1 must synchronize with Task 1.1.
[0085] Figure 3b shows a schematic diagram of an operating system executing Tasks 1 through 3 in parallel. As shown in Figure 3b, Task 1 requires synchronization with Task 1.1. That is, Task 1 cannot exit until Task 1.1 completes. After Task 1 completes, Tasks 2 and 3 execute in parallel. It can be seen that Task 3 only reads Data 2. That is, Task 3 depends on Data 2 but not Data 1. In contrast, in the scenario shown in Figure 3a, because Task 1 requires synchronization with Task 1.1, Task 3 must wait for Task 1.1 to complete before it can begin execution. This delays the execution of Task 3.
[0086] That is to say, when the parent task writes multiple data, if the child task only writes part of the multiple data, and some subsequent tasks of the parent task only need to read the data that the child task has not written, this will cause these subsequent tasks to also wait for the subtask to be completed, resulting in a delay in the execution time of the subsequent tasks.
[0087] In order to solve the problem of delayed execution time of subsequent tasks corresponding to a parent task in a nested task scenario, an embodiment of the present application proposes a task scheduling method. In a nested task scenario, if there is a data dependency between a parent task and a child task, that is, the child task has written data that is the same as part of the data written by the parent task (for example, the first data), it is possible to detect other subsequent tasks that have a dependency on the parent task and have a data dependency on the first data, for example, called the first subsequent task, and convert the data dependency between the parent task and the first subsequent task into a data dependency between the child task and the first subsequent task, so that the parent task can exit directly after the writing is completed, so that the tasks that have no data dependency on the first data among other tasks that have a dependency on the parent task can start execution in time after the parent task is completed, thereby avoiding the problem of delayed execution time of the above-mentioned subsequent tasks.
[0088] For example, for the nested tasks in Figure 3a, when Task 1 is completed before Task 1.1, the data dependency of Task 2 on Task 1 can be converted to the data dependency of Task 2 on Task 1.1, and Task 1 can exit directly after completion. As shown in Figure 3c, if Task 1 is completed before Task 1.1 in time, the data dependency between Task 1 and Task 2 on Data 1 is converted to the data dependency between Task 1.1 and Task 2, then Task 1 can exit directly and Task 3 can be executed in a timely manner. Compared to the example in Figure 3b, where Task 3 needs to wait for the completion of synchronization Task 1.1 before execution, this can effectively reduce the waiting time of Task 3 and improve the efficiency of the operating system in processing tasks.
[0089] The following describes the architecture of the operating system of the electronic device that executes the task scheduling method according to the embodiment of the present application. FIG4 a is a software structure block diagram of the operating system 200 according to the embodiment of the present invention.
[0090] The layered architecture of operating system 200 divides the operating system into several layers, each with distinct roles and responsibilities. Layers communicate with each other via software interfaces. In some embodiments, the layered architecture of the operating system can be divided into four layers: from top to bottom, the application layer, the application framework layer, the runtime and system libraries layer, and the kernel layer.
[0091] As shown in Figure 4a, the application layer may include applications such as life, video, reading, shopping, gallery, calendar, call, navigation, and music.
[0092] The application framework layer may include a layout subsystem, a window management module, and so on. The layout subsystem is used to determine the position of various display elements on the terminal device's screen. The event input module is used to respond to user operations on the terminal device and change the displayed content on the terminal device's screen.
[0093] The system library can include a task scheduling module, a layout module, and a view module. The task scheduling module is used to schedule task execution based on the data dependencies between tasks. The layout module and the view module can be used to manage the operating mode of the user interface in the window.
[0094] The kernel layer includes display driver, event driver, sensor driver, etc.
[0095] Reference is now made to FIG4 b , which exemplarily illustrates the software module architecture of the task scheduling module in the software structure diagram of the operating system 200 in the embodiment of the present application described in FIG4 a .
[0096] As shown in FIG4 b , the task scheduling module may be a task scheduling architecture 400 , including: a resource management module 401 , an interface module 402 , a dependency management module 403 , a task scheduling module 404 , a task execution module 405 and an execution module 406 .
[0097] The resource management module 401 may include a task resource management unit 401 - 1 and a data version resource management unit 401 - 2 , which are used for application, recovery and destruction management of resources corresponding to tasks and data versions.
[0098] The interface module 402 provides an interface for the application (user) and supports the application to submit various tasks through the interface.
[0099] Dependency management module 403 is used to receive tasks submitted by upper-level applications, apply for resources corresponding to the tasks, analyze the data dependencies of the tasks based on the data read and / or written by the tasks, and apply for resources corresponding to the data versions to establish the corresponding data dependencies. Dependency management module 403 is also used to submit the task to task scheduling module 404 when all data dependencies of a task have been resolved. After a task is completed, the data dependencies with subsequent tasks are updated / removed based on the status of the data version corresponding to the task.
[0100] The task scheduling module 404 allocates the TASK_READY (data dependency released, task executable) task to the task execution module 405 according to the scheduling policy.
[0101] The task execution module 405 is used to assign the task to the designated or default execution module 406 and return the task to the dependency management module 403 after the task is completed.
[0102] The execution module 406 includes but is not limited to a multi-core processing unit such as a CPU and a GPU, and supports concurrent execution of multiple tasks.
[0103] In some embodiments, the dependency management module 403 shown in Figure 4b can be used to execute the task scheduling method of the embodiment of the present application. As shown in Figure 4c, the task scheduling method may include.
[0104] S401: Get the submitted parent task.
[0105] Exemplarily, the dependency management module 403 may obtain the parent task submitted by the application through the interface module 402. For example, the parent task here may be task 1 in FIG. 3a.
[0106] S402: It is detected that there is a data dependency relationship between the parent task and the child task.
[0107] For example, the subtask here may be task 1.1, and the dependency management module 403 may detect that both the parent task and the subtask write to data 1.
[0108] S403: Detecting a first subsequent task that has a data dependency relationship with the first data among other subsequent tasks that have a data dependency relationship with the parent task.
[0109] For example, the first successor task of the parent task here may be Task 2, that is, the successor task to be executed before the parent task is completed. Dependency management module 403 can obtain Task 2 submitted by the application through interface module 402, determine that Task 2 writes to Data 1, and establish a data dependency relationship between Task 1 and Task 2 for Data 1 before Task 1 generates Task 1.1.
[0110] S404: Convert the data dependency relationship between the parent task and the first subsequent task into a data dependency relationship between the child task and the first subsequent task.
[0111] For example, after detecting that task 1 has submitted task 1.1, the dependency management module 403 can convert the data dependency relationship between task 1 and task 2 on data 1 into a data dependency relationship between task 1.1 and task 2 on data 1. That is, task 2 needs to wait until task 1.1 completes writing data 1 before starting execution.
[0112] S405: Control the parent task to complete execution, and execute a second subsequent task that has no data dependency relationship with the first data.
[0113] For example, the second subsequent task here can be task 3. The dependency management module 403 determines that there is a data dependency relationship between task 1 and task 3 on data 2. After task 1 completes writing data 2, task 3 can start execution without waiting for task 1.1 to be completed.
[0114] Before describing in detail the task scheduling method provided in the embodiment of the present application, the following first provides a detailed explanation of tasks, data, and data dependencies between tasks.
[0115] In some embodiments, when the task is a task of writing data (eg, may include adding, modifying, and deleting), the task may be called a producer task; when the task is a task of reading data, the task may be called a consumer task.
[0116] In some embodiments, the operating system may establish / release data dependencies by defining data structures for tasks and data.
[0117] Taking the data structure of a task as an example, a task can also be called a task object. The data structure of a task can include the following storage information:
[0118] The function executed by the task is often a code block encapsulated by the application that generates the task or a function submitted by the application.
[0119] Task execution status: TASK_PENDING (data dependency not released), TASK_READY (data dependency released, task executable), TASK_EXECUTING (task executing), TASK_DONE (task execution completed).
[0120] Input data version list: The input data version here can represent the data version corresponding to the data read by the task. After the task is executed, if the task is the last consumer of the input data version (there may be multiple consumer tasks for the data version), the status of the input data version is updated to VERSION_CONSUMED.
[0121] Output data version list: The output data version here can represent the data version corresponding to the data written by the task. After the task is completed, the status of the output data version is updated to VERSION_PRODUCED.
[0122] Dependency Quantity: This includes the sum of the "producer-consumer" data dependency, "producer-next producer" data dependency, and "consumer-next producer" data dependency corresponding to the task, and can be uniformly expressed by the number of data dependencies.
[0123] In terms of the data structure, data can be called a data object. One piece of data can generate multiple data versions. All data versions corresponding to the data can be managed in a linked list, that is, a data version linked list. Data versions have a sequential relationship. The data structure of the data can include the following storage information:
[0124] The data object expressed: the address of the data object or the specified memory address.
[0125] Data version status: Each data version in the data version list can include three states: VERSION_PENDING (dependency not released), VERSION_PRODUCED (producer task execution completed), VERSION_CONSUMED (all consumer tasks are completed).
[0126] Consumer task list: Each data version in the data version list can include zero, one, or more tasks as consumers. After the data version status is updated to VERSION_PRODUCED, the "producer-consumer" dependency between the producer task and the consumer task corresponding to the data version can be released.
[0127] Next producer task: Each data version in the data version list can include zero or one producer tasks, which represent the producer of the next data version rather than the producer of the current data version. After a data version's status is updated to VERSION_PRODUCED, the "producer-next producer" dependency between the producer of that data version and the producer of the next data version is resolved. After a data version's status is updated to VERSION_CONSUMED, the "consumer-next producer" dependency between all consumers of that data version and the producer of the next data version is resolved.
[0128] Previous data version: The previous node in the data version list, which may be empty, is the data version generated by the previous producer.
[0129] Next data version: The next node in the data version linked list, which may be empty, is the data version generated by the next producer.
[0130] After introducing the tasks and data used to establish / eliminate data dependencies, you can refer to Figures 5a to 5b below. Figures 5a to 5b exemplarily show the data dependencies between tasks acting as producers or consumers in an embodiment of the present application.
[0131] As shown in Figure 5a, 001, 002, and 003 represent the order in which the operating system's application submits Task 1, Task 2, and Task 3, rather than the order in which Task 1, Task 2, and Task 3 are executed. In 001, Task 1 writes to Data 1, making it the producer of Data 1. In 002, Task 2 reads from Data 1, making it the consumer of Data 1. Tasks 1 and 2 form a "producer-consumer" data dependency. In 003, Task 3 writes to Data 1, making it a producer of Data 1. Tasks 2 and 3 form a "consumer-next-producer" data dependency, while Tasks 1 and 3 form a "producer-next-producer" dependency.
[0132] It can be seen that according to the data dependency relationship established between Task 1, Task 2 and Task 3, Task 1 should be executed first, and after the "producer-consumer" data dependency relationship between Task 1 and Task 2 is resolved, Task 2 should be executed, and after the "consumer-next producer" data dependency relationship between Task 2 and Task 3 is resolved, Task 3 should be executed last.
[0133] As shown in Figure 5b, 004 represents the sequence number of task 4. Compared to Figure 5a, in 004, task 4 is a consumer of data 1 and a producer of data 2 and data 3. Task 4 and task 1 form a "consumer-producer" dependency, task 4 and task 2 form a "consumer-next-producer" dependency, and task 4 and task 3 form a "producer-next-producer" dependency.
[0134] It can be seen that according to the data dependency relationships established between Task 1, Task 2, Task 3 and Task 4, Task 4 can only start execution after Task 1, Task 2 and Task 3 are all completed. That is, Task 4 needs to wait until the data dependencies between Task 1, Task 2 and Task 3 are all released before it can start execution. In some embodiments, a task may have multiple data dependencies, and a task needs to meet the requirements that all data dependencies are released before it can start execution.
[0135] Refer to Figure 6, which exemplarily shows the data versions corresponding to the data dependency relationship between tasks acting as producers or consumers in an embodiment of the present application.
[0136] The data version here can be used to represent the relationship between data and tasks, that is, the relationship between the data and consumers and producers. In some embodiments, the same data can be read by multiple tasks and written by multiple tasks. For the same data, each time a producer appears (each time it is written), a new data version is generated.
[0137] As shown in Figure 6, 001, 002, 003, and 004 here can represent the order in which the operating system's application submits Task 1, Task 2, Task 3, and Task 4, rather than the order in which Task 1, Task 2, Task 3, and Task 4 are executed. In 001, Task 1 is the producer of Data 1 and can generate Version 1 of Data 1. Task 1 can be represented as the producer of Version 1. In 002, Task 2 is the consumer of Data 1. Task 2 can be represented as the consumer of Version 1. In 003, Task 3 is the producer of Data 1 and can generate Version 2 of Data 1. Task 3 can be represented as the producer of Version 2 and the next producer of Version 1. In 004, Task 4 is the consumer of Data 1. Task 4 can be represented as the consumer of Version 2.
[0138] As can be seen, based on the data version representation, each producer task corresponds to a unique data version. At the same time, different consumer tasks can be mapped to different data versions based on the timing (i.e., the order in which the tasks are executed). Tasks 1 through 4 in Figure 6 involve non-nested tasks; that is, there is no parent-child relationship between Tasks 1 through 4.
[0139] In some embodiments, when a task acting as a producer is completed, the task acting as a consumer corresponding to the first data version corresponding to the task can release the "producer-consumer" data dependency, and the task acting as a producer of the next data version (if any, i.e., the second data version) can release the "producer-next producer" data dependency.
[0140] In some embodiments, when all tasks acting as consumers of a first data version are completed, tasks acting as producers of the next data version (if any, ie, the second data version) can release the "consumer-next producer" data dependency.
[0141] In some embodiments, the dependency management module 403 shown in FIG4a can be used to adjust the data dependency between tasks in the task scheduling method of the embodiment of the present application, and can include a process for processing the data dependency after the task is submitted and a process for processing the data dependency after the task is executed. The following describes in detail, using FIG7a to FIG7c and FIG9a to FIG9c in conjunction with FIG6, in a non-nested task scenario, the task scheduling method mentioned in the present application can include: two processes of establishing and releasing data dependencies between tasks in the process of processing task submission and the process of processing task completion.
[0142] The steps of the task submission processing flow shown in FIG7a include:
[0143] S701: Acquire the target task submitted by the application through the interface module 402.
[0144] Exemplarily, the target tasks here may be tasks submitted by applications installed on the operating system. As shown in FIG6 , the target tasks may be tasks 1 to 4, that is, four tasks submitted by the application through the interface module 402 in sequence.
[0145] S702: Apply to the resource management module 401 for resources corresponding to the target task, and store the target task.
[0146] For example, the resource here may be a storage resource of a terminal device corresponding to the operating system, such as a memory resource. Storing the target task may be storing the data structure of the target task and the data structure of the data version corresponding to the task in the resource corresponding to the target task.
[0147] S703: Establishing a data dependency relationship based on the input data of the target task described by the application.
[0148] For example, if the target task reads data, the data read by the target task is used as input data to establish a data dependency relationship. It is understood that the dependency management module 403 can determine the input data of the target task by analyzing whether the target task reads data.
[0149] As shown in FIG7 b , the process of establishing a data dependency relationship for input data may include the following steps.
[0150] S703a: For the input data, read the data version linked list stored in the input data.
[0151] Exemplarily, the data version linked list stored in the input data here may be a data version linked list included in a data structure of a data version corresponding to the input data.
[0152] S703b: Determine whether the data version linked list is empty.
[0153] Exemplarily, determining whether the data version linked list is empty is used to determine whether other tasks are currently executing or have previously written or read the input data. If it is empty, it indicates that the target task is the first to read the input data, and step S703c is executed. The target task is the consumer of the input data and can generate a data version of the input data. If it is not empty, it indicates that other tasks are currently executing or have previously written or read the input data, and step S703d is executed to obtain the data version at the end of the data version linked list corresponding to the input data, that is, the current data version of the input data, and further determine whether other tasks have completed writing or reading the input data.
[0154] S703c: Generate a data version of the input data, initialize the data version status to VERSION_PRODUCED, and insert it at the end of the data version linked list.
[0155] For example, when the target task is the first to read the input data, a latest data version of the input data is generated, and the status of the latest data version is set to VERSION_PRODUCED (producer task execution completed), which is used to indicate that the "producer-next producer" dependency between the producer of the data version and the producer of the next data version is released, that is, the latest data version of the input data has no corresponding producer task.
[0156] S703d: Read the data version at the end of the data version linked list.
[0157] For example, the end of the data version linked list can be the last node in the data version linked list of the input data, that is, the current data version of the input data. For the input data, the data version at the end of the data version linked list can indicate whether there are tasks other than the target task and whose submission time is earlier than the target task that are writing or reading the input data.
[0158] S703e: Determine whether the data version status is VERSION_PENDING.
[0159] For example, if the status of the current data version of the input data is VERSION_PENDING (dependency not released), it means that before the target task, there are other tasks that need to write to the input data or are currently writing to it. Then, step S703f is executed to increase the number of data dependencies corresponding to the target task by one, indicating that before the target task, there are other tasks that need to write to the input data, and there is a "producer-consumer" data dependency relationship between the target task and the other tasks. Otherwise, step S703g is executed, and the target task is set as the consumer task of the input data if there is a read operation on the input data.
[0160] S703f: Increase the number of data dependencies of the target task by one.
[0161] Exemplarily, increasing the number of data dependencies corresponding to the target task by one indicates that before the target task, there are other tasks that need to write to the input data, and there is a data dependency relationship between the target task and the other tasks.
[0162] S703g: Add the target task to the consumer task list of the data version.
[0163] For example, setting the target task as a consumer task for the input data indicates that the target task has a read operation on the input data. In some embodiments, since the target task must wait until all dependencies are resolved before it can begin reading the input data, the excessive execution time of step S703g here describes the establishment of data dependencies and does not mean that the target task can immediately read the input data.
[0164] S703h: Add the data version to the input data version list of the target task.
[0165] Exemplarily, whether the data version is read for the first time in the target task or other tasks have written or read the input data, the data version at the end of the data version linked list of the input data can be added to the input data version list of the target task.
[0166] S704: Establishing a data dependency relationship based on the output data of the target task described by the application.
[0167] For example, if the target task writes data, the data written by the target task is used as output data, and a data dependency relationship is established. It is understood that the dependency management module 403 can determine the output data of the target task by analyzing whether the target task writes data. As shown in FIG7 c, the process of establishing a data dependency relationship for the output data may include the following steps.
[0168] S704a: For the output data, read the data version linked list stored in the output data.
[0169] Exemplarily, the data version linked list stored in the output data here may be a data version linked list included in a data structure of a data version corresponding to the output data.
[0170] S704b: Determine whether the data version linked list is empty.
[0171] Exemplarily, judging whether the data version linked list is empty is used to determine whether there are other tasks that are currently executing or have previously written or read the output data. If it is empty, it means that the target task is the first to write to the output data, and then step S704c is executed. The target task is the producer of the output data and can generate a data version of the output data. In some embodiments, if it is not empty, it means that there are other tasks that will need to execute or are currently executing or have previously written or read the output data, that is, there are other producer or consumer tasks before the target task, but they may not have been executed, are currently executing, or have been completed. Then step S704d is executed to obtain the data version at the end of the data version linked list corresponding to the output data, that is, the current data version of the output data, and further determine whether other tasks have completed writing or reading the output data.
[0172] S704c: Generate a data version of the output data, initialize the data version status to VERSION_PENDING, and insert it at the end of the data version linked list.
[0173] Exemplarily, if the data version linked list is empty, it means that the target task is the first to write to the output data; if the data version linked list is not empty, it means that there are other producer tasks before the target task. Generate the latest data version of the output data, and set the status of the latest data version to VERSION_PENDING (dependency not released) to indicate that there is still a "producer-consumer" data dependency relationship between the producer of the data version and the consumer of the data version that has not been released. In other words, the latest data version of the output data has a corresponding producer task. In some embodiments, the execution order of the target tasks may include: the producer task of the current data version (current task) is higher than the consumer task of the current data version, which is higher than the producer task of the next data version.
[0174] S704d: Read the data version at the end of the data version linked list.
[0175] For example, the end of the data version linked list can be the last node in the data version linked list of the output data, that is, the current data version of the output data. For the output data, the data version at the end of the data version linked list can indicate whether any task other than the target task is writing or reading the output data.
[0176] S704e: Determine whether the status of the data version at the end of the data version linked list is VERSION_CONSUMED.
[0177] For example, if the status of the current data version of the output data is VERSION_CONSUMED (all consumer tasks are completed), it means that other tasks before the target task (excluding the target task, because the target task is a producer task and has not been executed) have completed reading the output data, that is, all consumer tasks are completed. Then execute step S704c, the target task is the producer of the output data, and the data version of the output data can be generated. Otherwise, execute step S704f, and add one to the number of data dependencies corresponding to the target task, indicating that before the target task, there is a producer task that needs to write to the output data or there is a consumer task that needs to read the output data, and there is a data dependency relationship between the target task and other tasks, for example: corresponding to the "producer-next producer" data dependency relationship and the "consumer-next producer" data dependency relationship.
[0178] S704f: Increase the number of data dependencies of the target task by one.
[0179] Exemplarily, the number of data dependencies corresponding to the target task is increased by one, indicating that other tasks write or read the input data, and there is a data dependency relationship between the target task and the other tasks.
[0180] S704g: Set the target task as the next producer of the data version.
[0181] For example, the target task can be a producer task, indicating the producer of the next data version rather than the current data version. Step S704c is then executed to generate the latest data version of the output data, and the target task is set as the producer of the latest data version of the output data, that is, the producer of the next data version of the output data.
[0182] S704h: The newly generated data version is added to the output data version list of the target task.
[0183] For example, the data version in the output data version list here may represent the data version corresponding to the data written by the target task. After the target task is executed, the status of the data version may be updated to the VERSION_PRODUCED status.
[0184] S705 : When the number of data dependencies corresponding to the target task is zero, submit the target task to the task scheduling module 404 .
[0185] For example, the number of data dependencies corresponding to the target task here can also be expressed as the target task's dependency count, which includes the sum of "producer-consumer" data dependencies, "producer-next producer" data dependencies, and "consumer-next producer" data dependencies, and can be uniformly represented by the number of data dependencies. When the number of data dependencies corresponding to the target task is reduced to zero, it indicates that the target task's status has been updated to TASK_READY, that is, the target task's data dependencies have been released and the target task can be executed.
[0186] The following describes in detail the detailed process of the operating system establishing data dependencies between tasks based on the input data and input data corresponding to the tasks in the task submission processing flow in conjunction with Figures 7a to 7c, Figures 6, and Figures 8a to 8d.
[0187] As shown in Figure 6, the operating system's application program sequentially submits Task 1, Task 2, Task 3, and Task 4 through interface module 402 of task scheduling architecture 400. Resource management module 401 sequentially allocates resources to Task 1, Task 2, Task 3, and Task 4, and dependency management module 403 sequentially establishes data dependencies for Task 1, Task 2, Task 3, and Task 4.
[0188] For example, Task 1 writes to Data 1. After Task 1 is submitted, resources are first allocated to Task 1. As shown in Figure 8a, the data structure of Task 1 may include: the function corresponding to Task 1, such as Function 1; the input data version list and output data version list corresponding to Task 1 may be empty. After determining that Data 1 is the output data of Task 1, the data version list of Data 1 is read, and it is determined that the data version list of Data 1 is empty. A version 1 of Data 1 is generated, and the status of Version 1 is initialized to VERSION_PENDING (dependency not released). The data version list of Data 1 is inserted at the end of the data version list of Data 1. At this time, the data version list of Data 1 includes a node of Version 1; Version 1 of Data 1 is added to the output data version list of Task 1, and the number of data dependencies corresponding to Task 1 is 0.
[0189] Task 2 reads data 1. After task 2 is submitted, resources are first allocated to task 2. Continuing to refer to Figure 8b, the data structure of task 2 may include: the function corresponding to task 2, such as function 2; the input data version list and output data version list corresponding to task 2 may be empty. After determining that data 1 is the input data of task 2, the data version list of data 1 is read, and it is determined that the data version list of data 1 is not empty. The data version at the end of the data version list of data 1 is read, that is, version 1. When it is determined that the status of version 1 is VERSION_PENDING (dependency not released), the number of data dependencies of task 2 is increased by one, that is, a data dependency relationship is established between task 2 and task 1. Task 2 is added to the consumer task list of version 1, and at the same time, version 1 is added to the input data version list of task 2.
[0190] Task 3 writes to data 1. After task 3 is submitted, resources are first allocated to task 3. As shown in Figure 8c, the data structure of task 3 may include: the function corresponding to task 3, such as function 3; the input data version list and output data version list corresponding to task 3 may be empty. After determining that data 1 is the output data of task 3, the data version list of data 1 is read, and it is determined that the data version list of data 1 is not empty. The data version at the end of the data version list of data 1 is read, that is, version 1. When it is determined that the status of version 1 is not VERSION_CONSUMED (all consumer tasks have been completed), the number of data dependencies of task 3 is increased by one, and task 3 is set as the next producer of version 1, that is, the producer of the next data version of version 1. Version 2 of data 1 is generated as the next data version of version 1, and version 2 is added to the output data version list of task 3. At the same time, the status of version 2 is initialized to VERSION_PENDING (dependency not released), and inserted at the end of the data version list of data 1.
[0191] Task 4 reads data 1. After task 4 is submitted, resources are first allocated to task 4. Continuing to refer to Figure 8d, the data structure of task 4 may include: the function corresponding to task 4, such as function 4; the input data version list and output data version list corresponding to task 2 may be empty. After determining that data 1 is the input data of task 4, the data version list of data 1 is read, and it is determined that the data version list of data 1 is not empty. The data version at the end of the data version list of data 1 is read, that is, version 2. When it is determined that the status of version 2 is VERSION_PENDING (dependency not released), the number of data dependencies of task 4 is increased by one, that is, a data dependency relationship is established between task 4 and task 3. Task 4 is added to the consumer task list of version 2, and at the same time, version 2 is added to the input data version list of task 4.
[0192] After introducing the process of establishing data dependencies between tasks in the task submission processing flow through Figures 7a to 7c, the following Figures 9a to 9c and combined with Figure 6 describe in detail the process of removing data dependencies between tasks in the task completion processing flow in a non-nested task scenario.
[0193] The steps of the task completion process shown in FIG9a include:
[0194] S901: Receive a target task that has been completed and returned by the task execution module 405.
[0195] For example, the target task here may be a task whose status is updated to TASK_DONE (task execution completed). That is, the task scheduling module 404 assigns the task with zero data dependencies and a status of TASK_READY (data dependencies removed, task executable) to the task execution module 405 for execution, and returns the task to the dependency management module 403 after the execution is completed.
[0196] S902: Removing data dependencies according to the data version of the input data of the target task.
[0197] Exemplarily, if there is a situation where the target task executes reading on data, the data read by the target task is used as input data, and the data dependency is released according to the data version of the input data.
[0198] As shown in FIG9 b , the process of removing data dependencies from input data may include the following steps.
[0199] S902a: For the input data, read the data version of the input data corresponding to the target task.
[0200] For example, the data version of the input data here may be a data version generated when the target task reads the input data, and the data version is stored in a data version linked list corresponding to the input data and an input data version list corresponding to the target task.
[0201] S902b: Determine whether the target task is the last consumer task of the data version.
[0202] For example, determining whether the target task is the last consumer task of the data version is used to determine whether no other tasks, other than the target task, are reading the input data with the data version. If not, step S902 ends. If so, step S902c is executed.
[0203] S902c: Update the status of the data version to VERSION_CONSUMED.
[0204] For example, since the status of the target task is TASK_DONE (task execution completed), that is, the target task is completed, the target task completes reading the input data, and the status of the data version of the input data can be updated to VERSION_CONSUMED (all consumer tasks are completed).
[0205] S902d: Determine whether the data version has the next producer task.
[0206] Exemplarily, the determination of whether a next producer task exists for a data version is used to determine whether a next task writes the input data corresponding to the data version. If so, step S902e is executed to reduce the number of data dependencies of the task that writes the input data corresponding to the data version by one. In other words, the number of data dependencies of the task that writes the input data corresponding to the data version is reduced by one. In other words, all "consumer-next producer" data dependencies between consumers and producers of the next data version are reduced from the number of data dependencies of the task.
[0207] S902e: The number of data dependencies corresponding to the next producer task is reduced by one.
[0208] Exemplarily, the "consumer-next producer" data dependency relationship between all consumers in the number of data dependencies on the producer task corresponding to the next data version of the data version and the producer of the next data version is released.
[0209] S903: Removing data dependencies according to the data version of the output data of the target task.
[0210] Exemplarily, if there is a situation where the target task writes data, the data written by the target task is used as output data, and the data dependency is released according to the data version of the output data.
[0211] As shown in FIG9 c , the process of removing data dependencies from output data may include the following steps.
[0212] S903a: For the output data, read the data version of the output data corresponding to the target task.
[0213] For example, the data version of the output data here may be a data version generated when the target task writes the output data, and the data version is stored in a data version linked list corresponding to the output data and an output data version list corresponding to the target task.
[0214] S903b: Determine whether there is a consumer task for the data version.
[0215] For example, the task "Determine if a data version consumer exists" is used to determine whether other tasks are reading output data with the data version. If so, step S903c is executed to update the data version status to VERSION_PRODUCED. If not, step S902 ends. If so, step S903e is executed to update the data version status to VERSION_PRODUCED.
[0216] S903c: Update the status of the data version to VERSION_PRODUCED.
[0217] For example, since the status of the target task is TASK_DONE (task execution completed), that is, the target task execution is completed, the target task completes writing the output data, and the status of the data version of the output data can be updated to VERSION_PRODUCED (producer task execution completed).
[0218] S903d: Subtract one from the number of data dependencies of the consumer task corresponding to the data version.
[0219] For example, since the target task has completed writing the output data, even if there are multiple subsequent tasks that need to read the output data after the target task, the accuracy of the subsequent tasks will not be affected. After that, the execution ends.
[0220] S903e: Update the status of the data version to VERSION_CONSUMED.
[0221] For example, if there is no consumer task for the data version, the status of the data version is updated to VERSION_CONSUMED (all consumer tasks are executed to completion).
[0222] S903f: Determine whether the data version has the next producer task.
[0223] For example, the determination of whether a next producer task exists for a data version is used to determine whether a producer task writes the output data corresponding to the next data version. If so, step S903g is executed to reduce the number of data dependencies of the task that writes the output data corresponding to the next data version by one. In other words, the "producer-next producer" dependency between the target task of the data version and the subsequent task of the next data version is removed. Otherwise, the execution ends.
[0224] S903g: The number of data dependencies corresponding to the next producer task is reduced by one.
[0225] For example, the next data version of the output data corresponds to only one producer task. That is, only one producer task can write to a data version of the output data. Subtracting one from the number of data dependencies corresponding to the next producer task resolves the next producer's "consumer-next producer" or "producer-next producer" dependency. Execution then terminates.
[0226] S904 : In the process of releasing the data dependency of the target task, when the number of data dependencies between the target task and the subsequent tasks is reduced to zero, the subsequent tasks are submitted to the task scheduling module 404 .
[0227] For example, the number of data dependencies corresponding to the target task here can also be expressed as the dependency number of the target task, which includes the sum of the "producer-consumer" data dependency, the "producer-next producer" data dependency, and the "consumer-next producer" data dependency, and can be uniformly represented by the dependency number. When the dependency number corresponding to the target task is reduced to zero and the status of the target task is updated to TASK_DONE (task execution completed), it means that the data dependency relationship between the target task and the subsequent task has been released, and the task scheduling module 404 can execute the subsequent task.
[0228] S905: Reclaim the resources of the completed target task through the resource management module 401.
[0229] Exemplarily, the resource management module 401 may recycle the resources of the target task whose status is TASK_DONE (task execution completed), that is, recycle the data structure of the target task.
[0230] 9a to 9c and FIG6 and FIG10a to 10d in conjunction with the processing flow of task completion, the operating system removes the detailed process of data dependency between tasks according to the input data and input data corresponding to the tasks.
[0231] As shown in Figure 6, the operating system's application program sequentially submits Task 1, Task 2, Task 3, and Task 4 through interface module 402 of task scheduling architecture 400. Resource management module 401 allocates resources to Task 1, Task 2, Task 3, and Task 4, respectively. Dependency management module 403 establishes data dependencies for Task 1, Task 2, Task 3, and Task 4, respectively. Task scheduling module 404 schedules Task 1, Task 2, Task 3, and Task 4 for execution.
[0232] For example, Task 1 writes to Data 1. After Task 1 is completed, as shown in FIG10 a, the data version list of Data 1 is read. The data version list includes: Version 1 and Version 2. The output data version list corresponding to Task 1 is read to obtain Version 1. There is a consumer task for Version 1, that is, Task 2; the status of Version 1 is updated to VERSION_PRODUCED (the producer task is completed); the number of data dependencies of the consumer task corresponding to Version 1 is reduced by one, that is, the dependency of all consumer tasks that read Version 1 of Data 1 is released. Here, the "producer-consumer" dependency between Task 1 and Task 2 corresponding to Version 1 can be released.
[0233] Task 2 reads Data 1. After Task 2 completes, referencing Figure 10b, the input data version list corresponding to Task 2 is read to obtain Version 1. If the last consumer task of Version 1 is Task 1, the status of Version 1 is updated to VERSION_CONSUMED (all consumer tasks have completed). The next producer task of Version 1 is Task 3, and the number of data dependencies of Task 3 is reduced by one.
[0234] Task 3 and Task 1 write to Data 1. After Task 3 completes, as shown in Figure 10c, the output data version list corresponding to Task 3 is read to obtain Version 2. A consumer task for Version 2 exists, Task 4. The status of Version 2 is updated to VERSION_PRODUCED (producer task execution completed). The number of data dependencies for the consumer task corresponding to Version 2 is reduced by one. In other words, the producer-consumer dependency between Task 3 and Task 4 corresponding to Version 2 is removed.
[0235] Task 4 reads data 1. After Task 4 completes, refer to Figure 10d again and read the input data version list corresponding to Task 2 to obtain version 1. If the last consumer task of version 1 is a task, the status of version 1 is updated to VERSION_CONSUMED (all consumer tasks have completed execution).
[0236] After describing in detail the process of establishing and releasing data dependencies between tasks in the processing flow of task submission and the processing flow of task completion in a non-nested task scenario through the above Figures 7a to 7c and Figures 9a to 9c in combination with Figure 6, the following describes in detail the process of establishing and releasing data dependencies between tasks in the processing flow of task submission and the processing flow of task completion in a nested task scenario through Figures 11 and 12.
[0237] As shown in Figure 11, in the nested task scenario, in the task submission process, the process of establishing data dependencies for output data may include the following steps:
[0238] S1101: Obtain output data of the target task.
[0239] For example, if the target task writes data, the data written by the target task is used as output data (data_i) to establish a data dependency relationship. It is understood that the target task here can be a subtask.
[0240] S1102: Determine whether the output data is nested with the parent task of the target task.
[0241] Exemplarily, if the output data (data_i) of the target task also exists in the data dependency relationship of the parent task that has been processed by the dependency management module 403, it is determined that the output data and the parent task of the target task are nested, that is, the target task and the parent task belong to a nested task scenario, and step S1103 is executed; otherwise, step S1102-1 can be executed, and in a non-nested task scenario, a process of establishing a data dependency relationship for the output data is performed, that is, the process of establishing a data dependency relationship for the output data is executed as shown in Figure 7c.
[0242] S1103: Obtain the data version of the output data corresponding to the parent task of the target task.
[0243] For example, the parent task of the target task also writes to the output data (data_i), and the parent task's output data version list stores the data version (version_k) of the output data (data_i). It is understood that the data version (version_k) here can also be stored in the data version linked list corresponding to the output data (data_i).
[0244] S1104: Whether there is a previous data version of the output data corresponding to the parent task.
[0245] For example, whether the previous data version exists here can be determined by whether the data version (version_k) has the previous data version (version_k-1) in the data version linked list corresponding to the output data (data_i). If not, step S1105 is executed, indicating that only the parent task of the target task is writing to the output data (data_i); if so, step S1107 is executed, indicating that in addition to the parent task of the target task, other tasks are also writing to the output data (data_i).
[0246] S1105: Generate a data version of the output data, initialize the state of the data version to VERSION_PENDING, and insert it before the data version of the parent task of the target task in the data version linked list.
[0247] For example, before the target task writes the output data, the parent task of the target task also writes the output data to generate the latest data version (version_k+1) of the output data, sets the status of the latest data version to VERSION_PENDING (dependency not released), and inserts it before the data version of the parent task, which is called the previous data version of the data version of the parent task.
[0248] S1106: The newly generated data version is added to the output data version list of the target task.
[0249] Exemplarily, the data version in the output data version list here may represent the data version (version_k+1) corresponding to the data written by the target task.
[0250] S1107: Obtain the previous data version of the output data corresponding to the parent task.
[0251] Exemplarily, the previous data version (version_k-1) here can be the data version before the data version (version_k) of the parent task in the data version linked list corresponding to the output data (data_i), that is, the previous data version of the data version (version_k).
[0252] S1108: Determine whether the status of the previous data version is VERSION_CONSUMED.
[0253] For example, if the status of the previous data version (version_k-1) is VERSION_CONSUMED (all consumer tasks have completed execution), it indicates that other tasks prior to the target task have completed reading the output data. Step S1105 is then executed. Otherwise, step S1109 is executed, and the number of data dependencies corresponding to the target task is incremented by one, indicating that other tasks have written to the output data, and a data dependency relationship exists between the target task and the other tasks.
[0254] S1109: Increment the number of data dependencies of the target task by one.
[0255] Exemplarily, the number of data dependencies corresponding to the target task is increased by one, indicating that other tasks write or read the input data, and there is a data dependency relationship between the target task and the other tasks.
[0256] S1110: Set the target task as the next producer of the previous data version.
[0257] For example, the target task can be a producer task that represents the producer of the next data version of the previous data version. Then, step S1105 is executed to generate the latest data version of the output data, and the target task is set as the producer of the data version (version_k-1) after the data version (version_k) of the original parent task.
[0258] As shown in Figure 12, in the nested task scenario, in the task completion process, the process of removing data dependencies from the output data may include the following steps:
[0259] As shown in FIG12 , the process of removing data dependencies from output data may include the following steps.
[0260] S1201: For output data, read the data version of the output data corresponding to the target task.
[0261] For example, the data version (version_i) of the output data here can be the data version generated when the target task writes the output data. The data version is stored in the data version linked list corresponding to the output data and the output data version list corresponding to the target task.
[0262] S1202: Determine whether there is a previous data version or whether the status of the previous data version is VERSION_CONSUMED.
[0263] Exemplarily, the previous data version here can be the previous data version (version_k) of the data version (version_i) of the output data in the linked list, that is, only when the subtask nestedly writes or reads the output data of the target task (parent task) and the target task is completed but the subtask has not been completed, the previous data version (version_k) status is not equal to VERSION_CONSUMED (all consumer tasks are completed), then step S1203 is executed, and data dependency conversion is required between the target task (parent task) and the subtask; otherwise, step S1202-1 is executed, that is, the process of releasing the data dependency relationship of the output data as shown in Figure 9c.
[0264] S1203: Get the previous data version.
[0265] Exemplarily, the previous data version here may be a data version (version_k) before the data version (version_i) of the output data.
[0266] S1204: Determine whether there is a consumer task for the data version of the output data.
[0267] Exemplarily, if the data version (version_i) of the output data of the target task exists as a consumer task, execute step S1205 to add the consumer of the target task to the consumer task list of the subtask; otherwise, execute step S1209 to determine whether the data version of the output data exists as the next producer task.
[0268] S1205: Add all consumer tasks of the data version of the output data corresponding to the target task to the consumer task list of the previous data version.
[0269] Exemplarily, the consumer of the target task (parent task) is added to the consumer task list of the child task.
[0270] S1206: For each consumer task of the data version of the output data corresponding to the target task, in the input data version list of each consumer task, the data version of the output data corresponding to the target task is replaced with the previous data version.
[0271] For example, it is necessary to convert the consumer task of the target task (parent task) to the child task, and in the input data version list of all target tasks (parent tasks), the data version (version_i) of the output data corresponding to the target task needs to be replaced with the previous data version (version_k).
[0272] S1207: Determine whether the status of the previous data version is VERSION_PRODUCED.
[0273] For example, if the status of the previous data version (version_k), that is, the data version of the subtask is VERSION_PRODUCED (producer task execution completed), it means that the status of the subtask is TASK_DONE (task execution completed), that is, the subtask execution is completed, and step S1208 is executed to release the data dependency of the subsequent tasks of the subtask.
[0274] S1208: The number of data dependencies of the consumer task corresponding to the data version of the target task is reduced by one
[0275] For example, since the child tasks of the target task (parent task) also complete writing to the output data, even if there are multiple subsequent tasks after the target task that need to read the output data, it will not affect the accuracy of the subsequent tasks.
[0276] S1209: Determine whether the data version of the output data corresponding to the target task exists in the next producer task.
[0277] Exemplarily, the determination of whether a next producer task exists for the data version (version_i) of the output data corresponding to the target task is used to determine whether a producer task writes the output data corresponding to the next data version of the data version (version_i). If so, step S1210 is executed to replace the next producer of the previous data version (version_k) with the next producer of the data version (version_i) of the output data. In other words, the next producer of the completed target task (parent task) is transferred to the child task of the uncompleted target task.
[0278] S1210: The next producer of the previous data version is replaced with the next producer of the data version of the output data.
[0279] Exemplarily, the next producer of the completed target task (parent task) is transferred to the child task of the uncompleted target task.
[0280] The following first introduces the detailed process of the operating system establishing data dependency relationships between tasks based on the input data and output data corresponding to the tasks in the task submission processing flow in conjunction with Figure 11 and Figures 13a to 13d.
[0281] For example, Task 1 writes Data 1 and Data 2. After Task 1 is submitted, as shown in Figure 13a, Task 1's data structure may include: a function corresponding to Task 1, such as Function 1; the input data version list corresponding to Task 1 may be empty, and the output data version list may include Version 1.1 and Version 2.1. The status of Version 1.1 and Version 2.1 is VERSION_PENDING (dependency not released).
[0282] During the execution of Task 1, Task 1 submitted Task 1.1. Task 1.1 writes to Data 1. Continuing with Figure 13b, the function corresponding to Task 1.1 is, for example, Function 1.1. The input data version list for Task 1.1 may be empty, while the output data version list may include Version 1.01. For Data 1, Version 1.01 precedes Version 1.1, and its status is VERSION_PENDING (dependency not released).
[0283] Task 2 reads Data 1. After Task 2 submits, as shown in Figure 13c , Task 2's data structure may include the corresponding function for Task 2, such as Function 4. After confirming that Data 1 is input data for Task 2, Task 2 reads Data 1's data version list. Confirming that the data version list is not empty, Task 2 reads the data version at the end of the data version list, i.e., Version 1.1. If the status of Version 1.1 is determined to be VERSION_PENDING (dependency not released), Task 2's data dependency count is incremented by one, Task 2 is added to Version 1.1's consumer task list, and Version 1.1 is added to Task 2's input data version list.
[0284] Task 3 reads data 2. After task 3 is submitted, resources are first allocated to task 3. Continuing to refer to Figure 13d, the data structure of task 3 may include: the function corresponding to task 3, such as function 3; the input data version list and output data version list of task 3 may be empty. After determining that data 2 is the input data of task 3, the data version list of data 2 is read, and it is determined that the data version list of data 2 is not empty. The data version at the end of the data version list of data 2 is read, that is, version 2.1. When it is determined that the status of version 2.1 is VERSION_PENDING (dependency not released), the number of data dependencies of task 3 is increased by one, and task 3 is added to the consumer task list of version 2.1. At the same time, version 2.1 is added to the input data version list of task 3.
[0285] 12 and 14a to 14d, the following first introduces the detailed process of the operating system removing data dependencies between tasks according to the input data and output data corresponding to the tasks in the task completion processing flow.
[0286] For example, after Task 1 is completed, as shown in FIG14a , the data version list of Data 1 is read, and the data version list includes: Version 1.01 and Version 1.1. The output data version list corresponding to Task 1 is read to obtain Version 1.1 and Version 2.1. Version 1.1 has a previous data version, namely, Version 1.01, and the status of Version 1.01 is VERSION_PENDING (dependency not released) and the status of Version 1.1 is VERSION_PRODUCED (producer task execution completed), and Version 1.01 is obtained. Version 1.1 has a consumer task, namely, Task 2. Task 2 is added to the consumer task list of Version 1.01, and Version 1.1 in the input data version list of Task 2 is replaced with Version 1.01. Version 2.1 does not have a previous data version, and Version 2.1 has a consumer task, namely, Task 3; the status of Version 2.1 is updated to VERSION_PRODUCED (producer task execution completed); the number of data dependencies of the consumer task corresponding to Version 2.1, namely, Task 3, is reduced by one.
[0287] Task 3 reads Data 2. After Task 3 completes, referencing Figure 14b, the input data version list corresponding to Task 3 is read to obtain version 2.1. Since Task 3 is the last consumer task of version 2.1, the status of version 2.1 is updated to VERSION_CONSUMED (all consumer tasks have completed execution).
[0288] Task 1.1 writes to Data 1. After Task 1.1 completes, as shown in Figure 14c, the output data version list corresponding to Task 1.1 is read to obtain Version 1.01. Version 1.01 has a consumer task, Task 2. The status of Version 1.01 is updated to VERSION_PRODUCED (producer task execution completed). The number of data dependencies of Task 2, the consumer task corresponding to Version 1.01, is reduced by one. In other words, the producer-consumer dependency between Task 1.1 and Task 2, corresponding to Version 1.01, is resolved.
[0289] Task 2 reads Data 1. After Task 2 completes, referencing Figure 14d, the input data version list corresponding to Task 2 is read to obtain version 1.01. Since Task 2 is the last consumer of version 1.01, the status of version 1.01 is updated to VERSION_CONSUMED (all consumer tasks have completed execution).
[0290] It can be seen that in the task scheduling method provided in the embodiment of the present application, for nested task scenarios, when establishing data dependencies for output data, if a subtask and a parent task are nested and use the same output data, then in the data version linked list order of the output data, the data version created by the subtask will be inserted before the data version of the parent task. When removing the data dependency for the output data, if the subtask has not yet completed when the parent task is completed, the relevant dependencies of the parent task's data version will be converted to the subtask's data version, thereby ensuring that the parent task can exit earlier than the subtask and that the data dependency remains correct.
[0291] The above Figures 11 and 12 describe in detail the process of establishing and removing data dependencies between tasks in the task submission processing flow and the task completion processing flow in the nested task scenario. It can be seen that Figures 11 and 12 are a solution for handling data dependencies in the nested task scenario. The following Figures 15 and 16 introduce another solution for handling data dependencies in the nested task scenario.
[0292] In some embodiments, a scope is added to the data version of the output data. The scope of the data version is the target task, that is, all data versions generated during the execution of a target task, that is, all data versions generated when the target task writes to the output data.
[0293] In some embodiments, the data version linked list corresponding to the output data can use a two-level storage structure. The first-level linked list is stored by scope information, and the second-level linked list is stored in the order of data versions. Each data version belongs to only one scope. For example, the scope information can be directly represented by the task address of the parent task.
[0294] As shown in Figure 15, in the task submission process in a nested task scenario, the process of establishing data dependencies on output data based on the task scope may include the following steps:
[0295] S1501: For the output data of the target task, obtain a data version linked list corresponding to the output data.
[0296] For example, if the target task (scope scope_j) writes data, the data written by the target task is used as the output data (data_i), and a data dependency relationship is established. The data version linked list here can include a first-level linked list and a second-level linked list, where the first-level linked list is used to store scope information and the second-level linked list is used to store data versions.
[0297] S1502: Determine whether the first-level linked list has a scope.
[0298] For example, if there is no scope in the first-level linked list, it means that no other task has written or read the output data in the scope, and the scope in the first-level linked list has not been created.
[0299] , then execute step S1503 to add the target task's scope (scope_j) to the first-level linked list of the output data and add a second-level linked list to scope (scope_j) to store the data version of the output data. Otherwise, execute step S1504 to directly obtain the second-level linked list corresponding to the target task's scope (scope_j).
[0300] S1503: Create a second-level linked list for the output data based on the scope of the target task.
[0301] Exemplarily, the second-level linked list here is used to store the data version of the output data.
[0302] S1504: Obtain the second-level linked list corresponding to the scope of the target task.
[0303] For example, the second-level linked lists under different scopes do not affect each other when establishing quantity dependencies. In a nested task scenario, the data version of the parent task and the data version of the child task can belong to different scopes.
[0304] S1505: Determine whether the second-level linked list is empty.
[0305] For example, if it is empty, step S1506 is executed, indicating that only the target task writes to the output data (data_i); if it is not empty, step S1508 is executed, indicating that in addition to the target task, there are other tasks that write to the output data (data_i), and it is determined whether the status of the data version at the end of the second-level linked list is VERSION_CONSUMED (all consumer tasks are completed).
[0306] S1506: Generate a data version of the output data, initialize the data version status to VERSION_PENDING, and insert it at the end of the second-level linked list.
[0307] Exemplarily, when the target task is the first to write the output data, a latest data version of the output data is generated, and the status of the latest data version is set to VERSION_PENDING (dependency not released).
[0308] S1507: The newly generated data version is added to the output data version list of the target task.
[0309] For example, the data version in the output data version list here may represent the data version corresponding to the data written by the target task. After the target task is executed, the status of the data version may be updated to the VERSION_PRODUCED status.
[0310] S1508: Determine whether the status of the data version at the end of the second-level linked list is VERSION_CONSUMED.
[0311] For example, if the current data version of the output data is VERSION_CONSUMED (all consumer tasks have completed execution), indicating that the target task or other tasks have completed reading the output data, then step S1506 is executed. The target task is the producer of the output data and can generate a data version of the output data. Otherwise, step S1509 is executed to increase the number of data dependencies corresponding to the target task by one, indicating that other tasks have written to the output data and that a data dependency relationship exists between the target task and the other tasks.
[0312] S1509: Increment the number of data dependencies of the target task by one.
[0313] Exemplarily, the number of data dependencies corresponding to the target task is increased by one, indicating that other tasks write or read the input data, and there is a data dependency relationship between the target task and the other tasks.
[0314] S1510: Set the target task as the next producer of the data version at the end of the second-level linked list.
[0315] For example, the target task can be a producer task, indicating the producer of the next data version rather than the current data version. Step S1506 is then executed to generate the latest data version of the output data, and the target task is set as the producer of the latest data version of the output data, that is, the producer of the next data version of the output data.
[0316] As shown in Figure 16, in the nested task scenario, in the task completion process, the process of removing data dependencies of output data based on scope may include the following steps:
[0317] S1601: Obtain the output data of the target task and the data version of the output data.
[0318] For example, if the target task writes data, the data written by the target task is used as the output data (data_i), and a data dependency relationship is established based on the data version (version_i) of the output data obtained by the target task. It can be understood that the target task here can be the parent task.
[0319] S1602: Determine whether the output data is nested with a subtask of the target task.
[0320] Exemplarily, if the first-level linked list in the data version linked list of the output data (data_i) of the target task includes two or more scopes, it is determined that the output data and the subtask of the target task are nested, that is, the target task and the parent task belong to a nested task scenario, and step S1603 is executed; otherwise, the process of removing the data dependency of the output data in a non-nested task scenario can be executed, that is, otherwise, step S1602-1 is executed, which is the process of removing the data dependency of the output data as shown in Figure 9c.
[0321] S1603: According to the scope of the subtask of the target task, search the corresponding second-level linked list.
[0322] Exemplarily, the second-level linked list here is used to store the data version of the output data corresponding to the subtask.
[0323] S1604: Determine whether the second-level linked list is empty or whether the status of the data version at the end of the second-level linked list is VERSION_CONSUMED.
[0324] Exemplarily, the data version at the end of the second-level linked list is the latest data version (version_k) corresponding to the scope of the subtask. When the parent task is completed but the subtask is not, and the status of the data version (version_k) is not equal to VERSION_CONSUMED, if the second-level linked list is not empty and the status of the data version at the end of the second-level linked list is not VERSION_CONSUMED, then step S1605 is executed, and data dependency conversion needs to be performed between the target task (parent task) and the subtask; otherwise, step S1602-1 is executed, as shown in FIG9c , to remove the data dependency relationship of the output data.
[0325] S1605: Obtain the data version at the end of the second-level linked list.
[0326] Exemplarily, the data version (version_k) at the end of the second-level linked list is obtained.
[0327] S1606: Determine whether there is a consumer task for the data version of the output data.
[0328] Exemplarily, if the data version (version_i) of the output data of the target task exists as a consumer task, execute step S1607 to add the consumer of the target task to the consumer task list of the subtask; otherwise, execute step S1611 to determine whether the data version of the output data exists as the next producer task.
[0329] S1607: Add all consumer tasks of the data version of the output data corresponding to the target task to the consumer task list of the previous data version.
[0330] Exemplarily, the consumer of the target task (parent task) is added to the consumer task list of the data version of the corresponding output data of the child task.
[0331] S1608: For each consumer task of the data version of the output data corresponding to the target task, in the input data version list of each consumer task, the data version of the output data corresponding to the target task is replaced with the previous data version.
[0332] For example, it is necessary to convert the consumer task of the target task (parent task) to the child task, and in the input data version list of all target tasks (parent tasks), the data version (version_i) of the output data corresponding to the target task needs to be replaced with the previous data version (version_k).
[0333] S1609: Determine whether the status of the previous data version is VERSION_PRODUCED.
[0334] For example, if the status of the previous data version (version_k), that is, the data version of the subtask is VERSION_PRODUCED (producer task execution completed), it means that the status of the subtask is TASK_DONE (task execution completed), that is, the subtask execution is completed, and step S1610 is executed to release the data dependency of the subsequent tasks of the subtask.
[0335] S1610: The number of data dependencies of the consumer task corresponding to the data version of the target task is reduced by one.
[0336] For example, since the child tasks of the target task (parent task) also complete writing to the output data, even if there are multiple subsequent tasks after the target task that need to read the output data, it will not affect the accuracy of the subsequent tasks.
[0337] S1611: Determine whether the data version of the output data corresponding to the target task exists in the next producer task.
[0338] Exemplarily, the determination of whether a next producer task exists for the data version (version_i) of the output data corresponding to the target task is used to determine whether a producer task writes the output data corresponding to the next data version of the data version (version_i). If so, step S1612 is executed to replace the next producer of the previous data version (version_k) with the next producer of the data version (version_i) of the output data. In other words, the next producer of the completed target task (parent task) is transferred to the child task of the uncompleted target task. Otherwise, execution ends.
[0339] S1612: The next producer of the previous data version is replaced with the next producer of the data version of the output data.
[0340] For example, the next producer of the completed target task (parent task) is transferred to the child task of the uncompleted target task. After that, the execution ends.
[0341] It can be seen that in the task scheduling method provided in the embodiment of the present application, for the nested task scenario, the data version linked list of the output data is divided into two levels, the first-level linked list is stored according to the scope of the task, and the second-level linked list is stored in the order of the data versions corresponding to the scope. When establishing a data dependency relationship for the output data, if the subtask and the parent task are nested and use the same output data, then the data versions corresponding to the subtask and the parent task belong to different scopes in the first-level linked list, and therefore do not interfere with each other in the process of establishing the data dependency relationship. When removing the data dependency relationship for the output data, the second-level linked list of the subtask can be found according to the scope of the subtask. If the subtask has not been completed when the parent task is completed, the relevant dependency relationship of the parent task's data version will be converted to the subtask's data version, thereby ensuring that the parent task can exit ahead of the subtask and that the data dependency relationship remains correct.
[0342] The following describes in detail the detailed process of the operating system establishing data dependencies between tasks based on the input data and input data corresponding to the tasks in the task submission processing flow in the nested task scenario, in conjunction with Figure 15 and Figures 17a to 17d.
[0343] Exemplarily, task 1 writes data 1 and data 2. After task 1 is submitted, the output data corresponding to task 1 can be data 1 and data 2. As shown in Figure 17a, the data structure of task 1 may include: the function corresponding to task 1, such as function 1; the scope corresponding to task 1 can be directly identified by task 1. Create scopes for data 1 and data 2 respectively: the first-level linked list corresponding to task 1. Generate version 1.1 and version 2.1 of data 1 and data 2. The status of version 1.1 and version 2.1 is VERSION_PENDING (dependency not released), and insert them into the end of the second-level linked list corresponding to the first-level linked list of task 1, where the scope of data 1 and data 2 is respectively. Add version 1.1 and version 2.1 to the output data version list of task 1.
[0344] During the execution of Task 1, Task 1 submitted Task 1.1. Task 1.1 writes to Data 1. The output data corresponding to Task 1.1 can be Data 1. Referring to Figure 17b, the function corresponding to Task 1.1 is as follows: Function 1.1; the scope corresponding to Task 1.1 can be directly identified by Task 1.1. Create a scope for Data 1: the first-level linked list corresponding to Task 1.1. Generate version 1.01 of Data 1. The status of version 1.01 is VERSION_PENDING (dependency not released). The scope of Data 1 inserted is the end of the second-level linked list corresponding to the first-level linked list of Task 1.1. Add version 1.01 to the output data version list of Task 1.1.
[0345] Task 2 reads Data 1. After Task 2 submits, as shown in Figure 17c, Task 2's data structure may include the function corresponding to Task 2, such as Function 2. After confirming that Data 1 is input data for Task 2, Task 2 reads Data 1's data version list. Confirming that the data version list is not empty, Task 2 reads the data version at the end of the data version list, i.e., Version 1.1. If the status of Version 1.1 is determined to be VERSION_PENDING (dependency not released), Task 2's data dependency count is incremented by one, Task 2 is added to Version 1.1's consumer task list, and Version 1.1 is added to Task 2's input data version list.
[0346] Task 3 reads data 2. After task 3 is submitted, resources are first allocated to task 3. Continuing with reference to Figure 17d, the data structure of task 3 may include: the function corresponding to task 3, such as function 3; the input data version list and output data version list of task 3 may be empty. After determining that data 2 is the input data of task 3, the data version list of data 2 is read, and it is determined that the data version list of data 2 is not empty. The data version at the end of the data version list of data 2 is read, that is, version 2.1. When it is determined that the status of version 2.1 is VERSION_PENDING (dependency not released), the number of data dependencies of task 3 is increased by one, and task 3 is added to the consumer task list of version 2.1. At the same time, version 2.1 is added to the input data version list of task 3.
[0347] The following first introduces the detailed process of the operating system removing data dependencies between tasks according to the input data and output data corresponding to the tasks in the task completion processing flow in conjunction with Figure 16 and Figures 18a to 18d.
[0348] For example, after the execution of Task 1 is completed, as shown in FIG18a, the output data corresponding to Task 1 is read: Data 1 and Data 2, and the output data version list corresponding to Task 1 is read to obtain Version 1.1 and Version 2.1. For Data 1, the first-level linked list in the data version linked list of Data 1 includes two scopes, Task 1 and Task 1.1, and Data 1 and the subtask of Task 1, i.e., Task 1.1, are nested. According to the scope of Task 1.1, the status of the data version at the end of the second-level linked list corresponding to Task 1.1 is determined to be VERSION_PENDING (dependency not released), and the data version at the end is obtained as Version 1.01. Version 1.1 has a consumer task, i.e., Task 2. Task 2 is added to the consumer task list of Version 1.01, and Version 1.1 in the input data version list of Task 2 is replaced with Version 1.01.
[0349] For data 2, continuing to refer to Figure 18a, the first-level linked list in the data version linked list of data 2 includes a scope of task 1, the data version of data 2 is version 2.1, and there is a consumer task for version 2.1, that is, task 3; the status of version 2.1 is updated to VERSION_PRODUCED (producer task execution is completed), and the number of data dependencies of task 3 is reduced by one.
[0350] Task 3 reads Data 2. After Task 3 completes, referencing Figure 18b, the input data version list corresponding to Task 3 is read to obtain version 2.1. Since Task 3 is the last consumer task of version 2.1, the status of version 2.1 is updated to VERSION_CONSUMED (all consumer tasks have completed execution).
[0351] Task 1.1 writes to Data 1. After Task 1.1 completes, as shown in Figure 18c, the output data version list corresponding to Task 1.1 is read to obtain Version 1.01. Version 1.01 has a consumer task, Task 2. The status of Version 1.01 is updated to VERSION_PRODUCED (producer task execution completed). The number of data dependencies of Task 2, the consumer task corresponding to Version 1.01, is reduced by one. In other words, the producer-consumer dependency between Task 1.1 and Task 2, corresponding to Version 1.01, is resolved.
[0352] Task 2 reads Data 1. After Task 2 completes, referencing Figure 14d, the input data version list corresponding to Task 2 is read to obtain version 1.01. Since Task 2 is the last consumer of version 1.01, the status of version 1.01 is updated to VERSION_CONSUMED (all consumer tasks have completed execution).
[0353] The task scheduling method provided in the embodiment of the present application can be applied to electronic devices installed with an operating system. The following describes an electronic device 100 involved in implementing the method provided in the embodiment of the present application. The electronic device 100 can be a mobile phone, a tablet computer, a wearable device, an in-vehicle device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), or other terminal devices installed with an operating system. The embodiment of the present application does not impose any restrictions on the specific type of electronic device.
[0354] FIG19 is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of the present application. As shown in FIG19 , the electronic device (terminal device) may include: a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 13, a display 194, and a subscriber identification module (SIM) card interface 195, etc.
[0355] Among them, the above-mentioned sensor module 180 may include sensors such as pressure sensor, gyroscope sensor, air pressure sensor, magnetic sensor, acceleration sensor, distance sensor, proximity light sensor, fingerprint sensor, temperature sensor, touch sensor and ambient light sensor.
[0356] It should be understood that the structure illustrated in this embodiment does not constitute a specific limitation on the electronic device. In other embodiments, the electronic device may include more or fewer components than shown, or may combine or separate certain components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0357] The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Among them, different processing units can be independent devices or integrated into one or more processors. In some embodiments, the processor 110 can be used to execute the task scheduling method provided in the embodiments of the present application.
[0358] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0359] In some embodiments, the processor 110 may include one or more interfaces. The interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface.
[0360] It is understood that the interface connection relationship between the modules illustrated in this embodiment is only for illustrative purposes and does not constitute a structural limitation on the electronic device. In other embodiments, the electronic device may also adopt different interface connection methods from the above embodiments, or a combination of multiple interface connection methods.
[0361] The electronic device implements display functionality through a GPU, display screen 194, and an application processor. A GPU is a microprocessor for image processing that connects display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0362] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel.
[0363] The electronic device can implement a camera function using an ISP, camera 193, a video codec, a GPU, a display 194, and an application processor. The ISP processes data fed back by camera 193. Camera 193 is used to capture still images or video. In some embodiments, the electronic device may include one or N cameras 193, where N is a positive integer greater than 1.
[0364] The external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device. The external memory card communicates with the processor 110 via the external memory interface 120 to implement data storage functions. For example, files such as music and videos can be stored on the external memory card.
[0365] The internal memory 121 can be used to store computer executable program code, which includes instructions. The processor 110 executes various functional applications and data processing of the electronic device by running the instructions stored in the internal memory 121. For example, in an embodiment of the present application, the processor 110 can execute instructions stored in the internal memory 121, and the internal memory 121 can include a program storage area and a data storage area.
[0366] The program storage area may store an operating system, at least one application required for a function (such as a sound playback function, an image playback function, etc.), etc. The data storage area may store data created during the use of the electronic device (such as audio data, a phone book, etc.), etc. In addition, the internal memory 121 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, a universal flash storage (UFS), etc.
[0367] It is understood that the structures illustrated in the embodiments of the present application do not constitute specific limitations on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown, or may combine or separate certain components, or arrange the components differently. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0368] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or, for example, A / B can mean A or B; “and / or” in the text is merely a way to describe the association relationship of associated objects, indicating that three relationships may exist, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone.
[0369] In the following, the terms "first" and "second" are used for descriptive purposes only and should not be understood to imply or suggest relative importance or implicitly indicate the number of the technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the embodiments of this application, unless otherwise specified, "plurality" means two or more.
[0370] References to "embodiments" in this application mean that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0371] It should be understood that although the terms "first," "second," and the like may be used herein to describe various features, these features should not be limited by these terms. These terms are used merely to distinguish and should not be understood as indicating or implying relative importance. For example, a first feature may be referred to as a second feature, and similarly, a second feature may be referred to as a first feature, without departing from the scope of the exemplary embodiments.
[0372] Furthermore, various operations will be described as multiple, separate operations in a manner that is most helpful for understanding the illustrative embodiments; however, the order of description should not be construed to imply that the operations must be performed in order of description, and many of the operations can be performed in parallel, concurrently, or simultaneously. Furthermore, the order of the operations can be rearranged. The process can terminate when the described operations are completed, but can also have additional operations not included in the figures. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0373] References in the specification to "one embodiment," "an embodiment," "an illustrative embodiment," etc., indicate that the described embodiment may include a particular feature, structure, or property, but that every embodiment may or may not necessarily include the particular feature, structure, or property. Furthermore, these phrases are not necessarily referring to the same embodiment. Furthermore, while particular features may be described in conjunction with a specific embodiment, the knowledge of those skilled in the art may affect how those features may be combined with other embodiments, whether or not those embodiments are explicitly described.
[0374] Unless the context dictates otherwise, the terms "comprising," "having," and "including" are synonymous. The phrase "A / B" means "A or B." The phrase "A and / or B" means "(A), (B), or (A and B)."
[0375] As used herein, the term "module" may refer to, be part of, or include: memory (shared, dedicated, or group) for running one or more software or firmware programs, application-specific integrated circuits (ASICs), electronic circuits and / or processors (shared, dedicated, or group), combinational logic circuits, and / or other suitable components that provide the functionality.
[0376] In the accompanying drawings, some structural or method features may be shown in a particular arrangement and / or order. However, it should be understood that such a particular arrangement and / or order is not required. Rather, in some embodiments, these features may be illustrated in a manner and / or order different from that shown in the illustrative drawings. In addition, the inclusion of structural or method features in a particular drawing does not mean that all embodiments need to include such features. In some embodiments, these features may not be included, or they may be combined with other features.
[0377] The embodiments of the present application are described in detail above with reference to the accompanying drawings. However, the application of the technical solution of the present application is not limited to the various applications mentioned in the embodiments of the present patent. Various structures and variations can be easily implemented with reference to the technical solution of the present application to achieve the various beneficial effects mentioned herein. Various changes made within the knowledge of ordinary technicians in this field without departing from the purpose of the present application should fall within the scope of coverage of the patent application.
Claims
1. A task scheduling method, characterized in that: A processor applied to an electronic device, the method comprising: Executing a first task, wherein the first task includes executing a write operation on first data, wherein the first data includes first sub-data and second sub-data; generating a second task during the execution of the first task, wherein the second task includes performing a write operation on the first sub-data; confirming that the third task includes executing a read operation on the first sub-data, and an execution association relationship has been established between the third task and the first task; During the period when the first task is completed and the second task is being executed, the execution association relationship between the third task and the first task is converted into an execution association relationship between the third task and the second task; and after the first task is completed, a fourth task is executed, wherein the fourth task performs a read operation on the second sub-data.
2. The method according to claim 1, characterized in that Also includes: After the second task is completed, the third task is executed.
3. The method according to claim 1, characterized in that The confirming that the third task includes executing a read operation on the first sub-data, and an execution association relationship has been established between the third task and the first task, includes: A first task list corresponding to the first sub-data is obtained, and based on the first task list, it is confirmed that an execution association relationship has been established between the third task and the first task.
4. The method according to claim 3, characterized in that The converting the execution association relationship between the third task and the first task into an execution association relationship between the third task and the second task includes: In the first task list, the reading relationship of the third task reading the first sub-data through the first task is modified to the third task reading the first sub-data through the second task.
5. The method according to claim 4, characterized in that The first task list is in the form of a linked list.
6. The method according to claim 5, characterized in that The first task list includes a plurality of version sub-data corresponding to the first sub-data; In the first task list, the reading relationship between the third task and the first sub-data through the first task includes: a reading relationship between the third task and the first version sub-data among the multiple version sub-data of the first sub-data, and a writing relationship between the first task and the first version sub-data.
7. The method according to claim 6, characterized in that The step of modifying the reading relationship of the third task reading the first sub-data through the first task to the step of the third task reading the first sub-data through the second task includes: In the first task list, the read relationship between the third task and the first version sub-data is modified to a read relationship between the third task and the second version sub-data, wherein the second task and the second version sub-data have a write relationship.
8. The method according to claim 7, characterized in that The acquiring a first task list corresponding to the first sub-data, and confirming based on the first task list that an execution association relationship has been established between the third task and the first task, includes: The first version sub-data is located at the end of the first task list; The first task includes a first write data list, and the first write data list includes the first version sub-data, wherein the first version sub-data includes a first data state, and the first data state indicates that the first task has not yet completed the write operation on the first sub-data; The third task includes a third read data list, and the third read data list includes the first version sub-data; The first version sub-data includes a first read task list, and the first read task list includes the third task.
9. The method according to claim 8, characterized in that The second task has a write relationship with the second version sub-data, including: When the first task and the second task are in a nested task relationship, in the first task list, the second version sub-data is located before the first version sub-data; The second task includes a second write data list, and the second write data list includes the second version sub-data, wherein the second version sub-data includes a first data state.
10. The method according to claim 9, characterized in that The step of modifying the reading relationship between the third task and the first version sub-data in the first task list to the reading relationship between the third task and the second version sub-data includes: The second version sub-data includes a second reading task list, and the second reading task list includes the third task; The third read data list of the third task includes the second version sub-data; The first version sub-data includes a second data state, and the second data state indicates that the first task completes the write operation on the first sub-data.
11. The method according to claim 10, characterized in that After completing the second task, executing the third task includes: The second version sub-data includes a second data state.
12. The method according to claim 1, characterized in that Also includes: A second task list corresponding to the second sub-data is obtained, and based on the second task list, it is confirmed that an execution association relationship has been established between the fourth task and the first task.
13. The method according to claim 12, characterized in that The second task list is in the form of a linked list; The second task list includes a plurality of version sub-data corresponding to the second sub-data, and In the second task list, there is an execution association relationship between the corresponding fourth task and the first task, and the following relationship exists: The fourth task has a reading relationship with a third version of the second sub-data among the multiple version sub-data, and the first task has a writing relationship with the third version of the second sub-data.
14. The method according to claim 13, characterized in that Also includes: After the first task is executed, the writing relationship between the first task and the third version sub-data in the second task list is terminated.
15. The method according to claim 14, characterized in that The reading relationship in the second task list in which the fourth task reads the second sub-data through the first task includes: The third version sub-data is located at the end of the second task list; The first task includes a first write data list, and the first write data list includes the third version sub-data, wherein the third version sub-data includes a first data state; The fourth task includes a fourth read data list, and the fourth read data list includes the third version sub-data; The third version sub-data includes a third read task list, and the third read task list includes the fourth task.
16. The method according to claim 15, characterized in that Also includes: The third version sub-data includes a second data state.
17. A computer storage medium, characterized in that: The computer storage medium stores computer instructions, and the computer instructions are used to implement the task scheduling method according to any one of claims 1 to 16.
18. An electronic device, characterized in that: include: a memory for storing instructions to be executed by one or more processors of the electronic device, and The processor is one of the processors of the electronic device, and is used to execute the task scheduling method described in any one of claims 1-16.
19. A computer program product, characterized in that include: A non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium contains a computer program code for executing the task scheduling method according to any one of claims 1 to 16.
Citation Information
Patent Citations
Electronic equipment, task scheduling method thereof and medium
CN118567794A
Method for efficient task scheduling in the presence of conflicts
CN108139946A
High-concurrency multi-task scheduling management method based on real-time task queue
CN115309531A
Flexible binding of tasks to target resources
US20170262320A1
System, Apparatus And Method For Real-Time Activated Scheduling In A Queue Management Device
US20190102223A1
