Poller management method, device, medium and computer program product

By receiving the task callback function and dynamic management task list configured by the user thread, it solves the problem of lack of priority and dynamic management of task scheduling in poller management, realizes task priority scheduling and dynamic management under limited hardware resources, and simplifies the operation process.

CN118277067BActive Publication Date: 2024-09-03JINAN INSPUR DATA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410704396.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-03
Publication Date
2024-09-03
Estimated Expiration
2044-06-03

AI Technical Summary

Technical Problem

Under the limited computer hardware resources, the existing poller management method lacks priority differentiation in task scheduling, cannot dynamically add or remove tasks, and the code operation is complex and inconvenient to maintain.

Method used

By receiving the task registration and cancellation callback functions configured by user threads, dynamically manage the task list, perform polling scheduling according to task priority, support dynamic addition and removal of tasks, without modifying the poller-related source code, and use multi-threading and message communication mode to improve efficiency.

Benefits of technology

It realizes priority management of task scheduling, supports dynamic task management, simplifies the operation process, and improves resource utilization and maintenance convenience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118277067B
    Figure CN118277067B
Patent Text Reader

Abstract

The present invention relates to the technical field of computer data storage, and discloses a poller management method, device, medium and computer program product, including: receiving a task registration callback function sent by a user thread; obtaining a corresponding task list according to a priority parameter in the attribute information of the task to be registered; the task priorities managed by each task list are different; each task is polled and scheduled by the core thread of the poller according to the priority; adding the task to be registered to the corresponding task list; receiving a task cancellation callback function sent by a user thread; traversing all task lists, and obtaining the existing task identity information in the task list one by one; when the identity information of the task to be destroyed matches the existing task identity information, deleting the task with the same identity match from the corresponding task list. In this way, it supports dynamically adding and removing tasks to the corresponding task list without modifying the relevant source code of the poller, and can realize the priority of task scheduling.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of computer data storage, and in particular to a poller management method, device, medium and computer program product. Background Art

[0002] In the field of computer data storage technology, there are often a large number of repetitive tasks that need to be processed by the central processing unit, but in fact, computer hardware resources are always limited. In order to give full play to the performance of data storage software on limited computer hardware resources, a large loop operation mode is usually adopted to handle repetitive tasks, that is, a single central processing unit core is used to run the loop mode, and constantly poll to process pending tasks. When the task function is simple, the large loop method can meet the requirements, but when the task function is complex and diverse and the scheduling priority requirements are high, this level of architecture will have great defects, such as no priority distinction between the execution of each task, complex code addition and deletion operations, and no support for dynamic addition or removal of tasks.

[0003] It can be seen that under the objective conditions of limited computer hardware resources, how to solve the above-mentioned defects of the large-loop operation mode is a technical problem that people in this field urgently need to solve. Summary of the invention

[0004] The purpose of the present invention is to provide a poller management method, device, medium and computer program product, which can realize the priority of task scheduling, support dynamic addition and removal of tasks to the corresponding task list, without modifying the relevant source code of the poller, and the process operation is simple and maintenance is convenient.

[0005] In order to solve the above technical problems, the present invention provides a poller management method, the method comprising:

[0006] The task registration callback function that receives the user thread configuration and sends it as a message;

[0007] According to the priority parameter in the attribute information of the task to be registered of the task registration callback function, the corresponding task chain list is obtained; the tasks managed by each task chain list have different priorities; the tasks in each task chain list are polled and scheduled by the poller core thread according to the priority;

[0008] Add the task to be registered corresponding to the task registration callback function to the acquired task linked list;

[0009] The task cancellation callback function that receives the user thread configuration and sends it as a message;

[0010] Traverse all task lists and obtain the existing task identity information in the task list one by one;

[0011] When the identity information of the task to be destroyed in the task cancellation callback function matches the identity information of the existing task, the task with the same identity information is deleted from the corresponding task chain list.

[0012] In a first aspect, in the poller management method provided by the present invention, before receiving the task registration callback function configured by the user thread and sent in the form of a message, it also includes:

[0013] Initializing a plurality of task linked lists; the plurality of task linked lists include a first task linked list for managing high priority tasks, a second task linked list for managing medium priority tasks, and a third task linked list for managing low priority tasks;

[0014] The poller core thread is created, and the CPU affinity of the poller core thread is configured, and a CPU core is bound to the poller core thread.

[0015] On the other hand, in the poller management method provided by the present invention, the process of configuring the task registration callback function by the user thread includes:

[0016] The user thread allocates a memory for storing attribute information of the task to be registered and the first communication message;

[0017] Initialize the attribute information of the task to be registered; the attribute information of the task to be registered includes the running state, identity, priority, execution mode, execution required parameters, execution cycle, and set execution time point of the task to be registered; the attribute information of the task to be registered is used as parameter information of the task registration callback function;

[0018] Initialize the first communication message; the first communication message includes a task attribute information reference and a first task method reference; the task attribute information reference points to the initialized task attribute information block to be registered, and the first task method reference points to the task registration callback function.

[0019] On the other hand, in the poller management method provided by the present invention, the process of configuring the task cancellation callback function by the user thread includes:

[0020] The user thread allocates memory for storing the identity information of the task to be destroyed and the second communication message;

[0021] Initialize the identity information of the task to be destroyed; use the identity information of the task to be destroyed as parameter information of the task cancellation callback function;

[0022] Initialize the second communication message; the second communication message includes a task identity information reference and a second task method reference; the task identity information reference points to the initialized task identity information block to be destroyed, and the second task method reference points to the task cancellation callback function.

[0023] On the other hand, in the poller management method provided by the present invention, adding the task to be registered corresponding to the task registration callback function to the acquired task linked list includes:

