Task processing method, device, electronic device and storage medium
By converting driver tasks into driver task flow and using flow task queues and driver distribution methods, the problem of heavy overhead in parallel computing scheduling in a multi-threaded environment is solved, and more efficient task scheduling and scalability are achieved.
Patent Information
- Application Number
- CN202111051998.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-08
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2041-09-08
AI Technical Summary
In the multi-threaded environment, the operating system scheduling overhead is too high due to too many threads, and the process of adding computing units to improve scheduling capabilities is cumbersome and has poor scalability.
By converting driver tasks into driver task flow, scheduling between multiple threads into scheduling between streams, scheduling between drive task flows is achieved using stream task queues and driver distribution, reducing system scheduling overhead, and expanding by configuring stream task queues and drivers.
The system scheduling overhead for direct scheduling between multiple threads is reduced, and the efficiency and scalability of task scheduling are improved.
Smart Images

Figure CN113934520B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a task processing method, device, electronic equipment and storage medium. Background Art
[0002] With the development of computer technology, parallel computing is usually used to improve the computing speed in solving large amounts of data calculations. Parallel computing requires the use of multiple computing resources to solve computing problems. The computing resources include hardware acceleration units, neural network computing units, CPU units, DSP units, etc. The current parallel computing scheduling is mainly scheduled by multi-threading and inter-thread message queues. However, due to too many threads, parallel computing scheduling will cause excessive operating system scheduling overhead. If computing units are added to improve the operating system scheduling capability, due to the high dependence between software and hardware, the process of adding computing units is cumbersome and requires various complex configurations, making expansion difficult. Therefore, in the prior art, the scheduling efficiency of multi-threaded computing resources is low and the scalability is poor. Summary of the invention
[0003] The embodiment of the present invention provides a task processing method, which converts the drive task into a drive task flow, so that the scheduling between multiple threads is converted into the scheduling between flows, and the scheduling between the drive task flows is realized by using the flow task queue and the drive distribution. Due to the scheduling by the flow task queue, the system scheduling overhead is reduced compared with the direct scheduling between multiple threads. In addition, the application layer and the driver layer are decoupled by the flow task queue, and the expansion can be carried out by configuring the flow task queue and the driver.
[0004] In a first aspect, an embodiment of the present invention provides a task processing method, the method comprising:
[0005] Obtaining pending tasks from the application layer, wherein the pending tasks include control tasks and drive request tasks;
[0006] Based on the control task, convert the drive request task into a drive task flow and add it to a flow task queue;
[0007] Based on the driving response task returned by the driving layer, driving distribution is performed on the driving task flow in the flow task queue;
[0008] The driver task flow is processed by matching the distributed drivers from the driver layer.
[0009] Optionally, the method further includes:
[0010] In the initialization phase, the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status are obtained for each driver;
[0011] Register the driver according to the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status to obtain driver information;
[0012] The driving information is stored in a driving information table, and the driving information in the driving information table is updated in real time according to the driving load query function, the driving processing function, and the application and release functions of the driving task completion status.
[0013] Optionally, based on the control task, converting the drive request task into a drive task flow and adding the flow task flow to a flow task queue includes:
[0014] Based on the control task, when creating a stream task queue, determining whether the number of stream task queues to be created exceeds a first number threshold;
[0015] If the number of the to-be-created stream task queues does not exceed the first number threshold, creating a new stream task queue;
[0016] The drive request task is forcibly converted into a drive task flow according to a preset conversion rule, and is added to the new flow task queue according to a first-in-first-out rule.
[0017] Optionally, the method further includes:
[0018] Based on the control task, when destroying the stream task queue, it is determined whether there is an unfinished driving task flow in the stream task queue to be destroyed;
[0019] If there is an unfinished driving task flow in the stream task queue to be destroyed, and / or if the number of the stream task queue to be created exceeds the first number threshold, returning first failure information to the application layer;
[0020] Based on the control task, determining whether the number of driving task flows in the flow task queue exceeds a second number threshold;
[0021] If the number of driving task flows in the flow task queue exceeds a second number threshold, the task of the application layer is blocked and second failure information is returned to the application layer.
[0022] Optionally, the driving response task returned by the driver layer, driving and distributing the driving task flow in the flow task queue, includes:
[0023] Taking out the driving task flow from the flow task queue;
[0024] According to the driving response task returned by the driving layer, the driving load query function and the application and release functions of the driving task completion status are called to return the driving status of the driver required by the driving task flow;
[0025] If the driving state is available, the driving task flow is marked as entering a state of waiting for driving completion, and when the driving state is returned to executable, the driving task flow is switched to an executable state;
[0026] If the driving state is unavailable, marking the driving task flow as entering a state of waiting for driving resources to be available;
[0027] The drive task flow waiting for the available drive resources is traversed in real time, and the drive load query function is called to query the load status of the corresponding drive. If the load status meets the preset executable conditions, the corresponding drive task flow waiting for the available drive resources is switched to the executable state.
[0028] Optionally, matching the distributed driver from the driver layer to process the stream includes:
[0029] Matching the executable driver required to execute the driver task flow in the executable state in the driver layer;
[0030] The driver processing function is called to forward the driver task flow in the executable state to the executable driver for processing.
[0031] Optionally, the method further includes:
[0032] The acquired tasks to be processed are retained in a preset task queue;
[0033] Determine whether the driving task flow corresponding to the task to be processed has completed processing;
[0034] If the driving task flow is processed, the pending task is released from the preset task queue;
[0035] If the driving task flow has not completed processing, the pending tasks will continue to be retained in the preset task queue.
[0036] In a second aspect, an embodiment of the present invention provides a task processing device, the device comprising:
[0037] A first acquisition module, used for acquiring tasks to be processed from the application layer, wherein the tasks to be processed include control tasks and drive request tasks;
[0038] A conversion module, used for converting the drive request task into a drive task flow based on the control task, and adding the drive task flow into a flow task queue;
[0039] A driver distribution module, used for performing driver distribution on the driver task flow in the flow task queue based on the driver response task returned by the driver layer;
[0040] The matching module is used to match the distributed drivers from the driver layer to process the driver task flow.
[0041] In a third aspect, an embodiment of the present invention provides a task processing system, the system comprising: an application layer, a stream scheduling layer and a driver layer, wherein the application layer is used to generate tasks to be processed and receive task processing results, the driver layer is used to provide a driver to calculate the tasks to be processed and return a driver response task, and the stream scheduling layer is used to implement the steps in the task processing method provided in an embodiment of the present invention.
[0042] In a fourth aspect, an embodiment of the present invention provides an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the task processing method provided in the embodiment of the present invention when executing the computer program.
[0043] In a fifth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the task processing method provided in the embodiment of the invention are implemented.
[0044] In an embodiment of the present invention, a task to be processed is obtained from the application layer, and the task to be processed includes a control task, a drive request task, and a drive response task; based on the control task, the drive request task is converted into a drive task flow and added to a flow task queue; based on the drive response task, the drive task flow in the flow task queue is driven and distributed; and the drive task flow is processed by matching the distributed driver from the driver layer. By converting the drive request task into a drive task flow, the scheduling between multiple threads is converted into scheduling between flows, and the scheduling between drive task flows is realized by using the flow task queue and drive distribution. Due to the scheduling through the flow task queue, the system scheduling overhead is reduced compared to the direct scheduling between multiple threads. In addition, the application layer and the driver layer are decoupled by the flow task queue, and can be expanded by configuring the flow task queue and the driver. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0046] Figure 1 is an architecture diagram of a task processing system provided by an embodiment of the present invention;
[0047] Figure 2 is a state diagram of flow scheduling provided by an embodiment of the present invention;
[0048] Figure 3 is a flowchart of a task processing method provided by an embodiment of the present invention;
[0049] Figure 4 is a structural schematic diagram of a task processing device provided by an embodiment of the present invention;
[0050] Figure 5 is a structural schematic diagram of another task processing device provided by an embodiment of the present invention;
[0051] Figure 6 is a structural schematic diagram of a conversion module provided by an embodiment of the present invention;
[0052] Figure 7 is a structural schematic diagram of another task processing device provided by an embodiment of the present invention;
[0053] Figure 8 is a structural diagram of a drive distribution module provided by an embodiment of the present invention;
[0054] Fig. 9 is a structural schematic diagram of a matching module provided by an embodiment of the present invention;
[0055] Fig.10 is a structural schematic diagram of another task processing device provided by an embodiment of the present invention;
[0056] Fig.11 It is a structural schematic diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0057] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0058] See also Figure 1 , Figure 1 is an architecture diagram of a task processing system provided by an embodiment of the present invention, such as Figure 1As shown, the task processing system includes: an application layer, a stream scheduling layer and a driver layer, wherein the application layer includes one or more application threads, the stream scheduling layer includes one or more stream scheduling threads, and the driver layer includes multiple drivers.
[0059] In an embodiment of the present invention, the application layer is used to generate tasks to be processed and receive task processing results, and the driver layer is used to provide a driver to calculate the tasks to be processed and return a driver response task. The stream scheduling layer is used to obtain tasks to be processed from the application layer, and the tasks to be processed include control tasks and driver request tasks; based on the control tasks, the driver request tasks are converted into driver task flows and added to the flow task queue; based on the driver response tasks, the driver task flows in the flow task queue are driven and distributed; and the driver task flows are processed by matching the distributed drivers from the driver layer. It should be noted that the driver request tasks can also be called driver tasks.
[0060] Specifically, the stream scheduling thread includes a pending task queue, a task distribution unit, a stream control management unit, a stream task queue, a stream scheduling unit, a driver distribution unit, a driver information storage unit, and a driver information registration unit. The driver information storage unit may be in the form of a driver information table.
[0061] Among them, the input of the above-mentioned pending task queue is connected to the output of the above-mentioned application thread, and the input of the above-mentioned pending task queue is connected to the output of the above-mentioned driver layer for returning the driver response task. The pending task queue stores the pending tasks generated by the application thread and the driver response tasks according to the first-in-first-out rule. The input of the above-mentioned task distribution unit is connected to the output of the above-mentioned pending task queue. The above-mentioned task distribution unit is used to distribute the pending tasks to the flow control management unit, the flow task queue and the flow scheduling unit. The output of the above-mentioned flow scheduling unit is connected to the input of the driver distribution unit. The above-mentioned driver distribution unit is used to query the information in the driver storage unit, and the output of the above-mentioned driver distribution unit is connected to the input of the above-mentioned driver layer. The above-mentioned driver information registration unit is used to register the drivers in the driver layer and store the registration information of each driver in the above-mentioned driver storage unit.
[0062] Furthermore, the task distribution unit issues tasks according to the task types in the pending task queue, and the task types in the pending task queue include pending task types and drive response task types, wherein the pending task types can be divided into control tasks and drive request tasks. Specifically, the task distribution unit distributes control tasks to the flow control management unit, distributes drive request tasks to the flow task queue, and distributes drive response tasks to the flow scheduling unit.
[0063] The control tasks are mainly flow creation and destruction commands, and the control tasks are forwarded by the task distribution unit to the flow control management unit for processing. Furthermore, the flow control management unit creates and destroys flows according to the control tasks.
[0064] Optionally, the flow control management unit can detect the maximum number of flows when creating flows. If the maximum number of created flow task queues exceeds a preset creation number threshold, a failure is returned to the application layer. The flow control management unit can detect whether there are any unfinished driver task flows when destroying flow task queues. If there are any unfinished driver task flows, a failure is returned to the application layer. At the same time, the flow control management unit can also detect in real time whether the number of driver task flows in the flow task queue exceeds a preset task number threshold. If so, the upper-layer flow control can be triggered to block the application line layer of the application layer.
[0065] The above-mentioned driver request tasks are mainly tasks that upper-level users request the driver to process and calculate through the stream scheduling unit. According to the stream where the task is located, it is written to the tail of the corresponding stream in the stream task queue to obtain a first-in-first-out stream.
[0066] Optionally, the flow scheduling unit triggers the flow task scheduling after receiving the drive request task and the drive response task. The flow scheduling unit can be implemented by a state machine. Specifically, the state machine schedules the flow in the flow scheduling process to include an executable state, a waiting drive completion state, and a waiting drive resource availability state.
[0067] The above-mentioned driving response task is mainly to send the driving task completion status auxiliary information to the flow scheduling unit after the driving is completed, and the flow scheduling unit triggers the driving request task processing of the subsequent flow.
[0068] The driver distribution unit receives the driver request task from the stream scheduling unit, parses the driver id of the driver request task, and searches for matching driver registration information in the driver storage unit according to the driver id.
[0069] In a possible embodiment, the above-mentioned stream scheduling thread is one, which can be understood as the above-mentioned stream scheduling is implemented by an independent thread. The above-mentioned application thread and the driver thread are decoupled through the above-mentioned independent stream scheduling thread, so that the above-mentioned task processing system of the embodiment of the present invention can be expanded by configuring the stream task queue and the driver.
[0070] Furthermore, when using independent threads to implement stream scheduling, a preset number of stream task queues can be scheduled in parallel. For example, 1024 stream task queues can be scheduled in parallel. Any time-consuming internal processing will seriously affect the scheduling efficiency. The stream scheduling thread can prohibit the execution of any other computing tasks. The driver layer can be designed as a driver thread. The general driver processing function (also called the driver task processing function) registered in the driver_register_table (driver information storage unit) will forward the driver request task in the stream scheduling to the driver thread for processing.
[0071] Optional, see Figure 2 , Figure 2 is a state diagram of a flow scheduling provided by an embodiment of the present invention, such as Figure 2 As shown, when the above-mentioned stream scheduling unit is performing scheduling processing, the driving task stream can be taken out from the head of the stream task queue and handed over to the above-mentioned driving distribution unit for processing. The above-mentioned driving distribution unit receives the driving task stream of the stream scheduling unit, parses the driving ID of the driving request task, searches for matching driving registration information in the driving storage unit according to the driving ID, and calls the driving load query function through the above-mentioned driving distribution unit to query the load status of the driving corresponding to the driving ID.
[0072] If the load of the driver corresponding to the driver ID is high, it means that the driver corresponding to the driver ID is in a busy state, and the driver state is returned to the above-mentioned flow scheduling unit as unavailable (failed), and the above-mentioned flow scheduling unit marks the driver task flow as waiting for the driver resource to be available; if the load of the driver corresponding to the driver ID is low, it means that the driver corresponding to the driver ID is in an available state, and the driver state is returned to the above-mentioned flow scheduling unit as available, and the above-mentioned flow scheduling unit marks the driver task flow as waiting for the driver to be completed, and records the auxiliary information of the driver task completion state that the driver task flow is waiting for (the driver state is executable), if the auxiliary information of the driver task completion state is received, the driver task flow waiting for the auxiliary information of the driver task completion state is found, and the state of the driver task flow is switched to the executable state; further, all driver task flows waiting for the driver resource to be available can be traversed, and according to the driver ID waiting for the resource, the driver load query function is called by the driver distribution unit to query the load state of the driver corresponding to the driver ID, if the driver load is low, then the driver task flow state is switched from the waiting for the driver resource to be available state to the executable state.
[0073] The driver distribution unit may allocate driver task completion status auxiliary information resources to the driver task flow, and call the driver processing function to control the driver to process the driver task flow.
[0074] In the embodiment of the present invention, the task processing system converts the driver request task into the driver task flow, so that the scheduling between multiple threads is converted into the scheduling between flows, and the scheduling between driver task flows is realized by using the flow task queue and the driver distribution. Due to the scheduling by the flow task queue, the system scheduling overhead is reduced compared with the direct scheduling between multiple threads. In addition, the application layer and the driver layer are decoupled by the flow task queue, and the expansion can be carried out by configuring the flow task queue and the driver.
[0075] See also Figure 3 , Figure 3 is a flowchart of a task processing method provided by an embodiment of the present invention. The task processing method can be applied to the above Figure 1 The task processing system of the embodiment, such as Figure 3 As shown, the task processing method includes the following steps:
[0076] 301. Obtain pending tasks from the application layer.
[0077] In an embodiment of the present invention, the tasks to be processed may be tasks that require parallel computing, and the tasks to be processed include control tasks and drive request tasks.
[0078] The above-mentioned application layer includes one or more application threads, and the above-mentioned application threads generate corresponding tasks to be processed through user interaction. The above-mentioned control tasks are mainly the creation and destruction commands of the driving task flow, and the control tasks are forwarded by the above-mentioned task distribution unit to the flow control management unit for processing. The above-mentioned drive request tasks are mainly the tasks that the upper-level users request the drive to process and calculate through the flow scheduling unit. According to the flow task queue where the drive request task is located, the drive task flow is written to the tail of the corresponding flow task queue to obtain a first-in-first-out flow. The above-mentioned drive response task is mainly generated by the drive task completion status auxiliary information after the drive is completed. According to the drive response task, the flow scheduling unit can trigger the drive request task processing of the subsequent flow.
[0079] Furthermore, the above-mentioned driver request task includes the driver ID corresponding to the task, the above-mentioned stream scheduling layer includes one or more stream scheduling threads, the above-mentioned driver layer includes multiple driver threads (driver threads can also be called drivers), and the above-mentioned driver request task is transmitted between the application thread, the stream scheduling thread and the driver thread in the form of stream data.
[0080] 302. Based on the control task, convert the drive request task into a drive task flow and add it to the flow task queue.
[0081] In an embodiment of the present invention, the above-mentioned control task is processed by the above-mentioned stream scheduling layer, and the above-mentioned stream scheduling layer creates and destroys the driving task flow through the above-mentioned control task, and converts the above-mentioned driving request task into the driving task flow; the above-mentioned driving request task is converted into the driving task flow by forced conversion, thereby converting the data format of the application thread into the stream data format to obtain the above-mentioned driving task flow.
[0082] Furthermore, based on the above-mentioned control task, when creating a flow task queue, it can be determined whether the number of flow task queues to be created exceeds the first number threshold; if the number of flow task queues to be created does not exceed the first number threshold, a new flow task queue is created; the above-mentioned driving request task is forcibly converted into a driving task flow according to a preset conversion rule, and is added to the above-mentioned new flow task queue according to the first-in-first-out rule.
[0083] Furthermore, based on the above-mentioned control task, when destroying the flow task queue, it can be determined whether there are any unfinished driver task flows in the flow task queue to be destroyed; if there are any unfinished driver request task flows in the flow task queue to be destroyed, and / or if the number of the flow task queues to be created exceeds the above-mentioned first quantity threshold, a first failure message is returned to the application layer; based on the above-mentioned control task, it is determined whether the number of driver task flows in the above-mentioned flow task queue exceeds the second quantity threshold; if the number of driver task flows in the above-mentioned flow task queue exceeds the second quantity threshold, the task of the above-mentioned application layer is blocked, and a second failure message is returned to the application layer.
[0084] Specifically, when there is an unfinished driver request task flow in the stream task queue to be destroyed, it means that the previous task has not been executed and needs to continue to be executed; if the number of the stream task queues to be created exceeds the first number threshold, it means that the parallel stream task queues in the stream scheduling layer have reached the load limit.
[0085] The first failure information includes creation failure information and destruction failure information. The creation failure information can be used to prompt the user that the stream task queue creation failed, and the destruction failure information can be used to prompt the user that the stream task queue destruction failed.
[0086] The first quantity threshold can be understood as the maximum number of parallel stream task queues. In the embodiment of the present invention, the first quantity threshold is preferably 1024. When creating a stream task queue, determine whether the number of stream task queues to be created exceeds 1024; if the number of stream task queues to be created does not exceed 1024, create a new stream task queue. If the number of stream task queues to be created exceeds 1024, return a creation failure message. When destroying a stream task queue, if it is detected that there is still a driving task flow in the stream task queue, it means that there is an unfinished driving task flow in the stream task queue, and then return a destruction failure message.
[0087] The above-mentioned second quantity threshold can be understood as the maximum flow data volume of a driving task flow in a flow task queue. If the data volume of the driving task flow in the above-mentioned flow task queue exceeds the maximum flow data volume of the flow task queue, the above-mentioned application layer task will be blocked and the second failure information will be returned to the application layer.
[0088] 303. Based on the driver response task returned by the driver layer, the driver task flow in the flow task queue is driven and distributed.
[0089] In an embodiment of the present invention, after the driving is completed, a corresponding driving response task can be generated through the driving task completion status auxiliary information, added to the pending task queue, and distributed by the task distribution unit to notify the flow scheduling unit of the load status of the corresponding drive, so that the driving request task can be processed after the flow scheduling unit is triggered.
[0090] Optionally, the above-mentioned flow scheduling unit can take out the above-mentioned driving task flow from the above-mentioned flow task queue; according to the above-mentioned driving response task, call the above-mentioned driving load query function and the application and release functions of the above-mentioned driving task completion status, and return the driving status of the driving task flow required by the above-mentioned driving task flow; if the above-mentioned driving status is available, the above-mentioned driving task flow is marked as entering the waiting driving completion state, and when the driving status is returned to be executable, the above-mentioned driving task flow is switched to the executable state; if the above-mentioned driving status is unavailable, the above-mentioned driving task flow is marked as waiting for the driving resources to be available state; traverse the above-mentioned driving task flow in the waiting driving resources to be available state in real time, and call the driving load query function to query the load status of the corresponding driving; if the above-mentioned load status meets the preset executable conditions, the corresponding driving task flow in the waiting driving resources to be available state is switched to the executable state.
[0091] In an embodiment of the present invention, it is possible to traverse all driver task flows in executable states, take out the driver task flow from the head of the corresponding flow task queue, and hand it over to the driver distribution unit for processing. The driver distribution unit receives the driver task flow from the flow scheduling unit, parses the driver ID of the driver request task, searches for matching driver registration information in the driver storage unit based on the driver ID, and calls the driver load query function through the driver distribution unit to query the load status of the driver corresponding to the driver ID.
[0092] If the load of the driver corresponding to the driver ID is high, it means that the driver corresponding to the driver ID is in a busy state, and the driver state is returned to the above-mentioned flow scheduling unit as unavailable (failed), and the above-mentioned flow scheduling unit marks the driver task flow as waiting for the driver resource to be available; if the load of the driver corresponding to the driver ID is low, it means that the driver corresponding to the driver ID is in an available state, and the driver state is returned to the above-mentioned flow scheduling unit as available, and the above-mentioned flow scheduling unit marks the driver task flow as waiting for the driver to be completed, and records the auxiliary information of the driver task completion state that the driver task flow is waiting for (the driver state is executable), if the auxiliary information of the driver task completion state is received, the driver task flow waiting for the auxiliary information of the driver task completion state is found, and the state of the driver task flow is switched to the executable state; further, all driver task flows waiting for the driver resource to be available can be traversed, and according to the driver ID waiting for the resource, the driver load query function is called by the driver distribution unit to query the load state of the driver corresponding to the driver ID, if the driver load is low, then the driver task flow state is switched from the waiting for the driver resource to be available state to the executable state.
[0093] 304. Match the distributed driver from the driver layer to process the driver task flow.
[0094] In the embodiment of the present invention, the executable driver required for executing the driver task flow in the executable state is matched in the driver layer; the driver processing function is called to forward the driver task flow in the executable state to the executable driver for processing.
[0095] Furthermore, the driver thread in the driver layer can be registered through the driver information registration unit and then stored in the driver information storage unit. In the initialization phase, the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status of each driver are obtained; according to the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status, the driver is registered to obtain the driver information; the driver information is stored in the driver information table, and the driver information in the driver information table is updated in real time according to the driver load query function, driver processing function, and application and release functions of the driver task completion status.
[0096] Among them, the application and release functions of the above-mentioned driving task completion status are used to process the above-mentioned driving task completion status auxiliary information. The above-mentioned driving load query function is used to query the load status of each driving thread in the driving layer, and the above-mentioned driving processing function is used to call the corresponding driving thread in the driving layer to process the driving task flow. The above-mentioned driving task completion status auxiliary information also includes a resource release request. After receiving the driving response task, if the driving task completion status auxiliary information corresponding to the driving response task is a resource release request, the driving distribution unit will release the resources of the driving task flow corresponding to the driving response task.
[0097] Specifically, each drive request task is allocated a corresponding resource of the drive task completion status auxiliary information when it is issued. When the drive request task is completed, the flow scheduling unit is notified through the drive task completion status auxiliary information. The flow scheduling unit performs operations based on the drive task completion status auxiliary information and releases the corresponding resource of the drive task completion status auxiliary information after completion.
[0098] In the embodiment of the present invention, by converting the driver request task into the driver task flow, the scheduling between multiple threads is converted into the scheduling between flows, and the scheduling between the driver task flows is realized by using the flow task queue and the driver distribution. Due to the scheduling by the flow task queue, the system scheduling overhead is reduced compared with the direct scheduling between multiple threads. In addition, the application layer and the driver layer are decoupled by the flow task queue, and the expansion can be carried out by configuring the flow task queue and the driver.
[0099] Optionally, in a possible embodiment, the above-mentioned stream scheduling thread is one, which can be understood as the above-mentioned stream scheduling is implemented by an independent thread, and the above-mentioned application thread and the driving thread are decoupled through the above-mentioned independent stream scheduling thread, so that the above-mentioned task processing system of the embodiment of the present invention can be expanded by configuring the stream task queue and the driver.
[0100] Furthermore, when using independent threads to implement stream scheduling, a preset number of stream task queues can be scheduled in parallel. For example, 1024 stream task queues can be scheduled in parallel. Any time-consuming internal processing will seriously affect the scheduling efficiency. The stream scheduling thread can prohibit the execution of any other computing tasks. The driver layer can be designed as a driver thread. The general driver processing function (also called the driver task processing function) registered in the driver_register_table (driver information storage unit) will forward the driver request task in the stream scheduling to the driver thread for processing.
[0101] In a possible embodiment, the above-mentioned driver request task is transmitted between the application thread, the stream scheduling thread and the driver thread. In order to reduce the storage management overhead of the driver request task, the relevant data structure definition method is as follows: define a general driver message DrvCommonTask: the general driver message includes driver id, driver event and other information; define individual driver messages: define individual driver messages according to the driver id, such as the DrvTaskA1 message of driver A, the message header DrvTaskA1::header is of DrvCommonTask type, and the subsequent DrvTaskA1::body stores the specific parameter configuration message of driver A.
[0102] Specifically, take DrvTaskA1 as an example to explain the storage of relevant data: 1) The upper-level user creates a DrvTaskA1 object in the application thread and sends it to the stream scheduling thread for processing; 2) After receiving the driver request task, the stream scheduling thread is forced to convert it to the common driver message DrvCommonTask for processing; during the processing, the driver request task object is not deleted, but directly forwarded to the driver A thread for processing; 3) After receiving the driver request task, the driver A thread is forced to convert it to the DrvTaskA1 type for processing, and the driver request task is released after the processing is completed. In this way, the storage management overhead of the driver request task can be reduced.
[0103] In a possible embodiment, the acquired pending tasks can be retained in a preset task queue; it is determined whether the driving task flow corresponding to the pending tasks has completed processing; if the driving task flow has completed processing, the pending tasks are released from the preset task queue; if the driving task flow has not completed processing, the pending tasks are continued to be retained in the preset task queue. In this way, it can be ensured that the pending tasks can be reused when problems occur during the processing of the driving task flow, without having to search for the corresponding pending tasks in the application layer.
[0104] It should be noted that the task processing method provided in the embodiment of the present invention can be applied to devices such as smart phones, computers, servers, etc. that can perform task processing.
[0105] Optional, see Figure 4 , Figure 4 is a structural diagram of a task processing device provided by an embodiment of the present invention, such as Figure 4 As shown, the device comprises:
[0106] A first acquisition module 401 is used to acquire tasks to be processed from the application layer, wherein the tasks to be processed include control tasks and drive request tasks;
[0107] A conversion module 402, configured to convert the driving flow request task into a driving task flow based on the control task, and add the driving task flow to a flow task queue;
[0108] A driver distribution module 403 is used to perform driver distribution on the driver task flow in the flow task queue based on the driver response task returned by the driver layer;
[0109] The matching module 404 is used to match the distributed drivers from the driver layer to process the driver task flow.
[0110] Optional, such as Figure 5 As shown, the device also includes:
[0111] The second acquisition module 405 is used to acquire the driver ID, driver load query function, driver processing function and application and release functions of each driver during the initialization phase;
[0112] A registration module 406 is used to register the driver according to the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status, and obtain driver information;
[0113] The storage module 407 is used to store the driving information in a driving information table. The driving information in the driving information table is updated in real time according to the driving load query function, driving processing function, and application and release functions of the driving task completion status.
[0114] Optional, such as Figure 6 As shown, the conversion module 402 includes:
[0115] A judgment submodule 4021 is used to judge whether the number of the flow task queues to be created exceeds a first number threshold when creating the flow task queue based on the control task;
[0116] A creation submodule 4022, configured to create a new flow task queue if the number of the flow task queues to be created does not exceed the first number threshold;
[0117] The conversion submodule 4023 is used to forcibly convert the driving request task into a driving task flow according to a preset conversion rule, and add it to the new flow task queue according to a first-in-first-out rule.
[0118] Optional, such as Figure 7 As shown, the device also includes:
[0119] A first judgment module 408 is used to judge whether there is an unfinished driving task flow in the flow task queue to be destroyed when destroying the flow task queue based on the control task;
[0120] A first returning module 409 is configured to return first failure information to the application layer if there is an unfinished driving task flow in the flow task queue to be destroyed, and / or if the number of the flow task queue to be created exceeds the first number threshold;
[0121] A second judgment module 410 is used to judge whether the number of driving task flows in the flow task queue exceeds a second number threshold based on the control task;
[0122] The second returning module 411 is configured to block the task of the application layer and return second failure information to the application layer if the number of driving task flows in the flow task queue exceeds a second number threshold.
[0123] Optional, such as Figure 8 As shown, the drive distribution module 403 includes:
[0124] The fetching submodule 4041 is used to fetch the driving task flow from the flow task queue;
[0125] The first calling submodule 4042 is used to call the driving load query function and the application and release functions of the driving task completion status according to the driving response task returned by the driving layer, and return the driving status of the driver required by the driving task flow;
[0126] The first state submodule 4043 is used to mark the driving task flow as entering the waiting driving completion state if the driving state is available, and switch the driving task flow to the executable state when the driving state is returned to executable;
[0127] The second state submodule 4044 is used to mark the driving task flow as entering a state of waiting for driving resources to be available if the driving state is unavailable;
[0128] The third state submodule 4045 is used to traverse the driving task flow waiting for the driving resource to be available in real time, and call the driving load query function to query the load state of the corresponding driver. If the load state meets the preset executable conditions, the corresponding driving task flow waiting for the driving resource to be available is switched to the executable state.
[0129] Optional, such as Fig. 9 As shown, the matching module 404 includes:
[0130] A matching submodule 4051 is used to match the executable driver required to execute the driver task flow in the executable state in the driver layer;
[0131] The second calling submodule 4052 is used to call the driver processing function to forward the driver task flow in the executable state to the executable driver for processing.
[0132] Optional, such as Fig.10 As shown, the device also includes:
[0133] A reservation module 412 is used to reserve the acquired tasks to be processed in a preset task queue;
[0134] The third judgment module 413 is used to judge whether the driving task flow corresponding to the task to be processed has been processed;
[0135] A release module 414 is used to release the pending task from the preset task queue if the driving task flow is processed;
[0136] The retention module 415 is used to continue retaining the pending tasks in the preset task queue if the driving task flow has not completed processing.
[0137] It should be noted that the task processing device provided in the embodiment of the present invention can be applied to devices such as smart phones, computers, servers, etc. that can perform task processing.
[0138] The task processing device provided in the embodiment of the present invention can implement each process implemented by the task processing method in the above method embodiment and can achieve the same beneficial effect. To avoid repetition, it will not be described here.
[0139] See also Fig.11 , Fig.11 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention, such as Fig.11 As shown, it includes: a memory 1102, a processor 1101, and a computer program of a task processing method stored in the memory 1102 and executable on the processor 1101, wherein:
[0140] The processor 1101 is used to call the computer program stored in the memory 1102 and execute the following steps:
[0141] Obtaining pending tasks from the application layer, wherein the pending tasks include control tasks and drive request tasks;
[0142] Based on the control task, convert the drive request task into a drive task flow and add it to a flow task queue;
[0143] Based on the driving response task returned by the driving layer, driving distribution is performed on the driving task flow in the flow task queue;
[0144] The driver task flow is processed by matching the distributed drivers from the driver layer.
[0145] Optionally, the method executed by the processor 1101 further includes:
[0146] In the initialization phase, the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status are obtained for each driver;
[0147] Register the driver according to the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status to obtain driver information;
[0148] The driving information is stored in a driving information table, and the driving information in the driving information table is updated in real time according to the driving load query function, the driving processing function, and the application and release functions of the driving task completion status.
[0149] Optionally, the processor 1101 executes the step of converting the drive request task into a drive task flow based on the control task and adding the flow task flow to a flow task queue, including:
[0150] Based on the control task, when creating a stream task queue, determining whether the number of stream task queues to be created exceeds a first number threshold;
[0151] If the number of the to-be-created stream task queues does not exceed the first number threshold, creating a new stream task queue;
[0152] The drive request task is forcibly converted into a drive task flow according to a preset conversion rule, and is added to the new flow task queue according to a first-in-first-out rule.
[0153] Optionally, the method executed by the processor 1101 further includes:
[0154] Based on the control task, when destroying the stream task queue, it is determined whether there is an unfinished driving task flow in the stream task queue to be destroyed;
[0155] If there is an unfinished driving task flow in the stream task queue to be destroyed, and / or if the number of the stream task queue to be created exceeds the first number threshold, returning first failure information to the application layer;
[0156] Based on the control task, determining whether the number of driving task flows in the flow task queue exceeds a second number threshold;
[0157] If the number of driving task flows in the flow task queue exceeds a second number threshold, the task of the application layer is blocked and second failure information is returned to the application layer.
[0158] Optionally, the processor 1101 executes the driving response task based on the return of the driving layer to drive and distribute the driving task flow in the flow task queue, including:
[0159] Taking out the driving task flow from the flow task queue;
[0160] According to the driving response task, the driving load query function and the application and release functions of the driving task completion status are called to return the driving status of the driver required by the driving task flow;
[0161] If the driving state is available, the driving task flow is marked as entering a state of waiting for driving completion, and when the driving state is returned to executable, the driving task flow is switched to an executable state;
[0162] If the driving state is unavailable, marking the driving task flow as entering a state of waiting for driving resources to be available;
[0163] The drive task flow waiting for the available drive resources is traversed in real time, and the drive load query function is called to query the load status of the corresponding drive. If the load status meets the preset executable conditions, the corresponding drive task flow waiting for the available drive resources is switched to the executable state.
[0164] Optionally, the processor 1101 performs the matching of the distributed driver from the driver layer to process the stream, including:
[0165] Matching the executable driver required to execute the driver task flow in the executable state in the driver layer;
[0166] The driver processing function is called to forward the driver task flow in the executable state to the executable driver for processing.
[0167] Optionally, the method executed by the processor 1101 further includes:
[0168] The acquired tasks to be processed are retained in a preset task queue;
[0169] Determine whether the driving task flow corresponding to the task to be processed has completed processing;
[0170] If the driving task flow is processed, the pending task is released from the preset task queue;
[0171] If the driving task flow has not completed processing, the pending tasks will continue to be retained in the preset task queue.
[0172] It should be noted that the electronic device provided by the embodiment of the present invention can be applied to devices such as smart phones, computers, servers, etc. that can perform task processing.
[0173] The electronic device provided by the embodiment of the present invention can implement each process implemented by the task processing method in the above method embodiment and can achieve the same beneficial effect. To avoid repetition, it will not be described here.
[0174] An embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the computer program implements the various processes of the task processing method or the application-side task processing method provided by the embodiment of the present invention, and can achieve the same technical effect. To avoid repetition, it will not be repeated here.
[0175] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM).
[0176] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.
Claims
1. A task processing method, characterized in that: The following steps are involved: In the initialization phase, the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status are obtained for each driver; Register the driver according to the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status to obtain driver information; The driving information is stored in a driving information table, and the driving information in the driving information table is updated in real time according to the driving load query function, the driving processing function, and the application and release functions of the driving task completion status; Obtaining pending tasks from the application layer, wherein the pending tasks include control tasks and drive request tasks; Based on the control task, convert the drive request task into a drive task flow and add it to a flow task queue; Taking out the driving task flow from the flow task queue; According to the driving response task returned by the driving layer, the driving load query function and the application and release functions of the driving task completion status are called to return the driving status of the driver required by the driving task flow; If the driving state is available, the driving task flow is marked as entering a state of waiting for driving completion, and when the driving state is returned to executable, the driving task flow is switched to an executable state; If the driving state is unavailable, marking the driving task flow as a state of waiting for driving resources to be available; Traversing the drive task flow waiting for the available state of the drive resource in real time, and calling the drive load query function to query the load state of the corresponding drive, if the load state meets the preset executable condition, switching the corresponding drive task flow waiting for the available state of the drive resource to the executable state; Matching the executable driver required to execute the driver task flow in the executable state in the driver layer; The driver processing function is called to forward the driver task flow in the executable state to the executable driver for processing.
2. The method according to claim 1, characterized in that The step of converting the drive request task into a drive task flow based on the control task and adding the flow task flow to a flow task queue includes: Based on the control task, when creating a stream task queue, determining whether the number of stream task queues to be created exceeds a first number threshold; If the number of the to-be-created stream task queues does not exceed the first number threshold, creating a new stream task queue; The drive request task is forcibly converted into a drive task flow according to a preset conversion rule, and is added to the new flow task queue according to a first-in-first-out rule.
3. The method according to claim 2, characterized in that The method further comprises: Based on the control task, when destroying the stream task queue, it is determined whether there is an unfinished driving task flow in the stream task queue to be destroyed; If there is an unfinished driver request task flow in the stream task queue to be destroyed, and / or if the number of the stream task queue to be created exceeds the first number threshold, returning first failure information to the application layer; Based on the control task, determining whether the number of driving task flows in the flow task queue exceeds a second number threshold; If the number of driving task flows in the flow task queue exceeds a second number threshold, the task of the application layer is blocked and second failure information is returned to the application layer.
4. The method according to claim 3, characterized in that The method further comprises: The acquired tasks to be processed are retained in a preset task queue; Determine whether the driving task flow corresponding to the task to be processed has completed processing; If the driving task flow is processed, the pending task is released from the preset task queue; If the driving task flow has not completed processing, the pending tasks will continue to be retained in the preset task queue.
5. A task processing device, characterized in that: The device comprises: The second acquisition module is used to obtain the driver ID, driver load query function, driver processing function and application and release function of the driver task completion status of each driver during the initialization phase; A registration module, used to register the driver according to the driver ID, driver load query function, driver processing function, and application and release functions of the driver task completion status, and obtain driver information; A storage module, used for storing the driving information in a driving information table, wherein the driving information in the driving information table is updated in real time according to the driving load query function, the driving processing function, and the application and release functions of the driving task completion status; A first acquisition module, used for acquiring tasks to be processed from the application layer, wherein the tasks to be processed include control tasks and drive request tasks; A conversion module, used for converting the drive request task into a drive task flow based on the control task, and adding the drive task flow into a flow task queue; A driver distribution module is used to take out the driver task flow from the flow task queue; according to the driver response task returned by the driver layer, call the driver load query function and the application and release functions of the driver task completion status, and return the driver status of the driver required by the driver task flow; if the driver status is available, mark the driver task flow as entering the waiting driver completion state, and when the driver status is returned to be executable, switch the driver task flow to the executable state; if the driver status is unavailable, mark the driver task flow as waiting for the driver resource to be available; traverse the driver task flow in the waiting driver resource available state in real time, and call the driver load query function to query the load state of the corresponding driver. If the load state meets the preset executable condition, switch the corresponding driver task flow in the waiting driver resource available state to the executable state; The matching module is used to match the executable driver required to execute the driver task flow in the executable state in the driver layer; call the driver processing function to forward the driver task flow in the executable state to the executable driver for processing.
6. A task processing system, characterized in that: The system includes: an application layer, a stream scheduling layer and a driver layer, wherein the application layer is used to generate tasks to be processed and receive task processing results, the driver layer is used to provide a driver to calculate the tasks to be processed and return a driver response task, and the stream scheduling layer is used to implement the steps in the task processing method as described in any one of claims 1 to 4.
7. An electronic device, characterized in that: include: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the task processing method according to any one of claims 1 to 4 when executing the computer program.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the task processing method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Task processing method, device and system, equipment and storage medium
CN110187958A
Container-based workflow scheduling method, device and system and storage medium
CN113225269A