Electronic equipment, task scheduling method thereof and medium
By converting the execution relationship between parent tasks and subtasks in nested task scenarios, the task delay problem caused by data dependence between parent tasks and subtasks is solved, and the parallelism and processing efficiency of the operating system are improved.
Patent Information
- Application Number
- CN202310232901.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-28
- Publication Date
- 2024-08-30
AI Technical Summary
In nested task scenarios, data dependencies between parent tasks and subtasks lead to delays in the execution of subsequent tasks and affect the parallelism of multitasking.
By detecting the data dependency between the parent task and the sub-task, the execution association between the parent task and the sub-task is converted, allowing the parent task to exit directly after completion, preventing subsequent tasks from waiting for the sub-task to complete.
It is possible to immediately start executing tasks that have no data dependency on the child task after the parent task is completed, reducing task waiting time and improving the processing efficiency of the operating system.
Smart Images

Figure CN118567794A
Abstract
Description
Technical Field
[0001] 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
[0002] Task parallelism is used to describe the number of tasks executed in parallel by the operating system (also called the terminal system). The operating system establishes dependencies between tasks submitted or generated by applications (users), where the form of dependencies can include indirect dependencies (data dependencies) based on the data of the tasks and direct dependencies (task dependencies) based on the execution of the tasks. After the dependencies are established, the operating system can obtain the dependencies of the tasks during the runtime of the tasks, make scheduling decisions for the tasks, achieve parallelism in the execution of the tasks, and optimize the utilization of the operating system's resources.
[0003] Figure 1a and Figure 1b The process of scheduling task execution by the operating system through task dependency and data dependency is shown respectively. Figure 1a As shown in , when the dependency is task dependency, the execution of task 2 depends on the execution of task 1. Figure 1b As shown, when the dependency is data dependency, data 1 is written during the execution of task 1 and read during the execution of task 2, and the execution data of task 2 depends on the execution of task 1.
[0004] However, for nested task scenarios, that is, during the execution of a task, a new task is generated. In this case, the new task can be called a subtask, and the original task is called a parent task. If there is a data dependency relationship between the parent task and the subtask on the first data, the parent task needs to synchronize the result of the subtask (that is, the parent task needs to wait for the subtask to be executed before it can be executed, so that the subsequent task that has a data dependency relationship with the parent task on the second data can start to execute, which will cause a delay in the execution of the subsequent task and affect the parallelism of multiple tasks. Summary of the invention
[0005] The present application provides an electronic device and a task scheduling method and medium thereof.
[0006] In a first aspect, an embodiment of the present application provides a task scheduling method, which is applied to a processor of an electronic device, and the method includes:
[0007] Execute a first task, the first task includes performing a write operation on first data, the first data includes first sub-data and second sub-data; generate a second task during the execution of the first task, wherein the second task includes performing a write operation on the first sub-data; confirm 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, convert 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 after the first task is completed, execute a fourth task, wherein the fourth task performs a read operation on the second sub-data.
[0008] In the embodiment of the present application, the electronic device here can be a terminal device with an operating system installed, and the processor can 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 can be tasks that the application can submit to the processor through the operating system of the electronic device, and 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 belong to 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 be directly exited after the execution is completed. 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.
[0009] 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 be started in time after the parent task is completed, thereby 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.
[0010] In a possible implementation of the first aspect, the present invention further includes:
[0011] After the second task is completed, the third task is executed.
[0012] In the embodiment of the present application, there is an execution association relationship (data dependency relationship) between the third task and the second task for the second sub-data, and the third task can only start execution after the second task is completed.
[0013] In a possible implementation of the first aspect, 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:
[0014] 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.
[0015] 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. 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 write operations such as update and 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.
[0016] In a possible implementation of the first aspect, converting the execution association relationship between the third task and the first task into the execution association relationship between the third task and the second task includes:
[0017] 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.
[0018] 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.
[0019] In a possible implementation of the first aspect above, the first task list includes a plurality of version sub-data corresponding to the first sub-data;
[0020] In the first task list, the reading relationship of the third task reading the first sub-data through the first task includes a reading relationship between the third task and the first version sub-data among multiple version sub-data of the first sub-data, and a writing relationship between the first task and the first version sub-data.
[0021] In an embodiment of the present application, the version sub-data here may be multiple data versions of the first sub-data, where the first version sub-data here 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 that the first task has completed the write operation on.
[0022] In a possible implementation of the first aspect, modifying the reading relationship of the third task reading the first sub-data through the first task to the third task reading the first sub-data through the second task includes:
[0023] 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.
[0024] In the embodiment of the present application, the write relationship here can be that the second task also needs to perform write operations such as update, delete, etc. on the first sub-data. A second version sub-data is added to the first sub-data that the second task needs to perform write operations on.
[0025] 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.
[0026] 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;
[0027] 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.
[0028] 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;
[0029] 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.
[0030] In an embodiment of the present application, a first task list of 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.
[0031] 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 completes the write operation on the first sub-data.
[0032] In an embodiment of the present application, according to 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 located before the first version sub-data in the first task list is obtained; the 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.
[0033] In a possible implementation of the first aspect, after the second task is completed, a third task is executed, including: the second version sub-data includes a second data state.
[0034] 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.
[0035] In a possible implementation of the first aspect, the present invention further includes:
[0036] 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.
[0037] In an embodiment of the present application, the second task list here can be a data version linked list, 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 write operations such as update and delete on the second sub-data, and 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.
[0038] In a possible implementation of the first aspect above, the second task list is in the form of a linked list;
[0039] The second task list includes a plurality of version sub-data corresponding to the second sub-data, and
[0040] In the second task list, there is an execution association relationship between the fourth task and the first task, and the following relationship exists:
[0041] The fourth task has a reading relationship with the third version sub-data among the multiple version sub-data of the second sub-data, and the first task has a writing relationship with the third version sub-data.
[0042] In an embodiment of the present application, the version sub-data here may be multiple data versions of the second sub-data, and the third version sub-data here corresponds to the second sub-data that the first task needs to perform a write operation on. The fourth task needs to perform a read operation on the second sub-data corresponding to the third version sub-data that the first task has completed the write operation on.
[0043] In a possible implementation of the first aspect, the present invention further includes:
[0044] 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.
[0045] 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.
[0046] In a possible implementation of the first aspect above, in the second task list, the reading relationship of the fourth task reading 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.
[0047] 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 in 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.
[0048] In a possible implementation of the first aspect above, the third version sub-data further includes: the second data state.
[0049] 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.
[0050] In a second aspect, an embodiment of the present application provides a readable medium, on which instructions are stored, and when the instructions are executed on an electronic device, the electronic device executes the task scheduling method of the first aspect.
[0051] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0052] a memory for storing instructions to be executed by one or more processors of the electronic device, and
[0053] The processor is one of the processors of the electronic device and is used to execute the task scheduling method of the first aspect.
[0054] 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
[0055] Figure 1a and Figure 1b A schematic diagram of an operating system provided in an embodiment of the present application scheduling task execution through a dependency relationship between task dependency and data dependency;
[0056] Figure 2a to Figure 2d A schematic diagram of an operating system scheduling task execution through data dependencies in a nested task scenario provided in an embodiment of the present application;
[0057] Figure 3a to Figure 3c , exemplarily showing a schematic diagram of an operating system scheduling task execution in a nested task scenario through data dependencies between subsequent tasks and parent tasks;
[0058] Figure 4a A software structure diagram of the operating system provided in the embodiment of the present application;
[0059] Figure 4b The software module architecture of the task scheduling module in the software structure diagram of the operating system provided in the embodiment of the present application;
[0060] Figure 4c A flowchart of a task scheduling method provided in an embodiment of the present application;
[0061] Figure 5a to Figure 5b A schematic diagram of data dependency between tasks as producers or consumers provided in an embodiment of the present application;
[0062] Figure 6 A schematic diagram of data versions corresponding to data dependencies between tasks as producers or consumers provided in an embodiment of the present application;
[0063] Figures 7a to 7c A schematic diagram of a process for establishing data dependencies between tasks in a task submission process provided in an embodiment of the present application;
[0064] Figures 8a to 8d A schematic diagram of a scenario for establishing data dependency relationships between tasks in a task submission processing flow provided in an embodiment of the present application;
[0065] Figures 9a to 9c A schematic diagram of a process for removing data dependencies between tasks in a task completion process provided in an embodiment of the present application;
[0066] Figures 10a to 10d A schematic diagram of a scenario for removing data dependencies between tasks in a task completion process provided in an embodiment of the present application;
[0067] Fig.11 and Fig.12 A schematic diagram 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;
[0068] Figures 13a to 13dA schematic diagram of a scenario in which an operating system establishes data dependency relationships between tasks according to input data and output data corresponding to the tasks in a task submission processing flow provided in an embodiment of the present application;
[0069] Figures 14a to 14d A schematic diagram of a scenario in which an operating system releases data dependencies between tasks according to input data and output data corresponding to the tasks in a task completion processing flow provided in an embodiment of the present application;
[0070] Fig.15 and Fig.16 A schematic diagram 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;
[0071] Figures 17a to 17d A schematic diagram of a scenario in which an operating system establishes data dependency relationships between tasks according to input data and output data corresponding to the tasks in a task submission processing flow provided in an embodiment of the present application;
[0072] Figures 18a to 18d A schematic diagram of a scenario in which an operating system releases data dependencies between tasks according to input data and output data corresponding to the tasks in a task completion processing flow provided in an embodiment of the present application;
[0073] Fig.19 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0074] The technical solutions in the embodiments of the present application will be described clearly and in detail below with reference to the accompanying drawings.
[0075] refer to Figure 2a to Figure 2d , Figure 2a to Figure 2d The schematic diagram exemplarily shows an operating system scheduling task execution through data dependencies in a nested task scenario provided by an embodiment of the present application.
[0076] like Figure 2aAs shown, Task 1 may 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 may submit tasks to the processor through the operating system of the electronic device 100, and the processor may execute the instructions corresponding to the tasks. During the execution of Task 1, Task 1.1 is generated. Task 1 may be referred to as the parent task of Task 1.1, and Task 1.1 may be referred to as the child task of Task 1. There is a nested task relationship between Task 1 and Task 1.1, and the child task may be executed in parallel with the parent task. In the process of writing functions run by the operating system, nested task relationships often occur. For example, if a recursive function is encapsulated into a task, then 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 may be encapsulated into multiple subtasks.
[0077] In a nested task scenario, since the subtask and parent task may be executed in parallel, the parent task will need to synchronize the results of the subtask.
[0078] The following is a brief introduction to several different types of nested tasks.
[0079] Figure 2b shows a type of nested task where the parent task does not need to synchronize child tasks. Figure 2b In the example, the subtask corresponding to Task 1 is Task 1.1. After Task 1 completes writing to 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 is completed, Task 2 can read the correct Data 1 even if Task 1.1 has not yet been completed. That is, Task 1.1 will not affect the execution of Task 2.
[0080] and Figure 2c and Figure 2d Each shows a type of nested task where the parent task needs to synchronize child tasks. Figure 2c In the example, Task 1 generates Task 1.1 during execution, and 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 Task 1.1 before it can continue to execute. In other words, Task 1 needs to synchronize the result of Task 1.1. If Task 1 completes writing to Data 1 before Task 1.1 is completed, Task 2 (the subsequent task of Task 1) will read Data 1 that Task 1.1 is writing, making the output result of Task 2 incorrect. Similarly, if Figure 2dAs shown, after Task 1 completes writing to Data 1, Task 1.1 is generated. Since Task 1 also needs to write to Data 1, if Task 1 is completed, Task 2 (the subsequent task) will also read Data 1 that Task 1.1 is writing, making the output result of Task 2 incorrect.
[0081] It can be seen that Figure 2a to Figure 2d The scenario shown only describes that the parent task (task 1) has one successor task (task 2). Figure 3a to Figure 3b , Figure 3a to Figure 3b The example shows a scenario in which a parent task has multiple subsequent tasks in a nested task scenario, and the operating system schedules the execution of the tasks based on the data dependency relationship between the subsequent tasks and the parent task.
[0082] Figure 3a As shown, after Task 1 completes writing to Data 2, Task 1.1 is generated. Task 1 needs to write to 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 that will complete writing to Task 1.1, Task 1 needs to synchronize with Task 1.1.
[0083] Figure 3b FIG. 4 shows a schematic diagram of an operating system executing tasks 1 to 3 in parallel, as shown in FIG. Figure 3b As shown in the figure, Task 1 needs to synchronize Task 1.1, that is, Task 1 can exit only after Task 1.1 is completed. After Task 1 is completed, Task 2 and Task 3 are executed in parallel. It can be seen that for Task 3, Task 3 only reads Data 2, that is, Task 3 depends on Data 2 but not Data 1. Figure 3a In the scenario shown, since Task 1 needs to synchronize with Task 1.1, Task 3 must wait for Task 1.1 to complete before it can start executing. That is, the operation of Task 1 synchronously waiting for Task 1.1 to complete delays the execution time of Task 3.
[0084] 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.
[0085] 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 write 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 tasks that have a data dependency on the first data among other subsequent tasks that have a dependency on the parent task, such as 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 tasks that have no data dependency on the first data among other tasks that have a dependency on the parent task can be started in time after the parent task is completed, thereby avoiding the problem of delayed execution time of the above-mentioned subsequent tasks.
[0086] For example, for Figure 3a In the nested tasks, 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 execution. Figure 3c As shown in , 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 time. Figure 3b In the example, task 3 needs to wait for the completion of synchronization task 1.1 before it can be executed. This can effectively reduce the waiting time of task 3 and improve the efficiency of the operating system in processing tasks.
[0087] The following describes the architecture of the operating system of the electronic device that executes the task scheduling method of the embodiment of the present application. Figure 4a It is a software structure block diagram of the operating system 200 according to an embodiment of the present invention.
[0088] The layered architecture of the operating system 200 divides the operating system into several layers, each layer has a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the layered architecture of the operating system can be divided into four layers, from top to bottom, namely, the application layer, the application framework layer, the runtime and system library, and the kernel layer.
[0089] like Figure 4a As shown, the application layer may include applications such as life, video, reading, shopping, gallery, calendar, call, navigation, and music.
[0090] The application framework layer may include a layout subsystem, a window management module, etc. Among them, the layout subsystem is used to determine the position of each display element on the screen of the terminal device. The event input module is used to respond to the user's operation on the terminal device and change the display content on the screen of the terminal device.
[0091] The system library may include a task scheduling module, a layout module, a view module, etc. Among them, the task scheduling module is used to schedule task execution according to the data dependency relationship between tasks. The layout module and the view module can be used to manage the operation mode of the user interface in the window.
[0092] The kernel layer includes display driver, event driver, sensor driver, etc.
[0093] Reference below Figure 4b , Figure 4b An example is shown Figure 4a 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 is described.
[0094] like Figure 4b As shown, 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 .
[0095] 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.
[0096] The interface module 402 provides an interface for the application program (user) and supports the application program to submit various tasks through the interface.
[0097] The dependency management module 403 is used to receive tasks submitted by upper-layer applications, apply for resources corresponding to the tasks, analyze the data dependencies of the tasks through the data read and / or written by the tasks, and apply for resources corresponding to the data version to establish the corresponding data dependencies. The dependency management module 403 is also used to submit the task to the task scheduling module 404 when all the data dependencies of a task are released. When a task is executed, the data dependency with subsequent tasks is updated / released through the status of the data version corresponding to the task.
[0098] The task scheduling module 404 allocates the TASK_READY (data dependency is released, task is executable) task to the task execution module 405 according to the scheduling strategy.
[0099] The task execution module 405 is used to assign the task to the specified or default execution module 406, and return the task to the dependency management module 403 after the task is executed.
[0100] 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.
[0101] In some embodiments, Figure 4b The dependency management module 403 shown can be used to execute the task scheduling method of the embodiment of the present application. Figure 4c As shown, the task scheduling method may include.
[0102] S401: Get the submitted parent task.
[0103] 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 Figure 3a Task 1 in .
[0104] S402: It is detected that there is a data dependency relationship between the parent task and the child task.
[0105] Exemplarily, 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.
[0106] 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.
[0107] For example, the first subsequent task of the parent task here may be task 2, that is, the subsequent task to be executed when the parent task has not yet been completed. The dependency management module 403 may obtain task 2 submitted by the application through the 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.
[0108] S404: Convert the data dependency relationship between the parent task and the first subsequent task into the data dependency relationship between the child task and the first subsequent task.
[0109] Exemplarily, 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 of Data 1 before starting execution.
[0110] S405: Control the execution of the parent task to be completed, and execute the second subsequent task that has no data dependency relationship with the first data.
[0111] Exemplarily, the second subsequent task here may 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 executing without waiting for task 1.1 to complete.
[0112] Before describing in detail the task scheduling method provided in the embodiment of the present application, the tasks, data, and data dependencies between tasks are explained in detail below.
[0113] 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, and when the task is a task of reading data, the task may be called a consumer task.
[0114] In some embodiments, the operating system may establish / eliminate data dependencies by defining data structures for tasks and data.
[0115] 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:
[0116] 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.
[0117] Task execution status: TASK_PENDING (data dependency has not been resolved), TASK_READY (data dependency has been resolved and the task can be executed), TASK_EXECUTING (task executing), TASK_DONE (task execution completed).
[0118] 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 status.
[0119] 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 executed, the status of the output data version is updated to VERSION_PRODUCED status.
[0120] Dependency quantity: includes the sum of the "producer-consumer" data dependency, "producer-next producer" data dependency, and "consumer-next producer" data dependency corresponding to the task, which can be uniformly expressed by the number of data dependencies.
[0121] 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. The data versions have a sequential relationship. The data structure of the data can include the following storage information:
[0122] The data object expressed: the address of the data object or the specified memory address.
[0123] 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).
[0124] Consumer task list: Each data version in the data version list can include zero, one or more tasks as consumers. After the status of the data version is updated to the VERSION_PRODUCED status, the "producer-consumer" dependency between the task as the producer and the task as the consumer corresponding to the data version can be released.
[0125] Next producer task: Each data version in the data version list can include zero or one producer task, which is used to represent the producer of the next data version instead of the producer of the current data version. After the status of the data version is updated to the VERSION_PRODUCED state, the "producer-next producer" dependency between the producer of this data version and the producer of the next data version can be released; after the status of the data version is updated to the VERSION_CONSUMED state, the "consumer-next producer" dependency between all consumers of this data version and the producer of the next data version can be released.
[0126] Previous data version: The previous node in the data version list, which may be empty, is the data version generated by the previous producer.
[0127] 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.
[0128] After introducing the tasks and data used to establish / eliminate data dependencies, you can refer to Figure 5a to Figure 5b , Figure 5a to Figure 5b The data dependency relationship between tasks acting as producers or consumers in the embodiments of the present application is exemplarily shown.
[0129] like Figure 5a As shown, 001, 002, and 003 here can represent the order in which the operating system's application program submits tasks 1, 2, and 3, rather than the execution order of tasks 1, 2, and 3. In 001, task 1 has a write operation on data 1, and task 1 can be represented as the producer of data 1. In 002, task 2 has a read operation on data 1, so task 2 can be represented as the consumer of data 1. A "producer-consumer" data dependency relationship is formed between task 1 and task 2. In 003, task 3 has a write operation on data 1, so task 3 is also the producer of data 1. A "consumer-next producer" data dependency relationship is formed between task 2 and task 3, and a "producer-next producer" dependency is formed between task 1 and task 3.
[0130] 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 then Task 2 should be executed after the "producer-consumer" data dependency relationship between Task 1 and Task 2 is resolved, and finally Task 3 should be executed after the "consumer-next producer" data dependency relationship between Task 2 and Task 3 is resolved.
[0131] like Figure 5b As shown, 004 here can represent the sequence number of task 4. Figure 5a In 004, task 4 is the consumer of data 1 and the 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.
[0132] It can be seen that according to the data dependency relationship 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.
[0133] refer to Figure 6 , Figure 6 The data versions corresponding to the data dependency relationship between tasks acting as producers or consumers in the embodiments of the present application are exemplarily shown.
[0134] 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 (Version) will be generated.
[0135] like Figure 6 As shown, 001, 002, 003 and 004 here can represent the order in which the application of the operating system submits tasks 1, 2, 3 and 4, rather than representing the execution order of tasks 1, 2, 3 and 4. In 001, task 1 is the producer of data 1, which can generate version 1 of data 1, and task 1 can be represented as the producer of version 1. In 002, task 2 is the consumer of data 1, and task 2 can be represented as the consumer of version 1. In 003, task 3 is the producer of data 1, which can generate version 2 of data 1, and task 3 can be represented as the producer of version 2, and task 3 can also be represented as the next producer of version 1. In 004, task 4 is the consumer of data 1, and task 4 can be represented as the consumer of version 2.
[0136] It can be seen that based on the expression of data versions, each task acting as a producer corresponds to a unique data version. At the same time, different tasks acting as consumers can correspond to different data versions according to the timing (i.e., the order in which the tasks run). Figure 6 The involved tasks 1 to 4 involve a non-nested task scenario, that is, there is no parent-child task relationship between tasks 1 to 4.
[0137] 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.
[0138] 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.
[0139] In some embodiments, Figure 4aThe dependency management module 403 shown 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 the processing flow of the data dependency after the task is submitted and the processing flow of the data dependency after the task is executed. Figures 7a to 7c as well as Figures 9a to 9c Combined with Figure 6 , describing in detail in a non-nested task scenario, the task scheduling method mentioned in this application may include: two processes of establishing and releasing data dependencies between tasks in the task submission processing flow and the task completion processing flow.
[0140] Figure 7a The steps of the task submission processing flow shown include:
[0141] S701: Acquire the target task submitted by the application through the interface module 402.
[0142] For example, the target task here may be a task submitted by an application installed on the operating system, such as Figure 6 As shown, the target tasks may be task 1 to task 4, that is, four tasks submitted by the application program in sequence through the interface module 402.
[0143] S702: Apply to the resource management module 401 for resources corresponding to the target task, and store the target task.
[0144] Exemplarily, 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 a data structure of the target task and a data structure of a data version corresponding to the task in the resource corresponding to the target task.
[0145] S703: Establishing data dependency relationships according to input data of the target task described by the application.
[0146] Exemplarily, if the target task reads data, the data read by the target task is used as input data to establish a data dependency. It is understandable that the dependency management module 403 can determine the input data of the target task by analyzing whether the target task reads data.
[0147] like Figure 7b As shown, the process of establishing data dependency relationships for input data may include the following steps.
[0148] S703a: For the input data, read the data version linked list stored in the input data.
[0149] Exemplarily, the data version linked list for input data storage here may be a data version linked list included in a data structure of a data version corresponding to the input data.
[0150] S703b: Determine whether the data version linked list is empty.
[0151] Exemplarily, judging whether the data version linked list is empty is used to determine whether other tasks are executing or have executed writing or reading on the input data. If it is empty, it means that the target task is the first to execute reading on the input data, then step S703c is executed, and the target task is the consumer of the input data, and the data version of the input data can be generated. If it is not empty, it means that other tasks are executing or have executed writing or reading on the input data, then 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.
[0152] S703c: Generate a data version of the input data, initialize the state of the data version to VERSION_PRODUCED, and insert it at the end of the data version linked list.
[0153] Exemplarily, when the target task is the first to perform a read on 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.
[0154] S703d: Read the data version at the end of the data version linked list.
[0155] Exemplarily, the end of the data version linked list here may 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 may indicate whether there is a task other than the target task and whose submission time is earlier than the target task that is writing or reading the input data.
[0156] S703e: Determine whether the status of the data version is VERSION_PENDING.
[0157] Exemplarily, 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 writing to it. Then execute step S703f, 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, execute step S703g, the target task has a read operation on the input data, and the target task is set as the consumer task of the input data.
[0158] S703f: Increase the number of data dependencies of the target task by one.
[0159] Exemplarily, the number of data dependencies corresponding to the target task is increased by one, indicating 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.
[0160] S703g: Add the target task to the consumer task list of the data version.
[0161] Exemplarily, setting the target task as the consumer task of the input data indicates that the target task has a read operation on the input data. In some embodiments, since the target task needs to wait until all dependencies are released before it can start to read the input data, the execution of step S703g here is too long to describe the establishment of the data dependency relationship, and does not mean that the target task can immediately read the input data.
[0162] S703h: Add the data version to the input data version list of the target task.
[0163] 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.
[0164] S704: Establishing data dependency relationships according to output data of the target task described by the application.
[0165] For example, if the target task writes data, the data written by the target task is used as output data to establish a data dependency relationship. It can be understood that the dependency management module 403 can determine the output data of the target task by analyzing whether there is a situation in which the target task writes data. Figure 7c As shown, the process of establishing data dependency for output data may include the following steps.
[0166] S704a: For the output data, read the data version linked list storing the output data.
[0167] Exemplarily, the data version linked list for output data storage here may be a data version linked list included in a data structure of a data version corresponding to the output data.
[0168] S704b: Determine whether the data version linked list is empty.
[0169] 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 executed writing or reading on the output data. If it is empty, it means that the target task is the first to write to the output data, then step S704c is executed, and the target task is the producer of the output data, and a data version of the output data can be generated. 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 executed writing or reading on the output data, that is, there are other producer or consumer tasks before the target task, but they may not have been executed, or are being executed, 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.
[0170] S704c: Generate a data version of the output data, initialize the state of the data version to VERSION_PENDING, and insert it at the end of the data version linked list.
[0171] 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.
[0172] S704d: Read the data version at the end of the data version linked list.
[0173] Exemplarily, the end of the data version linked list here may 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 may indicate whether there are tasks other than the target task that are writing or reading the output data.
[0174] S704e: Determine whether the status of the data version at the end of the data version linked list is VERSION_CONSUMED.
[0175] Exemplarily, if the status of the current data version of the output data is VERSION_CONSUMED (all consumer tasks have been 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 have been 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 increase the number of data dependencies corresponding to the target task by one, 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.
[0176] S704f: Increase the number of data dependencies of the target task by one.
[0177] Exemplarily, the number of data dependencies corresponding to the target task is increased by one, indicating that there are other tasks that write or read the input data, and there is a data dependency relationship between the target task and the other tasks.
[0178] S704g: Set the target task as the next producer of the data version.
[0179] Exemplarily, the target task may be a task that serves as a producer, which indicates the producer of the next data version instead of the producer of the current data version. Then, step S704c is 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.
[0180] S704h: The newly generated data version is added to the output data version list of the target task.
[0181] Exemplarily, 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.
[0182] S705 : When the number of data dependencies corresponding to the target task is zero, submit the target task to the task scheduling module 404 .
[0183] Exemplarily, the number of data dependencies corresponding to the target task here can also be expressed as the number of dependencies of the target task, including the sum of the "producer-consumer" data dependency, the "producer-next producer" data dependency, and the "consumer-next producer" data dependency, which can be uniformly expressed by the number of data dependencies. When the number of data dependencies corresponding to the target task is reduced to zero, it means that the state of the target task is updated to the TASK_READY state, that is, the data dependency of the target task is released and the target task can be executed.
[0184] Combine the following Figures 7a to 7c as well as Figure 6 and Figures 8a to 8d To explain in detail the detailed process of establishing data dependency between tasks according to the input data and output data corresponding to the tasks in the task submission processing flow.
[0185] like Figure 6 As shown, the application of the operating system submits Task 1, Task 2, Task 3 and Task 4 in sequence through the interface module 402 of the task scheduling architecture 400. The resource management module 401 allocates resources to Task 1, Task 2, Task 3 and Task 4 in sequence, and the dependency management module 403 establishes data dependency relationships for Task 1, Task 2, Task 3 and Task 4 in sequence.
[0186] For example, task 1 writes data 1. After task 1 is submitted, resources are first allocated to task 1, such as Figure 8a As shown, 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, read the data version list of data 1, determine that the data version list of data 1 is empty, generate a version 1 of data 1, initialize the state of version 1 to VERSION_PENDING (dependency not released), and insert it to 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; add version 1 of data 1 to the output data version list of task 1, and the number of data dependencies corresponding to task 1 is 0.
[0187] Task 2 reads data 1. After task 2 is submitted, resources are allocated to task 2. 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, read the data version linked list of data 1, determine that the data version linked list of data 1 is not empty, and read the data version at the end of the data version linked list of data 1, that is, version 1. When it is determined that the status of version 1 is VERSION_PENDING (dependency not released), add one to the number of data dependencies of task 2, that is, establish a data dependency relationship between task 2 and task 1. Add task 2 to the consumer task list of version 1, and at the same time, add version 1 to the input data version list of task 2.
[0188] Task 3 writes data 1. After task 3 is submitted, resources are allocated to task 3 first, such as Figure 8c As shown, 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, read the data version linked list of data 1, determine that the data version linked list of data 1 is not empty, and read the data version at the end of the data version linked list of data 1, that is, version 1. When it is determined that the status of version 1 is not VERSION_CONSUMED (all consumer tasks are executed), add one to the number of data dependencies of task 3, set task 3 as the next producer of version 1, that is, the producer of the next data version of version 1, generate version 2 of data 1 as the next data version of version 1, add version 2 to the output data version list of task 3, and at the same time, initialize the status of version 2 to VERSION_PENDING (dependency not released), and insert it at the end of the data version linked list of data 1.
[0189] Task 4 reads data 1. After task 4 is submitted, resources are allocated to task 4. 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, read the data version linked list of data 1, determine that the data version linked list of data 1 is not empty, and read the data version at the end of the data version linked list of data 1, that is, version 2. When it is determined that the status of version 2 is VERSION_PENDING (dependency not released), increase the number of data dependencies of task 4 by one, that is, establish a data dependency relationship between task 4 and task 3. Add task 4 to the consumer task list of version 2, and at the same time, add version 2 to the input data version list of task 4.
[0190] In passing Figures 7a to 7c After introducing the process of establishing data dependencies between tasks in the task submission process, Figures 9a to 9c Combined with Figure 6 , describes in detail the process of removing data dependencies between tasks in the task completion processing flow in a non-nested task scenario.
[0191] Figure 9a The steps of the task completion process shown include:
[0192] S901: receiving a target task returned by the task execution module 405 that has been executed.
[0193] 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 whose data dependency number is zero and whose status is TASK_READY (data dependency is released and task can be executed) to the task execution module 405 for execution, and returns the task to the dependency management module 403 after the execution is completed.
[0194] S902: Removing data dependencies according to the data version of the input data of the target task.
[0195] 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.
[0196] like Figure 9b As shown, the process of removing data dependencies from input data may include the following steps.
[0197] S902a: For the input data, read the data version of the input data corresponding to the target task.
[0198] Exemplarily, 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.
[0199] S902b: Determine whether the target task is the last consumer task of the data version.
[0200] Exemplarily, the determination of whether the target task is the last consumer task of the data version is used to determine that, except for the target task, no other task performs reading on the input data with the data version. If not, step S902 is executed and ends. If yes, step S902c is executed.
[0201] S902c: Update the status of the data version to VERSION_CONSUMED.
[0202] Exemplarily, since the state of the target task is TASK_DONE (task execution completed), that is, the target task execution is completed, the target task completes reading of the input data, and the state of the data version of the input data can be updated to VERSION_CONSUMED (all consumer tasks are completed).
[0203] S902d: Determine whether the data version has a next producer task.
[0204] Exemplarily, the determination of whether there is a next producer task for the data version is used to determine whether there is a next task to write the input data corresponding to the data version. If there is, 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, that is, to reduce the number of data dependencies of the task by the "consumer-next producer" data dependency relationships between all consumers and the producers of the next data version.
[0205] S902e: The number of data dependencies corresponding to the next producer task is reduced by one.
[0206] Exemplarily, the "consumer-next producer" data dependency relationship between all consumers in the number of data dependencies of the producer task corresponding to the next data version of the data version and the producer of the next data version is released.
[0207] S903: Removing data dependencies according to the data version of the output data of the target task.
[0208] 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.
[0209] like Fig.9c As shown, the process of removing data dependencies from output data may include the following steps.
[0210] S903a: For the output data, read the data version of the output data corresponding to the target task.
[0211] Exemplarily, 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.
[0212] S903b: Determine whether there is a consumer task for the data version.
[0213] Exemplarily, the determination of whether there is a consumer task for the data version is used to determine whether there are other tasks that read the output data with the data version. If yes, step S903c is executed to update the status of the data version to VERSION_PRODUCED; if not, step S902 is terminated. If yes, step S903e is executed to update the status of the data version to VERSION_PRODUCED.
[0214] S903c: Update the status of the data version to VERSION_PRODUCED.
[0215] Exemplarily, since the state of the target task is TASK_DONE (task execution completed), that is, the target task execution is completed, the target task has completed writing the output data, and the state of the data version of the output data can be updated to VERSION_PRODUCED (producer task execution completed).
[0216] S903d: Reduce the number of data dependencies of the consumer task corresponding to the data version by one.
[0217] 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.
[0218] S903e: Update the status of the data version to VERSION_CONSUMED.
[0219] Exemplarily, 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).
[0220] S903f: Determine whether the data version has the next producer task.
[0221] Exemplarily, the determination of whether there is a next producer task for the data version is used to determine whether there is a producer task that writes the output data corresponding to the next data version. If yes, execute step S903g to reduce the number of data dependencies of the task that writes the output data corresponding to the next data version by one, that is, to release the "producer-next producer" dependency between the target task of the data version and the subsequent task of the next data version. Otherwise, the execution ends.
[0222] S903g: The number of data dependencies corresponding to the next producer task is reduced by one.
[0223] For example, the next data version of the output data will only correspond to one producer task, that is, only one producer task can write to one data version of the output data, and the operation of reducing the number of data dependencies corresponding to the next producer task by one is to release the "consumer-next producer" dependency or "producer-next producer" dependency of the next producer. After that, the execution ends.
[0224] 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 task is reduced to zero, the subsequent task is submitted to the task scheduling module 404 .
[0225] Exemplarily, the number of data dependencies corresponding to the target task here can also be expressed as the number of dependencies of the target task, including the sum of the "producer-consumer" data dependency, the "producer-next producer" data dependency, and the "consumer-next producer" data dependency, which can be uniformly expressed by the number of dependencies. When the number of dependencies corresponding to the target task is reduced to zero, and the state of the target task is updated to TASK_DONE (task execution completed), it means that the data dependency between the target task and the subsequent task has been released, and the task scheduling module 404 can execute the subsequent task.
[0226] S905: Reclaim the resources of the completed target task through the resource management module 401.
[0227] 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.
[0228] Combine the following Figures 9a to 9c as well as Figure 6 and Figures 10a to 10d To explain in detail the detailed process of the operating system removing data dependencies between tasks according to the input data and input data corresponding to the tasks in the task completion processing flow.
[0229] like Figure 6 As shown, the application of the operating system submits Task 1, Task 2, Task 3 and Task 4 in sequence through the interface module 402 of the task scheduling architecture 400. The resource management module 401 allocates resources to Task 1, Task 2, Task 3 and Task 4 in sequence, the dependency management module 403 establishes data dependency relationships for Task 1, Task 2, Task 3 and Task 4 in sequence, and the task scheduling module 404 schedules Task 1, Task 2, Task 3 and Task 4 for execution.
[0230] For example, task 1 writes data 1. After task 1 is completed, Fig.10aAs shown, the data version list of data 1 is read, and 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 (producer task execution 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.
[0231] Task 2 reads data 1. After task 2 is completed, continue to refer to Fig.10b , read the input data version list corresponding to task 2 to get version 1. If the last consumer task of version 1 is task, update the status of version 1 to VERSION_CONSUMED (all consumer tasks are completed). The next producer task of version 1 is task 3, and reduce the number of data dependencies of task 3 by one.
[0232] Task 3 and Task 1 write to Data 1. After Task 3 is completed, Fig.10c As shown, read the output data version list corresponding to task 3 to obtain version 2. Version 2 has a consumer task, that is, task 4; update the status of version 2 to VERSION_PRODUCED (producer task execution completed); reduce the number of data dependencies of the consumer task corresponding to version 2 by one, that is, release the "producer-consumer" dependency between task 3 and task 4 corresponding to version 2.
[0233] Task 4 reads data 1. After task 4 is completed, continue to refer to Fig.10d , 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, update the status of version 1 to VERSION_CONSUMED (all consumer tasks are completed).
[0234] Through the above Figures 7a to 7c as well as Figures 9a to 9c Combined with Figure 6 After describing in detail the process of establishing and removing data dependencies between tasks in the task submission process and task completion process in a non-nested task scenario, the following is a Fig.11 and Fig.12 , describes in detail the process of establishing and removing data dependencies between tasks in the task submission process and the task completion process in a nested task scenario.
[0235] like Fig.11As shown, in the nested task scenario, in the task submission process, the process of establishing data dependency for output data may include the following steps:
[0236] S1101: Obtain output data of the target task.
[0237] Exemplarily, if there is a situation where 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 can be understood that the target task here can be a subtask.
[0238] S1102: Determine whether the output data is nested with the parent task of the target task.
[0239] 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 to establish a data dependency relationship for the output data in a non-nested task scenario, that is, execute the following steps: Figure 7c The process of establishing data dependencies on output data is shown.
[0240] S1103: Obtain the data version of the output data corresponding to the parent task of the target task.
[0241] Exemplarily, the parent task of the target task also writes the output data (data_i), and the output data version list of the parent task stores the data version (version_k) of the output data (data_i). It can be 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).
[0242] S1104: Whether there is a previous data version of the output data corresponding to the parent task.
[0243] Exemplarily, whether there is a previous data version here can be whether there is a 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 writes 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 also write to the output data (data_i).
[0244] 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.
[0245] Exemplarily, before the target task writes the output data, the parent task of the target task also writes the output data to generate an updated data version (version_k+1) of the output data, sets the status of the updated 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.
[0246] S1106: The newly generated data version is added to the output data version list of the target task.
[0247] 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.
[0248] S1107: Obtain the previous data version of the output data corresponding to the parent task.
[0249] Exemplarily, the previous data version (version_k-1) here may be a data version that is located 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, a data version previous to the data version (version_k).
[0250] S1108: Determine whether the status of the previous data version is VERSION_CONSUMED.
[0251] For example, if the status of the previous data version (version_k-1) is VERSION_CONSUMED (all consumer tasks are completed), it means that other tasks before the target task have completed reading the output data. Then execute step S1105. Otherwise, execute step S1109, increase the number of data dependencies corresponding to the target task by one, indicating that other tasks have written to the output data, and there is a data dependency relationship between the target task and the other tasks.
[0252] S1109: Increase the number of data dependencies of the target task by one.
[0253] Exemplarily, the number of data dependencies corresponding to the target task is increased by one, indicating that there are other tasks that write or read the input data, and there is a data dependency relationship between the target task and the other tasks.
[0254] S1110: Set the target task as the next producer of the previous data version.
[0255] Exemplarily, the target task may be a task that is a producer, used to represent 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 previous data version (version_k-1) after the data version (version_k) of the original parent task.
[0256] like Fig.12 As shown, in the nested task scenario, in the task completion process, the process of removing data dependencies from output data may include the following steps:
[0257] like Fig.12 As shown, the process of removing data dependencies from output data may include the following steps.
[0258] S1201: For output data, read the data version of the output data corresponding to the target task.
[0259] Exemplarily, the data version (version_i) of the output data here may be a data version generated when the target task writes the output data. 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.
[0260] S1202: Determine whether there is a previous data version or whether the status of the previous data version is VERSION_CONSUMED.
[0261] 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 nested writes or reads the output data of the target task (parent task) and the target task is completed but the subtask is not completed, the previous data version (version_k) status will not be 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, if Fig.9c The process of removing data dependencies from output data is shown.
[0262] S1203: Get the previous data version.
[0263] Exemplarily, the previous data version here may be a data version (version_k) before the data version (version_i) of the output data.
[0264] S1204: Determine whether there is a consumer task for the data version of the output data.
[0265] Exemplarily, if the data version (version_i) of the output data of the target task exists 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 a next producer task.
[0266] 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.
[0267] Exemplarily, the consumer of the target task (parent task) is added to the consumer task list of the subtask.
[0268] 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.
[0269] Exemplarily, here 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), it is also necessary to replace the data version (version_i) of the output data corresponding to the target task with the previous data version (version_k).
[0270] S1207: Determine whether the status of the previous data version is VERSION_PRODUCED.
[0271] Exemplarily, 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.
[0272] S1208: The number of data dependencies of the consumer task corresponding to the data version of the target task is reduced by one
[0273] Exemplarily, 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, the accuracy of the subsequent tasks will not be affected.
[0274] S1209: Determine whether the data version of the output data corresponding to the target task exists in the next producer task.
[0275] Exemplarily, the determination here whether there is a next producer task for the data version (version_i) of the output data corresponding to the target task is used to determine whether there is a producer task that writes the output data corresponding to the next data version of the data version (version_i). If there is, 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, that is, the next producer of the completed target task (parent task) is converted to the child task of the uncompleted target task.
[0276] S1210: The next producer of the previous data version is replaced by the next producer of the data version of the output data.
[0277] Exemplarily, the next producer of the completed target task (parent task) is switched to the child task of the uncompleted target task.
[0278] Combine the following Fig.11 as well as Figures 13a to 13d First, the detailed process of establishing data dependencies between tasks based on the input data and output data corresponding to the tasks in the task submission processing flow is introduced.
[0279] For example, task 1 writes data 1 and data 2. After task 1 is submitted, Fig.13a As shown, the data structure of task 1 may include: the 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, version 2.1. The status of version 1.1 and version 2.1 is VERSION_PENDING (dependency not released).
[0280] During the execution of Task 1, Task 1.1 is submitted. Task 1.1 writes data 1. Fig.13b, the function corresponding to task 1.1, such as: function 1.1; the input data version list corresponding to task 1.1 can be empty, and the output data version list can include: version 1.01. For data 1, version 1.01 is before version 1.1, and the status of version 1.01 is VERSION_PENDING (dependency not released).
[0281] Task 2 reads data 1. After task 2 is submitted, refer to Fig.13c , the data structure of task 2 may include: the function corresponding to task 2, such as: function 4. After determining that data 1 is the input data of task 2, read the data version list of data 1, determine that the data version list of data 1 is not empty, and read the data version at the end of the data version list of data 1, that is, version 1.1. When it is determined that the status of version 1.1 is VERSION_PENDING (dependency not released), increase the number of data dependencies of task 2 by one, add task 2 to the consumer task list of version 1.1, and at the same time, add version 1.1 to the input data version list of task 2.
[0282] Task 3 reads data 2. After task 3 is submitted, resources are allocated to task 3. Fig.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, read the data version list of data 2, determine that the data version list of data 2 is not empty, and read the data version at the end of the data version list of data 2, that is, version 2.1. When it is determined that the status of version 2.1 is VERSION_PENDING (dependency not released), increase the number of data dependencies of task 3 by one, add task 3 to the consumer task list of version 2.1, and at the same time, add version 2.1 to the input data version list of task 3.
[0283] Combine the following Fig.12 as well as Figures 14a to 14d First, 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 is introduced.
[0284] For example, after task 1 is completed, Fig.14aAs shown, 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, that is, version 1.01, and the status of version 1.01 is VERSION_PENDING (dependency has not been released) and the status of version 1.1 is VERSION_PRODUCED (producer task execution is completed), and version 1.01 is obtained. Version 1.1 has a consumer task, that is, 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, that is, task 3; the status of version 2.1 is updated to VERSION_PRODUCED (producer task execution is completed); the number of data dependencies of the consumer task corresponding to version 2.1, that is, task 3, is reduced by one.
[0285] Task 3 reads data 2. After task 3 is completed, continue to refer to Fig.14b , read the input data version list corresponding to task 3 to obtain version 2.1. If the last consumer task of version 2.1 is task 3, update the status of version 2.1 to VERSION_CONSUMED (all consumer tasks are completed).
[0286] Task 1.1 writes data 1. After task 1.1 is completed, Fig.14c As shown, the output data version list corresponding to task 1.1 is read to obtain version 1.01. Version 1.01 has a consumer task, namely, task 2; the status of version 1.01 is updated to VERSION_PRODUCED (producer task execution completed); the number of data dependencies of the consumer task corresponding to version 1.01, namely, task 2, is reduced by one, that is, the "producer-consumer" dependency between task 1.1 and task 2 corresponding to version 1.01 is released.
[0287] Task 2 reads data 1. After task 2 is completed, continue to refer to Fig.14d , read the input data version list corresponding to task 2 to obtain version 1.01. If the last consumer task of version 1.01 is task 2, update the status of version 1.01 to VERSION_CONSUMED (all consumer tasks are completed).
[0288] It can be seen that in the task scheduling method provided in the embodiment of the present application, for the nested task scenario, when establishing data dependency for output data, if the subtask and the parent task are nested and use the same output data, then in the data version 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 releasing the data dependency for the output data, if the subtask is not completed when the parent task is completed, the related dependency of the data version of the parent task will be converted to the data version of the subtask, thereby ensuring that the parent task can exit ahead of the subtask and the data dependency remains correct.
[0289] Through the above Fig.11 and 12 The process of establishing and removing data dependencies between tasks in the task submission process and task completion process in the nested task scenario is described in detail. It can be seen that Fig.11 and 12 This is a solution for handling data dependencies in nested task scenarios. Fig.15 and Fig.16 This paper introduces another solution for handling data dependencies in nested task scenarios.
[0290] 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 for 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.
[0291] 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 according to the scope information, and the second-level linked list is stored in the order of the data version. 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.
[0292] like Fig.15 As shown, in the nested task scenario, in the task submission process, the process of establishing data dependency on output data based on the task scope may include the following steps:
[0293] S1501: For the output data of the target task, obtain a data version linked list corresponding to the output data.
[0294] Exemplarily, if there is a situation where the target task (scope scope_j) writes data, the data written by the target task is used as the output data (data_i) to establish a data dependency. The data version linked list here may include a first-level linked list and a second-level linked list, wherein the first-level linked list is used to store scope information, and the second-level linked list is used to store data versions.
[0295] S1502: Determine whether there is a scope for the first-level linked list.
[0296] 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.
[0297] , then execute step S1503, add the scope (scope_j) of the target task to the first-level linked list of the output data, and add a second-level linked list to the scope (scope_j) to store the data version of the output data. Otherwise, execute step S1504, directly obtain the second-level linked list corresponding to the scope (scope_j) of the target task.
[0298] S1503: Create a second-level linked list for the output data based on the scope of the target task.
[0299] Exemplarily, the second-level linked list here is used to store data versions of output data.
[0300] S1504: Obtain the second-level linked list corresponding to the scope of the target task.
[0301] Exemplarily, 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 may belong to different scopes.
[0302] S1505: Determine whether the second-level linked list is empty.
[0303] Exemplarily, 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).
[0304] S1506: Generate a data version of the output data, initialize the state of the data version to VERSION_PENDING, and insert it at the end of the second-level linked list.
[0305] 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).
[0306] S1507: The newly generated data version is added to the output data version list of the target task.
[0307] Exemplarily, 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.
[0308] S1508: Determine whether the status of the data version at the end of the second-level linked list is VERSION_CONSUMED.
[0309] For example, if the current data version of the output data is VERSION_CONSUMED (all consumer tasks are completed), indicating that the target task or other tasks have completed reading the output data, then step S1506 is executed, and 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, and the number of data dependencies corresponding to the target task is increased by one, indicating that other tasks are writing to the output data, and there is a data dependency relationship between the target task and the other tasks.
[0310] S1509: Increase the number of data dependencies of the target task by one.
[0311] Exemplarily, the number of data dependencies corresponding to the target task is increased by one, indicating that there are other tasks that write or read the input data, and there is a data dependency relationship between the target task and the other tasks.
[0312] S1510: Set the target task as the next producer of the data version at the end of the second-level linked list.
[0313] Exemplarily, the target task may be a task that serves as a producer, which indicates the producer of the next data version instead of the producer of the current data version. Then, step S1506 is performed 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.
[0314] like Fig.16 As shown, in the nested task scenario, in the task completion process, the process of removing data dependencies from output data based on the scope may include the following steps:
[0315] S1601: Obtain output data of a target task and a data version of the output data.
[0316] For example, if the target task writes data, the data written by the target task is used as 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 a parent task.
[0317] S1602: Determine whether the output data is nested with the subtask of the target task.
[0318] 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 relationship of the output data in a non-nested task scenario can be executed, that is, otherwise, step S1602-1 is executed, such as Fig.9c The process of removing data dependencies from output data is shown.
[0319] S1603: According to the scope of the subtask of the target task, search for the corresponding second-level linked list.
[0320] Exemplarily, the second-level linked list here is used to store the data version of the output data corresponding to the subtask.
[0321] 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.
[0322] 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 completed, and the status of the data version (version_k) is not equal to VERSION_CONSUMED, when 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, execute step S1605, and it is necessary to perform data dependency conversion between the target task (parent task) and the subtask; otherwise, execute S1602-1, such as Fig.9c The process of removing data dependencies from output data is shown.
[0323] S1605: Obtain the data version at the end of the second-level linked list.
[0324] Exemplarily, the data version (version_k) at the end of the second-level linked list is obtained.
[0325] S1606: Determine whether there is a consumer task for the data version of the output data.
[0326] Exemplarily, if the data version (version_i) of the output data of the target task exists 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 a next producer task.
[0327] S1607: In the consumer task list of the previous data version, add all consumer tasks of the data version of the output data corresponding to the target task.
[0328] 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.
[0329] 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.
[0330] Exemplarily, here 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), it is also necessary to replace the data version (version_i) of the output data corresponding to the target task with the previous data version (version_k).
[0331] S1609: Determine whether the status of the previous data version is VERSION_PRODUCED.
[0332] Exemplarily, 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.
[0333] S1610: The number of data dependencies of the consumer task corresponding to the data version of the target task is reduced by one.
[0334] Exemplarily, 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, the accuracy of the subsequent tasks will not be affected.
[0335] S1611: Determine whether the data version of the output data corresponding to the target task exists in the next producer task.
[0336] Exemplarily, the determination here whether there is a next producer task for the data version (version_i) of the output data corresponding to the target task is used to determine whether there is a producer task that writes the output data corresponding to the next data version of the data version (version_i). If yes, execute step S1612 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, that is, convert the next producer of the completed target task (parent task) to the child task of the uncompleted target task; otherwise, the execution ends.
[0337] S1612: The next producer of the previous data version is replaced by the next producer of the data version of the output data.
[0338] Exemplarily, the next producer of the completed target task (parent task) is converted to the child task of the uncompleted target task. After that, the execution ends.
[0339] 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, so they do not interfere with each other in the process of establishing the data dependency relationship. When the data dependency relationship for the output data is released, the second-level linked list of the subtask can be found according to the scope of the subtask. If the subtask is not completed when the parent task is completed, the relevant dependency of the data version of the parent task will be converted to the data version of the subtask, thereby ensuring that the parent task can exit ahead of the subtask and the data dependency relationship remains correct.
[0340] Combine the following Fig.15 as well as Figures 17a to 17d To explain in detail the detailed process of establishing data dependencies between tasks based on the input data and output data corresponding to the tasks in the task submission processing flow in the nested task scenario.
[0341] For example, task 1 writes data 1 and data 2. After task 1 is submitted, the output data corresponding to task 1 may be data 1 and data 2. Fig.17aAs shown, 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 for the respective scopes of data 1 and data 2. Add version 1.1 and version 2.1 to the output data version list of task 1.
[0342] During the execution of Task 1, Task 1.1 is submitted. Task 1.1 writes to Data 1. The output data corresponding to Task 1.1 can be Data 1. Fig.17b , the function corresponding to task 1.1, such as: 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), and the scope of inserting data 1 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.
[0343] Task 2 reads data 1. After task 2 is submitted, refer to Fig.17c , the data structure of task 2 may include: the function corresponding to task 2, such as: function 2. After determining that data 1 is the input data of task 2, read the data version list of data 1, determine that the data version list of data 1 is not empty, and read the data version at the end of the data version list of data 1, that is, version 1.1. When it is determined that the status of version 1.1 is VERSION_PENDING (dependency not released), increase the number of data dependencies of task 2 by one, add task 2 to the consumer task list of version 1.1, and at the same time, add version 1.1 to the input data version list of task 2.
[0344] Task 3 reads data 2. After task 3 is submitted, resources are allocated to task 3. Fig.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, read the data version list of data 2, determine that the data version list of data 2 is not empty, and read the data version at the end of the data version list of data 2, that is, version 2.1. When it is determined that the status of version 2.1 is VERSION_PENDING (dependency not released), increase the number of data dependencies of task 3 by one, add task 3 to the consumer task list of version 2.1, and at the same time, add version 2.1 to the input data version list of task 3.
[0345] Combine the following Fig.16 as well as Figures 18a to 18d First, 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 is introduced.
[0346] For example, after task 1 is completed, Fig.18a As shown, 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, that is, task 1.1, are nested. According to the scope of task 1.1, the state 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, that is, 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.
[0347] For data 2, continue to refer to Fig.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. 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.
[0348] Task 3 reads data 2. After task 3 is completed, continue to refer to Fig.18b , read the input data version list corresponding to task 3 to obtain version 2.1. If the last consumer task of version 2.1 is task 3, update the status of version 2.1 to VERSION_CONSUMED (all consumer tasks are completed).
[0349] Task 1.1 Task 1 writes data 1. After Task 1.1 is completed, Fig.18c As shown, the output data version list corresponding to task 1.1 is read to obtain version 1.01. Version 1.01 has a consumer task, namely, task 2; the status of version 1.01 is updated to VERSION_PRODUCED (producer task execution completed); the number of data dependencies of the consumer task corresponding to version 1.01, namely, task 2, is reduced by one, that is, the "producer-consumer" dependency between task 1.1 and task 2 corresponding to version 1.01 is released.
[0350] Task 2 reads data 1. After task 2 is completed, continue to refer to Fig.14d , read the input data version list corresponding to task 2 to obtain version 1.01. If the last consumer task of version 1.01 is task 2, update the status of version 1.01 to VERSION_CONSUMED (all consumer tasks are completed).
[0351] The task scheduling method provided in the embodiment of the present application can be applied to an electronic device installed with an operating system. The electronic device 100 involved in implementing the method provided in the embodiment of the present application is introduced below. The electronic device 100 can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA) and other terminal devices installed with an operating system. The embodiment of the present application does not impose any restrictions on the specific type of the electronic device.
[0352] Fig.19 1 is a schematic diagram of the structure of an electronic device 100 provided in an embodiment of the present application. Fig.19As shown, 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 screen 194, and a subscriber identification module (SIM) card interface 195, etc.
[0353] Among them, the above-mentioned sensor module 180 may include sensors such as a pressure sensor, a gyroscope sensor, an air pressure sensor, a magnetic sensor, an acceleration sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a temperature sensor, a touch sensor and an ambient light sensor.
[0354] It is to 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 in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0355] The processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural-network processing unit (neural-network processing unit, NPU), etc. Among them, different processing units can be independent devices or integrated in 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.
[0356] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0357] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0358] It is understandable that the interface connection relationship between the modules illustrated in this embodiment is only a schematic illustration and does not constitute a structural limitation of the electronic device. In other embodiments, the electronic device may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0359] The electronic device implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0360] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel.
[0361] The electronic device can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor. ISP is used to process the data fed back by camera 193. Camera 193 is used to capture static images or videos. In some embodiments, the electronic device may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0362] 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 through the external memory interface 120 to implement a data storage function. For example, files such as music and videos can be stored in the external memory card.
[0363] The internal memory 121 may be used to store computer executable program codes, which include 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 may execute the instructions stored in the internal memory 121, and the internal memory 121 may include a program storage area and a data storage area.
[0364] The program storage area may store an operating system, an application required for at least one 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.
[0365] It is to be understood that the structure illustrated in the embodiments of the present application does not constitute a specific limitation on the electronic device. In other embodiments of the present application, the electronic device may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0366] In the description of the embodiments of the present application, unless otherwise specified, “ / ” means or. For example, A / B can mean A or B. The “and / or” in the text is merely a description of the association relationship between 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.
[0367] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features, and in the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
[0368] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described in this application may be combined with other embodiments.
[0369] It should be understood that although the terms "first", "second", etc. may be used herein to describe various features, these features should not be limited by these terms. These terms are used only 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.
[0370] In addition, 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 interpreted as implying that these operations must rely on the order of description, and many of the operations can be implemented in parallel, concurrently, or simultaneously. In addition, the order of the operations can also be rearranged. When the described operations are completed, the process can be terminated, but there can also be additional operations not included in the drawings. The process can correspond to a method, function, procedure, subroutine, subprogram, etc.
[0371] 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 each embodiment may or may not necessarily include the particular feature, structure, or property. Moreover, these phrases are not necessarily directed to the same embodiment. In addition, when particular features are described in conjunction with a specific embodiment, the knowledge of those skilled in the art can affect the combination of these features with other embodiments, whether or not these embodiments are explicitly described.
[0372] 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)."
[0373] As used herein, the term "module" may refer to, be part of, or include: a memory (shared, dedicated, or group) for running one or more software or firmware programs, an application-specific integrated circuit (ASIC), an electronic circuit and / or processor (shared, dedicated, or group), a combinational logic circuit, and / or other suitable components that provide the described functionality.
[0374] In the accompanying drawings, some structural or method features may be shown in a specific arrangement and / or order. However, it should be understood that such a specific arrangement and / or order is not required. Instead, in some embodiments, these features may be described in a manner and / or order different from that shown in the illustrative drawings. In addition, the structural or method features included in a specific figure do not mean that all embodiments need to include such features. In some embodiments, these features may not be included, or these features may be combined with other features.
[0375] The embodiments of the present application are described in detail above in conjunction with the accompanying drawings, but the use 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 the field without departing from the purpose of the present application should all fall within the scope 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 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 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
Cited By
Electronic device, task scheduling method therefor, and medium
EP4629073A1
Electronic device, task scheduling method therefor, and medium
WO2024179147A1