[0024] The state of the task to be registered corresponding to the task registration callback function is set to a waiting state, and the task to be registered is added to the tail of the acquired task chain list, waiting for scheduling execution;

[0025] When the task to be registered is scheduled, the state of the task to be registered is adjusted to the running state, and then restored to the waiting state after execution is completed.

[0026] On the other hand, in the poller management method provided by the present invention, the tasks in each task list are polled and scheduled by the poller core thread according to the priority, including:

[0027] The poller core thread uses a two-level loop to manage the priority of each task list;

[0028] The two-level loop includes an outer loop and an inner loop; the outer loop polls all task linked lists in a set order, and the inner loop polls the tasks on each task linked list.

[0029] On the other hand, in the above poller management method provided by the present invention, it also includes:

[0030] Traversing all task linked lists, and scheduling the current task in the task linked list according to the task priority management strategy; the scheduling number of the first task linked list in the task priority management strategy is greater than the scheduling number of the second task linked list, and the scheduling number of the second task linked list is greater than the scheduling number of the third task linked list;

[0031] Get the type of the current task and execute the corresponding task execution method according to the type.

[0032] On the other hand, in the poller management method provided by the present invention, obtaining the type of the current task includes:

[0033] If the current task is a preset task that is executed only once at a specified future set time point, the current task is determined to be a scheduled task;

[0034] If the current task is a preset task to be executed once every set time interval in the future, the current task is determined to be a periodic task;

[0035] If the current task is a task that has no time requirement and needs to be executed only once, then the current task is determined to be a scheduled task.

[0036] On the other hand, in the poller management method provided by the present invention, executing a corresponding task execution mode according to the type includes:

[0037] If the current task is a scheduled task, determine whether the set time point has arrived;

[0038] If the set time point arrives, the scheduled task is scheduled, and the state of the scheduled task is set to the running state, and the scheduled task is executed. After the execution is completed, the state of the scheduled task is adjusted to the waiting state, and the scheduled task is deleted; if the set time point is not arrived, the next task is scheduled;

[0039] If the current task is a periodic task, determine whether the periodic time has arrived;

[0040] If the cycle time is reached, the periodic task is scheduled, and the state of the periodic task is set to the running state, and the periodic task is executed. After the execution is completed, the state of the periodic task is adjusted to the waiting state, and the next task is scheduled; if the cycle time is not reached, the next task is continuously scheduled;

[0041] If the current task is a real-time task, the real-time task is directly scheduled, and the state of the real-time task is set to the running state, and the real-time task is executed. After the execution is completed, the state of the real-time task is adjusted to the waiting state, and the real-time task is deleted, and the next task is scheduled.

[0042] On the other hand, in the poller management method provided by the present invention, deleting tasks with the same identity identifier from the corresponding task list includes:

[0043] Determine that the tasks with the same identity information are tasks to be destroyed;

[0044] Release the attribute information memory resource of the task to be destroyed from the task chain list where the task to be destroyed is located;

[0045] At the same time, the identity memory resource of the task to be destroyed is released.

[0046] On the other hand, in the above poller management method provided by the present invention, it also includes:

[0047] When receiving a stop instruction sent by a user thread, determining whether the poller core thread exists;

[0048] If the poller core thread exists, determine whether the current task has been processed;

[0049] If the current task processing is completed, the poller core thread is destroyed, including recycling the poller core thread and registered task-related resources;

[0050] If the current task is not processed completely, the poller core thread is destroyed after the current task is processed completely.

[0051] On the other hand, in the above poller management method provided by the present invention, it also includes:

[0052] If the poller core thread does not exist, determine whether there is a message being sent or received; or, after destroying the poller core thread, determine whether there is a message being sent or received;

[0053] If a message is being sent or received, wait for the current message sending or receiving process to complete;

[0054] If no message is being sent or received, the task list is destroyed directly.

[0055] In order to solve the above technical problems, the present invention further provides a poller management device, the device comprising:

[0056] Memory for storing computer programs;

[0057] A processor is used to implement the steps of the above-mentioned poller management method when executing the computer program.

[0058] In order to solve the above technical problem, the present invention further provides a non-volatile storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above polling device management method are implemented.

[0059] In order to solve the above technical problem, the present invention also provides a computer program product, including a computer program / instruction, which implements the steps of the above poller management method when executed by a processor.

[0060] It can be seen from the above technical scheme that the present invention provides a poller management method, which includes: receiving a task registration callback function configured by a user thread and sent in the form of a message; obtaining a corresponding task list according to a priority parameter in the attribute information of the task to be registered of the task registration callback function; the tasks managed by each task list have different priorities; the tasks in each task list are polled and scheduled by the poller core thread according to the priority; the task to be registered corresponding to the task registration callback function is added to the acquired task list; receiving a task cancellation callback function configured by a user thread and sent in the form of a message; traversing all task lists and obtaining the existing task identity information in the task list one by one; when the task identity information to be destroyed of the task cancellation callback function matches the existing task identity information, deleting the tasks with the same identity match from the corresponding task list.

[0061] The beneficial effect of the present invention lies in that the above-mentioned poller management method provided by the present invention can receive the corresponding task registration callback function, obtain the corresponding task list according to the priority parameter in the task attribute information, and support dynamic addition of tasks to the corresponding task list. Compared with the traditional scheme, the dynamic addition of tasks does not require modification of the relevant source code of the poller, and the tasks managed by each task list in the poller have different priorities. The tasks in each task list are polled and scheduled by the core thread of the poller according to the priority. In this way, the tasks in the task list support a scheduling method with priority, and urgent and important tasks of users with different priorities can be scheduled first; in addition, the corresponding task cancellation callback function can also be received. When a task with the same identity mark information is matched, it supports dynamic removal of the task from the corresponding task list. Compared with the traditional scheme, the dynamic removal of tasks does not require modification of the relevant source code of the poller. In this way, the priority of task scheduling can be realized under the objective conditions of limited computer resources, and dynamic addition and removal of tasks are supported without modifying the source code. The whole process is simple to operate and convenient to maintain.

