Scheduling Method and Device for a Multi-Task Processing Unit Based on Messages and Events
Through the coordinated work of the task management unit and the task processing unit, the task processing unit is dynamically scheduled using the message and event caching mechanism, the problem of low resource utilization in embedded CPU is solved, and task processing efficiency and delay satisfaction are improved.
Patent Information
- Application Number
- CN201910253885.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-03-30
- Publication Date
- 2025-08-05
- Estimated Expiration
- 2039-03-30
AI Technical Summary
In embedded CPUs, existing operating systems are difficult to effectively schedule concurrent tasks, resulting in low resource utilization and difficult to meet the strict requirements of task processing delays.
Through the coordinated work of the task management unit and the task processing unit, the message and event caching mechanisms are used to dynamically schedule the task processing unit to avoid resource conflicts and improve CPU utilization.
It realizes efficient scheduling of concurrent tasks in embedded CPU, reduces the complexity of task processing units, and improves resource utilization and task processing efficiency.
Smart Images

Figure CN111767120B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to task scheduling, and in particular, to a scheduling method and device for a multi-task processing unit based on messages and events. Background Art
[0002] In some applications, processors handle large-scale concurrent tasks. For example, embedded processors used in network devices and storage devices handle multiple concurrent network packets or I / O commands.
[0003] Desktop and server CPUs run an operating system that schedules multiple processes and / or threads running on the CPU to handle tasks. Users don't need to intervene in switching between processes / threads; the operating system selects the appropriate process / thread for scheduling, fully utilizing the CPU's computing power. However, in embedded CPUs, resources such as available memory and CPU processing power are limited. Furthermore, some embedded systems have strict performance requirements, particularly for task processing latency, making existing operating systems difficult to adapt to these scenarios.
[0004] Chinese patent applications with application numbers 201811095364.7 and 201811160925.7 provide a signal-slot based task scheduling solution to handle a large number of concurrent IO commands and ensure the overall service quality of multiple IO commands.
[0005] Figure 1A This is a diagram of task scheduling.
[0006] Figure 1A , the direction from left to right is the direction of time passage. A plurality of tasks (1-1, 2-1, 3-1, 1-2, 2-2, and 3-2) being processed are also shown, wherein in the reference numerals having the structure "ab", the preceding symbol a indicates a task, and the following symbol b indicates a subtask included in the task. Figure 1A It shows that 3 tasks are processed in time sequence, each task consists of 2 subtasks.
[0007] The solid arrows indicate the time sequence of processing multiple tasks, and the dotted arrows indicate the logical sequence of task processing. For example, taking Task 1 as an example, its subtask 1-1 (Task 1-1) should be processed first, and then its subtask 1-2 (Task 1-2) should be processed. Figure 1A After processing subtask 1-1, subtask 1-2 cannot be processed immediately (because the required resources are not yet ready), so subtask 2-1 and subtask 3-1 are scheduled for execution. Then, it is recognized that the resources required for subtask 1-2 are ready, and after processing subtask 3-1, subtask 1-2 is scheduled for execution.
[0008] On a processor, tasks (or subtasks) are processed by executing code segments. A single CPU (or CPU core) processes only a single task at any one time. For example, Figure 1A As shown, for multiple tasks to be processed, the code segment for processing subtask 1-1 is executed first, the code segment for processing subtask 2-1 is executed next, the code segment for processing subtask 3-1 is executed next, the code segment for processing subtask 1-2 is executed next, the code segment for processing subtask 2-2 is executed next, and the code segment for processing subtask 3-2 is executed next. Optionally, the logical order of task processing is indicated in the code segment of each processing task (or subtask). For example, the logical order includes that subtask 1-2 should be processed after task 1-1. As another example, in the code segment for processing subtask 1-1, it is indicated that the code segment whose logical order is to be processed later should be the code segment for processing subtask 1-2.
[0009] The code segment indicates the code segment to be executed next in the logical sequence by, for example, sending a signal, for example, using the value of the signal as an index to the code segment to be executed.
[0010] Figure 1B It is a block diagram of the task processing system.
[0011] See Figure 1B The task processing system consists of two parts: software and hardware. The hardware includes, for example, one or more CPUs that run the software and other hardware resources that handle related tasks (e.g., memory, codecs, interfaces, accelerators, interrupt controllers, DMA units, etc.).
[0012] The code segments of software running on a CPU are called task processing units. A task processing system includes multiple task processing units. Each task processing unit processes the same or different tasks. For example, task processing unit 0 processes the first subtask of a task (e.g., subtask 1-1, subtask 2-1, and subtask 3-1), while task processing units 1, 2, and 3 process the second subtask of a task (e.g., subtask 1-2, subtask 2-2, and subtask 3-2).
[0013] The task processing system further includes a task management unit implemented in software for scheduling one of the task processing units to run on the hardware.
[0014] When executed by the CPU, the task management unit provides an API (Application Programming Interface) to the task processing unit. The task processing unit calls the API to inform the task management unit of other task processing units that should be scheduled. The task management unit checks whether the resources required by the other task processing units are ready and schedules them if the resources are ready.
[0015] The resources required by the task processing unit include, for example, a cache unit, a descriptor (or context) for processing the task, a container unit, and the like.
[0016] By using the task management unit, an API that can be called by the task processing unit is provided, so that the task processing unit only needs to specify its successor task processing unit according to the logical order of the task, and the task management unit efficiently schedules the task processing unit while meeting the requirements of the logical order.
[0017] In an embodiment of the present application, the task processing unit does not need to poll or wait for resource availability, and does not need to maintain the order between multiple task processing units, thereby improving CPU utilization and reducing the complexity of the task processing unit.
[0018] In an optional implementation, the task processing unit and / or the task management unit are implemented by hardware.
[0019] Figure 2 It is a schematic diagram of the task management unit.
[0020] The task management unit includes a signal distribution unit 210 , one or more signal buffers ( 220 , 222 . . . , 22 n ) and a task scheduling unit 240 .
[0021] The task scheduling unit 240 schedules one or more task processing units (260, 262, ... 26n) to process the tasks indicated by the signals. For example, the signals correspond one to one with the task processing units.
[0022] The signal dispatch unit 210 receives signals from a task processing unit or hardware. The signals indicate which task processing unit should be scheduled to process the task indicated by the signals. For example, the task processing unit may provide the signals to the signal dispatch unit 210 by calling an API, or the hardware may provide the signals to the signal dispatch unit 210 by interrupting the task.
[0023] There are many types of signals. Signal types are identified, for example, by their values. Each signal has a corresponding task processing unit. The task management unit provides a signal buffer for each signal. For example, signal buffer 220 is used to store signal 0, signal buffer 222 is used to store signal 2, and signal buffer 22n is used to store signal n. The signal buffer contains multiple entries, each of which holds a signal instance. Signal instances in the buffer are sorted in the order in which they were added to the buffer. Signals are added to the buffer from the end of the queue and removed from the head of the queue.
[0024] In response to receiving a signal, the signal distribution unit 210 adds the signal to a signal buffer corresponding to the type of the received signal, and optionally, causes the API for providing the signal to return without blocking the caller of the API.
[0025] Periodically, in response to an interrupt, in response to the completion of a current task, or for other reasons, the task scheduling unit 240 has the opportunity to schedule a task processing unit based on a signal in the signal buffer. The task scheduling unit 240 retrieves a signal from one of the signal buffers and schedules one of the task processing units to process the signal. In one example, the task scheduling unit 240 calls the task processing unit corresponding to the type of signal retrieved. As another example, the task scheduling unit 240 uses the retrieved signal as an index to obtain the scheduled task processing unit.
[0026] Optionally, the task scheduling unit 240 selects the signal buffer in a random, round-robin, weighted round-robin, etc. Priority can be set for each signal buffer. The priority of each signal buffer can be adjusted.
[0027] Still optionally, the task management unit further clears the signals in the signal buffer. For example, in response to receiving a shutdown or power-off request, the task management unit clears all signals in the signal buffer to terminate the processing of the signals.
[0028] It should be pointed out that Figure 1A 、 Figure 1B and Figure 2 The relevant content is provided in Chinese patent applications No. 201811095364.7 and No. 201811160925.7, but is not the prior art in the field. Summary of the Invention
[0029] For example, a storage device that processes I / O commands simultaneously processes a large number of concurrent I / O commands. The processing of each I / O command involves multiple stages and uses multiple resources.
[0030] Storage devices need to be able to process a large number of I / O commands simultaneously, minimize I / O command processing delays, and avoid excessive processing delays for individual I / O commands. Storage devices also need to improve processing efficiency, reduce resource usage conflicts when processing multiple I / O commands, and avoid wasting CPU processing power.
[0031] According to the first aspect of the present application, a first task scheduling method according to the first aspect of the present application is provided, comprising the following steps: in response to receiving a message and / or event provided to a task processing unit, caching the provided message and / or event, and updating the status of the task processing unit; scheduling a task processing unit that is in a schedulable state, and executing the function of the scheduled task processing unit.
[0032] According to the first task scheduling method of the first aspect of the present application, a second task scheduling method according to the first aspect of the present application is provided, wherein messages are recorded in the message cache of the task processing unit, and events are recorded in the event cache of the task processing unit.
[0033] According to the second task scheduling method of the first aspect of the present application, a third task scheduling method according to the first aspect of the present application is provided, wherein the message cache that records the message is a message cache corresponding to the type of the message, and the event cache that records the event is an event cache corresponding to the type of the event.
[0034] According to one of the first to third task scheduling methods of the first aspect of the present application, a fourth task scheduling method according to the first aspect of the present application is provided, wherein, in response to an API for providing a deletion message and / or a deletion event to a task processing unit being called, the message and / or event provided to the task processing unit is deleted, and the status of the task processing unit is updated.
[0035] According to one of the first to fourth task scheduling methods of the first aspect of the present application, a fifth task scheduling method according to the first aspect of the present application is provided, wherein if all message caches of the task processing unit are filled and all its event caches indicate the occurrence of events, the task processing unit is in a schedulable state.
[0036] According to one of the first to fifth task scheduling methods of the first aspect of the present application, a sixth task scheduling method according to the first aspect of the present application is provided, wherein, if any message cache of the task processing unit is not filled, or any event cache does not indicate the occurrence of an event, the task processing unit is in an uncallable state.
[0037] According to the sixth task scheduling method of the first aspect of the present application, a seventh task scheduling method according to the first aspect of the present application is provided, wherein when the bitmap or table of the task processing unit indicates that all messages and / or events required by the task processing unit have been filled or exist, the task processing unit is in a schedulable state.
[0038] According to one of the first to seventh task scheduling methods of the first aspect of the present application, an eighth task scheduling method according to the first aspect of the present application is provided, wherein, in response to identifying that a task processing unit is in a schedulable state, the task processing unit in the schedulable state is removed from the task processing unit linked list and added to the ready linked list to schedule the task processing unit from the ready linked list.
[0039] According to the eighth task scheduling method of the first aspect of the present application, a ninth task scheduling method according to the first aspect of the present application is provided, wherein task units are scheduled from the ready list periodically, in response to an interrupt, and in response to the completion of execution of the currently scheduled task processing unit.
[0040] According to one of the first to ninth task scheduling methods of the first aspect of the present application, a tenth task scheduling method according to the first aspect of the present application is provided, wherein task processing units in a schedulable state are scheduled according to their priority order.
[0041] According to the tenth task scheduling method of the first aspect of the present application, an eleventh task scheduling method according to the first aspect of the present application is provided, wherein the scheduled task processing unit generates a new message and provides the generated new message to itself or other task processing units.
[0042] According to one of the first to eleventh task scheduling methods of the first aspect of the present application, a twelfth task scheduling method according to the first aspect of the present application is provided, wherein, in response to an update of the status of a task processing unit or in response to completion of function execution of a scheduled task processing unit, the task processing unit is added to a task processing unit linked list or retained in a ready linked list according to the status of the task processing unit.
[0043] According to the twelfth task scheduling method of the first aspect of the present application, a thirteenth task scheduling method according to the first aspect of the present application is provided. In response to identifying that a task processing unit is in an uncallable state, the task processing unit in the uncallable state is removed from the ready list and added to the task processing unit list.
[0044] According to one of the first to thirteenth task scheduling methods of the first aspect of the present application, a fourteenth task scheduling method according to the first aspect of the present application is provided, wherein, in response to an API for creating a task processing unit being called, a task processing unit is created according to information indicated by the API.
[0045] According to the fourteenth task scheduling method of the first aspect of the present application, a fifteenth task scheduling method according to the first aspect of the present application is provided, wherein a message cache, an event cache and a function of a task processing unit are specified to create a task processing unit.
[0046] According to the fifteenth task scheduling method of the first aspect of the present application, a sixteenth task scheduling method according to the first aspect of the present application is provided, wherein creating a task processing unit further specifies a priority and / or bitmap of the task processing unit.
[0047] According to the sixteenth task scheduling method of the first aspect of the present application, a seventeenth task scheduling method according to the first aspect of the present application is provided, wherein, in response to creating a task processing unit, the created task processing unit is added to a task processing unit linked list.
[0048] According to one of the first to seventeenth task scheduling methods of the first aspect of the present application, an eighteenth task scheduling method according to the first aspect of the present application is provided, wherein the task processing unit includes a producer task processing unit and a consumer task processing unit, and the producer task processing unit provides a message representing available resources to the consumer task processing unit.
[0049] According to the eighteenth task scheduling method of the first aspect of the present application, a nineteenth task scheduling method according to the first aspect of the present application is provided, wherein the scheduled consumer task processing unit uses the available resources represented by the message.
[0050] According to the eighteenth or nineteenth task scheduling method of the first aspect of the present application, a twentieth task scheduling method according to the first aspect of the present application is provided, wherein the scheduled consumer task processing unit generates a message requesting resources and provides it to the producer task processing unit.
[0051] According to one of the eighteenth to twentieth task scheduling methods of the first aspect of the present application, a twenty-first task scheduling method according to the first aspect of the present application is provided, wherein, if there are available resources or there are available resources and there is a message from the consumer task processing unit requesting resources, the producer task processing unit is in a schedulable state.
[0052] According to one of the eighteenth to twenty-first task scheduling methods of the first aspect of the present application, a twenty-second task scheduling method according to the first aspect of the present application is provided, wherein the available resources include: a cache unit, a command context, and a cache container.
[0053] According to one of the eighteenth to twenty-second task scheduling methods of the first aspect of the present application, a twenty-third task scheduling method according to the first aspect of the present application is provided, wherein the consumer task processing unit calls an API to provide a message requesting resources to the producer task processing unit, so that the producer task processing unit provides it with a message representing available resources.
[0054] According to one of the eighteenth to twenty-third task scheduling methods of the first aspect of the present application, a twenty-fourth task scheduling method according to the first aspect of the present application is provided, wherein the scheduled consumer task processing unit generates a message to release resources and provides it to the producer task processing unit.
[0055] According to one of the eighteenth to twenty-fourth task scheduling methods of the first aspect of the present application, a twenty-fifth task scheduling method according to the first aspect of the present application is provided, wherein, if there is a message representing available resources or there is a message representing available resources and there is an IO command to be processed, the consumer task processing unit is in a schedulable state.
[0056] According to the twenty-fifth task scheduling method of the first aspect of the present application, a twenty-sixth task scheduling method according to the first aspect of the present application is provided, wherein, when there is a message indicating the first command context and an event that an IO command is to be processed, the first consumer task processing unit is in a schedulable state.
[0057] According to the twenty-sixth task scheduling method of the first aspect of the present application, a twenty-seventh task scheduling method according to the first aspect of the present application is provided, wherein the first producer task processing unit provides a message representing the first command context to the first consumer task processing unit, and the interrupt source provides the first consumer task processing unit with an event that an IO command is to be processed.
[0058] According to the twenty-sixth or twenty-seventh task scheduling method of the first aspect of the present application, a twenty-eighth task scheduling method according to the first aspect of the present application is provided, wherein the first consumer task processing unit includes a message cache and an event cache, the message cache records messages indicating the first command context, and the event cache records whether there are IO command events to be processed.
[0059] According to the twenty-eighth task scheduling method of the first aspect of the present application, a twenty-ninth task scheduling method according to the first aspect of the present application is provided, wherein the first consumer task processing unit generates a second command context based on the first command context, and generates a message representing the second command context and provides it to the second consumer task processing unit.
[0060] According to one of the twenty-seventh to twenty-ninth task scheduling methods of the first aspect of the present application, a thirtieth task scheduling method according to the first aspect of the present application is provided, wherein, if there is a message indicating a second command context generated by the first consumer task processing unit and there is a message representing an available cache, the second consumer task processing unit is in a schedulable state.
[0061] According to the 30th task scheduling method of the first aspect of the present application, a 31st task scheduling method according to the first aspect of the present application is provided, wherein the second producer task processing unit provides a message indicating that there is available cache to the second consumer task processing unit.
[0062] According to the thirtieth or thirty-first task scheduling method of the first aspect of the present application, a thirty-second task scheduling method according to the first aspect of the present application is provided, wherein the second consumer task processing unit includes two message caches, the first message cache records messages indicating the second command context, and the second message cache records messages with available cache.
[0063] According to the thirty-second task scheduling method of the first aspect of the present application, a thirty-third task scheduling method according to the first aspect of the present application is provided, wherein the second consumer task processing unit generates a third command context based on the second command context, and generates a message representing the third command context and provides it to the third consumer task processing unit.
[0064] According to one of the 30th to 33rd task scheduling methods of the first aspect of the present application, a 34th task scheduling method according to the first aspect of the present application is provided, wherein, if there is a message indicating a third command context generated by the second consumer task processing unit and there is an event representing an available DMA unit, the third consumer task processing unit is in a schedulable state.
[0065] According to the thirty-fourth task scheduling method of the first aspect of the present application, a thirty-fifth task scheduling method according to the first aspect of the present application is provided, wherein the interrupt source provides an event indicating that the DMA unit is available to the third consumer task processing unit.
[0066] According to the thirty-fourth or thirty-fifth task scheduling method of the first aspect of the present application, a thirty-sixth task scheduling method according to the first aspect of the present application is provided, wherein the third consumer task processing unit includes a message cache and an event cache, the message cache records messages indicating the third command context, and the event cache records events of whether there is an available DMA unit.
[0067] According to one of the thirty-fourth to thirty-sixth task scheduling methods of the first aspect of the present application, a thirty-seventh task scheduling method according to the first aspect of the present application is provided, wherein the scheduled third consumer task processing unit uses a DMA unit to initiate data movement from the host to the cache.
[0068] According to the thirty-seventh task scheduling method of the first aspect of the present application, a thirty-eighth task scheduling method according to the first aspect of the present application is provided, wherein, after the DMA unit completes the data movement, the third command context is provided to the cache to indicate that the completed data transfer is associated with the third command context.
[0069] According to one of the thirty-fourth to thirty-eighth task scheduling methods of the first aspect of the present application, a thirty-ninth task scheduling method according to the first aspect of the present application is provided, wherein there is a message representing that there is an available cache container, and there is an event indicating that the DMA transfer is completed, and the fourth consumer task processing unit is in a schedulable state.
[0070] According to the thirty-ninth task scheduling method of the first aspect of the present application, a fortieth task scheduling method according to the first aspect of the present application is provided, wherein the third producer task processing unit provides a message indicating that a cache container is available to the fourth consumer task processing unit.
[0071] According to the thirty-ninth or fortieth task scheduling method of the first aspect of the present application, a forty-first task scheduling method according to the first aspect of the present application is provided, wherein the interrupt source provides an event indicating completion of the DMA transfer of the DMA unit to the fourth consumer task processing unit.
[0072] According to one of the thirty-ninth to forty-first task scheduling methods of the first aspect of the present application, a forty-second task scheduling method according to the first aspect of the present application is provided, wherein the fourth consumer task processing unit includes a message cache and an event cache, a message cache records messages indicating a cache container, and an event cache records events indicating whether the DMA transmission of the DMA unit is completed.
[0073] According to one of the thirty-ninth to forty-second task scheduling methods of the first aspect of the present application, a forty-third task scheduling method according to the first aspect of the present application is provided, wherein the command context provided by the DMA unit is obtained, and the cache filled with data by the DMA unit is bound to the cache container to realize the fourth consumer task processing unit being scheduled to execute the function.
[0074] According to the second aspect of the present application, a first task scheduling system according to the second aspect of the present application is provided, comprising: a task management unit and a task processing unit, wherein the task management unit comprises an API processing unit, a scheduling unit, and one or more APIs; in response to an API that provides messages and / or events to the task processing unit being called, the API processing unit records the messages and / or events in the cache of the task processing unit and updates the status of the task processing unit; the scheduling unit schedules a task processing unit that is in a schedulable state and executes the function of the scheduled task processing unit. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0076] Figure 1A It is a schematic diagram of task scheduling;
[0077] Figure 1B It is a block diagram of the task processing system;
[0078] Figure 2 It is a schematic diagram of the task management unit;
[0079] Figure 3 is a schematic diagram of a task scheduling system according to an embodiment of the present application;
[0080] Figure 4 is a task processing unit according to an embodiment of the present application;
[0081] Figure 5 is a block diagram of a task scheduling system according to an embodiment of the present application;
[0082] Figure 6 is a flowchart of a task scheduling system according to an embodiment of the present application;
[0083] Figure 7A and Figure 7B is a schematic diagram of resource allocation according to an embodiment of the present application;
[0084] Figure 8 Schematic diagram of processing tasks using a task scheduling system according to an embodiment of the present application. DETAILED DESCRIPTION
[0085] The following is a clear and complete description of the technical solutions in the embodiments of the present invention, in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0086] Figure 3 is a schematic diagram of a task scheduling system according to an embodiment of the present application.
[0087] Multiple processes can run in a CPU, and a processor can include multiple CPU cores. According to an embodiment of the present application, a task management unit is provided for each process running on a CPU core. The task management unit manages one or more task processing units belonging to the process in which it is located. For the sake of simplicity, those skilled in the art will appreciate that the task management unit applied to a system including multiple processors / multiple CPU cores / multiple processes is also applicable to a multi-threaded system.
[0088] See Figure 3 , showing process 0 and process 1. Each process includes a task management unit. For example, process 0 includes task management unit 310, and process 1 includes task management unit 320.
[0089] Task management unit 310 manages multiple task processing units (task processing unit 0, task processing unit 1, task processing unit 2, and task processing unit 3), and task management unit 320 manages multiple task processing units (task processing unit 4, task processing unit 5, task processing unit 6, and task processing unit 7). It is understood that the number of task processing units managed by each task management unit can be the same or different.
[0090] The task management unit (310, 320) schedules the operation of the task processing units it manages. The task management unit (310, 320) also provides an API. The task processing units to be managed by the task management unit are registered with the API, and messages and / or events are provided to the task processing units through the API. The task processing units are able to provide messages and / or events to themselves or other task processing units through the API provided by the task management unit. The task scheduling system is able to provide messages and / or events to the task processing units through the API provided by the task management unit.
[0091] For example, task processing unit 0 performs the first phase of processing for an IO command and provides the IO command context, including the results of the first phase of processing, to task processing unit 1 via the task management unit's API for the second phase of processing of the IO command. Thus, logically, task processing unit 0 provides messages to task processing unit 1 to demonstrate the sequence of the first and second phases of IO command processing. In essence, the task management unit 310 API receives the IO command context provided by task processing unit 0 without immediately calling task processing unit 1.
[0092] According to an embodiment of the present application, the task management unit further provides a variety of APIs for, for example, creating a task processing unit and canceling messages and / or events provided to a task processing unit.
[0093] The task management unit maintains all task processing units created through its API and schedules these task processing units when conditions are met. For the sake of simplicity, the task processing units created through its API maintained by the task management unit are called task processing units of the task management unit.
[0094] For example, the task management unit maintains all of its task processing units through a task processing unit linked list, and maintains the schedulable task processing units among all of its task processing units through a ready linked list. A schedulable task processing unit is one that has all the resources required for its execution, which will be described in more detail below.
[0095] In response to a call to an API that provides a message and / or event to a task processing unit, the task management unit obtains the message and / or event, obtains the task processing unit specified by the call to the API, caches the obtained message and / or event in association with the task processing unit, and updates the status of the task processing unit to reflect that the message and / or event required for the execution of the task processing unit is available. For example, the status of the task processing unit is reflected by a bitmap or table associated with the task processing unit, each bit of the bitmap or each table entry in the table indicates whether the corresponding message and / or event is ready or exists. When the bitmap or table indicates that all messages and / or events required by the task processing unit are ready or exist, it means that the task processing unit can be scheduled.
[0096] For example, messages have multiple values while events have two values to distinguish between messages and events. Messages indicate, for example, a buffered instance or an instance of an IO command context, while events indicate the presence of an IO command to be processed, the expiration of a timer interrupt, etc.
[0097] Figure 4 It is a task processing unit according to an embodiment of the present application.
[0098] The task processing unit includes one or more message buffers to store messages sent to it. For example, each message buffer stores one or more instances of a message. The task processing unit also includes one or more event buffers, each of which stores a type of event, such as an indication of whether an event has occurred.
[0099] The task processing unit further includes a priority, and the task management unit determines the order of scheduling the task processing units according to the priority when there are multiple task processing units that can be scheduled.
[0100] The task processing unit also includes, for example, a bitmap, each bit of the bitmap being associated with one of the message buffer and event buffer of the task processing unit, so that the bitmap can be used to identify whether each message buffer is filled with messages and whether each event has occurred. According to an embodiment of the present application, each task processing unit is created separately, so that each task processing unit has, for example, different types and quantities of message buffers. Still as an example, the condition for a task processing unit to be scheduled is that all its message buffers are filled with at least one message and all its event buffers indicate that an event has occurred. Still as an example, a task processing unit includes at most 2 message buffers and at most 1 event buffer.
[0101] Thus, according to an embodiment of the present application, in response to an API being called to provide a message or event to a task processing unit, the task management unit obtains the message or event, and obtains the task processing unit specified by calling the API, fills the message into the message cache corresponding to the same message type of the task processing unit, and records in a bitmap that the message cache of this type is filled with the message, or sets an event cache corresponding to the event type according to the obtained event, and records in a bitmap that an event of this type occurs.
[0102] The function of the task processing unit is called when the task processing unit is scheduled to process tasks on behalf of the task processing unit.
[0103] When registering a task processing unit with the task management unit through the API, the message cache, event cache, priority, bitmap and function of the task processing unit are specified. It can be understood that the priority and / or bitmap of the task processing unit are optional. Even if the task processing unit does not have a bitmap, it can be determined whether the task processing unit can be called by identifying whether each message cache is empty and the content of each event cache. In response to registering the task processing unit, the task management unit also adds the registered task processing unit to the task processing unit linked list to maintain the task processing unit. When the task management unit identifies that, for example, the bitmap of the task processing unit indicates that the task processing unit can be called, the task management unit adds the task processing unit to the ready linked list.
[0104] The task management unit retrieves one of the task processing units from the ready list, for example, based on priority, and schedules it. After the function of the scheduled task processing unit is completed, the task management unit adds it to the task processing unit list. Optionally, after the function of the scheduled task processing unit is completed, the task management unit recognizes that it is still schedulable and adds it to the ready list.
[0105] Figure 5 is a block diagram of a task scheduling system according to an embodiment of the present application.
[0106] The task management unit includes an API processing unit, a scheduling unit, and one or more APIs. The task management unit also maintains a task processing unit linked list and a ready linked list. The API processing unit processes calls to each API. For example, in response to a call to an API that creates a task processing unit, the API processing unit creates the task processing unit based on the information indicated by the API, initializes its message buffer and / or event buffer, and adds the task processing unit to the task processing unit linked list. Still for example, in response to a call to an API that provides a message to a task processing unit, based on the message content and the task processing unit indicated by the API, the API processing unit records in the task processing unit's bitmap that the message buffer corresponding to the message is not empty, and adds the message to the corresponding message buffer. Similarly, in response to a call to an API that provides an event to a task processing unit, based on the event content and the task processing unit indicated by the API, the API processing unit records in the task processing unit's bitmap that the event buffer corresponding to the event is not empty, and adds the event to the corresponding event buffer. External events such as interrupts, for example, call the task management unit's API in an interrupt handling function to provide the event represented by the interrupt to the task processing unit.
[0107] Optionally, when the API processing unit updates the bitmap of the task processing unit, if it is recognized that the scheduling condition of the task processing unit indicated by the bitmap has been met, the task processing unit is also set in the ready list.
[0108] Although Figure 5 4. In the figure, a single API processing unit is shown for each task processing unit to process calls to all its APIs. It can be understood that a corresponding API processing unit can be provided for processing each API.
[0109] The scheduling unit of the task management unit periodically schedules the task processing units in the ready list, in response to an interrupt, in response to the completion of execution of the currently scheduled task processing unit, or for other reasons. The scheduling unit selects, for example, the task processing unit with the highest priority from the ready list and calls its function to schedule the task processing unit. All task processing units in the ready list are schedulable, eliminating the need for the scheduling unit to determine whether the scheduling conditions of the task processing units are met. This reduces complexity and eliminates resource conflicts among multiple task processing units.
[0110] During the execution of a task processing unit's function, it consumes messages from the message cache, retrieves the consumed messages from the message cache, and updates the event cache to indicate that the event indicated by the event cache has been processed. This may cause the scheduling conditions for the task processing unit to no longer be met. Task processing units whose scheduling conditions are no longer met are removed from the ready list.
[0111] During the function execution process of the task processing unit, new messages are generated and sent to itself or other task processing units. The task processing unit sends the generated messages to itself or other task processing units by calling the API of the task management unit. For example, see Figure 5 , the task processing unit 520 calls the API 510 to send a message. When calling the API 510, the task processing unit 520 also specifies the task processing unit that receives the message.
[0112] Figure 5 Four task management units are shown. These task management units can run on the same or different CPU cores.
[0113] Figure 6 This is a flowchart of a task scheduling system according to an embodiment of the present application.
[0114] According to an embodiment of the present application, during the initialization phase, one or more task processing units are registered (610) through an API provided by a task management unit. In response, the API processing unit of the task management unit records the registered task processing units in a task processing unit linked list. It is understood that after the initialization phase, one or more task processing units may still be registered. Alternatively, the registration of one or more task processing units may be canceled through the API provided by the task management unit.
[0115] The API processing unit also provides messages and / or events (620) to the task processing unit in response to the API call, maintains information of the task processing unit based on the provided messages and / or events (630), including, for example, updating the bitmap, message cache, and / or event cache of the task processing unit, and also records the task processing unit whose scheduled conditions are met in the ready list. Optionally, the API processing unit also deletes the messages and / or events provided to the task processing unit in response to the API call, and also removes the task processing unit whose scheduled conditions are no longer met from the ready list.
[0116] The scheduling unit of the task management unit selects a task processing unit from the ready list (650) and runs the function of the selected task processing unit (660). During execution, the function of the task processing unit may call itself or provide messages and / or events to the task processing unit through APIs provided by other task management units (indicated by the dotted arrow from box 660 to box 620). Optionally, after running the task processing unit, the task scheduling unit also checks whether the scheduling conditions of the running task processing unit are met, and removes the task processing unit whose scheduling conditions are no longer met from the ready list.
[0117] Figure 7A and Figure 7BIt is a schematic diagram of resource allocation according to an embodiment of the present application.
[0118] According to an embodiment of the present application, the task management unit includes one or more producer task processing units to manage the allocation of resources. The resources of the task scheduling system include, for example, cache units, descriptors (or contexts) for processing tasks, cache containers, etc.
[0119] Optionally, a producer task processing unit is a type of task processing unit that is created by the task management unit during initialization and is also recorded in the task processing unit linked list. In contrast to the producer task processing unit, a consumer task processing unit is also a type of task processing unit that is registered with the task management unit from outside the task management unit.
[0120] The task management unit manages the producer task processing unit and / or the consumer task processing unit in, for example, the same manner.
[0121] according to Figure 7A In an embodiment, the producer task processing unit 710 proactively provides available resources to the consumer task processing units (712, 714) via messages. For example, the existence of available resources is a condition for the producer task processing unit 710 to be scheduled. When the producer task processing unit 710 is scheduled, it provides instances of available resources to the consumer task processing unit 712 and / or the consumer task processing unit 714, wherein the message representing the available resource instance is provided to the consumer task processing unit by calling the API of the task management unit.
[0122] according to Figure 7B In an embodiment, the producer task processing unit 720 provides available resources to the consumer task processing unit (722, 724) through a message based on the request for resources by the consumer task processing unit. The conditions for scheduling the producer task processing unit include the availability of available resources and the request for resources by the consumer task processing unit. Thus, the message of releasing resources is provided to the producer task processing unit 720 through the API of the task management unit, so that the producer task processing unit 720 is aware of all released available resources. The message of requesting resources is also provided to the producer task processing unit 720 through the API. The message of requesting resources is generated by the consumer task processing unit (722, 724) and provided to the producer task processing unit 720.
[0123] After being called, the producer task processing unit 720 sends available resources to the consumer task processing unit 722 and / or the consumer task processing unit 724 via a message. Optionally, the producer task processing unit 720 maintains a priority or selection strategy for providing messages indicating available resource instances to the consumer task processing unit 722 and the consumer task processing unit 724.
[0124] The conditions for scheduling the consumer task processing units (722, 724) include the availability of resources. Therefore, when the producer task processing unit 720 provides a message indicating the availability of resources to the consumer task processing units (722, 724), the conditions for scheduling the consumer task processing units (722, 724) are met. It is understood that the conditions for scheduling the consumer task processing units (722, 724) may include other conditions.
[0125] The task management unit schedules the consumer task processing units (722, 724) in the ready list. During execution, the consumer task processing units (722, 724) consume the available resources provided to them and provide new resource request messages to the producer task processing unit 720. Due to the consumption of available resources, the scheduling conditions of the consumer task processing units (722, 724) become unsatisfied, and they are removed from the ready list and wait for the producer task processing unit 720 to provide them with new messages indicating available resources.
[0126] Figure 8 Schematic diagram of processing tasks using a task scheduling system according to an embodiment of the present application.
[0127] according to Figure 8 The task scheduling system of the embodiment is used to process IO commands. For example, the task scheduling system includes four task processing units (810, 812, 814, and 816), which are respectively used to process the first stage (stage 1), the second stage (stage 2), the third stage (stage 3), and the fourth stage (stage 4) of the IO commands.
[0128] As an example, the IO command is a write command. In response to receiving the IO command to be processed, an IO command context (referred to as command context) is allocated to the IO command in stage 1. In response to obtaining the command context, a cache is allocated to the IO command in stage 2, and the cache is used to accommodate the data to be written by the IO command. In response to obtaining the cache and the DMA unit being available, a DMA transfer is initiated in stage 3 to move the data to be written by the IO command to the cache. In response to the DMA unit completing the operation of moving the IO command to the cache and having an available cache container, in stage 4, the cache allocated to the IO command is bound to the cache container. Cache containers are introduced in Chinese patent applications No. 201811154294.8, 201811203693.9, 201811497635.1 and 201811496068.8, the entire text of which is incorporated herein by reference.
[0129] according to Figure 8The task scheduling system of the embodiment further includes three producer task processing units (820, 822 and 824). The command context allocation task processing unit 820 is used for active (see also Figure 7A ) provides available command context to the task scheduling unit 810. The cache allocation task processing unit 822 is used to provide available cache to the task scheduling unit 812. The container allocation task processing unit 824 is used to provide available cache containers to the task processing unit 816.
[0130] The scheduling conditions of the task processing unit 810 are that there is an available command context and a new IO command is to be processed. The task processing unit 810 includes a message buffer for recording messages indicating the available command context. The command processing unit 810 also includes an event buffer for recording whether there is an IO command to be processed. If a message indicating the available command context provided by the command context allocation task processing unit 820 is received, and an event indicating that a new IO command is to be processed is received, the scheduling conditions of the task processing unit 810 are met and the task processing unit 810 is placed in the ready list. The task scheduling unit thus has the opportunity to obtain and execute the task processing unit 810 from the ready list. The execution of the task processing unit 810 consumes the command context, adds new content to the command context (for example, information obtained according to the IO command), and provides the updated command context to the task processing unit 812 through the API of the task scheduling system. The event of a new IO command to be processed is provided to the task processing unit 810 by, for example, an interrupt.
[0131] The scheduling conditions for task processing unit 812 are the availability of a command context and an available cache. The command context required by task processing unit 812 is the command context provided to task processing unit 810 by task processing unit 810. Therefore, task processing unit 812 includes two message buffers, one for recording messages indicating the command context and the other for recording messages indicating the available cache. Task processing unit 812 does not include an event buffer. If task processing unit 812 receives a message indicating the command context provided by task processing unit 810 and a message indicating the available cache provided by cache allocation task processing unit 822, the scheduling conditions for task processing unit 812 are met and task processing unit 812 is placed in the ready list. The task scheduling unit then has the opportunity to retrieve and execute task processing unit 812 from the ready list. The execution of task processing unit 812 consumes the command context and cache, adds new content to the command context (e.g., the cache index), and provides the updated command context to task processing unit 814 via the task scheduling system's API.
[0132] The conditions for task processing unit 814 to be scheduled are the availability of a command context and the availability of the DMA unit. The command context required by task processing unit 814 is the command context provided to it by task processing unit 812. Therefore, task processing unit 814 includes a message buffer for recording messages indicating the command context. Task processing unit 814 also includes an event buffer for recording whether the DMA unit is available. If task processing unit 814 receives a message indicating the command context provided by task processing unit 812 and the DMA unit is available, the scheduling conditions for task processing unit 814 are met and it is placed in the ready list. The task scheduling unit then has the opportunity to retrieve and execute task processing unit 814 from the ready list. During execution, task processing unit 814 uses the DMA unit to initiate data transfers from the host to the cache. Optionally, the task processing unit also provides the command context to the DMA unit, so that after the DMA unit completes the data transfer, it also provides the command context to indicate which command context the completed data transfer is associated with. The event indicating the availability of the DMA unit is provided to task processing unit 814, for example, by an interrupt.
[0133] The conditions for task processing unit 816 to be scheduled are the availability of a buffer container and the completion of a DMA transfer. The buffer container required by task processing unit 816 is the command context provided to task processing unit 816 by container allocation task processing unit 824. Therefore, task processing unit 816 includes a message buffer for recording messages indicating the buffer container. Task processing unit 816 also includes an event buffer for recording whether the DMA unit's DMA transfer is complete. If task processing unit 816 receives a message indicating the buffer container provided by container allocation task processing unit 824, and the DMA unit's DMA transfer is complete, the scheduling conditions for task processing unit 816 are met and the task processing unit is placed in the ready list. The task scheduling unit then has the opportunity to retrieve and execute task processing unit 816 from the ready list. During execution, task processing unit 816 retrieves the command context provided by the DMA unit and binds the buffer filled with data by the DMA unit to the buffer container. The event indicating the completion of the DMA unit's DMA transfer is provided to task processing unit 816, for example, by an interrupt.
[0134] It is understandable that the task scheduling system also includes other task processing units to continue processing IO commands. The execution of some task processing units generates released resources, and the released resources are indicated by messages provided to the producer task processing units (command context allocation task processing unit 820, cache allocation task processing unit 822, container allocation task processing unit 824). In response to the message indicating the released resources, the scheduling conditions of the producer task processing unit are met and it is placed in the ready list. The task scheduling unit thus has the opportunity to obtain and execute the producer task processing unit (command context allocation task processing unit 820, cache allocation task processing unit 822, container allocation task processing unit 824) from the ready list. During the execution of the producer task processing unit (command context allocation task processing unit 820, cache allocation task processing unit 822, container allocation task processing unit 824), messages are generated and provided to, for example, task processing units (810, 812, 816) to provide each task processing unit with the resources it needs.
[0135] In addition to being applied to storage devices, the embodiments of the present application are also applicable to task scheduling in other electronic devices such as computers, servers, and network devices.
[0136] An embodiment of the present application further provides a program including program code. When the program is loaded into an electronic device and executed on the electronic device, the program code enables the electronic device to execute the method described above.
[0137] It should be understood that each block of the block diagrams and flow charts, and combinations of blocks of the block diagrams and flow charts, can be implemented by various means including program instructions. These program instructions can be loaded onto a general-purpose computer, a special-purpose computer, or other programmable data control device to produce a machine, so that the instructions executed on the computer or other programmable data control device create a means for implementing the functions specified in one or more flow chart blocks.
[0138] Thus, the blocks of the block diagrams and flow charts support combinations of means for performing the specified functions, combinations of operations for performing the specified functions, and combinations of program instruction means for performing the specified functions. It should also be understood that each block of the block diagrams and flow charts, and combinations of blocks of the block diagrams and flow charts, can be implemented by a hardware-based special-purpose computer system that performs the specified functions or operations, or by a combination of special-purpose hardware and computer instructions.
[0139] At least a portion of the various blocks, operations, and techniques described above may be implemented using hardware, a control device executing firmware instructions, a control device executing software instructions, or any combination thereof. When implemented using a control device executing firmware and software instructions, the software or firmware instructions may be stored in any computer-readable storage medium, such as a disk, optical disk, or other storage medium, in RAM or ROM or flash memory, a control device, a hard disk, optical disk, or disk, etc. Similarly, the software and firmware instructions may be transmitted to a user or system using any known or desired transmission method. The software or firmware instructions may include machine-readable instructions that, when executed by the control device, cause the control device to perform various actions.
[0140] When implemented in hardware, the hardware may include one or more discrete components, an integrated circuit, an application specific integrated circuit (ASIC), and the like.
[0141] It should be understood that the present application can be implemented in pure software, pure hardware, firmware, or any combination thereof. Hardware may be, for example, a control device, a dedicated integrated circuit, a large-scale integrated circuit, or the like.
[0142] Although the present application has been described with reference to examples, this is for illustrative purposes only and is not intended to limit the present application, and changes, additions and / or deletions to the embodiments may be made without departing from the scope of the present application.
[0143] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A task scheduling method, comprising the following steps: In response to receiving a message and / or event provided to a consumer task processing unit, the cache of the consumer task processing unit records the message and / or event and updates the state of the consumer task processing unit; Scheduling a consumer task processing unit that is in a schedulable state and executing a function of the scheduled consumer task processing unit to process a stage of the IO command, wherein all consumer task processing units process different stages of the IO command; The execution of the consumer task processing unit generates released resources, and in response to a message indicating the released resources, the scheduling condition of the producer task processing unit is satisfied; Scheduling the producer task processing unit in a schedulable state, executing the producer task processing unit, and generating a message to be provided to the consumer task processing unit to provide the required resources to the consumer task processing unit; The execution of the consumer task processing unit will generate new messages, and the new messages will be recorded in the cache of another consumer task processing unit.
2. The task scheduling method according to claim 1, wherein: In response to the API providing the deletion message and / or deletion event to the task processing unit being called, the message and / or event provided to the task processing unit is deleted, and the state of the task processing unit is updated.
3. The task scheduling method according to claim 1, wherein: If all message buffers of a task processing unit are filled and all event buffers thereof indicate that an event has occurred, the task processing unit is in a schedulable state.
4. One of the task scheduling methods according to claim 1-3, wherein: In response to identifying that the task processing unit is in a schedulable state, the task processing unit in the schedulable state is removed from the task processing unit linked list and added to the ready linked list, so that the task processing unit is scheduled from the ready linked list.
5. One of the task scheduling methods according to claim 1-3, wherein: The scheduled consumer task processing unit generates a message requesting resources and provides it to the producer task processing unit.
6. One of the task scheduling methods according to claim 1-3, wherein: If there are available resources and a message from a consumer task processing unit requesting resources, the producer task processing unit is in a schedulable state.
7. One of the task scheduling methods according to claims 1-3, wherein: The consumer task processing unit calls an API to provide a message requesting resources to the producer task processing unit, so that the producer task processing unit provides it with a message representing available resources.
8. One of the task scheduling methods according to claim 1-3, wherein: If there is a message representing available resources or an event that there is a message representing available resources and an IO command to be processed, the consumer task processing unit is in a schedulable state.
9. A task scheduling system comprising: A task management unit and multiple producer task processing units and multiple consumer task processing units, wherein the task management unit includes an API processing unit, a scheduling unit, and multiple APIs; In response to an API being called to provide a message and / or event to a consumer task processing unit, the API processing unit records the message and / or event in a cache of the consumer task processing unit and updates a state of the consumer task processing unit; The scheduling unit schedules the consumer task processing unit in a schedulable state and executes the function of the scheduled consumer task processing unit to process a stage of the IO command. All consumer task processing units process different stages of the IO command. The execution of the consumer task processing unit generates released resources, and in response to a message indicating the released resources, the scheduling condition of the producer task processing unit is satisfied; The scheduling unit schedules the producer task processing unit in a schedulable state, executes the function of the producer task processing unit, generates a message to be provided to the consumer task processing unit, and provides the required resources to the consumer task processing unit; The execution of the consumer task processing unit generates a new message, and the API processing unit records the new message in the cache of another consumer task processing unit.
Citation Information
Patent Citations
Multi-stream storage device based on unified cache architecture
CN110968520B
Cache provided by FTL, its optimization method and storage device
CN110968525B
Lightweight operating system for embedded multicore central processing unit
CN108958905A