Method, device and direct access memory for obtaining task completion notification
Patent Information
- Application Number
- CN202211035562.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-26
- Publication Date
- 2026-10-27
- Estimated Expiration
- 2042-08-26
AI Technical Summary
[0010]针对现有技术的缺陷和改进需求,本发明提供了一种获取任务完成通知的方法、装置及直接访问内存的方法,其目的在于,在不消耗过多CPU资源的情况下快速获取任务完成通知
[0053](1)本发明将中断获取CQE的方式和轮询获取CQE的方式相结合,利用计数器counter记录从完成队列中获取的CQE所执行的轮询次数,并根据counter对轮询状态进行维持,具体地,当完成队列中有CQE时,则从完成队列中批量获取CQE,并将计数器counter清零,当完成队列中没有CQE时,不会立即停止轮询,而是利用counter记录轮询次数,并在轮询次数超过计数上限count_limit时才退出轮询模式,由此能够确保在短时间内到达的任务完成通知WC都能及时被获取并处理,减小延迟,同时又能避免CPU盲目轮询而占用过多的CPU资源。总体而言,本发明能够在不消耗过多的CPU资源的情况下快速获取任务完成通知,降低任务处理延迟。
Smart Images

Figure CN115470014B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer network communication, and more specifically, relates to a method, apparatus for obtaining task completion notifications, and a method for directly accessing memory. Background Technology
[0002] Remote Direct Memory Access (RDMA) is a new type of memory access technology that enables direct memory access from the memory of one computer to the memory of another computer.
[0003] In the traditional TCP / IP transmission process, the CPU needs to copy data between user space and kernel space. The encapsulation and parsing of data packets also require the full participation of the CPU. When the data volume is large, the CPU utilization rate is high. Compared with the traditional TCP / IP network, RDMA has three major advantages: (1) Kernel bypass: I / O process can bypass the kernel, that is, data can be prepared in user space and the hardware can be notified to send and receive, avoiding the overhead of system calls and context switching; (2) Zero copy: Due to the inherent defects of the TCP / IP protocol stack, the message sending and receiving process needs to copy data back and forth between user space and kernel space, while RDMA does not need to; (3) CPU offloading: Memory can be read and written without the participation of the CPU on the remote node. In fact, the encapsulation and parsing of the packets are all handled by the RDMA network card. Compared with TCP / IP, RDMA has the advantages of low latency and high bandwidth, so it has been widely used in data centers.
[0004] One of the advantages of RDMA over TCP / IP is CPU offloading, meaning that the remote CPU does not need to participate in the transmission process. However, this is only when using RDMA READ / WRITE; in other stages, the CPU still needs to handle the processing.
[0005] During RDMA resource initialization, the CPU needs to perform a series of operations, including obtaining the RDMA device list, opening the RDMA device, allocating protection domains, registering memory, creating completion queues, and creating queue pairs. Similarly, resource destruction also requires the CPU to call relevant interfaces to execute functions. This portion of CPU resources is only used during system initialization and shutdown, does not affect the transmission process, and cannot be omitted.
[0006] During data transmission, the CPU needs to encapsulate the transmission task into an RDMA Work Request (WR) and pass it to the RDMA network card. If RDMA SEND / RECV is used for data transmission, a batch of RECV WRs also needs to be prepared and passed to the Recv Queue (RQ). Besides the transmission of work requests, the processing of work completion notifications (WC) also requires CPU involvement. When a completion queue element (CQE) is generated, the CPU needs to retrieve the task completion notification from the completion queue (CQ) and then process it. Only after processing a task completion notification is a transmission task truly complete. The processing of WR and WC requires CPU participation, and the different methods of checking for new CQEs in the CQ result in different CPU utilization. There are two basic methods for checking for new CQEs in the CQ: interrupt-based and polling-based.
[0007] The interrupt-driven method of acquiring a CQE requires using a multiplexing mechanism such as Epoll / Select / Kqueue to monitor the completion channel (CC) bound to the completion queue (CQ). When a new CQE is generated in the CQ, the file descriptor of the completion channel CC will generate a readable event, notifying the CPU via an interrupt. The CQE acquisition thread is then awakened and calls the ibv_poll_cq() interface to acquire the CQE. This method does not require the thread to constantly check for CQEs in the CQ, thus not consuming CPU resources, but it does require waking up the thread, resulting in higher latency.
[0008] The polling method for acquiring the CQE continuously polls the CQ without falling asleep. When a completion event occurs in the CQ, the polling thread acquires and processes the completion event sequentially. While this method avoids thread wake-up overhead, resulting in low latency and fast response, the CQE acquisition thread occupies CPU cores, and prolonged idling wastes CPU resources.
[0009] Besides the basic interrupt and polling methods for acquiring CQEs, some other methods attempt to combine interrupts and polling for better performance, such as batch polling. This method doesn't poll the CQE itself; instead, it uses multiplexing to listen to the completion channel (CC). When a CQE occurs, it notifies the CPU via an interrupt. After the interrupt is triggered, the CQE acquisition thread polls the CQ a fixed number of times. Unless an error occurs, it can acquire K WCs, where K is greater than 0 and less than or equal to the polling count N. This method can reduce the number of interrupts from N to 1, improving performance compared to the traditional interrupt-based approach. However, after polling N times, even if other CQEs occur later in the CQE, the batch polling method will revert to interrupt-triggered mode, waiting for the next interrupt to process them. This results in these later-arriving CQEs not being processed promptly, leading to higher overall latency. Summary of the Invention
[0010] To address the shortcomings and improvement needs of existing technologies, this invention provides a method, apparatus, and method for directly accessing memory to obtain task completion notifications, with the aim of quickly obtaining task completion notifications without consuming excessive CPU resources.
[0011] To achieve the above objectives, according to one aspect of the present invention, a method for obtaining a task completion notification is provided, comprising:
[0012] When the system starts, a past count record `pre_record2` is set to record the number of polls required to retrieve a completion notification from the completion queue in the last instance, and a past count record `pre_record1` is set to record the number of polls required to retrieve a completion notification from the completion queue in the current instance. These two past count records are initialized according to `pre_record1 = UPPER_LIMIT` and `pre_record2 = UPPER_LIMIT`, where `UPPER_LIMIT` is the preset maximum count limit.
[0013] When a new task completion notification is generated in the completion queue, a polling step is executed to enter polling mode; the polling step includes:
[0014] (S1) Calculate the upper limit of the count, count_limit, according to count_limit = (pre_record1 + pre_record2) / 2;
[0015] (S2) Set the value of the counter to 0;
[0016] (S3) Poll the completion queue. If there is a task completion notification in the completion queue, proceed to step (S4); otherwise, proceed to step (S5).
[0017] (S4) After acquiring the task completion notifications in the completion queue in batches, the process proceeds to step (S2);
[0018] (S5) After incrementing the value of the counter counter by 1, it is determined whether counter<count_limit is satisfied. If yes, the process proceeds to step (S3); otherwise, the polling mode is exited, and the polling step ends.
[0019] Further, in the method for acquiring a task completion notification provided by the present invention, before proceeding to step (S2) in step (S4), the method further comprises:
[0020] It is determined whether counter≥LOWER_LIMIT is satisfied. If yes, the past count records pre_record2 and pre_record1 are updated according to pre_record2=pre_record1, pre_record1=counter, and then the process proceeds to step (S1);
[0021] Herein, LOWER_LIMIT is a preset minimum value of the count upper limit; LOWER_LIMIT<UPPER_LIMIT.
[0022] Further, in the method for acquiring a task completion notification provided by the present invention, before exiting the polling mode in step (S5), the method further comprises:
[0023] The past count records pre_record2 and pre_record1 are updated, and the updating manner is as follows:
[0024] pre_record2=pre_record1;
[0025] pre_record1=min(counter+STEP_FORWARD, UPPER_LIMIT);
[0026] Herein, STEP_FORWARD is a preset non-negative integer.
[0027] Further, STEP_FORWARD>0.
[0028] According to another aspect of the present invention, an apparatus for acquiring a task completion notification is provided, comprising: an initialization module, a monitoring module, and a polling module;
[0029] an initialization module, configured to set a past count record pre_record2 for recording the number of polling executions required to obtain a completion notification from the completion queue last time, and a past count record pre_record1 for recording the number of polling executions required to obtain a completion notification from the completion queue currently when the system starts, and initialize the two past count records according to pre_record1=UPPER_LIMIT and pre_record2=UPPER_LIMIT; wherein UPPER_LIMIT is a preset maximum count upper limit;
[0030] a listening module, configured to trigger a polling module to enter a polling mode when a new task completion notification is generated in the completion queue;
[0031] the polling module comprises: a count upper limit updating unit, a counter zeroing unit, a polling unit, a CQE obtaining unit and a counter updating unit;
[0032] the count upper limit updating unit is configured to calculate the count upper limit count_limit according to count_limit=(pre_record1+pre_record2) / 2, and then trigger the counter zeroing unit;
[0033] the counter zeroing unit is configured to set the value of the counter counter to 0, and then trigger the polling unit;
[0034] the polling unit is configured to poll the completion queue, trigger the CQE obtaining unit when there is a task completion notification in the completion queue, and trigger the counter updating unit when there is no task completion notification in the completion queue;
[0035] the CQE obtaining unit is configured to obtain task completion notifications in the completion queue in batches, and then trigger the counter zeroing unit;
[0036] the counter updating unit is configured to add 1 to the value of the counter counter, then judge whether counter<count_limit is satisfied, if yes, trigger the polling unit, otherwise, exit the polling mode and end the polling.
[0037] Further, the apparatus for obtaining a task completion notification provided by the present invention further comprises: a first past count record updating unit, configured to update the past count records pre_record2 and pre_record1 according to pre_record2=pre_record1 and pre_record1=counter, and then trigger the count upper limit updating unit;
[0038] Furthermore, before triggering the counter reset unit, the CQE acquisition unit will determine whether counter≥LOWER_LIMIT is satisfied. If so, the first past count record update unit will be triggered; otherwise, the counter reset unit will be triggered.
[0039] Where LOWER_LIMIT is the preset minimum upper limit of the count; LOWER_LIMIT <UPPER_LIMIT。
[0040] Furthermore, the apparatus for obtaining task completion notification provided by the present invention further includes: a second past count record update unit, used to update past count records pre_record2 and pre_record1, wherein the update method is as follows:
[0041] pre_record2 = pre_record1;
[0042] pre_record1=min(counter+STEP_FORWARD,UPPER_LIMIT);
[0043] Furthermore, before exiting polling mode, the counter update unit will first trigger the second past count record update unit;
[0044] STEP_FORWARD is a preset non-negative integer.
[0045] Furthermore, STEP_FORWARD > 0.
[0046] According to another aspect of the present invention, a method for remote direct access to memory is provided, comprising:
[0047] The communication thread generates transmission tasks and passes them to the work queue;
[0048] RDMA enables the network interface card to obtain work tasks from the work queue and perform network data communication according to the work tasks. After the network data communication is completed, the work task completion status is encapsulated into a task completion notification and transmitted to the completion queue.
[0049] The method for obtaining task completion notifications provided by the present invention is used to obtain task completion notifications from the completion queue, process them, and then notify the communication thread that the task is complete.
[0050] Furthermore, the method for notifying the communication thread that the transmission task has been completed is as follows:
[0051] The completion queue channel associated with the completion queue is registered to the I / O multiplexing Epoll. The communication thread calls the remote direct memory access interface to provide a notification mechanism for the specified completion queue. When the RDMA-enabled network interface card places a new completion notification in the completion queue, the I / O multiplexing triggers a callback, switches to the communication thread, and calls the interface to confirm receipt of the notification.
[0052] In summary, the above-described technical solutions conceived in this invention can achieve the following beneficial effects:
[0053] (1) This invention combines interrupt-based acquisition of CQE with polling-based acquisition of CQE. A counter is used to record the number of polling operations performed when acquiring CQE from the completion queue, and the polling state is maintained based on the counter. Specifically, when there are CQEs in the completion queue, CQEs are acquired in batches from the queue, and the counter is cleared. When there are no CQEs in the completion queue, polling does not stop immediately, but the counter records the number of polling operations. Polling mode is only exited when the number of polling operations exceeds the count limit (count_limit). This ensures that task completion notifications (WCs) arriving within a short time are acquired and processed promptly, reducing latency, while also avoiding excessive CPU resource consumption due to blind polling. Overall, this invention can quickly acquire task completion notifications without consuming excessive CPU resources, reducing task processing latency.
[0054] (2) Before clearing the counter, the present invention will first determine whether the counter has reached the preset minimum count limit. If so, it will first use the number of polling times required to obtain the CQE last time to dynamically update the past count records. The update method adopted will make the count limit count_limit gradually decrease within the preset range [LOWER_LIMIT, UPPER_LIMIT] in a single interrupt, avoiding infinite loop and also avoiding excessive CPU usage.
[0055] (3) Before exiting the polling mode, the present invention will dynamically update the past count records by using the number of polling times required to obtain CQE in the last time. The update method adopted will make the count limit count_limit be adjusted to a larger value when entering the polling mode next time, so as to obtain CQE.
[0056] In summary, this invention combines interrupt-based CQE acquisition with polling-based CQE acquisition. It avoids preempting CPU resources when there are no elements in the completion queue and quickly obtains task completion notifications when there are elements in the completion queue. This avoids the problems of multiple interrupts required to process multiple CQEs and the need for a second interrupt to process a CQE that arrives slightly late. It balances low CPU utilization and low acquisition latency, and further dynamically adjusts the upper limit of the polling count according to the load, keeping the number of polling attempts within a reasonable range based on load characteristics. Therefore, it has strong adaptability. Attached Figure Description
[0057] Figure 1 This is a flowchart of the method for obtaining task completion notification provided in an embodiment of the present invention;
[0058] Figure 2 This is an algorithm diagram of the method for obtaining task completion notifications using remote direct memory access technology provided in this embodiment of the invention;
[0059] Figure 3 This is a schematic diagram of a method for remote direct access to memory provided in an embodiment of the present invention. Detailed Implementation
[0060] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0061] In this invention, the terms "first," "second," etc. (if present) in the invention and the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence.
[0062] Before explaining the technical solution of this invention in detail, the English abbreviations of relevant technical terms are briefly introduced as follows:
[0063] RDMA: Remote Direct Memory Access;
[0064] WR: Work Request, RDMA work request;
[0065] RQ: Recv Queue;
[0066] CQ: Completion Queue;
[0067] CQE: Completion Queue Element;
[0068] WC: Work Completion, task completion notification; in this invention, the task completion notification will be placed in the completion queue CQ as a CQE.
[0069] CC: Completion Channel.
[0070] To address the shortcomings of existing methods for obtaining task completion notifications via remote direct memory access (CQE), which cannot simultaneously achieve low CPU utilization and low latency, and require an interrupt to process new completion notifications, this invention provides a method, apparatus, and direct memory access method for obtaining task completion notifications. The overall approach combines interrupt-driven CQE acquisition with polling-based CQE acquisition. When no CQE is generated in the completion queue, the communication thread does not actively access the queue, concentrating resources on data transmission. When a new CQE is generated in the completion queue, a notification mechanism notifies the communication thread. After completing its current task, the communication thread begins polling the completion queue. After obtaining all task completion notifications, polling continues until the maximum number of polling attempts is reached without any new CQEs being generated, at which point the polling mode is exited. Furthermore, the maximum number of polling attempts is dynamically adjusted based on load to maintain it within a reasonable range.
[0071] The following is an example.
[0072] Example 1:
[0073] A method for obtaining a task completion notification includes:
[0074] When the system starts, a past count record `pre_record2` is set to record the number of polls required to retrieve a completion notification from the completion queue in the last instance, and a past count record `pre_record1` is set to record the number of polls required to retrieve a completion notification from the completion queue in the current instance. These two past count records are initialized according to `pre_record1 = UPPER_LIMIT` and `pre_record2 = UPPER_LIMIT`, where `UPPER_LIMIT` is the preset maximum count limit.
[0075] When a new task completion notification is generated in the completion queue, a polling step is executed to enter polling mode; such as Figure 1 and Figure 2 As shown, the polling steps include:
[0076] (S1) Calculate the count upper limit count_limit according to count_limit=(pre_record1+pre_record2) / 2;
[0077] (S2) Set the value of the counter counter to 0;
[0078] (S3) Poll the completion queue, if there is a task completion notification in the completion queue, proceed to step (S4); otherwise, proceed to step (S5);
[0079] (S4) After batch acquiring the task completion notifications in the completion queue, proceed to step (S2);
[0080] (S5) After incrementing the value of the counter counter by 1, determine whether counter<count_limit is satisfied. If yes, proceed to step (S3); otherwise, it indicates that no new CQE has been generated in the completion queue for a relatively long time, therefore, exit the polling mode and end the polling step.
[0081] This embodiment combines the manner of acquiring CQEs by interrupts and the manner of acquiring CQEs by polling, uses the counter counter to record the number of polling executions performed for the CQEs acquired from the completion queue, and maintains the polling state according to the counter. Specifically, when there is a CQE in the completion queue, the CQEs are acquired from the completion queue in batches and the counter counter is cleared; when there is no CQE in the completion queue, the polling is not stopped immediately, instead the counter is used to record the number of polling times, and the polling mode is exited only when the number of polling times exceeds the count upper limit count_limit. This can ensure that all task completion notifications WC arriving in a short period of time can be acquired and processed in time to reduce latency, and at the same time prevent the CPU from blindly polling and occupying excessive CPU resources.
[0082] To adapt to dynamic load changes, during the process of executing the polling step, this embodiment also updates two past count records according to the load situation, and updates the count upper limit count_limit according to the updated past count records, so that the count upper limit counter_limit adapts to the load; as Figure 1 and Figure 2 shown, before the counter counter is cleared, this embodiment updates the past count records according to the polling count situation, and also updates the past count records before exiting the polling mode; the specific update is as follows:
[0083] In step (S4) of this embodiment, before proceeding to step (S2), the method further comprises:
[0084] Determine whether counter≥LOWER_LIMIT is satisfied. If so, update the past count records pre_record2 and pre_record1 according to pre_record2=pre_record1 and pre_record1=counter, and then proceed to step (S1).
[0085] Where LOWER_LIMIT is the preset minimum upper limit of the count; LOWER_LIMIT <UPPER_LIMIT;
[0086] This update method dynamically adjusts the count limit for the next round by utilizing the number of polling operations required when the CQE is acquired in the previous round. This update method ensures that the count limit for each round gradually decreases during a single interrupt, avoiding infinite loops. In this embodiment, each time the CQE is acquired, the counter value is updated to the previous count record only if the counter value is greater than or equal to LOWER_LIMIT, ensuring that the previous count record is greater than or equal to LOWER_LIMIT.
[0087] In step (S5) of this embodiment, before exiting the polling mode, the method further includes:
[0088] Update the previous count records pre_record2 and pre_record1 as follows:
[0089] pre_record2 = pre_record1;
[0090] pre_record1=min(counter+STEP_FORWARD,UPPER_LIMIT);
[0091] Where STEP_FORWARD is a preset non-negative integer; considering that when exiting polling mode, it means that the value of the counter is equal to the count limit count_limit, the count limit should be adjusted to be larger when entering polling mode again in order to obtain CQE. In this embodiment, STEP_FORWARD>0, and its specific value can be set according to the load characteristics; in this embodiment, when updating the past count record pre_record1, the smaller value of counter+STEP_FORWARD and UPPER_LIMIT is taken as its updated value, ensuring that the count limit is increased but does not exceed UPPER_LIMIT.
[0092] This embodiment maintains two past count records to track the number of polling operations required to obtain CQE twice, and takes the average of the two past count records as the upper limit of the count. This method allows the upper limit of the count to be dynamically adjusted between UPPER_LIMIT and LOWER_LIMIT, which can adjust the number of polling operations according to the load within the range selected by the user, thus achieving a low CPU utilization rate while ensuring low latency.
[0093] In summary, this embodiment proposes a novel method for obtaining task completion notifications for remote direct memory access by combining interrupt methods and busy polling methods. It does not preempt CPU resources when there are no completion queue elements, and can quickly enter polling mode to obtain task completion notifications after a new completion queue element is generated, thus balancing low CPU utilization and low acquisition latency. After entering polling mode, a counter is used to maintain polling of the CQE, avoiding the problems of multiple interrupts required to process multiple CQEs and the need for a second interrupt to process a CQE arriving slightly late. Simultaneously, the upper limit of the counter is dynamically adjusted based on past records, ensuring that the number of polling times remains within a reasonable range according to load characteristics, thus exhibiting strong adaptability.
[0094] Example 2:
[0095] An apparatus for obtaining a task completion notification includes: an initialization module, a listening module, and a polling module;
[0096] The initialization module is used to set up two past count records at system startup: pre_record2, which records the number of polls required to retrieve a completion notification from the completion queue last time, and pre_record1, which records the number of polls required to retrieve a completion notification from the completion queue currently. These two past count records are initialized according to the following settings: pre_record1 = UPPER_LIMIT, pre_record2 = UPPER_LIMIT; UPPER_LIMIT is the preset maximum count limit.
[0097] The listening module is used to trigger the polling module to enter polling mode when a new task completion notification is generated in the completion queue.
[0098] The polling module includes: a count limit update unit, a counter reset unit, a polling unit, a CQE acquisition unit, and a counter update unit;
[0099] The upper limit of the count update unit is used to calculate the upper limit of the count, count_limit, according to count_limit = (pre_record1 + pre_record2) / 2, and then trigger the counter clearing unit.
[0100] A counter zeroing unit, configured to set the value of the counter counter to 0, and then trigger a polling unit;
[0101] The polling unit, configured to poll a completion queue, trigger a CQE acquisition unit when there is a task completion notification in the completion queue, and trigger a counter update unit when there is no task completion notification in the completion queue;
[0102] The CQE acquisition unit, configured to acquire task completion notifications in the completion queue in batches, and then trigger the counter zeroing unit;
[0103] The counter update unit, configured to add 1 to the value of the counter counter, then determine whether counter<count_limit is satisfied, if yes, trigger the polling unit, otherwise, exit the polling mode and terminate the polling.
[0104] To dynamically adjust the count upper limit according to the load, this embodiment further comprises: a first historical count record update unit, configured to update the historical count records pre_record2 and pre_record1 according to pre_record2=pre_record1 and pre_record1=counter, and then trigger a count upper limit update unit;
[0105] Moreover, before the CQE acquisition unit triggers the counter zeroing unit, it will determine whether counter≥LOWER_LIMIT is satisfied, if yes, trigger the first historical count record update unit, otherwise, trigger the counter zeroing unit;
[0106] Wherein, LOWER_LIMIT is a preset minimum value of the count upper limit; LOWER_LIMIT<UPPER_LIMIT.
[0107] To dynamically adjust the count upper limit according to the load, this embodiment further comprises: a second historical count record update unit, configured to update the historical count records pre_record2 and pre_record1, with the updating manner as follows:
[0108] pre_record2=pre_record1;
[0109] pre_record1=min(counter+STEP_FORWARD,UPPER_LIMIT);
[0110] Moreover, before the counter update unit exits the polling mode, it will trigger the second historical count record update unit first;
[0111] In this embodiment, STEP_FORWARD is a preset non-negative integer; similarly, in order to adjust the upper limit of the count to be larger when entering the polling mode next time so as to obtain CQE, STEP_FORWARD>0;
[0112] In this embodiment, the specific implementation methods of each module or unit can also refer to the description in Embodiment 1 above.
[0113] Example 3:
[0114] A method for remote direct access to memory, such as Figure 3 As shown, it includes:
[0115] The communication thread generates transmission tasks and passes them to the work queue;
[0116] RDMA enables the network interface card to obtain work tasks from the work queue and perform network data communication according to the work tasks. After the network data communication is completed, the work task completion status is encapsulated into a task completion notification and transmitted to the completion queue.
[0117] The task completion notification is obtained from the completion queue using the method for obtaining task completion notification provided in Embodiment 1 above, and then processed. After processing, the communication thread is notified that the task is completed.
[0118] In this embodiment, the method for notifying the communication thread that the transmission task has been completed is as follows:
[0119] The completion queue channel associated with the completion queue is registered to the I / O multiplexing Epoll. The communication thread calls the remote direct memory access interface to provide a notification mechanism for the specified completion queue. When the RDMA-enabled network interface card places a new completion notification in the completion queue, the I / O multiplexing triggers a callback, switches to the communication thread, and calls the interface to confirm receipt of the notification.
[0120] Those skilled in the art will readily understand that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for obtaining a task completion notification, characterized in that, comprising: upon system startup, setting a past count record pre_record2 for recording the number of polling executions performed last time a completion notification is obtained from the completion queue, and a past count record pre_record1 for recording the number of polling executions performed currently a completion notification is obtained from the completion queue, and initializing these two past count records according to pre_record1=UPPER_LIMIT, pre_record2=UPPER_LIMIT; wherein UPPER_LIMIT is a preset maximum count upper limit; when a new task completion notification is generated in the completion queue, executing a polling step to enter a polling mode; the polling step comprises: (S1) calculating a count upper limit count_limit according to count_limit=(pre_record1+pre_record2) / 2; (S2) setting the value of a counter counter to 0; (S3) polling the completion queue, and if there is a task completion notification in the completion queue, proceeding to step (S4); otherwise, proceeding to step (S5); (S4) after batch acquiring the task completion notifications in the completion queue, proceeding to step (S2); (S5) incrementing the value of the counter counter by 1, then determining whether counter<count_limit is satisfied, if yes, proceeding to step (S3); otherwise, exiting the polling mode, and ending the polling step; in the step (S4), before proceeding to step (S2), the method further comprises: determining whether counter≥LOWER_LIMIT is satisfied, if yes, updating the past count records pre_record2 and pre_record1 according to pre_record2=pre_record1, pre_record1=counter, then proceeding to step (S1); wherein LOWER_LIMIT is a preset minimum count upper limit; LOWER_LIMIT<UPPER_LIMIT; in the step (S5), before exiting the polling mode, the method further comprises: updating the past count records pre_record2 and pre_record1 in the following updating manner: pre_record2=pre_record1; pre_record1=min(counter+STEP_FORWARD, UPPER_LIMIT); wherein STEP_FORWARD is a preset non-negative integer.
2. The method for obtaining a task completion notification as described in claim 1, characterized in that, STEP_FORWARD>0.
3. A device for obtaining a task completion notification, characterized in that, comprising: an initialization module, a monitoring module and a polling module; the initialization module, configured to set a past count record pre_record2 for recording the number of polling executions required to obtain a completion notification from the completion queue last time and a past count record pre_record1 for recording the number of polling executions required to obtain a completion notification from the completion queue currently when the system is started, and initialize the two past count records according to pre_record1=UPPER_LIMIT and pre_record2=UPPER_LIMIT; wherein UPPER_LIMIT is a preset maximum count upper limit; the listening module, configured to trigger the polling module to enter a polling mode when a new task completion notification is generated in the completion queue; the polling module comprises: a count upper limit updating unit, a counter zero clearing unit, a polling unit, a CQE obtaining unit and a counter updating unit; the count upper limit updating unit, configured to calculate a count upper limit count_limit according to count_limit = (pre_record1+ pre_record2) / 2, and then trigger the counter zero clearing unit; the counter zero clearing unit, configured to set the value of a counter counter to 0, and then trigger the polling unit; the polling unit, configured to poll the completion queue, trigger the CQE obtaining unit when there is a task completion notification in the completion queue, and trigger the counter updating unit when there is no task completion notification in the completion queue; the CQE obtaining unit, configured to obtain task completion notifications in the completion queue in batches, and then trigger the counter zero clearing unit; the counter updating unit, configured to add 1 to the value of the counter counter, then determine whether counter<count_limit is satisfied, if yes, trigger the polling unit, otherwise, exit the polling mode and end the polling; the apparatus for obtaining a task completion notification further comprises: a first past count record updating unit, configured to update the past count records pre_record2 and pre_record1 according to pre_record2=pre_record1 and pre_record1=counter, and then trigger the count upper limit updating unit; and before the CQE obtaining unit triggers the counter zero clearing unit, it determines whether counter≥LOWER_LIMIT is satisfied, if yes, triggers the first past count record updating unit, otherwise, triggers the counter zero clearing unit; wherein LOWER_LIMIT is a preset minimum count upper limit; LOWER_LIMIT<UPPER_LIMIT; the apparatus for obtaining a task completion notification further comprises: a second past count record updating unit, configured to update the past count records pre_record2 and pre_record1 in the following manner: pre_record2=pre_record1; pre_record1=min(counter+STEP_FORWARD, UPPER_LIMIT); Furthermore, before exiting the polling mode, the counter update unit will first trigger the second past count record update unit; STEP_FORWARD is a preset non-negative integer.
4. The apparatus for obtaining a task completion notification as described in claim 3, characterized in that, STEP_FORWARD>0.
5. A method for remote direct access to memory, characterized in that, include: The communication thread generates transmission tasks and passes them to the work queue; RDMA enables the network interface card to obtain work tasks from the work queue and perform network data communication according to the work tasks. After the network data communication is completed, the work task completion status is encapsulated into a task completion notification and transmitted to the completion queue. The task completion notification is obtained from the completion queue using the method for obtaining task completion notification as described in claim 1 or 2, and processed. After processing, the communication thread is notified that the task is complete.
6. The method for remote direct access to memory as described in claim 5, characterized in that, The method for notifying the communication thread that the transmission task has been completed is as follows: The completion queue channel associated with the completion queue is registered to the I / O multiplexing Epoll. The communication thread calls the remote direct memory access interface to provide a notification mechanism for the specified completion queue. When the RDMA-enabled network interface card places a new completion notification in the completion queue, the I / O multiplexing triggers a callback, switches to the communication thread, and calls the interface to confirm receipt of the notification.