[0062] In addition, the present invention also provides a corresponding poller management device, a non-volatile storage medium and a computer program product for the poller management method, which have the same or corresponding technical features as the above-mentioned poller management method and have the same effects as above. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] In order to more clearly illustrate the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. 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.

[0064] Figure 1 A schematic diagram of the existing poller management framework;

[0065] Figure 2 A specific flow chart of the poller management method provided by an embodiment of the present invention;

[0066] Figure 3 A schematic diagram of a poller management framework provided by an embodiment of the present invention;

[0067] Figure 4 A schematic diagram of the framework of a user thread and a poller thread provided by an embodiment of the present invention;

[0068] Figure 5 A task management logic diagram provided for an embodiment of the present invention;

[0069] Figure 6 A schematic diagram of the structure of a poller management device provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0070] Figure 1 The following is a schematic diagram of the existing poller management framework. Figure 1 As shown in the figure, Task A (task_A), Task B (task_B), Task C (task_C), and Task D (task_D) are tasks that need to be executed repeatedly. The poller is the main thread that runs the large loop. It usually executes Task A, Task B, Task C, and Task D in turn through a while (a basic loop mode of a computer) loop. There is no scheduling priority distinction for the execution of each task. Urgent and important tasks cannot be scheduled in time, and unurgent and unimportant tasks still have the same scheduling status. If the business adjustment requires the addition of Task E (task_E), in addition to developing the code of Task E, the code of the poller main thread needs to be modified at the same time to add Task E to the poller large loop. That is, dynamic addition of Task E is not supported, and the relevant code can only be modified and recompiled. If the business adjustment requires the removal of Task A, the code of the poller main thread still needs to be modified. That is, once a task is added to the poller large loop, it does not support dynamic cancellation of the task, and the relevant code can only be modified and recompiled. This makes the coupling between each task and the poller main thread large, which is not conducive to code development and maintenance.

[0071] Based on this, the present invention provides a poller management method, device, medium and computer program product to solve the technical problems that the execution of each task in the above-mentioned poller management has no scheduling priority distinction, the operation of adding and deleting code is complicated, and dynamic addition or removal of tasks is not supported.

[0072] 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.

[0073] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods. Figure 2 A flowchart of a poller management method provided by an embodiment of the present invention, such as Figure 2 As shown, the method includes:

[0074] S201, receiving the task registration callback function configured by the user thread and sent in the form of a message.

[0075] Figure 3 Schematic diagram of the poller management framework provided by the embodiment of the present invention. Figure 3 As shown, the poller can be used as an independent module to run a large loop. Task A, Task B, Task C and Task D are independent of the poller and have no direct coupling.

[0076] It should be noted that the execution subject of the present invention can be understood as a poller management module. The task registration callback function is configured by the user thread, and then sent by the user thread to the poller management module in the form of a message. The task registration callback function sent in the form of a message here can be understood as a first communication message. That is: after the poller management module is enabled, the poller management module process (thread-manage) is pulled up, and the user thread (thread-user) sends the first communication message to the poller management module. After the poller management module receives the first communication message, the poller core thread (thread-poller) executes the subsequent steps. The poller core thread refers to the thread that executes the polling task of the poller. The core thread refers to the thread in the thread pool that will not be destroyed even if the thread is idle, unless the thread pool is closed. These threads will always wait for tasks in the thread pool. Once a task is submitted, they will start executing immediately.

[0077] In addition, it should be noted that the poller management module of the present invention has a message communication interface (also referred to as a management control command interface) for data communication with user threads. The message communication interface here does not use the traditional socket communication mode, but uses the communication mode of the lock-free circular queue (rte_ring) in the open source Data Plane Development Kit (DPDK). This mode is a thread-to-thread communication mode that supports multiple producers and multiple consumers. It does not require locking in multi-threaded concurrent scenarios, and can effectively avoid resource competition. In implementation, the message communication interface of the present invention may include a dynamic registration interface and a dynamic deregistration interface, that is, it supports multiple user threads to concurrently register tasks or deregister tasks, which can effectively improve data communication efficiency.

[0078] When executing step S201, a dynamic registration interface may be used to receive user thread configuration and send a task registration callback function in the form of a message.

[0079] S202. Obtain the corresponding task linked list according to the priority parameter in the attribute information of the task to be registered of the task registration callback function; each task linked list manages tasks with different priorities; and the tasks in each task linked list are polled and scheduled by the poller core thread according to the priority.

[0080] It should be noted that each task list can manage tasks of different priorities, such as high-priority tasks, medium-priority tasks, and low-priority tasks; of course, it can also be tasks of other priorities, which are not limited here. Tasks in each task list can be scheduled by the poller core thread according to the priority of the task, that is, high-priority tasks are scheduled first, then medium-priority tasks, and finally low-priority tasks. In this way, the execution of each task has a scheduling priority distinction, and urgent and important tasks can be scheduled in time. The attribute information of each task has parameters about priority (such as the priority field), and the priority of the task list where the task is located can be obtained based on the parameter.

[0081] When executing step S202, the priority parameter in the attribute information of the task to be registered of the task registration callback function can be first extracted, and then the corresponding task chain list can be obtained according to the priority parameter. If the priority parameter corresponds to a high priority, the obtained task chain list is a task chain list for managing high priority tasks; if the priority parameter corresponds to a medium priority, the obtained task chain list is a task chain list for managing medium priority tasks; if the priority parameter corresponds to a low priority, the obtained task chain list is a task chain list for managing low priority tasks.

[0082] S203: Add the task to be registered corresponding to the task registration callback function to the acquired task linked list.

[0083] In implementation, after the corresponding task linked list is obtained, the task to be registered can be directly added to the task linked list when executing step S203, waiting for scheduling execution.

[0084] S204: Receive the task cancellation callback function configured by the user thread and sent in the form of a message.

[0085] In implementation, when executing step S204, the dynamic deregistration interface can be used to receive the task deregistration callback function configured by the user thread and sent in the form of a message. The task deregistration callback function is configured by the user thread, and then sent by the user thread to the poller management module in the form of a message. The task deregistration callback function sent in the form of a message here can be understood as a second communication message. That is, the user thread sends the second communication message to the poller management module, and after the poller management module receives the second communication message, the poller core thread executes the subsequent steps.

[0086] S205, traverse all task chain lists, and obtain existing task identity information in the task chain lists one by one.

[0087] In the implementation, all task lists are traversed, including multiple task lists of different priorities. No requirement is made on the traversal strategy here. The purpose is to obtain the existing task identities in the task list one by one to facilitate subsequent matching operations.

[0088] S206: When the identity information of the task to be destroyed in the task cancellation callback function matches the identity information of the existing task, the task with the same identity information is deleted from the corresponding task linked list.

[0089] In implementation, if the identity information of the task to be destroyed is consistent with the identity information of the task already existing in the task chain list, it is considered that the task to be destroyed is matched, and then the tasks in the task chain list whose task identities match the task to be destroyed can be deleted.

[0090] In the above-mentioned poller management method provided by the embodiment of the present invention, a corresponding task registration callback function can be received, and the corresponding task list can be obtained according to the priority parameter in the task attribute information, and it supports dynamically adding tasks to the corresponding task list. Compared with the traditional scheme, dynamically adding tasks does not require modifying the relevant source code of the poller, and the tasks managed by each task list in the poller have different priorities. The tasks in each task list are polled and scheduled by the core thread of the poller according to the priority. In this way, the tasks in the task list support a scheduling method with priority, and urgent and important tasks of tasks of different priorities can be scheduled first; in addition, a corresponding task cancellation callback function can also be received. When a task with the same identity mark information is matched, it supports dynamically removing the task from the corresponding task list. Compared with the traditional scheme, dynamically removing tasks does not require modifying the relevant source code of the poller. In this way, the priority of task scheduling can be realized under the objective conditions of limited computer resources, and it supports dynamic addition and removal of tasks without modifying the source code. The whole process is simple to operate and convenient to maintain.

[0091] Figure 4 A schematic diagram of the framework of the user thread and the poller thread provided by the embodiment of the present invention. The poller management module running the poller thread may include a communication unit, a core control unit, a priority control unit, a timed task processing unit, a periodic task processing unit, and a real-time task processing unit. The poller management module directly supports two types of interfaces, the control plane and the data plane, externally. The control plane belongs to the scope of the poller management module and mainly provides the message communication interface of the poller management module, including four types of starting the poller, stopping the poller, dynamic registration tasks, and dynamic cancellation tasks; the data plane belongs to the scope of user services and does not belong to the scope of the poller management module. It mainly provides data input and data output functions, and interacts with the poller management module through the transmission channel. That is, the data plane is optional, and only tasks with data interaction (data interaction between the user thread and the poller main thread) are required. The communication unit is mainly used for direct command communication between the user thread and the poller thread in the poller management module, that is, receiving control instructions outside the module. The core control unit is mainly responsible for starting and stopping the poller management module, registering and unregistering tasks, allocating and recycling resources for tasks, and managing the status of tasks. The priority control unit is used to manage the priority of tasks that have been registered to the poller management module and provide task priority scheduling strategies. The scheduled task processing unit is used to process scheduled tasks. The periodic task processing unit is used to process periodic tasks. The real-time task processing unit is used to process real-time tasks. This makes the poller management function modular, greatly reducing the coupling between other functional modules in the project code, providing a standard control interface to the outside world, facilitating maintenance, and having strong scalability.

[0092] Furthermore, in a specific implementation, in the above-mentioned poller management method provided in an embodiment of the present invention, before executing step S201 to receive the user thread configuration and send the task registration callback function in the form of a message, it may also include: initializing multiple task lists; the multiple task lists include a first task list for managing high-priority tasks, a second task list for managing medium-priority tasks, and a third task list for managing low-priority tasks; in addition, creating a poller core thread, and configuring the CPU affinity of the poller core thread, and binding a CPU core to the poller core thread.

[0093] In the implementation, first, three task lists of different priorities can be initialized, including the first task list (i.e., the high priority task list list-high), the second task list (i.e., the medium priority task list list-middle) and the third task list (i.e., the low priority task list list-low). Then create a message communication interface for data communication with the user thread. Then create the poller core thread, and finally configure the CPU affinity of the poller core thread, bind the poller core thread to a CPU core, ensure that the poller core thread always occupies the CPU, and prevent the poller core thread from being blocked and waiting for CPU resources due to system scheduling and other reasons. Since then, the poller management module has been started and the poller core thread has started to run.

[0094] Furthermore, in a specific implementation, in the above-mentioned poller management method provided by an embodiment of the present invention, in the process of the user thread configuring the task registration callback function in step S201, it can specifically include: the user thread allocates memory for storing the attribute information of the task to be registered and the first communication message; initializes the attribute information of the task to be registered; the attribute information of the task to be registered includes the running status, identity, priority, execution mode, parameters required for execution, execution cycle, and set time point of the task to be registered; the attribute information of the task to be registered is used as parameter information of the task registration callback function; initializes the first communication message; the first communication message includes a task attribute information reference and a first task method reference; the task attribute information reference points to the initialized attribute information block of the task to be registered, and the first task method reference points to the task registration callback function.

[0095] In implementation, during the operation of the poller, when the user thread needs to dynamically register a task to the poller management module, the user thread first allocates a memory for storing the first communication message, and then allocates a memory for storing the task attribute information. The allocation order of the two memory blocks is not required. It is also possible to first allocate a memory for storing the task attribute information, and then allocate a memory for storing the first communication message. Then initialize the relevant attribute information of the task, including the running state (used to record the real-time running state of the task to be registered, which is convenient for task management), the identity (used to distinguish different tasks to be registered, each task to be registered has a unique number, and the identity can be numbered from 1), the task priority (used to indicate the scheduling priority of the task to be registered), the task execution mode (the actual processing method of the task to be registered, such as the processing method configured as the interface input and output request), the parameters required for task execution (the parameter information required when the task to be registered is running, such as the context information configured as the input and output request), the task execution period (only the periodic tasks to be registered need to be configured, marking the period of execution of the task to be registered, such as 100ms), and the set time point of task execution (only the scheduled tasks to be registered need to be configured, marking the time point of execution of the task to be registered). Then initialize the first communication message, including the task attribute information reference and the first task method reference. The task attribute information reference directly points to the previously initialized task attribute information block, and the first task method reference points to the task registration callback function. The task attribute information is used as the parameter information of the task registration callback function. Finally, send the first communication message to the poller management module.

[0096] In actual applications, the task registration callback function is used to dynamically register tasks. In addition, the first task method reference can also be extended to callback functions of other functions, which can be expanded according to actual conditions.

[0097] Further, in a specific implementation, in the above-mentioned poller management method provided by an embodiment of the present invention, in the process of step S204 in which the user thread configures the task cancellation callback function, it can specifically include: the user thread allocates memory for storing the identity information of the task to be destroyed and the second communication message; initializes the identity information of the task to be destroyed; uses the identity information of the task to be destroyed as parameter information of the task cancellation callback function; initializes the second communication message; the second communication message includes a task identity information reference and a second task method reference; the task identity information reference points to the initialized identity information block of the task to be destroyed, and the second task method reference points to the task cancellation callback function.

[0098] In implementation, during the operation of the poller, when the user thread needs to dynamically destroy the task from the poller management module, it is necessary to provide the identity of the task to be destroyed. The user thread first allocates a piece of memory for storing the task identity, and then allocates a piece of memory for storing the second communication message. The allocation order of these two pieces of memory is not required. It is also possible to first allocate a piece of memory for storing the second communication message, and then allocate a piece of memory for storing the task identity. Then initialize the task identity, that is, write the task identity that the user thread is going to destroy into the above-allocated memory area. Then initialize the second communication message, including the task identity information reference and the second task method reference. The task identity information reference directly points to the previously initialized task identity information block, and the second task method reference points to the task cancellation callback function. The task identity information is used as the parameter information of the task cancellation callback function. Finally, send the second communication message to the poller management module.

[0099] In actual applications, the task deregistration callback function is used to dynamically register tasks. In addition, the second task method reference can also be extended to callback functions of other functions, which can be expanded according to actual conditions.

[0100] Furthermore, in a specific implementation, in the above-mentioned poller management method provided in an embodiment of the present invention, step S203 adds the task to be registered corresponding to the task registration callback function to the acquired task list, which may specifically include: setting the state of the task to be registered corresponding to the task registration callback function to a waiting state, and adding the task to be registered to the tail of the acquired task list, waiting for scheduling and execution; when the task to be registered is scheduled, the state of the task to be registered is adjusted to a running state, and then restored to a waiting state after execution is completed.

[0101] In implementation, the status of a task can be divided into three types: INVALID, WAITING, and RUNNING. When a task is just created, it is configured as an invalid state, and its life cycle is from creation to dynamic registration with the poller management module. When a task is dynamically registered with the poller management module, it is adjusted to a waiting state, and its life cycle is the non-running stage from the dynamic registration of the task with the poller to the deregistration of the task. Specifically, the corresponding task list can be obtained according to the task priority parameter (such as field) in the task attribute information, and then the status field in the task attribute information is set to the waiting state, indicating that the current task enters the waiting state, and then the task is added to the end of the corresponding task list, waiting for scheduling and execution. When the task is scheduled, it is adjusted to the running state, and then restored to the waiting state after execution.

[0102] After the poller management module receives the first communication message, the poller core thread executes the task registration callback function. Assuming that the task priority field in the attribute information of the task to be registered is low priority, the task list for managing low priority tasks is obtained according to the field, and then the status field in the attribute information of the task to be registered is adjusted to the waiting state, indicating that the current task to be registered enters the waiting state, and then the task to be registered is added to the tail of the task list for managing low priority tasks, waiting for scheduling and execution. In the same way, other tasks to be registered can also be dynamically registered to the poller management module.

[0103] Figure 5 The following is a schematic diagram of the task management logic provided by the embodiment of the present invention. Figure 5 As shown, the poller management module contains three task lists with different priorities. When the poller management module receives the task registration instruction, that is, after receiving the task registration callback function, it will put it on the corresponding task list according to the priority parameter of the task to be registered. Since the poller core thread always occupies a central processing unit core and continuously loops through the task list, it can be placed at the end of the list. There is no need to sort different tasks in the same task list. When the poller management module receives the task cancellation instruction, that is, after receiving the task cancellation callback function, it will remove it from the task list and release the corresponding system resources.

[0104] Furthermore, in specific implementation, in the above-mentioned poller management method provided in an embodiment of the present invention, the tasks in each task list are polled and scheduled by the poller core thread according to the priority, which may specifically include: the poller core thread adopts a two-level loop to perform priority management of each task list; wherein the two-level loop includes an outer loop and an inner loop; the outer loop polls all task lists in a set order, and the inner loop polls the tasks on each task list.

[0105] It should be noted that, since the poller core thread has been continuously polling multiple task lists, it is impossible to achieve priority management by adjusting the position of the task in the list, so the present invention adopts a two-level loop to reflect the priority management of tasks. The outer loop continuously polls the three task lists, the inner loop polls the tasks on the task list, and the outer loop polls the three task lists in the order of the set order. When the order is set to "high-high-medium-high-high-medium-low", during the outer layer running a lap, the high priority list will be scheduled 4 times, the medium priority list will be scheduled 2 times, and the low priority list will be scheduled 1 time. At this time, the ratio of high, medium and low is 4:2:1, thereby reflecting the priority strategy of the task. When the order is set to "high-high-high-medium-medium-high-high-medium-low", during one lap of the outer layer, the high priority list will be scheduled 5 times, the medium priority list will be scheduled 3 times, and the low priority list will be scheduled 1 time. At this time, the ratio of high, medium and low is 5:3:1, thus reflecting the priority strategy of the task. The setting order here can be determined according to the actual situation and is not limited here.

[0106] It should be emphasized that in the task priority management strategy, the scheduling number of the first task linked list is greater than the scheduling number of the second task linked list, and the scheduling number of the second task linked list is greater than the scheduling number of the third task linked list.

[0107] Furthermore, in specific implementation, the above-mentioned poller management method provided in the embodiment of the present invention may also include: first, traversing all task lists and scheduling the current task in the task list according to the task priority management strategy; then, obtaining the type of the current task and executing the corresponding task execution method according to the type.

[0108] In implementation, the poller core thread repeatedly loops and performs the following actions: when receiving first communication messages in batches, if a new first communication message is received, the method in the first communication message is immediately executed (i.e., the task registration callback function is executed), and the memory resources of the first communication message are released after execution, and all new first communication messages are processed in sequence, and if no new first communication message is obtained, the next link is directly entered. The next link can be to traverse the task list and schedule the next task according to the task priority management strategy, then determine the type of task, and execute the corresponding task execution method according to the type.

[0109] Similarly, when receiving second communication messages in batches, if a new second communication message is received, the method in the second communication message (i.e., the task cancellation callback function) is executed immediately. After execution, the memory resources of the second communication message are released, and all new second communication messages are processed in sequence. If no new second communication message is obtained, the next link is directly entered.

[0110] In the specific implementation, the type of the current task is obtained in the above steps, which may specifically include: if the current task is a preset task that is executed only once at a specified future set time point, then the current task is determined to be a scheduled task; if the current task is a preset task that is executed once at a set time interval in the future, then the current task is determined to be a periodic task; if the current task is a task that has no time requirement and only needs to be executed once (a task that is done whenever there is an opportunity), then the current task is determined to be a scheduled task.

[0111] In specific implementation, the above steps execute the corresponding task execution method according to the type, which may specifically include: if the current task is a scheduled task, then determine whether the set time point has arrived; if the set time point has arrived, schedule the scheduled task, set the state of the scheduled task to the running state, execute the scheduled task, adjust the state of the scheduled task to the waiting state after the execution is completed, and delete the scheduled task; if the set time point has not arrived, continue to schedule the next task; if the current task is a periodic task, then determine whether the cycle time has arrived; if the cycle time has arrived, schedule the periodic task, set the state of the periodic task to the running state, execute the periodic task, adjust the state of the periodic task to the waiting state after the execution is completed, and schedule the next task; if the cycle time has not arrived, continue to schedule the next task; if the current task is a real-time task, directly schedule the real-time task, set the state of the real-time task to the running state, execute the real-time task, adjust the state of the real-time task to the waiting state after the execution is completed, delete the real-time task, and schedule the next task.

[0112] In implementation, if it is a scheduled task, it is further determined whether the scheduled time has arrived. If the scheduled time has arrived, the task is scheduled, and its state is set to the running state, the task execution method of the task is executed, and its state is set to the waiting state after the execution is completed, and the scheduled task is destroyed. The destruction processing action includes: deleting the task from the task list, releasing the attribute information memory resources of the task, and releasing the identity memory resources of the task. If the scheduled time has not arrived, the next task is continued to be scheduled. If it is a periodic task, it is further determined whether the cycle time has arrived. If the cycle time has arrived, the task is scheduled, and its state is set to the running state, and the task execution method of the task is executed, such as receiving input and output requests. After the execution is completed, its state is set to the waiting state, and then the next task is scheduled. If the cycle time has not arrived, the next task is continued to be scheduled. If it is neither a scheduled task nor a periodic task, it is considered to be a real-time task. When a real-time task is scheduled, its state is set to the running state, the task execution method of the task is executed, and its state is set to the waiting state after the execution is completed, and the real-time task is destroyed, and then the next task is scheduled.

[0113] Further, in a specific implementation, in the above-mentioned poller management method provided in an embodiment of the present invention, step S206 deletes tasks with the same identity identifier match from the corresponding task list, which may specifically include: determining that tasks with the same identity identifier information match are tasks to be destroyed; releasing the attribute information memory resources of the tasks to be destroyed from the task list where the tasks to be destroyed are located; and at the same time, releasing the identity identifier memory resources of the tasks to be destroyed.

[0114] In implementation, after the poller management module receives the second communication message, the poller core thread executes the task cancellation callback function. First, traverse all task lists, including three lists of different priorities. There is no requirement for the traversal strategy here. The purpose is to obtain the existing task identity information in the task list one by one. If the identity information of the task to be destroyed is consistent with the task identity information obtained from the task list, it is considered that the task to be destroyed is matched. Next, the following three actions can be performed in sequence: delete the task from the task list. If the task is being executed, it is necessary to wait for the task to be executed. The memory resources of the attribute information of the task are released, and the identity memory resources of the task are released. If no task is matched, continue to traverse the task list until the task to be destroyed is matched. If no task is matched after traversing the task list, it is considered that the task has been destroyed, or it has not been registered, and no action is taken.

[0115] It should be pointed out that in addition to the task registration callback method (user thread dynamically registers tasks to the poller management module) and the task deregistration callback method (user thread deregisters tasks from the poller management module), the present invention also supports the expansion of callback functions that define other functions to implement other control interfaces in addition to dynamic registration of tasks and dynamic deregistration of tasks. The usage method can refer to the above-mentioned task registration callback method and task deregistration callback method.

[0116] Furthermore, in specific implementation, the poller management method provided in the embodiment of the present invention may also include: upon receiving a stop instruction sent by a user thread, determining whether the poller core thread exists; if the poller core thread exists, determining whether the current task has been processed; if the current task has been processed, destroying the poller core thread, including recycling the poller core thread and registered task-related resources; if the current task has not been processed, waiting for the current task to be processed before destroying the poller core thread. When the poller core thread does not exist, determining whether there is a message being sent or received; or, after destroying the poller core thread, determining whether there is a message being sent or received; if there is a message being sent or received, waiting for the current message sending and receiving process to be completed; if no message is being sent or received, directly destroying the task list.

[0117] In implementation, when the user thread issues an instruction to stop the poller management module, the poller management module receives the stop instruction through the communication unit, and first checks whether the poller core thread exists. If it exists, it checks whether the current task has been processed. If the current task has been processed, the poller core thread is destroyed, including recycling the poller core thread and the registered task-related resources. Otherwise, the poller core thread is destroyed after the task is processed. Then check whether the message communication interface is sending or receiving messages. If so, wait for the current message sending and receiving to be completed, otherwise the thread message communication interface is directly destroyed. Finally, the three task lists with different priorities are destroyed. From then on, the poller management module stops working.

[0118] In the above embodiments, the poller management method is described in detail, and the present invention also provides a corresponding embodiment of the poller management device. It should be noted that the present invention describes the embodiments of the device part from the perspective of hardware.

[0119] Figure 6 Schematic diagram of the structure of the polling device management device provided by the embodiment of the present invention. This embodiment is based on the hardware perspective, such as Figure 6 As shown, the poller management device includes:

[0120] A memory 60, for storing computer programs;

[0121] The processor 61 is used to implement the steps of the poller management method mentioned in the above embodiment when executing the computer program.

[0122] Among them, the processor 61 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 61 can be implemented in at least one hardware form of a digital signal processor (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 61 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU; the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 61 may be integrated with a graphics processing unit (GPU), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 61 may also include an artificial intelligence (AI) processor, which is used to process computing operations related to machine learning.

[0123] The memory 60 may include one or more non-volatile storage media, which may be non-transitory. The memory 60 may also include a high-speed random access memory, and a non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory 60 is at least used to store the following computer program 601, wherein, after the computer program is loaded and executed by the processor 61, it can implement the relevant steps of the poller management method disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory 60 may also include an operating system 602 and data 603, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system 602 may include Windows, Unix, Linux, etc. The data 603 may include, but is not limited to, the data involved in the above-mentioned poller management method, etc.

[0124] In some embodiments, the poller management device may further include a display screen 62, an input / output interface 63, a communication interface 64, a power supply 65, and a communication bus 66. Those skilled in the art will appreciate that Figure 6 The structure shown in does not constitute a limitation on the poller management device, and may include more or fewer components than shown. The poller management device provided by the embodiment of the present invention includes a memory and a processor. When the processor executes the program stored in the memory, it can implement the following method: the poller management method, the effect is the same as above.

[0125] Finally, the present invention also provides an embodiment corresponding to a non-volatile storage medium. The non-volatile storage medium stores a computer program, and when the computer program is executed by a processor, the steps recorded in the above method embodiment are implemented.

[0126] It is understandable that if the method in the above embodiment is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and executes all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code. The non-volatile storage medium provided by the present invention can implement the above-mentioned polling management method, and the effect is the same as above.

[0127] Finally, the present invention also provides an embodiment corresponding to a computer program product. The computer program product includes a computer program / instruction, and when the computer program / instruction is executed by a processor, the steps described in the above-mentioned poller management method embodiment are implemented. The computer program product provided by the present invention can implement the above-mentioned poller management method, and the effect is the same as above.

[0128] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the statement "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0129] The poller management method, device, medium and computer program product provided by the present invention are introduced in detail above. The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the embodiments can be referenced to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principle of the present invention, several improvements and modifications can be made to the present invention, and these improvements and modifications also fall within the scope of protection of the present invention.

Claims

1. A poller management method, It is characterized in that The method comprises: Initializing multiple task linked lists; the multiple task linked lists include a first task linked list for managing high-priority tasks, a second task linked list for managing medium-priority tasks, and a third task linked list for managing low-priority tasks; the tasks managed by each task linked list have different priorities; Create a poller core thread, configure the CPU affinity of the poller core thread, and bind a CPU core to the poller core thread; the tasks in each task list are polled and scheduled by the poller core thread according to the priority; the tasks in each task list are independent of the poller; A task registration callback function is received by using a dynamic registration interface in a message communication interface and sent as a message by a user thread configuration; the message communication interface is used for data communication with a user thread; the message communication interface uses a communication mode of a lock-free circular queue in an open source data plane development toolkit; the process of the user thread configuring the task registration callback function includes: the user thread allocates a memory for storing attribute information of the task to be registered and a first communication message; the attribute information of the task to be registered is initialized; the attribute information of the task to be registered includes the running state, identity, priority, execution mode, parameters required for execution, execution cycle, and set time point of the task to be registered; the attribute information of the task to be registered is used as parameter information of the task registration callback function; the first communication message is initialized; the first communication message includes a task attribute information reference and a first task method reference; the task attribute information reference points to an initialized attribute information block of the task to be registered, and the first task method reference points to the task registration callback function; According to the priority parameter in the attribute information of the task to be registered of the task registration callback function, the corresponding task linked list is obtained; if the priority parameter corresponds to a high priority, the obtained task linked list is the first task linked list; if the priority parameter corresponds to a medium priority, the obtained task linked list is the second task linked list; if the priority parameter corresponds to a low priority, the obtained task linked list is the third task linked list; Add the task to be registered corresponding to the task registration callback function to the acquired task linked list; A task deregistration callback function configured by a user thread and sent in the form of a message is received by using a dynamic deregistration interface in the message communication interface; the process of configuring the task deregistration callback function by the user thread includes: the user thread allocates a memory for storing the identity information of the task to be destroyed and the second communication message; the identity information of the task to be destroyed is initialized; the identity information of the task to be destroyed is used as parameter information of the task deregistration callback function; the second communication message is initialized; the second communication message includes a task identity information reference and a second task method reference; the task identity information reference points to the initialized identity information block of the task to be destroyed, and the second task method reference points to the task deregistration callback function; Traverse all task lists and obtain the existing task identity information in the task list one by one; When the identity information of the task to be destroyed in the task cancellation callback function matches the identity information of the existing task, the task with the same identity information is deleted from the corresponding task linked list.

2. The poller management method according to claim 1, It is characterized in that Add the task to be registered corresponding to the task registration callback function to the acquired task list, including: The state of the task to be registered corresponding to the task registration callback function is set to a waiting state, and the task to be registered is added to the tail of the acquired task chain list, waiting for scheduling execution; When the task to be registered is scheduled, the state of the task to be registered is adjusted to the running state, and then restored to the waiting state after execution is completed.

3. The poller management method according to claim 1, It is characterized in that The tasks in each task list are polled and scheduled by the poller core thread according to the priority, including: The poller core thread uses a two-level loop to manage the priority of each task list; The two-level loop includes an outer loop and an inner loop; the outer loop polls all task linked lists in a set order, and the inner loop polls the tasks on each task linked list.

4. The poller management method according to claim 1, It is characterized in that Also includes: Traverse all task lists and schedule the current task in the task list according to the task priority management strategy; The scheduling number of the first task linked list in the task priority management strategy is greater than the scheduling number of the second task linked list, and the scheduling number of the second task linked list is greater than the scheduling number of the third task linked list; Get the type of the current task and execute the corresponding task execution method according to the type.

5. The poller management method according to claim 4, It is characterized in that Get the type of the current task, including: If the current task is a preset task that is executed only once at a specified future set time point, the current task is determined to be a scheduled task; If the current task is a preset task to be executed once every set time interval in the future, the current task is determined to be a periodic task; If the current task is a task that has no time requirement and needs to be executed only once, then the current task is determined to be a real-time task.

6. The poller management method according to claim 5, It is characterized in that Execute the corresponding task execution mode according to the type, including: If the current task is a scheduled task, determine whether the set time point has arrived; If the set time point arrives, the scheduled task is scheduled, and the state of the scheduled task is set to the running state, and the scheduled task is executed. After the execution is completed, the state of the scheduled task is adjusted to the waiting state, and the scheduled task is deleted; if the set time point is not arrived, the next task is scheduled; If the current task is a periodic task, determine whether the periodic time has arrived; If the cycle time is reached, the periodic task is scheduled, and the state of the periodic task is set to the running state, and the periodic task is executed. After the execution is completed, the state of the periodic task is adjusted to the waiting state, and the next task is scheduled; if the cycle time is not reached, the next task is continuously scheduled; If the current task is a real-time task, the real-time task is directly scheduled, and the state of the real-time task is set to the running state, and the real-time task is executed. After the execution is completed, the state of the real-time task is adjusted to the waiting state, and the real-time task is deleted, and the next task is scheduled.

7. The poller management method according to claim 1, It is characterized in that Delete tasks with the same identity from the corresponding task list, including: Determine that the tasks with the same identity information are tasks to be destroyed; Release the attribute information memory resource of the task to be destroyed from the task chain list where the task to be destroyed is located; At the same time, the identity memory resource of the task to be destroyed is released.

8. The poller management method according to claim 1, It is characterized in that Also includes: When receiving a stop instruction sent by a user thread, determining whether the poller core thread exists; If the poller core thread exists, determine whether the current task has been processed; If the current task processing is completed, the poller core thread is destroyed, including recycling the poller core thread and registered task-related resources; If the current task is not processed completely, the poller core thread is destroyed after the current task is processed completely.

9. The poller management method according to claim 8, It is characterized in that Also includes: If the poller core thread does not exist, determine whether there is a message being sent or received; or, after destroying the poller core thread, determine whether there is a message being sent or received; If a message is being sent or received, wait for the current message sending or receiving process to complete; If no message is being sent or received, the task list is destroyed directly.

10. A poller management device, It is characterized in that The device comprises: Memory for storing computer programs; A processor, configured to implement the steps of the poller management method according to any one of claims 1 to 9 when executing the computer program.

11. A non-volatile storage medium, It is characterized in that The non-volatile storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the poller management method according to any one of claims 1 to 9 are implemented.

12. A computer program product comprising a computer program / instructions, It is characterized in that When the computer program / instructions are executed by a processor, the steps of the poller management method according to any one of claims 1 to 9 are implemented.